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, ...) \
101 if (dwarf_read_debug >= 1) \
102 debug_prefixed_printf ("dwarf-read", __func__, fmt, ##__VA_ARGS__); \
106 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
108 #define dwarf_read_debug_printf_v(fmt, ...) \
111 if (dwarf_read_debug >= 2) \
112 debug_prefixed_printf ("dwarf-read", __func__, fmt, ##__VA_ARGS__); \
116 /* When non-zero, dump DIEs after they are read in. */
117 static unsigned int dwarf_die_debug
= 0;
119 /* When non-zero, dump line number entries as they are read in. */
120 unsigned int dwarf_line_debug
= 0;
122 /* When true, cross-check physname against demangler. */
123 static bool check_physname
= false;
125 /* When true, do not reject deprecated .gdb_index sections. */
126 static bool use_deprecated_index_sections
= false;
128 /* This is used to store the data that is always per objfile. */
129 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
131 /* These are used to store the dwarf2_per_bfd objects.
133 objfiles having the same BFD, which doesn't require relocations, are going to
134 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
136 Other objfiles are not going to share a dwarf2_per_bfd with any other
137 objfiles, so they'll have their own version kept in the _objfile_data_key
139 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
140 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
142 /* The "aclass" indices for various kinds of computed DWARF symbols. */
144 static int dwarf2_locexpr_index
;
145 static int dwarf2_loclist_index
;
146 static int dwarf2_locexpr_block_index
;
147 static int dwarf2_loclist_block_index
;
149 /* Size of .debug_loclists section header for 32-bit DWARF format. */
150 #define LOCLIST_HEADER_SIZE32 12
152 /* Size of .debug_loclists section header for 64-bit DWARF format. */
153 #define LOCLIST_HEADER_SIZE64 20
155 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
156 #define RNGLIST_HEADER_SIZE32 12
158 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
159 #define RNGLIST_HEADER_SIZE64 20
161 /* An index into a (C++) symbol name component in a symbol name as
162 recorded in the mapped_index's symbol table. For each C++ symbol
163 in the symbol table, we record one entry for the start of each
164 component in the symbol in a table of name components, and then
165 sort the table, in order to be able to binary search symbol names,
166 ignoring leading namespaces, both completion and regular look up.
167 For example, for symbol "A::B::C", we'll have an entry that points
168 to "A::B::C", another that points to "B::C", and another for "C".
169 Note that function symbols in GDB index have no parameter
170 information, just the function/method names. You can convert a
171 name_component to a "const char *" using the
172 'mapped_index::symbol_name_at(offset_type)' method. */
174 struct name_component
176 /* Offset in the symbol name where the component starts. Stored as
177 a (32-bit) offset instead of a pointer to save memory and improve
178 locality on 64-bit architectures. */
179 offset_type name_offset
;
181 /* The symbol's index in the symbol and constant pool tables of a
186 /* Base class containing bits shared by both .gdb_index and
187 .debug_name indexes. */
189 struct mapped_index_base
191 mapped_index_base () = default;
192 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
194 /* The name_component table (a sorted vector). See name_component's
195 description above. */
196 std::vector
<name_component
> name_components
;
198 /* How NAME_COMPONENTS is sorted. */
199 enum case_sensitivity name_components_casing
;
201 /* Return the number of names in the symbol table. */
202 virtual size_t symbol_name_count () const = 0;
204 /* Get the name of the symbol at IDX in the symbol table. */
205 virtual const char *symbol_name_at
206 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
208 /* Return whether the name at IDX in the symbol table should be
210 virtual bool symbol_name_slot_invalid (offset_type idx
) const
215 /* Build the symbol name component sorted vector, if we haven't
217 void build_name_components (dwarf2_per_objfile
*per_objfile
);
219 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
220 possible matches for LN_NO_PARAMS in the name component
222 std::pair
<std::vector
<name_component
>::const_iterator
,
223 std::vector
<name_component
>::const_iterator
>
224 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
226 dwarf2_per_objfile
*per_objfile
) const;
228 /* Prevent deleting/destroying via a base class pointer. */
230 ~mapped_index_base() = default;
233 /* A description of the mapped index. The file format is described in
234 a comment by the code that writes the index. */
235 struct mapped_index final
: public mapped_index_base
237 /* A slot/bucket in the symbol table hash. */
238 struct symbol_table_slot
240 const offset_type name
;
241 const offset_type vec
;
244 /* Index data format version. */
247 /* The address table data. */
248 gdb::array_view
<const gdb_byte
> address_table
;
250 /* The symbol table, implemented as a hash table. */
251 gdb::array_view
<symbol_table_slot
> symbol_table
;
253 /* A pointer to the constant pool. */
254 const char *constant_pool
= nullptr;
256 bool symbol_name_slot_invalid (offset_type idx
) const override
258 const auto &bucket
= this->symbol_table
[idx
];
259 return bucket
.name
== 0 && bucket
.vec
== 0;
262 /* Convenience method to get at the name of the symbol at IDX in the
264 const char *symbol_name_at
265 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
266 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
268 size_t symbol_name_count () const override
269 { return this->symbol_table
.size (); }
272 /* A description of the mapped .debug_names.
273 Uninitialized map has CU_COUNT 0. */
274 struct mapped_debug_names final
: public mapped_index_base
276 bfd_endian dwarf5_byte_order
;
277 bool dwarf5_is_dwarf64
;
278 bool augmentation_is_gdb
;
280 uint32_t cu_count
= 0;
281 uint32_t tu_count
, bucket_count
, name_count
;
282 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
283 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
284 const gdb_byte
*name_table_string_offs_reordered
;
285 const gdb_byte
*name_table_entry_offs_reordered
;
286 const gdb_byte
*entry_pool
;
293 /* Attribute name DW_IDX_*. */
296 /* Attribute form DW_FORM_*. */
299 /* Value if FORM is DW_FORM_implicit_const. */
300 LONGEST implicit_const
;
302 std::vector
<attr
> attr_vec
;
305 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
307 const char *namei_to_name
308 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
310 /* Implementation of the mapped_index_base virtual interface, for
311 the name_components cache. */
313 const char *symbol_name_at
314 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
315 { return namei_to_name (idx
, per_objfile
); }
317 size_t symbol_name_count () const override
318 { return this->name_count
; }
321 /* See dwarf2read.h. */
324 get_dwarf2_per_objfile (struct objfile
*objfile
)
326 return dwarf2_objfile_data_key
.get (objfile
);
329 /* Default names of the debugging sections. */
331 /* Note that if the debugging section has been compressed, it might
332 have a name like .zdebug_info. */
334 static const struct dwarf2_debug_sections dwarf2_elf_names
=
336 { ".debug_info", ".zdebug_info" },
337 { ".debug_abbrev", ".zdebug_abbrev" },
338 { ".debug_line", ".zdebug_line" },
339 { ".debug_loc", ".zdebug_loc" },
340 { ".debug_loclists", ".zdebug_loclists" },
341 { ".debug_macinfo", ".zdebug_macinfo" },
342 { ".debug_macro", ".zdebug_macro" },
343 { ".debug_str", ".zdebug_str" },
344 { ".debug_str_offsets", ".zdebug_str_offsets" },
345 { ".debug_line_str", ".zdebug_line_str" },
346 { ".debug_ranges", ".zdebug_ranges" },
347 { ".debug_rnglists", ".zdebug_rnglists" },
348 { ".debug_types", ".zdebug_types" },
349 { ".debug_addr", ".zdebug_addr" },
350 { ".debug_frame", ".zdebug_frame" },
351 { ".eh_frame", NULL
},
352 { ".gdb_index", ".zgdb_index" },
353 { ".debug_names", ".zdebug_names" },
354 { ".debug_aranges", ".zdebug_aranges" },
358 /* List of DWO/DWP sections. */
360 static const struct dwop_section_names
362 struct dwarf2_section_names abbrev_dwo
;
363 struct dwarf2_section_names info_dwo
;
364 struct dwarf2_section_names line_dwo
;
365 struct dwarf2_section_names loc_dwo
;
366 struct dwarf2_section_names loclists_dwo
;
367 struct dwarf2_section_names macinfo_dwo
;
368 struct dwarf2_section_names macro_dwo
;
369 struct dwarf2_section_names rnglists_dwo
;
370 struct dwarf2_section_names str_dwo
;
371 struct dwarf2_section_names str_offsets_dwo
;
372 struct dwarf2_section_names types_dwo
;
373 struct dwarf2_section_names cu_index
;
374 struct dwarf2_section_names tu_index
;
378 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
379 { ".debug_info.dwo", ".zdebug_info.dwo" },
380 { ".debug_line.dwo", ".zdebug_line.dwo" },
381 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
382 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
383 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
384 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
385 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
386 { ".debug_str.dwo", ".zdebug_str.dwo" },
387 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
388 { ".debug_types.dwo", ".zdebug_types.dwo" },
389 { ".debug_cu_index", ".zdebug_cu_index" },
390 { ".debug_tu_index", ".zdebug_tu_index" },
393 /* local data types */
395 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
396 begin with a header, which contains the following information. */
397 struct loclists_rnglists_header
399 /* A 4-byte or 12-byte length containing the length of the
400 set of entries for this compilation unit, not including the
401 length field itself. */
404 /* A 2-byte version identifier. */
407 /* A 1-byte unsigned integer containing the size in bytes of an address on
408 the target system. */
409 unsigned char addr_size
;
411 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
412 on the target system. */
413 unsigned char segment_collector_size
;
415 /* A 4-byte count of the number of offsets that follow the header. */
416 unsigned int offset_entry_count
;
419 /* Type used for delaying computation of method physnames.
420 See comments for compute_delayed_physnames. */
421 struct delayed_method_info
423 /* The type to which the method is attached, i.e., its parent class. */
426 /* The index of the method in the type's function fieldlists. */
429 /* The index of the method in the fieldlist. */
432 /* The name of the DIE. */
435 /* The DIE associated with this method. */
436 struct die_info
*die
;
439 /* Internal state when decoding a particular compilation unit. */
442 explicit dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
443 dwarf2_per_objfile
*per_objfile
);
445 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
447 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
448 Create the set of symtabs used by this TU, or if this TU is sharing
449 symtabs with another TU and the symtabs have already been created
450 then restore those symtabs in the line header.
451 We don't need the pc/line-number mapping for type units. */
452 void setup_type_unit_groups (struct die_info
*die
);
454 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
455 buildsym_compunit constructor. */
456 struct compunit_symtab
*start_symtab (const char *name
,
457 const char *comp_dir
,
460 /* Reset the builder. */
461 void reset_builder () { m_builder
.reset (); }
463 /* Return a type that is a generic pointer type, the size of which
464 matches the address size given in the compilation unit header for
466 struct type
*addr_type () const;
468 /* Find an integer type the same size as the address size given in
469 the compilation unit header for this CU. UNSIGNED_P controls if
470 the integer is unsigned or not. */
471 struct type
*addr_sized_int_type (bool unsigned_p
) const;
473 /* The header of the compilation unit. */
474 struct comp_unit_head header
{};
476 /* Base address of this compilation unit. */
477 gdb::optional
<CORE_ADDR
> base_address
;
479 /* The language we are debugging. */
480 enum language language
= language_unknown
;
481 const struct language_defn
*language_defn
= nullptr;
483 const char *producer
= nullptr;
486 /* The symtab builder for this CU. This is only non-NULL when full
487 symbols are being read. */
488 std::unique_ptr
<buildsym_compunit
> m_builder
;
491 /* The generic symbol table building routines have separate lists for
492 file scope symbols and all all other scopes (local scopes). So
493 we need to select the right one to pass to add_symbol_to_list().
494 We do it by keeping a pointer to the correct list in list_in_scope.
496 FIXME: The original dwarf code just treated the file scope as the
497 first local scope, and all other local scopes as nested local
498 scopes, and worked fine. Check to see if we really need to
499 distinguish these in buildsym.c. */
500 struct pending
**list_in_scope
= nullptr;
502 /* Hash table holding all the loaded partial DIEs
503 with partial_die->offset.SECT_OFF as hash. */
504 htab_t partial_dies
= nullptr;
506 /* Storage for things with the same lifetime as this read-in compilation
507 unit, including partial DIEs. */
508 auto_obstack comp_unit_obstack
;
510 /* Backlink to our per_cu entry. */
511 struct dwarf2_per_cu_data
*per_cu
;
513 /* The dwarf2_per_objfile that owns this. */
514 dwarf2_per_objfile
*per_objfile
;
516 /* How many compilation units ago was this CU last referenced? */
519 /* A hash table of DIE cu_offset for following references with
520 die_info->offset.sect_off as hash. */
521 htab_t die_hash
= nullptr;
523 /* Full DIEs if read in. */
524 struct die_info
*dies
= nullptr;
526 /* A set of pointers to dwarf2_per_cu_data objects for compilation
527 units referenced by this one. Only set during full symbol processing;
528 partial symbol tables do not have dependencies. */
529 htab_t dependencies
= nullptr;
531 /* Header data from the line table, during full symbol processing. */
532 struct line_header
*line_header
= nullptr;
533 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
534 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
535 this is the DW_TAG_compile_unit die for this CU. We'll hold on
536 to the line header as long as this DIE is being processed. See
537 process_die_scope. */
538 die_info
*line_header_die_owner
= nullptr;
540 /* A list of methods which need to have physnames computed
541 after all type information has been read. */
542 std::vector
<delayed_method_info
> method_list
;
544 /* To be copied to symtab->call_site_htab. */
545 htab_t call_site_htab
= nullptr;
547 /* Non-NULL if this CU came from a DWO file.
548 There is an invariant here that is important to remember:
549 Except for attributes copied from the top level DIE in the "main"
550 (or "stub") file in preparation for reading the DWO file
551 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
552 Either there isn't a DWO file (in which case this is NULL and the point
553 is moot), or there is and either we're not going to read it (in which
554 case this is NULL) or there is and we are reading it (in which case this
556 struct dwo_unit
*dwo_unit
= nullptr;
558 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
559 Note this value comes from the Fission stub CU/TU's DIE. */
560 gdb::optional
<ULONGEST
> addr_base
;
562 /* The DW_AT_rnglists_base attribute if present.
563 Note this value comes from the Fission stub CU/TU's DIE.
564 Also note that the value is zero in the non-DWO case so this value can
565 be used without needing to know whether DWO files are in use or not.
566 N.B. This does not apply to DW_AT_ranges appearing in
567 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
568 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
569 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
570 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
571 ULONGEST ranges_base
= 0;
573 /* The DW_AT_loclists_base attribute if present. */
574 ULONGEST loclist_base
= 0;
576 /* When reading debug info generated by older versions of rustc, we
577 have to rewrite some union types to be struct types with a
578 variant part. This rewriting must be done after the CU is fully
579 read in, because otherwise at the point of rewriting some struct
580 type might not have been fully processed. So, we keep a list of
581 all such types here and process them after expansion. */
582 std::vector
<struct type
*> rust_unions
;
584 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
585 files, the value is implicitly zero. For DWARF 5 version DWO files, the
586 value is often implicit and is the size of the header of
587 .debug_str_offsets section (8 or 4, depending on the address size). */
588 gdb::optional
<ULONGEST
> str_offsets_base
;
590 /* Mark used when releasing cached dies. */
593 /* This CU references .debug_loc. See the symtab->locations_valid field.
594 This test is imperfect as there may exist optimized debug code not using
595 any location list and still facing inlining issues if handled as
596 unoptimized code. For a future better test see GCC PR other/32998. */
597 bool has_loclist
: 1;
599 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
600 if all the producer_is_* fields are valid. This information is cached
601 because profiling CU expansion showed excessive time spent in
602 producer_is_gxx_lt_4_6. */
603 bool checked_producer
: 1;
604 bool producer_is_gxx_lt_4_6
: 1;
605 bool producer_is_gcc_lt_4_3
: 1;
606 bool producer_is_icc
: 1;
607 bool producer_is_icc_lt_14
: 1;
608 bool producer_is_codewarrior
: 1;
610 /* When true, the file that we're processing is known to have
611 debugging info for C++ namespaces. GCC 3.3.x did not produce
612 this information, but later versions do. */
614 bool processing_has_namespace_info
: 1;
616 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
618 /* If this CU was inherited by another CU (via specification,
619 abstract_origin, etc), this is the ancestor CU. */
622 /* Get the buildsym_compunit for this CU. */
623 buildsym_compunit
*get_builder ()
625 /* If this CU has a builder associated with it, use that. */
626 if (m_builder
!= nullptr)
627 return m_builder
.get ();
629 /* Otherwise, search ancestors for a valid builder. */
630 if (ancestor
!= nullptr)
631 return ancestor
->get_builder ();
637 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
638 This includes type_unit_group and quick_file_names. */
640 struct stmt_list_hash
642 /* The DWO unit this table is from or NULL if there is none. */
643 struct dwo_unit
*dwo_unit
;
645 /* Offset in .debug_line or .debug_line.dwo. */
646 sect_offset line_sect_off
;
649 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
650 an object of this type. This contains elements of type unit groups
651 that can be shared across objfiles. The non-shareable parts are in
652 type_unit_group_unshareable. */
654 struct type_unit_group
656 /* dwarf2read.c's main "handle" on a TU symtab.
657 To simplify things we create an artificial CU that "includes" all the
658 type units using this stmt_list so that the rest of the code still has
659 a "per_cu" handle on the symtab. */
660 struct dwarf2_per_cu_data per_cu
;
662 /* The TUs that share this DW_AT_stmt_list entry.
663 This is added to while parsing type units to build partial symtabs,
664 and is deleted afterwards and not used again. */
665 std::vector
<signatured_type
*> *tus
;
667 /* The data used to construct the hash key. */
668 struct stmt_list_hash hash
;
671 /* These sections are what may appear in a (real or virtual) DWO file. */
675 struct dwarf2_section_info abbrev
;
676 struct dwarf2_section_info line
;
677 struct dwarf2_section_info loc
;
678 struct dwarf2_section_info loclists
;
679 struct dwarf2_section_info macinfo
;
680 struct dwarf2_section_info macro
;
681 struct dwarf2_section_info rnglists
;
682 struct dwarf2_section_info str
;
683 struct dwarf2_section_info str_offsets
;
684 /* In the case of a virtual DWO file, these two are unused. */
685 struct dwarf2_section_info info
;
686 std::vector
<dwarf2_section_info
> types
;
689 /* CUs/TUs in DWP/DWO files. */
693 /* Backlink to the containing struct dwo_file. */
694 struct dwo_file
*dwo_file
;
696 /* The "id" that distinguishes this CU/TU.
697 .debug_info calls this "dwo_id", .debug_types calls this "signature".
698 Since signatures came first, we stick with it for consistency. */
701 /* The section this CU/TU lives in, in the DWO file. */
702 struct dwarf2_section_info
*section
;
704 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
705 sect_offset sect_off
;
708 /* For types, offset in the type's DIE of the type defined by this TU. */
709 cu_offset type_offset_in_tu
;
712 /* include/dwarf2.h defines the DWP section codes.
713 It defines a max value but it doesn't define a min value, which we
714 use for error checking, so provide one. */
716 enum dwp_v2_section_ids
721 /* Data for one DWO file.
723 This includes virtual DWO files (a virtual DWO file is a DWO file as it
724 appears in a DWP file). DWP files don't really have DWO files per se -
725 comdat folding of types "loses" the DWO file they came from, and from
726 a high level view DWP files appear to contain a mass of random types.
727 However, to maintain consistency with the non-DWP case we pretend DWP
728 files contain virtual DWO files, and we assign each TU with one virtual
729 DWO file (generally based on the line and abbrev section offsets -
730 a heuristic that seems to work in practice). */
734 dwo_file () = default;
735 DISABLE_COPY_AND_ASSIGN (dwo_file
);
737 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
738 For virtual DWO files the name is constructed from the section offsets
739 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
740 from related CU+TUs. */
741 const char *dwo_name
= nullptr;
743 /* The DW_AT_comp_dir attribute. */
744 const char *comp_dir
= nullptr;
746 /* The bfd, when the file is open. Otherwise this is NULL.
747 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
748 gdb_bfd_ref_ptr dbfd
;
750 /* The sections that make up this DWO file.
751 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
752 sections (for lack of a better name). */
753 struct dwo_sections sections
{};
755 /* The CUs in the file.
756 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
757 an extension to handle LLVM's Link Time Optimization output (where
758 multiple source files may be compiled into a single object/dwo pair). */
761 /* Table of TUs in the file.
762 Each element is a struct dwo_unit. */
766 /* These sections are what may appear in a DWP file. */
770 /* These are used by all DWP versions (1, 2 and 5). */
771 struct dwarf2_section_info str
;
772 struct dwarf2_section_info cu_index
;
773 struct dwarf2_section_info tu_index
;
775 /* These are only used by DWP version 2 and version 5 files.
776 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
777 sections are referenced by section number, and are not recorded here.
778 In DWP version 2 or 5 there is at most one copy of all these sections,
779 each section being (effectively) comprised of the concatenation of all of
780 the individual sections that exist in the version 1 format.
781 To keep the code simple we treat each of these concatenated pieces as a
782 section itself (a virtual section?). */
783 struct dwarf2_section_info abbrev
;
784 struct dwarf2_section_info info
;
785 struct dwarf2_section_info line
;
786 struct dwarf2_section_info loc
;
787 struct dwarf2_section_info loclists
;
788 struct dwarf2_section_info macinfo
;
789 struct dwarf2_section_info macro
;
790 struct dwarf2_section_info rnglists
;
791 struct dwarf2_section_info str_offsets
;
792 struct dwarf2_section_info types
;
795 /* These sections are what may appear in a virtual DWO file in DWP version 1.
796 A virtual DWO file is a DWO file as it appears in a DWP file. */
798 struct virtual_v1_dwo_sections
800 struct dwarf2_section_info abbrev
;
801 struct dwarf2_section_info line
;
802 struct dwarf2_section_info loc
;
803 struct dwarf2_section_info macinfo
;
804 struct dwarf2_section_info macro
;
805 struct dwarf2_section_info str_offsets
;
806 /* Each DWP hash table entry records one CU or one TU.
807 That is recorded here, and copied to dwo_unit.section. */
808 struct dwarf2_section_info info_or_types
;
811 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
812 In version 2, the sections of the DWO files are concatenated together
813 and stored in one section of that name. Thus each ELF section contains
814 several "virtual" sections. */
816 struct virtual_v2_or_v5_dwo_sections
818 bfd_size_type abbrev_offset
;
819 bfd_size_type abbrev_size
;
821 bfd_size_type line_offset
;
822 bfd_size_type line_size
;
824 bfd_size_type loc_offset
;
825 bfd_size_type loc_size
;
827 bfd_size_type loclists_offset
;
828 bfd_size_type loclists_size
;
830 bfd_size_type macinfo_offset
;
831 bfd_size_type macinfo_size
;
833 bfd_size_type macro_offset
;
834 bfd_size_type macro_size
;
836 bfd_size_type rnglists_offset
;
837 bfd_size_type rnglists_size
;
839 bfd_size_type str_offsets_offset
;
840 bfd_size_type str_offsets_size
;
842 /* Each DWP hash table entry records one CU or one TU.
843 That is recorded here, and copied to dwo_unit.section. */
844 bfd_size_type info_or_types_offset
;
845 bfd_size_type info_or_types_size
;
848 /* Contents of DWP hash tables. */
850 struct dwp_hash_table
852 uint32_t version
, nr_columns
;
853 uint32_t nr_units
, nr_slots
;
854 const gdb_byte
*hash_table
, *unit_table
;
859 const gdb_byte
*indices
;
863 /* This is indexed by column number and gives the id of the section
865 #define MAX_NR_V2_DWO_SECTIONS \
866 (1 /* .debug_info or .debug_types */ \
867 + 1 /* .debug_abbrev */ \
868 + 1 /* .debug_line */ \
869 + 1 /* .debug_loc */ \
870 + 1 /* .debug_str_offsets */ \
871 + 1 /* .debug_macro or .debug_macinfo */)
872 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
873 const gdb_byte
*offsets
;
874 const gdb_byte
*sizes
;
878 /* This is indexed by column number and gives the id of the section
880 #define MAX_NR_V5_DWO_SECTIONS \
881 (1 /* .debug_info */ \
882 + 1 /* .debug_abbrev */ \
883 + 1 /* .debug_line */ \
884 + 1 /* .debug_loclists */ \
885 + 1 /* .debug_str_offsets */ \
886 + 1 /* .debug_macro */ \
887 + 1 /* .debug_rnglists */)
888 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
889 const gdb_byte
*offsets
;
890 const gdb_byte
*sizes
;
895 /* Data for one DWP file. */
899 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
901 dbfd (std::move (abfd
))
905 /* Name of the file. */
908 /* File format version. */
912 gdb_bfd_ref_ptr dbfd
;
914 /* Section info for this file. */
915 struct dwp_sections sections
{};
917 /* Table of CUs in the file. */
918 const struct dwp_hash_table
*cus
= nullptr;
920 /* Table of TUs in the file. */
921 const struct dwp_hash_table
*tus
= nullptr;
923 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
927 /* Table to map ELF section numbers to their sections.
928 This is only needed for the DWP V1 file format. */
929 unsigned int num_sections
= 0;
930 asection
**elf_sections
= nullptr;
933 /* Struct used to pass misc. parameters to read_die_and_children, et
934 al. which are used for both .debug_info and .debug_types dies.
935 All parameters here are unchanging for the life of the call. This
936 struct exists to abstract away the constant parameters of die reading. */
938 struct die_reader_specs
940 /* The bfd of die_section. */
943 /* The CU of the DIE we are parsing. */
944 struct dwarf2_cu
*cu
;
946 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
947 struct dwo_file
*dwo_file
;
949 /* The section the die comes from.
950 This is either .debug_info or .debug_types, or the .dwo variants. */
951 struct dwarf2_section_info
*die_section
;
953 /* die_section->buffer. */
954 const gdb_byte
*buffer
;
956 /* The end of the buffer. */
957 const gdb_byte
*buffer_end
;
959 /* The abbreviation table to use when reading the DIEs. */
960 struct abbrev_table
*abbrev_table
;
963 /* A subclass of die_reader_specs that holds storage and has complex
964 constructor and destructor behavior. */
966 class cutu_reader
: public die_reader_specs
970 cutu_reader (dwarf2_per_cu_data
*this_cu
,
971 dwarf2_per_objfile
*per_objfile
,
972 struct abbrev_table
*abbrev_table
,
973 dwarf2_cu
*existing_cu
,
976 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
977 dwarf2_per_objfile
*per_objfile
,
978 struct dwarf2_cu
*parent_cu
= nullptr,
979 struct dwo_file
*dwo_file
= nullptr);
981 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
983 const gdb_byte
*info_ptr
= nullptr;
984 struct die_info
*comp_unit_die
= nullptr;
985 bool dummy_p
= false;
987 /* Release the new CU, putting it on the chain. This cannot be done
992 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
993 dwarf2_per_objfile
*per_objfile
,
994 dwarf2_cu
*existing_cu
);
996 struct dwarf2_per_cu_data
*m_this_cu
;
997 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
999 /* The ordinary abbreviation table. */
1000 abbrev_table_up m_abbrev_table_holder
;
1002 /* The DWO abbreviation table. */
1003 abbrev_table_up m_dwo_abbrev_table
;
1006 /* When we construct a partial symbol table entry we only
1007 need this much information. */
1008 struct partial_die_info
: public allocate_on_obstack
1010 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1012 /* Disable assign but still keep copy ctor, which is needed
1013 load_partial_dies. */
1014 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1016 /* Adjust the partial die before generating a symbol for it. This
1017 function may set the is_external flag or change the DIE's
1019 void fixup (struct dwarf2_cu
*cu
);
1021 /* Read a minimal amount of information into the minimal die
1023 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1024 const struct abbrev_info
&abbrev
,
1025 const gdb_byte
*info_ptr
);
1027 /* Compute the name of this partial DIE. This memoizes the
1028 result, so it is safe to call multiple times. */
1029 const char *name (dwarf2_cu
*cu
);
1031 /* Offset of this DIE. */
1032 const sect_offset sect_off
;
1034 /* DWARF-2 tag for this DIE. */
1035 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1037 /* Assorted flags describing the data found in this DIE. */
1038 const unsigned int has_children
: 1;
1040 unsigned int is_external
: 1;
1041 unsigned int is_declaration
: 1;
1042 unsigned int has_type
: 1;
1043 unsigned int has_specification
: 1;
1044 unsigned int has_pc_info
: 1;
1045 unsigned int may_be_inlined
: 1;
1047 /* This DIE has been marked DW_AT_main_subprogram. */
1048 unsigned int main_subprogram
: 1;
1050 /* Flag set if the SCOPE field of this structure has been
1052 unsigned int scope_set
: 1;
1054 /* Flag set if the DIE has a byte_size attribute. */
1055 unsigned int has_byte_size
: 1;
1057 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1058 unsigned int has_const_value
: 1;
1060 /* Flag set if any of the DIE's children are template arguments. */
1061 unsigned int has_template_arguments
: 1;
1063 /* Flag set if fixup has been called on this die. */
1064 unsigned int fixup_called
: 1;
1066 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1067 unsigned int is_dwz
: 1;
1069 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1070 unsigned int spec_is_dwz
: 1;
1072 unsigned int canonical_name
: 1;
1074 /* The name of this DIE. Normally the value of DW_AT_name, but
1075 sometimes a default name for unnamed DIEs. */
1076 const char *raw_name
= nullptr;
1078 /* The linkage name, if present. */
1079 const char *linkage_name
= nullptr;
1081 /* The scope to prepend to our children. This is generally
1082 allocated on the comp_unit_obstack, so will disappear
1083 when this compilation unit leaves the cache. */
1084 const char *scope
= nullptr;
1086 /* Some data associated with the partial DIE. The tag determines
1087 which field is live. */
1090 /* The location description associated with this DIE, if any. */
1091 struct dwarf_block
*locdesc
;
1092 /* The offset of an import, for DW_TAG_imported_unit. */
1093 sect_offset sect_off
;
1096 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1097 CORE_ADDR lowpc
= 0;
1098 CORE_ADDR highpc
= 0;
1100 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1101 DW_AT_sibling, if any. */
1102 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1103 could return DW_AT_sibling values to its caller load_partial_dies. */
1104 const gdb_byte
*sibling
= nullptr;
1106 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1107 DW_AT_specification (or DW_AT_abstract_origin or
1108 DW_AT_extension). */
1109 sect_offset spec_offset
{};
1111 /* Pointers to this DIE's parent, first child, and next sibling,
1113 struct partial_die_info
*die_parent
= nullptr;
1114 struct partial_die_info
*die_child
= nullptr;
1115 struct partial_die_info
*die_sibling
= nullptr;
1117 friend struct partial_die_info
*
1118 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1121 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1122 partial_die_info (sect_offset sect_off
)
1123 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1127 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1129 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1134 has_specification
= 0;
1137 main_subprogram
= 0;
1140 has_const_value
= 0;
1141 has_template_arguments
= 0;
1149 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1150 but this would require a corresponding change in unpack_field_as_long
1152 static int bits_per_byte
= 8;
1154 struct variant_part_builder
;
1156 /* When reading a variant, we track a bit more information about the
1157 field, and store it in an object of this type. */
1159 struct variant_field
1161 int first_field
= -1;
1162 int last_field
= -1;
1164 /* A variant can contain other variant parts. */
1165 std::vector
<variant_part_builder
> variant_parts
;
1167 /* If we see a DW_TAG_variant, then this will be set if this is the
1169 bool default_branch
= false;
1170 /* If we see a DW_AT_discr_value, then this will be the discriminant
1172 ULONGEST discriminant_value
= 0;
1173 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1175 struct dwarf_block
*discr_list_data
= nullptr;
1178 /* This represents a DW_TAG_variant_part. */
1180 struct variant_part_builder
1182 /* The offset of the discriminant field. */
1183 sect_offset discriminant_offset
{};
1185 /* Variants that are direct children of this variant part. */
1186 std::vector
<variant_field
> variants
;
1188 /* True if we're currently reading a variant. */
1189 bool processing_variant
= false;
1194 int accessibility
= 0;
1196 /* Variant parts need to find the discriminant, which is a DIE
1197 reference. We track the section offset of each field to make
1200 struct field field
{};
1205 const char *name
= nullptr;
1206 std::vector
<struct fn_field
> fnfields
;
1209 /* The routines that read and process dies for a C struct or C++ class
1210 pass lists of data member fields and lists of member function fields
1211 in an instance of a field_info structure, as defined below. */
1214 /* List of data member and baseclasses fields. */
1215 std::vector
<struct nextfield
> fields
;
1216 std::vector
<struct nextfield
> baseclasses
;
1218 /* Set if the accessibility of one of the fields is not public. */
1219 bool non_public_fields
= false;
1221 /* Member function fieldlist array, contains name of possibly overloaded
1222 member function, number of overloaded member functions and a pointer
1223 to the head of the member function field chain. */
1224 std::vector
<struct fnfieldlist
> fnfieldlists
;
1226 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1227 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1228 std::vector
<struct decl_field
> typedef_field_list
;
1230 /* Nested types defined by this class and the number of elements in this
1232 std::vector
<struct decl_field
> nested_types_list
;
1234 /* If non-null, this is the variant part we are currently
1236 variant_part_builder
*current_variant_part
= nullptr;
1237 /* This holds all the top-level variant parts attached to the type
1239 std::vector
<variant_part_builder
> variant_parts
;
1241 /* Return the total number of fields (including baseclasses). */
1242 int nfields () const
1244 return fields
.size () + baseclasses
.size ();
1248 /* Loaded secondary compilation units are kept in memory until they
1249 have not been referenced for the processing of this many
1250 compilation units. Set this to zero to disable caching. Cache
1251 sizes of up to at least twenty will improve startup time for
1252 typical inter-CU-reference binaries, at an obvious memory cost. */
1253 static int dwarf_max_cache_age
= 5;
1255 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1256 struct cmd_list_element
*c
, const char *value
)
1258 fprintf_filtered (file
, _("The upper bound on the age of cached "
1259 "DWARF compilation units is %s.\n"),
1263 /* local function prototypes */
1265 static void dwarf2_find_base_address (struct die_info
*die
,
1266 struct dwarf2_cu
*cu
);
1268 static dwarf2_psymtab
*create_partial_symtab
1269 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1272 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1273 const gdb_byte
*info_ptr
,
1274 struct die_info
*type_unit_die
);
1276 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1278 static void scan_partial_symbols (struct partial_die_info
*,
1279 CORE_ADDR
*, CORE_ADDR
*,
1280 int, struct dwarf2_cu
*);
1282 static void add_partial_symbol (struct partial_die_info
*,
1283 struct dwarf2_cu
*);
1285 static void add_partial_namespace (struct partial_die_info
*pdi
,
1286 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1287 int set_addrmap
, struct dwarf2_cu
*cu
);
1289 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1290 CORE_ADDR
*highpc
, int set_addrmap
,
1291 struct dwarf2_cu
*cu
);
1293 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1294 struct dwarf2_cu
*cu
);
1296 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1297 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1298 int need_pc
, struct dwarf2_cu
*cu
);
1300 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1302 static struct partial_die_info
*load_partial_dies
1303 (const struct die_reader_specs
*, const gdb_byte
*, int);
1305 /* A pair of partial_die_info and compilation unit. */
1306 struct cu_partial_die_info
1308 /* The compilation unit of the partial_die_info. */
1309 struct dwarf2_cu
*cu
;
1310 /* A partial_die_info. */
1311 struct partial_die_info
*pdi
;
1313 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1319 cu_partial_die_info () = delete;
1322 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1323 struct dwarf2_cu
*);
1325 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1326 struct attribute
*, struct attr_abbrev
*,
1329 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1330 struct attribute
*attr
, dwarf_tag tag
);
1332 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1334 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1335 dwarf2_section_info
*, sect_offset
);
1337 static const char *read_indirect_string
1338 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1339 const struct comp_unit_head
*, unsigned int *);
1341 static const char *read_indirect_string_at_offset
1342 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1344 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1348 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1349 ULONGEST str_index
);
1351 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1352 ULONGEST str_index
);
1354 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1356 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1357 struct dwarf2_cu
*);
1359 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1360 struct dwarf2_cu
*cu
);
1362 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1364 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1365 struct dwarf2_cu
*cu
);
1367 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1369 static struct die_info
*die_specification (struct die_info
*die
,
1370 struct dwarf2_cu
**);
1372 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1373 struct dwarf2_cu
*cu
);
1375 static void dwarf_decode_lines (struct line_header
*, const char *,
1376 struct dwarf2_cu
*, dwarf2_psymtab
*,
1377 CORE_ADDR
, int decode_mapping
);
1379 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1382 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1383 struct dwarf2_cu
*, struct symbol
* = NULL
);
1385 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1386 struct dwarf2_cu
*);
1388 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1391 struct obstack
*obstack
,
1392 struct dwarf2_cu
*cu
, LONGEST
*value
,
1393 const gdb_byte
**bytes
,
1394 struct dwarf2_locexpr_baton
**baton
);
1396 static struct type
*read_subrange_index_type (struct die_info
*die
,
1397 struct dwarf2_cu
*cu
);
1399 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1401 static int need_gnat_info (struct dwarf2_cu
*);
1403 static struct type
*die_descriptive_type (struct die_info
*,
1404 struct dwarf2_cu
*);
1406 static void set_descriptive_type (struct type
*, struct die_info
*,
1407 struct dwarf2_cu
*);
1409 static struct type
*die_containing_type (struct die_info
*,
1410 struct dwarf2_cu
*);
1412 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1413 struct dwarf2_cu
*);
1415 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1417 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1419 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1421 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1422 const char *suffix
, int physname
,
1423 struct dwarf2_cu
*cu
);
1425 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1427 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1429 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1431 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1433 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1435 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1437 /* Return the .debug_loclists section to use for cu. */
1438 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1440 /* Return the .debug_rnglists section to use for cu. */
1441 static struct dwarf2_section_info
*cu_debug_rnglists_section
1442 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1444 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1445 values. Keep the items ordered with increasing constraints compliance. */
1448 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1449 PC_BOUNDS_NOT_PRESENT
,
1451 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1452 were present but they do not form a valid range of PC addresses. */
1455 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1458 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1462 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1463 CORE_ADDR
*, CORE_ADDR
*,
1467 static void get_scope_pc_bounds (struct die_info
*,
1468 CORE_ADDR
*, CORE_ADDR
*,
1469 struct dwarf2_cu
*);
1471 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1472 CORE_ADDR
, struct dwarf2_cu
*);
1474 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1475 struct dwarf2_cu
*);
1477 static void dwarf2_attach_fields_to_type (struct field_info
*,
1478 struct type
*, struct dwarf2_cu
*);
1480 static void dwarf2_add_member_fn (struct field_info
*,
1481 struct die_info
*, struct type
*,
1482 struct dwarf2_cu
*);
1484 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1486 struct dwarf2_cu
*);
1488 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1490 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1492 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1494 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1496 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1498 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1500 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1502 static struct type
*read_module_type (struct die_info
*die
,
1503 struct dwarf2_cu
*cu
);
1505 static const char *namespace_name (struct die_info
*die
,
1506 int *is_anonymous
, struct dwarf2_cu
*);
1508 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1510 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1513 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1514 struct dwarf2_cu
*);
1516 static struct die_info
*read_die_and_siblings_1
1517 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1520 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1521 const gdb_byte
*info_ptr
,
1522 const gdb_byte
**new_info_ptr
,
1523 struct die_info
*parent
);
1525 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1526 struct die_info
**, const gdb_byte
*,
1529 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1530 struct die_info
**, const gdb_byte
*);
1532 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1534 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1537 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1539 static const char *dwarf2_full_name (const char *name
,
1540 struct die_info
*die
,
1541 struct dwarf2_cu
*cu
);
1543 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1544 struct dwarf2_cu
*cu
);
1546 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1547 struct dwarf2_cu
**);
1549 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1551 static void dump_die_for_error (struct die_info
*);
1553 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1556 /*static*/ void dump_die (struct die_info
*, int max_level
);
1558 static void store_in_ref_table (struct die_info
*,
1559 struct dwarf2_cu
*);
1561 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1562 const struct attribute
*,
1563 struct dwarf2_cu
**);
1565 static struct die_info
*follow_die_ref (struct die_info
*,
1566 const struct attribute
*,
1567 struct dwarf2_cu
**);
1569 static struct die_info
*follow_die_sig (struct die_info
*,
1570 const struct attribute
*,
1571 struct dwarf2_cu
**);
1573 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1574 struct dwarf2_cu
*);
1576 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1577 const struct attribute
*,
1578 struct dwarf2_cu
*);
1580 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1581 dwarf2_per_objfile
*per_objfile
);
1583 static void read_signatured_type (signatured_type
*sig_type
,
1584 dwarf2_per_objfile
*per_objfile
);
1586 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1587 struct die_info
*die
, struct dwarf2_cu
*cu
,
1588 struct dynamic_prop
*prop
, struct type
*type
);
1590 /* memory allocation interface */
1592 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1594 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1596 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1598 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1599 struct dwarf2_loclist_baton
*baton
,
1600 const struct attribute
*attr
);
1602 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1604 struct dwarf2_cu
*cu
,
1607 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1608 const gdb_byte
*info_ptr
,
1609 struct abbrev_info
*abbrev
);
1611 static hashval_t
partial_die_hash (const void *item
);
1613 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1615 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1616 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1617 dwarf2_per_objfile
*per_objfile
);
1619 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1620 struct die_info
*comp_unit_die
,
1621 enum language pretend_language
);
1623 static struct type
*set_die_type (struct die_info
*, struct type
*,
1624 struct dwarf2_cu
*, bool = false);
1626 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1628 static int create_all_type_units (dwarf2_per_objfile
*per_objfile
);
1630 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1631 dwarf2_per_objfile
*per_objfile
,
1632 dwarf2_cu
*existing_cu
,
1634 enum language pretend_language
);
1636 static void process_full_comp_unit (dwarf2_cu
*cu
,
1637 enum language pretend_language
);
1639 static void process_full_type_unit (dwarf2_cu
*cu
,
1640 enum language pretend_language
);
1642 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1643 struct dwarf2_per_cu_data
*);
1645 static void dwarf2_mark (struct dwarf2_cu
*);
1647 static struct type
*get_die_type_at_offset (sect_offset
,
1648 dwarf2_per_cu_data
*per_cu
,
1649 dwarf2_per_objfile
*per_objfile
);
1651 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1653 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1654 dwarf2_per_objfile
*per_objfile
,
1655 enum language pretend_language
);
1657 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1659 /* Class, the destructor of which frees all allocated queue entries. This
1660 will only have work to do if an error was thrown while processing the
1661 dwarf. If no error was thrown then the queue entries should have all
1662 been processed, and freed, as we went along. */
1664 class dwarf2_queue_guard
1667 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1668 : m_per_objfile (per_objfile
)
1672 /* Free any entries remaining on the queue. There should only be
1673 entries left if we hit an error while processing the dwarf. */
1674 ~dwarf2_queue_guard ()
1676 /* Ensure that no memory is allocated by the queue. */
1677 std::queue
<dwarf2_queue_item
> empty
;
1678 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1681 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1684 dwarf2_per_objfile
*m_per_objfile
;
1687 dwarf2_queue_item::~dwarf2_queue_item ()
1689 /* Anything still marked queued is likely to be in an
1690 inconsistent state, so discard it. */
1693 per_objfile
->remove_cu (per_cu
);
1698 /* The return type of find_file_and_directory. Note, the enclosed
1699 string pointers are only valid while this object is valid. */
1701 struct file_and_directory
1703 /* The filename. This is never NULL. */
1706 /* The compilation directory. NULL if not known. If we needed to
1707 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1708 points directly to the DW_AT_comp_dir string attribute owned by
1709 the obstack that owns the DIE. */
1710 const char *comp_dir
;
1712 /* If we needed to build a new string for comp_dir, this is what
1713 owns the storage. */
1714 std::string comp_dir_storage
;
1717 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1718 struct dwarf2_cu
*cu
);
1720 static htab_up
allocate_signatured_type_table ();
1722 static htab_up
allocate_dwo_unit_table ();
1724 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1725 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1726 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1728 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1730 static struct dwo_unit
*lookup_dwo_comp_unit
1731 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1732 ULONGEST signature
);
1734 static struct dwo_unit
*lookup_dwo_type_unit
1735 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1737 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1739 /* A unique pointer to a dwo_file. */
1741 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1743 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1745 static void check_producer (struct dwarf2_cu
*cu
);
1747 static void free_line_header_voidp (void *arg
);
1749 /* Various complaints about symbol reading that don't abort the process. */
1752 dwarf2_debug_line_missing_file_complaint (void)
1754 complaint (_(".debug_line section has line data without a file"));
1758 dwarf2_debug_line_missing_end_sequence_complaint (void)
1760 complaint (_(".debug_line section has line "
1761 "program sequence without an end"));
1765 dwarf2_complex_location_expr_complaint (void)
1767 complaint (_("location expression too complex"));
1771 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1774 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1779 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1781 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1785 /* Hash function for line_header_hash. */
1788 line_header_hash (const struct line_header
*ofs
)
1790 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1793 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1796 line_header_hash_voidp (const void *item
)
1798 const struct line_header
*ofs
= (const struct line_header
*) item
;
1800 return line_header_hash (ofs
);
1803 /* Equality function for line_header_hash. */
1806 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1808 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1809 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1811 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1812 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1817 /* See declaration. */
1819 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1822 can_copy (can_copy_
)
1825 names
= &dwarf2_elf_names
;
1827 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1828 locate_sections (obfd
, sec
, *names
);
1831 dwarf2_per_bfd::~dwarf2_per_bfd ()
1833 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1834 per_cu
->imported_symtabs_free ();
1836 for (signatured_type
*sig_type
: all_type_units
)
1837 sig_type
->per_cu
.imported_symtabs_free ();
1839 /* Everything else should be on this->obstack. */
1845 dwarf2_per_objfile::remove_all_cus ()
1847 for (auto pair
: m_dwarf2_cus
)
1850 m_dwarf2_cus
.clear ();
1853 /* A helper class that calls free_cached_comp_units on
1856 class free_cached_comp_units
1860 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1861 : m_per_objfile (per_objfile
)
1865 ~free_cached_comp_units ()
1867 m_per_objfile
->remove_all_cus ();
1870 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1874 dwarf2_per_objfile
*m_per_objfile
;
1880 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1882 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1884 return this->m_symtabs
[per_cu
->index
] != nullptr;
1890 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1892 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1894 return this->m_symtabs
[per_cu
->index
];
1900 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1901 compunit_symtab
*symtab
)
1903 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1904 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1906 this->m_symtabs
[per_cu
->index
] = symtab
;
1909 /* Try to locate the sections we need for DWARF 2 debugging
1910 information and return true if we have enough to do something.
1911 NAMES points to the dwarf2 section names, or is NULL if the standard
1912 ELF names are used. CAN_COPY is true for formats where symbol
1913 interposition is possible and so symbol values must follow copy
1914 relocation rules. */
1917 dwarf2_has_info (struct objfile
*objfile
,
1918 const struct dwarf2_debug_sections
*names
,
1921 if (objfile
->flags
& OBJF_READNEVER
)
1924 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1926 if (per_objfile
== NULL
)
1928 dwarf2_per_bfd
*per_bfd
;
1930 /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
1931 doesn't require relocations and if there aren't partial symbols
1932 from some other reader. */
1933 if (!objfile_has_partial_symbols (objfile
)
1934 && !gdb_bfd_requires_relocations (objfile
->obfd
))
1936 /* See if one has been created for this BFD yet. */
1937 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1939 if (per_bfd
== nullptr)
1941 /* No, create it now. */
1942 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1943 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1948 /* No sharing possible, create one specifically for this objfile. */
1949 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1950 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1953 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1956 return (!per_objfile
->per_bfd
->info
.is_virtual
1957 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1958 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1959 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1962 /* When loading sections, we look either for uncompressed section or for
1963 compressed section names. */
1966 section_is_p (const char *section_name
,
1967 const struct dwarf2_section_names
*names
)
1969 if (names
->normal
!= NULL
1970 && strcmp (section_name
, names
->normal
) == 0)
1972 if (names
->compressed
!= NULL
1973 && strcmp (section_name
, names
->compressed
) == 0)
1978 /* See declaration. */
1981 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1982 const dwarf2_debug_sections
&names
)
1984 flagword aflag
= bfd_section_flags (sectp
);
1986 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1989 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1990 > bfd_get_file_size (abfd
))
1992 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1993 warning (_("Discarding section %s which has a section size (%s"
1994 ") larger than the file size [in module %s]"),
1995 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1996 bfd_get_filename (abfd
));
1998 else if (section_is_p (sectp
->name
, &names
.info
))
2000 this->info
.s
.section
= sectp
;
2001 this->info
.size
= bfd_section_size (sectp
);
2003 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2005 this->abbrev
.s
.section
= sectp
;
2006 this->abbrev
.size
= bfd_section_size (sectp
);
2008 else if (section_is_p (sectp
->name
, &names
.line
))
2010 this->line
.s
.section
= sectp
;
2011 this->line
.size
= bfd_section_size (sectp
);
2013 else if (section_is_p (sectp
->name
, &names
.loc
))
2015 this->loc
.s
.section
= sectp
;
2016 this->loc
.size
= bfd_section_size (sectp
);
2018 else if (section_is_p (sectp
->name
, &names
.loclists
))
2020 this->loclists
.s
.section
= sectp
;
2021 this->loclists
.size
= bfd_section_size (sectp
);
2023 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2025 this->macinfo
.s
.section
= sectp
;
2026 this->macinfo
.size
= bfd_section_size (sectp
);
2028 else if (section_is_p (sectp
->name
, &names
.macro
))
2030 this->macro
.s
.section
= sectp
;
2031 this->macro
.size
= bfd_section_size (sectp
);
2033 else if (section_is_p (sectp
->name
, &names
.str
))
2035 this->str
.s
.section
= sectp
;
2036 this->str
.size
= bfd_section_size (sectp
);
2038 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
2040 this->str_offsets
.s
.section
= sectp
;
2041 this->str_offsets
.size
= bfd_section_size (sectp
);
2043 else if (section_is_p (sectp
->name
, &names
.line_str
))
2045 this->line_str
.s
.section
= sectp
;
2046 this->line_str
.size
= bfd_section_size (sectp
);
2048 else if (section_is_p (sectp
->name
, &names
.addr
))
2050 this->addr
.s
.section
= sectp
;
2051 this->addr
.size
= bfd_section_size (sectp
);
2053 else if (section_is_p (sectp
->name
, &names
.frame
))
2055 this->frame
.s
.section
= sectp
;
2056 this->frame
.size
= bfd_section_size (sectp
);
2058 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2060 this->eh_frame
.s
.section
= sectp
;
2061 this->eh_frame
.size
= bfd_section_size (sectp
);
2063 else if (section_is_p (sectp
->name
, &names
.ranges
))
2065 this->ranges
.s
.section
= sectp
;
2066 this->ranges
.size
= bfd_section_size (sectp
);
2068 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2070 this->rnglists
.s
.section
= sectp
;
2071 this->rnglists
.size
= bfd_section_size (sectp
);
2073 else if (section_is_p (sectp
->name
, &names
.types
))
2075 struct dwarf2_section_info type_section
;
2077 memset (&type_section
, 0, sizeof (type_section
));
2078 type_section
.s
.section
= sectp
;
2079 type_section
.size
= bfd_section_size (sectp
);
2081 this->types
.push_back (type_section
);
2083 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2085 this->gdb_index
.s
.section
= sectp
;
2086 this->gdb_index
.size
= bfd_section_size (sectp
);
2088 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2090 this->debug_names
.s
.section
= sectp
;
2091 this->debug_names
.size
= bfd_section_size (sectp
);
2093 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2095 this->debug_aranges
.s
.section
= sectp
;
2096 this->debug_aranges
.size
= bfd_section_size (sectp
);
2099 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2100 && bfd_section_vma (sectp
) == 0)
2101 this->has_section_at_zero
= true;
2104 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2108 dwarf2_get_section_info (struct objfile
*objfile
,
2109 enum dwarf2_section_enum sect
,
2110 asection
**sectp
, const gdb_byte
**bufp
,
2111 bfd_size_type
*sizep
)
2113 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2114 struct dwarf2_section_info
*info
;
2116 /* We may see an objfile without any DWARF, in which case we just
2118 if (per_objfile
== NULL
)
2127 case DWARF2_DEBUG_FRAME
:
2128 info
= &per_objfile
->per_bfd
->frame
;
2130 case DWARF2_EH_FRAME
:
2131 info
= &per_objfile
->per_bfd
->eh_frame
;
2134 gdb_assert_not_reached ("unexpected section");
2137 info
->read (objfile
);
2139 *sectp
= info
->get_bfd_section ();
2140 *bufp
= info
->buffer
;
2141 *sizep
= info
->size
;
2144 /* A helper function to find the sections for a .dwz file. */
2147 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, dwz_file
*dwz_file
)
2149 /* Note that we only support the standard ELF names, because .dwz
2150 is ELF-only (at the time of writing). */
2151 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2153 dwz_file
->abbrev
.s
.section
= sectp
;
2154 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2156 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2158 dwz_file
->info
.s
.section
= sectp
;
2159 dwz_file
->info
.size
= bfd_section_size (sectp
);
2161 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2163 dwz_file
->str
.s
.section
= sectp
;
2164 dwz_file
->str
.size
= bfd_section_size (sectp
);
2166 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2168 dwz_file
->line
.s
.section
= sectp
;
2169 dwz_file
->line
.size
= bfd_section_size (sectp
);
2171 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2173 dwz_file
->macro
.s
.section
= sectp
;
2174 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2176 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2178 dwz_file
->gdb_index
.s
.section
= sectp
;
2179 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2181 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2183 dwz_file
->debug_names
.s
.section
= sectp
;
2184 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2188 /* See dwarf2read.h. */
2191 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2193 const char *filename
;
2194 bfd_size_type buildid_len_arg
;
2198 if (per_bfd
->dwz_file
!= NULL
)
2199 return per_bfd
->dwz_file
.get ();
2201 bfd_set_error (bfd_error_no_error
);
2202 gdb::unique_xmalloc_ptr
<char> data
2203 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2204 &buildid_len_arg
, &buildid
));
2207 if (bfd_get_error () == bfd_error_no_error
)
2209 error (_("could not read '.gnu_debugaltlink' section: %s"),
2210 bfd_errmsg (bfd_get_error ()));
2213 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2215 buildid_len
= (size_t) buildid_len_arg
;
2217 filename
= data
.get ();
2219 std::string abs_storage
;
2220 if (!IS_ABSOLUTE_PATH (filename
))
2222 gdb::unique_xmalloc_ptr
<char> abs
2223 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2225 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2226 filename
= abs_storage
.c_str ();
2229 /* First try the file name given in the section. If that doesn't
2230 work, try to use the build-id instead. */
2231 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2232 if (dwz_bfd
!= NULL
)
2234 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2235 dwz_bfd
.reset (nullptr);
2238 if (dwz_bfd
== NULL
)
2239 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2241 if (dwz_bfd
== nullptr)
2243 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2244 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2246 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2253 /* File successfully retrieved from server. */
2254 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2256 if (dwz_bfd
== nullptr)
2257 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2258 alt_filename
.get ());
2259 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2260 dwz_bfd
.reset (nullptr);
2264 if (dwz_bfd
== NULL
)
2265 error (_("could not find '.gnu_debugaltlink' file for %s"),
2266 bfd_get_filename (per_bfd
->obfd
));
2268 std::unique_ptr
<struct dwz_file
> result
2269 (new struct dwz_file (std::move (dwz_bfd
)));
2271 for (asection
*sec
: gdb_bfd_sections (result
->dwz_bfd
))
2272 locate_dwz_sections (result
->dwz_bfd
.get (), sec
, result
.get ());
2274 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2275 per_bfd
->dwz_file
= std::move (result
);
2276 return per_bfd
->dwz_file
.get ();
2279 /* DWARF quick_symbols_functions support. */
2281 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2282 unique line tables, so we maintain a separate table of all .debug_line
2283 derived entries to support the sharing.
2284 All the quick functions need is the list of file names. We discard the
2285 line_header when we're done and don't need to record it here. */
2286 struct quick_file_names
2288 /* The data used to construct the hash key. */
2289 struct stmt_list_hash hash
;
2291 /* The number of entries in file_names, real_names. */
2292 unsigned int num_file_names
;
2294 /* The file names from the line table, after being run through
2296 const char **file_names
;
2298 /* The file names from the line table after being run through
2299 gdb_realpath. These are computed lazily. */
2300 const char **real_names
;
2303 /* When using the index (and thus not using psymtabs), each CU has an
2304 object of this type. This is used to hold information needed by
2305 the various "quick" methods. */
2306 struct dwarf2_per_cu_quick_data
2308 /* The file table. This can be NULL if there was no file table
2309 or it's currently not read in.
2310 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2311 struct quick_file_names
*file_names
;
2313 /* A temporary mark bit used when iterating over all CUs in
2314 expand_symtabs_matching. */
2315 unsigned int mark
: 1;
2317 /* True if we've tried to read the file table and found there isn't one.
2318 There will be no point in trying to read it again next time. */
2319 unsigned int no_file_data
: 1;
2322 /* Utility hash function for a stmt_list_hash. */
2325 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2329 if (stmt_list_hash
->dwo_unit
!= NULL
)
2330 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2331 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2335 /* Utility equality function for a stmt_list_hash. */
2338 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2339 const struct stmt_list_hash
*rhs
)
2341 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2343 if (lhs
->dwo_unit
!= NULL
2344 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2347 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2350 /* Hash function for a quick_file_names. */
2353 hash_file_name_entry (const void *e
)
2355 const struct quick_file_names
*file_data
2356 = (const struct quick_file_names
*) e
;
2358 return hash_stmt_list_entry (&file_data
->hash
);
2361 /* Equality function for a quick_file_names. */
2364 eq_file_name_entry (const void *a
, const void *b
)
2366 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2367 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2369 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2372 /* Delete function for a quick_file_names. */
2375 delete_file_name_entry (void *e
)
2377 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2380 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2382 xfree ((void*) file_data
->file_names
[i
]);
2383 if (file_data
->real_names
)
2384 xfree ((void*) file_data
->real_names
[i
]);
2387 /* The space for the struct itself lives on the obstack, so we don't
2391 /* Create a quick_file_names hash table. */
2394 create_quick_file_names_table (unsigned int nr_initial_entries
)
2396 return htab_up (htab_create_alloc (nr_initial_entries
,
2397 hash_file_name_entry
, eq_file_name_entry
,
2398 delete_file_name_entry
, xcalloc
, xfree
));
2401 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2402 function is unrelated to symtabs, symtab would have to be created afterwards.
2403 You should call age_cached_comp_units after processing the CU. */
2406 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2409 if (per_cu
->is_debug_types
)
2410 load_full_type_unit (per_cu
, per_objfile
);
2412 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2413 skip_partial
, language_minimal
);
2415 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2417 return nullptr; /* Dummy CU. */
2419 dwarf2_find_base_address (cu
->dies
, cu
);
2424 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2427 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2428 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2430 /* Skip type_unit_groups, reading the type units they contain
2431 is handled elsewhere. */
2432 if (per_cu
->type_unit_group_p ())
2435 /* The destructor of dwarf2_queue_guard frees any entries left on
2436 the queue. After this point we're guaranteed to leave this function
2437 with the dwarf queue empty. */
2438 dwarf2_queue_guard
q_guard (per_objfile
);
2440 if (!per_objfile
->symtab_set_p (per_cu
))
2442 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2443 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2445 /* If we just loaded a CU from a DWO, and we're working with an index
2446 that may badly handle TUs, load all the TUs in that DWO as well.
2447 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2448 if (!per_cu
->is_debug_types
2450 && cu
->dwo_unit
!= NULL
2451 && per_objfile
->per_bfd
->index_table
!= NULL
2452 && per_objfile
->per_bfd
->index_table
->version
<= 7
2453 /* DWP files aren't supported yet. */
2454 && get_dwp_file (per_objfile
) == NULL
)
2455 queue_and_load_all_dwo_tus (cu
);
2458 process_queue (per_objfile
);
2460 /* Age the cache, releasing compilation units that have not
2461 been used recently. */
2462 per_objfile
->age_comp_units ();
2465 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2466 the per-objfile for which this symtab is instantiated.
2468 Returns the resulting symbol table. */
2470 static struct compunit_symtab
*
2471 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2472 dwarf2_per_objfile
*per_objfile
,
2475 gdb_assert (per_objfile
->per_bfd
->using_index
);
2477 if (!per_objfile
->symtab_set_p (per_cu
))
2479 free_cached_comp_units
freer (per_objfile
);
2480 scoped_restore decrementer
= increment_reading_symtab ();
2481 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2482 process_cu_includes (per_objfile
);
2485 return per_objfile
->get_symtab (per_cu
);
2488 /* See declaration. */
2490 dwarf2_per_cu_data
*
2491 dwarf2_per_bfd::get_cutu (int index
)
2493 if (index
>= this->all_comp_units
.size ())
2495 index
-= this->all_comp_units
.size ();
2496 gdb_assert (index
< this->all_type_units
.size ());
2497 return &this->all_type_units
[index
]->per_cu
;
2500 return this->all_comp_units
[index
];
2503 /* See declaration. */
2505 dwarf2_per_cu_data
*
2506 dwarf2_per_bfd::get_cu (int index
)
2508 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2510 return this->all_comp_units
[index
];
2513 /* See declaration. */
2516 dwarf2_per_bfd::get_tu (int index
)
2518 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2520 return this->all_type_units
[index
];
2525 dwarf2_per_cu_data
*
2526 dwarf2_per_bfd::allocate_per_cu ()
2528 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2529 result
->per_bfd
= this;
2530 result
->index
= m_num_psymtabs
++;
2537 dwarf2_per_bfd::allocate_signatured_type ()
2539 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2540 result
->per_cu
.per_bfd
= this;
2541 result
->per_cu
.index
= m_num_psymtabs
++;
2545 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2546 obstack, and constructed with the specified field values. */
2548 static dwarf2_per_cu_data
*
2549 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2550 struct dwarf2_section_info
*section
,
2552 sect_offset sect_off
, ULONGEST length
)
2554 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2555 the_cu
->sect_off
= sect_off
;
2556 the_cu
->length
= length
;
2557 the_cu
->section
= section
;
2558 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2559 struct dwarf2_per_cu_quick_data
);
2560 the_cu
->is_dwz
= is_dwz
;
2564 /* A helper for create_cus_from_index that handles a given list of
2568 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2569 const gdb_byte
*cu_list
, offset_type n_elements
,
2570 struct dwarf2_section_info
*section
,
2573 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2575 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2577 sect_offset sect_off
2578 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2579 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2582 dwarf2_per_cu_data
*per_cu
2583 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2585 per_bfd
->all_comp_units
.push_back (per_cu
);
2589 /* Read the CU list from the mapped index, and use it to create all
2590 the CU objects for PER_BFD. */
2593 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2594 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2595 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2597 gdb_assert (per_bfd
->all_comp_units
.empty ());
2598 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2600 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2603 if (dwz_elements
== 0)
2606 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2607 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2611 /* Create the signatured type hash table from the index. */
2614 create_signatured_type_table_from_index
2615 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2616 const gdb_byte
*bytes
, offset_type elements
)
2618 gdb_assert (per_bfd
->all_type_units
.empty ());
2619 per_bfd
->all_type_units
.reserve (elements
/ 3);
2621 htab_up sig_types_hash
= allocate_signatured_type_table ();
2623 for (offset_type i
= 0; i
< elements
; i
+= 3)
2625 struct signatured_type
*sig_type
;
2628 cu_offset type_offset_in_tu
;
2630 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2631 sect_offset sect_off
2632 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2634 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2636 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2639 sig_type
= per_bfd
->allocate_signatured_type ();
2640 sig_type
->signature
= signature
;
2641 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2642 sig_type
->per_cu
.is_debug_types
= 1;
2643 sig_type
->per_cu
.section
= section
;
2644 sig_type
->per_cu
.sect_off
= sect_off
;
2645 sig_type
->per_cu
.v
.quick
2646 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2647 struct dwarf2_per_cu_quick_data
);
2649 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2652 per_bfd
->all_type_units
.push_back (sig_type
);
2655 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2658 /* Create the signatured type hash table from .debug_names. */
2661 create_signatured_type_table_from_debug_names
2662 (dwarf2_per_objfile
*per_objfile
,
2663 const mapped_debug_names
&map
,
2664 struct dwarf2_section_info
*section
,
2665 struct dwarf2_section_info
*abbrev_section
)
2667 struct objfile
*objfile
= per_objfile
->objfile
;
2669 section
->read (objfile
);
2670 abbrev_section
->read (objfile
);
2672 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
2673 per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2675 htab_up sig_types_hash
= allocate_signatured_type_table ();
2677 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2679 struct signatured_type
*sig_type
;
2682 sect_offset sect_off
2683 = (sect_offset
) (extract_unsigned_integer
2684 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2686 map
.dwarf5_byte_order
));
2688 comp_unit_head cu_header
;
2689 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2691 section
->buffer
+ to_underlying (sect_off
),
2694 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2695 sig_type
->signature
= cu_header
.signature
;
2696 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2697 sig_type
->per_cu
.is_debug_types
= 1;
2698 sig_type
->per_cu
.section
= section
;
2699 sig_type
->per_cu
.sect_off
= sect_off
;
2700 sig_type
->per_cu
.v
.quick
2701 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2702 struct dwarf2_per_cu_quick_data
);
2704 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2707 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2710 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2713 /* Read the address map data from the mapped index, and use it to
2714 populate the objfile's psymtabs_addrmap. */
2717 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2718 struct mapped_index
*index
)
2720 struct objfile
*objfile
= per_objfile
->objfile
;
2721 struct gdbarch
*gdbarch
= objfile
->arch ();
2722 const gdb_byte
*iter
, *end
;
2723 struct addrmap
*mutable_map
;
2726 auto_obstack temp_obstack
;
2728 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2730 iter
= index
->address_table
.data ();
2731 end
= iter
+ index
->address_table
.size ();
2733 baseaddr
= objfile
->text_section_offset ();
2737 ULONGEST hi
, lo
, cu_index
;
2738 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2740 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2742 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2747 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2748 hex_string (lo
), hex_string (hi
));
2752 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
2754 complaint (_(".gdb_index address table has invalid CU number %u"),
2755 (unsigned) cu_index
);
2759 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2760 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2761 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2762 per_objfile
->per_bfd
->get_cu (cu_index
));
2765 objfile
->partial_symtabs
->psymtabs_addrmap
2766 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2769 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2770 populate the objfile's psymtabs_addrmap. */
2773 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2774 struct dwarf2_section_info
*section
)
2776 struct objfile
*objfile
= per_objfile
->objfile
;
2777 bfd
*abfd
= objfile
->obfd
;
2778 struct gdbarch
*gdbarch
= objfile
->arch ();
2779 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2781 auto_obstack temp_obstack
;
2782 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2784 std::unordered_map
<sect_offset
,
2785 dwarf2_per_cu_data
*,
2786 gdb::hash_enum
<sect_offset
>>
2787 debug_info_offset_to_per_cu
;
2788 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
2790 const auto insertpair
2791 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2792 if (!insertpair
.second
)
2794 warning (_("Section .debug_aranges in %s has duplicate "
2795 "debug_info_offset %s, ignoring .debug_aranges."),
2796 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2801 section
->read (objfile
);
2803 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2805 const gdb_byte
*addr
= section
->buffer
;
2807 while (addr
< section
->buffer
+ section
->size
)
2809 const gdb_byte
*const entry_addr
= addr
;
2810 unsigned int bytes_read
;
2812 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2816 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2817 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2818 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2819 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2821 warning (_("Section .debug_aranges in %s entry at offset %s "
2822 "length %s exceeds section length %s, "
2823 "ignoring .debug_aranges."),
2824 objfile_name (objfile
),
2825 plongest (entry_addr
- section
->buffer
),
2826 plongest (bytes_read
+ entry_length
),
2827 pulongest (section
->size
));
2831 /* The version number. */
2832 const uint16_t version
= read_2_bytes (abfd
, addr
);
2836 warning (_("Section .debug_aranges in %s entry at offset %s "
2837 "has unsupported version %d, ignoring .debug_aranges."),
2838 objfile_name (objfile
),
2839 plongest (entry_addr
- section
->buffer
), version
);
2843 const uint64_t debug_info_offset
2844 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2845 addr
+= offset_size
;
2846 const auto per_cu_it
2847 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2848 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2850 warning (_("Section .debug_aranges in %s entry at offset %s "
2851 "debug_info_offset %s does not exists, "
2852 "ignoring .debug_aranges."),
2853 objfile_name (objfile
),
2854 plongest (entry_addr
- section
->buffer
),
2855 pulongest (debug_info_offset
));
2858 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2860 const uint8_t address_size
= *addr
++;
2861 if (address_size
< 1 || address_size
> 8)
2863 warning (_("Section .debug_aranges in %s entry at offset %s "
2864 "address_size %u is invalid, ignoring .debug_aranges."),
2865 objfile_name (objfile
),
2866 plongest (entry_addr
- section
->buffer
), address_size
);
2870 const uint8_t segment_selector_size
= *addr
++;
2871 if (segment_selector_size
!= 0)
2873 warning (_("Section .debug_aranges in %s entry at offset %s "
2874 "segment_selector_size %u is not supported, "
2875 "ignoring .debug_aranges."),
2876 objfile_name (objfile
),
2877 plongest (entry_addr
- section
->buffer
),
2878 segment_selector_size
);
2882 /* Must pad to an alignment boundary that is twice the address
2883 size. It is undocumented by the DWARF standard but GCC does
2885 for (size_t padding
= ((-(addr
- section
->buffer
))
2886 & (2 * address_size
- 1));
2887 padding
> 0; padding
--)
2890 warning (_("Section .debug_aranges in %s entry at offset %s "
2891 "padding is not zero, ignoring .debug_aranges."),
2892 objfile_name (objfile
),
2893 plongest (entry_addr
- section
->buffer
));
2899 if (addr
+ 2 * address_size
> entry_end
)
2901 warning (_("Section .debug_aranges in %s entry at offset %s "
2902 "address list is not properly terminated, "
2903 "ignoring .debug_aranges."),
2904 objfile_name (objfile
),
2905 plongest (entry_addr
- section
->buffer
));
2908 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2910 addr
+= address_size
;
2911 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2913 addr
+= address_size
;
2914 if (start
== 0 && length
== 0)
2916 if (start
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
2918 /* Symbol was eliminated due to a COMDAT group. */
2921 ULONGEST end
= start
+ length
;
2922 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2924 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2926 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2930 objfile
->partial_symtabs
->psymtabs_addrmap
2931 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2934 /* Find a slot in the mapped index INDEX for the object named NAME.
2935 If NAME is found, set *VEC_OUT to point to the CU vector in the
2936 constant pool and return true. If NAME cannot be found, return
2940 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2941 offset_type
**vec_out
)
2944 offset_type slot
, step
;
2945 int (*cmp
) (const char *, const char *);
2947 gdb::unique_xmalloc_ptr
<char> without_params
;
2948 if (current_language
->la_language
== language_cplus
2949 || current_language
->la_language
== language_fortran
2950 || current_language
->la_language
== language_d
)
2952 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2955 if (strchr (name
, '(') != NULL
)
2957 without_params
= cp_remove_params (name
);
2959 if (without_params
!= NULL
)
2960 name
= without_params
.get ();
2964 /* Index version 4 did not support case insensitive searches. But the
2965 indices for case insensitive languages are built in lowercase, therefore
2966 simulate our NAME being searched is also lowercased. */
2967 hash
= mapped_index_string_hash ((index
->version
== 4
2968 && case_sensitivity
== case_sensitive_off
2969 ? 5 : index
->version
),
2972 slot
= hash
& (index
->symbol_table
.size () - 1);
2973 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2974 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2980 const auto &bucket
= index
->symbol_table
[slot
];
2981 if (bucket
.name
== 0 && bucket
.vec
== 0)
2984 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2985 if (!cmp (name
, str
))
2987 *vec_out
= (offset_type
*) (index
->constant_pool
2988 + MAYBE_SWAP (bucket
.vec
));
2992 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2996 /* A helper function that reads the .gdb_index from BUFFER and fills
2997 in MAP. FILENAME is the name of the file containing the data;
2998 it is used for error reporting. DEPRECATED_OK is true if it is
2999 ok to use deprecated sections.
3001 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3002 out parameters that are filled in with information about the CU and
3003 TU lists in the section.
3005 Returns true if all went well, false otherwise. */
3008 read_gdb_index_from_buffer (const char *filename
,
3010 gdb::array_view
<const gdb_byte
> buffer
,
3011 struct mapped_index
*map
,
3012 const gdb_byte
**cu_list
,
3013 offset_type
*cu_list_elements
,
3014 const gdb_byte
**types_list
,
3015 offset_type
*types_list_elements
)
3017 const gdb_byte
*addr
= &buffer
[0];
3019 /* Version check. */
3020 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3021 /* Versions earlier than 3 emitted every copy of a psymbol. This
3022 causes the index to behave very poorly for certain requests. Version 3
3023 contained incomplete addrmap. So, it seems better to just ignore such
3027 static int warning_printed
= 0;
3028 if (!warning_printed
)
3030 warning (_("Skipping obsolete .gdb_index section in %s."),
3032 warning_printed
= 1;
3036 /* Index version 4 uses a different hash function than index version
3039 Versions earlier than 6 did not emit psymbols for inlined
3040 functions. Using these files will cause GDB not to be able to
3041 set breakpoints on inlined functions by name, so we ignore these
3042 indices unless the user has done
3043 "set use-deprecated-index-sections on". */
3044 if (version
< 6 && !deprecated_ok
)
3046 static int warning_printed
= 0;
3047 if (!warning_printed
)
3050 Skipping deprecated .gdb_index section in %s.\n\
3051 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3052 to use the section anyway."),
3054 warning_printed
= 1;
3058 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3059 of the TU (for symbols coming from TUs),
3060 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3061 Plus gold-generated indices can have duplicate entries for global symbols,
3062 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3063 These are just performance bugs, and we can't distinguish gdb-generated
3064 indices from gold-generated ones, so issue no warning here. */
3066 /* Indexes with higher version than the one supported by GDB may be no
3067 longer backward compatible. */
3071 map
->version
= version
;
3073 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3076 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3077 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3081 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3082 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3083 - MAYBE_SWAP (metadata
[i
]))
3087 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3088 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3090 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3093 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3094 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3096 = gdb::array_view
<mapped_index::symbol_table_slot
>
3097 ((mapped_index::symbol_table_slot
*) symbol_table
,
3098 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3101 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3106 /* Callback types for dwarf2_read_gdb_index. */
3108 typedef gdb::function_view
3109 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3110 get_gdb_index_contents_ftype
;
3111 typedef gdb::function_view
3112 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3113 get_gdb_index_contents_dwz_ftype
;
3115 /* Read .gdb_index. If everything went ok, initialize the "quick"
3116 elements of all the CUs and return 1. Otherwise, return 0. */
3119 dwarf2_read_gdb_index
3120 (dwarf2_per_objfile
*per_objfile
,
3121 get_gdb_index_contents_ftype get_gdb_index_contents
,
3122 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3124 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3125 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3126 struct dwz_file
*dwz
;
3127 struct objfile
*objfile
= per_objfile
->objfile
;
3128 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3130 gdb::array_view
<const gdb_byte
> main_index_contents
3131 = get_gdb_index_contents (objfile
, per_bfd
);
3133 if (main_index_contents
.empty ())
3136 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3137 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3138 use_deprecated_index_sections
,
3139 main_index_contents
, map
.get (), &cu_list
,
3140 &cu_list_elements
, &types_list
,
3141 &types_list_elements
))
3144 /* Don't use the index if it's empty. */
3145 if (map
->symbol_table
.empty ())
3148 /* If there is a .dwz file, read it so we can get its CU list as
3150 dwz
= dwarf2_get_dwz_file (per_bfd
);
3153 struct mapped_index dwz_map
;
3154 const gdb_byte
*dwz_types_ignore
;
3155 offset_type dwz_types_elements_ignore
;
3157 gdb::array_view
<const gdb_byte
> dwz_index_content
3158 = get_gdb_index_contents_dwz (objfile
, dwz
);
3160 if (dwz_index_content
.empty ())
3163 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3164 1, dwz_index_content
, &dwz_map
,
3165 &dwz_list
, &dwz_list_elements
,
3167 &dwz_types_elements_ignore
))
3169 warning (_("could not read '.gdb_index' section from %s; skipping"),
3170 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3175 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
3178 if (types_list_elements
)
3180 /* We can only handle a single .debug_types when we have an
3182 if (per_bfd
->types
.size () != 1)
3185 dwarf2_section_info
*section
= &per_bfd
->types
[0];
3187 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
3188 types_list_elements
);
3191 create_addrmap_from_index (per_objfile
, map
.get ());
3193 per_bfd
->index_table
= std::move (map
);
3194 per_bfd
->using_index
= 1;
3195 per_bfd
->quick_file_names_table
=
3196 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
3198 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
3199 objfiles using the same BFD. */
3200 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
3201 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
3206 /* die_reader_func for dw2_get_file_names. */
3209 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3210 const gdb_byte
*info_ptr
,
3211 struct die_info
*comp_unit_die
)
3213 struct dwarf2_cu
*cu
= reader
->cu
;
3214 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3215 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3216 struct dwarf2_per_cu_data
*lh_cu
;
3217 struct attribute
*attr
;
3219 struct quick_file_names
*qfn
;
3221 gdb_assert (! this_cu
->is_debug_types
);
3223 /* Our callers never want to match partial units -- instead they
3224 will match the enclosing full CU. */
3225 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3227 this_cu
->v
.quick
->no_file_data
= 1;
3235 sect_offset line_offset
{};
3237 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3238 if (attr
!= nullptr && attr
->form_is_unsigned ())
3240 struct quick_file_names find_entry
;
3242 line_offset
= (sect_offset
) attr
->as_unsigned ();
3244 /* We may have already read in this line header (TU line header sharing).
3245 If we have we're done. */
3246 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3247 find_entry
.hash
.line_sect_off
= line_offset
;
3248 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3249 &find_entry
, INSERT
);
3252 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3256 lh
= dwarf_decode_line_header (line_offset
, cu
);
3260 lh_cu
->v
.quick
->no_file_data
= 1;
3264 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3265 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3266 qfn
->hash
.line_sect_off
= line_offset
;
3267 gdb_assert (slot
!= NULL
);
3270 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3273 if (strcmp (fnd
.name
, "<unknown>") != 0)
3276 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3278 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3279 qfn
->num_file_names
);
3281 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3282 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3283 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3284 fnd
.comp_dir
).release ();
3285 qfn
->real_names
= NULL
;
3287 lh_cu
->v
.quick
->file_names
= qfn
;
3290 /* A helper for the "quick" functions which attempts to read the line
3291 table for THIS_CU. */
3293 static struct quick_file_names
*
3294 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3295 dwarf2_per_objfile
*per_objfile
)
3297 /* This should never be called for TUs. */
3298 gdb_assert (! this_cu
->is_debug_types
);
3299 /* Nor type unit groups. */
3300 gdb_assert (! this_cu
->type_unit_group_p ());
3302 if (this_cu
->v
.quick
->file_names
!= NULL
)
3303 return this_cu
->v
.quick
->file_names
;
3304 /* If we know there is no line data, no point in looking again. */
3305 if (this_cu
->v
.quick
->no_file_data
)
3308 cutu_reader
reader (this_cu
, per_objfile
);
3309 if (!reader
.dummy_p
)
3310 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3312 if (this_cu
->v
.quick
->no_file_data
)
3314 return this_cu
->v
.quick
->file_names
;
3317 /* A helper for the "quick" functions which computes and caches the
3318 real path for a given file name from the line table. */
3321 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3322 struct quick_file_names
*qfn
, int index
)
3324 if (qfn
->real_names
== NULL
)
3325 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3326 qfn
->num_file_names
, const char *);
3328 if (qfn
->real_names
[index
] == NULL
)
3329 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3331 return qfn
->real_names
[index
];
3334 static struct symtab
*
3335 dw2_find_last_source_symtab (struct objfile
*objfile
)
3337 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3338 dwarf2_per_cu_data
*dwarf_cu
= per_objfile
->per_bfd
->all_comp_units
.back ();
3339 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3344 return compunit_primary_filetab (cust
);
3347 /* Traversal function for dw2_forget_cached_source_info. */
3350 dw2_free_cached_file_names (void **slot
, void *info
)
3352 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3354 if (file_data
->real_names
)
3358 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3360 xfree ((void*) file_data
->real_names
[i
]);
3361 file_data
->real_names
[i
] = NULL
;
3369 dw2_forget_cached_source_info (struct objfile
*objfile
)
3371 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3373 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3374 dw2_free_cached_file_names
, NULL
);
3377 /* Helper function for dw2_map_symtabs_matching_filename that expands
3378 the symtabs and calls the iterator. */
3381 dw2_map_expand_apply (struct objfile
*objfile
,
3382 struct dwarf2_per_cu_data
*per_cu
,
3383 const char *name
, const char *real_path
,
3384 gdb::function_view
<bool (symtab
*)> callback
)
3386 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3388 /* Don't visit already-expanded CUs. */
3389 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3390 if (per_objfile
->symtab_set_p (per_cu
))
3393 /* This may expand more than one symtab, and we want to iterate over
3395 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3397 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3398 last_made
, callback
);
3401 /* Implementation of the map_symtabs_matching_filename method. */
3404 dw2_map_symtabs_matching_filename
3405 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3406 gdb::function_view
<bool (symtab
*)> callback
)
3408 const char *name_basename
= lbasename (name
);
3409 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3411 /* The rule is CUs specify all the files, including those used by
3412 any TU, so there's no need to scan TUs here. */
3414 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3416 /* We only need to look at symtabs not already expanded. */
3417 if (per_objfile
->symtab_set_p (per_cu
))
3420 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3421 if (file_data
== NULL
)
3424 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3426 const char *this_name
= file_data
->file_names
[j
];
3427 const char *this_real_name
;
3429 if (compare_filenames_for_search (this_name
, name
))
3431 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3437 /* Before we invoke realpath, which can get expensive when many
3438 files are involved, do a quick comparison of the basenames. */
3439 if (! basenames_may_differ
3440 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3443 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3444 if (compare_filenames_for_search (this_real_name
, name
))
3446 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3452 if (real_path
!= NULL
)
3454 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3455 gdb_assert (IS_ABSOLUTE_PATH (name
));
3456 if (this_real_name
!= NULL
3457 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3459 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3471 /* Struct used to manage iterating over all CUs looking for a symbol. */
3473 struct dw2_symtab_iterator
3475 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3476 dwarf2_per_objfile
*per_objfile
;
3477 /* If set, only look for symbols that match that block. Valid values are
3478 GLOBAL_BLOCK and STATIC_BLOCK. */
3479 gdb::optional
<block_enum
> block_index
;
3480 /* The kind of symbol we're looking for. */
3482 /* The list of CUs from the index entry of the symbol,
3483 or NULL if not found. */
3485 /* The next element in VEC to look at. */
3487 /* The number of elements in VEC, or zero if there is no match. */
3489 /* Have we seen a global version of the symbol?
3490 If so we can ignore all further global instances.
3491 This is to work around gold/15646, inefficient gold-generated
3496 /* Initialize the index symtab iterator ITER, common part. */
3499 dw2_symtab_iter_init_common (struct dw2_symtab_iterator
*iter
,
3500 dwarf2_per_objfile
*per_objfile
,
3501 gdb::optional
<block_enum
> block_index
,
3504 iter
->per_objfile
= per_objfile
;
3505 iter
->block_index
= block_index
;
3506 iter
->domain
= domain
;
3508 iter
->global_seen
= 0;
3513 /* Initialize the index symtab iterator ITER, const char *NAME variant. */
3516 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3517 dwarf2_per_objfile
*per_objfile
,
3518 gdb::optional
<block_enum
> block_index
,
3522 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3524 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3525 /* index is NULL if OBJF_READNOW. */
3529 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3530 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3533 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3536 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3537 dwarf2_per_objfile
*per_objfile
,
3538 gdb::optional
<block_enum
> block_index
,
3539 domain_enum domain
, offset_type namei
)
3541 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3543 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3544 /* index is NULL if OBJF_READNOW. */
3548 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3549 const auto &bucket
= index
->symbol_table
[namei
];
3551 iter
->vec
= (offset_type
*) (index
->constant_pool
3552 + MAYBE_SWAP (bucket
.vec
));
3553 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3556 /* Return the next matching CU or NULL if there are no more. */
3558 static struct dwarf2_per_cu_data
*
3559 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3561 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3563 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3565 offset_type cu_index_and_attrs
=
3566 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3567 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3568 gdb_index_symbol_kind symbol_kind
=
3569 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3570 /* Only check the symbol attributes if they're present.
3571 Indices prior to version 7 don't record them,
3572 and indices >= 7 may elide them for certain symbols
3573 (gold does this). */
3575 (per_objfile
->per_bfd
->index_table
->version
>= 7
3576 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3578 /* Don't crash on bad data. */
3579 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
3580 + per_objfile
->per_bfd
->all_type_units
.size ()))
3582 complaint (_(".gdb_index entry has bad CU index"
3583 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3587 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
3589 /* Skip if already read in. */
3590 if (per_objfile
->symtab_set_p (per_cu
))
3593 /* Check static vs global. */
3596 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3598 if (iter
->block_index
.has_value ())
3600 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3602 if (is_static
!= want_static
)
3606 /* Work around gold/15646. */
3608 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3610 if (iter
->global_seen
)
3613 iter
->global_seen
= 1;
3617 /* Only check the symbol's kind if it has one. */
3620 switch (iter
->domain
)
3623 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3624 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3625 /* Some types are also in VAR_DOMAIN. */
3626 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3630 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3634 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3638 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3653 static struct compunit_symtab
*
3654 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3655 const char *name
, domain_enum domain
)
3657 struct compunit_symtab
*stab_best
= NULL
;
3658 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3660 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3662 struct dw2_symtab_iterator iter
;
3663 struct dwarf2_per_cu_data
*per_cu
;
3665 dw2_symtab_iter_init (&iter
, per_objfile
, block_index
, domain
, name
);
3667 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3669 struct symbol
*sym
, *with_opaque
= NULL
;
3670 struct compunit_symtab
*stab
3671 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3672 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3673 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3675 sym
= block_find_symbol (block
, name
, domain
,
3676 block_find_non_opaque_type_preferred
,
3679 /* Some caution must be observed with overloaded functions
3680 and methods, since the index will not contain any overload
3681 information (but NAME might contain it). */
3684 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3686 if (with_opaque
!= NULL
3687 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3690 /* Keep looking through other CUs. */
3697 dw2_print_stats (struct objfile
*objfile
)
3699 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3700 int total
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3701 + per_objfile
->per_bfd
->all_type_units
.size ());
3704 for (int i
= 0; i
< total
; ++i
)
3706 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3708 if (!per_objfile
->symtab_set_p (per_cu
))
3711 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3712 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3715 /* This dumps minimal information about the index.
3716 It is called via "mt print objfiles".
3717 One use is to verify .gdb_index has been loaded by the
3718 gdb.dwarf2/gdb-index.exp testcase. */
3721 dw2_dump (struct objfile
*objfile
)
3723 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3725 gdb_assert (per_objfile
->per_bfd
->using_index
);
3726 printf_filtered (".gdb_index:");
3727 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3729 printf_filtered (" version %d\n",
3730 per_objfile
->per_bfd
->index_table
->version
);
3733 printf_filtered (" faked for \"readnow\"\n");
3734 printf_filtered ("\n");
3738 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3739 const char *func_name
)
3741 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3743 struct dw2_symtab_iterator iter
;
3744 struct dwarf2_per_cu_data
*per_cu
;
3746 dw2_symtab_iter_init (&iter
, per_objfile
, {}, VAR_DOMAIN
, func_name
);
3748 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3749 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3754 dw2_expand_all_symtabs (struct objfile
*objfile
)
3756 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3757 int total_units
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3758 + per_objfile
->per_bfd
->all_type_units
.size ());
3760 for (int i
= 0; i
< total_units
; ++i
)
3762 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3764 /* We don't want to directly expand a partial CU, because if we
3765 read it with the wrong language, then assertion failures can
3766 be triggered later on. See PR symtab/23010. So, tell
3767 dw2_instantiate_symtab to skip partial CUs -- any important
3768 partial CU will be read via DW_TAG_imported_unit anyway. */
3769 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3774 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3775 const char *fullname
)
3777 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3779 /* We don't need to consider type units here.
3780 This is only called for examining code, e.g. expand_line_sal.
3781 There can be an order of magnitude (or more) more type units
3782 than comp units, and we avoid them if we can. */
3784 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3786 /* We only need to look at symtabs not already expanded. */
3787 if (per_objfile
->symtab_set_p (per_cu
))
3790 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3791 if (file_data
== NULL
)
3794 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3796 const char *this_fullname
= file_data
->file_names
[j
];
3798 if (filename_cmp (this_fullname
, fullname
) == 0)
3800 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3808 dw2_expand_symtabs_matching_symbol
3809 (mapped_index_base
&index
,
3810 const lookup_name_info
&lookup_name_in
,
3811 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3812 enum search_domain kind
,
3813 gdb::function_view
<bool (offset_type
)> match_callback
,
3814 dwarf2_per_objfile
*per_objfile
);
3817 dw2_expand_symtabs_matching_one
3818 (dwarf2_per_cu_data
*per_cu
,
3819 dwarf2_per_objfile
*per_objfile
,
3820 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3821 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3824 dw2_map_matching_symbols
3825 (struct objfile
*objfile
,
3826 const lookup_name_info
&name
, domain_enum domain
,
3828 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3829 symbol_compare_ftype
*ordered_compare
)
3832 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3834 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3836 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3838 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3840 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3841 auto matcher
= [&] (const char *symname
)
3843 if (ordered_compare
== nullptr)
3845 return ordered_compare (symname
, match_name
) == 0;
3848 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3849 [&] (offset_type namei
)
3851 struct dw2_symtab_iterator iter
;
3852 struct dwarf2_per_cu_data
*per_cu
;
3854 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3856 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3857 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3864 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3865 proceed assuming all symtabs have been read in. */
3868 for (compunit_symtab
*cust
: objfile
->compunits ())
3870 const struct block
*block
;
3874 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3875 if (!iterate_over_symbols_terminated (block
, name
,
3881 /* Starting from a search name, return the string that finds the upper
3882 bound of all strings that start with SEARCH_NAME in a sorted name
3883 list. Returns the empty string to indicate that the upper bound is
3884 the end of the list. */
3887 make_sort_after_prefix_name (const char *search_name
)
3889 /* When looking to complete "func", we find the upper bound of all
3890 symbols that start with "func" by looking for where we'd insert
3891 the closest string that would follow "func" in lexicographical
3892 order. Usually, that's "func"-with-last-character-incremented,
3893 i.e. "fund". Mind non-ASCII characters, though. Usually those
3894 will be UTF-8 multi-byte sequences, but we can't be certain.
3895 Especially mind the 0xff character, which is a valid character in
3896 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3897 rule out compilers allowing it in identifiers. Note that
3898 conveniently, strcmp/strcasecmp are specified to compare
3899 characters interpreted as unsigned char. So what we do is treat
3900 the whole string as a base 256 number composed of a sequence of
3901 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3902 to 0, and carries 1 to the following more-significant position.
3903 If the very first character in SEARCH_NAME ends up incremented
3904 and carries/overflows, then the upper bound is the end of the
3905 list. The string after the empty string is also the empty
3908 Some examples of this operation:
3910 SEARCH_NAME => "+1" RESULT
3914 "\xff" "a" "\xff" => "\xff" "b"
3919 Then, with these symbols for example:
3925 completing "func" looks for symbols between "func" and
3926 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3927 which finds "func" and "func1", but not "fund".
3931 funcÿ (Latin1 'ÿ' [0xff])
3935 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3936 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3940 ÿÿ (Latin1 'ÿ' [0xff])
3943 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3944 the end of the list.
3946 std::string after
= search_name
;
3947 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3949 if (!after
.empty ())
3950 after
.back () = (unsigned char) after
.back () + 1;
3954 /* See declaration. */
3956 std::pair
<std::vector
<name_component
>::const_iterator
,
3957 std::vector
<name_component
>::const_iterator
>
3958 mapped_index_base::find_name_components_bounds
3959 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3960 dwarf2_per_objfile
*per_objfile
) const
3963 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3965 const char *lang_name
3966 = lookup_name_without_params
.language_lookup_name (lang
);
3968 /* Comparison function object for lower_bound that matches against a
3969 given symbol name. */
3970 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3973 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3974 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3975 return name_cmp (elem_name
, name
) < 0;
3978 /* Comparison function object for upper_bound that matches against a
3979 given symbol name. */
3980 auto lookup_compare_upper
= [&] (const char *name
,
3981 const name_component
&elem
)
3983 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3984 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3985 return name_cmp (name
, elem_name
) < 0;
3988 auto begin
= this->name_components
.begin ();
3989 auto end
= this->name_components
.end ();
3991 /* Find the lower bound. */
3994 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3997 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4000 /* Find the upper bound. */
4003 if (lookup_name_without_params
.completion_mode ())
4005 /* In completion mode, we want UPPER to point past all
4006 symbols names that have the same prefix. I.e., with
4007 these symbols, and completing "func":
4009 function << lower bound
4011 other_function << upper bound
4013 We find the upper bound by looking for the insertion
4014 point of "func"-with-last-character-incremented,
4016 std::string after
= make_sort_after_prefix_name (lang_name
);
4019 return std::lower_bound (lower
, end
, after
.c_str (),
4020 lookup_compare_lower
);
4023 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4026 return {lower
, upper
};
4029 /* See declaration. */
4032 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
4034 if (!this->name_components
.empty ())
4037 this->name_components_casing
= case_sensitivity
;
4039 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4041 /* The code below only knows how to break apart components of C++
4042 symbol names (and other languages that use '::' as
4043 namespace/module separator) and Ada symbol names. */
4044 auto count
= this->symbol_name_count ();
4045 for (offset_type idx
= 0; idx
< count
; idx
++)
4047 if (this->symbol_name_slot_invalid (idx
))
4050 const char *name
= this->symbol_name_at (idx
, per_objfile
);
4052 /* Add each name component to the name component table. */
4053 unsigned int previous_len
= 0;
4055 if (strstr (name
, "::") != nullptr)
4057 for (unsigned int current_len
= cp_find_first_component (name
);
4058 name
[current_len
] != '\0';
4059 current_len
+= cp_find_first_component (name
+ current_len
))
4061 gdb_assert (name
[current_len
] == ':');
4062 this->name_components
.push_back ({previous_len
, idx
});
4063 /* Skip the '::'. */
4065 previous_len
= current_len
;
4070 /* Handle the Ada encoded (aka mangled) form here. */
4071 for (const char *iter
= strstr (name
, "__");
4073 iter
= strstr (iter
, "__"))
4075 this->name_components
.push_back ({previous_len
, idx
});
4077 previous_len
= iter
- name
;
4081 this->name_components
.push_back ({previous_len
, idx
});
4084 /* Sort name_components elements by name. */
4085 auto name_comp_compare
= [&] (const name_component
&left
,
4086 const name_component
&right
)
4088 const char *left_qualified
4089 = this->symbol_name_at (left
.idx
, per_objfile
);
4090 const char *right_qualified
4091 = this->symbol_name_at (right
.idx
, per_objfile
);
4093 const char *left_name
= left_qualified
+ left
.name_offset
;
4094 const char *right_name
= right_qualified
+ right
.name_offset
;
4096 return name_cmp (left_name
, right_name
) < 0;
4099 std::sort (this->name_components
.begin (),
4100 this->name_components
.end (),
4104 /* Helper for dw2_expand_symtabs_matching that works with a
4105 mapped_index_base instead of the containing objfile. This is split
4106 to a separate function in order to be able to unit test the
4107 name_components matching using a mock mapped_index_base. For each
4108 symbol name that matches, calls MATCH_CALLBACK, passing it the
4109 symbol's index in the mapped_index_base symbol table. */
4112 dw2_expand_symtabs_matching_symbol
4113 (mapped_index_base
&index
,
4114 const lookup_name_info
&lookup_name_in
,
4115 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4116 enum search_domain kind
,
4117 gdb::function_view
<bool (offset_type
)> match_callback
,
4118 dwarf2_per_objfile
*per_objfile
)
4120 lookup_name_info lookup_name_without_params
4121 = lookup_name_in
.make_ignore_params ();
4123 /* Build the symbol name component sorted vector, if we haven't
4125 index
.build_name_components (per_objfile
);
4127 /* The same symbol may appear more than once in the range though.
4128 E.g., if we're looking for symbols that complete "w", and we have
4129 a symbol named "w1::w2", we'll find the two name components for
4130 that same symbol in the range. To be sure we only call the
4131 callback once per symbol, we first collect the symbol name
4132 indexes that matched in a temporary vector and ignore
4134 std::vector
<offset_type
> matches
;
4136 struct name_and_matcher
4138 symbol_name_matcher_ftype
*matcher
;
4141 bool operator== (const name_and_matcher
&other
) const
4143 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4147 /* A vector holding all the different symbol name matchers, for all
4149 std::vector
<name_and_matcher
> matchers
;
4151 for (int i
= 0; i
< nr_languages
; i
++)
4153 enum language lang_e
= (enum language
) i
;
4155 const language_defn
*lang
= language_def (lang_e
);
4156 symbol_name_matcher_ftype
*name_matcher
4157 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
4159 name_and_matcher key
{
4161 lookup_name_without_params
.language_lookup_name (lang_e
)
4164 /* Don't insert the same comparison routine more than once.
4165 Note that we do this linear walk. This is not a problem in
4166 practice because the number of supported languages is
4168 if (std::find (matchers
.begin (), matchers
.end (), key
)
4171 matchers
.push_back (std::move (key
));
4174 = index
.find_name_components_bounds (lookup_name_without_params
,
4175 lang_e
, per_objfile
);
4177 /* Now for each symbol name in range, check to see if we have a name
4178 match, and if so, call the MATCH_CALLBACK callback. */
4180 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4182 const char *qualified
4183 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4185 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4186 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4189 matches
.push_back (bounds
.first
->idx
);
4193 std::sort (matches
.begin (), matches
.end ());
4195 /* Finally call the callback, once per match. */
4197 for (offset_type idx
: matches
)
4201 if (!match_callback (idx
))
4207 /* Above we use a type wider than idx's for 'prev', since 0 and
4208 (offset_type)-1 are both possible values. */
4209 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4214 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4216 /* A mock .gdb_index/.debug_names-like name index table, enough to
4217 exercise dw2_expand_symtabs_matching_symbol, which works with the
4218 mapped_index_base interface. Builds an index from the symbol list
4219 passed as parameter to the constructor. */
4220 class mock_mapped_index
: public mapped_index_base
4223 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4224 : m_symbol_table (symbols
)
4227 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4229 /* Return the number of names in the symbol table. */
4230 size_t symbol_name_count () const override
4232 return m_symbol_table
.size ();
4235 /* Get the name of the symbol at IDX in the symbol table. */
4236 const char *symbol_name_at
4237 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4239 return m_symbol_table
[idx
];
4243 gdb::array_view
<const char *> m_symbol_table
;
4246 /* Convenience function that converts a NULL pointer to a "<null>"
4247 string, to pass to print routines. */
4250 string_or_null (const char *str
)
4252 return str
!= NULL
? str
: "<null>";
4255 /* Check if a lookup_name_info built from
4256 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4257 index. EXPECTED_LIST is the list of expected matches, in expected
4258 matching order. If no match expected, then an empty list is
4259 specified. Returns true on success. On failure prints a warning
4260 indicating the file:line that failed, and returns false. */
4263 check_match (const char *file
, int line
,
4264 mock_mapped_index
&mock_index
,
4265 const char *name
, symbol_name_match_type match_type
,
4266 bool completion_mode
,
4267 std::initializer_list
<const char *> expected_list
,
4268 dwarf2_per_objfile
*per_objfile
)
4270 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4272 bool matched
= true;
4274 auto mismatch
= [&] (const char *expected_str
,
4277 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4278 "expected=\"%s\", got=\"%s\"\n"),
4280 (match_type
== symbol_name_match_type::FULL
4282 name
, string_or_null (expected_str
), string_or_null (got
));
4286 auto expected_it
= expected_list
.begin ();
4287 auto expected_end
= expected_list
.end ();
4289 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4291 [&] (offset_type idx
)
4293 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4294 const char *expected_str
4295 = expected_it
== expected_end
? NULL
: *expected_it
++;
4297 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4298 mismatch (expected_str
, matched_name
);
4302 const char *expected_str
4303 = expected_it
== expected_end
? NULL
: *expected_it
++;
4304 if (expected_str
!= NULL
)
4305 mismatch (expected_str
, NULL
);
4310 /* The symbols added to the mock mapped_index for testing (in
4312 static const char *test_symbols
[] = {
4321 "ns2::tmpl<int>::foo2",
4322 "(anonymous namespace)::A::B::C",
4324 /* These are used to check that the increment-last-char in the
4325 matching algorithm for completion doesn't match "t1_fund" when
4326 completing "t1_func". */
4332 /* A UTF-8 name with multi-byte sequences to make sure that
4333 cp-name-parser understands this as a single identifier ("função"
4334 is "function" in PT). */
4337 /* \377 (0xff) is Latin1 'ÿ'. */
4340 /* \377 (0xff) is Latin1 'ÿ'. */
4344 /* A name with all sorts of complications. Starts with "z" to make
4345 it easier for the completion tests below. */
4346 #define Z_SYM_NAME \
4347 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4348 "::tuple<(anonymous namespace)::ui*, " \
4349 "std::default_delete<(anonymous namespace)::ui>, void>"
4354 /* Returns true if the mapped_index_base::find_name_component_bounds
4355 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4356 in completion mode. */
4359 check_find_bounds_finds (mapped_index_base
&index
,
4360 const char *search_name
,
4361 gdb::array_view
<const char *> expected_syms
,
4362 dwarf2_per_objfile
*per_objfile
)
4364 lookup_name_info
lookup_name (search_name
,
4365 symbol_name_match_type::FULL
, true);
4367 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4371 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4372 if (distance
!= expected_syms
.size ())
4375 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4377 auto nc_elem
= bounds
.first
+ exp_elem
;
4378 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4379 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4386 /* Test the lower-level mapped_index::find_name_component_bounds
4390 test_mapped_index_find_name_component_bounds ()
4392 mock_mapped_index
mock_index (test_symbols
);
4394 mock_index
.build_name_components (NULL
/* per_objfile */);
4396 /* Test the lower-level mapped_index::find_name_component_bounds
4397 method in completion mode. */
4399 static const char *expected_syms
[] = {
4404 SELF_CHECK (check_find_bounds_finds
4405 (mock_index
, "t1_func", expected_syms
,
4406 NULL
/* per_objfile */));
4409 /* Check that the increment-last-char in the name matching algorithm
4410 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4412 static const char *expected_syms1
[] = {
4416 SELF_CHECK (check_find_bounds_finds
4417 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4419 static const char *expected_syms2
[] = {
4422 SELF_CHECK (check_find_bounds_finds
4423 (mock_index
, "\377\377", expected_syms2
,
4424 NULL
/* per_objfile */));
4428 /* Test dw2_expand_symtabs_matching_symbol. */
4431 test_dw2_expand_symtabs_matching_symbol ()
4433 mock_mapped_index
mock_index (test_symbols
);
4435 /* We let all tests run until the end even if some fails, for debug
4437 bool any_mismatch
= false;
4439 /* Create the expected symbols list (an initializer_list). Needed
4440 because lists have commas, and we need to pass them to CHECK,
4441 which is a macro. */
4442 #define EXPECT(...) { __VA_ARGS__ }
4444 /* Wrapper for check_match that passes down the current
4445 __FILE__/__LINE__. */
4446 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4447 any_mismatch |= !check_match (__FILE__, __LINE__, \
4449 NAME, MATCH_TYPE, COMPLETION_MODE, \
4450 EXPECTED_LIST, NULL)
4452 /* Identity checks. */
4453 for (const char *sym
: test_symbols
)
4455 /* Should be able to match all existing symbols. */
4456 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4459 /* Should be able to match all existing symbols with
4461 std::string with_params
= std::string (sym
) + "(int)";
4462 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4465 /* Should be able to match all existing symbols with
4466 parameters and qualifiers. */
4467 with_params
= std::string (sym
) + " ( int ) const";
4468 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4471 /* This should really find sym, but cp-name-parser.y doesn't
4472 know about lvalue/rvalue qualifiers yet. */
4473 with_params
= std::string (sym
) + " ( int ) &&";
4474 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4478 /* Check that the name matching algorithm for completion doesn't get
4479 confused with Latin1 'ÿ' / 0xff. */
4481 static const char str
[] = "\377";
4482 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4483 EXPECT ("\377", "\377\377123"));
4486 /* Check that the increment-last-char in the matching algorithm for
4487 completion doesn't match "t1_fund" when completing "t1_func". */
4489 static const char str
[] = "t1_func";
4490 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4491 EXPECT ("t1_func", "t1_func1"));
4494 /* Check that completion mode works at each prefix of the expected
4497 static const char str
[] = "function(int)";
4498 size_t len
= strlen (str
);
4501 for (size_t i
= 1; i
< len
; i
++)
4503 lookup
.assign (str
, i
);
4504 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4505 EXPECT ("function"));
4509 /* While "w" is a prefix of both components, the match function
4510 should still only be called once. */
4512 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4514 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4518 /* Same, with a "complicated" symbol. */
4520 static const char str
[] = Z_SYM_NAME
;
4521 size_t len
= strlen (str
);
4524 for (size_t i
= 1; i
< len
; i
++)
4526 lookup
.assign (str
, i
);
4527 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4528 EXPECT (Z_SYM_NAME
));
4532 /* In FULL mode, an incomplete symbol doesn't match. */
4534 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4538 /* A complete symbol with parameters matches any overload, since the
4539 index has no overload info. */
4541 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4542 EXPECT ("std::zfunction", "std::zfunction2"));
4543 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4544 EXPECT ("std::zfunction", "std::zfunction2"));
4545 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4546 EXPECT ("std::zfunction", "std::zfunction2"));
4549 /* Check that whitespace is ignored appropriately. A symbol with a
4550 template argument list. */
4552 static const char expected
[] = "ns::foo<int>";
4553 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4555 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4559 /* Check that whitespace is ignored appropriately. A symbol with a
4560 template argument list that includes a pointer. */
4562 static const char expected
[] = "ns::foo<char*>";
4563 /* Try both completion and non-completion modes. */
4564 static const bool completion_mode
[2] = {false, true};
4565 for (size_t i
= 0; i
< 2; i
++)
4567 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4568 completion_mode
[i
], EXPECT (expected
));
4569 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4570 completion_mode
[i
], EXPECT (expected
));
4572 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4573 completion_mode
[i
], EXPECT (expected
));
4574 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4575 completion_mode
[i
], EXPECT (expected
));
4580 /* Check method qualifiers are ignored. */
4581 static const char expected
[] = "ns::foo<char*>";
4582 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4583 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4584 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4585 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4586 CHECK_MATCH ("foo < char * > ( int ) const",
4587 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4588 CHECK_MATCH ("foo < char * > ( int ) &&",
4589 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4592 /* Test lookup names that don't match anything. */
4594 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4597 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4601 /* Some wild matching tests, exercising "(anonymous namespace)",
4602 which should not be confused with a parameter list. */
4604 static const char *syms
[] = {
4608 "A :: B :: C ( int )",
4613 for (const char *s
: syms
)
4615 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4616 EXPECT ("(anonymous namespace)::A::B::C"));
4621 static const char expected
[] = "ns2::tmpl<int>::foo2";
4622 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4624 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4628 SELF_CHECK (!any_mismatch
);
4637 test_mapped_index_find_name_component_bounds ();
4638 test_dw2_expand_symtabs_matching_symbol ();
4641 }} // namespace selftests::dw2_expand_symtabs_matching
4643 #endif /* GDB_SELF_TEST */
4645 /* If FILE_MATCHER is NULL or if PER_CU has
4646 dwarf2_per_cu_quick_data::MARK set (see
4647 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4648 EXPANSION_NOTIFY on it. */
4651 dw2_expand_symtabs_matching_one
4652 (dwarf2_per_cu_data
*per_cu
,
4653 dwarf2_per_objfile
*per_objfile
,
4654 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4655 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4657 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4659 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4661 compunit_symtab
*symtab
4662 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4663 gdb_assert (symtab
!= nullptr);
4665 if (expansion_notify
!= NULL
&& symtab_was_null
)
4666 expansion_notify (symtab
);
4670 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4671 matched, to expand corresponding CUs that were marked. IDX is the
4672 index of the symbol name that matched. */
4675 dw2_expand_marked_cus
4676 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4677 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4678 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4681 offset_type
*vec
, vec_len
, vec_idx
;
4682 bool global_seen
= false;
4683 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4685 vec
= (offset_type
*) (index
.constant_pool
4686 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4687 vec_len
= MAYBE_SWAP (vec
[0]);
4688 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4690 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4691 /* This value is only valid for index versions >= 7. */
4692 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4693 gdb_index_symbol_kind symbol_kind
=
4694 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4695 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4696 /* Only check the symbol attributes if they're present.
4697 Indices prior to version 7 don't record them,
4698 and indices >= 7 may elide them for certain symbols
4699 (gold does this). */
4702 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4704 /* Work around gold/15646. */
4707 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4715 /* Only check the symbol's kind if it has one. */
4720 case VARIABLES_DOMAIN
:
4721 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4724 case FUNCTIONS_DOMAIN
:
4725 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4729 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4732 case MODULES_DOMAIN
:
4733 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4741 /* Don't crash on bad data. */
4742 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
4743 + per_objfile
->per_bfd
->all_type_units
.size ()))
4745 complaint (_(".gdb_index entry has bad CU index"
4746 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4750 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
4751 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4756 /* If FILE_MATCHER is non-NULL, set all the
4757 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4758 that match FILE_MATCHER. */
4761 dw_expand_symtabs_matching_file_matcher
4762 (dwarf2_per_objfile
*per_objfile
,
4763 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4765 if (file_matcher
== NULL
)
4768 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4770 NULL
, xcalloc
, xfree
));
4771 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4773 NULL
, xcalloc
, xfree
));
4775 /* The rule is CUs specify all the files, including those used by
4776 any TU, so there's no need to scan TUs here. */
4778 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4782 per_cu
->v
.quick
->mark
= 0;
4784 /* We only need to look at symtabs not already expanded. */
4785 if (per_objfile
->symtab_set_p (per_cu
))
4788 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4789 if (file_data
== NULL
)
4792 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4794 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4796 per_cu
->v
.quick
->mark
= 1;
4800 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4802 const char *this_real_name
;
4804 if (file_matcher (file_data
->file_names
[j
], false))
4806 per_cu
->v
.quick
->mark
= 1;
4810 /* Before we invoke realpath, which can get expensive when many
4811 files are involved, do a quick comparison of the basenames. */
4812 if (!basenames_may_differ
4813 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4817 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4818 if (file_matcher (this_real_name
, false))
4820 per_cu
->v
.quick
->mark
= 1;
4825 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4826 ? visited_found
.get ()
4827 : visited_not_found
.get (),
4834 dw2_expand_symtabs_matching
4835 (struct objfile
*objfile
,
4836 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4837 const lookup_name_info
*lookup_name
,
4838 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4839 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4840 enum search_domain kind
)
4842 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4844 /* index_table is NULL if OBJF_READNOW. */
4845 if (!per_objfile
->per_bfd
->index_table
)
4848 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4850 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4852 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4856 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4857 file_matcher
, expansion_notify
);
4862 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4864 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4866 kind
, [&] (offset_type idx
)
4868 dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
, expansion_notify
,
4874 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4877 static struct compunit_symtab
*
4878 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4883 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4884 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4887 if (cust
->includes
== NULL
)
4890 for (i
= 0; cust
->includes
[i
]; ++i
)
4892 struct compunit_symtab
*s
= cust
->includes
[i
];
4894 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4902 static struct compunit_symtab
*
4903 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4904 struct bound_minimal_symbol msymbol
,
4906 struct obj_section
*section
,
4909 struct dwarf2_per_cu_data
*data
;
4910 struct compunit_symtab
*result
;
4912 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4915 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4916 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4917 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4921 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4922 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4923 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4924 paddress (objfile
->arch (), pc
));
4926 result
= recursively_find_pc_sect_compunit_symtab
4927 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4929 gdb_assert (result
!= NULL
);
4934 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4935 void *data
, int need_fullname
)
4937 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4939 if (!per_objfile
->per_bfd
->filenames_cache
)
4941 per_objfile
->per_bfd
->filenames_cache
.emplace ();
4943 htab_up
visited (htab_create_alloc (10,
4944 htab_hash_pointer
, htab_eq_pointer
,
4945 NULL
, xcalloc
, xfree
));
4947 /* The rule is CUs specify all the files, including those used
4948 by any TU, so there's no need to scan TUs here. We can
4949 ignore file names coming from already-expanded CUs. */
4951 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4953 if (per_objfile
->symtab_set_p (per_cu
))
4955 void **slot
= htab_find_slot (visited
.get (),
4956 per_cu
->v
.quick
->file_names
,
4959 *slot
= per_cu
->v
.quick
->file_names
;
4963 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4965 /* We only need to look at symtabs not already expanded. */
4966 if (per_objfile
->symtab_set_p (per_cu
))
4969 quick_file_names
*file_data
4970 = dw2_get_file_names (per_cu
, per_objfile
);
4971 if (file_data
== NULL
)
4974 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4977 /* Already visited. */
4982 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4984 const char *filename
= file_data
->file_names
[j
];
4985 per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4990 per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4992 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4995 this_real_name
= gdb_realpath (filename
);
4996 (*fun
) (filename
, this_real_name
.get (), data
);
5001 dw2_has_symbols (struct objfile
*objfile
)
5006 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5009 dw2_find_last_source_symtab
,
5010 dw2_forget_cached_source_info
,
5011 dw2_map_symtabs_matching_filename
,
5016 dw2_expand_symtabs_for_function
,
5017 dw2_expand_all_symtabs
,
5018 dw2_expand_symtabs_with_fullname
,
5019 dw2_map_matching_symbols
,
5020 dw2_expand_symtabs_matching
,
5021 dw2_find_pc_sect_compunit_symtab
,
5023 dw2_map_symbol_filenames
5026 /* DWARF-5 debug_names reader. */
5028 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5029 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5031 /* A helper function that reads the .debug_names section in SECTION
5032 and fills in MAP. FILENAME is the name of the file containing the
5033 section; it is used for error reporting.
5035 Returns true if all went well, false otherwise. */
5038 read_debug_names_from_section (struct objfile
*objfile
,
5039 const char *filename
,
5040 struct dwarf2_section_info
*section
,
5041 mapped_debug_names
&map
)
5043 if (section
->empty ())
5046 /* Older elfutils strip versions could keep the section in the main
5047 executable while splitting it for the separate debug info file. */
5048 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5051 section
->read (objfile
);
5053 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
5055 const gdb_byte
*addr
= section
->buffer
;
5057 bfd
*const abfd
= section
->get_bfd_owner ();
5059 unsigned int bytes_read
;
5060 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5063 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5064 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5065 if (bytes_read
+ length
!= section
->size
)
5067 /* There may be multiple per-CU indices. */
5068 warning (_("Section .debug_names in %s length %s does not match "
5069 "section length %s, ignoring .debug_names."),
5070 filename
, plongest (bytes_read
+ length
),
5071 pulongest (section
->size
));
5075 /* The version number. */
5076 uint16_t version
= read_2_bytes (abfd
, addr
);
5080 warning (_("Section .debug_names in %s has unsupported version %d, "
5081 "ignoring .debug_names."),
5087 uint16_t padding
= read_2_bytes (abfd
, addr
);
5091 warning (_("Section .debug_names in %s has unsupported padding %d, "
5092 "ignoring .debug_names."),
5097 /* comp_unit_count - The number of CUs in the CU list. */
5098 map
.cu_count
= read_4_bytes (abfd
, addr
);
5101 /* local_type_unit_count - The number of TUs in the local TU
5103 map
.tu_count
= read_4_bytes (abfd
, addr
);
5106 /* foreign_type_unit_count - The number of TUs in the foreign TU
5108 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5110 if (foreign_tu_count
!= 0)
5112 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5113 "ignoring .debug_names."),
5114 filename
, static_cast<unsigned long> (foreign_tu_count
));
5118 /* bucket_count - The number of hash buckets in the hash lookup
5120 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5123 /* name_count - The number of unique names in the index. */
5124 map
.name_count
= read_4_bytes (abfd
, addr
);
5127 /* abbrev_table_size - The size in bytes of the abbreviations
5129 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5132 /* augmentation_string_size - The size in bytes of the augmentation
5133 string. This value is rounded up to a multiple of 4. */
5134 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5136 map
.augmentation_is_gdb
= ((augmentation_string_size
5137 == sizeof (dwarf5_augmentation
))
5138 && memcmp (addr
, dwarf5_augmentation
,
5139 sizeof (dwarf5_augmentation
)) == 0);
5140 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5141 addr
+= augmentation_string_size
;
5144 map
.cu_table_reordered
= addr
;
5145 addr
+= map
.cu_count
* map
.offset_size
;
5147 /* List of Local TUs */
5148 map
.tu_table_reordered
= addr
;
5149 addr
+= map
.tu_count
* map
.offset_size
;
5151 /* Hash Lookup Table */
5152 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5153 addr
+= map
.bucket_count
* 4;
5154 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5155 addr
+= map
.name_count
* 4;
5158 map
.name_table_string_offs_reordered
= addr
;
5159 addr
+= map
.name_count
* map
.offset_size
;
5160 map
.name_table_entry_offs_reordered
= addr
;
5161 addr
+= map
.name_count
* map
.offset_size
;
5163 const gdb_byte
*abbrev_table_start
= addr
;
5166 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5171 const auto insertpair
5172 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5173 if (!insertpair
.second
)
5175 warning (_("Section .debug_names in %s has duplicate index %s, "
5176 "ignoring .debug_names."),
5177 filename
, pulongest (index_num
));
5180 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5181 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5186 mapped_debug_names::index_val::attr attr
;
5187 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5189 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5191 if (attr
.form
== DW_FORM_implicit_const
)
5193 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5197 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5199 indexval
.attr_vec
.push_back (std::move (attr
));
5202 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5204 warning (_("Section .debug_names in %s has abbreviation_table "
5205 "of size %s vs. written as %u, ignoring .debug_names."),
5206 filename
, plongest (addr
- abbrev_table_start
),
5210 map
.entry_pool
= addr
;
5215 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5219 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5220 const mapped_debug_names
&map
,
5221 dwarf2_section_info
§ion
,
5224 if (!map
.augmentation_is_gdb
)
5226 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5228 sect_offset sect_off
5229 = (sect_offset
) (extract_unsigned_integer
5230 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5232 map
.dwarf5_byte_order
));
5233 /* We don't know the length of the CU, because the CU list in a
5234 .debug_names index can be incomplete, so we can't use the start of
5235 the next CU as end of this CU. We create the CUs here with length 0,
5236 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5237 dwarf2_per_cu_data
*per_cu
5238 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
, sect_off
, 0);
5239 per_bfd
->all_comp_units
.push_back (per_cu
);
5243 sect_offset sect_off_prev
;
5244 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5246 sect_offset sect_off_next
;
5247 if (i
< map
.cu_count
)
5250 = (sect_offset
) (extract_unsigned_integer
5251 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5253 map
.dwarf5_byte_order
));
5256 sect_off_next
= (sect_offset
) section
.size
;
5259 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5260 dwarf2_per_cu_data
*per_cu
5261 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5262 sect_off_prev
, length
);
5263 per_bfd
->all_comp_units
.push_back (per_cu
);
5265 sect_off_prev
= sect_off_next
;
5269 /* Read the CU list from the mapped index, and use it to create all
5270 the CU objects for this dwarf2_per_objfile. */
5273 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5274 const mapped_debug_names
&map
,
5275 const mapped_debug_names
&dwz_map
)
5277 gdb_assert (per_bfd
->all_comp_units
.empty ());
5278 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5280 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5281 false /* is_dwz */);
5283 if (dwz_map
.cu_count
== 0)
5286 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5287 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5291 /* Read .debug_names. If everything went ok, initialize the "quick"
5292 elements of all the CUs and return true. Otherwise, return false. */
5295 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
5297 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5298 mapped_debug_names dwz_map
;
5299 struct objfile
*objfile
= per_objfile
->objfile
;
5300 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5302 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5303 &per_objfile
->per_bfd
->debug_names
, *map
))
5306 /* Don't use the index if it's empty. */
5307 if (map
->name_count
== 0)
5310 /* If there is a .dwz file, read it so we can get its CU list as
5312 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5315 if (!read_debug_names_from_section (objfile
,
5316 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5317 &dwz
->debug_names
, dwz_map
))
5319 warning (_("could not read '.debug_names' section from %s; skipping"),
5320 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5325 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
5327 if (map
->tu_count
!= 0)
5329 /* We can only handle a single .debug_types when we have an
5331 if (per_bfd
->types
.size () != 1)
5334 dwarf2_section_info
*section
= &per_bfd
->types
[0];
5336 create_signatured_type_table_from_debug_names
5337 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
5340 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
5342 per_bfd
->debug_names_table
= std::move (map
);
5343 per_bfd
->using_index
= 1;
5344 per_bfd
->quick_file_names_table
=
5345 create_quick_file_names_table (per_objfile
->per_bfd
->all_comp_units
.size ());
5347 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
5348 objfiles using the same BFD. */
5349 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
5350 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
5355 /* Type used to manage iterating over all CUs looking for a symbol for
5358 class dw2_debug_names_iterator
5361 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5362 gdb::optional
<block_enum
> block_index
,
5364 const char *name
, dwarf2_per_objfile
*per_objfile
)
5365 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5366 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5367 m_per_objfile (per_objfile
)
5370 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5371 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5374 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5375 m_per_objfile (per_objfile
)
5378 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5379 block_enum block_index
, domain_enum domain
,
5380 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5381 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5382 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5383 m_per_objfile (per_objfile
)
5386 /* Return the next matching CU or NULL if there are no more. */
5387 dwarf2_per_cu_data
*next ();
5390 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5392 dwarf2_per_objfile
*per_objfile
);
5393 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5395 dwarf2_per_objfile
*per_objfile
);
5397 /* The internalized form of .debug_names. */
5398 const mapped_debug_names
&m_map
;
5400 /* If set, only look for symbols that match that block. Valid values are
5401 GLOBAL_BLOCK and STATIC_BLOCK. */
5402 const gdb::optional
<block_enum
> m_block_index
;
5404 /* The kind of symbol we're looking for. */
5405 const domain_enum m_domain
= UNDEF_DOMAIN
;
5406 const search_domain m_search
= ALL_DOMAIN
;
5408 /* The list of CUs from the index entry of the symbol, or NULL if
5410 const gdb_byte
*m_addr
;
5412 dwarf2_per_objfile
*m_per_objfile
;
5416 mapped_debug_names::namei_to_name
5417 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5419 const ULONGEST namei_string_offs
5420 = extract_unsigned_integer ((name_table_string_offs_reordered
5421 + namei
* offset_size
),
5424 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5427 /* Find a slot in .debug_names for the object named NAME. If NAME is
5428 found, return pointer to its pool data. If NAME cannot be found,
5432 dw2_debug_names_iterator::find_vec_in_debug_names
5433 (const mapped_debug_names
&map
, const char *name
,
5434 dwarf2_per_objfile
*per_objfile
)
5436 int (*cmp
) (const char *, const char *);
5438 gdb::unique_xmalloc_ptr
<char> without_params
;
5439 if (current_language
->la_language
== language_cplus
5440 || current_language
->la_language
== language_fortran
5441 || current_language
->la_language
== language_d
)
5443 /* NAME is already canonical. Drop any qualifiers as
5444 .debug_names does not contain any. */
5446 if (strchr (name
, '(') != NULL
)
5448 without_params
= cp_remove_params (name
);
5449 if (without_params
!= NULL
)
5450 name
= without_params
.get ();
5454 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5456 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5458 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5459 (map
.bucket_table_reordered
5460 + (full_hash
% map
.bucket_count
)), 4,
5461 map
.dwarf5_byte_order
);
5465 if (namei
>= map
.name_count
)
5467 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5469 namei
, map
.name_count
,
5470 objfile_name (per_objfile
->objfile
));
5476 const uint32_t namei_full_hash
5477 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5478 (map
.hash_table_reordered
+ namei
), 4,
5479 map
.dwarf5_byte_order
);
5480 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5483 if (full_hash
== namei_full_hash
)
5485 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5487 #if 0 /* An expensive sanity check. */
5488 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5490 complaint (_("Wrong .debug_names hash for string at index %u "
5492 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5497 if (cmp (namei_string
, name
) == 0)
5499 const ULONGEST namei_entry_offs
5500 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5501 + namei
* map
.offset_size
),
5502 map
.offset_size
, map
.dwarf5_byte_order
);
5503 return map
.entry_pool
+ namei_entry_offs
;
5508 if (namei
>= map
.name_count
)
5514 dw2_debug_names_iterator::find_vec_in_debug_names
5515 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5517 if (namei
>= map
.name_count
)
5519 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5521 namei
, map
.name_count
,
5522 objfile_name (per_objfile
->objfile
));
5526 const ULONGEST namei_entry_offs
5527 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5528 + namei
* map
.offset_size
),
5529 map
.offset_size
, map
.dwarf5_byte_order
);
5530 return map
.entry_pool
+ namei_entry_offs
;
5533 /* See dw2_debug_names_iterator. */
5535 dwarf2_per_cu_data
*
5536 dw2_debug_names_iterator::next ()
5541 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5542 struct objfile
*objfile
= m_per_objfile
->objfile
;
5543 bfd
*const abfd
= objfile
->obfd
;
5547 unsigned int bytes_read
;
5548 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5549 m_addr
+= bytes_read
;
5553 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5554 if (indexval_it
== m_map
.abbrev_map
.cend ())
5556 complaint (_("Wrong .debug_names undefined abbrev code %s "
5558 pulongest (abbrev
), objfile_name (objfile
));
5561 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5562 enum class symbol_linkage
{
5566 } symbol_linkage_
= symbol_linkage::unknown
;
5567 dwarf2_per_cu_data
*per_cu
= NULL
;
5568 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5573 case DW_FORM_implicit_const
:
5574 ull
= attr
.implicit_const
;
5576 case DW_FORM_flag_present
:
5580 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5581 m_addr
+= bytes_read
;
5584 ull
= read_4_bytes (abfd
, m_addr
);
5588 ull
= read_8_bytes (abfd
, m_addr
);
5591 case DW_FORM_ref_sig8
:
5592 ull
= read_8_bytes (abfd
, m_addr
);
5596 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5597 dwarf_form_name (attr
.form
),
5598 objfile_name (objfile
));
5601 switch (attr
.dw_idx
)
5603 case DW_IDX_compile_unit
:
5604 /* Don't crash on bad data. */
5605 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5607 complaint (_(".debug_names entry has bad CU index %s"
5610 objfile_name (objfile
));
5613 per_cu
= per_bfd
->get_cutu (ull
);
5615 case DW_IDX_type_unit
:
5616 /* Don't crash on bad data. */
5617 if (ull
>= per_bfd
->all_type_units
.size ())
5619 complaint (_(".debug_names entry has bad TU index %s"
5622 objfile_name (objfile
));
5625 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5627 case DW_IDX_die_offset
:
5628 /* In a per-CU index (as opposed to a per-module index), index
5629 entries without CU attribute implicitly refer to the single CU. */
5631 per_cu
= per_bfd
->get_cu (0);
5633 case DW_IDX_GNU_internal
:
5634 if (!m_map
.augmentation_is_gdb
)
5636 symbol_linkage_
= symbol_linkage::static_
;
5638 case DW_IDX_GNU_external
:
5639 if (!m_map
.augmentation_is_gdb
)
5641 symbol_linkage_
= symbol_linkage::extern_
;
5646 /* Skip if already read in. */
5647 if (m_per_objfile
->symtab_set_p (per_cu
))
5650 /* Check static vs global. */
5651 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5653 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5654 const bool symbol_is_static
=
5655 symbol_linkage_
== symbol_linkage::static_
;
5656 if (want_static
!= symbol_is_static
)
5660 /* Match dw2_symtab_iter_next, symbol_kind
5661 and debug_names::psymbol_tag. */
5665 switch (indexval
.dwarf_tag
)
5667 case DW_TAG_variable
:
5668 case DW_TAG_subprogram
:
5669 /* Some types are also in VAR_DOMAIN. */
5670 case DW_TAG_typedef
:
5671 case DW_TAG_structure_type
:
5678 switch (indexval
.dwarf_tag
)
5680 case DW_TAG_typedef
:
5681 case DW_TAG_structure_type
:
5688 switch (indexval
.dwarf_tag
)
5691 case DW_TAG_variable
:
5698 switch (indexval
.dwarf_tag
)
5710 /* Match dw2_expand_symtabs_matching, symbol_kind and
5711 debug_names::psymbol_tag. */
5714 case VARIABLES_DOMAIN
:
5715 switch (indexval
.dwarf_tag
)
5717 case DW_TAG_variable
:
5723 case FUNCTIONS_DOMAIN
:
5724 switch (indexval
.dwarf_tag
)
5726 case DW_TAG_subprogram
:
5733 switch (indexval
.dwarf_tag
)
5735 case DW_TAG_typedef
:
5736 case DW_TAG_structure_type
:
5742 case MODULES_DOMAIN
:
5743 switch (indexval
.dwarf_tag
)
5757 static struct compunit_symtab
*
5758 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5759 const char *name
, domain_enum domain
)
5761 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5763 const auto &mapp
= per_objfile
->per_bfd
->debug_names_table
;
5766 /* index is NULL if OBJF_READNOW. */
5769 const auto &map
= *mapp
;
5771 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
, per_objfile
);
5773 struct compunit_symtab
*stab_best
= NULL
;
5774 struct dwarf2_per_cu_data
*per_cu
;
5775 while ((per_cu
= iter
.next ()) != NULL
)
5777 struct symbol
*sym
, *with_opaque
= NULL
;
5778 compunit_symtab
*stab
5779 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5780 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5781 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5783 sym
= block_find_symbol (block
, name
, domain
,
5784 block_find_non_opaque_type_preferred
,
5787 /* Some caution must be observed with overloaded functions and
5788 methods, since the index will not contain any overload
5789 information (but NAME might contain it). */
5792 && strcmp_iw (sym
->search_name (), name
) == 0)
5794 if (with_opaque
!= NULL
5795 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5798 /* Keep looking through other CUs. */
5804 /* This dumps minimal information about .debug_names. It is called
5805 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5806 uses this to verify that .debug_names has been loaded. */
5809 dw2_debug_names_dump (struct objfile
*objfile
)
5811 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5813 gdb_assert (per_objfile
->per_bfd
->using_index
);
5814 printf_filtered (".debug_names:");
5815 if (per_objfile
->per_bfd
->debug_names_table
)
5816 printf_filtered (" exists\n");
5818 printf_filtered (" faked for \"readnow\"\n");
5819 printf_filtered ("\n");
5823 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5824 const char *func_name
)
5826 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5828 /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5829 if (per_objfile
->per_bfd
->debug_names_table
)
5831 const mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5833 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5836 struct dwarf2_per_cu_data
*per_cu
;
5837 while ((per_cu
= iter
.next ()) != NULL
)
5838 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5843 dw2_debug_names_map_matching_symbols
5844 (struct objfile
*objfile
,
5845 const lookup_name_info
&name
, domain_enum domain
,
5847 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5848 symbol_compare_ftype
*ordered_compare
)
5850 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5852 /* debug_names_table is NULL if OBJF_READNOW. */
5853 if (!per_objfile
->per_bfd
->debug_names_table
)
5856 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5857 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5859 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5860 auto matcher
= [&] (const char *symname
)
5862 if (ordered_compare
== nullptr)
5864 return ordered_compare (symname
, match_name
) == 0;
5867 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5868 [&] (offset_type namei
)
5870 /* The name was matched, now expand corresponding CUs that were
5872 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5875 struct dwarf2_per_cu_data
*per_cu
;
5876 while ((per_cu
= iter
.next ()) != NULL
)
5877 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5882 /* It's a shame we couldn't do this inside the
5883 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5884 that have already been expanded. Instead, this loop matches what
5885 the psymtab code does. */
5886 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5888 compunit_symtab
*symtab
= per_objfile
->get_symtab (per_cu
);
5889 if (symtab
!= nullptr)
5891 const struct block
*block
5892 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5893 if (!iterate_over_symbols_terminated (block
, name
,
5901 dw2_debug_names_expand_symtabs_matching
5902 (struct objfile
*objfile
,
5903 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5904 const lookup_name_info
*lookup_name
,
5905 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5906 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5907 enum search_domain kind
)
5909 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5911 /* debug_names_table is NULL if OBJF_READNOW. */
5912 if (!per_objfile
->per_bfd
->debug_names_table
)
5915 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5917 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5919 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5923 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5929 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5931 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5933 kind
, [&] (offset_type namei
)
5935 /* The name was matched, now expand corresponding CUs that were
5937 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
);
5939 struct dwarf2_per_cu_data
*per_cu
;
5940 while ((per_cu
= iter
.next ()) != NULL
)
5941 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5947 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5950 dw2_find_last_source_symtab
,
5951 dw2_forget_cached_source_info
,
5952 dw2_map_symtabs_matching_filename
,
5953 dw2_debug_names_lookup_symbol
,
5956 dw2_debug_names_dump
,
5957 dw2_debug_names_expand_symtabs_for_function
,
5958 dw2_expand_all_symtabs
,
5959 dw2_expand_symtabs_with_fullname
,
5960 dw2_debug_names_map_matching_symbols
,
5961 dw2_debug_names_expand_symtabs_matching
,
5962 dw2_find_pc_sect_compunit_symtab
,
5964 dw2_map_symbol_filenames
5967 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5968 to either a dwarf2_per_bfd or dwz_file object. */
5970 template <typename T
>
5971 static gdb::array_view
<const gdb_byte
>
5972 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5974 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5976 if (section
->empty ())
5979 /* Older elfutils strip versions could keep the section in the main
5980 executable while splitting it for the separate debug info file. */
5981 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5984 section
->read (obj
);
5986 /* dwarf2_section_info::size is a bfd_size_type, while
5987 gdb::array_view works with size_t. On 32-bit hosts, with
5988 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5989 is 32-bit. So we need an explicit narrowing conversion here.
5990 This is fine, because it's impossible to allocate or mmap an
5991 array/buffer larger than what size_t can represent. */
5992 return gdb::make_array_view (section
->buffer
, section
->size
);
5995 /* Lookup the index cache for the contents of the index associated to
5998 static gdb::array_view
<const gdb_byte
>
5999 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
6001 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6002 if (build_id
== nullptr)
6005 return global_index_cache
.lookup_gdb_index (build_id
,
6006 &dwarf2_per_bfd
->index_cache_res
);
6009 /* Same as the above, but for DWZ. */
6011 static gdb::array_view
<const gdb_byte
>
6012 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6014 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6015 if (build_id
== nullptr)
6018 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6021 /* See symfile.h. */
6024 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6026 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6027 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6029 /* If we're about to read full symbols, don't bother with the
6030 indices. In this case we also don't care if some other debug
6031 format is making psymtabs, because they are all about to be
6033 if ((objfile
->flags
& OBJF_READNOW
))
6035 /* When using READNOW, the using_index flag (set below) indicates that
6036 PER_BFD was already initialized, when we loaded some other objfile. */
6037 if (per_bfd
->using_index
)
6039 *index_kind
= dw_index_kind::GDB_INDEX
;
6040 per_objfile
->resize_symtabs ();
6044 per_bfd
->using_index
= 1;
6045 create_all_comp_units (per_objfile
);
6046 create_all_type_units (per_objfile
);
6047 per_bfd
->quick_file_names_table
6048 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
6049 per_objfile
->resize_symtabs ();
6051 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
6052 + per_bfd
->all_type_units
.size ()); ++i
)
6054 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
6056 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6057 struct dwarf2_per_cu_quick_data
);
6060 /* Return 1 so that gdb sees the "quick" functions. However,
6061 these functions will be no-ops because we will have expanded
6063 *index_kind
= dw_index_kind::GDB_INDEX
;
6067 /* Was a debug names index already read when we processed an objfile sharing
6069 if (per_bfd
->debug_names_table
!= nullptr)
6071 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6072 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6073 per_objfile
->resize_symtabs ();
6077 /* Was a GDB index already read when we processed an objfile sharing
6079 if (per_bfd
->index_table
!= nullptr)
6081 *index_kind
= dw_index_kind::GDB_INDEX
;
6082 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6083 per_objfile
->resize_symtabs ();
6087 /* There might already be partial symtabs built for this BFD. This happens
6088 when loading the same binary twice with the index-cache enabled. If so,
6089 don't try to read an index. The objfile / per_objfile initialization will
6090 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
6092 if (per_bfd
->partial_symtabs
!= nullptr)
6095 if (dwarf2_read_debug_names (per_objfile
))
6097 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6098 per_objfile
->resize_symtabs ();
6102 if (dwarf2_read_gdb_index (per_objfile
,
6103 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
6104 get_gdb_index_contents_from_section
<dwz_file
>))
6106 *index_kind
= dw_index_kind::GDB_INDEX
;
6107 per_objfile
->resize_symtabs ();
6111 /* ... otherwise, try to find the index in the index cache. */
6112 if (dwarf2_read_gdb_index (per_objfile
,
6113 get_gdb_index_contents_from_cache
,
6114 get_gdb_index_contents_from_cache_dwz
))
6116 global_index_cache
.hit ();
6117 *index_kind
= dw_index_kind::GDB_INDEX
;
6118 per_objfile
->resize_symtabs ();
6122 global_index_cache
.miss ();
6128 /* Build a partial symbol table. */
6131 dwarf2_build_psymtabs (struct objfile
*objfile
)
6133 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6134 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6136 if (per_bfd
->partial_symtabs
!= nullptr)
6138 /* Partial symbols were already read, so now we can simply
6140 objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6141 per_objfile
->resize_symtabs ();
6147 /* This isn't really ideal: all the data we allocate on the
6148 objfile's obstack is still uselessly kept around. However,
6149 freeing it seems unsafe. */
6150 psymtab_discarder
psymtabs (objfile
);
6151 dwarf2_build_psymtabs_hard (per_objfile
);
6154 per_objfile
->resize_symtabs ();
6156 /* (maybe) store an index in the cache. */
6157 global_index_cache
.store (per_objfile
);
6159 catch (const gdb_exception_error
&except
)
6161 exception_print (gdb_stderr
, except
);
6164 /* Finish by setting the local reference to partial symtabs, so that
6165 we don't try to read them again if reading another objfile with the same
6166 BFD. If we can't in fact share, this won't make a difference anyway as
6167 the dwarf2_per_bfd object won't be shared. */
6168 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
6171 /* Find the base address of the compilation unit for range lists and
6172 location lists. It will normally be specified by DW_AT_low_pc.
6173 In DWARF-3 draft 4, the base address could be overridden by
6174 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6175 compilation units with discontinuous ranges. */
6178 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6180 struct attribute
*attr
;
6182 cu
->base_address
.reset ();
6184 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6185 if (attr
!= nullptr)
6186 cu
->base_address
= attr
->as_address ();
6189 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6190 if (attr
!= nullptr)
6191 cu
->base_address
= attr
->as_address ();
6195 /* Helper function that returns the proper abbrev section for
6198 static struct dwarf2_section_info
*
6199 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6201 struct dwarf2_section_info
*abbrev
;
6202 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6204 if (this_cu
->is_dwz
)
6205 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6207 abbrev
= &per_bfd
->abbrev
;
6212 /* Fetch the abbreviation table offset from a comp or type unit header. */
6215 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
6216 struct dwarf2_section_info
*section
,
6217 sect_offset sect_off
)
6219 bfd
*abfd
= section
->get_bfd_owner ();
6220 const gdb_byte
*info_ptr
;
6221 unsigned int initial_length_size
, offset_size
;
6224 section
->read (per_objfile
->objfile
);
6225 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6226 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6227 offset_size
= initial_length_size
== 4 ? 4 : 8;
6228 info_ptr
+= initial_length_size
;
6230 version
= read_2_bytes (abfd
, info_ptr
);
6234 /* Skip unit type and address size. */
6238 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6241 /* A partial symtab that is used only for include files. */
6242 struct dwarf2_include_psymtab
: public partial_symtab
6244 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6245 : partial_symtab (filename
, objfile
)
6249 void read_symtab (struct objfile
*objfile
) override
6251 /* It's an include file, no symbols to read for it.
6252 Everything is in the includer symtab. */
6254 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6255 expansion of the includer psymtab. We use the dependencies[0] field to
6256 model the includer. But if we go the regular route of calling
6257 expand_psymtab here, and having expand_psymtab call expand_dependencies
6258 to expand the includer, we'll only use expand_psymtab on the includer
6259 (making it a non-toplevel psymtab), while if we expand the includer via
6260 another path, we'll use read_symtab (making it a toplevel psymtab).
6261 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6262 psymtab, and trigger read_symtab on the includer here directly. */
6263 includer ()->read_symtab (objfile
);
6266 void expand_psymtab (struct objfile
*objfile
) override
6268 /* This is not called by read_symtab, and should not be called by any
6269 expand_dependencies. */
6273 bool readin_p (struct objfile
*objfile
) const override
6275 return includer ()->readin_p (objfile
);
6278 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6284 partial_symtab
*includer () const
6286 /* An include psymtab has exactly one dependency: the psymtab that
6288 gdb_assert (this->number_of_dependencies
== 1);
6289 return this->dependencies
[0];
6293 /* Allocate a new partial symtab for file named NAME and mark this new
6294 partial symtab as being an include of PST. */
6297 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6298 struct objfile
*objfile
)
6300 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6302 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6303 subpst
->dirname
= pst
->dirname
;
6305 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6306 subpst
->dependencies
[0] = pst
;
6307 subpst
->number_of_dependencies
= 1;
6310 /* Read the Line Number Program data and extract the list of files
6311 included by the source file represented by PST. Build an include
6312 partial symtab for each of these included files. */
6315 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6316 struct die_info
*die
,
6317 dwarf2_psymtab
*pst
)
6320 struct attribute
*attr
;
6322 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6323 if (attr
!= nullptr && attr
->form_is_unsigned ())
6324 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
6326 return; /* No linetable, so no includes. */
6328 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6329 that we pass in the raw text_low here; that is ok because we're
6330 only decoding the line table to make include partial symtabs, and
6331 so the addresses aren't really used. */
6332 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6333 pst
->raw_text_low (), 1);
6337 hash_signatured_type (const void *item
)
6339 const struct signatured_type
*sig_type
6340 = (const struct signatured_type
*) item
;
6342 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6343 return sig_type
->signature
;
6347 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6349 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6350 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6352 return lhs
->signature
== rhs
->signature
;
6355 /* Allocate a hash table for signatured types. */
6358 allocate_signatured_type_table ()
6360 return htab_up (htab_create_alloc (41,
6361 hash_signatured_type
,
6363 NULL
, xcalloc
, xfree
));
6366 /* A helper function to add a signatured type CU to a table. */
6369 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6371 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6372 std::vector
<signatured_type
*> *all_type_units
6373 = (std::vector
<signatured_type
*> *) datum
;
6375 all_type_units
->push_back (sigt
);
6380 /* A helper for create_debug_types_hash_table. Read types from SECTION
6381 and fill them into TYPES_HTAB. It will process only type units,
6382 therefore DW_UT_type. */
6385 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6386 struct dwo_file
*dwo_file
,
6387 dwarf2_section_info
*section
, htab_up
&types_htab
,
6388 rcuh_kind section_kind
)
6390 struct objfile
*objfile
= per_objfile
->objfile
;
6391 struct dwarf2_section_info
*abbrev_section
;
6393 const gdb_byte
*info_ptr
, *end_ptr
;
6395 abbrev_section
= (dwo_file
!= NULL
6396 ? &dwo_file
->sections
.abbrev
6397 : &per_objfile
->per_bfd
->abbrev
);
6399 dwarf_read_debug_printf ("Reading %s for %s:",
6400 section
->get_name (),
6401 abbrev_section
->get_file_name ());
6403 section
->read (objfile
);
6404 info_ptr
= section
->buffer
;
6406 if (info_ptr
== NULL
)
6409 /* We can't set abfd until now because the section may be empty or
6410 not present, in which case the bfd is unknown. */
6411 abfd
= section
->get_bfd_owner ();
6413 /* We don't use cutu_reader here because we don't need to read
6414 any dies: the signature is in the header. */
6416 end_ptr
= info_ptr
+ section
->size
;
6417 while (info_ptr
< end_ptr
)
6419 struct signatured_type
*sig_type
;
6420 struct dwo_unit
*dwo_tu
;
6422 const gdb_byte
*ptr
= info_ptr
;
6423 struct comp_unit_head header
;
6424 unsigned int length
;
6426 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6428 /* Initialize it due to a false compiler warning. */
6429 header
.signature
= -1;
6430 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6432 /* We need to read the type's signature in order to build the hash
6433 table, but we don't need anything else just yet. */
6435 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6436 abbrev_section
, ptr
, section_kind
);
6438 length
= header
.get_length ();
6440 /* Skip dummy type units. */
6441 if (ptr
>= info_ptr
+ length
6442 || peek_abbrev_code (abfd
, ptr
) == 0
6443 || (header
.unit_type
!= DW_UT_type
6444 && header
.unit_type
!= DW_UT_split_type
))
6450 if (types_htab
== NULL
)
6453 types_htab
= allocate_dwo_unit_table ();
6455 types_htab
= allocate_signatured_type_table ();
6461 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6462 dwo_tu
->dwo_file
= dwo_file
;
6463 dwo_tu
->signature
= header
.signature
;
6464 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6465 dwo_tu
->section
= section
;
6466 dwo_tu
->sect_off
= sect_off
;
6467 dwo_tu
->length
= length
;
6471 /* N.B.: type_offset is not usable if this type uses a DWO file.
6472 The real type_offset is in the DWO file. */
6474 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6475 sig_type
->signature
= header
.signature
;
6476 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6477 sig_type
->per_cu
.is_debug_types
= 1;
6478 sig_type
->per_cu
.section
= section
;
6479 sig_type
->per_cu
.sect_off
= sect_off
;
6480 sig_type
->per_cu
.length
= length
;
6483 slot
= htab_find_slot (types_htab
.get (),
6484 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6486 gdb_assert (slot
!= NULL
);
6489 sect_offset dup_sect_off
;
6493 const struct dwo_unit
*dup_tu
6494 = (const struct dwo_unit
*) *slot
;
6496 dup_sect_off
= dup_tu
->sect_off
;
6500 const struct signatured_type
*dup_tu
6501 = (const struct signatured_type
*) *slot
;
6503 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6506 complaint (_("debug type entry at offset %s is duplicate to"
6507 " the entry at offset %s, signature %s"),
6508 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6509 hex_string (header
.signature
));
6511 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6513 dwarf_read_debug_printf_v (" offset %s, signature %s",
6514 sect_offset_str (sect_off
),
6515 hex_string (header
.signature
));
6521 /* Create the hash table of all entries in the .debug_types
6522 (or .debug_types.dwo) section(s).
6523 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6524 otherwise it is NULL.
6526 The result is a pointer to the hash table or NULL if there are no types.
6528 Note: This function processes DWO files only, not DWP files. */
6531 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6532 struct dwo_file
*dwo_file
,
6533 gdb::array_view
<dwarf2_section_info
> type_sections
,
6534 htab_up
&types_htab
)
6536 for (dwarf2_section_info
§ion
: type_sections
)
6537 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6541 /* Create the hash table of all entries in the .debug_types section,
6542 and initialize all_type_units.
6543 The result is zero if there is an error (e.g. missing .debug_types section),
6544 otherwise non-zero. */
6547 create_all_type_units (dwarf2_per_objfile
*per_objfile
)
6551 create_debug_type_hash_table (per_objfile
, NULL
, &per_objfile
->per_bfd
->info
,
6552 types_htab
, rcuh_kind::COMPILE
);
6553 create_debug_types_hash_table (per_objfile
, NULL
, per_objfile
->per_bfd
->types
,
6555 if (types_htab
== NULL
)
6557 per_objfile
->per_bfd
->signatured_types
= NULL
;
6561 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6563 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
6564 per_objfile
->per_bfd
->all_type_units
.reserve
6565 (htab_elements (per_objfile
->per_bfd
->signatured_types
.get ()));
6567 htab_traverse_noresize (per_objfile
->per_bfd
->signatured_types
.get (),
6568 add_signatured_type_cu_to_table
,
6569 &per_objfile
->per_bfd
->all_type_units
);
6574 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6575 If SLOT is non-NULL, it is the entry to use in the hash table.
6576 Otherwise we find one. */
6578 static struct signatured_type
*
6579 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6581 if (per_objfile
->per_bfd
->all_type_units
.size ()
6582 == per_objfile
->per_bfd
->all_type_units
.capacity ())
6583 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6585 signatured_type
*sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6587 per_objfile
->resize_symtabs ();
6589 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6590 sig_type
->signature
= sig
;
6591 sig_type
->per_cu
.is_debug_types
= 1;
6592 if (per_objfile
->per_bfd
->using_index
)
6594 sig_type
->per_cu
.v
.quick
=
6595 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6596 struct dwarf2_per_cu_quick_data
);
6601 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6604 gdb_assert (*slot
== NULL
);
6606 /* The rest of sig_type must be filled in by the caller. */
6610 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6611 Fill in SIG_ENTRY with DWO_ENTRY. */
6614 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6615 struct signatured_type
*sig_entry
,
6616 struct dwo_unit
*dwo_entry
)
6618 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6620 /* Make sure we're not clobbering something we don't expect to. */
6621 gdb_assert (! sig_entry
->per_cu
.queued
);
6622 gdb_assert (per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6623 if (per_bfd
->using_index
)
6625 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6626 gdb_assert (!per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6629 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6630 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6631 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6632 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6633 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6635 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6636 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6637 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6638 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6639 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6640 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6641 sig_entry
->dwo_unit
= dwo_entry
;
6644 /* Subroutine of lookup_signatured_type.
6645 If we haven't read the TU yet, create the signatured_type data structure
6646 for a TU to be read in directly from a DWO file, bypassing the stub.
6647 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6648 using .gdb_index, then when reading a CU we want to stay in the DWO file
6649 containing that CU. Otherwise we could end up reading several other DWO
6650 files (due to comdat folding) to process the transitive closure of all the
6651 mentioned TUs, and that can be slow. The current DWO file will have every
6652 type signature that it needs.
6653 We only do this for .gdb_index because in the psymtab case we already have
6654 to read all the DWOs to build the type unit groups. */
6656 static struct signatured_type
*
6657 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6659 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6660 struct dwo_file
*dwo_file
;
6661 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6662 struct signatured_type find_sig_entry
, *sig_entry
;
6665 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6667 /* If TU skeletons have been removed then we may not have read in any
6669 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6670 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6672 /* We only ever need to read in one copy of a signatured type.
6673 Use the global signatured_types array to do our own comdat-folding
6674 of types. If this is the first time we're reading this TU, and
6675 the TU has an entry in .gdb_index, replace the recorded data from
6676 .gdb_index with this TU. */
6678 find_sig_entry
.signature
= sig
;
6679 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6680 &find_sig_entry
, INSERT
);
6681 sig_entry
= (struct signatured_type
*) *slot
;
6683 /* We can get here with the TU already read, *or* in the process of being
6684 read. Don't reassign the global entry to point to this DWO if that's
6685 the case. Also note that if the TU is already being read, it may not
6686 have come from a DWO, the program may be a mix of Fission-compiled
6687 code and non-Fission-compiled code. */
6689 /* Have we already tried to read this TU?
6690 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6691 needn't exist in the global table yet). */
6692 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6695 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6696 dwo_unit of the TU itself. */
6697 dwo_file
= cu
->dwo_unit
->dwo_file
;
6699 /* Ok, this is the first time we're reading this TU. */
6700 if (dwo_file
->tus
== NULL
)
6702 find_dwo_entry
.signature
= sig
;
6703 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6705 if (dwo_entry
== NULL
)
6708 /* If the global table doesn't have an entry for this TU, add one. */
6709 if (sig_entry
== NULL
)
6710 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6712 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6713 sig_entry
->per_cu
.tu_read
= 1;
6717 /* Subroutine of lookup_signatured_type.
6718 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6719 then try the DWP file. If the TU stub (skeleton) has been removed then
6720 it won't be in .gdb_index. */
6722 static struct signatured_type
*
6723 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6725 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6726 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6727 struct dwo_unit
*dwo_entry
;
6728 struct signatured_type find_sig_entry
, *sig_entry
;
6731 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6732 gdb_assert (dwp_file
!= NULL
);
6734 /* If TU skeletons have been removed then we may not have read in any
6736 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6737 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6739 find_sig_entry
.signature
= sig
;
6740 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6741 &find_sig_entry
, INSERT
);
6742 sig_entry
= (struct signatured_type
*) *slot
;
6744 /* Have we already tried to read this TU?
6745 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6746 needn't exist in the global table yet). */
6747 if (sig_entry
!= NULL
)
6750 if (dwp_file
->tus
== NULL
)
6752 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6753 1 /* is_debug_types */);
6754 if (dwo_entry
== NULL
)
6757 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6758 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6763 /* Lookup a signature based type for DW_FORM_ref_sig8.
6764 Returns NULL if signature SIG is not present in the table.
6765 It is up to the caller to complain about this. */
6767 static struct signatured_type
*
6768 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6770 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6772 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6774 /* We're in a DWO/DWP file, and we're using .gdb_index.
6775 These cases require special processing. */
6776 if (get_dwp_file (per_objfile
) == NULL
)
6777 return lookup_dwo_signatured_type (cu
, sig
);
6779 return lookup_dwp_signatured_type (cu
, sig
);
6783 struct signatured_type find_entry
, *entry
;
6785 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6787 find_entry
.signature
= sig
;
6788 entry
= ((struct signatured_type
*)
6789 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6795 /* Low level DIE reading support. */
6797 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6800 init_cu_die_reader (struct die_reader_specs
*reader
,
6801 struct dwarf2_cu
*cu
,
6802 struct dwarf2_section_info
*section
,
6803 struct dwo_file
*dwo_file
,
6804 struct abbrev_table
*abbrev_table
)
6806 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6807 reader
->abfd
= section
->get_bfd_owner ();
6809 reader
->dwo_file
= dwo_file
;
6810 reader
->die_section
= section
;
6811 reader
->buffer
= section
->buffer
;
6812 reader
->buffer_end
= section
->buffer
+ section
->size
;
6813 reader
->abbrev_table
= abbrev_table
;
6816 /* Subroutine of cutu_reader to simplify it.
6817 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6818 There's just a lot of work to do, and cutu_reader is big enough
6821 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6822 from it to the DIE in the DWO. If NULL we are skipping the stub.
6823 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6824 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6825 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6826 STUB_COMP_DIR may be non-NULL.
6827 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6828 are filled in with the info of the DIE from the DWO file.
6829 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6830 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6831 kept around for at least as long as *RESULT_READER.
6833 The result is non-zero if a valid (non-dummy) DIE was found. */
6836 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6837 struct dwo_unit
*dwo_unit
,
6838 struct die_info
*stub_comp_unit_die
,
6839 const char *stub_comp_dir
,
6840 struct die_reader_specs
*result_reader
,
6841 const gdb_byte
**result_info_ptr
,
6842 struct die_info
**result_comp_unit_die
,
6843 abbrev_table_up
*result_dwo_abbrev_table
)
6845 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6846 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6847 struct objfile
*objfile
= per_objfile
->objfile
;
6849 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6850 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6851 int i
,num_extra_attrs
;
6852 struct dwarf2_section_info
*dwo_abbrev_section
;
6853 struct die_info
*comp_unit_die
;
6855 /* At most one of these may be provided. */
6856 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6858 /* These attributes aren't processed until later:
6859 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6860 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6861 referenced later. However, these attributes are found in the stub
6862 which we won't have later. In order to not impose this complication
6863 on the rest of the code, we read them here and copy them to the
6872 if (stub_comp_unit_die
!= NULL
)
6874 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6876 if (!per_cu
->is_debug_types
)
6877 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6878 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6879 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6880 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6881 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6883 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6885 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6886 here (if needed). We need the value before we can process
6888 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6890 else if (stub_comp_dir
!= NULL
)
6892 /* Reconstruct the comp_dir attribute to simplify the code below. */
6893 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6894 comp_dir
->name
= DW_AT_comp_dir
;
6895 comp_dir
->form
= DW_FORM_string
;
6896 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6899 /* Set up for reading the DWO CU/TU. */
6900 cu
->dwo_unit
= dwo_unit
;
6901 dwarf2_section_info
*section
= dwo_unit
->section
;
6902 section
->read (objfile
);
6903 abfd
= section
->get_bfd_owner ();
6904 begin_info_ptr
= info_ptr
= (section
->buffer
6905 + to_underlying (dwo_unit
->sect_off
));
6906 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6908 if (per_cu
->is_debug_types
)
6910 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6912 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6913 section
, dwo_abbrev_section
,
6914 info_ptr
, rcuh_kind::TYPE
);
6915 /* This is not an assert because it can be caused by bad debug info. */
6916 if (sig_type
->signature
!= cu
->header
.signature
)
6918 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6919 " TU at offset %s [in module %s]"),
6920 hex_string (sig_type
->signature
),
6921 hex_string (cu
->header
.signature
),
6922 sect_offset_str (dwo_unit
->sect_off
),
6923 bfd_get_filename (abfd
));
6925 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6926 /* For DWOs coming from DWP files, we don't know the CU length
6927 nor the type's offset in the TU until now. */
6928 dwo_unit
->length
= cu
->header
.get_length ();
6929 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6931 /* Establish the type offset that can be used to lookup the type.
6932 For DWO files, we don't know it until now. */
6933 sig_type
->type_offset_in_section
6934 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6938 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6939 section
, dwo_abbrev_section
,
6940 info_ptr
, rcuh_kind::COMPILE
);
6941 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6942 /* For DWOs coming from DWP files, we don't know the CU length
6944 dwo_unit
->length
= cu
->header
.get_length ();
6947 dwo_abbrev_section
->read (objfile
);
6948 *result_dwo_abbrev_table
6949 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6950 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6951 result_dwo_abbrev_table
->get ());
6953 /* Read in the die, but leave space to copy over the attributes
6954 from the stub. This has the benefit of simplifying the rest of
6955 the code - all the work to maintain the illusion of a single
6956 DW_TAG_{compile,type}_unit DIE is done here. */
6957 num_extra_attrs
= ((stmt_list
!= NULL
)
6961 + (comp_dir
!= NULL
));
6962 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6965 /* Copy over the attributes from the stub to the DIE we just read in. */
6966 comp_unit_die
= *result_comp_unit_die
;
6967 i
= comp_unit_die
->num_attrs
;
6968 if (stmt_list
!= NULL
)
6969 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6971 comp_unit_die
->attrs
[i
++] = *low_pc
;
6972 if (high_pc
!= NULL
)
6973 comp_unit_die
->attrs
[i
++] = *high_pc
;
6975 comp_unit_die
->attrs
[i
++] = *ranges
;
6976 if (comp_dir
!= NULL
)
6977 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6978 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6980 if (dwarf_die_debug
)
6982 fprintf_unfiltered (gdb_stdlog
,
6983 "Read die from %s@0x%x of %s:\n",
6984 section
->get_name (),
6985 (unsigned) (begin_info_ptr
- section
->buffer
),
6986 bfd_get_filename (abfd
));
6987 dump_die (comp_unit_die
, dwarf_die_debug
);
6990 /* Skip dummy compilation units. */
6991 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6992 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6995 *result_info_ptr
= info_ptr
;
6999 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7000 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7001 signature is part of the header. */
7002 static gdb::optional
<ULONGEST
>
7003 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7005 if (cu
->header
.version
>= 5)
7006 return cu
->header
.signature
;
7007 struct attribute
*attr
;
7008 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7009 if (attr
== nullptr || !attr
->form_is_unsigned ())
7010 return gdb::optional
<ULONGEST
> ();
7011 return attr
->as_unsigned ();
7014 /* Subroutine of cutu_reader to simplify it.
7015 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7016 Returns NULL if the specified DWO unit cannot be found. */
7018 static struct dwo_unit
*
7019 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
7021 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7022 struct dwo_unit
*dwo_unit
;
7023 const char *comp_dir
;
7025 gdb_assert (cu
!= NULL
);
7027 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7028 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7029 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7031 if (per_cu
->is_debug_types
)
7032 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
7035 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7037 if (!signature
.has_value ())
7038 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7040 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
7042 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
7048 /* Subroutine of cutu_reader to simplify it.
7049 See it for a description of the parameters.
7050 Read a TU directly from a DWO file, bypassing the stub. */
7053 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
7054 dwarf2_per_objfile
*per_objfile
,
7055 dwarf2_cu
*existing_cu
)
7057 struct signatured_type
*sig_type
;
7059 /* Verify we can do the following downcast, and that we have the
7061 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7062 sig_type
= (struct signatured_type
*) this_cu
;
7063 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7067 if (existing_cu
!= nullptr)
7070 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
7071 /* There's no need to do the rereading_dwo_cu handling that
7072 cutu_reader does since we don't read the stub. */
7076 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7077 in per_objfile yet. */
7078 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7079 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7080 cu
= m_new_cu
.get ();
7083 /* A future optimization, if needed, would be to use an existing
7084 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7085 could share abbrev tables. */
7087 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
7088 NULL
/* stub_comp_unit_die */,
7089 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7092 &m_dwo_abbrev_table
) == 0)
7099 /* Initialize a CU (or TU) and read its DIEs.
7100 If the CU defers to a DWO file, read the DWO file as well.
7102 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7103 Otherwise the table specified in the comp unit header is read in and used.
7104 This is an optimization for when we already have the abbrev table.
7106 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7109 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7110 dwarf2_per_objfile
*per_objfile
,
7111 struct abbrev_table
*abbrev_table
,
7112 dwarf2_cu
*existing_cu
,
7114 : die_reader_specs
{},
7117 struct objfile
*objfile
= per_objfile
->objfile
;
7118 struct dwarf2_section_info
*section
= this_cu
->section
;
7119 bfd
*abfd
= section
->get_bfd_owner ();
7120 const gdb_byte
*begin_info_ptr
;
7121 struct signatured_type
*sig_type
= NULL
;
7122 struct dwarf2_section_info
*abbrev_section
;
7123 /* Non-zero if CU currently points to a DWO file and we need to
7124 reread it. When this happens we need to reread the skeleton die
7125 before we can reread the DWO file (this only applies to CUs, not TUs). */
7126 int rereading_dwo_cu
= 0;
7128 if (dwarf_die_debug
)
7129 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7130 this_cu
->is_debug_types
? "type" : "comp",
7131 sect_offset_str (this_cu
->sect_off
));
7133 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7134 file (instead of going through the stub), short-circuit all of this. */
7135 if (this_cu
->reading_dwo_directly
)
7137 /* Narrow down the scope of possibilities to have to understand. */
7138 gdb_assert (this_cu
->is_debug_types
);
7139 gdb_assert (abbrev_table
== NULL
);
7140 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
7144 /* This is cheap if the section is already read in. */
7145 section
->read (objfile
);
7147 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7149 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7153 if (existing_cu
!= nullptr)
7156 /* If this CU is from a DWO file we need to start over, we need to
7157 refetch the attributes from the skeleton CU.
7158 This could be optimized by retrieving those attributes from when we
7159 were here the first time: the previous comp_unit_die was stored in
7160 comp_unit_obstack. But there's no data yet that we need this
7162 if (cu
->dwo_unit
!= NULL
)
7163 rereading_dwo_cu
= 1;
7167 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7168 in per_objfile yet. */
7169 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7170 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7171 cu
= m_new_cu
.get ();
7174 /* Get the header. */
7175 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7177 /* We already have the header, there's no need to read it in again. */
7178 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7182 if (this_cu
->is_debug_types
)
7184 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7185 section
, abbrev_section
,
7186 info_ptr
, rcuh_kind::TYPE
);
7188 /* Since per_cu is the first member of struct signatured_type,
7189 we can go from a pointer to one to a pointer to the other. */
7190 sig_type
= (struct signatured_type
*) this_cu
;
7191 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7192 gdb_assert (sig_type
->type_offset_in_tu
7193 == cu
->header
.type_cu_offset_in_tu
);
7194 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7196 /* LENGTH has not been set yet for type units if we're
7197 using .gdb_index. */
7198 this_cu
->length
= cu
->header
.get_length ();
7200 /* Establish the type offset that can be used to lookup the type. */
7201 sig_type
->type_offset_in_section
=
7202 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7204 this_cu
->dwarf_version
= cu
->header
.version
;
7208 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7209 section
, abbrev_section
,
7211 rcuh_kind::COMPILE
);
7213 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7214 if (this_cu
->length
== 0)
7215 this_cu
->length
= cu
->header
.get_length ();
7217 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7218 this_cu
->dwarf_version
= cu
->header
.version
;
7222 /* Skip dummy compilation units. */
7223 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7224 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7230 /* If we don't have them yet, read the abbrevs for this compilation unit.
7231 And if we need to read them now, make sure they're freed when we're
7233 if (abbrev_table
!= NULL
)
7234 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7237 abbrev_section
->read (objfile
);
7238 m_abbrev_table_holder
7239 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
7240 abbrev_table
= m_abbrev_table_holder
.get ();
7243 /* Read the top level CU/TU die. */
7244 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7245 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7247 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7253 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7254 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7255 table from the DWO file and pass the ownership over to us. It will be
7256 referenced from READER, so we must make sure to free it after we're done
7259 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7260 DWO CU, that this test will fail (the attribute will not be present). */
7261 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7262 if (dwo_name
!= nullptr)
7264 struct dwo_unit
*dwo_unit
;
7265 struct die_info
*dwo_comp_unit_die
;
7267 if (comp_unit_die
->has_children
)
7269 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7270 " has children (offset %s) [in module %s]"),
7271 sect_offset_str (this_cu
->sect_off
),
7272 bfd_get_filename (abfd
));
7274 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7275 if (dwo_unit
!= NULL
)
7277 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7278 comp_unit_die
, NULL
,
7281 &m_dwo_abbrev_table
) == 0)
7287 comp_unit_die
= dwo_comp_unit_die
;
7291 /* Yikes, we couldn't find the rest of the DIE, we only have
7292 the stub. A complaint has already been logged. There's
7293 not much more we can do except pass on the stub DIE to
7294 die_reader_func. We don't want to throw an error on bad
7301 cutu_reader::keep ()
7303 /* Done, clean up. */
7304 gdb_assert (!dummy_p
);
7305 if (m_new_cu
!= NULL
)
7307 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7309 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7310 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7314 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7315 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7316 assumed to have already done the lookup to find the DWO file).
7318 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7319 THIS_CU->is_debug_types, but nothing else.
7321 We fill in THIS_CU->length.
7323 THIS_CU->cu is always freed when done.
7324 This is done in order to not leave THIS_CU->cu in a state where we have
7325 to care whether it refers to the "main" CU or the DWO CU.
7327 When parent_cu is passed, it is used to provide a default value for
7328 str_offsets_base and addr_base from the parent. */
7330 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7331 dwarf2_per_objfile
*per_objfile
,
7332 struct dwarf2_cu
*parent_cu
,
7333 struct dwo_file
*dwo_file
)
7334 : die_reader_specs
{},
7337 struct objfile
*objfile
= per_objfile
->objfile
;
7338 struct dwarf2_section_info
*section
= this_cu
->section
;
7339 bfd
*abfd
= section
->get_bfd_owner ();
7340 struct dwarf2_section_info
*abbrev_section
;
7341 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7343 if (dwarf_die_debug
)
7344 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7345 this_cu
->is_debug_types
? "type" : "comp",
7346 sect_offset_str (this_cu
->sect_off
));
7348 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7350 abbrev_section
= (dwo_file
!= NULL
7351 ? &dwo_file
->sections
.abbrev
7352 : get_abbrev_section_for_cu (this_cu
));
7354 /* This is cheap if the section is already read in. */
7355 section
->read (objfile
);
7357 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7359 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7360 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
7361 section
, abbrev_section
, info_ptr
,
7362 (this_cu
->is_debug_types
7364 : rcuh_kind::COMPILE
));
7366 if (parent_cu
!= nullptr)
7368 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7369 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7371 this_cu
->length
= m_new_cu
->header
.get_length ();
7373 /* Skip dummy compilation units. */
7374 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7375 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7381 abbrev_section
->read (objfile
);
7382 m_abbrev_table_holder
7383 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
7385 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7386 m_abbrev_table_holder
.get ());
7387 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7391 /* Type Unit Groups.
7393 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7394 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7395 so that all types coming from the same compilation (.o file) are grouped
7396 together. A future step could be to put the types in the same symtab as
7397 the CU the types ultimately came from. */
7400 hash_type_unit_group (const void *item
)
7402 const struct type_unit_group
*tu_group
7403 = (const struct type_unit_group
*) item
;
7405 return hash_stmt_list_entry (&tu_group
->hash
);
7409 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7411 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7412 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7414 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7417 /* Allocate a hash table for type unit groups. */
7420 allocate_type_unit_groups_table ()
7422 return htab_up (htab_create_alloc (3,
7423 hash_type_unit_group
,
7425 NULL
, xcalloc
, xfree
));
7428 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7429 partial symtabs. We combine several TUs per psymtab to not let the size
7430 of any one psymtab grow too big. */
7431 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7432 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7434 /* Helper routine for get_type_unit_group.
7435 Create the type_unit_group object used to hold one or more TUs. */
7437 static struct type_unit_group
*
7438 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7440 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7441 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7442 struct dwarf2_per_cu_data
*per_cu
;
7443 struct type_unit_group
*tu_group
;
7445 tu_group
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, type_unit_group
);
7446 per_cu
= &tu_group
->per_cu
;
7447 per_cu
->per_bfd
= per_bfd
;
7449 if (per_bfd
->using_index
)
7451 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7452 struct dwarf2_per_cu_quick_data
);
7456 unsigned int line_offset
= to_underlying (line_offset_struct
);
7457 dwarf2_psymtab
*pst
;
7460 /* Give the symtab a useful name for debug purposes. */
7461 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7462 name
= string_printf ("<type_units_%d>",
7463 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7465 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7467 pst
= create_partial_symtab (per_cu
, per_objfile
, name
.c_str ());
7468 pst
->anonymous
= true;
7471 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7472 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7477 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7478 STMT_LIST is a DW_AT_stmt_list attribute. */
7480 static struct type_unit_group
*
7481 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7483 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7484 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7485 struct type_unit_group
*tu_group
;
7487 unsigned int line_offset
;
7488 struct type_unit_group type_unit_group_for_lookup
;
7490 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7491 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7493 /* Do we need to create a new group, or can we use an existing one? */
7495 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
7497 line_offset
= stmt_list
->as_unsigned ();
7498 ++tu_stats
->nr_symtab_sharers
;
7502 /* Ugh, no stmt_list. Rare, but we have to handle it.
7503 We can do various things here like create one group per TU or
7504 spread them over multiple groups to split up the expansion work.
7505 To avoid worst case scenarios (too many groups or too large groups)
7506 we, umm, group them in bunches. */
7507 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7508 | (tu_stats
->nr_stmt_less_type_units
7509 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7510 ++tu_stats
->nr_stmt_less_type_units
;
7513 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7514 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7515 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7516 &type_unit_group_for_lookup
, INSERT
);
7519 tu_group
= (struct type_unit_group
*) *slot
;
7520 gdb_assert (tu_group
!= NULL
);
7524 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7525 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7527 ++tu_stats
->nr_symtabs
;
7533 /* Partial symbol tables. */
7535 /* Create a psymtab named NAME and assign it to PER_CU.
7537 The caller must fill in the following details:
7538 dirname, textlow, texthigh. */
7540 static dwarf2_psymtab
*
7541 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7542 dwarf2_per_objfile
*per_objfile
,
7545 struct objfile
*objfile
= per_objfile
->objfile
;
7546 dwarf2_psymtab
*pst
;
7548 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7550 pst
->psymtabs_addrmap_supported
= true;
7552 /* This is the glue that links PST into GDB's symbol API. */
7553 per_cu
->v
.psymtab
= pst
;
7558 /* DIE reader function for process_psymtab_comp_unit. */
7561 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7562 const gdb_byte
*info_ptr
,
7563 struct die_info
*comp_unit_die
,
7564 enum language pretend_language
)
7566 struct dwarf2_cu
*cu
= reader
->cu
;
7567 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7568 struct objfile
*objfile
= per_objfile
->objfile
;
7569 struct gdbarch
*gdbarch
= objfile
->arch ();
7570 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7572 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7573 dwarf2_psymtab
*pst
;
7574 enum pc_bounds_kind cu_bounds_kind
;
7575 const char *filename
;
7577 gdb_assert (! per_cu
->is_debug_types
);
7579 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7581 /* Allocate a new partial symbol table structure. */
7582 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7583 static const char artificial
[] = "<artificial>";
7584 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7585 if (filename
== NULL
)
7587 else if (strcmp (filename
, artificial
) == 0)
7589 debug_filename
.reset (concat (artificial
, "@",
7590 sect_offset_str (per_cu
->sect_off
),
7592 filename
= debug_filename
.get ();
7595 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7597 /* This must be done before calling dwarf2_build_include_psymtabs. */
7598 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7600 baseaddr
= objfile
->text_section_offset ();
7602 dwarf2_find_base_address (comp_unit_die
, cu
);
7604 /* Possibly set the default values of LOWPC and HIGHPC from
7606 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7607 &best_highpc
, cu
, pst
);
7608 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7611 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7614 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7616 /* Store the contiguous range if it is not empty; it can be
7617 empty for CUs with no code. */
7618 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7622 /* Check if comp unit has_children.
7623 If so, read the rest of the partial symbols from this comp unit.
7624 If not, there's no more debug_info for this comp unit. */
7625 if (comp_unit_die
->has_children
)
7627 struct partial_die_info
*first_die
;
7628 CORE_ADDR lowpc
, highpc
;
7630 lowpc
= ((CORE_ADDR
) -1);
7631 highpc
= ((CORE_ADDR
) 0);
7633 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7635 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7636 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7638 /* If we didn't find a lowpc, set it to highpc to avoid
7639 complaints from `maint check'. */
7640 if (lowpc
== ((CORE_ADDR
) -1))
7643 /* If the compilation unit didn't have an explicit address range,
7644 then use the information extracted from its child dies. */
7645 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7648 best_highpc
= highpc
;
7651 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7652 best_lowpc
+ baseaddr
)
7654 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7655 best_highpc
+ baseaddr
)
7660 if (!cu
->per_cu
->imported_symtabs_empty ())
7663 int len
= cu
->per_cu
->imported_symtabs_size ();
7665 /* Fill in 'dependencies' here; we fill in 'users' in a
7667 pst
->number_of_dependencies
= len
;
7669 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7670 for (i
= 0; i
< len
; ++i
)
7672 pst
->dependencies
[i
]
7673 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7676 cu
->per_cu
->imported_symtabs_free ();
7679 /* Get the list of files included in the current compilation unit,
7680 and build a psymtab for each of them. */
7681 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7683 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7684 ", %d global, %d static syms",
7685 per_cu
->is_debug_types
? "type" : "comp",
7686 sect_offset_str (per_cu
->sect_off
),
7687 paddress (gdbarch
, pst
->text_low (objfile
)),
7688 paddress (gdbarch
, pst
->text_high (objfile
)),
7689 (int) pst
->global_psymbols
.size (),
7690 (int) pst
->static_psymbols
.size ());
7693 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7694 Process compilation unit THIS_CU for a psymtab. */
7697 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7698 dwarf2_per_objfile
*per_objfile
,
7699 bool want_partial_unit
,
7700 enum language pretend_language
)
7702 /* If this compilation unit was already read in, free the
7703 cached copy in order to read it in again. This is
7704 necessary because we skipped some symbols when we first
7705 read in the compilation unit (see load_partial_dies).
7706 This problem could be avoided, but the benefit is unclear. */
7707 per_objfile
->remove_cu (this_cu
);
7709 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7711 switch (reader
.comp_unit_die
->tag
)
7713 case DW_TAG_compile_unit
:
7714 this_cu
->unit_type
= DW_UT_compile
;
7716 case DW_TAG_partial_unit
:
7717 this_cu
->unit_type
= DW_UT_partial
;
7727 else if (this_cu
->is_debug_types
)
7728 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7729 reader
.comp_unit_die
);
7730 else if (want_partial_unit
7731 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7732 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7733 reader
.comp_unit_die
,
7736 this_cu
->lang
= reader
.cu
->language
;
7738 /* Age out any secondary CUs. */
7739 per_objfile
->age_comp_units ();
7742 /* Reader function for build_type_psymtabs. */
7745 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7746 const gdb_byte
*info_ptr
,
7747 struct die_info
*type_unit_die
)
7749 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7750 struct dwarf2_cu
*cu
= reader
->cu
;
7751 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7752 struct signatured_type
*sig_type
;
7753 struct type_unit_group
*tu_group
;
7754 struct attribute
*attr
;
7755 struct partial_die_info
*first_die
;
7756 CORE_ADDR lowpc
, highpc
;
7757 dwarf2_psymtab
*pst
;
7759 gdb_assert (per_cu
->is_debug_types
);
7760 sig_type
= (struct signatured_type
*) per_cu
;
7762 if (! type_unit_die
->has_children
)
7765 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7766 tu_group
= get_type_unit_group (cu
, attr
);
7768 if (tu_group
->tus
== nullptr)
7769 tu_group
->tus
= new std::vector
<signatured_type
*>;
7770 tu_group
->tus
->push_back (sig_type
);
7772 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7773 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7774 pst
->anonymous
= true;
7776 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7778 lowpc
= (CORE_ADDR
) -1;
7779 highpc
= (CORE_ADDR
) 0;
7780 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7785 /* Struct used to sort TUs by their abbreviation table offset. */
7787 struct tu_abbrev_offset
7789 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7790 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7793 signatured_type
*sig_type
;
7794 sect_offset abbrev_offset
;
7797 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7800 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7801 const struct tu_abbrev_offset
&b
)
7803 return a
.abbrev_offset
< b
.abbrev_offset
;
7806 /* Efficiently read all the type units.
7807 This does the bulk of the work for build_type_psymtabs.
7809 The efficiency is because we sort TUs by the abbrev table they use and
7810 only read each abbrev table once. In one program there are 200K TUs
7811 sharing 8K abbrev tables.
7813 The main purpose of this function is to support building the
7814 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7815 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7816 can collapse the search space by grouping them by stmt_list.
7817 The savings can be significant, in the same program from above the 200K TUs
7818 share 8K stmt_list tables.
7820 FUNC is expected to call get_type_unit_group, which will create the
7821 struct type_unit_group if necessary and add it to
7822 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7825 build_type_psymtabs_1 (dwarf2_per_objfile
*per_objfile
)
7827 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7828 abbrev_table_up abbrev_table
;
7829 sect_offset abbrev_offset
;
7831 /* It's up to the caller to not call us multiple times. */
7832 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7834 if (per_objfile
->per_bfd
->all_type_units
.empty ())
7837 /* TUs typically share abbrev tables, and there can be way more TUs than
7838 abbrev tables. Sort by abbrev table to reduce the number of times we
7839 read each abbrev table in.
7840 Alternatives are to punt or to maintain a cache of abbrev tables.
7841 This is simpler and efficient enough for now.
7843 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7844 symtab to use). Typically TUs with the same abbrev offset have the same
7845 stmt_list value too so in practice this should work well.
7847 The basic algorithm here is:
7849 sort TUs by abbrev table
7850 for each TU with same abbrev table:
7851 read abbrev table if first user
7852 read TU top level DIE
7853 [IWBN if DWO skeletons had DW_AT_stmt_list]
7856 dwarf_read_debug_printf ("Building type unit groups ...");
7858 /* Sort in a separate table to maintain the order of all_type_units
7859 for .gdb_index: TU indices directly index all_type_units. */
7860 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7861 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
7863 for (signatured_type
*sig_type
: per_objfile
->per_bfd
->all_type_units
)
7864 sorted_by_abbrev
.emplace_back
7865 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->per_cu
.section
,
7866 sig_type
->per_cu
.sect_off
));
7868 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7869 sort_tu_by_abbrev_offset
);
7871 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7873 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7875 /* Switch to the next abbrev table if necessary. */
7876 if (abbrev_table
== NULL
7877 || tu
.abbrev_offset
!= abbrev_offset
)
7879 abbrev_offset
= tu
.abbrev_offset
;
7880 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7882 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7883 ++tu_stats
->nr_uniq_abbrev_tables
;
7886 cutu_reader
reader (&tu
.sig_type
->per_cu
, per_objfile
,
7887 abbrev_table
.get (), nullptr, false);
7888 if (!reader
.dummy_p
)
7889 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7890 reader
.comp_unit_die
);
7894 /* Print collected type unit statistics. */
7897 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7899 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7901 dwarf_read_debug_printf ("Type unit statistics:");
7902 dwarf_read_debug_printf (" %zu TUs",
7903 per_objfile
->per_bfd
->all_type_units
.size ());
7904 dwarf_read_debug_printf (" %d uniq abbrev tables",
7905 tu_stats
->nr_uniq_abbrev_tables
);
7906 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7907 tu_stats
->nr_symtabs
);
7908 dwarf_read_debug_printf (" %d symtab sharers",
7909 tu_stats
->nr_symtab_sharers
);
7910 dwarf_read_debug_printf (" %d type units without a stmt_list",
7911 tu_stats
->nr_stmt_less_type_units
);
7912 dwarf_read_debug_printf (" %d all_type_units reallocs",
7913 tu_stats
->nr_all_type_units_reallocs
);
7916 /* Traversal function for build_type_psymtabs. */
7919 build_type_psymtab_dependencies (void **slot
, void *info
)
7921 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7922 struct objfile
*objfile
= per_objfile
->objfile
;
7923 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7924 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7925 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7926 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7929 gdb_assert (len
> 0);
7930 gdb_assert (per_cu
->type_unit_group_p ());
7932 pst
->number_of_dependencies
= len
;
7933 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7934 for (i
= 0; i
< len
; ++i
)
7936 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7937 gdb_assert (iter
->per_cu
.is_debug_types
);
7938 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7939 iter
->type_unit_group
= tu_group
;
7942 delete tu_group
->tus
;
7943 tu_group
->tus
= nullptr;
7948 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7949 Build partial symbol tables for the .debug_types comp-units. */
7952 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7954 if (! create_all_type_units (per_objfile
))
7957 build_type_psymtabs_1 (per_objfile
);
7960 /* Traversal function for process_skeletonless_type_unit.
7961 Read a TU in a DWO file and build partial symbols for it. */
7964 process_skeletonless_type_unit (void **slot
, void *info
)
7966 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7967 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7968 struct signatured_type find_entry
, *entry
;
7970 /* If this TU doesn't exist in the global table, add it and read it in. */
7972 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7973 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7975 find_entry
.signature
= dwo_unit
->signature
;
7976 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7977 &find_entry
, INSERT
);
7978 /* If we've already seen this type there's nothing to do. What's happening
7979 is we're doing our own version of comdat-folding here. */
7983 /* This does the job that create_all_type_units would have done for
7985 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7986 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7989 /* This does the job that build_type_psymtabs_1 would have done. */
7990 cutu_reader
reader (&entry
->per_cu
, per_objfile
, nullptr, nullptr, false);
7991 if (!reader
.dummy_p
)
7992 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7993 reader
.comp_unit_die
);
7998 /* Traversal function for process_skeletonless_type_units. */
8001 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8003 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8005 if (dwo_file
->tus
!= NULL
)
8006 htab_traverse_noresize (dwo_file
->tus
.get (),
8007 process_skeletonless_type_unit
, info
);
8012 /* Scan all TUs of DWO files, verifying we've processed them.
8013 This is needed in case a TU was emitted without its skeleton.
8014 Note: This can't be done until we know what all the DWO files are. */
8017 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
8019 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8020 if (get_dwp_file (per_objfile
) == NULL
8021 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
8023 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
8024 process_dwo_file_for_skeletonless_type_units
,
8029 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8032 set_partial_user (dwarf2_per_objfile
*per_objfile
)
8034 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8036 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8041 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8043 /* Set the 'user' field only if it is not already set. */
8044 if (pst
->dependencies
[j
]->user
== NULL
)
8045 pst
->dependencies
[j
]->user
= pst
;
8050 /* Build the partial symbol table by doing a quick pass through the
8051 .debug_info and .debug_abbrev sections. */
8054 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
8056 struct objfile
*objfile
= per_objfile
->objfile
;
8058 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
8059 objfile_name (objfile
));
8061 scoped_restore restore_reading_psyms
8062 = make_scoped_restore (&per_objfile
->per_bfd
->reading_partial_symbols
,
8065 per_objfile
->per_bfd
->info
.read (objfile
);
8067 /* Any cached compilation units will be linked by the per-objfile
8068 read_in_chain. Make sure to free them when we're done. */
8069 free_cached_comp_units
freer (per_objfile
);
8071 build_type_psymtabs (per_objfile
);
8073 create_all_comp_units (per_objfile
);
8075 /* Create a temporary address map on a temporary obstack. We later
8076 copy this to the final obstack. */
8077 auto_obstack temp_obstack
;
8079 scoped_restore save_psymtabs_addrmap
8080 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8081 addrmap_create_mutable (&temp_obstack
));
8083 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8085 if (per_cu
->v
.psymtab
!= NULL
)
8086 /* In case a forward DW_TAG_imported_unit has read the CU already. */
8088 process_psymtab_comp_unit (per_cu
, per_objfile
, false,
8092 /* This has to wait until we read the CUs, we need the list of DWOs. */
8093 process_skeletonless_type_units (per_objfile
);
8095 /* Now that all TUs have been processed we can fill in the dependencies. */
8096 if (per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
8098 htab_traverse_noresize (per_objfile
->per_bfd
->type_unit_groups
.get (),
8099 build_type_psymtab_dependencies
, per_objfile
);
8102 if (dwarf_read_debug
> 0)
8103 print_tu_stats (per_objfile
);
8105 set_partial_user (per_objfile
);
8107 objfile
->partial_symtabs
->psymtabs_addrmap
8108 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8109 objfile
->partial_symtabs
->obstack ());
8110 /* At this point we want to keep the address map. */
8111 save_psymtabs_addrmap
.release ();
8113 dwarf_read_debug_printf ("Done building psymtabs of %s",
8114 objfile_name (objfile
));
8117 /* Load the partial DIEs for a secondary CU into memory.
8118 This is also used when rereading a primary CU with load_all_dies. */
8121 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8122 dwarf2_per_objfile
*per_objfile
,
8123 dwarf2_cu
*existing_cu
)
8125 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8127 if (!reader
.dummy_p
)
8129 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8132 /* Check if comp unit has_children.
8133 If so, read the rest of the partial symbols from this comp unit.
8134 If not, there's no more debug_info for this comp unit. */
8135 if (reader
.comp_unit_die
->has_children
)
8136 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8143 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
8144 struct dwarf2_section_info
*section
,
8145 struct dwarf2_section_info
*abbrev_section
,
8146 unsigned int is_dwz
)
8148 const gdb_byte
*info_ptr
;
8149 struct objfile
*objfile
= per_objfile
->objfile
;
8151 dwarf_read_debug_printf ("Reading %s for %s",
8152 section
->get_name (),
8153 section
->get_file_name ());
8155 section
->read (objfile
);
8157 info_ptr
= section
->buffer
;
8159 while (info_ptr
< section
->buffer
+ section
->size
)
8161 struct dwarf2_per_cu_data
*this_cu
;
8163 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8165 comp_unit_head cu_header
;
8166 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
8167 abbrev_section
, info_ptr
,
8168 rcuh_kind::COMPILE
);
8170 /* Save the compilation unit for later lookup. */
8171 if (cu_header
.unit_type
!= DW_UT_type
)
8172 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
8175 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
8176 sig_type
->signature
= cu_header
.signature
;
8177 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8178 this_cu
= &sig_type
->per_cu
;
8180 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8181 this_cu
->sect_off
= sect_off
;
8182 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8183 this_cu
->is_dwz
= is_dwz
;
8184 this_cu
->section
= section
;
8186 per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8188 info_ptr
= info_ptr
+ this_cu
->length
;
8192 /* Create a list of all compilation units in OBJFILE.
8193 This is only done for -readnow and building partial symtabs. */
8196 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
8198 gdb_assert (per_objfile
->per_bfd
->all_comp_units
.empty ());
8199 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
8200 &per_objfile
->per_bfd
->abbrev
, 0);
8202 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
8204 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1);
8207 /* Process all loaded DIEs for compilation unit CU, starting at
8208 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8209 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8210 DW_AT_ranges). See the comments of add_partial_subprogram on how
8211 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8214 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8215 CORE_ADDR
*highpc
, int set_addrmap
,
8216 struct dwarf2_cu
*cu
)
8218 struct partial_die_info
*pdi
;
8220 /* Now, march along the PDI's, descending into ones which have
8221 interesting children but skipping the children of the other ones,
8222 until we reach the end of the compilation unit. */
8230 /* Anonymous namespaces or modules have no name but have interesting
8231 children, so we need to look at them. Ditto for anonymous
8234 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8235 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8236 || pdi
->tag
== DW_TAG_imported_unit
8237 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8241 case DW_TAG_subprogram
:
8242 case DW_TAG_inlined_subroutine
:
8243 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8244 if (cu
->language
== language_cplus
)
8245 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8248 case DW_TAG_constant
:
8249 case DW_TAG_variable
:
8250 case DW_TAG_typedef
:
8251 case DW_TAG_union_type
:
8252 if (!pdi
->is_declaration
8253 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8255 add_partial_symbol (pdi
, cu
);
8258 case DW_TAG_class_type
:
8259 case DW_TAG_interface_type
:
8260 case DW_TAG_structure_type
:
8261 if (!pdi
->is_declaration
)
8263 add_partial_symbol (pdi
, cu
);
8265 if ((cu
->language
== language_rust
8266 || cu
->language
== language_cplus
) && pdi
->has_children
)
8267 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8270 case DW_TAG_enumeration_type
:
8271 if (!pdi
->is_declaration
)
8272 add_partial_enumeration (pdi
, cu
);
8274 case DW_TAG_base_type
:
8275 case DW_TAG_subrange_type
:
8276 /* File scope base type definitions are added to the partial
8278 add_partial_symbol (pdi
, cu
);
8280 case DW_TAG_namespace
:
8281 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8284 if (!pdi
->is_declaration
)
8285 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8287 case DW_TAG_imported_unit
:
8289 struct dwarf2_per_cu_data
*per_cu
;
8291 /* For now we don't handle imported units in type units. */
8292 if (cu
->per_cu
->is_debug_types
)
8294 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8295 " supported in type units [in module %s]"),
8296 objfile_name (cu
->per_objfile
->objfile
));
8299 per_cu
= dwarf2_find_containing_comp_unit
8300 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8302 /* Go read the partial unit, if needed. */
8303 if (per_cu
->v
.psymtab
== NULL
)
8304 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8307 cu
->per_cu
->imported_symtabs_push (per_cu
);
8310 case DW_TAG_imported_declaration
:
8311 add_partial_symbol (pdi
, cu
);
8318 /* If the die has a sibling, skip to the sibling. */
8320 pdi
= pdi
->die_sibling
;
8324 /* Functions used to compute the fully scoped name of a partial DIE.
8326 Normally, this is simple. For C++, the parent DIE's fully scoped
8327 name is concatenated with "::" and the partial DIE's name.
8328 Enumerators are an exception; they use the scope of their parent
8329 enumeration type, i.e. the name of the enumeration type is not
8330 prepended to the enumerator.
8332 There are two complexities. One is DW_AT_specification; in this
8333 case "parent" means the parent of the target of the specification,
8334 instead of the direct parent of the DIE. The other is compilers
8335 which do not emit DW_TAG_namespace; in this case we try to guess
8336 the fully qualified name of structure types from their members'
8337 linkage names. This must be done using the DIE's children rather
8338 than the children of any DW_AT_specification target. We only need
8339 to do this for structures at the top level, i.e. if the target of
8340 any DW_AT_specification (if any; otherwise the DIE itself) does not
8343 /* Compute the scope prefix associated with PDI's parent, in
8344 compilation unit CU. The result will be allocated on CU's
8345 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8346 field. NULL is returned if no prefix is necessary. */
8348 partial_die_parent_scope (struct partial_die_info
*pdi
,
8349 struct dwarf2_cu
*cu
)
8351 const char *grandparent_scope
;
8352 struct partial_die_info
*parent
, *real_pdi
;
8354 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8355 then this means the parent of the specification DIE. */
8358 while (real_pdi
->has_specification
)
8360 auto res
= find_partial_die (real_pdi
->spec_offset
,
8361 real_pdi
->spec_is_dwz
, cu
);
8366 parent
= real_pdi
->die_parent
;
8370 if (parent
->scope_set
)
8371 return parent
->scope
;
8375 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8377 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8378 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8379 Work around this problem here. */
8380 if (cu
->language
== language_cplus
8381 && parent
->tag
== DW_TAG_namespace
8382 && strcmp (parent
->name (cu
), "::") == 0
8383 && grandparent_scope
== NULL
)
8385 parent
->scope
= NULL
;
8386 parent
->scope_set
= 1;
8390 /* Nested subroutines in Fortran get a prefix. */
8391 if (pdi
->tag
== DW_TAG_enumerator
)
8392 /* Enumerators should not get the name of the enumeration as a prefix. */
8393 parent
->scope
= grandparent_scope
;
8394 else if (parent
->tag
== DW_TAG_namespace
8395 || parent
->tag
== DW_TAG_module
8396 || parent
->tag
== DW_TAG_structure_type
8397 || parent
->tag
== DW_TAG_class_type
8398 || parent
->tag
== DW_TAG_interface_type
8399 || parent
->tag
== DW_TAG_union_type
8400 || parent
->tag
== DW_TAG_enumeration_type
8401 || (cu
->language
== language_fortran
8402 && parent
->tag
== DW_TAG_subprogram
8403 && pdi
->tag
== DW_TAG_subprogram
))
8405 if (grandparent_scope
== NULL
)
8406 parent
->scope
= parent
->name (cu
);
8408 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8410 parent
->name (cu
), 0, cu
);
8414 /* FIXME drow/2004-04-01: What should we be doing with
8415 function-local names? For partial symbols, we should probably be
8417 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8418 dwarf_tag_name (parent
->tag
),
8419 sect_offset_str (pdi
->sect_off
));
8420 parent
->scope
= grandparent_scope
;
8423 parent
->scope_set
= 1;
8424 return parent
->scope
;
8427 /* Return the fully scoped name associated with PDI, from compilation unit
8428 CU. The result will be allocated with malloc. */
8430 static gdb::unique_xmalloc_ptr
<char>
8431 partial_die_full_name (struct partial_die_info
*pdi
,
8432 struct dwarf2_cu
*cu
)
8434 const char *parent_scope
;
8436 /* If this is a template instantiation, we can not work out the
8437 template arguments from partial DIEs. So, unfortunately, we have
8438 to go through the full DIEs. At least any work we do building
8439 types here will be reused if full symbols are loaded later. */
8440 if (pdi
->has_template_arguments
)
8444 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8446 struct die_info
*die
;
8447 struct attribute attr
;
8448 struct dwarf2_cu
*ref_cu
= cu
;
8450 /* DW_FORM_ref_addr is using section offset. */
8451 attr
.name
= (enum dwarf_attribute
) 0;
8452 attr
.form
= DW_FORM_ref_addr
;
8453 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8454 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8456 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8460 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8461 if (parent_scope
== NULL
)
8464 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8470 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8472 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8473 struct objfile
*objfile
= per_objfile
->objfile
;
8474 struct gdbarch
*gdbarch
= objfile
->arch ();
8476 const char *actual_name
= NULL
;
8479 baseaddr
= objfile
->text_section_offset ();
8481 gdb::unique_xmalloc_ptr
<char> built_actual_name
8482 = partial_die_full_name (pdi
, cu
);
8483 if (built_actual_name
!= NULL
)
8484 actual_name
= built_actual_name
.get ();
8486 if (actual_name
== NULL
)
8487 actual_name
= pdi
->name (cu
);
8489 partial_symbol psymbol
;
8490 memset (&psymbol
, 0, sizeof (psymbol
));
8491 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8492 psymbol
.ginfo
.section
= -1;
8494 /* The code below indicates that the psymbol should be installed by
8496 gdb::optional
<psymbol_placement
> where
;
8500 case DW_TAG_inlined_subroutine
:
8501 case DW_TAG_subprogram
:
8502 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8504 if (pdi
->is_external
8505 || cu
->language
== language_ada
8506 || (cu
->language
== language_fortran
8507 && pdi
->die_parent
!= NULL
8508 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8510 /* Normally, only "external" DIEs are part of the global scope.
8511 But in Ada and Fortran, we want to be able to access nested
8512 procedures globally. So all Ada and Fortran subprograms are
8513 stored in the global scope. */
8514 where
= psymbol_placement::GLOBAL
;
8517 where
= psymbol_placement::STATIC
;
8519 psymbol
.domain
= VAR_DOMAIN
;
8520 psymbol
.aclass
= LOC_BLOCK
;
8521 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8522 psymbol
.ginfo
.value
.address
= addr
;
8524 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8525 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8527 case DW_TAG_constant
:
8528 psymbol
.domain
= VAR_DOMAIN
;
8529 psymbol
.aclass
= LOC_STATIC
;
8530 where
= (pdi
->is_external
8531 ? psymbol_placement::GLOBAL
8532 : psymbol_placement::STATIC
);
8534 case DW_TAG_variable
:
8536 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8540 && !per_objfile
->per_bfd
->has_section_at_zero
)
8542 /* A global or static variable may also have been stripped
8543 out by the linker if unused, in which case its address
8544 will be nullified; do not add such variables into partial
8545 symbol table then. */
8547 else if (pdi
->is_external
)
8550 Don't enter into the minimal symbol tables as there is
8551 a minimal symbol table entry from the ELF symbols already.
8552 Enter into partial symbol table if it has a location
8553 descriptor or a type.
8554 If the location descriptor is missing, new_symbol will create
8555 a LOC_UNRESOLVED symbol, the address of the variable will then
8556 be determined from the minimal symbol table whenever the variable
8558 The address for the partial symbol table entry is not
8559 used by GDB, but it comes in handy for debugging partial symbol
8562 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8564 psymbol
.domain
= VAR_DOMAIN
;
8565 psymbol
.aclass
= LOC_STATIC
;
8566 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8567 psymbol
.ginfo
.value
.address
= addr
;
8568 where
= psymbol_placement::GLOBAL
;
8573 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8575 /* Static Variable. Skip symbols whose value we cannot know (those
8576 without location descriptors or constant values). */
8577 if (!has_loc
&& !pdi
->has_const_value
)
8580 psymbol
.domain
= VAR_DOMAIN
;
8581 psymbol
.aclass
= LOC_STATIC
;
8582 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8584 psymbol
.ginfo
.value
.address
= addr
;
8585 where
= psymbol_placement::STATIC
;
8588 case DW_TAG_array_type
:
8589 case DW_TAG_typedef
:
8590 case DW_TAG_base_type
:
8591 case DW_TAG_subrange_type
:
8592 psymbol
.domain
= VAR_DOMAIN
;
8593 psymbol
.aclass
= LOC_TYPEDEF
;
8594 where
= psymbol_placement::STATIC
;
8596 case DW_TAG_imported_declaration
:
8597 case DW_TAG_namespace
:
8598 psymbol
.domain
= VAR_DOMAIN
;
8599 psymbol
.aclass
= LOC_TYPEDEF
;
8600 where
= psymbol_placement::GLOBAL
;
8603 /* With Fortran 77 there might be a "BLOCK DATA" module
8604 available without any name. If so, we skip the module as it
8605 doesn't bring any value. */
8606 if (actual_name
!= nullptr)
8608 psymbol
.domain
= MODULE_DOMAIN
;
8609 psymbol
.aclass
= LOC_TYPEDEF
;
8610 where
= psymbol_placement::GLOBAL
;
8613 case DW_TAG_class_type
:
8614 case DW_TAG_interface_type
:
8615 case DW_TAG_structure_type
:
8616 case DW_TAG_union_type
:
8617 case DW_TAG_enumeration_type
:
8618 /* Skip external references. The DWARF standard says in the section
8619 about "Structure, Union, and Class Type Entries": "An incomplete
8620 structure, union or class type is represented by a structure,
8621 union or class entry that does not have a byte size attribute
8622 and that has a DW_AT_declaration attribute." */
8623 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8626 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8627 static vs. global. */
8628 psymbol
.domain
= STRUCT_DOMAIN
;
8629 psymbol
.aclass
= LOC_TYPEDEF
;
8630 where
= (cu
->language
== language_cplus
8631 ? psymbol_placement::GLOBAL
8632 : psymbol_placement::STATIC
);
8634 case DW_TAG_enumerator
:
8635 psymbol
.domain
= VAR_DOMAIN
;
8636 psymbol
.aclass
= LOC_CONST
;
8637 where
= (cu
->language
== language_cplus
8638 ? psymbol_placement::GLOBAL
8639 : psymbol_placement::STATIC
);
8645 if (where
.has_value ())
8647 if (built_actual_name
!= nullptr)
8648 actual_name
= objfile
->intern (actual_name
);
8649 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8650 psymbol
.ginfo
.set_linkage_name (actual_name
);
8653 psymbol
.ginfo
.set_demangled_name (actual_name
,
8654 &objfile
->objfile_obstack
);
8655 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8657 cu
->per_cu
->v
.psymtab
->add_psymbol (psymbol
, *where
, objfile
);
8661 /* Read a partial die corresponding to a namespace; also, add a symbol
8662 corresponding to that namespace to the symbol table. NAMESPACE is
8663 the name of the enclosing namespace. */
8666 add_partial_namespace (struct partial_die_info
*pdi
,
8667 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8668 int set_addrmap
, struct dwarf2_cu
*cu
)
8670 /* Add a symbol for the namespace. */
8672 add_partial_symbol (pdi
, cu
);
8674 /* Now scan partial symbols in that namespace. */
8676 if (pdi
->has_children
)
8677 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8680 /* Read a partial die corresponding to a Fortran module. */
8683 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8684 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8686 /* Add a symbol for the namespace. */
8688 add_partial_symbol (pdi
, cu
);
8690 /* Now scan partial symbols in that module. */
8692 if (pdi
->has_children
)
8693 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8696 /* Read a partial die corresponding to a subprogram or an inlined
8697 subprogram and create a partial symbol for that subprogram.
8698 When the CU language allows it, this routine also defines a partial
8699 symbol for each nested subprogram that this subprogram contains.
8700 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8701 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8703 PDI may also be a lexical block, in which case we simply search
8704 recursively for subprograms defined inside that lexical block.
8705 Again, this is only performed when the CU language allows this
8706 type of definitions. */
8709 add_partial_subprogram (struct partial_die_info
*pdi
,
8710 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8711 int set_addrmap
, struct dwarf2_cu
*cu
)
8713 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8715 if (pdi
->has_pc_info
)
8717 if (pdi
->lowpc
< *lowpc
)
8718 *lowpc
= pdi
->lowpc
;
8719 if (pdi
->highpc
> *highpc
)
8720 *highpc
= pdi
->highpc
;
8723 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8724 struct gdbarch
*gdbarch
= objfile
->arch ();
8726 CORE_ADDR this_highpc
;
8727 CORE_ADDR this_lowpc
;
8729 baseaddr
= objfile
->text_section_offset ();
8731 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8732 pdi
->lowpc
+ baseaddr
)
8735 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8736 pdi
->highpc
+ baseaddr
)
8738 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8739 this_lowpc
, this_highpc
- 1,
8740 cu
->per_cu
->v
.psymtab
);
8744 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8746 if (!pdi
->is_declaration
)
8747 /* Ignore subprogram DIEs that do not have a name, they are
8748 illegal. Do not emit a complaint at this point, we will
8749 do so when we convert this psymtab into a symtab. */
8751 add_partial_symbol (pdi
, cu
);
8755 if (! pdi
->has_children
)
8758 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8760 pdi
= pdi
->die_child
;
8764 if (pdi
->tag
== DW_TAG_subprogram
8765 || pdi
->tag
== DW_TAG_inlined_subroutine
8766 || pdi
->tag
== DW_TAG_lexical_block
)
8767 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8768 pdi
= pdi
->die_sibling
;
8773 /* Read a partial die corresponding to an enumeration type. */
8776 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8777 struct dwarf2_cu
*cu
)
8779 struct partial_die_info
*pdi
;
8781 if (enum_pdi
->name (cu
) != NULL
)
8782 add_partial_symbol (enum_pdi
, cu
);
8784 pdi
= enum_pdi
->die_child
;
8787 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8788 complaint (_("malformed enumerator DIE ignored"));
8790 add_partial_symbol (pdi
, cu
);
8791 pdi
= pdi
->die_sibling
;
8795 /* Return the initial uleb128 in the die at INFO_PTR. */
8798 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8800 unsigned int bytes_read
;
8802 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8805 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8806 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8808 Return the corresponding abbrev, or NULL if the number is zero (indicating
8809 an empty DIE). In either case *BYTES_READ will be set to the length of
8810 the initial number. */
8812 static struct abbrev_info
*
8813 peek_die_abbrev (const die_reader_specs
&reader
,
8814 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8816 dwarf2_cu
*cu
= reader
.cu
;
8817 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8818 unsigned int abbrev_number
8819 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8821 if (abbrev_number
== 0)
8824 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8827 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8828 " at offset %s [in module %s]"),
8829 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8830 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8836 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8837 Returns a pointer to the end of a series of DIEs, terminated by an empty
8838 DIE. Any children of the skipped DIEs will also be skipped. */
8840 static const gdb_byte
*
8841 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8845 unsigned int bytes_read
;
8846 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8849 return info_ptr
+ bytes_read
;
8851 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8855 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8856 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8857 abbrev corresponding to that skipped uleb128 should be passed in
8858 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8861 static const gdb_byte
*
8862 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8863 struct abbrev_info
*abbrev
)
8865 unsigned int bytes_read
;
8866 struct attribute attr
;
8867 bfd
*abfd
= reader
->abfd
;
8868 struct dwarf2_cu
*cu
= reader
->cu
;
8869 const gdb_byte
*buffer
= reader
->buffer
;
8870 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8871 unsigned int form
, i
;
8873 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8875 /* The only abbrev we care about is DW_AT_sibling. */
8876 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8878 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8879 if (attr
.form
== DW_FORM_ref_addr
)
8880 complaint (_("ignoring absolute DW_AT_sibling"));
8883 sect_offset off
= attr
.get_ref_die_offset ();
8884 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8886 if (sibling_ptr
< info_ptr
)
8887 complaint (_("DW_AT_sibling points backwards"));
8888 else if (sibling_ptr
> reader
->buffer_end
)
8889 reader
->die_section
->overflow_complaint ();
8895 /* If it isn't DW_AT_sibling, skip this attribute. */
8896 form
= abbrev
->attrs
[i
].form
;
8900 case DW_FORM_ref_addr
:
8901 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8902 and later it is offset sized. */
8903 if (cu
->header
.version
== 2)
8904 info_ptr
+= cu
->header
.addr_size
;
8906 info_ptr
+= cu
->header
.offset_size
;
8908 case DW_FORM_GNU_ref_alt
:
8909 info_ptr
+= cu
->header
.offset_size
;
8912 info_ptr
+= cu
->header
.addr_size
;
8920 case DW_FORM_flag_present
:
8921 case DW_FORM_implicit_const
:
8938 case DW_FORM_ref_sig8
:
8941 case DW_FORM_data16
:
8944 case DW_FORM_string
:
8945 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8946 info_ptr
+= bytes_read
;
8948 case DW_FORM_sec_offset
:
8950 case DW_FORM_GNU_strp_alt
:
8951 info_ptr
+= cu
->header
.offset_size
;
8953 case DW_FORM_exprloc
:
8955 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8956 info_ptr
+= bytes_read
;
8958 case DW_FORM_block1
:
8959 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8961 case DW_FORM_block2
:
8962 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8964 case DW_FORM_block4
:
8965 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8971 case DW_FORM_ref_udata
:
8972 case DW_FORM_GNU_addr_index
:
8973 case DW_FORM_GNU_str_index
:
8974 case DW_FORM_rnglistx
:
8975 case DW_FORM_loclistx
:
8976 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8978 case DW_FORM_indirect
:
8979 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8980 info_ptr
+= bytes_read
;
8981 /* We need to continue parsing from here, so just go back to
8983 goto skip_attribute
;
8986 error (_("Dwarf Error: Cannot handle %s "
8987 "in DWARF reader [in module %s]"),
8988 dwarf_form_name (form
),
8989 bfd_get_filename (abfd
));
8993 if (abbrev
->has_children
)
8994 return skip_children (reader
, info_ptr
);
8999 /* Locate ORIG_PDI's sibling.
9000 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9002 static const gdb_byte
*
9003 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9004 struct partial_die_info
*orig_pdi
,
9005 const gdb_byte
*info_ptr
)
9007 /* Do we know the sibling already? */
9009 if (orig_pdi
->sibling
)
9010 return orig_pdi
->sibling
;
9012 /* Are there any children to deal with? */
9014 if (!orig_pdi
->has_children
)
9017 /* Skip the children the long way. */
9019 return skip_children (reader
, info_ptr
);
9022 /* Expand this partial symbol table into a full symbol table. SELF is
9026 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
9028 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9030 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
9032 /* If this psymtab is constructed from a debug-only objfile, the
9033 has_section_at_zero flag will not necessarily be correct. We
9034 can get the correct value for this flag by looking at the data
9035 associated with the (presumably stripped) associated objfile. */
9036 if (objfile
->separate_debug_objfile_backlink
)
9038 dwarf2_per_objfile
*per_objfile_backlink
9039 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9041 per_objfile
->per_bfd
->has_section_at_zero
9042 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
9045 expand_psymtab (objfile
);
9047 process_cu_includes (per_objfile
);
9050 /* Reading in full CUs. */
9052 /* Add PER_CU to the queue. */
9055 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
9056 dwarf2_per_objfile
*per_objfile
,
9057 enum language pretend_language
)
9060 per_cu
->per_bfd
->queue
.emplace (per_cu
, per_objfile
, pretend_language
);
9063 /* If PER_CU is not yet queued, add it to the queue.
9064 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9066 The result is non-zero if PER_CU was queued, otherwise the result is zero
9067 meaning either PER_CU is already queued or it is already loaded.
9069 N.B. There is an invariant here that if a CU is queued then it is loaded.
9070 The caller is required to load PER_CU if we return non-zero. */
9073 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9074 dwarf2_per_cu_data
*per_cu
,
9075 dwarf2_per_objfile
*per_objfile
,
9076 enum language pretend_language
)
9078 /* We may arrive here during partial symbol reading, if we need full
9079 DIEs to process an unusual case (e.g. template arguments). Do
9080 not queue PER_CU, just tell our caller to load its DIEs. */
9081 if (per_cu
->per_bfd
->reading_partial_symbols
)
9083 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9085 if (cu
== NULL
|| cu
->dies
== NULL
)
9090 /* Mark the dependence relation so that we don't flush PER_CU
9092 if (dependent_cu
!= NULL
)
9093 dwarf2_add_dependence (dependent_cu
, per_cu
);
9095 /* If it's already on the queue, we have nothing to do. */
9099 /* If the compilation unit is already loaded, just mark it as
9101 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9108 /* Add it to the queue. */
9109 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9114 /* Process the queue. */
9117 process_queue (dwarf2_per_objfile
*per_objfile
)
9119 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
9120 objfile_name (per_objfile
->objfile
));
9122 /* The queue starts out with one item, but following a DIE reference
9123 may load a new CU, adding it to the end of the queue. */
9124 while (!per_objfile
->per_bfd
->queue
.empty ())
9126 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
.front ();
9127 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9129 if (!per_objfile
->symtab_set_p (per_cu
))
9131 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9133 /* Skip dummy CUs. */
9136 unsigned int debug_print_threshold
;
9139 if (per_cu
->is_debug_types
)
9141 struct signatured_type
*sig_type
=
9142 (struct signatured_type
*) per_cu
;
9144 sprintf (buf
, "TU %s at offset %s",
9145 hex_string (sig_type
->signature
),
9146 sect_offset_str (per_cu
->sect_off
));
9147 /* There can be 100s of TUs.
9148 Only print them in verbose mode. */
9149 debug_print_threshold
= 2;
9153 sprintf (buf
, "CU at offset %s",
9154 sect_offset_str (per_cu
->sect_off
));
9155 debug_print_threshold
= 1;
9158 if (dwarf_read_debug
>= debug_print_threshold
)
9159 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
9161 if (per_cu
->is_debug_types
)
9162 process_full_type_unit (cu
, item
.pretend_language
);
9164 process_full_comp_unit (cu
, item
.pretend_language
);
9166 if (dwarf_read_debug
>= debug_print_threshold
)
9167 dwarf_read_debug_printf ("Done expanding %s", buf
);
9172 per_objfile
->per_bfd
->queue
.pop ();
9175 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
9176 objfile_name (per_objfile
->objfile
));
9179 /* Read in full symbols for PST, and anything it depends on. */
9182 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9184 gdb_assert (!readin_p (objfile
));
9186 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9187 free_cached_comp_units
freer (per_objfile
);
9188 expand_dependencies (objfile
);
9190 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9191 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9194 /* See psympriv.h. */
9197 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9199 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9200 return per_objfile
->symtab_set_p (per_cu_data
);
9203 /* See psympriv.h. */
9206 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9208 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9209 return per_objfile
->get_symtab (per_cu_data
);
9212 /* Trivial hash function for die_info: the hash value of a DIE
9213 is its offset in .debug_info for this objfile. */
9216 die_hash (const void *item
)
9218 const struct die_info
*die
= (const struct die_info
*) item
;
9220 return to_underlying (die
->sect_off
);
9223 /* Trivial comparison function for die_info structures: two DIEs
9224 are equal if they have the same offset. */
9227 die_eq (const void *item_lhs
, const void *item_rhs
)
9229 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9230 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9232 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9235 /* Load the DIEs associated with PER_CU into memory.
9237 In some cases, the caller, while reading partial symbols, will need to load
9238 the full symbols for the CU for some reason. It will already have a
9239 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
9240 rather than creating a new one. */
9243 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9244 dwarf2_per_objfile
*per_objfile
,
9245 dwarf2_cu
*existing_cu
,
9247 enum language pretend_language
)
9249 gdb_assert (! this_cu
->is_debug_types
);
9251 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9255 struct dwarf2_cu
*cu
= reader
.cu
;
9256 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9258 gdb_assert (cu
->die_hash
== NULL
);
9260 htab_create_alloc_ex (cu
->header
.length
/ 12,
9264 &cu
->comp_unit_obstack
,
9265 hashtab_obstack_allocate
,
9266 dummy_obstack_deallocate
);
9268 if (reader
.comp_unit_die
->has_children
)
9269 reader
.comp_unit_die
->child
9270 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9271 &info_ptr
, reader
.comp_unit_die
);
9272 cu
->dies
= reader
.comp_unit_die
;
9273 /* comp_unit_die is not stored in die_hash, no need. */
9275 /* We try not to read any attributes in this function, because not
9276 all CUs needed for references have been loaded yet, and symbol
9277 table processing isn't initialized. But we have to set the CU language,
9278 or we won't be able to build types correctly.
9279 Similarly, if we do not read the producer, we can not apply
9280 producer-specific interpretation. */
9281 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9286 /* Add a DIE to the delayed physname list. */
9289 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9290 const char *name
, struct die_info
*die
,
9291 struct dwarf2_cu
*cu
)
9293 struct delayed_method_info mi
;
9295 mi
.fnfield_index
= fnfield_index
;
9299 cu
->method_list
.push_back (mi
);
9302 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9303 "const" / "volatile". If so, decrements LEN by the length of the
9304 modifier and return true. Otherwise return false. */
9308 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9310 size_t mod_len
= sizeof (mod
) - 1;
9311 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9319 /* Compute the physnames of any methods on the CU's method list.
9321 The computation of method physnames is delayed in order to avoid the
9322 (bad) condition that one of the method's formal parameters is of an as yet
9326 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9328 /* Only C++ delays computing physnames. */
9329 if (cu
->method_list
.empty ())
9331 gdb_assert (cu
->language
== language_cplus
);
9333 for (const delayed_method_info
&mi
: cu
->method_list
)
9335 const char *physname
;
9336 struct fn_fieldlist
*fn_flp
9337 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9338 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9339 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9340 = physname
? physname
: "";
9342 /* Since there's no tag to indicate whether a method is a
9343 const/volatile overload, extract that information out of the
9345 if (physname
!= NULL
)
9347 size_t len
= strlen (physname
);
9351 if (physname
[len
] == ')') /* shortcut */
9353 else if (check_modifier (physname
, len
, " const"))
9354 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9355 else if (check_modifier (physname
, len
, " volatile"))
9356 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9363 /* The list is no longer needed. */
9364 cu
->method_list
.clear ();
9367 /* Go objects should be embedded in a DW_TAG_module DIE,
9368 and it's not clear if/how imported objects will appear.
9369 To keep Go support simple until that's worked out,
9370 go back through what we've read and create something usable.
9371 We could do this while processing each DIE, and feels kinda cleaner,
9372 but that way is more invasive.
9373 This is to, for example, allow the user to type "p var" or "b main"
9374 without having to specify the package name, and allow lookups
9375 of module.object to work in contexts that use the expression
9379 fixup_go_packaging (struct dwarf2_cu
*cu
)
9381 gdb::unique_xmalloc_ptr
<char> package_name
;
9382 struct pending
*list
;
9385 for (list
= *cu
->get_builder ()->get_global_symbols ();
9389 for (i
= 0; i
< list
->nsyms
; ++i
)
9391 struct symbol
*sym
= list
->symbol
[i
];
9393 if (sym
->language () == language_go
9394 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9396 gdb::unique_xmalloc_ptr
<char> this_package_name
9397 (go_symbol_package_name (sym
));
9399 if (this_package_name
== NULL
)
9401 if (package_name
== NULL
)
9402 package_name
= std::move (this_package_name
);
9405 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9406 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9407 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9408 (symbol_symtab (sym
) != NULL
9409 ? symtab_to_filename_for_display
9410 (symbol_symtab (sym
))
9411 : objfile_name (objfile
)),
9412 this_package_name
.get (), package_name
.get ());
9418 if (package_name
!= NULL
)
9420 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9421 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9422 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9423 saved_package_name
);
9426 sym
= new (&objfile
->objfile_obstack
) symbol
;
9427 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9428 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9429 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9430 e.g., "main" finds the "main" module and not C's main(). */
9431 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9432 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9433 SYMBOL_TYPE (sym
) = type
;
9435 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9439 /* Allocate a fully-qualified name consisting of the two parts on the
9443 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9445 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9448 /* A helper that allocates a variant part to attach to a Rust enum
9449 type. OBSTACK is where the results should be allocated. TYPE is
9450 the type we're processing. DISCRIMINANT_INDEX is the index of the
9451 discriminant. It must be the index of one of the fields of TYPE,
9452 or -1 to mean there is no discriminant (univariant enum).
9453 DEFAULT_INDEX is the index of the default field; or -1 if there is
9454 no default. RANGES is indexed by "effective" field number (the
9455 field index, but omitting the discriminant and default fields) and
9456 must hold the discriminant values used by the variants. Note that
9457 RANGES must have a lifetime at least as long as OBSTACK -- either
9458 already allocated on it, or static. */
9461 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9462 int discriminant_index
, int default_index
,
9463 gdb::array_view
<discriminant_range
> ranges
)
9465 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
9466 gdb_assert (discriminant_index
== -1
9467 || (discriminant_index
>= 0
9468 && discriminant_index
< type
->num_fields ()));
9469 gdb_assert (default_index
== -1
9470 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9472 /* We have one variant for each non-discriminant field. */
9473 int n_variants
= type
->num_fields ();
9474 if (discriminant_index
!= -1)
9477 variant
*variants
= new (obstack
) variant
[n_variants
];
9480 for (int i
= 0; i
< type
->num_fields (); ++i
)
9482 if (i
== discriminant_index
)
9485 variants
[var_idx
].first_field
= i
;
9486 variants
[var_idx
].last_field
= i
+ 1;
9488 /* The default field does not need a range, but other fields do.
9489 We skipped the discriminant above. */
9490 if (i
!= default_index
)
9492 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9499 gdb_assert (range_idx
== ranges
.size ());
9500 gdb_assert (var_idx
== n_variants
);
9502 variant_part
*part
= new (obstack
) variant_part
;
9503 part
->discriminant_index
= discriminant_index
;
9504 /* If there is no discriminant, then whether it is signed is of no
9507 = (discriminant_index
== -1
9509 : type
->field (discriminant_index
).type ()->is_unsigned ());
9510 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9512 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9513 gdb::array_view
<variant_part
> *prop_value
9514 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9516 struct dynamic_prop prop
;
9517 prop
.set_variant_parts (prop_value
);
9519 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9522 /* Some versions of rustc emitted enums in an unusual way.
9524 Ordinary enums were emitted as unions. The first element of each
9525 structure in the union was named "RUST$ENUM$DISR". This element
9526 held the discriminant.
9528 These versions of Rust also implemented the "non-zero"
9529 optimization. When the enum had two values, and one is empty and
9530 the other holds a pointer that cannot be zero, the pointer is used
9531 as the discriminant, with a zero value meaning the empty variant.
9532 Here, the union's first member is of the form
9533 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9534 where the fieldnos are the indices of the fields that should be
9535 traversed in order to find the field (which may be several fields deep)
9536 and the variantname is the name of the variant of the case when the
9539 This function recognizes whether TYPE is of one of these forms,
9540 and, if so, smashes it to be a variant type. */
9543 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9545 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9547 /* We don't need to deal with empty enums. */
9548 if (type
->num_fields () == 0)
9551 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9552 if (type
->num_fields () == 1
9553 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9555 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9557 /* Decode the field name to find the offset of the
9559 ULONGEST bit_offset
= 0;
9560 struct type
*field_type
= type
->field (0).type ();
9561 while (name
[0] >= '0' && name
[0] <= '9')
9564 unsigned long index
= strtoul (name
, &tail
, 10);
9567 || index
>= field_type
->num_fields ()
9568 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9569 != FIELD_LOC_KIND_BITPOS
))
9571 complaint (_("Could not parse Rust enum encoding string \"%s\""
9573 TYPE_FIELD_NAME (type
, 0),
9574 objfile_name (objfile
));
9579 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9580 field_type
= field_type
->field (index
).type ();
9583 /* Smash this type to be a structure type. We have to do this
9584 because the type has already been recorded. */
9585 type
->set_code (TYPE_CODE_STRUCT
);
9586 type
->set_num_fields (3);
9587 /* Save the field we care about. */
9588 struct field saved_field
= type
->field (0);
9590 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9592 /* Put the discriminant at index 0. */
9593 type
->field (0).set_type (field_type
);
9594 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9595 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9596 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9598 /* The order of fields doesn't really matter, so put the real
9599 field at index 1 and the data-less field at index 2. */
9600 type
->field (1) = saved_field
;
9601 TYPE_FIELD_NAME (type
, 1)
9602 = rust_last_path_segment (type
->field (1).type ()->name ());
9603 type
->field (1).type ()->set_name
9604 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9605 TYPE_FIELD_NAME (type
, 1)));
9607 const char *dataless_name
9608 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9610 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9612 type
->field (2).set_type (dataless_type
);
9613 /* NAME points into the original discriminant name, which
9614 already has the correct lifetime. */
9615 TYPE_FIELD_NAME (type
, 2) = name
;
9616 SET_FIELD_BITPOS (type
->field (2), 0);
9618 /* Indicate that this is a variant type. */
9619 static discriminant_range ranges
[1] = { { 0, 0 } };
9620 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9622 /* A union with a single anonymous field is probably an old-style
9624 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9626 /* Smash this type to be a structure type. We have to do this
9627 because the type has already been recorded. */
9628 type
->set_code (TYPE_CODE_STRUCT
);
9630 struct type
*field_type
= type
->field (0).type ();
9631 const char *variant_name
9632 = rust_last_path_segment (field_type
->name ());
9633 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9634 field_type
->set_name
9635 (rust_fully_qualify (&objfile
->objfile_obstack
,
9636 type
->name (), variant_name
));
9638 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9642 struct type
*disr_type
= nullptr;
9643 for (int i
= 0; i
< type
->num_fields (); ++i
)
9645 disr_type
= type
->field (i
).type ();
9647 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9649 /* All fields of a true enum will be structs. */
9652 else if (disr_type
->num_fields () == 0)
9654 /* Could be data-less variant, so keep going. */
9655 disr_type
= nullptr;
9657 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9658 "RUST$ENUM$DISR") != 0)
9660 /* Not a Rust enum. */
9670 /* If we got here without a discriminant, then it's probably
9672 if (disr_type
== nullptr)
9675 /* Smash this type to be a structure type. We have to do this
9676 because the type has already been recorded. */
9677 type
->set_code (TYPE_CODE_STRUCT
);
9679 /* Make space for the discriminant field. */
9680 struct field
*disr_field
= &disr_type
->field (0);
9682 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9683 * sizeof (struct field
)));
9684 memcpy (new_fields
+ 1, type
->fields (),
9685 type
->num_fields () * sizeof (struct field
));
9686 type
->set_fields (new_fields
);
9687 type
->set_num_fields (type
->num_fields () + 1);
9689 /* Install the discriminant at index 0 in the union. */
9690 type
->field (0) = *disr_field
;
9691 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9692 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9694 /* We need a way to find the correct discriminant given a
9695 variant name. For convenience we build a map here. */
9696 struct type
*enum_type
= disr_field
->type ();
9697 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9698 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9700 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9703 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9704 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9708 int n_fields
= type
->num_fields ();
9709 /* We don't need a range entry for the discriminant, but we do
9710 need one for every other field, as there is no default
9712 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9715 /* Skip the discriminant here. */
9716 for (int i
= 1; i
< n_fields
; ++i
)
9718 /* Find the final word in the name of this variant's type.
9719 That name can be used to look up the correct
9721 const char *variant_name
9722 = rust_last_path_segment (type
->field (i
).type ()->name ());
9724 auto iter
= discriminant_map
.find (variant_name
);
9725 if (iter
!= discriminant_map
.end ())
9727 ranges
[i
- 1].low
= iter
->second
;
9728 ranges
[i
- 1].high
= iter
->second
;
9731 /* In Rust, each element should have the size of the
9733 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9735 /* Remove the discriminant field, if it exists. */
9736 struct type
*sub_type
= type
->field (i
).type ();
9737 if (sub_type
->num_fields () > 0)
9739 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9740 sub_type
->set_fields (sub_type
->fields () + 1);
9742 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9744 (rust_fully_qualify (&objfile
->objfile_obstack
,
9745 type
->name (), variant_name
));
9748 /* Indicate that this is a variant type. */
9749 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9750 gdb::array_view
<discriminant_range
> (ranges
,
9755 /* Rewrite some Rust unions to be structures with variants parts. */
9758 rust_union_quirks (struct dwarf2_cu
*cu
)
9760 gdb_assert (cu
->language
== language_rust
);
9761 for (type
*type_
: cu
->rust_unions
)
9762 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9763 /* We don't need this any more. */
9764 cu
->rust_unions
.clear ();
9769 type_unit_group_unshareable
*
9770 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9772 auto iter
= this->m_type_units
.find (tu_group
);
9773 if (iter
!= this->m_type_units
.end ())
9774 return iter
->second
.get ();
9776 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9777 type_unit_group_unshareable
*result
= uniq
.get ();
9778 this->m_type_units
[tu_group
] = std::move (uniq
);
9783 dwarf2_per_objfile::get_type_for_signatured_type
9784 (signatured_type
*sig_type
) const
9786 auto iter
= this->m_type_map
.find (sig_type
);
9787 if (iter
== this->m_type_map
.end ())
9790 return iter
->second
;
9793 void dwarf2_per_objfile::set_type_for_signatured_type
9794 (signatured_type
*sig_type
, struct type
*type
)
9796 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9798 this->m_type_map
[sig_type
] = type
;
9801 /* A helper function for computing the list of all symbol tables
9802 included by PER_CU. */
9805 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9806 htab_t all_children
, htab_t all_type_symtabs
,
9807 dwarf2_per_cu_data
*per_cu
,
9808 dwarf2_per_objfile
*per_objfile
,
9809 struct compunit_symtab
*immediate_parent
)
9811 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9814 /* This inclusion and its children have been processed. */
9820 /* Only add a CU if it has a symbol table. */
9821 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9824 /* If this is a type unit only add its symbol table if we haven't
9825 seen it yet (type unit per_cu's can share symtabs). */
9826 if (per_cu
->is_debug_types
)
9828 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9832 result
->push_back (cust
);
9833 if (cust
->user
== NULL
)
9834 cust
->user
= immediate_parent
;
9839 result
->push_back (cust
);
9840 if (cust
->user
== NULL
)
9841 cust
->user
= immediate_parent
;
9845 if (!per_cu
->imported_symtabs_empty ())
9846 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9848 recursively_compute_inclusions (result
, all_children
,
9849 all_type_symtabs
, ptr
, per_objfile
,
9854 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9858 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9859 dwarf2_per_objfile
*per_objfile
)
9861 gdb_assert (! per_cu
->is_debug_types
);
9863 if (!per_cu
->imported_symtabs_empty ())
9866 std::vector
<compunit_symtab
*> result_symtabs
;
9867 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9869 /* If we don't have a symtab, we can just skip this case. */
9873 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9875 NULL
, xcalloc
, xfree
));
9876 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9878 NULL
, xcalloc
, xfree
));
9880 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9882 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9883 all_type_symtabs
.get (), ptr
,
9887 /* Now we have a transitive closure of all the included symtabs. */
9888 len
= result_symtabs
.size ();
9890 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9891 struct compunit_symtab
*, len
+ 1);
9892 memcpy (cust
->includes
, result_symtabs
.data (),
9893 len
* sizeof (compunit_symtab
*));
9894 cust
->includes
[len
] = NULL
;
9898 /* Compute the 'includes' field for the symtabs of all the CUs we just
9902 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9904 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9906 if (! iter
->is_debug_types
)
9907 compute_compunit_symtab_includes (iter
, per_objfile
);
9910 per_objfile
->per_bfd
->just_read_cus
.clear ();
9913 /* Generate full symbol information for CU, whose DIEs have
9914 already been loaded into memory. */
9917 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9919 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9920 struct objfile
*objfile
= per_objfile
->objfile
;
9921 struct gdbarch
*gdbarch
= objfile
->arch ();
9922 CORE_ADDR lowpc
, highpc
;
9923 struct compunit_symtab
*cust
;
9925 struct block
*static_block
;
9928 baseaddr
= objfile
->text_section_offset ();
9930 /* Clear the list here in case something was left over. */
9931 cu
->method_list
.clear ();
9933 cu
->language
= pretend_language
;
9934 cu
->language_defn
= language_def (cu
->language
);
9936 dwarf2_find_base_address (cu
->dies
, cu
);
9938 /* Do line number decoding in read_file_scope () */
9939 process_die (cu
->dies
, cu
);
9941 /* For now fudge the Go package. */
9942 if (cu
->language
== language_go
)
9943 fixup_go_packaging (cu
);
9945 /* Now that we have processed all the DIEs in the CU, all the types
9946 should be complete, and it should now be safe to compute all of the
9948 compute_delayed_physnames (cu
);
9950 if (cu
->language
== language_rust
)
9951 rust_union_quirks (cu
);
9953 /* Some compilers don't define a DW_AT_high_pc attribute for the
9954 compilation unit. If the DW_AT_high_pc is missing, synthesize
9955 it, by scanning the DIE's below the compilation unit. */
9956 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9958 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9959 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9961 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9962 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9963 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9964 addrmap to help ensure it has an accurate map of pc values belonging to
9966 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9968 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9969 SECT_OFF_TEXT (objfile
),
9974 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9976 /* Set symtab language to language from DW_AT_language. If the
9977 compilation is from a C file generated by language preprocessors, do
9978 not set the language if it was already deduced by start_subfile. */
9979 if (!(cu
->language
== language_c
9980 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9981 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9983 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9984 produce DW_AT_location with location lists but it can be possibly
9985 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9986 there were bugs in prologue debug info, fixed later in GCC-4.5
9987 by "unwind info for epilogues" patch (which is not directly related).
9989 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9990 needed, it would be wrong due to missing DW_AT_producer there.
9992 Still one can confuse GDB by using non-standard GCC compilation
9993 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9995 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9996 cust
->locations_valid
= 1;
9998 if (gcc_4_minor
>= 5)
9999 cust
->epilogue_unwind_valid
= 1;
10001 cust
->call_site_htab
= cu
->call_site_htab
;
10004 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10006 /* Push it for inclusion processing later. */
10007 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
10009 /* Not needed any more. */
10010 cu
->reset_builder ();
10013 /* Generate full symbol information for type unit CU, whose DIEs have
10014 already been loaded into memory. */
10017 process_full_type_unit (dwarf2_cu
*cu
,
10018 enum language pretend_language
)
10020 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10021 struct objfile
*objfile
= per_objfile
->objfile
;
10022 struct compunit_symtab
*cust
;
10023 struct signatured_type
*sig_type
;
10025 gdb_assert (cu
->per_cu
->is_debug_types
);
10026 sig_type
= (struct signatured_type
*) cu
->per_cu
;
10028 /* Clear the list here in case something was left over. */
10029 cu
->method_list
.clear ();
10031 cu
->language
= pretend_language
;
10032 cu
->language_defn
= language_def (cu
->language
);
10034 /* The symbol tables are set up in read_type_unit_scope. */
10035 process_die (cu
->dies
, cu
);
10037 /* For now fudge the Go package. */
10038 if (cu
->language
== language_go
)
10039 fixup_go_packaging (cu
);
10041 /* Now that we have processed all the DIEs in the CU, all the types
10042 should be complete, and it should now be safe to compute all of the
10044 compute_delayed_physnames (cu
);
10046 if (cu
->language
== language_rust
)
10047 rust_union_quirks (cu
);
10049 /* TUs share symbol tables.
10050 If this is the first TU to use this symtab, complete the construction
10051 of it with end_expandable_symtab. Otherwise, complete the addition of
10052 this TU's symbols to the existing symtab. */
10053 type_unit_group_unshareable
*tug_unshare
=
10054 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
10055 if (tug_unshare
->compunit_symtab
== NULL
)
10057 buildsym_compunit
*builder
= cu
->get_builder ();
10058 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10059 tug_unshare
->compunit_symtab
= cust
;
10063 /* Set symtab language to language from DW_AT_language. If the
10064 compilation is from a C file generated by language preprocessors,
10065 do not set the language if it was already deduced by
10067 if (!(cu
->language
== language_c
10068 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10069 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10074 cu
->get_builder ()->augment_type_symtab ();
10075 cust
= tug_unshare
->compunit_symtab
;
10078 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10080 /* Not needed any more. */
10081 cu
->reset_builder ();
10084 /* Process an imported unit DIE. */
10087 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10089 struct attribute
*attr
;
10091 /* For now we don't handle imported units in type units. */
10092 if (cu
->per_cu
->is_debug_types
)
10094 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10095 " supported in type units [in module %s]"),
10096 objfile_name (cu
->per_objfile
->objfile
));
10099 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10102 sect_offset sect_off
= attr
->get_ref_die_offset ();
10103 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10104 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10105 dwarf2_per_cu_data
*per_cu
10106 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10108 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10109 into another compilation unit, at root level. Regard this as a hint,
10111 if (die
->parent
&& die
->parent
->parent
== NULL
10112 && per_cu
->unit_type
== DW_UT_compile
10113 && per_cu
->lang
== language_cplus
)
10116 /* If necessary, add it to the queue and load its DIEs. */
10117 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10118 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
10119 false, cu
->language
);
10121 cu
->per_cu
->imported_symtabs_push (per_cu
);
10125 /* RAII object that represents a process_die scope: i.e.,
10126 starts/finishes processing a DIE. */
10127 class process_die_scope
10130 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10131 : m_die (die
), m_cu (cu
)
10133 /* We should only be processing DIEs not already in process. */
10134 gdb_assert (!m_die
->in_process
);
10135 m_die
->in_process
= true;
10138 ~process_die_scope ()
10140 m_die
->in_process
= false;
10142 /* If we're done processing the DIE for the CU that owns the line
10143 header, we don't need the line header anymore. */
10144 if (m_cu
->line_header_die_owner
== m_die
)
10146 delete m_cu
->line_header
;
10147 m_cu
->line_header
= NULL
;
10148 m_cu
->line_header_die_owner
= NULL
;
10157 /* Process a die and its children. */
10160 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10162 process_die_scope
scope (die
, cu
);
10166 case DW_TAG_padding
:
10168 case DW_TAG_compile_unit
:
10169 case DW_TAG_partial_unit
:
10170 read_file_scope (die
, cu
);
10172 case DW_TAG_type_unit
:
10173 read_type_unit_scope (die
, cu
);
10175 case DW_TAG_subprogram
:
10176 /* Nested subprograms in Fortran get a prefix. */
10177 if (cu
->language
== language_fortran
10178 && die
->parent
!= NULL
10179 && die
->parent
->tag
== DW_TAG_subprogram
)
10180 cu
->processing_has_namespace_info
= true;
10181 /* Fall through. */
10182 case DW_TAG_inlined_subroutine
:
10183 read_func_scope (die
, cu
);
10185 case DW_TAG_lexical_block
:
10186 case DW_TAG_try_block
:
10187 case DW_TAG_catch_block
:
10188 read_lexical_block_scope (die
, cu
);
10190 case DW_TAG_call_site
:
10191 case DW_TAG_GNU_call_site
:
10192 read_call_site_scope (die
, cu
);
10194 case DW_TAG_class_type
:
10195 case DW_TAG_interface_type
:
10196 case DW_TAG_structure_type
:
10197 case DW_TAG_union_type
:
10198 process_structure_scope (die
, cu
);
10200 case DW_TAG_enumeration_type
:
10201 process_enumeration_scope (die
, cu
);
10204 /* These dies have a type, but processing them does not create
10205 a symbol or recurse to process the children. Therefore we can
10206 read them on-demand through read_type_die. */
10207 case DW_TAG_subroutine_type
:
10208 case DW_TAG_set_type
:
10209 case DW_TAG_pointer_type
:
10210 case DW_TAG_ptr_to_member_type
:
10211 case DW_TAG_reference_type
:
10212 case DW_TAG_rvalue_reference_type
:
10213 case DW_TAG_string_type
:
10216 case DW_TAG_array_type
:
10217 /* We only need to handle this case for Ada -- in other
10218 languages, it's normal for the compiler to emit a typedef
10220 if (cu
->language
!= language_ada
)
10223 case DW_TAG_base_type
:
10224 case DW_TAG_subrange_type
:
10225 case DW_TAG_typedef
:
10226 /* Add a typedef symbol for the type definition, if it has a
10228 new_symbol (die
, read_type_die (die
, cu
), cu
);
10230 case DW_TAG_common_block
:
10231 read_common_block (die
, cu
);
10233 case DW_TAG_common_inclusion
:
10235 case DW_TAG_namespace
:
10236 cu
->processing_has_namespace_info
= true;
10237 read_namespace (die
, cu
);
10239 case DW_TAG_module
:
10240 cu
->processing_has_namespace_info
= true;
10241 read_module (die
, cu
);
10243 case DW_TAG_imported_declaration
:
10244 cu
->processing_has_namespace_info
= true;
10245 if (read_namespace_alias (die
, cu
))
10247 /* The declaration is not a global namespace alias. */
10248 /* Fall through. */
10249 case DW_TAG_imported_module
:
10250 cu
->processing_has_namespace_info
= true;
10251 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10252 || cu
->language
!= language_fortran
))
10253 complaint (_("Tag '%s' has unexpected children"),
10254 dwarf_tag_name (die
->tag
));
10255 read_import_statement (die
, cu
);
10258 case DW_TAG_imported_unit
:
10259 process_imported_unit_die (die
, cu
);
10262 case DW_TAG_variable
:
10263 read_variable (die
, cu
);
10267 new_symbol (die
, NULL
, cu
);
10272 /* DWARF name computation. */
10274 /* A helper function for dwarf2_compute_name which determines whether DIE
10275 needs to have the name of the scope prepended to the name listed in the
10279 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10281 struct attribute
*attr
;
10285 case DW_TAG_namespace
:
10286 case DW_TAG_typedef
:
10287 case DW_TAG_class_type
:
10288 case DW_TAG_interface_type
:
10289 case DW_TAG_structure_type
:
10290 case DW_TAG_union_type
:
10291 case DW_TAG_enumeration_type
:
10292 case DW_TAG_enumerator
:
10293 case DW_TAG_subprogram
:
10294 case DW_TAG_inlined_subroutine
:
10295 case DW_TAG_member
:
10296 case DW_TAG_imported_declaration
:
10299 case DW_TAG_variable
:
10300 case DW_TAG_constant
:
10301 /* We only need to prefix "globally" visible variables. These include
10302 any variable marked with DW_AT_external or any variable that
10303 lives in a namespace. [Variables in anonymous namespaces
10304 require prefixing, but they are not DW_AT_external.] */
10306 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10308 struct dwarf2_cu
*spec_cu
= cu
;
10310 return die_needs_namespace (die_specification (die
, &spec_cu
),
10314 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10315 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10316 && die
->parent
->tag
!= DW_TAG_module
)
10318 /* A variable in a lexical block of some kind does not need a
10319 namespace, even though in C++ such variables may be external
10320 and have a mangled name. */
10321 if (die
->parent
->tag
== DW_TAG_lexical_block
10322 || die
->parent
->tag
== DW_TAG_try_block
10323 || die
->parent
->tag
== DW_TAG_catch_block
10324 || die
->parent
->tag
== DW_TAG_subprogram
)
10333 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10334 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10335 defined for the given DIE. */
10337 static struct attribute
*
10338 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10340 struct attribute
*attr
;
10342 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10344 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10349 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10350 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10351 defined for the given DIE. */
10353 static const char *
10354 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10356 const char *linkage_name
;
10358 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10359 if (linkage_name
== NULL
)
10360 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10362 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10363 See https://github.com/rust-lang/rust/issues/32925. */
10364 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10365 && strchr (linkage_name
, '{') != NULL
)
10366 linkage_name
= NULL
;
10368 return linkage_name
;
10371 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10372 compute the physname for the object, which include a method's:
10373 - formal parameters (C++),
10374 - receiver type (Go),
10376 The term "physname" is a bit confusing.
10377 For C++, for example, it is the demangled name.
10378 For Go, for example, it's the mangled name.
10380 For Ada, return the DIE's linkage name rather than the fully qualified
10381 name. PHYSNAME is ignored..
10383 The result is allocated on the objfile->per_bfd's obstack and
10386 static const char *
10387 dwarf2_compute_name (const char *name
,
10388 struct die_info
*die
, struct dwarf2_cu
*cu
,
10391 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10394 name
= dwarf2_name (die
, cu
);
10396 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10397 but otherwise compute it by typename_concat inside GDB.
10398 FIXME: Actually this is not really true, or at least not always true.
10399 It's all very confusing. compute_and_set_names doesn't try to demangle
10400 Fortran names because there is no mangling standard. So new_symbol
10401 will set the demangled name to the result of dwarf2_full_name, and it is
10402 the demangled name that GDB uses if it exists. */
10403 if (cu
->language
== language_ada
10404 || (cu
->language
== language_fortran
&& physname
))
10406 /* For Ada unit, we prefer the linkage name over the name, as
10407 the former contains the exported name, which the user expects
10408 to be able to reference. Ideally, we want the user to be able
10409 to reference this entity using either natural or linkage name,
10410 but we haven't started looking at this enhancement yet. */
10411 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10413 if (linkage_name
!= NULL
)
10414 return linkage_name
;
10417 /* These are the only languages we know how to qualify names in. */
10419 && (cu
->language
== language_cplus
10420 || cu
->language
== language_fortran
|| cu
->language
== language_d
10421 || cu
->language
== language_rust
))
10423 if (die_needs_namespace (die
, cu
))
10425 const char *prefix
;
10426 const char *canonical_name
= NULL
;
10430 prefix
= determine_prefix (die
, cu
);
10431 if (*prefix
!= '\0')
10433 gdb::unique_xmalloc_ptr
<char> prefixed_name
10434 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10436 buf
.puts (prefixed_name
.get ());
10441 /* Template parameters may be specified in the DIE's DW_AT_name, or
10442 as children with DW_TAG_template_type_param or
10443 DW_TAG_value_type_param. If the latter, add them to the name
10444 here. If the name already has template parameters, then
10445 skip this step; some versions of GCC emit both, and
10446 it is more efficient to use the pre-computed name.
10448 Something to keep in mind about this process: it is very
10449 unlikely, or in some cases downright impossible, to produce
10450 something that will match the mangled name of a function.
10451 If the definition of the function has the same debug info,
10452 we should be able to match up with it anyway. But fallbacks
10453 using the minimal symbol, for instance to find a method
10454 implemented in a stripped copy of libstdc++, will not work.
10455 If we do not have debug info for the definition, we will have to
10456 match them up some other way.
10458 When we do name matching there is a related problem with function
10459 templates; two instantiated function templates are allowed to
10460 differ only by their return types, which we do not add here. */
10462 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10464 struct attribute
*attr
;
10465 struct die_info
*child
;
10468 die
->building_fullname
= 1;
10470 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10474 const gdb_byte
*bytes
;
10475 struct dwarf2_locexpr_baton
*baton
;
10478 if (child
->tag
!= DW_TAG_template_type_param
10479 && child
->tag
!= DW_TAG_template_value_param
)
10490 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10493 complaint (_("template parameter missing DW_AT_type"));
10494 buf
.puts ("UNKNOWN_TYPE");
10497 type
= die_type (child
, cu
);
10499 if (child
->tag
== DW_TAG_template_type_param
)
10501 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10502 &type_print_raw_options
);
10506 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10509 complaint (_("template parameter missing "
10510 "DW_AT_const_value"));
10511 buf
.puts ("UNKNOWN_VALUE");
10515 dwarf2_const_value_attr (attr
, type
, name
,
10516 &cu
->comp_unit_obstack
, cu
,
10517 &value
, &bytes
, &baton
);
10519 if (type
->has_no_signedness ())
10520 /* GDB prints characters as NUMBER 'CHAR'. If that's
10521 changed, this can use value_print instead. */
10522 c_printchar (value
, type
, &buf
);
10525 struct value_print_options opts
;
10528 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10532 baton
->per_objfile
);
10533 else if (bytes
!= NULL
)
10535 v
= allocate_value (type
);
10536 memcpy (value_contents_writeable (v
), bytes
,
10537 TYPE_LENGTH (type
));
10540 v
= value_from_longest (type
, value
);
10542 /* Specify decimal so that we do not depend on
10544 get_formatted_print_options (&opts
, 'd');
10546 value_print (v
, &buf
, &opts
);
10551 die
->building_fullname
= 0;
10555 /* Close the argument list, with a space if necessary
10556 (nested templates). */
10557 if (!buf
.empty () && buf
.string ().back () == '>')
10564 /* For C++ methods, append formal parameter type
10565 information, if PHYSNAME. */
10567 if (physname
&& die
->tag
== DW_TAG_subprogram
10568 && cu
->language
== language_cplus
)
10570 struct type
*type
= read_type_die (die
, cu
);
10572 c_type_print_args (type
, &buf
, 1, cu
->language
,
10573 &type_print_raw_options
);
10575 if (cu
->language
== language_cplus
)
10577 /* Assume that an artificial first parameter is
10578 "this", but do not crash if it is not. RealView
10579 marks unnamed (and thus unused) parameters as
10580 artificial; there is no way to differentiate
10582 if (type
->num_fields () > 0
10583 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10584 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10585 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10586 buf
.puts (" const");
10590 const std::string
&intermediate_name
= buf
.string ();
10592 if (cu
->language
== language_cplus
)
10594 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10597 /* If we only computed INTERMEDIATE_NAME, or if
10598 INTERMEDIATE_NAME is already canonical, then we need to
10600 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10601 name
= objfile
->intern (intermediate_name
);
10603 name
= canonical_name
;
10610 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10611 If scope qualifiers are appropriate they will be added. The result
10612 will be allocated on the storage_obstack, or NULL if the DIE does
10613 not have a name. NAME may either be from a previous call to
10614 dwarf2_name or NULL.
10616 The output string will be canonicalized (if C++). */
10618 static const char *
10619 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10621 return dwarf2_compute_name (name
, die
, cu
, 0);
10624 /* Construct a physname for the given DIE in CU. NAME may either be
10625 from a previous call to dwarf2_name or NULL. The result will be
10626 allocated on the objfile_objstack or NULL if the DIE does not have a
10629 The output string will be canonicalized (if C++). */
10631 static const char *
10632 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10634 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10635 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10638 /* In this case dwarf2_compute_name is just a shortcut not building anything
10640 if (!die_needs_namespace (die
, cu
))
10641 return dwarf2_compute_name (name
, die
, cu
, 1);
10643 if (cu
->language
!= language_rust
)
10644 mangled
= dw2_linkage_name (die
, cu
);
10646 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10648 gdb::unique_xmalloc_ptr
<char> demangled
;
10649 if (mangled
!= NULL
)
10652 if (language_def (cu
->language
)->store_sym_names_in_linkage_form_p ())
10654 /* Do nothing (do not demangle the symbol name). */
10658 /* Use DMGL_RET_DROP for C++ template functions to suppress
10659 their return type. It is easier for GDB users to search
10660 for such functions as `name(params)' than `long name(params)'.
10661 In such case the minimal symbol names do not match the full
10662 symbol names but for template functions there is never a need
10663 to look up their definition from their declaration so
10664 the only disadvantage remains the minimal symbol variant
10665 `long name(params)' does not have the proper inferior type. */
10666 demangled
.reset (gdb_demangle (mangled
,
10667 (DMGL_PARAMS
| DMGL_ANSI
10668 | DMGL_RET_DROP
)));
10671 canon
= demangled
.get ();
10679 if (canon
== NULL
|| check_physname
)
10681 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10683 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10685 /* It may not mean a bug in GDB. The compiler could also
10686 compute DW_AT_linkage_name incorrectly. But in such case
10687 GDB would need to be bug-to-bug compatible. */
10689 complaint (_("Computed physname <%s> does not match demangled <%s> "
10690 "(from linkage <%s>) - DIE at %s [in module %s]"),
10691 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10692 objfile_name (objfile
));
10694 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10695 is available here - over computed PHYSNAME. It is safer
10696 against both buggy GDB and buggy compilers. */
10710 retval
= objfile
->intern (retval
);
10715 /* Inspect DIE in CU for a namespace alias. If one exists, record
10716 a new symbol for it.
10718 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10721 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10723 struct attribute
*attr
;
10725 /* If the die does not have a name, this is not a namespace
10727 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10731 struct die_info
*d
= die
;
10732 struct dwarf2_cu
*imported_cu
= cu
;
10734 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10735 keep inspecting DIEs until we hit the underlying import. */
10736 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10737 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10739 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10743 d
= follow_die_ref (d
, attr
, &imported_cu
);
10744 if (d
->tag
!= DW_TAG_imported_declaration
)
10748 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10750 complaint (_("DIE at %s has too many recursively imported "
10751 "declarations"), sect_offset_str (d
->sect_off
));
10758 sect_offset sect_off
= attr
->get_ref_die_offset ();
10760 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10761 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10763 /* This declaration is a global namespace alias. Add
10764 a symbol for it whose type is the aliased namespace. */
10765 new_symbol (die
, type
, cu
);
10774 /* Return the using directives repository (global or local?) to use in the
10775 current context for CU.
10777 For Ada, imported declarations can materialize renamings, which *may* be
10778 global. However it is impossible (for now?) in DWARF to distinguish
10779 "external" imported declarations and "static" ones. As all imported
10780 declarations seem to be static in all other languages, make them all CU-wide
10781 global only in Ada. */
10783 static struct using_direct
**
10784 using_directives (struct dwarf2_cu
*cu
)
10786 if (cu
->language
== language_ada
10787 && cu
->get_builder ()->outermost_context_p ())
10788 return cu
->get_builder ()->get_global_using_directives ();
10790 return cu
->get_builder ()->get_local_using_directives ();
10793 /* Read the import statement specified by the given die and record it. */
10796 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10798 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10799 struct attribute
*import_attr
;
10800 struct die_info
*imported_die
, *child_die
;
10801 struct dwarf2_cu
*imported_cu
;
10802 const char *imported_name
;
10803 const char *imported_name_prefix
;
10804 const char *canonical_name
;
10805 const char *import_alias
;
10806 const char *imported_declaration
= NULL
;
10807 const char *import_prefix
;
10808 std::vector
<const char *> excludes
;
10810 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10811 if (import_attr
== NULL
)
10813 complaint (_("Tag '%s' has no DW_AT_import"),
10814 dwarf_tag_name (die
->tag
));
10819 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10820 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10821 if (imported_name
== NULL
)
10823 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10825 The import in the following code:
10839 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10840 <52> DW_AT_decl_file : 1
10841 <53> DW_AT_decl_line : 6
10842 <54> DW_AT_import : <0x75>
10843 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10844 <59> DW_AT_name : B
10845 <5b> DW_AT_decl_file : 1
10846 <5c> DW_AT_decl_line : 2
10847 <5d> DW_AT_type : <0x6e>
10849 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10850 <76> DW_AT_byte_size : 4
10851 <77> DW_AT_encoding : 5 (signed)
10853 imports the wrong die ( 0x75 instead of 0x58 ).
10854 This case will be ignored until the gcc bug is fixed. */
10858 /* Figure out the local name after import. */
10859 import_alias
= dwarf2_name (die
, cu
);
10861 /* Figure out where the statement is being imported to. */
10862 import_prefix
= determine_prefix (die
, cu
);
10864 /* Figure out what the scope of the imported die is and prepend it
10865 to the name of the imported die. */
10866 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10868 if (imported_die
->tag
!= DW_TAG_namespace
10869 && imported_die
->tag
!= DW_TAG_module
)
10871 imported_declaration
= imported_name
;
10872 canonical_name
= imported_name_prefix
;
10874 else if (strlen (imported_name_prefix
) > 0)
10875 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10876 imported_name_prefix
,
10877 (cu
->language
== language_d
? "." : "::"),
10878 imported_name
, (char *) NULL
);
10880 canonical_name
= imported_name
;
10882 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10883 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10884 child_die
= child_die
->sibling
)
10886 /* DWARF-4: A Fortran use statement with a “rename list” may be
10887 represented by an imported module entry with an import attribute
10888 referring to the module and owned entries corresponding to those
10889 entities that are renamed as part of being imported. */
10891 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10893 complaint (_("child DW_TAG_imported_declaration expected "
10894 "- DIE at %s [in module %s]"),
10895 sect_offset_str (child_die
->sect_off
),
10896 objfile_name (objfile
));
10900 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10901 if (import_attr
== NULL
)
10903 complaint (_("Tag '%s' has no DW_AT_import"),
10904 dwarf_tag_name (child_die
->tag
));
10909 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10911 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10912 if (imported_name
== NULL
)
10914 complaint (_("child DW_TAG_imported_declaration has unknown "
10915 "imported name - DIE at %s [in module %s]"),
10916 sect_offset_str (child_die
->sect_off
),
10917 objfile_name (objfile
));
10921 excludes
.push_back (imported_name
);
10923 process_die (child_die
, cu
);
10926 add_using_directive (using_directives (cu
),
10930 imported_declaration
,
10933 &objfile
->objfile_obstack
);
10936 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10937 types, but gives them a size of zero. Starting with version 14,
10938 ICC is compatible with GCC. */
10941 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10943 if (!cu
->checked_producer
)
10944 check_producer (cu
);
10946 return cu
->producer_is_icc_lt_14
;
10949 /* ICC generates a DW_AT_type for C void functions. This was observed on
10950 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10951 which says that void functions should not have a DW_AT_type. */
10954 producer_is_icc (struct dwarf2_cu
*cu
)
10956 if (!cu
->checked_producer
)
10957 check_producer (cu
);
10959 return cu
->producer_is_icc
;
10962 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10963 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10964 this, it was first present in GCC release 4.3.0. */
10967 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10969 if (!cu
->checked_producer
)
10970 check_producer (cu
);
10972 return cu
->producer_is_gcc_lt_4_3
;
10975 static file_and_directory
10976 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10978 file_and_directory res
;
10980 /* Find the filename. Do not use dwarf2_name here, since the filename
10981 is not a source language identifier. */
10982 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10983 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10985 if (res
.comp_dir
== NULL
10986 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10987 && IS_ABSOLUTE_PATH (res
.name
))
10989 res
.comp_dir_storage
= ldirname (res
.name
);
10990 if (!res
.comp_dir_storage
.empty ())
10991 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10993 if (res
.comp_dir
!= NULL
)
10995 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10996 directory, get rid of it. */
10997 const char *cp
= strchr (res
.comp_dir
, ':');
10999 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11000 res
.comp_dir
= cp
+ 1;
11003 if (res
.name
== NULL
)
11004 res
.name
= "<unknown>";
11009 /* Handle DW_AT_stmt_list for a compilation unit.
11010 DIE is the DW_TAG_compile_unit die for CU.
11011 COMP_DIR is the compilation directory. LOWPC is passed to
11012 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11015 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11016 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11018 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11019 struct attribute
*attr
;
11020 struct line_header line_header_local
;
11021 hashval_t line_header_local_hash
;
11023 int decode_mapping
;
11025 gdb_assert (! cu
->per_cu
->is_debug_types
);
11027 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11028 if (attr
== NULL
|| !attr
->form_is_unsigned ())
11031 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11033 /* The line header hash table is only created if needed (it exists to
11034 prevent redundant reading of the line table for partial_units).
11035 If we're given a partial_unit, we'll need it. If we're given a
11036 compile_unit, then use the line header hash table if it's already
11037 created, but don't create one just yet. */
11039 if (per_objfile
->line_header_hash
== NULL
11040 && die
->tag
== DW_TAG_partial_unit
)
11042 per_objfile
->line_header_hash
11043 .reset (htab_create_alloc (127, line_header_hash_voidp
,
11044 line_header_eq_voidp
,
11045 free_line_header_voidp
,
11049 line_header_local
.sect_off
= line_offset
;
11050 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11051 line_header_local_hash
= line_header_hash (&line_header_local
);
11052 if (per_objfile
->line_header_hash
!= NULL
)
11054 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11055 &line_header_local
,
11056 line_header_local_hash
, NO_INSERT
);
11058 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11059 is not present in *SLOT (since if there is something in *SLOT then
11060 it will be for a partial_unit). */
11061 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11063 gdb_assert (*slot
!= NULL
);
11064 cu
->line_header
= (struct line_header
*) *slot
;
11069 /* dwarf_decode_line_header does not yet provide sufficient information.
11070 We always have to call also dwarf_decode_lines for it. */
11071 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11075 cu
->line_header
= lh
.release ();
11076 cu
->line_header_die_owner
= die
;
11078 if (per_objfile
->line_header_hash
== NULL
)
11082 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11083 &line_header_local
,
11084 line_header_local_hash
, INSERT
);
11085 gdb_assert (slot
!= NULL
);
11087 if (slot
!= NULL
&& *slot
== NULL
)
11089 /* This newly decoded line number information unit will be owned
11090 by line_header_hash hash table. */
11091 *slot
= cu
->line_header
;
11092 cu
->line_header_die_owner
= NULL
;
11096 /* We cannot free any current entry in (*slot) as that struct line_header
11097 may be already used by multiple CUs. Create only temporary decoded
11098 line_header for this CU - it may happen at most once for each line
11099 number information unit. And if we're not using line_header_hash
11100 then this is what we want as well. */
11101 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11103 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11104 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11109 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11112 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11114 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11115 struct objfile
*objfile
= per_objfile
->objfile
;
11116 struct gdbarch
*gdbarch
= objfile
->arch ();
11117 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11118 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11119 struct attribute
*attr
;
11120 struct die_info
*child_die
;
11121 CORE_ADDR baseaddr
;
11123 prepare_one_comp_unit (cu
, die
, cu
->language
);
11124 baseaddr
= objfile
->text_section_offset ();
11126 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11128 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11129 from finish_block. */
11130 if (lowpc
== ((CORE_ADDR
) -1))
11132 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11134 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11136 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11137 standardised yet. As a workaround for the language detection we fall
11138 back to the DW_AT_producer string. */
11139 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11140 cu
->language
= language_opencl
;
11142 /* Similar hack for Go. */
11143 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11144 set_cu_language (DW_LANG_Go
, cu
);
11146 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11148 /* Decode line number information if present. We do this before
11149 processing child DIEs, so that the line header table is available
11150 for DW_AT_decl_file. */
11151 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11153 /* Process all dies in compilation unit. */
11154 if (die
->child
!= NULL
)
11156 child_die
= die
->child
;
11157 while (child_die
&& child_die
->tag
)
11159 process_die (child_die
, cu
);
11160 child_die
= child_die
->sibling
;
11164 /* Decode macro information, if present. Dwarf 2 macro information
11165 refers to information in the line number info statement program
11166 header, so we can only read it if we've read the header
11168 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11170 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11171 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11173 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11174 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11176 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
11180 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11181 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11183 unsigned int macro_offset
= attr
->as_unsigned ();
11185 dwarf_decode_macros (cu
, macro_offset
, 0);
11191 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11193 struct type_unit_group
*tu_group
;
11195 struct attribute
*attr
;
11197 struct signatured_type
*sig_type
;
11199 gdb_assert (per_cu
->is_debug_types
);
11200 sig_type
= (struct signatured_type
*) per_cu
;
11202 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11204 /* If we're using .gdb_index (includes -readnow) then
11205 per_cu->type_unit_group may not have been set up yet. */
11206 if (sig_type
->type_unit_group
== NULL
)
11207 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11208 tu_group
= sig_type
->type_unit_group
;
11210 /* If we've already processed this stmt_list there's no real need to
11211 do it again, we could fake it and just recreate the part we need
11212 (file name,index -> symtab mapping). If data shows this optimization
11213 is useful we can do it then. */
11214 type_unit_group_unshareable
*tug_unshare
11215 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11216 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11218 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11221 if (attr
!= NULL
&& attr
->form_is_unsigned ())
11223 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11224 lh
= dwarf_decode_line_header (line_offset
, this);
11229 start_symtab ("", NULL
, 0);
11232 gdb_assert (tug_unshare
->symtabs
== NULL
);
11233 gdb_assert (m_builder
== nullptr);
11234 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11235 m_builder
.reset (new struct buildsym_compunit
11236 (COMPUNIT_OBJFILE (cust
), "",
11237 COMPUNIT_DIRNAME (cust
),
11238 compunit_language (cust
),
11240 list_in_scope
= get_builder ()->get_file_symbols ();
11245 line_header
= lh
.release ();
11246 line_header_die_owner
= die
;
11250 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11252 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11253 still initializing it, and our caller (a few levels up)
11254 process_full_type_unit still needs to know if this is the first
11257 tug_unshare
->symtabs
11258 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11259 struct symtab
*, line_header
->file_names_size ());
11261 auto &file_names
= line_header
->file_names ();
11262 for (i
= 0; i
< file_names
.size (); ++i
)
11264 file_entry
&fe
= file_names
[i
];
11265 dwarf2_start_subfile (this, fe
.name
,
11266 fe
.include_dir (line_header
));
11267 buildsym_compunit
*b
= get_builder ();
11268 if (b
->get_current_subfile ()->symtab
== NULL
)
11270 /* NOTE: start_subfile will recognize when it's been
11271 passed a file it has already seen. So we can't
11272 assume there's a simple mapping from
11273 cu->line_header->file_names to subfiles, plus
11274 cu->line_header->file_names may contain dups. */
11275 b
->get_current_subfile ()->symtab
11276 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11279 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11280 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11285 gdb_assert (m_builder
== nullptr);
11286 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11287 m_builder
.reset (new struct buildsym_compunit
11288 (COMPUNIT_OBJFILE (cust
), "",
11289 COMPUNIT_DIRNAME (cust
),
11290 compunit_language (cust
),
11292 list_in_scope
= get_builder ()->get_file_symbols ();
11294 auto &file_names
= line_header
->file_names ();
11295 for (i
= 0; i
< file_names
.size (); ++i
)
11297 file_entry
&fe
= file_names
[i
];
11298 fe
.symtab
= tug_unshare
->symtabs
[i
];
11302 /* The main symtab is allocated last. Type units don't have DW_AT_name
11303 so they don't have a "real" (so to speak) symtab anyway.
11304 There is later code that will assign the main symtab to all symbols
11305 that don't have one. We need to handle the case of a symbol with a
11306 missing symtab (DW_AT_decl_file) anyway. */
11309 /* Process DW_TAG_type_unit.
11310 For TUs we want to skip the first top level sibling if it's not the
11311 actual type being defined by this TU. In this case the first top
11312 level sibling is there to provide context only. */
11315 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11317 struct die_info
*child_die
;
11319 prepare_one_comp_unit (cu
, die
, language_minimal
);
11321 /* Initialize (or reinitialize) the machinery for building symtabs.
11322 We do this before processing child DIEs, so that the line header table
11323 is available for DW_AT_decl_file. */
11324 cu
->setup_type_unit_groups (die
);
11326 if (die
->child
!= NULL
)
11328 child_die
= die
->child
;
11329 while (child_die
&& child_die
->tag
)
11331 process_die (child_die
, cu
);
11332 child_die
= child_die
->sibling
;
11339 http://gcc.gnu.org/wiki/DebugFission
11340 http://gcc.gnu.org/wiki/DebugFissionDWP
11342 To simplify handling of both DWO files ("object" files with the DWARF info)
11343 and DWP files (a file with the DWOs packaged up into one file), we treat
11344 DWP files as having a collection of virtual DWO files. */
11347 hash_dwo_file (const void *item
)
11349 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11352 hash
= htab_hash_string (dwo_file
->dwo_name
);
11353 if (dwo_file
->comp_dir
!= NULL
)
11354 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11359 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11361 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11362 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11364 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11366 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11367 return lhs
->comp_dir
== rhs
->comp_dir
;
11368 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11371 /* Allocate a hash table for DWO files. */
11374 allocate_dwo_file_hash_table ()
11376 auto delete_dwo_file
= [] (void *item
)
11378 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11383 return htab_up (htab_create_alloc (41,
11390 /* Lookup DWO file DWO_NAME. */
11393 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11394 const char *dwo_name
,
11395 const char *comp_dir
)
11397 struct dwo_file find_entry
;
11400 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11401 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11403 find_entry
.dwo_name
= dwo_name
;
11404 find_entry
.comp_dir
= comp_dir
;
11405 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11412 hash_dwo_unit (const void *item
)
11414 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11416 /* This drops the top 32 bits of the id, but is ok for a hash. */
11417 return dwo_unit
->signature
;
11421 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11423 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11424 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11426 /* The signature is assumed to be unique within the DWO file.
11427 So while object file CU dwo_id's always have the value zero,
11428 that's OK, assuming each object file DWO file has only one CU,
11429 and that's the rule for now. */
11430 return lhs
->signature
== rhs
->signature
;
11433 /* Allocate a hash table for DWO CUs,TUs.
11434 There is one of these tables for each of CUs,TUs for each DWO file. */
11437 allocate_dwo_unit_table ()
11439 /* Start out with a pretty small number.
11440 Generally DWO files contain only one CU and maybe some TUs. */
11441 return htab_up (htab_create_alloc (3,
11444 NULL
, xcalloc
, xfree
));
11447 /* die_reader_func for create_dwo_cu. */
11450 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11451 const gdb_byte
*info_ptr
,
11452 struct die_info
*comp_unit_die
,
11453 struct dwo_file
*dwo_file
,
11454 struct dwo_unit
*dwo_unit
)
11456 struct dwarf2_cu
*cu
= reader
->cu
;
11457 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11458 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11460 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11461 if (!signature
.has_value ())
11463 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11464 " its dwo_id [in module %s]"),
11465 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11469 dwo_unit
->dwo_file
= dwo_file
;
11470 dwo_unit
->signature
= *signature
;
11471 dwo_unit
->section
= section
;
11472 dwo_unit
->sect_off
= sect_off
;
11473 dwo_unit
->length
= cu
->per_cu
->length
;
11475 dwarf_read_debug_printf (" offset %s, dwo_id %s",
11476 sect_offset_str (sect_off
),
11477 hex_string (dwo_unit
->signature
));
11480 /* Create the dwo_units for the CUs in a DWO_FILE.
11481 Note: This function processes DWO files only, not DWP files. */
11484 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11485 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11486 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11488 struct objfile
*objfile
= per_objfile
->objfile
;
11489 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11490 const gdb_byte
*info_ptr
, *end_ptr
;
11492 section
.read (objfile
);
11493 info_ptr
= section
.buffer
;
11495 if (info_ptr
== NULL
)
11498 dwarf_read_debug_printf ("Reading %s for %s:",
11499 section
.get_name (),
11500 section
.get_file_name ());
11502 end_ptr
= info_ptr
+ section
.size
;
11503 while (info_ptr
< end_ptr
)
11505 struct dwarf2_per_cu_data per_cu
;
11506 struct dwo_unit read_unit
{};
11507 struct dwo_unit
*dwo_unit
;
11509 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11511 memset (&per_cu
, 0, sizeof (per_cu
));
11512 per_cu
.per_bfd
= per_bfd
;
11513 per_cu
.is_debug_types
= 0;
11514 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11515 per_cu
.section
= §ion
;
11517 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11518 if (!reader
.dummy_p
)
11519 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11520 &dwo_file
, &read_unit
);
11521 info_ptr
+= per_cu
.length
;
11523 // If the unit could not be parsed, skip it.
11524 if (read_unit
.dwo_file
== NULL
)
11527 if (cus_htab
== NULL
)
11528 cus_htab
= allocate_dwo_unit_table ();
11530 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11532 *dwo_unit
= read_unit
;
11533 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11534 gdb_assert (slot
!= NULL
);
11537 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11538 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11540 complaint (_("debug cu entry at offset %s is duplicate to"
11541 " the entry at offset %s, signature %s"),
11542 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11543 hex_string (dwo_unit
->signature
));
11545 *slot
= (void *)dwo_unit
;
11549 /* DWP file .debug_{cu,tu}_index section format:
11550 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11551 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11553 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11554 officially standard DWP format was published with DWARF v5 and is called
11555 Version 5. There are no versions 3 or 4.
11559 Both index sections have the same format, and serve to map a 64-bit
11560 signature to a set of section numbers. Each section begins with a header,
11561 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11562 indexes, and a pool of 32-bit section numbers. The index sections will be
11563 aligned at 8-byte boundaries in the file.
11565 The index section header consists of:
11567 V, 32 bit version number
11569 N, 32 bit number of compilation units or type units in the index
11570 M, 32 bit number of slots in the hash table
11572 Numbers are recorded using the byte order of the application binary.
11574 The hash table begins at offset 16 in the section, and consists of an array
11575 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11576 order of the application binary). Unused slots in the hash table are 0.
11577 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11579 The parallel table begins immediately after the hash table
11580 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11581 array of 32-bit indexes (using the byte order of the application binary),
11582 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11583 table contains a 32-bit index into the pool of section numbers. For unused
11584 hash table slots, the corresponding entry in the parallel table will be 0.
11586 The pool of section numbers begins immediately following the hash table
11587 (at offset 16 + 12 * M from the beginning of the section). The pool of
11588 section numbers consists of an array of 32-bit words (using the byte order
11589 of the application binary). Each item in the array is indexed starting
11590 from 0. The hash table entry provides the index of the first section
11591 number in the set. Additional section numbers in the set follow, and the
11592 set is terminated by a 0 entry (section number 0 is not used in ELF).
11594 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11595 section must be the first entry in the set, and the .debug_abbrev.dwo must
11596 be the second entry. Other members of the set may follow in any order.
11600 DWP Versions 2 and 5:
11602 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11603 and the entries in the index tables are now offsets into these sections.
11604 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11607 Index Section Contents:
11609 Hash Table of Signatures dwp_hash_table.hash_table
11610 Parallel Table of Indices dwp_hash_table.unit_table
11611 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11612 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11614 The index section header consists of:
11616 V, 32 bit version number
11617 L, 32 bit number of columns in the table of section offsets
11618 N, 32 bit number of compilation units or type units in the index
11619 M, 32 bit number of slots in the hash table
11621 Numbers are recorded using the byte order of the application binary.
11623 The hash table has the same format as version 1.
11624 The parallel table of indices has the same format as version 1,
11625 except that the entries are origin-1 indices into the table of sections
11626 offsets and the table of section sizes.
11628 The table of offsets begins immediately following the parallel table
11629 (at offset 16 + 12 * M from the beginning of the section). The table is
11630 a two-dimensional array of 32-bit words (using the byte order of the
11631 application binary), with L columns and N+1 rows, in row-major order.
11632 Each row in the array is indexed starting from 0. The first row provides
11633 a key to the remaining rows: each column in this row provides an identifier
11634 for a debug section, and the offsets in the same column of subsequent rows
11635 refer to that section. The section identifiers for Version 2 are:
11637 DW_SECT_INFO 1 .debug_info.dwo
11638 DW_SECT_TYPES 2 .debug_types.dwo
11639 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11640 DW_SECT_LINE 4 .debug_line.dwo
11641 DW_SECT_LOC 5 .debug_loc.dwo
11642 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11643 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11644 DW_SECT_MACRO 8 .debug_macro.dwo
11646 The section identifiers for Version 5 are:
11648 DW_SECT_INFO_V5 1 .debug_info.dwo
11649 DW_SECT_RESERVED_V5 2 --
11650 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11651 DW_SECT_LINE_V5 4 .debug_line.dwo
11652 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11653 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11654 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11655 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11657 The offsets provided by the CU and TU index sections are the base offsets
11658 for the contributions made by each CU or TU to the corresponding section
11659 in the package file. Each CU and TU header contains an abbrev_offset
11660 field, used to find the abbreviations table for that CU or TU within the
11661 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11662 be interpreted as relative to the base offset given in the index section.
11663 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11664 should be interpreted as relative to the base offset for .debug_line.dwo,
11665 and offsets into other debug sections obtained from DWARF attributes should
11666 also be interpreted as relative to the corresponding base offset.
11668 The table of sizes begins immediately following the table of offsets.
11669 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11670 with L columns and N rows, in row-major order. Each row in the array is
11671 indexed starting from 1 (row 0 is shared by the two tables).
11675 Hash table lookup is handled the same in version 1 and 2:
11677 We assume that N and M will not exceed 2^32 - 1.
11678 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11680 Given a 64-bit compilation unit signature or a type signature S, an entry
11681 in the hash table is located as follows:
11683 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11684 the low-order k bits all set to 1.
11686 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11688 3) If the hash table entry at index H matches the signature, use that
11689 entry. If the hash table entry at index H is unused (all zeroes),
11690 terminate the search: the signature is not present in the table.
11692 4) Let H = (H + H') modulo M. Repeat at Step 3.
11694 Because M > N and H' and M are relatively prime, the search is guaranteed
11695 to stop at an unused slot or find the match. */
11697 /* Create a hash table to map DWO IDs to their CU/TU entry in
11698 .debug_{info,types}.dwo in DWP_FILE.
11699 Returns NULL if there isn't one.
11700 Note: This function processes DWP files only, not DWO files. */
11702 static struct dwp_hash_table
*
11703 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11704 struct dwp_file
*dwp_file
, int is_debug_types
)
11706 struct objfile
*objfile
= per_objfile
->objfile
;
11707 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11708 const gdb_byte
*index_ptr
, *index_end
;
11709 struct dwarf2_section_info
*index
;
11710 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11711 struct dwp_hash_table
*htab
;
11713 if (is_debug_types
)
11714 index
= &dwp_file
->sections
.tu_index
;
11716 index
= &dwp_file
->sections
.cu_index
;
11718 if (index
->empty ())
11720 index
->read (objfile
);
11722 index_ptr
= index
->buffer
;
11723 index_end
= index_ptr
+ index
->size
;
11725 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11726 For now it's safe to just read 4 bytes (particularly as it's difficult to
11727 tell if you're dealing with Version 5 before you've read the version). */
11728 version
= read_4_bytes (dbfd
, index_ptr
);
11730 if (version
== 2 || version
== 5)
11731 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11735 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11737 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11740 if (version
!= 1 && version
!= 2 && version
!= 5)
11742 error (_("Dwarf Error: unsupported DWP file version (%s)"
11743 " [in module %s]"),
11744 pulongest (version
), dwp_file
->name
);
11746 if (nr_slots
!= (nr_slots
& -nr_slots
))
11748 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11749 " is not power of 2 [in module %s]"),
11750 pulongest (nr_slots
), dwp_file
->name
);
11753 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11754 htab
->version
= version
;
11755 htab
->nr_columns
= nr_columns
;
11756 htab
->nr_units
= nr_units
;
11757 htab
->nr_slots
= nr_slots
;
11758 htab
->hash_table
= index_ptr
;
11759 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11761 /* Exit early if the table is empty. */
11762 if (nr_slots
== 0 || nr_units
== 0
11763 || (version
== 2 && nr_columns
== 0)
11764 || (version
== 5 && nr_columns
== 0))
11766 /* All must be zero. */
11767 if (nr_slots
!= 0 || nr_units
!= 0
11768 || (version
== 2 && nr_columns
!= 0)
11769 || (version
== 5 && nr_columns
!= 0))
11771 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11772 " all zero [in modules %s]"),
11780 htab
->section_pool
.v1
.indices
=
11781 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11782 /* It's harder to decide whether the section is too small in v1.
11783 V1 is deprecated anyway so we punt. */
11785 else if (version
== 2)
11787 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11788 int *ids
= htab
->section_pool
.v2
.section_ids
;
11789 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11790 /* Reverse map for error checking. */
11791 int ids_seen
[DW_SECT_MAX
+ 1];
11794 if (nr_columns
< 2)
11796 error (_("Dwarf Error: bad DWP hash table, too few columns"
11797 " in section table [in module %s]"),
11800 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11802 error (_("Dwarf Error: bad DWP hash table, too many columns"
11803 " in section table [in module %s]"),
11806 memset (ids
, 255, sizeof_ids
);
11807 memset (ids_seen
, 255, sizeof (ids_seen
));
11808 for (i
= 0; i
< nr_columns
; ++i
)
11810 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11812 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11814 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11815 " in section table [in module %s]"),
11816 id
, dwp_file
->name
);
11818 if (ids_seen
[id
] != -1)
11820 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11821 " id %d in section table [in module %s]"),
11822 id
, dwp_file
->name
);
11827 /* Must have exactly one info or types section. */
11828 if (((ids_seen
[DW_SECT_INFO
] != -1)
11829 + (ids_seen
[DW_SECT_TYPES
] != -1))
11832 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11833 " DWO info/types section [in module %s]"),
11836 /* Must have an abbrev section. */
11837 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11839 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11840 " section [in module %s]"),
11843 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11844 htab
->section_pool
.v2
.sizes
=
11845 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11846 * nr_units
* nr_columns
);
11847 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11848 * nr_units
* nr_columns
))
11851 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11852 " [in module %s]"),
11856 else /* version == 5 */
11858 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11859 int *ids
= htab
->section_pool
.v5
.section_ids
;
11860 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11861 /* Reverse map for error checking. */
11862 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11864 if (nr_columns
< 2)
11866 error (_("Dwarf Error: bad DWP hash table, too few columns"
11867 " in section table [in module %s]"),
11870 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11872 error (_("Dwarf Error: bad DWP hash table, too many columns"
11873 " in section table [in module %s]"),
11876 memset (ids
, 255, sizeof_ids
);
11877 memset (ids_seen
, 255, sizeof (ids_seen
));
11878 for (int i
= 0; i
< nr_columns
; ++i
)
11880 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11882 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11884 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11885 " in section table [in module %s]"),
11886 id
, dwp_file
->name
);
11888 if (ids_seen
[id
] != -1)
11890 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11891 " id %d in section table [in module %s]"),
11892 id
, dwp_file
->name
);
11897 /* Must have seen an info section. */
11898 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11900 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11901 " DWO info/types section [in module %s]"),
11904 /* Must have an abbrev section. */
11905 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11907 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11908 " section [in module %s]"),
11911 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11912 htab
->section_pool
.v5
.sizes
11913 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11914 * nr_units
* nr_columns
);
11915 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11916 * nr_units
* nr_columns
))
11919 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11920 " [in module %s]"),
11928 /* Update SECTIONS with the data from SECTP.
11930 This function is like the other "locate" section routines, but in
11931 this context the sections to read comes from the DWP V1 hash table,
11932 not the full ELF section table.
11934 The result is non-zero for success, or zero if an error was found. */
11937 locate_v1_virtual_dwo_sections (asection
*sectp
,
11938 struct virtual_v1_dwo_sections
*sections
)
11940 const struct dwop_section_names
*names
= &dwop_section_names
;
11942 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11944 /* There can be only one. */
11945 if (sections
->abbrev
.s
.section
!= NULL
)
11947 sections
->abbrev
.s
.section
= sectp
;
11948 sections
->abbrev
.size
= bfd_section_size (sectp
);
11950 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11951 || section_is_p (sectp
->name
, &names
->types_dwo
))
11953 /* There can be only one. */
11954 if (sections
->info_or_types
.s
.section
!= NULL
)
11956 sections
->info_or_types
.s
.section
= sectp
;
11957 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11959 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11961 /* There can be only one. */
11962 if (sections
->line
.s
.section
!= NULL
)
11964 sections
->line
.s
.section
= sectp
;
11965 sections
->line
.size
= bfd_section_size (sectp
);
11967 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11969 /* There can be only one. */
11970 if (sections
->loc
.s
.section
!= NULL
)
11972 sections
->loc
.s
.section
= sectp
;
11973 sections
->loc
.size
= bfd_section_size (sectp
);
11975 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11977 /* There can be only one. */
11978 if (sections
->macinfo
.s
.section
!= NULL
)
11980 sections
->macinfo
.s
.section
= sectp
;
11981 sections
->macinfo
.size
= bfd_section_size (sectp
);
11983 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11985 /* There can be only one. */
11986 if (sections
->macro
.s
.section
!= NULL
)
11988 sections
->macro
.s
.section
= sectp
;
11989 sections
->macro
.size
= bfd_section_size (sectp
);
11991 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11993 /* There can be only one. */
11994 if (sections
->str_offsets
.s
.section
!= NULL
)
11996 sections
->str_offsets
.s
.section
= sectp
;
11997 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12001 /* No other kind of section is valid. */
12008 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12009 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12010 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12011 This is for DWP version 1 files. */
12013 static struct dwo_unit
*
12014 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
12015 struct dwp_file
*dwp_file
,
12016 uint32_t unit_index
,
12017 const char *comp_dir
,
12018 ULONGEST signature
, int is_debug_types
)
12020 const struct dwp_hash_table
*dwp_htab
=
12021 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12022 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12023 const char *kind
= is_debug_types
? "TU" : "CU";
12024 struct dwo_file
*dwo_file
;
12025 struct dwo_unit
*dwo_unit
;
12026 struct virtual_v1_dwo_sections sections
;
12027 void **dwo_file_slot
;
12030 gdb_assert (dwp_file
->version
== 1);
12032 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
12033 kind
, pulongest (unit_index
), hex_string (signature
),
12036 /* Fetch the sections of this DWO unit.
12037 Put a limit on the number of sections we look for so that bad data
12038 doesn't cause us to loop forever. */
12040 #define MAX_NR_V1_DWO_SECTIONS \
12041 (1 /* .debug_info or .debug_types */ \
12042 + 1 /* .debug_abbrev */ \
12043 + 1 /* .debug_line */ \
12044 + 1 /* .debug_loc */ \
12045 + 1 /* .debug_str_offsets */ \
12046 + 1 /* .debug_macro or .debug_macinfo */ \
12047 + 1 /* trailing zero */)
12049 memset (§ions
, 0, sizeof (sections
));
12051 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12054 uint32_t section_nr
=
12055 read_4_bytes (dbfd
,
12056 dwp_htab
->section_pool
.v1
.indices
12057 + (unit_index
+ i
) * sizeof (uint32_t));
12059 if (section_nr
== 0)
12061 if (section_nr
>= dwp_file
->num_sections
)
12063 error (_("Dwarf Error: bad DWP hash table, section number too large"
12064 " [in module %s]"),
12068 sectp
= dwp_file
->elf_sections
[section_nr
];
12069 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12071 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12072 " [in module %s]"),
12078 || sections
.info_or_types
.empty ()
12079 || sections
.abbrev
.empty ())
12081 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12082 " [in module %s]"),
12085 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12087 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12088 " [in module %s]"),
12092 /* It's easier for the rest of the code if we fake a struct dwo_file and
12093 have dwo_unit "live" in that. At least for now.
12095 The DWP file can be made up of a random collection of CUs and TUs.
12096 However, for each CU + set of TUs that came from the same original DWO
12097 file, we can combine them back into a virtual DWO file to save space
12098 (fewer struct dwo_file objects to allocate). Remember that for really
12099 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12101 std::string virtual_dwo_name
=
12102 string_printf ("virtual-dwo/%d-%d-%d-%d",
12103 sections
.abbrev
.get_id (),
12104 sections
.line
.get_id (),
12105 sections
.loc
.get_id (),
12106 sections
.str_offsets
.get_id ());
12107 /* Can we use an existing virtual DWO file? */
12108 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12110 /* Create one if necessary. */
12111 if (*dwo_file_slot
== NULL
)
12113 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12114 virtual_dwo_name
.c_str ());
12116 dwo_file
= new struct dwo_file
;
12117 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12118 dwo_file
->comp_dir
= comp_dir
;
12119 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12120 dwo_file
->sections
.line
= sections
.line
;
12121 dwo_file
->sections
.loc
= sections
.loc
;
12122 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12123 dwo_file
->sections
.macro
= sections
.macro
;
12124 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12125 /* The "str" section is global to the entire DWP file. */
12126 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12127 /* The info or types section is assigned below to dwo_unit,
12128 there's no need to record it in dwo_file.
12129 Also, we can't simply record type sections in dwo_file because
12130 we record a pointer into the vector in dwo_unit. As we collect more
12131 types we'll grow the vector and eventually have to reallocate space
12132 for it, invalidating all copies of pointers into the previous
12134 *dwo_file_slot
= dwo_file
;
12138 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12139 virtual_dwo_name
.c_str ());
12141 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12144 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12145 dwo_unit
->dwo_file
= dwo_file
;
12146 dwo_unit
->signature
= signature
;
12147 dwo_unit
->section
=
12148 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12149 *dwo_unit
->section
= sections
.info_or_types
;
12150 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12155 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
12156 simplify them. Given a pointer to the containing section SECTION, and
12157 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
12158 virtual section of just that piece. */
12160 static struct dwarf2_section_info
12161 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
12162 struct dwarf2_section_info
*section
,
12163 bfd_size_type offset
, bfd_size_type size
)
12165 struct dwarf2_section_info result
;
12168 gdb_assert (section
!= NULL
);
12169 gdb_assert (!section
->is_virtual
);
12171 memset (&result
, 0, sizeof (result
));
12172 result
.s
.containing_section
= section
;
12173 result
.is_virtual
= true;
12178 sectp
= section
->get_bfd_section ();
12180 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12181 bounds of the real section. This is a pretty-rare event, so just
12182 flag an error (easier) instead of a warning and trying to cope. */
12184 || offset
+ size
> bfd_section_size (sectp
))
12186 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
12187 " in section %s [in module %s]"),
12188 sectp
? bfd_section_name (sectp
) : "<unknown>",
12189 objfile_name (per_objfile
->objfile
));
12192 result
.virtual_offset
= offset
;
12193 result
.size
= size
;
12197 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12198 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12199 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12200 This is for DWP version 2 files. */
12202 static struct dwo_unit
*
12203 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
12204 struct dwp_file
*dwp_file
,
12205 uint32_t unit_index
,
12206 const char *comp_dir
,
12207 ULONGEST signature
, int is_debug_types
)
12209 const struct dwp_hash_table
*dwp_htab
=
12210 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12211 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12212 const char *kind
= is_debug_types
? "TU" : "CU";
12213 struct dwo_file
*dwo_file
;
12214 struct dwo_unit
*dwo_unit
;
12215 struct virtual_v2_or_v5_dwo_sections sections
;
12216 void **dwo_file_slot
;
12219 gdb_assert (dwp_file
->version
== 2);
12221 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
12222 kind
, pulongest (unit_index
), hex_string (signature
),
12225 /* Fetch the section offsets of this DWO unit. */
12227 memset (§ions
, 0, sizeof (sections
));
12229 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12231 uint32_t offset
= read_4_bytes (dbfd
,
12232 dwp_htab
->section_pool
.v2
.offsets
12233 + (((unit_index
- 1) * dwp_htab
->nr_columns
12235 * sizeof (uint32_t)));
12236 uint32_t size
= read_4_bytes (dbfd
,
12237 dwp_htab
->section_pool
.v2
.sizes
12238 + (((unit_index
- 1) * dwp_htab
->nr_columns
12240 * sizeof (uint32_t)));
12242 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12245 case DW_SECT_TYPES
:
12246 sections
.info_or_types_offset
= offset
;
12247 sections
.info_or_types_size
= size
;
12249 case DW_SECT_ABBREV
:
12250 sections
.abbrev_offset
= offset
;
12251 sections
.abbrev_size
= size
;
12254 sections
.line_offset
= offset
;
12255 sections
.line_size
= size
;
12258 sections
.loc_offset
= offset
;
12259 sections
.loc_size
= size
;
12261 case DW_SECT_STR_OFFSETS
:
12262 sections
.str_offsets_offset
= offset
;
12263 sections
.str_offsets_size
= size
;
12265 case DW_SECT_MACINFO
:
12266 sections
.macinfo_offset
= offset
;
12267 sections
.macinfo_size
= size
;
12269 case DW_SECT_MACRO
:
12270 sections
.macro_offset
= offset
;
12271 sections
.macro_size
= size
;
12276 /* It's easier for the rest of the code if we fake a struct dwo_file and
12277 have dwo_unit "live" in that. At least for now.
12279 The DWP file can be made up of a random collection of CUs and TUs.
12280 However, for each CU + set of TUs that came from the same original DWO
12281 file, we can combine them back into a virtual DWO file to save space
12282 (fewer struct dwo_file objects to allocate). Remember that for really
12283 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12285 std::string virtual_dwo_name
=
12286 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12287 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12288 (long) (sections
.line_size
? sections
.line_offset
: 0),
12289 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12290 (long) (sections
.str_offsets_size
12291 ? sections
.str_offsets_offset
: 0));
12292 /* Can we use an existing virtual DWO file? */
12293 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12295 /* Create one if necessary. */
12296 if (*dwo_file_slot
== NULL
)
12298 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12299 virtual_dwo_name
.c_str ());
12301 dwo_file
= new struct dwo_file
;
12302 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12303 dwo_file
->comp_dir
= comp_dir
;
12304 dwo_file
->sections
.abbrev
=
12305 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12306 sections
.abbrev_offset
,
12307 sections
.abbrev_size
);
12308 dwo_file
->sections
.line
=
12309 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
12310 sections
.line_offset
,
12311 sections
.line_size
);
12312 dwo_file
->sections
.loc
=
12313 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
12314 sections
.loc_offset
, sections
.loc_size
);
12315 dwo_file
->sections
.macinfo
=
12316 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12317 sections
.macinfo_offset
,
12318 sections
.macinfo_size
);
12319 dwo_file
->sections
.macro
=
12320 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
12321 sections
.macro_offset
,
12322 sections
.macro_size
);
12323 dwo_file
->sections
.str_offsets
=
12324 create_dwp_v2_or_v5_section (per_objfile
,
12325 &dwp_file
->sections
.str_offsets
,
12326 sections
.str_offsets_offset
,
12327 sections
.str_offsets_size
);
12328 /* The "str" section is global to the entire DWP file. */
12329 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12330 /* The info or types section is assigned below to dwo_unit,
12331 there's no need to record it in dwo_file.
12332 Also, we can't simply record type sections in dwo_file because
12333 we record a pointer into the vector in dwo_unit. As we collect more
12334 types we'll grow the vector and eventually have to reallocate space
12335 for it, invalidating all copies of pointers into the previous
12337 *dwo_file_slot
= dwo_file
;
12341 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12342 virtual_dwo_name
.c_str ());
12344 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12347 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12348 dwo_unit
->dwo_file
= dwo_file
;
12349 dwo_unit
->signature
= signature
;
12350 dwo_unit
->section
=
12351 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12352 *dwo_unit
->section
= create_dwp_v2_or_v5_section
12355 ? &dwp_file
->sections
.types
12356 : &dwp_file
->sections
.info
,
12357 sections
.info_or_types_offset
,
12358 sections
.info_or_types_size
);
12359 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12364 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12365 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12366 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12367 This is for DWP version 5 files. */
12369 static struct dwo_unit
*
12370 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
12371 struct dwp_file
*dwp_file
,
12372 uint32_t unit_index
,
12373 const char *comp_dir
,
12374 ULONGEST signature
, int is_debug_types
)
12376 const struct dwp_hash_table
*dwp_htab
12377 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12378 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12379 const char *kind
= is_debug_types
? "TU" : "CU";
12380 struct dwo_file
*dwo_file
;
12381 struct dwo_unit
*dwo_unit
;
12382 struct virtual_v2_or_v5_dwo_sections sections
{};
12383 void **dwo_file_slot
;
12385 gdb_assert (dwp_file
->version
== 5);
12387 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
12388 kind
, pulongest (unit_index
), hex_string (signature
),
12391 /* Fetch the section offsets of this DWO unit. */
12393 /* memset (§ions, 0, sizeof (sections)); */
12395 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12397 uint32_t offset
= read_4_bytes (dbfd
,
12398 dwp_htab
->section_pool
.v5
.offsets
12399 + (((unit_index
- 1)
12400 * dwp_htab
->nr_columns
12402 * sizeof (uint32_t)));
12403 uint32_t size
= read_4_bytes (dbfd
,
12404 dwp_htab
->section_pool
.v5
.sizes
12405 + (((unit_index
- 1) * dwp_htab
->nr_columns
12407 * sizeof (uint32_t)));
12409 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
12411 case DW_SECT_ABBREV_V5
:
12412 sections
.abbrev_offset
= offset
;
12413 sections
.abbrev_size
= size
;
12415 case DW_SECT_INFO_V5
:
12416 sections
.info_or_types_offset
= offset
;
12417 sections
.info_or_types_size
= size
;
12419 case DW_SECT_LINE_V5
:
12420 sections
.line_offset
= offset
;
12421 sections
.line_size
= size
;
12423 case DW_SECT_LOCLISTS_V5
:
12424 sections
.loclists_offset
= offset
;
12425 sections
.loclists_size
= size
;
12427 case DW_SECT_MACRO_V5
:
12428 sections
.macro_offset
= offset
;
12429 sections
.macro_size
= size
;
12431 case DW_SECT_RNGLISTS_V5
:
12432 sections
.rnglists_offset
= offset
;
12433 sections
.rnglists_size
= size
;
12435 case DW_SECT_STR_OFFSETS_V5
:
12436 sections
.str_offsets_offset
= offset
;
12437 sections
.str_offsets_size
= size
;
12439 case DW_SECT_RESERVED_V5
:
12445 /* It's easier for the rest of the code if we fake a struct dwo_file and
12446 have dwo_unit "live" in that. At least for now.
12448 The DWP file can be made up of a random collection of CUs and TUs.
12449 However, for each CU + set of TUs that came from the same original DWO
12450 file, we can combine them back into a virtual DWO file to save space
12451 (fewer struct dwo_file objects to allocate). Remember that for really
12452 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12454 std::string virtual_dwo_name
=
12455 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
12456 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12457 (long) (sections
.line_size
? sections
.line_offset
: 0),
12458 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
12459 (long) (sections
.str_offsets_size
12460 ? sections
.str_offsets_offset
: 0),
12461 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
12462 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
12463 /* Can we use an existing virtual DWO file? */
12464 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
12465 virtual_dwo_name
.c_str (),
12467 /* Create one if necessary. */
12468 if (*dwo_file_slot
== NULL
)
12470 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12471 virtual_dwo_name
.c_str ());
12473 dwo_file
= new struct dwo_file
;
12474 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12475 dwo_file
->comp_dir
= comp_dir
;
12476 dwo_file
->sections
.abbrev
=
12477 create_dwp_v2_or_v5_section (per_objfile
,
12478 &dwp_file
->sections
.abbrev
,
12479 sections
.abbrev_offset
,
12480 sections
.abbrev_size
);
12481 dwo_file
->sections
.line
=
12482 create_dwp_v2_or_v5_section (per_objfile
,
12483 &dwp_file
->sections
.line
,
12484 sections
.line_offset
, sections
.line_size
);
12485 dwo_file
->sections
.macro
=
12486 create_dwp_v2_or_v5_section (per_objfile
,
12487 &dwp_file
->sections
.macro
,
12488 sections
.macro_offset
,
12489 sections
.macro_size
);
12490 dwo_file
->sections
.loclists
=
12491 create_dwp_v2_or_v5_section (per_objfile
,
12492 &dwp_file
->sections
.loclists
,
12493 sections
.loclists_offset
,
12494 sections
.loclists_size
);
12495 dwo_file
->sections
.rnglists
=
12496 create_dwp_v2_or_v5_section (per_objfile
,
12497 &dwp_file
->sections
.rnglists
,
12498 sections
.rnglists_offset
,
12499 sections
.rnglists_size
);
12500 dwo_file
->sections
.str_offsets
=
12501 create_dwp_v2_or_v5_section (per_objfile
,
12502 &dwp_file
->sections
.str_offsets
,
12503 sections
.str_offsets_offset
,
12504 sections
.str_offsets_size
);
12505 /* The "str" section is global to the entire DWP file. */
12506 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12507 /* The info or types section is assigned below to dwo_unit,
12508 there's no need to record it in dwo_file.
12509 Also, we can't simply record type sections in dwo_file because
12510 we record a pointer into the vector in dwo_unit. As we collect more
12511 types we'll grow the vector and eventually have to reallocate space
12512 for it, invalidating all copies of pointers into the previous
12514 *dwo_file_slot
= dwo_file
;
12518 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12519 virtual_dwo_name
.c_str ());
12521 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12524 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12525 dwo_unit
->dwo_file
= dwo_file
;
12526 dwo_unit
->signature
= signature
;
12528 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12529 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12530 &dwp_file
->sections
.info
,
12531 sections
.info_or_types_offset
,
12532 sections
.info_or_types_size
);
12533 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12538 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12539 Returns NULL if the signature isn't found. */
12541 static struct dwo_unit
*
12542 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12543 struct dwp_file
*dwp_file
, const char *comp_dir
,
12544 ULONGEST signature
, int is_debug_types
)
12546 const struct dwp_hash_table
*dwp_htab
=
12547 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12548 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12549 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12550 uint32_t hash
= signature
& mask
;
12551 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12554 struct dwo_unit find_dwo_cu
;
12556 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12557 find_dwo_cu
.signature
= signature
;
12558 slot
= htab_find_slot (is_debug_types
12559 ? dwp_file
->loaded_tus
.get ()
12560 : dwp_file
->loaded_cus
.get (),
12561 &find_dwo_cu
, INSERT
);
12564 return (struct dwo_unit
*) *slot
;
12566 /* Use a for loop so that we don't loop forever on bad debug info. */
12567 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12569 ULONGEST signature_in_table
;
12571 signature_in_table
=
12572 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12573 if (signature_in_table
== signature
)
12575 uint32_t unit_index
=
12576 read_4_bytes (dbfd
,
12577 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12579 if (dwp_file
->version
== 1)
12581 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12582 unit_index
, comp_dir
,
12583 signature
, is_debug_types
);
12585 else if (dwp_file
->version
== 2)
12587 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12588 unit_index
, comp_dir
,
12589 signature
, is_debug_types
);
12591 else /* version == 5 */
12593 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12594 unit_index
, comp_dir
,
12595 signature
, is_debug_types
);
12597 return (struct dwo_unit
*) *slot
;
12599 if (signature_in_table
== 0)
12601 hash
= (hash
+ hash2
) & mask
;
12604 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12605 " [in module %s]"),
12609 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12610 Open the file specified by FILE_NAME and hand it off to BFD for
12611 preliminary analysis. Return a newly initialized bfd *, which
12612 includes a canonicalized copy of FILE_NAME.
12613 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12614 SEARCH_CWD is true if the current directory is to be searched.
12615 It will be searched before debug-file-directory.
12616 If successful, the file is added to the bfd include table of the
12617 objfile's bfd (see gdb_bfd_record_inclusion).
12618 If unable to find/open the file, return NULL.
12619 NOTE: This function is derived from symfile_bfd_open. */
12621 static gdb_bfd_ref_ptr
12622 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12623 const char *file_name
, int is_dwp
, int search_cwd
)
12626 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12627 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12628 to debug_file_directory. */
12629 const char *search_path
;
12630 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12632 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12635 if (*debug_file_directory
!= '\0')
12637 search_path_holder
.reset (concat (".", dirname_separator_string
,
12638 debug_file_directory
,
12640 search_path
= search_path_holder
.get ();
12646 search_path
= debug_file_directory
;
12648 openp_flags flags
= OPF_RETURN_REALPATH
;
12650 flags
|= OPF_SEARCH_IN_PATH
;
12652 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12653 desc
= openp (search_path
, flags
, file_name
,
12654 O_RDONLY
| O_BINARY
, &absolute_name
);
12658 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12660 if (sym_bfd
== NULL
)
12662 bfd_set_cacheable (sym_bfd
.get (), 1);
12664 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12667 /* Success. Record the bfd as having been included by the objfile's bfd.
12668 This is important because things like demangled_names_hash lives in the
12669 objfile's per_bfd space and may have references to things like symbol
12670 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12671 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12676 /* Try to open DWO file FILE_NAME.
12677 COMP_DIR is the DW_AT_comp_dir attribute.
12678 The result is the bfd handle of the file.
12679 If there is a problem finding or opening the file, return NULL.
12680 Upon success, the canonicalized path of the file is stored in the bfd,
12681 same as symfile_bfd_open. */
12683 static gdb_bfd_ref_ptr
12684 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12685 const char *file_name
, const char *comp_dir
)
12687 if (IS_ABSOLUTE_PATH (file_name
))
12688 return try_open_dwop_file (per_objfile
, file_name
,
12689 0 /*is_dwp*/, 0 /*search_cwd*/);
12691 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12693 if (comp_dir
!= NULL
)
12695 gdb::unique_xmalloc_ptr
<char> path_to_try
12696 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12698 /* NOTE: If comp_dir is a relative path, this will also try the
12699 search path, which seems useful. */
12700 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12702 1 /*search_cwd*/));
12707 /* That didn't work, try debug-file-directory, which, despite its name,
12708 is a list of paths. */
12710 if (*debug_file_directory
== '\0')
12713 return try_open_dwop_file (per_objfile
, file_name
,
12714 0 /*is_dwp*/, 1 /*search_cwd*/);
12717 /* This function is mapped across the sections and remembers the offset and
12718 size of each of the DWO debugging sections we are interested in. */
12721 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12722 dwo_sections
*dwo_sections
)
12724 const struct dwop_section_names
*names
= &dwop_section_names
;
12726 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12728 dwo_sections
->abbrev
.s
.section
= sectp
;
12729 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12731 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12733 dwo_sections
->info
.s
.section
= sectp
;
12734 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12736 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12738 dwo_sections
->line
.s
.section
= sectp
;
12739 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12741 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12743 dwo_sections
->loc
.s
.section
= sectp
;
12744 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12746 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12748 dwo_sections
->loclists
.s
.section
= sectp
;
12749 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12751 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12753 dwo_sections
->macinfo
.s
.section
= sectp
;
12754 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12756 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12758 dwo_sections
->macro
.s
.section
= sectp
;
12759 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12761 else if (section_is_p (sectp
->name
, &names
->rnglists_dwo
))
12763 dwo_sections
->rnglists
.s
.section
= sectp
;
12764 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12766 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12768 dwo_sections
->str
.s
.section
= sectp
;
12769 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12771 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12773 dwo_sections
->str_offsets
.s
.section
= sectp
;
12774 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12776 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12778 struct dwarf2_section_info type_section
;
12780 memset (&type_section
, 0, sizeof (type_section
));
12781 type_section
.s
.section
= sectp
;
12782 type_section
.size
= bfd_section_size (sectp
);
12783 dwo_sections
->types
.push_back (type_section
);
12787 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12788 by PER_CU. This is for the non-DWP case.
12789 The result is NULL if DWO_NAME can't be found. */
12791 static struct dwo_file
*
12792 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12793 const char *comp_dir
)
12795 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12797 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12800 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12805 dwo_file_up
dwo_file (new struct dwo_file
);
12806 dwo_file
->dwo_name
= dwo_name
;
12807 dwo_file
->comp_dir
= comp_dir
;
12808 dwo_file
->dbfd
= std::move (dbfd
);
12810 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12811 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12812 &dwo_file
->sections
);
12814 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12817 if (cu
->per_cu
->dwarf_version
< 5)
12819 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12820 dwo_file
->sections
.types
, dwo_file
->tus
);
12824 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12825 &dwo_file
->sections
.info
, dwo_file
->tus
,
12829 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12831 return dwo_file
.release ();
12834 /* This function is mapped across the sections and remembers the offset and
12835 size of each of the DWP debugging sections common to version 1 and 2 that
12836 we are interested in. */
12839 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12840 dwp_file
*dwp_file
)
12842 const struct dwop_section_names
*names
= &dwop_section_names
;
12843 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12845 /* Record the ELF section number for later lookup: this is what the
12846 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12847 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12848 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12850 /* Look for specific sections that we need. */
12851 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12853 dwp_file
->sections
.str
.s
.section
= sectp
;
12854 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12856 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12858 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12859 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12861 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12863 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12864 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12868 /* This function is mapped across the sections and remembers the offset and
12869 size of each of the DWP version 2 debugging sections that we are interested
12870 in. This is split into a separate function because we don't know if we
12871 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12874 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12876 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12877 const struct dwop_section_names
*names
= &dwop_section_names
;
12878 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12880 /* Record the ELF section number for later lookup: this is what the
12881 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12882 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12883 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12885 /* Look for specific sections that we need. */
12886 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12888 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12889 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12891 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12893 dwp_file
->sections
.info
.s
.section
= sectp
;
12894 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12896 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12898 dwp_file
->sections
.line
.s
.section
= sectp
;
12899 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12901 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12903 dwp_file
->sections
.loc
.s
.section
= sectp
;
12904 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12906 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12908 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12909 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12911 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12913 dwp_file
->sections
.macro
.s
.section
= sectp
;
12914 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12916 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12918 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12919 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12921 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12923 dwp_file
->sections
.types
.s
.section
= sectp
;
12924 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12928 /* This function is mapped across the sections and remembers the offset and
12929 size of each of the DWP version 5 debugging sections that we are interested
12930 in. This is split into a separate function because we don't know if we
12931 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12934 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12936 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12937 const struct dwop_section_names
*names
= &dwop_section_names
;
12938 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12940 /* Record the ELF section number for later lookup: this is what the
12941 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12942 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12943 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12945 /* Look for specific sections that we need. */
12946 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12948 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12949 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12951 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12953 dwp_file
->sections
.info
.s
.section
= sectp
;
12954 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12956 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12958 dwp_file
->sections
.line
.s
.section
= sectp
;
12959 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12961 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12963 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12964 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12966 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12968 dwp_file
->sections
.macro
.s
.section
= sectp
;
12969 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12971 else if (section_is_p (sectp
->name
, &names
->rnglists_dwo
))
12973 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12974 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12976 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12978 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12979 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12983 /* Hash function for dwp_file loaded CUs/TUs. */
12986 hash_dwp_loaded_cutus (const void *item
)
12988 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12990 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12991 return dwo_unit
->signature
;
12994 /* Equality function for dwp_file loaded CUs/TUs. */
12997 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12999 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13000 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13002 return dua
->signature
== dub
->signature
;
13005 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13008 allocate_dwp_loaded_cutus_table ()
13010 return htab_up (htab_create_alloc (3,
13011 hash_dwp_loaded_cutus
,
13012 eq_dwp_loaded_cutus
,
13013 NULL
, xcalloc
, xfree
));
13016 /* Try to open DWP file FILE_NAME.
13017 The result is the bfd handle of the file.
13018 If there is a problem finding or opening the file, return NULL.
13019 Upon success, the canonicalized path of the file is stored in the bfd,
13020 same as symfile_bfd_open. */
13022 static gdb_bfd_ref_ptr
13023 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
13025 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
13027 1 /*search_cwd*/));
13031 /* Work around upstream bug 15652.
13032 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13033 [Whether that's a "bug" is debatable, but it is getting in our way.]
13034 We have no real idea where the dwp file is, because gdb's realpath-ing
13035 of the executable's path may have discarded the needed info.
13036 [IWBN if the dwp file name was recorded in the executable, akin to
13037 .gnu_debuglink, but that doesn't exist yet.]
13038 Strip the directory from FILE_NAME and search again. */
13039 if (*debug_file_directory
!= '\0')
13041 /* Don't implicitly search the current directory here.
13042 If the user wants to search "." to handle this case,
13043 it must be added to debug-file-directory. */
13044 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
13052 /* Initialize the use of the DWP file for the current objfile.
13053 By convention the name of the DWP file is ${objfile}.dwp.
13054 The result is NULL if it can't be found. */
13056 static std::unique_ptr
<struct dwp_file
>
13057 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
13059 struct objfile
*objfile
= per_objfile
->objfile
;
13061 /* Try to find first .dwp for the binary file before any symbolic links
13064 /* If the objfile is a debug file, find the name of the real binary
13065 file and get the name of dwp file from there. */
13066 std::string dwp_name
;
13067 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13069 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13070 const char *backlink_basename
= lbasename (backlink
->original_name
);
13072 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13075 dwp_name
= objfile
->original_name
;
13077 dwp_name
+= ".dwp";
13079 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
13081 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13083 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13084 dwp_name
= objfile_name (objfile
);
13085 dwp_name
+= ".dwp";
13086 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
13091 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
13093 return std::unique_ptr
<dwp_file
> ();
13096 const char *name
= bfd_get_filename (dbfd
.get ());
13097 std::unique_ptr
<struct dwp_file
> dwp_file
13098 (new struct dwp_file (name
, std::move (dbfd
)));
13100 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13101 dwp_file
->elf_sections
=
13102 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
13103 dwp_file
->num_sections
, asection
*);
13105 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13106 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13109 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
13111 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
13113 /* The DWP file version is stored in the hash table. Oh well. */
13114 if (dwp_file
->cus
&& dwp_file
->tus
13115 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13117 /* Technically speaking, we should try to limp along, but this is
13118 pretty bizarre. We use pulongest here because that's the established
13119 portability solution (e.g, we cannot use %u for uint32_t). */
13120 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13121 " TU version %s [in DWP file %s]"),
13122 pulongest (dwp_file
->cus
->version
),
13123 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13127 dwp_file
->version
= dwp_file
->cus
->version
;
13128 else if (dwp_file
->tus
)
13129 dwp_file
->version
= dwp_file
->tus
->version
;
13131 dwp_file
->version
= 2;
13133 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13135 if (dwp_file
->version
== 2)
13136 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13139 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13143 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
13144 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
13146 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
13147 dwarf_read_debug_printf (" %s CUs, %s TUs",
13148 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13149 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13154 /* Wrapper around open_and_init_dwp_file, only open it once. */
13156 static struct dwp_file
*
13157 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
13159 if (!per_objfile
->per_bfd
->dwp_checked
)
13161 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
13162 per_objfile
->per_bfd
->dwp_checked
= 1;
13164 return per_objfile
->per_bfd
->dwp_file
.get ();
13167 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13168 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13169 or in the DWP file for the objfile, referenced by THIS_UNIT.
13170 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13171 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13173 This is called, for example, when wanting to read a variable with a
13174 complex location. Therefore we don't want to do file i/o for every call.
13175 Therefore we don't want to look for a DWO file on every call.
13176 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13177 then we check if we've already seen DWO_NAME, and only THEN do we check
13180 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13181 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13183 static struct dwo_unit
*
13184 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13185 ULONGEST signature
, int is_debug_types
)
13187 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13188 struct objfile
*objfile
= per_objfile
->objfile
;
13189 const char *kind
= is_debug_types
? "TU" : "CU";
13190 void **dwo_file_slot
;
13191 struct dwo_file
*dwo_file
;
13192 struct dwp_file
*dwp_file
;
13194 /* First see if there's a DWP file.
13195 If we have a DWP file but didn't find the DWO inside it, don't
13196 look for the original DWO file. It makes gdb behave differently
13197 depending on whether one is debugging in the build tree. */
13199 dwp_file
= get_dwp_file (per_objfile
);
13200 if (dwp_file
!= NULL
)
13202 const struct dwp_hash_table
*dwp_htab
=
13203 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13205 if (dwp_htab
!= NULL
)
13207 struct dwo_unit
*dwo_cutu
=
13208 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
13211 if (dwo_cutu
!= NULL
)
13213 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
13214 kind
, hex_string (signature
),
13215 host_address_to_string (dwo_cutu
));
13223 /* No DWP file, look for the DWO file. */
13225 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
13226 if (*dwo_file_slot
== NULL
)
13228 /* Read in the file and build a table of the CUs/TUs it contains. */
13229 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
13231 /* NOTE: This will be NULL if unable to open the file. */
13232 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13234 if (dwo_file
!= NULL
)
13236 struct dwo_unit
*dwo_cutu
= NULL
;
13238 if (is_debug_types
&& dwo_file
->tus
)
13240 struct dwo_unit find_dwo_cutu
;
13242 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13243 find_dwo_cutu
.signature
= signature
;
13245 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
13248 else if (!is_debug_types
&& dwo_file
->cus
)
13250 struct dwo_unit find_dwo_cutu
;
13252 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13253 find_dwo_cutu
.signature
= signature
;
13254 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
13258 if (dwo_cutu
!= NULL
)
13260 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
13261 kind
, dwo_name
, hex_string (signature
),
13262 host_address_to_string (dwo_cutu
));
13269 /* We didn't find it. This could mean a dwo_id mismatch, or
13270 someone deleted the DWO/DWP file, or the search path isn't set up
13271 correctly to find the file. */
13273 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
13274 kind
, dwo_name
, hex_string (signature
));
13276 /* This is a warning and not a complaint because it can be caused by
13277 pilot error (e.g., user accidentally deleting the DWO). */
13279 /* Print the name of the DWP file if we looked there, helps the user
13280 better diagnose the problem. */
13281 std::string dwp_text
;
13283 if (dwp_file
!= NULL
)
13284 dwp_text
= string_printf (" [in DWP file %s]",
13285 lbasename (dwp_file
->name
));
13287 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13288 " [in module %s]"),
13289 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
13290 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
13295 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13296 See lookup_dwo_cutu_unit for details. */
13298 static struct dwo_unit
*
13299 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13300 ULONGEST signature
)
13302 gdb_assert (!cu
->per_cu
->is_debug_types
);
13304 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
13307 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13308 See lookup_dwo_cutu_unit for details. */
13310 static struct dwo_unit
*
13311 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
13313 gdb_assert (cu
->per_cu
->is_debug_types
);
13315 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
13317 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
13320 /* Traversal function for queue_and_load_all_dwo_tus. */
13323 queue_and_load_dwo_tu (void **slot
, void *info
)
13325 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13326 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
13327 ULONGEST signature
= dwo_unit
->signature
;
13328 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
13330 if (sig_type
!= NULL
)
13332 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13334 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13335 a real dependency of PER_CU on SIG_TYPE. That is detected later
13336 while processing PER_CU. */
13337 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
13338 load_full_type_unit (sig_cu
, cu
->per_objfile
);
13339 cu
->per_cu
->imported_symtabs_push (sig_cu
);
13345 /* Queue all TUs contained in the DWO of CU to be read in.
13346 The DWO may have the only definition of the type, though it may not be
13347 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13348 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13351 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
13353 struct dwo_unit
*dwo_unit
;
13354 struct dwo_file
*dwo_file
;
13356 gdb_assert (cu
!= nullptr);
13357 gdb_assert (!cu
->per_cu
->is_debug_types
);
13358 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
13360 dwo_unit
= cu
->dwo_unit
;
13361 gdb_assert (dwo_unit
!= NULL
);
13363 dwo_file
= dwo_unit
->dwo_file
;
13364 if (dwo_file
->tus
!= NULL
)
13365 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
13368 /* Read in various DIEs. */
13370 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13371 Inherit only the children of the DW_AT_abstract_origin DIE not being
13372 already referenced by DW_AT_abstract_origin from the children of the
13376 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13378 struct die_info
*child_die
;
13379 sect_offset
*offsetp
;
13380 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13381 struct die_info
*origin_die
;
13382 /* Iterator of the ORIGIN_DIE children. */
13383 struct die_info
*origin_child_die
;
13384 struct attribute
*attr
;
13385 struct dwarf2_cu
*origin_cu
;
13386 struct pending
**origin_previous_list_in_scope
;
13388 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13392 /* Note that following die references may follow to a die in a
13396 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13398 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13400 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13401 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13403 if (die
->tag
!= origin_die
->tag
13404 && !(die
->tag
== DW_TAG_inlined_subroutine
13405 && origin_die
->tag
== DW_TAG_subprogram
))
13406 complaint (_("DIE %s and its abstract origin %s have different tags"),
13407 sect_offset_str (die
->sect_off
),
13408 sect_offset_str (origin_die
->sect_off
));
13410 std::vector
<sect_offset
> offsets
;
13412 for (child_die
= die
->child
;
13413 child_die
&& child_die
->tag
;
13414 child_die
= child_die
->sibling
)
13416 struct die_info
*child_origin_die
;
13417 struct dwarf2_cu
*child_origin_cu
;
13419 /* We are trying to process concrete instance entries:
13420 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13421 it's not relevant to our analysis here. i.e. detecting DIEs that are
13422 present in the abstract instance but not referenced in the concrete
13424 if (child_die
->tag
== DW_TAG_call_site
13425 || child_die
->tag
== DW_TAG_GNU_call_site
)
13428 /* For each CHILD_DIE, find the corresponding child of
13429 ORIGIN_DIE. If there is more than one layer of
13430 DW_AT_abstract_origin, follow them all; there shouldn't be,
13431 but GCC versions at least through 4.4 generate this (GCC PR
13433 child_origin_die
= child_die
;
13434 child_origin_cu
= cu
;
13437 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13441 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13445 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13446 counterpart may exist. */
13447 if (child_origin_die
!= child_die
)
13449 if (child_die
->tag
!= child_origin_die
->tag
13450 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13451 && child_origin_die
->tag
== DW_TAG_subprogram
))
13452 complaint (_("Child DIE %s and its abstract origin %s have "
13454 sect_offset_str (child_die
->sect_off
),
13455 sect_offset_str (child_origin_die
->sect_off
));
13456 if (child_origin_die
->parent
!= origin_die
)
13457 complaint (_("Child DIE %s and its abstract origin %s have "
13458 "different parents"),
13459 sect_offset_str (child_die
->sect_off
),
13460 sect_offset_str (child_origin_die
->sect_off
));
13462 offsets
.push_back (child_origin_die
->sect_off
);
13465 std::sort (offsets
.begin (), offsets
.end ());
13466 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13467 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13468 if (offsetp
[-1] == *offsetp
)
13469 complaint (_("Multiple children of DIE %s refer "
13470 "to DIE %s as their abstract origin"),
13471 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13473 offsetp
= offsets
.data ();
13474 origin_child_die
= origin_die
->child
;
13475 while (origin_child_die
&& origin_child_die
->tag
)
13477 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13478 while (offsetp
< offsets_end
13479 && *offsetp
< origin_child_die
->sect_off
)
13481 if (offsetp
>= offsets_end
13482 || *offsetp
> origin_child_die
->sect_off
)
13484 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13485 Check whether we're already processing ORIGIN_CHILD_DIE.
13486 This can happen with mutually referenced abstract_origins.
13488 if (!origin_child_die
->in_process
)
13489 process_die (origin_child_die
, origin_cu
);
13491 origin_child_die
= origin_child_die
->sibling
;
13493 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13495 if (cu
!= origin_cu
)
13496 compute_delayed_physnames (origin_cu
);
13500 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13502 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13503 struct gdbarch
*gdbarch
= objfile
->arch ();
13504 struct context_stack
*newobj
;
13507 struct die_info
*child_die
;
13508 struct attribute
*attr
, *call_line
, *call_file
;
13510 CORE_ADDR baseaddr
;
13511 struct block
*block
;
13512 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13513 std::vector
<struct symbol
*> template_args
;
13514 struct template_symbol
*templ_func
= NULL
;
13518 /* If we do not have call site information, we can't show the
13519 caller of this inlined function. That's too confusing, so
13520 only use the scope for local variables. */
13521 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13522 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13523 if (call_line
== NULL
|| call_file
== NULL
)
13525 read_lexical_block_scope (die
, cu
);
13530 baseaddr
= objfile
->text_section_offset ();
13532 name
= dwarf2_name (die
, cu
);
13534 /* Ignore functions with missing or empty names. These are actually
13535 illegal according to the DWARF standard. */
13538 complaint (_("missing name for subprogram DIE at %s"),
13539 sect_offset_str (die
->sect_off
));
13543 /* Ignore functions with missing or invalid low and high pc attributes. */
13544 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13545 <= PC_BOUNDS_INVALID
)
13547 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13548 if (attr
== nullptr || !attr
->as_boolean ())
13549 complaint (_("cannot get low and high bounds "
13550 "for subprogram DIE at %s"),
13551 sect_offset_str (die
->sect_off
));
13555 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13556 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13558 /* If we have any template arguments, then we must allocate a
13559 different sort of symbol. */
13560 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13562 if (child_die
->tag
== DW_TAG_template_type_param
13563 || child_die
->tag
== DW_TAG_template_value_param
)
13565 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13566 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13571 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13572 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13573 (struct symbol
*) templ_func
);
13575 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13576 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13579 /* If there is a location expression for DW_AT_frame_base, record
13581 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13582 if (attr
!= nullptr)
13583 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13585 /* If there is a location for the static link, record it. */
13586 newobj
->static_link
= NULL
;
13587 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13588 if (attr
!= nullptr)
13590 newobj
->static_link
13591 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13592 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13596 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13598 if (die
->child
!= NULL
)
13600 child_die
= die
->child
;
13601 while (child_die
&& child_die
->tag
)
13603 if (child_die
->tag
== DW_TAG_template_type_param
13604 || child_die
->tag
== DW_TAG_template_value_param
)
13606 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13609 template_args
.push_back (arg
);
13612 process_die (child_die
, cu
);
13613 child_die
= child_die
->sibling
;
13617 inherit_abstract_dies (die
, cu
);
13619 /* If we have a DW_AT_specification, we might need to import using
13620 directives from the context of the specification DIE. See the
13621 comment in determine_prefix. */
13622 if (cu
->language
== language_cplus
13623 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13625 struct dwarf2_cu
*spec_cu
= cu
;
13626 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13630 child_die
= spec_die
->child
;
13631 while (child_die
&& child_die
->tag
)
13633 if (child_die
->tag
== DW_TAG_imported_module
)
13634 process_die (child_die
, spec_cu
);
13635 child_die
= child_die
->sibling
;
13638 /* In some cases, GCC generates specification DIEs that
13639 themselves contain DW_AT_specification attributes. */
13640 spec_die
= die_specification (spec_die
, &spec_cu
);
13644 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13645 /* Make a block for the local symbols within. */
13646 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13647 cstk
.static_link
, lowpc
, highpc
);
13649 /* For C++, set the block's scope. */
13650 if ((cu
->language
== language_cplus
13651 || cu
->language
== language_fortran
13652 || cu
->language
== language_d
13653 || cu
->language
== language_rust
)
13654 && cu
->processing_has_namespace_info
)
13655 block_set_scope (block
, determine_prefix (die
, cu
),
13656 &objfile
->objfile_obstack
);
13658 /* If we have address ranges, record them. */
13659 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13661 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13663 /* Attach template arguments to function. */
13664 if (!template_args
.empty ())
13666 gdb_assert (templ_func
!= NULL
);
13668 templ_func
->n_template_arguments
= template_args
.size ();
13669 templ_func
->template_arguments
13670 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13671 templ_func
->n_template_arguments
);
13672 memcpy (templ_func
->template_arguments
,
13673 template_args
.data (),
13674 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13676 /* Make sure that the symtab is set on the new symbols. Even
13677 though they don't appear in this symtab directly, other parts
13678 of gdb assume that symbols do, and this is reasonably
13680 for (symbol
*sym
: template_args
)
13681 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13684 /* In C++, we can have functions nested inside functions (e.g., when
13685 a function declares a class that has methods). This means that
13686 when we finish processing a function scope, we may need to go
13687 back to building a containing block's symbol lists. */
13688 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13689 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13691 /* If we've finished processing a top-level function, subsequent
13692 symbols go in the file symbol list. */
13693 if (cu
->get_builder ()->outermost_context_p ())
13694 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13697 /* Process all the DIES contained within a lexical block scope. Start
13698 a new scope, process the dies, and then close the scope. */
13701 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13703 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13704 struct gdbarch
*gdbarch
= objfile
->arch ();
13705 CORE_ADDR lowpc
, highpc
;
13706 struct die_info
*child_die
;
13707 CORE_ADDR baseaddr
;
13709 baseaddr
= objfile
->text_section_offset ();
13711 /* Ignore blocks with missing or invalid low and high pc attributes. */
13712 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13713 as multiple lexical blocks? Handling children in a sane way would
13714 be nasty. Might be easier to properly extend generic blocks to
13715 describe ranges. */
13716 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13718 case PC_BOUNDS_NOT_PRESENT
:
13719 /* DW_TAG_lexical_block has no attributes, process its children as if
13720 there was no wrapping by that DW_TAG_lexical_block.
13721 GCC does no longer produces such DWARF since GCC r224161. */
13722 for (child_die
= die
->child
;
13723 child_die
!= NULL
&& child_die
->tag
;
13724 child_die
= child_die
->sibling
)
13726 /* We might already be processing this DIE. This can happen
13727 in an unusual circumstance -- where a subroutine A
13728 appears lexically in another subroutine B, but A actually
13729 inlines B. The recursion is broken here, rather than in
13730 inherit_abstract_dies, because it seems better to simply
13731 drop concrete children here. */
13732 if (!child_die
->in_process
)
13733 process_die (child_die
, cu
);
13736 case PC_BOUNDS_INVALID
:
13739 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13740 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13742 cu
->get_builder ()->push_context (0, lowpc
);
13743 if (die
->child
!= NULL
)
13745 child_die
= die
->child
;
13746 while (child_die
&& child_die
->tag
)
13748 process_die (child_die
, cu
);
13749 child_die
= child_die
->sibling
;
13752 inherit_abstract_dies (die
, cu
);
13753 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13755 if (*cu
->get_builder ()->get_local_symbols () != NULL
13756 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13758 struct block
*block
13759 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13760 cstk
.start_addr
, highpc
);
13762 /* Note that recording ranges after traversing children, as we
13763 do here, means that recording a parent's ranges entails
13764 walking across all its children's ranges as they appear in
13765 the address map, which is quadratic behavior.
13767 It would be nicer to record the parent's ranges before
13768 traversing its children, simply overriding whatever you find
13769 there. But since we don't even decide whether to create a
13770 block until after we've traversed its children, that's hard
13772 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13774 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13775 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13778 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13781 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13783 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13784 struct objfile
*objfile
= per_objfile
->objfile
;
13785 struct gdbarch
*gdbarch
= objfile
->arch ();
13786 CORE_ADDR pc
, baseaddr
;
13787 struct attribute
*attr
;
13788 struct call_site
*call_site
, call_site_local
;
13791 struct die_info
*child_die
;
13793 baseaddr
= objfile
->text_section_offset ();
13795 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13798 /* This was a pre-DWARF-5 GNU extension alias
13799 for DW_AT_call_return_pc. */
13800 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13804 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13805 "DIE %s [in module %s]"),
13806 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13809 pc
= attr
->as_address () + baseaddr
;
13810 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13812 if (cu
->call_site_htab
== NULL
)
13813 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13814 NULL
, &objfile
->objfile_obstack
,
13815 hashtab_obstack_allocate
, NULL
);
13816 call_site_local
.pc
= pc
;
13817 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13820 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13821 "DIE %s [in module %s]"),
13822 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13823 objfile_name (objfile
));
13827 /* Count parameters at the caller. */
13830 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13831 child_die
= child_die
->sibling
)
13833 if (child_die
->tag
!= DW_TAG_call_site_parameter
13834 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13836 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13837 "DW_TAG_call_site child DIE %s [in module %s]"),
13838 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13839 objfile_name (objfile
));
13847 = ((struct call_site
*)
13848 obstack_alloc (&objfile
->objfile_obstack
,
13849 sizeof (*call_site
)
13850 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13852 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13853 call_site
->pc
= pc
;
13855 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13856 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13858 struct die_info
*func_die
;
13860 /* Skip also over DW_TAG_inlined_subroutine. */
13861 for (func_die
= die
->parent
;
13862 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13863 && func_die
->tag
!= DW_TAG_subroutine_type
;
13864 func_die
= func_die
->parent
);
13866 /* DW_AT_call_all_calls is a superset
13867 of DW_AT_call_all_tail_calls. */
13869 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13870 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13871 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13872 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13874 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13875 not complete. But keep CALL_SITE for look ups via call_site_htab,
13876 both the initial caller containing the real return address PC and
13877 the final callee containing the current PC of a chain of tail
13878 calls do not need to have the tail call list complete. But any
13879 function candidate for a virtual tail call frame searched via
13880 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13881 determined unambiguously. */
13885 struct type
*func_type
= NULL
;
13888 func_type
= get_die_type (func_die
, cu
);
13889 if (func_type
!= NULL
)
13891 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13893 /* Enlist this call site to the function. */
13894 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13895 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13898 complaint (_("Cannot find function owning DW_TAG_call_site "
13899 "DIE %s [in module %s]"),
13900 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13904 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13906 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13908 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13911 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13912 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13914 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13915 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13916 /* Keep NULL DWARF_BLOCK. */;
13917 else if (attr
->form_is_block ())
13919 struct dwarf2_locexpr_baton
*dlbaton
;
13920 struct dwarf_block
*block
= attr
->as_block ();
13922 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13923 dlbaton
->data
= block
->data
;
13924 dlbaton
->size
= block
->size
;
13925 dlbaton
->per_objfile
= per_objfile
;
13926 dlbaton
->per_cu
= cu
->per_cu
;
13928 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13930 else if (attr
->form_is_ref ())
13932 struct dwarf2_cu
*target_cu
= cu
;
13933 struct die_info
*target_die
;
13935 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13936 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13937 if (die_is_declaration (target_die
, target_cu
))
13939 const char *target_physname
;
13941 /* Prefer the mangled name; otherwise compute the demangled one. */
13942 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13943 if (target_physname
== NULL
)
13944 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13945 if (target_physname
== NULL
)
13946 complaint (_("DW_AT_call_target target DIE has invalid "
13947 "physname, for referencing DIE %s [in module %s]"),
13948 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13950 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13956 /* DW_AT_entry_pc should be preferred. */
13957 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13958 <= PC_BOUNDS_INVALID
)
13959 complaint (_("DW_AT_call_target target DIE has invalid "
13960 "low pc, for referencing DIE %s [in module %s]"),
13961 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13964 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13965 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13970 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13971 "block nor reference, for DIE %s [in module %s]"),
13972 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13974 call_site
->per_cu
= cu
->per_cu
;
13975 call_site
->per_objfile
= per_objfile
;
13977 for (child_die
= die
->child
;
13978 child_die
&& child_die
->tag
;
13979 child_die
= child_die
->sibling
)
13981 struct call_site_parameter
*parameter
;
13982 struct attribute
*loc
, *origin
;
13984 if (child_die
->tag
!= DW_TAG_call_site_parameter
13985 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13987 /* Already printed the complaint above. */
13991 gdb_assert (call_site
->parameter_count
< nparams
);
13992 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13994 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13995 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13996 register is contained in DW_AT_call_value. */
13998 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13999 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14000 if (origin
== NULL
)
14002 /* This was a pre-DWARF-5 GNU extension alias
14003 for DW_AT_call_parameter. */
14004 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14006 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
14008 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14010 sect_offset sect_off
= origin
->get_ref_die_offset ();
14011 if (!cu
->header
.offset_in_cu_p (sect_off
))
14013 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14014 binding can be done only inside one CU. Such referenced DIE
14015 therefore cannot be even moved to DW_TAG_partial_unit. */
14016 complaint (_("DW_AT_call_parameter offset is not in CU for "
14017 "DW_TAG_call_site child DIE %s [in module %s]"),
14018 sect_offset_str (child_die
->sect_off
),
14019 objfile_name (objfile
));
14022 parameter
->u
.param_cu_off
14023 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14025 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
14027 complaint (_("No DW_FORM_block* DW_AT_location for "
14028 "DW_TAG_call_site child DIE %s [in module %s]"),
14029 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14034 struct dwarf_block
*block
= loc
->as_block ();
14036 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14037 (block
->data
, &block
->data
[block
->size
]);
14038 if (parameter
->u
.dwarf_reg
!= -1)
14039 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14040 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
14041 &block
->data
[block
->size
],
14042 ¶meter
->u
.fb_offset
))
14043 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14046 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14047 "for DW_FORM_block* DW_AT_location is supported for "
14048 "DW_TAG_call_site child DIE %s "
14050 sect_offset_str (child_die
->sect_off
),
14051 objfile_name (objfile
));
14056 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14058 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14059 if (attr
== NULL
|| !attr
->form_is_block ())
14061 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14062 "DW_TAG_call_site child DIE %s [in module %s]"),
14063 sect_offset_str (child_die
->sect_off
),
14064 objfile_name (objfile
));
14068 struct dwarf_block
*block
= attr
->as_block ();
14069 parameter
->value
= block
->data
;
14070 parameter
->value_size
= block
->size
;
14072 /* Parameters are not pre-cleared by memset above. */
14073 parameter
->data_value
= NULL
;
14074 parameter
->data_value_size
= 0;
14075 call_site
->parameter_count
++;
14077 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14079 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14080 if (attr
!= nullptr)
14082 if (!attr
->form_is_block ())
14083 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14084 "DW_TAG_call_site child DIE %s [in module %s]"),
14085 sect_offset_str (child_die
->sect_off
),
14086 objfile_name (objfile
));
14089 block
= attr
->as_block ();
14090 parameter
->data_value
= block
->data
;
14091 parameter
->data_value_size
= block
->size
;
14097 /* Helper function for read_variable. If DIE represents a virtual
14098 table, then return the type of the concrete object that is
14099 associated with the virtual table. Otherwise, return NULL. */
14101 static struct type
*
14102 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14104 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14108 /* Find the type DIE. */
14109 struct die_info
*type_die
= NULL
;
14110 struct dwarf2_cu
*type_cu
= cu
;
14112 if (attr
->form_is_ref ())
14113 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14114 if (type_die
== NULL
)
14117 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14119 return die_containing_type (type_die
, type_cu
);
14122 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14125 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14127 struct rust_vtable_symbol
*storage
= NULL
;
14129 if (cu
->language
== language_rust
)
14131 struct type
*containing_type
= rust_containing_type (die
, cu
);
14133 if (containing_type
!= NULL
)
14135 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14137 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
14138 storage
->concrete_type
= containing_type
;
14139 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14143 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14144 struct attribute
*abstract_origin
14145 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14146 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14147 if (res
== NULL
&& loc
&& abstract_origin
)
14149 /* We have a variable without a name, but with a location and an abstract
14150 origin. This may be a concrete instance of an abstract variable
14151 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14153 struct dwarf2_cu
*origin_cu
= cu
;
14154 struct die_info
*origin_die
14155 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14156 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14157 per_objfile
->per_bfd
->abstract_to_concrete
14158 [origin_die
->sect_off
].push_back (die
->sect_off
);
14162 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14163 reading .debug_rnglists.
14164 Callback's type should be:
14165 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14166 Return true if the attributes are present and valid, otherwise,
14169 template <typename Callback
>
14171 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14172 dwarf_tag tag
, Callback
&&callback
)
14174 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14175 struct objfile
*objfile
= per_objfile
->objfile
;
14176 bfd
*obfd
= objfile
->obfd
;
14177 /* Base address selection entry. */
14178 gdb::optional
<CORE_ADDR
> base
;
14179 const gdb_byte
*buffer
;
14180 CORE_ADDR baseaddr
;
14181 bool overflow
= false;
14182 ULONGEST addr_index
;
14183 struct dwarf2_section_info
*rnglists_section
;
14185 base
= cu
->base_address
;
14186 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
14187 rnglists_section
->read (objfile
);
14189 if (offset
>= rnglists_section
->size
)
14191 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14195 buffer
= rnglists_section
->buffer
+ offset
;
14197 baseaddr
= objfile
->text_section_offset ();
14201 /* Initialize it due to a false compiler warning. */
14202 CORE_ADDR range_beginning
= 0, range_end
= 0;
14203 const gdb_byte
*buf_end
= (rnglists_section
->buffer
14204 + rnglists_section
->size
);
14205 unsigned int bytes_read
;
14207 if (buffer
== buf_end
)
14212 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14215 case DW_RLE_end_of_list
:
14217 case DW_RLE_base_address
:
14218 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14223 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14224 buffer
+= bytes_read
;
14226 case DW_RLE_base_addressx
:
14227 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14228 buffer
+= bytes_read
;
14229 base
= read_addr_index (cu
, addr_index
);
14231 case DW_RLE_start_length
:
14232 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14237 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14239 buffer
+= bytes_read
;
14240 range_end
= (range_beginning
14241 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14242 buffer
+= bytes_read
;
14243 if (buffer
> buf_end
)
14249 case DW_RLE_startx_length
:
14250 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14251 buffer
+= bytes_read
;
14252 range_beginning
= read_addr_index (cu
, addr_index
);
14253 if (buffer
> buf_end
)
14258 range_end
= (range_beginning
14259 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14260 buffer
+= bytes_read
;
14262 case DW_RLE_offset_pair
:
14263 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14264 buffer
+= bytes_read
;
14265 if (buffer
> buf_end
)
14270 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14271 buffer
+= bytes_read
;
14272 if (buffer
> buf_end
)
14278 case DW_RLE_start_end
:
14279 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14284 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14286 buffer
+= bytes_read
;
14287 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14288 buffer
+= bytes_read
;
14290 case DW_RLE_startx_endx
:
14291 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14292 buffer
+= bytes_read
;
14293 range_beginning
= read_addr_index (cu
, addr_index
);
14294 if (buffer
> buf_end
)
14299 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14300 buffer
+= bytes_read
;
14301 range_end
= read_addr_index (cu
, addr_index
);
14304 complaint (_("Invalid .debug_rnglists data (no base address)"));
14307 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14309 if (rlet
== DW_RLE_base_address
)
14312 if (range_beginning
> range_end
)
14314 /* Inverted range entries are invalid. */
14315 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14319 /* Empty range entries have no effect. */
14320 if (range_beginning
== range_end
)
14323 /* Only DW_RLE_offset_pair needs the base address added. */
14324 if (rlet
== DW_RLE_offset_pair
)
14326 if (!base
.has_value ())
14328 /* We have no valid base address for the DW_RLE_offset_pair. */
14329 complaint (_("Invalid .debug_rnglists data (no base address for "
14330 "DW_RLE_offset_pair)"));
14334 range_beginning
+= *base
;
14335 range_end
+= *base
;
14338 /* A not-uncommon case of bad debug info.
14339 Don't pollute the addrmap with bad data. */
14340 if (range_beginning
+ baseaddr
== 0
14341 && !per_objfile
->per_bfd
->has_section_at_zero
)
14343 complaint (_(".debug_rnglists entry has start address of zero"
14344 " [in module %s]"), objfile_name (objfile
));
14348 callback (range_beginning
, range_end
);
14353 complaint (_("Offset %d is not terminated "
14354 "for DW_AT_ranges attribute"),
14362 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14363 Callback's type should be:
14364 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14365 Return 1 if the attributes are present and valid, otherwise, return 0. */
14367 template <typename Callback
>
14369 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
14370 Callback
&&callback
)
14372 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14373 struct objfile
*objfile
= per_objfile
->objfile
;
14374 struct comp_unit_head
*cu_header
= &cu
->header
;
14375 bfd
*obfd
= objfile
->obfd
;
14376 unsigned int addr_size
= cu_header
->addr_size
;
14377 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14378 /* Base address selection entry. */
14379 gdb::optional
<CORE_ADDR
> base
;
14380 unsigned int dummy
;
14381 const gdb_byte
*buffer
;
14382 CORE_ADDR baseaddr
;
14384 if (cu_header
->version
>= 5)
14385 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
14387 base
= cu
->base_address
;
14389 per_objfile
->per_bfd
->ranges
.read (objfile
);
14390 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
14392 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14396 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
14398 baseaddr
= objfile
->text_section_offset ();
14402 CORE_ADDR range_beginning
, range_end
;
14404 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14405 buffer
+= addr_size
;
14406 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14407 buffer
+= addr_size
;
14408 offset
+= 2 * addr_size
;
14410 /* An end of list marker is a pair of zero addresses. */
14411 if (range_beginning
== 0 && range_end
== 0)
14412 /* Found the end of list entry. */
14415 /* Each base address selection entry is a pair of 2 values.
14416 The first is the largest possible address, the second is
14417 the base address. Check for a base address here. */
14418 if ((range_beginning
& mask
) == mask
)
14420 /* If we found the largest possible address, then we already
14421 have the base address in range_end. */
14426 if (!base
.has_value ())
14428 /* We have no valid base address for the ranges
14430 complaint (_("Invalid .debug_ranges data (no base address)"));
14434 if (range_beginning
> range_end
)
14436 /* Inverted range entries are invalid. */
14437 complaint (_("Invalid .debug_ranges data (inverted range)"));
14441 /* Empty range entries have no effect. */
14442 if (range_beginning
== range_end
)
14445 range_beginning
+= *base
;
14446 range_end
+= *base
;
14448 /* A not-uncommon case of bad debug info.
14449 Don't pollute the addrmap with bad data. */
14450 if (range_beginning
+ baseaddr
== 0
14451 && !per_objfile
->per_bfd
->has_section_at_zero
)
14453 complaint (_(".debug_ranges entry has start address of zero"
14454 " [in module %s]"), objfile_name (objfile
));
14458 callback (range_beginning
, range_end
);
14464 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14465 Return 1 if the attributes are present and valid, otherwise, return 0.
14466 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14469 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14470 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14471 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
14473 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14474 struct gdbarch
*gdbarch
= objfile
->arch ();
14475 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14478 CORE_ADDR high
= 0;
14481 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14482 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14484 if (ranges_pst
!= NULL
)
14489 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14490 range_beginning
+ baseaddr
)
14492 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14493 range_end
+ baseaddr
)
14495 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14496 lowpc
, highpc
- 1, ranges_pst
);
14499 /* FIXME: This is recording everything as a low-high
14500 segment of consecutive addresses. We should have a
14501 data structure for discontiguous block ranges
14505 low
= range_beginning
;
14511 if (range_beginning
< low
)
14512 low
= range_beginning
;
14513 if (range_end
> high
)
14521 /* If the first entry is an end-of-list marker, the range
14522 describes an empty scope, i.e. no instructions. */
14528 *high_return
= high
;
14532 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14533 definition for the return value. *LOWPC and *HIGHPC are set iff
14534 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14536 static enum pc_bounds_kind
14537 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14538 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14539 dwarf2_psymtab
*pst
)
14541 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14542 struct attribute
*attr
;
14543 struct attribute
*attr_high
;
14545 CORE_ADDR high
= 0;
14546 enum pc_bounds_kind ret
;
14548 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14551 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14552 if (attr
!= nullptr)
14554 low
= attr
->as_address ();
14555 high
= attr_high
->as_address ();
14556 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14560 /* Found high w/o low attribute. */
14561 return PC_BOUNDS_INVALID
;
14563 /* Found consecutive range of addresses. */
14564 ret
= PC_BOUNDS_HIGH_LOW
;
14568 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14569 if (attr
!= nullptr && attr
->form_is_unsigned ())
14571 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14572 We take advantage of the fact that DW_AT_ranges does not appear
14573 in DW_TAG_compile_unit of DWO files.
14575 Attributes of the form DW_FORM_rnglistx have already had their
14576 value changed by read_rnglist_index and already include
14577 DW_AT_rnglists_base, so don't need to add the ranges base,
14579 int need_ranges_base
= (die
->tag
!= DW_TAG_compile_unit
14580 && attr
->form
!= DW_FORM_rnglistx
);
14581 unsigned int ranges_offset
= (attr
->as_unsigned ()
14582 + (need_ranges_base
14586 /* Value of the DW_AT_ranges attribute is the offset in the
14587 .debug_ranges section. */
14588 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14590 return PC_BOUNDS_INVALID
;
14591 /* Found discontinuous range of addresses. */
14592 ret
= PC_BOUNDS_RANGES
;
14595 return PC_BOUNDS_NOT_PRESENT
;
14598 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14600 return PC_BOUNDS_INVALID
;
14602 /* When using the GNU linker, .gnu.linkonce. sections are used to
14603 eliminate duplicate copies of functions and vtables and such.
14604 The linker will arbitrarily choose one and discard the others.
14605 The AT_*_pc values for such functions refer to local labels in
14606 these sections. If the section from that file was discarded, the
14607 labels are not in the output, so the relocs get a value of 0.
14608 If this is a discarded function, mark the pc bounds as invalid,
14609 so that GDB will ignore it. */
14610 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14611 return PC_BOUNDS_INVALID
;
14619 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14620 its low and high PC addresses. Do nothing if these addresses could not
14621 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14622 and HIGHPC to the high address if greater than HIGHPC. */
14625 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14626 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14627 struct dwarf2_cu
*cu
)
14629 CORE_ADDR low
, high
;
14630 struct die_info
*child
= die
->child
;
14632 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14634 *lowpc
= std::min (*lowpc
, low
);
14635 *highpc
= std::max (*highpc
, high
);
14638 /* If the language does not allow nested subprograms (either inside
14639 subprograms or lexical blocks), we're done. */
14640 if (cu
->language
!= language_ada
)
14643 /* Check all the children of the given DIE. If it contains nested
14644 subprograms, then check their pc bounds. Likewise, we need to
14645 check lexical blocks as well, as they may also contain subprogram
14647 while (child
&& child
->tag
)
14649 if (child
->tag
== DW_TAG_subprogram
14650 || child
->tag
== DW_TAG_lexical_block
)
14651 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14652 child
= child
->sibling
;
14656 /* Get the low and high pc's represented by the scope DIE, and store
14657 them in *LOWPC and *HIGHPC. If the correct values can't be
14658 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14661 get_scope_pc_bounds (struct die_info
*die
,
14662 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14663 struct dwarf2_cu
*cu
)
14665 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14666 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14667 CORE_ADDR current_low
, current_high
;
14669 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14670 >= PC_BOUNDS_RANGES
)
14672 best_low
= current_low
;
14673 best_high
= current_high
;
14677 struct die_info
*child
= die
->child
;
14679 while (child
&& child
->tag
)
14681 switch (child
->tag
) {
14682 case DW_TAG_subprogram
:
14683 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14685 case DW_TAG_namespace
:
14686 case DW_TAG_module
:
14687 /* FIXME: carlton/2004-01-16: Should we do this for
14688 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14689 that current GCC's always emit the DIEs corresponding
14690 to definitions of methods of classes as children of a
14691 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14692 the DIEs giving the declarations, which could be
14693 anywhere). But I don't see any reason why the
14694 standards says that they have to be there. */
14695 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14697 if (current_low
!= ((CORE_ADDR
) -1))
14699 best_low
= std::min (best_low
, current_low
);
14700 best_high
= std::max (best_high
, current_high
);
14708 child
= child
->sibling
;
14713 *highpc
= best_high
;
14716 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14720 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14721 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14723 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14724 struct gdbarch
*gdbarch
= objfile
->arch ();
14725 struct attribute
*attr
;
14726 struct attribute
*attr_high
;
14728 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14731 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14732 if (attr
!= nullptr)
14734 CORE_ADDR low
= attr
->as_address ();
14735 CORE_ADDR high
= attr_high
->as_address ();
14737 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14740 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14741 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14742 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14746 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14747 if (attr
!= nullptr && attr
->form_is_unsigned ())
14749 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14750 We take advantage of the fact that DW_AT_ranges does not appear
14751 in DW_TAG_compile_unit of DWO files.
14753 Attributes of the form DW_FORM_rnglistx have already had their
14754 value changed by read_rnglist_index and already include
14755 DW_AT_rnglists_base, so don't need to add the ranges base,
14757 int need_ranges_base
= (die
->tag
!= DW_TAG_compile_unit
14758 && attr
->form
!= DW_FORM_rnglistx
);
14760 /* The value of the DW_AT_ranges attribute is the offset of the
14761 address range list in the .debug_ranges section. */
14762 unsigned long offset
= (attr
->as_unsigned ()
14763 + (need_ranges_base
? cu
->ranges_base
: 0));
14765 std::vector
<blockrange
> blockvec
;
14766 dwarf2_ranges_process (offset
, cu
, die
->tag
,
14767 [&] (CORE_ADDR start
, CORE_ADDR end
)
14771 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14772 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14773 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14774 blockvec
.emplace_back (start
, end
);
14777 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14781 /* Check whether the producer field indicates either of GCC < 4.6, or the
14782 Intel C/C++ compiler, and cache the result in CU. */
14785 check_producer (struct dwarf2_cu
*cu
)
14789 if (cu
->producer
== NULL
)
14791 /* For unknown compilers expect their behavior is DWARF version
14794 GCC started to support .debug_types sections by -gdwarf-4 since
14795 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14796 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14797 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14798 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14800 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14802 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14803 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14805 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14807 cu
->producer_is_icc
= true;
14808 cu
->producer_is_icc_lt_14
= major
< 14;
14810 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14811 cu
->producer_is_codewarrior
= true;
14814 /* For other non-GCC compilers, expect their behavior is DWARF version
14818 cu
->checked_producer
= true;
14821 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14822 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14823 during 4.6.0 experimental. */
14826 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14828 if (!cu
->checked_producer
)
14829 check_producer (cu
);
14831 return cu
->producer_is_gxx_lt_4_6
;
14835 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14836 with incorrect is_stmt attributes. */
14839 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14841 if (!cu
->checked_producer
)
14842 check_producer (cu
);
14844 return cu
->producer_is_codewarrior
;
14847 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14848 If that attribute is not available, return the appropriate
14851 static enum dwarf_access_attribute
14852 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14854 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14855 if (attr
!= nullptr)
14857 LONGEST value
= attr
->constant_value (-1);
14858 if (value
== DW_ACCESS_public
14859 || value
== DW_ACCESS_protected
14860 || value
== DW_ACCESS_private
)
14861 return (dwarf_access_attribute
) value
;
14862 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14866 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14868 /* The default DWARF 2 accessibility for members is public, the default
14869 accessibility for inheritance is private. */
14871 if (die
->tag
!= DW_TAG_inheritance
)
14872 return DW_ACCESS_public
;
14874 return DW_ACCESS_private
;
14878 /* DWARF 3+ defines the default accessibility a different way. The same
14879 rules apply now for DW_TAG_inheritance as for the members and it only
14880 depends on the container kind. */
14882 if (die
->parent
->tag
== DW_TAG_class_type
)
14883 return DW_ACCESS_private
;
14885 return DW_ACCESS_public
;
14889 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14890 offset. If the attribute was not found return 0, otherwise return
14891 1. If it was found but could not properly be handled, set *OFFSET
14895 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14898 struct attribute
*attr
;
14900 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14905 /* Note that we do not check for a section offset first here.
14906 This is because DW_AT_data_member_location is new in DWARF 4,
14907 so if we see it, we can assume that a constant form is really
14908 a constant and not a section offset. */
14909 if (attr
->form_is_constant ())
14910 *offset
= attr
->constant_value (0);
14911 else if (attr
->form_is_section_offset ())
14912 dwarf2_complex_location_expr_complaint ();
14913 else if (attr
->form_is_block ())
14914 *offset
= decode_locdesc (attr
->as_block (), cu
);
14916 dwarf2_complex_location_expr_complaint ();
14924 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14927 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14928 struct field
*field
)
14930 struct attribute
*attr
;
14932 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14935 if (attr
->form_is_constant ())
14937 LONGEST offset
= attr
->constant_value (0);
14938 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14940 else if (attr
->form_is_section_offset ())
14941 dwarf2_complex_location_expr_complaint ();
14942 else if (attr
->form_is_block ())
14945 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14947 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14950 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14951 struct objfile
*objfile
= per_objfile
->objfile
;
14952 struct dwarf2_locexpr_baton
*dlbaton
14953 = XOBNEW (&objfile
->objfile_obstack
,
14954 struct dwarf2_locexpr_baton
);
14955 dlbaton
->data
= attr
->as_block ()->data
;
14956 dlbaton
->size
= attr
->as_block ()->size
;
14957 /* When using this baton, we want to compute the address
14958 of the field, not the value. This is why
14959 is_reference is set to false here. */
14960 dlbaton
->is_reference
= false;
14961 dlbaton
->per_objfile
= per_objfile
;
14962 dlbaton
->per_cu
= cu
->per_cu
;
14964 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14968 dwarf2_complex_location_expr_complaint ();
14972 /* Add an aggregate field to the field list. */
14975 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14976 struct dwarf2_cu
*cu
)
14978 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14979 struct gdbarch
*gdbarch
= objfile
->arch ();
14980 struct nextfield
*new_field
;
14981 struct attribute
*attr
;
14983 const char *fieldname
= "";
14985 if (die
->tag
== DW_TAG_inheritance
)
14987 fip
->baseclasses
.emplace_back ();
14988 new_field
= &fip
->baseclasses
.back ();
14992 fip
->fields
.emplace_back ();
14993 new_field
= &fip
->fields
.back ();
14996 new_field
->offset
= die
->sect_off
;
14998 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14999 if (new_field
->accessibility
!= DW_ACCESS_public
)
15000 fip
->non_public_fields
= true;
15002 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15003 if (attr
!= nullptr)
15004 new_field
->virtuality
= attr
->as_virtuality ();
15006 new_field
->virtuality
= DW_VIRTUALITY_none
;
15008 fp
= &new_field
->field
;
15010 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15012 /* Data member other than a C++ static data member. */
15014 /* Get type of field. */
15015 fp
->set_type (die_type (die
, cu
));
15017 SET_FIELD_BITPOS (*fp
, 0);
15019 /* Get bit size of field (zero if none). */
15020 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15021 if (attr
!= nullptr)
15023 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
15027 FIELD_BITSIZE (*fp
) = 0;
15030 /* Get bit offset of field. */
15031 handle_data_member_location (die
, cu
, fp
);
15032 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15033 if (attr
!= nullptr && attr
->form_is_constant ())
15035 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15037 /* For big endian bits, the DW_AT_bit_offset gives the
15038 additional bit offset from the MSB of the containing
15039 anonymous object to the MSB of the field. We don't
15040 have to do anything special since we don't need to
15041 know the size of the anonymous object. */
15042 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15043 + attr
->constant_value (0)));
15047 /* For little endian bits, compute the bit offset to the
15048 MSB of the anonymous object, subtract off the number of
15049 bits from the MSB of the field to the MSB of the
15050 object, and then subtract off the number of bits of
15051 the field itself. The result is the bit offset of
15052 the LSB of the field. */
15053 int anonymous_size
;
15054 int bit_offset
= attr
->constant_value (0);
15056 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15057 if (attr
!= nullptr && attr
->form_is_constant ())
15059 /* The size of the anonymous object containing
15060 the bit field is explicit, so use the
15061 indicated size (in bytes). */
15062 anonymous_size
= attr
->constant_value (0);
15066 /* The size of the anonymous object containing
15067 the bit field must be inferred from the type
15068 attribute of the data member containing the
15070 anonymous_size
= TYPE_LENGTH (fp
->type ());
15072 SET_FIELD_BITPOS (*fp
,
15073 (FIELD_BITPOS (*fp
)
15074 + anonymous_size
* bits_per_byte
15075 - bit_offset
- FIELD_BITSIZE (*fp
)));
15078 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15080 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15081 + attr
->constant_value (0)));
15083 /* Get name of field. */
15084 fieldname
= dwarf2_name (die
, cu
);
15085 if (fieldname
== NULL
)
15088 /* The name is already allocated along with this objfile, so we don't
15089 need to duplicate it for the type. */
15090 fp
->name
= fieldname
;
15092 /* Change accessibility for artificial fields (e.g. virtual table
15093 pointer or virtual base class pointer) to private. */
15094 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15096 FIELD_ARTIFICIAL (*fp
) = 1;
15097 new_field
->accessibility
= DW_ACCESS_private
;
15098 fip
->non_public_fields
= true;
15101 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15103 /* C++ static member. */
15105 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15106 is a declaration, but all versions of G++ as of this writing
15107 (so through at least 3.2.1) incorrectly generate
15108 DW_TAG_variable tags. */
15110 const char *physname
;
15112 /* Get name of field. */
15113 fieldname
= dwarf2_name (die
, cu
);
15114 if (fieldname
== NULL
)
15117 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15119 /* Only create a symbol if this is an external value.
15120 new_symbol checks this and puts the value in the global symbol
15121 table, which we want. If it is not external, new_symbol
15122 will try to put the value in cu->list_in_scope which is wrong. */
15123 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15125 /* A static const member, not much different than an enum as far as
15126 we're concerned, except that we can support more types. */
15127 new_symbol (die
, NULL
, cu
);
15130 /* Get physical name. */
15131 physname
= dwarf2_physname (fieldname
, die
, cu
);
15133 /* The name is already allocated along with this objfile, so we don't
15134 need to duplicate it for the type. */
15135 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15136 fp
->set_type (die_type (die
, cu
));
15137 FIELD_NAME (*fp
) = fieldname
;
15139 else if (die
->tag
== DW_TAG_inheritance
)
15141 /* C++ base class field. */
15142 handle_data_member_location (die
, cu
, fp
);
15143 FIELD_BITSIZE (*fp
) = 0;
15144 fp
->set_type (die_type (die
, cu
));
15145 FIELD_NAME (*fp
) = fp
->type ()->name ();
15148 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15151 /* Can the type given by DIE define another type? */
15154 type_can_define_types (const struct die_info
*die
)
15158 case DW_TAG_typedef
:
15159 case DW_TAG_class_type
:
15160 case DW_TAG_structure_type
:
15161 case DW_TAG_union_type
:
15162 case DW_TAG_enumeration_type
:
15170 /* Add a type definition defined in the scope of the FIP's class. */
15173 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15174 struct dwarf2_cu
*cu
)
15176 struct decl_field fp
;
15177 memset (&fp
, 0, sizeof (fp
));
15179 gdb_assert (type_can_define_types (die
));
15181 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15182 fp
.name
= dwarf2_name (die
, cu
);
15183 fp
.type
= read_type_die (die
, cu
);
15185 /* Save accessibility. */
15186 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15187 switch (accessibility
)
15189 case DW_ACCESS_public
:
15190 /* The assumed value if neither private nor protected. */
15192 case DW_ACCESS_private
:
15195 case DW_ACCESS_protected
:
15196 fp
.is_protected
= 1;
15200 if (die
->tag
== DW_TAG_typedef
)
15201 fip
->typedef_field_list
.push_back (fp
);
15203 fip
->nested_types_list
.push_back (fp
);
15206 /* A convenience typedef that's used when finding the discriminant
15207 field for a variant part. */
15208 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
15211 /* Compute the discriminant range for a given variant. OBSTACK is
15212 where the results will be stored. VARIANT is the variant to
15213 process. IS_UNSIGNED indicates whether the discriminant is signed
15216 static const gdb::array_view
<discriminant_range
>
15217 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
15220 std::vector
<discriminant_range
> ranges
;
15222 if (variant
.default_branch
)
15225 if (variant
.discr_list_data
== nullptr)
15227 discriminant_range r
15228 = {variant
.discriminant_value
, variant
.discriminant_value
};
15229 ranges
.push_back (r
);
15233 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
15234 variant
.discr_list_data
->size
);
15235 while (!data
.empty ())
15237 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
15239 complaint (_("invalid discriminant marker: %d"), data
[0]);
15242 bool is_range
= data
[0] == DW_DSC_range
;
15243 data
= data
.slice (1);
15245 ULONGEST low
, high
;
15246 unsigned int bytes_read
;
15250 complaint (_("DW_AT_discr_list missing low value"));
15254 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
15256 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
15258 data
= data
.slice (bytes_read
);
15264 complaint (_("DW_AT_discr_list missing high value"));
15268 high
= read_unsigned_leb128 (nullptr, data
.data (),
15271 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
15273 data
= data
.slice (bytes_read
);
15278 ranges
.push_back ({ low
, high
});
15282 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
15284 std::copy (ranges
.begin (), ranges
.end (), result
);
15285 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
15288 static const gdb::array_view
<variant_part
> create_variant_parts
15289 (struct obstack
*obstack
,
15290 const offset_map_type
&offset_map
,
15291 struct field_info
*fi
,
15292 const std::vector
<variant_part_builder
> &variant_parts
);
15294 /* Fill in a "struct variant" for a given variant field. RESULT is
15295 the variant to fill in. OBSTACK is where any needed allocations
15296 will be done. OFFSET_MAP holds the mapping from section offsets to
15297 fields for the type. FI describes the fields of the type we're
15298 processing. FIELD is the variant field we're converting. */
15301 create_one_variant (variant
&result
, struct obstack
*obstack
,
15302 const offset_map_type
&offset_map
,
15303 struct field_info
*fi
, const variant_field
&field
)
15305 result
.discriminants
= convert_variant_range (obstack
, field
, false);
15306 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
15307 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
15308 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
15309 field
.variant_parts
);
15312 /* Fill in a "struct variant_part" for a given variant part. RESULT
15313 is the variant part to fill in. OBSTACK is where any needed
15314 allocations will be done. OFFSET_MAP holds the mapping from
15315 section offsets to fields for the type. FI describes the fields of
15316 the type we're processing. BUILDER is the variant part to be
15320 create_one_variant_part (variant_part
&result
,
15321 struct obstack
*obstack
,
15322 const offset_map_type
&offset_map
,
15323 struct field_info
*fi
,
15324 const variant_part_builder
&builder
)
15326 auto iter
= offset_map
.find (builder
.discriminant_offset
);
15327 if (iter
== offset_map
.end ())
15329 result
.discriminant_index
= -1;
15330 /* Doesn't matter. */
15331 result
.is_unsigned
= false;
15335 result
.discriminant_index
= iter
->second
;
15337 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
15340 size_t n
= builder
.variants
.size ();
15341 variant
*output
= new (obstack
) variant
[n
];
15342 for (size_t i
= 0; i
< n
; ++i
)
15343 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
15344 builder
.variants
[i
]);
15346 result
.variants
= gdb::array_view
<variant
> (output
, n
);
15349 /* Create a vector of variant parts that can be attached to a type.
15350 OBSTACK is where any needed allocations will be done. OFFSET_MAP
15351 holds the mapping from section offsets to fields for the type. FI
15352 describes the fields of the type we're processing. VARIANT_PARTS
15353 is the vector to convert. */
15355 static const gdb::array_view
<variant_part
>
15356 create_variant_parts (struct obstack
*obstack
,
15357 const offset_map_type
&offset_map
,
15358 struct field_info
*fi
,
15359 const std::vector
<variant_part_builder
> &variant_parts
)
15361 if (variant_parts
.empty ())
15364 size_t n
= variant_parts
.size ();
15365 variant_part
*result
= new (obstack
) variant_part
[n
];
15366 for (size_t i
= 0; i
< n
; ++i
)
15367 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
15370 return gdb::array_view
<variant_part
> (result
, n
);
15373 /* Compute the variant part vector for FIP, attaching it to TYPE when
15377 add_variant_property (struct field_info
*fip
, struct type
*type
,
15378 struct dwarf2_cu
*cu
)
15380 /* Map section offsets of fields to their field index. Note the
15381 field index here does not take the number of baseclasses into
15383 offset_map_type offset_map
;
15384 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
15385 offset_map
[fip
->fields
[i
].offset
] = i
;
15387 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15388 gdb::array_view
<variant_part
> parts
15389 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
15390 fip
->variant_parts
);
15392 struct dynamic_prop prop
;
15393 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
15394 obstack_copy (&objfile
->objfile_obstack
, &parts
,
15397 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
15400 /* Create the vector of fields, and attach it to the type. */
15403 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15404 struct dwarf2_cu
*cu
)
15406 int nfields
= fip
->nfields ();
15408 /* Record the field count, allocate space for the array of fields,
15409 and create blank accessibility bitfields if necessary. */
15410 type
->set_num_fields (nfields
);
15412 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
15414 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15416 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15418 TYPE_FIELD_PRIVATE_BITS (type
) =
15419 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15420 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15422 TYPE_FIELD_PROTECTED_BITS (type
) =
15423 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15424 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15426 TYPE_FIELD_IGNORE_BITS (type
) =
15427 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15428 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15431 /* If the type has baseclasses, allocate and clear a bit vector for
15432 TYPE_FIELD_VIRTUAL_BITS. */
15433 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15435 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15436 unsigned char *pointer
;
15438 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15439 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15440 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15441 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15442 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15445 if (!fip
->variant_parts
.empty ())
15446 add_variant_property (fip
, type
, cu
);
15448 /* Copy the saved-up fields into the field vector. */
15449 for (int i
= 0; i
< nfields
; ++i
)
15451 struct nextfield
&field
15452 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15453 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15455 type
->field (i
) = field
.field
;
15456 switch (field
.accessibility
)
15458 case DW_ACCESS_private
:
15459 if (cu
->language
!= language_ada
)
15460 SET_TYPE_FIELD_PRIVATE (type
, i
);
15463 case DW_ACCESS_protected
:
15464 if (cu
->language
!= language_ada
)
15465 SET_TYPE_FIELD_PROTECTED (type
, i
);
15468 case DW_ACCESS_public
:
15472 /* Unknown accessibility. Complain and treat it as public. */
15474 complaint (_("unsupported accessibility %d"),
15475 field
.accessibility
);
15479 if (i
< fip
->baseclasses
.size ())
15481 switch (field
.virtuality
)
15483 case DW_VIRTUALITY_virtual
:
15484 case DW_VIRTUALITY_pure_virtual
:
15485 if (cu
->language
== language_ada
)
15486 error (_("unexpected virtuality in component of Ada type"));
15487 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15494 /* Return true if this member function is a constructor, false
15498 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15500 const char *fieldname
;
15501 const char *type_name
;
15504 if (die
->parent
== NULL
)
15507 if (die
->parent
->tag
!= DW_TAG_structure_type
15508 && die
->parent
->tag
!= DW_TAG_union_type
15509 && die
->parent
->tag
!= DW_TAG_class_type
)
15512 fieldname
= dwarf2_name (die
, cu
);
15513 type_name
= dwarf2_name (die
->parent
, cu
);
15514 if (fieldname
== NULL
|| type_name
== NULL
)
15517 len
= strlen (fieldname
);
15518 return (strncmp (fieldname
, type_name
, len
) == 0
15519 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15522 /* Add a member function to the proper fieldlist. */
15525 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15526 struct type
*type
, struct dwarf2_cu
*cu
)
15528 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15529 struct attribute
*attr
;
15531 struct fnfieldlist
*flp
= nullptr;
15532 struct fn_field
*fnp
;
15533 const char *fieldname
;
15534 struct type
*this_type
;
15536 if (cu
->language
== language_ada
)
15537 error (_("unexpected member function in Ada type"));
15539 /* Get name of member function. */
15540 fieldname
= dwarf2_name (die
, cu
);
15541 if (fieldname
== NULL
)
15544 /* Look up member function name in fieldlist. */
15545 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15547 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15549 flp
= &fip
->fnfieldlists
[i
];
15554 /* Create a new fnfieldlist if necessary. */
15555 if (flp
== nullptr)
15557 fip
->fnfieldlists
.emplace_back ();
15558 flp
= &fip
->fnfieldlists
.back ();
15559 flp
->name
= fieldname
;
15560 i
= fip
->fnfieldlists
.size () - 1;
15563 /* Create a new member function field and add it to the vector of
15565 flp
->fnfields
.emplace_back ();
15566 fnp
= &flp
->fnfields
.back ();
15568 /* Delay processing of the physname until later. */
15569 if (cu
->language
== language_cplus
)
15570 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15574 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15575 fnp
->physname
= physname
? physname
: "";
15578 fnp
->type
= alloc_type (objfile
);
15579 this_type
= read_type_die (die
, cu
);
15580 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15582 int nparams
= this_type
->num_fields ();
15584 /* TYPE is the domain of this method, and THIS_TYPE is the type
15585 of the method itself (TYPE_CODE_METHOD). */
15586 smash_to_method_type (fnp
->type
, type
,
15587 TYPE_TARGET_TYPE (this_type
),
15588 this_type
->fields (),
15589 this_type
->num_fields (),
15590 this_type
->has_varargs ());
15592 /* Handle static member functions.
15593 Dwarf2 has no clean way to discern C++ static and non-static
15594 member functions. G++ helps GDB by marking the first
15595 parameter for non-static member functions (which is the this
15596 pointer) as artificial. We obtain this information from
15597 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15598 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15599 fnp
->voffset
= VOFFSET_STATIC
;
15602 complaint (_("member function type missing for '%s'"),
15603 dwarf2_full_name (fieldname
, die
, cu
));
15605 /* Get fcontext from DW_AT_containing_type if present. */
15606 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15607 fnp
->fcontext
= die_containing_type (die
, cu
);
15609 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15610 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15612 /* Get accessibility. */
15613 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15614 switch (accessibility
)
15616 case DW_ACCESS_private
:
15617 fnp
->is_private
= 1;
15619 case DW_ACCESS_protected
:
15620 fnp
->is_protected
= 1;
15624 /* Check for artificial methods. */
15625 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15626 if (attr
&& attr
->as_boolean ())
15627 fnp
->is_artificial
= 1;
15629 /* Check for defaulted methods. */
15630 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15631 if (attr
!= nullptr)
15632 fnp
->defaulted
= attr
->defaulted ();
15634 /* Check for deleted methods. */
15635 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15636 if (attr
!= nullptr && attr
->as_boolean ())
15637 fnp
->is_deleted
= 1;
15639 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15641 /* Get index in virtual function table if it is a virtual member
15642 function. For older versions of GCC, this is an offset in the
15643 appropriate virtual table, as specified by DW_AT_containing_type.
15644 For everyone else, it is an expression to be evaluated relative
15645 to the object address. */
15647 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15648 if (attr
!= nullptr)
15650 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15652 struct dwarf_block
*block
= attr
->as_block ();
15654 if (block
->data
[0] == DW_OP_constu
)
15656 /* Old-style GCC. */
15657 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15659 else if (block
->data
[0] == DW_OP_deref
15660 || (block
->size
> 1
15661 && block
->data
[0] == DW_OP_deref_size
15662 && block
->data
[1] == cu
->header
.addr_size
))
15664 fnp
->voffset
= decode_locdesc (block
, cu
);
15665 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15666 dwarf2_complex_location_expr_complaint ();
15668 fnp
->voffset
/= cu
->header
.addr_size
;
15672 dwarf2_complex_location_expr_complaint ();
15674 if (!fnp
->fcontext
)
15676 /* If there is no `this' field and no DW_AT_containing_type,
15677 we cannot actually find a base class context for the
15679 if (this_type
->num_fields () == 0
15680 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15682 complaint (_("cannot determine context for virtual member "
15683 "function \"%s\" (offset %s)"),
15684 fieldname
, sect_offset_str (die
->sect_off
));
15689 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15693 else if (attr
->form_is_section_offset ())
15695 dwarf2_complex_location_expr_complaint ();
15699 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15705 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15706 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15708 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15709 complaint (_("Member function \"%s\" (offset %s) is virtual "
15710 "but the vtable offset is not specified"),
15711 fieldname
, sect_offset_str (die
->sect_off
));
15712 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15713 TYPE_CPLUS_DYNAMIC (type
) = 1;
15718 /* Create the vector of member function fields, and attach it to the type. */
15721 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15722 struct dwarf2_cu
*cu
)
15724 if (cu
->language
== language_ada
)
15725 error (_("unexpected member functions in Ada type"));
15727 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15728 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15730 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15732 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15734 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15735 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15737 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15738 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15739 fn_flp
->fn_fields
= (struct fn_field
*)
15740 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15742 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15743 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15746 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15749 /* Returns non-zero if NAME is the name of a vtable member in CU's
15750 language, zero otherwise. */
15752 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15754 static const char vptr
[] = "_vptr";
15756 /* Look for the C++ form of the vtable. */
15757 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15763 /* GCC outputs unnamed structures that are really pointers to member
15764 functions, with the ABI-specified layout. If TYPE describes
15765 such a structure, smash it into a member function type.
15767 GCC shouldn't do this; it should just output pointer to member DIEs.
15768 This is GCC PR debug/28767. */
15771 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15773 struct type
*pfn_type
, *self_type
, *new_type
;
15775 /* Check for a structure with no name and two children. */
15776 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15779 /* Check for __pfn and __delta members. */
15780 if (TYPE_FIELD_NAME (type
, 0) == NULL
15781 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15782 || TYPE_FIELD_NAME (type
, 1) == NULL
15783 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15786 /* Find the type of the method. */
15787 pfn_type
= type
->field (0).type ();
15788 if (pfn_type
== NULL
15789 || pfn_type
->code () != TYPE_CODE_PTR
15790 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15793 /* Look for the "this" argument. */
15794 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15795 if (pfn_type
->num_fields () == 0
15796 /* || pfn_type->field (0).type () == NULL */
15797 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15800 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15801 new_type
= alloc_type (objfile
);
15802 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15803 pfn_type
->fields (), pfn_type
->num_fields (),
15804 pfn_type
->has_varargs ());
15805 smash_to_methodptr_type (type
, new_type
);
15808 /* While some versions of GCC will generate complicated DWARF for an
15809 array (see quirk_ada_thick_pointer), more recent versions were
15810 modified to emit an explicit thick pointer structure. However, in
15811 this case, the array still has DWARF expressions for its ranges,
15812 and these must be ignored. */
15815 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15818 gdb_assert (cu
->language
== language_ada
);
15820 /* Check for a structure with two children. */
15821 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15824 /* Check for P_ARRAY and P_BOUNDS members. */
15825 if (TYPE_FIELD_NAME (type
, 0) == NULL
15826 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
15827 || TYPE_FIELD_NAME (type
, 1) == NULL
15828 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
15831 /* Make sure we're looking at a pointer to an array. */
15832 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15834 struct type
*ary_type
= TYPE_TARGET_TYPE (type
->field (0).type ());
15836 while (ary_type
->code () == TYPE_CODE_ARRAY
)
15838 /* The Ada code already knows how to handle these types, so all
15839 that we need to do is turn the bounds into static bounds. */
15840 struct type
*index_type
= ary_type
->index_type ();
15842 index_type
->bounds ()->low
.set_const_val (1);
15843 index_type
->bounds ()->high
.set_const_val (0);
15845 /* Handle multi-dimensional arrays. */
15846 ary_type
= TYPE_TARGET_TYPE (ary_type
);
15850 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15851 appropriate error checking and issuing complaints if there is a
15855 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15857 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15859 if (attr
== nullptr)
15862 if (!attr
->form_is_constant ())
15864 complaint (_("DW_AT_alignment must have constant form"
15865 " - DIE at %s [in module %s]"),
15866 sect_offset_str (die
->sect_off
),
15867 objfile_name (cu
->per_objfile
->objfile
));
15871 LONGEST val
= attr
->constant_value (0);
15874 complaint (_("DW_AT_alignment value must not be negative"
15875 " - DIE at %s [in module %s]"),
15876 sect_offset_str (die
->sect_off
),
15877 objfile_name (cu
->per_objfile
->objfile
));
15880 ULONGEST align
= val
;
15884 complaint (_("DW_AT_alignment value must not be zero"
15885 " - DIE at %s [in module %s]"),
15886 sect_offset_str (die
->sect_off
),
15887 objfile_name (cu
->per_objfile
->objfile
));
15890 if ((align
& (align
- 1)) != 0)
15892 complaint (_("DW_AT_alignment value must be a power of 2"
15893 " - DIE at %s [in module %s]"),
15894 sect_offset_str (die
->sect_off
),
15895 objfile_name (cu
->per_objfile
->objfile
));
15902 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15903 the alignment for TYPE. */
15906 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15909 if (!set_type_align (type
, get_alignment (cu
, die
)))
15910 complaint (_("DW_AT_alignment value too large"
15911 " - DIE at %s [in module %s]"),
15912 sect_offset_str (die
->sect_off
),
15913 objfile_name (cu
->per_objfile
->objfile
));
15916 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15917 constant for a type, according to DWARF5 spec, Table 5.5. */
15920 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15925 case DW_CC_pass_by_reference
:
15926 case DW_CC_pass_by_value
:
15930 complaint (_("unrecognized DW_AT_calling_convention value "
15931 "(%s) for a type"), pulongest (value
));
15936 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15937 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15938 also according to GNU-specific values (see include/dwarf2.h). */
15941 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15946 case DW_CC_program
:
15950 case DW_CC_GNU_renesas_sh
:
15951 case DW_CC_GNU_borland_fastcall_i386
:
15952 case DW_CC_GDB_IBM_OpenCL
:
15956 complaint (_("unrecognized DW_AT_calling_convention value "
15957 "(%s) for a subroutine"), pulongest (value
));
15962 /* Called when we find the DIE that starts a structure or union scope
15963 (definition) to create a type for the structure or union. Fill in
15964 the type's name and general properties; the members will not be
15965 processed until process_structure_scope. A symbol table entry for
15966 the type will also not be done until process_structure_scope (assuming
15967 the type has a name).
15969 NOTE: we need to call these functions regardless of whether or not the
15970 DIE has a DW_AT_name attribute, since it might be an anonymous
15971 structure or union. This gets the type entered into our set of
15972 user defined types. */
15974 static struct type
*
15975 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15977 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15979 struct attribute
*attr
;
15982 /* If the definition of this type lives in .debug_types, read that type.
15983 Don't follow DW_AT_specification though, that will take us back up
15984 the chain and we want to go down. */
15985 attr
= die
->attr (DW_AT_signature
);
15986 if (attr
!= nullptr)
15988 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15990 /* The type's CU may not be the same as CU.
15991 Ensure TYPE is recorded with CU in die_type_hash. */
15992 return set_die_type (die
, type
, cu
);
15995 type
= alloc_type (objfile
);
15996 INIT_CPLUS_SPECIFIC (type
);
15998 name
= dwarf2_name (die
, cu
);
16001 if (cu
->language
== language_cplus
16002 || cu
->language
== language_d
16003 || cu
->language
== language_rust
)
16005 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
16007 /* dwarf2_full_name might have already finished building the DIE's
16008 type. If so, there is no need to continue. */
16009 if (get_die_type (die
, cu
) != NULL
)
16010 return get_die_type (die
, cu
);
16012 type
->set_name (full_name
);
16016 /* The name is already allocated along with this objfile, so
16017 we don't need to duplicate it for the type. */
16018 type
->set_name (name
);
16022 if (die
->tag
== DW_TAG_structure_type
)
16024 type
->set_code (TYPE_CODE_STRUCT
);
16026 else if (die
->tag
== DW_TAG_union_type
)
16028 type
->set_code (TYPE_CODE_UNION
);
16032 type
->set_code (TYPE_CODE_STRUCT
);
16035 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
16036 TYPE_DECLARED_CLASS (type
) = 1;
16038 /* Store the calling convention in the type if it's available in
16039 the die. Otherwise the calling convention remains set to
16040 the default value DW_CC_normal. */
16041 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16042 if (attr
!= nullptr
16043 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
16045 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16046 TYPE_CPLUS_CALLING_CONVENTION (type
)
16047 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
16050 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16051 if (attr
!= nullptr)
16053 if (attr
->form_is_constant ())
16054 TYPE_LENGTH (type
) = attr
->constant_value (0);
16057 struct dynamic_prop prop
;
16058 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
16059 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
16060 TYPE_LENGTH (type
) = 0;
16065 TYPE_LENGTH (type
) = 0;
16068 maybe_set_alignment (cu
, die
, type
);
16070 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16072 /* ICC<14 does not output the required DW_AT_declaration on
16073 incomplete types, but gives them a size of zero. */
16074 type
->set_is_stub (true);
16077 type
->set_stub_is_supported (true);
16079 if (die_is_declaration (die
, cu
))
16080 type
->set_is_stub (true);
16081 else if (attr
== NULL
&& die
->child
== NULL
16082 && producer_is_realview (cu
->producer
))
16083 /* RealView does not output the required DW_AT_declaration
16084 on incomplete types. */
16085 type
->set_is_stub (true);
16087 /* We need to add the type field to the die immediately so we don't
16088 infinitely recurse when dealing with pointers to the structure
16089 type within the structure itself. */
16090 set_die_type (die
, type
, cu
);
16092 /* set_die_type should be already done. */
16093 set_descriptive_type (type
, die
, cu
);
16098 static void handle_struct_member_die
16099 (struct die_info
*child_die
,
16101 struct field_info
*fi
,
16102 std::vector
<struct symbol
*> *template_args
,
16103 struct dwarf2_cu
*cu
);
16105 /* A helper for handle_struct_member_die that handles
16106 DW_TAG_variant_part. */
16109 handle_variant_part (struct die_info
*die
, struct type
*type
,
16110 struct field_info
*fi
,
16111 std::vector
<struct symbol
*> *template_args
,
16112 struct dwarf2_cu
*cu
)
16114 variant_part_builder
*new_part
;
16115 if (fi
->current_variant_part
== nullptr)
16117 fi
->variant_parts
.emplace_back ();
16118 new_part
= &fi
->variant_parts
.back ();
16120 else if (!fi
->current_variant_part
->processing_variant
)
16122 complaint (_("nested DW_TAG_variant_part seen "
16123 "- DIE at %s [in module %s]"),
16124 sect_offset_str (die
->sect_off
),
16125 objfile_name (cu
->per_objfile
->objfile
));
16130 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
16131 current
.variant_parts
.emplace_back ();
16132 new_part
= ¤t
.variant_parts
.back ();
16135 /* When we recurse, we want callees to add to this new variant
16137 scoped_restore save_current_variant_part
16138 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
16140 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16143 /* It's a univariant form, an extension we support. */
16145 else if (discr
->form_is_ref ())
16147 struct dwarf2_cu
*target_cu
= cu
;
16148 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16150 new_part
->discriminant_offset
= target_die
->sect_off
;
16154 complaint (_("DW_AT_discr does not have DIE reference form"
16155 " - DIE at %s [in module %s]"),
16156 sect_offset_str (die
->sect_off
),
16157 objfile_name (cu
->per_objfile
->objfile
));
16160 for (die_info
*child_die
= die
->child
;
16162 child_die
= child_die
->sibling
)
16163 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
16166 /* A helper for handle_struct_member_die that handles
16170 handle_variant (struct die_info
*die
, struct type
*type
,
16171 struct field_info
*fi
,
16172 std::vector
<struct symbol
*> *template_args
,
16173 struct dwarf2_cu
*cu
)
16175 if (fi
->current_variant_part
== nullptr)
16177 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
16178 "- DIE at %s [in module %s]"),
16179 sect_offset_str (die
->sect_off
),
16180 objfile_name (cu
->per_objfile
->objfile
));
16183 if (fi
->current_variant_part
->processing_variant
)
16185 complaint (_("nested DW_TAG_variant seen "
16186 "- DIE at %s [in module %s]"),
16187 sect_offset_str (die
->sect_off
),
16188 objfile_name (cu
->per_objfile
->objfile
));
16192 scoped_restore save_processing_variant
16193 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
16196 fi
->current_variant_part
->variants
.emplace_back ();
16197 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
16198 variant
.first_field
= fi
->fields
.size ();
16200 /* In a variant we want to get the discriminant and also add a
16201 field for our sole member child. */
16202 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
16203 if (discr
== nullptr || !discr
->form_is_constant ())
16205 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
16206 if (discr
== nullptr || discr
->as_block ()->size
== 0)
16207 variant
.default_branch
= true;
16209 variant
.discr_list_data
= discr
->as_block ();
16212 variant
.discriminant_value
= discr
->constant_value (0);
16214 for (die_info
*variant_child
= die
->child
;
16215 variant_child
!= NULL
;
16216 variant_child
= variant_child
->sibling
)
16217 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
16219 variant
.last_field
= fi
->fields
.size ();
16222 /* A helper for process_structure_scope that handles a single member
16226 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16227 struct field_info
*fi
,
16228 std::vector
<struct symbol
*> *template_args
,
16229 struct dwarf2_cu
*cu
)
16231 if (child_die
->tag
== DW_TAG_member
16232 || child_die
->tag
== DW_TAG_variable
)
16234 /* NOTE: carlton/2002-11-05: A C++ static data member
16235 should be a DW_TAG_member that is a declaration, but
16236 all versions of G++ as of this writing (so through at
16237 least 3.2.1) incorrectly generate DW_TAG_variable
16238 tags for them instead. */
16239 dwarf2_add_field (fi
, child_die
, cu
);
16241 else if (child_die
->tag
== DW_TAG_subprogram
)
16243 /* Rust doesn't have member functions in the C++ sense.
16244 However, it does emit ordinary functions as children
16245 of a struct DIE. */
16246 if (cu
->language
== language_rust
)
16247 read_func_scope (child_die
, cu
);
16250 /* C++ member function. */
16251 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16254 else if (child_die
->tag
== DW_TAG_inheritance
)
16256 /* C++ base class field. */
16257 dwarf2_add_field (fi
, child_die
, cu
);
16259 else if (type_can_define_types (child_die
))
16260 dwarf2_add_type_defn (fi
, child_die
, cu
);
16261 else if (child_die
->tag
== DW_TAG_template_type_param
16262 || child_die
->tag
== DW_TAG_template_value_param
)
16264 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16267 template_args
->push_back (arg
);
16269 else if (child_die
->tag
== DW_TAG_variant_part
)
16270 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
16271 else if (child_die
->tag
== DW_TAG_variant
)
16272 handle_variant (child_die
, type
, fi
, template_args
, cu
);
16275 /* Finish creating a structure or union type, including filling in
16276 its members and creating a symbol for it. */
16279 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16281 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16282 struct die_info
*child_die
;
16285 type
= get_die_type (die
, cu
);
16287 type
= read_structure_type (die
, cu
);
16289 bool has_template_parameters
= false;
16290 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16292 struct field_info fi
;
16293 std::vector
<struct symbol
*> template_args
;
16295 child_die
= die
->child
;
16297 while (child_die
&& child_die
->tag
)
16299 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16300 child_die
= child_die
->sibling
;
16303 /* Attach template arguments to type. */
16304 if (!template_args
.empty ())
16306 has_template_parameters
= true;
16307 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16308 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16309 TYPE_TEMPLATE_ARGUMENTS (type
)
16310 = XOBNEWVEC (&objfile
->objfile_obstack
,
16312 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16313 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16314 template_args
.data (),
16315 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16316 * sizeof (struct symbol
*)));
16319 /* Attach fields and member functions to the type. */
16320 if (fi
.nfields () > 0)
16321 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16322 if (!fi
.fnfieldlists
.empty ())
16324 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16326 /* Get the type which refers to the base class (possibly this
16327 class itself) which contains the vtable pointer for the current
16328 class from the DW_AT_containing_type attribute. This use of
16329 DW_AT_containing_type is a GNU extension. */
16331 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16333 struct type
*t
= die_containing_type (die
, cu
);
16335 set_type_vptr_basetype (type
, t
);
16340 /* Our own class provides vtbl ptr. */
16341 for (i
= t
->num_fields () - 1;
16342 i
>= TYPE_N_BASECLASSES (t
);
16345 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16347 if (is_vtable_name (fieldname
, cu
))
16349 set_type_vptr_fieldno (type
, i
);
16354 /* Complain if virtual function table field not found. */
16355 if (i
< TYPE_N_BASECLASSES (t
))
16356 complaint (_("virtual function table pointer "
16357 "not found when defining class '%s'"),
16358 type
->name () ? type
->name () : "");
16362 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16365 else if (cu
->producer
16366 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16368 /* The IBM XLC compiler does not provide direct indication
16369 of the containing type, but the vtable pointer is
16370 always named __vfp. */
16374 for (i
= type
->num_fields () - 1;
16375 i
>= TYPE_N_BASECLASSES (type
);
16378 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16380 set_type_vptr_fieldno (type
, i
);
16381 set_type_vptr_basetype (type
, type
);
16388 /* Copy fi.typedef_field_list linked list elements content into the
16389 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16390 if (!fi
.typedef_field_list
.empty ())
16392 int count
= fi
.typedef_field_list
.size ();
16394 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16395 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16396 = ((struct decl_field
*)
16398 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16399 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16401 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16402 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16405 /* Copy fi.nested_types_list linked list elements content into the
16406 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16407 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16409 int count
= fi
.nested_types_list
.size ();
16411 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16412 TYPE_NESTED_TYPES_ARRAY (type
)
16413 = ((struct decl_field
*)
16414 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16415 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16417 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16418 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16422 quirk_gcc_member_function_pointer (type
, objfile
);
16423 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16424 cu
->rust_unions
.push_back (type
);
16425 else if (cu
->language
== language_ada
)
16426 quirk_ada_thick_pointer_struct (die
, cu
, type
);
16428 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16429 snapshots) has been known to create a die giving a declaration
16430 for a class that has, as a child, a die giving a definition for a
16431 nested class. So we have to process our children even if the
16432 current die is a declaration. Normally, of course, a declaration
16433 won't have any children at all. */
16435 child_die
= die
->child
;
16437 while (child_die
!= NULL
&& child_die
->tag
)
16439 if (child_die
->tag
== DW_TAG_member
16440 || child_die
->tag
== DW_TAG_variable
16441 || child_die
->tag
== DW_TAG_inheritance
16442 || child_die
->tag
== DW_TAG_template_value_param
16443 || child_die
->tag
== DW_TAG_template_type_param
)
16448 process_die (child_die
, cu
);
16450 child_die
= child_die
->sibling
;
16453 /* Do not consider external references. According to the DWARF standard,
16454 these DIEs are identified by the fact that they have no byte_size
16455 attribute, and a declaration attribute. */
16456 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16457 || !die_is_declaration (die
, cu
)
16458 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16460 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16462 if (has_template_parameters
)
16464 struct symtab
*symtab
;
16465 if (sym
!= nullptr)
16466 symtab
= symbol_symtab (sym
);
16467 else if (cu
->line_header
!= nullptr)
16469 /* Any related symtab will do. */
16471 = cu
->line_header
->file_names ()[0].symtab
;
16476 complaint (_("could not find suitable "
16477 "symtab for template parameter"
16478 " - DIE at %s [in module %s]"),
16479 sect_offset_str (die
->sect_off
),
16480 objfile_name (objfile
));
16483 if (symtab
!= nullptr)
16485 /* Make sure that the symtab is set on the new symbols.
16486 Even though they don't appear in this symtab directly,
16487 other parts of gdb assume that symbols do, and this is
16488 reasonably true. */
16489 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16490 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16496 /* Assuming DIE is an enumeration type, and TYPE is its associated
16497 type, update TYPE using some information only available in DIE's
16498 children. In particular, the fields are computed. */
16501 update_enumeration_type_from_children (struct die_info
*die
,
16503 struct dwarf2_cu
*cu
)
16505 struct die_info
*child_die
;
16506 int unsigned_enum
= 1;
16509 auto_obstack obstack
;
16510 std::vector
<struct field
> fields
;
16512 for (child_die
= die
->child
;
16513 child_die
!= NULL
&& child_die
->tag
;
16514 child_die
= child_die
->sibling
)
16516 struct attribute
*attr
;
16518 const gdb_byte
*bytes
;
16519 struct dwarf2_locexpr_baton
*baton
;
16522 if (child_die
->tag
!= DW_TAG_enumerator
)
16525 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16529 name
= dwarf2_name (child_die
, cu
);
16531 name
= "<anonymous enumerator>";
16533 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16534 &value
, &bytes
, &baton
);
16542 if (count_one_bits_ll (value
) >= 2)
16546 fields
.emplace_back ();
16547 struct field
&field
= fields
.back ();
16548 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16549 SET_FIELD_ENUMVAL (field
, value
);
16552 if (!fields
.empty ())
16554 type
->set_num_fields (fields
.size ());
16557 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16558 memcpy (type
->fields (), fields
.data (),
16559 sizeof (struct field
) * fields
.size ());
16563 type
->set_is_unsigned (true);
16566 TYPE_FLAG_ENUM (type
) = 1;
16569 /* Given a DW_AT_enumeration_type die, set its type. We do not
16570 complete the type's fields yet, or create any symbols. */
16572 static struct type
*
16573 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16575 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16577 struct attribute
*attr
;
16580 /* If the definition of this type lives in .debug_types, read that type.
16581 Don't follow DW_AT_specification though, that will take us back up
16582 the chain and we want to go down. */
16583 attr
= die
->attr (DW_AT_signature
);
16584 if (attr
!= nullptr)
16586 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16588 /* The type's CU may not be the same as CU.
16589 Ensure TYPE is recorded with CU in die_type_hash. */
16590 return set_die_type (die
, type
, cu
);
16593 type
= alloc_type (objfile
);
16595 type
->set_code (TYPE_CODE_ENUM
);
16596 name
= dwarf2_full_name (NULL
, die
, cu
);
16598 type
->set_name (name
);
16600 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16603 struct type
*underlying_type
= die_type (die
, cu
);
16605 TYPE_TARGET_TYPE (type
) = underlying_type
;
16608 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16609 if (attr
!= nullptr)
16611 TYPE_LENGTH (type
) = attr
->constant_value (0);
16615 TYPE_LENGTH (type
) = 0;
16618 maybe_set_alignment (cu
, die
, type
);
16620 /* The enumeration DIE can be incomplete. In Ada, any type can be
16621 declared as private in the package spec, and then defined only
16622 inside the package body. Such types are known as Taft Amendment
16623 Types. When another package uses such a type, an incomplete DIE
16624 may be generated by the compiler. */
16625 if (die_is_declaration (die
, cu
))
16626 type
->set_is_stub (true);
16628 /* If this type has an underlying type that is not a stub, then we
16629 may use its attributes. We always use the "unsigned" attribute
16630 in this situation, because ordinarily we guess whether the type
16631 is unsigned -- but the guess can be wrong and the underlying type
16632 can tell us the reality. However, we defer to a local size
16633 attribute if one exists, because this lets the compiler override
16634 the underlying type if needed. */
16635 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16637 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16638 underlying_type
= check_typedef (underlying_type
);
16640 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16642 if (TYPE_LENGTH (type
) == 0)
16643 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16645 if (TYPE_RAW_ALIGN (type
) == 0
16646 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16647 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16650 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16652 set_die_type (die
, type
, cu
);
16654 /* Finish the creation of this type by using the enum's children.
16655 Note that, as usual, this must come after set_die_type to avoid
16656 infinite recursion when trying to compute the names of the
16658 update_enumeration_type_from_children (die
, type
, cu
);
16663 /* Given a pointer to a die which begins an enumeration, process all
16664 the dies that define the members of the enumeration, and create the
16665 symbol for the enumeration type.
16667 NOTE: We reverse the order of the element list. */
16670 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16672 struct type
*this_type
;
16674 this_type
= get_die_type (die
, cu
);
16675 if (this_type
== NULL
)
16676 this_type
= read_enumeration_type (die
, cu
);
16678 if (die
->child
!= NULL
)
16680 struct die_info
*child_die
;
16683 child_die
= die
->child
;
16684 while (child_die
&& child_die
->tag
)
16686 if (child_die
->tag
!= DW_TAG_enumerator
)
16688 process_die (child_die
, cu
);
16692 name
= dwarf2_name (child_die
, cu
);
16694 new_symbol (child_die
, this_type
, cu
);
16697 child_die
= child_die
->sibling
;
16701 /* If we are reading an enum from a .debug_types unit, and the enum
16702 is a declaration, and the enum is not the signatured type in the
16703 unit, then we do not want to add a symbol for it. Adding a
16704 symbol would in some cases obscure the true definition of the
16705 enum, giving users an incomplete type when the definition is
16706 actually available. Note that we do not want to do this for all
16707 enums which are just declarations, because C++0x allows forward
16708 enum declarations. */
16709 if (cu
->per_cu
->is_debug_types
16710 && die_is_declaration (die
, cu
))
16712 struct signatured_type
*sig_type
;
16714 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16715 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16716 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16720 new_symbol (die
, this_type
, cu
);
16723 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16724 expression for an index type and finds the corresponding field
16725 offset in the hidden "P_BOUNDS" structure. Returns true on success
16726 and updates *FIELD, false if it fails to recognize an
16730 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16731 int *bounds_offset
, struct field
*field
,
16732 struct dwarf2_cu
*cu
)
16734 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16735 if (attr
== nullptr || !attr
->form_is_block ())
16738 const struct dwarf_block
*block
= attr
->as_block ();
16739 const gdb_byte
*start
= block
->data
;
16740 const gdb_byte
*end
= block
->data
+ block
->size
;
16742 /* The expression to recognize generally looks like:
16744 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16745 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16747 However, the second "plus_uconst" may be missing:
16749 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16750 DW_OP_deref_size: 4)
16752 This happens when the field is at the start of the structure.
16754 Also, the final deref may not be sized:
16756 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16759 This happens when the size of the index type happens to be the
16760 same as the architecture's word size. This can occur with or
16761 without the second plus_uconst. */
16763 if (end
- start
< 2)
16765 if (*start
++ != DW_OP_push_object_address
)
16767 if (*start
++ != DW_OP_plus_uconst
)
16770 uint64_t this_bound_off
;
16771 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16772 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16774 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16775 is consistent among all bounds. */
16776 if (*bounds_offset
== -1)
16777 *bounds_offset
= this_bound_off
;
16778 else if (*bounds_offset
!= this_bound_off
)
16781 if (start
== end
|| *start
++ != DW_OP_deref
)
16787 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16789 /* This means an offset of 0. */
16791 else if (*start
++ != DW_OP_plus_uconst
)
16795 /* The size is the parameter to DW_OP_plus_uconst. */
16797 start
= gdb_read_uleb128 (start
, end
, &val
);
16798 if (start
== nullptr)
16800 if ((int) val
!= val
)
16809 if (*start
== DW_OP_deref_size
)
16811 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16812 if (start
== nullptr)
16815 else if (*start
== DW_OP_deref
)
16817 size
= cu
->header
.addr_size
;
16823 SET_FIELD_BITPOS (*field
, 8 * offset
);
16824 if (size
!= TYPE_LENGTH (field
->type ()))
16825 FIELD_BITSIZE (*field
) = 8 * size
;
16830 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16831 some kinds of Ada arrays:
16833 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16834 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16835 <11e0> DW_AT_data_location: 2 byte block: 97 6
16836 (DW_OP_push_object_address; DW_OP_deref)
16837 <11e3> DW_AT_type : <0x1173>
16838 <11e7> DW_AT_sibling : <0x1201>
16839 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16840 <11ec> DW_AT_type : <0x1206>
16841 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16842 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16843 DW_OP_deref_size: 4)
16844 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16845 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16846 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16848 This actually represents a "thick pointer", which is a structure
16849 with two elements: one that is a pointer to the array data, and one
16850 that is a pointer to another structure; this second structure holds
16853 This returns a new type on success, or nullptr if this didn't
16854 recognize the type. */
16856 static struct type
*
16857 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16860 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16861 /* So far we've only seen this with block form. */
16862 if (attr
== nullptr || !attr
->form_is_block ())
16865 /* Note that this will fail if the structure layout is changed by
16866 the compiler. However, we have no good way to recognize some
16867 other layout, because we don't know what expression the compiler
16868 might choose to emit should this happen. */
16869 struct dwarf_block
*blk
= attr
->as_block ();
16871 || blk
->data
[0] != DW_OP_push_object_address
16872 || blk
->data
[1] != DW_OP_deref
)
16875 int bounds_offset
= -1;
16876 int max_align
= -1;
16877 std::vector
<struct field
> range_fields
;
16878 for (struct die_info
*child_die
= die
->child
;
16880 child_die
= child_die
->sibling
)
16882 if (child_die
->tag
== DW_TAG_subrange_type
)
16884 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16886 int this_align
= type_align (underlying
);
16887 if (this_align
> max_align
)
16888 max_align
= this_align
;
16890 range_fields
.emplace_back ();
16891 range_fields
.emplace_back ();
16893 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16894 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16896 lower
.set_type (underlying
);
16897 FIELD_ARTIFICIAL (lower
) = 1;
16899 upper
.set_type (underlying
);
16900 FIELD_ARTIFICIAL (upper
) = 1;
16902 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16903 &bounds_offset
, &lower
, cu
)
16904 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16905 &bounds_offset
, &upper
, cu
))
16910 /* This shouldn't really happen, but double-check that we found
16911 where the bounds are stored. */
16912 if (bounds_offset
== -1)
16915 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16916 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16920 /* Set the name of each field in the bounds. */
16921 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16922 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
16923 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16924 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
16927 struct type
*bounds
= alloc_type (objfile
);
16928 bounds
->set_code (TYPE_CODE_STRUCT
);
16930 bounds
->set_num_fields (range_fields
.size ());
16932 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16933 * sizeof (struct field
))));
16934 memcpy (bounds
->fields (), range_fields
.data (),
16935 bounds
->num_fields () * sizeof (struct field
));
16937 int last_fieldno
= range_fields
.size () - 1;
16938 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
16939 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16940 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16942 /* Rewrite the existing array type in place. Specifically, we
16943 remove any dynamic properties we might have read, and we replace
16944 the index types. */
16945 struct type
*iter
= type
;
16946 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16948 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16949 iter
->main_type
->dyn_prop_list
= nullptr;
16950 iter
->set_index_type
16951 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16952 iter
= TYPE_TARGET_TYPE (iter
);
16955 struct type
*result
= alloc_type (objfile
);
16956 result
->set_code (TYPE_CODE_STRUCT
);
16958 result
->set_num_fields (2);
16960 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16961 * sizeof (struct field
))));
16963 /* The names are chosen to coincide with what the compiler does with
16964 -fgnat-encodings=all, which the Ada code in gdb already
16966 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
16967 result
->field (0).set_type (lookup_pointer_type (type
));
16969 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
16970 result
->field (1).set_type (lookup_pointer_type (bounds
));
16971 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
16973 result
->set_name (type
->name ());
16974 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16975 + TYPE_LENGTH (result
->field (1).type ()));
16980 /* Extract all information from a DW_TAG_array_type DIE and put it in
16981 the DIE's type field. For now, this only handles one dimensional
16984 static struct type
*
16985 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16987 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16988 struct die_info
*child_die
;
16990 struct type
*element_type
, *range_type
, *index_type
;
16991 struct attribute
*attr
;
16993 struct dynamic_prop
*byte_stride_prop
= NULL
;
16994 unsigned int bit_stride
= 0;
16996 element_type
= die_type (die
, cu
);
16998 /* The die_type call above may have already set the type for this DIE. */
16999 type
= get_die_type (die
, cu
);
17003 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17007 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17010 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
17011 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
17015 complaint (_("unable to read array DW_AT_byte_stride "
17016 " - DIE at %s [in module %s]"),
17017 sect_offset_str (die
->sect_off
),
17018 objfile_name (cu
->per_objfile
->objfile
));
17019 /* Ignore this attribute. We will likely not be able to print
17020 arrays of this type correctly, but there is little we can do
17021 to help if we cannot read the attribute's value. */
17022 byte_stride_prop
= NULL
;
17026 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17028 bit_stride
= attr
->constant_value (0);
17030 /* Irix 6.2 native cc creates array types without children for
17031 arrays with unspecified length. */
17032 if (die
->child
== NULL
)
17034 index_type
= objfile_type (objfile
)->builtin_int
;
17035 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
17036 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
17037 byte_stride_prop
, bit_stride
);
17038 return set_die_type (die
, type
, cu
);
17041 std::vector
<struct type
*> range_types
;
17042 child_die
= die
->child
;
17043 while (child_die
&& child_die
->tag
)
17045 if (child_die
->tag
== DW_TAG_subrange_type
)
17047 struct type
*child_type
= read_type_die (child_die
, cu
);
17049 if (child_type
!= NULL
)
17051 /* The range type was succesfully read. Save it for the
17052 array type creation. */
17053 range_types
.push_back (child_type
);
17056 child_die
= child_die
->sibling
;
17059 /* Dwarf2 dimensions are output from left to right, create the
17060 necessary array types in backwards order. */
17062 type
= element_type
;
17064 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
17068 while (i
< range_types
.size ())
17070 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
17071 byte_stride_prop
, bit_stride
);
17073 byte_stride_prop
= nullptr;
17078 size_t ndim
= range_types
.size ();
17081 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
17082 byte_stride_prop
, bit_stride
);
17084 byte_stride_prop
= nullptr;
17088 /* Understand Dwarf2 support for vector types (like they occur on
17089 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
17090 array type. This is not part of the Dwarf2/3 standard yet, but a
17091 custom vendor extension. The main difference between a regular
17092 array and the vector variant is that vectors are passed by value
17094 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
17095 if (attr
!= nullptr)
17096 make_vector_type (type
);
17098 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
17099 implementation may choose to implement triple vectors using this
17101 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17102 if (attr
!= nullptr && attr
->form_is_unsigned ())
17104 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
17105 TYPE_LENGTH (type
) = attr
->as_unsigned ();
17107 complaint (_("DW_AT_byte_size for array type smaller "
17108 "than the total size of elements"));
17111 name
= dwarf2_name (die
, cu
);
17113 type
->set_name (name
);
17115 maybe_set_alignment (cu
, die
, type
);
17117 struct type
*replacement_type
= nullptr;
17118 if (cu
->language
== language_ada
)
17120 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
17121 if (replacement_type
!= nullptr)
17122 type
= replacement_type
;
17125 /* Install the type in the die. */
17126 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
17128 /* set_die_type should be already done. */
17129 set_descriptive_type (type
, die
, cu
);
17134 static enum dwarf_array_dim_ordering
17135 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
17137 struct attribute
*attr
;
17139 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
17141 if (attr
!= nullptr)
17143 LONGEST val
= attr
->constant_value (-1);
17144 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
17145 return (enum dwarf_array_dim_ordering
) val
;
17148 /* GNU F77 is a special case, as at 08/2004 array type info is the
17149 opposite order to the dwarf2 specification, but data is still
17150 laid out as per normal fortran.
17152 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
17153 version checking. */
17155 if (cu
->language
== language_fortran
17156 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
17158 return DW_ORD_row_major
;
17161 switch (cu
->language_defn
->array_ordering ())
17163 case array_column_major
:
17164 return DW_ORD_col_major
;
17165 case array_row_major
:
17167 return DW_ORD_row_major
;
17171 /* Extract all information from a DW_TAG_set_type DIE and put it in
17172 the DIE's type field. */
17174 static struct type
*
17175 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17177 struct type
*domain_type
, *set_type
;
17178 struct attribute
*attr
;
17180 domain_type
= die_type (die
, cu
);
17182 /* The die_type call above may have already set the type for this DIE. */
17183 set_type
= get_die_type (die
, cu
);
17187 set_type
= create_set_type (NULL
, domain_type
);
17189 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17190 if (attr
!= nullptr && attr
->form_is_unsigned ())
17191 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
17193 maybe_set_alignment (cu
, die
, set_type
);
17195 return set_die_type (die
, set_type
, cu
);
17198 /* A helper for read_common_block that creates a locexpr baton.
17199 SYM is the symbol which we are marking as computed.
17200 COMMON_DIE is the DIE for the common block.
17201 COMMON_LOC is the location expression attribute for the common
17203 MEMBER_LOC is the location expression attribute for the particular
17204 member of the common block that we are processing.
17205 CU is the CU from which the above come. */
17208 mark_common_block_symbol_computed (struct symbol
*sym
,
17209 struct die_info
*common_die
,
17210 struct attribute
*common_loc
,
17211 struct attribute
*member_loc
,
17212 struct dwarf2_cu
*cu
)
17214 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17215 struct objfile
*objfile
= per_objfile
->objfile
;
17216 struct dwarf2_locexpr_baton
*baton
;
17218 unsigned int cu_off
;
17219 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
17220 LONGEST offset
= 0;
17222 gdb_assert (common_loc
&& member_loc
);
17223 gdb_assert (common_loc
->form_is_block ());
17224 gdb_assert (member_loc
->form_is_block ()
17225 || member_loc
->form_is_constant ());
17227 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
17228 baton
->per_objfile
= per_objfile
;
17229 baton
->per_cu
= cu
->per_cu
;
17230 gdb_assert (baton
->per_cu
);
17232 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
17234 if (member_loc
->form_is_constant ())
17236 offset
= member_loc
->constant_value (0);
17237 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
17240 baton
->size
+= member_loc
->as_block ()->size
;
17242 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
17245 *ptr
++ = DW_OP_call4
;
17246 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
17247 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
17250 if (member_loc
->form_is_constant ())
17252 *ptr
++ = DW_OP_addr
;
17253 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
17254 ptr
+= cu
->header
.addr_size
;
17258 /* We have to copy the data here, because DW_OP_call4 will only
17259 use a DW_AT_location attribute. */
17260 struct dwarf_block
*block
= member_loc
->as_block ();
17261 memcpy (ptr
, block
->data
, block
->size
);
17262 ptr
+= block
->size
;
17265 *ptr
++ = DW_OP_plus
;
17266 gdb_assert (ptr
- baton
->data
== baton
->size
);
17268 SYMBOL_LOCATION_BATON (sym
) = baton
;
17269 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
17272 /* Create appropriate locally-scoped variables for all the
17273 DW_TAG_common_block entries. Also create a struct common_block
17274 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
17275 is used to separate the common blocks name namespace from regular
17279 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
17281 struct attribute
*attr
;
17283 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17284 if (attr
!= nullptr)
17286 /* Support the .debug_loc offsets. */
17287 if (attr
->form_is_block ())
17291 else if (attr
->form_is_section_offset ())
17293 dwarf2_complex_location_expr_complaint ();
17298 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17299 "common block member");
17304 if (die
->child
!= NULL
)
17306 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17307 struct die_info
*child_die
;
17308 size_t n_entries
= 0, size
;
17309 struct common_block
*common_block
;
17310 struct symbol
*sym
;
17312 for (child_die
= die
->child
;
17313 child_die
&& child_die
->tag
;
17314 child_die
= child_die
->sibling
)
17317 size
= (sizeof (struct common_block
)
17318 + (n_entries
- 1) * sizeof (struct symbol
*));
17320 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17322 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17323 common_block
->n_entries
= 0;
17325 for (child_die
= die
->child
;
17326 child_die
&& child_die
->tag
;
17327 child_die
= child_die
->sibling
)
17329 /* Create the symbol in the DW_TAG_common_block block in the current
17331 sym
= new_symbol (child_die
, NULL
, cu
);
17334 struct attribute
*member_loc
;
17336 common_block
->contents
[common_block
->n_entries
++] = sym
;
17338 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17342 /* GDB has handled this for a long time, but it is
17343 not specified by DWARF. It seems to have been
17344 emitted by gfortran at least as recently as:
17345 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17346 complaint (_("Variable in common block has "
17347 "DW_AT_data_member_location "
17348 "- DIE at %s [in module %s]"),
17349 sect_offset_str (child_die
->sect_off
),
17350 objfile_name (objfile
));
17352 if (member_loc
->form_is_section_offset ())
17353 dwarf2_complex_location_expr_complaint ();
17354 else if (member_loc
->form_is_constant ()
17355 || member_loc
->form_is_block ())
17357 if (attr
!= nullptr)
17358 mark_common_block_symbol_computed (sym
, die
, attr
,
17362 dwarf2_complex_location_expr_complaint ();
17367 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17368 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17372 /* Create a type for a C++ namespace. */
17374 static struct type
*
17375 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17377 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17378 const char *previous_prefix
, *name
;
17382 /* For extensions, reuse the type of the original namespace. */
17383 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17385 struct die_info
*ext_die
;
17386 struct dwarf2_cu
*ext_cu
= cu
;
17388 ext_die
= dwarf2_extension (die
, &ext_cu
);
17389 type
= read_type_die (ext_die
, ext_cu
);
17391 /* EXT_CU may not be the same as CU.
17392 Ensure TYPE is recorded with CU in die_type_hash. */
17393 return set_die_type (die
, type
, cu
);
17396 name
= namespace_name (die
, &is_anonymous
, cu
);
17398 /* Now build the name of the current namespace. */
17400 previous_prefix
= determine_prefix (die
, cu
);
17401 if (previous_prefix
[0] != '\0')
17402 name
= typename_concat (&objfile
->objfile_obstack
,
17403 previous_prefix
, name
, 0, cu
);
17405 /* Create the type. */
17406 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17408 return set_die_type (die
, type
, cu
);
17411 /* Read a namespace scope. */
17414 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17416 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17419 /* Add a symbol associated to this if we haven't seen the namespace
17420 before. Also, add a using directive if it's an anonymous
17423 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17427 type
= read_type_die (die
, cu
);
17428 new_symbol (die
, type
, cu
);
17430 namespace_name (die
, &is_anonymous
, cu
);
17433 const char *previous_prefix
= determine_prefix (die
, cu
);
17435 std::vector
<const char *> excludes
;
17436 add_using_directive (using_directives (cu
),
17437 previous_prefix
, type
->name (), NULL
,
17438 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17442 if (die
->child
!= NULL
)
17444 struct die_info
*child_die
= die
->child
;
17446 while (child_die
&& child_die
->tag
)
17448 process_die (child_die
, cu
);
17449 child_die
= child_die
->sibling
;
17454 /* Read a Fortran module as type. This DIE can be only a declaration used for
17455 imported module. Still we need that type as local Fortran "use ... only"
17456 declaration imports depend on the created type in determine_prefix. */
17458 static struct type
*
17459 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17461 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17462 const char *module_name
;
17465 module_name
= dwarf2_name (die
, cu
);
17466 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17468 return set_die_type (die
, type
, cu
);
17471 /* Read a Fortran module. */
17474 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17476 struct die_info
*child_die
= die
->child
;
17479 type
= read_type_die (die
, cu
);
17480 new_symbol (die
, type
, cu
);
17482 while (child_die
&& child_die
->tag
)
17484 process_die (child_die
, cu
);
17485 child_die
= child_die
->sibling
;
17489 /* Return the name of the namespace represented by DIE. Set
17490 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17493 static const char *
17494 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17496 struct die_info
*current_die
;
17497 const char *name
= NULL
;
17499 /* Loop through the extensions until we find a name. */
17501 for (current_die
= die
;
17502 current_die
!= NULL
;
17503 current_die
= dwarf2_extension (die
, &cu
))
17505 /* We don't use dwarf2_name here so that we can detect the absence
17506 of a name -> anonymous namespace. */
17507 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17513 /* Is it an anonymous namespace? */
17515 *is_anonymous
= (name
== NULL
);
17517 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17522 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17523 the user defined type vector. */
17525 static struct type
*
17526 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17528 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17529 struct comp_unit_head
*cu_header
= &cu
->header
;
17531 struct attribute
*attr_byte_size
;
17532 struct attribute
*attr_address_class
;
17533 int byte_size
, addr_class
;
17534 struct type
*target_type
;
17536 target_type
= die_type (die
, cu
);
17538 /* The die_type call above may have already set the type for this DIE. */
17539 type
= get_die_type (die
, cu
);
17543 type
= lookup_pointer_type (target_type
);
17545 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17546 if (attr_byte_size
)
17547 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17549 byte_size
= cu_header
->addr_size
;
17551 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17552 if (attr_address_class
)
17553 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17555 addr_class
= DW_ADDR_none
;
17557 ULONGEST alignment
= get_alignment (cu
, die
);
17559 /* If the pointer size, alignment, or address class is different
17560 than the default, create a type variant marked as such and set
17561 the length accordingly. */
17562 if (TYPE_LENGTH (type
) != byte_size
17563 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17564 && alignment
!= TYPE_RAW_ALIGN (type
))
17565 || addr_class
!= DW_ADDR_none
)
17567 if (gdbarch_address_class_type_flags_p (gdbarch
))
17569 type_instance_flags type_flags
17570 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17572 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17574 type
= make_type_with_address_space (type
, type_flags
);
17576 else if (TYPE_LENGTH (type
) != byte_size
)
17578 complaint (_("invalid pointer size %d"), byte_size
);
17580 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17582 complaint (_("Invalid DW_AT_alignment"
17583 " - DIE at %s [in module %s]"),
17584 sect_offset_str (die
->sect_off
),
17585 objfile_name (cu
->per_objfile
->objfile
));
17589 /* Should we also complain about unhandled address classes? */
17593 TYPE_LENGTH (type
) = byte_size
;
17594 set_type_align (type
, alignment
);
17595 return set_die_type (die
, type
, cu
);
17598 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17599 the user defined type vector. */
17601 static struct type
*
17602 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17605 struct type
*to_type
;
17606 struct type
*domain
;
17608 to_type
= die_type (die
, cu
);
17609 domain
= die_containing_type (die
, cu
);
17611 /* The calls above may have already set the type for this DIE. */
17612 type
= get_die_type (die
, cu
);
17616 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17617 type
= lookup_methodptr_type (to_type
);
17618 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17620 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17622 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17623 to_type
->fields (), to_type
->num_fields (),
17624 to_type
->has_varargs ());
17625 type
= lookup_methodptr_type (new_type
);
17628 type
= lookup_memberptr_type (to_type
, domain
);
17630 return set_die_type (die
, type
, cu
);
17633 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17634 the user defined type vector. */
17636 static struct type
*
17637 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17638 enum type_code refcode
)
17640 struct comp_unit_head
*cu_header
= &cu
->header
;
17641 struct type
*type
, *target_type
;
17642 struct attribute
*attr
;
17644 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17646 target_type
= die_type (die
, cu
);
17648 /* The die_type call above may have already set the type for this DIE. */
17649 type
= get_die_type (die
, cu
);
17653 type
= lookup_reference_type (target_type
, refcode
);
17654 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17655 if (attr
!= nullptr)
17657 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17661 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17663 maybe_set_alignment (cu
, die
, type
);
17664 return set_die_type (die
, type
, cu
);
17667 /* Add the given cv-qualifiers to the element type of the array. GCC
17668 outputs DWARF type qualifiers that apply to an array, not the
17669 element type. But GDB relies on the array element type to carry
17670 the cv-qualifiers. This mimics section 6.7.3 of the C99
17673 static struct type
*
17674 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17675 struct type
*base_type
, int cnst
, int voltl
)
17677 struct type
*el_type
, *inner_array
;
17679 base_type
= copy_type (base_type
);
17680 inner_array
= base_type
;
17682 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17684 TYPE_TARGET_TYPE (inner_array
) =
17685 copy_type (TYPE_TARGET_TYPE (inner_array
));
17686 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17689 el_type
= TYPE_TARGET_TYPE (inner_array
);
17690 cnst
|= TYPE_CONST (el_type
);
17691 voltl
|= TYPE_VOLATILE (el_type
);
17692 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17694 return set_die_type (die
, base_type
, cu
);
17697 static struct type
*
17698 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17700 struct type
*base_type
, *cv_type
;
17702 base_type
= die_type (die
, cu
);
17704 /* The die_type call above may have already set the type for this DIE. */
17705 cv_type
= get_die_type (die
, cu
);
17709 /* In case the const qualifier is applied to an array type, the element type
17710 is so qualified, not the array type (section 6.7.3 of C99). */
17711 if (base_type
->code () == TYPE_CODE_ARRAY
)
17712 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17714 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17715 return set_die_type (die
, cv_type
, cu
);
17718 static struct type
*
17719 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17721 struct type
*base_type
, *cv_type
;
17723 base_type
= die_type (die
, cu
);
17725 /* The die_type call above may have already set the type for this DIE. */
17726 cv_type
= get_die_type (die
, cu
);
17730 /* In case the volatile qualifier is applied to an array type, the
17731 element type is so qualified, not the array type (section 6.7.3
17733 if (base_type
->code () == TYPE_CODE_ARRAY
)
17734 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17736 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17737 return set_die_type (die
, cv_type
, cu
);
17740 /* Handle DW_TAG_restrict_type. */
17742 static struct type
*
17743 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17745 struct type
*base_type
, *cv_type
;
17747 base_type
= die_type (die
, cu
);
17749 /* The die_type call above may have already set the type for this DIE. */
17750 cv_type
= get_die_type (die
, cu
);
17754 cv_type
= make_restrict_type (base_type
);
17755 return set_die_type (die
, cv_type
, cu
);
17758 /* Handle DW_TAG_atomic_type. */
17760 static struct type
*
17761 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17763 struct type
*base_type
, *cv_type
;
17765 base_type
= die_type (die
, cu
);
17767 /* The die_type call above may have already set the type for this DIE. */
17768 cv_type
= get_die_type (die
, cu
);
17772 cv_type
= make_atomic_type (base_type
);
17773 return set_die_type (die
, cv_type
, cu
);
17776 /* Extract all information from a DW_TAG_string_type DIE and add to
17777 the user defined type vector. It isn't really a user defined type,
17778 but it behaves like one, with other DIE's using an AT_user_def_type
17779 attribute to reference it. */
17781 static struct type
*
17782 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17784 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17785 struct gdbarch
*gdbarch
= objfile
->arch ();
17786 struct type
*type
, *range_type
, *index_type
, *char_type
;
17787 struct attribute
*attr
;
17788 struct dynamic_prop prop
;
17789 bool length_is_constant
= true;
17792 /* There are a couple of places where bit sizes might be made use of
17793 when parsing a DW_TAG_string_type, however, no producer that we know
17794 of make use of these. Handling bit sizes that are a multiple of the
17795 byte size is easy enough, but what about other bit sizes? Lets deal
17796 with that problem when we have to. Warn about these attributes being
17797 unsupported, then parse the type and ignore them like we always
17799 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17800 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17802 static bool warning_printed
= false;
17803 if (!warning_printed
)
17805 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17806 "currently supported on DW_TAG_string_type."));
17807 warning_printed
= true;
17811 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17812 if (attr
!= nullptr && !attr
->form_is_constant ())
17814 /* The string length describes the location at which the length of
17815 the string can be found. The size of the length field can be
17816 specified with one of the attributes below. */
17817 struct type
*prop_type
;
17818 struct attribute
*len
17819 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17820 if (len
== nullptr)
17821 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17822 if (len
!= nullptr && len
->form_is_constant ())
17824 /* Pass 0 as the default as we know this attribute is constant
17825 and the default value will not be returned. */
17826 LONGEST sz
= len
->constant_value (0);
17827 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17831 /* If the size is not specified then we assume it is the size of
17832 an address on this target. */
17833 prop_type
= cu
->addr_sized_int_type (true);
17836 /* Convert the attribute into a dynamic property. */
17837 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17840 length_is_constant
= false;
17842 else if (attr
!= nullptr)
17844 /* This DW_AT_string_length just contains the length with no
17845 indirection. There's no need to create a dynamic property in this
17846 case. Pass 0 for the default value as we know it will not be
17847 returned in this case. */
17848 length
= attr
->constant_value (0);
17850 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17852 /* We don't currently support non-constant byte sizes for strings. */
17853 length
= attr
->constant_value (1);
17857 /* Use 1 as a fallback length if we have nothing else. */
17861 index_type
= objfile_type (objfile
)->builtin_int
;
17862 if (length_is_constant
)
17863 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17866 struct dynamic_prop low_bound
;
17868 low_bound
.set_const_val (1);
17869 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17871 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17872 type
= create_string_type (NULL
, char_type
, range_type
);
17874 return set_die_type (die
, type
, cu
);
17877 /* Assuming that DIE corresponds to a function, returns nonzero
17878 if the function is prototyped. */
17881 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17883 struct attribute
*attr
;
17885 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17886 if (attr
&& attr
->as_boolean ())
17889 /* The DWARF standard implies that the DW_AT_prototyped attribute
17890 is only meaningful for C, but the concept also extends to other
17891 languages that allow unprototyped functions (Eg: Objective C).
17892 For all other languages, assume that functions are always
17894 if (cu
->language
!= language_c
17895 && cu
->language
!= language_objc
17896 && cu
->language
!= language_opencl
)
17899 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17900 prototyped and unprototyped functions; default to prototyped,
17901 since that is more common in modern code (and RealView warns
17902 about unprototyped functions). */
17903 if (producer_is_realview (cu
->producer
))
17909 /* Handle DIES due to C code like:
17913 int (*funcp)(int a, long l);
17917 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17919 static struct type
*
17920 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17922 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17923 struct type
*type
; /* Type that this function returns. */
17924 struct type
*ftype
; /* Function that returns above type. */
17925 struct attribute
*attr
;
17927 type
= die_type (die
, cu
);
17929 /* The die_type call above may have already set the type for this DIE. */
17930 ftype
= get_die_type (die
, cu
);
17934 ftype
= lookup_function_type (type
);
17936 if (prototyped_function_p (die
, cu
))
17937 ftype
->set_is_prototyped (true);
17939 /* Store the calling convention in the type if it's available in
17940 the subroutine die. Otherwise set the calling convention to
17941 the default value DW_CC_normal. */
17942 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17943 if (attr
!= nullptr
17944 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17945 TYPE_CALLING_CONVENTION (ftype
)
17946 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17947 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17948 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17950 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17952 /* Record whether the function returns normally to its caller or not
17953 if the DWARF producer set that information. */
17954 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17955 if (attr
&& attr
->as_boolean ())
17956 TYPE_NO_RETURN (ftype
) = 1;
17958 /* We need to add the subroutine type to the die immediately so
17959 we don't infinitely recurse when dealing with parameters
17960 declared as the same subroutine type. */
17961 set_die_type (die
, ftype
, cu
);
17963 if (die
->child
!= NULL
)
17965 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17966 struct die_info
*child_die
;
17967 int nparams
, iparams
;
17969 /* Count the number of parameters.
17970 FIXME: GDB currently ignores vararg functions, but knows about
17971 vararg member functions. */
17973 child_die
= die
->child
;
17974 while (child_die
&& child_die
->tag
)
17976 if (child_die
->tag
== DW_TAG_formal_parameter
)
17978 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17979 ftype
->set_has_varargs (true);
17981 child_die
= child_die
->sibling
;
17984 /* Allocate storage for parameters and fill them in. */
17985 ftype
->set_num_fields (nparams
);
17987 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17989 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17990 even if we error out during the parameters reading below. */
17991 for (iparams
= 0; iparams
< nparams
; iparams
++)
17992 ftype
->field (iparams
).set_type (void_type
);
17995 child_die
= die
->child
;
17996 while (child_die
&& child_die
->tag
)
17998 if (child_die
->tag
== DW_TAG_formal_parameter
)
18000 struct type
*arg_type
;
18002 /* DWARF version 2 has no clean way to discern C++
18003 static and non-static member functions. G++ helps
18004 GDB by marking the first parameter for non-static
18005 member functions (which is the this pointer) as
18006 artificial. We pass this information to
18007 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
18009 DWARF version 3 added DW_AT_object_pointer, which GCC
18010 4.5 does not yet generate. */
18011 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
18012 if (attr
!= nullptr)
18013 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
18015 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
18016 arg_type
= die_type (child_die
, cu
);
18018 /* RealView does not mark THIS as const, which the testsuite
18019 expects. GCC marks THIS as const in method definitions,
18020 but not in the class specifications (GCC PR 43053). */
18021 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
18022 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
18025 struct dwarf2_cu
*arg_cu
= cu
;
18026 const char *name
= dwarf2_name (child_die
, cu
);
18028 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
18029 if (attr
!= nullptr)
18031 /* If the compiler emits this, use it. */
18032 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
18035 else if (name
&& strcmp (name
, "this") == 0)
18036 /* Function definitions will have the argument names. */
18038 else if (name
== NULL
&& iparams
== 0)
18039 /* Declarations may not have the names, so like
18040 elsewhere in GDB, assume an artificial first
18041 argument is "this". */
18045 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
18049 ftype
->field (iparams
).set_type (arg_type
);
18052 child_die
= child_die
->sibling
;
18059 static struct type
*
18060 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
18062 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18063 const char *name
= NULL
;
18064 struct type
*this_type
, *target_type
;
18066 name
= dwarf2_full_name (NULL
, die
, cu
);
18067 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
18068 this_type
->set_target_is_stub (true);
18069 set_die_type (die
, this_type
, cu
);
18070 target_type
= die_type (die
, cu
);
18071 if (target_type
!= this_type
)
18072 TYPE_TARGET_TYPE (this_type
) = target_type
;
18075 /* Self-referential typedefs are, it seems, not allowed by the DWARF
18076 spec and cause infinite loops in GDB. */
18077 complaint (_("Self-referential DW_TAG_typedef "
18078 "- DIE at %s [in module %s]"),
18079 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
18080 TYPE_TARGET_TYPE (this_type
) = NULL
;
18084 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
18085 anonymous typedefs, which is, strictly speaking, invalid DWARF.
18086 Handle these by just returning the target type, rather than
18087 constructing an anonymous typedef type and trying to handle this
18089 set_die_type (die
, target_type
, cu
);
18090 return target_type
;
18095 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
18096 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
18098 If the numerator and/or numerator attribute is missing,
18099 a complaint is filed, and NUMERATOR and DENOMINATOR are left
18103 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
18104 LONGEST
*numerator
, LONGEST
*denominator
)
18106 struct attribute
*num_attr
, *denom_attr
;
18108 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
18109 if (num_attr
== nullptr)
18110 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
18111 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18113 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
18114 if (denom_attr
== nullptr)
18115 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
18116 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18118 if (num_attr
== nullptr || denom_attr
== nullptr)
18121 *numerator
= num_attr
->constant_value (1);
18122 *denominator
= denom_attr
->constant_value (1);
18125 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
18126 rational constant, rather than a signed one.
18128 If the rational constant has a negative value, a complaint
18129 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
18132 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
18133 struct dwarf2_cu
*cu
,
18134 ULONGEST
*numerator
,
18135 ULONGEST
*denominator
)
18137 LONGEST num
= 1, denom
= 1;
18139 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
18140 if (num
< 0 && denom
< 0)
18147 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
18149 sect_offset_str (die
->sect_off
));
18152 else if (denom
< 0)
18154 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
18156 sect_offset_str (die
->sect_off
));
18161 *denominator
= denom
;
18164 /* Assuming DIE corresponds to a fixed point type, finish the creation
18165 of the corresponding TYPE by setting its type-specific data.
18166 CU is the DIE's CU. */
18169 finish_fixed_point_type (struct type
*type
, struct die_info
*die
,
18170 struct dwarf2_cu
*cu
)
18172 struct attribute
*attr
;
18173 /* Numerator and denominator of our fixed-point type's scaling factor.
18174 The default is a scaling factor of 1, which we use as a fallback
18175 when we are not able to decode it (problem with the debugging info,
18176 unsupported forms, bug in GDB, etc...). Using that as the default
18177 allows us to at least print the unscaled value, which might still
18178 be useful to a user. */
18179 ULONGEST scale_num
= 1;
18180 ULONGEST scale_denom
= 1;
18182 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
18183 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
18185 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
18187 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
18189 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18191 if (attr
== nullptr)
18193 /* Scaling factor not found. Assume a scaling factor of 1,
18194 and hope for the best. At least the user will be able to see
18195 the encoded value. */
18196 complaint (_("no scale found for fixed-point type (DIE at %s)"),
18197 sect_offset_str (die
->sect_off
));
18199 else if (attr
->name
== DW_AT_binary_scale
)
18201 LONGEST scale_exp
= attr
->constant_value (0);
18202 ULONGEST
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18204 *num_or_denom
= 1 << std::abs (scale_exp
);
18206 else if (attr
->name
== DW_AT_decimal_scale
)
18208 LONGEST scale_exp
= attr
->constant_value (0);
18209 ULONGEST
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18211 *num_or_denom
= uinteger_pow (10, std::abs (scale_exp
));
18213 else if (attr
->name
== DW_AT_small
)
18215 struct die_info
*scale_die
;
18216 struct dwarf2_cu
*scale_cu
= cu
;
18218 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
18219 if (scale_die
->tag
== DW_TAG_constant
)
18220 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
18221 &scale_num
, &scale_denom
);
18223 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
18225 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18229 complaint (_("unsupported scale attribute %s for fixed-point type"
18231 dwarf_attr_name (attr
->name
),
18232 sect_offset_str (die
->sect_off
));
18235 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
18237 gdb_mpz
tmp_z (scale_num
);
18238 mpz_set (mpq_numref (scaling_factor
.val
), tmp_z
.val
);
18240 tmp_z
= scale_denom
;
18241 mpz_set (mpq_denref (scaling_factor
.val
), tmp_z
.val
);
18243 mpq_canonicalize (scaling_factor
.val
);
18246 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
18247 (which may be different from NAME) to the architecture back-end to allow
18248 it to guess the correct format if necessary. */
18250 static struct type
*
18251 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
18252 const char *name_hint
, enum bfd_endian byte_order
)
18254 struct gdbarch
*gdbarch
= objfile
->arch ();
18255 const struct floatformat
**format
;
18258 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
18260 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
18262 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18267 /* Allocate an integer type of size BITS and name NAME. */
18269 static struct type
*
18270 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
18271 int bits
, int unsigned_p
, const char *name
)
18275 /* Versions of Intel's C Compiler generate an integer type called "void"
18276 instead of using DW_TAG_unspecified_type. This has been seen on
18277 at least versions 14, 17, and 18. */
18278 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18279 && strcmp (name
, "void") == 0)
18280 type
= objfile_type (objfile
)->builtin_void
;
18282 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18287 /* Return true if DIE has a DW_AT_small attribute whose value is
18288 a constant rational, where both the numerator and denominator
18291 CU is the DIE's Compilation Unit. */
18294 has_zero_over_zero_small_attribute (struct die_info
*die
,
18295 struct dwarf2_cu
*cu
)
18297 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18298 if (attr
== nullptr)
18301 struct dwarf2_cu
*scale_cu
= cu
;
18302 struct die_info
*scale_die
18303 = follow_die_ref (die
, attr
, &scale_cu
);
18305 if (scale_die
->tag
!= DW_TAG_constant
)
18308 LONGEST num
= 1, denom
= 1;
18309 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18310 return (num
== 0 && denom
== 0);
18313 /* Initialise and return a floating point type of size BITS suitable for
18314 use as a component of a complex number. The NAME_HINT is passed through
18315 when initialising the floating point type and is the name of the complex
18318 As DWARF doesn't currently provide an explicit name for the components
18319 of a complex number, but it can be helpful to have these components
18320 named, we try to select a suitable name based on the size of the
18322 static struct type
*
18323 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18324 struct objfile
*objfile
,
18325 int bits
, const char *name_hint
,
18326 enum bfd_endian byte_order
)
18328 gdbarch
*gdbarch
= objfile
->arch ();
18329 struct type
*tt
= nullptr;
18331 /* Try to find a suitable floating point builtin type of size BITS.
18332 We're going to use the name of this type as the name for the complex
18333 target type that we are about to create. */
18334 switch (cu
->language
)
18336 case language_fortran
:
18340 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18343 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18345 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18347 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18355 tt
= builtin_type (gdbarch
)->builtin_float
;
18358 tt
= builtin_type (gdbarch
)->builtin_double
;
18360 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18362 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18368 /* If the type we found doesn't match the size we were looking for, then
18369 pretend we didn't find a type at all, the complex target type we
18370 create will then be nameless. */
18371 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18374 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18375 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18378 /* Find a representation of a given base type and install
18379 it in the TYPE field of the die. */
18381 static struct type
*
18382 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18384 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18386 struct attribute
*attr
;
18387 int encoding
= 0, bits
= 0;
18391 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18392 if (attr
!= nullptr && attr
->form_is_constant ())
18393 encoding
= attr
->constant_value (0);
18394 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18395 if (attr
!= nullptr)
18396 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18397 name
= dwarf2_name (die
, cu
);
18399 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18401 arch
= objfile
->arch ();
18402 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18404 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18405 if (attr
!= nullptr && attr
->form_is_constant ())
18407 int endianity
= attr
->constant_value (0);
18412 byte_order
= BFD_ENDIAN_BIG
;
18414 case DW_END_little
:
18415 byte_order
= BFD_ENDIAN_LITTLE
;
18418 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18423 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18424 && cu
->language
== language_ada
18425 && has_zero_over_zero_small_attribute (die
, cu
))
18427 /* brobecker/2018-02-24: This is a fixed point type for which
18428 the scaling factor is represented as fraction whose value
18429 does not make sense (zero divided by zero), so we should
18430 normally never see these. However, there is a small category
18431 of fixed point types for which GNAT is unable to provide
18432 the scaling factor via the standard DWARF mechanisms, and
18433 for which the info is provided via the GNAT encodings instead.
18434 This is likely what this DIE is about.
18436 Ideally, GNAT should be declaring this type the same way
18437 it declares other fixed point types when using the legacy
18438 GNAT encoding, which is to use a simple signed or unsigned
18439 base type. A report to the GNAT team has been created to
18440 look into it. In the meantime, pretend this type is a simple
18441 signed or unsigned integral, rather than a fixed point type,
18442 to avoid any confusion later on as to how to process this type. */
18443 encoding
= (encoding
== DW_ATE_signed_fixed
18445 : DW_ATE_unsigned
);
18450 case DW_ATE_address
:
18451 /* Turn DW_ATE_address into a void * pointer. */
18452 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18453 type
= init_pointer_type (objfile
, bits
, name
, type
);
18455 case DW_ATE_boolean
:
18456 type
= init_boolean_type (objfile
, bits
, 1, name
);
18458 case DW_ATE_complex_float
:
18459 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18461 if (type
->code () == TYPE_CODE_ERROR
)
18463 if (name
== nullptr)
18465 struct obstack
*obstack
18466 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18467 name
= obconcat (obstack
, "_Complex ", type
->name (),
18470 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18473 type
= init_complex_type (name
, type
);
18475 case DW_ATE_decimal_float
:
18476 type
= init_decfloat_type (objfile
, bits
, name
);
18479 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18481 case DW_ATE_signed
:
18482 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18484 case DW_ATE_unsigned
:
18485 if (cu
->language
== language_fortran
18487 && startswith (name
, "character("))
18488 type
= init_character_type (objfile
, bits
, 1, name
);
18490 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18492 case DW_ATE_signed_char
:
18493 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18494 || cu
->language
== language_pascal
18495 || cu
->language
== language_fortran
)
18496 type
= init_character_type (objfile
, bits
, 0, name
);
18498 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18500 case DW_ATE_unsigned_char
:
18501 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18502 || cu
->language
== language_pascal
18503 || cu
->language
== language_fortran
18504 || cu
->language
== language_rust
)
18505 type
= init_character_type (objfile
, bits
, 1, name
);
18507 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18512 type
= builtin_type (arch
)->builtin_char16
;
18513 else if (bits
== 32)
18514 type
= builtin_type (arch
)->builtin_char32
;
18517 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18519 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18521 return set_die_type (die
, type
, cu
);
18524 case DW_ATE_signed_fixed
:
18525 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18526 finish_fixed_point_type (type
, die
, cu
);
18528 case DW_ATE_unsigned_fixed
:
18529 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18530 finish_fixed_point_type (type
, die
, cu
);
18534 complaint (_("unsupported DW_AT_encoding: '%s'"),
18535 dwarf_type_encoding_name (encoding
));
18536 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18540 if (name
&& strcmp (name
, "char") == 0)
18541 type
->set_has_no_signedness (true);
18543 maybe_set_alignment (cu
, die
, type
);
18545 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18547 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18549 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18550 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18552 unsigned real_bit_size
= attr
->as_unsigned ();
18553 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18554 /* Only use the attributes if they make sense together. */
18555 if (attr
== nullptr
18556 || (attr
->as_unsigned () + real_bit_size
18557 <= 8 * TYPE_LENGTH (type
)))
18559 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18561 if (attr
!= nullptr)
18562 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18563 = attr
->as_unsigned ();
18568 return set_die_type (die
, type
, cu
);
18571 /* Parse dwarf attribute if it's a block, reference or constant and put the
18572 resulting value of the attribute into struct bound_prop.
18573 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18576 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18577 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18578 struct type
*default_type
)
18580 struct dwarf2_property_baton
*baton
;
18581 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18582 struct objfile
*objfile
= per_objfile
->objfile
;
18583 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18585 gdb_assert (default_type
!= NULL
);
18587 if (attr
== NULL
|| prop
== NULL
)
18590 if (attr
->form_is_block ())
18592 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18593 baton
->property_type
= default_type
;
18594 baton
->locexpr
.per_cu
= cu
->per_cu
;
18595 baton
->locexpr
.per_objfile
= per_objfile
;
18597 struct dwarf_block
*block
= attr
->as_block ();
18598 baton
->locexpr
.size
= block
->size
;
18599 baton
->locexpr
.data
= block
->data
;
18600 switch (attr
->name
)
18602 case DW_AT_string_length
:
18603 baton
->locexpr
.is_reference
= true;
18606 baton
->locexpr
.is_reference
= false;
18610 prop
->set_locexpr (baton
);
18611 gdb_assert (prop
->baton () != NULL
);
18613 else if (attr
->form_is_ref ())
18615 struct dwarf2_cu
*target_cu
= cu
;
18616 struct die_info
*target_die
;
18617 struct attribute
*target_attr
;
18619 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18620 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18621 if (target_attr
== NULL
)
18622 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18624 if (target_attr
== NULL
)
18627 switch (target_attr
->name
)
18629 case DW_AT_location
:
18630 if (target_attr
->form_is_section_offset ())
18632 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18633 baton
->property_type
= die_type (target_die
, target_cu
);
18634 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18635 prop
->set_loclist (baton
);
18636 gdb_assert (prop
->baton () != NULL
);
18638 else if (target_attr
->form_is_block ())
18640 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18641 baton
->property_type
= die_type (target_die
, target_cu
);
18642 baton
->locexpr
.per_cu
= cu
->per_cu
;
18643 baton
->locexpr
.per_objfile
= per_objfile
;
18644 struct dwarf_block
*block
= target_attr
->as_block ();
18645 baton
->locexpr
.size
= block
->size
;
18646 baton
->locexpr
.data
= block
->data
;
18647 baton
->locexpr
.is_reference
= true;
18648 prop
->set_locexpr (baton
);
18649 gdb_assert (prop
->baton () != NULL
);
18653 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18654 "dynamic property");
18658 case DW_AT_data_member_location
:
18662 if (!handle_data_member_location (target_die
, target_cu
,
18666 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18667 baton
->property_type
= read_type_die (target_die
->parent
,
18669 baton
->offset_info
.offset
= offset
;
18670 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18671 prop
->set_addr_offset (baton
);
18676 else if (attr
->form_is_constant ())
18677 prop
->set_const_val (attr
->constant_value (0));
18680 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18681 dwarf2_name (die
, cu
));
18691 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18693 struct type
*int_type
;
18695 /* Helper macro to examine the various builtin types. */
18696 #define TRY_TYPE(F) \
18697 int_type = (unsigned_p \
18698 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18699 : objfile_type (objfile)->builtin_ ## F); \
18700 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18707 TRY_TYPE (long_long
);
18711 gdb_assert_not_reached ("unable to find suitable integer type");
18717 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
18719 int addr_size
= this->per_cu
->addr_size ();
18720 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
18723 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18724 present (which is valid) then compute the default type based on the
18725 compilation units address size. */
18727 static struct type
*
18728 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18730 struct type
*index_type
= die_type (die
, cu
);
18732 /* Dwarf-2 specifications explicitly allows to create subrange types
18733 without specifying a base type.
18734 In that case, the base type must be set to the type of
18735 the lower bound, upper bound or count, in that order, if any of these
18736 three attributes references an object that has a type.
18737 If no base type is found, the Dwarf-2 specifications say that
18738 a signed integer type of size equal to the size of an address should
18740 For the following C code: `extern char gdb_int [];'
18741 GCC produces an empty range DIE.
18742 FIXME: muller/2010-05-28: Possible references to object for low bound,
18743 high bound or count are not yet handled by this code. */
18744 if (index_type
->code () == TYPE_CODE_VOID
)
18745 index_type
= cu
->addr_sized_int_type (false);
18750 /* Read the given DW_AT_subrange DIE. */
18752 static struct type
*
18753 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18755 struct type
*base_type
, *orig_base_type
;
18756 struct type
*range_type
;
18757 struct attribute
*attr
;
18758 struct dynamic_prop low
, high
;
18759 int low_default_is_valid
;
18760 int high_bound_is_count
= 0;
18762 ULONGEST negative_mask
;
18764 orig_base_type
= read_subrange_index_type (die
, cu
);
18766 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18767 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18768 creating the range type, but we use the result of check_typedef
18769 when examining properties of the type. */
18770 base_type
= check_typedef (orig_base_type
);
18772 /* The die_type call above may have already set the type for this DIE. */
18773 range_type
= get_die_type (die
, cu
);
18777 high
.set_const_val (0);
18779 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18780 omitting DW_AT_lower_bound. */
18781 switch (cu
->language
)
18784 case language_cplus
:
18785 low
.set_const_val (0);
18786 low_default_is_valid
= 1;
18788 case language_fortran
:
18789 low
.set_const_val (1);
18790 low_default_is_valid
= 1;
18793 case language_objc
:
18794 case language_rust
:
18795 low
.set_const_val (0);
18796 low_default_is_valid
= (cu
->header
.version
>= 4);
18800 case language_pascal
:
18801 low
.set_const_val (1);
18802 low_default_is_valid
= (cu
->header
.version
>= 4);
18805 low
.set_const_val (0);
18806 low_default_is_valid
= 0;
18810 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18811 if (attr
!= nullptr)
18812 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18813 else if (!low_default_is_valid
)
18814 complaint (_("Missing DW_AT_lower_bound "
18815 "- DIE at %s [in module %s]"),
18816 sect_offset_str (die
->sect_off
),
18817 objfile_name (cu
->per_objfile
->objfile
));
18819 struct attribute
*attr_ub
, *attr_count
;
18820 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18821 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18823 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18824 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18826 /* If bounds are constant do the final calculation here. */
18827 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18828 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18830 high_bound_is_count
= 1;
18834 if (attr_ub
!= NULL
)
18835 complaint (_("Unresolved DW_AT_upper_bound "
18836 "- DIE at %s [in module %s]"),
18837 sect_offset_str (die
->sect_off
),
18838 objfile_name (cu
->per_objfile
->objfile
));
18839 if (attr_count
!= NULL
)
18840 complaint (_("Unresolved DW_AT_count "
18841 "- DIE at %s [in module %s]"),
18842 sect_offset_str (die
->sect_off
),
18843 objfile_name (cu
->per_objfile
->objfile
));
18848 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18849 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18850 bias
= bias_attr
->constant_value (0);
18852 /* Normally, the DWARF producers are expected to use a signed
18853 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18854 But this is unfortunately not always the case, as witnessed
18855 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18856 is used instead. To work around that ambiguity, we treat
18857 the bounds as signed, and thus sign-extend their values, when
18858 the base type is signed. */
18860 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18861 if (low
.kind () == PROP_CONST
18862 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18863 low
.set_const_val (low
.const_val () | negative_mask
);
18864 if (high
.kind () == PROP_CONST
18865 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18866 high
.set_const_val (high
.const_val () | negative_mask
);
18868 /* Check for bit and byte strides. */
18869 struct dynamic_prop byte_stride_prop
;
18870 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18871 if (attr_byte_stride
!= nullptr)
18873 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18874 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18878 struct dynamic_prop bit_stride_prop
;
18879 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18880 if (attr_bit_stride
!= nullptr)
18882 /* It only makes sense to have either a bit or byte stride. */
18883 if (attr_byte_stride
!= nullptr)
18885 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18886 "- DIE at %s [in module %s]"),
18887 sect_offset_str (die
->sect_off
),
18888 objfile_name (cu
->per_objfile
->objfile
));
18889 attr_bit_stride
= nullptr;
18893 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18894 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18899 if (attr_byte_stride
!= nullptr
18900 || attr_bit_stride
!= nullptr)
18902 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18903 struct dynamic_prop
*stride
18904 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18907 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18908 &high
, bias
, stride
, byte_stride_p
);
18911 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18913 if (high_bound_is_count
)
18914 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18916 /* Ada expects an empty array on no boundary attributes. */
18917 if (attr
== NULL
&& cu
->language
!= language_ada
)
18918 range_type
->bounds ()->high
.set_undefined ();
18920 name
= dwarf2_name (die
, cu
);
18922 range_type
->set_name (name
);
18924 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18925 if (attr
!= nullptr)
18926 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18928 maybe_set_alignment (cu
, die
, range_type
);
18930 set_die_type (die
, range_type
, cu
);
18932 /* set_die_type should be already done. */
18933 set_descriptive_type (range_type
, die
, cu
);
18938 static struct type
*
18939 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18943 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18944 type
->set_name (dwarf2_name (die
, cu
));
18946 /* In Ada, an unspecified type is typically used when the description
18947 of the type is deferred to a different unit. When encountering
18948 such a type, we treat it as a stub, and try to resolve it later on,
18950 if (cu
->language
== language_ada
)
18951 type
->set_is_stub (true);
18953 return set_die_type (die
, type
, cu
);
18956 /* Read a single die and all its descendents. Set the die's sibling
18957 field to NULL; set other fields in the die correctly, and set all
18958 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18959 location of the info_ptr after reading all of those dies. PARENT
18960 is the parent of the die in question. */
18962 static struct die_info
*
18963 read_die_and_children (const struct die_reader_specs
*reader
,
18964 const gdb_byte
*info_ptr
,
18965 const gdb_byte
**new_info_ptr
,
18966 struct die_info
*parent
)
18968 struct die_info
*die
;
18969 const gdb_byte
*cur_ptr
;
18971 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18974 *new_info_ptr
= cur_ptr
;
18977 store_in_ref_table (die
, reader
->cu
);
18979 if (die
->has_children
)
18980 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18984 *new_info_ptr
= cur_ptr
;
18987 die
->sibling
= NULL
;
18988 die
->parent
= parent
;
18992 /* Read a die, all of its descendents, and all of its siblings; set
18993 all of the fields of all of the dies correctly. Arguments are as
18994 in read_die_and_children. */
18996 static struct die_info
*
18997 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18998 const gdb_byte
*info_ptr
,
18999 const gdb_byte
**new_info_ptr
,
19000 struct die_info
*parent
)
19002 struct die_info
*first_die
, *last_sibling
;
19003 const gdb_byte
*cur_ptr
;
19005 cur_ptr
= info_ptr
;
19006 first_die
= last_sibling
= NULL
;
19010 struct die_info
*die
19011 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
19015 *new_info_ptr
= cur_ptr
;
19022 last_sibling
->sibling
= die
;
19024 last_sibling
= die
;
19028 /* Read a die, all of its descendents, and all of its siblings; set
19029 all of the fields of all of the dies correctly. Arguments are as
19030 in read_die_and_children.
19031 This the main entry point for reading a DIE and all its children. */
19033 static struct die_info
*
19034 read_die_and_siblings (const struct die_reader_specs
*reader
,
19035 const gdb_byte
*info_ptr
,
19036 const gdb_byte
**new_info_ptr
,
19037 struct die_info
*parent
)
19039 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
19040 new_info_ptr
, parent
);
19042 if (dwarf_die_debug
)
19044 fprintf_unfiltered (gdb_stdlog
,
19045 "Read die from %s@0x%x of %s:\n",
19046 reader
->die_section
->get_name (),
19047 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19048 bfd_get_filename (reader
->abfd
));
19049 dump_die (die
, dwarf_die_debug
);
19055 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
19057 The caller is responsible for filling in the extra attributes
19058 and updating (*DIEP)->num_attrs.
19059 Set DIEP to point to a newly allocated die with its information,
19060 except for its child, sibling, and parent fields. */
19062 static const gdb_byte
*
19063 read_full_die_1 (const struct die_reader_specs
*reader
,
19064 struct die_info
**diep
, const gdb_byte
*info_ptr
,
19065 int num_extra_attrs
)
19067 unsigned int abbrev_number
, bytes_read
, i
;
19068 struct abbrev_info
*abbrev
;
19069 struct die_info
*die
;
19070 struct dwarf2_cu
*cu
= reader
->cu
;
19071 bfd
*abfd
= reader
->abfd
;
19073 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
19074 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19075 info_ptr
+= bytes_read
;
19076 if (!abbrev_number
)
19082 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
19084 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
19086 bfd_get_filename (abfd
));
19088 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
19089 die
->sect_off
= sect_off
;
19090 die
->tag
= abbrev
->tag
;
19091 die
->abbrev
= abbrev_number
;
19092 die
->has_children
= abbrev
->has_children
;
19094 /* Make the result usable.
19095 The caller needs to update num_attrs after adding the extra
19097 die
->num_attrs
= abbrev
->num_attrs
;
19099 bool any_need_reprocess
= false;
19100 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19102 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
19104 if (die
->attrs
[i
].requires_reprocessing_p ())
19105 any_need_reprocess
= true;
19108 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
19109 if (attr
!= nullptr && attr
->form_is_unsigned ())
19110 cu
->str_offsets_base
= attr
->as_unsigned ();
19112 attr
= die
->attr (DW_AT_loclists_base
);
19113 if (attr
!= nullptr)
19114 cu
->loclist_base
= attr
->as_unsigned ();
19116 auto maybe_addr_base
= die
->addr_base ();
19117 if (maybe_addr_base
.has_value ())
19118 cu
->addr_base
= *maybe_addr_base
;
19120 attr
= die
->attr (DW_AT_rnglists_base
);
19121 if (attr
!= nullptr)
19122 cu
->ranges_base
= attr
->as_unsigned ();
19124 if (any_need_reprocess
)
19126 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19128 if (die
->attrs
[i
].requires_reprocessing_p ())
19129 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
19136 /* Read a die and all its attributes.
19137 Set DIEP to point to a newly allocated die with its information,
19138 except for its child, sibling, and parent fields. */
19140 static const gdb_byte
*
19141 read_full_die (const struct die_reader_specs
*reader
,
19142 struct die_info
**diep
, const gdb_byte
*info_ptr
)
19144 const gdb_byte
*result
;
19146 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
19148 if (dwarf_die_debug
)
19150 fprintf_unfiltered (gdb_stdlog
,
19151 "Read die from %s@0x%x of %s:\n",
19152 reader
->die_section
->get_name (),
19153 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19154 bfd_get_filename (reader
->abfd
));
19155 dump_die (*diep
, dwarf_die_debug
);
19162 /* Returns nonzero if TAG represents a type that we might generate a partial
19166 is_type_tag_for_partial (int tag
, enum language lang
)
19171 /* Some types that would be reasonable to generate partial symbols for,
19172 that we don't at present. Note that normally this does not
19173 matter, mainly because C compilers don't give names to these
19174 types, but instead emit DW_TAG_typedef. */
19175 case DW_TAG_file_type
:
19176 case DW_TAG_ptr_to_member_type
:
19177 case DW_TAG_set_type
:
19178 case DW_TAG_string_type
:
19179 case DW_TAG_subroutine_type
:
19182 /* GNAT may emit an array with a name, but no typedef, so we
19183 need to make a symbol in this case. */
19184 case DW_TAG_array_type
:
19185 return lang
== language_ada
;
19187 case DW_TAG_base_type
:
19188 case DW_TAG_class_type
:
19189 case DW_TAG_interface_type
:
19190 case DW_TAG_enumeration_type
:
19191 case DW_TAG_structure_type
:
19192 case DW_TAG_subrange_type
:
19193 case DW_TAG_typedef
:
19194 case DW_TAG_union_type
:
19201 /* Load all DIEs that are interesting for partial symbols into memory. */
19203 static struct partial_die_info
*
19204 load_partial_dies (const struct die_reader_specs
*reader
,
19205 const gdb_byte
*info_ptr
, int building_psymtab
)
19207 struct dwarf2_cu
*cu
= reader
->cu
;
19208 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19209 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
19210 unsigned int bytes_read
;
19211 unsigned int load_all
= 0;
19212 int nesting_level
= 1;
19217 gdb_assert (cu
->per_cu
!= NULL
);
19218 if (cu
->per_cu
->load_all_dies
)
19222 = htab_create_alloc_ex (cu
->header
.length
/ 12,
19226 &cu
->comp_unit_obstack
,
19227 hashtab_obstack_allocate
,
19228 dummy_obstack_deallocate
);
19232 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
19234 /* A NULL abbrev means the end of a series of children. */
19235 if (abbrev
== NULL
)
19237 if (--nesting_level
== 0)
19240 info_ptr
+= bytes_read
;
19241 last_die
= parent_die
;
19242 parent_die
= parent_die
->die_parent
;
19246 /* Check for template arguments. We never save these; if
19247 they're seen, we just mark the parent, and go on our way. */
19248 if (parent_die
!= NULL
19249 && cu
->language
== language_cplus
19250 && (abbrev
->tag
== DW_TAG_template_type_param
19251 || abbrev
->tag
== DW_TAG_template_value_param
))
19253 parent_die
->has_template_arguments
= 1;
19257 /* We don't need a partial DIE for the template argument. */
19258 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19263 /* We only recurse into c++ subprograms looking for template arguments.
19264 Skip their other children. */
19266 && cu
->language
== language_cplus
19267 && parent_die
!= NULL
19268 && parent_die
->tag
== DW_TAG_subprogram
19269 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19271 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19275 /* Check whether this DIE is interesting enough to save. Normally
19276 we would not be interested in members here, but there may be
19277 later variables referencing them via DW_AT_specification (for
19278 static members). */
19280 && !is_type_tag_for_partial (abbrev
->tag
, cu
->language
)
19281 && abbrev
->tag
!= DW_TAG_constant
19282 && abbrev
->tag
!= DW_TAG_enumerator
19283 && abbrev
->tag
!= DW_TAG_subprogram
19284 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19285 && abbrev
->tag
!= DW_TAG_lexical_block
19286 && abbrev
->tag
!= DW_TAG_variable
19287 && abbrev
->tag
!= DW_TAG_namespace
19288 && abbrev
->tag
!= DW_TAG_module
19289 && abbrev
->tag
!= DW_TAG_member
19290 && abbrev
->tag
!= DW_TAG_imported_unit
19291 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19293 /* Otherwise we skip to the next sibling, if any. */
19294 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19298 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19301 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19303 /* This two-pass algorithm for processing partial symbols has a
19304 high cost in cache pressure. Thus, handle some simple cases
19305 here which cover the majority of C partial symbols. DIEs
19306 which neither have specification tags in them, nor could have
19307 specification tags elsewhere pointing at them, can simply be
19308 processed and discarded.
19310 This segment is also optional; scan_partial_symbols and
19311 add_partial_symbol will handle these DIEs if we chain
19312 them in normally. When compilers which do not emit large
19313 quantities of duplicate debug information are more common,
19314 this code can probably be removed. */
19316 /* Any complete simple types at the top level (pretty much all
19317 of them, for a language without namespaces), can be processed
19319 if (parent_die
== NULL
19320 && pdi
.has_specification
== 0
19321 && pdi
.is_declaration
== 0
19322 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19323 || pdi
.tag
== DW_TAG_base_type
19324 || pdi
.tag
== DW_TAG_array_type
19325 || pdi
.tag
== DW_TAG_subrange_type
))
19327 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19328 add_partial_symbol (&pdi
, cu
);
19330 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19334 /* The exception for DW_TAG_typedef with has_children above is
19335 a workaround of GCC PR debug/47510. In the case of this complaint
19336 type_name_or_error will error on such types later.
19338 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19339 it could not find the child DIEs referenced later, this is checked
19340 above. In correct DWARF DW_TAG_typedef should have no children. */
19342 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19343 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19344 "- DIE at %s [in module %s]"),
19345 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19347 /* If we're at the second level, and we're an enumerator, and
19348 our parent has no specification (meaning possibly lives in a
19349 namespace elsewhere), then we can add the partial symbol now
19350 instead of queueing it. */
19351 if (pdi
.tag
== DW_TAG_enumerator
19352 && parent_die
!= NULL
19353 && parent_die
->die_parent
== NULL
19354 && parent_die
->tag
== DW_TAG_enumeration_type
19355 && parent_die
->has_specification
== 0)
19357 if (pdi
.raw_name
== NULL
)
19358 complaint (_("malformed enumerator DIE ignored"));
19359 else if (building_psymtab
)
19360 add_partial_symbol (&pdi
, cu
);
19362 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19366 struct partial_die_info
*part_die
19367 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19369 /* We'll save this DIE so link it in. */
19370 part_die
->die_parent
= parent_die
;
19371 part_die
->die_sibling
= NULL
;
19372 part_die
->die_child
= NULL
;
19374 if (last_die
&& last_die
== parent_die
)
19375 last_die
->die_child
= part_die
;
19377 last_die
->die_sibling
= part_die
;
19379 last_die
= part_die
;
19381 if (first_die
== NULL
)
19382 first_die
= part_die
;
19384 /* Maybe add the DIE to the hash table. Not all DIEs that we
19385 find interesting need to be in the hash table, because we
19386 also have the parent/sibling/child chains; only those that we
19387 might refer to by offset later during partial symbol reading.
19389 For now this means things that might have be the target of a
19390 DW_AT_specification, DW_AT_abstract_origin, or
19391 DW_AT_extension. DW_AT_extension will refer only to
19392 namespaces; DW_AT_abstract_origin refers to functions (and
19393 many things under the function DIE, but we do not recurse
19394 into function DIEs during partial symbol reading) and
19395 possibly variables as well; DW_AT_specification refers to
19396 declarations. Declarations ought to have the DW_AT_declaration
19397 flag. It happens that GCC forgets to put it in sometimes, but
19398 only for functions, not for types.
19400 Adding more things than necessary to the hash table is harmless
19401 except for the performance cost. Adding too few will result in
19402 wasted time in find_partial_die, when we reread the compilation
19403 unit with load_all_dies set. */
19406 || abbrev
->tag
== DW_TAG_constant
19407 || abbrev
->tag
== DW_TAG_subprogram
19408 || abbrev
->tag
== DW_TAG_variable
19409 || abbrev
->tag
== DW_TAG_namespace
19410 || part_die
->is_declaration
)
19414 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19415 to_underlying (part_die
->sect_off
),
19420 /* For some DIEs we want to follow their children (if any). For C
19421 we have no reason to follow the children of structures; for other
19422 languages we have to, so that we can get at method physnames
19423 to infer fully qualified class names, for DW_AT_specification,
19424 and for C++ template arguments. For C++, we also look one level
19425 inside functions to find template arguments (if the name of the
19426 function does not already contain the template arguments).
19428 For Ada and Fortran, we need to scan the children of subprograms
19429 and lexical blocks as well because these languages allow the
19430 definition of nested entities that could be interesting for the
19431 debugger, such as nested subprograms for instance. */
19432 if (last_die
->has_children
19434 || last_die
->tag
== DW_TAG_namespace
19435 || last_die
->tag
== DW_TAG_module
19436 || last_die
->tag
== DW_TAG_enumeration_type
19437 || (cu
->language
== language_cplus
19438 && last_die
->tag
== DW_TAG_subprogram
19439 && (last_die
->raw_name
== NULL
19440 || strchr (last_die
->raw_name
, '<') == NULL
))
19441 || (cu
->language
!= language_c
19442 && (last_die
->tag
== DW_TAG_class_type
19443 || last_die
->tag
== DW_TAG_interface_type
19444 || last_die
->tag
== DW_TAG_structure_type
19445 || last_die
->tag
== DW_TAG_union_type
))
19446 || ((cu
->language
== language_ada
19447 || cu
->language
== language_fortran
)
19448 && (last_die
->tag
== DW_TAG_subprogram
19449 || last_die
->tag
== DW_TAG_lexical_block
))))
19452 parent_die
= last_die
;
19456 /* Otherwise we skip to the next sibling, if any. */
19457 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19459 /* Back to the top, do it again. */
19463 partial_die_info::partial_die_info (sect_offset sect_off_
,
19464 struct abbrev_info
*abbrev
)
19465 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19469 /* See class definition. */
19472 partial_die_info::name (dwarf2_cu
*cu
)
19474 if (!canonical_name
&& raw_name
!= nullptr)
19476 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19477 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19478 canonical_name
= 1;
19484 /* Read a minimal amount of information into the minimal die structure.
19485 INFO_PTR should point just after the initial uleb128 of a DIE. */
19488 partial_die_info::read (const struct die_reader_specs
*reader
,
19489 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19491 struct dwarf2_cu
*cu
= reader
->cu
;
19492 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19494 int has_low_pc_attr
= 0;
19495 int has_high_pc_attr
= 0;
19496 int high_pc_relative
= 0;
19498 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19501 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19502 /* String and address offsets that need to do the reprocessing have
19503 already been read at this point, so there is no need to wait until
19504 the loop terminates to do the reprocessing. */
19505 if (attr
.requires_reprocessing_p ())
19506 read_attribute_reprocess (reader
, &attr
, tag
);
19507 /* Store the data if it is of an attribute we want to keep in a
19508 partial symbol table. */
19514 case DW_TAG_compile_unit
:
19515 case DW_TAG_partial_unit
:
19516 case DW_TAG_type_unit
:
19517 /* Compilation units have a DW_AT_name that is a filename, not
19518 a source language identifier. */
19519 case DW_TAG_enumeration_type
:
19520 case DW_TAG_enumerator
:
19521 /* These tags always have simple identifiers already; no need
19522 to canonicalize them. */
19523 canonical_name
= 1;
19524 raw_name
= attr
.as_string ();
19527 canonical_name
= 0;
19528 raw_name
= attr
.as_string ();
19532 case DW_AT_linkage_name
:
19533 case DW_AT_MIPS_linkage_name
:
19534 /* Note that both forms of linkage name might appear. We
19535 assume they will be the same, and we only store the last
19537 linkage_name
= attr
.as_string ();
19540 has_low_pc_attr
= 1;
19541 lowpc
= attr
.as_address ();
19543 case DW_AT_high_pc
:
19544 has_high_pc_attr
= 1;
19545 highpc
= attr
.as_address ();
19546 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19547 high_pc_relative
= 1;
19549 case DW_AT_location
:
19550 /* Support the .debug_loc offsets. */
19551 if (attr
.form_is_block ())
19553 d
.locdesc
= attr
.as_block ();
19555 else if (attr
.form_is_section_offset ())
19557 dwarf2_complex_location_expr_complaint ();
19561 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19562 "partial symbol information");
19565 case DW_AT_external
:
19566 is_external
= attr
.as_boolean ();
19568 case DW_AT_declaration
:
19569 is_declaration
= attr
.as_boolean ();
19574 case DW_AT_abstract_origin
:
19575 case DW_AT_specification
:
19576 case DW_AT_extension
:
19577 has_specification
= 1;
19578 spec_offset
= attr
.get_ref_die_offset ();
19579 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19580 || cu
->per_cu
->is_dwz
);
19582 case DW_AT_sibling
:
19583 /* Ignore absolute siblings, they might point outside of
19584 the current compile unit. */
19585 if (attr
.form
== DW_FORM_ref_addr
)
19586 complaint (_("ignoring absolute DW_AT_sibling"));
19589 const gdb_byte
*buffer
= reader
->buffer
;
19590 sect_offset off
= attr
.get_ref_die_offset ();
19591 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19593 if (sibling_ptr
< info_ptr
)
19594 complaint (_("DW_AT_sibling points backwards"));
19595 else if (sibling_ptr
> reader
->buffer_end
)
19596 reader
->die_section
->overflow_complaint ();
19598 sibling
= sibling_ptr
;
19601 case DW_AT_byte_size
:
19604 case DW_AT_const_value
:
19605 has_const_value
= 1;
19607 case DW_AT_calling_convention
:
19608 /* DWARF doesn't provide a way to identify a program's source-level
19609 entry point. DW_AT_calling_convention attributes are only meant
19610 to describe functions' calling conventions.
19612 However, because it's a necessary piece of information in
19613 Fortran, and before DWARF 4 DW_CC_program was the only
19614 piece of debugging information whose definition refers to
19615 a 'main program' at all, several compilers marked Fortran
19616 main programs with DW_CC_program --- even when those
19617 functions use the standard calling conventions.
19619 Although DWARF now specifies a way to provide this
19620 information, we support this practice for backward
19622 if (attr
.constant_value (0) == DW_CC_program
19623 && cu
->language
== language_fortran
)
19624 main_subprogram
= 1;
19628 LONGEST value
= attr
.constant_value (-1);
19629 if (value
== DW_INL_inlined
19630 || value
== DW_INL_declared_inlined
)
19631 may_be_inlined
= 1;
19636 if (tag
== DW_TAG_imported_unit
)
19638 d
.sect_off
= attr
.get_ref_die_offset ();
19639 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19640 || cu
->per_cu
->is_dwz
);
19644 case DW_AT_main_subprogram
:
19645 main_subprogram
= attr
.as_boolean ();
19650 /* DW_AT_rnglists_base does not apply to DIEs from the DWO
19651 skeleton. We take advantage of the fact the DW_AT_ranges
19652 does not appear in DW_TAG_compile_unit of DWO files.
19654 Attributes of the form DW_FORM_rnglistx have already had
19655 their value changed by read_rnglist_index and already
19656 include DW_AT_rnglists_base, so don't need to add the ranges
19658 int need_ranges_base
= (tag
!= DW_TAG_compile_unit
19659 && attr
.form
!= DW_FORM_rnglistx
);
19660 /* It would be nice to reuse dwarf2_get_pc_bounds here,
19661 but that requires a full DIE, so instead we just
19663 unsigned int ranges_offset
= (attr
.constant_value (0)
19664 + (need_ranges_base
19668 /* Value of the DW_AT_ranges attribute is the offset in the
19669 .debug_ranges section. */
19670 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19681 /* For Ada, if both the name and the linkage name appear, we prefer
19682 the latter. This lets "catch exception" work better, regardless
19683 of the order in which the name and linkage name were emitted.
19684 Really, though, this is just a workaround for the fact that gdb
19685 doesn't store both the name and the linkage name. */
19686 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19687 raw_name
= linkage_name
;
19689 if (high_pc_relative
)
19692 if (has_low_pc_attr
&& has_high_pc_attr
)
19694 /* When using the GNU linker, .gnu.linkonce. sections are used to
19695 eliminate duplicate copies of functions and vtables and such.
19696 The linker will arbitrarily choose one and discard the others.
19697 The AT_*_pc values for such functions refer to local labels in
19698 these sections. If the section from that file was discarded, the
19699 labels are not in the output, so the relocs get a value of 0.
19700 If this is a discarded function, mark the pc bounds as invalid,
19701 so that GDB will ignore it. */
19702 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19704 struct objfile
*objfile
= per_objfile
->objfile
;
19705 struct gdbarch
*gdbarch
= objfile
->arch ();
19707 complaint (_("DW_AT_low_pc %s is zero "
19708 "for DIE at %s [in module %s]"),
19709 paddress (gdbarch
, lowpc
),
19710 sect_offset_str (sect_off
),
19711 objfile_name (objfile
));
19713 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19714 else if (lowpc
>= highpc
)
19716 struct objfile
*objfile
= per_objfile
->objfile
;
19717 struct gdbarch
*gdbarch
= objfile
->arch ();
19719 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19720 "for DIE at %s [in module %s]"),
19721 paddress (gdbarch
, lowpc
),
19722 paddress (gdbarch
, highpc
),
19723 sect_offset_str (sect_off
),
19724 objfile_name (objfile
));
19733 /* Find a cached partial DIE at OFFSET in CU. */
19735 struct partial_die_info
*
19736 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19738 struct partial_die_info
*lookup_die
= NULL
;
19739 struct partial_die_info
part_die (sect_off
);
19741 lookup_die
= ((struct partial_die_info
*)
19742 htab_find_with_hash (partial_dies
, &part_die
,
19743 to_underlying (sect_off
)));
19748 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19749 except in the case of .debug_types DIEs which do not reference
19750 outside their CU (they do however referencing other types via
19751 DW_FORM_ref_sig8). */
19753 static const struct cu_partial_die_info
19754 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19756 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19757 struct objfile
*objfile
= per_objfile
->objfile
;
19758 struct partial_die_info
*pd
= NULL
;
19760 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19761 && cu
->header
.offset_in_cu_p (sect_off
))
19763 pd
= cu
->find_partial_die (sect_off
);
19766 /* We missed recording what we needed.
19767 Load all dies and try again. */
19771 /* TUs don't reference other CUs/TUs (except via type signatures). */
19772 if (cu
->per_cu
->is_debug_types
)
19774 error (_("Dwarf Error: Type Unit at offset %s contains"
19775 " external reference to offset %s [in module %s].\n"),
19776 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19777 bfd_get_filename (objfile
->obfd
));
19779 dwarf2_per_cu_data
*per_cu
19780 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19783 cu
= per_objfile
->get_cu (per_cu
);
19784 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19785 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19787 cu
= per_objfile
->get_cu (per_cu
);
19790 pd
= cu
->find_partial_die (sect_off
);
19793 /* If we didn't find it, and not all dies have been loaded,
19794 load them all and try again. */
19796 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
19798 cu
->per_cu
->load_all_dies
= 1;
19800 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19801 THIS_CU->cu may already be in use. So we can't just free it and
19802 replace its DIEs with the ones we read in. Instead, we leave those
19803 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19804 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19806 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19808 pd
= cu
->find_partial_die (sect_off
);
19812 error (_("Dwarf Error: Cannot not find DIE at %s [from module %s]\n"),
19813 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19817 /* See if we can figure out if the class lives in a namespace. We do
19818 this by looking for a member function; its demangled name will
19819 contain namespace info, if there is any. */
19822 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19823 struct dwarf2_cu
*cu
)
19825 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19826 what template types look like, because the demangler
19827 frequently doesn't give the same name as the debug info. We
19828 could fix this by only using the demangled name to get the
19829 prefix (but see comment in read_structure_type). */
19831 struct partial_die_info
*real_pdi
;
19832 struct partial_die_info
*child_pdi
;
19834 /* If this DIE (this DIE's specification, if any) has a parent, then
19835 we should not do this. We'll prepend the parent's fully qualified
19836 name when we create the partial symbol. */
19838 real_pdi
= struct_pdi
;
19839 while (real_pdi
->has_specification
)
19841 auto res
= find_partial_die (real_pdi
->spec_offset
,
19842 real_pdi
->spec_is_dwz
, cu
);
19843 real_pdi
= res
.pdi
;
19847 if (real_pdi
->die_parent
!= NULL
)
19850 for (child_pdi
= struct_pdi
->die_child
;
19852 child_pdi
= child_pdi
->die_sibling
)
19854 if (child_pdi
->tag
== DW_TAG_subprogram
19855 && child_pdi
->linkage_name
!= NULL
)
19857 gdb::unique_xmalloc_ptr
<char> actual_class_name
19858 (cu
->language_defn
->class_name_from_physname
19859 (child_pdi
->linkage_name
));
19860 if (actual_class_name
!= NULL
)
19862 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19863 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19864 struct_pdi
->canonical_name
= 1;
19871 /* Return true if a DIE with TAG may have the DW_AT_const_value
19875 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19879 case DW_TAG_constant
:
19880 case DW_TAG_enumerator
:
19881 case DW_TAG_formal_parameter
:
19882 case DW_TAG_template_value_param
:
19883 case DW_TAG_variable
:
19891 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19893 /* Once we've fixed up a die, there's no point in doing so again.
19894 This also avoids a memory leak if we were to call
19895 guess_partial_die_structure_name multiple times. */
19899 /* If we found a reference attribute and the DIE has no name, try
19900 to find a name in the referred to DIE. */
19902 if (raw_name
== NULL
&& has_specification
)
19904 struct partial_die_info
*spec_die
;
19906 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19907 spec_die
= res
.pdi
;
19910 spec_die
->fixup (cu
);
19912 if (spec_die
->raw_name
)
19914 raw_name
= spec_die
->raw_name
;
19915 canonical_name
= spec_die
->canonical_name
;
19917 /* Copy DW_AT_external attribute if it is set. */
19918 if (spec_die
->is_external
)
19919 is_external
= spec_die
->is_external
;
19923 if (!has_const_value
&& has_specification
19924 && can_have_DW_AT_const_value_p (tag
))
19926 struct partial_die_info
*spec_die
;
19928 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19929 spec_die
= res
.pdi
;
19932 spec_die
->fixup (cu
);
19934 if (spec_die
->has_const_value
)
19936 /* Copy DW_AT_const_value attribute if it is set. */
19937 has_const_value
= spec_die
->has_const_value
;
19941 /* Set default names for some unnamed DIEs. */
19943 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19945 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19946 canonical_name
= 1;
19949 /* If there is no parent die to provide a namespace, and there are
19950 children, see if we can determine the namespace from their linkage
19952 if (cu
->language
== language_cplus
19953 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19954 && die_parent
== NULL
19956 && (tag
== DW_TAG_class_type
19957 || tag
== DW_TAG_structure_type
19958 || tag
== DW_TAG_union_type
))
19959 guess_partial_die_structure_name (this, cu
);
19961 /* GCC might emit a nameless struct or union that has a linkage
19962 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19963 if (raw_name
== NULL
19964 && (tag
== DW_TAG_class_type
19965 || tag
== DW_TAG_interface_type
19966 || tag
== DW_TAG_structure_type
19967 || tag
== DW_TAG_union_type
)
19968 && linkage_name
!= NULL
)
19970 gdb::unique_xmalloc_ptr
<char> demangled
19971 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19972 if (demangled
!= nullptr)
19976 /* Strip any leading namespaces/classes, keep only the base name.
19977 DW_AT_name for named DIEs does not contain the prefixes. */
19978 base
= strrchr (demangled
.get (), ':');
19979 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19982 base
= demangled
.get ();
19984 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19985 raw_name
= objfile
->intern (base
);
19986 canonical_name
= 1;
19993 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19994 contents from the given SECTION in the HEADER. */
19996 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19997 struct dwarf2_section_info
*section
)
19999 unsigned int bytes_read
;
20000 bfd
*abfd
= section
->get_bfd_owner ();
20001 const gdb_byte
*info_ptr
= section
->buffer
;
20002 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
20003 info_ptr
+= bytes_read
;
20004 header
->version
= read_2_bytes (abfd
, info_ptr
);
20006 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
20008 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
20010 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
20013 /* Return the DW_AT_loclists_base value for the CU. */
20015 lookup_loclist_base (struct dwarf2_cu
*cu
)
20017 /* For the .dwo unit, the loclist_base points to the first offset following
20018 the header. The header consists of the following entities-
20019 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
20021 2. version (2 bytes)
20022 3. address size (1 byte)
20023 4. segment selector size (1 byte)
20024 5. offset entry count (4 bytes)
20025 These sizes are derived as per the DWARFv5 standard. */
20026 if (cu
->dwo_unit
!= nullptr)
20028 if (cu
->header
.initial_length_size
== 4)
20029 return LOCLIST_HEADER_SIZE32
;
20030 return LOCLIST_HEADER_SIZE64
;
20032 return cu
->loclist_base
;
20035 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
20036 array of offsets in the .debug_loclists section. */
20038 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
20040 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20041 struct objfile
*objfile
= per_objfile
->objfile
;
20042 bfd
*abfd
= objfile
->obfd
;
20043 ULONGEST loclist_base
= lookup_loclist_base (cu
);
20044 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
20046 section
->read (objfile
);
20047 if (section
->buffer
== NULL
)
20048 complaint (_("DW_FORM_loclistx used without .debug_loclists "
20049 "section [in module %s]"), objfile_name (objfile
));
20050 struct loclists_rnglists_header header
;
20051 read_loclists_rnglists_header (&header
, section
);
20052 if (loclist_index
>= header
.offset_entry_count
)
20053 complaint (_("DW_FORM_loclistx pointing outside of "
20054 ".debug_loclists offset array [in module %s]"),
20055 objfile_name (objfile
));
20056 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
20058 complaint (_("DW_FORM_loclistx pointing outside of "
20059 ".debug_loclists section [in module %s]"),
20060 objfile_name (objfile
));
20061 const gdb_byte
*info_ptr
20062 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
20064 if (cu
->header
.offset_size
== 4)
20065 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
20067 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
20070 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
20071 array of offsets in the .debug_rnglists section. */
20073 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
20076 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
20077 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20078 bfd
*abfd
= objfile
->obfd
;
20079 ULONGEST rnglist_header_size
=
20080 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
20081 : RNGLIST_HEADER_SIZE64
);
20082 ULONGEST rnglist_base
=
20083 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->ranges_base
;
20084 ULONGEST start_offset
=
20085 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
20087 /* Get rnglists section. */
20088 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
20090 /* Read the rnglists section content. */
20091 section
->read (objfile
);
20092 if (section
->buffer
== nullptr)
20093 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
20095 objfile_name (objfile
));
20097 /* Verify the rnglist index is valid. */
20098 struct loclists_rnglists_header header
;
20099 read_loclists_rnglists_header (&header
, section
);
20100 if (rnglist_index
>= header
.offset_entry_count
)
20101 error (_("DW_FORM_rnglistx index pointing outside of "
20102 ".debug_rnglists offset array [in module %s]"),
20103 objfile_name (objfile
));
20105 /* Validate that the offset is within the section's range. */
20106 if (start_offset
>= section
->size
)
20107 error (_("DW_FORM_rnglistx pointing outside of "
20108 ".debug_rnglists section [in module %s]"),
20109 objfile_name (objfile
));
20111 /* Validate that reading won't go beyond the end of the section. */
20112 if (start_offset
+ cu
->header
.offset_size
> rnglist_base
+ section
->size
)
20113 error (_("Reading DW_FORM_rnglistx index beyond end of"
20114 ".debug_rnglists section [in module %s]"),
20115 objfile_name (objfile
));
20117 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20119 if (cu
->header
.offset_size
== 4)
20120 return read_4_bytes (abfd
, info_ptr
) + rnglist_base
;
20122 return read_8_bytes (abfd
, info_ptr
) + rnglist_base
;
20125 /* Process the attributes that had to be skipped in the first round. These
20126 attributes are the ones that need str_offsets_base or addr_base attributes.
20127 They could not have been processed in the first round, because at the time
20128 the values of str_offsets_base or addr_base may not have been known. */
20130 read_attribute_reprocess (const struct die_reader_specs
*reader
,
20131 struct attribute
*attr
, dwarf_tag tag
)
20133 struct dwarf2_cu
*cu
= reader
->cu
;
20134 switch (attr
->form
)
20136 case DW_FORM_addrx
:
20137 case DW_FORM_GNU_addr_index
:
20138 attr
->set_address (read_addr_index (cu
,
20139 attr
->as_unsigned_reprocess ()));
20141 case DW_FORM_loclistx
:
20142 attr
->set_address (read_loclist_index (cu
, attr
->as_unsigned ()));
20144 case DW_FORM_rnglistx
:
20145 attr
->set_address (read_rnglist_index (cu
, attr
->as_unsigned (), tag
));
20148 case DW_FORM_strx1
:
20149 case DW_FORM_strx2
:
20150 case DW_FORM_strx3
:
20151 case DW_FORM_strx4
:
20152 case DW_FORM_GNU_str_index
:
20154 unsigned int str_index
= attr
->as_unsigned_reprocess ();
20155 gdb_assert (!attr
->canonical_string_p ());
20156 if (reader
->dwo_file
!= NULL
)
20157 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
20160 attr
->set_string_noncanonical (read_stub_str_index (cu
,
20165 gdb_assert_not_reached (_("Unexpected DWARF form."));
20169 /* Read an attribute value described by an attribute form. */
20171 static const gdb_byte
*
20172 read_attribute_value (const struct die_reader_specs
*reader
,
20173 struct attribute
*attr
, unsigned form
,
20174 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
20176 struct dwarf2_cu
*cu
= reader
->cu
;
20177 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20178 struct objfile
*objfile
= per_objfile
->objfile
;
20179 bfd
*abfd
= reader
->abfd
;
20180 struct comp_unit_head
*cu_header
= &cu
->header
;
20181 unsigned int bytes_read
;
20182 struct dwarf_block
*blk
;
20184 attr
->form
= (enum dwarf_form
) form
;
20187 case DW_FORM_ref_addr
:
20188 if (cu
->header
.version
== 2)
20189 attr
->set_unsigned (cu
->header
.read_address (abfd
, info_ptr
,
20192 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
20194 info_ptr
+= bytes_read
;
20196 case DW_FORM_GNU_ref_alt
:
20197 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
20199 info_ptr
+= bytes_read
;
20203 struct gdbarch
*gdbarch
= objfile
->arch ();
20204 CORE_ADDR addr
= cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
20205 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
20206 attr
->set_address (addr
);
20207 info_ptr
+= bytes_read
;
20210 case DW_FORM_block2
:
20211 blk
= dwarf_alloc_block (cu
);
20212 blk
->size
= read_2_bytes (abfd
, info_ptr
);
20214 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20215 info_ptr
+= blk
->size
;
20216 attr
->set_block (blk
);
20218 case DW_FORM_block4
:
20219 blk
= dwarf_alloc_block (cu
);
20220 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20222 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20223 info_ptr
+= blk
->size
;
20224 attr
->set_block (blk
);
20226 case DW_FORM_data2
:
20227 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20230 case DW_FORM_data4
:
20231 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20234 case DW_FORM_data8
:
20235 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20238 case DW_FORM_data16
:
20239 blk
= dwarf_alloc_block (cu
);
20241 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20243 attr
->set_block (blk
);
20245 case DW_FORM_sec_offset
:
20246 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
20248 info_ptr
+= bytes_read
;
20250 case DW_FORM_loclistx
:
20252 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20254 info_ptr
+= bytes_read
;
20257 case DW_FORM_string
:
20258 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20260 info_ptr
+= bytes_read
;
20263 if (!cu
->per_cu
->is_dwz
)
20265 attr
->set_string_noncanonical
20266 (read_indirect_string (per_objfile
,
20267 abfd
, info_ptr
, cu_header
,
20269 info_ptr
+= bytes_read
;
20273 case DW_FORM_line_strp
:
20274 if (!cu
->per_cu
->is_dwz
)
20276 attr
->set_string_noncanonical
20277 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20279 info_ptr
+= bytes_read
;
20283 case DW_FORM_GNU_strp_alt
:
20285 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
20286 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20289 attr
->set_string_noncanonical
20290 (dwz
->read_string (objfile
, str_offset
));
20291 info_ptr
+= bytes_read
;
20294 case DW_FORM_exprloc
:
20295 case DW_FORM_block
:
20296 blk
= dwarf_alloc_block (cu
);
20297 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20298 info_ptr
+= bytes_read
;
20299 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20300 info_ptr
+= blk
->size
;
20301 attr
->set_block (blk
);
20303 case DW_FORM_block1
:
20304 blk
= dwarf_alloc_block (cu
);
20305 blk
->size
= read_1_byte (abfd
, info_ptr
);
20307 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20308 info_ptr
+= blk
->size
;
20309 attr
->set_block (blk
);
20311 case DW_FORM_data1
:
20313 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20316 case DW_FORM_flag_present
:
20317 attr
->set_unsigned (1);
20319 case DW_FORM_sdata
:
20320 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20321 info_ptr
+= bytes_read
;
20323 case DW_FORM_rnglistx
:
20325 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20327 info_ptr
+= bytes_read
;
20330 case DW_FORM_udata
:
20331 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20332 info_ptr
+= bytes_read
;
20335 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20336 + read_1_byte (abfd
, info_ptr
)));
20340 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20341 + read_2_bytes (abfd
, info_ptr
)));
20345 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20346 + read_4_bytes (abfd
, info_ptr
)));
20350 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20351 + read_8_bytes (abfd
, info_ptr
)));
20354 case DW_FORM_ref_sig8
:
20355 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20358 case DW_FORM_ref_udata
:
20359 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20360 + read_unsigned_leb128 (abfd
, info_ptr
,
20362 info_ptr
+= bytes_read
;
20364 case DW_FORM_indirect
:
20365 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20366 info_ptr
+= bytes_read
;
20367 if (form
== DW_FORM_implicit_const
)
20369 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20370 info_ptr
+= bytes_read
;
20372 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20375 case DW_FORM_implicit_const
:
20376 attr
->set_signed (implicit_const
);
20378 case DW_FORM_addrx
:
20379 case DW_FORM_GNU_addr_index
:
20380 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20382 info_ptr
+= bytes_read
;
20385 case DW_FORM_strx1
:
20386 case DW_FORM_strx2
:
20387 case DW_FORM_strx3
:
20388 case DW_FORM_strx4
:
20389 case DW_FORM_GNU_str_index
:
20391 ULONGEST str_index
;
20392 if (form
== DW_FORM_strx1
)
20394 str_index
= read_1_byte (abfd
, info_ptr
);
20397 else if (form
== DW_FORM_strx2
)
20399 str_index
= read_2_bytes (abfd
, info_ptr
);
20402 else if (form
== DW_FORM_strx3
)
20404 str_index
= read_3_bytes (abfd
, info_ptr
);
20407 else if (form
== DW_FORM_strx4
)
20409 str_index
= read_4_bytes (abfd
, info_ptr
);
20414 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20415 info_ptr
+= bytes_read
;
20417 attr
->set_unsigned_reprocess (str_index
);
20421 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20422 dwarf_form_name (form
),
20423 bfd_get_filename (abfd
));
20427 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20428 attr
->form
= DW_FORM_GNU_ref_alt
;
20430 /* We have seen instances where the compiler tried to emit a byte
20431 size attribute of -1 which ended up being encoded as an unsigned
20432 0xffffffff. Although 0xffffffff is technically a valid size value,
20433 an object of this size seems pretty unlikely so we can relatively
20434 safely treat these cases as if the size attribute was invalid and
20435 treat them as zero by default. */
20436 if (attr
->name
== DW_AT_byte_size
20437 && form
== DW_FORM_data4
20438 && attr
->as_unsigned () >= 0xffffffff)
20441 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20442 hex_string (attr
->as_unsigned ()));
20443 attr
->set_unsigned (0);
20449 /* Read an attribute described by an abbreviated attribute. */
20451 static const gdb_byte
*
20452 read_attribute (const struct die_reader_specs
*reader
,
20453 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
20454 const gdb_byte
*info_ptr
)
20456 attr
->name
= abbrev
->name
;
20457 attr
->string_is_canonical
= 0;
20458 attr
->requires_reprocessing
= 0;
20459 return read_attribute_value (reader
, attr
, abbrev
->form
,
20460 abbrev
->implicit_const
, info_ptr
);
20463 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20465 static const char *
20466 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20467 LONGEST str_offset
)
20469 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20470 str_offset
, "DW_FORM_strp");
20473 /* Return pointer to string at .debug_str offset as read from BUF.
20474 BUF is assumed to be in a compilation unit described by CU_HEADER.
20475 Return *BYTES_READ_PTR count of bytes read from BUF. */
20477 static const char *
20478 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20479 const gdb_byte
*buf
,
20480 const struct comp_unit_head
*cu_header
,
20481 unsigned int *bytes_read_ptr
)
20483 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20485 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20491 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20492 const struct comp_unit_head
*cu_header
,
20493 unsigned int *bytes_read_ptr
)
20495 bfd
*abfd
= objfile
->obfd
;
20496 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20498 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20501 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20502 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20503 ADDR_SIZE is the size of addresses from the CU header. */
20506 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20507 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20509 struct objfile
*objfile
= per_objfile
->objfile
;
20510 bfd
*abfd
= objfile
->obfd
;
20511 const gdb_byte
*info_ptr
;
20512 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20514 per_objfile
->per_bfd
->addr
.read (objfile
);
20515 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20516 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20517 objfile_name (objfile
));
20518 if (addr_base_or_zero
+ addr_index
* addr_size
20519 >= per_objfile
->per_bfd
->addr
.size
)
20520 error (_("DW_FORM_addr_index pointing outside of "
20521 ".debug_addr section [in module %s]"),
20522 objfile_name (objfile
));
20523 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20524 + addr_index
* addr_size
);
20525 if (addr_size
== 4)
20526 return bfd_get_32 (abfd
, info_ptr
);
20528 return bfd_get_64 (abfd
, info_ptr
);
20531 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20534 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20536 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20537 cu
->addr_base
, cu
->header
.addr_size
);
20540 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20543 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20544 unsigned int *bytes_read
)
20546 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20547 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20549 return read_addr_index (cu
, addr_index
);
20555 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20556 dwarf2_per_objfile
*per_objfile
,
20557 unsigned int addr_index
)
20559 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20560 gdb::optional
<ULONGEST
> addr_base
;
20563 /* We need addr_base and addr_size.
20564 If we don't have PER_CU->cu, we have to get it.
20565 Nasty, but the alternative is storing the needed info in PER_CU,
20566 which at this point doesn't seem justified: it's not clear how frequently
20567 it would get used and it would increase the size of every PER_CU.
20568 Entry points like dwarf2_per_cu_addr_size do a similar thing
20569 so we're not in uncharted territory here.
20570 Alas we need to be a bit more complicated as addr_base is contained
20573 We don't need to read the entire CU(/TU).
20574 We just need the header and top level die.
20576 IWBN to use the aging mechanism to let us lazily later discard the CU.
20577 For now we skip this optimization. */
20581 addr_base
= cu
->addr_base
;
20582 addr_size
= cu
->header
.addr_size
;
20586 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20587 addr_base
= reader
.cu
->addr_base
;
20588 addr_size
= reader
.cu
->header
.addr_size
;
20591 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20594 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20595 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20598 static const char *
20599 read_str_index (struct dwarf2_cu
*cu
,
20600 struct dwarf2_section_info
*str_section
,
20601 struct dwarf2_section_info
*str_offsets_section
,
20602 ULONGEST str_offsets_base
, ULONGEST str_index
)
20604 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20605 struct objfile
*objfile
= per_objfile
->objfile
;
20606 const char *objf_name
= objfile_name (objfile
);
20607 bfd
*abfd
= objfile
->obfd
;
20608 const gdb_byte
*info_ptr
;
20609 ULONGEST str_offset
;
20610 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20612 str_section
->read (objfile
);
20613 str_offsets_section
->read (objfile
);
20614 if (str_section
->buffer
== NULL
)
20615 error (_("%s used without %s section"
20616 " in CU at offset %s [in module %s]"),
20617 form_name
, str_section
->get_name (),
20618 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20619 if (str_offsets_section
->buffer
== NULL
)
20620 error (_("%s used without %s section"
20621 " in CU at offset %s [in module %s]"),
20622 form_name
, str_section
->get_name (),
20623 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20624 info_ptr
= (str_offsets_section
->buffer
20626 + str_index
* cu
->header
.offset_size
);
20627 if (cu
->header
.offset_size
== 4)
20628 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20630 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20631 if (str_offset
>= str_section
->size
)
20632 error (_("Offset from %s pointing outside of"
20633 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20634 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20635 return (const char *) (str_section
->buffer
+ str_offset
);
20638 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20640 static const char *
20641 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20643 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20644 ? reader
->cu
->header
.addr_size
: 0;
20645 return read_str_index (reader
->cu
,
20646 &reader
->dwo_file
->sections
.str
,
20647 &reader
->dwo_file
->sections
.str_offsets
,
20648 str_offsets_base
, str_index
);
20651 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20653 static const char *
20654 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20656 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20657 const char *objf_name
= objfile_name (objfile
);
20658 static const char form_name
[] = "DW_FORM_GNU_str_index";
20659 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20661 if (!cu
->str_offsets_base
.has_value ())
20662 error (_("%s used in Fission stub without %s"
20663 " in CU at offset 0x%lx [in module %s]"),
20664 form_name
, str_offsets_attr_name
,
20665 (long) cu
->header
.offset_size
, objf_name
);
20667 return read_str_index (cu
,
20668 &cu
->per_objfile
->per_bfd
->str
,
20669 &cu
->per_objfile
->per_bfd
->str_offsets
,
20670 *cu
->str_offsets_base
, str_index
);
20673 /* Return the length of an LEB128 number in BUF. */
20676 leb128_size (const gdb_byte
*buf
)
20678 const gdb_byte
*begin
= buf
;
20684 if ((byte
& 128) == 0)
20685 return buf
- begin
;
20690 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20699 cu
->language
= language_c
;
20702 case DW_LANG_C_plus_plus
:
20703 case DW_LANG_C_plus_plus_11
:
20704 case DW_LANG_C_plus_plus_14
:
20705 cu
->language
= language_cplus
;
20708 cu
->language
= language_d
;
20710 case DW_LANG_Fortran77
:
20711 case DW_LANG_Fortran90
:
20712 case DW_LANG_Fortran95
:
20713 case DW_LANG_Fortran03
:
20714 case DW_LANG_Fortran08
:
20715 cu
->language
= language_fortran
;
20718 cu
->language
= language_go
;
20720 case DW_LANG_Mips_Assembler
:
20721 cu
->language
= language_asm
;
20723 case DW_LANG_Ada83
:
20724 case DW_LANG_Ada95
:
20725 cu
->language
= language_ada
;
20727 case DW_LANG_Modula2
:
20728 cu
->language
= language_m2
;
20730 case DW_LANG_Pascal83
:
20731 cu
->language
= language_pascal
;
20734 cu
->language
= language_objc
;
20737 case DW_LANG_Rust_old
:
20738 cu
->language
= language_rust
;
20740 case DW_LANG_Cobol74
:
20741 case DW_LANG_Cobol85
:
20743 cu
->language
= language_minimal
;
20746 cu
->language_defn
= language_def (cu
->language
);
20749 /* Return the named attribute or NULL if not there. */
20751 static struct attribute
*
20752 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20757 struct attribute
*spec
= NULL
;
20759 for (i
= 0; i
< die
->num_attrs
; ++i
)
20761 if (die
->attrs
[i
].name
== name
)
20762 return &die
->attrs
[i
];
20763 if (die
->attrs
[i
].name
== DW_AT_specification
20764 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20765 spec
= &die
->attrs
[i
];
20771 die
= follow_die_ref (die
, spec
, &cu
);
20777 /* Return the string associated with a string-typed attribute, or NULL if it
20778 is either not found or is of an incorrect type. */
20780 static const char *
20781 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20783 struct attribute
*attr
;
20784 const char *str
= NULL
;
20786 attr
= dwarf2_attr (die
, name
, cu
);
20790 str
= attr
->as_string ();
20791 if (str
== nullptr)
20792 complaint (_("string type expected for attribute %s for "
20793 "DIE at %s in module %s"),
20794 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20795 objfile_name (cu
->per_objfile
->objfile
));
20801 /* Return the dwo name or NULL if not present. If present, it is in either
20802 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20803 static const char *
20804 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20806 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20807 if (dwo_name
== nullptr)
20808 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20812 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20813 and holds a non-zero value. This function should only be used for
20814 DW_FORM_flag or DW_FORM_flag_present attributes. */
20817 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20819 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20821 return attr
!= nullptr && attr
->as_boolean ();
20825 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20827 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20828 which value is non-zero. However, we have to be careful with
20829 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20830 (via dwarf2_flag_true_p) follows this attribute. So we may
20831 end up accidently finding a declaration attribute that belongs
20832 to a different DIE referenced by the specification attribute,
20833 even though the given DIE does not have a declaration attribute. */
20834 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20835 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20838 /* Return the die giving the specification for DIE, if there is
20839 one. *SPEC_CU is the CU containing DIE on input, and the CU
20840 containing the return value on output. If there is no
20841 specification, but there is an abstract origin, that is
20844 static struct die_info
*
20845 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20847 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20850 if (spec_attr
== NULL
)
20851 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20853 if (spec_attr
== NULL
)
20856 return follow_die_ref (die
, spec_attr
, spec_cu
);
20859 /* Stub for free_line_header to match void * callback types. */
20862 free_line_header_voidp (void *arg
)
20864 struct line_header
*lh
= (struct line_header
*) arg
;
20869 /* A convenience function to find the proper .debug_line section for a CU. */
20871 static struct dwarf2_section_info
*
20872 get_debug_line_section (struct dwarf2_cu
*cu
)
20874 struct dwarf2_section_info
*section
;
20875 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20877 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20879 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20880 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20881 else if (cu
->per_cu
->is_dwz
)
20883 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
20885 section
= &dwz
->line
;
20888 section
= &per_objfile
->per_bfd
->line
;
20893 /* Read the statement program header starting at OFFSET in
20894 .debug_line, or .debug_line.dwo. Return a pointer
20895 to a struct line_header, allocated using xmalloc.
20896 Returns NULL if there is a problem reading the header, e.g., if it
20897 has a version we don't understand.
20899 NOTE: the strings in the include directory and file name tables of
20900 the returned object point into the dwarf line section buffer,
20901 and must not be freed. */
20903 static line_header_up
20904 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20906 struct dwarf2_section_info
*section
;
20907 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20909 section
= get_debug_line_section (cu
);
20910 section
->read (per_objfile
->objfile
);
20911 if (section
->buffer
== NULL
)
20913 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20914 complaint (_("missing .debug_line.dwo section"));
20916 complaint (_("missing .debug_line section"));
20920 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20921 per_objfile
, section
, &cu
->header
);
20924 /* Subroutine of dwarf_decode_lines to simplify it.
20925 Return the file name of the psymtab for the given file_entry.
20926 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20927 If space for the result is malloc'd, *NAME_HOLDER will be set.
20928 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20930 static const char *
20931 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20932 const dwarf2_psymtab
*pst
,
20933 const char *comp_dir
,
20934 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20936 const char *include_name
= fe
.name
;
20937 const char *include_name_to_compare
= include_name
;
20938 const char *pst_filename
;
20941 const char *dir_name
= fe
.include_dir (lh
);
20943 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20944 if (!IS_ABSOLUTE_PATH (include_name
)
20945 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20947 /* Avoid creating a duplicate psymtab for PST.
20948 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20949 Before we do the comparison, however, we need to account
20950 for DIR_NAME and COMP_DIR.
20951 First prepend dir_name (if non-NULL). If we still don't
20952 have an absolute path prepend comp_dir (if non-NULL).
20953 However, the directory we record in the include-file's
20954 psymtab does not contain COMP_DIR (to match the
20955 corresponding symtab(s)).
20960 bash$ gcc -g ./hello.c
20961 include_name = "hello.c"
20963 DW_AT_comp_dir = comp_dir = "/tmp"
20964 DW_AT_name = "./hello.c"
20968 if (dir_name
!= NULL
)
20970 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20971 include_name
, (char *) NULL
));
20972 include_name
= name_holder
->get ();
20973 include_name_to_compare
= include_name
;
20975 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20977 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20978 include_name
, (char *) NULL
));
20979 include_name_to_compare
= hold_compare
.get ();
20983 pst_filename
= pst
->filename
;
20984 gdb::unique_xmalloc_ptr
<char> copied_name
;
20985 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20987 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20988 pst_filename
, (char *) NULL
));
20989 pst_filename
= copied_name
.get ();
20992 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20996 return include_name
;
20999 /* State machine to track the state of the line number program. */
21001 class lnp_state_machine
21004 /* Initialize a machine state for the start of a line number
21006 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
21007 bool record_lines_p
);
21009 file_entry
*current_file ()
21011 /* lh->file_names is 0-based, but the file name numbers in the
21012 statement program are 1-based. */
21013 return m_line_header
->file_name_at (m_file
);
21016 /* Record the line in the state machine. END_SEQUENCE is true if
21017 we're processing the end of a sequence. */
21018 void record_line (bool end_sequence
);
21020 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
21021 nop-out rest of the lines in this sequence. */
21022 void check_line_address (struct dwarf2_cu
*cu
,
21023 const gdb_byte
*line_ptr
,
21024 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
21026 void handle_set_discriminator (unsigned int discriminator
)
21028 m_discriminator
= discriminator
;
21029 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21032 /* Handle DW_LNE_set_address. */
21033 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21036 address
+= baseaddr
;
21037 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21040 /* Handle DW_LNS_advance_pc. */
21041 void handle_advance_pc (CORE_ADDR adjust
);
21043 /* Handle a special opcode. */
21044 void handle_special_opcode (unsigned char op_code
);
21046 /* Handle DW_LNS_advance_line. */
21047 void handle_advance_line (int line_delta
)
21049 advance_line (line_delta
);
21052 /* Handle DW_LNS_set_file. */
21053 void handle_set_file (file_name_index file
);
21055 /* Handle DW_LNS_negate_stmt. */
21056 void handle_negate_stmt ()
21058 m_is_stmt
= !m_is_stmt
;
21061 /* Handle DW_LNS_const_add_pc. */
21062 void handle_const_add_pc ();
21064 /* Handle DW_LNS_fixed_advance_pc. */
21065 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21067 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21071 /* Handle DW_LNS_copy. */
21072 void handle_copy ()
21074 record_line (false);
21075 m_discriminator
= 0;
21078 /* Handle DW_LNE_end_sequence. */
21079 void handle_end_sequence ()
21081 m_currently_recording_lines
= true;
21085 /* Advance the line by LINE_DELTA. */
21086 void advance_line (int line_delta
)
21088 m_line
+= line_delta
;
21090 if (line_delta
!= 0)
21091 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21094 struct dwarf2_cu
*m_cu
;
21096 gdbarch
*m_gdbarch
;
21098 /* True if we're recording lines.
21099 Otherwise we're building partial symtabs and are just interested in
21100 finding include files mentioned by the line number program. */
21101 bool m_record_lines_p
;
21103 /* The line number header. */
21104 line_header
*m_line_header
;
21106 /* These are part of the standard DWARF line number state machine,
21107 and initialized according to the DWARF spec. */
21109 unsigned char m_op_index
= 0;
21110 /* The line table index of the current file. */
21111 file_name_index m_file
= 1;
21112 unsigned int m_line
= 1;
21114 /* These are initialized in the constructor. */
21116 CORE_ADDR m_address
;
21118 unsigned int m_discriminator
;
21120 /* Additional bits of state we need to track. */
21122 /* The last file that we called dwarf2_start_subfile for.
21123 This is only used for TLLs. */
21124 unsigned int m_last_file
= 0;
21125 /* The last file a line number was recorded for. */
21126 struct subfile
*m_last_subfile
= NULL
;
21128 /* The address of the last line entry. */
21129 CORE_ADDR m_last_address
;
21131 /* Set to true when a previous line at the same address (using
21132 m_last_address) had m_is_stmt true. This is reset to false when a
21133 line entry at a new address (m_address different to m_last_address) is
21135 bool m_stmt_at_address
= false;
21137 /* When true, record the lines we decode. */
21138 bool m_currently_recording_lines
= false;
21140 /* The last line number that was recorded, used to coalesce
21141 consecutive entries for the same line. This can happen, for
21142 example, when discriminators are present. PR 17276. */
21143 unsigned int m_last_line
= 0;
21144 bool m_line_has_non_zero_discriminator
= false;
21148 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21150 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21151 / m_line_header
->maximum_ops_per_instruction
)
21152 * m_line_header
->minimum_instruction_length
);
21153 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21154 m_op_index
= ((m_op_index
+ adjust
)
21155 % m_line_header
->maximum_ops_per_instruction
);
21159 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21161 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21162 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
21163 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
21164 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
21165 / m_line_header
->maximum_ops_per_instruction
)
21166 * m_line_header
->minimum_instruction_length
);
21167 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21168 m_op_index
= ((m_op_index
+ adj_opcode_d
)
21169 % m_line_header
->maximum_ops_per_instruction
);
21171 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
21172 advance_line (line_delta
);
21173 record_line (false);
21174 m_discriminator
= 0;
21178 lnp_state_machine::handle_set_file (file_name_index file
)
21182 const file_entry
*fe
= current_file ();
21184 dwarf2_debug_line_missing_file_complaint ();
21185 else if (m_record_lines_p
)
21187 const char *dir
= fe
->include_dir (m_line_header
);
21189 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21190 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21191 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21196 lnp_state_machine::handle_const_add_pc ()
21199 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21202 = (((m_op_index
+ adjust
)
21203 / m_line_header
->maximum_ops_per_instruction
)
21204 * m_line_header
->minimum_instruction_length
);
21206 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21207 m_op_index
= ((m_op_index
+ adjust
)
21208 % m_line_header
->maximum_ops_per_instruction
);
21211 /* Return non-zero if we should add LINE to the line number table.
21212 LINE is the line to add, LAST_LINE is the last line that was added,
21213 LAST_SUBFILE is the subfile for LAST_LINE.
21214 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21215 had a non-zero discriminator.
21217 We have to be careful in the presence of discriminators.
21218 E.g., for this line:
21220 for (i = 0; i < 100000; i++);
21222 clang can emit four line number entries for that one line,
21223 each with a different discriminator.
21224 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21226 However, we want gdb to coalesce all four entries into one.
21227 Otherwise the user could stepi into the middle of the line and
21228 gdb would get confused about whether the pc really was in the
21229 middle of the line.
21231 Things are further complicated by the fact that two consecutive
21232 line number entries for the same line is a heuristic used by gcc
21233 to denote the end of the prologue. So we can't just discard duplicate
21234 entries, we have to be selective about it. The heuristic we use is
21235 that we only collapse consecutive entries for the same line if at least
21236 one of those entries has a non-zero discriminator. PR 17276.
21238 Note: Addresses in the line number state machine can never go backwards
21239 within one sequence, thus this coalescing is ok. */
21242 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21243 unsigned int line
, unsigned int last_line
,
21244 int line_has_non_zero_discriminator
,
21245 struct subfile
*last_subfile
)
21247 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21249 if (line
!= last_line
)
21251 /* Same line for the same file that we've seen already.
21252 As a last check, for pr 17276, only record the line if the line
21253 has never had a non-zero discriminator. */
21254 if (!line_has_non_zero_discriminator
)
21259 /* Use the CU's builder to record line number LINE beginning at
21260 address ADDRESS in the line table of subfile SUBFILE. */
21263 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21264 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
21265 struct dwarf2_cu
*cu
)
21267 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21269 if (dwarf_line_debug
)
21271 fprintf_unfiltered (gdb_stdlog
,
21272 "Recording line %u, file %s, address %s\n",
21273 line
, lbasename (subfile
->name
),
21274 paddress (gdbarch
, address
));
21278 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21281 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21282 Mark the end of a set of line number records.
21283 The arguments are the same as for dwarf_record_line_1.
21284 If SUBFILE is NULL the request is ignored. */
21287 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21288 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21290 if (subfile
== NULL
)
21293 if (dwarf_line_debug
)
21295 fprintf_unfiltered (gdb_stdlog
,
21296 "Finishing current line, file %s, address %s\n",
21297 lbasename (subfile
->name
),
21298 paddress (gdbarch
, address
));
21301 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21305 lnp_state_machine::record_line (bool end_sequence
)
21307 if (dwarf_line_debug
)
21309 fprintf_unfiltered (gdb_stdlog
,
21310 "Processing actual line %u: file %u,"
21311 " address %s, is_stmt %u, discrim %u%s\n",
21313 paddress (m_gdbarch
, m_address
),
21314 m_is_stmt
, m_discriminator
,
21315 (end_sequence
? "\t(end sequence)" : ""));
21318 file_entry
*fe
= current_file ();
21321 dwarf2_debug_line_missing_file_complaint ();
21322 /* For now we ignore lines not starting on an instruction boundary.
21323 But not when processing end_sequence for compatibility with the
21324 previous version of the code. */
21325 else if (m_op_index
== 0 || end_sequence
)
21327 fe
->included_p
= 1;
21328 if (m_record_lines_p
)
21330 /* When we switch files we insert an end maker in the first file,
21331 switch to the second file and add a new line entry. The
21332 problem is that the end marker inserted in the first file will
21333 discard any previous line entries at the same address. If the
21334 line entries in the first file are marked as is-stmt, while
21335 the new line in the second file is non-stmt, then this means
21336 the end marker will discard is-stmt lines so we can have a
21337 non-stmt line. This means that there are less addresses at
21338 which the user can insert a breakpoint.
21340 To improve this we track the last address in m_last_address,
21341 and whether we have seen an is-stmt at this address. Then
21342 when switching files, if we have seen a stmt at the current
21343 address, and we are switching to create a non-stmt line, then
21344 discard the new line. */
21346 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21347 bool ignore_this_line
21348 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21349 && !m_is_stmt
&& m_stmt_at_address
)
21350 || (!end_sequence
&& m_line
== 0));
21352 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21354 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21355 m_currently_recording_lines
? m_cu
: nullptr);
21358 if (!end_sequence
&& !ignore_this_line
)
21360 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21362 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21363 m_line_has_non_zero_discriminator
,
21366 buildsym_compunit
*builder
= m_cu
->get_builder ();
21367 dwarf_record_line_1 (m_gdbarch
,
21368 builder
->get_current_subfile (),
21369 m_line
, m_address
, is_stmt
,
21370 m_currently_recording_lines
? m_cu
: nullptr);
21372 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21373 m_last_line
= m_line
;
21378 /* Track whether we have seen any m_is_stmt true at m_address in case we
21379 have multiple line table entries all at m_address. */
21380 if (m_last_address
!= m_address
)
21382 m_stmt_at_address
= false;
21383 m_last_address
= m_address
;
21385 m_stmt_at_address
|= m_is_stmt
;
21388 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21389 line_header
*lh
, bool record_lines_p
)
21393 m_record_lines_p
= record_lines_p
;
21394 m_line_header
= lh
;
21396 m_currently_recording_lines
= true;
21398 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21399 was a line entry for it so that the backend has a chance to adjust it
21400 and also record it in case it needs it. This is currently used by MIPS
21401 code, cf. `mips_adjust_dwarf2_line'. */
21402 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21403 m_is_stmt
= lh
->default_is_stmt
;
21404 m_discriminator
= 0;
21406 m_last_address
= m_address
;
21407 m_stmt_at_address
= false;
21411 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21412 const gdb_byte
*line_ptr
,
21413 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21415 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21416 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21417 located at 0x0. In this case, additionally check that if
21418 ADDRESS < UNRELOCATED_LOWPC. */
21420 if ((address
== 0 && address
< unrelocated_lowpc
)
21421 || address
== (CORE_ADDR
) -1)
21423 /* This line table is for a function which has been
21424 GCd by the linker. Ignore it. PR gdb/12528 */
21426 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21427 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21429 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21430 line_offset
, objfile_name (objfile
));
21431 m_currently_recording_lines
= false;
21432 /* Note: m_currently_recording_lines is left as false until we see
21433 DW_LNE_end_sequence. */
21437 /* Subroutine of dwarf_decode_lines to simplify it.
21438 Process the line number information in LH.
21439 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21440 program in order to set included_p for every referenced header. */
21443 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21444 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21446 const gdb_byte
*line_ptr
, *extended_end
;
21447 const gdb_byte
*line_end
;
21448 unsigned int bytes_read
, extended_len
;
21449 unsigned char op_code
, extended_op
;
21450 CORE_ADDR baseaddr
;
21451 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21452 bfd
*abfd
= objfile
->obfd
;
21453 struct gdbarch
*gdbarch
= objfile
->arch ();
21454 /* True if we're recording line info (as opposed to building partial
21455 symtabs and just interested in finding include files mentioned by
21456 the line number program). */
21457 bool record_lines_p
= !decode_for_pst_p
;
21459 baseaddr
= objfile
->text_section_offset ();
21461 line_ptr
= lh
->statement_program_start
;
21462 line_end
= lh
->statement_program_end
;
21464 /* Read the statement sequences until there's nothing left. */
21465 while (line_ptr
< line_end
)
21467 /* The DWARF line number program state machine. Reset the state
21468 machine at the start of each sequence. */
21469 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21470 bool end_sequence
= false;
21472 if (record_lines_p
)
21474 /* Start a subfile for the current file of the state
21476 const file_entry
*fe
= state_machine
.current_file ();
21479 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21482 /* Decode the table. */
21483 while (line_ptr
< line_end
&& !end_sequence
)
21485 op_code
= read_1_byte (abfd
, line_ptr
);
21488 if (op_code
>= lh
->opcode_base
)
21490 /* Special opcode. */
21491 state_machine
.handle_special_opcode (op_code
);
21493 else switch (op_code
)
21495 case DW_LNS_extended_op
:
21496 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21498 line_ptr
+= bytes_read
;
21499 extended_end
= line_ptr
+ extended_len
;
21500 extended_op
= read_1_byte (abfd
, line_ptr
);
21502 if (DW_LNE_lo_user
<= extended_op
21503 && extended_op
<= DW_LNE_hi_user
)
21505 /* Vendor extension, ignore. */
21506 line_ptr
= extended_end
;
21509 switch (extended_op
)
21511 case DW_LNE_end_sequence
:
21512 state_machine
.handle_end_sequence ();
21513 end_sequence
= true;
21515 case DW_LNE_set_address
:
21518 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21519 line_ptr
+= bytes_read
;
21521 state_machine
.check_line_address (cu
, line_ptr
,
21522 lowpc
- baseaddr
, address
);
21523 state_machine
.handle_set_address (baseaddr
, address
);
21526 case DW_LNE_define_file
:
21528 const char *cur_file
;
21529 unsigned int mod_time
, length
;
21532 cur_file
= read_direct_string (abfd
, line_ptr
,
21534 line_ptr
+= bytes_read
;
21535 dindex
= (dir_index
)
21536 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21537 line_ptr
+= bytes_read
;
21539 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21540 line_ptr
+= bytes_read
;
21542 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21543 line_ptr
+= bytes_read
;
21544 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21547 case DW_LNE_set_discriminator
:
21549 /* The discriminator is not interesting to the
21550 debugger; just ignore it. We still need to
21551 check its value though:
21552 if there are consecutive entries for the same
21553 (non-prologue) line we want to coalesce them.
21556 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21557 line_ptr
+= bytes_read
;
21559 state_machine
.handle_set_discriminator (discr
);
21563 complaint (_("mangled .debug_line section"));
21566 /* Make sure that we parsed the extended op correctly. If e.g.
21567 we expected a different address size than the producer used,
21568 we may have read the wrong number of bytes. */
21569 if (line_ptr
!= extended_end
)
21571 complaint (_("mangled .debug_line section"));
21576 state_machine
.handle_copy ();
21578 case DW_LNS_advance_pc
:
21581 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21582 line_ptr
+= bytes_read
;
21584 state_machine
.handle_advance_pc (adjust
);
21587 case DW_LNS_advance_line
:
21590 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21591 line_ptr
+= bytes_read
;
21593 state_machine
.handle_advance_line (line_delta
);
21596 case DW_LNS_set_file
:
21598 file_name_index file
21599 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21601 line_ptr
+= bytes_read
;
21603 state_machine
.handle_set_file (file
);
21606 case DW_LNS_set_column
:
21607 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21608 line_ptr
+= bytes_read
;
21610 case DW_LNS_negate_stmt
:
21611 state_machine
.handle_negate_stmt ();
21613 case DW_LNS_set_basic_block
:
21615 /* Add to the address register of the state machine the
21616 address increment value corresponding to special opcode
21617 255. I.e., this value is scaled by the minimum
21618 instruction length since special opcode 255 would have
21619 scaled the increment. */
21620 case DW_LNS_const_add_pc
:
21621 state_machine
.handle_const_add_pc ();
21623 case DW_LNS_fixed_advance_pc
:
21625 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21628 state_machine
.handle_fixed_advance_pc (addr_adj
);
21633 /* Unknown standard opcode, ignore it. */
21636 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21638 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21639 line_ptr
+= bytes_read
;
21646 dwarf2_debug_line_missing_end_sequence_complaint ();
21648 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21649 in which case we still finish recording the last line). */
21650 state_machine
.record_line (true);
21654 /* Decode the Line Number Program (LNP) for the given line_header
21655 structure and CU. The actual information extracted and the type
21656 of structures created from the LNP depends on the value of PST.
21658 1. If PST is NULL, then this procedure uses the data from the program
21659 to create all necessary symbol tables, and their linetables.
21661 2. If PST is not NULL, this procedure reads the program to determine
21662 the list of files included by the unit represented by PST, and
21663 builds all the associated partial symbol tables.
21665 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21666 It is used for relative paths in the line table.
21667 NOTE: When processing partial symtabs (pst != NULL),
21668 comp_dir == pst->dirname.
21670 NOTE: It is important that psymtabs have the same file name (via strcmp)
21671 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21672 symtab we don't use it in the name of the psymtabs we create.
21673 E.g. expand_line_sal requires this when finding psymtabs to expand.
21674 A good testcase for this is mb-inline.exp.
21676 LOWPC is the lowest address in CU (or 0 if not known).
21678 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21679 for its PC<->lines mapping information. Otherwise only the filename
21680 table is read in. */
21683 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21684 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21685 CORE_ADDR lowpc
, int decode_mapping
)
21687 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21688 const int decode_for_pst_p
= (pst
!= NULL
);
21690 if (decode_mapping
)
21691 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21693 if (decode_for_pst_p
)
21695 /* Now that we're done scanning the Line Header Program, we can
21696 create the psymtab of each included file. */
21697 for (auto &file_entry
: lh
->file_names ())
21698 if (file_entry
.included_p
== 1)
21700 gdb::unique_xmalloc_ptr
<char> name_holder
;
21701 const char *include_name
=
21702 psymtab_include_file_name (lh
, file_entry
, pst
,
21703 comp_dir
, &name_holder
);
21704 if (include_name
!= NULL
)
21705 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21710 /* Make sure a symtab is created for every file, even files
21711 which contain only variables (i.e. no code with associated
21713 buildsym_compunit
*builder
= cu
->get_builder ();
21714 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21716 for (auto &fe
: lh
->file_names ())
21718 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21719 if (builder
->get_current_subfile ()->symtab
== NULL
)
21721 builder
->get_current_subfile ()->symtab
21722 = allocate_symtab (cust
,
21723 builder
->get_current_subfile ()->name
);
21725 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21730 /* Start a subfile for DWARF. FILENAME is the name of the file and
21731 DIRNAME the name of the source directory which contains FILENAME
21732 or NULL if not known.
21733 This routine tries to keep line numbers from identical absolute and
21734 relative file names in a common subfile.
21736 Using the `list' example from the GDB testsuite, which resides in
21737 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21738 of /srcdir/list0.c yields the following debugging information for list0.c:
21740 DW_AT_name: /srcdir/list0.c
21741 DW_AT_comp_dir: /compdir
21742 files.files[0].name: list0.h
21743 files.files[0].dir: /srcdir
21744 files.files[1].name: list0.c
21745 files.files[1].dir: /srcdir
21747 The line number information for list0.c has to end up in a single
21748 subfile, so that `break /srcdir/list0.c:1' works as expected.
21749 start_subfile will ensure that this happens provided that we pass the
21750 concatenation of files.files[1].dir and files.files[1].name as the
21754 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21755 const char *dirname
)
21757 gdb::unique_xmalloc_ptr
<char> copy
;
21759 /* In order not to lose the line information directory,
21760 we concatenate it to the filename when it makes sense.
21761 Note that the Dwarf3 standard says (speaking of filenames in line
21762 information): ``The directory index is ignored for file names
21763 that represent full path names''. Thus ignoring dirname in the
21764 `else' branch below isn't an issue. */
21766 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21768 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21769 filename
= copy
.get ();
21772 cu
->get_builder ()->start_subfile (filename
);
21775 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21776 buildsym_compunit constructor. */
21778 struct compunit_symtab
*
21779 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21782 gdb_assert (m_builder
== nullptr);
21784 m_builder
.reset (new struct buildsym_compunit
21785 (this->per_objfile
->objfile
,
21786 name
, comp_dir
, language
, low_pc
));
21788 list_in_scope
= get_builder ()->get_file_symbols ();
21790 get_builder ()->record_debugformat ("DWARF 2");
21791 get_builder ()->record_producer (producer
);
21793 processing_has_namespace_info
= false;
21795 return get_builder ()->get_compunit_symtab ();
21799 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21800 struct dwarf2_cu
*cu
)
21802 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21803 struct comp_unit_head
*cu_header
= &cu
->header
;
21805 /* NOTE drow/2003-01-30: There used to be a comment and some special
21806 code here to turn a symbol with DW_AT_external and a
21807 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21808 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21809 with some versions of binutils) where shared libraries could have
21810 relocations against symbols in their debug information - the
21811 minimal symbol would have the right address, but the debug info
21812 would not. It's no longer necessary, because we will explicitly
21813 apply relocations when we read in the debug information now. */
21815 /* A DW_AT_location attribute with no contents indicates that a
21816 variable has been optimized away. */
21817 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21819 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21823 /* Handle one degenerate form of location expression specially, to
21824 preserve GDB's previous behavior when section offsets are
21825 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21826 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21828 if (attr
->form_is_block ())
21830 struct dwarf_block
*block
= attr
->as_block ();
21832 if ((block
->data
[0] == DW_OP_addr
21833 && block
->size
== 1 + cu_header
->addr_size
)
21834 || ((block
->data
[0] == DW_OP_GNU_addr_index
21835 || block
->data
[0] == DW_OP_addrx
)
21837 == 1 + leb128_size (&block
->data
[1]))))
21839 unsigned int dummy
;
21841 if (block
->data
[0] == DW_OP_addr
)
21842 SET_SYMBOL_VALUE_ADDRESS
21843 (sym
, cu
->header
.read_address (objfile
->obfd
,
21847 SET_SYMBOL_VALUE_ADDRESS
21848 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21850 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21851 fixup_symbol_section (sym
, objfile
);
21852 SET_SYMBOL_VALUE_ADDRESS
21854 SYMBOL_VALUE_ADDRESS (sym
)
21855 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
21860 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21861 expression evaluator, and use LOC_COMPUTED only when necessary
21862 (i.e. when the value of a register or memory location is
21863 referenced, or a thread-local block, etc.). Then again, it might
21864 not be worthwhile. I'm assuming that it isn't unless performance
21865 or memory numbers show me otherwise. */
21867 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21869 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21870 cu
->has_loclist
= true;
21873 /* Given a pointer to a DWARF information entry, figure out if we need
21874 to make a symbol table entry for it, and if so, create a new entry
21875 and return a pointer to it.
21876 If TYPE is NULL, determine symbol type from the die, otherwise
21877 used the passed type.
21878 If SPACE is not NULL, use it to hold the new symbol. If it is
21879 NULL, allocate a new symbol on the objfile's obstack. */
21881 static struct symbol
*
21882 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21883 struct symbol
*space
)
21885 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21886 struct objfile
*objfile
= per_objfile
->objfile
;
21887 struct gdbarch
*gdbarch
= objfile
->arch ();
21888 struct symbol
*sym
= NULL
;
21890 struct attribute
*attr
= NULL
;
21891 struct attribute
*attr2
= NULL
;
21892 CORE_ADDR baseaddr
;
21893 struct pending
**list_to_add
= NULL
;
21895 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21897 baseaddr
= objfile
->text_section_offset ();
21899 name
= dwarf2_name (die
, cu
);
21902 int suppress_add
= 0;
21907 sym
= new (&objfile
->objfile_obstack
) symbol
;
21908 OBJSTAT (objfile
, n_syms
++);
21910 /* Cache this symbol's name and the name's demangled form (if any). */
21911 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21912 /* Fortran does not have mangling standard and the mangling does differ
21913 between gfortran, iFort etc. */
21914 const char *physname
21915 = (cu
->language
== language_fortran
21916 ? dwarf2_full_name (name
, die
, cu
)
21917 : dwarf2_physname (name
, die
, cu
));
21918 const char *linkagename
= dw2_linkage_name (die
, cu
);
21920 if (linkagename
== nullptr || cu
->language
== language_ada
)
21921 sym
->set_linkage_name (physname
);
21924 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21925 sym
->set_linkage_name (linkagename
);
21928 /* Default assumptions.
21929 Use the passed type or decode it from the die. */
21930 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21931 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21933 SYMBOL_TYPE (sym
) = type
;
21935 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21936 attr
= dwarf2_attr (die
,
21937 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21939 if (attr
!= nullptr)
21940 SYMBOL_LINE (sym
) = attr
->constant_value (0);
21942 attr
= dwarf2_attr (die
,
21943 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21945 if (attr
!= nullptr && attr
->form_is_unsigned ())
21947 file_name_index file_index
21948 = (file_name_index
) attr
->as_unsigned ();
21949 struct file_entry
*fe
;
21951 if (cu
->line_header
!= NULL
)
21952 fe
= cu
->line_header
->file_name_at (file_index
);
21957 complaint (_("file index out of range"));
21959 symbol_set_symtab (sym
, fe
->symtab
);
21965 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21966 if (attr
!= nullptr)
21970 addr
= attr
->as_address ();
21971 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21972 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21973 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21976 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21977 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21978 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21979 add_symbol_to_list (sym
, cu
->list_in_scope
);
21981 case DW_TAG_subprogram
:
21982 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21984 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21985 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21986 if ((attr2
!= nullptr && attr2
->as_boolean ())
21987 || cu
->language
== language_ada
21988 || cu
->language
== language_fortran
)
21990 /* Subprograms marked external are stored as a global symbol.
21991 Ada and Fortran subprograms, whether marked external or
21992 not, are always stored as a global symbol, because we want
21993 to be able to access them globally. For instance, we want
21994 to be able to break on a nested subprogram without having
21995 to specify the context. */
21996 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22000 list_to_add
= cu
->list_in_scope
;
22003 case DW_TAG_inlined_subroutine
:
22004 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22006 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22007 SYMBOL_INLINED (sym
) = 1;
22008 list_to_add
= cu
->list_in_scope
;
22010 case DW_TAG_template_value_param
:
22012 /* Fall through. */
22013 case DW_TAG_constant
:
22014 case DW_TAG_variable
:
22015 case DW_TAG_member
:
22016 /* Compilation with minimal debug info may result in
22017 variables with missing type entries. Change the
22018 misleading `void' type to something sensible. */
22019 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
22020 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
22022 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22023 /* In the case of DW_TAG_member, we should only be called for
22024 static const members. */
22025 if (die
->tag
== DW_TAG_member
)
22027 /* dwarf2_add_field uses die_is_declaration,
22028 so we do the same. */
22029 gdb_assert (die_is_declaration (die
, cu
));
22032 if (attr
!= nullptr)
22034 dwarf2_const_value (attr
, sym
, cu
);
22035 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22038 if (attr2
!= nullptr && attr2
->as_boolean ())
22039 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22041 list_to_add
= cu
->list_in_scope
;
22045 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22046 if (attr
!= nullptr)
22048 var_decode_location (attr
, sym
, cu
);
22049 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22051 /* Fortran explicitly imports any global symbols to the local
22052 scope by DW_TAG_common_block. */
22053 if (cu
->language
== language_fortran
&& die
->parent
22054 && die
->parent
->tag
== DW_TAG_common_block
)
22057 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22058 && SYMBOL_VALUE_ADDRESS (sym
) == 0
22059 && !per_objfile
->per_bfd
->has_section_at_zero
)
22061 /* When a static variable is eliminated by the linker,
22062 the corresponding debug information is not stripped
22063 out, but the variable address is set to null;
22064 do not add such variables into symbol table. */
22066 else if (attr2
!= nullptr && attr2
->as_boolean ())
22068 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22069 && (objfile
->flags
& OBJF_MAINLINE
) == 0
22070 && per_objfile
->per_bfd
->can_copy
)
22072 /* A global static variable might be subject to
22073 copy relocation. We first check for a local
22074 minsym, though, because maybe the symbol was
22075 marked hidden, in which case this would not
22077 bound_minimal_symbol found
22078 = (lookup_minimal_symbol_linkage
22079 (sym
->linkage_name (), objfile
));
22080 if (found
.minsym
!= nullptr)
22081 sym
->maybe_copied
= 1;
22084 /* A variable with DW_AT_external is never static,
22085 but it may be block-scoped. */
22087 = ((cu
->list_in_scope
22088 == cu
->get_builder ()->get_file_symbols ())
22089 ? cu
->get_builder ()->get_global_symbols ()
22090 : cu
->list_in_scope
);
22093 list_to_add
= cu
->list_in_scope
;
22097 /* We do not know the address of this symbol.
22098 If it is an external symbol and we have type information
22099 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22100 The address of the variable will then be determined from
22101 the minimal symbol table whenever the variable is
22103 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22105 /* Fortran explicitly imports any global symbols to the local
22106 scope by DW_TAG_common_block. */
22107 if (cu
->language
== language_fortran
&& die
->parent
22108 && die
->parent
->tag
== DW_TAG_common_block
)
22110 /* SYMBOL_CLASS doesn't matter here because
22111 read_common_block is going to reset it. */
22113 list_to_add
= cu
->list_in_scope
;
22115 else if (attr2
!= nullptr && attr2
->as_boolean ()
22116 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22118 /* A variable with DW_AT_external is never static, but it
22119 may be block-scoped. */
22121 = ((cu
->list_in_scope
22122 == cu
->get_builder ()->get_file_symbols ())
22123 ? cu
->get_builder ()->get_global_symbols ()
22124 : cu
->list_in_scope
);
22126 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22128 else if (!die_is_declaration (die
, cu
))
22130 /* Use the default LOC_OPTIMIZED_OUT class. */
22131 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22133 list_to_add
= cu
->list_in_scope
;
22137 case DW_TAG_formal_parameter
:
22139 /* If we are inside a function, mark this as an argument. If
22140 not, we might be looking at an argument to an inlined function
22141 when we do not have enough information to show inlined frames;
22142 pretend it's a local variable in that case so that the user can
22144 struct context_stack
*curr
22145 = cu
->get_builder ()->get_current_context_stack ();
22146 if (curr
!= nullptr && curr
->name
!= nullptr)
22147 SYMBOL_IS_ARGUMENT (sym
) = 1;
22148 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22149 if (attr
!= nullptr)
22151 var_decode_location (attr
, sym
, cu
);
22153 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22154 if (attr
!= nullptr)
22156 dwarf2_const_value (attr
, sym
, cu
);
22159 list_to_add
= cu
->list_in_scope
;
22162 case DW_TAG_unspecified_parameters
:
22163 /* From varargs functions; gdb doesn't seem to have any
22164 interest in this information, so just ignore it for now.
22167 case DW_TAG_template_type_param
:
22169 /* Fall through. */
22170 case DW_TAG_class_type
:
22171 case DW_TAG_interface_type
:
22172 case DW_TAG_structure_type
:
22173 case DW_TAG_union_type
:
22174 case DW_TAG_set_type
:
22175 case DW_TAG_enumeration_type
:
22176 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22177 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22180 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22181 really ever be static objects: otherwise, if you try
22182 to, say, break of a class's method and you're in a file
22183 which doesn't mention that class, it won't work unless
22184 the check for all static symbols in lookup_symbol_aux
22185 saves you. See the OtherFileClass tests in
22186 gdb.c++/namespace.exp. */
22190 buildsym_compunit
*builder
= cu
->get_builder ();
22192 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22193 && cu
->language
== language_cplus
22194 ? builder
->get_global_symbols ()
22195 : cu
->list_in_scope
);
22197 /* The semantics of C++ state that "struct foo {
22198 ... }" also defines a typedef for "foo". */
22199 if (cu
->language
== language_cplus
22200 || cu
->language
== language_ada
22201 || cu
->language
== language_d
22202 || cu
->language
== language_rust
)
22204 /* The symbol's name is already allocated along
22205 with this objfile, so we don't need to
22206 duplicate it for the type. */
22207 if (SYMBOL_TYPE (sym
)->name () == 0)
22208 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
22213 case DW_TAG_typedef
:
22214 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22215 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22216 list_to_add
= cu
->list_in_scope
;
22218 case DW_TAG_array_type
:
22219 case DW_TAG_base_type
:
22220 case DW_TAG_subrange_type
:
22221 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22222 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22223 list_to_add
= cu
->list_in_scope
;
22225 case DW_TAG_enumerator
:
22226 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22227 if (attr
!= nullptr)
22229 dwarf2_const_value (attr
, sym
, cu
);
22232 /* NOTE: carlton/2003-11-10: See comment above in the
22233 DW_TAG_class_type, etc. block. */
22236 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22237 && cu
->language
== language_cplus
22238 ? cu
->get_builder ()->get_global_symbols ()
22239 : cu
->list_in_scope
);
22242 case DW_TAG_imported_declaration
:
22243 case DW_TAG_namespace
:
22244 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22245 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22247 case DW_TAG_module
:
22248 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22249 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22250 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22252 case DW_TAG_common_block
:
22253 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22254 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22255 add_symbol_to_list (sym
, cu
->list_in_scope
);
22258 /* Not a tag we recognize. Hopefully we aren't processing
22259 trash data, but since we must specifically ignore things
22260 we don't recognize, there is nothing else we should do at
22262 complaint (_("unsupported tag: '%s'"),
22263 dwarf_tag_name (die
->tag
));
22269 sym
->hash_next
= objfile
->template_symbols
;
22270 objfile
->template_symbols
= sym
;
22271 list_to_add
= NULL
;
22274 if (list_to_add
!= NULL
)
22275 add_symbol_to_list (sym
, list_to_add
);
22277 /* For the benefit of old versions of GCC, check for anonymous
22278 namespaces based on the demangled name. */
22279 if (!cu
->processing_has_namespace_info
22280 && cu
->language
== language_cplus
)
22281 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22286 /* Given an attr with a DW_FORM_dataN value in host byte order,
22287 zero-extend it as appropriate for the symbol's type. The DWARF
22288 standard (v4) is not entirely clear about the meaning of using
22289 DW_FORM_dataN for a constant with a signed type, where the type is
22290 wider than the data. The conclusion of a discussion on the DWARF
22291 list was that this is unspecified. We choose to always zero-extend
22292 because that is the interpretation long in use by GCC. */
22295 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22296 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22298 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22299 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22300 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22301 LONGEST l
= attr
->constant_value (0);
22303 if (bits
< sizeof (*value
) * 8)
22305 l
&= ((LONGEST
) 1 << bits
) - 1;
22308 else if (bits
== sizeof (*value
) * 8)
22312 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22313 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22320 /* Read a constant value from an attribute. Either set *VALUE, or if
22321 the value does not fit in *VALUE, set *BYTES - either already
22322 allocated on the objfile obstack, or newly allocated on OBSTACK,
22323 or, set *BATON, if we translated the constant to a location
22327 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22328 const char *name
, struct obstack
*obstack
,
22329 struct dwarf2_cu
*cu
,
22330 LONGEST
*value
, const gdb_byte
**bytes
,
22331 struct dwarf2_locexpr_baton
**baton
)
22333 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22334 struct objfile
*objfile
= per_objfile
->objfile
;
22335 struct comp_unit_head
*cu_header
= &cu
->header
;
22336 struct dwarf_block
*blk
;
22337 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22338 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22344 switch (attr
->form
)
22347 case DW_FORM_addrx
:
22348 case DW_FORM_GNU_addr_index
:
22352 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22353 dwarf2_const_value_length_mismatch_complaint (name
,
22354 cu_header
->addr_size
,
22355 TYPE_LENGTH (type
));
22356 /* Symbols of this form are reasonably rare, so we just
22357 piggyback on the existing location code rather than writing
22358 a new implementation of symbol_computed_ops. */
22359 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22360 (*baton
)->per_objfile
= per_objfile
;
22361 (*baton
)->per_cu
= cu
->per_cu
;
22362 gdb_assert ((*baton
)->per_cu
);
22364 (*baton
)->size
= 2 + cu_header
->addr_size
;
22365 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22366 (*baton
)->data
= data
;
22368 data
[0] = DW_OP_addr
;
22369 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22370 byte_order
, attr
->as_address ());
22371 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22374 case DW_FORM_string
:
22377 case DW_FORM_GNU_str_index
:
22378 case DW_FORM_GNU_strp_alt
:
22379 /* The string is already allocated on the objfile obstack, point
22381 *bytes
= (const gdb_byte
*) attr
->as_string ();
22383 case DW_FORM_block1
:
22384 case DW_FORM_block2
:
22385 case DW_FORM_block4
:
22386 case DW_FORM_block
:
22387 case DW_FORM_exprloc
:
22388 case DW_FORM_data16
:
22389 blk
= attr
->as_block ();
22390 if (TYPE_LENGTH (type
) != blk
->size
)
22391 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22392 TYPE_LENGTH (type
));
22393 *bytes
= blk
->data
;
22396 /* The DW_AT_const_value attributes are supposed to carry the
22397 symbol's value "represented as it would be on the target
22398 architecture." By the time we get here, it's already been
22399 converted to host endianness, so we just need to sign- or
22400 zero-extend it as appropriate. */
22401 case DW_FORM_data1
:
22402 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22404 case DW_FORM_data2
:
22405 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22407 case DW_FORM_data4
:
22408 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22410 case DW_FORM_data8
:
22411 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22414 case DW_FORM_sdata
:
22415 case DW_FORM_implicit_const
:
22416 *value
= attr
->as_signed ();
22419 case DW_FORM_udata
:
22420 *value
= attr
->as_unsigned ();
22424 complaint (_("unsupported const value attribute form: '%s'"),
22425 dwarf_form_name (attr
->form
));
22432 /* Copy constant value from an attribute to a symbol. */
22435 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22436 struct dwarf2_cu
*cu
)
22438 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22440 const gdb_byte
*bytes
;
22441 struct dwarf2_locexpr_baton
*baton
;
22443 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22444 sym
->print_name (),
22445 &objfile
->objfile_obstack
, cu
,
22446 &value
, &bytes
, &baton
);
22450 SYMBOL_LOCATION_BATON (sym
) = baton
;
22451 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22453 else if (bytes
!= NULL
)
22455 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22456 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22460 SYMBOL_VALUE (sym
) = value
;
22461 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22465 /* Return the type of the die in question using its DW_AT_type attribute. */
22467 static struct type
*
22468 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22470 struct attribute
*type_attr
;
22472 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22475 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22476 /* A missing DW_AT_type represents a void type. */
22477 return objfile_type (objfile
)->builtin_void
;
22480 return lookup_die_type (die
, type_attr
, cu
);
22483 /* True iff CU's producer generates GNAT Ada auxiliary information
22484 that allows to find parallel types through that information instead
22485 of having to do expensive parallel lookups by type name. */
22488 need_gnat_info (struct dwarf2_cu
*cu
)
22490 /* Assume that the Ada compiler was GNAT, which always produces
22491 the auxiliary information. */
22492 return (cu
->language
== language_ada
);
22495 /* Return the auxiliary type of the die in question using its
22496 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22497 attribute is not present. */
22499 static struct type
*
22500 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22502 struct attribute
*type_attr
;
22504 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22508 return lookup_die_type (die
, type_attr
, cu
);
22511 /* If DIE has a descriptive_type attribute, then set the TYPE's
22512 descriptive type accordingly. */
22515 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22516 struct dwarf2_cu
*cu
)
22518 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22520 if (descriptive_type
)
22522 ALLOCATE_GNAT_AUX_TYPE (type
);
22523 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22527 /* Return the containing type of the die in question using its
22528 DW_AT_containing_type attribute. */
22530 static struct type
*
22531 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22533 struct attribute
*type_attr
;
22534 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22536 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22538 error (_("Dwarf Error: Problem turning containing type into gdb type "
22539 "[in module %s]"), objfile_name (objfile
));
22541 return lookup_die_type (die
, type_attr
, cu
);
22544 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22546 static struct type
*
22547 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22549 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22550 struct objfile
*objfile
= per_objfile
->objfile
;
22553 std::string message
22554 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22555 objfile_name (objfile
),
22556 sect_offset_str (cu
->header
.sect_off
),
22557 sect_offset_str (die
->sect_off
));
22558 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22560 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22563 /* Look up the type of DIE in CU using its type attribute ATTR.
22564 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22565 DW_AT_containing_type.
22566 If there is no type substitute an error marker. */
22568 static struct type
*
22569 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22570 struct dwarf2_cu
*cu
)
22572 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22573 struct objfile
*objfile
= per_objfile
->objfile
;
22574 struct type
*this_type
;
22576 gdb_assert (attr
->name
== DW_AT_type
22577 || attr
->name
== DW_AT_GNAT_descriptive_type
22578 || attr
->name
== DW_AT_containing_type
);
22580 /* First see if we have it cached. */
22582 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22584 struct dwarf2_per_cu_data
*per_cu
;
22585 sect_offset sect_off
= attr
->get_ref_die_offset ();
22587 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22588 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22590 else if (attr
->form_is_ref ())
22592 sect_offset sect_off
= attr
->get_ref_die_offset ();
22594 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22596 else if (attr
->form
== DW_FORM_ref_sig8
)
22598 ULONGEST signature
= attr
->as_signature ();
22600 return get_signatured_type (die
, signature
, cu
);
22604 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22605 " at %s [in module %s]"),
22606 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22607 objfile_name (objfile
));
22608 return build_error_marker_type (cu
, die
);
22611 /* If not cached we need to read it in. */
22613 if (this_type
== NULL
)
22615 struct die_info
*type_die
= NULL
;
22616 struct dwarf2_cu
*type_cu
= cu
;
22618 if (attr
->form_is_ref ())
22619 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22620 if (type_die
== NULL
)
22621 return build_error_marker_type (cu
, die
);
22622 /* If we find the type now, it's probably because the type came
22623 from an inter-CU reference and the type's CU got expanded before
22625 this_type
= read_type_die (type_die
, type_cu
);
22628 /* If we still don't have a type use an error marker. */
22630 if (this_type
== NULL
)
22631 return build_error_marker_type (cu
, die
);
22636 /* Return the type in DIE, CU.
22637 Returns NULL for invalid types.
22639 This first does a lookup in die_type_hash,
22640 and only reads the die in if necessary.
22642 NOTE: This can be called when reading in partial or full symbols. */
22644 static struct type
*
22645 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22647 struct type
*this_type
;
22649 this_type
= get_die_type (die
, cu
);
22653 return read_type_die_1 (die
, cu
);
22656 /* Read the type in DIE, CU.
22657 Returns NULL for invalid types. */
22659 static struct type
*
22660 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22662 struct type
*this_type
= NULL
;
22666 case DW_TAG_class_type
:
22667 case DW_TAG_interface_type
:
22668 case DW_TAG_structure_type
:
22669 case DW_TAG_union_type
:
22670 this_type
= read_structure_type (die
, cu
);
22672 case DW_TAG_enumeration_type
:
22673 this_type
= read_enumeration_type (die
, cu
);
22675 case DW_TAG_subprogram
:
22676 case DW_TAG_subroutine_type
:
22677 case DW_TAG_inlined_subroutine
:
22678 this_type
= read_subroutine_type (die
, cu
);
22680 case DW_TAG_array_type
:
22681 this_type
= read_array_type (die
, cu
);
22683 case DW_TAG_set_type
:
22684 this_type
= read_set_type (die
, cu
);
22686 case DW_TAG_pointer_type
:
22687 this_type
= read_tag_pointer_type (die
, cu
);
22689 case DW_TAG_ptr_to_member_type
:
22690 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22692 case DW_TAG_reference_type
:
22693 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22695 case DW_TAG_rvalue_reference_type
:
22696 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22698 case DW_TAG_const_type
:
22699 this_type
= read_tag_const_type (die
, cu
);
22701 case DW_TAG_volatile_type
:
22702 this_type
= read_tag_volatile_type (die
, cu
);
22704 case DW_TAG_restrict_type
:
22705 this_type
= read_tag_restrict_type (die
, cu
);
22707 case DW_TAG_string_type
:
22708 this_type
= read_tag_string_type (die
, cu
);
22710 case DW_TAG_typedef
:
22711 this_type
= read_typedef (die
, cu
);
22713 case DW_TAG_subrange_type
:
22714 this_type
= read_subrange_type (die
, cu
);
22716 case DW_TAG_base_type
:
22717 this_type
= read_base_type (die
, cu
);
22719 case DW_TAG_unspecified_type
:
22720 this_type
= read_unspecified_type (die
, cu
);
22722 case DW_TAG_namespace
:
22723 this_type
= read_namespace_type (die
, cu
);
22725 case DW_TAG_module
:
22726 this_type
= read_module_type (die
, cu
);
22728 case DW_TAG_atomic_type
:
22729 this_type
= read_tag_atomic_type (die
, cu
);
22732 complaint (_("unexpected tag in read_type_die: '%s'"),
22733 dwarf_tag_name (die
->tag
));
22740 /* See if we can figure out if the class lives in a namespace. We do
22741 this by looking for a member function; its demangled name will
22742 contain namespace info, if there is any.
22743 Return the computed name or NULL.
22744 Space for the result is allocated on the objfile's obstack.
22745 This is the full-die version of guess_partial_die_structure_name.
22746 In this case we know DIE has no useful parent. */
22748 static const char *
22749 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22751 struct die_info
*spec_die
;
22752 struct dwarf2_cu
*spec_cu
;
22753 struct die_info
*child
;
22754 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22757 spec_die
= die_specification (die
, &spec_cu
);
22758 if (spec_die
!= NULL
)
22764 for (child
= die
->child
;
22766 child
= child
->sibling
)
22768 if (child
->tag
== DW_TAG_subprogram
)
22770 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22772 if (linkage_name
!= NULL
)
22774 gdb::unique_xmalloc_ptr
<char> actual_name
22775 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22776 const char *name
= NULL
;
22778 if (actual_name
!= NULL
)
22780 const char *die_name
= dwarf2_name (die
, cu
);
22782 if (die_name
!= NULL
22783 && strcmp (die_name
, actual_name
.get ()) != 0)
22785 /* Strip off the class name from the full name.
22786 We want the prefix. */
22787 int die_name_len
= strlen (die_name
);
22788 int actual_name_len
= strlen (actual_name
.get ());
22789 const char *ptr
= actual_name
.get ();
22791 /* Test for '::' as a sanity check. */
22792 if (actual_name_len
> die_name_len
+ 2
22793 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22794 name
= obstack_strndup (
22795 &objfile
->per_bfd
->storage_obstack
,
22796 ptr
, actual_name_len
- die_name_len
- 2);
22807 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22808 prefix part in such case. See
22809 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22811 static const char *
22812 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22814 struct attribute
*attr
;
22817 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22818 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22821 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22824 attr
= dw2_linkage_name_attr (die
, cu
);
22825 const char *attr_name
= attr
->as_string ();
22826 if (attr
== NULL
|| attr_name
== NULL
)
22829 /* dwarf2_name had to be already called. */
22830 gdb_assert (attr
->canonical_string_p ());
22832 /* Strip the base name, keep any leading namespaces/classes. */
22833 base
= strrchr (attr_name
, ':');
22834 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22837 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22838 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22840 &base
[-1] - attr_name
);
22843 /* Return the name of the namespace/class that DIE is defined within,
22844 or "" if we can't tell. The caller should not xfree the result.
22846 For example, if we're within the method foo() in the following
22856 then determine_prefix on foo's die will return "N::C". */
22858 static const char *
22859 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22861 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22862 struct die_info
*parent
, *spec_die
;
22863 struct dwarf2_cu
*spec_cu
;
22864 struct type
*parent_type
;
22865 const char *retval
;
22867 if (cu
->language
!= language_cplus
22868 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22869 && cu
->language
!= language_rust
)
22872 retval
= anonymous_struct_prefix (die
, cu
);
22876 /* We have to be careful in the presence of DW_AT_specification.
22877 For example, with GCC 3.4, given the code
22881 // Definition of N::foo.
22885 then we'll have a tree of DIEs like this:
22887 1: DW_TAG_compile_unit
22888 2: DW_TAG_namespace // N
22889 3: DW_TAG_subprogram // declaration of N::foo
22890 4: DW_TAG_subprogram // definition of N::foo
22891 DW_AT_specification // refers to die #3
22893 Thus, when processing die #4, we have to pretend that we're in
22894 the context of its DW_AT_specification, namely the contex of die
22897 spec_die
= die_specification (die
, &spec_cu
);
22898 if (spec_die
== NULL
)
22899 parent
= die
->parent
;
22902 parent
= spec_die
->parent
;
22906 if (parent
== NULL
)
22908 else if (parent
->building_fullname
)
22911 const char *parent_name
;
22913 /* It has been seen on RealView 2.2 built binaries,
22914 DW_TAG_template_type_param types actually _defined_ as
22915 children of the parent class:
22918 template class <class Enum> Class{};
22919 Class<enum E> class_e;
22921 1: DW_TAG_class_type (Class)
22922 2: DW_TAG_enumeration_type (E)
22923 3: DW_TAG_enumerator (enum1:0)
22924 3: DW_TAG_enumerator (enum2:1)
22926 2: DW_TAG_template_type_param
22927 DW_AT_type DW_FORM_ref_udata (E)
22929 Besides being broken debug info, it can put GDB into an
22930 infinite loop. Consider:
22932 When we're building the full name for Class<E>, we'll start
22933 at Class, and go look over its template type parameters,
22934 finding E. We'll then try to build the full name of E, and
22935 reach here. We're now trying to build the full name of E,
22936 and look over the parent DIE for containing scope. In the
22937 broken case, if we followed the parent DIE of E, we'd again
22938 find Class, and once again go look at its template type
22939 arguments, etc., etc. Simply don't consider such parent die
22940 as source-level parent of this die (it can't be, the language
22941 doesn't allow it), and break the loop here. */
22942 name
= dwarf2_name (die
, cu
);
22943 parent_name
= dwarf2_name (parent
, cu
);
22944 complaint (_("template param type '%s' defined within parent '%s'"),
22945 name
? name
: "<unknown>",
22946 parent_name
? parent_name
: "<unknown>");
22950 switch (parent
->tag
)
22952 case DW_TAG_namespace
:
22953 parent_type
= read_type_die (parent
, cu
);
22954 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22955 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22956 Work around this problem here. */
22957 if (cu
->language
== language_cplus
22958 && strcmp (parent_type
->name (), "::") == 0)
22960 /* We give a name to even anonymous namespaces. */
22961 return parent_type
->name ();
22962 case DW_TAG_class_type
:
22963 case DW_TAG_interface_type
:
22964 case DW_TAG_structure_type
:
22965 case DW_TAG_union_type
:
22966 case DW_TAG_module
:
22967 parent_type
= read_type_die (parent
, cu
);
22968 if (parent_type
->name () != NULL
)
22969 return parent_type
->name ();
22971 /* An anonymous structure is only allowed non-static data
22972 members; no typedefs, no member functions, et cetera.
22973 So it does not need a prefix. */
22975 case DW_TAG_compile_unit
:
22976 case DW_TAG_partial_unit
:
22977 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22978 if (cu
->language
== language_cplus
22979 && !per_objfile
->per_bfd
->types
.empty ()
22980 && die
->child
!= NULL
22981 && (die
->tag
== DW_TAG_class_type
22982 || die
->tag
== DW_TAG_structure_type
22983 || die
->tag
== DW_TAG_union_type
))
22985 const char *name
= guess_full_die_structure_name (die
, cu
);
22990 case DW_TAG_subprogram
:
22991 /* Nested subroutines in Fortran get a prefix with the name
22992 of the parent's subroutine. */
22993 if (cu
->language
== language_fortran
)
22995 if ((die
->tag
== DW_TAG_subprogram
)
22996 && (dwarf2_name (parent
, cu
) != NULL
))
22997 return dwarf2_name (parent
, cu
);
22999 return determine_prefix (parent
, cu
);
23000 case DW_TAG_enumeration_type
:
23001 parent_type
= read_type_die (parent
, cu
);
23002 if (TYPE_DECLARED_CLASS (parent_type
))
23004 if (parent_type
->name () != NULL
)
23005 return parent_type
->name ();
23008 /* Fall through. */
23010 return determine_prefix (parent
, cu
);
23014 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
23015 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
23016 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
23017 an obconcat, otherwise allocate storage for the result. The CU argument is
23018 used to determine the language and hence, the appropriate separator. */
23020 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
23023 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
23024 int physname
, struct dwarf2_cu
*cu
)
23026 const char *lead
= "";
23029 if (suffix
== NULL
|| suffix
[0] == '\0'
23030 || prefix
== NULL
|| prefix
[0] == '\0')
23032 else if (cu
->language
== language_d
)
23034 /* For D, the 'main' function could be defined in any module, but it
23035 should never be prefixed. */
23036 if (strcmp (suffix
, "D main") == 0)
23044 else if (cu
->language
== language_fortran
&& physname
)
23046 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
23047 DW_AT_MIPS_linkage_name is preferred and used instead. */
23055 if (prefix
== NULL
)
23057 if (suffix
== NULL
)
23064 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
23066 strcpy (retval
, lead
);
23067 strcat (retval
, prefix
);
23068 strcat (retval
, sep
);
23069 strcat (retval
, suffix
);
23074 /* We have an obstack. */
23075 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
23079 /* Get name of a die, return NULL if not found. */
23081 static const char *
23082 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
23083 struct objfile
*objfile
)
23085 if (name
&& cu
->language
== language_cplus
)
23087 gdb::unique_xmalloc_ptr
<char> canon_name
23088 = cp_canonicalize_string (name
);
23090 if (canon_name
!= nullptr)
23091 name
= objfile
->intern (canon_name
.get ());
23097 /* Get name of a die, return NULL if not found.
23098 Anonymous namespaces are converted to their magic string. */
23100 static const char *
23101 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23103 struct attribute
*attr
;
23104 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23106 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23107 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23108 if (attr_name
== nullptr
23109 && die
->tag
!= DW_TAG_namespace
23110 && die
->tag
!= DW_TAG_class_type
23111 && die
->tag
!= DW_TAG_interface_type
23112 && die
->tag
!= DW_TAG_structure_type
23113 && die
->tag
!= DW_TAG_union_type
)
23118 case DW_TAG_compile_unit
:
23119 case DW_TAG_partial_unit
:
23120 /* Compilation units have a DW_AT_name that is a filename, not
23121 a source language identifier. */
23122 case DW_TAG_enumeration_type
:
23123 case DW_TAG_enumerator
:
23124 /* These tags always have simple identifiers already; no need
23125 to canonicalize them. */
23128 case DW_TAG_namespace
:
23129 if (attr_name
!= nullptr)
23131 return CP_ANONYMOUS_NAMESPACE_STR
;
23133 case DW_TAG_class_type
:
23134 case DW_TAG_interface_type
:
23135 case DW_TAG_structure_type
:
23136 case DW_TAG_union_type
:
23137 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23138 structures or unions. These were of the form "._%d" in GCC 4.1,
23139 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23140 and GCC 4.4. We work around this problem by ignoring these. */
23141 if (attr_name
!= nullptr
23142 && (startswith (attr_name
, "._")
23143 || startswith (attr_name
, "<anonymous")))
23146 /* GCC might emit a nameless typedef that has a linkage name. See
23147 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23148 if (!attr
|| attr_name
== NULL
)
23150 attr
= dw2_linkage_name_attr (die
, cu
);
23151 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23152 if (attr
== NULL
|| attr_name
== NULL
)
23155 /* Avoid demangling attr_name the second time on a second
23156 call for the same DIE. */
23157 if (!attr
->canonical_string_p ())
23159 gdb::unique_xmalloc_ptr
<char> demangled
23160 (gdb_demangle (attr_name
, DMGL_TYPES
));
23161 if (demangled
== nullptr)
23164 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
23165 attr_name
= attr
->as_string ();
23168 /* Strip any leading namespaces/classes, keep only the
23169 base name. DW_AT_name for named DIEs does not
23170 contain the prefixes. */
23171 const char *base
= strrchr (attr_name
, ':');
23172 if (base
&& base
> attr_name
&& base
[-1] == ':')
23183 if (!attr
->canonical_string_p ())
23184 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
23186 return attr
->as_string ();
23189 /* Return the die that this die in an extension of, or NULL if there
23190 is none. *EXT_CU is the CU containing DIE on input, and the CU
23191 containing the return value on output. */
23193 static struct die_info
*
23194 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23196 struct attribute
*attr
;
23198 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23202 return follow_die_ref (die
, attr
, ext_cu
);
23206 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23210 print_spaces (indent
, f
);
23211 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23212 dwarf_tag_name (die
->tag
), die
->abbrev
,
23213 sect_offset_str (die
->sect_off
));
23215 if (die
->parent
!= NULL
)
23217 print_spaces (indent
, f
);
23218 fprintf_unfiltered (f
, " parent at offset: %s\n",
23219 sect_offset_str (die
->parent
->sect_off
));
23222 print_spaces (indent
, f
);
23223 fprintf_unfiltered (f
, " has children: %s\n",
23224 dwarf_bool_name (die
->child
!= NULL
));
23226 print_spaces (indent
, f
);
23227 fprintf_unfiltered (f
, " attributes:\n");
23229 for (i
= 0; i
< die
->num_attrs
; ++i
)
23231 print_spaces (indent
, f
);
23232 fprintf_unfiltered (f
, " %s (%s) ",
23233 dwarf_attr_name (die
->attrs
[i
].name
),
23234 dwarf_form_name (die
->attrs
[i
].form
));
23236 switch (die
->attrs
[i
].form
)
23239 case DW_FORM_addrx
:
23240 case DW_FORM_GNU_addr_index
:
23241 fprintf_unfiltered (f
, "address: ");
23242 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
23244 case DW_FORM_block2
:
23245 case DW_FORM_block4
:
23246 case DW_FORM_block
:
23247 case DW_FORM_block1
:
23248 fprintf_unfiltered (f
, "block: size %s",
23249 pulongest (die
->attrs
[i
].as_block ()->size
));
23251 case DW_FORM_exprloc
:
23252 fprintf_unfiltered (f
, "expression: size %s",
23253 pulongest (die
->attrs
[i
].as_block ()->size
));
23255 case DW_FORM_data16
:
23256 fprintf_unfiltered (f
, "constant of 16 bytes");
23258 case DW_FORM_ref_addr
:
23259 fprintf_unfiltered (f
, "ref address: ");
23260 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23262 case DW_FORM_GNU_ref_alt
:
23263 fprintf_unfiltered (f
, "alt ref address: ");
23264 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23270 case DW_FORM_ref_udata
:
23271 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23272 (long) (die
->attrs
[i
].as_unsigned ()));
23274 case DW_FORM_data1
:
23275 case DW_FORM_data2
:
23276 case DW_FORM_data4
:
23277 case DW_FORM_data8
:
23278 case DW_FORM_udata
:
23279 fprintf_unfiltered (f
, "constant: %s",
23280 pulongest (die
->attrs
[i
].as_unsigned ()));
23282 case DW_FORM_sec_offset
:
23283 fprintf_unfiltered (f
, "section offset: %s",
23284 pulongest (die
->attrs
[i
].as_unsigned ()));
23286 case DW_FORM_ref_sig8
:
23287 fprintf_unfiltered (f
, "signature: %s",
23288 hex_string (die
->attrs
[i
].as_signature ()));
23290 case DW_FORM_string
:
23292 case DW_FORM_line_strp
:
23294 case DW_FORM_GNU_str_index
:
23295 case DW_FORM_GNU_strp_alt
:
23296 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23297 die
->attrs
[i
].as_string ()
23298 ? die
->attrs
[i
].as_string () : "",
23299 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23302 if (die
->attrs
[i
].as_boolean ())
23303 fprintf_unfiltered (f
, "flag: TRUE");
23305 fprintf_unfiltered (f
, "flag: FALSE");
23307 case DW_FORM_flag_present
:
23308 fprintf_unfiltered (f
, "flag: TRUE");
23310 case DW_FORM_indirect
:
23311 /* The reader will have reduced the indirect form to
23312 the "base form" so this form should not occur. */
23313 fprintf_unfiltered (f
,
23314 "unexpected attribute form: DW_FORM_indirect");
23316 case DW_FORM_sdata
:
23317 case DW_FORM_implicit_const
:
23318 fprintf_unfiltered (f
, "constant: %s",
23319 plongest (die
->attrs
[i
].as_signed ()));
23322 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23323 die
->attrs
[i
].form
);
23326 fprintf_unfiltered (f
, "\n");
23331 dump_die_for_error (struct die_info
*die
)
23333 dump_die_shallow (gdb_stderr
, 0, die
);
23337 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23339 int indent
= level
* 4;
23341 gdb_assert (die
!= NULL
);
23343 if (level
>= max_level
)
23346 dump_die_shallow (f
, indent
, die
);
23348 if (die
->child
!= NULL
)
23350 print_spaces (indent
, f
);
23351 fprintf_unfiltered (f
, " Children:");
23352 if (level
+ 1 < max_level
)
23354 fprintf_unfiltered (f
, "\n");
23355 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23359 fprintf_unfiltered (f
,
23360 " [not printed, max nesting level reached]\n");
23364 if (die
->sibling
!= NULL
&& level
> 0)
23366 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23370 /* This is called from the pdie macro in gdbinit.in.
23371 It's not static so gcc will keep a copy callable from gdb. */
23374 dump_die (struct die_info
*die
, int max_level
)
23376 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23380 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23384 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23385 to_underlying (die
->sect_off
),
23391 /* Follow reference or signature attribute ATTR of SRC_DIE.
23392 On entry *REF_CU is the CU of SRC_DIE.
23393 On exit *REF_CU is the CU of the result. */
23395 static struct die_info
*
23396 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23397 struct dwarf2_cu
**ref_cu
)
23399 struct die_info
*die
;
23401 if (attr
->form_is_ref ())
23402 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23403 else if (attr
->form
== DW_FORM_ref_sig8
)
23404 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23407 dump_die_for_error (src_die
);
23408 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23409 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23415 /* Follow reference OFFSET.
23416 On entry *REF_CU is the CU of the source die referencing OFFSET.
23417 On exit *REF_CU is the CU of the result.
23418 Returns NULL if OFFSET is invalid. */
23420 static struct die_info
*
23421 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23422 struct dwarf2_cu
**ref_cu
)
23424 struct die_info temp_die
;
23425 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23426 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23428 gdb_assert (cu
->per_cu
!= NULL
);
23432 if (cu
->per_cu
->is_debug_types
)
23434 /* .debug_types CUs cannot reference anything outside their CU.
23435 If they need to, they have to reference a signatured type via
23436 DW_FORM_ref_sig8. */
23437 if (!cu
->header
.offset_in_cu_p (sect_off
))
23440 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23441 || !cu
->header
.offset_in_cu_p (sect_off
))
23443 struct dwarf2_per_cu_data
*per_cu
;
23445 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23448 /* If necessary, add it to the queue and load its DIEs. */
23449 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
23450 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23451 false, cu
->language
);
23453 target_cu
= per_objfile
->get_cu (per_cu
);
23455 else if (cu
->dies
== NULL
)
23457 /* We're loading full DIEs during partial symbol reading. */
23458 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23459 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23463 *ref_cu
= target_cu
;
23464 temp_die
.sect_off
= sect_off
;
23466 if (target_cu
!= cu
)
23467 target_cu
->ancestor
= cu
;
23469 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23471 to_underlying (sect_off
));
23474 /* Follow reference attribute ATTR of SRC_DIE.
23475 On entry *REF_CU is the CU of SRC_DIE.
23476 On exit *REF_CU is the CU of the result. */
23478 static struct die_info
*
23479 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23480 struct dwarf2_cu
**ref_cu
)
23482 sect_offset sect_off
= attr
->get_ref_die_offset ();
23483 struct dwarf2_cu
*cu
= *ref_cu
;
23484 struct die_info
*die
;
23486 die
= follow_die_offset (sect_off
,
23487 (attr
->form
== DW_FORM_GNU_ref_alt
23488 || cu
->per_cu
->is_dwz
),
23491 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23492 "at %s [in module %s]"),
23493 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23494 objfile_name (cu
->per_objfile
->objfile
));
23501 struct dwarf2_locexpr_baton
23502 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23503 dwarf2_per_cu_data
*per_cu
,
23504 dwarf2_per_objfile
*per_objfile
,
23505 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23506 bool resolve_abstract_p
)
23508 struct die_info
*die
;
23509 struct attribute
*attr
;
23510 struct dwarf2_locexpr_baton retval
;
23511 struct objfile
*objfile
= per_objfile
->objfile
;
23513 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23515 cu
= load_cu (per_cu
, per_objfile
, false);
23519 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23520 Instead just throw an error, not much else we can do. */
23521 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23522 sect_offset_str (sect_off
), objfile_name (objfile
));
23525 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23527 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23528 sect_offset_str (sect_off
), objfile_name (objfile
));
23530 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23531 if (!attr
&& resolve_abstract_p
23532 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23533 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23535 CORE_ADDR pc
= get_frame_pc ();
23536 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23537 struct gdbarch
*gdbarch
= objfile
->arch ();
23539 for (const auto &cand_off
23540 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23542 struct dwarf2_cu
*cand_cu
= cu
;
23543 struct die_info
*cand
23544 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23547 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23550 CORE_ADDR pc_low
, pc_high
;
23551 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23552 if (pc_low
== ((CORE_ADDR
) -1))
23554 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23555 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23556 if (!(pc_low
<= pc
&& pc
< pc_high
))
23560 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23567 /* DWARF: "If there is no such attribute, then there is no effect.".
23568 DATA is ignored if SIZE is 0. */
23570 retval
.data
= NULL
;
23573 else if (attr
->form_is_section_offset ())
23575 struct dwarf2_loclist_baton loclist_baton
;
23576 CORE_ADDR pc
= get_frame_pc ();
23579 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23581 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23583 retval
.size
= size
;
23587 if (!attr
->form_is_block ())
23588 error (_("Dwarf Error: DIE at %s referenced in module %s "
23589 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23590 sect_offset_str (sect_off
), objfile_name (objfile
));
23592 struct dwarf_block
*block
= attr
->as_block ();
23593 retval
.data
= block
->data
;
23594 retval
.size
= block
->size
;
23596 retval
.per_objfile
= per_objfile
;
23597 retval
.per_cu
= cu
->per_cu
;
23599 per_objfile
->age_comp_units ();
23606 struct dwarf2_locexpr_baton
23607 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23608 dwarf2_per_cu_data
*per_cu
,
23609 dwarf2_per_objfile
*per_objfile
,
23610 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23612 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23614 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23618 /* Write a constant of a given type as target-ordered bytes into
23621 static const gdb_byte
*
23622 write_constant_as_bytes (struct obstack
*obstack
,
23623 enum bfd_endian byte_order
,
23630 *len
= TYPE_LENGTH (type
);
23631 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23632 store_unsigned_integer (result
, *len
, byte_order
, value
);
23640 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23641 dwarf2_per_cu_data
*per_cu
,
23642 dwarf2_per_objfile
*per_objfile
,
23646 struct die_info
*die
;
23647 struct attribute
*attr
;
23648 const gdb_byte
*result
= NULL
;
23651 enum bfd_endian byte_order
;
23652 struct objfile
*objfile
= per_objfile
->objfile
;
23654 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23656 cu
= load_cu (per_cu
, per_objfile
, false);
23660 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23661 Instead just throw an error, not much else we can do. */
23662 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23663 sect_offset_str (sect_off
), objfile_name (objfile
));
23666 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23668 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23669 sect_offset_str (sect_off
), objfile_name (objfile
));
23671 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23675 byte_order
= (bfd_big_endian (objfile
->obfd
)
23676 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23678 switch (attr
->form
)
23681 case DW_FORM_addrx
:
23682 case DW_FORM_GNU_addr_index
:
23686 *len
= cu
->header
.addr_size
;
23687 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23688 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23692 case DW_FORM_string
:
23695 case DW_FORM_GNU_str_index
:
23696 case DW_FORM_GNU_strp_alt
:
23697 /* The string is already allocated on the objfile obstack, point
23700 const char *attr_name
= attr
->as_string ();
23701 result
= (const gdb_byte
*) attr_name
;
23702 *len
= strlen (attr_name
);
23705 case DW_FORM_block1
:
23706 case DW_FORM_block2
:
23707 case DW_FORM_block4
:
23708 case DW_FORM_block
:
23709 case DW_FORM_exprloc
:
23710 case DW_FORM_data16
:
23712 struct dwarf_block
*block
= attr
->as_block ();
23713 result
= block
->data
;
23714 *len
= block
->size
;
23718 /* The DW_AT_const_value attributes are supposed to carry the
23719 symbol's value "represented as it would be on the target
23720 architecture." By the time we get here, it's already been
23721 converted to host endianness, so we just need to sign- or
23722 zero-extend it as appropriate. */
23723 case DW_FORM_data1
:
23724 type
= die_type (die
, cu
);
23725 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23726 if (result
== NULL
)
23727 result
= write_constant_as_bytes (obstack
, byte_order
,
23730 case DW_FORM_data2
:
23731 type
= die_type (die
, cu
);
23732 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23733 if (result
== NULL
)
23734 result
= write_constant_as_bytes (obstack
, byte_order
,
23737 case DW_FORM_data4
:
23738 type
= die_type (die
, cu
);
23739 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23740 if (result
== NULL
)
23741 result
= write_constant_as_bytes (obstack
, byte_order
,
23744 case DW_FORM_data8
:
23745 type
= die_type (die
, cu
);
23746 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23747 if (result
== NULL
)
23748 result
= write_constant_as_bytes (obstack
, byte_order
,
23752 case DW_FORM_sdata
:
23753 case DW_FORM_implicit_const
:
23754 type
= die_type (die
, cu
);
23755 result
= write_constant_as_bytes (obstack
, byte_order
,
23756 type
, attr
->as_signed (), len
);
23759 case DW_FORM_udata
:
23760 type
= die_type (die
, cu
);
23761 result
= write_constant_as_bytes (obstack
, byte_order
,
23762 type
, attr
->as_unsigned (), len
);
23766 complaint (_("unsupported const value attribute form: '%s'"),
23767 dwarf_form_name (attr
->form
));
23777 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23778 dwarf2_per_cu_data
*per_cu
,
23779 dwarf2_per_objfile
*per_objfile
)
23781 struct die_info
*die
;
23783 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23785 cu
= load_cu (per_cu
, per_objfile
, false);
23790 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23794 return die_type (die
, cu
);
23800 dwarf2_get_die_type (cu_offset die_offset
,
23801 dwarf2_per_cu_data
*per_cu
,
23802 dwarf2_per_objfile
*per_objfile
)
23804 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23805 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23808 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23809 On entry *REF_CU is the CU of SRC_DIE.
23810 On exit *REF_CU is the CU of the result.
23811 Returns NULL if the referenced DIE isn't found. */
23813 static struct die_info
*
23814 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23815 struct dwarf2_cu
**ref_cu
)
23817 struct die_info temp_die
;
23818 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23819 struct die_info
*die
;
23820 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23823 /* While it might be nice to assert sig_type->type == NULL here,
23824 we can get here for DW_AT_imported_declaration where we need
23825 the DIE not the type. */
23827 /* If necessary, add it to the queue and load its DIEs. */
23829 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
23831 read_signatured_type (sig_type
, per_objfile
);
23833 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
23834 gdb_assert (sig_cu
!= NULL
);
23835 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23836 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23837 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23838 to_underlying (temp_die
.sect_off
));
23841 /* For .gdb_index version 7 keep track of included TUs.
23842 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23843 if (per_objfile
->per_bfd
->index_table
!= NULL
23844 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23846 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23851 sig_cu
->ancestor
= cu
;
23859 /* Follow signatured type referenced by ATTR in SRC_DIE.
23860 On entry *REF_CU is the CU of SRC_DIE.
23861 On exit *REF_CU is the CU of the result.
23862 The result is the DIE of the type.
23863 If the referenced type cannot be found an error is thrown. */
23865 static struct die_info
*
23866 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23867 struct dwarf2_cu
**ref_cu
)
23869 ULONGEST signature
= attr
->as_signature ();
23870 struct signatured_type
*sig_type
;
23871 struct die_info
*die
;
23873 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23875 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23876 /* sig_type will be NULL if the signatured type is missing from
23878 if (sig_type
== NULL
)
23880 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23881 " from DIE at %s [in module %s]"),
23882 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23883 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23886 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23889 dump_die_for_error (src_die
);
23890 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23891 " from DIE at %s [in module %s]"),
23892 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23893 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23899 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23900 reading in and processing the type unit if necessary. */
23902 static struct type
*
23903 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23904 struct dwarf2_cu
*cu
)
23906 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23907 struct signatured_type
*sig_type
;
23908 struct dwarf2_cu
*type_cu
;
23909 struct die_info
*type_die
;
23912 sig_type
= lookup_signatured_type (cu
, signature
);
23913 /* sig_type will be NULL if the signatured type is missing from
23915 if (sig_type
== NULL
)
23917 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23918 " from DIE at %s [in module %s]"),
23919 hex_string (signature
), sect_offset_str (die
->sect_off
),
23920 objfile_name (per_objfile
->objfile
));
23921 return build_error_marker_type (cu
, die
);
23924 /* If we already know the type we're done. */
23925 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23926 if (type
!= nullptr)
23930 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23931 if (type_die
!= NULL
)
23933 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23934 is created. This is important, for example, because for c++ classes
23935 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23936 type
= read_type_die (type_die
, type_cu
);
23939 complaint (_("Dwarf Error: Cannot build signatured type %s"
23940 " referenced from DIE at %s [in module %s]"),
23941 hex_string (signature
), sect_offset_str (die
->sect_off
),
23942 objfile_name (per_objfile
->objfile
));
23943 type
= build_error_marker_type (cu
, die
);
23948 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23949 " from DIE at %s [in module %s]"),
23950 hex_string (signature
), sect_offset_str (die
->sect_off
),
23951 objfile_name (per_objfile
->objfile
));
23952 type
= build_error_marker_type (cu
, die
);
23955 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23960 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23961 reading in and processing the type unit if necessary. */
23963 static struct type
*
23964 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23965 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23967 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23968 if (attr
->form_is_ref ())
23970 struct dwarf2_cu
*type_cu
= cu
;
23971 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23973 return read_type_die (type_die
, type_cu
);
23975 else if (attr
->form
== DW_FORM_ref_sig8
)
23977 return get_signatured_type (die
, attr
->as_signature (), cu
);
23981 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23983 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23984 " at %s [in module %s]"),
23985 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23986 objfile_name (per_objfile
->objfile
));
23987 return build_error_marker_type (cu
, die
);
23991 /* Load the DIEs associated with type unit PER_CU into memory. */
23994 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23995 dwarf2_per_objfile
*per_objfile
)
23997 struct signatured_type
*sig_type
;
23999 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24000 gdb_assert (! per_cu
->type_unit_group_p ());
24002 /* We have the per_cu, but we need the signatured_type.
24003 Fortunately this is an easy translation. */
24004 gdb_assert (per_cu
->is_debug_types
);
24005 sig_type
= (struct signatured_type
*) per_cu
;
24007 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
24009 read_signatured_type (sig_type
, per_objfile
);
24011 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
24014 /* Read in a signatured type and build its CU and DIEs.
24015 If the type is a stub for the real type in a DWO file,
24016 read in the real type from the DWO file as well. */
24019 read_signatured_type (signatured_type
*sig_type
,
24020 dwarf2_per_objfile
*per_objfile
)
24022 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24024 gdb_assert (per_cu
->is_debug_types
);
24025 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
24027 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
24029 if (!reader
.dummy_p
)
24031 struct dwarf2_cu
*cu
= reader
.cu
;
24032 const gdb_byte
*info_ptr
= reader
.info_ptr
;
24034 gdb_assert (cu
->die_hash
== NULL
);
24036 htab_create_alloc_ex (cu
->header
.length
/ 12,
24040 &cu
->comp_unit_obstack
,
24041 hashtab_obstack_allocate
,
24042 dummy_obstack_deallocate
);
24044 if (reader
.comp_unit_die
->has_children
)
24045 reader
.comp_unit_die
->child
24046 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
24047 reader
.comp_unit_die
);
24048 cu
->dies
= reader
.comp_unit_die
;
24049 /* comp_unit_die is not stored in die_hash, no need. */
24051 /* We try not to read any attributes in this function, because
24052 not all CUs needed for references have been loaded yet, and
24053 symbol table processing isn't initialized. But we have to
24054 set the CU language, or we won't be able to build types
24055 correctly. Similarly, if we do not read the producer, we can
24056 not apply producer-specific interpretation. */
24057 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24062 sig_type
->per_cu
.tu_read
= 1;
24065 /* Decode simple location descriptions.
24066 Given a pointer to a dwarf block that defines a location, compute
24067 the location and return the value. If COMPUTED is non-null, it is
24068 set to true to indicate that decoding was successful, and false
24069 otherwise. If COMPUTED is null, then this function may emit a
24073 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
24075 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
24077 size_t size
= blk
->size
;
24078 const gdb_byte
*data
= blk
->data
;
24079 CORE_ADDR stack
[64];
24081 unsigned int bytes_read
, unsnd
;
24084 if (computed
!= nullptr)
24090 stack
[++stacki
] = 0;
24129 stack
[++stacki
] = op
- DW_OP_lit0
;
24164 stack
[++stacki
] = op
- DW_OP_reg0
;
24167 if (computed
== nullptr)
24168 dwarf2_complex_location_expr_complaint ();
24175 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24177 stack
[++stacki
] = unsnd
;
24180 if (computed
== nullptr)
24181 dwarf2_complex_location_expr_complaint ();
24188 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
24193 case DW_OP_const1u
:
24194 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24198 case DW_OP_const1s
:
24199 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24203 case DW_OP_const2u
:
24204 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24208 case DW_OP_const2s
:
24209 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24213 case DW_OP_const4u
:
24214 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24218 case DW_OP_const4s
:
24219 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24223 case DW_OP_const8u
:
24224 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24229 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24235 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24240 stack
[stacki
+ 1] = stack
[stacki
];
24245 stack
[stacki
- 1] += stack
[stacki
];
24249 case DW_OP_plus_uconst
:
24250 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24256 stack
[stacki
- 1] -= stack
[stacki
];
24261 /* If we're not the last op, then we definitely can't encode
24262 this using GDB's address_class enum. This is valid for partial
24263 global symbols, although the variable's address will be bogus
24267 if (computed
== nullptr)
24268 dwarf2_complex_location_expr_complaint ();
24274 case DW_OP_GNU_push_tls_address
:
24275 case DW_OP_form_tls_address
:
24276 /* The top of the stack has the offset from the beginning
24277 of the thread control block at which the variable is located. */
24278 /* Nothing should follow this operator, so the top of stack would
24280 /* This is valid for partial global symbols, but the variable's
24281 address will be bogus in the psymtab. Make it always at least
24282 non-zero to not look as a variable garbage collected by linker
24283 which have DW_OP_addr 0. */
24286 if (computed
== nullptr)
24287 dwarf2_complex_location_expr_complaint ();
24294 case DW_OP_GNU_uninit
:
24295 if (computed
!= nullptr)
24300 case DW_OP_GNU_addr_index
:
24301 case DW_OP_GNU_const_index
:
24302 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24308 if (computed
== nullptr)
24310 const char *name
= get_DW_OP_name (op
);
24313 complaint (_("unsupported stack op: '%s'"),
24316 complaint (_("unsupported stack op: '%02x'"),
24320 return (stack
[stacki
]);
24323 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24324 outside of the allocated space. Also enforce minimum>0. */
24325 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24327 if (computed
== nullptr)
24328 complaint (_("location description stack overflow"));
24334 if (computed
== nullptr)
24335 complaint (_("location description stack underflow"));
24340 if (computed
!= nullptr)
24342 return (stack
[stacki
]);
24345 /* memory allocation interface */
24347 static struct dwarf_block
*
24348 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24350 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24353 static struct die_info
*
24354 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24356 struct die_info
*die
;
24357 size_t size
= sizeof (struct die_info
);
24360 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24362 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24363 memset (die
, 0, sizeof (struct die_info
));
24369 /* Macro support. */
24371 /* An overload of dwarf_decode_macros that finds the correct section
24372 and ensures it is read in before calling the other overload. */
24375 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24376 int section_is_gnu
)
24378 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24379 struct objfile
*objfile
= per_objfile
->objfile
;
24380 const struct line_header
*lh
= cu
->line_header
;
24381 unsigned int offset_size
= cu
->header
.offset_size
;
24382 struct dwarf2_section_info
*section
;
24383 const char *section_name
;
24385 if (cu
->dwo_unit
!= nullptr)
24387 if (section_is_gnu
)
24389 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24390 section_name
= ".debug_macro.dwo";
24394 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24395 section_name
= ".debug_macinfo.dwo";
24400 if (section_is_gnu
)
24402 section
= &per_objfile
->per_bfd
->macro
;
24403 section_name
= ".debug_macro";
24407 section
= &per_objfile
->per_bfd
->macinfo
;
24408 section_name
= ".debug_macinfo";
24412 section
->read (objfile
);
24413 if (section
->buffer
== nullptr)
24415 complaint (_("missing %s section"), section_name
);
24419 buildsym_compunit
*builder
= cu
->get_builder ();
24421 struct dwarf2_section_info
*str_offsets_section
;
24422 struct dwarf2_section_info
*str_section
;
24423 ULONGEST str_offsets_base
;
24425 if (cu
->dwo_unit
!= nullptr)
24427 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24428 ->sections
.str_offsets
;
24429 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24430 str_offsets_base
= cu
->header
.addr_size
;
24434 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24435 str_section
= &per_objfile
->per_bfd
->str
;
24436 str_offsets_base
= *cu
->str_offsets_base
;
24439 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24440 offset_size
, offset
, str_section
, str_offsets_section
,
24441 str_offsets_base
, section_is_gnu
);
24444 /* Return the .debug_loc section to use for CU.
24445 For DWO files use .debug_loc.dwo. */
24447 static struct dwarf2_section_info
*
24448 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24450 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24454 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24456 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24458 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24459 : &per_objfile
->per_bfd
->loc
);
24462 /* Return the .debug_rnglists section to use for CU. */
24463 static struct dwarf2_section_info
*
24464 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24466 if (cu
->header
.version
< 5)
24467 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24468 cu
->header
.version
);
24469 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24471 /* Make sure we read the .debug_rnglists section from the file that
24472 contains the DW_AT_ranges attribute we are reading. Normally that
24473 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24474 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24476 if (cu
->dwo_unit
!= nullptr
24477 && tag
!= DW_TAG_compile_unit
24478 && tag
!= DW_TAG_skeleton_unit
)
24480 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24482 if (sections
->rnglists
.size
> 0)
24483 return §ions
->rnglists
;
24485 error (_(".debug_rnglists section is missing from .dwo file."));
24487 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24490 /* A helper function that fills in a dwarf2_loclist_baton. */
24493 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24494 struct dwarf2_loclist_baton
*baton
,
24495 const struct attribute
*attr
)
24497 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24498 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24500 section
->read (per_objfile
->objfile
);
24502 baton
->per_objfile
= per_objfile
;
24503 baton
->per_cu
= cu
->per_cu
;
24504 gdb_assert (baton
->per_cu
);
24505 /* We don't know how long the location list is, but make sure we
24506 don't run off the edge of the section. */
24507 baton
->size
= section
->size
- attr
->as_unsigned ();
24508 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24509 if (cu
->base_address
.has_value ())
24510 baton
->base_address
= *cu
->base_address
;
24512 baton
->base_address
= 0;
24513 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24517 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24518 struct dwarf2_cu
*cu
, int is_block
)
24520 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24521 struct objfile
*objfile
= per_objfile
->objfile
;
24522 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24524 if (attr
->form_is_section_offset ()
24525 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24526 the section. If so, fall through to the complaint in the
24528 && attr
->as_unsigned () < section
->get_size (objfile
))
24530 struct dwarf2_loclist_baton
*baton
;
24532 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24534 fill_in_loclist_baton (cu
, baton
, attr
);
24536 if (!cu
->base_address
.has_value ())
24537 complaint (_("Location list used without "
24538 "specifying the CU base address."));
24540 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24541 ? dwarf2_loclist_block_index
24542 : dwarf2_loclist_index
);
24543 SYMBOL_LOCATION_BATON (sym
) = baton
;
24547 struct dwarf2_locexpr_baton
*baton
;
24549 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24550 baton
->per_objfile
= per_objfile
;
24551 baton
->per_cu
= cu
->per_cu
;
24552 gdb_assert (baton
->per_cu
);
24554 if (attr
->form_is_block ())
24556 /* Note that we're just copying the block's data pointer
24557 here, not the actual data. We're still pointing into the
24558 info_buffer for SYM's objfile; right now we never release
24559 that buffer, but when we do clean up properly this may
24561 struct dwarf_block
*block
= attr
->as_block ();
24562 baton
->size
= block
->size
;
24563 baton
->data
= block
->data
;
24567 dwarf2_invalid_attrib_class_complaint ("location description",
24568 sym
->natural_name ());
24572 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24573 ? dwarf2_locexpr_block_index
24574 : dwarf2_locexpr_index
);
24575 SYMBOL_LOCATION_BATON (sym
) = baton
;
24581 const comp_unit_head
*
24582 dwarf2_per_cu_data::get_header () const
24584 if (!m_header_read_in
)
24586 const gdb_byte
*info_ptr
24587 = this->section
->buffer
+ to_underlying (this->sect_off
);
24589 memset (&m_header
, 0, sizeof (m_header
));
24591 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24592 rcuh_kind::COMPILE
);
24601 dwarf2_per_cu_data::addr_size () const
24603 return this->get_header ()->addr_size
;
24609 dwarf2_per_cu_data::offset_size () const
24611 return this->get_header ()->offset_size
;
24617 dwarf2_per_cu_data::ref_addr_size () const
24619 const comp_unit_head
*header
= this->get_header ();
24621 if (header
->version
== 2)
24622 return header
->addr_size
;
24624 return header
->offset_size
;
24630 dwarf2_cu::addr_type () const
24632 struct objfile
*objfile
= this->per_objfile
->objfile
;
24633 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24634 struct type
*addr_type
= lookup_pointer_type (void_type
);
24635 int addr_size
= this->per_cu
->addr_size ();
24637 if (TYPE_LENGTH (addr_type
) == addr_size
)
24640 addr_type
= addr_sized_int_type (addr_type
->is_unsigned ());
24644 /* A helper function for dwarf2_find_containing_comp_unit that returns
24645 the index of the result, and that searches a vector. It will
24646 return a result even if the offset in question does not actually
24647 occur in any CU. This is separate so that it can be unit
24651 dwarf2_find_containing_comp_unit
24652 (sect_offset sect_off
,
24653 unsigned int offset_in_dwz
,
24654 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
24659 high
= all_comp_units
.size () - 1;
24662 struct dwarf2_per_cu_data
*mid_cu
;
24663 int mid
= low
+ (high
- low
) / 2;
24665 mid_cu
= all_comp_units
[mid
];
24666 if (mid_cu
->is_dwz
> offset_in_dwz
24667 || (mid_cu
->is_dwz
== offset_in_dwz
24668 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24673 gdb_assert (low
== high
);
24677 /* Locate the .debug_info compilation unit from CU's objfile which contains
24678 the DIE at OFFSET. Raises an error on failure. */
24680 static struct dwarf2_per_cu_data
*
24681 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24682 unsigned int offset_in_dwz
,
24683 dwarf2_per_objfile
*per_objfile
)
24685 int low
= dwarf2_find_containing_comp_unit
24686 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24687 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
24689 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24691 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24692 error (_("Dwarf Error: could not find partial DIE containing "
24693 "offset %s [in module %s]"),
24694 sect_offset_str (sect_off
),
24695 bfd_get_filename (per_objfile
->objfile
->obfd
));
24697 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24699 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
24703 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24704 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24705 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24706 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24713 namespace selftests
{
24714 namespace find_containing_comp_unit
{
24719 struct dwarf2_per_cu_data one
{};
24720 struct dwarf2_per_cu_data two
{};
24721 struct dwarf2_per_cu_data three
{};
24722 struct dwarf2_per_cu_data four
{};
24725 two
.sect_off
= sect_offset (one
.length
);
24730 four
.sect_off
= sect_offset (three
.length
);
24734 std::vector
<dwarf2_per_cu_data
*> units
;
24735 units
.push_back (&one
);
24736 units
.push_back (&two
);
24737 units
.push_back (&three
);
24738 units
.push_back (&four
);
24742 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24743 SELF_CHECK (units
[result
] == &one
);
24744 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24745 SELF_CHECK (units
[result
] == &one
);
24746 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24747 SELF_CHECK (units
[result
] == &two
);
24749 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24750 SELF_CHECK (units
[result
] == &three
);
24751 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24752 SELF_CHECK (units
[result
] == &three
);
24753 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24754 SELF_CHECK (units
[result
] == &four
);
24760 #endif /* GDB_SELF_TEST */
24762 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
24764 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
24765 dwarf2_per_objfile
*per_objfile
)
24767 per_objfile (per_objfile
),
24769 has_loclist (false),
24770 checked_producer (false),
24771 producer_is_gxx_lt_4_6 (false),
24772 producer_is_gcc_lt_4_3 (false),
24773 producer_is_icc (false),
24774 producer_is_icc_lt_14 (false),
24775 producer_is_codewarrior (false),
24776 processing_has_namespace_info (false)
24780 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24783 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24784 enum language pretend_language
)
24786 struct attribute
*attr
;
24788 /* Set the language we're debugging. */
24789 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24790 if (attr
!= nullptr)
24791 set_cu_language (attr
->constant_value (0), cu
);
24794 cu
->language
= pretend_language
;
24795 cu
->language_defn
= language_def (cu
->language
);
24798 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24804 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24806 auto it
= m_dwarf2_cus
.find (per_cu
);
24807 if (it
== m_dwarf2_cus
.end ())
24816 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24818 gdb_assert (this->get_cu (per_cu
) == nullptr);
24820 m_dwarf2_cus
[per_cu
] = cu
;
24826 dwarf2_per_objfile::age_comp_units ()
24828 /* Start by clearing all marks. */
24829 for (auto pair
: m_dwarf2_cus
)
24830 pair
.second
->mark
= false;
24832 /* Traverse all CUs, mark them and their dependencies if used recently
24834 for (auto pair
: m_dwarf2_cus
)
24836 dwarf2_cu
*cu
= pair
.second
;
24839 if (cu
->last_used
<= dwarf_max_cache_age
)
24843 /* Delete all CUs still not marked. */
24844 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24846 dwarf2_cu
*cu
= it
->second
;
24851 it
= m_dwarf2_cus
.erase (it
);
24861 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24863 auto it
= m_dwarf2_cus
.find (per_cu
);
24864 if (it
== m_dwarf2_cus
.end ())
24869 m_dwarf2_cus
.erase (it
);
24872 dwarf2_per_objfile::~dwarf2_per_objfile ()
24877 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24878 We store these in a hash table separate from the DIEs, and preserve them
24879 when the DIEs are flushed out of cache.
24881 The CU "per_cu" pointer is needed because offset alone is not enough to
24882 uniquely identify the type. A file may have multiple .debug_types sections,
24883 or the type may come from a DWO file. Furthermore, while it's more logical
24884 to use per_cu->section+offset, with Fission the section with the data is in
24885 the DWO file but we don't know that section at the point we need it.
24886 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24887 because we can enter the lookup routine, get_die_type_at_offset, from
24888 outside this file, and thus won't necessarily have PER_CU->cu.
24889 Fortunately, PER_CU is stable for the life of the objfile. */
24891 struct dwarf2_per_cu_offset_and_type
24893 const struct dwarf2_per_cu_data
*per_cu
;
24894 sect_offset sect_off
;
24898 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24901 per_cu_offset_and_type_hash (const void *item
)
24903 const struct dwarf2_per_cu_offset_and_type
*ofs
24904 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24906 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24909 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24912 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24914 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24915 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24916 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24917 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24919 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24920 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24923 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24924 table if necessary. For convenience, return TYPE.
24926 The DIEs reading must have careful ordering to:
24927 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24928 reading current DIE.
24929 * Not trying to dereference contents of still incompletely read in types
24930 while reading in other DIEs.
24931 * Enable referencing still incompletely read in types just by a pointer to
24932 the type without accessing its fields.
24934 Therefore caller should follow these rules:
24935 * Try to fetch any prerequisite types we may need to build this DIE type
24936 before building the type and calling set_die_type.
24937 * After building type call set_die_type for current DIE as soon as
24938 possible before fetching more types to complete the current type.
24939 * Make the type as complete as possible before fetching more types. */
24941 static struct type
*
24942 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
24943 bool skip_data_location
)
24945 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24946 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24947 struct objfile
*objfile
= per_objfile
->objfile
;
24948 struct attribute
*attr
;
24949 struct dynamic_prop prop
;
24951 /* For Ada types, make sure that the gnat-specific data is always
24952 initialized (if not already set). There are a few types where
24953 we should not be doing so, because the type-specific area is
24954 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24955 where the type-specific area is used to store the floatformat).
24956 But this is not a problem, because the gnat-specific information
24957 is actually not needed for these types. */
24958 if (need_gnat_info (cu
)
24959 && type
->code () != TYPE_CODE_FUNC
24960 && type
->code () != TYPE_CODE_FLT
24961 && type
->code () != TYPE_CODE_METHODPTR
24962 && type
->code () != TYPE_CODE_MEMBERPTR
24963 && type
->code () != TYPE_CODE_METHOD
24964 && type
->code () != TYPE_CODE_FIXED_POINT
24965 && !HAVE_GNAT_AUX_INFO (type
))
24966 INIT_GNAT_SPECIFIC (type
);
24968 /* Read DW_AT_allocated and set in type. */
24969 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24972 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24973 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24974 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24977 /* Read DW_AT_associated and set in type. */
24978 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24981 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24982 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24983 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24986 /* Read DW_AT_data_location and set in type. */
24987 if (!skip_data_location
)
24989 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24990 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24991 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24994 if (per_objfile
->die_type_hash
== NULL
)
24995 per_objfile
->die_type_hash
24996 = htab_up (htab_create_alloc (127,
24997 per_cu_offset_and_type_hash
,
24998 per_cu_offset_and_type_eq
,
24999 NULL
, xcalloc
, xfree
));
25001 ofs
.per_cu
= cu
->per_cu
;
25002 ofs
.sect_off
= die
->sect_off
;
25004 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25005 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
25007 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25008 sect_offset_str (die
->sect_off
));
25009 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25010 struct dwarf2_per_cu_offset_and_type
);
25015 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25016 or return NULL if the die does not have a saved type. */
25018 static struct type
*
25019 get_die_type_at_offset (sect_offset sect_off
,
25020 dwarf2_per_cu_data
*per_cu
,
25021 dwarf2_per_objfile
*per_objfile
)
25023 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25025 if (per_objfile
->die_type_hash
== NULL
)
25028 ofs
.per_cu
= per_cu
;
25029 ofs
.sect_off
= sect_off
;
25030 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25031 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
25038 /* Look up the type for DIE in CU in die_type_hash,
25039 or return NULL if DIE does not have a saved type. */
25041 static struct type
*
25042 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25044 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
25047 /* Add a dependence relationship from CU to REF_PER_CU. */
25050 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25051 struct dwarf2_per_cu_data
*ref_per_cu
)
25055 if (cu
->dependencies
== NULL
)
25057 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25058 NULL
, &cu
->comp_unit_obstack
,
25059 hashtab_obstack_allocate
,
25060 dummy_obstack_deallocate
);
25062 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25064 *slot
= ref_per_cu
;
25067 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25068 Set the mark field in every compilation unit in the
25069 cache that we must keep because we are keeping CU.
25071 DATA is the dwarf2_per_objfile object in which to look up CUs. */
25074 dwarf2_mark_helper (void **slot
, void *data
)
25076 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
25077 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
25078 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
25080 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25081 reading of the chain. As such dependencies remain valid it is not much
25082 useful to track and undo them during QUIT cleanups. */
25091 if (cu
->dependencies
!= nullptr)
25092 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
25097 /* Set the mark field in CU and in every other compilation unit in the
25098 cache that we must keep because we are keeping CU. */
25101 dwarf2_mark (struct dwarf2_cu
*cu
)
25108 if (cu
->dependencies
!= nullptr)
25109 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
25112 /* Trivial hash function for partial_die_info: the hash value of a DIE
25113 is its offset in .debug_info for this objfile. */
25116 partial_die_hash (const void *item
)
25118 const struct partial_die_info
*part_die
25119 = (const struct partial_die_info
*) item
;
25121 return to_underlying (part_die
->sect_off
);
25124 /* Trivial comparison function for partial_die_info structures: two DIEs
25125 are equal if they have the same offset. */
25128 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25130 const struct partial_die_info
*part_die_lhs
25131 = (const struct partial_die_info
*) item_lhs
;
25132 const struct partial_die_info
*part_die_rhs
25133 = (const struct partial_die_info
*) item_rhs
;
25135 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25138 struct cmd_list_element
*set_dwarf_cmdlist
;
25139 struct cmd_list_element
*show_dwarf_cmdlist
;
25142 show_check_physname (struct ui_file
*file
, int from_tty
,
25143 struct cmd_list_element
*c
, const char *value
)
25145 fprintf_filtered (file
,
25146 _("Whether to check \"physname\" is %s.\n"),
25150 void _initialize_dwarf2_read ();
25152 _initialize_dwarf2_read ()
25154 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
25155 Set DWARF specific variables.\n\
25156 Configure DWARF variables such as the cache size."),
25157 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25158 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25160 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
25161 Show DWARF specific variables.\n\
25162 Show DWARF variables such as the cache size."),
25163 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25164 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25166 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25167 &dwarf_max_cache_age
, _("\
25168 Set the upper bound on the age of cached DWARF compilation units."), _("\
25169 Show the upper bound on the age of cached DWARF compilation units."), _("\
25170 A higher limit means that cached compilation units will be stored\n\
25171 in memory longer, and more total memory will be used. Zero disables\n\
25172 caching, which can slow down startup."),
25174 show_dwarf_max_cache_age
,
25175 &set_dwarf_cmdlist
,
25176 &show_dwarf_cmdlist
);
25178 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25179 Set debugging of the DWARF reader."), _("\
25180 Show debugging of the DWARF reader."), _("\
25181 When enabled (non-zero), debugging messages are printed during DWARF\n\
25182 reading and symtab expansion. A value of 1 (one) provides basic\n\
25183 information. A value greater than 1 provides more verbose information."),
25186 &setdebuglist
, &showdebuglist
);
25188 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25189 Set debugging of the DWARF DIE reader."), _("\
25190 Show debugging of the DWARF DIE reader."), _("\
25191 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25192 The value is the maximum depth to print."),
25195 &setdebuglist
, &showdebuglist
);
25197 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25198 Set debugging of the dwarf line reader."), _("\
25199 Show debugging of the dwarf line reader."), _("\
25200 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25201 A value of 1 (one) provides basic information.\n\
25202 A value greater than 1 provides more verbose information."),
25205 &setdebuglist
, &showdebuglist
);
25207 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25208 Set cross-checking of \"physname\" code against demangler."), _("\
25209 Show cross-checking of \"physname\" code against demangler."), _("\
25210 When enabled, GDB's internal \"physname\" code is checked against\n\
25212 NULL
, show_check_physname
,
25213 &setdebuglist
, &showdebuglist
);
25215 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25216 no_class
, &use_deprecated_index_sections
, _("\
25217 Set whether to use deprecated gdb_index sections."), _("\
25218 Show whether to use deprecated gdb_index sections."), _("\
25219 When enabled, deprecated .gdb_index sections are used anyway.\n\
25220 Normally they are ignored either because of a missing feature or\n\
25221 performance issue.\n\
25222 Warning: This option must be enabled before gdb reads the file."),
25225 &setlist
, &showlist
);
25227 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25228 &dwarf2_locexpr_funcs
);
25229 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25230 &dwarf2_loclist_funcs
);
25232 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25233 &dwarf2_block_frame_base_locexpr_funcs
);
25234 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25235 &dwarf2_block_frame_base_loclist_funcs
);
25238 selftests::register_test ("dw2_expand_symtabs_matching",
25239 selftests::dw2_expand_symtabs_matching::run_test
);
25240 selftests::register_test ("dwarf2_find_containing_comp_unit",
25241 selftests::find_containing_comp_unit::run_test
);