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 DWARF"_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 (dwarf2_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 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
18096 (which may be different from NAME) to the architecture back-end to allow
18097 it to guess the correct format if necessary. */
18099 static struct type
*
18100 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
18101 const char *name_hint
, enum bfd_endian byte_order
)
18103 struct gdbarch
*gdbarch
= objfile
->arch ();
18104 const struct floatformat
**format
;
18107 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
18109 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
18111 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18116 /* Allocate an integer type of size BITS and name NAME. */
18118 static struct type
*
18119 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
18120 int bits
, int unsigned_p
, const char *name
)
18124 /* Versions of Intel's C Compiler generate an integer type called "void"
18125 instead of using DW_TAG_unspecified_type. This has been seen on
18126 at least versions 14, 17, and 18. */
18127 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18128 && strcmp (name
, "void") == 0)
18129 type
= objfile_type (objfile
)->builtin_void
;
18131 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18136 /* Initialise and return a floating point type of size BITS suitable for
18137 use as a component of a complex number. The NAME_HINT is passed through
18138 when initialising the floating point type and is the name of the complex
18141 As DWARF doesn't currently provide an explicit name for the components
18142 of a complex number, but it can be helpful to have these components
18143 named, we try to select a suitable name based on the size of the
18145 static struct type
*
18146 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18147 struct objfile
*objfile
,
18148 int bits
, const char *name_hint
,
18149 enum bfd_endian byte_order
)
18151 gdbarch
*gdbarch
= objfile
->arch ();
18152 struct type
*tt
= nullptr;
18154 /* Try to find a suitable floating point builtin type of size BITS.
18155 We're going to use the name of this type as the name for the complex
18156 target type that we are about to create. */
18157 switch (cu
->language
)
18159 case language_fortran
:
18163 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18166 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18168 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18170 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18178 tt
= builtin_type (gdbarch
)->builtin_float
;
18181 tt
= builtin_type (gdbarch
)->builtin_double
;
18183 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18185 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18191 /* If the type we found doesn't match the size we were looking for, then
18192 pretend we didn't find a type at all, the complex target type we
18193 create will then be nameless. */
18194 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18197 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18198 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18201 /* Find a representation of a given base type and install
18202 it in the TYPE field of the die. */
18204 static struct type
*
18205 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18207 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18209 struct attribute
*attr
;
18210 int encoding
= 0, bits
= 0;
18214 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18215 if (attr
!= nullptr && attr
->form_is_constant ())
18216 encoding
= attr
->constant_value (0);
18217 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18218 if (attr
!= nullptr)
18219 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18220 name
= dwarf2_name (die
, cu
);
18222 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18224 arch
= objfile
->arch ();
18225 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18227 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18228 if (attr
!= nullptr && attr
->form_is_constant ())
18230 int endianity
= attr
->constant_value (0);
18235 byte_order
= BFD_ENDIAN_BIG
;
18237 case DW_END_little
:
18238 byte_order
= BFD_ENDIAN_LITTLE
;
18241 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18248 case DW_ATE_address
:
18249 /* Turn DW_ATE_address into a void * pointer. */
18250 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18251 type
= init_pointer_type (objfile
, bits
, name
, type
);
18253 case DW_ATE_boolean
:
18254 type
= init_boolean_type (objfile
, bits
, 1, name
);
18256 case DW_ATE_complex_float
:
18257 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18259 if (type
->code () == TYPE_CODE_ERROR
)
18261 if (name
== nullptr)
18263 struct obstack
*obstack
18264 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18265 name
= obconcat (obstack
, "_Complex ", type
->name (),
18268 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18271 type
= init_complex_type (name
, type
);
18273 case DW_ATE_decimal_float
:
18274 type
= init_decfloat_type (objfile
, bits
, name
);
18277 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18279 case DW_ATE_signed
:
18280 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18282 case DW_ATE_unsigned
:
18283 if (cu
->language
== language_fortran
18285 && startswith (name
, "character("))
18286 type
= init_character_type (objfile
, bits
, 1, name
);
18288 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18290 case DW_ATE_signed_char
:
18291 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18292 || cu
->language
== language_pascal
18293 || cu
->language
== language_fortran
)
18294 type
= init_character_type (objfile
, bits
, 0, name
);
18296 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18298 case DW_ATE_unsigned_char
:
18299 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18300 || cu
->language
== language_pascal
18301 || cu
->language
== language_fortran
18302 || cu
->language
== language_rust
)
18303 type
= init_character_type (objfile
, bits
, 1, name
);
18305 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18310 type
= builtin_type (arch
)->builtin_char16
;
18311 else if (bits
== 32)
18312 type
= builtin_type (arch
)->builtin_char32
;
18315 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18317 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18319 return set_die_type (die
, type
, cu
);
18324 complaint (_("unsupported DW_AT_encoding: '%s'"),
18325 dwarf_type_encoding_name (encoding
));
18326 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18330 if (name
&& strcmp (name
, "char") == 0)
18331 type
->set_has_no_signedness (true);
18333 maybe_set_alignment (cu
, die
, type
);
18335 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18337 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18339 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18340 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18342 unsigned real_bit_size
= attr
->as_unsigned ();
18343 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18344 /* Only use the attributes if they make sense together. */
18345 if (attr
== nullptr
18346 || (attr
->as_unsigned () + real_bit_size
18347 <= 8 * TYPE_LENGTH (type
)))
18349 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18351 if (attr
!= nullptr)
18352 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18353 = attr
->as_unsigned ();
18358 return set_die_type (die
, type
, cu
);
18361 /* Parse dwarf attribute if it's a block, reference or constant and put the
18362 resulting value of the attribute into struct bound_prop.
18363 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18366 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18367 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18368 struct type
*default_type
)
18370 struct dwarf2_property_baton
*baton
;
18371 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18372 struct objfile
*objfile
= per_objfile
->objfile
;
18373 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18375 gdb_assert (default_type
!= NULL
);
18377 if (attr
== NULL
|| prop
== NULL
)
18380 if (attr
->form_is_block ())
18382 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18383 baton
->property_type
= default_type
;
18384 baton
->locexpr
.per_cu
= cu
->per_cu
;
18385 baton
->locexpr
.per_objfile
= per_objfile
;
18387 struct dwarf_block
*block
= attr
->as_block ();
18388 baton
->locexpr
.size
= block
->size
;
18389 baton
->locexpr
.data
= block
->data
;
18390 switch (attr
->name
)
18392 case DW_AT_string_length
:
18393 baton
->locexpr
.is_reference
= true;
18396 baton
->locexpr
.is_reference
= false;
18400 prop
->set_locexpr (baton
);
18401 gdb_assert (prop
->baton () != NULL
);
18403 else if (attr
->form_is_ref ())
18405 struct dwarf2_cu
*target_cu
= cu
;
18406 struct die_info
*target_die
;
18407 struct attribute
*target_attr
;
18409 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18410 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18411 if (target_attr
== NULL
)
18412 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18414 if (target_attr
== NULL
)
18417 switch (target_attr
->name
)
18419 case DW_AT_location
:
18420 if (target_attr
->form_is_section_offset ())
18422 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18423 baton
->property_type
= die_type (target_die
, target_cu
);
18424 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18425 prop
->set_loclist (baton
);
18426 gdb_assert (prop
->baton () != NULL
);
18428 else if (target_attr
->form_is_block ())
18430 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18431 baton
->property_type
= die_type (target_die
, target_cu
);
18432 baton
->locexpr
.per_cu
= cu
->per_cu
;
18433 baton
->locexpr
.per_objfile
= per_objfile
;
18434 struct dwarf_block
*block
= target_attr
->as_block ();
18435 baton
->locexpr
.size
= block
->size
;
18436 baton
->locexpr
.data
= block
->data
;
18437 baton
->locexpr
.is_reference
= true;
18438 prop
->set_locexpr (baton
);
18439 gdb_assert (prop
->baton () != NULL
);
18443 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18444 "dynamic property");
18448 case DW_AT_data_member_location
:
18452 if (!handle_data_member_location (target_die
, target_cu
,
18456 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18457 baton
->property_type
= read_type_die (target_die
->parent
,
18459 baton
->offset_info
.offset
= offset
;
18460 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18461 prop
->set_addr_offset (baton
);
18466 else if (attr
->form_is_constant ())
18467 prop
->set_const_val (attr
->constant_value (0));
18470 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18471 dwarf2_name (die
, cu
));
18481 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18483 struct type
*int_type
;
18485 /* Helper macro to examine the various builtin types. */
18486 #define TRY_TYPE(F) \
18487 int_type = (unsigned_p \
18488 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18489 : objfile_type (objfile)->builtin_ ## F); \
18490 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18497 TRY_TYPE (long_long
);
18501 gdb_assert_not_reached ("unable to find suitable integer type");
18507 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
18509 int addr_size
= this->per_cu
->addr_size ();
18510 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
18513 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18514 present (which is valid) then compute the default type based on the
18515 compilation units address size. */
18517 static struct type
*
18518 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18520 struct type
*index_type
= die_type (die
, cu
);
18522 /* Dwarf-2 specifications explicitly allows to create subrange types
18523 without specifying a base type.
18524 In that case, the base type must be set to the type of
18525 the lower bound, upper bound or count, in that order, if any of these
18526 three attributes references an object that has a type.
18527 If no base type is found, the Dwarf-2 specifications say that
18528 a signed integer type of size equal to the size of an address should
18530 For the following C code: `extern char gdb_int [];'
18531 GCC produces an empty range DIE.
18532 FIXME: muller/2010-05-28: Possible references to object for low bound,
18533 high bound or count are not yet handled by this code. */
18534 if (index_type
->code () == TYPE_CODE_VOID
)
18535 index_type
= cu
->addr_sized_int_type (false);
18540 /* Read the given DW_AT_subrange DIE. */
18542 static struct type
*
18543 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18545 struct type
*base_type
, *orig_base_type
;
18546 struct type
*range_type
;
18547 struct attribute
*attr
;
18548 struct dynamic_prop low
, high
;
18549 int low_default_is_valid
;
18550 int high_bound_is_count
= 0;
18552 ULONGEST negative_mask
;
18554 orig_base_type
= read_subrange_index_type (die
, cu
);
18556 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18557 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18558 creating the range type, but we use the result of check_typedef
18559 when examining properties of the type. */
18560 base_type
= check_typedef (orig_base_type
);
18562 /* The die_type call above may have already set the type for this DIE. */
18563 range_type
= get_die_type (die
, cu
);
18567 high
.set_const_val (0);
18569 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18570 omitting DW_AT_lower_bound. */
18571 switch (cu
->language
)
18574 case language_cplus
:
18575 low
.set_const_val (0);
18576 low_default_is_valid
= 1;
18578 case language_fortran
:
18579 low
.set_const_val (1);
18580 low_default_is_valid
= 1;
18583 case language_objc
:
18584 case language_rust
:
18585 low
.set_const_val (0);
18586 low_default_is_valid
= (cu
->header
.version
>= 4);
18590 case language_pascal
:
18591 low
.set_const_val (1);
18592 low_default_is_valid
= (cu
->header
.version
>= 4);
18595 low
.set_const_val (0);
18596 low_default_is_valid
= 0;
18600 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18601 if (attr
!= nullptr)
18602 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18603 else if (!low_default_is_valid
)
18604 complaint (_("Missing DW_AT_lower_bound "
18605 "- DIE at %s [in module %s]"),
18606 sect_offset_str (die
->sect_off
),
18607 objfile_name (cu
->per_objfile
->objfile
));
18609 struct attribute
*attr_ub
, *attr_count
;
18610 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18611 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18613 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18614 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18616 /* If bounds are constant do the final calculation here. */
18617 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18618 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18620 high_bound_is_count
= 1;
18624 if (attr_ub
!= NULL
)
18625 complaint (_("Unresolved DW_AT_upper_bound "
18626 "- DIE at %s [in module %s]"),
18627 sect_offset_str (die
->sect_off
),
18628 objfile_name (cu
->per_objfile
->objfile
));
18629 if (attr_count
!= NULL
)
18630 complaint (_("Unresolved DW_AT_count "
18631 "- DIE at %s [in module %s]"),
18632 sect_offset_str (die
->sect_off
),
18633 objfile_name (cu
->per_objfile
->objfile
));
18638 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18639 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18640 bias
= bias_attr
->constant_value (0);
18642 /* Normally, the DWARF producers are expected to use a signed
18643 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18644 But this is unfortunately not always the case, as witnessed
18645 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18646 is used instead. To work around that ambiguity, we treat
18647 the bounds as signed, and thus sign-extend their values, when
18648 the base type is signed. */
18650 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18651 if (low
.kind () == PROP_CONST
18652 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18653 low
.set_const_val (low
.const_val () | negative_mask
);
18654 if (high
.kind () == PROP_CONST
18655 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18656 high
.set_const_val (high
.const_val () | negative_mask
);
18658 /* Check for bit and byte strides. */
18659 struct dynamic_prop byte_stride_prop
;
18660 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18661 if (attr_byte_stride
!= nullptr)
18663 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18664 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18668 struct dynamic_prop bit_stride_prop
;
18669 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18670 if (attr_bit_stride
!= nullptr)
18672 /* It only makes sense to have either a bit or byte stride. */
18673 if (attr_byte_stride
!= nullptr)
18675 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18676 "- DIE at %s [in module %s]"),
18677 sect_offset_str (die
->sect_off
),
18678 objfile_name (cu
->per_objfile
->objfile
));
18679 attr_bit_stride
= nullptr;
18683 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18684 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18689 if (attr_byte_stride
!= nullptr
18690 || attr_bit_stride
!= nullptr)
18692 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18693 struct dynamic_prop
*stride
18694 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18697 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18698 &high
, bias
, stride
, byte_stride_p
);
18701 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18703 if (high_bound_is_count
)
18704 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18706 /* Ada expects an empty array on no boundary attributes. */
18707 if (attr
== NULL
&& cu
->language
!= language_ada
)
18708 range_type
->bounds ()->high
.set_undefined ();
18710 name
= dwarf2_name (die
, cu
);
18712 range_type
->set_name (name
);
18714 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18715 if (attr
!= nullptr)
18716 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18718 maybe_set_alignment (cu
, die
, range_type
);
18720 set_die_type (die
, range_type
, cu
);
18722 /* set_die_type should be already done. */
18723 set_descriptive_type (range_type
, die
, cu
);
18728 static struct type
*
18729 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18733 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18734 type
->set_name (dwarf2_name (die
, cu
));
18736 /* In Ada, an unspecified type is typically used when the description
18737 of the type is deferred to a different unit. When encountering
18738 such a type, we treat it as a stub, and try to resolve it later on,
18740 if (cu
->language
== language_ada
)
18741 type
->set_is_stub (true);
18743 return set_die_type (die
, type
, cu
);
18746 /* Read a single die and all its descendents. Set the die's sibling
18747 field to NULL; set other fields in the die correctly, and set all
18748 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18749 location of the info_ptr after reading all of those dies. PARENT
18750 is the parent of the die in question. */
18752 static struct die_info
*
18753 read_die_and_children (const struct die_reader_specs
*reader
,
18754 const gdb_byte
*info_ptr
,
18755 const gdb_byte
**new_info_ptr
,
18756 struct die_info
*parent
)
18758 struct die_info
*die
;
18759 const gdb_byte
*cur_ptr
;
18761 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18764 *new_info_ptr
= cur_ptr
;
18767 store_in_ref_table (die
, reader
->cu
);
18769 if (die
->has_children
)
18770 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18774 *new_info_ptr
= cur_ptr
;
18777 die
->sibling
= NULL
;
18778 die
->parent
= parent
;
18782 /* Read a die, all of its descendents, and all of its siblings; set
18783 all of the fields of all of the dies correctly. Arguments are as
18784 in read_die_and_children. */
18786 static struct die_info
*
18787 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18788 const gdb_byte
*info_ptr
,
18789 const gdb_byte
**new_info_ptr
,
18790 struct die_info
*parent
)
18792 struct die_info
*first_die
, *last_sibling
;
18793 const gdb_byte
*cur_ptr
;
18795 cur_ptr
= info_ptr
;
18796 first_die
= last_sibling
= NULL
;
18800 struct die_info
*die
18801 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18805 *new_info_ptr
= cur_ptr
;
18812 last_sibling
->sibling
= die
;
18814 last_sibling
= die
;
18818 /* Read a die, all of its descendents, and all of its siblings; set
18819 all of the fields of all of the dies correctly. Arguments are as
18820 in read_die_and_children.
18821 This the main entry point for reading a DIE and all its children. */
18823 static struct die_info
*
18824 read_die_and_siblings (const struct die_reader_specs
*reader
,
18825 const gdb_byte
*info_ptr
,
18826 const gdb_byte
**new_info_ptr
,
18827 struct die_info
*parent
)
18829 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18830 new_info_ptr
, parent
);
18832 if (dwarf_die_debug
)
18834 fprintf_unfiltered (gdb_stdlog
,
18835 "Read die from %s@0x%x of %s:\n",
18836 reader
->die_section
->get_name (),
18837 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18838 bfd_get_filename (reader
->abfd
));
18839 dump_die (die
, dwarf_die_debug
);
18845 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18847 The caller is responsible for filling in the extra attributes
18848 and updating (*DIEP)->num_attrs.
18849 Set DIEP to point to a newly allocated die with its information,
18850 except for its child, sibling, and parent fields. */
18852 static const gdb_byte
*
18853 read_full_die_1 (const struct die_reader_specs
*reader
,
18854 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18855 int num_extra_attrs
)
18857 unsigned int abbrev_number
, bytes_read
, i
;
18858 struct abbrev_info
*abbrev
;
18859 struct die_info
*die
;
18860 struct dwarf2_cu
*cu
= reader
->cu
;
18861 bfd
*abfd
= reader
->abfd
;
18863 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18864 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18865 info_ptr
+= bytes_read
;
18866 if (!abbrev_number
)
18872 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18874 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18876 bfd_get_filename (abfd
));
18878 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18879 die
->sect_off
= sect_off
;
18880 die
->tag
= abbrev
->tag
;
18881 die
->abbrev
= abbrev_number
;
18882 die
->has_children
= abbrev
->has_children
;
18884 /* Make the result usable.
18885 The caller needs to update num_attrs after adding the extra
18887 die
->num_attrs
= abbrev
->num_attrs
;
18889 bool any_need_reprocess
= false;
18890 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18892 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18894 if (die
->attrs
[i
].requires_reprocessing_p ())
18895 any_need_reprocess
= true;
18898 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18899 if (attr
!= nullptr && attr
->form_is_unsigned ())
18900 cu
->str_offsets_base
= attr
->as_unsigned ();
18902 attr
= die
->attr (DW_AT_loclists_base
);
18903 if (attr
!= nullptr)
18904 cu
->loclist_base
= attr
->as_unsigned ();
18906 auto maybe_addr_base
= die
->addr_base ();
18907 if (maybe_addr_base
.has_value ())
18908 cu
->addr_base
= *maybe_addr_base
;
18910 attr
= die
->attr (DW_AT_rnglists_base
);
18911 if (attr
!= nullptr)
18912 cu
->ranges_base
= attr
->as_unsigned ();
18914 if (any_need_reprocess
)
18916 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18918 if (die
->attrs
[i
].requires_reprocessing_p ())
18919 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
18926 /* Read a die and all its attributes.
18927 Set DIEP to point to a newly allocated die with its information,
18928 except for its child, sibling, and parent fields. */
18930 static const gdb_byte
*
18931 read_full_die (const struct die_reader_specs
*reader
,
18932 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18934 const gdb_byte
*result
;
18936 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18938 if (dwarf_die_debug
)
18940 fprintf_unfiltered (gdb_stdlog
,
18941 "Read die from %s@0x%x of %s:\n",
18942 reader
->die_section
->get_name (),
18943 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18944 bfd_get_filename (reader
->abfd
));
18945 dump_die (*diep
, dwarf_die_debug
);
18952 /* Returns nonzero if TAG represents a type that we might generate a partial
18956 is_type_tag_for_partial (int tag
, enum language lang
)
18961 /* Some types that would be reasonable to generate partial symbols for,
18962 that we don't at present. Note that normally this does not
18963 matter, mainly because C compilers don't give names to these
18964 types, but instead emit DW_TAG_typedef. */
18965 case DW_TAG_file_type
:
18966 case DW_TAG_ptr_to_member_type
:
18967 case DW_TAG_set_type
:
18968 case DW_TAG_string_type
:
18969 case DW_TAG_subroutine_type
:
18972 /* GNAT may emit an array with a name, but no typedef, so we
18973 need to make a symbol in this case. */
18974 case DW_TAG_array_type
:
18975 return lang
== language_ada
;
18977 case DW_TAG_base_type
:
18978 case DW_TAG_class_type
:
18979 case DW_TAG_interface_type
:
18980 case DW_TAG_enumeration_type
:
18981 case DW_TAG_structure_type
:
18982 case DW_TAG_subrange_type
:
18983 case DW_TAG_typedef
:
18984 case DW_TAG_union_type
:
18991 /* Load all DIEs that are interesting for partial symbols into memory. */
18993 static struct partial_die_info
*
18994 load_partial_dies (const struct die_reader_specs
*reader
,
18995 const gdb_byte
*info_ptr
, int building_psymtab
)
18997 struct dwarf2_cu
*cu
= reader
->cu
;
18998 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18999 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
19000 unsigned int bytes_read
;
19001 unsigned int load_all
= 0;
19002 int nesting_level
= 1;
19007 gdb_assert (cu
->per_cu
!= NULL
);
19008 if (cu
->per_cu
->load_all_dies
)
19012 = htab_create_alloc_ex (cu
->header
.length
/ 12,
19016 &cu
->comp_unit_obstack
,
19017 hashtab_obstack_allocate
,
19018 dummy_obstack_deallocate
);
19022 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
19024 /* A NULL abbrev means the end of a series of children. */
19025 if (abbrev
== NULL
)
19027 if (--nesting_level
== 0)
19030 info_ptr
+= bytes_read
;
19031 last_die
= parent_die
;
19032 parent_die
= parent_die
->die_parent
;
19036 /* Check for template arguments. We never save these; if
19037 they're seen, we just mark the parent, and go on our way. */
19038 if (parent_die
!= NULL
19039 && cu
->language
== language_cplus
19040 && (abbrev
->tag
== DW_TAG_template_type_param
19041 || abbrev
->tag
== DW_TAG_template_value_param
))
19043 parent_die
->has_template_arguments
= 1;
19047 /* We don't need a partial DIE for the template argument. */
19048 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19053 /* We only recurse into c++ subprograms looking for template arguments.
19054 Skip their other children. */
19056 && cu
->language
== language_cplus
19057 && parent_die
!= NULL
19058 && parent_die
->tag
== DW_TAG_subprogram
19059 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19061 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19065 /* Check whether this DIE is interesting enough to save. Normally
19066 we would not be interested in members here, but there may be
19067 later variables referencing them via DW_AT_specification (for
19068 static members). */
19070 && !is_type_tag_for_partial (abbrev
->tag
, cu
->language
)
19071 && abbrev
->tag
!= DW_TAG_constant
19072 && abbrev
->tag
!= DW_TAG_enumerator
19073 && abbrev
->tag
!= DW_TAG_subprogram
19074 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19075 && abbrev
->tag
!= DW_TAG_lexical_block
19076 && abbrev
->tag
!= DW_TAG_variable
19077 && abbrev
->tag
!= DW_TAG_namespace
19078 && abbrev
->tag
!= DW_TAG_module
19079 && abbrev
->tag
!= DW_TAG_member
19080 && abbrev
->tag
!= DW_TAG_imported_unit
19081 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19083 /* Otherwise we skip to the next sibling, if any. */
19084 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19088 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19091 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19093 /* This two-pass algorithm for processing partial symbols has a
19094 high cost in cache pressure. Thus, handle some simple cases
19095 here which cover the majority of C partial symbols. DIEs
19096 which neither have specification tags in them, nor could have
19097 specification tags elsewhere pointing at them, can simply be
19098 processed and discarded.
19100 This segment is also optional; scan_partial_symbols and
19101 add_partial_symbol will handle these DIEs if we chain
19102 them in normally. When compilers which do not emit large
19103 quantities of duplicate debug information are more common,
19104 this code can probably be removed. */
19106 /* Any complete simple types at the top level (pretty much all
19107 of them, for a language without namespaces), can be processed
19109 if (parent_die
== NULL
19110 && pdi
.has_specification
== 0
19111 && pdi
.is_declaration
== 0
19112 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19113 || pdi
.tag
== DW_TAG_base_type
19114 || pdi
.tag
== DW_TAG_array_type
19115 || pdi
.tag
== DW_TAG_subrange_type
))
19117 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19118 add_partial_symbol (&pdi
, cu
);
19120 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19124 /* The exception for DW_TAG_typedef with has_children above is
19125 a workaround of GCC PR debug/47510. In the case of this complaint
19126 type_name_or_error will error on such types later.
19128 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19129 it could not find the child DIEs referenced later, this is checked
19130 above. In correct DWARF DW_TAG_typedef should have no children. */
19132 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19133 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19134 "- DIE at %s [in module %s]"),
19135 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19137 /* If we're at the second level, and we're an enumerator, and
19138 our parent has no specification (meaning possibly lives in a
19139 namespace elsewhere), then we can add the partial symbol now
19140 instead of queueing it. */
19141 if (pdi
.tag
== DW_TAG_enumerator
19142 && parent_die
!= NULL
19143 && parent_die
->die_parent
== NULL
19144 && parent_die
->tag
== DW_TAG_enumeration_type
19145 && parent_die
->has_specification
== 0)
19147 if (pdi
.raw_name
== NULL
)
19148 complaint (_("malformed enumerator DIE ignored"));
19149 else if (building_psymtab
)
19150 add_partial_symbol (&pdi
, cu
);
19152 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19156 struct partial_die_info
*part_die
19157 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19159 /* We'll save this DIE so link it in. */
19160 part_die
->die_parent
= parent_die
;
19161 part_die
->die_sibling
= NULL
;
19162 part_die
->die_child
= NULL
;
19164 if (last_die
&& last_die
== parent_die
)
19165 last_die
->die_child
= part_die
;
19167 last_die
->die_sibling
= part_die
;
19169 last_die
= part_die
;
19171 if (first_die
== NULL
)
19172 first_die
= part_die
;
19174 /* Maybe add the DIE to the hash table. Not all DIEs that we
19175 find interesting need to be in the hash table, because we
19176 also have the parent/sibling/child chains; only those that we
19177 might refer to by offset later during partial symbol reading.
19179 For now this means things that might have be the target of a
19180 DW_AT_specification, DW_AT_abstract_origin, or
19181 DW_AT_extension. DW_AT_extension will refer only to
19182 namespaces; DW_AT_abstract_origin refers to functions (and
19183 many things under the function DIE, but we do not recurse
19184 into function DIEs during partial symbol reading) and
19185 possibly variables as well; DW_AT_specification refers to
19186 declarations. Declarations ought to have the DW_AT_declaration
19187 flag. It happens that GCC forgets to put it in sometimes, but
19188 only for functions, not for types.
19190 Adding more things than necessary to the hash table is harmless
19191 except for the performance cost. Adding too few will result in
19192 wasted time in find_partial_die, when we reread the compilation
19193 unit with load_all_dies set. */
19196 || abbrev
->tag
== DW_TAG_constant
19197 || abbrev
->tag
== DW_TAG_subprogram
19198 || abbrev
->tag
== DW_TAG_variable
19199 || abbrev
->tag
== DW_TAG_namespace
19200 || part_die
->is_declaration
)
19204 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19205 to_underlying (part_die
->sect_off
),
19210 /* For some DIEs we want to follow their children (if any). For C
19211 we have no reason to follow the children of structures; for other
19212 languages we have to, so that we can get at method physnames
19213 to infer fully qualified class names, for DW_AT_specification,
19214 and for C++ template arguments. For C++, we also look one level
19215 inside functions to find template arguments (if the name of the
19216 function does not already contain the template arguments).
19218 For Ada and Fortran, we need to scan the children of subprograms
19219 and lexical blocks as well because these languages allow the
19220 definition of nested entities that could be interesting for the
19221 debugger, such as nested subprograms for instance. */
19222 if (last_die
->has_children
19224 || last_die
->tag
== DW_TAG_namespace
19225 || last_die
->tag
== DW_TAG_module
19226 || last_die
->tag
== DW_TAG_enumeration_type
19227 || (cu
->language
== language_cplus
19228 && last_die
->tag
== DW_TAG_subprogram
19229 && (last_die
->raw_name
== NULL
19230 || strchr (last_die
->raw_name
, '<') == NULL
))
19231 || (cu
->language
!= language_c
19232 && (last_die
->tag
== DW_TAG_class_type
19233 || last_die
->tag
== DW_TAG_interface_type
19234 || last_die
->tag
== DW_TAG_structure_type
19235 || last_die
->tag
== DW_TAG_union_type
))
19236 || ((cu
->language
== language_ada
19237 || cu
->language
== language_fortran
)
19238 && (last_die
->tag
== DW_TAG_subprogram
19239 || last_die
->tag
== DW_TAG_lexical_block
))))
19242 parent_die
= last_die
;
19246 /* Otherwise we skip to the next sibling, if any. */
19247 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19249 /* Back to the top, do it again. */
19253 partial_die_info::partial_die_info (sect_offset sect_off_
,
19254 struct abbrev_info
*abbrev
)
19255 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19259 /* See class definition. */
19262 partial_die_info::name (dwarf2_cu
*cu
)
19264 if (!canonical_name
&& raw_name
!= nullptr)
19266 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19267 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19268 canonical_name
= 1;
19274 /* Read a minimal amount of information into the minimal die structure.
19275 INFO_PTR should point just after the initial uleb128 of a DIE. */
19278 partial_die_info::read (const struct die_reader_specs
*reader
,
19279 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19281 struct dwarf2_cu
*cu
= reader
->cu
;
19282 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19284 int has_low_pc_attr
= 0;
19285 int has_high_pc_attr
= 0;
19286 int high_pc_relative
= 0;
19288 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19291 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19292 /* String and address offsets that need to do the reprocessing have
19293 already been read at this point, so there is no need to wait until
19294 the loop terminates to do the reprocessing. */
19295 if (attr
.requires_reprocessing_p ())
19296 read_attribute_reprocess (reader
, &attr
, tag
);
19297 /* Store the data if it is of an attribute we want to keep in a
19298 partial symbol table. */
19304 case DW_TAG_compile_unit
:
19305 case DW_TAG_partial_unit
:
19306 case DW_TAG_type_unit
:
19307 /* Compilation units have a DW_AT_name that is a filename, not
19308 a source language identifier. */
19309 case DW_TAG_enumeration_type
:
19310 case DW_TAG_enumerator
:
19311 /* These tags always have simple identifiers already; no need
19312 to canonicalize them. */
19313 canonical_name
= 1;
19314 raw_name
= attr
.as_string ();
19317 canonical_name
= 0;
19318 raw_name
= attr
.as_string ();
19322 case DW_AT_linkage_name
:
19323 case DW_AT_MIPS_linkage_name
:
19324 /* Note that both forms of linkage name might appear. We
19325 assume they will be the same, and we only store the last
19327 linkage_name
= attr
.as_string ();
19330 has_low_pc_attr
= 1;
19331 lowpc
= attr
.as_address ();
19333 case DW_AT_high_pc
:
19334 has_high_pc_attr
= 1;
19335 highpc
= attr
.as_address ();
19336 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19337 high_pc_relative
= 1;
19339 case DW_AT_location
:
19340 /* Support the .debug_loc offsets. */
19341 if (attr
.form_is_block ())
19343 d
.locdesc
= attr
.as_block ();
19345 else if (attr
.form_is_section_offset ())
19347 dwarf2_complex_location_expr_complaint ();
19351 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19352 "partial symbol information");
19355 case DW_AT_external
:
19356 is_external
= attr
.as_boolean ();
19358 case DW_AT_declaration
:
19359 is_declaration
= attr
.as_boolean ();
19364 case DW_AT_abstract_origin
:
19365 case DW_AT_specification
:
19366 case DW_AT_extension
:
19367 has_specification
= 1;
19368 spec_offset
= attr
.get_ref_die_offset ();
19369 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19370 || cu
->per_cu
->is_dwz
);
19372 case DW_AT_sibling
:
19373 /* Ignore absolute siblings, they might point outside of
19374 the current compile unit. */
19375 if (attr
.form
== DW_FORM_ref_addr
)
19376 complaint (_("ignoring absolute DW_AT_sibling"));
19379 const gdb_byte
*buffer
= reader
->buffer
;
19380 sect_offset off
= attr
.get_ref_die_offset ();
19381 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19383 if (sibling_ptr
< info_ptr
)
19384 complaint (_("DW_AT_sibling points backwards"));
19385 else if (sibling_ptr
> reader
->buffer_end
)
19386 reader
->die_section
->overflow_complaint ();
19388 sibling
= sibling_ptr
;
19391 case DW_AT_byte_size
:
19394 case DW_AT_const_value
:
19395 has_const_value
= 1;
19397 case DW_AT_calling_convention
:
19398 /* DWARF doesn't provide a way to identify a program's source-level
19399 entry point. DW_AT_calling_convention attributes are only meant
19400 to describe functions' calling conventions.
19402 However, because it's a necessary piece of information in
19403 Fortran, and before DWARF 4 DW_CC_program was the only
19404 piece of debugging information whose definition refers to
19405 a 'main program' at all, several compilers marked Fortran
19406 main programs with DW_CC_program --- even when those
19407 functions use the standard calling conventions.
19409 Although DWARF now specifies a way to provide this
19410 information, we support this practice for backward
19412 if (attr
.constant_value (0) == DW_CC_program
19413 && cu
->language
== language_fortran
)
19414 main_subprogram
= 1;
19418 LONGEST value
= attr
.constant_value (-1);
19419 if (value
== DW_INL_inlined
19420 || value
== DW_INL_declared_inlined
)
19421 may_be_inlined
= 1;
19426 if (tag
== DW_TAG_imported_unit
)
19428 d
.sect_off
= attr
.get_ref_die_offset ();
19429 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19430 || cu
->per_cu
->is_dwz
);
19434 case DW_AT_main_subprogram
:
19435 main_subprogram
= attr
.as_boolean ();
19440 /* DW_AT_rnglists_base does not apply to DIEs from the DWO
19441 skeleton. We take advantage of the fact the DW_AT_ranges
19442 does not appear in DW_TAG_compile_unit of DWO files.
19444 Attributes of the form DW_FORM_rnglistx have already had
19445 their value changed by read_rnglist_index and already
19446 include DW_AT_rnglists_base, so don't need to add the ranges
19448 int need_ranges_base
= (tag
!= DW_TAG_compile_unit
19449 && attr
.form
!= DW_FORM_rnglistx
);
19450 /* It would be nice to reuse dwarf2_get_pc_bounds here,
19451 but that requires a full DIE, so instead we just
19453 unsigned int ranges_offset
= (attr
.constant_value (0)
19454 + (need_ranges_base
19458 /* Value of the DW_AT_ranges attribute is the offset in the
19459 .debug_ranges section. */
19460 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19471 /* For Ada, if both the name and the linkage name appear, we prefer
19472 the latter. This lets "catch exception" work better, regardless
19473 of the order in which the name and linkage name were emitted.
19474 Really, though, this is just a workaround for the fact that gdb
19475 doesn't store both the name and the linkage name. */
19476 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19477 raw_name
= linkage_name
;
19479 if (high_pc_relative
)
19482 if (has_low_pc_attr
&& has_high_pc_attr
)
19484 /* When using the GNU linker, .gnu.linkonce. sections are used to
19485 eliminate duplicate copies of functions and vtables and such.
19486 The linker will arbitrarily choose one and discard the others.
19487 The AT_*_pc values for such functions refer to local labels in
19488 these sections. If the section from that file was discarded, the
19489 labels are not in the output, so the relocs get a value of 0.
19490 If this is a discarded function, mark the pc bounds as invalid,
19491 so that GDB will ignore it. */
19492 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19494 struct objfile
*objfile
= per_objfile
->objfile
;
19495 struct gdbarch
*gdbarch
= objfile
->arch ();
19497 complaint (_("DW_AT_low_pc %s is zero "
19498 "for DIE at %s [in module %s]"),
19499 paddress (gdbarch
, lowpc
),
19500 sect_offset_str (sect_off
),
19501 objfile_name (objfile
));
19503 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19504 else if (lowpc
>= highpc
)
19506 struct objfile
*objfile
= per_objfile
->objfile
;
19507 struct gdbarch
*gdbarch
= objfile
->arch ();
19509 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19510 "for DIE at %s [in module %s]"),
19511 paddress (gdbarch
, lowpc
),
19512 paddress (gdbarch
, highpc
),
19513 sect_offset_str (sect_off
),
19514 objfile_name (objfile
));
19523 /* Find a cached partial DIE at OFFSET in CU. */
19525 struct partial_die_info
*
19526 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19528 struct partial_die_info
*lookup_die
= NULL
;
19529 struct partial_die_info
part_die (sect_off
);
19531 lookup_die
= ((struct partial_die_info
*)
19532 htab_find_with_hash (partial_dies
, &part_die
,
19533 to_underlying (sect_off
)));
19538 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19539 except in the case of .debug_types DIEs which do not reference
19540 outside their CU (they do however referencing other types via
19541 DW_FORM_ref_sig8). */
19543 static const struct cu_partial_die_info
19544 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19546 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19547 struct objfile
*objfile
= per_objfile
->objfile
;
19548 struct partial_die_info
*pd
= NULL
;
19550 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19551 && cu
->header
.offset_in_cu_p (sect_off
))
19553 pd
= cu
->find_partial_die (sect_off
);
19556 /* We missed recording what we needed.
19557 Load all dies and try again. */
19561 /* TUs don't reference other CUs/TUs (except via type signatures). */
19562 if (cu
->per_cu
->is_debug_types
)
19564 error (_("Dwarf Error: Type Unit at offset %s contains"
19565 " external reference to offset %s [in module %s].\n"),
19566 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19567 bfd_get_filename (objfile
->obfd
));
19569 dwarf2_per_cu_data
*per_cu
19570 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19573 cu
= per_objfile
->get_cu (per_cu
);
19574 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19575 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19577 cu
= per_objfile
->get_cu (per_cu
);
19580 pd
= cu
->find_partial_die (sect_off
);
19583 /* If we didn't find it, and not all dies have been loaded,
19584 load them all and try again. */
19586 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
19588 cu
->per_cu
->load_all_dies
= 1;
19590 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19591 THIS_CU->cu may already be in use. So we can't just free it and
19592 replace its DIEs with the ones we read in. Instead, we leave those
19593 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19594 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19596 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19598 pd
= cu
->find_partial_die (sect_off
);
19602 error (_("Dwarf Error: Cannot not find DIE at %s [from module %s]\n"),
19603 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19607 /* See if we can figure out if the class lives in a namespace. We do
19608 this by looking for a member function; its demangled name will
19609 contain namespace info, if there is any. */
19612 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19613 struct dwarf2_cu
*cu
)
19615 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19616 what template types look like, because the demangler
19617 frequently doesn't give the same name as the debug info. We
19618 could fix this by only using the demangled name to get the
19619 prefix (but see comment in read_structure_type). */
19621 struct partial_die_info
*real_pdi
;
19622 struct partial_die_info
*child_pdi
;
19624 /* If this DIE (this DIE's specification, if any) has a parent, then
19625 we should not do this. We'll prepend the parent's fully qualified
19626 name when we create the partial symbol. */
19628 real_pdi
= struct_pdi
;
19629 while (real_pdi
->has_specification
)
19631 auto res
= find_partial_die (real_pdi
->spec_offset
,
19632 real_pdi
->spec_is_dwz
, cu
);
19633 real_pdi
= res
.pdi
;
19637 if (real_pdi
->die_parent
!= NULL
)
19640 for (child_pdi
= struct_pdi
->die_child
;
19642 child_pdi
= child_pdi
->die_sibling
)
19644 if (child_pdi
->tag
== DW_TAG_subprogram
19645 && child_pdi
->linkage_name
!= NULL
)
19647 gdb::unique_xmalloc_ptr
<char> actual_class_name
19648 (cu
->language_defn
->class_name_from_physname
19649 (child_pdi
->linkage_name
));
19650 if (actual_class_name
!= NULL
)
19652 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19653 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19654 struct_pdi
->canonical_name
= 1;
19661 /* Return true if a DIE with TAG may have the DW_AT_const_value
19665 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19669 case DW_TAG_constant
:
19670 case DW_TAG_enumerator
:
19671 case DW_TAG_formal_parameter
:
19672 case DW_TAG_template_value_param
:
19673 case DW_TAG_variable
:
19681 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19683 /* Once we've fixed up a die, there's no point in doing so again.
19684 This also avoids a memory leak if we were to call
19685 guess_partial_die_structure_name multiple times. */
19689 /* If we found a reference attribute and the DIE has no name, try
19690 to find a name in the referred to DIE. */
19692 if (raw_name
== NULL
&& has_specification
)
19694 struct partial_die_info
*spec_die
;
19696 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19697 spec_die
= res
.pdi
;
19700 spec_die
->fixup (cu
);
19702 if (spec_die
->raw_name
)
19704 raw_name
= spec_die
->raw_name
;
19705 canonical_name
= spec_die
->canonical_name
;
19707 /* Copy DW_AT_external attribute if it is set. */
19708 if (spec_die
->is_external
)
19709 is_external
= spec_die
->is_external
;
19713 if (!has_const_value
&& has_specification
19714 && can_have_DW_AT_const_value_p (tag
))
19716 struct partial_die_info
*spec_die
;
19718 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19719 spec_die
= res
.pdi
;
19722 spec_die
->fixup (cu
);
19724 if (spec_die
->has_const_value
)
19726 /* Copy DW_AT_const_value attribute if it is set. */
19727 has_const_value
= spec_die
->has_const_value
;
19731 /* Set default names for some unnamed DIEs. */
19733 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19735 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19736 canonical_name
= 1;
19739 /* If there is no parent die to provide a namespace, and there are
19740 children, see if we can determine the namespace from their linkage
19742 if (cu
->language
== language_cplus
19743 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19744 && die_parent
== NULL
19746 && (tag
== DW_TAG_class_type
19747 || tag
== DW_TAG_structure_type
19748 || tag
== DW_TAG_union_type
))
19749 guess_partial_die_structure_name (this, cu
);
19751 /* GCC might emit a nameless struct or union that has a linkage
19752 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19753 if (raw_name
== NULL
19754 && (tag
== DW_TAG_class_type
19755 || tag
== DW_TAG_interface_type
19756 || tag
== DW_TAG_structure_type
19757 || tag
== DW_TAG_union_type
)
19758 && linkage_name
!= NULL
)
19760 gdb::unique_xmalloc_ptr
<char> demangled
19761 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19762 if (demangled
!= nullptr)
19766 /* Strip any leading namespaces/classes, keep only the base name.
19767 DW_AT_name for named DIEs does not contain the prefixes. */
19768 base
= strrchr (demangled
.get (), ':');
19769 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19772 base
= demangled
.get ();
19774 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19775 raw_name
= objfile
->intern (base
);
19776 canonical_name
= 1;
19783 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19784 contents from the given SECTION in the HEADER. */
19786 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19787 struct dwarf2_section_info
*section
)
19789 unsigned int bytes_read
;
19790 bfd
*abfd
= section
->get_bfd_owner ();
19791 const gdb_byte
*info_ptr
= section
->buffer
;
19792 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19793 info_ptr
+= bytes_read
;
19794 header
->version
= read_2_bytes (abfd
, info_ptr
);
19796 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19798 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19800 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19803 /* Return the DW_AT_loclists_base value for the CU. */
19805 lookup_loclist_base (struct dwarf2_cu
*cu
)
19807 /* For the .dwo unit, the loclist_base points to the first offset following
19808 the header. The header consists of the following entities-
19809 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19811 2. version (2 bytes)
19812 3. address size (1 byte)
19813 4. segment selector size (1 byte)
19814 5. offset entry count (4 bytes)
19815 These sizes are derived as per the DWARFv5 standard. */
19816 if (cu
->dwo_unit
!= nullptr)
19818 if (cu
->header
.initial_length_size
== 4)
19819 return LOCLIST_HEADER_SIZE32
;
19820 return LOCLIST_HEADER_SIZE64
;
19822 return cu
->loclist_base
;
19825 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19826 array of offsets in the .debug_loclists section. */
19828 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19830 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19831 struct objfile
*objfile
= per_objfile
->objfile
;
19832 bfd
*abfd
= objfile
->obfd
;
19833 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19834 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19836 section
->read (objfile
);
19837 if (section
->buffer
== NULL
)
19838 complaint (_("DW_FORM_loclistx used without .debug_loclists "
19839 "section [in module %s]"), objfile_name (objfile
));
19840 struct loclists_rnglists_header header
;
19841 read_loclists_rnglists_header (&header
, section
);
19842 if (loclist_index
>= header
.offset_entry_count
)
19843 complaint (_("DW_FORM_loclistx pointing outside of "
19844 ".debug_loclists offset array [in module %s]"),
19845 objfile_name (objfile
));
19846 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
19848 complaint (_("DW_FORM_loclistx pointing outside of "
19849 ".debug_loclists section [in module %s]"),
19850 objfile_name (objfile
));
19851 const gdb_byte
*info_ptr
19852 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19854 if (cu
->header
.offset_size
== 4)
19855 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
19857 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
19860 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19861 array of offsets in the .debug_rnglists section. */
19863 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19866 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19867 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19868 bfd
*abfd
= objfile
->obfd
;
19869 ULONGEST rnglist_header_size
=
19870 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19871 : RNGLIST_HEADER_SIZE64
);
19872 ULONGEST rnglist_base
=
19873 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->ranges_base
;
19874 ULONGEST start_offset
=
19875 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19877 /* Get rnglists section. */
19878 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19880 /* Read the rnglists section content. */
19881 section
->read (objfile
);
19882 if (section
->buffer
== nullptr)
19883 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19885 objfile_name (objfile
));
19887 /* Verify the rnglist index is valid. */
19888 struct loclists_rnglists_header header
;
19889 read_loclists_rnglists_header (&header
, section
);
19890 if (rnglist_index
>= header
.offset_entry_count
)
19891 error (_("DW_FORM_rnglistx index pointing outside of "
19892 ".debug_rnglists offset array [in module %s]"),
19893 objfile_name (objfile
));
19895 /* Validate that the offset is within the section's range. */
19896 if (start_offset
>= section
->size
)
19897 error (_("DW_FORM_rnglistx pointing outside of "
19898 ".debug_rnglists section [in module %s]"),
19899 objfile_name (objfile
));
19901 /* Validate that reading won't go beyond the end of the section. */
19902 if (start_offset
+ cu
->header
.offset_size
> rnglist_base
+ section
->size
)
19903 error (_("Reading DW_FORM_rnglistx index beyond end of"
19904 ".debug_rnglists section [in module %s]"),
19905 objfile_name (objfile
));
19907 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19909 if (cu
->header
.offset_size
== 4)
19910 return read_4_bytes (abfd
, info_ptr
) + rnglist_base
;
19912 return read_8_bytes (abfd
, info_ptr
) + rnglist_base
;
19915 /* Process the attributes that had to be skipped in the first round. These
19916 attributes are the ones that need str_offsets_base or addr_base attributes.
19917 They could not have been processed in the first round, because at the time
19918 the values of str_offsets_base or addr_base may not have been known. */
19920 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19921 struct attribute
*attr
, dwarf_tag tag
)
19923 struct dwarf2_cu
*cu
= reader
->cu
;
19924 switch (attr
->form
)
19926 case DW_FORM_addrx
:
19927 case DW_FORM_GNU_addr_index
:
19928 attr
->set_address (read_addr_index (cu
,
19929 attr
->as_unsigned_reprocess ()));
19931 case DW_FORM_loclistx
:
19932 attr
->set_address (read_loclist_index (cu
, attr
->as_unsigned ()));
19934 case DW_FORM_rnglistx
:
19935 attr
->set_address (read_rnglist_index (cu
, attr
->as_unsigned (), tag
));
19938 case DW_FORM_strx1
:
19939 case DW_FORM_strx2
:
19940 case DW_FORM_strx3
:
19941 case DW_FORM_strx4
:
19942 case DW_FORM_GNU_str_index
:
19944 unsigned int str_index
= attr
->as_unsigned_reprocess ();
19945 gdb_assert (!attr
->canonical_string_p ());
19946 if (reader
->dwo_file
!= NULL
)
19947 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
19950 attr
->set_string_noncanonical (read_stub_str_index (cu
,
19955 gdb_assert_not_reached (_("Unexpected DWARF form."));
19959 /* Read an attribute value described by an attribute form. */
19961 static const gdb_byte
*
19962 read_attribute_value (const struct die_reader_specs
*reader
,
19963 struct attribute
*attr
, unsigned form
,
19964 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19966 struct dwarf2_cu
*cu
= reader
->cu
;
19967 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19968 struct objfile
*objfile
= per_objfile
->objfile
;
19969 bfd
*abfd
= reader
->abfd
;
19970 struct comp_unit_head
*cu_header
= &cu
->header
;
19971 unsigned int bytes_read
;
19972 struct dwarf_block
*blk
;
19974 attr
->form
= (enum dwarf_form
) form
;
19977 case DW_FORM_ref_addr
:
19978 if (cu
->header
.version
== 2)
19979 attr
->set_unsigned (cu
->header
.read_address (abfd
, info_ptr
,
19982 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
19984 info_ptr
+= bytes_read
;
19986 case DW_FORM_GNU_ref_alt
:
19987 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
19989 info_ptr
+= bytes_read
;
19993 struct gdbarch
*gdbarch
= objfile
->arch ();
19994 CORE_ADDR addr
= cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19995 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
19996 attr
->set_address (addr
);
19997 info_ptr
+= bytes_read
;
20000 case DW_FORM_block2
:
20001 blk
= dwarf_alloc_block (cu
);
20002 blk
->size
= read_2_bytes (abfd
, info_ptr
);
20004 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20005 info_ptr
+= blk
->size
;
20006 attr
->set_block (blk
);
20008 case DW_FORM_block4
:
20009 blk
= dwarf_alloc_block (cu
);
20010 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20012 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20013 info_ptr
+= blk
->size
;
20014 attr
->set_block (blk
);
20016 case DW_FORM_data2
:
20017 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20020 case DW_FORM_data4
:
20021 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20024 case DW_FORM_data8
:
20025 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20028 case DW_FORM_data16
:
20029 blk
= dwarf_alloc_block (cu
);
20031 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20033 attr
->set_block (blk
);
20035 case DW_FORM_sec_offset
:
20036 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
20038 info_ptr
+= bytes_read
;
20040 case DW_FORM_loclistx
:
20042 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20044 info_ptr
+= bytes_read
;
20047 case DW_FORM_string
:
20048 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20050 info_ptr
+= bytes_read
;
20053 if (!cu
->per_cu
->is_dwz
)
20055 attr
->set_string_noncanonical
20056 (read_indirect_string (per_objfile
,
20057 abfd
, info_ptr
, cu_header
,
20059 info_ptr
+= bytes_read
;
20063 case DW_FORM_line_strp
:
20064 if (!cu
->per_cu
->is_dwz
)
20066 attr
->set_string_noncanonical
20067 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20069 info_ptr
+= bytes_read
;
20073 case DW_FORM_GNU_strp_alt
:
20075 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
20076 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20079 attr
->set_string_noncanonical
20080 (dwz
->read_string (objfile
, str_offset
));
20081 info_ptr
+= bytes_read
;
20084 case DW_FORM_exprloc
:
20085 case DW_FORM_block
:
20086 blk
= dwarf_alloc_block (cu
);
20087 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20088 info_ptr
+= bytes_read
;
20089 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20090 info_ptr
+= blk
->size
;
20091 attr
->set_block (blk
);
20093 case DW_FORM_block1
:
20094 blk
= dwarf_alloc_block (cu
);
20095 blk
->size
= read_1_byte (abfd
, info_ptr
);
20097 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20098 info_ptr
+= blk
->size
;
20099 attr
->set_block (blk
);
20101 case DW_FORM_data1
:
20103 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20106 case DW_FORM_flag_present
:
20107 attr
->set_unsigned (1);
20109 case DW_FORM_sdata
:
20110 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20111 info_ptr
+= bytes_read
;
20113 case DW_FORM_rnglistx
:
20115 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20117 info_ptr
+= bytes_read
;
20120 case DW_FORM_udata
:
20121 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20122 info_ptr
+= bytes_read
;
20125 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20126 + read_1_byte (abfd
, info_ptr
)));
20130 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20131 + read_2_bytes (abfd
, info_ptr
)));
20135 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20136 + read_4_bytes (abfd
, info_ptr
)));
20140 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20141 + read_8_bytes (abfd
, info_ptr
)));
20144 case DW_FORM_ref_sig8
:
20145 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20148 case DW_FORM_ref_udata
:
20149 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20150 + read_unsigned_leb128 (abfd
, info_ptr
,
20152 info_ptr
+= bytes_read
;
20154 case DW_FORM_indirect
:
20155 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20156 info_ptr
+= bytes_read
;
20157 if (form
== DW_FORM_implicit_const
)
20159 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20160 info_ptr
+= bytes_read
;
20162 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20165 case DW_FORM_implicit_const
:
20166 attr
->set_signed (implicit_const
);
20168 case DW_FORM_addrx
:
20169 case DW_FORM_GNU_addr_index
:
20170 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20172 info_ptr
+= bytes_read
;
20175 case DW_FORM_strx1
:
20176 case DW_FORM_strx2
:
20177 case DW_FORM_strx3
:
20178 case DW_FORM_strx4
:
20179 case DW_FORM_GNU_str_index
:
20181 ULONGEST str_index
;
20182 if (form
== DW_FORM_strx1
)
20184 str_index
= read_1_byte (abfd
, info_ptr
);
20187 else if (form
== DW_FORM_strx2
)
20189 str_index
= read_2_bytes (abfd
, info_ptr
);
20192 else if (form
== DW_FORM_strx3
)
20194 str_index
= read_3_bytes (abfd
, info_ptr
);
20197 else if (form
== DW_FORM_strx4
)
20199 str_index
= read_4_bytes (abfd
, info_ptr
);
20204 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20205 info_ptr
+= bytes_read
;
20207 attr
->set_unsigned_reprocess (str_index
);
20211 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20212 dwarf_form_name (form
),
20213 bfd_get_filename (abfd
));
20217 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20218 attr
->form
= DW_FORM_GNU_ref_alt
;
20220 /* We have seen instances where the compiler tried to emit a byte
20221 size attribute of -1 which ended up being encoded as an unsigned
20222 0xffffffff. Although 0xffffffff is technically a valid size value,
20223 an object of this size seems pretty unlikely so we can relatively
20224 safely treat these cases as if the size attribute was invalid and
20225 treat them as zero by default. */
20226 if (attr
->name
== DW_AT_byte_size
20227 && form
== DW_FORM_data4
20228 && attr
->as_unsigned () >= 0xffffffff)
20231 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20232 hex_string (attr
->as_unsigned ()));
20233 attr
->set_unsigned (0);
20239 /* Read an attribute described by an abbreviated attribute. */
20241 static const gdb_byte
*
20242 read_attribute (const struct die_reader_specs
*reader
,
20243 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
20244 const gdb_byte
*info_ptr
)
20246 attr
->name
= abbrev
->name
;
20247 attr
->string_is_canonical
= 0;
20248 attr
->requires_reprocessing
= 0;
20249 return read_attribute_value (reader
, attr
, abbrev
->form
,
20250 abbrev
->implicit_const
, info_ptr
);
20253 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20255 static const char *
20256 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20257 LONGEST str_offset
)
20259 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20260 str_offset
, "DW_FORM_strp");
20263 /* Return pointer to string at .debug_str offset as read from BUF.
20264 BUF is assumed to be in a compilation unit described by CU_HEADER.
20265 Return *BYTES_READ_PTR count of bytes read from BUF. */
20267 static const char *
20268 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20269 const gdb_byte
*buf
,
20270 const struct comp_unit_head
*cu_header
,
20271 unsigned int *bytes_read_ptr
)
20273 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20275 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20281 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20282 const struct comp_unit_head
*cu_header
,
20283 unsigned int *bytes_read_ptr
)
20285 bfd
*abfd
= objfile
->obfd
;
20286 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20288 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20291 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20292 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20293 ADDR_SIZE is the size of addresses from the CU header. */
20296 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20297 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20299 struct objfile
*objfile
= per_objfile
->objfile
;
20300 bfd
*abfd
= objfile
->obfd
;
20301 const gdb_byte
*info_ptr
;
20302 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20304 per_objfile
->per_bfd
->addr
.read (objfile
);
20305 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20306 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20307 objfile_name (objfile
));
20308 if (addr_base_or_zero
+ addr_index
* addr_size
20309 >= per_objfile
->per_bfd
->addr
.size
)
20310 error (_("DW_FORM_addr_index pointing outside of "
20311 ".debug_addr section [in module %s]"),
20312 objfile_name (objfile
));
20313 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20314 + addr_index
* addr_size
);
20315 if (addr_size
== 4)
20316 return bfd_get_32 (abfd
, info_ptr
);
20318 return bfd_get_64 (abfd
, info_ptr
);
20321 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20324 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20326 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20327 cu
->addr_base
, cu
->header
.addr_size
);
20330 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20333 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20334 unsigned int *bytes_read
)
20336 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20337 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20339 return read_addr_index (cu
, addr_index
);
20345 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20346 dwarf2_per_objfile
*per_objfile
,
20347 unsigned int addr_index
)
20349 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20350 gdb::optional
<ULONGEST
> addr_base
;
20353 /* We need addr_base and addr_size.
20354 If we don't have PER_CU->cu, we have to get it.
20355 Nasty, but the alternative is storing the needed info in PER_CU,
20356 which at this point doesn't seem justified: it's not clear how frequently
20357 it would get used and it would increase the size of every PER_CU.
20358 Entry points like dwarf2_per_cu_addr_size do a similar thing
20359 so we're not in uncharted territory here.
20360 Alas we need to be a bit more complicated as addr_base is contained
20363 We don't need to read the entire CU(/TU).
20364 We just need the header and top level die.
20366 IWBN to use the aging mechanism to let us lazily later discard the CU.
20367 For now we skip this optimization. */
20371 addr_base
= cu
->addr_base
;
20372 addr_size
= cu
->header
.addr_size
;
20376 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20377 addr_base
= reader
.cu
->addr_base
;
20378 addr_size
= reader
.cu
->header
.addr_size
;
20381 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20384 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20385 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20388 static const char *
20389 read_str_index (struct dwarf2_cu
*cu
,
20390 struct dwarf2_section_info
*str_section
,
20391 struct dwarf2_section_info
*str_offsets_section
,
20392 ULONGEST str_offsets_base
, ULONGEST str_index
)
20394 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20395 struct objfile
*objfile
= per_objfile
->objfile
;
20396 const char *objf_name
= objfile_name (objfile
);
20397 bfd
*abfd
= objfile
->obfd
;
20398 const gdb_byte
*info_ptr
;
20399 ULONGEST str_offset
;
20400 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20402 str_section
->read (objfile
);
20403 str_offsets_section
->read (objfile
);
20404 if (str_section
->buffer
== NULL
)
20405 error (_("%s used without %s section"
20406 " in CU at offset %s [in module %s]"),
20407 form_name
, str_section
->get_name (),
20408 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20409 if (str_offsets_section
->buffer
== NULL
)
20410 error (_("%s used without %s section"
20411 " in CU at offset %s [in module %s]"),
20412 form_name
, str_section
->get_name (),
20413 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20414 info_ptr
= (str_offsets_section
->buffer
20416 + str_index
* cu
->header
.offset_size
);
20417 if (cu
->header
.offset_size
== 4)
20418 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20420 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20421 if (str_offset
>= str_section
->size
)
20422 error (_("Offset from %s pointing outside of"
20423 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20424 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20425 return (const char *) (str_section
->buffer
+ str_offset
);
20428 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20430 static const char *
20431 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20433 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20434 ? reader
->cu
->header
.addr_size
: 0;
20435 return read_str_index (reader
->cu
,
20436 &reader
->dwo_file
->sections
.str
,
20437 &reader
->dwo_file
->sections
.str_offsets
,
20438 str_offsets_base
, str_index
);
20441 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20443 static const char *
20444 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20446 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20447 const char *objf_name
= objfile_name (objfile
);
20448 static const char form_name
[] = "DW_FORM_GNU_str_index";
20449 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20451 if (!cu
->str_offsets_base
.has_value ())
20452 error (_("%s used in Fission stub without %s"
20453 " in CU at offset 0x%lx [in module %s]"),
20454 form_name
, str_offsets_attr_name
,
20455 (long) cu
->header
.offset_size
, objf_name
);
20457 return read_str_index (cu
,
20458 &cu
->per_objfile
->per_bfd
->str
,
20459 &cu
->per_objfile
->per_bfd
->str_offsets
,
20460 *cu
->str_offsets_base
, str_index
);
20463 /* Return the length of an LEB128 number in BUF. */
20466 leb128_size (const gdb_byte
*buf
)
20468 const gdb_byte
*begin
= buf
;
20474 if ((byte
& 128) == 0)
20475 return buf
- begin
;
20480 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20489 cu
->language
= language_c
;
20492 case DW_LANG_C_plus_plus
:
20493 case DW_LANG_C_plus_plus_11
:
20494 case DW_LANG_C_plus_plus_14
:
20495 cu
->language
= language_cplus
;
20498 cu
->language
= language_d
;
20500 case DW_LANG_Fortran77
:
20501 case DW_LANG_Fortran90
:
20502 case DW_LANG_Fortran95
:
20503 case DW_LANG_Fortran03
:
20504 case DW_LANG_Fortran08
:
20505 cu
->language
= language_fortran
;
20508 cu
->language
= language_go
;
20510 case DW_LANG_Mips_Assembler
:
20511 cu
->language
= language_asm
;
20513 case DW_LANG_Ada83
:
20514 case DW_LANG_Ada95
:
20515 cu
->language
= language_ada
;
20517 case DW_LANG_Modula2
:
20518 cu
->language
= language_m2
;
20520 case DW_LANG_Pascal83
:
20521 cu
->language
= language_pascal
;
20524 cu
->language
= language_objc
;
20527 case DW_LANG_Rust_old
:
20528 cu
->language
= language_rust
;
20530 case DW_LANG_Cobol74
:
20531 case DW_LANG_Cobol85
:
20533 cu
->language
= language_minimal
;
20536 cu
->language_defn
= language_def (cu
->language
);
20539 /* Return the named attribute or NULL if not there. */
20541 static struct attribute
*
20542 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20547 struct attribute
*spec
= NULL
;
20549 for (i
= 0; i
< die
->num_attrs
; ++i
)
20551 if (die
->attrs
[i
].name
== name
)
20552 return &die
->attrs
[i
];
20553 if (die
->attrs
[i
].name
== DW_AT_specification
20554 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20555 spec
= &die
->attrs
[i
];
20561 die
= follow_die_ref (die
, spec
, &cu
);
20567 /* Return the string associated with a string-typed attribute, or NULL if it
20568 is either not found or is of an incorrect type. */
20570 static const char *
20571 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20573 struct attribute
*attr
;
20574 const char *str
= NULL
;
20576 attr
= dwarf2_attr (die
, name
, cu
);
20580 str
= attr
->as_string ();
20581 if (str
== nullptr)
20582 complaint (_("string type expected for attribute %s for "
20583 "DIE at %s in module %s"),
20584 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20585 objfile_name (cu
->per_objfile
->objfile
));
20591 /* Return the dwo name or NULL if not present. If present, it is in either
20592 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20593 static const char *
20594 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20596 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20597 if (dwo_name
== nullptr)
20598 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20602 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20603 and holds a non-zero value. This function should only be used for
20604 DW_FORM_flag or DW_FORM_flag_present attributes. */
20607 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20609 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20611 return attr
!= nullptr && attr
->as_boolean ();
20615 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20617 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20618 which value is non-zero. However, we have to be careful with
20619 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20620 (via dwarf2_flag_true_p) follows this attribute. So we may
20621 end up accidently finding a declaration attribute that belongs
20622 to a different DIE referenced by the specification attribute,
20623 even though the given DIE does not have a declaration attribute. */
20624 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20625 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20628 /* Return the die giving the specification for DIE, if there is
20629 one. *SPEC_CU is the CU containing DIE on input, and the CU
20630 containing the return value on output. If there is no
20631 specification, but there is an abstract origin, that is
20634 static struct die_info
*
20635 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20637 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20640 if (spec_attr
== NULL
)
20641 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20643 if (spec_attr
== NULL
)
20646 return follow_die_ref (die
, spec_attr
, spec_cu
);
20649 /* Stub for free_line_header to match void * callback types. */
20652 free_line_header_voidp (void *arg
)
20654 struct line_header
*lh
= (struct line_header
*) arg
;
20659 /* A convenience function to find the proper .debug_line section for a CU. */
20661 static struct dwarf2_section_info
*
20662 get_debug_line_section (struct dwarf2_cu
*cu
)
20664 struct dwarf2_section_info
*section
;
20665 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20667 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20669 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20670 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20671 else if (cu
->per_cu
->is_dwz
)
20673 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
20675 section
= &dwz
->line
;
20678 section
= &per_objfile
->per_bfd
->line
;
20683 /* Read the statement program header starting at OFFSET in
20684 .debug_line, or .debug_line.dwo. Return a pointer
20685 to a struct line_header, allocated using xmalloc.
20686 Returns NULL if there is a problem reading the header, e.g., if it
20687 has a version we don't understand.
20689 NOTE: the strings in the include directory and file name tables of
20690 the returned object point into the dwarf line section buffer,
20691 and must not be freed. */
20693 static line_header_up
20694 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20696 struct dwarf2_section_info
*section
;
20697 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20699 section
= get_debug_line_section (cu
);
20700 section
->read (per_objfile
->objfile
);
20701 if (section
->buffer
== NULL
)
20703 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20704 complaint (_("missing .debug_line.dwo section"));
20706 complaint (_("missing .debug_line section"));
20710 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20711 per_objfile
, section
, &cu
->header
);
20714 /* Subroutine of dwarf_decode_lines to simplify it.
20715 Return the file name of the psymtab for the given file_entry.
20716 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20717 If space for the result is malloc'd, *NAME_HOLDER will be set.
20718 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20720 static const char *
20721 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20722 const dwarf2_psymtab
*pst
,
20723 const char *comp_dir
,
20724 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20726 const char *include_name
= fe
.name
;
20727 const char *include_name_to_compare
= include_name
;
20728 const char *pst_filename
;
20731 const char *dir_name
= fe
.include_dir (lh
);
20733 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20734 if (!IS_ABSOLUTE_PATH (include_name
)
20735 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20737 /* Avoid creating a duplicate psymtab for PST.
20738 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20739 Before we do the comparison, however, we need to account
20740 for DIR_NAME and COMP_DIR.
20741 First prepend dir_name (if non-NULL). If we still don't
20742 have an absolute path prepend comp_dir (if non-NULL).
20743 However, the directory we record in the include-file's
20744 psymtab does not contain COMP_DIR (to match the
20745 corresponding symtab(s)).
20750 bash$ gcc -g ./hello.c
20751 include_name = "hello.c"
20753 DW_AT_comp_dir = comp_dir = "/tmp"
20754 DW_AT_name = "./hello.c"
20758 if (dir_name
!= NULL
)
20760 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20761 include_name
, (char *) NULL
));
20762 include_name
= name_holder
->get ();
20763 include_name_to_compare
= include_name
;
20765 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20767 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20768 include_name
, (char *) NULL
));
20769 include_name_to_compare
= hold_compare
.get ();
20773 pst_filename
= pst
->filename
;
20774 gdb::unique_xmalloc_ptr
<char> copied_name
;
20775 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20777 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20778 pst_filename
, (char *) NULL
));
20779 pst_filename
= copied_name
.get ();
20782 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20786 return include_name
;
20789 /* State machine to track the state of the line number program. */
20791 class lnp_state_machine
20794 /* Initialize a machine state for the start of a line number
20796 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20797 bool record_lines_p
);
20799 file_entry
*current_file ()
20801 /* lh->file_names is 0-based, but the file name numbers in the
20802 statement program are 1-based. */
20803 return m_line_header
->file_name_at (m_file
);
20806 /* Record the line in the state machine. END_SEQUENCE is true if
20807 we're processing the end of a sequence. */
20808 void record_line (bool end_sequence
);
20810 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20811 nop-out rest of the lines in this sequence. */
20812 void check_line_address (struct dwarf2_cu
*cu
,
20813 const gdb_byte
*line_ptr
,
20814 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20816 void handle_set_discriminator (unsigned int discriminator
)
20818 m_discriminator
= discriminator
;
20819 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20822 /* Handle DW_LNE_set_address. */
20823 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20826 address
+= baseaddr
;
20827 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20830 /* Handle DW_LNS_advance_pc. */
20831 void handle_advance_pc (CORE_ADDR adjust
);
20833 /* Handle a special opcode. */
20834 void handle_special_opcode (unsigned char op_code
);
20836 /* Handle DW_LNS_advance_line. */
20837 void handle_advance_line (int line_delta
)
20839 advance_line (line_delta
);
20842 /* Handle DW_LNS_set_file. */
20843 void handle_set_file (file_name_index file
);
20845 /* Handle DW_LNS_negate_stmt. */
20846 void handle_negate_stmt ()
20848 m_is_stmt
= !m_is_stmt
;
20851 /* Handle DW_LNS_const_add_pc. */
20852 void handle_const_add_pc ();
20854 /* Handle DW_LNS_fixed_advance_pc. */
20855 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20857 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20861 /* Handle DW_LNS_copy. */
20862 void handle_copy ()
20864 record_line (false);
20865 m_discriminator
= 0;
20868 /* Handle DW_LNE_end_sequence. */
20869 void handle_end_sequence ()
20871 m_currently_recording_lines
= true;
20875 /* Advance the line by LINE_DELTA. */
20876 void advance_line (int line_delta
)
20878 m_line
+= line_delta
;
20880 if (line_delta
!= 0)
20881 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20884 struct dwarf2_cu
*m_cu
;
20886 gdbarch
*m_gdbarch
;
20888 /* True if we're recording lines.
20889 Otherwise we're building partial symtabs and are just interested in
20890 finding include files mentioned by the line number program. */
20891 bool m_record_lines_p
;
20893 /* The line number header. */
20894 line_header
*m_line_header
;
20896 /* These are part of the standard DWARF line number state machine,
20897 and initialized according to the DWARF spec. */
20899 unsigned char m_op_index
= 0;
20900 /* The line table index of the current file. */
20901 file_name_index m_file
= 1;
20902 unsigned int m_line
= 1;
20904 /* These are initialized in the constructor. */
20906 CORE_ADDR m_address
;
20908 unsigned int m_discriminator
;
20910 /* Additional bits of state we need to track. */
20912 /* The last file that we called dwarf2_start_subfile for.
20913 This is only used for TLLs. */
20914 unsigned int m_last_file
= 0;
20915 /* The last file a line number was recorded for. */
20916 struct subfile
*m_last_subfile
= NULL
;
20918 /* The address of the last line entry. */
20919 CORE_ADDR m_last_address
;
20921 /* Set to true when a previous line at the same address (using
20922 m_last_address) had m_is_stmt true. This is reset to false when a
20923 line entry at a new address (m_address different to m_last_address) is
20925 bool m_stmt_at_address
= false;
20927 /* When true, record the lines we decode. */
20928 bool m_currently_recording_lines
= false;
20930 /* The last line number that was recorded, used to coalesce
20931 consecutive entries for the same line. This can happen, for
20932 example, when discriminators are present. PR 17276. */
20933 unsigned int m_last_line
= 0;
20934 bool m_line_has_non_zero_discriminator
= false;
20938 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20940 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20941 / m_line_header
->maximum_ops_per_instruction
)
20942 * m_line_header
->minimum_instruction_length
);
20943 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20944 m_op_index
= ((m_op_index
+ adjust
)
20945 % m_line_header
->maximum_ops_per_instruction
);
20949 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20951 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20952 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20953 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20954 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20955 / m_line_header
->maximum_ops_per_instruction
)
20956 * m_line_header
->minimum_instruction_length
);
20957 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20958 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20959 % m_line_header
->maximum_ops_per_instruction
);
20961 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20962 advance_line (line_delta
);
20963 record_line (false);
20964 m_discriminator
= 0;
20968 lnp_state_machine::handle_set_file (file_name_index file
)
20972 const file_entry
*fe
= current_file ();
20974 dwarf2_debug_line_missing_file_complaint ();
20975 else if (m_record_lines_p
)
20977 const char *dir
= fe
->include_dir (m_line_header
);
20979 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20980 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20981 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20986 lnp_state_machine::handle_const_add_pc ()
20989 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20992 = (((m_op_index
+ adjust
)
20993 / m_line_header
->maximum_ops_per_instruction
)
20994 * m_line_header
->minimum_instruction_length
);
20996 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20997 m_op_index
= ((m_op_index
+ adjust
)
20998 % m_line_header
->maximum_ops_per_instruction
);
21001 /* Return non-zero if we should add LINE to the line number table.
21002 LINE is the line to add, LAST_LINE is the last line that was added,
21003 LAST_SUBFILE is the subfile for LAST_LINE.
21004 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21005 had a non-zero discriminator.
21007 We have to be careful in the presence of discriminators.
21008 E.g., for this line:
21010 for (i = 0; i < 100000; i++);
21012 clang can emit four line number entries for that one line,
21013 each with a different discriminator.
21014 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21016 However, we want gdb to coalesce all four entries into one.
21017 Otherwise the user could stepi into the middle of the line and
21018 gdb would get confused about whether the pc really was in the
21019 middle of the line.
21021 Things are further complicated by the fact that two consecutive
21022 line number entries for the same line is a heuristic used by gcc
21023 to denote the end of the prologue. So we can't just discard duplicate
21024 entries, we have to be selective about it. The heuristic we use is
21025 that we only collapse consecutive entries for the same line if at least
21026 one of those entries has a non-zero discriminator. PR 17276.
21028 Note: Addresses in the line number state machine can never go backwards
21029 within one sequence, thus this coalescing is ok. */
21032 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21033 unsigned int line
, unsigned int last_line
,
21034 int line_has_non_zero_discriminator
,
21035 struct subfile
*last_subfile
)
21037 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21039 if (line
!= last_line
)
21041 /* Same line for the same file that we've seen already.
21042 As a last check, for pr 17276, only record the line if the line
21043 has never had a non-zero discriminator. */
21044 if (!line_has_non_zero_discriminator
)
21049 /* Use the CU's builder to record line number LINE beginning at
21050 address ADDRESS in the line table of subfile SUBFILE. */
21053 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21054 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
21055 struct dwarf2_cu
*cu
)
21057 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21059 if (dwarf_line_debug
)
21061 fprintf_unfiltered (gdb_stdlog
,
21062 "Recording line %u, file %s, address %s\n",
21063 line
, lbasename (subfile
->name
),
21064 paddress (gdbarch
, address
));
21068 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21071 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21072 Mark the end of a set of line number records.
21073 The arguments are the same as for dwarf_record_line_1.
21074 If SUBFILE is NULL the request is ignored. */
21077 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21078 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21080 if (subfile
== NULL
)
21083 if (dwarf_line_debug
)
21085 fprintf_unfiltered (gdb_stdlog
,
21086 "Finishing current line, file %s, address %s\n",
21087 lbasename (subfile
->name
),
21088 paddress (gdbarch
, address
));
21091 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21095 lnp_state_machine::record_line (bool end_sequence
)
21097 if (dwarf_line_debug
)
21099 fprintf_unfiltered (gdb_stdlog
,
21100 "Processing actual line %u: file %u,"
21101 " address %s, is_stmt %u, discrim %u%s\n",
21103 paddress (m_gdbarch
, m_address
),
21104 m_is_stmt
, m_discriminator
,
21105 (end_sequence
? "\t(end sequence)" : ""));
21108 file_entry
*fe
= current_file ();
21111 dwarf2_debug_line_missing_file_complaint ();
21112 /* For now we ignore lines not starting on an instruction boundary.
21113 But not when processing end_sequence for compatibility with the
21114 previous version of the code. */
21115 else if (m_op_index
== 0 || end_sequence
)
21117 fe
->included_p
= 1;
21118 if (m_record_lines_p
)
21120 /* When we switch files we insert an end maker in the first file,
21121 switch to the second file and add a new line entry. The
21122 problem is that the end marker inserted in the first file will
21123 discard any previous line entries at the same address. If the
21124 line entries in the first file are marked as is-stmt, while
21125 the new line in the second file is non-stmt, then this means
21126 the end marker will discard is-stmt lines so we can have a
21127 non-stmt line. This means that there are less addresses at
21128 which the user can insert a breakpoint.
21130 To improve this we track the last address in m_last_address,
21131 and whether we have seen an is-stmt at this address. Then
21132 when switching files, if we have seen a stmt at the current
21133 address, and we are switching to create a non-stmt line, then
21134 discard the new line. */
21136 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21137 bool ignore_this_line
21138 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21139 && !m_is_stmt
&& m_stmt_at_address
)
21140 || (!end_sequence
&& m_line
== 0));
21142 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21144 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21145 m_currently_recording_lines
? m_cu
: nullptr);
21148 if (!end_sequence
&& !ignore_this_line
)
21150 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21152 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21153 m_line_has_non_zero_discriminator
,
21156 buildsym_compunit
*builder
= m_cu
->get_builder ();
21157 dwarf_record_line_1 (m_gdbarch
,
21158 builder
->get_current_subfile (),
21159 m_line
, m_address
, is_stmt
,
21160 m_currently_recording_lines
? m_cu
: nullptr);
21162 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21163 m_last_line
= m_line
;
21168 /* Track whether we have seen any m_is_stmt true at m_address in case we
21169 have multiple line table entries all at m_address. */
21170 if (m_last_address
!= m_address
)
21172 m_stmt_at_address
= false;
21173 m_last_address
= m_address
;
21175 m_stmt_at_address
|= m_is_stmt
;
21178 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21179 line_header
*lh
, bool record_lines_p
)
21183 m_record_lines_p
= record_lines_p
;
21184 m_line_header
= lh
;
21186 m_currently_recording_lines
= true;
21188 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21189 was a line entry for it so that the backend has a chance to adjust it
21190 and also record it in case it needs it. This is currently used by MIPS
21191 code, cf. `mips_adjust_dwarf2_line'. */
21192 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21193 m_is_stmt
= lh
->default_is_stmt
;
21194 m_discriminator
= 0;
21196 m_last_address
= m_address
;
21197 m_stmt_at_address
= false;
21201 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21202 const gdb_byte
*line_ptr
,
21203 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21205 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21206 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21207 located at 0x0. In this case, additionally check that if
21208 ADDRESS < UNRELOCATED_LOWPC. */
21210 if ((address
== 0 && address
< unrelocated_lowpc
)
21211 || address
== (CORE_ADDR
) -1)
21213 /* This line table is for a function which has been
21214 GCd by the linker. Ignore it. PR gdb/12528 */
21216 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21217 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21219 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21220 line_offset
, objfile_name (objfile
));
21221 m_currently_recording_lines
= false;
21222 /* Note: m_currently_recording_lines is left as false until we see
21223 DW_LNE_end_sequence. */
21227 /* Subroutine of dwarf_decode_lines to simplify it.
21228 Process the line number information in LH.
21229 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21230 program in order to set included_p for every referenced header. */
21233 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21234 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21236 const gdb_byte
*line_ptr
, *extended_end
;
21237 const gdb_byte
*line_end
;
21238 unsigned int bytes_read
, extended_len
;
21239 unsigned char op_code
, extended_op
;
21240 CORE_ADDR baseaddr
;
21241 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21242 bfd
*abfd
= objfile
->obfd
;
21243 struct gdbarch
*gdbarch
= objfile
->arch ();
21244 /* True if we're recording line info (as opposed to building partial
21245 symtabs and just interested in finding include files mentioned by
21246 the line number program). */
21247 bool record_lines_p
= !decode_for_pst_p
;
21249 baseaddr
= objfile
->text_section_offset ();
21251 line_ptr
= lh
->statement_program_start
;
21252 line_end
= lh
->statement_program_end
;
21254 /* Read the statement sequences until there's nothing left. */
21255 while (line_ptr
< line_end
)
21257 /* The DWARF line number program state machine. Reset the state
21258 machine at the start of each sequence. */
21259 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21260 bool end_sequence
= false;
21262 if (record_lines_p
)
21264 /* Start a subfile for the current file of the state
21266 const file_entry
*fe
= state_machine
.current_file ();
21269 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21272 /* Decode the table. */
21273 while (line_ptr
< line_end
&& !end_sequence
)
21275 op_code
= read_1_byte (abfd
, line_ptr
);
21278 if (op_code
>= lh
->opcode_base
)
21280 /* Special opcode. */
21281 state_machine
.handle_special_opcode (op_code
);
21283 else switch (op_code
)
21285 case DW_LNS_extended_op
:
21286 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21288 line_ptr
+= bytes_read
;
21289 extended_end
= line_ptr
+ extended_len
;
21290 extended_op
= read_1_byte (abfd
, line_ptr
);
21292 if (DW_LNE_lo_user
<= extended_op
21293 && extended_op
<= DW_LNE_hi_user
)
21295 /* Vendor extension, ignore. */
21296 line_ptr
= extended_end
;
21299 switch (extended_op
)
21301 case DW_LNE_end_sequence
:
21302 state_machine
.handle_end_sequence ();
21303 end_sequence
= true;
21305 case DW_LNE_set_address
:
21308 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21309 line_ptr
+= bytes_read
;
21311 state_machine
.check_line_address (cu
, line_ptr
,
21312 lowpc
- baseaddr
, address
);
21313 state_machine
.handle_set_address (baseaddr
, address
);
21316 case DW_LNE_define_file
:
21318 const char *cur_file
;
21319 unsigned int mod_time
, length
;
21322 cur_file
= read_direct_string (abfd
, line_ptr
,
21324 line_ptr
+= bytes_read
;
21325 dindex
= (dir_index
)
21326 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21327 line_ptr
+= bytes_read
;
21329 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21330 line_ptr
+= bytes_read
;
21332 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21333 line_ptr
+= bytes_read
;
21334 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21337 case DW_LNE_set_discriminator
:
21339 /* The discriminator is not interesting to the
21340 debugger; just ignore it. We still need to
21341 check its value though:
21342 if there are consecutive entries for the same
21343 (non-prologue) line we want to coalesce them.
21346 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21347 line_ptr
+= bytes_read
;
21349 state_machine
.handle_set_discriminator (discr
);
21353 complaint (_("mangled .debug_line section"));
21356 /* Make sure that we parsed the extended op correctly. If e.g.
21357 we expected a different address size than the producer used,
21358 we may have read the wrong number of bytes. */
21359 if (line_ptr
!= extended_end
)
21361 complaint (_("mangled .debug_line section"));
21366 state_machine
.handle_copy ();
21368 case DW_LNS_advance_pc
:
21371 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21372 line_ptr
+= bytes_read
;
21374 state_machine
.handle_advance_pc (adjust
);
21377 case DW_LNS_advance_line
:
21380 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21381 line_ptr
+= bytes_read
;
21383 state_machine
.handle_advance_line (line_delta
);
21386 case DW_LNS_set_file
:
21388 file_name_index file
21389 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21391 line_ptr
+= bytes_read
;
21393 state_machine
.handle_set_file (file
);
21396 case DW_LNS_set_column
:
21397 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21398 line_ptr
+= bytes_read
;
21400 case DW_LNS_negate_stmt
:
21401 state_machine
.handle_negate_stmt ();
21403 case DW_LNS_set_basic_block
:
21405 /* Add to the address register of the state machine the
21406 address increment value corresponding to special opcode
21407 255. I.e., this value is scaled by the minimum
21408 instruction length since special opcode 255 would have
21409 scaled the increment. */
21410 case DW_LNS_const_add_pc
:
21411 state_machine
.handle_const_add_pc ();
21413 case DW_LNS_fixed_advance_pc
:
21415 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21418 state_machine
.handle_fixed_advance_pc (addr_adj
);
21423 /* Unknown standard opcode, ignore it. */
21426 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21428 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21429 line_ptr
+= bytes_read
;
21436 dwarf2_debug_line_missing_end_sequence_complaint ();
21438 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21439 in which case we still finish recording the last line). */
21440 state_machine
.record_line (true);
21444 /* Decode the Line Number Program (LNP) for the given line_header
21445 structure and CU. The actual information extracted and the type
21446 of structures created from the LNP depends on the value of PST.
21448 1. If PST is NULL, then this procedure uses the data from the program
21449 to create all necessary symbol tables, and their linetables.
21451 2. If PST is not NULL, this procedure reads the program to determine
21452 the list of files included by the unit represented by PST, and
21453 builds all the associated partial symbol tables.
21455 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21456 It is used for relative paths in the line table.
21457 NOTE: When processing partial symtabs (pst != NULL),
21458 comp_dir == pst->dirname.
21460 NOTE: It is important that psymtabs have the same file name (via strcmp)
21461 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21462 symtab we don't use it in the name of the psymtabs we create.
21463 E.g. expand_line_sal requires this when finding psymtabs to expand.
21464 A good testcase for this is mb-inline.exp.
21466 LOWPC is the lowest address in CU (or 0 if not known).
21468 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21469 for its PC<->lines mapping information. Otherwise only the filename
21470 table is read in. */
21473 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21474 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21475 CORE_ADDR lowpc
, int decode_mapping
)
21477 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21478 const int decode_for_pst_p
= (pst
!= NULL
);
21480 if (decode_mapping
)
21481 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21483 if (decode_for_pst_p
)
21485 /* Now that we're done scanning the Line Header Program, we can
21486 create the psymtab of each included file. */
21487 for (auto &file_entry
: lh
->file_names ())
21488 if (file_entry
.included_p
== 1)
21490 gdb::unique_xmalloc_ptr
<char> name_holder
;
21491 const char *include_name
=
21492 psymtab_include_file_name (lh
, file_entry
, pst
,
21493 comp_dir
, &name_holder
);
21494 if (include_name
!= NULL
)
21495 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21500 /* Make sure a symtab is created for every file, even files
21501 which contain only variables (i.e. no code with associated
21503 buildsym_compunit
*builder
= cu
->get_builder ();
21504 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21506 for (auto &fe
: lh
->file_names ())
21508 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21509 if (builder
->get_current_subfile ()->symtab
== NULL
)
21511 builder
->get_current_subfile ()->symtab
21512 = allocate_symtab (cust
,
21513 builder
->get_current_subfile ()->name
);
21515 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21520 /* Start a subfile for DWARF. FILENAME is the name of the file and
21521 DIRNAME the name of the source directory which contains FILENAME
21522 or NULL if not known.
21523 This routine tries to keep line numbers from identical absolute and
21524 relative file names in a common subfile.
21526 Using the `list' example from the GDB testsuite, which resides in
21527 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21528 of /srcdir/list0.c yields the following debugging information for list0.c:
21530 DW_AT_name: /srcdir/list0.c
21531 DW_AT_comp_dir: /compdir
21532 files.files[0].name: list0.h
21533 files.files[0].dir: /srcdir
21534 files.files[1].name: list0.c
21535 files.files[1].dir: /srcdir
21537 The line number information for list0.c has to end up in a single
21538 subfile, so that `break /srcdir/list0.c:1' works as expected.
21539 start_subfile will ensure that this happens provided that we pass the
21540 concatenation of files.files[1].dir and files.files[1].name as the
21544 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21545 const char *dirname
)
21547 gdb::unique_xmalloc_ptr
<char> copy
;
21549 /* In order not to lose the line information directory,
21550 we concatenate it to the filename when it makes sense.
21551 Note that the Dwarf3 standard says (speaking of filenames in line
21552 information): ``The directory index is ignored for file names
21553 that represent full path names''. Thus ignoring dirname in the
21554 `else' branch below isn't an issue. */
21556 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21558 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21559 filename
= copy
.get ();
21562 cu
->get_builder ()->start_subfile (filename
);
21565 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21566 buildsym_compunit constructor. */
21568 struct compunit_symtab
*
21569 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21572 gdb_assert (m_builder
== nullptr);
21574 m_builder
.reset (new struct buildsym_compunit
21575 (this->per_objfile
->objfile
,
21576 name
, comp_dir
, language
, low_pc
));
21578 list_in_scope
= get_builder ()->get_file_symbols ();
21580 get_builder ()->record_debugformat ("DWARF 2");
21581 get_builder ()->record_producer (producer
);
21583 processing_has_namespace_info
= false;
21585 return get_builder ()->get_compunit_symtab ();
21589 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21590 struct dwarf2_cu
*cu
)
21592 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21593 struct comp_unit_head
*cu_header
= &cu
->header
;
21595 /* NOTE drow/2003-01-30: There used to be a comment and some special
21596 code here to turn a symbol with DW_AT_external and a
21597 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21598 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21599 with some versions of binutils) where shared libraries could have
21600 relocations against symbols in their debug information - the
21601 minimal symbol would have the right address, but the debug info
21602 would not. It's no longer necessary, because we will explicitly
21603 apply relocations when we read in the debug information now. */
21605 /* A DW_AT_location attribute with no contents indicates that a
21606 variable has been optimized away. */
21607 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21609 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21613 /* Handle one degenerate form of location expression specially, to
21614 preserve GDB's previous behavior when section offsets are
21615 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21616 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21618 if (attr
->form_is_block ())
21620 struct dwarf_block
*block
= attr
->as_block ();
21622 if ((block
->data
[0] == DW_OP_addr
21623 && block
->size
== 1 + cu_header
->addr_size
)
21624 || ((block
->data
[0] == DW_OP_GNU_addr_index
21625 || block
->data
[0] == DW_OP_addrx
)
21627 == 1 + leb128_size (&block
->data
[1]))))
21629 unsigned int dummy
;
21631 if (block
->data
[0] == DW_OP_addr
)
21632 SET_SYMBOL_VALUE_ADDRESS
21633 (sym
, cu
->header
.read_address (objfile
->obfd
,
21637 SET_SYMBOL_VALUE_ADDRESS
21638 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21640 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21641 fixup_symbol_section (sym
, objfile
);
21642 SET_SYMBOL_VALUE_ADDRESS
21644 SYMBOL_VALUE_ADDRESS (sym
)
21645 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
21650 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21651 expression evaluator, and use LOC_COMPUTED only when necessary
21652 (i.e. when the value of a register or memory location is
21653 referenced, or a thread-local block, etc.). Then again, it might
21654 not be worthwhile. I'm assuming that it isn't unless performance
21655 or memory numbers show me otherwise. */
21657 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21659 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21660 cu
->has_loclist
= true;
21663 /* Given a pointer to a DWARF information entry, figure out if we need
21664 to make a symbol table entry for it, and if so, create a new entry
21665 and return a pointer to it.
21666 If TYPE is NULL, determine symbol type from the die, otherwise
21667 used the passed type.
21668 If SPACE is not NULL, use it to hold the new symbol. If it is
21669 NULL, allocate a new symbol on the objfile's obstack. */
21671 static struct symbol
*
21672 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21673 struct symbol
*space
)
21675 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21676 struct objfile
*objfile
= per_objfile
->objfile
;
21677 struct gdbarch
*gdbarch
= objfile
->arch ();
21678 struct symbol
*sym
= NULL
;
21680 struct attribute
*attr
= NULL
;
21681 struct attribute
*attr2
= NULL
;
21682 CORE_ADDR baseaddr
;
21683 struct pending
**list_to_add
= NULL
;
21685 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21687 baseaddr
= objfile
->text_section_offset ();
21689 name
= dwarf2_name (die
, cu
);
21692 int suppress_add
= 0;
21697 sym
= new (&objfile
->objfile_obstack
) symbol
;
21698 OBJSTAT (objfile
, n_syms
++);
21700 /* Cache this symbol's name and the name's demangled form (if any). */
21701 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21702 /* Fortran does not have mangling standard and the mangling does differ
21703 between gfortran, iFort etc. */
21704 const char *physname
21705 = (cu
->language
== language_fortran
21706 ? dwarf2_full_name (name
, die
, cu
)
21707 : dwarf2_physname (name
, die
, cu
));
21708 const char *linkagename
= dw2_linkage_name (die
, cu
);
21710 if (linkagename
== nullptr || cu
->language
== language_ada
)
21711 sym
->set_linkage_name (physname
);
21714 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21715 sym
->set_linkage_name (linkagename
);
21718 /* Default assumptions.
21719 Use the passed type or decode it from the die. */
21720 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21721 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21723 SYMBOL_TYPE (sym
) = type
;
21725 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21726 attr
= dwarf2_attr (die
,
21727 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21729 if (attr
!= nullptr)
21730 SYMBOL_LINE (sym
) = attr
->constant_value (0);
21732 attr
= dwarf2_attr (die
,
21733 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21735 if (attr
!= nullptr && attr
->form_is_unsigned ())
21737 file_name_index file_index
21738 = (file_name_index
) attr
->as_unsigned ();
21739 struct file_entry
*fe
;
21741 if (cu
->line_header
!= NULL
)
21742 fe
= cu
->line_header
->file_name_at (file_index
);
21747 complaint (_("file index out of range"));
21749 symbol_set_symtab (sym
, fe
->symtab
);
21755 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21756 if (attr
!= nullptr)
21760 addr
= attr
->as_address ();
21761 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21762 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21763 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21766 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21767 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21768 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21769 add_symbol_to_list (sym
, cu
->list_in_scope
);
21771 case DW_TAG_subprogram
:
21772 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21774 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21775 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21776 if ((attr2
!= nullptr && attr2
->as_boolean ())
21777 || cu
->language
== language_ada
21778 || cu
->language
== language_fortran
)
21780 /* Subprograms marked external are stored as a global symbol.
21781 Ada and Fortran subprograms, whether marked external or
21782 not, are always stored as a global symbol, because we want
21783 to be able to access them globally. For instance, we want
21784 to be able to break on a nested subprogram without having
21785 to specify the context. */
21786 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21790 list_to_add
= cu
->list_in_scope
;
21793 case DW_TAG_inlined_subroutine
:
21794 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21796 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21797 SYMBOL_INLINED (sym
) = 1;
21798 list_to_add
= cu
->list_in_scope
;
21800 case DW_TAG_template_value_param
:
21802 /* Fall through. */
21803 case DW_TAG_constant
:
21804 case DW_TAG_variable
:
21805 case DW_TAG_member
:
21806 /* Compilation with minimal debug info may result in
21807 variables with missing type entries. Change the
21808 misleading `void' type to something sensible. */
21809 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
21810 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21812 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21813 /* In the case of DW_TAG_member, we should only be called for
21814 static const members. */
21815 if (die
->tag
== DW_TAG_member
)
21817 /* dwarf2_add_field uses die_is_declaration,
21818 so we do the same. */
21819 gdb_assert (die_is_declaration (die
, cu
));
21822 if (attr
!= nullptr)
21824 dwarf2_const_value (attr
, sym
, cu
);
21825 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21828 if (attr2
!= nullptr && attr2
->as_boolean ())
21829 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21831 list_to_add
= cu
->list_in_scope
;
21835 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21836 if (attr
!= nullptr)
21838 var_decode_location (attr
, sym
, cu
);
21839 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21841 /* Fortran explicitly imports any global symbols to the local
21842 scope by DW_TAG_common_block. */
21843 if (cu
->language
== language_fortran
&& die
->parent
21844 && die
->parent
->tag
== DW_TAG_common_block
)
21847 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21848 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21849 && !per_objfile
->per_bfd
->has_section_at_zero
)
21851 /* When a static variable is eliminated by the linker,
21852 the corresponding debug information is not stripped
21853 out, but the variable address is set to null;
21854 do not add such variables into symbol table. */
21856 else if (attr2
!= nullptr && attr2
->as_boolean ())
21858 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21859 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21860 && per_objfile
->per_bfd
->can_copy
)
21862 /* A global static variable might be subject to
21863 copy relocation. We first check for a local
21864 minsym, though, because maybe the symbol was
21865 marked hidden, in which case this would not
21867 bound_minimal_symbol found
21868 = (lookup_minimal_symbol_linkage
21869 (sym
->linkage_name (), objfile
));
21870 if (found
.minsym
!= nullptr)
21871 sym
->maybe_copied
= 1;
21874 /* A variable with DW_AT_external is never static,
21875 but it may be block-scoped. */
21877 = ((cu
->list_in_scope
21878 == cu
->get_builder ()->get_file_symbols ())
21879 ? cu
->get_builder ()->get_global_symbols ()
21880 : cu
->list_in_scope
);
21883 list_to_add
= cu
->list_in_scope
;
21887 /* We do not know the address of this symbol.
21888 If it is an external symbol and we have type information
21889 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21890 The address of the variable will then be determined from
21891 the minimal symbol table whenever the variable is
21893 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21895 /* Fortran explicitly imports any global symbols to the local
21896 scope by DW_TAG_common_block. */
21897 if (cu
->language
== language_fortran
&& die
->parent
21898 && die
->parent
->tag
== DW_TAG_common_block
)
21900 /* SYMBOL_CLASS doesn't matter here because
21901 read_common_block is going to reset it. */
21903 list_to_add
= cu
->list_in_scope
;
21905 else if (attr2
!= nullptr && attr2
->as_boolean ()
21906 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21908 /* A variable with DW_AT_external is never static, but it
21909 may be block-scoped. */
21911 = ((cu
->list_in_scope
21912 == cu
->get_builder ()->get_file_symbols ())
21913 ? cu
->get_builder ()->get_global_symbols ()
21914 : cu
->list_in_scope
);
21916 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21918 else if (!die_is_declaration (die
, cu
))
21920 /* Use the default LOC_OPTIMIZED_OUT class. */
21921 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21923 list_to_add
= cu
->list_in_scope
;
21927 case DW_TAG_formal_parameter
:
21929 /* If we are inside a function, mark this as an argument. If
21930 not, we might be looking at an argument to an inlined function
21931 when we do not have enough information to show inlined frames;
21932 pretend it's a local variable in that case so that the user can
21934 struct context_stack
*curr
21935 = cu
->get_builder ()->get_current_context_stack ();
21936 if (curr
!= nullptr && curr
->name
!= nullptr)
21937 SYMBOL_IS_ARGUMENT (sym
) = 1;
21938 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21939 if (attr
!= nullptr)
21941 var_decode_location (attr
, sym
, cu
);
21943 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21944 if (attr
!= nullptr)
21946 dwarf2_const_value (attr
, sym
, cu
);
21949 list_to_add
= cu
->list_in_scope
;
21952 case DW_TAG_unspecified_parameters
:
21953 /* From varargs functions; gdb doesn't seem to have any
21954 interest in this information, so just ignore it for now.
21957 case DW_TAG_template_type_param
:
21959 /* Fall through. */
21960 case DW_TAG_class_type
:
21961 case DW_TAG_interface_type
:
21962 case DW_TAG_structure_type
:
21963 case DW_TAG_union_type
:
21964 case DW_TAG_set_type
:
21965 case DW_TAG_enumeration_type
:
21966 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21967 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21970 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21971 really ever be static objects: otherwise, if you try
21972 to, say, break of a class's method and you're in a file
21973 which doesn't mention that class, it won't work unless
21974 the check for all static symbols in lookup_symbol_aux
21975 saves you. See the OtherFileClass tests in
21976 gdb.c++/namespace.exp. */
21980 buildsym_compunit
*builder
= cu
->get_builder ();
21982 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21983 && cu
->language
== language_cplus
21984 ? builder
->get_global_symbols ()
21985 : cu
->list_in_scope
);
21987 /* The semantics of C++ state that "struct foo {
21988 ... }" also defines a typedef for "foo". */
21989 if (cu
->language
== language_cplus
21990 || cu
->language
== language_ada
21991 || cu
->language
== language_d
21992 || cu
->language
== language_rust
)
21994 /* The symbol's name is already allocated along
21995 with this objfile, so we don't need to
21996 duplicate it for the type. */
21997 if (SYMBOL_TYPE (sym
)->name () == 0)
21998 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
22003 case DW_TAG_typedef
:
22004 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22005 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22006 list_to_add
= cu
->list_in_scope
;
22008 case DW_TAG_array_type
:
22009 case DW_TAG_base_type
:
22010 case DW_TAG_subrange_type
:
22011 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22012 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22013 list_to_add
= cu
->list_in_scope
;
22015 case DW_TAG_enumerator
:
22016 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22017 if (attr
!= nullptr)
22019 dwarf2_const_value (attr
, sym
, cu
);
22022 /* NOTE: carlton/2003-11-10: See comment above in the
22023 DW_TAG_class_type, etc. block. */
22026 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22027 && cu
->language
== language_cplus
22028 ? cu
->get_builder ()->get_global_symbols ()
22029 : cu
->list_in_scope
);
22032 case DW_TAG_imported_declaration
:
22033 case DW_TAG_namespace
:
22034 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22035 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22037 case DW_TAG_module
:
22038 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22039 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22040 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22042 case DW_TAG_common_block
:
22043 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22044 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22045 add_symbol_to_list (sym
, cu
->list_in_scope
);
22048 /* Not a tag we recognize. Hopefully we aren't processing
22049 trash data, but since we must specifically ignore things
22050 we don't recognize, there is nothing else we should do at
22052 complaint (_("unsupported tag: '%s'"),
22053 dwarf_tag_name (die
->tag
));
22059 sym
->hash_next
= objfile
->template_symbols
;
22060 objfile
->template_symbols
= sym
;
22061 list_to_add
= NULL
;
22064 if (list_to_add
!= NULL
)
22065 add_symbol_to_list (sym
, list_to_add
);
22067 /* For the benefit of old versions of GCC, check for anonymous
22068 namespaces based on the demangled name. */
22069 if (!cu
->processing_has_namespace_info
22070 && cu
->language
== language_cplus
)
22071 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22076 /* Given an attr with a DW_FORM_dataN value in host byte order,
22077 zero-extend it as appropriate for the symbol's type. The DWARF
22078 standard (v4) is not entirely clear about the meaning of using
22079 DW_FORM_dataN for a constant with a signed type, where the type is
22080 wider than the data. The conclusion of a discussion on the DWARF
22081 list was that this is unspecified. We choose to always zero-extend
22082 because that is the interpretation long in use by GCC. */
22085 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22086 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22088 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22089 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22090 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22091 LONGEST l
= attr
->constant_value (0);
22093 if (bits
< sizeof (*value
) * 8)
22095 l
&= ((LONGEST
) 1 << bits
) - 1;
22098 else if (bits
== sizeof (*value
) * 8)
22102 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22103 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22110 /* Read a constant value from an attribute. Either set *VALUE, or if
22111 the value does not fit in *VALUE, set *BYTES - either already
22112 allocated on the objfile obstack, or newly allocated on OBSTACK,
22113 or, set *BATON, if we translated the constant to a location
22117 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22118 const char *name
, struct obstack
*obstack
,
22119 struct dwarf2_cu
*cu
,
22120 LONGEST
*value
, const gdb_byte
**bytes
,
22121 struct dwarf2_locexpr_baton
**baton
)
22123 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22124 struct objfile
*objfile
= per_objfile
->objfile
;
22125 struct comp_unit_head
*cu_header
= &cu
->header
;
22126 struct dwarf_block
*blk
;
22127 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22128 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22134 switch (attr
->form
)
22137 case DW_FORM_addrx
:
22138 case DW_FORM_GNU_addr_index
:
22142 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22143 dwarf2_const_value_length_mismatch_complaint (name
,
22144 cu_header
->addr_size
,
22145 TYPE_LENGTH (type
));
22146 /* Symbols of this form are reasonably rare, so we just
22147 piggyback on the existing location code rather than writing
22148 a new implementation of symbol_computed_ops. */
22149 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22150 (*baton
)->per_objfile
= per_objfile
;
22151 (*baton
)->per_cu
= cu
->per_cu
;
22152 gdb_assert ((*baton
)->per_cu
);
22154 (*baton
)->size
= 2 + cu_header
->addr_size
;
22155 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22156 (*baton
)->data
= data
;
22158 data
[0] = DW_OP_addr
;
22159 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22160 byte_order
, attr
->as_address ());
22161 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22164 case DW_FORM_string
:
22167 case DW_FORM_GNU_str_index
:
22168 case DW_FORM_GNU_strp_alt
:
22169 /* The string is already allocated on the objfile obstack, point
22171 *bytes
= (const gdb_byte
*) attr
->as_string ();
22173 case DW_FORM_block1
:
22174 case DW_FORM_block2
:
22175 case DW_FORM_block4
:
22176 case DW_FORM_block
:
22177 case DW_FORM_exprloc
:
22178 case DW_FORM_data16
:
22179 blk
= attr
->as_block ();
22180 if (TYPE_LENGTH (type
) != blk
->size
)
22181 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22182 TYPE_LENGTH (type
));
22183 *bytes
= blk
->data
;
22186 /* The DW_AT_const_value attributes are supposed to carry the
22187 symbol's value "represented as it would be on the target
22188 architecture." By the time we get here, it's already been
22189 converted to host endianness, so we just need to sign- or
22190 zero-extend it as appropriate. */
22191 case DW_FORM_data1
:
22192 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22194 case DW_FORM_data2
:
22195 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22197 case DW_FORM_data4
:
22198 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22200 case DW_FORM_data8
:
22201 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22204 case DW_FORM_sdata
:
22205 case DW_FORM_implicit_const
:
22206 *value
= attr
->as_signed ();
22209 case DW_FORM_udata
:
22210 *value
= attr
->as_unsigned ();
22214 complaint (_("unsupported const value attribute form: '%s'"),
22215 dwarf_form_name (attr
->form
));
22222 /* Copy constant value from an attribute to a symbol. */
22225 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22226 struct dwarf2_cu
*cu
)
22228 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22230 const gdb_byte
*bytes
;
22231 struct dwarf2_locexpr_baton
*baton
;
22233 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22234 sym
->print_name (),
22235 &objfile
->objfile_obstack
, cu
,
22236 &value
, &bytes
, &baton
);
22240 SYMBOL_LOCATION_BATON (sym
) = baton
;
22241 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22243 else if (bytes
!= NULL
)
22245 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22246 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22250 SYMBOL_VALUE (sym
) = value
;
22251 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22255 /* Return the type of the die in question using its DW_AT_type attribute. */
22257 static struct type
*
22258 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22260 struct attribute
*type_attr
;
22262 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22265 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22266 /* A missing DW_AT_type represents a void type. */
22267 return objfile_type (objfile
)->builtin_void
;
22270 return lookup_die_type (die
, type_attr
, cu
);
22273 /* True iff CU's producer generates GNAT Ada auxiliary information
22274 that allows to find parallel types through that information instead
22275 of having to do expensive parallel lookups by type name. */
22278 need_gnat_info (struct dwarf2_cu
*cu
)
22280 /* Assume that the Ada compiler was GNAT, which always produces
22281 the auxiliary information. */
22282 return (cu
->language
== language_ada
);
22285 /* Return the auxiliary type of the die in question using its
22286 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22287 attribute is not present. */
22289 static struct type
*
22290 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22292 struct attribute
*type_attr
;
22294 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22298 return lookup_die_type (die
, type_attr
, cu
);
22301 /* If DIE has a descriptive_type attribute, then set the TYPE's
22302 descriptive type accordingly. */
22305 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22306 struct dwarf2_cu
*cu
)
22308 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22310 if (descriptive_type
)
22312 ALLOCATE_GNAT_AUX_TYPE (type
);
22313 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22317 /* Return the containing type of the die in question using its
22318 DW_AT_containing_type attribute. */
22320 static struct type
*
22321 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22323 struct attribute
*type_attr
;
22324 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22326 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22328 error (_("Dwarf Error: Problem turning containing type into gdb type "
22329 "[in module %s]"), objfile_name (objfile
));
22331 return lookup_die_type (die
, type_attr
, cu
);
22334 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22336 static struct type
*
22337 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22339 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22340 struct objfile
*objfile
= per_objfile
->objfile
;
22343 std::string message
22344 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22345 objfile_name (objfile
),
22346 sect_offset_str (cu
->header
.sect_off
),
22347 sect_offset_str (die
->sect_off
));
22348 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22350 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22353 /* Look up the type of DIE in CU using its type attribute ATTR.
22354 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22355 DW_AT_containing_type.
22356 If there is no type substitute an error marker. */
22358 static struct type
*
22359 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22360 struct dwarf2_cu
*cu
)
22362 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22363 struct objfile
*objfile
= per_objfile
->objfile
;
22364 struct type
*this_type
;
22366 gdb_assert (attr
->name
== DW_AT_type
22367 || attr
->name
== DW_AT_GNAT_descriptive_type
22368 || attr
->name
== DW_AT_containing_type
);
22370 /* First see if we have it cached. */
22372 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22374 struct dwarf2_per_cu_data
*per_cu
;
22375 sect_offset sect_off
= attr
->get_ref_die_offset ();
22377 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22378 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22380 else if (attr
->form_is_ref ())
22382 sect_offset sect_off
= attr
->get_ref_die_offset ();
22384 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22386 else if (attr
->form
== DW_FORM_ref_sig8
)
22388 ULONGEST signature
= attr
->as_signature ();
22390 return get_signatured_type (die
, signature
, cu
);
22394 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22395 " at %s [in module %s]"),
22396 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22397 objfile_name (objfile
));
22398 return build_error_marker_type (cu
, die
);
22401 /* If not cached we need to read it in. */
22403 if (this_type
== NULL
)
22405 struct die_info
*type_die
= NULL
;
22406 struct dwarf2_cu
*type_cu
= cu
;
22408 if (attr
->form_is_ref ())
22409 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22410 if (type_die
== NULL
)
22411 return build_error_marker_type (cu
, die
);
22412 /* If we find the type now, it's probably because the type came
22413 from an inter-CU reference and the type's CU got expanded before
22415 this_type
= read_type_die (type_die
, type_cu
);
22418 /* If we still don't have a type use an error marker. */
22420 if (this_type
== NULL
)
22421 return build_error_marker_type (cu
, die
);
22426 /* Return the type in DIE, CU.
22427 Returns NULL for invalid types.
22429 This first does a lookup in die_type_hash,
22430 and only reads the die in if necessary.
22432 NOTE: This can be called when reading in partial or full symbols. */
22434 static struct type
*
22435 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22437 struct type
*this_type
;
22439 this_type
= get_die_type (die
, cu
);
22443 return read_type_die_1 (die
, cu
);
22446 /* Read the type in DIE, CU.
22447 Returns NULL for invalid types. */
22449 static struct type
*
22450 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22452 struct type
*this_type
= NULL
;
22456 case DW_TAG_class_type
:
22457 case DW_TAG_interface_type
:
22458 case DW_TAG_structure_type
:
22459 case DW_TAG_union_type
:
22460 this_type
= read_structure_type (die
, cu
);
22462 case DW_TAG_enumeration_type
:
22463 this_type
= read_enumeration_type (die
, cu
);
22465 case DW_TAG_subprogram
:
22466 case DW_TAG_subroutine_type
:
22467 case DW_TAG_inlined_subroutine
:
22468 this_type
= read_subroutine_type (die
, cu
);
22470 case DW_TAG_array_type
:
22471 this_type
= read_array_type (die
, cu
);
22473 case DW_TAG_set_type
:
22474 this_type
= read_set_type (die
, cu
);
22476 case DW_TAG_pointer_type
:
22477 this_type
= read_tag_pointer_type (die
, cu
);
22479 case DW_TAG_ptr_to_member_type
:
22480 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22482 case DW_TAG_reference_type
:
22483 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22485 case DW_TAG_rvalue_reference_type
:
22486 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22488 case DW_TAG_const_type
:
22489 this_type
= read_tag_const_type (die
, cu
);
22491 case DW_TAG_volatile_type
:
22492 this_type
= read_tag_volatile_type (die
, cu
);
22494 case DW_TAG_restrict_type
:
22495 this_type
= read_tag_restrict_type (die
, cu
);
22497 case DW_TAG_string_type
:
22498 this_type
= read_tag_string_type (die
, cu
);
22500 case DW_TAG_typedef
:
22501 this_type
= read_typedef (die
, cu
);
22503 case DW_TAG_subrange_type
:
22504 this_type
= read_subrange_type (die
, cu
);
22506 case DW_TAG_base_type
:
22507 this_type
= read_base_type (die
, cu
);
22509 case DW_TAG_unspecified_type
:
22510 this_type
= read_unspecified_type (die
, cu
);
22512 case DW_TAG_namespace
:
22513 this_type
= read_namespace_type (die
, cu
);
22515 case DW_TAG_module
:
22516 this_type
= read_module_type (die
, cu
);
22518 case DW_TAG_atomic_type
:
22519 this_type
= read_tag_atomic_type (die
, cu
);
22522 complaint (_("unexpected tag in read_type_die: '%s'"),
22523 dwarf_tag_name (die
->tag
));
22530 /* See if we can figure out if the class lives in a namespace. We do
22531 this by looking for a member function; its demangled name will
22532 contain namespace info, if there is any.
22533 Return the computed name or NULL.
22534 Space for the result is allocated on the objfile's obstack.
22535 This is the full-die version of guess_partial_die_structure_name.
22536 In this case we know DIE has no useful parent. */
22538 static const char *
22539 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22541 struct die_info
*spec_die
;
22542 struct dwarf2_cu
*spec_cu
;
22543 struct die_info
*child
;
22544 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22547 spec_die
= die_specification (die
, &spec_cu
);
22548 if (spec_die
!= NULL
)
22554 for (child
= die
->child
;
22556 child
= child
->sibling
)
22558 if (child
->tag
== DW_TAG_subprogram
)
22560 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22562 if (linkage_name
!= NULL
)
22564 gdb::unique_xmalloc_ptr
<char> actual_name
22565 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22566 const char *name
= NULL
;
22568 if (actual_name
!= NULL
)
22570 const char *die_name
= dwarf2_name (die
, cu
);
22572 if (die_name
!= NULL
22573 && strcmp (die_name
, actual_name
.get ()) != 0)
22575 /* Strip off the class name from the full name.
22576 We want the prefix. */
22577 int die_name_len
= strlen (die_name
);
22578 int actual_name_len
= strlen (actual_name
.get ());
22579 const char *ptr
= actual_name
.get ();
22581 /* Test for '::' as a sanity check. */
22582 if (actual_name_len
> die_name_len
+ 2
22583 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22584 name
= obstack_strndup (
22585 &objfile
->per_bfd
->storage_obstack
,
22586 ptr
, actual_name_len
- die_name_len
- 2);
22597 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22598 prefix part in such case. See
22599 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22601 static const char *
22602 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22604 struct attribute
*attr
;
22607 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22608 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22611 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22614 attr
= dw2_linkage_name_attr (die
, cu
);
22615 const char *attr_name
= attr
->as_string ();
22616 if (attr
== NULL
|| attr_name
== NULL
)
22619 /* dwarf2_name had to be already called. */
22620 gdb_assert (attr
->canonical_string_p ());
22622 /* Strip the base name, keep any leading namespaces/classes. */
22623 base
= strrchr (attr_name
, ':');
22624 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22627 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22628 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22630 &base
[-1] - attr_name
);
22633 /* Return the name of the namespace/class that DIE is defined within,
22634 or "" if we can't tell. The caller should not xfree the result.
22636 For example, if we're within the method foo() in the following
22646 then determine_prefix on foo's die will return "N::C". */
22648 static const char *
22649 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22651 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22652 struct die_info
*parent
, *spec_die
;
22653 struct dwarf2_cu
*spec_cu
;
22654 struct type
*parent_type
;
22655 const char *retval
;
22657 if (cu
->language
!= language_cplus
22658 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22659 && cu
->language
!= language_rust
)
22662 retval
= anonymous_struct_prefix (die
, cu
);
22666 /* We have to be careful in the presence of DW_AT_specification.
22667 For example, with GCC 3.4, given the code
22671 // Definition of N::foo.
22675 then we'll have a tree of DIEs like this:
22677 1: DW_TAG_compile_unit
22678 2: DW_TAG_namespace // N
22679 3: DW_TAG_subprogram // declaration of N::foo
22680 4: DW_TAG_subprogram // definition of N::foo
22681 DW_AT_specification // refers to die #3
22683 Thus, when processing die #4, we have to pretend that we're in
22684 the context of its DW_AT_specification, namely the contex of die
22687 spec_die
= die_specification (die
, &spec_cu
);
22688 if (spec_die
== NULL
)
22689 parent
= die
->parent
;
22692 parent
= spec_die
->parent
;
22696 if (parent
== NULL
)
22698 else if (parent
->building_fullname
)
22701 const char *parent_name
;
22703 /* It has been seen on RealView 2.2 built binaries,
22704 DW_TAG_template_type_param types actually _defined_ as
22705 children of the parent class:
22708 template class <class Enum> Class{};
22709 Class<enum E> class_e;
22711 1: DW_TAG_class_type (Class)
22712 2: DW_TAG_enumeration_type (E)
22713 3: DW_TAG_enumerator (enum1:0)
22714 3: DW_TAG_enumerator (enum2:1)
22716 2: DW_TAG_template_type_param
22717 DW_AT_type DW_FORM_ref_udata (E)
22719 Besides being broken debug info, it can put GDB into an
22720 infinite loop. Consider:
22722 When we're building the full name for Class<E>, we'll start
22723 at Class, and go look over its template type parameters,
22724 finding E. We'll then try to build the full name of E, and
22725 reach here. We're now trying to build the full name of E,
22726 and look over the parent DIE for containing scope. In the
22727 broken case, if we followed the parent DIE of E, we'd again
22728 find Class, and once again go look at its template type
22729 arguments, etc., etc. Simply don't consider such parent die
22730 as source-level parent of this die (it can't be, the language
22731 doesn't allow it), and break the loop here. */
22732 name
= dwarf2_name (die
, cu
);
22733 parent_name
= dwarf2_name (parent
, cu
);
22734 complaint (_("template param type '%s' defined within parent '%s'"),
22735 name
? name
: "<unknown>",
22736 parent_name
? parent_name
: "<unknown>");
22740 switch (parent
->tag
)
22742 case DW_TAG_namespace
:
22743 parent_type
= read_type_die (parent
, cu
);
22744 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22745 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22746 Work around this problem here. */
22747 if (cu
->language
== language_cplus
22748 && strcmp (parent_type
->name (), "::") == 0)
22750 /* We give a name to even anonymous namespaces. */
22751 return parent_type
->name ();
22752 case DW_TAG_class_type
:
22753 case DW_TAG_interface_type
:
22754 case DW_TAG_structure_type
:
22755 case DW_TAG_union_type
:
22756 case DW_TAG_module
:
22757 parent_type
= read_type_die (parent
, cu
);
22758 if (parent_type
->name () != NULL
)
22759 return parent_type
->name ();
22761 /* An anonymous structure is only allowed non-static data
22762 members; no typedefs, no member functions, et cetera.
22763 So it does not need a prefix. */
22765 case DW_TAG_compile_unit
:
22766 case DW_TAG_partial_unit
:
22767 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22768 if (cu
->language
== language_cplus
22769 && !per_objfile
->per_bfd
->types
.empty ()
22770 && die
->child
!= NULL
22771 && (die
->tag
== DW_TAG_class_type
22772 || die
->tag
== DW_TAG_structure_type
22773 || die
->tag
== DW_TAG_union_type
))
22775 const char *name
= guess_full_die_structure_name (die
, cu
);
22780 case DW_TAG_subprogram
:
22781 /* Nested subroutines in Fortran get a prefix with the name
22782 of the parent's subroutine. */
22783 if (cu
->language
== language_fortran
)
22785 if ((die
->tag
== DW_TAG_subprogram
)
22786 && (dwarf2_name (parent
, cu
) != NULL
))
22787 return dwarf2_name (parent
, cu
);
22789 return determine_prefix (parent
, cu
);
22790 case DW_TAG_enumeration_type
:
22791 parent_type
= read_type_die (parent
, cu
);
22792 if (TYPE_DECLARED_CLASS (parent_type
))
22794 if (parent_type
->name () != NULL
)
22795 return parent_type
->name ();
22798 /* Fall through. */
22800 return determine_prefix (parent
, cu
);
22804 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22805 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22806 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22807 an obconcat, otherwise allocate storage for the result. The CU argument is
22808 used to determine the language and hence, the appropriate separator. */
22810 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22813 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22814 int physname
, struct dwarf2_cu
*cu
)
22816 const char *lead
= "";
22819 if (suffix
== NULL
|| suffix
[0] == '\0'
22820 || prefix
== NULL
|| prefix
[0] == '\0')
22822 else if (cu
->language
== language_d
)
22824 /* For D, the 'main' function could be defined in any module, but it
22825 should never be prefixed. */
22826 if (strcmp (suffix
, "D main") == 0)
22834 else if (cu
->language
== language_fortran
&& physname
)
22836 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22837 DW_AT_MIPS_linkage_name is preferred and used instead. */
22845 if (prefix
== NULL
)
22847 if (suffix
== NULL
)
22854 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22856 strcpy (retval
, lead
);
22857 strcat (retval
, prefix
);
22858 strcat (retval
, sep
);
22859 strcat (retval
, suffix
);
22864 /* We have an obstack. */
22865 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22869 /* Get name of a die, return NULL if not found. */
22871 static const char *
22872 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22873 struct objfile
*objfile
)
22875 if (name
&& cu
->language
== language_cplus
)
22877 gdb::unique_xmalloc_ptr
<char> canon_name
22878 = cp_canonicalize_string (name
);
22880 if (canon_name
!= nullptr)
22881 name
= objfile
->intern (canon_name
.get ());
22887 /* Get name of a die, return NULL if not found.
22888 Anonymous namespaces are converted to their magic string. */
22890 static const char *
22891 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22893 struct attribute
*attr
;
22894 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22896 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22897 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22898 if (attr_name
== nullptr
22899 && die
->tag
!= DW_TAG_namespace
22900 && die
->tag
!= DW_TAG_class_type
22901 && die
->tag
!= DW_TAG_interface_type
22902 && die
->tag
!= DW_TAG_structure_type
22903 && die
->tag
!= DW_TAG_union_type
)
22908 case DW_TAG_compile_unit
:
22909 case DW_TAG_partial_unit
:
22910 /* Compilation units have a DW_AT_name that is a filename, not
22911 a source language identifier. */
22912 case DW_TAG_enumeration_type
:
22913 case DW_TAG_enumerator
:
22914 /* These tags always have simple identifiers already; no need
22915 to canonicalize them. */
22918 case DW_TAG_namespace
:
22919 if (attr_name
!= nullptr)
22921 return CP_ANONYMOUS_NAMESPACE_STR
;
22923 case DW_TAG_class_type
:
22924 case DW_TAG_interface_type
:
22925 case DW_TAG_structure_type
:
22926 case DW_TAG_union_type
:
22927 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22928 structures or unions. These were of the form "._%d" in GCC 4.1,
22929 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22930 and GCC 4.4. We work around this problem by ignoring these. */
22931 if (attr_name
!= nullptr
22932 && (startswith (attr_name
, "._")
22933 || startswith (attr_name
, "<anonymous")))
22936 /* GCC might emit a nameless typedef that has a linkage name. See
22937 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22938 if (!attr
|| attr_name
== NULL
)
22940 attr
= dw2_linkage_name_attr (die
, cu
);
22941 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22942 if (attr
== NULL
|| attr_name
== NULL
)
22945 /* Avoid demangling attr_name the second time on a second
22946 call for the same DIE. */
22947 if (!attr
->canonical_string_p ())
22949 gdb::unique_xmalloc_ptr
<char> demangled
22950 (gdb_demangle (attr_name
, DMGL_TYPES
));
22951 if (demangled
== nullptr)
22954 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
22955 attr_name
= attr
->as_string ();
22958 /* Strip any leading namespaces/classes, keep only the
22959 base name. DW_AT_name for named DIEs does not
22960 contain the prefixes. */
22961 const char *base
= strrchr (attr_name
, ':');
22962 if (base
&& base
> attr_name
&& base
[-1] == ':')
22973 if (!attr
->canonical_string_p ())
22974 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
22976 return attr
->as_string ();
22979 /* Return the die that this die in an extension of, or NULL if there
22980 is none. *EXT_CU is the CU containing DIE on input, and the CU
22981 containing the return value on output. */
22983 static struct die_info
*
22984 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22986 struct attribute
*attr
;
22988 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22992 return follow_die_ref (die
, attr
, ext_cu
);
22996 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23000 print_spaces (indent
, f
);
23001 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23002 dwarf_tag_name (die
->tag
), die
->abbrev
,
23003 sect_offset_str (die
->sect_off
));
23005 if (die
->parent
!= NULL
)
23007 print_spaces (indent
, f
);
23008 fprintf_unfiltered (f
, " parent at offset: %s\n",
23009 sect_offset_str (die
->parent
->sect_off
));
23012 print_spaces (indent
, f
);
23013 fprintf_unfiltered (f
, " has children: %s\n",
23014 dwarf_bool_name (die
->child
!= NULL
));
23016 print_spaces (indent
, f
);
23017 fprintf_unfiltered (f
, " attributes:\n");
23019 for (i
= 0; i
< die
->num_attrs
; ++i
)
23021 print_spaces (indent
, f
);
23022 fprintf_unfiltered (f
, " %s (%s) ",
23023 dwarf_attr_name (die
->attrs
[i
].name
),
23024 dwarf_form_name (die
->attrs
[i
].form
));
23026 switch (die
->attrs
[i
].form
)
23029 case DW_FORM_addrx
:
23030 case DW_FORM_GNU_addr_index
:
23031 fprintf_unfiltered (f
, "address: ");
23032 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
23034 case DW_FORM_block2
:
23035 case DW_FORM_block4
:
23036 case DW_FORM_block
:
23037 case DW_FORM_block1
:
23038 fprintf_unfiltered (f
, "block: size %s",
23039 pulongest (die
->attrs
[i
].as_block ()->size
));
23041 case DW_FORM_exprloc
:
23042 fprintf_unfiltered (f
, "expression: size %s",
23043 pulongest (die
->attrs
[i
].as_block ()->size
));
23045 case DW_FORM_data16
:
23046 fprintf_unfiltered (f
, "constant of 16 bytes");
23048 case DW_FORM_ref_addr
:
23049 fprintf_unfiltered (f
, "ref address: ");
23050 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23052 case DW_FORM_GNU_ref_alt
:
23053 fprintf_unfiltered (f
, "alt ref address: ");
23054 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23060 case DW_FORM_ref_udata
:
23061 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23062 (long) (die
->attrs
[i
].as_unsigned ()));
23064 case DW_FORM_data1
:
23065 case DW_FORM_data2
:
23066 case DW_FORM_data4
:
23067 case DW_FORM_data8
:
23068 case DW_FORM_udata
:
23069 fprintf_unfiltered (f
, "constant: %s",
23070 pulongest (die
->attrs
[i
].as_unsigned ()));
23072 case DW_FORM_sec_offset
:
23073 fprintf_unfiltered (f
, "section offset: %s",
23074 pulongest (die
->attrs
[i
].as_unsigned ()));
23076 case DW_FORM_ref_sig8
:
23077 fprintf_unfiltered (f
, "signature: %s",
23078 hex_string (die
->attrs
[i
].as_signature ()));
23080 case DW_FORM_string
:
23082 case DW_FORM_line_strp
:
23084 case DW_FORM_GNU_str_index
:
23085 case DW_FORM_GNU_strp_alt
:
23086 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23087 die
->attrs
[i
].as_string ()
23088 ? die
->attrs
[i
].as_string () : "",
23089 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23092 if (die
->attrs
[i
].as_boolean ())
23093 fprintf_unfiltered (f
, "flag: TRUE");
23095 fprintf_unfiltered (f
, "flag: FALSE");
23097 case DW_FORM_flag_present
:
23098 fprintf_unfiltered (f
, "flag: TRUE");
23100 case DW_FORM_indirect
:
23101 /* The reader will have reduced the indirect form to
23102 the "base form" so this form should not occur. */
23103 fprintf_unfiltered (f
,
23104 "unexpected attribute form: DW_FORM_indirect");
23106 case DW_FORM_sdata
:
23107 case DW_FORM_implicit_const
:
23108 fprintf_unfiltered (f
, "constant: %s",
23109 plongest (die
->attrs
[i
].as_signed ()));
23112 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23113 die
->attrs
[i
].form
);
23116 fprintf_unfiltered (f
, "\n");
23121 dump_die_for_error (struct die_info
*die
)
23123 dump_die_shallow (gdb_stderr
, 0, die
);
23127 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23129 int indent
= level
* 4;
23131 gdb_assert (die
!= NULL
);
23133 if (level
>= max_level
)
23136 dump_die_shallow (f
, indent
, die
);
23138 if (die
->child
!= NULL
)
23140 print_spaces (indent
, f
);
23141 fprintf_unfiltered (f
, " Children:");
23142 if (level
+ 1 < max_level
)
23144 fprintf_unfiltered (f
, "\n");
23145 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23149 fprintf_unfiltered (f
,
23150 " [not printed, max nesting level reached]\n");
23154 if (die
->sibling
!= NULL
&& level
> 0)
23156 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23160 /* This is called from the pdie macro in gdbinit.in.
23161 It's not static so gcc will keep a copy callable from gdb. */
23164 dump_die (struct die_info
*die
, int max_level
)
23166 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23170 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23174 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23175 to_underlying (die
->sect_off
),
23181 /* Follow reference or signature attribute ATTR of SRC_DIE.
23182 On entry *REF_CU is the CU of SRC_DIE.
23183 On exit *REF_CU is the CU of the result. */
23185 static struct die_info
*
23186 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23187 struct dwarf2_cu
**ref_cu
)
23189 struct die_info
*die
;
23191 if (attr
->form_is_ref ())
23192 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23193 else if (attr
->form
== DW_FORM_ref_sig8
)
23194 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23197 dump_die_for_error (src_die
);
23198 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23199 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23205 /* Follow reference OFFSET.
23206 On entry *REF_CU is the CU of the source die referencing OFFSET.
23207 On exit *REF_CU is the CU of the result.
23208 Returns NULL if OFFSET is invalid. */
23210 static struct die_info
*
23211 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23212 struct dwarf2_cu
**ref_cu
)
23214 struct die_info temp_die
;
23215 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23216 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23218 gdb_assert (cu
->per_cu
!= NULL
);
23222 if (cu
->per_cu
->is_debug_types
)
23224 /* .debug_types CUs cannot reference anything outside their CU.
23225 If they need to, they have to reference a signatured type via
23226 DW_FORM_ref_sig8. */
23227 if (!cu
->header
.offset_in_cu_p (sect_off
))
23230 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23231 || !cu
->header
.offset_in_cu_p (sect_off
))
23233 struct dwarf2_per_cu_data
*per_cu
;
23235 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23238 /* If necessary, add it to the queue and load its DIEs. */
23239 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
23240 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23241 false, cu
->language
);
23243 target_cu
= per_objfile
->get_cu (per_cu
);
23245 else if (cu
->dies
== NULL
)
23247 /* We're loading full DIEs during partial symbol reading. */
23248 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23249 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23253 *ref_cu
= target_cu
;
23254 temp_die
.sect_off
= sect_off
;
23256 if (target_cu
!= cu
)
23257 target_cu
->ancestor
= cu
;
23259 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23261 to_underlying (sect_off
));
23264 /* Follow reference attribute ATTR of SRC_DIE.
23265 On entry *REF_CU is the CU of SRC_DIE.
23266 On exit *REF_CU is the CU of the result. */
23268 static struct die_info
*
23269 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23270 struct dwarf2_cu
**ref_cu
)
23272 sect_offset sect_off
= attr
->get_ref_die_offset ();
23273 struct dwarf2_cu
*cu
= *ref_cu
;
23274 struct die_info
*die
;
23276 die
= follow_die_offset (sect_off
,
23277 (attr
->form
== DW_FORM_GNU_ref_alt
23278 || cu
->per_cu
->is_dwz
),
23281 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23282 "at %s [in module %s]"),
23283 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23284 objfile_name (cu
->per_objfile
->objfile
));
23291 struct dwarf2_locexpr_baton
23292 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23293 dwarf2_per_cu_data
*per_cu
,
23294 dwarf2_per_objfile
*per_objfile
,
23295 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23296 bool resolve_abstract_p
)
23298 struct die_info
*die
;
23299 struct attribute
*attr
;
23300 struct dwarf2_locexpr_baton retval
;
23301 struct objfile
*objfile
= per_objfile
->objfile
;
23303 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23305 cu
= load_cu (per_cu
, per_objfile
, false);
23309 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23310 Instead just throw an error, not much else we can do. */
23311 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23312 sect_offset_str (sect_off
), objfile_name (objfile
));
23315 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23317 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23318 sect_offset_str (sect_off
), objfile_name (objfile
));
23320 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23321 if (!attr
&& resolve_abstract_p
23322 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23323 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23325 CORE_ADDR pc
= get_frame_pc ();
23326 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23327 struct gdbarch
*gdbarch
= objfile
->arch ();
23329 for (const auto &cand_off
23330 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23332 struct dwarf2_cu
*cand_cu
= cu
;
23333 struct die_info
*cand
23334 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23337 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23340 CORE_ADDR pc_low
, pc_high
;
23341 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23342 if (pc_low
== ((CORE_ADDR
) -1))
23344 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23345 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23346 if (!(pc_low
<= pc
&& pc
< pc_high
))
23350 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23357 /* DWARF: "If there is no such attribute, then there is no effect.".
23358 DATA is ignored if SIZE is 0. */
23360 retval
.data
= NULL
;
23363 else if (attr
->form_is_section_offset ())
23365 struct dwarf2_loclist_baton loclist_baton
;
23366 CORE_ADDR pc
= get_frame_pc ();
23369 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23371 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23373 retval
.size
= size
;
23377 if (!attr
->form_is_block ())
23378 error (_("Dwarf Error: DIE at %s referenced in module %s "
23379 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23380 sect_offset_str (sect_off
), objfile_name (objfile
));
23382 struct dwarf_block
*block
= attr
->as_block ();
23383 retval
.data
= block
->data
;
23384 retval
.size
= block
->size
;
23386 retval
.per_objfile
= per_objfile
;
23387 retval
.per_cu
= cu
->per_cu
;
23389 per_objfile
->age_comp_units ();
23396 struct dwarf2_locexpr_baton
23397 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23398 dwarf2_per_cu_data
*per_cu
,
23399 dwarf2_per_objfile
*per_objfile
,
23400 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23402 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23404 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23408 /* Write a constant of a given type as target-ordered bytes into
23411 static const gdb_byte
*
23412 write_constant_as_bytes (struct obstack
*obstack
,
23413 enum bfd_endian byte_order
,
23420 *len
= TYPE_LENGTH (type
);
23421 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23422 store_unsigned_integer (result
, *len
, byte_order
, value
);
23430 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23431 dwarf2_per_cu_data
*per_cu
,
23432 dwarf2_per_objfile
*per_objfile
,
23436 struct die_info
*die
;
23437 struct attribute
*attr
;
23438 const gdb_byte
*result
= NULL
;
23441 enum bfd_endian byte_order
;
23442 struct objfile
*objfile
= per_objfile
->objfile
;
23444 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23446 cu
= load_cu (per_cu
, per_objfile
, false);
23450 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23451 Instead just throw an error, not much else we can do. */
23452 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23453 sect_offset_str (sect_off
), objfile_name (objfile
));
23456 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23458 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23459 sect_offset_str (sect_off
), objfile_name (objfile
));
23461 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23465 byte_order
= (bfd_big_endian (objfile
->obfd
)
23466 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23468 switch (attr
->form
)
23471 case DW_FORM_addrx
:
23472 case DW_FORM_GNU_addr_index
:
23476 *len
= cu
->header
.addr_size
;
23477 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23478 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23482 case DW_FORM_string
:
23485 case DW_FORM_GNU_str_index
:
23486 case DW_FORM_GNU_strp_alt
:
23487 /* The string is already allocated on the objfile obstack, point
23490 const char *attr_name
= attr
->as_string ();
23491 result
= (const gdb_byte
*) attr_name
;
23492 *len
= strlen (attr_name
);
23495 case DW_FORM_block1
:
23496 case DW_FORM_block2
:
23497 case DW_FORM_block4
:
23498 case DW_FORM_block
:
23499 case DW_FORM_exprloc
:
23500 case DW_FORM_data16
:
23502 struct dwarf_block
*block
= attr
->as_block ();
23503 result
= block
->data
;
23504 *len
= block
->size
;
23508 /* The DW_AT_const_value attributes are supposed to carry the
23509 symbol's value "represented as it would be on the target
23510 architecture." By the time we get here, it's already been
23511 converted to host endianness, so we just need to sign- or
23512 zero-extend it as appropriate. */
23513 case DW_FORM_data1
:
23514 type
= die_type (die
, cu
);
23515 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23516 if (result
== NULL
)
23517 result
= write_constant_as_bytes (obstack
, byte_order
,
23520 case DW_FORM_data2
:
23521 type
= die_type (die
, cu
);
23522 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23523 if (result
== NULL
)
23524 result
= write_constant_as_bytes (obstack
, byte_order
,
23527 case DW_FORM_data4
:
23528 type
= die_type (die
, cu
);
23529 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23530 if (result
== NULL
)
23531 result
= write_constant_as_bytes (obstack
, byte_order
,
23534 case DW_FORM_data8
:
23535 type
= die_type (die
, cu
);
23536 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23537 if (result
== NULL
)
23538 result
= write_constant_as_bytes (obstack
, byte_order
,
23542 case DW_FORM_sdata
:
23543 case DW_FORM_implicit_const
:
23544 type
= die_type (die
, cu
);
23545 result
= write_constant_as_bytes (obstack
, byte_order
,
23546 type
, attr
->as_signed (), len
);
23549 case DW_FORM_udata
:
23550 type
= die_type (die
, cu
);
23551 result
= write_constant_as_bytes (obstack
, byte_order
,
23552 type
, attr
->as_unsigned (), len
);
23556 complaint (_("unsupported const value attribute form: '%s'"),
23557 dwarf_form_name (attr
->form
));
23567 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23568 dwarf2_per_cu_data
*per_cu
,
23569 dwarf2_per_objfile
*per_objfile
)
23571 struct die_info
*die
;
23573 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23575 cu
= load_cu (per_cu
, per_objfile
, false);
23580 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23584 return die_type (die
, cu
);
23590 dwarf2_get_die_type (cu_offset die_offset
,
23591 dwarf2_per_cu_data
*per_cu
,
23592 dwarf2_per_objfile
*per_objfile
)
23594 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23595 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23598 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23599 On entry *REF_CU is the CU of SRC_DIE.
23600 On exit *REF_CU is the CU of the result.
23601 Returns NULL if the referenced DIE isn't found. */
23603 static struct die_info
*
23604 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23605 struct dwarf2_cu
**ref_cu
)
23607 struct die_info temp_die
;
23608 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23609 struct die_info
*die
;
23610 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23613 /* While it might be nice to assert sig_type->type == NULL here,
23614 we can get here for DW_AT_imported_declaration where we need
23615 the DIE not the type. */
23617 /* If necessary, add it to the queue and load its DIEs. */
23619 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
23621 read_signatured_type (sig_type
, per_objfile
);
23623 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
23624 gdb_assert (sig_cu
!= NULL
);
23625 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23626 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23627 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23628 to_underlying (temp_die
.sect_off
));
23631 /* For .gdb_index version 7 keep track of included TUs.
23632 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23633 if (per_objfile
->per_bfd
->index_table
!= NULL
23634 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23636 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23641 sig_cu
->ancestor
= cu
;
23649 /* Follow signatured type referenced by ATTR in SRC_DIE.
23650 On entry *REF_CU is the CU of SRC_DIE.
23651 On exit *REF_CU is the CU of the result.
23652 The result is the DIE of the type.
23653 If the referenced type cannot be found an error is thrown. */
23655 static struct die_info
*
23656 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23657 struct dwarf2_cu
**ref_cu
)
23659 ULONGEST signature
= attr
->as_signature ();
23660 struct signatured_type
*sig_type
;
23661 struct die_info
*die
;
23663 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23665 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23666 /* sig_type will be NULL if the signatured type is missing from
23668 if (sig_type
== NULL
)
23670 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23671 " from DIE at %s [in module %s]"),
23672 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23673 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23676 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23679 dump_die_for_error (src_die
);
23680 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23681 " from DIE at %s [in module %s]"),
23682 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23683 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23689 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23690 reading in and processing the type unit if necessary. */
23692 static struct type
*
23693 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23694 struct dwarf2_cu
*cu
)
23696 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23697 struct signatured_type
*sig_type
;
23698 struct dwarf2_cu
*type_cu
;
23699 struct die_info
*type_die
;
23702 sig_type
= lookup_signatured_type (cu
, signature
);
23703 /* sig_type will be NULL if the signatured type is missing from
23705 if (sig_type
== NULL
)
23707 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23708 " from DIE at %s [in module %s]"),
23709 hex_string (signature
), sect_offset_str (die
->sect_off
),
23710 objfile_name (per_objfile
->objfile
));
23711 return build_error_marker_type (cu
, die
);
23714 /* If we already know the type we're done. */
23715 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23716 if (type
!= nullptr)
23720 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23721 if (type_die
!= NULL
)
23723 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23724 is created. This is important, for example, because for c++ classes
23725 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23726 type
= read_type_die (type_die
, type_cu
);
23729 complaint (_("Dwarf Error: Cannot build signatured type %s"
23730 " referenced from DIE at %s [in module %s]"),
23731 hex_string (signature
), sect_offset_str (die
->sect_off
),
23732 objfile_name (per_objfile
->objfile
));
23733 type
= build_error_marker_type (cu
, die
);
23738 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23739 " from DIE at %s [in module %s]"),
23740 hex_string (signature
), sect_offset_str (die
->sect_off
),
23741 objfile_name (per_objfile
->objfile
));
23742 type
= build_error_marker_type (cu
, die
);
23745 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23750 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23751 reading in and processing the type unit if necessary. */
23753 static struct type
*
23754 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23755 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23757 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23758 if (attr
->form_is_ref ())
23760 struct dwarf2_cu
*type_cu
= cu
;
23761 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23763 return read_type_die (type_die
, type_cu
);
23765 else if (attr
->form
== DW_FORM_ref_sig8
)
23767 return get_signatured_type (die
, attr
->as_signature (), cu
);
23771 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23773 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23774 " at %s [in module %s]"),
23775 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23776 objfile_name (per_objfile
->objfile
));
23777 return build_error_marker_type (cu
, die
);
23781 /* Load the DIEs associated with type unit PER_CU into memory. */
23784 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23785 dwarf2_per_objfile
*per_objfile
)
23787 struct signatured_type
*sig_type
;
23789 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23790 gdb_assert (! per_cu
->type_unit_group_p ());
23792 /* We have the per_cu, but we need the signatured_type.
23793 Fortunately this is an easy translation. */
23794 gdb_assert (per_cu
->is_debug_types
);
23795 sig_type
= (struct signatured_type
*) per_cu
;
23797 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23799 read_signatured_type (sig_type
, per_objfile
);
23801 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23804 /* Read in a signatured type and build its CU and DIEs.
23805 If the type is a stub for the real type in a DWO file,
23806 read in the real type from the DWO file as well. */
23809 read_signatured_type (signatured_type
*sig_type
,
23810 dwarf2_per_objfile
*per_objfile
)
23812 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23814 gdb_assert (per_cu
->is_debug_types
);
23815 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23817 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
23819 if (!reader
.dummy_p
)
23821 struct dwarf2_cu
*cu
= reader
.cu
;
23822 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23824 gdb_assert (cu
->die_hash
== NULL
);
23826 htab_create_alloc_ex (cu
->header
.length
/ 12,
23830 &cu
->comp_unit_obstack
,
23831 hashtab_obstack_allocate
,
23832 dummy_obstack_deallocate
);
23834 if (reader
.comp_unit_die
->has_children
)
23835 reader
.comp_unit_die
->child
23836 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23837 reader
.comp_unit_die
);
23838 cu
->dies
= reader
.comp_unit_die
;
23839 /* comp_unit_die is not stored in die_hash, no need. */
23841 /* We try not to read any attributes in this function, because
23842 not all CUs needed for references have been loaded yet, and
23843 symbol table processing isn't initialized. But we have to
23844 set the CU language, or we won't be able to build types
23845 correctly. Similarly, if we do not read the producer, we can
23846 not apply producer-specific interpretation. */
23847 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23852 sig_type
->per_cu
.tu_read
= 1;
23855 /* Decode simple location descriptions.
23856 Given a pointer to a dwarf block that defines a location, compute
23857 the location and return the value. If COMPUTED is non-null, it is
23858 set to true to indicate that decoding was successful, and false
23859 otherwise. If COMPUTED is null, then this function may emit a
23863 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23865 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23867 size_t size
= blk
->size
;
23868 const gdb_byte
*data
= blk
->data
;
23869 CORE_ADDR stack
[64];
23871 unsigned int bytes_read
, unsnd
;
23874 if (computed
!= nullptr)
23880 stack
[++stacki
] = 0;
23919 stack
[++stacki
] = op
- DW_OP_lit0
;
23954 stack
[++stacki
] = op
- DW_OP_reg0
;
23957 if (computed
== nullptr)
23958 dwarf2_complex_location_expr_complaint ();
23965 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23967 stack
[++stacki
] = unsnd
;
23970 if (computed
== nullptr)
23971 dwarf2_complex_location_expr_complaint ();
23978 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23983 case DW_OP_const1u
:
23984 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23988 case DW_OP_const1s
:
23989 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23993 case DW_OP_const2u
:
23994 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23998 case DW_OP_const2s
:
23999 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24003 case DW_OP_const4u
:
24004 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24008 case DW_OP_const4s
:
24009 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24013 case DW_OP_const8u
:
24014 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24019 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24025 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24030 stack
[stacki
+ 1] = stack
[stacki
];
24035 stack
[stacki
- 1] += stack
[stacki
];
24039 case DW_OP_plus_uconst
:
24040 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24046 stack
[stacki
- 1] -= stack
[stacki
];
24051 /* If we're not the last op, then we definitely can't encode
24052 this using GDB's address_class enum. This is valid for partial
24053 global symbols, although the variable's address will be bogus
24057 if (computed
== nullptr)
24058 dwarf2_complex_location_expr_complaint ();
24064 case DW_OP_GNU_push_tls_address
:
24065 case DW_OP_form_tls_address
:
24066 /* The top of the stack has the offset from the beginning
24067 of the thread control block at which the variable is located. */
24068 /* Nothing should follow this operator, so the top of stack would
24070 /* This is valid for partial global symbols, but the variable's
24071 address will be bogus in the psymtab. Make it always at least
24072 non-zero to not look as a variable garbage collected by linker
24073 which have DW_OP_addr 0. */
24076 if (computed
== nullptr)
24077 dwarf2_complex_location_expr_complaint ();
24084 case DW_OP_GNU_uninit
:
24085 if (computed
!= nullptr)
24090 case DW_OP_GNU_addr_index
:
24091 case DW_OP_GNU_const_index
:
24092 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24098 if (computed
== nullptr)
24100 const char *name
= get_DW_OP_name (op
);
24103 complaint (_("unsupported stack op: '%s'"),
24106 complaint (_("unsupported stack op: '%02x'"),
24110 return (stack
[stacki
]);
24113 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24114 outside of the allocated space. Also enforce minimum>0. */
24115 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24117 if (computed
== nullptr)
24118 complaint (_("location description stack overflow"));
24124 if (computed
== nullptr)
24125 complaint (_("location description stack underflow"));
24130 if (computed
!= nullptr)
24132 return (stack
[stacki
]);
24135 /* memory allocation interface */
24137 static struct dwarf_block
*
24138 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24140 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24143 static struct die_info
*
24144 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24146 struct die_info
*die
;
24147 size_t size
= sizeof (struct die_info
);
24150 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24152 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24153 memset (die
, 0, sizeof (struct die_info
));
24159 /* Macro support. */
24161 /* An overload of dwarf_decode_macros that finds the correct section
24162 and ensures it is read in before calling the other overload. */
24165 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24166 int section_is_gnu
)
24168 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24169 struct objfile
*objfile
= per_objfile
->objfile
;
24170 const struct line_header
*lh
= cu
->line_header
;
24171 unsigned int offset_size
= cu
->header
.offset_size
;
24172 struct dwarf2_section_info
*section
;
24173 const char *section_name
;
24175 if (cu
->dwo_unit
!= nullptr)
24177 if (section_is_gnu
)
24179 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24180 section_name
= ".debug_macro.dwo";
24184 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24185 section_name
= ".debug_macinfo.dwo";
24190 if (section_is_gnu
)
24192 section
= &per_objfile
->per_bfd
->macro
;
24193 section_name
= ".debug_macro";
24197 section
= &per_objfile
->per_bfd
->macinfo
;
24198 section_name
= ".debug_macinfo";
24202 section
->read (objfile
);
24203 if (section
->buffer
== nullptr)
24205 complaint (_("missing %s section"), section_name
);
24209 buildsym_compunit
*builder
= cu
->get_builder ();
24211 struct dwarf2_section_info
*str_offsets_section
;
24212 struct dwarf2_section_info
*str_section
;
24213 ULONGEST str_offsets_base
;
24215 if (cu
->dwo_unit
!= nullptr)
24217 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24218 ->sections
.str_offsets
;
24219 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24220 str_offsets_base
= cu
->header
.addr_size
;
24224 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24225 str_section
= &per_objfile
->per_bfd
->str
;
24226 str_offsets_base
= *cu
->str_offsets_base
;
24229 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24230 offset_size
, offset
, str_section
, str_offsets_section
,
24231 str_offsets_base
, section_is_gnu
);
24234 /* Return the .debug_loc section to use for CU.
24235 For DWO files use .debug_loc.dwo. */
24237 static struct dwarf2_section_info
*
24238 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24240 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24244 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24246 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24248 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24249 : &per_objfile
->per_bfd
->loc
);
24252 /* Return the .debug_rnglists section to use for CU. */
24253 static struct dwarf2_section_info
*
24254 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24256 if (cu
->header
.version
< 5)
24257 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24258 cu
->header
.version
);
24259 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24261 /* Make sure we read the .debug_rnglists section from the file that
24262 contains the DW_AT_ranges attribute we are reading. Normally that
24263 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24264 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24266 if (cu
->dwo_unit
!= nullptr
24267 && tag
!= DW_TAG_compile_unit
24268 && tag
!= DW_TAG_skeleton_unit
)
24270 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24272 if (sections
->rnglists
.size
> 0)
24273 return §ions
->rnglists
;
24275 error (_(".debug_rnglists section is missing from .dwo file."));
24277 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24280 /* A helper function that fills in a dwarf2_loclist_baton. */
24283 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24284 struct dwarf2_loclist_baton
*baton
,
24285 const struct attribute
*attr
)
24287 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24288 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24290 section
->read (per_objfile
->objfile
);
24292 baton
->per_objfile
= per_objfile
;
24293 baton
->per_cu
= cu
->per_cu
;
24294 gdb_assert (baton
->per_cu
);
24295 /* We don't know how long the location list is, but make sure we
24296 don't run off the edge of the section. */
24297 baton
->size
= section
->size
- attr
->as_unsigned ();
24298 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24299 if (cu
->base_address
.has_value ())
24300 baton
->base_address
= *cu
->base_address
;
24302 baton
->base_address
= 0;
24303 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24307 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24308 struct dwarf2_cu
*cu
, int is_block
)
24310 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24311 struct objfile
*objfile
= per_objfile
->objfile
;
24312 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24314 if (attr
->form_is_section_offset ()
24315 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24316 the section. If so, fall through to the complaint in the
24318 && attr
->as_unsigned () < section
->get_size (objfile
))
24320 struct dwarf2_loclist_baton
*baton
;
24322 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24324 fill_in_loclist_baton (cu
, baton
, attr
);
24326 if (!cu
->base_address
.has_value ())
24327 complaint (_("Location list used without "
24328 "specifying the CU base address."));
24330 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24331 ? dwarf2_loclist_block_index
24332 : dwarf2_loclist_index
);
24333 SYMBOL_LOCATION_BATON (sym
) = baton
;
24337 struct dwarf2_locexpr_baton
*baton
;
24339 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24340 baton
->per_objfile
= per_objfile
;
24341 baton
->per_cu
= cu
->per_cu
;
24342 gdb_assert (baton
->per_cu
);
24344 if (attr
->form_is_block ())
24346 /* Note that we're just copying the block's data pointer
24347 here, not the actual data. We're still pointing into the
24348 info_buffer for SYM's objfile; right now we never release
24349 that buffer, but when we do clean up properly this may
24351 struct dwarf_block
*block
= attr
->as_block ();
24352 baton
->size
= block
->size
;
24353 baton
->data
= block
->data
;
24357 dwarf2_invalid_attrib_class_complaint ("location description",
24358 sym
->natural_name ());
24362 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24363 ? dwarf2_locexpr_block_index
24364 : dwarf2_locexpr_index
);
24365 SYMBOL_LOCATION_BATON (sym
) = baton
;
24371 const comp_unit_head
*
24372 dwarf2_per_cu_data::get_header () const
24374 if (!m_header_read_in
)
24376 const gdb_byte
*info_ptr
24377 = this->section
->buffer
+ to_underlying (this->sect_off
);
24379 memset (&m_header
, 0, sizeof (m_header
));
24381 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24382 rcuh_kind::COMPILE
);
24391 dwarf2_per_cu_data::addr_size () const
24393 return this->get_header ()->addr_size
;
24399 dwarf2_per_cu_data::offset_size () const
24401 return this->get_header ()->offset_size
;
24407 dwarf2_per_cu_data::ref_addr_size () const
24409 const comp_unit_head
*header
= this->get_header ();
24411 if (header
->version
== 2)
24412 return header
->addr_size
;
24414 return header
->offset_size
;
24420 dwarf2_cu::addr_type () const
24422 struct objfile
*objfile
= this->per_objfile
->objfile
;
24423 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24424 struct type
*addr_type
= lookup_pointer_type (void_type
);
24425 int addr_size
= this->per_cu
->addr_size ();
24427 if (TYPE_LENGTH (addr_type
) == addr_size
)
24430 addr_type
= addr_sized_int_type (addr_type
->is_unsigned ());
24434 /* A helper function for dwarf2_find_containing_comp_unit that returns
24435 the index of the result, and that searches a vector. It will
24436 return a result even if the offset in question does not actually
24437 occur in any CU. This is separate so that it can be unit
24441 dwarf2_find_containing_comp_unit
24442 (sect_offset sect_off
,
24443 unsigned int offset_in_dwz
,
24444 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
24449 high
= all_comp_units
.size () - 1;
24452 struct dwarf2_per_cu_data
*mid_cu
;
24453 int mid
= low
+ (high
- low
) / 2;
24455 mid_cu
= all_comp_units
[mid
];
24456 if (mid_cu
->is_dwz
> offset_in_dwz
24457 || (mid_cu
->is_dwz
== offset_in_dwz
24458 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24463 gdb_assert (low
== high
);
24467 /* Locate the .debug_info compilation unit from CU's objfile which contains
24468 the DIE at OFFSET. Raises an error on failure. */
24470 static struct dwarf2_per_cu_data
*
24471 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24472 unsigned int offset_in_dwz
,
24473 dwarf2_per_objfile
*per_objfile
)
24475 int low
= dwarf2_find_containing_comp_unit
24476 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24477 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
24479 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24481 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24482 error (_("Dwarf Error: could not find partial DIE containing "
24483 "offset %s [in module %s]"),
24484 sect_offset_str (sect_off
),
24485 bfd_get_filename (per_objfile
->objfile
->obfd
));
24487 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24489 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
24493 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24494 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24495 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24496 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24503 namespace selftests
{
24504 namespace find_containing_comp_unit
{
24509 struct dwarf2_per_cu_data one
{};
24510 struct dwarf2_per_cu_data two
{};
24511 struct dwarf2_per_cu_data three
{};
24512 struct dwarf2_per_cu_data four
{};
24515 two
.sect_off
= sect_offset (one
.length
);
24520 four
.sect_off
= sect_offset (three
.length
);
24524 std::vector
<dwarf2_per_cu_data
*> units
;
24525 units
.push_back (&one
);
24526 units
.push_back (&two
);
24527 units
.push_back (&three
);
24528 units
.push_back (&four
);
24532 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24533 SELF_CHECK (units
[result
] == &one
);
24534 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24535 SELF_CHECK (units
[result
] == &one
);
24536 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24537 SELF_CHECK (units
[result
] == &two
);
24539 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24540 SELF_CHECK (units
[result
] == &three
);
24541 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24542 SELF_CHECK (units
[result
] == &three
);
24543 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24544 SELF_CHECK (units
[result
] == &four
);
24550 #endif /* GDB_SELF_TEST */
24552 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
24554 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
24555 dwarf2_per_objfile
*per_objfile
)
24557 per_objfile (per_objfile
),
24559 has_loclist (false),
24560 checked_producer (false),
24561 producer_is_gxx_lt_4_6 (false),
24562 producer_is_gcc_lt_4_3 (false),
24563 producer_is_icc (false),
24564 producer_is_icc_lt_14 (false),
24565 producer_is_codewarrior (false),
24566 processing_has_namespace_info (false)
24570 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24573 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24574 enum language pretend_language
)
24576 struct attribute
*attr
;
24578 /* Set the language we're debugging. */
24579 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24580 if (attr
!= nullptr)
24581 set_cu_language (attr
->constant_value (0), cu
);
24584 cu
->language
= pretend_language
;
24585 cu
->language_defn
= language_def (cu
->language
);
24588 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24594 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24596 auto it
= m_dwarf2_cus
.find (per_cu
);
24597 if (it
== m_dwarf2_cus
.end ())
24606 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24608 gdb_assert (this->get_cu (per_cu
) == nullptr);
24610 m_dwarf2_cus
[per_cu
] = cu
;
24616 dwarf2_per_objfile::age_comp_units ()
24618 /* Start by clearing all marks. */
24619 for (auto pair
: m_dwarf2_cus
)
24620 pair
.second
->mark
= false;
24622 /* Traverse all CUs, mark them and their dependencies if used recently
24624 for (auto pair
: m_dwarf2_cus
)
24626 dwarf2_cu
*cu
= pair
.second
;
24629 if (cu
->last_used
<= dwarf_max_cache_age
)
24633 /* Delete all CUs still not marked. */
24634 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24636 dwarf2_cu
*cu
= it
->second
;
24641 it
= m_dwarf2_cus
.erase (it
);
24651 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24653 auto it
= m_dwarf2_cus
.find (per_cu
);
24654 if (it
== m_dwarf2_cus
.end ())
24659 m_dwarf2_cus
.erase (it
);
24662 dwarf2_per_objfile::~dwarf2_per_objfile ()
24667 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24668 We store these in a hash table separate from the DIEs, and preserve them
24669 when the DIEs are flushed out of cache.
24671 The CU "per_cu" pointer is needed because offset alone is not enough to
24672 uniquely identify the type. A file may have multiple .debug_types sections,
24673 or the type may come from a DWO file. Furthermore, while it's more logical
24674 to use per_cu->section+offset, with Fission the section with the data is in
24675 the DWO file but we don't know that section at the point we need it.
24676 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24677 because we can enter the lookup routine, get_die_type_at_offset, from
24678 outside this file, and thus won't necessarily have PER_CU->cu.
24679 Fortunately, PER_CU is stable for the life of the objfile. */
24681 struct dwarf2_per_cu_offset_and_type
24683 const struct dwarf2_per_cu_data
*per_cu
;
24684 sect_offset sect_off
;
24688 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24691 per_cu_offset_and_type_hash (const void *item
)
24693 const struct dwarf2_per_cu_offset_and_type
*ofs
24694 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24696 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24699 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24702 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24704 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24705 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24706 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24707 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24709 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24710 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24713 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24714 table if necessary. For convenience, return TYPE.
24716 The DIEs reading must have careful ordering to:
24717 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24718 reading current DIE.
24719 * Not trying to dereference contents of still incompletely read in types
24720 while reading in other DIEs.
24721 * Enable referencing still incompletely read in types just by a pointer to
24722 the type without accessing its fields.
24724 Therefore caller should follow these rules:
24725 * Try to fetch any prerequisite types we may need to build this DIE type
24726 before building the type and calling set_die_type.
24727 * After building type call set_die_type for current DIE as soon as
24728 possible before fetching more types to complete the current type.
24729 * Make the type as complete as possible before fetching more types. */
24731 static struct type
*
24732 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
24733 bool skip_data_location
)
24735 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24736 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24737 struct objfile
*objfile
= per_objfile
->objfile
;
24738 struct attribute
*attr
;
24739 struct dynamic_prop prop
;
24741 /* For Ada types, make sure that the gnat-specific data is always
24742 initialized (if not already set). There are a few types where
24743 we should not be doing so, because the type-specific area is
24744 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24745 where the type-specific area is used to store the floatformat).
24746 But this is not a problem, because the gnat-specific information
24747 is actually not needed for these types. */
24748 if (need_gnat_info (cu
)
24749 && type
->code () != TYPE_CODE_FUNC
24750 && type
->code () != TYPE_CODE_FLT
24751 && type
->code () != TYPE_CODE_METHODPTR
24752 && type
->code () != TYPE_CODE_MEMBERPTR
24753 && type
->code () != TYPE_CODE_METHOD
24754 && !HAVE_GNAT_AUX_INFO (type
))
24755 INIT_GNAT_SPECIFIC (type
);
24757 /* Read DW_AT_allocated and set in type. */
24758 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24761 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24762 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24763 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24766 /* Read DW_AT_associated and set in type. */
24767 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24770 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24771 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24772 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24775 /* Read DW_AT_data_location and set in type. */
24776 if (!skip_data_location
)
24778 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24779 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24780 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24783 if (per_objfile
->die_type_hash
== NULL
)
24784 per_objfile
->die_type_hash
24785 = htab_up (htab_create_alloc (127,
24786 per_cu_offset_and_type_hash
,
24787 per_cu_offset_and_type_eq
,
24788 NULL
, xcalloc
, xfree
));
24790 ofs
.per_cu
= cu
->per_cu
;
24791 ofs
.sect_off
= die
->sect_off
;
24793 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24794 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24796 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24797 sect_offset_str (die
->sect_off
));
24798 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24799 struct dwarf2_per_cu_offset_and_type
);
24804 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24805 or return NULL if the die does not have a saved type. */
24807 static struct type
*
24808 get_die_type_at_offset (sect_offset sect_off
,
24809 dwarf2_per_cu_data
*per_cu
,
24810 dwarf2_per_objfile
*per_objfile
)
24812 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24814 if (per_objfile
->die_type_hash
== NULL
)
24817 ofs
.per_cu
= per_cu
;
24818 ofs
.sect_off
= sect_off
;
24819 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24820 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24827 /* Look up the type for DIE in CU in die_type_hash,
24828 or return NULL if DIE does not have a saved type. */
24830 static struct type
*
24831 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24833 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24836 /* Add a dependence relationship from CU to REF_PER_CU. */
24839 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
24840 struct dwarf2_per_cu_data
*ref_per_cu
)
24844 if (cu
->dependencies
== NULL
)
24846 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
24847 NULL
, &cu
->comp_unit_obstack
,
24848 hashtab_obstack_allocate
,
24849 dummy_obstack_deallocate
);
24851 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
24853 *slot
= ref_per_cu
;
24856 /* Subroutine of dwarf2_mark to pass to htab_traverse.
24857 Set the mark field in every compilation unit in the
24858 cache that we must keep because we are keeping CU.
24860 DATA is the dwarf2_per_objfile object in which to look up CUs. */
24863 dwarf2_mark_helper (void **slot
, void *data
)
24865 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
24866 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
24867 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
24869 /* cu->dependencies references may not yet have been ever read if QUIT aborts
24870 reading of the chain. As such dependencies remain valid it is not much
24871 useful to track and undo them during QUIT cleanups. */
24880 if (cu
->dependencies
!= nullptr)
24881 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
24886 /* Set the mark field in CU and in every other compilation unit in the
24887 cache that we must keep because we are keeping CU. */
24890 dwarf2_mark (struct dwarf2_cu
*cu
)
24897 if (cu
->dependencies
!= nullptr)
24898 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
24901 /* Trivial hash function for partial_die_info: the hash value of a DIE
24902 is its offset in .debug_info for this objfile. */
24905 partial_die_hash (const void *item
)
24907 const struct partial_die_info
*part_die
24908 = (const struct partial_die_info
*) item
;
24910 return to_underlying (part_die
->sect_off
);
24913 /* Trivial comparison function for partial_die_info structures: two DIEs
24914 are equal if they have the same offset. */
24917 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24919 const struct partial_die_info
*part_die_lhs
24920 = (const struct partial_die_info
*) item_lhs
;
24921 const struct partial_die_info
*part_die_rhs
24922 = (const struct partial_die_info
*) item_rhs
;
24924 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24927 struct cmd_list_element
*set_dwarf_cmdlist
;
24928 struct cmd_list_element
*show_dwarf_cmdlist
;
24931 show_check_physname (struct ui_file
*file
, int from_tty
,
24932 struct cmd_list_element
*c
, const char *value
)
24934 fprintf_filtered (file
,
24935 _("Whether to check \"physname\" is %s.\n"),
24939 void _initialize_dwarf2_read ();
24941 _initialize_dwarf2_read ()
24943 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24944 Set DWARF specific variables.\n\
24945 Configure DWARF variables such as the cache size."),
24946 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24947 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24949 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24950 Show DWARF specific variables.\n\
24951 Show DWARF variables such as the cache size."),
24952 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24953 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24955 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24956 &dwarf_max_cache_age
, _("\
24957 Set the upper bound on the age of cached DWARF compilation units."), _("\
24958 Show the upper bound on the age of cached DWARF compilation units."), _("\
24959 A higher limit means that cached compilation units will be stored\n\
24960 in memory longer, and more total memory will be used. Zero disables\n\
24961 caching, which can slow down startup."),
24963 show_dwarf_max_cache_age
,
24964 &set_dwarf_cmdlist
,
24965 &show_dwarf_cmdlist
);
24967 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24968 Set debugging of the DWARF reader."), _("\
24969 Show debugging of the DWARF reader."), _("\
24970 When enabled (non-zero), debugging messages are printed during DWARF\n\
24971 reading and symtab expansion. A value of 1 (one) provides basic\n\
24972 information. A value greater than 1 provides more verbose information."),
24975 &setdebuglist
, &showdebuglist
);
24977 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24978 Set debugging of the DWARF DIE reader."), _("\
24979 Show debugging of the DWARF DIE reader."), _("\
24980 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24981 The value is the maximum depth to print."),
24984 &setdebuglist
, &showdebuglist
);
24986 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24987 Set debugging of the dwarf line reader."), _("\
24988 Show debugging of the dwarf line reader."), _("\
24989 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24990 A value of 1 (one) provides basic information.\n\
24991 A value greater than 1 provides more verbose information."),
24994 &setdebuglist
, &showdebuglist
);
24996 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24997 Set cross-checking of \"physname\" code against demangler."), _("\
24998 Show cross-checking of \"physname\" code against demangler."), _("\
24999 When enabled, GDB's internal \"physname\" code is checked against\n\
25001 NULL
, show_check_physname
,
25002 &setdebuglist
, &showdebuglist
);
25004 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25005 no_class
, &use_deprecated_index_sections
, _("\
25006 Set whether to use deprecated gdb_index sections."), _("\
25007 Show whether to use deprecated gdb_index sections."), _("\
25008 When enabled, deprecated .gdb_index sections are used anyway.\n\
25009 Normally they are ignored either because of a missing feature or\n\
25010 performance issue.\n\
25011 Warning: This option must be enabled before gdb reads the file."),
25014 &setlist
, &showlist
);
25016 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25017 &dwarf2_locexpr_funcs
);
25018 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25019 &dwarf2_loclist_funcs
);
25021 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25022 &dwarf2_block_frame_base_locexpr_funcs
);
25023 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25024 &dwarf2_block_frame_base_loclist_funcs
);
25027 selftests::register_test ("dw2_expand_symtabs_matching",
25028 selftests::dw2_expand_symtabs_matching::run_test
);
25029 selftests::register_test ("dwarf2_find_containing_comp_unit",
25030 selftests::find_containing_comp_unit::run_test
);