1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2017 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. */
40 #include "gdb-demangle.h"
41 #include "expression.h"
42 #include "filenames.h" /* for DOSish file names */
45 #include "complaints.h"
47 #include "dwarf2expr.h"
48 #include "dwarf2loc.h"
49 #include "cp-support.h"
55 #include "typeprint.h"
58 #include "completer.h"
63 #include "gdbcore.h" /* for gnutarget */
64 #include "gdb/gdb-index.h"
69 #include "filestuff.h"
71 #include "namespace.h"
72 #include "common/gdb_unlinker.h"
73 #include "common/function-view.h"
74 #include "common/gdb_optional.h"
75 #include "common/underlying.h"
76 #include "common/byte-vector.h"
77 #include "filename-seen-cache.h"
80 #include <sys/types.h>
82 #include <unordered_set>
83 #include <unordered_map>
85 typedef struct symbol
*symbolp
;
88 /* When == 1, print basic high level tracing messages.
89 When > 1, be more verbose.
90 This is in contrast to the low level DIE reading of dwarf_die_debug. */
91 static unsigned int dwarf_read_debug
= 0;
93 /* When non-zero, dump DIEs after they are read in. */
94 static unsigned int dwarf_die_debug
= 0;
96 /* When non-zero, dump line number entries as they are read in. */
97 static unsigned int dwarf_line_debug
= 0;
99 /* When non-zero, cross-check physname against demangler. */
100 static int check_physname
= 0;
102 /* When non-zero, do not reject deprecated .gdb_index sections. */
103 static int use_deprecated_index_sections
= 0;
105 static const struct objfile_data
*dwarf2_objfile_data_key
;
107 /* The "aclass" indices for various kinds of computed DWARF symbols. */
109 static int dwarf2_locexpr_index
;
110 static int dwarf2_loclist_index
;
111 static int dwarf2_locexpr_block_index
;
112 static int dwarf2_loclist_block_index
;
114 /* A descriptor for dwarf sections.
116 S.ASECTION, SIZE are typically initialized when the objfile is first
117 scanned. BUFFER, READIN are filled in later when the section is read.
118 If the section contained compressed data then SIZE is updated to record
119 the uncompressed size of the section.
121 DWP file format V2 introduces a wrinkle that is easiest to handle by
122 creating the concept of virtual sections contained within a real section.
123 In DWP V2 the sections of the input DWO files are concatenated together
124 into one section, but section offsets are kept relative to the original
126 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
127 the real section this "virtual" section is contained in, and BUFFER,SIZE
128 describe the virtual section. */
130 struct dwarf2_section_info
134 /* If this is a real section, the bfd section. */
136 /* If this is a virtual section, pointer to the containing ("real")
138 struct dwarf2_section_info
*containing_section
;
140 /* Pointer to section data, only valid if readin. */
141 const gdb_byte
*buffer
;
142 /* The size of the section, real or virtual. */
144 /* If this is a virtual section, the offset in the real section.
145 Only valid if is_virtual. */
146 bfd_size_type virtual_offset
;
147 /* True if we have tried to read this section. */
149 /* True if this is a virtual section, False otherwise.
150 This specifies which of s.section and s.containing_section to use. */
154 typedef struct dwarf2_section_info dwarf2_section_info_def
;
155 DEF_VEC_O (dwarf2_section_info_def
);
157 /* All offsets in the index are of this type. It must be
158 architecture-independent. */
159 typedef uint32_t offset_type
;
161 DEF_VEC_I (offset_type
);
163 /* Ensure only legit values are used. */
164 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
166 gdb_assert ((unsigned int) (value) <= 1); \
167 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
170 /* Ensure only legit values are used. */
171 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
173 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
174 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
175 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
178 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
179 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
181 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
182 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
187 /* Convert VALUE between big- and little-endian. */
190 byte_swap (offset_type value
)
194 result
= (value
& 0xff) << 24;
195 result
|= (value
& 0xff00) << 8;
196 result
|= (value
& 0xff0000) >> 8;
197 result
|= (value
& 0xff000000) >> 24;
201 #define MAYBE_SWAP(V) byte_swap (V)
204 #define MAYBE_SWAP(V) static_cast<offset_type> (V)
205 #endif /* WORDS_BIGENDIAN */
207 /* An index into a (C++) symbol name component in a symbol name as
208 recorded in the mapped_index's symbol table. For each C++ symbol
209 in the symbol table, we record one entry for the start of each
210 component in the symbol in a table of name components, and then
211 sort the table, in order to be able to binary search symbol names,
212 ignoring leading namespaces, both completion and regular look up.
213 For example, for symbol "A::B::C", we'll have an entry that points
214 to "A::B::C", another that points to "B::C", and another for "C".
215 Note that function symbols in GDB index have no parameter
216 information, just the function/method names. You can convert a
217 name_component to a "const char *" using the
218 'mapped_index::symbol_name_at(offset_type)' method. */
220 struct name_component
222 /* Offset in the symbol name where the component starts. Stored as
223 a (32-bit) offset instead of a pointer to save memory and improve
224 locality on 64-bit architectures. */
225 offset_type name_offset
;
227 /* The symbol's index in the symbol and constant pool tables of a
232 /* A description of the mapped index. The file format is described in
233 a comment by the code that writes the index. */
236 /* Index data format version. */
239 /* The total length of the buffer. */
242 /* A pointer to the address table data. */
243 const gdb_byte
*address_table
;
245 /* Size of the address table data in bytes. */
246 offset_type address_table_size
;
248 /* The symbol table, implemented as a hash table. */
249 const offset_type
*symbol_table
;
251 /* Size in slots, each slot is 2 offset_types. */
252 offset_type symbol_table_slots
;
254 /* A pointer to the constant pool. */
255 const char *constant_pool
;
257 /* The name_component table (a sorted vector). See name_component's
258 description above. */
259 std::vector
<name_component
> name_components
;
261 /* Convenience method to get at the name of the symbol at IDX in the
263 const char *symbol_name_at (offset_type idx
) const
264 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
]); }
267 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
268 DEF_VEC_P (dwarf2_per_cu_ptr
);
272 int nr_uniq_abbrev_tables
;
274 int nr_symtab_sharers
;
275 int nr_stmt_less_type_units
;
276 int nr_all_type_units_reallocs
;
279 /* Collection of data recorded per objfile.
280 This hangs off of dwarf2_objfile_data_key. */
282 struct dwarf2_per_objfile
284 /* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the
285 dwarf2 section names, or is NULL if the standard ELF names are
287 dwarf2_per_objfile (struct objfile
*objfile
,
288 const dwarf2_debug_sections
*names
);
290 ~dwarf2_per_objfile ();
292 DISABLE_COPY_AND_ASSIGN (dwarf2_per_objfile
);
294 /* Free all cached compilation units. */
295 void free_cached_comp_units ();
297 /* This function is mapped across the sections and remembers the
298 offset and size of each of the debugging sections we are
300 void locate_sections (bfd
*abfd
, asection
*sectp
,
301 const dwarf2_debug_sections
&names
);
304 dwarf2_section_info info
{};
305 dwarf2_section_info abbrev
{};
306 dwarf2_section_info line
{};
307 dwarf2_section_info loc
{};
308 dwarf2_section_info loclists
{};
309 dwarf2_section_info macinfo
{};
310 dwarf2_section_info macro
{};
311 dwarf2_section_info str
{};
312 dwarf2_section_info line_str
{};
313 dwarf2_section_info ranges
{};
314 dwarf2_section_info rnglists
{};
315 dwarf2_section_info addr
{};
316 dwarf2_section_info frame
{};
317 dwarf2_section_info eh_frame
{};
318 dwarf2_section_info gdb_index
{};
320 VEC (dwarf2_section_info_def
) *types
= NULL
;
323 struct objfile
*objfile
= NULL
;
325 /* Table of all the compilation units. This is used to locate
326 the target compilation unit of a particular reference. */
327 struct dwarf2_per_cu_data
**all_comp_units
= NULL
;
329 /* The number of compilation units in ALL_COMP_UNITS. */
330 int n_comp_units
= 0;
332 /* The number of .debug_types-related CUs. */
333 int n_type_units
= 0;
335 /* The number of elements allocated in all_type_units.
336 If there are skeleton-less TUs, we add them to all_type_units lazily. */
337 int n_allocated_type_units
= 0;
339 /* The .debug_types-related CUs (TUs).
340 This is stored in malloc space because we may realloc it. */
341 struct signatured_type
**all_type_units
= NULL
;
343 /* Table of struct type_unit_group objects.
344 The hash key is the DW_AT_stmt_list value. */
345 htab_t type_unit_groups
{};
347 /* A table mapping .debug_types signatures to its signatured_type entry.
348 This is NULL if the .debug_types section hasn't been read in yet. */
349 htab_t signatured_types
{};
351 /* Type unit statistics, to see how well the scaling improvements
353 struct tu_stats tu_stats
{};
355 /* A chain of compilation units that are currently read in, so that
356 they can be freed later. */
357 dwarf2_per_cu_data
*read_in_chain
= NULL
;
359 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
360 This is NULL if the table hasn't been allocated yet. */
363 /* True if we've checked for whether there is a DWP file. */
364 bool dwp_checked
= false;
366 /* The DWP file if there is one, or NULL. */
367 struct dwp_file
*dwp_file
= NULL
;
369 /* The shared '.dwz' file, if one exists. This is used when the
370 original data was compressed using 'dwz -m'. */
371 struct dwz_file
*dwz_file
= NULL
;
373 /* A flag indicating whether this objfile has a section loaded at a
375 bool has_section_at_zero
= false;
377 /* True if we are using the mapped index,
378 or we are faking it for OBJF_READNOW's sake. */
379 bool using_index
= false;
381 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
382 mapped_index
*index_table
= NULL
;
384 /* When using index_table, this keeps track of all quick_file_names entries.
385 TUs typically share line table entries with a CU, so we maintain a
386 separate table of all line table entries to support the sharing.
387 Note that while there can be way more TUs than CUs, we've already
388 sorted all the TUs into "type unit groups", grouped by their
389 DW_AT_stmt_list value. Therefore the only sharing done here is with a
390 CU and its associated TU group if there is one. */
391 htab_t quick_file_names_table
{};
393 /* Set during partial symbol reading, to prevent queueing of full
395 bool reading_partial_symbols
= false;
397 /* Table mapping type DIEs to their struct type *.
398 This is NULL if not allocated yet.
399 The mapping is done via (CU/TU + DIE offset) -> type. */
400 htab_t die_type_hash
{};
402 /* The CUs we recently read. */
403 VEC (dwarf2_per_cu_ptr
) *just_read_cus
= NULL
;
405 /* Table containing line_header indexed by offset and offset_in_dwz. */
406 htab_t line_header_hash
{};
408 /* Table containing all filenames. This is an optional because the
409 table is lazily constructed on first access. */
410 gdb::optional
<filename_seen_cache
> filenames_cache
;
413 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
415 /* Default names of the debugging sections. */
417 /* Note that if the debugging section has been compressed, it might
418 have a name like .zdebug_info. */
420 static const struct dwarf2_debug_sections dwarf2_elf_names
=
422 { ".debug_info", ".zdebug_info" },
423 { ".debug_abbrev", ".zdebug_abbrev" },
424 { ".debug_line", ".zdebug_line" },
425 { ".debug_loc", ".zdebug_loc" },
426 { ".debug_loclists", ".zdebug_loclists" },
427 { ".debug_macinfo", ".zdebug_macinfo" },
428 { ".debug_macro", ".zdebug_macro" },
429 { ".debug_str", ".zdebug_str" },
430 { ".debug_line_str", ".zdebug_line_str" },
431 { ".debug_ranges", ".zdebug_ranges" },
432 { ".debug_rnglists", ".zdebug_rnglists" },
433 { ".debug_types", ".zdebug_types" },
434 { ".debug_addr", ".zdebug_addr" },
435 { ".debug_frame", ".zdebug_frame" },
436 { ".eh_frame", NULL
},
437 { ".gdb_index", ".zgdb_index" },
441 /* List of DWO/DWP sections. */
443 static const struct dwop_section_names
445 struct dwarf2_section_names abbrev_dwo
;
446 struct dwarf2_section_names info_dwo
;
447 struct dwarf2_section_names line_dwo
;
448 struct dwarf2_section_names loc_dwo
;
449 struct dwarf2_section_names loclists_dwo
;
450 struct dwarf2_section_names macinfo_dwo
;
451 struct dwarf2_section_names macro_dwo
;
452 struct dwarf2_section_names str_dwo
;
453 struct dwarf2_section_names str_offsets_dwo
;
454 struct dwarf2_section_names types_dwo
;
455 struct dwarf2_section_names cu_index
;
456 struct dwarf2_section_names tu_index
;
460 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
461 { ".debug_info.dwo", ".zdebug_info.dwo" },
462 { ".debug_line.dwo", ".zdebug_line.dwo" },
463 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
464 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
465 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
466 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
467 { ".debug_str.dwo", ".zdebug_str.dwo" },
468 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
469 { ".debug_types.dwo", ".zdebug_types.dwo" },
470 { ".debug_cu_index", ".zdebug_cu_index" },
471 { ".debug_tu_index", ".zdebug_tu_index" },
474 /* local data types */
476 /* The data in a compilation unit header, after target2host
477 translation, looks like this. */
478 struct comp_unit_head
482 unsigned char addr_size
;
483 unsigned char signed_addr_p
;
484 sect_offset abbrev_sect_off
;
486 /* Size of file offsets; either 4 or 8. */
487 unsigned int offset_size
;
489 /* Size of the length field; either 4 or 12. */
490 unsigned int initial_length_size
;
492 enum dwarf_unit_type unit_type
;
494 /* Offset to the first byte of this compilation unit header in the
495 .debug_info section, for resolving relative reference dies. */
496 sect_offset sect_off
;
498 /* Offset to first die in this cu from the start of the cu.
499 This will be the first byte following the compilation unit header. */
500 cu_offset first_die_cu_offset
;
502 /* 64-bit signature of this type unit - it is valid only for
503 UNIT_TYPE DW_UT_type. */
506 /* For types, offset in the type's DIE of the type defined by this TU. */
507 cu_offset type_cu_offset_in_tu
;
510 /* Type used for delaying computation of method physnames.
511 See comments for compute_delayed_physnames. */
512 struct delayed_method_info
514 /* The type to which the method is attached, i.e., its parent class. */
517 /* The index of the method in the type's function fieldlists. */
520 /* The index of the method in the fieldlist. */
523 /* The name of the DIE. */
526 /* The DIE associated with this method. */
527 struct die_info
*die
;
530 typedef struct delayed_method_info delayed_method_info
;
531 DEF_VEC_O (delayed_method_info
);
533 /* Internal state when decoding a particular compilation unit. */
536 /* The objfile containing this compilation unit. */
537 struct objfile
*objfile
;
539 /* The header of the compilation unit. */
540 struct comp_unit_head header
;
542 /* Base address of this compilation unit. */
543 CORE_ADDR base_address
;
545 /* Non-zero if base_address has been set. */
548 /* The language we are debugging. */
549 enum language language
;
550 const struct language_defn
*language_defn
;
552 const char *producer
;
554 /* The generic symbol table building routines have separate lists for
555 file scope symbols and all all other scopes (local scopes). So
556 we need to select the right one to pass to add_symbol_to_list().
557 We do it by keeping a pointer to the correct list in list_in_scope.
559 FIXME: The original dwarf code just treated the file scope as the
560 first local scope, and all other local scopes as nested local
561 scopes, and worked fine. Check to see if we really need to
562 distinguish these in buildsym.c. */
563 struct pending
**list_in_scope
;
565 /* The abbrev table for this CU.
566 Normally this points to the abbrev table in the objfile.
567 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
568 struct abbrev_table
*abbrev_table
;
570 /* Hash table holding all the loaded partial DIEs
571 with partial_die->offset.SECT_OFF as hash. */
574 /* Storage for things with the same lifetime as this read-in compilation
575 unit, including partial DIEs. */
576 struct obstack comp_unit_obstack
;
578 /* When multiple dwarf2_cu structures are living in memory, this field
579 chains them all together, so that they can be released efficiently.
580 We will probably also want a generation counter so that most-recently-used
581 compilation units are cached... */
582 struct dwarf2_per_cu_data
*read_in_chain
;
584 /* Backlink to our per_cu entry. */
585 struct dwarf2_per_cu_data
*per_cu
;
587 /* How many compilation units ago was this CU last referenced? */
590 /* A hash table of DIE cu_offset for following references with
591 die_info->offset.sect_off as hash. */
594 /* Full DIEs if read in. */
595 struct die_info
*dies
;
597 /* A set of pointers to dwarf2_per_cu_data objects for compilation
598 units referenced by this one. Only set during full symbol processing;
599 partial symbol tables do not have dependencies. */
602 /* Header data from the line table, during full symbol processing. */
603 struct line_header
*line_header
;
604 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
605 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
606 this is the DW_TAG_compile_unit die for this CU. We'll hold on
607 to the line header as long as this DIE is being processed. See
608 process_die_scope. */
609 die_info
*line_header_die_owner
;
611 /* A list of methods which need to have physnames computed
612 after all type information has been read. */
613 VEC (delayed_method_info
) *method_list
;
615 /* To be copied to symtab->call_site_htab. */
616 htab_t call_site_htab
;
618 /* Non-NULL if this CU came from a DWO file.
619 There is an invariant here that is important to remember:
620 Except for attributes copied from the top level DIE in the "main"
621 (or "stub") file in preparation for reading the DWO file
622 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
623 Either there isn't a DWO file (in which case this is NULL and the point
624 is moot), or there is and either we're not going to read it (in which
625 case this is NULL) or there is and we are reading it (in which case this
627 struct dwo_unit
*dwo_unit
;
629 /* The DW_AT_addr_base attribute if present, zero otherwise
630 (zero is a valid value though).
631 Note this value comes from the Fission stub CU/TU's DIE. */
634 /* The DW_AT_ranges_base attribute if present, zero otherwise
635 (zero is a valid value though).
636 Note this value comes from the Fission stub CU/TU's DIE.
637 Also note that the value is zero in the non-DWO case so this value can
638 be used without needing to know whether DWO files are in use or not.
639 N.B. This does not apply to DW_AT_ranges appearing in
640 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
641 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
642 DW_AT_ranges_base *would* have to be applied, and we'd have to care
643 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
644 ULONGEST ranges_base
;
646 /* Mark used when releasing cached dies. */
647 unsigned int mark
: 1;
649 /* This CU references .debug_loc. See the symtab->locations_valid field.
650 This test is imperfect as there may exist optimized debug code not using
651 any location list and still facing inlining issues if handled as
652 unoptimized code. For a future better test see GCC PR other/32998. */
653 unsigned int has_loclist
: 1;
655 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
656 if all the producer_is_* fields are valid. This information is cached
657 because profiling CU expansion showed excessive time spent in
658 producer_is_gxx_lt_4_6. */
659 unsigned int checked_producer
: 1;
660 unsigned int producer_is_gxx_lt_4_6
: 1;
661 unsigned int producer_is_gcc_lt_4_3
: 1;
662 unsigned int producer_is_icc_lt_14
: 1;
664 /* When set, the file that we're processing is known to have
665 debugging info for C++ namespaces. GCC 3.3.x did not produce
666 this information, but later versions do. */
668 unsigned int processing_has_namespace_info
: 1;
671 /* Persistent data held for a compilation unit, even when not
672 processing it. We put a pointer to this structure in the
673 read_symtab_private field of the psymtab. */
675 struct dwarf2_per_cu_data
677 /* The start offset and length of this compilation unit.
678 NOTE: Unlike comp_unit_head.length, this length includes
680 If the DIE refers to a DWO file, this is always of the original die,
682 sect_offset sect_off
;
685 /* DWARF standard version this data has been read from (such as 4 or 5). */
688 /* Flag indicating this compilation unit will be read in before
689 any of the current compilation units are processed. */
690 unsigned int queued
: 1;
692 /* This flag will be set when reading partial DIEs if we need to load
693 absolutely all DIEs for this compilation unit, instead of just the ones
694 we think are interesting. It gets set if we look for a DIE in the
695 hash table and don't find it. */
696 unsigned int load_all_dies
: 1;
698 /* Non-zero if this CU is from .debug_types.
699 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
701 unsigned int is_debug_types
: 1;
703 /* Non-zero if this CU is from the .dwz file. */
704 unsigned int is_dwz
: 1;
706 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
707 This flag is only valid if is_debug_types is true.
708 We can't read a CU directly from a DWO file: There are required
709 attributes in the stub. */
710 unsigned int reading_dwo_directly
: 1;
712 /* Non-zero if the TU has been read.
713 This is used to assist the "Stay in DWO Optimization" for Fission:
714 When reading a DWO, it's faster to read TUs from the DWO instead of
715 fetching them from random other DWOs (due to comdat folding).
716 If the TU has already been read, the optimization is unnecessary
717 (and unwise - we don't want to change where gdb thinks the TU lives
719 This flag is only valid if is_debug_types is true. */
720 unsigned int tu_read
: 1;
722 /* The section this CU/TU lives in.
723 If the DIE refers to a DWO file, this is always the original die,
725 struct dwarf2_section_info
*section
;
727 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
728 of the CU cache it gets reset to NULL again. This is left as NULL for
729 dummy CUs (a CU header, but nothing else). */
730 struct dwarf2_cu
*cu
;
732 /* The corresponding objfile.
733 Normally we can get the objfile from dwarf2_per_objfile.
734 However we can enter this file with just a "per_cu" handle. */
735 struct objfile
*objfile
;
737 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
738 is active. Otherwise, the 'psymtab' field is active. */
741 /* The partial symbol table associated with this compilation unit,
742 or NULL for unread partial units. */
743 struct partial_symtab
*psymtab
;
745 /* Data needed by the "quick" functions. */
746 struct dwarf2_per_cu_quick_data
*quick
;
749 /* The CUs we import using DW_TAG_imported_unit. This is filled in
750 while reading psymtabs, used to compute the psymtab dependencies,
751 and then cleared. Then it is filled in again while reading full
752 symbols, and only deleted when the objfile is destroyed.
754 This is also used to work around a difference between the way gold
755 generates .gdb_index version <=7 and the way gdb does. Arguably this
756 is a gold bug. For symbols coming from TUs, gold records in the index
757 the CU that includes the TU instead of the TU itself. This breaks
758 dw2_lookup_symbol: It assumes that if the index says symbol X lives
759 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
760 will find X. Alas TUs live in their own symtab, so after expanding CU Y
761 we need to look in TU Z to find X. Fortunately, this is akin to
762 DW_TAG_imported_unit, so we just use the same mechanism: For
763 .gdb_index version <=7 this also records the TUs that the CU referred
764 to. Concurrently with this change gdb was modified to emit version 8
765 indices so we only pay a price for gold generated indices.
766 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
767 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
770 /* Entry in the signatured_types hash table. */
772 struct signatured_type
774 /* The "per_cu" object of this type.
775 This struct is used iff per_cu.is_debug_types.
776 N.B.: This is the first member so that it's easy to convert pointers
778 struct dwarf2_per_cu_data per_cu
;
780 /* The type's signature. */
783 /* Offset in the TU of the type's DIE, as read from the TU header.
784 If this TU is a DWO stub and the definition lives in a DWO file
785 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
786 cu_offset type_offset_in_tu
;
788 /* Offset in the section of the type's DIE.
789 If the definition lives in a DWO file, this is the offset in the
790 .debug_types.dwo section.
791 The value is zero until the actual value is known.
792 Zero is otherwise not a valid section offset. */
793 sect_offset type_offset_in_section
;
795 /* Type units are grouped by their DW_AT_stmt_list entry so that they
796 can share them. This points to the containing symtab. */
797 struct type_unit_group
*type_unit_group
;
800 The first time we encounter this type we fully read it in and install it
801 in the symbol tables. Subsequent times we only need the type. */
804 /* Containing DWO unit.
805 This field is valid iff per_cu.reading_dwo_directly. */
806 struct dwo_unit
*dwo_unit
;
809 typedef struct signatured_type
*sig_type_ptr
;
810 DEF_VEC_P (sig_type_ptr
);
812 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
813 This includes type_unit_group and quick_file_names. */
815 struct stmt_list_hash
817 /* The DWO unit this table is from or NULL if there is none. */
818 struct dwo_unit
*dwo_unit
;
820 /* Offset in .debug_line or .debug_line.dwo. */
821 sect_offset line_sect_off
;
824 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
825 an object of this type. */
827 struct type_unit_group
829 /* dwarf2read.c's main "handle" on a TU symtab.
830 To simplify things we create an artificial CU that "includes" all the
831 type units using this stmt_list so that the rest of the code still has
832 a "per_cu" handle on the symtab.
833 This PER_CU is recognized by having no section. */
834 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
835 struct dwarf2_per_cu_data per_cu
;
837 /* The TUs that share this DW_AT_stmt_list entry.
838 This is added to while parsing type units to build partial symtabs,
839 and is deleted afterwards and not used again. */
840 VEC (sig_type_ptr
) *tus
;
842 /* The compunit symtab.
843 Type units in a group needn't all be defined in the same source file,
844 so we create an essentially anonymous symtab as the compunit symtab. */
845 struct compunit_symtab
*compunit_symtab
;
847 /* The data used to construct the hash key. */
848 struct stmt_list_hash hash
;
850 /* The number of symtabs from the line header.
851 The value here must match line_header.num_file_names. */
852 unsigned int num_symtabs
;
854 /* The symbol tables for this TU (obtained from the files listed in
856 WARNING: The order of entries here must match the order of entries
857 in the line header. After the first TU using this type_unit_group, the
858 line header for the subsequent TUs is recreated from this. This is done
859 because we need to use the same symtabs for each TU using the same
860 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
861 there's no guarantee the line header doesn't have duplicate entries. */
862 struct symtab
**symtabs
;
865 /* These sections are what may appear in a (real or virtual) DWO file. */
869 struct dwarf2_section_info abbrev
;
870 struct dwarf2_section_info line
;
871 struct dwarf2_section_info loc
;
872 struct dwarf2_section_info loclists
;
873 struct dwarf2_section_info macinfo
;
874 struct dwarf2_section_info macro
;
875 struct dwarf2_section_info str
;
876 struct dwarf2_section_info str_offsets
;
877 /* In the case of a virtual DWO file, these two are unused. */
878 struct dwarf2_section_info info
;
879 VEC (dwarf2_section_info_def
) *types
;
882 /* CUs/TUs in DWP/DWO files. */
886 /* Backlink to the containing struct dwo_file. */
887 struct dwo_file
*dwo_file
;
889 /* The "id" that distinguishes this CU/TU.
890 .debug_info calls this "dwo_id", .debug_types calls this "signature".
891 Since signatures came first, we stick with it for consistency. */
894 /* The section this CU/TU lives in, in the DWO file. */
895 struct dwarf2_section_info
*section
;
897 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
898 sect_offset sect_off
;
901 /* For types, offset in the type's DIE of the type defined by this TU. */
902 cu_offset type_offset_in_tu
;
905 /* include/dwarf2.h defines the DWP section codes.
906 It defines a max value but it doesn't define a min value, which we
907 use for error checking, so provide one. */
909 enum dwp_v2_section_ids
914 /* Data for one DWO file.
916 This includes virtual DWO files (a virtual DWO file is a DWO file as it
917 appears in a DWP file). DWP files don't really have DWO files per se -
918 comdat folding of types "loses" the DWO file they came from, and from
919 a high level view DWP files appear to contain a mass of random types.
920 However, to maintain consistency with the non-DWP case we pretend DWP
921 files contain virtual DWO files, and we assign each TU with one virtual
922 DWO file (generally based on the line and abbrev section offsets -
923 a heuristic that seems to work in practice). */
927 /* The DW_AT_GNU_dwo_name attribute.
928 For virtual DWO files the name is constructed from the section offsets
929 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
930 from related CU+TUs. */
931 const char *dwo_name
;
933 /* The DW_AT_comp_dir attribute. */
934 const char *comp_dir
;
936 /* The bfd, when the file is open. Otherwise this is NULL.
937 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
940 /* The sections that make up this DWO file.
941 Remember that for virtual DWO files in DWP V2, these are virtual
942 sections (for lack of a better name). */
943 struct dwo_sections sections
;
945 /* The CUs in the file.
946 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
947 an extension to handle LLVM's Link Time Optimization output (where
948 multiple source files may be compiled into a single object/dwo pair). */
951 /* Table of TUs in the file.
952 Each element is a struct dwo_unit. */
956 /* These sections are what may appear in a DWP file. */
960 /* These are used by both DWP version 1 and 2. */
961 struct dwarf2_section_info str
;
962 struct dwarf2_section_info cu_index
;
963 struct dwarf2_section_info tu_index
;
965 /* These are only used by DWP version 2 files.
966 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
967 sections are referenced by section number, and are not recorded here.
968 In DWP version 2 there is at most one copy of all these sections, each
969 section being (effectively) comprised of the concatenation of all of the
970 individual sections that exist in the version 1 format.
971 To keep the code simple we treat each of these concatenated pieces as a
972 section itself (a virtual section?). */
973 struct dwarf2_section_info abbrev
;
974 struct dwarf2_section_info info
;
975 struct dwarf2_section_info line
;
976 struct dwarf2_section_info loc
;
977 struct dwarf2_section_info macinfo
;
978 struct dwarf2_section_info macro
;
979 struct dwarf2_section_info str_offsets
;
980 struct dwarf2_section_info types
;
983 /* These sections are what may appear in a virtual DWO file in DWP version 1.
984 A virtual DWO file is a DWO file as it appears in a DWP file. */
986 struct virtual_v1_dwo_sections
988 struct dwarf2_section_info abbrev
;
989 struct dwarf2_section_info line
;
990 struct dwarf2_section_info loc
;
991 struct dwarf2_section_info macinfo
;
992 struct dwarf2_section_info macro
;
993 struct dwarf2_section_info str_offsets
;
994 /* Each DWP hash table entry records one CU or one TU.
995 That is recorded here, and copied to dwo_unit.section. */
996 struct dwarf2_section_info info_or_types
;
999 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
1000 In version 2, the sections of the DWO files are concatenated together
1001 and stored in one section of that name. Thus each ELF section contains
1002 several "virtual" sections. */
1004 struct virtual_v2_dwo_sections
1006 bfd_size_type abbrev_offset
;
1007 bfd_size_type abbrev_size
;
1009 bfd_size_type line_offset
;
1010 bfd_size_type line_size
;
1012 bfd_size_type loc_offset
;
1013 bfd_size_type loc_size
;
1015 bfd_size_type macinfo_offset
;
1016 bfd_size_type macinfo_size
;
1018 bfd_size_type macro_offset
;
1019 bfd_size_type macro_size
;
1021 bfd_size_type str_offsets_offset
;
1022 bfd_size_type str_offsets_size
;
1024 /* Each DWP hash table entry records one CU or one TU.
1025 That is recorded here, and copied to dwo_unit.section. */
1026 bfd_size_type info_or_types_offset
;
1027 bfd_size_type info_or_types_size
;
1030 /* Contents of DWP hash tables. */
1032 struct dwp_hash_table
1034 uint32_t version
, nr_columns
;
1035 uint32_t nr_units
, nr_slots
;
1036 const gdb_byte
*hash_table
, *unit_table
;
1041 const gdb_byte
*indices
;
1045 /* This is indexed by column number and gives the id of the section
1047 #define MAX_NR_V2_DWO_SECTIONS \
1048 (1 /* .debug_info or .debug_types */ \
1049 + 1 /* .debug_abbrev */ \
1050 + 1 /* .debug_line */ \
1051 + 1 /* .debug_loc */ \
1052 + 1 /* .debug_str_offsets */ \
1053 + 1 /* .debug_macro or .debug_macinfo */)
1054 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
1055 const gdb_byte
*offsets
;
1056 const gdb_byte
*sizes
;
1061 /* Data for one DWP file. */
1065 /* Name of the file. */
1068 /* File format version. */
1074 /* Section info for this file. */
1075 struct dwp_sections sections
;
1077 /* Table of CUs in the file. */
1078 const struct dwp_hash_table
*cus
;
1080 /* Table of TUs in the file. */
1081 const struct dwp_hash_table
*tus
;
1083 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
1087 /* Table to map ELF section numbers to their sections.
1088 This is only needed for the DWP V1 file format. */
1089 unsigned int num_sections
;
1090 asection
**elf_sections
;
1093 /* This represents a '.dwz' file. */
1097 /* A dwz file can only contain a few sections. */
1098 struct dwarf2_section_info abbrev
;
1099 struct dwarf2_section_info info
;
1100 struct dwarf2_section_info str
;
1101 struct dwarf2_section_info line
;
1102 struct dwarf2_section_info macro
;
1103 struct dwarf2_section_info gdb_index
;
1105 /* The dwz's BFD. */
1109 /* Struct used to pass misc. parameters to read_die_and_children, et
1110 al. which are used for both .debug_info and .debug_types dies.
1111 All parameters here are unchanging for the life of the call. This
1112 struct exists to abstract away the constant parameters of die reading. */
1114 struct die_reader_specs
1116 /* The bfd of die_section. */
1119 /* The CU of the DIE we are parsing. */
1120 struct dwarf2_cu
*cu
;
1122 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1123 struct dwo_file
*dwo_file
;
1125 /* The section the die comes from.
1126 This is either .debug_info or .debug_types, or the .dwo variants. */
1127 struct dwarf2_section_info
*die_section
;
1129 /* die_section->buffer. */
1130 const gdb_byte
*buffer
;
1132 /* The end of the buffer. */
1133 const gdb_byte
*buffer_end
;
1135 /* The value of the DW_AT_comp_dir attribute. */
1136 const char *comp_dir
;
1139 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1140 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1141 const gdb_byte
*info_ptr
,
1142 struct die_info
*comp_unit_die
,
1146 /* A 1-based directory index. This is a strong typedef to prevent
1147 accidentally using a directory index as a 0-based index into an
1149 enum class dir_index
: unsigned int {};
1151 /* Likewise, a 1-based file name index. */
1152 enum class file_name_index
: unsigned int {};
1156 file_entry () = default;
1158 file_entry (const char *name_
, dir_index d_index_
,
1159 unsigned int mod_time_
, unsigned int length_
)
1162 mod_time (mod_time_
),
1166 /* Return the include directory at D_INDEX stored in LH. Returns
1167 NULL if D_INDEX is out of bounds. */
1168 const char *include_dir (const line_header
*lh
) const;
1170 /* The file name. Note this is an observing pointer. The memory is
1171 owned by debug_line_buffer. */
1172 const char *name
{};
1174 /* The directory index (1-based). */
1175 dir_index d_index
{};
1177 unsigned int mod_time
{};
1179 unsigned int length
{};
1181 /* True if referenced by the Line Number Program. */
1184 /* The associated symbol table, if any. */
1185 struct symtab
*symtab
{};
1188 /* The line number information for a compilation unit (found in the
1189 .debug_line section) begins with a "statement program header",
1190 which contains the following information. */
1197 /* Add an entry to the include directory table. */
1198 void add_include_dir (const char *include_dir
);
1200 /* Add an entry to the file name table. */
1201 void add_file_name (const char *name
, dir_index d_index
,
1202 unsigned int mod_time
, unsigned int length
);
1204 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
1205 is out of bounds. */
1206 const char *include_dir_at (dir_index index
) const
1208 /* Convert directory index number (1-based) to vector index
1210 size_t vec_index
= to_underlying (index
) - 1;
1212 if (vec_index
>= include_dirs
.size ())
1214 return include_dirs
[vec_index
];
1217 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
1218 is out of bounds. */
1219 file_entry
*file_name_at (file_name_index index
)
1221 /* Convert file name index number (1-based) to vector index
1223 size_t vec_index
= to_underlying (index
) - 1;
1225 if (vec_index
>= file_names
.size ())
1227 return &file_names
[vec_index
];
1230 /* Const version of the above. */
1231 const file_entry
*file_name_at (unsigned int index
) const
1233 if (index
>= file_names
.size ())
1235 return &file_names
[index
];
1238 /* Offset of line number information in .debug_line section. */
1239 sect_offset sect_off
{};
1241 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1242 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1244 unsigned int total_length
{};
1245 unsigned short version
{};
1246 unsigned int header_length
{};
1247 unsigned char minimum_instruction_length
{};
1248 unsigned char maximum_ops_per_instruction
{};
1249 unsigned char default_is_stmt
{};
1251 unsigned char line_range
{};
1252 unsigned char opcode_base
{};
1254 /* standard_opcode_lengths[i] is the number of operands for the
1255 standard opcode whose value is i. This means that
1256 standard_opcode_lengths[0] is unused, and the last meaningful
1257 element is standard_opcode_lengths[opcode_base - 1]. */
1258 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1260 /* The include_directories table. Note these are observing
1261 pointers. The memory is owned by debug_line_buffer. */
1262 std::vector
<const char *> include_dirs
;
1264 /* The file_names table. */
1265 std::vector
<file_entry
> file_names
;
1267 /* The start and end of the statement program following this
1268 header. These point into dwarf2_per_objfile->line_buffer. */
1269 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1272 typedef std::unique_ptr
<line_header
> line_header_up
;
1275 file_entry::include_dir (const line_header
*lh
) const
1277 return lh
->include_dir_at (d_index
);
1280 /* When we construct a partial symbol table entry we only
1281 need this much information. */
1282 struct partial_die_info
1284 /* Offset of this DIE. */
1285 sect_offset sect_off
;
1287 /* DWARF-2 tag for this DIE. */
1288 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1290 /* Assorted flags describing the data found in this DIE. */
1291 unsigned int has_children
: 1;
1292 unsigned int is_external
: 1;
1293 unsigned int is_declaration
: 1;
1294 unsigned int has_type
: 1;
1295 unsigned int has_specification
: 1;
1296 unsigned int has_pc_info
: 1;
1297 unsigned int may_be_inlined
: 1;
1299 /* This DIE has been marked DW_AT_main_subprogram. */
1300 unsigned int main_subprogram
: 1;
1302 /* Flag set if the SCOPE field of this structure has been
1304 unsigned int scope_set
: 1;
1306 /* Flag set if the DIE has a byte_size attribute. */
1307 unsigned int has_byte_size
: 1;
1309 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1310 unsigned int has_const_value
: 1;
1312 /* Flag set if any of the DIE's children are template arguments. */
1313 unsigned int has_template_arguments
: 1;
1315 /* Flag set if fixup_partial_die has been called on this die. */
1316 unsigned int fixup_called
: 1;
1318 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1319 unsigned int is_dwz
: 1;
1321 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1322 unsigned int spec_is_dwz
: 1;
1324 /* The name of this DIE. Normally the value of DW_AT_name, but
1325 sometimes a default name for unnamed DIEs. */
1328 /* The linkage name, if present. */
1329 const char *linkage_name
;
1331 /* The scope to prepend to our children. This is generally
1332 allocated on the comp_unit_obstack, so will disappear
1333 when this compilation unit leaves the cache. */
1336 /* Some data associated with the partial DIE. The tag determines
1337 which field is live. */
1340 /* The location description associated with this DIE, if any. */
1341 struct dwarf_block
*locdesc
;
1342 /* The offset of an import, for DW_TAG_imported_unit. */
1343 sect_offset sect_off
;
1346 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1350 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1351 DW_AT_sibling, if any. */
1352 /* NOTE: This member isn't strictly necessary, read_partial_die could
1353 return DW_AT_sibling values to its caller load_partial_dies. */
1354 const gdb_byte
*sibling
;
1356 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1357 DW_AT_specification (or DW_AT_abstract_origin or
1358 DW_AT_extension). */
1359 sect_offset spec_offset
;
1361 /* Pointers to this DIE's parent, first child, and next sibling,
1363 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
1366 /* This data structure holds the information of an abbrev. */
1369 unsigned int number
; /* number identifying abbrev */
1370 enum dwarf_tag tag
; /* dwarf tag */
1371 unsigned short has_children
; /* boolean */
1372 unsigned short num_attrs
; /* number of attributes */
1373 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1374 struct abbrev_info
*next
; /* next in chain */
1379 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1380 ENUM_BITFIELD(dwarf_form
) form
: 16;
1382 /* It is valid only if FORM is DW_FORM_implicit_const. */
1383 LONGEST implicit_const
;
1386 /* Size of abbrev_table.abbrev_hash_table. */
1387 #define ABBREV_HASH_SIZE 121
1389 /* Top level data structure to contain an abbreviation table. */
1393 /* Where the abbrev table came from.
1394 This is used as a sanity check when the table is used. */
1395 sect_offset sect_off
;
1397 /* Storage for the abbrev table. */
1398 struct obstack abbrev_obstack
;
1400 /* Hash table of abbrevs.
1401 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1402 It could be statically allocated, but the previous code didn't so we
1404 struct abbrev_info
**abbrevs
;
1407 /* Attributes have a name and a value. */
1410 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1411 ENUM_BITFIELD(dwarf_form
) form
: 15;
1413 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1414 field should be in u.str (existing only for DW_STRING) but it is kept
1415 here for better struct attribute alignment. */
1416 unsigned int string_is_canonical
: 1;
1421 struct dwarf_block
*blk
;
1430 /* This data structure holds a complete die structure. */
1433 /* DWARF-2 tag for this DIE. */
1434 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1436 /* Number of attributes */
1437 unsigned char num_attrs
;
1439 /* True if we're presently building the full type name for the
1440 type derived from this DIE. */
1441 unsigned char building_fullname
: 1;
1443 /* True if this die is in process. PR 16581. */
1444 unsigned char in_process
: 1;
1447 unsigned int abbrev
;
1449 /* Offset in .debug_info or .debug_types section. */
1450 sect_offset sect_off
;
1452 /* The dies in a compilation unit form an n-ary tree. PARENT
1453 points to this die's parent; CHILD points to the first child of
1454 this node; and all the children of a given node are chained
1455 together via their SIBLING fields. */
1456 struct die_info
*child
; /* Its first child, if any. */
1457 struct die_info
*sibling
; /* Its next sibling, if any. */
1458 struct die_info
*parent
; /* Its parent, if any. */
1460 /* An array of attributes, with NUM_ATTRS elements. There may be
1461 zero, but it's not common and zero-sized arrays are not
1462 sufficiently portable C. */
1463 struct attribute attrs
[1];
1466 /* Get at parts of an attribute structure. */
1468 #define DW_STRING(attr) ((attr)->u.str)
1469 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1470 #define DW_UNSND(attr) ((attr)->u.unsnd)
1471 #define DW_BLOCK(attr) ((attr)->u.blk)
1472 #define DW_SND(attr) ((attr)->u.snd)
1473 #define DW_ADDR(attr) ((attr)->u.addr)
1474 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1476 /* Blocks are a bunch of untyped bytes. */
1481 /* Valid only if SIZE is not zero. */
1482 const gdb_byte
*data
;
1485 #ifndef ATTR_ALLOC_CHUNK
1486 #define ATTR_ALLOC_CHUNK 4
1489 /* Allocate fields for structs, unions and enums in this size. */
1490 #ifndef DW_FIELD_ALLOC_CHUNK
1491 #define DW_FIELD_ALLOC_CHUNK 4
1494 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1495 but this would require a corresponding change in unpack_field_as_long
1497 static int bits_per_byte
= 8;
1501 struct nextfield
*next
;
1509 struct nextfnfield
*next
;
1510 struct fn_field fnfield
;
1517 struct nextfnfield
*head
;
1520 struct typedef_field_list
1522 struct typedef_field field
;
1523 struct typedef_field_list
*next
;
1526 /* The routines that read and process dies for a C struct or C++ class
1527 pass lists of data member fields and lists of member function fields
1528 in an instance of a field_info structure, as defined below. */
1531 /* List of data member and baseclasses fields. */
1532 struct nextfield
*fields
, *baseclasses
;
1534 /* Number of fields (including baseclasses). */
1537 /* Number of baseclasses. */
1540 /* Set if the accesibility of one of the fields is not public. */
1541 int non_public_fields
;
1543 /* Member function fieldlist array, contains name of possibly overloaded
1544 member function, number of overloaded member functions and a pointer
1545 to the head of the member function field chain. */
1546 struct fnfieldlist
*fnfieldlists
;
1548 /* Number of entries in the fnfieldlists array. */
1551 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1552 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1553 struct typedef_field_list
*typedef_field_list
;
1554 unsigned typedef_field_list_count
;
1557 /* One item on the queue of compilation units to read in full symbols
1559 struct dwarf2_queue_item
1561 struct dwarf2_per_cu_data
*per_cu
;
1562 enum language pretend_language
;
1563 struct dwarf2_queue_item
*next
;
1566 /* The current queue. */
1567 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1569 /* Loaded secondary compilation units are kept in memory until they
1570 have not been referenced for the processing of this many
1571 compilation units. Set this to zero to disable caching. Cache
1572 sizes of up to at least twenty will improve startup time for
1573 typical inter-CU-reference binaries, at an obvious memory cost. */
1574 static int dwarf_max_cache_age
= 5;
1576 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1577 struct cmd_list_element
*c
, const char *value
)
1579 fprintf_filtered (file
, _("The upper bound on the age of cached "
1580 "DWARF compilation units is %s.\n"),
1584 /* local function prototypes */
1586 static const char *get_section_name (const struct dwarf2_section_info
*);
1588 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1590 static void dwarf2_find_base_address (struct die_info
*die
,
1591 struct dwarf2_cu
*cu
);
1593 static struct partial_symtab
*create_partial_symtab
1594 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1596 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1597 const gdb_byte
*info_ptr
,
1598 struct die_info
*type_unit_die
,
1599 int has_children
, void *data
);
1601 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1603 static void scan_partial_symbols (struct partial_die_info
*,
1604 CORE_ADDR
*, CORE_ADDR
*,
1605 int, struct dwarf2_cu
*);
1607 static void add_partial_symbol (struct partial_die_info
*,
1608 struct dwarf2_cu
*);
1610 static void add_partial_namespace (struct partial_die_info
*pdi
,
1611 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1612 int set_addrmap
, struct dwarf2_cu
*cu
);
1614 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1615 CORE_ADDR
*highpc
, int set_addrmap
,
1616 struct dwarf2_cu
*cu
);
1618 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1619 struct dwarf2_cu
*cu
);
1621 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1622 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1623 int need_pc
, struct dwarf2_cu
*cu
);
1625 static void dwarf2_read_symtab (struct partial_symtab
*,
1628 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1630 static struct abbrev_info
*abbrev_table_lookup_abbrev
1631 (const struct abbrev_table
*, unsigned int);
1633 static struct abbrev_table
*abbrev_table_read_table
1634 (struct dwarf2_section_info
*, sect_offset
);
1636 static void abbrev_table_free (struct abbrev_table
*);
1638 static void abbrev_table_free_cleanup (void *);
1640 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1641 struct dwarf2_section_info
*);
1643 static void dwarf2_free_abbrev_table (void *);
1645 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1647 static struct partial_die_info
*load_partial_dies
1648 (const struct die_reader_specs
*, const gdb_byte
*, int);
1650 static const gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1651 struct partial_die_info
*,
1652 struct abbrev_info
*,
1656 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1657 struct dwarf2_cu
*);
1659 static void fixup_partial_die (struct partial_die_info
*,
1660 struct dwarf2_cu
*);
1662 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1663 struct attribute
*, struct attr_abbrev
*,
1666 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1668 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1670 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1672 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1674 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1676 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1679 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1681 static LONGEST read_checked_initial_length_and_offset
1682 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1683 unsigned int *, unsigned int *);
1685 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1686 const struct comp_unit_head
*,
1689 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1691 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1694 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1696 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1698 static const char *read_indirect_string (bfd
*, const gdb_byte
*,
1699 const struct comp_unit_head
*,
1702 static const char *read_indirect_line_string (bfd
*, const gdb_byte
*,
1703 const struct comp_unit_head
*,
1706 static const char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1708 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1710 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1714 static const char *read_str_index (const struct die_reader_specs
*reader
,
1715 ULONGEST str_index
);
1717 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1719 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1720 struct dwarf2_cu
*);
1722 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1725 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1726 struct dwarf2_cu
*cu
);
1728 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1729 struct dwarf2_cu
*cu
);
1731 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1733 static struct die_info
*die_specification (struct die_info
*die
,
1734 struct dwarf2_cu
**);
1736 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1737 struct dwarf2_cu
*cu
);
1739 static void dwarf_decode_lines (struct line_header
*, const char *,
1740 struct dwarf2_cu
*, struct partial_symtab
*,
1741 CORE_ADDR
, int decode_mapping
);
1743 static void dwarf2_start_subfile (const char *, const char *);
1745 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1746 const char *, const char *,
1749 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1750 struct dwarf2_cu
*);
1752 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1753 struct dwarf2_cu
*, struct symbol
*);
1755 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1756 struct dwarf2_cu
*);
1758 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1761 struct obstack
*obstack
,
1762 struct dwarf2_cu
*cu
, LONGEST
*value
,
1763 const gdb_byte
**bytes
,
1764 struct dwarf2_locexpr_baton
**baton
);
1766 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1768 static int need_gnat_info (struct dwarf2_cu
*);
1770 static struct type
*die_descriptive_type (struct die_info
*,
1771 struct dwarf2_cu
*);
1773 static void set_descriptive_type (struct type
*, struct die_info
*,
1774 struct dwarf2_cu
*);
1776 static struct type
*die_containing_type (struct die_info
*,
1777 struct dwarf2_cu
*);
1779 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1780 struct dwarf2_cu
*);
1782 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1784 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1786 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1788 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1789 const char *suffix
, int physname
,
1790 struct dwarf2_cu
*cu
);
1792 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1794 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1796 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1798 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1800 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1802 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1803 struct dwarf2_cu
*, struct partial_symtab
*);
1805 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1806 values. Keep the items ordered with increasing constraints compliance. */
1809 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1810 PC_BOUNDS_NOT_PRESENT
,
1812 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1813 were present but they do not form a valid range of PC addresses. */
1816 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1819 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1823 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1824 CORE_ADDR
*, CORE_ADDR
*,
1826 struct partial_symtab
*);
1828 static void get_scope_pc_bounds (struct die_info
*,
1829 CORE_ADDR
*, CORE_ADDR
*,
1830 struct dwarf2_cu
*);
1832 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1833 CORE_ADDR
, struct dwarf2_cu
*);
1835 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1836 struct dwarf2_cu
*);
1838 static void dwarf2_attach_fields_to_type (struct field_info
*,
1839 struct type
*, struct dwarf2_cu
*);
1841 static void dwarf2_add_member_fn (struct field_info
*,
1842 struct die_info
*, struct type
*,
1843 struct dwarf2_cu
*);
1845 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1847 struct dwarf2_cu
*);
1849 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1851 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1853 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1855 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1857 static struct using_direct
**using_directives (enum language
);
1859 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1861 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1863 static struct type
*read_module_type (struct die_info
*die
,
1864 struct dwarf2_cu
*cu
);
1866 static const char *namespace_name (struct die_info
*die
,
1867 int *is_anonymous
, struct dwarf2_cu
*);
1869 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1871 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1873 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1874 struct dwarf2_cu
*);
1876 static struct die_info
*read_die_and_siblings_1
1877 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1880 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1881 const gdb_byte
*info_ptr
,
1882 const gdb_byte
**new_info_ptr
,
1883 struct die_info
*parent
);
1885 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1886 struct die_info
**, const gdb_byte
*,
1889 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1890 struct die_info
**, const gdb_byte
*,
1893 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1895 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1898 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1900 static const char *dwarf2_full_name (const char *name
,
1901 struct die_info
*die
,
1902 struct dwarf2_cu
*cu
);
1904 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1905 struct dwarf2_cu
*cu
);
1907 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1908 struct dwarf2_cu
**);
1910 static const char *dwarf_tag_name (unsigned int);
1912 static const char *dwarf_attr_name (unsigned int);
1914 static const char *dwarf_form_name (unsigned int);
1916 static const char *dwarf_bool_name (unsigned int);
1918 static const char *dwarf_type_encoding_name (unsigned int);
1920 static struct die_info
*sibling_die (struct die_info
*);
1922 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1924 static void dump_die_for_error (struct die_info
*);
1926 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1929 /*static*/ void dump_die (struct die_info
*, int max_level
);
1931 static void store_in_ref_table (struct die_info
*,
1932 struct dwarf2_cu
*);
1934 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1936 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1938 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1939 const struct attribute
*,
1940 struct dwarf2_cu
**);
1942 static struct die_info
*follow_die_ref (struct die_info
*,
1943 const struct attribute
*,
1944 struct dwarf2_cu
**);
1946 static struct die_info
*follow_die_sig (struct die_info
*,
1947 const struct attribute
*,
1948 struct dwarf2_cu
**);
1950 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1951 struct dwarf2_cu
*);
1953 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1954 const struct attribute
*,
1955 struct dwarf2_cu
*);
1957 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1959 static void read_signatured_type (struct signatured_type
*);
1961 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1962 struct die_info
*die
, struct dwarf2_cu
*cu
,
1963 struct dynamic_prop
*prop
);
1965 /* memory allocation interface */
1967 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1969 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1971 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1973 static int attr_form_is_block (const struct attribute
*);
1975 static int attr_form_is_section_offset (const struct attribute
*);
1977 static int attr_form_is_constant (const struct attribute
*);
1979 static int attr_form_is_ref (const struct attribute
*);
1981 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1982 struct dwarf2_loclist_baton
*baton
,
1983 const struct attribute
*attr
);
1985 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1987 struct dwarf2_cu
*cu
,
1990 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1991 const gdb_byte
*info_ptr
,
1992 struct abbrev_info
*abbrev
);
1994 static void free_stack_comp_unit (void *);
1996 static hashval_t
partial_die_hash (const void *item
);
1998 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
2000 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
2001 (sect_offset sect_off
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
2003 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
2004 struct dwarf2_per_cu_data
*per_cu
);
2006 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
2007 struct die_info
*comp_unit_die
,
2008 enum language pretend_language
);
2010 static void free_heap_comp_unit (void *);
2012 static void free_cached_comp_units (void *);
2014 static void age_cached_comp_units (void);
2016 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
2018 static struct type
*set_die_type (struct die_info
*, struct type
*,
2019 struct dwarf2_cu
*);
2021 static void create_all_comp_units (struct objfile
*);
2023 static int create_all_type_units (struct objfile
*);
2025 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
2028 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
2031 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
2034 static void dwarf2_add_dependence (struct dwarf2_cu
*,
2035 struct dwarf2_per_cu_data
*);
2037 static void dwarf2_mark (struct dwarf2_cu
*);
2039 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
2041 static struct type
*get_die_type_at_offset (sect_offset
,
2042 struct dwarf2_per_cu_data
*);
2044 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
2046 static void dwarf2_release_queue (void *dummy
);
2048 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
2049 enum language pretend_language
);
2051 static void process_queue (void);
2053 /* The return type of find_file_and_directory. Note, the enclosed
2054 string pointers are only valid while this object is valid. */
2056 struct file_and_directory
2058 /* The filename. This is never NULL. */
2061 /* The compilation directory. NULL if not known. If we needed to
2062 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
2063 points directly to the DW_AT_comp_dir string attribute owned by
2064 the obstack that owns the DIE. */
2065 const char *comp_dir
;
2067 /* If we needed to build a new string for comp_dir, this is what
2068 owns the storage. */
2069 std::string comp_dir_storage
;
2072 static file_and_directory
find_file_and_directory (struct die_info
*die
,
2073 struct dwarf2_cu
*cu
);
2075 static char *file_full_name (int file
, struct line_header
*lh
,
2076 const char *comp_dir
);
2078 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
2079 enum class rcuh_kind
{ COMPILE
, TYPE
};
2081 static const gdb_byte
*read_and_check_comp_unit_head
2082 (struct comp_unit_head
*header
,
2083 struct dwarf2_section_info
*section
,
2084 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
2085 rcuh_kind section_kind
);
2087 static void init_cutu_and_read_dies
2088 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
2089 int use_existing_cu
, int keep
,
2090 die_reader_func_ftype
*die_reader_func
, void *data
);
2092 static void init_cutu_and_read_dies_simple
2093 (struct dwarf2_per_cu_data
*this_cu
,
2094 die_reader_func_ftype
*die_reader_func
, void *data
);
2096 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2098 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2100 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2101 (struct dwp_file
*dwp_file
, const char *comp_dir
,
2102 ULONGEST signature
, int is_debug_types
);
2104 static struct dwp_file
*get_dwp_file (void);
2106 static struct dwo_unit
*lookup_dwo_comp_unit
2107 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2109 static struct dwo_unit
*lookup_dwo_type_unit
2110 (struct signatured_type
*, const char *, const char *);
2112 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2114 static void free_dwo_file_cleanup (void *);
2116 static void process_cu_includes (void);
2118 static void check_producer (struct dwarf2_cu
*cu
);
2120 static void free_line_header_voidp (void *arg
);
2122 /* Various complaints about symbol reading that don't abort the process. */
2125 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2127 complaint (&symfile_complaints
,
2128 _("statement list doesn't fit in .debug_line section"));
2132 dwarf2_debug_line_missing_file_complaint (void)
2134 complaint (&symfile_complaints
,
2135 _(".debug_line section has line data without a file"));
2139 dwarf2_debug_line_missing_end_sequence_complaint (void)
2141 complaint (&symfile_complaints
,
2142 _(".debug_line section has line "
2143 "program sequence without an end"));
2147 dwarf2_complex_location_expr_complaint (void)
2149 complaint (&symfile_complaints
, _("location expression too complex"));
2153 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2156 complaint (&symfile_complaints
,
2157 _("const value length mismatch for '%s', got %d, expected %d"),
2162 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2164 complaint (&symfile_complaints
,
2165 _("debug info runs off end of %s section"
2167 get_section_name (section
),
2168 get_section_file_name (section
));
2172 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2174 complaint (&symfile_complaints
,
2175 _("macro debug info contains a "
2176 "malformed macro definition:\n`%s'"),
2181 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2183 complaint (&symfile_complaints
,
2184 _("invalid attribute class or form for '%s' in '%s'"),
2188 /* Hash function for line_header_hash. */
2191 line_header_hash (const struct line_header
*ofs
)
2193 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2196 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2199 line_header_hash_voidp (const void *item
)
2201 const struct line_header
*ofs
= (const struct line_header
*) item
;
2203 return line_header_hash (ofs
);
2206 /* Equality function for line_header_hash. */
2209 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2211 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2212 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2214 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2215 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2220 /* Read the given attribute value as an address, taking the attribute's
2221 form into account. */
2224 attr_value_as_address (struct attribute
*attr
)
2228 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2230 /* Aside from a few clearly defined exceptions, attributes that
2231 contain an address must always be in DW_FORM_addr form.
2232 Unfortunately, some compilers happen to be violating this
2233 requirement by encoding addresses using other forms, such
2234 as DW_FORM_data4 for example. For those broken compilers,
2235 we try to do our best, without any guarantee of success,
2236 to interpret the address correctly. It would also be nice
2237 to generate a complaint, but that would require us to maintain
2238 a list of legitimate cases where a non-address form is allowed,
2239 as well as update callers to pass in at least the CU's DWARF
2240 version. This is more overhead than what we're willing to
2241 expand for a pretty rare case. */
2242 addr
= DW_UNSND (attr
);
2245 addr
= DW_ADDR (attr
);
2250 /* The suffix for an index file. */
2251 #define INDEX_SUFFIX ".gdb-index"
2253 /* See declaration. */
2255 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2256 const dwarf2_debug_sections
*names
)
2257 : objfile (objfile_
)
2260 names
= &dwarf2_elf_names
;
2262 bfd
*obfd
= objfile
->obfd
;
2264 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2265 locate_sections (obfd
, sec
, *names
);
2268 dwarf2_per_objfile::~dwarf2_per_objfile ()
2270 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2271 free_cached_comp_units ();
2273 if (quick_file_names_table
)
2274 htab_delete (quick_file_names_table
);
2276 if (line_header_hash
)
2277 htab_delete (line_header_hash
);
2279 /* Everything else should be on the objfile obstack. */
2282 /* See declaration. */
2285 dwarf2_per_objfile::free_cached_comp_units ()
2287 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2288 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2289 while (per_cu
!= NULL
)
2291 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2293 free_heap_comp_unit (per_cu
->cu
);
2294 *last_chain
= next_cu
;
2299 /* Try to locate the sections we need for DWARF 2 debugging
2300 information and return true if we have enough to do something.
2301 NAMES points to the dwarf2 section names, or is NULL if the standard
2302 ELF names are used. */
2305 dwarf2_has_info (struct objfile
*objfile
,
2306 const struct dwarf2_debug_sections
*names
)
2308 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
2309 objfile_data (objfile
, dwarf2_objfile_data_key
));
2310 if (!dwarf2_per_objfile
)
2312 /* Initialize per-objfile state. */
2313 struct dwarf2_per_objfile
*data
2314 = XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_objfile
);
2316 dwarf2_per_objfile
= new (data
) struct dwarf2_per_objfile (objfile
, names
);
2317 set_objfile_data (objfile
, dwarf2_objfile_data_key
, dwarf2_per_objfile
);
2319 return (!dwarf2_per_objfile
->info
.is_virtual
2320 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2321 && !dwarf2_per_objfile
->abbrev
.is_virtual
2322 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2325 /* Return the containing section of virtual section SECTION. */
2327 static struct dwarf2_section_info
*
2328 get_containing_section (const struct dwarf2_section_info
*section
)
2330 gdb_assert (section
->is_virtual
);
2331 return section
->s
.containing_section
;
2334 /* Return the bfd owner of SECTION. */
2337 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2339 if (section
->is_virtual
)
2341 section
= get_containing_section (section
);
2342 gdb_assert (!section
->is_virtual
);
2344 return section
->s
.section
->owner
;
2347 /* Return the bfd section of SECTION.
2348 Returns NULL if the section is not present. */
2351 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2353 if (section
->is_virtual
)
2355 section
= get_containing_section (section
);
2356 gdb_assert (!section
->is_virtual
);
2358 return section
->s
.section
;
2361 /* Return the name of SECTION. */
2364 get_section_name (const struct dwarf2_section_info
*section
)
2366 asection
*sectp
= get_section_bfd_section (section
);
2368 gdb_assert (sectp
!= NULL
);
2369 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2372 /* Return the name of the file SECTION is in. */
2375 get_section_file_name (const struct dwarf2_section_info
*section
)
2377 bfd
*abfd
= get_section_bfd_owner (section
);
2379 return bfd_get_filename (abfd
);
2382 /* Return the id of SECTION.
2383 Returns 0 if SECTION doesn't exist. */
2386 get_section_id (const struct dwarf2_section_info
*section
)
2388 asection
*sectp
= get_section_bfd_section (section
);
2395 /* Return the flags of SECTION.
2396 SECTION (or containing section if this is a virtual section) must exist. */
2399 get_section_flags (const struct dwarf2_section_info
*section
)
2401 asection
*sectp
= get_section_bfd_section (section
);
2403 gdb_assert (sectp
!= NULL
);
2404 return bfd_get_section_flags (sectp
->owner
, sectp
);
2407 /* When loading sections, we look either for uncompressed section or for
2408 compressed section names. */
2411 section_is_p (const char *section_name
,
2412 const struct dwarf2_section_names
*names
)
2414 if (names
->normal
!= NULL
2415 && strcmp (section_name
, names
->normal
) == 0)
2417 if (names
->compressed
!= NULL
2418 && strcmp (section_name
, names
->compressed
) == 0)
2423 /* See declaration. */
2426 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2427 const dwarf2_debug_sections
&names
)
2429 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2431 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2434 else if (section_is_p (sectp
->name
, &names
.info
))
2436 this->info
.s
.section
= sectp
;
2437 this->info
.size
= bfd_get_section_size (sectp
);
2439 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2441 this->abbrev
.s
.section
= sectp
;
2442 this->abbrev
.size
= bfd_get_section_size (sectp
);
2444 else if (section_is_p (sectp
->name
, &names
.line
))
2446 this->line
.s
.section
= sectp
;
2447 this->line
.size
= bfd_get_section_size (sectp
);
2449 else if (section_is_p (sectp
->name
, &names
.loc
))
2451 this->loc
.s
.section
= sectp
;
2452 this->loc
.size
= bfd_get_section_size (sectp
);
2454 else if (section_is_p (sectp
->name
, &names
.loclists
))
2456 this->loclists
.s
.section
= sectp
;
2457 this->loclists
.size
= bfd_get_section_size (sectp
);
2459 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2461 this->macinfo
.s
.section
= sectp
;
2462 this->macinfo
.size
= bfd_get_section_size (sectp
);
2464 else if (section_is_p (sectp
->name
, &names
.macro
))
2466 this->macro
.s
.section
= sectp
;
2467 this->macro
.size
= bfd_get_section_size (sectp
);
2469 else if (section_is_p (sectp
->name
, &names
.str
))
2471 this->str
.s
.section
= sectp
;
2472 this->str
.size
= bfd_get_section_size (sectp
);
2474 else if (section_is_p (sectp
->name
, &names
.line_str
))
2476 this->line_str
.s
.section
= sectp
;
2477 this->line_str
.size
= bfd_get_section_size (sectp
);
2479 else if (section_is_p (sectp
->name
, &names
.addr
))
2481 this->addr
.s
.section
= sectp
;
2482 this->addr
.size
= bfd_get_section_size (sectp
);
2484 else if (section_is_p (sectp
->name
, &names
.frame
))
2486 this->frame
.s
.section
= sectp
;
2487 this->frame
.size
= bfd_get_section_size (sectp
);
2489 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2491 this->eh_frame
.s
.section
= sectp
;
2492 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2494 else if (section_is_p (sectp
->name
, &names
.ranges
))
2496 this->ranges
.s
.section
= sectp
;
2497 this->ranges
.size
= bfd_get_section_size (sectp
);
2499 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2501 this->rnglists
.s
.section
= sectp
;
2502 this->rnglists
.size
= bfd_get_section_size (sectp
);
2504 else if (section_is_p (sectp
->name
, &names
.types
))
2506 struct dwarf2_section_info type_section
;
2508 memset (&type_section
, 0, sizeof (type_section
));
2509 type_section
.s
.section
= sectp
;
2510 type_section
.size
= bfd_get_section_size (sectp
);
2512 VEC_safe_push (dwarf2_section_info_def
, this->types
,
2515 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2517 this->gdb_index
.s
.section
= sectp
;
2518 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2521 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2522 && bfd_section_vma (abfd
, sectp
) == 0)
2523 this->has_section_at_zero
= true;
2526 /* A helper function that decides whether a section is empty,
2530 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2532 if (section
->is_virtual
)
2533 return section
->size
== 0;
2534 return section
->s
.section
== NULL
|| section
->size
== 0;
2537 /* Read the contents of the section INFO.
2538 OBJFILE is the main object file, but not necessarily the file where
2539 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2541 If the section is compressed, uncompress it before returning. */
2544 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2548 gdb_byte
*buf
, *retbuf
;
2552 info
->buffer
= NULL
;
2555 if (dwarf2_section_empty_p (info
))
2558 sectp
= get_section_bfd_section (info
);
2560 /* If this is a virtual section we need to read in the real one first. */
2561 if (info
->is_virtual
)
2563 struct dwarf2_section_info
*containing_section
=
2564 get_containing_section (info
);
2566 gdb_assert (sectp
!= NULL
);
2567 if ((sectp
->flags
& SEC_RELOC
) != 0)
2569 error (_("Dwarf Error: DWP format V2 with relocations is not"
2570 " supported in section %s [in module %s]"),
2571 get_section_name (info
), get_section_file_name (info
));
2573 dwarf2_read_section (objfile
, containing_section
);
2574 /* Other code should have already caught virtual sections that don't
2576 gdb_assert (info
->virtual_offset
+ info
->size
2577 <= containing_section
->size
);
2578 /* If the real section is empty or there was a problem reading the
2579 section we shouldn't get here. */
2580 gdb_assert (containing_section
->buffer
!= NULL
);
2581 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2585 /* If the section has relocations, we must read it ourselves.
2586 Otherwise we attach it to the BFD. */
2587 if ((sectp
->flags
& SEC_RELOC
) == 0)
2589 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2593 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2596 /* When debugging .o files, we may need to apply relocations; see
2597 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2598 We never compress sections in .o files, so we only need to
2599 try this when the section is not compressed. */
2600 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2603 info
->buffer
= retbuf
;
2607 abfd
= get_section_bfd_owner (info
);
2608 gdb_assert (abfd
!= NULL
);
2610 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2611 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2613 error (_("Dwarf Error: Can't read DWARF data"
2614 " in section %s [in module %s]"),
2615 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2619 /* A helper function that returns the size of a section in a safe way.
2620 If you are positive that the section has been read before using the
2621 size, then it is safe to refer to the dwarf2_section_info object's
2622 "size" field directly. In other cases, you must call this
2623 function, because for compressed sections the size field is not set
2624 correctly until the section has been read. */
2626 static bfd_size_type
2627 dwarf2_section_size (struct objfile
*objfile
,
2628 struct dwarf2_section_info
*info
)
2631 dwarf2_read_section (objfile
, info
);
2635 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2639 dwarf2_get_section_info (struct objfile
*objfile
,
2640 enum dwarf2_section_enum sect
,
2641 asection
**sectp
, const gdb_byte
**bufp
,
2642 bfd_size_type
*sizep
)
2644 struct dwarf2_per_objfile
*data
2645 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2646 dwarf2_objfile_data_key
);
2647 struct dwarf2_section_info
*info
;
2649 /* We may see an objfile without any DWARF, in which case we just
2660 case DWARF2_DEBUG_FRAME
:
2661 info
= &data
->frame
;
2663 case DWARF2_EH_FRAME
:
2664 info
= &data
->eh_frame
;
2667 gdb_assert_not_reached ("unexpected section");
2670 dwarf2_read_section (objfile
, info
);
2672 *sectp
= get_section_bfd_section (info
);
2673 *bufp
= info
->buffer
;
2674 *sizep
= info
->size
;
2677 /* A helper function to find the sections for a .dwz file. */
2680 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2682 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2684 /* Note that we only support the standard ELF names, because .dwz
2685 is ELF-only (at the time of writing). */
2686 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2688 dwz_file
->abbrev
.s
.section
= sectp
;
2689 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2691 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2693 dwz_file
->info
.s
.section
= sectp
;
2694 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2696 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2698 dwz_file
->str
.s
.section
= sectp
;
2699 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2701 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2703 dwz_file
->line
.s
.section
= sectp
;
2704 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2706 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2708 dwz_file
->macro
.s
.section
= sectp
;
2709 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2711 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2713 dwz_file
->gdb_index
.s
.section
= sectp
;
2714 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2718 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2719 there is no .gnu_debugaltlink section in the file. Error if there
2720 is such a section but the file cannot be found. */
2722 static struct dwz_file
*
2723 dwarf2_get_dwz_file (void)
2725 const char *filename
;
2726 struct dwz_file
*result
;
2727 bfd_size_type buildid_len_arg
;
2731 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2732 return dwarf2_per_objfile
->dwz_file
;
2734 bfd_set_error (bfd_error_no_error
);
2735 gdb::unique_xmalloc_ptr
<char> data
2736 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2737 &buildid_len_arg
, &buildid
));
2740 if (bfd_get_error () == bfd_error_no_error
)
2742 error (_("could not read '.gnu_debugaltlink' section: %s"),
2743 bfd_errmsg (bfd_get_error ()));
2746 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2748 buildid_len
= (size_t) buildid_len_arg
;
2750 filename
= data
.get ();
2752 std::string abs_storage
;
2753 if (!IS_ABSOLUTE_PATH (filename
))
2755 gdb::unique_xmalloc_ptr
<char> abs
2756 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2758 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2759 filename
= abs_storage
.c_str ();
2762 /* First try the file name given in the section. If that doesn't
2763 work, try to use the build-id instead. */
2764 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2765 if (dwz_bfd
!= NULL
)
2767 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2771 if (dwz_bfd
== NULL
)
2772 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2774 if (dwz_bfd
== NULL
)
2775 error (_("could not find '.gnu_debugaltlink' file for %s"),
2776 objfile_name (dwarf2_per_objfile
->objfile
));
2778 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2780 result
->dwz_bfd
= dwz_bfd
.release ();
2782 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
2784 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
2785 dwarf2_per_objfile
->dwz_file
= result
;
2789 /* DWARF quick_symbols_functions support. */
2791 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2792 unique line tables, so we maintain a separate table of all .debug_line
2793 derived entries to support the sharing.
2794 All the quick functions need is the list of file names. We discard the
2795 line_header when we're done and don't need to record it here. */
2796 struct quick_file_names
2798 /* The data used to construct the hash key. */
2799 struct stmt_list_hash hash
;
2801 /* The number of entries in file_names, real_names. */
2802 unsigned int num_file_names
;
2804 /* The file names from the line table, after being run through
2806 const char **file_names
;
2808 /* The file names from the line table after being run through
2809 gdb_realpath. These are computed lazily. */
2810 const char **real_names
;
2813 /* When using the index (and thus not using psymtabs), each CU has an
2814 object of this type. This is used to hold information needed by
2815 the various "quick" methods. */
2816 struct dwarf2_per_cu_quick_data
2818 /* The file table. This can be NULL if there was no file table
2819 or it's currently not read in.
2820 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2821 struct quick_file_names
*file_names
;
2823 /* The corresponding symbol table. This is NULL if symbols for this
2824 CU have not yet been read. */
2825 struct compunit_symtab
*compunit_symtab
;
2827 /* A temporary mark bit used when iterating over all CUs in
2828 expand_symtabs_matching. */
2829 unsigned int mark
: 1;
2831 /* True if we've tried to read the file table and found there isn't one.
2832 There will be no point in trying to read it again next time. */
2833 unsigned int no_file_data
: 1;
2836 /* Utility hash function for a stmt_list_hash. */
2839 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2843 if (stmt_list_hash
->dwo_unit
!= NULL
)
2844 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2845 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2849 /* Utility equality function for a stmt_list_hash. */
2852 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2853 const struct stmt_list_hash
*rhs
)
2855 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2857 if (lhs
->dwo_unit
!= NULL
2858 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2861 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2864 /* Hash function for a quick_file_names. */
2867 hash_file_name_entry (const void *e
)
2869 const struct quick_file_names
*file_data
2870 = (const struct quick_file_names
*) e
;
2872 return hash_stmt_list_entry (&file_data
->hash
);
2875 /* Equality function for a quick_file_names. */
2878 eq_file_name_entry (const void *a
, const void *b
)
2880 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2881 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2883 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2886 /* Delete function for a quick_file_names. */
2889 delete_file_name_entry (void *e
)
2891 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2894 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2896 xfree ((void*) file_data
->file_names
[i
]);
2897 if (file_data
->real_names
)
2898 xfree ((void*) file_data
->real_names
[i
]);
2901 /* The space for the struct itself lives on objfile_obstack,
2902 so we don't free it here. */
2905 /* Create a quick_file_names hash table. */
2908 create_quick_file_names_table (unsigned int nr_initial_entries
)
2910 return htab_create_alloc (nr_initial_entries
,
2911 hash_file_name_entry
, eq_file_name_entry
,
2912 delete_file_name_entry
, xcalloc
, xfree
);
2915 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2916 have to be created afterwards. You should call age_cached_comp_units after
2917 processing PER_CU->CU. dw2_setup must have been already called. */
2920 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2922 if (per_cu
->is_debug_types
)
2923 load_full_type_unit (per_cu
);
2925 load_full_comp_unit (per_cu
, language_minimal
);
2927 if (per_cu
->cu
== NULL
)
2928 return; /* Dummy CU. */
2930 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2933 /* Read in the symbols for PER_CU. */
2936 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2938 struct cleanup
*back_to
;
2940 /* Skip type_unit_groups, reading the type units they contain
2941 is handled elsewhere. */
2942 if (IS_TYPE_UNIT_GROUP (per_cu
))
2945 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2947 if (dwarf2_per_objfile
->using_index
2948 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2949 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2951 queue_comp_unit (per_cu
, language_minimal
);
2954 /* If we just loaded a CU from a DWO, and we're working with an index
2955 that may badly handle TUs, load all the TUs in that DWO as well.
2956 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2957 if (!per_cu
->is_debug_types
2958 && per_cu
->cu
!= NULL
2959 && per_cu
->cu
->dwo_unit
!= NULL
2960 && dwarf2_per_objfile
->index_table
!= NULL
2961 && dwarf2_per_objfile
->index_table
->version
<= 7
2962 /* DWP files aren't supported yet. */
2963 && get_dwp_file () == NULL
)
2964 queue_and_load_all_dwo_tus (per_cu
);
2969 /* Age the cache, releasing compilation units that have not
2970 been used recently. */
2971 age_cached_comp_units ();
2973 do_cleanups (back_to
);
2976 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2977 the objfile from which this CU came. Returns the resulting symbol
2980 static struct compunit_symtab
*
2981 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2983 gdb_assert (dwarf2_per_objfile
->using_index
);
2984 if (!per_cu
->v
.quick
->compunit_symtab
)
2986 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2987 scoped_restore decrementer
= increment_reading_symtab ();
2988 dw2_do_instantiate_symtab (per_cu
);
2989 process_cu_includes ();
2990 do_cleanups (back_to
);
2993 return per_cu
->v
.quick
->compunit_symtab
;
2996 /* Return the CU/TU given its index.
2998 This is intended for loops like:
3000 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3001 + dwarf2_per_objfile->n_type_units); ++i)
3003 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
3009 static struct dwarf2_per_cu_data
*
3010 dw2_get_cutu (int index
)
3012 if (index
>= dwarf2_per_objfile
->n_comp_units
)
3014 index
-= dwarf2_per_objfile
->n_comp_units
;
3015 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
3016 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
3019 return dwarf2_per_objfile
->all_comp_units
[index
];
3022 /* Return the CU given its index.
3023 This differs from dw2_get_cutu in that it's for when you know INDEX
3026 static struct dwarf2_per_cu_data
*
3027 dw2_get_cu (int index
)
3029 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
3031 return dwarf2_per_objfile
->all_comp_units
[index
];
3034 /* A helper for create_cus_from_index that handles a given list of
3038 create_cus_from_index_list (struct objfile
*objfile
,
3039 const gdb_byte
*cu_list
, offset_type n_elements
,
3040 struct dwarf2_section_info
*section
,
3046 for (i
= 0; i
< n_elements
; i
+= 2)
3048 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3050 sect_offset sect_off
3051 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3052 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3055 dwarf2_per_cu_data
*the_cu
3056 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3057 struct dwarf2_per_cu_data
);
3058 the_cu
->sect_off
= sect_off
;
3059 the_cu
->length
= length
;
3060 the_cu
->objfile
= objfile
;
3061 the_cu
->section
= section
;
3062 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3063 struct dwarf2_per_cu_quick_data
);
3064 the_cu
->is_dwz
= is_dwz
;
3065 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
3069 /* Read the CU list from the mapped index, and use it to create all
3070 the CU objects for this objfile. */
3073 create_cus_from_index (struct objfile
*objfile
,
3074 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3075 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3077 struct dwz_file
*dwz
;
3079 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
3080 dwarf2_per_objfile
->all_comp_units
=
3081 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
3082 dwarf2_per_objfile
->n_comp_units
);
3084 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
3085 &dwarf2_per_objfile
->info
, 0, 0);
3087 if (dwz_elements
== 0)
3090 dwz
= dwarf2_get_dwz_file ();
3091 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
3092 cu_list_elements
/ 2);
3095 /* Create the signatured type hash table from the index. */
3098 create_signatured_type_table_from_index (struct objfile
*objfile
,
3099 struct dwarf2_section_info
*section
,
3100 const gdb_byte
*bytes
,
3101 offset_type elements
)
3104 htab_t sig_types_hash
;
3106 dwarf2_per_objfile
->n_type_units
3107 = dwarf2_per_objfile
->n_allocated_type_units
3109 dwarf2_per_objfile
->all_type_units
=
3110 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3112 sig_types_hash
= allocate_signatured_type_table (objfile
);
3114 for (i
= 0; i
< elements
; i
+= 3)
3116 struct signatured_type
*sig_type
;
3119 cu_offset type_offset_in_tu
;
3121 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3122 sect_offset sect_off
3123 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3125 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3127 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3130 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3131 struct signatured_type
);
3132 sig_type
->signature
= signature
;
3133 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3134 sig_type
->per_cu
.is_debug_types
= 1;
3135 sig_type
->per_cu
.section
= section
;
3136 sig_type
->per_cu
.sect_off
= sect_off
;
3137 sig_type
->per_cu
.objfile
= objfile
;
3138 sig_type
->per_cu
.v
.quick
3139 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3140 struct dwarf2_per_cu_quick_data
);
3142 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3145 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
3148 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3151 /* Read the address map data from the mapped index, and use it to
3152 populate the objfile's psymtabs_addrmap. */
3155 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
3157 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3158 const gdb_byte
*iter
, *end
;
3159 struct addrmap
*mutable_map
;
3162 auto_obstack temp_obstack
;
3164 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3166 iter
= index
->address_table
;
3167 end
= iter
+ index
->address_table_size
;
3169 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3173 ULONGEST hi
, lo
, cu_index
;
3174 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3176 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3178 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3183 complaint (&symfile_complaints
,
3184 _(".gdb_index address table has invalid range (%s - %s)"),
3185 hex_string (lo
), hex_string (hi
));
3189 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
3191 complaint (&symfile_complaints
,
3192 _(".gdb_index address table has invalid CU number %u"),
3193 (unsigned) cu_index
);
3197 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3198 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3199 addrmap_set_empty (mutable_map
, lo
, hi
- 1, dw2_get_cutu (cu_index
));
3202 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3203 &objfile
->objfile_obstack
);
3206 /* The hash function for strings in the mapped index. This is the same as
3207 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
3208 implementation. This is necessary because the hash function is tied to the
3209 format of the mapped index file. The hash values do not have to match with
3212 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
3215 mapped_index_string_hash (int index_version
, const void *p
)
3217 const unsigned char *str
= (const unsigned char *) p
;
3221 while ((c
= *str
++) != 0)
3223 if (index_version
>= 5)
3225 r
= r
* 67 + c
- 113;
3231 /* Find a slot in the mapped index INDEX for the object named NAME.
3232 If NAME is found, set *VEC_OUT to point to the CU vector in the
3233 constant pool and return true. If NAME cannot be found, return
3237 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3238 offset_type
**vec_out
)
3241 offset_type slot
, step
;
3242 int (*cmp
) (const char *, const char *);
3244 gdb::unique_xmalloc_ptr
<char> without_params
;
3245 if (current_language
->la_language
== language_cplus
3246 || current_language
->la_language
== language_fortran
3247 || current_language
->la_language
== language_d
)
3249 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3252 if (strchr (name
, '(') != NULL
)
3254 without_params
= cp_remove_params (name
);
3256 if (without_params
!= NULL
)
3257 name
= without_params
.get ();
3261 /* Index version 4 did not support case insensitive searches. But the
3262 indices for case insensitive languages are built in lowercase, therefore
3263 simulate our NAME being searched is also lowercased. */
3264 hash
= mapped_index_string_hash ((index
->version
== 4
3265 && case_sensitivity
== case_sensitive_off
3266 ? 5 : index
->version
),
3269 slot
= hash
& (index
->symbol_table_slots
- 1);
3270 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
3271 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3275 /* Convert a slot number to an offset into the table. */
3276 offset_type i
= 2 * slot
;
3278 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
3281 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
3282 if (!cmp (name
, str
))
3284 *vec_out
= (offset_type
*) (index
->constant_pool
3285 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
3289 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
3293 /* A helper function that reads the .gdb_index from SECTION and fills
3294 in MAP. FILENAME is the name of the file containing the section;
3295 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3296 ok to use deprecated sections.
3298 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3299 out parameters that are filled in with information about the CU and
3300 TU lists in the section.
3302 Returns 1 if all went well, 0 otherwise. */
3305 read_index_from_section (struct objfile
*objfile
,
3306 const char *filename
,
3308 struct dwarf2_section_info
*section
,
3309 struct mapped_index
*map
,
3310 const gdb_byte
**cu_list
,
3311 offset_type
*cu_list_elements
,
3312 const gdb_byte
**types_list
,
3313 offset_type
*types_list_elements
)
3315 const gdb_byte
*addr
;
3316 offset_type version
;
3317 offset_type
*metadata
;
3320 if (dwarf2_section_empty_p (section
))
3323 /* Older elfutils strip versions could keep the section in the main
3324 executable while splitting it for the separate debug info file. */
3325 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3328 dwarf2_read_section (objfile
, section
);
3330 addr
= section
->buffer
;
3331 /* Version check. */
3332 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3333 /* Versions earlier than 3 emitted every copy of a psymbol. This
3334 causes the index to behave very poorly for certain requests. Version 3
3335 contained incomplete addrmap. So, it seems better to just ignore such
3339 static int warning_printed
= 0;
3340 if (!warning_printed
)
3342 warning (_("Skipping obsolete .gdb_index section in %s."),
3344 warning_printed
= 1;
3348 /* Index version 4 uses a different hash function than index version
3351 Versions earlier than 6 did not emit psymbols for inlined
3352 functions. Using these files will cause GDB not to be able to
3353 set breakpoints on inlined functions by name, so we ignore these
3354 indices unless the user has done
3355 "set use-deprecated-index-sections on". */
3356 if (version
< 6 && !deprecated_ok
)
3358 static int warning_printed
= 0;
3359 if (!warning_printed
)
3362 Skipping deprecated .gdb_index section in %s.\n\
3363 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3364 to use the section anyway."),
3366 warning_printed
= 1;
3370 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3371 of the TU (for symbols coming from TUs),
3372 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3373 Plus gold-generated indices can have duplicate entries for global symbols,
3374 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3375 These are just performance bugs, and we can't distinguish gdb-generated
3376 indices from gold-generated ones, so issue no warning here. */
3378 /* Indexes with higher version than the one supported by GDB may be no
3379 longer backward compatible. */
3383 map
->version
= version
;
3384 map
->total_size
= section
->size
;
3386 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3389 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3390 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3394 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3395 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3396 - MAYBE_SWAP (metadata
[i
]))
3400 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3401 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
3402 - MAYBE_SWAP (metadata
[i
]));
3405 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
3406 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
3407 - MAYBE_SWAP (metadata
[i
]))
3408 / (2 * sizeof (offset_type
)));
3411 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3417 /* Read the index file. If everything went ok, initialize the "quick"
3418 elements of all the CUs and return 1. Otherwise, return 0. */
3421 dwarf2_read_index (struct objfile
*objfile
)
3423 struct mapped_index local_map
, *map
;
3424 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3425 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3426 struct dwz_file
*dwz
;
3428 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3429 use_deprecated_index_sections
,
3430 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3431 &cu_list
, &cu_list_elements
,
3432 &types_list
, &types_list_elements
))
3435 /* Don't use the index if it's empty. */
3436 if (local_map
.symbol_table_slots
== 0)
3439 /* If there is a .dwz file, read it so we can get its CU list as
3441 dwz
= dwarf2_get_dwz_file ();
3444 struct mapped_index dwz_map
;
3445 const gdb_byte
*dwz_types_ignore
;
3446 offset_type dwz_types_elements_ignore
;
3448 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3450 &dwz
->gdb_index
, &dwz_map
,
3451 &dwz_list
, &dwz_list_elements
,
3453 &dwz_types_elements_ignore
))
3455 warning (_("could not read '.gdb_index' section from %s; skipping"),
3456 bfd_get_filename (dwz
->dwz_bfd
));
3461 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3464 if (types_list_elements
)
3466 struct dwarf2_section_info
*section
;
3468 /* We can only handle a single .debug_types when we have an
3470 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3473 section
= VEC_index (dwarf2_section_info_def
,
3474 dwarf2_per_objfile
->types
, 0);
3476 create_signatured_type_table_from_index (objfile
, section
, types_list
,
3477 types_list_elements
);
3480 create_addrmap_from_index (objfile
, &local_map
);
3482 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3483 map
= new (map
) mapped_index ();
3486 dwarf2_per_objfile
->index_table
= map
;
3487 dwarf2_per_objfile
->using_index
= 1;
3488 dwarf2_per_objfile
->quick_file_names_table
=
3489 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3494 /* A helper for the "quick" functions which sets the global
3495 dwarf2_per_objfile according to OBJFILE. */
3498 dw2_setup (struct objfile
*objfile
)
3500 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
3501 objfile_data (objfile
, dwarf2_objfile_data_key
));
3502 gdb_assert (dwarf2_per_objfile
);
3505 /* die_reader_func for dw2_get_file_names. */
3508 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3509 const gdb_byte
*info_ptr
,
3510 struct die_info
*comp_unit_die
,
3514 struct dwarf2_cu
*cu
= reader
->cu
;
3515 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3516 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3517 struct dwarf2_per_cu_data
*lh_cu
;
3518 struct attribute
*attr
;
3521 struct quick_file_names
*qfn
;
3523 gdb_assert (! this_cu
->is_debug_types
);
3525 /* Our callers never want to match partial units -- instead they
3526 will match the enclosing full CU. */
3527 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3529 this_cu
->v
.quick
->no_file_data
= 1;
3537 sect_offset line_offset
{};
3539 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3542 struct quick_file_names find_entry
;
3544 line_offset
= (sect_offset
) DW_UNSND (attr
);
3546 /* We may have already read in this line header (TU line header sharing).
3547 If we have we're done. */
3548 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3549 find_entry
.hash
.line_sect_off
= line_offset
;
3550 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3551 &find_entry
, INSERT
);
3554 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3558 lh
= dwarf_decode_line_header (line_offset
, cu
);
3562 lh_cu
->v
.quick
->no_file_data
= 1;
3566 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3567 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3568 qfn
->hash
.line_sect_off
= line_offset
;
3569 gdb_assert (slot
!= NULL
);
3572 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3574 qfn
->num_file_names
= lh
->file_names
.size ();
3576 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
3577 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3578 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3579 qfn
->real_names
= NULL
;
3581 lh_cu
->v
.quick
->file_names
= qfn
;
3584 /* A helper for the "quick" functions which attempts to read the line
3585 table for THIS_CU. */
3587 static struct quick_file_names
*
3588 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3590 /* This should never be called for TUs. */
3591 gdb_assert (! this_cu
->is_debug_types
);
3592 /* Nor type unit groups. */
3593 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3595 if (this_cu
->v
.quick
->file_names
!= NULL
)
3596 return this_cu
->v
.quick
->file_names
;
3597 /* If we know there is no line data, no point in looking again. */
3598 if (this_cu
->v
.quick
->no_file_data
)
3601 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3603 if (this_cu
->v
.quick
->no_file_data
)
3605 return this_cu
->v
.quick
->file_names
;
3608 /* A helper for the "quick" functions which computes and caches the
3609 real path for a given file name from the line table. */
3612 dw2_get_real_path (struct objfile
*objfile
,
3613 struct quick_file_names
*qfn
, int index
)
3615 if (qfn
->real_names
== NULL
)
3616 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3617 qfn
->num_file_names
, const char *);
3619 if (qfn
->real_names
[index
] == NULL
)
3620 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3622 return qfn
->real_names
[index
];
3625 static struct symtab
*
3626 dw2_find_last_source_symtab (struct objfile
*objfile
)
3628 struct compunit_symtab
*cust
;
3631 dw2_setup (objfile
);
3632 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3633 cust
= dw2_instantiate_symtab (dw2_get_cutu (index
));
3636 return compunit_primary_filetab (cust
);
3639 /* Traversal function for dw2_forget_cached_source_info. */
3642 dw2_free_cached_file_names (void **slot
, void *info
)
3644 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3646 if (file_data
->real_names
)
3650 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3652 xfree ((void*) file_data
->real_names
[i
]);
3653 file_data
->real_names
[i
] = NULL
;
3661 dw2_forget_cached_source_info (struct objfile
*objfile
)
3663 dw2_setup (objfile
);
3665 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3666 dw2_free_cached_file_names
, NULL
);
3669 /* Helper function for dw2_map_symtabs_matching_filename that expands
3670 the symtabs and calls the iterator. */
3673 dw2_map_expand_apply (struct objfile
*objfile
,
3674 struct dwarf2_per_cu_data
*per_cu
,
3675 const char *name
, const char *real_path
,
3676 gdb::function_view
<bool (symtab
*)> callback
)
3678 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3680 /* Don't visit already-expanded CUs. */
3681 if (per_cu
->v
.quick
->compunit_symtab
)
3684 /* This may expand more than one symtab, and we want to iterate over
3686 dw2_instantiate_symtab (per_cu
);
3688 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3689 last_made
, callback
);
3692 /* Implementation of the map_symtabs_matching_filename method. */
3695 dw2_map_symtabs_matching_filename
3696 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3697 gdb::function_view
<bool (symtab
*)> callback
)
3700 const char *name_basename
= lbasename (name
);
3702 dw2_setup (objfile
);
3704 /* The rule is CUs specify all the files, including those used by
3705 any TU, so there's no need to scan TUs here. */
3707 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3710 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3711 struct quick_file_names
*file_data
;
3713 /* We only need to look at symtabs not already expanded. */
3714 if (per_cu
->v
.quick
->compunit_symtab
)
3717 file_data
= dw2_get_file_names (per_cu
);
3718 if (file_data
== NULL
)
3721 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3723 const char *this_name
= file_data
->file_names
[j
];
3724 const char *this_real_name
;
3726 if (compare_filenames_for_search (this_name
, name
))
3728 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3734 /* Before we invoke realpath, which can get expensive when many
3735 files are involved, do a quick comparison of the basenames. */
3736 if (! basenames_may_differ
3737 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3740 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3741 if (compare_filenames_for_search (this_real_name
, name
))
3743 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3749 if (real_path
!= NULL
)
3751 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3752 gdb_assert (IS_ABSOLUTE_PATH (name
));
3753 if (this_real_name
!= NULL
3754 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3756 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3768 /* Struct used to manage iterating over all CUs looking for a symbol. */
3770 struct dw2_symtab_iterator
3772 /* The internalized form of .gdb_index. */
3773 struct mapped_index
*index
;
3774 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3775 int want_specific_block
;
3776 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3777 Unused if !WANT_SPECIFIC_BLOCK. */
3779 /* The kind of symbol we're looking for. */
3781 /* The list of CUs from the index entry of the symbol,
3782 or NULL if not found. */
3784 /* The next element in VEC to look at. */
3786 /* The number of elements in VEC, or zero if there is no match. */
3788 /* Have we seen a global version of the symbol?
3789 If so we can ignore all further global instances.
3790 This is to work around gold/15646, inefficient gold-generated
3795 /* Initialize the index symtab iterator ITER.
3796 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3797 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3800 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3801 struct mapped_index
*index
,
3802 int want_specific_block
,
3807 iter
->index
= index
;
3808 iter
->want_specific_block
= want_specific_block
;
3809 iter
->block_index
= block_index
;
3810 iter
->domain
= domain
;
3812 iter
->global_seen
= 0;
3814 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3815 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3823 /* Return the next matching CU or NULL if there are no more. */
3825 static struct dwarf2_per_cu_data
*
3826 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3828 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3830 offset_type cu_index_and_attrs
=
3831 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3832 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3833 struct dwarf2_per_cu_data
*per_cu
;
3834 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3835 /* This value is only valid for index versions >= 7. */
3836 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3837 gdb_index_symbol_kind symbol_kind
=
3838 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3839 /* Only check the symbol attributes if they're present.
3840 Indices prior to version 7 don't record them,
3841 and indices >= 7 may elide them for certain symbols
3842 (gold does this). */
3844 (iter
->index
->version
>= 7
3845 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3847 /* Don't crash on bad data. */
3848 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3849 + dwarf2_per_objfile
->n_type_units
))
3851 complaint (&symfile_complaints
,
3852 _(".gdb_index entry has bad CU index"
3854 objfile_name (dwarf2_per_objfile
->objfile
));
3858 per_cu
= dw2_get_cutu (cu_index
);
3860 /* Skip if already read in. */
3861 if (per_cu
->v
.quick
->compunit_symtab
)
3864 /* Check static vs global. */
3867 if (iter
->want_specific_block
3868 && want_static
!= is_static
)
3870 /* Work around gold/15646. */
3871 if (!is_static
&& iter
->global_seen
)
3874 iter
->global_seen
= 1;
3877 /* Only check the symbol's kind if it has one. */
3880 switch (iter
->domain
)
3883 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3884 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3885 /* Some types are also in VAR_DOMAIN. */
3886 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3890 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3894 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3909 static struct compunit_symtab
*
3910 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3911 const char *name
, domain_enum domain
)
3913 struct compunit_symtab
*stab_best
= NULL
;
3914 struct mapped_index
*index
;
3916 dw2_setup (objfile
);
3918 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3920 index
= dwarf2_per_objfile
->index_table
;
3922 /* index is NULL if OBJF_READNOW. */
3925 struct dw2_symtab_iterator iter
;
3926 struct dwarf2_per_cu_data
*per_cu
;
3928 dw2_symtab_iter_init (&iter
, index
, 1, block_index
, domain
, name
);
3930 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3932 struct symbol
*sym
, *with_opaque
= NULL
;
3933 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
3934 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3935 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3937 sym
= block_find_symbol (block
, name
, domain
,
3938 block_find_non_opaque_type_preferred
,
3941 /* Some caution must be observed with overloaded functions
3942 and methods, since the index will not contain any overload
3943 information (but NAME might contain it). */
3946 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3948 if (with_opaque
!= NULL
3949 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3952 /* Keep looking through other CUs. */
3960 dw2_print_stats (struct objfile
*objfile
)
3962 int i
, total
, count
;
3964 dw2_setup (objfile
);
3965 total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
3967 for (i
= 0; i
< total
; ++i
)
3969 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3971 if (!per_cu
->v
.quick
->compunit_symtab
)
3974 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3975 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3978 /* This dumps minimal information about the index.
3979 It is called via "mt print objfiles".
3980 One use is to verify .gdb_index has been loaded by the
3981 gdb.dwarf2/gdb-index.exp testcase. */
3984 dw2_dump (struct objfile
*objfile
)
3986 dw2_setup (objfile
);
3987 gdb_assert (dwarf2_per_objfile
->using_index
);
3988 printf_filtered (".gdb_index:");
3989 if (dwarf2_per_objfile
->index_table
!= NULL
)
3991 printf_filtered (" version %d\n",
3992 dwarf2_per_objfile
->index_table
->version
);
3995 printf_filtered (" faked for \"readnow\"\n");
3996 printf_filtered ("\n");
4000 dw2_relocate (struct objfile
*objfile
,
4001 const struct section_offsets
*new_offsets
,
4002 const struct section_offsets
*delta
)
4004 /* There's nothing to relocate here. */
4008 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4009 const char *func_name
)
4011 struct mapped_index
*index
;
4013 dw2_setup (objfile
);
4015 index
= dwarf2_per_objfile
->index_table
;
4017 /* index is NULL if OBJF_READNOW. */
4020 struct dw2_symtab_iterator iter
;
4021 struct dwarf2_per_cu_data
*per_cu
;
4023 /* Note: It doesn't matter what we pass for block_index here. */
4024 dw2_symtab_iter_init (&iter
, index
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
4027 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4028 dw2_instantiate_symtab (per_cu
);
4033 dw2_expand_all_symtabs (struct objfile
*objfile
)
4037 dw2_setup (objfile
);
4039 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
4040 + dwarf2_per_objfile
->n_type_units
); ++i
)
4042 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4044 dw2_instantiate_symtab (per_cu
);
4049 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4050 const char *fullname
)
4054 dw2_setup (objfile
);
4056 /* We don't need to consider type units here.
4057 This is only called for examining code, e.g. expand_line_sal.
4058 There can be an order of magnitude (or more) more type units
4059 than comp units, and we avoid them if we can. */
4061 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4064 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4065 struct quick_file_names
*file_data
;
4067 /* We only need to look at symtabs not already expanded. */
4068 if (per_cu
->v
.quick
->compunit_symtab
)
4071 file_data
= dw2_get_file_names (per_cu
);
4072 if (file_data
== NULL
)
4075 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4077 const char *this_fullname
= file_data
->file_names
[j
];
4079 if (filename_cmp (this_fullname
, fullname
) == 0)
4081 dw2_instantiate_symtab (per_cu
);
4089 dw2_map_matching_symbols (struct objfile
*objfile
,
4090 const char * name
, domain_enum domain
,
4092 int (*callback
) (struct block
*,
4093 struct symbol
*, void *),
4094 void *data
, symbol_name_match_type match
,
4095 symbol_compare_ftype
*ordered_compare
)
4097 /* Currently unimplemented; used for Ada. The function can be called if the
4098 current language is Ada for a non-Ada objfile using GNU index. As Ada
4099 does not look for non-Ada symbols this function should just return. */
4102 /* Symbol name matcher for .gdb_index names.
4104 Symbol names in .gdb_index have a few particularities:
4106 - There's no indication of which is the language of each symbol.
4108 Since each language has its own symbol name matching algorithm,
4109 and we don't know which language is the right one, we must match
4110 each symbol against all languages. This would be a potential
4111 performance problem if it were not mitigated by the
4112 mapped_index::name_components lookup table, which significantly
4113 reduces the number of times we need to call into this matcher,
4114 making it a non-issue.
4116 - Symbol names in the index have no overload (parameter)
4117 information. I.e., in C++, "foo(int)" and "foo(long)" both
4118 appear as "foo" in the index, for example.
4120 This means that the lookup names passed to the symbol name
4121 matcher functions must have no parameter information either
4122 because (e.g.) symbol search name "foo" does not match
4123 lookup-name "foo(int)" [while swapping search name for lookup
4126 class gdb_index_symbol_name_matcher
4129 /* Prepares the vector of comparison functions for LOOKUP_NAME. */
4130 gdb_index_symbol_name_matcher (const lookup_name_info
&lookup_name
);
4132 /* Walk all the matcher routines and match SYMBOL_NAME against them.
4133 Returns true if any matcher matches. */
4134 bool matches (const char *symbol_name
);
4137 /* A reference to the lookup name we're matching against. */
4138 const lookup_name_info
&m_lookup_name
;
4140 /* A vector holding all the different symbol name matchers, for all
4142 std::vector
<symbol_name_matcher_ftype
*> m_symbol_name_matcher_funcs
;
4145 gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
4146 (const lookup_name_info
&lookup_name
)
4147 : m_lookup_name (lookup_name
)
4149 /* Prepare the vector of comparison functions upfront, to avoid
4150 doing the same work for each symbol. Care is taken to avoid
4151 matching with the same matcher more than once if/when multiple
4152 languages use the same matcher function. */
4153 auto &matchers
= m_symbol_name_matcher_funcs
;
4154 matchers
.reserve (nr_languages
);
4156 matchers
.push_back (default_symbol_name_matcher
);
4158 for (int i
= 0; i
< nr_languages
; i
++)
4160 const language_defn
*lang
= language_def ((enum language
) i
);
4161 if (lang
->la_get_symbol_name_matcher
!= NULL
)
4163 symbol_name_matcher_ftype
*name_matcher
4164 = lang
->la_get_symbol_name_matcher (m_lookup_name
);
4166 /* Don't insert the same comparison routine more than once.
4167 Note that we do this linear walk instead of a cheaper
4168 sorted insert, or use a std::set or something like that,
4169 because relative order of function addresses is not
4170 stable. This is not a problem in practice because the
4171 number of supported languages is low, and the cost here
4172 is tiny compared to the number of searches we'll do
4173 afterwards using this object. */
4174 if (std::find (matchers
.begin (), matchers
.end (), name_matcher
)
4176 matchers
.push_back (name_matcher
);
4182 gdb_index_symbol_name_matcher::matches (const char *symbol_name
)
4184 for (auto matches_name
: m_symbol_name_matcher_funcs
)
4185 if (matches_name (symbol_name
, m_lookup_name
, NULL
))
4192 dw2_expand_marked_cus
4193 (mapped_index
&index
, offset_type idx
,
4194 struct objfile
*objfile
,
4195 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4196 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4197 search_domain kind
);
4200 dw2_expand_symtabs_matching_symbol
4201 (mapped_index
&index
,
4202 const lookup_name_info
&lookup_name_in
,
4203 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4204 enum search_domain kind
,
4205 gdb::function_view
<void (offset_type
)> on_match
);
4208 dw2_expand_symtabs_matching
4209 (struct objfile
*objfile
,
4210 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4211 const lookup_name_info
&lookup_name
,
4212 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4213 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4214 enum search_domain kind
)
4219 dw2_setup (objfile
);
4221 /* index_table is NULL if OBJF_READNOW. */
4222 if (!dwarf2_per_objfile
->index_table
)
4225 if (file_matcher
!= NULL
)
4227 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4229 NULL
, xcalloc
, xfree
));
4230 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4232 NULL
, xcalloc
, xfree
));
4234 /* The rule is CUs specify all the files, including those used by
4235 any TU, so there's no need to scan TUs here. */
4237 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4240 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4241 struct quick_file_names
*file_data
;
4246 per_cu
->v
.quick
->mark
= 0;
4248 /* We only need to look at symtabs not already expanded. */
4249 if (per_cu
->v
.quick
->compunit_symtab
)
4252 file_data
= dw2_get_file_names (per_cu
);
4253 if (file_data
== NULL
)
4256 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4258 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4260 per_cu
->v
.quick
->mark
= 1;
4264 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4266 const char *this_real_name
;
4268 if (file_matcher (file_data
->file_names
[j
], false))
4270 per_cu
->v
.quick
->mark
= 1;
4274 /* Before we invoke realpath, which can get expensive when many
4275 files are involved, do a quick comparison of the basenames. */
4276 if (!basenames_may_differ
4277 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4281 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4282 if (file_matcher (this_real_name
, false))
4284 per_cu
->v
.quick
->mark
= 1;
4289 slot
= htab_find_slot (per_cu
->v
.quick
->mark
4290 ? visited_found
.get ()
4291 : visited_not_found
.get (),
4297 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4299 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4301 kind
, [&] (offset_type idx
)
4303 dw2_expand_marked_cus (index
, idx
, objfile
, file_matcher
,
4304 expansion_notify
, kind
);
4308 /* Helper for dw2_expand_symtabs_matching that works with a
4309 mapped_index instead of the containing objfile. This is split to a
4310 separate function in order to be able to unit test the
4311 name_components matching using a mock mapped_index. For each
4312 symbol name that matches, calls MATCH_CALLBACK, passing it the
4313 symbol's index in the mapped_index symbol table. */
4316 dw2_expand_symtabs_matching_symbol
4317 (mapped_index
&index
,
4318 const lookup_name_info
&lookup_name
,
4319 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4320 enum search_domain kind
,
4321 gdb::function_view
<void (offset_type
)> match_callback
)
4323 gdb_index_symbol_name_matcher lookup_name_matcher
4326 auto *name_cmp
= case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
;
4328 /* Build the symbol name component sorted vector, if we haven't yet.
4329 The code below only knows how to break apart components of C++
4330 symbol names (and other languages that use '::' as
4331 namespace/module separator). If we add support for wild matching
4332 to some language that uses some other operator (E.g., Ada, Go and
4333 D use '.'), then we'll need to try splitting the symbol name
4334 according to that language too. Note that Ada does support wild
4335 matching, but doesn't currently support .gdb_index. */
4336 if (index
.name_components
.empty ())
4338 for (size_t iter
= 0; iter
< index
.symbol_table_slots
; ++iter
)
4340 offset_type idx
= 2 * iter
;
4342 if (index
.symbol_table
[idx
] == 0
4343 && index
.symbol_table
[idx
+ 1] == 0)
4346 const char *name
= index
.symbol_name_at (idx
);
4348 /* Add each name component to the name component table. */
4349 unsigned int previous_len
= 0;
4350 for (unsigned int current_len
= cp_find_first_component (name
);
4351 name
[current_len
] != '\0';
4352 current_len
+= cp_find_first_component (name
+ current_len
))
4354 gdb_assert (name
[current_len
] == ':');
4355 index
.name_components
.push_back ({previous_len
, idx
});
4356 /* Skip the '::'. */
4358 previous_len
= current_len
;
4360 index
.name_components
.push_back ({previous_len
, idx
});
4363 /* Sort name_components elements by name. */
4364 auto name_comp_compare
= [&] (const name_component
&left
,
4365 const name_component
&right
)
4367 const char *left_qualified
= index
.symbol_name_at (left
.idx
);
4368 const char *right_qualified
= index
.symbol_name_at (right
.idx
);
4370 const char *left_name
= left_qualified
+ left
.name_offset
;
4371 const char *right_name
= right_qualified
+ right
.name_offset
;
4373 return name_cmp (left_name
, right_name
) < 0;
4376 std::sort (index
.name_components
.begin (),
4377 index
.name_components
.end (),
4382 = lookup_name
.cplus ().lookup_name ().c_str ();
4384 /* Comparison function object for lower_bound that matches against a
4385 given symbol name. */
4386 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4389 const char *elem_qualified
= index
.symbol_name_at (elem
.idx
);
4390 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4391 return name_cmp (elem_name
, name
) < 0;
4394 /* Comparison function object for upper_bound that matches against a
4395 given symbol name. */
4396 auto lookup_compare_upper
= [&] (const char *name
,
4397 const name_component
&elem
)
4399 const char *elem_qualified
= index
.symbol_name_at (elem
.idx
);
4400 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4401 return name_cmp (name
, elem_name
) < 0;
4404 auto begin
= index
.name_components
.begin ();
4405 auto end
= index
.name_components
.end ();
4407 /* Find the lower bound. */
4410 if (lookup_name
.completion_mode () && cplus
[0] == '\0')
4413 return std::lower_bound (begin
, end
, cplus
, lookup_compare_lower
);
4416 /* Find the upper bound. */
4419 if (lookup_name
.completion_mode ())
4421 /* The string frobbing below won't work if the string is
4422 empty. We don't need it then, anyway -- if we're
4423 completing an empty string, then we want to iterate over
4425 if (cplus
[0] == '\0')
4428 /* In completion mode, increment the last character because
4429 we want UPPER to point past all symbols names that have
4431 std::string after
= cplus
;
4433 gdb_assert (after
.back () != 0xff);
4436 return std::upper_bound (lower
, end
, after
.c_str (),
4437 lookup_compare_upper
);
4440 return std::upper_bound (lower
, end
, cplus
, lookup_compare_upper
);
4443 /* Now for each symbol name in range, check to see if we have a name
4444 match, and if so, call the MATCH_CALLBACK callback. */
4446 /* The same symbol may appear more than once in the range though.
4447 E.g., if we're looking for symbols that complete "w", and we have
4448 a symbol named "w1::w2", we'll find the two name components for
4449 that same symbol in the range. To be sure we only call the
4450 callback once per symbol, we first collect the symbol name
4451 indexes that matched in a temporary vector and ignore
4453 std::vector
<offset_type
> matches
;
4454 matches
.reserve (std::distance (lower
, upper
));
4456 for (;lower
!= upper
; ++lower
)
4458 const char *qualified
= index
.symbol_name_at (lower
->idx
);
4460 if (!lookup_name_matcher
.matches (qualified
)
4461 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4464 matches
.push_back (lower
->idx
);
4467 std::sort (matches
.begin (), matches
.end ());
4469 /* Finally call the callback, once per match. */
4471 for (offset_type idx
: matches
)
4475 match_callback (idx
);
4480 /* Above we use a type wider than idx's for 'prev', since 0 and
4481 (offset_type)-1 are both possible values. */
4482 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4485 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4486 matched, to expand corresponding CUs that were marked. IDX is the
4487 index of the symbol name that matched. */
4490 dw2_expand_marked_cus
4491 (mapped_index
&index
, offset_type idx
,
4492 struct objfile
*objfile
,
4493 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4494 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4498 offset_type
*vec
, vec_len
, vec_idx
;
4499 bool global_seen
= false;
4501 vec
= (offset_type
*) (index
.constant_pool
4502 + MAYBE_SWAP (index
.symbol_table
[idx
+ 1]));
4503 vec_len
= MAYBE_SWAP (vec
[0]);
4504 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4506 struct dwarf2_per_cu_data
*per_cu
;
4507 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4508 /* This value is only valid for index versions >= 7. */
4509 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4510 gdb_index_symbol_kind symbol_kind
=
4511 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4512 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4513 /* Only check the symbol attributes if they're present.
4514 Indices prior to version 7 don't record them,
4515 and indices >= 7 may elide them for certain symbols
4516 (gold does this). */
4519 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4521 /* Work around gold/15646. */
4524 if (!is_static
&& global_seen
)
4530 /* Only check the symbol's kind if it has one. */
4535 case VARIABLES_DOMAIN
:
4536 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4539 case FUNCTIONS_DOMAIN
:
4540 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4544 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4552 /* Don't crash on bad data. */
4553 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
4554 + dwarf2_per_objfile
->n_type_units
))
4556 complaint (&symfile_complaints
,
4557 _(".gdb_index entry has bad CU index"
4558 " [in module %s]"), objfile_name (objfile
));
4562 per_cu
= dw2_get_cutu (cu_index
);
4563 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4565 int symtab_was_null
=
4566 (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4568 dw2_instantiate_symtab (per_cu
);
4570 if (expansion_notify
!= NULL
4572 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4574 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4580 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4583 static struct compunit_symtab
*
4584 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4589 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4590 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4593 if (cust
->includes
== NULL
)
4596 for (i
= 0; cust
->includes
[i
]; ++i
)
4598 struct compunit_symtab
*s
= cust
->includes
[i
];
4600 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4608 static struct compunit_symtab
*
4609 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4610 struct bound_minimal_symbol msymbol
,
4612 struct obj_section
*section
,
4615 struct dwarf2_per_cu_data
*data
;
4616 struct compunit_symtab
*result
;
4618 dw2_setup (objfile
);
4620 if (!objfile
->psymtabs_addrmap
)
4623 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
4628 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4629 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4630 paddress (get_objfile_arch (objfile
), pc
));
4633 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
4635 gdb_assert (result
!= NULL
);
4640 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4641 void *data
, int need_fullname
)
4643 dw2_setup (objfile
);
4645 if (!dwarf2_per_objfile
->filenames_cache
)
4647 dwarf2_per_objfile
->filenames_cache
.emplace ();
4649 htab_up
visited (htab_create_alloc (10,
4650 htab_hash_pointer
, htab_eq_pointer
,
4651 NULL
, xcalloc
, xfree
));
4653 /* The rule is CUs specify all the files, including those used
4654 by any TU, so there's no need to scan TUs here. We can
4655 ignore file names coming from already-expanded CUs. */
4657 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4659 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4661 if (per_cu
->v
.quick
->compunit_symtab
)
4663 void **slot
= htab_find_slot (visited
.get (),
4664 per_cu
->v
.quick
->file_names
,
4667 *slot
= per_cu
->v
.quick
->file_names
;
4671 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4674 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4675 struct quick_file_names
*file_data
;
4678 /* We only need to look at symtabs not already expanded. */
4679 if (per_cu
->v
.quick
->compunit_symtab
)
4682 file_data
= dw2_get_file_names (per_cu
);
4683 if (file_data
== NULL
)
4686 slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4689 /* Already visited. */
4694 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4696 const char *filename
= file_data
->file_names
[j
];
4697 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4702 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4704 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4707 this_real_name
= gdb_realpath (filename
);
4708 (*fun
) (filename
, this_real_name
.get (), data
);
4713 dw2_has_symbols (struct objfile
*objfile
)
4718 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4721 dw2_find_last_source_symtab
,
4722 dw2_forget_cached_source_info
,
4723 dw2_map_symtabs_matching_filename
,
4728 dw2_expand_symtabs_for_function
,
4729 dw2_expand_all_symtabs
,
4730 dw2_expand_symtabs_with_fullname
,
4731 dw2_map_matching_symbols
,
4732 dw2_expand_symtabs_matching
,
4733 dw2_find_pc_sect_compunit_symtab
,
4734 dw2_map_symbol_filenames
4737 /* Initialize for reading DWARF for this objfile. Return 0 if this
4738 file will use psymtabs, or 1 if using the GNU index. */
4741 dwarf2_initialize_objfile (struct objfile
*objfile
)
4743 /* If we're about to read full symbols, don't bother with the
4744 indices. In this case we also don't care if some other debug
4745 format is making psymtabs, because they are all about to be
4747 if ((objfile
->flags
& OBJF_READNOW
))
4751 dwarf2_per_objfile
->using_index
= 1;
4752 create_all_comp_units (objfile
);
4753 create_all_type_units (objfile
);
4754 dwarf2_per_objfile
->quick_file_names_table
=
4755 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
4757 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
4758 + dwarf2_per_objfile
->n_type_units
); ++i
)
4760 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4762 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4763 struct dwarf2_per_cu_quick_data
);
4766 /* Return 1 so that gdb sees the "quick" functions. However,
4767 these functions will be no-ops because we will have expanded
4772 if (dwarf2_read_index (objfile
))
4780 /* Build a partial symbol table. */
4783 dwarf2_build_psymtabs (struct objfile
*objfile
)
4786 if (objfile
->global_psymbols
.capacity () == 0
4787 && objfile
->static_psymbols
.capacity () == 0)
4788 init_psymbol_list (objfile
, 1024);
4792 /* This isn't really ideal: all the data we allocate on the
4793 objfile's obstack is still uselessly kept around. However,
4794 freeing it seems unsafe. */
4795 psymtab_discarder
psymtabs (objfile
);
4796 dwarf2_build_psymtabs_hard (objfile
);
4799 CATCH (except
, RETURN_MASK_ERROR
)
4801 exception_print (gdb_stderr
, except
);
4806 /* Return the total length of the CU described by HEADER. */
4809 get_cu_length (const struct comp_unit_head
*header
)
4811 return header
->initial_length_size
+ header
->length
;
4814 /* Return TRUE if SECT_OFF is within CU_HEADER. */
4817 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
4819 sect_offset bottom
= cu_header
->sect_off
;
4820 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
4822 return sect_off
>= bottom
&& sect_off
< top
;
4825 /* Find the base address of the compilation unit for range lists and
4826 location lists. It will normally be specified by DW_AT_low_pc.
4827 In DWARF-3 draft 4, the base address could be overridden by
4828 DW_AT_entry_pc. It's been removed, but GCC still uses this for
4829 compilation units with discontinuous ranges. */
4832 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
4834 struct attribute
*attr
;
4837 cu
->base_address
= 0;
4839 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
4842 cu
->base_address
= attr_value_as_address (attr
);
4847 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4850 cu
->base_address
= attr_value_as_address (attr
);
4856 /* Read in the comp unit header information from the debug_info at info_ptr.
4857 Use rcuh_kind::COMPILE as the default type if not known by the caller.
4858 NOTE: This leaves members offset, first_die_offset to be filled in
4861 static const gdb_byte
*
4862 read_comp_unit_head (struct comp_unit_head
*cu_header
,
4863 const gdb_byte
*info_ptr
,
4864 struct dwarf2_section_info
*section
,
4865 rcuh_kind section_kind
)
4868 unsigned int bytes_read
;
4869 const char *filename
= get_section_file_name (section
);
4870 bfd
*abfd
= get_section_bfd_owner (section
);
4872 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
4873 cu_header
->initial_length_size
= bytes_read
;
4874 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
4875 info_ptr
+= bytes_read
;
4876 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
4878 if (cu_header
->version
< 5)
4879 switch (section_kind
)
4881 case rcuh_kind::COMPILE
:
4882 cu_header
->unit_type
= DW_UT_compile
;
4884 case rcuh_kind::TYPE
:
4885 cu_header
->unit_type
= DW_UT_type
;
4888 internal_error (__FILE__
, __LINE__
,
4889 _("read_comp_unit_head: invalid section_kind"));
4893 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
4894 (read_1_byte (abfd
, info_ptr
));
4896 switch (cu_header
->unit_type
)
4899 if (section_kind
!= rcuh_kind::COMPILE
)
4900 error (_("Dwarf Error: wrong unit_type in compilation unit header "
4901 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
4905 section_kind
= rcuh_kind::TYPE
;
4908 error (_("Dwarf Error: wrong unit_type in compilation unit header "
4909 "(is %d, should be %d or %d) [in module %s]"),
4910 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
4913 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
4916 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
4919 info_ptr
+= bytes_read
;
4920 if (cu_header
->version
< 5)
4922 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
4925 signed_addr
= bfd_get_sign_extend_vma (abfd
);
4926 if (signed_addr
< 0)
4927 internal_error (__FILE__
, __LINE__
,
4928 _("read_comp_unit_head: dwarf from non elf file"));
4929 cu_header
->signed_addr_p
= signed_addr
;
4931 if (section_kind
== rcuh_kind::TYPE
)
4933 LONGEST type_offset
;
4935 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
4938 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
4939 info_ptr
+= bytes_read
;
4940 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
4941 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
4942 error (_("Dwarf Error: Too big type_offset in compilation unit "
4943 "header (is %s) [in module %s]"), plongest (type_offset
),
4950 /* Helper function that returns the proper abbrev section for
4953 static struct dwarf2_section_info
*
4954 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
4956 struct dwarf2_section_info
*abbrev
;
4958 if (this_cu
->is_dwz
)
4959 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
4961 abbrev
= &dwarf2_per_objfile
->abbrev
;
4966 /* Subroutine of read_and_check_comp_unit_head and
4967 read_and_check_type_unit_head to simplify them.
4968 Perform various error checking on the header. */
4971 error_check_comp_unit_head (struct comp_unit_head
*header
,
4972 struct dwarf2_section_info
*section
,
4973 struct dwarf2_section_info
*abbrev_section
)
4975 const char *filename
= get_section_file_name (section
);
4977 if (header
->version
< 2 || header
->version
> 5)
4978 error (_("Dwarf Error: wrong version in compilation unit header "
4979 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
4982 if (to_underlying (header
->abbrev_sect_off
)
4983 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
4984 error (_("Dwarf Error: bad offset (0x%x) in compilation unit header "
4985 "(offset 0x%x + 6) [in module %s]"),
4986 to_underlying (header
->abbrev_sect_off
),
4987 to_underlying (header
->sect_off
),
4990 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
4991 avoid potential 32-bit overflow. */
4992 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
4994 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
4995 "(offset 0x%x + 0) [in module %s]"),
4996 header
->length
, to_underlying (header
->sect_off
),
5000 /* Read in a CU/TU header and perform some basic error checking.
5001 The contents of the header are stored in HEADER.
5002 The result is a pointer to the start of the first DIE. */
5004 static const gdb_byte
*
5005 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
5006 struct dwarf2_section_info
*section
,
5007 struct dwarf2_section_info
*abbrev_section
,
5008 const gdb_byte
*info_ptr
,
5009 rcuh_kind section_kind
)
5011 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
5012 bfd
*abfd
= get_section_bfd_owner (section
);
5014 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
5016 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
5018 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
5020 error_check_comp_unit_head (header
, section
, abbrev_section
);
5025 /* Fetch the abbreviation table offset from a comp or type unit header. */
5028 read_abbrev_offset (struct dwarf2_section_info
*section
,
5029 sect_offset sect_off
)
5031 bfd
*abfd
= get_section_bfd_owner (section
);
5032 const gdb_byte
*info_ptr
;
5033 unsigned int initial_length_size
, offset_size
;
5036 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
5037 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5038 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5039 offset_size
= initial_length_size
== 4 ? 4 : 8;
5040 info_ptr
+= initial_length_size
;
5042 version
= read_2_bytes (abfd
, info_ptr
);
5046 /* Skip unit type and address size. */
5050 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
5053 /* Allocate a new partial symtab for file named NAME and mark this new
5054 partial symtab as being an include of PST. */
5057 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
5058 struct objfile
*objfile
)
5060 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
5062 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5064 /* It shares objfile->objfile_obstack. */
5065 subpst
->dirname
= pst
->dirname
;
5068 subpst
->textlow
= 0;
5069 subpst
->texthigh
= 0;
5071 subpst
->dependencies
5072 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
5073 subpst
->dependencies
[0] = pst
;
5074 subpst
->number_of_dependencies
= 1;
5076 subpst
->globals_offset
= 0;
5077 subpst
->n_global_syms
= 0;
5078 subpst
->statics_offset
= 0;
5079 subpst
->n_static_syms
= 0;
5080 subpst
->compunit_symtab
= NULL
;
5081 subpst
->read_symtab
= pst
->read_symtab
;
5084 /* No private part is necessary for include psymtabs. This property
5085 can be used to differentiate between such include psymtabs and
5086 the regular ones. */
5087 subpst
->read_symtab_private
= NULL
;
5090 /* Read the Line Number Program data and extract the list of files
5091 included by the source file represented by PST. Build an include
5092 partial symtab for each of these included files. */
5095 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5096 struct die_info
*die
,
5097 struct partial_symtab
*pst
)
5100 struct attribute
*attr
;
5102 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5104 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5106 return; /* No linetable, so no includes. */
5108 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
5109 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
5113 hash_signatured_type (const void *item
)
5115 const struct signatured_type
*sig_type
5116 = (const struct signatured_type
*) item
;
5118 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5119 return sig_type
->signature
;
5123 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5125 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5126 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5128 return lhs
->signature
== rhs
->signature
;
5131 /* Allocate a hash table for signatured types. */
5134 allocate_signatured_type_table (struct objfile
*objfile
)
5136 return htab_create_alloc_ex (41,
5137 hash_signatured_type
,
5140 &objfile
->objfile_obstack
,
5141 hashtab_obstack_allocate
,
5142 dummy_obstack_deallocate
);
5145 /* A helper function to add a signatured type CU to a table. */
5148 add_signatured_type_cu_to_table (void **slot
, void *datum
)
5150 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
5151 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
5159 /* A helper for create_debug_types_hash_table. Read types from SECTION
5160 and fill them into TYPES_HTAB. It will process only type units,
5161 therefore DW_UT_type. */
5164 create_debug_type_hash_table (struct dwo_file
*dwo_file
,
5165 dwarf2_section_info
*section
, htab_t
&types_htab
,
5166 rcuh_kind section_kind
)
5168 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5169 struct dwarf2_section_info
*abbrev_section
;
5171 const gdb_byte
*info_ptr
, *end_ptr
;
5173 abbrev_section
= (dwo_file
!= NULL
5174 ? &dwo_file
->sections
.abbrev
5175 : &dwarf2_per_objfile
->abbrev
);
5177 if (dwarf_read_debug
)
5178 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
5179 get_section_name (section
),
5180 get_section_file_name (abbrev_section
));
5182 dwarf2_read_section (objfile
, section
);
5183 info_ptr
= section
->buffer
;
5185 if (info_ptr
== NULL
)
5188 /* We can't set abfd until now because the section may be empty or
5189 not present, in which case the bfd is unknown. */
5190 abfd
= get_section_bfd_owner (section
);
5192 /* We don't use init_cutu_and_read_dies_simple, or some such, here
5193 because we don't need to read any dies: the signature is in the
5196 end_ptr
= info_ptr
+ section
->size
;
5197 while (info_ptr
< end_ptr
)
5199 struct signatured_type
*sig_type
;
5200 struct dwo_unit
*dwo_tu
;
5202 const gdb_byte
*ptr
= info_ptr
;
5203 struct comp_unit_head header
;
5204 unsigned int length
;
5206 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
5208 /* Initialize it due to a false compiler warning. */
5209 header
.signature
= -1;
5210 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
5212 /* We need to read the type's signature in order to build the hash
5213 table, but we don't need anything else just yet. */
5215 ptr
= read_and_check_comp_unit_head (&header
, section
,
5216 abbrev_section
, ptr
, section_kind
);
5218 length
= get_cu_length (&header
);
5220 /* Skip dummy type units. */
5221 if (ptr
>= info_ptr
+ length
5222 || peek_abbrev_code (abfd
, ptr
) == 0
5223 || header
.unit_type
!= DW_UT_type
)
5229 if (types_htab
== NULL
)
5232 types_htab
= allocate_dwo_unit_table (objfile
);
5234 types_htab
= allocate_signatured_type_table (objfile
);
5240 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5242 dwo_tu
->dwo_file
= dwo_file
;
5243 dwo_tu
->signature
= header
.signature
;
5244 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
5245 dwo_tu
->section
= section
;
5246 dwo_tu
->sect_off
= sect_off
;
5247 dwo_tu
->length
= length
;
5251 /* N.B.: type_offset is not usable if this type uses a DWO file.
5252 The real type_offset is in the DWO file. */
5254 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5255 struct signatured_type
);
5256 sig_type
->signature
= header
.signature
;
5257 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
5258 sig_type
->per_cu
.objfile
= objfile
;
5259 sig_type
->per_cu
.is_debug_types
= 1;
5260 sig_type
->per_cu
.section
= section
;
5261 sig_type
->per_cu
.sect_off
= sect_off
;
5262 sig_type
->per_cu
.length
= length
;
5265 slot
= htab_find_slot (types_htab
,
5266 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
5268 gdb_assert (slot
!= NULL
);
5271 sect_offset dup_sect_off
;
5275 const struct dwo_unit
*dup_tu
5276 = (const struct dwo_unit
*) *slot
;
5278 dup_sect_off
= dup_tu
->sect_off
;
5282 const struct signatured_type
*dup_tu
5283 = (const struct signatured_type
*) *slot
;
5285 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
5288 complaint (&symfile_complaints
,
5289 _("debug type entry at offset 0x%x is duplicate to"
5290 " the entry at offset 0x%x, signature %s"),
5291 to_underlying (sect_off
), to_underlying (dup_sect_off
),
5292 hex_string (header
.signature
));
5294 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
5296 if (dwarf_read_debug
> 1)
5297 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature %s\n",
5298 to_underlying (sect_off
),
5299 hex_string (header
.signature
));
5305 /* Create the hash table of all entries in the .debug_types
5306 (or .debug_types.dwo) section(s).
5307 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
5308 otherwise it is NULL.
5310 The result is a pointer to the hash table or NULL if there are no types.
5312 Note: This function processes DWO files only, not DWP files. */
5315 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
5316 VEC (dwarf2_section_info_def
) *types
,
5320 struct dwarf2_section_info
*section
;
5322 if (VEC_empty (dwarf2_section_info_def
, types
))
5326 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
5328 create_debug_type_hash_table (dwo_file
, section
, types_htab
,
5332 /* Create the hash table of all entries in the .debug_types section,
5333 and initialize all_type_units.
5334 The result is zero if there is an error (e.g. missing .debug_types section),
5335 otherwise non-zero. */
5338 create_all_type_units (struct objfile
*objfile
)
5340 htab_t types_htab
= NULL
;
5341 struct signatured_type
**iter
;
5343 create_debug_type_hash_table (NULL
, &dwarf2_per_objfile
->info
, types_htab
,
5344 rcuh_kind::COMPILE
);
5345 create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
, types_htab
);
5346 if (types_htab
== NULL
)
5348 dwarf2_per_objfile
->signatured_types
= NULL
;
5352 dwarf2_per_objfile
->signatured_types
= types_htab
;
5354 dwarf2_per_objfile
->n_type_units
5355 = dwarf2_per_objfile
->n_allocated_type_units
5356 = htab_elements (types_htab
);
5357 dwarf2_per_objfile
->all_type_units
=
5358 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
5359 iter
= &dwarf2_per_objfile
->all_type_units
[0];
5360 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
5361 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
5362 == dwarf2_per_objfile
->n_type_units
);
5367 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
5368 If SLOT is non-NULL, it is the entry to use in the hash table.
5369 Otherwise we find one. */
5371 static struct signatured_type
*
5372 add_type_unit (ULONGEST sig
, void **slot
)
5374 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5375 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
5376 struct signatured_type
*sig_type
;
5378 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
5380 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
5382 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
5383 dwarf2_per_objfile
->n_allocated_type_units
= 1;
5384 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
5385 dwarf2_per_objfile
->all_type_units
5386 = XRESIZEVEC (struct signatured_type
*,
5387 dwarf2_per_objfile
->all_type_units
,
5388 dwarf2_per_objfile
->n_allocated_type_units
);
5389 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
5391 dwarf2_per_objfile
->n_type_units
= n_type_units
;
5393 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5394 struct signatured_type
);
5395 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
5396 sig_type
->signature
= sig
;
5397 sig_type
->per_cu
.is_debug_types
= 1;
5398 if (dwarf2_per_objfile
->using_index
)
5400 sig_type
->per_cu
.v
.quick
=
5401 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5402 struct dwarf2_per_cu_quick_data
);
5407 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5410 gdb_assert (*slot
== NULL
);
5412 /* The rest of sig_type must be filled in by the caller. */
5416 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
5417 Fill in SIG_ENTRY with DWO_ENTRY. */
5420 fill_in_sig_entry_from_dwo_entry (struct objfile
*objfile
,
5421 struct signatured_type
*sig_entry
,
5422 struct dwo_unit
*dwo_entry
)
5424 /* Make sure we're not clobbering something we don't expect to. */
5425 gdb_assert (! sig_entry
->per_cu
.queued
);
5426 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
5427 if (dwarf2_per_objfile
->using_index
)
5429 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
5430 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
5433 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
5434 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
5435 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
5436 gdb_assert (sig_entry
->type_unit_group
== NULL
);
5437 gdb_assert (sig_entry
->dwo_unit
== NULL
);
5439 sig_entry
->per_cu
.section
= dwo_entry
->section
;
5440 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
5441 sig_entry
->per_cu
.length
= dwo_entry
->length
;
5442 sig_entry
->per_cu
.reading_dwo_directly
= 1;
5443 sig_entry
->per_cu
.objfile
= objfile
;
5444 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
5445 sig_entry
->dwo_unit
= dwo_entry
;
5448 /* Subroutine of lookup_signatured_type.
5449 If we haven't read the TU yet, create the signatured_type data structure
5450 for a TU to be read in directly from a DWO file, bypassing the stub.
5451 This is the "Stay in DWO Optimization": When there is no DWP file and we're
5452 using .gdb_index, then when reading a CU we want to stay in the DWO file
5453 containing that CU. Otherwise we could end up reading several other DWO
5454 files (due to comdat folding) to process the transitive closure of all the
5455 mentioned TUs, and that can be slow. The current DWO file will have every
5456 type signature that it needs.
5457 We only do this for .gdb_index because in the psymtab case we already have
5458 to read all the DWOs to build the type unit groups. */
5460 static struct signatured_type
*
5461 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5463 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5464 struct dwo_file
*dwo_file
;
5465 struct dwo_unit find_dwo_entry
, *dwo_entry
;
5466 struct signatured_type find_sig_entry
, *sig_entry
;
5469 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
5471 /* If TU skeletons have been removed then we may not have read in any
5473 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5475 dwarf2_per_objfile
->signatured_types
5476 = allocate_signatured_type_table (objfile
);
5479 /* We only ever need to read in one copy of a signatured type.
5480 Use the global signatured_types array to do our own comdat-folding
5481 of types. If this is the first time we're reading this TU, and
5482 the TU has an entry in .gdb_index, replace the recorded data from
5483 .gdb_index with this TU. */
5485 find_sig_entry
.signature
= sig
;
5486 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5487 &find_sig_entry
, INSERT
);
5488 sig_entry
= (struct signatured_type
*) *slot
;
5490 /* We can get here with the TU already read, *or* in the process of being
5491 read. Don't reassign the global entry to point to this DWO if that's
5492 the case. Also note that if the TU is already being read, it may not
5493 have come from a DWO, the program may be a mix of Fission-compiled
5494 code and non-Fission-compiled code. */
5496 /* Have we already tried to read this TU?
5497 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5498 needn't exist in the global table yet). */
5499 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
5502 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
5503 dwo_unit of the TU itself. */
5504 dwo_file
= cu
->dwo_unit
->dwo_file
;
5506 /* Ok, this is the first time we're reading this TU. */
5507 if (dwo_file
->tus
== NULL
)
5509 find_dwo_entry
.signature
= sig
;
5510 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
5511 if (dwo_entry
== NULL
)
5514 /* If the global table doesn't have an entry for this TU, add one. */
5515 if (sig_entry
== NULL
)
5516 sig_entry
= add_type_unit (sig
, slot
);
5518 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
5519 sig_entry
->per_cu
.tu_read
= 1;
5523 /* Subroutine of lookup_signatured_type.
5524 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
5525 then try the DWP file. If the TU stub (skeleton) has been removed then
5526 it won't be in .gdb_index. */
5528 static struct signatured_type
*
5529 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5531 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5532 struct dwp_file
*dwp_file
= get_dwp_file ();
5533 struct dwo_unit
*dwo_entry
;
5534 struct signatured_type find_sig_entry
, *sig_entry
;
5537 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
5538 gdb_assert (dwp_file
!= NULL
);
5540 /* If TU skeletons have been removed then we may not have read in any
5542 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5544 dwarf2_per_objfile
->signatured_types
5545 = allocate_signatured_type_table (objfile
);
5548 find_sig_entry
.signature
= sig
;
5549 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5550 &find_sig_entry
, INSERT
);
5551 sig_entry
= (struct signatured_type
*) *slot
;
5553 /* Have we already tried to read this TU?
5554 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5555 needn't exist in the global table yet). */
5556 if (sig_entry
!= NULL
)
5559 if (dwp_file
->tus
== NULL
)
5561 dwo_entry
= lookup_dwo_unit_in_dwp (dwp_file
, NULL
,
5562 sig
, 1 /* is_debug_types */);
5563 if (dwo_entry
== NULL
)
5566 sig_entry
= add_type_unit (sig
, slot
);
5567 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
5572 /* Lookup a signature based type for DW_FORM_ref_sig8.
5573 Returns NULL if signature SIG is not present in the table.
5574 It is up to the caller to complain about this. */
5576 static struct signatured_type
*
5577 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5580 && dwarf2_per_objfile
->using_index
)
5582 /* We're in a DWO/DWP file, and we're using .gdb_index.
5583 These cases require special processing. */
5584 if (get_dwp_file () == NULL
)
5585 return lookup_dwo_signatured_type (cu
, sig
);
5587 return lookup_dwp_signatured_type (cu
, sig
);
5591 struct signatured_type find_entry
, *entry
;
5593 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5595 find_entry
.signature
= sig
;
5596 entry
= ((struct signatured_type
*)
5597 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
5602 /* Low level DIE reading support. */
5604 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
5607 init_cu_die_reader (struct die_reader_specs
*reader
,
5608 struct dwarf2_cu
*cu
,
5609 struct dwarf2_section_info
*section
,
5610 struct dwo_file
*dwo_file
)
5612 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
5613 reader
->abfd
= get_section_bfd_owner (section
);
5615 reader
->dwo_file
= dwo_file
;
5616 reader
->die_section
= section
;
5617 reader
->buffer
= section
->buffer
;
5618 reader
->buffer_end
= section
->buffer
+ section
->size
;
5619 reader
->comp_dir
= NULL
;
5622 /* Subroutine of init_cutu_and_read_dies to simplify it.
5623 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
5624 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
5627 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
5628 from it to the DIE in the DWO. If NULL we are skipping the stub.
5629 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
5630 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
5631 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
5632 STUB_COMP_DIR may be non-NULL.
5633 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
5634 are filled in with the info of the DIE from the DWO file.
5635 ABBREV_TABLE_PROVIDED is non-zero if the caller of init_cutu_and_read_dies
5636 provided an abbrev table to use.
5637 The result is non-zero if a valid (non-dummy) DIE was found. */
5640 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
5641 struct dwo_unit
*dwo_unit
,
5642 int abbrev_table_provided
,
5643 struct die_info
*stub_comp_unit_die
,
5644 const char *stub_comp_dir
,
5645 struct die_reader_specs
*result_reader
,
5646 const gdb_byte
**result_info_ptr
,
5647 struct die_info
**result_comp_unit_die
,
5648 int *result_has_children
)
5650 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5651 struct dwarf2_cu
*cu
= this_cu
->cu
;
5652 struct dwarf2_section_info
*section
;
5654 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5655 ULONGEST signature
; /* Or dwo_id. */
5656 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
5657 int i
,num_extra_attrs
;
5658 struct dwarf2_section_info
*dwo_abbrev_section
;
5659 struct attribute
*attr
;
5660 struct die_info
*comp_unit_die
;
5662 /* At most one of these may be provided. */
5663 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
5665 /* These attributes aren't processed until later:
5666 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
5667 DW_AT_comp_dir is used now, to find the DWO file, but it is also
5668 referenced later. However, these attributes are found in the stub
5669 which we won't have later. In order to not impose this complication
5670 on the rest of the code, we read them here and copy them to the
5679 if (stub_comp_unit_die
!= NULL
)
5681 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
5683 if (! this_cu
->is_debug_types
)
5684 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
5685 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
5686 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
5687 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
5688 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
5690 /* There should be a DW_AT_addr_base attribute here (if needed).
5691 We need the value before we can process DW_FORM_GNU_addr_index. */
5693 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
5695 cu
->addr_base
= DW_UNSND (attr
);
5697 /* There should be a DW_AT_ranges_base attribute here (if needed).
5698 We need the value before we can process DW_AT_ranges. */
5699 cu
->ranges_base
= 0;
5700 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
5702 cu
->ranges_base
= DW_UNSND (attr
);
5704 else if (stub_comp_dir
!= NULL
)
5706 /* Reconstruct the comp_dir attribute to simplify the code below. */
5707 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
5708 comp_dir
->name
= DW_AT_comp_dir
;
5709 comp_dir
->form
= DW_FORM_string
;
5710 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
5711 DW_STRING (comp_dir
) = stub_comp_dir
;
5714 /* Set up for reading the DWO CU/TU. */
5715 cu
->dwo_unit
= dwo_unit
;
5716 section
= dwo_unit
->section
;
5717 dwarf2_read_section (objfile
, section
);
5718 abfd
= get_section_bfd_owner (section
);
5719 begin_info_ptr
= info_ptr
= (section
->buffer
5720 + to_underlying (dwo_unit
->sect_off
));
5721 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
5722 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
);
5724 if (this_cu
->is_debug_types
)
5726 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
5728 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5730 info_ptr
, rcuh_kind::TYPE
);
5731 /* This is not an assert because it can be caused by bad debug info. */
5732 if (sig_type
->signature
!= cu
->header
.signature
)
5734 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
5735 " TU at offset 0x%x [in module %s]"),
5736 hex_string (sig_type
->signature
),
5737 hex_string (cu
->header
.signature
),
5738 to_underlying (dwo_unit
->sect_off
),
5739 bfd_get_filename (abfd
));
5741 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
5742 /* For DWOs coming from DWP files, we don't know the CU length
5743 nor the type's offset in the TU until now. */
5744 dwo_unit
->length
= get_cu_length (&cu
->header
);
5745 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
5747 /* Establish the type offset that can be used to lookup the type.
5748 For DWO files, we don't know it until now. */
5749 sig_type
->type_offset_in_section
5750 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
5754 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5756 info_ptr
, rcuh_kind::COMPILE
);
5757 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
5758 /* For DWOs coming from DWP files, we don't know the CU length
5760 dwo_unit
->length
= get_cu_length (&cu
->header
);
5763 /* Replace the CU's original abbrev table with the DWO's.
5764 Reminder: We can't read the abbrev table until we've read the header. */
5765 if (abbrev_table_provided
)
5767 /* Don't free the provided abbrev table, the caller of
5768 init_cutu_and_read_dies owns it. */
5769 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5770 /* Ensure the DWO abbrev table gets freed. */
5771 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5775 dwarf2_free_abbrev_table (cu
);
5776 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5777 /* Leave any existing abbrev table cleanup as is. */
5780 /* Read in the die, but leave space to copy over the attributes
5781 from the stub. This has the benefit of simplifying the rest of
5782 the code - all the work to maintain the illusion of a single
5783 DW_TAG_{compile,type}_unit DIE is done here. */
5784 num_extra_attrs
= ((stmt_list
!= NULL
)
5788 + (comp_dir
!= NULL
));
5789 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
5790 result_has_children
, num_extra_attrs
);
5792 /* Copy over the attributes from the stub to the DIE we just read in. */
5793 comp_unit_die
= *result_comp_unit_die
;
5794 i
= comp_unit_die
->num_attrs
;
5795 if (stmt_list
!= NULL
)
5796 comp_unit_die
->attrs
[i
++] = *stmt_list
;
5798 comp_unit_die
->attrs
[i
++] = *low_pc
;
5799 if (high_pc
!= NULL
)
5800 comp_unit_die
->attrs
[i
++] = *high_pc
;
5802 comp_unit_die
->attrs
[i
++] = *ranges
;
5803 if (comp_dir
!= NULL
)
5804 comp_unit_die
->attrs
[i
++] = *comp_dir
;
5805 comp_unit_die
->num_attrs
+= num_extra_attrs
;
5807 if (dwarf_die_debug
)
5809 fprintf_unfiltered (gdb_stdlog
,
5810 "Read die from %s@0x%x of %s:\n",
5811 get_section_name (section
),
5812 (unsigned) (begin_info_ptr
- section
->buffer
),
5813 bfd_get_filename (abfd
));
5814 dump_die (comp_unit_die
, dwarf_die_debug
);
5817 /* Save the comp_dir attribute. If there is no DWP file then we'll read
5818 TUs by skipping the stub and going directly to the entry in the DWO file.
5819 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
5820 to get it via circuitous means. Blech. */
5821 if (comp_dir
!= NULL
)
5822 result_reader
->comp_dir
= DW_STRING (comp_dir
);
5824 /* Skip dummy compilation units. */
5825 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
5826 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5829 *result_info_ptr
= info_ptr
;
5833 /* Subroutine of init_cutu_and_read_dies to simplify it.
5834 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
5835 Returns NULL if the specified DWO unit cannot be found. */
5837 static struct dwo_unit
*
5838 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
5839 struct die_info
*comp_unit_die
)
5841 struct dwarf2_cu
*cu
= this_cu
->cu
;
5842 struct attribute
*attr
;
5844 struct dwo_unit
*dwo_unit
;
5845 const char *comp_dir
, *dwo_name
;
5847 gdb_assert (cu
!= NULL
);
5849 /* Yeah, we look dwo_name up again, but it simplifies the code. */
5850 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5851 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
5853 if (this_cu
->is_debug_types
)
5855 struct signatured_type
*sig_type
;
5857 /* Since this_cu is the first member of struct signatured_type,
5858 we can go from a pointer to one to a pointer to the other. */
5859 sig_type
= (struct signatured_type
*) this_cu
;
5860 signature
= sig_type
->signature
;
5861 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
5865 struct attribute
*attr
;
5867 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
5869 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
5871 dwo_name
, objfile_name (this_cu
->objfile
));
5872 signature
= DW_UNSND (attr
);
5873 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
5880 /* Subroutine of init_cutu_and_read_dies to simplify it.
5881 See it for a description of the parameters.
5882 Read a TU directly from a DWO file, bypassing the stub.
5884 Note: This function could be a little bit simpler if we shared cleanups
5885 with our caller, init_cutu_and_read_dies. That's generally a fragile thing
5886 to do, so we keep this function self-contained. Or we could move this
5887 into our caller, but it's complex enough already. */
5890 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
5891 int use_existing_cu
, int keep
,
5892 die_reader_func_ftype
*die_reader_func
,
5895 struct dwarf2_cu
*cu
;
5896 struct signatured_type
*sig_type
;
5897 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5898 struct die_reader_specs reader
;
5899 const gdb_byte
*info_ptr
;
5900 struct die_info
*comp_unit_die
;
5903 /* Verify we can do the following downcast, and that we have the
5905 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
5906 sig_type
= (struct signatured_type
*) this_cu
;
5907 gdb_assert (sig_type
->dwo_unit
!= NULL
);
5909 cleanups
= make_cleanup (null_cleanup
, NULL
);
5911 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5913 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
5915 /* There's no need to do the rereading_dwo_cu handling that
5916 init_cutu_and_read_dies does since we don't read the stub. */
5920 /* If !use_existing_cu, this_cu->cu must be NULL. */
5921 gdb_assert (this_cu
->cu
== NULL
);
5922 cu
= XNEW (struct dwarf2_cu
);
5923 init_one_comp_unit (cu
, this_cu
);
5924 /* If an error occurs while loading, release our storage. */
5925 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5928 /* A future optimization, if needed, would be to use an existing
5929 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
5930 could share abbrev tables. */
5932 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
5933 0 /* abbrev_table_provided */,
5934 NULL
/* stub_comp_unit_die */,
5935 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
5937 &comp_unit_die
, &has_children
) == 0)
5940 do_cleanups (cleanups
);
5944 /* All the "real" work is done here. */
5945 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5947 /* This duplicates the code in init_cutu_and_read_dies,
5948 but the alternative is making the latter more complex.
5949 This function is only for the special case of using DWO files directly:
5950 no point in overly complicating the general case just to handle this. */
5951 if (free_cu_cleanup
!= NULL
)
5955 /* We've successfully allocated this compilation unit. Let our
5956 caller clean it up when finished with it. */
5957 discard_cleanups (free_cu_cleanup
);
5959 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5960 So we have to manually free the abbrev table. */
5961 dwarf2_free_abbrev_table (cu
);
5963 /* Link this CU into read_in_chain. */
5964 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5965 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5968 do_cleanups (free_cu_cleanup
);
5971 do_cleanups (cleanups
);
5974 /* Initialize a CU (or TU) and read its DIEs.
5975 If the CU defers to a DWO file, read the DWO file as well.
5977 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
5978 Otherwise the table specified in the comp unit header is read in and used.
5979 This is an optimization for when we already have the abbrev table.
5981 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
5982 Otherwise, a new CU is allocated with xmalloc.
5984 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
5985 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
5987 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5988 linker) then DIE_READER_FUNC will not get called. */
5991 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
5992 struct abbrev_table
*abbrev_table
,
5993 int use_existing_cu
, int keep
,
5994 die_reader_func_ftype
*die_reader_func
,
5997 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5998 struct dwarf2_section_info
*section
= this_cu
->section
;
5999 bfd
*abfd
= get_section_bfd_owner (section
);
6000 struct dwarf2_cu
*cu
;
6001 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6002 struct die_reader_specs reader
;
6003 struct die_info
*comp_unit_die
;
6005 struct attribute
*attr
;
6006 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
6007 struct signatured_type
*sig_type
= NULL
;
6008 struct dwarf2_section_info
*abbrev_section
;
6009 /* Non-zero if CU currently points to a DWO file and we need to
6010 reread it. When this happens we need to reread the skeleton die
6011 before we can reread the DWO file (this only applies to CUs, not TUs). */
6012 int rereading_dwo_cu
= 0;
6014 if (dwarf_die_debug
)
6015 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
6016 this_cu
->is_debug_types
? "type" : "comp",
6017 to_underlying (this_cu
->sect_off
));
6019 if (use_existing_cu
)
6022 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6023 file (instead of going through the stub), short-circuit all of this. */
6024 if (this_cu
->reading_dwo_directly
)
6026 /* Narrow down the scope of possibilities to have to understand. */
6027 gdb_assert (this_cu
->is_debug_types
);
6028 gdb_assert (abbrev_table
== NULL
);
6029 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
6030 die_reader_func
, data
);
6034 cleanups
= make_cleanup (null_cleanup
, NULL
);
6036 /* This is cheap if the section is already read in. */
6037 dwarf2_read_section (objfile
, section
);
6039 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6041 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6043 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6046 /* If this CU is from a DWO file we need to start over, we need to
6047 refetch the attributes from the skeleton CU.
6048 This could be optimized by retrieving those attributes from when we
6049 were here the first time: the previous comp_unit_die was stored in
6050 comp_unit_obstack. But there's no data yet that we need this
6052 if (cu
->dwo_unit
!= NULL
)
6053 rereading_dwo_cu
= 1;
6057 /* If !use_existing_cu, this_cu->cu must be NULL. */
6058 gdb_assert (this_cu
->cu
== NULL
);
6059 cu
= XNEW (struct dwarf2_cu
);
6060 init_one_comp_unit (cu
, this_cu
);
6061 /* If an error occurs while loading, release our storage. */
6062 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
6065 /* Get the header. */
6066 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6068 /* We already have the header, there's no need to read it in again. */
6069 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6073 if (this_cu
->is_debug_types
)
6075 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
6076 abbrev_section
, info_ptr
,
6079 /* Since per_cu is the first member of struct signatured_type,
6080 we can go from a pointer to one to a pointer to the other. */
6081 sig_type
= (struct signatured_type
*) this_cu
;
6082 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6083 gdb_assert (sig_type
->type_offset_in_tu
6084 == cu
->header
.type_cu_offset_in_tu
);
6085 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6087 /* LENGTH has not been set yet for type units if we're
6088 using .gdb_index. */
6089 this_cu
->length
= get_cu_length (&cu
->header
);
6091 /* Establish the type offset that can be used to lookup the type. */
6092 sig_type
->type_offset_in_section
=
6093 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6095 this_cu
->dwarf_version
= cu
->header
.version
;
6099 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
6102 rcuh_kind::COMPILE
);
6104 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6105 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
6106 this_cu
->dwarf_version
= cu
->header
.version
;
6110 /* Skip dummy compilation units. */
6111 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6112 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6114 do_cleanups (cleanups
);
6118 /* If we don't have them yet, read the abbrevs for this compilation unit.
6119 And if we need to read them now, make sure they're freed when we're
6120 done. Note that it's important that if the CU had an abbrev table
6121 on entry we don't free it when we're done: Somewhere up the call stack
6122 it may be in use. */
6123 if (abbrev_table
!= NULL
)
6125 gdb_assert (cu
->abbrev_table
== NULL
);
6126 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6127 cu
->abbrev_table
= abbrev_table
;
6129 else if (cu
->abbrev_table
== NULL
)
6131 dwarf2_read_abbrevs (cu
, abbrev_section
);
6132 make_cleanup (dwarf2_free_abbrev_table
, cu
);
6134 else if (rereading_dwo_cu
)
6136 dwarf2_free_abbrev_table (cu
);
6137 dwarf2_read_abbrevs (cu
, abbrev_section
);
6140 /* Read the top level CU/TU die. */
6141 init_cu_die_reader (&reader
, cu
, section
, NULL
);
6142 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
6144 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6146 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6147 DWO CU, that this test will fail (the attribute will not be present). */
6148 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
6151 struct dwo_unit
*dwo_unit
;
6152 struct die_info
*dwo_comp_unit_die
;
6156 complaint (&symfile_complaints
,
6157 _("compilation unit with DW_AT_GNU_dwo_name"
6158 " has children (offset 0x%x) [in module %s]"),
6159 to_underlying (this_cu
->sect_off
), bfd_get_filename (abfd
));
6161 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
6162 if (dwo_unit
!= NULL
)
6164 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6165 abbrev_table
!= NULL
,
6166 comp_unit_die
, NULL
,
6168 &dwo_comp_unit_die
, &has_children
) == 0)
6171 do_cleanups (cleanups
);
6174 comp_unit_die
= dwo_comp_unit_die
;
6178 /* Yikes, we couldn't find the rest of the DIE, we only have
6179 the stub. A complaint has already been logged. There's
6180 not much more we can do except pass on the stub DIE to
6181 die_reader_func. We don't want to throw an error on bad
6186 /* All of the above is setup for this call. Yikes. */
6187 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
6189 /* Done, clean up. */
6190 if (free_cu_cleanup
!= NULL
)
6194 /* We've successfully allocated this compilation unit. Let our
6195 caller clean it up when finished with it. */
6196 discard_cleanups (free_cu_cleanup
);
6198 /* We can only discard free_cu_cleanup and all subsequent cleanups.
6199 So we have to manually free the abbrev table. */
6200 dwarf2_free_abbrev_table (cu
);
6202 /* Link this CU into read_in_chain. */
6203 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6204 dwarf2_per_objfile
->read_in_chain
= this_cu
;
6207 do_cleanups (free_cu_cleanup
);
6210 do_cleanups (cleanups
);
6213 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
6214 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
6215 to have already done the lookup to find the DWO file).
6217 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6218 THIS_CU->is_debug_types, but nothing else.
6220 We fill in THIS_CU->length.
6222 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
6223 linker) then DIE_READER_FUNC will not get called.
6225 THIS_CU->cu is always freed when done.
6226 This is done in order to not leave THIS_CU->cu in a state where we have
6227 to care whether it refers to the "main" CU or the DWO CU. */
6230 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
6231 struct dwo_file
*dwo_file
,
6232 die_reader_func_ftype
*die_reader_func
,
6235 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6236 struct dwarf2_section_info
*section
= this_cu
->section
;
6237 bfd
*abfd
= get_section_bfd_owner (section
);
6238 struct dwarf2_section_info
*abbrev_section
;
6239 struct dwarf2_cu cu
;
6240 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6241 struct die_reader_specs reader
;
6242 struct cleanup
*cleanups
;
6243 struct die_info
*comp_unit_die
;
6246 if (dwarf_die_debug
)
6247 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
6248 this_cu
->is_debug_types
? "type" : "comp",
6249 to_underlying (this_cu
->sect_off
));
6251 gdb_assert (this_cu
->cu
== NULL
);
6253 abbrev_section
= (dwo_file
!= NULL
6254 ? &dwo_file
->sections
.abbrev
6255 : get_abbrev_section_for_cu (this_cu
));
6257 /* This is cheap if the section is already read in. */
6258 dwarf2_read_section (objfile
, section
);
6260 init_one_comp_unit (&cu
, this_cu
);
6262 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
6264 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6265 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
6266 abbrev_section
, info_ptr
,
6267 (this_cu
->is_debug_types
6269 : rcuh_kind::COMPILE
));
6271 this_cu
->length
= get_cu_length (&cu
.header
);
6273 /* Skip dummy compilation units. */
6274 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6275 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6277 do_cleanups (cleanups
);
6281 dwarf2_read_abbrevs (&cu
, abbrev_section
);
6282 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
6284 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
6285 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
6287 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
6289 do_cleanups (cleanups
);
6292 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
6293 does not lookup the specified DWO file.
6294 This cannot be used to read DWO files.
6296 THIS_CU->cu is always freed when done.
6297 This is done in order to not leave THIS_CU->cu in a state where we have
6298 to care whether it refers to the "main" CU or the DWO CU.
6299 We can revisit this if the data shows there's a performance issue. */
6302 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
6303 die_reader_func_ftype
*die_reader_func
,
6306 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
6309 /* Type Unit Groups.
6311 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6312 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6313 so that all types coming from the same compilation (.o file) are grouped
6314 together. A future step could be to put the types in the same symtab as
6315 the CU the types ultimately came from. */
6318 hash_type_unit_group (const void *item
)
6320 const struct type_unit_group
*tu_group
6321 = (const struct type_unit_group
*) item
;
6323 return hash_stmt_list_entry (&tu_group
->hash
);
6327 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6329 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6330 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6332 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6335 /* Allocate a hash table for type unit groups. */
6338 allocate_type_unit_groups_table (void)
6340 return htab_create_alloc_ex (3,
6341 hash_type_unit_group
,
6344 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
6345 hashtab_obstack_allocate
,
6346 dummy_obstack_deallocate
);
6349 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6350 partial symtabs. We combine several TUs per psymtab to not let the size
6351 of any one psymtab grow too big. */
6352 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6353 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6355 /* Helper routine for get_type_unit_group.
6356 Create the type_unit_group object used to hold one or more TUs. */
6358 static struct type_unit_group
*
6359 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6361 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6362 struct dwarf2_per_cu_data
*per_cu
;
6363 struct type_unit_group
*tu_group
;
6365 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6366 struct type_unit_group
);
6367 per_cu
= &tu_group
->per_cu
;
6368 per_cu
->objfile
= objfile
;
6370 if (dwarf2_per_objfile
->using_index
)
6372 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6373 struct dwarf2_per_cu_quick_data
);
6377 unsigned int line_offset
= to_underlying (line_offset_struct
);
6378 struct partial_symtab
*pst
;
6381 /* Give the symtab a useful name for debug purposes. */
6382 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
6383 name
= xstrprintf ("<type_units_%d>",
6384 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
6386 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
6388 pst
= create_partial_symtab (per_cu
, name
);
6394 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6395 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6400 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6401 STMT_LIST is a DW_AT_stmt_list attribute. */
6403 static struct type_unit_group
*
6404 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6406 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6407 struct type_unit_group
*tu_group
;
6409 unsigned int line_offset
;
6410 struct type_unit_group type_unit_group_for_lookup
;
6412 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
6414 dwarf2_per_objfile
->type_unit_groups
=
6415 allocate_type_unit_groups_table ();
6418 /* Do we need to create a new group, or can we use an existing one? */
6422 line_offset
= DW_UNSND (stmt_list
);
6423 ++tu_stats
->nr_symtab_sharers
;
6427 /* Ugh, no stmt_list. Rare, but we have to handle it.
6428 We can do various things here like create one group per TU or
6429 spread them over multiple groups to split up the expansion work.
6430 To avoid worst case scenarios (too many groups or too large groups)
6431 we, umm, group them in bunches. */
6432 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6433 | (tu_stats
->nr_stmt_less_type_units
6434 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6435 ++tu_stats
->nr_stmt_less_type_units
;
6438 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6439 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6440 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
6441 &type_unit_group_for_lookup
, INSERT
);
6444 tu_group
= (struct type_unit_group
*) *slot
;
6445 gdb_assert (tu_group
!= NULL
);
6449 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6450 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
6452 ++tu_stats
->nr_symtabs
;
6458 /* Partial symbol tables. */
6460 /* Create a psymtab named NAME and assign it to PER_CU.
6462 The caller must fill in the following details:
6463 dirname, textlow, texthigh. */
6465 static struct partial_symtab
*
6466 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
6468 struct objfile
*objfile
= per_cu
->objfile
;
6469 struct partial_symtab
*pst
;
6471 pst
= start_psymtab_common (objfile
, name
, 0,
6472 objfile
->global_psymbols
,
6473 objfile
->static_psymbols
);
6475 pst
->psymtabs_addrmap_supported
= 1;
6477 /* This is the glue that links PST into GDB's symbol API. */
6478 pst
->read_symtab_private
= per_cu
;
6479 pst
->read_symtab
= dwarf2_read_symtab
;
6480 per_cu
->v
.psymtab
= pst
;
6485 /* The DATA object passed to process_psymtab_comp_unit_reader has this
6488 struct process_psymtab_comp_unit_data
6490 /* True if we are reading a DW_TAG_partial_unit. */
6492 int want_partial_unit
;
6494 /* The "pretend" language that is used if the CU doesn't declare a
6497 enum language pretend_language
;
6500 /* die_reader_func for process_psymtab_comp_unit. */
6503 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6504 const gdb_byte
*info_ptr
,
6505 struct die_info
*comp_unit_die
,
6509 struct dwarf2_cu
*cu
= reader
->cu
;
6510 struct objfile
*objfile
= cu
->objfile
;
6511 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6512 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6514 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6515 struct partial_symtab
*pst
;
6516 enum pc_bounds_kind cu_bounds_kind
;
6517 const char *filename
;
6518 struct process_psymtab_comp_unit_data
*info
6519 = (struct process_psymtab_comp_unit_data
*) data
;
6521 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
6524 gdb_assert (! per_cu
->is_debug_types
);
6526 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
6528 cu
->list_in_scope
= &file_symbols
;
6530 /* Allocate a new partial symbol table structure. */
6531 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
6532 if (filename
== NULL
)
6535 pst
= create_partial_symtab (per_cu
, filename
);
6537 /* This must be done before calling dwarf2_build_include_psymtabs. */
6538 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6540 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6542 dwarf2_find_base_address (comp_unit_die
, cu
);
6544 /* Possibly set the default values of LOWPC and HIGHPC from
6546 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
6547 &best_highpc
, cu
, pst
);
6548 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
6549 /* Store the contiguous range if it is not empty; it can be empty for
6550 CUs with no code. */
6551 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6552 gdbarch_adjust_dwarf2_addr (gdbarch
,
6553 best_lowpc
+ baseaddr
),
6554 gdbarch_adjust_dwarf2_addr (gdbarch
,
6555 best_highpc
+ baseaddr
) - 1,
6558 /* Check if comp unit has_children.
6559 If so, read the rest of the partial symbols from this comp unit.
6560 If not, there's no more debug_info for this comp unit. */
6563 struct partial_die_info
*first_die
;
6564 CORE_ADDR lowpc
, highpc
;
6566 lowpc
= ((CORE_ADDR
) -1);
6567 highpc
= ((CORE_ADDR
) 0);
6569 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6571 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
6572 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
6574 /* If we didn't find a lowpc, set it to highpc to avoid
6575 complaints from `maint check'. */
6576 if (lowpc
== ((CORE_ADDR
) -1))
6579 /* If the compilation unit didn't have an explicit address range,
6580 then use the information extracted from its child dies. */
6581 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
6584 best_highpc
= highpc
;
6587 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
6588 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
6590 end_psymtab_common (objfile
, pst
);
6592 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
6595 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6596 struct dwarf2_per_cu_data
*iter
;
6598 /* Fill in 'dependencies' here; we fill in 'users' in a
6600 pst
->number_of_dependencies
= len
;
6602 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6604 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
6607 pst
->dependencies
[i
] = iter
->v
.psymtab
;
6609 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6612 /* Get the list of files included in the current compilation unit,
6613 and build a psymtab for each of them. */
6614 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
6616 if (dwarf_read_debug
)
6618 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6620 fprintf_unfiltered (gdb_stdlog
,
6621 "Psymtab for %s unit @0x%x: %s - %s"
6622 ", %d global, %d static syms\n",
6623 per_cu
->is_debug_types
? "type" : "comp",
6624 to_underlying (per_cu
->sect_off
),
6625 paddress (gdbarch
, pst
->textlow
),
6626 paddress (gdbarch
, pst
->texthigh
),
6627 pst
->n_global_syms
, pst
->n_static_syms
);
6631 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6632 Process compilation unit THIS_CU for a psymtab. */
6635 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6636 int want_partial_unit
,
6637 enum language pretend_language
)
6639 /* If this compilation unit was already read in, free the
6640 cached copy in order to read it in again. This is
6641 necessary because we skipped some symbols when we first
6642 read in the compilation unit (see load_partial_dies).
6643 This problem could be avoided, but the benefit is unclear. */
6644 if (this_cu
->cu
!= NULL
)
6645 free_one_cached_comp_unit (this_cu
);
6647 if (this_cu
->is_debug_types
)
6648 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, build_type_psymtabs_reader
,
6652 process_psymtab_comp_unit_data info
;
6653 info
.want_partial_unit
= want_partial_unit
;
6654 info
.pretend_language
= pretend_language
;
6655 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
6656 process_psymtab_comp_unit_reader
, &info
);
6659 /* Age out any secondary CUs. */
6660 age_cached_comp_units ();
6663 /* Reader function for build_type_psymtabs. */
6666 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
6667 const gdb_byte
*info_ptr
,
6668 struct die_info
*type_unit_die
,
6672 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6673 struct dwarf2_cu
*cu
= reader
->cu
;
6674 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6675 struct signatured_type
*sig_type
;
6676 struct type_unit_group
*tu_group
;
6677 struct attribute
*attr
;
6678 struct partial_die_info
*first_die
;
6679 CORE_ADDR lowpc
, highpc
;
6680 struct partial_symtab
*pst
;
6682 gdb_assert (data
== NULL
);
6683 gdb_assert (per_cu
->is_debug_types
);
6684 sig_type
= (struct signatured_type
*) per_cu
;
6689 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
6690 tu_group
= get_type_unit_group (cu
, attr
);
6692 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
6694 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
6695 cu
->list_in_scope
= &file_symbols
;
6696 pst
= create_partial_symtab (per_cu
, "");
6699 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6701 lowpc
= (CORE_ADDR
) -1;
6702 highpc
= (CORE_ADDR
) 0;
6703 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
6705 end_psymtab_common (objfile
, pst
);
6708 /* Struct used to sort TUs by their abbreviation table offset. */
6710 struct tu_abbrev_offset
6712 struct signatured_type
*sig_type
;
6713 sect_offset abbrev_offset
;
6716 /* Helper routine for build_type_psymtabs_1, passed to qsort. */
6719 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
6721 const struct tu_abbrev_offset
* const *a
6722 = (const struct tu_abbrev_offset
* const*) ap
;
6723 const struct tu_abbrev_offset
* const *b
6724 = (const struct tu_abbrev_offset
* const*) bp
;
6725 sect_offset aoff
= (*a
)->abbrev_offset
;
6726 sect_offset boff
= (*b
)->abbrev_offset
;
6728 return (aoff
> boff
) - (aoff
< boff
);
6731 /* Efficiently read all the type units.
6732 This does the bulk of the work for build_type_psymtabs.
6734 The efficiency is because we sort TUs by the abbrev table they use and
6735 only read each abbrev table once. In one program there are 200K TUs
6736 sharing 8K abbrev tables.
6738 The main purpose of this function is to support building the
6739 dwarf2_per_objfile->type_unit_groups table.
6740 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
6741 can collapse the search space by grouping them by stmt_list.
6742 The savings can be significant, in the same program from above the 200K TUs
6743 share 8K stmt_list tables.
6745 FUNC is expected to call get_type_unit_group, which will create the
6746 struct type_unit_group if necessary and add it to
6747 dwarf2_per_objfile->type_unit_groups. */
6750 build_type_psymtabs_1 (void)
6752 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6753 struct cleanup
*cleanups
;
6754 struct abbrev_table
*abbrev_table
;
6755 sect_offset abbrev_offset
;
6756 struct tu_abbrev_offset
*sorted_by_abbrev
;
6759 /* It's up to the caller to not call us multiple times. */
6760 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
6762 if (dwarf2_per_objfile
->n_type_units
== 0)
6765 /* TUs typically share abbrev tables, and there can be way more TUs than
6766 abbrev tables. Sort by abbrev table to reduce the number of times we
6767 read each abbrev table in.
6768 Alternatives are to punt or to maintain a cache of abbrev tables.
6769 This is simpler and efficient enough for now.
6771 Later we group TUs by their DW_AT_stmt_list value (as this defines the
6772 symtab to use). Typically TUs with the same abbrev offset have the same
6773 stmt_list value too so in practice this should work well.
6775 The basic algorithm here is:
6777 sort TUs by abbrev table
6778 for each TU with same abbrev table:
6779 read abbrev table if first user
6780 read TU top level DIE
6781 [IWBN if DWO skeletons had DW_AT_stmt_list]
6784 if (dwarf_read_debug
)
6785 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
6787 /* Sort in a separate table to maintain the order of all_type_units
6788 for .gdb_index: TU indices directly index all_type_units. */
6789 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
6790 dwarf2_per_objfile
->n_type_units
);
6791 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6793 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
6795 sorted_by_abbrev
[i
].sig_type
= sig_type
;
6796 sorted_by_abbrev
[i
].abbrev_offset
=
6797 read_abbrev_offset (sig_type
->per_cu
.section
,
6798 sig_type
->per_cu
.sect_off
);
6800 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
6801 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
6802 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
6804 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
6805 abbrev_table
= NULL
;
6806 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
6808 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6810 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
6812 /* Switch to the next abbrev table if necessary. */
6813 if (abbrev_table
== NULL
6814 || tu
->abbrev_offset
!= abbrev_offset
)
6816 if (abbrev_table
!= NULL
)
6818 abbrev_table_free (abbrev_table
);
6819 /* Reset to NULL in case abbrev_table_read_table throws
6820 an error: abbrev_table_free_cleanup will get called. */
6821 abbrev_table
= NULL
;
6823 abbrev_offset
= tu
->abbrev_offset
;
6825 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
6827 ++tu_stats
->nr_uniq_abbrev_tables
;
6830 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
6831 build_type_psymtabs_reader
, NULL
);
6834 do_cleanups (cleanups
);
6837 /* Print collected type unit statistics. */
6840 print_tu_stats (void)
6842 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6844 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
6845 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
6846 dwarf2_per_objfile
->n_type_units
);
6847 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
6848 tu_stats
->nr_uniq_abbrev_tables
);
6849 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
6850 tu_stats
->nr_symtabs
);
6851 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
6852 tu_stats
->nr_symtab_sharers
);
6853 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
6854 tu_stats
->nr_stmt_less_type_units
);
6855 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
6856 tu_stats
->nr_all_type_units_reallocs
);
6859 /* Traversal function for build_type_psymtabs. */
6862 build_type_psymtab_dependencies (void **slot
, void *info
)
6864 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6865 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
6866 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
6867 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6868 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
6869 struct signatured_type
*iter
;
6872 gdb_assert (len
> 0);
6873 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
6875 pst
->number_of_dependencies
= len
;
6877 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6879 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
6882 gdb_assert (iter
->per_cu
.is_debug_types
);
6883 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
6884 iter
->type_unit_group
= tu_group
;
6887 VEC_free (sig_type_ptr
, tu_group
->tus
);
6892 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6893 Build partial symbol tables for the .debug_types comp-units. */
6896 build_type_psymtabs (struct objfile
*objfile
)
6898 if (! create_all_type_units (objfile
))
6901 build_type_psymtabs_1 ();
6904 /* Traversal function for process_skeletonless_type_unit.
6905 Read a TU in a DWO file and build partial symbols for it. */
6908 process_skeletonless_type_unit (void **slot
, void *info
)
6910 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
6911 struct objfile
*objfile
= (struct objfile
*) info
;
6912 struct signatured_type find_entry
, *entry
;
6914 /* If this TU doesn't exist in the global table, add it and read it in. */
6916 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6918 dwarf2_per_objfile
->signatured_types
6919 = allocate_signatured_type_table (objfile
);
6922 find_entry
.signature
= dwo_unit
->signature
;
6923 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
6925 /* If we've already seen this type there's nothing to do. What's happening
6926 is we're doing our own version of comdat-folding here. */
6930 /* This does the job that create_all_type_units would have done for
6932 entry
= add_type_unit (dwo_unit
->signature
, slot
);
6933 fill_in_sig_entry_from_dwo_entry (objfile
, entry
, dwo_unit
);
6936 /* This does the job that build_type_psymtabs_1 would have done. */
6937 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
6938 build_type_psymtabs_reader
, NULL
);
6943 /* Traversal function for process_skeletonless_type_units. */
6946 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
6948 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
6950 if (dwo_file
->tus
!= NULL
)
6952 htab_traverse_noresize (dwo_file
->tus
,
6953 process_skeletonless_type_unit
, info
);
6959 /* Scan all TUs of DWO files, verifying we've processed them.
6960 This is needed in case a TU was emitted without its skeleton.
6961 Note: This can't be done until we know what all the DWO files are. */
6964 process_skeletonless_type_units (struct objfile
*objfile
)
6966 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
6967 if (get_dwp_file () == NULL
6968 && dwarf2_per_objfile
->dwo_files
!= NULL
)
6970 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
6971 process_dwo_file_for_skeletonless_type_units
,
6976 /* Compute the 'user' field for each psymtab in OBJFILE. */
6979 set_partial_user (struct objfile
*objfile
)
6983 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6985 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6986 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6992 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
6994 /* Set the 'user' field only if it is not already set. */
6995 if (pst
->dependencies
[j
]->user
== NULL
)
6996 pst
->dependencies
[j
]->user
= pst
;
7001 /* Build the partial symbol table by doing a quick pass through the
7002 .debug_info and .debug_abbrev sections. */
7005 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
7007 struct cleanup
*back_to
;
7010 if (dwarf_read_debug
)
7012 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7013 objfile_name (objfile
));
7016 dwarf2_per_objfile
->reading_partial_symbols
= 1;
7018 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
7020 /* Any cached compilation units will be linked by the per-objfile
7021 read_in_chain. Make sure to free them when we're done. */
7022 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
7024 build_type_psymtabs (objfile
);
7026 create_all_comp_units (objfile
);
7028 /* Create a temporary address map on a temporary obstack. We later
7029 copy this to the final obstack. */
7030 auto_obstack temp_obstack
;
7032 scoped_restore save_psymtabs_addrmap
7033 = make_scoped_restore (&objfile
->psymtabs_addrmap
,
7034 addrmap_create_mutable (&temp_obstack
));
7036 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
7038 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
7040 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
7043 /* This has to wait until we read the CUs, we need the list of DWOs. */
7044 process_skeletonless_type_units (objfile
);
7046 /* Now that all TUs have been processed we can fill in the dependencies. */
7047 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7049 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
7050 build_type_psymtab_dependencies
, NULL
);
7053 if (dwarf_read_debug
)
7056 set_partial_user (objfile
);
7058 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
7059 &objfile
->objfile_obstack
);
7060 /* At this point we want to keep the address map. */
7061 save_psymtabs_addrmap
.release ();
7063 do_cleanups (back_to
);
7065 if (dwarf_read_debug
)
7066 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7067 objfile_name (objfile
));
7070 /* die_reader_func for load_partial_comp_unit. */
7073 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
7074 const gdb_byte
*info_ptr
,
7075 struct die_info
*comp_unit_die
,
7079 struct dwarf2_cu
*cu
= reader
->cu
;
7081 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
7083 /* Check if comp unit has_children.
7084 If so, read the rest of the partial symbols from this comp unit.
7085 If not, there's no more debug_info for this comp unit. */
7087 load_partial_dies (reader
, info_ptr
, 0);
7090 /* Load the partial DIEs for a secondary CU into memory.
7091 This is also used when rereading a primary CU with load_all_dies. */
7094 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7096 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
7097 load_partial_comp_unit_reader
, NULL
);
7101 read_comp_units_from_section (struct objfile
*objfile
,
7102 struct dwarf2_section_info
*section
,
7103 struct dwarf2_section_info
*abbrev_section
,
7104 unsigned int is_dwz
,
7107 struct dwarf2_per_cu_data
***all_comp_units
)
7109 const gdb_byte
*info_ptr
;
7110 bfd
*abfd
= get_section_bfd_owner (section
);
7112 if (dwarf_read_debug
)
7113 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7114 get_section_name (section
),
7115 get_section_file_name (section
));
7117 dwarf2_read_section (objfile
, section
);
7119 info_ptr
= section
->buffer
;
7121 while (info_ptr
< section
->buffer
+ section
->size
)
7123 struct dwarf2_per_cu_data
*this_cu
;
7125 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7127 comp_unit_head cu_header
;
7128 read_and_check_comp_unit_head (&cu_header
, section
, abbrev_section
,
7129 info_ptr
, rcuh_kind::COMPILE
);
7131 /* Save the compilation unit for later lookup. */
7132 if (cu_header
.unit_type
!= DW_UT_type
)
7134 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7135 struct dwarf2_per_cu_data
);
7136 memset (this_cu
, 0, sizeof (*this_cu
));
7140 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7141 struct signatured_type
);
7142 memset (sig_type
, 0, sizeof (*sig_type
));
7143 sig_type
->signature
= cu_header
.signature
;
7144 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7145 this_cu
= &sig_type
->per_cu
;
7147 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7148 this_cu
->sect_off
= sect_off
;
7149 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7150 this_cu
->is_dwz
= is_dwz
;
7151 this_cu
->objfile
= objfile
;
7152 this_cu
->section
= section
;
7154 if (*n_comp_units
== *n_allocated
)
7157 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
7158 *all_comp_units
, *n_allocated
);
7160 (*all_comp_units
)[*n_comp_units
] = this_cu
;
7163 info_ptr
= info_ptr
+ this_cu
->length
;
7167 /* Create a list of all compilation units in OBJFILE.
7168 This is only done for -readnow and building partial symtabs. */
7171 create_all_comp_units (struct objfile
*objfile
)
7175 struct dwarf2_per_cu_data
**all_comp_units
;
7176 struct dwz_file
*dwz
;
7180 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
7182 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
,
7183 &dwarf2_per_objfile
->abbrev
, 0,
7184 &n_allocated
, &n_comp_units
, &all_comp_units
);
7186 dwz
= dwarf2_get_dwz_file ();
7188 read_comp_units_from_section (objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
7189 &n_allocated
, &n_comp_units
,
7192 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
7193 struct dwarf2_per_cu_data
*,
7195 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
7196 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
7197 xfree (all_comp_units
);
7198 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
7201 /* Process all loaded DIEs for compilation unit CU, starting at
7202 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7203 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7204 DW_AT_ranges). See the comments of add_partial_subprogram on how
7205 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7208 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7209 CORE_ADDR
*highpc
, int set_addrmap
,
7210 struct dwarf2_cu
*cu
)
7212 struct partial_die_info
*pdi
;
7214 /* Now, march along the PDI's, descending into ones which have
7215 interesting children but skipping the children of the other ones,
7216 until we reach the end of the compilation unit. */
7222 fixup_partial_die (pdi
, cu
);
7224 /* Anonymous namespaces or modules have no name but have interesting
7225 children, so we need to look at them. Ditto for anonymous
7228 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7229 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7230 || pdi
->tag
== DW_TAG_imported_unit
)
7234 case DW_TAG_subprogram
:
7235 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7237 case DW_TAG_constant
:
7238 case DW_TAG_variable
:
7239 case DW_TAG_typedef
:
7240 case DW_TAG_union_type
:
7241 if (!pdi
->is_declaration
)
7243 add_partial_symbol (pdi
, cu
);
7246 case DW_TAG_class_type
:
7247 case DW_TAG_interface_type
:
7248 case DW_TAG_structure_type
:
7249 if (!pdi
->is_declaration
)
7251 add_partial_symbol (pdi
, cu
);
7253 if (cu
->language
== language_rust
&& pdi
->has_children
)
7254 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7257 case DW_TAG_enumeration_type
:
7258 if (!pdi
->is_declaration
)
7259 add_partial_enumeration (pdi
, cu
);
7261 case DW_TAG_base_type
:
7262 case DW_TAG_subrange_type
:
7263 /* File scope base type definitions are added to the partial
7265 add_partial_symbol (pdi
, cu
);
7267 case DW_TAG_namespace
:
7268 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7271 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7273 case DW_TAG_imported_unit
:
7275 struct dwarf2_per_cu_data
*per_cu
;
7277 /* For now we don't handle imported units in type units. */
7278 if (cu
->per_cu
->is_debug_types
)
7280 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7281 " supported in type units [in module %s]"),
7282 objfile_name (cu
->objfile
));
7285 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.sect_off
,
7289 /* Go read the partial unit, if needed. */
7290 if (per_cu
->v
.psymtab
== NULL
)
7291 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
7293 VEC_safe_push (dwarf2_per_cu_ptr
,
7294 cu
->per_cu
->imported_symtabs
, per_cu
);
7297 case DW_TAG_imported_declaration
:
7298 add_partial_symbol (pdi
, cu
);
7305 /* If the die has a sibling, skip to the sibling. */
7307 pdi
= pdi
->die_sibling
;
7311 /* Functions used to compute the fully scoped name of a partial DIE.
7313 Normally, this is simple. For C++, the parent DIE's fully scoped
7314 name is concatenated with "::" and the partial DIE's name.
7315 Enumerators are an exception; they use the scope of their parent
7316 enumeration type, i.e. the name of the enumeration type is not
7317 prepended to the enumerator.
7319 There are two complexities. One is DW_AT_specification; in this
7320 case "parent" means the parent of the target of the specification,
7321 instead of the direct parent of the DIE. The other is compilers
7322 which do not emit DW_TAG_namespace; in this case we try to guess
7323 the fully qualified name of structure types from their members'
7324 linkage names. This must be done using the DIE's children rather
7325 than the children of any DW_AT_specification target. We only need
7326 to do this for structures at the top level, i.e. if the target of
7327 any DW_AT_specification (if any; otherwise the DIE itself) does not
7330 /* Compute the scope prefix associated with PDI's parent, in
7331 compilation unit CU. The result will be allocated on CU's
7332 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7333 field. NULL is returned if no prefix is necessary. */
7335 partial_die_parent_scope (struct partial_die_info
*pdi
,
7336 struct dwarf2_cu
*cu
)
7338 const char *grandparent_scope
;
7339 struct partial_die_info
*parent
, *real_pdi
;
7341 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7342 then this means the parent of the specification DIE. */
7345 while (real_pdi
->has_specification
)
7346 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
7347 real_pdi
->spec_is_dwz
, cu
);
7349 parent
= real_pdi
->die_parent
;
7353 if (parent
->scope_set
)
7354 return parent
->scope
;
7356 fixup_partial_die (parent
, cu
);
7358 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7360 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7361 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7362 Work around this problem here. */
7363 if (cu
->language
== language_cplus
7364 && parent
->tag
== DW_TAG_namespace
7365 && strcmp (parent
->name
, "::") == 0
7366 && grandparent_scope
== NULL
)
7368 parent
->scope
= NULL
;
7369 parent
->scope_set
= 1;
7373 if (pdi
->tag
== DW_TAG_enumerator
)
7374 /* Enumerators should not get the name of the enumeration as a prefix. */
7375 parent
->scope
= grandparent_scope
;
7376 else if (parent
->tag
== DW_TAG_namespace
7377 || parent
->tag
== DW_TAG_module
7378 || parent
->tag
== DW_TAG_structure_type
7379 || parent
->tag
== DW_TAG_class_type
7380 || parent
->tag
== DW_TAG_interface_type
7381 || parent
->tag
== DW_TAG_union_type
7382 || parent
->tag
== DW_TAG_enumeration_type
)
7384 if (grandparent_scope
== NULL
)
7385 parent
->scope
= parent
->name
;
7387 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7389 parent
->name
, 0, cu
);
7393 /* FIXME drow/2004-04-01: What should we be doing with
7394 function-local names? For partial symbols, we should probably be
7396 complaint (&symfile_complaints
,
7397 _("unhandled containing DIE tag %d for DIE at %d"),
7398 parent
->tag
, to_underlying (pdi
->sect_off
));
7399 parent
->scope
= grandparent_scope
;
7402 parent
->scope_set
= 1;
7403 return parent
->scope
;
7406 /* Return the fully scoped name associated with PDI, from compilation unit
7407 CU. The result will be allocated with malloc. */
7410 partial_die_full_name (struct partial_die_info
*pdi
,
7411 struct dwarf2_cu
*cu
)
7413 const char *parent_scope
;
7415 /* If this is a template instantiation, we can not work out the
7416 template arguments from partial DIEs. So, unfortunately, we have
7417 to go through the full DIEs. At least any work we do building
7418 types here will be reused if full symbols are loaded later. */
7419 if (pdi
->has_template_arguments
)
7421 fixup_partial_die (pdi
, cu
);
7423 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
7425 struct die_info
*die
;
7426 struct attribute attr
;
7427 struct dwarf2_cu
*ref_cu
= cu
;
7429 /* DW_FORM_ref_addr is using section offset. */
7430 attr
.name
= (enum dwarf_attribute
) 0;
7431 attr
.form
= DW_FORM_ref_addr
;
7432 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7433 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7435 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7439 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7440 if (parent_scope
== NULL
)
7443 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
7447 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7449 struct objfile
*objfile
= cu
->objfile
;
7450 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7452 const char *actual_name
= NULL
;
7454 char *built_actual_name
;
7456 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7458 built_actual_name
= partial_die_full_name (pdi
, cu
);
7459 if (built_actual_name
!= NULL
)
7460 actual_name
= built_actual_name
;
7462 if (actual_name
== NULL
)
7463 actual_name
= pdi
->name
;
7467 case DW_TAG_subprogram
:
7468 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
7469 if (pdi
->is_external
|| cu
->language
== language_ada
)
7471 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
7472 of the global scope. But in Ada, we want to be able to access
7473 nested procedures globally. So all Ada subprograms are stored
7474 in the global scope. */
7475 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7476 built_actual_name
!= NULL
,
7477 VAR_DOMAIN
, LOC_BLOCK
,
7478 &objfile
->global_psymbols
,
7479 addr
, cu
->language
, objfile
);
7483 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7484 built_actual_name
!= NULL
,
7485 VAR_DOMAIN
, LOC_BLOCK
,
7486 &objfile
->static_psymbols
,
7487 addr
, cu
->language
, objfile
);
7490 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7491 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
7493 case DW_TAG_constant
:
7495 std::vector
<partial_symbol
*> *list
;
7497 if (pdi
->is_external
)
7498 list
= &objfile
->global_psymbols
;
7500 list
= &objfile
->static_psymbols
;
7501 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7502 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
7503 list
, 0, cu
->language
, objfile
);
7506 case DW_TAG_variable
:
7508 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7512 && !dwarf2_per_objfile
->has_section_at_zero
)
7514 /* A global or static variable may also have been stripped
7515 out by the linker if unused, in which case its address
7516 will be nullified; do not add such variables into partial
7517 symbol table then. */
7519 else if (pdi
->is_external
)
7522 Don't enter into the minimal symbol tables as there is
7523 a minimal symbol table entry from the ELF symbols already.
7524 Enter into partial symbol table if it has a location
7525 descriptor or a type.
7526 If the location descriptor is missing, new_symbol will create
7527 a LOC_UNRESOLVED symbol, the address of the variable will then
7528 be determined from the minimal symbol table whenever the variable
7530 The address for the partial symbol table entry is not
7531 used by GDB, but it comes in handy for debugging partial symbol
7534 if (pdi
->d
.locdesc
|| pdi
->has_type
)
7535 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7536 built_actual_name
!= NULL
,
7537 VAR_DOMAIN
, LOC_STATIC
,
7538 &objfile
->global_psymbols
,
7540 cu
->language
, objfile
);
7544 int has_loc
= pdi
->d
.locdesc
!= NULL
;
7546 /* Static Variable. Skip symbols whose value we cannot know (those
7547 without location descriptors or constant values). */
7548 if (!has_loc
&& !pdi
->has_const_value
)
7550 xfree (built_actual_name
);
7554 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7555 built_actual_name
!= NULL
,
7556 VAR_DOMAIN
, LOC_STATIC
,
7557 &objfile
->static_psymbols
,
7558 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
7559 cu
->language
, objfile
);
7562 case DW_TAG_typedef
:
7563 case DW_TAG_base_type
:
7564 case DW_TAG_subrange_type
:
7565 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7566 built_actual_name
!= NULL
,
7567 VAR_DOMAIN
, LOC_TYPEDEF
,
7568 &objfile
->static_psymbols
,
7569 0, cu
->language
, objfile
);
7571 case DW_TAG_imported_declaration
:
7572 case DW_TAG_namespace
:
7573 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7574 built_actual_name
!= NULL
,
7575 VAR_DOMAIN
, LOC_TYPEDEF
,
7576 &objfile
->global_psymbols
,
7577 0, cu
->language
, objfile
);
7580 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7581 built_actual_name
!= NULL
,
7582 MODULE_DOMAIN
, LOC_TYPEDEF
,
7583 &objfile
->global_psymbols
,
7584 0, cu
->language
, objfile
);
7586 case DW_TAG_class_type
:
7587 case DW_TAG_interface_type
:
7588 case DW_TAG_structure_type
:
7589 case DW_TAG_union_type
:
7590 case DW_TAG_enumeration_type
:
7591 /* Skip external references. The DWARF standard says in the section
7592 about "Structure, Union, and Class Type Entries": "An incomplete
7593 structure, union or class type is represented by a structure,
7594 union or class entry that does not have a byte size attribute
7595 and that has a DW_AT_declaration attribute." */
7596 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
7598 xfree (built_actual_name
);
7602 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
7603 static vs. global. */
7604 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7605 built_actual_name
!= NULL
,
7606 STRUCT_DOMAIN
, LOC_TYPEDEF
,
7607 cu
->language
== language_cplus
7608 ? &objfile
->global_psymbols
7609 : &objfile
->static_psymbols
,
7610 0, cu
->language
, objfile
);
7613 case DW_TAG_enumerator
:
7614 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7615 built_actual_name
!= NULL
,
7616 VAR_DOMAIN
, LOC_CONST
,
7617 cu
->language
== language_cplus
7618 ? &objfile
->global_psymbols
7619 : &objfile
->static_psymbols
,
7620 0, cu
->language
, objfile
);
7626 xfree (built_actual_name
);
7629 /* Read a partial die corresponding to a namespace; also, add a symbol
7630 corresponding to that namespace to the symbol table. NAMESPACE is
7631 the name of the enclosing namespace. */
7634 add_partial_namespace (struct partial_die_info
*pdi
,
7635 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7636 int set_addrmap
, struct dwarf2_cu
*cu
)
7638 /* Add a symbol for the namespace. */
7640 add_partial_symbol (pdi
, cu
);
7642 /* Now scan partial symbols in that namespace. */
7644 if (pdi
->has_children
)
7645 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7648 /* Read a partial die corresponding to a Fortran module. */
7651 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
7652 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
7654 /* Add a symbol for the namespace. */
7656 add_partial_symbol (pdi
, cu
);
7658 /* Now scan partial symbols in that module. */
7660 if (pdi
->has_children
)
7661 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7664 /* Read a partial die corresponding to a subprogram and create a partial
7665 symbol for that subprogram. When the CU language allows it, this
7666 routine also defines a partial symbol for each nested subprogram
7667 that this subprogram contains. If SET_ADDRMAP is true, record the
7668 covered ranges in the addrmap. Set *LOWPC and *HIGHPC to the lowest
7669 and highest PC values found in PDI.
7671 PDI may also be a lexical block, in which case we simply search
7672 recursively for subprograms defined inside that lexical block.
7673 Again, this is only performed when the CU language allows this
7674 type of definitions. */
7677 add_partial_subprogram (struct partial_die_info
*pdi
,
7678 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7679 int set_addrmap
, struct dwarf2_cu
*cu
)
7681 if (pdi
->tag
== DW_TAG_subprogram
)
7683 if (pdi
->has_pc_info
)
7685 if (pdi
->lowpc
< *lowpc
)
7686 *lowpc
= pdi
->lowpc
;
7687 if (pdi
->highpc
> *highpc
)
7688 *highpc
= pdi
->highpc
;
7691 struct objfile
*objfile
= cu
->objfile
;
7692 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7697 baseaddr
= ANOFFSET (objfile
->section_offsets
,
7698 SECT_OFF_TEXT (objfile
));
7699 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7700 pdi
->lowpc
+ baseaddr
);
7701 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7702 pdi
->highpc
+ baseaddr
);
7703 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
7704 cu
->per_cu
->v
.psymtab
);
7708 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
7710 if (!pdi
->is_declaration
)
7711 /* Ignore subprogram DIEs that do not have a name, they are
7712 illegal. Do not emit a complaint at this point, we will
7713 do so when we convert this psymtab into a symtab. */
7715 add_partial_symbol (pdi
, cu
);
7719 if (! pdi
->has_children
)
7722 if (cu
->language
== language_ada
)
7724 pdi
= pdi
->die_child
;
7727 fixup_partial_die (pdi
, cu
);
7728 if (pdi
->tag
== DW_TAG_subprogram
7729 || pdi
->tag
== DW_TAG_lexical_block
)
7730 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7731 pdi
= pdi
->die_sibling
;
7736 /* Read a partial die corresponding to an enumeration type. */
7739 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
7740 struct dwarf2_cu
*cu
)
7742 struct partial_die_info
*pdi
;
7744 if (enum_pdi
->name
!= NULL
)
7745 add_partial_symbol (enum_pdi
, cu
);
7747 pdi
= enum_pdi
->die_child
;
7750 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
7751 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
7753 add_partial_symbol (pdi
, cu
);
7754 pdi
= pdi
->die_sibling
;
7758 /* Return the initial uleb128 in the die at INFO_PTR. */
7761 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
7763 unsigned int bytes_read
;
7765 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7768 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
7769 Return the corresponding abbrev, or NULL if the number is zero (indicating
7770 an empty DIE). In either case *BYTES_READ will be set to the length of
7771 the initial number. */
7773 static struct abbrev_info
*
7774 peek_die_abbrev (const gdb_byte
*info_ptr
, unsigned int *bytes_read
,
7775 struct dwarf2_cu
*cu
)
7777 bfd
*abfd
= cu
->objfile
->obfd
;
7778 unsigned int abbrev_number
;
7779 struct abbrev_info
*abbrev
;
7781 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
7783 if (abbrev_number
== 0)
7786 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
7789 error (_("Dwarf Error: Could not find abbrev number %d in %s"
7790 " at offset 0x%x [in module %s]"),
7791 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
7792 to_underlying (cu
->header
.sect_off
), bfd_get_filename (abfd
));
7798 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7799 Returns a pointer to the end of a series of DIEs, terminated by an empty
7800 DIE. Any children of the skipped DIEs will also be skipped. */
7802 static const gdb_byte
*
7803 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
7805 struct dwarf2_cu
*cu
= reader
->cu
;
7806 struct abbrev_info
*abbrev
;
7807 unsigned int bytes_read
;
7811 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
7813 return info_ptr
+ bytes_read
;
7815 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
7819 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7820 INFO_PTR should point just after the initial uleb128 of a DIE, and the
7821 abbrev corresponding to that skipped uleb128 should be passed in
7822 ABBREV. Returns a pointer to this DIE's sibling, skipping any
7825 static const gdb_byte
*
7826 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
7827 struct abbrev_info
*abbrev
)
7829 unsigned int bytes_read
;
7830 struct attribute attr
;
7831 bfd
*abfd
= reader
->abfd
;
7832 struct dwarf2_cu
*cu
= reader
->cu
;
7833 const gdb_byte
*buffer
= reader
->buffer
;
7834 const gdb_byte
*buffer_end
= reader
->buffer_end
;
7835 unsigned int form
, i
;
7837 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
7839 /* The only abbrev we care about is DW_AT_sibling. */
7840 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
7842 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
7843 if (attr
.form
== DW_FORM_ref_addr
)
7844 complaint (&symfile_complaints
,
7845 _("ignoring absolute DW_AT_sibling"));
7848 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
7849 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
7851 if (sibling_ptr
< info_ptr
)
7852 complaint (&symfile_complaints
,
7853 _("DW_AT_sibling points backwards"));
7854 else if (sibling_ptr
> reader
->buffer_end
)
7855 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
7861 /* If it isn't DW_AT_sibling, skip this attribute. */
7862 form
= abbrev
->attrs
[i
].form
;
7866 case DW_FORM_ref_addr
:
7867 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
7868 and later it is offset sized. */
7869 if (cu
->header
.version
== 2)
7870 info_ptr
+= cu
->header
.addr_size
;
7872 info_ptr
+= cu
->header
.offset_size
;
7874 case DW_FORM_GNU_ref_alt
:
7875 info_ptr
+= cu
->header
.offset_size
;
7878 info_ptr
+= cu
->header
.addr_size
;
7885 case DW_FORM_flag_present
:
7886 case DW_FORM_implicit_const
:
7898 case DW_FORM_ref_sig8
:
7901 case DW_FORM_data16
:
7904 case DW_FORM_string
:
7905 read_direct_string (abfd
, info_ptr
, &bytes_read
);
7906 info_ptr
+= bytes_read
;
7908 case DW_FORM_sec_offset
:
7910 case DW_FORM_GNU_strp_alt
:
7911 info_ptr
+= cu
->header
.offset_size
;
7913 case DW_FORM_exprloc
:
7915 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7916 info_ptr
+= bytes_read
;
7918 case DW_FORM_block1
:
7919 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
7921 case DW_FORM_block2
:
7922 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
7924 case DW_FORM_block4
:
7925 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
7929 case DW_FORM_ref_udata
:
7930 case DW_FORM_GNU_addr_index
:
7931 case DW_FORM_GNU_str_index
:
7932 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
7934 case DW_FORM_indirect
:
7935 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7936 info_ptr
+= bytes_read
;
7937 /* We need to continue parsing from here, so just go back to
7939 goto skip_attribute
;
7942 error (_("Dwarf Error: Cannot handle %s "
7943 "in DWARF reader [in module %s]"),
7944 dwarf_form_name (form
),
7945 bfd_get_filename (abfd
));
7949 if (abbrev
->has_children
)
7950 return skip_children (reader
, info_ptr
);
7955 /* Locate ORIG_PDI's sibling.
7956 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
7958 static const gdb_byte
*
7959 locate_pdi_sibling (const struct die_reader_specs
*reader
,
7960 struct partial_die_info
*orig_pdi
,
7961 const gdb_byte
*info_ptr
)
7963 /* Do we know the sibling already? */
7965 if (orig_pdi
->sibling
)
7966 return orig_pdi
->sibling
;
7968 /* Are there any children to deal with? */
7970 if (!orig_pdi
->has_children
)
7973 /* Skip the children the long way. */
7975 return skip_children (reader
, info_ptr
);
7978 /* Expand this partial symbol table into a full symbol table. SELF is
7982 dwarf2_read_symtab (struct partial_symtab
*self
,
7983 struct objfile
*objfile
)
7987 warning (_("bug: psymtab for %s is already read in."),
7994 printf_filtered (_("Reading in symbols for %s..."),
7996 gdb_flush (gdb_stdout
);
7999 /* Restore our global data. */
8001 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
8002 dwarf2_objfile_data_key
);
8004 /* If this psymtab is constructed from a debug-only objfile, the
8005 has_section_at_zero flag will not necessarily be correct. We
8006 can get the correct value for this flag by looking at the data
8007 associated with the (presumably stripped) associated objfile. */
8008 if (objfile
->separate_debug_objfile_backlink
)
8010 struct dwarf2_per_objfile
*dpo_backlink
8011 = ((struct dwarf2_per_objfile
*)
8012 objfile_data (objfile
->separate_debug_objfile_backlink
,
8013 dwarf2_objfile_data_key
));
8015 dwarf2_per_objfile
->has_section_at_zero
8016 = dpo_backlink
->has_section_at_zero
;
8019 dwarf2_per_objfile
->reading_partial_symbols
= 0;
8021 psymtab_to_symtab_1 (self
);
8023 /* Finish up the debug error message. */
8025 printf_filtered (_("done.\n"));
8028 process_cu_includes ();
8031 /* Reading in full CUs. */
8033 /* Add PER_CU to the queue. */
8036 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8037 enum language pretend_language
)
8039 struct dwarf2_queue_item
*item
;
8042 item
= XNEW (struct dwarf2_queue_item
);
8043 item
->per_cu
= per_cu
;
8044 item
->pretend_language
= pretend_language
;
8047 if (dwarf2_queue
== NULL
)
8048 dwarf2_queue
= item
;
8050 dwarf2_queue_tail
->next
= item
;
8052 dwarf2_queue_tail
= item
;
8055 /* If PER_CU is not yet queued, add it to the queue.
8056 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8058 The result is non-zero if PER_CU was queued, otherwise the result is zero
8059 meaning either PER_CU is already queued or it is already loaded.
8061 N.B. There is an invariant here that if a CU is queued then it is loaded.
8062 The caller is required to load PER_CU if we return non-zero. */
8065 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8066 struct dwarf2_per_cu_data
*per_cu
,
8067 enum language pretend_language
)
8069 /* We may arrive here during partial symbol reading, if we need full
8070 DIEs to process an unusual case (e.g. template arguments). Do
8071 not queue PER_CU, just tell our caller to load its DIEs. */
8072 if (dwarf2_per_objfile
->reading_partial_symbols
)
8074 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8079 /* Mark the dependence relation so that we don't flush PER_CU
8081 if (dependent_cu
!= NULL
)
8082 dwarf2_add_dependence (dependent_cu
, per_cu
);
8084 /* If it's already on the queue, we have nothing to do. */
8088 /* If the compilation unit is already loaded, just mark it as
8090 if (per_cu
->cu
!= NULL
)
8092 per_cu
->cu
->last_used
= 0;
8096 /* Add it to the queue. */
8097 queue_comp_unit (per_cu
, pretend_language
);
8102 /* Process the queue. */
8105 process_queue (void)
8107 struct dwarf2_queue_item
*item
, *next_item
;
8109 if (dwarf_read_debug
)
8111 fprintf_unfiltered (gdb_stdlog
,
8112 "Expanding one or more symtabs of objfile %s ...\n",
8113 objfile_name (dwarf2_per_objfile
->objfile
));
8116 /* The queue starts out with one item, but following a DIE reference
8117 may load a new CU, adding it to the end of the queue. */
8118 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
8120 if ((dwarf2_per_objfile
->using_index
8121 ? !item
->per_cu
->v
.quick
->compunit_symtab
8122 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
8123 /* Skip dummy CUs. */
8124 && item
->per_cu
->cu
!= NULL
)
8126 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
8127 unsigned int debug_print_threshold
;
8130 if (per_cu
->is_debug_types
)
8132 struct signatured_type
*sig_type
=
8133 (struct signatured_type
*) per_cu
;
8135 sprintf (buf
, "TU %s at offset 0x%x",
8136 hex_string (sig_type
->signature
),
8137 to_underlying (per_cu
->sect_off
));
8138 /* There can be 100s of TUs.
8139 Only print them in verbose mode. */
8140 debug_print_threshold
= 2;
8144 sprintf (buf
, "CU at offset 0x%x",
8145 to_underlying (per_cu
->sect_off
));
8146 debug_print_threshold
= 1;
8149 if (dwarf_read_debug
>= debug_print_threshold
)
8150 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8152 if (per_cu
->is_debug_types
)
8153 process_full_type_unit (per_cu
, item
->pretend_language
);
8155 process_full_comp_unit (per_cu
, item
->pretend_language
);
8157 if (dwarf_read_debug
>= debug_print_threshold
)
8158 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8161 item
->per_cu
->queued
= 0;
8162 next_item
= item
->next
;
8166 dwarf2_queue_tail
= NULL
;
8168 if (dwarf_read_debug
)
8170 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8171 objfile_name (dwarf2_per_objfile
->objfile
));
8175 /* Free all allocated queue entries. This function only releases anything if
8176 an error was thrown; if the queue was processed then it would have been
8177 freed as we went along. */
8180 dwarf2_release_queue (void *dummy
)
8182 struct dwarf2_queue_item
*item
, *last
;
8184 item
= dwarf2_queue
;
8187 /* Anything still marked queued is likely to be in an
8188 inconsistent state, so discard it. */
8189 if (item
->per_cu
->queued
)
8191 if (item
->per_cu
->cu
!= NULL
)
8192 free_one_cached_comp_unit (item
->per_cu
);
8193 item
->per_cu
->queued
= 0;
8201 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
8204 /* Read in full symbols for PST, and anything it depends on. */
8207 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
8209 struct dwarf2_per_cu_data
*per_cu
;
8215 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
8216 if (!pst
->dependencies
[i
]->readin
8217 && pst
->dependencies
[i
]->user
== NULL
)
8219 /* Inform about additional files that need to be read in. */
8222 /* FIXME: i18n: Need to make this a single string. */
8223 fputs_filtered (" ", gdb_stdout
);
8225 fputs_filtered ("and ", gdb_stdout
);
8227 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
8228 wrap_here (""); /* Flush output. */
8229 gdb_flush (gdb_stdout
);
8231 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
8234 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
8238 /* It's an include file, no symbols to read for it.
8239 Everything is in the parent symtab. */
8244 dw2_do_instantiate_symtab (per_cu
);
8247 /* Trivial hash function for die_info: the hash value of a DIE
8248 is its offset in .debug_info for this objfile. */
8251 die_hash (const void *item
)
8253 const struct die_info
*die
= (const struct die_info
*) item
;
8255 return to_underlying (die
->sect_off
);
8258 /* Trivial comparison function for die_info structures: two DIEs
8259 are equal if they have the same offset. */
8262 die_eq (const void *item_lhs
, const void *item_rhs
)
8264 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8265 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8267 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8270 /* die_reader_func for load_full_comp_unit.
8271 This is identical to read_signatured_type_reader,
8272 but is kept separate for now. */
8275 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
8276 const gdb_byte
*info_ptr
,
8277 struct die_info
*comp_unit_die
,
8281 struct dwarf2_cu
*cu
= reader
->cu
;
8282 enum language
*language_ptr
= (enum language
*) data
;
8284 gdb_assert (cu
->die_hash
== NULL
);
8286 htab_create_alloc_ex (cu
->header
.length
/ 12,
8290 &cu
->comp_unit_obstack
,
8291 hashtab_obstack_allocate
,
8292 dummy_obstack_deallocate
);
8295 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
8296 &info_ptr
, comp_unit_die
);
8297 cu
->dies
= comp_unit_die
;
8298 /* comp_unit_die is not stored in die_hash, no need. */
8300 /* We try not to read any attributes in this function, because not
8301 all CUs needed for references have been loaded yet, and symbol
8302 table processing isn't initialized. But we have to set the CU language,
8303 or we won't be able to build types correctly.
8304 Similarly, if we do not read the producer, we can not apply
8305 producer-specific interpretation. */
8306 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
8309 /* Load the DIEs associated with PER_CU into memory. */
8312 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8313 enum language pretend_language
)
8315 gdb_assert (! this_cu
->is_debug_types
);
8317 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
8318 load_full_comp_unit_reader
, &pretend_language
);
8321 /* Add a DIE to the delayed physname list. */
8324 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8325 const char *name
, struct die_info
*die
,
8326 struct dwarf2_cu
*cu
)
8328 struct delayed_method_info mi
;
8330 mi
.fnfield_index
= fnfield_index
;
8334 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
8337 /* A cleanup for freeing the delayed method list. */
8340 free_delayed_list (void *ptr
)
8342 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
8343 if (cu
->method_list
!= NULL
)
8345 VEC_free (delayed_method_info
, cu
->method_list
);
8346 cu
->method_list
= NULL
;
8350 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8351 "const" / "volatile". If so, decrements LEN by the length of the
8352 modifier and return true. Otherwise return false. */
8356 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8358 size_t mod_len
= sizeof (mod
) - 1;
8359 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8367 /* Compute the physnames of any methods on the CU's method list.
8369 The computation of method physnames is delayed in order to avoid the
8370 (bad) condition that one of the method's formal parameters is of an as yet
8374 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8377 struct delayed_method_info
*mi
;
8379 /* Only C++ delays computing physnames. */
8380 if (VEC_empty (delayed_method_info
, cu
->method_list
))
8382 gdb_assert (cu
->language
== language_cplus
);
8384 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
8386 const char *physname
;
8387 struct fn_fieldlist
*fn_flp
8388 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
8389 physname
= dwarf2_physname (mi
->name
, mi
->die
, cu
);
8390 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
->index
)
8391 = physname
? physname
: "";
8393 /* Since there's no tag to indicate whether a method is a
8394 const/volatile overload, extract that information out of the
8396 if (physname
!= NULL
)
8398 size_t len
= strlen (physname
);
8402 if (physname
[len
] == ')') /* shortcut */
8404 else if (check_modifier (physname
, len
, " const"))
8405 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
->index
) = 1;
8406 else if (check_modifier (physname
, len
, " volatile"))
8407 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
->index
) = 1;
8415 /* Go objects should be embedded in a DW_TAG_module DIE,
8416 and it's not clear if/how imported objects will appear.
8417 To keep Go support simple until that's worked out,
8418 go back through what we've read and create something usable.
8419 We could do this while processing each DIE, and feels kinda cleaner,
8420 but that way is more invasive.
8421 This is to, for example, allow the user to type "p var" or "b main"
8422 without having to specify the package name, and allow lookups
8423 of module.object to work in contexts that use the expression
8427 fixup_go_packaging (struct dwarf2_cu
*cu
)
8429 char *package_name
= NULL
;
8430 struct pending
*list
;
8433 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
8435 for (i
= 0; i
< list
->nsyms
; ++i
)
8437 struct symbol
*sym
= list
->symbol
[i
];
8439 if (SYMBOL_LANGUAGE (sym
) == language_go
8440 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8442 char *this_package_name
= go_symbol_package_name (sym
);
8444 if (this_package_name
== NULL
)
8446 if (package_name
== NULL
)
8447 package_name
= this_package_name
;
8450 if (strcmp (package_name
, this_package_name
) != 0)
8451 complaint (&symfile_complaints
,
8452 _("Symtab %s has objects from two different Go packages: %s and %s"),
8453 (symbol_symtab (sym
) != NULL
8454 ? symtab_to_filename_for_display
8455 (symbol_symtab (sym
))
8456 : objfile_name (cu
->objfile
)),
8457 this_package_name
, package_name
);
8458 xfree (this_package_name
);
8464 if (package_name
!= NULL
)
8466 struct objfile
*objfile
= cu
->objfile
;
8467 const char *saved_package_name
8468 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8470 strlen (package_name
));
8471 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8472 saved_package_name
);
8475 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8477 sym
= allocate_symbol (objfile
);
8478 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
8479 SYMBOL_SET_NAMES (sym
, saved_package_name
,
8480 strlen (saved_package_name
), 0, objfile
);
8481 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8482 e.g., "main" finds the "main" module and not C's main(). */
8483 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8484 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
8485 SYMBOL_TYPE (sym
) = type
;
8487 add_symbol_to_list (sym
, &global_symbols
);
8489 xfree (package_name
);
8493 /* Return the symtab for PER_CU. This works properly regardless of
8494 whether we're using the index or psymtabs. */
8496 static struct compunit_symtab
*
8497 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
8499 return (dwarf2_per_objfile
->using_index
8500 ? per_cu
->v
.quick
->compunit_symtab
8501 : per_cu
->v
.psymtab
->compunit_symtab
);
8504 /* A helper function for computing the list of all symbol tables
8505 included by PER_CU. */
8508 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
8509 htab_t all_children
, htab_t all_type_symtabs
,
8510 struct dwarf2_per_cu_data
*per_cu
,
8511 struct compunit_symtab
*immediate_parent
)
8515 struct compunit_symtab
*cust
;
8516 struct dwarf2_per_cu_data
*iter
;
8518 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
8521 /* This inclusion and its children have been processed. */
8526 /* Only add a CU if it has a symbol table. */
8527 cust
= get_compunit_symtab (per_cu
);
8530 /* If this is a type unit only add its symbol table if we haven't
8531 seen it yet (type unit per_cu's can share symtabs). */
8532 if (per_cu
->is_debug_types
)
8534 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
8538 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
8539 if (cust
->user
== NULL
)
8540 cust
->user
= immediate_parent
;
8545 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
8546 if (cust
->user
== NULL
)
8547 cust
->user
= immediate_parent
;
8552 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
8555 recursively_compute_inclusions (result
, all_children
,
8556 all_type_symtabs
, iter
, cust
);
8560 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
8564 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
8566 gdb_assert (! per_cu
->is_debug_types
);
8568 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
8571 struct dwarf2_per_cu_data
*per_cu_iter
;
8572 struct compunit_symtab
*compunit_symtab_iter
;
8573 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
8574 htab_t all_children
, all_type_symtabs
;
8575 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
8577 /* If we don't have a symtab, we can just skip this case. */
8581 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
8582 NULL
, xcalloc
, xfree
);
8583 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
8584 NULL
, xcalloc
, xfree
);
8587 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
8591 recursively_compute_inclusions (&result_symtabs
, all_children
,
8592 all_type_symtabs
, per_cu_iter
,
8596 /* Now we have a transitive closure of all the included symtabs. */
8597 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
8599 = XOBNEWVEC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
8600 struct compunit_symtab
*, len
+ 1);
8602 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
8603 compunit_symtab_iter
);
8605 cust
->includes
[ix
] = compunit_symtab_iter
;
8606 cust
->includes
[len
] = NULL
;
8608 VEC_free (compunit_symtab_ptr
, result_symtabs
);
8609 htab_delete (all_children
);
8610 htab_delete (all_type_symtabs
);
8614 /* Compute the 'includes' field for the symtabs of all the CUs we just
8618 process_cu_includes (void)
8621 struct dwarf2_per_cu_data
*iter
;
8624 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
8628 if (! iter
->is_debug_types
)
8629 compute_compunit_symtab_includes (iter
);
8632 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
8635 /* Generate full symbol information for PER_CU, whose DIEs have
8636 already been loaded into memory. */
8639 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8640 enum language pretend_language
)
8642 struct dwarf2_cu
*cu
= per_cu
->cu
;
8643 struct objfile
*objfile
= per_cu
->objfile
;
8644 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8645 CORE_ADDR lowpc
, highpc
;
8646 struct compunit_symtab
*cust
;
8647 struct cleanup
*delayed_list_cleanup
;
8649 struct block
*static_block
;
8652 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8655 scoped_free_pendings free_pending
;
8656 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8658 cu
->list_in_scope
= &file_symbols
;
8660 cu
->language
= pretend_language
;
8661 cu
->language_defn
= language_def (cu
->language
);
8663 /* Do line number decoding in read_file_scope () */
8664 process_die (cu
->dies
, cu
);
8666 /* For now fudge the Go package. */
8667 if (cu
->language
== language_go
)
8668 fixup_go_packaging (cu
);
8670 /* Now that we have processed all the DIEs in the CU, all the types
8671 should be complete, and it should now be safe to compute all of the
8673 compute_delayed_physnames (cu
);
8674 do_cleanups (delayed_list_cleanup
);
8676 /* Some compilers don't define a DW_AT_high_pc attribute for the
8677 compilation unit. If the DW_AT_high_pc is missing, synthesize
8678 it, by scanning the DIE's below the compilation unit. */
8679 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
8681 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
8682 static_block
= end_symtab_get_static_block (addr
, 0, 1);
8684 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
8685 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
8686 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
8687 addrmap to help ensure it has an accurate map of pc values belonging to
8689 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
8691 cust
= end_symtab_from_static_block (static_block
,
8692 SECT_OFF_TEXT (objfile
), 0);
8696 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
8698 /* Set symtab language to language from DW_AT_language. If the
8699 compilation is from a C file generated by language preprocessors, do
8700 not set the language if it was already deduced by start_subfile. */
8701 if (!(cu
->language
== language_c
8702 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
8703 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8705 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
8706 produce DW_AT_location with location lists but it can be possibly
8707 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
8708 there were bugs in prologue debug info, fixed later in GCC-4.5
8709 by "unwind info for epilogues" patch (which is not directly related).
8711 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
8712 needed, it would be wrong due to missing DW_AT_producer there.
8714 Still one can confuse GDB by using non-standard GCC compilation
8715 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
8717 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
8718 cust
->locations_valid
= 1;
8720 if (gcc_4_minor
>= 5)
8721 cust
->epilogue_unwind_valid
= 1;
8723 cust
->call_site_htab
= cu
->call_site_htab
;
8726 if (dwarf2_per_objfile
->using_index
)
8727 per_cu
->v
.quick
->compunit_symtab
= cust
;
8730 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8731 pst
->compunit_symtab
= cust
;
8735 /* Push it for inclusion processing later. */
8736 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
8739 /* Generate full symbol information for type unit PER_CU, whose DIEs have
8740 already been loaded into memory. */
8743 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
8744 enum language pretend_language
)
8746 struct dwarf2_cu
*cu
= per_cu
->cu
;
8747 struct objfile
*objfile
= per_cu
->objfile
;
8748 struct compunit_symtab
*cust
;
8749 struct cleanup
*delayed_list_cleanup
;
8750 struct signatured_type
*sig_type
;
8752 gdb_assert (per_cu
->is_debug_types
);
8753 sig_type
= (struct signatured_type
*) per_cu
;
8756 scoped_free_pendings free_pending
;
8757 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8759 cu
->list_in_scope
= &file_symbols
;
8761 cu
->language
= pretend_language
;
8762 cu
->language_defn
= language_def (cu
->language
);
8764 /* The symbol tables are set up in read_type_unit_scope. */
8765 process_die (cu
->dies
, cu
);
8767 /* For now fudge the Go package. */
8768 if (cu
->language
== language_go
)
8769 fixup_go_packaging (cu
);
8771 /* Now that we have processed all the DIEs in the CU, all the types
8772 should be complete, and it should now be safe to compute all of the
8774 compute_delayed_physnames (cu
);
8775 do_cleanups (delayed_list_cleanup
);
8777 /* TUs share symbol tables.
8778 If this is the first TU to use this symtab, complete the construction
8779 of it with end_expandable_symtab. Otherwise, complete the addition of
8780 this TU's symbols to the existing symtab. */
8781 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
8783 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
8784 sig_type
->type_unit_group
->compunit_symtab
= cust
;
8788 /* Set symtab language to language from DW_AT_language. If the
8789 compilation is from a C file generated by language preprocessors,
8790 do not set the language if it was already deduced by
8792 if (!(cu
->language
== language_c
8793 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
8794 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8799 augment_type_symtab ();
8800 cust
= sig_type
->type_unit_group
->compunit_symtab
;
8803 if (dwarf2_per_objfile
->using_index
)
8804 per_cu
->v
.quick
->compunit_symtab
= cust
;
8807 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8808 pst
->compunit_symtab
= cust
;
8813 /* Process an imported unit DIE. */
8816 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8818 struct attribute
*attr
;
8820 /* For now we don't handle imported units in type units. */
8821 if (cu
->per_cu
->is_debug_types
)
8823 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8824 " supported in type units [in module %s]"),
8825 objfile_name (cu
->objfile
));
8828 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8831 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
8832 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
8833 dwarf2_per_cu_data
*per_cu
8834 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, cu
->objfile
);
8836 /* If necessary, add it to the queue and load its DIEs. */
8837 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
8838 load_full_comp_unit (per_cu
, cu
->language
);
8840 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8845 /* RAII object that represents a process_die scope: i.e.,
8846 starts/finishes processing a DIE. */
8847 class process_die_scope
8850 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
8851 : m_die (die
), m_cu (cu
)
8853 /* We should only be processing DIEs not already in process. */
8854 gdb_assert (!m_die
->in_process
);
8855 m_die
->in_process
= true;
8858 ~process_die_scope ()
8860 m_die
->in_process
= false;
8862 /* If we're done processing the DIE for the CU that owns the line
8863 header, we don't need the line header anymore. */
8864 if (m_cu
->line_header_die_owner
== m_die
)
8866 delete m_cu
->line_header
;
8867 m_cu
->line_header
= NULL
;
8868 m_cu
->line_header_die_owner
= NULL
;
8877 /* Process a die and its children. */
8880 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8882 process_die_scope
scope (die
, cu
);
8886 case DW_TAG_padding
:
8888 case DW_TAG_compile_unit
:
8889 case DW_TAG_partial_unit
:
8890 read_file_scope (die
, cu
);
8892 case DW_TAG_type_unit
:
8893 read_type_unit_scope (die
, cu
);
8895 case DW_TAG_subprogram
:
8896 case DW_TAG_inlined_subroutine
:
8897 read_func_scope (die
, cu
);
8899 case DW_TAG_lexical_block
:
8900 case DW_TAG_try_block
:
8901 case DW_TAG_catch_block
:
8902 read_lexical_block_scope (die
, cu
);
8904 case DW_TAG_call_site
:
8905 case DW_TAG_GNU_call_site
:
8906 read_call_site_scope (die
, cu
);
8908 case DW_TAG_class_type
:
8909 case DW_TAG_interface_type
:
8910 case DW_TAG_structure_type
:
8911 case DW_TAG_union_type
:
8912 process_structure_scope (die
, cu
);
8914 case DW_TAG_enumeration_type
:
8915 process_enumeration_scope (die
, cu
);
8918 /* These dies have a type, but processing them does not create
8919 a symbol or recurse to process the children. Therefore we can
8920 read them on-demand through read_type_die. */
8921 case DW_TAG_subroutine_type
:
8922 case DW_TAG_set_type
:
8923 case DW_TAG_array_type
:
8924 case DW_TAG_pointer_type
:
8925 case DW_TAG_ptr_to_member_type
:
8926 case DW_TAG_reference_type
:
8927 case DW_TAG_rvalue_reference_type
:
8928 case DW_TAG_string_type
:
8931 case DW_TAG_base_type
:
8932 case DW_TAG_subrange_type
:
8933 case DW_TAG_typedef
:
8934 /* Add a typedef symbol for the type definition, if it has a
8936 new_symbol (die
, read_type_die (die
, cu
), cu
);
8938 case DW_TAG_common_block
:
8939 read_common_block (die
, cu
);
8941 case DW_TAG_common_inclusion
:
8943 case DW_TAG_namespace
:
8944 cu
->processing_has_namespace_info
= 1;
8945 read_namespace (die
, cu
);
8948 cu
->processing_has_namespace_info
= 1;
8949 read_module (die
, cu
);
8951 case DW_TAG_imported_declaration
:
8952 cu
->processing_has_namespace_info
= 1;
8953 if (read_namespace_alias (die
, cu
))
8955 /* The declaration is not a global namespace alias: fall through. */
8956 case DW_TAG_imported_module
:
8957 cu
->processing_has_namespace_info
= 1;
8958 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
8959 || cu
->language
!= language_fortran
))
8960 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
8961 dwarf_tag_name (die
->tag
));
8962 read_import_statement (die
, cu
);
8965 case DW_TAG_imported_unit
:
8966 process_imported_unit_die (die
, cu
);
8970 new_symbol (die
, NULL
, cu
);
8975 /* DWARF name computation. */
8977 /* A helper function for dwarf2_compute_name which determines whether DIE
8978 needs to have the name of the scope prepended to the name listed in the
8982 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8984 struct attribute
*attr
;
8988 case DW_TAG_namespace
:
8989 case DW_TAG_typedef
:
8990 case DW_TAG_class_type
:
8991 case DW_TAG_interface_type
:
8992 case DW_TAG_structure_type
:
8993 case DW_TAG_union_type
:
8994 case DW_TAG_enumeration_type
:
8995 case DW_TAG_enumerator
:
8996 case DW_TAG_subprogram
:
8997 case DW_TAG_inlined_subroutine
:
8999 case DW_TAG_imported_declaration
:
9002 case DW_TAG_variable
:
9003 case DW_TAG_constant
:
9004 /* We only need to prefix "globally" visible variables. These include
9005 any variable marked with DW_AT_external or any variable that
9006 lives in a namespace. [Variables in anonymous namespaces
9007 require prefixing, but they are not DW_AT_external.] */
9009 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9011 struct dwarf2_cu
*spec_cu
= cu
;
9013 return die_needs_namespace (die_specification (die
, &spec_cu
),
9017 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9018 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9019 && die
->parent
->tag
!= DW_TAG_module
)
9021 /* A variable in a lexical block of some kind does not need a
9022 namespace, even though in C++ such variables may be external
9023 and have a mangled name. */
9024 if (die
->parent
->tag
== DW_TAG_lexical_block
9025 || die
->parent
->tag
== DW_TAG_try_block
9026 || die
->parent
->tag
== DW_TAG_catch_block
9027 || die
->parent
->tag
== DW_TAG_subprogram
)
9036 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9037 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9038 defined for the given DIE. */
9040 static struct attribute
*
9041 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9043 struct attribute
*attr
;
9045 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9047 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9052 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9053 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9054 defined for the given DIE. */
9057 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9059 const char *linkage_name
;
9061 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9062 if (linkage_name
== NULL
)
9063 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9065 return linkage_name
;
9068 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9069 compute the physname for the object, which include a method's:
9070 - formal parameters (C++),
9071 - receiver type (Go),
9073 The term "physname" is a bit confusing.
9074 For C++, for example, it is the demangled name.
9075 For Go, for example, it's the mangled name.
9077 For Ada, return the DIE's linkage name rather than the fully qualified
9078 name. PHYSNAME is ignored..
9080 The result is allocated on the objfile_obstack and canonicalized. */
9083 dwarf2_compute_name (const char *name
,
9084 struct die_info
*die
, struct dwarf2_cu
*cu
,
9087 struct objfile
*objfile
= cu
->objfile
;
9090 name
= dwarf2_name (die
, cu
);
9092 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9093 but otherwise compute it by typename_concat inside GDB.
9094 FIXME: Actually this is not really true, or at least not always true.
9095 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
9096 Fortran names because there is no mangling standard. So new_symbol_full
9097 will set the demangled name to the result of dwarf2_full_name, and it is
9098 the demangled name that GDB uses if it exists. */
9099 if (cu
->language
== language_ada
9100 || (cu
->language
== language_fortran
&& physname
))
9102 /* For Ada unit, we prefer the linkage name over the name, as
9103 the former contains the exported name, which the user expects
9104 to be able to reference. Ideally, we want the user to be able
9105 to reference this entity using either natural or linkage name,
9106 but we haven't started looking at this enhancement yet. */
9107 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9109 if (linkage_name
!= NULL
)
9110 return linkage_name
;
9113 /* These are the only languages we know how to qualify names in. */
9115 && (cu
->language
== language_cplus
9116 || cu
->language
== language_fortran
|| cu
->language
== language_d
9117 || cu
->language
== language_rust
))
9119 if (die_needs_namespace (die
, cu
))
9123 const char *canonical_name
= NULL
;
9127 prefix
= determine_prefix (die
, cu
);
9128 if (*prefix
!= '\0')
9130 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
9133 buf
.puts (prefixed_name
);
9134 xfree (prefixed_name
);
9139 /* Template parameters may be specified in the DIE's DW_AT_name, or
9140 as children with DW_TAG_template_type_param or
9141 DW_TAG_value_type_param. If the latter, add them to the name
9142 here. If the name already has template parameters, then
9143 skip this step; some versions of GCC emit both, and
9144 it is more efficient to use the pre-computed name.
9146 Something to keep in mind about this process: it is very
9147 unlikely, or in some cases downright impossible, to produce
9148 something that will match the mangled name of a function.
9149 If the definition of the function has the same debug info,
9150 we should be able to match up with it anyway. But fallbacks
9151 using the minimal symbol, for instance to find a method
9152 implemented in a stripped copy of libstdc++, will not work.
9153 If we do not have debug info for the definition, we will have to
9154 match them up some other way.
9156 When we do name matching there is a related problem with function
9157 templates; two instantiated function templates are allowed to
9158 differ only by their return types, which we do not add here. */
9160 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
9162 struct attribute
*attr
;
9163 struct die_info
*child
;
9166 die
->building_fullname
= 1;
9168 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
9172 const gdb_byte
*bytes
;
9173 struct dwarf2_locexpr_baton
*baton
;
9176 if (child
->tag
!= DW_TAG_template_type_param
9177 && child
->tag
!= DW_TAG_template_value_param
)
9188 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
9191 complaint (&symfile_complaints
,
9192 _("template parameter missing DW_AT_type"));
9193 buf
.puts ("UNKNOWN_TYPE");
9196 type
= die_type (child
, cu
);
9198 if (child
->tag
== DW_TAG_template_type_param
)
9200 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
9204 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
9207 complaint (&symfile_complaints
,
9208 _("template parameter missing "
9209 "DW_AT_const_value"));
9210 buf
.puts ("UNKNOWN_VALUE");
9214 dwarf2_const_value_attr (attr
, type
, name
,
9215 &cu
->comp_unit_obstack
, cu
,
9216 &value
, &bytes
, &baton
);
9218 if (TYPE_NOSIGN (type
))
9219 /* GDB prints characters as NUMBER 'CHAR'. If that's
9220 changed, this can use value_print instead. */
9221 c_printchar (value
, type
, &buf
);
9224 struct value_print_options opts
;
9227 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
9231 else if (bytes
!= NULL
)
9233 v
= allocate_value (type
);
9234 memcpy (value_contents_writeable (v
), bytes
,
9235 TYPE_LENGTH (type
));
9238 v
= value_from_longest (type
, value
);
9240 /* Specify decimal so that we do not depend on
9242 get_formatted_print_options (&opts
, 'd');
9244 value_print (v
, &buf
, &opts
);
9250 die
->building_fullname
= 0;
9254 /* Close the argument list, with a space if necessary
9255 (nested templates). */
9256 if (!buf
.empty () && buf
.string ().back () == '>')
9263 /* For C++ methods, append formal parameter type
9264 information, if PHYSNAME. */
9266 if (physname
&& die
->tag
== DW_TAG_subprogram
9267 && cu
->language
== language_cplus
)
9269 struct type
*type
= read_type_die (die
, cu
);
9271 c_type_print_args (type
, &buf
, 1, cu
->language
,
9272 &type_print_raw_options
);
9274 if (cu
->language
== language_cplus
)
9276 /* Assume that an artificial first parameter is
9277 "this", but do not crash if it is not. RealView
9278 marks unnamed (and thus unused) parameters as
9279 artificial; there is no way to differentiate
9281 if (TYPE_NFIELDS (type
) > 0
9282 && TYPE_FIELD_ARTIFICIAL (type
, 0)
9283 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
9284 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
9286 buf
.puts (" const");
9290 const std::string
&intermediate_name
= buf
.string ();
9292 if (cu
->language
== language_cplus
)
9294 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
9295 &objfile
->per_bfd
->storage_obstack
);
9297 /* If we only computed INTERMEDIATE_NAME, or if
9298 INTERMEDIATE_NAME is already canonical, then we need to
9299 copy it to the appropriate obstack. */
9300 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
9301 name
= ((const char *)
9302 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
9303 intermediate_name
.c_str (),
9304 intermediate_name
.length ()));
9306 name
= canonical_name
;
9313 /* Return the fully qualified name of DIE, based on its DW_AT_name.
9314 If scope qualifiers are appropriate they will be added. The result
9315 will be allocated on the storage_obstack, or NULL if the DIE does
9316 not have a name. NAME may either be from a previous call to
9317 dwarf2_name or NULL.
9319 The output string will be canonicalized (if C++). */
9322 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
9324 return dwarf2_compute_name (name
, die
, cu
, 0);
9327 /* Construct a physname for the given DIE in CU. NAME may either be
9328 from a previous call to dwarf2_name or NULL. The result will be
9329 allocated on the objfile_objstack or NULL if the DIE does not have a
9332 The output string will be canonicalized (if C++). */
9335 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
9337 struct objfile
*objfile
= cu
->objfile
;
9338 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
9341 /* In this case dwarf2_compute_name is just a shortcut not building anything
9343 if (!die_needs_namespace (die
, cu
))
9344 return dwarf2_compute_name (name
, die
, cu
, 1);
9346 mangled
= dw2_linkage_name (die
, cu
);
9348 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9349 See https://github.com/rust-lang/rust/issues/32925. */
9350 if (cu
->language
== language_rust
&& mangled
!= NULL
9351 && strchr (mangled
, '{') != NULL
)
9354 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
9356 gdb::unique_xmalloc_ptr
<char> demangled
;
9357 if (mangled
!= NULL
)
9359 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
9360 type. It is easier for GDB users to search for such functions as
9361 `name(params)' than `long name(params)'. In such case the minimal
9362 symbol names do not match the full symbol names but for template
9363 functions there is never a need to look up their definition from their
9364 declaration so the only disadvantage remains the minimal symbol
9365 variant `long name(params)' does not have the proper inferior type.
9368 if (cu
->language
== language_go
)
9370 /* This is a lie, but we already lie to the caller new_symbol_full.
9371 new_symbol_full assumes we return the mangled name.
9372 This just undoes that lie until things are cleaned up. */
9376 demangled
.reset (gdb_demangle (mangled
,
9377 (DMGL_PARAMS
| DMGL_ANSI
9381 canon
= demangled
.get ();
9389 if (canon
== NULL
|| check_physname
)
9391 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
9393 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
9395 /* It may not mean a bug in GDB. The compiler could also
9396 compute DW_AT_linkage_name incorrectly. But in such case
9397 GDB would need to be bug-to-bug compatible. */
9399 complaint (&symfile_complaints
,
9400 _("Computed physname <%s> does not match demangled <%s> "
9401 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
9402 physname
, canon
, mangled
, to_underlying (die
->sect_off
),
9403 objfile_name (objfile
));
9405 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
9406 is available here - over computed PHYSNAME. It is safer
9407 against both buggy GDB and buggy compilers. */
9421 retval
= ((const char *)
9422 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
9423 retval
, strlen (retval
)));
9428 /* Inspect DIE in CU for a namespace alias. If one exists, record
9429 a new symbol for it.
9431 Returns 1 if a namespace alias was recorded, 0 otherwise. */
9434 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
9436 struct attribute
*attr
;
9438 /* If the die does not have a name, this is not a namespace
9440 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
9444 struct die_info
*d
= die
;
9445 struct dwarf2_cu
*imported_cu
= cu
;
9447 /* If the compiler has nested DW_AT_imported_declaration DIEs,
9448 keep inspecting DIEs until we hit the underlying import. */
9449 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
9450 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
9452 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
9456 d
= follow_die_ref (d
, attr
, &imported_cu
);
9457 if (d
->tag
!= DW_TAG_imported_declaration
)
9461 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
9463 complaint (&symfile_complaints
,
9464 _("DIE at 0x%x has too many recursively imported "
9465 "declarations"), to_underlying (d
->sect_off
));
9472 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9474 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
9475 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
9477 /* This declaration is a global namespace alias. Add
9478 a symbol for it whose type is the aliased namespace. */
9479 new_symbol (die
, type
, cu
);
9488 /* Return the using directives repository (global or local?) to use in the
9489 current context for LANGUAGE.
9491 For Ada, imported declarations can materialize renamings, which *may* be
9492 global. However it is impossible (for now?) in DWARF to distinguish
9493 "external" imported declarations and "static" ones. As all imported
9494 declarations seem to be static in all other languages, make them all CU-wide
9495 global only in Ada. */
9497 static struct using_direct
**
9498 using_directives (enum language language
)
9500 if (language
== language_ada
&& context_stack_depth
== 0)
9501 return &global_using_directives
;
9503 return &local_using_directives
;
9506 /* Read the import statement specified by the given die and record it. */
9509 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
9511 struct objfile
*objfile
= cu
->objfile
;
9512 struct attribute
*import_attr
;
9513 struct die_info
*imported_die
, *child_die
;
9514 struct dwarf2_cu
*imported_cu
;
9515 const char *imported_name
;
9516 const char *imported_name_prefix
;
9517 const char *canonical_name
;
9518 const char *import_alias
;
9519 const char *imported_declaration
= NULL
;
9520 const char *import_prefix
;
9521 std::vector
<const char *> excludes
;
9523 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9524 if (import_attr
== NULL
)
9526 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
9527 dwarf_tag_name (die
->tag
));
9532 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
9533 imported_name
= dwarf2_name (imported_die
, imported_cu
);
9534 if (imported_name
== NULL
)
9536 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
9538 The import in the following code:
9552 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
9553 <52> DW_AT_decl_file : 1
9554 <53> DW_AT_decl_line : 6
9555 <54> DW_AT_import : <0x75>
9556 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
9558 <5b> DW_AT_decl_file : 1
9559 <5c> DW_AT_decl_line : 2
9560 <5d> DW_AT_type : <0x6e>
9562 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
9563 <76> DW_AT_byte_size : 4
9564 <77> DW_AT_encoding : 5 (signed)
9566 imports the wrong die ( 0x75 instead of 0x58 ).
9567 This case will be ignored until the gcc bug is fixed. */
9571 /* Figure out the local name after import. */
9572 import_alias
= dwarf2_name (die
, cu
);
9574 /* Figure out where the statement is being imported to. */
9575 import_prefix
= determine_prefix (die
, cu
);
9577 /* Figure out what the scope of the imported die is and prepend it
9578 to the name of the imported die. */
9579 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
9581 if (imported_die
->tag
!= DW_TAG_namespace
9582 && imported_die
->tag
!= DW_TAG_module
)
9584 imported_declaration
= imported_name
;
9585 canonical_name
= imported_name_prefix
;
9587 else if (strlen (imported_name_prefix
) > 0)
9588 canonical_name
= obconcat (&objfile
->objfile_obstack
,
9589 imported_name_prefix
,
9590 (cu
->language
== language_d
? "." : "::"),
9591 imported_name
, (char *) NULL
);
9593 canonical_name
= imported_name
;
9595 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
9596 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
9597 child_die
= sibling_die (child_die
))
9599 /* DWARF-4: A Fortran use statement with a “rename list” may be
9600 represented by an imported module entry with an import attribute
9601 referring to the module and owned entries corresponding to those
9602 entities that are renamed as part of being imported. */
9604 if (child_die
->tag
!= DW_TAG_imported_declaration
)
9606 complaint (&symfile_complaints
,
9607 _("child DW_TAG_imported_declaration expected "
9608 "- DIE at 0x%x [in module %s]"),
9609 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
9613 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
9614 if (import_attr
== NULL
)
9616 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
9617 dwarf_tag_name (child_die
->tag
));
9622 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
9624 imported_name
= dwarf2_name (imported_die
, imported_cu
);
9625 if (imported_name
== NULL
)
9627 complaint (&symfile_complaints
,
9628 _("child DW_TAG_imported_declaration has unknown "
9629 "imported name - DIE at 0x%x [in module %s]"),
9630 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
9634 excludes
.push_back (imported_name
);
9636 process_die (child_die
, cu
);
9639 add_using_directive (using_directives (cu
->language
),
9643 imported_declaration
,
9646 &objfile
->objfile_obstack
);
9649 /* ICC<14 does not output the required DW_AT_declaration on incomplete
9650 types, but gives them a size of zero. Starting with version 14,
9651 ICC is compatible with GCC. */
9654 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
9656 if (!cu
->checked_producer
)
9657 check_producer (cu
);
9659 return cu
->producer_is_icc_lt_14
;
9662 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
9663 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
9664 this, it was first present in GCC release 4.3.0. */
9667 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
9669 if (!cu
->checked_producer
)
9670 check_producer (cu
);
9672 return cu
->producer_is_gcc_lt_4_3
;
9675 static file_and_directory
9676 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
9678 file_and_directory res
;
9680 /* Find the filename. Do not use dwarf2_name here, since the filename
9681 is not a source language identifier. */
9682 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
9683 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
9685 if (res
.comp_dir
== NULL
9686 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
9687 && IS_ABSOLUTE_PATH (res
.name
))
9689 res
.comp_dir_storage
= ldirname (res
.name
);
9690 if (!res
.comp_dir_storage
.empty ())
9691 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
9693 if (res
.comp_dir
!= NULL
)
9695 /* Irix 6.2 native cc prepends <machine>.: to the compilation
9696 directory, get rid of it. */
9697 const char *cp
= strchr (res
.comp_dir
, ':');
9699 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
9700 res
.comp_dir
= cp
+ 1;
9703 if (res
.name
== NULL
)
9704 res
.name
= "<unknown>";
9709 /* Handle DW_AT_stmt_list for a compilation unit.
9710 DIE is the DW_TAG_compile_unit die for CU.
9711 COMP_DIR is the compilation directory. LOWPC is passed to
9712 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
9715 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
9716 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
9718 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9719 struct attribute
*attr
;
9720 struct line_header line_header_local
;
9721 hashval_t line_header_local_hash
;
9726 gdb_assert (! cu
->per_cu
->is_debug_types
);
9728 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9732 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
9734 /* The line header hash table is only created if needed (it exists to
9735 prevent redundant reading of the line table for partial_units).
9736 If we're given a partial_unit, we'll need it. If we're given a
9737 compile_unit, then use the line header hash table if it's already
9738 created, but don't create one just yet. */
9740 if (dwarf2_per_objfile
->line_header_hash
== NULL
9741 && die
->tag
== DW_TAG_partial_unit
)
9743 dwarf2_per_objfile
->line_header_hash
9744 = htab_create_alloc_ex (127, line_header_hash_voidp
,
9745 line_header_eq_voidp
,
9746 free_line_header_voidp
,
9747 &objfile
->objfile_obstack
,
9748 hashtab_obstack_allocate
,
9749 dummy_obstack_deallocate
);
9752 line_header_local
.sect_off
= line_offset
;
9753 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
9754 line_header_local_hash
= line_header_hash (&line_header_local
);
9755 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
9757 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9759 line_header_local_hash
, NO_INSERT
);
9761 /* For DW_TAG_compile_unit we need info like symtab::linetable which
9762 is not present in *SLOT (since if there is something in *SLOT then
9763 it will be for a partial_unit). */
9764 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
9766 gdb_assert (*slot
!= NULL
);
9767 cu
->line_header
= (struct line_header
*) *slot
;
9772 /* dwarf_decode_line_header does not yet provide sufficient information.
9773 We always have to call also dwarf_decode_lines for it. */
9774 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
9778 cu
->line_header
= lh
.release ();
9779 cu
->line_header_die_owner
= die
;
9781 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
9785 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9787 line_header_local_hash
, INSERT
);
9788 gdb_assert (slot
!= NULL
);
9790 if (slot
!= NULL
&& *slot
== NULL
)
9792 /* This newly decoded line number information unit will be owned
9793 by line_header_hash hash table. */
9794 *slot
= cu
->line_header
;
9795 cu
->line_header_die_owner
= NULL
;
9799 /* We cannot free any current entry in (*slot) as that struct line_header
9800 may be already used by multiple CUs. Create only temporary decoded
9801 line_header for this CU - it may happen at most once for each line
9802 number information unit. And if we're not using line_header_hash
9803 then this is what we want as well. */
9804 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
9806 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
9807 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
9812 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
9815 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9817 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9818 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9819 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
9820 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
9821 struct attribute
*attr
;
9822 struct die_info
*child_die
;
9825 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9827 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
9829 /* If we didn't find a lowpc, set it to highpc to avoid complaints
9830 from finish_block. */
9831 if (lowpc
== ((CORE_ADDR
) -1))
9833 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
9835 file_and_directory fnd
= find_file_and_directory (die
, cu
);
9837 prepare_one_comp_unit (cu
, die
, cu
->language
);
9839 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
9840 standardised yet. As a workaround for the language detection we fall
9841 back to the DW_AT_producer string. */
9842 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
9843 cu
->language
= language_opencl
;
9845 /* Similar hack for Go. */
9846 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
9847 set_cu_language (DW_LANG_Go
, cu
);
9849 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
9851 /* Decode line number information if present. We do this before
9852 processing child DIEs, so that the line header table is available
9853 for DW_AT_decl_file. */
9854 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
9856 /* Process all dies in compilation unit. */
9857 if (die
->child
!= NULL
)
9859 child_die
= die
->child
;
9860 while (child_die
&& child_die
->tag
)
9862 process_die (child_die
, cu
);
9863 child_die
= sibling_die (child_die
);
9867 /* Decode macro information, if present. Dwarf 2 macro information
9868 refers to information in the line number info statement program
9869 header, so we can only read it if we've read the header
9871 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
9873 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
9874 if (attr
&& cu
->line_header
)
9876 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
9877 complaint (&symfile_complaints
,
9878 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
9880 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
9884 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
9885 if (attr
&& cu
->line_header
)
9887 unsigned int macro_offset
= DW_UNSND (attr
);
9889 dwarf_decode_macros (cu
, macro_offset
, 0);
9894 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
9895 Create the set of symtabs used by this TU, or if this TU is sharing
9896 symtabs with another TU and the symtabs have already been created
9897 then restore those symtabs in the line header.
9898 We don't need the pc/line-number mapping for type units. */
9901 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
9903 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
9904 struct type_unit_group
*tu_group
;
9906 struct attribute
*attr
;
9908 struct signatured_type
*sig_type
;
9910 gdb_assert (per_cu
->is_debug_types
);
9911 sig_type
= (struct signatured_type
*) per_cu
;
9913 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9915 /* If we're using .gdb_index (includes -readnow) then
9916 per_cu->type_unit_group may not have been set up yet. */
9917 if (sig_type
->type_unit_group
== NULL
)
9918 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
9919 tu_group
= sig_type
->type_unit_group
;
9921 /* If we've already processed this stmt_list there's no real need to
9922 do it again, we could fake it and just recreate the part we need
9923 (file name,index -> symtab mapping). If data shows this optimization
9924 is useful we can do it then. */
9925 first_time
= tu_group
->compunit_symtab
== NULL
;
9927 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
9932 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
9933 lh
= dwarf_decode_line_header (line_offset
, cu
);
9938 dwarf2_start_symtab (cu
, "", NULL
, 0);
9941 gdb_assert (tu_group
->symtabs
== NULL
);
9942 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9947 cu
->line_header
= lh
.release ();
9948 cu
->line_header_die_owner
= die
;
9952 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
9954 /* Note: We don't assign tu_group->compunit_symtab yet because we're
9955 still initializing it, and our caller (a few levels up)
9956 process_full_type_unit still needs to know if this is the first
9959 tu_group
->num_symtabs
= cu
->line_header
->file_names
.size ();
9960 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
9961 cu
->line_header
->file_names
.size ());
9963 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
9965 file_entry
&fe
= cu
->line_header
->file_names
[i
];
9967 dwarf2_start_subfile (fe
.name
, fe
.include_dir (cu
->line_header
));
9969 if (current_subfile
->symtab
== NULL
)
9971 /* NOTE: start_subfile will recognize when it's been
9972 passed a file it has already seen. So we can't
9973 assume there's a simple mapping from
9974 cu->line_header->file_names to subfiles, plus
9975 cu->line_header->file_names may contain dups. */
9976 current_subfile
->symtab
9977 = allocate_symtab (cust
, current_subfile
->name
);
9980 fe
.symtab
= current_subfile
->symtab
;
9981 tu_group
->symtabs
[i
] = fe
.symtab
;
9986 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9988 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
9990 file_entry
&fe
= cu
->line_header
->file_names
[i
];
9992 fe
.symtab
= tu_group
->symtabs
[i
];
9996 /* The main symtab is allocated last. Type units don't have DW_AT_name
9997 so they don't have a "real" (so to speak) symtab anyway.
9998 There is later code that will assign the main symtab to all symbols
9999 that don't have one. We need to handle the case of a symbol with a
10000 missing symtab (DW_AT_decl_file) anyway. */
10003 /* Process DW_TAG_type_unit.
10004 For TUs we want to skip the first top level sibling if it's not the
10005 actual type being defined by this TU. In this case the first top
10006 level sibling is there to provide context only. */
10009 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10011 struct die_info
*child_die
;
10013 prepare_one_comp_unit (cu
, die
, language_minimal
);
10015 /* Initialize (or reinitialize) the machinery for building symtabs.
10016 We do this before processing child DIEs, so that the line header table
10017 is available for DW_AT_decl_file. */
10018 setup_type_unit_groups (die
, cu
);
10020 if (die
->child
!= NULL
)
10022 child_die
= die
->child
;
10023 while (child_die
&& child_die
->tag
)
10025 process_die (child_die
, cu
);
10026 child_die
= sibling_die (child_die
);
10033 http://gcc.gnu.org/wiki/DebugFission
10034 http://gcc.gnu.org/wiki/DebugFissionDWP
10036 To simplify handling of both DWO files ("object" files with the DWARF info)
10037 and DWP files (a file with the DWOs packaged up into one file), we treat
10038 DWP files as having a collection of virtual DWO files. */
10041 hash_dwo_file (const void *item
)
10043 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10046 hash
= htab_hash_string (dwo_file
->dwo_name
);
10047 if (dwo_file
->comp_dir
!= NULL
)
10048 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10053 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10055 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10056 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10058 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10060 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10061 return lhs
->comp_dir
== rhs
->comp_dir
;
10062 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10065 /* Allocate a hash table for DWO files. */
10068 allocate_dwo_file_hash_table (void)
10070 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10072 return htab_create_alloc_ex (41,
10076 &objfile
->objfile_obstack
,
10077 hashtab_obstack_allocate
,
10078 dummy_obstack_deallocate
);
10081 /* Lookup DWO file DWO_NAME. */
10084 lookup_dwo_file_slot (const char *dwo_name
, const char *comp_dir
)
10086 struct dwo_file find_entry
;
10089 if (dwarf2_per_objfile
->dwo_files
== NULL
)
10090 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
10092 memset (&find_entry
, 0, sizeof (find_entry
));
10093 find_entry
.dwo_name
= dwo_name
;
10094 find_entry
.comp_dir
= comp_dir
;
10095 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
10101 hash_dwo_unit (const void *item
)
10103 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10105 /* This drops the top 32 bits of the id, but is ok for a hash. */
10106 return dwo_unit
->signature
;
10110 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10112 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10113 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10115 /* The signature is assumed to be unique within the DWO file.
10116 So while object file CU dwo_id's always have the value zero,
10117 that's OK, assuming each object file DWO file has only one CU,
10118 and that's the rule for now. */
10119 return lhs
->signature
== rhs
->signature
;
10122 /* Allocate a hash table for DWO CUs,TUs.
10123 There is one of these tables for each of CUs,TUs for each DWO file. */
10126 allocate_dwo_unit_table (struct objfile
*objfile
)
10128 /* Start out with a pretty small number.
10129 Generally DWO files contain only one CU and maybe some TUs. */
10130 return htab_create_alloc_ex (3,
10134 &objfile
->objfile_obstack
,
10135 hashtab_obstack_allocate
,
10136 dummy_obstack_deallocate
);
10139 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
10141 struct create_dwo_cu_data
10143 struct dwo_file
*dwo_file
;
10144 struct dwo_unit dwo_unit
;
10147 /* die_reader_func for create_dwo_cu. */
10150 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10151 const gdb_byte
*info_ptr
,
10152 struct die_info
*comp_unit_die
,
10156 struct dwarf2_cu
*cu
= reader
->cu
;
10157 sect_offset sect_off
= cu
->per_cu
->sect_off
;
10158 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
10159 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
10160 struct dwo_file
*dwo_file
= data
->dwo_file
;
10161 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
10162 struct attribute
*attr
;
10164 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
10167 complaint (&symfile_complaints
,
10168 _("Dwarf Error: debug entry at offset 0x%x is missing"
10169 " its dwo_id [in module %s]"),
10170 to_underlying (sect_off
), dwo_file
->dwo_name
);
10174 dwo_unit
->dwo_file
= dwo_file
;
10175 dwo_unit
->signature
= DW_UNSND (attr
);
10176 dwo_unit
->section
= section
;
10177 dwo_unit
->sect_off
= sect_off
;
10178 dwo_unit
->length
= cu
->per_cu
->length
;
10180 if (dwarf_read_debug
)
10181 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id %s\n",
10182 to_underlying (sect_off
),
10183 hex_string (dwo_unit
->signature
));
10186 /* Create the dwo_units for the CUs in a DWO_FILE.
10187 Note: This function processes DWO files only, not DWP files. */
10190 create_cus_hash_table (struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
10193 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10194 const struct dwarf2_section_info
*abbrev_section
= &dwo_file
.sections
.abbrev
;
10195 const gdb_byte
*info_ptr
, *end_ptr
;
10197 dwarf2_read_section (objfile
, §ion
);
10198 info_ptr
= section
.buffer
;
10200 if (info_ptr
== NULL
)
10203 if (dwarf_read_debug
)
10205 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
10206 get_section_name (§ion
),
10207 get_section_file_name (§ion
));
10210 end_ptr
= info_ptr
+ section
.size
;
10211 while (info_ptr
< end_ptr
)
10213 struct dwarf2_per_cu_data per_cu
;
10214 struct create_dwo_cu_data create_dwo_cu_data
;
10215 struct dwo_unit
*dwo_unit
;
10217 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
10219 memset (&create_dwo_cu_data
.dwo_unit
, 0,
10220 sizeof (create_dwo_cu_data
.dwo_unit
));
10221 memset (&per_cu
, 0, sizeof (per_cu
));
10222 per_cu
.objfile
= objfile
;
10223 per_cu
.is_debug_types
= 0;
10224 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
10225 per_cu
.section
= §ion
;
10226 create_dwo_cu_data
.dwo_file
= &dwo_file
;
10228 init_cutu_and_read_dies_no_follow (
10229 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
10230 info_ptr
+= per_cu
.length
;
10232 // If the unit could not be parsed, skip it.
10233 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
10236 if (cus_htab
== NULL
)
10237 cus_htab
= allocate_dwo_unit_table (objfile
);
10239 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10240 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
10241 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
10242 gdb_assert (slot
!= NULL
);
10245 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
10246 sect_offset dup_sect_off
= dup_cu
->sect_off
;
10248 complaint (&symfile_complaints
,
10249 _("debug cu entry at offset 0x%x is duplicate to"
10250 " the entry at offset 0x%x, signature %s"),
10251 to_underlying (sect_off
), to_underlying (dup_sect_off
),
10252 hex_string (dwo_unit
->signature
));
10254 *slot
= (void *)dwo_unit
;
10258 /* DWP file .debug_{cu,tu}_index section format:
10259 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
10263 Both index sections have the same format, and serve to map a 64-bit
10264 signature to a set of section numbers. Each section begins with a header,
10265 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
10266 indexes, and a pool of 32-bit section numbers. The index sections will be
10267 aligned at 8-byte boundaries in the file.
10269 The index section header consists of:
10271 V, 32 bit version number
10273 N, 32 bit number of compilation units or type units in the index
10274 M, 32 bit number of slots in the hash table
10276 Numbers are recorded using the byte order of the application binary.
10278 The hash table begins at offset 16 in the section, and consists of an array
10279 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
10280 order of the application binary). Unused slots in the hash table are 0.
10281 (We rely on the extreme unlikeliness of a signature being exactly 0.)
10283 The parallel table begins immediately after the hash table
10284 (at offset 16 + 8 * M from the beginning of the section), and consists of an
10285 array of 32-bit indexes (using the byte order of the application binary),
10286 corresponding 1-1 with slots in the hash table. Each entry in the parallel
10287 table contains a 32-bit index into the pool of section numbers. For unused
10288 hash table slots, the corresponding entry in the parallel table will be 0.
10290 The pool of section numbers begins immediately following the hash table
10291 (at offset 16 + 12 * M from the beginning of the section). The pool of
10292 section numbers consists of an array of 32-bit words (using the byte order
10293 of the application binary). Each item in the array is indexed starting
10294 from 0. The hash table entry provides the index of the first section
10295 number in the set. Additional section numbers in the set follow, and the
10296 set is terminated by a 0 entry (section number 0 is not used in ELF).
10298 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
10299 section must be the first entry in the set, and the .debug_abbrev.dwo must
10300 be the second entry. Other members of the set may follow in any order.
10306 DWP Version 2 combines all the .debug_info, etc. sections into one,
10307 and the entries in the index tables are now offsets into these sections.
10308 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
10311 Index Section Contents:
10313 Hash Table of Signatures dwp_hash_table.hash_table
10314 Parallel Table of Indices dwp_hash_table.unit_table
10315 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
10316 Table of Section Sizes dwp_hash_table.v2.sizes
10318 The index section header consists of:
10320 V, 32 bit version number
10321 L, 32 bit number of columns in the table of section offsets
10322 N, 32 bit number of compilation units or type units in the index
10323 M, 32 bit number of slots in the hash table
10325 Numbers are recorded using the byte order of the application binary.
10327 The hash table has the same format as version 1.
10328 The parallel table of indices has the same format as version 1,
10329 except that the entries are origin-1 indices into the table of sections
10330 offsets and the table of section sizes.
10332 The table of offsets begins immediately following the parallel table
10333 (at offset 16 + 12 * M from the beginning of the section). The table is
10334 a two-dimensional array of 32-bit words (using the byte order of the
10335 application binary), with L columns and N+1 rows, in row-major order.
10336 Each row in the array is indexed starting from 0. The first row provides
10337 a key to the remaining rows: each column in this row provides an identifier
10338 for a debug section, and the offsets in the same column of subsequent rows
10339 refer to that section. The section identifiers are:
10341 DW_SECT_INFO 1 .debug_info.dwo
10342 DW_SECT_TYPES 2 .debug_types.dwo
10343 DW_SECT_ABBREV 3 .debug_abbrev.dwo
10344 DW_SECT_LINE 4 .debug_line.dwo
10345 DW_SECT_LOC 5 .debug_loc.dwo
10346 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
10347 DW_SECT_MACINFO 7 .debug_macinfo.dwo
10348 DW_SECT_MACRO 8 .debug_macro.dwo
10350 The offsets provided by the CU and TU index sections are the base offsets
10351 for the contributions made by each CU or TU to the corresponding section
10352 in the package file. Each CU and TU header contains an abbrev_offset
10353 field, used to find the abbreviations table for that CU or TU within the
10354 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
10355 be interpreted as relative to the base offset given in the index section.
10356 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
10357 should be interpreted as relative to the base offset for .debug_line.dwo,
10358 and offsets into other debug sections obtained from DWARF attributes should
10359 also be interpreted as relative to the corresponding base offset.
10361 The table of sizes begins immediately following the table of offsets.
10362 Like the table of offsets, it is a two-dimensional array of 32-bit words,
10363 with L columns and N rows, in row-major order. Each row in the array is
10364 indexed starting from 1 (row 0 is shared by the two tables).
10368 Hash table lookup is handled the same in version 1 and 2:
10370 We assume that N and M will not exceed 2^32 - 1.
10371 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
10373 Given a 64-bit compilation unit signature or a type signature S, an entry
10374 in the hash table is located as follows:
10376 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
10377 the low-order k bits all set to 1.
10379 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
10381 3) If the hash table entry at index H matches the signature, use that
10382 entry. If the hash table entry at index H is unused (all zeroes),
10383 terminate the search: the signature is not present in the table.
10385 4) Let H = (H + H') modulo M. Repeat at Step 3.
10387 Because M > N and H' and M are relatively prime, the search is guaranteed
10388 to stop at an unused slot or find the match. */
10390 /* Create a hash table to map DWO IDs to their CU/TU entry in
10391 .debug_{info,types}.dwo in DWP_FILE.
10392 Returns NULL if there isn't one.
10393 Note: This function processes DWP files only, not DWO files. */
10395 static struct dwp_hash_table
*
10396 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
10398 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10399 bfd
*dbfd
= dwp_file
->dbfd
;
10400 const gdb_byte
*index_ptr
, *index_end
;
10401 struct dwarf2_section_info
*index
;
10402 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
10403 struct dwp_hash_table
*htab
;
10405 if (is_debug_types
)
10406 index
= &dwp_file
->sections
.tu_index
;
10408 index
= &dwp_file
->sections
.cu_index
;
10410 if (dwarf2_section_empty_p (index
))
10412 dwarf2_read_section (objfile
, index
);
10414 index_ptr
= index
->buffer
;
10415 index_end
= index_ptr
+ index
->size
;
10417 version
= read_4_bytes (dbfd
, index_ptr
);
10420 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
10424 nr_units
= read_4_bytes (dbfd
, index_ptr
);
10426 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
10429 if (version
!= 1 && version
!= 2)
10431 error (_("Dwarf Error: unsupported DWP file version (%s)"
10432 " [in module %s]"),
10433 pulongest (version
), dwp_file
->name
);
10435 if (nr_slots
!= (nr_slots
& -nr_slots
))
10437 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
10438 " is not power of 2 [in module %s]"),
10439 pulongest (nr_slots
), dwp_file
->name
);
10442 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
10443 htab
->version
= version
;
10444 htab
->nr_columns
= nr_columns
;
10445 htab
->nr_units
= nr_units
;
10446 htab
->nr_slots
= nr_slots
;
10447 htab
->hash_table
= index_ptr
;
10448 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
10450 /* Exit early if the table is empty. */
10451 if (nr_slots
== 0 || nr_units
== 0
10452 || (version
== 2 && nr_columns
== 0))
10454 /* All must be zero. */
10455 if (nr_slots
!= 0 || nr_units
!= 0
10456 || (version
== 2 && nr_columns
!= 0))
10458 complaint (&symfile_complaints
,
10459 _("Empty DWP but nr_slots,nr_units,nr_columns not"
10460 " all zero [in modules %s]"),
10468 htab
->section_pool
.v1
.indices
=
10469 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
10470 /* It's harder to decide whether the section is too small in v1.
10471 V1 is deprecated anyway so we punt. */
10475 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
10476 int *ids
= htab
->section_pool
.v2
.section_ids
;
10477 /* Reverse map for error checking. */
10478 int ids_seen
[DW_SECT_MAX
+ 1];
10481 if (nr_columns
< 2)
10483 error (_("Dwarf Error: bad DWP hash table, too few columns"
10484 " in section table [in module %s]"),
10487 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
10489 error (_("Dwarf Error: bad DWP hash table, too many columns"
10490 " in section table [in module %s]"),
10493 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
10494 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
10495 for (i
= 0; i
< nr_columns
; ++i
)
10497 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
10499 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
10501 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
10502 " in section table [in module %s]"),
10503 id
, dwp_file
->name
);
10505 if (ids_seen
[id
] != -1)
10507 error (_("Dwarf Error: bad DWP hash table, duplicate section"
10508 " id %d in section table [in module %s]"),
10509 id
, dwp_file
->name
);
10514 /* Must have exactly one info or types section. */
10515 if (((ids_seen
[DW_SECT_INFO
] != -1)
10516 + (ids_seen
[DW_SECT_TYPES
] != -1))
10519 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
10520 " DWO info/types section [in module %s]"),
10523 /* Must have an abbrev section. */
10524 if (ids_seen
[DW_SECT_ABBREV
] == -1)
10526 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
10527 " section [in module %s]"),
10530 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
10531 htab
->section_pool
.v2
.sizes
=
10532 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
10533 * nr_units
* nr_columns
);
10534 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
10535 * nr_units
* nr_columns
))
10538 error (_("Dwarf Error: DWP index section is corrupt (too small)"
10539 " [in module %s]"),
10547 /* Update SECTIONS with the data from SECTP.
10549 This function is like the other "locate" section routines that are
10550 passed to bfd_map_over_sections, but in this context the sections to
10551 read comes from the DWP V1 hash table, not the full ELF section table.
10553 The result is non-zero for success, or zero if an error was found. */
10556 locate_v1_virtual_dwo_sections (asection
*sectp
,
10557 struct virtual_v1_dwo_sections
*sections
)
10559 const struct dwop_section_names
*names
= &dwop_section_names
;
10561 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10563 /* There can be only one. */
10564 if (sections
->abbrev
.s
.section
!= NULL
)
10566 sections
->abbrev
.s
.section
= sectp
;
10567 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10569 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
10570 || section_is_p (sectp
->name
, &names
->types_dwo
))
10572 /* There can be only one. */
10573 if (sections
->info_or_types
.s
.section
!= NULL
)
10575 sections
->info_or_types
.s
.section
= sectp
;
10576 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
10578 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10580 /* There can be only one. */
10581 if (sections
->line
.s
.section
!= NULL
)
10583 sections
->line
.s
.section
= sectp
;
10584 sections
->line
.size
= bfd_get_section_size (sectp
);
10586 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10588 /* There can be only one. */
10589 if (sections
->loc
.s
.section
!= NULL
)
10591 sections
->loc
.s
.section
= sectp
;
10592 sections
->loc
.size
= bfd_get_section_size (sectp
);
10594 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10596 /* There can be only one. */
10597 if (sections
->macinfo
.s
.section
!= NULL
)
10599 sections
->macinfo
.s
.section
= sectp
;
10600 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10602 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10604 /* There can be only one. */
10605 if (sections
->macro
.s
.section
!= NULL
)
10607 sections
->macro
.s
.section
= sectp
;
10608 sections
->macro
.size
= bfd_get_section_size (sectp
);
10610 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10612 /* There can be only one. */
10613 if (sections
->str_offsets
.s
.section
!= NULL
)
10615 sections
->str_offsets
.s
.section
= sectp
;
10616 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10620 /* No other kind of section is valid. */
10627 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10628 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10629 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10630 This is for DWP version 1 files. */
10632 static struct dwo_unit
*
10633 create_dwo_unit_in_dwp_v1 (struct dwp_file
*dwp_file
,
10634 uint32_t unit_index
,
10635 const char *comp_dir
,
10636 ULONGEST signature
, int is_debug_types
)
10638 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10639 const struct dwp_hash_table
*dwp_htab
=
10640 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10641 bfd
*dbfd
= dwp_file
->dbfd
;
10642 const char *kind
= is_debug_types
? "TU" : "CU";
10643 struct dwo_file
*dwo_file
;
10644 struct dwo_unit
*dwo_unit
;
10645 struct virtual_v1_dwo_sections sections
;
10646 void **dwo_file_slot
;
10649 gdb_assert (dwp_file
->version
== 1);
10651 if (dwarf_read_debug
)
10653 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
10655 pulongest (unit_index
), hex_string (signature
),
10659 /* Fetch the sections of this DWO unit.
10660 Put a limit on the number of sections we look for so that bad data
10661 doesn't cause us to loop forever. */
10663 #define MAX_NR_V1_DWO_SECTIONS \
10664 (1 /* .debug_info or .debug_types */ \
10665 + 1 /* .debug_abbrev */ \
10666 + 1 /* .debug_line */ \
10667 + 1 /* .debug_loc */ \
10668 + 1 /* .debug_str_offsets */ \
10669 + 1 /* .debug_macro or .debug_macinfo */ \
10670 + 1 /* trailing zero */)
10672 memset (§ions
, 0, sizeof (sections
));
10674 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
10677 uint32_t section_nr
=
10678 read_4_bytes (dbfd
,
10679 dwp_htab
->section_pool
.v1
.indices
10680 + (unit_index
+ i
) * sizeof (uint32_t));
10682 if (section_nr
== 0)
10684 if (section_nr
>= dwp_file
->num_sections
)
10686 error (_("Dwarf Error: bad DWP hash table, section number too large"
10687 " [in module %s]"),
10691 sectp
= dwp_file
->elf_sections
[section_nr
];
10692 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
10694 error (_("Dwarf Error: bad DWP hash table, invalid section found"
10695 " [in module %s]"),
10701 || dwarf2_section_empty_p (§ions
.info_or_types
)
10702 || dwarf2_section_empty_p (§ions
.abbrev
))
10704 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
10705 " [in module %s]"),
10708 if (i
== MAX_NR_V1_DWO_SECTIONS
)
10710 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
10711 " [in module %s]"),
10715 /* It's easier for the rest of the code if we fake a struct dwo_file and
10716 have dwo_unit "live" in that. At least for now.
10718 The DWP file can be made up of a random collection of CUs and TUs.
10719 However, for each CU + set of TUs that came from the same original DWO
10720 file, we can combine them back into a virtual DWO file to save space
10721 (fewer struct dwo_file objects to allocate). Remember that for really
10722 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10724 std::string virtual_dwo_name
=
10725 string_printf ("virtual-dwo/%d-%d-%d-%d",
10726 get_section_id (§ions
.abbrev
),
10727 get_section_id (§ions
.line
),
10728 get_section_id (§ions
.loc
),
10729 get_section_id (§ions
.str_offsets
));
10730 /* Can we use an existing virtual DWO file? */
10731 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
.c_str (), comp_dir
);
10732 /* Create one if necessary. */
10733 if (*dwo_file_slot
== NULL
)
10735 if (dwarf_read_debug
)
10737 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10738 virtual_dwo_name
.c_str ());
10740 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10742 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
10743 virtual_dwo_name
.c_str (),
10744 virtual_dwo_name
.size ());
10745 dwo_file
->comp_dir
= comp_dir
;
10746 dwo_file
->sections
.abbrev
= sections
.abbrev
;
10747 dwo_file
->sections
.line
= sections
.line
;
10748 dwo_file
->sections
.loc
= sections
.loc
;
10749 dwo_file
->sections
.macinfo
= sections
.macinfo
;
10750 dwo_file
->sections
.macro
= sections
.macro
;
10751 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
10752 /* The "str" section is global to the entire DWP file. */
10753 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10754 /* The info or types section is assigned below to dwo_unit,
10755 there's no need to record it in dwo_file.
10756 Also, we can't simply record type sections in dwo_file because
10757 we record a pointer into the vector in dwo_unit. As we collect more
10758 types we'll grow the vector and eventually have to reallocate space
10759 for it, invalidating all copies of pointers into the previous
10761 *dwo_file_slot
= dwo_file
;
10765 if (dwarf_read_debug
)
10767 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10768 virtual_dwo_name
.c_str ());
10770 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10773 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10774 dwo_unit
->dwo_file
= dwo_file
;
10775 dwo_unit
->signature
= signature
;
10776 dwo_unit
->section
=
10777 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
10778 *dwo_unit
->section
= sections
.info_or_types
;
10779 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10784 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
10785 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
10786 piece within that section used by a TU/CU, return a virtual section
10787 of just that piece. */
10789 static struct dwarf2_section_info
10790 create_dwp_v2_section (struct dwarf2_section_info
*section
,
10791 bfd_size_type offset
, bfd_size_type size
)
10793 struct dwarf2_section_info result
;
10796 gdb_assert (section
!= NULL
);
10797 gdb_assert (!section
->is_virtual
);
10799 memset (&result
, 0, sizeof (result
));
10800 result
.s
.containing_section
= section
;
10801 result
.is_virtual
= 1;
10806 sectp
= get_section_bfd_section (section
);
10808 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
10809 bounds of the real section. This is a pretty-rare event, so just
10810 flag an error (easier) instead of a warning and trying to cope. */
10812 || offset
+ size
> bfd_get_section_size (sectp
))
10814 bfd
*abfd
= sectp
->owner
;
10816 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
10817 " in section %s [in module %s]"),
10818 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
10819 objfile_name (dwarf2_per_objfile
->objfile
));
10822 result
.virtual_offset
= offset
;
10823 result
.size
= size
;
10827 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10828 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10829 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10830 This is for DWP version 2 files. */
10832 static struct dwo_unit
*
10833 create_dwo_unit_in_dwp_v2 (struct dwp_file
*dwp_file
,
10834 uint32_t unit_index
,
10835 const char *comp_dir
,
10836 ULONGEST signature
, int is_debug_types
)
10838 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10839 const struct dwp_hash_table
*dwp_htab
=
10840 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10841 bfd
*dbfd
= dwp_file
->dbfd
;
10842 const char *kind
= is_debug_types
? "TU" : "CU";
10843 struct dwo_file
*dwo_file
;
10844 struct dwo_unit
*dwo_unit
;
10845 struct virtual_v2_dwo_sections sections
;
10846 void **dwo_file_slot
;
10849 gdb_assert (dwp_file
->version
== 2);
10851 if (dwarf_read_debug
)
10853 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
10855 pulongest (unit_index
), hex_string (signature
),
10859 /* Fetch the section offsets of this DWO unit. */
10861 memset (§ions
, 0, sizeof (sections
));
10863 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
10865 uint32_t offset
= read_4_bytes (dbfd
,
10866 dwp_htab
->section_pool
.v2
.offsets
10867 + (((unit_index
- 1) * dwp_htab
->nr_columns
10869 * sizeof (uint32_t)));
10870 uint32_t size
= read_4_bytes (dbfd
,
10871 dwp_htab
->section_pool
.v2
.sizes
10872 + (((unit_index
- 1) * dwp_htab
->nr_columns
10874 * sizeof (uint32_t)));
10876 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
10879 case DW_SECT_TYPES
:
10880 sections
.info_or_types_offset
= offset
;
10881 sections
.info_or_types_size
= size
;
10883 case DW_SECT_ABBREV
:
10884 sections
.abbrev_offset
= offset
;
10885 sections
.abbrev_size
= size
;
10888 sections
.line_offset
= offset
;
10889 sections
.line_size
= size
;
10892 sections
.loc_offset
= offset
;
10893 sections
.loc_size
= size
;
10895 case DW_SECT_STR_OFFSETS
:
10896 sections
.str_offsets_offset
= offset
;
10897 sections
.str_offsets_size
= size
;
10899 case DW_SECT_MACINFO
:
10900 sections
.macinfo_offset
= offset
;
10901 sections
.macinfo_size
= size
;
10903 case DW_SECT_MACRO
:
10904 sections
.macro_offset
= offset
;
10905 sections
.macro_size
= size
;
10910 /* It's easier for the rest of the code if we fake a struct dwo_file and
10911 have dwo_unit "live" in that. At least for now.
10913 The DWP file can be made up of a random collection of CUs and TUs.
10914 However, for each CU + set of TUs that came from the same original DWO
10915 file, we can combine them back into a virtual DWO file to save space
10916 (fewer struct dwo_file objects to allocate). Remember that for really
10917 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10919 std::string virtual_dwo_name
=
10920 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
10921 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
10922 (long) (sections
.line_size
? sections
.line_offset
: 0),
10923 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
10924 (long) (sections
.str_offsets_size
10925 ? sections
.str_offsets_offset
: 0));
10926 /* Can we use an existing virtual DWO file? */
10927 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
.c_str (), comp_dir
);
10928 /* Create one if necessary. */
10929 if (*dwo_file_slot
== NULL
)
10931 if (dwarf_read_debug
)
10933 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10934 virtual_dwo_name
.c_str ());
10936 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10938 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
10939 virtual_dwo_name
.c_str (),
10940 virtual_dwo_name
.size ());
10941 dwo_file
->comp_dir
= comp_dir
;
10942 dwo_file
->sections
.abbrev
=
10943 create_dwp_v2_section (&dwp_file
->sections
.abbrev
,
10944 sections
.abbrev_offset
, sections
.abbrev_size
);
10945 dwo_file
->sections
.line
=
10946 create_dwp_v2_section (&dwp_file
->sections
.line
,
10947 sections
.line_offset
, sections
.line_size
);
10948 dwo_file
->sections
.loc
=
10949 create_dwp_v2_section (&dwp_file
->sections
.loc
,
10950 sections
.loc_offset
, sections
.loc_size
);
10951 dwo_file
->sections
.macinfo
=
10952 create_dwp_v2_section (&dwp_file
->sections
.macinfo
,
10953 sections
.macinfo_offset
, sections
.macinfo_size
);
10954 dwo_file
->sections
.macro
=
10955 create_dwp_v2_section (&dwp_file
->sections
.macro
,
10956 sections
.macro_offset
, sections
.macro_size
);
10957 dwo_file
->sections
.str_offsets
=
10958 create_dwp_v2_section (&dwp_file
->sections
.str_offsets
,
10959 sections
.str_offsets_offset
,
10960 sections
.str_offsets_size
);
10961 /* The "str" section is global to the entire DWP file. */
10962 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10963 /* The info or types section is assigned below to dwo_unit,
10964 there's no need to record it in dwo_file.
10965 Also, we can't simply record type sections in dwo_file because
10966 we record a pointer into the vector in dwo_unit. As we collect more
10967 types we'll grow the vector and eventually have to reallocate space
10968 for it, invalidating all copies of pointers into the previous
10970 *dwo_file_slot
= dwo_file
;
10974 if (dwarf_read_debug
)
10976 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10977 virtual_dwo_name
.c_str ());
10979 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10982 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10983 dwo_unit
->dwo_file
= dwo_file
;
10984 dwo_unit
->signature
= signature
;
10985 dwo_unit
->section
=
10986 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
10987 *dwo_unit
->section
= create_dwp_v2_section (is_debug_types
10988 ? &dwp_file
->sections
.types
10989 : &dwp_file
->sections
.info
,
10990 sections
.info_or_types_offset
,
10991 sections
.info_or_types_size
);
10992 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10997 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
10998 Returns NULL if the signature isn't found. */
11000 static struct dwo_unit
*
11001 lookup_dwo_unit_in_dwp (struct dwp_file
*dwp_file
, const char *comp_dir
,
11002 ULONGEST signature
, int is_debug_types
)
11004 const struct dwp_hash_table
*dwp_htab
=
11005 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11006 bfd
*dbfd
= dwp_file
->dbfd
;
11007 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11008 uint32_t hash
= signature
& mask
;
11009 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11012 struct dwo_unit find_dwo_cu
;
11014 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11015 find_dwo_cu
.signature
= signature
;
11016 slot
= htab_find_slot (is_debug_types
11017 ? dwp_file
->loaded_tus
11018 : dwp_file
->loaded_cus
,
11019 &find_dwo_cu
, INSERT
);
11022 return (struct dwo_unit
*) *slot
;
11024 /* Use a for loop so that we don't loop forever on bad debug info. */
11025 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11027 ULONGEST signature_in_table
;
11029 signature_in_table
=
11030 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11031 if (signature_in_table
== signature
)
11033 uint32_t unit_index
=
11034 read_4_bytes (dbfd
,
11035 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11037 if (dwp_file
->version
== 1)
11039 *slot
= create_dwo_unit_in_dwp_v1 (dwp_file
, unit_index
,
11040 comp_dir
, signature
,
11045 *slot
= create_dwo_unit_in_dwp_v2 (dwp_file
, unit_index
,
11046 comp_dir
, signature
,
11049 return (struct dwo_unit
*) *slot
;
11051 if (signature_in_table
== 0)
11053 hash
= (hash
+ hash2
) & mask
;
11056 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11057 " [in module %s]"),
11061 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11062 Open the file specified by FILE_NAME and hand it off to BFD for
11063 preliminary analysis. Return a newly initialized bfd *, which
11064 includes a canonicalized copy of FILE_NAME.
11065 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11066 SEARCH_CWD is true if the current directory is to be searched.
11067 It will be searched before debug-file-directory.
11068 If successful, the file is added to the bfd include table of the
11069 objfile's bfd (see gdb_bfd_record_inclusion).
11070 If unable to find/open the file, return NULL.
11071 NOTE: This function is derived from symfile_bfd_open. */
11073 static gdb_bfd_ref_ptr
11074 try_open_dwop_file (const char *file_name
, int is_dwp
, int search_cwd
)
11077 char *absolute_name
;
11078 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11079 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11080 to debug_file_directory. */
11082 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11086 if (*debug_file_directory
!= '\0')
11087 search_path
= concat (".", dirname_separator_string
,
11088 debug_file_directory
, (char *) NULL
);
11090 search_path
= xstrdup (".");
11093 search_path
= xstrdup (debug_file_directory
);
11095 flags
= OPF_RETURN_REALPATH
;
11097 flags
|= OPF_SEARCH_IN_PATH
;
11098 desc
= openp (search_path
, flags
, file_name
,
11099 O_RDONLY
| O_BINARY
, &absolute_name
);
11100 xfree (search_path
);
11104 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
, gnutarget
, desc
));
11105 xfree (absolute_name
);
11106 if (sym_bfd
== NULL
)
11108 bfd_set_cacheable (sym_bfd
.get (), 1);
11110 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
11113 /* Success. Record the bfd as having been included by the objfile's bfd.
11114 This is important because things like demangled_names_hash lives in the
11115 objfile's per_bfd space and may have references to things like symbol
11116 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
11117 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
11122 /* Try to open DWO file FILE_NAME.
11123 COMP_DIR is the DW_AT_comp_dir attribute.
11124 The result is the bfd handle of the file.
11125 If there is a problem finding or opening the file, return NULL.
11126 Upon success, the canonicalized path of the file is stored in the bfd,
11127 same as symfile_bfd_open. */
11129 static gdb_bfd_ref_ptr
11130 open_dwo_file (const char *file_name
, const char *comp_dir
)
11132 if (IS_ABSOLUTE_PATH (file_name
))
11133 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 0 /*search_cwd*/);
11135 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
11137 if (comp_dir
!= NULL
)
11139 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
11140 file_name
, (char *) NULL
);
11142 /* NOTE: If comp_dir is a relative path, this will also try the
11143 search path, which seems useful. */
11144 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (path_to_try
, 0 /*is_dwp*/,
11145 1 /*search_cwd*/));
11146 xfree (path_to_try
);
11151 /* That didn't work, try debug-file-directory, which, despite its name,
11152 is a list of paths. */
11154 if (*debug_file_directory
== '\0')
11157 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 1 /*search_cwd*/);
11160 /* This function is mapped across the sections and remembers the offset and
11161 size of each of the DWO debugging sections we are interested in. */
11164 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
11166 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
11167 const struct dwop_section_names
*names
= &dwop_section_names
;
11169 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11171 dwo_sections
->abbrev
.s
.section
= sectp
;
11172 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
11174 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
11176 dwo_sections
->info
.s
.section
= sectp
;
11177 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
11179 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11181 dwo_sections
->line
.s
.section
= sectp
;
11182 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
11184 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11186 dwo_sections
->loc
.s
.section
= sectp
;
11187 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
11189 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11191 dwo_sections
->macinfo
.s
.section
= sectp
;
11192 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
11194 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11196 dwo_sections
->macro
.s
.section
= sectp
;
11197 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
11199 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
11201 dwo_sections
->str
.s
.section
= sectp
;
11202 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
11204 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11206 dwo_sections
->str_offsets
.s
.section
= sectp
;
11207 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
11209 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
11211 struct dwarf2_section_info type_section
;
11213 memset (&type_section
, 0, sizeof (type_section
));
11214 type_section
.s
.section
= sectp
;
11215 type_section
.size
= bfd_get_section_size (sectp
);
11216 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
11221 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
11222 by PER_CU. This is for the non-DWP case.
11223 The result is NULL if DWO_NAME can't be found. */
11225 static struct dwo_file
*
11226 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
11227 const char *dwo_name
, const char *comp_dir
)
11229 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11230 struct dwo_file
*dwo_file
;
11231 struct cleanup
*cleanups
;
11233 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwo_name
, comp_dir
));
11236 if (dwarf_read_debug
)
11237 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
11240 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
11241 dwo_file
->dwo_name
= dwo_name
;
11242 dwo_file
->comp_dir
= comp_dir
;
11243 dwo_file
->dbfd
= dbfd
.release ();
11245 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
11247 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
11248 &dwo_file
->sections
);
11250 create_cus_hash_table (*dwo_file
, dwo_file
->sections
.info
, dwo_file
->cus
);
11252 create_debug_types_hash_table (dwo_file
, dwo_file
->sections
.types
,
11255 discard_cleanups (cleanups
);
11257 if (dwarf_read_debug
)
11258 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
11263 /* This function is mapped across the sections and remembers the offset and
11264 size of each of the DWP debugging sections common to version 1 and 2 that
11265 we are interested in. */
11268 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
11269 void *dwp_file_ptr
)
11271 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
11272 const struct dwop_section_names
*names
= &dwop_section_names
;
11273 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
11275 /* Record the ELF section number for later lookup: this is what the
11276 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
11277 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
11278 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
11280 /* Look for specific sections that we need. */
11281 if (section_is_p (sectp
->name
, &names
->str_dwo
))
11283 dwp_file
->sections
.str
.s
.section
= sectp
;
11284 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
11286 else if (section_is_p (sectp
->name
, &names
->cu_index
))
11288 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
11289 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
11291 else if (section_is_p (sectp
->name
, &names
->tu_index
))
11293 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
11294 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
11298 /* This function is mapped across the sections and remembers the offset and
11299 size of each of the DWP version 2 debugging sections that we are interested
11300 in. This is split into a separate function because we don't know if we
11301 have version 1 or 2 until we parse the cu_index/tu_index sections. */
11304 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
11306 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
11307 const struct dwop_section_names
*names
= &dwop_section_names
;
11308 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
11310 /* Record the ELF section number for later lookup: this is what the
11311 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
11312 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
11313 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
11315 /* Look for specific sections that we need. */
11316 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11318 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
11319 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
11321 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
11323 dwp_file
->sections
.info
.s
.section
= sectp
;
11324 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
11326 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11328 dwp_file
->sections
.line
.s
.section
= sectp
;
11329 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
11331 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11333 dwp_file
->sections
.loc
.s
.section
= sectp
;
11334 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
11336 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11338 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
11339 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
11341 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11343 dwp_file
->sections
.macro
.s
.section
= sectp
;
11344 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
11346 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11348 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
11349 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
11351 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
11353 dwp_file
->sections
.types
.s
.section
= sectp
;
11354 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
11358 /* Hash function for dwp_file loaded CUs/TUs. */
11361 hash_dwp_loaded_cutus (const void *item
)
11363 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11365 /* This drops the top 32 bits of the signature, but is ok for a hash. */
11366 return dwo_unit
->signature
;
11369 /* Equality function for dwp_file loaded CUs/TUs. */
11372 eq_dwp_loaded_cutus (const void *a
, const void *b
)
11374 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
11375 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
11377 return dua
->signature
== dub
->signature
;
11380 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
11383 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
11385 return htab_create_alloc_ex (3,
11386 hash_dwp_loaded_cutus
,
11387 eq_dwp_loaded_cutus
,
11389 &objfile
->objfile_obstack
,
11390 hashtab_obstack_allocate
,
11391 dummy_obstack_deallocate
);
11394 /* Try to open DWP file FILE_NAME.
11395 The result is the bfd handle of the file.
11396 If there is a problem finding or opening the file, return NULL.
11397 Upon success, the canonicalized path of the file is stored in the bfd,
11398 same as symfile_bfd_open. */
11400 static gdb_bfd_ref_ptr
11401 open_dwp_file (const char *file_name
)
11403 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (file_name
, 1 /*is_dwp*/,
11404 1 /*search_cwd*/));
11408 /* Work around upstream bug 15652.
11409 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
11410 [Whether that's a "bug" is debatable, but it is getting in our way.]
11411 We have no real idea where the dwp file is, because gdb's realpath-ing
11412 of the executable's path may have discarded the needed info.
11413 [IWBN if the dwp file name was recorded in the executable, akin to
11414 .gnu_debuglink, but that doesn't exist yet.]
11415 Strip the directory from FILE_NAME and search again. */
11416 if (*debug_file_directory
!= '\0')
11418 /* Don't implicitly search the current directory here.
11419 If the user wants to search "." to handle this case,
11420 it must be added to debug-file-directory. */
11421 return try_open_dwop_file (lbasename (file_name
), 1 /*is_dwp*/,
11428 /* Initialize the use of the DWP file for the current objfile.
11429 By convention the name of the DWP file is ${objfile}.dwp.
11430 The result is NULL if it can't be found. */
11432 static struct dwp_file
*
11433 open_and_init_dwp_file (void)
11435 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11436 struct dwp_file
*dwp_file
;
11438 /* Try to find first .dwp for the binary file before any symbolic links
11441 /* If the objfile is a debug file, find the name of the real binary
11442 file and get the name of dwp file from there. */
11443 std::string dwp_name
;
11444 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
11446 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
11447 const char *backlink_basename
= lbasename (backlink
->original_name
);
11449 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
11452 dwp_name
= objfile
->original_name
;
11454 dwp_name
+= ".dwp";
11456 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwp_name
.c_str ()));
11458 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
11460 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
11461 dwp_name
= objfile_name (objfile
);
11462 dwp_name
+= ".dwp";
11463 dbfd
= open_dwp_file (dwp_name
.c_str ());
11468 if (dwarf_read_debug
)
11469 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
11472 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
11473 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
11474 dwp_file
->dbfd
= dbfd
.release ();
11476 /* +1: section 0 is unused */
11477 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
11478 dwp_file
->elf_sections
=
11479 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
11480 dwp_file
->num_sections
, asection
*);
11482 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
11485 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
11487 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
11489 /* The DWP file version is stored in the hash table. Oh well. */
11490 if (dwp_file
->cus
&& dwp_file
->tus
11491 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
11493 /* Technically speaking, we should try to limp along, but this is
11494 pretty bizarre. We use pulongest here because that's the established
11495 portability solution (e.g, we cannot use %u for uint32_t). */
11496 error (_("Dwarf Error: DWP file CU version %s doesn't match"
11497 " TU version %s [in DWP file %s]"),
11498 pulongest (dwp_file
->cus
->version
),
11499 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
11503 dwp_file
->version
= dwp_file
->cus
->version
;
11504 else if (dwp_file
->tus
)
11505 dwp_file
->version
= dwp_file
->tus
->version
;
11507 dwp_file
->version
= 2;
11509 if (dwp_file
->version
== 2)
11510 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
11513 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
11514 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
11516 if (dwarf_read_debug
)
11518 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
11519 fprintf_unfiltered (gdb_stdlog
,
11520 " %s CUs, %s TUs\n",
11521 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
11522 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
11528 /* Wrapper around open_and_init_dwp_file, only open it once. */
11530 static struct dwp_file
*
11531 get_dwp_file (void)
11533 if (! dwarf2_per_objfile
->dwp_checked
)
11535 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file ();
11536 dwarf2_per_objfile
->dwp_checked
= 1;
11538 return dwarf2_per_objfile
->dwp_file
;
11541 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
11542 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
11543 or in the DWP file for the objfile, referenced by THIS_UNIT.
11544 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
11545 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
11547 This is called, for example, when wanting to read a variable with a
11548 complex location. Therefore we don't want to do file i/o for every call.
11549 Therefore we don't want to look for a DWO file on every call.
11550 Therefore we first see if we've already seen SIGNATURE in a DWP file,
11551 then we check if we've already seen DWO_NAME, and only THEN do we check
11554 The result is a pointer to the dwo_unit object or NULL if we didn't find it
11555 (dwo_id mismatch or couldn't find the DWO/DWP file). */
11557 static struct dwo_unit
*
11558 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
11559 const char *dwo_name
, const char *comp_dir
,
11560 ULONGEST signature
, int is_debug_types
)
11562 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11563 const char *kind
= is_debug_types
? "TU" : "CU";
11564 void **dwo_file_slot
;
11565 struct dwo_file
*dwo_file
;
11566 struct dwp_file
*dwp_file
;
11568 /* First see if there's a DWP file.
11569 If we have a DWP file but didn't find the DWO inside it, don't
11570 look for the original DWO file. It makes gdb behave differently
11571 depending on whether one is debugging in the build tree. */
11573 dwp_file
= get_dwp_file ();
11574 if (dwp_file
!= NULL
)
11576 const struct dwp_hash_table
*dwp_htab
=
11577 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11579 if (dwp_htab
!= NULL
)
11581 struct dwo_unit
*dwo_cutu
=
11582 lookup_dwo_unit_in_dwp (dwp_file
, comp_dir
,
11583 signature
, is_debug_types
);
11585 if (dwo_cutu
!= NULL
)
11587 if (dwarf_read_debug
)
11589 fprintf_unfiltered (gdb_stdlog
,
11590 "Virtual DWO %s %s found: @%s\n",
11591 kind
, hex_string (signature
),
11592 host_address_to_string (dwo_cutu
));
11600 /* No DWP file, look for the DWO file. */
11602 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
, comp_dir
);
11603 if (*dwo_file_slot
== NULL
)
11605 /* Read in the file and build a table of the CUs/TUs it contains. */
11606 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
11608 /* NOTE: This will be NULL if unable to open the file. */
11609 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11611 if (dwo_file
!= NULL
)
11613 struct dwo_unit
*dwo_cutu
= NULL
;
11615 if (is_debug_types
&& dwo_file
->tus
)
11617 struct dwo_unit find_dwo_cutu
;
11619 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
11620 find_dwo_cutu
.signature
= signature
;
11622 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
11624 else if (!is_debug_types
&& dwo_file
->cus
)
11626 struct dwo_unit find_dwo_cutu
;
11628 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
11629 find_dwo_cutu
.signature
= signature
;
11630 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
11634 if (dwo_cutu
!= NULL
)
11636 if (dwarf_read_debug
)
11638 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
11639 kind
, dwo_name
, hex_string (signature
),
11640 host_address_to_string (dwo_cutu
));
11647 /* We didn't find it. This could mean a dwo_id mismatch, or
11648 someone deleted the DWO/DWP file, or the search path isn't set up
11649 correctly to find the file. */
11651 if (dwarf_read_debug
)
11653 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
11654 kind
, dwo_name
, hex_string (signature
));
11657 /* This is a warning and not a complaint because it can be caused by
11658 pilot error (e.g., user accidentally deleting the DWO). */
11660 /* Print the name of the DWP file if we looked there, helps the user
11661 better diagnose the problem. */
11662 std::string dwp_text
;
11664 if (dwp_file
!= NULL
)
11665 dwp_text
= string_printf (" [in DWP file %s]",
11666 lbasename (dwp_file
->name
));
11668 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset 0x%x"
11669 " [in module %s]"),
11670 kind
, dwo_name
, hex_string (signature
),
11672 this_unit
->is_debug_types
? "TU" : "CU",
11673 to_underlying (this_unit
->sect_off
), objfile_name (objfile
));
11678 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
11679 See lookup_dwo_cutu_unit for details. */
11681 static struct dwo_unit
*
11682 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
11683 const char *dwo_name
, const char *comp_dir
,
11684 ULONGEST signature
)
11686 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
11689 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
11690 See lookup_dwo_cutu_unit for details. */
11692 static struct dwo_unit
*
11693 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
11694 const char *dwo_name
, const char *comp_dir
)
11696 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
11699 /* Traversal function for queue_and_load_all_dwo_tus. */
11702 queue_and_load_dwo_tu (void **slot
, void *info
)
11704 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
11705 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
11706 ULONGEST signature
= dwo_unit
->signature
;
11707 struct signatured_type
*sig_type
=
11708 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
11710 if (sig_type
!= NULL
)
11712 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
11714 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
11715 a real dependency of PER_CU on SIG_TYPE. That is detected later
11716 while processing PER_CU. */
11717 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
11718 load_full_type_unit (sig_cu
);
11719 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
11725 /* Queue all TUs contained in the DWO of PER_CU to be read in.
11726 The DWO may have the only definition of the type, though it may not be
11727 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
11728 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
11731 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
11733 struct dwo_unit
*dwo_unit
;
11734 struct dwo_file
*dwo_file
;
11736 gdb_assert (!per_cu
->is_debug_types
);
11737 gdb_assert (get_dwp_file () == NULL
);
11738 gdb_assert (per_cu
->cu
!= NULL
);
11740 dwo_unit
= per_cu
->cu
->dwo_unit
;
11741 gdb_assert (dwo_unit
!= NULL
);
11743 dwo_file
= dwo_unit
->dwo_file
;
11744 if (dwo_file
->tus
!= NULL
)
11745 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
11748 /* Free all resources associated with DWO_FILE.
11749 Close the DWO file and munmap the sections.
11750 All memory should be on the objfile obstack. */
11753 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
11756 /* Note: dbfd is NULL for virtual DWO files. */
11757 gdb_bfd_unref (dwo_file
->dbfd
);
11759 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
11762 /* Wrapper for free_dwo_file for use in cleanups. */
11765 free_dwo_file_cleanup (void *arg
)
11767 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
11768 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11770 free_dwo_file (dwo_file
, objfile
);
11773 /* Traversal function for free_dwo_files. */
11776 free_dwo_file_from_slot (void **slot
, void *info
)
11778 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
11779 struct objfile
*objfile
= (struct objfile
*) info
;
11781 free_dwo_file (dwo_file
, objfile
);
11786 /* Free all resources associated with DWO_FILES. */
11789 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
11791 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
11794 /* Read in various DIEs. */
11796 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
11797 Inherit only the children of the DW_AT_abstract_origin DIE not being
11798 already referenced by DW_AT_abstract_origin from the children of the
11802 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
11804 struct die_info
*child_die
;
11805 sect_offset
*offsetp
;
11806 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
11807 struct die_info
*origin_die
;
11808 /* Iterator of the ORIGIN_DIE children. */
11809 struct die_info
*origin_child_die
;
11810 struct attribute
*attr
;
11811 struct dwarf2_cu
*origin_cu
;
11812 struct pending
**origin_previous_list_in_scope
;
11814 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11818 /* Note that following die references may follow to a die in a
11822 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
11824 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
11826 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
11827 origin_cu
->list_in_scope
= cu
->list_in_scope
;
11829 if (die
->tag
!= origin_die
->tag
11830 && !(die
->tag
== DW_TAG_inlined_subroutine
11831 && origin_die
->tag
== DW_TAG_subprogram
))
11832 complaint (&symfile_complaints
,
11833 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
11834 to_underlying (die
->sect_off
),
11835 to_underlying (origin_die
->sect_off
));
11837 std::vector
<sect_offset
> offsets
;
11839 for (child_die
= die
->child
;
11840 child_die
&& child_die
->tag
;
11841 child_die
= sibling_die (child_die
))
11843 struct die_info
*child_origin_die
;
11844 struct dwarf2_cu
*child_origin_cu
;
11846 /* We are trying to process concrete instance entries:
11847 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
11848 it's not relevant to our analysis here. i.e. detecting DIEs that are
11849 present in the abstract instance but not referenced in the concrete
11851 if (child_die
->tag
== DW_TAG_call_site
11852 || child_die
->tag
== DW_TAG_GNU_call_site
)
11855 /* For each CHILD_DIE, find the corresponding child of
11856 ORIGIN_DIE. If there is more than one layer of
11857 DW_AT_abstract_origin, follow them all; there shouldn't be,
11858 but GCC versions at least through 4.4 generate this (GCC PR
11860 child_origin_die
= child_die
;
11861 child_origin_cu
= cu
;
11864 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
11868 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
11872 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
11873 counterpart may exist. */
11874 if (child_origin_die
!= child_die
)
11876 if (child_die
->tag
!= child_origin_die
->tag
11877 && !(child_die
->tag
== DW_TAG_inlined_subroutine
11878 && child_origin_die
->tag
== DW_TAG_subprogram
))
11879 complaint (&symfile_complaints
,
11880 _("Child DIE 0x%x and its abstract origin 0x%x have "
11882 to_underlying (child_die
->sect_off
),
11883 to_underlying (child_origin_die
->sect_off
));
11884 if (child_origin_die
->parent
!= origin_die
)
11885 complaint (&symfile_complaints
,
11886 _("Child DIE 0x%x and its abstract origin 0x%x have "
11887 "different parents"),
11888 to_underlying (child_die
->sect_off
),
11889 to_underlying (child_origin_die
->sect_off
));
11891 offsets
.push_back (child_origin_die
->sect_off
);
11894 std::sort (offsets
.begin (), offsets
.end ());
11895 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
11896 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
11897 if (offsetp
[-1] == *offsetp
)
11898 complaint (&symfile_complaints
,
11899 _("Multiple children of DIE 0x%x refer "
11900 "to DIE 0x%x as their abstract origin"),
11901 to_underlying (die
->sect_off
), to_underlying (*offsetp
));
11903 offsetp
= offsets
.data ();
11904 origin_child_die
= origin_die
->child
;
11905 while (origin_child_die
&& origin_child_die
->tag
)
11907 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
11908 while (offsetp
< offsets_end
11909 && *offsetp
< origin_child_die
->sect_off
)
11911 if (offsetp
>= offsets_end
11912 || *offsetp
> origin_child_die
->sect_off
)
11914 /* Found that ORIGIN_CHILD_DIE is really not referenced.
11915 Check whether we're already processing ORIGIN_CHILD_DIE.
11916 This can happen with mutually referenced abstract_origins.
11918 if (!origin_child_die
->in_process
)
11919 process_die (origin_child_die
, origin_cu
);
11921 origin_child_die
= sibling_die (origin_child_die
);
11923 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
11927 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11929 struct objfile
*objfile
= cu
->objfile
;
11930 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11931 struct context_stack
*newobj
;
11934 struct die_info
*child_die
;
11935 struct attribute
*attr
, *call_line
, *call_file
;
11937 CORE_ADDR baseaddr
;
11938 struct block
*block
;
11939 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11940 VEC (symbolp
) *template_args
= NULL
;
11941 struct template_symbol
*templ_func
= NULL
;
11945 /* If we do not have call site information, we can't show the
11946 caller of this inlined function. That's too confusing, so
11947 only use the scope for local variables. */
11948 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
11949 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
11950 if (call_line
== NULL
|| call_file
== NULL
)
11952 read_lexical_block_scope (die
, cu
);
11957 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11959 name
= dwarf2_name (die
, cu
);
11961 /* Ignore functions with missing or empty names. These are actually
11962 illegal according to the DWARF standard. */
11965 complaint (&symfile_complaints
,
11966 _("missing name for subprogram DIE at %d"),
11967 to_underlying (die
->sect_off
));
11971 /* Ignore functions with missing or invalid low and high pc attributes. */
11972 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
11973 <= PC_BOUNDS_INVALID
)
11975 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
11976 if (!attr
|| !DW_UNSND (attr
))
11977 complaint (&symfile_complaints
,
11978 _("cannot get low and high bounds "
11979 "for subprogram DIE at %d"),
11980 to_underlying (die
->sect_off
));
11984 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11985 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11987 /* If we have any template arguments, then we must allocate a
11988 different sort of symbol. */
11989 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
11991 if (child_die
->tag
== DW_TAG_template_type_param
11992 || child_die
->tag
== DW_TAG_template_value_param
)
11994 templ_func
= allocate_template_symbol (objfile
);
11995 templ_func
->base
.is_cplus_template_function
= 1;
12000 newobj
= push_context (0, lowpc
);
12001 newobj
->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
12002 (struct symbol
*) templ_func
);
12004 /* If there is a location expression for DW_AT_frame_base, record
12006 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12008 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12010 /* If there is a location for the static link, record it. */
12011 newobj
->static_link
= NULL
;
12012 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12015 newobj
->static_link
12016 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12017 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
12020 cu
->list_in_scope
= &local_symbols
;
12022 if (die
->child
!= NULL
)
12024 child_die
= die
->child
;
12025 while (child_die
&& child_die
->tag
)
12027 if (child_die
->tag
== DW_TAG_template_type_param
12028 || child_die
->tag
== DW_TAG_template_value_param
)
12030 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12033 VEC_safe_push (symbolp
, template_args
, arg
);
12036 process_die (child_die
, cu
);
12037 child_die
= sibling_die (child_die
);
12041 inherit_abstract_dies (die
, cu
);
12043 /* If we have a DW_AT_specification, we might need to import using
12044 directives from the context of the specification DIE. See the
12045 comment in determine_prefix. */
12046 if (cu
->language
== language_cplus
12047 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12049 struct dwarf2_cu
*spec_cu
= cu
;
12050 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12054 child_die
= spec_die
->child
;
12055 while (child_die
&& child_die
->tag
)
12057 if (child_die
->tag
== DW_TAG_imported_module
)
12058 process_die (child_die
, spec_cu
);
12059 child_die
= sibling_die (child_die
);
12062 /* In some cases, GCC generates specification DIEs that
12063 themselves contain DW_AT_specification attributes. */
12064 spec_die
= die_specification (spec_die
, &spec_cu
);
12068 newobj
= pop_context ();
12069 /* Make a block for the local symbols within. */
12070 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
12071 newobj
->static_link
, lowpc
, highpc
);
12073 /* For C++, set the block's scope. */
12074 if ((cu
->language
== language_cplus
12075 || cu
->language
== language_fortran
12076 || cu
->language
== language_d
12077 || cu
->language
== language_rust
)
12078 && cu
->processing_has_namespace_info
)
12079 block_set_scope (block
, determine_prefix (die
, cu
),
12080 &objfile
->objfile_obstack
);
12082 /* If we have address ranges, record them. */
12083 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12085 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
12087 /* Attach template arguments to function. */
12088 if (! VEC_empty (symbolp
, template_args
))
12090 gdb_assert (templ_func
!= NULL
);
12092 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
12093 templ_func
->template_arguments
12094 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12095 templ_func
->n_template_arguments
);
12096 memcpy (templ_func
->template_arguments
,
12097 VEC_address (symbolp
, template_args
),
12098 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12099 VEC_free (symbolp
, template_args
);
12102 /* In C++, we can have functions nested inside functions (e.g., when
12103 a function declares a class that has methods). This means that
12104 when we finish processing a function scope, we may need to go
12105 back to building a containing block's symbol lists. */
12106 local_symbols
= newobj
->locals
;
12107 local_using_directives
= newobj
->local_using_directives
;
12109 /* If we've finished processing a top-level function, subsequent
12110 symbols go in the file symbol list. */
12111 if (outermost_context_p ())
12112 cu
->list_in_scope
= &file_symbols
;
12115 /* Process all the DIES contained within a lexical block scope. Start
12116 a new scope, process the dies, and then close the scope. */
12119 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12121 struct objfile
*objfile
= cu
->objfile
;
12122 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12123 struct context_stack
*newobj
;
12124 CORE_ADDR lowpc
, highpc
;
12125 struct die_info
*child_die
;
12126 CORE_ADDR baseaddr
;
12128 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12130 /* Ignore blocks with missing or invalid low and high pc attributes. */
12131 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
12132 as multiple lexical blocks? Handling children in a sane way would
12133 be nasty. Might be easier to properly extend generic blocks to
12134 describe ranges. */
12135 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
12137 case PC_BOUNDS_NOT_PRESENT
:
12138 /* DW_TAG_lexical_block has no attributes, process its children as if
12139 there was no wrapping by that DW_TAG_lexical_block.
12140 GCC does no longer produces such DWARF since GCC r224161. */
12141 for (child_die
= die
->child
;
12142 child_die
!= NULL
&& child_die
->tag
;
12143 child_die
= sibling_die (child_die
))
12144 process_die (child_die
, cu
);
12146 case PC_BOUNDS_INVALID
:
12149 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12150 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12152 push_context (0, lowpc
);
12153 if (die
->child
!= NULL
)
12155 child_die
= die
->child
;
12156 while (child_die
&& child_die
->tag
)
12158 process_die (child_die
, cu
);
12159 child_die
= sibling_die (child_die
);
12162 inherit_abstract_dies (die
, cu
);
12163 newobj
= pop_context ();
12165 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
12167 struct block
*block
12168 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
12169 newobj
->start_addr
, highpc
);
12171 /* Note that recording ranges after traversing children, as we
12172 do here, means that recording a parent's ranges entails
12173 walking across all its children's ranges as they appear in
12174 the address map, which is quadratic behavior.
12176 It would be nicer to record the parent's ranges before
12177 traversing its children, simply overriding whatever you find
12178 there. But since we don't even decide whether to create a
12179 block until after we've traversed its children, that's hard
12181 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12183 local_symbols
= newobj
->locals
;
12184 local_using_directives
= newobj
->local_using_directives
;
12187 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
12190 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12192 struct objfile
*objfile
= cu
->objfile
;
12193 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12194 CORE_ADDR pc
, baseaddr
;
12195 struct attribute
*attr
;
12196 struct call_site
*call_site
, call_site_local
;
12199 struct die_info
*child_die
;
12201 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12203 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
12206 /* This was a pre-DWARF-5 GNU extension alias
12207 for DW_AT_call_return_pc. */
12208 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12212 complaint (&symfile_complaints
,
12213 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
12214 "DIE 0x%x [in module %s]"),
12215 to_underlying (die
->sect_off
), objfile_name (objfile
));
12218 pc
= attr_value_as_address (attr
) + baseaddr
;
12219 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
12221 if (cu
->call_site_htab
== NULL
)
12222 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
12223 NULL
, &objfile
->objfile_obstack
,
12224 hashtab_obstack_allocate
, NULL
);
12225 call_site_local
.pc
= pc
;
12226 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
12229 complaint (&symfile_complaints
,
12230 _("Duplicate PC %s for DW_TAG_call_site "
12231 "DIE 0x%x [in module %s]"),
12232 paddress (gdbarch
, pc
), to_underlying (die
->sect_off
),
12233 objfile_name (objfile
));
12237 /* Count parameters at the caller. */
12240 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
12241 child_die
= sibling_die (child_die
))
12243 if (child_die
->tag
!= DW_TAG_call_site_parameter
12244 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
12246 complaint (&symfile_complaints
,
12247 _("Tag %d is not DW_TAG_call_site_parameter in "
12248 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12249 child_die
->tag
, to_underlying (child_die
->sect_off
),
12250 objfile_name (objfile
));
12258 = ((struct call_site
*)
12259 obstack_alloc (&objfile
->objfile_obstack
,
12260 sizeof (*call_site
)
12261 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
12263 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
12264 call_site
->pc
= pc
;
12266 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
12267 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
12269 struct die_info
*func_die
;
12271 /* Skip also over DW_TAG_inlined_subroutine. */
12272 for (func_die
= die
->parent
;
12273 func_die
&& func_die
->tag
!= DW_TAG_subprogram
12274 && func_die
->tag
!= DW_TAG_subroutine_type
;
12275 func_die
= func_die
->parent
);
12277 /* DW_AT_call_all_calls is a superset
12278 of DW_AT_call_all_tail_calls. */
12280 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
12281 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
12282 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
12283 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
12285 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
12286 not complete. But keep CALL_SITE for look ups via call_site_htab,
12287 both the initial caller containing the real return address PC and
12288 the final callee containing the current PC of a chain of tail
12289 calls do not need to have the tail call list complete. But any
12290 function candidate for a virtual tail call frame searched via
12291 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
12292 determined unambiguously. */
12296 struct type
*func_type
= NULL
;
12299 func_type
= get_die_type (func_die
, cu
);
12300 if (func_type
!= NULL
)
12302 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
12304 /* Enlist this call site to the function. */
12305 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
12306 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
12309 complaint (&symfile_complaints
,
12310 _("Cannot find function owning DW_TAG_call_site "
12311 "DIE 0x%x [in module %s]"),
12312 to_underlying (die
->sect_off
), objfile_name (objfile
));
12316 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
12318 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
12320 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
12323 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
12324 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12326 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
12327 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
12328 /* Keep NULL DWARF_BLOCK. */;
12329 else if (attr_form_is_block (attr
))
12331 struct dwarf2_locexpr_baton
*dlbaton
;
12333 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
12334 dlbaton
->data
= DW_BLOCK (attr
)->data
;
12335 dlbaton
->size
= DW_BLOCK (attr
)->size
;
12336 dlbaton
->per_cu
= cu
->per_cu
;
12338 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
12340 else if (attr_form_is_ref (attr
))
12342 struct dwarf2_cu
*target_cu
= cu
;
12343 struct die_info
*target_die
;
12345 target_die
= follow_die_ref (die
, attr
, &target_cu
);
12346 gdb_assert (target_cu
->objfile
== objfile
);
12347 if (die_is_declaration (target_die
, target_cu
))
12349 const char *target_physname
;
12351 /* Prefer the mangled name; otherwise compute the demangled one. */
12352 target_physname
= dw2_linkage_name (target_die
, target_cu
);
12353 if (target_physname
== NULL
)
12354 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
12355 if (target_physname
== NULL
)
12356 complaint (&symfile_complaints
,
12357 _("DW_AT_call_target target DIE has invalid "
12358 "physname, for referencing DIE 0x%x [in module %s]"),
12359 to_underlying (die
->sect_off
), objfile_name (objfile
));
12361 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
12367 /* DW_AT_entry_pc should be preferred. */
12368 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
12369 <= PC_BOUNDS_INVALID
)
12370 complaint (&symfile_complaints
,
12371 _("DW_AT_call_target target DIE has invalid "
12372 "low pc, for referencing DIE 0x%x [in module %s]"),
12373 to_underlying (die
->sect_off
), objfile_name (objfile
));
12376 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12377 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
12382 complaint (&symfile_complaints
,
12383 _("DW_TAG_call_site DW_AT_call_target is neither "
12384 "block nor reference, for DIE 0x%x [in module %s]"),
12385 to_underlying (die
->sect_off
), objfile_name (objfile
));
12387 call_site
->per_cu
= cu
->per_cu
;
12389 for (child_die
= die
->child
;
12390 child_die
&& child_die
->tag
;
12391 child_die
= sibling_die (child_die
))
12393 struct call_site_parameter
*parameter
;
12394 struct attribute
*loc
, *origin
;
12396 if (child_die
->tag
!= DW_TAG_call_site_parameter
12397 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
12399 /* Already printed the complaint above. */
12403 gdb_assert (call_site
->parameter_count
< nparams
);
12404 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
12406 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
12407 specifies DW_TAG_formal_parameter. Value of the data assumed for the
12408 register is contained in DW_AT_call_value. */
12410 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
12411 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
12412 if (origin
== NULL
)
12414 /* This was a pre-DWARF-5 GNU extension alias
12415 for DW_AT_call_parameter. */
12416 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
12418 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
12420 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
12422 sect_offset sect_off
12423 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
12424 if (!offset_in_cu_p (&cu
->header
, sect_off
))
12426 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
12427 binding can be done only inside one CU. Such referenced DIE
12428 therefore cannot be even moved to DW_TAG_partial_unit. */
12429 complaint (&symfile_complaints
,
12430 _("DW_AT_call_parameter offset is not in CU for "
12431 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12432 to_underlying (child_die
->sect_off
),
12433 objfile_name (objfile
));
12436 parameter
->u
.param_cu_off
12437 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
12439 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
12441 complaint (&symfile_complaints
,
12442 _("No DW_FORM_block* DW_AT_location for "
12443 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12444 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
12449 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
12450 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
12451 if (parameter
->u
.dwarf_reg
!= -1)
12452 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
12453 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
12454 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
12455 ¶meter
->u
.fb_offset
))
12456 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
12459 complaint (&symfile_complaints
,
12460 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
12461 "for DW_FORM_block* DW_AT_location is supported for "
12462 "DW_TAG_call_site child DIE 0x%x "
12464 to_underlying (child_die
->sect_off
),
12465 objfile_name (objfile
));
12470 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
12472 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
12473 if (!attr_form_is_block (attr
))
12475 complaint (&symfile_complaints
,
12476 _("No DW_FORM_block* DW_AT_call_value for "
12477 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12478 to_underlying (child_die
->sect_off
),
12479 objfile_name (objfile
));
12482 parameter
->value
= DW_BLOCK (attr
)->data
;
12483 parameter
->value_size
= DW_BLOCK (attr
)->size
;
12485 /* Parameters are not pre-cleared by memset above. */
12486 parameter
->data_value
= NULL
;
12487 parameter
->data_value_size
= 0;
12488 call_site
->parameter_count
++;
12490 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
12492 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
12495 if (!attr_form_is_block (attr
))
12496 complaint (&symfile_complaints
,
12497 _("No DW_FORM_block* DW_AT_call_data_value for "
12498 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12499 to_underlying (child_die
->sect_off
),
12500 objfile_name (objfile
));
12503 parameter
->data_value
= DW_BLOCK (attr
)->data
;
12504 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
12510 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
12511 reading .debug_rnglists.
12512 Callback's type should be:
12513 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
12514 Return true if the attributes are present and valid, otherwise,
12517 template <typename Callback
>
12519 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
12520 Callback
&&callback
)
12522 struct objfile
*objfile
= cu
->objfile
;
12523 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12524 struct comp_unit_head
*cu_header
= &cu
->header
;
12525 bfd
*obfd
= objfile
->obfd
;
12526 unsigned int addr_size
= cu_header
->addr_size
;
12527 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12528 /* Base address selection entry. */
12531 unsigned int dummy
;
12532 const gdb_byte
*buffer
;
12534 CORE_ADDR high
= 0;
12535 CORE_ADDR baseaddr
;
12536 bool overflow
= false;
12538 found_base
= cu
->base_known
;
12539 base
= cu
->base_address
;
12541 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
12542 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
12544 complaint (&symfile_complaints
,
12545 _("Offset %d out of bounds for DW_AT_ranges attribute"),
12549 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
12551 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12555 /* Initialize it due to a false compiler warning. */
12556 CORE_ADDR range_beginning
= 0, range_end
= 0;
12557 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
12558 + dwarf2_per_objfile
->rnglists
.size
);
12559 unsigned int bytes_read
;
12561 if (buffer
== buf_end
)
12566 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
12569 case DW_RLE_end_of_list
:
12571 case DW_RLE_base_address
:
12572 if (buffer
+ cu
->header
.addr_size
> buf_end
)
12577 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12579 buffer
+= bytes_read
;
12581 case DW_RLE_start_length
:
12582 if (buffer
+ cu
->header
.addr_size
> buf_end
)
12587 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12588 buffer
+= bytes_read
;
12589 range_end
= (range_beginning
12590 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
12591 buffer
+= bytes_read
;
12592 if (buffer
> buf_end
)
12598 case DW_RLE_offset_pair
:
12599 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12600 buffer
+= bytes_read
;
12601 if (buffer
> buf_end
)
12606 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12607 buffer
+= bytes_read
;
12608 if (buffer
> buf_end
)
12614 case DW_RLE_start_end
:
12615 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
12620 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12621 buffer
+= bytes_read
;
12622 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12623 buffer
+= bytes_read
;
12626 complaint (&symfile_complaints
,
12627 _("Invalid .debug_rnglists data (no base address)"));
12630 if (rlet
== DW_RLE_end_of_list
|| overflow
)
12632 if (rlet
== DW_RLE_base_address
)
12637 /* We have no valid base address for the ranges
12639 complaint (&symfile_complaints
,
12640 _("Invalid .debug_rnglists data (no base address)"));
12644 if (range_beginning
> range_end
)
12646 /* Inverted range entries are invalid. */
12647 complaint (&symfile_complaints
,
12648 _("Invalid .debug_rnglists data (inverted range)"));
12652 /* Empty range entries have no effect. */
12653 if (range_beginning
== range_end
)
12656 range_beginning
+= base
;
12659 /* A not-uncommon case of bad debug info.
12660 Don't pollute the addrmap with bad data. */
12661 if (range_beginning
+ baseaddr
== 0
12662 && !dwarf2_per_objfile
->has_section_at_zero
)
12664 complaint (&symfile_complaints
,
12665 _(".debug_rnglists entry has start address of zero"
12666 " [in module %s]"), objfile_name (objfile
));
12670 callback (range_beginning
, range_end
);
12675 complaint (&symfile_complaints
,
12676 _("Offset %d is not terminated "
12677 "for DW_AT_ranges attribute"),
12685 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
12686 Callback's type should be:
12687 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
12688 Return 1 if the attributes are present and valid, otherwise, return 0. */
12690 template <typename Callback
>
12692 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
12693 Callback
&&callback
)
12695 struct objfile
*objfile
= cu
->objfile
;
12696 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12697 struct comp_unit_head
*cu_header
= &cu
->header
;
12698 bfd
*obfd
= objfile
->obfd
;
12699 unsigned int addr_size
= cu_header
->addr_size
;
12700 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12701 /* Base address selection entry. */
12704 unsigned int dummy
;
12705 const gdb_byte
*buffer
;
12706 CORE_ADDR baseaddr
;
12708 if (cu_header
->version
>= 5)
12709 return dwarf2_rnglists_process (offset
, cu
, callback
);
12711 found_base
= cu
->base_known
;
12712 base
= cu
->base_address
;
12714 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
12715 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
12717 complaint (&symfile_complaints
,
12718 _("Offset %d out of bounds for DW_AT_ranges attribute"),
12722 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
12724 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12728 CORE_ADDR range_beginning
, range_end
;
12730 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
12731 buffer
+= addr_size
;
12732 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
12733 buffer
+= addr_size
;
12734 offset
+= 2 * addr_size
;
12736 /* An end of list marker is a pair of zero addresses. */
12737 if (range_beginning
== 0 && range_end
== 0)
12738 /* Found the end of list entry. */
12741 /* Each base address selection entry is a pair of 2 values.
12742 The first is the largest possible address, the second is
12743 the base address. Check for a base address here. */
12744 if ((range_beginning
& mask
) == mask
)
12746 /* If we found the largest possible address, then we already
12747 have the base address in range_end. */
12755 /* We have no valid base address for the ranges
12757 complaint (&symfile_complaints
,
12758 _("Invalid .debug_ranges data (no base address)"));
12762 if (range_beginning
> range_end
)
12764 /* Inverted range entries are invalid. */
12765 complaint (&symfile_complaints
,
12766 _("Invalid .debug_ranges data (inverted range)"));
12770 /* Empty range entries have no effect. */
12771 if (range_beginning
== range_end
)
12774 range_beginning
+= base
;
12777 /* A not-uncommon case of bad debug info.
12778 Don't pollute the addrmap with bad data. */
12779 if (range_beginning
+ baseaddr
== 0
12780 && !dwarf2_per_objfile
->has_section_at_zero
)
12782 complaint (&symfile_complaints
,
12783 _(".debug_ranges entry has start address of zero"
12784 " [in module %s]"), objfile_name (objfile
));
12788 callback (range_beginning
, range_end
);
12794 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
12795 Return 1 if the attributes are present and valid, otherwise, return 0.
12796 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
12799 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
12800 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
12801 struct partial_symtab
*ranges_pst
)
12803 struct objfile
*objfile
= cu
->objfile
;
12804 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12805 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
12806 SECT_OFF_TEXT (objfile
));
12809 CORE_ADDR high
= 0;
12812 retval
= dwarf2_ranges_process (offset
, cu
,
12813 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
12815 if (ranges_pst
!= NULL
)
12820 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
12821 range_beginning
+ baseaddr
);
12822 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
12823 range_end
+ baseaddr
);
12824 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
12828 /* FIXME: This is recording everything as a low-high
12829 segment of consecutive addresses. We should have a
12830 data structure for discontiguous block ranges
12834 low
= range_beginning
;
12840 if (range_beginning
< low
)
12841 low
= range_beginning
;
12842 if (range_end
> high
)
12850 /* If the first entry is an end-of-list marker, the range
12851 describes an empty scope, i.e. no instructions. */
12857 *high_return
= high
;
12861 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
12862 definition for the return value. *LOWPC and *HIGHPC are set iff
12863 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
12865 static enum pc_bounds_kind
12866 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
12867 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
12868 struct partial_symtab
*pst
)
12870 struct attribute
*attr
;
12871 struct attribute
*attr_high
;
12873 CORE_ADDR high
= 0;
12874 enum pc_bounds_kind ret
;
12876 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12879 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12882 low
= attr_value_as_address (attr
);
12883 high
= attr_value_as_address (attr_high
);
12884 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12888 /* Found high w/o low attribute. */
12889 return PC_BOUNDS_INVALID
;
12891 /* Found consecutive range of addresses. */
12892 ret
= PC_BOUNDS_HIGH_LOW
;
12896 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12899 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12900 We take advantage of the fact that DW_AT_ranges does not appear
12901 in DW_TAG_compile_unit of DWO files. */
12902 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12903 unsigned int ranges_offset
= (DW_UNSND (attr
)
12904 + (need_ranges_base
12908 /* Value of the DW_AT_ranges attribute is the offset in the
12909 .debug_ranges section. */
12910 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
12911 return PC_BOUNDS_INVALID
;
12912 /* Found discontinuous range of addresses. */
12913 ret
= PC_BOUNDS_RANGES
;
12916 return PC_BOUNDS_NOT_PRESENT
;
12919 /* read_partial_die has also the strict LOW < HIGH requirement. */
12921 return PC_BOUNDS_INVALID
;
12923 /* When using the GNU linker, .gnu.linkonce. sections are used to
12924 eliminate duplicate copies of functions and vtables and such.
12925 The linker will arbitrarily choose one and discard the others.
12926 The AT_*_pc values for such functions refer to local labels in
12927 these sections. If the section from that file was discarded, the
12928 labels are not in the output, so the relocs get a value of 0.
12929 If this is a discarded function, mark the pc bounds as invalid,
12930 so that GDB will ignore it. */
12931 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12932 return PC_BOUNDS_INVALID
;
12940 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
12941 its low and high PC addresses. Do nothing if these addresses could not
12942 be determined. Otherwise, set LOWPC to the low address if it is smaller,
12943 and HIGHPC to the high address if greater than HIGHPC. */
12946 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
12947 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12948 struct dwarf2_cu
*cu
)
12950 CORE_ADDR low
, high
;
12951 struct die_info
*child
= die
->child
;
12953 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
12955 *lowpc
= std::min (*lowpc
, low
);
12956 *highpc
= std::max (*highpc
, high
);
12959 /* If the language does not allow nested subprograms (either inside
12960 subprograms or lexical blocks), we're done. */
12961 if (cu
->language
!= language_ada
)
12964 /* Check all the children of the given DIE. If it contains nested
12965 subprograms, then check their pc bounds. Likewise, we need to
12966 check lexical blocks as well, as they may also contain subprogram
12968 while (child
&& child
->tag
)
12970 if (child
->tag
== DW_TAG_subprogram
12971 || child
->tag
== DW_TAG_lexical_block
)
12972 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
12973 child
= sibling_die (child
);
12977 /* Get the low and high pc's represented by the scope DIE, and store
12978 them in *LOWPC and *HIGHPC. If the correct values can't be
12979 determined, set *LOWPC to -1 and *HIGHPC to 0. */
12982 get_scope_pc_bounds (struct die_info
*die
,
12983 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12984 struct dwarf2_cu
*cu
)
12986 CORE_ADDR best_low
= (CORE_ADDR
) -1;
12987 CORE_ADDR best_high
= (CORE_ADDR
) 0;
12988 CORE_ADDR current_low
, current_high
;
12990 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
12991 >= PC_BOUNDS_RANGES
)
12993 best_low
= current_low
;
12994 best_high
= current_high
;
12998 struct die_info
*child
= die
->child
;
13000 while (child
&& child
->tag
)
13002 switch (child
->tag
) {
13003 case DW_TAG_subprogram
:
13004 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13006 case DW_TAG_namespace
:
13007 case DW_TAG_module
:
13008 /* FIXME: carlton/2004-01-16: Should we do this for
13009 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13010 that current GCC's always emit the DIEs corresponding
13011 to definitions of methods of classes as children of a
13012 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13013 the DIEs giving the declarations, which could be
13014 anywhere). But I don't see any reason why the
13015 standards says that they have to be there. */
13016 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13018 if (current_low
!= ((CORE_ADDR
) -1))
13020 best_low
= std::min (best_low
, current_low
);
13021 best_high
= std::max (best_high
, current_high
);
13029 child
= sibling_die (child
);
13034 *highpc
= best_high
;
13037 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13041 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13042 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13044 struct objfile
*objfile
= cu
->objfile
;
13045 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13046 struct attribute
*attr
;
13047 struct attribute
*attr_high
;
13049 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13052 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13055 CORE_ADDR low
= attr_value_as_address (attr
);
13056 CORE_ADDR high
= attr_value_as_address (attr_high
);
13058 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
13061 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13062 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13063 record_block_range (block
, low
, high
- 1);
13067 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13070 bfd
*obfd
= objfile
->obfd
;
13071 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
13072 We take advantage of the fact that DW_AT_ranges does not appear
13073 in DW_TAG_compile_unit of DWO files. */
13074 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13076 /* The value of the DW_AT_ranges attribute is the offset of the
13077 address range list in the .debug_ranges section. */
13078 unsigned long offset
= (DW_UNSND (attr
)
13079 + (need_ranges_base
? cu
->ranges_base
: 0));
13080 const gdb_byte
*buffer
;
13082 /* For some target architectures, but not others, the
13083 read_address function sign-extends the addresses it returns.
13084 To recognize base address selection entries, we need a
13086 unsigned int addr_size
= cu
->header
.addr_size
;
13087 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13089 /* The base address, to which the next pair is relative. Note
13090 that this 'base' is a DWARF concept: most entries in a range
13091 list are relative, to reduce the number of relocs against the
13092 debugging information. This is separate from this function's
13093 'baseaddr' argument, which GDB uses to relocate debugging
13094 information from a shared library based on the address at
13095 which the library was loaded. */
13096 CORE_ADDR base
= cu
->base_address
;
13097 int base_known
= cu
->base_known
;
13099 dwarf2_ranges_process (offset
, cu
,
13100 [&] (CORE_ADDR start
, CORE_ADDR end
)
13104 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
13105 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
13106 record_block_range (block
, start
, end
- 1);
13111 /* Check whether the producer field indicates either of GCC < 4.6, or the
13112 Intel C/C++ compiler, and cache the result in CU. */
13115 check_producer (struct dwarf2_cu
*cu
)
13119 if (cu
->producer
== NULL
)
13121 /* For unknown compilers expect their behavior is DWARF version
13124 GCC started to support .debug_types sections by -gdwarf-4 since
13125 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
13126 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
13127 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
13128 interpreted incorrectly by GDB now - GCC PR debug/48229. */
13130 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
13132 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
13133 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
13135 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
13136 cu
->producer_is_icc_lt_14
= major
< 14;
13139 /* For other non-GCC compilers, expect their behavior is DWARF version
13143 cu
->checked_producer
= 1;
13146 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
13147 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
13148 during 4.6.0 experimental. */
13151 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
13153 if (!cu
->checked_producer
)
13154 check_producer (cu
);
13156 return cu
->producer_is_gxx_lt_4_6
;
13159 /* Return the default accessibility type if it is not overriden by
13160 DW_AT_accessibility. */
13162 static enum dwarf_access_attribute
13163 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
13165 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
13167 /* The default DWARF 2 accessibility for members is public, the default
13168 accessibility for inheritance is private. */
13170 if (die
->tag
!= DW_TAG_inheritance
)
13171 return DW_ACCESS_public
;
13173 return DW_ACCESS_private
;
13177 /* DWARF 3+ defines the default accessibility a different way. The same
13178 rules apply now for DW_TAG_inheritance as for the members and it only
13179 depends on the container kind. */
13181 if (die
->parent
->tag
== DW_TAG_class_type
)
13182 return DW_ACCESS_private
;
13184 return DW_ACCESS_public
;
13188 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
13189 offset. If the attribute was not found return 0, otherwise return
13190 1. If it was found but could not properly be handled, set *OFFSET
13194 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
13197 struct attribute
*attr
;
13199 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
13204 /* Note that we do not check for a section offset first here.
13205 This is because DW_AT_data_member_location is new in DWARF 4,
13206 so if we see it, we can assume that a constant form is really
13207 a constant and not a section offset. */
13208 if (attr_form_is_constant (attr
))
13209 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
13210 else if (attr_form_is_section_offset (attr
))
13211 dwarf2_complex_location_expr_complaint ();
13212 else if (attr_form_is_block (attr
))
13213 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
13215 dwarf2_complex_location_expr_complaint ();
13223 /* Add an aggregate field to the field list. */
13226 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
13227 struct dwarf2_cu
*cu
)
13229 struct objfile
*objfile
= cu
->objfile
;
13230 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13231 struct nextfield
*new_field
;
13232 struct attribute
*attr
;
13234 const char *fieldname
= "";
13236 /* Allocate a new field list entry and link it in. */
13237 new_field
= XNEW (struct nextfield
);
13238 make_cleanup (xfree
, new_field
);
13239 memset (new_field
, 0, sizeof (struct nextfield
));
13241 if (die
->tag
== DW_TAG_inheritance
)
13243 new_field
->next
= fip
->baseclasses
;
13244 fip
->baseclasses
= new_field
;
13248 new_field
->next
= fip
->fields
;
13249 fip
->fields
= new_field
;
13253 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
13255 new_field
->accessibility
= DW_UNSND (attr
);
13257 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
13258 if (new_field
->accessibility
!= DW_ACCESS_public
)
13259 fip
->non_public_fields
= 1;
13261 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
13263 new_field
->virtuality
= DW_UNSND (attr
);
13265 new_field
->virtuality
= DW_VIRTUALITY_none
;
13267 fp
= &new_field
->field
;
13269 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
13273 /* Data member other than a C++ static data member. */
13275 /* Get type of field. */
13276 fp
->type
= die_type (die
, cu
);
13278 SET_FIELD_BITPOS (*fp
, 0);
13280 /* Get bit size of field (zero if none). */
13281 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
13284 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
13288 FIELD_BITSIZE (*fp
) = 0;
13291 /* Get bit offset of field. */
13292 if (handle_data_member_location (die
, cu
, &offset
))
13293 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
13294 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
13297 if (gdbarch_bits_big_endian (gdbarch
))
13299 /* For big endian bits, the DW_AT_bit_offset gives the
13300 additional bit offset from the MSB of the containing
13301 anonymous object to the MSB of the field. We don't
13302 have to do anything special since we don't need to
13303 know the size of the anonymous object. */
13304 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
13308 /* For little endian bits, compute the bit offset to the
13309 MSB of the anonymous object, subtract off the number of
13310 bits from the MSB of the field to the MSB of the
13311 object, and then subtract off the number of bits of
13312 the field itself. The result is the bit offset of
13313 the LSB of the field. */
13314 int anonymous_size
;
13315 int bit_offset
= DW_UNSND (attr
);
13317 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13320 /* The size of the anonymous object containing
13321 the bit field is explicit, so use the
13322 indicated size (in bytes). */
13323 anonymous_size
= DW_UNSND (attr
);
13327 /* The size of the anonymous object containing
13328 the bit field must be inferred from the type
13329 attribute of the data member containing the
13331 anonymous_size
= TYPE_LENGTH (fp
->type
);
13333 SET_FIELD_BITPOS (*fp
,
13334 (FIELD_BITPOS (*fp
)
13335 + anonymous_size
* bits_per_byte
13336 - bit_offset
- FIELD_BITSIZE (*fp
)));
13339 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
13341 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
13342 + dwarf2_get_attr_constant_value (attr
, 0)));
13344 /* Get name of field. */
13345 fieldname
= dwarf2_name (die
, cu
);
13346 if (fieldname
== NULL
)
13349 /* The name is already allocated along with this objfile, so we don't
13350 need to duplicate it for the type. */
13351 fp
->name
= fieldname
;
13353 /* Change accessibility for artificial fields (e.g. virtual table
13354 pointer or virtual base class pointer) to private. */
13355 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
13357 FIELD_ARTIFICIAL (*fp
) = 1;
13358 new_field
->accessibility
= DW_ACCESS_private
;
13359 fip
->non_public_fields
= 1;
13362 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
13364 /* C++ static member. */
13366 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
13367 is a declaration, but all versions of G++ as of this writing
13368 (so through at least 3.2.1) incorrectly generate
13369 DW_TAG_variable tags. */
13371 const char *physname
;
13373 /* Get name of field. */
13374 fieldname
= dwarf2_name (die
, cu
);
13375 if (fieldname
== NULL
)
13378 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13380 /* Only create a symbol if this is an external value.
13381 new_symbol checks this and puts the value in the global symbol
13382 table, which we want. If it is not external, new_symbol
13383 will try to put the value in cu->list_in_scope which is wrong. */
13384 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
13386 /* A static const member, not much different than an enum as far as
13387 we're concerned, except that we can support more types. */
13388 new_symbol (die
, NULL
, cu
);
13391 /* Get physical name. */
13392 physname
= dwarf2_physname (fieldname
, die
, cu
);
13394 /* The name is already allocated along with this objfile, so we don't
13395 need to duplicate it for the type. */
13396 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
13397 FIELD_TYPE (*fp
) = die_type (die
, cu
);
13398 FIELD_NAME (*fp
) = fieldname
;
13400 else if (die
->tag
== DW_TAG_inheritance
)
13404 /* C++ base class field. */
13405 if (handle_data_member_location (die
, cu
, &offset
))
13406 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
13407 FIELD_BITSIZE (*fp
) = 0;
13408 FIELD_TYPE (*fp
) = die_type (die
, cu
);
13409 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
13410 fip
->nbaseclasses
++;
13414 /* Add a typedef defined in the scope of the FIP's class. */
13417 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
13418 struct dwarf2_cu
*cu
)
13420 struct typedef_field_list
*new_field
;
13421 struct typedef_field
*fp
;
13423 /* Allocate a new field list entry and link it in. */
13424 new_field
= XCNEW (struct typedef_field_list
);
13425 make_cleanup (xfree
, new_field
);
13427 gdb_assert (die
->tag
== DW_TAG_typedef
);
13429 fp
= &new_field
->field
;
13431 /* Get name of field. */
13432 fp
->name
= dwarf2_name (die
, cu
);
13433 if (fp
->name
== NULL
)
13436 fp
->type
= read_type_die (die
, cu
);
13438 /* Save accessibility. */
13439 enum dwarf_access_attribute accessibility
;
13440 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
13442 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
13444 accessibility
= dwarf2_default_access_attribute (die
, cu
);
13445 switch (accessibility
)
13447 case DW_ACCESS_public
:
13448 /* The assumed value if neither private nor protected. */
13450 case DW_ACCESS_private
:
13451 fp
->is_private
= 1;
13453 case DW_ACCESS_protected
:
13454 fp
->is_protected
= 1;
13457 complaint (&symfile_complaints
,
13458 _("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
13461 new_field
->next
= fip
->typedef_field_list
;
13462 fip
->typedef_field_list
= new_field
;
13463 fip
->typedef_field_list_count
++;
13466 /* Create the vector of fields, and attach it to the type. */
13469 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
13470 struct dwarf2_cu
*cu
)
13472 int nfields
= fip
->nfields
;
13474 /* Record the field count, allocate space for the array of fields,
13475 and create blank accessibility bitfields if necessary. */
13476 TYPE_NFIELDS (type
) = nfields
;
13477 TYPE_FIELDS (type
) = (struct field
*)
13478 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
13479 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
13481 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
13483 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13485 TYPE_FIELD_PRIVATE_BITS (type
) =
13486 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
13487 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
13489 TYPE_FIELD_PROTECTED_BITS (type
) =
13490 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
13491 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
13493 TYPE_FIELD_IGNORE_BITS (type
) =
13494 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
13495 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
13498 /* If the type has baseclasses, allocate and clear a bit vector for
13499 TYPE_FIELD_VIRTUAL_BITS. */
13500 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
13502 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
13503 unsigned char *pointer
;
13505 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13506 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
13507 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
13508 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
13509 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
13512 /* Copy the saved-up fields into the field vector. Start from the head of
13513 the list, adding to the tail of the field array, so that they end up in
13514 the same order in the array in which they were added to the list. */
13515 while (nfields
-- > 0)
13517 struct nextfield
*fieldp
;
13521 fieldp
= fip
->fields
;
13522 fip
->fields
= fieldp
->next
;
13526 fieldp
= fip
->baseclasses
;
13527 fip
->baseclasses
= fieldp
->next
;
13530 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
13531 switch (fieldp
->accessibility
)
13533 case DW_ACCESS_private
:
13534 if (cu
->language
!= language_ada
)
13535 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
13538 case DW_ACCESS_protected
:
13539 if (cu
->language
!= language_ada
)
13540 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
13543 case DW_ACCESS_public
:
13547 /* Unknown accessibility. Complain and treat it as public. */
13549 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
13550 fieldp
->accessibility
);
13554 if (nfields
< fip
->nbaseclasses
)
13556 switch (fieldp
->virtuality
)
13558 case DW_VIRTUALITY_virtual
:
13559 case DW_VIRTUALITY_pure_virtual
:
13560 if (cu
->language
== language_ada
)
13561 error (_("unexpected virtuality in component of Ada type"));
13562 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
13569 /* Return true if this member function is a constructor, false
13573 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
13575 const char *fieldname
;
13576 const char *type_name
;
13579 if (die
->parent
== NULL
)
13582 if (die
->parent
->tag
!= DW_TAG_structure_type
13583 && die
->parent
->tag
!= DW_TAG_union_type
13584 && die
->parent
->tag
!= DW_TAG_class_type
)
13587 fieldname
= dwarf2_name (die
, cu
);
13588 type_name
= dwarf2_name (die
->parent
, cu
);
13589 if (fieldname
== NULL
|| type_name
== NULL
)
13592 len
= strlen (fieldname
);
13593 return (strncmp (fieldname
, type_name
, len
) == 0
13594 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
13597 /* Add a member function to the proper fieldlist. */
13600 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
13601 struct type
*type
, struct dwarf2_cu
*cu
)
13603 struct objfile
*objfile
= cu
->objfile
;
13604 struct attribute
*attr
;
13605 struct fnfieldlist
*flp
;
13607 struct fn_field
*fnp
;
13608 const char *fieldname
;
13609 struct nextfnfield
*new_fnfield
;
13610 struct type
*this_type
;
13611 enum dwarf_access_attribute accessibility
;
13613 if (cu
->language
== language_ada
)
13614 error (_("unexpected member function in Ada type"));
13616 /* Get name of member function. */
13617 fieldname
= dwarf2_name (die
, cu
);
13618 if (fieldname
== NULL
)
13621 /* Look up member function name in fieldlist. */
13622 for (i
= 0; i
< fip
->nfnfields
; i
++)
13624 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
13628 /* Create new list element if necessary. */
13629 if (i
< fip
->nfnfields
)
13630 flp
= &fip
->fnfieldlists
[i
];
13633 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
13635 fip
->fnfieldlists
= (struct fnfieldlist
*)
13636 xrealloc (fip
->fnfieldlists
,
13637 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
13638 * sizeof (struct fnfieldlist
));
13639 if (fip
->nfnfields
== 0)
13640 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
13642 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
13643 flp
->name
= fieldname
;
13646 i
= fip
->nfnfields
++;
13649 /* Create a new member function field and chain it to the field list
13651 new_fnfield
= XNEW (struct nextfnfield
);
13652 make_cleanup (xfree
, new_fnfield
);
13653 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
13654 new_fnfield
->next
= flp
->head
;
13655 flp
->head
= new_fnfield
;
13658 /* Fill in the member function field info. */
13659 fnp
= &new_fnfield
->fnfield
;
13661 /* Delay processing of the physname until later. */
13662 if (cu
->language
== language_cplus
)
13664 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
13669 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
13670 fnp
->physname
= physname
? physname
: "";
13673 fnp
->type
= alloc_type (objfile
);
13674 this_type
= read_type_die (die
, cu
);
13675 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
13677 int nparams
= TYPE_NFIELDS (this_type
);
13679 /* TYPE is the domain of this method, and THIS_TYPE is the type
13680 of the method itself (TYPE_CODE_METHOD). */
13681 smash_to_method_type (fnp
->type
, type
,
13682 TYPE_TARGET_TYPE (this_type
),
13683 TYPE_FIELDS (this_type
),
13684 TYPE_NFIELDS (this_type
),
13685 TYPE_VARARGS (this_type
));
13687 /* Handle static member functions.
13688 Dwarf2 has no clean way to discern C++ static and non-static
13689 member functions. G++ helps GDB by marking the first
13690 parameter for non-static member functions (which is the this
13691 pointer) as artificial. We obtain this information from
13692 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
13693 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
13694 fnp
->voffset
= VOFFSET_STATIC
;
13697 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
13698 dwarf2_full_name (fieldname
, die
, cu
));
13700 /* Get fcontext from DW_AT_containing_type if present. */
13701 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
13702 fnp
->fcontext
= die_containing_type (die
, cu
);
13704 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
13705 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
13707 /* Get accessibility. */
13708 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
13710 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
13712 accessibility
= dwarf2_default_access_attribute (die
, cu
);
13713 switch (accessibility
)
13715 case DW_ACCESS_private
:
13716 fnp
->is_private
= 1;
13718 case DW_ACCESS_protected
:
13719 fnp
->is_protected
= 1;
13723 /* Check for artificial methods. */
13724 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
13725 if (attr
&& DW_UNSND (attr
) != 0)
13726 fnp
->is_artificial
= 1;
13728 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
13730 /* Get index in virtual function table if it is a virtual member
13731 function. For older versions of GCC, this is an offset in the
13732 appropriate virtual table, as specified by DW_AT_containing_type.
13733 For everyone else, it is an expression to be evaluated relative
13734 to the object address. */
13736 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
13739 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
13741 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
13743 /* Old-style GCC. */
13744 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
13746 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
13747 || (DW_BLOCK (attr
)->size
> 1
13748 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
13749 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
13751 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
13752 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
13753 dwarf2_complex_location_expr_complaint ();
13755 fnp
->voffset
/= cu
->header
.addr_size
;
13759 dwarf2_complex_location_expr_complaint ();
13761 if (!fnp
->fcontext
)
13763 /* If there is no `this' field and no DW_AT_containing_type,
13764 we cannot actually find a base class context for the
13766 if (TYPE_NFIELDS (this_type
) == 0
13767 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
13769 complaint (&symfile_complaints
,
13770 _("cannot determine context for virtual member "
13771 "function \"%s\" (offset %d)"),
13772 fieldname
, to_underlying (die
->sect_off
));
13777 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
13781 else if (attr_form_is_section_offset (attr
))
13783 dwarf2_complex_location_expr_complaint ();
13787 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
13793 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
13794 if (attr
&& DW_UNSND (attr
))
13796 /* GCC does this, as of 2008-08-25; PR debug/37237. */
13797 complaint (&symfile_complaints
,
13798 _("Member function \"%s\" (offset %d) is virtual "
13799 "but the vtable offset is not specified"),
13800 fieldname
, to_underlying (die
->sect_off
));
13801 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13802 TYPE_CPLUS_DYNAMIC (type
) = 1;
13807 /* Create the vector of member function fields, and attach it to the type. */
13810 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
13811 struct dwarf2_cu
*cu
)
13813 struct fnfieldlist
*flp
;
13816 if (cu
->language
== language_ada
)
13817 error (_("unexpected member functions in Ada type"));
13819 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13820 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
13821 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
13823 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
13825 struct nextfnfield
*nfp
= flp
->head
;
13826 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
13829 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
13830 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
13831 fn_flp
->fn_fields
= (struct fn_field
*)
13832 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
13833 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
13834 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
13837 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
13840 /* Returns non-zero if NAME is the name of a vtable member in CU's
13841 language, zero otherwise. */
13843 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
13845 static const char vptr
[] = "_vptr";
13846 static const char vtable
[] = "vtable";
13848 /* Look for the C++ form of the vtable. */
13849 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
13855 /* GCC outputs unnamed structures that are really pointers to member
13856 functions, with the ABI-specified layout. If TYPE describes
13857 such a structure, smash it into a member function type.
13859 GCC shouldn't do this; it should just output pointer to member DIEs.
13860 This is GCC PR debug/28767. */
13863 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
13865 struct type
*pfn_type
, *self_type
, *new_type
;
13867 /* Check for a structure with no name and two children. */
13868 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
13871 /* Check for __pfn and __delta members. */
13872 if (TYPE_FIELD_NAME (type
, 0) == NULL
13873 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
13874 || TYPE_FIELD_NAME (type
, 1) == NULL
13875 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
13878 /* Find the type of the method. */
13879 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
13880 if (pfn_type
== NULL
13881 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
13882 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
13885 /* Look for the "this" argument. */
13886 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
13887 if (TYPE_NFIELDS (pfn_type
) == 0
13888 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
13889 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
13892 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
13893 new_type
= alloc_type (objfile
);
13894 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
13895 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
13896 TYPE_VARARGS (pfn_type
));
13897 smash_to_methodptr_type (type
, new_type
);
13901 /* Called when we find the DIE that starts a structure or union scope
13902 (definition) to create a type for the structure or union. Fill in
13903 the type's name and general properties; the members will not be
13904 processed until process_structure_scope. A symbol table entry for
13905 the type will also not be done until process_structure_scope (assuming
13906 the type has a name).
13908 NOTE: we need to call these functions regardless of whether or not the
13909 DIE has a DW_AT_name attribute, since it might be an anonymous
13910 structure or union. This gets the type entered into our set of
13911 user defined types. */
13913 static struct type
*
13914 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13916 struct objfile
*objfile
= cu
->objfile
;
13918 struct attribute
*attr
;
13921 /* If the definition of this type lives in .debug_types, read that type.
13922 Don't follow DW_AT_specification though, that will take us back up
13923 the chain and we want to go down. */
13924 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
13927 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13929 /* The type's CU may not be the same as CU.
13930 Ensure TYPE is recorded with CU in die_type_hash. */
13931 return set_die_type (die
, type
, cu
);
13934 type
= alloc_type (objfile
);
13935 INIT_CPLUS_SPECIFIC (type
);
13937 name
= dwarf2_name (die
, cu
);
13940 if (cu
->language
== language_cplus
13941 || cu
->language
== language_d
13942 || cu
->language
== language_rust
)
13944 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
13946 /* dwarf2_full_name might have already finished building the DIE's
13947 type. If so, there is no need to continue. */
13948 if (get_die_type (die
, cu
) != NULL
)
13949 return get_die_type (die
, cu
);
13951 TYPE_TAG_NAME (type
) = full_name
;
13952 if (die
->tag
== DW_TAG_structure_type
13953 || die
->tag
== DW_TAG_class_type
)
13954 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13958 /* The name is already allocated along with this objfile, so
13959 we don't need to duplicate it for the type. */
13960 TYPE_TAG_NAME (type
) = name
;
13961 if (die
->tag
== DW_TAG_class_type
)
13962 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13966 if (die
->tag
== DW_TAG_structure_type
)
13968 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13970 else if (die
->tag
== DW_TAG_union_type
)
13972 TYPE_CODE (type
) = TYPE_CODE_UNION
;
13976 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13979 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
13980 TYPE_DECLARED_CLASS (type
) = 1;
13982 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13985 if (attr_form_is_constant (attr
))
13986 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13989 /* For the moment, dynamic type sizes are not supported
13990 by GDB's struct type. The actual size is determined
13991 on-demand when resolving the type of a given object,
13992 so set the type's length to zero for now. Otherwise,
13993 we record an expression as the length, and that expression
13994 could lead to a very large value, which could eventually
13995 lead to us trying to allocate that much memory when creating
13996 a value of that type. */
13997 TYPE_LENGTH (type
) = 0;
14002 TYPE_LENGTH (type
) = 0;
14005 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
14007 /* ICC<14 does not output the required DW_AT_declaration on
14008 incomplete types, but gives them a size of zero. */
14009 TYPE_STUB (type
) = 1;
14012 TYPE_STUB_SUPPORTED (type
) = 1;
14014 if (die_is_declaration (die
, cu
))
14015 TYPE_STUB (type
) = 1;
14016 else if (attr
== NULL
&& die
->child
== NULL
14017 && producer_is_realview (cu
->producer
))
14018 /* RealView does not output the required DW_AT_declaration
14019 on incomplete types. */
14020 TYPE_STUB (type
) = 1;
14022 /* We need to add the type field to the die immediately so we don't
14023 infinitely recurse when dealing with pointers to the structure
14024 type within the structure itself. */
14025 set_die_type (die
, type
, cu
);
14027 /* set_die_type should be already done. */
14028 set_descriptive_type (type
, die
, cu
);
14033 /* Finish creating a structure or union type, including filling in
14034 its members and creating a symbol for it. */
14037 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14039 struct objfile
*objfile
= cu
->objfile
;
14040 struct die_info
*child_die
;
14043 type
= get_die_type (die
, cu
);
14045 type
= read_structure_type (die
, cu
);
14047 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
14049 struct field_info fi
;
14050 VEC (symbolp
) *template_args
= NULL
;
14051 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
14053 memset (&fi
, 0, sizeof (struct field_info
));
14055 child_die
= die
->child
;
14057 while (child_die
&& child_die
->tag
)
14059 if (child_die
->tag
== DW_TAG_member
14060 || child_die
->tag
== DW_TAG_variable
)
14062 /* NOTE: carlton/2002-11-05: A C++ static data member
14063 should be a DW_TAG_member that is a declaration, but
14064 all versions of G++ as of this writing (so through at
14065 least 3.2.1) incorrectly generate DW_TAG_variable
14066 tags for them instead. */
14067 dwarf2_add_field (&fi
, child_die
, cu
);
14069 else if (child_die
->tag
== DW_TAG_subprogram
)
14071 /* Rust doesn't have member functions in the C++ sense.
14072 However, it does emit ordinary functions as children
14073 of a struct DIE. */
14074 if (cu
->language
== language_rust
)
14075 read_func_scope (child_die
, cu
);
14078 /* C++ member function. */
14079 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
14082 else if (child_die
->tag
== DW_TAG_inheritance
)
14084 /* C++ base class field. */
14085 dwarf2_add_field (&fi
, child_die
, cu
);
14087 else if (child_die
->tag
== DW_TAG_typedef
)
14088 dwarf2_add_typedef (&fi
, child_die
, cu
);
14089 else if (child_die
->tag
== DW_TAG_template_type_param
14090 || child_die
->tag
== DW_TAG_template_value_param
)
14092 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
14095 VEC_safe_push (symbolp
, template_args
, arg
);
14098 child_die
= sibling_die (child_die
);
14101 /* Attach template arguments to type. */
14102 if (! VEC_empty (symbolp
, template_args
))
14104 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14105 TYPE_N_TEMPLATE_ARGUMENTS (type
)
14106 = VEC_length (symbolp
, template_args
);
14107 TYPE_TEMPLATE_ARGUMENTS (type
)
14108 = XOBNEWVEC (&objfile
->objfile_obstack
,
14110 TYPE_N_TEMPLATE_ARGUMENTS (type
));
14111 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
14112 VEC_address (symbolp
, template_args
),
14113 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
14114 * sizeof (struct symbol
*)));
14115 VEC_free (symbolp
, template_args
);
14118 /* Attach fields and member functions to the type. */
14120 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
14123 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
14125 /* Get the type which refers to the base class (possibly this
14126 class itself) which contains the vtable pointer for the current
14127 class from the DW_AT_containing_type attribute. This use of
14128 DW_AT_containing_type is a GNU extension. */
14130 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14132 struct type
*t
= die_containing_type (die
, cu
);
14134 set_type_vptr_basetype (type
, t
);
14139 /* Our own class provides vtbl ptr. */
14140 for (i
= TYPE_NFIELDS (t
) - 1;
14141 i
>= TYPE_N_BASECLASSES (t
);
14144 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
14146 if (is_vtable_name (fieldname
, cu
))
14148 set_type_vptr_fieldno (type
, i
);
14153 /* Complain if virtual function table field not found. */
14154 if (i
< TYPE_N_BASECLASSES (t
))
14155 complaint (&symfile_complaints
,
14156 _("virtual function table pointer "
14157 "not found when defining class '%s'"),
14158 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
14163 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
14166 else if (cu
->producer
14167 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
14169 /* The IBM XLC compiler does not provide direct indication
14170 of the containing type, but the vtable pointer is
14171 always named __vfp. */
14175 for (i
= TYPE_NFIELDS (type
) - 1;
14176 i
>= TYPE_N_BASECLASSES (type
);
14179 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
14181 set_type_vptr_fieldno (type
, i
);
14182 set_type_vptr_basetype (type
, type
);
14189 /* Copy fi.typedef_field_list linked list elements content into the
14190 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
14191 if (fi
.typedef_field_list
)
14193 int i
= fi
.typedef_field_list_count
;
14195 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14196 TYPE_TYPEDEF_FIELD_ARRAY (type
)
14197 = ((struct typedef_field
*)
14198 TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
));
14199 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
14201 /* Reverse the list order to keep the debug info elements order. */
14204 struct typedef_field
*dest
, *src
;
14206 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
14207 src
= &fi
.typedef_field_list
->field
;
14208 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
14213 do_cleanups (back_to
);
14216 quirk_gcc_member_function_pointer (type
, objfile
);
14218 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
14219 snapshots) has been known to create a die giving a declaration
14220 for a class that has, as a child, a die giving a definition for a
14221 nested class. So we have to process our children even if the
14222 current die is a declaration. Normally, of course, a declaration
14223 won't have any children at all. */
14225 child_die
= die
->child
;
14227 while (child_die
!= NULL
&& child_die
->tag
)
14229 if (child_die
->tag
== DW_TAG_member
14230 || child_die
->tag
== DW_TAG_variable
14231 || child_die
->tag
== DW_TAG_inheritance
14232 || child_die
->tag
== DW_TAG_template_value_param
14233 || child_die
->tag
== DW_TAG_template_type_param
)
14238 process_die (child_die
, cu
);
14240 child_die
= sibling_die (child_die
);
14243 /* Do not consider external references. According to the DWARF standard,
14244 these DIEs are identified by the fact that they have no byte_size
14245 attribute, and a declaration attribute. */
14246 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
14247 || !die_is_declaration (die
, cu
))
14248 new_symbol (die
, type
, cu
);
14251 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
14252 update TYPE using some information only available in DIE's children. */
14255 update_enumeration_type_from_children (struct die_info
*die
,
14257 struct dwarf2_cu
*cu
)
14259 struct die_info
*child_die
;
14260 int unsigned_enum
= 1;
14264 auto_obstack obstack
;
14266 for (child_die
= die
->child
;
14267 child_die
!= NULL
&& child_die
->tag
;
14268 child_die
= sibling_die (child_die
))
14270 struct attribute
*attr
;
14272 const gdb_byte
*bytes
;
14273 struct dwarf2_locexpr_baton
*baton
;
14276 if (child_die
->tag
!= DW_TAG_enumerator
)
14279 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
14283 name
= dwarf2_name (child_die
, cu
);
14285 name
= "<anonymous enumerator>";
14287 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
14288 &value
, &bytes
, &baton
);
14294 else if ((mask
& value
) != 0)
14299 /* If we already know that the enum type is neither unsigned, nor
14300 a flag type, no need to look at the rest of the enumerates. */
14301 if (!unsigned_enum
&& !flag_enum
)
14306 TYPE_UNSIGNED (type
) = 1;
14308 TYPE_FLAG_ENUM (type
) = 1;
14311 /* Given a DW_AT_enumeration_type die, set its type. We do not
14312 complete the type's fields yet, or create any symbols. */
14314 static struct type
*
14315 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14317 struct objfile
*objfile
= cu
->objfile
;
14319 struct attribute
*attr
;
14322 /* If the definition of this type lives in .debug_types, read that type.
14323 Don't follow DW_AT_specification though, that will take us back up
14324 the chain and we want to go down. */
14325 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
14328 type
= get_DW_AT_signature_type (die
, attr
, cu
);
14330 /* The type's CU may not be the same as CU.
14331 Ensure TYPE is recorded with CU in die_type_hash. */
14332 return set_die_type (die
, type
, cu
);
14335 type
= alloc_type (objfile
);
14337 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
14338 name
= dwarf2_full_name (NULL
, die
, cu
);
14340 TYPE_TAG_NAME (type
) = name
;
14342 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14345 struct type
*underlying_type
= die_type (die
, cu
);
14347 TYPE_TARGET_TYPE (type
) = underlying_type
;
14350 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14353 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14357 TYPE_LENGTH (type
) = 0;
14360 /* The enumeration DIE can be incomplete. In Ada, any type can be
14361 declared as private in the package spec, and then defined only
14362 inside the package body. Such types are known as Taft Amendment
14363 Types. When another package uses such a type, an incomplete DIE
14364 may be generated by the compiler. */
14365 if (die_is_declaration (die
, cu
))
14366 TYPE_STUB (type
) = 1;
14368 /* Finish the creation of this type by using the enum's children.
14369 We must call this even when the underlying type has been provided
14370 so that we can determine if we're looking at a "flag" enum. */
14371 update_enumeration_type_from_children (die
, type
, cu
);
14373 /* If this type has an underlying type that is not a stub, then we
14374 may use its attributes. We always use the "unsigned" attribute
14375 in this situation, because ordinarily we guess whether the type
14376 is unsigned -- but the guess can be wrong and the underlying type
14377 can tell us the reality. However, we defer to a local size
14378 attribute if one exists, because this lets the compiler override
14379 the underlying type if needed. */
14380 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
14382 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
14383 if (TYPE_LENGTH (type
) == 0)
14384 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
14387 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
14389 return set_die_type (die
, type
, cu
);
14392 /* Given a pointer to a die which begins an enumeration, process all
14393 the dies that define the members of the enumeration, and create the
14394 symbol for the enumeration type.
14396 NOTE: We reverse the order of the element list. */
14399 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14401 struct type
*this_type
;
14403 this_type
= get_die_type (die
, cu
);
14404 if (this_type
== NULL
)
14405 this_type
= read_enumeration_type (die
, cu
);
14407 if (die
->child
!= NULL
)
14409 struct die_info
*child_die
;
14410 struct symbol
*sym
;
14411 struct field
*fields
= NULL
;
14412 int num_fields
= 0;
14415 child_die
= die
->child
;
14416 while (child_die
&& child_die
->tag
)
14418 if (child_die
->tag
!= DW_TAG_enumerator
)
14420 process_die (child_die
, cu
);
14424 name
= dwarf2_name (child_die
, cu
);
14427 sym
= new_symbol (child_die
, this_type
, cu
);
14429 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
14431 fields
= (struct field
*)
14433 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
14434 * sizeof (struct field
));
14437 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
14438 FIELD_TYPE (fields
[num_fields
]) = NULL
;
14439 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
14440 FIELD_BITSIZE (fields
[num_fields
]) = 0;
14446 child_die
= sibling_die (child_die
);
14451 TYPE_NFIELDS (this_type
) = num_fields
;
14452 TYPE_FIELDS (this_type
) = (struct field
*)
14453 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
14454 memcpy (TYPE_FIELDS (this_type
), fields
,
14455 sizeof (struct field
) * num_fields
);
14460 /* If we are reading an enum from a .debug_types unit, and the enum
14461 is a declaration, and the enum is not the signatured type in the
14462 unit, then we do not want to add a symbol for it. Adding a
14463 symbol would in some cases obscure the true definition of the
14464 enum, giving users an incomplete type when the definition is
14465 actually available. Note that we do not want to do this for all
14466 enums which are just declarations, because C++0x allows forward
14467 enum declarations. */
14468 if (cu
->per_cu
->is_debug_types
14469 && die_is_declaration (die
, cu
))
14471 struct signatured_type
*sig_type
;
14473 sig_type
= (struct signatured_type
*) cu
->per_cu
;
14474 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
14475 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
14479 new_symbol (die
, this_type
, cu
);
14482 /* Extract all information from a DW_TAG_array_type DIE and put it in
14483 the DIE's type field. For now, this only handles one dimensional
14486 static struct type
*
14487 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14489 struct objfile
*objfile
= cu
->objfile
;
14490 struct die_info
*child_die
;
14492 struct type
*element_type
, *range_type
, *index_type
;
14493 struct attribute
*attr
;
14495 unsigned int bit_stride
= 0;
14497 element_type
= die_type (die
, cu
);
14499 /* The die_type call above may have already set the type for this DIE. */
14500 type
= get_die_type (die
, cu
);
14504 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
14506 bit_stride
= DW_UNSND (attr
) * 8;
14508 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
14510 bit_stride
= DW_UNSND (attr
);
14512 /* Irix 6.2 native cc creates array types without children for
14513 arrays with unspecified length. */
14514 if (die
->child
== NULL
)
14516 index_type
= objfile_type (objfile
)->builtin_int
;
14517 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
14518 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
14520 return set_die_type (die
, type
, cu
);
14523 std::vector
<struct type
*> range_types
;
14524 child_die
= die
->child
;
14525 while (child_die
&& child_die
->tag
)
14527 if (child_die
->tag
== DW_TAG_subrange_type
)
14529 struct type
*child_type
= read_type_die (child_die
, cu
);
14531 if (child_type
!= NULL
)
14533 /* The range type was succesfully read. Save it for the
14534 array type creation. */
14535 range_types
.push_back (child_type
);
14538 child_die
= sibling_die (child_die
);
14541 /* Dwarf2 dimensions are output from left to right, create the
14542 necessary array types in backwards order. */
14544 type
= element_type
;
14546 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
14550 while (i
< range_types
.size ())
14551 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
14556 size_t ndim
= range_types
.size ();
14558 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
14562 /* Understand Dwarf2 support for vector types (like they occur on
14563 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
14564 array type. This is not part of the Dwarf2/3 standard yet, but a
14565 custom vendor extension. The main difference between a regular
14566 array and the vector variant is that vectors are passed by value
14568 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
14570 make_vector_type (type
);
14572 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
14573 implementation may choose to implement triple vectors using this
14575 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14578 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
14579 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14581 complaint (&symfile_complaints
,
14582 _("DW_AT_byte_size for array type smaller "
14583 "than the total size of elements"));
14586 name
= dwarf2_name (die
, cu
);
14588 TYPE_NAME (type
) = name
;
14590 /* Install the type in the die. */
14591 set_die_type (die
, type
, cu
);
14593 /* set_die_type should be already done. */
14594 set_descriptive_type (type
, die
, cu
);
14599 static enum dwarf_array_dim_ordering
14600 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
14602 struct attribute
*attr
;
14604 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
14607 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
14609 /* GNU F77 is a special case, as at 08/2004 array type info is the
14610 opposite order to the dwarf2 specification, but data is still
14611 laid out as per normal fortran.
14613 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
14614 version checking. */
14616 if (cu
->language
== language_fortran
14617 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
14619 return DW_ORD_row_major
;
14622 switch (cu
->language_defn
->la_array_ordering
)
14624 case array_column_major
:
14625 return DW_ORD_col_major
;
14626 case array_row_major
:
14628 return DW_ORD_row_major
;
14632 /* Extract all information from a DW_TAG_set_type DIE and put it in
14633 the DIE's type field. */
14635 static struct type
*
14636 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14638 struct type
*domain_type
, *set_type
;
14639 struct attribute
*attr
;
14641 domain_type
= die_type (die
, cu
);
14643 /* The die_type call above may have already set the type for this DIE. */
14644 set_type
= get_die_type (die
, cu
);
14648 set_type
= create_set_type (NULL
, domain_type
);
14650 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14652 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
14654 return set_die_type (die
, set_type
, cu
);
14657 /* A helper for read_common_block that creates a locexpr baton.
14658 SYM is the symbol which we are marking as computed.
14659 COMMON_DIE is the DIE for the common block.
14660 COMMON_LOC is the location expression attribute for the common
14662 MEMBER_LOC is the location expression attribute for the particular
14663 member of the common block that we are processing.
14664 CU is the CU from which the above come. */
14667 mark_common_block_symbol_computed (struct symbol
*sym
,
14668 struct die_info
*common_die
,
14669 struct attribute
*common_loc
,
14670 struct attribute
*member_loc
,
14671 struct dwarf2_cu
*cu
)
14673 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14674 struct dwarf2_locexpr_baton
*baton
;
14676 unsigned int cu_off
;
14677 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
14678 LONGEST offset
= 0;
14680 gdb_assert (common_loc
&& member_loc
);
14681 gdb_assert (attr_form_is_block (common_loc
));
14682 gdb_assert (attr_form_is_block (member_loc
)
14683 || attr_form_is_constant (member_loc
));
14685 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14686 baton
->per_cu
= cu
->per_cu
;
14687 gdb_assert (baton
->per_cu
);
14689 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
14691 if (attr_form_is_constant (member_loc
))
14693 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
14694 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
14697 baton
->size
+= DW_BLOCK (member_loc
)->size
;
14699 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
14702 *ptr
++ = DW_OP_call4
;
14703 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
14704 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
14707 if (attr_form_is_constant (member_loc
))
14709 *ptr
++ = DW_OP_addr
;
14710 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
14711 ptr
+= cu
->header
.addr_size
;
14715 /* We have to copy the data here, because DW_OP_call4 will only
14716 use a DW_AT_location attribute. */
14717 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
14718 ptr
+= DW_BLOCK (member_loc
)->size
;
14721 *ptr
++ = DW_OP_plus
;
14722 gdb_assert (ptr
- baton
->data
== baton
->size
);
14724 SYMBOL_LOCATION_BATON (sym
) = baton
;
14725 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
14728 /* Create appropriate locally-scoped variables for all the
14729 DW_TAG_common_block entries. Also create a struct common_block
14730 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
14731 is used to sepate the common blocks name namespace from regular
14735 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
14737 struct attribute
*attr
;
14739 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14742 /* Support the .debug_loc offsets. */
14743 if (attr_form_is_block (attr
))
14747 else if (attr_form_is_section_offset (attr
))
14749 dwarf2_complex_location_expr_complaint ();
14754 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
14755 "common block member");
14760 if (die
->child
!= NULL
)
14762 struct objfile
*objfile
= cu
->objfile
;
14763 struct die_info
*child_die
;
14764 size_t n_entries
= 0, size
;
14765 struct common_block
*common_block
;
14766 struct symbol
*sym
;
14768 for (child_die
= die
->child
;
14769 child_die
&& child_die
->tag
;
14770 child_die
= sibling_die (child_die
))
14773 size
= (sizeof (struct common_block
)
14774 + (n_entries
- 1) * sizeof (struct symbol
*));
14776 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
14778 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
14779 common_block
->n_entries
= 0;
14781 for (child_die
= die
->child
;
14782 child_die
&& child_die
->tag
;
14783 child_die
= sibling_die (child_die
))
14785 /* Create the symbol in the DW_TAG_common_block block in the current
14787 sym
= new_symbol (child_die
, NULL
, cu
);
14790 struct attribute
*member_loc
;
14792 common_block
->contents
[common_block
->n_entries
++] = sym
;
14794 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
14798 /* GDB has handled this for a long time, but it is
14799 not specified by DWARF. It seems to have been
14800 emitted by gfortran at least as recently as:
14801 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
14802 complaint (&symfile_complaints
,
14803 _("Variable in common block has "
14804 "DW_AT_data_member_location "
14805 "- DIE at 0x%x [in module %s]"),
14806 to_underlying (child_die
->sect_off
),
14807 objfile_name (cu
->objfile
));
14809 if (attr_form_is_section_offset (member_loc
))
14810 dwarf2_complex_location_expr_complaint ();
14811 else if (attr_form_is_constant (member_loc
)
14812 || attr_form_is_block (member_loc
))
14815 mark_common_block_symbol_computed (sym
, die
, attr
,
14819 dwarf2_complex_location_expr_complaint ();
14824 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
14825 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
14829 /* Create a type for a C++ namespace. */
14831 static struct type
*
14832 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14834 struct objfile
*objfile
= cu
->objfile
;
14835 const char *previous_prefix
, *name
;
14839 /* For extensions, reuse the type of the original namespace. */
14840 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
14842 struct die_info
*ext_die
;
14843 struct dwarf2_cu
*ext_cu
= cu
;
14845 ext_die
= dwarf2_extension (die
, &ext_cu
);
14846 type
= read_type_die (ext_die
, ext_cu
);
14848 /* EXT_CU may not be the same as CU.
14849 Ensure TYPE is recorded with CU in die_type_hash. */
14850 return set_die_type (die
, type
, cu
);
14853 name
= namespace_name (die
, &is_anonymous
, cu
);
14855 /* Now build the name of the current namespace. */
14857 previous_prefix
= determine_prefix (die
, cu
);
14858 if (previous_prefix
[0] != '\0')
14859 name
= typename_concat (&objfile
->objfile_obstack
,
14860 previous_prefix
, name
, 0, cu
);
14862 /* Create the type. */
14863 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
14864 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14866 return set_die_type (die
, type
, cu
);
14869 /* Read a namespace scope. */
14872 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
14874 struct objfile
*objfile
= cu
->objfile
;
14877 /* Add a symbol associated to this if we haven't seen the namespace
14878 before. Also, add a using directive if it's an anonymous
14881 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
14885 type
= read_type_die (die
, cu
);
14886 new_symbol (die
, type
, cu
);
14888 namespace_name (die
, &is_anonymous
, cu
);
14891 const char *previous_prefix
= determine_prefix (die
, cu
);
14893 std::vector
<const char *> excludes
;
14894 add_using_directive (using_directives (cu
->language
),
14895 previous_prefix
, TYPE_NAME (type
), NULL
,
14896 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
14900 if (die
->child
!= NULL
)
14902 struct die_info
*child_die
= die
->child
;
14904 while (child_die
&& child_die
->tag
)
14906 process_die (child_die
, cu
);
14907 child_die
= sibling_die (child_die
);
14912 /* Read a Fortran module as type. This DIE can be only a declaration used for
14913 imported module. Still we need that type as local Fortran "use ... only"
14914 declaration imports depend on the created type in determine_prefix. */
14916 static struct type
*
14917 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14919 struct objfile
*objfile
= cu
->objfile
;
14920 const char *module_name
;
14923 module_name
= dwarf2_name (die
, cu
);
14925 complaint (&symfile_complaints
,
14926 _("DW_TAG_module has no name, offset 0x%x"),
14927 to_underlying (die
->sect_off
));
14928 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
14930 /* determine_prefix uses TYPE_TAG_NAME. */
14931 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14933 return set_die_type (die
, type
, cu
);
14936 /* Read a Fortran module. */
14939 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
14941 struct die_info
*child_die
= die
->child
;
14944 type
= read_type_die (die
, cu
);
14945 new_symbol (die
, type
, cu
);
14947 while (child_die
&& child_die
->tag
)
14949 process_die (child_die
, cu
);
14950 child_die
= sibling_die (child_die
);
14954 /* Return the name of the namespace represented by DIE. Set
14955 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
14958 static const char *
14959 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
14961 struct die_info
*current_die
;
14962 const char *name
= NULL
;
14964 /* Loop through the extensions until we find a name. */
14966 for (current_die
= die
;
14967 current_die
!= NULL
;
14968 current_die
= dwarf2_extension (die
, &cu
))
14970 /* We don't use dwarf2_name here so that we can detect the absence
14971 of a name -> anonymous namespace. */
14972 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
14978 /* Is it an anonymous namespace? */
14980 *is_anonymous
= (name
== NULL
);
14982 name
= CP_ANONYMOUS_NAMESPACE_STR
;
14987 /* Extract all information from a DW_TAG_pointer_type DIE and add to
14988 the user defined type vector. */
14990 static struct type
*
14991 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14993 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
14994 struct comp_unit_head
*cu_header
= &cu
->header
;
14996 struct attribute
*attr_byte_size
;
14997 struct attribute
*attr_address_class
;
14998 int byte_size
, addr_class
;
14999 struct type
*target_type
;
15001 target_type
= die_type (die
, cu
);
15003 /* The die_type call above may have already set the type for this DIE. */
15004 type
= get_die_type (die
, cu
);
15008 type
= lookup_pointer_type (target_type
);
15010 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15011 if (attr_byte_size
)
15012 byte_size
= DW_UNSND (attr_byte_size
);
15014 byte_size
= cu_header
->addr_size
;
15016 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
15017 if (attr_address_class
)
15018 addr_class
= DW_UNSND (attr_address_class
);
15020 addr_class
= DW_ADDR_none
;
15022 /* If the pointer size or address class is different than the
15023 default, create a type variant marked as such and set the
15024 length accordingly. */
15025 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
15027 if (gdbarch_address_class_type_flags_p (gdbarch
))
15031 type_flags
= gdbarch_address_class_type_flags
15032 (gdbarch
, byte_size
, addr_class
);
15033 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
15035 type
= make_type_with_address_space (type
, type_flags
);
15037 else if (TYPE_LENGTH (type
) != byte_size
)
15039 complaint (&symfile_complaints
,
15040 _("invalid pointer size %d"), byte_size
);
15044 /* Should we also complain about unhandled address classes? */
15048 TYPE_LENGTH (type
) = byte_size
;
15049 return set_die_type (die
, type
, cu
);
15052 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
15053 the user defined type vector. */
15055 static struct type
*
15056 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15059 struct type
*to_type
;
15060 struct type
*domain
;
15062 to_type
= die_type (die
, cu
);
15063 domain
= die_containing_type (die
, cu
);
15065 /* The calls above may have already set the type for this DIE. */
15066 type
= get_die_type (die
, cu
);
15070 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
15071 type
= lookup_methodptr_type (to_type
);
15072 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
15074 struct type
*new_type
= alloc_type (cu
->objfile
);
15076 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
15077 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
15078 TYPE_VARARGS (to_type
));
15079 type
= lookup_methodptr_type (new_type
);
15082 type
= lookup_memberptr_type (to_type
, domain
);
15084 return set_die_type (die
, type
, cu
);
15087 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
15088 the user defined type vector. */
15090 static struct type
*
15091 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
15092 enum type_code refcode
)
15094 struct comp_unit_head
*cu_header
= &cu
->header
;
15095 struct type
*type
, *target_type
;
15096 struct attribute
*attr
;
15098 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
15100 target_type
= die_type (die
, cu
);
15102 /* The die_type call above may have already set the type for this DIE. */
15103 type
= get_die_type (die
, cu
);
15107 type
= lookup_reference_type (target_type
, refcode
);
15108 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15111 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15115 TYPE_LENGTH (type
) = cu_header
->addr_size
;
15117 return set_die_type (die
, type
, cu
);
15120 /* Add the given cv-qualifiers to the element type of the array. GCC
15121 outputs DWARF type qualifiers that apply to an array, not the
15122 element type. But GDB relies on the array element type to carry
15123 the cv-qualifiers. This mimics section 6.7.3 of the C99
15126 static struct type
*
15127 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
15128 struct type
*base_type
, int cnst
, int voltl
)
15130 struct type
*el_type
, *inner_array
;
15132 base_type
= copy_type (base_type
);
15133 inner_array
= base_type
;
15135 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
15137 TYPE_TARGET_TYPE (inner_array
) =
15138 copy_type (TYPE_TARGET_TYPE (inner_array
));
15139 inner_array
= TYPE_TARGET_TYPE (inner_array
);
15142 el_type
= TYPE_TARGET_TYPE (inner_array
);
15143 cnst
|= TYPE_CONST (el_type
);
15144 voltl
|= TYPE_VOLATILE (el_type
);
15145 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
15147 return set_die_type (die
, base_type
, cu
);
15150 static struct type
*
15151 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15153 struct type
*base_type
, *cv_type
;
15155 base_type
= die_type (die
, cu
);
15157 /* The die_type call above may have already set the type for this DIE. */
15158 cv_type
= get_die_type (die
, cu
);
15162 /* In case the const qualifier is applied to an array type, the element type
15163 is so qualified, not the array type (section 6.7.3 of C99). */
15164 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
15165 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
15167 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
15168 return set_die_type (die
, cv_type
, cu
);
15171 static struct type
*
15172 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15174 struct type
*base_type
, *cv_type
;
15176 base_type
= die_type (die
, cu
);
15178 /* The die_type call above may have already set the type for this DIE. */
15179 cv_type
= get_die_type (die
, cu
);
15183 /* In case the volatile qualifier is applied to an array type, the
15184 element type is so qualified, not the array type (section 6.7.3
15186 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
15187 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
15189 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
15190 return set_die_type (die
, cv_type
, cu
);
15193 /* Handle DW_TAG_restrict_type. */
15195 static struct type
*
15196 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15198 struct type
*base_type
, *cv_type
;
15200 base_type
= die_type (die
, cu
);
15202 /* The die_type call above may have already set the type for this DIE. */
15203 cv_type
= get_die_type (die
, cu
);
15207 cv_type
= make_restrict_type (base_type
);
15208 return set_die_type (die
, cv_type
, cu
);
15211 /* Handle DW_TAG_atomic_type. */
15213 static struct type
*
15214 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15216 struct type
*base_type
, *cv_type
;
15218 base_type
= die_type (die
, cu
);
15220 /* The die_type call above may have already set the type for this DIE. */
15221 cv_type
= get_die_type (die
, cu
);
15225 cv_type
= make_atomic_type (base_type
);
15226 return set_die_type (die
, cv_type
, cu
);
15229 /* Extract all information from a DW_TAG_string_type DIE and add to
15230 the user defined type vector. It isn't really a user defined type,
15231 but it behaves like one, with other DIE's using an AT_user_def_type
15232 attribute to reference it. */
15234 static struct type
*
15235 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15237 struct objfile
*objfile
= cu
->objfile
;
15238 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15239 struct type
*type
, *range_type
, *index_type
, *char_type
;
15240 struct attribute
*attr
;
15241 unsigned int length
;
15243 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
15246 length
= DW_UNSND (attr
);
15250 /* Check for the DW_AT_byte_size attribute. */
15251 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15254 length
= DW_UNSND (attr
);
15262 index_type
= objfile_type (objfile
)->builtin_int
;
15263 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
15264 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
15265 type
= create_string_type (NULL
, char_type
, range_type
);
15267 return set_die_type (die
, type
, cu
);
15270 /* Assuming that DIE corresponds to a function, returns nonzero
15271 if the function is prototyped. */
15274 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
15276 struct attribute
*attr
;
15278 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
15279 if (attr
&& (DW_UNSND (attr
) != 0))
15282 /* The DWARF standard implies that the DW_AT_prototyped attribute
15283 is only meaninful for C, but the concept also extends to other
15284 languages that allow unprototyped functions (Eg: Objective C).
15285 For all other languages, assume that functions are always
15287 if (cu
->language
!= language_c
15288 && cu
->language
!= language_objc
15289 && cu
->language
!= language_opencl
)
15292 /* RealView does not emit DW_AT_prototyped. We can not distinguish
15293 prototyped and unprototyped functions; default to prototyped,
15294 since that is more common in modern code (and RealView warns
15295 about unprototyped functions). */
15296 if (producer_is_realview (cu
->producer
))
15302 /* Handle DIES due to C code like:
15306 int (*funcp)(int a, long l);
15310 ('funcp' generates a DW_TAG_subroutine_type DIE). */
15312 static struct type
*
15313 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15315 struct objfile
*objfile
= cu
->objfile
;
15316 struct type
*type
; /* Type that this function returns. */
15317 struct type
*ftype
; /* Function that returns above type. */
15318 struct attribute
*attr
;
15320 type
= die_type (die
, cu
);
15322 /* The die_type call above may have already set the type for this DIE. */
15323 ftype
= get_die_type (die
, cu
);
15327 ftype
= lookup_function_type (type
);
15329 if (prototyped_function_p (die
, cu
))
15330 TYPE_PROTOTYPED (ftype
) = 1;
15332 /* Store the calling convention in the type if it's available in
15333 the subroutine die. Otherwise set the calling convention to
15334 the default value DW_CC_normal. */
15335 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15337 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
15338 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
15339 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
15341 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
15343 /* Record whether the function returns normally to its caller or not
15344 if the DWARF producer set that information. */
15345 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
15346 if (attr
&& (DW_UNSND (attr
) != 0))
15347 TYPE_NO_RETURN (ftype
) = 1;
15349 /* We need to add the subroutine type to the die immediately so
15350 we don't infinitely recurse when dealing with parameters
15351 declared as the same subroutine type. */
15352 set_die_type (die
, ftype
, cu
);
15354 if (die
->child
!= NULL
)
15356 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
15357 struct die_info
*child_die
;
15358 int nparams
, iparams
;
15360 /* Count the number of parameters.
15361 FIXME: GDB currently ignores vararg functions, but knows about
15362 vararg member functions. */
15364 child_die
= die
->child
;
15365 while (child_die
&& child_die
->tag
)
15367 if (child_die
->tag
== DW_TAG_formal_parameter
)
15369 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
15370 TYPE_VARARGS (ftype
) = 1;
15371 child_die
= sibling_die (child_die
);
15374 /* Allocate storage for parameters and fill them in. */
15375 TYPE_NFIELDS (ftype
) = nparams
;
15376 TYPE_FIELDS (ftype
) = (struct field
*)
15377 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
15379 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
15380 even if we error out during the parameters reading below. */
15381 for (iparams
= 0; iparams
< nparams
; iparams
++)
15382 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
15385 child_die
= die
->child
;
15386 while (child_die
&& child_die
->tag
)
15388 if (child_die
->tag
== DW_TAG_formal_parameter
)
15390 struct type
*arg_type
;
15392 /* DWARF version 2 has no clean way to discern C++
15393 static and non-static member functions. G++ helps
15394 GDB by marking the first parameter for non-static
15395 member functions (which is the this pointer) as
15396 artificial. We pass this information to
15397 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
15399 DWARF version 3 added DW_AT_object_pointer, which GCC
15400 4.5 does not yet generate. */
15401 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
15403 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
15405 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
15406 arg_type
= die_type (child_die
, cu
);
15408 /* RealView does not mark THIS as const, which the testsuite
15409 expects. GCC marks THIS as const in method definitions,
15410 but not in the class specifications (GCC PR 43053). */
15411 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
15412 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
15415 struct dwarf2_cu
*arg_cu
= cu
;
15416 const char *name
= dwarf2_name (child_die
, cu
);
15418 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
15421 /* If the compiler emits this, use it. */
15422 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
15425 else if (name
&& strcmp (name
, "this") == 0)
15426 /* Function definitions will have the argument names. */
15428 else if (name
== NULL
&& iparams
== 0)
15429 /* Declarations may not have the names, so like
15430 elsewhere in GDB, assume an artificial first
15431 argument is "this". */
15435 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
15439 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
15442 child_die
= sibling_die (child_die
);
15449 static struct type
*
15450 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
15452 struct objfile
*objfile
= cu
->objfile
;
15453 const char *name
= NULL
;
15454 struct type
*this_type
, *target_type
;
15456 name
= dwarf2_full_name (NULL
, die
, cu
);
15457 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
15458 TYPE_TARGET_STUB (this_type
) = 1;
15459 set_die_type (die
, this_type
, cu
);
15460 target_type
= die_type (die
, cu
);
15461 if (target_type
!= this_type
)
15462 TYPE_TARGET_TYPE (this_type
) = target_type
;
15465 /* Self-referential typedefs are, it seems, not allowed by the DWARF
15466 spec and cause infinite loops in GDB. */
15467 complaint (&symfile_complaints
,
15468 _("Self-referential DW_TAG_typedef "
15469 "- DIE at 0x%x [in module %s]"),
15470 to_underlying (die
->sect_off
), objfile_name (objfile
));
15471 TYPE_TARGET_TYPE (this_type
) = NULL
;
15476 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
15477 (which may be different from NAME) to the architecture back-end to allow
15478 it to guess the correct format if necessary. */
15480 static struct type
*
15481 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
15482 const char *name_hint
)
15484 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15485 const struct floatformat
**format
;
15488 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
15490 type
= init_float_type (objfile
, bits
, name
, format
);
15492 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
15497 /* Find a representation of a given base type and install
15498 it in the TYPE field of the die. */
15500 static struct type
*
15501 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15503 struct objfile
*objfile
= cu
->objfile
;
15505 struct attribute
*attr
;
15506 int encoding
= 0, bits
= 0;
15509 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
15512 encoding
= DW_UNSND (attr
);
15514 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15517 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
15519 name
= dwarf2_name (die
, cu
);
15522 complaint (&symfile_complaints
,
15523 _("DW_AT_name missing from DW_TAG_base_type"));
15528 case DW_ATE_address
:
15529 /* Turn DW_ATE_address into a void * pointer. */
15530 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
15531 type
= init_pointer_type (objfile
, bits
, name
, type
);
15533 case DW_ATE_boolean
:
15534 type
= init_boolean_type (objfile
, bits
, 1, name
);
15536 case DW_ATE_complex_float
:
15537 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
15538 type
= init_complex_type (objfile
, name
, type
);
15540 case DW_ATE_decimal_float
:
15541 type
= init_decfloat_type (objfile
, bits
, name
);
15544 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
15546 case DW_ATE_signed
:
15547 type
= init_integer_type (objfile
, bits
, 0, name
);
15549 case DW_ATE_unsigned
:
15550 if (cu
->language
== language_fortran
15552 && startswith (name
, "character("))
15553 type
= init_character_type (objfile
, bits
, 1, name
);
15555 type
= init_integer_type (objfile
, bits
, 1, name
);
15557 case DW_ATE_signed_char
:
15558 if (cu
->language
== language_ada
|| cu
->language
== language_m2
15559 || cu
->language
== language_pascal
15560 || cu
->language
== language_fortran
)
15561 type
= init_character_type (objfile
, bits
, 0, name
);
15563 type
= init_integer_type (objfile
, bits
, 0, name
);
15565 case DW_ATE_unsigned_char
:
15566 if (cu
->language
== language_ada
|| cu
->language
== language_m2
15567 || cu
->language
== language_pascal
15568 || cu
->language
== language_fortran
15569 || cu
->language
== language_rust
)
15570 type
= init_character_type (objfile
, bits
, 1, name
);
15572 type
= init_integer_type (objfile
, bits
, 1, name
);
15576 gdbarch
*arch
= get_objfile_arch (objfile
);
15579 type
= builtin_type (arch
)->builtin_char16
;
15580 else if (bits
== 32)
15581 type
= builtin_type (arch
)->builtin_char32
;
15584 complaint (&symfile_complaints
,
15585 _("unsupported DW_ATE_UTF bit size: '%d'"),
15587 type
= init_integer_type (objfile
, bits
, 1, name
);
15589 return set_die_type (die
, type
, cu
);
15594 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
15595 dwarf_type_encoding_name (encoding
));
15596 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
15600 if (name
&& strcmp (name
, "char") == 0)
15601 TYPE_NOSIGN (type
) = 1;
15603 return set_die_type (die
, type
, cu
);
15606 /* Parse dwarf attribute if it's a block, reference or constant and put the
15607 resulting value of the attribute into struct bound_prop.
15608 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
15611 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
15612 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
15614 struct dwarf2_property_baton
*baton
;
15615 struct obstack
*obstack
= &cu
->objfile
->objfile_obstack
;
15617 if (attr
== NULL
|| prop
== NULL
)
15620 if (attr_form_is_block (attr
))
15622 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15623 baton
->referenced_type
= NULL
;
15624 baton
->locexpr
.per_cu
= cu
->per_cu
;
15625 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
15626 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
15627 prop
->data
.baton
= baton
;
15628 prop
->kind
= PROP_LOCEXPR
;
15629 gdb_assert (prop
->data
.baton
!= NULL
);
15631 else if (attr_form_is_ref (attr
))
15633 struct dwarf2_cu
*target_cu
= cu
;
15634 struct die_info
*target_die
;
15635 struct attribute
*target_attr
;
15637 target_die
= follow_die_ref (die
, attr
, &target_cu
);
15638 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
15639 if (target_attr
== NULL
)
15640 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
15642 if (target_attr
== NULL
)
15645 switch (target_attr
->name
)
15647 case DW_AT_location
:
15648 if (attr_form_is_section_offset (target_attr
))
15650 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15651 baton
->referenced_type
= die_type (target_die
, target_cu
);
15652 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
15653 prop
->data
.baton
= baton
;
15654 prop
->kind
= PROP_LOCLIST
;
15655 gdb_assert (prop
->data
.baton
!= NULL
);
15657 else if (attr_form_is_block (target_attr
))
15659 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15660 baton
->referenced_type
= die_type (target_die
, target_cu
);
15661 baton
->locexpr
.per_cu
= cu
->per_cu
;
15662 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
15663 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
15664 prop
->data
.baton
= baton
;
15665 prop
->kind
= PROP_LOCEXPR
;
15666 gdb_assert (prop
->data
.baton
!= NULL
);
15670 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15671 "dynamic property");
15675 case DW_AT_data_member_location
:
15679 if (!handle_data_member_location (target_die
, target_cu
,
15683 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15684 baton
->referenced_type
= read_type_die (target_die
->parent
,
15686 baton
->offset_info
.offset
= offset
;
15687 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
15688 prop
->data
.baton
= baton
;
15689 prop
->kind
= PROP_ADDR_OFFSET
;
15694 else if (attr_form_is_constant (attr
))
15696 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
15697 prop
->kind
= PROP_CONST
;
15701 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
15702 dwarf2_name (die
, cu
));
15709 /* Read the given DW_AT_subrange DIE. */
15711 static struct type
*
15712 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15714 struct type
*base_type
, *orig_base_type
;
15715 struct type
*range_type
;
15716 struct attribute
*attr
;
15717 struct dynamic_prop low
, high
;
15718 int low_default_is_valid
;
15719 int high_bound_is_count
= 0;
15721 LONGEST negative_mask
;
15723 orig_base_type
= die_type (die
, cu
);
15724 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
15725 whereas the real type might be. So, we use ORIG_BASE_TYPE when
15726 creating the range type, but we use the result of check_typedef
15727 when examining properties of the type. */
15728 base_type
= check_typedef (orig_base_type
);
15730 /* The die_type call above may have already set the type for this DIE. */
15731 range_type
= get_die_type (die
, cu
);
15735 low
.kind
= PROP_CONST
;
15736 high
.kind
= PROP_CONST
;
15737 high
.data
.const_val
= 0;
15739 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
15740 omitting DW_AT_lower_bound. */
15741 switch (cu
->language
)
15744 case language_cplus
:
15745 low
.data
.const_val
= 0;
15746 low_default_is_valid
= 1;
15748 case language_fortran
:
15749 low
.data
.const_val
= 1;
15750 low_default_is_valid
= 1;
15753 case language_objc
:
15754 case language_rust
:
15755 low
.data
.const_val
= 0;
15756 low_default_is_valid
= (cu
->header
.version
>= 4);
15760 case language_pascal
:
15761 low
.data
.const_val
= 1;
15762 low_default_is_valid
= (cu
->header
.version
>= 4);
15765 low
.data
.const_val
= 0;
15766 low_default_is_valid
= 0;
15770 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
15772 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
15773 else if (!low_default_is_valid
)
15774 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
15775 "- DIE at 0x%x [in module %s]"),
15776 to_underlying (die
->sect_off
), objfile_name (cu
->objfile
));
15778 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
15779 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
15781 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
15782 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
15784 /* If bounds are constant do the final calculation here. */
15785 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
15786 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
15788 high_bound_is_count
= 1;
15792 /* Dwarf-2 specifications explicitly allows to create subrange types
15793 without specifying a base type.
15794 In that case, the base type must be set to the type of
15795 the lower bound, upper bound or count, in that order, if any of these
15796 three attributes references an object that has a type.
15797 If no base type is found, the Dwarf-2 specifications say that
15798 a signed integer type of size equal to the size of an address should
15800 For the following C code: `extern char gdb_int [];'
15801 GCC produces an empty range DIE.
15802 FIXME: muller/2010-05-28: Possible references to object for low bound,
15803 high bound or count are not yet handled by this code. */
15804 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
15806 struct objfile
*objfile
= cu
->objfile
;
15807 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15808 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
15809 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
15811 /* Test "int", "long int", and "long long int" objfile types,
15812 and select the first one having a size above or equal to the
15813 architecture address size. */
15814 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15815 base_type
= int_type
;
15818 int_type
= objfile_type (objfile
)->builtin_long
;
15819 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15820 base_type
= int_type
;
15823 int_type
= objfile_type (objfile
)->builtin_long_long
;
15824 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15825 base_type
= int_type
;
15830 /* Normally, the DWARF producers are expected to use a signed
15831 constant form (Eg. DW_FORM_sdata) to express negative bounds.
15832 But this is unfortunately not always the case, as witnessed
15833 with GCC, for instance, where the ambiguous DW_FORM_dataN form
15834 is used instead. To work around that ambiguity, we treat
15835 the bounds as signed, and thus sign-extend their values, when
15836 the base type is signed. */
15838 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
15839 if (low
.kind
== PROP_CONST
15840 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
15841 low
.data
.const_val
|= negative_mask
;
15842 if (high
.kind
== PROP_CONST
15843 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
15844 high
.data
.const_val
|= negative_mask
;
15846 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
15848 if (high_bound_is_count
)
15849 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
15851 /* Ada expects an empty array on no boundary attributes. */
15852 if (attr
== NULL
&& cu
->language
!= language_ada
)
15853 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
15855 name
= dwarf2_name (die
, cu
);
15857 TYPE_NAME (range_type
) = name
;
15859 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15861 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
15863 set_die_type (die
, range_type
, cu
);
15865 /* set_die_type should be already done. */
15866 set_descriptive_type (range_type
, die
, cu
);
15871 static struct type
*
15872 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15876 /* For now, we only support the C meaning of an unspecified type: void. */
15878 type
= init_type (cu
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
15879 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
15881 return set_die_type (die
, type
, cu
);
15884 /* Read a single die and all its descendents. Set the die's sibling
15885 field to NULL; set other fields in the die correctly, and set all
15886 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
15887 location of the info_ptr after reading all of those dies. PARENT
15888 is the parent of the die in question. */
15890 static struct die_info
*
15891 read_die_and_children (const struct die_reader_specs
*reader
,
15892 const gdb_byte
*info_ptr
,
15893 const gdb_byte
**new_info_ptr
,
15894 struct die_info
*parent
)
15896 struct die_info
*die
;
15897 const gdb_byte
*cur_ptr
;
15900 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
15903 *new_info_ptr
= cur_ptr
;
15906 store_in_ref_table (die
, reader
->cu
);
15909 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
15913 *new_info_ptr
= cur_ptr
;
15916 die
->sibling
= NULL
;
15917 die
->parent
= parent
;
15921 /* Read a die, all of its descendents, and all of its siblings; set
15922 all of the fields of all of the dies correctly. Arguments are as
15923 in read_die_and_children. */
15925 static struct die_info
*
15926 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
15927 const gdb_byte
*info_ptr
,
15928 const gdb_byte
**new_info_ptr
,
15929 struct die_info
*parent
)
15931 struct die_info
*first_die
, *last_sibling
;
15932 const gdb_byte
*cur_ptr
;
15934 cur_ptr
= info_ptr
;
15935 first_die
= last_sibling
= NULL
;
15939 struct die_info
*die
15940 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
15944 *new_info_ptr
= cur_ptr
;
15951 last_sibling
->sibling
= die
;
15953 last_sibling
= die
;
15957 /* Read a die, all of its descendents, and all of its siblings; set
15958 all of the fields of all of the dies correctly. Arguments are as
15959 in read_die_and_children.
15960 This the main entry point for reading a DIE and all its children. */
15962 static struct die_info
*
15963 read_die_and_siblings (const struct die_reader_specs
*reader
,
15964 const gdb_byte
*info_ptr
,
15965 const gdb_byte
**new_info_ptr
,
15966 struct die_info
*parent
)
15968 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
15969 new_info_ptr
, parent
);
15971 if (dwarf_die_debug
)
15973 fprintf_unfiltered (gdb_stdlog
,
15974 "Read die from %s@0x%x of %s:\n",
15975 get_section_name (reader
->die_section
),
15976 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15977 bfd_get_filename (reader
->abfd
));
15978 dump_die (die
, dwarf_die_debug
);
15984 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
15986 The caller is responsible for filling in the extra attributes
15987 and updating (*DIEP)->num_attrs.
15988 Set DIEP to point to a newly allocated die with its information,
15989 except for its child, sibling, and parent fields.
15990 Set HAS_CHILDREN to tell whether the die has children or not. */
15992 static const gdb_byte
*
15993 read_full_die_1 (const struct die_reader_specs
*reader
,
15994 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15995 int *has_children
, int num_extra_attrs
)
15997 unsigned int abbrev_number
, bytes_read
, i
;
15998 struct abbrev_info
*abbrev
;
15999 struct die_info
*die
;
16000 struct dwarf2_cu
*cu
= reader
->cu
;
16001 bfd
*abfd
= reader
->abfd
;
16003 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
16004 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16005 info_ptr
+= bytes_read
;
16006 if (!abbrev_number
)
16013 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
16015 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
16017 bfd_get_filename (abfd
));
16019 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
16020 die
->sect_off
= sect_off
;
16021 die
->tag
= abbrev
->tag
;
16022 die
->abbrev
= abbrev_number
;
16024 /* Make the result usable.
16025 The caller needs to update num_attrs after adding the extra
16027 die
->num_attrs
= abbrev
->num_attrs
;
16029 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
16030 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
16034 *has_children
= abbrev
->has_children
;
16038 /* Read a die and all its attributes.
16039 Set DIEP to point to a newly allocated die with its information,
16040 except for its child, sibling, and parent fields.
16041 Set HAS_CHILDREN to tell whether the die has children or not. */
16043 static const gdb_byte
*
16044 read_full_die (const struct die_reader_specs
*reader
,
16045 struct die_info
**diep
, const gdb_byte
*info_ptr
,
16048 const gdb_byte
*result
;
16050 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
16052 if (dwarf_die_debug
)
16054 fprintf_unfiltered (gdb_stdlog
,
16055 "Read die from %s@0x%x of %s:\n",
16056 get_section_name (reader
->die_section
),
16057 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
16058 bfd_get_filename (reader
->abfd
));
16059 dump_die (*diep
, dwarf_die_debug
);
16065 /* Abbreviation tables.
16067 In DWARF version 2, the description of the debugging information is
16068 stored in a separate .debug_abbrev section. Before we read any
16069 dies from a section we read in all abbreviations and install them
16070 in a hash table. */
16072 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
16074 static struct abbrev_info
*
16075 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
16077 struct abbrev_info
*abbrev
;
16079 abbrev
= XOBNEW (&abbrev_table
->abbrev_obstack
, struct abbrev_info
);
16080 memset (abbrev
, 0, sizeof (struct abbrev_info
));
16085 /* Add an abbreviation to the table. */
16088 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
16089 unsigned int abbrev_number
,
16090 struct abbrev_info
*abbrev
)
16092 unsigned int hash_number
;
16094 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
16095 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
16096 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
16099 /* Look up an abbrev in the table.
16100 Returns NULL if the abbrev is not found. */
16102 static struct abbrev_info
*
16103 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
16104 unsigned int abbrev_number
)
16106 unsigned int hash_number
;
16107 struct abbrev_info
*abbrev
;
16109 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
16110 abbrev
= abbrev_table
->abbrevs
[hash_number
];
16114 if (abbrev
->number
== abbrev_number
)
16116 abbrev
= abbrev
->next
;
16121 /* Read in an abbrev table. */
16123 static struct abbrev_table
*
16124 abbrev_table_read_table (struct dwarf2_section_info
*section
,
16125 sect_offset sect_off
)
16127 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16128 bfd
*abfd
= get_section_bfd_owner (section
);
16129 struct abbrev_table
*abbrev_table
;
16130 const gdb_byte
*abbrev_ptr
;
16131 struct abbrev_info
*cur_abbrev
;
16132 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
16133 unsigned int abbrev_form
;
16134 struct attr_abbrev
*cur_attrs
;
16135 unsigned int allocated_attrs
;
16137 abbrev_table
= XNEW (struct abbrev_table
);
16138 abbrev_table
->sect_off
= sect_off
;
16139 obstack_init (&abbrev_table
->abbrev_obstack
);
16140 abbrev_table
->abbrevs
=
16141 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct abbrev_info
*,
16143 memset (abbrev_table
->abbrevs
, 0,
16144 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
16146 dwarf2_read_section (objfile
, section
);
16147 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
16148 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
16149 abbrev_ptr
+= bytes_read
;
16151 allocated_attrs
= ATTR_ALLOC_CHUNK
;
16152 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
16154 /* Loop until we reach an abbrev number of 0. */
16155 while (abbrev_number
)
16157 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
16159 /* read in abbrev header */
16160 cur_abbrev
->number
= abbrev_number
;
16162 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
16163 abbrev_ptr
+= bytes_read
;
16164 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
16167 /* now read in declarations */
16170 LONGEST implicit_const
;
16172 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
16173 abbrev_ptr
+= bytes_read
;
16174 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
16175 abbrev_ptr
+= bytes_read
;
16176 if (abbrev_form
== DW_FORM_implicit_const
)
16178 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
16180 abbrev_ptr
+= bytes_read
;
16184 /* Initialize it due to a false compiler warning. */
16185 implicit_const
= -1;
16188 if (abbrev_name
== 0)
16191 if (cur_abbrev
->num_attrs
== allocated_attrs
)
16193 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
16195 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
16198 cur_attrs
[cur_abbrev
->num_attrs
].name
16199 = (enum dwarf_attribute
) abbrev_name
;
16200 cur_attrs
[cur_abbrev
->num_attrs
].form
16201 = (enum dwarf_form
) abbrev_form
;
16202 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
16203 ++cur_abbrev
->num_attrs
;
16206 cur_abbrev
->attrs
=
16207 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
16208 cur_abbrev
->num_attrs
);
16209 memcpy (cur_abbrev
->attrs
, cur_attrs
,
16210 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
16212 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
16214 /* Get next abbreviation.
16215 Under Irix6 the abbreviations for a compilation unit are not
16216 always properly terminated with an abbrev number of 0.
16217 Exit loop if we encounter an abbreviation which we have
16218 already read (which means we are about to read the abbreviations
16219 for the next compile unit) or if the end of the abbreviation
16220 table is reached. */
16221 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
16223 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
16224 abbrev_ptr
+= bytes_read
;
16225 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
16230 return abbrev_table
;
16233 /* Free the resources held by ABBREV_TABLE. */
16236 abbrev_table_free (struct abbrev_table
*abbrev_table
)
16238 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
16239 xfree (abbrev_table
);
16242 /* Same as abbrev_table_free but as a cleanup.
16243 We pass in a pointer to the pointer to the table so that we can
16244 set the pointer to NULL when we're done. It also simplifies
16245 build_type_psymtabs_1. */
16248 abbrev_table_free_cleanup (void *table_ptr
)
16250 struct abbrev_table
**abbrev_table_ptr
= (struct abbrev_table
**) table_ptr
;
16252 if (*abbrev_table_ptr
!= NULL
)
16253 abbrev_table_free (*abbrev_table_ptr
);
16254 *abbrev_table_ptr
= NULL
;
16257 /* Read the abbrev table for CU from ABBREV_SECTION. */
16260 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
16261 struct dwarf2_section_info
*abbrev_section
)
16264 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_sect_off
);
16267 /* Release the memory used by the abbrev table for a compilation unit. */
16270 dwarf2_free_abbrev_table (void *ptr_to_cu
)
16272 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr_to_cu
;
16274 if (cu
->abbrev_table
!= NULL
)
16275 abbrev_table_free (cu
->abbrev_table
);
16276 /* Set this to NULL so that we SEGV if we try to read it later,
16277 and also because free_comp_unit verifies this is NULL. */
16278 cu
->abbrev_table
= NULL
;
16281 /* Returns nonzero if TAG represents a type that we might generate a partial
16285 is_type_tag_for_partial (int tag
)
16290 /* Some types that would be reasonable to generate partial symbols for,
16291 that we don't at present. */
16292 case DW_TAG_array_type
:
16293 case DW_TAG_file_type
:
16294 case DW_TAG_ptr_to_member_type
:
16295 case DW_TAG_set_type
:
16296 case DW_TAG_string_type
:
16297 case DW_TAG_subroutine_type
:
16299 case DW_TAG_base_type
:
16300 case DW_TAG_class_type
:
16301 case DW_TAG_interface_type
:
16302 case DW_TAG_enumeration_type
:
16303 case DW_TAG_structure_type
:
16304 case DW_TAG_subrange_type
:
16305 case DW_TAG_typedef
:
16306 case DW_TAG_union_type
:
16313 /* Load all DIEs that are interesting for partial symbols into memory. */
16315 static struct partial_die_info
*
16316 load_partial_dies (const struct die_reader_specs
*reader
,
16317 const gdb_byte
*info_ptr
, int building_psymtab
)
16319 struct dwarf2_cu
*cu
= reader
->cu
;
16320 struct objfile
*objfile
= cu
->objfile
;
16321 struct partial_die_info
*part_die
;
16322 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
16323 struct abbrev_info
*abbrev
;
16324 unsigned int bytes_read
;
16325 unsigned int load_all
= 0;
16326 int nesting_level
= 1;
16331 gdb_assert (cu
->per_cu
!= NULL
);
16332 if (cu
->per_cu
->load_all_dies
)
16336 = htab_create_alloc_ex (cu
->header
.length
/ 12,
16340 &cu
->comp_unit_obstack
,
16341 hashtab_obstack_allocate
,
16342 dummy_obstack_deallocate
);
16344 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
16348 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
16350 /* A NULL abbrev means the end of a series of children. */
16351 if (abbrev
== NULL
)
16353 if (--nesting_level
== 0)
16355 /* PART_DIE was probably the last thing allocated on the
16356 comp_unit_obstack, so we could call obstack_free
16357 here. We don't do that because the waste is small,
16358 and will be cleaned up when we're done with this
16359 compilation unit. This way, we're also more robust
16360 against other users of the comp_unit_obstack. */
16363 info_ptr
+= bytes_read
;
16364 last_die
= parent_die
;
16365 parent_die
= parent_die
->die_parent
;
16369 /* Check for template arguments. We never save these; if
16370 they're seen, we just mark the parent, and go on our way. */
16371 if (parent_die
!= NULL
16372 && cu
->language
== language_cplus
16373 && (abbrev
->tag
== DW_TAG_template_type_param
16374 || abbrev
->tag
== DW_TAG_template_value_param
))
16376 parent_die
->has_template_arguments
= 1;
16380 /* We don't need a partial DIE for the template argument. */
16381 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
16386 /* We only recurse into c++ subprograms looking for template arguments.
16387 Skip their other children. */
16389 && cu
->language
== language_cplus
16390 && parent_die
!= NULL
16391 && parent_die
->tag
== DW_TAG_subprogram
)
16393 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
16397 /* Check whether this DIE is interesting enough to save. Normally
16398 we would not be interested in members here, but there may be
16399 later variables referencing them via DW_AT_specification (for
16400 static members). */
16402 && !is_type_tag_for_partial (abbrev
->tag
)
16403 && abbrev
->tag
!= DW_TAG_constant
16404 && abbrev
->tag
!= DW_TAG_enumerator
16405 && abbrev
->tag
!= DW_TAG_subprogram
16406 && abbrev
->tag
!= DW_TAG_lexical_block
16407 && abbrev
->tag
!= DW_TAG_variable
16408 && abbrev
->tag
!= DW_TAG_namespace
16409 && abbrev
->tag
!= DW_TAG_module
16410 && abbrev
->tag
!= DW_TAG_member
16411 && abbrev
->tag
!= DW_TAG_imported_unit
16412 && abbrev
->tag
!= DW_TAG_imported_declaration
)
16414 /* Otherwise we skip to the next sibling, if any. */
16415 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
16419 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
16422 /* This two-pass algorithm for processing partial symbols has a
16423 high cost in cache pressure. Thus, handle some simple cases
16424 here which cover the majority of C partial symbols. DIEs
16425 which neither have specification tags in them, nor could have
16426 specification tags elsewhere pointing at them, can simply be
16427 processed and discarded.
16429 This segment is also optional; scan_partial_symbols and
16430 add_partial_symbol will handle these DIEs if we chain
16431 them in normally. When compilers which do not emit large
16432 quantities of duplicate debug information are more common,
16433 this code can probably be removed. */
16435 /* Any complete simple types at the top level (pretty much all
16436 of them, for a language without namespaces), can be processed
16438 if (parent_die
== NULL
16439 && part_die
->has_specification
== 0
16440 && part_die
->is_declaration
== 0
16441 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
16442 || part_die
->tag
== DW_TAG_base_type
16443 || part_die
->tag
== DW_TAG_subrange_type
))
16445 if (building_psymtab
&& part_die
->name
!= NULL
)
16446 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
16447 VAR_DOMAIN
, LOC_TYPEDEF
,
16448 &objfile
->static_psymbols
,
16449 0, cu
->language
, objfile
);
16450 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
16454 /* The exception for DW_TAG_typedef with has_children above is
16455 a workaround of GCC PR debug/47510. In the case of this complaint
16456 type_name_no_tag_or_error will error on such types later.
16458 GDB skipped children of DW_TAG_typedef by the shortcut above and then
16459 it could not find the child DIEs referenced later, this is checked
16460 above. In correct DWARF DW_TAG_typedef should have no children. */
16462 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
16463 complaint (&symfile_complaints
,
16464 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
16465 "- DIE at 0x%x [in module %s]"),
16466 to_underlying (part_die
->sect_off
), objfile_name (objfile
));
16468 /* If we're at the second level, and we're an enumerator, and
16469 our parent has no specification (meaning possibly lives in a
16470 namespace elsewhere), then we can add the partial symbol now
16471 instead of queueing it. */
16472 if (part_die
->tag
== DW_TAG_enumerator
16473 && parent_die
!= NULL
16474 && parent_die
->die_parent
== NULL
16475 && parent_die
->tag
== DW_TAG_enumeration_type
16476 && parent_die
->has_specification
== 0)
16478 if (part_die
->name
== NULL
)
16479 complaint (&symfile_complaints
,
16480 _("malformed enumerator DIE ignored"));
16481 else if (building_psymtab
)
16482 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
16483 VAR_DOMAIN
, LOC_CONST
,
16484 cu
->language
== language_cplus
16485 ? &objfile
->global_psymbols
16486 : &objfile
->static_psymbols
,
16487 0, cu
->language
, objfile
);
16489 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
16493 /* We'll save this DIE so link it in. */
16494 part_die
->die_parent
= parent_die
;
16495 part_die
->die_sibling
= NULL
;
16496 part_die
->die_child
= NULL
;
16498 if (last_die
&& last_die
== parent_die
)
16499 last_die
->die_child
= part_die
;
16501 last_die
->die_sibling
= part_die
;
16503 last_die
= part_die
;
16505 if (first_die
== NULL
)
16506 first_die
= part_die
;
16508 /* Maybe add the DIE to the hash table. Not all DIEs that we
16509 find interesting need to be in the hash table, because we
16510 also have the parent/sibling/child chains; only those that we
16511 might refer to by offset later during partial symbol reading.
16513 For now this means things that might have be the target of a
16514 DW_AT_specification, DW_AT_abstract_origin, or
16515 DW_AT_extension. DW_AT_extension will refer only to
16516 namespaces; DW_AT_abstract_origin refers to functions (and
16517 many things under the function DIE, but we do not recurse
16518 into function DIEs during partial symbol reading) and
16519 possibly variables as well; DW_AT_specification refers to
16520 declarations. Declarations ought to have the DW_AT_declaration
16521 flag. It happens that GCC forgets to put it in sometimes, but
16522 only for functions, not for types.
16524 Adding more things than necessary to the hash table is harmless
16525 except for the performance cost. Adding too few will result in
16526 wasted time in find_partial_die, when we reread the compilation
16527 unit with load_all_dies set. */
16530 || abbrev
->tag
== DW_TAG_constant
16531 || abbrev
->tag
== DW_TAG_subprogram
16532 || abbrev
->tag
== DW_TAG_variable
16533 || abbrev
->tag
== DW_TAG_namespace
16534 || part_die
->is_declaration
)
16538 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
16539 to_underlying (part_die
->sect_off
),
16544 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
16546 /* For some DIEs we want to follow their children (if any). For C
16547 we have no reason to follow the children of structures; for other
16548 languages we have to, so that we can get at method physnames
16549 to infer fully qualified class names, for DW_AT_specification,
16550 and for C++ template arguments. For C++, we also look one level
16551 inside functions to find template arguments (if the name of the
16552 function does not already contain the template arguments).
16554 For Ada, we need to scan the children of subprograms and lexical
16555 blocks as well because Ada allows the definition of nested
16556 entities that could be interesting for the debugger, such as
16557 nested subprograms for instance. */
16558 if (last_die
->has_children
16560 || last_die
->tag
== DW_TAG_namespace
16561 || last_die
->tag
== DW_TAG_module
16562 || last_die
->tag
== DW_TAG_enumeration_type
16563 || (cu
->language
== language_cplus
16564 && last_die
->tag
== DW_TAG_subprogram
16565 && (last_die
->name
== NULL
16566 || strchr (last_die
->name
, '<') == NULL
))
16567 || (cu
->language
!= language_c
16568 && (last_die
->tag
== DW_TAG_class_type
16569 || last_die
->tag
== DW_TAG_interface_type
16570 || last_die
->tag
== DW_TAG_structure_type
16571 || last_die
->tag
== DW_TAG_union_type
))
16572 || (cu
->language
== language_ada
16573 && (last_die
->tag
== DW_TAG_subprogram
16574 || last_die
->tag
== DW_TAG_lexical_block
))))
16577 parent_die
= last_die
;
16581 /* Otherwise we skip to the next sibling, if any. */
16582 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
16584 /* Back to the top, do it again. */
16588 /* Read a minimal amount of information into the minimal die structure. */
16590 static const gdb_byte
*
16591 read_partial_die (const struct die_reader_specs
*reader
,
16592 struct partial_die_info
*part_die
,
16593 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
16594 const gdb_byte
*info_ptr
)
16596 struct dwarf2_cu
*cu
= reader
->cu
;
16597 struct objfile
*objfile
= cu
->objfile
;
16598 const gdb_byte
*buffer
= reader
->buffer
;
16600 struct attribute attr
;
16601 int has_low_pc_attr
= 0;
16602 int has_high_pc_attr
= 0;
16603 int high_pc_relative
= 0;
16605 memset (part_die
, 0, sizeof (struct partial_die_info
));
16607 part_die
->sect_off
= (sect_offset
) (info_ptr
- buffer
);
16609 info_ptr
+= abbrev_len
;
16611 if (abbrev
== NULL
)
16614 part_die
->tag
= abbrev
->tag
;
16615 part_die
->has_children
= abbrev
->has_children
;
16617 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
16619 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
16621 /* Store the data if it is of an attribute we want to keep in a
16622 partial symbol table. */
16626 switch (part_die
->tag
)
16628 case DW_TAG_compile_unit
:
16629 case DW_TAG_partial_unit
:
16630 case DW_TAG_type_unit
:
16631 /* Compilation units have a DW_AT_name that is a filename, not
16632 a source language identifier. */
16633 case DW_TAG_enumeration_type
:
16634 case DW_TAG_enumerator
:
16635 /* These tags always have simple identifiers already; no need
16636 to canonicalize them. */
16637 part_die
->name
= DW_STRING (&attr
);
16641 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
16642 &objfile
->per_bfd
->storage_obstack
);
16646 case DW_AT_linkage_name
:
16647 case DW_AT_MIPS_linkage_name
:
16648 /* Note that both forms of linkage name might appear. We
16649 assume they will be the same, and we only store the last
16651 if (cu
->language
== language_ada
)
16652 part_die
->name
= DW_STRING (&attr
);
16653 part_die
->linkage_name
= DW_STRING (&attr
);
16656 has_low_pc_attr
= 1;
16657 part_die
->lowpc
= attr_value_as_address (&attr
);
16659 case DW_AT_high_pc
:
16660 has_high_pc_attr
= 1;
16661 part_die
->highpc
= attr_value_as_address (&attr
);
16662 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
16663 high_pc_relative
= 1;
16665 case DW_AT_location
:
16666 /* Support the .debug_loc offsets. */
16667 if (attr_form_is_block (&attr
))
16669 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
16671 else if (attr_form_is_section_offset (&attr
))
16673 dwarf2_complex_location_expr_complaint ();
16677 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16678 "partial symbol information");
16681 case DW_AT_external
:
16682 part_die
->is_external
= DW_UNSND (&attr
);
16684 case DW_AT_declaration
:
16685 part_die
->is_declaration
= DW_UNSND (&attr
);
16688 part_die
->has_type
= 1;
16690 case DW_AT_abstract_origin
:
16691 case DW_AT_specification
:
16692 case DW_AT_extension
:
16693 part_die
->has_specification
= 1;
16694 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
16695 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
16696 || cu
->per_cu
->is_dwz
);
16698 case DW_AT_sibling
:
16699 /* Ignore absolute siblings, they might point outside of
16700 the current compile unit. */
16701 if (attr
.form
== DW_FORM_ref_addr
)
16702 complaint (&symfile_complaints
,
16703 _("ignoring absolute DW_AT_sibling"));
16706 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
16707 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
16709 if (sibling_ptr
< info_ptr
)
16710 complaint (&symfile_complaints
,
16711 _("DW_AT_sibling points backwards"));
16712 else if (sibling_ptr
> reader
->buffer_end
)
16713 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
16715 part_die
->sibling
= sibling_ptr
;
16718 case DW_AT_byte_size
:
16719 part_die
->has_byte_size
= 1;
16721 case DW_AT_const_value
:
16722 part_die
->has_const_value
= 1;
16724 case DW_AT_calling_convention
:
16725 /* DWARF doesn't provide a way to identify a program's source-level
16726 entry point. DW_AT_calling_convention attributes are only meant
16727 to describe functions' calling conventions.
16729 However, because it's a necessary piece of information in
16730 Fortran, and before DWARF 4 DW_CC_program was the only
16731 piece of debugging information whose definition refers to
16732 a 'main program' at all, several compilers marked Fortran
16733 main programs with DW_CC_program --- even when those
16734 functions use the standard calling conventions.
16736 Although DWARF now specifies a way to provide this
16737 information, we support this practice for backward
16739 if (DW_UNSND (&attr
) == DW_CC_program
16740 && cu
->language
== language_fortran
)
16741 part_die
->main_subprogram
= 1;
16744 if (DW_UNSND (&attr
) == DW_INL_inlined
16745 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
16746 part_die
->may_be_inlined
= 1;
16750 if (part_die
->tag
== DW_TAG_imported_unit
)
16752 part_die
->d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
16753 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
16754 || cu
->per_cu
->is_dwz
);
16758 case DW_AT_main_subprogram
:
16759 part_die
->main_subprogram
= DW_UNSND (&attr
);
16767 if (high_pc_relative
)
16768 part_die
->highpc
+= part_die
->lowpc
;
16770 if (has_low_pc_attr
&& has_high_pc_attr
)
16772 /* When using the GNU linker, .gnu.linkonce. sections are used to
16773 eliminate duplicate copies of functions and vtables and such.
16774 The linker will arbitrarily choose one and discard the others.
16775 The AT_*_pc values for such functions refer to local labels in
16776 these sections. If the section from that file was discarded, the
16777 labels are not in the output, so the relocs get a value of 0.
16778 If this is a discarded function, mark the pc bounds as invalid,
16779 so that GDB will ignore it. */
16780 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
16782 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16784 complaint (&symfile_complaints
,
16785 _("DW_AT_low_pc %s is zero "
16786 "for DIE at 0x%x [in module %s]"),
16787 paddress (gdbarch
, part_die
->lowpc
),
16788 to_underlying (part_die
->sect_off
), objfile_name (objfile
));
16790 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
16791 else if (part_die
->lowpc
>= part_die
->highpc
)
16793 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16795 complaint (&symfile_complaints
,
16796 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
16797 "for DIE at 0x%x [in module %s]"),
16798 paddress (gdbarch
, part_die
->lowpc
),
16799 paddress (gdbarch
, part_die
->highpc
),
16800 to_underlying (part_die
->sect_off
),
16801 objfile_name (objfile
));
16804 part_die
->has_pc_info
= 1;
16810 /* Find a cached partial DIE at OFFSET in CU. */
16812 static struct partial_die_info
*
16813 find_partial_die_in_comp_unit (sect_offset sect_off
, struct dwarf2_cu
*cu
)
16815 struct partial_die_info
*lookup_die
= NULL
;
16816 struct partial_die_info part_die
;
16818 part_die
.sect_off
= sect_off
;
16819 lookup_die
= ((struct partial_die_info
*)
16820 htab_find_with_hash (cu
->partial_dies
, &part_die
,
16821 to_underlying (sect_off
)));
16826 /* Find a partial DIE at OFFSET, which may or may not be in CU,
16827 except in the case of .debug_types DIEs which do not reference
16828 outside their CU (they do however referencing other types via
16829 DW_FORM_ref_sig8). */
16831 static struct partial_die_info
*
16832 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
16834 struct objfile
*objfile
= cu
->objfile
;
16835 struct dwarf2_per_cu_data
*per_cu
= NULL
;
16836 struct partial_die_info
*pd
= NULL
;
16838 if (offset_in_dwz
== cu
->per_cu
->is_dwz
16839 && offset_in_cu_p (&cu
->header
, sect_off
))
16841 pd
= find_partial_die_in_comp_unit (sect_off
, cu
);
16844 /* We missed recording what we needed.
16845 Load all dies and try again. */
16846 per_cu
= cu
->per_cu
;
16850 /* TUs don't reference other CUs/TUs (except via type signatures). */
16851 if (cu
->per_cu
->is_debug_types
)
16853 error (_("Dwarf Error: Type Unit at offset 0x%x contains"
16854 " external reference to offset 0x%x [in module %s].\n"),
16855 to_underlying (cu
->header
.sect_off
), to_underlying (sect_off
),
16856 bfd_get_filename (objfile
->obfd
));
16858 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
16861 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
16862 load_partial_comp_unit (per_cu
);
16864 per_cu
->cu
->last_used
= 0;
16865 pd
= find_partial_die_in_comp_unit (sect_off
, per_cu
->cu
);
16868 /* If we didn't find it, and not all dies have been loaded,
16869 load them all and try again. */
16871 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
16873 per_cu
->load_all_dies
= 1;
16875 /* This is nasty. When we reread the DIEs, somewhere up the call chain
16876 THIS_CU->cu may already be in use. So we can't just free it and
16877 replace its DIEs with the ones we read in. Instead, we leave those
16878 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
16879 and clobber THIS_CU->cu->partial_dies with the hash table for the new
16881 load_partial_comp_unit (per_cu
);
16883 pd
= find_partial_die_in_comp_unit (sect_off
, per_cu
->cu
);
16887 internal_error (__FILE__
, __LINE__
,
16888 _("could not find partial DIE 0x%x "
16889 "in cache [from module %s]\n"),
16890 to_underlying (sect_off
), bfd_get_filename (objfile
->obfd
));
16894 /* See if we can figure out if the class lives in a namespace. We do
16895 this by looking for a member function; its demangled name will
16896 contain namespace info, if there is any. */
16899 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
16900 struct dwarf2_cu
*cu
)
16902 /* NOTE: carlton/2003-10-07: Getting the info this way changes
16903 what template types look like, because the demangler
16904 frequently doesn't give the same name as the debug info. We
16905 could fix this by only using the demangled name to get the
16906 prefix (but see comment in read_structure_type). */
16908 struct partial_die_info
*real_pdi
;
16909 struct partial_die_info
*child_pdi
;
16911 /* If this DIE (this DIE's specification, if any) has a parent, then
16912 we should not do this. We'll prepend the parent's fully qualified
16913 name when we create the partial symbol. */
16915 real_pdi
= struct_pdi
;
16916 while (real_pdi
->has_specification
)
16917 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
16918 real_pdi
->spec_is_dwz
, cu
);
16920 if (real_pdi
->die_parent
!= NULL
)
16923 for (child_pdi
= struct_pdi
->die_child
;
16925 child_pdi
= child_pdi
->die_sibling
)
16927 if (child_pdi
->tag
== DW_TAG_subprogram
16928 && child_pdi
->linkage_name
!= NULL
)
16930 char *actual_class_name
16931 = language_class_name_from_physname (cu
->language_defn
,
16932 child_pdi
->linkage_name
);
16933 if (actual_class_name
!= NULL
)
16937 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16939 strlen (actual_class_name
)));
16940 xfree (actual_class_name
);
16947 /* Adjust PART_DIE before generating a symbol for it. This function
16948 may set the is_external flag or change the DIE's name. */
16951 fixup_partial_die (struct partial_die_info
*part_die
,
16952 struct dwarf2_cu
*cu
)
16954 /* Once we've fixed up a die, there's no point in doing so again.
16955 This also avoids a memory leak if we were to call
16956 guess_partial_die_structure_name multiple times. */
16957 if (part_die
->fixup_called
)
16960 /* If we found a reference attribute and the DIE has no name, try
16961 to find a name in the referred to DIE. */
16963 if (part_die
->name
== NULL
&& part_die
->has_specification
)
16965 struct partial_die_info
*spec_die
;
16967 spec_die
= find_partial_die (part_die
->spec_offset
,
16968 part_die
->spec_is_dwz
, cu
);
16970 fixup_partial_die (spec_die
, cu
);
16972 if (spec_die
->name
)
16974 part_die
->name
= spec_die
->name
;
16976 /* Copy DW_AT_external attribute if it is set. */
16977 if (spec_die
->is_external
)
16978 part_die
->is_external
= spec_die
->is_external
;
16982 /* Set default names for some unnamed DIEs. */
16984 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
16985 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
16987 /* If there is no parent die to provide a namespace, and there are
16988 children, see if we can determine the namespace from their linkage
16990 if (cu
->language
== language_cplus
16991 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
16992 && part_die
->die_parent
== NULL
16993 && part_die
->has_children
16994 && (part_die
->tag
== DW_TAG_class_type
16995 || part_die
->tag
== DW_TAG_structure_type
16996 || part_die
->tag
== DW_TAG_union_type
))
16997 guess_partial_die_structure_name (part_die
, cu
);
16999 /* GCC might emit a nameless struct or union that has a linkage
17000 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
17001 if (part_die
->name
== NULL
17002 && (part_die
->tag
== DW_TAG_class_type
17003 || part_die
->tag
== DW_TAG_interface_type
17004 || part_die
->tag
== DW_TAG_structure_type
17005 || part_die
->tag
== DW_TAG_union_type
)
17006 && part_die
->linkage_name
!= NULL
)
17010 demangled
= gdb_demangle (part_die
->linkage_name
, DMGL_TYPES
);
17015 /* Strip any leading namespaces/classes, keep only the base name.
17016 DW_AT_name for named DIEs does not contain the prefixes. */
17017 base
= strrchr (demangled
, ':');
17018 if (base
&& base
> demangled
&& base
[-1] == ':')
17025 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
17026 base
, strlen (base
)));
17031 part_die
->fixup_called
= 1;
17034 /* Read an attribute value described by an attribute form. */
17036 static const gdb_byte
*
17037 read_attribute_value (const struct die_reader_specs
*reader
,
17038 struct attribute
*attr
, unsigned form
,
17039 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
17041 struct dwarf2_cu
*cu
= reader
->cu
;
17042 struct objfile
*objfile
= cu
->objfile
;
17043 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17044 bfd
*abfd
= reader
->abfd
;
17045 struct comp_unit_head
*cu_header
= &cu
->header
;
17046 unsigned int bytes_read
;
17047 struct dwarf_block
*blk
;
17049 attr
->form
= (enum dwarf_form
) form
;
17052 case DW_FORM_ref_addr
:
17053 if (cu
->header
.version
== 2)
17054 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
17056 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
17057 &cu
->header
, &bytes_read
);
17058 info_ptr
+= bytes_read
;
17060 case DW_FORM_GNU_ref_alt
:
17061 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
17062 info_ptr
+= bytes_read
;
17065 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
17066 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
17067 info_ptr
+= bytes_read
;
17069 case DW_FORM_block2
:
17070 blk
= dwarf_alloc_block (cu
);
17071 blk
->size
= read_2_bytes (abfd
, info_ptr
);
17073 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
17074 info_ptr
+= blk
->size
;
17075 DW_BLOCK (attr
) = blk
;
17077 case DW_FORM_block4
:
17078 blk
= dwarf_alloc_block (cu
);
17079 blk
->size
= read_4_bytes (abfd
, info_ptr
);
17081 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
17082 info_ptr
+= blk
->size
;
17083 DW_BLOCK (attr
) = blk
;
17085 case DW_FORM_data2
:
17086 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
17089 case DW_FORM_data4
:
17090 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
17093 case DW_FORM_data8
:
17094 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
17097 case DW_FORM_data16
:
17098 blk
= dwarf_alloc_block (cu
);
17100 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
17102 DW_BLOCK (attr
) = blk
;
17104 case DW_FORM_sec_offset
:
17105 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
17106 info_ptr
+= bytes_read
;
17108 case DW_FORM_string
:
17109 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
17110 DW_STRING_IS_CANONICAL (attr
) = 0;
17111 info_ptr
+= bytes_read
;
17114 if (!cu
->per_cu
->is_dwz
)
17116 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
17118 DW_STRING_IS_CANONICAL (attr
) = 0;
17119 info_ptr
+= bytes_read
;
17123 case DW_FORM_line_strp
:
17124 if (!cu
->per_cu
->is_dwz
)
17126 DW_STRING (attr
) = read_indirect_line_string (abfd
, info_ptr
,
17127 cu_header
, &bytes_read
);
17128 DW_STRING_IS_CANONICAL (attr
) = 0;
17129 info_ptr
+= bytes_read
;
17133 case DW_FORM_GNU_strp_alt
:
17135 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
17136 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
17139 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
17140 DW_STRING_IS_CANONICAL (attr
) = 0;
17141 info_ptr
+= bytes_read
;
17144 case DW_FORM_exprloc
:
17145 case DW_FORM_block
:
17146 blk
= dwarf_alloc_block (cu
);
17147 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17148 info_ptr
+= bytes_read
;
17149 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
17150 info_ptr
+= blk
->size
;
17151 DW_BLOCK (attr
) = blk
;
17153 case DW_FORM_block1
:
17154 blk
= dwarf_alloc_block (cu
);
17155 blk
->size
= read_1_byte (abfd
, info_ptr
);
17157 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
17158 info_ptr
+= blk
->size
;
17159 DW_BLOCK (attr
) = blk
;
17161 case DW_FORM_data1
:
17162 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
17166 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
17169 case DW_FORM_flag_present
:
17170 DW_UNSND (attr
) = 1;
17172 case DW_FORM_sdata
:
17173 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
17174 info_ptr
+= bytes_read
;
17176 case DW_FORM_udata
:
17177 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17178 info_ptr
+= bytes_read
;
17181 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
17182 + read_1_byte (abfd
, info_ptr
));
17186 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
17187 + read_2_bytes (abfd
, info_ptr
));
17191 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
17192 + read_4_bytes (abfd
, info_ptr
));
17196 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
17197 + read_8_bytes (abfd
, info_ptr
));
17200 case DW_FORM_ref_sig8
:
17201 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
17204 case DW_FORM_ref_udata
:
17205 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
17206 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
17207 info_ptr
+= bytes_read
;
17209 case DW_FORM_indirect
:
17210 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17211 info_ptr
+= bytes_read
;
17212 if (form
== DW_FORM_implicit_const
)
17214 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
17215 info_ptr
+= bytes_read
;
17217 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
17220 case DW_FORM_implicit_const
:
17221 DW_SND (attr
) = implicit_const
;
17223 case DW_FORM_GNU_addr_index
:
17224 if (reader
->dwo_file
== NULL
)
17226 /* For now flag a hard error.
17227 Later we can turn this into a complaint. */
17228 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
17229 dwarf_form_name (form
),
17230 bfd_get_filename (abfd
));
17232 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
17233 info_ptr
+= bytes_read
;
17235 case DW_FORM_GNU_str_index
:
17236 if (reader
->dwo_file
== NULL
)
17238 /* For now flag a hard error.
17239 Later we can turn this into a complaint if warranted. */
17240 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
17241 dwarf_form_name (form
),
17242 bfd_get_filename (abfd
));
17245 ULONGEST str_index
=
17246 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17248 DW_STRING (attr
) = read_str_index (reader
, str_index
);
17249 DW_STRING_IS_CANONICAL (attr
) = 0;
17250 info_ptr
+= bytes_read
;
17254 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
17255 dwarf_form_name (form
),
17256 bfd_get_filename (abfd
));
17260 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
17261 attr
->form
= DW_FORM_GNU_ref_alt
;
17263 /* We have seen instances where the compiler tried to emit a byte
17264 size attribute of -1 which ended up being encoded as an unsigned
17265 0xffffffff. Although 0xffffffff is technically a valid size value,
17266 an object of this size seems pretty unlikely so we can relatively
17267 safely treat these cases as if the size attribute was invalid and
17268 treat them as zero by default. */
17269 if (attr
->name
== DW_AT_byte_size
17270 && form
== DW_FORM_data4
17271 && DW_UNSND (attr
) >= 0xffffffff)
17274 (&symfile_complaints
,
17275 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
17276 hex_string (DW_UNSND (attr
)));
17277 DW_UNSND (attr
) = 0;
17283 /* Read an attribute described by an abbreviated attribute. */
17285 static const gdb_byte
*
17286 read_attribute (const struct die_reader_specs
*reader
,
17287 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
17288 const gdb_byte
*info_ptr
)
17290 attr
->name
= abbrev
->name
;
17291 return read_attribute_value (reader
, attr
, abbrev
->form
,
17292 abbrev
->implicit_const
, info_ptr
);
17295 /* Read dwarf information from a buffer. */
17297 static unsigned int
17298 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
17300 return bfd_get_8 (abfd
, buf
);
17304 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
17306 return bfd_get_signed_8 (abfd
, buf
);
17309 static unsigned int
17310 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
17312 return bfd_get_16 (abfd
, buf
);
17316 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
17318 return bfd_get_signed_16 (abfd
, buf
);
17321 static unsigned int
17322 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
17324 return bfd_get_32 (abfd
, buf
);
17328 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
17330 return bfd_get_signed_32 (abfd
, buf
);
17334 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
17336 return bfd_get_64 (abfd
, buf
);
17340 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
17341 unsigned int *bytes_read
)
17343 struct comp_unit_head
*cu_header
= &cu
->header
;
17344 CORE_ADDR retval
= 0;
17346 if (cu_header
->signed_addr_p
)
17348 switch (cu_header
->addr_size
)
17351 retval
= bfd_get_signed_16 (abfd
, buf
);
17354 retval
= bfd_get_signed_32 (abfd
, buf
);
17357 retval
= bfd_get_signed_64 (abfd
, buf
);
17360 internal_error (__FILE__
, __LINE__
,
17361 _("read_address: bad switch, signed [in module %s]"),
17362 bfd_get_filename (abfd
));
17367 switch (cu_header
->addr_size
)
17370 retval
= bfd_get_16 (abfd
, buf
);
17373 retval
= bfd_get_32 (abfd
, buf
);
17376 retval
= bfd_get_64 (abfd
, buf
);
17379 internal_error (__FILE__
, __LINE__
,
17380 _("read_address: bad switch, "
17381 "unsigned [in module %s]"),
17382 bfd_get_filename (abfd
));
17386 *bytes_read
= cu_header
->addr_size
;
17390 /* Read the initial length from a section. The (draft) DWARF 3
17391 specification allows the initial length to take up either 4 bytes
17392 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
17393 bytes describe the length and all offsets will be 8 bytes in length
17396 An older, non-standard 64-bit format is also handled by this
17397 function. The older format in question stores the initial length
17398 as an 8-byte quantity without an escape value. Lengths greater
17399 than 2^32 aren't very common which means that the initial 4 bytes
17400 is almost always zero. Since a length value of zero doesn't make
17401 sense for the 32-bit format, this initial zero can be considered to
17402 be an escape value which indicates the presence of the older 64-bit
17403 format. As written, the code can't detect (old format) lengths
17404 greater than 4GB. If it becomes necessary to handle lengths
17405 somewhat larger than 4GB, we could allow other small values (such
17406 as the non-sensical values of 1, 2, and 3) to also be used as
17407 escape values indicating the presence of the old format.
17409 The value returned via bytes_read should be used to increment the
17410 relevant pointer after calling read_initial_length().
17412 [ Note: read_initial_length() and read_offset() are based on the
17413 document entitled "DWARF Debugging Information Format", revision
17414 3, draft 8, dated November 19, 2001. This document was obtained
17417 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
17419 This document is only a draft and is subject to change. (So beware.)
17421 Details regarding the older, non-standard 64-bit format were
17422 determined empirically by examining 64-bit ELF files produced by
17423 the SGI toolchain on an IRIX 6.5 machine.
17425 - Kevin, July 16, 2002
17429 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
17431 LONGEST length
= bfd_get_32 (abfd
, buf
);
17433 if (length
== 0xffffffff)
17435 length
= bfd_get_64 (abfd
, buf
+ 4);
17438 else if (length
== 0)
17440 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
17441 length
= bfd_get_64 (abfd
, buf
);
17452 /* Cover function for read_initial_length.
17453 Returns the length of the object at BUF, and stores the size of the
17454 initial length in *BYTES_READ and stores the size that offsets will be in
17456 If the initial length size is not equivalent to that specified in
17457 CU_HEADER then issue a complaint.
17458 This is useful when reading non-comp-unit headers. */
17461 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
17462 const struct comp_unit_head
*cu_header
,
17463 unsigned int *bytes_read
,
17464 unsigned int *offset_size
)
17466 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
17468 gdb_assert (cu_header
->initial_length_size
== 4
17469 || cu_header
->initial_length_size
== 8
17470 || cu_header
->initial_length_size
== 12);
17472 if (cu_header
->initial_length_size
!= *bytes_read
)
17473 complaint (&symfile_complaints
,
17474 _("intermixed 32-bit and 64-bit DWARF sections"));
17476 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
17480 /* Read an offset from the data stream. The size of the offset is
17481 given by cu_header->offset_size. */
17484 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
17485 const struct comp_unit_head
*cu_header
,
17486 unsigned int *bytes_read
)
17488 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
17490 *bytes_read
= cu_header
->offset_size
;
17494 /* Read an offset from the data stream. */
17497 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
17499 LONGEST retval
= 0;
17501 switch (offset_size
)
17504 retval
= bfd_get_32 (abfd
, buf
);
17507 retval
= bfd_get_64 (abfd
, buf
);
17510 internal_error (__FILE__
, __LINE__
,
17511 _("read_offset_1: bad switch [in module %s]"),
17512 bfd_get_filename (abfd
));
17518 static const gdb_byte
*
17519 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
17521 /* If the size of a host char is 8 bits, we can return a pointer
17522 to the buffer, otherwise we have to copy the data to a buffer
17523 allocated on the temporary obstack. */
17524 gdb_assert (HOST_CHAR_BIT
== 8);
17528 static const char *
17529 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
17530 unsigned int *bytes_read_ptr
)
17532 /* If the size of a host char is 8 bits, we can return a pointer
17533 to the string, otherwise we have to copy the string to a buffer
17534 allocated on the temporary obstack. */
17535 gdb_assert (HOST_CHAR_BIT
== 8);
17538 *bytes_read_ptr
= 1;
17541 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
17542 return (const char *) buf
;
17545 /* Return pointer to string at section SECT offset STR_OFFSET with error
17546 reporting strings FORM_NAME and SECT_NAME. */
17548 static const char *
17549 read_indirect_string_at_offset_from (bfd
*abfd
, LONGEST str_offset
,
17550 struct dwarf2_section_info
*sect
,
17551 const char *form_name
,
17552 const char *sect_name
)
17554 dwarf2_read_section (dwarf2_per_objfile
->objfile
, sect
);
17555 if (sect
->buffer
== NULL
)
17556 error (_("%s used without %s section [in module %s]"),
17557 form_name
, sect_name
, bfd_get_filename (abfd
));
17558 if (str_offset
>= sect
->size
)
17559 error (_("%s pointing outside of %s section [in module %s]"),
17560 form_name
, sect_name
, bfd_get_filename (abfd
));
17561 gdb_assert (HOST_CHAR_BIT
== 8);
17562 if (sect
->buffer
[str_offset
] == '\0')
17564 return (const char *) (sect
->buffer
+ str_offset
);
17567 /* Return pointer to string at .debug_str offset STR_OFFSET. */
17569 static const char *
17570 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
17572 return read_indirect_string_at_offset_from (abfd
, str_offset
,
17573 &dwarf2_per_objfile
->str
,
17574 "DW_FORM_strp", ".debug_str");
17577 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
17579 static const char *
17580 read_indirect_line_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
17582 return read_indirect_string_at_offset_from (abfd
, str_offset
,
17583 &dwarf2_per_objfile
->line_str
,
17584 "DW_FORM_line_strp",
17585 ".debug_line_str");
17588 /* Read a string at offset STR_OFFSET in the .debug_str section from
17589 the .dwz file DWZ. Throw an error if the offset is too large. If
17590 the string consists of a single NUL byte, return NULL; otherwise
17591 return a pointer to the string. */
17593 static const char *
17594 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
17596 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
17598 if (dwz
->str
.buffer
== NULL
)
17599 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
17600 "section [in module %s]"),
17601 bfd_get_filename (dwz
->dwz_bfd
));
17602 if (str_offset
>= dwz
->str
.size
)
17603 error (_("DW_FORM_GNU_strp_alt pointing outside of "
17604 ".debug_str section [in module %s]"),
17605 bfd_get_filename (dwz
->dwz_bfd
));
17606 gdb_assert (HOST_CHAR_BIT
== 8);
17607 if (dwz
->str
.buffer
[str_offset
] == '\0')
17609 return (const char *) (dwz
->str
.buffer
+ str_offset
);
17612 /* Return pointer to string at .debug_str offset as read from BUF.
17613 BUF is assumed to be in a compilation unit described by CU_HEADER.
17614 Return *BYTES_READ_PTR count of bytes read from BUF. */
17616 static const char *
17617 read_indirect_string (bfd
*abfd
, const gdb_byte
*buf
,
17618 const struct comp_unit_head
*cu_header
,
17619 unsigned int *bytes_read_ptr
)
17621 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
17623 return read_indirect_string_at_offset (abfd
, str_offset
);
17626 /* Return pointer to string at .debug_line_str offset as read from BUF.
17627 BUF is assumed to be in a compilation unit described by CU_HEADER.
17628 Return *BYTES_READ_PTR count of bytes read from BUF. */
17630 static const char *
17631 read_indirect_line_string (bfd
*abfd
, const gdb_byte
*buf
,
17632 const struct comp_unit_head
*cu_header
,
17633 unsigned int *bytes_read_ptr
)
17635 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
17637 return read_indirect_line_string_at_offset (abfd
, str_offset
);
17641 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
17642 unsigned int *bytes_read_ptr
)
17645 unsigned int num_read
;
17647 unsigned char byte
;
17654 byte
= bfd_get_8 (abfd
, buf
);
17657 result
|= ((ULONGEST
) (byte
& 127) << shift
);
17658 if ((byte
& 128) == 0)
17664 *bytes_read_ptr
= num_read
;
17669 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
17670 unsigned int *bytes_read_ptr
)
17673 int shift
, num_read
;
17674 unsigned char byte
;
17681 byte
= bfd_get_8 (abfd
, buf
);
17684 result
|= ((LONGEST
) (byte
& 127) << shift
);
17686 if ((byte
& 128) == 0)
17691 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
17692 result
|= -(((LONGEST
) 1) << shift
);
17693 *bytes_read_ptr
= num_read
;
17697 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
17698 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
17699 ADDR_SIZE is the size of addresses from the CU header. */
17702 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
17704 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17705 bfd
*abfd
= objfile
->obfd
;
17706 const gdb_byte
*info_ptr
;
17708 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
17709 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
17710 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
17711 objfile_name (objfile
));
17712 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
17713 error (_("DW_FORM_addr_index pointing outside of "
17714 ".debug_addr section [in module %s]"),
17715 objfile_name (objfile
));
17716 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
17717 + addr_base
+ addr_index
* addr_size
);
17718 if (addr_size
== 4)
17719 return bfd_get_32 (abfd
, info_ptr
);
17721 return bfd_get_64 (abfd
, info_ptr
);
17724 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
17727 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
17729 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
17732 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
17735 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
17736 unsigned int *bytes_read
)
17738 bfd
*abfd
= cu
->objfile
->obfd
;
17739 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
17741 return read_addr_index (cu
, addr_index
);
17744 /* Data structure to pass results from dwarf2_read_addr_index_reader
17745 back to dwarf2_read_addr_index. */
17747 struct dwarf2_read_addr_index_data
17749 ULONGEST addr_base
;
17753 /* die_reader_func for dwarf2_read_addr_index. */
17756 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
17757 const gdb_byte
*info_ptr
,
17758 struct die_info
*comp_unit_die
,
17762 struct dwarf2_cu
*cu
= reader
->cu
;
17763 struct dwarf2_read_addr_index_data
*aidata
=
17764 (struct dwarf2_read_addr_index_data
*) data
;
17766 aidata
->addr_base
= cu
->addr_base
;
17767 aidata
->addr_size
= cu
->header
.addr_size
;
17770 /* Given an index in .debug_addr, fetch the value.
17771 NOTE: This can be called during dwarf expression evaluation,
17772 long after the debug information has been read, and thus per_cu->cu
17773 may no longer exist. */
17776 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
17777 unsigned int addr_index
)
17779 struct objfile
*objfile
= per_cu
->objfile
;
17780 struct dwarf2_cu
*cu
= per_cu
->cu
;
17781 ULONGEST addr_base
;
17784 /* This is intended to be called from outside this file. */
17785 dw2_setup (objfile
);
17787 /* We need addr_base and addr_size.
17788 If we don't have PER_CU->cu, we have to get it.
17789 Nasty, but the alternative is storing the needed info in PER_CU,
17790 which at this point doesn't seem justified: it's not clear how frequently
17791 it would get used and it would increase the size of every PER_CU.
17792 Entry points like dwarf2_per_cu_addr_size do a similar thing
17793 so we're not in uncharted territory here.
17794 Alas we need to be a bit more complicated as addr_base is contained
17797 We don't need to read the entire CU(/TU).
17798 We just need the header and top level die.
17800 IWBN to use the aging mechanism to let us lazily later discard the CU.
17801 For now we skip this optimization. */
17805 addr_base
= cu
->addr_base
;
17806 addr_size
= cu
->header
.addr_size
;
17810 struct dwarf2_read_addr_index_data aidata
;
17812 /* Note: We can't use init_cutu_and_read_dies_simple here,
17813 we need addr_base. */
17814 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
17815 dwarf2_read_addr_index_reader
, &aidata
);
17816 addr_base
= aidata
.addr_base
;
17817 addr_size
= aidata
.addr_size
;
17820 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
17823 /* Given a DW_FORM_GNU_str_index, fetch the string.
17824 This is only used by the Fission support. */
17826 static const char *
17827 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
17829 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17830 const char *objf_name
= objfile_name (objfile
);
17831 bfd
*abfd
= objfile
->obfd
;
17832 struct dwarf2_cu
*cu
= reader
->cu
;
17833 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
17834 struct dwarf2_section_info
*str_offsets_section
=
17835 &reader
->dwo_file
->sections
.str_offsets
;
17836 const gdb_byte
*info_ptr
;
17837 ULONGEST str_offset
;
17838 static const char form_name
[] = "DW_FORM_GNU_str_index";
17840 dwarf2_read_section (objfile
, str_section
);
17841 dwarf2_read_section (objfile
, str_offsets_section
);
17842 if (str_section
->buffer
== NULL
)
17843 error (_("%s used without .debug_str.dwo section"
17844 " in CU at offset 0x%x [in module %s]"),
17845 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
17846 if (str_offsets_section
->buffer
== NULL
)
17847 error (_("%s used without .debug_str_offsets.dwo section"
17848 " in CU at offset 0x%x [in module %s]"),
17849 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
17850 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
17851 error (_("%s pointing outside of .debug_str_offsets.dwo"
17852 " section in CU at offset 0x%x [in module %s]"),
17853 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
17854 info_ptr
= (str_offsets_section
->buffer
17855 + str_index
* cu
->header
.offset_size
);
17856 if (cu
->header
.offset_size
== 4)
17857 str_offset
= bfd_get_32 (abfd
, info_ptr
);
17859 str_offset
= bfd_get_64 (abfd
, info_ptr
);
17860 if (str_offset
>= str_section
->size
)
17861 error (_("Offset from %s pointing outside of"
17862 " .debug_str.dwo section in CU at offset 0x%x [in module %s]"),
17863 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
17864 return (const char *) (str_section
->buffer
+ str_offset
);
17867 /* Return the length of an LEB128 number in BUF. */
17870 leb128_size (const gdb_byte
*buf
)
17872 const gdb_byte
*begin
= buf
;
17878 if ((byte
& 128) == 0)
17879 return buf
- begin
;
17884 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
17893 cu
->language
= language_c
;
17896 case DW_LANG_C_plus_plus
:
17897 case DW_LANG_C_plus_plus_11
:
17898 case DW_LANG_C_plus_plus_14
:
17899 cu
->language
= language_cplus
;
17902 cu
->language
= language_d
;
17904 case DW_LANG_Fortran77
:
17905 case DW_LANG_Fortran90
:
17906 case DW_LANG_Fortran95
:
17907 case DW_LANG_Fortran03
:
17908 case DW_LANG_Fortran08
:
17909 cu
->language
= language_fortran
;
17912 cu
->language
= language_go
;
17914 case DW_LANG_Mips_Assembler
:
17915 cu
->language
= language_asm
;
17917 case DW_LANG_Ada83
:
17918 case DW_LANG_Ada95
:
17919 cu
->language
= language_ada
;
17921 case DW_LANG_Modula2
:
17922 cu
->language
= language_m2
;
17924 case DW_LANG_Pascal83
:
17925 cu
->language
= language_pascal
;
17928 cu
->language
= language_objc
;
17931 case DW_LANG_Rust_old
:
17932 cu
->language
= language_rust
;
17934 case DW_LANG_Cobol74
:
17935 case DW_LANG_Cobol85
:
17937 cu
->language
= language_minimal
;
17940 cu
->language_defn
= language_def (cu
->language
);
17943 /* Return the named attribute or NULL if not there. */
17945 static struct attribute
*
17946 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17951 struct attribute
*spec
= NULL
;
17953 for (i
= 0; i
< die
->num_attrs
; ++i
)
17955 if (die
->attrs
[i
].name
== name
)
17956 return &die
->attrs
[i
];
17957 if (die
->attrs
[i
].name
== DW_AT_specification
17958 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
17959 spec
= &die
->attrs
[i
];
17965 die
= follow_die_ref (die
, spec
, &cu
);
17971 /* Return the named attribute or NULL if not there,
17972 but do not follow DW_AT_specification, etc.
17973 This is for use in contexts where we're reading .debug_types dies.
17974 Following DW_AT_specification, DW_AT_abstract_origin will take us
17975 back up the chain, and we want to go down. */
17977 static struct attribute
*
17978 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
17982 for (i
= 0; i
< die
->num_attrs
; ++i
)
17983 if (die
->attrs
[i
].name
== name
)
17984 return &die
->attrs
[i
];
17989 /* Return the string associated with a string-typed attribute, or NULL if it
17990 is either not found or is of an incorrect type. */
17992 static const char *
17993 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17995 struct attribute
*attr
;
17996 const char *str
= NULL
;
17998 attr
= dwarf2_attr (die
, name
, cu
);
18002 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
18003 || attr
->form
== DW_FORM_string
18004 || attr
->form
== DW_FORM_GNU_str_index
18005 || attr
->form
== DW_FORM_GNU_strp_alt
)
18006 str
= DW_STRING (attr
);
18008 complaint (&symfile_complaints
,
18009 _("string type expected for attribute %s for "
18010 "DIE at 0x%x in module %s"),
18011 dwarf_attr_name (name
), to_underlying (die
->sect_off
),
18012 objfile_name (cu
->objfile
));
18018 /* Return non-zero iff the attribute NAME is defined for the given DIE,
18019 and holds a non-zero value. This function should only be used for
18020 DW_FORM_flag or DW_FORM_flag_present attributes. */
18023 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
18025 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
18027 return (attr
&& DW_UNSND (attr
));
18031 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
18033 /* A DIE is a declaration if it has a DW_AT_declaration attribute
18034 which value is non-zero. However, we have to be careful with
18035 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
18036 (via dwarf2_flag_true_p) follows this attribute. So we may
18037 end up accidently finding a declaration attribute that belongs
18038 to a different DIE referenced by the specification attribute,
18039 even though the given DIE does not have a declaration attribute. */
18040 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
18041 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
18044 /* Return the die giving the specification for DIE, if there is
18045 one. *SPEC_CU is the CU containing DIE on input, and the CU
18046 containing the return value on output. If there is no
18047 specification, but there is an abstract origin, that is
18050 static struct die_info
*
18051 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
18053 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
18056 if (spec_attr
== NULL
)
18057 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
18059 if (spec_attr
== NULL
)
18062 return follow_die_ref (die
, spec_attr
, spec_cu
);
18065 /* Stub for free_line_header to match void * callback types. */
18068 free_line_header_voidp (void *arg
)
18070 struct line_header
*lh
= (struct line_header
*) arg
;
18076 line_header::add_include_dir (const char *include_dir
)
18078 if (dwarf_line_debug
>= 2)
18079 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
18080 include_dirs
.size () + 1, include_dir
);
18082 include_dirs
.push_back (include_dir
);
18086 line_header::add_file_name (const char *name
,
18088 unsigned int mod_time
,
18089 unsigned int length
)
18091 if (dwarf_line_debug
>= 2)
18092 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
18093 (unsigned) file_names
.size () + 1, name
);
18095 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
18098 /* A convenience function to find the proper .debug_line section for a CU. */
18100 static struct dwarf2_section_info
*
18101 get_debug_line_section (struct dwarf2_cu
*cu
)
18103 struct dwarf2_section_info
*section
;
18105 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
18107 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
18108 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
18109 else if (cu
->per_cu
->is_dwz
)
18111 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18113 section
= &dwz
->line
;
18116 section
= &dwarf2_per_objfile
->line
;
18121 /* Read directory or file name entry format, starting with byte of
18122 format count entries, ULEB128 pairs of entry formats, ULEB128 of
18123 entries count and the entries themselves in the described entry
18127 read_formatted_entries (bfd
*abfd
, const gdb_byte
**bufp
,
18128 struct line_header
*lh
,
18129 const struct comp_unit_head
*cu_header
,
18130 void (*callback
) (struct line_header
*lh
,
18133 unsigned int mod_time
,
18134 unsigned int length
))
18136 gdb_byte format_count
, formati
;
18137 ULONGEST data_count
, datai
;
18138 const gdb_byte
*buf
= *bufp
;
18139 const gdb_byte
*format_header_data
;
18141 unsigned int bytes_read
;
18143 format_count
= read_1_byte (abfd
, buf
);
18145 format_header_data
= buf
;
18146 for (formati
= 0; formati
< format_count
; formati
++)
18148 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
18150 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
18154 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
18156 for (datai
= 0; datai
< data_count
; datai
++)
18158 const gdb_byte
*format
= format_header_data
;
18159 struct file_entry fe
;
18161 for (formati
= 0; formati
< format_count
; formati
++)
18163 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
18164 format
+= bytes_read
;
18166 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
18167 format
+= bytes_read
;
18169 gdb::optional
<const char *> string
;
18170 gdb::optional
<unsigned int> uint
;
18174 case DW_FORM_string
:
18175 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
18179 case DW_FORM_line_strp
:
18180 string
.emplace (read_indirect_line_string (abfd
, buf
,
18186 case DW_FORM_data1
:
18187 uint
.emplace (read_1_byte (abfd
, buf
));
18191 case DW_FORM_data2
:
18192 uint
.emplace (read_2_bytes (abfd
, buf
));
18196 case DW_FORM_data4
:
18197 uint
.emplace (read_4_bytes (abfd
, buf
));
18201 case DW_FORM_data8
:
18202 uint
.emplace (read_8_bytes (abfd
, buf
));
18206 case DW_FORM_udata
:
18207 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
18211 case DW_FORM_block
:
18212 /* It is valid only for DW_LNCT_timestamp which is ignored by
18217 switch (content_type
)
18220 if (string
.has_value ())
18223 case DW_LNCT_directory_index
:
18224 if (uint
.has_value ())
18225 fe
.d_index
= (dir_index
) *uint
;
18227 case DW_LNCT_timestamp
:
18228 if (uint
.has_value ())
18229 fe
.mod_time
= *uint
;
18232 if (uint
.has_value ())
18238 complaint (&symfile_complaints
,
18239 _("Unknown format content type %s"),
18240 pulongest (content_type
));
18244 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
18250 /* Read the statement program header starting at OFFSET in
18251 .debug_line, or .debug_line.dwo. Return a pointer
18252 to a struct line_header, allocated using xmalloc.
18253 Returns NULL if there is a problem reading the header, e.g., if it
18254 has a version we don't understand.
18256 NOTE: the strings in the include directory and file name tables of
18257 the returned object point into the dwarf line section buffer,
18258 and must not be freed. */
18260 static line_header_up
18261 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
18263 const gdb_byte
*line_ptr
;
18264 unsigned int bytes_read
, offset_size
;
18266 const char *cur_dir
, *cur_file
;
18267 struct dwarf2_section_info
*section
;
18270 section
= get_debug_line_section (cu
);
18271 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
18272 if (section
->buffer
== NULL
)
18274 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
18275 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
18277 complaint (&symfile_complaints
, _("missing .debug_line section"));
18281 /* We can't do this until we know the section is non-empty.
18282 Only then do we know we have such a section. */
18283 abfd
= get_section_bfd_owner (section
);
18285 /* Make sure that at least there's room for the total_length field.
18286 That could be 12 bytes long, but we're just going to fudge that. */
18287 if (to_underlying (sect_off
) + 4 >= section
->size
)
18289 dwarf2_statement_list_fits_in_line_number_section_complaint ();
18293 line_header_up
lh (new line_header ());
18295 lh
->sect_off
= sect_off
;
18296 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
18298 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
18300 /* Read in the header. */
18302 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
18303 &bytes_read
, &offset_size
);
18304 line_ptr
+= bytes_read
;
18305 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
18307 dwarf2_statement_list_fits_in_line_number_section_complaint ();
18310 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
18311 lh
->version
= read_2_bytes (abfd
, line_ptr
);
18313 if (lh
->version
> 5)
18315 /* This is a version we don't understand. The format could have
18316 changed in ways we don't handle properly so just punt. */
18317 complaint (&symfile_complaints
,
18318 _("unsupported version in .debug_line section"));
18321 if (lh
->version
>= 5)
18323 gdb_byte segment_selector_size
;
18325 /* Skip address size. */
18326 read_1_byte (abfd
, line_ptr
);
18329 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
18331 if (segment_selector_size
!= 0)
18333 complaint (&symfile_complaints
,
18334 _("unsupported segment selector size %u "
18335 "in .debug_line section"),
18336 segment_selector_size
);
18340 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
18341 line_ptr
+= offset_size
;
18342 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
18344 if (lh
->version
>= 4)
18346 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
18350 lh
->maximum_ops_per_instruction
= 1;
18352 if (lh
->maximum_ops_per_instruction
== 0)
18354 lh
->maximum_ops_per_instruction
= 1;
18355 complaint (&symfile_complaints
,
18356 _("invalid maximum_ops_per_instruction "
18357 "in `.debug_line' section"));
18360 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
18362 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
18364 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
18366 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
18368 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
18370 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
18371 for (i
= 1; i
< lh
->opcode_base
; ++i
)
18373 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
18377 if (lh
->version
>= 5)
18379 /* Read directory table. */
18380 read_formatted_entries (abfd
, &line_ptr
, lh
.get (), &cu
->header
,
18381 [] (struct line_header
*lh
, const char *name
,
18382 dir_index d_index
, unsigned int mod_time
,
18383 unsigned int length
)
18385 lh
->add_include_dir (name
);
18388 /* Read file name table. */
18389 read_formatted_entries (abfd
, &line_ptr
, lh
.get (), &cu
->header
,
18390 [] (struct line_header
*lh
, const char *name
,
18391 dir_index d_index
, unsigned int mod_time
,
18392 unsigned int length
)
18394 lh
->add_file_name (name
, d_index
, mod_time
, length
);
18399 /* Read directory table. */
18400 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
18402 line_ptr
+= bytes_read
;
18403 lh
->add_include_dir (cur_dir
);
18405 line_ptr
+= bytes_read
;
18407 /* Read file name table. */
18408 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
18410 unsigned int mod_time
, length
;
18413 line_ptr
+= bytes_read
;
18414 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18415 line_ptr
+= bytes_read
;
18416 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18417 line_ptr
+= bytes_read
;
18418 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18419 line_ptr
+= bytes_read
;
18421 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
18423 line_ptr
+= bytes_read
;
18425 lh
->statement_program_start
= line_ptr
;
18427 if (line_ptr
> (section
->buffer
+ section
->size
))
18428 complaint (&symfile_complaints
,
18429 _("line number info header doesn't "
18430 "fit in `.debug_line' section"));
18435 /* Subroutine of dwarf_decode_lines to simplify it.
18436 Return the file name of the psymtab for included file FILE_INDEX
18437 in line header LH of PST.
18438 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
18439 If space for the result is malloc'd, it will be freed by a cleanup.
18440 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
18442 The function creates dangling cleanup registration. */
18444 static const char *
18445 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
18446 const struct partial_symtab
*pst
,
18447 const char *comp_dir
)
18449 const file_entry
&fe
= lh
->file_names
[file_index
];
18450 const char *include_name
= fe
.name
;
18451 const char *include_name_to_compare
= include_name
;
18452 const char *pst_filename
;
18453 char *copied_name
= NULL
;
18456 const char *dir_name
= fe
.include_dir (lh
);
18458 if (!IS_ABSOLUTE_PATH (include_name
)
18459 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
18461 /* Avoid creating a duplicate psymtab for PST.
18462 We do this by comparing INCLUDE_NAME and PST_FILENAME.
18463 Before we do the comparison, however, we need to account
18464 for DIR_NAME and COMP_DIR.
18465 First prepend dir_name (if non-NULL). If we still don't
18466 have an absolute path prepend comp_dir (if non-NULL).
18467 However, the directory we record in the include-file's
18468 psymtab does not contain COMP_DIR (to match the
18469 corresponding symtab(s)).
18474 bash$ gcc -g ./hello.c
18475 include_name = "hello.c"
18477 DW_AT_comp_dir = comp_dir = "/tmp"
18478 DW_AT_name = "./hello.c"
18482 if (dir_name
!= NULL
)
18484 char *tem
= concat (dir_name
, SLASH_STRING
,
18485 include_name
, (char *)NULL
);
18487 make_cleanup (xfree
, tem
);
18488 include_name
= tem
;
18489 include_name_to_compare
= include_name
;
18491 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
18493 char *tem
= concat (comp_dir
, SLASH_STRING
,
18494 include_name
, (char *)NULL
);
18496 make_cleanup (xfree
, tem
);
18497 include_name_to_compare
= tem
;
18501 pst_filename
= pst
->filename
;
18502 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
18504 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
18505 pst_filename
, (char *)NULL
);
18506 pst_filename
= copied_name
;
18509 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
18511 if (copied_name
!= NULL
)
18512 xfree (copied_name
);
18516 return include_name
;
18519 /* State machine to track the state of the line number program. */
18521 class lnp_state_machine
18524 /* Initialize a machine state for the start of a line number
18526 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
18528 file_entry
*current_file ()
18530 /* lh->file_names is 0-based, but the file name numbers in the
18531 statement program are 1-based. */
18532 return m_line_header
->file_name_at (m_file
);
18535 /* Record the line in the state machine. END_SEQUENCE is true if
18536 we're processing the end of a sequence. */
18537 void record_line (bool end_sequence
);
18539 /* Check address and if invalid nop-out the rest of the lines in this
18541 void check_line_address (struct dwarf2_cu
*cu
,
18542 const gdb_byte
*line_ptr
,
18543 CORE_ADDR lowpc
, CORE_ADDR address
);
18545 void handle_set_discriminator (unsigned int discriminator
)
18547 m_discriminator
= discriminator
;
18548 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
18551 /* Handle DW_LNE_set_address. */
18552 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
18555 address
+= baseaddr
;
18556 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
18559 /* Handle DW_LNS_advance_pc. */
18560 void handle_advance_pc (CORE_ADDR adjust
);
18562 /* Handle a special opcode. */
18563 void handle_special_opcode (unsigned char op_code
);
18565 /* Handle DW_LNS_advance_line. */
18566 void handle_advance_line (int line_delta
)
18568 advance_line (line_delta
);
18571 /* Handle DW_LNS_set_file. */
18572 void handle_set_file (file_name_index file
);
18574 /* Handle DW_LNS_negate_stmt. */
18575 void handle_negate_stmt ()
18577 m_is_stmt
= !m_is_stmt
;
18580 /* Handle DW_LNS_const_add_pc. */
18581 void handle_const_add_pc ();
18583 /* Handle DW_LNS_fixed_advance_pc. */
18584 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
18586 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18590 /* Handle DW_LNS_copy. */
18591 void handle_copy ()
18593 record_line (false);
18594 m_discriminator
= 0;
18597 /* Handle DW_LNE_end_sequence. */
18598 void handle_end_sequence ()
18600 m_record_line_callback
= ::record_line
;
18604 /* Advance the line by LINE_DELTA. */
18605 void advance_line (int line_delta
)
18607 m_line
+= line_delta
;
18609 if (line_delta
!= 0)
18610 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
18613 gdbarch
*m_gdbarch
;
18615 /* True if we're recording lines.
18616 Otherwise we're building partial symtabs and are just interested in
18617 finding include files mentioned by the line number program. */
18618 bool m_record_lines_p
;
18620 /* The line number header. */
18621 line_header
*m_line_header
;
18623 /* These are part of the standard DWARF line number state machine,
18624 and initialized according to the DWARF spec. */
18626 unsigned char m_op_index
= 0;
18627 /* The line table index (1-based) of the current file. */
18628 file_name_index m_file
= (file_name_index
) 1;
18629 unsigned int m_line
= 1;
18631 /* These are initialized in the constructor. */
18633 CORE_ADDR m_address
;
18635 unsigned int m_discriminator
;
18637 /* Additional bits of state we need to track. */
18639 /* The last file that we called dwarf2_start_subfile for.
18640 This is only used for TLLs. */
18641 unsigned int m_last_file
= 0;
18642 /* The last file a line number was recorded for. */
18643 struct subfile
*m_last_subfile
= NULL
;
18645 /* The function to call to record a line. */
18646 record_line_ftype
*m_record_line_callback
= NULL
;
18648 /* The last line number that was recorded, used to coalesce
18649 consecutive entries for the same line. This can happen, for
18650 example, when discriminators are present. PR 17276. */
18651 unsigned int m_last_line
= 0;
18652 bool m_line_has_non_zero_discriminator
= false;
18656 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
18658 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
18659 / m_line_header
->maximum_ops_per_instruction
)
18660 * m_line_header
->minimum_instruction_length
);
18661 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18662 m_op_index
= ((m_op_index
+ adjust
)
18663 % m_line_header
->maximum_ops_per_instruction
);
18667 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
18669 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
18670 CORE_ADDR addr_adj
= (((m_op_index
18671 + (adj_opcode
/ m_line_header
->line_range
))
18672 / m_line_header
->maximum_ops_per_instruction
)
18673 * m_line_header
->minimum_instruction_length
);
18674 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18675 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
18676 % m_line_header
->maximum_ops_per_instruction
);
18678 int line_delta
= (m_line_header
->line_base
18679 + (adj_opcode
% m_line_header
->line_range
));
18680 advance_line (line_delta
);
18681 record_line (false);
18682 m_discriminator
= 0;
18686 lnp_state_machine::handle_set_file (file_name_index file
)
18690 const file_entry
*fe
= current_file ();
18692 dwarf2_debug_line_missing_file_complaint ();
18693 else if (m_record_lines_p
)
18695 const char *dir
= fe
->include_dir (m_line_header
);
18697 m_last_subfile
= current_subfile
;
18698 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
18699 dwarf2_start_subfile (fe
->name
, dir
);
18704 lnp_state_machine::handle_const_add_pc ()
18707 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
18710 = (((m_op_index
+ adjust
)
18711 / m_line_header
->maximum_ops_per_instruction
)
18712 * m_line_header
->minimum_instruction_length
);
18714 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18715 m_op_index
= ((m_op_index
+ adjust
)
18716 % m_line_header
->maximum_ops_per_instruction
);
18719 /* Ignore this record_line request. */
18722 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
18727 /* Return non-zero if we should add LINE to the line number table.
18728 LINE is the line to add, LAST_LINE is the last line that was added,
18729 LAST_SUBFILE is the subfile for LAST_LINE.
18730 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
18731 had a non-zero discriminator.
18733 We have to be careful in the presence of discriminators.
18734 E.g., for this line:
18736 for (i = 0; i < 100000; i++);
18738 clang can emit four line number entries for that one line,
18739 each with a different discriminator.
18740 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
18742 However, we want gdb to coalesce all four entries into one.
18743 Otherwise the user could stepi into the middle of the line and
18744 gdb would get confused about whether the pc really was in the
18745 middle of the line.
18747 Things are further complicated by the fact that two consecutive
18748 line number entries for the same line is a heuristic used by gcc
18749 to denote the end of the prologue. So we can't just discard duplicate
18750 entries, we have to be selective about it. The heuristic we use is
18751 that we only collapse consecutive entries for the same line if at least
18752 one of those entries has a non-zero discriminator. PR 17276.
18754 Note: Addresses in the line number state machine can never go backwards
18755 within one sequence, thus this coalescing is ok. */
18758 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
18759 int line_has_non_zero_discriminator
,
18760 struct subfile
*last_subfile
)
18762 if (current_subfile
!= last_subfile
)
18764 if (line
!= last_line
)
18766 /* Same line for the same file that we've seen already.
18767 As a last check, for pr 17276, only record the line if the line
18768 has never had a non-zero discriminator. */
18769 if (!line_has_non_zero_discriminator
)
18774 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
18775 in the line table of subfile SUBFILE. */
18778 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
18779 unsigned int line
, CORE_ADDR address
,
18780 record_line_ftype p_record_line
)
18782 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
18784 if (dwarf_line_debug
)
18786 fprintf_unfiltered (gdb_stdlog
,
18787 "Recording line %u, file %s, address %s\n",
18788 line
, lbasename (subfile
->name
),
18789 paddress (gdbarch
, address
));
18792 (*p_record_line
) (subfile
, line
, addr
);
18795 /* Subroutine of dwarf_decode_lines_1 to simplify it.
18796 Mark the end of a set of line number records.
18797 The arguments are the same as for dwarf_record_line_1.
18798 If SUBFILE is NULL the request is ignored. */
18801 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
18802 CORE_ADDR address
, record_line_ftype p_record_line
)
18804 if (subfile
== NULL
)
18807 if (dwarf_line_debug
)
18809 fprintf_unfiltered (gdb_stdlog
,
18810 "Finishing current line, file %s, address %s\n",
18811 lbasename (subfile
->name
),
18812 paddress (gdbarch
, address
));
18815 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
18819 lnp_state_machine::record_line (bool end_sequence
)
18821 if (dwarf_line_debug
)
18823 fprintf_unfiltered (gdb_stdlog
,
18824 "Processing actual line %u: file %u,"
18825 " address %s, is_stmt %u, discrim %u\n",
18826 m_line
, to_underlying (m_file
),
18827 paddress (m_gdbarch
, m_address
),
18828 m_is_stmt
, m_discriminator
);
18831 file_entry
*fe
= current_file ();
18834 dwarf2_debug_line_missing_file_complaint ();
18835 /* For now we ignore lines not starting on an instruction boundary.
18836 But not when processing end_sequence for compatibility with the
18837 previous version of the code. */
18838 else if (m_op_index
== 0 || end_sequence
)
18840 fe
->included_p
= 1;
18841 if (m_record_lines_p
&& m_is_stmt
)
18843 if (m_last_subfile
!= current_subfile
|| end_sequence
)
18845 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
18846 m_address
, m_record_line_callback
);
18851 if (dwarf_record_line_p (m_line
, m_last_line
,
18852 m_line_has_non_zero_discriminator
,
18855 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
18857 m_record_line_callback
);
18859 m_last_subfile
= current_subfile
;
18860 m_last_line
= m_line
;
18866 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
18867 bool record_lines_p
)
18870 m_record_lines_p
= record_lines_p
;
18871 m_line_header
= lh
;
18873 m_record_line_callback
= ::record_line
;
18875 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
18876 was a line entry for it so that the backend has a chance to adjust it
18877 and also record it in case it needs it. This is currently used by MIPS
18878 code, cf. `mips_adjust_dwarf2_line'. */
18879 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
18880 m_is_stmt
= lh
->default_is_stmt
;
18881 m_discriminator
= 0;
18885 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
18886 const gdb_byte
*line_ptr
,
18887 CORE_ADDR lowpc
, CORE_ADDR address
)
18889 /* If address < lowpc then it's not a usable value, it's outside the
18890 pc range of the CU. However, we restrict the test to only address
18891 values of zero to preserve GDB's previous behaviour which is to
18892 handle the specific case of a function being GC'd by the linker. */
18894 if (address
== 0 && address
< lowpc
)
18896 /* This line table is for a function which has been
18897 GCd by the linker. Ignore it. PR gdb/12528 */
18899 struct objfile
*objfile
= cu
->objfile
;
18900 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
18902 complaint (&symfile_complaints
,
18903 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
18904 line_offset
, objfile_name (objfile
));
18905 m_record_line_callback
= noop_record_line
;
18906 /* Note: record_line_callback is left as noop_record_line until
18907 we see DW_LNE_end_sequence. */
18911 /* Subroutine of dwarf_decode_lines to simplify it.
18912 Process the line number information in LH.
18913 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
18914 program in order to set included_p for every referenced header. */
18917 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
18918 const int decode_for_pst_p
, CORE_ADDR lowpc
)
18920 const gdb_byte
*line_ptr
, *extended_end
;
18921 const gdb_byte
*line_end
;
18922 unsigned int bytes_read
, extended_len
;
18923 unsigned char op_code
, extended_op
;
18924 CORE_ADDR baseaddr
;
18925 struct objfile
*objfile
= cu
->objfile
;
18926 bfd
*abfd
= objfile
->obfd
;
18927 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18928 /* True if we're recording line info (as opposed to building partial
18929 symtabs and just interested in finding include files mentioned by
18930 the line number program). */
18931 bool record_lines_p
= !decode_for_pst_p
;
18933 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18935 line_ptr
= lh
->statement_program_start
;
18936 line_end
= lh
->statement_program_end
;
18938 /* Read the statement sequences until there's nothing left. */
18939 while (line_ptr
< line_end
)
18941 /* The DWARF line number program state machine. Reset the state
18942 machine at the start of each sequence. */
18943 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
18944 bool end_sequence
= false;
18946 if (record_lines_p
)
18948 /* Start a subfile for the current file of the state
18950 const file_entry
*fe
= state_machine
.current_file ();
18953 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
18956 /* Decode the table. */
18957 while (line_ptr
< line_end
&& !end_sequence
)
18959 op_code
= read_1_byte (abfd
, line_ptr
);
18962 if (op_code
>= lh
->opcode_base
)
18964 /* Special opcode. */
18965 state_machine
.handle_special_opcode (op_code
);
18967 else switch (op_code
)
18969 case DW_LNS_extended_op
:
18970 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
18972 line_ptr
+= bytes_read
;
18973 extended_end
= line_ptr
+ extended_len
;
18974 extended_op
= read_1_byte (abfd
, line_ptr
);
18976 switch (extended_op
)
18978 case DW_LNE_end_sequence
:
18979 state_machine
.handle_end_sequence ();
18980 end_sequence
= true;
18982 case DW_LNE_set_address
:
18985 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
18986 line_ptr
+= bytes_read
;
18988 state_machine
.check_line_address (cu
, line_ptr
,
18990 state_machine
.handle_set_address (baseaddr
, address
);
18993 case DW_LNE_define_file
:
18995 const char *cur_file
;
18996 unsigned int mod_time
, length
;
18999 cur_file
= read_direct_string (abfd
, line_ptr
,
19001 line_ptr
+= bytes_read
;
19002 dindex
= (dir_index
)
19003 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19004 line_ptr
+= bytes_read
;
19006 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19007 line_ptr
+= bytes_read
;
19009 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19010 line_ptr
+= bytes_read
;
19011 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
19014 case DW_LNE_set_discriminator
:
19016 /* The discriminator is not interesting to the
19017 debugger; just ignore it. We still need to
19018 check its value though:
19019 if there are consecutive entries for the same
19020 (non-prologue) line we want to coalesce them.
19023 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19024 line_ptr
+= bytes_read
;
19026 state_machine
.handle_set_discriminator (discr
);
19030 complaint (&symfile_complaints
,
19031 _("mangled .debug_line section"));
19034 /* Make sure that we parsed the extended op correctly. If e.g.
19035 we expected a different address size than the producer used,
19036 we may have read the wrong number of bytes. */
19037 if (line_ptr
!= extended_end
)
19039 complaint (&symfile_complaints
,
19040 _("mangled .debug_line section"));
19045 state_machine
.handle_copy ();
19047 case DW_LNS_advance_pc
:
19050 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19051 line_ptr
+= bytes_read
;
19053 state_machine
.handle_advance_pc (adjust
);
19056 case DW_LNS_advance_line
:
19059 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
19060 line_ptr
+= bytes_read
;
19062 state_machine
.handle_advance_line (line_delta
);
19065 case DW_LNS_set_file
:
19067 file_name_index file
19068 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
19070 line_ptr
+= bytes_read
;
19072 state_machine
.handle_set_file (file
);
19075 case DW_LNS_set_column
:
19076 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19077 line_ptr
+= bytes_read
;
19079 case DW_LNS_negate_stmt
:
19080 state_machine
.handle_negate_stmt ();
19082 case DW_LNS_set_basic_block
:
19084 /* Add to the address register of the state machine the
19085 address increment value corresponding to special opcode
19086 255. I.e., this value is scaled by the minimum
19087 instruction length since special opcode 255 would have
19088 scaled the increment. */
19089 case DW_LNS_const_add_pc
:
19090 state_machine
.handle_const_add_pc ();
19092 case DW_LNS_fixed_advance_pc
:
19094 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
19097 state_machine
.handle_fixed_advance_pc (addr_adj
);
19102 /* Unknown standard opcode, ignore it. */
19105 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
19107 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19108 line_ptr
+= bytes_read
;
19115 dwarf2_debug_line_missing_end_sequence_complaint ();
19117 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
19118 in which case we still finish recording the last line). */
19119 state_machine
.record_line (true);
19123 /* Decode the Line Number Program (LNP) for the given line_header
19124 structure and CU. The actual information extracted and the type
19125 of structures created from the LNP depends on the value of PST.
19127 1. If PST is NULL, then this procedure uses the data from the program
19128 to create all necessary symbol tables, and their linetables.
19130 2. If PST is not NULL, this procedure reads the program to determine
19131 the list of files included by the unit represented by PST, and
19132 builds all the associated partial symbol tables.
19134 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19135 It is used for relative paths in the line table.
19136 NOTE: When processing partial symtabs (pst != NULL),
19137 comp_dir == pst->dirname.
19139 NOTE: It is important that psymtabs have the same file name (via strcmp)
19140 as the corresponding symtab. Since COMP_DIR is not used in the name of the
19141 symtab we don't use it in the name of the psymtabs we create.
19142 E.g. expand_line_sal requires this when finding psymtabs to expand.
19143 A good testcase for this is mb-inline.exp.
19145 LOWPC is the lowest address in CU (or 0 if not known).
19147 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
19148 for its PC<->lines mapping information. Otherwise only the filename
19149 table is read in. */
19152 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
19153 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
19154 CORE_ADDR lowpc
, int decode_mapping
)
19156 struct objfile
*objfile
= cu
->objfile
;
19157 const int decode_for_pst_p
= (pst
!= NULL
);
19159 if (decode_mapping
)
19160 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
19162 if (decode_for_pst_p
)
19166 /* Now that we're done scanning the Line Header Program, we can
19167 create the psymtab of each included file. */
19168 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
19169 if (lh
->file_names
[file_index
].included_p
== 1)
19171 const char *include_name
=
19172 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
19173 if (include_name
!= NULL
)
19174 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
19179 /* Make sure a symtab is created for every file, even files
19180 which contain only variables (i.e. no code with associated
19182 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
19185 for (i
= 0; i
< lh
->file_names
.size (); i
++)
19187 file_entry
&fe
= lh
->file_names
[i
];
19189 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
19191 if (current_subfile
->symtab
== NULL
)
19193 current_subfile
->symtab
19194 = allocate_symtab (cust
, current_subfile
->name
);
19196 fe
.symtab
= current_subfile
->symtab
;
19201 /* Start a subfile for DWARF. FILENAME is the name of the file and
19202 DIRNAME the name of the source directory which contains FILENAME
19203 or NULL if not known.
19204 This routine tries to keep line numbers from identical absolute and
19205 relative file names in a common subfile.
19207 Using the `list' example from the GDB testsuite, which resides in
19208 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
19209 of /srcdir/list0.c yields the following debugging information for list0.c:
19211 DW_AT_name: /srcdir/list0.c
19212 DW_AT_comp_dir: /compdir
19213 files.files[0].name: list0.h
19214 files.files[0].dir: /srcdir
19215 files.files[1].name: list0.c
19216 files.files[1].dir: /srcdir
19218 The line number information for list0.c has to end up in a single
19219 subfile, so that `break /srcdir/list0.c:1' works as expected.
19220 start_subfile will ensure that this happens provided that we pass the
19221 concatenation of files.files[1].dir and files.files[1].name as the
19225 dwarf2_start_subfile (const char *filename
, const char *dirname
)
19229 /* In order not to lose the line information directory,
19230 we concatenate it to the filename when it makes sense.
19231 Note that the Dwarf3 standard says (speaking of filenames in line
19232 information): ``The directory index is ignored for file names
19233 that represent full path names''. Thus ignoring dirname in the
19234 `else' branch below isn't an issue. */
19236 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
19238 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
19242 start_subfile (filename
);
19248 /* Start a symtab for DWARF.
19249 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
19251 static struct compunit_symtab
*
19252 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
19253 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
19255 struct compunit_symtab
*cust
19256 = start_symtab (cu
->objfile
, name
, comp_dir
, low_pc
, cu
->language
);
19258 record_debugformat ("DWARF 2");
19259 record_producer (cu
->producer
);
19261 /* We assume that we're processing GCC output. */
19262 processing_gcc_compilation
= 2;
19264 cu
->processing_has_namespace_info
= 0;
19270 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
19271 struct dwarf2_cu
*cu
)
19273 struct objfile
*objfile
= cu
->objfile
;
19274 struct comp_unit_head
*cu_header
= &cu
->header
;
19276 /* NOTE drow/2003-01-30: There used to be a comment and some special
19277 code here to turn a symbol with DW_AT_external and a
19278 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
19279 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
19280 with some versions of binutils) where shared libraries could have
19281 relocations against symbols in their debug information - the
19282 minimal symbol would have the right address, but the debug info
19283 would not. It's no longer necessary, because we will explicitly
19284 apply relocations when we read in the debug information now. */
19286 /* A DW_AT_location attribute with no contents indicates that a
19287 variable has been optimized away. */
19288 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
19290 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
19294 /* Handle one degenerate form of location expression specially, to
19295 preserve GDB's previous behavior when section offsets are
19296 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
19297 then mark this symbol as LOC_STATIC. */
19299 if (attr_form_is_block (attr
)
19300 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
19301 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
19302 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
19303 && (DW_BLOCK (attr
)->size
19304 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
19306 unsigned int dummy
;
19308 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
19309 SYMBOL_VALUE_ADDRESS (sym
) =
19310 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
19312 SYMBOL_VALUE_ADDRESS (sym
) =
19313 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
19314 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
19315 fixup_symbol_section (sym
, objfile
);
19316 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
19317 SYMBOL_SECTION (sym
));
19321 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
19322 expression evaluator, and use LOC_COMPUTED only when necessary
19323 (i.e. when the value of a register or memory location is
19324 referenced, or a thread-local block, etc.). Then again, it might
19325 not be worthwhile. I'm assuming that it isn't unless performance
19326 or memory numbers show me otherwise. */
19328 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
19330 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
19331 cu
->has_loclist
= 1;
19334 /* Given a pointer to a DWARF information entry, figure out if we need
19335 to make a symbol table entry for it, and if so, create a new entry
19336 and return a pointer to it.
19337 If TYPE is NULL, determine symbol type from the die, otherwise
19338 used the passed type.
19339 If SPACE is not NULL, use it to hold the new symbol. If it is
19340 NULL, allocate a new symbol on the objfile's obstack. */
19342 static struct symbol
*
19343 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
19344 struct symbol
*space
)
19346 struct objfile
*objfile
= cu
->objfile
;
19347 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19348 struct symbol
*sym
= NULL
;
19350 struct attribute
*attr
= NULL
;
19351 struct attribute
*attr2
= NULL
;
19352 CORE_ADDR baseaddr
;
19353 struct pending
**list_to_add
= NULL
;
19355 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
19357 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19359 name
= dwarf2_name (die
, cu
);
19362 const char *linkagename
;
19363 int suppress_add
= 0;
19368 sym
= allocate_symbol (objfile
);
19369 OBJSTAT (objfile
, n_syms
++);
19371 /* Cache this symbol's name and the name's demangled form (if any). */
19372 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
19373 linkagename
= dwarf2_physname (name
, die
, cu
);
19374 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
19376 /* Fortran does not have mangling standard and the mangling does differ
19377 between gfortran, iFort etc. */
19378 if (cu
->language
== language_fortran
19379 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
19380 symbol_set_demangled_name (&(sym
->ginfo
),
19381 dwarf2_full_name (name
, die
, cu
),
19384 /* Default assumptions.
19385 Use the passed type or decode it from the die. */
19386 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19387 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
19389 SYMBOL_TYPE (sym
) = type
;
19391 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
19392 attr
= dwarf2_attr (die
,
19393 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
19397 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
19400 attr
= dwarf2_attr (die
,
19401 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
19405 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
19406 struct file_entry
*fe
;
19408 if (cu
->line_header
!= NULL
)
19409 fe
= cu
->line_header
->file_name_at (file_index
);
19414 complaint (&symfile_complaints
,
19415 _("file index out of range"));
19417 symbol_set_symtab (sym
, fe
->symtab
);
19423 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
19428 addr
= attr_value_as_address (attr
);
19429 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
19430 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
19432 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
19433 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
19434 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
19435 add_symbol_to_list (sym
, cu
->list_in_scope
);
19437 case DW_TAG_subprogram
:
19438 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
19440 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
19441 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19442 if ((attr2
&& (DW_UNSND (attr2
) != 0))
19443 || cu
->language
== language_ada
)
19445 /* Subprograms marked external are stored as a global symbol.
19446 Ada subprograms, whether marked external or not, are always
19447 stored as a global symbol, because we want to be able to
19448 access them globally. For instance, we want to be able
19449 to break on a nested subprogram without having to
19450 specify the context. */
19451 list_to_add
= &global_symbols
;
19455 list_to_add
= cu
->list_in_scope
;
19458 case DW_TAG_inlined_subroutine
:
19459 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
19461 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
19462 SYMBOL_INLINED (sym
) = 1;
19463 list_to_add
= cu
->list_in_scope
;
19465 case DW_TAG_template_value_param
:
19467 /* Fall through. */
19468 case DW_TAG_constant
:
19469 case DW_TAG_variable
:
19470 case DW_TAG_member
:
19471 /* Compilation with minimal debug info may result in
19472 variables with missing type entries. Change the
19473 misleading `void' type to something sensible. */
19474 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
19475 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
19477 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19478 /* In the case of DW_TAG_member, we should only be called for
19479 static const members. */
19480 if (die
->tag
== DW_TAG_member
)
19482 /* dwarf2_add_field uses die_is_declaration,
19483 so we do the same. */
19484 gdb_assert (die_is_declaration (die
, cu
));
19489 dwarf2_const_value (attr
, sym
, cu
);
19490 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19493 if (attr2
&& (DW_UNSND (attr2
) != 0))
19494 list_to_add
= &global_symbols
;
19496 list_to_add
= cu
->list_in_scope
;
19500 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
19503 var_decode_location (attr
, sym
, cu
);
19504 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19506 /* Fortran explicitly imports any global symbols to the local
19507 scope by DW_TAG_common_block. */
19508 if (cu
->language
== language_fortran
&& die
->parent
19509 && die
->parent
->tag
== DW_TAG_common_block
)
19512 if (SYMBOL_CLASS (sym
) == LOC_STATIC
19513 && SYMBOL_VALUE_ADDRESS (sym
) == 0
19514 && !dwarf2_per_objfile
->has_section_at_zero
)
19516 /* When a static variable is eliminated by the linker,
19517 the corresponding debug information is not stripped
19518 out, but the variable address is set to null;
19519 do not add such variables into symbol table. */
19521 else if (attr2
&& (DW_UNSND (attr2
) != 0))
19523 /* Workaround gfortran PR debug/40040 - it uses
19524 DW_AT_location for variables in -fPIC libraries which may
19525 get overriden by other libraries/executable and get
19526 a different address. Resolve it by the minimal symbol
19527 which may come from inferior's executable using copy
19528 relocation. Make this workaround only for gfortran as for
19529 other compilers GDB cannot guess the minimal symbol
19530 Fortran mangling kind. */
19531 if (cu
->language
== language_fortran
&& die
->parent
19532 && die
->parent
->tag
== DW_TAG_module
19534 && startswith (cu
->producer
, "GNU Fortran"))
19535 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
19537 /* A variable with DW_AT_external is never static,
19538 but it may be block-scoped. */
19539 list_to_add
= (cu
->list_in_scope
== &file_symbols
19540 ? &global_symbols
: cu
->list_in_scope
);
19543 list_to_add
= cu
->list_in_scope
;
19547 /* We do not know the address of this symbol.
19548 If it is an external symbol and we have type information
19549 for it, enter the symbol as a LOC_UNRESOLVED symbol.
19550 The address of the variable will then be determined from
19551 the minimal symbol table whenever the variable is
19553 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19555 /* Fortran explicitly imports any global symbols to the local
19556 scope by DW_TAG_common_block. */
19557 if (cu
->language
== language_fortran
&& die
->parent
19558 && die
->parent
->tag
== DW_TAG_common_block
)
19560 /* SYMBOL_CLASS doesn't matter here because
19561 read_common_block is going to reset it. */
19563 list_to_add
= cu
->list_in_scope
;
19565 else if (attr2
&& (DW_UNSND (attr2
) != 0)
19566 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
19568 /* A variable with DW_AT_external is never static, but it
19569 may be block-scoped. */
19570 list_to_add
= (cu
->list_in_scope
== &file_symbols
19571 ? &global_symbols
: cu
->list_in_scope
);
19573 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
19575 else if (!die_is_declaration (die
, cu
))
19577 /* Use the default LOC_OPTIMIZED_OUT class. */
19578 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
19580 list_to_add
= cu
->list_in_scope
;
19584 case DW_TAG_formal_parameter
:
19585 /* If we are inside a function, mark this as an argument. If
19586 not, we might be looking at an argument to an inlined function
19587 when we do not have enough information to show inlined frames;
19588 pretend it's a local variable in that case so that the user can
19590 if (context_stack_depth
> 0
19591 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
19592 SYMBOL_IS_ARGUMENT (sym
) = 1;
19593 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
19596 var_decode_location (attr
, sym
, cu
);
19598 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19601 dwarf2_const_value (attr
, sym
, cu
);
19604 list_to_add
= cu
->list_in_scope
;
19606 case DW_TAG_unspecified_parameters
:
19607 /* From varargs functions; gdb doesn't seem to have any
19608 interest in this information, so just ignore it for now.
19611 case DW_TAG_template_type_param
:
19613 /* Fall through. */
19614 case DW_TAG_class_type
:
19615 case DW_TAG_interface_type
:
19616 case DW_TAG_structure_type
:
19617 case DW_TAG_union_type
:
19618 case DW_TAG_set_type
:
19619 case DW_TAG_enumeration_type
:
19620 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19621 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
19624 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
19625 really ever be static objects: otherwise, if you try
19626 to, say, break of a class's method and you're in a file
19627 which doesn't mention that class, it won't work unless
19628 the check for all static symbols in lookup_symbol_aux
19629 saves you. See the OtherFileClass tests in
19630 gdb.c++/namespace.exp. */
19634 list_to_add
= (cu
->list_in_scope
== &file_symbols
19635 && cu
->language
== language_cplus
19636 ? &global_symbols
: cu
->list_in_scope
);
19638 /* The semantics of C++ state that "struct foo {
19639 ... }" also defines a typedef for "foo". */
19640 if (cu
->language
== language_cplus
19641 || cu
->language
== language_ada
19642 || cu
->language
== language_d
19643 || cu
->language
== language_rust
)
19645 /* The symbol's name is already allocated along
19646 with this objfile, so we don't need to
19647 duplicate it for the type. */
19648 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
19649 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
19654 case DW_TAG_typedef
:
19655 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19656 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19657 list_to_add
= cu
->list_in_scope
;
19659 case DW_TAG_base_type
:
19660 case DW_TAG_subrange_type
:
19661 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19662 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19663 list_to_add
= cu
->list_in_scope
;
19665 case DW_TAG_enumerator
:
19666 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19669 dwarf2_const_value (attr
, sym
, cu
);
19672 /* NOTE: carlton/2003-11-10: See comment above in the
19673 DW_TAG_class_type, etc. block. */
19675 list_to_add
= (cu
->list_in_scope
== &file_symbols
19676 && cu
->language
== language_cplus
19677 ? &global_symbols
: cu
->list_in_scope
);
19680 case DW_TAG_imported_declaration
:
19681 case DW_TAG_namespace
:
19682 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19683 list_to_add
= &global_symbols
;
19685 case DW_TAG_module
:
19686 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19687 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
19688 list_to_add
= &global_symbols
;
19690 case DW_TAG_common_block
:
19691 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
19692 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
19693 add_symbol_to_list (sym
, cu
->list_in_scope
);
19696 /* Not a tag we recognize. Hopefully we aren't processing
19697 trash data, but since we must specifically ignore things
19698 we don't recognize, there is nothing else we should do at
19700 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
19701 dwarf_tag_name (die
->tag
));
19707 sym
->hash_next
= objfile
->template_symbols
;
19708 objfile
->template_symbols
= sym
;
19709 list_to_add
= NULL
;
19712 if (list_to_add
!= NULL
)
19713 add_symbol_to_list (sym
, list_to_add
);
19715 /* For the benefit of old versions of GCC, check for anonymous
19716 namespaces based on the demangled name. */
19717 if (!cu
->processing_has_namespace_info
19718 && cu
->language
== language_cplus
)
19719 cp_scan_for_anonymous_namespaces (sym
, objfile
);
19724 /* A wrapper for new_symbol_full that always allocates a new symbol. */
19726 static struct symbol
*
19727 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
19729 return new_symbol_full (die
, type
, cu
, NULL
);
19732 /* Given an attr with a DW_FORM_dataN value in host byte order,
19733 zero-extend it as appropriate for the symbol's type. The DWARF
19734 standard (v4) is not entirely clear about the meaning of using
19735 DW_FORM_dataN for a constant with a signed type, where the type is
19736 wider than the data. The conclusion of a discussion on the DWARF
19737 list was that this is unspecified. We choose to always zero-extend
19738 because that is the interpretation long in use by GCC. */
19741 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
19742 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
19744 struct objfile
*objfile
= cu
->objfile
;
19745 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
19746 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
19747 LONGEST l
= DW_UNSND (attr
);
19749 if (bits
< sizeof (*value
) * 8)
19751 l
&= ((LONGEST
) 1 << bits
) - 1;
19754 else if (bits
== sizeof (*value
) * 8)
19758 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
19759 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
19766 /* Read a constant value from an attribute. Either set *VALUE, or if
19767 the value does not fit in *VALUE, set *BYTES - either already
19768 allocated on the objfile obstack, or newly allocated on OBSTACK,
19769 or, set *BATON, if we translated the constant to a location
19773 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
19774 const char *name
, struct obstack
*obstack
,
19775 struct dwarf2_cu
*cu
,
19776 LONGEST
*value
, const gdb_byte
**bytes
,
19777 struct dwarf2_locexpr_baton
**baton
)
19779 struct objfile
*objfile
= cu
->objfile
;
19780 struct comp_unit_head
*cu_header
= &cu
->header
;
19781 struct dwarf_block
*blk
;
19782 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
19783 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
19789 switch (attr
->form
)
19792 case DW_FORM_GNU_addr_index
:
19796 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
19797 dwarf2_const_value_length_mismatch_complaint (name
,
19798 cu_header
->addr_size
,
19799 TYPE_LENGTH (type
));
19800 /* Symbols of this form are reasonably rare, so we just
19801 piggyback on the existing location code rather than writing
19802 a new implementation of symbol_computed_ops. */
19803 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
19804 (*baton
)->per_cu
= cu
->per_cu
;
19805 gdb_assert ((*baton
)->per_cu
);
19807 (*baton
)->size
= 2 + cu_header
->addr_size
;
19808 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
19809 (*baton
)->data
= data
;
19811 data
[0] = DW_OP_addr
;
19812 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
19813 byte_order
, DW_ADDR (attr
));
19814 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
19817 case DW_FORM_string
:
19819 case DW_FORM_GNU_str_index
:
19820 case DW_FORM_GNU_strp_alt
:
19821 /* DW_STRING is already allocated on the objfile obstack, point
19823 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
19825 case DW_FORM_block1
:
19826 case DW_FORM_block2
:
19827 case DW_FORM_block4
:
19828 case DW_FORM_block
:
19829 case DW_FORM_exprloc
:
19830 case DW_FORM_data16
:
19831 blk
= DW_BLOCK (attr
);
19832 if (TYPE_LENGTH (type
) != blk
->size
)
19833 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
19834 TYPE_LENGTH (type
));
19835 *bytes
= blk
->data
;
19838 /* The DW_AT_const_value attributes are supposed to carry the
19839 symbol's value "represented as it would be on the target
19840 architecture." By the time we get here, it's already been
19841 converted to host endianness, so we just need to sign- or
19842 zero-extend it as appropriate. */
19843 case DW_FORM_data1
:
19844 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
19846 case DW_FORM_data2
:
19847 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
19849 case DW_FORM_data4
:
19850 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
19852 case DW_FORM_data8
:
19853 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
19856 case DW_FORM_sdata
:
19857 case DW_FORM_implicit_const
:
19858 *value
= DW_SND (attr
);
19861 case DW_FORM_udata
:
19862 *value
= DW_UNSND (attr
);
19866 complaint (&symfile_complaints
,
19867 _("unsupported const value attribute form: '%s'"),
19868 dwarf_form_name (attr
->form
));
19875 /* Copy constant value from an attribute to a symbol. */
19878 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
19879 struct dwarf2_cu
*cu
)
19881 struct objfile
*objfile
= cu
->objfile
;
19883 const gdb_byte
*bytes
;
19884 struct dwarf2_locexpr_baton
*baton
;
19886 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
19887 SYMBOL_PRINT_NAME (sym
),
19888 &objfile
->objfile_obstack
, cu
,
19889 &value
, &bytes
, &baton
);
19893 SYMBOL_LOCATION_BATON (sym
) = baton
;
19894 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
19896 else if (bytes
!= NULL
)
19898 SYMBOL_VALUE_BYTES (sym
) = bytes
;
19899 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
19903 SYMBOL_VALUE (sym
) = value
;
19904 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
19908 /* Return the type of the die in question using its DW_AT_type attribute. */
19910 static struct type
*
19911 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19913 struct attribute
*type_attr
;
19915 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
19918 /* A missing DW_AT_type represents a void type. */
19919 return objfile_type (cu
->objfile
)->builtin_void
;
19922 return lookup_die_type (die
, type_attr
, cu
);
19925 /* True iff CU's producer generates GNAT Ada auxiliary information
19926 that allows to find parallel types through that information instead
19927 of having to do expensive parallel lookups by type name. */
19930 need_gnat_info (struct dwarf2_cu
*cu
)
19932 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
19933 of GNAT produces this auxiliary information, without any indication
19934 that it is produced. Part of enhancing the FSF version of GNAT
19935 to produce that information will be to put in place an indicator
19936 that we can use in order to determine whether the descriptive type
19937 info is available or not. One suggestion that has been made is
19938 to use a new attribute, attached to the CU die. For now, assume
19939 that the descriptive type info is not available. */
19943 /* Return the auxiliary type of the die in question using its
19944 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
19945 attribute is not present. */
19947 static struct type
*
19948 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19950 struct attribute
*type_attr
;
19952 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
19956 return lookup_die_type (die
, type_attr
, cu
);
19959 /* If DIE has a descriptive_type attribute, then set the TYPE's
19960 descriptive type accordingly. */
19963 set_descriptive_type (struct type
*type
, struct die_info
*die
,
19964 struct dwarf2_cu
*cu
)
19966 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
19968 if (descriptive_type
)
19970 ALLOCATE_GNAT_AUX_TYPE (type
);
19971 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
19975 /* Return the containing type of the die in question using its
19976 DW_AT_containing_type attribute. */
19978 static struct type
*
19979 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19981 struct attribute
*type_attr
;
19983 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
19985 error (_("Dwarf Error: Problem turning containing type into gdb type "
19986 "[in module %s]"), objfile_name (cu
->objfile
));
19988 return lookup_die_type (die
, type_attr
, cu
);
19991 /* Return an error marker type to use for the ill formed type in DIE/CU. */
19993 static struct type
*
19994 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
19996 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19997 char *message
, *saved
;
19999 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
20000 objfile_name (objfile
),
20001 to_underlying (cu
->header
.sect_off
),
20002 to_underlying (die
->sect_off
));
20003 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
20004 message
, strlen (message
));
20007 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
20010 /* Look up the type of DIE in CU using its type attribute ATTR.
20011 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
20012 DW_AT_containing_type.
20013 If there is no type substitute an error marker. */
20015 static struct type
*
20016 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
20017 struct dwarf2_cu
*cu
)
20019 struct objfile
*objfile
= cu
->objfile
;
20020 struct type
*this_type
;
20022 gdb_assert (attr
->name
== DW_AT_type
20023 || attr
->name
== DW_AT_GNAT_descriptive_type
20024 || attr
->name
== DW_AT_containing_type
);
20026 /* First see if we have it cached. */
20028 if (attr
->form
== DW_FORM_GNU_ref_alt
)
20030 struct dwarf2_per_cu_data
*per_cu
;
20031 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
20033 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, cu
->objfile
);
20034 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
20036 else if (attr_form_is_ref (attr
))
20038 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
20040 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
20042 else if (attr
->form
== DW_FORM_ref_sig8
)
20044 ULONGEST signature
= DW_SIGNATURE (attr
);
20046 return get_signatured_type (die
, signature
, cu
);
20050 complaint (&symfile_complaints
,
20051 _("Dwarf Error: Bad type attribute %s in DIE"
20052 " at 0x%x [in module %s]"),
20053 dwarf_attr_name (attr
->name
), to_underlying (die
->sect_off
),
20054 objfile_name (objfile
));
20055 return build_error_marker_type (cu
, die
);
20058 /* If not cached we need to read it in. */
20060 if (this_type
== NULL
)
20062 struct die_info
*type_die
= NULL
;
20063 struct dwarf2_cu
*type_cu
= cu
;
20065 if (attr_form_is_ref (attr
))
20066 type_die
= follow_die_ref (die
, attr
, &type_cu
);
20067 if (type_die
== NULL
)
20068 return build_error_marker_type (cu
, die
);
20069 /* If we find the type now, it's probably because the type came
20070 from an inter-CU reference and the type's CU got expanded before
20072 this_type
= read_type_die (type_die
, type_cu
);
20075 /* If we still don't have a type use an error marker. */
20077 if (this_type
== NULL
)
20078 return build_error_marker_type (cu
, die
);
20083 /* Return the type in DIE, CU.
20084 Returns NULL for invalid types.
20086 This first does a lookup in die_type_hash,
20087 and only reads the die in if necessary.
20089 NOTE: This can be called when reading in partial or full symbols. */
20091 static struct type
*
20092 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
20094 struct type
*this_type
;
20096 this_type
= get_die_type (die
, cu
);
20100 return read_type_die_1 (die
, cu
);
20103 /* Read the type in DIE, CU.
20104 Returns NULL for invalid types. */
20106 static struct type
*
20107 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
20109 struct type
*this_type
= NULL
;
20113 case DW_TAG_class_type
:
20114 case DW_TAG_interface_type
:
20115 case DW_TAG_structure_type
:
20116 case DW_TAG_union_type
:
20117 this_type
= read_structure_type (die
, cu
);
20119 case DW_TAG_enumeration_type
:
20120 this_type
= read_enumeration_type (die
, cu
);
20122 case DW_TAG_subprogram
:
20123 case DW_TAG_subroutine_type
:
20124 case DW_TAG_inlined_subroutine
:
20125 this_type
= read_subroutine_type (die
, cu
);
20127 case DW_TAG_array_type
:
20128 this_type
= read_array_type (die
, cu
);
20130 case DW_TAG_set_type
:
20131 this_type
= read_set_type (die
, cu
);
20133 case DW_TAG_pointer_type
:
20134 this_type
= read_tag_pointer_type (die
, cu
);
20136 case DW_TAG_ptr_to_member_type
:
20137 this_type
= read_tag_ptr_to_member_type (die
, cu
);
20139 case DW_TAG_reference_type
:
20140 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
20142 case DW_TAG_rvalue_reference_type
:
20143 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
20145 case DW_TAG_const_type
:
20146 this_type
= read_tag_const_type (die
, cu
);
20148 case DW_TAG_volatile_type
:
20149 this_type
= read_tag_volatile_type (die
, cu
);
20151 case DW_TAG_restrict_type
:
20152 this_type
= read_tag_restrict_type (die
, cu
);
20154 case DW_TAG_string_type
:
20155 this_type
= read_tag_string_type (die
, cu
);
20157 case DW_TAG_typedef
:
20158 this_type
= read_typedef (die
, cu
);
20160 case DW_TAG_subrange_type
:
20161 this_type
= read_subrange_type (die
, cu
);
20163 case DW_TAG_base_type
:
20164 this_type
= read_base_type (die
, cu
);
20166 case DW_TAG_unspecified_type
:
20167 this_type
= read_unspecified_type (die
, cu
);
20169 case DW_TAG_namespace
:
20170 this_type
= read_namespace_type (die
, cu
);
20172 case DW_TAG_module
:
20173 this_type
= read_module_type (die
, cu
);
20175 case DW_TAG_atomic_type
:
20176 this_type
= read_tag_atomic_type (die
, cu
);
20179 complaint (&symfile_complaints
,
20180 _("unexpected tag in read_type_die: '%s'"),
20181 dwarf_tag_name (die
->tag
));
20188 /* See if we can figure out if the class lives in a namespace. We do
20189 this by looking for a member function; its demangled name will
20190 contain namespace info, if there is any.
20191 Return the computed name or NULL.
20192 Space for the result is allocated on the objfile's obstack.
20193 This is the full-die version of guess_partial_die_structure_name.
20194 In this case we know DIE has no useful parent. */
20197 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20199 struct die_info
*spec_die
;
20200 struct dwarf2_cu
*spec_cu
;
20201 struct die_info
*child
;
20204 spec_die
= die_specification (die
, &spec_cu
);
20205 if (spec_die
!= NULL
)
20211 for (child
= die
->child
;
20213 child
= child
->sibling
)
20215 if (child
->tag
== DW_TAG_subprogram
)
20217 const char *linkage_name
= dw2_linkage_name (child
, cu
);
20219 if (linkage_name
!= NULL
)
20222 = language_class_name_from_physname (cu
->language_defn
,
20226 if (actual_name
!= NULL
)
20228 const char *die_name
= dwarf2_name (die
, cu
);
20230 if (die_name
!= NULL
20231 && strcmp (die_name
, actual_name
) != 0)
20233 /* Strip off the class name from the full name.
20234 We want the prefix. */
20235 int die_name_len
= strlen (die_name
);
20236 int actual_name_len
= strlen (actual_name
);
20238 /* Test for '::' as a sanity check. */
20239 if (actual_name_len
> die_name_len
+ 2
20240 && actual_name
[actual_name_len
20241 - die_name_len
- 1] == ':')
20242 name
= (char *) obstack_copy0 (
20243 &cu
->objfile
->per_bfd
->storage_obstack
,
20244 actual_name
, actual_name_len
- die_name_len
- 2);
20247 xfree (actual_name
);
20256 /* GCC might emit a nameless typedef that has a linkage name. Determine the
20257 prefix part in such case. See
20258 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20260 static const char *
20261 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
20263 struct attribute
*attr
;
20266 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
20267 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
20270 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
20273 attr
= dw2_linkage_name_attr (die
, cu
);
20274 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
20277 /* dwarf2_name had to be already called. */
20278 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
20280 /* Strip the base name, keep any leading namespaces/classes. */
20281 base
= strrchr (DW_STRING (attr
), ':');
20282 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
20285 return (char *) obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
20287 &base
[-1] - DW_STRING (attr
));
20290 /* Return the name of the namespace/class that DIE is defined within,
20291 or "" if we can't tell. The caller should not xfree the result.
20293 For example, if we're within the method foo() in the following
20303 then determine_prefix on foo's die will return "N::C". */
20305 static const char *
20306 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
20308 struct die_info
*parent
, *spec_die
;
20309 struct dwarf2_cu
*spec_cu
;
20310 struct type
*parent_type
;
20311 const char *retval
;
20313 if (cu
->language
!= language_cplus
20314 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
20315 && cu
->language
!= language_rust
)
20318 retval
= anonymous_struct_prefix (die
, cu
);
20322 /* We have to be careful in the presence of DW_AT_specification.
20323 For example, with GCC 3.4, given the code
20327 // Definition of N::foo.
20331 then we'll have a tree of DIEs like this:
20333 1: DW_TAG_compile_unit
20334 2: DW_TAG_namespace // N
20335 3: DW_TAG_subprogram // declaration of N::foo
20336 4: DW_TAG_subprogram // definition of N::foo
20337 DW_AT_specification // refers to die #3
20339 Thus, when processing die #4, we have to pretend that we're in
20340 the context of its DW_AT_specification, namely the contex of die
20343 spec_die
= die_specification (die
, &spec_cu
);
20344 if (spec_die
== NULL
)
20345 parent
= die
->parent
;
20348 parent
= spec_die
->parent
;
20352 if (parent
== NULL
)
20354 else if (parent
->building_fullname
)
20357 const char *parent_name
;
20359 /* It has been seen on RealView 2.2 built binaries,
20360 DW_TAG_template_type_param types actually _defined_ as
20361 children of the parent class:
20364 template class <class Enum> Class{};
20365 Class<enum E> class_e;
20367 1: DW_TAG_class_type (Class)
20368 2: DW_TAG_enumeration_type (E)
20369 3: DW_TAG_enumerator (enum1:0)
20370 3: DW_TAG_enumerator (enum2:1)
20372 2: DW_TAG_template_type_param
20373 DW_AT_type DW_FORM_ref_udata (E)
20375 Besides being broken debug info, it can put GDB into an
20376 infinite loop. Consider:
20378 When we're building the full name for Class<E>, we'll start
20379 at Class, and go look over its template type parameters,
20380 finding E. We'll then try to build the full name of E, and
20381 reach here. We're now trying to build the full name of E,
20382 and look over the parent DIE for containing scope. In the
20383 broken case, if we followed the parent DIE of E, we'd again
20384 find Class, and once again go look at its template type
20385 arguments, etc., etc. Simply don't consider such parent die
20386 as source-level parent of this die (it can't be, the language
20387 doesn't allow it), and break the loop here. */
20388 name
= dwarf2_name (die
, cu
);
20389 parent_name
= dwarf2_name (parent
, cu
);
20390 complaint (&symfile_complaints
,
20391 _("template param type '%s' defined within parent '%s'"),
20392 name
? name
: "<unknown>",
20393 parent_name
? parent_name
: "<unknown>");
20397 switch (parent
->tag
)
20399 case DW_TAG_namespace
:
20400 parent_type
= read_type_die (parent
, cu
);
20401 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
20402 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
20403 Work around this problem here. */
20404 if (cu
->language
== language_cplus
20405 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
20407 /* We give a name to even anonymous namespaces. */
20408 return TYPE_TAG_NAME (parent_type
);
20409 case DW_TAG_class_type
:
20410 case DW_TAG_interface_type
:
20411 case DW_TAG_structure_type
:
20412 case DW_TAG_union_type
:
20413 case DW_TAG_module
:
20414 parent_type
= read_type_die (parent
, cu
);
20415 if (TYPE_TAG_NAME (parent_type
) != NULL
)
20416 return TYPE_TAG_NAME (parent_type
);
20418 /* An anonymous structure is only allowed non-static data
20419 members; no typedefs, no member functions, et cetera.
20420 So it does not need a prefix. */
20422 case DW_TAG_compile_unit
:
20423 case DW_TAG_partial_unit
:
20424 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
20425 if (cu
->language
== language_cplus
20426 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
20427 && die
->child
!= NULL
20428 && (die
->tag
== DW_TAG_class_type
20429 || die
->tag
== DW_TAG_structure_type
20430 || die
->tag
== DW_TAG_union_type
))
20432 char *name
= guess_full_die_structure_name (die
, cu
);
20437 case DW_TAG_enumeration_type
:
20438 parent_type
= read_type_die (parent
, cu
);
20439 if (TYPE_DECLARED_CLASS (parent_type
))
20441 if (TYPE_TAG_NAME (parent_type
) != NULL
)
20442 return TYPE_TAG_NAME (parent_type
);
20445 /* Fall through. */
20447 return determine_prefix (parent
, cu
);
20451 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
20452 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
20453 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
20454 an obconcat, otherwise allocate storage for the result. The CU argument is
20455 used to determine the language and hence, the appropriate separator. */
20457 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
20460 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
20461 int physname
, struct dwarf2_cu
*cu
)
20463 const char *lead
= "";
20466 if (suffix
== NULL
|| suffix
[0] == '\0'
20467 || prefix
== NULL
|| prefix
[0] == '\0')
20469 else if (cu
->language
== language_d
)
20471 /* For D, the 'main' function could be defined in any module, but it
20472 should never be prefixed. */
20473 if (strcmp (suffix
, "D main") == 0)
20481 else if (cu
->language
== language_fortran
&& physname
)
20483 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
20484 DW_AT_MIPS_linkage_name is preferred and used instead. */
20492 if (prefix
== NULL
)
20494 if (suffix
== NULL
)
20501 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
20503 strcpy (retval
, lead
);
20504 strcat (retval
, prefix
);
20505 strcat (retval
, sep
);
20506 strcat (retval
, suffix
);
20511 /* We have an obstack. */
20512 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
20516 /* Return sibling of die, NULL if no sibling. */
20518 static struct die_info
*
20519 sibling_die (struct die_info
*die
)
20521 return die
->sibling
;
20524 /* Get name of a die, return NULL if not found. */
20526 static const char *
20527 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
20528 struct obstack
*obstack
)
20530 if (name
&& cu
->language
== language_cplus
)
20532 std::string canon_name
= cp_canonicalize_string (name
);
20534 if (!canon_name
.empty ())
20536 if (canon_name
!= name
)
20537 name
= (const char *) obstack_copy0 (obstack
,
20538 canon_name
.c_str (),
20539 canon_name
.length ());
20546 /* Get name of a die, return NULL if not found.
20547 Anonymous namespaces are converted to their magic string. */
20549 static const char *
20550 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20552 struct attribute
*attr
;
20554 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
20555 if ((!attr
|| !DW_STRING (attr
))
20556 && die
->tag
!= DW_TAG_namespace
20557 && die
->tag
!= DW_TAG_class_type
20558 && die
->tag
!= DW_TAG_interface_type
20559 && die
->tag
!= DW_TAG_structure_type
20560 && die
->tag
!= DW_TAG_union_type
)
20565 case DW_TAG_compile_unit
:
20566 case DW_TAG_partial_unit
:
20567 /* Compilation units have a DW_AT_name that is a filename, not
20568 a source language identifier. */
20569 case DW_TAG_enumeration_type
:
20570 case DW_TAG_enumerator
:
20571 /* These tags always have simple identifiers already; no need
20572 to canonicalize them. */
20573 return DW_STRING (attr
);
20575 case DW_TAG_namespace
:
20576 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
20577 return DW_STRING (attr
);
20578 return CP_ANONYMOUS_NAMESPACE_STR
;
20580 case DW_TAG_class_type
:
20581 case DW_TAG_interface_type
:
20582 case DW_TAG_structure_type
:
20583 case DW_TAG_union_type
:
20584 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
20585 structures or unions. These were of the form "._%d" in GCC 4.1,
20586 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
20587 and GCC 4.4. We work around this problem by ignoring these. */
20588 if (attr
&& DW_STRING (attr
)
20589 && (startswith (DW_STRING (attr
), "._")
20590 || startswith (DW_STRING (attr
), "<anonymous")))
20593 /* GCC might emit a nameless typedef that has a linkage name. See
20594 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20595 if (!attr
|| DW_STRING (attr
) == NULL
)
20597 char *demangled
= NULL
;
20599 attr
= dw2_linkage_name_attr (die
, cu
);
20600 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
20603 /* Avoid demangling DW_STRING (attr) the second time on a second
20604 call for the same DIE. */
20605 if (!DW_STRING_IS_CANONICAL (attr
))
20606 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
20612 /* FIXME: we already did this for the partial symbol... */
20615 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
20616 demangled
, strlen (demangled
)));
20617 DW_STRING_IS_CANONICAL (attr
) = 1;
20620 /* Strip any leading namespaces/classes, keep only the base name.
20621 DW_AT_name for named DIEs does not contain the prefixes. */
20622 base
= strrchr (DW_STRING (attr
), ':');
20623 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
20626 return DW_STRING (attr
);
20635 if (!DW_STRING_IS_CANONICAL (attr
))
20638 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
20639 &cu
->objfile
->per_bfd
->storage_obstack
);
20640 DW_STRING_IS_CANONICAL (attr
) = 1;
20642 return DW_STRING (attr
);
20645 /* Return the die that this die in an extension of, or NULL if there
20646 is none. *EXT_CU is the CU containing DIE on input, and the CU
20647 containing the return value on output. */
20649 static struct die_info
*
20650 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
20652 struct attribute
*attr
;
20654 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
20658 return follow_die_ref (die
, attr
, ext_cu
);
20661 /* Convert a DIE tag into its string name. */
20663 static const char *
20664 dwarf_tag_name (unsigned tag
)
20666 const char *name
= get_DW_TAG_name (tag
);
20669 return "DW_TAG_<unknown>";
20674 /* Convert a DWARF attribute code into its string name. */
20676 static const char *
20677 dwarf_attr_name (unsigned attr
)
20681 #ifdef MIPS /* collides with DW_AT_HP_block_index */
20682 if (attr
== DW_AT_MIPS_fde
)
20683 return "DW_AT_MIPS_fde";
20685 if (attr
== DW_AT_HP_block_index
)
20686 return "DW_AT_HP_block_index";
20689 name
= get_DW_AT_name (attr
);
20692 return "DW_AT_<unknown>";
20697 /* Convert a DWARF value form code into its string name. */
20699 static const char *
20700 dwarf_form_name (unsigned form
)
20702 const char *name
= get_DW_FORM_name (form
);
20705 return "DW_FORM_<unknown>";
20710 static const char *
20711 dwarf_bool_name (unsigned mybool
)
20719 /* Convert a DWARF type code into its string name. */
20721 static const char *
20722 dwarf_type_encoding_name (unsigned enc
)
20724 const char *name
= get_DW_ATE_name (enc
);
20727 return "DW_ATE_<unknown>";
20733 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
20737 print_spaces (indent
, f
);
20738 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
20739 dwarf_tag_name (die
->tag
), die
->abbrev
,
20740 to_underlying (die
->sect_off
));
20742 if (die
->parent
!= NULL
)
20744 print_spaces (indent
, f
);
20745 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
20746 to_underlying (die
->parent
->sect_off
));
20749 print_spaces (indent
, f
);
20750 fprintf_unfiltered (f
, " has children: %s\n",
20751 dwarf_bool_name (die
->child
!= NULL
));
20753 print_spaces (indent
, f
);
20754 fprintf_unfiltered (f
, " attributes:\n");
20756 for (i
= 0; i
< die
->num_attrs
; ++i
)
20758 print_spaces (indent
, f
);
20759 fprintf_unfiltered (f
, " %s (%s) ",
20760 dwarf_attr_name (die
->attrs
[i
].name
),
20761 dwarf_form_name (die
->attrs
[i
].form
));
20763 switch (die
->attrs
[i
].form
)
20766 case DW_FORM_GNU_addr_index
:
20767 fprintf_unfiltered (f
, "address: ");
20768 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
20770 case DW_FORM_block2
:
20771 case DW_FORM_block4
:
20772 case DW_FORM_block
:
20773 case DW_FORM_block1
:
20774 fprintf_unfiltered (f
, "block: size %s",
20775 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
20777 case DW_FORM_exprloc
:
20778 fprintf_unfiltered (f
, "expression: size %s",
20779 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
20781 case DW_FORM_data16
:
20782 fprintf_unfiltered (f
, "constant of 16 bytes");
20784 case DW_FORM_ref_addr
:
20785 fprintf_unfiltered (f
, "ref address: ");
20786 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
20788 case DW_FORM_GNU_ref_alt
:
20789 fprintf_unfiltered (f
, "alt ref address: ");
20790 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
20796 case DW_FORM_ref_udata
:
20797 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
20798 (long) (DW_UNSND (&die
->attrs
[i
])));
20800 case DW_FORM_data1
:
20801 case DW_FORM_data2
:
20802 case DW_FORM_data4
:
20803 case DW_FORM_data8
:
20804 case DW_FORM_udata
:
20805 case DW_FORM_sdata
:
20806 fprintf_unfiltered (f
, "constant: %s",
20807 pulongest (DW_UNSND (&die
->attrs
[i
])));
20809 case DW_FORM_sec_offset
:
20810 fprintf_unfiltered (f
, "section offset: %s",
20811 pulongest (DW_UNSND (&die
->attrs
[i
])));
20813 case DW_FORM_ref_sig8
:
20814 fprintf_unfiltered (f
, "signature: %s",
20815 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
20817 case DW_FORM_string
:
20819 case DW_FORM_line_strp
:
20820 case DW_FORM_GNU_str_index
:
20821 case DW_FORM_GNU_strp_alt
:
20822 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
20823 DW_STRING (&die
->attrs
[i
])
20824 ? DW_STRING (&die
->attrs
[i
]) : "",
20825 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
20828 if (DW_UNSND (&die
->attrs
[i
]))
20829 fprintf_unfiltered (f
, "flag: TRUE");
20831 fprintf_unfiltered (f
, "flag: FALSE");
20833 case DW_FORM_flag_present
:
20834 fprintf_unfiltered (f
, "flag: TRUE");
20836 case DW_FORM_indirect
:
20837 /* The reader will have reduced the indirect form to
20838 the "base form" so this form should not occur. */
20839 fprintf_unfiltered (f
,
20840 "unexpected attribute form: DW_FORM_indirect");
20842 case DW_FORM_implicit_const
:
20843 fprintf_unfiltered (f
, "constant: %s",
20844 plongest (DW_SND (&die
->attrs
[i
])));
20847 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
20848 die
->attrs
[i
].form
);
20851 fprintf_unfiltered (f
, "\n");
20856 dump_die_for_error (struct die_info
*die
)
20858 dump_die_shallow (gdb_stderr
, 0, die
);
20862 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
20864 int indent
= level
* 4;
20866 gdb_assert (die
!= NULL
);
20868 if (level
>= max_level
)
20871 dump_die_shallow (f
, indent
, die
);
20873 if (die
->child
!= NULL
)
20875 print_spaces (indent
, f
);
20876 fprintf_unfiltered (f
, " Children:");
20877 if (level
+ 1 < max_level
)
20879 fprintf_unfiltered (f
, "\n");
20880 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
20884 fprintf_unfiltered (f
,
20885 " [not printed, max nesting level reached]\n");
20889 if (die
->sibling
!= NULL
&& level
> 0)
20891 dump_die_1 (f
, level
, max_level
, die
->sibling
);
20895 /* This is called from the pdie macro in gdbinit.in.
20896 It's not static so gcc will keep a copy callable from gdb. */
20899 dump_die (struct die_info
*die
, int max_level
)
20901 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
20905 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
20909 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
20910 to_underlying (die
->sect_off
),
20916 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
20920 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
20922 if (attr_form_is_ref (attr
))
20923 return (sect_offset
) DW_UNSND (attr
);
20925 complaint (&symfile_complaints
,
20926 _("unsupported die ref attribute form: '%s'"),
20927 dwarf_form_name (attr
->form
));
20931 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
20932 * the value held by the attribute is not constant. */
20935 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
20937 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
20938 return DW_SND (attr
);
20939 else if (attr
->form
== DW_FORM_udata
20940 || attr
->form
== DW_FORM_data1
20941 || attr
->form
== DW_FORM_data2
20942 || attr
->form
== DW_FORM_data4
20943 || attr
->form
== DW_FORM_data8
)
20944 return DW_UNSND (attr
);
20947 /* For DW_FORM_data16 see attr_form_is_constant. */
20948 complaint (&symfile_complaints
,
20949 _("Attribute value is not a constant (%s)"),
20950 dwarf_form_name (attr
->form
));
20951 return default_value
;
20955 /* Follow reference or signature attribute ATTR of SRC_DIE.
20956 On entry *REF_CU is the CU of SRC_DIE.
20957 On exit *REF_CU is the CU of the result. */
20959 static struct die_info
*
20960 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20961 struct dwarf2_cu
**ref_cu
)
20963 struct die_info
*die
;
20965 if (attr_form_is_ref (attr
))
20966 die
= follow_die_ref (src_die
, attr
, ref_cu
);
20967 else if (attr
->form
== DW_FORM_ref_sig8
)
20968 die
= follow_die_sig (src_die
, attr
, ref_cu
);
20971 dump_die_for_error (src_die
);
20972 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
20973 objfile_name ((*ref_cu
)->objfile
));
20979 /* Follow reference OFFSET.
20980 On entry *REF_CU is the CU of the source die referencing OFFSET.
20981 On exit *REF_CU is the CU of the result.
20982 Returns NULL if OFFSET is invalid. */
20984 static struct die_info
*
20985 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
20986 struct dwarf2_cu
**ref_cu
)
20988 struct die_info temp_die
;
20989 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
20991 gdb_assert (cu
->per_cu
!= NULL
);
20995 if (cu
->per_cu
->is_debug_types
)
20997 /* .debug_types CUs cannot reference anything outside their CU.
20998 If they need to, they have to reference a signatured type via
20999 DW_FORM_ref_sig8. */
21000 if (!offset_in_cu_p (&cu
->header
, sect_off
))
21003 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
21004 || !offset_in_cu_p (&cu
->header
, sect_off
))
21006 struct dwarf2_per_cu_data
*per_cu
;
21008 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
21011 /* If necessary, add it to the queue and load its DIEs. */
21012 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
21013 load_full_comp_unit (per_cu
, cu
->language
);
21015 target_cu
= per_cu
->cu
;
21017 else if (cu
->dies
== NULL
)
21019 /* We're loading full DIEs during partial symbol reading. */
21020 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
21021 load_full_comp_unit (cu
->per_cu
, language_minimal
);
21024 *ref_cu
= target_cu
;
21025 temp_die
.sect_off
= sect_off
;
21026 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
21028 to_underlying (sect_off
));
21031 /* Follow reference attribute ATTR of SRC_DIE.
21032 On entry *REF_CU is the CU of SRC_DIE.
21033 On exit *REF_CU is the CU of the result. */
21035 static struct die_info
*
21036 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
21037 struct dwarf2_cu
**ref_cu
)
21039 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21040 struct dwarf2_cu
*cu
= *ref_cu
;
21041 struct die_info
*die
;
21043 die
= follow_die_offset (sect_off
,
21044 (attr
->form
== DW_FORM_GNU_ref_alt
21045 || cu
->per_cu
->is_dwz
),
21048 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
21049 "at 0x%x [in module %s]"),
21050 to_underlying (sect_off
), to_underlying (src_die
->sect_off
),
21051 objfile_name (cu
->objfile
));
21056 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
21057 Returned value is intended for DW_OP_call*. Returned
21058 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
21060 struct dwarf2_locexpr_baton
21061 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
21062 struct dwarf2_per_cu_data
*per_cu
,
21063 CORE_ADDR (*get_frame_pc
) (void *baton
),
21066 struct dwarf2_cu
*cu
;
21067 struct die_info
*die
;
21068 struct attribute
*attr
;
21069 struct dwarf2_locexpr_baton retval
;
21071 dw2_setup (per_cu
->objfile
);
21073 if (per_cu
->cu
== NULL
)
21078 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21079 Instead just throw an error, not much else we can do. */
21080 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
21081 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
21084 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21086 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
21087 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
21089 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21092 /* DWARF: "If there is no such attribute, then there is no effect.".
21093 DATA is ignored if SIZE is 0. */
21095 retval
.data
= NULL
;
21098 else if (attr_form_is_section_offset (attr
))
21100 struct dwarf2_loclist_baton loclist_baton
;
21101 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21104 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
21106 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
21108 retval
.size
= size
;
21112 if (!attr_form_is_block (attr
))
21113 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
21114 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
21115 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
21117 retval
.data
= DW_BLOCK (attr
)->data
;
21118 retval
.size
= DW_BLOCK (attr
)->size
;
21120 retval
.per_cu
= cu
->per_cu
;
21122 age_cached_comp_units ();
21127 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
21130 struct dwarf2_locexpr_baton
21131 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
21132 struct dwarf2_per_cu_data
*per_cu
,
21133 CORE_ADDR (*get_frame_pc
) (void *baton
),
21136 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
21138 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
21141 /* Write a constant of a given type as target-ordered bytes into
21144 static const gdb_byte
*
21145 write_constant_as_bytes (struct obstack
*obstack
,
21146 enum bfd_endian byte_order
,
21153 *len
= TYPE_LENGTH (type
);
21154 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21155 store_unsigned_integer (result
, *len
, byte_order
, value
);
21160 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
21161 pointer to the constant bytes and set LEN to the length of the
21162 data. If memory is needed, allocate it on OBSTACK. If the DIE
21163 does not have a DW_AT_const_value, return NULL. */
21166 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
21167 struct dwarf2_per_cu_data
*per_cu
,
21168 struct obstack
*obstack
,
21171 struct dwarf2_cu
*cu
;
21172 struct die_info
*die
;
21173 struct attribute
*attr
;
21174 const gdb_byte
*result
= NULL
;
21177 enum bfd_endian byte_order
;
21179 dw2_setup (per_cu
->objfile
);
21181 if (per_cu
->cu
== NULL
)
21186 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21187 Instead just throw an error, not much else we can do. */
21188 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
21189 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
21192 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21194 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
21195 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
21198 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21202 byte_order
= (bfd_big_endian (per_cu
->objfile
->obfd
)
21203 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21205 switch (attr
->form
)
21208 case DW_FORM_GNU_addr_index
:
21212 *len
= cu
->header
.addr_size
;
21213 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21214 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
21218 case DW_FORM_string
:
21220 case DW_FORM_GNU_str_index
:
21221 case DW_FORM_GNU_strp_alt
:
21222 /* DW_STRING is already allocated on the objfile obstack, point
21224 result
= (const gdb_byte
*) DW_STRING (attr
);
21225 *len
= strlen (DW_STRING (attr
));
21227 case DW_FORM_block1
:
21228 case DW_FORM_block2
:
21229 case DW_FORM_block4
:
21230 case DW_FORM_block
:
21231 case DW_FORM_exprloc
:
21232 case DW_FORM_data16
:
21233 result
= DW_BLOCK (attr
)->data
;
21234 *len
= DW_BLOCK (attr
)->size
;
21237 /* The DW_AT_const_value attributes are supposed to carry the
21238 symbol's value "represented as it would be on the target
21239 architecture." By the time we get here, it's already been
21240 converted to host endianness, so we just need to sign- or
21241 zero-extend it as appropriate. */
21242 case DW_FORM_data1
:
21243 type
= die_type (die
, cu
);
21244 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
21245 if (result
== NULL
)
21246 result
= write_constant_as_bytes (obstack
, byte_order
,
21249 case DW_FORM_data2
:
21250 type
= die_type (die
, cu
);
21251 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
21252 if (result
== NULL
)
21253 result
= write_constant_as_bytes (obstack
, byte_order
,
21256 case DW_FORM_data4
:
21257 type
= die_type (die
, cu
);
21258 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
21259 if (result
== NULL
)
21260 result
= write_constant_as_bytes (obstack
, byte_order
,
21263 case DW_FORM_data8
:
21264 type
= die_type (die
, cu
);
21265 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
21266 if (result
== NULL
)
21267 result
= write_constant_as_bytes (obstack
, byte_order
,
21271 case DW_FORM_sdata
:
21272 case DW_FORM_implicit_const
:
21273 type
= die_type (die
, cu
);
21274 result
= write_constant_as_bytes (obstack
, byte_order
,
21275 type
, DW_SND (attr
), len
);
21278 case DW_FORM_udata
:
21279 type
= die_type (die
, cu
);
21280 result
= write_constant_as_bytes (obstack
, byte_order
,
21281 type
, DW_UNSND (attr
), len
);
21285 complaint (&symfile_complaints
,
21286 _("unsupported const value attribute form: '%s'"),
21287 dwarf_form_name (attr
->form
));
21294 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
21295 valid type for this die is found. */
21298 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
21299 struct dwarf2_per_cu_data
*per_cu
)
21301 struct dwarf2_cu
*cu
;
21302 struct die_info
*die
;
21304 dw2_setup (per_cu
->objfile
);
21306 if (per_cu
->cu
== NULL
)
21312 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21316 return die_type (die
, cu
);
21319 /* Return the type of the DIE at DIE_OFFSET in the CU named by
21323 dwarf2_get_die_type (cu_offset die_offset
,
21324 struct dwarf2_per_cu_data
*per_cu
)
21326 dw2_setup (per_cu
->objfile
);
21328 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
21329 return get_die_type_at_offset (die_offset_sect
, per_cu
);
21332 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
21333 On entry *REF_CU is the CU of SRC_DIE.
21334 On exit *REF_CU is the CU of the result.
21335 Returns NULL if the referenced DIE isn't found. */
21337 static struct die_info
*
21338 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
21339 struct dwarf2_cu
**ref_cu
)
21341 struct die_info temp_die
;
21342 struct dwarf2_cu
*sig_cu
;
21343 struct die_info
*die
;
21345 /* While it might be nice to assert sig_type->type == NULL here,
21346 we can get here for DW_AT_imported_declaration where we need
21347 the DIE not the type. */
21349 /* If necessary, add it to the queue and load its DIEs. */
21351 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
21352 read_signatured_type (sig_type
);
21354 sig_cu
= sig_type
->per_cu
.cu
;
21355 gdb_assert (sig_cu
!= NULL
);
21356 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
21357 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
21358 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
21359 to_underlying (temp_die
.sect_off
));
21362 /* For .gdb_index version 7 keep track of included TUs.
21363 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
21364 if (dwarf2_per_objfile
->index_table
!= NULL
21365 && dwarf2_per_objfile
->index_table
->version
<= 7)
21367 VEC_safe_push (dwarf2_per_cu_ptr
,
21368 (*ref_cu
)->per_cu
->imported_symtabs
,
21379 /* Follow signatured type referenced by ATTR in SRC_DIE.
21380 On entry *REF_CU is the CU of SRC_DIE.
21381 On exit *REF_CU is the CU of the result.
21382 The result is the DIE of the type.
21383 If the referenced type cannot be found an error is thrown. */
21385 static struct die_info
*
21386 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21387 struct dwarf2_cu
**ref_cu
)
21389 ULONGEST signature
= DW_SIGNATURE (attr
);
21390 struct signatured_type
*sig_type
;
21391 struct die_info
*die
;
21393 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
21395 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
21396 /* sig_type will be NULL if the signatured type is missing from
21398 if (sig_type
== NULL
)
21400 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
21401 " from DIE at 0x%x [in module %s]"),
21402 hex_string (signature
), to_underlying (src_die
->sect_off
),
21403 objfile_name ((*ref_cu
)->objfile
));
21406 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
21409 dump_die_for_error (src_die
);
21410 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
21411 " from DIE at 0x%x [in module %s]"),
21412 hex_string (signature
), to_underlying (src_die
->sect_off
),
21413 objfile_name ((*ref_cu
)->objfile
));
21419 /* Get the type specified by SIGNATURE referenced in DIE/CU,
21420 reading in and processing the type unit if necessary. */
21422 static struct type
*
21423 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
21424 struct dwarf2_cu
*cu
)
21426 struct signatured_type
*sig_type
;
21427 struct dwarf2_cu
*type_cu
;
21428 struct die_info
*type_die
;
21431 sig_type
= lookup_signatured_type (cu
, signature
);
21432 /* sig_type will be NULL if the signatured type is missing from
21434 if (sig_type
== NULL
)
21436 complaint (&symfile_complaints
,
21437 _("Dwarf Error: Cannot find signatured DIE %s referenced"
21438 " from DIE at 0x%x [in module %s]"),
21439 hex_string (signature
), to_underlying (die
->sect_off
),
21440 objfile_name (dwarf2_per_objfile
->objfile
));
21441 return build_error_marker_type (cu
, die
);
21444 /* If we already know the type we're done. */
21445 if (sig_type
->type
!= NULL
)
21446 return sig_type
->type
;
21449 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
21450 if (type_die
!= NULL
)
21452 /* N.B. We need to call get_die_type to ensure only one type for this DIE
21453 is created. This is important, for example, because for c++ classes
21454 we need TYPE_NAME set which is only done by new_symbol. Blech. */
21455 type
= read_type_die (type_die
, type_cu
);
21458 complaint (&symfile_complaints
,
21459 _("Dwarf Error: Cannot build signatured type %s"
21460 " referenced from DIE at 0x%x [in module %s]"),
21461 hex_string (signature
), to_underlying (die
->sect_off
),
21462 objfile_name (dwarf2_per_objfile
->objfile
));
21463 type
= build_error_marker_type (cu
, die
);
21468 complaint (&symfile_complaints
,
21469 _("Dwarf Error: Problem reading signatured DIE %s referenced"
21470 " from DIE at 0x%x [in module %s]"),
21471 hex_string (signature
), to_underlying (die
->sect_off
),
21472 objfile_name (dwarf2_per_objfile
->objfile
));
21473 type
= build_error_marker_type (cu
, die
);
21475 sig_type
->type
= type
;
21480 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
21481 reading in and processing the type unit if necessary. */
21483 static struct type
*
21484 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
21485 struct dwarf2_cu
*cu
) /* ARI: editCase function */
21487 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
21488 if (attr_form_is_ref (attr
))
21490 struct dwarf2_cu
*type_cu
= cu
;
21491 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
21493 return read_type_die (type_die
, type_cu
);
21495 else if (attr
->form
== DW_FORM_ref_sig8
)
21497 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
21501 complaint (&symfile_complaints
,
21502 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
21503 " at 0x%x [in module %s]"),
21504 dwarf_form_name (attr
->form
), to_underlying (die
->sect_off
),
21505 objfile_name (dwarf2_per_objfile
->objfile
));
21506 return build_error_marker_type (cu
, die
);
21510 /* Load the DIEs associated with type unit PER_CU into memory. */
21513 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
21515 struct signatured_type
*sig_type
;
21517 /* Caller is responsible for ensuring type_unit_groups don't get here. */
21518 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
21520 /* We have the per_cu, but we need the signatured_type.
21521 Fortunately this is an easy translation. */
21522 gdb_assert (per_cu
->is_debug_types
);
21523 sig_type
= (struct signatured_type
*) per_cu
;
21525 gdb_assert (per_cu
->cu
== NULL
);
21527 read_signatured_type (sig_type
);
21529 gdb_assert (per_cu
->cu
!= NULL
);
21532 /* die_reader_func for read_signatured_type.
21533 This is identical to load_full_comp_unit_reader,
21534 but is kept separate for now. */
21537 read_signatured_type_reader (const struct die_reader_specs
*reader
,
21538 const gdb_byte
*info_ptr
,
21539 struct die_info
*comp_unit_die
,
21543 struct dwarf2_cu
*cu
= reader
->cu
;
21545 gdb_assert (cu
->die_hash
== NULL
);
21547 htab_create_alloc_ex (cu
->header
.length
/ 12,
21551 &cu
->comp_unit_obstack
,
21552 hashtab_obstack_allocate
,
21553 dummy_obstack_deallocate
);
21556 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
21557 &info_ptr
, comp_unit_die
);
21558 cu
->dies
= comp_unit_die
;
21559 /* comp_unit_die is not stored in die_hash, no need. */
21561 /* We try not to read any attributes in this function, because not
21562 all CUs needed for references have been loaded yet, and symbol
21563 table processing isn't initialized. But we have to set the CU language,
21564 or we won't be able to build types correctly.
21565 Similarly, if we do not read the producer, we can not apply
21566 producer-specific interpretation. */
21567 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
21570 /* Read in a signatured type and build its CU and DIEs.
21571 If the type is a stub for the real type in a DWO file,
21572 read in the real type from the DWO file as well. */
21575 read_signatured_type (struct signatured_type
*sig_type
)
21577 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
21579 gdb_assert (per_cu
->is_debug_types
);
21580 gdb_assert (per_cu
->cu
== NULL
);
21582 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
21583 read_signatured_type_reader
, NULL
);
21584 sig_type
->per_cu
.tu_read
= 1;
21587 /* Decode simple location descriptions.
21588 Given a pointer to a dwarf block that defines a location, compute
21589 the location and return the value.
21591 NOTE drow/2003-11-18: This function is called in two situations
21592 now: for the address of static or global variables (partial symbols
21593 only) and for offsets into structures which are expected to be
21594 (more or less) constant. The partial symbol case should go away,
21595 and only the constant case should remain. That will let this
21596 function complain more accurately. A few special modes are allowed
21597 without complaint for global variables (for instance, global
21598 register values and thread-local values).
21600 A location description containing no operations indicates that the
21601 object is optimized out. The return value is 0 for that case.
21602 FIXME drow/2003-11-16: No callers check for this case any more; soon all
21603 callers will only want a very basic result and this can become a
21606 Note that stack[0] is unused except as a default error return. */
21609 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
21611 struct objfile
*objfile
= cu
->objfile
;
21613 size_t size
= blk
->size
;
21614 const gdb_byte
*data
= blk
->data
;
21615 CORE_ADDR stack
[64];
21617 unsigned int bytes_read
, unsnd
;
21623 stack
[++stacki
] = 0;
21662 stack
[++stacki
] = op
- DW_OP_lit0
;
21697 stack
[++stacki
] = op
- DW_OP_reg0
;
21699 dwarf2_complex_location_expr_complaint ();
21703 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
21705 stack
[++stacki
] = unsnd
;
21707 dwarf2_complex_location_expr_complaint ();
21711 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
21716 case DW_OP_const1u
:
21717 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
21721 case DW_OP_const1s
:
21722 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
21726 case DW_OP_const2u
:
21727 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
21731 case DW_OP_const2s
:
21732 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
21736 case DW_OP_const4u
:
21737 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
21741 case DW_OP_const4s
:
21742 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
21746 case DW_OP_const8u
:
21747 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
21752 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
21758 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
21763 stack
[stacki
+ 1] = stack
[stacki
];
21768 stack
[stacki
- 1] += stack
[stacki
];
21772 case DW_OP_plus_uconst
:
21773 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
21779 stack
[stacki
- 1] -= stack
[stacki
];
21784 /* If we're not the last op, then we definitely can't encode
21785 this using GDB's address_class enum. This is valid for partial
21786 global symbols, although the variable's address will be bogus
21789 dwarf2_complex_location_expr_complaint ();
21792 case DW_OP_GNU_push_tls_address
:
21793 case DW_OP_form_tls_address
:
21794 /* The top of the stack has the offset from the beginning
21795 of the thread control block at which the variable is located. */
21796 /* Nothing should follow this operator, so the top of stack would
21798 /* This is valid for partial global symbols, but the variable's
21799 address will be bogus in the psymtab. Make it always at least
21800 non-zero to not look as a variable garbage collected by linker
21801 which have DW_OP_addr 0. */
21803 dwarf2_complex_location_expr_complaint ();
21807 case DW_OP_GNU_uninit
:
21810 case DW_OP_GNU_addr_index
:
21811 case DW_OP_GNU_const_index
:
21812 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
21819 const char *name
= get_DW_OP_name (op
);
21822 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
21825 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
21829 return (stack
[stacki
]);
21832 /* Enforce maximum stack depth of SIZE-1 to avoid writing
21833 outside of the allocated space. Also enforce minimum>0. */
21834 if (stacki
>= ARRAY_SIZE (stack
) - 1)
21836 complaint (&symfile_complaints
,
21837 _("location description stack overflow"));
21843 complaint (&symfile_complaints
,
21844 _("location description stack underflow"));
21848 return (stack
[stacki
]);
21851 /* memory allocation interface */
21853 static struct dwarf_block
*
21854 dwarf_alloc_block (struct dwarf2_cu
*cu
)
21856 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
21859 static struct die_info
*
21860 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
21862 struct die_info
*die
;
21863 size_t size
= sizeof (struct die_info
);
21866 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
21868 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
21869 memset (die
, 0, sizeof (struct die_info
));
21874 /* Macro support. */
21876 /* Return file name relative to the compilation directory of file number I in
21877 *LH's file name table. The result is allocated using xmalloc; the caller is
21878 responsible for freeing it. */
21881 file_file_name (int file
, struct line_header
*lh
)
21883 /* Is the file number a valid index into the line header's file name
21884 table? Remember that file numbers start with one, not zero. */
21885 if (1 <= file
&& file
<= lh
->file_names
.size ())
21887 const file_entry
&fe
= lh
->file_names
[file
- 1];
21889 if (!IS_ABSOLUTE_PATH (fe
.name
))
21891 const char *dir
= fe
.include_dir (lh
);
21893 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
21895 return xstrdup (fe
.name
);
21899 /* The compiler produced a bogus file number. We can at least
21900 record the macro definitions made in the file, even if we
21901 won't be able to find the file by name. */
21902 char fake_name
[80];
21904 xsnprintf (fake_name
, sizeof (fake_name
),
21905 "<bad macro file number %d>", file
);
21907 complaint (&symfile_complaints
,
21908 _("bad file number in macro information (%d)"),
21911 return xstrdup (fake_name
);
21915 /* Return the full name of file number I in *LH's file name table.
21916 Use COMP_DIR as the name of the current directory of the
21917 compilation. The result is allocated using xmalloc; the caller is
21918 responsible for freeing it. */
21920 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
21922 /* Is the file number a valid index into the line header's file name
21923 table? Remember that file numbers start with one, not zero. */
21924 if (1 <= file
&& file
<= lh
->file_names
.size ())
21926 char *relative
= file_file_name (file
, lh
);
21928 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
21930 return reconcat (relative
, comp_dir
, SLASH_STRING
,
21931 relative
, (char *) NULL
);
21934 return file_file_name (file
, lh
);
21938 static struct macro_source_file
*
21939 macro_start_file (int file
, int line
,
21940 struct macro_source_file
*current_file
,
21941 struct line_header
*lh
)
21943 /* File name relative to the compilation directory of this source file. */
21944 char *file_name
= file_file_name (file
, lh
);
21946 if (! current_file
)
21948 /* Note: We don't create a macro table for this compilation unit
21949 at all until we actually get a filename. */
21950 struct macro_table
*macro_table
= get_macro_table ();
21952 /* If we have no current file, then this must be the start_file
21953 directive for the compilation unit's main source file. */
21954 current_file
= macro_set_main (macro_table
, file_name
);
21955 macro_define_special (macro_table
);
21958 current_file
= macro_include (current_file
, line
, file_name
);
21962 return current_file
;
21965 static const char *
21966 consume_improper_spaces (const char *p
, const char *body
)
21970 complaint (&symfile_complaints
,
21971 _("macro definition contains spaces "
21972 "in formal argument list:\n`%s'"),
21984 parse_macro_definition (struct macro_source_file
*file
, int line
,
21989 /* The body string takes one of two forms. For object-like macro
21990 definitions, it should be:
21992 <macro name> " " <definition>
21994 For function-like macro definitions, it should be:
21996 <macro name> "() " <definition>
21998 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
22000 Spaces may appear only where explicitly indicated, and in the
22003 The Dwarf 2 spec says that an object-like macro's name is always
22004 followed by a space, but versions of GCC around March 2002 omit
22005 the space when the macro's definition is the empty string.
22007 The Dwarf 2 spec says that there should be no spaces between the
22008 formal arguments in a function-like macro's formal argument list,
22009 but versions of GCC around March 2002 include spaces after the
22013 /* Find the extent of the macro name. The macro name is terminated
22014 by either a space or null character (for an object-like macro) or
22015 an opening paren (for a function-like macro). */
22016 for (p
= body
; *p
; p
++)
22017 if (*p
== ' ' || *p
== '(')
22020 if (*p
== ' ' || *p
== '\0')
22022 /* It's an object-like macro. */
22023 int name_len
= p
- body
;
22024 char *name
= savestring (body
, name_len
);
22025 const char *replacement
;
22028 replacement
= body
+ name_len
+ 1;
22031 dwarf2_macro_malformed_definition_complaint (body
);
22032 replacement
= body
+ name_len
;
22035 macro_define_object (file
, line
, name
, replacement
);
22039 else if (*p
== '(')
22041 /* It's a function-like macro. */
22042 char *name
= savestring (body
, p
- body
);
22045 char **argv
= XNEWVEC (char *, argv_size
);
22049 p
= consume_improper_spaces (p
, body
);
22051 /* Parse the formal argument list. */
22052 while (*p
&& *p
!= ')')
22054 /* Find the extent of the current argument name. */
22055 const char *arg_start
= p
;
22057 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
22060 if (! *p
|| p
== arg_start
)
22061 dwarf2_macro_malformed_definition_complaint (body
);
22064 /* Make sure argv has room for the new argument. */
22065 if (argc
>= argv_size
)
22068 argv
= XRESIZEVEC (char *, argv
, argv_size
);
22071 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
22074 p
= consume_improper_spaces (p
, body
);
22076 /* Consume the comma, if present. */
22081 p
= consume_improper_spaces (p
, body
);
22090 /* Perfectly formed definition, no complaints. */
22091 macro_define_function (file
, line
, name
,
22092 argc
, (const char **) argv
,
22094 else if (*p
== '\0')
22096 /* Complain, but do define it. */
22097 dwarf2_macro_malformed_definition_complaint (body
);
22098 macro_define_function (file
, line
, name
,
22099 argc
, (const char **) argv
,
22103 /* Just complain. */
22104 dwarf2_macro_malformed_definition_complaint (body
);
22107 /* Just complain. */
22108 dwarf2_macro_malformed_definition_complaint (body
);
22114 for (i
= 0; i
< argc
; i
++)
22120 dwarf2_macro_malformed_definition_complaint (body
);
22123 /* Skip some bytes from BYTES according to the form given in FORM.
22124 Returns the new pointer. */
22126 static const gdb_byte
*
22127 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
22128 enum dwarf_form form
,
22129 unsigned int offset_size
,
22130 struct dwarf2_section_info
*section
)
22132 unsigned int bytes_read
;
22136 case DW_FORM_data1
:
22141 case DW_FORM_data2
:
22145 case DW_FORM_data4
:
22149 case DW_FORM_data8
:
22153 case DW_FORM_data16
:
22157 case DW_FORM_string
:
22158 read_direct_string (abfd
, bytes
, &bytes_read
);
22159 bytes
+= bytes_read
;
22162 case DW_FORM_sec_offset
:
22164 case DW_FORM_GNU_strp_alt
:
22165 bytes
+= offset_size
;
22168 case DW_FORM_block
:
22169 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
22170 bytes
+= bytes_read
;
22173 case DW_FORM_block1
:
22174 bytes
+= 1 + read_1_byte (abfd
, bytes
);
22176 case DW_FORM_block2
:
22177 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
22179 case DW_FORM_block4
:
22180 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
22183 case DW_FORM_sdata
:
22184 case DW_FORM_udata
:
22185 case DW_FORM_GNU_addr_index
:
22186 case DW_FORM_GNU_str_index
:
22187 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
22190 dwarf2_section_buffer_overflow_complaint (section
);
22195 case DW_FORM_implicit_const
:
22201 complaint (&symfile_complaints
,
22202 _("invalid form 0x%x in `%s'"),
22203 form
, get_section_name (section
));
22211 /* A helper for dwarf_decode_macros that handles skipping an unknown
22212 opcode. Returns an updated pointer to the macro data buffer; or,
22213 on error, issues a complaint and returns NULL. */
22215 static const gdb_byte
*
22216 skip_unknown_opcode (unsigned int opcode
,
22217 const gdb_byte
**opcode_definitions
,
22218 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
22220 unsigned int offset_size
,
22221 struct dwarf2_section_info
*section
)
22223 unsigned int bytes_read
, i
;
22225 const gdb_byte
*defn
;
22227 if (opcode_definitions
[opcode
] == NULL
)
22229 complaint (&symfile_complaints
,
22230 _("unrecognized DW_MACFINO opcode 0x%x"),
22235 defn
= opcode_definitions
[opcode
];
22236 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
22237 defn
+= bytes_read
;
22239 for (i
= 0; i
< arg
; ++i
)
22241 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
22242 (enum dwarf_form
) defn
[i
], offset_size
,
22244 if (mac_ptr
== NULL
)
22246 /* skip_form_bytes already issued the complaint. */
22254 /* A helper function which parses the header of a macro section.
22255 If the macro section is the extended (for now called "GNU") type,
22256 then this updates *OFFSET_SIZE. Returns a pointer to just after
22257 the header, or issues a complaint and returns NULL on error. */
22259 static const gdb_byte
*
22260 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
22262 const gdb_byte
*mac_ptr
,
22263 unsigned int *offset_size
,
22264 int section_is_gnu
)
22266 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
22268 if (section_is_gnu
)
22270 unsigned int version
, flags
;
22272 version
= read_2_bytes (abfd
, mac_ptr
);
22273 if (version
!= 4 && version
!= 5)
22275 complaint (&symfile_complaints
,
22276 _("unrecognized version `%d' in .debug_macro section"),
22282 flags
= read_1_byte (abfd
, mac_ptr
);
22284 *offset_size
= (flags
& 1) ? 8 : 4;
22286 if ((flags
& 2) != 0)
22287 /* We don't need the line table offset. */
22288 mac_ptr
+= *offset_size
;
22290 /* Vendor opcode descriptions. */
22291 if ((flags
& 4) != 0)
22293 unsigned int i
, count
;
22295 count
= read_1_byte (abfd
, mac_ptr
);
22297 for (i
= 0; i
< count
; ++i
)
22299 unsigned int opcode
, bytes_read
;
22302 opcode
= read_1_byte (abfd
, mac_ptr
);
22304 opcode_definitions
[opcode
] = mac_ptr
;
22305 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22306 mac_ptr
+= bytes_read
;
22315 /* A helper for dwarf_decode_macros that handles the GNU extensions,
22316 including DW_MACRO_import. */
22319 dwarf_decode_macro_bytes (bfd
*abfd
,
22320 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
22321 struct macro_source_file
*current_file
,
22322 struct line_header
*lh
,
22323 struct dwarf2_section_info
*section
,
22324 int section_is_gnu
, int section_is_dwz
,
22325 unsigned int offset_size
,
22326 htab_t include_hash
)
22328 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22329 enum dwarf_macro_record_type macinfo_type
;
22330 int at_commandline
;
22331 const gdb_byte
*opcode_definitions
[256];
22333 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
22334 &offset_size
, section_is_gnu
);
22335 if (mac_ptr
== NULL
)
22337 /* We already issued a complaint. */
22341 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
22342 GDB is still reading the definitions from command line. First
22343 DW_MACINFO_start_file will need to be ignored as it was already executed
22344 to create CURRENT_FILE for the main source holding also the command line
22345 definitions. On first met DW_MACINFO_start_file this flag is reset to
22346 normally execute all the remaining DW_MACINFO_start_file macinfos. */
22348 at_commandline
= 1;
22352 /* Do we at least have room for a macinfo type byte? */
22353 if (mac_ptr
>= mac_end
)
22355 dwarf2_section_buffer_overflow_complaint (section
);
22359 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
22362 /* Note that we rely on the fact that the corresponding GNU and
22363 DWARF constants are the same. */
22364 switch (macinfo_type
)
22366 /* A zero macinfo type indicates the end of the macro
22371 case DW_MACRO_define
:
22372 case DW_MACRO_undef
:
22373 case DW_MACRO_define_strp
:
22374 case DW_MACRO_undef_strp
:
22375 case DW_MACRO_define_sup
:
22376 case DW_MACRO_undef_sup
:
22378 unsigned int bytes_read
;
22383 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22384 mac_ptr
+= bytes_read
;
22386 if (macinfo_type
== DW_MACRO_define
22387 || macinfo_type
== DW_MACRO_undef
)
22389 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22390 mac_ptr
+= bytes_read
;
22394 LONGEST str_offset
;
22396 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
22397 mac_ptr
+= offset_size
;
22399 if (macinfo_type
== DW_MACRO_define_sup
22400 || macinfo_type
== DW_MACRO_undef_sup
22403 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
22405 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
22408 body
= read_indirect_string_at_offset (abfd
, str_offset
);
22411 is_define
= (macinfo_type
== DW_MACRO_define
22412 || macinfo_type
== DW_MACRO_define_strp
22413 || macinfo_type
== DW_MACRO_define_sup
);
22414 if (! current_file
)
22416 /* DWARF violation as no main source is present. */
22417 complaint (&symfile_complaints
,
22418 _("debug info with no main source gives macro %s "
22420 is_define
? _("definition") : _("undefinition"),
22424 if ((line
== 0 && !at_commandline
)
22425 || (line
!= 0 && at_commandline
))
22426 complaint (&symfile_complaints
,
22427 _("debug info gives %s macro %s with %s line %d: %s"),
22428 at_commandline
? _("command-line") : _("in-file"),
22429 is_define
? _("definition") : _("undefinition"),
22430 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
22433 parse_macro_definition (current_file
, line
, body
);
22436 gdb_assert (macinfo_type
== DW_MACRO_undef
22437 || macinfo_type
== DW_MACRO_undef_strp
22438 || macinfo_type
== DW_MACRO_undef_sup
);
22439 macro_undef (current_file
, line
, body
);
22444 case DW_MACRO_start_file
:
22446 unsigned int bytes_read
;
22449 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22450 mac_ptr
+= bytes_read
;
22451 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22452 mac_ptr
+= bytes_read
;
22454 if ((line
== 0 && !at_commandline
)
22455 || (line
!= 0 && at_commandline
))
22456 complaint (&symfile_complaints
,
22457 _("debug info gives source %d included "
22458 "from %s at %s line %d"),
22459 file
, at_commandline
? _("command-line") : _("file"),
22460 line
== 0 ? _("zero") : _("non-zero"), line
);
22462 if (at_commandline
)
22464 /* This DW_MACRO_start_file was executed in the
22466 at_commandline
= 0;
22469 current_file
= macro_start_file (file
, line
, current_file
, lh
);
22473 case DW_MACRO_end_file
:
22474 if (! current_file
)
22475 complaint (&symfile_complaints
,
22476 _("macro debug info has an unmatched "
22477 "`close_file' directive"));
22480 current_file
= current_file
->included_by
;
22481 if (! current_file
)
22483 enum dwarf_macro_record_type next_type
;
22485 /* GCC circa March 2002 doesn't produce the zero
22486 type byte marking the end of the compilation
22487 unit. Complain if it's not there, but exit no
22490 /* Do we at least have room for a macinfo type byte? */
22491 if (mac_ptr
>= mac_end
)
22493 dwarf2_section_buffer_overflow_complaint (section
);
22497 /* We don't increment mac_ptr here, so this is just
22500 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
22502 if (next_type
!= 0)
22503 complaint (&symfile_complaints
,
22504 _("no terminating 0-type entry for "
22505 "macros in `.debug_macinfo' section"));
22512 case DW_MACRO_import
:
22513 case DW_MACRO_import_sup
:
22517 bfd
*include_bfd
= abfd
;
22518 struct dwarf2_section_info
*include_section
= section
;
22519 const gdb_byte
*include_mac_end
= mac_end
;
22520 int is_dwz
= section_is_dwz
;
22521 const gdb_byte
*new_mac_ptr
;
22523 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
22524 mac_ptr
+= offset_size
;
22526 if (macinfo_type
== DW_MACRO_import_sup
)
22528 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
22530 dwarf2_read_section (objfile
, &dwz
->macro
);
22532 include_section
= &dwz
->macro
;
22533 include_bfd
= get_section_bfd_owner (include_section
);
22534 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
22538 new_mac_ptr
= include_section
->buffer
+ offset
;
22539 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
22543 /* This has actually happened; see
22544 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
22545 complaint (&symfile_complaints
,
22546 _("recursive DW_MACRO_import in "
22547 ".debug_macro section"));
22551 *slot
= (void *) new_mac_ptr
;
22553 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
22554 include_mac_end
, current_file
, lh
,
22555 section
, section_is_gnu
, is_dwz
,
22556 offset_size
, include_hash
);
22558 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
22563 case DW_MACINFO_vendor_ext
:
22564 if (!section_is_gnu
)
22566 unsigned int bytes_read
;
22568 /* This reads the constant, but since we don't recognize
22569 any vendor extensions, we ignore it. */
22570 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22571 mac_ptr
+= bytes_read
;
22572 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22573 mac_ptr
+= bytes_read
;
22575 /* We don't recognize any vendor extensions. */
22581 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
22582 mac_ptr
, mac_end
, abfd
, offset_size
,
22584 if (mac_ptr
== NULL
)
22588 } while (macinfo_type
!= 0);
22592 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22593 int section_is_gnu
)
22595 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22596 struct line_header
*lh
= cu
->line_header
;
22598 const gdb_byte
*mac_ptr
, *mac_end
;
22599 struct macro_source_file
*current_file
= 0;
22600 enum dwarf_macro_record_type macinfo_type
;
22601 unsigned int offset_size
= cu
->header
.offset_size
;
22602 const gdb_byte
*opcode_definitions
[256];
22604 struct dwarf2_section_info
*section
;
22605 const char *section_name
;
22607 if (cu
->dwo_unit
!= NULL
)
22609 if (section_is_gnu
)
22611 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22612 section_name
= ".debug_macro.dwo";
22616 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22617 section_name
= ".debug_macinfo.dwo";
22622 if (section_is_gnu
)
22624 section
= &dwarf2_per_objfile
->macro
;
22625 section_name
= ".debug_macro";
22629 section
= &dwarf2_per_objfile
->macinfo
;
22630 section_name
= ".debug_macinfo";
22634 dwarf2_read_section (objfile
, section
);
22635 if (section
->buffer
== NULL
)
22637 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
22640 abfd
= get_section_bfd_owner (section
);
22642 /* First pass: Find the name of the base filename.
22643 This filename is needed in order to process all macros whose definition
22644 (or undefinition) comes from the command line. These macros are defined
22645 before the first DW_MACINFO_start_file entry, and yet still need to be
22646 associated to the base file.
22648 To determine the base file name, we scan the macro definitions until we
22649 reach the first DW_MACINFO_start_file entry. We then initialize
22650 CURRENT_FILE accordingly so that any macro definition found before the
22651 first DW_MACINFO_start_file can still be associated to the base file. */
22653 mac_ptr
= section
->buffer
+ offset
;
22654 mac_end
= section
->buffer
+ section
->size
;
22656 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
22657 &offset_size
, section_is_gnu
);
22658 if (mac_ptr
== NULL
)
22660 /* We already issued a complaint. */
22666 /* Do we at least have room for a macinfo type byte? */
22667 if (mac_ptr
>= mac_end
)
22669 /* Complaint is printed during the second pass as GDB will probably
22670 stop the first pass earlier upon finding
22671 DW_MACINFO_start_file. */
22675 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
22678 /* Note that we rely on the fact that the corresponding GNU and
22679 DWARF constants are the same. */
22680 switch (macinfo_type
)
22682 /* A zero macinfo type indicates the end of the macro
22687 case DW_MACRO_define
:
22688 case DW_MACRO_undef
:
22689 /* Only skip the data by MAC_PTR. */
22691 unsigned int bytes_read
;
22693 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22694 mac_ptr
+= bytes_read
;
22695 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22696 mac_ptr
+= bytes_read
;
22700 case DW_MACRO_start_file
:
22702 unsigned int bytes_read
;
22705 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22706 mac_ptr
+= bytes_read
;
22707 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22708 mac_ptr
+= bytes_read
;
22710 current_file
= macro_start_file (file
, line
, current_file
, lh
);
22714 case DW_MACRO_end_file
:
22715 /* No data to skip by MAC_PTR. */
22718 case DW_MACRO_define_strp
:
22719 case DW_MACRO_undef_strp
:
22720 case DW_MACRO_define_sup
:
22721 case DW_MACRO_undef_sup
:
22723 unsigned int bytes_read
;
22725 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22726 mac_ptr
+= bytes_read
;
22727 mac_ptr
+= offset_size
;
22731 case DW_MACRO_import
:
22732 case DW_MACRO_import_sup
:
22733 /* Note that, according to the spec, a transparent include
22734 chain cannot call DW_MACRO_start_file. So, we can just
22735 skip this opcode. */
22736 mac_ptr
+= offset_size
;
22739 case DW_MACINFO_vendor_ext
:
22740 /* Only skip the data by MAC_PTR. */
22741 if (!section_is_gnu
)
22743 unsigned int bytes_read
;
22745 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22746 mac_ptr
+= bytes_read
;
22747 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22748 mac_ptr
+= bytes_read
;
22753 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
22754 mac_ptr
, mac_end
, abfd
, offset_size
,
22756 if (mac_ptr
== NULL
)
22760 } while (macinfo_type
!= 0 && current_file
== NULL
);
22762 /* Second pass: Process all entries.
22764 Use the AT_COMMAND_LINE flag to determine whether we are still processing
22765 command-line macro definitions/undefinitions. This flag is unset when we
22766 reach the first DW_MACINFO_start_file entry. */
22768 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
22770 NULL
, xcalloc
, xfree
));
22771 mac_ptr
= section
->buffer
+ offset
;
22772 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
22773 *slot
= (void *) mac_ptr
;
22774 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
22775 current_file
, lh
, section
,
22776 section_is_gnu
, 0, offset_size
,
22777 include_hash
.get ());
22780 /* Check if the attribute's form is a DW_FORM_block*
22781 if so return true else false. */
22784 attr_form_is_block (const struct attribute
*attr
)
22786 return (attr
== NULL
? 0 :
22787 attr
->form
== DW_FORM_block1
22788 || attr
->form
== DW_FORM_block2
22789 || attr
->form
== DW_FORM_block4
22790 || attr
->form
== DW_FORM_block
22791 || attr
->form
== DW_FORM_exprloc
);
22794 /* Return non-zero if ATTR's value is a section offset --- classes
22795 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
22796 You may use DW_UNSND (attr) to retrieve such offsets.
22798 Section 7.5.4, "Attribute Encodings", explains that no attribute
22799 may have a value that belongs to more than one of these classes; it
22800 would be ambiguous if we did, because we use the same forms for all
22804 attr_form_is_section_offset (const struct attribute
*attr
)
22806 return (attr
->form
== DW_FORM_data4
22807 || attr
->form
== DW_FORM_data8
22808 || attr
->form
== DW_FORM_sec_offset
);
22811 /* Return non-zero if ATTR's value falls in the 'constant' class, or
22812 zero otherwise. When this function returns true, you can apply
22813 dwarf2_get_attr_constant_value to it.
22815 However, note that for some attributes you must check
22816 attr_form_is_section_offset before using this test. DW_FORM_data4
22817 and DW_FORM_data8 are members of both the constant class, and of
22818 the classes that contain offsets into other debug sections
22819 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
22820 that, if an attribute's can be either a constant or one of the
22821 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
22822 taken as section offsets, not constants.
22824 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
22825 cannot handle that. */
22828 attr_form_is_constant (const struct attribute
*attr
)
22830 switch (attr
->form
)
22832 case DW_FORM_sdata
:
22833 case DW_FORM_udata
:
22834 case DW_FORM_data1
:
22835 case DW_FORM_data2
:
22836 case DW_FORM_data4
:
22837 case DW_FORM_data8
:
22838 case DW_FORM_implicit_const
:
22846 /* DW_ADDR is always stored already as sect_offset; despite for the forms
22847 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
22850 attr_form_is_ref (const struct attribute
*attr
)
22852 switch (attr
->form
)
22854 case DW_FORM_ref_addr
:
22859 case DW_FORM_ref_udata
:
22860 case DW_FORM_GNU_ref_alt
:
22867 /* Return the .debug_loc section to use for CU.
22868 For DWO files use .debug_loc.dwo. */
22870 static struct dwarf2_section_info
*
22871 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22875 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22877 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22879 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22880 : &dwarf2_per_objfile
->loc
);
22883 /* A helper function that fills in a dwarf2_loclist_baton. */
22886 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22887 struct dwarf2_loclist_baton
*baton
,
22888 const struct attribute
*attr
)
22890 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22892 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
22894 baton
->per_cu
= cu
->per_cu
;
22895 gdb_assert (baton
->per_cu
);
22896 /* We don't know how long the location list is, but make sure we
22897 don't run off the edge of the section. */
22898 baton
->size
= section
->size
- DW_UNSND (attr
);
22899 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22900 baton
->base_address
= cu
->base_address
;
22901 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22905 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22906 struct dwarf2_cu
*cu
, int is_block
)
22908 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22909 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22911 if (attr_form_is_section_offset (attr
)
22912 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22913 the section. If so, fall through to the complaint in the
22915 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
22917 struct dwarf2_loclist_baton
*baton
;
22919 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22921 fill_in_loclist_baton (cu
, baton
, attr
);
22923 if (cu
->base_known
== 0)
22924 complaint (&symfile_complaints
,
22925 _("Location list used without "
22926 "specifying the CU base address."));
22928 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22929 ? dwarf2_loclist_block_index
22930 : dwarf2_loclist_index
);
22931 SYMBOL_LOCATION_BATON (sym
) = baton
;
22935 struct dwarf2_locexpr_baton
*baton
;
22937 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22938 baton
->per_cu
= cu
->per_cu
;
22939 gdb_assert (baton
->per_cu
);
22941 if (attr_form_is_block (attr
))
22943 /* Note that we're just copying the block's data pointer
22944 here, not the actual data. We're still pointing into the
22945 info_buffer for SYM's objfile; right now we never release
22946 that buffer, but when we do clean up properly this may
22948 baton
->size
= DW_BLOCK (attr
)->size
;
22949 baton
->data
= DW_BLOCK (attr
)->data
;
22953 dwarf2_invalid_attrib_class_complaint ("location description",
22954 SYMBOL_NATURAL_NAME (sym
));
22958 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22959 ? dwarf2_locexpr_block_index
22960 : dwarf2_locexpr_index
);
22961 SYMBOL_LOCATION_BATON (sym
) = baton
;
22965 /* Return the OBJFILE associated with the compilation unit CU. If CU
22966 came from a separate debuginfo file, then the master objfile is
22970 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
22972 struct objfile
*objfile
= per_cu
->objfile
;
22974 /* Return the master objfile, so that we can report and look up the
22975 correct file containing this variable. */
22976 if (objfile
->separate_debug_objfile_backlink
)
22977 objfile
= objfile
->separate_debug_objfile_backlink
;
22982 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22983 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22984 CU_HEADERP first. */
22986 static const struct comp_unit_head
*
22987 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22988 struct dwarf2_per_cu_data
*per_cu
)
22990 const gdb_byte
*info_ptr
;
22993 return &per_cu
->cu
->header
;
22995 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
22997 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22998 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22999 rcuh_kind::COMPILE
);
23004 /* Return the address size given in the compilation unit header for CU. */
23007 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
23009 struct comp_unit_head cu_header_local
;
23010 const struct comp_unit_head
*cu_headerp
;
23012 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
23014 return cu_headerp
->addr_size
;
23017 /* Return the offset size given in the compilation unit header for CU. */
23020 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
23022 struct comp_unit_head cu_header_local
;
23023 const struct comp_unit_head
*cu_headerp
;
23025 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
23027 return cu_headerp
->offset_size
;
23030 /* See its dwarf2loc.h declaration. */
23033 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
23035 struct comp_unit_head cu_header_local
;
23036 const struct comp_unit_head
*cu_headerp
;
23038 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
23040 if (cu_headerp
->version
== 2)
23041 return cu_headerp
->addr_size
;
23043 return cu_headerp
->offset_size
;
23046 /* Return the text offset of the CU. The returned offset comes from
23047 this CU's objfile. If this objfile came from a separate debuginfo
23048 file, then the offset may be different from the corresponding
23049 offset in the parent objfile. */
23052 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
23054 struct objfile
*objfile
= per_cu
->objfile
;
23056 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23059 /* Return DWARF version number of PER_CU. */
23062 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
23064 return per_cu
->dwarf_version
;
23067 /* Locate the .debug_info compilation unit from CU's objfile which contains
23068 the DIE at OFFSET. Raises an error on failure. */
23070 static struct dwarf2_per_cu_data
*
23071 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23072 unsigned int offset_in_dwz
,
23073 struct objfile
*objfile
)
23075 struct dwarf2_per_cu_data
*this_cu
;
23077 const sect_offset
*cu_off
;
23080 high
= dwarf2_per_objfile
->n_comp_units
- 1;
23083 struct dwarf2_per_cu_data
*mid_cu
;
23084 int mid
= low
+ (high
- low
) / 2;
23086 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
23087 cu_off
= &mid_cu
->sect_off
;
23088 if (mid_cu
->is_dwz
> offset_in_dwz
23089 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
23094 gdb_assert (low
== high
);
23095 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
23096 cu_off
= &this_cu
->sect_off
;
23097 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
23099 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23100 error (_("Dwarf Error: could not find partial DIE containing "
23101 "offset 0x%x [in module %s]"),
23102 to_underlying (sect_off
), bfd_get_filename (objfile
->obfd
));
23104 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
23106 return dwarf2_per_objfile
->all_comp_units
[low
-1];
23110 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
23111 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
23112 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23113 error (_("invalid dwarf2 offset %u"), to_underlying (sect_off
));
23114 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23119 /* Initialize dwarf2_cu CU, owned by PER_CU. */
23122 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
23124 memset (cu
, 0, sizeof (*cu
));
23126 cu
->per_cu
= per_cu
;
23127 cu
->objfile
= per_cu
->objfile
;
23128 obstack_init (&cu
->comp_unit_obstack
);
23131 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23134 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23135 enum language pretend_language
)
23137 struct attribute
*attr
;
23139 /* Set the language we're debugging. */
23140 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23142 set_cu_language (DW_UNSND (attr
), cu
);
23145 cu
->language
= pretend_language
;
23146 cu
->language_defn
= language_def (cu
->language
);
23149 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23152 /* Release one cached compilation unit, CU. We unlink it from the tree
23153 of compilation units, but we don't remove it from the read_in_chain;
23154 the caller is responsible for that.
23155 NOTE: DATA is a void * because this function is also used as a
23156 cleanup routine. */
23159 free_heap_comp_unit (void *data
)
23161 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
23163 gdb_assert (cu
->per_cu
!= NULL
);
23164 cu
->per_cu
->cu
= NULL
;
23167 obstack_free (&cu
->comp_unit_obstack
, NULL
);
23172 /* This cleanup function is passed the address of a dwarf2_cu on the stack
23173 when we're finished with it. We can't free the pointer itself, but be
23174 sure to unlink it from the cache. Also release any associated storage. */
23177 free_stack_comp_unit (void *data
)
23179 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
23181 gdb_assert (cu
->per_cu
!= NULL
);
23182 cu
->per_cu
->cu
= NULL
;
23185 obstack_free (&cu
->comp_unit_obstack
, NULL
);
23186 cu
->partial_dies
= NULL
;
23189 /* Free all cached compilation units. */
23192 free_cached_comp_units (void *data
)
23194 dwarf2_per_objfile
->free_cached_comp_units ();
23197 /* Increase the age counter on each cached compilation unit, and free
23198 any that are too old. */
23201 age_cached_comp_units (void)
23203 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23205 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
23206 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23207 while (per_cu
!= NULL
)
23209 per_cu
->cu
->last_used
++;
23210 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23211 dwarf2_mark (per_cu
->cu
);
23212 per_cu
= per_cu
->cu
->read_in_chain
;
23215 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23216 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23217 while (per_cu
!= NULL
)
23219 struct dwarf2_per_cu_data
*next_cu
;
23221 next_cu
= per_cu
->cu
->read_in_chain
;
23223 if (!per_cu
->cu
->mark
)
23225 free_heap_comp_unit (per_cu
->cu
);
23226 *last_chain
= next_cu
;
23229 last_chain
= &per_cu
->cu
->read_in_chain
;
23235 /* Remove a single compilation unit from the cache. */
23238 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23240 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23242 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23243 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23244 while (per_cu
!= NULL
)
23246 struct dwarf2_per_cu_data
*next_cu
;
23248 next_cu
= per_cu
->cu
->read_in_chain
;
23250 if (per_cu
== target_per_cu
)
23252 free_heap_comp_unit (per_cu
->cu
);
23254 *last_chain
= next_cu
;
23258 last_chain
= &per_cu
->cu
->read_in_chain
;
23264 /* Release all extra memory associated with OBJFILE. */
23267 dwarf2_free_objfile (struct objfile
*objfile
)
23270 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
23271 dwarf2_objfile_data_key
);
23273 if (dwarf2_per_objfile
== NULL
)
23276 dwarf2_per_objfile
->~dwarf2_per_objfile ();
23279 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23280 We store these in a hash table separate from the DIEs, and preserve them
23281 when the DIEs are flushed out of cache.
23283 The CU "per_cu" pointer is needed because offset alone is not enough to
23284 uniquely identify the type. A file may have multiple .debug_types sections,
23285 or the type may come from a DWO file. Furthermore, while it's more logical
23286 to use per_cu->section+offset, with Fission the section with the data is in
23287 the DWO file but we don't know that section at the point we need it.
23288 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23289 because we can enter the lookup routine, get_die_type_at_offset, from
23290 outside this file, and thus won't necessarily have PER_CU->cu.
23291 Fortunately, PER_CU is stable for the life of the objfile. */
23293 struct dwarf2_per_cu_offset_and_type
23295 const struct dwarf2_per_cu_data
*per_cu
;
23296 sect_offset sect_off
;
23300 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23303 per_cu_offset_and_type_hash (const void *item
)
23305 const struct dwarf2_per_cu_offset_and_type
*ofs
23306 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23308 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23311 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23314 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23316 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23317 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23318 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23319 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23321 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23322 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23325 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23326 table if necessary. For convenience, return TYPE.
23328 The DIEs reading must have careful ordering to:
23329 * Not cause infite loops trying to read in DIEs as a prerequisite for
23330 reading current DIE.
23331 * Not trying to dereference contents of still incompletely read in types
23332 while reading in other DIEs.
23333 * Enable referencing still incompletely read in types just by a pointer to
23334 the type without accessing its fields.
23336 Therefore caller should follow these rules:
23337 * Try to fetch any prerequisite types we may need to build this DIE type
23338 before building the type and calling set_die_type.
23339 * After building type call set_die_type for current DIE as soon as
23340 possible before fetching more types to complete the current type.
23341 * Make the type as complete as possible before fetching more types. */
23343 static struct type
*
23344 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23346 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23347 struct objfile
*objfile
= cu
->objfile
;
23348 struct attribute
*attr
;
23349 struct dynamic_prop prop
;
23351 /* For Ada types, make sure that the gnat-specific data is always
23352 initialized (if not already set). There are a few types where
23353 we should not be doing so, because the type-specific area is
23354 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23355 where the type-specific area is used to store the floatformat).
23356 But this is not a problem, because the gnat-specific information
23357 is actually not needed for these types. */
23358 if (need_gnat_info (cu
)
23359 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23360 && TYPE_CODE (type
) != TYPE_CODE_FLT
23361 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23362 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23363 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23364 && !HAVE_GNAT_AUX_INFO (type
))
23365 INIT_GNAT_SPECIFIC (type
);
23367 /* Read DW_AT_allocated and set in type. */
23368 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23369 if (attr_form_is_block (attr
))
23371 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
23372 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
, objfile
);
23374 else if (attr
!= NULL
)
23376 complaint (&symfile_complaints
,
23377 _("DW_AT_allocated has the wrong form (%s) at DIE 0x%x"),
23378 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23379 to_underlying (die
->sect_off
));
23382 /* Read DW_AT_associated and set in type. */
23383 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23384 if (attr_form_is_block (attr
))
23386 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
23387 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
, objfile
);
23389 else if (attr
!= NULL
)
23391 complaint (&symfile_complaints
,
23392 _("DW_AT_associated has the wrong form (%s) at DIE 0x%x"),
23393 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23394 to_underlying (die
->sect_off
));
23397 /* Read DW_AT_data_location and set in type. */
23398 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23399 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
23400 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
, objfile
);
23402 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23404 dwarf2_per_objfile
->die_type_hash
=
23405 htab_create_alloc_ex (127,
23406 per_cu_offset_and_type_hash
,
23407 per_cu_offset_and_type_eq
,
23409 &objfile
->objfile_obstack
,
23410 hashtab_obstack_allocate
,
23411 dummy_obstack_deallocate
);
23414 ofs
.per_cu
= cu
->per_cu
;
23415 ofs
.sect_off
= die
->sect_off
;
23417 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23418 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
23420 complaint (&symfile_complaints
,
23421 _("A problem internal to GDB: DIE 0x%x has type already set"),
23422 to_underlying (die
->sect_off
));
23423 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23424 struct dwarf2_per_cu_offset_and_type
);
23429 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23430 or return NULL if the die does not have a saved type. */
23432 static struct type
*
23433 get_die_type_at_offset (sect_offset sect_off
,
23434 struct dwarf2_per_cu_data
*per_cu
)
23436 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23438 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23441 ofs
.per_cu
= per_cu
;
23442 ofs
.sect_off
= sect_off
;
23443 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23444 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
23451 /* Look up the type for DIE in CU in die_type_hash,
23452 or return NULL if DIE does not have a saved type. */
23454 static struct type
*
23455 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23457 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23460 /* Add a dependence relationship from CU to REF_PER_CU. */
23463 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23464 struct dwarf2_per_cu_data
*ref_per_cu
)
23468 if (cu
->dependencies
== NULL
)
23470 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23471 NULL
, &cu
->comp_unit_obstack
,
23472 hashtab_obstack_allocate
,
23473 dummy_obstack_deallocate
);
23475 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23477 *slot
= ref_per_cu
;
23480 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23481 Set the mark field in every compilation unit in the
23482 cache that we must keep because we are keeping CU. */
23485 dwarf2_mark_helper (void **slot
, void *data
)
23487 struct dwarf2_per_cu_data
*per_cu
;
23489 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23491 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23492 reading of the chain. As such dependencies remain valid it is not much
23493 useful to track and undo them during QUIT cleanups. */
23494 if (per_cu
->cu
== NULL
)
23497 if (per_cu
->cu
->mark
)
23499 per_cu
->cu
->mark
= 1;
23501 if (per_cu
->cu
->dependencies
!= NULL
)
23502 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23507 /* Set the mark field in CU and in every other compilation unit in the
23508 cache that we must keep because we are keeping CU. */
23511 dwarf2_mark (struct dwarf2_cu
*cu
)
23516 if (cu
->dependencies
!= NULL
)
23517 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23521 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23525 per_cu
->cu
->mark
= 0;
23526 per_cu
= per_cu
->cu
->read_in_chain
;
23530 /* Trivial hash function for partial_die_info: the hash value of a DIE
23531 is its offset in .debug_info for this objfile. */
23534 partial_die_hash (const void *item
)
23536 const struct partial_die_info
*part_die
23537 = (const struct partial_die_info
*) item
;
23539 return to_underlying (part_die
->sect_off
);
23542 /* Trivial comparison function for partial_die_info structures: two DIEs
23543 are equal if they have the same offset. */
23546 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23548 const struct partial_die_info
*part_die_lhs
23549 = (const struct partial_die_info
*) item_lhs
;
23550 const struct partial_die_info
*part_die_rhs
23551 = (const struct partial_die_info
*) item_rhs
;
23553 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23556 static struct cmd_list_element
*set_dwarf_cmdlist
;
23557 static struct cmd_list_element
*show_dwarf_cmdlist
;
23560 set_dwarf_cmd (const char *args
, int from_tty
)
23562 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23567 show_dwarf_cmd (const char *args
, int from_tty
)
23569 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23572 /* Free data associated with OBJFILE, if necessary. */
23575 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
23577 struct dwarf2_per_objfile
*data
= (struct dwarf2_per_objfile
*) d
;
23580 /* Make sure we don't accidentally use dwarf2_per_objfile while
23582 dwarf2_per_objfile
= NULL
;
23584 for (ix
= 0; ix
< data
->n_comp_units
; ++ix
)
23585 VEC_free (dwarf2_per_cu_ptr
, data
->all_comp_units
[ix
]->imported_symtabs
);
23587 for (ix
= 0; ix
< data
->n_type_units
; ++ix
)
23588 VEC_free (dwarf2_per_cu_ptr
,
23589 data
->all_type_units
[ix
]->per_cu
.imported_symtabs
);
23590 xfree (data
->all_type_units
);
23592 VEC_free (dwarf2_section_info_def
, data
->types
);
23594 if (data
->dwo_files
)
23595 free_dwo_files (data
->dwo_files
, objfile
);
23596 if (data
->dwp_file
)
23597 gdb_bfd_unref (data
->dwp_file
->dbfd
);
23599 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
23600 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
23602 if (data
->index_table
!= NULL
)
23603 data
->index_table
->~mapped_index ();
23607 /* The "save gdb-index" command. */
23609 /* In-memory buffer to prepare data to be written later to a file. */
23613 /* Copy DATA to the end of the buffer. */
23614 template<typename T
>
23615 void append_data (const T
&data
)
23617 std::copy (reinterpret_cast<const gdb_byte
*> (&data
),
23618 reinterpret_cast<const gdb_byte
*> (&data
+ 1),
23619 grow (sizeof (data
)));
23622 /* Copy CSTR (a zero-terminated string) to the end of buffer. The
23623 terminating zero is appended too. */
23624 void append_cstr0 (const char *cstr
)
23626 const size_t size
= strlen (cstr
) + 1;
23627 std::copy (cstr
, cstr
+ size
, grow (size
));
23630 /* Accept a host-format integer in VAL and append it to the buffer
23631 as a target-format integer which is LEN bytes long. */
23632 void append_uint (size_t len
, bfd_endian byte_order
, ULONGEST val
)
23634 ::store_unsigned_integer (grow (len
), len
, byte_order
, val
);
23637 /* Return the size of the buffer. */
23638 size_t size () const
23640 return m_vec
.size ();
23643 /* Write the buffer to FILE. */
23644 void file_write (FILE *file
) const
23646 if (::fwrite (m_vec
.data (), 1, m_vec
.size (), file
) != m_vec
.size ())
23647 error (_("couldn't write data to file"));
23651 /* Grow SIZE bytes at the end of the buffer. Returns a pointer to
23652 the start of the new block. */
23653 gdb_byte
*grow (size_t size
)
23655 m_vec
.resize (m_vec
.size () + size
);
23656 return &*m_vec
.end () - size
;
23659 gdb::byte_vector m_vec
;
23662 /* An entry in the symbol table. */
23663 struct symtab_index_entry
23665 /* The name of the symbol. */
23667 /* The offset of the name in the constant pool. */
23668 offset_type index_offset
;
23669 /* A sorted vector of the indices of all the CUs that hold an object
23671 std::vector
<offset_type
> cu_indices
;
23674 /* The symbol table. This is a power-of-2-sized hash table. */
23675 struct mapped_symtab
23679 data
.resize (1024);
23682 offset_type n_elements
= 0;
23683 std::vector
<symtab_index_entry
> data
;
23686 /* Find a slot in SYMTAB for the symbol NAME. Returns a reference to
23689 Function is used only during write_hash_table so no index format backward
23690 compatibility is needed. */
23692 static symtab_index_entry
&
23693 find_slot (struct mapped_symtab
*symtab
, const char *name
)
23695 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
23697 index
= hash
& (symtab
->data
.size () - 1);
23698 step
= ((hash
* 17) & (symtab
->data
.size () - 1)) | 1;
23702 if (symtab
->data
[index
].name
== NULL
23703 || strcmp (name
, symtab
->data
[index
].name
) == 0)
23704 return symtab
->data
[index
];
23705 index
= (index
+ step
) & (symtab
->data
.size () - 1);
23709 /* Expand SYMTAB's hash table. */
23712 hash_expand (struct mapped_symtab
*symtab
)
23714 auto old_entries
= std::move (symtab
->data
);
23716 symtab
->data
.clear ();
23717 symtab
->data
.resize (old_entries
.size () * 2);
23719 for (auto &it
: old_entries
)
23720 if (it
.name
!= NULL
)
23722 auto &ref
= find_slot (symtab
, it
.name
);
23723 ref
= std::move (it
);
23727 /* Add an entry to SYMTAB. NAME is the name of the symbol.
23728 CU_INDEX is the index of the CU in which the symbol appears.
23729 IS_STATIC is one if the symbol is static, otherwise zero (global). */
23732 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
23733 int is_static
, gdb_index_symbol_kind kind
,
23734 offset_type cu_index
)
23736 offset_type cu_index_and_attrs
;
23738 ++symtab
->n_elements
;
23739 if (4 * symtab
->n_elements
/ 3 >= symtab
->data
.size ())
23740 hash_expand (symtab
);
23742 symtab_index_entry
&slot
= find_slot (symtab
, name
);
23743 if (slot
.name
== NULL
)
23746 /* index_offset is set later. */
23749 cu_index_and_attrs
= 0;
23750 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
23751 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
23752 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
23754 /* We don't want to record an index value twice as we want to avoid the
23756 We process all global symbols and then all static symbols
23757 (which would allow us to avoid the duplication by only having to check
23758 the last entry pushed), but a symbol could have multiple kinds in one CU.
23759 To keep things simple we don't worry about the duplication here and
23760 sort and uniqufy the list after we've processed all symbols. */
23761 slot
.cu_indices
.push_back (cu_index_and_attrs
);
23764 /* Sort and remove duplicates of all symbols' cu_indices lists. */
23767 uniquify_cu_indices (struct mapped_symtab
*symtab
)
23769 for (auto &entry
: symtab
->data
)
23771 if (entry
.name
!= NULL
&& !entry
.cu_indices
.empty ())
23773 auto &cu_indices
= entry
.cu_indices
;
23774 std::sort (cu_indices
.begin (), cu_indices
.end ());
23775 auto from
= std::unique (cu_indices
.begin (), cu_indices
.end ());
23776 cu_indices
.erase (from
, cu_indices
.end ());
23781 /* A form of 'const char *' suitable for container keys. Only the
23782 pointer is stored. The strings themselves are compared, not the
23787 c_str_view (const char *cstr
)
23791 bool operator== (const c_str_view
&other
) const
23793 return strcmp (m_cstr
, other
.m_cstr
) == 0;
23797 friend class c_str_view_hasher
;
23798 const char *const m_cstr
;
23801 /* A std::unordered_map::hasher for c_str_view that uses the right
23802 hash function for strings in a mapped index. */
23803 class c_str_view_hasher
23806 size_t operator () (const c_str_view
&x
) const
23808 return mapped_index_string_hash (INT_MAX
, x
.m_cstr
);
23812 /* A std::unordered_map::hasher for std::vector<>. */
23813 template<typename T
>
23814 class vector_hasher
23817 size_t operator () (const std::vector
<T
> &key
) const
23819 return iterative_hash (key
.data (),
23820 sizeof (key
.front ()) * key
.size (), 0);
23824 /* Write the mapped hash table SYMTAB to the data buffer OUTPUT, with
23825 constant pool entries going into the data buffer CPOOL. */
23828 write_hash_table (mapped_symtab
*symtab
, data_buf
&output
, data_buf
&cpool
)
23831 /* Elements are sorted vectors of the indices of all the CUs that
23832 hold an object of this name. */
23833 std::unordered_map
<std::vector
<offset_type
>, offset_type
,
23834 vector_hasher
<offset_type
>>
23837 /* We add all the index vectors to the constant pool first, to
23838 ensure alignment is ok. */
23839 for (symtab_index_entry
&entry
: symtab
->data
)
23841 if (entry
.name
== NULL
)
23843 gdb_assert (entry
.index_offset
== 0);
23845 /* Finding before inserting is faster than always trying to
23846 insert, because inserting always allocates a node, does the
23847 lookup, and then destroys the new node if another node
23848 already had the same key. C++17 try_emplace will avoid
23851 = symbol_hash_table
.find (entry
.cu_indices
);
23852 if (found
!= symbol_hash_table
.end ())
23854 entry
.index_offset
= found
->second
;
23858 symbol_hash_table
.emplace (entry
.cu_indices
, cpool
.size ());
23859 entry
.index_offset
= cpool
.size ();
23860 cpool
.append_data (MAYBE_SWAP (entry
.cu_indices
.size ()));
23861 for (const auto index
: entry
.cu_indices
)
23862 cpool
.append_data (MAYBE_SWAP (index
));
23866 /* Now write out the hash table. */
23867 std::unordered_map
<c_str_view
, offset_type
, c_str_view_hasher
> str_table
;
23868 for (const auto &entry
: symtab
->data
)
23870 offset_type str_off
, vec_off
;
23872 if (entry
.name
!= NULL
)
23874 const auto insertpair
= str_table
.emplace (entry
.name
, cpool
.size ());
23875 if (insertpair
.second
)
23876 cpool
.append_cstr0 (entry
.name
);
23877 str_off
= insertpair
.first
->second
;
23878 vec_off
= entry
.index_offset
;
23882 /* While 0 is a valid constant pool index, it is not valid
23883 to have 0 for both offsets. */
23888 output
.append_data (MAYBE_SWAP (str_off
));
23889 output
.append_data (MAYBE_SWAP (vec_off
));
23893 typedef std::unordered_map
<partial_symtab
*, unsigned int> psym_index_map
;
23895 /* Helper struct for building the address table. */
23896 struct addrmap_index_data
23898 addrmap_index_data (data_buf
&addr_vec_
, psym_index_map
&cu_index_htab_
)
23899 : addr_vec (addr_vec_
), cu_index_htab (cu_index_htab_
)
23902 struct objfile
*objfile
;
23903 data_buf
&addr_vec
;
23904 psym_index_map
&cu_index_htab
;
23906 /* Non-zero if the previous_* fields are valid.
23907 We can't write an entry until we see the next entry (since it is only then
23908 that we know the end of the entry). */
23909 int previous_valid
;
23910 /* Index of the CU in the table of all CUs in the index file. */
23911 unsigned int previous_cu_index
;
23912 /* Start address of the CU. */
23913 CORE_ADDR previous_cu_start
;
23916 /* Write an address entry to ADDR_VEC. */
23919 add_address_entry (struct objfile
*objfile
, data_buf
&addr_vec
,
23920 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
23922 CORE_ADDR baseaddr
;
23924 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23926 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
23927 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
23928 addr_vec
.append_data (MAYBE_SWAP (cu_index
));
23931 /* Worker function for traversing an addrmap to build the address table. */
23934 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
23936 struct addrmap_index_data
*data
= (struct addrmap_index_data
*) datap
;
23937 struct partial_symtab
*pst
= (struct partial_symtab
*) obj
;
23939 if (data
->previous_valid
)
23940 add_address_entry (data
->objfile
, data
->addr_vec
,
23941 data
->previous_cu_start
, start_addr
,
23942 data
->previous_cu_index
);
23944 data
->previous_cu_start
= start_addr
;
23947 const auto it
= data
->cu_index_htab
.find (pst
);
23948 gdb_assert (it
!= data
->cu_index_htab
.cend ());
23949 data
->previous_cu_index
= it
->second
;
23950 data
->previous_valid
= 1;
23953 data
->previous_valid
= 0;
23958 /* Write OBJFILE's address map to ADDR_VEC.
23959 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
23960 in the index file. */
23963 write_address_map (struct objfile
*objfile
, data_buf
&addr_vec
,
23964 psym_index_map
&cu_index_htab
)
23966 struct addrmap_index_data
addrmap_index_data (addr_vec
, cu_index_htab
);
23968 /* When writing the address table, we have to cope with the fact that
23969 the addrmap iterator only provides the start of a region; we have to
23970 wait until the next invocation to get the start of the next region. */
23972 addrmap_index_data
.objfile
= objfile
;
23973 addrmap_index_data
.previous_valid
= 0;
23975 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
23976 &addrmap_index_data
);
23978 /* It's highly unlikely the last entry (end address = 0xff...ff)
23979 is valid, but we should still handle it.
23980 The end address is recorded as the start of the next region, but that
23981 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
23983 if (addrmap_index_data
.previous_valid
)
23984 add_address_entry (objfile
, addr_vec
,
23985 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
23986 addrmap_index_data
.previous_cu_index
);
23989 /* Return the symbol kind of PSYM. */
23991 static gdb_index_symbol_kind
23992 symbol_kind (struct partial_symbol
*psym
)
23994 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
23995 enum address_class aclass
= PSYMBOL_CLASS (psym
);
24003 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
24005 return GDB_INDEX_SYMBOL_KIND_TYPE
;
24007 case LOC_CONST_BYTES
:
24008 case LOC_OPTIMIZED_OUT
:
24010 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
24012 /* Note: It's currently impossible to recognize psyms as enum values
24013 short of reading the type info. For now punt. */
24014 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
24016 /* There are other LOC_FOO values that one might want to classify
24017 as variables, but dwarf2read.c doesn't currently use them. */
24018 return GDB_INDEX_SYMBOL_KIND_OTHER
;
24020 case STRUCT_DOMAIN
:
24021 return GDB_INDEX_SYMBOL_KIND_TYPE
;
24023 return GDB_INDEX_SYMBOL_KIND_OTHER
;
24027 /* Add a list of partial symbols to SYMTAB. */
24030 write_psymbols (struct mapped_symtab
*symtab
,
24031 std::unordered_set
<partial_symbol
*> &psyms_seen
,
24032 struct partial_symbol
**psymp
,
24034 offset_type cu_index
,
24037 for (; count
-- > 0; ++psymp
)
24039 struct partial_symbol
*psym
= *psymp
;
24041 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
24042 error (_("Ada is not currently supported by the index"));
24044 /* Only add a given psymbol once. */
24045 if (psyms_seen
.insert (psym
).second
)
24047 gdb_index_symbol_kind kind
= symbol_kind (psym
);
24049 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
24050 is_static
, kind
, cu_index
);
24055 /* A helper struct used when iterating over debug_types. */
24056 struct signatured_type_index_data
24058 signatured_type_index_data (data_buf
&types_list_
,
24059 std::unordered_set
<partial_symbol
*> &psyms_seen_
)
24060 : types_list (types_list_
), psyms_seen (psyms_seen_
)
24063 struct objfile
*objfile
;
24064 struct mapped_symtab
*symtab
;
24065 data_buf
&types_list
;
24066 std::unordered_set
<partial_symbol
*> &psyms_seen
;
24070 /* A helper function that writes a single signatured_type to an
24074 write_one_signatured_type (void **slot
, void *d
)
24076 struct signatured_type_index_data
*info
24077 = (struct signatured_type_index_data
*) d
;
24078 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
24079 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
24081 write_psymbols (info
->symtab
,
24083 &info
->objfile
->global_psymbols
[psymtab
->globals_offset
],
24084 psymtab
->n_global_syms
, info
->cu_index
,
24086 write_psymbols (info
->symtab
,
24088 &info
->objfile
->static_psymbols
[psymtab
->statics_offset
],
24089 psymtab
->n_static_syms
, info
->cu_index
,
24092 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
24093 to_underlying (entry
->per_cu
.sect_off
));
24094 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
24095 to_underlying (entry
->type_offset_in_tu
));
24096 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
, entry
->signature
);
24103 /* Recurse into all "included" dependencies and count their symbols as
24104 if they appeared in this psymtab. */
24107 recursively_count_psymbols (struct partial_symtab
*psymtab
,
24108 size_t &psyms_seen
)
24110 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
24111 if (psymtab
->dependencies
[i
]->user
!= NULL
)
24112 recursively_count_psymbols (psymtab
->dependencies
[i
],
24115 psyms_seen
+= psymtab
->n_global_syms
;
24116 psyms_seen
+= psymtab
->n_static_syms
;
24119 /* Recurse into all "included" dependencies and write their symbols as
24120 if they appeared in this psymtab. */
24123 recursively_write_psymbols (struct objfile
*objfile
,
24124 struct partial_symtab
*psymtab
,
24125 struct mapped_symtab
*symtab
,
24126 std::unordered_set
<partial_symbol
*> &psyms_seen
,
24127 offset_type cu_index
)
24131 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
24132 if (psymtab
->dependencies
[i
]->user
!= NULL
)
24133 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
24134 symtab
, psyms_seen
, cu_index
);
24136 write_psymbols (symtab
,
24138 &objfile
->global_psymbols
[psymtab
->globals_offset
],
24139 psymtab
->n_global_syms
, cu_index
,
24141 write_psymbols (symtab
,
24143 &objfile
->static_psymbols
[psymtab
->statics_offset
],
24144 psymtab
->n_static_syms
, cu_index
,
24148 /* Create an index file for OBJFILE in the directory DIR. */
24151 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
24153 if (dwarf2_per_objfile
->using_index
)
24154 error (_("Cannot use an index to create the index"));
24156 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
24157 error (_("Cannot make an index when the file has multiple .debug_types sections"));
24159 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
24163 if (stat (objfile_name (objfile
), &st
) < 0)
24164 perror_with_name (objfile_name (objfile
));
24166 std::string
filename (std::string (dir
) + SLASH_STRING
24167 + lbasename (objfile_name (objfile
)) + INDEX_SUFFIX
);
24169 FILE *out_file
= gdb_fopen_cloexec (filename
.c_str (), "wb").release ();
24171 error (_("Can't open `%s' for writing"), filename
.c_str ());
24173 /* Order matters here; we want FILE to be closed before FILENAME is
24174 unlinked, because on MS-Windows one cannot delete a file that is
24175 still open. (Don't call anything here that might throw until
24176 file_closer is created.) */
24177 gdb::unlinker
unlink_file (filename
.c_str ());
24178 gdb_file_up
close_out_file (out_file
);
24180 mapped_symtab symtab
;
24183 /* While we're scanning CU's create a table that maps a psymtab pointer
24184 (which is what addrmap records) to its index (which is what is recorded
24185 in the index file). This will later be needed to write the address
24187 psym_index_map cu_index_htab
;
24188 cu_index_htab
.reserve (dwarf2_per_objfile
->n_comp_units
);
24190 /* The CU list is already sorted, so we don't need to do additional
24191 work here. Also, the debug_types entries do not appear in
24192 all_comp_units, but only in their own hash table. */
24194 /* The psyms_seen set is potentially going to be largish (~40k
24195 elements when indexing a -g3 build of GDB itself). Estimate the
24196 number of elements in order to avoid too many rehashes, which
24197 require rebuilding buckets and thus many trips to
24199 size_t psyms_count
= 0;
24200 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
24202 struct dwarf2_per_cu_data
*per_cu
24203 = dwarf2_per_objfile
->all_comp_units
[i
];
24204 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
24206 if (psymtab
!= NULL
&& psymtab
->user
== NULL
)
24207 recursively_count_psymbols (psymtab
, psyms_count
);
24209 /* Generating an index for gdb itself shows a ratio of
24210 TOTAL_SEEN_SYMS/UNIQUE_SYMS or ~5. 4 seems like a good bet. */
24211 std::unordered_set
<partial_symbol
*> psyms_seen (psyms_count
/ 4);
24212 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
24214 struct dwarf2_per_cu_data
*per_cu
24215 = dwarf2_per_objfile
->all_comp_units
[i
];
24216 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
24218 /* CU of a shared file from 'dwz -m' may be unused by this main file.
24219 It may be referenced from a local scope but in such case it does not
24220 need to be present in .gdb_index. */
24221 if (psymtab
== NULL
)
24224 if (psymtab
->user
== NULL
)
24225 recursively_write_psymbols (objfile
, psymtab
, &symtab
,
24228 const auto insertpair
= cu_index_htab
.emplace (psymtab
, i
);
24229 gdb_assert (insertpair
.second
);
24231 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
24232 to_underlying (per_cu
->sect_off
));
24233 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
24236 /* Dump the address map. */
24238 write_address_map (objfile
, addr_vec
, cu_index_htab
);
24240 /* Write out the .debug_type entries, if any. */
24241 data_buf types_cu_list
;
24242 if (dwarf2_per_objfile
->signatured_types
)
24244 signatured_type_index_data
sig_data (types_cu_list
,
24247 sig_data
.objfile
= objfile
;
24248 sig_data
.symtab
= &symtab
;
24249 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
24250 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
24251 write_one_signatured_type
, &sig_data
);
24254 /* Now that we've processed all symbols we can shrink their cu_indices
24256 uniquify_cu_indices (&symtab
);
24258 data_buf symtab_vec
, constant_pool
;
24259 write_hash_table (&symtab
, symtab_vec
, constant_pool
);
24262 const offset_type size_of_contents
= 6 * sizeof (offset_type
);
24263 offset_type total_len
= size_of_contents
;
24265 /* The version number. */
24266 contents
.append_data (MAYBE_SWAP (8));
24268 /* The offset of the CU list from the start of the file. */
24269 contents
.append_data (MAYBE_SWAP (total_len
));
24270 total_len
+= cu_list
.size ();
24272 /* The offset of the types CU list from the start of the file. */
24273 contents
.append_data (MAYBE_SWAP (total_len
));
24274 total_len
+= types_cu_list
.size ();
24276 /* The offset of the address table from the start of the file. */
24277 contents
.append_data (MAYBE_SWAP (total_len
));
24278 total_len
+= addr_vec
.size ();
24280 /* The offset of the symbol table from the start of the file. */
24281 contents
.append_data (MAYBE_SWAP (total_len
));
24282 total_len
+= symtab_vec
.size ();
24284 /* The offset of the constant pool from the start of the file. */
24285 contents
.append_data (MAYBE_SWAP (total_len
));
24286 total_len
+= constant_pool
.size ();
24288 gdb_assert (contents
.size () == size_of_contents
);
24290 contents
.file_write (out_file
);
24291 cu_list
.file_write (out_file
);
24292 types_cu_list
.file_write (out_file
);
24293 addr_vec
.file_write (out_file
);
24294 symtab_vec
.file_write (out_file
);
24295 constant_pool
.file_write (out_file
);
24297 /* We want to keep the file. */
24298 unlink_file
.keep ();
24301 /* Implementation of the `save gdb-index' command.
24303 Note that the file format used by this command is documented in the
24304 GDB manual. Any changes here must be documented there. */
24307 save_gdb_index_command (const char *arg
, int from_tty
)
24309 struct objfile
*objfile
;
24312 error (_("usage: save gdb-index DIRECTORY"));
24314 ALL_OBJFILES (objfile
)
24318 /* If the objfile does not correspond to an actual file, skip it. */
24319 if (stat (objfile_name (objfile
), &st
) < 0)
24323 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
24324 dwarf2_objfile_data_key
);
24325 if (dwarf2_per_objfile
)
24330 write_psymtabs_to_index (objfile
, arg
);
24332 CATCH (except
, RETURN_MASK_ERROR
)
24334 exception_fprintf (gdb_stderr
, except
,
24335 _("Error while writing index for `%s': "),
24336 objfile_name (objfile
));
24345 int dwarf_always_disassemble
;
24348 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
24349 struct cmd_list_element
*c
, const char *value
)
24351 fprintf_filtered (file
,
24352 _("Whether to always disassemble "
24353 "DWARF expressions is %s.\n"),
24358 show_check_physname (struct ui_file
*file
, int from_tty
,
24359 struct cmd_list_element
*c
, const char *value
)
24361 fprintf_filtered (file
,
24362 _("Whether to check \"physname\" is %s.\n"),
24367 _initialize_dwarf2_read (void)
24369 struct cmd_list_element
*c
;
24371 dwarf2_objfile_data_key
24372 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
24374 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
24375 Set DWARF specific variables.\n\
24376 Configure DWARF variables such as the cache size"),
24377 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24378 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24380 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
24381 Show DWARF specific variables\n\
24382 Show DWARF variables such as the cache size"),
24383 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24384 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24386 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24387 &dwarf_max_cache_age
, _("\
24388 Set the upper bound on the age of cached DWARF compilation units."), _("\
24389 Show the upper bound on the age of cached DWARF compilation units."), _("\
24390 A higher limit means that cached compilation units will be stored\n\
24391 in memory longer, and more total memory will be used. Zero disables\n\
24392 caching, which can slow down startup."),
24394 show_dwarf_max_cache_age
,
24395 &set_dwarf_cmdlist
,
24396 &show_dwarf_cmdlist
);
24398 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
24399 &dwarf_always_disassemble
, _("\
24400 Set whether `info address' always disassembles DWARF expressions."), _("\
24401 Show whether `info address' always disassembles DWARF expressions."), _("\
24402 When enabled, DWARF expressions are always printed in an assembly-like\n\
24403 syntax. When disabled, expressions will be printed in a more\n\
24404 conversational style, when possible."),
24406 show_dwarf_always_disassemble
,
24407 &set_dwarf_cmdlist
,
24408 &show_dwarf_cmdlist
);
24410 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24411 Set debugging of the DWARF reader."), _("\
24412 Show debugging of the DWARF reader."), _("\
24413 When enabled (non-zero), debugging messages are printed during DWARF\n\
24414 reading and symtab expansion. A value of 1 (one) provides basic\n\
24415 information. A value greater than 1 provides more verbose information."),
24418 &setdebuglist
, &showdebuglist
);
24420 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24421 Set debugging of the DWARF DIE reader."), _("\
24422 Show debugging of the DWARF DIE reader."), _("\
24423 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24424 The value is the maximum depth to print."),
24427 &setdebuglist
, &showdebuglist
);
24429 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24430 Set debugging of the dwarf line reader."), _("\
24431 Show debugging of the dwarf line reader."), _("\
24432 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24433 A value of 1 (one) provides basic information.\n\
24434 A value greater than 1 provides more verbose information."),
24437 &setdebuglist
, &showdebuglist
);
24439 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24440 Set cross-checking of \"physname\" code against demangler."), _("\
24441 Show cross-checking of \"physname\" code against demangler."), _("\
24442 When enabled, GDB's internal \"physname\" code is checked against\n\
24444 NULL
, show_check_physname
,
24445 &setdebuglist
, &showdebuglist
);
24447 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24448 no_class
, &use_deprecated_index_sections
, _("\
24449 Set whether to use deprecated gdb_index sections."), _("\
24450 Show whether to use deprecated gdb_index sections."), _("\
24451 When enabled, deprecated .gdb_index sections are used anyway.\n\
24452 Normally they are ignored either because of a missing feature or\n\
24453 performance issue.\n\
24454 Warning: This option must be enabled before gdb reads the file."),
24457 &setlist
, &showlist
);
24459 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
24461 Save a gdb-index file.\n\
24462 Usage: save gdb-index DIRECTORY"),
24464 set_cmd_completer (c
, filename_completer
);
24466 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24467 &dwarf2_locexpr_funcs
);
24468 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24469 &dwarf2_loclist_funcs
);
24471 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24472 &dwarf2_block_frame_base_locexpr_funcs
);
24473 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24474 &dwarf2_block_frame_base_loclist_funcs
);