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 (struct dwo_file
*);
1964 /* A unique_ptr helper to free a dwo_file. */
1966 struct dwo_file_deleter
1968 void operator() (struct dwo_file
*df
) const
1974 /* A unique pointer to a dwo_file. */
1976 typedef std::unique_ptr
<struct dwo_file
, dwo_file_deleter
> dwo_file_up
;
1978 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1980 static void check_producer (struct dwarf2_cu
*cu
);
1982 static void free_line_header_voidp (void *arg
);
1984 /* Various complaints about symbol reading that don't abort the process. */
1987 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1989 complaint (&symfile_complaints
,
1990 _("statement list doesn't fit in .debug_line section"));
1994 dwarf2_debug_line_missing_file_complaint (void)
1996 complaint (&symfile_complaints
,
1997 _(".debug_line section has line data without a file"));
2001 dwarf2_debug_line_missing_end_sequence_complaint (void)
2003 complaint (&symfile_complaints
,
2004 _(".debug_line section has line "
2005 "program sequence without an end"));
2009 dwarf2_complex_location_expr_complaint (void)
2011 complaint (&symfile_complaints
, _("location expression too complex"));
2015 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2018 complaint (&symfile_complaints
,
2019 _("const value length mismatch for '%s', got %d, expected %d"),
2024 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2026 complaint (&symfile_complaints
,
2027 _("debug info runs off end of %s section"
2029 get_section_name (section
),
2030 get_section_file_name (section
));
2034 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2036 complaint (&symfile_complaints
,
2037 _("macro debug info contains a "
2038 "malformed macro definition:\n`%s'"),
2043 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2045 complaint (&symfile_complaints
,
2046 _("invalid attribute class or form for '%s' in '%s'"),
2050 /* Hash function for line_header_hash. */
2053 line_header_hash (const struct line_header
*ofs
)
2055 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2058 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2061 line_header_hash_voidp (const void *item
)
2063 const struct line_header
*ofs
= (const struct line_header
*) item
;
2065 return line_header_hash (ofs
);
2068 /* Equality function for line_header_hash. */
2071 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2073 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2074 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2076 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2077 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2082 /* Read the given attribute value as an address, taking the attribute's
2083 form into account. */
2086 attr_value_as_address (struct attribute
*attr
)
2090 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2092 /* Aside from a few clearly defined exceptions, attributes that
2093 contain an address must always be in DW_FORM_addr form.
2094 Unfortunately, some compilers happen to be violating this
2095 requirement by encoding addresses using other forms, such
2096 as DW_FORM_data4 for example. For those broken compilers,
2097 we try to do our best, without any guarantee of success,
2098 to interpret the address correctly. It would also be nice
2099 to generate a complaint, but that would require us to maintain
2100 a list of legitimate cases where a non-address form is allowed,
2101 as well as update callers to pass in at least the CU's DWARF
2102 version. This is more overhead than what we're willing to
2103 expand for a pretty rare case. */
2104 addr
= DW_UNSND (attr
);
2107 addr
= DW_ADDR (attr
);
2112 /* See declaration. */
2114 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2115 const dwarf2_debug_sections
*names
)
2116 : objfile (objfile_
)
2119 names
= &dwarf2_elf_names
;
2121 bfd
*obfd
= objfile
->obfd
;
2123 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2124 locate_sections (obfd
, sec
, *names
);
2127 static void free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
);
2129 dwarf2_per_objfile::~dwarf2_per_objfile ()
2131 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2132 free_cached_comp_units ();
2134 if (quick_file_names_table
)
2135 htab_delete (quick_file_names_table
);
2137 if (line_header_hash
)
2138 htab_delete (line_header_hash
);
2140 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2141 VEC_free (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
);
2143 for (int ix
= 0; ix
< n_type_units
; ++ix
)
2144 VEC_free (dwarf2_per_cu_ptr
,
2145 all_type_units
[ix
]->per_cu
.imported_symtabs
);
2146 xfree (all_type_units
);
2148 VEC_free (dwarf2_section_info_def
, types
);
2150 if (dwo_files
!= NULL
)
2151 free_dwo_files (dwo_files
, objfile
);
2152 if (dwp_file
!= NULL
)
2153 gdb_bfd_unref (dwp_file
->dbfd
);
2155 if (dwz_file
!= NULL
&& dwz_file
->dwz_bfd
)
2156 gdb_bfd_unref (dwz_file
->dwz_bfd
);
2158 if (index_table
!= NULL
)
2159 index_table
->~mapped_index ();
2161 /* Everything else should be on the objfile obstack. */
2164 /* See declaration. */
2167 dwarf2_per_objfile::free_cached_comp_units ()
2169 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2170 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2171 while (per_cu
!= NULL
)
2173 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2176 *last_chain
= next_cu
;
2181 /* A helper class that calls free_cached_comp_units on
2184 class free_cached_comp_units
2188 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2189 : m_per_objfile (per_objfile
)
2193 ~free_cached_comp_units ()
2195 m_per_objfile
->free_cached_comp_units ();
2198 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2202 dwarf2_per_objfile
*m_per_objfile
;
2205 /* Try to locate the sections we need for DWARF 2 debugging
2206 information and return true if we have enough to do something.
2207 NAMES points to the dwarf2 section names, or is NULL if the standard
2208 ELF names are used. */
2211 dwarf2_has_info (struct objfile
*objfile
,
2212 const struct dwarf2_debug_sections
*names
)
2214 if (objfile
->flags
& OBJF_READNEVER
)
2217 struct dwarf2_per_objfile
*dwarf2_per_objfile
2218 = get_dwarf2_per_objfile (objfile
);
2220 if (dwarf2_per_objfile
== NULL
)
2222 /* Initialize per-objfile state. */
2224 = new (&objfile
->objfile_obstack
) struct dwarf2_per_objfile (objfile
,
2226 set_dwarf2_per_objfile (objfile
, dwarf2_per_objfile
);
2228 return (!dwarf2_per_objfile
->info
.is_virtual
2229 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2230 && !dwarf2_per_objfile
->abbrev
.is_virtual
2231 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2234 /* Return the containing section of virtual section SECTION. */
2236 static struct dwarf2_section_info
*
2237 get_containing_section (const struct dwarf2_section_info
*section
)
2239 gdb_assert (section
->is_virtual
);
2240 return section
->s
.containing_section
;
2243 /* Return the bfd owner of SECTION. */
2246 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2248 if (section
->is_virtual
)
2250 section
= get_containing_section (section
);
2251 gdb_assert (!section
->is_virtual
);
2253 return section
->s
.section
->owner
;
2256 /* Return the bfd section of SECTION.
2257 Returns NULL if the section is not present. */
2260 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2262 if (section
->is_virtual
)
2264 section
= get_containing_section (section
);
2265 gdb_assert (!section
->is_virtual
);
2267 return section
->s
.section
;
2270 /* Return the name of SECTION. */
2273 get_section_name (const struct dwarf2_section_info
*section
)
2275 asection
*sectp
= get_section_bfd_section (section
);
2277 gdb_assert (sectp
!= NULL
);
2278 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2281 /* Return the name of the file SECTION is in. */
2284 get_section_file_name (const struct dwarf2_section_info
*section
)
2286 bfd
*abfd
= get_section_bfd_owner (section
);
2288 return bfd_get_filename (abfd
);
2291 /* Return the id of SECTION.
2292 Returns 0 if SECTION doesn't exist. */
2295 get_section_id (const struct dwarf2_section_info
*section
)
2297 asection
*sectp
= get_section_bfd_section (section
);
2304 /* Return the flags of SECTION.
2305 SECTION (or containing section if this is a virtual section) must exist. */
2308 get_section_flags (const struct dwarf2_section_info
*section
)
2310 asection
*sectp
= get_section_bfd_section (section
);
2312 gdb_assert (sectp
!= NULL
);
2313 return bfd_get_section_flags (sectp
->owner
, sectp
);
2316 /* When loading sections, we look either for uncompressed section or for
2317 compressed section names. */
2320 section_is_p (const char *section_name
,
2321 const struct dwarf2_section_names
*names
)
2323 if (names
->normal
!= NULL
2324 && strcmp (section_name
, names
->normal
) == 0)
2326 if (names
->compressed
!= NULL
2327 && strcmp (section_name
, names
->compressed
) == 0)
2332 /* See declaration. */
2335 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2336 const dwarf2_debug_sections
&names
)
2338 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2340 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2343 else if (section_is_p (sectp
->name
, &names
.info
))
2345 this->info
.s
.section
= sectp
;
2346 this->info
.size
= bfd_get_section_size (sectp
);
2348 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2350 this->abbrev
.s
.section
= sectp
;
2351 this->abbrev
.size
= bfd_get_section_size (sectp
);
2353 else if (section_is_p (sectp
->name
, &names
.line
))
2355 this->line
.s
.section
= sectp
;
2356 this->line
.size
= bfd_get_section_size (sectp
);
2358 else if (section_is_p (sectp
->name
, &names
.loc
))
2360 this->loc
.s
.section
= sectp
;
2361 this->loc
.size
= bfd_get_section_size (sectp
);
2363 else if (section_is_p (sectp
->name
, &names
.loclists
))
2365 this->loclists
.s
.section
= sectp
;
2366 this->loclists
.size
= bfd_get_section_size (sectp
);
2368 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2370 this->macinfo
.s
.section
= sectp
;
2371 this->macinfo
.size
= bfd_get_section_size (sectp
);
2373 else if (section_is_p (sectp
->name
, &names
.macro
))
2375 this->macro
.s
.section
= sectp
;
2376 this->macro
.size
= bfd_get_section_size (sectp
);
2378 else if (section_is_p (sectp
->name
, &names
.str
))
2380 this->str
.s
.section
= sectp
;
2381 this->str
.size
= bfd_get_section_size (sectp
);
2383 else if (section_is_p (sectp
->name
, &names
.line_str
))
2385 this->line_str
.s
.section
= sectp
;
2386 this->line_str
.size
= bfd_get_section_size (sectp
);
2388 else if (section_is_p (sectp
->name
, &names
.addr
))
2390 this->addr
.s
.section
= sectp
;
2391 this->addr
.size
= bfd_get_section_size (sectp
);
2393 else if (section_is_p (sectp
->name
, &names
.frame
))
2395 this->frame
.s
.section
= sectp
;
2396 this->frame
.size
= bfd_get_section_size (sectp
);
2398 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2400 this->eh_frame
.s
.section
= sectp
;
2401 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2403 else if (section_is_p (sectp
->name
, &names
.ranges
))
2405 this->ranges
.s
.section
= sectp
;
2406 this->ranges
.size
= bfd_get_section_size (sectp
);
2408 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2410 this->rnglists
.s
.section
= sectp
;
2411 this->rnglists
.size
= bfd_get_section_size (sectp
);
2413 else if (section_is_p (sectp
->name
, &names
.types
))
2415 struct dwarf2_section_info type_section
;
2417 memset (&type_section
, 0, sizeof (type_section
));
2418 type_section
.s
.section
= sectp
;
2419 type_section
.size
= bfd_get_section_size (sectp
);
2421 VEC_safe_push (dwarf2_section_info_def
, this->types
,
2424 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2426 this->gdb_index
.s
.section
= sectp
;
2427 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2429 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2431 this->debug_names
.s
.section
= sectp
;
2432 this->debug_names
.size
= bfd_get_section_size (sectp
);
2434 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2436 this->debug_aranges
.s
.section
= sectp
;
2437 this->debug_aranges
.size
= bfd_get_section_size (sectp
);
2440 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2441 && bfd_section_vma (abfd
, sectp
) == 0)
2442 this->has_section_at_zero
= true;
2445 /* A helper function that decides whether a section is empty,
2449 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2451 if (section
->is_virtual
)
2452 return section
->size
== 0;
2453 return section
->s
.section
== NULL
|| section
->size
== 0;
2456 /* See dwarf2read.h. */
2459 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2463 gdb_byte
*buf
, *retbuf
;
2467 info
->buffer
= NULL
;
2470 if (dwarf2_section_empty_p (info
))
2473 sectp
= get_section_bfd_section (info
);
2475 /* If this is a virtual section we need to read in the real one first. */
2476 if (info
->is_virtual
)
2478 struct dwarf2_section_info
*containing_section
=
2479 get_containing_section (info
);
2481 gdb_assert (sectp
!= NULL
);
2482 if ((sectp
->flags
& SEC_RELOC
) != 0)
2484 error (_("Dwarf Error: DWP format V2 with relocations is not"
2485 " supported in section %s [in module %s]"),
2486 get_section_name (info
), get_section_file_name (info
));
2488 dwarf2_read_section (objfile
, containing_section
);
2489 /* Other code should have already caught virtual sections that don't
2491 gdb_assert (info
->virtual_offset
+ info
->size
2492 <= containing_section
->size
);
2493 /* If the real section is empty or there was a problem reading the
2494 section we shouldn't get here. */
2495 gdb_assert (containing_section
->buffer
!= NULL
);
2496 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2500 /* If the section has relocations, we must read it ourselves.
2501 Otherwise we attach it to the BFD. */
2502 if ((sectp
->flags
& SEC_RELOC
) == 0)
2504 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2508 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2511 /* When debugging .o files, we may need to apply relocations; see
2512 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2513 We never compress sections in .o files, so we only need to
2514 try this when the section is not compressed. */
2515 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2518 info
->buffer
= retbuf
;
2522 abfd
= get_section_bfd_owner (info
);
2523 gdb_assert (abfd
!= NULL
);
2525 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2526 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2528 error (_("Dwarf Error: Can't read DWARF data"
2529 " in section %s [in module %s]"),
2530 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2534 /* A helper function that returns the size of a section in a safe way.
2535 If you are positive that the section has been read before using the
2536 size, then it is safe to refer to the dwarf2_section_info object's
2537 "size" field directly. In other cases, you must call this
2538 function, because for compressed sections the size field is not set
2539 correctly until the section has been read. */
2541 static bfd_size_type
2542 dwarf2_section_size (struct objfile
*objfile
,
2543 struct dwarf2_section_info
*info
)
2546 dwarf2_read_section (objfile
, info
);
2550 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2554 dwarf2_get_section_info (struct objfile
*objfile
,
2555 enum dwarf2_section_enum sect
,
2556 asection
**sectp
, const gdb_byte
**bufp
,
2557 bfd_size_type
*sizep
)
2559 struct dwarf2_per_objfile
*data
2560 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2561 dwarf2_objfile_data_key
);
2562 struct dwarf2_section_info
*info
;
2564 /* We may see an objfile without any DWARF, in which case we just
2575 case DWARF2_DEBUG_FRAME
:
2576 info
= &data
->frame
;
2578 case DWARF2_EH_FRAME
:
2579 info
= &data
->eh_frame
;
2582 gdb_assert_not_reached ("unexpected section");
2585 dwarf2_read_section (objfile
, info
);
2587 *sectp
= get_section_bfd_section (info
);
2588 *bufp
= info
->buffer
;
2589 *sizep
= info
->size
;
2592 /* A helper function to find the sections for a .dwz file. */
2595 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2597 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2599 /* Note that we only support the standard ELF names, because .dwz
2600 is ELF-only (at the time of writing). */
2601 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2603 dwz_file
->abbrev
.s
.section
= sectp
;
2604 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2606 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2608 dwz_file
->info
.s
.section
= sectp
;
2609 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2611 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2613 dwz_file
->str
.s
.section
= sectp
;
2614 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2616 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2618 dwz_file
->line
.s
.section
= sectp
;
2619 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2621 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2623 dwz_file
->macro
.s
.section
= sectp
;
2624 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2626 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2628 dwz_file
->gdb_index
.s
.section
= sectp
;
2629 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2631 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2633 dwz_file
->debug_names
.s
.section
= sectp
;
2634 dwz_file
->debug_names
.size
= bfd_get_section_size (sectp
);
2638 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2639 there is no .gnu_debugaltlink section in the file. Error if there
2640 is such a section but the file cannot be found. */
2642 static struct dwz_file
*
2643 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2645 const char *filename
;
2646 struct dwz_file
*result
;
2647 bfd_size_type buildid_len_arg
;
2651 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2652 return dwarf2_per_objfile
->dwz_file
;
2654 bfd_set_error (bfd_error_no_error
);
2655 gdb::unique_xmalloc_ptr
<char> data
2656 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2657 &buildid_len_arg
, &buildid
));
2660 if (bfd_get_error () == bfd_error_no_error
)
2662 error (_("could not read '.gnu_debugaltlink' section: %s"),
2663 bfd_errmsg (bfd_get_error ()));
2666 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2668 buildid_len
= (size_t) buildid_len_arg
;
2670 filename
= data
.get ();
2672 std::string abs_storage
;
2673 if (!IS_ABSOLUTE_PATH (filename
))
2675 gdb::unique_xmalloc_ptr
<char> abs
2676 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2678 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2679 filename
= abs_storage
.c_str ();
2682 /* First try the file name given in the section. If that doesn't
2683 work, try to use the build-id instead. */
2684 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2685 if (dwz_bfd
!= NULL
)
2687 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2691 if (dwz_bfd
== NULL
)
2692 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2694 if (dwz_bfd
== NULL
)
2695 error (_("could not find '.gnu_debugaltlink' file for %s"),
2696 objfile_name (dwarf2_per_objfile
->objfile
));
2698 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2700 result
->dwz_bfd
= dwz_bfd
.release ();
2702 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
2704 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
2705 dwarf2_per_objfile
->dwz_file
= result
;
2709 /* DWARF quick_symbols_functions support. */
2711 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2712 unique line tables, so we maintain a separate table of all .debug_line
2713 derived entries to support the sharing.
2714 All the quick functions need is the list of file names. We discard the
2715 line_header when we're done and don't need to record it here. */
2716 struct quick_file_names
2718 /* The data used to construct the hash key. */
2719 struct stmt_list_hash hash
;
2721 /* The number of entries in file_names, real_names. */
2722 unsigned int num_file_names
;
2724 /* The file names from the line table, after being run through
2726 const char **file_names
;
2728 /* The file names from the line table after being run through
2729 gdb_realpath. These are computed lazily. */
2730 const char **real_names
;
2733 /* When using the index (and thus not using psymtabs), each CU has an
2734 object of this type. This is used to hold information needed by
2735 the various "quick" methods. */
2736 struct dwarf2_per_cu_quick_data
2738 /* The file table. This can be NULL if there was no file table
2739 or it's currently not read in.
2740 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2741 struct quick_file_names
*file_names
;
2743 /* The corresponding symbol table. This is NULL if symbols for this
2744 CU have not yet been read. */
2745 struct compunit_symtab
*compunit_symtab
;
2747 /* A temporary mark bit used when iterating over all CUs in
2748 expand_symtabs_matching. */
2749 unsigned int mark
: 1;
2751 /* True if we've tried to read the file table and found there isn't one.
2752 There will be no point in trying to read it again next time. */
2753 unsigned int no_file_data
: 1;
2756 /* Utility hash function for a stmt_list_hash. */
2759 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2763 if (stmt_list_hash
->dwo_unit
!= NULL
)
2764 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2765 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2769 /* Utility equality function for a stmt_list_hash. */
2772 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2773 const struct stmt_list_hash
*rhs
)
2775 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2777 if (lhs
->dwo_unit
!= NULL
2778 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2781 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2784 /* Hash function for a quick_file_names. */
2787 hash_file_name_entry (const void *e
)
2789 const struct quick_file_names
*file_data
2790 = (const struct quick_file_names
*) e
;
2792 return hash_stmt_list_entry (&file_data
->hash
);
2795 /* Equality function for a quick_file_names. */
2798 eq_file_name_entry (const void *a
, const void *b
)
2800 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2801 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2803 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2806 /* Delete function for a quick_file_names. */
2809 delete_file_name_entry (void *e
)
2811 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2814 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2816 xfree ((void*) file_data
->file_names
[i
]);
2817 if (file_data
->real_names
)
2818 xfree ((void*) file_data
->real_names
[i
]);
2821 /* The space for the struct itself lives on objfile_obstack,
2822 so we don't free it here. */
2825 /* Create a quick_file_names hash table. */
2828 create_quick_file_names_table (unsigned int nr_initial_entries
)
2830 return htab_create_alloc (nr_initial_entries
,
2831 hash_file_name_entry
, eq_file_name_entry
,
2832 delete_file_name_entry
, xcalloc
, xfree
);
2835 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2836 have to be created afterwards. You should call age_cached_comp_units after
2837 processing PER_CU->CU. dw2_setup must have been already called. */
2840 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2842 if (per_cu
->is_debug_types
)
2843 load_full_type_unit (per_cu
);
2845 load_full_comp_unit (per_cu
, language_minimal
);
2847 if (per_cu
->cu
== NULL
)
2848 return; /* Dummy CU. */
2850 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2853 /* Read in the symbols for PER_CU. */
2856 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2858 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2860 /* Skip type_unit_groups, reading the type units they contain
2861 is handled elsewhere. */
2862 if (IS_TYPE_UNIT_GROUP (per_cu
))
2865 /* The destructor of dwarf2_queue_guard frees any entries left on
2866 the queue. After this point we're guaranteed to leave this function
2867 with the dwarf queue empty. */
2868 dwarf2_queue_guard q_guard
;
2870 if (dwarf2_per_objfile
->using_index
2871 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2872 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2874 queue_comp_unit (per_cu
, language_minimal
);
2877 /* If we just loaded a CU from a DWO, and we're working with an index
2878 that may badly handle TUs, load all the TUs in that DWO as well.
2879 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2880 if (!per_cu
->is_debug_types
2881 && per_cu
->cu
!= NULL
2882 && per_cu
->cu
->dwo_unit
!= NULL
2883 && dwarf2_per_objfile
->index_table
!= NULL
2884 && dwarf2_per_objfile
->index_table
->version
<= 7
2885 /* DWP files aren't supported yet. */
2886 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2887 queue_and_load_all_dwo_tus (per_cu
);
2890 process_queue (dwarf2_per_objfile
);
2892 /* Age the cache, releasing compilation units that have not
2893 been used recently. */
2894 age_cached_comp_units (dwarf2_per_objfile
);
2897 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2898 the objfile from which this CU came. Returns the resulting symbol
2901 static struct compunit_symtab
*
2902 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2904 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2906 gdb_assert (dwarf2_per_objfile
->using_index
);
2907 if (!per_cu
->v
.quick
->compunit_symtab
)
2909 free_cached_comp_units
freer (dwarf2_per_objfile
);
2910 scoped_restore decrementer
= increment_reading_symtab ();
2911 dw2_do_instantiate_symtab (per_cu
);
2912 process_cu_includes (dwarf2_per_objfile
);
2915 return per_cu
->v
.quick
->compunit_symtab
;
2918 /* See declaration. */
2920 dwarf2_per_cu_data
*
2921 dwarf2_per_objfile::get_cutu (int index
)
2923 if (index
>= this->all_comp_units
.size ())
2925 index
-= this->all_comp_units
.size ();
2926 gdb_assert (index
< this->n_type_units
);
2927 return &this->all_type_units
[index
]->per_cu
;
2930 return this->all_comp_units
[index
];
2933 /* See declaration. */
2935 dwarf2_per_cu_data
*
2936 dwarf2_per_objfile::get_cu (int index
)
2938 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2940 return this->all_comp_units
[index
];
2943 /* See declaration. */
2946 dwarf2_per_objfile::get_tu (int index
)
2948 gdb_assert (index
>= 0 && index
< this->n_type_units
);
2950 return this->all_type_units
[index
];
2953 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2954 objfile_obstack, and constructed with the specified field
2957 static dwarf2_per_cu_data
*
2958 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2959 struct dwarf2_section_info
*section
,
2961 sect_offset sect_off
, ULONGEST length
)
2963 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2964 dwarf2_per_cu_data
*the_cu
2965 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2966 struct dwarf2_per_cu_data
);
2967 the_cu
->sect_off
= sect_off
;
2968 the_cu
->length
= length
;
2969 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2970 the_cu
->section
= section
;
2971 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2972 struct dwarf2_per_cu_quick_data
);
2973 the_cu
->is_dwz
= is_dwz
;
2977 /* A helper for create_cus_from_index that handles a given list of
2981 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2982 const gdb_byte
*cu_list
, offset_type n_elements
,
2983 struct dwarf2_section_info
*section
,
2986 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2988 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2990 sect_offset sect_off
2991 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2992 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2995 dwarf2_per_cu_data
*per_cu
2996 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2998 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
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 dwarf2_per_objfile
*dwarf2_per_objfile
,
3007 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3008 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3010 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3011 dwarf2_per_objfile
->all_comp_units
.reserve
3012 ((cu_list_elements
+ dwz_elements
) / 2);
3014 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3015 &dwarf2_per_objfile
->info
, 0);
3017 if (dwz_elements
== 0)
3020 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3021 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3025 /* Create the signatured type hash table from the index. */
3028 create_signatured_type_table_from_index
3029 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3030 struct dwarf2_section_info
*section
,
3031 const gdb_byte
*bytes
,
3032 offset_type elements
)
3034 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3036 dwarf2_per_objfile
->n_type_units
3037 = dwarf2_per_objfile
->n_allocated_type_units
3039 dwarf2_per_objfile
->all_type_units
=
3040 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3042 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3044 for (offset_type i
= 0; i
< elements
; i
+= 3)
3046 struct signatured_type
*sig_type
;
3049 cu_offset type_offset_in_tu
;
3051 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3052 sect_offset sect_off
3053 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3055 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3057 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3060 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3061 struct signatured_type
);
3062 sig_type
->signature
= signature
;
3063 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3064 sig_type
->per_cu
.is_debug_types
= 1;
3065 sig_type
->per_cu
.section
= section
;
3066 sig_type
->per_cu
.sect_off
= sect_off
;
3067 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3068 sig_type
->per_cu
.v
.quick
3069 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3070 struct dwarf2_per_cu_quick_data
);
3072 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3075 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
3078 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3081 /* Create the signatured type hash table from .debug_names. */
3084 create_signatured_type_table_from_debug_names
3085 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3086 const mapped_debug_names
&map
,
3087 struct dwarf2_section_info
*section
,
3088 struct dwarf2_section_info
*abbrev_section
)
3090 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3092 dwarf2_read_section (objfile
, section
);
3093 dwarf2_read_section (objfile
, abbrev_section
);
3095 dwarf2_per_objfile
->n_type_units
3096 = dwarf2_per_objfile
->n_allocated_type_units
3098 dwarf2_per_objfile
->all_type_units
3099 = XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3101 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3103 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3105 struct signatured_type
*sig_type
;
3108 sect_offset sect_off
3109 = (sect_offset
) (extract_unsigned_integer
3110 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3112 map
.dwarf5_byte_order
));
3114 comp_unit_head cu_header
;
3115 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3117 section
->buffer
+ to_underlying (sect_off
),
3120 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3121 struct signatured_type
);
3122 sig_type
->signature
= cu_header
.signature
;
3123 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3124 sig_type
->per_cu
.is_debug_types
= 1;
3125 sig_type
->per_cu
.section
= section
;
3126 sig_type
->per_cu
.sect_off
= sect_off
;
3127 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3128 sig_type
->per_cu
.v
.quick
3129 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3130 struct dwarf2_per_cu_quick_data
);
3132 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3135 dwarf2_per_objfile
->all_type_units
[i
] = sig_type
;
3138 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3141 /* Read the address map data from the mapped index, and use it to
3142 populate the objfile's psymtabs_addrmap. */
3145 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3146 struct mapped_index
*index
)
3148 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3149 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3150 const gdb_byte
*iter
, *end
;
3151 struct addrmap
*mutable_map
;
3154 auto_obstack temp_obstack
;
3156 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3158 iter
= index
->address_table
.data ();
3159 end
= iter
+ index
->address_table
.size ();
3161 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3165 ULONGEST hi
, lo
, cu_index
;
3166 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3168 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3170 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3175 complaint (&symfile_complaints
,
3176 _(".gdb_index address table has invalid range (%s - %s)"),
3177 hex_string (lo
), hex_string (hi
));
3181 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3183 complaint (&symfile_complaints
,
3184 _(".gdb_index address table has invalid CU number %u"),
3185 (unsigned) cu_index
);
3189 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3190 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3191 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3192 dwarf2_per_objfile
->get_cu (cu_index
));
3195 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3196 &objfile
->objfile_obstack
);
3199 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3200 populate the objfile's psymtabs_addrmap. */
3203 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3204 struct dwarf2_section_info
*section
)
3206 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3207 bfd
*abfd
= objfile
->obfd
;
3208 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3209 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3210 SECT_OFF_TEXT (objfile
));
3212 auto_obstack temp_obstack
;
3213 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3215 std::unordered_map
<sect_offset
,
3216 dwarf2_per_cu_data
*,
3217 gdb::hash_enum
<sect_offset
>>
3218 debug_info_offset_to_per_cu
;
3219 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3221 const auto insertpair
3222 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3223 if (!insertpair
.second
)
3225 warning (_("Section .debug_aranges in %s has duplicate "
3226 "debug_info_offset %s, ignoring .debug_aranges."),
3227 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3232 dwarf2_read_section (objfile
, section
);
3234 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3236 const gdb_byte
*addr
= section
->buffer
;
3238 while (addr
< section
->buffer
+ section
->size
)
3240 const gdb_byte
*const entry_addr
= addr
;
3241 unsigned int bytes_read
;
3243 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3247 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3248 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3249 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3250 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3252 warning (_("Section .debug_aranges in %s entry at offset %zu "
3253 "length %s exceeds section length %s, "
3254 "ignoring .debug_aranges."),
3255 objfile_name (objfile
), entry_addr
- section
->buffer
,
3256 plongest (bytes_read
+ entry_length
),
3257 pulongest (section
->size
));
3261 /* The version number. */
3262 const uint16_t version
= read_2_bytes (abfd
, addr
);
3266 warning (_("Section .debug_aranges in %s entry at offset %zu "
3267 "has unsupported version %d, ignoring .debug_aranges."),
3268 objfile_name (objfile
), entry_addr
- section
->buffer
,
3273 const uint64_t debug_info_offset
3274 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3275 addr
+= offset_size
;
3276 const auto per_cu_it
3277 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3278 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3280 warning (_("Section .debug_aranges in %s entry at offset %zu "
3281 "debug_info_offset %s does not exists, "
3282 "ignoring .debug_aranges."),
3283 objfile_name (objfile
), entry_addr
- section
->buffer
,
3284 pulongest (debug_info_offset
));
3287 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3289 const uint8_t address_size
= *addr
++;
3290 if (address_size
< 1 || address_size
> 8)
3292 warning (_("Section .debug_aranges in %s entry at offset %zu "
3293 "address_size %u is invalid, ignoring .debug_aranges."),
3294 objfile_name (objfile
), entry_addr
- section
->buffer
,
3299 const uint8_t segment_selector_size
= *addr
++;
3300 if (segment_selector_size
!= 0)
3302 warning (_("Section .debug_aranges in %s entry at offset %zu "
3303 "segment_selector_size %u is not supported, "
3304 "ignoring .debug_aranges."),
3305 objfile_name (objfile
), entry_addr
- section
->buffer
,
3306 segment_selector_size
);
3310 /* Must pad to an alignment boundary that is twice the address
3311 size. It is undocumented by the DWARF standard but GCC does
3313 for (size_t padding
= ((-(addr
- section
->buffer
))
3314 & (2 * address_size
- 1));
3315 padding
> 0; padding
--)
3318 warning (_("Section .debug_aranges in %s entry at offset %zu "
3319 "padding is not zero, ignoring .debug_aranges."),
3320 objfile_name (objfile
), entry_addr
- section
->buffer
);
3326 if (addr
+ 2 * address_size
> entry_end
)
3328 warning (_("Section .debug_aranges in %s entry at offset %zu "
3329 "address list is not properly terminated, "
3330 "ignoring .debug_aranges."),
3331 objfile_name (objfile
), entry_addr
- section
->buffer
);
3334 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3336 addr
+= address_size
;
3337 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3339 addr
+= address_size
;
3340 if (start
== 0 && length
== 0)
3342 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3344 /* Symbol was eliminated due to a COMDAT group. */
3347 ULONGEST end
= start
+ length
;
3348 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
);
3349 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
);
3350 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3354 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3355 &objfile
->objfile_obstack
);
3358 /* Find a slot in the mapped index INDEX for the object named NAME.
3359 If NAME is found, set *VEC_OUT to point to the CU vector in the
3360 constant pool and return true. If NAME cannot be found, return
3364 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3365 offset_type
**vec_out
)
3368 offset_type slot
, step
;
3369 int (*cmp
) (const char *, const char *);
3371 gdb::unique_xmalloc_ptr
<char> without_params
;
3372 if (current_language
->la_language
== language_cplus
3373 || current_language
->la_language
== language_fortran
3374 || current_language
->la_language
== language_d
)
3376 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3379 if (strchr (name
, '(') != NULL
)
3381 without_params
= cp_remove_params (name
);
3383 if (without_params
!= NULL
)
3384 name
= without_params
.get ();
3388 /* Index version 4 did not support case insensitive searches. But the
3389 indices for case insensitive languages are built in lowercase, therefore
3390 simulate our NAME being searched is also lowercased. */
3391 hash
= mapped_index_string_hash ((index
->version
== 4
3392 && case_sensitivity
== case_sensitive_off
3393 ? 5 : index
->version
),
3396 slot
= hash
& (index
->symbol_table
.size () - 1);
3397 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3398 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3404 const auto &bucket
= index
->symbol_table
[slot
];
3405 if (bucket
.name
== 0 && bucket
.vec
== 0)
3408 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3409 if (!cmp (name
, str
))
3411 *vec_out
= (offset_type
*) (index
->constant_pool
3412 + MAYBE_SWAP (bucket
.vec
));
3416 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3420 /* A helper function that reads the .gdb_index from SECTION and fills
3421 in MAP. FILENAME is the name of the file containing the section;
3422 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3423 ok to use deprecated sections.
3425 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3426 out parameters that are filled in with information about the CU and
3427 TU lists in the section.
3429 Returns 1 if all went well, 0 otherwise. */
3432 read_index_from_section (struct objfile
*objfile
,
3433 const char *filename
,
3435 struct dwarf2_section_info
*section
,
3436 struct mapped_index
*map
,
3437 const gdb_byte
**cu_list
,
3438 offset_type
*cu_list_elements
,
3439 const gdb_byte
**types_list
,
3440 offset_type
*types_list_elements
)
3442 const gdb_byte
*addr
;
3443 offset_type version
;
3444 offset_type
*metadata
;
3447 if (dwarf2_section_empty_p (section
))
3450 /* Older elfutils strip versions could keep the section in the main
3451 executable while splitting it for the separate debug info file. */
3452 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3455 dwarf2_read_section (objfile
, section
);
3457 addr
= section
->buffer
;
3458 /* Version check. */
3459 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3460 /* Versions earlier than 3 emitted every copy of a psymbol. This
3461 causes the index to behave very poorly for certain requests. Version 3
3462 contained incomplete addrmap. So, it seems better to just ignore such
3466 static int warning_printed
= 0;
3467 if (!warning_printed
)
3469 warning (_("Skipping obsolete .gdb_index section in %s."),
3471 warning_printed
= 1;
3475 /* Index version 4 uses a different hash function than index version
3478 Versions earlier than 6 did not emit psymbols for inlined
3479 functions. Using these files will cause GDB not to be able to
3480 set breakpoints on inlined functions by name, so we ignore these
3481 indices unless the user has done
3482 "set use-deprecated-index-sections on". */
3483 if (version
< 6 && !deprecated_ok
)
3485 static int warning_printed
= 0;
3486 if (!warning_printed
)
3489 Skipping deprecated .gdb_index section in %s.\n\
3490 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3491 to use the section anyway."),
3493 warning_printed
= 1;
3497 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3498 of the TU (for symbols coming from TUs),
3499 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3500 Plus gold-generated indices can have duplicate entries for global symbols,
3501 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3502 These are just performance bugs, and we can't distinguish gdb-generated
3503 indices from gold-generated ones, so issue no warning here. */
3505 /* Indexes with higher version than the one supported by GDB may be no
3506 longer backward compatible. */
3510 map
->version
= version
;
3511 map
->total_size
= section
->size
;
3513 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3516 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3517 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3521 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3522 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3523 - MAYBE_SWAP (metadata
[i
]))
3527 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3528 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3530 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3533 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3534 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3536 = gdb::array_view
<mapped_index::symbol_table_slot
>
3537 ((mapped_index::symbol_table_slot
*) symbol_table
,
3538 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3541 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3546 /* Read .gdb_index. If everything went ok, initialize the "quick"
3547 elements of all the CUs and return 1. Otherwise, return 0. */
3550 dwarf2_read_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
3552 struct mapped_index local_map
, *map
;
3553 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3554 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3555 struct dwz_file
*dwz
;
3556 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3558 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3559 use_deprecated_index_sections
,
3560 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3561 &cu_list
, &cu_list_elements
,
3562 &types_list
, &types_list_elements
))
3565 /* Don't use the index if it's empty. */
3566 if (local_map
.symbol_table
.empty ())
3569 /* If there is a .dwz file, read it so we can get its CU list as
3571 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3574 struct mapped_index dwz_map
;
3575 const gdb_byte
*dwz_types_ignore
;
3576 offset_type dwz_types_elements_ignore
;
3578 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3580 &dwz
->gdb_index
, &dwz_map
,
3581 &dwz_list
, &dwz_list_elements
,
3583 &dwz_types_elements_ignore
))
3585 warning (_("could not read '.gdb_index' section from %s; skipping"),
3586 bfd_get_filename (dwz
->dwz_bfd
));
3591 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3592 dwz_list
, dwz_list_elements
);
3594 if (types_list_elements
)
3596 struct dwarf2_section_info
*section
;
3598 /* We can only handle a single .debug_types when we have an
3600 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3603 section
= VEC_index (dwarf2_section_info_def
,
3604 dwarf2_per_objfile
->types
, 0);
3606 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3607 types_list
, types_list_elements
);
3610 create_addrmap_from_index (dwarf2_per_objfile
, &local_map
);
3612 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3613 map
= new (map
) mapped_index ();
3616 dwarf2_per_objfile
->index_table
= map
;
3617 dwarf2_per_objfile
->using_index
= 1;
3618 dwarf2_per_objfile
->quick_file_names_table
=
3619 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3624 /* die_reader_func for dw2_get_file_names. */
3627 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3628 const gdb_byte
*info_ptr
,
3629 struct die_info
*comp_unit_die
,
3633 struct dwarf2_cu
*cu
= reader
->cu
;
3634 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3635 struct dwarf2_per_objfile
*dwarf2_per_objfile
3636 = cu
->per_cu
->dwarf2_per_objfile
;
3637 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3638 struct dwarf2_per_cu_data
*lh_cu
;
3639 struct attribute
*attr
;
3642 struct quick_file_names
*qfn
;
3644 gdb_assert (! this_cu
->is_debug_types
);
3646 /* Our callers never want to match partial units -- instead they
3647 will match the enclosing full CU. */
3648 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3650 this_cu
->v
.quick
->no_file_data
= 1;
3658 sect_offset line_offset
{};
3660 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3663 struct quick_file_names find_entry
;
3665 line_offset
= (sect_offset
) DW_UNSND (attr
);
3667 /* We may have already read in this line header (TU line header sharing).
3668 If we have we're done. */
3669 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3670 find_entry
.hash
.line_sect_off
= line_offset
;
3671 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3672 &find_entry
, INSERT
);
3675 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3679 lh
= dwarf_decode_line_header (line_offset
, cu
);
3683 lh_cu
->v
.quick
->no_file_data
= 1;
3687 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3688 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3689 qfn
->hash
.line_sect_off
= line_offset
;
3690 gdb_assert (slot
!= NULL
);
3693 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3695 qfn
->num_file_names
= lh
->file_names
.size ();
3697 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
3698 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3699 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3700 qfn
->real_names
= NULL
;
3702 lh_cu
->v
.quick
->file_names
= qfn
;
3705 /* A helper for the "quick" functions which attempts to read the line
3706 table for THIS_CU. */
3708 static struct quick_file_names
*
3709 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3711 /* This should never be called for TUs. */
3712 gdb_assert (! this_cu
->is_debug_types
);
3713 /* Nor type unit groups. */
3714 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3716 if (this_cu
->v
.quick
->file_names
!= NULL
)
3717 return this_cu
->v
.quick
->file_names
;
3718 /* If we know there is no line data, no point in looking again. */
3719 if (this_cu
->v
.quick
->no_file_data
)
3722 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3724 if (this_cu
->v
.quick
->no_file_data
)
3726 return this_cu
->v
.quick
->file_names
;
3729 /* A helper for the "quick" functions which computes and caches the
3730 real path for a given file name from the line table. */
3733 dw2_get_real_path (struct objfile
*objfile
,
3734 struct quick_file_names
*qfn
, int index
)
3736 if (qfn
->real_names
== NULL
)
3737 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3738 qfn
->num_file_names
, const char *);
3740 if (qfn
->real_names
[index
] == NULL
)
3741 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3743 return qfn
->real_names
[index
];
3746 static struct symtab
*
3747 dw2_find_last_source_symtab (struct objfile
*objfile
)
3749 struct dwarf2_per_objfile
*dwarf2_per_objfile
3750 = get_dwarf2_per_objfile (objfile
);
3751 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3752 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
);
3757 return compunit_primary_filetab (cust
);
3760 /* Traversal function for dw2_forget_cached_source_info. */
3763 dw2_free_cached_file_names (void **slot
, void *info
)
3765 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3767 if (file_data
->real_names
)
3771 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3773 xfree ((void*) file_data
->real_names
[i
]);
3774 file_data
->real_names
[i
] = NULL
;
3782 dw2_forget_cached_source_info (struct objfile
*objfile
)
3784 struct dwarf2_per_objfile
*dwarf2_per_objfile
3785 = get_dwarf2_per_objfile (objfile
);
3787 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3788 dw2_free_cached_file_names
, NULL
);
3791 /* Helper function for dw2_map_symtabs_matching_filename that expands
3792 the symtabs and calls the iterator. */
3795 dw2_map_expand_apply (struct objfile
*objfile
,
3796 struct dwarf2_per_cu_data
*per_cu
,
3797 const char *name
, const char *real_path
,
3798 gdb::function_view
<bool (symtab
*)> callback
)
3800 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3802 /* Don't visit already-expanded CUs. */
3803 if (per_cu
->v
.quick
->compunit_symtab
)
3806 /* This may expand more than one symtab, and we want to iterate over
3808 dw2_instantiate_symtab (per_cu
);
3810 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3811 last_made
, callback
);
3814 /* Implementation of the map_symtabs_matching_filename method. */
3817 dw2_map_symtabs_matching_filename
3818 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3819 gdb::function_view
<bool (symtab
*)> callback
)
3821 const char *name_basename
= lbasename (name
);
3822 struct dwarf2_per_objfile
*dwarf2_per_objfile
3823 = get_dwarf2_per_objfile (objfile
);
3825 /* The rule is CUs specify all the files, including those used by
3826 any TU, so there's no need to scan TUs here. */
3828 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3830 /* We only need to look at symtabs not already expanded. */
3831 if (per_cu
->v
.quick
->compunit_symtab
)
3834 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3835 if (file_data
== NULL
)
3838 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3840 const char *this_name
= file_data
->file_names
[j
];
3841 const char *this_real_name
;
3843 if (compare_filenames_for_search (this_name
, name
))
3845 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3851 /* Before we invoke realpath, which can get expensive when many
3852 files are involved, do a quick comparison of the basenames. */
3853 if (! basenames_may_differ
3854 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3857 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3858 if (compare_filenames_for_search (this_real_name
, name
))
3860 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3866 if (real_path
!= NULL
)
3868 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3869 gdb_assert (IS_ABSOLUTE_PATH (name
));
3870 if (this_real_name
!= NULL
3871 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3873 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3885 /* Struct used to manage iterating over all CUs looking for a symbol. */
3887 struct dw2_symtab_iterator
3889 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3890 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3891 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3892 int want_specific_block
;
3893 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3894 Unused if !WANT_SPECIFIC_BLOCK. */
3896 /* The kind of symbol we're looking for. */
3898 /* The list of CUs from the index entry of the symbol,
3899 or NULL if not found. */
3901 /* The next element in VEC to look at. */
3903 /* The number of elements in VEC, or zero if there is no match. */
3905 /* Have we seen a global version of the symbol?
3906 If so we can ignore all further global instances.
3907 This is to work around gold/15646, inefficient gold-generated
3912 /* Initialize the index symtab iterator ITER.
3913 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3914 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3917 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3918 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3919 int want_specific_block
,
3924 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3925 iter
->want_specific_block
= want_specific_block
;
3926 iter
->block_index
= block_index
;
3927 iter
->domain
= domain
;
3929 iter
->global_seen
= 0;
3931 mapped_index
*index
= dwarf2_per_objfile
->index_table
;
3933 /* index is NULL if OBJF_READNOW. */
3934 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3935 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3943 /* Return the next matching CU or NULL if there are no more. */
3945 static struct dwarf2_per_cu_data
*
3946 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3948 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3950 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3952 offset_type cu_index_and_attrs
=
3953 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3954 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3955 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3956 /* This value is only valid for index versions >= 7. */
3957 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3958 gdb_index_symbol_kind symbol_kind
=
3959 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3960 /* Only check the symbol attributes if they're present.
3961 Indices prior to version 7 don't record them,
3962 and indices >= 7 may elide them for certain symbols
3963 (gold does this). */
3965 (dwarf2_per_objfile
->index_table
->version
>= 7
3966 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3968 /* Don't crash on bad data. */
3969 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3970 + dwarf2_per_objfile
->n_type_units
))
3972 complaint (&symfile_complaints
,
3973 _(".gdb_index entry has bad CU index"
3975 objfile_name (dwarf2_per_objfile
->objfile
));
3979 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3981 /* Skip if already read in. */
3982 if (per_cu
->v
.quick
->compunit_symtab
)
3985 /* Check static vs global. */
3988 if (iter
->want_specific_block
3989 && want_static
!= is_static
)
3991 /* Work around gold/15646. */
3992 if (!is_static
&& iter
->global_seen
)
3995 iter
->global_seen
= 1;
3998 /* Only check the symbol's kind if it has one. */
4001 switch (iter
->domain
)
4004 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4005 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4006 /* Some types are also in VAR_DOMAIN. */
4007 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4011 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4015 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4030 static struct compunit_symtab
*
4031 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
4032 const char *name
, domain_enum domain
)
4034 struct compunit_symtab
*stab_best
= NULL
;
4035 struct dwarf2_per_objfile
*dwarf2_per_objfile
4036 = get_dwarf2_per_objfile (objfile
);
4038 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4040 struct dw2_symtab_iterator iter
;
4041 struct dwarf2_per_cu_data
*per_cu
;
4043 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 1, block_index
, domain
, name
);
4045 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4047 struct symbol
*sym
, *with_opaque
= NULL
;
4048 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
4049 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4050 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4052 sym
= block_find_symbol (block
, name
, domain
,
4053 block_find_non_opaque_type_preferred
,
4056 /* Some caution must be observed with overloaded functions
4057 and methods, since the index will not contain any overload
4058 information (but NAME might contain it). */
4061 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4063 if (with_opaque
!= NULL
4064 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4067 /* Keep looking through other CUs. */
4074 dw2_print_stats (struct objfile
*objfile
)
4076 struct dwarf2_per_objfile
*dwarf2_per_objfile
4077 = get_dwarf2_per_objfile (objfile
);
4078 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4079 + dwarf2_per_objfile
->n_type_units
);
4082 for (int i
= 0; i
< total
; ++i
)
4084 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4086 if (!per_cu
->v
.quick
->compunit_symtab
)
4089 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4090 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4093 /* This dumps minimal information about the index.
4094 It is called via "mt print objfiles".
4095 One use is to verify .gdb_index has been loaded by the
4096 gdb.dwarf2/gdb-index.exp testcase. */
4099 dw2_dump (struct objfile
*objfile
)
4101 struct dwarf2_per_objfile
*dwarf2_per_objfile
4102 = get_dwarf2_per_objfile (objfile
);
4104 gdb_assert (dwarf2_per_objfile
->using_index
);
4105 printf_filtered (".gdb_index:");
4106 if (dwarf2_per_objfile
->index_table
!= NULL
)
4108 printf_filtered (" version %d\n",
4109 dwarf2_per_objfile
->index_table
->version
);
4112 printf_filtered (" faked for \"readnow\"\n");
4113 printf_filtered ("\n");
4117 dw2_relocate (struct objfile
*objfile
,
4118 const struct section_offsets
*new_offsets
,
4119 const struct section_offsets
*delta
)
4121 /* There's nothing to relocate here. */
4125 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4126 const char *func_name
)
4128 struct dwarf2_per_objfile
*dwarf2_per_objfile
4129 = get_dwarf2_per_objfile (objfile
);
4131 struct dw2_symtab_iterator iter
;
4132 struct dwarf2_per_cu_data
*per_cu
;
4134 /* Note: It doesn't matter what we pass for block_index here. */
4135 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
4138 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4139 dw2_instantiate_symtab (per_cu
);
4144 dw2_expand_all_symtabs (struct objfile
*objfile
)
4146 struct dwarf2_per_objfile
*dwarf2_per_objfile
4147 = get_dwarf2_per_objfile (objfile
);
4148 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4149 + dwarf2_per_objfile
->n_type_units
);
4151 for (int i
= 0; i
< total_units
; ++i
)
4153 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4155 dw2_instantiate_symtab (per_cu
);
4160 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4161 const char *fullname
)
4163 struct dwarf2_per_objfile
*dwarf2_per_objfile
4164 = get_dwarf2_per_objfile (objfile
);
4166 /* We don't need to consider type units here.
4167 This is only called for examining code, e.g. expand_line_sal.
4168 There can be an order of magnitude (or more) more type units
4169 than comp units, and we avoid them if we can. */
4171 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4173 /* We only need to look at symtabs not already expanded. */
4174 if (per_cu
->v
.quick
->compunit_symtab
)
4177 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4178 if (file_data
== NULL
)
4181 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4183 const char *this_fullname
= file_data
->file_names
[j
];
4185 if (filename_cmp (this_fullname
, fullname
) == 0)
4187 dw2_instantiate_symtab (per_cu
);
4195 dw2_map_matching_symbols (struct objfile
*objfile
,
4196 const char * name
, domain_enum domain
,
4198 int (*callback
) (struct block
*,
4199 struct symbol
*, void *),
4200 void *data
, symbol_name_match_type match
,
4201 symbol_compare_ftype
*ordered_compare
)
4203 /* Currently unimplemented; used for Ada. The function can be called if the
4204 current language is Ada for a non-Ada objfile using GNU index. As Ada
4205 does not look for non-Ada symbols this function should just return. */
4208 /* Symbol name matcher for .gdb_index names.
4210 Symbol names in .gdb_index have a few particularities:
4212 - There's no indication of which is the language of each symbol.
4214 Since each language has its own symbol name matching algorithm,
4215 and we don't know which language is the right one, we must match
4216 each symbol against all languages. This would be a potential
4217 performance problem if it were not mitigated by the
4218 mapped_index::name_components lookup table, which significantly
4219 reduces the number of times we need to call into this matcher,
4220 making it a non-issue.
4222 - Symbol names in the index have no overload (parameter)
4223 information. I.e., in C++, "foo(int)" and "foo(long)" both
4224 appear as "foo" in the index, for example.
4226 This means that the lookup names passed to the symbol name
4227 matcher functions must have no parameter information either
4228 because (e.g.) symbol search name "foo" does not match
4229 lookup-name "foo(int)" [while swapping search name for lookup
4232 class gdb_index_symbol_name_matcher
4235 /* Prepares the vector of comparison functions for LOOKUP_NAME. */
4236 gdb_index_symbol_name_matcher (const lookup_name_info
&lookup_name
);
4238 /* Walk all the matcher routines and match SYMBOL_NAME against them.
4239 Returns true if any matcher matches. */
4240 bool matches (const char *symbol_name
);
4243 /* A reference to the lookup name we're matching against. */
4244 const lookup_name_info
&m_lookup_name
;
4246 /* A vector holding all the different symbol name matchers, for all
4248 std::vector
<symbol_name_matcher_ftype
*> m_symbol_name_matcher_funcs
;
4251 gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
4252 (const lookup_name_info
&lookup_name
)
4253 : m_lookup_name (lookup_name
)
4255 /* Prepare the vector of comparison functions upfront, to avoid
4256 doing the same work for each symbol. Care is taken to avoid
4257 matching with the same matcher more than once if/when multiple
4258 languages use the same matcher function. */
4259 auto &matchers
= m_symbol_name_matcher_funcs
;
4260 matchers
.reserve (nr_languages
);
4262 matchers
.push_back (default_symbol_name_matcher
);
4264 for (int i
= 0; i
< nr_languages
; i
++)
4266 const language_defn
*lang
= language_def ((enum language
) i
);
4267 symbol_name_matcher_ftype
*name_matcher
4268 = get_symbol_name_matcher (lang
, m_lookup_name
);
4270 /* Don't insert the same comparison routine more than once.
4271 Note that we do this linear walk instead of a seemingly
4272 cheaper sorted insert, or use a std::set or something like
4273 that, because relative order of function addresses is not
4274 stable. This is not a problem in practice because the number
4275 of supported languages is low, and the cost here is tiny
4276 compared to the number of searches we'll do afterwards using
4278 if (name_matcher
!= default_symbol_name_matcher
4279 && (std::find (matchers
.begin (), matchers
.end (), name_matcher
)
4280 == matchers
.end ()))
4281 matchers
.push_back (name_matcher
);
4286 gdb_index_symbol_name_matcher::matches (const char *symbol_name
)
4288 for (auto matches_name
: m_symbol_name_matcher_funcs
)
4289 if (matches_name (symbol_name
, m_lookup_name
, NULL
))
4295 /* Starting from a search name, return the string that finds the upper
4296 bound of all strings that start with SEARCH_NAME in a sorted name
4297 list. Returns the empty string to indicate that the upper bound is
4298 the end of the list. */
4301 make_sort_after_prefix_name (const char *search_name
)
4303 /* When looking to complete "func", we find the upper bound of all
4304 symbols that start with "func" by looking for where we'd insert
4305 the closest string that would follow "func" in lexicographical
4306 order. Usually, that's "func"-with-last-character-incremented,
4307 i.e. "fund". Mind non-ASCII characters, though. Usually those
4308 will be UTF-8 multi-byte sequences, but we can't be certain.
4309 Especially mind the 0xff character, which is a valid character in
4310 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4311 rule out compilers allowing it in identifiers. Note that
4312 conveniently, strcmp/strcasecmp are specified to compare
4313 characters interpreted as unsigned char. So what we do is treat
4314 the whole string as a base 256 number composed of a sequence of
4315 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4316 to 0, and carries 1 to the following more-significant position.
4317 If the very first character in SEARCH_NAME ends up incremented
4318 and carries/overflows, then the upper bound is the end of the
4319 list. The string after the empty string is also the empty
4322 Some examples of this operation:
4324 SEARCH_NAME => "+1" RESULT
4328 "\xff" "a" "\xff" => "\xff" "b"
4333 Then, with these symbols for example:
4339 completing "func" looks for symbols between "func" and
4340 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4341 which finds "func" and "func1", but not "fund".
4345 funcÿ (Latin1 'ÿ' [0xff])
4349 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4350 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4354 ÿÿ (Latin1 'ÿ' [0xff])
4357 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4358 the end of the list.
4360 std::string after
= search_name
;
4361 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4363 if (!after
.empty ())
4364 after
.back () = (unsigned char) after
.back () + 1;
4368 /* See declaration. */
4370 std::pair
<std::vector
<name_component
>::const_iterator
,
4371 std::vector
<name_component
>::const_iterator
>
4372 mapped_index_base::find_name_components_bounds
4373 (const lookup_name_info
&lookup_name_without_params
) const
4376 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4379 = lookup_name_without_params
.cplus ().lookup_name ().c_str ();
4381 /* Comparison function object for lower_bound that matches against a
4382 given symbol name. */
4383 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4386 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4387 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4388 return name_cmp (elem_name
, name
) < 0;
4391 /* Comparison function object for upper_bound that matches against a
4392 given symbol name. */
4393 auto lookup_compare_upper
= [&] (const char *name
,
4394 const name_component
&elem
)
4396 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4397 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4398 return name_cmp (name
, elem_name
) < 0;
4401 auto begin
= this->name_components
.begin ();
4402 auto end
= this->name_components
.end ();
4404 /* Find the lower bound. */
4407 if (lookup_name_without_params
.completion_mode () && cplus
[0] == '\0')
4410 return std::lower_bound (begin
, end
, cplus
, lookup_compare_lower
);
4413 /* Find the upper bound. */
4416 if (lookup_name_without_params
.completion_mode ())
4418 /* In completion mode, we want UPPER to point past all
4419 symbols names that have the same prefix. I.e., with
4420 these symbols, and completing "func":
4422 function << lower bound
4424 other_function << upper bound
4426 We find the upper bound by looking for the insertion
4427 point of "func"-with-last-character-incremented,
4429 std::string after
= make_sort_after_prefix_name (cplus
);
4432 return std::lower_bound (lower
, end
, after
.c_str (),
4433 lookup_compare_lower
);
4436 return std::upper_bound (lower
, end
, cplus
, lookup_compare_upper
);
4439 return {lower
, upper
};
4442 /* See declaration. */
4445 mapped_index_base::build_name_components ()
4447 if (!this->name_components
.empty ())
4450 this->name_components_casing
= case_sensitivity
;
4452 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4454 /* The code below only knows how to break apart components of C++
4455 symbol names (and other languages that use '::' as
4456 namespace/module separator). If we add support for wild matching
4457 to some language that uses some other operator (E.g., Ada, Go and
4458 D use '.'), then we'll need to try splitting the symbol name
4459 according to that language too. Note that Ada does support wild
4460 matching, but doesn't currently support .gdb_index. */
4461 auto count
= this->symbol_name_count ();
4462 for (offset_type idx
= 0; idx
< count
; idx
++)
4464 if (this->symbol_name_slot_invalid (idx
))
4467 const char *name
= this->symbol_name_at (idx
);
4469 /* Add each name component to the name component table. */
4470 unsigned int previous_len
= 0;
4471 for (unsigned int current_len
= cp_find_first_component (name
);
4472 name
[current_len
] != '\0';
4473 current_len
+= cp_find_first_component (name
+ current_len
))
4475 gdb_assert (name
[current_len
] == ':');
4476 this->name_components
.push_back ({previous_len
, idx
});
4477 /* Skip the '::'. */
4479 previous_len
= current_len
;
4481 this->name_components
.push_back ({previous_len
, idx
});
4484 /* Sort name_components elements by name. */
4485 auto name_comp_compare
= [&] (const name_component
&left
,
4486 const name_component
&right
)
4488 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4489 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4491 const char *left_name
= left_qualified
+ left
.name_offset
;
4492 const char *right_name
= right_qualified
+ right
.name_offset
;
4494 return name_cmp (left_name
, right_name
) < 0;
4497 std::sort (this->name_components
.begin (),
4498 this->name_components
.end (),
4502 /* Helper for dw2_expand_symtabs_matching that works with a
4503 mapped_index_base instead of the containing objfile. This is split
4504 to a separate function in order to be able to unit test the
4505 name_components matching using a mock mapped_index_base. For each
4506 symbol name that matches, calls MATCH_CALLBACK, passing it the
4507 symbol's index in the mapped_index_base symbol table. */
4510 dw2_expand_symtabs_matching_symbol
4511 (mapped_index_base
&index
,
4512 const lookup_name_info
&lookup_name_in
,
4513 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4514 enum search_domain kind
,
4515 gdb::function_view
<void (offset_type
)> match_callback
)
4517 lookup_name_info lookup_name_without_params
4518 = lookup_name_in
.make_ignore_params ();
4519 gdb_index_symbol_name_matcher lookup_name_matcher
4520 (lookup_name_without_params
);
4522 /* Build the symbol name component sorted vector, if we haven't
4524 index
.build_name_components ();
4526 auto bounds
= index
.find_name_components_bounds (lookup_name_without_params
);
4528 /* Now for each symbol name in range, check to see if we have a name
4529 match, and if so, call the MATCH_CALLBACK callback. */
4531 /* The same symbol may appear more than once in the range though.
4532 E.g., if we're looking for symbols that complete "w", and we have
4533 a symbol named "w1::w2", we'll find the two name components for
4534 that same symbol in the range. To be sure we only call the
4535 callback once per symbol, we first collect the symbol name
4536 indexes that matched in a temporary vector and ignore
4538 std::vector
<offset_type
> matches
;
4539 matches
.reserve (std::distance (bounds
.first
, bounds
.second
));
4541 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4543 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4545 if (!lookup_name_matcher
.matches (qualified
)
4546 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4549 matches
.push_back (bounds
.first
->idx
);
4552 std::sort (matches
.begin (), matches
.end ());
4554 /* Finally call the callback, once per match. */
4556 for (offset_type idx
: matches
)
4560 match_callback (idx
);
4565 /* Above we use a type wider than idx's for 'prev', since 0 and
4566 (offset_type)-1 are both possible values. */
4567 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4572 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4574 /* A mock .gdb_index/.debug_names-like name index table, enough to
4575 exercise dw2_expand_symtabs_matching_symbol, which works with the
4576 mapped_index_base interface. Builds an index from the symbol list
4577 passed as parameter to the constructor. */
4578 class mock_mapped_index
: public mapped_index_base
4581 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4582 : m_symbol_table (symbols
)
4585 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4587 /* Return the number of names in the symbol table. */
4588 virtual size_t symbol_name_count () const
4590 return m_symbol_table
.size ();
4593 /* Get the name of the symbol at IDX in the symbol table. */
4594 virtual const char *symbol_name_at (offset_type idx
) const
4596 return m_symbol_table
[idx
];
4600 gdb::array_view
<const char *> m_symbol_table
;
4603 /* Convenience function that converts a NULL pointer to a "<null>"
4604 string, to pass to print routines. */
4607 string_or_null (const char *str
)
4609 return str
!= NULL
? str
: "<null>";
4612 /* Check if a lookup_name_info built from
4613 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4614 index. EXPECTED_LIST is the list of expected matches, in expected
4615 matching order. If no match expected, then an empty list is
4616 specified. Returns true on success. On failure prints a warning
4617 indicating the file:line that failed, and returns false. */
4620 check_match (const char *file
, int line
,
4621 mock_mapped_index
&mock_index
,
4622 const char *name
, symbol_name_match_type match_type
,
4623 bool completion_mode
,
4624 std::initializer_list
<const char *> expected_list
)
4626 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4628 bool matched
= true;
4630 auto mismatch
= [&] (const char *expected_str
,
4633 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4634 "expected=\"%s\", got=\"%s\"\n"),
4636 (match_type
== symbol_name_match_type::FULL
4638 name
, string_or_null (expected_str
), string_or_null (got
));
4642 auto expected_it
= expected_list
.begin ();
4643 auto expected_end
= expected_list
.end ();
4645 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4647 [&] (offset_type idx
)
4649 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4650 const char *expected_str
4651 = expected_it
== expected_end
? NULL
: *expected_it
++;
4653 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4654 mismatch (expected_str
, matched_name
);
4657 const char *expected_str
4658 = expected_it
== expected_end
? NULL
: *expected_it
++;
4659 if (expected_str
!= NULL
)
4660 mismatch (expected_str
, NULL
);
4665 /* The symbols added to the mock mapped_index for testing (in
4667 static const char *test_symbols
[] = {
4676 "ns2::tmpl<int>::foo2",
4677 "(anonymous namespace)::A::B::C",
4679 /* These are used to check that the increment-last-char in the
4680 matching algorithm for completion doesn't match "t1_fund" when
4681 completing "t1_func". */
4687 /* A UTF-8 name with multi-byte sequences to make sure that
4688 cp-name-parser understands this as a single identifier ("função"
4689 is "function" in PT). */
4692 /* \377 (0xff) is Latin1 'ÿ'. */
4695 /* \377 (0xff) is Latin1 'ÿ'. */
4699 /* A name with all sorts of complications. Starts with "z" to make
4700 it easier for the completion tests below. */
4701 #define Z_SYM_NAME \
4702 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4703 "::tuple<(anonymous namespace)::ui*, " \
4704 "std::default_delete<(anonymous namespace)::ui>, void>"
4709 /* Returns true if the mapped_index_base::find_name_component_bounds
4710 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4711 in completion mode. */
4714 check_find_bounds_finds (mapped_index_base
&index
,
4715 const char *search_name
,
4716 gdb::array_view
<const char *> expected_syms
)
4718 lookup_name_info
lookup_name (search_name
,
4719 symbol_name_match_type::FULL
, true);
4721 auto bounds
= index
.find_name_components_bounds (lookup_name
);
4723 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4724 if (distance
!= expected_syms
.size ())
4727 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4729 auto nc_elem
= bounds
.first
+ exp_elem
;
4730 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4731 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4738 /* Test the lower-level mapped_index::find_name_component_bounds
4742 test_mapped_index_find_name_component_bounds ()
4744 mock_mapped_index
mock_index (test_symbols
);
4746 mock_index
.build_name_components ();
4748 /* Test the lower-level mapped_index::find_name_component_bounds
4749 method in completion mode. */
4751 static const char *expected_syms
[] = {
4756 SELF_CHECK (check_find_bounds_finds (mock_index
,
4757 "t1_func", expected_syms
));
4760 /* Check that the increment-last-char in the name matching algorithm
4761 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4763 static const char *expected_syms1
[] = {
4767 SELF_CHECK (check_find_bounds_finds (mock_index
,
4768 "\377", expected_syms1
));
4770 static const char *expected_syms2
[] = {
4773 SELF_CHECK (check_find_bounds_finds (mock_index
,
4774 "\377\377", expected_syms2
));
4778 /* Test dw2_expand_symtabs_matching_symbol. */
4781 test_dw2_expand_symtabs_matching_symbol ()
4783 mock_mapped_index
mock_index (test_symbols
);
4785 /* We let all tests run until the end even if some fails, for debug
4787 bool any_mismatch
= false;
4789 /* Create the expected symbols list (an initializer_list). Needed
4790 because lists have commas, and we need to pass them to CHECK,
4791 which is a macro. */
4792 #define EXPECT(...) { __VA_ARGS__ }
4794 /* Wrapper for check_match that passes down the current
4795 __FILE__/__LINE__. */
4796 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4797 any_mismatch |= !check_match (__FILE__, __LINE__, \
4799 NAME, MATCH_TYPE, COMPLETION_MODE, \
4802 /* Identity checks. */
4803 for (const char *sym
: test_symbols
)
4805 /* Should be able to match all existing symbols. */
4806 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4809 /* Should be able to match all existing symbols with
4811 std::string with_params
= std::string (sym
) + "(int)";
4812 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4815 /* Should be able to match all existing symbols with
4816 parameters and qualifiers. */
4817 with_params
= std::string (sym
) + " ( int ) const";
4818 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4821 /* This should really find sym, but cp-name-parser.y doesn't
4822 know about lvalue/rvalue qualifiers yet. */
4823 with_params
= std::string (sym
) + " ( int ) &&";
4824 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4828 /* Check that the name matching algorithm for completion doesn't get
4829 confused with Latin1 'ÿ' / 0xff. */
4831 static const char str
[] = "\377";
4832 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4833 EXPECT ("\377", "\377\377123"));
4836 /* Check that the increment-last-char in the matching algorithm for
4837 completion doesn't match "t1_fund" when completing "t1_func". */
4839 static const char str
[] = "t1_func";
4840 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4841 EXPECT ("t1_func", "t1_func1"));
4844 /* Check that completion mode works at each prefix of the expected
4847 static const char str
[] = "function(int)";
4848 size_t len
= strlen (str
);
4851 for (size_t i
= 1; i
< len
; i
++)
4853 lookup
.assign (str
, i
);
4854 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4855 EXPECT ("function"));
4859 /* While "w" is a prefix of both components, the match function
4860 should still only be called once. */
4862 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4864 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4868 /* Same, with a "complicated" symbol. */
4870 static const char str
[] = Z_SYM_NAME
;
4871 size_t len
= strlen (str
);
4874 for (size_t i
= 1; i
< len
; i
++)
4876 lookup
.assign (str
, i
);
4877 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4878 EXPECT (Z_SYM_NAME
));
4882 /* In FULL mode, an incomplete symbol doesn't match. */
4884 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4888 /* A complete symbol with parameters matches any overload, since the
4889 index has no overload info. */
4891 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4892 EXPECT ("std::zfunction", "std::zfunction2"));
4893 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4894 EXPECT ("std::zfunction", "std::zfunction2"));
4895 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4896 EXPECT ("std::zfunction", "std::zfunction2"));
4899 /* Check that whitespace is ignored appropriately. A symbol with a
4900 template argument list. */
4902 static const char expected
[] = "ns::foo<int>";
4903 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4905 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4909 /* Check that whitespace is ignored appropriately. A symbol with a
4910 template argument list that includes a pointer. */
4912 static const char expected
[] = "ns::foo<char*>";
4913 /* Try both completion and non-completion modes. */
4914 static const bool completion_mode
[2] = {false, true};
4915 for (size_t i
= 0; i
< 2; i
++)
4917 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4918 completion_mode
[i
], EXPECT (expected
));
4919 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4920 completion_mode
[i
], EXPECT (expected
));
4922 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4923 completion_mode
[i
], EXPECT (expected
));
4924 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4925 completion_mode
[i
], EXPECT (expected
));
4930 /* Check method qualifiers are ignored. */
4931 static const char expected
[] = "ns::foo<char*>";
4932 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4933 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4934 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4935 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4936 CHECK_MATCH ("foo < char * > ( int ) const",
4937 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4938 CHECK_MATCH ("foo < char * > ( int ) &&",
4939 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4942 /* Test lookup names that don't match anything. */
4944 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4947 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4951 /* Some wild matching tests, exercising "(anonymous namespace)",
4952 which should not be confused with a parameter list. */
4954 static const char *syms
[] = {
4958 "A :: B :: C ( int )",
4963 for (const char *s
: syms
)
4965 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4966 EXPECT ("(anonymous namespace)::A::B::C"));
4971 static const char expected
[] = "ns2::tmpl<int>::foo2";
4972 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4974 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4978 SELF_CHECK (!any_mismatch
);
4987 test_mapped_index_find_name_component_bounds ();
4988 test_dw2_expand_symtabs_matching_symbol ();
4991 }} // namespace selftests::dw2_expand_symtabs_matching
4993 #endif /* GDB_SELF_TEST */
4995 /* If FILE_MATCHER is NULL or if PER_CU has
4996 dwarf2_per_cu_quick_data::MARK set (see
4997 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4998 EXPANSION_NOTIFY on it. */
5001 dw2_expand_symtabs_matching_one
5002 (struct dwarf2_per_cu_data
*per_cu
,
5003 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5004 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5006 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5008 bool symtab_was_null
5009 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5011 dw2_instantiate_symtab (per_cu
);
5013 if (expansion_notify
!= NULL
5015 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5016 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5020 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5021 matched, to expand corresponding CUs that were marked. IDX is the
5022 index of the symbol name that matched. */
5025 dw2_expand_marked_cus
5026 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5027 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5028 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5031 offset_type
*vec
, vec_len
, vec_idx
;
5032 bool global_seen
= false;
5033 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5035 vec
= (offset_type
*) (index
.constant_pool
5036 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5037 vec_len
= MAYBE_SWAP (vec
[0]);
5038 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5040 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5041 /* This value is only valid for index versions >= 7. */
5042 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5043 gdb_index_symbol_kind symbol_kind
=
5044 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5045 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5046 /* Only check the symbol attributes if they're present.
5047 Indices prior to version 7 don't record them,
5048 and indices >= 7 may elide them for certain symbols
5049 (gold does this). */
5052 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5054 /* Work around gold/15646. */
5057 if (!is_static
&& global_seen
)
5063 /* Only check the symbol's kind if it has one. */
5068 case VARIABLES_DOMAIN
:
5069 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5072 case FUNCTIONS_DOMAIN
:
5073 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5077 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5085 /* Don't crash on bad data. */
5086 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5087 + dwarf2_per_objfile
->n_type_units
))
5089 complaint (&symfile_complaints
,
5090 _(".gdb_index entry has bad CU index"
5092 objfile_name (dwarf2_per_objfile
->objfile
));
5096 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5097 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5102 /* If FILE_MATCHER is non-NULL, set all the
5103 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5104 that match FILE_MATCHER. */
5107 dw_expand_symtabs_matching_file_matcher
5108 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5109 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5111 if (file_matcher
== NULL
)
5114 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5116 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5118 NULL
, xcalloc
, xfree
));
5119 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5121 NULL
, xcalloc
, xfree
));
5123 /* The rule is CUs specify all the files, including those used by
5124 any TU, so there's no need to scan TUs here. */
5126 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5130 per_cu
->v
.quick
->mark
= 0;
5132 /* We only need to look at symtabs not already expanded. */
5133 if (per_cu
->v
.quick
->compunit_symtab
)
5136 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5137 if (file_data
== NULL
)
5140 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5142 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5144 per_cu
->v
.quick
->mark
= 1;
5148 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5150 const char *this_real_name
;
5152 if (file_matcher (file_data
->file_names
[j
], false))
5154 per_cu
->v
.quick
->mark
= 1;
5158 /* Before we invoke realpath, which can get expensive when many
5159 files are involved, do a quick comparison of the basenames. */
5160 if (!basenames_may_differ
5161 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5165 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5166 if (file_matcher (this_real_name
, false))
5168 per_cu
->v
.quick
->mark
= 1;
5173 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5174 ? visited_found
.get ()
5175 : visited_not_found
.get (),
5182 dw2_expand_symtabs_matching
5183 (struct objfile
*objfile
,
5184 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5185 const lookup_name_info
&lookup_name
,
5186 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5187 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5188 enum search_domain kind
)
5190 struct dwarf2_per_objfile
*dwarf2_per_objfile
5191 = get_dwarf2_per_objfile (objfile
);
5193 /* index_table is NULL if OBJF_READNOW. */
5194 if (!dwarf2_per_objfile
->index_table
)
5197 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5199 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5201 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5203 kind
, [&] (offset_type idx
)
5205 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5206 expansion_notify
, kind
);
5210 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5213 static struct compunit_symtab
*
5214 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5219 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5220 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5223 if (cust
->includes
== NULL
)
5226 for (i
= 0; cust
->includes
[i
]; ++i
)
5228 struct compunit_symtab
*s
= cust
->includes
[i
];
5230 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5238 static struct compunit_symtab
*
5239 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5240 struct bound_minimal_symbol msymbol
,
5242 struct obj_section
*section
,
5245 struct dwarf2_per_cu_data
*data
;
5246 struct compunit_symtab
*result
;
5248 if (!objfile
->psymtabs_addrmap
)
5251 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
5256 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5257 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5258 paddress (get_objfile_arch (objfile
), pc
));
5261 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
5263 gdb_assert (result
!= NULL
);
5268 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5269 void *data
, int need_fullname
)
5271 struct dwarf2_per_objfile
*dwarf2_per_objfile
5272 = get_dwarf2_per_objfile (objfile
);
5274 if (!dwarf2_per_objfile
->filenames_cache
)
5276 dwarf2_per_objfile
->filenames_cache
.emplace ();
5278 htab_up
visited (htab_create_alloc (10,
5279 htab_hash_pointer
, htab_eq_pointer
,
5280 NULL
, xcalloc
, xfree
));
5282 /* The rule is CUs specify all the files, including those used
5283 by any TU, so there's no need to scan TUs here. We can
5284 ignore file names coming from already-expanded CUs. */
5286 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5288 if (per_cu
->v
.quick
->compunit_symtab
)
5290 void **slot
= htab_find_slot (visited
.get (),
5291 per_cu
->v
.quick
->file_names
,
5294 *slot
= per_cu
->v
.quick
->file_names
;
5298 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5300 /* We only need to look at symtabs not already expanded. */
5301 if (per_cu
->v
.quick
->compunit_symtab
)
5304 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5305 if (file_data
== NULL
)
5308 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5311 /* Already visited. */
5316 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5318 const char *filename
= file_data
->file_names
[j
];
5319 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5324 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5326 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5329 this_real_name
= gdb_realpath (filename
);
5330 (*fun
) (filename
, this_real_name
.get (), data
);
5335 dw2_has_symbols (struct objfile
*objfile
)
5340 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5343 dw2_find_last_source_symtab
,
5344 dw2_forget_cached_source_info
,
5345 dw2_map_symtabs_matching_filename
,
5350 dw2_expand_symtabs_for_function
,
5351 dw2_expand_all_symtabs
,
5352 dw2_expand_symtabs_with_fullname
,
5353 dw2_map_matching_symbols
,
5354 dw2_expand_symtabs_matching
,
5355 dw2_find_pc_sect_compunit_symtab
,
5357 dw2_map_symbol_filenames
5360 /* DWARF-5 debug_names reader. */
5362 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5363 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5365 /* A helper function that reads the .debug_names section in SECTION
5366 and fills in MAP. FILENAME is the name of the file containing the
5367 section; it is used for error reporting.
5369 Returns true if all went well, false otherwise. */
5372 read_debug_names_from_section (struct objfile
*objfile
,
5373 const char *filename
,
5374 struct dwarf2_section_info
*section
,
5375 mapped_debug_names
&map
)
5377 if (dwarf2_section_empty_p (section
))
5380 /* Older elfutils strip versions could keep the section in the main
5381 executable while splitting it for the separate debug info file. */
5382 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5385 dwarf2_read_section (objfile
, section
);
5387 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5389 const gdb_byte
*addr
= section
->buffer
;
5391 bfd
*const abfd
= get_section_bfd_owner (section
);
5393 unsigned int bytes_read
;
5394 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5397 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5398 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5399 if (bytes_read
+ length
!= section
->size
)
5401 /* There may be multiple per-CU indices. */
5402 warning (_("Section .debug_names in %s length %s does not match "
5403 "section length %s, ignoring .debug_names."),
5404 filename
, plongest (bytes_read
+ length
),
5405 pulongest (section
->size
));
5409 /* The version number. */
5410 uint16_t version
= read_2_bytes (abfd
, addr
);
5414 warning (_("Section .debug_names in %s has unsupported version %d, "
5415 "ignoring .debug_names."),
5421 uint16_t padding
= read_2_bytes (abfd
, addr
);
5425 warning (_("Section .debug_names in %s has unsupported padding %d, "
5426 "ignoring .debug_names."),
5431 /* comp_unit_count - The number of CUs in the CU list. */
5432 map
.cu_count
= read_4_bytes (abfd
, addr
);
5435 /* local_type_unit_count - The number of TUs in the local TU
5437 map
.tu_count
= read_4_bytes (abfd
, addr
);
5440 /* foreign_type_unit_count - The number of TUs in the foreign TU
5442 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5444 if (foreign_tu_count
!= 0)
5446 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5447 "ignoring .debug_names."),
5448 filename
, static_cast<unsigned long> (foreign_tu_count
));
5452 /* bucket_count - The number of hash buckets in the hash lookup
5454 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5457 /* name_count - The number of unique names in the index. */
5458 map
.name_count
= read_4_bytes (abfd
, addr
);
5461 /* abbrev_table_size - The size in bytes of the abbreviations
5463 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5466 /* augmentation_string_size - The size in bytes of the augmentation
5467 string. This value is rounded up to a multiple of 4. */
5468 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5470 map
.augmentation_is_gdb
= ((augmentation_string_size
5471 == sizeof (dwarf5_augmentation
))
5472 && memcmp (addr
, dwarf5_augmentation
,
5473 sizeof (dwarf5_augmentation
)) == 0);
5474 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5475 addr
+= augmentation_string_size
;
5478 map
.cu_table_reordered
= addr
;
5479 addr
+= map
.cu_count
* map
.offset_size
;
5481 /* List of Local TUs */
5482 map
.tu_table_reordered
= addr
;
5483 addr
+= map
.tu_count
* map
.offset_size
;
5485 /* Hash Lookup Table */
5486 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5487 addr
+= map
.bucket_count
* 4;
5488 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5489 addr
+= map
.name_count
* 4;
5492 map
.name_table_string_offs_reordered
= addr
;
5493 addr
+= map
.name_count
* map
.offset_size
;
5494 map
.name_table_entry_offs_reordered
= addr
;
5495 addr
+= map
.name_count
* map
.offset_size
;
5497 const gdb_byte
*abbrev_table_start
= addr
;
5500 unsigned int bytes_read
;
5501 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5506 const auto insertpair
5507 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5508 if (!insertpair
.second
)
5510 warning (_("Section .debug_names in %s has duplicate index %s, "
5511 "ignoring .debug_names."),
5512 filename
, pulongest (index_num
));
5515 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5516 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5521 mapped_debug_names::index_val::attr attr
;
5522 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5524 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5526 if (attr
.form
== DW_FORM_implicit_const
)
5528 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5532 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5534 indexval
.attr_vec
.push_back (std::move (attr
));
5537 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5539 warning (_("Section .debug_names in %s has abbreviation_table "
5540 "of size %zu vs. written as %u, ignoring .debug_names."),
5541 filename
, addr
- abbrev_table_start
, abbrev_table_size
);
5544 map
.entry_pool
= addr
;
5549 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5553 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5554 const mapped_debug_names
&map
,
5555 dwarf2_section_info
§ion
,
5558 sect_offset sect_off_prev
;
5559 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5561 sect_offset sect_off_next
;
5562 if (i
< map
.cu_count
)
5565 = (sect_offset
) (extract_unsigned_integer
5566 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5568 map
.dwarf5_byte_order
));
5571 sect_off_next
= (sect_offset
) section
.size
;
5574 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5575 dwarf2_per_cu_data
*per_cu
5576 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5577 sect_off_prev
, length
);
5578 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5580 sect_off_prev
= sect_off_next
;
5584 /* Read the CU list from the mapped index, and use it to create all
5585 the CU objects for this dwarf2_per_objfile. */
5588 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5589 const mapped_debug_names
&map
,
5590 const mapped_debug_names
&dwz_map
)
5592 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5593 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5595 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5596 dwarf2_per_objfile
->info
,
5597 false /* is_dwz */);
5599 if (dwz_map
.cu_count
== 0)
5602 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5603 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5607 /* Read .debug_names. If everything went ok, initialize the "quick"
5608 elements of all the CUs and return true. Otherwise, return false. */
5611 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5613 mapped_debug_names
local_map (dwarf2_per_objfile
);
5614 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5615 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5617 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5618 &dwarf2_per_objfile
->debug_names
,
5622 /* Don't use the index if it's empty. */
5623 if (local_map
.name_count
== 0)
5626 /* If there is a .dwz file, read it so we can get its CU list as
5628 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5631 if (!read_debug_names_from_section (objfile
,
5632 bfd_get_filename (dwz
->dwz_bfd
),
5633 &dwz
->debug_names
, dwz_map
))
5635 warning (_("could not read '.debug_names' section from %s; skipping"),
5636 bfd_get_filename (dwz
->dwz_bfd
));
5641 create_cus_from_debug_names (dwarf2_per_objfile
, local_map
, dwz_map
);
5643 if (local_map
.tu_count
!= 0)
5645 /* We can only handle a single .debug_types when we have an
5647 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
5650 dwarf2_section_info
*section
= VEC_index (dwarf2_section_info_def
,
5651 dwarf2_per_objfile
->types
, 0);
5653 create_signatured_type_table_from_debug_names
5654 (dwarf2_per_objfile
, local_map
, section
, &dwarf2_per_objfile
->abbrev
);
5657 create_addrmap_from_aranges (dwarf2_per_objfile
,
5658 &dwarf2_per_objfile
->debug_aranges
);
5660 dwarf2_per_objfile
->debug_names_table
.reset
5661 (new mapped_debug_names (dwarf2_per_objfile
));
5662 *dwarf2_per_objfile
->debug_names_table
= std::move (local_map
);
5663 dwarf2_per_objfile
->using_index
= 1;
5664 dwarf2_per_objfile
->quick_file_names_table
=
5665 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5670 /* Type used to manage iterating over all CUs looking for a symbol for
5673 class dw2_debug_names_iterator
5676 /* If WANT_SPECIFIC_BLOCK is true, only look for symbols in block
5677 BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
5678 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5679 bool want_specific_block
,
5680 block_enum block_index
, domain_enum domain
,
5682 : m_map (map
), m_want_specific_block (want_specific_block
),
5683 m_block_index (block_index
), m_domain (domain
),
5684 m_addr (find_vec_in_debug_names (map
, name
))
5687 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5688 search_domain search
, uint32_t namei
)
5691 m_addr (find_vec_in_debug_names (map
, namei
))
5694 /* Return the next matching CU or NULL if there are no more. */
5695 dwarf2_per_cu_data
*next ();
5698 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5700 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5703 /* The internalized form of .debug_names. */
5704 const mapped_debug_names
&m_map
;
5706 /* If true, only look for symbols that match BLOCK_INDEX. */
5707 const bool m_want_specific_block
= false;
5709 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
5710 Unused if !WANT_SPECIFIC_BLOCK - FIRST_LOCAL_BLOCK is an invalid
5712 const block_enum m_block_index
= FIRST_LOCAL_BLOCK
;
5714 /* The kind of symbol we're looking for. */
5715 const domain_enum m_domain
= UNDEF_DOMAIN
;
5716 const search_domain m_search
= ALL_DOMAIN
;
5718 /* The list of CUs from the index entry of the symbol, or NULL if
5720 const gdb_byte
*m_addr
;
5724 mapped_debug_names::namei_to_name (uint32_t namei
) const
5726 const ULONGEST namei_string_offs
5727 = extract_unsigned_integer ((name_table_string_offs_reordered
5728 + namei
* offset_size
),
5731 return read_indirect_string_at_offset
5732 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5735 /* Find a slot in .debug_names for the object named NAME. If NAME is
5736 found, return pointer to its pool data. If NAME cannot be found,
5740 dw2_debug_names_iterator::find_vec_in_debug_names
5741 (const mapped_debug_names
&map
, const char *name
)
5743 int (*cmp
) (const char *, const char *);
5745 if (current_language
->la_language
== language_cplus
5746 || current_language
->la_language
== language_fortran
5747 || current_language
->la_language
== language_d
)
5749 /* NAME is already canonical. Drop any qualifiers as
5750 .debug_names does not contain any. */
5752 if (strchr (name
, '(') != NULL
)
5754 gdb::unique_xmalloc_ptr
<char> without_params
5755 = cp_remove_params (name
);
5757 if (without_params
!= NULL
)
5759 name
= without_params
.get();
5764 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5766 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5768 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5769 (map
.bucket_table_reordered
5770 + (full_hash
% map
.bucket_count
)), 4,
5771 map
.dwarf5_byte_order
);
5775 if (namei
>= map
.name_count
)
5777 complaint (&symfile_complaints
,
5778 _("Wrong .debug_names with name index %u but name_count=%u "
5780 namei
, map
.name_count
,
5781 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5787 const uint32_t namei_full_hash
5788 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5789 (map
.hash_table_reordered
+ namei
), 4,
5790 map
.dwarf5_byte_order
);
5791 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5794 if (full_hash
== namei_full_hash
)
5796 const char *const namei_string
= map
.namei_to_name (namei
);
5798 #if 0 /* An expensive sanity check. */
5799 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5801 complaint (&symfile_complaints
,
5802 _("Wrong .debug_names hash for string at index %u "
5804 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5809 if (cmp (namei_string
, name
) == 0)
5811 const ULONGEST namei_entry_offs
5812 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5813 + namei
* map
.offset_size
),
5814 map
.offset_size
, map
.dwarf5_byte_order
);
5815 return map
.entry_pool
+ namei_entry_offs
;
5820 if (namei
>= map
.name_count
)
5826 dw2_debug_names_iterator::find_vec_in_debug_names
5827 (const mapped_debug_names
&map
, uint32_t namei
)
5829 if (namei
>= map
.name_count
)
5831 complaint (&symfile_complaints
,
5832 _("Wrong .debug_names with name index %u but name_count=%u "
5834 namei
, map
.name_count
,
5835 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5839 const ULONGEST namei_entry_offs
5840 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5841 + namei
* map
.offset_size
),
5842 map
.offset_size
, map
.dwarf5_byte_order
);
5843 return map
.entry_pool
+ namei_entry_offs
;
5846 /* See dw2_debug_names_iterator. */
5848 dwarf2_per_cu_data
*
5849 dw2_debug_names_iterator::next ()
5854 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5855 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5856 bfd
*const abfd
= objfile
->obfd
;
5860 unsigned int bytes_read
;
5861 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5862 m_addr
+= bytes_read
;
5866 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5867 if (indexval_it
== m_map
.abbrev_map
.cend ())
5869 complaint (&symfile_complaints
,
5870 _("Wrong .debug_names undefined abbrev code %s "
5872 pulongest (abbrev
), objfile_name (objfile
));
5875 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5876 bool have_is_static
= false;
5878 dwarf2_per_cu_data
*per_cu
= NULL
;
5879 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5884 case DW_FORM_implicit_const
:
5885 ull
= attr
.implicit_const
;
5887 case DW_FORM_flag_present
:
5891 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5892 m_addr
+= bytes_read
;
5895 complaint (&symfile_complaints
,
5896 _("Unsupported .debug_names form %s [in module %s]"),
5897 dwarf_form_name (attr
.form
),
5898 objfile_name (objfile
));
5901 switch (attr
.dw_idx
)
5903 case DW_IDX_compile_unit
:
5904 /* Don't crash on bad data. */
5905 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5907 complaint (&symfile_complaints
,
5908 _(".debug_names entry has bad CU index %s"
5911 objfile_name (dwarf2_per_objfile
->objfile
));
5914 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5916 case DW_IDX_type_unit
:
5917 /* Don't crash on bad data. */
5918 if (ull
>= dwarf2_per_objfile
->n_type_units
)
5920 complaint (&symfile_complaints
,
5921 _(".debug_names entry has bad TU index %s"
5924 objfile_name (dwarf2_per_objfile
->objfile
));
5927 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5929 case DW_IDX_GNU_internal
:
5930 if (!m_map
.augmentation_is_gdb
)
5932 have_is_static
= true;
5935 case DW_IDX_GNU_external
:
5936 if (!m_map
.augmentation_is_gdb
)
5938 have_is_static
= true;
5944 /* Skip if already read in. */
5945 if (per_cu
->v
.quick
->compunit_symtab
)
5948 /* Check static vs global. */
5951 const bool want_static
= m_block_index
!= GLOBAL_BLOCK
;
5952 if (m_want_specific_block
&& want_static
!= is_static
)
5956 /* Match dw2_symtab_iter_next, symbol_kind
5957 and debug_names::psymbol_tag. */
5961 switch (indexval
.dwarf_tag
)
5963 case DW_TAG_variable
:
5964 case DW_TAG_subprogram
:
5965 /* Some types are also in VAR_DOMAIN. */
5966 case DW_TAG_typedef
:
5967 case DW_TAG_structure_type
:
5974 switch (indexval
.dwarf_tag
)
5976 case DW_TAG_typedef
:
5977 case DW_TAG_structure_type
:
5984 switch (indexval
.dwarf_tag
)
5987 case DW_TAG_variable
:
5997 /* Match dw2_expand_symtabs_matching, symbol_kind and
5998 debug_names::psymbol_tag. */
6001 case VARIABLES_DOMAIN
:
6002 switch (indexval
.dwarf_tag
)
6004 case DW_TAG_variable
:
6010 case FUNCTIONS_DOMAIN
:
6011 switch (indexval
.dwarf_tag
)
6013 case DW_TAG_subprogram
:
6020 switch (indexval
.dwarf_tag
)
6022 case DW_TAG_typedef
:
6023 case DW_TAG_structure_type
:
6036 static struct compunit_symtab
*
6037 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, int block_index_int
,
6038 const char *name
, domain_enum domain
)
6040 const block_enum block_index
= static_cast<block_enum
> (block_index_int
);
6041 struct dwarf2_per_objfile
*dwarf2_per_objfile
6042 = get_dwarf2_per_objfile (objfile
);
6044 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6047 /* index is NULL if OBJF_READNOW. */
6050 const auto &map
= *mapp
;
6052 dw2_debug_names_iterator
iter (map
, true /* want_specific_block */,
6053 block_index
, domain
, name
);
6055 struct compunit_symtab
*stab_best
= NULL
;
6056 struct dwarf2_per_cu_data
*per_cu
;
6057 while ((per_cu
= iter
.next ()) != NULL
)
6059 struct symbol
*sym
, *with_opaque
= NULL
;
6060 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
6061 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6062 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6064 sym
= block_find_symbol (block
, name
, domain
,
6065 block_find_non_opaque_type_preferred
,
6068 /* Some caution must be observed with overloaded functions and
6069 methods, since the index will not contain any overload
6070 information (but NAME might contain it). */
6073 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6075 if (with_opaque
!= NULL
6076 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6079 /* Keep looking through other CUs. */
6085 /* This dumps minimal information about .debug_names. It is called
6086 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6087 uses this to verify that .debug_names has been loaded. */
6090 dw2_debug_names_dump (struct objfile
*objfile
)
6092 struct dwarf2_per_objfile
*dwarf2_per_objfile
6093 = get_dwarf2_per_objfile (objfile
);
6095 gdb_assert (dwarf2_per_objfile
->using_index
);
6096 printf_filtered (".debug_names:");
6097 if (dwarf2_per_objfile
->debug_names_table
)
6098 printf_filtered (" exists\n");
6100 printf_filtered (" faked for \"readnow\"\n");
6101 printf_filtered ("\n");
6105 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6106 const char *func_name
)
6108 struct dwarf2_per_objfile
*dwarf2_per_objfile
6109 = get_dwarf2_per_objfile (objfile
);
6111 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6112 if (dwarf2_per_objfile
->debug_names_table
)
6114 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6116 /* Note: It doesn't matter what we pass for block_index here. */
6117 dw2_debug_names_iterator
iter (map
, false /* want_specific_block */,
6118 GLOBAL_BLOCK
, VAR_DOMAIN
, func_name
);
6120 struct dwarf2_per_cu_data
*per_cu
;
6121 while ((per_cu
= iter
.next ()) != NULL
)
6122 dw2_instantiate_symtab (per_cu
);
6127 dw2_debug_names_expand_symtabs_matching
6128 (struct objfile
*objfile
,
6129 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6130 const lookup_name_info
&lookup_name
,
6131 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6132 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6133 enum search_domain kind
)
6135 struct dwarf2_per_objfile
*dwarf2_per_objfile
6136 = get_dwarf2_per_objfile (objfile
);
6138 /* debug_names_table is NULL if OBJF_READNOW. */
6139 if (!dwarf2_per_objfile
->debug_names_table
)
6142 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6144 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6146 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6148 kind
, [&] (offset_type namei
)
6150 /* The name was matched, now expand corresponding CUs that were
6152 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6154 struct dwarf2_per_cu_data
*per_cu
;
6155 while ((per_cu
= iter
.next ()) != NULL
)
6156 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6161 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6164 dw2_find_last_source_symtab
,
6165 dw2_forget_cached_source_info
,
6166 dw2_map_symtabs_matching_filename
,
6167 dw2_debug_names_lookup_symbol
,
6169 dw2_debug_names_dump
,
6171 dw2_debug_names_expand_symtabs_for_function
,
6172 dw2_expand_all_symtabs
,
6173 dw2_expand_symtabs_with_fullname
,
6174 dw2_map_matching_symbols
,
6175 dw2_debug_names_expand_symtabs_matching
,
6176 dw2_find_pc_sect_compunit_symtab
,
6178 dw2_map_symbol_filenames
6181 /* See symfile.h. */
6184 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6186 struct dwarf2_per_objfile
*dwarf2_per_objfile
6187 = get_dwarf2_per_objfile (objfile
);
6189 /* If we're about to read full symbols, don't bother with the
6190 indices. In this case we also don't care if some other debug
6191 format is making psymtabs, because they are all about to be
6193 if ((objfile
->flags
& OBJF_READNOW
))
6195 dwarf2_per_objfile
->using_index
= 1;
6196 create_all_comp_units (dwarf2_per_objfile
);
6197 create_all_type_units (dwarf2_per_objfile
);
6198 dwarf2_per_objfile
->quick_file_names_table
6199 = create_quick_file_names_table
6200 (dwarf2_per_objfile
->all_comp_units
.size ());
6202 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6203 + dwarf2_per_objfile
->n_type_units
); ++i
)
6205 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6207 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6208 struct dwarf2_per_cu_quick_data
);
6211 /* Return 1 so that gdb sees the "quick" functions. However,
6212 these functions will be no-ops because we will have expanded
6214 *index_kind
= dw_index_kind::GDB_INDEX
;
6218 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6220 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6224 if (dwarf2_read_index (dwarf2_per_objfile
))
6226 *index_kind
= dw_index_kind::GDB_INDEX
;
6235 /* Build a partial symbol table. */
6238 dwarf2_build_psymtabs (struct objfile
*objfile
)
6240 struct dwarf2_per_objfile
*dwarf2_per_objfile
6241 = get_dwarf2_per_objfile (objfile
);
6243 if (objfile
->global_psymbols
.capacity () == 0
6244 && objfile
->static_psymbols
.capacity () == 0)
6245 init_psymbol_list (objfile
, 1024);
6249 /* This isn't really ideal: all the data we allocate on the
6250 objfile's obstack is still uselessly kept around. However,
6251 freeing it seems unsafe. */
6252 psymtab_discarder
psymtabs (objfile
);
6253 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6256 CATCH (except
, RETURN_MASK_ERROR
)
6258 exception_print (gdb_stderr
, except
);
6263 /* Return the total length of the CU described by HEADER. */
6266 get_cu_length (const struct comp_unit_head
*header
)
6268 return header
->initial_length_size
+ header
->length
;
6271 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6274 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6276 sect_offset bottom
= cu_header
->sect_off
;
6277 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6279 return sect_off
>= bottom
&& sect_off
< top
;
6282 /* Find the base address of the compilation unit for range lists and
6283 location lists. It will normally be specified by DW_AT_low_pc.
6284 In DWARF-3 draft 4, the base address could be overridden by
6285 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6286 compilation units with discontinuous ranges. */
6289 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6291 struct attribute
*attr
;
6294 cu
->base_address
= 0;
6296 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6299 cu
->base_address
= attr_value_as_address (attr
);
6304 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6307 cu
->base_address
= attr_value_as_address (attr
);
6313 /* Read in the comp unit header information from the debug_info at info_ptr.
6314 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6315 NOTE: This leaves members offset, first_die_offset to be filled in
6318 static const gdb_byte
*
6319 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6320 const gdb_byte
*info_ptr
,
6321 struct dwarf2_section_info
*section
,
6322 rcuh_kind section_kind
)
6325 unsigned int bytes_read
;
6326 const char *filename
= get_section_file_name (section
);
6327 bfd
*abfd
= get_section_bfd_owner (section
);
6329 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6330 cu_header
->initial_length_size
= bytes_read
;
6331 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6332 info_ptr
+= bytes_read
;
6333 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6335 if (cu_header
->version
< 5)
6336 switch (section_kind
)
6338 case rcuh_kind::COMPILE
:
6339 cu_header
->unit_type
= DW_UT_compile
;
6341 case rcuh_kind::TYPE
:
6342 cu_header
->unit_type
= DW_UT_type
;
6345 internal_error (__FILE__
, __LINE__
,
6346 _("read_comp_unit_head: invalid section_kind"));
6350 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6351 (read_1_byte (abfd
, info_ptr
));
6353 switch (cu_header
->unit_type
)
6356 if (section_kind
!= rcuh_kind::COMPILE
)
6357 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6358 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
6362 section_kind
= rcuh_kind::TYPE
;
6365 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6366 "(is %d, should be %d or %d) [in module %s]"),
6367 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
6370 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6373 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6376 info_ptr
+= bytes_read
;
6377 if (cu_header
->version
< 5)
6379 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6382 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6383 if (signed_addr
< 0)
6384 internal_error (__FILE__
, __LINE__
,
6385 _("read_comp_unit_head: dwarf from non elf file"));
6386 cu_header
->signed_addr_p
= signed_addr
;
6388 if (section_kind
== rcuh_kind::TYPE
)
6390 LONGEST type_offset
;
6392 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6395 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6396 info_ptr
+= bytes_read
;
6397 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6398 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6399 error (_("Dwarf Error: Too big type_offset in compilation unit "
6400 "header (is %s) [in module %s]"), plongest (type_offset
),
6407 /* Helper function that returns the proper abbrev section for
6410 static struct dwarf2_section_info
*
6411 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6413 struct dwarf2_section_info
*abbrev
;
6414 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6416 if (this_cu
->is_dwz
)
6417 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6419 abbrev
= &dwarf2_per_objfile
->abbrev
;
6424 /* Subroutine of read_and_check_comp_unit_head and
6425 read_and_check_type_unit_head to simplify them.
6426 Perform various error checking on the header. */
6429 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6430 struct comp_unit_head
*header
,
6431 struct dwarf2_section_info
*section
,
6432 struct dwarf2_section_info
*abbrev_section
)
6434 const char *filename
= get_section_file_name (section
);
6436 if (header
->version
< 2 || header
->version
> 5)
6437 error (_("Dwarf Error: wrong version in compilation unit header "
6438 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
6441 if (to_underlying (header
->abbrev_sect_off
)
6442 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6443 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6444 "(offset %s + 6) [in module %s]"),
6445 sect_offset_str (header
->abbrev_sect_off
),
6446 sect_offset_str (header
->sect_off
),
6449 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6450 avoid potential 32-bit overflow. */
6451 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6453 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6454 "(offset %s + 0) [in module %s]"),
6455 header
->length
, sect_offset_str (header
->sect_off
),
6459 /* Read in a CU/TU header and perform some basic error checking.
6460 The contents of the header are stored in HEADER.
6461 The result is a pointer to the start of the first DIE. */
6463 static const gdb_byte
*
6464 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6465 struct comp_unit_head
*header
,
6466 struct dwarf2_section_info
*section
,
6467 struct dwarf2_section_info
*abbrev_section
,
6468 const gdb_byte
*info_ptr
,
6469 rcuh_kind section_kind
)
6471 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6473 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6475 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6477 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6479 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6485 /* Fetch the abbreviation table offset from a comp or type unit header. */
6488 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6489 struct dwarf2_section_info
*section
,
6490 sect_offset sect_off
)
6492 bfd
*abfd
= get_section_bfd_owner (section
);
6493 const gdb_byte
*info_ptr
;
6494 unsigned int initial_length_size
, offset_size
;
6497 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6498 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6499 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6500 offset_size
= initial_length_size
== 4 ? 4 : 8;
6501 info_ptr
+= initial_length_size
;
6503 version
= read_2_bytes (abfd
, info_ptr
);
6507 /* Skip unit type and address size. */
6511 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6514 /* Allocate a new partial symtab for file named NAME and mark this new
6515 partial symtab as being an include of PST. */
6518 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6519 struct objfile
*objfile
)
6521 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6523 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6525 /* It shares objfile->objfile_obstack. */
6526 subpst
->dirname
= pst
->dirname
;
6529 subpst
->textlow
= 0;
6530 subpst
->texthigh
= 0;
6532 subpst
->dependencies
6533 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
6534 subpst
->dependencies
[0] = pst
;
6535 subpst
->number_of_dependencies
= 1;
6537 subpst
->globals_offset
= 0;
6538 subpst
->n_global_syms
= 0;
6539 subpst
->statics_offset
= 0;
6540 subpst
->n_static_syms
= 0;
6541 subpst
->compunit_symtab
= NULL
;
6542 subpst
->read_symtab
= pst
->read_symtab
;
6545 /* No private part is necessary for include psymtabs. This property
6546 can be used to differentiate between such include psymtabs and
6547 the regular ones. */
6548 subpst
->read_symtab_private
= NULL
;
6551 /* Read the Line Number Program data and extract the list of files
6552 included by the source file represented by PST. Build an include
6553 partial symtab for each of these included files. */
6556 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6557 struct die_info
*die
,
6558 struct partial_symtab
*pst
)
6561 struct attribute
*attr
;
6563 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6565 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6567 return; /* No linetable, so no includes. */
6569 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
6570 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
6574 hash_signatured_type (const void *item
)
6576 const struct signatured_type
*sig_type
6577 = (const struct signatured_type
*) item
;
6579 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6580 return sig_type
->signature
;
6584 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6586 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6587 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6589 return lhs
->signature
== rhs
->signature
;
6592 /* Allocate a hash table for signatured types. */
6595 allocate_signatured_type_table (struct objfile
*objfile
)
6597 return htab_create_alloc_ex (41,
6598 hash_signatured_type
,
6601 &objfile
->objfile_obstack
,
6602 hashtab_obstack_allocate
,
6603 dummy_obstack_deallocate
);
6606 /* A helper function to add a signatured type CU to a table. */
6609 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6611 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6612 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
6620 /* A helper for create_debug_types_hash_table. Read types from SECTION
6621 and fill them into TYPES_HTAB. It will process only type units,
6622 therefore DW_UT_type. */
6625 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6626 struct dwo_file
*dwo_file
,
6627 dwarf2_section_info
*section
, htab_t
&types_htab
,
6628 rcuh_kind section_kind
)
6630 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6631 struct dwarf2_section_info
*abbrev_section
;
6633 const gdb_byte
*info_ptr
, *end_ptr
;
6635 abbrev_section
= (dwo_file
!= NULL
6636 ? &dwo_file
->sections
.abbrev
6637 : &dwarf2_per_objfile
->abbrev
);
6639 if (dwarf_read_debug
)
6640 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6641 get_section_name (section
),
6642 get_section_file_name (abbrev_section
));
6644 dwarf2_read_section (objfile
, section
);
6645 info_ptr
= section
->buffer
;
6647 if (info_ptr
== NULL
)
6650 /* We can't set abfd until now because the section may be empty or
6651 not present, in which case the bfd is unknown. */
6652 abfd
= get_section_bfd_owner (section
);
6654 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6655 because we don't need to read any dies: the signature is in the
6658 end_ptr
= info_ptr
+ section
->size
;
6659 while (info_ptr
< end_ptr
)
6661 struct signatured_type
*sig_type
;
6662 struct dwo_unit
*dwo_tu
;
6664 const gdb_byte
*ptr
= info_ptr
;
6665 struct comp_unit_head header
;
6666 unsigned int length
;
6668 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6670 /* Initialize it due to a false compiler warning. */
6671 header
.signature
= -1;
6672 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6674 /* We need to read the type's signature in order to build the hash
6675 table, but we don't need anything else just yet. */
6677 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6678 abbrev_section
, ptr
, section_kind
);
6680 length
= get_cu_length (&header
);
6682 /* Skip dummy type units. */
6683 if (ptr
>= info_ptr
+ length
6684 || peek_abbrev_code (abfd
, ptr
) == 0
6685 || header
.unit_type
!= DW_UT_type
)
6691 if (types_htab
== NULL
)
6694 types_htab
= allocate_dwo_unit_table (objfile
);
6696 types_htab
= allocate_signatured_type_table (objfile
);
6702 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6704 dwo_tu
->dwo_file
= dwo_file
;
6705 dwo_tu
->signature
= header
.signature
;
6706 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6707 dwo_tu
->section
= section
;
6708 dwo_tu
->sect_off
= sect_off
;
6709 dwo_tu
->length
= length
;
6713 /* N.B.: type_offset is not usable if this type uses a DWO file.
6714 The real type_offset is in the DWO file. */
6716 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6717 struct signatured_type
);
6718 sig_type
->signature
= header
.signature
;
6719 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6720 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6721 sig_type
->per_cu
.is_debug_types
= 1;
6722 sig_type
->per_cu
.section
= section
;
6723 sig_type
->per_cu
.sect_off
= sect_off
;
6724 sig_type
->per_cu
.length
= length
;
6727 slot
= htab_find_slot (types_htab
,
6728 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6730 gdb_assert (slot
!= NULL
);
6733 sect_offset dup_sect_off
;
6737 const struct dwo_unit
*dup_tu
6738 = (const struct dwo_unit
*) *slot
;
6740 dup_sect_off
= dup_tu
->sect_off
;
6744 const struct signatured_type
*dup_tu
6745 = (const struct signatured_type
*) *slot
;
6747 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6750 complaint (&symfile_complaints
,
6751 _("debug type entry at offset %s is duplicate to"
6752 " the entry at offset %s, signature %s"),
6753 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6754 hex_string (header
.signature
));
6756 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6758 if (dwarf_read_debug
> 1)
6759 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6760 sect_offset_str (sect_off
),
6761 hex_string (header
.signature
));
6767 /* Create the hash table of all entries in the .debug_types
6768 (or .debug_types.dwo) section(s).
6769 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6770 otherwise it is NULL.
6772 The result is a pointer to the hash table or NULL if there are no types.
6774 Note: This function processes DWO files only, not DWP files. */
6777 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6778 struct dwo_file
*dwo_file
,
6779 VEC (dwarf2_section_info_def
) *types
,
6783 struct dwarf2_section_info
*section
;
6785 if (VEC_empty (dwarf2_section_info_def
, types
))
6789 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
6791 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, section
,
6792 types_htab
, rcuh_kind::TYPE
);
6795 /* Create the hash table of all entries in the .debug_types section,
6796 and initialize all_type_units.
6797 The result is zero if there is an error (e.g. missing .debug_types section),
6798 otherwise non-zero. */
6801 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6803 htab_t types_htab
= NULL
;
6804 struct signatured_type
**iter
;
6806 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6807 &dwarf2_per_objfile
->info
, types_htab
,
6808 rcuh_kind::COMPILE
);
6809 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6810 dwarf2_per_objfile
->types
, types_htab
);
6811 if (types_htab
== NULL
)
6813 dwarf2_per_objfile
->signatured_types
= NULL
;
6817 dwarf2_per_objfile
->signatured_types
= types_htab
;
6819 dwarf2_per_objfile
->n_type_units
6820 = dwarf2_per_objfile
->n_allocated_type_units
6821 = htab_elements (types_htab
);
6822 dwarf2_per_objfile
->all_type_units
=
6823 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
6824 iter
= &dwarf2_per_objfile
->all_type_units
[0];
6825 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
6826 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
6827 == dwarf2_per_objfile
->n_type_units
);
6832 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6833 If SLOT is non-NULL, it is the entry to use in the hash table.
6834 Otherwise we find one. */
6836 static struct signatured_type
*
6837 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6840 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6841 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
6842 struct signatured_type
*sig_type
;
6844 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
6846 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
6848 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
6849 dwarf2_per_objfile
->n_allocated_type_units
= 1;
6850 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
6851 dwarf2_per_objfile
->all_type_units
6852 = XRESIZEVEC (struct signatured_type
*,
6853 dwarf2_per_objfile
->all_type_units
,
6854 dwarf2_per_objfile
->n_allocated_type_units
);
6855 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6857 dwarf2_per_objfile
->n_type_units
= n_type_units
;
6859 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6860 struct signatured_type
);
6861 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
6862 sig_type
->signature
= sig
;
6863 sig_type
->per_cu
.is_debug_types
= 1;
6864 if (dwarf2_per_objfile
->using_index
)
6866 sig_type
->per_cu
.v
.quick
=
6867 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6868 struct dwarf2_per_cu_quick_data
);
6873 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6876 gdb_assert (*slot
== NULL
);
6878 /* The rest of sig_type must be filled in by the caller. */
6882 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6883 Fill in SIG_ENTRY with DWO_ENTRY. */
6886 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6887 struct signatured_type
*sig_entry
,
6888 struct dwo_unit
*dwo_entry
)
6890 /* Make sure we're not clobbering something we don't expect to. */
6891 gdb_assert (! sig_entry
->per_cu
.queued
);
6892 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6893 if (dwarf2_per_objfile
->using_index
)
6895 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6896 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6899 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6900 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6901 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6902 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6903 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6905 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6906 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6907 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6908 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6909 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6910 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6911 sig_entry
->dwo_unit
= dwo_entry
;
6914 /* Subroutine of lookup_signatured_type.
6915 If we haven't read the TU yet, create the signatured_type data structure
6916 for a TU to be read in directly from a DWO file, bypassing the stub.
6917 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6918 using .gdb_index, then when reading a CU we want to stay in the DWO file
6919 containing that CU. Otherwise we could end up reading several other DWO
6920 files (due to comdat folding) to process the transitive closure of all the
6921 mentioned TUs, and that can be slow. The current DWO file will have every
6922 type signature that it needs.
6923 We only do this for .gdb_index because in the psymtab case we already have
6924 to read all the DWOs to build the type unit groups. */
6926 static struct signatured_type
*
6927 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6929 struct dwarf2_per_objfile
*dwarf2_per_objfile
6930 = cu
->per_cu
->dwarf2_per_objfile
;
6931 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6932 struct dwo_file
*dwo_file
;
6933 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6934 struct signatured_type find_sig_entry
, *sig_entry
;
6937 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6939 /* If TU skeletons have been removed then we may not have read in any
6941 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6943 dwarf2_per_objfile
->signatured_types
6944 = allocate_signatured_type_table (objfile
);
6947 /* We only ever need to read in one copy of a signatured type.
6948 Use the global signatured_types array to do our own comdat-folding
6949 of types. If this is the first time we're reading this TU, and
6950 the TU has an entry in .gdb_index, replace the recorded data from
6951 .gdb_index with this TU. */
6953 find_sig_entry
.signature
= sig
;
6954 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6955 &find_sig_entry
, INSERT
);
6956 sig_entry
= (struct signatured_type
*) *slot
;
6958 /* We can get here with the TU already read, *or* in the process of being
6959 read. Don't reassign the global entry to point to this DWO if that's
6960 the case. Also note that if the TU is already being read, it may not
6961 have come from a DWO, the program may be a mix of Fission-compiled
6962 code and non-Fission-compiled code. */
6964 /* Have we already tried to read this TU?
6965 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6966 needn't exist in the global table yet). */
6967 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6970 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6971 dwo_unit of the TU itself. */
6972 dwo_file
= cu
->dwo_unit
->dwo_file
;
6974 /* Ok, this is the first time we're reading this TU. */
6975 if (dwo_file
->tus
== NULL
)
6977 find_dwo_entry
.signature
= sig
;
6978 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
6979 if (dwo_entry
== NULL
)
6982 /* If the global table doesn't have an entry for this TU, add one. */
6983 if (sig_entry
== NULL
)
6984 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6986 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6987 sig_entry
->per_cu
.tu_read
= 1;
6991 /* Subroutine of lookup_signatured_type.
6992 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6993 then try the DWP file. If the TU stub (skeleton) has been removed then
6994 it won't be in .gdb_index. */
6996 static struct signatured_type
*
6997 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6999 struct dwarf2_per_objfile
*dwarf2_per_objfile
7000 = cu
->per_cu
->dwarf2_per_objfile
;
7001 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7002 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7003 struct dwo_unit
*dwo_entry
;
7004 struct signatured_type find_sig_entry
, *sig_entry
;
7007 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7008 gdb_assert (dwp_file
!= NULL
);
7010 /* If TU skeletons have been removed then we may not have read in any
7012 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7014 dwarf2_per_objfile
->signatured_types
7015 = allocate_signatured_type_table (objfile
);
7018 find_sig_entry
.signature
= sig
;
7019 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7020 &find_sig_entry
, INSERT
);
7021 sig_entry
= (struct signatured_type
*) *slot
;
7023 /* Have we already tried to read this TU?
7024 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7025 needn't exist in the global table yet). */
7026 if (sig_entry
!= NULL
)
7029 if (dwp_file
->tus
== NULL
)
7031 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7032 sig
, 1 /* is_debug_types */);
7033 if (dwo_entry
== NULL
)
7036 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7037 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7042 /* Lookup a signature based type for DW_FORM_ref_sig8.
7043 Returns NULL if signature SIG is not present in the table.
7044 It is up to the caller to complain about this. */
7046 static struct signatured_type
*
7047 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7049 struct dwarf2_per_objfile
*dwarf2_per_objfile
7050 = cu
->per_cu
->dwarf2_per_objfile
;
7053 && dwarf2_per_objfile
->using_index
)
7055 /* We're in a DWO/DWP file, and we're using .gdb_index.
7056 These cases require special processing. */
7057 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7058 return lookup_dwo_signatured_type (cu
, sig
);
7060 return lookup_dwp_signatured_type (cu
, sig
);
7064 struct signatured_type find_entry
, *entry
;
7066 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7068 find_entry
.signature
= sig
;
7069 entry
= ((struct signatured_type
*)
7070 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7075 /* Low level DIE reading support. */
7077 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7080 init_cu_die_reader (struct die_reader_specs
*reader
,
7081 struct dwarf2_cu
*cu
,
7082 struct dwarf2_section_info
*section
,
7083 struct dwo_file
*dwo_file
,
7084 struct abbrev_table
*abbrev_table
)
7086 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7087 reader
->abfd
= get_section_bfd_owner (section
);
7089 reader
->dwo_file
= dwo_file
;
7090 reader
->die_section
= section
;
7091 reader
->buffer
= section
->buffer
;
7092 reader
->buffer_end
= section
->buffer
+ section
->size
;
7093 reader
->comp_dir
= NULL
;
7094 reader
->abbrev_table
= abbrev_table
;
7097 /* Subroutine of init_cutu_and_read_dies to simplify it.
7098 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7099 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7102 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7103 from it to the DIE in the DWO. If NULL we are skipping the stub.
7104 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7105 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7106 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7107 STUB_COMP_DIR may be non-NULL.
7108 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7109 are filled in with the info of the DIE from the DWO file.
7110 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7111 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7112 kept around for at least as long as *RESULT_READER.
7114 The result is non-zero if a valid (non-dummy) DIE was found. */
7117 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7118 struct dwo_unit
*dwo_unit
,
7119 struct die_info
*stub_comp_unit_die
,
7120 const char *stub_comp_dir
,
7121 struct die_reader_specs
*result_reader
,
7122 const gdb_byte
**result_info_ptr
,
7123 struct die_info
**result_comp_unit_die
,
7124 int *result_has_children
,
7125 abbrev_table_up
*result_dwo_abbrev_table
)
7127 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7128 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7129 struct dwarf2_cu
*cu
= this_cu
->cu
;
7131 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7132 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7133 int i
,num_extra_attrs
;
7134 struct dwarf2_section_info
*dwo_abbrev_section
;
7135 struct attribute
*attr
;
7136 struct die_info
*comp_unit_die
;
7138 /* At most one of these may be provided. */
7139 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7141 /* These attributes aren't processed until later:
7142 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7143 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7144 referenced later. However, these attributes are found in the stub
7145 which we won't have later. In order to not impose this complication
7146 on the rest of the code, we read them here and copy them to the
7155 if (stub_comp_unit_die
!= NULL
)
7157 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7159 if (! this_cu
->is_debug_types
)
7160 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7161 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7162 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7163 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7164 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7166 /* There should be a DW_AT_addr_base attribute here (if needed).
7167 We need the value before we can process DW_FORM_GNU_addr_index. */
7169 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7171 cu
->addr_base
= DW_UNSND (attr
);
7173 /* There should be a DW_AT_ranges_base attribute here (if needed).
7174 We need the value before we can process DW_AT_ranges. */
7175 cu
->ranges_base
= 0;
7176 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7178 cu
->ranges_base
= DW_UNSND (attr
);
7180 else if (stub_comp_dir
!= NULL
)
7182 /* Reconstruct the comp_dir attribute to simplify the code below. */
7183 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7184 comp_dir
->name
= DW_AT_comp_dir
;
7185 comp_dir
->form
= DW_FORM_string
;
7186 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7187 DW_STRING (comp_dir
) = stub_comp_dir
;
7190 /* Set up for reading the DWO CU/TU. */
7191 cu
->dwo_unit
= dwo_unit
;
7192 dwarf2_section_info
*section
= dwo_unit
->section
;
7193 dwarf2_read_section (objfile
, section
);
7194 abfd
= get_section_bfd_owner (section
);
7195 begin_info_ptr
= info_ptr
= (section
->buffer
7196 + to_underlying (dwo_unit
->sect_off
));
7197 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7199 if (this_cu
->is_debug_types
)
7201 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7203 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7204 &cu
->header
, section
,
7206 info_ptr
, rcuh_kind::TYPE
);
7207 /* This is not an assert because it can be caused by bad debug info. */
7208 if (sig_type
->signature
!= cu
->header
.signature
)
7210 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7211 " TU at offset %s [in module %s]"),
7212 hex_string (sig_type
->signature
),
7213 hex_string (cu
->header
.signature
),
7214 sect_offset_str (dwo_unit
->sect_off
),
7215 bfd_get_filename (abfd
));
7217 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7218 /* For DWOs coming from DWP files, we don't know the CU length
7219 nor the type's offset in the TU until now. */
7220 dwo_unit
->length
= get_cu_length (&cu
->header
);
7221 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7223 /* Establish the type offset that can be used to lookup the type.
7224 For DWO files, we don't know it until now. */
7225 sig_type
->type_offset_in_section
7226 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7230 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7231 &cu
->header
, section
,
7233 info_ptr
, rcuh_kind::COMPILE
);
7234 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7235 /* For DWOs coming from DWP files, we don't know the CU length
7237 dwo_unit
->length
= get_cu_length (&cu
->header
);
7240 *result_dwo_abbrev_table
7241 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7242 cu
->header
.abbrev_sect_off
);
7243 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7244 result_dwo_abbrev_table
->get ());
7246 /* Read in the die, but leave space to copy over the attributes
7247 from the stub. This has the benefit of simplifying the rest of
7248 the code - all the work to maintain the illusion of a single
7249 DW_TAG_{compile,type}_unit DIE is done here. */
7250 num_extra_attrs
= ((stmt_list
!= NULL
)
7254 + (comp_dir
!= NULL
));
7255 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7256 result_has_children
, num_extra_attrs
);
7258 /* Copy over the attributes from the stub to the DIE we just read in. */
7259 comp_unit_die
= *result_comp_unit_die
;
7260 i
= comp_unit_die
->num_attrs
;
7261 if (stmt_list
!= NULL
)
7262 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7264 comp_unit_die
->attrs
[i
++] = *low_pc
;
7265 if (high_pc
!= NULL
)
7266 comp_unit_die
->attrs
[i
++] = *high_pc
;
7268 comp_unit_die
->attrs
[i
++] = *ranges
;
7269 if (comp_dir
!= NULL
)
7270 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7271 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7273 if (dwarf_die_debug
)
7275 fprintf_unfiltered (gdb_stdlog
,
7276 "Read die from %s@0x%x of %s:\n",
7277 get_section_name (section
),
7278 (unsigned) (begin_info_ptr
- section
->buffer
),
7279 bfd_get_filename (abfd
));
7280 dump_die (comp_unit_die
, dwarf_die_debug
);
7283 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7284 TUs by skipping the stub and going directly to the entry in the DWO file.
7285 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7286 to get it via circuitous means. Blech. */
7287 if (comp_dir
!= NULL
)
7288 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7290 /* Skip dummy compilation units. */
7291 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7292 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7295 *result_info_ptr
= info_ptr
;
7299 /* Subroutine of init_cutu_and_read_dies to simplify it.
7300 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7301 Returns NULL if the specified DWO unit cannot be found. */
7303 static struct dwo_unit
*
7304 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7305 struct die_info
*comp_unit_die
)
7307 struct dwarf2_cu
*cu
= this_cu
->cu
;
7309 struct dwo_unit
*dwo_unit
;
7310 const char *comp_dir
, *dwo_name
;
7312 gdb_assert (cu
!= NULL
);
7314 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7315 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7316 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7318 if (this_cu
->is_debug_types
)
7320 struct signatured_type
*sig_type
;
7322 /* Since this_cu is the first member of struct signatured_type,
7323 we can go from a pointer to one to a pointer to the other. */
7324 sig_type
= (struct signatured_type
*) this_cu
;
7325 signature
= sig_type
->signature
;
7326 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7330 struct attribute
*attr
;
7332 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7334 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7336 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7337 signature
= DW_UNSND (attr
);
7338 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7345 /* Subroutine of init_cutu_and_read_dies to simplify it.
7346 See it for a description of the parameters.
7347 Read a TU directly from a DWO file, bypassing the stub. */
7350 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7351 int use_existing_cu
, int keep
,
7352 die_reader_func_ftype
*die_reader_func
,
7355 std::unique_ptr
<dwarf2_cu
> new_cu
;
7356 struct signatured_type
*sig_type
;
7357 struct die_reader_specs reader
;
7358 const gdb_byte
*info_ptr
;
7359 struct die_info
*comp_unit_die
;
7361 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7363 /* Verify we can do the following downcast, and that we have the
7365 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7366 sig_type
= (struct signatured_type
*) this_cu
;
7367 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7369 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7371 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7372 /* There's no need to do the rereading_dwo_cu handling that
7373 init_cutu_and_read_dies does since we don't read the stub. */
7377 /* If !use_existing_cu, this_cu->cu must be NULL. */
7378 gdb_assert (this_cu
->cu
== NULL
);
7379 new_cu
.reset (new dwarf2_cu (this_cu
));
7382 /* A future optimization, if needed, would be to use an existing
7383 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7384 could share abbrev tables. */
7386 /* The abbreviation table used by READER, this must live at least as long as
7388 abbrev_table_up dwo_abbrev_table
;
7390 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7391 NULL
/* stub_comp_unit_die */,
7392 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7394 &comp_unit_die
, &has_children
,
7395 &dwo_abbrev_table
) == 0)
7401 /* All the "real" work is done here. */
7402 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7404 /* This duplicates the code in init_cutu_and_read_dies,
7405 but the alternative is making the latter more complex.
7406 This function is only for the special case of using DWO files directly:
7407 no point in overly complicating the general case just to handle this. */
7408 if (new_cu
!= NULL
&& keep
)
7410 /* Link this CU into read_in_chain. */
7411 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7412 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7413 /* The chain owns it now. */
7418 /* Initialize a CU (or TU) and read its DIEs.
7419 If the CU defers to a DWO file, read the DWO file as well.
7421 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7422 Otherwise the table specified in the comp unit header is read in and used.
7423 This is an optimization for when we already have the abbrev table.
7425 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7426 Otherwise, a new CU is allocated with xmalloc.
7428 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7429 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7431 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7432 linker) then DIE_READER_FUNC will not get called. */
7435 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7436 struct abbrev_table
*abbrev_table
,
7437 int use_existing_cu
, int keep
,
7438 die_reader_func_ftype
*die_reader_func
,
7441 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7442 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7443 struct dwarf2_section_info
*section
= this_cu
->section
;
7444 bfd
*abfd
= get_section_bfd_owner (section
);
7445 struct dwarf2_cu
*cu
;
7446 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7447 struct die_reader_specs reader
;
7448 struct die_info
*comp_unit_die
;
7450 struct attribute
*attr
;
7451 struct signatured_type
*sig_type
= NULL
;
7452 struct dwarf2_section_info
*abbrev_section
;
7453 /* Non-zero if CU currently points to a DWO file and we need to
7454 reread it. When this happens we need to reread the skeleton die
7455 before we can reread the DWO file (this only applies to CUs, not TUs). */
7456 int rereading_dwo_cu
= 0;
7458 if (dwarf_die_debug
)
7459 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7460 this_cu
->is_debug_types
? "type" : "comp",
7461 sect_offset_str (this_cu
->sect_off
));
7463 if (use_existing_cu
)
7466 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7467 file (instead of going through the stub), short-circuit all of this. */
7468 if (this_cu
->reading_dwo_directly
)
7470 /* Narrow down the scope of possibilities to have to understand. */
7471 gdb_assert (this_cu
->is_debug_types
);
7472 gdb_assert (abbrev_table
== NULL
);
7473 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7474 die_reader_func
, data
);
7478 /* This is cheap if the section is already read in. */
7479 dwarf2_read_section (objfile
, section
);
7481 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7483 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7485 std::unique_ptr
<dwarf2_cu
> new_cu
;
7486 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7489 /* If this CU is from a DWO file we need to start over, we need to
7490 refetch the attributes from the skeleton CU.
7491 This could be optimized by retrieving those attributes from when we
7492 were here the first time: the previous comp_unit_die was stored in
7493 comp_unit_obstack. But there's no data yet that we need this
7495 if (cu
->dwo_unit
!= NULL
)
7496 rereading_dwo_cu
= 1;
7500 /* If !use_existing_cu, this_cu->cu must be NULL. */
7501 gdb_assert (this_cu
->cu
== NULL
);
7502 new_cu
.reset (new dwarf2_cu (this_cu
));
7506 /* Get the header. */
7507 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7509 /* We already have the header, there's no need to read it in again. */
7510 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7514 if (this_cu
->is_debug_types
)
7516 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7517 &cu
->header
, section
,
7518 abbrev_section
, info_ptr
,
7521 /* Since per_cu is the first member of struct signatured_type,
7522 we can go from a pointer to one to a pointer to the other. */
7523 sig_type
= (struct signatured_type
*) this_cu
;
7524 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7525 gdb_assert (sig_type
->type_offset_in_tu
7526 == cu
->header
.type_cu_offset_in_tu
);
7527 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7529 /* LENGTH has not been set yet for type units if we're
7530 using .gdb_index. */
7531 this_cu
->length
= get_cu_length (&cu
->header
);
7533 /* Establish the type offset that can be used to lookup the type. */
7534 sig_type
->type_offset_in_section
=
7535 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7537 this_cu
->dwarf_version
= cu
->header
.version
;
7541 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7542 &cu
->header
, section
,
7545 rcuh_kind::COMPILE
);
7547 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7548 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7549 this_cu
->dwarf_version
= cu
->header
.version
;
7553 /* Skip dummy compilation units. */
7554 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7555 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7558 /* If we don't have them yet, read the abbrevs for this compilation unit.
7559 And if we need to read them now, make sure they're freed when we're
7560 done (own the table through ABBREV_TABLE_HOLDER). */
7561 abbrev_table_up abbrev_table_holder
;
7562 if (abbrev_table
!= NULL
)
7563 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7567 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7568 cu
->header
.abbrev_sect_off
);
7569 abbrev_table
= abbrev_table_holder
.get ();
7572 /* Read the top level CU/TU die. */
7573 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7574 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7576 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7577 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7578 table from the DWO file and pass the ownership over to us. It will be
7579 referenced from READER, so we must make sure to free it after we're done
7582 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7583 DWO CU, that this test will fail (the attribute will not be present). */
7584 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7585 abbrev_table_up dwo_abbrev_table
;
7588 struct dwo_unit
*dwo_unit
;
7589 struct die_info
*dwo_comp_unit_die
;
7593 complaint (&symfile_complaints
,
7594 _("compilation unit with DW_AT_GNU_dwo_name"
7595 " has children (offset %s) [in module %s]"),
7596 sect_offset_str (this_cu
->sect_off
),
7597 bfd_get_filename (abfd
));
7599 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7600 if (dwo_unit
!= NULL
)
7602 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7603 comp_unit_die
, NULL
,
7605 &dwo_comp_unit_die
, &has_children
,
7606 &dwo_abbrev_table
) == 0)
7611 comp_unit_die
= dwo_comp_unit_die
;
7615 /* Yikes, we couldn't find the rest of the DIE, we only have
7616 the stub. A complaint has already been logged. There's
7617 not much more we can do except pass on the stub DIE to
7618 die_reader_func. We don't want to throw an error on bad
7623 /* All of the above is setup for this call. Yikes. */
7624 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7626 /* Done, clean up. */
7627 if (new_cu
!= NULL
&& keep
)
7629 /* Link this CU into read_in_chain. */
7630 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7631 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7632 /* The chain owns it now. */
7637 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7638 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7639 to have already done the lookup to find the DWO file).
7641 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7642 THIS_CU->is_debug_types, but nothing else.
7644 We fill in THIS_CU->length.
7646 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7647 linker) then DIE_READER_FUNC will not get called.
7649 THIS_CU->cu is always freed when done.
7650 This is done in order to not leave THIS_CU->cu in a state where we have
7651 to care whether it refers to the "main" CU or the DWO CU. */
7654 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7655 struct dwo_file
*dwo_file
,
7656 die_reader_func_ftype
*die_reader_func
,
7659 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7660 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7661 struct dwarf2_section_info
*section
= this_cu
->section
;
7662 bfd
*abfd
= get_section_bfd_owner (section
);
7663 struct dwarf2_section_info
*abbrev_section
;
7664 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7665 struct die_reader_specs reader
;
7666 struct die_info
*comp_unit_die
;
7669 if (dwarf_die_debug
)
7670 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7671 this_cu
->is_debug_types
? "type" : "comp",
7672 sect_offset_str (this_cu
->sect_off
));
7674 gdb_assert (this_cu
->cu
== NULL
);
7676 abbrev_section
= (dwo_file
!= NULL
7677 ? &dwo_file
->sections
.abbrev
7678 : get_abbrev_section_for_cu (this_cu
));
7680 /* This is cheap if the section is already read in. */
7681 dwarf2_read_section (objfile
, section
);
7683 struct dwarf2_cu
cu (this_cu
);
7685 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7686 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7687 &cu
.header
, section
,
7688 abbrev_section
, info_ptr
,
7689 (this_cu
->is_debug_types
7691 : rcuh_kind::COMPILE
));
7693 this_cu
->length
= get_cu_length (&cu
.header
);
7695 /* Skip dummy compilation units. */
7696 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7697 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7700 abbrev_table_up abbrev_table
7701 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7702 cu
.header
.abbrev_sect_off
);
7704 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7705 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7707 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7710 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
7711 does not lookup the specified DWO file.
7712 This cannot be used to read DWO files.
7714 THIS_CU->cu is always freed when done.
7715 This is done in order to not leave THIS_CU->cu in a state where we have
7716 to care whether it refers to the "main" CU or the DWO CU.
7717 We can revisit this if the data shows there's a performance issue. */
7720 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7721 die_reader_func_ftype
*die_reader_func
,
7724 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
7727 /* Type Unit Groups.
7729 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7730 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7731 so that all types coming from the same compilation (.o file) are grouped
7732 together. A future step could be to put the types in the same symtab as
7733 the CU the types ultimately came from. */
7736 hash_type_unit_group (const void *item
)
7738 const struct type_unit_group
*tu_group
7739 = (const struct type_unit_group
*) item
;
7741 return hash_stmt_list_entry (&tu_group
->hash
);
7745 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7747 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7748 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7750 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7753 /* Allocate a hash table for type unit groups. */
7756 allocate_type_unit_groups_table (struct objfile
*objfile
)
7758 return htab_create_alloc_ex (3,
7759 hash_type_unit_group
,
7762 &objfile
->objfile_obstack
,
7763 hashtab_obstack_allocate
,
7764 dummy_obstack_deallocate
);
7767 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7768 partial symtabs. We combine several TUs per psymtab to not let the size
7769 of any one psymtab grow too big. */
7770 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7771 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7773 /* Helper routine for get_type_unit_group.
7774 Create the type_unit_group object used to hold one or more TUs. */
7776 static struct type_unit_group
*
7777 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7779 struct dwarf2_per_objfile
*dwarf2_per_objfile
7780 = cu
->per_cu
->dwarf2_per_objfile
;
7781 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7782 struct dwarf2_per_cu_data
*per_cu
;
7783 struct type_unit_group
*tu_group
;
7785 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7786 struct type_unit_group
);
7787 per_cu
= &tu_group
->per_cu
;
7788 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7790 if (dwarf2_per_objfile
->using_index
)
7792 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7793 struct dwarf2_per_cu_quick_data
);
7797 unsigned int line_offset
= to_underlying (line_offset_struct
);
7798 struct partial_symtab
*pst
;
7801 /* Give the symtab a useful name for debug purposes. */
7802 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7803 name
= xstrprintf ("<type_units_%d>",
7804 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7806 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
7808 pst
= create_partial_symtab (per_cu
, name
);
7814 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7815 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7820 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7821 STMT_LIST is a DW_AT_stmt_list attribute. */
7823 static struct type_unit_group
*
7824 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7826 struct dwarf2_per_objfile
*dwarf2_per_objfile
7827 = cu
->per_cu
->dwarf2_per_objfile
;
7828 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7829 struct type_unit_group
*tu_group
;
7831 unsigned int line_offset
;
7832 struct type_unit_group type_unit_group_for_lookup
;
7834 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7836 dwarf2_per_objfile
->type_unit_groups
=
7837 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7840 /* Do we need to create a new group, or can we use an existing one? */
7844 line_offset
= DW_UNSND (stmt_list
);
7845 ++tu_stats
->nr_symtab_sharers
;
7849 /* Ugh, no stmt_list. Rare, but we have to handle it.
7850 We can do various things here like create one group per TU or
7851 spread them over multiple groups to split up the expansion work.
7852 To avoid worst case scenarios (too many groups or too large groups)
7853 we, umm, group them in bunches. */
7854 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7855 | (tu_stats
->nr_stmt_less_type_units
7856 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7857 ++tu_stats
->nr_stmt_less_type_units
;
7860 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7861 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7862 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7863 &type_unit_group_for_lookup
, INSERT
);
7866 tu_group
= (struct type_unit_group
*) *slot
;
7867 gdb_assert (tu_group
!= NULL
);
7871 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7872 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7874 ++tu_stats
->nr_symtabs
;
7880 /* Partial symbol tables. */
7882 /* Create a psymtab named NAME and assign it to PER_CU.
7884 The caller must fill in the following details:
7885 dirname, textlow, texthigh. */
7887 static struct partial_symtab
*
7888 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7890 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7891 struct partial_symtab
*pst
;
7893 pst
= start_psymtab_common (objfile
, name
, 0,
7894 objfile
->global_psymbols
,
7895 objfile
->static_psymbols
);
7897 pst
->psymtabs_addrmap_supported
= 1;
7899 /* This is the glue that links PST into GDB's symbol API. */
7900 pst
->read_symtab_private
= per_cu
;
7901 pst
->read_symtab
= dwarf2_read_symtab
;
7902 per_cu
->v
.psymtab
= pst
;
7907 /* The DATA object passed to process_psymtab_comp_unit_reader has this
7910 struct process_psymtab_comp_unit_data
7912 /* True if we are reading a DW_TAG_partial_unit. */
7914 int want_partial_unit
;
7916 /* The "pretend" language that is used if the CU doesn't declare a
7919 enum language pretend_language
;
7922 /* die_reader_func for process_psymtab_comp_unit. */
7925 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7926 const gdb_byte
*info_ptr
,
7927 struct die_info
*comp_unit_die
,
7931 struct dwarf2_cu
*cu
= reader
->cu
;
7932 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7933 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7934 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7936 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7937 struct partial_symtab
*pst
;
7938 enum pc_bounds_kind cu_bounds_kind
;
7939 const char *filename
;
7940 struct process_psymtab_comp_unit_data
*info
7941 = (struct process_psymtab_comp_unit_data
*) data
;
7943 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
7946 gdb_assert (! per_cu
->is_debug_types
);
7948 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
7950 cu
->list_in_scope
= &file_symbols
;
7952 /* Allocate a new partial symbol table structure. */
7953 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7954 if (filename
== NULL
)
7957 pst
= create_partial_symtab (per_cu
, filename
);
7959 /* This must be done before calling dwarf2_build_include_psymtabs. */
7960 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7962 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7964 dwarf2_find_base_address (comp_unit_die
, cu
);
7966 /* Possibly set the default values of LOWPC and HIGHPC from
7968 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7969 &best_highpc
, cu
, pst
);
7970 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7971 /* Store the contiguous range if it is not empty; it can be empty for
7972 CUs with no code. */
7973 addrmap_set_empty (objfile
->psymtabs_addrmap
,
7974 gdbarch_adjust_dwarf2_addr (gdbarch
,
7975 best_lowpc
+ baseaddr
),
7976 gdbarch_adjust_dwarf2_addr (gdbarch
,
7977 best_highpc
+ baseaddr
) - 1,
7980 /* Check if comp unit has_children.
7981 If so, read the rest of the partial symbols from this comp unit.
7982 If not, there's no more debug_info for this comp unit. */
7985 struct partial_die_info
*first_die
;
7986 CORE_ADDR lowpc
, highpc
;
7988 lowpc
= ((CORE_ADDR
) -1);
7989 highpc
= ((CORE_ADDR
) 0);
7991 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7993 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7994 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7996 /* If we didn't find a lowpc, set it to highpc to avoid
7997 complaints from `maint check'. */
7998 if (lowpc
== ((CORE_ADDR
) -1))
8001 /* If the compilation unit didn't have an explicit address range,
8002 then use the information extracted from its child dies. */
8003 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8006 best_highpc
= highpc
;
8009 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
8010 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
8012 end_psymtab_common (objfile
, pst
);
8014 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
8017 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8018 struct dwarf2_per_cu_data
*iter
;
8020 /* Fill in 'dependencies' here; we fill in 'users' in a
8022 pst
->number_of_dependencies
= len
;
8024 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8026 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8029 pst
->dependencies
[i
] = iter
->v
.psymtab
;
8031 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8034 /* Get the list of files included in the current compilation unit,
8035 and build a psymtab for each of them. */
8036 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8038 if (dwarf_read_debug
)
8040 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8042 fprintf_unfiltered (gdb_stdlog
,
8043 "Psymtab for %s unit @%s: %s - %s"
8044 ", %d global, %d static syms\n",
8045 per_cu
->is_debug_types
? "type" : "comp",
8046 sect_offset_str (per_cu
->sect_off
),
8047 paddress (gdbarch
, pst
->textlow
),
8048 paddress (gdbarch
, pst
->texthigh
),
8049 pst
->n_global_syms
, pst
->n_static_syms
);
8053 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8054 Process compilation unit THIS_CU for a psymtab. */
8057 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8058 int want_partial_unit
,
8059 enum language pretend_language
)
8061 /* If this compilation unit was already read in, free the
8062 cached copy in order to read it in again. This is
8063 necessary because we skipped some symbols when we first
8064 read in the compilation unit (see load_partial_dies).
8065 This problem could be avoided, but the benefit is unclear. */
8066 if (this_cu
->cu
!= NULL
)
8067 free_one_cached_comp_unit (this_cu
);
8069 if (this_cu
->is_debug_types
)
8070 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, build_type_psymtabs_reader
,
8074 process_psymtab_comp_unit_data info
;
8075 info
.want_partial_unit
= want_partial_unit
;
8076 info
.pretend_language
= pretend_language
;
8077 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
8078 process_psymtab_comp_unit_reader
, &info
);
8081 /* Age out any secondary CUs. */
8082 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8085 /* Reader function for build_type_psymtabs. */
8088 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8089 const gdb_byte
*info_ptr
,
8090 struct die_info
*type_unit_die
,
8094 struct dwarf2_per_objfile
*dwarf2_per_objfile
8095 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8096 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8097 struct dwarf2_cu
*cu
= reader
->cu
;
8098 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8099 struct signatured_type
*sig_type
;
8100 struct type_unit_group
*tu_group
;
8101 struct attribute
*attr
;
8102 struct partial_die_info
*first_die
;
8103 CORE_ADDR lowpc
, highpc
;
8104 struct partial_symtab
*pst
;
8106 gdb_assert (data
== NULL
);
8107 gdb_assert (per_cu
->is_debug_types
);
8108 sig_type
= (struct signatured_type
*) per_cu
;
8113 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8114 tu_group
= get_type_unit_group (cu
, attr
);
8116 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
8118 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8119 cu
->list_in_scope
= &file_symbols
;
8120 pst
= create_partial_symtab (per_cu
, "");
8123 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8125 lowpc
= (CORE_ADDR
) -1;
8126 highpc
= (CORE_ADDR
) 0;
8127 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8129 end_psymtab_common (objfile
, pst
);
8132 /* Struct used to sort TUs by their abbreviation table offset. */
8134 struct tu_abbrev_offset
8136 struct signatured_type
*sig_type
;
8137 sect_offset abbrev_offset
;
8140 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8143 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8144 const struct tu_abbrev_offset
&b
)
8146 return a
.abbrev_offset
< b
.abbrev_offset
;
8149 /* Efficiently read all the type units.
8150 This does the bulk of the work for build_type_psymtabs.
8152 The efficiency is because we sort TUs by the abbrev table they use and
8153 only read each abbrev table once. In one program there are 200K TUs
8154 sharing 8K abbrev tables.
8156 The main purpose of this function is to support building the
8157 dwarf2_per_objfile->type_unit_groups table.
8158 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8159 can collapse the search space by grouping them by stmt_list.
8160 The savings can be significant, in the same program from above the 200K TUs
8161 share 8K stmt_list tables.
8163 FUNC is expected to call get_type_unit_group, which will create the
8164 struct type_unit_group if necessary and add it to
8165 dwarf2_per_objfile->type_unit_groups. */
8168 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8170 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8171 abbrev_table_up abbrev_table
;
8172 sect_offset abbrev_offset
;
8175 /* It's up to the caller to not call us multiple times. */
8176 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8178 if (dwarf2_per_objfile
->n_type_units
== 0)
8181 /* TUs typically share abbrev tables, and there can be way more TUs than
8182 abbrev tables. Sort by abbrev table to reduce the number of times we
8183 read each abbrev table in.
8184 Alternatives are to punt or to maintain a cache of abbrev tables.
8185 This is simpler and efficient enough for now.
8187 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8188 symtab to use). Typically TUs with the same abbrev offset have the same
8189 stmt_list value too so in practice this should work well.
8191 The basic algorithm here is:
8193 sort TUs by abbrev table
8194 for each TU with same abbrev table:
8195 read abbrev table if first user
8196 read TU top level DIE
8197 [IWBN if DWO skeletons had DW_AT_stmt_list]
8200 if (dwarf_read_debug
)
8201 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8203 /* Sort in a separate table to maintain the order of all_type_units
8204 for .gdb_index: TU indices directly index all_type_units. */
8205 std::vector
<struct tu_abbrev_offset
> sorted_by_abbrev
8206 (dwarf2_per_objfile
->n_type_units
);
8207 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8209 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
8211 sorted_by_abbrev
[i
].sig_type
= sig_type
;
8212 sorted_by_abbrev
[i
].abbrev_offset
=
8213 read_abbrev_offset (dwarf2_per_objfile
,
8214 sig_type
->per_cu
.section
,
8215 sig_type
->per_cu
.sect_off
);
8217 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8218 sort_tu_by_abbrev_offset
);
8220 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8222 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8224 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
8226 /* Switch to the next abbrev table if necessary. */
8227 if (abbrev_table
== NULL
8228 || tu
->abbrev_offset
!= abbrev_offset
)
8230 abbrev_offset
= tu
->abbrev_offset
;
8232 abbrev_table_read_table (dwarf2_per_objfile
,
8233 &dwarf2_per_objfile
->abbrev
,
8235 ++tu_stats
->nr_uniq_abbrev_tables
;
8238 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
.get (),
8239 0, 0, build_type_psymtabs_reader
, NULL
);
8243 /* Print collected type unit statistics. */
8246 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8248 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8250 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8251 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
8252 dwarf2_per_objfile
->n_type_units
);
8253 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8254 tu_stats
->nr_uniq_abbrev_tables
);
8255 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8256 tu_stats
->nr_symtabs
);
8257 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8258 tu_stats
->nr_symtab_sharers
);
8259 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8260 tu_stats
->nr_stmt_less_type_units
);
8261 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8262 tu_stats
->nr_all_type_units_reallocs
);
8265 /* Traversal function for build_type_psymtabs. */
8268 build_type_psymtab_dependencies (void **slot
, void *info
)
8270 struct dwarf2_per_objfile
*dwarf2_per_objfile
8271 = (struct dwarf2_per_objfile
*) info
;
8272 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8273 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8274 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8275 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8276 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
8277 struct signatured_type
*iter
;
8280 gdb_assert (len
> 0);
8281 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8283 pst
->number_of_dependencies
= len
;
8285 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8287 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
8290 gdb_assert (iter
->per_cu
.is_debug_types
);
8291 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8292 iter
->type_unit_group
= tu_group
;
8295 VEC_free (sig_type_ptr
, tu_group
->tus
);
8300 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8301 Build partial symbol tables for the .debug_types comp-units. */
8304 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8306 if (! create_all_type_units (dwarf2_per_objfile
))
8309 build_type_psymtabs_1 (dwarf2_per_objfile
);
8312 /* Traversal function for process_skeletonless_type_unit.
8313 Read a TU in a DWO file and build partial symbols for it. */
8316 process_skeletonless_type_unit (void **slot
, void *info
)
8318 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8319 struct dwarf2_per_objfile
*dwarf2_per_objfile
8320 = (struct dwarf2_per_objfile
*) info
;
8321 struct signatured_type find_entry
, *entry
;
8323 /* If this TU doesn't exist in the global table, add it and read it in. */
8325 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8327 dwarf2_per_objfile
->signatured_types
8328 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8331 find_entry
.signature
= dwo_unit
->signature
;
8332 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8334 /* If we've already seen this type there's nothing to do. What's happening
8335 is we're doing our own version of comdat-folding here. */
8339 /* This does the job that create_all_type_units would have done for
8341 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8342 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8345 /* This does the job that build_type_psymtabs_1 would have done. */
8346 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
8347 build_type_psymtabs_reader
, NULL
);
8352 /* Traversal function for process_skeletonless_type_units. */
8355 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8357 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8359 if (dwo_file
->tus
!= NULL
)
8361 htab_traverse_noresize (dwo_file
->tus
,
8362 process_skeletonless_type_unit
, info
);
8368 /* Scan all TUs of DWO files, verifying we've processed them.
8369 This is needed in case a TU was emitted without its skeleton.
8370 Note: This can't be done until we know what all the DWO files are. */
8373 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8375 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8376 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8377 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8379 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
8380 process_dwo_file_for_skeletonless_type_units
,
8381 dwarf2_per_objfile
);
8385 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8388 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8390 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8392 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8397 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8399 /* Set the 'user' field only if it is not already set. */
8400 if (pst
->dependencies
[j
]->user
== NULL
)
8401 pst
->dependencies
[j
]->user
= pst
;
8406 /* Build the partial symbol table by doing a quick pass through the
8407 .debug_info and .debug_abbrev sections. */
8410 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8412 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8414 if (dwarf_read_debug
)
8416 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8417 objfile_name (objfile
));
8420 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8422 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8424 /* Any cached compilation units will be linked by the per-objfile
8425 read_in_chain. Make sure to free them when we're done. */
8426 free_cached_comp_units
freer (dwarf2_per_objfile
);
8428 build_type_psymtabs (dwarf2_per_objfile
);
8430 create_all_comp_units (dwarf2_per_objfile
);
8432 /* Create a temporary address map on a temporary obstack. We later
8433 copy this to the final obstack. */
8434 auto_obstack temp_obstack
;
8436 scoped_restore save_psymtabs_addrmap
8437 = make_scoped_restore (&objfile
->psymtabs_addrmap
,
8438 addrmap_create_mutable (&temp_obstack
));
8440 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8441 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8443 /* This has to wait until we read the CUs, we need the list of DWOs. */
8444 process_skeletonless_type_units (dwarf2_per_objfile
);
8446 /* Now that all TUs have been processed we can fill in the dependencies. */
8447 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8449 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8450 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8453 if (dwarf_read_debug
)
8454 print_tu_stats (dwarf2_per_objfile
);
8456 set_partial_user (dwarf2_per_objfile
);
8458 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
8459 &objfile
->objfile_obstack
);
8460 /* At this point we want to keep the address map. */
8461 save_psymtabs_addrmap
.release ();
8463 if (dwarf_read_debug
)
8464 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8465 objfile_name (objfile
));
8468 /* die_reader_func for load_partial_comp_unit. */
8471 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8472 const gdb_byte
*info_ptr
,
8473 struct die_info
*comp_unit_die
,
8477 struct dwarf2_cu
*cu
= reader
->cu
;
8479 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8481 /* Check if comp unit has_children.
8482 If so, read the rest of the partial symbols from this comp unit.
8483 If not, there's no more debug_info for this comp unit. */
8485 load_partial_dies (reader
, info_ptr
, 0);
8488 /* Load the partial DIEs for a secondary CU into memory.
8489 This is also used when rereading a primary CU with load_all_dies. */
8492 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8494 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
8495 load_partial_comp_unit_reader
, NULL
);
8499 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8500 struct dwarf2_section_info
*section
,
8501 struct dwarf2_section_info
*abbrev_section
,
8502 unsigned int is_dwz
)
8504 const gdb_byte
*info_ptr
;
8505 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8507 if (dwarf_read_debug
)
8508 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8509 get_section_name (section
),
8510 get_section_file_name (section
));
8512 dwarf2_read_section (objfile
, section
);
8514 info_ptr
= section
->buffer
;
8516 while (info_ptr
< section
->buffer
+ section
->size
)
8518 struct dwarf2_per_cu_data
*this_cu
;
8520 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8522 comp_unit_head cu_header
;
8523 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8524 abbrev_section
, info_ptr
,
8525 rcuh_kind::COMPILE
);
8527 /* Save the compilation unit for later lookup. */
8528 if (cu_header
.unit_type
!= DW_UT_type
)
8530 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8531 struct dwarf2_per_cu_data
);
8532 memset (this_cu
, 0, sizeof (*this_cu
));
8536 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8537 struct signatured_type
);
8538 memset (sig_type
, 0, sizeof (*sig_type
));
8539 sig_type
->signature
= cu_header
.signature
;
8540 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8541 this_cu
= &sig_type
->per_cu
;
8543 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8544 this_cu
->sect_off
= sect_off
;
8545 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8546 this_cu
->is_dwz
= is_dwz
;
8547 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8548 this_cu
->section
= section
;
8550 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8552 info_ptr
= info_ptr
+ this_cu
->length
;
8556 /* Create a list of all compilation units in OBJFILE.
8557 This is only done for -readnow and building partial symtabs. */
8560 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8562 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8563 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8564 &dwarf2_per_objfile
->abbrev
, 0);
8566 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8568 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8572 /* Process all loaded DIEs for compilation unit CU, starting at
8573 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8574 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8575 DW_AT_ranges). See the comments of add_partial_subprogram on how
8576 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8579 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8580 CORE_ADDR
*highpc
, int set_addrmap
,
8581 struct dwarf2_cu
*cu
)
8583 struct partial_die_info
*pdi
;
8585 /* Now, march along the PDI's, descending into ones which have
8586 interesting children but skipping the children of the other ones,
8587 until we reach the end of the compilation unit. */
8595 /* Anonymous namespaces or modules have no name but have interesting
8596 children, so we need to look at them. Ditto for anonymous
8599 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8600 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8601 || pdi
->tag
== DW_TAG_imported_unit
8602 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8606 case DW_TAG_subprogram
:
8607 case DW_TAG_inlined_subroutine
:
8608 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8610 case DW_TAG_constant
:
8611 case DW_TAG_variable
:
8612 case DW_TAG_typedef
:
8613 case DW_TAG_union_type
:
8614 if (!pdi
->is_declaration
)
8616 add_partial_symbol (pdi
, cu
);
8619 case DW_TAG_class_type
:
8620 case DW_TAG_interface_type
:
8621 case DW_TAG_structure_type
:
8622 if (!pdi
->is_declaration
)
8624 add_partial_symbol (pdi
, cu
);
8626 if ((cu
->language
== language_rust
8627 || cu
->language
== language_cplus
) && pdi
->has_children
)
8628 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8631 case DW_TAG_enumeration_type
:
8632 if (!pdi
->is_declaration
)
8633 add_partial_enumeration (pdi
, cu
);
8635 case DW_TAG_base_type
:
8636 case DW_TAG_subrange_type
:
8637 /* File scope base type definitions are added to the partial
8639 add_partial_symbol (pdi
, cu
);
8641 case DW_TAG_namespace
:
8642 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8645 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8647 case DW_TAG_imported_unit
:
8649 struct dwarf2_per_cu_data
*per_cu
;
8651 /* For now we don't handle imported units in type units. */
8652 if (cu
->per_cu
->is_debug_types
)
8654 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8655 " supported in type units [in module %s]"),
8656 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8659 per_cu
= dwarf2_find_containing_comp_unit
8660 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8661 cu
->per_cu
->dwarf2_per_objfile
);
8663 /* Go read the partial unit, if needed. */
8664 if (per_cu
->v
.psymtab
== NULL
)
8665 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8667 VEC_safe_push (dwarf2_per_cu_ptr
,
8668 cu
->per_cu
->imported_symtabs
, per_cu
);
8671 case DW_TAG_imported_declaration
:
8672 add_partial_symbol (pdi
, cu
);
8679 /* If the die has a sibling, skip to the sibling. */
8681 pdi
= pdi
->die_sibling
;
8685 /* Functions used to compute the fully scoped name of a partial DIE.
8687 Normally, this is simple. For C++, the parent DIE's fully scoped
8688 name is concatenated with "::" and the partial DIE's name.
8689 Enumerators are an exception; they use the scope of their parent
8690 enumeration type, i.e. the name of the enumeration type is not
8691 prepended to the enumerator.
8693 There are two complexities. One is DW_AT_specification; in this
8694 case "parent" means the parent of the target of the specification,
8695 instead of the direct parent of the DIE. The other is compilers
8696 which do not emit DW_TAG_namespace; in this case we try to guess
8697 the fully qualified name of structure types from their members'
8698 linkage names. This must be done using the DIE's children rather
8699 than the children of any DW_AT_specification target. We only need
8700 to do this for structures at the top level, i.e. if the target of
8701 any DW_AT_specification (if any; otherwise the DIE itself) does not
8704 /* Compute the scope prefix associated with PDI's parent, in
8705 compilation unit CU. The result will be allocated on CU's
8706 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8707 field. NULL is returned if no prefix is necessary. */
8709 partial_die_parent_scope (struct partial_die_info
*pdi
,
8710 struct dwarf2_cu
*cu
)
8712 const char *grandparent_scope
;
8713 struct partial_die_info
*parent
, *real_pdi
;
8715 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8716 then this means the parent of the specification DIE. */
8719 while (real_pdi
->has_specification
)
8720 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
8721 real_pdi
->spec_is_dwz
, cu
);
8723 parent
= real_pdi
->die_parent
;
8727 if (parent
->scope_set
)
8728 return parent
->scope
;
8732 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8734 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8735 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8736 Work around this problem here. */
8737 if (cu
->language
== language_cplus
8738 && parent
->tag
== DW_TAG_namespace
8739 && strcmp (parent
->name
, "::") == 0
8740 && grandparent_scope
== NULL
)
8742 parent
->scope
= NULL
;
8743 parent
->scope_set
= 1;
8747 if (pdi
->tag
== DW_TAG_enumerator
)
8748 /* Enumerators should not get the name of the enumeration as a prefix. */
8749 parent
->scope
= grandparent_scope
;
8750 else if (parent
->tag
== DW_TAG_namespace
8751 || parent
->tag
== DW_TAG_module
8752 || parent
->tag
== DW_TAG_structure_type
8753 || parent
->tag
== DW_TAG_class_type
8754 || parent
->tag
== DW_TAG_interface_type
8755 || parent
->tag
== DW_TAG_union_type
8756 || parent
->tag
== DW_TAG_enumeration_type
)
8758 if (grandparent_scope
== NULL
)
8759 parent
->scope
= parent
->name
;
8761 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8763 parent
->name
, 0, cu
);
8767 /* FIXME drow/2004-04-01: What should we be doing with
8768 function-local names? For partial symbols, we should probably be
8770 complaint (&symfile_complaints
,
8771 _("unhandled containing DIE tag %d for DIE at %s"),
8772 parent
->tag
, sect_offset_str (pdi
->sect_off
));
8773 parent
->scope
= grandparent_scope
;
8776 parent
->scope_set
= 1;
8777 return parent
->scope
;
8780 /* Return the fully scoped name associated with PDI, from compilation unit
8781 CU. The result will be allocated with malloc. */
8784 partial_die_full_name (struct partial_die_info
*pdi
,
8785 struct dwarf2_cu
*cu
)
8787 const char *parent_scope
;
8789 /* If this is a template instantiation, we can not work out the
8790 template arguments from partial DIEs. So, unfortunately, we have
8791 to go through the full DIEs. At least any work we do building
8792 types here will be reused if full symbols are loaded later. */
8793 if (pdi
->has_template_arguments
)
8797 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8799 struct die_info
*die
;
8800 struct attribute attr
;
8801 struct dwarf2_cu
*ref_cu
= cu
;
8803 /* DW_FORM_ref_addr is using section offset. */
8804 attr
.name
= (enum dwarf_attribute
) 0;
8805 attr
.form
= DW_FORM_ref_addr
;
8806 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8807 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8809 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8813 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8814 if (parent_scope
== NULL
)
8817 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
8821 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8823 struct dwarf2_per_objfile
*dwarf2_per_objfile
8824 = cu
->per_cu
->dwarf2_per_objfile
;
8825 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8826 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8828 const char *actual_name
= NULL
;
8830 char *built_actual_name
;
8832 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8834 built_actual_name
= partial_die_full_name (pdi
, cu
);
8835 if (built_actual_name
!= NULL
)
8836 actual_name
= built_actual_name
;
8838 if (actual_name
== NULL
)
8839 actual_name
= pdi
->name
;
8843 case DW_TAG_inlined_subroutine
:
8844 case DW_TAG_subprogram
:
8845 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
8846 if (pdi
->is_external
|| cu
->language
== language_ada
)
8848 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
8849 of the global scope. But in Ada, we want to be able to access
8850 nested procedures globally. So all Ada subprograms are stored
8851 in the global scope. */
8852 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8853 built_actual_name
!= NULL
,
8854 VAR_DOMAIN
, LOC_BLOCK
,
8855 &objfile
->global_psymbols
,
8856 addr
, cu
->language
, objfile
);
8860 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8861 built_actual_name
!= NULL
,
8862 VAR_DOMAIN
, LOC_BLOCK
,
8863 &objfile
->static_psymbols
,
8864 addr
, cu
->language
, objfile
);
8867 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8868 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8870 case DW_TAG_constant
:
8872 std::vector
<partial_symbol
*> *list
;
8874 if (pdi
->is_external
)
8875 list
= &objfile
->global_psymbols
;
8877 list
= &objfile
->static_psymbols
;
8878 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8879 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8880 list
, 0, cu
->language
, objfile
);
8883 case DW_TAG_variable
:
8885 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8889 && !dwarf2_per_objfile
->has_section_at_zero
)
8891 /* A global or static variable may also have been stripped
8892 out by the linker if unused, in which case its address
8893 will be nullified; do not add such variables into partial
8894 symbol table then. */
8896 else if (pdi
->is_external
)
8899 Don't enter into the minimal symbol tables as there is
8900 a minimal symbol table entry from the ELF symbols already.
8901 Enter into partial symbol table if it has a location
8902 descriptor or a type.
8903 If the location descriptor is missing, new_symbol will create
8904 a LOC_UNRESOLVED symbol, the address of the variable will then
8905 be determined from the minimal symbol table whenever the variable
8907 The address for the partial symbol table entry is not
8908 used by GDB, but it comes in handy for debugging partial symbol
8911 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8912 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8913 built_actual_name
!= NULL
,
8914 VAR_DOMAIN
, LOC_STATIC
,
8915 &objfile
->global_psymbols
,
8917 cu
->language
, objfile
);
8921 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8923 /* Static Variable. Skip symbols whose value we cannot know (those
8924 without location descriptors or constant values). */
8925 if (!has_loc
&& !pdi
->has_const_value
)
8927 xfree (built_actual_name
);
8931 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8932 built_actual_name
!= NULL
,
8933 VAR_DOMAIN
, LOC_STATIC
,
8934 &objfile
->static_psymbols
,
8935 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
8936 cu
->language
, objfile
);
8939 case DW_TAG_typedef
:
8940 case DW_TAG_base_type
:
8941 case DW_TAG_subrange_type
:
8942 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8943 built_actual_name
!= NULL
,
8944 VAR_DOMAIN
, LOC_TYPEDEF
,
8945 &objfile
->static_psymbols
,
8946 0, cu
->language
, objfile
);
8948 case DW_TAG_imported_declaration
:
8949 case DW_TAG_namespace
:
8950 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8951 built_actual_name
!= NULL
,
8952 VAR_DOMAIN
, LOC_TYPEDEF
,
8953 &objfile
->global_psymbols
,
8954 0, cu
->language
, objfile
);
8957 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8958 built_actual_name
!= NULL
,
8959 MODULE_DOMAIN
, LOC_TYPEDEF
,
8960 &objfile
->global_psymbols
,
8961 0, cu
->language
, objfile
);
8963 case DW_TAG_class_type
:
8964 case DW_TAG_interface_type
:
8965 case DW_TAG_structure_type
:
8966 case DW_TAG_union_type
:
8967 case DW_TAG_enumeration_type
:
8968 /* Skip external references. The DWARF standard says in the section
8969 about "Structure, Union, and Class Type Entries": "An incomplete
8970 structure, union or class type is represented by a structure,
8971 union or class entry that does not have a byte size attribute
8972 and that has a DW_AT_declaration attribute." */
8973 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8975 xfree (built_actual_name
);
8979 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8980 static vs. global. */
8981 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8982 built_actual_name
!= NULL
,
8983 STRUCT_DOMAIN
, LOC_TYPEDEF
,
8984 cu
->language
== language_cplus
8985 ? &objfile
->global_psymbols
8986 : &objfile
->static_psymbols
,
8987 0, cu
->language
, objfile
);
8990 case DW_TAG_enumerator
:
8991 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8992 built_actual_name
!= NULL
,
8993 VAR_DOMAIN
, LOC_CONST
,
8994 cu
->language
== language_cplus
8995 ? &objfile
->global_psymbols
8996 : &objfile
->static_psymbols
,
8997 0, cu
->language
, objfile
);
9003 xfree (built_actual_name
);
9006 /* Read a partial die corresponding to a namespace; also, add a symbol
9007 corresponding to that namespace to the symbol table. NAMESPACE is
9008 the name of the enclosing namespace. */
9011 add_partial_namespace (struct partial_die_info
*pdi
,
9012 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9013 int set_addrmap
, struct dwarf2_cu
*cu
)
9015 /* Add a symbol for the namespace. */
9017 add_partial_symbol (pdi
, cu
);
9019 /* Now scan partial symbols in that namespace. */
9021 if (pdi
->has_children
)
9022 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9025 /* Read a partial die corresponding to a Fortran module. */
9028 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9029 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9031 /* Add a symbol for the namespace. */
9033 add_partial_symbol (pdi
, cu
);
9035 /* Now scan partial symbols in that module. */
9037 if (pdi
->has_children
)
9038 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9041 /* Read a partial die corresponding to a subprogram or an inlined
9042 subprogram and create a partial symbol for that subprogram.
9043 When the CU language allows it, this routine also defines a partial
9044 symbol for each nested subprogram that this subprogram contains.
9045 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9046 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9048 PDI may also be a lexical block, in which case we simply search
9049 recursively for subprograms defined inside that lexical block.
9050 Again, this is only performed when the CU language allows this
9051 type of definitions. */
9054 add_partial_subprogram (struct partial_die_info
*pdi
,
9055 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9056 int set_addrmap
, struct dwarf2_cu
*cu
)
9058 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9060 if (pdi
->has_pc_info
)
9062 if (pdi
->lowpc
< *lowpc
)
9063 *lowpc
= pdi
->lowpc
;
9064 if (pdi
->highpc
> *highpc
)
9065 *highpc
= pdi
->highpc
;
9068 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9069 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9074 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9075 SECT_OFF_TEXT (objfile
));
9076 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9077 pdi
->lowpc
+ baseaddr
);
9078 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9079 pdi
->highpc
+ baseaddr
);
9080 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
9081 cu
->per_cu
->v
.psymtab
);
9085 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9087 if (!pdi
->is_declaration
)
9088 /* Ignore subprogram DIEs that do not have a name, they are
9089 illegal. Do not emit a complaint at this point, we will
9090 do so when we convert this psymtab into a symtab. */
9092 add_partial_symbol (pdi
, cu
);
9096 if (! pdi
->has_children
)
9099 if (cu
->language
== language_ada
)
9101 pdi
= pdi
->die_child
;
9105 if (pdi
->tag
== DW_TAG_subprogram
9106 || pdi
->tag
== DW_TAG_inlined_subroutine
9107 || pdi
->tag
== DW_TAG_lexical_block
)
9108 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9109 pdi
= pdi
->die_sibling
;
9114 /* Read a partial die corresponding to an enumeration type. */
9117 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9118 struct dwarf2_cu
*cu
)
9120 struct partial_die_info
*pdi
;
9122 if (enum_pdi
->name
!= NULL
)
9123 add_partial_symbol (enum_pdi
, cu
);
9125 pdi
= enum_pdi
->die_child
;
9128 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9129 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
9131 add_partial_symbol (pdi
, cu
);
9132 pdi
= pdi
->die_sibling
;
9136 /* Return the initial uleb128 in the die at INFO_PTR. */
9139 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9141 unsigned int bytes_read
;
9143 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9146 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9147 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9149 Return the corresponding abbrev, or NULL if the number is zero (indicating
9150 an empty DIE). In either case *BYTES_READ will be set to the length of
9151 the initial number. */
9153 static struct abbrev_info
*
9154 peek_die_abbrev (const die_reader_specs
&reader
,
9155 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9157 dwarf2_cu
*cu
= reader
.cu
;
9158 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9159 unsigned int abbrev_number
9160 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9162 if (abbrev_number
== 0)
9165 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9168 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9169 " at offset %s [in module %s]"),
9170 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9171 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9177 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9178 Returns a pointer to the end of a series of DIEs, terminated by an empty
9179 DIE. Any children of the skipped DIEs will also be skipped. */
9181 static const gdb_byte
*
9182 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9186 unsigned int bytes_read
;
9187 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9190 return info_ptr
+ bytes_read
;
9192 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9196 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9197 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9198 abbrev corresponding to that skipped uleb128 should be passed in
9199 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9202 static const gdb_byte
*
9203 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9204 struct abbrev_info
*abbrev
)
9206 unsigned int bytes_read
;
9207 struct attribute attr
;
9208 bfd
*abfd
= reader
->abfd
;
9209 struct dwarf2_cu
*cu
= reader
->cu
;
9210 const gdb_byte
*buffer
= reader
->buffer
;
9211 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9212 unsigned int form
, i
;
9214 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9216 /* The only abbrev we care about is DW_AT_sibling. */
9217 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9219 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9220 if (attr
.form
== DW_FORM_ref_addr
)
9221 complaint (&symfile_complaints
,
9222 _("ignoring absolute DW_AT_sibling"));
9225 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9226 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9228 if (sibling_ptr
< info_ptr
)
9229 complaint (&symfile_complaints
,
9230 _("DW_AT_sibling points backwards"));
9231 else if (sibling_ptr
> reader
->buffer_end
)
9232 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9238 /* If it isn't DW_AT_sibling, skip this attribute. */
9239 form
= abbrev
->attrs
[i
].form
;
9243 case DW_FORM_ref_addr
:
9244 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9245 and later it is offset sized. */
9246 if (cu
->header
.version
== 2)
9247 info_ptr
+= cu
->header
.addr_size
;
9249 info_ptr
+= cu
->header
.offset_size
;
9251 case DW_FORM_GNU_ref_alt
:
9252 info_ptr
+= cu
->header
.offset_size
;
9255 info_ptr
+= cu
->header
.addr_size
;
9262 case DW_FORM_flag_present
:
9263 case DW_FORM_implicit_const
:
9275 case DW_FORM_ref_sig8
:
9278 case DW_FORM_data16
:
9281 case DW_FORM_string
:
9282 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9283 info_ptr
+= bytes_read
;
9285 case DW_FORM_sec_offset
:
9287 case DW_FORM_GNU_strp_alt
:
9288 info_ptr
+= cu
->header
.offset_size
;
9290 case DW_FORM_exprloc
:
9292 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9293 info_ptr
+= bytes_read
;
9295 case DW_FORM_block1
:
9296 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9298 case DW_FORM_block2
:
9299 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9301 case DW_FORM_block4
:
9302 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9306 case DW_FORM_ref_udata
:
9307 case DW_FORM_GNU_addr_index
:
9308 case DW_FORM_GNU_str_index
:
9309 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9311 case DW_FORM_indirect
:
9312 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9313 info_ptr
+= bytes_read
;
9314 /* We need to continue parsing from here, so just go back to
9316 goto skip_attribute
;
9319 error (_("Dwarf Error: Cannot handle %s "
9320 "in DWARF reader [in module %s]"),
9321 dwarf_form_name (form
),
9322 bfd_get_filename (abfd
));
9326 if (abbrev
->has_children
)
9327 return skip_children (reader
, info_ptr
);
9332 /* Locate ORIG_PDI's sibling.
9333 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9335 static const gdb_byte
*
9336 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9337 struct partial_die_info
*orig_pdi
,
9338 const gdb_byte
*info_ptr
)
9340 /* Do we know the sibling already? */
9342 if (orig_pdi
->sibling
)
9343 return orig_pdi
->sibling
;
9345 /* Are there any children to deal with? */
9347 if (!orig_pdi
->has_children
)
9350 /* Skip the children the long way. */
9352 return skip_children (reader
, info_ptr
);
9355 /* Expand this partial symbol table into a full symbol table. SELF is
9359 dwarf2_read_symtab (struct partial_symtab
*self
,
9360 struct objfile
*objfile
)
9362 struct dwarf2_per_objfile
*dwarf2_per_objfile
9363 = get_dwarf2_per_objfile (objfile
);
9367 warning (_("bug: psymtab for %s is already read in."),
9374 printf_filtered (_("Reading in symbols for %s..."),
9376 gdb_flush (gdb_stdout
);
9379 /* If this psymtab is constructed from a debug-only objfile, the
9380 has_section_at_zero flag will not necessarily be correct. We
9381 can get the correct value for this flag by looking at the data
9382 associated with the (presumably stripped) associated objfile. */
9383 if (objfile
->separate_debug_objfile_backlink
)
9385 struct dwarf2_per_objfile
*dpo_backlink
9386 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9388 dwarf2_per_objfile
->has_section_at_zero
9389 = dpo_backlink
->has_section_at_zero
;
9392 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9394 psymtab_to_symtab_1 (self
);
9396 /* Finish up the debug error message. */
9398 printf_filtered (_("done.\n"));
9401 process_cu_includes (dwarf2_per_objfile
);
9404 /* Reading in full CUs. */
9406 /* Add PER_CU to the queue. */
9409 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9410 enum language pretend_language
)
9412 struct dwarf2_queue_item
*item
;
9415 item
= XNEW (struct dwarf2_queue_item
);
9416 item
->per_cu
= per_cu
;
9417 item
->pretend_language
= pretend_language
;
9420 if (dwarf2_queue
== NULL
)
9421 dwarf2_queue
= item
;
9423 dwarf2_queue_tail
->next
= item
;
9425 dwarf2_queue_tail
= item
;
9428 /* If PER_CU is not yet queued, add it to the queue.
9429 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9431 The result is non-zero if PER_CU was queued, otherwise the result is zero
9432 meaning either PER_CU is already queued or it is already loaded.
9434 N.B. There is an invariant here that if a CU is queued then it is loaded.
9435 The caller is required to load PER_CU if we return non-zero. */
9438 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9439 struct dwarf2_per_cu_data
*per_cu
,
9440 enum language pretend_language
)
9442 /* We may arrive here during partial symbol reading, if we need full
9443 DIEs to process an unusual case (e.g. template arguments). Do
9444 not queue PER_CU, just tell our caller to load its DIEs. */
9445 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9447 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9452 /* Mark the dependence relation so that we don't flush PER_CU
9454 if (dependent_cu
!= NULL
)
9455 dwarf2_add_dependence (dependent_cu
, per_cu
);
9457 /* If it's already on the queue, we have nothing to do. */
9461 /* If the compilation unit is already loaded, just mark it as
9463 if (per_cu
->cu
!= NULL
)
9465 per_cu
->cu
->last_used
= 0;
9469 /* Add it to the queue. */
9470 queue_comp_unit (per_cu
, pretend_language
);
9475 /* Process the queue. */
9478 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9480 struct dwarf2_queue_item
*item
, *next_item
;
9482 if (dwarf_read_debug
)
9484 fprintf_unfiltered (gdb_stdlog
,
9485 "Expanding one or more symtabs of objfile %s ...\n",
9486 objfile_name (dwarf2_per_objfile
->objfile
));
9489 /* The queue starts out with one item, but following a DIE reference
9490 may load a new CU, adding it to the end of the queue. */
9491 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9493 if ((dwarf2_per_objfile
->using_index
9494 ? !item
->per_cu
->v
.quick
->compunit_symtab
9495 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9496 /* Skip dummy CUs. */
9497 && item
->per_cu
->cu
!= NULL
)
9499 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9500 unsigned int debug_print_threshold
;
9503 if (per_cu
->is_debug_types
)
9505 struct signatured_type
*sig_type
=
9506 (struct signatured_type
*) per_cu
;
9508 sprintf (buf
, "TU %s at offset %s",
9509 hex_string (sig_type
->signature
),
9510 sect_offset_str (per_cu
->sect_off
));
9511 /* There can be 100s of TUs.
9512 Only print them in verbose mode. */
9513 debug_print_threshold
= 2;
9517 sprintf (buf
, "CU at offset %s",
9518 sect_offset_str (per_cu
->sect_off
));
9519 debug_print_threshold
= 1;
9522 if (dwarf_read_debug
>= debug_print_threshold
)
9523 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9525 if (per_cu
->is_debug_types
)
9526 process_full_type_unit (per_cu
, item
->pretend_language
);
9528 process_full_comp_unit (per_cu
, item
->pretend_language
);
9530 if (dwarf_read_debug
>= debug_print_threshold
)
9531 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9534 item
->per_cu
->queued
= 0;
9535 next_item
= item
->next
;
9539 dwarf2_queue_tail
= NULL
;
9541 if (dwarf_read_debug
)
9543 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9544 objfile_name (dwarf2_per_objfile
->objfile
));
9548 /* Read in full symbols for PST, and anything it depends on. */
9551 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9553 struct dwarf2_per_cu_data
*per_cu
;
9559 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9560 if (!pst
->dependencies
[i
]->readin
9561 && pst
->dependencies
[i
]->user
== NULL
)
9563 /* Inform about additional files that need to be read in. */
9566 /* FIXME: i18n: Need to make this a single string. */
9567 fputs_filtered (" ", gdb_stdout
);
9569 fputs_filtered ("and ", gdb_stdout
);
9571 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9572 wrap_here (""); /* Flush output. */
9573 gdb_flush (gdb_stdout
);
9575 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9578 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9582 /* It's an include file, no symbols to read for it.
9583 Everything is in the parent symtab. */
9588 dw2_do_instantiate_symtab (per_cu
);
9591 /* Trivial hash function for die_info: the hash value of a DIE
9592 is its offset in .debug_info for this objfile. */
9595 die_hash (const void *item
)
9597 const struct die_info
*die
= (const struct die_info
*) item
;
9599 return to_underlying (die
->sect_off
);
9602 /* Trivial comparison function for die_info structures: two DIEs
9603 are equal if they have the same offset. */
9606 die_eq (const void *item_lhs
, const void *item_rhs
)
9608 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9609 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9611 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9614 /* die_reader_func for load_full_comp_unit.
9615 This is identical to read_signatured_type_reader,
9616 but is kept separate for now. */
9619 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9620 const gdb_byte
*info_ptr
,
9621 struct die_info
*comp_unit_die
,
9625 struct dwarf2_cu
*cu
= reader
->cu
;
9626 enum language
*language_ptr
= (enum language
*) data
;
9628 gdb_assert (cu
->die_hash
== NULL
);
9630 htab_create_alloc_ex (cu
->header
.length
/ 12,
9634 &cu
->comp_unit_obstack
,
9635 hashtab_obstack_allocate
,
9636 dummy_obstack_deallocate
);
9639 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9640 &info_ptr
, comp_unit_die
);
9641 cu
->dies
= comp_unit_die
;
9642 /* comp_unit_die is not stored in die_hash, no need. */
9644 /* We try not to read any attributes in this function, because not
9645 all CUs needed for references have been loaded yet, and symbol
9646 table processing isn't initialized. But we have to set the CU language,
9647 or we won't be able to build types correctly.
9648 Similarly, if we do not read the producer, we can not apply
9649 producer-specific interpretation. */
9650 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9653 /* Load the DIEs associated with PER_CU into memory. */
9656 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9657 enum language pretend_language
)
9659 gdb_assert (! this_cu
->is_debug_types
);
9661 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
9662 load_full_comp_unit_reader
, &pretend_language
);
9665 /* Add a DIE to the delayed physname list. */
9668 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9669 const char *name
, struct die_info
*die
,
9670 struct dwarf2_cu
*cu
)
9672 struct delayed_method_info mi
;
9674 mi
.fnfield_index
= fnfield_index
;
9678 cu
->method_list
.push_back (mi
);
9681 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9682 "const" / "volatile". If so, decrements LEN by the length of the
9683 modifier and return true. Otherwise return false. */
9687 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9689 size_t mod_len
= sizeof (mod
) - 1;
9690 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9698 /* Compute the physnames of any methods on the CU's method list.
9700 The computation of method physnames is delayed in order to avoid the
9701 (bad) condition that one of the method's formal parameters is of an as yet
9705 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9707 /* Only C++ delays computing physnames. */
9708 if (cu
->method_list
.empty ())
9710 gdb_assert (cu
->language
== language_cplus
);
9712 for (struct delayed_method_info
&mi
: cu
->method_list
)
9714 const char *physname
;
9715 struct fn_fieldlist
*fn_flp
9716 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9717 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9718 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9719 = physname
? physname
: "";
9721 /* Since there's no tag to indicate whether a method is a
9722 const/volatile overload, extract that information out of the
9724 if (physname
!= NULL
)
9726 size_t len
= strlen (physname
);
9730 if (physname
[len
] == ')') /* shortcut */
9732 else if (check_modifier (physname
, len
, " const"))
9733 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9734 else if (check_modifier (physname
, len
, " volatile"))
9735 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9742 /* The list is no longer needed. */
9743 cu
->method_list
.clear ();
9746 /* Go objects should be embedded in a DW_TAG_module DIE,
9747 and it's not clear if/how imported objects will appear.
9748 To keep Go support simple until that's worked out,
9749 go back through what we've read and create something usable.
9750 We could do this while processing each DIE, and feels kinda cleaner,
9751 but that way is more invasive.
9752 This is to, for example, allow the user to type "p var" or "b main"
9753 without having to specify the package name, and allow lookups
9754 of module.object to work in contexts that use the expression
9758 fixup_go_packaging (struct dwarf2_cu
*cu
)
9760 char *package_name
= NULL
;
9761 struct pending
*list
;
9764 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
9766 for (i
= 0; i
< list
->nsyms
; ++i
)
9768 struct symbol
*sym
= list
->symbol
[i
];
9770 if (SYMBOL_LANGUAGE (sym
) == language_go
9771 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9773 char *this_package_name
= go_symbol_package_name (sym
);
9775 if (this_package_name
== NULL
)
9777 if (package_name
== NULL
)
9778 package_name
= this_package_name
;
9781 struct objfile
*objfile
9782 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9783 if (strcmp (package_name
, this_package_name
) != 0)
9784 complaint (&symfile_complaints
,
9785 _("Symtab %s has objects from two different Go packages: %s and %s"),
9786 (symbol_symtab (sym
) != NULL
9787 ? symtab_to_filename_for_display
9788 (symbol_symtab (sym
))
9789 : objfile_name (objfile
)),
9790 this_package_name
, package_name
);
9791 xfree (this_package_name
);
9797 if (package_name
!= NULL
)
9799 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9800 const char *saved_package_name
9801 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
9803 strlen (package_name
));
9804 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9805 saved_package_name
);
9808 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9810 sym
= allocate_symbol (objfile
);
9811 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
9812 SYMBOL_SET_NAMES (sym
, saved_package_name
,
9813 strlen (saved_package_name
), 0, objfile
);
9814 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9815 e.g., "main" finds the "main" module and not C's main(). */
9816 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9817 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9818 SYMBOL_TYPE (sym
) = type
;
9820 add_symbol_to_list (sym
, &global_symbols
);
9822 xfree (package_name
);
9826 /* Allocate a fully-qualified name consisting of the two parts on the
9830 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9832 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9835 /* A helper that allocates a struct discriminant_info to attach to a
9838 static struct discriminant_info
*
9839 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9842 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9843 gdb_assert (discriminant_index
== -1
9844 || (discriminant_index
>= 0
9845 && discriminant_index
< TYPE_NFIELDS (type
)));
9846 gdb_assert (default_index
== -1
9847 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9849 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9851 struct discriminant_info
*disc
9852 = ((struct discriminant_info
*)
9854 offsetof (struct discriminant_info
, discriminants
)
9855 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9856 disc
->default_index
= default_index
;
9857 disc
->discriminant_index
= discriminant_index
;
9859 struct dynamic_prop prop
;
9860 prop
.kind
= PROP_UNDEFINED
;
9861 prop
.data
.baton
= disc
;
9863 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9868 /* Some versions of rustc emitted enums in an unusual way.
9870 Ordinary enums were emitted as unions. The first element of each
9871 structure in the union was named "RUST$ENUM$DISR". This element
9872 held the discriminant.
9874 These versions of Rust also implemented the "non-zero"
9875 optimization. When the enum had two values, and one is empty and
9876 the other holds a pointer that cannot be zero, the pointer is used
9877 as the discriminant, with a zero value meaning the empty variant.
9878 Here, the union's first member is of the form
9879 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9880 where the fieldnos are the indices of the fields that should be
9881 traversed in order to find the field (which may be several fields deep)
9882 and the variantname is the name of the variant of the case when the
9885 This function recognizes whether TYPE is of one of these forms,
9886 and, if so, smashes it to be a variant type. */
9889 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9891 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9893 /* We don't need to deal with empty enums. */
9894 if (TYPE_NFIELDS (type
) == 0)
9897 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9898 if (TYPE_NFIELDS (type
) == 1
9899 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9901 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9903 /* Decode the field name to find the offset of the
9905 ULONGEST bit_offset
= 0;
9906 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9907 while (name
[0] >= '0' && name
[0] <= '9')
9910 unsigned long index
= strtoul (name
, &tail
, 10);
9913 || index
>= TYPE_NFIELDS (field_type
)
9914 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9915 != FIELD_LOC_KIND_BITPOS
))
9917 complaint (&symfile_complaints
,
9918 _("Could not parse Rust enum encoding string \"%s\""
9920 TYPE_FIELD_NAME (type
, 0),
9921 objfile_name (objfile
));
9926 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9927 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9930 /* Make a union to hold the variants. */
9931 struct type
*union_type
= alloc_type (objfile
);
9932 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9933 TYPE_NFIELDS (union_type
) = 3;
9934 TYPE_FIELDS (union_type
)
9935 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9936 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9938 /* Put the discriminant must at index 0. */
9939 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9940 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9941 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9942 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9944 /* The order of fields doesn't really matter, so put the real
9945 field at index 1 and the data-less field at index 2. */
9946 struct discriminant_info
*disc
9947 = alloc_discriminant_info (union_type
, 0, 1);
9948 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9949 TYPE_FIELD_NAME (union_type
, 1)
9950 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9951 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9952 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9953 TYPE_FIELD_NAME (union_type
, 1));
9955 const char *dataless_name
9956 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9958 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9960 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9961 /* NAME points into the original discriminant name, which
9962 already has the correct lifetime. */
9963 TYPE_FIELD_NAME (union_type
, 2) = name
;
9964 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9965 disc
->discriminants
[2] = 0;
9967 /* Smash this type to be a structure type. We have to do this
9968 because the type has already been recorded. */
9969 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9970 TYPE_NFIELDS (type
) = 1;
9972 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9974 /* Install the variant part. */
9975 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9976 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9977 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9979 else if (TYPE_NFIELDS (type
) == 1)
9981 /* We assume that a union with a single field is a univariant
9983 /* Smash this type to be a structure type. We have to do this
9984 because the type has already been recorded. */
9985 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9987 /* Make a union to hold the variants. */
9988 struct type
*union_type
= alloc_type (objfile
);
9989 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9990 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9991 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9992 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9994 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9995 const char *variant_name
9996 = rust_last_path_segment (TYPE_NAME (field_type
));
9997 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9998 TYPE_NAME (field_type
)
9999 = rust_fully_qualify (&objfile
->objfile_obstack
,
10000 TYPE_NAME (type
), variant_name
);
10002 /* Install the union in the outer struct type. */
10003 TYPE_NFIELDS (type
) = 1;
10005 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10006 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10007 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10008 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10010 alloc_discriminant_info (union_type
, -1, 0);
10014 struct type
*disr_type
= nullptr;
10015 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10017 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10019 if (TYPE_NFIELDS (disr_type
) == 0)
10021 /* Could be data-less variant, so keep going. */
10023 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10024 "RUST$ENUM$DISR") != 0)
10026 /* Not a Rust enum. */
10036 /* If we got here without a discriminant, then it's probably
10038 if (disr_type
== nullptr)
10041 /* Smash this type to be a structure type. We have to do this
10042 because the type has already been recorded. */
10043 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10045 /* Make a union to hold the variants. */
10046 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10047 struct type
*union_type
= alloc_type (objfile
);
10048 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10049 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10050 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10051 TYPE_FIELDS (union_type
)
10052 = (struct field
*) TYPE_ZALLOC (union_type
,
10053 (TYPE_NFIELDS (union_type
)
10054 * sizeof (struct field
)));
10056 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10057 TYPE_NFIELDS (type
) * sizeof (struct field
));
10059 /* Install the discriminant at index 0 in the union. */
10060 TYPE_FIELD (union_type
, 0) = *disr_field
;
10061 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10062 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10064 /* Install the union in the outer struct type. */
10065 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10066 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10067 TYPE_NFIELDS (type
) = 1;
10069 /* Set the size and offset of the union type. */
10070 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10072 /* We need a way to find the correct discriminant given a
10073 variant name. For convenience we build a map here. */
10074 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10075 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10076 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10078 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10081 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10082 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10086 int n_fields
= TYPE_NFIELDS (union_type
);
10087 struct discriminant_info
*disc
10088 = alloc_discriminant_info (union_type
, 0, -1);
10089 /* Skip the discriminant here. */
10090 for (int i
= 1; i
< n_fields
; ++i
)
10092 /* Find the final word in the name of this variant's type.
10093 That name can be used to look up the correct
10095 const char *variant_name
10096 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10099 auto iter
= discriminant_map
.find (variant_name
);
10100 if (iter
!= discriminant_map
.end ())
10101 disc
->discriminants
[i
] = iter
->second
;
10103 /* Remove the discriminant field. */
10104 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10105 --TYPE_NFIELDS (sub_type
);
10106 ++TYPE_FIELDS (sub_type
);
10107 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10108 TYPE_NAME (sub_type
)
10109 = rust_fully_qualify (&objfile
->objfile_obstack
,
10110 TYPE_NAME (type
), variant_name
);
10115 /* Rewrite some Rust unions to be structures with variants parts. */
10118 rust_union_quirks (struct dwarf2_cu
*cu
)
10120 gdb_assert (cu
->language
== language_rust
);
10121 for (struct type
*type
: cu
->rust_unions
)
10122 quirk_rust_enum (type
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10125 /* Return the symtab for PER_CU. This works properly regardless of
10126 whether we're using the index or psymtabs. */
10128 static struct compunit_symtab
*
10129 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10131 return (per_cu
->dwarf2_per_objfile
->using_index
10132 ? per_cu
->v
.quick
->compunit_symtab
10133 : per_cu
->v
.psymtab
->compunit_symtab
);
10136 /* A helper function for computing the list of all symbol tables
10137 included by PER_CU. */
10140 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
10141 htab_t all_children
, htab_t all_type_symtabs
,
10142 struct dwarf2_per_cu_data
*per_cu
,
10143 struct compunit_symtab
*immediate_parent
)
10147 struct compunit_symtab
*cust
;
10148 struct dwarf2_per_cu_data
*iter
;
10150 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10153 /* This inclusion and its children have been processed. */
10158 /* Only add a CU if it has a symbol table. */
10159 cust
= get_compunit_symtab (per_cu
);
10162 /* If this is a type unit only add its symbol table if we haven't
10163 seen it yet (type unit per_cu's can share symtabs). */
10164 if (per_cu
->is_debug_types
)
10166 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10170 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10171 if (cust
->user
== NULL
)
10172 cust
->user
= immediate_parent
;
10177 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10178 if (cust
->user
== NULL
)
10179 cust
->user
= immediate_parent
;
10184 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
10187 recursively_compute_inclusions (result
, all_children
,
10188 all_type_symtabs
, iter
, cust
);
10192 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10196 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10198 gdb_assert (! per_cu
->is_debug_types
);
10200 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
10203 struct dwarf2_per_cu_data
*per_cu_iter
;
10204 struct compunit_symtab
*compunit_symtab_iter
;
10205 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
10206 htab_t all_children
, all_type_symtabs
;
10207 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10209 /* If we don't have a symtab, we can just skip this case. */
10213 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10214 NULL
, xcalloc
, xfree
);
10215 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10216 NULL
, xcalloc
, xfree
);
10219 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
10223 recursively_compute_inclusions (&result_symtabs
, all_children
,
10224 all_type_symtabs
, per_cu_iter
,
10228 /* Now we have a transitive closure of all the included symtabs. */
10229 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
10231 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10232 struct compunit_symtab
*, len
+ 1);
10234 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
10235 compunit_symtab_iter
);
10237 cust
->includes
[ix
] = compunit_symtab_iter
;
10238 cust
->includes
[len
] = NULL
;
10240 VEC_free (compunit_symtab_ptr
, result_symtabs
);
10241 htab_delete (all_children
);
10242 htab_delete (all_type_symtabs
);
10246 /* Compute the 'includes' field for the symtabs of all the CUs we just
10250 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10253 struct dwarf2_per_cu_data
*iter
;
10256 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
10260 if (! iter
->is_debug_types
)
10261 compute_compunit_symtab_includes (iter
);
10264 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
10267 /* Generate full symbol information for PER_CU, whose DIEs have
10268 already been loaded into memory. */
10271 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10272 enum language pretend_language
)
10274 struct dwarf2_cu
*cu
= per_cu
->cu
;
10275 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10276 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10277 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10278 CORE_ADDR lowpc
, highpc
;
10279 struct compunit_symtab
*cust
;
10280 CORE_ADDR baseaddr
;
10281 struct block
*static_block
;
10284 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10287 scoped_free_pendings free_pending
;
10289 /* Clear the list here in case something was left over. */
10290 cu
->method_list
.clear ();
10292 cu
->list_in_scope
= &file_symbols
;
10294 cu
->language
= pretend_language
;
10295 cu
->language_defn
= language_def (cu
->language
);
10297 /* Do line number decoding in read_file_scope () */
10298 process_die (cu
->dies
, cu
);
10300 /* For now fudge the Go package. */
10301 if (cu
->language
== language_go
)
10302 fixup_go_packaging (cu
);
10304 /* Now that we have processed all the DIEs in the CU, all the types
10305 should be complete, and it should now be safe to compute all of the
10307 compute_delayed_physnames (cu
);
10309 if (cu
->language
== language_rust
)
10310 rust_union_quirks (cu
);
10312 /* Some compilers don't define a DW_AT_high_pc attribute for the
10313 compilation unit. If the DW_AT_high_pc is missing, synthesize
10314 it, by scanning the DIE's below the compilation unit. */
10315 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10317 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10318 static_block
= end_symtab_get_static_block (addr
, 0, 1);
10320 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10321 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10322 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10323 addrmap to help ensure it has an accurate map of pc values belonging to
10325 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10327 cust
= end_symtab_from_static_block (static_block
,
10328 SECT_OFF_TEXT (objfile
), 0);
10332 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10334 /* Set symtab language to language from DW_AT_language. If the
10335 compilation is from a C file generated by language preprocessors, do
10336 not set the language if it was already deduced by start_subfile. */
10337 if (!(cu
->language
== language_c
10338 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10339 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10341 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10342 produce DW_AT_location with location lists but it can be possibly
10343 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10344 there were bugs in prologue debug info, fixed later in GCC-4.5
10345 by "unwind info for epilogues" patch (which is not directly related).
10347 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10348 needed, it would be wrong due to missing DW_AT_producer there.
10350 Still one can confuse GDB by using non-standard GCC compilation
10351 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10353 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10354 cust
->locations_valid
= 1;
10356 if (gcc_4_minor
>= 5)
10357 cust
->epilogue_unwind_valid
= 1;
10359 cust
->call_site_htab
= cu
->call_site_htab
;
10362 if (dwarf2_per_objfile
->using_index
)
10363 per_cu
->v
.quick
->compunit_symtab
= cust
;
10366 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10367 pst
->compunit_symtab
= cust
;
10371 /* Push it for inclusion processing later. */
10372 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
10375 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10376 already been loaded into memory. */
10379 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10380 enum language pretend_language
)
10382 struct dwarf2_cu
*cu
= per_cu
->cu
;
10383 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10384 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10385 struct compunit_symtab
*cust
;
10386 struct signatured_type
*sig_type
;
10388 gdb_assert (per_cu
->is_debug_types
);
10389 sig_type
= (struct signatured_type
*) per_cu
;
10392 scoped_free_pendings free_pending
;
10394 /* Clear the list here in case something was left over. */
10395 cu
->method_list
.clear ();
10397 cu
->list_in_scope
= &file_symbols
;
10399 cu
->language
= pretend_language
;
10400 cu
->language_defn
= language_def (cu
->language
);
10402 /* The symbol tables are set up in read_type_unit_scope. */
10403 process_die (cu
->dies
, cu
);
10405 /* For now fudge the Go package. */
10406 if (cu
->language
== language_go
)
10407 fixup_go_packaging (cu
);
10409 /* Now that we have processed all the DIEs in the CU, all the types
10410 should be complete, and it should now be safe to compute all of the
10412 compute_delayed_physnames (cu
);
10414 if (cu
->language
== language_rust
)
10415 rust_union_quirks (cu
);
10417 /* TUs share symbol tables.
10418 If this is the first TU to use this symtab, complete the construction
10419 of it with end_expandable_symtab. Otherwise, complete the addition of
10420 this TU's symbols to the existing symtab. */
10421 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10423 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10424 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10428 /* Set symtab language to language from DW_AT_language. If the
10429 compilation is from a C file generated by language preprocessors,
10430 do not set the language if it was already deduced by
10432 if (!(cu
->language
== language_c
10433 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10434 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10439 augment_type_symtab ();
10440 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10443 if (dwarf2_per_objfile
->using_index
)
10444 per_cu
->v
.quick
->compunit_symtab
= cust
;
10447 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10448 pst
->compunit_symtab
= cust
;
10453 /* Process an imported unit DIE. */
10456 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10458 struct attribute
*attr
;
10460 /* For now we don't handle imported units in type units. */
10461 if (cu
->per_cu
->is_debug_types
)
10463 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10464 " supported in type units [in module %s]"),
10465 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10468 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10471 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10472 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10473 dwarf2_per_cu_data
*per_cu
10474 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10475 cu
->per_cu
->dwarf2_per_objfile
);
10477 /* If necessary, add it to the queue and load its DIEs. */
10478 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10479 load_full_comp_unit (per_cu
, cu
->language
);
10481 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
10486 /* RAII object that represents a process_die scope: i.e.,
10487 starts/finishes processing a DIE. */
10488 class process_die_scope
10491 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10492 : m_die (die
), m_cu (cu
)
10494 /* We should only be processing DIEs not already in process. */
10495 gdb_assert (!m_die
->in_process
);
10496 m_die
->in_process
= true;
10499 ~process_die_scope ()
10501 m_die
->in_process
= false;
10503 /* If we're done processing the DIE for the CU that owns the line
10504 header, we don't need the line header anymore. */
10505 if (m_cu
->line_header_die_owner
== m_die
)
10507 delete m_cu
->line_header
;
10508 m_cu
->line_header
= NULL
;
10509 m_cu
->line_header_die_owner
= NULL
;
10518 /* Process a die and its children. */
10521 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10523 process_die_scope
scope (die
, cu
);
10527 case DW_TAG_padding
:
10529 case DW_TAG_compile_unit
:
10530 case DW_TAG_partial_unit
:
10531 read_file_scope (die
, cu
);
10533 case DW_TAG_type_unit
:
10534 read_type_unit_scope (die
, cu
);
10536 case DW_TAG_subprogram
:
10537 case DW_TAG_inlined_subroutine
:
10538 read_func_scope (die
, cu
);
10540 case DW_TAG_lexical_block
:
10541 case DW_TAG_try_block
:
10542 case DW_TAG_catch_block
:
10543 read_lexical_block_scope (die
, cu
);
10545 case DW_TAG_call_site
:
10546 case DW_TAG_GNU_call_site
:
10547 read_call_site_scope (die
, cu
);
10549 case DW_TAG_class_type
:
10550 case DW_TAG_interface_type
:
10551 case DW_TAG_structure_type
:
10552 case DW_TAG_union_type
:
10553 process_structure_scope (die
, cu
);
10555 case DW_TAG_enumeration_type
:
10556 process_enumeration_scope (die
, cu
);
10559 /* These dies have a type, but processing them does not create
10560 a symbol or recurse to process the children. Therefore we can
10561 read them on-demand through read_type_die. */
10562 case DW_TAG_subroutine_type
:
10563 case DW_TAG_set_type
:
10564 case DW_TAG_array_type
:
10565 case DW_TAG_pointer_type
:
10566 case DW_TAG_ptr_to_member_type
:
10567 case DW_TAG_reference_type
:
10568 case DW_TAG_rvalue_reference_type
:
10569 case DW_TAG_string_type
:
10572 case DW_TAG_base_type
:
10573 case DW_TAG_subrange_type
:
10574 case DW_TAG_typedef
:
10575 /* Add a typedef symbol for the type definition, if it has a
10577 new_symbol (die
, read_type_die (die
, cu
), cu
);
10579 case DW_TAG_common_block
:
10580 read_common_block (die
, cu
);
10582 case DW_TAG_common_inclusion
:
10584 case DW_TAG_namespace
:
10585 cu
->processing_has_namespace_info
= 1;
10586 read_namespace (die
, cu
);
10588 case DW_TAG_module
:
10589 cu
->processing_has_namespace_info
= 1;
10590 read_module (die
, cu
);
10592 case DW_TAG_imported_declaration
:
10593 cu
->processing_has_namespace_info
= 1;
10594 if (read_namespace_alias (die
, cu
))
10596 /* The declaration is not a global namespace alias: fall through. */
10597 case DW_TAG_imported_module
:
10598 cu
->processing_has_namespace_info
= 1;
10599 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10600 || cu
->language
!= language_fortran
))
10601 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
10602 dwarf_tag_name (die
->tag
));
10603 read_import_statement (die
, cu
);
10606 case DW_TAG_imported_unit
:
10607 process_imported_unit_die (die
, cu
);
10610 case DW_TAG_variable
:
10611 read_variable (die
, cu
);
10615 new_symbol (die
, NULL
, cu
);
10620 /* DWARF name computation. */
10622 /* A helper function for dwarf2_compute_name which determines whether DIE
10623 needs to have the name of the scope prepended to the name listed in the
10627 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10629 struct attribute
*attr
;
10633 case DW_TAG_namespace
:
10634 case DW_TAG_typedef
:
10635 case DW_TAG_class_type
:
10636 case DW_TAG_interface_type
:
10637 case DW_TAG_structure_type
:
10638 case DW_TAG_union_type
:
10639 case DW_TAG_enumeration_type
:
10640 case DW_TAG_enumerator
:
10641 case DW_TAG_subprogram
:
10642 case DW_TAG_inlined_subroutine
:
10643 case DW_TAG_member
:
10644 case DW_TAG_imported_declaration
:
10647 case DW_TAG_variable
:
10648 case DW_TAG_constant
:
10649 /* We only need to prefix "globally" visible variables. These include
10650 any variable marked with DW_AT_external or any variable that
10651 lives in a namespace. [Variables in anonymous namespaces
10652 require prefixing, but they are not DW_AT_external.] */
10654 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10656 struct dwarf2_cu
*spec_cu
= cu
;
10658 return die_needs_namespace (die_specification (die
, &spec_cu
),
10662 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10663 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10664 && die
->parent
->tag
!= DW_TAG_module
)
10666 /* A variable in a lexical block of some kind does not need a
10667 namespace, even though in C++ such variables may be external
10668 and have a mangled name. */
10669 if (die
->parent
->tag
== DW_TAG_lexical_block
10670 || die
->parent
->tag
== DW_TAG_try_block
10671 || die
->parent
->tag
== DW_TAG_catch_block
10672 || die
->parent
->tag
== DW_TAG_subprogram
)
10681 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10682 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10683 defined for the given DIE. */
10685 static struct attribute
*
10686 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10688 struct attribute
*attr
;
10690 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10692 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10697 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10698 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10699 defined for the given DIE. */
10701 static const char *
10702 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10704 const char *linkage_name
;
10706 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10707 if (linkage_name
== NULL
)
10708 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10710 return linkage_name
;
10713 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10714 compute the physname for the object, which include a method's:
10715 - formal parameters (C++),
10716 - receiver type (Go),
10718 The term "physname" is a bit confusing.
10719 For C++, for example, it is the demangled name.
10720 For Go, for example, it's the mangled name.
10722 For Ada, return the DIE's linkage name rather than the fully qualified
10723 name. PHYSNAME is ignored..
10725 The result is allocated on the objfile_obstack and canonicalized. */
10727 static const char *
10728 dwarf2_compute_name (const char *name
,
10729 struct die_info
*die
, struct dwarf2_cu
*cu
,
10732 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10735 name
= dwarf2_name (die
, cu
);
10737 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10738 but otherwise compute it by typename_concat inside GDB.
10739 FIXME: Actually this is not really true, or at least not always true.
10740 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
10741 Fortran names because there is no mangling standard. So new_symbol
10742 will set the demangled name to the result of dwarf2_full_name, and it is
10743 the demangled name that GDB uses if it exists. */
10744 if (cu
->language
== language_ada
10745 || (cu
->language
== language_fortran
&& physname
))
10747 /* For Ada unit, we prefer the linkage name over the name, as
10748 the former contains the exported name, which the user expects
10749 to be able to reference. Ideally, we want the user to be able
10750 to reference this entity using either natural or linkage name,
10751 but we haven't started looking at this enhancement yet. */
10752 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10754 if (linkage_name
!= NULL
)
10755 return linkage_name
;
10758 /* These are the only languages we know how to qualify names in. */
10760 && (cu
->language
== language_cplus
10761 || cu
->language
== language_fortran
|| cu
->language
== language_d
10762 || cu
->language
== language_rust
))
10764 if (die_needs_namespace (die
, cu
))
10766 const char *prefix
;
10767 const char *canonical_name
= NULL
;
10771 prefix
= determine_prefix (die
, cu
);
10772 if (*prefix
!= '\0')
10774 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
10777 buf
.puts (prefixed_name
);
10778 xfree (prefixed_name
);
10783 /* Template parameters may be specified in the DIE's DW_AT_name, or
10784 as children with DW_TAG_template_type_param or
10785 DW_TAG_value_type_param. If the latter, add them to the name
10786 here. If the name already has template parameters, then
10787 skip this step; some versions of GCC emit both, and
10788 it is more efficient to use the pre-computed name.
10790 Something to keep in mind about this process: it is very
10791 unlikely, or in some cases downright impossible, to produce
10792 something that will match the mangled name of a function.
10793 If the definition of the function has the same debug info,
10794 we should be able to match up with it anyway. But fallbacks
10795 using the minimal symbol, for instance to find a method
10796 implemented in a stripped copy of libstdc++, will not work.
10797 If we do not have debug info for the definition, we will have to
10798 match them up some other way.
10800 When we do name matching there is a related problem with function
10801 templates; two instantiated function templates are allowed to
10802 differ only by their return types, which we do not add here. */
10804 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10806 struct attribute
*attr
;
10807 struct die_info
*child
;
10810 die
->building_fullname
= 1;
10812 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10816 const gdb_byte
*bytes
;
10817 struct dwarf2_locexpr_baton
*baton
;
10820 if (child
->tag
!= DW_TAG_template_type_param
10821 && child
->tag
!= DW_TAG_template_value_param
)
10832 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10835 complaint (&symfile_complaints
,
10836 _("template parameter missing DW_AT_type"));
10837 buf
.puts ("UNKNOWN_TYPE");
10840 type
= die_type (child
, cu
);
10842 if (child
->tag
== DW_TAG_template_type_param
)
10844 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
10848 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10851 complaint (&symfile_complaints
,
10852 _("template parameter missing "
10853 "DW_AT_const_value"));
10854 buf
.puts ("UNKNOWN_VALUE");
10858 dwarf2_const_value_attr (attr
, type
, name
,
10859 &cu
->comp_unit_obstack
, cu
,
10860 &value
, &bytes
, &baton
);
10862 if (TYPE_NOSIGN (type
))
10863 /* GDB prints characters as NUMBER 'CHAR'. If that's
10864 changed, this can use value_print instead. */
10865 c_printchar (value
, type
, &buf
);
10868 struct value_print_options opts
;
10871 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10875 else if (bytes
!= NULL
)
10877 v
= allocate_value (type
);
10878 memcpy (value_contents_writeable (v
), bytes
,
10879 TYPE_LENGTH (type
));
10882 v
= value_from_longest (type
, value
);
10884 /* Specify decimal so that we do not depend on
10886 get_formatted_print_options (&opts
, 'd');
10888 value_print (v
, &buf
, &opts
);
10893 die
->building_fullname
= 0;
10897 /* Close the argument list, with a space if necessary
10898 (nested templates). */
10899 if (!buf
.empty () && buf
.string ().back () == '>')
10906 /* For C++ methods, append formal parameter type
10907 information, if PHYSNAME. */
10909 if (physname
&& die
->tag
== DW_TAG_subprogram
10910 && cu
->language
== language_cplus
)
10912 struct type
*type
= read_type_die (die
, cu
);
10914 c_type_print_args (type
, &buf
, 1, cu
->language
,
10915 &type_print_raw_options
);
10917 if (cu
->language
== language_cplus
)
10919 /* Assume that an artificial first parameter is
10920 "this", but do not crash if it is not. RealView
10921 marks unnamed (and thus unused) parameters as
10922 artificial; there is no way to differentiate
10924 if (TYPE_NFIELDS (type
) > 0
10925 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10926 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10927 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10929 buf
.puts (" const");
10933 const std::string
&intermediate_name
= buf
.string ();
10935 if (cu
->language
== language_cplus
)
10937 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10938 &objfile
->per_bfd
->storage_obstack
);
10940 /* If we only computed INTERMEDIATE_NAME, or if
10941 INTERMEDIATE_NAME is already canonical, then we need to
10942 copy it to the appropriate obstack. */
10943 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10944 name
= ((const char *)
10945 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
10946 intermediate_name
.c_str (),
10947 intermediate_name
.length ()));
10949 name
= canonical_name
;
10956 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10957 If scope qualifiers are appropriate they will be added. The result
10958 will be allocated on the storage_obstack, or NULL if the DIE does
10959 not have a name. NAME may either be from a previous call to
10960 dwarf2_name or NULL.
10962 The output string will be canonicalized (if C++). */
10964 static const char *
10965 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10967 return dwarf2_compute_name (name
, die
, cu
, 0);
10970 /* Construct a physname for the given DIE in CU. NAME may either be
10971 from a previous call to dwarf2_name or NULL. The result will be
10972 allocated on the objfile_objstack or NULL if the DIE does not have a
10975 The output string will be canonicalized (if C++). */
10977 static const char *
10978 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10980 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10981 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10984 /* In this case dwarf2_compute_name is just a shortcut not building anything
10986 if (!die_needs_namespace (die
, cu
))
10987 return dwarf2_compute_name (name
, die
, cu
, 1);
10989 mangled
= dw2_linkage_name (die
, cu
);
10991 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10992 See https://github.com/rust-lang/rust/issues/32925. */
10993 if (cu
->language
== language_rust
&& mangled
!= NULL
10994 && strchr (mangled
, '{') != NULL
)
10997 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10999 gdb::unique_xmalloc_ptr
<char> demangled
;
11000 if (mangled
!= NULL
)
11003 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11005 /* Do nothing (do not demangle the symbol name). */
11007 else if (cu
->language
== language_go
)
11009 /* This is a lie, but we already lie to the caller new_symbol.
11010 new_symbol assumes we return the mangled name.
11011 This just undoes that lie until things are cleaned up. */
11015 /* Use DMGL_RET_DROP for C++ template functions to suppress
11016 their return type. It is easier for GDB users to search
11017 for such functions as `name(params)' than `long name(params)'.
11018 In such case the minimal symbol names do not match the full
11019 symbol names but for template functions there is never a need
11020 to look up their definition from their declaration so
11021 the only disadvantage remains the minimal symbol variant
11022 `long name(params)' does not have the proper inferior type. */
11023 demangled
.reset (gdb_demangle (mangled
,
11024 (DMGL_PARAMS
| DMGL_ANSI
11025 | DMGL_RET_DROP
)));
11028 canon
= demangled
.get ();
11036 if (canon
== NULL
|| check_physname
)
11038 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11040 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11042 /* It may not mean a bug in GDB. The compiler could also
11043 compute DW_AT_linkage_name incorrectly. But in such case
11044 GDB would need to be bug-to-bug compatible. */
11046 complaint (&symfile_complaints
,
11047 _("Computed physname <%s> does not match demangled <%s> "
11048 "(from linkage <%s>) - DIE at %s [in module %s]"),
11049 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11050 objfile_name (objfile
));
11052 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11053 is available here - over computed PHYSNAME. It is safer
11054 against both buggy GDB and buggy compilers. */
11068 retval
= ((const char *)
11069 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11070 retval
, strlen (retval
)));
11075 /* Inspect DIE in CU for a namespace alias. If one exists, record
11076 a new symbol for it.
11078 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11081 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11083 struct attribute
*attr
;
11085 /* If the die does not have a name, this is not a namespace
11087 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11091 struct die_info
*d
= die
;
11092 struct dwarf2_cu
*imported_cu
= cu
;
11094 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11095 keep inspecting DIEs until we hit the underlying import. */
11096 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11097 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11099 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11103 d
= follow_die_ref (d
, attr
, &imported_cu
);
11104 if (d
->tag
!= DW_TAG_imported_declaration
)
11108 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11110 complaint (&symfile_complaints
,
11111 _("DIE at %s has too many recursively imported "
11112 "declarations"), sect_offset_str (d
->sect_off
));
11119 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11121 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11122 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11124 /* This declaration is a global namespace alias. Add
11125 a symbol for it whose type is the aliased namespace. */
11126 new_symbol (die
, type
, cu
);
11135 /* Return the using directives repository (global or local?) to use in the
11136 current context for LANGUAGE.
11138 For Ada, imported declarations can materialize renamings, which *may* be
11139 global. However it is impossible (for now?) in DWARF to distinguish
11140 "external" imported declarations and "static" ones. As all imported
11141 declarations seem to be static in all other languages, make them all CU-wide
11142 global only in Ada. */
11144 static struct using_direct
**
11145 using_directives (enum language language
)
11147 if (language
== language_ada
&& context_stack_depth
== 0)
11148 return &global_using_directives
;
11150 return &local_using_directives
;
11153 /* Read the import statement specified by the given die and record it. */
11156 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11158 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11159 struct attribute
*import_attr
;
11160 struct die_info
*imported_die
, *child_die
;
11161 struct dwarf2_cu
*imported_cu
;
11162 const char *imported_name
;
11163 const char *imported_name_prefix
;
11164 const char *canonical_name
;
11165 const char *import_alias
;
11166 const char *imported_declaration
= NULL
;
11167 const char *import_prefix
;
11168 std::vector
<const char *> excludes
;
11170 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11171 if (import_attr
== NULL
)
11173 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11174 dwarf_tag_name (die
->tag
));
11179 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11180 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11181 if (imported_name
== NULL
)
11183 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11185 The import in the following code:
11199 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11200 <52> DW_AT_decl_file : 1
11201 <53> DW_AT_decl_line : 6
11202 <54> DW_AT_import : <0x75>
11203 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11204 <59> DW_AT_name : B
11205 <5b> DW_AT_decl_file : 1
11206 <5c> DW_AT_decl_line : 2
11207 <5d> DW_AT_type : <0x6e>
11209 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11210 <76> DW_AT_byte_size : 4
11211 <77> DW_AT_encoding : 5 (signed)
11213 imports the wrong die ( 0x75 instead of 0x58 ).
11214 This case will be ignored until the gcc bug is fixed. */
11218 /* Figure out the local name after import. */
11219 import_alias
= dwarf2_name (die
, cu
);
11221 /* Figure out where the statement is being imported to. */
11222 import_prefix
= determine_prefix (die
, cu
);
11224 /* Figure out what the scope of the imported die is and prepend it
11225 to the name of the imported die. */
11226 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11228 if (imported_die
->tag
!= DW_TAG_namespace
11229 && imported_die
->tag
!= DW_TAG_module
)
11231 imported_declaration
= imported_name
;
11232 canonical_name
= imported_name_prefix
;
11234 else if (strlen (imported_name_prefix
) > 0)
11235 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11236 imported_name_prefix
,
11237 (cu
->language
== language_d
? "." : "::"),
11238 imported_name
, (char *) NULL
);
11240 canonical_name
= imported_name
;
11242 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11243 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11244 child_die
= sibling_die (child_die
))
11246 /* DWARF-4: A Fortran use statement with a “rename list” may be
11247 represented by an imported module entry with an import attribute
11248 referring to the module and owned entries corresponding to those
11249 entities that are renamed as part of being imported. */
11251 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11253 complaint (&symfile_complaints
,
11254 _("child DW_TAG_imported_declaration expected "
11255 "- DIE at %s [in module %s]"),
11256 sect_offset_str (child_die
->sect_off
),
11257 objfile_name (objfile
));
11261 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11262 if (import_attr
== NULL
)
11264 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11265 dwarf_tag_name (child_die
->tag
));
11270 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11272 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11273 if (imported_name
== NULL
)
11275 complaint (&symfile_complaints
,
11276 _("child DW_TAG_imported_declaration has unknown "
11277 "imported name - DIE at %s [in module %s]"),
11278 sect_offset_str (child_die
->sect_off
),
11279 objfile_name (objfile
));
11283 excludes
.push_back (imported_name
);
11285 process_die (child_die
, cu
);
11288 add_using_directive (using_directives (cu
->language
),
11292 imported_declaration
,
11295 &objfile
->objfile_obstack
);
11298 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11299 types, but gives them a size of zero. Starting with version 14,
11300 ICC is compatible with GCC. */
11303 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11305 if (!cu
->checked_producer
)
11306 check_producer (cu
);
11308 return cu
->producer_is_icc_lt_14
;
11311 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11312 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11313 this, it was first present in GCC release 4.3.0. */
11316 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11318 if (!cu
->checked_producer
)
11319 check_producer (cu
);
11321 return cu
->producer_is_gcc_lt_4_3
;
11324 static file_and_directory
11325 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11327 file_and_directory res
;
11329 /* Find the filename. Do not use dwarf2_name here, since the filename
11330 is not a source language identifier. */
11331 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11332 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11334 if (res
.comp_dir
== NULL
11335 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11336 && IS_ABSOLUTE_PATH (res
.name
))
11338 res
.comp_dir_storage
= ldirname (res
.name
);
11339 if (!res
.comp_dir_storage
.empty ())
11340 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11342 if (res
.comp_dir
!= NULL
)
11344 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11345 directory, get rid of it. */
11346 const char *cp
= strchr (res
.comp_dir
, ':');
11348 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11349 res
.comp_dir
= cp
+ 1;
11352 if (res
.name
== NULL
)
11353 res
.name
= "<unknown>";
11358 /* Handle DW_AT_stmt_list for a compilation unit.
11359 DIE is the DW_TAG_compile_unit die for CU.
11360 COMP_DIR is the compilation directory. LOWPC is passed to
11361 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11364 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11365 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11367 struct dwarf2_per_objfile
*dwarf2_per_objfile
11368 = cu
->per_cu
->dwarf2_per_objfile
;
11369 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11370 struct attribute
*attr
;
11371 struct line_header line_header_local
;
11372 hashval_t line_header_local_hash
;
11374 int decode_mapping
;
11376 gdb_assert (! cu
->per_cu
->is_debug_types
);
11378 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11382 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11384 /* The line header hash table is only created if needed (it exists to
11385 prevent redundant reading of the line table for partial_units).
11386 If we're given a partial_unit, we'll need it. If we're given a
11387 compile_unit, then use the line header hash table if it's already
11388 created, but don't create one just yet. */
11390 if (dwarf2_per_objfile
->line_header_hash
== NULL
11391 && die
->tag
== DW_TAG_partial_unit
)
11393 dwarf2_per_objfile
->line_header_hash
11394 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11395 line_header_eq_voidp
,
11396 free_line_header_voidp
,
11397 &objfile
->objfile_obstack
,
11398 hashtab_obstack_allocate
,
11399 dummy_obstack_deallocate
);
11402 line_header_local
.sect_off
= line_offset
;
11403 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11404 line_header_local_hash
= line_header_hash (&line_header_local
);
11405 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11407 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11408 &line_header_local
,
11409 line_header_local_hash
, NO_INSERT
);
11411 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11412 is not present in *SLOT (since if there is something in *SLOT then
11413 it will be for a partial_unit). */
11414 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11416 gdb_assert (*slot
!= NULL
);
11417 cu
->line_header
= (struct line_header
*) *slot
;
11422 /* dwarf_decode_line_header does not yet provide sufficient information.
11423 We always have to call also dwarf_decode_lines for it. */
11424 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11428 cu
->line_header
= lh
.release ();
11429 cu
->line_header_die_owner
= die
;
11431 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11435 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11436 &line_header_local
,
11437 line_header_local_hash
, INSERT
);
11438 gdb_assert (slot
!= NULL
);
11440 if (slot
!= NULL
&& *slot
== NULL
)
11442 /* This newly decoded line number information unit will be owned
11443 by line_header_hash hash table. */
11444 *slot
= cu
->line_header
;
11445 cu
->line_header_die_owner
= NULL
;
11449 /* We cannot free any current entry in (*slot) as that struct line_header
11450 may be already used by multiple CUs. Create only temporary decoded
11451 line_header for this CU - it may happen at most once for each line
11452 number information unit. And if we're not using line_header_hash
11453 then this is what we want as well. */
11454 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11456 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11457 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11462 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11465 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11467 struct dwarf2_per_objfile
*dwarf2_per_objfile
11468 = cu
->per_cu
->dwarf2_per_objfile
;
11469 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11470 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11471 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11472 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11473 struct attribute
*attr
;
11474 struct die_info
*child_die
;
11475 CORE_ADDR baseaddr
;
11477 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11479 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11481 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11482 from finish_block. */
11483 if (lowpc
== ((CORE_ADDR
) -1))
11485 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11487 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11489 prepare_one_comp_unit (cu
, die
, cu
->language
);
11491 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11492 standardised yet. As a workaround for the language detection we fall
11493 back to the DW_AT_producer string. */
11494 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11495 cu
->language
= language_opencl
;
11497 /* Similar hack for Go. */
11498 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11499 set_cu_language (DW_LANG_Go
, cu
);
11501 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
11503 /* Decode line number information if present. We do this before
11504 processing child DIEs, so that the line header table is available
11505 for DW_AT_decl_file. */
11506 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11508 /* Process all dies in compilation unit. */
11509 if (die
->child
!= NULL
)
11511 child_die
= die
->child
;
11512 while (child_die
&& child_die
->tag
)
11514 process_die (child_die
, cu
);
11515 child_die
= sibling_die (child_die
);
11519 /* Decode macro information, if present. Dwarf 2 macro information
11520 refers to information in the line number info statement program
11521 header, so we can only read it if we've read the header
11523 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11525 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11526 if (attr
&& cu
->line_header
)
11528 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11529 complaint (&symfile_complaints
,
11530 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11532 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11536 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11537 if (attr
&& cu
->line_header
)
11539 unsigned int macro_offset
= DW_UNSND (attr
);
11541 dwarf_decode_macros (cu
, macro_offset
, 0);
11546 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
11547 Create the set of symtabs used by this TU, or if this TU is sharing
11548 symtabs with another TU and the symtabs have already been created
11549 then restore those symtabs in the line header.
11550 We don't need the pc/line-number mapping for type units. */
11553 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
11555 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
11556 struct type_unit_group
*tu_group
;
11558 struct attribute
*attr
;
11560 struct signatured_type
*sig_type
;
11562 gdb_assert (per_cu
->is_debug_types
);
11563 sig_type
= (struct signatured_type
*) per_cu
;
11565 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11567 /* If we're using .gdb_index (includes -readnow) then
11568 per_cu->type_unit_group may not have been set up yet. */
11569 if (sig_type
->type_unit_group
== NULL
)
11570 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
11571 tu_group
= sig_type
->type_unit_group
;
11573 /* If we've already processed this stmt_list there's no real need to
11574 do it again, we could fake it and just recreate the part we need
11575 (file name,index -> symtab mapping). If data shows this optimization
11576 is useful we can do it then. */
11577 first_time
= tu_group
->compunit_symtab
== NULL
;
11579 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11584 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11585 lh
= dwarf_decode_line_header (line_offset
, cu
);
11590 dwarf2_start_symtab (cu
, "", NULL
, 0);
11593 gdb_assert (tu_group
->symtabs
== NULL
);
11594 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11599 cu
->line_header
= lh
.release ();
11600 cu
->line_header_die_owner
= die
;
11604 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
11606 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11607 still initializing it, and our caller (a few levels up)
11608 process_full_type_unit still needs to know if this is the first
11611 tu_group
->num_symtabs
= cu
->line_header
->file_names
.size ();
11612 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11613 cu
->line_header
->file_names
.size ());
11615 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11617 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11619 dwarf2_start_subfile (fe
.name
, fe
.include_dir (cu
->line_header
));
11621 if (current_subfile
->symtab
== NULL
)
11623 /* NOTE: start_subfile will recognize when it's been
11624 passed a file it has already seen. So we can't
11625 assume there's a simple mapping from
11626 cu->line_header->file_names to subfiles, plus
11627 cu->line_header->file_names may contain dups. */
11628 current_subfile
->symtab
11629 = allocate_symtab (cust
, current_subfile
->name
);
11632 fe
.symtab
= current_subfile
->symtab
;
11633 tu_group
->symtabs
[i
] = fe
.symtab
;
11638 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11640 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11642 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11644 fe
.symtab
= tu_group
->symtabs
[i
];
11648 /* The main symtab is allocated last. Type units don't have DW_AT_name
11649 so they don't have a "real" (so to speak) symtab anyway.
11650 There is later code that will assign the main symtab to all symbols
11651 that don't have one. We need to handle the case of a symbol with a
11652 missing symtab (DW_AT_decl_file) anyway. */
11655 /* Process DW_TAG_type_unit.
11656 For TUs we want to skip the first top level sibling if it's not the
11657 actual type being defined by this TU. In this case the first top
11658 level sibling is there to provide context only. */
11661 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11663 struct die_info
*child_die
;
11665 prepare_one_comp_unit (cu
, die
, language_minimal
);
11667 /* Initialize (or reinitialize) the machinery for building symtabs.
11668 We do this before processing child DIEs, so that the line header table
11669 is available for DW_AT_decl_file. */
11670 setup_type_unit_groups (die
, cu
);
11672 if (die
->child
!= NULL
)
11674 child_die
= die
->child
;
11675 while (child_die
&& child_die
->tag
)
11677 process_die (child_die
, cu
);
11678 child_die
= sibling_die (child_die
);
11685 http://gcc.gnu.org/wiki/DebugFission
11686 http://gcc.gnu.org/wiki/DebugFissionDWP
11688 To simplify handling of both DWO files ("object" files with the DWARF info)
11689 and DWP files (a file with the DWOs packaged up into one file), we treat
11690 DWP files as having a collection of virtual DWO files. */
11693 hash_dwo_file (const void *item
)
11695 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11698 hash
= htab_hash_string (dwo_file
->dwo_name
);
11699 if (dwo_file
->comp_dir
!= NULL
)
11700 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11705 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11707 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11708 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11710 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11712 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11713 return lhs
->comp_dir
== rhs
->comp_dir
;
11714 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11717 /* Allocate a hash table for DWO files. */
11720 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11722 return htab_create_alloc_ex (41,
11726 &objfile
->objfile_obstack
,
11727 hashtab_obstack_allocate
,
11728 dummy_obstack_deallocate
);
11731 /* Lookup DWO file DWO_NAME. */
11734 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11735 const char *dwo_name
,
11736 const char *comp_dir
)
11738 struct dwo_file find_entry
;
11741 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11742 dwarf2_per_objfile
->dwo_files
11743 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11745 memset (&find_entry
, 0, sizeof (find_entry
));
11746 find_entry
.dwo_name
= dwo_name
;
11747 find_entry
.comp_dir
= comp_dir
;
11748 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
11754 hash_dwo_unit (const void *item
)
11756 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11758 /* This drops the top 32 bits of the id, but is ok for a hash. */
11759 return dwo_unit
->signature
;
11763 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11765 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11766 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11768 /* The signature is assumed to be unique within the DWO file.
11769 So while object file CU dwo_id's always have the value zero,
11770 that's OK, assuming each object file DWO file has only one CU,
11771 and that's the rule for now. */
11772 return lhs
->signature
== rhs
->signature
;
11775 /* Allocate a hash table for DWO CUs,TUs.
11776 There is one of these tables for each of CUs,TUs for each DWO file. */
11779 allocate_dwo_unit_table (struct objfile
*objfile
)
11781 /* Start out with a pretty small number.
11782 Generally DWO files contain only one CU and maybe some TUs. */
11783 return htab_create_alloc_ex (3,
11787 &objfile
->objfile_obstack
,
11788 hashtab_obstack_allocate
,
11789 dummy_obstack_deallocate
);
11792 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11794 struct create_dwo_cu_data
11796 struct dwo_file
*dwo_file
;
11797 struct dwo_unit dwo_unit
;
11800 /* die_reader_func for create_dwo_cu. */
11803 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11804 const gdb_byte
*info_ptr
,
11805 struct die_info
*comp_unit_die
,
11809 struct dwarf2_cu
*cu
= reader
->cu
;
11810 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11811 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11812 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11813 struct dwo_file
*dwo_file
= data
->dwo_file
;
11814 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11815 struct attribute
*attr
;
11817 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
11820 complaint (&symfile_complaints
,
11821 _("Dwarf Error: debug entry at offset %s is missing"
11822 " its dwo_id [in module %s]"),
11823 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11827 dwo_unit
->dwo_file
= dwo_file
;
11828 dwo_unit
->signature
= DW_UNSND (attr
);
11829 dwo_unit
->section
= section
;
11830 dwo_unit
->sect_off
= sect_off
;
11831 dwo_unit
->length
= cu
->per_cu
->length
;
11833 if (dwarf_read_debug
)
11834 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11835 sect_offset_str (sect_off
),
11836 hex_string (dwo_unit
->signature
));
11839 /* Create the dwo_units for the CUs in a DWO_FILE.
11840 Note: This function processes DWO files only, not DWP files. */
11843 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11844 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11847 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11848 const gdb_byte
*info_ptr
, *end_ptr
;
11850 dwarf2_read_section (objfile
, §ion
);
11851 info_ptr
= section
.buffer
;
11853 if (info_ptr
== NULL
)
11856 if (dwarf_read_debug
)
11858 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11859 get_section_name (§ion
),
11860 get_section_file_name (§ion
));
11863 end_ptr
= info_ptr
+ section
.size
;
11864 while (info_ptr
< end_ptr
)
11866 struct dwarf2_per_cu_data per_cu
;
11867 struct create_dwo_cu_data create_dwo_cu_data
;
11868 struct dwo_unit
*dwo_unit
;
11870 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11872 memset (&create_dwo_cu_data
.dwo_unit
, 0,
11873 sizeof (create_dwo_cu_data
.dwo_unit
));
11874 memset (&per_cu
, 0, sizeof (per_cu
));
11875 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11876 per_cu
.is_debug_types
= 0;
11877 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11878 per_cu
.section
= §ion
;
11879 create_dwo_cu_data
.dwo_file
= &dwo_file
;
11881 init_cutu_and_read_dies_no_follow (
11882 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
11883 info_ptr
+= per_cu
.length
;
11885 // If the unit could not be parsed, skip it.
11886 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
11889 if (cus_htab
== NULL
)
11890 cus_htab
= allocate_dwo_unit_table (objfile
);
11892 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11893 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
11894 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
11895 gdb_assert (slot
!= NULL
);
11898 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11899 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11901 complaint (&symfile_complaints
,
11902 _("debug cu entry at offset %s is duplicate to"
11903 " the entry at offset %s, signature %s"),
11904 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11905 hex_string (dwo_unit
->signature
));
11907 *slot
= (void *)dwo_unit
;
11911 /* DWP file .debug_{cu,tu}_index section format:
11912 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11916 Both index sections have the same format, and serve to map a 64-bit
11917 signature to a set of section numbers. Each section begins with a header,
11918 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11919 indexes, and a pool of 32-bit section numbers. The index sections will be
11920 aligned at 8-byte boundaries in the file.
11922 The index section header consists of:
11924 V, 32 bit version number
11926 N, 32 bit number of compilation units or type units in the index
11927 M, 32 bit number of slots in the hash table
11929 Numbers are recorded using the byte order of the application binary.
11931 The hash table begins at offset 16 in the section, and consists of an array
11932 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11933 order of the application binary). Unused slots in the hash table are 0.
11934 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11936 The parallel table begins immediately after the hash table
11937 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11938 array of 32-bit indexes (using the byte order of the application binary),
11939 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11940 table contains a 32-bit index into the pool of section numbers. For unused
11941 hash table slots, the corresponding entry in the parallel table will be 0.
11943 The pool of section numbers begins immediately following the hash table
11944 (at offset 16 + 12 * M from the beginning of the section). The pool of
11945 section numbers consists of an array of 32-bit words (using the byte order
11946 of the application binary). Each item in the array is indexed starting
11947 from 0. The hash table entry provides the index of the first section
11948 number in the set. Additional section numbers in the set follow, and the
11949 set is terminated by a 0 entry (section number 0 is not used in ELF).
11951 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11952 section must be the first entry in the set, and the .debug_abbrev.dwo must
11953 be the second entry. Other members of the set may follow in any order.
11959 DWP Version 2 combines all the .debug_info, etc. sections into one,
11960 and the entries in the index tables are now offsets into these sections.
11961 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11964 Index Section Contents:
11966 Hash Table of Signatures dwp_hash_table.hash_table
11967 Parallel Table of Indices dwp_hash_table.unit_table
11968 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11969 Table of Section Sizes dwp_hash_table.v2.sizes
11971 The index section header consists of:
11973 V, 32 bit version number
11974 L, 32 bit number of columns in the table of section offsets
11975 N, 32 bit number of compilation units or type units in the index
11976 M, 32 bit number of slots in the hash table
11978 Numbers are recorded using the byte order of the application binary.
11980 The hash table has the same format as version 1.
11981 The parallel table of indices has the same format as version 1,
11982 except that the entries are origin-1 indices into the table of sections
11983 offsets and the table of section sizes.
11985 The table of offsets begins immediately following the parallel table
11986 (at offset 16 + 12 * M from the beginning of the section). The table is
11987 a two-dimensional array of 32-bit words (using the byte order of the
11988 application binary), with L columns and N+1 rows, in row-major order.
11989 Each row in the array is indexed starting from 0. The first row provides
11990 a key to the remaining rows: each column in this row provides an identifier
11991 for a debug section, and the offsets in the same column of subsequent rows
11992 refer to that section. The section identifiers are:
11994 DW_SECT_INFO 1 .debug_info.dwo
11995 DW_SECT_TYPES 2 .debug_types.dwo
11996 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11997 DW_SECT_LINE 4 .debug_line.dwo
11998 DW_SECT_LOC 5 .debug_loc.dwo
11999 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12000 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12001 DW_SECT_MACRO 8 .debug_macro.dwo
12003 The offsets provided by the CU and TU index sections are the base offsets
12004 for the contributions made by each CU or TU to the corresponding section
12005 in the package file. Each CU and TU header contains an abbrev_offset
12006 field, used to find the abbreviations table for that CU or TU within the
12007 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12008 be interpreted as relative to the base offset given in the index section.
12009 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12010 should be interpreted as relative to the base offset for .debug_line.dwo,
12011 and offsets into other debug sections obtained from DWARF attributes should
12012 also be interpreted as relative to the corresponding base offset.
12014 The table of sizes begins immediately following the table of offsets.
12015 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12016 with L columns and N rows, in row-major order. Each row in the array is
12017 indexed starting from 1 (row 0 is shared by the two tables).
12021 Hash table lookup is handled the same in version 1 and 2:
12023 We assume that N and M will not exceed 2^32 - 1.
12024 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12026 Given a 64-bit compilation unit signature or a type signature S, an entry
12027 in the hash table is located as follows:
12029 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12030 the low-order k bits all set to 1.
12032 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12034 3) If the hash table entry at index H matches the signature, use that
12035 entry. If the hash table entry at index H is unused (all zeroes),
12036 terminate the search: the signature is not present in the table.
12038 4) Let H = (H + H') modulo M. Repeat at Step 3.
12040 Because M > N and H' and M are relatively prime, the search is guaranteed
12041 to stop at an unused slot or find the match. */
12043 /* Create a hash table to map DWO IDs to their CU/TU entry in
12044 .debug_{info,types}.dwo in DWP_FILE.
12045 Returns NULL if there isn't one.
12046 Note: This function processes DWP files only, not DWO files. */
12048 static struct dwp_hash_table
*
12049 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12050 struct dwp_file
*dwp_file
, int is_debug_types
)
12052 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12053 bfd
*dbfd
= dwp_file
->dbfd
;
12054 const gdb_byte
*index_ptr
, *index_end
;
12055 struct dwarf2_section_info
*index
;
12056 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12057 struct dwp_hash_table
*htab
;
12059 if (is_debug_types
)
12060 index
= &dwp_file
->sections
.tu_index
;
12062 index
= &dwp_file
->sections
.cu_index
;
12064 if (dwarf2_section_empty_p (index
))
12066 dwarf2_read_section (objfile
, index
);
12068 index_ptr
= index
->buffer
;
12069 index_end
= index_ptr
+ index
->size
;
12071 version
= read_4_bytes (dbfd
, index_ptr
);
12074 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12078 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12080 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12083 if (version
!= 1 && version
!= 2)
12085 error (_("Dwarf Error: unsupported DWP file version (%s)"
12086 " [in module %s]"),
12087 pulongest (version
), dwp_file
->name
);
12089 if (nr_slots
!= (nr_slots
& -nr_slots
))
12091 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12092 " is not power of 2 [in module %s]"),
12093 pulongest (nr_slots
), dwp_file
->name
);
12096 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12097 htab
->version
= version
;
12098 htab
->nr_columns
= nr_columns
;
12099 htab
->nr_units
= nr_units
;
12100 htab
->nr_slots
= nr_slots
;
12101 htab
->hash_table
= index_ptr
;
12102 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12104 /* Exit early if the table is empty. */
12105 if (nr_slots
== 0 || nr_units
== 0
12106 || (version
== 2 && nr_columns
== 0))
12108 /* All must be zero. */
12109 if (nr_slots
!= 0 || nr_units
!= 0
12110 || (version
== 2 && nr_columns
!= 0))
12112 complaint (&symfile_complaints
,
12113 _("Empty DWP but nr_slots,nr_units,nr_columns not"
12114 " all zero [in modules %s]"),
12122 htab
->section_pool
.v1
.indices
=
12123 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12124 /* It's harder to decide whether the section is too small in v1.
12125 V1 is deprecated anyway so we punt. */
12129 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12130 int *ids
= htab
->section_pool
.v2
.section_ids
;
12131 /* Reverse map for error checking. */
12132 int ids_seen
[DW_SECT_MAX
+ 1];
12135 if (nr_columns
< 2)
12137 error (_("Dwarf Error: bad DWP hash table, too few columns"
12138 " in section table [in module %s]"),
12141 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12143 error (_("Dwarf Error: bad DWP hash table, too many columns"
12144 " in section table [in module %s]"),
12147 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12148 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12149 for (i
= 0; i
< nr_columns
; ++i
)
12151 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12153 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12155 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12156 " in section table [in module %s]"),
12157 id
, dwp_file
->name
);
12159 if (ids_seen
[id
] != -1)
12161 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12162 " id %d in section table [in module %s]"),
12163 id
, dwp_file
->name
);
12168 /* Must have exactly one info or types section. */
12169 if (((ids_seen
[DW_SECT_INFO
] != -1)
12170 + (ids_seen
[DW_SECT_TYPES
] != -1))
12173 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12174 " DWO info/types section [in module %s]"),
12177 /* Must have an abbrev section. */
12178 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12180 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12181 " section [in module %s]"),
12184 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12185 htab
->section_pool
.v2
.sizes
=
12186 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12187 * nr_units
* nr_columns
);
12188 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12189 * nr_units
* nr_columns
))
12192 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12193 " [in module %s]"),
12201 /* Update SECTIONS with the data from SECTP.
12203 This function is like the other "locate" section routines that are
12204 passed to bfd_map_over_sections, but in this context the sections to
12205 read comes from the DWP V1 hash table, not the full ELF section table.
12207 The result is non-zero for success, or zero if an error was found. */
12210 locate_v1_virtual_dwo_sections (asection
*sectp
,
12211 struct virtual_v1_dwo_sections
*sections
)
12213 const struct dwop_section_names
*names
= &dwop_section_names
;
12215 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12217 /* There can be only one. */
12218 if (sections
->abbrev
.s
.section
!= NULL
)
12220 sections
->abbrev
.s
.section
= sectp
;
12221 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12223 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12224 || section_is_p (sectp
->name
, &names
->types_dwo
))
12226 /* There can be only one. */
12227 if (sections
->info_or_types
.s
.section
!= NULL
)
12229 sections
->info_or_types
.s
.section
= sectp
;
12230 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
12232 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12234 /* There can be only one. */
12235 if (sections
->line
.s
.section
!= NULL
)
12237 sections
->line
.s
.section
= sectp
;
12238 sections
->line
.size
= bfd_get_section_size (sectp
);
12240 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12242 /* There can be only one. */
12243 if (sections
->loc
.s
.section
!= NULL
)
12245 sections
->loc
.s
.section
= sectp
;
12246 sections
->loc
.size
= bfd_get_section_size (sectp
);
12248 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12250 /* There can be only one. */
12251 if (sections
->macinfo
.s
.section
!= NULL
)
12253 sections
->macinfo
.s
.section
= sectp
;
12254 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12256 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12258 /* There can be only one. */
12259 if (sections
->macro
.s
.section
!= NULL
)
12261 sections
->macro
.s
.section
= sectp
;
12262 sections
->macro
.size
= bfd_get_section_size (sectp
);
12264 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12266 /* There can be only one. */
12267 if (sections
->str_offsets
.s
.section
!= NULL
)
12269 sections
->str_offsets
.s
.section
= sectp
;
12270 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12274 /* No other kind of section is valid. */
12281 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12282 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12283 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12284 This is for DWP version 1 files. */
12286 static struct dwo_unit
*
12287 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12288 struct dwp_file
*dwp_file
,
12289 uint32_t unit_index
,
12290 const char *comp_dir
,
12291 ULONGEST signature
, int is_debug_types
)
12293 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12294 const struct dwp_hash_table
*dwp_htab
=
12295 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12296 bfd
*dbfd
= dwp_file
->dbfd
;
12297 const char *kind
= is_debug_types
? "TU" : "CU";
12298 struct dwo_file
*dwo_file
;
12299 struct dwo_unit
*dwo_unit
;
12300 struct virtual_v1_dwo_sections sections
;
12301 void **dwo_file_slot
;
12304 gdb_assert (dwp_file
->version
== 1);
12306 if (dwarf_read_debug
)
12308 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12310 pulongest (unit_index
), hex_string (signature
),
12314 /* Fetch the sections of this DWO unit.
12315 Put a limit on the number of sections we look for so that bad data
12316 doesn't cause us to loop forever. */
12318 #define MAX_NR_V1_DWO_SECTIONS \
12319 (1 /* .debug_info or .debug_types */ \
12320 + 1 /* .debug_abbrev */ \
12321 + 1 /* .debug_line */ \
12322 + 1 /* .debug_loc */ \
12323 + 1 /* .debug_str_offsets */ \
12324 + 1 /* .debug_macro or .debug_macinfo */ \
12325 + 1 /* trailing zero */)
12327 memset (§ions
, 0, sizeof (sections
));
12329 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12332 uint32_t section_nr
=
12333 read_4_bytes (dbfd
,
12334 dwp_htab
->section_pool
.v1
.indices
12335 + (unit_index
+ i
) * sizeof (uint32_t));
12337 if (section_nr
== 0)
12339 if (section_nr
>= dwp_file
->num_sections
)
12341 error (_("Dwarf Error: bad DWP hash table, section number too large"
12342 " [in module %s]"),
12346 sectp
= dwp_file
->elf_sections
[section_nr
];
12347 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12349 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12350 " [in module %s]"),
12356 || dwarf2_section_empty_p (§ions
.info_or_types
)
12357 || dwarf2_section_empty_p (§ions
.abbrev
))
12359 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12360 " [in module %s]"),
12363 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12365 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12366 " [in module %s]"),
12370 /* It's easier for the rest of the code if we fake a struct dwo_file and
12371 have dwo_unit "live" in that. At least for now.
12373 The DWP file can be made up of a random collection of CUs and TUs.
12374 However, for each CU + set of TUs that came from the same original DWO
12375 file, we can combine them back into a virtual DWO file to save space
12376 (fewer struct dwo_file objects to allocate). Remember that for really
12377 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12379 std::string virtual_dwo_name
=
12380 string_printf ("virtual-dwo/%d-%d-%d-%d",
12381 get_section_id (§ions
.abbrev
),
12382 get_section_id (§ions
.line
),
12383 get_section_id (§ions
.loc
),
12384 get_section_id (§ions
.str_offsets
));
12385 /* Can we use an existing virtual DWO file? */
12386 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12387 virtual_dwo_name
.c_str (),
12389 /* Create one if necessary. */
12390 if (*dwo_file_slot
== NULL
)
12392 if (dwarf_read_debug
)
12394 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12395 virtual_dwo_name
.c_str ());
12397 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12399 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12400 virtual_dwo_name
.c_str (),
12401 virtual_dwo_name
.size ());
12402 dwo_file
->comp_dir
= comp_dir
;
12403 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12404 dwo_file
->sections
.line
= sections
.line
;
12405 dwo_file
->sections
.loc
= sections
.loc
;
12406 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12407 dwo_file
->sections
.macro
= sections
.macro
;
12408 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12409 /* The "str" section is global to the entire DWP file. */
12410 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12411 /* The info or types section is assigned below to dwo_unit,
12412 there's no need to record it in dwo_file.
12413 Also, we can't simply record type sections in dwo_file because
12414 we record a pointer into the vector in dwo_unit. As we collect more
12415 types we'll grow the vector and eventually have to reallocate space
12416 for it, invalidating all copies of pointers into the previous
12418 *dwo_file_slot
= dwo_file
;
12422 if (dwarf_read_debug
)
12424 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12425 virtual_dwo_name
.c_str ());
12427 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12430 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12431 dwo_unit
->dwo_file
= dwo_file
;
12432 dwo_unit
->signature
= signature
;
12433 dwo_unit
->section
=
12434 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12435 *dwo_unit
->section
= sections
.info_or_types
;
12436 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12441 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12442 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12443 piece within that section used by a TU/CU, return a virtual section
12444 of just that piece. */
12446 static struct dwarf2_section_info
12447 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12448 struct dwarf2_section_info
*section
,
12449 bfd_size_type offset
, bfd_size_type size
)
12451 struct dwarf2_section_info result
;
12454 gdb_assert (section
!= NULL
);
12455 gdb_assert (!section
->is_virtual
);
12457 memset (&result
, 0, sizeof (result
));
12458 result
.s
.containing_section
= section
;
12459 result
.is_virtual
= 1;
12464 sectp
= get_section_bfd_section (section
);
12466 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12467 bounds of the real section. This is a pretty-rare event, so just
12468 flag an error (easier) instead of a warning and trying to cope. */
12470 || offset
+ size
> bfd_get_section_size (sectp
))
12472 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12473 " in section %s [in module %s]"),
12474 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
12475 objfile_name (dwarf2_per_objfile
->objfile
));
12478 result
.virtual_offset
= offset
;
12479 result
.size
= size
;
12483 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12484 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12485 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12486 This is for DWP version 2 files. */
12488 static struct dwo_unit
*
12489 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12490 struct dwp_file
*dwp_file
,
12491 uint32_t unit_index
,
12492 const char *comp_dir
,
12493 ULONGEST signature
, int is_debug_types
)
12495 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12496 const struct dwp_hash_table
*dwp_htab
=
12497 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12498 bfd
*dbfd
= dwp_file
->dbfd
;
12499 const char *kind
= is_debug_types
? "TU" : "CU";
12500 struct dwo_file
*dwo_file
;
12501 struct dwo_unit
*dwo_unit
;
12502 struct virtual_v2_dwo_sections sections
;
12503 void **dwo_file_slot
;
12506 gdb_assert (dwp_file
->version
== 2);
12508 if (dwarf_read_debug
)
12510 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12512 pulongest (unit_index
), hex_string (signature
),
12516 /* Fetch the section offsets of this DWO unit. */
12518 memset (§ions
, 0, sizeof (sections
));
12520 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12522 uint32_t offset
= read_4_bytes (dbfd
,
12523 dwp_htab
->section_pool
.v2
.offsets
12524 + (((unit_index
- 1) * dwp_htab
->nr_columns
12526 * sizeof (uint32_t)));
12527 uint32_t size
= read_4_bytes (dbfd
,
12528 dwp_htab
->section_pool
.v2
.sizes
12529 + (((unit_index
- 1) * dwp_htab
->nr_columns
12531 * sizeof (uint32_t)));
12533 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12536 case DW_SECT_TYPES
:
12537 sections
.info_or_types_offset
= offset
;
12538 sections
.info_or_types_size
= size
;
12540 case DW_SECT_ABBREV
:
12541 sections
.abbrev_offset
= offset
;
12542 sections
.abbrev_size
= size
;
12545 sections
.line_offset
= offset
;
12546 sections
.line_size
= size
;
12549 sections
.loc_offset
= offset
;
12550 sections
.loc_size
= size
;
12552 case DW_SECT_STR_OFFSETS
:
12553 sections
.str_offsets_offset
= offset
;
12554 sections
.str_offsets_size
= size
;
12556 case DW_SECT_MACINFO
:
12557 sections
.macinfo_offset
= offset
;
12558 sections
.macinfo_size
= size
;
12560 case DW_SECT_MACRO
:
12561 sections
.macro_offset
= offset
;
12562 sections
.macro_size
= size
;
12567 /* It's easier for the rest of the code if we fake a struct dwo_file and
12568 have dwo_unit "live" in that. At least for now.
12570 The DWP file can be made up of a random collection of CUs and TUs.
12571 However, for each CU + set of TUs that came from the same original DWO
12572 file, we can combine them back into a virtual DWO file to save space
12573 (fewer struct dwo_file objects to allocate). Remember that for really
12574 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12576 std::string virtual_dwo_name
=
12577 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12578 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12579 (long) (sections
.line_size
? sections
.line_offset
: 0),
12580 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12581 (long) (sections
.str_offsets_size
12582 ? sections
.str_offsets_offset
: 0));
12583 /* Can we use an existing virtual DWO file? */
12584 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12585 virtual_dwo_name
.c_str (),
12587 /* Create one if necessary. */
12588 if (*dwo_file_slot
== NULL
)
12590 if (dwarf_read_debug
)
12592 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12593 virtual_dwo_name
.c_str ());
12595 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12597 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12598 virtual_dwo_name
.c_str (),
12599 virtual_dwo_name
.size ());
12600 dwo_file
->comp_dir
= comp_dir
;
12601 dwo_file
->sections
.abbrev
=
12602 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12603 sections
.abbrev_offset
, sections
.abbrev_size
);
12604 dwo_file
->sections
.line
=
12605 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12606 sections
.line_offset
, sections
.line_size
);
12607 dwo_file
->sections
.loc
=
12608 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12609 sections
.loc_offset
, sections
.loc_size
);
12610 dwo_file
->sections
.macinfo
=
12611 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12612 sections
.macinfo_offset
, sections
.macinfo_size
);
12613 dwo_file
->sections
.macro
=
12614 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12615 sections
.macro_offset
, sections
.macro_size
);
12616 dwo_file
->sections
.str_offsets
=
12617 create_dwp_v2_section (dwarf2_per_objfile
,
12618 &dwp_file
->sections
.str_offsets
,
12619 sections
.str_offsets_offset
,
12620 sections
.str_offsets_size
);
12621 /* The "str" section is global to the entire DWP file. */
12622 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12623 /* The info or types section is assigned below to dwo_unit,
12624 there's no need to record it in dwo_file.
12625 Also, we can't simply record type sections in dwo_file because
12626 we record a pointer into the vector in dwo_unit. As we collect more
12627 types we'll grow the vector and eventually have to reallocate space
12628 for it, invalidating all copies of pointers into the previous
12630 *dwo_file_slot
= dwo_file
;
12634 if (dwarf_read_debug
)
12636 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12637 virtual_dwo_name
.c_str ());
12639 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12642 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12643 dwo_unit
->dwo_file
= dwo_file
;
12644 dwo_unit
->signature
= signature
;
12645 dwo_unit
->section
=
12646 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12647 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12649 ? &dwp_file
->sections
.types
12650 : &dwp_file
->sections
.info
,
12651 sections
.info_or_types_offset
,
12652 sections
.info_or_types_size
);
12653 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12658 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12659 Returns NULL if the signature isn't found. */
12661 static struct dwo_unit
*
12662 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12663 struct dwp_file
*dwp_file
, const char *comp_dir
,
12664 ULONGEST signature
, int is_debug_types
)
12666 const struct dwp_hash_table
*dwp_htab
=
12667 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12668 bfd
*dbfd
= dwp_file
->dbfd
;
12669 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12670 uint32_t hash
= signature
& mask
;
12671 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12674 struct dwo_unit find_dwo_cu
;
12676 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12677 find_dwo_cu
.signature
= signature
;
12678 slot
= htab_find_slot (is_debug_types
12679 ? dwp_file
->loaded_tus
12680 : dwp_file
->loaded_cus
,
12681 &find_dwo_cu
, INSERT
);
12684 return (struct dwo_unit
*) *slot
;
12686 /* Use a for loop so that we don't loop forever on bad debug info. */
12687 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12689 ULONGEST signature_in_table
;
12691 signature_in_table
=
12692 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12693 if (signature_in_table
== signature
)
12695 uint32_t unit_index
=
12696 read_4_bytes (dbfd
,
12697 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12699 if (dwp_file
->version
== 1)
12701 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12702 dwp_file
, unit_index
,
12703 comp_dir
, signature
,
12708 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12709 dwp_file
, unit_index
,
12710 comp_dir
, signature
,
12713 return (struct dwo_unit
*) *slot
;
12715 if (signature_in_table
== 0)
12717 hash
= (hash
+ hash2
) & mask
;
12720 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12721 " [in module %s]"),
12725 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12726 Open the file specified by FILE_NAME and hand it off to BFD for
12727 preliminary analysis. Return a newly initialized bfd *, which
12728 includes a canonicalized copy of FILE_NAME.
12729 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12730 SEARCH_CWD is true if the current directory is to be searched.
12731 It will be searched before debug-file-directory.
12732 If successful, the file is added to the bfd include table of the
12733 objfile's bfd (see gdb_bfd_record_inclusion).
12734 If unable to find/open the file, return NULL.
12735 NOTE: This function is derived from symfile_bfd_open. */
12737 static gdb_bfd_ref_ptr
12738 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12739 const char *file_name
, int is_dwp
, int search_cwd
)
12742 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12743 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12744 to debug_file_directory. */
12745 const char *search_path
;
12746 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12748 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12751 if (*debug_file_directory
!= '\0')
12753 search_path_holder
.reset (concat (".", dirname_separator_string
,
12754 debug_file_directory
,
12756 search_path
= search_path_holder
.get ();
12762 search_path
= debug_file_directory
;
12764 openp_flags flags
= OPF_RETURN_REALPATH
;
12766 flags
|= OPF_SEARCH_IN_PATH
;
12768 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12769 desc
= openp (search_path
, flags
, file_name
,
12770 O_RDONLY
| O_BINARY
, &absolute_name
);
12774 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12776 if (sym_bfd
== NULL
)
12778 bfd_set_cacheable (sym_bfd
.get (), 1);
12780 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12783 /* Success. Record the bfd as having been included by the objfile's bfd.
12784 This is important because things like demangled_names_hash lives in the
12785 objfile's per_bfd space and may have references to things like symbol
12786 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12787 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12792 /* Try to open DWO file FILE_NAME.
12793 COMP_DIR is the DW_AT_comp_dir attribute.
12794 The result is the bfd handle of the file.
12795 If there is a problem finding or opening the file, return NULL.
12796 Upon success, the canonicalized path of the file is stored in the bfd,
12797 same as symfile_bfd_open. */
12799 static gdb_bfd_ref_ptr
12800 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12801 const char *file_name
, const char *comp_dir
)
12803 if (IS_ABSOLUTE_PATH (file_name
))
12804 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12805 0 /*is_dwp*/, 0 /*search_cwd*/);
12807 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12809 if (comp_dir
!= NULL
)
12811 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
12812 file_name
, (char *) NULL
);
12814 /* NOTE: If comp_dir is a relative path, this will also try the
12815 search path, which seems useful. */
12816 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12819 1 /*search_cwd*/));
12820 xfree (path_to_try
);
12825 /* That didn't work, try debug-file-directory, which, despite its name,
12826 is a list of paths. */
12828 if (*debug_file_directory
== '\0')
12831 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12832 0 /*is_dwp*/, 1 /*search_cwd*/);
12835 /* This function is mapped across the sections and remembers the offset and
12836 size of each of the DWO debugging sections we are interested in. */
12839 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12841 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12842 const struct dwop_section_names
*names
= &dwop_section_names
;
12844 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12846 dwo_sections
->abbrev
.s
.section
= sectp
;
12847 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12849 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12851 dwo_sections
->info
.s
.section
= sectp
;
12852 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
12854 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12856 dwo_sections
->line
.s
.section
= sectp
;
12857 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
12859 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12861 dwo_sections
->loc
.s
.section
= sectp
;
12862 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
12864 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12866 dwo_sections
->macinfo
.s
.section
= sectp
;
12867 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12869 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12871 dwo_sections
->macro
.s
.section
= sectp
;
12872 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
12874 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12876 dwo_sections
->str
.s
.section
= sectp
;
12877 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
12879 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12881 dwo_sections
->str_offsets
.s
.section
= sectp
;
12882 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12884 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12886 struct dwarf2_section_info type_section
;
12888 memset (&type_section
, 0, sizeof (type_section
));
12889 type_section
.s
.section
= sectp
;
12890 type_section
.size
= bfd_get_section_size (sectp
);
12891 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
12896 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12897 by PER_CU. This is for the non-DWP case.
12898 The result is NULL if DWO_NAME can't be found. */
12900 static struct dwo_file
*
12901 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12902 const char *dwo_name
, const char *comp_dir
)
12904 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12905 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12907 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
));
12910 if (dwarf_read_debug
)
12911 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12915 /* We use a unique pointer here, despite the obstack allocation,
12916 because a dwo_file needs some cleanup if it is abandoned. */
12917 dwo_file_up
dwo_file (OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
12919 dwo_file
->dwo_name
= dwo_name
;
12920 dwo_file
->comp_dir
= comp_dir
;
12921 dwo_file
->dbfd
= dbfd
.release ();
12923 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
12924 &dwo_file
->sections
);
12926 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
12929 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12930 dwo_file
->sections
.types
, dwo_file
->tus
);
12932 if (dwarf_read_debug
)
12933 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12935 return dwo_file
.release ();
12938 /* This function is mapped across the sections and remembers the offset and
12939 size of each of the DWP debugging sections common to version 1 and 2 that
12940 we are interested in. */
12943 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12944 void *dwp_file_ptr
)
12946 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12947 const struct dwop_section_names
*names
= &dwop_section_names
;
12948 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12950 /* Record the ELF section number for later lookup: this is what the
12951 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12952 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12953 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12955 /* Look for specific sections that we need. */
12956 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12958 dwp_file
->sections
.str
.s
.section
= sectp
;
12959 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
12961 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12963 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12964 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
12966 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12968 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12969 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
12973 /* This function is mapped across the sections and remembers the offset and
12974 size of each of the DWP version 2 debugging sections that we are interested
12975 in. This is split into a separate function because we don't know if we
12976 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12979 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12981 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12982 const struct dwop_section_names
*names
= &dwop_section_names
;
12983 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12985 /* Record the ELF section number for later lookup: this is what the
12986 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12987 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12988 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12990 /* Look for specific sections that we need. */
12991 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12993 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12994 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
12996 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12998 dwp_file
->sections
.info
.s
.section
= sectp
;
12999 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
13001 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13003 dwp_file
->sections
.line
.s
.section
= sectp
;
13004 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
13006 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13008 dwp_file
->sections
.loc
.s
.section
= sectp
;
13009 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
13011 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13013 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13014 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
13016 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13018 dwp_file
->sections
.macro
.s
.section
= sectp
;
13019 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
13021 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13023 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13024 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
13026 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13028 dwp_file
->sections
.types
.s
.section
= sectp
;
13029 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
13033 /* Hash function for dwp_file loaded CUs/TUs. */
13036 hash_dwp_loaded_cutus (const void *item
)
13038 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13040 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13041 return dwo_unit
->signature
;
13044 /* Equality function for dwp_file loaded CUs/TUs. */
13047 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13049 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13050 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13052 return dua
->signature
== dub
->signature
;
13055 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13058 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13060 return htab_create_alloc_ex (3,
13061 hash_dwp_loaded_cutus
,
13062 eq_dwp_loaded_cutus
,
13064 &objfile
->objfile_obstack
,
13065 hashtab_obstack_allocate
,
13066 dummy_obstack_deallocate
);
13069 /* Try to open DWP file FILE_NAME.
13070 The result is the bfd handle of the file.
13071 If there is a problem finding or opening the file, return NULL.
13072 Upon success, the canonicalized path of the file is stored in the bfd,
13073 same as symfile_bfd_open. */
13075 static gdb_bfd_ref_ptr
13076 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13077 const char *file_name
)
13079 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13081 1 /*search_cwd*/));
13085 /* Work around upstream bug 15652.
13086 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13087 [Whether that's a "bug" is debatable, but it is getting in our way.]
13088 We have no real idea where the dwp file is, because gdb's realpath-ing
13089 of the executable's path may have discarded the needed info.
13090 [IWBN if the dwp file name was recorded in the executable, akin to
13091 .gnu_debuglink, but that doesn't exist yet.]
13092 Strip the directory from FILE_NAME and search again. */
13093 if (*debug_file_directory
!= '\0')
13095 /* Don't implicitly search the current directory here.
13096 If the user wants to search "." to handle this case,
13097 it must be added to debug-file-directory. */
13098 return try_open_dwop_file (dwarf2_per_objfile
,
13099 lbasename (file_name
), 1 /*is_dwp*/,
13106 /* Initialize the use of the DWP file for the current objfile.
13107 By convention the name of the DWP file is ${objfile}.dwp.
13108 The result is NULL if it can't be found. */
13110 static struct dwp_file
*
13111 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13113 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13114 struct dwp_file
*dwp_file
;
13116 /* Try to find first .dwp for the binary file before any symbolic links
13119 /* If the objfile is a debug file, find the name of the real binary
13120 file and get the name of dwp file from there. */
13121 std::string dwp_name
;
13122 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13124 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13125 const char *backlink_basename
= lbasename (backlink
->original_name
);
13127 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13130 dwp_name
= objfile
->original_name
;
13132 dwp_name
+= ".dwp";
13134 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13136 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13138 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13139 dwp_name
= objfile_name (objfile
);
13140 dwp_name
+= ".dwp";
13141 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13146 if (dwarf_read_debug
)
13147 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13150 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
13151 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
13152 dwp_file
->dbfd
= dbfd
.release ();
13154 /* +1: section 0 is unused */
13155 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
13156 dwp_file
->elf_sections
=
13157 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13158 dwp_file
->num_sections
, asection
*);
13160 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
13163 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 0);
13165 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 1);
13167 /* The DWP file version is stored in the hash table. Oh well. */
13168 if (dwp_file
->cus
&& dwp_file
->tus
13169 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13171 /* Technically speaking, we should try to limp along, but this is
13172 pretty bizarre. We use pulongest here because that's the established
13173 portability solution (e.g, we cannot use %u for uint32_t). */
13174 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13175 " TU version %s [in DWP file %s]"),
13176 pulongest (dwp_file
->cus
->version
),
13177 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13181 dwp_file
->version
= dwp_file
->cus
->version
;
13182 else if (dwp_file
->tus
)
13183 dwp_file
->version
= dwp_file
->tus
->version
;
13185 dwp_file
->version
= 2;
13187 if (dwp_file
->version
== 2)
13188 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
13191 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13192 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13194 if (dwarf_read_debug
)
13196 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13197 fprintf_unfiltered (gdb_stdlog
,
13198 " %s CUs, %s TUs\n",
13199 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13200 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13206 /* Wrapper around open_and_init_dwp_file, only open it once. */
13208 static struct dwp_file
*
13209 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13211 if (! dwarf2_per_objfile
->dwp_checked
)
13213 dwarf2_per_objfile
->dwp_file
13214 = open_and_init_dwp_file (dwarf2_per_objfile
);
13215 dwarf2_per_objfile
->dwp_checked
= 1;
13217 return dwarf2_per_objfile
->dwp_file
;
13220 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13221 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13222 or in the DWP file for the objfile, referenced by THIS_UNIT.
13223 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13224 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13226 This is called, for example, when wanting to read a variable with a
13227 complex location. Therefore we don't want to do file i/o for every call.
13228 Therefore we don't want to look for a DWO file on every call.
13229 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13230 then we check if we've already seen DWO_NAME, and only THEN do we check
13233 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13234 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13236 static struct dwo_unit
*
13237 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13238 const char *dwo_name
, const char *comp_dir
,
13239 ULONGEST signature
, int is_debug_types
)
13241 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13242 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13243 const char *kind
= is_debug_types
? "TU" : "CU";
13244 void **dwo_file_slot
;
13245 struct dwo_file
*dwo_file
;
13246 struct dwp_file
*dwp_file
;
13248 /* First see if there's a DWP file.
13249 If we have a DWP file but didn't find the DWO inside it, don't
13250 look for the original DWO file. It makes gdb behave differently
13251 depending on whether one is debugging in the build tree. */
13253 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13254 if (dwp_file
!= NULL
)
13256 const struct dwp_hash_table
*dwp_htab
=
13257 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13259 if (dwp_htab
!= NULL
)
13261 struct dwo_unit
*dwo_cutu
=
13262 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13263 signature
, is_debug_types
);
13265 if (dwo_cutu
!= NULL
)
13267 if (dwarf_read_debug
)
13269 fprintf_unfiltered (gdb_stdlog
,
13270 "Virtual DWO %s %s found: @%s\n",
13271 kind
, hex_string (signature
),
13272 host_address_to_string (dwo_cutu
));
13280 /* No DWP file, look for the DWO file. */
13282 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13283 dwo_name
, comp_dir
);
13284 if (*dwo_file_slot
== NULL
)
13286 /* Read in the file and build a table of the CUs/TUs it contains. */
13287 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13289 /* NOTE: This will be NULL if unable to open the file. */
13290 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13292 if (dwo_file
!= NULL
)
13294 struct dwo_unit
*dwo_cutu
= NULL
;
13296 if (is_debug_types
&& dwo_file
->tus
)
13298 struct dwo_unit find_dwo_cutu
;
13300 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13301 find_dwo_cutu
.signature
= signature
;
13303 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13305 else if (!is_debug_types
&& dwo_file
->cus
)
13307 struct dwo_unit find_dwo_cutu
;
13309 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13310 find_dwo_cutu
.signature
= signature
;
13311 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13315 if (dwo_cutu
!= NULL
)
13317 if (dwarf_read_debug
)
13319 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13320 kind
, dwo_name
, hex_string (signature
),
13321 host_address_to_string (dwo_cutu
));
13328 /* We didn't find it. This could mean a dwo_id mismatch, or
13329 someone deleted the DWO/DWP file, or the search path isn't set up
13330 correctly to find the file. */
13332 if (dwarf_read_debug
)
13334 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13335 kind
, dwo_name
, hex_string (signature
));
13338 /* This is a warning and not a complaint because it can be caused by
13339 pilot error (e.g., user accidentally deleting the DWO). */
13341 /* Print the name of the DWP file if we looked there, helps the user
13342 better diagnose the problem. */
13343 std::string dwp_text
;
13345 if (dwp_file
!= NULL
)
13346 dwp_text
= string_printf (" [in DWP file %s]",
13347 lbasename (dwp_file
->name
));
13349 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13350 " [in module %s]"),
13351 kind
, dwo_name
, hex_string (signature
),
13353 this_unit
->is_debug_types
? "TU" : "CU",
13354 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13359 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13360 See lookup_dwo_cutu_unit for details. */
13362 static struct dwo_unit
*
13363 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13364 const char *dwo_name
, const char *comp_dir
,
13365 ULONGEST signature
)
13367 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13370 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13371 See lookup_dwo_cutu_unit for details. */
13373 static struct dwo_unit
*
13374 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13375 const char *dwo_name
, const char *comp_dir
)
13377 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13380 /* Traversal function for queue_and_load_all_dwo_tus. */
13383 queue_and_load_dwo_tu (void **slot
, void *info
)
13385 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13386 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13387 ULONGEST signature
= dwo_unit
->signature
;
13388 struct signatured_type
*sig_type
=
13389 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13391 if (sig_type
!= NULL
)
13393 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13395 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13396 a real dependency of PER_CU on SIG_TYPE. That is detected later
13397 while processing PER_CU. */
13398 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13399 load_full_type_unit (sig_cu
);
13400 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
13406 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13407 The DWO may have the only definition of the type, though it may not be
13408 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13409 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13412 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13414 struct dwo_unit
*dwo_unit
;
13415 struct dwo_file
*dwo_file
;
13417 gdb_assert (!per_cu
->is_debug_types
);
13418 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13419 gdb_assert (per_cu
->cu
!= NULL
);
13421 dwo_unit
= per_cu
->cu
->dwo_unit
;
13422 gdb_assert (dwo_unit
!= NULL
);
13424 dwo_file
= dwo_unit
->dwo_file
;
13425 if (dwo_file
->tus
!= NULL
)
13426 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13429 /* Free all resources associated with DWO_FILE.
13430 Close the DWO file and munmap the sections. */
13433 free_dwo_file (struct dwo_file
*dwo_file
)
13435 /* Note: dbfd is NULL for virtual DWO files. */
13436 gdb_bfd_unref (dwo_file
->dbfd
);
13438 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
13441 /* Traversal function for free_dwo_files. */
13444 free_dwo_file_from_slot (void **slot
, void *info
)
13446 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
13448 free_dwo_file (dwo_file
);
13453 /* Free all resources associated with DWO_FILES. */
13456 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
13458 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
13461 /* Read in various DIEs. */
13463 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13464 Inherit only the children of the DW_AT_abstract_origin DIE not being
13465 already referenced by DW_AT_abstract_origin from the children of the
13469 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13471 struct die_info
*child_die
;
13472 sect_offset
*offsetp
;
13473 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13474 struct die_info
*origin_die
;
13475 /* Iterator of the ORIGIN_DIE children. */
13476 struct die_info
*origin_child_die
;
13477 struct attribute
*attr
;
13478 struct dwarf2_cu
*origin_cu
;
13479 struct pending
**origin_previous_list_in_scope
;
13481 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13485 /* Note that following die references may follow to a die in a
13489 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13491 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13493 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13494 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13496 if (die
->tag
!= origin_die
->tag
13497 && !(die
->tag
== DW_TAG_inlined_subroutine
13498 && origin_die
->tag
== DW_TAG_subprogram
))
13499 complaint (&symfile_complaints
,
13500 _("DIE %s and its abstract origin %s have different tags"),
13501 sect_offset_str (die
->sect_off
),
13502 sect_offset_str (origin_die
->sect_off
));
13504 std::vector
<sect_offset
> offsets
;
13506 for (child_die
= die
->child
;
13507 child_die
&& child_die
->tag
;
13508 child_die
= sibling_die (child_die
))
13510 struct die_info
*child_origin_die
;
13511 struct dwarf2_cu
*child_origin_cu
;
13513 /* We are trying to process concrete instance entries:
13514 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13515 it's not relevant to our analysis here. i.e. detecting DIEs that are
13516 present in the abstract instance but not referenced in the concrete
13518 if (child_die
->tag
== DW_TAG_call_site
13519 || child_die
->tag
== DW_TAG_GNU_call_site
)
13522 /* For each CHILD_DIE, find the corresponding child of
13523 ORIGIN_DIE. If there is more than one layer of
13524 DW_AT_abstract_origin, follow them all; there shouldn't be,
13525 but GCC versions at least through 4.4 generate this (GCC PR
13527 child_origin_die
= child_die
;
13528 child_origin_cu
= cu
;
13531 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13535 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13539 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13540 counterpart may exist. */
13541 if (child_origin_die
!= child_die
)
13543 if (child_die
->tag
!= child_origin_die
->tag
13544 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13545 && child_origin_die
->tag
== DW_TAG_subprogram
))
13546 complaint (&symfile_complaints
,
13547 _("Child DIE %s and its abstract origin %s have "
13549 sect_offset_str (child_die
->sect_off
),
13550 sect_offset_str (child_origin_die
->sect_off
));
13551 if (child_origin_die
->parent
!= origin_die
)
13552 complaint (&symfile_complaints
,
13553 _("Child DIE %s and its abstract origin %s have "
13554 "different parents"),
13555 sect_offset_str (child_die
->sect_off
),
13556 sect_offset_str (child_origin_die
->sect_off
));
13558 offsets
.push_back (child_origin_die
->sect_off
);
13561 std::sort (offsets
.begin (), offsets
.end ());
13562 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13563 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13564 if (offsetp
[-1] == *offsetp
)
13565 complaint (&symfile_complaints
,
13566 _("Multiple children of DIE %s refer "
13567 "to DIE %s as their abstract origin"),
13568 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13570 offsetp
= offsets
.data ();
13571 origin_child_die
= origin_die
->child
;
13572 while (origin_child_die
&& origin_child_die
->tag
)
13574 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13575 while (offsetp
< offsets_end
13576 && *offsetp
< origin_child_die
->sect_off
)
13578 if (offsetp
>= offsets_end
13579 || *offsetp
> origin_child_die
->sect_off
)
13581 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13582 Check whether we're already processing ORIGIN_CHILD_DIE.
13583 This can happen with mutually referenced abstract_origins.
13585 if (!origin_child_die
->in_process
)
13586 process_die (origin_child_die
, origin_cu
);
13588 origin_child_die
= sibling_die (origin_child_die
);
13590 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13594 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13596 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13597 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13598 struct context_stack
*newobj
;
13601 struct die_info
*child_die
;
13602 struct attribute
*attr
, *call_line
, *call_file
;
13604 CORE_ADDR baseaddr
;
13605 struct block
*block
;
13606 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13607 std::vector
<struct symbol
*> template_args
;
13608 struct template_symbol
*templ_func
= NULL
;
13612 /* If we do not have call site information, we can't show the
13613 caller of this inlined function. That's too confusing, so
13614 only use the scope for local variables. */
13615 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13616 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13617 if (call_line
== NULL
|| call_file
== NULL
)
13619 read_lexical_block_scope (die
, cu
);
13624 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13626 name
= dwarf2_name (die
, cu
);
13628 /* Ignore functions with missing or empty names. These are actually
13629 illegal according to the DWARF standard. */
13632 complaint (&symfile_complaints
,
13633 _("missing name for subprogram DIE at %s"),
13634 sect_offset_str (die
->sect_off
));
13638 /* Ignore functions with missing or invalid low and high pc attributes. */
13639 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13640 <= PC_BOUNDS_INVALID
)
13642 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13643 if (!attr
|| !DW_UNSND (attr
))
13644 complaint (&symfile_complaints
,
13645 _("cannot get low and high bounds "
13646 "for subprogram DIE at %s"),
13647 sect_offset_str (die
->sect_off
));
13651 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13652 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13654 /* If we have any template arguments, then we must allocate a
13655 different sort of symbol. */
13656 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13658 if (child_die
->tag
== DW_TAG_template_type_param
13659 || child_die
->tag
== DW_TAG_template_value_param
)
13661 templ_func
= allocate_template_symbol (objfile
);
13662 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13667 newobj
= push_context (0, lowpc
);
13668 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13669 (struct symbol
*) templ_func
);
13671 /* If there is a location expression for DW_AT_frame_base, record
13673 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13675 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13677 /* If there is a location for the static link, record it. */
13678 newobj
->static_link
= NULL
;
13679 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13682 newobj
->static_link
13683 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13684 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
13687 cu
->list_in_scope
= &local_symbols
;
13689 if (die
->child
!= NULL
)
13691 child_die
= die
->child
;
13692 while (child_die
&& child_die
->tag
)
13694 if (child_die
->tag
== DW_TAG_template_type_param
13695 || child_die
->tag
== DW_TAG_template_value_param
)
13697 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13700 template_args
.push_back (arg
);
13703 process_die (child_die
, cu
);
13704 child_die
= sibling_die (child_die
);
13708 inherit_abstract_dies (die
, cu
);
13710 /* If we have a DW_AT_specification, we might need to import using
13711 directives from the context of the specification DIE. See the
13712 comment in determine_prefix. */
13713 if (cu
->language
== language_cplus
13714 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13716 struct dwarf2_cu
*spec_cu
= cu
;
13717 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13721 child_die
= spec_die
->child
;
13722 while (child_die
&& child_die
->tag
)
13724 if (child_die
->tag
== DW_TAG_imported_module
)
13725 process_die (child_die
, spec_cu
);
13726 child_die
= sibling_die (child_die
);
13729 /* In some cases, GCC generates specification DIEs that
13730 themselves contain DW_AT_specification attributes. */
13731 spec_die
= die_specification (spec_die
, &spec_cu
);
13735 newobj
= pop_context ();
13736 /* Make a block for the local symbols within. */
13737 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
13738 newobj
->static_link
, lowpc
, highpc
);
13740 /* For C++, set the block's scope. */
13741 if ((cu
->language
== language_cplus
13742 || cu
->language
== language_fortran
13743 || cu
->language
== language_d
13744 || cu
->language
== language_rust
)
13745 && cu
->processing_has_namespace_info
)
13746 block_set_scope (block
, determine_prefix (die
, cu
),
13747 &objfile
->objfile_obstack
);
13749 /* If we have address ranges, record them. */
13750 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13752 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
13754 /* Attach template arguments to function. */
13755 if (!template_args
.empty ())
13757 gdb_assert (templ_func
!= NULL
);
13759 templ_func
->n_template_arguments
= template_args
.size ();
13760 templ_func
->template_arguments
13761 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13762 templ_func
->n_template_arguments
);
13763 memcpy (templ_func
->template_arguments
,
13764 template_args
.data (),
13765 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13768 /* In C++, we can have functions nested inside functions (e.g., when
13769 a function declares a class that has methods). This means that
13770 when we finish processing a function scope, we may need to go
13771 back to building a containing block's symbol lists. */
13772 local_symbols
= newobj
->locals
;
13773 local_using_directives
= newobj
->local_using_directives
;
13775 /* If we've finished processing a top-level function, subsequent
13776 symbols go in the file symbol list. */
13777 if (outermost_context_p ())
13778 cu
->list_in_scope
= &file_symbols
;
13781 /* Process all the DIES contained within a lexical block scope. Start
13782 a new scope, process the dies, and then close the scope. */
13785 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13787 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13788 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13789 struct context_stack
*newobj
;
13790 CORE_ADDR lowpc
, highpc
;
13791 struct die_info
*child_die
;
13792 CORE_ADDR baseaddr
;
13794 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13796 /* Ignore blocks with missing or invalid low and high pc attributes. */
13797 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13798 as multiple lexical blocks? Handling children in a sane way would
13799 be nasty. Might be easier to properly extend generic blocks to
13800 describe ranges. */
13801 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13803 case PC_BOUNDS_NOT_PRESENT
:
13804 /* DW_TAG_lexical_block has no attributes, process its children as if
13805 there was no wrapping by that DW_TAG_lexical_block.
13806 GCC does no longer produces such DWARF since GCC r224161. */
13807 for (child_die
= die
->child
;
13808 child_die
!= NULL
&& child_die
->tag
;
13809 child_die
= sibling_die (child_die
))
13810 process_die (child_die
, cu
);
13812 case PC_BOUNDS_INVALID
:
13815 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13816 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13818 push_context (0, lowpc
);
13819 if (die
->child
!= NULL
)
13821 child_die
= die
->child
;
13822 while (child_die
&& child_die
->tag
)
13824 process_die (child_die
, cu
);
13825 child_die
= sibling_die (child_die
);
13828 inherit_abstract_dies (die
, cu
);
13829 newobj
= pop_context ();
13831 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
13833 struct block
*block
13834 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
13835 newobj
->start_addr
, highpc
);
13837 /* Note that recording ranges after traversing children, as we
13838 do here, means that recording a parent's ranges entails
13839 walking across all its children's ranges as they appear in
13840 the address map, which is quadratic behavior.
13842 It would be nicer to record the parent's ranges before
13843 traversing its children, simply overriding whatever you find
13844 there. But since we don't even decide whether to create a
13845 block until after we've traversed its children, that's hard
13847 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13849 local_symbols
= newobj
->locals
;
13850 local_using_directives
= newobj
->local_using_directives
;
13853 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13856 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13858 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13859 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13860 CORE_ADDR pc
, baseaddr
;
13861 struct attribute
*attr
;
13862 struct call_site
*call_site
, call_site_local
;
13865 struct die_info
*child_die
;
13867 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13869 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13872 /* This was a pre-DWARF-5 GNU extension alias
13873 for DW_AT_call_return_pc. */
13874 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13878 complaint (&symfile_complaints
,
13879 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
13880 "DIE %s [in module %s]"),
13881 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13884 pc
= attr_value_as_address (attr
) + baseaddr
;
13885 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13887 if (cu
->call_site_htab
== NULL
)
13888 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13889 NULL
, &objfile
->objfile_obstack
,
13890 hashtab_obstack_allocate
, NULL
);
13891 call_site_local
.pc
= pc
;
13892 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13895 complaint (&symfile_complaints
,
13896 _("Duplicate PC %s for DW_TAG_call_site "
13897 "DIE %s [in module %s]"),
13898 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13899 objfile_name (objfile
));
13903 /* Count parameters at the caller. */
13906 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13907 child_die
= sibling_die (child_die
))
13909 if (child_die
->tag
!= DW_TAG_call_site_parameter
13910 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13912 complaint (&symfile_complaints
,
13913 _("Tag %d is not DW_TAG_call_site_parameter in "
13914 "DW_TAG_call_site child DIE %s [in module %s]"),
13915 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13916 objfile_name (objfile
));
13924 = ((struct call_site
*)
13925 obstack_alloc (&objfile
->objfile_obstack
,
13926 sizeof (*call_site
)
13927 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13929 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13930 call_site
->pc
= pc
;
13932 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13933 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13935 struct die_info
*func_die
;
13937 /* Skip also over DW_TAG_inlined_subroutine. */
13938 for (func_die
= die
->parent
;
13939 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13940 && func_die
->tag
!= DW_TAG_subroutine_type
;
13941 func_die
= func_die
->parent
);
13943 /* DW_AT_call_all_calls is a superset
13944 of DW_AT_call_all_tail_calls. */
13946 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13947 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13948 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13949 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13951 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13952 not complete. But keep CALL_SITE for look ups via call_site_htab,
13953 both the initial caller containing the real return address PC and
13954 the final callee containing the current PC of a chain of tail
13955 calls do not need to have the tail call list complete. But any
13956 function candidate for a virtual tail call frame searched via
13957 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13958 determined unambiguously. */
13962 struct type
*func_type
= NULL
;
13965 func_type
= get_die_type (func_die
, cu
);
13966 if (func_type
!= NULL
)
13968 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13970 /* Enlist this call site to the function. */
13971 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13972 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13975 complaint (&symfile_complaints
,
13976 _("Cannot find function owning DW_TAG_call_site "
13977 "DIE %s [in module %s]"),
13978 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13982 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13984 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13986 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13989 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13990 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13992 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13993 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
13994 /* Keep NULL DWARF_BLOCK. */;
13995 else if (attr_form_is_block (attr
))
13997 struct dwarf2_locexpr_baton
*dlbaton
;
13999 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14000 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14001 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14002 dlbaton
->per_cu
= cu
->per_cu
;
14004 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14006 else if (attr_form_is_ref (attr
))
14008 struct dwarf2_cu
*target_cu
= cu
;
14009 struct die_info
*target_die
;
14011 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14012 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14013 if (die_is_declaration (target_die
, target_cu
))
14015 const char *target_physname
;
14017 /* Prefer the mangled name; otherwise compute the demangled one. */
14018 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14019 if (target_physname
== NULL
)
14020 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14021 if (target_physname
== NULL
)
14022 complaint (&symfile_complaints
,
14023 _("DW_AT_call_target target DIE has invalid "
14024 "physname, for referencing DIE %s [in module %s]"),
14025 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14027 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14033 /* DW_AT_entry_pc should be preferred. */
14034 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14035 <= PC_BOUNDS_INVALID
)
14036 complaint (&symfile_complaints
,
14037 _("DW_AT_call_target target DIE has invalid "
14038 "low pc, for referencing DIE %s [in module %s]"),
14039 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14042 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14043 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14048 complaint (&symfile_complaints
,
14049 _("DW_TAG_call_site DW_AT_call_target is neither "
14050 "block nor reference, for DIE %s [in module %s]"),
14051 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14053 call_site
->per_cu
= cu
->per_cu
;
14055 for (child_die
= die
->child
;
14056 child_die
&& child_die
->tag
;
14057 child_die
= sibling_die (child_die
))
14059 struct call_site_parameter
*parameter
;
14060 struct attribute
*loc
, *origin
;
14062 if (child_die
->tag
!= DW_TAG_call_site_parameter
14063 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14065 /* Already printed the complaint above. */
14069 gdb_assert (call_site
->parameter_count
< nparams
);
14070 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14072 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14073 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14074 register is contained in DW_AT_call_value. */
14076 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14077 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14078 if (origin
== NULL
)
14080 /* This was a pre-DWARF-5 GNU extension alias
14081 for DW_AT_call_parameter. */
14082 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14084 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14086 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14088 sect_offset sect_off
14089 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14090 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14092 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14093 binding can be done only inside one CU. Such referenced DIE
14094 therefore cannot be even moved to DW_TAG_partial_unit. */
14095 complaint (&symfile_complaints
,
14096 _("DW_AT_call_parameter offset is not in CU for "
14097 "DW_TAG_call_site child DIE %s [in module %s]"),
14098 sect_offset_str (child_die
->sect_off
),
14099 objfile_name (objfile
));
14102 parameter
->u
.param_cu_off
14103 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14105 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14107 complaint (&symfile_complaints
,
14108 _("No DW_FORM_block* DW_AT_location for "
14109 "DW_TAG_call_site child DIE %s [in module %s]"),
14110 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14115 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14116 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14117 if (parameter
->u
.dwarf_reg
!= -1)
14118 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14119 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14120 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14121 ¶meter
->u
.fb_offset
))
14122 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14125 complaint (&symfile_complaints
,
14126 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
14127 "for DW_FORM_block* DW_AT_location is supported for "
14128 "DW_TAG_call_site child DIE %s "
14130 sect_offset_str (child_die
->sect_off
),
14131 objfile_name (objfile
));
14136 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14138 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14139 if (!attr_form_is_block (attr
))
14141 complaint (&symfile_complaints
,
14142 _("No DW_FORM_block* DW_AT_call_value for "
14143 "DW_TAG_call_site child DIE %s [in module %s]"),
14144 sect_offset_str (child_die
->sect_off
),
14145 objfile_name (objfile
));
14148 parameter
->value
= DW_BLOCK (attr
)->data
;
14149 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14151 /* Parameters are not pre-cleared by memset above. */
14152 parameter
->data_value
= NULL
;
14153 parameter
->data_value_size
= 0;
14154 call_site
->parameter_count
++;
14156 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14158 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14161 if (!attr_form_is_block (attr
))
14162 complaint (&symfile_complaints
,
14163 _("No DW_FORM_block* DW_AT_call_data_value for "
14164 "DW_TAG_call_site child DIE %s [in module %s]"),
14165 sect_offset_str (child_die
->sect_off
),
14166 objfile_name (objfile
));
14169 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14170 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14176 /* Helper function for read_variable. If DIE represents a virtual
14177 table, then return the type of the concrete object that is
14178 associated with the virtual table. Otherwise, return NULL. */
14180 static struct type
*
14181 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14183 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14187 /* Find the type DIE. */
14188 struct die_info
*type_die
= NULL
;
14189 struct dwarf2_cu
*type_cu
= cu
;
14191 if (attr_form_is_ref (attr
))
14192 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14193 if (type_die
== NULL
)
14196 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14198 return die_containing_type (type_die
, type_cu
);
14201 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14204 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14206 struct rust_vtable_symbol
*storage
= NULL
;
14208 if (cu
->language
== language_rust
)
14210 struct type
*containing_type
= rust_containing_type (die
, cu
);
14212 if (containing_type
!= NULL
)
14214 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14216 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14217 struct rust_vtable_symbol
);
14218 initialize_objfile_symbol (storage
);
14219 storage
->concrete_type
= containing_type
;
14220 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14224 new_symbol (die
, NULL
, cu
, storage
);
14227 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14228 reading .debug_rnglists.
14229 Callback's type should be:
14230 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14231 Return true if the attributes are present and valid, otherwise,
14234 template <typename Callback
>
14236 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14237 Callback
&&callback
)
14239 struct dwarf2_per_objfile
*dwarf2_per_objfile
14240 = cu
->per_cu
->dwarf2_per_objfile
;
14241 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14242 bfd
*obfd
= objfile
->obfd
;
14243 /* Base address selection entry. */
14246 const gdb_byte
*buffer
;
14247 CORE_ADDR baseaddr
;
14248 bool overflow
= false;
14250 found_base
= cu
->base_known
;
14251 base
= cu
->base_address
;
14253 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14254 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14256 complaint (&symfile_complaints
,
14257 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14261 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14263 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14267 /* Initialize it due to a false compiler warning. */
14268 CORE_ADDR range_beginning
= 0, range_end
= 0;
14269 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14270 + dwarf2_per_objfile
->rnglists
.size
);
14271 unsigned int bytes_read
;
14273 if (buffer
== buf_end
)
14278 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14281 case DW_RLE_end_of_list
:
14283 case DW_RLE_base_address
:
14284 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14289 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14291 buffer
+= bytes_read
;
14293 case DW_RLE_start_length
:
14294 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14299 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14300 buffer
+= bytes_read
;
14301 range_end
= (range_beginning
14302 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14303 buffer
+= bytes_read
;
14304 if (buffer
> buf_end
)
14310 case DW_RLE_offset_pair
:
14311 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14312 buffer
+= bytes_read
;
14313 if (buffer
> buf_end
)
14318 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14319 buffer
+= bytes_read
;
14320 if (buffer
> buf_end
)
14326 case DW_RLE_start_end
:
14327 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14332 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14333 buffer
+= bytes_read
;
14334 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14335 buffer
+= bytes_read
;
14338 complaint (&symfile_complaints
,
14339 _("Invalid .debug_rnglists data (no base address)"));
14342 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14344 if (rlet
== DW_RLE_base_address
)
14349 /* We have no valid base address for the ranges
14351 complaint (&symfile_complaints
,
14352 _("Invalid .debug_rnglists data (no base address)"));
14356 if (range_beginning
> range_end
)
14358 /* Inverted range entries are invalid. */
14359 complaint (&symfile_complaints
,
14360 _("Invalid .debug_rnglists data (inverted range)"));
14364 /* Empty range entries have no effect. */
14365 if (range_beginning
== range_end
)
14368 range_beginning
+= base
;
14371 /* A not-uncommon case of bad debug info.
14372 Don't pollute the addrmap with bad data. */
14373 if (range_beginning
+ baseaddr
== 0
14374 && !dwarf2_per_objfile
->has_section_at_zero
)
14376 complaint (&symfile_complaints
,
14377 _(".debug_rnglists entry has start address of zero"
14378 " [in module %s]"), objfile_name (objfile
));
14382 callback (range_beginning
, range_end
);
14387 complaint (&symfile_complaints
,
14388 _("Offset %d is not terminated "
14389 "for DW_AT_ranges attribute"),
14397 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14398 Callback's type should be:
14399 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14400 Return 1 if the attributes are present and valid, otherwise, return 0. */
14402 template <typename Callback
>
14404 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14405 Callback
&&callback
)
14407 struct dwarf2_per_objfile
*dwarf2_per_objfile
14408 = cu
->per_cu
->dwarf2_per_objfile
;
14409 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14410 struct comp_unit_head
*cu_header
= &cu
->header
;
14411 bfd
*obfd
= objfile
->obfd
;
14412 unsigned int addr_size
= cu_header
->addr_size
;
14413 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14414 /* Base address selection entry. */
14417 unsigned int dummy
;
14418 const gdb_byte
*buffer
;
14419 CORE_ADDR baseaddr
;
14421 if (cu_header
->version
>= 5)
14422 return dwarf2_rnglists_process (offset
, cu
, callback
);
14424 found_base
= cu
->base_known
;
14425 base
= cu
->base_address
;
14427 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14428 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14430 complaint (&symfile_complaints
,
14431 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14435 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14437 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14441 CORE_ADDR range_beginning
, range_end
;
14443 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14444 buffer
+= addr_size
;
14445 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14446 buffer
+= addr_size
;
14447 offset
+= 2 * addr_size
;
14449 /* An end of list marker is a pair of zero addresses. */
14450 if (range_beginning
== 0 && range_end
== 0)
14451 /* Found the end of list entry. */
14454 /* Each base address selection entry is a pair of 2 values.
14455 The first is the largest possible address, the second is
14456 the base address. Check for a base address here. */
14457 if ((range_beginning
& mask
) == mask
)
14459 /* If we found the largest possible address, then we already
14460 have the base address in range_end. */
14468 /* We have no valid base address for the ranges
14470 complaint (&symfile_complaints
,
14471 _("Invalid .debug_ranges data (no base address)"));
14475 if (range_beginning
> range_end
)
14477 /* Inverted range entries are invalid. */
14478 complaint (&symfile_complaints
,
14479 _("Invalid .debug_ranges data (inverted range)"));
14483 /* Empty range entries have no effect. */
14484 if (range_beginning
== range_end
)
14487 range_beginning
+= base
;
14490 /* A not-uncommon case of bad debug info.
14491 Don't pollute the addrmap with bad data. */
14492 if (range_beginning
+ baseaddr
== 0
14493 && !dwarf2_per_objfile
->has_section_at_zero
)
14495 complaint (&symfile_complaints
,
14496 _(".debug_ranges entry has start address of zero"
14497 " [in module %s]"), objfile_name (objfile
));
14501 callback (range_beginning
, range_end
);
14507 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14508 Return 1 if the attributes are present and valid, otherwise, return 0.
14509 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14512 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14513 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14514 struct partial_symtab
*ranges_pst
)
14516 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14517 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14518 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14519 SECT_OFF_TEXT (objfile
));
14522 CORE_ADDR high
= 0;
14525 retval
= dwarf2_ranges_process (offset
, cu
,
14526 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14528 if (ranges_pst
!= NULL
)
14533 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14534 range_beginning
+ baseaddr
);
14535 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14536 range_end
+ baseaddr
);
14537 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
14541 /* FIXME: This is recording everything as a low-high
14542 segment of consecutive addresses. We should have a
14543 data structure for discontiguous block ranges
14547 low
= range_beginning
;
14553 if (range_beginning
< low
)
14554 low
= range_beginning
;
14555 if (range_end
> high
)
14563 /* If the first entry is an end-of-list marker, the range
14564 describes an empty scope, i.e. no instructions. */
14570 *high_return
= high
;
14574 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14575 definition for the return value. *LOWPC and *HIGHPC are set iff
14576 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14578 static enum pc_bounds_kind
14579 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14580 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14581 struct partial_symtab
*pst
)
14583 struct dwarf2_per_objfile
*dwarf2_per_objfile
14584 = cu
->per_cu
->dwarf2_per_objfile
;
14585 struct attribute
*attr
;
14586 struct attribute
*attr_high
;
14588 CORE_ADDR high
= 0;
14589 enum pc_bounds_kind ret
;
14591 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14594 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14597 low
= attr_value_as_address (attr
);
14598 high
= attr_value_as_address (attr_high
);
14599 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14603 /* Found high w/o low attribute. */
14604 return PC_BOUNDS_INVALID
;
14606 /* Found consecutive range of addresses. */
14607 ret
= PC_BOUNDS_HIGH_LOW
;
14611 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14614 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14615 We take advantage of the fact that DW_AT_ranges does not appear
14616 in DW_TAG_compile_unit of DWO files. */
14617 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14618 unsigned int ranges_offset
= (DW_UNSND (attr
)
14619 + (need_ranges_base
14623 /* Value of the DW_AT_ranges attribute is the offset in the
14624 .debug_ranges section. */
14625 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14626 return PC_BOUNDS_INVALID
;
14627 /* Found discontinuous range of addresses. */
14628 ret
= PC_BOUNDS_RANGES
;
14631 return PC_BOUNDS_NOT_PRESENT
;
14634 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14636 return PC_BOUNDS_INVALID
;
14638 /* When using the GNU linker, .gnu.linkonce. sections are used to
14639 eliminate duplicate copies of functions and vtables and such.
14640 The linker will arbitrarily choose one and discard the others.
14641 The AT_*_pc values for such functions refer to local labels in
14642 these sections. If the section from that file was discarded, the
14643 labels are not in the output, so the relocs get a value of 0.
14644 If this is a discarded function, mark the pc bounds as invalid,
14645 so that GDB will ignore it. */
14646 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14647 return PC_BOUNDS_INVALID
;
14655 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14656 its low and high PC addresses. Do nothing if these addresses could not
14657 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14658 and HIGHPC to the high address if greater than HIGHPC. */
14661 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14662 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14663 struct dwarf2_cu
*cu
)
14665 CORE_ADDR low
, high
;
14666 struct die_info
*child
= die
->child
;
14668 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14670 *lowpc
= std::min (*lowpc
, low
);
14671 *highpc
= std::max (*highpc
, high
);
14674 /* If the language does not allow nested subprograms (either inside
14675 subprograms or lexical blocks), we're done. */
14676 if (cu
->language
!= language_ada
)
14679 /* Check all the children of the given DIE. If it contains nested
14680 subprograms, then check their pc bounds. Likewise, we need to
14681 check lexical blocks as well, as they may also contain subprogram
14683 while (child
&& child
->tag
)
14685 if (child
->tag
== DW_TAG_subprogram
14686 || child
->tag
== DW_TAG_lexical_block
)
14687 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14688 child
= sibling_die (child
);
14692 /* Get the low and high pc's represented by the scope DIE, and store
14693 them in *LOWPC and *HIGHPC. If the correct values can't be
14694 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14697 get_scope_pc_bounds (struct die_info
*die
,
14698 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14699 struct dwarf2_cu
*cu
)
14701 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14702 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14703 CORE_ADDR current_low
, current_high
;
14705 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14706 >= PC_BOUNDS_RANGES
)
14708 best_low
= current_low
;
14709 best_high
= current_high
;
14713 struct die_info
*child
= die
->child
;
14715 while (child
&& child
->tag
)
14717 switch (child
->tag
) {
14718 case DW_TAG_subprogram
:
14719 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14721 case DW_TAG_namespace
:
14722 case DW_TAG_module
:
14723 /* FIXME: carlton/2004-01-16: Should we do this for
14724 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14725 that current GCC's always emit the DIEs corresponding
14726 to definitions of methods of classes as children of a
14727 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14728 the DIEs giving the declarations, which could be
14729 anywhere). But I don't see any reason why the
14730 standards says that they have to be there. */
14731 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14733 if (current_low
!= ((CORE_ADDR
) -1))
14735 best_low
= std::min (best_low
, current_low
);
14736 best_high
= std::max (best_high
, current_high
);
14744 child
= sibling_die (child
);
14749 *highpc
= best_high
;
14752 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14756 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14757 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14759 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14760 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14761 struct attribute
*attr
;
14762 struct attribute
*attr_high
;
14764 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14767 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14770 CORE_ADDR low
= attr_value_as_address (attr
);
14771 CORE_ADDR high
= attr_value_as_address (attr_high
);
14773 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14776 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14777 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14778 record_block_range (block
, low
, high
- 1);
14782 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14785 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14786 We take advantage of the fact that DW_AT_ranges does not appear
14787 in DW_TAG_compile_unit of DWO files. */
14788 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14790 /* The value of the DW_AT_ranges attribute is the offset of the
14791 address range list in the .debug_ranges section. */
14792 unsigned long offset
= (DW_UNSND (attr
)
14793 + (need_ranges_base
? cu
->ranges_base
: 0));
14795 dwarf2_ranges_process (offset
, cu
,
14796 [&] (CORE_ADDR start
, CORE_ADDR end
)
14800 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14801 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14802 record_block_range (block
, start
, end
- 1);
14807 /* Check whether the producer field indicates either of GCC < 4.6, or the
14808 Intel C/C++ compiler, and cache the result in CU. */
14811 check_producer (struct dwarf2_cu
*cu
)
14815 if (cu
->producer
== NULL
)
14817 /* For unknown compilers expect their behavior is DWARF version
14820 GCC started to support .debug_types sections by -gdwarf-4 since
14821 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14822 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14823 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14824 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14826 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14828 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14829 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14831 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14832 cu
->producer_is_icc_lt_14
= major
< 14;
14835 /* For other non-GCC compilers, expect their behavior is DWARF version
14839 cu
->checked_producer
= 1;
14842 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14843 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14844 during 4.6.0 experimental. */
14847 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14849 if (!cu
->checked_producer
)
14850 check_producer (cu
);
14852 return cu
->producer_is_gxx_lt_4_6
;
14855 /* Return the default accessibility type if it is not overriden by
14856 DW_AT_accessibility. */
14858 static enum dwarf_access_attribute
14859 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14861 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14863 /* The default DWARF 2 accessibility for members is public, the default
14864 accessibility for inheritance is private. */
14866 if (die
->tag
!= DW_TAG_inheritance
)
14867 return DW_ACCESS_public
;
14869 return DW_ACCESS_private
;
14873 /* DWARF 3+ defines the default accessibility a different way. The same
14874 rules apply now for DW_TAG_inheritance as for the members and it only
14875 depends on the container kind. */
14877 if (die
->parent
->tag
== DW_TAG_class_type
)
14878 return DW_ACCESS_private
;
14880 return DW_ACCESS_public
;
14884 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14885 offset. If the attribute was not found return 0, otherwise return
14886 1. If it was found but could not properly be handled, set *OFFSET
14890 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14893 struct attribute
*attr
;
14895 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14900 /* Note that we do not check for a section offset first here.
14901 This is because DW_AT_data_member_location is new in DWARF 4,
14902 so if we see it, we can assume that a constant form is really
14903 a constant and not a section offset. */
14904 if (attr_form_is_constant (attr
))
14905 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14906 else if (attr_form_is_section_offset (attr
))
14907 dwarf2_complex_location_expr_complaint ();
14908 else if (attr_form_is_block (attr
))
14909 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14911 dwarf2_complex_location_expr_complaint ();
14919 /* Add an aggregate field to the field list. */
14922 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14923 struct dwarf2_cu
*cu
)
14925 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14926 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14927 struct nextfield
*new_field
;
14928 struct attribute
*attr
;
14930 const char *fieldname
= "";
14932 if (die
->tag
== DW_TAG_inheritance
)
14934 fip
->baseclasses
.emplace_back ();
14935 new_field
= &fip
->baseclasses
.back ();
14939 fip
->fields
.emplace_back ();
14940 new_field
= &fip
->fields
.back ();
14945 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14947 new_field
->accessibility
= DW_UNSND (attr
);
14949 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14950 if (new_field
->accessibility
!= DW_ACCESS_public
)
14951 fip
->non_public_fields
= 1;
14953 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14955 new_field
->virtuality
= DW_UNSND (attr
);
14957 new_field
->virtuality
= DW_VIRTUALITY_none
;
14959 fp
= &new_field
->field
;
14961 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14965 /* Data member other than a C++ static data member. */
14967 /* Get type of field. */
14968 fp
->type
= die_type (die
, cu
);
14970 SET_FIELD_BITPOS (*fp
, 0);
14972 /* Get bit size of field (zero if none). */
14973 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14976 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14980 FIELD_BITSIZE (*fp
) = 0;
14983 /* Get bit offset of field. */
14984 if (handle_data_member_location (die
, cu
, &offset
))
14985 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14986 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14989 if (gdbarch_bits_big_endian (gdbarch
))
14991 /* For big endian bits, the DW_AT_bit_offset gives the
14992 additional bit offset from the MSB of the containing
14993 anonymous object to the MSB of the field. We don't
14994 have to do anything special since we don't need to
14995 know the size of the anonymous object. */
14996 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15000 /* For little endian bits, compute the bit offset to the
15001 MSB of the anonymous object, subtract off the number of
15002 bits from the MSB of the field to the MSB of the
15003 object, and then subtract off the number of bits of
15004 the field itself. The result is the bit offset of
15005 the LSB of the field. */
15006 int anonymous_size
;
15007 int bit_offset
= DW_UNSND (attr
);
15009 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15012 /* The size of the anonymous object containing
15013 the bit field is explicit, so use the
15014 indicated size (in bytes). */
15015 anonymous_size
= DW_UNSND (attr
);
15019 /* The size of the anonymous object containing
15020 the bit field must be inferred from the type
15021 attribute of the data member containing the
15023 anonymous_size
= TYPE_LENGTH (fp
->type
);
15025 SET_FIELD_BITPOS (*fp
,
15026 (FIELD_BITPOS (*fp
)
15027 + anonymous_size
* bits_per_byte
15028 - bit_offset
- FIELD_BITSIZE (*fp
)));
15031 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15033 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15034 + dwarf2_get_attr_constant_value (attr
, 0)));
15036 /* Get name of field. */
15037 fieldname
= dwarf2_name (die
, cu
);
15038 if (fieldname
== NULL
)
15041 /* The name is already allocated along with this objfile, so we don't
15042 need to duplicate it for the type. */
15043 fp
->name
= fieldname
;
15045 /* Change accessibility for artificial fields (e.g. virtual table
15046 pointer or virtual base class pointer) to private. */
15047 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15049 FIELD_ARTIFICIAL (*fp
) = 1;
15050 new_field
->accessibility
= DW_ACCESS_private
;
15051 fip
->non_public_fields
= 1;
15054 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15056 /* C++ static member. */
15058 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15059 is a declaration, but all versions of G++ as of this writing
15060 (so through at least 3.2.1) incorrectly generate
15061 DW_TAG_variable tags. */
15063 const char *physname
;
15065 /* Get name of field. */
15066 fieldname
= dwarf2_name (die
, cu
);
15067 if (fieldname
== NULL
)
15070 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15072 /* Only create a symbol if this is an external value.
15073 new_symbol checks this and puts the value in the global symbol
15074 table, which we want. If it is not external, new_symbol
15075 will try to put the value in cu->list_in_scope which is wrong. */
15076 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15078 /* A static const member, not much different than an enum as far as
15079 we're concerned, except that we can support more types. */
15080 new_symbol (die
, NULL
, cu
);
15083 /* Get physical name. */
15084 physname
= dwarf2_physname (fieldname
, die
, cu
);
15086 /* The name is already allocated along with this objfile, so we don't
15087 need to duplicate it for the type. */
15088 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15089 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15090 FIELD_NAME (*fp
) = fieldname
;
15092 else if (die
->tag
== DW_TAG_inheritance
)
15096 /* C++ base class field. */
15097 if (handle_data_member_location (die
, cu
, &offset
))
15098 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15099 FIELD_BITSIZE (*fp
) = 0;
15100 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15101 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
15103 else if (die
->tag
== DW_TAG_variant_part
)
15105 /* process_structure_scope will treat this DIE as a union. */
15106 process_structure_scope (die
, cu
);
15108 /* The variant part is relative to the start of the enclosing
15110 SET_FIELD_BITPOS (*fp
, 0);
15111 fp
->type
= get_die_type (die
, cu
);
15112 fp
->artificial
= 1;
15113 fp
->name
= "<<variant>>";
15116 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15119 /* Can the type given by DIE define another type? */
15122 type_can_define_types (const struct die_info
*die
)
15126 case DW_TAG_typedef
:
15127 case DW_TAG_class_type
:
15128 case DW_TAG_structure_type
:
15129 case DW_TAG_union_type
:
15130 case DW_TAG_enumeration_type
:
15138 /* Add a type definition defined in the scope of the FIP's class. */
15141 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15142 struct dwarf2_cu
*cu
)
15144 struct decl_field fp
;
15145 memset (&fp
, 0, sizeof (fp
));
15147 gdb_assert (type_can_define_types (die
));
15149 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15150 fp
.name
= dwarf2_name (die
, cu
);
15151 fp
.type
= read_type_die (die
, cu
);
15153 /* Save accessibility. */
15154 enum dwarf_access_attribute accessibility
;
15155 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15157 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15159 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15160 switch (accessibility
)
15162 case DW_ACCESS_public
:
15163 /* The assumed value if neither private nor protected. */
15165 case DW_ACCESS_private
:
15168 case DW_ACCESS_protected
:
15169 fp
.is_protected
= 1;
15172 complaint (&symfile_complaints
,
15173 _("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15176 if (die
->tag
== DW_TAG_typedef
)
15177 fip
->typedef_field_list
.push_back (fp
);
15179 fip
->nested_types_list
.push_back (fp
);
15182 /* Create the vector of fields, and attach it to the type. */
15185 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15186 struct dwarf2_cu
*cu
)
15188 int nfields
= fip
->nfields
;
15190 /* Record the field count, allocate space for the array of fields,
15191 and create blank accessibility bitfields if necessary. */
15192 TYPE_NFIELDS (type
) = nfields
;
15193 TYPE_FIELDS (type
) = (struct field
*)
15194 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15196 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15198 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15200 TYPE_FIELD_PRIVATE_BITS (type
) =
15201 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15202 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15204 TYPE_FIELD_PROTECTED_BITS (type
) =
15205 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15206 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15208 TYPE_FIELD_IGNORE_BITS (type
) =
15209 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15210 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15213 /* If the type has baseclasses, allocate and clear a bit vector for
15214 TYPE_FIELD_VIRTUAL_BITS. */
15215 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15217 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15218 unsigned char *pointer
;
15220 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15221 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15222 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15223 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15224 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15227 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15229 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15231 for (int index
= 0; index
< nfields
; ++index
)
15233 struct nextfield
&field
= fip
->fields
[index
];
15235 if (field
.variant
.is_discriminant
)
15236 di
->discriminant_index
= index
;
15237 else if (field
.variant
.default_branch
)
15238 di
->default_index
= index
;
15240 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15244 /* Copy the saved-up fields into the field vector. */
15245 for (int i
= 0; i
< nfields
; ++i
)
15247 struct nextfield
&field
15248 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15249 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15251 TYPE_FIELD (type
, i
) = field
.field
;
15252 switch (field
.accessibility
)
15254 case DW_ACCESS_private
:
15255 if (cu
->language
!= language_ada
)
15256 SET_TYPE_FIELD_PRIVATE (type
, i
);
15259 case DW_ACCESS_protected
:
15260 if (cu
->language
!= language_ada
)
15261 SET_TYPE_FIELD_PROTECTED (type
, i
);
15264 case DW_ACCESS_public
:
15268 /* Unknown accessibility. Complain and treat it as public. */
15270 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
15271 field
.accessibility
);
15275 if (i
< fip
->baseclasses
.size ())
15277 switch (field
.virtuality
)
15279 case DW_VIRTUALITY_virtual
:
15280 case DW_VIRTUALITY_pure_virtual
:
15281 if (cu
->language
== language_ada
)
15282 error (_("unexpected virtuality in component of Ada type"));
15283 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15290 /* Return true if this member function is a constructor, false
15294 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15296 const char *fieldname
;
15297 const char *type_name
;
15300 if (die
->parent
== NULL
)
15303 if (die
->parent
->tag
!= DW_TAG_structure_type
15304 && die
->parent
->tag
!= DW_TAG_union_type
15305 && die
->parent
->tag
!= DW_TAG_class_type
)
15308 fieldname
= dwarf2_name (die
, cu
);
15309 type_name
= dwarf2_name (die
->parent
, cu
);
15310 if (fieldname
== NULL
|| type_name
== NULL
)
15313 len
= strlen (fieldname
);
15314 return (strncmp (fieldname
, type_name
, len
) == 0
15315 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15318 /* Add a member function to the proper fieldlist. */
15321 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15322 struct type
*type
, struct dwarf2_cu
*cu
)
15324 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15325 struct attribute
*attr
;
15327 struct fnfieldlist
*flp
= nullptr;
15328 struct fn_field
*fnp
;
15329 const char *fieldname
;
15330 struct type
*this_type
;
15331 enum dwarf_access_attribute accessibility
;
15333 if (cu
->language
== language_ada
)
15334 error (_("unexpected member function in Ada type"));
15336 /* Get name of member function. */
15337 fieldname
= dwarf2_name (die
, cu
);
15338 if (fieldname
== NULL
)
15341 /* Look up member function name in fieldlist. */
15342 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15344 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15346 flp
= &fip
->fnfieldlists
[i
];
15351 /* Create a new fnfieldlist if necessary. */
15352 if (flp
== nullptr)
15354 fip
->fnfieldlists
.emplace_back ();
15355 flp
= &fip
->fnfieldlists
.back ();
15356 flp
->name
= fieldname
;
15357 i
= fip
->fnfieldlists
.size () - 1;
15360 /* Create a new member function field and add it to the vector of
15362 flp
->fnfields
.emplace_back ();
15363 fnp
= &flp
->fnfields
.back ();
15365 /* Delay processing of the physname until later. */
15366 if (cu
->language
== language_cplus
)
15367 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15371 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15372 fnp
->physname
= physname
? physname
: "";
15375 fnp
->type
= alloc_type (objfile
);
15376 this_type
= read_type_die (die
, cu
);
15377 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15379 int nparams
= TYPE_NFIELDS (this_type
);
15381 /* TYPE is the domain of this method, and THIS_TYPE is the type
15382 of the method itself (TYPE_CODE_METHOD). */
15383 smash_to_method_type (fnp
->type
, type
,
15384 TYPE_TARGET_TYPE (this_type
),
15385 TYPE_FIELDS (this_type
),
15386 TYPE_NFIELDS (this_type
),
15387 TYPE_VARARGS (this_type
));
15389 /* Handle static member functions.
15390 Dwarf2 has no clean way to discern C++ static and non-static
15391 member functions. G++ helps GDB by marking the first
15392 parameter for non-static member functions (which is the this
15393 pointer) as artificial. We obtain this information from
15394 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15395 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15396 fnp
->voffset
= VOFFSET_STATIC
;
15399 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
15400 dwarf2_full_name (fieldname
, die
, cu
));
15402 /* Get fcontext from DW_AT_containing_type if present. */
15403 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15404 fnp
->fcontext
= die_containing_type (die
, cu
);
15406 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15407 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15409 /* Get accessibility. */
15410 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15412 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15414 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15415 switch (accessibility
)
15417 case DW_ACCESS_private
:
15418 fnp
->is_private
= 1;
15420 case DW_ACCESS_protected
:
15421 fnp
->is_protected
= 1;
15425 /* Check for artificial methods. */
15426 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15427 if (attr
&& DW_UNSND (attr
) != 0)
15428 fnp
->is_artificial
= 1;
15430 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15432 /* Get index in virtual function table if it is a virtual member
15433 function. For older versions of GCC, this is an offset in the
15434 appropriate virtual table, as specified by DW_AT_containing_type.
15435 For everyone else, it is an expression to be evaluated relative
15436 to the object address. */
15438 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15441 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15443 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15445 /* Old-style GCC. */
15446 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15448 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15449 || (DW_BLOCK (attr
)->size
> 1
15450 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15451 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15453 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15454 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15455 dwarf2_complex_location_expr_complaint ();
15457 fnp
->voffset
/= cu
->header
.addr_size
;
15461 dwarf2_complex_location_expr_complaint ();
15463 if (!fnp
->fcontext
)
15465 /* If there is no `this' field and no DW_AT_containing_type,
15466 we cannot actually find a base class context for the
15468 if (TYPE_NFIELDS (this_type
) == 0
15469 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15471 complaint (&symfile_complaints
,
15472 _("cannot determine context for virtual member "
15473 "function \"%s\" (offset %s)"),
15474 fieldname
, sect_offset_str (die
->sect_off
));
15479 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15483 else if (attr_form_is_section_offset (attr
))
15485 dwarf2_complex_location_expr_complaint ();
15489 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15495 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15496 if (attr
&& DW_UNSND (attr
))
15498 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15499 complaint (&symfile_complaints
,
15500 _("Member function \"%s\" (offset %s) is virtual "
15501 "but the vtable offset is not specified"),
15502 fieldname
, sect_offset_str (die
->sect_off
));
15503 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15504 TYPE_CPLUS_DYNAMIC (type
) = 1;
15509 /* Create the vector of member function fields, and attach it to the type. */
15512 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15513 struct dwarf2_cu
*cu
)
15515 if (cu
->language
== language_ada
)
15516 error (_("unexpected member functions in Ada type"));
15518 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15519 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15521 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15523 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15525 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15526 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15528 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15529 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15530 fn_flp
->fn_fields
= (struct fn_field
*)
15531 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15533 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15534 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15537 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15540 /* Returns non-zero if NAME is the name of a vtable member in CU's
15541 language, zero otherwise. */
15543 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15545 static const char vptr
[] = "_vptr";
15547 /* Look for the C++ form of the vtable. */
15548 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15554 /* GCC outputs unnamed structures that are really pointers to member
15555 functions, with the ABI-specified layout. If TYPE describes
15556 such a structure, smash it into a member function type.
15558 GCC shouldn't do this; it should just output pointer to member DIEs.
15559 This is GCC PR debug/28767. */
15562 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15564 struct type
*pfn_type
, *self_type
, *new_type
;
15566 /* Check for a structure with no name and two children. */
15567 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15570 /* Check for __pfn and __delta members. */
15571 if (TYPE_FIELD_NAME (type
, 0) == NULL
15572 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15573 || TYPE_FIELD_NAME (type
, 1) == NULL
15574 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15577 /* Find the type of the method. */
15578 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15579 if (pfn_type
== NULL
15580 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15581 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15584 /* Look for the "this" argument. */
15585 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15586 if (TYPE_NFIELDS (pfn_type
) == 0
15587 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15588 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15591 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15592 new_type
= alloc_type (objfile
);
15593 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15594 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15595 TYPE_VARARGS (pfn_type
));
15596 smash_to_methodptr_type (type
, new_type
);
15600 /* Called when we find the DIE that starts a structure or union scope
15601 (definition) to create a type for the structure or union. Fill in
15602 the type's name and general properties; the members will not be
15603 processed until process_structure_scope. A symbol table entry for
15604 the type will also not be done until process_structure_scope (assuming
15605 the type has a name).
15607 NOTE: we need to call these functions regardless of whether or not the
15608 DIE has a DW_AT_name attribute, since it might be an anonymous
15609 structure or union. This gets the type entered into our set of
15610 user defined types. */
15612 static struct type
*
15613 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15615 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15617 struct attribute
*attr
;
15620 /* If the definition of this type lives in .debug_types, read that type.
15621 Don't follow DW_AT_specification though, that will take us back up
15622 the chain and we want to go down. */
15623 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15626 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15628 /* The type's CU may not be the same as CU.
15629 Ensure TYPE is recorded with CU in die_type_hash. */
15630 return set_die_type (die
, type
, cu
);
15633 type
= alloc_type (objfile
);
15634 INIT_CPLUS_SPECIFIC (type
);
15636 name
= dwarf2_name (die
, cu
);
15639 if (cu
->language
== language_cplus
15640 || cu
->language
== language_d
15641 || cu
->language
== language_rust
)
15643 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15645 /* dwarf2_full_name might have already finished building the DIE's
15646 type. If so, there is no need to continue. */
15647 if (get_die_type (die
, cu
) != NULL
)
15648 return get_die_type (die
, cu
);
15650 TYPE_TAG_NAME (type
) = full_name
;
15651 if (die
->tag
== DW_TAG_structure_type
15652 || die
->tag
== DW_TAG_class_type
)
15653 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15657 /* The name is already allocated along with this objfile, so
15658 we don't need to duplicate it for the type. */
15659 TYPE_TAG_NAME (type
) = name
;
15660 if (die
->tag
== DW_TAG_class_type
)
15661 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15665 if (die
->tag
== DW_TAG_structure_type
)
15667 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15669 else if (die
->tag
== DW_TAG_union_type
)
15671 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15673 else if (die
->tag
== DW_TAG_variant_part
)
15675 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15676 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15680 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15683 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15684 TYPE_DECLARED_CLASS (type
) = 1;
15686 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15689 if (attr_form_is_constant (attr
))
15690 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15693 /* For the moment, dynamic type sizes are not supported
15694 by GDB's struct type. The actual size is determined
15695 on-demand when resolving the type of a given object,
15696 so set the type's length to zero for now. Otherwise,
15697 we record an expression as the length, and that expression
15698 could lead to a very large value, which could eventually
15699 lead to us trying to allocate that much memory when creating
15700 a value of that type. */
15701 TYPE_LENGTH (type
) = 0;
15706 TYPE_LENGTH (type
) = 0;
15709 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15711 /* ICC<14 does not output the required DW_AT_declaration on
15712 incomplete types, but gives them a size of zero. */
15713 TYPE_STUB (type
) = 1;
15716 TYPE_STUB_SUPPORTED (type
) = 1;
15718 if (die_is_declaration (die
, cu
))
15719 TYPE_STUB (type
) = 1;
15720 else if (attr
== NULL
&& die
->child
== NULL
15721 && producer_is_realview (cu
->producer
))
15722 /* RealView does not output the required DW_AT_declaration
15723 on incomplete types. */
15724 TYPE_STUB (type
) = 1;
15726 /* We need to add the type field to the die immediately so we don't
15727 infinitely recurse when dealing with pointers to the structure
15728 type within the structure itself. */
15729 set_die_type (die
, type
, cu
);
15731 /* set_die_type should be already done. */
15732 set_descriptive_type (type
, die
, cu
);
15737 /* A helper for process_structure_scope that handles a single member
15741 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15742 struct field_info
*fi
,
15743 std::vector
<struct symbol
*> *template_args
,
15744 struct dwarf2_cu
*cu
)
15746 if (child_die
->tag
== DW_TAG_member
15747 || child_die
->tag
== DW_TAG_variable
15748 || child_die
->tag
== DW_TAG_variant_part
)
15750 /* NOTE: carlton/2002-11-05: A C++ static data member
15751 should be a DW_TAG_member that is a declaration, but
15752 all versions of G++ as of this writing (so through at
15753 least 3.2.1) incorrectly generate DW_TAG_variable
15754 tags for them instead. */
15755 dwarf2_add_field (fi
, child_die
, cu
);
15757 else if (child_die
->tag
== DW_TAG_subprogram
)
15759 /* Rust doesn't have member functions in the C++ sense.
15760 However, it does emit ordinary functions as children
15761 of a struct DIE. */
15762 if (cu
->language
== language_rust
)
15763 read_func_scope (child_die
, cu
);
15766 /* C++ member function. */
15767 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15770 else if (child_die
->tag
== DW_TAG_inheritance
)
15772 /* C++ base class field. */
15773 dwarf2_add_field (fi
, child_die
, cu
);
15775 else if (type_can_define_types (child_die
))
15776 dwarf2_add_type_defn (fi
, child_die
, cu
);
15777 else if (child_die
->tag
== DW_TAG_template_type_param
15778 || child_die
->tag
== DW_TAG_template_value_param
)
15780 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15783 template_args
->push_back (arg
);
15785 else if (child_die
->tag
== DW_TAG_variant
)
15787 /* In a variant we want to get the discriminant and also add a
15788 field for our sole member child. */
15789 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15791 for (struct die_info
*variant_child
= child_die
->child
;
15792 variant_child
!= NULL
;
15793 variant_child
= sibling_die (variant_child
))
15795 if (variant_child
->tag
== DW_TAG_member
)
15797 handle_struct_member_die (variant_child
, type
, fi
,
15798 template_args
, cu
);
15799 /* Only handle the one. */
15804 /* We don't handle this but we might as well report it if we see
15806 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15807 complaint (&symfile_complaints
,
15808 _("DW_AT_discr_list is not supported yet"
15809 " - DIE at %s [in module %s]"),
15810 sect_offset_str (child_die
->sect_off
),
15811 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15813 /* The first field was just added, so we can stash the
15814 discriminant there. */
15815 gdb_assert (!fi
->fields
.empty ());
15817 fi
->fields
.back ().variant
.default_branch
= true;
15819 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15823 /* Finish creating a structure or union type, including filling in
15824 its members and creating a symbol for it. */
15827 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15829 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15830 struct die_info
*child_die
;
15833 type
= get_die_type (die
, cu
);
15835 type
= read_structure_type (die
, cu
);
15837 /* When reading a DW_TAG_variant_part, we need to notice when we
15838 read the discriminant member, so we can record it later in the
15839 discriminant_info. */
15840 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15841 sect_offset discr_offset
;
15843 if (is_variant_part
)
15845 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15848 /* Maybe it's a univariant form, an extension we support.
15849 In this case arrange not to check the offset. */
15850 is_variant_part
= false;
15852 else if (attr_form_is_ref (discr
))
15854 struct dwarf2_cu
*target_cu
= cu
;
15855 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15857 discr_offset
= target_die
->sect_off
;
15861 complaint (&symfile_complaints
,
15862 _("DW_AT_discr does not have DIE reference form"
15863 " - DIE at %s [in module %s]"),
15864 sect_offset_str (die
->sect_off
),
15865 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15866 is_variant_part
= false;
15870 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15872 struct field_info fi
;
15873 std::vector
<struct symbol
*> template_args
;
15875 child_die
= die
->child
;
15877 while (child_die
&& child_die
->tag
)
15879 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15881 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15882 fi
.fields
.back ().variant
.is_discriminant
= true;
15884 child_die
= sibling_die (child_die
);
15887 /* Attach template arguments to type. */
15888 if (!template_args
.empty ())
15890 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15891 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15892 TYPE_TEMPLATE_ARGUMENTS (type
)
15893 = XOBNEWVEC (&objfile
->objfile_obstack
,
15895 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15896 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15897 template_args
.data (),
15898 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15899 * sizeof (struct symbol
*)));
15902 /* Attach fields and member functions to the type. */
15904 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15905 if (!fi
.fnfieldlists
.empty ())
15907 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15909 /* Get the type which refers to the base class (possibly this
15910 class itself) which contains the vtable pointer for the current
15911 class from the DW_AT_containing_type attribute. This use of
15912 DW_AT_containing_type is a GNU extension. */
15914 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15916 struct type
*t
= die_containing_type (die
, cu
);
15918 set_type_vptr_basetype (type
, t
);
15923 /* Our own class provides vtbl ptr. */
15924 for (i
= TYPE_NFIELDS (t
) - 1;
15925 i
>= TYPE_N_BASECLASSES (t
);
15928 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15930 if (is_vtable_name (fieldname
, cu
))
15932 set_type_vptr_fieldno (type
, i
);
15937 /* Complain if virtual function table field not found. */
15938 if (i
< TYPE_N_BASECLASSES (t
))
15939 complaint (&symfile_complaints
,
15940 _("virtual function table pointer "
15941 "not found when defining class '%s'"),
15942 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
15947 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15950 else if (cu
->producer
15951 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15953 /* The IBM XLC compiler does not provide direct indication
15954 of the containing type, but the vtable pointer is
15955 always named __vfp. */
15959 for (i
= TYPE_NFIELDS (type
) - 1;
15960 i
>= TYPE_N_BASECLASSES (type
);
15963 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15965 set_type_vptr_fieldno (type
, i
);
15966 set_type_vptr_basetype (type
, type
);
15973 /* Copy fi.typedef_field_list linked list elements content into the
15974 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15975 if (!fi
.typedef_field_list
.empty ())
15977 int count
= fi
.typedef_field_list
.size ();
15979 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15980 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15981 = ((struct decl_field
*)
15983 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15984 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15986 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15987 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15990 /* Copy fi.nested_types_list linked list elements content into the
15991 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15992 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15994 int count
= fi
.nested_types_list
.size ();
15996 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15997 TYPE_NESTED_TYPES_ARRAY (type
)
15998 = ((struct decl_field
*)
15999 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16000 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16002 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16003 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16007 quirk_gcc_member_function_pointer (type
, objfile
);
16008 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16009 cu
->rust_unions
.push_back (type
);
16011 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16012 snapshots) has been known to create a die giving a declaration
16013 for a class that has, as a child, a die giving a definition for a
16014 nested class. So we have to process our children even if the
16015 current die is a declaration. Normally, of course, a declaration
16016 won't have any children at all. */
16018 child_die
= die
->child
;
16020 while (child_die
!= NULL
&& child_die
->tag
)
16022 if (child_die
->tag
== DW_TAG_member
16023 || child_die
->tag
== DW_TAG_variable
16024 || child_die
->tag
== DW_TAG_inheritance
16025 || child_die
->tag
== DW_TAG_template_value_param
16026 || child_die
->tag
== DW_TAG_template_type_param
)
16031 process_die (child_die
, cu
);
16033 child_die
= sibling_die (child_die
);
16036 /* Do not consider external references. According to the DWARF standard,
16037 these DIEs are identified by the fact that they have no byte_size
16038 attribute, and a declaration attribute. */
16039 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16040 || !die_is_declaration (die
, cu
))
16041 new_symbol (die
, type
, cu
);
16044 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16045 update TYPE using some information only available in DIE's children. */
16048 update_enumeration_type_from_children (struct die_info
*die
,
16050 struct dwarf2_cu
*cu
)
16052 struct die_info
*child_die
;
16053 int unsigned_enum
= 1;
16057 auto_obstack obstack
;
16059 for (child_die
= die
->child
;
16060 child_die
!= NULL
&& child_die
->tag
;
16061 child_die
= sibling_die (child_die
))
16063 struct attribute
*attr
;
16065 const gdb_byte
*bytes
;
16066 struct dwarf2_locexpr_baton
*baton
;
16069 if (child_die
->tag
!= DW_TAG_enumerator
)
16072 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16076 name
= dwarf2_name (child_die
, cu
);
16078 name
= "<anonymous enumerator>";
16080 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16081 &value
, &bytes
, &baton
);
16087 else if ((mask
& value
) != 0)
16092 /* If we already know that the enum type is neither unsigned, nor
16093 a flag type, no need to look at the rest of the enumerates. */
16094 if (!unsigned_enum
&& !flag_enum
)
16099 TYPE_UNSIGNED (type
) = 1;
16101 TYPE_FLAG_ENUM (type
) = 1;
16104 /* Given a DW_AT_enumeration_type die, set its type. We do not
16105 complete the type's fields yet, or create any symbols. */
16107 static struct type
*
16108 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16110 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16112 struct attribute
*attr
;
16115 /* If the definition of this type lives in .debug_types, read that type.
16116 Don't follow DW_AT_specification though, that will take us back up
16117 the chain and we want to go down. */
16118 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16121 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16123 /* The type's CU may not be the same as CU.
16124 Ensure TYPE is recorded with CU in die_type_hash. */
16125 return set_die_type (die
, type
, cu
);
16128 type
= alloc_type (objfile
);
16130 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16131 name
= dwarf2_full_name (NULL
, die
, cu
);
16133 TYPE_TAG_NAME (type
) = name
;
16135 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16138 struct type
*underlying_type
= die_type (die
, cu
);
16140 TYPE_TARGET_TYPE (type
) = underlying_type
;
16143 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16146 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16150 TYPE_LENGTH (type
) = 0;
16153 /* The enumeration DIE can be incomplete. In Ada, any type can be
16154 declared as private in the package spec, and then defined only
16155 inside the package body. Such types are known as Taft Amendment
16156 Types. When another package uses such a type, an incomplete DIE
16157 may be generated by the compiler. */
16158 if (die_is_declaration (die
, cu
))
16159 TYPE_STUB (type
) = 1;
16161 /* Finish the creation of this type by using the enum's children.
16162 We must call this even when the underlying type has been provided
16163 so that we can determine if we're looking at a "flag" enum. */
16164 update_enumeration_type_from_children (die
, type
, cu
);
16166 /* If this type has an underlying type that is not a stub, then we
16167 may use its attributes. We always use the "unsigned" attribute
16168 in this situation, because ordinarily we guess whether the type
16169 is unsigned -- but the guess can be wrong and the underlying type
16170 can tell us the reality. However, we defer to a local size
16171 attribute if one exists, because this lets the compiler override
16172 the underlying type if needed. */
16173 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16175 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16176 if (TYPE_LENGTH (type
) == 0)
16177 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16180 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16182 return set_die_type (die
, type
, cu
);
16185 /* Given a pointer to a die which begins an enumeration, process all
16186 the dies that define the members of the enumeration, and create the
16187 symbol for the enumeration type.
16189 NOTE: We reverse the order of the element list. */
16192 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16194 struct type
*this_type
;
16196 this_type
= get_die_type (die
, cu
);
16197 if (this_type
== NULL
)
16198 this_type
= read_enumeration_type (die
, cu
);
16200 if (die
->child
!= NULL
)
16202 struct die_info
*child_die
;
16203 struct symbol
*sym
;
16204 struct field
*fields
= NULL
;
16205 int num_fields
= 0;
16208 child_die
= die
->child
;
16209 while (child_die
&& child_die
->tag
)
16211 if (child_die
->tag
!= DW_TAG_enumerator
)
16213 process_die (child_die
, cu
);
16217 name
= dwarf2_name (child_die
, cu
);
16220 sym
= new_symbol (child_die
, this_type
, cu
);
16222 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16224 fields
= (struct field
*)
16226 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16227 * sizeof (struct field
));
16230 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16231 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16232 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16233 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16239 child_die
= sibling_die (child_die
);
16244 TYPE_NFIELDS (this_type
) = num_fields
;
16245 TYPE_FIELDS (this_type
) = (struct field
*)
16246 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16247 memcpy (TYPE_FIELDS (this_type
), fields
,
16248 sizeof (struct field
) * num_fields
);
16253 /* If we are reading an enum from a .debug_types unit, and the enum
16254 is a declaration, and the enum is not the signatured type in the
16255 unit, then we do not want to add a symbol for it. Adding a
16256 symbol would in some cases obscure the true definition of the
16257 enum, giving users an incomplete type when the definition is
16258 actually available. Note that we do not want to do this for all
16259 enums which are just declarations, because C++0x allows forward
16260 enum declarations. */
16261 if (cu
->per_cu
->is_debug_types
16262 && die_is_declaration (die
, cu
))
16264 struct signatured_type
*sig_type
;
16266 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16267 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16268 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16272 new_symbol (die
, this_type
, cu
);
16275 /* Extract all information from a DW_TAG_array_type DIE and put it in
16276 the DIE's type field. For now, this only handles one dimensional
16279 static struct type
*
16280 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16282 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16283 struct die_info
*child_die
;
16285 struct type
*element_type
, *range_type
, *index_type
;
16286 struct attribute
*attr
;
16288 struct dynamic_prop
*byte_stride_prop
= NULL
;
16289 unsigned int bit_stride
= 0;
16291 element_type
= die_type (die
, cu
);
16293 /* The die_type call above may have already set the type for this DIE. */
16294 type
= get_die_type (die
, cu
);
16298 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16304 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16305 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
);
16308 complaint (&symfile_complaints
,
16309 _("unable to read array DW_AT_byte_stride "
16310 " - DIE at %s [in module %s]"),
16311 sect_offset_str (die
->sect_off
),
16312 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16313 /* Ignore this attribute. We will likely not be able to print
16314 arrays of this type correctly, but there is little we can do
16315 to help if we cannot read the attribute's value. */
16316 byte_stride_prop
= NULL
;
16320 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16322 bit_stride
= DW_UNSND (attr
);
16324 /* Irix 6.2 native cc creates array types without children for
16325 arrays with unspecified length. */
16326 if (die
->child
== NULL
)
16328 index_type
= objfile_type (objfile
)->builtin_int
;
16329 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16330 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16331 byte_stride_prop
, bit_stride
);
16332 return set_die_type (die
, type
, cu
);
16335 std::vector
<struct type
*> range_types
;
16336 child_die
= die
->child
;
16337 while (child_die
&& child_die
->tag
)
16339 if (child_die
->tag
== DW_TAG_subrange_type
)
16341 struct type
*child_type
= read_type_die (child_die
, cu
);
16343 if (child_type
!= NULL
)
16345 /* The range type was succesfully read. Save it for the
16346 array type creation. */
16347 range_types
.push_back (child_type
);
16350 child_die
= sibling_die (child_die
);
16353 /* Dwarf2 dimensions are output from left to right, create the
16354 necessary array types in backwards order. */
16356 type
= element_type
;
16358 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16362 while (i
< range_types
.size ())
16363 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16364 byte_stride_prop
, bit_stride
);
16368 size_t ndim
= range_types
.size ();
16370 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16371 byte_stride_prop
, bit_stride
);
16374 /* Understand Dwarf2 support for vector types (like they occur on
16375 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16376 array type. This is not part of the Dwarf2/3 standard yet, but a
16377 custom vendor extension. The main difference between a regular
16378 array and the vector variant is that vectors are passed by value
16380 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16382 make_vector_type (type
);
16384 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16385 implementation may choose to implement triple vectors using this
16387 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16390 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16391 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16393 complaint (&symfile_complaints
,
16394 _("DW_AT_byte_size for array type smaller "
16395 "than the total size of elements"));
16398 name
= dwarf2_name (die
, cu
);
16400 TYPE_NAME (type
) = name
;
16402 /* Install the type in the die. */
16403 set_die_type (die
, type
, cu
);
16405 /* set_die_type should be already done. */
16406 set_descriptive_type (type
, die
, cu
);
16411 static enum dwarf_array_dim_ordering
16412 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16414 struct attribute
*attr
;
16416 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16419 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16421 /* GNU F77 is a special case, as at 08/2004 array type info is the
16422 opposite order to the dwarf2 specification, but data is still
16423 laid out as per normal fortran.
16425 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16426 version checking. */
16428 if (cu
->language
== language_fortran
16429 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16431 return DW_ORD_row_major
;
16434 switch (cu
->language_defn
->la_array_ordering
)
16436 case array_column_major
:
16437 return DW_ORD_col_major
;
16438 case array_row_major
:
16440 return DW_ORD_row_major
;
16444 /* Extract all information from a DW_TAG_set_type DIE and put it in
16445 the DIE's type field. */
16447 static struct type
*
16448 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16450 struct type
*domain_type
, *set_type
;
16451 struct attribute
*attr
;
16453 domain_type
= die_type (die
, cu
);
16455 /* The die_type call above may have already set the type for this DIE. */
16456 set_type
= get_die_type (die
, cu
);
16460 set_type
= create_set_type (NULL
, domain_type
);
16462 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16464 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16466 return set_die_type (die
, set_type
, cu
);
16469 /* A helper for read_common_block that creates a locexpr baton.
16470 SYM is the symbol which we are marking as computed.
16471 COMMON_DIE is the DIE for the common block.
16472 COMMON_LOC is the location expression attribute for the common
16474 MEMBER_LOC is the location expression attribute for the particular
16475 member of the common block that we are processing.
16476 CU is the CU from which the above come. */
16479 mark_common_block_symbol_computed (struct symbol
*sym
,
16480 struct die_info
*common_die
,
16481 struct attribute
*common_loc
,
16482 struct attribute
*member_loc
,
16483 struct dwarf2_cu
*cu
)
16485 struct dwarf2_per_objfile
*dwarf2_per_objfile
16486 = cu
->per_cu
->dwarf2_per_objfile
;
16487 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16488 struct dwarf2_locexpr_baton
*baton
;
16490 unsigned int cu_off
;
16491 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16492 LONGEST offset
= 0;
16494 gdb_assert (common_loc
&& member_loc
);
16495 gdb_assert (attr_form_is_block (common_loc
));
16496 gdb_assert (attr_form_is_block (member_loc
)
16497 || attr_form_is_constant (member_loc
));
16499 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16500 baton
->per_cu
= cu
->per_cu
;
16501 gdb_assert (baton
->per_cu
);
16503 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16505 if (attr_form_is_constant (member_loc
))
16507 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16508 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16511 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16513 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16516 *ptr
++ = DW_OP_call4
;
16517 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16518 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16521 if (attr_form_is_constant (member_loc
))
16523 *ptr
++ = DW_OP_addr
;
16524 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16525 ptr
+= cu
->header
.addr_size
;
16529 /* We have to copy the data here, because DW_OP_call4 will only
16530 use a DW_AT_location attribute. */
16531 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16532 ptr
+= DW_BLOCK (member_loc
)->size
;
16535 *ptr
++ = DW_OP_plus
;
16536 gdb_assert (ptr
- baton
->data
== baton
->size
);
16538 SYMBOL_LOCATION_BATON (sym
) = baton
;
16539 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16542 /* Create appropriate locally-scoped variables for all the
16543 DW_TAG_common_block entries. Also create a struct common_block
16544 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16545 is used to sepate the common blocks name namespace from regular
16549 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16551 struct attribute
*attr
;
16553 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16556 /* Support the .debug_loc offsets. */
16557 if (attr_form_is_block (attr
))
16561 else if (attr_form_is_section_offset (attr
))
16563 dwarf2_complex_location_expr_complaint ();
16568 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16569 "common block member");
16574 if (die
->child
!= NULL
)
16576 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16577 struct die_info
*child_die
;
16578 size_t n_entries
= 0, size
;
16579 struct common_block
*common_block
;
16580 struct symbol
*sym
;
16582 for (child_die
= die
->child
;
16583 child_die
&& child_die
->tag
;
16584 child_die
= sibling_die (child_die
))
16587 size
= (sizeof (struct common_block
)
16588 + (n_entries
- 1) * sizeof (struct symbol
*));
16590 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16592 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16593 common_block
->n_entries
= 0;
16595 for (child_die
= die
->child
;
16596 child_die
&& child_die
->tag
;
16597 child_die
= sibling_die (child_die
))
16599 /* Create the symbol in the DW_TAG_common_block block in the current
16601 sym
= new_symbol (child_die
, NULL
, cu
);
16604 struct attribute
*member_loc
;
16606 common_block
->contents
[common_block
->n_entries
++] = sym
;
16608 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16612 /* GDB has handled this for a long time, but it is
16613 not specified by DWARF. It seems to have been
16614 emitted by gfortran at least as recently as:
16615 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16616 complaint (&symfile_complaints
,
16617 _("Variable in common block has "
16618 "DW_AT_data_member_location "
16619 "- DIE at %s [in module %s]"),
16620 sect_offset_str (child_die
->sect_off
),
16621 objfile_name (objfile
));
16623 if (attr_form_is_section_offset (member_loc
))
16624 dwarf2_complex_location_expr_complaint ();
16625 else if (attr_form_is_constant (member_loc
)
16626 || attr_form_is_block (member_loc
))
16629 mark_common_block_symbol_computed (sym
, die
, attr
,
16633 dwarf2_complex_location_expr_complaint ();
16638 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16639 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16643 /* Create a type for a C++ namespace. */
16645 static struct type
*
16646 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16648 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16649 const char *previous_prefix
, *name
;
16653 /* For extensions, reuse the type of the original namespace. */
16654 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16656 struct die_info
*ext_die
;
16657 struct dwarf2_cu
*ext_cu
= cu
;
16659 ext_die
= dwarf2_extension (die
, &ext_cu
);
16660 type
= read_type_die (ext_die
, ext_cu
);
16662 /* EXT_CU may not be the same as CU.
16663 Ensure TYPE is recorded with CU in die_type_hash. */
16664 return set_die_type (die
, type
, cu
);
16667 name
= namespace_name (die
, &is_anonymous
, cu
);
16669 /* Now build the name of the current namespace. */
16671 previous_prefix
= determine_prefix (die
, cu
);
16672 if (previous_prefix
[0] != '\0')
16673 name
= typename_concat (&objfile
->objfile_obstack
,
16674 previous_prefix
, name
, 0, cu
);
16676 /* Create the type. */
16677 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16678 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16680 return set_die_type (die
, type
, cu
);
16683 /* Read a namespace scope. */
16686 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16688 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16691 /* Add a symbol associated to this if we haven't seen the namespace
16692 before. Also, add a using directive if it's an anonymous
16695 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16699 type
= read_type_die (die
, cu
);
16700 new_symbol (die
, type
, cu
);
16702 namespace_name (die
, &is_anonymous
, cu
);
16705 const char *previous_prefix
= determine_prefix (die
, cu
);
16707 std::vector
<const char *> excludes
;
16708 add_using_directive (using_directives (cu
->language
),
16709 previous_prefix
, TYPE_NAME (type
), NULL
,
16710 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16714 if (die
->child
!= NULL
)
16716 struct die_info
*child_die
= die
->child
;
16718 while (child_die
&& child_die
->tag
)
16720 process_die (child_die
, cu
);
16721 child_die
= sibling_die (child_die
);
16726 /* Read a Fortran module as type. This DIE can be only a declaration used for
16727 imported module. Still we need that type as local Fortran "use ... only"
16728 declaration imports depend on the created type in determine_prefix. */
16730 static struct type
*
16731 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16733 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16734 const char *module_name
;
16737 module_name
= dwarf2_name (die
, cu
);
16739 complaint (&symfile_complaints
,
16740 _("DW_TAG_module has no name, offset %s"),
16741 sect_offset_str (die
->sect_off
));
16742 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16744 /* determine_prefix uses TYPE_TAG_NAME. */
16745 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16747 return set_die_type (die
, type
, cu
);
16750 /* Read a Fortran module. */
16753 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16755 struct die_info
*child_die
= die
->child
;
16758 type
= read_type_die (die
, cu
);
16759 new_symbol (die
, type
, cu
);
16761 while (child_die
&& child_die
->tag
)
16763 process_die (child_die
, cu
);
16764 child_die
= sibling_die (child_die
);
16768 /* Return the name of the namespace represented by DIE. Set
16769 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16772 static const char *
16773 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16775 struct die_info
*current_die
;
16776 const char *name
= NULL
;
16778 /* Loop through the extensions until we find a name. */
16780 for (current_die
= die
;
16781 current_die
!= NULL
;
16782 current_die
= dwarf2_extension (die
, &cu
))
16784 /* We don't use dwarf2_name here so that we can detect the absence
16785 of a name -> anonymous namespace. */
16786 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16792 /* Is it an anonymous namespace? */
16794 *is_anonymous
= (name
== NULL
);
16796 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16801 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16802 the user defined type vector. */
16804 static struct type
*
16805 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16807 struct gdbarch
*gdbarch
16808 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16809 struct comp_unit_head
*cu_header
= &cu
->header
;
16811 struct attribute
*attr_byte_size
;
16812 struct attribute
*attr_address_class
;
16813 int byte_size
, addr_class
;
16814 struct type
*target_type
;
16816 target_type
= die_type (die
, cu
);
16818 /* The die_type call above may have already set the type for this DIE. */
16819 type
= get_die_type (die
, cu
);
16823 type
= lookup_pointer_type (target_type
);
16825 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16826 if (attr_byte_size
)
16827 byte_size
= DW_UNSND (attr_byte_size
);
16829 byte_size
= cu_header
->addr_size
;
16831 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16832 if (attr_address_class
)
16833 addr_class
= DW_UNSND (attr_address_class
);
16835 addr_class
= DW_ADDR_none
;
16837 /* If the pointer size or address class is different than the
16838 default, create a type variant marked as such and set the
16839 length accordingly. */
16840 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
16842 if (gdbarch_address_class_type_flags_p (gdbarch
))
16846 type_flags
= gdbarch_address_class_type_flags
16847 (gdbarch
, byte_size
, addr_class
);
16848 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16850 type
= make_type_with_address_space (type
, type_flags
);
16852 else if (TYPE_LENGTH (type
) != byte_size
)
16854 complaint (&symfile_complaints
,
16855 _("invalid pointer size %d"), byte_size
);
16859 /* Should we also complain about unhandled address classes? */
16863 TYPE_LENGTH (type
) = byte_size
;
16864 return set_die_type (die
, type
, cu
);
16867 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16868 the user defined type vector. */
16870 static struct type
*
16871 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16874 struct type
*to_type
;
16875 struct type
*domain
;
16877 to_type
= die_type (die
, cu
);
16878 domain
= die_containing_type (die
, cu
);
16880 /* The calls above may have already set the type for this DIE. */
16881 type
= get_die_type (die
, cu
);
16885 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16886 type
= lookup_methodptr_type (to_type
);
16887 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16889 struct type
*new_type
16890 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16892 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16893 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16894 TYPE_VARARGS (to_type
));
16895 type
= lookup_methodptr_type (new_type
);
16898 type
= lookup_memberptr_type (to_type
, domain
);
16900 return set_die_type (die
, type
, cu
);
16903 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16904 the user defined type vector. */
16906 static struct type
*
16907 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16908 enum type_code refcode
)
16910 struct comp_unit_head
*cu_header
= &cu
->header
;
16911 struct type
*type
, *target_type
;
16912 struct attribute
*attr
;
16914 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16916 target_type
= die_type (die
, cu
);
16918 /* The die_type call above may have already set the type for this DIE. */
16919 type
= get_die_type (die
, cu
);
16923 type
= lookup_reference_type (target_type
, refcode
);
16924 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16927 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16931 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16933 return set_die_type (die
, type
, cu
);
16936 /* Add the given cv-qualifiers to the element type of the array. GCC
16937 outputs DWARF type qualifiers that apply to an array, not the
16938 element type. But GDB relies on the array element type to carry
16939 the cv-qualifiers. This mimics section 6.7.3 of the C99
16942 static struct type
*
16943 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16944 struct type
*base_type
, int cnst
, int voltl
)
16946 struct type
*el_type
, *inner_array
;
16948 base_type
= copy_type (base_type
);
16949 inner_array
= base_type
;
16951 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16953 TYPE_TARGET_TYPE (inner_array
) =
16954 copy_type (TYPE_TARGET_TYPE (inner_array
));
16955 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16958 el_type
= TYPE_TARGET_TYPE (inner_array
);
16959 cnst
|= TYPE_CONST (el_type
);
16960 voltl
|= TYPE_VOLATILE (el_type
);
16961 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16963 return set_die_type (die
, base_type
, cu
);
16966 static struct type
*
16967 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16969 struct type
*base_type
, *cv_type
;
16971 base_type
= die_type (die
, cu
);
16973 /* The die_type call above may have already set the type for this DIE. */
16974 cv_type
= get_die_type (die
, cu
);
16978 /* In case the const qualifier is applied to an array type, the element type
16979 is so qualified, not the array type (section 6.7.3 of C99). */
16980 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16981 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16983 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16984 return set_die_type (die
, cv_type
, cu
);
16987 static struct type
*
16988 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16990 struct type
*base_type
, *cv_type
;
16992 base_type
= die_type (die
, cu
);
16994 /* The die_type call above may have already set the type for this DIE. */
16995 cv_type
= get_die_type (die
, cu
);
16999 /* In case the volatile qualifier is applied to an array type, the
17000 element type is so qualified, not the array type (section 6.7.3
17002 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17003 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17005 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17006 return set_die_type (die
, cv_type
, cu
);
17009 /* Handle DW_TAG_restrict_type. */
17011 static struct type
*
17012 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17014 struct type
*base_type
, *cv_type
;
17016 base_type
= die_type (die
, cu
);
17018 /* The die_type call above may have already set the type for this DIE. */
17019 cv_type
= get_die_type (die
, cu
);
17023 cv_type
= make_restrict_type (base_type
);
17024 return set_die_type (die
, cv_type
, cu
);
17027 /* Handle DW_TAG_atomic_type. */
17029 static struct type
*
17030 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17032 struct type
*base_type
, *cv_type
;
17034 base_type
= die_type (die
, cu
);
17036 /* The die_type call above may have already set the type for this DIE. */
17037 cv_type
= get_die_type (die
, cu
);
17041 cv_type
= make_atomic_type (base_type
);
17042 return set_die_type (die
, cv_type
, cu
);
17045 /* Extract all information from a DW_TAG_string_type DIE and add to
17046 the user defined type vector. It isn't really a user defined type,
17047 but it behaves like one, with other DIE's using an AT_user_def_type
17048 attribute to reference it. */
17050 static struct type
*
17051 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17053 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17054 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17055 struct type
*type
, *range_type
, *index_type
, *char_type
;
17056 struct attribute
*attr
;
17057 unsigned int length
;
17059 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17062 length
= DW_UNSND (attr
);
17066 /* Check for the DW_AT_byte_size attribute. */
17067 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17070 length
= DW_UNSND (attr
);
17078 index_type
= objfile_type (objfile
)->builtin_int
;
17079 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17080 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17081 type
= create_string_type (NULL
, char_type
, range_type
);
17083 return set_die_type (die
, type
, cu
);
17086 /* Assuming that DIE corresponds to a function, returns nonzero
17087 if the function is prototyped. */
17090 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17092 struct attribute
*attr
;
17094 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17095 if (attr
&& (DW_UNSND (attr
) != 0))
17098 /* The DWARF standard implies that the DW_AT_prototyped attribute
17099 is only meaninful for C, but the concept also extends to other
17100 languages that allow unprototyped functions (Eg: Objective C).
17101 For all other languages, assume that functions are always
17103 if (cu
->language
!= language_c
17104 && cu
->language
!= language_objc
17105 && cu
->language
!= language_opencl
)
17108 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17109 prototyped and unprototyped functions; default to prototyped,
17110 since that is more common in modern code (and RealView warns
17111 about unprototyped functions). */
17112 if (producer_is_realview (cu
->producer
))
17118 /* Handle DIES due to C code like:
17122 int (*funcp)(int a, long l);
17126 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17128 static struct type
*
17129 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17131 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17132 struct type
*type
; /* Type that this function returns. */
17133 struct type
*ftype
; /* Function that returns above type. */
17134 struct attribute
*attr
;
17136 type
= die_type (die
, cu
);
17138 /* The die_type call above may have already set the type for this DIE. */
17139 ftype
= get_die_type (die
, cu
);
17143 ftype
= lookup_function_type (type
);
17145 if (prototyped_function_p (die
, cu
))
17146 TYPE_PROTOTYPED (ftype
) = 1;
17148 /* Store the calling convention in the type if it's available in
17149 the subroutine die. Otherwise set the calling convention to
17150 the default value DW_CC_normal. */
17151 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17153 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17154 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17155 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17157 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17159 /* Record whether the function returns normally to its caller or not
17160 if the DWARF producer set that information. */
17161 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17162 if (attr
&& (DW_UNSND (attr
) != 0))
17163 TYPE_NO_RETURN (ftype
) = 1;
17165 /* We need to add the subroutine type to the die immediately so
17166 we don't infinitely recurse when dealing with parameters
17167 declared as the same subroutine type. */
17168 set_die_type (die
, ftype
, cu
);
17170 if (die
->child
!= NULL
)
17172 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17173 struct die_info
*child_die
;
17174 int nparams
, iparams
;
17176 /* Count the number of parameters.
17177 FIXME: GDB currently ignores vararg functions, but knows about
17178 vararg member functions. */
17180 child_die
= die
->child
;
17181 while (child_die
&& child_die
->tag
)
17183 if (child_die
->tag
== DW_TAG_formal_parameter
)
17185 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17186 TYPE_VARARGS (ftype
) = 1;
17187 child_die
= sibling_die (child_die
);
17190 /* Allocate storage for parameters and fill them in. */
17191 TYPE_NFIELDS (ftype
) = nparams
;
17192 TYPE_FIELDS (ftype
) = (struct field
*)
17193 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17195 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17196 even if we error out during the parameters reading below. */
17197 for (iparams
= 0; iparams
< nparams
; iparams
++)
17198 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17201 child_die
= die
->child
;
17202 while (child_die
&& child_die
->tag
)
17204 if (child_die
->tag
== DW_TAG_formal_parameter
)
17206 struct type
*arg_type
;
17208 /* DWARF version 2 has no clean way to discern C++
17209 static and non-static member functions. G++ helps
17210 GDB by marking the first parameter for non-static
17211 member functions (which is the this pointer) as
17212 artificial. We pass this information to
17213 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17215 DWARF version 3 added DW_AT_object_pointer, which GCC
17216 4.5 does not yet generate. */
17217 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17219 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17221 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17222 arg_type
= die_type (child_die
, cu
);
17224 /* RealView does not mark THIS as const, which the testsuite
17225 expects. GCC marks THIS as const in method definitions,
17226 but not in the class specifications (GCC PR 43053). */
17227 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17228 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17231 struct dwarf2_cu
*arg_cu
= cu
;
17232 const char *name
= dwarf2_name (child_die
, cu
);
17234 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17237 /* If the compiler emits this, use it. */
17238 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17241 else if (name
&& strcmp (name
, "this") == 0)
17242 /* Function definitions will have the argument names. */
17244 else if (name
== NULL
&& iparams
== 0)
17245 /* Declarations may not have the names, so like
17246 elsewhere in GDB, assume an artificial first
17247 argument is "this". */
17251 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17255 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17258 child_die
= sibling_die (child_die
);
17265 static struct type
*
17266 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17268 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17269 const char *name
= NULL
;
17270 struct type
*this_type
, *target_type
;
17272 name
= dwarf2_full_name (NULL
, die
, cu
);
17273 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17274 TYPE_TARGET_STUB (this_type
) = 1;
17275 set_die_type (die
, this_type
, cu
);
17276 target_type
= die_type (die
, cu
);
17277 if (target_type
!= this_type
)
17278 TYPE_TARGET_TYPE (this_type
) = target_type
;
17281 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17282 spec and cause infinite loops in GDB. */
17283 complaint (&symfile_complaints
,
17284 _("Self-referential DW_TAG_typedef "
17285 "- DIE at %s [in module %s]"),
17286 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17287 TYPE_TARGET_TYPE (this_type
) = NULL
;
17292 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17293 (which may be different from NAME) to the architecture back-end to allow
17294 it to guess the correct format if necessary. */
17296 static struct type
*
17297 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17298 const char *name_hint
)
17300 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17301 const struct floatformat
**format
;
17304 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17306 type
= init_float_type (objfile
, bits
, name
, format
);
17308 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17313 /* Find a representation of a given base type and install
17314 it in the TYPE field of the die. */
17316 static struct type
*
17317 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17319 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17321 struct attribute
*attr
;
17322 int encoding
= 0, bits
= 0;
17325 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17328 encoding
= DW_UNSND (attr
);
17330 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17333 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17335 name
= dwarf2_name (die
, cu
);
17338 complaint (&symfile_complaints
,
17339 _("DW_AT_name missing from DW_TAG_base_type"));
17344 case DW_ATE_address
:
17345 /* Turn DW_ATE_address into a void * pointer. */
17346 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17347 type
= init_pointer_type (objfile
, bits
, name
, type
);
17349 case DW_ATE_boolean
:
17350 type
= init_boolean_type (objfile
, bits
, 1, name
);
17352 case DW_ATE_complex_float
:
17353 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
17354 type
= init_complex_type (objfile
, name
, type
);
17356 case DW_ATE_decimal_float
:
17357 type
= init_decfloat_type (objfile
, bits
, name
);
17360 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17362 case DW_ATE_signed
:
17363 type
= init_integer_type (objfile
, bits
, 0, name
);
17365 case DW_ATE_unsigned
:
17366 if (cu
->language
== language_fortran
17368 && startswith (name
, "character("))
17369 type
= init_character_type (objfile
, bits
, 1, name
);
17371 type
= init_integer_type (objfile
, bits
, 1, name
);
17373 case DW_ATE_signed_char
:
17374 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17375 || cu
->language
== language_pascal
17376 || cu
->language
== language_fortran
)
17377 type
= init_character_type (objfile
, bits
, 0, name
);
17379 type
= init_integer_type (objfile
, bits
, 0, name
);
17381 case DW_ATE_unsigned_char
:
17382 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17383 || cu
->language
== language_pascal
17384 || cu
->language
== language_fortran
17385 || cu
->language
== language_rust
)
17386 type
= init_character_type (objfile
, bits
, 1, name
);
17388 type
= init_integer_type (objfile
, bits
, 1, name
);
17392 gdbarch
*arch
= get_objfile_arch (objfile
);
17395 type
= builtin_type (arch
)->builtin_char16
;
17396 else if (bits
== 32)
17397 type
= builtin_type (arch
)->builtin_char32
;
17400 complaint (&symfile_complaints
,
17401 _("unsupported DW_ATE_UTF bit size: '%d'"),
17403 type
= init_integer_type (objfile
, bits
, 1, name
);
17405 return set_die_type (die
, type
, cu
);
17410 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
17411 dwarf_type_encoding_name (encoding
));
17412 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17416 if (name
&& strcmp (name
, "char") == 0)
17417 TYPE_NOSIGN (type
) = 1;
17419 return set_die_type (die
, type
, cu
);
17422 /* Parse dwarf attribute if it's a block, reference or constant and put the
17423 resulting value of the attribute into struct bound_prop.
17424 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17427 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17428 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
17430 struct dwarf2_property_baton
*baton
;
17431 struct obstack
*obstack
17432 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17434 if (attr
== NULL
|| prop
== NULL
)
17437 if (attr_form_is_block (attr
))
17439 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17440 baton
->referenced_type
= NULL
;
17441 baton
->locexpr
.per_cu
= cu
->per_cu
;
17442 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17443 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17444 prop
->data
.baton
= baton
;
17445 prop
->kind
= PROP_LOCEXPR
;
17446 gdb_assert (prop
->data
.baton
!= NULL
);
17448 else if (attr_form_is_ref (attr
))
17450 struct dwarf2_cu
*target_cu
= cu
;
17451 struct die_info
*target_die
;
17452 struct attribute
*target_attr
;
17454 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17455 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17456 if (target_attr
== NULL
)
17457 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17459 if (target_attr
== NULL
)
17462 switch (target_attr
->name
)
17464 case DW_AT_location
:
17465 if (attr_form_is_section_offset (target_attr
))
17467 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17468 baton
->referenced_type
= die_type (target_die
, target_cu
);
17469 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17470 prop
->data
.baton
= baton
;
17471 prop
->kind
= PROP_LOCLIST
;
17472 gdb_assert (prop
->data
.baton
!= NULL
);
17474 else if (attr_form_is_block (target_attr
))
17476 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17477 baton
->referenced_type
= die_type (target_die
, target_cu
);
17478 baton
->locexpr
.per_cu
= cu
->per_cu
;
17479 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17480 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17481 prop
->data
.baton
= baton
;
17482 prop
->kind
= PROP_LOCEXPR
;
17483 gdb_assert (prop
->data
.baton
!= NULL
);
17487 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17488 "dynamic property");
17492 case DW_AT_data_member_location
:
17496 if (!handle_data_member_location (target_die
, target_cu
,
17500 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17501 baton
->referenced_type
= read_type_die (target_die
->parent
,
17503 baton
->offset_info
.offset
= offset
;
17504 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17505 prop
->data
.baton
= baton
;
17506 prop
->kind
= PROP_ADDR_OFFSET
;
17511 else if (attr_form_is_constant (attr
))
17513 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17514 prop
->kind
= PROP_CONST
;
17518 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17519 dwarf2_name (die
, cu
));
17526 /* Read the given DW_AT_subrange DIE. */
17528 static struct type
*
17529 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17531 struct type
*base_type
, *orig_base_type
;
17532 struct type
*range_type
;
17533 struct attribute
*attr
;
17534 struct dynamic_prop low
, high
;
17535 int low_default_is_valid
;
17536 int high_bound_is_count
= 0;
17538 LONGEST negative_mask
;
17540 orig_base_type
= die_type (die
, cu
);
17541 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17542 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17543 creating the range type, but we use the result of check_typedef
17544 when examining properties of the type. */
17545 base_type
= check_typedef (orig_base_type
);
17547 /* The die_type call above may have already set the type for this DIE. */
17548 range_type
= get_die_type (die
, cu
);
17552 low
.kind
= PROP_CONST
;
17553 high
.kind
= PROP_CONST
;
17554 high
.data
.const_val
= 0;
17556 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17557 omitting DW_AT_lower_bound. */
17558 switch (cu
->language
)
17561 case language_cplus
:
17562 low
.data
.const_val
= 0;
17563 low_default_is_valid
= 1;
17565 case language_fortran
:
17566 low
.data
.const_val
= 1;
17567 low_default_is_valid
= 1;
17570 case language_objc
:
17571 case language_rust
:
17572 low
.data
.const_val
= 0;
17573 low_default_is_valid
= (cu
->header
.version
>= 4);
17577 case language_pascal
:
17578 low
.data
.const_val
= 1;
17579 low_default_is_valid
= (cu
->header
.version
>= 4);
17582 low
.data
.const_val
= 0;
17583 low_default_is_valid
= 0;
17587 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17589 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
17590 else if (!low_default_is_valid
)
17591 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
17592 "- DIE at %s [in module %s]"),
17593 sect_offset_str (die
->sect_off
),
17594 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17596 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17597 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17599 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
17600 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17602 /* If bounds are constant do the final calculation here. */
17603 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17604 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17606 high_bound_is_count
= 1;
17610 /* Dwarf-2 specifications explicitly allows to create subrange types
17611 without specifying a base type.
17612 In that case, the base type must be set to the type of
17613 the lower bound, upper bound or count, in that order, if any of these
17614 three attributes references an object that has a type.
17615 If no base type is found, the Dwarf-2 specifications say that
17616 a signed integer type of size equal to the size of an address should
17618 For the following C code: `extern char gdb_int [];'
17619 GCC produces an empty range DIE.
17620 FIXME: muller/2010-05-28: Possible references to object for low bound,
17621 high bound or count are not yet handled by this code. */
17622 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
17624 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17625 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17626 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
17627 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
17629 /* Test "int", "long int", and "long long int" objfile types,
17630 and select the first one having a size above or equal to the
17631 architecture address size. */
17632 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17633 base_type
= int_type
;
17636 int_type
= objfile_type (objfile
)->builtin_long
;
17637 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17638 base_type
= int_type
;
17641 int_type
= objfile_type (objfile
)->builtin_long_long
;
17642 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17643 base_type
= int_type
;
17648 /* Normally, the DWARF producers are expected to use a signed
17649 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17650 But this is unfortunately not always the case, as witnessed
17651 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17652 is used instead. To work around that ambiguity, we treat
17653 the bounds as signed, and thus sign-extend their values, when
17654 the base type is signed. */
17656 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17657 if (low
.kind
== PROP_CONST
17658 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17659 low
.data
.const_val
|= negative_mask
;
17660 if (high
.kind
== PROP_CONST
17661 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17662 high
.data
.const_val
|= negative_mask
;
17664 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
17666 if (high_bound_is_count
)
17667 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17669 /* Ada expects an empty array on no boundary attributes. */
17670 if (attr
== NULL
&& cu
->language
!= language_ada
)
17671 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17673 name
= dwarf2_name (die
, cu
);
17675 TYPE_NAME (range_type
) = name
;
17677 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17679 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17681 set_die_type (die
, range_type
, cu
);
17683 /* set_die_type should be already done. */
17684 set_descriptive_type (range_type
, die
, cu
);
17689 static struct type
*
17690 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17694 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17696 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17698 /* In Ada, an unspecified type is typically used when the description
17699 of the type is defered to a different unit. When encountering
17700 such a type, we treat it as a stub, and try to resolve it later on,
17702 if (cu
->language
== language_ada
)
17703 TYPE_STUB (type
) = 1;
17705 return set_die_type (die
, type
, cu
);
17708 /* Read a single die and all its descendents. Set the die's sibling
17709 field to NULL; set other fields in the die correctly, and set all
17710 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17711 location of the info_ptr after reading all of those dies. PARENT
17712 is the parent of the die in question. */
17714 static struct die_info
*
17715 read_die_and_children (const struct die_reader_specs
*reader
,
17716 const gdb_byte
*info_ptr
,
17717 const gdb_byte
**new_info_ptr
,
17718 struct die_info
*parent
)
17720 struct die_info
*die
;
17721 const gdb_byte
*cur_ptr
;
17724 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
17727 *new_info_ptr
= cur_ptr
;
17730 store_in_ref_table (die
, reader
->cu
);
17733 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17737 *new_info_ptr
= cur_ptr
;
17740 die
->sibling
= NULL
;
17741 die
->parent
= parent
;
17745 /* Read a die, all of its descendents, and all of its siblings; set
17746 all of the fields of all of the dies correctly. Arguments are as
17747 in read_die_and_children. */
17749 static struct die_info
*
17750 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17751 const gdb_byte
*info_ptr
,
17752 const gdb_byte
**new_info_ptr
,
17753 struct die_info
*parent
)
17755 struct die_info
*first_die
, *last_sibling
;
17756 const gdb_byte
*cur_ptr
;
17758 cur_ptr
= info_ptr
;
17759 first_die
= last_sibling
= NULL
;
17763 struct die_info
*die
17764 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17768 *new_info_ptr
= cur_ptr
;
17775 last_sibling
->sibling
= die
;
17777 last_sibling
= die
;
17781 /* Read a die, all of its descendents, and all of its siblings; set
17782 all of the fields of all of the dies correctly. Arguments are as
17783 in read_die_and_children.
17784 This the main entry point for reading a DIE and all its children. */
17786 static struct die_info
*
17787 read_die_and_siblings (const struct die_reader_specs
*reader
,
17788 const gdb_byte
*info_ptr
,
17789 const gdb_byte
**new_info_ptr
,
17790 struct die_info
*parent
)
17792 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17793 new_info_ptr
, parent
);
17795 if (dwarf_die_debug
)
17797 fprintf_unfiltered (gdb_stdlog
,
17798 "Read die from %s@0x%x of %s:\n",
17799 get_section_name (reader
->die_section
),
17800 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17801 bfd_get_filename (reader
->abfd
));
17802 dump_die (die
, dwarf_die_debug
);
17808 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17810 The caller is responsible for filling in the extra attributes
17811 and updating (*DIEP)->num_attrs.
17812 Set DIEP to point to a newly allocated die with its information,
17813 except for its child, sibling, and parent fields.
17814 Set HAS_CHILDREN to tell whether the die has children or not. */
17816 static const gdb_byte
*
17817 read_full_die_1 (const struct die_reader_specs
*reader
,
17818 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17819 int *has_children
, int num_extra_attrs
)
17821 unsigned int abbrev_number
, bytes_read
, i
;
17822 struct abbrev_info
*abbrev
;
17823 struct die_info
*die
;
17824 struct dwarf2_cu
*cu
= reader
->cu
;
17825 bfd
*abfd
= reader
->abfd
;
17827 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17828 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17829 info_ptr
+= bytes_read
;
17830 if (!abbrev_number
)
17837 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17839 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17841 bfd_get_filename (abfd
));
17843 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17844 die
->sect_off
= sect_off
;
17845 die
->tag
= abbrev
->tag
;
17846 die
->abbrev
= abbrev_number
;
17848 /* Make the result usable.
17849 The caller needs to update num_attrs after adding the extra
17851 die
->num_attrs
= abbrev
->num_attrs
;
17853 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17854 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17858 *has_children
= abbrev
->has_children
;
17862 /* Read a die and all its attributes.
17863 Set DIEP to point to a newly allocated die with its information,
17864 except for its child, sibling, and parent fields.
17865 Set HAS_CHILDREN to tell whether the die has children or not. */
17867 static const gdb_byte
*
17868 read_full_die (const struct die_reader_specs
*reader
,
17869 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17872 const gdb_byte
*result
;
17874 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
17876 if (dwarf_die_debug
)
17878 fprintf_unfiltered (gdb_stdlog
,
17879 "Read die from %s@0x%x of %s:\n",
17880 get_section_name (reader
->die_section
),
17881 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17882 bfd_get_filename (reader
->abfd
));
17883 dump_die (*diep
, dwarf_die_debug
);
17889 /* Abbreviation tables.
17891 In DWARF version 2, the description of the debugging information is
17892 stored in a separate .debug_abbrev section. Before we read any
17893 dies from a section we read in all abbreviations and install them
17894 in a hash table. */
17896 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
17898 struct abbrev_info
*
17899 abbrev_table::alloc_abbrev ()
17901 struct abbrev_info
*abbrev
;
17903 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
17904 memset (abbrev
, 0, sizeof (struct abbrev_info
));
17909 /* Add an abbreviation to the table. */
17912 abbrev_table::add_abbrev (unsigned int abbrev_number
,
17913 struct abbrev_info
*abbrev
)
17915 unsigned int hash_number
;
17917 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
17918 abbrev
->next
= m_abbrevs
[hash_number
];
17919 m_abbrevs
[hash_number
] = abbrev
;
17922 /* Look up an abbrev in the table.
17923 Returns NULL if the abbrev is not found. */
17925 struct abbrev_info
*
17926 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
17928 unsigned int hash_number
;
17929 struct abbrev_info
*abbrev
;
17931 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
17932 abbrev
= m_abbrevs
[hash_number
];
17936 if (abbrev
->number
== abbrev_number
)
17938 abbrev
= abbrev
->next
;
17943 /* Read in an abbrev table. */
17945 static abbrev_table_up
17946 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
17947 struct dwarf2_section_info
*section
,
17948 sect_offset sect_off
)
17950 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17951 bfd
*abfd
= get_section_bfd_owner (section
);
17952 const gdb_byte
*abbrev_ptr
;
17953 struct abbrev_info
*cur_abbrev
;
17954 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
17955 unsigned int abbrev_form
;
17956 struct attr_abbrev
*cur_attrs
;
17957 unsigned int allocated_attrs
;
17959 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
17961 dwarf2_read_section (objfile
, section
);
17962 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
17963 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
17964 abbrev_ptr
+= bytes_read
;
17966 allocated_attrs
= ATTR_ALLOC_CHUNK
;
17967 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
17969 /* Loop until we reach an abbrev number of 0. */
17970 while (abbrev_number
)
17972 cur_abbrev
= abbrev_table
->alloc_abbrev ();
17974 /* read in abbrev header */
17975 cur_abbrev
->number
= abbrev_number
;
17977 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
17978 abbrev_ptr
+= bytes_read
;
17979 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
17982 /* now read in declarations */
17985 LONGEST implicit_const
;
17987 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
17988 abbrev_ptr
+= bytes_read
;
17989 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
17990 abbrev_ptr
+= bytes_read
;
17991 if (abbrev_form
== DW_FORM_implicit_const
)
17993 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
17995 abbrev_ptr
+= bytes_read
;
17999 /* Initialize it due to a false compiler warning. */
18000 implicit_const
= -1;
18003 if (abbrev_name
== 0)
18006 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18008 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18010 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18013 cur_attrs
[cur_abbrev
->num_attrs
].name
18014 = (enum dwarf_attribute
) abbrev_name
;
18015 cur_attrs
[cur_abbrev
->num_attrs
].form
18016 = (enum dwarf_form
) abbrev_form
;
18017 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18018 ++cur_abbrev
->num_attrs
;
18021 cur_abbrev
->attrs
=
18022 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18023 cur_abbrev
->num_attrs
);
18024 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18025 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18027 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18029 /* Get next abbreviation.
18030 Under Irix6 the abbreviations for a compilation unit are not
18031 always properly terminated with an abbrev number of 0.
18032 Exit loop if we encounter an abbreviation which we have
18033 already read (which means we are about to read the abbreviations
18034 for the next compile unit) or if the end of the abbreviation
18035 table is reached. */
18036 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18038 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18039 abbrev_ptr
+= bytes_read
;
18040 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18045 return abbrev_table
;
18048 /* Returns nonzero if TAG represents a type that we might generate a partial
18052 is_type_tag_for_partial (int tag
)
18057 /* Some types that would be reasonable to generate partial symbols for,
18058 that we don't at present. */
18059 case DW_TAG_array_type
:
18060 case DW_TAG_file_type
:
18061 case DW_TAG_ptr_to_member_type
:
18062 case DW_TAG_set_type
:
18063 case DW_TAG_string_type
:
18064 case DW_TAG_subroutine_type
:
18066 case DW_TAG_base_type
:
18067 case DW_TAG_class_type
:
18068 case DW_TAG_interface_type
:
18069 case DW_TAG_enumeration_type
:
18070 case DW_TAG_structure_type
:
18071 case DW_TAG_subrange_type
:
18072 case DW_TAG_typedef
:
18073 case DW_TAG_union_type
:
18080 /* Load all DIEs that are interesting for partial symbols into memory. */
18082 static struct partial_die_info
*
18083 load_partial_dies (const struct die_reader_specs
*reader
,
18084 const gdb_byte
*info_ptr
, int building_psymtab
)
18086 struct dwarf2_cu
*cu
= reader
->cu
;
18087 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18088 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18089 unsigned int bytes_read
;
18090 unsigned int load_all
= 0;
18091 int nesting_level
= 1;
18096 gdb_assert (cu
->per_cu
!= NULL
);
18097 if (cu
->per_cu
->load_all_dies
)
18101 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18105 &cu
->comp_unit_obstack
,
18106 hashtab_obstack_allocate
,
18107 dummy_obstack_deallocate
);
18111 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18113 /* A NULL abbrev means the end of a series of children. */
18114 if (abbrev
== NULL
)
18116 if (--nesting_level
== 0)
18119 info_ptr
+= bytes_read
;
18120 last_die
= parent_die
;
18121 parent_die
= parent_die
->die_parent
;
18125 /* Check for template arguments. We never save these; if
18126 they're seen, we just mark the parent, and go on our way. */
18127 if (parent_die
!= NULL
18128 && cu
->language
== language_cplus
18129 && (abbrev
->tag
== DW_TAG_template_type_param
18130 || abbrev
->tag
== DW_TAG_template_value_param
))
18132 parent_die
->has_template_arguments
= 1;
18136 /* We don't need a partial DIE for the template argument. */
18137 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18142 /* We only recurse into c++ subprograms looking for template arguments.
18143 Skip their other children. */
18145 && cu
->language
== language_cplus
18146 && parent_die
!= NULL
18147 && parent_die
->tag
== DW_TAG_subprogram
)
18149 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18153 /* Check whether this DIE is interesting enough to save. Normally
18154 we would not be interested in members here, but there may be
18155 later variables referencing them via DW_AT_specification (for
18156 static members). */
18158 && !is_type_tag_for_partial (abbrev
->tag
)
18159 && abbrev
->tag
!= DW_TAG_constant
18160 && abbrev
->tag
!= DW_TAG_enumerator
18161 && abbrev
->tag
!= DW_TAG_subprogram
18162 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18163 && abbrev
->tag
!= DW_TAG_lexical_block
18164 && abbrev
->tag
!= DW_TAG_variable
18165 && abbrev
->tag
!= DW_TAG_namespace
18166 && abbrev
->tag
!= DW_TAG_module
18167 && abbrev
->tag
!= DW_TAG_member
18168 && abbrev
->tag
!= DW_TAG_imported_unit
18169 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18171 /* Otherwise we skip to the next sibling, if any. */
18172 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18176 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18179 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18181 /* This two-pass algorithm for processing partial symbols has a
18182 high cost in cache pressure. Thus, handle some simple cases
18183 here which cover the majority of C partial symbols. DIEs
18184 which neither have specification tags in them, nor could have
18185 specification tags elsewhere pointing at them, can simply be
18186 processed and discarded.
18188 This segment is also optional; scan_partial_symbols and
18189 add_partial_symbol will handle these DIEs if we chain
18190 them in normally. When compilers which do not emit large
18191 quantities of duplicate debug information are more common,
18192 this code can probably be removed. */
18194 /* Any complete simple types at the top level (pretty much all
18195 of them, for a language without namespaces), can be processed
18197 if (parent_die
== NULL
18198 && pdi
.has_specification
== 0
18199 && pdi
.is_declaration
== 0
18200 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18201 || pdi
.tag
== DW_TAG_base_type
18202 || pdi
.tag
== DW_TAG_subrange_type
))
18204 if (building_psymtab
&& pdi
.name
!= NULL
)
18205 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18206 VAR_DOMAIN
, LOC_TYPEDEF
,
18207 &objfile
->static_psymbols
,
18208 0, cu
->language
, objfile
);
18209 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18213 /* The exception for DW_TAG_typedef with has_children above is
18214 a workaround of GCC PR debug/47510. In the case of this complaint
18215 type_name_no_tag_or_error will error on such types later.
18217 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18218 it could not find the child DIEs referenced later, this is checked
18219 above. In correct DWARF DW_TAG_typedef should have no children. */
18221 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18222 complaint (&symfile_complaints
,
18223 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18224 "- DIE at %s [in module %s]"),
18225 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18227 /* If we're at the second level, and we're an enumerator, and
18228 our parent has no specification (meaning possibly lives in a
18229 namespace elsewhere), then we can add the partial symbol now
18230 instead of queueing it. */
18231 if (pdi
.tag
== DW_TAG_enumerator
18232 && parent_die
!= NULL
18233 && parent_die
->die_parent
== NULL
18234 && parent_die
->tag
== DW_TAG_enumeration_type
18235 && parent_die
->has_specification
== 0)
18237 if (pdi
.name
== NULL
)
18238 complaint (&symfile_complaints
,
18239 _("malformed enumerator DIE ignored"));
18240 else if (building_psymtab
)
18241 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18242 VAR_DOMAIN
, LOC_CONST
,
18243 cu
->language
== language_cplus
18244 ? &objfile
->global_psymbols
18245 : &objfile
->static_psymbols
,
18246 0, cu
->language
, objfile
);
18248 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18252 struct partial_die_info
*part_die
18253 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18255 /* We'll save this DIE so link it in. */
18256 part_die
->die_parent
= parent_die
;
18257 part_die
->die_sibling
= NULL
;
18258 part_die
->die_child
= NULL
;
18260 if (last_die
&& last_die
== parent_die
)
18261 last_die
->die_child
= part_die
;
18263 last_die
->die_sibling
= part_die
;
18265 last_die
= part_die
;
18267 if (first_die
== NULL
)
18268 first_die
= part_die
;
18270 /* Maybe add the DIE to the hash table. Not all DIEs that we
18271 find interesting need to be in the hash table, because we
18272 also have the parent/sibling/child chains; only those that we
18273 might refer to by offset later during partial symbol reading.
18275 For now this means things that might have be the target of a
18276 DW_AT_specification, DW_AT_abstract_origin, or
18277 DW_AT_extension. DW_AT_extension will refer only to
18278 namespaces; DW_AT_abstract_origin refers to functions (and
18279 many things under the function DIE, but we do not recurse
18280 into function DIEs during partial symbol reading) and
18281 possibly variables as well; DW_AT_specification refers to
18282 declarations. Declarations ought to have the DW_AT_declaration
18283 flag. It happens that GCC forgets to put it in sometimes, but
18284 only for functions, not for types.
18286 Adding more things than necessary to the hash table is harmless
18287 except for the performance cost. Adding too few will result in
18288 wasted time in find_partial_die, when we reread the compilation
18289 unit with load_all_dies set. */
18292 || abbrev
->tag
== DW_TAG_constant
18293 || abbrev
->tag
== DW_TAG_subprogram
18294 || abbrev
->tag
== DW_TAG_variable
18295 || abbrev
->tag
== DW_TAG_namespace
18296 || part_die
->is_declaration
)
18300 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18301 to_underlying (part_die
->sect_off
),
18306 /* For some DIEs we want to follow their children (if any). For C
18307 we have no reason to follow the children of structures; for other
18308 languages we have to, so that we can get at method physnames
18309 to infer fully qualified class names, for DW_AT_specification,
18310 and for C++ template arguments. For C++, we also look one level
18311 inside functions to find template arguments (if the name of the
18312 function does not already contain the template arguments).
18314 For Ada, we need to scan the children of subprograms and lexical
18315 blocks as well because Ada allows the definition of nested
18316 entities that could be interesting for the debugger, such as
18317 nested subprograms for instance. */
18318 if (last_die
->has_children
18320 || last_die
->tag
== DW_TAG_namespace
18321 || last_die
->tag
== DW_TAG_module
18322 || last_die
->tag
== DW_TAG_enumeration_type
18323 || (cu
->language
== language_cplus
18324 && last_die
->tag
== DW_TAG_subprogram
18325 && (last_die
->name
== NULL
18326 || strchr (last_die
->name
, '<') == NULL
))
18327 || (cu
->language
!= language_c
18328 && (last_die
->tag
== DW_TAG_class_type
18329 || last_die
->tag
== DW_TAG_interface_type
18330 || last_die
->tag
== DW_TAG_structure_type
18331 || last_die
->tag
== DW_TAG_union_type
))
18332 || (cu
->language
== language_ada
18333 && (last_die
->tag
== DW_TAG_subprogram
18334 || last_die
->tag
== DW_TAG_lexical_block
))))
18337 parent_die
= last_die
;
18341 /* Otherwise we skip to the next sibling, if any. */
18342 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18344 /* Back to the top, do it again. */
18348 partial_die_info::partial_die_info (sect_offset sect_off_
,
18349 struct abbrev_info
*abbrev
)
18350 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18354 /* Read a minimal amount of information into the minimal die structure.
18355 INFO_PTR should point just after the initial uleb128 of a DIE. */
18358 partial_die_info::read (const struct die_reader_specs
*reader
,
18359 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18361 struct dwarf2_cu
*cu
= reader
->cu
;
18362 struct dwarf2_per_objfile
*dwarf2_per_objfile
18363 = cu
->per_cu
->dwarf2_per_objfile
;
18365 int has_low_pc_attr
= 0;
18366 int has_high_pc_attr
= 0;
18367 int high_pc_relative
= 0;
18369 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18371 struct attribute attr
;
18373 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18375 /* Store the data if it is of an attribute we want to keep in a
18376 partial symbol table. */
18382 case DW_TAG_compile_unit
:
18383 case DW_TAG_partial_unit
:
18384 case DW_TAG_type_unit
:
18385 /* Compilation units have a DW_AT_name that is a filename, not
18386 a source language identifier. */
18387 case DW_TAG_enumeration_type
:
18388 case DW_TAG_enumerator
:
18389 /* These tags always have simple identifiers already; no need
18390 to canonicalize them. */
18391 name
= DW_STRING (&attr
);
18395 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18398 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18399 &objfile
->per_bfd
->storage_obstack
);
18404 case DW_AT_linkage_name
:
18405 case DW_AT_MIPS_linkage_name
:
18406 /* Note that both forms of linkage name might appear. We
18407 assume they will be the same, and we only store the last
18409 if (cu
->language
== language_ada
)
18410 name
= DW_STRING (&attr
);
18411 linkage_name
= DW_STRING (&attr
);
18414 has_low_pc_attr
= 1;
18415 lowpc
= attr_value_as_address (&attr
);
18417 case DW_AT_high_pc
:
18418 has_high_pc_attr
= 1;
18419 highpc
= attr_value_as_address (&attr
);
18420 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18421 high_pc_relative
= 1;
18423 case DW_AT_location
:
18424 /* Support the .debug_loc offsets. */
18425 if (attr_form_is_block (&attr
))
18427 d
.locdesc
= DW_BLOCK (&attr
);
18429 else if (attr_form_is_section_offset (&attr
))
18431 dwarf2_complex_location_expr_complaint ();
18435 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18436 "partial symbol information");
18439 case DW_AT_external
:
18440 is_external
= DW_UNSND (&attr
);
18442 case DW_AT_declaration
:
18443 is_declaration
= DW_UNSND (&attr
);
18448 case DW_AT_abstract_origin
:
18449 case DW_AT_specification
:
18450 case DW_AT_extension
:
18451 has_specification
= 1;
18452 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18453 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18454 || cu
->per_cu
->is_dwz
);
18456 case DW_AT_sibling
:
18457 /* Ignore absolute siblings, they might point outside of
18458 the current compile unit. */
18459 if (attr
.form
== DW_FORM_ref_addr
)
18460 complaint (&symfile_complaints
,
18461 _("ignoring absolute DW_AT_sibling"));
18464 const gdb_byte
*buffer
= reader
->buffer
;
18465 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18466 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18468 if (sibling_ptr
< info_ptr
)
18469 complaint (&symfile_complaints
,
18470 _("DW_AT_sibling points backwards"));
18471 else if (sibling_ptr
> reader
->buffer_end
)
18472 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18474 sibling
= sibling_ptr
;
18477 case DW_AT_byte_size
:
18480 case DW_AT_const_value
:
18481 has_const_value
= 1;
18483 case DW_AT_calling_convention
:
18484 /* DWARF doesn't provide a way to identify a program's source-level
18485 entry point. DW_AT_calling_convention attributes are only meant
18486 to describe functions' calling conventions.
18488 However, because it's a necessary piece of information in
18489 Fortran, and before DWARF 4 DW_CC_program was the only
18490 piece of debugging information whose definition refers to
18491 a 'main program' at all, several compilers marked Fortran
18492 main programs with DW_CC_program --- even when those
18493 functions use the standard calling conventions.
18495 Although DWARF now specifies a way to provide this
18496 information, we support this practice for backward
18498 if (DW_UNSND (&attr
) == DW_CC_program
18499 && cu
->language
== language_fortran
)
18500 main_subprogram
= 1;
18503 if (DW_UNSND (&attr
) == DW_INL_inlined
18504 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18505 may_be_inlined
= 1;
18509 if (tag
== DW_TAG_imported_unit
)
18511 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18512 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18513 || cu
->per_cu
->is_dwz
);
18517 case DW_AT_main_subprogram
:
18518 main_subprogram
= DW_UNSND (&attr
);
18526 if (high_pc_relative
)
18529 if (has_low_pc_attr
&& has_high_pc_attr
)
18531 /* When using the GNU linker, .gnu.linkonce. sections are used to
18532 eliminate duplicate copies of functions and vtables and such.
18533 The linker will arbitrarily choose one and discard the others.
18534 The AT_*_pc values for such functions refer to local labels in
18535 these sections. If the section from that file was discarded, the
18536 labels are not in the output, so the relocs get a value of 0.
18537 If this is a discarded function, mark the pc bounds as invalid,
18538 so that GDB will ignore it. */
18539 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18541 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18542 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18544 complaint (&symfile_complaints
,
18545 _("DW_AT_low_pc %s is zero "
18546 "for DIE at %s [in module %s]"),
18547 paddress (gdbarch
, lowpc
),
18548 sect_offset_str (sect_off
),
18549 objfile_name (objfile
));
18551 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18552 else if (lowpc
>= highpc
)
18554 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18555 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18557 complaint (&symfile_complaints
,
18558 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18559 "for DIE at %s [in module %s]"),
18560 paddress (gdbarch
, lowpc
),
18561 paddress (gdbarch
, highpc
),
18562 sect_offset_str (sect_off
),
18563 objfile_name (objfile
));
18572 /* Find a cached partial DIE at OFFSET in CU. */
18574 struct partial_die_info
*
18575 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18577 struct partial_die_info
*lookup_die
= NULL
;
18578 struct partial_die_info
part_die (sect_off
);
18580 lookup_die
= ((struct partial_die_info
*)
18581 htab_find_with_hash (partial_dies
, &part_die
,
18582 to_underlying (sect_off
)));
18587 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18588 except in the case of .debug_types DIEs which do not reference
18589 outside their CU (they do however referencing other types via
18590 DW_FORM_ref_sig8). */
18592 static struct partial_die_info
*
18593 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18595 struct dwarf2_per_objfile
*dwarf2_per_objfile
18596 = cu
->per_cu
->dwarf2_per_objfile
;
18597 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18598 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18599 struct partial_die_info
*pd
= NULL
;
18601 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18602 && offset_in_cu_p (&cu
->header
, sect_off
))
18604 pd
= cu
->find_partial_die (sect_off
);
18607 /* We missed recording what we needed.
18608 Load all dies and try again. */
18609 per_cu
= cu
->per_cu
;
18613 /* TUs don't reference other CUs/TUs (except via type signatures). */
18614 if (cu
->per_cu
->is_debug_types
)
18616 error (_("Dwarf Error: Type Unit at offset %s contains"
18617 " external reference to offset %s [in module %s].\n"),
18618 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18619 bfd_get_filename (objfile
->obfd
));
18621 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18622 dwarf2_per_objfile
);
18624 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18625 load_partial_comp_unit (per_cu
);
18627 per_cu
->cu
->last_used
= 0;
18628 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18631 /* If we didn't find it, and not all dies have been loaded,
18632 load them all and try again. */
18634 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18636 per_cu
->load_all_dies
= 1;
18638 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18639 THIS_CU->cu may already be in use. So we can't just free it and
18640 replace its DIEs with the ones we read in. Instead, we leave those
18641 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18642 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18644 load_partial_comp_unit (per_cu
);
18646 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18650 internal_error (__FILE__
, __LINE__
,
18651 _("could not find partial DIE %s "
18652 "in cache [from module %s]\n"),
18653 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18657 /* See if we can figure out if the class lives in a namespace. We do
18658 this by looking for a member function; its demangled name will
18659 contain namespace info, if there is any. */
18662 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18663 struct dwarf2_cu
*cu
)
18665 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18666 what template types look like, because the demangler
18667 frequently doesn't give the same name as the debug info. We
18668 could fix this by only using the demangled name to get the
18669 prefix (but see comment in read_structure_type). */
18671 struct partial_die_info
*real_pdi
;
18672 struct partial_die_info
*child_pdi
;
18674 /* If this DIE (this DIE's specification, if any) has a parent, then
18675 we should not do this. We'll prepend the parent's fully qualified
18676 name when we create the partial symbol. */
18678 real_pdi
= struct_pdi
;
18679 while (real_pdi
->has_specification
)
18680 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
18681 real_pdi
->spec_is_dwz
, cu
);
18683 if (real_pdi
->die_parent
!= NULL
)
18686 for (child_pdi
= struct_pdi
->die_child
;
18688 child_pdi
= child_pdi
->die_sibling
)
18690 if (child_pdi
->tag
== DW_TAG_subprogram
18691 && child_pdi
->linkage_name
!= NULL
)
18693 char *actual_class_name
18694 = language_class_name_from_physname (cu
->language_defn
,
18695 child_pdi
->linkage_name
);
18696 if (actual_class_name
!= NULL
)
18698 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18701 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18703 strlen (actual_class_name
)));
18704 xfree (actual_class_name
);
18712 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18714 /* Once we've fixed up a die, there's no point in doing so again.
18715 This also avoids a memory leak if we were to call
18716 guess_partial_die_structure_name multiple times. */
18720 /* If we found a reference attribute and the DIE has no name, try
18721 to find a name in the referred to DIE. */
18723 if (name
== NULL
&& has_specification
)
18725 struct partial_die_info
*spec_die
;
18727 spec_die
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18729 spec_die
->fixup (cu
);
18731 if (spec_die
->name
)
18733 name
= spec_die
->name
;
18735 /* Copy DW_AT_external attribute if it is set. */
18736 if (spec_die
->is_external
)
18737 is_external
= spec_die
->is_external
;
18741 /* Set default names for some unnamed DIEs. */
18743 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18744 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18746 /* If there is no parent die to provide a namespace, and there are
18747 children, see if we can determine the namespace from their linkage
18749 if (cu
->language
== language_cplus
18750 && !VEC_empty (dwarf2_section_info_def
,
18751 cu
->per_cu
->dwarf2_per_objfile
->types
)
18752 && die_parent
== NULL
18754 && (tag
== DW_TAG_class_type
18755 || tag
== DW_TAG_structure_type
18756 || tag
== DW_TAG_union_type
))
18757 guess_partial_die_structure_name (this, cu
);
18759 /* GCC might emit a nameless struct or union that has a linkage
18760 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18762 && (tag
== DW_TAG_class_type
18763 || tag
== DW_TAG_interface_type
18764 || tag
== DW_TAG_structure_type
18765 || tag
== DW_TAG_union_type
)
18766 && linkage_name
!= NULL
)
18770 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
18775 /* Strip any leading namespaces/classes, keep only the base name.
18776 DW_AT_name for named DIEs does not contain the prefixes. */
18777 base
= strrchr (demangled
, ':');
18778 if (base
&& base
> demangled
&& base
[-1] == ':')
18783 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18786 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18787 base
, strlen (base
)));
18795 /* Read an attribute value described by an attribute form. */
18797 static const gdb_byte
*
18798 read_attribute_value (const struct die_reader_specs
*reader
,
18799 struct attribute
*attr
, unsigned form
,
18800 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
18802 struct dwarf2_cu
*cu
= reader
->cu
;
18803 struct dwarf2_per_objfile
*dwarf2_per_objfile
18804 = cu
->per_cu
->dwarf2_per_objfile
;
18805 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18806 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18807 bfd
*abfd
= reader
->abfd
;
18808 struct comp_unit_head
*cu_header
= &cu
->header
;
18809 unsigned int bytes_read
;
18810 struct dwarf_block
*blk
;
18812 attr
->form
= (enum dwarf_form
) form
;
18815 case DW_FORM_ref_addr
:
18816 if (cu
->header
.version
== 2)
18817 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18819 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
18820 &cu
->header
, &bytes_read
);
18821 info_ptr
+= bytes_read
;
18823 case DW_FORM_GNU_ref_alt
:
18824 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18825 info_ptr
+= bytes_read
;
18828 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18829 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18830 info_ptr
+= bytes_read
;
18832 case DW_FORM_block2
:
18833 blk
= dwarf_alloc_block (cu
);
18834 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18836 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18837 info_ptr
+= blk
->size
;
18838 DW_BLOCK (attr
) = blk
;
18840 case DW_FORM_block4
:
18841 blk
= dwarf_alloc_block (cu
);
18842 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18844 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18845 info_ptr
+= blk
->size
;
18846 DW_BLOCK (attr
) = blk
;
18848 case DW_FORM_data2
:
18849 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18852 case DW_FORM_data4
:
18853 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18856 case DW_FORM_data8
:
18857 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18860 case DW_FORM_data16
:
18861 blk
= dwarf_alloc_block (cu
);
18863 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18865 DW_BLOCK (attr
) = blk
;
18867 case DW_FORM_sec_offset
:
18868 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18869 info_ptr
+= bytes_read
;
18871 case DW_FORM_string
:
18872 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18873 DW_STRING_IS_CANONICAL (attr
) = 0;
18874 info_ptr
+= bytes_read
;
18877 if (!cu
->per_cu
->is_dwz
)
18879 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18880 abfd
, info_ptr
, cu_header
,
18882 DW_STRING_IS_CANONICAL (attr
) = 0;
18883 info_ptr
+= bytes_read
;
18887 case DW_FORM_line_strp
:
18888 if (!cu
->per_cu
->is_dwz
)
18890 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
18892 cu_header
, &bytes_read
);
18893 DW_STRING_IS_CANONICAL (attr
) = 0;
18894 info_ptr
+= bytes_read
;
18898 case DW_FORM_GNU_strp_alt
:
18900 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18901 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
18904 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
18906 DW_STRING_IS_CANONICAL (attr
) = 0;
18907 info_ptr
+= bytes_read
;
18910 case DW_FORM_exprloc
:
18911 case DW_FORM_block
:
18912 blk
= dwarf_alloc_block (cu
);
18913 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18914 info_ptr
+= bytes_read
;
18915 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18916 info_ptr
+= blk
->size
;
18917 DW_BLOCK (attr
) = blk
;
18919 case DW_FORM_block1
:
18920 blk
= dwarf_alloc_block (cu
);
18921 blk
->size
= read_1_byte (abfd
, info_ptr
);
18923 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18924 info_ptr
+= blk
->size
;
18925 DW_BLOCK (attr
) = blk
;
18927 case DW_FORM_data1
:
18928 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18932 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18935 case DW_FORM_flag_present
:
18936 DW_UNSND (attr
) = 1;
18938 case DW_FORM_sdata
:
18939 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18940 info_ptr
+= bytes_read
;
18942 case DW_FORM_udata
:
18943 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18944 info_ptr
+= bytes_read
;
18947 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18948 + read_1_byte (abfd
, info_ptr
));
18952 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18953 + read_2_bytes (abfd
, info_ptr
));
18957 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18958 + read_4_bytes (abfd
, info_ptr
));
18962 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18963 + read_8_bytes (abfd
, info_ptr
));
18966 case DW_FORM_ref_sig8
:
18967 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18970 case DW_FORM_ref_udata
:
18971 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18972 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18973 info_ptr
+= bytes_read
;
18975 case DW_FORM_indirect
:
18976 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18977 info_ptr
+= bytes_read
;
18978 if (form
== DW_FORM_implicit_const
)
18980 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18981 info_ptr
+= bytes_read
;
18983 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18986 case DW_FORM_implicit_const
:
18987 DW_SND (attr
) = implicit_const
;
18989 case DW_FORM_GNU_addr_index
:
18990 if (reader
->dwo_file
== NULL
)
18992 /* For now flag a hard error.
18993 Later we can turn this into a complaint. */
18994 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
18995 dwarf_form_name (form
),
18996 bfd_get_filename (abfd
));
18998 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
18999 info_ptr
+= bytes_read
;
19001 case DW_FORM_GNU_str_index
:
19002 if (reader
->dwo_file
== NULL
)
19004 /* For now flag a hard error.
19005 Later we can turn this into a complaint if warranted. */
19006 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19007 dwarf_form_name (form
),
19008 bfd_get_filename (abfd
));
19011 ULONGEST str_index
=
19012 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19014 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19015 DW_STRING_IS_CANONICAL (attr
) = 0;
19016 info_ptr
+= bytes_read
;
19020 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19021 dwarf_form_name (form
),
19022 bfd_get_filename (abfd
));
19026 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19027 attr
->form
= DW_FORM_GNU_ref_alt
;
19029 /* We have seen instances where the compiler tried to emit a byte
19030 size attribute of -1 which ended up being encoded as an unsigned
19031 0xffffffff. Although 0xffffffff is technically a valid size value,
19032 an object of this size seems pretty unlikely so we can relatively
19033 safely treat these cases as if the size attribute was invalid and
19034 treat them as zero by default. */
19035 if (attr
->name
== DW_AT_byte_size
19036 && form
== DW_FORM_data4
19037 && DW_UNSND (attr
) >= 0xffffffff)
19040 (&symfile_complaints
,
19041 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19042 hex_string (DW_UNSND (attr
)));
19043 DW_UNSND (attr
) = 0;
19049 /* Read an attribute described by an abbreviated attribute. */
19051 static const gdb_byte
*
19052 read_attribute (const struct die_reader_specs
*reader
,
19053 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19054 const gdb_byte
*info_ptr
)
19056 attr
->name
= abbrev
->name
;
19057 return read_attribute_value (reader
, attr
, abbrev
->form
,
19058 abbrev
->implicit_const
, info_ptr
);
19061 /* Read dwarf information from a buffer. */
19063 static unsigned int
19064 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19066 return bfd_get_8 (abfd
, buf
);
19070 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19072 return bfd_get_signed_8 (abfd
, buf
);
19075 static unsigned int
19076 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19078 return bfd_get_16 (abfd
, buf
);
19082 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19084 return bfd_get_signed_16 (abfd
, buf
);
19087 static unsigned int
19088 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19090 return bfd_get_32 (abfd
, buf
);
19094 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19096 return bfd_get_signed_32 (abfd
, buf
);
19100 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19102 return bfd_get_64 (abfd
, buf
);
19106 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19107 unsigned int *bytes_read
)
19109 struct comp_unit_head
*cu_header
= &cu
->header
;
19110 CORE_ADDR retval
= 0;
19112 if (cu_header
->signed_addr_p
)
19114 switch (cu_header
->addr_size
)
19117 retval
= bfd_get_signed_16 (abfd
, buf
);
19120 retval
= bfd_get_signed_32 (abfd
, buf
);
19123 retval
= bfd_get_signed_64 (abfd
, buf
);
19126 internal_error (__FILE__
, __LINE__
,
19127 _("read_address: bad switch, signed [in module %s]"),
19128 bfd_get_filename (abfd
));
19133 switch (cu_header
->addr_size
)
19136 retval
= bfd_get_16 (abfd
, buf
);
19139 retval
= bfd_get_32 (abfd
, buf
);
19142 retval
= bfd_get_64 (abfd
, buf
);
19145 internal_error (__FILE__
, __LINE__
,
19146 _("read_address: bad switch, "
19147 "unsigned [in module %s]"),
19148 bfd_get_filename (abfd
));
19152 *bytes_read
= cu_header
->addr_size
;
19156 /* Read the initial length from a section. The (draft) DWARF 3
19157 specification allows the initial length to take up either 4 bytes
19158 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19159 bytes describe the length and all offsets will be 8 bytes in length
19162 An older, non-standard 64-bit format is also handled by this
19163 function. The older format in question stores the initial length
19164 as an 8-byte quantity without an escape value. Lengths greater
19165 than 2^32 aren't very common which means that the initial 4 bytes
19166 is almost always zero. Since a length value of zero doesn't make
19167 sense for the 32-bit format, this initial zero can be considered to
19168 be an escape value which indicates the presence of the older 64-bit
19169 format. As written, the code can't detect (old format) lengths
19170 greater than 4GB. If it becomes necessary to handle lengths
19171 somewhat larger than 4GB, we could allow other small values (such
19172 as the non-sensical values of 1, 2, and 3) to also be used as
19173 escape values indicating the presence of the old format.
19175 The value returned via bytes_read should be used to increment the
19176 relevant pointer after calling read_initial_length().
19178 [ Note: read_initial_length() and read_offset() are based on the
19179 document entitled "DWARF Debugging Information Format", revision
19180 3, draft 8, dated November 19, 2001. This document was obtained
19183 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19185 This document is only a draft and is subject to change. (So beware.)
19187 Details regarding the older, non-standard 64-bit format were
19188 determined empirically by examining 64-bit ELF files produced by
19189 the SGI toolchain on an IRIX 6.5 machine.
19191 - Kevin, July 16, 2002
19195 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19197 LONGEST length
= bfd_get_32 (abfd
, buf
);
19199 if (length
== 0xffffffff)
19201 length
= bfd_get_64 (abfd
, buf
+ 4);
19204 else if (length
== 0)
19206 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19207 length
= bfd_get_64 (abfd
, buf
);
19218 /* Cover function for read_initial_length.
19219 Returns the length of the object at BUF, and stores the size of the
19220 initial length in *BYTES_READ and stores the size that offsets will be in
19222 If the initial length size is not equivalent to that specified in
19223 CU_HEADER then issue a complaint.
19224 This is useful when reading non-comp-unit headers. */
19227 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19228 const struct comp_unit_head
*cu_header
,
19229 unsigned int *bytes_read
,
19230 unsigned int *offset_size
)
19232 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19234 gdb_assert (cu_header
->initial_length_size
== 4
19235 || cu_header
->initial_length_size
== 8
19236 || cu_header
->initial_length_size
== 12);
19238 if (cu_header
->initial_length_size
!= *bytes_read
)
19239 complaint (&symfile_complaints
,
19240 _("intermixed 32-bit and 64-bit DWARF sections"));
19242 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19246 /* Read an offset from the data stream. The size of the offset is
19247 given by cu_header->offset_size. */
19250 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19251 const struct comp_unit_head
*cu_header
,
19252 unsigned int *bytes_read
)
19254 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19256 *bytes_read
= cu_header
->offset_size
;
19260 /* Read an offset from the data stream. */
19263 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19265 LONGEST retval
= 0;
19267 switch (offset_size
)
19270 retval
= bfd_get_32 (abfd
, buf
);
19273 retval
= bfd_get_64 (abfd
, buf
);
19276 internal_error (__FILE__
, __LINE__
,
19277 _("read_offset_1: bad switch [in module %s]"),
19278 bfd_get_filename (abfd
));
19284 static const gdb_byte
*
19285 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19287 /* If the size of a host char is 8 bits, we can return a pointer
19288 to the buffer, otherwise we have to copy the data to a buffer
19289 allocated on the temporary obstack. */
19290 gdb_assert (HOST_CHAR_BIT
== 8);
19294 static const char *
19295 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19296 unsigned int *bytes_read_ptr
)
19298 /* If the size of a host char is 8 bits, we can return a pointer
19299 to the string, otherwise we have to copy the string to a buffer
19300 allocated on the temporary obstack. */
19301 gdb_assert (HOST_CHAR_BIT
== 8);
19304 *bytes_read_ptr
= 1;
19307 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19308 return (const char *) buf
;
19311 /* Return pointer to string at section SECT offset STR_OFFSET with error
19312 reporting strings FORM_NAME and SECT_NAME. */
19314 static const char *
19315 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19316 bfd
*abfd
, LONGEST str_offset
,
19317 struct dwarf2_section_info
*sect
,
19318 const char *form_name
,
19319 const char *sect_name
)
19321 dwarf2_read_section (objfile
, sect
);
19322 if (sect
->buffer
== NULL
)
19323 error (_("%s used without %s section [in module %s]"),
19324 form_name
, sect_name
, bfd_get_filename (abfd
));
19325 if (str_offset
>= sect
->size
)
19326 error (_("%s pointing outside of %s section [in module %s]"),
19327 form_name
, sect_name
, bfd_get_filename (abfd
));
19328 gdb_assert (HOST_CHAR_BIT
== 8);
19329 if (sect
->buffer
[str_offset
] == '\0')
19331 return (const char *) (sect
->buffer
+ str_offset
);
19334 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19336 static const char *
19337 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19338 bfd
*abfd
, LONGEST str_offset
)
19340 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19342 &dwarf2_per_objfile
->str
,
19343 "DW_FORM_strp", ".debug_str");
19346 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19348 static const char *
19349 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19350 bfd
*abfd
, LONGEST str_offset
)
19352 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19354 &dwarf2_per_objfile
->line_str
,
19355 "DW_FORM_line_strp",
19356 ".debug_line_str");
19359 /* Read a string at offset STR_OFFSET in the .debug_str section from
19360 the .dwz file DWZ. Throw an error if the offset is too large. If
19361 the string consists of a single NUL byte, return NULL; otherwise
19362 return a pointer to the string. */
19364 static const char *
19365 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19366 LONGEST str_offset
)
19368 dwarf2_read_section (objfile
, &dwz
->str
);
19370 if (dwz
->str
.buffer
== NULL
)
19371 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19372 "section [in module %s]"),
19373 bfd_get_filename (dwz
->dwz_bfd
));
19374 if (str_offset
>= dwz
->str
.size
)
19375 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19376 ".debug_str section [in module %s]"),
19377 bfd_get_filename (dwz
->dwz_bfd
));
19378 gdb_assert (HOST_CHAR_BIT
== 8);
19379 if (dwz
->str
.buffer
[str_offset
] == '\0')
19381 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19384 /* Return pointer to string at .debug_str offset as read from BUF.
19385 BUF is assumed to be in a compilation unit described by CU_HEADER.
19386 Return *BYTES_READ_PTR count of bytes read from BUF. */
19388 static const char *
19389 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19390 const gdb_byte
*buf
,
19391 const struct comp_unit_head
*cu_header
,
19392 unsigned int *bytes_read_ptr
)
19394 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19396 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19399 /* Return pointer to string at .debug_line_str offset as read from BUF.
19400 BUF is assumed to be in a compilation unit described by CU_HEADER.
19401 Return *BYTES_READ_PTR count of bytes read from BUF. */
19403 static const char *
19404 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19405 bfd
*abfd
, const gdb_byte
*buf
,
19406 const struct comp_unit_head
*cu_header
,
19407 unsigned int *bytes_read_ptr
)
19409 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19411 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19416 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19417 unsigned int *bytes_read_ptr
)
19420 unsigned int num_read
;
19422 unsigned char byte
;
19429 byte
= bfd_get_8 (abfd
, buf
);
19432 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19433 if ((byte
& 128) == 0)
19439 *bytes_read_ptr
= num_read
;
19444 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19445 unsigned int *bytes_read_ptr
)
19448 int shift
, num_read
;
19449 unsigned char byte
;
19456 byte
= bfd_get_8 (abfd
, buf
);
19459 result
|= ((LONGEST
) (byte
& 127) << shift
);
19461 if ((byte
& 128) == 0)
19466 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19467 result
|= -(((LONGEST
) 1) << shift
);
19468 *bytes_read_ptr
= num_read
;
19472 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19473 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
19474 ADDR_SIZE is the size of addresses from the CU header. */
19477 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19478 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
19480 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19481 bfd
*abfd
= objfile
->obfd
;
19482 const gdb_byte
*info_ptr
;
19484 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
19485 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19486 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19487 objfile_name (objfile
));
19488 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
19489 error (_("DW_FORM_addr_index pointing outside of "
19490 ".debug_addr section [in module %s]"),
19491 objfile_name (objfile
));
19492 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19493 + addr_base
+ addr_index
* addr_size
);
19494 if (addr_size
== 4)
19495 return bfd_get_32 (abfd
, info_ptr
);
19497 return bfd_get_64 (abfd
, info_ptr
);
19500 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19503 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19505 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19506 cu
->addr_base
, cu
->header
.addr_size
);
19509 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19512 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19513 unsigned int *bytes_read
)
19515 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19516 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19518 return read_addr_index (cu
, addr_index
);
19521 /* Data structure to pass results from dwarf2_read_addr_index_reader
19522 back to dwarf2_read_addr_index. */
19524 struct dwarf2_read_addr_index_data
19526 ULONGEST addr_base
;
19530 /* die_reader_func for dwarf2_read_addr_index. */
19533 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
19534 const gdb_byte
*info_ptr
,
19535 struct die_info
*comp_unit_die
,
19539 struct dwarf2_cu
*cu
= reader
->cu
;
19540 struct dwarf2_read_addr_index_data
*aidata
=
19541 (struct dwarf2_read_addr_index_data
*) data
;
19543 aidata
->addr_base
= cu
->addr_base
;
19544 aidata
->addr_size
= cu
->header
.addr_size
;
19547 /* Given an index in .debug_addr, fetch the value.
19548 NOTE: This can be called during dwarf expression evaluation,
19549 long after the debug information has been read, and thus per_cu->cu
19550 may no longer exist. */
19553 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19554 unsigned int addr_index
)
19556 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19557 struct dwarf2_cu
*cu
= per_cu
->cu
;
19558 ULONGEST addr_base
;
19561 /* We need addr_base and addr_size.
19562 If we don't have PER_CU->cu, we have to get it.
19563 Nasty, but the alternative is storing the needed info in PER_CU,
19564 which at this point doesn't seem justified: it's not clear how frequently
19565 it would get used and it would increase the size of every PER_CU.
19566 Entry points like dwarf2_per_cu_addr_size do a similar thing
19567 so we're not in uncharted territory here.
19568 Alas we need to be a bit more complicated as addr_base is contained
19571 We don't need to read the entire CU(/TU).
19572 We just need the header and top level die.
19574 IWBN to use the aging mechanism to let us lazily later discard the CU.
19575 For now we skip this optimization. */
19579 addr_base
= cu
->addr_base
;
19580 addr_size
= cu
->header
.addr_size
;
19584 struct dwarf2_read_addr_index_data aidata
;
19586 /* Note: We can't use init_cutu_and_read_dies_simple here,
19587 we need addr_base. */
19588 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
19589 dwarf2_read_addr_index_reader
, &aidata
);
19590 addr_base
= aidata
.addr_base
;
19591 addr_size
= aidata
.addr_size
;
19594 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19598 /* Given a DW_FORM_GNU_str_index, fetch the string.
19599 This is only used by the Fission support. */
19601 static const char *
19602 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19604 struct dwarf2_cu
*cu
= reader
->cu
;
19605 struct dwarf2_per_objfile
*dwarf2_per_objfile
19606 = cu
->per_cu
->dwarf2_per_objfile
;
19607 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19608 const char *objf_name
= objfile_name (objfile
);
19609 bfd
*abfd
= objfile
->obfd
;
19610 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
19611 struct dwarf2_section_info
*str_offsets_section
=
19612 &reader
->dwo_file
->sections
.str_offsets
;
19613 const gdb_byte
*info_ptr
;
19614 ULONGEST str_offset
;
19615 static const char form_name
[] = "DW_FORM_GNU_str_index";
19617 dwarf2_read_section (objfile
, str_section
);
19618 dwarf2_read_section (objfile
, str_offsets_section
);
19619 if (str_section
->buffer
== NULL
)
19620 error (_("%s used without .debug_str.dwo section"
19621 " in CU at offset %s [in module %s]"),
19622 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19623 if (str_offsets_section
->buffer
== NULL
)
19624 error (_("%s used without .debug_str_offsets.dwo section"
19625 " in CU at offset %s [in module %s]"),
19626 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19627 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
19628 error (_("%s pointing outside of .debug_str_offsets.dwo"
19629 " section in CU at offset %s [in module %s]"),
19630 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19631 info_ptr
= (str_offsets_section
->buffer
19632 + str_index
* cu
->header
.offset_size
);
19633 if (cu
->header
.offset_size
== 4)
19634 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19636 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19637 if (str_offset
>= str_section
->size
)
19638 error (_("Offset from %s pointing outside of"
19639 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19640 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19641 return (const char *) (str_section
->buffer
+ str_offset
);
19644 /* Return the length of an LEB128 number in BUF. */
19647 leb128_size (const gdb_byte
*buf
)
19649 const gdb_byte
*begin
= buf
;
19655 if ((byte
& 128) == 0)
19656 return buf
- begin
;
19661 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19670 cu
->language
= language_c
;
19673 case DW_LANG_C_plus_plus
:
19674 case DW_LANG_C_plus_plus_11
:
19675 case DW_LANG_C_plus_plus_14
:
19676 cu
->language
= language_cplus
;
19679 cu
->language
= language_d
;
19681 case DW_LANG_Fortran77
:
19682 case DW_LANG_Fortran90
:
19683 case DW_LANG_Fortran95
:
19684 case DW_LANG_Fortran03
:
19685 case DW_LANG_Fortran08
:
19686 cu
->language
= language_fortran
;
19689 cu
->language
= language_go
;
19691 case DW_LANG_Mips_Assembler
:
19692 cu
->language
= language_asm
;
19694 case DW_LANG_Ada83
:
19695 case DW_LANG_Ada95
:
19696 cu
->language
= language_ada
;
19698 case DW_LANG_Modula2
:
19699 cu
->language
= language_m2
;
19701 case DW_LANG_Pascal83
:
19702 cu
->language
= language_pascal
;
19705 cu
->language
= language_objc
;
19708 case DW_LANG_Rust_old
:
19709 cu
->language
= language_rust
;
19711 case DW_LANG_Cobol74
:
19712 case DW_LANG_Cobol85
:
19714 cu
->language
= language_minimal
;
19717 cu
->language_defn
= language_def (cu
->language
);
19720 /* Return the named attribute or NULL if not there. */
19722 static struct attribute
*
19723 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19728 struct attribute
*spec
= NULL
;
19730 for (i
= 0; i
< die
->num_attrs
; ++i
)
19732 if (die
->attrs
[i
].name
== name
)
19733 return &die
->attrs
[i
];
19734 if (die
->attrs
[i
].name
== DW_AT_specification
19735 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19736 spec
= &die
->attrs
[i
];
19742 die
= follow_die_ref (die
, spec
, &cu
);
19748 /* Return the named attribute or NULL if not there,
19749 but do not follow DW_AT_specification, etc.
19750 This is for use in contexts where we're reading .debug_types dies.
19751 Following DW_AT_specification, DW_AT_abstract_origin will take us
19752 back up the chain, and we want to go down. */
19754 static struct attribute
*
19755 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19759 for (i
= 0; i
< die
->num_attrs
; ++i
)
19760 if (die
->attrs
[i
].name
== name
)
19761 return &die
->attrs
[i
];
19766 /* Return the string associated with a string-typed attribute, or NULL if it
19767 is either not found or is of an incorrect type. */
19769 static const char *
19770 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19772 struct attribute
*attr
;
19773 const char *str
= NULL
;
19775 attr
= dwarf2_attr (die
, name
, cu
);
19779 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19780 || attr
->form
== DW_FORM_string
19781 || attr
->form
== DW_FORM_GNU_str_index
19782 || attr
->form
== DW_FORM_GNU_strp_alt
)
19783 str
= DW_STRING (attr
);
19785 complaint (&symfile_complaints
,
19786 _("string type expected for attribute %s for "
19787 "DIE at %s in module %s"),
19788 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19789 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19795 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19796 and holds a non-zero value. This function should only be used for
19797 DW_FORM_flag or DW_FORM_flag_present attributes. */
19800 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19802 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19804 return (attr
&& DW_UNSND (attr
));
19808 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19810 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19811 which value is non-zero. However, we have to be careful with
19812 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19813 (via dwarf2_flag_true_p) follows this attribute. So we may
19814 end up accidently finding a declaration attribute that belongs
19815 to a different DIE referenced by the specification attribute,
19816 even though the given DIE does not have a declaration attribute. */
19817 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19818 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19821 /* Return the die giving the specification for DIE, if there is
19822 one. *SPEC_CU is the CU containing DIE on input, and the CU
19823 containing the return value on output. If there is no
19824 specification, but there is an abstract origin, that is
19827 static struct die_info
*
19828 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19830 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19833 if (spec_attr
== NULL
)
19834 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19836 if (spec_attr
== NULL
)
19839 return follow_die_ref (die
, spec_attr
, spec_cu
);
19842 /* Stub for free_line_header to match void * callback types. */
19845 free_line_header_voidp (void *arg
)
19847 struct line_header
*lh
= (struct line_header
*) arg
;
19853 line_header::add_include_dir (const char *include_dir
)
19855 if (dwarf_line_debug
>= 2)
19856 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
19857 include_dirs
.size () + 1, include_dir
);
19859 include_dirs
.push_back (include_dir
);
19863 line_header::add_file_name (const char *name
,
19865 unsigned int mod_time
,
19866 unsigned int length
)
19868 if (dwarf_line_debug
>= 2)
19869 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
19870 (unsigned) file_names
.size () + 1, name
);
19872 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
19875 /* A convenience function to find the proper .debug_line section for a CU. */
19877 static struct dwarf2_section_info
*
19878 get_debug_line_section (struct dwarf2_cu
*cu
)
19880 struct dwarf2_section_info
*section
;
19881 struct dwarf2_per_objfile
*dwarf2_per_objfile
19882 = cu
->per_cu
->dwarf2_per_objfile
;
19884 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19886 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19887 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19888 else if (cu
->per_cu
->is_dwz
)
19890 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19892 section
= &dwz
->line
;
19895 section
= &dwarf2_per_objfile
->line
;
19900 /* Read directory or file name entry format, starting with byte of
19901 format count entries, ULEB128 pairs of entry formats, ULEB128 of
19902 entries count and the entries themselves in the described entry
19906 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19907 bfd
*abfd
, const gdb_byte
**bufp
,
19908 struct line_header
*lh
,
19909 const struct comp_unit_head
*cu_header
,
19910 void (*callback
) (struct line_header
*lh
,
19913 unsigned int mod_time
,
19914 unsigned int length
))
19916 gdb_byte format_count
, formati
;
19917 ULONGEST data_count
, datai
;
19918 const gdb_byte
*buf
= *bufp
;
19919 const gdb_byte
*format_header_data
;
19920 unsigned int bytes_read
;
19922 format_count
= read_1_byte (abfd
, buf
);
19924 format_header_data
= buf
;
19925 for (formati
= 0; formati
< format_count
; formati
++)
19927 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19929 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19933 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19935 for (datai
= 0; datai
< data_count
; datai
++)
19937 const gdb_byte
*format
= format_header_data
;
19938 struct file_entry fe
;
19940 for (formati
= 0; formati
< format_count
; formati
++)
19942 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19943 format
+= bytes_read
;
19945 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19946 format
+= bytes_read
;
19948 gdb::optional
<const char *> string
;
19949 gdb::optional
<unsigned int> uint
;
19953 case DW_FORM_string
:
19954 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
19958 case DW_FORM_line_strp
:
19959 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
19966 case DW_FORM_data1
:
19967 uint
.emplace (read_1_byte (abfd
, buf
));
19971 case DW_FORM_data2
:
19972 uint
.emplace (read_2_bytes (abfd
, buf
));
19976 case DW_FORM_data4
:
19977 uint
.emplace (read_4_bytes (abfd
, buf
));
19981 case DW_FORM_data8
:
19982 uint
.emplace (read_8_bytes (abfd
, buf
));
19986 case DW_FORM_udata
:
19987 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
19991 case DW_FORM_block
:
19992 /* It is valid only for DW_LNCT_timestamp which is ignored by
19997 switch (content_type
)
20000 if (string
.has_value ())
20003 case DW_LNCT_directory_index
:
20004 if (uint
.has_value ())
20005 fe
.d_index
= (dir_index
) *uint
;
20007 case DW_LNCT_timestamp
:
20008 if (uint
.has_value ())
20009 fe
.mod_time
= *uint
;
20012 if (uint
.has_value ())
20018 complaint (&symfile_complaints
,
20019 _("Unknown format content type %s"),
20020 pulongest (content_type
));
20024 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20030 /* Read the statement program header starting at OFFSET in
20031 .debug_line, or .debug_line.dwo. Return a pointer
20032 to a struct line_header, allocated using xmalloc.
20033 Returns NULL if there is a problem reading the header, e.g., if it
20034 has a version we don't understand.
20036 NOTE: the strings in the include directory and file name tables of
20037 the returned object point into the dwarf line section buffer,
20038 and must not be freed. */
20040 static line_header_up
20041 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20043 const gdb_byte
*line_ptr
;
20044 unsigned int bytes_read
, offset_size
;
20046 const char *cur_dir
, *cur_file
;
20047 struct dwarf2_section_info
*section
;
20049 struct dwarf2_per_objfile
*dwarf2_per_objfile
20050 = cu
->per_cu
->dwarf2_per_objfile
;
20052 section
= get_debug_line_section (cu
);
20053 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20054 if (section
->buffer
== NULL
)
20056 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20057 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
20059 complaint (&symfile_complaints
, _("missing .debug_line section"));
20063 /* We can't do this until we know the section is non-empty.
20064 Only then do we know we have such a section. */
20065 abfd
= get_section_bfd_owner (section
);
20067 /* Make sure that at least there's room for the total_length field.
20068 That could be 12 bytes long, but we're just going to fudge that. */
20069 if (to_underlying (sect_off
) + 4 >= section
->size
)
20071 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20075 line_header_up
lh (new line_header ());
20077 lh
->sect_off
= sect_off
;
20078 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20080 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20082 /* Read in the header. */
20084 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20085 &bytes_read
, &offset_size
);
20086 line_ptr
+= bytes_read
;
20087 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20089 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20092 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20093 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20095 if (lh
->version
> 5)
20097 /* This is a version we don't understand. The format could have
20098 changed in ways we don't handle properly so just punt. */
20099 complaint (&symfile_complaints
,
20100 _("unsupported version in .debug_line section"));
20103 if (lh
->version
>= 5)
20105 gdb_byte segment_selector_size
;
20107 /* Skip address size. */
20108 read_1_byte (abfd
, line_ptr
);
20111 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20113 if (segment_selector_size
!= 0)
20115 complaint (&symfile_complaints
,
20116 _("unsupported segment selector size %u "
20117 "in .debug_line section"),
20118 segment_selector_size
);
20122 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20123 line_ptr
+= offset_size
;
20124 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20126 if (lh
->version
>= 4)
20128 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20132 lh
->maximum_ops_per_instruction
= 1;
20134 if (lh
->maximum_ops_per_instruction
== 0)
20136 lh
->maximum_ops_per_instruction
= 1;
20137 complaint (&symfile_complaints
,
20138 _("invalid maximum_ops_per_instruction "
20139 "in `.debug_line' section"));
20142 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20144 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20146 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20148 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20150 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20152 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20153 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20155 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20159 if (lh
->version
>= 5)
20161 /* Read directory table. */
20162 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20164 [] (struct line_header
*lh
, const char *name
,
20165 dir_index d_index
, unsigned int mod_time
,
20166 unsigned int length
)
20168 lh
->add_include_dir (name
);
20171 /* Read file name table. */
20172 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20174 [] (struct line_header
*lh
, const char *name
,
20175 dir_index d_index
, unsigned int mod_time
,
20176 unsigned int length
)
20178 lh
->add_file_name (name
, d_index
, mod_time
, length
);
20183 /* Read directory table. */
20184 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20186 line_ptr
+= bytes_read
;
20187 lh
->add_include_dir (cur_dir
);
20189 line_ptr
+= bytes_read
;
20191 /* Read file name table. */
20192 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20194 unsigned int mod_time
, length
;
20197 line_ptr
+= bytes_read
;
20198 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20199 line_ptr
+= bytes_read
;
20200 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20201 line_ptr
+= bytes_read
;
20202 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20203 line_ptr
+= bytes_read
;
20205 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20207 line_ptr
+= bytes_read
;
20209 lh
->statement_program_start
= line_ptr
;
20211 if (line_ptr
> (section
->buffer
+ section
->size
))
20212 complaint (&symfile_complaints
,
20213 _("line number info header doesn't "
20214 "fit in `.debug_line' section"));
20219 /* Subroutine of dwarf_decode_lines to simplify it.
20220 Return the file name of the psymtab for included file FILE_INDEX
20221 in line header LH of PST.
20222 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20223 If space for the result is malloc'd, *NAME_HOLDER will be set.
20224 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20226 static const char *
20227 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20228 const struct partial_symtab
*pst
,
20229 const char *comp_dir
,
20230 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20232 const file_entry
&fe
= lh
->file_names
[file_index
];
20233 const char *include_name
= fe
.name
;
20234 const char *include_name_to_compare
= include_name
;
20235 const char *pst_filename
;
20238 const char *dir_name
= fe
.include_dir (lh
);
20240 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20241 if (!IS_ABSOLUTE_PATH (include_name
)
20242 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20244 /* Avoid creating a duplicate psymtab for PST.
20245 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20246 Before we do the comparison, however, we need to account
20247 for DIR_NAME and COMP_DIR.
20248 First prepend dir_name (if non-NULL). If we still don't
20249 have an absolute path prepend comp_dir (if non-NULL).
20250 However, the directory we record in the include-file's
20251 psymtab does not contain COMP_DIR (to match the
20252 corresponding symtab(s)).
20257 bash$ gcc -g ./hello.c
20258 include_name = "hello.c"
20260 DW_AT_comp_dir = comp_dir = "/tmp"
20261 DW_AT_name = "./hello.c"
20265 if (dir_name
!= NULL
)
20267 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20268 include_name
, (char *) NULL
));
20269 include_name
= name_holder
->get ();
20270 include_name_to_compare
= include_name
;
20272 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20274 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20275 include_name
, (char *) NULL
));
20276 include_name_to_compare
= hold_compare
.get ();
20280 pst_filename
= pst
->filename
;
20281 gdb::unique_xmalloc_ptr
<char> copied_name
;
20282 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20284 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20285 pst_filename
, (char *) NULL
));
20286 pst_filename
= copied_name
.get ();
20289 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20293 return include_name
;
20296 /* State machine to track the state of the line number program. */
20298 class lnp_state_machine
20301 /* Initialize a machine state for the start of a line number
20303 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
20305 file_entry
*current_file ()
20307 /* lh->file_names is 0-based, but the file name numbers in the
20308 statement program are 1-based. */
20309 return m_line_header
->file_name_at (m_file
);
20312 /* Record the line in the state machine. END_SEQUENCE is true if
20313 we're processing the end of a sequence. */
20314 void record_line (bool end_sequence
);
20316 /* Check address and if invalid nop-out the rest of the lines in this
20318 void check_line_address (struct dwarf2_cu
*cu
,
20319 const gdb_byte
*line_ptr
,
20320 CORE_ADDR lowpc
, CORE_ADDR address
);
20322 void handle_set_discriminator (unsigned int discriminator
)
20324 m_discriminator
= discriminator
;
20325 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20328 /* Handle DW_LNE_set_address. */
20329 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20332 address
+= baseaddr
;
20333 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20336 /* Handle DW_LNS_advance_pc. */
20337 void handle_advance_pc (CORE_ADDR adjust
);
20339 /* Handle a special opcode. */
20340 void handle_special_opcode (unsigned char op_code
);
20342 /* Handle DW_LNS_advance_line. */
20343 void handle_advance_line (int line_delta
)
20345 advance_line (line_delta
);
20348 /* Handle DW_LNS_set_file. */
20349 void handle_set_file (file_name_index file
);
20351 /* Handle DW_LNS_negate_stmt. */
20352 void handle_negate_stmt ()
20354 m_is_stmt
= !m_is_stmt
;
20357 /* Handle DW_LNS_const_add_pc. */
20358 void handle_const_add_pc ();
20360 /* Handle DW_LNS_fixed_advance_pc. */
20361 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20363 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20367 /* Handle DW_LNS_copy. */
20368 void handle_copy ()
20370 record_line (false);
20371 m_discriminator
= 0;
20374 /* Handle DW_LNE_end_sequence. */
20375 void handle_end_sequence ()
20377 m_record_line_callback
= ::record_line
;
20381 /* Advance the line by LINE_DELTA. */
20382 void advance_line (int line_delta
)
20384 m_line
+= line_delta
;
20386 if (line_delta
!= 0)
20387 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20390 gdbarch
*m_gdbarch
;
20392 /* True if we're recording lines.
20393 Otherwise we're building partial symtabs and are just interested in
20394 finding include files mentioned by the line number program. */
20395 bool m_record_lines_p
;
20397 /* The line number header. */
20398 line_header
*m_line_header
;
20400 /* These are part of the standard DWARF line number state machine,
20401 and initialized according to the DWARF spec. */
20403 unsigned char m_op_index
= 0;
20404 /* The line table index (1-based) of the current file. */
20405 file_name_index m_file
= (file_name_index
) 1;
20406 unsigned int m_line
= 1;
20408 /* These are initialized in the constructor. */
20410 CORE_ADDR m_address
;
20412 unsigned int m_discriminator
;
20414 /* Additional bits of state we need to track. */
20416 /* The last file that we called dwarf2_start_subfile for.
20417 This is only used for TLLs. */
20418 unsigned int m_last_file
= 0;
20419 /* The last file a line number was recorded for. */
20420 struct subfile
*m_last_subfile
= NULL
;
20422 /* The function to call to record a line. */
20423 record_line_ftype
*m_record_line_callback
= NULL
;
20425 /* The last line number that was recorded, used to coalesce
20426 consecutive entries for the same line. This can happen, for
20427 example, when discriminators are present. PR 17276. */
20428 unsigned int m_last_line
= 0;
20429 bool m_line_has_non_zero_discriminator
= false;
20433 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20435 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20436 / m_line_header
->maximum_ops_per_instruction
)
20437 * m_line_header
->minimum_instruction_length
);
20438 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20439 m_op_index
= ((m_op_index
+ adjust
)
20440 % m_line_header
->maximum_ops_per_instruction
);
20444 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20446 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20447 CORE_ADDR addr_adj
= (((m_op_index
20448 + (adj_opcode
/ m_line_header
->line_range
))
20449 / m_line_header
->maximum_ops_per_instruction
)
20450 * m_line_header
->minimum_instruction_length
);
20451 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20452 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20453 % m_line_header
->maximum_ops_per_instruction
);
20455 int line_delta
= (m_line_header
->line_base
20456 + (adj_opcode
% m_line_header
->line_range
));
20457 advance_line (line_delta
);
20458 record_line (false);
20459 m_discriminator
= 0;
20463 lnp_state_machine::handle_set_file (file_name_index file
)
20467 const file_entry
*fe
= current_file ();
20469 dwarf2_debug_line_missing_file_complaint ();
20470 else if (m_record_lines_p
)
20472 const char *dir
= fe
->include_dir (m_line_header
);
20474 m_last_subfile
= current_subfile
;
20475 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20476 dwarf2_start_subfile (fe
->name
, dir
);
20481 lnp_state_machine::handle_const_add_pc ()
20484 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20487 = (((m_op_index
+ adjust
)
20488 / m_line_header
->maximum_ops_per_instruction
)
20489 * m_line_header
->minimum_instruction_length
);
20491 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20492 m_op_index
= ((m_op_index
+ adjust
)
20493 % m_line_header
->maximum_ops_per_instruction
);
20496 /* Ignore this record_line request. */
20499 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
20504 /* Return non-zero if we should add LINE to the line number table.
20505 LINE is the line to add, LAST_LINE is the last line that was added,
20506 LAST_SUBFILE is the subfile for LAST_LINE.
20507 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20508 had a non-zero discriminator.
20510 We have to be careful in the presence of discriminators.
20511 E.g., for this line:
20513 for (i = 0; i < 100000; i++);
20515 clang can emit four line number entries for that one line,
20516 each with a different discriminator.
20517 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20519 However, we want gdb to coalesce all four entries into one.
20520 Otherwise the user could stepi into the middle of the line and
20521 gdb would get confused about whether the pc really was in the
20522 middle of the line.
20524 Things are further complicated by the fact that two consecutive
20525 line number entries for the same line is a heuristic used by gcc
20526 to denote the end of the prologue. So we can't just discard duplicate
20527 entries, we have to be selective about it. The heuristic we use is
20528 that we only collapse consecutive entries for the same line if at least
20529 one of those entries has a non-zero discriminator. PR 17276.
20531 Note: Addresses in the line number state machine can never go backwards
20532 within one sequence, thus this coalescing is ok. */
20535 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
20536 int line_has_non_zero_discriminator
,
20537 struct subfile
*last_subfile
)
20539 if (current_subfile
!= last_subfile
)
20541 if (line
!= last_line
)
20543 /* Same line for the same file that we've seen already.
20544 As a last check, for pr 17276, only record the line if the line
20545 has never had a non-zero discriminator. */
20546 if (!line_has_non_zero_discriminator
)
20551 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
20552 in the line table of subfile SUBFILE. */
20555 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20556 unsigned int line
, CORE_ADDR address
,
20557 record_line_ftype p_record_line
)
20559 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20561 if (dwarf_line_debug
)
20563 fprintf_unfiltered (gdb_stdlog
,
20564 "Recording line %u, file %s, address %s\n",
20565 line
, lbasename (subfile
->name
),
20566 paddress (gdbarch
, address
));
20569 (*p_record_line
) (subfile
, line
, addr
);
20572 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20573 Mark the end of a set of line number records.
20574 The arguments are the same as for dwarf_record_line_1.
20575 If SUBFILE is NULL the request is ignored. */
20578 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20579 CORE_ADDR address
, record_line_ftype p_record_line
)
20581 if (subfile
== NULL
)
20584 if (dwarf_line_debug
)
20586 fprintf_unfiltered (gdb_stdlog
,
20587 "Finishing current line, file %s, address %s\n",
20588 lbasename (subfile
->name
),
20589 paddress (gdbarch
, address
));
20592 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
20596 lnp_state_machine::record_line (bool end_sequence
)
20598 if (dwarf_line_debug
)
20600 fprintf_unfiltered (gdb_stdlog
,
20601 "Processing actual line %u: file %u,"
20602 " address %s, is_stmt %u, discrim %u\n",
20603 m_line
, to_underlying (m_file
),
20604 paddress (m_gdbarch
, m_address
),
20605 m_is_stmt
, m_discriminator
);
20608 file_entry
*fe
= current_file ();
20611 dwarf2_debug_line_missing_file_complaint ();
20612 /* For now we ignore lines not starting on an instruction boundary.
20613 But not when processing end_sequence for compatibility with the
20614 previous version of the code. */
20615 else if (m_op_index
== 0 || end_sequence
)
20617 fe
->included_p
= 1;
20618 if (m_record_lines_p
&& m_is_stmt
)
20620 if (m_last_subfile
!= current_subfile
|| end_sequence
)
20622 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
20623 m_address
, m_record_line_callback
);
20628 if (dwarf_record_line_p (m_line
, m_last_line
,
20629 m_line_has_non_zero_discriminator
,
20632 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
20634 m_record_line_callback
);
20636 m_last_subfile
= current_subfile
;
20637 m_last_line
= m_line
;
20643 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
20644 bool record_lines_p
)
20647 m_record_lines_p
= record_lines_p
;
20648 m_line_header
= lh
;
20650 m_record_line_callback
= ::record_line
;
20652 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20653 was a line entry for it so that the backend has a chance to adjust it
20654 and also record it in case it needs it. This is currently used by MIPS
20655 code, cf. `mips_adjust_dwarf2_line'. */
20656 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20657 m_is_stmt
= lh
->default_is_stmt
;
20658 m_discriminator
= 0;
20662 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20663 const gdb_byte
*line_ptr
,
20664 CORE_ADDR lowpc
, CORE_ADDR address
)
20666 /* If address < lowpc then it's not a usable value, it's outside the
20667 pc range of the CU. However, we restrict the test to only address
20668 values of zero to preserve GDB's previous behaviour which is to
20669 handle the specific case of a function being GC'd by the linker. */
20671 if (address
== 0 && address
< lowpc
)
20673 /* This line table is for a function which has been
20674 GCd by the linker. Ignore it. PR gdb/12528 */
20676 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20677 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20679 complaint (&symfile_complaints
,
20680 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20681 line_offset
, objfile_name (objfile
));
20682 m_record_line_callback
= noop_record_line
;
20683 /* Note: record_line_callback is left as noop_record_line until
20684 we see DW_LNE_end_sequence. */
20688 /* Subroutine of dwarf_decode_lines to simplify it.
20689 Process the line number information in LH.
20690 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20691 program in order to set included_p for every referenced header. */
20694 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20695 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20697 const gdb_byte
*line_ptr
, *extended_end
;
20698 const gdb_byte
*line_end
;
20699 unsigned int bytes_read
, extended_len
;
20700 unsigned char op_code
, extended_op
;
20701 CORE_ADDR baseaddr
;
20702 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20703 bfd
*abfd
= objfile
->obfd
;
20704 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20705 /* True if we're recording line info (as opposed to building partial
20706 symtabs and just interested in finding include files mentioned by
20707 the line number program). */
20708 bool record_lines_p
= !decode_for_pst_p
;
20710 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
20712 line_ptr
= lh
->statement_program_start
;
20713 line_end
= lh
->statement_program_end
;
20715 /* Read the statement sequences until there's nothing left. */
20716 while (line_ptr
< line_end
)
20718 /* The DWARF line number program state machine. Reset the state
20719 machine at the start of each sequence. */
20720 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
20721 bool end_sequence
= false;
20723 if (record_lines_p
)
20725 /* Start a subfile for the current file of the state
20727 const file_entry
*fe
= state_machine
.current_file ();
20730 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
20733 /* Decode the table. */
20734 while (line_ptr
< line_end
&& !end_sequence
)
20736 op_code
= read_1_byte (abfd
, line_ptr
);
20739 if (op_code
>= lh
->opcode_base
)
20741 /* Special opcode. */
20742 state_machine
.handle_special_opcode (op_code
);
20744 else switch (op_code
)
20746 case DW_LNS_extended_op
:
20747 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20749 line_ptr
+= bytes_read
;
20750 extended_end
= line_ptr
+ extended_len
;
20751 extended_op
= read_1_byte (abfd
, line_ptr
);
20753 switch (extended_op
)
20755 case DW_LNE_end_sequence
:
20756 state_machine
.handle_end_sequence ();
20757 end_sequence
= true;
20759 case DW_LNE_set_address
:
20762 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
20763 line_ptr
+= bytes_read
;
20765 state_machine
.check_line_address (cu
, line_ptr
,
20767 state_machine
.handle_set_address (baseaddr
, address
);
20770 case DW_LNE_define_file
:
20772 const char *cur_file
;
20773 unsigned int mod_time
, length
;
20776 cur_file
= read_direct_string (abfd
, line_ptr
,
20778 line_ptr
+= bytes_read
;
20779 dindex
= (dir_index
)
20780 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20781 line_ptr
+= bytes_read
;
20783 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20784 line_ptr
+= bytes_read
;
20786 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20787 line_ptr
+= bytes_read
;
20788 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20791 case DW_LNE_set_discriminator
:
20793 /* The discriminator is not interesting to the
20794 debugger; just ignore it. We still need to
20795 check its value though:
20796 if there are consecutive entries for the same
20797 (non-prologue) line we want to coalesce them.
20800 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20801 line_ptr
+= bytes_read
;
20803 state_machine
.handle_set_discriminator (discr
);
20807 complaint (&symfile_complaints
,
20808 _("mangled .debug_line section"));
20811 /* Make sure that we parsed the extended op correctly. If e.g.
20812 we expected a different address size than the producer used,
20813 we may have read the wrong number of bytes. */
20814 if (line_ptr
!= extended_end
)
20816 complaint (&symfile_complaints
,
20817 _("mangled .debug_line section"));
20822 state_machine
.handle_copy ();
20824 case DW_LNS_advance_pc
:
20827 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20828 line_ptr
+= bytes_read
;
20830 state_machine
.handle_advance_pc (adjust
);
20833 case DW_LNS_advance_line
:
20836 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20837 line_ptr
+= bytes_read
;
20839 state_machine
.handle_advance_line (line_delta
);
20842 case DW_LNS_set_file
:
20844 file_name_index file
20845 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20847 line_ptr
+= bytes_read
;
20849 state_machine
.handle_set_file (file
);
20852 case DW_LNS_set_column
:
20853 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20854 line_ptr
+= bytes_read
;
20856 case DW_LNS_negate_stmt
:
20857 state_machine
.handle_negate_stmt ();
20859 case DW_LNS_set_basic_block
:
20861 /* Add to the address register of the state machine the
20862 address increment value corresponding to special opcode
20863 255. I.e., this value is scaled by the minimum
20864 instruction length since special opcode 255 would have
20865 scaled the increment. */
20866 case DW_LNS_const_add_pc
:
20867 state_machine
.handle_const_add_pc ();
20869 case DW_LNS_fixed_advance_pc
:
20871 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20874 state_machine
.handle_fixed_advance_pc (addr_adj
);
20879 /* Unknown standard opcode, ignore it. */
20882 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20884 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20885 line_ptr
+= bytes_read
;
20892 dwarf2_debug_line_missing_end_sequence_complaint ();
20894 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20895 in which case we still finish recording the last line). */
20896 state_machine
.record_line (true);
20900 /* Decode the Line Number Program (LNP) for the given line_header
20901 structure and CU. The actual information extracted and the type
20902 of structures created from the LNP depends on the value of PST.
20904 1. If PST is NULL, then this procedure uses the data from the program
20905 to create all necessary symbol tables, and their linetables.
20907 2. If PST is not NULL, this procedure reads the program to determine
20908 the list of files included by the unit represented by PST, and
20909 builds all the associated partial symbol tables.
20911 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20912 It is used for relative paths in the line table.
20913 NOTE: When processing partial symtabs (pst != NULL),
20914 comp_dir == pst->dirname.
20916 NOTE: It is important that psymtabs have the same file name (via strcmp)
20917 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20918 symtab we don't use it in the name of the psymtabs we create.
20919 E.g. expand_line_sal requires this when finding psymtabs to expand.
20920 A good testcase for this is mb-inline.exp.
20922 LOWPC is the lowest address in CU (or 0 if not known).
20924 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20925 for its PC<->lines mapping information. Otherwise only the filename
20926 table is read in. */
20929 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20930 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
20931 CORE_ADDR lowpc
, int decode_mapping
)
20933 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20934 const int decode_for_pst_p
= (pst
!= NULL
);
20936 if (decode_mapping
)
20937 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20939 if (decode_for_pst_p
)
20943 /* Now that we're done scanning the Line Header Program, we can
20944 create the psymtab of each included file. */
20945 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
20946 if (lh
->file_names
[file_index
].included_p
== 1)
20948 gdb::unique_xmalloc_ptr
<char> name_holder
;
20949 const char *include_name
=
20950 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
20952 if (include_name
!= NULL
)
20953 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20958 /* Make sure a symtab is created for every file, even files
20959 which contain only variables (i.e. no code with associated
20961 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
20964 for (i
= 0; i
< lh
->file_names
.size (); i
++)
20966 file_entry
&fe
= lh
->file_names
[i
];
20968 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
20970 if (current_subfile
->symtab
== NULL
)
20972 current_subfile
->symtab
20973 = allocate_symtab (cust
, current_subfile
->name
);
20975 fe
.symtab
= current_subfile
->symtab
;
20980 /* Start a subfile for DWARF. FILENAME is the name of the file and
20981 DIRNAME the name of the source directory which contains FILENAME
20982 or NULL if not known.
20983 This routine tries to keep line numbers from identical absolute and
20984 relative file names in a common subfile.
20986 Using the `list' example from the GDB testsuite, which resides in
20987 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20988 of /srcdir/list0.c yields the following debugging information for list0.c:
20990 DW_AT_name: /srcdir/list0.c
20991 DW_AT_comp_dir: /compdir
20992 files.files[0].name: list0.h
20993 files.files[0].dir: /srcdir
20994 files.files[1].name: list0.c
20995 files.files[1].dir: /srcdir
20997 The line number information for list0.c has to end up in a single
20998 subfile, so that `break /srcdir/list0.c:1' works as expected.
20999 start_subfile will ensure that this happens provided that we pass the
21000 concatenation of files.files[1].dir and files.files[1].name as the
21004 dwarf2_start_subfile (const char *filename
, const char *dirname
)
21008 /* In order not to lose the line information directory,
21009 we concatenate it to the filename when it makes sense.
21010 Note that the Dwarf3 standard says (speaking of filenames in line
21011 information): ``The directory index is ignored for file names
21012 that represent full path names''. Thus ignoring dirname in the
21013 `else' branch below isn't an issue. */
21015 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21017 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21021 start_subfile (filename
);
21027 /* Start a symtab for DWARF.
21028 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
21030 static struct compunit_symtab
*
21031 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
21032 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
21034 struct compunit_symtab
*cust
21035 = start_symtab (cu
->per_cu
->dwarf2_per_objfile
->objfile
, name
, comp_dir
,
21036 low_pc
, cu
->language
);
21038 record_debugformat ("DWARF 2");
21039 record_producer (cu
->producer
);
21041 /* We assume that we're processing GCC output. */
21042 processing_gcc_compilation
= 2;
21044 cu
->processing_has_namespace_info
= 0;
21050 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21051 struct dwarf2_cu
*cu
)
21053 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21054 struct comp_unit_head
*cu_header
= &cu
->header
;
21056 /* NOTE drow/2003-01-30: There used to be a comment and some special
21057 code here to turn a symbol with DW_AT_external and a
21058 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21059 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21060 with some versions of binutils) where shared libraries could have
21061 relocations against symbols in their debug information - the
21062 minimal symbol would have the right address, but the debug info
21063 would not. It's no longer necessary, because we will explicitly
21064 apply relocations when we read in the debug information now. */
21066 /* A DW_AT_location attribute with no contents indicates that a
21067 variable has been optimized away. */
21068 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21070 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21074 /* Handle one degenerate form of location expression specially, to
21075 preserve GDB's previous behavior when section offsets are
21076 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
21077 then mark this symbol as LOC_STATIC. */
21079 if (attr_form_is_block (attr
)
21080 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21081 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21082 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21083 && (DW_BLOCK (attr
)->size
21084 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21086 unsigned int dummy
;
21088 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21089 SYMBOL_VALUE_ADDRESS (sym
) =
21090 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
21092 SYMBOL_VALUE_ADDRESS (sym
) =
21093 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
21094 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21095 fixup_symbol_section (sym
, objfile
);
21096 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
21097 SYMBOL_SECTION (sym
));
21101 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21102 expression evaluator, and use LOC_COMPUTED only when necessary
21103 (i.e. when the value of a register or memory location is
21104 referenced, or a thread-local block, etc.). Then again, it might
21105 not be worthwhile. I'm assuming that it isn't unless performance
21106 or memory numbers show me otherwise. */
21108 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21110 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21111 cu
->has_loclist
= 1;
21114 /* Given a pointer to a DWARF information entry, figure out if we need
21115 to make a symbol table entry for it, and if so, create a new entry
21116 and return a pointer to it.
21117 If TYPE is NULL, determine symbol type from the die, otherwise
21118 used the passed type.
21119 If SPACE is not NULL, use it to hold the new symbol. If it is
21120 NULL, allocate a new symbol on the objfile's obstack. */
21122 static struct symbol
*
21123 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21124 struct symbol
*space
)
21126 struct dwarf2_per_objfile
*dwarf2_per_objfile
21127 = cu
->per_cu
->dwarf2_per_objfile
;
21128 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21129 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21130 struct symbol
*sym
= NULL
;
21132 struct attribute
*attr
= NULL
;
21133 struct attribute
*attr2
= NULL
;
21134 CORE_ADDR baseaddr
;
21135 struct pending
**list_to_add
= NULL
;
21137 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21139 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21141 name
= dwarf2_name (die
, cu
);
21144 const char *linkagename
;
21145 int suppress_add
= 0;
21150 sym
= allocate_symbol (objfile
);
21151 OBJSTAT (objfile
, n_syms
++);
21153 /* Cache this symbol's name and the name's demangled form (if any). */
21154 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21155 linkagename
= dwarf2_physname (name
, die
, cu
);
21156 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21158 /* Fortran does not have mangling standard and the mangling does differ
21159 between gfortran, iFort etc. */
21160 if (cu
->language
== language_fortran
21161 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21162 symbol_set_demangled_name (&(sym
->ginfo
),
21163 dwarf2_full_name (name
, die
, cu
),
21166 /* Default assumptions.
21167 Use the passed type or decode it from the die. */
21168 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21169 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21171 SYMBOL_TYPE (sym
) = type
;
21173 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21174 attr
= dwarf2_attr (die
,
21175 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21179 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21182 attr
= dwarf2_attr (die
,
21183 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21187 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21188 struct file_entry
*fe
;
21190 if (cu
->line_header
!= NULL
)
21191 fe
= cu
->line_header
->file_name_at (file_index
);
21196 complaint (&symfile_complaints
,
21197 _("file index out of range"));
21199 symbol_set_symtab (sym
, fe
->symtab
);
21205 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21210 addr
= attr_value_as_address (attr
);
21211 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21212 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
21214 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21215 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21216 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21217 add_symbol_to_list (sym
, cu
->list_in_scope
);
21219 case DW_TAG_subprogram
:
21220 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21222 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21223 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21224 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21225 || cu
->language
== language_ada
)
21227 /* Subprograms marked external are stored as a global symbol.
21228 Ada subprograms, whether marked external or not, are always
21229 stored as a global symbol, because we want to be able to
21230 access them globally. For instance, we want to be able
21231 to break on a nested subprogram without having to
21232 specify the context. */
21233 list_to_add
= &global_symbols
;
21237 list_to_add
= cu
->list_in_scope
;
21240 case DW_TAG_inlined_subroutine
:
21241 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21243 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21244 SYMBOL_INLINED (sym
) = 1;
21245 list_to_add
= cu
->list_in_scope
;
21247 case DW_TAG_template_value_param
:
21249 /* Fall through. */
21250 case DW_TAG_constant
:
21251 case DW_TAG_variable
:
21252 case DW_TAG_member
:
21253 /* Compilation with minimal debug info may result in
21254 variables with missing type entries. Change the
21255 misleading `void' type to something sensible. */
21256 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21257 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21259 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21260 /* In the case of DW_TAG_member, we should only be called for
21261 static const members. */
21262 if (die
->tag
== DW_TAG_member
)
21264 /* dwarf2_add_field uses die_is_declaration,
21265 so we do the same. */
21266 gdb_assert (die_is_declaration (die
, cu
));
21271 dwarf2_const_value (attr
, sym
, cu
);
21272 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21275 if (attr2
&& (DW_UNSND (attr2
) != 0))
21276 list_to_add
= &global_symbols
;
21278 list_to_add
= cu
->list_in_scope
;
21282 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21285 var_decode_location (attr
, sym
, cu
);
21286 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21288 /* Fortran explicitly imports any global symbols to the local
21289 scope by DW_TAG_common_block. */
21290 if (cu
->language
== language_fortran
&& die
->parent
21291 && die
->parent
->tag
== DW_TAG_common_block
)
21294 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21295 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21296 && !dwarf2_per_objfile
->has_section_at_zero
)
21298 /* When a static variable is eliminated by the linker,
21299 the corresponding debug information is not stripped
21300 out, but the variable address is set to null;
21301 do not add such variables into symbol table. */
21303 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21305 /* Workaround gfortran PR debug/40040 - it uses
21306 DW_AT_location for variables in -fPIC libraries which may
21307 get overriden by other libraries/executable and get
21308 a different address. Resolve it by the minimal symbol
21309 which may come from inferior's executable using copy
21310 relocation. Make this workaround only for gfortran as for
21311 other compilers GDB cannot guess the minimal symbol
21312 Fortran mangling kind. */
21313 if (cu
->language
== language_fortran
&& die
->parent
21314 && die
->parent
->tag
== DW_TAG_module
21316 && startswith (cu
->producer
, "GNU Fortran"))
21317 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21319 /* A variable with DW_AT_external is never static,
21320 but it may be block-scoped. */
21321 list_to_add
= (cu
->list_in_scope
== &file_symbols
21322 ? &global_symbols
: cu
->list_in_scope
);
21325 list_to_add
= cu
->list_in_scope
;
21329 /* We do not know the address of this symbol.
21330 If it is an external symbol and we have type information
21331 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21332 The address of the variable will then be determined from
21333 the minimal symbol table whenever the variable is
21335 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21337 /* Fortran explicitly imports any global symbols to the local
21338 scope by DW_TAG_common_block. */
21339 if (cu
->language
== language_fortran
&& die
->parent
21340 && die
->parent
->tag
== DW_TAG_common_block
)
21342 /* SYMBOL_CLASS doesn't matter here because
21343 read_common_block is going to reset it. */
21345 list_to_add
= cu
->list_in_scope
;
21347 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21348 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21350 /* A variable with DW_AT_external is never static, but it
21351 may be block-scoped. */
21352 list_to_add
= (cu
->list_in_scope
== &file_symbols
21353 ? &global_symbols
: cu
->list_in_scope
);
21355 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21357 else if (!die_is_declaration (die
, cu
))
21359 /* Use the default LOC_OPTIMIZED_OUT class. */
21360 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21362 list_to_add
= cu
->list_in_scope
;
21366 case DW_TAG_formal_parameter
:
21367 /* If we are inside a function, mark this as an argument. If
21368 not, we might be looking at an argument to an inlined function
21369 when we do not have enough information to show inlined frames;
21370 pretend it's a local variable in that case so that the user can
21372 if (context_stack_depth
> 0
21373 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
21374 SYMBOL_IS_ARGUMENT (sym
) = 1;
21375 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21378 var_decode_location (attr
, sym
, cu
);
21380 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21383 dwarf2_const_value (attr
, sym
, cu
);
21386 list_to_add
= cu
->list_in_scope
;
21388 case DW_TAG_unspecified_parameters
:
21389 /* From varargs functions; gdb doesn't seem to have any
21390 interest in this information, so just ignore it for now.
21393 case DW_TAG_template_type_param
:
21395 /* Fall through. */
21396 case DW_TAG_class_type
:
21397 case DW_TAG_interface_type
:
21398 case DW_TAG_structure_type
:
21399 case DW_TAG_union_type
:
21400 case DW_TAG_set_type
:
21401 case DW_TAG_enumeration_type
:
21402 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21403 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21406 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21407 really ever be static objects: otherwise, if you try
21408 to, say, break of a class's method and you're in a file
21409 which doesn't mention that class, it won't work unless
21410 the check for all static symbols in lookup_symbol_aux
21411 saves you. See the OtherFileClass tests in
21412 gdb.c++/namespace.exp. */
21416 list_to_add
= (cu
->list_in_scope
== &file_symbols
21417 && cu
->language
== language_cplus
21418 ? &global_symbols
: cu
->list_in_scope
);
21420 /* The semantics of C++ state that "struct foo {
21421 ... }" also defines a typedef for "foo". */
21422 if (cu
->language
== language_cplus
21423 || cu
->language
== language_ada
21424 || cu
->language
== language_d
21425 || cu
->language
== language_rust
)
21427 /* The symbol's name is already allocated along
21428 with this objfile, so we don't need to
21429 duplicate it for the type. */
21430 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21431 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21436 case DW_TAG_typedef
:
21437 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21438 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21439 list_to_add
= cu
->list_in_scope
;
21441 case DW_TAG_base_type
:
21442 case DW_TAG_subrange_type
:
21443 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21444 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21445 list_to_add
= cu
->list_in_scope
;
21447 case DW_TAG_enumerator
:
21448 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21451 dwarf2_const_value (attr
, sym
, cu
);
21454 /* NOTE: carlton/2003-11-10: See comment above in the
21455 DW_TAG_class_type, etc. block. */
21457 list_to_add
= (cu
->list_in_scope
== &file_symbols
21458 && cu
->language
== language_cplus
21459 ? &global_symbols
: cu
->list_in_scope
);
21462 case DW_TAG_imported_declaration
:
21463 case DW_TAG_namespace
:
21464 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21465 list_to_add
= &global_symbols
;
21467 case DW_TAG_module
:
21468 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21469 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21470 list_to_add
= &global_symbols
;
21472 case DW_TAG_common_block
:
21473 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21474 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21475 add_symbol_to_list (sym
, cu
->list_in_scope
);
21478 /* Not a tag we recognize. Hopefully we aren't processing
21479 trash data, but since we must specifically ignore things
21480 we don't recognize, there is nothing else we should do at
21482 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
21483 dwarf_tag_name (die
->tag
));
21489 sym
->hash_next
= objfile
->template_symbols
;
21490 objfile
->template_symbols
= sym
;
21491 list_to_add
= NULL
;
21494 if (list_to_add
!= NULL
)
21495 add_symbol_to_list (sym
, list_to_add
);
21497 /* For the benefit of old versions of GCC, check for anonymous
21498 namespaces based on the demangled name. */
21499 if (!cu
->processing_has_namespace_info
21500 && cu
->language
== language_cplus
)
21501 cp_scan_for_anonymous_namespaces (sym
, objfile
);
21506 /* Given an attr with a DW_FORM_dataN value in host byte order,
21507 zero-extend it as appropriate for the symbol's type. The DWARF
21508 standard (v4) is not entirely clear about the meaning of using
21509 DW_FORM_dataN for a constant with a signed type, where the type is
21510 wider than the data. The conclusion of a discussion on the DWARF
21511 list was that this is unspecified. We choose to always zero-extend
21512 because that is the interpretation long in use by GCC. */
21515 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21516 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21518 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21519 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21520 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21521 LONGEST l
= DW_UNSND (attr
);
21523 if (bits
< sizeof (*value
) * 8)
21525 l
&= ((LONGEST
) 1 << bits
) - 1;
21528 else if (bits
== sizeof (*value
) * 8)
21532 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21533 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21540 /* Read a constant value from an attribute. Either set *VALUE, or if
21541 the value does not fit in *VALUE, set *BYTES - either already
21542 allocated on the objfile obstack, or newly allocated on OBSTACK,
21543 or, set *BATON, if we translated the constant to a location
21547 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21548 const char *name
, struct obstack
*obstack
,
21549 struct dwarf2_cu
*cu
,
21550 LONGEST
*value
, const gdb_byte
**bytes
,
21551 struct dwarf2_locexpr_baton
**baton
)
21553 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21554 struct comp_unit_head
*cu_header
= &cu
->header
;
21555 struct dwarf_block
*blk
;
21556 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21557 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21563 switch (attr
->form
)
21566 case DW_FORM_GNU_addr_index
:
21570 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21571 dwarf2_const_value_length_mismatch_complaint (name
,
21572 cu_header
->addr_size
,
21573 TYPE_LENGTH (type
));
21574 /* Symbols of this form are reasonably rare, so we just
21575 piggyback on the existing location code rather than writing
21576 a new implementation of symbol_computed_ops. */
21577 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21578 (*baton
)->per_cu
= cu
->per_cu
;
21579 gdb_assert ((*baton
)->per_cu
);
21581 (*baton
)->size
= 2 + cu_header
->addr_size
;
21582 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21583 (*baton
)->data
= data
;
21585 data
[0] = DW_OP_addr
;
21586 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21587 byte_order
, DW_ADDR (attr
));
21588 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21591 case DW_FORM_string
:
21593 case DW_FORM_GNU_str_index
:
21594 case DW_FORM_GNU_strp_alt
:
21595 /* DW_STRING is already allocated on the objfile obstack, point
21597 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21599 case DW_FORM_block1
:
21600 case DW_FORM_block2
:
21601 case DW_FORM_block4
:
21602 case DW_FORM_block
:
21603 case DW_FORM_exprloc
:
21604 case DW_FORM_data16
:
21605 blk
= DW_BLOCK (attr
);
21606 if (TYPE_LENGTH (type
) != blk
->size
)
21607 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21608 TYPE_LENGTH (type
));
21609 *bytes
= blk
->data
;
21612 /* The DW_AT_const_value attributes are supposed to carry the
21613 symbol's value "represented as it would be on the target
21614 architecture." By the time we get here, it's already been
21615 converted to host endianness, so we just need to sign- or
21616 zero-extend it as appropriate. */
21617 case DW_FORM_data1
:
21618 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21620 case DW_FORM_data2
:
21621 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21623 case DW_FORM_data4
:
21624 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21626 case DW_FORM_data8
:
21627 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21630 case DW_FORM_sdata
:
21631 case DW_FORM_implicit_const
:
21632 *value
= DW_SND (attr
);
21635 case DW_FORM_udata
:
21636 *value
= DW_UNSND (attr
);
21640 complaint (&symfile_complaints
,
21641 _("unsupported const value attribute form: '%s'"),
21642 dwarf_form_name (attr
->form
));
21649 /* Copy constant value from an attribute to a symbol. */
21652 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21653 struct dwarf2_cu
*cu
)
21655 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21657 const gdb_byte
*bytes
;
21658 struct dwarf2_locexpr_baton
*baton
;
21660 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21661 SYMBOL_PRINT_NAME (sym
),
21662 &objfile
->objfile_obstack
, cu
,
21663 &value
, &bytes
, &baton
);
21667 SYMBOL_LOCATION_BATON (sym
) = baton
;
21668 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21670 else if (bytes
!= NULL
)
21672 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21673 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21677 SYMBOL_VALUE (sym
) = value
;
21678 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21682 /* Return the type of the die in question using its DW_AT_type attribute. */
21684 static struct type
*
21685 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21687 struct attribute
*type_attr
;
21689 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21692 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21693 /* A missing DW_AT_type represents a void type. */
21694 return objfile_type (objfile
)->builtin_void
;
21697 return lookup_die_type (die
, type_attr
, cu
);
21700 /* True iff CU's producer generates GNAT Ada auxiliary information
21701 that allows to find parallel types through that information instead
21702 of having to do expensive parallel lookups by type name. */
21705 need_gnat_info (struct dwarf2_cu
*cu
)
21707 /* Assume that the Ada compiler was GNAT, which always produces
21708 the auxiliary information. */
21709 return (cu
->language
== language_ada
);
21712 /* Return the auxiliary type of the die in question using its
21713 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21714 attribute is not present. */
21716 static struct type
*
21717 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21719 struct attribute
*type_attr
;
21721 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21725 return lookup_die_type (die
, type_attr
, cu
);
21728 /* If DIE has a descriptive_type attribute, then set the TYPE's
21729 descriptive type accordingly. */
21732 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21733 struct dwarf2_cu
*cu
)
21735 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21737 if (descriptive_type
)
21739 ALLOCATE_GNAT_AUX_TYPE (type
);
21740 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21744 /* Return the containing type of the die in question using its
21745 DW_AT_containing_type attribute. */
21747 static struct type
*
21748 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21750 struct attribute
*type_attr
;
21751 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21753 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21755 error (_("Dwarf Error: Problem turning containing type into gdb type "
21756 "[in module %s]"), objfile_name (objfile
));
21758 return lookup_die_type (die
, type_attr
, cu
);
21761 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21763 static struct type
*
21764 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21766 struct dwarf2_per_objfile
*dwarf2_per_objfile
21767 = cu
->per_cu
->dwarf2_per_objfile
;
21768 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21769 char *message
, *saved
;
21771 message
= xstrprintf (_("<unknown type in %s, CU %s, DIE %s>"),
21772 objfile_name (objfile
),
21773 sect_offset_str (cu
->header
.sect_off
),
21774 sect_offset_str (die
->sect_off
));
21775 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
21776 message
, strlen (message
));
21779 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21782 /* Look up the type of DIE in CU using its type attribute ATTR.
21783 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21784 DW_AT_containing_type.
21785 If there is no type substitute an error marker. */
21787 static struct type
*
21788 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21789 struct dwarf2_cu
*cu
)
21791 struct dwarf2_per_objfile
*dwarf2_per_objfile
21792 = cu
->per_cu
->dwarf2_per_objfile
;
21793 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21794 struct type
*this_type
;
21796 gdb_assert (attr
->name
== DW_AT_type
21797 || attr
->name
== DW_AT_GNAT_descriptive_type
21798 || attr
->name
== DW_AT_containing_type
);
21800 /* First see if we have it cached. */
21802 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21804 struct dwarf2_per_cu_data
*per_cu
;
21805 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21807 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21808 dwarf2_per_objfile
);
21809 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21811 else if (attr_form_is_ref (attr
))
21813 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21815 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21817 else if (attr
->form
== DW_FORM_ref_sig8
)
21819 ULONGEST signature
= DW_SIGNATURE (attr
);
21821 return get_signatured_type (die
, signature
, cu
);
21825 complaint (&symfile_complaints
,
21826 _("Dwarf Error: Bad type attribute %s in DIE"
21827 " at %s [in module %s]"),
21828 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21829 objfile_name (objfile
));
21830 return build_error_marker_type (cu
, die
);
21833 /* If not cached we need to read it in. */
21835 if (this_type
== NULL
)
21837 struct die_info
*type_die
= NULL
;
21838 struct dwarf2_cu
*type_cu
= cu
;
21840 if (attr_form_is_ref (attr
))
21841 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21842 if (type_die
== NULL
)
21843 return build_error_marker_type (cu
, die
);
21844 /* If we find the type now, it's probably because the type came
21845 from an inter-CU reference and the type's CU got expanded before
21847 this_type
= read_type_die (type_die
, type_cu
);
21850 /* If we still don't have a type use an error marker. */
21852 if (this_type
== NULL
)
21853 return build_error_marker_type (cu
, die
);
21858 /* Return the type in DIE, CU.
21859 Returns NULL for invalid types.
21861 This first does a lookup in die_type_hash,
21862 and only reads the die in if necessary.
21864 NOTE: This can be called when reading in partial or full symbols. */
21866 static struct type
*
21867 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21869 struct type
*this_type
;
21871 this_type
= get_die_type (die
, cu
);
21875 return read_type_die_1 (die
, cu
);
21878 /* Read the type in DIE, CU.
21879 Returns NULL for invalid types. */
21881 static struct type
*
21882 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21884 struct type
*this_type
= NULL
;
21888 case DW_TAG_class_type
:
21889 case DW_TAG_interface_type
:
21890 case DW_TAG_structure_type
:
21891 case DW_TAG_union_type
:
21892 this_type
= read_structure_type (die
, cu
);
21894 case DW_TAG_enumeration_type
:
21895 this_type
= read_enumeration_type (die
, cu
);
21897 case DW_TAG_subprogram
:
21898 case DW_TAG_subroutine_type
:
21899 case DW_TAG_inlined_subroutine
:
21900 this_type
= read_subroutine_type (die
, cu
);
21902 case DW_TAG_array_type
:
21903 this_type
= read_array_type (die
, cu
);
21905 case DW_TAG_set_type
:
21906 this_type
= read_set_type (die
, cu
);
21908 case DW_TAG_pointer_type
:
21909 this_type
= read_tag_pointer_type (die
, cu
);
21911 case DW_TAG_ptr_to_member_type
:
21912 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21914 case DW_TAG_reference_type
:
21915 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21917 case DW_TAG_rvalue_reference_type
:
21918 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21920 case DW_TAG_const_type
:
21921 this_type
= read_tag_const_type (die
, cu
);
21923 case DW_TAG_volatile_type
:
21924 this_type
= read_tag_volatile_type (die
, cu
);
21926 case DW_TAG_restrict_type
:
21927 this_type
= read_tag_restrict_type (die
, cu
);
21929 case DW_TAG_string_type
:
21930 this_type
= read_tag_string_type (die
, cu
);
21932 case DW_TAG_typedef
:
21933 this_type
= read_typedef (die
, cu
);
21935 case DW_TAG_subrange_type
:
21936 this_type
= read_subrange_type (die
, cu
);
21938 case DW_TAG_base_type
:
21939 this_type
= read_base_type (die
, cu
);
21941 case DW_TAG_unspecified_type
:
21942 this_type
= read_unspecified_type (die
, cu
);
21944 case DW_TAG_namespace
:
21945 this_type
= read_namespace_type (die
, cu
);
21947 case DW_TAG_module
:
21948 this_type
= read_module_type (die
, cu
);
21950 case DW_TAG_atomic_type
:
21951 this_type
= read_tag_atomic_type (die
, cu
);
21954 complaint (&symfile_complaints
,
21955 _("unexpected tag in read_type_die: '%s'"),
21956 dwarf_tag_name (die
->tag
));
21963 /* See if we can figure out if the class lives in a namespace. We do
21964 this by looking for a member function; its demangled name will
21965 contain namespace info, if there is any.
21966 Return the computed name or NULL.
21967 Space for the result is allocated on the objfile's obstack.
21968 This is the full-die version of guess_partial_die_structure_name.
21969 In this case we know DIE has no useful parent. */
21972 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21974 struct die_info
*spec_die
;
21975 struct dwarf2_cu
*spec_cu
;
21976 struct die_info
*child
;
21977 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21980 spec_die
= die_specification (die
, &spec_cu
);
21981 if (spec_die
!= NULL
)
21987 for (child
= die
->child
;
21989 child
= child
->sibling
)
21991 if (child
->tag
== DW_TAG_subprogram
)
21993 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21995 if (linkage_name
!= NULL
)
21998 = language_class_name_from_physname (cu
->language_defn
,
22002 if (actual_name
!= NULL
)
22004 const char *die_name
= dwarf2_name (die
, cu
);
22006 if (die_name
!= NULL
22007 && strcmp (die_name
, actual_name
) != 0)
22009 /* Strip off the class name from the full name.
22010 We want the prefix. */
22011 int die_name_len
= strlen (die_name
);
22012 int actual_name_len
= strlen (actual_name
);
22014 /* Test for '::' as a sanity check. */
22015 if (actual_name_len
> die_name_len
+ 2
22016 && actual_name
[actual_name_len
22017 - die_name_len
- 1] == ':')
22018 name
= (char *) obstack_copy0 (
22019 &objfile
->per_bfd
->storage_obstack
,
22020 actual_name
, actual_name_len
- die_name_len
- 2);
22023 xfree (actual_name
);
22032 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22033 prefix part in such case. See
22034 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22036 static const char *
22037 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22039 struct attribute
*attr
;
22042 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22043 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22046 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22049 attr
= dw2_linkage_name_attr (die
, cu
);
22050 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22053 /* dwarf2_name had to be already called. */
22054 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22056 /* Strip the base name, keep any leading namespaces/classes. */
22057 base
= strrchr (DW_STRING (attr
), ':');
22058 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22061 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22062 return (char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22064 &base
[-1] - DW_STRING (attr
));
22067 /* Return the name of the namespace/class that DIE is defined within,
22068 or "" if we can't tell. The caller should not xfree the result.
22070 For example, if we're within the method foo() in the following
22080 then determine_prefix on foo's die will return "N::C". */
22082 static const char *
22083 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22085 struct dwarf2_per_objfile
*dwarf2_per_objfile
22086 = cu
->per_cu
->dwarf2_per_objfile
;
22087 struct die_info
*parent
, *spec_die
;
22088 struct dwarf2_cu
*spec_cu
;
22089 struct type
*parent_type
;
22090 const char *retval
;
22092 if (cu
->language
!= language_cplus
22093 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22094 && cu
->language
!= language_rust
)
22097 retval
= anonymous_struct_prefix (die
, cu
);
22101 /* We have to be careful in the presence of DW_AT_specification.
22102 For example, with GCC 3.4, given the code
22106 // Definition of N::foo.
22110 then we'll have a tree of DIEs like this:
22112 1: DW_TAG_compile_unit
22113 2: DW_TAG_namespace // N
22114 3: DW_TAG_subprogram // declaration of N::foo
22115 4: DW_TAG_subprogram // definition of N::foo
22116 DW_AT_specification // refers to die #3
22118 Thus, when processing die #4, we have to pretend that we're in
22119 the context of its DW_AT_specification, namely the contex of die
22122 spec_die
= die_specification (die
, &spec_cu
);
22123 if (spec_die
== NULL
)
22124 parent
= die
->parent
;
22127 parent
= spec_die
->parent
;
22131 if (parent
== NULL
)
22133 else if (parent
->building_fullname
)
22136 const char *parent_name
;
22138 /* It has been seen on RealView 2.2 built binaries,
22139 DW_TAG_template_type_param types actually _defined_ as
22140 children of the parent class:
22143 template class <class Enum> Class{};
22144 Class<enum E> class_e;
22146 1: DW_TAG_class_type (Class)
22147 2: DW_TAG_enumeration_type (E)
22148 3: DW_TAG_enumerator (enum1:0)
22149 3: DW_TAG_enumerator (enum2:1)
22151 2: DW_TAG_template_type_param
22152 DW_AT_type DW_FORM_ref_udata (E)
22154 Besides being broken debug info, it can put GDB into an
22155 infinite loop. Consider:
22157 When we're building the full name for Class<E>, we'll start
22158 at Class, and go look over its template type parameters,
22159 finding E. We'll then try to build the full name of E, and
22160 reach here. We're now trying to build the full name of E,
22161 and look over the parent DIE for containing scope. In the
22162 broken case, if we followed the parent DIE of E, we'd again
22163 find Class, and once again go look at its template type
22164 arguments, etc., etc. Simply don't consider such parent die
22165 as source-level parent of this die (it can't be, the language
22166 doesn't allow it), and break the loop here. */
22167 name
= dwarf2_name (die
, cu
);
22168 parent_name
= dwarf2_name (parent
, cu
);
22169 complaint (&symfile_complaints
,
22170 _("template param type '%s' defined within parent '%s'"),
22171 name
? name
: "<unknown>",
22172 parent_name
? parent_name
: "<unknown>");
22176 switch (parent
->tag
)
22178 case DW_TAG_namespace
:
22179 parent_type
= read_type_die (parent
, cu
);
22180 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22181 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22182 Work around this problem here. */
22183 if (cu
->language
== language_cplus
22184 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
22186 /* We give a name to even anonymous namespaces. */
22187 return TYPE_TAG_NAME (parent_type
);
22188 case DW_TAG_class_type
:
22189 case DW_TAG_interface_type
:
22190 case DW_TAG_structure_type
:
22191 case DW_TAG_union_type
:
22192 case DW_TAG_module
:
22193 parent_type
= read_type_die (parent
, cu
);
22194 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22195 return TYPE_TAG_NAME (parent_type
);
22197 /* An anonymous structure is only allowed non-static data
22198 members; no typedefs, no member functions, et cetera.
22199 So it does not need a prefix. */
22201 case DW_TAG_compile_unit
:
22202 case DW_TAG_partial_unit
:
22203 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22204 if (cu
->language
== language_cplus
22205 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
22206 && die
->child
!= NULL
22207 && (die
->tag
== DW_TAG_class_type
22208 || die
->tag
== DW_TAG_structure_type
22209 || die
->tag
== DW_TAG_union_type
))
22211 char *name
= guess_full_die_structure_name (die
, cu
);
22216 case DW_TAG_enumeration_type
:
22217 parent_type
= read_type_die (parent
, cu
);
22218 if (TYPE_DECLARED_CLASS (parent_type
))
22220 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22221 return TYPE_TAG_NAME (parent_type
);
22224 /* Fall through. */
22226 return determine_prefix (parent
, cu
);
22230 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22231 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22232 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22233 an obconcat, otherwise allocate storage for the result. The CU argument is
22234 used to determine the language and hence, the appropriate separator. */
22236 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22239 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22240 int physname
, struct dwarf2_cu
*cu
)
22242 const char *lead
= "";
22245 if (suffix
== NULL
|| suffix
[0] == '\0'
22246 || prefix
== NULL
|| prefix
[0] == '\0')
22248 else if (cu
->language
== language_d
)
22250 /* For D, the 'main' function could be defined in any module, but it
22251 should never be prefixed. */
22252 if (strcmp (suffix
, "D main") == 0)
22260 else if (cu
->language
== language_fortran
&& physname
)
22262 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22263 DW_AT_MIPS_linkage_name is preferred and used instead. */
22271 if (prefix
== NULL
)
22273 if (suffix
== NULL
)
22280 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22282 strcpy (retval
, lead
);
22283 strcat (retval
, prefix
);
22284 strcat (retval
, sep
);
22285 strcat (retval
, suffix
);
22290 /* We have an obstack. */
22291 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22295 /* Return sibling of die, NULL if no sibling. */
22297 static struct die_info
*
22298 sibling_die (struct die_info
*die
)
22300 return die
->sibling
;
22303 /* Get name of a die, return NULL if not found. */
22305 static const char *
22306 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22307 struct obstack
*obstack
)
22309 if (name
&& cu
->language
== language_cplus
)
22311 std::string canon_name
= cp_canonicalize_string (name
);
22313 if (!canon_name
.empty ())
22315 if (canon_name
!= name
)
22316 name
= (const char *) obstack_copy0 (obstack
,
22317 canon_name
.c_str (),
22318 canon_name
.length ());
22325 /* Get name of a die, return NULL if not found.
22326 Anonymous namespaces are converted to their magic string. */
22328 static const char *
22329 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22331 struct attribute
*attr
;
22332 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22334 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22335 if ((!attr
|| !DW_STRING (attr
))
22336 && die
->tag
!= DW_TAG_namespace
22337 && die
->tag
!= DW_TAG_class_type
22338 && die
->tag
!= DW_TAG_interface_type
22339 && die
->tag
!= DW_TAG_structure_type
22340 && die
->tag
!= DW_TAG_union_type
)
22345 case DW_TAG_compile_unit
:
22346 case DW_TAG_partial_unit
:
22347 /* Compilation units have a DW_AT_name that is a filename, not
22348 a source language identifier. */
22349 case DW_TAG_enumeration_type
:
22350 case DW_TAG_enumerator
:
22351 /* These tags always have simple identifiers already; no need
22352 to canonicalize them. */
22353 return DW_STRING (attr
);
22355 case DW_TAG_namespace
:
22356 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22357 return DW_STRING (attr
);
22358 return CP_ANONYMOUS_NAMESPACE_STR
;
22360 case DW_TAG_class_type
:
22361 case DW_TAG_interface_type
:
22362 case DW_TAG_structure_type
:
22363 case DW_TAG_union_type
:
22364 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22365 structures or unions. These were of the form "._%d" in GCC 4.1,
22366 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22367 and GCC 4.4. We work around this problem by ignoring these. */
22368 if (attr
&& DW_STRING (attr
)
22369 && (startswith (DW_STRING (attr
), "._")
22370 || startswith (DW_STRING (attr
), "<anonymous")))
22373 /* GCC might emit a nameless typedef that has a linkage name. See
22374 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22375 if (!attr
|| DW_STRING (attr
) == NULL
)
22377 char *demangled
= NULL
;
22379 attr
= dw2_linkage_name_attr (die
, cu
);
22380 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22383 /* Avoid demangling DW_STRING (attr) the second time on a second
22384 call for the same DIE. */
22385 if (!DW_STRING_IS_CANONICAL (attr
))
22386 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22392 /* FIXME: we already did this for the partial symbol... */
22395 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22396 demangled
, strlen (demangled
)));
22397 DW_STRING_IS_CANONICAL (attr
) = 1;
22400 /* Strip any leading namespaces/classes, keep only the base name.
22401 DW_AT_name for named DIEs does not contain the prefixes. */
22402 base
= strrchr (DW_STRING (attr
), ':');
22403 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22406 return DW_STRING (attr
);
22415 if (!DW_STRING_IS_CANONICAL (attr
))
22418 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22419 &objfile
->per_bfd
->storage_obstack
);
22420 DW_STRING_IS_CANONICAL (attr
) = 1;
22422 return DW_STRING (attr
);
22425 /* Return the die that this die in an extension of, or NULL if there
22426 is none. *EXT_CU is the CU containing DIE on input, and the CU
22427 containing the return value on output. */
22429 static struct die_info
*
22430 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22432 struct attribute
*attr
;
22434 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22438 return follow_die_ref (die
, attr
, ext_cu
);
22441 /* Convert a DIE tag into its string name. */
22443 static const char *
22444 dwarf_tag_name (unsigned tag
)
22446 const char *name
= get_DW_TAG_name (tag
);
22449 return "DW_TAG_<unknown>";
22454 /* Convert a DWARF attribute code into its string name. */
22456 static const char *
22457 dwarf_attr_name (unsigned attr
)
22461 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22462 if (attr
== DW_AT_MIPS_fde
)
22463 return "DW_AT_MIPS_fde";
22465 if (attr
== DW_AT_HP_block_index
)
22466 return "DW_AT_HP_block_index";
22469 name
= get_DW_AT_name (attr
);
22472 return "DW_AT_<unknown>";
22477 /* Convert a DWARF value form code into its string name. */
22479 static const char *
22480 dwarf_form_name (unsigned form
)
22482 const char *name
= get_DW_FORM_name (form
);
22485 return "DW_FORM_<unknown>";
22490 static const char *
22491 dwarf_bool_name (unsigned mybool
)
22499 /* Convert a DWARF type code into its string name. */
22501 static const char *
22502 dwarf_type_encoding_name (unsigned enc
)
22504 const char *name
= get_DW_ATE_name (enc
);
22507 return "DW_ATE_<unknown>";
22513 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22517 print_spaces (indent
, f
);
22518 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22519 dwarf_tag_name (die
->tag
), die
->abbrev
,
22520 sect_offset_str (die
->sect_off
));
22522 if (die
->parent
!= NULL
)
22524 print_spaces (indent
, f
);
22525 fprintf_unfiltered (f
, " parent at offset: %s\n",
22526 sect_offset_str (die
->parent
->sect_off
));
22529 print_spaces (indent
, f
);
22530 fprintf_unfiltered (f
, " has children: %s\n",
22531 dwarf_bool_name (die
->child
!= NULL
));
22533 print_spaces (indent
, f
);
22534 fprintf_unfiltered (f
, " attributes:\n");
22536 for (i
= 0; i
< die
->num_attrs
; ++i
)
22538 print_spaces (indent
, f
);
22539 fprintf_unfiltered (f
, " %s (%s) ",
22540 dwarf_attr_name (die
->attrs
[i
].name
),
22541 dwarf_form_name (die
->attrs
[i
].form
));
22543 switch (die
->attrs
[i
].form
)
22546 case DW_FORM_GNU_addr_index
:
22547 fprintf_unfiltered (f
, "address: ");
22548 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22550 case DW_FORM_block2
:
22551 case DW_FORM_block4
:
22552 case DW_FORM_block
:
22553 case DW_FORM_block1
:
22554 fprintf_unfiltered (f
, "block: size %s",
22555 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22557 case DW_FORM_exprloc
:
22558 fprintf_unfiltered (f
, "expression: size %s",
22559 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22561 case DW_FORM_data16
:
22562 fprintf_unfiltered (f
, "constant of 16 bytes");
22564 case DW_FORM_ref_addr
:
22565 fprintf_unfiltered (f
, "ref address: ");
22566 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22568 case DW_FORM_GNU_ref_alt
:
22569 fprintf_unfiltered (f
, "alt ref address: ");
22570 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22576 case DW_FORM_ref_udata
:
22577 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22578 (long) (DW_UNSND (&die
->attrs
[i
])));
22580 case DW_FORM_data1
:
22581 case DW_FORM_data2
:
22582 case DW_FORM_data4
:
22583 case DW_FORM_data8
:
22584 case DW_FORM_udata
:
22585 case DW_FORM_sdata
:
22586 fprintf_unfiltered (f
, "constant: %s",
22587 pulongest (DW_UNSND (&die
->attrs
[i
])));
22589 case DW_FORM_sec_offset
:
22590 fprintf_unfiltered (f
, "section offset: %s",
22591 pulongest (DW_UNSND (&die
->attrs
[i
])));
22593 case DW_FORM_ref_sig8
:
22594 fprintf_unfiltered (f
, "signature: %s",
22595 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22597 case DW_FORM_string
:
22599 case DW_FORM_line_strp
:
22600 case DW_FORM_GNU_str_index
:
22601 case DW_FORM_GNU_strp_alt
:
22602 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22603 DW_STRING (&die
->attrs
[i
])
22604 ? DW_STRING (&die
->attrs
[i
]) : "",
22605 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22608 if (DW_UNSND (&die
->attrs
[i
]))
22609 fprintf_unfiltered (f
, "flag: TRUE");
22611 fprintf_unfiltered (f
, "flag: FALSE");
22613 case DW_FORM_flag_present
:
22614 fprintf_unfiltered (f
, "flag: TRUE");
22616 case DW_FORM_indirect
:
22617 /* The reader will have reduced the indirect form to
22618 the "base form" so this form should not occur. */
22619 fprintf_unfiltered (f
,
22620 "unexpected attribute form: DW_FORM_indirect");
22622 case DW_FORM_implicit_const
:
22623 fprintf_unfiltered (f
, "constant: %s",
22624 plongest (DW_SND (&die
->attrs
[i
])));
22627 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22628 die
->attrs
[i
].form
);
22631 fprintf_unfiltered (f
, "\n");
22636 dump_die_for_error (struct die_info
*die
)
22638 dump_die_shallow (gdb_stderr
, 0, die
);
22642 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22644 int indent
= level
* 4;
22646 gdb_assert (die
!= NULL
);
22648 if (level
>= max_level
)
22651 dump_die_shallow (f
, indent
, die
);
22653 if (die
->child
!= NULL
)
22655 print_spaces (indent
, f
);
22656 fprintf_unfiltered (f
, " Children:");
22657 if (level
+ 1 < max_level
)
22659 fprintf_unfiltered (f
, "\n");
22660 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22664 fprintf_unfiltered (f
,
22665 " [not printed, max nesting level reached]\n");
22669 if (die
->sibling
!= NULL
&& level
> 0)
22671 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22675 /* This is called from the pdie macro in gdbinit.in.
22676 It's not static so gcc will keep a copy callable from gdb. */
22679 dump_die (struct die_info
*die
, int max_level
)
22681 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22685 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22689 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22690 to_underlying (die
->sect_off
),
22696 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22700 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22702 if (attr_form_is_ref (attr
))
22703 return (sect_offset
) DW_UNSND (attr
);
22705 complaint (&symfile_complaints
,
22706 _("unsupported die ref attribute form: '%s'"),
22707 dwarf_form_name (attr
->form
));
22711 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22712 * the value held by the attribute is not constant. */
22715 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22717 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22718 return DW_SND (attr
);
22719 else if (attr
->form
== DW_FORM_udata
22720 || attr
->form
== DW_FORM_data1
22721 || attr
->form
== DW_FORM_data2
22722 || attr
->form
== DW_FORM_data4
22723 || attr
->form
== DW_FORM_data8
)
22724 return DW_UNSND (attr
);
22727 /* For DW_FORM_data16 see attr_form_is_constant. */
22728 complaint (&symfile_complaints
,
22729 _("Attribute value is not a constant (%s)"),
22730 dwarf_form_name (attr
->form
));
22731 return default_value
;
22735 /* Follow reference or signature attribute ATTR of SRC_DIE.
22736 On entry *REF_CU is the CU of SRC_DIE.
22737 On exit *REF_CU is the CU of the result. */
22739 static struct die_info
*
22740 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22741 struct dwarf2_cu
**ref_cu
)
22743 struct die_info
*die
;
22745 if (attr_form_is_ref (attr
))
22746 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22747 else if (attr
->form
== DW_FORM_ref_sig8
)
22748 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22751 dump_die_for_error (src_die
);
22752 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22753 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22759 /* Follow reference OFFSET.
22760 On entry *REF_CU is the CU of the source die referencing OFFSET.
22761 On exit *REF_CU is the CU of the result.
22762 Returns NULL if OFFSET is invalid. */
22764 static struct die_info
*
22765 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22766 struct dwarf2_cu
**ref_cu
)
22768 struct die_info temp_die
;
22769 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22770 struct dwarf2_per_objfile
*dwarf2_per_objfile
22771 = cu
->per_cu
->dwarf2_per_objfile
;
22773 gdb_assert (cu
->per_cu
!= NULL
);
22777 if (cu
->per_cu
->is_debug_types
)
22779 /* .debug_types CUs cannot reference anything outside their CU.
22780 If they need to, they have to reference a signatured type via
22781 DW_FORM_ref_sig8. */
22782 if (!offset_in_cu_p (&cu
->header
, sect_off
))
22785 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22786 || !offset_in_cu_p (&cu
->header
, sect_off
))
22788 struct dwarf2_per_cu_data
*per_cu
;
22790 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22791 dwarf2_per_objfile
);
22793 /* If necessary, add it to the queue and load its DIEs. */
22794 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22795 load_full_comp_unit (per_cu
, cu
->language
);
22797 target_cu
= per_cu
->cu
;
22799 else if (cu
->dies
== NULL
)
22801 /* We're loading full DIEs during partial symbol reading. */
22802 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22803 load_full_comp_unit (cu
->per_cu
, language_minimal
);
22806 *ref_cu
= target_cu
;
22807 temp_die
.sect_off
= sect_off
;
22808 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22810 to_underlying (sect_off
));
22813 /* Follow reference attribute ATTR of SRC_DIE.
22814 On entry *REF_CU is the CU of SRC_DIE.
22815 On exit *REF_CU is the CU of the result. */
22817 static struct die_info
*
22818 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22819 struct dwarf2_cu
**ref_cu
)
22821 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22822 struct dwarf2_cu
*cu
= *ref_cu
;
22823 struct die_info
*die
;
22825 die
= follow_die_offset (sect_off
,
22826 (attr
->form
== DW_FORM_GNU_ref_alt
22827 || cu
->per_cu
->is_dwz
),
22830 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22831 "at %s [in module %s]"),
22832 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22833 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22838 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22839 Returned value is intended for DW_OP_call*. Returned
22840 dwarf2_locexpr_baton->data has lifetime of
22841 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22843 struct dwarf2_locexpr_baton
22844 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22845 struct dwarf2_per_cu_data
*per_cu
,
22846 CORE_ADDR (*get_frame_pc
) (void *baton
),
22849 struct dwarf2_cu
*cu
;
22850 struct die_info
*die
;
22851 struct attribute
*attr
;
22852 struct dwarf2_locexpr_baton retval
;
22853 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22854 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22856 if (per_cu
->cu
== NULL
)
22861 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22862 Instead just throw an error, not much else we can do. */
22863 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22864 sect_offset_str (sect_off
), objfile_name (objfile
));
22867 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22869 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22870 sect_offset_str (sect_off
), objfile_name (objfile
));
22872 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22875 /* DWARF: "If there is no such attribute, then there is no effect.".
22876 DATA is ignored if SIZE is 0. */
22878 retval
.data
= NULL
;
22881 else if (attr_form_is_section_offset (attr
))
22883 struct dwarf2_loclist_baton loclist_baton
;
22884 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22887 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22889 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22891 retval
.size
= size
;
22895 if (!attr_form_is_block (attr
))
22896 error (_("Dwarf Error: DIE at %s referenced in module %s "
22897 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22898 sect_offset_str (sect_off
), objfile_name (objfile
));
22900 retval
.data
= DW_BLOCK (attr
)->data
;
22901 retval
.size
= DW_BLOCK (attr
)->size
;
22903 retval
.per_cu
= cu
->per_cu
;
22905 age_cached_comp_units (dwarf2_per_objfile
);
22910 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
22913 struct dwarf2_locexpr_baton
22914 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22915 struct dwarf2_per_cu_data
*per_cu
,
22916 CORE_ADDR (*get_frame_pc
) (void *baton
),
22919 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22921 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22924 /* Write a constant of a given type as target-ordered bytes into
22927 static const gdb_byte
*
22928 write_constant_as_bytes (struct obstack
*obstack
,
22929 enum bfd_endian byte_order
,
22936 *len
= TYPE_LENGTH (type
);
22937 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22938 store_unsigned_integer (result
, *len
, byte_order
, value
);
22943 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
22944 pointer to the constant bytes and set LEN to the length of the
22945 data. If memory is needed, allocate it on OBSTACK. If the DIE
22946 does not have a DW_AT_const_value, return NULL. */
22949 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22950 struct dwarf2_per_cu_data
*per_cu
,
22951 struct obstack
*obstack
,
22954 struct dwarf2_cu
*cu
;
22955 struct die_info
*die
;
22956 struct attribute
*attr
;
22957 const gdb_byte
*result
= NULL
;
22960 enum bfd_endian byte_order
;
22961 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22963 if (per_cu
->cu
== NULL
)
22968 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22969 Instead just throw an error, not much else we can do. */
22970 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22971 sect_offset_str (sect_off
), objfile_name (objfile
));
22974 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22976 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22977 sect_offset_str (sect_off
), objfile_name (objfile
));
22979 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22983 byte_order
= (bfd_big_endian (objfile
->obfd
)
22984 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22986 switch (attr
->form
)
22989 case DW_FORM_GNU_addr_index
:
22993 *len
= cu
->header
.addr_size
;
22994 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22995 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22999 case DW_FORM_string
:
23001 case DW_FORM_GNU_str_index
:
23002 case DW_FORM_GNU_strp_alt
:
23003 /* DW_STRING is already allocated on the objfile obstack, point
23005 result
= (const gdb_byte
*) DW_STRING (attr
);
23006 *len
= strlen (DW_STRING (attr
));
23008 case DW_FORM_block1
:
23009 case DW_FORM_block2
:
23010 case DW_FORM_block4
:
23011 case DW_FORM_block
:
23012 case DW_FORM_exprloc
:
23013 case DW_FORM_data16
:
23014 result
= DW_BLOCK (attr
)->data
;
23015 *len
= DW_BLOCK (attr
)->size
;
23018 /* The DW_AT_const_value attributes are supposed to carry the
23019 symbol's value "represented as it would be on the target
23020 architecture." By the time we get here, it's already been
23021 converted to host endianness, so we just need to sign- or
23022 zero-extend it as appropriate. */
23023 case DW_FORM_data1
:
23024 type
= die_type (die
, cu
);
23025 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23026 if (result
== NULL
)
23027 result
= write_constant_as_bytes (obstack
, byte_order
,
23030 case DW_FORM_data2
:
23031 type
= die_type (die
, cu
);
23032 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23033 if (result
== NULL
)
23034 result
= write_constant_as_bytes (obstack
, byte_order
,
23037 case DW_FORM_data4
:
23038 type
= die_type (die
, cu
);
23039 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23040 if (result
== NULL
)
23041 result
= write_constant_as_bytes (obstack
, byte_order
,
23044 case DW_FORM_data8
:
23045 type
= die_type (die
, cu
);
23046 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23047 if (result
== NULL
)
23048 result
= write_constant_as_bytes (obstack
, byte_order
,
23052 case DW_FORM_sdata
:
23053 case DW_FORM_implicit_const
:
23054 type
= die_type (die
, cu
);
23055 result
= write_constant_as_bytes (obstack
, byte_order
,
23056 type
, DW_SND (attr
), len
);
23059 case DW_FORM_udata
:
23060 type
= die_type (die
, cu
);
23061 result
= write_constant_as_bytes (obstack
, byte_order
,
23062 type
, DW_UNSND (attr
), len
);
23066 complaint (&symfile_complaints
,
23067 _("unsupported const value attribute form: '%s'"),
23068 dwarf_form_name (attr
->form
));
23075 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23076 valid type for this die is found. */
23079 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23080 struct dwarf2_per_cu_data
*per_cu
)
23082 struct dwarf2_cu
*cu
;
23083 struct die_info
*die
;
23085 if (per_cu
->cu
== NULL
)
23091 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23095 return die_type (die
, cu
);
23098 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23102 dwarf2_get_die_type (cu_offset die_offset
,
23103 struct dwarf2_per_cu_data
*per_cu
)
23105 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23106 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23109 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23110 On entry *REF_CU is the CU of SRC_DIE.
23111 On exit *REF_CU is the CU of the result.
23112 Returns NULL if the referenced DIE isn't found. */
23114 static struct die_info
*
23115 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23116 struct dwarf2_cu
**ref_cu
)
23118 struct die_info temp_die
;
23119 struct dwarf2_cu
*sig_cu
;
23120 struct die_info
*die
;
23122 /* While it might be nice to assert sig_type->type == NULL here,
23123 we can get here for DW_AT_imported_declaration where we need
23124 the DIE not the type. */
23126 /* If necessary, add it to the queue and load its DIEs. */
23128 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23129 read_signatured_type (sig_type
);
23131 sig_cu
= sig_type
->per_cu
.cu
;
23132 gdb_assert (sig_cu
!= NULL
);
23133 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23134 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23135 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23136 to_underlying (temp_die
.sect_off
));
23139 struct dwarf2_per_objfile
*dwarf2_per_objfile
23140 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23142 /* For .gdb_index version 7 keep track of included TUs.
23143 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23144 if (dwarf2_per_objfile
->index_table
!= NULL
23145 && dwarf2_per_objfile
->index_table
->version
<= 7)
23147 VEC_safe_push (dwarf2_per_cu_ptr
,
23148 (*ref_cu
)->per_cu
->imported_symtabs
,
23159 /* Follow signatured type referenced by ATTR in SRC_DIE.
23160 On entry *REF_CU is the CU of SRC_DIE.
23161 On exit *REF_CU is the CU of the result.
23162 The result is the DIE of the type.
23163 If the referenced type cannot be found an error is thrown. */
23165 static struct die_info
*
23166 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23167 struct dwarf2_cu
**ref_cu
)
23169 ULONGEST signature
= DW_SIGNATURE (attr
);
23170 struct signatured_type
*sig_type
;
23171 struct die_info
*die
;
23173 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23175 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23176 /* sig_type will be NULL if the signatured type is missing from
23178 if (sig_type
== NULL
)
23180 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23181 " from DIE at %s [in module %s]"),
23182 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23183 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23186 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23189 dump_die_for_error (src_die
);
23190 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23191 " from DIE at %s [in module %s]"),
23192 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23193 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23199 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23200 reading in and processing the type unit if necessary. */
23202 static struct type
*
23203 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23204 struct dwarf2_cu
*cu
)
23206 struct dwarf2_per_objfile
*dwarf2_per_objfile
23207 = cu
->per_cu
->dwarf2_per_objfile
;
23208 struct signatured_type
*sig_type
;
23209 struct dwarf2_cu
*type_cu
;
23210 struct die_info
*type_die
;
23213 sig_type
= lookup_signatured_type (cu
, signature
);
23214 /* sig_type will be NULL if the signatured type is missing from
23216 if (sig_type
== NULL
)
23218 complaint (&symfile_complaints
,
23219 _("Dwarf Error: Cannot find signatured DIE %s referenced"
23220 " from DIE at %s [in module %s]"),
23221 hex_string (signature
), sect_offset_str (die
->sect_off
),
23222 objfile_name (dwarf2_per_objfile
->objfile
));
23223 return build_error_marker_type (cu
, die
);
23226 /* If we already know the type we're done. */
23227 if (sig_type
->type
!= NULL
)
23228 return sig_type
->type
;
23231 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23232 if (type_die
!= NULL
)
23234 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23235 is created. This is important, for example, because for c++ classes
23236 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23237 type
= read_type_die (type_die
, type_cu
);
23240 complaint (&symfile_complaints
,
23241 _("Dwarf Error: Cannot build signatured type %s"
23242 " referenced from DIE at %s [in module %s]"),
23243 hex_string (signature
), sect_offset_str (die
->sect_off
),
23244 objfile_name (dwarf2_per_objfile
->objfile
));
23245 type
= build_error_marker_type (cu
, die
);
23250 complaint (&symfile_complaints
,
23251 _("Dwarf Error: Problem reading signatured DIE %s referenced"
23252 " from DIE at %s [in module %s]"),
23253 hex_string (signature
), sect_offset_str (die
->sect_off
),
23254 objfile_name (dwarf2_per_objfile
->objfile
));
23255 type
= build_error_marker_type (cu
, die
);
23257 sig_type
->type
= type
;
23262 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23263 reading in and processing the type unit if necessary. */
23265 static struct type
*
23266 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23267 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23269 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23270 if (attr_form_is_ref (attr
))
23272 struct dwarf2_cu
*type_cu
= cu
;
23273 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23275 return read_type_die (type_die
, type_cu
);
23277 else if (attr
->form
== DW_FORM_ref_sig8
)
23279 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23283 struct dwarf2_per_objfile
*dwarf2_per_objfile
23284 = cu
->per_cu
->dwarf2_per_objfile
;
23286 complaint (&symfile_complaints
,
23287 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23288 " at %s [in module %s]"),
23289 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23290 objfile_name (dwarf2_per_objfile
->objfile
));
23291 return build_error_marker_type (cu
, die
);
23295 /* Load the DIEs associated with type unit PER_CU into memory. */
23298 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23300 struct signatured_type
*sig_type
;
23302 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23303 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23305 /* We have the per_cu, but we need the signatured_type.
23306 Fortunately this is an easy translation. */
23307 gdb_assert (per_cu
->is_debug_types
);
23308 sig_type
= (struct signatured_type
*) per_cu
;
23310 gdb_assert (per_cu
->cu
== NULL
);
23312 read_signatured_type (sig_type
);
23314 gdb_assert (per_cu
->cu
!= NULL
);
23317 /* die_reader_func for read_signatured_type.
23318 This is identical to load_full_comp_unit_reader,
23319 but is kept separate for now. */
23322 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23323 const gdb_byte
*info_ptr
,
23324 struct die_info
*comp_unit_die
,
23328 struct dwarf2_cu
*cu
= reader
->cu
;
23330 gdb_assert (cu
->die_hash
== NULL
);
23332 htab_create_alloc_ex (cu
->header
.length
/ 12,
23336 &cu
->comp_unit_obstack
,
23337 hashtab_obstack_allocate
,
23338 dummy_obstack_deallocate
);
23341 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23342 &info_ptr
, comp_unit_die
);
23343 cu
->dies
= comp_unit_die
;
23344 /* comp_unit_die is not stored in die_hash, no need. */
23346 /* We try not to read any attributes in this function, because not
23347 all CUs needed for references have been loaded yet, and symbol
23348 table processing isn't initialized. But we have to set the CU language,
23349 or we won't be able to build types correctly.
23350 Similarly, if we do not read the producer, we can not apply
23351 producer-specific interpretation. */
23352 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23355 /* Read in a signatured type and build its CU and DIEs.
23356 If the type is a stub for the real type in a DWO file,
23357 read in the real type from the DWO file as well. */
23360 read_signatured_type (struct signatured_type
*sig_type
)
23362 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23364 gdb_assert (per_cu
->is_debug_types
);
23365 gdb_assert (per_cu
->cu
== NULL
);
23367 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
23368 read_signatured_type_reader
, NULL
);
23369 sig_type
->per_cu
.tu_read
= 1;
23372 /* Decode simple location descriptions.
23373 Given a pointer to a dwarf block that defines a location, compute
23374 the location and return the value.
23376 NOTE drow/2003-11-18: This function is called in two situations
23377 now: for the address of static or global variables (partial symbols
23378 only) and for offsets into structures which are expected to be
23379 (more or less) constant. The partial symbol case should go away,
23380 and only the constant case should remain. That will let this
23381 function complain more accurately. A few special modes are allowed
23382 without complaint for global variables (for instance, global
23383 register values and thread-local values).
23385 A location description containing no operations indicates that the
23386 object is optimized out. The return value is 0 for that case.
23387 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23388 callers will only want a very basic result and this can become a
23391 Note that stack[0] is unused except as a default error return. */
23394 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23396 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23398 size_t size
= blk
->size
;
23399 const gdb_byte
*data
= blk
->data
;
23400 CORE_ADDR stack
[64];
23402 unsigned int bytes_read
, unsnd
;
23408 stack
[++stacki
] = 0;
23447 stack
[++stacki
] = op
- DW_OP_lit0
;
23482 stack
[++stacki
] = op
- DW_OP_reg0
;
23484 dwarf2_complex_location_expr_complaint ();
23488 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23490 stack
[++stacki
] = unsnd
;
23492 dwarf2_complex_location_expr_complaint ();
23496 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
23501 case DW_OP_const1u
:
23502 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23506 case DW_OP_const1s
:
23507 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23511 case DW_OP_const2u
:
23512 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23516 case DW_OP_const2s
:
23517 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23521 case DW_OP_const4u
:
23522 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23526 case DW_OP_const4s
:
23527 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23531 case DW_OP_const8u
:
23532 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23537 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23543 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23548 stack
[stacki
+ 1] = stack
[stacki
];
23553 stack
[stacki
- 1] += stack
[stacki
];
23557 case DW_OP_plus_uconst
:
23558 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23564 stack
[stacki
- 1] -= stack
[stacki
];
23569 /* If we're not the last op, then we definitely can't encode
23570 this using GDB's address_class enum. This is valid for partial
23571 global symbols, although the variable's address will be bogus
23574 dwarf2_complex_location_expr_complaint ();
23577 case DW_OP_GNU_push_tls_address
:
23578 case DW_OP_form_tls_address
:
23579 /* The top of the stack has the offset from the beginning
23580 of the thread control block at which the variable is located. */
23581 /* Nothing should follow this operator, so the top of stack would
23583 /* This is valid for partial global symbols, but the variable's
23584 address will be bogus in the psymtab. Make it always at least
23585 non-zero to not look as a variable garbage collected by linker
23586 which have DW_OP_addr 0. */
23588 dwarf2_complex_location_expr_complaint ();
23592 case DW_OP_GNU_uninit
:
23595 case DW_OP_GNU_addr_index
:
23596 case DW_OP_GNU_const_index
:
23597 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23604 const char *name
= get_DW_OP_name (op
);
23607 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
23610 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
23614 return (stack
[stacki
]);
23617 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23618 outside of the allocated space. Also enforce minimum>0. */
23619 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23621 complaint (&symfile_complaints
,
23622 _("location description stack overflow"));
23628 complaint (&symfile_complaints
,
23629 _("location description stack underflow"));
23633 return (stack
[stacki
]);
23636 /* memory allocation interface */
23638 static struct dwarf_block
*
23639 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23641 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23644 static struct die_info
*
23645 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23647 struct die_info
*die
;
23648 size_t size
= sizeof (struct die_info
);
23651 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23653 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23654 memset (die
, 0, sizeof (struct die_info
));
23659 /* Macro support. */
23661 /* Return file name relative to the compilation directory of file number I in
23662 *LH's file name table. The result is allocated using xmalloc; the caller is
23663 responsible for freeing it. */
23666 file_file_name (int file
, struct line_header
*lh
)
23668 /* Is the file number a valid index into the line header's file name
23669 table? Remember that file numbers start with one, not zero. */
23670 if (1 <= file
&& file
<= lh
->file_names
.size ())
23672 const file_entry
&fe
= lh
->file_names
[file
- 1];
23674 if (!IS_ABSOLUTE_PATH (fe
.name
))
23676 const char *dir
= fe
.include_dir (lh
);
23678 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
23680 return xstrdup (fe
.name
);
23684 /* The compiler produced a bogus file number. We can at least
23685 record the macro definitions made in the file, even if we
23686 won't be able to find the file by name. */
23687 char fake_name
[80];
23689 xsnprintf (fake_name
, sizeof (fake_name
),
23690 "<bad macro file number %d>", file
);
23692 complaint (&symfile_complaints
,
23693 _("bad file number in macro information (%d)"),
23696 return xstrdup (fake_name
);
23700 /* Return the full name of file number I in *LH's file name table.
23701 Use COMP_DIR as the name of the current directory of the
23702 compilation. The result is allocated using xmalloc; the caller is
23703 responsible for freeing it. */
23705 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
23707 /* Is the file number a valid index into the line header's file name
23708 table? Remember that file numbers start with one, not zero. */
23709 if (1 <= file
&& file
<= lh
->file_names
.size ())
23711 char *relative
= file_file_name (file
, lh
);
23713 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
23715 return reconcat (relative
, comp_dir
, SLASH_STRING
,
23716 relative
, (char *) NULL
);
23719 return file_file_name (file
, lh
);
23723 static struct macro_source_file
*
23724 macro_start_file (int file
, int line
,
23725 struct macro_source_file
*current_file
,
23726 struct line_header
*lh
)
23728 /* File name relative to the compilation directory of this source file. */
23729 char *file_name
= file_file_name (file
, lh
);
23731 if (! current_file
)
23733 /* Note: We don't create a macro table for this compilation unit
23734 at all until we actually get a filename. */
23735 struct macro_table
*macro_table
= get_macro_table ();
23737 /* If we have no current file, then this must be the start_file
23738 directive for the compilation unit's main source file. */
23739 current_file
= macro_set_main (macro_table
, file_name
);
23740 macro_define_special (macro_table
);
23743 current_file
= macro_include (current_file
, line
, file_name
);
23747 return current_file
;
23750 static const char *
23751 consume_improper_spaces (const char *p
, const char *body
)
23755 complaint (&symfile_complaints
,
23756 _("macro definition contains spaces "
23757 "in formal argument list:\n`%s'"),
23769 parse_macro_definition (struct macro_source_file
*file
, int line
,
23774 /* The body string takes one of two forms. For object-like macro
23775 definitions, it should be:
23777 <macro name> " " <definition>
23779 For function-like macro definitions, it should be:
23781 <macro name> "() " <definition>
23783 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23785 Spaces may appear only where explicitly indicated, and in the
23788 The Dwarf 2 spec says that an object-like macro's name is always
23789 followed by a space, but versions of GCC around March 2002 omit
23790 the space when the macro's definition is the empty string.
23792 The Dwarf 2 spec says that there should be no spaces between the
23793 formal arguments in a function-like macro's formal argument list,
23794 but versions of GCC around March 2002 include spaces after the
23798 /* Find the extent of the macro name. The macro name is terminated
23799 by either a space or null character (for an object-like macro) or
23800 an opening paren (for a function-like macro). */
23801 for (p
= body
; *p
; p
++)
23802 if (*p
== ' ' || *p
== '(')
23805 if (*p
== ' ' || *p
== '\0')
23807 /* It's an object-like macro. */
23808 int name_len
= p
- body
;
23809 char *name
= savestring (body
, name_len
);
23810 const char *replacement
;
23813 replacement
= body
+ name_len
+ 1;
23816 dwarf2_macro_malformed_definition_complaint (body
);
23817 replacement
= body
+ name_len
;
23820 macro_define_object (file
, line
, name
, replacement
);
23824 else if (*p
== '(')
23826 /* It's a function-like macro. */
23827 char *name
= savestring (body
, p
- body
);
23830 char **argv
= XNEWVEC (char *, argv_size
);
23834 p
= consume_improper_spaces (p
, body
);
23836 /* Parse the formal argument list. */
23837 while (*p
&& *p
!= ')')
23839 /* Find the extent of the current argument name. */
23840 const char *arg_start
= p
;
23842 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23845 if (! *p
|| p
== arg_start
)
23846 dwarf2_macro_malformed_definition_complaint (body
);
23849 /* Make sure argv has room for the new argument. */
23850 if (argc
>= argv_size
)
23853 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23856 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23859 p
= consume_improper_spaces (p
, body
);
23861 /* Consume the comma, if present. */
23866 p
= consume_improper_spaces (p
, body
);
23875 /* Perfectly formed definition, no complaints. */
23876 macro_define_function (file
, line
, name
,
23877 argc
, (const char **) argv
,
23879 else if (*p
== '\0')
23881 /* Complain, but do define it. */
23882 dwarf2_macro_malformed_definition_complaint (body
);
23883 macro_define_function (file
, line
, name
,
23884 argc
, (const char **) argv
,
23888 /* Just complain. */
23889 dwarf2_macro_malformed_definition_complaint (body
);
23892 /* Just complain. */
23893 dwarf2_macro_malformed_definition_complaint (body
);
23899 for (i
= 0; i
< argc
; i
++)
23905 dwarf2_macro_malformed_definition_complaint (body
);
23908 /* Skip some bytes from BYTES according to the form given in FORM.
23909 Returns the new pointer. */
23911 static const gdb_byte
*
23912 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
23913 enum dwarf_form form
,
23914 unsigned int offset_size
,
23915 struct dwarf2_section_info
*section
)
23917 unsigned int bytes_read
;
23921 case DW_FORM_data1
:
23926 case DW_FORM_data2
:
23930 case DW_FORM_data4
:
23934 case DW_FORM_data8
:
23938 case DW_FORM_data16
:
23942 case DW_FORM_string
:
23943 read_direct_string (abfd
, bytes
, &bytes_read
);
23944 bytes
+= bytes_read
;
23947 case DW_FORM_sec_offset
:
23949 case DW_FORM_GNU_strp_alt
:
23950 bytes
+= offset_size
;
23953 case DW_FORM_block
:
23954 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
23955 bytes
+= bytes_read
;
23958 case DW_FORM_block1
:
23959 bytes
+= 1 + read_1_byte (abfd
, bytes
);
23961 case DW_FORM_block2
:
23962 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
23964 case DW_FORM_block4
:
23965 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
23968 case DW_FORM_sdata
:
23969 case DW_FORM_udata
:
23970 case DW_FORM_GNU_addr_index
:
23971 case DW_FORM_GNU_str_index
:
23972 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
23975 dwarf2_section_buffer_overflow_complaint (section
);
23980 case DW_FORM_implicit_const
:
23985 complaint (&symfile_complaints
,
23986 _("invalid form 0x%x in `%s'"),
23987 form
, get_section_name (section
));
23995 /* A helper for dwarf_decode_macros that handles skipping an unknown
23996 opcode. Returns an updated pointer to the macro data buffer; or,
23997 on error, issues a complaint and returns NULL. */
23999 static const gdb_byte
*
24000 skip_unknown_opcode (unsigned int opcode
,
24001 const gdb_byte
**opcode_definitions
,
24002 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24004 unsigned int offset_size
,
24005 struct dwarf2_section_info
*section
)
24007 unsigned int bytes_read
, i
;
24009 const gdb_byte
*defn
;
24011 if (opcode_definitions
[opcode
] == NULL
)
24013 complaint (&symfile_complaints
,
24014 _("unrecognized DW_MACFINO opcode 0x%x"),
24019 defn
= opcode_definitions
[opcode
];
24020 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24021 defn
+= bytes_read
;
24023 for (i
= 0; i
< arg
; ++i
)
24025 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24026 (enum dwarf_form
) defn
[i
], offset_size
,
24028 if (mac_ptr
== NULL
)
24030 /* skip_form_bytes already issued the complaint. */
24038 /* A helper function which parses the header of a macro section.
24039 If the macro section is the extended (for now called "GNU") type,
24040 then this updates *OFFSET_SIZE. Returns a pointer to just after
24041 the header, or issues a complaint and returns NULL on error. */
24043 static const gdb_byte
*
24044 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24046 const gdb_byte
*mac_ptr
,
24047 unsigned int *offset_size
,
24048 int section_is_gnu
)
24050 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24052 if (section_is_gnu
)
24054 unsigned int version
, flags
;
24056 version
= read_2_bytes (abfd
, mac_ptr
);
24057 if (version
!= 4 && version
!= 5)
24059 complaint (&symfile_complaints
,
24060 _("unrecognized version `%d' in .debug_macro section"),
24066 flags
= read_1_byte (abfd
, mac_ptr
);
24068 *offset_size
= (flags
& 1) ? 8 : 4;
24070 if ((flags
& 2) != 0)
24071 /* We don't need the line table offset. */
24072 mac_ptr
+= *offset_size
;
24074 /* Vendor opcode descriptions. */
24075 if ((flags
& 4) != 0)
24077 unsigned int i
, count
;
24079 count
= read_1_byte (abfd
, mac_ptr
);
24081 for (i
= 0; i
< count
; ++i
)
24083 unsigned int opcode
, bytes_read
;
24086 opcode
= read_1_byte (abfd
, mac_ptr
);
24088 opcode_definitions
[opcode
] = mac_ptr
;
24089 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24090 mac_ptr
+= bytes_read
;
24099 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24100 including DW_MACRO_import. */
24103 dwarf_decode_macro_bytes (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
24105 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24106 struct macro_source_file
*current_file
,
24107 struct line_header
*lh
,
24108 struct dwarf2_section_info
*section
,
24109 int section_is_gnu
, int section_is_dwz
,
24110 unsigned int offset_size
,
24111 htab_t include_hash
)
24113 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24114 enum dwarf_macro_record_type macinfo_type
;
24115 int at_commandline
;
24116 const gdb_byte
*opcode_definitions
[256];
24118 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24119 &offset_size
, section_is_gnu
);
24120 if (mac_ptr
== NULL
)
24122 /* We already issued a complaint. */
24126 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24127 GDB is still reading the definitions from command line. First
24128 DW_MACINFO_start_file will need to be ignored as it was already executed
24129 to create CURRENT_FILE for the main source holding also the command line
24130 definitions. On first met DW_MACINFO_start_file this flag is reset to
24131 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24133 at_commandline
= 1;
24137 /* Do we at least have room for a macinfo type byte? */
24138 if (mac_ptr
>= mac_end
)
24140 dwarf2_section_buffer_overflow_complaint (section
);
24144 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24147 /* Note that we rely on the fact that the corresponding GNU and
24148 DWARF constants are the same. */
24150 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24151 switch (macinfo_type
)
24153 /* A zero macinfo type indicates the end of the macro
24158 case DW_MACRO_define
:
24159 case DW_MACRO_undef
:
24160 case DW_MACRO_define_strp
:
24161 case DW_MACRO_undef_strp
:
24162 case DW_MACRO_define_sup
:
24163 case DW_MACRO_undef_sup
:
24165 unsigned int bytes_read
;
24170 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24171 mac_ptr
+= bytes_read
;
24173 if (macinfo_type
== DW_MACRO_define
24174 || macinfo_type
== DW_MACRO_undef
)
24176 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24177 mac_ptr
+= bytes_read
;
24181 LONGEST str_offset
;
24183 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24184 mac_ptr
+= offset_size
;
24186 if (macinfo_type
== DW_MACRO_define_sup
24187 || macinfo_type
== DW_MACRO_undef_sup
24190 struct dwz_file
*dwz
24191 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24193 body
= read_indirect_string_from_dwz (objfile
,
24197 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24201 is_define
= (macinfo_type
== DW_MACRO_define
24202 || macinfo_type
== DW_MACRO_define_strp
24203 || macinfo_type
== DW_MACRO_define_sup
);
24204 if (! current_file
)
24206 /* DWARF violation as no main source is present. */
24207 complaint (&symfile_complaints
,
24208 _("debug info with no main source gives macro %s "
24210 is_define
? _("definition") : _("undefinition"),
24214 if ((line
== 0 && !at_commandline
)
24215 || (line
!= 0 && at_commandline
))
24216 complaint (&symfile_complaints
,
24217 _("debug info gives %s macro %s with %s line %d: %s"),
24218 at_commandline
? _("command-line") : _("in-file"),
24219 is_define
? _("definition") : _("undefinition"),
24220 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24223 parse_macro_definition (current_file
, line
, body
);
24226 gdb_assert (macinfo_type
== DW_MACRO_undef
24227 || macinfo_type
== DW_MACRO_undef_strp
24228 || macinfo_type
== DW_MACRO_undef_sup
);
24229 macro_undef (current_file
, line
, body
);
24234 case DW_MACRO_start_file
:
24236 unsigned int bytes_read
;
24239 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24240 mac_ptr
+= bytes_read
;
24241 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24242 mac_ptr
+= bytes_read
;
24244 if ((line
== 0 && !at_commandline
)
24245 || (line
!= 0 && at_commandline
))
24246 complaint (&symfile_complaints
,
24247 _("debug info gives source %d included "
24248 "from %s at %s line %d"),
24249 file
, at_commandline
? _("command-line") : _("file"),
24250 line
== 0 ? _("zero") : _("non-zero"), line
);
24252 if (at_commandline
)
24254 /* This DW_MACRO_start_file was executed in the
24256 at_commandline
= 0;
24259 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24263 case DW_MACRO_end_file
:
24264 if (! current_file
)
24265 complaint (&symfile_complaints
,
24266 _("macro debug info has an unmatched "
24267 "`close_file' directive"));
24270 current_file
= current_file
->included_by
;
24271 if (! current_file
)
24273 enum dwarf_macro_record_type next_type
;
24275 /* GCC circa March 2002 doesn't produce the zero
24276 type byte marking the end of the compilation
24277 unit. Complain if it's not there, but exit no
24280 /* Do we at least have room for a macinfo type byte? */
24281 if (mac_ptr
>= mac_end
)
24283 dwarf2_section_buffer_overflow_complaint (section
);
24287 /* We don't increment mac_ptr here, so this is just
24290 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24292 if (next_type
!= 0)
24293 complaint (&symfile_complaints
,
24294 _("no terminating 0-type entry for "
24295 "macros in `.debug_macinfo' section"));
24302 case DW_MACRO_import
:
24303 case DW_MACRO_import_sup
:
24307 bfd
*include_bfd
= abfd
;
24308 struct dwarf2_section_info
*include_section
= section
;
24309 const gdb_byte
*include_mac_end
= mac_end
;
24310 int is_dwz
= section_is_dwz
;
24311 const gdb_byte
*new_mac_ptr
;
24313 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24314 mac_ptr
+= offset_size
;
24316 if (macinfo_type
== DW_MACRO_import_sup
)
24318 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24320 dwarf2_read_section (objfile
, &dwz
->macro
);
24322 include_section
= &dwz
->macro
;
24323 include_bfd
= get_section_bfd_owner (include_section
);
24324 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24328 new_mac_ptr
= include_section
->buffer
+ offset
;
24329 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24333 /* This has actually happened; see
24334 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24335 complaint (&symfile_complaints
,
24336 _("recursive DW_MACRO_import in "
24337 ".debug_macro section"));
24341 *slot
= (void *) new_mac_ptr
;
24343 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24344 include_bfd
, new_mac_ptr
,
24345 include_mac_end
, current_file
, lh
,
24346 section
, section_is_gnu
, is_dwz
,
24347 offset_size
, include_hash
);
24349 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24354 case DW_MACINFO_vendor_ext
:
24355 if (!section_is_gnu
)
24357 unsigned int bytes_read
;
24359 /* This reads the constant, but since we don't recognize
24360 any vendor extensions, we ignore it. */
24361 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24362 mac_ptr
+= bytes_read
;
24363 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24364 mac_ptr
+= bytes_read
;
24366 /* We don't recognize any vendor extensions. */
24372 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24373 mac_ptr
, mac_end
, abfd
, offset_size
,
24375 if (mac_ptr
== NULL
)
24380 } while (macinfo_type
!= 0);
24384 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24385 int section_is_gnu
)
24387 struct dwarf2_per_objfile
*dwarf2_per_objfile
24388 = cu
->per_cu
->dwarf2_per_objfile
;
24389 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24390 struct line_header
*lh
= cu
->line_header
;
24392 const gdb_byte
*mac_ptr
, *mac_end
;
24393 struct macro_source_file
*current_file
= 0;
24394 enum dwarf_macro_record_type macinfo_type
;
24395 unsigned int offset_size
= cu
->header
.offset_size
;
24396 const gdb_byte
*opcode_definitions
[256];
24398 struct dwarf2_section_info
*section
;
24399 const char *section_name
;
24401 if (cu
->dwo_unit
!= NULL
)
24403 if (section_is_gnu
)
24405 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24406 section_name
= ".debug_macro.dwo";
24410 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24411 section_name
= ".debug_macinfo.dwo";
24416 if (section_is_gnu
)
24418 section
= &dwarf2_per_objfile
->macro
;
24419 section_name
= ".debug_macro";
24423 section
= &dwarf2_per_objfile
->macinfo
;
24424 section_name
= ".debug_macinfo";
24428 dwarf2_read_section (objfile
, section
);
24429 if (section
->buffer
== NULL
)
24431 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
24434 abfd
= get_section_bfd_owner (section
);
24436 /* First pass: Find the name of the base filename.
24437 This filename is needed in order to process all macros whose definition
24438 (or undefinition) comes from the command line. These macros are defined
24439 before the first DW_MACINFO_start_file entry, and yet still need to be
24440 associated to the base file.
24442 To determine the base file name, we scan the macro definitions until we
24443 reach the first DW_MACINFO_start_file entry. We then initialize
24444 CURRENT_FILE accordingly so that any macro definition found before the
24445 first DW_MACINFO_start_file can still be associated to the base file. */
24447 mac_ptr
= section
->buffer
+ offset
;
24448 mac_end
= section
->buffer
+ section
->size
;
24450 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24451 &offset_size
, section_is_gnu
);
24452 if (mac_ptr
== NULL
)
24454 /* We already issued a complaint. */
24460 /* Do we at least have room for a macinfo type byte? */
24461 if (mac_ptr
>= mac_end
)
24463 /* Complaint is printed during the second pass as GDB will probably
24464 stop the first pass earlier upon finding
24465 DW_MACINFO_start_file. */
24469 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24472 /* Note that we rely on the fact that the corresponding GNU and
24473 DWARF constants are the same. */
24475 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24476 switch (macinfo_type
)
24478 /* A zero macinfo type indicates the end of the macro
24483 case DW_MACRO_define
:
24484 case DW_MACRO_undef
:
24485 /* Only skip the data by MAC_PTR. */
24487 unsigned int bytes_read
;
24489 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24490 mac_ptr
+= bytes_read
;
24491 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24492 mac_ptr
+= bytes_read
;
24496 case DW_MACRO_start_file
:
24498 unsigned int bytes_read
;
24501 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24502 mac_ptr
+= bytes_read
;
24503 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24504 mac_ptr
+= bytes_read
;
24506 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24510 case DW_MACRO_end_file
:
24511 /* No data to skip by MAC_PTR. */
24514 case DW_MACRO_define_strp
:
24515 case DW_MACRO_undef_strp
:
24516 case DW_MACRO_define_sup
:
24517 case DW_MACRO_undef_sup
:
24519 unsigned int bytes_read
;
24521 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24522 mac_ptr
+= bytes_read
;
24523 mac_ptr
+= offset_size
;
24527 case DW_MACRO_import
:
24528 case DW_MACRO_import_sup
:
24529 /* Note that, according to the spec, a transparent include
24530 chain cannot call DW_MACRO_start_file. So, we can just
24531 skip this opcode. */
24532 mac_ptr
+= offset_size
;
24535 case DW_MACINFO_vendor_ext
:
24536 /* Only skip the data by MAC_PTR. */
24537 if (!section_is_gnu
)
24539 unsigned int bytes_read
;
24541 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24542 mac_ptr
+= bytes_read
;
24543 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24544 mac_ptr
+= bytes_read
;
24549 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24550 mac_ptr
, mac_end
, abfd
, offset_size
,
24552 if (mac_ptr
== NULL
)
24557 } while (macinfo_type
!= 0 && current_file
== NULL
);
24559 /* Second pass: Process all entries.
24561 Use the AT_COMMAND_LINE flag to determine whether we are still processing
24562 command-line macro definitions/undefinitions. This flag is unset when we
24563 reach the first DW_MACINFO_start_file entry. */
24565 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
24567 NULL
, xcalloc
, xfree
));
24568 mac_ptr
= section
->buffer
+ offset
;
24569 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
24570 *slot
= (void *) mac_ptr
;
24571 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24572 abfd
, mac_ptr
, mac_end
,
24573 current_file
, lh
, section
,
24574 section_is_gnu
, 0, offset_size
,
24575 include_hash
.get ());
24578 /* Check if the attribute's form is a DW_FORM_block*
24579 if so return true else false. */
24582 attr_form_is_block (const struct attribute
*attr
)
24584 return (attr
== NULL
? 0 :
24585 attr
->form
== DW_FORM_block1
24586 || attr
->form
== DW_FORM_block2
24587 || attr
->form
== DW_FORM_block4
24588 || attr
->form
== DW_FORM_block
24589 || attr
->form
== DW_FORM_exprloc
);
24592 /* Return non-zero if ATTR's value is a section offset --- classes
24593 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
24594 You may use DW_UNSND (attr) to retrieve such offsets.
24596 Section 7.5.4, "Attribute Encodings", explains that no attribute
24597 may have a value that belongs to more than one of these classes; it
24598 would be ambiguous if we did, because we use the same forms for all
24602 attr_form_is_section_offset (const struct attribute
*attr
)
24604 return (attr
->form
== DW_FORM_data4
24605 || attr
->form
== DW_FORM_data8
24606 || attr
->form
== DW_FORM_sec_offset
);
24609 /* Return non-zero if ATTR's value falls in the 'constant' class, or
24610 zero otherwise. When this function returns true, you can apply
24611 dwarf2_get_attr_constant_value to it.
24613 However, note that for some attributes you must check
24614 attr_form_is_section_offset before using this test. DW_FORM_data4
24615 and DW_FORM_data8 are members of both the constant class, and of
24616 the classes that contain offsets into other debug sections
24617 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
24618 that, if an attribute's can be either a constant or one of the
24619 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
24620 taken as section offsets, not constants.
24622 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
24623 cannot handle that. */
24626 attr_form_is_constant (const struct attribute
*attr
)
24628 switch (attr
->form
)
24630 case DW_FORM_sdata
:
24631 case DW_FORM_udata
:
24632 case DW_FORM_data1
:
24633 case DW_FORM_data2
:
24634 case DW_FORM_data4
:
24635 case DW_FORM_data8
:
24636 case DW_FORM_implicit_const
:
24644 /* DW_ADDR is always stored already as sect_offset; despite for the forms
24645 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
24648 attr_form_is_ref (const struct attribute
*attr
)
24650 switch (attr
->form
)
24652 case DW_FORM_ref_addr
:
24657 case DW_FORM_ref_udata
:
24658 case DW_FORM_GNU_ref_alt
:
24665 /* Return the .debug_loc section to use for CU.
24666 For DWO files use .debug_loc.dwo. */
24668 static struct dwarf2_section_info
*
24669 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24671 struct dwarf2_per_objfile
*dwarf2_per_objfile
24672 = cu
->per_cu
->dwarf2_per_objfile
;
24676 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24678 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24680 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
24681 : &dwarf2_per_objfile
->loc
);
24684 /* A helper function that fills in a dwarf2_loclist_baton. */
24687 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24688 struct dwarf2_loclist_baton
*baton
,
24689 const struct attribute
*attr
)
24691 struct dwarf2_per_objfile
*dwarf2_per_objfile
24692 = cu
->per_cu
->dwarf2_per_objfile
;
24693 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24695 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
24697 baton
->per_cu
= cu
->per_cu
;
24698 gdb_assert (baton
->per_cu
);
24699 /* We don't know how long the location list is, but make sure we
24700 don't run off the edge of the section. */
24701 baton
->size
= section
->size
- DW_UNSND (attr
);
24702 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
24703 baton
->base_address
= cu
->base_address
;
24704 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24708 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24709 struct dwarf2_cu
*cu
, int is_block
)
24711 struct dwarf2_per_objfile
*dwarf2_per_objfile
24712 = cu
->per_cu
->dwarf2_per_objfile
;
24713 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24714 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24716 if (attr_form_is_section_offset (attr
)
24717 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24718 the section. If so, fall through to the complaint in the
24720 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
24722 struct dwarf2_loclist_baton
*baton
;
24724 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24726 fill_in_loclist_baton (cu
, baton
, attr
);
24728 if (cu
->base_known
== 0)
24729 complaint (&symfile_complaints
,
24730 _("Location list used without "
24731 "specifying the CU base address."));
24733 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24734 ? dwarf2_loclist_block_index
24735 : dwarf2_loclist_index
);
24736 SYMBOL_LOCATION_BATON (sym
) = baton
;
24740 struct dwarf2_locexpr_baton
*baton
;
24742 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24743 baton
->per_cu
= cu
->per_cu
;
24744 gdb_assert (baton
->per_cu
);
24746 if (attr_form_is_block (attr
))
24748 /* Note that we're just copying the block's data pointer
24749 here, not the actual data. We're still pointing into the
24750 info_buffer for SYM's objfile; right now we never release
24751 that buffer, but when we do clean up properly this may
24753 baton
->size
= DW_BLOCK (attr
)->size
;
24754 baton
->data
= DW_BLOCK (attr
)->data
;
24758 dwarf2_invalid_attrib_class_complaint ("location description",
24759 SYMBOL_NATURAL_NAME (sym
));
24763 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24764 ? dwarf2_locexpr_block_index
24765 : dwarf2_locexpr_index
);
24766 SYMBOL_LOCATION_BATON (sym
) = baton
;
24770 /* Return the OBJFILE associated with the compilation unit CU. If CU
24771 came from a separate debuginfo file, then the master objfile is
24775 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
24777 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24779 /* Return the master objfile, so that we can report and look up the
24780 correct file containing this variable. */
24781 if (objfile
->separate_debug_objfile_backlink
)
24782 objfile
= objfile
->separate_debug_objfile_backlink
;
24787 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24788 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24789 CU_HEADERP first. */
24791 static const struct comp_unit_head
*
24792 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24793 struct dwarf2_per_cu_data
*per_cu
)
24795 const gdb_byte
*info_ptr
;
24798 return &per_cu
->cu
->header
;
24800 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24802 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24803 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24804 rcuh_kind::COMPILE
);
24809 /* Return the address size given in the compilation unit header for CU. */
24812 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24814 struct comp_unit_head cu_header_local
;
24815 const struct comp_unit_head
*cu_headerp
;
24817 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24819 return cu_headerp
->addr_size
;
24822 /* Return the offset size given in the compilation unit header for CU. */
24825 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
24827 struct comp_unit_head cu_header_local
;
24828 const struct comp_unit_head
*cu_headerp
;
24830 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24832 return cu_headerp
->offset_size
;
24835 /* See its dwarf2loc.h declaration. */
24838 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24840 struct comp_unit_head cu_header_local
;
24841 const struct comp_unit_head
*cu_headerp
;
24843 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24845 if (cu_headerp
->version
== 2)
24846 return cu_headerp
->addr_size
;
24848 return cu_headerp
->offset_size
;
24851 /* Return the text offset of the CU. The returned offset comes from
24852 this CU's objfile. If this objfile came from a separate debuginfo
24853 file, then the offset may be different from the corresponding
24854 offset in the parent objfile. */
24857 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
24859 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24861 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
24864 /* Return DWARF version number of PER_CU. */
24867 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
24869 return per_cu
->dwarf_version
;
24872 /* Locate the .debug_info compilation unit from CU's objfile which contains
24873 the DIE at OFFSET. Raises an error on failure. */
24875 static struct dwarf2_per_cu_data
*
24876 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24877 unsigned int offset_in_dwz
,
24878 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24880 struct dwarf2_per_cu_data
*this_cu
;
24882 const sect_offset
*cu_off
;
24885 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
24888 struct dwarf2_per_cu_data
*mid_cu
;
24889 int mid
= low
+ (high
- low
) / 2;
24891 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
24892 cu_off
= &mid_cu
->sect_off
;
24893 if (mid_cu
->is_dwz
> offset_in_dwz
24894 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
24899 gdb_assert (low
== high
);
24900 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
24901 cu_off
= &this_cu
->sect_off
;
24902 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
24904 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24905 error (_("Dwarf Error: could not find partial DIE containing "
24906 "offset %s [in module %s]"),
24907 sect_offset_str (sect_off
),
24908 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
24910 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
24912 return dwarf2_per_objfile
->all_comp_units
[low
-1];
24916 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
24917 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
24918 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24919 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24920 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24925 /* Initialize dwarf2_cu CU, owned by PER_CU. */
24927 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
24928 : per_cu (per_cu_
),
24931 checked_producer (0),
24932 producer_is_gxx_lt_4_6 (0),
24933 producer_is_gcc_lt_4_3 (0),
24934 producer_is_icc_lt_14 (0),
24935 processing_has_namespace_info (0)
24940 /* Destroy a dwarf2_cu. */
24942 dwarf2_cu::~dwarf2_cu ()
24947 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24950 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24951 enum language pretend_language
)
24953 struct attribute
*attr
;
24955 /* Set the language we're debugging. */
24956 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24958 set_cu_language (DW_UNSND (attr
), cu
);
24961 cu
->language
= pretend_language
;
24962 cu
->language_defn
= language_def (cu
->language
);
24965 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24968 /* Increase the age counter on each cached compilation unit, and free
24969 any that are too old. */
24972 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24974 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24976 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
24977 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24978 while (per_cu
!= NULL
)
24980 per_cu
->cu
->last_used
++;
24981 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
24982 dwarf2_mark (per_cu
->cu
);
24983 per_cu
= per_cu
->cu
->read_in_chain
;
24986 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24987 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24988 while (per_cu
!= NULL
)
24990 struct dwarf2_per_cu_data
*next_cu
;
24992 next_cu
= per_cu
->cu
->read_in_chain
;
24994 if (!per_cu
->cu
->mark
)
24997 *last_chain
= next_cu
;
25000 last_chain
= &per_cu
->cu
->read_in_chain
;
25006 /* Remove a single compilation unit from the cache. */
25009 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25011 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25012 struct dwarf2_per_objfile
*dwarf2_per_objfile
25013 = target_per_cu
->dwarf2_per_objfile
;
25015 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25016 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25017 while (per_cu
!= NULL
)
25019 struct dwarf2_per_cu_data
*next_cu
;
25021 next_cu
= per_cu
->cu
->read_in_chain
;
25023 if (per_cu
== target_per_cu
)
25027 *last_chain
= next_cu
;
25031 last_chain
= &per_cu
->cu
->read_in_chain
;
25037 /* Release all extra memory associated with OBJFILE. */
25040 dwarf2_free_objfile (struct objfile
*objfile
)
25042 struct dwarf2_per_objfile
*dwarf2_per_objfile
25043 = get_dwarf2_per_objfile (objfile
);
25045 delete dwarf2_per_objfile
;
25048 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25049 We store these in a hash table separate from the DIEs, and preserve them
25050 when the DIEs are flushed out of cache.
25052 The CU "per_cu" pointer is needed because offset alone is not enough to
25053 uniquely identify the type. A file may have multiple .debug_types sections,
25054 or the type may come from a DWO file. Furthermore, while it's more logical
25055 to use per_cu->section+offset, with Fission the section with the data is in
25056 the DWO file but we don't know that section at the point we need it.
25057 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25058 because we can enter the lookup routine, get_die_type_at_offset, from
25059 outside this file, and thus won't necessarily have PER_CU->cu.
25060 Fortunately, PER_CU is stable for the life of the objfile. */
25062 struct dwarf2_per_cu_offset_and_type
25064 const struct dwarf2_per_cu_data
*per_cu
;
25065 sect_offset sect_off
;
25069 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25072 per_cu_offset_and_type_hash (const void *item
)
25074 const struct dwarf2_per_cu_offset_and_type
*ofs
25075 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25077 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25080 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25083 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25085 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25086 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25087 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25088 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25090 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25091 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25094 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25095 table if necessary. For convenience, return TYPE.
25097 The DIEs reading must have careful ordering to:
25098 * Not cause infite loops trying to read in DIEs as a prerequisite for
25099 reading current DIE.
25100 * Not trying to dereference contents of still incompletely read in types
25101 while reading in other DIEs.
25102 * Enable referencing still incompletely read in types just by a pointer to
25103 the type without accessing its fields.
25105 Therefore caller should follow these rules:
25106 * Try to fetch any prerequisite types we may need to build this DIE type
25107 before building the type and calling set_die_type.
25108 * After building type call set_die_type for current DIE as soon as
25109 possible before fetching more types to complete the current type.
25110 * Make the type as complete as possible before fetching more types. */
25112 static struct type
*
25113 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25115 struct dwarf2_per_objfile
*dwarf2_per_objfile
25116 = cu
->per_cu
->dwarf2_per_objfile
;
25117 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25118 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25119 struct attribute
*attr
;
25120 struct dynamic_prop prop
;
25122 /* For Ada types, make sure that the gnat-specific data is always
25123 initialized (if not already set). There are a few types where
25124 we should not be doing so, because the type-specific area is
25125 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25126 where the type-specific area is used to store the floatformat).
25127 But this is not a problem, because the gnat-specific information
25128 is actually not needed for these types. */
25129 if (need_gnat_info (cu
)
25130 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25131 && TYPE_CODE (type
) != TYPE_CODE_FLT
25132 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25133 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25134 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25135 && !HAVE_GNAT_AUX_INFO (type
))
25136 INIT_GNAT_SPECIFIC (type
);
25138 /* Read DW_AT_allocated and set in type. */
25139 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25140 if (attr_form_is_block (attr
))
25142 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25143 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25145 else if (attr
!= NULL
)
25147 complaint (&symfile_complaints
,
25148 _("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25149 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25150 sect_offset_str (die
->sect_off
));
25153 /* Read DW_AT_associated and set in type. */
25154 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25155 if (attr_form_is_block (attr
))
25157 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25158 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25160 else if (attr
!= NULL
)
25162 complaint (&symfile_complaints
,
25163 _("DW_AT_associated has the wrong form (%s) at DIE %s"),
25164 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25165 sect_offset_str (die
->sect_off
));
25168 /* Read DW_AT_data_location and set in type. */
25169 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25170 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25171 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25173 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25175 dwarf2_per_objfile
->die_type_hash
=
25176 htab_create_alloc_ex (127,
25177 per_cu_offset_and_type_hash
,
25178 per_cu_offset_and_type_eq
,
25180 &objfile
->objfile_obstack
,
25181 hashtab_obstack_allocate
,
25182 dummy_obstack_deallocate
);
25185 ofs
.per_cu
= cu
->per_cu
;
25186 ofs
.sect_off
= die
->sect_off
;
25188 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25189 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25191 complaint (&symfile_complaints
,
25192 _("A problem internal to GDB: DIE %s has type already set"),
25193 sect_offset_str (die
->sect_off
));
25194 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25195 struct dwarf2_per_cu_offset_and_type
);
25200 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25201 or return NULL if the die does not have a saved type. */
25203 static struct type
*
25204 get_die_type_at_offset (sect_offset sect_off
,
25205 struct dwarf2_per_cu_data
*per_cu
)
25207 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25208 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25210 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25213 ofs
.per_cu
= per_cu
;
25214 ofs
.sect_off
= sect_off
;
25215 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25216 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25223 /* Look up the type for DIE in CU in die_type_hash,
25224 or return NULL if DIE does not have a saved type. */
25226 static struct type
*
25227 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25229 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25232 /* Add a dependence relationship from CU to REF_PER_CU. */
25235 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25236 struct dwarf2_per_cu_data
*ref_per_cu
)
25240 if (cu
->dependencies
== NULL
)
25242 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25243 NULL
, &cu
->comp_unit_obstack
,
25244 hashtab_obstack_allocate
,
25245 dummy_obstack_deallocate
);
25247 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25249 *slot
= ref_per_cu
;
25252 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25253 Set the mark field in every compilation unit in the
25254 cache that we must keep because we are keeping CU. */
25257 dwarf2_mark_helper (void **slot
, void *data
)
25259 struct dwarf2_per_cu_data
*per_cu
;
25261 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25263 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25264 reading of the chain. As such dependencies remain valid it is not much
25265 useful to track and undo them during QUIT cleanups. */
25266 if (per_cu
->cu
== NULL
)
25269 if (per_cu
->cu
->mark
)
25271 per_cu
->cu
->mark
= 1;
25273 if (per_cu
->cu
->dependencies
!= NULL
)
25274 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25279 /* Set the mark field in CU and in every other compilation unit in the
25280 cache that we must keep because we are keeping CU. */
25283 dwarf2_mark (struct dwarf2_cu
*cu
)
25288 if (cu
->dependencies
!= NULL
)
25289 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25293 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25297 per_cu
->cu
->mark
= 0;
25298 per_cu
= per_cu
->cu
->read_in_chain
;
25302 /* Trivial hash function for partial_die_info: the hash value of a DIE
25303 is its offset in .debug_info for this objfile. */
25306 partial_die_hash (const void *item
)
25308 const struct partial_die_info
*part_die
25309 = (const struct partial_die_info
*) item
;
25311 return to_underlying (part_die
->sect_off
);
25314 /* Trivial comparison function for partial_die_info structures: two DIEs
25315 are equal if they have the same offset. */
25318 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25320 const struct partial_die_info
*part_die_lhs
25321 = (const struct partial_die_info
*) item_lhs
;
25322 const struct partial_die_info
*part_die_rhs
25323 = (const struct partial_die_info
*) item_rhs
;
25325 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25328 static struct cmd_list_element
*set_dwarf_cmdlist
;
25329 static struct cmd_list_element
*show_dwarf_cmdlist
;
25332 set_dwarf_cmd (const char *args
, int from_tty
)
25334 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25339 show_dwarf_cmd (const char *args
, int from_tty
)
25341 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25344 int dwarf_always_disassemble
;
25347 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
25348 struct cmd_list_element
*c
, const char *value
)
25350 fprintf_filtered (file
,
25351 _("Whether to always disassemble "
25352 "DWARF expressions is %s.\n"),
25357 show_check_physname (struct ui_file
*file
, int from_tty
,
25358 struct cmd_list_element
*c
, const char *value
)
25360 fprintf_filtered (file
,
25361 _("Whether to check \"physname\" is %s.\n"),
25366 _initialize_dwarf2_read (void)
25369 dwarf2_objfile_data_key
= register_objfile_data ();
25371 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
25372 Set DWARF specific variables.\n\
25373 Configure DWARF variables such as the cache size"),
25374 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25375 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25377 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
25378 Show DWARF specific variables\n\
25379 Show DWARF variables such as the cache size"),
25380 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25381 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25383 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25384 &dwarf_max_cache_age
, _("\
25385 Set the upper bound on the age of cached DWARF compilation units."), _("\
25386 Show the upper bound on the age of cached DWARF compilation units."), _("\
25387 A higher limit means that cached compilation units will be stored\n\
25388 in memory longer, and more total memory will be used. Zero disables\n\
25389 caching, which can slow down startup."),
25391 show_dwarf_max_cache_age
,
25392 &set_dwarf_cmdlist
,
25393 &show_dwarf_cmdlist
);
25395 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
25396 &dwarf_always_disassemble
, _("\
25397 Set whether `info address' always disassembles DWARF expressions."), _("\
25398 Show whether `info address' always disassembles DWARF expressions."), _("\
25399 When enabled, DWARF expressions are always printed in an assembly-like\n\
25400 syntax. When disabled, expressions will be printed in a more\n\
25401 conversational style, when possible."),
25403 show_dwarf_always_disassemble
,
25404 &set_dwarf_cmdlist
,
25405 &show_dwarf_cmdlist
);
25407 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25408 Set debugging of the DWARF reader."), _("\
25409 Show debugging of the DWARF reader."), _("\
25410 When enabled (non-zero), debugging messages are printed during DWARF\n\
25411 reading and symtab expansion. A value of 1 (one) provides basic\n\
25412 information. A value greater than 1 provides more verbose information."),
25415 &setdebuglist
, &showdebuglist
);
25417 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25418 Set debugging of the DWARF DIE reader."), _("\
25419 Show debugging of the DWARF DIE reader."), _("\
25420 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25421 The value is the maximum depth to print."),
25424 &setdebuglist
, &showdebuglist
);
25426 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25427 Set debugging of the dwarf line reader."), _("\
25428 Show debugging of the dwarf line reader."), _("\
25429 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25430 A value of 1 (one) provides basic information.\n\
25431 A value greater than 1 provides more verbose information."),
25434 &setdebuglist
, &showdebuglist
);
25436 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25437 Set cross-checking of \"physname\" code against demangler."), _("\
25438 Show cross-checking of \"physname\" code against demangler."), _("\
25439 When enabled, GDB's internal \"physname\" code is checked against\n\
25441 NULL
, show_check_physname
,
25442 &setdebuglist
, &showdebuglist
);
25444 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25445 no_class
, &use_deprecated_index_sections
, _("\
25446 Set whether to use deprecated gdb_index sections."), _("\
25447 Show whether to use deprecated gdb_index sections."), _("\
25448 When enabled, deprecated .gdb_index sections are used anyway.\n\
25449 Normally they are ignored either because of a missing feature or\n\
25450 performance issue.\n\
25451 Warning: This option must be enabled before gdb reads the file."),
25454 &setlist
, &showlist
);
25456 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25457 &dwarf2_locexpr_funcs
);
25458 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25459 &dwarf2_loclist_funcs
);
25461 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25462 &dwarf2_block_frame_base_locexpr_funcs
);
25463 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25464 &dwarf2_block_frame_base_loclist_funcs
);
25467 selftests::register_test ("dw2_expand_symtabs_matching",
25468 selftests::dw2_expand_symtabs_matching::run_test
);