1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2018 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 "dwarf2read.h"
33 #include "dwarf-index-common.h"
42 #include "gdb-demangle.h"
43 #include "expression.h"
44 #include "filenames.h" /* for DOSish file names */
47 #include "complaints.h"
49 #include "dwarf2expr.h"
50 #include "dwarf2loc.h"
51 #include "cp-support.h"
57 #include "typeprint.h"
60 #include "completer.h"
65 #include "gdbcore.h" /* for gnutarget */
66 #include "gdb/gdb-index.h"
71 #include "filestuff.h"
73 #include "namespace.h"
74 #include "common/gdb_unlinker.h"
75 #include "common/function-view.h"
76 #include "common/gdb_optional.h"
77 #include "common/underlying.h"
78 #include "common/byte-vector.h"
79 #include "common/hash_enum.h"
80 #include "filename-seen-cache.h"
83 #include <sys/types.h>
85 #include <unordered_set>
86 #include <unordered_map>
90 #include <forward_list>
91 #include "rust-lang.h"
92 #include "common/pathstuff.h"
94 /* When == 1, print basic high level tracing messages.
95 When > 1, be more verbose.
96 This is in contrast to the low level DIE reading of dwarf_die_debug. */
97 static unsigned int dwarf_read_debug
= 0;
99 /* When non-zero, dump DIEs after they are read in. */
100 static unsigned int dwarf_die_debug
= 0;
102 /* When non-zero, dump line number entries as they are read in. */
103 static unsigned int dwarf_line_debug
= 0;
105 /* When non-zero, cross-check physname against demangler. */
106 static int check_physname
= 0;
108 /* When non-zero, do not reject deprecated .gdb_index sections. */
109 static int use_deprecated_index_sections
= 0;
111 static const struct objfile_data
*dwarf2_objfile_data_key
;
113 /* The "aclass" indices for various kinds of computed DWARF symbols. */
115 static int dwarf2_locexpr_index
;
116 static int dwarf2_loclist_index
;
117 static int dwarf2_locexpr_block_index
;
118 static int dwarf2_loclist_block_index
;
120 /* An index into a (C++) symbol name component in a symbol name as
121 recorded in the mapped_index's symbol table. For each C++ symbol
122 in the symbol table, we record one entry for the start of each
123 component in the symbol in a table of name components, and then
124 sort the table, in order to be able to binary search symbol names,
125 ignoring leading namespaces, both completion and regular look up.
126 For example, for symbol "A::B::C", we'll have an entry that points
127 to "A::B::C", another that points to "B::C", and another for "C".
128 Note that function symbols in GDB index have no parameter
129 information, just the function/method names. You can convert a
130 name_component to a "const char *" using the
131 'mapped_index::symbol_name_at(offset_type)' method. */
133 struct name_component
135 /* Offset in the symbol name where the component starts. Stored as
136 a (32-bit) offset instead of a pointer to save memory and improve
137 locality on 64-bit architectures. */
138 offset_type name_offset
;
140 /* The symbol's index in the symbol and constant pool tables of a
145 /* Base class containing bits shared by both .gdb_index and
146 .debug_name indexes. */
148 struct mapped_index_base
150 /* The name_component table (a sorted vector). See name_component's
151 description above. */
152 std::vector
<name_component
> name_components
;
154 /* How NAME_COMPONENTS is sorted. */
155 enum case_sensitivity name_components_casing
;
157 /* Return the number of names in the symbol table. */
158 virtual size_t symbol_name_count () const = 0;
160 /* Get the name of the symbol at IDX in the symbol table. */
161 virtual const char *symbol_name_at (offset_type idx
) const = 0;
163 /* Return whether the name at IDX in the symbol table should be
165 virtual bool symbol_name_slot_invalid (offset_type idx
) const
170 /* Build the symbol name component sorted vector, if we haven't
172 void build_name_components ();
174 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
175 possible matches for LN_NO_PARAMS in the name component
177 std::pair
<std::vector
<name_component
>::const_iterator
,
178 std::vector
<name_component
>::const_iterator
>
179 find_name_components_bounds (const lookup_name_info
&ln_no_params
) const;
181 /* Prevent deleting/destroying via a base class pointer. */
183 ~mapped_index_base() = default;
186 /* A description of the mapped index. The file format is described in
187 a comment by the code that writes the index. */
188 struct mapped_index final
: public mapped_index_base
190 /* A slot/bucket in the symbol table hash. */
191 struct symbol_table_slot
193 const offset_type name
;
194 const offset_type vec
;
197 /* Index data format version. */
200 /* The total length of the buffer. */
203 /* The address table data. */
204 gdb::array_view
<const gdb_byte
> address_table
;
206 /* The symbol table, implemented as a hash table. */
207 gdb::array_view
<symbol_table_slot
> symbol_table
;
209 /* A pointer to the constant pool. */
210 const char *constant_pool
;
212 bool symbol_name_slot_invalid (offset_type idx
) const override
214 const auto &bucket
= this->symbol_table
[idx
];
215 return bucket
.name
== 0 && bucket
.vec
;
218 /* Convenience method to get at the name of the symbol at IDX in the
220 const char *symbol_name_at (offset_type idx
) const override
221 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
223 size_t symbol_name_count () const override
224 { return this->symbol_table
.size (); }
227 /* A description of the mapped .debug_names.
228 Uninitialized map has CU_COUNT 0. */
229 struct mapped_debug_names final
: public mapped_index_base
231 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
232 : dwarf2_per_objfile (dwarf2_per_objfile_
)
235 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
236 bfd_endian dwarf5_byte_order
;
237 bool dwarf5_is_dwarf64
;
238 bool augmentation_is_gdb
;
240 uint32_t cu_count
= 0;
241 uint32_t tu_count
, bucket_count
, name_count
;
242 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
243 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
244 const gdb_byte
*name_table_string_offs_reordered
;
245 const gdb_byte
*name_table_entry_offs_reordered
;
246 const gdb_byte
*entry_pool
;
253 /* Attribute name DW_IDX_*. */
256 /* Attribute form DW_FORM_*. */
259 /* Value if FORM is DW_FORM_implicit_const. */
260 LONGEST implicit_const
;
262 std::vector
<attr
> attr_vec
;
265 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
267 const char *namei_to_name (uint32_t namei
) const;
269 /* Implementation of the mapped_index_base virtual interface, for
270 the name_components cache. */
272 const char *symbol_name_at (offset_type idx
) const override
273 { return namei_to_name (idx
); }
275 size_t symbol_name_count () const override
276 { return this->name_count
; }
279 /* See dwarf2read.h. */
282 get_dwarf2_per_objfile (struct objfile
*objfile
)
284 return ((struct dwarf2_per_objfile
*)
285 objfile_data (objfile
, dwarf2_objfile_data_key
));
288 /* Set the dwarf2_per_objfile associated to OBJFILE. */
291 set_dwarf2_per_objfile (struct objfile
*objfile
,
292 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
294 gdb_assert (get_dwarf2_per_objfile (objfile
) == NULL
);
295 set_objfile_data (objfile
, dwarf2_objfile_data_key
, dwarf2_per_objfile
);
298 /* Default names of the debugging sections. */
300 /* Note that if the debugging section has been compressed, it might
301 have a name like .zdebug_info. */
303 static const struct dwarf2_debug_sections dwarf2_elf_names
=
305 { ".debug_info", ".zdebug_info" },
306 { ".debug_abbrev", ".zdebug_abbrev" },
307 { ".debug_line", ".zdebug_line" },
308 { ".debug_loc", ".zdebug_loc" },
309 { ".debug_loclists", ".zdebug_loclists" },
310 { ".debug_macinfo", ".zdebug_macinfo" },
311 { ".debug_macro", ".zdebug_macro" },
312 { ".debug_str", ".zdebug_str" },
313 { ".debug_line_str", ".zdebug_line_str" },
314 { ".debug_ranges", ".zdebug_ranges" },
315 { ".debug_rnglists", ".zdebug_rnglists" },
316 { ".debug_types", ".zdebug_types" },
317 { ".debug_addr", ".zdebug_addr" },
318 { ".debug_frame", ".zdebug_frame" },
319 { ".eh_frame", NULL
},
320 { ".gdb_index", ".zgdb_index" },
321 { ".debug_names", ".zdebug_names" },
322 { ".debug_aranges", ".zdebug_aranges" },
326 /* List of DWO/DWP sections. */
328 static const struct dwop_section_names
330 struct dwarf2_section_names abbrev_dwo
;
331 struct dwarf2_section_names info_dwo
;
332 struct dwarf2_section_names line_dwo
;
333 struct dwarf2_section_names loc_dwo
;
334 struct dwarf2_section_names loclists_dwo
;
335 struct dwarf2_section_names macinfo_dwo
;
336 struct dwarf2_section_names macro_dwo
;
337 struct dwarf2_section_names str_dwo
;
338 struct dwarf2_section_names str_offsets_dwo
;
339 struct dwarf2_section_names types_dwo
;
340 struct dwarf2_section_names cu_index
;
341 struct dwarf2_section_names tu_index
;
345 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
346 { ".debug_info.dwo", ".zdebug_info.dwo" },
347 { ".debug_line.dwo", ".zdebug_line.dwo" },
348 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
349 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
350 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
351 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
352 { ".debug_str.dwo", ".zdebug_str.dwo" },
353 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
354 { ".debug_types.dwo", ".zdebug_types.dwo" },
355 { ".debug_cu_index", ".zdebug_cu_index" },
356 { ".debug_tu_index", ".zdebug_tu_index" },
359 /* local data types */
361 /* The data in a compilation unit header, after target2host
362 translation, looks like this. */
363 struct comp_unit_head
367 unsigned char addr_size
;
368 unsigned char signed_addr_p
;
369 sect_offset abbrev_sect_off
;
371 /* Size of file offsets; either 4 or 8. */
372 unsigned int offset_size
;
374 /* Size of the length field; either 4 or 12. */
375 unsigned int initial_length_size
;
377 enum dwarf_unit_type unit_type
;
379 /* Offset to the first byte of this compilation unit header in the
380 .debug_info section, for resolving relative reference dies. */
381 sect_offset sect_off
;
383 /* Offset to first die in this cu from the start of the cu.
384 This will be the first byte following the compilation unit header. */
385 cu_offset first_die_cu_offset
;
387 /* 64-bit signature of this type unit - it is valid only for
388 UNIT_TYPE DW_UT_type. */
391 /* For types, offset in the type's DIE of the type defined by this TU. */
392 cu_offset type_cu_offset_in_tu
;
395 /* Type used for delaying computation of method physnames.
396 See comments for compute_delayed_physnames. */
397 struct delayed_method_info
399 /* The type to which the method is attached, i.e., its parent class. */
402 /* The index of the method in the type's function fieldlists. */
405 /* The index of the method in the fieldlist. */
408 /* The name of the DIE. */
411 /* The DIE associated with this method. */
412 struct die_info
*die
;
415 /* Internal state when decoding a particular compilation unit. */
418 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
421 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
423 /* The header of the compilation unit. */
424 struct comp_unit_head header
{};
426 /* Base address of this compilation unit. */
427 CORE_ADDR base_address
= 0;
429 /* Non-zero if base_address has been set. */
432 /* The language we are debugging. */
433 enum language language
= language_unknown
;
434 const struct language_defn
*language_defn
= nullptr;
436 const char *producer
= nullptr;
438 /* The generic symbol table building routines have separate lists for
439 file scope symbols and all all other scopes (local scopes). So
440 we need to select the right one to pass to add_symbol_to_list().
441 We do it by keeping a pointer to the correct list in list_in_scope.
443 FIXME: The original dwarf code just treated the file scope as the
444 first local scope, and all other local scopes as nested local
445 scopes, and worked fine. Check to see if we really need to
446 distinguish these in buildsym.c. */
447 struct pending
**list_in_scope
= nullptr;
449 /* Hash table holding all the loaded partial DIEs
450 with partial_die->offset.SECT_OFF as hash. */
451 htab_t partial_dies
= nullptr;
453 /* Storage for things with the same lifetime as this read-in compilation
454 unit, including partial DIEs. */
455 auto_obstack comp_unit_obstack
;
457 /* When multiple dwarf2_cu structures are living in memory, this field
458 chains them all together, so that they can be released efficiently.
459 We will probably also want a generation counter so that most-recently-used
460 compilation units are cached... */
461 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
463 /* Backlink to our per_cu entry. */
464 struct dwarf2_per_cu_data
*per_cu
;
466 /* How many compilation units ago was this CU last referenced? */
469 /* A hash table of DIE cu_offset for following references with
470 die_info->offset.sect_off as hash. */
471 htab_t die_hash
= nullptr;
473 /* Full DIEs if read in. */
474 struct die_info
*dies
= nullptr;
476 /* A set of pointers to dwarf2_per_cu_data objects for compilation
477 units referenced by this one. Only set during full symbol processing;
478 partial symbol tables do not have dependencies. */
479 htab_t dependencies
= nullptr;
481 /* Header data from the line table, during full symbol processing. */
482 struct line_header
*line_header
= nullptr;
483 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
484 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
485 this is the DW_TAG_compile_unit die for this CU. We'll hold on
486 to the line header as long as this DIE is being processed. See
487 process_die_scope. */
488 die_info
*line_header_die_owner
= nullptr;
490 /* A list of methods which need to have physnames computed
491 after all type information has been read. */
492 std::vector
<delayed_method_info
> method_list
;
494 /* To be copied to symtab->call_site_htab. */
495 htab_t call_site_htab
= nullptr;
497 /* Non-NULL if this CU came from a DWO file.
498 There is an invariant here that is important to remember:
499 Except for attributes copied from the top level DIE in the "main"
500 (or "stub") file in preparation for reading the DWO file
501 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
502 Either there isn't a DWO file (in which case this is NULL and the point
503 is moot), or there is and either we're not going to read it (in which
504 case this is NULL) or there is and we are reading it (in which case this
506 struct dwo_unit
*dwo_unit
= nullptr;
508 /* The DW_AT_addr_base attribute if present, zero otherwise
509 (zero is a valid value though).
510 Note this value comes from the Fission stub CU/TU's DIE. */
511 ULONGEST addr_base
= 0;
513 /* The DW_AT_ranges_base attribute if present, zero otherwise
514 (zero is a valid value though).
515 Note this value comes from the Fission stub CU/TU's DIE.
516 Also note that the value is zero in the non-DWO case so this value can
517 be used without needing to know whether DWO files are in use or not.
518 N.B. This does not apply to DW_AT_ranges appearing in
519 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
520 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
521 DW_AT_ranges_base *would* have to be applied, and we'd have to care
522 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
523 ULONGEST ranges_base
= 0;
525 /* When reading debug info generated by older versions of rustc, we
526 have to rewrite some union types to be struct types with a
527 variant part. This rewriting must be done after the CU is fully
528 read in, because otherwise at the point of rewriting some struct
529 type might not have been fully processed. So, we keep a list of
530 all such types here and process them after expansion. */
531 std::vector
<struct type
*> rust_unions
;
533 /* Mark used when releasing cached dies. */
534 unsigned int mark
: 1;
536 /* This CU references .debug_loc. See the symtab->locations_valid field.
537 This test is imperfect as there may exist optimized debug code not using
538 any location list and still facing inlining issues if handled as
539 unoptimized code. For a future better test see GCC PR other/32998. */
540 unsigned int has_loclist
: 1;
542 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
543 if all the producer_is_* fields are valid. This information is cached
544 because profiling CU expansion showed excessive time spent in
545 producer_is_gxx_lt_4_6. */
546 unsigned int checked_producer
: 1;
547 unsigned int producer_is_gxx_lt_4_6
: 1;
548 unsigned int producer_is_gcc_lt_4_3
: 1;
549 unsigned int producer_is_icc_lt_14
: 1;
551 /* When set, the file that we're processing is known to have
552 debugging info for C++ namespaces. GCC 3.3.x did not produce
553 this information, but later versions do. */
555 unsigned int processing_has_namespace_info
: 1;
557 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
560 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
561 This includes type_unit_group and quick_file_names. */
563 struct stmt_list_hash
565 /* The DWO unit this table is from or NULL if there is none. */
566 struct dwo_unit
*dwo_unit
;
568 /* Offset in .debug_line or .debug_line.dwo. */
569 sect_offset line_sect_off
;
572 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
573 an object of this type. */
575 struct type_unit_group
577 /* dwarf2read.c's main "handle" on a TU symtab.
578 To simplify things we create an artificial CU that "includes" all the
579 type units using this stmt_list so that the rest of the code still has
580 a "per_cu" handle on the symtab.
581 This PER_CU is recognized by having no section. */
582 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
583 struct dwarf2_per_cu_data per_cu
;
585 /* The TUs that share this DW_AT_stmt_list entry.
586 This is added to while parsing type units to build partial symtabs,
587 and is deleted afterwards and not used again. */
588 VEC (sig_type_ptr
) *tus
;
590 /* The compunit symtab.
591 Type units in a group needn't all be defined in the same source file,
592 so we create an essentially anonymous symtab as the compunit symtab. */
593 struct compunit_symtab
*compunit_symtab
;
595 /* The data used to construct the hash key. */
596 struct stmt_list_hash hash
;
598 /* The number of symtabs from the line header.
599 The value here must match line_header.num_file_names. */
600 unsigned int num_symtabs
;
602 /* The symbol tables for this TU (obtained from the files listed in
604 WARNING: The order of entries here must match the order of entries
605 in the line header. After the first TU using this type_unit_group, the
606 line header for the subsequent TUs is recreated from this. This is done
607 because we need to use the same symtabs for each TU using the same
608 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
609 there's no guarantee the line header doesn't have duplicate entries. */
610 struct symtab
**symtabs
;
613 /* These sections are what may appear in a (real or virtual) DWO file. */
617 struct dwarf2_section_info abbrev
;
618 struct dwarf2_section_info line
;
619 struct dwarf2_section_info loc
;
620 struct dwarf2_section_info loclists
;
621 struct dwarf2_section_info macinfo
;
622 struct dwarf2_section_info macro
;
623 struct dwarf2_section_info str
;
624 struct dwarf2_section_info str_offsets
;
625 /* In the case of a virtual DWO file, these two are unused. */
626 struct dwarf2_section_info info
;
627 VEC (dwarf2_section_info_def
) *types
;
630 /* CUs/TUs in DWP/DWO files. */
634 /* Backlink to the containing struct dwo_file. */
635 struct dwo_file
*dwo_file
;
637 /* The "id" that distinguishes this CU/TU.
638 .debug_info calls this "dwo_id", .debug_types calls this "signature".
639 Since signatures came first, we stick with it for consistency. */
642 /* The section this CU/TU lives in, in the DWO file. */
643 struct dwarf2_section_info
*section
;
645 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
646 sect_offset sect_off
;
649 /* For types, offset in the type's DIE of the type defined by this TU. */
650 cu_offset type_offset_in_tu
;
653 /* include/dwarf2.h defines the DWP section codes.
654 It defines a max value but it doesn't define a min value, which we
655 use for error checking, so provide one. */
657 enum dwp_v2_section_ids
662 /* Data for one DWO file.
664 This includes virtual DWO files (a virtual DWO file is a DWO file as it
665 appears in a DWP file). DWP files don't really have DWO files per se -
666 comdat folding of types "loses" the DWO file they came from, and from
667 a high level view DWP files appear to contain a mass of random types.
668 However, to maintain consistency with the non-DWP case we pretend DWP
669 files contain virtual DWO files, and we assign each TU with one virtual
670 DWO file (generally based on the line and abbrev section offsets -
671 a heuristic that seems to work in practice). */
675 /* The DW_AT_GNU_dwo_name attribute.
676 For virtual DWO files the name is constructed from the section offsets
677 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
678 from related CU+TUs. */
679 const char *dwo_name
;
681 /* The DW_AT_comp_dir attribute. */
682 const char *comp_dir
;
684 /* The bfd, when the file is open. Otherwise this is NULL.
685 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
688 /* The sections that make up this DWO file.
689 Remember that for virtual DWO files in DWP V2, these are virtual
690 sections (for lack of a better name). */
691 struct dwo_sections sections
;
693 /* The CUs in the file.
694 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
695 an extension to handle LLVM's Link Time Optimization output (where
696 multiple source files may be compiled into a single object/dwo pair). */
699 /* Table of TUs in the file.
700 Each element is a struct dwo_unit. */
704 /* These sections are what may appear in a DWP file. */
708 /* These are used by both DWP version 1 and 2. */
709 struct dwarf2_section_info str
;
710 struct dwarf2_section_info cu_index
;
711 struct dwarf2_section_info tu_index
;
713 /* These are only used by DWP version 2 files.
714 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
715 sections are referenced by section number, and are not recorded here.
716 In DWP version 2 there is at most one copy of all these sections, each
717 section being (effectively) comprised of the concatenation of all of the
718 individual sections that exist in the version 1 format.
719 To keep the code simple we treat each of these concatenated pieces as a
720 section itself (a virtual section?). */
721 struct dwarf2_section_info abbrev
;
722 struct dwarf2_section_info info
;
723 struct dwarf2_section_info line
;
724 struct dwarf2_section_info loc
;
725 struct dwarf2_section_info macinfo
;
726 struct dwarf2_section_info macro
;
727 struct dwarf2_section_info str_offsets
;
728 struct dwarf2_section_info types
;
731 /* These sections are what may appear in a virtual DWO file in DWP version 1.
732 A virtual DWO file is a DWO file as it appears in a DWP file. */
734 struct virtual_v1_dwo_sections
736 struct dwarf2_section_info abbrev
;
737 struct dwarf2_section_info line
;
738 struct dwarf2_section_info loc
;
739 struct dwarf2_section_info macinfo
;
740 struct dwarf2_section_info macro
;
741 struct dwarf2_section_info str_offsets
;
742 /* Each DWP hash table entry records one CU or one TU.
743 That is recorded here, and copied to dwo_unit.section. */
744 struct dwarf2_section_info info_or_types
;
747 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
748 In version 2, the sections of the DWO files are concatenated together
749 and stored in one section of that name. Thus each ELF section contains
750 several "virtual" sections. */
752 struct virtual_v2_dwo_sections
754 bfd_size_type abbrev_offset
;
755 bfd_size_type abbrev_size
;
757 bfd_size_type line_offset
;
758 bfd_size_type line_size
;
760 bfd_size_type loc_offset
;
761 bfd_size_type loc_size
;
763 bfd_size_type macinfo_offset
;
764 bfd_size_type macinfo_size
;
766 bfd_size_type macro_offset
;
767 bfd_size_type macro_size
;
769 bfd_size_type str_offsets_offset
;
770 bfd_size_type str_offsets_size
;
772 /* Each DWP hash table entry records one CU or one TU.
773 That is recorded here, and copied to dwo_unit.section. */
774 bfd_size_type info_or_types_offset
;
775 bfd_size_type info_or_types_size
;
778 /* Contents of DWP hash tables. */
780 struct dwp_hash_table
782 uint32_t version
, nr_columns
;
783 uint32_t nr_units
, nr_slots
;
784 const gdb_byte
*hash_table
, *unit_table
;
789 const gdb_byte
*indices
;
793 /* This is indexed by column number and gives the id of the section
795 #define MAX_NR_V2_DWO_SECTIONS \
796 (1 /* .debug_info or .debug_types */ \
797 + 1 /* .debug_abbrev */ \
798 + 1 /* .debug_line */ \
799 + 1 /* .debug_loc */ \
800 + 1 /* .debug_str_offsets */ \
801 + 1 /* .debug_macro or .debug_macinfo */)
802 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
803 const gdb_byte
*offsets
;
804 const gdb_byte
*sizes
;
809 /* Data for one DWP file. */
813 /* Name of the file. */
816 /* File format version. */
822 /* Section info for this file. */
823 struct dwp_sections sections
;
825 /* Table of CUs in the file. */
826 const struct dwp_hash_table
*cus
;
828 /* Table of TUs in the file. */
829 const struct dwp_hash_table
*tus
;
831 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
835 /* Table to map ELF section numbers to their sections.
836 This is only needed for the DWP V1 file format. */
837 unsigned int num_sections
;
838 asection
**elf_sections
;
841 /* This represents a '.dwz' file. */
845 /* A dwz file can only contain a few sections. */
846 struct dwarf2_section_info abbrev
;
847 struct dwarf2_section_info info
;
848 struct dwarf2_section_info str
;
849 struct dwarf2_section_info line
;
850 struct dwarf2_section_info macro
;
851 struct dwarf2_section_info gdb_index
;
852 struct dwarf2_section_info debug_names
;
858 /* Struct used to pass misc. parameters to read_die_and_children, et
859 al. which are used for both .debug_info and .debug_types dies.
860 All parameters here are unchanging for the life of the call. This
861 struct exists to abstract away the constant parameters of die reading. */
863 struct die_reader_specs
865 /* The bfd of die_section. */
868 /* The CU of the DIE we are parsing. */
869 struct dwarf2_cu
*cu
;
871 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
872 struct dwo_file
*dwo_file
;
874 /* The section the die comes from.
875 This is either .debug_info or .debug_types, or the .dwo variants. */
876 struct dwarf2_section_info
*die_section
;
878 /* die_section->buffer. */
879 const gdb_byte
*buffer
;
881 /* The end of the buffer. */
882 const gdb_byte
*buffer_end
;
884 /* The value of the DW_AT_comp_dir attribute. */
885 const char *comp_dir
;
887 /* The abbreviation table to use when reading the DIEs. */
888 struct abbrev_table
*abbrev_table
;
891 /* Type of function passed to init_cutu_and_read_dies, et.al. */
892 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
893 const gdb_byte
*info_ptr
,
894 struct die_info
*comp_unit_die
,
898 /* A 1-based directory index. This is a strong typedef to prevent
899 accidentally using a directory index as a 0-based index into an
901 enum class dir_index
: unsigned int {};
903 /* Likewise, a 1-based file name index. */
904 enum class file_name_index
: unsigned int {};
908 file_entry () = default;
910 file_entry (const char *name_
, dir_index d_index_
,
911 unsigned int mod_time_
, unsigned int length_
)
914 mod_time (mod_time_
),
918 /* Return the include directory at D_INDEX stored in LH. Returns
919 NULL if D_INDEX is out of bounds. */
920 const char *include_dir (const line_header
*lh
) const;
922 /* The file name. Note this is an observing pointer. The memory is
923 owned by debug_line_buffer. */
926 /* The directory index (1-based). */
927 dir_index d_index
{};
929 unsigned int mod_time
{};
931 unsigned int length
{};
933 /* True if referenced by the Line Number Program. */
936 /* The associated symbol table, if any. */
937 struct symtab
*symtab
{};
940 /* The line number information for a compilation unit (found in the
941 .debug_line section) begins with a "statement program header",
942 which contains the following information. */
949 /* Add an entry to the include directory table. */
950 void add_include_dir (const char *include_dir
);
952 /* Add an entry to the file name table. */
953 void add_file_name (const char *name
, dir_index d_index
,
954 unsigned int mod_time
, unsigned int length
);
956 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
958 const char *include_dir_at (dir_index index
) const
960 /* Convert directory index number (1-based) to vector index
962 size_t vec_index
= to_underlying (index
) - 1;
964 if (vec_index
>= include_dirs
.size ())
966 return include_dirs
[vec_index
];
969 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
971 file_entry
*file_name_at (file_name_index index
)
973 /* Convert file name index number (1-based) to vector index
975 size_t vec_index
= to_underlying (index
) - 1;
977 if (vec_index
>= file_names
.size ())
979 return &file_names
[vec_index
];
982 /* Const version of the above. */
983 const file_entry
*file_name_at (unsigned int index
) const
985 if (index
>= file_names
.size ())
987 return &file_names
[index
];
990 /* Offset of line number information in .debug_line section. */
991 sect_offset sect_off
{};
993 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
994 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
996 unsigned int total_length
{};
997 unsigned short version
{};
998 unsigned int header_length
{};
999 unsigned char minimum_instruction_length
{};
1000 unsigned char maximum_ops_per_instruction
{};
1001 unsigned char default_is_stmt
{};
1003 unsigned char line_range
{};
1004 unsigned char opcode_base
{};
1006 /* standard_opcode_lengths[i] is the number of operands for the
1007 standard opcode whose value is i. This means that
1008 standard_opcode_lengths[0] is unused, and the last meaningful
1009 element is standard_opcode_lengths[opcode_base - 1]. */
1010 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1012 /* The include_directories table. Note these are observing
1013 pointers. The memory is owned by debug_line_buffer. */
1014 std::vector
<const char *> include_dirs
;
1016 /* The file_names table. */
1017 std::vector
<file_entry
> file_names
;
1019 /* The start and end of the statement program following this
1020 header. These point into dwarf2_per_objfile->line_buffer. */
1021 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1024 typedef std::unique_ptr
<line_header
> line_header_up
;
1027 file_entry::include_dir (const line_header
*lh
) const
1029 return lh
->include_dir_at (d_index
);
1032 /* When we construct a partial symbol table entry we only
1033 need this much information. */
1034 struct partial_die_info
: public allocate_on_obstack
1036 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1038 /* Disable assign but still keep copy ctor, which is needed
1039 load_partial_dies. */
1040 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1042 /* Adjust the partial die before generating a symbol for it. This
1043 function may set the is_external flag or change the DIE's
1045 void fixup (struct dwarf2_cu
*cu
);
1047 /* Read a minimal amount of information into the minimal die
1049 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1050 const struct abbrev_info
&abbrev
,
1051 const gdb_byte
*info_ptr
);
1053 /* Offset of this DIE. */
1054 const sect_offset sect_off
;
1056 /* DWARF-2 tag for this DIE. */
1057 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1059 /* Assorted flags describing the data found in this DIE. */
1060 const unsigned int has_children
: 1;
1062 unsigned int is_external
: 1;
1063 unsigned int is_declaration
: 1;
1064 unsigned int has_type
: 1;
1065 unsigned int has_specification
: 1;
1066 unsigned int has_pc_info
: 1;
1067 unsigned int may_be_inlined
: 1;
1069 /* This DIE has been marked DW_AT_main_subprogram. */
1070 unsigned int main_subprogram
: 1;
1072 /* Flag set if the SCOPE field of this structure has been
1074 unsigned int scope_set
: 1;
1076 /* Flag set if the DIE has a byte_size attribute. */
1077 unsigned int has_byte_size
: 1;
1079 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1080 unsigned int has_const_value
: 1;
1082 /* Flag set if any of the DIE's children are template arguments. */
1083 unsigned int has_template_arguments
: 1;
1085 /* Flag set if fixup has been called on this die. */
1086 unsigned int fixup_called
: 1;
1088 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1089 unsigned int is_dwz
: 1;
1091 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1092 unsigned int spec_is_dwz
: 1;
1094 /* The name of this DIE. Normally the value of DW_AT_name, but
1095 sometimes a default name for unnamed DIEs. */
1096 const char *name
= nullptr;
1098 /* The linkage name, if present. */
1099 const char *linkage_name
= nullptr;
1101 /* The scope to prepend to our children. This is generally
1102 allocated on the comp_unit_obstack, so will disappear
1103 when this compilation unit leaves the cache. */
1104 const char *scope
= nullptr;
1106 /* Some data associated with the partial DIE. The tag determines
1107 which field is live. */
1110 /* The location description associated with this DIE, if any. */
1111 struct dwarf_block
*locdesc
;
1112 /* The offset of an import, for DW_TAG_imported_unit. */
1113 sect_offset sect_off
;
1116 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1117 CORE_ADDR lowpc
= 0;
1118 CORE_ADDR highpc
= 0;
1120 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1121 DW_AT_sibling, if any. */
1122 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1123 could return DW_AT_sibling values to its caller load_partial_dies. */
1124 const gdb_byte
*sibling
= nullptr;
1126 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1127 DW_AT_specification (or DW_AT_abstract_origin or
1128 DW_AT_extension). */
1129 sect_offset spec_offset
{};
1131 /* Pointers to this DIE's parent, first child, and next sibling,
1133 struct partial_die_info
*die_parent
= nullptr;
1134 struct partial_die_info
*die_child
= nullptr;
1135 struct partial_die_info
*die_sibling
= nullptr;
1137 friend struct partial_die_info
*
1138 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1141 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1142 partial_die_info (sect_offset sect_off
)
1143 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1147 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1149 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1154 has_specification
= 0;
1157 main_subprogram
= 0;
1160 has_const_value
= 0;
1161 has_template_arguments
= 0;
1168 /* This data structure holds the information of an abbrev. */
1171 unsigned int number
; /* number identifying abbrev */
1172 enum dwarf_tag tag
; /* dwarf tag */
1173 unsigned short has_children
; /* boolean */
1174 unsigned short num_attrs
; /* number of attributes */
1175 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1176 struct abbrev_info
*next
; /* next in chain */
1181 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1182 ENUM_BITFIELD(dwarf_form
) form
: 16;
1184 /* It is valid only if FORM is DW_FORM_implicit_const. */
1185 LONGEST implicit_const
;
1188 /* Size of abbrev_table.abbrev_hash_table. */
1189 #define ABBREV_HASH_SIZE 121
1191 /* Top level data structure to contain an abbreviation table. */
1195 explicit abbrev_table (sect_offset off
)
1199 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1200 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1203 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1205 /* Allocate space for a struct abbrev_info object in
1207 struct abbrev_info
*alloc_abbrev ();
1209 /* Add an abbreviation to the table. */
1210 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1212 /* Look up an abbrev in the table.
1213 Returns NULL if the abbrev is not found. */
1215 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1218 /* Where the abbrev table came from.
1219 This is used as a sanity check when the table is used. */
1220 const sect_offset sect_off
;
1222 /* Storage for the abbrev table. */
1223 auto_obstack abbrev_obstack
;
1227 /* Hash table of abbrevs.
1228 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1229 It could be statically allocated, but the previous code didn't so we
1231 struct abbrev_info
**m_abbrevs
;
1234 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1236 /* Attributes have a name and a value. */
1239 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1240 ENUM_BITFIELD(dwarf_form
) form
: 15;
1242 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1243 field should be in u.str (existing only for DW_STRING) but it is kept
1244 here for better struct attribute alignment. */
1245 unsigned int string_is_canonical
: 1;
1250 struct dwarf_block
*blk
;
1259 /* This data structure holds a complete die structure. */
1262 /* DWARF-2 tag for this DIE. */
1263 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1265 /* Number of attributes */
1266 unsigned char num_attrs
;
1268 /* True if we're presently building the full type name for the
1269 type derived from this DIE. */
1270 unsigned char building_fullname
: 1;
1272 /* True if this die is in process. PR 16581. */
1273 unsigned char in_process
: 1;
1276 unsigned int abbrev
;
1278 /* Offset in .debug_info or .debug_types section. */
1279 sect_offset sect_off
;
1281 /* The dies in a compilation unit form an n-ary tree. PARENT
1282 points to this die's parent; CHILD points to the first child of
1283 this node; and all the children of a given node are chained
1284 together via their SIBLING fields. */
1285 struct die_info
*child
; /* Its first child, if any. */
1286 struct die_info
*sibling
; /* Its next sibling, if any. */
1287 struct die_info
*parent
; /* Its parent, if any. */
1289 /* An array of attributes, with NUM_ATTRS elements. There may be
1290 zero, but it's not common and zero-sized arrays are not
1291 sufficiently portable C. */
1292 struct attribute attrs
[1];
1295 /* Get at parts of an attribute structure. */
1297 #define DW_STRING(attr) ((attr)->u.str)
1298 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1299 #define DW_UNSND(attr) ((attr)->u.unsnd)
1300 #define DW_BLOCK(attr) ((attr)->u.blk)
1301 #define DW_SND(attr) ((attr)->u.snd)
1302 #define DW_ADDR(attr) ((attr)->u.addr)
1303 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1305 /* Blocks are a bunch of untyped bytes. */
1310 /* Valid only if SIZE is not zero. */
1311 const gdb_byte
*data
;
1314 #ifndef ATTR_ALLOC_CHUNK
1315 #define ATTR_ALLOC_CHUNK 4
1318 /* Allocate fields for structs, unions and enums in this size. */
1319 #ifndef DW_FIELD_ALLOC_CHUNK
1320 #define DW_FIELD_ALLOC_CHUNK 4
1323 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1324 but this would require a corresponding change in unpack_field_as_long
1326 static int bits_per_byte
= 8;
1328 /* When reading a variant or variant part, we track a bit more
1329 information about the field, and store it in an object of this
1332 struct variant_field
1334 /* If we see a DW_TAG_variant, then this will be the discriminant
1336 ULONGEST discriminant_value
;
1337 /* If we see a DW_TAG_variant, then this will be set if this is the
1339 bool default_branch
;
1340 /* While reading a DW_TAG_variant_part, this will be set if this
1341 field is the discriminant. */
1342 bool is_discriminant
;
1347 int accessibility
= 0;
1349 /* Extra information to describe a variant or variant part. */
1350 struct variant_field variant
{};
1351 struct field field
{};
1356 const char *name
= nullptr;
1357 std::vector
<struct fn_field
> fnfields
;
1360 /* The routines that read and process dies for a C struct or C++ class
1361 pass lists of data member fields and lists of member function fields
1362 in an instance of a field_info structure, as defined below. */
1365 /* List of data member and baseclasses fields. */
1366 std::vector
<struct nextfield
> fields
;
1367 std::vector
<struct nextfield
> baseclasses
;
1369 /* Number of fields (including baseclasses). */
1372 /* Set if the accesibility of one of the fields is not public. */
1373 int non_public_fields
= 0;
1375 /* Member function fieldlist array, contains name of possibly overloaded
1376 member function, number of overloaded member functions and a pointer
1377 to the head of the member function field chain. */
1378 std::vector
<struct fnfieldlist
> fnfieldlists
;
1380 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1381 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1382 std::vector
<struct decl_field
> typedef_field_list
;
1384 /* Nested types defined by this class and the number of elements in this
1386 std::vector
<struct decl_field
> nested_types_list
;
1389 /* One item on the queue of compilation units to read in full symbols
1391 struct dwarf2_queue_item
1393 struct dwarf2_per_cu_data
*per_cu
;
1394 enum language pretend_language
;
1395 struct dwarf2_queue_item
*next
;
1398 /* The current queue. */
1399 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1401 /* Loaded secondary compilation units are kept in memory until they
1402 have not been referenced for the processing of this many
1403 compilation units. Set this to zero to disable caching. Cache
1404 sizes of up to at least twenty will improve startup time for
1405 typical inter-CU-reference binaries, at an obvious memory cost. */
1406 static int dwarf_max_cache_age
= 5;
1408 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1409 struct cmd_list_element
*c
, const char *value
)
1411 fprintf_filtered (file
, _("The upper bound on the age of cached "
1412 "DWARF compilation units is %s.\n"),
1416 /* local function prototypes */
1418 static const char *get_section_name (const struct dwarf2_section_info
*);
1420 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1422 static void dwarf2_find_base_address (struct die_info
*die
,
1423 struct dwarf2_cu
*cu
);
1425 static struct partial_symtab
*create_partial_symtab
1426 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1428 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1429 const gdb_byte
*info_ptr
,
1430 struct die_info
*type_unit_die
,
1431 int has_children
, void *data
);
1433 static void dwarf2_build_psymtabs_hard
1434 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1436 static void scan_partial_symbols (struct partial_die_info
*,
1437 CORE_ADDR
*, CORE_ADDR
*,
1438 int, struct dwarf2_cu
*);
1440 static void add_partial_symbol (struct partial_die_info
*,
1441 struct dwarf2_cu
*);
1443 static void add_partial_namespace (struct partial_die_info
*pdi
,
1444 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1445 int set_addrmap
, struct dwarf2_cu
*cu
);
1447 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1448 CORE_ADDR
*highpc
, int set_addrmap
,
1449 struct dwarf2_cu
*cu
);
1451 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1452 struct dwarf2_cu
*cu
);
1454 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1455 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1456 int need_pc
, struct dwarf2_cu
*cu
);
1458 static void dwarf2_read_symtab (struct partial_symtab
*,
1461 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1463 static abbrev_table_up abbrev_table_read_table
1464 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1467 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1469 static struct partial_die_info
*load_partial_dies
1470 (const struct die_reader_specs
*, const gdb_byte
*, int);
1472 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1473 struct dwarf2_cu
*);
1475 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1476 struct attribute
*, struct attr_abbrev
*,
1479 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1481 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1483 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1485 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1487 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1489 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1492 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1494 static LONGEST read_checked_initial_length_and_offset
1495 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1496 unsigned int *, unsigned int *);
1498 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1499 const struct comp_unit_head
*,
1502 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1504 static sect_offset read_abbrev_offset
1505 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1506 struct dwarf2_section_info
*, sect_offset
);
1508 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1510 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1512 static const char *read_indirect_string
1513 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1514 const struct comp_unit_head
*, unsigned int *);
1516 static const char *read_indirect_line_string
1517 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1518 const struct comp_unit_head
*, unsigned int *);
1520 static const char *read_indirect_string_at_offset
1521 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1522 LONGEST str_offset
);
1524 static const char *read_indirect_string_from_dwz
1525 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1527 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1529 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1533 static const char *read_str_index (const struct die_reader_specs
*reader
,
1534 ULONGEST str_index
);
1536 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1538 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1539 struct dwarf2_cu
*);
1541 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1544 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1545 struct dwarf2_cu
*cu
);
1547 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1548 struct dwarf2_cu
*cu
);
1550 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1552 static struct die_info
*die_specification (struct die_info
*die
,
1553 struct dwarf2_cu
**);
1555 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1556 struct dwarf2_cu
*cu
);
1558 static void dwarf_decode_lines (struct line_header
*, const char *,
1559 struct dwarf2_cu
*, struct partial_symtab
*,
1560 CORE_ADDR
, int decode_mapping
);
1562 static void dwarf2_start_subfile (const char *, const char *);
1564 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1565 const char *, const char *,
1568 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1569 struct dwarf2_cu
*, struct symbol
* = NULL
);
1571 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1572 struct dwarf2_cu
*);
1574 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1577 struct obstack
*obstack
,
1578 struct dwarf2_cu
*cu
, LONGEST
*value
,
1579 const gdb_byte
**bytes
,
1580 struct dwarf2_locexpr_baton
**baton
);
1582 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1584 static int need_gnat_info (struct dwarf2_cu
*);
1586 static struct type
*die_descriptive_type (struct die_info
*,
1587 struct dwarf2_cu
*);
1589 static void set_descriptive_type (struct type
*, struct die_info
*,
1590 struct dwarf2_cu
*);
1592 static struct type
*die_containing_type (struct die_info
*,
1593 struct dwarf2_cu
*);
1595 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1596 struct dwarf2_cu
*);
1598 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1600 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1602 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1604 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1605 const char *suffix
, int physname
,
1606 struct dwarf2_cu
*cu
);
1608 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1610 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1612 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1614 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1616 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1618 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1620 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1621 struct dwarf2_cu
*, struct partial_symtab
*);
1623 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1624 values. Keep the items ordered with increasing constraints compliance. */
1627 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1628 PC_BOUNDS_NOT_PRESENT
,
1630 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1631 were present but they do not form a valid range of PC addresses. */
1634 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1637 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1641 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1642 CORE_ADDR
*, CORE_ADDR
*,
1644 struct partial_symtab
*);
1646 static void get_scope_pc_bounds (struct die_info
*,
1647 CORE_ADDR
*, CORE_ADDR
*,
1648 struct dwarf2_cu
*);
1650 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1651 CORE_ADDR
, struct dwarf2_cu
*);
1653 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1654 struct dwarf2_cu
*);
1656 static void dwarf2_attach_fields_to_type (struct field_info
*,
1657 struct type
*, struct dwarf2_cu
*);
1659 static void dwarf2_add_member_fn (struct field_info
*,
1660 struct die_info
*, struct type
*,
1661 struct dwarf2_cu
*);
1663 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1665 struct dwarf2_cu
*);
1667 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1669 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1671 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1673 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1675 static struct using_direct
**using_directives (enum language
);
1677 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1679 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1681 static struct type
*read_module_type (struct die_info
*die
,
1682 struct dwarf2_cu
*cu
);
1684 static const char *namespace_name (struct die_info
*die
,
1685 int *is_anonymous
, struct dwarf2_cu
*);
1687 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1689 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1691 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1692 struct dwarf2_cu
*);
1694 static struct die_info
*read_die_and_siblings_1
1695 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1698 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1699 const gdb_byte
*info_ptr
,
1700 const gdb_byte
**new_info_ptr
,
1701 struct die_info
*parent
);
1703 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1704 struct die_info
**, const gdb_byte
*,
1707 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1708 struct die_info
**, const gdb_byte
*,
1711 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1713 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1716 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1718 static const char *dwarf2_full_name (const char *name
,
1719 struct die_info
*die
,
1720 struct dwarf2_cu
*cu
);
1722 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1723 struct dwarf2_cu
*cu
);
1725 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1726 struct dwarf2_cu
**);
1728 static const char *dwarf_tag_name (unsigned int);
1730 static const char *dwarf_attr_name (unsigned int);
1732 static const char *dwarf_form_name (unsigned int);
1734 static const char *dwarf_bool_name (unsigned int);
1736 static const char *dwarf_type_encoding_name (unsigned int);
1738 static struct die_info
*sibling_die (struct die_info
*);
1740 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1742 static void dump_die_for_error (struct die_info
*);
1744 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1747 /*static*/ void dump_die (struct die_info
*, int max_level
);
1749 static void store_in_ref_table (struct die_info
*,
1750 struct dwarf2_cu
*);
1752 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1754 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1756 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1757 const struct attribute
*,
1758 struct dwarf2_cu
**);
1760 static struct die_info
*follow_die_ref (struct die_info
*,
1761 const struct attribute
*,
1762 struct dwarf2_cu
**);
1764 static struct die_info
*follow_die_sig (struct die_info
*,
1765 const struct attribute
*,
1766 struct dwarf2_cu
**);
1768 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1769 struct dwarf2_cu
*);
1771 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1772 const struct attribute
*,
1773 struct dwarf2_cu
*);
1775 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1777 static void read_signatured_type (struct signatured_type
*);
1779 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1780 struct die_info
*die
, struct dwarf2_cu
*cu
,
1781 struct dynamic_prop
*prop
);
1783 /* memory allocation interface */
1785 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1787 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1789 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1791 static int attr_form_is_block (const struct attribute
*);
1793 static int attr_form_is_section_offset (const struct attribute
*);
1795 static int attr_form_is_constant (const struct attribute
*);
1797 static int attr_form_is_ref (const struct attribute
*);
1799 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1800 struct dwarf2_loclist_baton
*baton
,
1801 const struct attribute
*attr
);
1803 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1805 struct dwarf2_cu
*cu
,
1808 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1809 const gdb_byte
*info_ptr
,
1810 struct abbrev_info
*abbrev
);
1812 static hashval_t
partial_die_hash (const void *item
);
1814 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1816 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1817 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1818 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1820 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1821 struct die_info
*comp_unit_die
,
1822 enum language pretend_language
);
1824 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1826 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1828 static struct type
*set_die_type (struct die_info
*, struct type
*,
1829 struct dwarf2_cu
*);
1831 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1833 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1835 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1838 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1841 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1844 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1845 struct dwarf2_per_cu_data
*);
1847 static void dwarf2_mark (struct dwarf2_cu
*);
1849 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1851 static struct type
*get_die_type_at_offset (sect_offset
,
1852 struct dwarf2_per_cu_data
*);
1854 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1856 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1857 enum language pretend_language
);
1859 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1861 /* Class, the destructor of which frees all allocated queue entries. This
1862 will only have work to do if an error was thrown while processing the
1863 dwarf. If no error was thrown then the queue entries should have all
1864 been processed, and freed, as we went along. */
1866 class dwarf2_queue_guard
1869 dwarf2_queue_guard () = default;
1871 /* Free any entries remaining on the queue. There should only be
1872 entries left if we hit an error while processing the dwarf. */
1873 ~dwarf2_queue_guard ()
1875 struct dwarf2_queue_item
*item
, *last
;
1877 item
= dwarf2_queue
;
1880 /* Anything still marked queued is likely to be in an
1881 inconsistent state, so discard it. */
1882 if (item
->per_cu
->queued
)
1884 if (item
->per_cu
->cu
!= NULL
)
1885 free_one_cached_comp_unit (item
->per_cu
);
1886 item
->per_cu
->queued
= 0;
1894 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1898 /* The return type of find_file_and_directory. Note, the enclosed
1899 string pointers are only valid while this object is valid. */
1901 struct file_and_directory
1903 /* The filename. This is never NULL. */
1906 /* The compilation directory. NULL if not known. If we needed to
1907 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1908 points directly to the DW_AT_comp_dir string attribute owned by
1909 the obstack that owns the DIE. */
1910 const char *comp_dir
;
1912 /* If we needed to build a new string for comp_dir, this is what
1913 owns the storage. */
1914 std::string comp_dir_storage
;
1917 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1918 struct dwarf2_cu
*cu
);
1920 static char *file_full_name (int file
, struct line_header
*lh
,
1921 const char *comp_dir
);
1923 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1924 enum class rcuh_kind
{ COMPILE
, TYPE
};
1926 static const gdb_byte
*read_and_check_comp_unit_head
1927 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1928 struct comp_unit_head
*header
,
1929 struct dwarf2_section_info
*section
,
1930 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1931 rcuh_kind section_kind
);
1933 static void init_cutu_and_read_dies
1934 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1935 int use_existing_cu
, int keep
,
1936 die_reader_func_ftype
*die_reader_func
, void *data
);
1938 static void init_cutu_and_read_dies_simple
1939 (struct dwarf2_per_cu_data
*this_cu
,
1940 die_reader_func_ftype
*die_reader_func
, void *data
);
1942 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1944 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1946 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1947 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1948 struct dwp_file
*dwp_file
, const char *comp_dir
,
1949 ULONGEST signature
, int is_debug_types
);
1951 static struct dwp_file
*get_dwp_file
1952 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1954 static struct dwo_unit
*lookup_dwo_comp_unit
1955 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1957 static struct dwo_unit
*lookup_dwo_type_unit
1958 (struct signatured_type
*, const char *, const char *);
1960 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1962 static void free_dwo_file_cleanup (void *);
1964 struct free_dwo_file_cleanup_data
1966 struct dwo_file
*dwo_file
;
1967 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
1970 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1972 static void check_producer (struct dwarf2_cu
*cu
);
1974 static void free_line_header_voidp (void *arg
);
1976 /* Various complaints about symbol reading that don't abort the process. */
1979 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1981 complaint (&symfile_complaints
,
1982 _("statement list doesn't fit in .debug_line section"));
1986 dwarf2_debug_line_missing_file_complaint (void)
1988 complaint (&symfile_complaints
,
1989 _(".debug_line section has line data without a file"));
1993 dwarf2_debug_line_missing_end_sequence_complaint (void)
1995 complaint (&symfile_complaints
,
1996 _(".debug_line section has line "
1997 "program sequence without an end"));
2001 dwarf2_complex_location_expr_complaint (void)
2003 complaint (&symfile_complaints
, _("location expression too complex"));
2007 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2010 complaint (&symfile_complaints
,
2011 _("const value length mismatch for '%s', got %d, expected %d"),
2016 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2018 complaint (&symfile_complaints
,
2019 _("debug info runs off end of %s section"
2021 get_section_name (section
),
2022 get_section_file_name (section
));
2026 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2028 complaint (&symfile_complaints
,
2029 _("macro debug info contains a "
2030 "malformed macro definition:\n`%s'"),
2035 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2037 complaint (&symfile_complaints
,
2038 _("invalid attribute class or form for '%s' in '%s'"),
2042 /* Hash function for line_header_hash. */
2045 line_header_hash (const struct line_header
*ofs
)
2047 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2050 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2053 line_header_hash_voidp (const void *item
)
2055 const struct line_header
*ofs
= (const struct line_header
*) item
;
2057 return line_header_hash (ofs
);
2060 /* Equality function for line_header_hash. */
2063 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2065 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2066 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2068 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2069 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2074 /* Read the given attribute value as an address, taking the attribute's
2075 form into account. */
2078 attr_value_as_address (struct attribute
*attr
)
2082 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2084 /* Aside from a few clearly defined exceptions, attributes that
2085 contain an address must always be in DW_FORM_addr form.
2086 Unfortunately, some compilers happen to be violating this
2087 requirement by encoding addresses using other forms, such
2088 as DW_FORM_data4 for example. For those broken compilers,
2089 we try to do our best, without any guarantee of success,
2090 to interpret the address correctly. It would also be nice
2091 to generate a complaint, but that would require us to maintain
2092 a list of legitimate cases where a non-address form is allowed,
2093 as well as update callers to pass in at least the CU's DWARF
2094 version. This is more overhead than what we're willing to
2095 expand for a pretty rare case. */
2096 addr
= DW_UNSND (attr
);
2099 addr
= DW_ADDR (attr
);
2104 /* See declaration. */
2106 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2107 const dwarf2_debug_sections
*names
)
2108 : objfile (objfile_
)
2111 names
= &dwarf2_elf_names
;
2113 bfd
*obfd
= objfile
->obfd
;
2115 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2116 locate_sections (obfd
, sec
, *names
);
2119 static void free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
);
2121 dwarf2_per_objfile::~dwarf2_per_objfile ()
2123 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2124 free_cached_comp_units ();
2126 if (quick_file_names_table
)
2127 htab_delete (quick_file_names_table
);
2129 if (line_header_hash
)
2130 htab_delete (line_header_hash
);
2132 for (int ix
= 0; ix
< n_comp_units
; ++ix
)
2133 VEC_free (dwarf2_per_cu_ptr
, all_comp_units
[ix
]->imported_symtabs
);
2135 for (int ix
= 0; ix
< n_type_units
; ++ix
)
2136 VEC_free (dwarf2_per_cu_ptr
,
2137 all_type_units
[ix
]->per_cu
.imported_symtabs
);
2138 xfree (all_type_units
);
2140 VEC_free (dwarf2_section_info_def
, types
);
2142 if (dwo_files
!= NULL
)
2143 free_dwo_files (dwo_files
, objfile
);
2144 if (dwp_file
!= NULL
)
2145 gdb_bfd_unref (dwp_file
->dbfd
);
2147 if (dwz_file
!= NULL
&& dwz_file
->dwz_bfd
)
2148 gdb_bfd_unref (dwz_file
->dwz_bfd
);
2150 if (index_table
!= NULL
)
2151 index_table
->~mapped_index ();
2153 /* Everything else should be on the objfile obstack. */
2156 /* See declaration. */
2159 dwarf2_per_objfile::free_cached_comp_units ()
2161 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2162 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2163 while (per_cu
!= NULL
)
2165 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2168 *last_chain
= next_cu
;
2173 /* A helper class that calls free_cached_comp_units on
2176 class free_cached_comp_units
2180 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2181 : m_per_objfile (per_objfile
)
2185 ~free_cached_comp_units ()
2187 m_per_objfile
->free_cached_comp_units ();
2190 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2194 dwarf2_per_objfile
*m_per_objfile
;
2197 /* Try to locate the sections we need for DWARF 2 debugging
2198 information and return true if we have enough to do something.
2199 NAMES points to the dwarf2 section names, or is NULL if the standard
2200 ELF names are used. */
2203 dwarf2_has_info (struct objfile
*objfile
,
2204 const struct dwarf2_debug_sections
*names
)
2206 if (objfile
->flags
& OBJF_READNEVER
)
2209 struct dwarf2_per_objfile
*dwarf2_per_objfile
2210 = get_dwarf2_per_objfile (objfile
);
2212 if (dwarf2_per_objfile
== NULL
)
2214 /* Initialize per-objfile state. */
2216 = new (&objfile
->objfile_obstack
) struct dwarf2_per_objfile (objfile
,
2218 set_dwarf2_per_objfile (objfile
, dwarf2_per_objfile
);
2220 return (!dwarf2_per_objfile
->info
.is_virtual
2221 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2222 && !dwarf2_per_objfile
->abbrev
.is_virtual
2223 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2226 /* Return the containing section of virtual section SECTION. */
2228 static struct dwarf2_section_info
*
2229 get_containing_section (const struct dwarf2_section_info
*section
)
2231 gdb_assert (section
->is_virtual
);
2232 return section
->s
.containing_section
;
2235 /* Return the bfd owner of SECTION. */
2238 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2240 if (section
->is_virtual
)
2242 section
= get_containing_section (section
);
2243 gdb_assert (!section
->is_virtual
);
2245 return section
->s
.section
->owner
;
2248 /* Return the bfd section of SECTION.
2249 Returns NULL if the section is not present. */
2252 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2254 if (section
->is_virtual
)
2256 section
= get_containing_section (section
);
2257 gdb_assert (!section
->is_virtual
);
2259 return section
->s
.section
;
2262 /* Return the name of SECTION. */
2265 get_section_name (const struct dwarf2_section_info
*section
)
2267 asection
*sectp
= get_section_bfd_section (section
);
2269 gdb_assert (sectp
!= NULL
);
2270 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2273 /* Return the name of the file SECTION is in. */
2276 get_section_file_name (const struct dwarf2_section_info
*section
)
2278 bfd
*abfd
= get_section_bfd_owner (section
);
2280 return bfd_get_filename (abfd
);
2283 /* Return the id of SECTION.
2284 Returns 0 if SECTION doesn't exist. */
2287 get_section_id (const struct dwarf2_section_info
*section
)
2289 asection
*sectp
= get_section_bfd_section (section
);
2296 /* Return the flags of SECTION.
2297 SECTION (or containing section if this is a virtual section) must exist. */
2300 get_section_flags (const struct dwarf2_section_info
*section
)
2302 asection
*sectp
= get_section_bfd_section (section
);
2304 gdb_assert (sectp
!= NULL
);
2305 return bfd_get_section_flags (sectp
->owner
, sectp
);
2308 /* When loading sections, we look either for uncompressed section or for
2309 compressed section names. */
2312 section_is_p (const char *section_name
,
2313 const struct dwarf2_section_names
*names
)
2315 if (names
->normal
!= NULL
2316 && strcmp (section_name
, names
->normal
) == 0)
2318 if (names
->compressed
!= NULL
2319 && strcmp (section_name
, names
->compressed
) == 0)
2324 /* See declaration. */
2327 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2328 const dwarf2_debug_sections
&names
)
2330 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2332 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2335 else if (section_is_p (sectp
->name
, &names
.info
))
2337 this->info
.s
.section
= sectp
;
2338 this->info
.size
= bfd_get_section_size (sectp
);
2340 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2342 this->abbrev
.s
.section
= sectp
;
2343 this->abbrev
.size
= bfd_get_section_size (sectp
);
2345 else if (section_is_p (sectp
->name
, &names
.line
))
2347 this->line
.s
.section
= sectp
;
2348 this->line
.size
= bfd_get_section_size (sectp
);
2350 else if (section_is_p (sectp
->name
, &names
.loc
))
2352 this->loc
.s
.section
= sectp
;
2353 this->loc
.size
= bfd_get_section_size (sectp
);
2355 else if (section_is_p (sectp
->name
, &names
.loclists
))
2357 this->loclists
.s
.section
= sectp
;
2358 this->loclists
.size
= bfd_get_section_size (sectp
);
2360 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2362 this->macinfo
.s
.section
= sectp
;
2363 this->macinfo
.size
= bfd_get_section_size (sectp
);
2365 else if (section_is_p (sectp
->name
, &names
.macro
))
2367 this->macro
.s
.section
= sectp
;
2368 this->macro
.size
= bfd_get_section_size (sectp
);
2370 else if (section_is_p (sectp
->name
, &names
.str
))
2372 this->str
.s
.section
= sectp
;
2373 this->str
.size
= bfd_get_section_size (sectp
);
2375 else if (section_is_p (sectp
->name
, &names
.line_str
))
2377 this->line_str
.s
.section
= sectp
;
2378 this->line_str
.size
= bfd_get_section_size (sectp
);
2380 else if (section_is_p (sectp
->name
, &names
.addr
))
2382 this->addr
.s
.section
= sectp
;
2383 this->addr
.size
= bfd_get_section_size (sectp
);
2385 else if (section_is_p (sectp
->name
, &names
.frame
))
2387 this->frame
.s
.section
= sectp
;
2388 this->frame
.size
= bfd_get_section_size (sectp
);
2390 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2392 this->eh_frame
.s
.section
= sectp
;
2393 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2395 else if (section_is_p (sectp
->name
, &names
.ranges
))
2397 this->ranges
.s
.section
= sectp
;
2398 this->ranges
.size
= bfd_get_section_size (sectp
);
2400 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2402 this->rnglists
.s
.section
= sectp
;
2403 this->rnglists
.size
= bfd_get_section_size (sectp
);
2405 else if (section_is_p (sectp
->name
, &names
.types
))
2407 struct dwarf2_section_info type_section
;
2409 memset (&type_section
, 0, sizeof (type_section
));
2410 type_section
.s
.section
= sectp
;
2411 type_section
.size
= bfd_get_section_size (sectp
);
2413 VEC_safe_push (dwarf2_section_info_def
, this->types
,
2416 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2418 this->gdb_index
.s
.section
= sectp
;
2419 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2421 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2423 this->debug_names
.s
.section
= sectp
;
2424 this->debug_names
.size
= bfd_get_section_size (sectp
);
2426 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2428 this->debug_aranges
.s
.section
= sectp
;
2429 this->debug_aranges
.size
= bfd_get_section_size (sectp
);
2432 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2433 && bfd_section_vma (abfd
, sectp
) == 0)
2434 this->has_section_at_zero
= true;
2437 /* A helper function that decides whether a section is empty,
2441 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2443 if (section
->is_virtual
)
2444 return section
->size
== 0;
2445 return section
->s
.section
== NULL
|| section
->size
== 0;
2448 /* See dwarf2read.h. */
2451 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2455 gdb_byte
*buf
, *retbuf
;
2459 info
->buffer
= NULL
;
2462 if (dwarf2_section_empty_p (info
))
2465 sectp
= get_section_bfd_section (info
);
2467 /* If this is a virtual section we need to read in the real one first. */
2468 if (info
->is_virtual
)
2470 struct dwarf2_section_info
*containing_section
=
2471 get_containing_section (info
);
2473 gdb_assert (sectp
!= NULL
);
2474 if ((sectp
->flags
& SEC_RELOC
) != 0)
2476 error (_("Dwarf Error: DWP format V2 with relocations is not"
2477 " supported in section %s [in module %s]"),
2478 get_section_name (info
), get_section_file_name (info
));
2480 dwarf2_read_section (objfile
, containing_section
);
2481 /* Other code should have already caught virtual sections that don't
2483 gdb_assert (info
->virtual_offset
+ info
->size
2484 <= containing_section
->size
);
2485 /* If the real section is empty or there was a problem reading the
2486 section we shouldn't get here. */
2487 gdb_assert (containing_section
->buffer
!= NULL
);
2488 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2492 /* If the section has relocations, we must read it ourselves.
2493 Otherwise we attach it to the BFD. */
2494 if ((sectp
->flags
& SEC_RELOC
) == 0)
2496 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2500 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2503 /* When debugging .o files, we may need to apply relocations; see
2504 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2505 We never compress sections in .o files, so we only need to
2506 try this when the section is not compressed. */
2507 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2510 info
->buffer
= retbuf
;
2514 abfd
= get_section_bfd_owner (info
);
2515 gdb_assert (abfd
!= NULL
);
2517 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2518 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2520 error (_("Dwarf Error: Can't read DWARF data"
2521 " in section %s [in module %s]"),
2522 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2526 /* A helper function that returns the size of a section in a safe way.
2527 If you are positive that the section has been read before using the
2528 size, then it is safe to refer to the dwarf2_section_info object's
2529 "size" field directly. In other cases, you must call this
2530 function, because for compressed sections the size field is not set
2531 correctly until the section has been read. */
2533 static bfd_size_type
2534 dwarf2_section_size (struct objfile
*objfile
,
2535 struct dwarf2_section_info
*info
)
2538 dwarf2_read_section (objfile
, info
);
2542 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2546 dwarf2_get_section_info (struct objfile
*objfile
,
2547 enum dwarf2_section_enum sect
,
2548 asection
**sectp
, const gdb_byte
**bufp
,
2549 bfd_size_type
*sizep
)
2551 struct dwarf2_per_objfile
*data
2552 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2553 dwarf2_objfile_data_key
);
2554 struct dwarf2_section_info
*info
;
2556 /* We may see an objfile without any DWARF, in which case we just
2567 case DWARF2_DEBUG_FRAME
:
2568 info
= &data
->frame
;
2570 case DWARF2_EH_FRAME
:
2571 info
= &data
->eh_frame
;
2574 gdb_assert_not_reached ("unexpected section");
2577 dwarf2_read_section (objfile
, info
);
2579 *sectp
= get_section_bfd_section (info
);
2580 *bufp
= info
->buffer
;
2581 *sizep
= info
->size
;
2584 /* A helper function to find the sections for a .dwz file. */
2587 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2589 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2591 /* Note that we only support the standard ELF names, because .dwz
2592 is ELF-only (at the time of writing). */
2593 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2595 dwz_file
->abbrev
.s
.section
= sectp
;
2596 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2598 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2600 dwz_file
->info
.s
.section
= sectp
;
2601 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2603 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2605 dwz_file
->str
.s
.section
= sectp
;
2606 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2608 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2610 dwz_file
->line
.s
.section
= sectp
;
2611 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2613 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2615 dwz_file
->macro
.s
.section
= sectp
;
2616 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2618 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2620 dwz_file
->gdb_index
.s
.section
= sectp
;
2621 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2623 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2625 dwz_file
->debug_names
.s
.section
= sectp
;
2626 dwz_file
->debug_names
.size
= bfd_get_section_size (sectp
);
2630 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2631 there is no .gnu_debugaltlink section in the file. Error if there
2632 is such a section but the file cannot be found. */
2634 static struct dwz_file
*
2635 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2637 const char *filename
;
2638 struct dwz_file
*result
;
2639 bfd_size_type buildid_len_arg
;
2643 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2644 return dwarf2_per_objfile
->dwz_file
;
2646 bfd_set_error (bfd_error_no_error
);
2647 gdb::unique_xmalloc_ptr
<char> data
2648 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2649 &buildid_len_arg
, &buildid
));
2652 if (bfd_get_error () == bfd_error_no_error
)
2654 error (_("could not read '.gnu_debugaltlink' section: %s"),
2655 bfd_errmsg (bfd_get_error ()));
2658 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2660 buildid_len
= (size_t) buildid_len_arg
;
2662 filename
= data
.get ();
2664 std::string abs_storage
;
2665 if (!IS_ABSOLUTE_PATH (filename
))
2667 gdb::unique_xmalloc_ptr
<char> abs
2668 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2670 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2671 filename
= abs_storage
.c_str ();
2674 /* First try the file name given in the section. If that doesn't
2675 work, try to use the build-id instead. */
2676 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2677 if (dwz_bfd
!= NULL
)
2679 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2683 if (dwz_bfd
== NULL
)
2684 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2686 if (dwz_bfd
== NULL
)
2687 error (_("could not find '.gnu_debugaltlink' file for %s"),
2688 objfile_name (dwarf2_per_objfile
->objfile
));
2690 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2692 result
->dwz_bfd
= dwz_bfd
.release ();
2694 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
2696 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
2697 dwarf2_per_objfile
->dwz_file
= result
;
2701 /* DWARF quick_symbols_functions support. */
2703 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2704 unique line tables, so we maintain a separate table of all .debug_line
2705 derived entries to support the sharing.
2706 All the quick functions need is the list of file names. We discard the
2707 line_header when we're done and don't need to record it here. */
2708 struct quick_file_names
2710 /* The data used to construct the hash key. */
2711 struct stmt_list_hash hash
;
2713 /* The number of entries in file_names, real_names. */
2714 unsigned int num_file_names
;
2716 /* The file names from the line table, after being run through
2718 const char **file_names
;
2720 /* The file names from the line table after being run through
2721 gdb_realpath. These are computed lazily. */
2722 const char **real_names
;
2725 /* When using the index (and thus not using psymtabs), each CU has an
2726 object of this type. This is used to hold information needed by
2727 the various "quick" methods. */
2728 struct dwarf2_per_cu_quick_data
2730 /* The file table. This can be NULL if there was no file table
2731 or it's currently not read in.
2732 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2733 struct quick_file_names
*file_names
;
2735 /* The corresponding symbol table. This is NULL if symbols for this
2736 CU have not yet been read. */
2737 struct compunit_symtab
*compunit_symtab
;
2739 /* A temporary mark bit used when iterating over all CUs in
2740 expand_symtabs_matching. */
2741 unsigned int mark
: 1;
2743 /* True if we've tried to read the file table and found there isn't one.
2744 There will be no point in trying to read it again next time. */
2745 unsigned int no_file_data
: 1;
2748 /* Utility hash function for a stmt_list_hash. */
2751 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2755 if (stmt_list_hash
->dwo_unit
!= NULL
)
2756 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2757 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2761 /* Utility equality function for a stmt_list_hash. */
2764 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2765 const struct stmt_list_hash
*rhs
)
2767 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2769 if (lhs
->dwo_unit
!= NULL
2770 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2773 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2776 /* Hash function for a quick_file_names. */
2779 hash_file_name_entry (const void *e
)
2781 const struct quick_file_names
*file_data
2782 = (const struct quick_file_names
*) e
;
2784 return hash_stmt_list_entry (&file_data
->hash
);
2787 /* Equality function for a quick_file_names. */
2790 eq_file_name_entry (const void *a
, const void *b
)
2792 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2793 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2795 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2798 /* Delete function for a quick_file_names. */
2801 delete_file_name_entry (void *e
)
2803 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2806 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2808 xfree ((void*) file_data
->file_names
[i
]);
2809 if (file_data
->real_names
)
2810 xfree ((void*) file_data
->real_names
[i
]);
2813 /* The space for the struct itself lives on objfile_obstack,
2814 so we don't free it here. */
2817 /* Create a quick_file_names hash table. */
2820 create_quick_file_names_table (unsigned int nr_initial_entries
)
2822 return htab_create_alloc (nr_initial_entries
,
2823 hash_file_name_entry
, eq_file_name_entry
,
2824 delete_file_name_entry
, xcalloc
, xfree
);
2827 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2828 have to be created afterwards. You should call age_cached_comp_units after
2829 processing PER_CU->CU. dw2_setup must have been already called. */
2832 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2834 if (per_cu
->is_debug_types
)
2835 load_full_type_unit (per_cu
);
2837 load_full_comp_unit (per_cu
, language_minimal
);
2839 if (per_cu
->cu
== NULL
)
2840 return; /* Dummy CU. */
2842 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2845 /* Read in the symbols for PER_CU. */
2848 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2850 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2852 /* Skip type_unit_groups, reading the type units they contain
2853 is handled elsewhere. */
2854 if (IS_TYPE_UNIT_GROUP (per_cu
))
2857 /* The destructor of dwarf2_queue_guard frees any entries left on
2858 the queue. After this point we're guaranteed to leave this function
2859 with the dwarf queue empty. */
2860 dwarf2_queue_guard q_guard
;
2862 if (dwarf2_per_objfile
->using_index
2863 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2864 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2866 queue_comp_unit (per_cu
, language_minimal
);
2869 /* If we just loaded a CU from a DWO, and we're working with an index
2870 that may badly handle TUs, load all the TUs in that DWO as well.
2871 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2872 if (!per_cu
->is_debug_types
2873 && per_cu
->cu
!= NULL
2874 && per_cu
->cu
->dwo_unit
!= NULL
2875 && dwarf2_per_objfile
->index_table
!= NULL
2876 && dwarf2_per_objfile
->index_table
->version
<= 7
2877 /* DWP files aren't supported yet. */
2878 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2879 queue_and_load_all_dwo_tus (per_cu
);
2882 process_queue (dwarf2_per_objfile
);
2884 /* Age the cache, releasing compilation units that have not
2885 been used recently. */
2886 age_cached_comp_units (dwarf2_per_objfile
);
2889 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2890 the objfile from which this CU came. Returns the resulting symbol
2893 static struct compunit_symtab
*
2894 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2896 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2898 gdb_assert (dwarf2_per_objfile
->using_index
);
2899 if (!per_cu
->v
.quick
->compunit_symtab
)
2901 free_cached_comp_units
freer (dwarf2_per_objfile
);
2902 scoped_restore decrementer
= increment_reading_symtab ();
2903 dw2_do_instantiate_symtab (per_cu
);
2904 process_cu_includes (dwarf2_per_objfile
);
2907 return per_cu
->v
.quick
->compunit_symtab
;
2910 /* Return the CU/TU given its index.
2912 This is intended for loops like:
2914 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2915 + dwarf2_per_objfile->n_type_units); ++i)
2917 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
2923 static struct dwarf2_per_cu_data
*
2924 dw2_get_cutu (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2927 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2929 index
-= dwarf2_per_objfile
->n_comp_units
;
2930 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2931 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2934 return dwarf2_per_objfile
->all_comp_units
[index
];
2937 /* Return the CU given its index.
2938 This differs from dw2_get_cutu in that it's for when you know INDEX
2941 static struct dwarf2_per_cu_data
*
2942 dw2_get_cu (struct dwarf2_per_objfile
*dwarf2_per_objfile
, int index
)
2944 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
2946 return dwarf2_per_objfile
->all_comp_units
[index
];
2949 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2950 objfile_obstack, and constructed with the specified field
2953 static dwarf2_per_cu_data
*
2954 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2955 struct dwarf2_section_info
*section
,
2957 sect_offset sect_off
, ULONGEST length
)
2959 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2960 dwarf2_per_cu_data
*the_cu
2961 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2962 struct dwarf2_per_cu_data
);
2963 the_cu
->sect_off
= sect_off
;
2964 the_cu
->length
= length
;
2965 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2966 the_cu
->section
= section
;
2967 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2968 struct dwarf2_per_cu_quick_data
);
2969 the_cu
->is_dwz
= is_dwz
;
2973 /* A helper for create_cus_from_index that handles a given list of
2977 create_cus_from_index_list (struct objfile
*objfile
,
2978 const gdb_byte
*cu_list
, offset_type n_elements
,
2979 struct dwarf2_section_info
*section
,
2984 struct dwarf2_per_objfile
*dwarf2_per_objfile
2985 = get_dwarf2_per_objfile (objfile
);
2987 for (i
= 0; i
< n_elements
; i
+= 2)
2989 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2991 sect_offset sect_off
2992 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2993 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2996 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2]
2997 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3002 /* Read the CU list from the mapped index, and use it to create all
3003 the CU objects for this objfile. */
3006 create_cus_from_index (struct objfile
*objfile
,
3007 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3008 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3010 struct dwz_file
*dwz
;
3011 struct dwarf2_per_objfile
*dwarf2_per_objfile
3012 = get_dwarf2_per_objfile (objfile
);
3014 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
3015 dwarf2_per_objfile
->all_comp_units
=
3016 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
3017 dwarf2_per_objfile
->n_comp_units
);
3019 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
3020 &dwarf2_per_objfile
->info
, 0, 0);
3022 if (dwz_elements
== 0)
3025 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3026 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
3027 cu_list_elements
/ 2);
3030 /* Create the signatured type hash table from the index. */
3033 create_signatured_type_table_from_index (struct objfile
*objfile
,
3034 struct dwarf2_section_info
*section
,
3035 const gdb_byte
*bytes
,
3036 offset_type elements
)
3039 htab_t sig_types_hash
;
3040 struct dwarf2_per_objfile
*dwarf2_per_objfile
3041 = get_dwarf2_per_objfile (objfile
);
3043 dwarf2_per_objfile
->n_type_units
3044 = dwarf2_per_objfile
->n_allocated_type_units
3046 dwarf2_per_objfile
->all_type_units
=
3047 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3049 sig_types_hash
= allocate_signatured_type_table (objfile
);
3051 for (i
= 0; i
< elements
; i
+= 3)
3053 struct signatured_type
*sig_type
;
3056 cu_offset type_offset_in_tu
;
3058 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3059 sect_offset sect_off
3060 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3062 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3064 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3067 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3068 struct signatured_type
);
3069 sig_type
->signature
= signature
;
3070 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3071 sig_type
->per_cu
.is_debug_types
= 1;
3072 sig_type
->per_cu
.section
= section
;
3073 sig_type
->per_cu
.sect_off
= sect_off
;
3074 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3075 sig_type
->per_cu
.v
.quick
3076 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3077 struct dwarf2_per_cu_quick_data
);
3079 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3082 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
3085 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3088 /* Create the signatured type hash table from .debug_names. */
3091 create_signatured_type_table_from_debug_names
3092 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3093 const mapped_debug_names
&map
,
3094 struct dwarf2_section_info
*section
,
3095 struct dwarf2_section_info
*abbrev_section
)
3097 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3099 dwarf2_read_section (objfile
, section
);
3100 dwarf2_read_section (objfile
, abbrev_section
);
3102 dwarf2_per_objfile
->n_type_units
3103 = dwarf2_per_objfile
->n_allocated_type_units
3105 dwarf2_per_objfile
->all_type_units
3106 = XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3108 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3110 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3112 struct signatured_type
*sig_type
;
3115 cu_offset type_offset_in_tu
;
3117 sect_offset sect_off
3118 = (sect_offset
) (extract_unsigned_integer
3119 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3121 map
.dwarf5_byte_order
));
3123 comp_unit_head cu_header
;
3124 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3126 section
->buffer
+ to_underlying (sect_off
),
3129 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3130 struct signatured_type
);
3131 sig_type
->signature
= cu_header
.signature
;
3132 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3133 sig_type
->per_cu
.is_debug_types
= 1;
3134 sig_type
->per_cu
.section
= section
;
3135 sig_type
->per_cu
.sect_off
= sect_off
;
3136 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3137 sig_type
->per_cu
.v
.quick
3138 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3139 struct dwarf2_per_cu_quick_data
);
3141 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3144 dwarf2_per_objfile
->all_type_units
[i
] = sig_type
;
3147 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3150 /* Read the address map data from the mapped index, and use it to
3151 populate the objfile's psymtabs_addrmap. */
3154 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3155 struct mapped_index
*index
)
3157 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3158 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3159 const gdb_byte
*iter
, *end
;
3160 struct addrmap
*mutable_map
;
3163 auto_obstack temp_obstack
;
3165 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3167 iter
= index
->address_table
.data ();
3168 end
= iter
+ index
->address_table
.size ();
3170 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3174 ULONGEST hi
, lo
, cu_index
;
3175 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3177 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3179 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3184 complaint (&symfile_complaints
,
3185 _(".gdb_index address table has invalid range (%s - %s)"),
3186 hex_string (lo
), hex_string (hi
));
3190 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
3192 complaint (&symfile_complaints
,
3193 _(".gdb_index address table has invalid CU number %u"),
3194 (unsigned) cu_index
);
3198 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3199 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3200 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3201 dw2_get_cutu (dwarf2_per_objfile
, cu_index
));
3204 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3205 &objfile
->objfile_obstack
);
3208 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3209 populate the objfile's psymtabs_addrmap. */
3212 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3213 struct dwarf2_section_info
*section
)
3215 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3216 bfd
*abfd
= objfile
->obfd
;
3217 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3218 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3219 SECT_OFF_TEXT (objfile
));
3221 auto_obstack temp_obstack
;
3222 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3224 std::unordered_map
<sect_offset
,
3225 dwarf2_per_cu_data
*,
3226 gdb::hash_enum
<sect_offset
>>
3227 debug_info_offset_to_per_cu
;
3228 for (int cui
= 0; cui
< dwarf2_per_objfile
->n_comp_units
; ++cui
)
3230 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cui
);
3231 const auto insertpair
3232 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3233 if (!insertpair
.second
)
3235 warning (_("Section .debug_aranges in %s has duplicate "
3236 "debug_info_offset %s, ignoring .debug_aranges."),
3237 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3242 dwarf2_read_section (objfile
, section
);
3244 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3246 const gdb_byte
*addr
= section
->buffer
;
3248 while (addr
< section
->buffer
+ section
->size
)
3250 const gdb_byte
*const entry_addr
= addr
;
3251 unsigned int bytes_read
;
3253 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3257 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3258 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3259 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3260 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3262 warning (_("Section .debug_aranges in %s entry at offset %zu "
3263 "length %s exceeds section length %s, "
3264 "ignoring .debug_aranges."),
3265 objfile_name (objfile
), entry_addr
- section
->buffer
,
3266 plongest (bytes_read
+ entry_length
),
3267 pulongest (section
->size
));
3271 /* The version number. */
3272 const uint16_t version
= read_2_bytes (abfd
, addr
);
3276 warning (_("Section .debug_aranges in %s entry at offset %zu "
3277 "has unsupported version %d, ignoring .debug_aranges."),
3278 objfile_name (objfile
), entry_addr
- section
->buffer
,
3283 const uint64_t debug_info_offset
3284 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3285 addr
+= offset_size
;
3286 const auto per_cu_it
3287 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3288 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3290 warning (_("Section .debug_aranges in %s entry at offset %zu "
3291 "debug_info_offset %s does not exists, "
3292 "ignoring .debug_aranges."),
3293 objfile_name (objfile
), entry_addr
- section
->buffer
,
3294 pulongest (debug_info_offset
));
3297 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3299 const uint8_t address_size
= *addr
++;
3300 if (address_size
< 1 || address_size
> 8)
3302 warning (_("Section .debug_aranges in %s entry at offset %zu "
3303 "address_size %u is invalid, ignoring .debug_aranges."),
3304 objfile_name (objfile
), entry_addr
- section
->buffer
,
3309 const uint8_t segment_selector_size
= *addr
++;
3310 if (segment_selector_size
!= 0)
3312 warning (_("Section .debug_aranges in %s entry at offset %zu "
3313 "segment_selector_size %u is not supported, "
3314 "ignoring .debug_aranges."),
3315 objfile_name (objfile
), entry_addr
- section
->buffer
,
3316 segment_selector_size
);
3320 /* Must pad to an alignment boundary that is twice the address
3321 size. It is undocumented by the DWARF standard but GCC does
3323 for (size_t padding
= ((-(addr
- section
->buffer
))
3324 & (2 * address_size
- 1));
3325 padding
> 0; padding
--)
3328 warning (_("Section .debug_aranges in %s entry at offset %zu "
3329 "padding is not zero, ignoring .debug_aranges."),
3330 objfile_name (objfile
), entry_addr
- section
->buffer
);
3336 if (addr
+ 2 * address_size
> entry_end
)
3338 warning (_("Section .debug_aranges in %s entry at offset %zu "
3339 "address list is not properly terminated, "
3340 "ignoring .debug_aranges."),
3341 objfile_name (objfile
), entry_addr
- section
->buffer
);
3344 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3346 addr
+= address_size
;
3347 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3349 addr
+= address_size
;
3350 if (start
== 0 && length
== 0)
3352 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3354 /* Symbol was eliminated due to a COMDAT group. */
3357 ULONGEST end
= start
+ length
;
3358 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
);
3359 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
);
3360 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3364 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3365 &objfile
->objfile_obstack
);
3368 /* Find a slot in the mapped index INDEX for the object named NAME.
3369 If NAME is found, set *VEC_OUT to point to the CU vector in the
3370 constant pool and return true. If NAME cannot be found, return
3374 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3375 offset_type
**vec_out
)
3378 offset_type slot
, step
;
3379 int (*cmp
) (const char *, const char *);
3381 gdb::unique_xmalloc_ptr
<char> without_params
;
3382 if (current_language
->la_language
== language_cplus
3383 || current_language
->la_language
== language_fortran
3384 || current_language
->la_language
== language_d
)
3386 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3389 if (strchr (name
, '(') != NULL
)
3391 without_params
= cp_remove_params (name
);
3393 if (without_params
!= NULL
)
3394 name
= without_params
.get ();
3398 /* Index version 4 did not support case insensitive searches. But the
3399 indices for case insensitive languages are built in lowercase, therefore
3400 simulate our NAME being searched is also lowercased. */
3401 hash
= mapped_index_string_hash ((index
->version
== 4
3402 && case_sensitivity
== case_sensitive_off
3403 ? 5 : index
->version
),
3406 slot
= hash
& (index
->symbol_table
.size () - 1);
3407 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3408 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3414 const auto &bucket
= index
->symbol_table
[slot
];
3415 if (bucket
.name
== 0 && bucket
.vec
== 0)
3418 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3419 if (!cmp (name
, str
))
3421 *vec_out
= (offset_type
*) (index
->constant_pool
3422 + MAYBE_SWAP (bucket
.vec
));
3426 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3430 /* A helper function that reads the .gdb_index from SECTION and fills
3431 in MAP. FILENAME is the name of the file containing the section;
3432 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3433 ok to use deprecated sections.
3435 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3436 out parameters that are filled in with information about the CU and
3437 TU lists in the section.
3439 Returns 1 if all went well, 0 otherwise. */
3442 read_index_from_section (struct objfile
*objfile
,
3443 const char *filename
,
3445 struct dwarf2_section_info
*section
,
3446 struct mapped_index
*map
,
3447 const gdb_byte
**cu_list
,
3448 offset_type
*cu_list_elements
,
3449 const gdb_byte
**types_list
,
3450 offset_type
*types_list_elements
)
3452 const gdb_byte
*addr
;
3453 offset_type version
;
3454 offset_type
*metadata
;
3457 if (dwarf2_section_empty_p (section
))
3460 /* Older elfutils strip versions could keep the section in the main
3461 executable while splitting it for the separate debug info file. */
3462 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3465 dwarf2_read_section (objfile
, section
);
3467 addr
= section
->buffer
;
3468 /* Version check. */
3469 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3470 /* Versions earlier than 3 emitted every copy of a psymbol. This
3471 causes the index to behave very poorly for certain requests. Version 3
3472 contained incomplete addrmap. So, it seems better to just ignore such
3476 static int warning_printed
= 0;
3477 if (!warning_printed
)
3479 warning (_("Skipping obsolete .gdb_index section in %s."),
3481 warning_printed
= 1;
3485 /* Index version 4 uses a different hash function than index version
3488 Versions earlier than 6 did not emit psymbols for inlined
3489 functions. Using these files will cause GDB not to be able to
3490 set breakpoints on inlined functions by name, so we ignore these
3491 indices unless the user has done
3492 "set use-deprecated-index-sections on". */
3493 if (version
< 6 && !deprecated_ok
)
3495 static int warning_printed
= 0;
3496 if (!warning_printed
)
3499 Skipping deprecated .gdb_index section in %s.\n\
3500 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3501 to use the section anyway."),
3503 warning_printed
= 1;
3507 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3508 of the TU (for symbols coming from TUs),
3509 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3510 Plus gold-generated indices can have duplicate entries for global symbols,
3511 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3512 These are just performance bugs, and we can't distinguish gdb-generated
3513 indices from gold-generated ones, so issue no warning here. */
3515 /* Indexes with higher version than the one supported by GDB may be no
3516 longer backward compatible. */
3520 map
->version
= version
;
3521 map
->total_size
= section
->size
;
3523 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3526 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3527 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3531 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3532 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3533 - MAYBE_SWAP (metadata
[i
]))
3537 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3538 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3540 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3543 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3544 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3546 = gdb::array_view
<mapped_index::symbol_table_slot
>
3547 ((mapped_index::symbol_table_slot
*) symbol_table
,
3548 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3551 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3556 /* Read .gdb_index. If everything went ok, initialize the "quick"
3557 elements of all the CUs and return 1. Otherwise, return 0. */
3560 dwarf2_read_index (struct objfile
*objfile
)
3562 struct mapped_index local_map
, *map
;
3563 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3564 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3565 struct dwz_file
*dwz
;
3566 struct dwarf2_per_objfile
*dwarf2_per_objfile
3567 = get_dwarf2_per_objfile (objfile
);
3569 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3570 use_deprecated_index_sections
,
3571 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3572 &cu_list
, &cu_list_elements
,
3573 &types_list
, &types_list_elements
))
3576 /* Don't use the index if it's empty. */
3577 if (local_map
.symbol_table
.empty ())
3580 /* If there is a .dwz file, read it so we can get its CU list as
3582 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3585 struct mapped_index dwz_map
;
3586 const gdb_byte
*dwz_types_ignore
;
3587 offset_type dwz_types_elements_ignore
;
3589 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3591 &dwz
->gdb_index
, &dwz_map
,
3592 &dwz_list
, &dwz_list_elements
,
3594 &dwz_types_elements_ignore
))
3596 warning (_("could not read '.gdb_index' section from %s; skipping"),
3597 bfd_get_filename (dwz
->dwz_bfd
));
3602 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3605 if (types_list_elements
)
3607 struct dwarf2_section_info
*section
;
3609 /* We can only handle a single .debug_types when we have an
3611 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3614 section
= VEC_index (dwarf2_section_info_def
,
3615 dwarf2_per_objfile
->types
, 0);
3617 create_signatured_type_table_from_index (objfile
, section
, types_list
,
3618 types_list_elements
);
3621 create_addrmap_from_index (dwarf2_per_objfile
, &local_map
);
3623 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3624 map
= new (map
) mapped_index ();
3627 dwarf2_per_objfile
->index_table
= map
;
3628 dwarf2_per_objfile
->using_index
= 1;
3629 dwarf2_per_objfile
->quick_file_names_table
=
3630 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3635 /* die_reader_func for dw2_get_file_names. */
3638 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3639 const gdb_byte
*info_ptr
,
3640 struct die_info
*comp_unit_die
,
3644 struct dwarf2_cu
*cu
= reader
->cu
;
3645 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3646 struct dwarf2_per_objfile
*dwarf2_per_objfile
3647 = cu
->per_cu
->dwarf2_per_objfile
;
3648 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3649 struct dwarf2_per_cu_data
*lh_cu
;
3650 struct attribute
*attr
;
3653 struct quick_file_names
*qfn
;
3655 gdb_assert (! this_cu
->is_debug_types
);
3657 /* Our callers never want to match partial units -- instead they
3658 will match the enclosing full CU. */
3659 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3661 this_cu
->v
.quick
->no_file_data
= 1;
3669 sect_offset line_offset
{};
3671 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3674 struct quick_file_names find_entry
;
3676 line_offset
= (sect_offset
) DW_UNSND (attr
);
3678 /* We may have already read in this line header (TU line header sharing).
3679 If we have we're done. */
3680 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3681 find_entry
.hash
.line_sect_off
= line_offset
;
3682 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3683 &find_entry
, INSERT
);
3686 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3690 lh
= dwarf_decode_line_header (line_offset
, cu
);
3694 lh_cu
->v
.quick
->no_file_data
= 1;
3698 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3699 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3700 qfn
->hash
.line_sect_off
= line_offset
;
3701 gdb_assert (slot
!= NULL
);
3704 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3706 qfn
->num_file_names
= lh
->file_names
.size ();
3708 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
3709 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3710 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3711 qfn
->real_names
= NULL
;
3713 lh_cu
->v
.quick
->file_names
= qfn
;
3716 /* A helper for the "quick" functions which attempts to read the line
3717 table for THIS_CU. */
3719 static struct quick_file_names
*
3720 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3722 /* This should never be called for TUs. */
3723 gdb_assert (! this_cu
->is_debug_types
);
3724 /* Nor type unit groups. */
3725 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3727 if (this_cu
->v
.quick
->file_names
!= NULL
)
3728 return this_cu
->v
.quick
->file_names
;
3729 /* If we know there is no line data, no point in looking again. */
3730 if (this_cu
->v
.quick
->no_file_data
)
3733 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3735 if (this_cu
->v
.quick
->no_file_data
)
3737 return this_cu
->v
.quick
->file_names
;
3740 /* A helper for the "quick" functions which computes and caches the
3741 real path for a given file name from the line table. */
3744 dw2_get_real_path (struct objfile
*objfile
,
3745 struct quick_file_names
*qfn
, int index
)
3747 if (qfn
->real_names
== NULL
)
3748 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3749 qfn
->num_file_names
, const char *);
3751 if (qfn
->real_names
[index
] == NULL
)
3752 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3754 return qfn
->real_names
[index
];
3757 static struct symtab
*
3758 dw2_find_last_source_symtab (struct objfile
*objfile
)
3760 struct dwarf2_per_objfile
*dwarf2_per_objfile
3761 = get_dwarf2_per_objfile (objfile
);
3762 int index
= dwarf2_per_objfile
->n_comp_units
- 1;
3763 dwarf2_per_cu_data
*dwarf_cu
= dw2_get_cutu (dwarf2_per_objfile
, index
);
3764 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
);
3769 return compunit_primary_filetab (cust
);
3772 /* Traversal function for dw2_forget_cached_source_info. */
3775 dw2_free_cached_file_names (void **slot
, void *info
)
3777 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3779 if (file_data
->real_names
)
3783 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3785 xfree ((void*) file_data
->real_names
[i
]);
3786 file_data
->real_names
[i
] = NULL
;
3794 dw2_forget_cached_source_info (struct objfile
*objfile
)
3796 struct dwarf2_per_objfile
*dwarf2_per_objfile
3797 = get_dwarf2_per_objfile (objfile
);
3799 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3800 dw2_free_cached_file_names
, NULL
);
3803 /* Helper function for dw2_map_symtabs_matching_filename that expands
3804 the symtabs and calls the iterator. */
3807 dw2_map_expand_apply (struct objfile
*objfile
,
3808 struct dwarf2_per_cu_data
*per_cu
,
3809 const char *name
, const char *real_path
,
3810 gdb::function_view
<bool (symtab
*)> callback
)
3812 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3814 /* Don't visit already-expanded CUs. */
3815 if (per_cu
->v
.quick
->compunit_symtab
)
3818 /* This may expand more than one symtab, and we want to iterate over
3820 dw2_instantiate_symtab (per_cu
);
3822 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3823 last_made
, callback
);
3826 /* Implementation of the map_symtabs_matching_filename method. */
3829 dw2_map_symtabs_matching_filename
3830 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3831 gdb::function_view
<bool (symtab
*)> callback
)
3834 const char *name_basename
= lbasename (name
);
3835 struct dwarf2_per_objfile
*dwarf2_per_objfile
3836 = get_dwarf2_per_objfile (objfile
);
3838 /* The rule is CUs specify all the files, including those used by
3839 any TU, so there's no need to scan TUs here. */
3841 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3844 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
3845 struct quick_file_names
*file_data
;
3847 /* We only need to look at symtabs not already expanded. */
3848 if (per_cu
->v
.quick
->compunit_symtab
)
3851 file_data
= dw2_get_file_names (per_cu
);
3852 if (file_data
== NULL
)
3855 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3857 const char *this_name
= file_data
->file_names
[j
];
3858 const char *this_real_name
;
3860 if (compare_filenames_for_search (this_name
, name
))
3862 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3868 /* Before we invoke realpath, which can get expensive when many
3869 files are involved, do a quick comparison of the basenames. */
3870 if (! basenames_may_differ
3871 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3874 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3875 if (compare_filenames_for_search (this_real_name
, name
))
3877 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3883 if (real_path
!= NULL
)
3885 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3886 gdb_assert (IS_ABSOLUTE_PATH (name
));
3887 if (this_real_name
!= NULL
3888 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3890 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3902 /* Struct used to manage iterating over all CUs looking for a symbol. */
3904 struct dw2_symtab_iterator
3906 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3907 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3908 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3909 int want_specific_block
;
3910 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3911 Unused if !WANT_SPECIFIC_BLOCK. */
3913 /* The kind of symbol we're looking for. */
3915 /* The list of CUs from the index entry of the symbol,
3916 or NULL if not found. */
3918 /* The next element in VEC to look at. */
3920 /* The number of elements in VEC, or zero if there is no match. */
3922 /* Have we seen a global version of the symbol?
3923 If so we can ignore all further global instances.
3924 This is to work around gold/15646, inefficient gold-generated
3929 /* Initialize the index symtab iterator ITER.
3930 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3931 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3934 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3935 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3936 int want_specific_block
,
3941 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3942 iter
->want_specific_block
= want_specific_block
;
3943 iter
->block_index
= block_index
;
3944 iter
->domain
= domain
;
3946 iter
->global_seen
= 0;
3948 mapped_index
*index
= dwarf2_per_objfile
->index_table
;
3950 /* index is NULL if OBJF_READNOW. */
3951 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3952 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3960 /* Return the next matching CU or NULL if there are no more. */
3962 static struct dwarf2_per_cu_data
*
3963 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3965 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3967 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3969 offset_type cu_index_and_attrs
=
3970 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3971 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3972 struct dwarf2_per_cu_data
*per_cu
;
3973 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3974 /* This value is only valid for index versions >= 7. */
3975 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3976 gdb_index_symbol_kind symbol_kind
=
3977 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3978 /* Only check the symbol attributes if they're present.
3979 Indices prior to version 7 don't record them,
3980 and indices >= 7 may elide them for certain symbols
3981 (gold does this). */
3983 (dwarf2_per_objfile
->index_table
->version
>= 7
3984 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3986 /* Don't crash on bad data. */
3987 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3988 + dwarf2_per_objfile
->n_type_units
))
3990 complaint (&symfile_complaints
,
3991 _(".gdb_index entry has bad CU index"
3993 objfile_name (dwarf2_per_objfile
->objfile
));
3997 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cu_index
);
3999 /* Skip if already read in. */
4000 if (per_cu
->v
.quick
->compunit_symtab
)
4003 /* Check static vs global. */
4006 if (iter
->want_specific_block
4007 && want_static
!= is_static
)
4009 /* Work around gold/15646. */
4010 if (!is_static
&& iter
->global_seen
)
4013 iter
->global_seen
= 1;
4016 /* Only check the symbol's kind if it has one. */
4019 switch (iter
->domain
)
4022 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4023 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4024 /* Some types are also in VAR_DOMAIN. */
4025 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4029 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4033 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4048 static struct compunit_symtab
*
4049 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
4050 const char *name
, domain_enum domain
)
4052 struct compunit_symtab
*stab_best
= NULL
;
4053 struct dwarf2_per_objfile
*dwarf2_per_objfile
4054 = get_dwarf2_per_objfile (objfile
);
4056 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4058 struct dw2_symtab_iterator iter
;
4059 struct dwarf2_per_cu_data
*per_cu
;
4061 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 1, block_index
, domain
, name
);
4063 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4065 struct symbol
*sym
, *with_opaque
= NULL
;
4066 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
4067 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4068 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4070 sym
= block_find_symbol (block
, name
, domain
,
4071 block_find_non_opaque_type_preferred
,
4074 /* Some caution must be observed with overloaded functions
4075 and methods, since the index will not contain any overload
4076 information (but NAME might contain it). */
4079 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4081 if (with_opaque
!= NULL
4082 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4085 /* Keep looking through other CUs. */
4092 dw2_print_stats (struct objfile
*objfile
)
4094 struct dwarf2_per_objfile
*dwarf2_per_objfile
4095 = get_dwarf2_per_objfile (objfile
);
4096 int total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
4099 for (int i
= 0; i
< total
; ++i
)
4101 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
4103 if (!per_cu
->v
.quick
->compunit_symtab
)
4106 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4107 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4110 /* This dumps minimal information about the index.
4111 It is called via "mt print objfiles".
4112 One use is to verify .gdb_index has been loaded by the
4113 gdb.dwarf2/gdb-index.exp testcase. */
4116 dw2_dump (struct objfile
*objfile
)
4118 struct dwarf2_per_objfile
*dwarf2_per_objfile
4119 = get_dwarf2_per_objfile (objfile
);
4121 gdb_assert (dwarf2_per_objfile
->using_index
);
4122 printf_filtered (".gdb_index:");
4123 if (dwarf2_per_objfile
->index_table
!= NULL
)
4125 printf_filtered (" version %d\n",
4126 dwarf2_per_objfile
->index_table
->version
);
4129 printf_filtered (" faked for \"readnow\"\n");
4130 printf_filtered ("\n");
4134 dw2_relocate (struct objfile
*objfile
,
4135 const struct section_offsets
*new_offsets
,
4136 const struct section_offsets
*delta
)
4138 /* There's nothing to relocate here. */
4142 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4143 const char *func_name
)
4145 struct dwarf2_per_objfile
*dwarf2_per_objfile
4146 = get_dwarf2_per_objfile (objfile
);
4148 struct dw2_symtab_iterator iter
;
4149 struct dwarf2_per_cu_data
*per_cu
;
4151 /* Note: It doesn't matter what we pass for block_index here. */
4152 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
4155 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4156 dw2_instantiate_symtab (per_cu
);
4161 dw2_expand_all_symtabs (struct objfile
*objfile
)
4163 struct dwarf2_per_objfile
*dwarf2_per_objfile
4164 = get_dwarf2_per_objfile (objfile
);
4165 int total_units
= (dwarf2_per_objfile
->n_comp_units
4166 + dwarf2_per_objfile
->n_type_units
);
4168 for (int i
= 0; i
< total_units
; ++i
)
4170 struct dwarf2_per_cu_data
*per_cu
4171 = dw2_get_cutu (dwarf2_per_objfile
, i
);
4173 dw2_instantiate_symtab (per_cu
);
4178 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4179 const char *fullname
)
4181 struct dwarf2_per_objfile
*dwarf2_per_objfile
4182 = get_dwarf2_per_objfile (objfile
);
4184 /* We don't need to consider type units here.
4185 This is only called for examining code, e.g. expand_line_sal.
4186 There can be an order of magnitude (or more) more type units
4187 than comp units, and we avoid them if we can. */
4189 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4192 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
4193 struct quick_file_names
*file_data
;
4195 /* We only need to look at symtabs not already expanded. */
4196 if (per_cu
->v
.quick
->compunit_symtab
)
4199 file_data
= dw2_get_file_names (per_cu
);
4200 if (file_data
== NULL
)
4203 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4205 const char *this_fullname
= file_data
->file_names
[j
];
4207 if (filename_cmp (this_fullname
, fullname
) == 0)
4209 dw2_instantiate_symtab (per_cu
);
4217 dw2_map_matching_symbols (struct objfile
*objfile
,
4218 const char * name
, domain_enum domain
,
4220 int (*callback
) (struct block
*,
4221 struct symbol
*, void *),
4222 void *data
, symbol_name_match_type match
,
4223 symbol_compare_ftype
*ordered_compare
)
4225 /* Currently unimplemented; used for Ada. The function can be called if the
4226 current language is Ada for a non-Ada objfile using GNU index. As Ada
4227 does not look for non-Ada symbols this function should just return. */
4230 /* Symbol name matcher for .gdb_index names.
4232 Symbol names in .gdb_index have a few particularities:
4234 - There's no indication of which is the language of each symbol.
4236 Since each language has its own symbol name matching algorithm,
4237 and we don't know which language is the right one, we must match
4238 each symbol against all languages. This would be a potential
4239 performance problem if it were not mitigated by the
4240 mapped_index::name_components lookup table, which significantly
4241 reduces the number of times we need to call into this matcher,
4242 making it a non-issue.
4244 - Symbol names in the index have no overload (parameter)
4245 information. I.e., in C++, "foo(int)" and "foo(long)" both
4246 appear as "foo" in the index, for example.
4248 This means that the lookup names passed to the symbol name
4249 matcher functions must have no parameter information either
4250 because (e.g.) symbol search name "foo" does not match
4251 lookup-name "foo(int)" [while swapping search name for lookup
4254 class gdb_index_symbol_name_matcher
4257 /* Prepares the vector of comparison functions for LOOKUP_NAME. */
4258 gdb_index_symbol_name_matcher (const lookup_name_info
&lookup_name
);
4260 /* Walk all the matcher routines and match SYMBOL_NAME against them.
4261 Returns true if any matcher matches. */
4262 bool matches (const char *symbol_name
);
4265 /* A reference to the lookup name we're matching against. */
4266 const lookup_name_info
&m_lookup_name
;
4268 /* A vector holding all the different symbol name matchers, for all
4270 std::vector
<symbol_name_matcher_ftype
*> m_symbol_name_matcher_funcs
;
4273 gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
4274 (const lookup_name_info
&lookup_name
)
4275 : m_lookup_name (lookup_name
)
4277 /* Prepare the vector of comparison functions upfront, to avoid
4278 doing the same work for each symbol. Care is taken to avoid
4279 matching with the same matcher more than once if/when multiple
4280 languages use the same matcher function. */
4281 auto &matchers
= m_symbol_name_matcher_funcs
;
4282 matchers
.reserve (nr_languages
);
4284 matchers
.push_back (default_symbol_name_matcher
);
4286 for (int i
= 0; i
< nr_languages
; i
++)
4288 const language_defn
*lang
= language_def ((enum language
) i
);
4289 symbol_name_matcher_ftype
*name_matcher
4290 = get_symbol_name_matcher (lang
, m_lookup_name
);
4292 /* Don't insert the same comparison routine more than once.
4293 Note that we do this linear walk instead of a seemingly
4294 cheaper sorted insert, or use a std::set or something like
4295 that, because relative order of function addresses is not
4296 stable. This is not a problem in practice because the number
4297 of supported languages is low, and the cost here is tiny
4298 compared to the number of searches we'll do afterwards using
4300 if (name_matcher
!= default_symbol_name_matcher
4301 && (std::find (matchers
.begin (), matchers
.end (), name_matcher
)
4302 == matchers
.end ()))
4303 matchers
.push_back (name_matcher
);
4308 gdb_index_symbol_name_matcher::matches (const char *symbol_name
)
4310 for (auto matches_name
: m_symbol_name_matcher_funcs
)
4311 if (matches_name (symbol_name
, m_lookup_name
, NULL
))
4317 /* Starting from a search name, return the string that finds the upper
4318 bound of all strings that start with SEARCH_NAME in a sorted name
4319 list. Returns the empty string to indicate that the upper bound is
4320 the end of the list. */
4323 make_sort_after_prefix_name (const char *search_name
)
4325 /* When looking to complete "func", we find the upper bound of all
4326 symbols that start with "func" by looking for where we'd insert
4327 the closest string that would follow "func" in lexicographical
4328 order. Usually, that's "func"-with-last-character-incremented,
4329 i.e. "fund". Mind non-ASCII characters, though. Usually those
4330 will be UTF-8 multi-byte sequences, but we can't be certain.
4331 Especially mind the 0xff character, which is a valid character in
4332 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4333 rule out compilers allowing it in identifiers. Note that
4334 conveniently, strcmp/strcasecmp are specified to compare
4335 characters interpreted as unsigned char. So what we do is treat
4336 the whole string as a base 256 number composed of a sequence of
4337 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4338 to 0, and carries 1 to the following more-significant position.
4339 If the very first character in SEARCH_NAME ends up incremented
4340 and carries/overflows, then the upper bound is the end of the
4341 list. The string after the empty string is also the empty
4344 Some examples of this operation:
4346 SEARCH_NAME => "+1" RESULT
4350 "\xff" "a" "\xff" => "\xff" "b"
4355 Then, with these symbols for example:
4361 completing "func" looks for symbols between "func" and
4362 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4363 which finds "func" and "func1", but not "fund".
4367 funcÿ (Latin1 'ÿ' [0xff])
4371 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4372 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4376 ÿÿ (Latin1 'ÿ' [0xff])
4379 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4380 the end of the list.
4382 std::string after
= search_name
;
4383 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4385 if (!after
.empty ())
4386 after
.back () = (unsigned char) after
.back () + 1;
4390 /* See declaration. */
4392 std::pair
<std::vector
<name_component
>::const_iterator
,
4393 std::vector
<name_component
>::const_iterator
>
4394 mapped_index_base::find_name_components_bounds
4395 (const lookup_name_info
&lookup_name_without_params
) const
4398 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4401 = lookup_name_without_params
.cplus ().lookup_name ().c_str ();
4403 /* Comparison function object for lower_bound that matches against a
4404 given symbol name. */
4405 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4408 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4409 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4410 return name_cmp (elem_name
, name
) < 0;
4413 /* Comparison function object for upper_bound that matches against a
4414 given symbol name. */
4415 auto lookup_compare_upper
= [&] (const char *name
,
4416 const name_component
&elem
)
4418 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4419 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4420 return name_cmp (name
, elem_name
) < 0;
4423 auto begin
= this->name_components
.begin ();
4424 auto end
= this->name_components
.end ();
4426 /* Find the lower bound. */
4429 if (lookup_name_without_params
.completion_mode () && cplus
[0] == '\0')
4432 return std::lower_bound (begin
, end
, cplus
, lookup_compare_lower
);
4435 /* Find the upper bound. */
4438 if (lookup_name_without_params
.completion_mode ())
4440 /* In completion mode, we want UPPER to point past all
4441 symbols names that have the same prefix. I.e., with
4442 these symbols, and completing "func":
4444 function << lower bound
4446 other_function << upper bound
4448 We find the upper bound by looking for the insertion
4449 point of "func"-with-last-character-incremented,
4451 std::string after
= make_sort_after_prefix_name (cplus
);
4454 return std::lower_bound (lower
, end
, after
.c_str (),
4455 lookup_compare_lower
);
4458 return std::upper_bound (lower
, end
, cplus
, lookup_compare_upper
);
4461 return {lower
, upper
};
4464 /* See declaration. */
4467 mapped_index_base::build_name_components ()
4469 if (!this->name_components
.empty ())
4472 this->name_components_casing
= case_sensitivity
;
4474 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4476 /* The code below only knows how to break apart components of C++
4477 symbol names (and other languages that use '::' as
4478 namespace/module separator). If we add support for wild matching
4479 to some language that uses some other operator (E.g., Ada, Go and
4480 D use '.'), then we'll need to try splitting the symbol name
4481 according to that language too. Note that Ada does support wild
4482 matching, but doesn't currently support .gdb_index. */
4483 auto count
= this->symbol_name_count ();
4484 for (offset_type idx
= 0; idx
< count
; idx
++)
4486 if (this->symbol_name_slot_invalid (idx
))
4489 const char *name
= this->symbol_name_at (idx
);
4491 /* Add each name component to the name component table. */
4492 unsigned int previous_len
= 0;
4493 for (unsigned int current_len
= cp_find_first_component (name
);
4494 name
[current_len
] != '\0';
4495 current_len
+= cp_find_first_component (name
+ current_len
))
4497 gdb_assert (name
[current_len
] == ':');
4498 this->name_components
.push_back ({previous_len
, idx
});
4499 /* Skip the '::'. */
4501 previous_len
= current_len
;
4503 this->name_components
.push_back ({previous_len
, idx
});
4506 /* Sort name_components elements by name. */
4507 auto name_comp_compare
= [&] (const name_component
&left
,
4508 const name_component
&right
)
4510 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4511 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4513 const char *left_name
= left_qualified
+ left
.name_offset
;
4514 const char *right_name
= right_qualified
+ right
.name_offset
;
4516 return name_cmp (left_name
, right_name
) < 0;
4519 std::sort (this->name_components
.begin (),
4520 this->name_components
.end (),
4524 /* Helper for dw2_expand_symtabs_matching that works with a
4525 mapped_index_base instead of the containing objfile. This is split
4526 to a separate function in order to be able to unit test the
4527 name_components matching using a mock mapped_index_base. For each
4528 symbol name that matches, calls MATCH_CALLBACK, passing it the
4529 symbol's index in the mapped_index_base symbol table. */
4532 dw2_expand_symtabs_matching_symbol
4533 (mapped_index_base
&index
,
4534 const lookup_name_info
&lookup_name_in
,
4535 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4536 enum search_domain kind
,
4537 gdb::function_view
<void (offset_type
)> match_callback
)
4539 lookup_name_info lookup_name_without_params
4540 = lookup_name_in
.make_ignore_params ();
4541 gdb_index_symbol_name_matcher lookup_name_matcher
4542 (lookup_name_without_params
);
4544 /* Build the symbol name component sorted vector, if we haven't
4546 index
.build_name_components ();
4548 auto bounds
= index
.find_name_components_bounds (lookup_name_without_params
);
4550 /* Now for each symbol name in range, check to see if we have a name
4551 match, and if so, call the MATCH_CALLBACK callback. */
4553 /* The same symbol may appear more than once in the range though.
4554 E.g., if we're looking for symbols that complete "w", and we have
4555 a symbol named "w1::w2", we'll find the two name components for
4556 that same symbol in the range. To be sure we only call the
4557 callback once per symbol, we first collect the symbol name
4558 indexes that matched in a temporary vector and ignore
4560 std::vector
<offset_type
> matches
;
4561 matches
.reserve (std::distance (bounds
.first
, bounds
.second
));
4563 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4565 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4567 if (!lookup_name_matcher
.matches (qualified
)
4568 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4571 matches
.push_back (bounds
.first
->idx
);
4574 std::sort (matches
.begin (), matches
.end ());
4576 /* Finally call the callback, once per match. */
4578 for (offset_type idx
: matches
)
4582 match_callback (idx
);
4587 /* Above we use a type wider than idx's for 'prev', since 0 and
4588 (offset_type)-1 are both possible values. */
4589 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4594 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4596 /* A mock .gdb_index/.debug_names-like name index table, enough to
4597 exercise dw2_expand_symtabs_matching_symbol, which works with the
4598 mapped_index_base interface. Builds an index from the symbol list
4599 passed as parameter to the constructor. */
4600 class mock_mapped_index
: public mapped_index_base
4603 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4604 : m_symbol_table (symbols
)
4607 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4609 /* Return the number of names in the symbol table. */
4610 virtual size_t symbol_name_count () const
4612 return m_symbol_table
.size ();
4615 /* Get the name of the symbol at IDX in the symbol table. */
4616 virtual const char *symbol_name_at (offset_type idx
) const
4618 return m_symbol_table
[idx
];
4622 gdb::array_view
<const char *> m_symbol_table
;
4625 /* Convenience function that converts a NULL pointer to a "<null>"
4626 string, to pass to print routines. */
4629 string_or_null (const char *str
)
4631 return str
!= NULL
? str
: "<null>";
4634 /* Check if a lookup_name_info built from
4635 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4636 index. EXPECTED_LIST is the list of expected matches, in expected
4637 matching order. If no match expected, then an empty list is
4638 specified. Returns true on success. On failure prints a warning
4639 indicating the file:line that failed, and returns false. */
4642 check_match (const char *file
, int line
,
4643 mock_mapped_index
&mock_index
,
4644 const char *name
, symbol_name_match_type match_type
,
4645 bool completion_mode
,
4646 std::initializer_list
<const char *> expected_list
)
4648 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4650 bool matched
= true;
4652 auto mismatch
= [&] (const char *expected_str
,
4655 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4656 "expected=\"%s\", got=\"%s\"\n"),
4658 (match_type
== symbol_name_match_type::FULL
4660 name
, string_or_null (expected_str
), string_or_null (got
));
4664 auto expected_it
= expected_list
.begin ();
4665 auto expected_end
= expected_list
.end ();
4667 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4669 [&] (offset_type idx
)
4671 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4672 const char *expected_str
4673 = expected_it
== expected_end
? NULL
: *expected_it
++;
4675 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4676 mismatch (expected_str
, matched_name
);
4679 const char *expected_str
4680 = expected_it
== expected_end
? NULL
: *expected_it
++;
4681 if (expected_str
!= NULL
)
4682 mismatch (expected_str
, NULL
);
4687 /* The symbols added to the mock mapped_index for testing (in
4689 static const char *test_symbols
[] = {
4698 "ns2::tmpl<int>::foo2",
4699 "(anonymous namespace)::A::B::C",
4701 /* These are used to check that the increment-last-char in the
4702 matching algorithm for completion doesn't match "t1_fund" when
4703 completing "t1_func". */
4709 /* A UTF-8 name with multi-byte sequences to make sure that
4710 cp-name-parser understands this as a single identifier ("função"
4711 is "function" in PT). */
4714 /* \377 (0xff) is Latin1 'ÿ'. */
4717 /* \377 (0xff) is Latin1 'ÿ'. */
4721 /* A name with all sorts of complications. Starts with "z" to make
4722 it easier for the completion tests below. */
4723 #define Z_SYM_NAME \
4724 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4725 "::tuple<(anonymous namespace)::ui*, " \
4726 "std::default_delete<(anonymous namespace)::ui>, void>"
4731 /* Returns true if the mapped_index_base::find_name_component_bounds
4732 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4733 in completion mode. */
4736 check_find_bounds_finds (mapped_index_base
&index
,
4737 const char *search_name
,
4738 gdb::array_view
<const char *> expected_syms
)
4740 lookup_name_info
lookup_name (search_name
,
4741 symbol_name_match_type::FULL
, true);
4743 auto bounds
= index
.find_name_components_bounds (lookup_name
);
4745 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4746 if (distance
!= expected_syms
.size ())
4749 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4751 auto nc_elem
= bounds
.first
+ exp_elem
;
4752 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4753 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4760 /* Test the lower-level mapped_index::find_name_component_bounds
4764 test_mapped_index_find_name_component_bounds ()
4766 mock_mapped_index
mock_index (test_symbols
);
4768 mock_index
.build_name_components ();
4770 /* Test the lower-level mapped_index::find_name_component_bounds
4771 method in completion mode. */
4773 static const char *expected_syms
[] = {
4778 SELF_CHECK (check_find_bounds_finds (mock_index
,
4779 "t1_func", expected_syms
));
4782 /* Check that the increment-last-char in the name matching algorithm
4783 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4785 static const char *expected_syms1
[] = {
4789 SELF_CHECK (check_find_bounds_finds (mock_index
,
4790 "\377", expected_syms1
));
4792 static const char *expected_syms2
[] = {
4795 SELF_CHECK (check_find_bounds_finds (mock_index
,
4796 "\377\377", expected_syms2
));
4800 /* Test dw2_expand_symtabs_matching_symbol. */
4803 test_dw2_expand_symtabs_matching_symbol ()
4805 mock_mapped_index
mock_index (test_symbols
);
4807 /* We let all tests run until the end even if some fails, for debug
4809 bool any_mismatch
= false;
4811 /* Create the expected symbols list (an initializer_list). Needed
4812 because lists have commas, and we need to pass them to CHECK,
4813 which is a macro. */
4814 #define EXPECT(...) { __VA_ARGS__ }
4816 /* Wrapper for check_match that passes down the current
4817 __FILE__/__LINE__. */
4818 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4819 any_mismatch |= !check_match (__FILE__, __LINE__, \
4821 NAME, MATCH_TYPE, COMPLETION_MODE, \
4824 /* Identity checks. */
4825 for (const char *sym
: test_symbols
)
4827 /* Should be able to match all existing symbols. */
4828 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4831 /* Should be able to match all existing symbols with
4833 std::string with_params
= std::string (sym
) + "(int)";
4834 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4837 /* Should be able to match all existing symbols with
4838 parameters and qualifiers. */
4839 with_params
= std::string (sym
) + " ( int ) const";
4840 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4843 /* This should really find sym, but cp-name-parser.y doesn't
4844 know about lvalue/rvalue qualifiers yet. */
4845 with_params
= std::string (sym
) + " ( int ) &&";
4846 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4850 /* Check that the name matching algorithm for completion doesn't get
4851 confused with Latin1 'ÿ' / 0xff. */
4853 static const char str
[] = "\377";
4854 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4855 EXPECT ("\377", "\377\377123"));
4858 /* Check that the increment-last-char in the matching algorithm for
4859 completion doesn't match "t1_fund" when completing "t1_func". */
4861 static const char str
[] = "t1_func";
4862 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4863 EXPECT ("t1_func", "t1_func1"));
4866 /* Check that completion mode works at each prefix of the expected
4869 static const char str
[] = "function(int)";
4870 size_t len
= strlen (str
);
4873 for (size_t i
= 1; i
< len
; i
++)
4875 lookup
.assign (str
, i
);
4876 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4877 EXPECT ("function"));
4881 /* While "w" is a prefix of both components, the match function
4882 should still only be called once. */
4884 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4886 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4890 /* Same, with a "complicated" symbol. */
4892 static const char str
[] = Z_SYM_NAME
;
4893 size_t len
= strlen (str
);
4896 for (size_t i
= 1; i
< len
; i
++)
4898 lookup
.assign (str
, i
);
4899 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4900 EXPECT (Z_SYM_NAME
));
4904 /* In FULL mode, an incomplete symbol doesn't match. */
4906 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4910 /* A complete symbol with parameters matches any overload, since the
4911 index has no overload info. */
4913 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4914 EXPECT ("std::zfunction", "std::zfunction2"));
4915 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4916 EXPECT ("std::zfunction", "std::zfunction2"));
4917 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4918 EXPECT ("std::zfunction", "std::zfunction2"));
4921 /* Check that whitespace is ignored appropriately. A symbol with a
4922 template argument list. */
4924 static const char expected
[] = "ns::foo<int>";
4925 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4927 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4931 /* Check that whitespace is ignored appropriately. A symbol with a
4932 template argument list that includes a pointer. */
4934 static const char expected
[] = "ns::foo<char*>";
4935 /* Try both completion and non-completion modes. */
4936 static const bool completion_mode
[2] = {false, true};
4937 for (size_t i
= 0; i
< 2; i
++)
4939 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4940 completion_mode
[i
], EXPECT (expected
));
4941 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4942 completion_mode
[i
], EXPECT (expected
));
4944 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4945 completion_mode
[i
], EXPECT (expected
));
4946 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4947 completion_mode
[i
], EXPECT (expected
));
4952 /* Check method qualifiers are ignored. */
4953 static const char expected
[] = "ns::foo<char*>";
4954 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4955 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4956 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4957 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4958 CHECK_MATCH ("foo < char * > ( int ) const",
4959 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4960 CHECK_MATCH ("foo < char * > ( int ) &&",
4961 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4964 /* Test lookup names that don't match anything. */
4966 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4969 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4973 /* Some wild matching tests, exercising "(anonymous namespace)",
4974 which should not be confused with a parameter list. */
4976 static const char *syms
[] = {
4980 "A :: B :: C ( int )",
4985 for (const char *s
: syms
)
4987 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4988 EXPECT ("(anonymous namespace)::A::B::C"));
4993 static const char expected
[] = "ns2::tmpl<int>::foo2";
4994 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4996 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
5000 SELF_CHECK (!any_mismatch
);
5009 test_mapped_index_find_name_component_bounds ();
5010 test_dw2_expand_symtabs_matching_symbol ();
5013 }} // namespace selftests::dw2_expand_symtabs_matching
5015 #endif /* GDB_SELF_TEST */
5017 /* If FILE_MATCHER is NULL or if PER_CU has
5018 dwarf2_per_cu_quick_data::MARK set (see
5019 dw_expand_symtabs_matching_file_matcher), expand the CU and call
5020 EXPANSION_NOTIFY on it. */
5023 dw2_expand_symtabs_matching_one
5024 (struct dwarf2_per_cu_data
*per_cu
,
5025 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5026 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5028 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5030 bool symtab_was_null
5031 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5033 dw2_instantiate_symtab (per_cu
);
5035 if (expansion_notify
!= NULL
5037 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5038 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5042 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5043 matched, to expand corresponding CUs that were marked. IDX is the
5044 index of the symbol name that matched. */
5047 dw2_expand_marked_cus
5048 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5049 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5050 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5053 offset_type
*vec
, vec_len
, vec_idx
;
5054 bool global_seen
= false;
5055 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5057 vec
= (offset_type
*) (index
.constant_pool
5058 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5059 vec_len
= MAYBE_SWAP (vec
[0]);
5060 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5062 struct dwarf2_per_cu_data
*per_cu
;
5063 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5064 /* This value is only valid for index versions >= 7. */
5065 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5066 gdb_index_symbol_kind symbol_kind
=
5067 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5068 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5069 /* Only check the symbol attributes if they're present.
5070 Indices prior to version 7 don't record them,
5071 and indices >= 7 may elide them for certain symbols
5072 (gold does this). */
5075 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5077 /* Work around gold/15646. */
5080 if (!is_static
&& global_seen
)
5086 /* Only check the symbol's kind if it has one. */
5091 case VARIABLES_DOMAIN
:
5092 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5095 case FUNCTIONS_DOMAIN
:
5096 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5100 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5108 /* Don't crash on bad data. */
5109 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
5110 + dwarf2_per_objfile
->n_type_units
))
5112 complaint (&symfile_complaints
,
5113 _(".gdb_index entry has bad CU index"
5115 objfile_name (dwarf2_per_objfile
->objfile
));
5119 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cu_index
);
5120 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5125 /* If FILE_MATCHER is non-NULL, set all the
5126 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5127 that match FILE_MATCHER. */
5130 dw_expand_symtabs_matching_file_matcher
5131 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5132 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5134 if (file_matcher
== NULL
)
5137 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5139 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5141 NULL
, xcalloc
, xfree
));
5142 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5144 NULL
, xcalloc
, xfree
));
5146 /* The rule is CUs specify all the files, including those used by
5147 any TU, so there's no need to scan TUs here. */
5149 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5152 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
5153 struct quick_file_names
*file_data
;
5158 per_cu
->v
.quick
->mark
= 0;
5160 /* We only need to look at symtabs not already expanded. */
5161 if (per_cu
->v
.quick
->compunit_symtab
)
5164 file_data
= dw2_get_file_names (per_cu
);
5165 if (file_data
== NULL
)
5168 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5170 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5172 per_cu
->v
.quick
->mark
= 1;
5176 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
5178 const char *this_real_name
;
5180 if (file_matcher (file_data
->file_names
[j
], false))
5182 per_cu
->v
.quick
->mark
= 1;
5186 /* Before we invoke realpath, which can get expensive when many
5187 files are involved, do a quick comparison of the basenames. */
5188 if (!basenames_may_differ
5189 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5193 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5194 if (file_matcher (this_real_name
, false))
5196 per_cu
->v
.quick
->mark
= 1;
5201 slot
= htab_find_slot (per_cu
->v
.quick
->mark
5202 ? visited_found
.get ()
5203 : visited_not_found
.get (),
5210 dw2_expand_symtabs_matching
5211 (struct objfile
*objfile
,
5212 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5213 const lookup_name_info
&lookup_name
,
5214 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5215 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5216 enum search_domain kind
)
5218 struct dwarf2_per_objfile
*dwarf2_per_objfile
5219 = get_dwarf2_per_objfile (objfile
);
5221 /* index_table is NULL if OBJF_READNOW. */
5222 if (!dwarf2_per_objfile
->index_table
)
5225 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5227 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5229 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5231 kind
, [&] (offset_type idx
)
5233 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5234 expansion_notify
, kind
);
5238 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5241 static struct compunit_symtab
*
5242 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5247 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5248 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5251 if (cust
->includes
== NULL
)
5254 for (i
= 0; cust
->includes
[i
]; ++i
)
5256 struct compunit_symtab
*s
= cust
->includes
[i
];
5258 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5266 static struct compunit_symtab
*
5267 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5268 struct bound_minimal_symbol msymbol
,
5270 struct obj_section
*section
,
5273 struct dwarf2_per_cu_data
*data
;
5274 struct compunit_symtab
*result
;
5276 if (!objfile
->psymtabs_addrmap
)
5279 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
5284 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5285 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5286 paddress (get_objfile_arch (objfile
), pc
));
5289 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
5291 gdb_assert (result
!= NULL
);
5296 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5297 void *data
, int need_fullname
)
5299 struct dwarf2_per_objfile
*dwarf2_per_objfile
5300 = get_dwarf2_per_objfile (objfile
);
5302 if (!dwarf2_per_objfile
->filenames_cache
)
5304 dwarf2_per_objfile
->filenames_cache
.emplace ();
5306 htab_up
visited (htab_create_alloc (10,
5307 htab_hash_pointer
, htab_eq_pointer
,
5308 NULL
, xcalloc
, xfree
));
5310 /* The rule is CUs specify all the files, including those used
5311 by any TU, so there's no need to scan TUs here. We can
5312 ignore file names coming from already-expanded CUs. */
5314 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5316 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
5318 if (per_cu
->v
.quick
->compunit_symtab
)
5320 void **slot
= htab_find_slot (visited
.get (),
5321 per_cu
->v
.quick
->file_names
,
5324 *slot
= per_cu
->v
.quick
->file_names
;
5328 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5330 dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
5331 struct quick_file_names
*file_data
;
5334 /* We only need to look at symtabs not already expanded. */
5335 if (per_cu
->v
.quick
->compunit_symtab
)
5338 file_data
= dw2_get_file_names (per_cu
);
5339 if (file_data
== NULL
)
5342 slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5345 /* Already visited. */
5350 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5352 const char *filename
= file_data
->file_names
[j
];
5353 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5358 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5360 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5363 this_real_name
= gdb_realpath (filename
);
5364 (*fun
) (filename
, this_real_name
.get (), data
);
5369 dw2_has_symbols (struct objfile
*objfile
)
5374 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5377 dw2_find_last_source_symtab
,
5378 dw2_forget_cached_source_info
,
5379 dw2_map_symtabs_matching_filename
,
5384 dw2_expand_symtabs_for_function
,
5385 dw2_expand_all_symtabs
,
5386 dw2_expand_symtabs_with_fullname
,
5387 dw2_map_matching_symbols
,
5388 dw2_expand_symtabs_matching
,
5389 dw2_find_pc_sect_compunit_symtab
,
5391 dw2_map_symbol_filenames
5394 /* DWARF-5 debug_names reader. */
5396 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5397 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5399 /* A helper function that reads the .debug_names section in SECTION
5400 and fills in MAP. FILENAME is the name of the file containing the
5401 section; it is used for error reporting.
5403 Returns true if all went well, false otherwise. */
5406 read_debug_names_from_section (struct objfile
*objfile
,
5407 const char *filename
,
5408 struct dwarf2_section_info
*section
,
5409 mapped_debug_names
&map
)
5411 if (dwarf2_section_empty_p (section
))
5414 /* Older elfutils strip versions could keep the section in the main
5415 executable while splitting it for the separate debug info file. */
5416 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5419 dwarf2_read_section (objfile
, section
);
5421 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5423 const gdb_byte
*addr
= section
->buffer
;
5425 bfd
*const abfd
= get_section_bfd_owner (section
);
5427 unsigned int bytes_read
;
5428 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5431 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5432 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5433 if (bytes_read
+ length
!= section
->size
)
5435 /* There may be multiple per-CU indices. */
5436 warning (_("Section .debug_names in %s length %s does not match "
5437 "section length %s, ignoring .debug_names."),
5438 filename
, plongest (bytes_read
+ length
),
5439 pulongest (section
->size
));
5443 /* The version number. */
5444 uint16_t version
= read_2_bytes (abfd
, addr
);
5448 warning (_("Section .debug_names in %s has unsupported version %d, "
5449 "ignoring .debug_names."),
5455 uint16_t padding
= read_2_bytes (abfd
, addr
);
5459 warning (_("Section .debug_names in %s has unsupported padding %d, "
5460 "ignoring .debug_names."),
5465 /* comp_unit_count - The number of CUs in the CU list. */
5466 map
.cu_count
= read_4_bytes (abfd
, addr
);
5469 /* local_type_unit_count - The number of TUs in the local TU
5471 map
.tu_count
= read_4_bytes (abfd
, addr
);
5474 /* foreign_type_unit_count - The number of TUs in the foreign TU
5476 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5478 if (foreign_tu_count
!= 0)
5480 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5481 "ignoring .debug_names."),
5482 filename
, static_cast<unsigned long> (foreign_tu_count
));
5486 /* bucket_count - The number of hash buckets in the hash lookup
5488 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5491 /* name_count - The number of unique names in the index. */
5492 map
.name_count
= read_4_bytes (abfd
, addr
);
5495 /* abbrev_table_size - The size in bytes of the abbreviations
5497 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5500 /* augmentation_string_size - The size in bytes of the augmentation
5501 string. This value is rounded up to a multiple of 4. */
5502 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5504 map
.augmentation_is_gdb
= ((augmentation_string_size
5505 == sizeof (dwarf5_augmentation
))
5506 && memcmp (addr
, dwarf5_augmentation
,
5507 sizeof (dwarf5_augmentation
)) == 0);
5508 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5509 addr
+= augmentation_string_size
;
5512 map
.cu_table_reordered
= addr
;
5513 addr
+= map
.cu_count
* map
.offset_size
;
5515 /* List of Local TUs */
5516 map
.tu_table_reordered
= addr
;
5517 addr
+= map
.tu_count
* map
.offset_size
;
5519 /* Hash Lookup Table */
5520 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5521 addr
+= map
.bucket_count
* 4;
5522 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5523 addr
+= map
.name_count
* 4;
5526 map
.name_table_string_offs_reordered
= addr
;
5527 addr
+= map
.name_count
* map
.offset_size
;
5528 map
.name_table_entry_offs_reordered
= addr
;
5529 addr
+= map
.name_count
* map
.offset_size
;
5531 const gdb_byte
*abbrev_table_start
= addr
;
5534 unsigned int bytes_read
;
5535 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5540 const auto insertpair
5541 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5542 if (!insertpair
.second
)
5544 warning (_("Section .debug_names in %s has duplicate index %s, "
5545 "ignoring .debug_names."),
5546 filename
, pulongest (index_num
));
5549 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5550 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5555 mapped_debug_names::index_val::attr attr
;
5556 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5558 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5560 if (attr
.form
== DW_FORM_implicit_const
)
5562 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5566 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5568 indexval
.attr_vec
.push_back (std::move (attr
));
5571 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5573 warning (_("Section .debug_names in %s has abbreviation_table "
5574 "of size %zu vs. written as %u, ignoring .debug_names."),
5575 filename
, addr
- abbrev_table_start
, abbrev_table_size
);
5578 map
.entry_pool
= addr
;
5583 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5587 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5588 const mapped_debug_names
&map
,
5589 dwarf2_section_info
§ion
,
5590 bool is_dwz
, int base_offset
)
5592 sect_offset sect_off_prev
;
5593 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5595 sect_offset sect_off_next
;
5596 if (i
< map
.cu_count
)
5599 = (sect_offset
) (extract_unsigned_integer
5600 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5602 map
.dwarf5_byte_order
));
5605 sect_off_next
= (sect_offset
) section
.size
;
5608 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5609 dwarf2_per_objfile
->all_comp_units
[base_offset
+ (i
- 1)]
5610 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5611 sect_off_prev
, length
);
5613 sect_off_prev
= sect_off_next
;
5617 /* Read the CU list from the mapped index, and use it to create all
5618 the CU objects for this dwarf2_per_objfile. */
5621 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5622 const mapped_debug_names
&map
,
5623 const mapped_debug_names
&dwz_map
)
5625 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5627 dwarf2_per_objfile
->n_comp_units
= map
.cu_count
+ dwz_map
.cu_count
;
5628 dwarf2_per_objfile
->all_comp_units
5629 = XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
5630 dwarf2_per_objfile
->n_comp_units
);
5632 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5633 dwarf2_per_objfile
->info
,
5635 0 /* base_offset */);
5637 if (dwz_map
.cu_count
== 0)
5640 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5641 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5643 map
.cu_count
/* base_offset */);
5646 /* Read .debug_names. If everything went ok, initialize the "quick"
5647 elements of all the CUs and return true. Otherwise, return false. */
5650 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5652 mapped_debug_names
local_map (dwarf2_per_objfile
);
5653 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5654 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5656 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5657 &dwarf2_per_objfile
->debug_names
,
5661 /* Don't use the index if it's empty. */
5662 if (local_map
.name_count
== 0)
5665 /* If there is a .dwz file, read it so we can get its CU list as
5667 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5670 if (!read_debug_names_from_section (objfile
,
5671 bfd_get_filename (dwz
->dwz_bfd
),
5672 &dwz
->debug_names
, dwz_map
))
5674 warning (_("could not read '.debug_names' section from %s; skipping"),
5675 bfd_get_filename (dwz
->dwz_bfd
));
5680 create_cus_from_debug_names (dwarf2_per_objfile
, local_map
, dwz_map
);
5682 if (local_map
.tu_count
!= 0)
5684 /* We can only handle a single .debug_types when we have an
5686 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
5689 dwarf2_section_info
*section
= VEC_index (dwarf2_section_info_def
,
5690 dwarf2_per_objfile
->types
, 0);
5692 create_signatured_type_table_from_debug_names
5693 (dwarf2_per_objfile
, local_map
, section
, &dwarf2_per_objfile
->abbrev
);
5696 create_addrmap_from_aranges (dwarf2_per_objfile
,
5697 &dwarf2_per_objfile
->debug_aranges
);
5699 dwarf2_per_objfile
->debug_names_table
.reset
5700 (new mapped_debug_names (dwarf2_per_objfile
));
5701 *dwarf2_per_objfile
->debug_names_table
= std::move (local_map
);
5702 dwarf2_per_objfile
->using_index
= 1;
5703 dwarf2_per_objfile
->quick_file_names_table
=
5704 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
5709 /* Type used to manage iterating over all CUs looking for a symbol for
5712 class dw2_debug_names_iterator
5715 /* If WANT_SPECIFIC_BLOCK is true, only look for symbols in block
5716 BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
5717 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5718 bool want_specific_block
,
5719 block_enum block_index
, domain_enum domain
,
5721 : m_map (map
), m_want_specific_block (want_specific_block
),
5722 m_block_index (block_index
), m_domain (domain
),
5723 m_addr (find_vec_in_debug_names (map
, name
))
5726 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5727 search_domain search
, uint32_t namei
)
5730 m_addr (find_vec_in_debug_names (map
, namei
))
5733 /* Return the next matching CU or NULL if there are no more. */
5734 dwarf2_per_cu_data
*next ();
5737 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5739 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5742 /* The internalized form of .debug_names. */
5743 const mapped_debug_names
&m_map
;
5745 /* If true, only look for symbols that match BLOCK_INDEX. */
5746 const bool m_want_specific_block
= false;
5748 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
5749 Unused if !WANT_SPECIFIC_BLOCK - FIRST_LOCAL_BLOCK is an invalid
5751 const block_enum m_block_index
= FIRST_LOCAL_BLOCK
;
5753 /* The kind of symbol we're looking for. */
5754 const domain_enum m_domain
= UNDEF_DOMAIN
;
5755 const search_domain m_search
= ALL_DOMAIN
;
5757 /* The list of CUs from the index entry of the symbol, or NULL if
5759 const gdb_byte
*m_addr
;
5763 mapped_debug_names::namei_to_name (uint32_t namei
) const
5765 const ULONGEST namei_string_offs
5766 = extract_unsigned_integer ((name_table_string_offs_reordered
5767 + namei
* offset_size
),
5770 return read_indirect_string_at_offset
5771 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5774 /* Find a slot in .debug_names for the object named NAME. If NAME is
5775 found, return pointer to its pool data. If NAME cannot be found,
5779 dw2_debug_names_iterator::find_vec_in_debug_names
5780 (const mapped_debug_names
&map
, const char *name
)
5782 int (*cmp
) (const char *, const char *);
5784 if (current_language
->la_language
== language_cplus
5785 || current_language
->la_language
== language_fortran
5786 || current_language
->la_language
== language_d
)
5788 /* NAME is already canonical. Drop any qualifiers as
5789 .debug_names does not contain any. */
5791 if (strchr (name
, '(') != NULL
)
5793 gdb::unique_xmalloc_ptr
<char> without_params
5794 = cp_remove_params (name
);
5796 if (without_params
!= NULL
)
5798 name
= without_params
.get();
5803 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5805 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5807 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5808 (map
.bucket_table_reordered
5809 + (full_hash
% map
.bucket_count
)), 4,
5810 map
.dwarf5_byte_order
);
5814 if (namei
>= map
.name_count
)
5816 complaint (&symfile_complaints
,
5817 _("Wrong .debug_names with name index %u but name_count=%u "
5819 namei
, map
.name_count
,
5820 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5826 const uint32_t namei_full_hash
5827 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5828 (map
.hash_table_reordered
+ namei
), 4,
5829 map
.dwarf5_byte_order
);
5830 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5833 if (full_hash
== namei_full_hash
)
5835 const char *const namei_string
= map
.namei_to_name (namei
);
5837 #if 0 /* An expensive sanity check. */
5838 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5840 complaint (&symfile_complaints
,
5841 _("Wrong .debug_names hash for string at index %u "
5843 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5848 if (cmp (namei_string
, name
) == 0)
5850 const ULONGEST namei_entry_offs
5851 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5852 + namei
* map
.offset_size
),
5853 map
.offset_size
, map
.dwarf5_byte_order
);
5854 return map
.entry_pool
+ namei_entry_offs
;
5859 if (namei
>= map
.name_count
)
5865 dw2_debug_names_iterator::find_vec_in_debug_names
5866 (const mapped_debug_names
&map
, uint32_t namei
)
5868 if (namei
>= map
.name_count
)
5870 complaint (&symfile_complaints
,
5871 _("Wrong .debug_names with name index %u but name_count=%u "
5873 namei
, map
.name_count
,
5874 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5878 const ULONGEST namei_entry_offs
5879 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5880 + namei
* map
.offset_size
),
5881 map
.offset_size
, map
.dwarf5_byte_order
);
5882 return map
.entry_pool
+ namei_entry_offs
;
5885 /* See dw2_debug_names_iterator. */
5887 dwarf2_per_cu_data
*
5888 dw2_debug_names_iterator::next ()
5893 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5894 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5895 bfd
*const abfd
= objfile
->obfd
;
5899 unsigned int bytes_read
;
5900 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5901 m_addr
+= bytes_read
;
5905 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5906 if (indexval_it
== m_map
.abbrev_map
.cend ())
5908 complaint (&symfile_complaints
,
5909 _("Wrong .debug_names undefined abbrev code %s "
5911 pulongest (abbrev
), objfile_name (objfile
));
5914 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5915 bool have_is_static
= false;
5917 dwarf2_per_cu_data
*per_cu
= NULL
;
5918 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5923 case DW_FORM_implicit_const
:
5924 ull
= attr
.implicit_const
;
5926 case DW_FORM_flag_present
:
5930 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5931 m_addr
+= bytes_read
;
5934 complaint (&symfile_complaints
,
5935 _("Unsupported .debug_names form %s [in module %s]"),
5936 dwarf_form_name (attr
.form
),
5937 objfile_name (objfile
));
5940 switch (attr
.dw_idx
)
5942 case DW_IDX_compile_unit
:
5943 /* Don't crash on bad data. */
5944 if (ull
>= dwarf2_per_objfile
->n_comp_units
)
5946 complaint (&symfile_complaints
,
5947 _(".debug_names entry has bad CU index %s"
5950 objfile_name (dwarf2_per_objfile
->objfile
));
5953 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, ull
);
5955 case DW_IDX_type_unit
:
5956 /* Don't crash on bad data. */
5957 if (ull
>= dwarf2_per_objfile
->n_type_units
)
5959 complaint (&symfile_complaints
,
5960 _(".debug_names entry has bad TU index %s"
5963 objfile_name (dwarf2_per_objfile
->objfile
));
5966 per_cu
= dw2_get_cutu (dwarf2_per_objfile
,
5967 dwarf2_per_objfile
->n_comp_units
+ ull
);
5969 case DW_IDX_GNU_internal
:
5970 if (!m_map
.augmentation_is_gdb
)
5972 have_is_static
= true;
5975 case DW_IDX_GNU_external
:
5976 if (!m_map
.augmentation_is_gdb
)
5978 have_is_static
= true;
5984 /* Skip if already read in. */
5985 if (per_cu
->v
.quick
->compunit_symtab
)
5988 /* Check static vs global. */
5991 const bool want_static
= m_block_index
!= GLOBAL_BLOCK
;
5992 if (m_want_specific_block
&& want_static
!= is_static
)
5996 /* Match dw2_symtab_iter_next, symbol_kind
5997 and debug_names::psymbol_tag. */
6001 switch (indexval
.dwarf_tag
)
6003 case DW_TAG_variable
:
6004 case DW_TAG_subprogram
:
6005 /* Some types are also in VAR_DOMAIN. */
6006 case DW_TAG_typedef
:
6007 case DW_TAG_structure_type
:
6014 switch (indexval
.dwarf_tag
)
6016 case DW_TAG_typedef
:
6017 case DW_TAG_structure_type
:
6024 switch (indexval
.dwarf_tag
)
6027 case DW_TAG_variable
:
6037 /* Match dw2_expand_symtabs_matching, symbol_kind and
6038 debug_names::psymbol_tag. */
6041 case VARIABLES_DOMAIN
:
6042 switch (indexval
.dwarf_tag
)
6044 case DW_TAG_variable
:
6050 case FUNCTIONS_DOMAIN
:
6051 switch (indexval
.dwarf_tag
)
6053 case DW_TAG_subprogram
:
6060 switch (indexval
.dwarf_tag
)
6062 case DW_TAG_typedef
:
6063 case DW_TAG_structure_type
:
6076 static struct compunit_symtab
*
6077 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, int block_index_int
,
6078 const char *name
, domain_enum domain
)
6080 const block_enum block_index
= static_cast<block_enum
> (block_index_int
);
6081 struct dwarf2_per_objfile
*dwarf2_per_objfile
6082 = get_dwarf2_per_objfile (objfile
);
6084 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6087 /* index is NULL if OBJF_READNOW. */
6090 const auto &map
= *mapp
;
6092 dw2_debug_names_iterator
iter (map
, true /* want_specific_block */,
6093 block_index
, domain
, name
);
6095 struct compunit_symtab
*stab_best
= NULL
;
6096 struct dwarf2_per_cu_data
*per_cu
;
6097 while ((per_cu
= iter
.next ()) != NULL
)
6099 struct symbol
*sym
, *with_opaque
= NULL
;
6100 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
6101 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6102 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6104 sym
= block_find_symbol (block
, name
, domain
,
6105 block_find_non_opaque_type_preferred
,
6108 /* Some caution must be observed with overloaded functions and
6109 methods, since the index will not contain any overload
6110 information (but NAME might contain it). */
6113 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6115 if (with_opaque
!= NULL
6116 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6119 /* Keep looking through other CUs. */
6125 /* This dumps minimal information about .debug_names. It is called
6126 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6127 uses this to verify that .debug_names has been loaded. */
6130 dw2_debug_names_dump (struct objfile
*objfile
)
6132 struct dwarf2_per_objfile
*dwarf2_per_objfile
6133 = get_dwarf2_per_objfile (objfile
);
6135 gdb_assert (dwarf2_per_objfile
->using_index
);
6136 printf_filtered (".debug_names:");
6137 if (dwarf2_per_objfile
->debug_names_table
)
6138 printf_filtered (" exists\n");
6140 printf_filtered (" faked for \"readnow\"\n");
6141 printf_filtered ("\n");
6145 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6146 const char *func_name
)
6148 struct dwarf2_per_objfile
*dwarf2_per_objfile
6149 = get_dwarf2_per_objfile (objfile
);
6151 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6152 if (dwarf2_per_objfile
->debug_names_table
)
6154 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6156 /* Note: It doesn't matter what we pass for block_index here. */
6157 dw2_debug_names_iterator
iter (map
, false /* want_specific_block */,
6158 GLOBAL_BLOCK
, VAR_DOMAIN
, func_name
);
6160 struct dwarf2_per_cu_data
*per_cu
;
6161 while ((per_cu
= iter
.next ()) != NULL
)
6162 dw2_instantiate_symtab (per_cu
);
6167 dw2_debug_names_expand_symtabs_matching
6168 (struct objfile
*objfile
,
6169 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6170 const lookup_name_info
&lookup_name
,
6171 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6172 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6173 enum search_domain kind
)
6175 struct dwarf2_per_objfile
*dwarf2_per_objfile
6176 = get_dwarf2_per_objfile (objfile
);
6178 /* debug_names_table is NULL if OBJF_READNOW. */
6179 if (!dwarf2_per_objfile
->debug_names_table
)
6182 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6184 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6186 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6188 kind
, [&] (offset_type namei
)
6190 /* The name was matched, now expand corresponding CUs that were
6192 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6194 struct dwarf2_per_cu_data
*per_cu
;
6195 while ((per_cu
= iter
.next ()) != NULL
)
6196 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6201 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6204 dw2_find_last_source_symtab
,
6205 dw2_forget_cached_source_info
,
6206 dw2_map_symtabs_matching_filename
,
6207 dw2_debug_names_lookup_symbol
,
6209 dw2_debug_names_dump
,
6211 dw2_debug_names_expand_symtabs_for_function
,
6212 dw2_expand_all_symtabs
,
6213 dw2_expand_symtabs_with_fullname
,
6214 dw2_map_matching_symbols
,
6215 dw2_debug_names_expand_symtabs_matching
,
6216 dw2_find_pc_sect_compunit_symtab
,
6218 dw2_map_symbol_filenames
6221 /* See symfile.h. */
6224 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6226 struct dwarf2_per_objfile
*dwarf2_per_objfile
6227 = get_dwarf2_per_objfile (objfile
);
6229 /* If we're about to read full symbols, don't bother with the
6230 indices. In this case we also don't care if some other debug
6231 format is making psymtabs, because they are all about to be
6233 if ((objfile
->flags
& OBJF_READNOW
))
6237 dwarf2_per_objfile
->using_index
= 1;
6238 create_all_comp_units (dwarf2_per_objfile
);
6239 create_all_type_units (dwarf2_per_objfile
);
6240 dwarf2_per_objfile
->quick_file_names_table
=
6241 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
6243 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
6244 + dwarf2_per_objfile
->n_type_units
); ++i
)
6246 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
6248 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6249 struct dwarf2_per_cu_quick_data
);
6252 /* Return 1 so that gdb sees the "quick" functions. However,
6253 these functions will be no-ops because we will have expanded
6255 *index_kind
= dw_index_kind::GDB_INDEX
;
6259 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6261 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6265 if (dwarf2_read_index (objfile
))
6267 *index_kind
= dw_index_kind::GDB_INDEX
;
6276 /* Build a partial symbol table. */
6279 dwarf2_build_psymtabs (struct objfile
*objfile
)
6281 struct dwarf2_per_objfile
*dwarf2_per_objfile
6282 = get_dwarf2_per_objfile (objfile
);
6284 if (objfile
->global_psymbols
.capacity () == 0
6285 && objfile
->static_psymbols
.capacity () == 0)
6286 init_psymbol_list (objfile
, 1024);
6290 /* This isn't really ideal: all the data we allocate on the
6291 objfile's obstack is still uselessly kept around. However,
6292 freeing it seems unsafe. */
6293 psymtab_discarder
psymtabs (objfile
);
6294 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6297 CATCH (except
, RETURN_MASK_ERROR
)
6299 exception_print (gdb_stderr
, except
);
6304 /* Return the total length of the CU described by HEADER. */
6307 get_cu_length (const struct comp_unit_head
*header
)
6309 return header
->initial_length_size
+ header
->length
;
6312 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6315 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6317 sect_offset bottom
= cu_header
->sect_off
;
6318 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6320 return sect_off
>= bottom
&& sect_off
< top
;
6323 /* Find the base address of the compilation unit for range lists and
6324 location lists. It will normally be specified by DW_AT_low_pc.
6325 In DWARF-3 draft 4, the base address could be overridden by
6326 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6327 compilation units with discontinuous ranges. */
6330 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6332 struct attribute
*attr
;
6335 cu
->base_address
= 0;
6337 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6340 cu
->base_address
= attr_value_as_address (attr
);
6345 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6348 cu
->base_address
= attr_value_as_address (attr
);
6354 /* Read in the comp unit header information from the debug_info at info_ptr.
6355 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6356 NOTE: This leaves members offset, first_die_offset to be filled in
6359 static const gdb_byte
*
6360 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6361 const gdb_byte
*info_ptr
,
6362 struct dwarf2_section_info
*section
,
6363 rcuh_kind section_kind
)
6366 unsigned int bytes_read
;
6367 const char *filename
= get_section_file_name (section
);
6368 bfd
*abfd
= get_section_bfd_owner (section
);
6370 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6371 cu_header
->initial_length_size
= bytes_read
;
6372 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6373 info_ptr
+= bytes_read
;
6374 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6376 if (cu_header
->version
< 5)
6377 switch (section_kind
)
6379 case rcuh_kind::COMPILE
:
6380 cu_header
->unit_type
= DW_UT_compile
;
6382 case rcuh_kind::TYPE
:
6383 cu_header
->unit_type
= DW_UT_type
;
6386 internal_error (__FILE__
, __LINE__
,
6387 _("read_comp_unit_head: invalid section_kind"));
6391 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6392 (read_1_byte (abfd
, info_ptr
));
6394 switch (cu_header
->unit_type
)
6397 if (section_kind
!= rcuh_kind::COMPILE
)
6398 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6399 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
6403 section_kind
= rcuh_kind::TYPE
;
6406 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6407 "(is %d, should be %d or %d) [in module %s]"),
6408 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
6411 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6414 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6417 info_ptr
+= bytes_read
;
6418 if (cu_header
->version
< 5)
6420 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6423 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6424 if (signed_addr
< 0)
6425 internal_error (__FILE__
, __LINE__
,
6426 _("read_comp_unit_head: dwarf from non elf file"));
6427 cu_header
->signed_addr_p
= signed_addr
;
6429 if (section_kind
== rcuh_kind::TYPE
)
6431 LONGEST type_offset
;
6433 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6436 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6437 info_ptr
+= bytes_read
;
6438 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6439 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6440 error (_("Dwarf Error: Too big type_offset in compilation unit "
6441 "header (is %s) [in module %s]"), plongest (type_offset
),
6448 /* Helper function that returns the proper abbrev section for
6451 static struct dwarf2_section_info
*
6452 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6454 struct dwarf2_section_info
*abbrev
;
6455 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6457 if (this_cu
->is_dwz
)
6458 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6460 abbrev
= &dwarf2_per_objfile
->abbrev
;
6465 /* Subroutine of read_and_check_comp_unit_head and
6466 read_and_check_type_unit_head to simplify them.
6467 Perform various error checking on the header. */
6470 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6471 struct comp_unit_head
*header
,
6472 struct dwarf2_section_info
*section
,
6473 struct dwarf2_section_info
*abbrev_section
)
6475 const char *filename
= get_section_file_name (section
);
6477 if (header
->version
< 2 || header
->version
> 5)
6478 error (_("Dwarf Error: wrong version in compilation unit header "
6479 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
6482 if (to_underlying (header
->abbrev_sect_off
)
6483 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6484 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6485 "(offset %s + 6) [in module %s]"),
6486 sect_offset_str (header
->abbrev_sect_off
),
6487 sect_offset_str (header
->sect_off
),
6490 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6491 avoid potential 32-bit overflow. */
6492 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6494 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6495 "(offset %s + 0) [in module %s]"),
6496 header
->length
, sect_offset_str (header
->sect_off
),
6500 /* Read in a CU/TU header and perform some basic error checking.
6501 The contents of the header are stored in HEADER.
6502 The result is a pointer to the start of the first DIE. */
6504 static const gdb_byte
*
6505 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6506 struct comp_unit_head
*header
,
6507 struct dwarf2_section_info
*section
,
6508 struct dwarf2_section_info
*abbrev_section
,
6509 const gdb_byte
*info_ptr
,
6510 rcuh_kind section_kind
)
6512 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6514 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6516 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6518 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6520 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6526 /* Fetch the abbreviation table offset from a comp or type unit header. */
6529 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6530 struct dwarf2_section_info
*section
,
6531 sect_offset sect_off
)
6533 bfd
*abfd
= get_section_bfd_owner (section
);
6534 const gdb_byte
*info_ptr
;
6535 unsigned int initial_length_size
, offset_size
;
6538 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6539 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6540 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6541 offset_size
= initial_length_size
== 4 ? 4 : 8;
6542 info_ptr
+= initial_length_size
;
6544 version
= read_2_bytes (abfd
, info_ptr
);
6548 /* Skip unit type and address size. */
6552 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6555 /* Allocate a new partial symtab for file named NAME and mark this new
6556 partial symtab as being an include of PST. */
6559 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6560 struct objfile
*objfile
)
6562 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6564 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6566 /* It shares objfile->objfile_obstack. */
6567 subpst
->dirname
= pst
->dirname
;
6570 subpst
->textlow
= 0;
6571 subpst
->texthigh
= 0;
6573 subpst
->dependencies
6574 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
6575 subpst
->dependencies
[0] = pst
;
6576 subpst
->number_of_dependencies
= 1;
6578 subpst
->globals_offset
= 0;
6579 subpst
->n_global_syms
= 0;
6580 subpst
->statics_offset
= 0;
6581 subpst
->n_static_syms
= 0;
6582 subpst
->compunit_symtab
= NULL
;
6583 subpst
->read_symtab
= pst
->read_symtab
;
6586 /* No private part is necessary for include psymtabs. This property
6587 can be used to differentiate between such include psymtabs and
6588 the regular ones. */
6589 subpst
->read_symtab_private
= NULL
;
6592 /* Read the Line Number Program data and extract the list of files
6593 included by the source file represented by PST. Build an include
6594 partial symtab for each of these included files. */
6597 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6598 struct die_info
*die
,
6599 struct partial_symtab
*pst
)
6602 struct attribute
*attr
;
6604 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6606 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6608 return; /* No linetable, so no includes. */
6610 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
6611 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
6615 hash_signatured_type (const void *item
)
6617 const struct signatured_type
*sig_type
6618 = (const struct signatured_type
*) item
;
6620 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6621 return sig_type
->signature
;
6625 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6627 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6628 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6630 return lhs
->signature
== rhs
->signature
;
6633 /* Allocate a hash table for signatured types. */
6636 allocate_signatured_type_table (struct objfile
*objfile
)
6638 return htab_create_alloc_ex (41,
6639 hash_signatured_type
,
6642 &objfile
->objfile_obstack
,
6643 hashtab_obstack_allocate
,
6644 dummy_obstack_deallocate
);
6647 /* A helper function to add a signatured type CU to a table. */
6650 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6652 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6653 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
6661 /* A helper for create_debug_types_hash_table. Read types from SECTION
6662 and fill them into TYPES_HTAB. It will process only type units,
6663 therefore DW_UT_type. */
6666 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6667 struct dwo_file
*dwo_file
,
6668 dwarf2_section_info
*section
, htab_t
&types_htab
,
6669 rcuh_kind section_kind
)
6671 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6672 struct dwarf2_section_info
*abbrev_section
;
6674 const gdb_byte
*info_ptr
, *end_ptr
;
6676 abbrev_section
= (dwo_file
!= NULL
6677 ? &dwo_file
->sections
.abbrev
6678 : &dwarf2_per_objfile
->abbrev
);
6680 if (dwarf_read_debug
)
6681 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6682 get_section_name (section
),
6683 get_section_file_name (abbrev_section
));
6685 dwarf2_read_section (objfile
, section
);
6686 info_ptr
= section
->buffer
;
6688 if (info_ptr
== NULL
)
6691 /* We can't set abfd until now because the section may be empty or
6692 not present, in which case the bfd is unknown. */
6693 abfd
= get_section_bfd_owner (section
);
6695 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6696 because we don't need to read any dies: the signature is in the
6699 end_ptr
= info_ptr
+ section
->size
;
6700 while (info_ptr
< end_ptr
)
6702 struct signatured_type
*sig_type
;
6703 struct dwo_unit
*dwo_tu
;
6705 const gdb_byte
*ptr
= info_ptr
;
6706 struct comp_unit_head header
;
6707 unsigned int length
;
6709 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6711 /* Initialize it due to a false compiler warning. */
6712 header
.signature
= -1;
6713 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6715 /* We need to read the type's signature in order to build the hash
6716 table, but we don't need anything else just yet. */
6718 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6719 abbrev_section
, ptr
, section_kind
);
6721 length
= get_cu_length (&header
);
6723 /* Skip dummy type units. */
6724 if (ptr
>= info_ptr
+ length
6725 || peek_abbrev_code (abfd
, ptr
) == 0
6726 || header
.unit_type
!= DW_UT_type
)
6732 if (types_htab
== NULL
)
6735 types_htab
= allocate_dwo_unit_table (objfile
);
6737 types_htab
= allocate_signatured_type_table (objfile
);
6743 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6745 dwo_tu
->dwo_file
= dwo_file
;
6746 dwo_tu
->signature
= header
.signature
;
6747 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6748 dwo_tu
->section
= section
;
6749 dwo_tu
->sect_off
= sect_off
;
6750 dwo_tu
->length
= length
;
6754 /* N.B.: type_offset is not usable if this type uses a DWO file.
6755 The real type_offset is in the DWO file. */
6757 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6758 struct signatured_type
);
6759 sig_type
->signature
= header
.signature
;
6760 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6761 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6762 sig_type
->per_cu
.is_debug_types
= 1;
6763 sig_type
->per_cu
.section
= section
;
6764 sig_type
->per_cu
.sect_off
= sect_off
;
6765 sig_type
->per_cu
.length
= length
;
6768 slot
= htab_find_slot (types_htab
,
6769 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6771 gdb_assert (slot
!= NULL
);
6774 sect_offset dup_sect_off
;
6778 const struct dwo_unit
*dup_tu
6779 = (const struct dwo_unit
*) *slot
;
6781 dup_sect_off
= dup_tu
->sect_off
;
6785 const struct signatured_type
*dup_tu
6786 = (const struct signatured_type
*) *slot
;
6788 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6791 complaint (&symfile_complaints
,
6792 _("debug type entry at offset %s is duplicate to"
6793 " the entry at offset %s, signature %s"),
6794 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6795 hex_string (header
.signature
));
6797 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6799 if (dwarf_read_debug
> 1)
6800 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6801 sect_offset_str (sect_off
),
6802 hex_string (header
.signature
));
6808 /* Create the hash table of all entries in the .debug_types
6809 (or .debug_types.dwo) section(s).
6810 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6811 otherwise it is NULL.
6813 The result is a pointer to the hash table or NULL if there are no types.
6815 Note: This function processes DWO files only, not DWP files. */
6818 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6819 struct dwo_file
*dwo_file
,
6820 VEC (dwarf2_section_info_def
) *types
,
6824 struct dwarf2_section_info
*section
;
6826 if (VEC_empty (dwarf2_section_info_def
, types
))
6830 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
6832 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, section
,
6833 types_htab
, rcuh_kind::TYPE
);
6836 /* Create the hash table of all entries in the .debug_types section,
6837 and initialize all_type_units.
6838 The result is zero if there is an error (e.g. missing .debug_types section),
6839 otherwise non-zero. */
6842 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6844 htab_t types_htab
= NULL
;
6845 struct signatured_type
**iter
;
6847 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6848 &dwarf2_per_objfile
->info
, types_htab
,
6849 rcuh_kind::COMPILE
);
6850 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6851 dwarf2_per_objfile
->types
, types_htab
);
6852 if (types_htab
== NULL
)
6854 dwarf2_per_objfile
->signatured_types
= NULL
;
6858 dwarf2_per_objfile
->signatured_types
= types_htab
;
6860 dwarf2_per_objfile
->n_type_units
6861 = dwarf2_per_objfile
->n_allocated_type_units
6862 = htab_elements (types_htab
);
6863 dwarf2_per_objfile
->all_type_units
=
6864 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
6865 iter
= &dwarf2_per_objfile
->all_type_units
[0];
6866 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
6867 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
6868 == dwarf2_per_objfile
->n_type_units
);
6873 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6874 If SLOT is non-NULL, it is the entry to use in the hash table.
6875 Otherwise we find one. */
6877 static struct signatured_type
*
6878 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6881 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6882 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
6883 struct signatured_type
*sig_type
;
6885 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
6887 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
6889 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
6890 dwarf2_per_objfile
->n_allocated_type_units
= 1;
6891 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
6892 dwarf2_per_objfile
->all_type_units
6893 = XRESIZEVEC (struct signatured_type
*,
6894 dwarf2_per_objfile
->all_type_units
,
6895 dwarf2_per_objfile
->n_allocated_type_units
);
6896 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6898 dwarf2_per_objfile
->n_type_units
= n_type_units
;
6900 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6901 struct signatured_type
);
6902 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
6903 sig_type
->signature
= sig
;
6904 sig_type
->per_cu
.is_debug_types
= 1;
6905 if (dwarf2_per_objfile
->using_index
)
6907 sig_type
->per_cu
.v
.quick
=
6908 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6909 struct dwarf2_per_cu_quick_data
);
6914 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6917 gdb_assert (*slot
== NULL
);
6919 /* The rest of sig_type must be filled in by the caller. */
6923 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6924 Fill in SIG_ENTRY with DWO_ENTRY. */
6927 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6928 struct signatured_type
*sig_entry
,
6929 struct dwo_unit
*dwo_entry
)
6931 /* Make sure we're not clobbering something we don't expect to. */
6932 gdb_assert (! sig_entry
->per_cu
.queued
);
6933 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6934 if (dwarf2_per_objfile
->using_index
)
6936 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6937 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6940 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6941 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6942 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6943 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6944 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6946 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6947 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6948 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6949 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6950 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6951 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6952 sig_entry
->dwo_unit
= dwo_entry
;
6955 /* Subroutine of lookup_signatured_type.
6956 If we haven't read the TU yet, create the signatured_type data structure
6957 for a TU to be read in directly from a DWO file, bypassing the stub.
6958 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6959 using .gdb_index, then when reading a CU we want to stay in the DWO file
6960 containing that CU. Otherwise we could end up reading several other DWO
6961 files (due to comdat folding) to process the transitive closure of all the
6962 mentioned TUs, and that can be slow. The current DWO file will have every
6963 type signature that it needs.
6964 We only do this for .gdb_index because in the psymtab case we already have
6965 to read all the DWOs to build the type unit groups. */
6967 static struct signatured_type
*
6968 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6970 struct dwarf2_per_objfile
*dwarf2_per_objfile
6971 = cu
->per_cu
->dwarf2_per_objfile
;
6972 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6973 struct dwo_file
*dwo_file
;
6974 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6975 struct signatured_type find_sig_entry
, *sig_entry
;
6978 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6980 /* If TU skeletons have been removed then we may not have read in any
6982 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6984 dwarf2_per_objfile
->signatured_types
6985 = allocate_signatured_type_table (objfile
);
6988 /* We only ever need to read in one copy of a signatured type.
6989 Use the global signatured_types array to do our own comdat-folding
6990 of types. If this is the first time we're reading this TU, and
6991 the TU has an entry in .gdb_index, replace the recorded data from
6992 .gdb_index with this TU. */
6994 find_sig_entry
.signature
= sig
;
6995 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6996 &find_sig_entry
, INSERT
);
6997 sig_entry
= (struct signatured_type
*) *slot
;
6999 /* We can get here with the TU already read, *or* in the process of being
7000 read. Don't reassign the global entry to point to this DWO if that's
7001 the case. Also note that if the TU is already being read, it may not
7002 have come from a DWO, the program may be a mix of Fission-compiled
7003 code and non-Fission-compiled code. */
7005 /* Have we already tried to read this TU?
7006 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7007 needn't exist in the global table yet). */
7008 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7011 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7012 dwo_unit of the TU itself. */
7013 dwo_file
= cu
->dwo_unit
->dwo_file
;
7015 /* Ok, this is the first time we're reading this TU. */
7016 if (dwo_file
->tus
== NULL
)
7018 find_dwo_entry
.signature
= sig
;
7019 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7020 if (dwo_entry
== NULL
)
7023 /* If the global table doesn't have an entry for this TU, add one. */
7024 if (sig_entry
== NULL
)
7025 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7027 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7028 sig_entry
->per_cu
.tu_read
= 1;
7032 /* Subroutine of lookup_signatured_type.
7033 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7034 then try the DWP file. If the TU stub (skeleton) has been removed then
7035 it won't be in .gdb_index. */
7037 static struct signatured_type
*
7038 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7040 struct dwarf2_per_objfile
*dwarf2_per_objfile
7041 = cu
->per_cu
->dwarf2_per_objfile
;
7042 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7043 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7044 struct dwo_unit
*dwo_entry
;
7045 struct signatured_type find_sig_entry
, *sig_entry
;
7048 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7049 gdb_assert (dwp_file
!= NULL
);
7051 /* If TU skeletons have been removed then we may not have read in any
7053 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7055 dwarf2_per_objfile
->signatured_types
7056 = allocate_signatured_type_table (objfile
);
7059 find_sig_entry
.signature
= sig
;
7060 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7061 &find_sig_entry
, INSERT
);
7062 sig_entry
= (struct signatured_type
*) *slot
;
7064 /* Have we already tried to read this TU?
7065 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7066 needn't exist in the global table yet). */
7067 if (sig_entry
!= NULL
)
7070 if (dwp_file
->tus
== NULL
)
7072 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7073 sig
, 1 /* is_debug_types */);
7074 if (dwo_entry
== NULL
)
7077 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7078 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7083 /* Lookup a signature based type for DW_FORM_ref_sig8.
7084 Returns NULL if signature SIG is not present in the table.
7085 It is up to the caller to complain about this. */
7087 static struct signatured_type
*
7088 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7090 struct dwarf2_per_objfile
*dwarf2_per_objfile
7091 = cu
->per_cu
->dwarf2_per_objfile
;
7094 && dwarf2_per_objfile
->using_index
)
7096 /* We're in a DWO/DWP file, and we're using .gdb_index.
7097 These cases require special processing. */
7098 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7099 return lookup_dwo_signatured_type (cu
, sig
);
7101 return lookup_dwp_signatured_type (cu
, sig
);
7105 struct signatured_type find_entry
, *entry
;
7107 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7109 find_entry
.signature
= sig
;
7110 entry
= ((struct signatured_type
*)
7111 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7116 /* Low level DIE reading support. */
7118 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7121 init_cu_die_reader (struct die_reader_specs
*reader
,
7122 struct dwarf2_cu
*cu
,
7123 struct dwarf2_section_info
*section
,
7124 struct dwo_file
*dwo_file
,
7125 struct abbrev_table
*abbrev_table
)
7127 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7128 reader
->abfd
= get_section_bfd_owner (section
);
7130 reader
->dwo_file
= dwo_file
;
7131 reader
->die_section
= section
;
7132 reader
->buffer
= section
->buffer
;
7133 reader
->buffer_end
= section
->buffer
+ section
->size
;
7134 reader
->comp_dir
= NULL
;
7135 reader
->abbrev_table
= abbrev_table
;
7138 /* Subroutine of init_cutu_and_read_dies to simplify it.
7139 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7140 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7143 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7144 from it to the DIE in the DWO. If NULL we are skipping the stub.
7145 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7146 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7147 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7148 STUB_COMP_DIR may be non-NULL.
7149 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7150 are filled in with the info of the DIE from the DWO file.
7151 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7152 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7153 kept around for at least as long as *RESULT_READER.
7155 The result is non-zero if a valid (non-dummy) DIE was found. */
7158 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7159 struct dwo_unit
*dwo_unit
,
7160 struct die_info
*stub_comp_unit_die
,
7161 const char *stub_comp_dir
,
7162 struct die_reader_specs
*result_reader
,
7163 const gdb_byte
**result_info_ptr
,
7164 struct die_info
**result_comp_unit_die
,
7165 int *result_has_children
,
7166 abbrev_table_up
*result_dwo_abbrev_table
)
7168 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7169 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7170 struct dwarf2_cu
*cu
= this_cu
->cu
;
7172 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7173 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7174 int i
,num_extra_attrs
;
7175 struct dwarf2_section_info
*dwo_abbrev_section
;
7176 struct attribute
*attr
;
7177 struct die_info
*comp_unit_die
;
7179 /* At most one of these may be provided. */
7180 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7182 /* These attributes aren't processed until later:
7183 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7184 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7185 referenced later. However, these attributes are found in the stub
7186 which we won't have later. In order to not impose this complication
7187 on the rest of the code, we read them here and copy them to the
7196 if (stub_comp_unit_die
!= NULL
)
7198 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7200 if (! this_cu
->is_debug_types
)
7201 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7202 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7203 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7204 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7205 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7207 /* There should be a DW_AT_addr_base attribute here (if needed).
7208 We need the value before we can process DW_FORM_GNU_addr_index. */
7210 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7212 cu
->addr_base
= DW_UNSND (attr
);
7214 /* There should be a DW_AT_ranges_base attribute here (if needed).
7215 We need the value before we can process DW_AT_ranges. */
7216 cu
->ranges_base
= 0;
7217 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7219 cu
->ranges_base
= DW_UNSND (attr
);
7221 else if (stub_comp_dir
!= NULL
)
7223 /* Reconstruct the comp_dir attribute to simplify the code below. */
7224 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7225 comp_dir
->name
= DW_AT_comp_dir
;
7226 comp_dir
->form
= DW_FORM_string
;
7227 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7228 DW_STRING (comp_dir
) = stub_comp_dir
;
7231 /* Set up for reading the DWO CU/TU. */
7232 cu
->dwo_unit
= dwo_unit
;
7233 dwarf2_section_info
*section
= dwo_unit
->section
;
7234 dwarf2_read_section (objfile
, section
);
7235 abfd
= get_section_bfd_owner (section
);
7236 begin_info_ptr
= info_ptr
= (section
->buffer
7237 + to_underlying (dwo_unit
->sect_off
));
7238 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7240 if (this_cu
->is_debug_types
)
7242 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7244 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7245 &cu
->header
, section
,
7247 info_ptr
, rcuh_kind::TYPE
);
7248 /* This is not an assert because it can be caused by bad debug info. */
7249 if (sig_type
->signature
!= cu
->header
.signature
)
7251 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7252 " TU at offset %s [in module %s]"),
7253 hex_string (sig_type
->signature
),
7254 hex_string (cu
->header
.signature
),
7255 sect_offset_str (dwo_unit
->sect_off
),
7256 bfd_get_filename (abfd
));
7258 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7259 /* For DWOs coming from DWP files, we don't know the CU length
7260 nor the type's offset in the TU until now. */
7261 dwo_unit
->length
= get_cu_length (&cu
->header
);
7262 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7264 /* Establish the type offset that can be used to lookup the type.
7265 For DWO files, we don't know it until now. */
7266 sig_type
->type_offset_in_section
7267 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7271 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7272 &cu
->header
, section
,
7274 info_ptr
, rcuh_kind::COMPILE
);
7275 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7276 /* For DWOs coming from DWP files, we don't know the CU length
7278 dwo_unit
->length
= get_cu_length (&cu
->header
);
7281 *result_dwo_abbrev_table
7282 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7283 cu
->header
.abbrev_sect_off
);
7284 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7285 result_dwo_abbrev_table
->get ());
7287 /* Read in the die, but leave space to copy over the attributes
7288 from the stub. This has the benefit of simplifying the rest of
7289 the code - all the work to maintain the illusion of a single
7290 DW_TAG_{compile,type}_unit DIE is done here. */
7291 num_extra_attrs
= ((stmt_list
!= NULL
)
7295 + (comp_dir
!= NULL
));
7296 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7297 result_has_children
, num_extra_attrs
);
7299 /* Copy over the attributes from the stub to the DIE we just read in. */
7300 comp_unit_die
= *result_comp_unit_die
;
7301 i
= comp_unit_die
->num_attrs
;
7302 if (stmt_list
!= NULL
)
7303 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7305 comp_unit_die
->attrs
[i
++] = *low_pc
;
7306 if (high_pc
!= NULL
)
7307 comp_unit_die
->attrs
[i
++] = *high_pc
;
7309 comp_unit_die
->attrs
[i
++] = *ranges
;
7310 if (comp_dir
!= NULL
)
7311 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7312 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7314 if (dwarf_die_debug
)
7316 fprintf_unfiltered (gdb_stdlog
,
7317 "Read die from %s@0x%x of %s:\n",
7318 get_section_name (section
),
7319 (unsigned) (begin_info_ptr
- section
->buffer
),
7320 bfd_get_filename (abfd
));
7321 dump_die (comp_unit_die
, dwarf_die_debug
);
7324 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7325 TUs by skipping the stub and going directly to the entry in the DWO file.
7326 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7327 to get it via circuitous means. Blech. */
7328 if (comp_dir
!= NULL
)
7329 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7331 /* Skip dummy compilation units. */
7332 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7333 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7336 *result_info_ptr
= info_ptr
;
7340 /* Subroutine of init_cutu_and_read_dies to simplify it.
7341 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7342 Returns NULL if the specified DWO unit cannot be found. */
7344 static struct dwo_unit
*
7345 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7346 struct die_info
*comp_unit_die
)
7348 struct dwarf2_cu
*cu
= this_cu
->cu
;
7350 struct dwo_unit
*dwo_unit
;
7351 const char *comp_dir
, *dwo_name
;
7353 gdb_assert (cu
!= NULL
);
7355 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7356 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7357 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7359 if (this_cu
->is_debug_types
)
7361 struct signatured_type
*sig_type
;
7363 /* Since this_cu is the first member of struct signatured_type,
7364 we can go from a pointer to one to a pointer to the other. */
7365 sig_type
= (struct signatured_type
*) this_cu
;
7366 signature
= sig_type
->signature
;
7367 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7371 struct attribute
*attr
;
7373 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7375 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7377 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7378 signature
= DW_UNSND (attr
);
7379 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7386 /* Subroutine of init_cutu_and_read_dies to simplify it.
7387 See it for a description of the parameters.
7388 Read a TU directly from a DWO file, bypassing the stub. */
7391 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7392 int use_existing_cu
, int keep
,
7393 die_reader_func_ftype
*die_reader_func
,
7396 std::unique_ptr
<dwarf2_cu
> new_cu
;
7397 struct signatured_type
*sig_type
;
7398 struct die_reader_specs reader
;
7399 const gdb_byte
*info_ptr
;
7400 struct die_info
*comp_unit_die
;
7402 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7404 /* Verify we can do the following downcast, and that we have the
7406 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7407 sig_type
= (struct signatured_type
*) this_cu
;
7408 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7410 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7412 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7413 /* There's no need to do the rereading_dwo_cu handling that
7414 init_cutu_and_read_dies does since we don't read the stub. */
7418 /* If !use_existing_cu, this_cu->cu must be NULL. */
7419 gdb_assert (this_cu
->cu
== NULL
);
7420 new_cu
.reset (new dwarf2_cu (this_cu
));
7423 /* A future optimization, if needed, would be to use an existing
7424 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7425 could share abbrev tables. */
7427 /* The abbreviation table used by READER, this must live at least as long as
7429 abbrev_table_up dwo_abbrev_table
;
7431 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7432 NULL
/* stub_comp_unit_die */,
7433 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7435 &comp_unit_die
, &has_children
,
7436 &dwo_abbrev_table
) == 0)
7442 /* All the "real" work is done here. */
7443 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7445 /* This duplicates the code in init_cutu_and_read_dies,
7446 but the alternative is making the latter more complex.
7447 This function is only for the special case of using DWO files directly:
7448 no point in overly complicating the general case just to handle this. */
7449 if (new_cu
!= NULL
&& keep
)
7451 /* Link this CU into read_in_chain. */
7452 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7453 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7454 /* The chain owns it now. */
7459 /* Initialize a CU (or TU) and read its DIEs.
7460 If the CU defers to a DWO file, read the DWO file as well.
7462 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7463 Otherwise the table specified in the comp unit header is read in and used.
7464 This is an optimization for when we already have the abbrev table.
7466 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7467 Otherwise, a new CU is allocated with xmalloc.
7469 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7470 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7472 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7473 linker) then DIE_READER_FUNC will not get called. */
7476 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7477 struct abbrev_table
*abbrev_table
,
7478 int use_existing_cu
, int keep
,
7479 die_reader_func_ftype
*die_reader_func
,
7482 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7483 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7484 struct dwarf2_section_info
*section
= this_cu
->section
;
7485 bfd
*abfd
= get_section_bfd_owner (section
);
7486 struct dwarf2_cu
*cu
;
7487 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7488 struct die_reader_specs reader
;
7489 struct die_info
*comp_unit_die
;
7491 struct attribute
*attr
;
7492 struct signatured_type
*sig_type
= NULL
;
7493 struct dwarf2_section_info
*abbrev_section
;
7494 /* Non-zero if CU currently points to a DWO file and we need to
7495 reread it. When this happens we need to reread the skeleton die
7496 before we can reread the DWO file (this only applies to CUs, not TUs). */
7497 int rereading_dwo_cu
= 0;
7499 if (dwarf_die_debug
)
7500 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7501 this_cu
->is_debug_types
? "type" : "comp",
7502 sect_offset_str (this_cu
->sect_off
));
7504 if (use_existing_cu
)
7507 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7508 file (instead of going through the stub), short-circuit all of this. */
7509 if (this_cu
->reading_dwo_directly
)
7511 /* Narrow down the scope of possibilities to have to understand. */
7512 gdb_assert (this_cu
->is_debug_types
);
7513 gdb_assert (abbrev_table
== NULL
);
7514 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7515 die_reader_func
, data
);
7519 /* This is cheap if the section is already read in. */
7520 dwarf2_read_section (objfile
, section
);
7522 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7524 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7526 std::unique_ptr
<dwarf2_cu
> new_cu
;
7527 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7530 /* If this CU is from a DWO file we need to start over, we need to
7531 refetch the attributes from the skeleton CU.
7532 This could be optimized by retrieving those attributes from when we
7533 were here the first time: the previous comp_unit_die was stored in
7534 comp_unit_obstack. But there's no data yet that we need this
7536 if (cu
->dwo_unit
!= NULL
)
7537 rereading_dwo_cu
= 1;
7541 /* If !use_existing_cu, this_cu->cu must be NULL. */
7542 gdb_assert (this_cu
->cu
== NULL
);
7543 new_cu
.reset (new dwarf2_cu (this_cu
));
7547 /* Get the header. */
7548 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7550 /* We already have the header, there's no need to read it in again. */
7551 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7555 if (this_cu
->is_debug_types
)
7557 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7558 &cu
->header
, section
,
7559 abbrev_section
, info_ptr
,
7562 /* Since per_cu is the first member of struct signatured_type,
7563 we can go from a pointer to one to a pointer to the other. */
7564 sig_type
= (struct signatured_type
*) this_cu
;
7565 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7566 gdb_assert (sig_type
->type_offset_in_tu
7567 == cu
->header
.type_cu_offset_in_tu
);
7568 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7570 /* LENGTH has not been set yet for type units if we're
7571 using .gdb_index. */
7572 this_cu
->length
= get_cu_length (&cu
->header
);
7574 /* Establish the type offset that can be used to lookup the type. */
7575 sig_type
->type_offset_in_section
=
7576 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7578 this_cu
->dwarf_version
= cu
->header
.version
;
7582 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7583 &cu
->header
, section
,
7586 rcuh_kind::COMPILE
);
7588 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7589 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7590 this_cu
->dwarf_version
= cu
->header
.version
;
7594 /* Skip dummy compilation units. */
7595 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7596 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7599 /* If we don't have them yet, read the abbrevs for this compilation unit.
7600 And if we need to read them now, make sure they're freed when we're
7601 done (own the table through ABBREV_TABLE_HOLDER). */
7602 abbrev_table_up abbrev_table_holder
;
7603 if (abbrev_table
!= NULL
)
7604 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7608 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7609 cu
->header
.abbrev_sect_off
);
7610 abbrev_table
= abbrev_table_holder
.get ();
7613 /* Read the top level CU/TU die. */
7614 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7615 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7617 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7618 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7619 table from the DWO file and pass the ownership over to us. It will be
7620 referenced from READER, so we must make sure to free it after we're done
7623 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7624 DWO CU, that this test will fail (the attribute will not be present). */
7625 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7626 abbrev_table_up dwo_abbrev_table
;
7629 struct dwo_unit
*dwo_unit
;
7630 struct die_info
*dwo_comp_unit_die
;
7634 complaint (&symfile_complaints
,
7635 _("compilation unit with DW_AT_GNU_dwo_name"
7636 " has children (offset %s) [in module %s]"),
7637 sect_offset_str (this_cu
->sect_off
),
7638 bfd_get_filename (abfd
));
7640 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7641 if (dwo_unit
!= NULL
)
7643 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7644 comp_unit_die
, NULL
,
7646 &dwo_comp_unit_die
, &has_children
,
7647 &dwo_abbrev_table
) == 0)
7652 comp_unit_die
= dwo_comp_unit_die
;
7656 /* Yikes, we couldn't find the rest of the DIE, we only have
7657 the stub. A complaint has already been logged. There's
7658 not much more we can do except pass on the stub DIE to
7659 die_reader_func. We don't want to throw an error on bad
7664 /* All of the above is setup for this call. Yikes. */
7665 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7667 /* Done, clean up. */
7668 if (new_cu
!= NULL
&& keep
)
7670 /* Link this CU into read_in_chain. */
7671 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7672 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7673 /* The chain owns it now. */
7678 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7679 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7680 to have already done the lookup to find the DWO file).
7682 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7683 THIS_CU->is_debug_types, but nothing else.
7685 We fill in THIS_CU->length.
7687 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7688 linker) then DIE_READER_FUNC will not get called.
7690 THIS_CU->cu is always freed when done.
7691 This is done in order to not leave THIS_CU->cu in a state where we have
7692 to care whether it refers to the "main" CU or the DWO CU. */
7695 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7696 struct dwo_file
*dwo_file
,
7697 die_reader_func_ftype
*die_reader_func
,
7700 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7701 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7702 struct dwarf2_section_info
*section
= this_cu
->section
;
7703 bfd
*abfd
= get_section_bfd_owner (section
);
7704 struct dwarf2_section_info
*abbrev_section
;
7705 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7706 struct die_reader_specs reader
;
7707 struct die_info
*comp_unit_die
;
7710 if (dwarf_die_debug
)
7711 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7712 this_cu
->is_debug_types
? "type" : "comp",
7713 sect_offset_str (this_cu
->sect_off
));
7715 gdb_assert (this_cu
->cu
== NULL
);
7717 abbrev_section
= (dwo_file
!= NULL
7718 ? &dwo_file
->sections
.abbrev
7719 : get_abbrev_section_for_cu (this_cu
));
7721 /* This is cheap if the section is already read in. */
7722 dwarf2_read_section (objfile
, section
);
7724 struct dwarf2_cu
cu (this_cu
);
7726 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7727 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7728 &cu
.header
, section
,
7729 abbrev_section
, info_ptr
,
7730 (this_cu
->is_debug_types
7732 : rcuh_kind::COMPILE
));
7734 this_cu
->length
= get_cu_length (&cu
.header
);
7736 /* Skip dummy compilation units. */
7737 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7738 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7741 abbrev_table_up abbrev_table
7742 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7743 cu
.header
.abbrev_sect_off
);
7745 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7746 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7748 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7751 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
7752 does not lookup the specified DWO file.
7753 This cannot be used to read DWO files.
7755 THIS_CU->cu is always freed when done.
7756 This is done in order to not leave THIS_CU->cu in a state where we have
7757 to care whether it refers to the "main" CU or the DWO CU.
7758 We can revisit this if the data shows there's a performance issue. */
7761 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7762 die_reader_func_ftype
*die_reader_func
,
7765 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
7768 /* Type Unit Groups.
7770 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7771 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7772 so that all types coming from the same compilation (.o file) are grouped
7773 together. A future step could be to put the types in the same symtab as
7774 the CU the types ultimately came from. */
7777 hash_type_unit_group (const void *item
)
7779 const struct type_unit_group
*tu_group
7780 = (const struct type_unit_group
*) item
;
7782 return hash_stmt_list_entry (&tu_group
->hash
);
7786 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7788 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7789 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7791 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7794 /* Allocate a hash table for type unit groups. */
7797 allocate_type_unit_groups_table (struct objfile
*objfile
)
7799 return htab_create_alloc_ex (3,
7800 hash_type_unit_group
,
7803 &objfile
->objfile_obstack
,
7804 hashtab_obstack_allocate
,
7805 dummy_obstack_deallocate
);
7808 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7809 partial symtabs. We combine several TUs per psymtab to not let the size
7810 of any one psymtab grow too big. */
7811 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7812 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7814 /* Helper routine for get_type_unit_group.
7815 Create the type_unit_group object used to hold one or more TUs. */
7817 static struct type_unit_group
*
7818 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7820 struct dwarf2_per_objfile
*dwarf2_per_objfile
7821 = cu
->per_cu
->dwarf2_per_objfile
;
7822 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7823 struct dwarf2_per_cu_data
*per_cu
;
7824 struct type_unit_group
*tu_group
;
7826 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7827 struct type_unit_group
);
7828 per_cu
= &tu_group
->per_cu
;
7829 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7831 if (dwarf2_per_objfile
->using_index
)
7833 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7834 struct dwarf2_per_cu_quick_data
);
7838 unsigned int line_offset
= to_underlying (line_offset_struct
);
7839 struct partial_symtab
*pst
;
7842 /* Give the symtab a useful name for debug purposes. */
7843 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7844 name
= xstrprintf ("<type_units_%d>",
7845 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7847 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
7849 pst
= create_partial_symtab (per_cu
, name
);
7855 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7856 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7861 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7862 STMT_LIST is a DW_AT_stmt_list attribute. */
7864 static struct type_unit_group
*
7865 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7867 struct dwarf2_per_objfile
*dwarf2_per_objfile
7868 = cu
->per_cu
->dwarf2_per_objfile
;
7869 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7870 struct type_unit_group
*tu_group
;
7872 unsigned int line_offset
;
7873 struct type_unit_group type_unit_group_for_lookup
;
7875 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7877 dwarf2_per_objfile
->type_unit_groups
=
7878 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7881 /* Do we need to create a new group, or can we use an existing one? */
7885 line_offset
= DW_UNSND (stmt_list
);
7886 ++tu_stats
->nr_symtab_sharers
;
7890 /* Ugh, no stmt_list. Rare, but we have to handle it.
7891 We can do various things here like create one group per TU or
7892 spread them over multiple groups to split up the expansion work.
7893 To avoid worst case scenarios (too many groups or too large groups)
7894 we, umm, group them in bunches. */
7895 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7896 | (tu_stats
->nr_stmt_less_type_units
7897 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7898 ++tu_stats
->nr_stmt_less_type_units
;
7901 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7902 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7903 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7904 &type_unit_group_for_lookup
, INSERT
);
7907 tu_group
= (struct type_unit_group
*) *slot
;
7908 gdb_assert (tu_group
!= NULL
);
7912 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7913 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7915 ++tu_stats
->nr_symtabs
;
7921 /* Partial symbol tables. */
7923 /* Create a psymtab named NAME and assign it to PER_CU.
7925 The caller must fill in the following details:
7926 dirname, textlow, texthigh. */
7928 static struct partial_symtab
*
7929 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7931 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7932 struct partial_symtab
*pst
;
7934 pst
= start_psymtab_common (objfile
, name
, 0,
7935 objfile
->global_psymbols
,
7936 objfile
->static_psymbols
);
7938 pst
->psymtabs_addrmap_supported
= 1;
7940 /* This is the glue that links PST into GDB's symbol API. */
7941 pst
->read_symtab_private
= per_cu
;
7942 pst
->read_symtab
= dwarf2_read_symtab
;
7943 per_cu
->v
.psymtab
= pst
;
7948 /* The DATA object passed to process_psymtab_comp_unit_reader has this
7951 struct process_psymtab_comp_unit_data
7953 /* True if we are reading a DW_TAG_partial_unit. */
7955 int want_partial_unit
;
7957 /* The "pretend" language that is used if the CU doesn't declare a
7960 enum language pretend_language
;
7963 /* die_reader_func for process_psymtab_comp_unit. */
7966 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7967 const gdb_byte
*info_ptr
,
7968 struct die_info
*comp_unit_die
,
7972 struct dwarf2_cu
*cu
= reader
->cu
;
7973 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7974 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7975 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7977 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7978 struct partial_symtab
*pst
;
7979 enum pc_bounds_kind cu_bounds_kind
;
7980 const char *filename
;
7981 struct process_psymtab_comp_unit_data
*info
7982 = (struct process_psymtab_comp_unit_data
*) data
;
7984 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
7987 gdb_assert (! per_cu
->is_debug_types
);
7989 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
7991 cu
->list_in_scope
= &file_symbols
;
7993 /* Allocate a new partial symbol table structure. */
7994 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7995 if (filename
== NULL
)
7998 pst
= create_partial_symtab (per_cu
, filename
);
8000 /* This must be done before calling dwarf2_build_include_psymtabs. */
8001 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8003 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8005 dwarf2_find_base_address (comp_unit_die
, cu
);
8007 /* Possibly set the default values of LOWPC and HIGHPC from
8009 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8010 &best_highpc
, cu
, pst
);
8011 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8012 /* Store the contiguous range if it is not empty; it can be empty for
8013 CUs with no code. */
8014 addrmap_set_empty (objfile
->psymtabs_addrmap
,
8015 gdbarch_adjust_dwarf2_addr (gdbarch
,
8016 best_lowpc
+ baseaddr
),
8017 gdbarch_adjust_dwarf2_addr (gdbarch
,
8018 best_highpc
+ baseaddr
) - 1,
8021 /* Check if comp unit has_children.
8022 If so, read the rest of the partial symbols from this comp unit.
8023 If not, there's no more debug_info for this comp unit. */
8026 struct partial_die_info
*first_die
;
8027 CORE_ADDR lowpc
, highpc
;
8029 lowpc
= ((CORE_ADDR
) -1);
8030 highpc
= ((CORE_ADDR
) 0);
8032 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8034 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8035 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8037 /* If we didn't find a lowpc, set it to highpc to avoid
8038 complaints from `maint check'. */
8039 if (lowpc
== ((CORE_ADDR
) -1))
8042 /* If the compilation unit didn't have an explicit address range,
8043 then use the information extracted from its child dies. */
8044 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8047 best_highpc
= highpc
;
8050 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
8051 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
8053 end_psymtab_common (objfile
, pst
);
8055 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
8058 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8059 struct dwarf2_per_cu_data
*iter
;
8061 /* Fill in 'dependencies' here; we fill in 'users' in a
8063 pst
->number_of_dependencies
= len
;
8065 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8067 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8070 pst
->dependencies
[i
] = iter
->v
.psymtab
;
8072 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8075 /* Get the list of files included in the current compilation unit,
8076 and build a psymtab for each of them. */
8077 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8079 if (dwarf_read_debug
)
8081 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8083 fprintf_unfiltered (gdb_stdlog
,
8084 "Psymtab for %s unit @%s: %s - %s"
8085 ", %d global, %d static syms\n",
8086 per_cu
->is_debug_types
? "type" : "comp",
8087 sect_offset_str (per_cu
->sect_off
),
8088 paddress (gdbarch
, pst
->textlow
),
8089 paddress (gdbarch
, pst
->texthigh
),
8090 pst
->n_global_syms
, pst
->n_static_syms
);
8094 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8095 Process compilation unit THIS_CU for a psymtab. */
8098 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8099 int want_partial_unit
,
8100 enum language pretend_language
)
8102 /* If this compilation unit was already read in, free the
8103 cached copy in order to read it in again. This is
8104 necessary because we skipped some symbols when we first
8105 read in the compilation unit (see load_partial_dies).
8106 This problem could be avoided, but the benefit is unclear. */
8107 if (this_cu
->cu
!= NULL
)
8108 free_one_cached_comp_unit (this_cu
);
8110 if (this_cu
->is_debug_types
)
8111 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, build_type_psymtabs_reader
,
8115 process_psymtab_comp_unit_data info
;
8116 info
.want_partial_unit
= want_partial_unit
;
8117 info
.pretend_language
= pretend_language
;
8118 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
8119 process_psymtab_comp_unit_reader
, &info
);
8122 /* Age out any secondary CUs. */
8123 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8126 /* Reader function for build_type_psymtabs. */
8129 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8130 const gdb_byte
*info_ptr
,
8131 struct die_info
*type_unit_die
,
8135 struct dwarf2_per_objfile
*dwarf2_per_objfile
8136 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8137 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8138 struct dwarf2_cu
*cu
= reader
->cu
;
8139 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8140 struct signatured_type
*sig_type
;
8141 struct type_unit_group
*tu_group
;
8142 struct attribute
*attr
;
8143 struct partial_die_info
*first_die
;
8144 CORE_ADDR lowpc
, highpc
;
8145 struct partial_symtab
*pst
;
8147 gdb_assert (data
== NULL
);
8148 gdb_assert (per_cu
->is_debug_types
);
8149 sig_type
= (struct signatured_type
*) per_cu
;
8154 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8155 tu_group
= get_type_unit_group (cu
, attr
);
8157 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
8159 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8160 cu
->list_in_scope
= &file_symbols
;
8161 pst
= create_partial_symtab (per_cu
, "");
8164 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8166 lowpc
= (CORE_ADDR
) -1;
8167 highpc
= (CORE_ADDR
) 0;
8168 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8170 end_psymtab_common (objfile
, pst
);
8173 /* Struct used to sort TUs by their abbreviation table offset. */
8175 struct tu_abbrev_offset
8177 struct signatured_type
*sig_type
;
8178 sect_offset abbrev_offset
;
8181 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8184 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8185 const struct tu_abbrev_offset
&b
)
8187 return a
.abbrev_offset
< b
.abbrev_offset
;
8190 /* Efficiently read all the type units.
8191 This does the bulk of the work for build_type_psymtabs.
8193 The efficiency is because we sort TUs by the abbrev table they use and
8194 only read each abbrev table once. In one program there are 200K TUs
8195 sharing 8K abbrev tables.
8197 The main purpose of this function is to support building the
8198 dwarf2_per_objfile->type_unit_groups table.
8199 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8200 can collapse the search space by grouping them by stmt_list.
8201 The savings can be significant, in the same program from above the 200K TUs
8202 share 8K stmt_list tables.
8204 FUNC is expected to call get_type_unit_group, which will create the
8205 struct type_unit_group if necessary and add it to
8206 dwarf2_per_objfile->type_unit_groups. */
8209 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8211 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8212 abbrev_table_up abbrev_table
;
8213 sect_offset abbrev_offset
;
8216 /* It's up to the caller to not call us multiple times. */
8217 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8219 if (dwarf2_per_objfile
->n_type_units
== 0)
8222 /* TUs typically share abbrev tables, and there can be way more TUs than
8223 abbrev tables. Sort by abbrev table to reduce the number of times we
8224 read each abbrev table in.
8225 Alternatives are to punt or to maintain a cache of abbrev tables.
8226 This is simpler and efficient enough for now.
8228 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8229 symtab to use). Typically TUs with the same abbrev offset have the same
8230 stmt_list value too so in practice this should work well.
8232 The basic algorithm here is:
8234 sort TUs by abbrev table
8235 for each TU with same abbrev table:
8236 read abbrev table if first user
8237 read TU top level DIE
8238 [IWBN if DWO skeletons had DW_AT_stmt_list]
8241 if (dwarf_read_debug
)
8242 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8244 /* Sort in a separate table to maintain the order of all_type_units
8245 for .gdb_index: TU indices directly index all_type_units. */
8246 std::vector
<struct tu_abbrev_offset
> sorted_by_abbrev
8247 (dwarf2_per_objfile
->n_type_units
);
8248 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8250 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
8252 sorted_by_abbrev
[i
].sig_type
= sig_type
;
8253 sorted_by_abbrev
[i
].abbrev_offset
=
8254 read_abbrev_offset (dwarf2_per_objfile
,
8255 sig_type
->per_cu
.section
,
8256 sig_type
->per_cu
.sect_off
);
8258 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8259 sort_tu_by_abbrev_offset
);
8261 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8263 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8265 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
8267 /* Switch to the next abbrev table if necessary. */
8268 if (abbrev_table
== NULL
8269 || tu
->abbrev_offset
!= abbrev_offset
)
8271 abbrev_offset
= tu
->abbrev_offset
;
8273 abbrev_table_read_table (dwarf2_per_objfile
,
8274 &dwarf2_per_objfile
->abbrev
,
8276 ++tu_stats
->nr_uniq_abbrev_tables
;
8279 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
.get (),
8280 0, 0, build_type_psymtabs_reader
, NULL
);
8284 /* Print collected type unit statistics. */
8287 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8289 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8291 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8292 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
8293 dwarf2_per_objfile
->n_type_units
);
8294 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8295 tu_stats
->nr_uniq_abbrev_tables
);
8296 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8297 tu_stats
->nr_symtabs
);
8298 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8299 tu_stats
->nr_symtab_sharers
);
8300 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8301 tu_stats
->nr_stmt_less_type_units
);
8302 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8303 tu_stats
->nr_all_type_units_reallocs
);
8306 /* Traversal function for build_type_psymtabs. */
8309 build_type_psymtab_dependencies (void **slot
, void *info
)
8311 struct dwarf2_per_objfile
*dwarf2_per_objfile
8312 = (struct dwarf2_per_objfile
*) info
;
8313 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8314 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8315 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8316 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8317 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
8318 struct signatured_type
*iter
;
8321 gdb_assert (len
> 0);
8322 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8324 pst
->number_of_dependencies
= len
;
8326 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8328 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
8331 gdb_assert (iter
->per_cu
.is_debug_types
);
8332 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8333 iter
->type_unit_group
= tu_group
;
8336 VEC_free (sig_type_ptr
, tu_group
->tus
);
8341 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8342 Build partial symbol tables for the .debug_types comp-units. */
8345 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8347 if (! create_all_type_units (dwarf2_per_objfile
))
8350 build_type_psymtabs_1 (dwarf2_per_objfile
);
8353 /* Traversal function for process_skeletonless_type_unit.
8354 Read a TU in a DWO file and build partial symbols for it. */
8357 process_skeletonless_type_unit (void **slot
, void *info
)
8359 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8360 struct dwarf2_per_objfile
*dwarf2_per_objfile
8361 = (struct dwarf2_per_objfile
*) info
;
8362 struct signatured_type find_entry
, *entry
;
8364 /* If this TU doesn't exist in the global table, add it and read it in. */
8366 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8368 dwarf2_per_objfile
->signatured_types
8369 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8372 find_entry
.signature
= dwo_unit
->signature
;
8373 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8375 /* If we've already seen this type there's nothing to do. What's happening
8376 is we're doing our own version of comdat-folding here. */
8380 /* This does the job that create_all_type_units would have done for
8382 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8383 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8386 /* This does the job that build_type_psymtabs_1 would have done. */
8387 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
8388 build_type_psymtabs_reader
, NULL
);
8393 /* Traversal function for process_skeletonless_type_units. */
8396 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8398 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8400 if (dwo_file
->tus
!= NULL
)
8402 htab_traverse_noresize (dwo_file
->tus
,
8403 process_skeletonless_type_unit
, info
);
8409 /* Scan all TUs of DWO files, verifying we've processed them.
8410 This is needed in case a TU was emitted without its skeleton.
8411 Note: This can't be done until we know what all the DWO files are. */
8414 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8416 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8417 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8418 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8420 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
8421 process_dwo_file_for_skeletonless_type_units
,
8422 dwarf2_per_objfile
);
8426 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8429 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8433 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
8435 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
8436 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8442 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8444 /* Set the 'user' field only if it is not already set. */
8445 if (pst
->dependencies
[j
]->user
== NULL
)
8446 pst
->dependencies
[j
]->user
= pst
;
8451 /* Build the partial symbol table by doing a quick pass through the
8452 .debug_info and .debug_abbrev sections. */
8455 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8458 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8460 if (dwarf_read_debug
)
8462 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8463 objfile_name (objfile
));
8466 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8468 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8470 /* Any cached compilation units will be linked by the per-objfile
8471 read_in_chain. Make sure to free them when we're done. */
8472 free_cached_comp_units
freer (dwarf2_per_objfile
);
8474 build_type_psymtabs (dwarf2_per_objfile
);
8476 create_all_comp_units (dwarf2_per_objfile
);
8478 /* Create a temporary address map on a temporary obstack. We later
8479 copy this to the final obstack. */
8480 auto_obstack temp_obstack
;
8482 scoped_restore save_psymtabs_addrmap
8483 = make_scoped_restore (&objfile
->psymtabs_addrmap
,
8484 addrmap_create_mutable (&temp_obstack
));
8486 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
8488 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
8490 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8493 /* This has to wait until we read the CUs, we need the list of DWOs. */
8494 process_skeletonless_type_units (dwarf2_per_objfile
);
8496 /* Now that all TUs have been processed we can fill in the dependencies. */
8497 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8499 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8500 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8503 if (dwarf_read_debug
)
8504 print_tu_stats (dwarf2_per_objfile
);
8506 set_partial_user (dwarf2_per_objfile
);
8508 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
8509 &objfile
->objfile_obstack
);
8510 /* At this point we want to keep the address map. */
8511 save_psymtabs_addrmap
.release ();
8513 if (dwarf_read_debug
)
8514 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8515 objfile_name (objfile
));
8518 /* die_reader_func for load_partial_comp_unit. */
8521 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8522 const gdb_byte
*info_ptr
,
8523 struct die_info
*comp_unit_die
,
8527 struct dwarf2_cu
*cu
= reader
->cu
;
8529 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8531 /* Check if comp unit has_children.
8532 If so, read the rest of the partial symbols from this comp unit.
8533 If not, there's no more debug_info for this comp unit. */
8535 load_partial_dies (reader
, info_ptr
, 0);
8538 /* Load the partial DIEs for a secondary CU into memory.
8539 This is also used when rereading a primary CU with load_all_dies. */
8542 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8544 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
8545 load_partial_comp_unit_reader
, NULL
);
8549 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8550 struct dwarf2_section_info
*section
,
8551 struct dwarf2_section_info
*abbrev_section
,
8552 unsigned int is_dwz
,
8555 struct dwarf2_per_cu_data
***all_comp_units
)
8557 const gdb_byte
*info_ptr
;
8558 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8560 if (dwarf_read_debug
)
8561 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8562 get_section_name (section
),
8563 get_section_file_name (section
));
8565 dwarf2_read_section (objfile
, section
);
8567 info_ptr
= section
->buffer
;
8569 while (info_ptr
< section
->buffer
+ section
->size
)
8571 struct dwarf2_per_cu_data
*this_cu
;
8573 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8575 comp_unit_head cu_header
;
8576 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8577 abbrev_section
, info_ptr
,
8578 rcuh_kind::COMPILE
);
8580 /* Save the compilation unit for later lookup. */
8581 if (cu_header
.unit_type
!= DW_UT_type
)
8583 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8584 struct dwarf2_per_cu_data
);
8585 memset (this_cu
, 0, sizeof (*this_cu
));
8589 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8590 struct signatured_type
);
8591 memset (sig_type
, 0, sizeof (*sig_type
));
8592 sig_type
->signature
= cu_header
.signature
;
8593 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8594 this_cu
= &sig_type
->per_cu
;
8596 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8597 this_cu
->sect_off
= sect_off
;
8598 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8599 this_cu
->is_dwz
= is_dwz
;
8600 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8601 this_cu
->section
= section
;
8603 if (*n_comp_units
== *n_allocated
)
8606 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
8607 *all_comp_units
, *n_allocated
);
8609 (*all_comp_units
)[*n_comp_units
] = this_cu
;
8612 info_ptr
= info_ptr
+ this_cu
->length
;
8616 /* Create a list of all compilation units in OBJFILE.
8617 This is only done for -readnow and building partial symtabs. */
8620 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8624 struct dwarf2_per_cu_data
**all_comp_units
;
8625 struct dwz_file
*dwz
;
8626 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8630 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
8632 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8633 &dwarf2_per_objfile
->abbrev
, 0,
8634 &n_allocated
, &n_comp_units
, &all_comp_units
);
8636 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8638 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8639 1, &n_allocated
, &n_comp_units
,
8642 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
8643 struct dwarf2_per_cu_data
*,
8645 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
8646 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
8647 xfree (all_comp_units
);
8648 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
8651 /* Process all loaded DIEs for compilation unit CU, starting at
8652 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8653 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8654 DW_AT_ranges). See the comments of add_partial_subprogram on how
8655 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8658 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8659 CORE_ADDR
*highpc
, int set_addrmap
,
8660 struct dwarf2_cu
*cu
)
8662 struct partial_die_info
*pdi
;
8664 /* Now, march along the PDI's, descending into ones which have
8665 interesting children but skipping the children of the other ones,
8666 until we reach the end of the compilation unit. */
8674 /* Anonymous namespaces or modules have no name but have interesting
8675 children, so we need to look at them. Ditto for anonymous
8678 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8679 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8680 || pdi
->tag
== DW_TAG_imported_unit
8681 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8685 case DW_TAG_subprogram
:
8686 case DW_TAG_inlined_subroutine
:
8687 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8689 case DW_TAG_constant
:
8690 case DW_TAG_variable
:
8691 case DW_TAG_typedef
:
8692 case DW_TAG_union_type
:
8693 if (!pdi
->is_declaration
)
8695 add_partial_symbol (pdi
, cu
);
8698 case DW_TAG_class_type
:
8699 case DW_TAG_interface_type
:
8700 case DW_TAG_structure_type
:
8701 if (!pdi
->is_declaration
)
8703 add_partial_symbol (pdi
, cu
);
8705 if ((cu
->language
== language_rust
8706 || cu
->language
== language_cplus
) && pdi
->has_children
)
8707 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8710 case DW_TAG_enumeration_type
:
8711 if (!pdi
->is_declaration
)
8712 add_partial_enumeration (pdi
, cu
);
8714 case DW_TAG_base_type
:
8715 case DW_TAG_subrange_type
:
8716 /* File scope base type definitions are added to the partial
8718 add_partial_symbol (pdi
, cu
);
8720 case DW_TAG_namespace
:
8721 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8724 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8726 case DW_TAG_imported_unit
:
8728 struct dwarf2_per_cu_data
*per_cu
;
8730 /* For now we don't handle imported units in type units. */
8731 if (cu
->per_cu
->is_debug_types
)
8733 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8734 " supported in type units [in module %s]"),
8735 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8738 per_cu
= dwarf2_find_containing_comp_unit
8739 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8740 cu
->per_cu
->dwarf2_per_objfile
);
8742 /* Go read the partial unit, if needed. */
8743 if (per_cu
->v
.psymtab
== NULL
)
8744 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8746 VEC_safe_push (dwarf2_per_cu_ptr
,
8747 cu
->per_cu
->imported_symtabs
, per_cu
);
8750 case DW_TAG_imported_declaration
:
8751 add_partial_symbol (pdi
, cu
);
8758 /* If the die has a sibling, skip to the sibling. */
8760 pdi
= pdi
->die_sibling
;
8764 /* Functions used to compute the fully scoped name of a partial DIE.
8766 Normally, this is simple. For C++, the parent DIE's fully scoped
8767 name is concatenated with "::" and the partial DIE's name.
8768 Enumerators are an exception; they use the scope of their parent
8769 enumeration type, i.e. the name of the enumeration type is not
8770 prepended to the enumerator.
8772 There are two complexities. One is DW_AT_specification; in this
8773 case "parent" means the parent of the target of the specification,
8774 instead of the direct parent of the DIE. The other is compilers
8775 which do not emit DW_TAG_namespace; in this case we try to guess
8776 the fully qualified name of structure types from their members'
8777 linkage names. This must be done using the DIE's children rather
8778 than the children of any DW_AT_specification target. We only need
8779 to do this for structures at the top level, i.e. if the target of
8780 any DW_AT_specification (if any; otherwise the DIE itself) does not
8783 /* Compute the scope prefix associated with PDI's parent, in
8784 compilation unit CU. The result will be allocated on CU's
8785 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8786 field. NULL is returned if no prefix is necessary. */
8788 partial_die_parent_scope (struct partial_die_info
*pdi
,
8789 struct dwarf2_cu
*cu
)
8791 const char *grandparent_scope
;
8792 struct partial_die_info
*parent
, *real_pdi
;
8794 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8795 then this means the parent of the specification DIE. */
8798 while (real_pdi
->has_specification
)
8799 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
8800 real_pdi
->spec_is_dwz
, cu
);
8802 parent
= real_pdi
->die_parent
;
8806 if (parent
->scope_set
)
8807 return parent
->scope
;
8811 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8813 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8814 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8815 Work around this problem here. */
8816 if (cu
->language
== language_cplus
8817 && parent
->tag
== DW_TAG_namespace
8818 && strcmp (parent
->name
, "::") == 0
8819 && grandparent_scope
== NULL
)
8821 parent
->scope
= NULL
;
8822 parent
->scope_set
= 1;
8826 if (pdi
->tag
== DW_TAG_enumerator
)
8827 /* Enumerators should not get the name of the enumeration as a prefix. */
8828 parent
->scope
= grandparent_scope
;
8829 else if (parent
->tag
== DW_TAG_namespace
8830 || parent
->tag
== DW_TAG_module
8831 || parent
->tag
== DW_TAG_structure_type
8832 || parent
->tag
== DW_TAG_class_type
8833 || parent
->tag
== DW_TAG_interface_type
8834 || parent
->tag
== DW_TAG_union_type
8835 || parent
->tag
== DW_TAG_enumeration_type
)
8837 if (grandparent_scope
== NULL
)
8838 parent
->scope
= parent
->name
;
8840 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8842 parent
->name
, 0, cu
);
8846 /* FIXME drow/2004-04-01: What should we be doing with
8847 function-local names? For partial symbols, we should probably be
8849 complaint (&symfile_complaints
,
8850 _("unhandled containing DIE tag %d for DIE at %s"),
8851 parent
->tag
, sect_offset_str (pdi
->sect_off
));
8852 parent
->scope
= grandparent_scope
;
8855 parent
->scope_set
= 1;
8856 return parent
->scope
;
8859 /* Return the fully scoped name associated with PDI, from compilation unit
8860 CU. The result will be allocated with malloc. */
8863 partial_die_full_name (struct partial_die_info
*pdi
,
8864 struct dwarf2_cu
*cu
)
8866 const char *parent_scope
;
8868 /* If this is a template instantiation, we can not work out the
8869 template arguments from partial DIEs. So, unfortunately, we have
8870 to go through the full DIEs. At least any work we do building
8871 types here will be reused if full symbols are loaded later. */
8872 if (pdi
->has_template_arguments
)
8876 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8878 struct die_info
*die
;
8879 struct attribute attr
;
8880 struct dwarf2_cu
*ref_cu
= cu
;
8882 /* DW_FORM_ref_addr is using section offset. */
8883 attr
.name
= (enum dwarf_attribute
) 0;
8884 attr
.form
= DW_FORM_ref_addr
;
8885 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8886 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8888 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8892 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8893 if (parent_scope
== NULL
)
8896 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
8900 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8902 struct dwarf2_per_objfile
*dwarf2_per_objfile
8903 = cu
->per_cu
->dwarf2_per_objfile
;
8904 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8905 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8907 const char *actual_name
= NULL
;
8909 char *built_actual_name
;
8911 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8913 built_actual_name
= partial_die_full_name (pdi
, cu
);
8914 if (built_actual_name
!= NULL
)
8915 actual_name
= built_actual_name
;
8917 if (actual_name
== NULL
)
8918 actual_name
= pdi
->name
;
8922 case DW_TAG_inlined_subroutine
:
8923 case DW_TAG_subprogram
:
8924 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
8925 if (pdi
->is_external
|| cu
->language
== language_ada
)
8927 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
8928 of the global scope. But in Ada, we want to be able to access
8929 nested procedures globally. So all Ada subprograms are stored
8930 in the global scope. */
8931 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8932 built_actual_name
!= NULL
,
8933 VAR_DOMAIN
, LOC_BLOCK
,
8934 &objfile
->global_psymbols
,
8935 addr
, cu
->language
, objfile
);
8939 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8940 built_actual_name
!= NULL
,
8941 VAR_DOMAIN
, LOC_BLOCK
,
8942 &objfile
->static_psymbols
,
8943 addr
, cu
->language
, objfile
);
8946 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8947 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8949 case DW_TAG_constant
:
8951 std::vector
<partial_symbol
*> *list
;
8953 if (pdi
->is_external
)
8954 list
= &objfile
->global_psymbols
;
8956 list
= &objfile
->static_psymbols
;
8957 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8958 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8959 list
, 0, cu
->language
, objfile
);
8962 case DW_TAG_variable
:
8964 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8968 && !dwarf2_per_objfile
->has_section_at_zero
)
8970 /* A global or static variable may also have been stripped
8971 out by the linker if unused, in which case its address
8972 will be nullified; do not add such variables into partial
8973 symbol table then. */
8975 else if (pdi
->is_external
)
8978 Don't enter into the minimal symbol tables as there is
8979 a minimal symbol table entry from the ELF symbols already.
8980 Enter into partial symbol table if it has a location
8981 descriptor or a type.
8982 If the location descriptor is missing, new_symbol will create
8983 a LOC_UNRESOLVED symbol, the address of the variable will then
8984 be determined from the minimal symbol table whenever the variable
8986 The address for the partial symbol table entry is not
8987 used by GDB, but it comes in handy for debugging partial symbol
8990 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8991 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8992 built_actual_name
!= NULL
,
8993 VAR_DOMAIN
, LOC_STATIC
,
8994 &objfile
->global_psymbols
,
8996 cu
->language
, objfile
);
9000 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9002 /* Static Variable. Skip symbols whose value we cannot know (those
9003 without location descriptors or constant values). */
9004 if (!has_loc
&& !pdi
->has_const_value
)
9006 xfree (built_actual_name
);
9010 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9011 built_actual_name
!= NULL
,
9012 VAR_DOMAIN
, LOC_STATIC
,
9013 &objfile
->static_psymbols
,
9014 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
9015 cu
->language
, objfile
);
9018 case DW_TAG_typedef
:
9019 case DW_TAG_base_type
:
9020 case DW_TAG_subrange_type
:
9021 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9022 built_actual_name
!= NULL
,
9023 VAR_DOMAIN
, LOC_TYPEDEF
,
9024 &objfile
->static_psymbols
,
9025 0, cu
->language
, objfile
);
9027 case DW_TAG_imported_declaration
:
9028 case DW_TAG_namespace
:
9029 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9030 built_actual_name
!= NULL
,
9031 VAR_DOMAIN
, LOC_TYPEDEF
,
9032 &objfile
->global_psymbols
,
9033 0, cu
->language
, objfile
);
9036 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9037 built_actual_name
!= NULL
,
9038 MODULE_DOMAIN
, LOC_TYPEDEF
,
9039 &objfile
->global_psymbols
,
9040 0, cu
->language
, objfile
);
9042 case DW_TAG_class_type
:
9043 case DW_TAG_interface_type
:
9044 case DW_TAG_structure_type
:
9045 case DW_TAG_union_type
:
9046 case DW_TAG_enumeration_type
:
9047 /* Skip external references. The DWARF standard says in the section
9048 about "Structure, Union, and Class Type Entries": "An incomplete
9049 structure, union or class type is represented by a structure,
9050 union or class entry that does not have a byte size attribute
9051 and that has a DW_AT_declaration attribute." */
9052 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9054 xfree (built_actual_name
);
9058 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9059 static vs. global. */
9060 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9061 built_actual_name
!= NULL
,
9062 STRUCT_DOMAIN
, LOC_TYPEDEF
,
9063 cu
->language
== language_cplus
9064 ? &objfile
->global_psymbols
9065 : &objfile
->static_psymbols
,
9066 0, cu
->language
, objfile
);
9069 case DW_TAG_enumerator
:
9070 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9071 built_actual_name
!= NULL
,
9072 VAR_DOMAIN
, LOC_CONST
,
9073 cu
->language
== language_cplus
9074 ? &objfile
->global_psymbols
9075 : &objfile
->static_psymbols
,
9076 0, cu
->language
, objfile
);
9082 xfree (built_actual_name
);
9085 /* Read a partial die corresponding to a namespace; also, add a symbol
9086 corresponding to that namespace to the symbol table. NAMESPACE is
9087 the name of the enclosing namespace. */
9090 add_partial_namespace (struct partial_die_info
*pdi
,
9091 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9092 int set_addrmap
, struct dwarf2_cu
*cu
)
9094 /* Add a symbol for the namespace. */
9096 add_partial_symbol (pdi
, cu
);
9098 /* Now scan partial symbols in that namespace. */
9100 if (pdi
->has_children
)
9101 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9104 /* Read a partial die corresponding to a Fortran module. */
9107 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9108 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9110 /* Add a symbol for the namespace. */
9112 add_partial_symbol (pdi
, cu
);
9114 /* Now scan partial symbols in that module. */
9116 if (pdi
->has_children
)
9117 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9120 /* Read a partial die corresponding to a subprogram or an inlined
9121 subprogram and create a partial symbol for that subprogram.
9122 When the CU language allows it, this routine also defines a partial
9123 symbol for each nested subprogram that this subprogram contains.
9124 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9125 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9127 PDI may also be a lexical block, in which case we simply search
9128 recursively for subprograms defined inside that lexical block.
9129 Again, this is only performed when the CU language allows this
9130 type of definitions. */
9133 add_partial_subprogram (struct partial_die_info
*pdi
,
9134 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9135 int set_addrmap
, struct dwarf2_cu
*cu
)
9137 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9139 if (pdi
->has_pc_info
)
9141 if (pdi
->lowpc
< *lowpc
)
9142 *lowpc
= pdi
->lowpc
;
9143 if (pdi
->highpc
> *highpc
)
9144 *highpc
= pdi
->highpc
;
9147 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9148 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9153 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9154 SECT_OFF_TEXT (objfile
));
9155 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9156 pdi
->lowpc
+ baseaddr
);
9157 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9158 pdi
->highpc
+ baseaddr
);
9159 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
9160 cu
->per_cu
->v
.psymtab
);
9164 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9166 if (!pdi
->is_declaration
)
9167 /* Ignore subprogram DIEs that do not have a name, they are
9168 illegal. Do not emit a complaint at this point, we will
9169 do so when we convert this psymtab into a symtab. */
9171 add_partial_symbol (pdi
, cu
);
9175 if (! pdi
->has_children
)
9178 if (cu
->language
== language_ada
)
9180 pdi
= pdi
->die_child
;
9184 if (pdi
->tag
== DW_TAG_subprogram
9185 || pdi
->tag
== DW_TAG_inlined_subroutine
9186 || pdi
->tag
== DW_TAG_lexical_block
)
9187 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9188 pdi
= pdi
->die_sibling
;
9193 /* Read a partial die corresponding to an enumeration type. */
9196 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9197 struct dwarf2_cu
*cu
)
9199 struct partial_die_info
*pdi
;
9201 if (enum_pdi
->name
!= NULL
)
9202 add_partial_symbol (enum_pdi
, cu
);
9204 pdi
= enum_pdi
->die_child
;
9207 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9208 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
9210 add_partial_symbol (pdi
, cu
);
9211 pdi
= pdi
->die_sibling
;
9215 /* Return the initial uleb128 in the die at INFO_PTR. */
9218 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9220 unsigned int bytes_read
;
9222 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9225 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9226 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9228 Return the corresponding abbrev, or NULL if the number is zero (indicating
9229 an empty DIE). In either case *BYTES_READ will be set to the length of
9230 the initial number. */
9232 static struct abbrev_info
*
9233 peek_die_abbrev (const die_reader_specs
&reader
,
9234 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9236 dwarf2_cu
*cu
= reader
.cu
;
9237 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9238 unsigned int abbrev_number
9239 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9241 if (abbrev_number
== 0)
9244 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9247 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9248 " at offset %s [in module %s]"),
9249 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9250 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9256 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9257 Returns a pointer to the end of a series of DIEs, terminated by an empty
9258 DIE. Any children of the skipped DIEs will also be skipped. */
9260 static const gdb_byte
*
9261 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9265 unsigned int bytes_read
;
9266 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9269 return info_ptr
+ bytes_read
;
9271 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9275 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9276 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9277 abbrev corresponding to that skipped uleb128 should be passed in
9278 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9281 static const gdb_byte
*
9282 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9283 struct abbrev_info
*abbrev
)
9285 unsigned int bytes_read
;
9286 struct attribute attr
;
9287 bfd
*abfd
= reader
->abfd
;
9288 struct dwarf2_cu
*cu
= reader
->cu
;
9289 const gdb_byte
*buffer
= reader
->buffer
;
9290 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9291 unsigned int form
, i
;
9293 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9295 /* The only abbrev we care about is DW_AT_sibling. */
9296 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9298 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9299 if (attr
.form
== DW_FORM_ref_addr
)
9300 complaint (&symfile_complaints
,
9301 _("ignoring absolute DW_AT_sibling"));
9304 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9305 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9307 if (sibling_ptr
< info_ptr
)
9308 complaint (&symfile_complaints
,
9309 _("DW_AT_sibling points backwards"));
9310 else if (sibling_ptr
> reader
->buffer_end
)
9311 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9317 /* If it isn't DW_AT_sibling, skip this attribute. */
9318 form
= abbrev
->attrs
[i
].form
;
9322 case DW_FORM_ref_addr
:
9323 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9324 and later it is offset sized. */
9325 if (cu
->header
.version
== 2)
9326 info_ptr
+= cu
->header
.addr_size
;
9328 info_ptr
+= cu
->header
.offset_size
;
9330 case DW_FORM_GNU_ref_alt
:
9331 info_ptr
+= cu
->header
.offset_size
;
9334 info_ptr
+= cu
->header
.addr_size
;
9341 case DW_FORM_flag_present
:
9342 case DW_FORM_implicit_const
:
9354 case DW_FORM_ref_sig8
:
9357 case DW_FORM_data16
:
9360 case DW_FORM_string
:
9361 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9362 info_ptr
+= bytes_read
;
9364 case DW_FORM_sec_offset
:
9366 case DW_FORM_GNU_strp_alt
:
9367 info_ptr
+= cu
->header
.offset_size
;
9369 case DW_FORM_exprloc
:
9371 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9372 info_ptr
+= bytes_read
;
9374 case DW_FORM_block1
:
9375 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9377 case DW_FORM_block2
:
9378 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9380 case DW_FORM_block4
:
9381 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9385 case DW_FORM_ref_udata
:
9386 case DW_FORM_GNU_addr_index
:
9387 case DW_FORM_GNU_str_index
:
9388 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9390 case DW_FORM_indirect
:
9391 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9392 info_ptr
+= bytes_read
;
9393 /* We need to continue parsing from here, so just go back to
9395 goto skip_attribute
;
9398 error (_("Dwarf Error: Cannot handle %s "
9399 "in DWARF reader [in module %s]"),
9400 dwarf_form_name (form
),
9401 bfd_get_filename (abfd
));
9405 if (abbrev
->has_children
)
9406 return skip_children (reader
, info_ptr
);
9411 /* Locate ORIG_PDI's sibling.
9412 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9414 static const gdb_byte
*
9415 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9416 struct partial_die_info
*orig_pdi
,
9417 const gdb_byte
*info_ptr
)
9419 /* Do we know the sibling already? */
9421 if (orig_pdi
->sibling
)
9422 return orig_pdi
->sibling
;
9424 /* Are there any children to deal with? */
9426 if (!orig_pdi
->has_children
)
9429 /* Skip the children the long way. */
9431 return skip_children (reader
, info_ptr
);
9434 /* Expand this partial symbol table into a full symbol table. SELF is
9438 dwarf2_read_symtab (struct partial_symtab
*self
,
9439 struct objfile
*objfile
)
9441 struct dwarf2_per_objfile
*dwarf2_per_objfile
9442 = get_dwarf2_per_objfile (objfile
);
9446 warning (_("bug: psymtab for %s is already read in."),
9453 printf_filtered (_("Reading in symbols for %s..."),
9455 gdb_flush (gdb_stdout
);
9458 /* If this psymtab is constructed from a debug-only objfile, the
9459 has_section_at_zero flag will not necessarily be correct. We
9460 can get the correct value for this flag by looking at the data
9461 associated with the (presumably stripped) associated objfile. */
9462 if (objfile
->separate_debug_objfile_backlink
)
9464 struct dwarf2_per_objfile
*dpo_backlink
9465 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9467 dwarf2_per_objfile
->has_section_at_zero
9468 = dpo_backlink
->has_section_at_zero
;
9471 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9473 psymtab_to_symtab_1 (self
);
9475 /* Finish up the debug error message. */
9477 printf_filtered (_("done.\n"));
9480 process_cu_includes (dwarf2_per_objfile
);
9483 /* Reading in full CUs. */
9485 /* Add PER_CU to the queue. */
9488 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9489 enum language pretend_language
)
9491 struct dwarf2_queue_item
*item
;
9494 item
= XNEW (struct dwarf2_queue_item
);
9495 item
->per_cu
= per_cu
;
9496 item
->pretend_language
= pretend_language
;
9499 if (dwarf2_queue
== NULL
)
9500 dwarf2_queue
= item
;
9502 dwarf2_queue_tail
->next
= item
;
9504 dwarf2_queue_tail
= item
;
9507 /* If PER_CU is not yet queued, add it to the queue.
9508 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9510 The result is non-zero if PER_CU was queued, otherwise the result is zero
9511 meaning either PER_CU is already queued or it is already loaded.
9513 N.B. There is an invariant here that if a CU is queued then it is loaded.
9514 The caller is required to load PER_CU if we return non-zero. */
9517 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9518 struct dwarf2_per_cu_data
*per_cu
,
9519 enum language pretend_language
)
9521 /* We may arrive here during partial symbol reading, if we need full
9522 DIEs to process an unusual case (e.g. template arguments). Do
9523 not queue PER_CU, just tell our caller to load its DIEs. */
9524 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9526 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9531 /* Mark the dependence relation so that we don't flush PER_CU
9533 if (dependent_cu
!= NULL
)
9534 dwarf2_add_dependence (dependent_cu
, per_cu
);
9536 /* If it's already on the queue, we have nothing to do. */
9540 /* If the compilation unit is already loaded, just mark it as
9542 if (per_cu
->cu
!= NULL
)
9544 per_cu
->cu
->last_used
= 0;
9548 /* Add it to the queue. */
9549 queue_comp_unit (per_cu
, pretend_language
);
9554 /* Process the queue. */
9557 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9559 struct dwarf2_queue_item
*item
, *next_item
;
9561 if (dwarf_read_debug
)
9563 fprintf_unfiltered (gdb_stdlog
,
9564 "Expanding one or more symtabs of objfile %s ...\n",
9565 objfile_name (dwarf2_per_objfile
->objfile
));
9568 /* The queue starts out with one item, but following a DIE reference
9569 may load a new CU, adding it to the end of the queue. */
9570 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9572 if ((dwarf2_per_objfile
->using_index
9573 ? !item
->per_cu
->v
.quick
->compunit_symtab
9574 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9575 /* Skip dummy CUs. */
9576 && item
->per_cu
->cu
!= NULL
)
9578 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9579 unsigned int debug_print_threshold
;
9582 if (per_cu
->is_debug_types
)
9584 struct signatured_type
*sig_type
=
9585 (struct signatured_type
*) per_cu
;
9587 sprintf (buf
, "TU %s at offset %s",
9588 hex_string (sig_type
->signature
),
9589 sect_offset_str (per_cu
->sect_off
));
9590 /* There can be 100s of TUs.
9591 Only print them in verbose mode. */
9592 debug_print_threshold
= 2;
9596 sprintf (buf
, "CU at offset %s",
9597 sect_offset_str (per_cu
->sect_off
));
9598 debug_print_threshold
= 1;
9601 if (dwarf_read_debug
>= debug_print_threshold
)
9602 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9604 if (per_cu
->is_debug_types
)
9605 process_full_type_unit (per_cu
, item
->pretend_language
);
9607 process_full_comp_unit (per_cu
, item
->pretend_language
);
9609 if (dwarf_read_debug
>= debug_print_threshold
)
9610 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9613 item
->per_cu
->queued
= 0;
9614 next_item
= item
->next
;
9618 dwarf2_queue_tail
= NULL
;
9620 if (dwarf_read_debug
)
9622 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9623 objfile_name (dwarf2_per_objfile
->objfile
));
9627 /* Read in full symbols for PST, and anything it depends on. */
9630 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9632 struct dwarf2_per_cu_data
*per_cu
;
9638 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9639 if (!pst
->dependencies
[i
]->readin
9640 && pst
->dependencies
[i
]->user
== NULL
)
9642 /* Inform about additional files that need to be read in. */
9645 /* FIXME: i18n: Need to make this a single string. */
9646 fputs_filtered (" ", gdb_stdout
);
9648 fputs_filtered ("and ", gdb_stdout
);
9650 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9651 wrap_here (""); /* Flush output. */
9652 gdb_flush (gdb_stdout
);
9654 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9657 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9661 /* It's an include file, no symbols to read for it.
9662 Everything is in the parent symtab. */
9667 dw2_do_instantiate_symtab (per_cu
);
9670 /* Trivial hash function for die_info: the hash value of a DIE
9671 is its offset in .debug_info for this objfile. */
9674 die_hash (const void *item
)
9676 const struct die_info
*die
= (const struct die_info
*) item
;
9678 return to_underlying (die
->sect_off
);
9681 /* Trivial comparison function for die_info structures: two DIEs
9682 are equal if they have the same offset. */
9685 die_eq (const void *item_lhs
, const void *item_rhs
)
9687 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9688 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9690 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9693 /* die_reader_func for load_full_comp_unit.
9694 This is identical to read_signatured_type_reader,
9695 but is kept separate for now. */
9698 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9699 const gdb_byte
*info_ptr
,
9700 struct die_info
*comp_unit_die
,
9704 struct dwarf2_cu
*cu
= reader
->cu
;
9705 enum language
*language_ptr
= (enum language
*) data
;
9707 gdb_assert (cu
->die_hash
== NULL
);
9709 htab_create_alloc_ex (cu
->header
.length
/ 12,
9713 &cu
->comp_unit_obstack
,
9714 hashtab_obstack_allocate
,
9715 dummy_obstack_deallocate
);
9718 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9719 &info_ptr
, comp_unit_die
);
9720 cu
->dies
= comp_unit_die
;
9721 /* comp_unit_die is not stored in die_hash, no need. */
9723 /* We try not to read any attributes in this function, because not
9724 all CUs needed for references have been loaded yet, and symbol
9725 table processing isn't initialized. But we have to set the CU language,
9726 or we won't be able to build types correctly.
9727 Similarly, if we do not read the producer, we can not apply
9728 producer-specific interpretation. */
9729 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9732 /* Load the DIEs associated with PER_CU into memory. */
9735 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9736 enum language pretend_language
)
9738 gdb_assert (! this_cu
->is_debug_types
);
9740 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
9741 load_full_comp_unit_reader
, &pretend_language
);
9744 /* Add a DIE to the delayed physname list. */
9747 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9748 const char *name
, struct die_info
*die
,
9749 struct dwarf2_cu
*cu
)
9751 struct delayed_method_info mi
;
9753 mi
.fnfield_index
= fnfield_index
;
9757 cu
->method_list
.push_back (mi
);
9760 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9761 "const" / "volatile". If so, decrements LEN by the length of the
9762 modifier and return true. Otherwise return false. */
9766 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9768 size_t mod_len
= sizeof (mod
) - 1;
9769 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9777 /* Compute the physnames of any methods on the CU's method list.
9779 The computation of method physnames is delayed in order to avoid the
9780 (bad) condition that one of the method's formal parameters is of an as yet
9784 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9786 /* Only C++ delays computing physnames. */
9787 if (cu
->method_list
.empty ())
9789 gdb_assert (cu
->language
== language_cplus
);
9791 for (struct delayed_method_info
&mi
: cu
->method_list
)
9793 const char *physname
;
9794 struct fn_fieldlist
*fn_flp
9795 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9796 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9797 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9798 = physname
? physname
: "";
9800 /* Since there's no tag to indicate whether a method is a
9801 const/volatile overload, extract that information out of the
9803 if (physname
!= NULL
)
9805 size_t len
= strlen (physname
);
9809 if (physname
[len
] == ')') /* shortcut */
9811 else if (check_modifier (physname
, len
, " const"))
9812 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9813 else if (check_modifier (physname
, len
, " volatile"))
9814 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9821 /* The list is no longer needed. */
9822 cu
->method_list
.clear ();
9825 /* Go objects should be embedded in a DW_TAG_module DIE,
9826 and it's not clear if/how imported objects will appear.
9827 To keep Go support simple until that's worked out,
9828 go back through what we've read and create something usable.
9829 We could do this while processing each DIE, and feels kinda cleaner,
9830 but that way is more invasive.
9831 This is to, for example, allow the user to type "p var" or "b main"
9832 without having to specify the package name, and allow lookups
9833 of module.object to work in contexts that use the expression
9837 fixup_go_packaging (struct dwarf2_cu
*cu
)
9839 char *package_name
= NULL
;
9840 struct pending
*list
;
9843 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
9845 for (i
= 0; i
< list
->nsyms
; ++i
)
9847 struct symbol
*sym
= list
->symbol
[i
];
9849 if (SYMBOL_LANGUAGE (sym
) == language_go
9850 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9852 char *this_package_name
= go_symbol_package_name (sym
);
9854 if (this_package_name
== NULL
)
9856 if (package_name
== NULL
)
9857 package_name
= this_package_name
;
9860 struct objfile
*objfile
9861 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9862 if (strcmp (package_name
, this_package_name
) != 0)
9863 complaint (&symfile_complaints
,
9864 _("Symtab %s has objects from two different Go packages: %s and %s"),
9865 (symbol_symtab (sym
) != NULL
9866 ? symtab_to_filename_for_display
9867 (symbol_symtab (sym
))
9868 : objfile_name (objfile
)),
9869 this_package_name
, package_name
);
9870 xfree (this_package_name
);
9876 if (package_name
!= NULL
)
9878 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9879 const char *saved_package_name
9880 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
9882 strlen (package_name
));
9883 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9884 saved_package_name
);
9887 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9889 sym
= allocate_symbol (objfile
);
9890 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
9891 SYMBOL_SET_NAMES (sym
, saved_package_name
,
9892 strlen (saved_package_name
), 0, objfile
);
9893 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9894 e.g., "main" finds the "main" module and not C's main(). */
9895 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9896 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9897 SYMBOL_TYPE (sym
) = type
;
9899 add_symbol_to_list (sym
, &global_symbols
);
9901 xfree (package_name
);
9905 /* Allocate a fully-qualified name consisting of the two parts on the
9909 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9911 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9914 /* A helper that allocates a struct discriminant_info to attach to a
9917 static struct discriminant_info
*
9918 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9921 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9922 gdb_assert (discriminant_index
== -1
9923 || (discriminant_index
>= 0
9924 && discriminant_index
< TYPE_NFIELDS (type
)));
9925 gdb_assert (default_index
== -1
9926 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9928 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9930 struct discriminant_info
*disc
9931 = ((struct discriminant_info
*)
9933 offsetof (struct discriminant_info
, discriminants
)
9934 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9935 disc
->default_index
= default_index
;
9936 disc
->discriminant_index
= discriminant_index
;
9938 struct dynamic_prop prop
;
9939 prop
.kind
= PROP_UNDEFINED
;
9940 prop
.data
.baton
= disc
;
9942 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9947 /* Some versions of rustc emitted enums in an unusual way.
9949 Ordinary enums were emitted as unions. The first element of each
9950 structure in the union was named "RUST$ENUM$DISR". This element
9951 held the discriminant.
9953 These versions of Rust also implemented the "non-zero"
9954 optimization. When the enum had two values, and one is empty and
9955 the other holds a pointer that cannot be zero, the pointer is used
9956 as the discriminant, with a zero value meaning the empty variant.
9957 Here, the union's first member is of the form
9958 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9959 where the fieldnos are the indices of the fields that should be
9960 traversed in order to find the field (which may be several fields deep)
9961 and the variantname is the name of the variant of the case when the
9964 This function recognizes whether TYPE is of one of these forms,
9965 and, if so, smashes it to be a variant type. */
9968 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9970 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9972 /* We don't need to deal with empty enums. */
9973 if (TYPE_NFIELDS (type
) == 0)
9976 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9977 if (TYPE_NFIELDS (type
) == 1
9978 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9980 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9982 /* Decode the field name to find the offset of the
9984 ULONGEST bit_offset
= 0;
9985 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9986 while (name
[0] >= '0' && name
[0] <= '9')
9989 unsigned long index
= strtoul (name
, &tail
, 10);
9992 || index
>= TYPE_NFIELDS (field_type
)
9993 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9994 != FIELD_LOC_KIND_BITPOS
))
9996 complaint (&symfile_complaints
,
9997 _("Could not parse Rust enum encoding string \"%s\""
9999 TYPE_FIELD_NAME (type
, 0),
10000 objfile_name (objfile
));
10005 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10006 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10009 /* Make a union to hold the variants. */
10010 struct type
*union_type
= alloc_type (objfile
);
10011 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10012 TYPE_NFIELDS (union_type
) = 3;
10013 TYPE_FIELDS (union_type
)
10014 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10015 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10017 /* Put the discriminant must at index 0. */
10018 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10019 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10020 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10021 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10023 /* The order of fields doesn't really matter, so put the real
10024 field at index 1 and the data-less field at index 2. */
10025 struct discriminant_info
*disc
10026 = alloc_discriminant_info (union_type
, 0, 1);
10027 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10028 TYPE_FIELD_NAME (union_type
, 1)
10029 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10030 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10031 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10032 TYPE_FIELD_NAME (union_type
, 1));
10034 const char *dataless_name
10035 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10037 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10039 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10040 /* NAME points into the original discriminant name, which
10041 already has the correct lifetime. */
10042 TYPE_FIELD_NAME (union_type
, 2) = name
;
10043 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10044 disc
->discriminants
[2] = 0;
10046 /* Smash this type to be a structure type. We have to do this
10047 because the type has already been recorded. */
10048 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10049 TYPE_NFIELDS (type
) = 1;
10051 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10053 /* Install the variant part. */
10054 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10055 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10056 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10058 else if (TYPE_NFIELDS (type
) == 1)
10060 /* We assume that a union with a single field is a univariant
10062 /* Smash this type to be a structure type. We have to do this
10063 because the type has already been recorded. */
10064 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10066 /* Make a union to hold the variants. */
10067 struct type
*union_type
= alloc_type (objfile
);
10068 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10069 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10070 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10071 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10073 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10074 const char *variant_name
10075 = rust_last_path_segment (TYPE_NAME (field_type
));
10076 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10077 TYPE_NAME (field_type
)
10078 = rust_fully_qualify (&objfile
->objfile_obstack
,
10079 TYPE_NAME (type
), variant_name
);
10081 /* Install the union in the outer struct type. */
10082 TYPE_NFIELDS (type
) = 1;
10084 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10085 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10086 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10087 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10089 alloc_discriminant_info (union_type
, -1, 0);
10093 struct type
*disr_type
= nullptr;
10094 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10096 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10098 if (TYPE_NFIELDS (disr_type
) == 0)
10100 /* Could be data-less variant, so keep going. */
10102 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10103 "RUST$ENUM$DISR") != 0)
10105 /* Not a Rust enum. */
10115 /* If we got here without a discriminant, then it's probably
10117 if (disr_type
== nullptr)
10120 /* Smash this type to be a structure type. We have to do this
10121 because the type has already been recorded. */
10122 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10124 /* Make a union to hold the variants. */
10125 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10126 struct type
*union_type
= alloc_type (objfile
);
10127 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10128 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10129 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10130 TYPE_FIELDS (union_type
)
10131 = (struct field
*) TYPE_ZALLOC (union_type
,
10132 (TYPE_NFIELDS (union_type
)
10133 * sizeof (struct field
)));
10135 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10136 TYPE_NFIELDS (type
) * sizeof (struct field
));
10138 /* Install the discriminant at index 0 in the union. */
10139 TYPE_FIELD (union_type
, 0) = *disr_field
;
10140 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10141 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10143 /* Install the union in the outer struct type. */
10144 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10145 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10146 TYPE_NFIELDS (type
) = 1;
10148 /* Set the size and offset of the union type. */
10149 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10151 /* We need a way to find the correct discriminant given a
10152 variant name. For convenience we build a map here. */
10153 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10154 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10155 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10157 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10160 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10161 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10165 int n_fields
= TYPE_NFIELDS (union_type
);
10166 struct discriminant_info
*disc
10167 = alloc_discriminant_info (union_type
, 0, -1);
10168 /* Skip the discriminant here. */
10169 for (int i
= 1; i
< n_fields
; ++i
)
10171 /* Find the final word in the name of this variant's type.
10172 That name can be used to look up the correct
10174 const char *variant_name
10175 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10178 auto iter
= discriminant_map
.find (variant_name
);
10179 if (iter
!= discriminant_map
.end ())
10180 disc
->discriminants
[i
] = iter
->second
;
10182 /* Remove the discriminant field. */
10183 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10184 --TYPE_NFIELDS (sub_type
);
10185 ++TYPE_FIELDS (sub_type
);
10186 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10187 TYPE_NAME (sub_type
)
10188 = rust_fully_qualify (&objfile
->objfile_obstack
,
10189 TYPE_NAME (type
), variant_name
);
10194 /* Rewrite some Rust unions to be structures with variants parts. */
10197 rust_union_quirks (struct dwarf2_cu
*cu
)
10199 gdb_assert (cu
->language
== language_rust
);
10200 for (struct type
*type
: cu
->rust_unions
)
10201 quirk_rust_enum (type
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10204 /* Return the symtab for PER_CU. This works properly regardless of
10205 whether we're using the index or psymtabs. */
10207 static struct compunit_symtab
*
10208 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10210 return (per_cu
->dwarf2_per_objfile
->using_index
10211 ? per_cu
->v
.quick
->compunit_symtab
10212 : per_cu
->v
.psymtab
->compunit_symtab
);
10215 /* A helper function for computing the list of all symbol tables
10216 included by PER_CU. */
10219 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
10220 htab_t all_children
, htab_t all_type_symtabs
,
10221 struct dwarf2_per_cu_data
*per_cu
,
10222 struct compunit_symtab
*immediate_parent
)
10226 struct compunit_symtab
*cust
;
10227 struct dwarf2_per_cu_data
*iter
;
10229 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10232 /* This inclusion and its children have been processed. */
10237 /* Only add a CU if it has a symbol table. */
10238 cust
= get_compunit_symtab (per_cu
);
10241 /* If this is a type unit only add its symbol table if we haven't
10242 seen it yet (type unit per_cu's can share symtabs). */
10243 if (per_cu
->is_debug_types
)
10245 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10249 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10250 if (cust
->user
== NULL
)
10251 cust
->user
= immediate_parent
;
10256 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10257 if (cust
->user
== NULL
)
10258 cust
->user
= immediate_parent
;
10263 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
10266 recursively_compute_inclusions (result
, all_children
,
10267 all_type_symtabs
, iter
, cust
);
10271 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10275 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10277 gdb_assert (! per_cu
->is_debug_types
);
10279 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
10282 struct dwarf2_per_cu_data
*per_cu_iter
;
10283 struct compunit_symtab
*compunit_symtab_iter
;
10284 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
10285 htab_t all_children
, all_type_symtabs
;
10286 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10288 /* If we don't have a symtab, we can just skip this case. */
10292 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10293 NULL
, xcalloc
, xfree
);
10294 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10295 NULL
, xcalloc
, xfree
);
10298 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
10302 recursively_compute_inclusions (&result_symtabs
, all_children
,
10303 all_type_symtabs
, per_cu_iter
,
10307 /* Now we have a transitive closure of all the included symtabs. */
10308 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
10310 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10311 struct compunit_symtab
*, len
+ 1);
10313 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
10314 compunit_symtab_iter
);
10316 cust
->includes
[ix
] = compunit_symtab_iter
;
10317 cust
->includes
[len
] = NULL
;
10319 VEC_free (compunit_symtab_ptr
, result_symtabs
);
10320 htab_delete (all_children
);
10321 htab_delete (all_type_symtabs
);
10325 /* Compute the 'includes' field for the symtabs of all the CUs we just
10329 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10332 struct dwarf2_per_cu_data
*iter
;
10335 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
10339 if (! iter
->is_debug_types
)
10340 compute_compunit_symtab_includes (iter
);
10343 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
10346 /* Generate full symbol information for PER_CU, whose DIEs have
10347 already been loaded into memory. */
10350 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10351 enum language pretend_language
)
10353 struct dwarf2_cu
*cu
= per_cu
->cu
;
10354 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10355 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10356 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10357 CORE_ADDR lowpc
, highpc
;
10358 struct compunit_symtab
*cust
;
10359 CORE_ADDR baseaddr
;
10360 struct block
*static_block
;
10363 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10366 scoped_free_pendings free_pending
;
10368 /* Clear the list here in case something was left over. */
10369 cu
->method_list
.clear ();
10371 cu
->list_in_scope
= &file_symbols
;
10373 cu
->language
= pretend_language
;
10374 cu
->language_defn
= language_def (cu
->language
);
10376 /* Do line number decoding in read_file_scope () */
10377 process_die (cu
->dies
, cu
);
10379 /* For now fudge the Go package. */
10380 if (cu
->language
== language_go
)
10381 fixup_go_packaging (cu
);
10383 /* Now that we have processed all the DIEs in the CU, all the types
10384 should be complete, and it should now be safe to compute all of the
10386 compute_delayed_physnames (cu
);
10388 if (cu
->language
== language_rust
)
10389 rust_union_quirks (cu
);
10391 /* Some compilers don't define a DW_AT_high_pc attribute for the
10392 compilation unit. If the DW_AT_high_pc is missing, synthesize
10393 it, by scanning the DIE's below the compilation unit. */
10394 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10396 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10397 static_block
= end_symtab_get_static_block (addr
, 0, 1);
10399 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10400 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10401 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10402 addrmap to help ensure it has an accurate map of pc values belonging to
10404 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10406 cust
= end_symtab_from_static_block (static_block
,
10407 SECT_OFF_TEXT (objfile
), 0);
10411 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10413 /* Set symtab language to language from DW_AT_language. If the
10414 compilation is from a C file generated by language preprocessors, do
10415 not set the language if it was already deduced by start_subfile. */
10416 if (!(cu
->language
== language_c
10417 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10418 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10420 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10421 produce DW_AT_location with location lists but it can be possibly
10422 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10423 there were bugs in prologue debug info, fixed later in GCC-4.5
10424 by "unwind info for epilogues" patch (which is not directly related).
10426 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10427 needed, it would be wrong due to missing DW_AT_producer there.
10429 Still one can confuse GDB by using non-standard GCC compilation
10430 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10432 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10433 cust
->locations_valid
= 1;
10435 if (gcc_4_minor
>= 5)
10436 cust
->epilogue_unwind_valid
= 1;
10438 cust
->call_site_htab
= cu
->call_site_htab
;
10441 if (dwarf2_per_objfile
->using_index
)
10442 per_cu
->v
.quick
->compunit_symtab
= cust
;
10445 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10446 pst
->compunit_symtab
= cust
;
10450 /* Push it for inclusion processing later. */
10451 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
10454 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10455 already been loaded into memory. */
10458 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10459 enum language pretend_language
)
10461 struct dwarf2_cu
*cu
= per_cu
->cu
;
10462 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10463 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10464 struct compunit_symtab
*cust
;
10465 struct signatured_type
*sig_type
;
10467 gdb_assert (per_cu
->is_debug_types
);
10468 sig_type
= (struct signatured_type
*) per_cu
;
10471 scoped_free_pendings free_pending
;
10473 /* Clear the list here in case something was left over. */
10474 cu
->method_list
.clear ();
10476 cu
->list_in_scope
= &file_symbols
;
10478 cu
->language
= pretend_language
;
10479 cu
->language_defn
= language_def (cu
->language
);
10481 /* The symbol tables are set up in read_type_unit_scope. */
10482 process_die (cu
->dies
, cu
);
10484 /* For now fudge the Go package. */
10485 if (cu
->language
== language_go
)
10486 fixup_go_packaging (cu
);
10488 /* Now that we have processed all the DIEs in the CU, all the types
10489 should be complete, and it should now be safe to compute all of the
10491 compute_delayed_physnames (cu
);
10493 if (cu
->language
== language_rust
)
10494 rust_union_quirks (cu
);
10496 /* TUs share symbol tables.
10497 If this is the first TU to use this symtab, complete the construction
10498 of it with end_expandable_symtab. Otherwise, complete the addition of
10499 this TU's symbols to the existing symtab. */
10500 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10502 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10503 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10507 /* Set symtab language to language from DW_AT_language. If the
10508 compilation is from a C file generated by language preprocessors,
10509 do not set the language if it was already deduced by
10511 if (!(cu
->language
== language_c
10512 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10513 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10518 augment_type_symtab ();
10519 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10522 if (dwarf2_per_objfile
->using_index
)
10523 per_cu
->v
.quick
->compunit_symtab
= cust
;
10526 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10527 pst
->compunit_symtab
= cust
;
10532 /* Process an imported unit DIE. */
10535 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10537 struct attribute
*attr
;
10539 /* For now we don't handle imported units in type units. */
10540 if (cu
->per_cu
->is_debug_types
)
10542 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10543 " supported in type units [in module %s]"),
10544 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10547 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10550 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10551 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10552 dwarf2_per_cu_data
*per_cu
10553 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10554 cu
->per_cu
->dwarf2_per_objfile
);
10556 /* If necessary, add it to the queue and load its DIEs. */
10557 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10558 load_full_comp_unit (per_cu
, cu
->language
);
10560 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
10565 /* RAII object that represents a process_die scope: i.e.,
10566 starts/finishes processing a DIE. */
10567 class process_die_scope
10570 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10571 : m_die (die
), m_cu (cu
)
10573 /* We should only be processing DIEs not already in process. */
10574 gdb_assert (!m_die
->in_process
);
10575 m_die
->in_process
= true;
10578 ~process_die_scope ()
10580 m_die
->in_process
= false;
10582 /* If we're done processing the DIE for the CU that owns the line
10583 header, we don't need the line header anymore. */
10584 if (m_cu
->line_header_die_owner
== m_die
)
10586 delete m_cu
->line_header
;
10587 m_cu
->line_header
= NULL
;
10588 m_cu
->line_header_die_owner
= NULL
;
10597 /* Process a die and its children. */
10600 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10602 process_die_scope
scope (die
, cu
);
10606 case DW_TAG_padding
:
10608 case DW_TAG_compile_unit
:
10609 case DW_TAG_partial_unit
:
10610 read_file_scope (die
, cu
);
10612 case DW_TAG_type_unit
:
10613 read_type_unit_scope (die
, cu
);
10615 case DW_TAG_subprogram
:
10616 case DW_TAG_inlined_subroutine
:
10617 read_func_scope (die
, cu
);
10619 case DW_TAG_lexical_block
:
10620 case DW_TAG_try_block
:
10621 case DW_TAG_catch_block
:
10622 read_lexical_block_scope (die
, cu
);
10624 case DW_TAG_call_site
:
10625 case DW_TAG_GNU_call_site
:
10626 read_call_site_scope (die
, cu
);
10628 case DW_TAG_class_type
:
10629 case DW_TAG_interface_type
:
10630 case DW_TAG_structure_type
:
10631 case DW_TAG_union_type
:
10632 process_structure_scope (die
, cu
);
10634 case DW_TAG_enumeration_type
:
10635 process_enumeration_scope (die
, cu
);
10638 /* These dies have a type, but processing them does not create
10639 a symbol or recurse to process the children. Therefore we can
10640 read them on-demand through read_type_die. */
10641 case DW_TAG_subroutine_type
:
10642 case DW_TAG_set_type
:
10643 case DW_TAG_array_type
:
10644 case DW_TAG_pointer_type
:
10645 case DW_TAG_ptr_to_member_type
:
10646 case DW_TAG_reference_type
:
10647 case DW_TAG_rvalue_reference_type
:
10648 case DW_TAG_string_type
:
10651 case DW_TAG_base_type
:
10652 case DW_TAG_subrange_type
:
10653 case DW_TAG_typedef
:
10654 /* Add a typedef symbol for the type definition, if it has a
10656 new_symbol (die
, read_type_die (die
, cu
), cu
);
10658 case DW_TAG_common_block
:
10659 read_common_block (die
, cu
);
10661 case DW_TAG_common_inclusion
:
10663 case DW_TAG_namespace
:
10664 cu
->processing_has_namespace_info
= 1;
10665 read_namespace (die
, cu
);
10667 case DW_TAG_module
:
10668 cu
->processing_has_namespace_info
= 1;
10669 read_module (die
, cu
);
10671 case DW_TAG_imported_declaration
:
10672 cu
->processing_has_namespace_info
= 1;
10673 if (read_namespace_alias (die
, cu
))
10675 /* The declaration is not a global namespace alias: fall through. */
10676 case DW_TAG_imported_module
:
10677 cu
->processing_has_namespace_info
= 1;
10678 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10679 || cu
->language
!= language_fortran
))
10680 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
10681 dwarf_tag_name (die
->tag
));
10682 read_import_statement (die
, cu
);
10685 case DW_TAG_imported_unit
:
10686 process_imported_unit_die (die
, cu
);
10689 case DW_TAG_variable
:
10690 read_variable (die
, cu
);
10694 new_symbol (die
, NULL
, cu
);
10699 /* DWARF name computation. */
10701 /* A helper function for dwarf2_compute_name which determines whether DIE
10702 needs to have the name of the scope prepended to the name listed in the
10706 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10708 struct attribute
*attr
;
10712 case DW_TAG_namespace
:
10713 case DW_TAG_typedef
:
10714 case DW_TAG_class_type
:
10715 case DW_TAG_interface_type
:
10716 case DW_TAG_structure_type
:
10717 case DW_TAG_union_type
:
10718 case DW_TAG_enumeration_type
:
10719 case DW_TAG_enumerator
:
10720 case DW_TAG_subprogram
:
10721 case DW_TAG_inlined_subroutine
:
10722 case DW_TAG_member
:
10723 case DW_TAG_imported_declaration
:
10726 case DW_TAG_variable
:
10727 case DW_TAG_constant
:
10728 /* We only need to prefix "globally" visible variables. These include
10729 any variable marked with DW_AT_external or any variable that
10730 lives in a namespace. [Variables in anonymous namespaces
10731 require prefixing, but they are not DW_AT_external.] */
10733 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10735 struct dwarf2_cu
*spec_cu
= cu
;
10737 return die_needs_namespace (die_specification (die
, &spec_cu
),
10741 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10742 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10743 && die
->parent
->tag
!= DW_TAG_module
)
10745 /* A variable in a lexical block of some kind does not need a
10746 namespace, even though in C++ such variables may be external
10747 and have a mangled name. */
10748 if (die
->parent
->tag
== DW_TAG_lexical_block
10749 || die
->parent
->tag
== DW_TAG_try_block
10750 || die
->parent
->tag
== DW_TAG_catch_block
10751 || die
->parent
->tag
== DW_TAG_subprogram
)
10760 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10761 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10762 defined for the given DIE. */
10764 static struct attribute
*
10765 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10767 struct attribute
*attr
;
10769 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10771 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10776 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10777 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10778 defined for the given DIE. */
10780 static const char *
10781 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10783 const char *linkage_name
;
10785 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10786 if (linkage_name
== NULL
)
10787 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10789 return linkage_name
;
10792 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10793 compute the physname for the object, which include a method's:
10794 - formal parameters (C++),
10795 - receiver type (Go),
10797 The term "physname" is a bit confusing.
10798 For C++, for example, it is the demangled name.
10799 For Go, for example, it's the mangled name.
10801 For Ada, return the DIE's linkage name rather than the fully qualified
10802 name. PHYSNAME is ignored..
10804 The result is allocated on the objfile_obstack and canonicalized. */
10806 static const char *
10807 dwarf2_compute_name (const char *name
,
10808 struct die_info
*die
, struct dwarf2_cu
*cu
,
10811 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10814 name
= dwarf2_name (die
, cu
);
10816 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10817 but otherwise compute it by typename_concat inside GDB.
10818 FIXME: Actually this is not really true, or at least not always true.
10819 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
10820 Fortran names because there is no mangling standard. So new_symbol
10821 will set the demangled name to the result of dwarf2_full_name, and it is
10822 the demangled name that GDB uses if it exists. */
10823 if (cu
->language
== language_ada
10824 || (cu
->language
== language_fortran
&& physname
))
10826 /* For Ada unit, we prefer the linkage name over the name, as
10827 the former contains the exported name, which the user expects
10828 to be able to reference. Ideally, we want the user to be able
10829 to reference this entity using either natural or linkage name,
10830 but we haven't started looking at this enhancement yet. */
10831 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10833 if (linkage_name
!= NULL
)
10834 return linkage_name
;
10837 /* These are the only languages we know how to qualify names in. */
10839 && (cu
->language
== language_cplus
10840 || cu
->language
== language_fortran
|| cu
->language
== language_d
10841 || cu
->language
== language_rust
))
10843 if (die_needs_namespace (die
, cu
))
10845 const char *prefix
;
10846 const char *canonical_name
= NULL
;
10850 prefix
= determine_prefix (die
, cu
);
10851 if (*prefix
!= '\0')
10853 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
10856 buf
.puts (prefixed_name
);
10857 xfree (prefixed_name
);
10862 /* Template parameters may be specified in the DIE's DW_AT_name, or
10863 as children with DW_TAG_template_type_param or
10864 DW_TAG_value_type_param. If the latter, add them to the name
10865 here. If the name already has template parameters, then
10866 skip this step; some versions of GCC emit both, and
10867 it is more efficient to use the pre-computed name.
10869 Something to keep in mind about this process: it is very
10870 unlikely, or in some cases downright impossible, to produce
10871 something that will match the mangled name of a function.
10872 If the definition of the function has the same debug info,
10873 we should be able to match up with it anyway. But fallbacks
10874 using the minimal symbol, for instance to find a method
10875 implemented in a stripped copy of libstdc++, will not work.
10876 If we do not have debug info for the definition, we will have to
10877 match them up some other way.
10879 When we do name matching there is a related problem with function
10880 templates; two instantiated function templates are allowed to
10881 differ only by their return types, which we do not add here. */
10883 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10885 struct attribute
*attr
;
10886 struct die_info
*child
;
10889 die
->building_fullname
= 1;
10891 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10895 const gdb_byte
*bytes
;
10896 struct dwarf2_locexpr_baton
*baton
;
10899 if (child
->tag
!= DW_TAG_template_type_param
10900 && child
->tag
!= DW_TAG_template_value_param
)
10911 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10914 complaint (&symfile_complaints
,
10915 _("template parameter missing DW_AT_type"));
10916 buf
.puts ("UNKNOWN_TYPE");
10919 type
= die_type (child
, cu
);
10921 if (child
->tag
== DW_TAG_template_type_param
)
10923 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
10927 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10930 complaint (&symfile_complaints
,
10931 _("template parameter missing "
10932 "DW_AT_const_value"));
10933 buf
.puts ("UNKNOWN_VALUE");
10937 dwarf2_const_value_attr (attr
, type
, name
,
10938 &cu
->comp_unit_obstack
, cu
,
10939 &value
, &bytes
, &baton
);
10941 if (TYPE_NOSIGN (type
))
10942 /* GDB prints characters as NUMBER 'CHAR'. If that's
10943 changed, this can use value_print instead. */
10944 c_printchar (value
, type
, &buf
);
10947 struct value_print_options opts
;
10950 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10954 else if (bytes
!= NULL
)
10956 v
= allocate_value (type
);
10957 memcpy (value_contents_writeable (v
), bytes
,
10958 TYPE_LENGTH (type
));
10961 v
= value_from_longest (type
, value
);
10963 /* Specify decimal so that we do not depend on
10965 get_formatted_print_options (&opts
, 'd');
10967 value_print (v
, &buf
, &opts
);
10973 die
->building_fullname
= 0;
10977 /* Close the argument list, with a space if necessary
10978 (nested templates). */
10979 if (!buf
.empty () && buf
.string ().back () == '>')
10986 /* For C++ methods, append formal parameter type
10987 information, if PHYSNAME. */
10989 if (physname
&& die
->tag
== DW_TAG_subprogram
10990 && cu
->language
== language_cplus
)
10992 struct type
*type
= read_type_die (die
, cu
);
10994 c_type_print_args (type
, &buf
, 1, cu
->language
,
10995 &type_print_raw_options
);
10997 if (cu
->language
== language_cplus
)
10999 /* Assume that an artificial first parameter is
11000 "this", but do not crash if it is not. RealView
11001 marks unnamed (and thus unused) parameters as
11002 artificial; there is no way to differentiate
11004 if (TYPE_NFIELDS (type
) > 0
11005 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11006 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11007 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11009 buf
.puts (" const");
11013 const std::string
&intermediate_name
= buf
.string ();
11015 if (cu
->language
== language_cplus
)
11017 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11018 &objfile
->per_bfd
->storage_obstack
);
11020 /* If we only computed INTERMEDIATE_NAME, or if
11021 INTERMEDIATE_NAME is already canonical, then we need to
11022 copy it to the appropriate obstack. */
11023 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11024 name
= ((const char *)
11025 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11026 intermediate_name
.c_str (),
11027 intermediate_name
.length ()));
11029 name
= canonical_name
;
11036 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11037 If scope qualifiers are appropriate they will be added. The result
11038 will be allocated on the storage_obstack, or NULL if the DIE does
11039 not have a name. NAME may either be from a previous call to
11040 dwarf2_name or NULL.
11042 The output string will be canonicalized (if C++). */
11044 static const char *
11045 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11047 return dwarf2_compute_name (name
, die
, cu
, 0);
11050 /* Construct a physname for the given DIE in CU. NAME may either be
11051 from a previous call to dwarf2_name or NULL. The result will be
11052 allocated on the objfile_objstack or NULL if the DIE does not have a
11055 The output string will be canonicalized (if C++). */
11057 static const char *
11058 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11060 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11061 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11064 /* In this case dwarf2_compute_name is just a shortcut not building anything
11066 if (!die_needs_namespace (die
, cu
))
11067 return dwarf2_compute_name (name
, die
, cu
, 1);
11069 mangled
= dw2_linkage_name (die
, cu
);
11071 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11072 See https://github.com/rust-lang/rust/issues/32925. */
11073 if (cu
->language
== language_rust
&& mangled
!= NULL
11074 && strchr (mangled
, '{') != NULL
)
11077 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11079 gdb::unique_xmalloc_ptr
<char> demangled
;
11080 if (mangled
!= NULL
)
11083 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11085 /* Do nothing (do not demangle the symbol name). */
11087 else if (cu
->language
== language_go
)
11089 /* This is a lie, but we already lie to the caller new_symbol.
11090 new_symbol assumes we return the mangled name.
11091 This just undoes that lie until things are cleaned up. */
11095 /* Use DMGL_RET_DROP for C++ template functions to suppress
11096 their return type. It is easier for GDB users to search
11097 for such functions as `name(params)' than `long name(params)'.
11098 In such case the minimal symbol names do not match the full
11099 symbol names but for template functions there is never a need
11100 to look up their definition from their declaration so
11101 the only disadvantage remains the minimal symbol variant
11102 `long name(params)' does not have the proper inferior type. */
11103 demangled
.reset (gdb_demangle (mangled
,
11104 (DMGL_PARAMS
| DMGL_ANSI
11105 | DMGL_RET_DROP
)));
11108 canon
= demangled
.get ();
11116 if (canon
== NULL
|| check_physname
)
11118 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11120 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11122 /* It may not mean a bug in GDB. The compiler could also
11123 compute DW_AT_linkage_name incorrectly. But in such case
11124 GDB would need to be bug-to-bug compatible. */
11126 complaint (&symfile_complaints
,
11127 _("Computed physname <%s> does not match demangled <%s> "
11128 "(from linkage <%s>) - DIE at %s [in module %s]"),
11129 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11130 objfile_name (objfile
));
11132 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11133 is available here - over computed PHYSNAME. It is safer
11134 against both buggy GDB and buggy compilers. */
11148 retval
= ((const char *)
11149 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11150 retval
, strlen (retval
)));
11155 /* Inspect DIE in CU for a namespace alias. If one exists, record
11156 a new symbol for it.
11158 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11161 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11163 struct attribute
*attr
;
11165 /* If the die does not have a name, this is not a namespace
11167 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11171 struct die_info
*d
= die
;
11172 struct dwarf2_cu
*imported_cu
= cu
;
11174 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11175 keep inspecting DIEs until we hit the underlying import. */
11176 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11177 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11179 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11183 d
= follow_die_ref (d
, attr
, &imported_cu
);
11184 if (d
->tag
!= DW_TAG_imported_declaration
)
11188 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11190 complaint (&symfile_complaints
,
11191 _("DIE at %s has too many recursively imported "
11192 "declarations"), sect_offset_str (d
->sect_off
));
11199 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11201 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11202 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11204 /* This declaration is a global namespace alias. Add
11205 a symbol for it whose type is the aliased namespace. */
11206 new_symbol (die
, type
, cu
);
11215 /* Return the using directives repository (global or local?) to use in the
11216 current context for LANGUAGE.
11218 For Ada, imported declarations can materialize renamings, which *may* be
11219 global. However it is impossible (for now?) in DWARF to distinguish
11220 "external" imported declarations and "static" ones. As all imported
11221 declarations seem to be static in all other languages, make them all CU-wide
11222 global only in Ada. */
11224 static struct using_direct
**
11225 using_directives (enum language language
)
11227 if (language
== language_ada
&& context_stack_depth
== 0)
11228 return &global_using_directives
;
11230 return &local_using_directives
;
11233 /* Read the import statement specified by the given die and record it. */
11236 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11238 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11239 struct attribute
*import_attr
;
11240 struct die_info
*imported_die
, *child_die
;
11241 struct dwarf2_cu
*imported_cu
;
11242 const char *imported_name
;
11243 const char *imported_name_prefix
;
11244 const char *canonical_name
;
11245 const char *import_alias
;
11246 const char *imported_declaration
= NULL
;
11247 const char *import_prefix
;
11248 std::vector
<const char *> excludes
;
11250 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11251 if (import_attr
== NULL
)
11253 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11254 dwarf_tag_name (die
->tag
));
11259 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11260 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11261 if (imported_name
== NULL
)
11263 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11265 The import in the following code:
11279 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11280 <52> DW_AT_decl_file : 1
11281 <53> DW_AT_decl_line : 6
11282 <54> DW_AT_import : <0x75>
11283 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11284 <59> DW_AT_name : B
11285 <5b> DW_AT_decl_file : 1
11286 <5c> DW_AT_decl_line : 2
11287 <5d> DW_AT_type : <0x6e>
11289 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11290 <76> DW_AT_byte_size : 4
11291 <77> DW_AT_encoding : 5 (signed)
11293 imports the wrong die ( 0x75 instead of 0x58 ).
11294 This case will be ignored until the gcc bug is fixed. */
11298 /* Figure out the local name after import. */
11299 import_alias
= dwarf2_name (die
, cu
);
11301 /* Figure out where the statement is being imported to. */
11302 import_prefix
= determine_prefix (die
, cu
);
11304 /* Figure out what the scope of the imported die is and prepend it
11305 to the name of the imported die. */
11306 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11308 if (imported_die
->tag
!= DW_TAG_namespace
11309 && imported_die
->tag
!= DW_TAG_module
)
11311 imported_declaration
= imported_name
;
11312 canonical_name
= imported_name_prefix
;
11314 else if (strlen (imported_name_prefix
) > 0)
11315 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11316 imported_name_prefix
,
11317 (cu
->language
== language_d
? "." : "::"),
11318 imported_name
, (char *) NULL
);
11320 canonical_name
= imported_name
;
11322 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11323 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11324 child_die
= sibling_die (child_die
))
11326 /* DWARF-4: A Fortran use statement with a “rename list” may be
11327 represented by an imported module entry with an import attribute
11328 referring to the module and owned entries corresponding to those
11329 entities that are renamed as part of being imported. */
11331 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11333 complaint (&symfile_complaints
,
11334 _("child DW_TAG_imported_declaration expected "
11335 "- DIE at %s [in module %s]"),
11336 sect_offset_str (child_die
->sect_off
),
11337 objfile_name (objfile
));
11341 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11342 if (import_attr
== NULL
)
11344 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11345 dwarf_tag_name (child_die
->tag
));
11350 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11352 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11353 if (imported_name
== NULL
)
11355 complaint (&symfile_complaints
,
11356 _("child DW_TAG_imported_declaration has unknown "
11357 "imported name - DIE at %s [in module %s]"),
11358 sect_offset_str (child_die
->sect_off
),
11359 objfile_name (objfile
));
11363 excludes
.push_back (imported_name
);
11365 process_die (child_die
, cu
);
11368 add_using_directive (using_directives (cu
->language
),
11372 imported_declaration
,
11375 &objfile
->objfile_obstack
);
11378 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11379 types, but gives them a size of zero. Starting with version 14,
11380 ICC is compatible with GCC. */
11383 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11385 if (!cu
->checked_producer
)
11386 check_producer (cu
);
11388 return cu
->producer_is_icc_lt_14
;
11391 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11392 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11393 this, it was first present in GCC release 4.3.0. */
11396 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11398 if (!cu
->checked_producer
)
11399 check_producer (cu
);
11401 return cu
->producer_is_gcc_lt_4_3
;
11404 static file_and_directory
11405 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11407 file_and_directory res
;
11409 /* Find the filename. Do not use dwarf2_name here, since the filename
11410 is not a source language identifier. */
11411 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11412 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11414 if (res
.comp_dir
== NULL
11415 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11416 && IS_ABSOLUTE_PATH (res
.name
))
11418 res
.comp_dir_storage
= ldirname (res
.name
);
11419 if (!res
.comp_dir_storage
.empty ())
11420 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11422 if (res
.comp_dir
!= NULL
)
11424 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11425 directory, get rid of it. */
11426 const char *cp
= strchr (res
.comp_dir
, ':');
11428 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11429 res
.comp_dir
= cp
+ 1;
11432 if (res
.name
== NULL
)
11433 res
.name
= "<unknown>";
11438 /* Handle DW_AT_stmt_list for a compilation unit.
11439 DIE is the DW_TAG_compile_unit die for CU.
11440 COMP_DIR is the compilation directory. LOWPC is passed to
11441 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11444 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11445 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11447 struct dwarf2_per_objfile
*dwarf2_per_objfile
11448 = cu
->per_cu
->dwarf2_per_objfile
;
11449 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11450 struct attribute
*attr
;
11451 struct line_header line_header_local
;
11452 hashval_t line_header_local_hash
;
11454 int decode_mapping
;
11456 gdb_assert (! cu
->per_cu
->is_debug_types
);
11458 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11462 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11464 /* The line header hash table is only created if needed (it exists to
11465 prevent redundant reading of the line table for partial_units).
11466 If we're given a partial_unit, we'll need it. If we're given a
11467 compile_unit, then use the line header hash table if it's already
11468 created, but don't create one just yet. */
11470 if (dwarf2_per_objfile
->line_header_hash
== NULL
11471 && die
->tag
== DW_TAG_partial_unit
)
11473 dwarf2_per_objfile
->line_header_hash
11474 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11475 line_header_eq_voidp
,
11476 free_line_header_voidp
,
11477 &objfile
->objfile_obstack
,
11478 hashtab_obstack_allocate
,
11479 dummy_obstack_deallocate
);
11482 line_header_local
.sect_off
= line_offset
;
11483 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11484 line_header_local_hash
= line_header_hash (&line_header_local
);
11485 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11487 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11488 &line_header_local
,
11489 line_header_local_hash
, NO_INSERT
);
11491 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11492 is not present in *SLOT (since if there is something in *SLOT then
11493 it will be for a partial_unit). */
11494 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11496 gdb_assert (*slot
!= NULL
);
11497 cu
->line_header
= (struct line_header
*) *slot
;
11502 /* dwarf_decode_line_header does not yet provide sufficient information.
11503 We always have to call also dwarf_decode_lines for it. */
11504 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11508 cu
->line_header
= lh
.release ();
11509 cu
->line_header_die_owner
= die
;
11511 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11515 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11516 &line_header_local
,
11517 line_header_local_hash
, INSERT
);
11518 gdb_assert (slot
!= NULL
);
11520 if (slot
!= NULL
&& *slot
== NULL
)
11522 /* This newly decoded line number information unit will be owned
11523 by line_header_hash hash table. */
11524 *slot
= cu
->line_header
;
11525 cu
->line_header_die_owner
= NULL
;
11529 /* We cannot free any current entry in (*slot) as that struct line_header
11530 may be already used by multiple CUs. Create only temporary decoded
11531 line_header for this CU - it may happen at most once for each line
11532 number information unit. And if we're not using line_header_hash
11533 then this is what we want as well. */
11534 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11536 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11537 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11542 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11545 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11547 struct dwarf2_per_objfile
*dwarf2_per_objfile
11548 = cu
->per_cu
->dwarf2_per_objfile
;
11549 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11550 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11551 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11552 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11553 struct attribute
*attr
;
11554 struct die_info
*child_die
;
11555 CORE_ADDR baseaddr
;
11557 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11559 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11561 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11562 from finish_block. */
11563 if (lowpc
== ((CORE_ADDR
) -1))
11565 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11567 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11569 prepare_one_comp_unit (cu
, die
, cu
->language
);
11571 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11572 standardised yet. As a workaround for the language detection we fall
11573 back to the DW_AT_producer string. */
11574 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11575 cu
->language
= language_opencl
;
11577 /* Similar hack for Go. */
11578 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11579 set_cu_language (DW_LANG_Go
, cu
);
11581 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
11583 /* Decode line number information if present. We do this before
11584 processing child DIEs, so that the line header table is available
11585 for DW_AT_decl_file. */
11586 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11588 /* Process all dies in compilation unit. */
11589 if (die
->child
!= NULL
)
11591 child_die
= die
->child
;
11592 while (child_die
&& child_die
->tag
)
11594 process_die (child_die
, cu
);
11595 child_die
= sibling_die (child_die
);
11599 /* Decode macro information, if present. Dwarf 2 macro information
11600 refers to information in the line number info statement program
11601 header, so we can only read it if we've read the header
11603 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11605 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11606 if (attr
&& cu
->line_header
)
11608 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11609 complaint (&symfile_complaints
,
11610 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11612 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11616 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11617 if (attr
&& cu
->line_header
)
11619 unsigned int macro_offset
= DW_UNSND (attr
);
11621 dwarf_decode_macros (cu
, macro_offset
, 0);
11626 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
11627 Create the set of symtabs used by this TU, or if this TU is sharing
11628 symtabs with another TU and the symtabs have already been created
11629 then restore those symtabs in the line header.
11630 We don't need the pc/line-number mapping for type units. */
11633 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
11635 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
11636 struct type_unit_group
*tu_group
;
11638 struct attribute
*attr
;
11640 struct signatured_type
*sig_type
;
11642 gdb_assert (per_cu
->is_debug_types
);
11643 sig_type
= (struct signatured_type
*) per_cu
;
11645 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11647 /* If we're using .gdb_index (includes -readnow) then
11648 per_cu->type_unit_group may not have been set up yet. */
11649 if (sig_type
->type_unit_group
== NULL
)
11650 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
11651 tu_group
= sig_type
->type_unit_group
;
11653 /* If we've already processed this stmt_list there's no real need to
11654 do it again, we could fake it and just recreate the part we need
11655 (file name,index -> symtab mapping). If data shows this optimization
11656 is useful we can do it then. */
11657 first_time
= tu_group
->compunit_symtab
== NULL
;
11659 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11664 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11665 lh
= dwarf_decode_line_header (line_offset
, cu
);
11670 dwarf2_start_symtab (cu
, "", NULL
, 0);
11673 gdb_assert (tu_group
->symtabs
== NULL
);
11674 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11679 cu
->line_header
= lh
.release ();
11680 cu
->line_header_die_owner
= die
;
11684 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
11686 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11687 still initializing it, and our caller (a few levels up)
11688 process_full_type_unit still needs to know if this is the first
11691 tu_group
->num_symtabs
= cu
->line_header
->file_names
.size ();
11692 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11693 cu
->line_header
->file_names
.size ());
11695 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11697 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11699 dwarf2_start_subfile (fe
.name
, fe
.include_dir (cu
->line_header
));
11701 if (current_subfile
->symtab
== NULL
)
11703 /* NOTE: start_subfile will recognize when it's been
11704 passed a file it has already seen. So we can't
11705 assume there's a simple mapping from
11706 cu->line_header->file_names to subfiles, plus
11707 cu->line_header->file_names may contain dups. */
11708 current_subfile
->symtab
11709 = allocate_symtab (cust
, current_subfile
->name
);
11712 fe
.symtab
= current_subfile
->symtab
;
11713 tu_group
->symtabs
[i
] = fe
.symtab
;
11718 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11720 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11722 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11724 fe
.symtab
= tu_group
->symtabs
[i
];
11728 /* The main symtab is allocated last. Type units don't have DW_AT_name
11729 so they don't have a "real" (so to speak) symtab anyway.
11730 There is later code that will assign the main symtab to all symbols
11731 that don't have one. We need to handle the case of a symbol with a
11732 missing symtab (DW_AT_decl_file) anyway. */
11735 /* Process DW_TAG_type_unit.
11736 For TUs we want to skip the first top level sibling if it's not the
11737 actual type being defined by this TU. In this case the first top
11738 level sibling is there to provide context only. */
11741 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11743 struct die_info
*child_die
;
11745 prepare_one_comp_unit (cu
, die
, language_minimal
);
11747 /* Initialize (or reinitialize) the machinery for building symtabs.
11748 We do this before processing child DIEs, so that the line header table
11749 is available for DW_AT_decl_file. */
11750 setup_type_unit_groups (die
, cu
);
11752 if (die
->child
!= NULL
)
11754 child_die
= die
->child
;
11755 while (child_die
&& child_die
->tag
)
11757 process_die (child_die
, cu
);
11758 child_die
= sibling_die (child_die
);
11765 http://gcc.gnu.org/wiki/DebugFission
11766 http://gcc.gnu.org/wiki/DebugFissionDWP
11768 To simplify handling of both DWO files ("object" files with the DWARF info)
11769 and DWP files (a file with the DWOs packaged up into one file), we treat
11770 DWP files as having a collection of virtual DWO files. */
11773 hash_dwo_file (const void *item
)
11775 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11778 hash
= htab_hash_string (dwo_file
->dwo_name
);
11779 if (dwo_file
->comp_dir
!= NULL
)
11780 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11785 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11787 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11788 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11790 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11792 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11793 return lhs
->comp_dir
== rhs
->comp_dir
;
11794 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11797 /* Allocate a hash table for DWO files. */
11800 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11802 return htab_create_alloc_ex (41,
11806 &objfile
->objfile_obstack
,
11807 hashtab_obstack_allocate
,
11808 dummy_obstack_deallocate
);
11811 /* Lookup DWO file DWO_NAME. */
11814 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11815 const char *dwo_name
,
11816 const char *comp_dir
)
11818 struct dwo_file find_entry
;
11821 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11822 dwarf2_per_objfile
->dwo_files
11823 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11825 memset (&find_entry
, 0, sizeof (find_entry
));
11826 find_entry
.dwo_name
= dwo_name
;
11827 find_entry
.comp_dir
= comp_dir
;
11828 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
11834 hash_dwo_unit (const void *item
)
11836 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11838 /* This drops the top 32 bits of the id, but is ok for a hash. */
11839 return dwo_unit
->signature
;
11843 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11845 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11846 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11848 /* The signature is assumed to be unique within the DWO file.
11849 So while object file CU dwo_id's always have the value zero,
11850 that's OK, assuming each object file DWO file has only one CU,
11851 and that's the rule for now. */
11852 return lhs
->signature
== rhs
->signature
;
11855 /* Allocate a hash table for DWO CUs,TUs.
11856 There is one of these tables for each of CUs,TUs for each DWO file. */
11859 allocate_dwo_unit_table (struct objfile
*objfile
)
11861 /* Start out with a pretty small number.
11862 Generally DWO files contain only one CU and maybe some TUs. */
11863 return htab_create_alloc_ex (3,
11867 &objfile
->objfile_obstack
,
11868 hashtab_obstack_allocate
,
11869 dummy_obstack_deallocate
);
11872 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11874 struct create_dwo_cu_data
11876 struct dwo_file
*dwo_file
;
11877 struct dwo_unit dwo_unit
;
11880 /* die_reader_func for create_dwo_cu. */
11883 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11884 const gdb_byte
*info_ptr
,
11885 struct die_info
*comp_unit_die
,
11889 struct dwarf2_cu
*cu
= reader
->cu
;
11890 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11891 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11892 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11893 struct dwo_file
*dwo_file
= data
->dwo_file
;
11894 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11895 struct attribute
*attr
;
11897 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
11900 complaint (&symfile_complaints
,
11901 _("Dwarf Error: debug entry at offset %s is missing"
11902 " its dwo_id [in module %s]"),
11903 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11907 dwo_unit
->dwo_file
= dwo_file
;
11908 dwo_unit
->signature
= DW_UNSND (attr
);
11909 dwo_unit
->section
= section
;
11910 dwo_unit
->sect_off
= sect_off
;
11911 dwo_unit
->length
= cu
->per_cu
->length
;
11913 if (dwarf_read_debug
)
11914 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11915 sect_offset_str (sect_off
),
11916 hex_string (dwo_unit
->signature
));
11919 /* Create the dwo_units for the CUs in a DWO_FILE.
11920 Note: This function processes DWO files only, not DWP files. */
11923 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11924 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11927 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11928 const gdb_byte
*info_ptr
, *end_ptr
;
11930 dwarf2_read_section (objfile
, §ion
);
11931 info_ptr
= section
.buffer
;
11933 if (info_ptr
== NULL
)
11936 if (dwarf_read_debug
)
11938 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11939 get_section_name (§ion
),
11940 get_section_file_name (§ion
));
11943 end_ptr
= info_ptr
+ section
.size
;
11944 while (info_ptr
< end_ptr
)
11946 struct dwarf2_per_cu_data per_cu
;
11947 struct create_dwo_cu_data create_dwo_cu_data
;
11948 struct dwo_unit
*dwo_unit
;
11950 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11952 memset (&create_dwo_cu_data
.dwo_unit
, 0,
11953 sizeof (create_dwo_cu_data
.dwo_unit
));
11954 memset (&per_cu
, 0, sizeof (per_cu
));
11955 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11956 per_cu
.is_debug_types
= 0;
11957 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11958 per_cu
.section
= §ion
;
11959 create_dwo_cu_data
.dwo_file
= &dwo_file
;
11961 init_cutu_and_read_dies_no_follow (
11962 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
11963 info_ptr
+= per_cu
.length
;
11965 // If the unit could not be parsed, skip it.
11966 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
11969 if (cus_htab
== NULL
)
11970 cus_htab
= allocate_dwo_unit_table (objfile
);
11972 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11973 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
11974 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
11975 gdb_assert (slot
!= NULL
);
11978 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11979 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11981 complaint (&symfile_complaints
,
11982 _("debug cu entry at offset %s is duplicate to"
11983 " the entry at offset %s, signature %s"),
11984 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11985 hex_string (dwo_unit
->signature
));
11987 *slot
= (void *)dwo_unit
;
11991 /* DWP file .debug_{cu,tu}_index section format:
11992 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11996 Both index sections have the same format, and serve to map a 64-bit
11997 signature to a set of section numbers. Each section begins with a header,
11998 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11999 indexes, and a pool of 32-bit section numbers. The index sections will be
12000 aligned at 8-byte boundaries in the file.
12002 The index section header consists of:
12004 V, 32 bit version number
12006 N, 32 bit number of compilation units or type units in the index
12007 M, 32 bit number of slots in the hash table
12009 Numbers are recorded using the byte order of the application binary.
12011 The hash table begins at offset 16 in the section, and consists of an array
12012 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12013 order of the application binary). Unused slots in the hash table are 0.
12014 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12016 The parallel table begins immediately after the hash table
12017 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12018 array of 32-bit indexes (using the byte order of the application binary),
12019 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12020 table contains a 32-bit index into the pool of section numbers. For unused
12021 hash table slots, the corresponding entry in the parallel table will be 0.
12023 The pool of section numbers begins immediately following the hash table
12024 (at offset 16 + 12 * M from the beginning of the section). The pool of
12025 section numbers consists of an array of 32-bit words (using the byte order
12026 of the application binary). Each item in the array is indexed starting
12027 from 0. The hash table entry provides the index of the first section
12028 number in the set. Additional section numbers in the set follow, and the
12029 set is terminated by a 0 entry (section number 0 is not used in ELF).
12031 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12032 section must be the first entry in the set, and the .debug_abbrev.dwo must
12033 be the second entry. Other members of the set may follow in any order.
12039 DWP Version 2 combines all the .debug_info, etc. sections into one,
12040 and the entries in the index tables are now offsets into these sections.
12041 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12044 Index Section Contents:
12046 Hash Table of Signatures dwp_hash_table.hash_table
12047 Parallel Table of Indices dwp_hash_table.unit_table
12048 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12049 Table of Section Sizes dwp_hash_table.v2.sizes
12051 The index section header consists of:
12053 V, 32 bit version number
12054 L, 32 bit number of columns in the table of section offsets
12055 N, 32 bit number of compilation units or type units in the index
12056 M, 32 bit number of slots in the hash table
12058 Numbers are recorded using the byte order of the application binary.
12060 The hash table has the same format as version 1.
12061 The parallel table of indices has the same format as version 1,
12062 except that the entries are origin-1 indices into the table of sections
12063 offsets and the table of section sizes.
12065 The table of offsets begins immediately following the parallel table
12066 (at offset 16 + 12 * M from the beginning of the section). The table is
12067 a two-dimensional array of 32-bit words (using the byte order of the
12068 application binary), with L columns and N+1 rows, in row-major order.
12069 Each row in the array is indexed starting from 0. The first row provides
12070 a key to the remaining rows: each column in this row provides an identifier
12071 for a debug section, and the offsets in the same column of subsequent rows
12072 refer to that section. The section identifiers are:
12074 DW_SECT_INFO 1 .debug_info.dwo
12075 DW_SECT_TYPES 2 .debug_types.dwo
12076 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12077 DW_SECT_LINE 4 .debug_line.dwo
12078 DW_SECT_LOC 5 .debug_loc.dwo
12079 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12080 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12081 DW_SECT_MACRO 8 .debug_macro.dwo
12083 The offsets provided by the CU and TU index sections are the base offsets
12084 for the contributions made by each CU or TU to the corresponding section
12085 in the package file. Each CU and TU header contains an abbrev_offset
12086 field, used to find the abbreviations table for that CU or TU within the
12087 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12088 be interpreted as relative to the base offset given in the index section.
12089 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12090 should be interpreted as relative to the base offset for .debug_line.dwo,
12091 and offsets into other debug sections obtained from DWARF attributes should
12092 also be interpreted as relative to the corresponding base offset.
12094 The table of sizes begins immediately following the table of offsets.
12095 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12096 with L columns and N rows, in row-major order. Each row in the array is
12097 indexed starting from 1 (row 0 is shared by the two tables).
12101 Hash table lookup is handled the same in version 1 and 2:
12103 We assume that N and M will not exceed 2^32 - 1.
12104 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12106 Given a 64-bit compilation unit signature or a type signature S, an entry
12107 in the hash table is located as follows:
12109 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12110 the low-order k bits all set to 1.
12112 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12114 3) If the hash table entry at index H matches the signature, use that
12115 entry. If the hash table entry at index H is unused (all zeroes),
12116 terminate the search: the signature is not present in the table.
12118 4) Let H = (H + H') modulo M. Repeat at Step 3.
12120 Because M > N and H' and M are relatively prime, the search is guaranteed
12121 to stop at an unused slot or find the match. */
12123 /* Create a hash table to map DWO IDs to their CU/TU entry in
12124 .debug_{info,types}.dwo in DWP_FILE.
12125 Returns NULL if there isn't one.
12126 Note: This function processes DWP files only, not DWO files. */
12128 static struct dwp_hash_table
*
12129 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12130 struct dwp_file
*dwp_file
, int is_debug_types
)
12132 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12133 bfd
*dbfd
= dwp_file
->dbfd
;
12134 const gdb_byte
*index_ptr
, *index_end
;
12135 struct dwarf2_section_info
*index
;
12136 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12137 struct dwp_hash_table
*htab
;
12139 if (is_debug_types
)
12140 index
= &dwp_file
->sections
.tu_index
;
12142 index
= &dwp_file
->sections
.cu_index
;
12144 if (dwarf2_section_empty_p (index
))
12146 dwarf2_read_section (objfile
, index
);
12148 index_ptr
= index
->buffer
;
12149 index_end
= index_ptr
+ index
->size
;
12151 version
= read_4_bytes (dbfd
, index_ptr
);
12154 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12158 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12160 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12163 if (version
!= 1 && version
!= 2)
12165 error (_("Dwarf Error: unsupported DWP file version (%s)"
12166 " [in module %s]"),
12167 pulongest (version
), dwp_file
->name
);
12169 if (nr_slots
!= (nr_slots
& -nr_slots
))
12171 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12172 " is not power of 2 [in module %s]"),
12173 pulongest (nr_slots
), dwp_file
->name
);
12176 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12177 htab
->version
= version
;
12178 htab
->nr_columns
= nr_columns
;
12179 htab
->nr_units
= nr_units
;
12180 htab
->nr_slots
= nr_slots
;
12181 htab
->hash_table
= index_ptr
;
12182 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12184 /* Exit early if the table is empty. */
12185 if (nr_slots
== 0 || nr_units
== 0
12186 || (version
== 2 && nr_columns
== 0))
12188 /* All must be zero. */
12189 if (nr_slots
!= 0 || nr_units
!= 0
12190 || (version
== 2 && nr_columns
!= 0))
12192 complaint (&symfile_complaints
,
12193 _("Empty DWP but nr_slots,nr_units,nr_columns not"
12194 " all zero [in modules %s]"),
12202 htab
->section_pool
.v1
.indices
=
12203 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12204 /* It's harder to decide whether the section is too small in v1.
12205 V1 is deprecated anyway so we punt. */
12209 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12210 int *ids
= htab
->section_pool
.v2
.section_ids
;
12211 /* Reverse map for error checking. */
12212 int ids_seen
[DW_SECT_MAX
+ 1];
12215 if (nr_columns
< 2)
12217 error (_("Dwarf Error: bad DWP hash table, too few columns"
12218 " in section table [in module %s]"),
12221 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12223 error (_("Dwarf Error: bad DWP hash table, too many columns"
12224 " in section table [in module %s]"),
12227 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12228 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12229 for (i
= 0; i
< nr_columns
; ++i
)
12231 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12233 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12235 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12236 " in section table [in module %s]"),
12237 id
, dwp_file
->name
);
12239 if (ids_seen
[id
] != -1)
12241 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12242 " id %d in section table [in module %s]"),
12243 id
, dwp_file
->name
);
12248 /* Must have exactly one info or types section. */
12249 if (((ids_seen
[DW_SECT_INFO
] != -1)
12250 + (ids_seen
[DW_SECT_TYPES
] != -1))
12253 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12254 " DWO info/types section [in module %s]"),
12257 /* Must have an abbrev section. */
12258 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12260 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12261 " section [in module %s]"),
12264 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12265 htab
->section_pool
.v2
.sizes
=
12266 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12267 * nr_units
* nr_columns
);
12268 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12269 * nr_units
* nr_columns
))
12272 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12273 " [in module %s]"),
12281 /* Update SECTIONS with the data from SECTP.
12283 This function is like the other "locate" section routines that are
12284 passed to bfd_map_over_sections, but in this context the sections to
12285 read comes from the DWP V1 hash table, not the full ELF section table.
12287 The result is non-zero for success, or zero if an error was found. */
12290 locate_v1_virtual_dwo_sections (asection
*sectp
,
12291 struct virtual_v1_dwo_sections
*sections
)
12293 const struct dwop_section_names
*names
= &dwop_section_names
;
12295 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12297 /* There can be only one. */
12298 if (sections
->abbrev
.s
.section
!= NULL
)
12300 sections
->abbrev
.s
.section
= sectp
;
12301 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12303 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12304 || section_is_p (sectp
->name
, &names
->types_dwo
))
12306 /* There can be only one. */
12307 if (sections
->info_or_types
.s
.section
!= NULL
)
12309 sections
->info_or_types
.s
.section
= sectp
;
12310 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
12312 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12314 /* There can be only one. */
12315 if (sections
->line
.s
.section
!= NULL
)
12317 sections
->line
.s
.section
= sectp
;
12318 sections
->line
.size
= bfd_get_section_size (sectp
);
12320 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12322 /* There can be only one. */
12323 if (sections
->loc
.s
.section
!= NULL
)
12325 sections
->loc
.s
.section
= sectp
;
12326 sections
->loc
.size
= bfd_get_section_size (sectp
);
12328 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12330 /* There can be only one. */
12331 if (sections
->macinfo
.s
.section
!= NULL
)
12333 sections
->macinfo
.s
.section
= sectp
;
12334 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12336 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12338 /* There can be only one. */
12339 if (sections
->macro
.s
.section
!= NULL
)
12341 sections
->macro
.s
.section
= sectp
;
12342 sections
->macro
.size
= bfd_get_section_size (sectp
);
12344 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12346 /* There can be only one. */
12347 if (sections
->str_offsets
.s
.section
!= NULL
)
12349 sections
->str_offsets
.s
.section
= sectp
;
12350 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12354 /* No other kind of section is valid. */
12361 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12362 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12363 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12364 This is for DWP version 1 files. */
12366 static struct dwo_unit
*
12367 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12368 struct dwp_file
*dwp_file
,
12369 uint32_t unit_index
,
12370 const char *comp_dir
,
12371 ULONGEST signature
, int is_debug_types
)
12373 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12374 const struct dwp_hash_table
*dwp_htab
=
12375 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12376 bfd
*dbfd
= dwp_file
->dbfd
;
12377 const char *kind
= is_debug_types
? "TU" : "CU";
12378 struct dwo_file
*dwo_file
;
12379 struct dwo_unit
*dwo_unit
;
12380 struct virtual_v1_dwo_sections sections
;
12381 void **dwo_file_slot
;
12384 gdb_assert (dwp_file
->version
== 1);
12386 if (dwarf_read_debug
)
12388 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12390 pulongest (unit_index
), hex_string (signature
),
12394 /* Fetch the sections of this DWO unit.
12395 Put a limit on the number of sections we look for so that bad data
12396 doesn't cause us to loop forever. */
12398 #define MAX_NR_V1_DWO_SECTIONS \
12399 (1 /* .debug_info or .debug_types */ \
12400 + 1 /* .debug_abbrev */ \
12401 + 1 /* .debug_line */ \
12402 + 1 /* .debug_loc */ \
12403 + 1 /* .debug_str_offsets */ \
12404 + 1 /* .debug_macro or .debug_macinfo */ \
12405 + 1 /* trailing zero */)
12407 memset (§ions
, 0, sizeof (sections
));
12409 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12412 uint32_t section_nr
=
12413 read_4_bytes (dbfd
,
12414 dwp_htab
->section_pool
.v1
.indices
12415 + (unit_index
+ i
) * sizeof (uint32_t));
12417 if (section_nr
== 0)
12419 if (section_nr
>= dwp_file
->num_sections
)
12421 error (_("Dwarf Error: bad DWP hash table, section number too large"
12422 " [in module %s]"),
12426 sectp
= dwp_file
->elf_sections
[section_nr
];
12427 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12429 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12430 " [in module %s]"),
12436 || dwarf2_section_empty_p (§ions
.info_or_types
)
12437 || dwarf2_section_empty_p (§ions
.abbrev
))
12439 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12440 " [in module %s]"),
12443 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12445 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12446 " [in module %s]"),
12450 /* It's easier for the rest of the code if we fake a struct dwo_file and
12451 have dwo_unit "live" in that. At least for now.
12453 The DWP file can be made up of a random collection of CUs and TUs.
12454 However, for each CU + set of TUs that came from the same original DWO
12455 file, we can combine them back into a virtual DWO file to save space
12456 (fewer struct dwo_file objects to allocate). Remember that for really
12457 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12459 std::string virtual_dwo_name
=
12460 string_printf ("virtual-dwo/%d-%d-%d-%d",
12461 get_section_id (§ions
.abbrev
),
12462 get_section_id (§ions
.line
),
12463 get_section_id (§ions
.loc
),
12464 get_section_id (§ions
.str_offsets
));
12465 /* Can we use an existing virtual DWO file? */
12466 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12467 virtual_dwo_name
.c_str (),
12469 /* Create one if necessary. */
12470 if (*dwo_file_slot
== NULL
)
12472 if (dwarf_read_debug
)
12474 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12475 virtual_dwo_name
.c_str ());
12477 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12479 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12480 virtual_dwo_name
.c_str (),
12481 virtual_dwo_name
.size ());
12482 dwo_file
->comp_dir
= comp_dir
;
12483 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12484 dwo_file
->sections
.line
= sections
.line
;
12485 dwo_file
->sections
.loc
= sections
.loc
;
12486 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12487 dwo_file
->sections
.macro
= sections
.macro
;
12488 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12489 /* The "str" section is global to the entire DWP file. */
12490 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12491 /* The info or types section is assigned below to dwo_unit,
12492 there's no need to record it in dwo_file.
12493 Also, we can't simply record type sections in dwo_file because
12494 we record a pointer into the vector in dwo_unit. As we collect more
12495 types we'll grow the vector and eventually have to reallocate space
12496 for it, invalidating all copies of pointers into the previous
12498 *dwo_file_slot
= dwo_file
;
12502 if (dwarf_read_debug
)
12504 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12505 virtual_dwo_name
.c_str ());
12507 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12510 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12511 dwo_unit
->dwo_file
= dwo_file
;
12512 dwo_unit
->signature
= signature
;
12513 dwo_unit
->section
=
12514 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12515 *dwo_unit
->section
= sections
.info_or_types
;
12516 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12521 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12522 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12523 piece within that section used by a TU/CU, return a virtual section
12524 of just that piece. */
12526 static struct dwarf2_section_info
12527 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12528 struct dwarf2_section_info
*section
,
12529 bfd_size_type offset
, bfd_size_type size
)
12531 struct dwarf2_section_info result
;
12534 gdb_assert (section
!= NULL
);
12535 gdb_assert (!section
->is_virtual
);
12537 memset (&result
, 0, sizeof (result
));
12538 result
.s
.containing_section
= section
;
12539 result
.is_virtual
= 1;
12544 sectp
= get_section_bfd_section (section
);
12546 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12547 bounds of the real section. This is a pretty-rare event, so just
12548 flag an error (easier) instead of a warning and trying to cope. */
12550 || offset
+ size
> bfd_get_section_size (sectp
))
12552 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12553 " in section %s [in module %s]"),
12554 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
12555 objfile_name (dwarf2_per_objfile
->objfile
));
12558 result
.virtual_offset
= offset
;
12559 result
.size
= size
;
12563 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12564 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12565 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12566 This is for DWP version 2 files. */
12568 static struct dwo_unit
*
12569 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12570 struct dwp_file
*dwp_file
,
12571 uint32_t unit_index
,
12572 const char *comp_dir
,
12573 ULONGEST signature
, int is_debug_types
)
12575 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12576 const struct dwp_hash_table
*dwp_htab
=
12577 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12578 bfd
*dbfd
= dwp_file
->dbfd
;
12579 const char *kind
= is_debug_types
? "TU" : "CU";
12580 struct dwo_file
*dwo_file
;
12581 struct dwo_unit
*dwo_unit
;
12582 struct virtual_v2_dwo_sections sections
;
12583 void **dwo_file_slot
;
12586 gdb_assert (dwp_file
->version
== 2);
12588 if (dwarf_read_debug
)
12590 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12592 pulongest (unit_index
), hex_string (signature
),
12596 /* Fetch the section offsets of this DWO unit. */
12598 memset (§ions
, 0, sizeof (sections
));
12600 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12602 uint32_t offset
= read_4_bytes (dbfd
,
12603 dwp_htab
->section_pool
.v2
.offsets
12604 + (((unit_index
- 1) * dwp_htab
->nr_columns
12606 * sizeof (uint32_t)));
12607 uint32_t size
= read_4_bytes (dbfd
,
12608 dwp_htab
->section_pool
.v2
.sizes
12609 + (((unit_index
- 1) * dwp_htab
->nr_columns
12611 * sizeof (uint32_t)));
12613 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12616 case DW_SECT_TYPES
:
12617 sections
.info_or_types_offset
= offset
;
12618 sections
.info_or_types_size
= size
;
12620 case DW_SECT_ABBREV
:
12621 sections
.abbrev_offset
= offset
;
12622 sections
.abbrev_size
= size
;
12625 sections
.line_offset
= offset
;
12626 sections
.line_size
= size
;
12629 sections
.loc_offset
= offset
;
12630 sections
.loc_size
= size
;
12632 case DW_SECT_STR_OFFSETS
:
12633 sections
.str_offsets_offset
= offset
;
12634 sections
.str_offsets_size
= size
;
12636 case DW_SECT_MACINFO
:
12637 sections
.macinfo_offset
= offset
;
12638 sections
.macinfo_size
= size
;
12640 case DW_SECT_MACRO
:
12641 sections
.macro_offset
= offset
;
12642 sections
.macro_size
= size
;
12647 /* It's easier for the rest of the code if we fake a struct dwo_file and
12648 have dwo_unit "live" in that. At least for now.
12650 The DWP file can be made up of a random collection of CUs and TUs.
12651 However, for each CU + set of TUs that came from the same original DWO
12652 file, we can combine them back into a virtual DWO file to save space
12653 (fewer struct dwo_file objects to allocate). Remember that for really
12654 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12656 std::string virtual_dwo_name
=
12657 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12658 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12659 (long) (sections
.line_size
? sections
.line_offset
: 0),
12660 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12661 (long) (sections
.str_offsets_size
12662 ? sections
.str_offsets_offset
: 0));
12663 /* Can we use an existing virtual DWO file? */
12664 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12665 virtual_dwo_name
.c_str (),
12667 /* Create one if necessary. */
12668 if (*dwo_file_slot
== NULL
)
12670 if (dwarf_read_debug
)
12672 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12673 virtual_dwo_name
.c_str ());
12675 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12677 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12678 virtual_dwo_name
.c_str (),
12679 virtual_dwo_name
.size ());
12680 dwo_file
->comp_dir
= comp_dir
;
12681 dwo_file
->sections
.abbrev
=
12682 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12683 sections
.abbrev_offset
, sections
.abbrev_size
);
12684 dwo_file
->sections
.line
=
12685 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12686 sections
.line_offset
, sections
.line_size
);
12687 dwo_file
->sections
.loc
=
12688 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12689 sections
.loc_offset
, sections
.loc_size
);
12690 dwo_file
->sections
.macinfo
=
12691 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12692 sections
.macinfo_offset
, sections
.macinfo_size
);
12693 dwo_file
->sections
.macro
=
12694 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12695 sections
.macro_offset
, sections
.macro_size
);
12696 dwo_file
->sections
.str_offsets
=
12697 create_dwp_v2_section (dwarf2_per_objfile
,
12698 &dwp_file
->sections
.str_offsets
,
12699 sections
.str_offsets_offset
,
12700 sections
.str_offsets_size
);
12701 /* The "str" section is global to the entire DWP file. */
12702 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12703 /* The info or types section is assigned below to dwo_unit,
12704 there's no need to record it in dwo_file.
12705 Also, we can't simply record type sections in dwo_file because
12706 we record a pointer into the vector in dwo_unit. As we collect more
12707 types we'll grow the vector and eventually have to reallocate space
12708 for it, invalidating all copies of pointers into the previous
12710 *dwo_file_slot
= dwo_file
;
12714 if (dwarf_read_debug
)
12716 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12717 virtual_dwo_name
.c_str ());
12719 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12722 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12723 dwo_unit
->dwo_file
= dwo_file
;
12724 dwo_unit
->signature
= signature
;
12725 dwo_unit
->section
=
12726 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12727 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12729 ? &dwp_file
->sections
.types
12730 : &dwp_file
->sections
.info
,
12731 sections
.info_or_types_offset
,
12732 sections
.info_or_types_size
);
12733 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12738 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12739 Returns NULL if the signature isn't found. */
12741 static struct dwo_unit
*
12742 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12743 struct dwp_file
*dwp_file
, const char *comp_dir
,
12744 ULONGEST signature
, int is_debug_types
)
12746 const struct dwp_hash_table
*dwp_htab
=
12747 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12748 bfd
*dbfd
= dwp_file
->dbfd
;
12749 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12750 uint32_t hash
= signature
& mask
;
12751 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12754 struct dwo_unit find_dwo_cu
;
12756 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12757 find_dwo_cu
.signature
= signature
;
12758 slot
= htab_find_slot (is_debug_types
12759 ? dwp_file
->loaded_tus
12760 : dwp_file
->loaded_cus
,
12761 &find_dwo_cu
, INSERT
);
12764 return (struct dwo_unit
*) *slot
;
12766 /* Use a for loop so that we don't loop forever on bad debug info. */
12767 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12769 ULONGEST signature_in_table
;
12771 signature_in_table
=
12772 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12773 if (signature_in_table
== signature
)
12775 uint32_t unit_index
=
12776 read_4_bytes (dbfd
,
12777 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12779 if (dwp_file
->version
== 1)
12781 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12782 dwp_file
, unit_index
,
12783 comp_dir
, signature
,
12788 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12789 dwp_file
, unit_index
,
12790 comp_dir
, signature
,
12793 return (struct dwo_unit
*) *slot
;
12795 if (signature_in_table
== 0)
12797 hash
= (hash
+ hash2
) & mask
;
12800 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12801 " [in module %s]"),
12805 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12806 Open the file specified by FILE_NAME and hand it off to BFD for
12807 preliminary analysis. Return a newly initialized bfd *, which
12808 includes a canonicalized copy of FILE_NAME.
12809 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12810 SEARCH_CWD is true if the current directory is to be searched.
12811 It will be searched before debug-file-directory.
12812 If successful, the file is added to the bfd include table of the
12813 objfile's bfd (see gdb_bfd_record_inclusion).
12814 If unable to find/open the file, return NULL.
12815 NOTE: This function is derived from symfile_bfd_open. */
12817 static gdb_bfd_ref_ptr
12818 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12819 const char *file_name
, int is_dwp
, int search_cwd
)
12822 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12823 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12824 to debug_file_directory. */
12825 const char *search_path
;
12826 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12828 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12831 if (*debug_file_directory
!= '\0')
12833 search_path_holder
.reset (concat (".", dirname_separator_string
,
12834 debug_file_directory
,
12836 search_path
= search_path_holder
.get ();
12842 search_path
= debug_file_directory
;
12844 openp_flags flags
= OPF_RETURN_REALPATH
;
12846 flags
|= OPF_SEARCH_IN_PATH
;
12848 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12849 desc
= openp (search_path
, flags
, file_name
,
12850 O_RDONLY
| O_BINARY
, &absolute_name
);
12854 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12856 if (sym_bfd
== NULL
)
12858 bfd_set_cacheable (sym_bfd
.get (), 1);
12860 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12863 /* Success. Record the bfd as having been included by the objfile's bfd.
12864 This is important because things like demangled_names_hash lives in the
12865 objfile's per_bfd space and may have references to things like symbol
12866 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12867 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12872 /* Try to open DWO file FILE_NAME.
12873 COMP_DIR is the DW_AT_comp_dir attribute.
12874 The result is the bfd handle of the file.
12875 If there is a problem finding or opening the file, return NULL.
12876 Upon success, the canonicalized path of the file is stored in the bfd,
12877 same as symfile_bfd_open. */
12879 static gdb_bfd_ref_ptr
12880 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12881 const char *file_name
, const char *comp_dir
)
12883 if (IS_ABSOLUTE_PATH (file_name
))
12884 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12885 0 /*is_dwp*/, 0 /*search_cwd*/);
12887 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12889 if (comp_dir
!= NULL
)
12891 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
12892 file_name
, (char *) NULL
);
12894 /* NOTE: If comp_dir is a relative path, this will also try the
12895 search path, which seems useful. */
12896 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12899 1 /*search_cwd*/));
12900 xfree (path_to_try
);
12905 /* That didn't work, try debug-file-directory, which, despite its name,
12906 is a list of paths. */
12908 if (*debug_file_directory
== '\0')
12911 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12912 0 /*is_dwp*/, 1 /*search_cwd*/);
12915 /* This function is mapped across the sections and remembers the offset and
12916 size of each of the DWO debugging sections we are interested in. */
12919 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12921 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12922 const struct dwop_section_names
*names
= &dwop_section_names
;
12924 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12926 dwo_sections
->abbrev
.s
.section
= sectp
;
12927 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12929 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12931 dwo_sections
->info
.s
.section
= sectp
;
12932 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
12934 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12936 dwo_sections
->line
.s
.section
= sectp
;
12937 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
12939 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12941 dwo_sections
->loc
.s
.section
= sectp
;
12942 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
12944 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12946 dwo_sections
->macinfo
.s
.section
= sectp
;
12947 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12949 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12951 dwo_sections
->macro
.s
.section
= sectp
;
12952 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
12954 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12956 dwo_sections
->str
.s
.section
= sectp
;
12957 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
12959 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12961 dwo_sections
->str_offsets
.s
.section
= sectp
;
12962 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12964 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12966 struct dwarf2_section_info type_section
;
12968 memset (&type_section
, 0, sizeof (type_section
));
12969 type_section
.s
.section
= sectp
;
12970 type_section
.size
= bfd_get_section_size (sectp
);
12971 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
12976 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12977 by PER_CU. This is for the non-DWP case.
12978 The result is NULL if DWO_NAME can't be found. */
12980 static struct dwo_file
*
12981 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12982 const char *dwo_name
, const char *comp_dir
)
12984 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12985 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12986 struct dwo_file
*dwo_file
;
12987 struct cleanup
*cleanups
;
12989 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
));
12992 if (dwarf_read_debug
)
12993 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12996 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12997 dwo_file
->dwo_name
= dwo_name
;
12998 dwo_file
->comp_dir
= comp_dir
;
12999 dwo_file
->dbfd
= dbfd
.release ();
13001 free_dwo_file_cleanup_data
*cleanup_data
= XNEW (free_dwo_file_cleanup_data
);
13002 cleanup_data
->dwo_file
= dwo_file
;
13003 cleanup_data
->dwarf2_per_objfile
= dwarf2_per_objfile
;
13005 cleanups
= make_cleanup (free_dwo_file_cleanup
, cleanup_data
);
13007 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
13008 &dwo_file
->sections
);
13010 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13013 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
,
13014 dwo_file
->sections
.types
, dwo_file
->tus
);
13016 discard_cleanups (cleanups
);
13018 if (dwarf_read_debug
)
13019 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13024 /* This function is mapped across the sections and remembers the offset and
13025 size of each of the DWP debugging sections common to version 1 and 2 that
13026 we are interested in. */
13029 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13030 void *dwp_file_ptr
)
13032 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13033 const struct dwop_section_names
*names
= &dwop_section_names
;
13034 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13036 /* Record the ELF section number for later lookup: this is what the
13037 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13038 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13039 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13041 /* Look for specific sections that we need. */
13042 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13044 dwp_file
->sections
.str
.s
.section
= sectp
;
13045 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
13047 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13049 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13050 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
13052 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13054 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13055 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
13059 /* This function is mapped across the sections and remembers the offset and
13060 size of each of the DWP version 2 debugging sections that we are interested
13061 in. This is split into a separate function because we don't know if we
13062 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13065 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13067 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13068 const struct dwop_section_names
*names
= &dwop_section_names
;
13069 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13071 /* Record the ELF section number for later lookup: this is what the
13072 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13073 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13074 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13076 /* Look for specific sections that we need. */
13077 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13079 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13080 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
13082 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13084 dwp_file
->sections
.info
.s
.section
= sectp
;
13085 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
13087 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13089 dwp_file
->sections
.line
.s
.section
= sectp
;
13090 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
13092 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13094 dwp_file
->sections
.loc
.s
.section
= sectp
;
13095 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
13097 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13099 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13100 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
13102 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13104 dwp_file
->sections
.macro
.s
.section
= sectp
;
13105 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
13107 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13109 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13110 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
13112 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13114 dwp_file
->sections
.types
.s
.section
= sectp
;
13115 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
13119 /* Hash function for dwp_file loaded CUs/TUs. */
13122 hash_dwp_loaded_cutus (const void *item
)
13124 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13126 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13127 return dwo_unit
->signature
;
13130 /* Equality function for dwp_file loaded CUs/TUs. */
13133 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13135 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13136 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13138 return dua
->signature
== dub
->signature
;
13141 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13144 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13146 return htab_create_alloc_ex (3,
13147 hash_dwp_loaded_cutus
,
13148 eq_dwp_loaded_cutus
,
13150 &objfile
->objfile_obstack
,
13151 hashtab_obstack_allocate
,
13152 dummy_obstack_deallocate
);
13155 /* Try to open DWP file FILE_NAME.
13156 The result is the bfd handle of the file.
13157 If there is a problem finding or opening the file, return NULL.
13158 Upon success, the canonicalized path of the file is stored in the bfd,
13159 same as symfile_bfd_open. */
13161 static gdb_bfd_ref_ptr
13162 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13163 const char *file_name
)
13165 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13167 1 /*search_cwd*/));
13171 /* Work around upstream bug 15652.
13172 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13173 [Whether that's a "bug" is debatable, but it is getting in our way.]
13174 We have no real idea where the dwp file is, because gdb's realpath-ing
13175 of the executable's path may have discarded the needed info.
13176 [IWBN if the dwp file name was recorded in the executable, akin to
13177 .gnu_debuglink, but that doesn't exist yet.]
13178 Strip the directory from FILE_NAME and search again. */
13179 if (*debug_file_directory
!= '\0')
13181 /* Don't implicitly search the current directory here.
13182 If the user wants to search "." to handle this case,
13183 it must be added to debug-file-directory. */
13184 return try_open_dwop_file (dwarf2_per_objfile
,
13185 lbasename (file_name
), 1 /*is_dwp*/,
13192 /* Initialize the use of the DWP file for the current objfile.
13193 By convention the name of the DWP file is ${objfile}.dwp.
13194 The result is NULL if it can't be found. */
13196 static struct dwp_file
*
13197 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13199 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13200 struct dwp_file
*dwp_file
;
13202 /* Try to find first .dwp for the binary file before any symbolic links
13205 /* If the objfile is a debug file, find the name of the real binary
13206 file and get the name of dwp file from there. */
13207 std::string dwp_name
;
13208 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13210 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13211 const char *backlink_basename
= lbasename (backlink
->original_name
);
13213 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13216 dwp_name
= objfile
->original_name
;
13218 dwp_name
+= ".dwp";
13220 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13222 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13224 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13225 dwp_name
= objfile_name (objfile
);
13226 dwp_name
+= ".dwp";
13227 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13232 if (dwarf_read_debug
)
13233 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13236 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
13237 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
13238 dwp_file
->dbfd
= dbfd
.release ();
13240 /* +1: section 0 is unused */
13241 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
13242 dwp_file
->elf_sections
=
13243 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13244 dwp_file
->num_sections
, asection
*);
13246 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
13249 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 0);
13251 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 1);
13253 /* The DWP file version is stored in the hash table. Oh well. */
13254 if (dwp_file
->cus
&& dwp_file
->tus
13255 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13257 /* Technically speaking, we should try to limp along, but this is
13258 pretty bizarre. We use pulongest here because that's the established
13259 portability solution (e.g, we cannot use %u for uint32_t). */
13260 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13261 " TU version %s [in DWP file %s]"),
13262 pulongest (dwp_file
->cus
->version
),
13263 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13267 dwp_file
->version
= dwp_file
->cus
->version
;
13268 else if (dwp_file
->tus
)
13269 dwp_file
->version
= dwp_file
->tus
->version
;
13271 dwp_file
->version
= 2;
13273 if (dwp_file
->version
== 2)
13274 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
13277 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13278 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13280 if (dwarf_read_debug
)
13282 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13283 fprintf_unfiltered (gdb_stdlog
,
13284 " %s CUs, %s TUs\n",
13285 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13286 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13292 /* Wrapper around open_and_init_dwp_file, only open it once. */
13294 static struct dwp_file
*
13295 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13297 if (! dwarf2_per_objfile
->dwp_checked
)
13299 dwarf2_per_objfile
->dwp_file
13300 = open_and_init_dwp_file (dwarf2_per_objfile
);
13301 dwarf2_per_objfile
->dwp_checked
= 1;
13303 return dwarf2_per_objfile
->dwp_file
;
13306 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13307 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13308 or in the DWP file for the objfile, referenced by THIS_UNIT.
13309 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13310 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13312 This is called, for example, when wanting to read a variable with a
13313 complex location. Therefore we don't want to do file i/o for every call.
13314 Therefore we don't want to look for a DWO file on every call.
13315 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13316 then we check if we've already seen DWO_NAME, and only THEN do we check
13319 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13320 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13322 static struct dwo_unit
*
13323 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13324 const char *dwo_name
, const char *comp_dir
,
13325 ULONGEST signature
, int is_debug_types
)
13327 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13328 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13329 const char *kind
= is_debug_types
? "TU" : "CU";
13330 void **dwo_file_slot
;
13331 struct dwo_file
*dwo_file
;
13332 struct dwp_file
*dwp_file
;
13334 /* First see if there's a DWP file.
13335 If we have a DWP file but didn't find the DWO inside it, don't
13336 look for the original DWO file. It makes gdb behave differently
13337 depending on whether one is debugging in the build tree. */
13339 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13340 if (dwp_file
!= NULL
)
13342 const struct dwp_hash_table
*dwp_htab
=
13343 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13345 if (dwp_htab
!= NULL
)
13347 struct dwo_unit
*dwo_cutu
=
13348 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13349 signature
, is_debug_types
);
13351 if (dwo_cutu
!= NULL
)
13353 if (dwarf_read_debug
)
13355 fprintf_unfiltered (gdb_stdlog
,
13356 "Virtual DWO %s %s found: @%s\n",
13357 kind
, hex_string (signature
),
13358 host_address_to_string (dwo_cutu
));
13366 /* No DWP file, look for the DWO file. */
13368 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13369 dwo_name
, comp_dir
);
13370 if (*dwo_file_slot
== NULL
)
13372 /* Read in the file and build a table of the CUs/TUs it contains. */
13373 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13375 /* NOTE: This will be NULL if unable to open the file. */
13376 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13378 if (dwo_file
!= NULL
)
13380 struct dwo_unit
*dwo_cutu
= NULL
;
13382 if (is_debug_types
&& dwo_file
->tus
)
13384 struct dwo_unit find_dwo_cutu
;
13386 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13387 find_dwo_cutu
.signature
= signature
;
13389 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13391 else if (!is_debug_types
&& dwo_file
->cus
)
13393 struct dwo_unit find_dwo_cutu
;
13395 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13396 find_dwo_cutu
.signature
= signature
;
13397 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13401 if (dwo_cutu
!= NULL
)
13403 if (dwarf_read_debug
)
13405 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13406 kind
, dwo_name
, hex_string (signature
),
13407 host_address_to_string (dwo_cutu
));
13414 /* We didn't find it. This could mean a dwo_id mismatch, or
13415 someone deleted the DWO/DWP file, or the search path isn't set up
13416 correctly to find the file. */
13418 if (dwarf_read_debug
)
13420 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13421 kind
, dwo_name
, hex_string (signature
));
13424 /* This is a warning and not a complaint because it can be caused by
13425 pilot error (e.g., user accidentally deleting the DWO). */
13427 /* Print the name of the DWP file if we looked there, helps the user
13428 better diagnose the problem. */
13429 std::string dwp_text
;
13431 if (dwp_file
!= NULL
)
13432 dwp_text
= string_printf (" [in DWP file %s]",
13433 lbasename (dwp_file
->name
));
13435 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13436 " [in module %s]"),
13437 kind
, dwo_name
, hex_string (signature
),
13439 this_unit
->is_debug_types
? "TU" : "CU",
13440 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13445 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13446 See lookup_dwo_cutu_unit for details. */
13448 static struct dwo_unit
*
13449 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13450 const char *dwo_name
, const char *comp_dir
,
13451 ULONGEST signature
)
13453 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13456 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13457 See lookup_dwo_cutu_unit for details. */
13459 static struct dwo_unit
*
13460 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13461 const char *dwo_name
, const char *comp_dir
)
13463 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13466 /* Traversal function for queue_and_load_all_dwo_tus. */
13469 queue_and_load_dwo_tu (void **slot
, void *info
)
13471 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13472 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13473 ULONGEST signature
= dwo_unit
->signature
;
13474 struct signatured_type
*sig_type
=
13475 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13477 if (sig_type
!= NULL
)
13479 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13481 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13482 a real dependency of PER_CU on SIG_TYPE. That is detected later
13483 while processing PER_CU. */
13484 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13485 load_full_type_unit (sig_cu
);
13486 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
13492 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13493 The DWO may have the only definition of the type, though it may not be
13494 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13495 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13498 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13500 struct dwo_unit
*dwo_unit
;
13501 struct dwo_file
*dwo_file
;
13503 gdb_assert (!per_cu
->is_debug_types
);
13504 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13505 gdb_assert (per_cu
->cu
!= NULL
);
13507 dwo_unit
= per_cu
->cu
->dwo_unit
;
13508 gdb_assert (dwo_unit
!= NULL
);
13510 dwo_file
= dwo_unit
->dwo_file
;
13511 if (dwo_file
->tus
!= NULL
)
13512 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13515 /* Free all resources associated with DWO_FILE.
13516 Close the DWO file and munmap the sections. */
13519 free_dwo_file (struct dwo_file
*dwo_file
)
13521 /* Note: dbfd is NULL for virtual DWO files. */
13522 gdb_bfd_unref (dwo_file
->dbfd
);
13524 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
13527 /* Wrapper for free_dwo_file for use in cleanups. */
13530 free_dwo_file_cleanup (void *arg
)
13532 struct free_dwo_file_cleanup_data
*data
13533 = (struct free_dwo_file_cleanup_data
*) arg
;
13535 free_dwo_file (data
->dwo_file
);
13540 /* Traversal function for free_dwo_files. */
13543 free_dwo_file_from_slot (void **slot
, void *info
)
13545 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
13547 free_dwo_file (dwo_file
);
13552 /* Free all resources associated with DWO_FILES. */
13555 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
13557 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
13560 /* Read in various DIEs. */
13562 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13563 Inherit only the children of the DW_AT_abstract_origin DIE not being
13564 already referenced by DW_AT_abstract_origin from the children of the
13568 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13570 struct die_info
*child_die
;
13571 sect_offset
*offsetp
;
13572 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13573 struct die_info
*origin_die
;
13574 /* Iterator of the ORIGIN_DIE children. */
13575 struct die_info
*origin_child_die
;
13576 struct attribute
*attr
;
13577 struct dwarf2_cu
*origin_cu
;
13578 struct pending
**origin_previous_list_in_scope
;
13580 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13584 /* Note that following die references may follow to a die in a
13588 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13590 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13592 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13593 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13595 if (die
->tag
!= origin_die
->tag
13596 && !(die
->tag
== DW_TAG_inlined_subroutine
13597 && origin_die
->tag
== DW_TAG_subprogram
))
13598 complaint (&symfile_complaints
,
13599 _("DIE %s and its abstract origin %s have different tags"),
13600 sect_offset_str (die
->sect_off
),
13601 sect_offset_str (origin_die
->sect_off
));
13603 std::vector
<sect_offset
> offsets
;
13605 for (child_die
= die
->child
;
13606 child_die
&& child_die
->tag
;
13607 child_die
= sibling_die (child_die
))
13609 struct die_info
*child_origin_die
;
13610 struct dwarf2_cu
*child_origin_cu
;
13612 /* We are trying to process concrete instance entries:
13613 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13614 it's not relevant to our analysis here. i.e. detecting DIEs that are
13615 present in the abstract instance but not referenced in the concrete
13617 if (child_die
->tag
== DW_TAG_call_site
13618 || child_die
->tag
== DW_TAG_GNU_call_site
)
13621 /* For each CHILD_DIE, find the corresponding child of
13622 ORIGIN_DIE. If there is more than one layer of
13623 DW_AT_abstract_origin, follow them all; there shouldn't be,
13624 but GCC versions at least through 4.4 generate this (GCC PR
13626 child_origin_die
= child_die
;
13627 child_origin_cu
= cu
;
13630 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13634 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13638 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13639 counterpart may exist. */
13640 if (child_origin_die
!= child_die
)
13642 if (child_die
->tag
!= child_origin_die
->tag
13643 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13644 && child_origin_die
->tag
== DW_TAG_subprogram
))
13645 complaint (&symfile_complaints
,
13646 _("Child DIE %s and its abstract origin %s have "
13648 sect_offset_str (child_die
->sect_off
),
13649 sect_offset_str (child_origin_die
->sect_off
));
13650 if (child_origin_die
->parent
!= origin_die
)
13651 complaint (&symfile_complaints
,
13652 _("Child DIE %s and its abstract origin %s have "
13653 "different parents"),
13654 sect_offset_str (child_die
->sect_off
),
13655 sect_offset_str (child_origin_die
->sect_off
));
13657 offsets
.push_back (child_origin_die
->sect_off
);
13660 std::sort (offsets
.begin (), offsets
.end ());
13661 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13662 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13663 if (offsetp
[-1] == *offsetp
)
13664 complaint (&symfile_complaints
,
13665 _("Multiple children of DIE %s refer "
13666 "to DIE %s as their abstract origin"),
13667 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13669 offsetp
= offsets
.data ();
13670 origin_child_die
= origin_die
->child
;
13671 while (origin_child_die
&& origin_child_die
->tag
)
13673 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13674 while (offsetp
< offsets_end
13675 && *offsetp
< origin_child_die
->sect_off
)
13677 if (offsetp
>= offsets_end
13678 || *offsetp
> origin_child_die
->sect_off
)
13680 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13681 Check whether we're already processing ORIGIN_CHILD_DIE.
13682 This can happen with mutually referenced abstract_origins.
13684 if (!origin_child_die
->in_process
)
13685 process_die (origin_child_die
, origin_cu
);
13687 origin_child_die
= sibling_die (origin_child_die
);
13689 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13693 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13695 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13696 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13697 struct context_stack
*newobj
;
13700 struct die_info
*child_die
;
13701 struct attribute
*attr
, *call_line
, *call_file
;
13703 CORE_ADDR baseaddr
;
13704 struct block
*block
;
13705 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13706 std::vector
<struct symbol
*> template_args
;
13707 struct template_symbol
*templ_func
= NULL
;
13711 /* If we do not have call site information, we can't show the
13712 caller of this inlined function. That's too confusing, so
13713 only use the scope for local variables. */
13714 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13715 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13716 if (call_line
== NULL
|| call_file
== NULL
)
13718 read_lexical_block_scope (die
, cu
);
13723 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13725 name
= dwarf2_name (die
, cu
);
13727 /* Ignore functions with missing or empty names. These are actually
13728 illegal according to the DWARF standard. */
13731 complaint (&symfile_complaints
,
13732 _("missing name for subprogram DIE at %s"),
13733 sect_offset_str (die
->sect_off
));
13737 /* Ignore functions with missing or invalid low and high pc attributes. */
13738 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13739 <= PC_BOUNDS_INVALID
)
13741 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13742 if (!attr
|| !DW_UNSND (attr
))
13743 complaint (&symfile_complaints
,
13744 _("cannot get low and high bounds "
13745 "for subprogram DIE at %s"),
13746 sect_offset_str (die
->sect_off
));
13750 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13751 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13753 /* If we have any template arguments, then we must allocate a
13754 different sort of symbol. */
13755 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13757 if (child_die
->tag
== DW_TAG_template_type_param
13758 || child_die
->tag
== DW_TAG_template_value_param
)
13760 templ_func
= allocate_template_symbol (objfile
);
13761 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13766 newobj
= push_context (0, lowpc
);
13767 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13768 (struct symbol
*) templ_func
);
13770 /* If there is a location expression for DW_AT_frame_base, record
13772 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13774 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13776 /* If there is a location for the static link, record it. */
13777 newobj
->static_link
= NULL
;
13778 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13781 newobj
->static_link
13782 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13783 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
13786 cu
->list_in_scope
= &local_symbols
;
13788 if (die
->child
!= NULL
)
13790 child_die
= die
->child
;
13791 while (child_die
&& child_die
->tag
)
13793 if (child_die
->tag
== DW_TAG_template_type_param
13794 || child_die
->tag
== DW_TAG_template_value_param
)
13796 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13799 template_args
.push_back (arg
);
13802 process_die (child_die
, cu
);
13803 child_die
= sibling_die (child_die
);
13807 inherit_abstract_dies (die
, cu
);
13809 /* If we have a DW_AT_specification, we might need to import using
13810 directives from the context of the specification DIE. See the
13811 comment in determine_prefix. */
13812 if (cu
->language
== language_cplus
13813 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13815 struct dwarf2_cu
*spec_cu
= cu
;
13816 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13820 child_die
= spec_die
->child
;
13821 while (child_die
&& child_die
->tag
)
13823 if (child_die
->tag
== DW_TAG_imported_module
)
13824 process_die (child_die
, spec_cu
);
13825 child_die
= sibling_die (child_die
);
13828 /* In some cases, GCC generates specification DIEs that
13829 themselves contain DW_AT_specification attributes. */
13830 spec_die
= die_specification (spec_die
, &spec_cu
);
13834 newobj
= pop_context ();
13835 /* Make a block for the local symbols within. */
13836 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
13837 newobj
->static_link
, lowpc
, highpc
);
13839 /* For C++, set the block's scope. */
13840 if ((cu
->language
== language_cplus
13841 || cu
->language
== language_fortran
13842 || cu
->language
== language_d
13843 || cu
->language
== language_rust
)
13844 && cu
->processing_has_namespace_info
)
13845 block_set_scope (block
, determine_prefix (die
, cu
),
13846 &objfile
->objfile_obstack
);
13848 /* If we have address ranges, record them. */
13849 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13851 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
13853 /* Attach template arguments to function. */
13854 if (!template_args
.empty ())
13856 gdb_assert (templ_func
!= NULL
);
13858 templ_func
->n_template_arguments
= template_args
.size ();
13859 templ_func
->template_arguments
13860 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13861 templ_func
->n_template_arguments
);
13862 memcpy (templ_func
->template_arguments
,
13863 template_args
.data (),
13864 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13867 /* In C++, we can have functions nested inside functions (e.g., when
13868 a function declares a class that has methods). This means that
13869 when we finish processing a function scope, we may need to go
13870 back to building a containing block's symbol lists. */
13871 local_symbols
= newobj
->locals
;
13872 local_using_directives
= newobj
->local_using_directives
;
13874 /* If we've finished processing a top-level function, subsequent
13875 symbols go in the file symbol list. */
13876 if (outermost_context_p ())
13877 cu
->list_in_scope
= &file_symbols
;
13880 /* Process all the DIES contained within a lexical block scope. Start
13881 a new scope, process the dies, and then close the scope. */
13884 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13886 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13887 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13888 struct context_stack
*newobj
;
13889 CORE_ADDR lowpc
, highpc
;
13890 struct die_info
*child_die
;
13891 CORE_ADDR baseaddr
;
13893 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13895 /* Ignore blocks with missing or invalid low and high pc attributes. */
13896 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13897 as multiple lexical blocks? Handling children in a sane way would
13898 be nasty. Might be easier to properly extend generic blocks to
13899 describe ranges. */
13900 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13902 case PC_BOUNDS_NOT_PRESENT
:
13903 /* DW_TAG_lexical_block has no attributes, process its children as if
13904 there was no wrapping by that DW_TAG_lexical_block.
13905 GCC does no longer produces such DWARF since GCC r224161. */
13906 for (child_die
= die
->child
;
13907 child_die
!= NULL
&& child_die
->tag
;
13908 child_die
= sibling_die (child_die
))
13909 process_die (child_die
, cu
);
13911 case PC_BOUNDS_INVALID
:
13914 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13915 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13917 push_context (0, lowpc
);
13918 if (die
->child
!= NULL
)
13920 child_die
= die
->child
;
13921 while (child_die
&& child_die
->tag
)
13923 process_die (child_die
, cu
);
13924 child_die
= sibling_die (child_die
);
13927 inherit_abstract_dies (die
, cu
);
13928 newobj
= pop_context ();
13930 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
13932 struct block
*block
13933 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
13934 newobj
->start_addr
, highpc
);
13936 /* Note that recording ranges after traversing children, as we
13937 do here, means that recording a parent's ranges entails
13938 walking across all its children's ranges as they appear in
13939 the address map, which is quadratic behavior.
13941 It would be nicer to record the parent's ranges before
13942 traversing its children, simply overriding whatever you find
13943 there. But since we don't even decide whether to create a
13944 block until after we've traversed its children, that's hard
13946 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13948 local_symbols
= newobj
->locals
;
13949 local_using_directives
= newobj
->local_using_directives
;
13952 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13955 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13957 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13958 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13959 CORE_ADDR pc
, baseaddr
;
13960 struct attribute
*attr
;
13961 struct call_site
*call_site
, call_site_local
;
13964 struct die_info
*child_die
;
13966 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13968 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13971 /* This was a pre-DWARF-5 GNU extension alias
13972 for DW_AT_call_return_pc. */
13973 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13977 complaint (&symfile_complaints
,
13978 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
13979 "DIE %s [in module %s]"),
13980 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13983 pc
= attr_value_as_address (attr
) + baseaddr
;
13984 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13986 if (cu
->call_site_htab
== NULL
)
13987 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13988 NULL
, &objfile
->objfile_obstack
,
13989 hashtab_obstack_allocate
, NULL
);
13990 call_site_local
.pc
= pc
;
13991 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13994 complaint (&symfile_complaints
,
13995 _("Duplicate PC %s for DW_TAG_call_site "
13996 "DIE %s [in module %s]"),
13997 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13998 objfile_name (objfile
));
14002 /* Count parameters at the caller. */
14005 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
14006 child_die
= sibling_die (child_die
))
14008 if (child_die
->tag
!= DW_TAG_call_site_parameter
14009 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14011 complaint (&symfile_complaints
,
14012 _("Tag %d is not DW_TAG_call_site_parameter in "
14013 "DW_TAG_call_site child DIE %s [in module %s]"),
14014 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
14015 objfile_name (objfile
));
14023 = ((struct call_site
*)
14024 obstack_alloc (&objfile
->objfile_obstack
,
14025 sizeof (*call_site
)
14026 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14028 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14029 call_site
->pc
= pc
;
14031 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14032 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14034 struct die_info
*func_die
;
14036 /* Skip also over DW_TAG_inlined_subroutine. */
14037 for (func_die
= die
->parent
;
14038 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14039 && func_die
->tag
!= DW_TAG_subroutine_type
;
14040 func_die
= func_die
->parent
);
14042 /* DW_AT_call_all_calls is a superset
14043 of DW_AT_call_all_tail_calls. */
14045 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14046 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14047 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14048 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14050 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14051 not complete. But keep CALL_SITE for look ups via call_site_htab,
14052 both the initial caller containing the real return address PC and
14053 the final callee containing the current PC of a chain of tail
14054 calls do not need to have the tail call list complete. But any
14055 function candidate for a virtual tail call frame searched via
14056 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14057 determined unambiguously. */
14061 struct type
*func_type
= NULL
;
14064 func_type
= get_die_type (func_die
, cu
);
14065 if (func_type
!= NULL
)
14067 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14069 /* Enlist this call site to the function. */
14070 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14071 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14074 complaint (&symfile_complaints
,
14075 _("Cannot find function owning DW_TAG_call_site "
14076 "DIE %s [in module %s]"),
14077 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14081 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14083 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14085 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14088 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14089 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14091 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14092 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14093 /* Keep NULL DWARF_BLOCK. */;
14094 else if (attr_form_is_block (attr
))
14096 struct dwarf2_locexpr_baton
*dlbaton
;
14098 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14099 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14100 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14101 dlbaton
->per_cu
= cu
->per_cu
;
14103 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14105 else if (attr_form_is_ref (attr
))
14107 struct dwarf2_cu
*target_cu
= cu
;
14108 struct die_info
*target_die
;
14110 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14111 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14112 if (die_is_declaration (target_die
, target_cu
))
14114 const char *target_physname
;
14116 /* Prefer the mangled name; otherwise compute the demangled one. */
14117 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14118 if (target_physname
== NULL
)
14119 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14120 if (target_physname
== NULL
)
14121 complaint (&symfile_complaints
,
14122 _("DW_AT_call_target target DIE has invalid "
14123 "physname, for referencing DIE %s [in module %s]"),
14124 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14126 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14132 /* DW_AT_entry_pc should be preferred. */
14133 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14134 <= PC_BOUNDS_INVALID
)
14135 complaint (&symfile_complaints
,
14136 _("DW_AT_call_target target DIE has invalid "
14137 "low pc, for referencing DIE %s [in module %s]"),
14138 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14141 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14142 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14147 complaint (&symfile_complaints
,
14148 _("DW_TAG_call_site DW_AT_call_target is neither "
14149 "block nor reference, for DIE %s [in module %s]"),
14150 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14152 call_site
->per_cu
= cu
->per_cu
;
14154 for (child_die
= die
->child
;
14155 child_die
&& child_die
->tag
;
14156 child_die
= sibling_die (child_die
))
14158 struct call_site_parameter
*parameter
;
14159 struct attribute
*loc
, *origin
;
14161 if (child_die
->tag
!= DW_TAG_call_site_parameter
14162 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14164 /* Already printed the complaint above. */
14168 gdb_assert (call_site
->parameter_count
< nparams
);
14169 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14171 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14172 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14173 register is contained in DW_AT_call_value. */
14175 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14176 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14177 if (origin
== NULL
)
14179 /* This was a pre-DWARF-5 GNU extension alias
14180 for DW_AT_call_parameter. */
14181 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14183 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14185 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14187 sect_offset sect_off
14188 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14189 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14191 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14192 binding can be done only inside one CU. Such referenced DIE
14193 therefore cannot be even moved to DW_TAG_partial_unit. */
14194 complaint (&symfile_complaints
,
14195 _("DW_AT_call_parameter offset is not in CU for "
14196 "DW_TAG_call_site child DIE %s [in module %s]"),
14197 sect_offset_str (child_die
->sect_off
),
14198 objfile_name (objfile
));
14201 parameter
->u
.param_cu_off
14202 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14204 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14206 complaint (&symfile_complaints
,
14207 _("No DW_FORM_block* DW_AT_location for "
14208 "DW_TAG_call_site child DIE %s [in module %s]"),
14209 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14214 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14215 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14216 if (parameter
->u
.dwarf_reg
!= -1)
14217 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14218 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14219 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14220 ¶meter
->u
.fb_offset
))
14221 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14224 complaint (&symfile_complaints
,
14225 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
14226 "for DW_FORM_block* DW_AT_location is supported for "
14227 "DW_TAG_call_site child DIE %s "
14229 sect_offset_str (child_die
->sect_off
),
14230 objfile_name (objfile
));
14235 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14237 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14238 if (!attr_form_is_block (attr
))
14240 complaint (&symfile_complaints
,
14241 _("No DW_FORM_block* DW_AT_call_value for "
14242 "DW_TAG_call_site child DIE %s [in module %s]"),
14243 sect_offset_str (child_die
->sect_off
),
14244 objfile_name (objfile
));
14247 parameter
->value
= DW_BLOCK (attr
)->data
;
14248 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14250 /* Parameters are not pre-cleared by memset above. */
14251 parameter
->data_value
= NULL
;
14252 parameter
->data_value_size
= 0;
14253 call_site
->parameter_count
++;
14255 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14257 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14260 if (!attr_form_is_block (attr
))
14261 complaint (&symfile_complaints
,
14262 _("No DW_FORM_block* DW_AT_call_data_value for "
14263 "DW_TAG_call_site child DIE %s [in module %s]"),
14264 sect_offset_str (child_die
->sect_off
),
14265 objfile_name (objfile
));
14268 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14269 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14275 /* Helper function for read_variable. If DIE represents a virtual
14276 table, then return the type of the concrete object that is
14277 associated with the virtual table. Otherwise, return NULL. */
14279 static struct type
*
14280 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14282 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14286 /* Find the type DIE. */
14287 struct die_info
*type_die
= NULL
;
14288 struct dwarf2_cu
*type_cu
= cu
;
14290 if (attr_form_is_ref (attr
))
14291 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14292 if (type_die
== NULL
)
14295 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14297 return die_containing_type (type_die
, type_cu
);
14300 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14303 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14305 struct rust_vtable_symbol
*storage
= NULL
;
14307 if (cu
->language
== language_rust
)
14309 struct type
*containing_type
= rust_containing_type (die
, cu
);
14311 if (containing_type
!= NULL
)
14313 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14315 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14316 struct rust_vtable_symbol
);
14317 initialize_objfile_symbol (storage
);
14318 storage
->concrete_type
= containing_type
;
14319 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14323 new_symbol (die
, NULL
, cu
, storage
);
14326 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14327 reading .debug_rnglists.
14328 Callback's type should be:
14329 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14330 Return true if the attributes are present and valid, otherwise,
14333 template <typename Callback
>
14335 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14336 Callback
&&callback
)
14338 struct dwarf2_per_objfile
*dwarf2_per_objfile
14339 = cu
->per_cu
->dwarf2_per_objfile
;
14340 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14341 bfd
*obfd
= objfile
->obfd
;
14342 /* Base address selection entry. */
14345 const gdb_byte
*buffer
;
14346 CORE_ADDR baseaddr
;
14347 bool overflow
= false;
14349 found_base
= cu
->base_known
;
14350 base
= cu
->base_address
;
14352 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14353 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14355 complaint (&symfile_complaints
,
14356 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14360 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14362 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14366 /* Initialize it due to a false compiler warning. */
14367 CORE_ADDR range_beginning
= 0, range_end
= 0;
14368 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14369 + dwarf2_per_objfile
->rnglists
.size
);
14370 unsigned int bytes_read
;
14372 if (buffer
== buf_end
)
14377 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14380 case DW_RLE_end_of_list
:
14382 case DW_RLE_base_address
:
14383 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14388 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14390 buffer
+= bytes_read
;
14392 case DW_RLE_start_length
:
14393 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14398 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14399 buffer
+= bytes_read
;
14400 range_end
= (range_beginning
14401 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14402 buffer
+= bytes_read
;
14403 if (buffer
> buf_end
)
14409 case DW_RLE_offset_pair
:
14410 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14411 buffer
+= bytes_read
;
14412 if (buffer
> buf_end
)
14417 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14418 buffer
+= bytes_read
;
14419 if (buffer
> buf_end
)
14425 case DW_RLE_start_end
:
14426 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14431 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14432 buffer
+= bytes_read
;
14433 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14434 buffer
+= bytes_read
;
14437 complaint (&symfile_complaints
,
14438 _("Invalid .debug_rnglists data (no base address)"));
14441 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14443 if (rlet
== DW_RLE_base_address
)
14448 /* We have no valid base address for the ranges
14450 complaint (&symfile_complaints
,
14451 _("Invalid .debug_rnglists data (no base address)"));
14455 if (range_beginning
> range_end
)
14457 /* Inverted range entries are invalid. */
14458 complaint (&symfile_complaints
,
14459 _("Invalid .debug_rnglists data (inverted range)"));
14463 /* Empty range entries have no effect. */
14464 if (range_beginning
== range_end
)
14467 range_beginning
+= base
;
14470 /* A not-uncommon case of bad debug info.
14471 Don't pollute the addrmap with bad data. */
14472 if (range_beginning
+ baseaddr
== 0
14473 && !dwarf2_per_objfile
->has_section_at_zero
)
14475 complaint (&symfile_complaints
,
14476 _(".debug_rnglists entry has start address of zero"
14477 " [in module %s]"), objfile_name (objfile
));
14481 callback (range_beginning
, range_end
);
14486 complaint (&symfile_complaints
,
14487 _("Offset %d is not terminated "
14488 "for DW_AT_ranges attribute"),
14496 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14497 Callback's type should be:
14498 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14499 Return 1 if the attributes are present and valid, otherwise, return 0. */
14501 template <typename Callback
>
14503 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14504 Callback
&&callback
)
14506 struct dwarf2_per_objfile
*dwarf2_per_objfile
14507 = cu
->per_cu
->dwarf2_per_objfile
;
14508 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14509 struct comp_unit_head
*cu_header
= &cu
->header
;
14510 bfd
*obfd
= objfile
->obfd
;
14511 unsigned int addr_size
= cu_header
->addr_size
;
14512 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14513 /* Base address selection entry. */
14516 unsigned int dummy
;
14517 const gdb_byte
*buffer
;
14518 CORE_ADDR baseaddr
;
14520 if (cu_header
->version
>= 5)
14521 return dwarf2_rnglists_process (offset
, cu
, callback
);
14523 found_base
= cu
->base_known
;
14524 base
= cu
->base_address
;
14526 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14527 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14529 complaint (&symfile_complaints
,
14530 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14534 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14536 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14540 CORE_ADDR range_beginning
, range_end
;
14542 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14543 buffer
+= addr_size
;
14544 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14545 buffer
+= addr_size
;
14546 offset
+= 2 * addr_size
;
14548 /* An end of list marker is a pair of zero addresses. */
14549 if (range_beginning
== 0 && range_end
== 0)
14550 /* Found the end of list entry. */
14553 /* Each base address selection entry is a pair of 2 values.
14554 The first is the largest possible address, the second is
14555 the base address. Check for a base address here. */
14556 if ((range_beginning
& mask
) == mask
)
14558 /* If we found the largest possible address, then we already
14559 have the base address in range_end. */
14567 /* We have no valid base address for the ranges
14569 complaint (&symfile_complaints
,
14570 _("Invalid .debug_ranges data (no base address)"));
14574 if (range_beginning
> range_end
)
14576 /* Inverted range entries are invalid. */
14577 complaint (&symfile_complaints
,
14578 _("Invalid .debug_ranges data (inverted range)"));
14582 /* Empty range entries have no effect. */
14583 if (range_beginning
== range_end
)
14586 range_beginning
+= base
;
14589 /* A not-uncommon case of bad debug info.
14590 Don't pollute the addrmap with bad data. */
14591 if (range_beginning
+ baseaddr
== 0
14592 && !dwarf2_per_objfile
->has_section_at_zero
)
14594 complaint (&symfile_complaints
,
14595 _(".debug_ranges entry has start address of zero"
14596 " [in module %s]"), objfile_name (objfile
));
14600 callback (range_beginning
, range_end
);
14606 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14607 Return 1 if the attributes are present and valid, otherwise, return 0.
14608 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14611 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14612 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14613 struct partial_symtab
*ranges_pst
)
14615 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14616 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14617 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14618 SECT_OFF_TEXT (objfile
));
14621 CORE_ADDR high
= 0;
14624 retval
= dwarf2_ranges_process (offset
, cu
,
14625 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14627 if (ranges_pst
!= NULL
)
14632 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14633 range_beginning
+ baseaddr
);
14634 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14635 range_end
+ baseaddr
);
14636 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
14640 /* FIXME: This is recording everything as a low-high
14641 segment of consecutive addresses. We should have a
14642 data structure for discontiguous block ranges
14646 low
= range_beginning
;
14652 if (range_beginning
< low
)
14653 low
= range_beginning
;
14654 if (range_end
> high
)
14662 /* If the first entry is an end-of-list marker, the range
14663 describes an empty scope, i.e. no instructions. */
14669 *high_return
= high
;
14673 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14674 definition for the return value. *LOWPC and *HIGHPC are set iff
14675 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14677 static enum pc_bounds_kind
14678 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14679 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14680 struct partial_symtab
*pst
)
14682 struct dwarf2_per_objfile
*dwarf2_per_objfile
14683 = cu
->per_cu
->dwarf2_per_objfile
;
14684 struct attribute
*attr
;
14685 struct attribute
*attr_high
;
14687 CORE_ADDR high
= 0;
14688 enum pc_bounds_kind ret
;
14690 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14693 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14696 low
= attr_value_as_address (attr
);
14697 high
= attr_value_as_address (attr_high
);
14698 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14702 /* Found high w/o low attribute. */
14703 return PC_BOUNDS_INVALID
;
14705 /* Found consecutive range of addresses. */
14706 ret
= PC_BOUNDS_HIGH_LOW
;
14710 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14713 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14714 We take advantage of the fact that DW_AT_ranges does not appear
14715 in DW_TAG_compile_unit of DWO files. */
14716 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14717 unsigned int ranges_offset
= (DW_UNSND (attr
)
14718 + (need_ranges_base
14722 /* Value of the DW_AT_ranges attribute is the offset in the
14723 .debug_ranges section. */
14724 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14725 return PC_BOUNDS_INVALID
;
14726 /* Found discontinuous range of addresses. */
14727 ret
= PC_BOUNDS_RANGES
;
14730 return PC_BOUNDS_NOT_PRESENT
;
14733 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14735 return PC_BOUNDS_INVALID
;
14737 /* When using the GNU linker, .gnu.linkonce. sections are used to
14738 eliminate duplicate copies of functions and vtables and such.
14739 The linker will arbitrarily choose one and discard the others.
14740 The AT_*_pc values for such functions refer to local labels in
14741 these sections. If the section from that file was discarded, the
14742 labels are not in the output, so the relocs get a value of 0.
14743 If this is a discarded function, mark the pc bounds as invalid,
14744 so that GDB will ignore it. */
14745 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14746 return PC_BOUNDS_INVALID
;
14754 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14755 its low and high PC addresses. Do nothing if these addresses could not
14756 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14757 and HIGHPC to the high address if greater than HIGHPC. */
14760 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14761 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14762 struct dwarf2_cu
*cu
)
14764 CORE_ADDR low
, high
;
14765 struct die_info
*child
= die
->child
;
14767 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14769 *lowpc
= std::min (*lowpc
, low
);
14770 *highpc
= std::max (*highpc
, high
);
14773 /* If the language does not allow nested subprograms (either inside
14774 subprograms or lexical blocks), we're done. */
14775 if (cu
->language
!= language_ada
)
14778 /* Check all the children of the given DIE. If it contains nested
14779 subprograms, then check their pc bounds. Likewise, we need to
14780 check lexical blocks as well, as they may also contain subprogram
14782 while (child
&& child
->tag
)
14784 if (child
->tag
== DW_TAG_subprogram
14785 || child
->tag
== DW_TAG_lexical_block
)
14786 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14787 child
= sibling_die (child
);
14791 /* Get the low and high pc's represented by the scope DIE, and store
14792 them in *LOWPC and *HIGHPC. If the correct values can't be
14793 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14796 get_scope_pc_bounds (struct die_info
*die
,
14797 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14798 struct dwarf2_cu
*cu
)
14800 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14801 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14802 CORE_ADDR current_low
, current_high
;
14804 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14805 >= PC_BOUNDS_RANGES
)
14807 best_low
= current_low
;
14808 best_high
= current_high
;
14812 struct die_info
*child
= die
->child
;
14814 while (child
&& child
->tag
)
14816 switch (child
->tag
) {
14817 case DW_TAG_subprogram
:
14818 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14820 case DW_TAG_namespace
:
14821 case DW_TAG_module
:
14822 /* FIXME: carlton/2004-01-16: Should we do this for
14823 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14824 that current GCC's always emit the DIEs corresponding
14825 to definitions of methods of classes as children of a
14826 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14827 the DIEs giving the declarations, which could be
14828 anywhere). But I don't see any reason why the
14829 standards says that they have to be there. */
14830 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14832 if (current_low
!= ((CORE_ADDR
) -1))
14834 best_low
= std::min (best_low
, current_low
);
14835 best_high
= std::max (best_high
, current_high
);
14843 child
= sibling_die (child
);
14848 *highpc
= best_high
;
14851 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14855 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14856 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14858 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14859 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14860 struct attribute
*attr
;
14861 struct attribute
*attr_high
;
14863 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14866 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14869 CORE_ADDR low
= attr_value_as_address (attr
);
14870 CORE_ADDR high
= attr_value_as_address (attr_high
);
14872 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14875 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14876 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14877 record_block_range (block
, low
, high
- 1);
14881 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14884 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14885 We take advantage of the fact that DW_AT_ranges does not appear
14886 in DW_TAG_compile_unit of DWO files. */
14887 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14889 /* The value of the DW_AT_ranges attribute is the offset of the
14890 address range list in the .debug_ranges section. */
14891 unsigned long offset
= (DW_UNSND (attr
)
14892 + (need_ranges_base
? cu
->ranges_base
: 0));
14893 const gdb_byte
*buffer
;
14895 /* For some target architectures, but not others, the
14896 read_address function sign-extends the addresses it returns.
14897 To recognize base address selection entries, we need a
14899 unsigned int addr_size
= cu
->header
.addr_size
;
14900 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14902 /* The base address, to which the next pair is relative. Note
14903 that this 'base' is a DWARF concept: most entries in a range
14904 list are relative, to reduce the number of relocs against the
14905 debugging information. This is separate from this function's
14906 'baseaddr' argument, which GDB uses to relocate debugging
14907 information from a shared library based on the address at
14908 which the library was loaded. */
14909 CORE_ADDR base
= cu
->base_address
;
14910 int base_known
= cu
->base_known
;
14912 dwarf2_ranges_process (offset
, cu
,
14913 [&] (CORE_ADDR start
, CORE_ADDR end
)
14917 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14918 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14919 record_block_range (block
, start
, end
- 1);
14924 /* Check whether the producer field indicates either of GCC < 4.6, or the
14925 Intel C/C++ compiler, and cache the result in CU. */
14928 check_producer (struct dwarf2_cu
*cu
)
14932 if (cu
->producer
== NULL
)
14934 /* For unknown compilers expect their behavior is DWARF version
14937 GCC started to support .debug_types sections by -gdwarf-4 since
14938 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14939 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14940 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14941 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14943 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14945 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14946 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14948 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14949 cu
->producer_is_icc_lt_14
= major
< 14;
14952 /* For other non-GCC compilers, expect their behavior is DWARF version
14956 cu
->checked_producer
= 1;
14959 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14960 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14961 during 4.6.0 experimental. */
14964 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14966 if (!cu
->checked_producer
)
14967 check_producer (cu
);
14969 return cu
->producer_is_gxx_lt_4_6
;
14972 /* Return the default accessibility type if it is not overriden by
14973 DW_AT_accessibility. */
14975 static enum dwarf_access_attribute
14976 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14978 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14980 /* The default DWARF 2 accessibility for members is public, the default
14981 accessibility for inheritance is private. */
14983 if (die
->tag
!= DW_TAG_inheritance
)
14984 return DW_ACCESS_public
;
14986 return DW_ACCESS_private
;
14990 /* DWARF 3+ defines the default accessibility a different way. The same
14991 rules apply now for DW_TAG_inheritance as for the members and it only
14992 depends on the container kind. */
14994 if (die
->parent
->tag
== DW_TAG_class_type
)
14995 return DW_ACCESS_private
;
14997 return DW_ACCESS_public
;
15001 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
15002 offset. If the attribute was not found return 0, otherwise return
15003 1. If it was found but could not properly be handled, set *OFFSET
15007 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15010 struct attribute
*attr
;
15012 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15017 /* Note that we do not check for a section offset first here.
15018 This is because DW_AT_data_member_location is new in DWARF 4,
15019 so if we see it, we can assume that a constant form is really
15020 a constant and not a section offset. */
15021 if (attr_form_is_constant (attr
))
15022 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15023 else if (attr_form_is_section_offset (attr
))
15024 dwarf2_complex_location_expr_complaint ();
15025 else if (attr_form_is_block (attr
))
15026 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15028 dwarf2_complex_location_expr_complaint ();
15036 /* Add an aggregate field to the field list. */
15039 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15040 struct dwarf2_cu
*cu
)
15042 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15043 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15044 struct nextfield
*new_field
;
15045 struct attribute
*attr
;
15047 const char *fieldname
= "";
15049 if (die
->tag
== DW_TAG_inheritance
)
15051 fip
->baseclasses
.emplace_back ();
15052 new_field
= &fip
->baseclasses
.back ();
15056 fip
->fields
.emplace_back ();
15057 new_field
= &fip
->fields
.back ();
15062 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15064 new_field
->accessibility
= DW_UNSND (attr
);
15066 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15067 if (new_field
->accessibility
!= DW_ACCESS_public
)
15068 fip
->non_public_fields
= 1;
15070 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15072 new_field
->virtuality
= DW_UNSND (attr
);
15074 new_field
->virtuality
= DW_VIRTUALITY_none
;
15076 fp
= &new_field
->field
;
15078 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15082 /* Data member other than a C++ static data member. */
15084 /* Get type of field. */
15085 fp
->type
= die_type (die
, cu
);
15087 SET_FIELD_BITPOS (*fp
, 0);
15089 /* Get bit size of field (zero if none). */
15090 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15093 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15097 FIELD_BITSIZE (*fp
) = 0;
15100 /* Get bit offset of field. */
15101 if (handle_data_member_location (die
, cu
, &offset
))
15102 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15103 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15106 if (gdbarch_bits_big_endian (gdbarch
))
15108 /* For big endian bits, the DW_AT_bit_offset gives the
15109 additional bit offset from the MSB of the containing
15110 anonymous object to the MSB of the field. We don't
15111 have to do anything special since we don't need to
15112 know the size of the anonymous object. */
15113 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15117 /* For little endian bits, compute the bit offset to the
15118 MSB of the anonymous object, subtract off the number of
15119 bits from the MSB of the field to the MSB of the
15120 object, and then subtract off the number of bits of
15121 the field itself. The result is the bit offset of
15122 the LSB of the field. */
15123 int anonymous_size
;
15124 int bit_offset
= DW_UNSND (attr
);
15126 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15129 /* The size of the anonymous object containing
15130 the bit field is explicit, so use the
15131 indicated size (in bytes). */
15132 anonymous_size
= DW_UNSND (attr
);
15136 /* The size of the anonymous object containing
15137 the bit field must be inferred from the type
15138 attribute of the data member containing the
15140 anonymous_size
= TYPE_LENGTH (fp
->type
);
15142 SET_FIELD_BITPOS (*fp
,
15143 (FIELD_BITPOS (*fp
)
15144 + anonymous_size
* bits_per_byte
15145 - bit_offset
- FIELD_BITSIZE (*fp
)));
15148 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15150 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15151 + dwarf2_get_attr_constant_value (attr
, 0)));
15153 /* Get name of field. */
15154 fieldname
= dwarf2_name (die
, cu
);
15155 if (fieldname
== NULL
)
15158 /* The name is already allocated along with this objfile, so we don't
15159 need to duplicate it for the type. */
15160 fp
->name
= fieldname
;
15162 /* Change accessibility for artificial fields (e.g. virtual table
15163 pointer or virtual base class pointer) to private. */
15164 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15166 FIELD_ARTIFICIAL (*fp
) = 1;
15167 new_field
->accessibility
= DW_ACCESS_private
;
15168 fip
->non_public_fields
= 1;
15171 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15173 /* C++ static member. */
15175 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15176 is a declaration, but all versions of G++ as of this writing
15177 (so through at least 3.2.1) incorrectly generate
15178 DW_TAG_variable tags. */
15180 const char *physname
;
15182 /* Get name of field. */
15183 fieldname
= dwarf2_name (die
, cu
);
15184 if (fieldname
== NULL
)
15187 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15189 /* Only create a symbol if this is an external value.
15190 new_symbol checks this and puts the value in the global symbol
15191 table, which we want. If it is not external, new_symbol
15192 will try to put the value in cu->list_in_scope which is wrong. */
15193 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15195 /* A static const member, not much different than an enum as far as
15196 we're concerned, except that we can support more types. */
15197 new_symbol (die
, NULL
, cu
);
15200 /* Get physical name. */
15201 physname
= dwarf2_physname (fieldname
, die
, cu
);
15203 /* The name is already allocated along with this objfile, so we don't
15204 need to duplicate it for the type. */
15205 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15206 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15207 FIELD_NAME (*fp
) = fieldname
;
15209 else if (die
->tag
== DW_TAG_inheritance
)
15213 /* C++ base class field. */
15214 if (handle_data_member_location (die
, cu
, &offset
))
15215 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15216 FIELD_BITSIZE (*fp
) = 0;
15217 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15218 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
15220 else if (die
->tag
== DW_TAG_variant_part
)
15222 /* process_structure_scope will treat this DIE as a union. */
15223 process_structure_scope (die
, cu
);
15225 /* The variant part is relative to the start of the enclosing
15227 SET_FIELD_BITPOS (*fp
, 0);
15228 fp
->type
= get_die_type (die
, cu
);
15229 fp
->artificial
= 1;
15230 fp
->name
= "<<variant>>";
15233 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15236 /* Can the type given by DIE define another type? */
15239 type_can_define_types (const struct die_info
*die
)
15243 case DW_TAG_typedef
:
15244 case DW_TAG_class_type
:
15245 case DW_TAG_structure_type
:
15246 case DW_TAG_union_type
:
15247 case DW_TAG_enumeration_type
:
15255 /* Add a type definition defined in the scope of the FIP's class. */
15258 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15259 struct dwarf2_cu
*cu
)
15261 struct decl_field fp
;
15262 memset (&fp
, 0, sizeof (fp
));
15264 gdb_assert (type_can_define_types (die
));
15266 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15267 fp
.name
= dwarf2_name (die
, cu
);
15268 fp
.type
= read_type_die (die
, cu
);
15270 /* Save accessibility. */
15271 enum dwarf_access_attribute accessibility
;
15272 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15274 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15276 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15277 switch (accessibility
)
15279 case DW_ACCESS_public
:
15280 /* The assumed value if neither private nor protected. */
15282 case DW_ACCESS_private
:
15285 case DW_ACCESS_protected
:
15286 fp
.is_protected
= 1;
15289 complaint (&symfile_complaints
,
15290 _("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15293 if (die
->tag
== DW_TAG_typedef
)
15294 fip
->typedef_field_list
.push_back (fp
);
15296 fip
->nested_types_list
.push_back (fp
);
15299 /* Create the vector of fields, and attach it to the type. */
15302 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15303 struct dwarf2_cu
*cu
)
15305 int nfields
= fip
->nfields
;
15307 /* Record the field count, allocate space for the array of fields,
15308 and create blank accessibility bitfields if necessary. */
15309 TYPE_NFIELDS (type
) = nfields
;
15310 TYPE_FIELDS (type
) = (struct field
*)
15311 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15313 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15315 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15317 TYPE_FIELD_PRIVATE_BITS (type
) =
15318 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15319 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15321 TYPE_FIELD_PROTECTED_BITS (type
) =
15322 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15323 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15325 TYPE_FIELD_IGNORE_BITS (type
) =
15326 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15327 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15330 /* If the type has baseclasses, allocate and clear a bit vector for
15331 TYPE_FIELD_VIRTUAL_BITS. */
15332 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15334 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15335 unsigned char *pointer
;
15337 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15338 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15339 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15340 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15341 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15344 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15346 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15348 for (int index
= 0; index
< nfields
; ++index
)
15350 struct nextfield
&field
= fip
->fields
[index
];
15352 if (field
.variant
.is_discriminant
)
15353 di
->discriminant_index
= index
;
15354 else if (field
.variant
.default_branch
)
15355 di
->default_index
= index
;
15357 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15361 /* Copy the saved-up fields into the field vector. */
15362 for (int i
= 0; i
< nfields
; ++i
)
15364 struct nextfield
&field
15365 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15366 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15368 TYPE_FIELD (type
, i
) = field
.field
;
15369 switch (field
.accessibility
)
15371 case DW_ACCESS_private
:
15372 if (cu
->language
!= language_ada
)
15373 SET_TYPE_FIELD_PRIVATE (type
, i
);
15376 case DW_ACCESS_protected
:
15377 if (cu
->language
!= language_ada
)
15378 SET_TYPE_FIELD_PROTECTED (type
, i
);
15381 case DW_ACCESS_public
:
15385 /* Unknown accessibility. Complain and treat it as public. */
15387 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
15388 field
.accessibility
);
15392 if (i
< fip
->baseclasses
.size ())
15394 switch (field
.virtuality
)
15396 case DW_VIRTUALITY_virtual
:
15397 case DW_VIRTUALITY_pure_virtual
:
15398 if (cu
->language
== language_ada
)
15399 error (_("unexpected virtuality in component of Ada type"));
15400 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15407 /* Return true if this member function is a constructor, false
15411 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15413 const char *fieldname
;
15414 const char *type_name
;
15417 if (die
->parent
== NULL
)
15420 if (die
->parent
->tag
!= DW_TAG_structure_type
15421 && die
->parent
->tag
!= DW_TAG_union_type
15422 && die
->parent
->tag
!= DW_TAG_class_type
)
15425 fieldname
= dwarf2_name (die
, cu
);
15426 type_name
= dwarf2_name (die
->parent
, cu
);
15427 if (fieldname
== NULL
|| type_name
== NULL
)
15430 len
= strlen (fieldname
);
15431 return (strncmp (fieldname
, type_name
, len
) == 0
15432 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15435 /* Add a member function to the proper fieldlist. */
15438 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15439 struct type
*type
, struct dwarf2_cu
*cu
)
15441 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15442 struct attribute
*attr
;
15444 struct fnfieldlist
*flp
= nullptr;
15445 struct fn_field
*fnp
;
15446 const char *fieldname
;
15447 struct type
*this_type
;
15448 enum dwarf_access_attribute accessibility
;
15450 if (cu
->language
== language_ada
)
15451 error (_("unexpected member function in Ada type"));
15453 /* Get name of member function. */
15454 fieldname
= dwarf2_name (die
, cu
);
15455 if (fieldname
== NULL
)
15458 /* Look up member function name in fieldlist. */
15459 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15461 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15463 flp
= &fip
->fnfieldlists
[i
];
15468 /* Create a new fnfieldlist if necessary. */
15469 if (flp
== nullptr)
15471 fip
->fnfieldlists
.emplace_back ();
15472 flp
= &fip
->fnfieldlists
.back ();
15473 flp
->name
= fieldname
;
15474 i
= fip
->fnfieldlists
.size () - 1;
15477 /* Create a new member function field and add it to the vector of
15479 flp
->fnfields
.emplace_back ();
15480 fnp
= &flp
->fnfields
.back ();
15482 /* Delay processing of the physname until later. */
15483 if (cu
->language
== language_cplus
)
15484 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15488 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15489 fnp
->physname
= physname
? physname
: "";
15492 fnp
->type
= alloc_type (objfile
);
15493 this_type
= read_type_die (die
, cu
);
15494 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15496 int nparams
= TYPE_NFIELDS (this_type
);
15498 /* TYPE is the domain of this method, and THIS_TYPE is the type
15499 of the method itself (TYPE_CODE_METHOD). */
15500 smash_to_method_type (fnp
->type
, type
,
15501 TYPE_TARGET_TYPE (this_type
),
15502 TYPE_FIELDS (this_type
),
15503 TYPE_NFIELDS (this_type
),
15504 TYPE_VARARGS (this_type
));
15506 /* Handle static member functions.
15507 Dwarf2 has no clean way to discern C++ static and non-static
15508 member functions. G++ helps GDB by marking the first
15509 parameter for non-static member functions (which is the this
15510 pointer) as artificial. We obtain this information from
15511 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15512 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15513 fnp
->voffset
= VOFFSET_STATIC
;
15516 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
15517 dwarf2_full_name (fieldname
, die
, cu
));
15519 /* Get fcontext from DW_AT_containing_type if present. */
15520 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15521 fnp
->fcontext
= die_containing_type (die
, cu
);
15523 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15524 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15526 /* Get accessibility. */
15527 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15529 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15531 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15532 switch (accessibility
)
15534 case DW_ACCESS_private
:
15535 fnp
->is_private
= 1;
15537 case DW_ACCESS_protected
:
15538 fnp
->is_protected
= 1;
15542 /* Check for artificial methods. */
15543 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15544 if (attr
&& DW_UNSND (attr
) != 0)
15545 fnp
->is_artificial
= 1;
15547 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15549 /* Get index in virtual function table if it is a virtual member
15550 function. For older versions of GCC, this is an offset in the
15551 appropriate virtual table, as specified by DW_AT_containing_type.
15552 For everyone else, it is an expression to be evaluated relative
15553 to the object address. */
15555 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15558 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15560 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15562 /* Old-style GCC. */
15563 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15565 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15566 || (DW_BLOCK (attr
)->size
> 1
15567 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15568 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15570 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15571 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15572 dwarf2_complex_location_expr_complaint ();
15574 fnp
->voffset
/= cu
->header
.addr_size
;
15578 dwarf2_complex_location_expr_complaint ();
15580 if (!fnp
->fcontext
)
15582 /* If there is no `this' field and no DW_AT_containing_type,
15583 we cannot actually find a base class context for the
15585 if (TYPE_NFIELDS (this_type
) == 0
15586 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15588 complaint (&symfile_complaints
,
15589 _("cannot determine context for virtual member "
15590 "function \"%s\" (offset %s)"),
15591 fieldname
, sect_offset_str (die
->sect_off
));
15596 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15600 else if (attr_form_is_section_offset (attr
))
15602 dwarf2_complex_location_expr_complaint ();
15606 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15612 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15613 if (attr
&& DW_UNSND (attr
))
15615 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15616 complaint (&symfile_complaints
,
15617 _("Member function \"%s\" (offset %s) is virtual "
15618 "but the vtable offset is not specified"),
15619 fieldname
, sect_offset_str (die
->sect_off
));
15620 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15621 TYPE_CPLUS_DYNAMIC (type
) = 1;
15626 /* Create the vector of member function fields, and attach it to the type. */
15629 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15630 struct dwarf2_cu
*cu
)
15632 if (cu
->language
== language_ada
)
15633 error (_("unexpected member functions in Ada type"));
15635 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15636 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15638 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15640 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15642 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15643 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15645 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15646 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15647 fn_flp
->fn_fields
= (struct fn_field
*)
15648 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15650 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15651 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15654 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15657 /* Returns non-zero if NAME is the name of a vtable member in CU's
15658 language, zero otherwise. */
15660 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15662 static const char vptr
[] = "_vptr";
15664 /* Look for the C++ form of the vtable. */
15665 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15671 /* GCC outputs unnamed structures that are really pointers to member
15672 functions, with the ABI-specified layout. If TYPE describes
15673 such a structure, smash it into a member function type.
15675 GCC shouldn't do this; it should just output pointer to member DIEs.
15676 This is GCC PR debug/28767. */
15679 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15681 struct type
*pfn_type
, *self_type
, *new_type
;
15683 /* Check for a structure with no name and two children. */
15684 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15687 /* Check for __pfn and __delta members. */
15688 if (TYPE_FIELD_NAME (type
, 0) == NULL
15689 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15690 || TYPE_FIELD_NAME (type
, 1) == NULL
15691 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15694 /* Find the type of the method. */
15695 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15696 if (pfn_type
== NULL
15697 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15698 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15701 /* Look for the "this" argument. */
15702 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15703 if (TYPE_NFIELDS (pfn_type
) == 0
15704 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15705 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15708 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15709 new_type
= alloc_type (objfile
);
15710 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15711 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15712 TYPE_VARARGS (pfn_type
));
15713 smash_to_methodptr_type (type
, new_type
);
15717 /* Called when we find the DIE that starts a structure or union scope
15718 (definition) to create a type for the structure or union. Fill in
15719 the type's name and general properties; the members will not be
15720 processed until process_structure_scope. A symbol table entry for
15721 the type will also not be done until process_structure_scope (assuming
15722 the type has a name).
15724 NOTE: we need to call these functions regardless of whether or not the
15725 DIE has a DW_AT_name attribute, since it might be an anonymous
15726 structure or union. This gets the type entered into our set of
15727 user defined types. */
15729 static struct type
*
15730 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15732 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15734 struct attribute
*attr
;
15737 /* If the definition of this type lives in .debug_types, read that type.
15738 Don't follow DW_AT_specification though, that will take us back up
15739 the chain and we want to go down. */
15740 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15743 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15745 /* The type's CU may not be the same as CU.
15746 Ensure TYPE is recorded with CU in die_type_hash. */
15747 return set_die_type (die
, type
, cu
);
15750 type
= alloc_type (objfile
);
15751 INIT_CPLUS_SPECIFIC (type
);
15753 name
= dwarf2_name (die
, cu
);
15756 if (cu
->language
== language_cplus
15757 || cu
->language
== language_d
15758 || cu
->language
== language_rust
)
15760 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15762 /* dwarf2_full_name might have already finished building the DIE's
15763 type. If so, there is no need to continue. */
15764 if (get_die_type (die
, cu
) != NULL
)
15765 return get_die_type (die
, cu
);
15767 TYPE_TAG_NAME (type
) = full_name
;
15768 if (die
->tag
== DW_TAG_structure_type
15769 || die
->tag
== DW_TAG_class_type
)
15770 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15774 /* The name is already allocated along with this objfile, so
15775 we don't need to duplicate it for the type. */
15776 TYPE_TAG_NAME (type
) = name
;
15777 if (die
->tag
== DW_TAG_class_type
)
15778 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15782 if (die
->tag
== DW_TAG_structure_type
)
15784 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15786 else if (die
->tag
== DW_TAG_union_type
)
15788 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15790 else if (die
->tag
== DW_TAG_variant_part
)
15792 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15793 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15797 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15800 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15801 TYPE_DECLARED_CLASS (type
) = 1;
15803 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15806 if (attr_form_is_constant (attr
))
15807 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15810 /* For the moment, dynamic type sizes are not supported
15811 by GDB's struct type. The actual size is determined
15812 on-demand when resolving the type of a given object,
15813 so set the type's length to zero for now. Otherwise,
15814 we record an expression as the length, and that expression
15815 could lead to a very large value, which could eventually
15816 lead to us trying to allocate that much memory when creating
15817 a value of that type. */
15818 TYPE_LENGTH (type
) = 0;
15823 TYPE_LENGTH (type
) = 0;
15826 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15828 /* ICC<14 does not output the required DW_AT_declaration on
15829 incomplete types, but gives them a size of zero. */
15830 TYPE_STUB (type
) = 1;
15833 TYPE_STUB_SUPPORTED (type
) = 1;
15835 if (die_is_declaration (die
, cu
))
15836 TYPE_STUB (type
) = 1;
15837 else if (attr
== NULL
&& die
->child
== NULL
15838 && producer_is_realview (cu
->producer
))
15839 /* RealView does not output the required DW_AT_declaration
15840 on incomplete types. */
15841 TYPE_STUB (type
) = 1;
15843 /* We need to add the type field to the die immediately so we don't
15844 infinitely recurse when dealing with pointers to the structure
15845 type within the structure itself. */
15846 set_die_type (die
, type
, cu
);
15848 /* set_die_type should be already done. */
15849 set_descriptive_type (type
, die
, cu
);
15854 /* A helper for process_structure_scope that handles a single member
15858 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15859 struct field_info
*fi
,
15860 std::vector
<struct symbol
*> *template_args
,
15861 struct dwarf2_cu
*cu
)
15863 if (child_die
->tag
== DW_TAG_member
15864 || child_die
->tag
== DW_TAG_variable
15865 || child_die
->tag
== DW_TAG_variant_part
)
15867 /* NOTE: carlton/2002-11-05: A C++ static data member
15868 should be a DW_TAG_member that is a declaration, but
15869 all versions of G++ as of this writing (so through at
15870 least 3.2.1) incorrectly generate DW_TAG_variable
15871 tags for them instead. */
15872 dwarf2_add_field (fi
, child_die
, cu
);
15874 else if (child_die
->tag
== DW_TAG_subprogram
)
15876 /* Rust doesn't have member functions in the C++ sense.
15877 However, it does emit ordinary functions as children
15878 of a struct DIE. */
15879 if (cu
->language
== language_rust
)
15880 read_func_scope (child_die
, cu
);
15883 /* C++ member function. */
15884 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15887 else if (child_die
->tag
== DW_TAG_inheritance
)
15889 /* C++ base class field. */
15890 dwarf2_add_field (fi
, child_die
, cu
);
15892 else if (type_can_define_types (child_die
))
15893 dwarf2_add_type_defn (fi
, child_die
, cu
);
15894 else if (child_die
->tag
== DW_TAG_template_type_param
15895 || child_die
->tag
== DW_TAG_template_value_param
)
15897 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15900 template_args
->push_back (arg
);
15902 else if (child_die
->tag
== DW_TAG_variant
)
15904 /* In a variant we want to get the discriminant and also add a
15905 field for our sole member child. */
15906 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15908 for (struct die_info
*variant_child
= child_die
->child
;
15909 variant_child
!= NULL
;
15910 variant_child
= sibling_die (variant_child
))
15912 if (variant_child
->tag
== DW_TAG_member
)
15914 handle_struct_member_die (variant_child
, type
, fi
,
15915 template_args
, cu
);
15916 /* Only handle the one. */
15921 /* We don't handle this but we might as well report it if we see
15923 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15924 complaint (&symfile_complaints
,
15925 _("DW_AT_discr_list is not supported yet"
15926 " - DIE at %s [in module %s]"),
15927 sect_offset_str (child_die
->sect_off
),
15928 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15930 /* The first field was just added, so we can stash the
15931 discriminant there. */
15932 gdb_assert (!fi
->fields
.empty ());
15934 fi
->fields
.back ().variant
.default_branch
= true;
15936 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15940 /* Finish creating a structure or union type, including filling in
15941 its members and creating a symbol for it. */
15944 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15946 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15947 struct die_info
*child_die
;
15950 type
= get_die_type (die
, cu
);
15952 type
= read_structure_type (die
, cu
);
15954 /* When reading a DW_TAG_variant_part, we need to notice when we
15955 read the discriminant member, so we can record it later in the
15956 discriminant_info. */
15957 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15958 sect_offset discr_offset
;
15960 if (is_variant_part
)
15962 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15965 /* Maybe it's a univariant form, an extension we support.
15966 In this case arrange not to check the offset. */
15967 is_variant_part
= false;
15969 else if (attr_form_is_ref (discr
))
15971 struct dwarf2_cu
*target_cu
= cu
;
15972 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15974 discr_offset
= target_die
->sect_off
;
15978 complaint (&symfile_complaints
,
15979 _("DW_AT_discr does not have DIE reference form"
15980 " - DIE at %s [in module %s]"),
15981 sect_offset_str (die
->sect_off
),
15982 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15983 is_variant_part
= false;
15987 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15989 struct field_info fi
;
15990 std::vector
<struct symbol
*> template_args
;
15992 child_die
= die
->child
;
15994 while (child_die
&& child_die
->tag
)
15996 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15998 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15999 fi
.fields
.back ().variant
.is_discriminant
= true;
16001 child_die
= sibling_die (child_die
);
16004 /* Attach template arguments to type. */
16005 if (!template_args
.empty ())
16007 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16008 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16009 TYPE_TEMPLATE_ARGUMENTS (type
)
16010 = XOBNEWVEC (&objfile
->objfile_obstack
,
16012 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16013 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16014 template_args
.data (),
16015 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16016 * sizeof (struct symbol
*)));
16019 /* Attach fields and member functions to the type. */
16021 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16022 if (!fi
.fnfieldlists
.empty ())
16024 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16026 /* Get the type which refers to the base class (possibly this
16027 class itself) which contains the vtable pointer for the current
16028 class from the DW_AT_containing_type attribute. This use of
16029 DW_AT_containing_type is a GNU extension. */
16031 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16033 struct type
*t
= die_containing_type (die
, cu
);
16035 set_type_vptr_basetype (type
, t
);
16040 /* Our own class provides vtbl ptr. */
16041 for (i
= TYPE_NFIELDS (t
) - 1;
16042 i
>= TYPE_N_BASECLASSES (t
);
16045 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16047 if (is_vtable_name (fieldname
, cu
))
16049 set_type_vptr_fieldno (type
, i
);
16054 /* Complain if virtual function table field not found. */
16055 if (i
< TYPE_N_BASECLASSES (t
))
16056 complaint (&symfile_complaints
,
16057 _("virtual function table pointer "
16058 "not found when defining class '%s'"),
16059 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
16064 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16067 else if (cu
->producer
16068 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16070 /* The IBM XLC compiler does not provide direct indication
16071 of the containing type, but the vtable pointer is
16072 always named __vfp. */
16076 for (i
= TYPE_NFIELDS (type
) - 1;
16077 i
>= TYPE_N_BASECLASSES (type
);
16080 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16082 set_type_vptr_fieldno (type
, i
);
16083 set_type_vptr_basetype (type
, type
);
16090 /* Copy fi.typedef_field_list linked list elements content into the
16091 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16092 if (!fi
.typedef_field_list
.empty ())
16094 int count
= fi
.typedef_field_list
.size ();
16096 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16097 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16098 = ((struct decl_field
*)
16100 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16101 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16103 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16104 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16107 /* Copy fi.nested_types_list linked list elements content into the
16108 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16109 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16111 int count
= fi
.nested_types_list
.size ();
16113 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16114 TYPE_NESTED_TYPES_ARRAY (type
)
16115 = ((struct decl_field
*)
16116 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16117 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16119 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16120 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16124 quirk_gcc_member_function_pointer (type
, objfile
);
16125 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16126 cu
->rust_unions
.push_back (type
);
16128 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16129 snapshots) has been known to create a die giving a declaration
16130 for a class that has, as a child, a die giving a definition for a
16131 nested class. So we have to process our children even if the
16132 current die is a declaration. Normally, of course, a declaration
16133 won't have any children at all. */
16135 child_die
= die
->child
;
16137 while (child_die
!= NULL
&& child_die
->tag
)
16139 if (child_die
->tag
== DW_TAG_member
16140 || child_die
->tag
== DW_TAG_variable
16141 || child_die
->tag
== DW_TAG_inheritance
16142 || child_die
->tag
== DW_TAG_template_value_param
16143 || child_die
->tag
== DW_TAG_template_type_param
)
16148 process_die (child_die
, cu
);
16150 child_die
= sibling_die (child_die
);
16153 /* Do not consider external references. According to the DWARF standard,
16154 these DIEs are identified by the fact that they have no byte_size
16155 attribute, and a declaration attribute. */
16156 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16157 || !die_is_declaration (die
, cu
))
16158 new_symbol (die
, type
, cu
);
16161 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16162 update TYPE using some information only available in DIE's children. */
16165 update_enumeration_type_from_children (struct die_info
*die
,
16167 struct dwarf2_cu
*cu
)
16169 struct die_info
*child_die
;
16170 int unsigned_enum
= 1;
16174 auto_obstack obstack
;
16176 for (child_die
= die
->child
;
16177 child_die
!= NULL
&& child_die
->tag
;
16178 child_die
= sibling_die (child_die
))
16180 struct attribute
*attr
;
16182 const gdb_byte
*bytes
;
16183 struct dwarf2_locexpr_baton
*baton
;
16186 if (child_die
->tag
!= DW_TAG_enumerator
)
16189 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16193 name
= dwarf2_name (child_die
, cu
);
16195 name
= "<anonymous enumerator>";
16197 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16198 &value
, &bytes
, &baton
);
16204 else if ((mask
& value
) != 0)
16209 /* If we already know that the enum type is neither unsigned, nor
16210 a flag type, no need to look at the rest of the enumerates. */
16211 if (!unsigned_enum
&& !flag_enum
)
16216 TYPE_UNSIGNED (type
) = 1;
16218 TYPE_FLAG_ENUM (type
) = 1;
16221 /* Given a DW_AT_enumeration_type die, set its type. We do not
16222 complete the type's fields yet, or create any symbols. */
16224 static struct type
*
16225 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16227 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16229 struct attribute
*attr
;
16232 /* If the definition of this type lives in .debug_types, read that type.
16233 Don't follow DW_AT_specification though, that will take us back up
16234 the chain and we want to go down. */
16235 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16238 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16240 /* The type's CU may not be the same as CU.
16241 Ensure TYPE is recorded with CU in die_type_hash. */
16242 return set_die_type (die
, type
, cu
);
16245 type
= alloc_type (objfile
);
16247 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16248 name
= dwarf2_full_name (NULL
, die
, cu
);
16250 TYPE_TAG_NAME (type
) = name
;
16252 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16255 struct type
*underlying_type
= die_type (die
, cu
);
16257 TYPE_TARGET_TYPE (type
) = underlying_type
;
16260 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16263 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16267 TYPE_LENGTH (type
) = 0;
16270 /* The enumeration DIE can be incomplete. In Ada, any type can be
16271 declared as private in the package spec, and then defined only
16272 inside the package body. Such types are known as Taft Amendment
16273 Types. When another package uses such a type, an incomplete DIE
16274 may be generated by the compiler. */
16275 if (die_is_declaration (die
, cu
))
16276 TYPE_STUB (type
) = 1;
16278 /* Finish the creation of this type by using the enum's children.
16279 We must call this even when the underlying type has been provided
16280 so that we can determine if we're looking at a "flag" enum. */
16281 update_enumeration_type_from_children (die
, type
, cu
);
16283 /* If this type has an underlying type that is not a stub, then we
16284 may use its attributes. We always use the "unsigned" attribute
16285 in this situation, because ordinarily we guess whether the type
16286 is unsigned -- but the guess can be wrong and the underlying type
16287 can tell us the reality. However, we defer to a local size
16288 attribute if one exists, because this lets the compiler override
16289 the underlying type if needed. */
16290 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16292 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16293 if (TYPE_LENGTH (type
) == 0)
16294 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16297 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16299 return set_die_type (die
, type
, cu
);
16302 /* Given a pointer to a die which begins an enumeration, process all
16303 the dies that define the members of the enumeration, and create the
16304 symbol for the enumeration type.
16306 NOTE: We reverse the order of the element list. */
16309 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16311 struct type
*this_type
;
16313 this_type
= get_die_type (die
, cu
);
16314 if (this_type
== NULL
)
16315 this_type
= read_enumeration_type (die
, cu
);
16317 if (die
->child
!= NULL
)
16319 struct die_info
*child_die
;
16320 struct symbol
*sym
;
16321 struct field
*fields
= NULL
;
16322 int num_fields
= 0;
16325 child_die
= die
->child
;
16326 while (child_die
&& child_die
->tag
)
16328 if (child_die
->tag
!= DW_TAG_enumerator
)
16330 process_die (child_die
, cu
);
16334 name
= dwarf2_name (child_die
, cu
);
16337 sym
= new_symbol (child_die
, this_type
, cu
);
16339 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16341 fields
= (struct field
*)
16343 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16344 * sizeof (struct field
));
16347 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16348 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16349 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16350 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16356 child_die
= sibling_die (child_die
);
16361 TYPE_NFIELDS (this_type
) = num_fields
;
16362 TYPE_FIELDS (this_type
) = (struct field
*)
16363 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16364 memcpy (TYPE_FIELDS (this_type
), fields
,
16365 sizeof (struct field
) * num_fields
);
16370 /* If we are reading an enum from a .debug_types unit, and the enum
16371 is a declaration, and the enum is not the signatured type in the
16372 unit, then we do not want to add a symbol for it. Adding a
16373 symbol would in some cases obscure the true definition of the
16374 enum, giving users an incomplete type when the definition is
16375 actually available. Note that we do not want to do this for all
16376 enums which are just declarations, because C++0x allows forward
16377 enum declarations. */
16378 if (cu
->per_cu
->is_debug_types
16379 && die_is_declaration (die
, cu
))
16381 struct signatured_type
*sig_type
;
16383 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16384 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16385 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16389 new_symbol (die
, this_type
, cu
);
16392 /* Extract all information from a DW_TAG_array_type DIE and put it in
16393 the DIE's type field. For now, this only handles one dimensional
16396 static struct type
*
16397 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16399 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16400 struct die_info
*child_die
;
16402 struct type
*element_type
, *range_type
, *index_type
;
16403 struct attribute
*attr
;
16405 struct dynamic_prop
*byte_stride_prop
= NULL
;
16406 unsigned int bit_stride
= 0;
16408 element_type
= die_type (die
, cu
);
16410 /* The die_type call above may have already set the type for this DIE. */
16411 type
= get_die_type (die
, cu
);
16415 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16421 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16422 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
);
16425 complaint (&symfile_complaints
,
16426 _("unable to read array DW_AT_byte_stride "
16427 " - DIE at %s [in module %s]"),
16428 sect_offset_str (die
->sect_off
),
16429 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16430 /* Ignore this attribute. We will likely not be able to print
16431 arrays of this type correctly, but there is little we can do
16432 to help if we cannot read the attribute's value. */
16433 byte_stride_prop
= NULL
;
16437 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16439 bit_stride
= DW_UNSND (attr
);
16441 /* Irix 6.2 native cc creates array types without children for
16442 arrays with unspecified length. */
16443 if (die
->child
== NULL
)
16445 index_type
= objfile_type (objfile
)->builtin_int
;
16446 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16447 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16448 byte_stride_prop
, bit_stride
);
16449 return set_die_type (die
, type
, cu
);
16452 std::vector
<struct type
*> range_types
;
16453 child_die
= die
->child
;
16454 while (child_die
&& child_die
->tag
)
16456 if (child_die
->tag
== DW_TAG_subrange_type
)
16458 struct type
*child_type
= read_type_die (child_die
, cu
);
16460 if (child_type
!= NULL
)
16462 /* The range type was succesfully read. Save it for the
16463 array type creation. */
16464 range_types
.push_back (child_type
);
16467 child_die
= sibling_die (child_die
);
16470 /* Dwarf2 dimensions are output from left to right, create the
16471 necessary array types in backwards order. */
16473 type
= element_type
;
16475 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16479 while (i
< range_types
.size ())
16480 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16481 byte_stride_prop
, bit_stride
);
16485 size_t ndim
= range_types
.size ();
16487 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16488 byte_stride_prop
, bit_stride
);
16491 /* Understand Dwarf2 support for vector types (like they occur on
16492 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16493 array type. This is not part of the Dwarf2/3 standard yet, but a
16494 custom vendor extension. The main difference between a regular
16495 array and the vector variant is that vectors are passed by value
16497 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16499 make_vector_type (type
);
16501 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16502 implementation may choose to implement triple vectors using this
16504 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16507 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16508 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16510 complaint (&symfile_complaints
,
16511 _("DW_AT_byte_size for array type smaller "
16512 "than the total size of elements"));
16515 name
= dwarf2_name (die
, cu
);
16517 TYPE_NAME (type
) = name
;
16519 /* Install the type in the die. */
16520 set_die_type (die
, type
, cu
);
16522 /* set_die_type should be already done. */
16523 set_descriptive_type (type
, die
, cu
);
16528 static enum dwarf_array_dim_ordering
16529 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16531 struct attribute
*attr
;
16533 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16536 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16538 /* GNU F77 is a special case, as at 08/2004 array type info is the
16539 opposite order to the dwarf2 specification, but data is still
16540 laid out as per normal fortran.
16542 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16543 version checking. */
16545 if (cu
->language
== language_fortran
16546 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16548 return DW_ORD_row_major
;
16551 switch (cu
->language_defn
->la_array_ordering
)
16553 case array_column_major
:
16554 return DW_ORD_col_major
;
16555 case array_row_major
:
16557 return DW_ORD_row_major
;
16561 /* Extract all information from a DW_TAG_set_type DIE and put it in
16562 the DIE's type field. */
16564 static struct type
*
16565 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16567 struct type
*domain_type
, *set_type
;
16568 struct attribute
*attr
;
16570 domain_type
= die_type (die
, cu
);
16572 /* The die_type call above may have already set the type for this DIE. */
16573 set_type
= get_die_type (die
, cu
);
16577 set_type
= create_set_type (NULL
, domain_type
);
16579 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16581 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16583 return set_die_type (die
, set_type
, cu
);
16586 /* A helper for read_common_block that creates a locexpr baton.
16587 SYM is the symbol which we are marking as computed.
16588 COMMON_DIE is the DIE for the common block.
16589 COMMON_LOC is the location expression attribute for the common
16591 MEMBER_LOC is the location expression attribute for the particular
16592 member of the common block that we are processing.
16593 CU is the CU from which the above come. */
16596 mark_common_block_symbol_computed (struct symbol
*sym
,
16597 struct die_info
*common_die
,
16598 struct attribute
*common_loc
,
16599 struct attribute
*member_loc
,
16600 struct dwarf2_cu
*cu
)
16602 struct dwarf2_per_objfile
*dwarf2_per_objfile
16603 = cu
->per_cu
->dwarf2_per_objfile
;
16604 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16605 struct dwarf2_locexpr_baton
*baton
;
16607 unsigned int cu_off
;
16608 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16609 LONGEST offset
= 0;
16611 gdb_assert (common_loc
&& member_loc
);
16612 gdb_assert (attr_form_is_block (common_loc
));
16613 gdb_assert (attr_form_is_block (member_loc
)
16614 || attr_form_is_constant (member_loc
));
16616 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16617 baton
->per_cu
= cu
->per_cu
;
16618 gdb_assert (baton
->per_cu
);
16620 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16622 if (attr_form_is_constant (member_loc
))
16624 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16625 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16628 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16630 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16633 *ptr
++ = DW_OP_call4
;
16634 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16635 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16638 if (attr_form_is_constant (member_loc
))
16640 *ptr
++ = DW_OP_addr
;
16641 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16642 ptr
+= cu
->header
.addr_size
;
16646 /* We have to copy the data here, because DW_OP_call4 will only
16647 use a DW_AT_location attribute. */
16648 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16649 ptr
+= DW_BLOCK (member_loc
)->size
;
16652 *ptr
++ = DW_OP_plus
;
16653 gdb_assert (ptr
- baton
->data
== baton
->size
);
16655 SYMBOL_LOCATION_BATON (sym
) = baton
;
16656 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16659 /* Create appropriate locally-scoped variables for all the
16660 DW_TAG_common_block entries. Also create a struct common_block
16661 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16662 is used to sepate the common blocks name namespace from regular
16666 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16668 struct attribute
*attr
;
16670 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16673 /* Support the .debug_loc offsets. */
16674 if (attr_form_is_block (attr
))
16678 else if (attr_form_is_section_offset (attr
))
16680 dwarf2_complex_location_expr_complaint ();
16685 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16686 "common block member");
16691 if (die
->child
!= NULL
)
16693 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16694 struct die_info
*child_die
;
16695 size_t n_entries
= 0, size
;
16696 struct common_block
*common_block
;
16697 struct symbol
*sym
;
16699 for (child_die
= die
->child
;
16700 child_die
&& child_die
->tag
;
16701 child_die
= sibling_die (child_die
))
16704 size
= (sizeof (struct common_block
)
16705 + (n_entries
- 1) * sizeof (struct symbol
*));
16707 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16709 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16710 common_block
->n_entries
= 0;
16712 for (child_die
= die
->child
;
16713 child_die
&& child_die
->tag
;
16714 child_die
= sibling_die (child_die
))
16716 /* Create the symbol in the DW_TAG_common_block block in the current
16718 sym
= new_symbol (child_die
, NULL
, cu
);
16721 struct attribute
*member_loc
;
16723 common_block
->contents
[common_block
->n_entries
++] = sym
;
16725 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16729 /* GDB has handled this for a long time, but it is
16730 not specified by DWARF. It seems to have been
16731 emitted by gfortran at least as recently as:
16732 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16733 complaint (&symfile_complaints
,
16734 _("Variable in common block has "
16735 "DW_AT_data_member_location "
16736 "- DIE at %s [in module %s]"),
16737 sect_offset_str (child_die
->sect_off
),
16738 objfile_name (objfile
));
16740 if (attr_form_is_section_offset (member_loc
))
16741 dwarf2_complex_location_expr_complaint ();
16742 else if (attr_form_is_constant (member_loc
)
16743 || attr_form_is_block (member_loc
))
16746 mark_common_block_symbol_computed (sym
, die
, attr
,
16750 dwarf2_complex_location_expr_complaint ();
16755 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16756 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16760 /* Create a type for a C++ namespace. */
16762 static struct type
*
16763 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16765 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16766 const char *previous_prefix
, *name
;
16770 /* For extensions, reuse the type of the original namespace. */
16771 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16773 struct die_info
*ext_die
;
16774 struct dwarf2_cu
*ext_cu
= cu
;
16776 ext_die
= dwarf2_extension (die
, &ext_cu
);
16777 type
= read_type_die (ext_die
, ext_cu
);
16779 /* EXT_CU may not be the same as CU.
16780 Ensure TYPE is recorded with CU in die_type_hash. */
16781 return set_die_type (die
, type
, cu
);
16784 name
= namespace_name (die
, &is_anonymous
, cu
);
16786 /* Now build the name of the current namespace. */
16788 previous_prefix
= determine_prefix (die
, cu
);
16789 if (previous_prefix
[0] != '\0')
16790 name
= typename_concat (&objfile
->objfile_obstack
,
16791 previous_prefix
, name
, 0, cu
);
16793 /* Create the type. */
16794 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16795 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16797 return set_die_type (die
, type
, cu
);
16800 /* Read a namespace scope. */
16803 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16805 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16808 /* Add a symbol associated to this if we haven't seen the namespace
16809 before. Also, add a using directive if it's an anonymous
16812 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16816 type
= read_type_die (die
, cu
);
16817 new_symbol (die
, type
, cu
);
16819 namespace_name (die
, &is_anonymous
, cu
);
16822 const char *previous_prefix
= determine_prefix (die
, cu
);
16824 std::vector
<const char *> excludes
;
16825 add_using_directive (using_directives (cu
->language
),
16826 previous_prefix
, TYPE_NAME (type
), NULL
,
16827 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16831 if (die
->child
!= NULL
)
16833 struct die_info
*child_die
= die
->child
;
16835 while (child_die
&& child_die
->tag
)
16837 process_die (child_die
, cu
);
16838 child_die
= sibling_die (child_die
);
16843 /* Read a Fortran module as type. This DIE can be only a declaration used for
16844 imported module. Still we need that type as local Fortran "use ... only"
16845 declaration imports depend on the created type in determine_prefix. */
16847 static struct type
*
16848 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16850 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16851 const char *module_name
;
16854 module_name
= dwarf2_name (die
, cu
);
16856 complaint (&symfile_complaints
,
16857 _("DW_TAG_module has no name, offset %s"),
16858 sect_offset_str (die
->sect_off
));
16859 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16861 /* determine_prefix uses TYPE_TAG_NAME. */
16862 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16864 return set_die_type (die
, type
, cu
);
16867 /* Read a Fortran module. */
16870 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16872 struct die_info
*child_die
= die
->child
;
16875 type
= read_type_die (die
, cu
);
16876 new_symbol (die
, type
, cu
);
16878 while (child_die
&& child_die
->tag
)
16880 process_die (child_die
, cu
);
16881 child_die
= sibling_die (child_die
);
16885 /* Return the name of the namespace represented by DIE. Set
16886 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16889 static const char *
16890 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16892 struct die_info
*current_die
;
16893 const char *name
= NULL
;
16895 /* Loop through the extensions until we find a name. */
16897 for (current_die
= die
;
16898 current_die
!= NULL
;
16899 current_die
= dwarf2_extension (die
, &cu
))
16901 /* We don't use dwarf2_name here so that we can detect the absence
16902 of a name -> anonymous namespace. */
16903 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16909 /* Is it an anonymous namespace? */
16911 *is_anonymous
= (name
== NULL
);
16913 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16918 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16919 the user defined type vector. */
16921 static struct type
*
16922 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16924 struct gdbarch
*gdbarch
16925 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16926 struct comp_unit_head
*cu_header
= &cu
->header
;
16928 struct attribute
*attr_byte_size
;
16929 struct attribute
*attr_address_class
;
16930 int byte_size
, addr_class
;
16931 struct type
*target_type
;
16933 target_type
= die_type (die
, cu
);
16935 /* The die_type call above may have already set the type for this DIE. */
16936 type
= get_die_type (die
, cu
);
16940 type
= lookup_pointer_type (target_type
);
16942 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16943 if (attr_byte_size
)
16944 byte_size
= DW_UNSND (attr_byte_size
);
16946 byte_size
= cu_header
->addr_size
;
16948 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16949 if (attr_address_class
)
16950 addr_class
= DW_UNSND (attr_address_class
);
16952 addr_class
= DW_ADDR_none
;
16954 /* If the pointer size or address class is different than the
16955 default, create a type variant marked as such and set the
16956 length accordingly. */
16957 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
16959 if (gdbarch_address_class_type_flags_p (gdbarch
))
16963 type_flags
= gdbarch_address_class_type_flags
16964 (gdbarch
, byte_size
, addr_class
);
16965 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16967 type
= make_type_with_address_space (type
, type_flags
);
16969 else if (TYPE_LENGTH (type
) != byte_size
)
16971 complaint (&symfile_complaints
,
16972 _("invalid pointer size %d"), byte_size
);
16976 /* Should we also complain about unhandled address classes? */
16980 TYPE_LENGTH (type
) = byte_size
;
16981 return set_die_type (die
, type
, cu
);
16984 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16985 the user defined type vector. */
16987 static struct type
*
16988 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16991 struct type
*to_type
;
16992 struct type
*domain
;
16994 to_type
= die_type (die
, cu
);
16995 domain
= die_containing_type (die
, cu
);
16997 /* The calls above may have already set the type for this DIE. */
16998 type
= get_die_type (die
, cu
);
17002 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17003 type
= lookup_methodptr_type (to_type
);
17004 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17006 struct type
*new_type
17007 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17009 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17010 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17011 TYPE_VARARGS (to_type
));
17012 type
= lookup_methodptr_type (new_type
);
17015 type
= lookup_memberptr_type (to_type
, domain
);
17017 return set_die_type (die
, type
, cu
);
17020 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17021 the user defined type vector. */
17023 static struct type
*
17024 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17025 enum type_code refcode
)
17027 struct comp_unit_head
*cu_header
= &cu
->header
;
17028 struct type
*type
, *target_type
;
17029 struct attribute
*attr
;
17031 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17033 target_type
= die_type (die
, cu
);
17035 /* The die_type call above may have already set the type for this DIE. */
17036 type
= get_die_type (die
, cu
);
17040 type
= lookup_reference_type (target_type
, refcode
);
17041 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17044 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17048 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17050 return set_die_type (die
, type
, cu
);
17053 /* Add the given cv-qualifiers to the element type of the array. GCC
17054 outputs DWARF type qualifiers that apply to an array, not the
17055 element type. But GDB relies on the array element type to carry
17056 the cv-qualifiers. This mimics section 6.7.3 of the C99
17059 static struct type
*
17060 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17061 struct type
*base_type
, int cnst
, int voltl
)
17063 struct type
*el_type
, *inner_array
;
17065 base_type
= copy_type (base_type
);
17066 inner_array
= base_type
;
17068 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17070 TYPE_TARGET_TYPE (inner_array
) =
17071 copy_type (TYPE_TARGET_TYPE (inner_array
));
17072 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17075 el_type
= TYPE_TARGET_TYPE (inner_array
);
17076 cnst
|= TYPE_CONST (el_type
);
17077 voltl
|= TYPE_VOLATILE (el_type
);
17078 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17080 return set_die_type (die
, base_type
, cu
);
17083 static struct type
*
17084 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17086 struct type
*base_type
, *cv_type
;
17088 base_type
= die_type (die
, cu
);
17090 /* The die_type call above may have already set the type for this DIE. */
17091 cv_type
= get_die_type (die
, cu
);
17095 /* In case the const qualifier is applied to an array type, the element type
17096 is so qualified, not the array type (section 6.7.3 of C99). */
17097 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17098 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17100 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17101 return set_die_type (die
, cv_type
, cu
);
17104 static struct type
*
17105 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17107 struct type
*base_type
, *cv_type
;
17109 base_type
= die_type (die
, cu
);
17111 /* The die_type call above may have already set the type for this DIE. */
17112 cv_type
= get_die_type (die
, cu
);
17116 /* In case the volatile qualifier is applied to an array type, the
17117 element type is so qualified, not the array type (section 6.7.3
17119 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17120 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17122 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17123 return set_die_type (die
, cv_type
, cu
);
17126 /* Handle DW_TAG_restrict_type. */
17128 static struct type
*
17129 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17131 struct type
*base_type
, *cv_type
;
17133 base_type
= die_type (die
, cu
);
17135 /* The die_type call above may have already set the type for this DIE. */
17136 cv_type
= get_die_type (die
, cu
);
17140 cv_type
= make_restrict_type (base_type
);
17141 return set_die_type (die
, cv_type
, cu
);
17144 /* Handle DW_TAG_atomic_type. */
17146 static struct type
*
17147 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17149 struct type
*base_type
, *cv_type
;
17151 base_type
= die_type (die
, cu
);
17153 /* The die_type call above may have already set the type for this DIE. */
17154 cv_type
= get_die_type (die
, cu
);
17158 cv_type
= make_atomic_type (base_type
);
17159 return set_die_type (die
, cv_type
, cu
);
17162 /* Extract all information from a DW_TAG_string_type DIE and add to
17163 the user defined type vector. It isn't really a user defined type,
17164 but it behaves like one, with other DIE's using an AT_user_def_type
17165 attribute to reference it. */
17167 static struct type
*
17168 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17170 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17171 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17172 struct type
*type
, *range_type
, *index_type
, *char_type
;
17173 struct attribute
*attr
;
17174 unsigned int length
;
17176 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17179 length
= DW_UNSND (attr
);
17183 /* Check for the DW_AT_byte_size attribute. */
17184 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17187 length
= DW_UNSND (attr
);
17195 index_type
= objfile_type (objfile
)->builtin_int
;
17196 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17197 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17198 type
= create_string_type (NULL
, char_type
, range_type
);
17200 return set_die_type (die
, type
, cu
);
17203 /* Assuming that DIE corresponds to a function, returns nonzero
17204 if the function is prototyped. */
17207 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17209 struct attribute
*attr
;
17211 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17212 if (attr
&& (DW_UNSND (attr
) != 0))
17215 /* The DWARF standard implies that the DW_AT_prototyped attribute
17216 is only meaninful for C, but the concept also extends to other
17217 languages that allow unprototyped functions (Eg: Objective C).
17218 For all other languages, assume that functions are always
17220 if (cu
->language
!= language_c
17221 && cu
->language
!= language_objc
17222 && cu
->language
!= language_opencl
)
17225 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17226 prototyped and unprototyped functions; default to prototyped,
17227 since that is more common in modern code (and RealView warns
17228 about unprototyped functions). */
17229 if (producer_is_realview (cu
->producer
))
17235 /* Handle DIES due to C code like:
17239 int (*funcp)(int a, long l);
17243 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17245 static struct type
*
17246 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17248 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17249 struct type
*type
; /* Type that this function returns. */
17250 struct type
*ftype
; /* Function that returns above type. */
17251 struct attribute
*attr
;
17253 type
= die_type (die
, cu
);
17255 /* The die_type call above may have already set the type for this DIE. */
17256 ftype
= get_die_type (die
, cu
);
17260 ftype
= lookup_function_type (type
);
17262 if (prototyped_function_p (die
, cu
))
17263 TYPE_PROTOTYPED (ftype
) = 1;
17265 /* Store the calling convention in the type if it's available in
17266 the subroutine die. Otherwise set the calling convention to
17267 the default value DW_CC_normal. */
17268 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17270 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17271 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17272 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17274 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17276 /* Record whether the function returns normally to its caller or not
17277 if the DWARF producer set that information. */
17278 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17279 if (attr
&& (DW_UNSND (attr
) != 0))
17280 TYPE_NO_RETURN (ftype
) = 1;
17282 /* We need to add the subroutine type to the die immediately so
17283 we don't infinitely recurse when dealing with parameters
17284 declared as the same subroutine type. */
17285 set_die_type (die
, ftype
, cu
);
17287 if (die
->child
!= NULL
)
17289 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17290 struct die_info
*child_die
;
17291 int nparams
, iparams
;
17293 /* Count the number of parameters.
17294 FIXME: GDB currently ignores vararg functions, but knows about
17295 vararg member functions. */
17297 child_die
= die
->child
;
17298 while (child_die
&& child_die
->tag
)
17300 if (child_die
->tag
== DW_TAG_formal_parameter
)
17302 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17303 TYPE_VARARGS (ftype
) = 1;
17304 child_die
= sibling_die (child_die
);
17307 /* Allocate storage for parameters and fill them in. */
17308 TYPE_NFIELDS (ftype
) = nparams
;
17309 TYPE_FIELDS (ftype
) = (struct field
*)
17310 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17312 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17313 even if we error out during the parameters reading below. */
17314 for (iparams
= 0; iparams
< nparams
; iparams
++)
17315 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17318 child_die
= die
->child
;
17319 while (child_die
&& child_die
->tag
)
17321 if (child_die
->tag
== DW_TAG_formal_parameter
)
17323 struct type
*arg_type
;
17325 /* DWARF version 2 has no clean way to discern C++
17326 static and non-static member functions. G++ helps
17327 GDB by marking the first parameter for non-static
17328 member functions (which is the this pointer) as
17329 artificial. We pass this information to
17330 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17332 DWARF version 3 added DW_AT_object_pointer, which GCC
17333 4.5 does not yet generate. */
17334 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17336 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17338 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17339 arg_type
= die_type (child_die
, cu
);
17341 /* RealView does not mark THIS as const, which the testsuite
17342 expects. GCC marks THIS as const in method definitions,
17343 but not in the class specifications (GCC PR 43053). */
17344 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17345 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17348 struct dwarf2_cu
*arg_cu
= cu
;
17349 const char *name
= dwarf2_name (child_die
, cu
);
17351 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17354 /* If the compiler emits this, use it. */
17355 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17358 else if (name
&& strcmp (name
, "this") == 0)
17359 /* Function definitions will have the argument names. */
17361 else if (name
== NULL
&& iparams
== 0)
17362 /* Declarations may not have the names, so like
17363 elsewhere in GDB, assume an artificial first
17364 argument is "this". */
17368 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17372 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17375 child_die
= sibling_die (child_die
);
17382 static struct type
*
17383 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17385 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17386 const char *name
= NULL
;
17387 struct type
*this_type
, *target_type
;
17389 name
= dwarf2_full_name (NULL
, die
, cu
);
17390 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17391 TYPE_TARGET_STUB (this_type
) = 1;
17392 set_die_type (die
, this_type
, cu
);
17393 target_type
= die_type (die
, cu
);
17394 if (target_type
!= this_type
)
17395 TYPE_TARGET_TYPE (this_type
) = target_type
;
17398 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17399 spec and cause infinite loops in GDB. */
17400 complaint (&symfile_complaints
,
17401 _("Self-referential DW_TAG_typedef "
17402 "- DIE at %s [in module %s]"),
17403 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17404 TYPE_TARGET_TYPE (this_type
) = NULL
;
17409 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17410 (which may be different from NAME) to the architecture back-end to allow
17411 it to guess the correct format if necessary. */
17413 static struct type
*
17414 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17415 const char *name_hint
)
17417 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17418 const struct floatformat
**format
;
17421 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17423 type
= init_float_type (objfile
, bits
, name
, format
);
17425 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17430 /* Find a representation of a given base type and install
17431 it in the TYPE field of the die. */
17433 static struct type
*
17434 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17436 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17438 struct attribute
*attr
;
17439 int encoding
= 0, bits
= 0;
17442 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17445 encoding
= DW_UNSND (attr
);
17447 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17450 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17452 name
= dwarf2_name (die
, cu
);
17455 complaint (&symfile_complaints
,
17456 _("DW_AT_name missing from DW_TAG_base_type"));
17461 case DW_ATE_address
:
17462 /* Turn DW_ATE_address into a void * pointer. */
17463 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17464 type
= init_pointer_type (objfile
, bits
, name
, type
);
17466 case DW_ATE_boolean
:
17467 type
= init_boolean_type (objfile
, bits
, 1, name
);
17469 case DW_ATE_complex_float
:
17470 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
17471 type
= init_complex_type (objfile
, name
, type
);
17473 case DW_ATE_decimal_float
:
17474 type
= init_decfloat_type (objfile
, bits
, name
);
17477 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17479 case DW_ATE_signed
:
17480 type
= init_integer_type (objfile
, bits
, 0, name
);
17482 case DW_ATE_unsigned
:
17483 if (cu
->language
== language_fortran
17485 && startswith (name
, "character("))
17486 type
= init_character_type (objfile
, bits
, 1, name
);
17488 type
= init_integer_type (objfile
, bits
, 1, name
);
17490 case DW_ATE_signed_char
:
17491 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17492 || cu
->language
== language_pascal
17493 || cu
->language
== language_fortran
)
17494 type
= init_character_type (objfile
, bits
, 0, name
);
17496 type
= init_integer_type (objfile
, bits
, 0, name
);
17498 case DW_ATE_unsigned_char
:
17499 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17500 || cu
->language
== language_pascal
17501 || cu
->language
== language_fortran
17502 || cu
->language
== language_rust
)
17503 type
= init_character_type (objfile
, bits
, 1, name
);
17505 type
= init_integer_type (objfile
, bits
, 1, name
);
17509 gdbarch
*arch
= get_objfile_arch (objfile
);
17512 type
= builtin_type (arch
)->builtin_char16
;
17513 else if (bits
== 32)
17514 type
= builtin_type (arch
)->builtin_char32
;
17517 complaint (&symfile_complaints
,
17518 _("unsupported DW_ATE_UTF bit size: '%d'"),
17520 type
= init_integer_type (objfile
, bits
, 1, name
);
17522 return set_die_type (die
, type
, cu
);
17527 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
17528 dwarf_type_encoding_name (encoding
));
17529 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17533 if (name
&& strcmp (name
, "char") == 0)
17534 TYPE_NOSIGN (type
) = 1;
17536 return set_die_type (die
, type
, cu
);
17539 /* Parse dwarf attribute if it's a block, reference or constant and put the
17540 resulting value of the attribute into struct bound_prop.
17541 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17544 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17545 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
17547 struct dwarf2_property_baton
*baton
;
17548 struct obstack
*obstack
17549 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17551 if (attr
== NULL
|| prop
== NULL
)
17554 if (attr_form_is_block (attr
))
17556 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17557 baton
->referenced_type
= NULL
;
17558 baton
->locexpr
.per_cu
= cu
->per_cu
;
17559 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17560 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17561 prop
->data
.baton
= baton
;
17562 prop
->kind
= PROP_LOCEXPR
;
17563 gdb_assert (prop
->data
.baton
!= NULL
);
17565 else if (attr_form_is_ref (attr
))
17567 struct dwarf2_cu
*target_cu
= cu
;
17568 struct die_info
*target_die
;
17569 struct attribute
*target_attr
;
17571 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17572 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17573 if (target_attr
== NULL
)
17574 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17576 if (target_attr
== NULL
)
17579 switch (target_attr
->name
)
17581 case DW_AT_location
:
17582 if (attr_form_is_section_offset (target_attr
))
17584 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17585 baton
->referenced_type
= die_type (target_die
, target_cu
);
17586 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17587 prop
->data
.baton
= baton
;
17588 prop
->kind
= PROP_LOCLIST
;
17589 gdb_assert (prop
->data
.baton
!= NULL
);
17591 else if (attr_form_is_block (target_attr
))
17593 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17594 baton
->referenced_type
= die_type (target_die
, target_cu
);
17595 baton
->locexpr
.per_cu
= cu
->per_cu
;
17596 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17597 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17598 prop
->data
.baton
= baton
;
17599 prop
->kind
= PROP_LOCEXPR
;
17600 gdb_assert (prop
->data
.baton
!= NULL
);
17604 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17605 "dynamic property");
17609 case DW_AT_data_member_location
:
17613 if (!handle_data_member_location (target_die
, target_cu
,
17617 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17618 baton
->referenced_type
= read_type_die (target_die
->parent
,
17620 baton
->offset_info
.offset
= offset
;
17621 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17622 prop
->data
.baton
= baton
;
17623 prop
->kind
= PROP_ADDR_OFFSET
;
17628 else if (attr_form_is_constant (attr
))
17630 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17631 prop
->kind
= PROP_CONST
;
17635 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17636 dwarf2_name (die
, cu
));
17643 /* Read the given DW_AT_subrange DIE. */
17645 static struct type
*
17646 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17648 struct type
*base_type
, *orig_base_type
;
17649 struct type
*range_type
;
17650 struct attribute
*attr
;
17651 struct dynamic_prop low
, high
;
17652 int low_default_is_valid
;
17653 int high_bound_is_count
= 0;
17655 LONGEST negative_mask
;
17657 orig_base_type
= die_type (die
, cu
);
17658 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17659 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17660 creating the range type, but we use the result of check_typedef
17661 when examining properties of the type. */
17662 base_type
= check_typedef (orig_base_type
);
17664 /* The die_type call above may have already set the type for this DIE. */
17665 range_type
= get_die_type (die
, cu
);
17669 low
.kind
= PROP_CONST
;
17670 high
.kind
= PROP_CONST
;
17671 high
.data
.const_val
= 0;
17673 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17674 omitting DW_AT_lower_bound. */
17675 switch (cu
->language
)
17678 case language_cplus
:
17679 low
.data
.const_val
= 0;
17680 low_default_is_valid
= 1;
17682 case language_fortran
:
17683 low
.data
.const_val
= 1;
17684 low_default_is_valid
= 1;
17687 case language_objc
:
17688 case language_rust
:
17689 low
.data
.const_val
= 0;
17690 low_default_is_valid
= (cu
->header
.version
>= 4);
17694 case language_pascal
:
17695 low
.data
.const_val
= 1;
17696 low_default_is_valid
= (cu
->header
.version
>= 4);
17699 low
.data
.const_val
= 0;
17700 low_default_is_valid
= 0;
17704 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17706 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
17707 else if (!low_default_is_valid
)
17708 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
17709 "- DIE at %s [in module %s]"),
17710 sect_offset_str (die
->sect_off
),
17711 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17713 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17714 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17716 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
17717 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17719 /* If bounds are constant do the final calculation here. */
17720 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17721 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17723 high_bound_is_count
= 1;
17727 /* Dwarf-2 specifications explicitly allows to create subrange types
17728 without specifying a base type.
17729 In that case, the base type must be set to the type of
17730 the lower bound, upper bound or count, in that order, if any of these
17731 three attributes references an object that has a type.
17732 If no base type is found, the Dwarf-2 specifications say that
17733 a signed integer type of size equal to the size of an address should
17735 For the following C code: `extern char gdb_int [];'
17736 GCC produces an empty range DIE.
17737 FIXME: muller/2010-05-28: Possible references to object for low bound,
17738 high bound or count are not yet handled by this code. */
17739 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
17741 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17742 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17743 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
17744 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
17746 /* Test "int", "long int", and "long long int" objfile types,
17747 and select the first one having a size above or equal to the
17748 architecture address size. */
17749 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17750 base_type
= int_type
;
17753 int_type
= objfile_type (objfile
)->builtin_long
;
17754 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17755 base_type
= int_type
;
17758 int_type
= objfile_type (objfile
)->builtin_long_long
;
17759 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17760 base_type
= int_type
;
17765 /* Normally, the DWARF producers are expected to use a signed
17766 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17767 But this is unfortunately not always the case, as witnessed
17768 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17769 is used instead. To work around that ambiguity, we treat
17770 the bounds as signed, and thus sign-extend their values, when
17771 the base type is signed. */
17773 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17774 if (low
.kind
== PROP_CONST
17775 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17776 low
.data
.const_val
|= negative_mask
;
17777 if (high
.kind
== PROP_CONST
17778 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17779 high
.data
.const_val
|= negative_mask
;
17781 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
17783 if (high_bound_is_count
)
17784 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17786 /* Ada expects an empty array on no boundary attributes. */
17787 if (attr
== NULL
&& cu
->language
!= language_ada
)
17788 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17790 name
= dwarf2_name (die
, cu
);
17792 TYPE_NAME (range_type
) = name
;
17794 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17796 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17798 set_die_type (die
, range_type
, cu
);
17800 /* set_die_type should be already done. */
17801 set_descriptive_type (range_type
, die
, cu
);
17806 static struct type
*
17807 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17811 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17813 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17815 /* In Ada, an unspecified type is typically used when the description
17816 of the type is defered to a different unit. When encountering
17817 such a type, we treat it as a stub, and try to resolve it later on,
17819 if (cu
->language
== language_ada
)
17820 TYPE_STUB (type
) = 1;
17822 return set_die_type (die
, type
, cu
);
17825 /* Read a single die and all its descendents. Set the die's sibling
17826 field to NULL; set other fields in the die correctly, and set all
17827 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17828 location of the info_ptr after reading all of those dies. PARENT
17829 is the parent of the die in question. */
17831 static struct die_info
*
17832 read_die_and_children (const struct die_reader_specs
*reader
,
17833 const gdb_byte
*info_ptr
,
17834 const gdb_byte
**new_info_ptr
,
17835 struct die_info
*parent
)
17837 struct die_info
*die
;
17838 const gdb_byte
*cur_ptr
;
17841 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
17844 *new_info_ptr
= cur_ptr
;
17847 store_in_ref_table (die
, reader
->cu
);
17850 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17854 *new_info_ptr
= cur_ptr
;
17857 die
->sibling
= NULL
;
17858 die
->parent
= parent
;
17862 /* Read a die, all of its descendents, and all of its siblings; set
17863 all of the fields of all of the dies correctly. Arguments are as
17864 in read_die_and_children. */
17866 static struct die_info
*
17867 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17868 const gdb_byte
*info_ptr
,
17869 const gdb_byte
**new_info_ptr
,
17870 struct die_info
*parent
)
17872 struct die_info
*first_die
, *last_sibling
;
17873 const gdb_byte
*cur_ptr
;
17875 cur_ptr
= info_ptr
;
17876 first_die
= last_sibling
= NULL
;
17880 struct die_info
*die
17881 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17885 *new_info_ptr
= cur_ptr
;
17892 last_sibling
->sibling
= die
;
17894 last_sibling
= die
;
17898 /* Read a die, all of its descendents, and all of its siblings; set
17899 all of the fields of all of the dies correctly. Arguments are as
17900 in read_die_and_children.
17901 This the main entry point for reading a DIE and all its children. */
17903 static struct die_info
*
17904 read_die_and_siblings (const struct die_reader_specs
*reader
,
17905 const gdb_byte
*info_ptr
,
17906 const gdb_byte
**new_info_ptr
,
17907 struct die_info
*parent
)
17909 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17910 new_info_ptr
, parent
);
17912 if (dwarf_die_debug
)
17914 fprintf_unfiltered (gdb_stdlog
,
17915 "Read die from %s@0x%x of %s:\n",
17916 get_section_name (reader
->die_section
),
17917 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17918 bfd_get_filename (reader
->abfd
));
17919 dump_die (die
, dwarf_die_debug
);
17925 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17927 The caller is responsible for filling in the extra attributes
17928 and updating (*DIEP)->num_attrs.
17929 Set DIEP to point to a newly allocated die with its information,
17930 except for its child, sibling, and parent fields.
17931 Set HAS_CHILDREN to tell whether the die has children or not. */
17933 static const gdb_byte
*
17934 read_full_die_1 (const struct die_reader_specs
*reader
,
17935 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17936 int *has_children
, int num_extra_attrs
)
17938 unsigned int abbrev_number
, bytes_read
, i
;
17939 struct abbrev_info
*abbrev
;
17940 struct die_info
*die
;
17941 struct dwarf2_cu
*cu
= reader
->cu
;
17942 bfd
*abfd
= reader
->abfd
;
17944 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17945 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17946 info_ptr
+= bytes_read
;
17947 if (!abbrev_number
)
17954 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17956 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17958 bfd_get_filename (abfd
));
17960 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17961 die
->sect_off
= sect_off
;
17962 die
->tag
= abbrev
->tag
;
17963 die
->abbrev
= abbrev_number
;
17965 /* Make the result usable.
17966 The caller needs to update num_attrs after adding the extra
17968 die
->num_attrs
= abbrev
->num_attrs
;
17970 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17971 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17975 *has_children
= abbrev
->has_children
;
17979 /* Read a die and all its attributes.
17980 Set DIEP to point to a newly allocated die with its information,
17981 except for its child, sibling, and parent fields.
17982 Set HAS_CHILDREN to tell whether the die has children or not. */
17984 static const gdb_byte
*
17985 read_full_die (const struct die_reader_specs
*reader
,
17986 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17989 const gdb_byte
*result
;
17991 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
17993 if (dwarf_die_debug
)
17995 fprintf_unfiltered (gdb_stdlog
,
17996 "Read die from %s@0x%x of %s:\n",
17997 get_section_name (reader
->die_section
),
17998 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17999 bfd_get_filename (reader
->abfd
));
18000 dump_die (*diep
, dwarf_die_debug
);
18006 /* Abbreviation tables.
18008 In DWARF version 2, the description of the debugging information is
18009 stored in a separate .debug_abbrev section. Before we read any
18010 dies from a section we read in all abbreviations and install them
18011 in a hash table. */
18013 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18015 struct abbrev_info
*
18016 abbrev_table::alloc_abbrev ()
18018 struct abbrev_info
*abbrev
;
18020 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18021 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18026 /* Add an abbreviation to the table. */
18029 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18030 struct abbrev_info
*abbrev
)
18032 unsigned int hash_number
;
18034 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18035 abbrev
->next
= m_abbrevs
[hash_number
];
18036 m_abbrevs
[hash_number
] = abbrev
;
18039 /* Look up an abbrev in the table.
18040 Returns NULL if the abbrev is not found. */
18042 struct abbrev_info
*
18043 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18045 unsigned int hash_number
;
18046 struct abbrev_info
*abbrev
;
18048 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18049 abbrev
= m_abbrevs
[hash_number
];
18053 if (abbrev
->number
== abbrev_number
)
18055 abbrev
= abbrev
->next
;
18060 /* Read in an abbrev table. */
18062 static abbrev_table_up
18063 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18064 struct dwarf2_section_info
*section
,
18065 sect_offset sect_off
)
18067 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18068 bfd
*abfd
= get_section_bfd_owner (section
);
18069 const gdb_byte
*abbrev_ptr
;
18070 struct abbrev_info
*cur_abbrev
;
18071 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18072 unsigned int abbrev_form
;
18073 struct attr_abbrev
*cur_attrs
;
18074 unsigned int allocated_attrs
;
18076 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18078 dwarf2_read_section (objfile
, section
);
18079 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18080 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18081 abbrev_ptr
+= bytes_read
;
18083 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18084 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18086 /* Loop until we reach an abbrev number of 0. */
18087 while (abbrev_number
)
18089 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18091 /* read in abbrev header */
18092 cur_abbrev
->number
= abbrev_number
;
18094 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18095 abbrev_ptr
+= bytes_read
;
18096 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18099 /* now read in declarations */
18102 LONGEST implicit_const
;
18104 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18105 abbrev_ptr
+= bytes_read
;
18106 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18107 abbrev_ptr
+= bytes_read
;
18108 if (abbrev_form
== DW_FORM_implicit_const
)
18110 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18112 abbrev_ptr
+= bytes_read
;
18116 /* Initialize it due to a false compiler warning. */
18117 implicit_const
= -1;
18120 if (abbrev_name
== 0)
18123 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18125 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18127 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18130 cur_attrs
[cur_abbrev
->num_attrs
].name
18131 = (enum dwarf_attribute
) abbrev_name
;
18132 cur_attrs
[cur_abbrev
->num_attrs
].form
18133 = (enum dwarf_form
) abbrev_form
;
18134 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18135 ++cur_abbrev
->num_attrs
;
18138 cur_abbrev
->attrs
=
18139 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18140 cur_abbrev
->num_attrs
);
18141 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18142 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18144 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18146 /* Get next abbreviation.
18147 Under Irix6 the abbreviations for a compilation unit are not
18148 always properly terminated with an abbrev number of 0.
18149 Exit loop if we encounter an abbreviation which we have
18150 already read (which means we are about to read the abbreviations
18151 for the next compile unit) or if the end of the abbreviation
18152 table is reached. */
18153 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18155 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18156 abbrev_ptr
+= bytes_read
;
18157 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18162 return abbrev_table
;
18165 /* Returns nonzero if TAG represents a type that we might generate a partial
18169 is_type_tag_for_partial (int tag
)
18174 /* Some types that would be reasonable to generate partial symbols for,
18175 that we don't at present. */
18176 case DW_TAG_array_type
:
18177 case DW_TAG_file_type
:
18178 case DW_TAG_ptr_to_member_type
:
18179 case DW_TAG_set_type
:
18180 case DW_TAG_string_type
:
18181 case DW_TAG_subroutine_type
:
18183 case DW_TAG_base_type
:
18184 case DW_TAG_class_type
:
18185 case DW_TAG_interface_type
:
18186 case DW_TAG_enumeration_type
:
18187 case DW_TAG_structure_type
:
18188 case DW_TAG_subrange_type
:
18189 case DW_TAG_typedef
:
18190 case DW_TAG_union_type
:
18197 /* Load all DIEs that are interesting for partial symbols into memory. */
18199 static struct partial_die_info
*
18200 load_partial_dies (const struct die_reader_specs
*reader
,
18201 const gdb_byte
*info_ptr
, int building_psymtab
)
18203 struct dwarf2_cu
*cu
= reader
->cu
;
18204 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18205 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18206 unsigned int bytes_read
;
18207 unsigned int load_all
= 0;
18208 int nesting_level
= 1;
18213 gdb_assert (cu
->per_cu
!= NULL
);
18214 if (cu
->per_cu
->load_all_dies
)
18218 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18222 &cu
->comp_unit_obstack
,
18223 hashtab_obstack_allocate
,
18224 dummy_obstack_deallocate
);
18228 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18230 /* A NULL abbrev means the end of a series of children. */
18231 if (abbrev
== NULL
)
18233 if (--nesting_level
== 0)
18236 info_ptr
+= bytes_read
;
18237 last_die
= parent_die
;
18238 parent_die
= parent_die
->die_parent
;
18242 /* Check for template arguments. We never save these; if
18243 they're seen, we just mark the parent, and go on our way. */
18244 if (parent_die
!= NULL
18245 && cu
->language
== language_cplus
18246 && (abbrev
->tag
== DW_TAG_template_type_param
18247 || abbrev
->tag
== DW_TAG_template_value_param
))
18249 parent_die
->has_template_arguments
= 1;
18253 /* We don't need a partial DIE for the template argument. */
18254 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18259 /* We only recurse into c++ subprograms looking for template arguments.
18260 Skip their other children. */
18262 && cu
->language
== language_cplus
18263 && parent_die
!= NULL
18264 && parent_die
->tag
== DW_TAG_subprogram
)
18266 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18270 /* Check whether this DIE is interesting enough to save. Normally
18271 we would not be interested in members here, but there may be
18272 later variables referencing them via DW_AT_specification (for
18273 static members). */
18275 && !is_type_tag_for_partial (abbrev
->tag
)
18276 && abbrev
->tag
!= DW_TAG_constant
18277 && abbrev
->tag
!= DW_TAG_enumerator
18278 && abbrev
->tag
!= DW_TAG_subprogram
18279 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18280 && abbrev
->tag
!= DW_TAG_lexical_block
18281 && abbrev
->tag
!= DW_TAG_variable
18282 && abbrev
->tag
!= DW_TAG_namespace
18283 && abbrev
->tag
!= DW_TAG_module
18284 && abbrev
->tag
!= DW_TAG_member
18285 && abbrev
->tag
!= DW_TAG_imported_unit
18286 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18288 /* Otherwise we skip to the next sibling, if any. */
18289 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18293 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18296 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18298 /* This two-pass algorithm for processing partial symbols has a
18299 high cost in cache pressure. Thus, handle some simple cases
18300 here which cover the majority of C partial symbols. DIEs
18301 which neither have specification tags in them, nor could have
18302 specification tags elsewhere pointing at them, can simply be
18303 processed and discarded.
18305 This segment is also optional; scan_partial_symbols and
18306 add_partial_symbol will handle these DIEs if we chain
18307 them in normally. When compilers which do not emit large
18308 quantities of duplicate debug information are more common,
18309 this code can probably be removed. */
18311 /* Any complete simple types at the top level (pretty much all
18312 of them, for a language without namespaces), can be processed
18314 if (parent_die
== NULL
18315 && pdi
.has_specification
== 0
18316 && pdi
.is_declaration
== 0
18317 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18318 || pdi
.tag
== DW_TAG_base_type
18319 || pdi
.tag
== DW_TAG_subrange_type
))
18321 if (building_psymtab
&& pdi
.name
!= NULL
)
18322 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18323 VAR_DOMAIN
, LOC_TYPEDEF
,
18324 &objfile
->static_psymbols
,
18325 0, cu
->language
, objfile
);
18326 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18330 /* The exception for DW_TAG_typedef with has_children above is
18331 a workaround of GCC PR debug/47510. In the case of this complaint
18332 type_name_no_tag_or_error will error on such types later.
18334 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18335 it could not find the child DIEs referenced later, this is checked
18336 above. In correct DWARF DW_TAG_typedef should have no children. */
18338 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18339 complaint (&symfile_complaints
,
18340 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18341 "- DIE at %s [in module %s]"),
18342 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18344 /* If we're at the second level, and we're an enumerator, and
18345 our parent has no specification (meaning possibly lives in a
18346 namespace elsewhere), then we can add the partial symbol now
18347 instead of queueing it. */
18348 if (pdi
.tag
== DW_TAG_enumerator
18349 && parent_die
!= NULL
18350 && parent_die
->die_parent
== NULL
18351 && parent_die
->tag
== DW_TAG_enumeration_type
18352 && parent_die
->has_specification
== 0)
18354 if (pdi
.name
== NULL
)
18355 complaint (&symfile_complaints
,
18356 _("malformed enumerator DIE ignored"));
18357 else if (building_psymtab
)
18358 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18359 VAR_DOMAIN
, LOC_CONST
,
18360 cu
->language
== language_cplus
18361 ? &objfile
->global_psymbols
18362 : &objfile
->static_psymbols
,
18363 0, cu
->language
, objfile
);
18365 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18369 struct partial_die_info
*part_die
18370 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18372 /* We'll save this DIE so link it in. */
18373 part_die
->die_parent
= parent_die
;
18374 part_die
->die_sibling
= NULL
;
18375 part_die
->die_child
= NULL
;
18377 if (last_die
&& last_die
== parent_die
)
18378 last_die
->die_child
= part_die
;
18380 last_die
->die_sibling
= part_die
;
18382 last_die
= part_die
;
18384 if (first_die
== NULL
)
18385 first_die
= part_die
;
18387 /* Maybe add the DIE to the hash table. Not all DIEs that we
18388 find interesting need to be in the hash table, because we
18389 also have the parent/sibling/child chains; only those that we
18390 might refer to by offset later during partial symbol reading.
18392 For now this means things that might have be the target of a
18393 DW_AT_specification, DW_AT_abstract_origin, or
18394 DW_AT_extension. DW_AT_extension will refer only to
18395 namespaces; DW_AT_abstract_origin refers to functions (and
18396 many things under the function DIE, but we do not recurse
18397 into function DIEs during partial symbol reading) and
18398 possibly variables as well; DW_AT_specification refers to
18399 declarations. Declarations ought to have the DW_AT_declaration
18400 flag. It happens that GCC forgets to put it in sometimes, but
18401 only for functions, not for types.
18403 Adding more things than necessary to the hash table is harmless
18404 except for the performance cost. Adding too few will result in
18405 wasted time in find_partial_die, when we reread the compilation
18406 unit with load_all_dies set. */
18409 || abbrev
->tag
== DW_TAG_constant
18410 || abbrev
->tag
== DW_TAG_subprogram
18411 || abbrev
->tag
== DW_TAG_variable
18412 || abbrev
->tag
== DW_TAG_namespace
18413 || part_die
->is_declaration
)
18417 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18418 to_underlying (part_die
->sect_off
),
18423 /* For some DIEs we want to follow their children (if any). For C
18424 we have no reason to follow the children of structures; for other
18425 languages we have to, so that we can get at method physnames
18426 to infer fully qualified class names, for DW_AT_specification,
18427 and for C++ template arguments. For C++, we also look one level
18428 inside functions to find template arguments (if the name of the
18429 function does not already contain the template arguments).
18431 For Ada, we need to scan the children of subprograms and lexical
18432 blocks as well because Ada allows the definition of nested
18433 entities that could be interesting for the debugger, such as
18434 nested subprograms for instance. */
18435 if (last_die
->has_children
18437 || last_die
->tag
== DW_TAG_namespace
18438 || last_die
->tag
== DW_TAG_module
18439 || last_die
->tag
== DW_TAG_enumeration_type
18440 || (cu
->language
== language_cplus
18441 && last_die
->tag
== DW_TAG_subprogram
18442 && (last_die
->name
== NULL
18443 || strchr (last_die
->name
, '<') == NULL
))
18444 || (cu
->language
!= language_c
18445 && (last_die
->tag
== DW_TAG_class_type
18446 || last_die
->tag
== DW_TAG_interface_type
18447 || last_die
->tag
== DW_TAG_structure_type
18448 || last_die
->tag
== DW_TAG_union_type
))
18449 || (cu
->language
== language_ada
18450 && (last_die
->tag
== DW_TAG_subprogram
18451 || last_die
->tag
== DW_TAG_lexical_block
))))
18454 parent_die
= last_die
;
18458 /* Otherwise we skip to the next sibling, if any. */
18459 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18461 /* Back to the top, do it again. */
18465 partial_die_info::partial_die_info (sect_offset sect_off_
,
18466 struct abbrev_info
*abbrev
)
18467 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18471 /* Read a minimal amount of information into the minimal die structure.
18472 INFO_PTR should point just after the initial uleb128 of a DIE. */
18475 partial_die_info::read (const struct die_reader_specs
*reader
,
18476 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18478 struct dwarf2_cu
*cu
= reader
->cu
;
18479 struct dwarf2_per_objfile
*dwarf2_per_objfile
18480 = cu
->per_cu
->dwarf2_per_objfile
;
18482 int has_low_pc_attr
= 0;
18483 int has_high_pc_attr
= 0;
18484 int high_pc_relative
= 0;
18486 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18488 struct attribute attr
;
18490 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18492 /* Store the data if it is of an attribute we want to keep in a
18493 partial symbol table. */
18499 case DW_TAG_compile_unit
:
18500 case DW_TAG_partial_unit
:
18501 case DW_TAG_type_unit
:
18502 /* Compilation units have a DW_AT_name that is a filename, not
18503 a source language identifier. */
18504 case DW_TAG_enumeration_type
:
18505 case DW_TAG_enumerator
:
18506 /* These tags always have simple identifiers already; no need
18507 to canonicalize them. */
18508 name
= DW_STRING (&attr
);
18512 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18515 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18516 &objfile
->per_bfd
->storage_obstack
);
18521 case DW_AT_linkage_name
:
18522 case DW_AT_MIPS_linkage_name
:
18523 /* Note that both forms of linkage name might appear. We
18524 assume they will be the same, and we only store the last
18526 if (cu
->language
== language_ada
)
18527 name
= DW_STRING (&attr
);
18528 linkage_name
= DW_STRING (&attr
);
18531 has_low_pc_attr
= 1;
18532 lowpc
= attr_value_as_address (&attr
);
18534 case DW_AT_high_pc
:
18535 has_high_pc_attr
= 1;
18536 highpc
= attr_value_as_address (&attr
);
18537 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18538 high_pc_relative
= 1;
18540 case DW_AT_location
:
18541 /* Support the .debug_loc offsets. */
18542 if (attr_form_is_block (&attr
))
18544 d
.locdesc
= DW_BLOCK (&attr
);
18546 else if (attr_form_is_section_offset (&attr
))
18548 dwarf2_complex_location_expr_complaint ();
18552 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18553 "partial symbol information");
18556 case DW_AT_external
:
18557 is_external
= DW_UNSND (&attr
);
18559 case DW_AT_declaration
:
18560 is_declaration
= DW_UNSND (&attr
);
18565 case DW_AT_abstract_origin
:
18566 case DW_AT_specification
:
18567 case DW_AT_extension
:
18568 has_specification
= 1;
18569 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18570 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18571 || cu
->per_cu
->is_dwz
);
18573 case DW_AT_sibling
:
18574 /* Ignore absolute siblings, they might point outside of
18575 the current compile unit. */
18576 if (attr
.form
== DW_FORM_ref_addr
)
18577 complaint (&symfile_complaints
,
18578 _("ignoring absolute DW_AT_sibling"));
18581 const gdb_byte
*buffer
= reader
->buffer
;
18582 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18583 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18585 if (sibling_ptr
< info_ptr
)
18586 complaint (&symfile_complaints
,
18587 _("DW_AT_sibling points backwards"));
18588 else if (sibling_ptr
> reader
->buffer_end
)
18589 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18591 sibling
= sibling_ptr
;
18594 case DW_AT_byte_size
:
18597 case DW_AT_const_value
:
18598 has_const_value
= 1;
18600 case DW_AT_calling_convention
:
18601 /* DWARF doesn't provide a way to identify a program's source-level
18602 entry point. DW_AT_calling_convention attributes are only meant
18603 to describe functions' calling conventions.
18605 However, because it's a necessary piece of information in
18606 Fortran, and before DWARF 4 DW_CC_program was the only
18607 piece of debugging information whose definition refers to
18608 a 'main program' at all, several compilers marked Fortran
18609 main programs with DW_CC_program --- even when those
18610 functions use the standard calling conventions.
18612 Although DWARF now specifies a way to provide this
18613 information, we support this practice for backward
18615 if (DW_UNSND (&attr
) == DW_CC_program
18616 && cu
->language
== language_fortran
)
18617 main_subprogram
= 1;
18620 if (DW_UNSND (&attr
) == DW_INL_inlined
18621 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18622 may_be_inlined
= 1;
18626 if (tag
== DW_TAG_imported_unit
)
18628 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18629 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18630 || cu
->per_cu
->is_dwz
);
18634 case DW_AT_main_subprogram
:
18635 main_subprogram
= DW_UNSND (&attr
);
18643 if (high_pc_relative
)
18646 if (has_low_pc_attr
&& has_high_pc_attr
)
18648 /* When using the GNU linker, .gnu.linkonce. sections are used to
18649 eliminate duplicate copies of functions and vtables and such.
18650 The linker will arbitrarily choose one and discard the others.
18651 The AT_*_pc values for such functions refer to local labels in
18652 these sections. If the section from that file was discarded, the
18653 labels are not in the output, so the relocs get a value of 0.
18654 If this is a discarded function, mark the pc bounds as invalid,
18655 so that GDB will ignore it. */
18656 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18658 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18659 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18661 complaint (&symfile_complaints
,
18662 _("DW_AT_low_pc %s is zero "
18663 "for DIE at %s [in module %s]"),
18664 paddress (gdbarch
, lowpc
),
18665 sect_offset_str (sect_off
),
18666 objfile_name (objfile
));
18668 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18669 else if (lowpc
>= highpc
)
18671 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18672 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18674 complaint (&symfile_complaints
,
18675 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18676 "for DIE at %s [in module %s]"),
18677 paddress (gdbarch
, lowpc
),
18678 paddress (gdbarch
, highpc
),
18679 sect_offset_str (sect_off
),
18680 objfile_name (objfile
));
18689 /* Find a cached partial DIE at OFFSET in CU. */
18691 struct partial_die_info
*
18692 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18694 struct partial_die_info
*lookup_die
= NULL
;
18695 struct partial_die_info
part_die (sect_off
);
18697 lookup_die
= ((struct partial_die_info
*)
18698 htab_find_with_hash (partial_dies
, &part_die
,
18699 to_underlying (sect_off
)));
18704 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18705 except in the case of .debug_types DIEs which do not reference
18706 outside their CU (they do however referencing other types via
18707 DW_FORM_ref_sig8). */
18709 static struct partial_die_info
*
18710 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18712 struct dwarf2_per_objfile
*dwarf2_per_objfile
18713 = cu
->per_cu
->dwarf2_per_objfile
;
18714 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18715 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18716 struct partial_die_info
*pd
= NULL
;
18718 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18719 && offset_in_cu_p (&cu
->header
, sect_off
))
18721 pd
= cu
->find_partial_die (sect_off
);
18724 /* We missed recording what we needed.
18725 Load all dies and try again. */
18726 per_cu
= cu
->per_cu
;
18730 /* TUs don't reference other CUs/TUs (except via type signatures). */
18731 if (cu
->per_cu
->is_debug_types
)
18733 error (_("Dwarf Error: Type Unit at offset %s contains"
18734 " external reference to offset %s [in module %s].\n"),
18735 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18736 bfd_get_filename (objfile
->obfd
));
18738 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18739 dwarf2_per_objfile
);
18741 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18742 load_partial_comp_unit (per_cu
);
18744 per_cu
->cu
->last_used
= 0;
18745 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18748 /* If we didn't find it, and not all dies have been loaded,
18749 load them all and try again. */
18751 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18753 per_cu
->load_all_dies
= 1;
18755 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18756 THIS_CU->cu may already be in use. So we can't just free it and
18757 replace its DIEs with the ones we read in. Instead, we leave those
18758 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18759 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18761 load_partial_comp_unit (per_cu
);
18763 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18767 internal_error (__FILE__
, __LINE__
,
18768 _("could not find partial DIE %s "
18769 "in cache [from module %s]\n"),
18770 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18774 /* See if we can figure out if the class lives in a namespace. We do
18775 this by looking for a member function; its demangled name will
18776 contain namespace info, if there is any. */
18779 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18780 struct dwarf2_cu
*cu
)
18782 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18783 what template types look like, because the demangler
18784 frequently doesn't give the same name as the debug info. We
18785 could fix this by only using the demangled name to get the
18786 prefix (but see comment in read_structure_type). */
18788 struct partial_die_info
*real_pdi
;
18789 struct partial_die_info
*child_pdi
;
18791 /* If this DIE (this DIE's specification, if any) has a parent, then
18792 we should not do this. We'll prepend the parent's fully qualified
18793 name when we create the partial symbol. */
18795 real_pdi
= struct_pdi
;
18796 while (real_pdi
->has_specification
)
18797 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
18798 real_pdi
->spec_is_dwz
, cu
);
18800 if (real_pdi
->die_parent
!= NULL
)
18803 for (child_pdi
= struct_pdi
->die_child
;
18805 child_pdi
= child_pdi
->die_sibling
)
18807 if (child_pdi
->tag
== DW_TAG_subprogram
18808 && child_pdi
->linkage_name
!= NULL
)
18810 char *actual_class_name
18811 = language_class_name_from_physname (cu
->language_defn
,
18812 child_pdi
->linkage_name
);
18813 if (actual_class_name
!= NULL
)
18815 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18818 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18820 strlen (actual_class_name
)));
18821 xfree (actual_class_name
);
18829 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18831 /* Once we've fixed up a die, there's no point in doing so again.
18832 This also avoids a memory leak if we were to call
18833 guess_partial_die_structure_name multiple times. */
18837 /* If we found a reference attribute and the DIE has no name, try
18838 to find a name in the referred to DIE. */
18840 if (name
== NULL
&& has_specification
)
18842 struct partial_die_info
*spec_die
;
18844 spec_die
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18846 spec_die
->fixup (cu
);
18848 if (spec_die
->name
)
18850 name
= spec_die
->name
;
18852 /* Copy DW_AT_external attribute if it is set. */
18853 if (spec_die
->is_external
)
18854 is_external
= spec_die
->is_external
;
18858 /* Set default names for some unnamed DIEs. */
18860 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18861 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18863 /* If there is no parent die to provide a namespace, and there are
18864 children, see if we can determine the namespace from their linkage
18866 if (cu
->language
== language_cplus
18867 && !VEC_empty (dwarf2_section_info_def
,
18868 cu
->per_cu
->dwarf2_per_objfile
->types
)
18869 && die_parent
== NULL
18871 && (tag
== DW_TAG_class_type
18872 || tag
== DW_TAG_structure_type
18873 || tag
== DW_TAG_union_type
))
18874 guess_partial_die_structure_name (this, cu
);
18876 /* GCC might emit a nameless struct or union that has a linkage
18877 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18879 && (tag
== DW_TAG_class_type
18880 || tag
== DW_TAG_interface_type
18881 || tag
== DW_TAG_structure_type
18882 || tag
== DW_TAG_union_type
)
18883 && linkage_name
!= NULL
)
18887 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
18892 /* Strip any leading namespaces/classes, keep only the base name.
18893 DW_AT_name for named DIEs does not contain the prefixes. */
18894 base
= strrchr (demangled
, ':');
18895 if (base
&& base
> demangled
&& base
[-1] == ':')
18900 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18903 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18904 base
, strlen (base
)));
18912 /* Read an attribute value described by an attribute form. */
18914 static const gdb_byte
*
18915 read_attribute_value (const struct die_reader_specs
*reader
,
18916 struct attribute
*attr
, unsigned form
,
18917 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
18919 struct dwarf2_cu
*cu
= reader
->cu
;
18920 struct dwarf2_per_objfile
*dwarf2_per_objfile
18921 = cu
->per_cu
->dwarf2_per_objfile
;
18922 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18923 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18924 bfd
*abfd
= reader
->abfd
;
18925 struct comp_unit_head
*cu_header
= &cu
->header
;
18926 unsigned int bytes_read
;
18927 struct dwarf_block
*blk
;
18929 attr
->form
= (enum dwarf_form
) form
;
18932 case DW_FORM_ref_addr
:
18933 if (cu
->header
.version
== 2)
18934 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18936 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
18937 &cu
->header
, &bytes_read
);
18938 info_ptr
+= bytes_read
;
18940 case DW_FORM_GNU_ref_alt
:
18941 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18942 info_ptr
+= bytes_read
;
18945 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18946 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18947 info_ptr
+= bytes_read
;
18949 case DW_FORM_block2
:
18950 blk
= dwarf_alloc_block (cu
);
18951 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18953 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18954 info_ptr
+= blk
->size
;
18955 DW_BLOCK (attr
) = blk
;
18957 case DW_FORM_block4
:
18958 blk
= dwarf_alloc_block (cu
);
18959 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18961 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18962 info_ptr
+= blk
->size
;
18963 DW_BLOCK (attr
) = blk
;
18965 case DW_FORM_data2
:
18966 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18969 case DW_FORM_data4
:
18970 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18973 case DW_FORM_data8
:
18974 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18977 case DW_FORM_data16
:
18978 blk
= dwarf_alloc_block (cu
);
18980 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18982 DW_BLOCK (attr
) = blk
;
18984 case DW_FORM_sec_offset
:
18985 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18986 info_ptr
+= bytes_read
;
18988 case DW_FORM_string
:
18989 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18990 DW_STRING_IS_CANONICAL (attr
) = 0;
18991 info_ptr
+= bytes_read
;
18994 if (!cu
->per_cu
->is_dwz
)
18996 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18997 abfd
, info_ptr
, cu_header
,
18999 DW_STRING_IS_CANONICAL (attr
) = 0;
19000 info_ptr
+= bytes_read
;
19004 case DW_FORM_line_strp
:
19005 if (!cu
->per_cu
->is_dwz
)
19007 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19009 cu_header
, &bytes_read
);
19010 DW_STRING_IS_CANONICAL (attr
) = 0;
19011 info_ptr
+= bytes_read
;
19015 case DW_FORM_GNU_strp_alt
:
19017 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19018 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19021 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19023 DW_STRING_IS_CANONICAL (attr
) = 0;
19024 info_ptr
+= bytes_read
;
19027 case DW_FORM_exprloc
:
19028 case DW_FORM_block
:
19029 blk
= dwarf_alloc_block (cu
);
19030 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19031 info_ptr
+= bytes_read
;
19032 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19033 info_ptr
+= blk
->size
;
19034 DW_BLOCK (attr
) = blk
;
19036 case DW_FORM_block1
:
19037 blk
= dwarf_alloc_block (cu
);
19038 blk
->size
= read_1_byte (abfd
, info_ptr
);
19040 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19041 info_ptr
+= blk
->size
;
19042 DW_BLOCK (attr
) = blk
;
19044 case DW_FORM_data1
:
19045 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19049 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19052 case DW_FORM_flag_present
:
19053 DW_UNSND (attr
) = 1;
19055 case DW_FORM_sdata
:
19056 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19057 info_ptr
+= bytes_read
;
19059 case DW_FORM_udata
:
19060 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19061 info_ptr
+= bytes_read
;
19064 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19065 + read_1_byte (abfd
, info_ptr
));
19069 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19070 + read_2_bytes (abfd
, info_ptr
));
19074 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19075 + read_4_bytes (abfd
, info_ptr
));
19079 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19080 + read_8_bytes (abfd
, info_ptr
));
19083 case DW_FORM_ref_sig8
:
19084 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19087 case DW_FORM_ref_udata
:
19088 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19089 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19090 info_ptr
+= bytes_read
;
19092 case DW_FORM_indirect
:
19093 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19094 info_ptr
+= bytes_read
;
19095 if (form
== DW_FORM_implicit_const
)
19097 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19098 info_ptr
+= bytes_read
;
19100 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19103 case DW_FORM_implicit_const
:
19104 DW_SND (attr
) = implicit_const
;
19106 case DW_FORM_GNU_addr_index
:
19107 if (reader
->dwo_file
== NULL
)
19109 /* For now flag a hard error.
19110 Later we can turn this into a complaint. */
19111 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19112 dwarf_form_name (form
),
19113 bfd_get_filename (abfd
));
19115 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19116 info_ptr
+= bytes_read
;
19118 case DW_FORM_GNU_str_index
:
19119 if (reader
->dwo_file
== NULL
)
19121 /* For now flag a hard error.
19122 Later we can turn this into a complaint if warranted. */
19123 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19124 dwarf_form_name (form
),
19125 bfd_get_filename (abfd
));
19128 ULONGEST str_index
=
19129 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19131 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19132 DW_STRING_IS_CANONICAL (attr
) = 0;
19133 info_ptr
+= bytes_read
;
19137 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19138 dwarf_form_name (form
),
19139 bfd_get_filename (abfd
));
19143 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19144 attr
->form
= DW_FORM_GNU_ref_alt
;
19146 /* We have seen instances where the compiler tried to emit a byte
19147 size attribute of -1 which ended up being encoded as an unsigned
19148 0xffffffff. Although 0xffffffff is technically a valid size value,
19149 an object of this size seems pretty unlikely so we can relatively
19150 safely treat these cases as if the size attribute was invalid and
19151 treat them as zero by default. */
19152 if (attr
->name
== DW_AT_byte_size
19153 && form
== DW_FORM_data4
19154 && DW_UNSND (attr
) >= 0xffffffff)
19157 (&symfile_complaints
,
19158 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19159 hex_string (DW_UNSND (attr
)));
19160 DW_UNSND (attr
) = 0;
19166 /* Read an attribute described by an abbreviated attribute. */
19168 static const gdb_byte
*
19169 read_attribute (const struct die_reader_specs
*reader
,
19170 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19171 const gdb_byte
*info_ptr
)
19173 attr
->name
= abbrev
->name
;
19174 return read_attribute_value (reader
, attr
, abbrev
->form
,
19175 abbrev
->implicit_const
, info_ptr
);
19178 /* Read dwarf information from a buffer. */
19180 static unsigned int
19181 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19183 return bfd_get_8 (abfd
, buf
);
19187 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19189 return bfd_get_signed_8 (abfd
, buf
);
19192 static unsigned int
19193 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19195 return bfd_get_16 (abfd
, buf
);
19199 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19201 return bfd_get_signed_16 (abfd
, buf
);
19204 static unsigned int
19205 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19207 return bfd_get_32 (abfd
, buf
);
19211 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19213 return bfd_get_signed_32 (abfd
, buf
);
19217 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19219 return bfd_get_64 (abfd
, buf
);
19223 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19224 unsigned int *bytes_read
)
19226 struct comp_unit_head
*cu_header
= &cu
->header
;
19227 CORE_ADDR retval
= 0;
19229 if (cu_header
->signed_addr_p
)
19231 switch (cu_header
->addr_size
)
19234 retval
= bfd_get_signed_16 (abfd
, buf
);
19237 retval
= bfd_get_signed_32 (abfd
, buf
);
19240 retval
= bfd_get_signed_64 (abfd
, buf
);
19243 internal_error (__FILE__
, __LINE__
,
19244 _("read_address: bad switch, signed [in module %s]"),
19245 bfd_get_filename (abfd
));
19250 switch (cu_header
->addr_size
)
19253 retval
= bfd_get_16 (abfd
, buf
);
19256 retval
= bfd_get_32 (abfd
, buf
);
19259 retval
= bfd_get_64 (abfd
, buf
);
19262 internal_error (__FILE__
, __LINE__
,
19263 _("read_address: bad switch, "
19264 "unsigned [in module %s]"),
19265 bfd_get_filename (abfd
));
19269 *bytes_read
= cu_header
->addr_size
;
19273 /* Read the initial length from a section. The (draft) DWARF 3
19274 specification allows the initial length to take up either 4 bytes
19275 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19276 bytes describe the length and all offsets will be 8 bytes in length
19279 An older, non-standard 64-bit format is also handled by this
19280 function. The older format in question stores the initial length
19281 as an 8-byte quantity without an escape value. Lengths greater
19282 than 2^32 aren't very common which means that the initial 4 bytes
19283 is almost always zero. Since a length value of zero doesn't make
19284 sense for the 32-bit format, this initial zero can be considered to
19285 be an escape value which indicates the presence of the older 64-bit
19286 format. As written, the code can't detect (old format) lengths
19287 greater than 4GB. If it becomes necessary to handle lengths
19288 somewhat larger than 4GB, we could allow other small values (such
19289 as the non-sensical values of 1, 2, and 3) to also be used as
19290 escape values indicating the presence of the old format.
19292 The value returned via bytes_read should be used to increment the
19293 relevant pointer after calling read_initial_length().
19295 [ Note: read_initial_length() and read_offset() are based on the
19296 document entitled "DWARF Debugging Information Format", revision
19297 3, draft 8, dated November 19, 2001. This document was obtained
19300 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19302 This document is only a draft and is subject to change. (So beware.)
19304 Details regarding the older, non-standard 64-bit format were
19305 determined empirically by examining 64-bit ELF files produced by
19306 the SGI toolchain on an IRIX 6.5 machine.
19308 - Kevin, July 16, 2002
19312 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19314 LONGEST length
= bfd_get_32 (abfd
, buf
);
19316 if (length
== 0xffffffff)
19318 length
= bfd_get_64 (abfd
, buf
+ 4);
19321 else if (length
== 0)
19323 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19324 length
= bfd_get_64 (abfd
, buf
);
19335 /* Cover function for read_initial_length.
19336 Returns the length of the object at BUF, and stores the size of the
19337 initial length in *BYTES_READ and stores the size that offsets will be in
19339 If the initial length size is not equivalent to that specified in
19340 CU_HEADER then issue a complaint.
19341 This is useful when reading non-comp-unit headers. */
19344 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19345 const struct comp_unit_head
*cu_header
,
19346 unsigned int *bytes_read
,
19347 unsigned int *offset_size
)
19349 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19351 gdb_assert (cu_header
->initial_length_size
== 4
19352 || cu_header
->initial_length_size
== 8
19353 || cu_header
->initial_length_size
== 12);
19355 if (cu_header
->initial_length_size
!= *bytes_read
)
19356 complaint (&symfile_complaints
,
19357 _("intermixed 32-bit and 64-bit DWARF sections"));
19359 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19363 /* Read an offset from the data stream. The size of the offset is
19364 given by cu_header->offset_size. */
19367 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19368 const struct comp_unit_head
*cu_header
,
19369 unsigned int *bytes_read
)
19371 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19373 *bytes_read
= cu_header
->offset_size
;
19377 /* Read an offset from the data stream. */
19380 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19382 LONGEST retval
= 0;
19384 switch (offset_size
)
19387 retval
= bfd_get_32 (abfd
, buf
);
19390 retval
= bfd_get_64 (abfd
, buf
);
19393 internal_error (__FILE__
, __LINE__
,
19394 _("read_offset_1: bad switch [in module %s]"),
19395 bfd_get_filename (abfd
));
19401 static const gdb_byte
*
19402 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19404 /* If the size of a host char is 8 bits, we can return a pointer
19405 to the buffer, otherwise we have to copy the data to a buffer
19406 allocated on the temporary obstack. */
19407 gdb_assert (HOST_CHAR_BIT
== 8);
19411 static const char *
19412 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19413 unsigned int *bytes_read_ptr
)
19415 /* If the size of a host char is 8 bits, we can return a pointer
19416 to the string, otherwise we have to copy the string to a buffer
19417 allocated on the temporary obstack. */
19418 gdb_assert (HOST_CHAR_BIT
== 8);
19421 *bytes_read_ptr
= 1;
19424 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19425 return (const char *) buf
;
19428 /* Return pointer to string at section SECT offset STR_OFFSET with error
19429 reporting strings FORM_NAME and SECT_NAME. */
19431 static const char *
19432 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19433 bfd
*abfd
, LONGEST str_offset
,
19434 struct dwarf2_section_info
*sect
,
19435 const char *form_name
,
19436 const char *sect_name
)
19438 dwarf2_read_section (objfile
, sect
);
19439 if (sect
->buffer
== NULL
)
19440 error (_("%s used without %s section [in module %s]"),
19441 form_name
, sect_name
, bfd_get_filename (abfd
));
19442 if (str_offset
>= sect
->size
)
19443 error (_("%s pointing outside of %s section [in module %s]"),
19444 form_name
, sect_name
, bfd_get_filename (abfd
));
19445 gdb_assert (HOST_CHAR_BIT
== 8);
19446 if (sect
->buffer
[str_offset
] == '\0')
19448 return (const char *) (sect
->buffer
+ str_offset
);
19451 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19453 static const char *
19454 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19455 bfd
*abfd
, LONGEST str_offset
)
19457 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19459 &dwarf2_per_objfile
->str
,
19460 "DW_FORM_strp", ".debug_str");
19463 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19465 static const char *
19466 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19467 bfd
*abfd
, LONGEST str_offset
)
19469 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19471 &dwarf2_per_objfile
->line_str
,
19472 "DW_FORM_line_strp",
19473 ".debug_line_str");
19476 /* Read a string at offset STR_OFFSET in the .debug_str section from
19477 the .dwz file DWZ. Throw an error if the offset is too large. If
19478 the string consists of a single NUL byte, return NULL; otherwise
19479 return a pointer to the string. */
19481 static const char *
19482 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19483 LONGEST str_offset
)
19485 dwarf2_read_section (objfile
, &dwz
->str
);
19487 if (dwz
->str
.buffer
== NULL
)
19488 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19489 "section [in module %s]"),
19490 bfd_get_filename (dwz
->dwz_bfd
));
19491 if (str_offset
>= dwz
->str
.size
)
19492 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19493 ".debug_str section [in module %s]"),
19494 bfd_get_filename (dwz
->dwz_bfd
));
19495 gdb_assert (HOST_CHAR_BIT
== 8);
19496 if (dwz
->str
.buffer
[str_offset
] == '\0')
19498 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19501 /* Return pointer to string at .debug_str offset as read from BUF.
19502 BUF is assumed to be in a compilation unit described by CU_HEADER.
19503 Return *BYTES_READ_PTR count of bytes read from BUF. */
19505 static const char *
19506 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19507 const gdb_byte
*buf
,
19508 const struct comp_unit_head
*cu_header
,
19509 unsigned int *bytes_read_ptr
)
19511 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19513 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19516 /* Return pointer to string at .debug_line_str offset as read from BUF.
19517 BUF is assumed to be in a compilation unit described by CU_HEADER.
19518 Return *BYTES_READ_PTR count of bytes read from BUF. */
19520 static const char *
19521 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19522 bfd
*abfd
, const gdb_byte
*buf
,
19523 const struct comp_unit_head
*cu_header
,
19524 unsigned int *bytes_read_ptr
)
19526 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19528 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19533 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19534 unsigned int *bytes_read_ptr
)
19537 unsigned int num_read
;
19539 unsigned char byte
;
19546 byte
= bfd_get_8 (abfd
, buf
);
19549 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19550 if ((byte
& 128) == 0)
19556 *bytes_read_ptr
= num_read
;
19561 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19562 unsigned int *bytes_read_ptr
)
19565 int shift
, num_read
;
19566 unsigned char byte
;
19573 byte
= bfd_get_8 (abfd
, buf
);
19576 result
|= ((LONGEST
) (byte
& 127) << shift
);
19578 if ((byte
& 128) == 0)
19583 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19584 result
|= -(((LONGEST
) 1) << shift
);
19585 *bytes_read_ptr
= num_read
;
19589 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19590 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
19591 ADDR_SIZE is the size of addresses from the CU header. */
19594 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19595 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
19597 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19598 bfd
*abfd
= objfile
->obfd
;
19599 const gdb_byte
*info_ptr
;
19601 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
19602 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19603 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19604 objfile_name (objfile
));
19605 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
19606 error (_("DW_FORM_addr_index pointing outside of "
19607 ".debug_addr section [in module %s]"),
19608 objfile_name (objfile
));
19609 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19610 + addr_base
+ addr_index
* addr_size
);
19611 if (addr_size
== 4)
19612 return bfd_get_32 (abfd
, info_ptr
);
19614 return bfd_get_64 (abfd
, info_ptr
);
19617 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19620 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19622 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19623 cu
->addr_base
, cu
->header
.addr_size
);
19626 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19629 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19630 unsigned int *bytes_read
)
19632 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19633 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19635 return read_addr_index (cu
, addr_index
);
19638 /* Data structure to pass results from dwarf2_read_addr_index_reader
19639 back to dwarf2_read_addr_index. */
19641 struct dwarf2_read_addr_index_data
19643 ULONGEST addr_base
;
19647 /* die_reader_func for dwarf2_read_addr_index. */
19650 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
19651 const gdb_byte
*info_ptr
,
19652 struct die_info
*comp_unit_die
,
19656 struct dwarf2_cu
*cu
= reader
->cu
;
19657 struct dwarf2_read_addr_index_data
*aidata
=
19658 (struct dwarf2_read_addr_index_data
*) data
;
19660 aidata
->addr_base
= cu
->addr_base
;
19661 aidata
->addr_size
= cu
->header
.addr_size
;
19664 /* Given an index in .debug_addr, fetch the value.
19665 NOTE: This can be called during dwarf expression evaluation,
19666 long after the debug information has been read, and thus per_cu->cu
19667 may no longer exist. */
19670 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19671 unsigned int addr_index
)
19673 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19674 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19675 struct dwarf2_cu
*cu
= per_cu
->cu
;
19676 ULONGEST addr_base
;
19679 /* We need addr_base and addr_size.
19680 If we don't have PER_CU->cu, we have to get it.
19681 Nasty, but the alternative is storing the needed info in PER_CU,
19682 which at this point doesn't seem justified: it's not clear how frequently
19683 it would get used and it would increase the size of every PER_CU.
19684 Entry points like dwarf2_per_cu_addr_size do a similar thing
19685 so we're not in uncharted territory here.
19686 Alas we need to be a bit more complicated as addr_base is contained
19689 We don't need to read the entire CU(/TU).
19690 We just need the header and top level die.
19692 IWBN to use the aging mechanism to let us lazily later discard the CU.
19693 For now we skip this optimization. */
19697 addr_base
= cu
->addr_base
;
19698 addr_size
= cu
->header
.addr_size
;
19702 struct dwarf2_read_addr_index_data aidata
;
19704 /* Note: We can't use init_cutu_and_read_dies_simple here,
19705 we need addr_base. */
19706 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
19707 dwarf2_read_addr_index_reader
, &aidata
);
19708 addr_base
= aidata
.addr_base
;
19709 addr_size
= aidata
.addr_size
;
19712 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19716 /* Given a DW_FORM_GNU_str_index, fetch the string.
19717 This is only used by the Fission support. */
19719 static const char *
19720 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19722 struct dwarf2_cu
*cu
= reader
->cu
;
19723 struct dwarf2_per_objfile
*dwarf2_per_objfile
19724 = cu
->per_cu
->dwarf2_per_objfile
;
19725 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19726 const char *objf_name
= objfile_name (objfile
);
19727 bfd
*abfd
= objfile
->obfd
;
19728 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
19729 struct dwarf2_section_info
*str_offsets_section
=
19730 &reader
->dwo_file
->sections
.str_offsets
;
19731 const gdb_byte
*info_ptr
;
19732 ULONGEST str_offset
;
19733 static const char form_name
[] = "DW_FORM_GNU_str_index";
19735 dwarf2_read_section (objfile
, str_section
);
19736 dwarf2_read_section (objfile
, str_offsets_section
);
19737 if (str_section
->buffer
== NULL
)
19738 error (_("%s used without .debug_str.dwo section"
19739 " in CU at offset %s [in module %s]"),
19740 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19741 if (str_offsets_section
->buffer
== NULL
)
19742 error (_("%s used without .debug_str_offsets.dwo section"
19743 " in CU at offset %s [in module %s]"),
19744 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19745 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
19746 error (_("%s pointing outside of .debug_str_offsets.dwo"
19747 " section in CU at offset %s [in module %s]"),
19748 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19749 info_ptr
= (str_offsets_section
->buffer
19750 + str_index
* cu
->header
.offset_size
);
19751 if (cu
->header
.offset_size
== 4)
19752 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19754 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19755 if (str_offset
>= str_section
->size
)
19756 error (_("Offset from %s pointing outside of"
19757 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19758 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19759 return (const char *) (str_section
->buffer
+ str_offset
);
19762 /* Return the length of an LEB128 number in BUF. */
19765 leb128_size (const gdb_byte
*buf
)
19767 const gdb_byte
*begin
= buf
;
19773 if ((byte
& 128) == 0)
19774 return buf
- begin
;
19779 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19788 cu
->language
= language_c
;
19791 case DW_LANG_C_plus_plus
:
19792 case DW_LANG_C_plus_plus_11
:
19793 case DW_LANG_C_plus_plus_14
:
19794 cu
->language
= language_cplus
;
19797 cu
->language
= language_d
;
19799 case DW_LANG_Fortran77
:
19800 case DW_LANG_Fortran90
:
19801 case DW_LANG_Fortran95
:
19802 case DW_LANG_Fortran03
:
19803 case DW_LANG_Fortran08
:
19804 cu
->language
= language_fortran
;
19807 cu
->language
= language_go
;
19809 case DW_LANG_Mips_Assembler
:
19810 cu
->language
= language_asm
;
19812 case DW_LANG_Ada83
:
19813 case DW_LANG_Ada95
:
19814 cu
->language
= language_ada
;
19816 case DW_LANG_Modula2
:
19817 cu
->language
= language_m2
;
19819 case DW_LANG_Pascal83
:
19820 cu
->language
= language_pascal
;
19823 cu
->language
= language_objc
;
19826 case DW_LANG_Rust_old
:
19827 cu
->language
= language_rust
;
19829 case DW_LANG_Cobol74
:
19830 case DW_LANG_Cobol85
:
19832 cu
->language
= language_minimal
;
19835 cu
->language_defn
= language_def (cu
->language
);
19838 /* Return the named attribute or NULL if not there. */
19840 static struct attribute
*
19841 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19846 struct attribute
*spec
= NULL
;
19848 for (i
= 0; i
< die
->num_attrs
; ++i
)
19850 if (die
->attrs
[i
].name
== name
)
19851 return &die
->attrs
[i
];
19852 if (die
->attrs
[i
].name
== DW_AT_specification
19853 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19854 spec
= &die
->attrs
[i
];
19860 die
= follow_die_ref (die
, spec
, &cu
);
19866 /* Return the named attribute or NULL if not there,
19867 but do not follow DW_AT_specification, etc.
19868 This is for use in contexts where we're reading .debug_types dies.
19869 Following DW_AT_specification, DW_AT_abstract_origin will take us
19870 back up the chain, and we want to go down. */
19872 static struct attribute
*
19873 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19877 for (i
= 0; i
< die
->num_attrs
; ++i
)
19878 if (die
->attrs
[i
].name
== name
)
19879 return &die
->attrs
[i
];
19884 /* Return the string associated with a string-typed attribute, or NULL if it
19885 is either not found or is of an incorrect type. */
19887 static const char *
19888 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19890 struct attribute
*attr
;
19891 const char *str
= NULL
;
19893 attr
= dwarf2_attr (die
, name
, cu
);
19897 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19898 || attr
->form
== DW_FORM_string
19899 || attr
->form
== DW_FORM_GNU_str_index
19900 || attr
->form
== DW_FORM_GNU_strp_alt
)
19901 str
= DW_STRING (attr
);
19903 complaint (&symfile_complaints
,
19904 _("string type expected for attribute %s for "
19905 "DIE at %s in module %s"),
19906 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19907 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19913 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19914 and holds a non-zero value. This function should only be used for
19915 DW_FORM_flag or DW_FORM_flag_present attributes. */
19918 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19920 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19922 return (attr
&& DW_UNSND (attr
));
19926 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19928 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19929 which value is non-zero. However, we have to be careful with
19930 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19931 (via dwarf2_flag_true_p) follows this attribute. So we may
19932 end up accidently finding a declaration attribute that belongs
19933 to a different DIE referenced by the specification attribute,
19934 even though the given DIE does not have a declaration attribute. */
19935 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19936 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19939 /* Return the die giving the specification for DIE, if there is
19940 one. *SPEC_CU is the CU containing DIE on input, and the CU
19941 containing the return value on output. If there is no
19942 specification, but there is an abstract origin, that is
19945 static struct die_info
*
19946 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19948 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19951 if (spec_attr
== NULL
)
19952 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19954 if (spec_attr
== NULL
)
19957 return follow_die_ref (die
, spec_attr
, spec_cu
);
19960 /* Stub for free_line_header to match void * callback types. */
19963 free_line_header_voidp (void *arg
)
19965 struct line_header
*lh
= (struct line_header
*) arg
;
19971 line_header::add_include_dir (const char *include_dir
)
19973 if (dwarf_line_debug
>= 2)
19974 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
19975 include_dirs
.size () + 1, include_dir
);
19977 include_dirs
.push_back (include_dir
);
19981 line_header::add_file_name (const char *name
,
19983 unsigned int mod_time
,
19984 unsigned int length
)
19986 if (dwarf_line_debug
>= 2)
19987 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
19988 (unsigned) file_names
.size () + 1, name
);
19990 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
19993 /* A convenience function to find the proper .debug_line section for a CU. */
19995 static struct dwarf2_section_info
*
19996 get_debug_line_section (struct dwarf2_cu
*cu
)
19998 struct dwarf2_section_info
*section
;
19999 struct dwarf2_per_objfile
*dwarf2_per_objfile
20000 = cu
->per_cu
->dwarf2_per_objfile
;
20002 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20004 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20005 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20006 else if (cu
->per_cu
->is_dwz
)
20008 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20010 section
= &dwz
->line
;
20013 section
= &dwarf2_per_objfile
->line
;
20018 /* Read directory or file name entry format, starting with byte of
20019 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20020 entries count and the entries themselves in the described entry
20024 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20025 bfd
*abfd
, const gdb_byte
**bufp
,
20026 struct line_header
*lh
,
20027 const struct comp_unit_head
*cu_header
,
20028 void (*callback
) (struct line_header
*lh
,
20031 unsigned int mod_time
,
20032 unsigned int length
))
20034 gdb_byte format_count
, formati
;
20035 ULONGEST data_count
, datai
;
20036 const gdb_byte
*buf
= *bufp
;
20037 const gdb_byte
*format_header_data
;
20038 unsigned int bytes_read
;
20040 format_count
= read_1_byte (abfd
, buf
);
20042 format_header_data
= buf
;
20043 for (formati
= 0; formati
< format_count
; formati
++)
20045 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20047 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20051 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20053 for (datai
= 0; datai
< data_count
; datai
++)
20055 const gdb_byte
*format
= format_header_data
;
20056 struct file_entry fe
;
20058 for (formati
= 0; formati
< format_count
; formati
++)
20060 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20061 format
+= bytes_read
;
20063 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20064 format
+= bytes_read
;
20066 gdb::optional
<const char *> string
;
20067 gdb::optional
<unsigned int> uint
;
20071 case DW_FORM_string
:
20072 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20076 case DW_FORM_line_strp
:
20077 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20084 case DW_FORM_data1
:
20085 uint
.emplace (read_1_byte (abfd
, buf
));
20089 case DW_FORM_data2
:
20090 uint
.emplace (read_2_bytes (abfd
, buf
));
20094 case DW_FORM_data4
:
20095 uint
.emplace (read_4_bytes (abfd
, buf
));
20099 case DW_FORM_data8
:
20100 uint
.emplace (read_8_bytes (abfd
, buf
));
20104 case DW_FORM_udata
:
20105 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20109 case DW_FORM_block
:
20110 /* It is valid only for DW_LNCT_timestamp which is ignored by
20115 switch (content_type
)
20118 if (string
.has_value ())
20121 case DW_LNCT_directory_index
:
20122 if (uint
.has_value ())
20123 fe
.d_index
= (dir_index
) *uint
;
20125 case DW_LNCT_timestamp
:
20126 if (uint
.has_value ())
20127 fe
.mod_time
= *uint
;
20130 if (uint
.has_value ())
20136 complaint (&symfile_complaints
,
20137 _("Unknown format content type %s"),
20138 pulongest (content_type
));
20142 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20148 /* Read the statement program header starting at OFFSET in
20149 .debug_line, or .debug_line.dwo. Return a pointer
20150 to a struct line_header, allocated using xmalloc.
20151 Returns NULL if there is a problem reading the header, e.g., if it
20152 has a version we don't understand.
20154 NOTE: the strings in the include directory and file name tables of
20155 the returned object point into the dwarf line section buffer,
20156 and must not be freed. */
20158 static line_header_up
20159 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20161 const gdb_byte
*line_ptr
;
20162 unsigned int bytes_read
, offset_size
;
20164 const char *cur_dir
, *cur_file
;
20165 struct dwarf2_section_info
*section
;
20167 struct dwarf2_per_objfile
*dwarf2_per_objfile
20168 = cu
->per_cu
->dwarf2_per_objfile
;
20170 section
= get_debug_line_section (cu
);
20171 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20172 if (section
->buffer
== NULL
)
20174 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20175 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
20177 complaint (&symfile_complaints
, _("missing .debug_line section"));
20181 /* We can't do this until we know the section is non-empty.
20182 Only then do we know we have such a section. */
20183 abfd
= get_section_bfd_owner (section
);
20185 /* Make sure that at least there's room for the total_length field.
20186 That could be 12 bytes long, but we're just going to fudge that. */
20187 if (to_underlying (sect_off
) + 4 >= section
->size
)
20189 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20193 line_header_up
lh (new line_header ());
20195 lh
->sect_off
= sect_off
;
20196 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20198 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20200 /* Read in the header. */
20202 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20203 &bytes_read
, &offset_size
);
20204 line_ptr
+= bytes_read
;
20205 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20207 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20210 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20211 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20213 if (lh
->version
> 5)
20215 /* This is a version we don't understand. The format could have
20216 changed in ways we don't handle properly so just punt. */
20217 complaint (&symfile_complaints
,
20218 _("unsupported version in .debug_line section"));
20221 if (lh
->version
>= 5)
20223 gdb_byte segment_selector_size
;
20225 /* Skip address size. */
20226 read_1_byte (abfd
, line_ptr
);
20229 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20231 if (segment_selector_size
!= 0)
20233 complaint (&symfile_complaints
,
20234 _("unsupported segment selector size %u "
20235 "in .debug_line section"),
20236 segment_selector_size
);
20240 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20241 line_ptr
+= offset_size
;
20242 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20244 if (lh
->version
>= 4)
20246 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20250 lh
->maximum_ops_per_instruction
= 1;
20252 if (lh
->maximum_ops_per_instruction
== 0)
20254 lh
->maximum_ops_per_instruction
= 1;
20255 complaint (&symfile_complaints
,
20256 _("invalid maximum_ops_per_instruction "
20257 "in `.debug_line' section"));
20260 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20262 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20264 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20266 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20268 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20270 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20271 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20273 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20277 if (lh
->version
>= 5)
20279 /* Read directory table. */
20280 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20282 [] (struct line_header
*lh
, const char *name
,
20283 dir_index d_index
, unsigned int mod_time
,
20284 unsigned int length
)
20286 lh
->add_include_dir (name
);
20289 /* Read file name table. */
20290 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20292 [] (struct line_header
*lh
, const char *name
,
20293 dir_index d_index
, unsigned int mod_time
,
20294 unsigned int length
)
20296 lh
->add_file_name (name
, d_index
, mod_time
, length
);
20301 /* Read directory table. */
20302 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20304 line_ptr
+= bytes_read
;
20305 lh
->add_include_dir (cur_dir
);
20307 line_ptr
+= bytes_read
;
20309 /* Read file name table. */
20310 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20312 unsigned int mod_time
, length
;
20315 line_ptr
+= bytes_read
;
20316 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20317 line_ptr
+= bytes_read
;
20318 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20319 line_ptr
+= bytes_read
;
20320 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20321 line_ptr
+= bytes_read
;
20323 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20325 line_ptr
+= bytes_read
;
20327 lh
->statement_program_start
= line_ptr
;
20329 if (line_ptr
> (section
->buffer
+ section
->size
))
20330 complaint (&symfile_complaints
,
20331 _("line number info header doesn't "
20332 "fit in `.debug_line' section"));
20337 /* Subroutine of dwarf_decode_lines to simplify it.
20338 Return the file name of the psymtab for included file FILE_INDEX
20339 in line header LH of PST.
20340 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20341 If space for the result is malloc'd, *NAME_HOLDER will be set.
20342 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20344 static const char *
20345 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20346 const struct partial_symtab
*pst
,
20347 const char *comp_dir
,
20348 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20350 const file_entry
&fe
= lh
->file_names
[file_index
];
20351 const char *include_name
= fe
.name
;
20352 const char *include_name_to_compare
= include_name
;
20353 const char *pst_filename
;
20356 const char *dir_name
= fe
.include_dir (lh
);
20358 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20359 if (!IS_ABSOLUTE_PATH (include_name
)
20360 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20362 /* Avoid creating a duplicate psymtab for PST.
20363 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20364 Before we do the comparison, however, we need to account
20365 for DIR_NAME and COMP_DIR.
20366 First prepend dir_name (if non-NULL). If we still don't
20367 have an absolute path prepend comp_dir (if non-NULL).
20368 However, the directory we record in the include-file's
20369 psymtab does not contain COMP_DIR (to match the
20370 corresponding symtab(s)).
20375 bash$ gcc -g ./hello.c
20376 include_name = "hello.c"
20378 DW_AT_comp_dir = comp_dir = "/tmp"
20379 DW_AT_name = "./hello.c"
20383 if (dir_name
!= NULL
)
20385 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20386 include_name
, (char *) NULL
));
20387 include_name
= name_holder
->get ();
20388 include_name_to_compare
= include_name
;
20390 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20392 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20393 include_name
, (char *) NULL
));
20394 include_name_to_compare
= hold_compare
.get ();
20398 pst_filename
= pst
->filename
;
20399 gdb::unique_xmalloc_ptr
<char> copied_name
;
20400 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20402 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20403 pst_filename
, (char *) NULL
));
20404 pst_filename
= copied_name
.get ();
20407 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20411 return include_name
;
20414 /* State machine to track the state of the line number program. */
20416 class lnp_state_machine
20419 /* Initialize a machine state for the start of a line number
20421 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
20423 file_entry
*current_file ()
20425 /* lh->file_names is 0-based, but the file name numbers in the
20426 statement program are 1-based. */
20427 return m_line_header
->file_name_at (m_file
);
20430 /* Record the line in the state machine. END_SEQUENCE is true if
20431 we're processing the end of a sequence. */
20432 void record_line (bool end_sequence
);
20434 /* Check address and if invalid nop-out the rest of the lines in this
20436 void check_line_address (struct dwarf2_cu
*cu
,
20437 const gdb_byte
*line_ptr
,
20438 CORE_ADDR lowpc
, CORE_ADDR address
);
20440 void handle_set_discriminator (unsigned int discriminator
)
20442 m_discriminator
= discriminator
;
20443 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20446 /* Handle DW_LNE_set_address. */
20447 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20450 address
+= baseaddr
;
20451 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20454 /* Handle DW_LNS_advance_pc. */
20455 void handle_advance_pc (CORE_ADDR adjust
);
20457 /* Handle a special opcode. */
20458 void handle_special_opcode (unsigned char op_code
);
20460 /* Handle DW_LNS_advance_line. */
20461 void handle_advance_line (int line_delta
)
20463 advance_line (line_delta
);
20466 /* Handle DW_LNS_set_file. */
20467 void handle_set_file (file_name_index file
);
20469 /* Handle DW_LNS_negate_stmt. */
20470 void handle_negate_stmt ()
20472 m_is_stmt
= !m_is_stmt
;
20475 /* Handle DW_LNS_const_add_pc. */
20476 void handle_const_add_pc ();
20478 /* Handle DW_LNS_fixed_advance_pc. */
20479 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20481 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20485 /* Handle DW_LNS_copy. */
20486 void handle_copy ()
20488 record_line (false);
20489 m_discriminator
= 0;
20492 /* Handle DW_LNE_end_sequence. */
20493 void handle_end_sequence ()
20495 m_record_line_callback
= ::record_line
;
20499 /* Advance the line by LINE_DELTA. */
20500 void advance_line (int line_delta
)
20502 m_line
+= line_delta
;
20504 if (line_delta
!= 0)
20505 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20508 gdbarch
*m_gdbarch
;
20510 /* True if we're recording lines.
20511 Otherwise we're building partial symtabs and are just interested in
20512 finding include files mentioned by the line number program. */
20513 bool m_record_lines_p
;
20515 /* The line number header. */
20516 line_header
*m_line_header
;
20518 /* These are part of the standard DWARF line number state machine,
20519 and initialized according to the DWARF spec. */
20521 unsigned char m_op_index
= 0;
20522 /* The line table index (1-based) of the current file. */
20523 file_name_index m_file
= (file_name_index
) 1;
20524 unsigned int m_line
= 1;
20526 /* These are initialized in the constructor. */
20528 CORE_ADDR m_address
;
20530 unsigned int m_discriminator
;
20532 /* Additional bits of state we need to track. */
20534 /* The last file that we called dwarf2_start_subfile for.
20535 This is only used for TLLs. */
20536 unsigned int m_last_file
= 0;
20537 /* The last file a line number was recorded for. */
20538 struct subfile
*m_last_subfile
= NULL
;
20540 /* The function to call to record a line. */
20541 record_line_ftype
*m_record_line_callback
= NULL
;
20543 /* The last line number that was recorded, used to coalesce
20544 consecutive entries for the same line. This can happen, for
20545 example, when discriminators are present. PR 17276. */
20546 unsigned int m_last_line
= 0;
20547 bool m_line_has_non_zero_discriminator
= false;
20551 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20553 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20554 / m_line_header
->maximum_ops_per_instruction
)
20555 * m_line_header
->minimum_instruction_length
);
20556 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20557 m_op_index
= ((m_op_index
+ adjust
)
20558 % m_line_header
->maximum_ops_per_instruction
);
20562 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20564 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20565 CORE_ADDR addr_adj
= (((m_op_index
20566 + (adj_opcode
/ m_line_header
->line_range
))
20567 / m_line_header
->maximum_ops_per_instruction
)
20568 * m_line_header
->minimum_instruction_length
);
20569 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20570 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20571 % m_line_header
->maximum_ops_per_instruction
);
20573 int line_delta
= (m_line_header
->line_base
20574 + (adj_opcode
% m_line_header
->line_range
));
20575 advance_line (line_delta
);
20576 record_line (false);
20577 m_discriminator
= 0;
20581 lnp_state_machine::handle_set_file (file_name_index file
)
20585 const file_entry
*fe
= current_file ();
20587 dwarf2_debug_line_missing_file_complaint ();
20588 else if (m_record_lines_p
)
20590 const char *dir
= fe
->include_dir (m_line_header
);
20592 m_last_subfile
= current_subfile
;
20593 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20594 dwarf2_start_subfile (fe
->name
, dir
);
20599 lnp_state_machine::handle_const_add_pc ()
20602 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20605 = (((m_op_index
+ adjust
)
20606 / m_line_header
->maximum_ops_per_instruction
)
20607 * m_line_header
->minimum_instruction_length
);
20609 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20610 m_op_index
= ((m_op_index
+ adjust
)
20611 % m_line_header
->maximum_ops_per_instruction
);
20614 /* Ignore this record_line request. */
20617 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
20622 /* Return non-zero if we should add LINE to the line number table.
20623 LINE is the line to add, LAST_LINE is the last line that was added,
20624 LAST_SUBFILE is the subfile for LAST_LINE.
20625 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20626 had a non-zero discriminator.
20628 We have to be careful in the presence of discriminators.
20629 E.g., for this line:
20631 for (i = 0; i < 100000; i++);
20633 clang can emit four line number entries for that one line,
20634 each with a different discriminator.
20635 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20637 However, we want gdb to coalesce all four entries into one.
20638 Otherwise the user could stepi into the middle of the line and
20639 gdb would get confused about whether the pc really was in the
20640 middle of the line.
20642 Things are further complicated by the fact that two consecutive
20643 line number entries for the same line is a heuristic used by gcc
20644 to denote the end of the prologue. So we can't just discard duplicate
20645 entries, we have to be selective about it. The heuristic we use is
20646 that we only collapse consecutive entries for the same line if at least
20647 one of those entries has a non-zero discriminator. PR 17276.
20649 Note: Addresses in the line number state machine can never go backwards
20650 within one sequence, thus this coalescing is ok. */
20653 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
20654 int line_has_non_zero_discriminator
,
20655 struct subfile
*last_subfile
)
20657 if (current_subfile
!= last_subfile
)
20659 if (line
!= last_line
)
20661 /* Same line for the same file that we've seen already.
20662 As a last check, for pr 17276, only record the line if the line
20663 has never had a non-zero discriminator. */
20664 if (!line_has_non_zero_discriminator
)
20669 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
20670 in the line table of subfile SUBFILE. */
20673 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20674 unsigned int line
, CORE_ADDR address
,
20675 record_line_ftype p_record_line
)
20677 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20679 if (dwarf_line_debug
)
20681 fprintf_unfiltered (gdb_stdlog
,
20682 "Recording line %u, file %s, address %s\n",
20683 line
, lbasename (subfile
->name
),
20684 paddress (gdbarch
, address
));
20687 (*p_record_line
) (subfile
, line
, addr
);
20690 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20691 Mark the end of a set of line number records.
20692 The arguments are the same as for dwarf_record_line_1.
20693 If SUBFILE is NULL the request is ignored. */
20696 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20697 CORE_ADDR address
, record_line_ftype p_record_line
)
20699 if (subfile
== NULL
)
20702 if (dwarf_line_debug
)
20704 fprintf_unfiltered (gdb_stdlog
,
20705 "Finishing current line, file %s, address %s\n",
20706 lbasename (subfile
->name
),
20707 paddress (gdbarch
, address
));
20710 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
20714 lnp_state_machine::record_line (bool end_sequence
)
20716 if (dwarf_line_debug
)
20718 fprintf_unfiltered (gdb_stdlog
,
20719 "Processing actual line %u: file %u,"
20720 " address %s, is_stmt %u, discrim %u\n",
20721 m_line
, to_underlying (m_file
),
20722 paddress (m_gdbarch
, m_address
),
20723 m_is_stmt
, m_discriminator
);
20726 file_entry
*fe
= current_file ();
20729 dwarf2_debug_line_missing_file_complaint ();
20730 /* For now we ignore lines not starting on an instruction boundary.
20731 But not when processing end_sequence for compatibility with the
20732 previous version of the code. */
20733 else if (m_op_index
== 0 || end_sequence
)
20735 fe
->included_p
= 1;
20736 if (m_record_lines_p
&& m_is_stmt
)
20738 if (m_last_subfile
!= current_subfile
|| end_sequence
)
20740 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
20741 m_address
, m_record_line_callback
);
20746 if (dwarf_record_line_p (m_line
, m_last_line
,
20747 m_line_has_non_zero_discriminator
,
20750 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
20752 m_record_line_callback
);
20754 m_last_subfile
= current_subfile
;
20755 m_last_line
= m_line
;
20761 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
20762 bool record_lines_p
)
20765 m_record_lines_p
= record_lines_p
;
20766 m_line_header
= lh
;
20768 m_record_line_callback
= ::record_line
;
20770 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20771 was a line entry for it so that the backend has a chance to adjust it
20772 and also record it in case it needs it. This is currently used by MIPS
20773 code, cf. `mips_adjust_dwarf2_line'. */
20774 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20775 m_is_stmt
= lh
->default_is_stmt
;
20776 m_discriminator
= 0;
20780 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20781 const gdb_byte
*line_ptr
,
20782 CORE_ADDR lowpc
, CORE_ADDR address
)
20784 /* If address < lowpc then it's not a usable value, it's outside the
20785 pc range of the CU. However, we restrict the test to only address
20786 values of zero to preserve GDB's previous behaviour which is to
20787 handle the specific case of a function being GC'd by the linker. */
20789 if (address
== 0 && address
< lowpc
)
20791 /* This line table is for a function which has been
20792 GCd by the linker. Ignore it. PR gdb/12528 */
20794 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20795 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20797 complaint (&symfile_complaints
,
20798 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20799 line_offset
, objfile_name (objfile
));
20800 m_record_line_callback
= noop_record_line
;
20801 /* Note: record_line_callback is left as noop_record_line until
20802 we see DW_LNE_end_sequence. */
20806 /* Subroutine of dwarf_decode_lines to simplify it.
20807 Process the line number information in LH.
20808 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20809 program in order to set included_p for every referenced header. */
20812 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20813 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20815 const gdb_byte
*line_ptr
, *extended_end
;
20816 const gdb_byte
*line_end
;
20817 unsigned int bytes_read
, extended_len
;
20818 unsigned char op_code
, extended_op
;
20819 CORE_ADDR baseaddr
;
20820 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20821 bfd
*abfd
= objfile
->obfd
;
20822 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20823 /* True if we're recording line info (as opposed to building partial
20824 symtabs and just interested in finding include files mentioned by
20825 the line number program). */
20826 bool record_lines_p
= !decode_for_pst_p
;
20828 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
20830 line_ptr
= lh
->statement_program_start
;
20831 line_end
= lh
->statement_program_end
;
20833 /* Read the statement sequences until there's nothing left. */
20834 while (line_ptr
< line_end
)
20836 /* The DWARF line number program state machine. Reset the state
20837 machine at the start of each sequence. */
20838 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
20839 bool end_sequence
= false;
20841 if (record_lines_p
)
20843 /* Start a subfile for the current file of the state
20845 const file_entry
*fe
= state_machine
.current_file ();
20848 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
20851 /* Decode the table. */
20852 while (line_ptr
< line_end
&& !end_sequence
)
20854 op_code
= read_1_byte (abfd
, line_ptr
);
20857 if (op_code
>= lh
->opcode_base
)
20859 /* Special opcode. */
20860 state_machine
.handle_special_opcode (op_code
);
20862 else switch (op_code
)
20864 case DW_LNS_extended_op
:
20865 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20867 line_ptr
+= bytes_read
;
20868 extended_end
= line_ptr
+ extended_len
;
20869 extended_op
= read_1_byte (abfd
, line_ptr
);
20871 switch (extended_op
)
20873 case DW_LNE_end_sequence
:
20874 state_machine
.handle_end_sequence ();
20875 end_sequence
= true;
20877 case DW_LNE_set_address
:
20880 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
20881 line_ptr
+= bytes_read
;
20883 state_machine
.check_line_address (cu
, line_ptr
,
20885 state_machine
.handle_set_address (baseaddr
, address
);
20888 case DW_LNE_define_file
:
20890 const char *cur_file
;
20891 unsigned int mod_time
, length
;
20894 cur_file
= read_direct_string (abfd
, line_ptr
,
20896 line_ptr
+= bytes_read
;
20897 dindex
= (dir_index
)
20898 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20899 line_ptr
+= bytes_read
;
20901 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20902 line_ptr
+= bytes_read
;
20904 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20905 line_ptr
+= bytes_read
;
20906 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20909 case DW_LNE_set_discriminator
:
20911 /* The discriminator is not interesting to the
20912 debugger; just ignore it. We still need to
20913 check its value though:
20914 if there are consecutive entries for the same
20915 (non-prologue) line we want to coalesce them.
20918 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20919 line_ptr
+= bytes_read
;
20921 state_machine
.handle_set_discriminator (discr
);
20925 complaint (&symfile_complaints
,
20926 _("mangled .debug_line section"));
20929 /* Make sure that we parsed the extended op correctly. If e.g.
20930 we expected a different address size than the producer used,
20931 we may have read the wrong number of bytes. */
20932 if (line_ptr
!= extended_end
)
20934 complaint (&symfile_complaints
,
20935 _("mangled .debug_line section"));
20940 state_machine
.handle_copy ();
20942 case DW_LNS_advance_pc
:
20945 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20946 line_ptr
+= bytes_read
;
20948 state_machine
.handle_advance_pc (adjust
);
20951 case DW_LNS_advance_line
:
20954 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20955 line_ptr
+= bytes_read
;
20957 state_machine
.handle_advance_line (line_delta
);
20960 case DW_LNS_set_file
:
20962 file_name_index file
20963 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20965 line_ptr
+= bytes_read
;
20967 state_machine
.handle_set_file (file
);
20970 case DW_LNS_set_column
:
20971 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20972 line_ptr
+= bytes_read
;
20974 case DW_LNS_negate_stmt
:
20975 state_machine
.handle_negate_stmt ();
20977 case DW_LNS_set_basic_block
:
20979 /* Add to the address register of the state machine the
20980 address increment value corresponding to special opcode
20981 255. I.e., this value is scaled by the minimum
20982 instruction length since special opcode 255 would have
20983 scaled the increment. */
20984 case DW_LNS_const_add_pc
:
20985 state_machine
.handle_const_add_pc ();
20987 case DW_LNS_fixed_advance_pc
:
20989 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20992 state_machine
.handle_fixed_advance_pc (addr_adj
);
20997 /* Unknown standard opcode, ignore it. */
21000 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21002 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21003 line_ptr
+= bytes_read
;
21010 dwarf2_debug_line_missing_end_sequence_complaint ();
21012 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21013 in which case we still finish recording the last line). */
21014 state_machine
.record_line (true);
21018 /* Decode the Line Number Program (LNP) for the given line_header
21019 structure and CU. The actual information extracted and the type
21020 of structures created from the LNP depends on the value of PST.
21022 1. If PST is NULL, then this procedure uses the data from the program
21023 to create all necessary symbol tables, and their linetables.
21025 2. If PST is not NULL, this procedure reads the program to determine
21026 the list of files included by the unit represented by PST, and
21027 builds all the associated partial symbol tables.
21029 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21030 It is used for relative paths in the line table.
21031 NOTE: When processing partial symtabs (pst != NULL),
21032 comp_dir == pst->dirname.
21034 NOTE: It is important that psymtabs have the same file name (via strcmp)
21035 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21036 symtab we don't use it in the name of the psymtabs we create.
21037 E.g. expand_line_sal requires this when finding psymtabs to expand.
21038 A good testcase for this is mb-inline.exp.
21040 LOWPC is the lowest address in CU (or 0 if not known).
21042 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21043 for its PC<->lines mapping information. Otherwise only the filename
21044 table is read in. */
21047 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21048 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21049 CORE_ADDR lowpc
, int decode_mapping
)
21051 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21052 const int decode_for_pst_p
= (pst
!= NULL
);
21054 if (decode_mapping
)
21055 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21057 if (decode_for_pst_p
)
21061 /* Now that we're done scanning the Line Header Program, we can
21062 create the psymtab of each included file. */
21063 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
21064 if (lh
->file_names
[file_index
].included_p
== 1)
21066 gdb::unique_xmalloc_ptr
<char> name_holder
;
21067 const char *include_name
=
21068 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
21070 if (include_name
!= NULL
)
21071 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21076 /* Make sure a symtab is created for every file, even files
21077 which contain only variables (i.e. no code with associated
21079 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
21082 for (i
= 0; i
< lh
->file_names
.size (); i
++)
21084 file_entry
&fe
= lh
->file_names
[i
];
21086 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
21088 if (current_subfile
->symtab
== NULL
)
21090 current_subfile
->symtab
21091 = allocate_symtab (cust
, current_subfile
->name
);
21093 fe
.symtab
= current_subfile
->symtab
;
21098 /* Start a subfile for DWARF. FILENAME is the name of the file and
21099 DIRNAME the name of the source directory which contains FILENAME
21100 or NULL if not known.
21101 This routine tries to keep line numbers from identical absolute and
21102 relative file names in a common subfile.
21104 Using the `list' example from the GDB testsuite, which resides in
21105 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21106 of /srcdir/list0.c yields the following debugging information for list0.c:
21108 DW_AT_name: /srcdir/list0.c
21109 DW_AT_comp_dir: /compdir
21110 files.files[0].name: list0.h
21111 files.files[0].dir: /srcdir
21112 files.files[1].name: list0.c
21113 files.files[1].dir: /srcdir
21115 The line number information for list0.c has to end up in a single
21116 subfile, so that `break /srcdir/list0.c:1' works as expected.
21117 start_subfile will ensure that this happens provided that we pass the
21118 concatenation of files.files[1].dir and files.files[1].name as the
21122 dwarf2_start_subfile (const char *filename
, const char *dirname
)
21126 /* In order not to lose the line information directory,
21127 we concatenate it to the filename when it makes sense.
21128 Note that the Dwarf3 standard says (speaking of filenames in line
21129 information): ``The directory index is ignored for file names
21130 that represent full path names''. Thus ignoring dirname in the
21131 `else' branch below isn't an issue. */
21133 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21135 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21139 start_subfile (filename
);
21145 /* Start a symtab for DWARF.
21146 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
21148 static struct compunit_symtab
*
21149 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
21150 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
21152 struct compunit_symtab
*cust
21153 = start_symtab (cu
->per_cu
->dwarf2_per_objfile
->objfile
, name
, comp_dir
,
21154 low_pc
, cu
->language
);
21156 record_debugformat ("DWARF 2");
21157 record_producer (cu
->producer
);
21159 /* We assume that we're processing GCC output. */
21160 processing_gcc_compilation
= 2;
21162 cu
->processing_has_namespace_info
= 0;
21168 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21169 struct dwarf2_cu
*cu
)
21171 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21172 struct comp_unit_head
*cu_header
= &cu
->header
;
21174 /* NOTE drow/2003-01-30: There used to be a comment and some special
21175 code here to turn a symbol with DW_AT_external and a
21176 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21177 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21178 with some versions of binutils) where shared libraries could have
21179 relocations against symbols in their debug information - the
21180 minimal symbol would have the right address, but the debug info
21181 would not. It's no longer necessary, because we will explicitly
21182 apply relocations when we read in the debug information now. */
21184 /* A DW_AT_location attribute with no contents indicates that a
21185 variable has been optimized away. */
21186 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21188 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21192 /* Handle one degenerate form of location expression specially, to
21193 preserve GDB's previous behavior when section offsets are
21194 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
21195 then mark this symbol as LOC_STATIC. */
21197 if (attr_form_is_block (attr
)
21198 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21199 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21200 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21201 && (DW_BLOCK (attr
)->size
21202 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21204 unsigned int dummy
;
21206 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21207 SYMBOL_VALUE_ADDRESS (sym
) =
21208 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
21210 SYMBOL_VALUE_ADDRESS (sym
) =
21211 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
21212 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21213 fixup_symbol_section (sym
, objfile
);
21214 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
21215 SYMBOL_SECTION (sym
));
21219 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21220 expression evaluator, and use LOC_COMPUTED only when necessary
21221 (i.e. when the value of a register or memory location is
21222 referenced, or a thread-local block, etc.). Then again, it might
21223 not be worthwhile. I'm assuming that it isn't unless performance
21224 or memory numbers show me otherwise. */
21226 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21228 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21229 cu
->has_loclist
= 1;
21232 /* Given a pointer to a DWARF information entry, figure out if we need
21233 to make a symbol table entry for it, and if so, create a new entry
21234 and return a pointer to it.
21235 If TYPE is NULL, determine symbol type from the die, otherwise
21236 used the passed type.
21237 If SPACE is not NULL, use it to hold the new symbol. If it is
21238 NULL, allocate a new symbol on the objfile's obstack. */
21240 static struct symbol
*
21241 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21242 struct symbol
*space
)
21244 struct dwarf2_per_objfile
*dwarf2_per_objfile
21245 = cu
->per_cu
->dwarf2_per_objfile
;
21246 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21247 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21248 struct symbol
*sym
= NULL
;
21250 struct attribute
*attr
= NULL
;
21251 struct attribute
*attr2
= NULL
;
21252 CORE_ADDR baseaddr
;
21253 struct pending
**list_to_add
= NULL
;
21255 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21257 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21259 name
= dwarf2_name (die
, cu
);
21262 const char *linkagename
;
21263 int suppress_add
= 0;
21268 sym
= allocate_symbol (objfile
);
21269 OBJSTAT (objfile
, n_syms
++);
21271 /* Cache this symbol's name and the name's demangled form (if any). */
21272 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21273 linkagename
= dwarf2_physname (name
, die
, cu
);
21274 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21276 /* Fortran does not have mangling standard and the mangling does differ
21277 between gfortran, iFort etc. */
21278 if (cu
->language
== language_fortran
21279 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21280 symbol_set_demangled_name (&(sym
->ginfo
),
21281 dwarf2_full_name (name
, die
, cu
),
21284 /* Default assumptions.
21285 Use the passed type or decode it from the die. */
21286 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21287 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21289 SYMBOL_TYPE (sym
) = type
;
21291 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21292 attr
= dwarf2_attr (die
,
21293 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21297 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21300 attr
= dwarf2_attr (die
,
21301 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21305 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21306 struct file_entry
*fe
;
21308 if (cu
->line_header
!= NULL
)
21309 fe
= cu
->line_header
->file_name_at (file_index
);
21314 complaint (&symfile_complaints
,
21315 _("file index out of range"));
21317 symbol_set_symtab (sym
, fe
->symtab
);
21323 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21328 addr
= attr_value_as_address (attr
);
21329 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21330 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
21332 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21333 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21334 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21335 add_symbol_to_list (sym
, cu
->list_in_scope
);
21337 case DW_TAG_subprogram
:
21338 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21340 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21341 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21342 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21343 || cu
->language
== language_ada
)
21345 /* Subprograms marked external are stored as a global symbol.
21346 Ada subprograms, whether marked external or not, are always
21347 stored as a global symbol, because we want to be able to
21348 access them globally. For instance, we want to be able
21349 to break on a nested subprogram without having to
21350 specify the context. */
21351 list_to_add
= &global_symbols
;
21355 list_to_add
= cu
->list_in_scope
;
21358 case DW_TAG_inlined_subroutine
:
21359 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21361 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21362 SYMBOL_INLINED (sym
) = 1;
21363 list_to_add
= cu
->list_in_scope
;
21365 case DW_TAG_template_value_param
:
21367 /* Fall through. */
21368 case DW_TAG_constant
:
21369 case DW_TAG_variable
:
21370 case DW_TAG_member
:
21371 /* Compilation with minimal debug info may result in
21372 variables with missing type entries. Change the
21373 misleading `void' type to something sensible. */
21374 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21375 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21377 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21378 /* In the case of DW_TAG_member, we should only be called for
21379 static const members. */
21380 if (die
->tag
== DW_TAG_member
)
21382 /* dwarf2_add_field uses die_is_declaration,
21383 so we do the same. */
21384 gdb_assert (die_is_declaration (die
, cu
));
21389 dwarf2_const_value (attr
, sym
, cu
);
21390 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21393 if (attr2
&& (DW_UNSND (attr2
) != 0))
21394 list_to_add
= &global_symbols
;
21396 list_to_add
= cu
->list_in_scope
;
21400 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21403 var_decode_location (attr
, sym
, cu
);
21404 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21406 /* Fortran explicitly imports any global symbols to the local
21407 scope by DW_TAG_common_block. */
21408 if (cu
->language
== language_fortran
&& die
->parent
21409 && die
->parent
->tag
== DW_TAG_common_block
)
21412 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21413 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21414 && !dwarf2_per_objfile
->has_section_at_zero
)
21416 /* When a static variable is eliminated by the linker,
21417 the corresponding debug information is not stripped
21418 out, but the variable address is set to null;
21419 do not add such variables into symbol table. */
21421 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21423 /* Workaround gfortran PR debug/40040 - it uses
21424 DW_AT_location for variables in -fPIC libraries which may
21425 get overriden by other libraries/executable and get
21426 a different address. Resolve it by the minimal symbol
21427 which may come from inferior's executable using copy
21428 relocation. Make this workaround only for gfortran as for
21429 other compilers GDB cannot guess the minimal symbol
21430 Fortran mangling kind. */
21431 if (cu
->language
== language_fortran
&& die
->parent
21432 && die
->parent
->tag
== DW_TAG_module
21434 && startswith (cu
->producer
, "GNU Fortran"))
21435 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21437 /* A variable with DW_AT_external is never static,
21438 but it may be block-scoped. */
21439 list_to_add
= (cu
->list_in_scope
== &file_symbols
21440 ? &global_symbols
: cu
->list_in_scope
);
21443 list_to_add
= cu
->list_in_scope
;
21447 /* We do not know the address of this symbol.
21448 If it is an external symbol and we have type information
21449 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21450 The address of the variable will then be determined from
21451 the minimal symbol table whenever the variable is
21453 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21455 /* Fortran explicitly imports any global symbols to the local
21456 scope by DW_TAG_common_block. */
21457 if (cu
->language
== language_fortran
&& die
->parent
21458 && die
->parent
->tag
== DW_TAG_common_block
)
21460 /* SYMBOL_CLASS doesn't matter here because
21461 read_common_block is going to reset it. */
21463 list_to_add
= cu
->list_in_scope
;
21465 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21466 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21468 /* A variable with DW_AT_external is never static, but it
21469 may be block-scoped. */
21470 list_to_add
= (cu
->list_in_scope
== &file_symbols
21471 ? &global_symbols
: cu
->list_in_scope
);
21473 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21475 else if (!die_is_declaration (die
, cu
))
21477 /* Use the default LOC_OPTIMIZED_OUT class. */
21478 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21480 list_to_add
= cu
->list_in_scope
;
21484 case DW_TAG_formal_parameter
:
21485 /* If we are inside a function, mark this as an argument. If
21486 not, we might be looking at an argument to an inlined function
21487 when we do not have enough information to show inlined frames;
21488 pretend it's a local variable in that case so that the user can
21490 if (context_stack_depth
> 0
21491 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
21492 SYMBOL_IS_ARGUMENT (sym
) = 1;
21493 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21496 var_decode_location (attr
, sym
, cu
);
21498 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21501 dwarf2_const_value (attr
, sym
, cu
);
21504 list_to_add
= cu
->list_in_scope
;
21506 case DW_TAG_unspecified_parameters
:
21507 /* From varargs functions; gdb doesn't seem to have any
21508 interest in this information, so just ignore it for now.
21511 case DW_TAG_template_type_param
:
21513 /* Fall through. */
21514 case DW_TAG_class_type
:
21515 case DW_TAG_interface_type
:
21516 case DW_TAG_structure_type
:
21517 case DW_TAG_union_type
:
21518 case DW_TAG_set_type
:
21519 case DW_TAG_enumeration_type
:
21520 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21521 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21524 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21525 really ever be static objects: otherwise, if you try
21526 to, say, break of a class's method and you're in a file
21527 which doesn't mention that class, it won't work unless
21528 the check for all static symbols in lookup_symbol_aux
21529 saves you. See the OtherFileClass tests in
21530 gdb.c++/namespace.exp. */
21534 list_to_add
= (cu
->list_in_scope
== &file_symbols
21535 && cu
->language
== language_cplus
21536 ? &global_symbols
: cu
->list_in_scope
);
21538 /* The semantics of C++ state that "struct foo {
21539 ... }" also defines a typedef for "foo". */
21540 if (cu
->language
== language_cplus
21541 || cu
->language
== language_ada
21542 || cu
->language
== language_d
21543 || cu
->language
== language_rust
)
21545 /* The symbol's name is already allocated along
21546 with this objfile, so we don't need to
21547 duplicate it for the type. */
21548 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21549 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21554 case DW_TAG_typedef
:
21555 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21556 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21557 list_to_add
= cu
->list_in_scope
;
21559 case DW_TAG_base_type
:
21560 case DW_TAG_subrange_type
:
21561 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21562 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21563 list_to_add
= cu
->list_in_scope
;
21565 case DW_TAG_enumerator
:
21566 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21569 dwarf2_const_value (attr
, sym
, cu
);
21572 /* NOTE: carlton/2003-11-10: See comment above in the
21573 DW_TAG_class_type, etc. block. */
21575 list_to_add
= (cu
->list_in_scope
== &file_symbols
21576 && cu
->language
== language_cplus
21577 ? &global_symbols
: cu
->list_in_scope
);
21580 case DW_TAG_imported_declaration
:
21581 case DW_TAG_namespace
:
21582 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21583 list_to_add
= &global_symbols
;
21585 case DW_TAG_module
:
21586 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21587 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21588 list_to_add
= &global_symbols
;
21590 case DW_TAG_common_block
:
21591 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21592 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21593 add_symbol_to_list (sym
, cu
->list_in_scope
);
21596 /* Not a tag we recognize. Hopefully we aren't processing
21597 trash data, but since we must specifically ignore things
21598 we don't recognize, there is nothing else we should do at
21600 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
21601 dwarf_tag_name (die
->tag
));
21607 sym
->hash_next
= objfile
->template_symbols
;
21608 objfile
->template_symbols
= sym
;
21609 list_to_add
= NULL
;
21612 if (list_to_add
!= NULL
)
21613 add_symbol_to_list (sym
, list_to_add
);
21615 /* For the benefit of old versions of GCC, check for anonymous
21616 namespaces based on the demangled name. */
21617 if (!cu
->processing_has_namespace_info
21618 && cu
->language
== language_cplus
)
21619 cp_scan_for_anonymous_namespaces (sym
, objfile
);
21624 /* Given an attr with a DW_FORM_dataN value in host byte order,
21625 zero-extend it as appropriate for the symbol's type. The DWARF
21626 standard (v4) is not entirely clear about the meaning of using
21627 DW_FORM_dataN for a constant with a signed type, where the type is
21628 wider than the data. The conclusion of a discussion on the DWARF
21629 list was that this is unspecified. We choose to always zero-extend
21630 because that is the interpretation long in use by GCC. */
21633 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21634 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21636 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21637 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21638 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21639 LONGEST l
= DW_UNSND (attr
);
21641 if (bits
< sizeof (*value
) * 8)
21643 l
&= ((LONGEST
) 1 << bits
) - 1;
21646 else if (bits
== sizeof (*value
) * 8)
21650 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21651 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21658 /* Read a constant value from an attribute. Either set *VALUE, or if
21659 the value does not fit in *VALUE, set *BYTES - either already
21660 allocated on the objfile obstack, or newly allocated on OBSTACK,
21661 or, set *BATON, if we translated the constant to a location
21665 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21666 const char *name
, struct obstack
*obstack
,
21667 struct dwarf2_cu
*cu
,
21668 LONGEST
*value
, const gdb_byte
**bytes
,
21669 struct dwarf2_locexpr_baton
**baton
)
21671 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21672 struct comp_unit_head
*cu_header
= &cu
->header
;
21673 struct dwarf_block
*blk
;
21674 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21675 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21681 switch (attr
->form
)
21684 case DW_FORM_GNU_addr_index
:
21688 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21689 dwarf2_const_value_length_mismatch_complaint (name
,
21690 cu_header
->addr_size
,
21691 TYPE_LENGTH (type
));
21692 /* Symbols of this form are reasonably rare, so we just
21693 piggyback on the existing location code rather than writing
21694 a new implementation of symbol_computed_ops. */
21695 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21696 (*baton
)->per_cu
= cu
->per_cu
;
21697 gdb_assert ((*baton
)->per_cu
);
21699 (*baton
)->size
= 2 + cu_header
->addr_size
;
21700 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21701 (*baton
)->data
= data
;
21703 data
[0] = DW_OP_addr
;
21704 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21705 byte_order
, DW_ADDR (attr
));
21706 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21709 case DW_FORM_string
:
21711 case DW_FORM_GNU_str_index
:
21712 case DW_FORM_GNU_strp_alt
:
21713 /* DW_STRING is already allocated on the objfile obstack, point
21715 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21717 case DW_FORM_block1
:
21718 case DW_FORM_block2
:
21719 case DW_FORM_block4
:
21720 case DW_FORM_block
:
21721 case DW_FORM_exprloc
:
21722 case DW_FORM_data16
:
21723 blk
= DW_BLOCK (attr
);
21724 if (TYPE_LENGTH (type
) != blk
->size
)
21725 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21726 TYPE_LENGTH (type
));
21727 *bytes
= blk
->data
;
21730 /* The DW_AT_const_value attributes are supposed to carry the
21731 symbol's value "represented as it would be on the target
21732 architecture." By the time we get here, it's already been
21733 converted to host endianness, so we just need to sign- or
21734 zero-extend it as appropriate. */
21735 case DW_FORM_data1
:
21736 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21738 case DW_FORM_data2
:
21739 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21741 case DW_FORM_data4
:
21742 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21744 case DW_FORM_data8
:
21745 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21748 case DW_FORM_sdata
:
21749 case DW_FORM_implicit_const
:
21750 *value
= DW_SND (attr
);
21753 case DW_FORM_udata
:
21754 *value
= DW_UNSND (attr
);
21758 complaint (&symfile_complaints
,
21759 _("unsupported const value attribute form: '%s'"),
21760 dwarf_form_name (attr
->form
));
21767 /* Copy constant value from an attribute to a symbol. */
21770 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21771 struct dwarf2_cu
*cu
)
21773 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21775 const gdb_byte
*bytes
;
21776 struct dwarf2_locexpr_baton
*baton
;
21778 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21779 SYMBOL_PRINT_NAME (sym
),
21780 &objfile
->objfile_obstack
, cu
,
21781 &value
, &bytes
, &baton
);
21785 SYMBOL_LOCATION_BATON (sym
) = baton
;
21786 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21788 else if (bytes
!= NULL
)
21790 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21791 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21795 SYMBOL_VALUE (sym
) = value
;
21796 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21800 /* Return the type of the die in question using its DW_AT_type attribute. */
21802 static struct type
*
21803 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21805 struct attribute
*type_attr
;
21807 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21810 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21811 /* A missing DW_AT_type represents a void type. */
21812 return objfile_type (objfile
)->builtin_void
;
21815 return lookup_die_type (die
, type_attr
, cu
);
21818 /* True iff CU's producer generates GNAT Ada auxiliary information
21819 that allows to find parallel types through that information instead
21820 of having to do expensive parallel lookups by type name. */
21823 need_gnat_info (struct dwarf2_cu
*cu
)
21825 /* Assume that the Ada compiler was GNAT, which always produces
21826 the auxiliary information. */
21827 return (cu
->language
== language_ada
);
21830 /* Return the auxiliary type of the die in question using its
21831 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21832 attribute is not present. */
21834 static struct type
*
21835 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21837 struct attribute
*type_attr
;
21839 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21843 return lookup_die_type (die
, type_attr
, cu
);
21846 /* If DIE has a descriptive_type attribute, then set the TYPE's
21847 descriptive type accordingly. */
21850 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21851 struct dwarf2_cu
*cu
)
21853 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21855 if (descriptive_type
)
21857 ALLOCATE_GNAT_AUX_TYPE (type
);
21858 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21862 /* Return the containing type of the die in question using its
21863 DW_AT_containing_type attribute. */
21865 static struct type
*
21866 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21868 struct attribute
*type_attr
;
21869 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21871 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21873 error (_("Dwarf Error: Problem turning containing type into gdb type "
21874 "[in module %s]"), objfile_name (objfile
));
21876 return lookup_die_type (die
, type_attr
, cu
);
21879 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21881 static struct type
*
21882 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21884 struct dwarf2_per_objfile
*dwarf2_per_objfile
21885 = cu
->per_cu
->dwarf2_per_objfile
;
21886 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21887 char *message
, *saved
;
21889 message
= xstrprintf (_("<unknown type in %s, CU %s, DIE %s>"),
21890 objfile_name (objfile
),
21891 sect_offset_str (cu
->header
.sect_off
),
21892 sect_offset_str (die
->sect_off
));
21893 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
21894 message
, strlen (message
));
21897 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21900 /* Look up the type of DIE in CU using its type attribute ATTR.
21901 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21902 DW_AT_containing_type.
21903 If there is no type substitute an error marker. */
21905 static struct type
*
21906 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21907 struct dwarf2_cu
*cu
)
21909 struct dwarf2_per_objfile
*dwarf2_per_objfile
21910 = cu
->per_cu
->dwarf2_per_objfile
;
21911 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21912 struct type
*this_type
;
21914 gdb_assert (attr
->name
== DW_AT_type
21915 || attr
->name
== DW_AT_GNAT_descriptive_type
21916 || attr
->name
== DW_AT_containing_type
);
21918 /* First see if we have it cached. */
21920 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21922 struct dwarf2_per_cu_data
*per_cu
;
21923 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21925 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21926 dwarf2_per_objfile
);
21927 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21929 else if (attr_form_is_ref (attr
))
21931 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21933 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21935 else if (attr
->form
== DW_FORM_ref_sig8
)
21937 ULONGEST signature
= DW_SIGNATURE (attr
);
21939 return get_signatured_type (die
, signature
, cu
);
21943 complaint (&symfile_complaints
,
21944 _("Dwarf Error: Bad type attribute %s in DIE"
21945 " at %s [in module %s]"),
21946 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21947 objfile_name (objfile
));
21948 return build_error_marker_type (cu
, die
);
21951 /* If not cached we need to read it in. */
21953 if (this_type
== NULL
)
21955 struct die_info
*type_die
= NULL
;
21956 struct dwarf2_cu
*type_cu
= cu
;
21958 if (attr_form_is_ref (attr
))
21959 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21960 if (type_die
== NULL
)
21961 return build_error_marker_type (cu
, die
);
21962 /* If we find the type now, it's probably because the type came
21963 from an inter-CU reference and the type's CU got expanded before
21965 this_type
= read_type_die (type_die
, type_cu
);
21968 /* If we still don't have a type use an error marker. */
21970 if (this_type
== NULL
)
21971 return build_error_marker_type (cu
, die
);
21976 /* Return the type in DIE, CU.
21977 Returns NULL for invalid types.
21979 This first does a lookup in die_type_hash,
21980 and only reads the die in if necessary.
21982 NOTE: This can be called when reading in partial or full symbols. */
21984 static struct type
*
21985 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21987 struct type
*this_type
;
21989 this_type
= get_die_type (die
, cu
);
21993 return read_type_die_1 (die
, cu
);
21996 /* Read the type in DIE, CU.
21997 Returns NULL for invalid types. */
21999 static struct type
*
22000 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22002 struct type
*this_type
= NULL
;
22006 case DW_TAG_class_type
:
22007 case DW_TAG_interface_type
:
22008 case DW_TAG_structure_type
:
22009 case DW_TAG_union_type
:
22010 this_type
= read_structure_type (die
, cu
);
22012 case DW_TAG_enumeration_type
:
22013 this_type
= read_enumeration_type (die
, cu
);
22015 case DW_TAG_subprogram
:
22016 case DW_TAG_subroutine_type
:
22017 case DW_TAG_inlined_subroutine
:
22018 this_type
= read_subroutine_type (die
, cu
);
22020 case DW_TAG_array_type
:
22021 this_type
= read_array_type (die
, cu
);
22023 case DW_TAG_set_type
:
22024 this_type
= read_set_type (die
, cu
);
22026 case DW_TAG_pointer_type
:
22027 this_type
= read_tag_pointer_type (die
, cu
);
22029 case DW_TAG_ptr_to_member_type
:
22030 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22032 case DW_TAG_reference_type
:
22033 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22035 case DW_TAG_rvalue_reference_type
:
22036 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22038 case DW_TAG_const_type
:
22039 this_type
= read_tag_const_type (die
, cu
);
22041 case DW_TAG_volatile_type
:
22042 this_type
= read_tag_volatile_type (die
, cu
);
22044 case DW_TAG_restrict_type
:
22045 this_type
= read_tag_restrict_type (die
, cu
);
22047 case DW_TAG_string_type
:
22048 this_type
= read_tag_string_type (die
, cu
);
22050 case DW_TAG_typedef
:
22051 this_type
= read_typedef (die
, cu
);
22053 case DW_TAG_subrange_type
:
22054 this_type
= read_subrange_type (die
, cu
);
22056 case DW_TAG_base_type
:
22057 this_type
= read_base_type (die
, cu
);
22059 case DW_TAG_unspecified_type
:
22060 this_type
= read_unspecified_type (die
, cu
);
22062 case DW_TAG_namespace
:
22063 this_type
= read_namespace_type (die
, cu
);
22065 case DW_TAG_module
:
22066 this_type
= read_module_type (die
, cu
);
22068 case DW_TAG_atomic_type
:
22069 this_type
= read_tag_atomic_type (die
, cu
);
22072 complaint (&symfile_complaints
,
22073 _("unexpected tag in read_type_die: '%s'"),
22074 dwarf_tag_name (die
->tag
));
22081 /* See if we can figure out if the class lives in a namespace. We do
22082 this by looking for a member function; its demangled name will
22083 contain namespace info, if there is any.
22084 Return the computed name or NULL.
22085 Space for the result is allocated on the objfile's obstack.
22086 This is the full-die version of guess_partial_die_structure_name.
22087 In this case we know DIE has no useful parent. */
22090 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22092 struct die_info
*spec_die
;
22093 struct dwarf2_cu
*spec_cu
;
22094 struct die_info
*child
;
22095 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22098 spec_die
= die_specification (die
, &spec_cu
);
22099 if (spec_die
!= NULL
)
22105 for (child
= die
->child
;
22107 child
= child
->sibling
)
22109 if (child
->tag
== DW_TAG_subprogram
)
22111 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22113 if (linkage_name
!= NULL
)
22116 = language_class_name_from_physname (cu
->language_defn
,
22120 if (actual_name
!= NULL
)
22122 const char *die_name
= dwarf2_name (die
, cu
);
22124 if (die_name
!= NULL
22125 && strcmp (die_name
, actual_name
) != 0)
22127 /* Strip off the class name from the full name.
22128 We want the prefix. */
22129 int die_name_len
= strlen (die_name
);
22130 int actual_name_len
= strlen (actual_name
);
22132 /* Test for '::' as a sanity check. */
22133 if (actual_name_len
> die_name_len
+ 2
22134 && actual_name
[actual_name_len
22135 - die_name_len
- 1] == ':')
22136 name
= (char *) obstack_copy0 (
22137 &objfile
->per_bfd
->storage_obstack
,
22138 actual_name
, actual_name_len
- die_name_len
- 2);
22141 xfree (actual_name
);
22150 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22151 prefix part in such case. See
22152 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22154 static const char *
22155 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22157 struct attribute
*attr
;
22160 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22161 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22164 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22167 attr
= dw2_linkage_name_attr (die
, cu
);
22168 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22171 /* dwarf2_name had to be already called. */
22172 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22174 /* Strip the base name, keep any leading namespaces/classes. */
22175 base
= strrchr (DW_STRING (attr
), ':');
22176 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22179 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22180 return (char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22182 &base
[-1] - DW_STRING (attr
));
22185 /* Return the name of the namespace/class that DIE is defined within,
22186 or "" if we can't tell. The caller should not xfree the result.
22188 For example, if we're within the method foo() in the following
22198 then determine_prefix on foo's die will return "N::C". */
22200 static const char *
22201 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22203 struct dwarf2_per_objfile
*dwarf2_per_objfile
22204 = cu
->per_cu
->dwarf2_per_objfile
;
22205 struct die_info
*parent
, *spec_die
;
22206 struct dwarf2_cu
*spec_cu
;
22207 struct type
*parent_type
;
22208 const char *retval
;
22210 if (cu
->language
!= language_cplus
22211 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22212 && cu
->language
!= language_rust
)
22215 retval
= anonymous_struct_prefix (die
, cu
);
22219 /* We have to be careful in the presence of DW_AT_specification.
22220 For example, with GCC 3.4, given the code
22224 // Definition of N::foo.
22228 then we'll have a tree of DIEs like this:
22230 1: DW_TAG_compile_unit
22231 2: DW_TAG_namespace // N
22232 3: DW_TAG_subprogram // declaration of N::foo
22233 4: DW_TAG_subprogram // definition of N::foo
22234 DW_AT_specification // refers to die #3
22236 Thus, when processing die #4, we have to pretend that we're in
22237 the context of its DW_AT_specification, namely the contex of die
22240 spec_die
= die_specification (die
, &spec_cu
);
22241 if (spec_die
== NULL
)
22242 parent
= die
->parent
;
22245 parent
= spec_die
->parent
;
22249 if (parent
== NULL
)
22251 else if (parent
->building_fullname
)
22254 const char *parent_name
;
22256 /* It has been seen on RealView 2.2 built binaries,
22257 DW_TAG_template_type_param types actually _defined_ as
22258 children of the parent class:
22261 template class <class Enum> Class{};
22262 Class<enum E> class_e;
22264 1: DW_TAG_class_type (Class)
22265 2: DW_TAG_enumeration_type (E)
22266 3: DW_TAG_enumerator (enum1:0)
22267 3: DW_TAG_enumerator (enum2:1)
22269 2: DW_TAG_template_type_param
22270 DW_AT_type DW_FORM_ref_udata (E)
22272 Besides being broken debug info, it can put GDB into an
22273 infinite loop. Consider:
22275 When we're building the full name for Class<E>, we'll start
22276 at Class, and go look over its template type parameters,
22277 finding E. We'll then try to build the full name of E, and
22278 reach here. We're now trying to build the full name of E,
22279 and look over the parent DIE for containing scope. In the
22280 broken case, if we followed the parent DIE of E, we'd again
22281 find Class, and once again go look at its template type
22282 arguments, etc., etc. Simply don't consider such parent die
22283 as source-level parent of this die (it can't be, the language
22284 doesn't allow it), and break the loop here. */
22285 name
= dwarf2_name (die
, cu
);
22286 parent_name
= dwarf2_name (parent
, cu
);
22287 complaint (&symfile_complaints
,
22288 _("template param type '%s' defined within parent '%s'"),
22289 name
? name
: "<unknown>",
22290 parent_name
? parent_name
: "<unknown>");
22294 switch (parent
->tag
)
22296 case DW_TAG_namespace
:
22297 parent_type
= read_type_die (parent
, cu
);
22298 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22299 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22300 Work around this problem here. */
22301 if (cu
->language
== language_cplus
22302 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
22304 /* We give a name to even anonymous namespaces. */
22305 return TYPE_TAG_NAME (parent_type
);
22306 case DW_TAG_class_type
:
22307 case DW_TAG_interface_type
:
22308 case DW_TAG_structure_type
:
22309 case DW_TAG_union_type
:
22310 case DW_TAG_module
:
22311 parent_type
= read_type_die (parent
, cu
);
22312 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22313 return TYPE_TAG_NAME (parent_type
);
22315 /* An anonymous structure is only allowed non-static data
22316 members; no typedefs, no member functions, et cetera.
22317 So it does not need a prefix. */
22319 case DW_TAG_compile_unit
:
22320 case DW_TAG_partial_unit
:
22321 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22322 if (cu
->language
== language_cplus
22323 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
22324 && die
->child
!= NULL
22325 && (die
->tag
== DW_TAG_class_type
22326 || die
->tag
== DW_TAG_structure_type
22327 || die
->tag
== DW_TAG_union_type
))
22329 char *name
= guess_full_die_structure_name (die
, cu
);
22334 case DW_TAG_enumeration_type
:
22335 parent_type
= read_type_die (parent
, cu
);
22336 if (TYPE_DECLARED_CLASS (parent_type
))
22338 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22339 return TYPE_TAG_NAME (parent_type
);
22342 /* Fall through. */
22344 return determine_prefix (parent
, cu
);
22348 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22349 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22350 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22351 an obconcat, otherwise allocate storage for the result. The CU argument is
22352 used to determine the language and hence, the appropriate separator. */
22354 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22357 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22358 int physname
, struct dwarf2_cu
*cu
)
22360 const char *lead
= "";
22363 if (suffix
== NULL
|| suffix
[0] == '\0'
22364 || prefix
== NULL
|| prefix
[0] == '\0')
22366 else if (cu
->language
== language_d
)
22368 /* For D, the 'main' function could be defined in any module, but it
22369 should never be prefixed. */
22370 if (strcmp (suffix
, "D main") == 0)
22378 else if (cu
->language
== language_fortran
&& physname
)
22380 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22381 DW_AT_MIPS_linkage_name is preferred and used instead. */
22389 if (prefix
== NULL
)
22391 if (suffix
== NULL
)
22398 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22400 strcpy (retval
, lead
);
22401 strcat (retval
, prefix
);
22402 strcat (retval
, sep
);
22403 strcat (retval
, suffix
);
22408 /* We have an obstack. */
22409 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22413 /* Return sibling of die, NULL if no sibling. */
22415 static struct die_info
*
22416 sibling_die (struct die_info
*die
)
22418 return die
->sibling
;
22421 /* Get name of a die, return NULL if not found. */
22423 static const char *
22424 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22425 struct obstack
*obstack
)
22427 if (name
&& cu
->language
== language_cplus
)
22429 std::string canon_name
= cp_canonicalize_string (name
);
22431 if (!canon_name
.empty ())
22433 if (canon_name
!= name
)
22434 name
= (const char *) obstack_copy0 (obstack
,
22435 canon_name
.c_str (),
22436 canon_name
.length ());
22443 /* Get name of a die, return NULL if not found.
22444 Anonymous namespaces are converted to their magic string. */
22446 static const char *
22447 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22449 struct attribute
*attr
;
22450 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22452 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22453 if ((!attr
|| !DW_STRING (attr
))
22454 && die
->tag
!= DW_TAG_namespace
22455 && die
->tag
!= DW_TAG_class_type
22456 && die
->tag
!= DW_TAG_interface_type
22457 && die
->tag
!= DW_TAG_structure_type
22458 && die
->tag
!= DW_TAG_union_type
)
22463 case DW_TAG_compile_unit
:
22464 case DW_TAG_partial_unit
:
22465 /* Compilation units have a DW_AT_name that is a filename, not
22466 a source language identifier. */
22467 case DW_TAG_enumeration_type
:
22468 case DW_TAG_enumerator
:
22469 /* These tags always have simple identifiers already; no need
22470 to canonicalize them. */
22471 return DW_STRING (attr
);
22473 case DW_TAG_namespace
:
22474 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22475 return DW_STRING (attr
);
22476 return CP_ANONYMOUS_NAMESPACE_STR
;
22478 case DW_TAG_class_type
:
22479 case DW_TAG_interface_type
:
22480 case DW_TAG_structure_type
:
22481 case DW_TAG_union_type
:
22482 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22483 structures or unions. These were of the form "._%d" in GCC 4.1,
22484 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22485 and GCC 4.4. We work around this problem by ignoring these. */
22486 if (attr
&& DW_STRING (attr
)
22487 && (startswith (DW_STRING (attr
), "._")
22488 || startswith (DW_STRING (attr
), "<anonymous")))
22491 /* GCC might emit a nameless typedef that has a linkage name. See
22492 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22493 if (!attr
|| DW_STRING (attr
) == NULL
)
22495 char *demangled
= NULL
;
22497 attr
= dw2_linkage_name_attr (die
, cu
);
22498 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22501 /* Avoid demangling DW_STRING (attr) the second time on a second
22502 call for the same DIE. */
22503 if (!DW_STRING_IS_CANONICAL (attr
))
22504 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22510 /* FIXME: we already did this for the partial symbol... */
22513 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22514 demangled
, strlen (demangled
)));
22515 DW_STRING_IS_CANONICAL (attr
) = 1;
22518 /* Strip any leading namespaces/classes, keep only the base name.
22519 DW_AT_name for named DIEs does not contain the prefixes. */
22520 base
= strrchr (DW_STRING (attr
), ':');
22521 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22524 return DW_STRING (attr
);
22533 if (!DW_STRING_IS_CANONICAL (attr
))
22536 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22537 &objfile
->per_bfd
->storage_obstack
);
22538 DW_STRING_IS_CANONICAL (attr
) = 1;
22540 return DW_STRING (attr
);
22543 /* Return the die that this die in an extension of, or NULL if there
22544 is none. *EXT_CU is the CU containing DIE on input, and the CU
22545 containing the return value on output. */
22547 static struct die_info
*
22548 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22550 struct attribute
*attr
;
22552 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22556 return follow_die_ref (die
, attr
, ext_cu
);
22559 /* Convert a DIE tag into its string name. */
22561 static const char *
22562 dwarf_tag_name (unsigned tag
)
22564 const char *name
= get_DW_TAG_name (tag
);
22567 return "DW_TAG_<unknown>";
22572 /* Convert a DWARF attribute code into its string name. */
22574 static const char *
22575 dwarf_attr_name (unsigned attr
)
22579 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22580 if (attr
== DW_AT_MIPS_fde
)
22581 return "DW_AT_MIPS_fde";
22583 if (attr
== DW_AT_HP_block_index
)
22584 return "DW_AT_HP_block_index";
22587 name
= get_DW_AT_name (attr
);
22590 return "DW_AT_<unknown>";
22595 /* Convert a DWARF value form code into its string name. */
22597 static const char *
22598 dwarf_form_name (unsigned form
)
22600 const char *name
= get_DW_FORM_name (form
);
22603 return "DW_FORM_<unknown>";
22608 static const char *
22609 dwarf_bool_name (unsigned mybool
)
22617 /* Convert a DWARF type code into its string name. */
22619 static const char *
22620 dwarf_type_encoding_name (unsigned enc
)
22622 const char *name
= get_DW_ATE_name (enc
);
22625 return "DW_ATE_<unknown>";
22631 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22635 print_spaces (indent
, f
);
22636 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22637 dwarf_tag_name (die
->tag
), die
->abbrev
,
22638 sect_offset_str (die
->sect_off
));
22640 if (die
->parent
!= NULL
)
22642 print_spaces (indent
, f
);
22643 fprintf_unfiltered (f
, " parent at offset: %s\n",
22644 sect_offset_str (die
->parent
->sect_off
));
22647 print_spaces (indent
, f
);
22648 fprintf_unfiltered (f
, " has children: %s\n",
22649 dwarf_bool_name (die
->child
!= NULL
));
22651 print_spaces (indent
, f
);
22652 fprintf_unfiltered (f
, " attributes:\n");
22654 for (i
= 0; i
< die
->num_attrs
; ++i
)
22656 print_spaces (indent
, f
);
22657 fprintf_unfiltered (f
, " %s (%s) ",
22658 dwarf_attr_name (die
->attrs
[i
].name
),
22659 dwarf_form_name (die
->attrs
[i
].form
));
22661 switch (die
->attrs
[i
].form
)
22664 case DW_FORM_GNU_addr_index
:
22665 fprintf_unfiltered (f
, "address: ");
22666 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22668 case DW_FORM_block2
:
22669 case DW_FORM_block4
:
22670 case DW_FORM_block
:
22671 case DW_FORM_block1
:
22672 fprintf_unfiltered (f
, "block: size %s",
22673 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22675 case DW_FORM_exprloc
:
22676 fprintf_unfiltered (f
, "expression: size %s",
22677 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22679 case DW_FORM_data16
:
22680 fprintf_unfiltered (f
, "constant of 16 bytes");
22682 case DW_FORM_ref_addr
:
22683 fprintf_unfiltered (f
, "ref address: ");
22684 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22686 case DW_FORM_GNU_ref_alt
:
22687 fprintf_unfiltered (f
, "alt ref address: ");
22688 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22694 case DW_FORM_ref_udata
:
22695 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22696 (long) (DW_UNSND (&die
->attrs
[i
])));
22698 case DW_FORM_data1
:
22699 case DW_FORM_data2
:
22700 case DW_FORM_data4
:
22701 case DW_FORM_data8
:
22702 case DW_FORM_udata
:
22703 case DW_FORM_sdata
:
22704 fprintf_unfiltered (f
, "constant: %s",
22705 pulongest (DW_UNSND (&die
->attrs
[i
])));
22707 case DW_FORM_sec_offset
:
22708 fprintf_unfiltered (f
, "section offset: %s",
22709 pulongest (DW_UNSND (&die
->attrs
[i
])));
22711 case DW_FORM_ref_sig8
:
22712 fprintf_unfiltered (f
, "signature: %s",
22713 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22715 case DW_FORM_string
:
22717 case DW_FORM_line_strp
:
22718 case DW_FORM_GNU_str_index
:
22719 case DW_FORM_GNU_strp_alt
:
22720 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22721 DW_STRING (&die
->attrs
[i
])
22722 ? DW_STRING (&die
->attrs
[i
]) : "",
22723 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22726 if (DW_UNSND (&die
->attrs
[i
]))
22727 fprintf_unfiltered (f
, "flag: TRUE");
22729 fprintf_unfiltered (f
, "flag: FALSE");
22731 case DW_FORM_flag_present
:
22732 fprintf_unfiltered (f
, "flag: TRUE");
22734 case DW_FORM_indirect
:
22735 /* The reader will have reduced the indirect form to
22736 the "base form" so this form should not occur. */
22737 fprintf_unfiltered (f
,
22738 "unexpected attribute form: DW_FORM_indirect");
22740 case DW_FORM_implicit_const
:
22741 fprintf_unfiltered (f
, "constant: %s",
22742 plongest (DW_SND (&die
->attrs
[i
])));
22745 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22746 die
->attrs
[i
].form
);
22749 fprintf_unfiltered (f
, "\n");
22754 dump_die_for_error (struct die_info
*die
)
22756 dump_die_shallow (gdb_stderr
, 0, die
);
22760 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22762 int indent
= level
* 4;
22764 gdb_assert (die
!= NULL
);
22766 if (level
>= max_level
)
22769 dump_die_shallow (f
, indent
, die
);
22771 if (die
->child
!= NULL
)
22773 print_spaces (indent
, f
);
22774 fprintf_unfiltered (f
, " Children:");
22775 if (level
+ 1 < max_level
)
22777 fprintf_unfiltered (f
, "\n");
22778 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22782 fprintf_unfiltered (f
,
22783 " [not printed, max nesting level reached]\n");
22787 if (die
->sibling
!= NULL
&& level
> 0)
22789 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22793 /* This is called from the pdie macro in gdbinit.in.
22794 It's not static so gcc will keep a copy callable from gdb. */
22797 dump_die (struct die_info
*die
, int max_level
)
22799 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22803 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22807 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22808 to_underlying (die
->sect_off
),
22814 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22818 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22820 if (attr_form_is_ref (attr
))
22821 return (sect_offset
) DW_UNSND (attr
);
22823 complaint (&symfile_complaints
,
22824 _("unsupported die ref attribute form: '%s'"),
22825 dwarf_form_name (attr
->form
));
22829 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22830 * the value held by the attribute is not constant. */
22833 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22835 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22836 return DW_SND (attr
);
22837 else if (attr
->form
== DW_FORM_udata
22838 || attr
->form
== DW_FORM_data1
22839 || attr
->form
== DW_FORM_data2
22840 || attr
->form
== DW_FORM_data4
22841 || attr
->form
== DW_FORM_data8
)
22842 return DW_UNSND (attr
);
22845 /* For DW_FORM_data16 see attr_form_is_constant. */
22846 complaint (&symfile_complaints
,
22847 _("Attribute value is not a constant (%s)"),
22848 dwarf_form_name (attr
->form
));
22849 return default_value
;
22853 /* Follow reference or signature attribute ATTR of SRC_DIE.
22854 On entry *REF_CU is the CU of SRC_DIE.
22855 On exit *REF_CU is the CU of the result. */
22857 static struct die_info
*
22858 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22859 struct dwarf2_cu
**ref_cu
)
22861 struct die_info
*die
;
22863 if (attr_form_is_ref (attr
))
22864 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22865 else if (attr
->form
== DW_FORM_ref_sig8
)
22866 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22869 dump_die_for_error (src_die
);
22870 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22871 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22877 /* Follow reference OFFSET.
22878 On entry *REF_CU is the CU of the source die referencing OFFSET.
22879 On exit *REF_CU is the CU of the result.
22880 Returns NULL if OFFSET is invalid. */
22882 static struct die_info
*
22883 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22884 struct dwarf2_cu
**ref_cu
)
22886 struct die_info temp_die
;
22887 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22888 struct dwarf2_per_objfile
*dwarf2_per_objfile
22889 = cu
->per_cu
->dwarf2_per_objfile
;
22890 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22892 gdb_assert (cu
->per_cu
!= NULL
);
22896 if (cu
->per_cu
->is_debug_types
)
22898 /* .debug_types CUs cannot reference anything outside their CU.
22899 If they need to, they have to reference a signatured type via
22900 DW_FORM_ref_sig8. */
22901 if (!offset_in_cu_p (&cu
->header
, sect_off
))
22904 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22905 || !offset_in_cu_p (&cu
->header
, sect_off
))
22907 struct dwarf2_per_cu_data
*per_cu
;
22909 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22910 dwarf2_per_objfile
);
22912 /* If necessary, add it to the queue and load its DIEs. */
22913 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22914 load_full_comp_unit (per_cu
, cu
->language
);
22916 target_cu
= per_cu
->cu
;
22918 else if (cu
->dies
== NULL
)
22920 /* We're loading full DIEs during partial symbol reading. */
22921 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22922 load_full_comp_unit (cu
->per_cu
, language_minimal
);
22925 *ref_cu
= target_cu
;
22926 temp_die
.sect_off
= sect_off
;
22927 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22929 to_underlying (sect_off
));
22932 /* Follow reference attribute ATTR of SRC_DIE.
22933 On entry *REF_CU is the CU of SRC_DIE.
22934 On exit *REF_CU is the CU of the result. */
22936 static struct die_info
*
22937 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22938 struct dwarf2_cu
**ref_cu
)
22940 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22941 struct dwarf2_cu
*cu
= *ref_cu
;
22942 struct die_info
*die
;
22944 die
= follow_die_offset (sect_off
,
22945 (attr
->form
== DW_FORM_GNU_ref_alt
22946 || cu
->per_cu
->is_dwz
),
22949 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22950 "at %s [in module %s]"),
22951 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22952 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22957 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22958 Returned value is intended for DW_OP_call*. Returned
22959 dwarf2_locexpr_baton->data has lifetime of
22960 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22962 struct dwarf2_locexpr_baton
22963 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22964 struct dwarf2_per_cu_data
*per_cu
,
22965 CORE_ADDR (*get_frame_pc
) (void *baton
),
22968 struct dwarf2_cu
*cu
;
22969 struct die_info
*die
;
22970 struct attribute
*attr
;
22971 struct dwarf2_locexpr_baton retval
;
22972 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22973 struct dwarf2_per_objfile
*dwarf2_per_objfile
22974 = get_dwarf2_per_objfile (objfile
);
22976 if (per_cu
->cu
== NULL
)
22981 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22982 Instead just throw an error, not much else we can do. */
22983 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22984 sect_offset_str (sect_off
), objfile_name (objfile
));
22987 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22989 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22990 sect_offset_str (sect_off
), objfile_name (objfile
));
22992 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22995 /* DWARF: "If there is no such attribute, then there is no effect.".
22996 DATA is ignored if SIZE is 0. */
22998 retval
.data
= NULL
;
23001 else if (attr_form_is_section_offset (attr
))
23003 struct dwarf2_loclist_baton loclist_baton
;
23004 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23007 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23009 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23011 retval
.size
= size
;
23015 if (!attr_form_is_block (attr
))
23016 error (_("Dwarf Error: DIE at %s referenced in module %s "
23017 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23018 sect_offset_str (sect_off
), objfile_name (objfile
));
23020 retval
.data
= DW_BLOCK (attr
)->data
;
23021 retval
.size
= DW_BLOCK (attr
)->size
;
23023 retval
.per_cu
= cu
->per_cu
;
23025 age_cached_comp_units (dwarf2_per_objfile
);
23030 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23033 struct dwarf2_locexpr_baton
23034 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23035 struct dwarf2_per_cu_data
*per_cu
,
23036 CORE_ADDR (*get_frame_pc
) (void *baton
),
23039 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23041 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23044 /* Write a constant of a given type as target-ordered bytes into
23047 static const gdb_byte
*
23048 write_constant_as_bytes (struct obstack
*obstack
,
23049 enum bfd_endian byte_order
,
23056 *len
= TYPE_LENGTH (type
);
23057 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23058 store_unsigned_integer (result
, *len
, byte_order
, value
);
23063 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23064 pointer to the constant bytes and set LEN to the length of the
23065 data. If memory is needed, allocate it on OBSTACK. If the DIE
23066 does not have a DW_AT_const_value, return NULL. */
23069 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23070 struct dwarf2_per_cu_data
*per_cu
,
23071 struct obstack
*obstack
,
23074 struct dwarf2_cu
*cu
;
23075 struct die_info
*die
;
23076 struct attribute
*attr
;
23077 const gdb_byte
*result
= NULL
;
23080 enum bfd_endian byte_order
;
23081 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23083 if (per_cu
->cu
== NULL
)
23088 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23089 Instead just throw an error, not much else we can do. */
23090 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23091 sect_offset_str (sect_off
), objfile_name (objfile
));
23094 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23096 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23097 sect_offset_str (sect_off
), objfile_name (objfile
));
23099 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23103 byte_order
= (bfd_big_endian (objfile
->obfd
)
23104 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23106 switch (attr
->form
)
23109 case DW_FORM_GNU_addr_index
:
23113 *len
= cu
->header
.addr_size
;
23114 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23115 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23119 case DW_FORM_string
:
23121 case DW_FORM_GNU_str_index
:
23122 case DW_FORM_GNU_strp_alt
:
23123 /* DW_STRING is already allocated on the objfile obstack, point
23125 result
= (const gdb_byte
*) DW_STRING (attr
);
23126 *len
= strlen (DW_STRING (attr
));
23128 case DW_FORM_block1
:
23129 case DW_FORM_block2
:
23130 case DW_FORM_block4
:
23131 case DW_FORM_block
:
23132 case DW_FORM_exprloc
:
23133 case DW_FORM_data16
:
23134 result
= DW_BLOCK (attr
)->data
;
23135 *len
= DW_BLOCK (attr
)->size
;
23138 /* The DW_AT_const_value attributes are supposed to carry the
23139 symbol's value "represented as it would be on the target
23140 architecture." By the time we get here, it's already been
23141 converted to host endianness, so we just need to sign- or
23142 zero-extend it as appropriate. */
23143 case DW_FORM_data1
:
23144 type
= die_type (die
, cu
);
23145 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23146 if (result
== NULL
)
23147 result
= write_constant_as_bytes (obstack
, byte_order
,
23150 case DW_FORM_data2
:
23151 type
= die_type (die
, cu
);
23152 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23153 if (result
== NULL
)
23154 result
= write_constant_as_bytes (obstack
, byte_order
,
23157 case DW_FORM_data4
:
23158 type
= die_type (die
, cu
);
23159 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23160 if (result
== NULL
)
23161 result
= write_constant_as_bytes (obstack
, byte_order
,
23164 case DW_FORM_data8
:
23165 type
= die_type (die
, cu
);
23166 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23167 if (result
== NULL
)
23168 result
= write_constant_as_bytes (obstack
, byte_order
,
23172 case DW_FORM_sdata
:
23173 case DW_FORM_implicit_const
:
23174 type
= die_type (die
, cu
);
23175 result
= write_constant_as_bytes (obstack
, byte_order
,
23176 type
, DW_SND (attr
), len
);
23179 case DW_FORM_udata
:
23180 type
= die_type (die
, cu
);
23181 result
= write_constant_as_bytes (obstack
, byte_order
,
23182 type
, DW_UNSND (attr
), len
);
23186 complaint (&symfile_complaints
,
23187 _("unsupported const value attribute form: '%s'"),
23188 dwarf_form_name (attr
->form
));
23195 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23196 valid type for this die is found. */
23199 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23200 struct dwarf2_per_cu_data
*per_cu
)
23202 struct dwarf2_cu
*cu
;
23203 struct die_info
*die
;
23205 if (per_cu
->cu
== NULL
)
23211 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23215 return die_type (die
, cu
);
23218 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23222 dwarf2_get_die_type (cu_offset die_offset
,
23223 struct dwarf2_per_cu_data
*per_cu
)
23225 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23226 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23229 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23230 On entry *REF_CU is the CU of SRC_DIE.
23231 On exit *REF_CU is the CU of the result.
23232 Returns NULL if the referenced DIE isn't found. */
23234 static struct die_info
*
23235 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23236 struct dwarf2_cu
**ref_cu
)
23238 struct die_info temp_die
;
23239 struct dwarf2_cu
*sig_cu
;
23240 struct die_info
*die
;
23242 /* While it might be nice to assert sig_type->type == NULL here,
23243 we can get here for DW_AT_imported_declaration where we need
23244 the DIE not the type. */
23246 /* If necessary, add it to the queue and load its DIEs. */
23248 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23249 read_signatured_type (sig_type
);
23251 sig_cu
= sig_type
->per_cu
.cu
;
23252 gdb_assert (sig_cu
!= NULL
);
23253 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23254 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23255 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23256 to_underlying (temp_die
.sect_off
));
23259 struct dwarf2_per_objfile
*dwarf2_per_objfile
23260 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23262 /* For .gdb_index version 7 keep track of included TUs.
23263 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23264 if (dwarf2_per_objfile
->index_table
!= NULL
23265 && dwarf2_per_objfile
->index_table
->version
<= 7)
23267 VEC_safe_push (dwarf2_per_cu_ptr
,
23268 (*ref_cu
)->per_cu
->imported_symtabs
,
23279 /* Follow signatured type referenced by ATTR in SRC_DIE.
23280 On entry *REF_CU is the CU of SRC_DIE.
23281 On exit *REF_CU is the CU of the result.
23282 The result is the DIE of the type.
23283 If the referenced type cannot be found an error is thrown. */
23285 static struct die_info
*
23286 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23287 struct dwarf2_cu
**ref_cu
)
23289 ULONGEST signature
= DW_SIGNATURE (attr
);
23290 struct signatured_type
*sig_type
;
23291 struct die_info
*die
;
23293 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23295 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23296 /* sig_type will be NULL if the signatured type is missing from
23298 if (sig_type
== NULL
)
23300 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23301 " from DIE at %s [in module %s]"),
23302 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23303 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23306 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23309 dump_die_for_error (src_die
);
23310 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23311 " from DIE at %s [in module %s]"),
23312 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23313 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23319 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23320 reading in and processing the type unit if necessary. */
23322 static struct type
*
23323 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23324 struct dwarf2_cu
*cu
)
23326 struct dwarf2_per_objfile
*dwarf2_per_objfile
23327 = cu
->per_cu
->dwarf2_per_objfile
;
23328 struct signatured_type
*sig_type
;
23329 struct dwarf2_cu
*type_cu
;
23330 struct die_info
*type_die
;
23333 sig_type
= lookup_signatured_type (cu
, signature
);
23334 /* sig_type will be NULL if the signatured type is missing from
23336 if (sig_type
== NULL
)
23338 complaint (&symfile_complaints
,
23339 _("Dwarf Error: Cannot find signatured DIE %s referenced"
23340 " from DIE at %s [in module %s]"),
23341 hex_string (signature
), sect_offset_str (die
->sect_off
),
23342 objfile_name (dwarf2_per_objfile
->objfile
));
23343 return build_error_marker_type (cu
, die
);
23346 /* If we already know the type we're done. */
23347 if (sig_type
->type
!= NULL
)
23348 return sig_type
->type
;
23351 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23352 if (type_die
!= NULL
)
23354 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23355 is created. This is important, for example, because for c++ classes
23356 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23357 type
= read_type_die (type_die
, type_cu
);
23360 complaint (&symfile_complaints
,
23361 _("Dwarf Error: Cannot build signatured type %s"
23362 " referenced from DIE at %s [in module %s]"),
23363 hex_string (signature
), sect_offset_str (die
->sect_off
),
23364 objfile_name (dwarf2_per_objfile
->objfile
));
23365 type
= build_error_marker_type (cu
, die
);
23370 complaint (&symfile_complaints
,
23371 _("Dwarf Error: Problem reading signatured DIE %s referenced"
23372 " from DIE at %s [in module %s]"),
23373 hex_string (signature
), sect_offset_str (die
->sect_off
),
23374 objfile_name (dwarf2_per_objfile
->objfile
));
23375 type
= build_error_marker_type (cu
, die
);
23377 sig_type
->type
= type
;
23382 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23383 reading in and processing the type unit if necessary. */
23385 static struct type
*
23386 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23387 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23389 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23390 if (attr_form_is_ref (attr
))
23392 struct dwarf2_cu
*type_cu
= cu
;
23393 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23395 return read_type_die (type_die
, type_cu
);
23397 else if (attr
->form
== DW_FORM_ref_sig8
)
23399 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23403 struct dwarf2_per_objfile
*dwarf2_per_objfile
23404 = cu
->per_cu
->dwarf2_per_objfile
;
23406 complaint (&symfile_complaints
,
23407 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23408 " at %s [in module %s]"),
23409 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23410 objfile_name (dwarf2_per_objfile
->objfile
));
23411 return build_error_marker_type (cu
, die
);
23415 /* Load the DIEs associated with type unit PER_CU into memory. */
23418 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23420 struct signatured_type
*sig_type
;
23422 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23423 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23425 /* We have the per_cu, but we need the signatured_type.
23426 Fortunately this is an easy translation. */
23427 gdb_assert (per_cu
->is_debug_types
);
23428 sig_type
= (struct signatured_type
*) per_cu
;
23430 gdb_assert (per_cu
->cu
== NULL
);
23432 read_signatured_type (sig_type
);
23434 gdb_assert (per_cu
->cu
!= NULL
);
23437 /* die_reader_func for read_signatured_type.
23438 This is identical to load_full_comp_unit_reader,
23439 but is kept separate for now. */
23442 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23443 const gdb_byte
*info_ptr
,
23444 struct die_info
*comp_unit_die
,
23448 struct dwarf2_cu
*cu
= reader
->cu
;
23450 gdb_assert (cu
->die_hash
== NULL
);
23452 htab_create_alloc_ex (cu
->header
.length
/ 12,
23456 &cu
->comp_unit_obstack
,
23457 hashtab_obstack_allocate
,
23458 dummy_obstack_deallocate
);
23461 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23462 &info_ptr
, comp_unit_die
);
23463 cu
->dies
= comp_unit_die
;
23464 /* comp_unit_die is not stored in die_hash, no need. */
23466 /* We try not to read any attributes in this function, because not
23467 all CUs needed for references have been loaded yet, and symbol
23468 table processing isn't initialized. But we have to set the CU language,
23469 or we won't be able to build types correctly.
23470 Similarly, if we do not read the producer, we can not apply
23471 producer-specific interpretation. */
23472 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23475 /* Read in a signatured type and build its CU and DIEs.
23476 If the type is a stub for the real type in a DWO file,
23477 read in the real type from the DWO file as well. */
23480 read_signatured_type (struct signatured_type
*sig_type
)
23482 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23484 gdb_assert (per_cu
->is_debug_types
);
23485 gdb_assert (per_cu
->cu
== NULL
);
23487 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
23488 read_signatured_type_reader
, NULL
);
23489 sig_type
->per_cu
.tu_read
= 1;
23492 /* Decode simple location descriptions.
23493 Given a pointer to a dwarf block that defines a location, compute
23494 the location and return the value.
23496 NOTE drow/2003-11-18: This function is called in two situations
23497 now: for the address of static or global variables (partial symbols
23498 only) and for offsets into structures which are expected to be
23499 (more or less) constant. The partial symbol case should go away,
23500 and only the constant case should remain. That will let this
23501 function complain more accurately. A few special modes are allowed
23502 without complaint for global variables (for instance, global
23503 register values and thread-local values).
23505 A location description containing no operations indicates that the
23506 object is optimized out. The return value is 0 for that case.
23507 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23508 callers will only want a very basic result and this can become a
23511 Note that stack[0] is unused except as a default error return. */
23514 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23516 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23518 size_t size
= blk
->size
;
23519 const gdb_byte
*data
= blk
->data
;
23520 CORE_ADDR stack
[64];
23522 unsigned int bytes_read
, unsnd
;
23528 stack
[++stacki
] = 0;
23567 stack
[++stacki
] = op
- DW_OP_lit0
;
23602 stack
[++stacki
] = op
- DW_OP_reg0
;
23604 dwarf2_complex_location_expr_complaint ();
23608 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23610 stack
[++stacki
] = unsnd
;
23612 dwarf2_complex_location_expr_complaint ();
23616 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
23621 case DW_OP_const1u
:
23622 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23626 case DW_OP_const1s
:
23627 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23631 case DW_OP_const2u
:
23632 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23636 case DW_OP_const2s
:
23637 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23641 case DW_OP_const4u
:
23642 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23646 case DW_OP_const4s
:
23647 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23651 case DW_OP_const8u
:
23652 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23657 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23663 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23668 stack
[stacki
+ 1] = stack
[stacki
];
23673 stack
[stacki
- 1] += stack
[stacki
];
23677 case DW_OP_plus_uconst
:
23678 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23684 stack
[stacki
- 1] -= stack
[stacki
];
23689 /* If we're not the last op, then we definitely can't encode
23690 this using GDB's address_class enum. This is valid for partial
23691 global symbols, although the variable's address will be bogus
23694 dwarf2_complex_location_expr_complaint ();
23697 case DW_OP_GNU_push_tls_address
:
23698 case DW_OP_form_tls_address
:
23699 /* The top of the stack has the offset from the beginning
23700 of the thread control block at which the variable is located. */
23701 /* Nothing should follow this operator, so the top of stack would
23703 /* This is valid for partial global symbols, but the variable's
23704 address will be bogus in the psymtab. Make it always at least
23705 non-zero to not look as a variable garbage collected by linker
23706 which have DW_OP_addr 0. */
23708 dwarf2_complex_location_expr_complaint ();
23712 case DW_OP_GNU_uninit
:
23715 case DW_OP_GNU_addr_index
:
23716 case DW_OP_GNU_const_index
:
23717 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23724 const char *name
= get_DW_OP_name (op
);
23727 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
23730 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
23734 return (stack
[stacki
]);
23737 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23738 outside of the allocated space. Also enforce minimum>0. */
23739 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23741 complaint (&symfile_complaints
,
23742 _("location description stack overflow"));
23748 complaint (&symfile_complaints
,
23749 _("location description stack underflow"));
23753 return (stack
[stacki
]);
23756 /* memory allocation interface */
23758 static struct dwarf_block
*
23759 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23761 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23764 static struct die_info
*
23765 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23767 struct die_info
*die
;
23768 size_t size
= sizeof (struct die_info
);
23771 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23773 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23774 memset (die
, 0, sizeof (struct die_info
));
23779 /* Macro support. */
23781 /* Return file name relative to the compilation directory of file number I in
23782 *LH's file name table. The result is allocated using xmalloc; the caller is
23783 responsible for freeing it. */
23786 file_file_name (int file
, struct line_header
*lh
)
23788 /* Is the file number a valid index into the line header's file name
23789 table? Remember that file numbers start with one, not zero. */
23790 if (1 <= file
&& file
<= lh
->file_names
.size ())
23792 const file_entry
&fe
= lh
->file_names
[file
- 1];
23794 if (!IS_ABSOLUTE_PATH (fe
.name
))
23796 const char *dir
= fe
.include_dir (lh
);
23798 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
23800 return xstrdup (fe
.name
);
23804 /* The compiler produced a bogus file number. We can at least
23805 record the macro definitions made in the file, even if we
23806 won't be able to find the file by name. */
23807 char fake_name
[80];
23809 xsnprintf (fake_name
, sizeof (fake_name
),
23810 "<bad macro file number %d>", file
);
23812 complaint (&symfile_complaints
,
23813 _("bad file number in macro information (%d)"),
23816 return xstrdup (fake_name
);
23820 /* Return the full name of file number I in *LH's file name table.
23821 Use COMP_DIR as the name of the current directory of the
23822 compilation. The result is allocated using xmalloc; the caller is
23823 responsible for freeing it. */
23825 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
23827 /* Is the file number a valid index into the line header's file name
23828 table? Remember that file numbers start with one, not zero. */
23829 if (1 <= file
&& file
<= lh
->file_names
.size ())
23831 char *relative
= file_file_name (file
, lh
);
23833 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
23835 return reconcat (relative
, comp_dir
, SLASH_STRING
,
23836 relative
, (char *) NULL
);
23839 return file_file_name (file
, lh
);
23843 static struct macro_source_file
*
23844 macro_start_file (int file
, int line
,
23845 struct macro_source_file
*current_file
,
23846 struct line_header
*lh
)
23848 /* File name relative to the compilation directory of this source file. */
23849 char *file_name
= file_file_name (file
, lh
);
23851 if (! current_file
)
23853 /* Note: We don't create a macro table for this compilation unit
23854 at all until we actually get a filename. */
23855 struct macro_table
*macro_table
= get_macro_table ();
23857 /* If we have no current file, then this must be the start_file
23858 directive for the compilation unit's main source file. */
23859 current_file
= macro_set_main (macro_table
, file_name
);
23860 macro_define_special (macro_table
);
23863 current_file
= macro_include (current_file
, line
, file_name
);
23867 return current_file
;
23870 static const char *
23871 consume_improper_spaces (const char *p
, const char *body
)
23875 complaint (&symfile_complaints
,
23876 _("macro definition contains spaces "
23877 "in formal argument list:\n`%s'"),
23889 parse_macro_definition (struct macro_source_file
*file
, int line
,
23894 /* The body string takes one of two forms. For object-like macro
23895 definitions, it should be:
23897 <macro name> " " <definition>
23899 For function-like macro definitions, it should be:
23901 <macro name> "() " <definition>
23903 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23905 Spaces may appear only where explicitly indicated, and in the
23908 The Dwarf 2 spec says that an object-like macro's name is always
23909 followed by a space, but versions of GCC around March 2002 omit
23910 the space when the macro's definition is the empty string.
23912 The Dwarf 2 spec says that there should be no spaces between the
23913 formal arguments in a function-like macro's formal argument list,
23914 but versions of GCC around March 2002 include spaces after the
23918 /* Find the extent of the macro name. The macro name is terminated
23919 by either a space or null character (for an object-like macro) or
23920 an opening paren (for a function-like macro). */
23921 for (p
= body
; *p
; p
++)
23922 if (*p
== ' ' || *p
== '(')
23925 if (*p
== ' ' || *p
== '\0')
23927 /* It's an object-like macro. */
23928 int name_len
= p
- body
;
23929 char *name
= savestring (body
, name_len
);
23930 const char *replacement
;
23933 replacement
= body
+ name_len
+ 1;
23936 dwarf2_macro_malformed_definition_complaint (body
);
23937 replacement
= body
+ name_len
;
23940 macro_define_object (file
, line
, name
, replacement
);
23944 else if (*p
== '(')
23946 /* It's a function-like macro. */
23947 char *name
= savestring (body
, p
- body
);
23950 char **argv
= XNEWVEC (char *, argv_size
);
23954 p
= consume_improper_spaces (p
, body
);
23956 /* Parse the formal argument list. */
23957 while (*p
&& *p
!= ')')
23959 /* Find the extent of the current argument name. */
23960 const char *arg_start
= p
;
23962 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23965 if (! *p
|| p
== arg_start
)
23966 dwarf2_macro_malformed_definition_complaint (body
);
23969 /* Make sure argv has room for the new argument. */
23970 if (argc
>= argv_size
)
23973 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23976 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23979 p
= consume_improper_spaces (p
, body
);
23981 /* Consume the comma, if present. */
23986 p
= consume_improper_spaces (p
, body
);
23995 /* Perfectly formed definition, no complaints. */
23996 macro_define_function (file
, line
, name
,
23997 argc
, (const char **) argv
,
23999 else if (*p
== '\0')
24001 /* Complain, but do define it. */
24002 dwarf2_macro_malformed_definition_complaint (body
);
24003 macro_define_function (file
, line
, name
,
24004 argc
, (const char **) argv
,
24008 /* Just complain. */
24009 dwarf2_macro_malformed_definition_complaint (body
);
24012 /* Just complain. */
24013 dwarf2_macro_malformed_definition_complaint (body
);
24019 for (i
= 0; i
< argc
; i
++)
24025 dwarf2_macro_malformed_definition_complaint (body
);
24028 /* Skip some bytes from BYTES according to the form given in FORM.
24029 Returns the new pointer. */
24031 static const gdb_byte
*
24032 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24033 enum dwarf_form form
,
24034 unsigned int offset_size
,
24035 struct dwarf2_section_info
*section
)
24037 unsigned int bytes_read
;
24041 case DW_FORM_data1
:
24046 case DW_FORM_data2
:
24050 case DW_FORM_data4
:
24054 case DW_FORM_data8
:
24058 case DW_FORM_data16
:
24062 case DW_FORM_string
:
24063 read_direct_string (abfd
, bytes
, &bytes_read
);
24064 bytes
+= bytes_read
;
24067 case DW_FORM_sec_offset
:
24069 case DW_FORM_GNU_strp_alt
:
24070 bytes
+= offset_size
;
24073 case DW_FORM_block
:
24074 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24075 bytes
+= bytes_read
;
24078 case DW_FORM_block1
:
24079 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24081 case DW_FORM_block2
:
24082 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24084 case DW_FORM_block4
:
24085 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24088 case DW_FORM_sdata
:
24089 case DW_FORM_udata
:
24090 case DW_FORM_GNU_addr_index
:
24091 case DW_FORM_GNU_str_index
:
24092 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24095 dwarf2_section_buffer_overflow_complaint (section
);
24100 case DW_FORM_implicit_const
:
24105 complaint (&symfile_complaints
,
24106 _("invalid form 0x%x in `%s'"),
24107 form
, get_section_name (section
));
24115 /* A helper for dwarf_decode_macros that handles skipping an unknown
24116 opcode. Returns an updated pointer to the macro data buffer; or,
24117 on error, issues a complaint and returns NULL. */
24119 static const gdb_byte
*
24120 skip_unknown_opcode (unsigned int opcode
,
24121 const gdb_byte
**opcode_definitions
,
24122 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24124 unsigned int offset_size
,
24125 struct dwarf2_section_info
*section
)
24127 unsigned int bytes_read
, i
;
24129 const gdb_byte
*defn
;
24131 if (opcode_definitions
[opcode
] == NULL
)
24133 complaint (&symfile_complaints
,
24134 _("unrecognized DW_MACFINO opcode 0x%x"),
24139 defn
= opcode_definitions
[opcode
];
24140 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24141 defn
+= bytes_read
;
24143 for (i
= 0; i
< arg
; ++i
)
24145 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24146 (enum dwarf_form
) defn
[i
], offset_size
,
24148 if (mac_ptr
== NULL
)
24150 /* skip_form_bytes already issued the complaint. */
24158 /* A helper function which parses the header of a macro section.
24159 If the macro section is the extended (for now called "GNU") type,
24160 then this updates *OFFSET_SIZE. Returns a pointer to just after
24161 the header, or issues a complaint and returns NULL on error. */
24163 static const gdb_byte
*
24164 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24166 const gdb_byte
*mac_ptr
,
24167 unsigned int *offset_size
,
24168 int section_is_gnu
)
24170 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24172 if (section_is_gnu
)
24174 unsigned int version
, flags
;
24176 version
= read_2_bytes (abfd
, mac_ptr
);
24177 if (version
!= 4 && version
!= 5)
24179 complaint (&symfile_complaints
,
24180 _("unrecognized version `%d' in .debug_macro section"),
24186 flags
= read_1_byte (abfd
, mac_ptr
);
24188 *offset_size
= (flags
& 1) ? 8 : 4;
24190 if ((flags
& 2) != 0)
24191 /* We don't need the line table offset. */
24192 mac_ptr
+= *offset_size
;
24194 /* Vendor opcode descriptions. */
24195 if ((flags
& 4) != 0)
24197 unsigned int i
, count
;
24199 count
= read_1_byte (abfd
, mac_ptr
);
24201 for (i
= 0; i
< count
; ++i
)
24203 unsigned int opcode
, bytes_read
;
24206 opcode
= read_1_byte (abfd
, mac_ptr
);
24208 opcode_definitions
[opcode
] = mac_ptr
;
24209 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24210 mac_ptr
+= bytes_read
;
24219 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24220 including DW_MACRO_import. */
24223 dwarf_decode_macro_bytes (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
24225 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24226 struct macro_source_file
*current_file
,
24227 struct line_header
*lh
,
24228 struct dwarf2_section_info
*section
,
24229 int section_is_gnu
, int section_is_dwz
,
24230 unsigned int offset_size
,
24231 htab_t include_hash
)
24233 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24234 enum dwarf_macro_record_type macinfo_type
;
24235 int at_commandline
;
24236 const gdb_byte
*opcode_definitions
[256];
24238 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24239 &offset_size
, section_is_gnu
);
24240 if (mac_ptr
== NULL
)
24242 /* We already issued a complaint. */
24246 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24247 GDB is still reading the definitions from command line. First
24248 DW_MACINFO_start_file will need to be ignored as it was already executed
24249 to create CURRENT_FILE for the main source holding also the command line
24250 definitions. On first met DW_MACINFO_start_file this flag is reset to
24251 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24253 at_commandline
= 1;
24257 /* Do we at least have room for a macinfo type byte? */
24258 if (mac_ptr
>= mac_end
)
24260 dwarf2_section_buffer_overflow_complaint (section
);
24264 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24267 /* Note that we rely on the fact that the corresponding GNU and
24268 DWARF constants are the same. */
24270 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24271 switch (macinfo_type
)
24273 /* A zero macinfo type indicates the end of the macro
24278 case DW_MACRO_define
:
24279 case DW_MACRO_undef
:
24280 case DW_MACRO_define_strp
:
24281 case DW_MACRO_undef_strp
:
24282 case DW_MACRO_define_sup
:
24283 case DW_MACRO_undef_sup
:
24285 unsigned int bytes_read
;
24290 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24291 mac_ptr
+= bytes_read
;
24293 if (macinfo_type
== DW_MACRO_define
24294 || macinfo_type
== DW_MACRO_undef
)
24296 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24297 mac_ptr
+= bytes_read
;
24301 LONGEST str_offset
;
24303 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24304 mac_ptr
+= offset_size
;
24306 if (macinfo_type
== DW_MACRO_define_sup
24307 || macinfo_type
== DW_MACRO_undef_sup
24310 struct dwz_file
*dwz
24311 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24313 body
= read_indirect_string_from_dwz (objfile
,
24317 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24321 is_define
= (macinfo_type
== DW_MACRO_define
24322 || macinfo_type
== DW_MACRO_define_strp
24323 || macinfo_type
== DW_MACRO_define_sup
);
24324 if (! current_file
)
24326 /* DWARF violation as no main source is present. */
24327 complaint (&symfile_complaints
,
24328 _("debug info with no main source gives macro %s "
24330 is_define
? _("definition") : _("undefinition"),
24334 if ((line
== 0 && !at_commandline
)
24335 || (line
!= 0 && at_commandline
))
24336 complaint (&symfile_complaints
,
24337 _("debug info gives %s macro %s with %s line %d: %s"),
24338 at_commandline
? _("command-line") : _("in-file"),
24339 is_define
? _("definition") : _("undefinition"),
24340 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24343 parse_macro_definition (current_file
, line
, body
);
24346 gdb_assert (macinfo_type
== DW_MACRO_undef
24347 || macinfo_type
== DW_MACRO_undef_strp
24348 || macinfo_type
== DW_MACRO_undef_sup
);
24349 macro_undef (current_file
, line
, body
);
24354 case DW_MACRO_start_file
:
24356 unsigned int bytes_read
;
24359 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24360 mac_ptr
+= bytes_read
;
24361 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24362 mac_ptr
+= bytes_read
;
24364 if ((line
== 0 && !at_commandline
)
24365 || (line
!= 0 && at_commandline
))
24366 complaint (&symfile_complaints
,
24367 _("debug info gives source %d included "
24368 "from %s at %s line %d"),
24369 file
, at_commandline
? _("command-line") : _("file"),
24370 line
== 0 ? _("zero") : _("non-zero"), line
);
24372 if (at_commandline
)
24374 /* This DW_MACRO_start_file was executed in the
24376 at_commandline
= 0;
24379 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24383 case DW_MACRO_end_file
:
24384 if (! current_file
)
24385 complaint (&symfile_complaints
,
24386 _("macro debug info has an unmatched "
24387 "`close_file' directive"));
24390 current_file
= current_file
->included_by
;
24391 if (! current_file
)
24393 enum dwarf_macro_record_type next_type
;
24395 /* GCC circa March 2002 doesn't produce the zero
24396 type byte marking the end of the compilation
24397 unit. Complain if it's not there, but exit no
24400 /* Do we at least have room for a macinfo type byte? */
24401 if (mac_ptr
>= mac_end
)
24403 dwarf2_section_buffer_overflow_complaint (section
);
24407 /* We don't increment mac_ptr here, so this is just
24410 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24412 if (next_type
!= 0)
24413 complaint (&symfile_complaints
,
24414 _("no terminating 0-type entry for "
24415 "macros in `.debug_macinfo' section"));
24422 case DW_MACRO_import
:
24423 case DW_MACRO_import_sup
:
24427 bfd
*include_bfd
= abfd
;
24428 struct dwarf2_section_info
*include_section
= section
;
24429 const gdb_byte
*include_mac_end
= mac_end
;
24430 int is_dwz
= section_is_dwz
;
24431 const gdb_byte
*new_mac_ptr
;
24433 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24434 mac_ptr
+= offset_size
;
24436 if (macinfo_type
== DW_MACRO_import_sup
)
24438 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24440 dwarf2_read_section (objfile
, &dwz
->macro
);
24442 include_section
= &dwz
->macro
;
24443 include_bfd
= get_section_bfd_owner (include_section
);
24444 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24448 new_mac_ptr
= include_section
->buffer
+ offset
;
24449 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24453 /* This has actually happened; see
24454 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24455 complaint (&symfile_complaints
,
24456 _("recursive DW_MACRO_import in "
24457 ".debug_macro section"));
24461 *slot
= (void *) new_mac_ptr
;
24463 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24464 include_bfd
, new_mac_ptr
,
24465 include_mac_end
, current_file
, lh
,
24466 section
, section_is_gnu
, is_dwz
,
24467 offset_size
, include_hash
);
24469 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24474 case DW_MACINFO_vendor_ext
:
24475 if (!section_is_gnu
)
24477 unsigned int bytes_read
;
24479 /* This reads the constant, but since we don't recognize
24480 any vendor extensions, we ignore it. */
24481 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24482 mac_ptr
+= bytes_read
;
24483 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24484 mac_ptr
+= bytes_read
;
24486 /* We don't recognize any vendor extensions. */
24492 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24493 mac_ptr
, mac_end
, abfd
, offset_size
,
24495 if (mac_ptr
== NULL
)
24500 } while (macinfo_type
!= 0);
24504 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24505 int section_is_gnu
)
24507 struct dwarf2_per_objfile
*dwarf2_per_objfile
24508 = cu
->per_cu
->dwarf2_per_objfile
;
24509 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24510 struct line_header
*lh
= cu
->line_header
;
24512 const gdb_byte
*mac_ptr
, *mac_end
;
24513 struct macro_source_file
*current_file
= 0;
24514 enum dwarf_macro_record_type macinfo_type
;
24515 unsigned int offset_size
= cu
->header
.offset_size
;
24516 const gdb_byte
*opcode_definitions
[256];
24518 struct dwarf2_section_info
*section
;
24519 const char *section_name
;
24521 if (cu
->dwo_unit
!= NULL
)
24523 if (section_is_gnu
)
24525 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24526 section_name
= ".debug_macro.dwo";
24530 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24531 section_name
= ".debug_macinfo.dwo";
24536 if (section_is_gnu
)
24538 section
= &dwarf2_per_objfile
->macro
;
24539 section_name
= ".debug_macro";
24543 section
= &dwarf2_per_objfile
->macinfo
;
24544 section_name
= ".debug_macinfo";
24548 dwarf2_read_section (objfile
, section
);
24549 if (section
->buffer
== NULL
)
24551 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
24554 abfd
= get_section_bfd_owner (section
);
24556 /* First pass: Find the name of the base filename.
24557 This filename is needed in order to process all macros whose definition
24558 (or undefinition) comes from the command line. These macros are defined
24559 before the first DW_MACINFO_start_file entry, and yet still need to be
24560 associated to the base file.
24562 To determine the base file name, we scan the macro definitions until we
24563 reach the first DW_MACINFO_start_file entry. We then initialize
24564 CURRENT_FILE accordingly so that any macro definition found before the
24565 first DW_MACINFO_start_file can still be associated to the base file. */
24567 mac_ptr
= section
->buffer
+ offset
;
24568 mac_end
= section
->buffer
+ section
->size
;
24570 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24571 &offset_size
, section_is_gnu
);
24572 if (mac_ptr
== NULL
)
24574 /* We already issued a complaint. */
24580 /* Do we at least have room for a macinfo type byte? */
24581 if (mac_ptr
>= mac_end
)
24583 /* Complaint is printed during the second pass as GDB will probably
24584 stop the first pass earlier upon finding
24585 DW_MACINFO_start_file. */
24589 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24592 /* Note that we rely on the fact that the corresponding GNU and
24593 DWARF constants are the same. */
24595 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24596 switch (macinfo_type
)
24598 /* A zero macinfo type indicates the end of the macro
24603 case DW_MACRO_define
:
24604 case DW_MACRO_undef
:
24605 /* Only skip the data by MAC_PTR. */
24607 unsigned int bytes_read
;
24609 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24610 mac_ptr
+= bytes_read
;
24611 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24612 mac_ptr
+= bytes_read
;
24616 case DW_MACRO_start_file
:
24618 unsigned int bytes_read
;
24621 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24622 mac_ptr
+= bytes_read
;
24623 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24624 mac_ptr
+= bytes_read
;
24626 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24630 case DW_MACRO_end_file
:
24631 /* No data to skip by MAC_PTR. */
24634 case DW_MACRO_define_strp
:
24635 case DW_MACRO_undef_strp
:
24636 case DW_MACRO_define_sup
:
24637 case DW_MACRO_undef_sup
:
24639 unsigned int bytes_read
;
24641 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24642 mac_ptr
+= bytes_read
;
24643 mac_ptr
+= offset_size
;
24647 case DW_MACRO_import
:
24648 case DW_MACRO_import_sup
:
24649 /* Note that, according to the spec, a transparent include
24650 chain cannot call DW_MACRO_start_file. So, we can just
24651 skip this opcode. */
24652 mac_ptr
+= offset_size
;
24655 case DW_MACINFO_vendor_ext
:
24656 /* Only skip the data by MAC_PTR. */
24657 if (!section_is_gnu
)
24659 unsigned int bytes_read
;
24661 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24662 mac_ptr
+= bytes_read
;
24663 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24664 mac_ptr
+= bytes_read
;
24669 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24670 mac_ptr
, mac_end
, abfd
, offset_size
,
24672 if (mac_ptr
== NULL
)
24677 } while (macinfo_type
!= 0 && current_file
== NULL
);
24679 /* Second pass: Process all entries.
24681 Use the AT_COMMAND_LINE flag to determine whether we are still processing
24682 command-line macro definitions/undefinitions. This flag is unset when we
24683 reach the first DW_MACINFO_start_file entry. */
24685 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
24687 NULL
, xcalloc
, xfree
));
24688 mac_ptr
= section
->buffer
+ offset
;
24689 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
24690 *slot
= (void *) mac_ptr
;
24691 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24692 abfd
, mac_ptr
, mac_end
,
24693 current_file
, lh
, section
,
24694 section_is_gnu
, 0, offset_size
,
24695 include_hash
.get ());
24698 /* Check if the attribute's form is a DW_FORM_block*
24699 if so return true else false. */
24702 attr_form_is_block (const struct attribute
*attr
)
24704 return (attr
== NULL
? 0 :
24705 attr
->form
== DW_FORM_block1
24706 || attr
->form
== DW_FORM_block2
24707 || attr
->form
== DW_FORM_block4
24708 || attr
->form
== DW_FORM_block
24709 || attr
->form
== DW_FORM_exprloc
);
24712 /* Return non-zero if ATTR's value is a section offset --- classes
24713 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
24714 You may use DW_UNSND (attr) to retrieve such offsets.
24716 Section 7.5.4, "Attribute Encodings", explains that no attribute
24717 may have a value that belongs to more than one of these classes; it
24718 would be ambiguous if we did, because we use the same forms for all
24722 attr_form_is_section_offset (const struct attribute
*attr
)
24724 return (attr
->form
== DW_FORM_data4
24725 || attr
->form
== DW_FORM_data8
24726 || attr
->form
== DW_FORM_sec_offset
);
24729 /* Return non-zero if ATTR's value falls in the 'constant' class, or
24730 zero otherwise. When this function returns true, you can apply
24731 dwarf2_get_attr_constant_value to it.
24733 However, note that for some attributes you must check
24734 attr_form_is_section_offset before using this test. DW_FORM_data4
24735 and DW_FORM_data8 are members of both the constant class, and of
24736 the classes that contain offsets into other debug sections
24737 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
24738 that, if an attribute's can be either a constant or one of the
24739 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
24740 taken as section offsets, not constants.
24742 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
24743 cannot handle that. */
24746 attr_form_is_constant (const struct attribute
*attr
)
24748 switch (attr
->form
)
24750 case DW_FORM_sdata
:
24751 case DW_FORM_udata
:
24752 case DW_FORM_data1
:
24753 case DW_FORM_data2
:
24754 case DW_FORM_data4
:
24755 case DW_FORM_data8
:
24756 case DW_FORM_implicit_const
:
24764 /* DW_ADDR is always stored already as sect_offset; despite for the forms
24765 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
24768 attr_form_is_ref (const struct attribute
*attr
)
24770 switch (attr
->form
)
24772 case DW_FORM_ref_addr
:
24777 case DW_FORM_ref_udata
:
24778 case DW_FORM_GNU_ref_alt
:
24785 /* Return the .debug_loc section to use for CU.
24786 For DWO files use .debug_loc.dwo. */
24788 static struct dwarf2_section_info
*
24789 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24791 struct dwarf2_per_objfile
*dwarf2_per_objfile
24792 = cu
->per_cu
->dwarf2_per_objfile
;
24796 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24798 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24800 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
24801 : &dwarf2_per_objfile
->loc
);
24804 /* A helper function that fills in a dwarf2_loclist_baton. */
24807 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24808 struct dwarf2_loclist_baton
*baton
,
24809 const struct attribute
*attr
)
24811 struct dwarf2_per_objfile
*dwarf2_per_objfile
24812 = cu
->per_cu
->dwarf2_per_objfile
;
24813 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24815 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
24817 baton
->per_cu
= cu
->per_cu
;
24818 gdb_assert (baton
->per_cu
);
24819 /* We don't know how long the location list is, but make sure we
24820 don't run off the edge of the section. */
24821 baton
->size
= section
->size
- DW_UNSND (attr
);
24822 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
24823 baton
->base_address
= cu
->base_address
;
24824 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24828 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24829 struct dwarf2_cu
*cu
, int is_block
)
24831 struct dwarf2_per_objfile
*dwarf2_per_objfile
24832 = cu
->per_cu
->dwarf2_per_objfile
;
24833 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24834 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24836 if (attr_form_is_section_offset (attr
)
24837 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24838 the section. If so, fall through to the complaint in the
24840 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
24842 struct dwarf2_loclist_baton
*baton
;
24844 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24846 fill_in_loclist_baton (cu
, baton
, attr
);
24848 if (cu
->base_known
== 0)
24849 complaint (&symfile_complaints
,
24850 _("Location list used without "
24851 "specifying the CU base address."));
24853 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24854 ? dwarf2_loclist_block_index
24855 : dwarf2_loclist_index
);
24856 SYMBOL_LOCATION_BATON (sym
) = baton
;
24860 struct dwarf2_locexpr_baton
*baton
;
24862 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24863 baton
->per_cu
= cu
->per_cu
;
24864 gdb_assert (baton
->per_cu
);
24866 if (attr_form_is_block (attr
))
24868 /* Note that we're just copying the block's data pointer
24869 here, not the actual data. We're still pointing into the
24870 info_buffer for SYM's objfile; right now we never release
24871 that buffer, but when we do clean up properly this may
24873 baton
->size
= DW_BLOCK (attr
)->size
;
24874 baton
->data
= DW_BLOCK (attr
)->data
;
24878 dwarf2_invalid_attrib_class_complaint ("location description",
24879 SYMBOL_NATURAL_NAME (sym
));
24883 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24884 ? dwarf2_locexpr_block_index
24885 : dwarf2_locexpr_index
);
24886 SYMBOL_LOCATION_BATON (sym
) = baton
;
24890 /* Return the OBJFILE associated with the compilation unit CU. If CU
24891 came from a separate debuginfo file, then the master objfile is
24895 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
24897 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24899 /* Return the master objfile, so that we can report and look up the
24900 correct file containing this variable. */
24901 if (objfile
->separate_debug_objfile_backlink
)
24902 objfile
= objfile
->separate_debug_objfile_backlink
;
24907 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24908 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24909 CU_HEADERP first. */
24911 static const struct comp_unit_head
*
24912 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24913 struct dwarf2_per_cu_data
*per_cu
)
24915 const gdb_byte
*info_ptr
;
24918 return &per_cu
->cu
->header
;
24920 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24922 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24923 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24924 rcuh_kind::COMPILE
);
24929 /* Return the address size given in the compilation unit header for CU. */
24932 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24934 struct comp_unit_head cu_header_local
;
24935 const struct comp_unit_head
*cu_headerp
;
24937 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24939 return cu_headerp
->addr_size
;
24942 /* Return the offset size given in the compilation unit header for CU. */
24945 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
24947 struct comp_unit_head cu_header_local
;
24948 const struct comp_unit_head
*cu_headerp
;
24950 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24952 return cu_headerp
->offset_size
;
24955 /* See its dwarf2loc.h declaration. */
24958 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24960 struct comp_unit_head cu_header_local
;
24961 const struct comp_unit_head
*cu_headerp
;
24963 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24965 if (cu_headerp
->version
== 2)
24966 return cu_headerp
->addr_size
;
24968 return cu_headerp
->offset_size
;
24971 /* Return the text offset of the CU. The returned offset comes from
24972 this CU's objfile. If this objfile came from a separate debuginfo
24973 file, then the offset may be different from the corresponding
24974 offset in the parent objfile. */
24977 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
24979 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24981 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
24984 /* Return DWARF version number of PER_CU. */
24987 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
24989 return per_cu
->dwarf_version
;
24992 /* Locate the .debug_info compilation unit from CU's objfile which contains
24993 the DIE at OFFSET. Raises an error on failure. */
24995 static struct dwarf2_per_cu_data
*
24996 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24997 unsigned int offset_in_dwz
,
24998 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25000 struct dwarf2_per_cu_data
*this_cu
;
25002 const sect_offset
*cu_off
;
25005 high
= dwarf2_per_objfile
->n_comp_units
- 1;
25008 struct dwarf2_per_cu_data
*mid_cu
;
25009 int mid
= low
+ (high
- low
) / 2;
25011 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25012 cu_off
= &mid_cu
->sect_off
;
25013 if (mid_cu
->is_dwz
> offset_in_dwz
25014 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
25019 gdb_assert (low
== high
);
25020 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25021 cu_off
= &this_cu
->sect_off
;
25022 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
25024 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25025 error (_("Dwarf Error: could not find partial DIE containing "
25026 "offset %s [in module %s]"),
25027 sect_offset_str (sect_off
),
25028 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25030 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25032 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25036 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25037 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
25038 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25039 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25040 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25045 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25047 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25048 : per_cu (per_cu_
),
25051 checked_producer (0),
25052 producer_is_gxx_lt_4_6 (0),
25053 producer_is_gcc_lt_4_3 (0),
25054 producer_is_icc_lt_14 (0),
25055 processing_has_namespace_info (0)
25060 /* Destroy a dwarf2_cu. */
25062 dwarf2_cu::~dwarf2_cu ()
25067 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25070 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25071 enum language pretend_language
)
25073 struct attribute
*attr
;
25075 /* Set the language we're debugging. */
25076 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25078 set_cu_language (DW_UNSND (attr
), cu
);
25081 cu
->language
= pretend_language
;
25082 cu
->language_defn
= language_def (cu
->language
);
25085 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25088 /* Increase the age counter on each cached compilation unit, and free
25089 any that are too old. */
25092 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25094 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25096 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25097 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25098 while (per_cu
!= NULL
)
25100 per_cu
->cu
->last_used
++;
25101 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25102 dwarf2_mark (per_cu
->cu
);
25103 per_cu
= per_cu
->cu
->read_in_chain
;
25106 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25107 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25108 while (per_cu
!= NULL
)
25110 struct dwarf2_per_cu_data
*next_cu
;
25112 next_cu
= per_cu
->cu
->read_in_chain
;
25114 if (!per_cu
->cu
->mark
)
25117 *last_chain
= next_cu
;
25120 last_chain
= &per_cu
->cu
->read_in_chain
;
25126 /* Remove a single compilation unit from the cache. */
25129 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25131 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25132 struct dwarf2_per_objfile
*dwarf2_per_objfile
25133 = target_per_cu
->dwarf2_per_objfile
;
25135 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25136 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25137 while (per_cu
!= NULL
)
25139 struct dwarf2_per_cu_data
*next_cu
;
25141 next_cu
= per_cu
->cu
->read_in_chain
;
25143 if (per_cu
== target_per_cu
)
25147 *last_chain
= next_cu
;
25151 last_chain
= &per_cu
->cu
->read_in_chain
;
25157 /* Release all extra memory associated with OBJFILE. */
25160 dwarf2_free_objfile (struct objfile
*objfile
)
25162 struct dwarf2_per_objfile
*dwarf2_per_objfile
25163 = get_dwarf2_per_objfile (objfile
);
25165 delete dwarf2_per_objfile
;
25168 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25169 We store these in a hash table separate from the DIEs, and preserve them
25170 when the DIEs are flushed out of cache.
25172 The CU "per_cu" pointer is needed because offset alone is not enough to
25173 uniquely identify the type. A file may have multiple .debug_types sections,
25174 or the type may come from a DWO file. Furthermore, while it's more logical
25175 to use per_cu->section+offset, with Fission the section with the data is in
25176 the DWO file but we don't know that section at the point we need it.
25177 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25178 because we can enter the lookup routine, get_die_type_at_offset, from
25179 outside this file, and thus won't necessarily have PER_CU->cu.
25180 Fortunately, PER_CU is stable for the life of the objfile. */
25182 struct dwarf2_per_cu_offset_and_type
25184 const struct dwarf2_per_cu_data
*per_cu
;
25185 sect_offset sect_off
;
25189 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25192 per_cu_offset_and_type_hash (const void *item
)
25194 const struct dwarf2_per_cu_offset_and_type
*ofs
25195 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25197 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25200 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25203 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25205 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25206 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25207 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25208 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25210 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25211 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25214 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25215 table if necessary. For convenience, return TYPE.
25217 The DIEs reading must have careful ordering to:
25218 * Not cause infite loops trying to read in DIEs as a prerequisite for
25219 reading current DIE.
25220 * Not trying to dereference contents of still incompletely read in types
25221 while reading in other DIEs.
25222 * Enable referencing still incompletely read in types just by a pointer to
25223 the type without accessing its fields.
25225 Therefore caller should follow these rules:
25226 * Try to fetch any prerequisite types we may need to build this DIE type
25227 before building the type and calling set_die_type.
25228 * After building type call set_die_type for current DIE as soon as
25229 possible before fetching more types to complete the current type.
25230 * Make the type as complete as possible before fetching more types. */
25232 static struct type
*
25233 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25235 struct dwarf2_per_objfile
*dwarf2_per_objfile
25236 = cu
->per_cu
->dwarf2_per_objfile
;
25237 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25238 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25239 struct attribute
*attr
;
25240 struct dynamic_prop prop
;
25242 /* For Ada types, make sure that the gnat-specific data is always
25243 initialized (if not already set). There are a few types where
25244 we should not be doing so, because the type-specific area is
25245 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25246 where the type-specific area is used to store the floatformat).
25247 But this is not a problem, because the gnat-specific information
25248 is actually not needed for these types. */
25249 if (need_gnat_info (cu
)
25250 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25251 && TYPE_CODE (type
) != TYPE_CODE_FLT
25252 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25253 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25254 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25255 && !HAVE_GNAT_AUX_INFO (type
))
25256 INIT_GNAT_SPECIFIC (type
);
25258 /* Read DW_AT_allocated and set in type. */
25259 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25260 if (attr_form_is_block (attr
))
25262 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25263 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25265 else if (attr
!= NULL
)
25267 complaint (&symfile_complaints
,
25268 _("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25269 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25270 sect_offset_str (die
->sect_off
));
25273 /* Read DW_AT_associated and set in type. */
25274 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25275 if (attr_form_is_block (attr
))
25277 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25278 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25280 else if (attr
!= NULL
)
25282 complaint (&symfile_complaints
,
25283 _("DW_AT_associated has the wrong form (%s) at DIE %s"),
25284 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25285 sect_offset_str (die
->sect_off
));
25288 /* Read DW_AT_data_location and set in type. */
25289 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25290 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25291 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25293 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25295 dwarf2_per_objfile
->die_type_hash
=
25296 htab_create_alloc_ex (127,
25297 per_cu_offset_and_type_hash
,
25298 per_cu_offset_and_type_eq
,
25300 &objfile
->objfile_obstack
,
25301 hashtab_obstack_allocate
,
25302 dummy_obstack_deallocate
);
25305 ofs
.per_cu
= cu
->per_cu
;
25306 ofs
.sect_off
= die
->sect_off
;
25308 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25309 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25311 complaint (&symfile_complaints
,
25312 _("A problem internal to GDB: DIE %s has type already set"),
25313 sect_offset_str (die
->sect_off
));
25314 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25315 struct dwarf2_per_cu_offset_and_type
);
25320 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25321 or return NULL if the die does not have a saved type. */
25323 static struct type
*
25324 get_die_type_at_offset (sect_offset sect_off
,
25325 struct dwarf2_per_cu_data
*per_cu
)
25327 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25328 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25330 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25333 ofs
.per_cu
= per_cu
;
25334 ofs
.sect_off
= sect_off
;
25335 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25336 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25343 /* Look up the type for DIE in CU in die_type_hash,
25344 or return NULL if DIE does not have a saved type. */
25346 static struct type
*
25347 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25349 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25352 /* Add a dependence relationship from CU to REF_PER_CU. */
25355 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25356 struct dwarf2_per_cu_data
*ref_per_cu
)
25360 if (cu
->dependencies
== NULL
)
25362 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25363 NULL
, &cu
->comp_unit_obstack
,
25364 hashtab_obstack_allocate
,
25365 dummy_obstack_deallocate
);
25367 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25369 *slot
= ref_per_cu
;
25372 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25373 Set the mark field in every compilation unit in the
25374 cache that we must keep because we are keeping CU. */
25377 dwarf2_mark_helper (void **slot
, void *data
)
25379 struct dwarf2_per_cu_data
*per_cu
;
25381 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25383 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25384 reading of the chain. As such dependencies remain valid it is not much
25385 useful to track and undo them during QUIT cleanups. */
25386 if (per_cu
->cu
== NULL
)
25389 if (per_cu
->cu
->mark
)
25391 per_cu
->cu
->mark
= 1;
25393 if (per_cu
->cu
->dependencies
!= NULL
)
25394 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25399 /* Set the mark field in CU and in every other compilation unit in the
25400 cache that we must keep because we are keeping CU. */
25403 dwarf2_mark (struct dwarf2_cu
*cu
)
25408 if (cu
->dependencies
!= NULL
)
25409 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25413 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25417 per_cu
->cu
->mark
= 0;
25418 per_cu
= per_cu
->cu
->read_in_chain
;
25422 /* Trivial hash function for partial_die_info: the hash value of a DIE
25423 is its offset in .debug_info for this objfile. */
25426 partial_die_hash (const void *item
)
25428 const struct partial_die_info
*part_die
25429 = (const struct partial_die_info
*) item
;
25431 return to_underlying (part_die
->sect_off
);
25434 /* Trivial comparison function for partial_die_info structures: two DIEs
25435 are equal if they have the same offset. */
25438 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25440 const struct partial_die_info
*part_die_lhs
25441 = (const struct partial_die_info
*) item_lhs
;
25442 const struct partial_die_info
*part_die_rhs
25443 = (const struct partial_die_info
*) item_rhs
;
25445 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25448 static struct cmd_list_element
*set_dwarf_cmdlist
;
25449 static struct cmd_list_element
*show_dwarf_cmdlist
;
25452 set_dwarf_cmd (const char *args
, int from_tty
)
25454 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25459 show_dwarf_cmd (const char *args
, int from_tty
)
25461 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25464 int dwarf_always_disassemble
;
25467 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
25468 struct cmd_list_element
*c
, const char *value
)
25470 fprintf_filtered (file
,
25471 _("Whether to always disassemble "
25472 "DWARF expressions is %s.\n"),
25477 show_check_physname (struct ui_file
*file
, int from_tty
,
25478 struct cmd_list_element
*c
, const char *value
)
25480 fprintf_filtered (file
,
25481 _("Whether to check \"physname\" is %s.\n"),
25486 _initialize_dwarf2_read (void)
25489 dwarf2_objfile_data_key
= register_objfile_data ();
25491 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
25492 Set DWARF specific variables.\n\
25493 Configure DWARF variables such as the cache size"),
25494 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25495 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25497 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
25498 Show DWARF specific variables\n\
25499 Show DWARF variables such as the cache size"),
25500 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25501 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25503 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25504 &dwarf_max_cache_age
, _("\
25505 Set the upper bound on the age of cached DWARF compilation units."), _("\
25506 Show the upper bound on the age of cached DWARF compilation units."), _("\
25507 A higher limit means that cached compilation units will be stored\n\
25508 in memory longer, and more total memory will be used. Zero disables\n\
25509 caching, which can slow down startup."),
25511 show_dwarf_max_cache_age
,
25512 &set_dwarf_cmdlist
,
25513 &show_dwarf_cmdlist
);
25515 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
25516 &dwarf_always_disassemble
, _("\
25517 Set whether `info address' always disassembles DWARF expressions."), _("\
25518 Show whether `info address' always disassembles DWARF expressions."), _("\
25519 When enabled, DWARF expressions are always printed in an assembly-like\n\
25520 syntax. When disabled, expressions will be printed in a more\n\
25521 conversational style, when possible."),
25523 show_dwarf_always_disassemble
,
25524 &set_dwarf_cmdlist
,
25525 &show_dwarf_cmdlist
);
25527 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25528 Set debugging of the DWARF reader."), _("\
25529 Show debugging of the DWARF reader."), _("\
25530 When enabled (non-zero), debugging messages are printed during DWARF\n\
25531 reading and symtab expansion. A value of 1 (one) provides basic\n\
25532 information. A value greater than 1 provides more verbose information."),
25535 &setdebuglist
, &showdebuglist
);
25537 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25538 Set debugging of the DWARF DIE reader."), _("\
25539 Show debugging of the DWARF DIE reader."), _("\
25540 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25541 The value is the maximum depth to print."),
25544 &setdebuglist
, &showdebuglist
);
25546 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25547 Set debugging of the dwarf line reader."), _("\
25548 Show debugging of the dwarf line reader."), _("\
25549 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25550 A value of 1 (one) provides basic information.\n\
25551 A value greater than 1 provides more verbose information."),
25554 &setdebuglist
, &showdebuglist
);
25556 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25557 Set cross-checking of \"physname\" code against demangler."), _("\
25558 Show cross-checking of \"physname\" code against demangler."), _("\
25559 When enabled, GDB's internal \"physname\" code is checked against\n\
25561 NULL
, show_check_physname
,
25562 &setdebuglist
, &showdebuglist
);
25564 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25565 no_class
, &use_deprecated_index_sections
, _("\
25566 Set whether to use deprecated gdb_index sections."), _("\
25567 Show whether to use deprecated gdb_index sections."), _("\
25568 When enabled, deprecated .gdb_index sections are used anyway.\n\
25569 Normally they are ignored either because of a missing feature or\n\
25570 performance issue.\n\
25571 Warning: This option must be enabled before gdb reads the file."),
25574 &setlist
, &showlist
);
25576 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25577 &dwarf2_locexpr_funcs
);
25578 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25579 &dwarf2_loclist_funcs
);
25581 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25582 &dwarf2_block_frame_base_locexpr_funcs
);
25583 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25584 &dwarf2_block_frame_base_loclist_funcs
);
25587 selftests::register_test ("dw2_expand_symtabs_matching",
25588 selftests::dw2_expand_symtabs_matching::run_test
);