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)); \
185 /* A description of the mapped index. The file format is described in
186 a comment by the code that writes the index. */
189 /* Index data format version. */
192 /* The total length of the buffer. */
195 /* A pointer to the address table data. */
196 const gdb_byte
*address_table
;
198 /* Size of the address table data in bytes. */
199 offset_type address_table_size
;
201 /* The symbol table, implemented as a hash table. */
202 const offset_type
*symbol_table
;
204 /* Size in slots, each slot is 2 offset_types. */
205 offset_type symbol_table_slots
;
207 /* A pointer to the constant pool. */
208 const char *constant_pool
;
211 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
212 DEF_VEC_P (dwarf2_per_cu_ptr
);
216 int nr_uniq_abbrev_tables
;
218 int nr_symtab_sharers
;
219 int nr_stmt_less_type_units
;
220 int nr_all_type_units_reallocs
;
223 /* Collection of data recorded per objfile.
224 This hangs off of dwarf2_objfile_data_key. */
226 struct dwarf2_per_objfile
228 /* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the
229 dwarf2 section names, or is NULL if the standard ELF names are
231 dwarf2_per_objfile (struct objfile
*objfile
,
232 const dwarf2_debug_sections
*names
);
234 ~dwarf2_per_objfile ();
236 DISABLE_COPY_AND_ASSIGN (dwarf2_per_objfile
);
238 /* Free all cached compilation units. */
239 void free_cached_comp_units ();
241 /* This function is mapped across the sections and remembers the
242 offset and size of each of the debugging sections we are
244 void locate_sections (bfd
*abfd
, asection
*sectp
,
245 const dwarf2_debug_sections
&names
);
248 dwarf2_section_info info
{};
249 dwarf2_section_info abbrev
{};
250 dwarf2_section_info line
{};
251 dwarf2_section_info loc
{};
252 dwarf2_section_info loclists
{};
253 dwarf2_section_info macinfo
{};
254 dwarf2_section_info macro
{};
255 dwarf2_section_info str
{};
256 dwarf2_section_info line_str
{};
257 dwarf2_section_info ranges
{};
258 dwarf2_section_info rnglists
{};
259 dwarf2_section_info addr
{};
260 dwarf2_section_info frame
{};
261 dwarf2_section_info eh_frame
{};
262 dwarf2_section_info gdb_index
{};
264 VEC (dwarf2_section_info_def
) *types
= NULL
;
267 struct objfile
*objfile
= NULL
;
269 /* Table of all the compilation units. This is used to locate
270 the target compilation unit of a particular reference. */
271 struct dwarf2_per_cu_data
**all_comp_units
= NULL
;
273 /* The number of compilation units in ALL_COMP_UNITS. */
274 int n_comp_units
= 0;
276 /* The number of .debug_types-related CUs. */
277 int n_type_units
= 0;
279 /* The number of elements allocated in all_type_units.
280 If there are skeleton-less TUs, we add them to all_type_units lazily. */
281 int n_allocated_type_units
= 0;
283 /* The .debug_types-related CUs (TUs).
284 This is stored in malloc space because we may realloc it. */
285 struct signatured_type
**all_type_units
= NULL
;
287 /* Table of struct type_unit_group objects.
288 The hash key is the DW_AT_stmt_list value. */
289 htab_t type_unit_groups
{};
291 /* A table mapping .debug_types signatures to its signatured_type entry.
292 This is NULL if the .debug_types section hasn't been read in yet. */
293 htab_t signatured_types
{};
295 /* Type unit statistics, to see how well the scaling improvements
297 struct tu_stats tu_stats
{};
299 /* A chain of compilation units that are currently read in, so that
300 they can be freed later. */
301 dwarf2_per_cu_data
*read_in_chain
= NULL
;
303 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
304 This is NULL if the table hasn't been allocated yet. */
307 /* True if we've checked for whether there is a DWP file. */
308 bool dwp_checked
= false;
310 /* The DWP file if there is one, or NULL. */
311 struct dwp_file
*dwp_file
= NULL
;
313 /* The shared '.dwz' file, if one exists. This is used when the
314 original data was compressed using 'dwz -m'. */
315 struct dwz_file
*dwz_file
= NULL
;
317 /* A flag indicating whether this objfile has a section loaded at a
319 bool has_section_at_zero
= false;
321 /* True if we are using the mapped index,
322 or we are faking it for OBJF_READNOW's sake. */
323 bool using_index
= false;
325 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
326 mapped_index
*index_table
= NULL
;
328 /* When using index_table, this keeps track of all quick_file_names entries.
329 TUs typically share line table entries with a CU, so we maintain a
330 separate table of all line table entries to support the sharing.
331 Note that while there can be way more TUs than CUs, we've already
332 sorted all the TUs into "type unit groups", grouped by their
333 DW_AT_stmt_list value. Therefore the only sharing done here is with a
334 CU and its associated TU group if there is one. */
335 htab_t quick_file_names_table
{};
337 /* Set during partial symbol reading, to prevent queueing of full
339 bool reading_partial_symbols
= false;
341 /* Table mapping type DIEs to their struct type *.
342 This is NULL if not allocated yet.
343 The mapping is done via (CU/TU + DIE offset) -> type. */
344 htab_t die_type_hash
{};
346 /* The CUs we recently read. */
347 VEC (dwarf2_per_cu_ptr
) *just_read_cus
= NULL
;
349 /* Table containing line_header indexed by offset and offset_in_dwz. */
350 htab_t line_header_hash
{};
352 /* Table containing all filenames. This is an optional because the
353 table is lazily constructed on first access. */
354 gdb::optional
<filename_seen_cache
> filenames_cache
;
357 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
359 /* Default names of the debugging sections. */
361 /* Note that if the debugging section has been compressed, it might
362 have a name like .zdebug_info. */
364 static const struct dwarf2_debug_sections dwarf2_elf_names
=
366 { ".debug_info", ".zdebug_info" },
367 { ".debug_abbrev", ".zdebug_abbrev" },
368 { ".debug_line", ".zdebug_line" },
369 { ".debug_loc", ".zdebug_loc" },
370 { ".debug_loclists", ".zdebug_loclists" },
371 { ".debug_macinfo", ".zdebug_macinfo" },
372 { ".debug_macro", ".zdebug_macro" },
373 { ".debug_str", ".zdebug_str" },
374 { ".debug_line_str", ".zdebug_line_str" },
375 { ".debug_ranges", ".zdebug_ranges" },
376 { ".debug_rnglists", ".zdebug_rnglists" },
377 { ".debug_types", ".zdebug_types" },
378 { ".debug_addr", ".zdebug_addr" },
379 { ".debug_frame", ".zdebug_frame" },
380 { ".eh_frame", NULL
},
381 { ".gdb_index", ".zgdb_index" },
385 /* List of DWO/DWP sections. */
387 static const struct dwop_section_names
389 struct dwarf2_section_names abbrev_dwo
;
390 struct dwarf2_section_names info_dwo
;
391 struct dwarf2_section_names line_dwo
;
392 struct dwarf2_section_names loc_dwo
;
393 struct dwarf2_section_names loclists_dwo
;
394 struct dwarf2_section_names macinfo_dwo
;
395 struct dwarf2_section_names macro_dwo
;
396 struct dwarf2_section_names str_dwo
;
397 struct dwarf2_section_names str_offsets_dwo
;
398 struct dwarf2_section_names types_dwo
;
399 struct dwarf2_section_names cu_index
;
400 struct dwarf2_section_names tu_index
;
404 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
405 { ".debug_info.dwo", ".zdebug_info.dwo" },
406 { ".debug_line.dwo", ".zdebug_line.dwo" },
407 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
408 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
409 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
410 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
411 { ".debug_str.dwo", ".zdebug_str.dwo" },
412 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
413 { ".debug_types.dwo", ".zdebug_types.dwo" },
414 { ".debug_cu_index", ".zdebug_cu_index" },
415 { ".debug_tu_index", ".zdebug_tu_index" },
418 /* local data types */
420 /* The data in a compilation unit header, after target2host
421 translation, looks like this. */
422 struct comp_unit_head
426 unsigned char addr_size
;
427 unsigned char signed_addr_p
;
428 sect_offset abbrev_sect_off
;
430 /* Size of file offsets; either 4 or 8. */
431 unsigned int offset_size
;
433 /* Size of the length field; either 4 or 12. */
434 unsigned int initial_length_size
;
436 enum dwarf_unit_type unit_type
;
438 /* Offset to the first byte of this compilation unit header in the
439 .debug_info section, for resolving relative reference dies. */
440 sect_offset sect_off
;
442 /* Offset to first die in this cu from the start of the cu.
443 This will be the first byte following the compilation unit header. */
444 cu_offset first_die_cu_offset
;
446 /* 64-bit signature of this type unit - it is valid only for
447 UNIT_TYPE DW_UT_type. */
450 /* For types, offset in the type's DIE of the type defined by this TU. */
451 cu_offset type_cu_offset_in_tu
;
454 /* Type used for delaying computation of method physnames.
455 See comments for compute_delayed_physnames. */
456 struct delayed_method_info
458 /* The type to which the method is attached, i.e., its parent class. */
461 /* The index of the method in the type's function fieldlists. */
464 /* The index of the method in the fieldlist. */
467 /* The name of the DIE. */
470 /* The DIE associated with this method. */
471 struct die_info
*die
;
474 typedef struct delayed_method_info delayed_method_info
;
475 DEF_VEC_O (delayed_method_info
);
477 /* Internal state when decoding a particular compilation unit. */
480 /* The objfile containing this compilation unit. */
481 struct objfile
*objfile
;
483 /* The header of the compilation unit. */
484 struct comp_unit_head header
;
486 /* Base address of this compilation unit. */
487 CORE_ADDR base_address
;
489 /* Non-zero if base_address has been set. */
492 /* The language we are debugging. */
493 enum language language
;
494 const struct language_defn
*language_defn
;
496 const char *producer
;
498 /* The generic symbol table building routines have separate lists for
499 file scope symbols and all all other scopes (local scopes). So
500 we need to select the right one to pass to add_symbol_to_list().
501 We do it by keeping a pointer to the correct list in list_in_scope.
503 FIXME: The original dwarf code just treated the file scope as the
504 first local scope, and all other local scopes as nested local
505 scopes, and worked fine. Check to see if we really need to
506 distinguish these in buildsym.c. */
507 struct pending
**list_in_scope
;
509 /* The abbrev table for this CU.
510 Normally this points to the abbrev table in the objfile.
511 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
512 struct abbrev_table
*abbrev_table
;
514 /* Hash table holding all the loaded partial DIEs
515 with partial_die->offset.SECT_OFF as hash. */
518 /* Storage for things with the same lifetime as this read-in compilation
519 unit, including partial DIEs. */
520 struct obstack comp_unit_obstack
;
522 /* When multiple dwarf2_cu structures are living in memory, this field
523 chains them all together, so that they can be released efficiently.
524 We will probably also want a generation counter so that most-recently-used
525 compilation units are cached... */
526 struct dwarf2_per_cu_data
*read_in_chain
;
528 /* Backlink to our per_cu entry. */
529 struct dwarf2_per_cu_data
*per_cu
;
531 /* How many compilation units ago was this CU last referenced? */
534 /* A hash table of DIE cu_offset for following references with
535 die_info->offset.sect_off as hash. */
538 /* Full DIEs if read in. */
539 struct die_info
*dies
;
541 /* A set of pointers to dwarf2_per_cu_data objects for compilation
542 units referenced by this one. Only set during full symbol processing;
543 partial symbol tables do not have dependencies. */
546 /* Header data from the line table, during full symbol processing. */
547 struct line_header
*line_header
;
548 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
549 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
550 this is the DW_TAG_compile_unit die for this CU. We'll hold on
551 to the line header as long as this DIE is being processed. See
552 process_die_scope. */
553 die_info
*line_header_die_owner
;
555 /* A list of methods which need to have physnames computed
556 after all type information has been read. */
557 VEC (delayed_method_info
) *method_list
;
559 /* To be copied to symtab->call_site_htab. */
560 htab_t call_site_htab
;
562 /* Non-NULL if this CU came from a DWO file.
563 There is an invariant here that is important to remember:
564 Except for attributes copied from the top level DIE in the "main"
565 (or "stub") file in preparation for reading the DWO file
566 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
567 Either there isn't a DWO file (in which case this is NULL and the point
568 is moot), or there is and either we're not going to read it (in which
569 case this is NULL) or there is and we are reading it (in which case this
571 struct dwo_unit
*dwo_unit
;
573 /* The DW_AT_addr_base attribute if present, zero otherwise
574 (zero is a valid value though).
575 Note this value comes from the Fission stub CU/TU's DIE. */
578 /* The DW_AT_ranges_base attribute if present, zero otherwise
579 (zero is a valid value though).
580 Note this value comes from the Fission stub CU/TU's DIE.
581 Also note that the value is zero in the non-DWO case so this value can
582 be used without needing to know whether DWO files are in use or not.
583 N.B. This does not apply to DW_AT_ranges appearing in
584 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
585 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
586 DW_AT_ranges_base *would* have to be applied, and we'd have to care
587 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
588 ULONGEST ranges_base
;
590 /* Mark used when releasing cached dies. */
591 unsigned int mark
: 1;
593 /* This CU references .debug_loc. See the symtab->locations_valid field.
594 This test is imperfect as there may exist optimized debug code not using
595 any location list and still facing inlining issues if handled as
596 unoptimized code. For a future better test see GCC PR other/32998. */
597 unsigned int has_loclist
: 1;
599 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
600 if all the producer_is_* fields are valid. This information is cached
601 because profiling CU expansion showed excessive time spent in
602 producer_is_gxx_lt_4_6. */
603 unsigned int checked_producer
: 1;
604 unsigned int producer_is_gxx_lt_4_6
: 1;
605 unsigned int producer_is_gcc_lt_4_3
: 1;
606 unsigned int producer_is_icc_lt_14
: 1;
608 /* When set, the file that we're processing is known to have
609 debugging info for C++ namespaces. GCC 3.3.x did not produce
610 this information, but later versions do. */
612 unsigned int processing_has_namespace_info
: 1;
615 /* Persistent data held for a compilation unit, even when not
616 processing it. We put a pointer to this structure in the
617 read_symtab_private field of the psymtab. */
619 struct dwarf2_per_cu_data
621 /* The start offset and length of this compilation unit.
622 NOTE: Unlike comp_unit_head.length, this length includes
624 If the DIE refers to a DWO file, this is always of the original die,
626 sect_offset sect_off
;
629 /* DWARF standard version this data has been read from (such as 4 or 5). */
632 /* Flag indicating this compilation unit will be read in before
633 any of the current compilation units are processed. */
634 unsigned int queued
: 1;
636 /* This flag will be set when reading partial DIEs if we need to load
637 absolutely all DIEs for this compilation unit, instead of just the ones
638 we think are interesting. It gets set if we look for a DIE in the
639 hash table and don't find it. */
640 unsigned int load_all_dies
: 1;
642 /* Non-zero if this CU is from .debug_types.
643 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
645 unsigned int is_debug_types
: 1;
647 /* Non-zero if this CU is from the .dwz file. */
648 unsigned int is_dwz
: 1;
650 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
651 This flag is only valid if is_debug_types is true.
652 We can't read a CU directly from a DWO file: There are required
653 attributes in the stub. */
654 unsigned int reading_dwo_directly
: 1;
656 /* Non-zero if the TU has been read.
657 This is used to assist the "Stay in DWO Optimization" for Fission:
658 When reading a DWO, it's faster to read TUs from the DWO instead of
659 fetching them from random other DWOs (due to comdat folding).
660 If the TU has already been read, the optimization is unnecessary
661 (and unwise - we don't want to change where gdb thinks the TU lives
663 This flag is only valid if is_debug_types is true. */
664 unsigned int tu_read
: 1;
666 /* The section this CU/TU lives in.
667 If the DIE refers to a DWO file, this is always the original die,
669 struct dwarf2_section_info
*section
;
671 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
672 of the CU cache it gets reset to NULL again. This is left as NULL for
673 dummy CUs (a CU header, but nothing else). */
674 struct dwarf2_cu
*cu
;
676 /* The corresponding objfile.
677 Normally we can get the objfile from dwarf2_per_objfile.
678 However we can enter this file with just a "per_cu" handle. */
679 struct objfile
*objfile
;
681 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
682 is active. Otherwise, the 'psymtab' field is active. */
685 /* The partial symbol table associated with this compilation unit,
686 or NULL for unread partial units. */
687 struct partial_symtab
*psymtab
;
689 /* Data needed by the "quick" functions. */
690 struct dwarf2_per_cu_quick_data
*quick
;
693 /* The CUs we import using DW_TAG_imported_unit. This is filled in
694 while reading psymtabs, used to compute the psymtab dependencies,
695 and then cleared. Then it is filled in again while reading full
696 symbols, and only deleted when the objfile is destroyed.
698 This is also used to work around a difference between the way gold
699 generates .gdb_index version <=7 and the way gdb does. Arguably this
700 is a gold bug. For symbols coming from TUs, gold records in the index
701 the CU that includes the TU instead of the TU itself. This breaks
702 dw2_lookup_symbol: It assumes that if the index says symbol X lives
703 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
704 will find X. Alas TUs live in their own symtab, so after expanding CU Y
705 we need to look in TU Z to find X. Fortunately, this is akin to
706 DW_TAG_imported_unit, so we just use the same mechanism: For
707 .gdb_index version <=7 this also records the TUs that the CU referred
708 to. Concurrently with this change gdb was modified to emit version 8
709 indices so we only pay a price for gold generated indices.
710 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
711 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
714 /* Entry in the signatured_types hash table. */
716 struct signatured_type
718 /* The "per_cu" object of this type.
719 This struct is used iff per_cu.is_debug_types.
720 N.B.: This is the first member so that it's easy to convert pointers
722 struct dwarf2_per_cu_data per_cu
;
724 /* The type's signature. */
727 /* Offset in the TU of the type's DIE, as read from the TU header.
728 If this TU is a DWO stub and the definition lives in a DWO file
729 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
730 cu_offset type_offset_in_tu
;
732 /* Offset in the section of the type's DIE.
733 If the definition lives in a DWO file, this is the offset in the
734 .debug_types.dwo section.
735 The value is zero until the actual value is known.
736 Zero is otherwise not a valid section offset. */
737 sect_offset type_offset_in_section
;
739 /* Type units are grouped by their DW_AT_stmt_list entry so that they
740 can share them. This points to the containing symtab. */
741 struct type_unit_group
*type_unit_group
;
744 The first time we encounter this type we fully read it in and install it
745 in the symbol tables. Subsequent times we only need the type. */
748 /* Containing DWO unit.
749 This field is valid iff per_cu.reading_dwo_directly. */
750 struct dwo_unit
*dwo_unit
;
753 typedef struct signatured_type
*sig_type_ptr
;
754 DEF_VEC_P (sig_type_ptr
);
756 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
757 This includes type_unit_group and quick_file_names. */
759 struct stmt_list_hash
761 /* The DWO unit this table is from or NULL if there is none. */
762 struct dwo_unit
*dwo_unit
;
764 /* Offset in .debug_line or .debug_line.dwo. */
765 sect_offset line_sect_off
;
768 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
769 an object of this type. */
771 struct type_unit_group
773 /* dwarf2read.c's main "handle" on a TU symtab.
774 To simplify things we create an artificial CU that "includes" all the
775 type units using this stmt_list so that the rest of the code still has
776 a "per_cu" handle on the symtab.
777 This PER_CU is recognized by having no section. */
778 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
779 struct dwarf2_per_cu_data per_cu
;
781 /* The TUs that share this DW_AT_stmt_list entry.
782 This is added to while parsing type units to build partial symtabs,
783 and is deleted afterwards and not used again. */
784 VEC (sig_type_ptr
) *tus
;
786 /* The compunit symtab.
787 Type units in a group needn't all be defined in the same source file,
788 so we create an essentially anonymous symtab as the compunit symtab. */
789 struct compunit_symtab
*compunit_symtab
;
791 /* The data used to construct the hash key. */
792 struct stmt_list_hash hash
;
794 /* The number of symtabs from the line header.
795 The value here must match line_header.num_file_names. */
796 unsigned int num_symtabs
;
798 /* The symbol tables for this TU (obtained from the files listed in
800 WARNING: The order of entries here must match the order of entries
801 in the line header. After the first TU using this type_unit_group, the
802 line header for the subsequent TUs is recreated from this. This is done
803 because we need to use the same symtabs for each TU using the same
804 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
805 there's no guarantee the line header doesn't have duplicate entries. */
806 struct symtab
**symtabs
;
809 /* These sections are what may appear in a (real or virtual) DWO file. */
813 struct dwarf2_section_info abbrev
;
814 struct dwarf2_section_info line
;
815 struct dwarf2_section_info loc
;
816 struct dwarf2_section_info loclists
;
817 struct dwarf2_section_info macinfo
;
818 struct dwarf2_section_info macro
;
819 struct dwarf2_section_info str
;
820 struct dwarf2_section_info str_offsets
;
821 /* In the case of a virtual DWO file, these two are unused. */
822 struct dwarf2_section_info info
;
823 VEC (dwarf2_section_info_def
) *types
;
826 /* CUs/TUs in DWP/DWO files. */
830 /* Backlink to the containing struct dwo_file. */
831 struct dwo_file
*dwo_file
;
833 /* The "id" that distinguishes this CU/TU.
834 .debug_info calls this "dwo_id", .debug_types calls this "signature".
835 Since signatures came first, we stick with it for consistency. */
838 /* The section this CU/TU lives in, in the DWO file. */
839 struct dwarf2_section_info
*section
;
841 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
842 sect_offset sect_off
;
845 /* For types, offset in the type's DIE of the type defined by this TU. */
846 cu_offset type_offset_in_tu
;
849 /* include/dwarf2.h defines the DWP section codes.
850 It defines a max value but it doesn't define a min value, which we
851 use for error checking, so provide one. */
853 enum dwp_v2_section_ids
858 /* Data for one DWO file.
860 This includes virtual DWO files (a virtual DWO file is a DWO file as it
861 appears in a DWP file). DWP files don't really have DWO files per se -
862 comdat folding of types "loses" the DWO file they came from, and from
863 a high level view DWP files appear to contain a mass of random types.
864 However, to maintain consistency with the non-DWP case we pretend DWP
865 files contain virtual DWO files, and we assign each TU with one virtual
866 DWO file (generally based on the line and abbrev section offsets -
867 a heuristic that seems to work in practice). */
871 /* The DW_AT_GNU_dwo_name attribute.
872 For virtual DWO files the name is constructed from the section offsets
873 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
874 from related CU+TUs. */
875 const char *dwo_name
;
877 /* The DW_AT_comp_dir attribute. */
878 const char *comp_dir
;
880 /* The bfd, when the file is open. Otherwise this is NULL.
881 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
884 /* The sections that make up this DWO file.
885 Remember that for virtual DWO files in DWP V2, these are virtual
886 sections (for lack of a better name). */
887 struct dwo_sections sections
;
889 /* The CUs in the file.
890 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
891 an extension to handle LLVM's Link Time Optimization output (where
892 multiple source files may be compiled into a single object/dwo pair). */
895 /* Table of TUs in the file.
896 Each element is a struct dwo_unit. */
900 /* These sections are what may appear in a DWP file. */
904 /* These are used by both DWP version 1 and 2. */
905 struct dwarf2_section_info str
;
906 struct dwarf2_section_info cu_index
;
907 struct dwarf2_section_info tu_index
;
909 /* These are only used by DWP version 2 files.
910 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
911 sections are referenced by section number, and are not recorded here.
912 In DWP version 2 there is at most one copy of all these sections, each
913 section being (effectively) comprised of the concatenation of all of the
914 individual sections that exist in the version 1 format.
915 To keep the code simple we treat each of these concatenated pieces as a
916 section itself (a virtual section?). */
917 struct dwarf2_section_info abbrev
;
918 struct dwarf2_section_info info
;
919 struct dwarf2_section_info line
;
920 struct dwarf2_section_info loc
;
921 struct dwarf2_section_info macinfo
;
922 struct dwarf2_section_info macro
;
923 struct dwarf2_section_info str_offsets
;
924 struct dwarf2_section_info types
;
927 /* These sections are what may appear in a virtual DWO file in DWP version 1.
928 A virtual DWO file is a DWO file as it appears in a DWP file. */
930 struct virtual_v1_dwo_sections
932 struct dwarf2_section_info abbrev
;
933 struct dwarf2_section_info line
;
934 struct dwarf2_section_info loc
;
935 struct dwarf2_section_info macinfo
;
936 struct dwarf2_section_info macro
;
937 struct dwarf2_section_info str_offsets
;
938 /* Each DWP hash table entry records one CU or one TU.
939 That is recorded here, and copied to dwo_unit.section. */
940 struct dwarf2_section_info info_or_types
;
943 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
944 In version 2, the sections of the DWO files are concatenated together
945 and stored in one section of that name. Thus each ELF section contains
946 several "virtual" sections. */
948 struct virtual_v2_dwo_sections
950 bfd_size_type abbrev_offset
;
951 bfd_size_type abbrev_size
;
953 bfd_size_type line_offset
;
954 bfd_size_type line_size
;
956 bfd_size_type loc_offset
;
957 bfd_size_type loc_size
;
959 bfd_size_type macinfo_offset
;
960 bfd_size_type macinfo_size
;
962 bfd_size_type macro_offset
;
963 bfd_size_type macro_size
;
965 bfd_size_type str_offsets_offset
;
966 bfd_size_type str_offsets_size
;
968 /* Each DWP hash table entry records one CU or one TU.
969 That is recorded here, and copied to dwo_unit.section. */
970 bfd_size_type info_or_types_offset
;
971 bfd_size_type info_or_types_size
;
974 /* Contents of DWP hash tables. */
976 struct dwp_hash_table
978 uint32_t version
, nr_columns
;
979 uint32_t nr_units
, nr_slots
;
980 const gdb_byte
*hash_table
, *unit_table
;
985 const gdb_byte
*indices
;
989 /* This is indexed by column number and gives the id of the section
991 #define MAX_NR_V2_DWO_SECTIONS \
992 (1 /* .debug_info or .debug_types */ \
993 + 1 /* .debug_abbrev */ \
994 + 1 /* .debug_line */ \
995 + 1 /* .debug_loc */ \
996 + 1 /* .debug_str_offsets */ \
997 + 1 /* .debug_macro or .debug_macinfo */)
998 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
999 const gdb_byte
*offsets
;
1000 const gdb_byte
*sizes
;
1005 /* Data for one DWP file. */
1009 /* Name of the file. */
1012 /* File format version. */
1018 /* Section info for this file. */
1019 struct dwp_sections sections
;
1021 /* Table of CUs in the file. */
1022 const struct dwp_hash_table
*cus
;
1024 /* Table of TUs in the file. */
1025 const struct dwp_hash_table
*tus
;
1027 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
1031 /* Table to map ELF section numbers to their sections.
1032 This is only needed for the DWP V1 file format. */
1033 unsigned int num_sections
;
1034 asection
**elf_sections
;
1037 /* This represents a '.dwz' file. */
1041 /* A dwz file can only contain a few sections. */
1042 struct dwarf2_section_info abbrev
;
1043 struct dwarf2_section_info info
;
1044 struct dwarf2_section_info str
;
1045 struct dwarf2_section_info line
;
1046 struct dwarf2_section_info macro
;
1047 struct dwarf2_section_info gdb_index
;
1049 /* The dwz's BFD. */
1053 /* Struct used to pass misc. parameters to read_die_and_children, et
1054 al. which are used for both .debug_info and .debug_types dies.
1055 All parameters here are unchanging for the life of the call. This
1056 struct exists to abstract away the constant parameters of die reading. */
1058 struct die_reader_specs
1060 /* The bfd of die_section. */
1063 /* The CU of the DIE we are parsing. */
1064 struct dwarf2_cu
*cu
;
1066 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1067 struct dwo_file
*dwo_file
;
1069 /* The section the die comes from.
1070 This is either .debug_info or .debug_types, or the .dwo variants. */
1071 struct dwarf2_section_info
*die_section
;
1073 /* die_section->buffer. */
1074 const gdb_byte
*buffer
;
1076 /* The end of the buffer. */
1077 const gdb_byte
*buffer_end
;
1079 /* The value of the DW_AT_comp_dir attribute. */
1080 const char *comp_dir
;
1083 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1084 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1085 const gdb_byte
*info_ptr
,
1086 struct die_info
*comp_unit_die
,
1090 /* A 1-based directory index. This is a strong typedef to prevent
1091 accidentally using a directory index as a 0-based index into an
1093 enum class dir_index
: unsigned int {};
1095 /* Likewise, a 1-based file name index. */
1096 enum class file_name_index
: unsigned int {};
1100 file_entry () = default;
1102 file_entry (const char *name_
, dir_index d_index_
,
1103 unsigned int mod_time_
, unsigned int length_
)
1106 mod_time (mod_time_
),
1110 /* Return the include directory at D_INDEX stored in LH. Returns
1111 NULL if D_INDEX is out of bounds. */
1112 const char *include_dir (const line_header
*lh
) const;
1114 /* The file name. Note this is an observing pointer. The memory is
1115 owned by debug_line_buffer. */
1116 const char *name
{};
1118 /* The directory index (1-based). */
1119 dir_index d_index
{};
1121 unsigned int mod_time
{};
1123 unsigned int length
{};
1125 /* True if referenced by the Line Number Program. */
1128 /* The associated symbol table, if any. */
1129 struct symtab
*symtab
{};
1132 /* The line number information for a compilation unit (found in the
1133 .debug_line section) begins with a "statement program header",
1134 which contains the following information. */
1141 /* Add an entry to the include directory table. */
1142 void add_include_dir (const char *include_dir
);
1144 /* Add an entry to the file name table. */
1145 void add_file_name (const char *name
, dir_index d_index
,
1146 unsigned int mod_time
, unsigned int length
);
1148 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
1149 is out of bounds. */
1150 const char *include_dir_at (dir_index index
) const
1152 /* Convert directory index number (1-based) to vector index
1154 size_t vec_index
= to_underlying (index
) - 1;
1156 if (vec_index
>= include_dirs
.size ())
1158 return include_dirs
[vec_index
];
1161 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
1162 is out of bounds. */
1163 file_entry
*file_name_at (file_name_index index
)
1165 /* Convert file name index number (1-based) to vector index
1167 size_t vec_index
= to_underlying (index
) - 1;
1169 if (vec_index
>= file_names
.size ())
1171 return &file_names
[vec_index
];
1174 /* Const version of the above. */
1175 const file_entry
*file_name_at (unsigned int index
) const
1177 if (index
>= file_names
.size ())
1179 return &file_names
[index
];
1182 /* Offset of line number information in .debug_line section. */
1183 sect_offset sect_off
{};
1185 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1186 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1188 unsigned int total_length
{};
1189 unsigned short version
{};
1190 unsigned int header_length
{};
1191 unsigned char minimum_instruction_length
{};
1192 unsigned char maximum_ops_per_instruction
{};
1193 unsigned char default_is_stmt
{};
1195 unsigned char line_range
{};
1196 unsigned char opcode_base
{};
1198 /* standard_opcode_lengths[i] is the number of operands for the
1199 standard opcode whose value is i. This means that
1200 standard_opcode_lengths[0] is unused, and the last meaningful
1201 element is standard_opcode_lengths[opcode_base - 1]. */
1202 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1204 /* The include_directories table. Note these are observing
1205 pointers. The memory is owned by debug_line_buffer. */
1206 std::vector
<const char *> include_dirs
;
1208 /* The file_names table. */
1209 std::vector
<file_entry
> file_names
;
1211 /* The start and end of the statement program following this
1212 header. These point into dwarf2_per_objfile->line_buffer. */
1213 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1216 typedef std::unique_ptr
<line_header
> line_header_up
;
1219 file_entry::include_dir (const line_header
*lh
) const
1221 return lh
->include_dir_at (d_index
);
1224 /* When we construct a partial symbol table entry we only
1225 need this much information. */
1226 struct partial_die_info
1228 /* Offset of this DIE. */
1229 sect_offset sect_off
;
1231 /* DWARF-2 tag for this DIE. */
1232 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1234 /* Assorted flags describing the data found in this DIE. */
1235 unsigned int has_children
: 1;
1236 unsigned int is_external
: 1;
1237 unsigned int is_declaration
: 1;
1238 unsigned int has_type
: 1;
1239 unsigned int has_specification
: 1;
1240 unsigned int has_pc_info
: 1;
1241 unsigned int may_be_inlined
: 1;
1243 /* This DIE has been marked DW_AT_main_subprogram. */
1244 unsigned int main_subprogram
: 1;
1246 /* Flag set if the SCOPE field of this structure has been
1248 unsigned int scope_set
: 1;
1250 /* Flag set if the DIE has a byte_size attribute. */
1251 unsigned int has_byte_size
: 1;
1253 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1254 unsigned int has_const_value
: 1;
1256 /* Flag set if any of the DIE's children are template arguments. */
1257 unsigned int has_template_arguments
: 1;
1259 /* Flag set if fixup_partial_die has been called on this die. */
1260 unsigned int fixup_called
: 1;
1262 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1263 unsigned int is_dwz
: 1;
1265 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1266 unsigned int spec_is_dwz
: 1;
1268 /* The name of this DIE. Normally the value of DW_AT_name, but
1269 sometimes a default name for unnamed DIEs. */
1272 /* The linkage name, if present. */
1273 const char *linkage_name
;
1275 /* The scope to prepend to our children. This is generally
1276 allocated on the comp_unit_obstack, so will disappear
1277 when this compilation unit leaves the cache. */
1280 /* Some data associated with the partial DIE. The tag determines
1281 which field is live. */
1284 /* The location description associated with this DIE, if any. */
1285 struct dwarf_block
*locdesc
;
1286 /* The offset of an import, for DW_TAG_imported_unit. */
1287 sect_offset sect_off
;
1290 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1294 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1295 DW_AT_sibling, if any. */
1296 /* NOTE: This member isn't strictly necessary, read_partial_die could
1297 return DW_AT_sibling values to its caller load_partial_dies. */
1298 const gdb_byte
*sibling
;
1300 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1301 DW_AT_specification (or DW_AT_abstract_origin or
1302 DW_AT_extension). */
1303 sect_offset spec_offset
;
1305 /* Pointers to this DIE's parent, first child, and next sibling,
1307 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
1310 /* This data structure holds the information of an abbrev. */
1313 unsigned int number
; /* number identifying abbrev */
1314 enum dwarf_tag tag
; /* dwarf tag */
1315 unsigned short has_children
; /* boolean */
1316 unsigned short num_attrs
; /* number of attributes */
1317 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1318 struct abbrev_info
*next
; /* next in chain */
1323 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1324 ENUM_BITFIELD(dwarf_form
) form
: 16;
1326 /* It is valid only if FORM is DW_FORM_implicit_const. */
1327 LONGEST implicit_const
;
1330 /* Size of abbrev_table.abbrev_hash_table. */
1331 #define ABBREV_HASH_SIZE 121
1333 /* Top level data structure to contain an abbreviation table. */
1337 /* Where the abbrev table came from.
1338 This is used as a sanity check when the table is used. */
1339 sect_offset sect_off
;
1341 /* Storage for the abbrev table. */
1342 struct obstack abbrev_obstack
;
1344 /* Hash table of abbrevs.
1345 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1346 It could be statically allocated, but the previous code didn't so we
1348 struct abbrev_info
**abbrevs
;
1351 /* Attributes have a name and a value. */
1354 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1355 ENUM_BITFIELD(dwarf_form
) form
: 15;
1357 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1358 field should be in u.str (existing only for DW_STRING) but it is kept
1359 here for better struct attribute alignment. */
1360 unsigned int string_is_canonical
: 1;
1365 struct dwarf_block
*blk
;
1374 /* This data structure holds a complete die structure. */
1377 /* DWARF-2 tag for this DIE. */
1378 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1380 /* Number of attributes */
1381 unsigned char num_attrs
;
1383 /* True if we're presently building the full type name for the
1384 type derived from this DIE. */
1385 unsigned char building_fullname
: 1;
1387 /* True if this die is in process. PR 16581. */
1388 unsigned char in_process
: 1;
1391 unsigned int abbrev
;
1393 /* Offset in .debug_info or .debug_types section. */
1394 sect_offset sect_off
;
1396 /* The dies in a compilation unit form an n-ary tree. PARENT
1397 points to this die's parent; CHILD points to the first child of
1398 this node; and all the children of a given node are chained
1399 together via their SIBLING fields. */
1400 struct die_info
*child
; /* Its first child, if any. */
1401 struct die_info
*sibling
; /* Its next sibling, if any. */
1402 struct die_info
*parent
; /* Its parent, if any. */
1404 /* An array of attributes, with NUM_ATTRS elements. There may be
1405 zero, but it's not common and zero-sized arrays are not
1406 sufficiently portable C. */
1407 struct attribute attrs
[1];
1410 /* Get at parts of an attribute structure. */
1412 #define DW_STRING(attr) ((attr)->u.str)
1413 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1414 #define DW_UNSND(attr) ((attr)->u.unsnd)
1415 #define DW_BLOCK(attr) ((attr)->u.blk)
1416 #define DW_SND(attr) ((attr)->u.snd)
1417 #define DW_ADDR(attr) ((attr)->u.addr)
1418 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1420 /* Blocks are a bunch of untyped bytes. */
1425 /* Valid only if SIZE is not zero. */
1426 const gdb_byte
*data
;
1429 #ifndef ATTR_ALLOC_CHUNK
1430 #define ATTR_ALLOC_CHUNK 4
1433 /* Allocate fields for structs, unions and enums in this size. */
1434 #ifndef DW_FIELD_ALLOC_CHUNK
1435 #define DW_FIELD_ALLOC_CHUNK 4
1438 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1439 but this would require a corresponding change in unpack_field_as_long
1441 static int bits_per_byte
= 8;
1445 struct nextfield
*next
;
1453 struct nextfnfield
*next
;
1454 struct fn_field fnfield
;
1461 struct nextfnfield
*head
;
1464 struct typedef_field_list
1466 struct typedef_field field
;
1467 struct typedef_field_list
*next
;
1470 /* The routines that read and process dies for a C struct or C++ class
1471 pass lists of data member fields and lists of member function fields
1472 in an instance of a field_info structure, as defined below. */
1475 /* List of data member and baseclasses fields. */
1476 struct nextfield
*fields
, *baseclasses
;
1478 /* Number of fields (including baseclasses). */
1481 /* Number of baseclasses. */
1484 /* Set if the accesibility of one of the fields is not public. */
1485 int non_public_fields
;
1487 /* Member function fieldlist array, contains name of possibly overloaded
1488 member function, number of overloaded member functions and a pointer
1489 to the head of the member function field chain. */
1490 struct fnfieldlist
*fnfieldlists
;
1492 /* Number of entries in the fnfieldlists array. */
1495 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1496 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1497 struct typedef_field_list
*typedef_field_list
;
1498 unsigned typedef_field_list_count
;
1501 /* One item on the queue of compilation units to read in full symbols
1503 struct dwarf2_queue_item
1505 struct dwarf2_per_cu_data
*per_cu
;
1506 enum language pretend_language
;
1507 struct dwarf2_queue_item
*next
;
1510 /* The current queue. */
1511 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1513 /* Loaded secondary compilation units are kept in memory until they
1514 have not been referenced for the processing of this many
1515 compilation units. Set this to zero to disable caching. Cache
1516 sizes of up to at least twenty will improve startup time for
1517 typical inter-CU-reference binaries, at an obvious memory cost. */
1518 static int dwarf_max_cache_age
= 5;
1520 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1521 struct cmd_list_element
*c
, const char *value
)
1523 fprintf_filtered (file
, _("The upper bound on the age of cached "
1524 "DWARF compilation units is %s.\n"),
1528 /* local function prototypes */
1530 static const char *get_section_name (const struct dwarf2_section_info
*);
1532 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1534 static void dwarf2_find_base_address (struct die_info
*die
,
1535 struct dwarf2_cu
*cu
);
1537 static struct partial_symtab
*create_partial_symtab
1538 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1540 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1541 const gdb_byte
*info_ptr
,
1542 struct die_info
*type_unit_die
,
1543 int has_children
, void *data
);
1545 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1547 static void scan_partial_symbols (struct partial_die_info
*,
1548 CORE_ADDR
*, CORE_ADDR
*,
1549 int, struct dwarf2_cu
*);
1551 static void add_partial_symbol (struct partial_die_info
*,
1552 struct dwarf2_cu
*);
1554 static void add_partial_namespace (struct partial_die_info
*pdi
,
1555 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1556 int set_addrmap
, struct dwarf2_cu
*cu
);
1558 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1559 CORE_ADDR
*highpc
, int set_addrmap
,
1560 struct dwarf2_cu
*cu
);
1562 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1563 struct dwarf2_cu
*cu
);
1565 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1566 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1567 int need_pc
, struct dwarf2_cu
*cu
);
1569 static void dwarf2_read_symtab (struct partial_symtab
*,
1572 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1574 static struct abbrev_info
*abbrev_table_lookup_abbrev
1575 (const struct abbrev_table
*, unsigned int);
1577 static struct abbrev_table
*abbrev_table_read_table
1578 (struct dwarf2_section_info
*, sect_offset
);
1580 static void abbrev_table_free (struct abbrev_table
*);
1582 static void abbrev_table_free_cleanup (void *);
1584 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1585 struct dwarf2_section_info
*);
1587 static void dwarf2_free_abbrev_table (void *);
1589 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1591 static struct partial_die_info
*load_partial_dies
1592 (const struct die_reader_specs
*, const gdb_byte
*, int);
1594 static const gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1595 struct partial_die_info
*,
1596 struct abbrev_info
*,
1600 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1601 struct dwarf2_cu
*);
1603 static void fixup_partial_die (struct partial_die_info
*,
1604 struct dwarf2_cu
*);
1606 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1607 struct attribute
*, struct attr_abbrev
*,
1610 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1612 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1614 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1616 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1618 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1620 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1623 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1625 static LONGEST read_checked_initial_length_and_offset
1626 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1627 unsigned int *, unsigned int *);
1629 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1630 const struct comp_unit_head
*,
1633 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1635 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1638 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1640 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1642 static const char *read_indirect_string (bfd
*, const gdb_byte
*,
1643 const struct comp_unit_head
*,
1646 static const char *read_indirect_line_string (bfd
*, const gdb_byte
*,
1647 const struct comp_unit_head
*,
1650 static const char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1652 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1654 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1658 static const char *read_str_index (const struct die_reader_specs
*reader
,
1659 ULONGEST str_index
);
1661 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1663 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1664 struct dwarf2_cu
*);
1666 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1669 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1670 struct dwarf2_cu
*cu
);
1672 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1673 struct dwarf2_cu
*cu
);
1675 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1677 static struct die_info
*die_specification (struct die_info
*die
,
1678 struct dwarf2_cu
**);
1680 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1681 struct dwarf2_cu
*cu
);
1683 static void dwarf_decode_lines (struct line_header
*, const char *,
1684 struct dwarf2_cu
*, struct partial_symtab
*,
1685 CORE_ADDR
, int decode_mapping
);
1687 static void dwarf2_start_subfile (const char *, const char *);
1689 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1690 const char *, const char *,
1693 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1694 struct dwarf2_cu
*);
1696 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1697 struct dwarf2_cu
*, struct symbol
*);
1699 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1700 struct dwarf2_cu
*);
1702 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1705 struct obstack
*obstack
,
1706 struct dwarf2_cu
*cu
, LONGEST
*value
,
1707 const gdb_byte
**bytes
,
1708 struct dwarf2_locexpr_baton
**baton
);
1710 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1712 static int need_gnat_info (struct dwarf2_cu
*);
1714 static struct type
*die_descriptive_type (struct die_info
*,
1715 struct dwarf2_cu
*);
1717 static void set_descriptive_type (struct type
*, struct die_info
*,
1718 struct dwarf2_cu
*);
1720 static struct type
*die_containing_type (struct die_info
*,
1721 struct dwarf2_cu
*);
1723 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1724 struct dwarf2_cu
*);
1726 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1728 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1730 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1732 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1733 const char *suffix
, int physname
,
1734 struct dwarf2_cu
*cu
);
1736 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1738 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1740 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1742 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1744 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1746 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1747 struct dwarf2_cu
*, struct partial_symtab
*);
1749 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1750 values. Keep the items ordered with increasing constraints compliance. */
1753 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1754 PC_BOUNDS_NOT_PRESENT
,
1756 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1757 were present but they do not form a valid range of PC addresses. */
1760 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1763 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1767 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1768 CORE_ADDR
*, CORE_ADDR
*,
1770 struct partial_symtab
*);
1772 static void get_scope_pc_bounds (struct die_info
*,
1773 CORE_ADDR
*, CORE_ADDR
*,
1774 struct dwarf2_cu
*);
1776 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1777 CORE_ADDR
, struct dwarf2_cu
*);
1779 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1780 struct dwarf2_cu
*);
1782 static void dwarf2_attach_fields_to_type (struct field_info
*,
1783 struct type
*, struct dwarf2_cu
*);
1785 static void dwarf2_add_member_fn (struct field_info
*,
1786 struct die_info
*, struct type
*,
1787 struct dwarf2_cu
*);
1789 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1791 struct dwarf2_cu
*);
1793 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1795 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1797 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1799 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1801 static struct using_direct
**using_directives (enum language
);
1803 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1805 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1807 static struct type
*read_module_type (struct die_info
*die
,
1808 struct dwarf2_cu
*cu
);
1810 static const char *namespace_name (struct die_info
*die
,
1811 int *is_anonymous
, struct dwarf2_cu
*);
1813 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1815 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1817 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1818 struct dwarf2_cu
*);
1820 static struct die_info
*read_die_and_siblings_1
1821 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1824 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1825 const gdb_byte
*info_ptr
,
1826 const gdb_byte
**new_info_ptr
,
1827 struct die_info
*parent
);
1829 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1830 struct die_info
**, const gdb_byte
*,
1833 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1834 struct die_info
**, const gdb_byte
*,
1837 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1839 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1842 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1844 static const char *dwarf2_full_name (const char *name
,
1845 struct die_info
*die
,
1846 struct dwarf2_cu
*cu
);
1848 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1849 struct dwarf2_cu
*cu
);
1851 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1852 struct dwarf2_cu
**);
1854 static const char *dwarf_tag_name (unsigned int);
1856 static const char *dwarf_attr_name (unsigned int);
1858 static const char *dwarf_form_name (unsigned int);
1860 static const char *dwarf_bool_name (unsigned int);
1862 static const char *dwarf_type_encoding_name (unsigned int);
1864 static struct die_info
*sibling_die (struct die_info
*);
1866 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1868 static void dump_die_for_error (struct die_info
*);
1870 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1873 /*static*/ void dump_die (struct die_info
*, int max_level
);
1875 static void store_in_ref_table (struct die_info
*,
1876 struct dwarf2_cu
*);
1878 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1880 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1882 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1883 const struct attribute
*,
1884 struct dwarf2_cu
**);
1886 static struct die_info
*follow_die_ref (struct die_info
*,
1887 const struct attribute
*,
1888 struct dwarf2_cu
**);
1890 static struct die_info
*follow_die_sig (struct die_info
*,
1891 const struct attribute
*,
1892 struct dwarf2_cu
**);
1894 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1895 struct dwarf2_cu
*);
1897 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1898 const struct attribute
*,
1899 struct dwarf2_cu
*);
1901 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1903 static void read_signatured_type (struct signatured_type
*);
1905 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1906 struct die_info
*die
, struct dwarf2_cu
*cu
,
1907 struct dynamic_prop
*prop
);
1909 /* memory allocation interface */
1911 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1913 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1915 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1917 static int attr_form_is_block (const struct attribute
*);
1919 static int attr_form_is_section_offset (const struct attribute
*);
1921 static int attr_form_is_constant (const struct attribute
*);
1923 static int attr_form_is_ref (const struct attribute
*);
1925 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1926 struct dwarf2_loclist_baton
*baton
,
1927 const struct attribute
*attr
);
1929 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1931 struct dwarf2_cu
*cu
,
1934 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1935 const gdb_byte
*info_ptr
,
1936 struct abbrev_info
*abbrev
);
1938 static void free_stack_comp_unit (void *);
1940 static hashval_t
partial_die_hash (const void *item
);
1942 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1944 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1945 (sect_offset sect_off
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1947 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1948 struct dwarf2_per_cu_data
*per_cu
);
1950 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1951 struct die_info
*comp_unit_die
,
1952 enum language pretend_language
);
1954 static void free_heap_comp_unit (void *);
1956 static void free_cached_comp_units (void *);
1958 static void age_cached_comp_units (void);
1960 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1962 static struct type
*set_die_type (struct die_info
*, struct type
*,
1963 struct dwarf2_cu
*);
1965 static void create_all_comp_units (struct objfile
*);
1967 static int create_all_type_units (struct objfile
*);
1969 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1972 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1975 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1978 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1979 struct dwarf2_per_cu_data
*);
1981 static void dwarf2_mark (struct dwarf2_cu
*);
1983 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1985 static struct type
*get_die_type_at_offset (sect_offset
,
1986 struct dwarf2_per_cu_data
*);
1988 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1990 static void dwarf2_release_queue (void *dummy
);
1992 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1993 enum language pretend_language
);
1995 static void process_queue (void);
1997 /* The return type of find_file_and_directory. Note, the enclosed
1998 string pointers are only valid while this object is valid. */
2000 struct file_and_directory
2002 /* The filename. This is never NULL. */
2005 /* The compilation directory. NULL if not known. If we needed to
2006 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
2007 points directly to the DW_AT_comp_dir string attribute owned by
2008 the obstack that owns the DIE. */
2009 const char *comp_dir
;
2011 /* If we needed to build a new string for comp_dir, this is what
2012 owns the storage. */
2013 std::string comp_dir_storage
;
2016 static file_and_directory
find_file_and_directory (struct die_info
*die
,
2017 struct dwarf2_cu
*cu
);
2019 static char *file_full_name (int file
, struct line_header
*lh
,
2020 const char *comp_dir
);
2022 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
2023 enum class rcuh_kind
{ COMPILE
, TYPE
};
2025 static const gdb_byte
*read_and_check_comp_unit_head
2026 (struct comp_unit_head
*header
,
2027 struct dwarf2_section_info
*section
,
2028 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
2029 rcuh_kind section_kind
);
2031 static void init_cutu_and_read_dies
2032 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
2033 int use_existing_cu
, int keep
,
2034 die_reader_func_ftype
*die_reader_func
, void *data
);
2036 static void init_cutu_and_read_dies_simple
2037 (struct dwarf2_per_cu_data
*this_cu
,
2038 die_reader_func_ftype
*die_reader_func
, void *data
);
2040 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2042 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2044 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2045 (struct dwp_file
*dwp_file
, const char *comp_dir
,
2046 ULONGEST signature
, int is_debug_types
);
2048 static struct dwp_file
*get_dwp_file (void);
2050 static struct dwo_unit
*lookup_dwo_comp_unit
2051 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2053 static struct dwo_unit
*lookup_dwo_type_unit
2054 (struct signatured_type
*, const char *, const char *);
2056 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2058 static void free_dwo_file_cleanup (void *);
2060 static void process_cu_includes (void);
2062 static void check_producer (struct dwarf2_cu
*cu
);
2064 static void free_line_header_voidp (void *arg
);
2066 /* Various complaints about symbol reading that don't abort the process. */
2069 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2071 complaint (&symfile_complaints
,
2072 _("statement list doesn't fit in .debug_line section"));
2076 dwarf2_debug_line_missing_file_complaint (void)
2078 complaint (&symfile_complaints
,
2079 _(".debug_line section has line data without a file"));
2083 dwarf2_debug_line_missing_end_sequence_complaint (void)
2085 complaint (&symfile_complaints
,
2086 _(".debug_line section has line "
2087 "program sequence without an end"));
2091 dwarf2_complex_location_expr_complaint (void)
2093 complaint (&symfile_complaints
, _("location expression too complex"));
2097 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2100 complaint (&symfile_complaints
,
2101 _("const value length mismatch for '%s', got %d, expected %d"),
2106 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2108 complaint (&symfile_complaints
,
2109 _("debug info runs off end of %s section"
2111 get_section_name (section
),
2112 get_section_file_name (section
));
2116 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2118 complaint (&symfile_complaints
,
2119 _("macro debug info contains a "
2120 "malformed macro definition:\n`%s'"),
2125 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2127 complaint (&symfile_complaints
,
2128 _("invalid attribute class or form for '%s' in '%s'"),
2132 /* Hash function for line_header_hash. */
2135 line_header_hash (const struct line_header
*ofs
)
2137 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2140 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2143 line_header_hash_voidp (const void *item
)
2145 const struct line_header
*ofs
= (const struct line_header
*) item
;
2147 return line_header_hash (ofs
);
2150 /* Equality function for line_header_hash. */
2153 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2155 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2156 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2158 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2159 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2165 /* Convert VALUE between big- and little-endian. */
2167 byte_swap (offset_type value
)
2171 result
= (value
& 0xff) << 24;
2172 result
|= (value
& 0xff00) << 8;
2173 result
|= (value
& 0xff0000) >> 8;
2174 result
|= (value
& 0xff000000) >> 24;
2178 #define MAYBE_SWAP(V) byte_swap (V)
2181 #define MAYBE_SWAP(V) static_cast<offset_type> (V)
2182 #endif /* WORDS_BIGENDIAN */
2184 /* Read the given attribute value as an address, taking the attribute's
2185 form into account. */
2188 attr_value_as_address (struct attribute
*attr
)
2192 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2194 /* Aside from a few clearly defined exceptions, attributes that
2195 contain an address must always be in DW_FORM_addr form.
2196 Unfortunately, some compilers happen to be violating this
2197 requirement by encoding addresses using other forms, such
2198 as DW_FORM_data4 for example. For those broken compilers,
2199 we try to do our best, without any guarantee of success,
2200 to interpret the address correctly. It would also be nice
2201 to generate a complaint, but that would require us to maintain
2202 a list of legitimate cases where a non-address form is allowed,
2203 as well as update callers to pass in at least the CU's DWARF
2204 version. This is more overhead than what we're willing to
2205 expand for a pretty rare case. */
2206 addr
= DW_UNSND (attr
);
2209 addr
= DW_ADDR (attr
);
2214 /* The suffix for an index file. */
2215 #define INDEX_SUFFIX ".gdb-index"
2217 /* See declaration. */
2219 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2220 const dwarf2_debug_sections
*names
)
2221 : objfile (objfile_
)
2224 names
= &dwarf2_elf_names
;
2226 bfd
*obfd
= objfile
->obfd
;
2228 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2229 locate_sections (obfd
, sec
, *names
);
2232 dwarf2_per_objfile::~dwarf2_per_objfile ()
2234 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2235 free_cached_comp_units ();
2237 if (quick_file_names_table
)
2238 htab_delete (quick_file_names_table
);
2240 if (line_header_hash
)
2241 htab_delete (line_header_hash
);
2243 /* Everything else should be on the objfile obstack. */
2246 /* See declaration. */
2249 dwarf2_per_objfile::free_cached_comp_units ()
2251 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2252 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2253 while (per_cu
!= NULL
)
2255 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2257 free_heap_comp_unit (per_cu
->cu
);
2258 *last_chain
= next_cu
;
2263 /* Try to locate the sections we need for DWARF 2 debugging
2264 information and return true if we have enough to do something.
2265 NAMES points to the dwarf2 section names, or is NULL if the standard
2266 ELF names are used. */
2269 dwarf2_has_info (struct objfile
*objfile
,
2270 const struct dwarf2_debug_sections
*names
)
2272 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
2273 objfile_data (objfile
, dwarf2_objfile_data_key
));
2274 if (!dwarf2_per_objfile
)
2276 /* Initialize per-objfile state. */
2277 struct dwarf2_per_objfile
*data
2278 = XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_objfile
);
2280 dwarf2_per_objfile
= new (data
) struct dwarf2_per_objfile (objfile
, names
);
2281 set_objfile_data (objfile
, dwarf2_objfile_data_key
, dwarf2_per_objfile
);
2283 return (!dwarf2_per_objfile
->info
.is_virtual
2284 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2285 && !dwarf2_per_objfile
->abbrev
.is_virtual
2286 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2289 /* Return the containing section of virtual section SECTION. */
2291 static struct dwarf2_section_info
*
2292 get_containing_section (const struct dwarf2_section_info
*section
)
2294 gdb_assert (section
->is_virtual
);
2295 return section
->s
.containing_section
;
2298 /* Return the bfd owner of SECTION. */
2301 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2303 if (section
->is_virtual
)
2305 section
= get_containing_section (section
);
2306 gdb_assert (!section
->is_virtual
);
2308 return section
->s
.section
->owner
;
2311 /* Return the bfd section of SECTION.
2312 Returns NULL if the section is not present. */
2315 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2317 if (section
->is_virtual
)
2319 section
= get_containing_section (section
);
2320 gdb_assert (!section
->is_virtual
);
2322 return section
->s
.section
;
2325 /* Return the name of SECTION. */
2328 get_section_name (const struct dwarf2_section_info
*section
)
2330 asection
*sectp
= get_section_bfd_section (section
);
2332 gdb_assert (sectp
!= NULL
);
2333 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2336 /* Return the name of the file SECTION is in. */
2339 get_section_file_name (const struct dwarf2_section_info
*section
)
2341 bfd
*abfd
= get_section_bfd_owner (section
);
2343 return bfd_get_filename (abfd
);
2346 /* Return the id of SECTION.
2347 Returns 0 if SECTION doesn't exist. */
2350 get_section_id (const struct dwarf2_section_info
*section
)
2352 asection
*sectp
= get_section_bfd_section (section
);
2359 /* Return the flags of SECTION.
2360 SECTION (or containing section if this is a virtual section) must exist. */
2363 get_section_flags (const struct dwarf2_section_info
*section
)
2365 asection
*sectp
= get_section_bfd_section (section
);
2367 gdb_assert (sectp
!= NULL
);
2368 return bfd_get_section_flags (sectp
->owner
, sectp
);
2371 /* When loading sections, we look either for uncompressed section or for
2372 compressed section names. */
2375 section_is_p (const char *section_name
,
2376 const struct dwarf2_section_names
*names
)
2378 if (names
->normal
!= NULL
2379 && strcmp (section_name
, names
->normal
) == 0)
2381 if (names
->compressed
!= NULL
2382 && strcmp (section_name
, names
->compressed
) == 0)
2387 /* See declaration. */
2390 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2391 const dwarf2_debug_sections
&names
)
2393 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2395 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2398 else if (section_is_p (sectp
->name
, &names
.info
))
2400 this->info
.s
.section
= sectp
;
2401 this->info
.size
= bfd_get_section_size (sectp
);
2403 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2405 this->abbrev
.s
.section
= sectp
;
2406 this->abbrev
.size
= bfd_get_section_size (sectp
);
2408 else if (section_is_p (sectp
->name
, &names
.line
))
2410 this->line
.s
.section
= sectp
;
2411 this->line
.size
= bfd_get_section_size (sectp
);
2413 else if (section_is_p (sectp
->name
, &names
.loc
))
2415 this->loc
.s
.section
= sectp
;
2416 this->loc
.size
= bfd_get_section_size (sectp
);
2418 else if (section_is_p (sectp
->name
, &names
.loclists
))
2420 this->loclists
.s
.section
= sectp
;
2421 this->loclists
.size
= bfd_get_section_size (sectp
);
2423 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2425 this->macinfo
.s
.section
= sectp
;
2426 this->macinfo
.size
= bfd_get_section_size (sectp
);
2428 else if (section_is_p (sectp
->name
, &names
.macro
))
2430 this->macro
.s
.section
= sectp
;
2431 this->macro
.size
= bfd_get_section_size (sectp
);
2433 else if (section_is_p (sectp
->name
, &names
.str
))
2435 this->str
.s
.section
= sectp
;
2436 this->str
.size
= bfd_get_section_size (sectp
);
2438 else if (section_is_p (sectp
->name
, &names
.line_str
))
2440 this->line_str
.s
.section
= sectp
;
2441 this->line_str
.size
= bfd_get_section_size (sectp
);
2443 else if (section_is_p (sectp
->name
, &names
.addr
))
2445 this->addr
.s
.section
= sectp
;
2446 this->addr
.size
= bfd_get_section_size (sectp
);
2448 else if (section_is_p (sectp
->name
, &names
.frame
))
2450 this->frame
.s
.section
= sectp
;
2451 this->frame
.size
= bfd_get_section_size (sectp
);
2453 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2455 this->eh_frame
.s
.section
= sectp
;
2456 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2458 else if (section_is_p (sectp
->name
, &names
.ranges
))
2460 this->ranges
.s
.section
= sectp
;
2461 this->ranges
.size
= bfd_get_section_size (sectp
);
2463 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2465 this->rnglists
.s
.section
= sectp
;
2466 this->rnglists
.size
= bfd_get_section_size (sectp
);
2468 else if (section_is_p (sectp
->name
, &names
.types
))
2470 struct dwarf2_section_info type_section
;
2472 memset (&type_section
, 0, sizeof (type_section
));
2473 type_section
.s
.section
= sectp
;
2474 type_section
.size
= bfd_get_section_size (sectp
);
2476 VEC_safe_push (dwarf2_section_info_def
, this->types
,
2479 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2481 this->gdb_index
.s
.section
= sectp
;
2482 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2485 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2486 && bfd_section_vma (abfd
, sectp
) == 0)
2487 this->has_section_at_zero
= true;
2490 /* A helper function that decides whether a section is empty,
2494 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2496 if (section
->is_virtual
)
2497 return section
->size
== 0;
2498 return section
->s
.section
== NULL
|| section
->size
== 0;
2501 /* Read the contents of the section INFO.
2502 OBJFILE is the main object file, but not necessarily the file where
2503 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2505 If the section is compressed, uncompress it before returning. */
2508 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2512 gdb_byte
*buf
, *retbuf
;
2516 info
->buffer
= NULL
;
2519 if (dwarf2_section_empty_p (info
))
2522 sectp
= get_section_bfd_section (info
);
2524 /* If this is a virtual section we need to read in the real one first. */
2525 if (info
->is_virtual
)
2527 struct dwarf2_section_info
*containing_section
=
2528 get_containing_section (info
);
2530 gdb_assert (sectp
!= NULL
);
2531 if ((sectp
->flags
& SEC_RELOC
) != 0)
2533 error (_("Dwarf Error: DWP format V2 with relocations is not"
2534 " supported in section %s [in module %s]"),
2535 get_section_name (info
), get_section_file_name (info
));
2537 dwarf2_read_section (objfile
, containing_section
);
2538 /* Other code should have already caught virtual sections that don't
2540 gdb_assert (info
->virtual_offset
+ info
->size
2541 <= containing_section
->size
);
2542 /* If the real section is empty or there was a problem reading the
2543 section we shouldn't get here. */
2544 gdb_assert (containing_section
->buffer
!= NULL
);
2545 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2549 /* If the section has relocations, we must read it ourselves.
2550 Otherwise we attach it to the BFD. */
2551 if ((sectp
->flags
& SEC_RELOC
) == 0)
2553 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2557 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2560 /* When debugging .o files, we may need to apply relocations; see
2561 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2562 We never compress sections in .o files, so we only need to
2563 try this when the section is not compressed. */
2564 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2567 info
->buffer
= retbuf
;
2571 abfd
= get_section_bfd_owner (info
);
2572 gdb_assert (abfd
!= NULL
);
2574 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2575 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2577 error (_("Dwarf Error: Can't read DWARF data"
2578 " in section %s [in module %s]"),
2579 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2583 /* A helper function that returns the size of a section in a safe way.
2584 If you are positive that the section has been read before using the
2585 size, then it is safe to refer to the dwarf2_section_info object's
2586 "size" field directly. In other cases, you must call this
2587 function, because for compressed sections the size field is not set
2588 correctly until the section has been read. */
2590 static bfd_size_type
2591 dwarf2_section_size (struct objfile
*objfile
,
2592 struct dwarf2_section_info
*info
)
2595 dwarf2_read_section (objfile
, info
);
2599 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2603 dwarf2_get_section_info (struct objfile
*objfile
,
2604 enum dwarf2_section_enum sect
,
2605 asection
**sectp
, const gdb_byte
**bufp
,
2606 bfd_size_type
*sizep
)
2608 struct dwarf2_per_objfile
*data
2609 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2610 dwarf2_objfile_data_key
);
2611 struct dwarf2_section_info
*info
;
2613 /* We may see an objfile without any DWARF, in which case we just
2624 case DWARF2_DEBUG_FRAME
:
2625 info
= &data
->frame
;
2627 case DWARF2_EH_FRAME
:
2628 info
= &data
->eh_frame
;
2631 gdb_assert_not_reached ("unexpected section");
2634 dwarf2_read_section (objfile
, info
);
2636 *sectp
= get_section_bfd_section (info
);
2637 *bufp
= info
->buffer
;
2638 *sizep
= info
->size
;
2641 /* A helper function to find the sections for a .dwz file. */
2644 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2646 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2648 /* Note that we only support the standard ELF names, because .dwz
2649 is ELF-only (at the time of writing). */
2650 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2652 dwz_file
->abbrev
.s
.section
= sectp
;
2653 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2655 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2657 dwz_file
->info
.s
.section
= sectp
;
2658 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2660 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2662 dwz_file
->str
.s
.section
= sectp
;
2663 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2665 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2667 dwz_file
->line
.s
.section
= sectp
;
2668 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2670 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2672 dwz_file
->macro
.s
.section
= sectp
;
2673 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2675 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2677 dwz_file
->gdb_index
.s
.section
= sectp
;
2678 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2682 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2683 there is no .gnu_debugaltlink section in the file. Error if there
2684 is such a section but the file cannot be found. */
2686 static struct dwz_file
*
2687 dwarf2_get_dwz_file (void)
2689 const char *filename
;
2690 struct dwz_file
*result
;
2691 bfd_size_type buildid_len_arg
;
2695 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2696 return dwarf2_per_objfile
->dwz_file
;
2698 bfd_set_error (bfd_error_no_error
);
2699 gdb::unique_xmalloc_ptr
<char> data
2700 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2701 &buildid_len_arg
, &buildid
));
2704 if (bfd_get_error () == bfd_error_no_error
)
2706 error (_("could not read '.gnu_debugaltlink' section: %s"),
2707 bfd_errmsg (bfd_get_error ()));
2710 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2712 buildid_len
= (size_t) buildid_len_arg
;
2714 filename
= data
.get ();
2716 std::string abs_storage
;
2717 if (!IS_ABSOLUTE_PATH (filename
))
2719 gdb::unique_xmalloc_ptr
<char> abs
2720 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2722 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2723 filename
= abs_storage
.c_str ();
2726 /* First try the file name given in the section. If that doesn't
2727 work, try to use the build-id instead. */
2728 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2729 if (dwz_bfd
!= NULL
)
2731 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2735 if (dwz_bfd
== NULL
)
2736 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2738 if (dwz_bfd
== NULL
)
2739 error (_("could not find '.gnu_debugaltlink' file for %s"),
2740 objfile_name (dwarf2_per_objfile
->objfile
));
2742 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2744 result
->dwz_bfd
= dwz_bfd
.release ();
2746 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
2748 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
2749 dwarf2_per_objfile
->dwz_file
= result
;
2753 /* DWARF quick_symbols_functions support. */
2755 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2756 unique line tables, so we maintain a separate table of all .debug_line
2757 derived entries to support the sharing.
2758 All the quick functions need is the list of file names. We discard the
2759 line_header when we're done and don't need to record it here. */
2760 struct quick_file_names
2762 /* The data used to construct the hash key. */
2763 struct stmt_list_hash hash
;
2765 /* The number of entries in file_names, real_names. */
2766 unsigned int num_file_names
;
2768 /* The file names from the line table, after being run through
2770 const char **file_names
;
2772 /* The file names from the line table after being run through
2773 gdb_realpath. These are computed lazily. */
2774 const char **real_names
;
2777 /* When using the index (and thus not using psymtabs), each CU has an
2778 object of this type. This is used to hold information needed by
2779 the various "quick" methods. */
2780 struct dwarf2_per_cu_quick_data
2782 /* The file table. This can be NULL if there was no file table
2783 or it's currently not read in.
2784 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2785 struct quick_file_names
*file_names
;
2787 /* The corresponding symbol table. This is NULL if symbols for this
2788 CU have not yet been read. */
2789 struct compunit_symtab
*compunit_symtab
;
2791 /* A temporary mark bit used when iterating over all CUs in
2792 expand_symtabs_matching. */
2793 unsigned int mark
: 1;
2795 /* True if we've tried to read the file table and found there isn't one.
2796 There will be no point in trying to read it again next time. */
2797 unsigned int no_file_data
: 1;
2800 /* Utility hash function for a stmt_list_hash. */
2803 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2807 if (stmt_list_hash
->dwo_unit
!= NULL
)
2808 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2809 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2813 /* Utility equality function for a stmt_list_hash. */
2816 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2817 const struct stmt_list_hash
*rhs
)
2819 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2821 if (lhs
->dwo_unit
!= NULL
2822 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2825 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2828 /* Hash function for a quick_file_names. */
2831 hash_file_name_entry (const void *e
)
2833 const struct quick_file_names
*file_data
2834 = (const struct quick_file_names
*) e
;
2836 return hash_stmt_list_entry (&file_data
->hash
);
2839 /* Equality function for a quick_file_names. */
2842 eq_file_name_entry (const void *a
, const void *b
)
2844 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2845 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2847 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2850 /* Delete function for a quick_file_names. */
2853 delete_file_name_entry (void *e
)
2855 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2858 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2860 xfree ((void*) file_data
->file_names
[i
]);
2861 if (file_data
->real_names
)
2862 xfree ((void*) file_data
->real_names
[i
]);
2865 /* The space for the struct itself lives on objfile_obstack,
2866 so we don't free it here. */
2869 /* Create a quick_file_names hash table. */
2872 create_quick_file_names_table (unsigned int nr_initial_entries
)
2874 return htab_create_alloc (nr_initial_entries
,
2875 hash_file_name_entry
, eq_file_name_entry
,
2876 delete_file_name_entry
, xcalloc
, xfree
);
2879 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2880 have to be created afterwards. You should call age_cached_comp_units after
2881 processing PER_CU->CU. dw2_setup must have been already called. */
2884 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2886 if (per_cu
->is_debug_types
)
2887 load_full_type_unit (per_cu
);
2889 load_full_comp_unit (per_cu
, language_minimal
);
2891 if (per_cu
->cu
== NULL
)
2892 return; /* Dummy CU. */
2894 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2897 /* Read in the symbols for PER_CU. */
2900 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2902 struct cleanup
*back_to
;
2904 /* Skip type_unit_groups, reading the type units they contain
2905 is handled elsewhere. */
2906 if (IS_TYPE_UNIT_GROUP (per_cu
))
2909 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2911 if (dwarf2_per_objfile
->using_index
2912 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2913 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2915 queue_comp_unit (per_cu
, language_minimal
);
2918 /* If we just loaded a CU from a DWO, and we're working with an index
2919 that may badly handle TUs, load all the TUs in that DWO as well.
2920 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2921 if (!per_cu
->is_debug_types
2922 && per_cu
->cu
!= NULL
2923 && per_cu
->cu
->dwo_unit
!= NULL
2924 && dwarf2_per_objfile
->index_table
!= NULL
2925 && dwarf2_per_objfile
->index_table
->version
<= 7
2926 /* DWP files aren't supported yet. */
2927 && get_dwp_file () == NULL
)
2928 queue_and_load_all_dwo_tus (per_cu
);
2933 /* Age the cache, releasing compilation units that have not
2934 been used recently. */
2935 age_cached_comp_units ();
2937 do_cleanups (back_to
);
2940 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2941 the objfile from which this CU came. Returns the resulting symbol
2944 static struct compunit_symtab
*
2945 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2947 gdb_assert (dwarf2_per_objfile
->using_index
);
2948 if (!per_cu
->v
.quick
->compunit_symtab
)
2950 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2951 scoped_restore decrementer
= increment_reading_symtab ();
2952 dw2_do_instantiate_symtab (per_cu
);
2953 process_cu_includes ();
2954 do_cleanups (back_to
);
2957 return per_cu
->v
.quick
->compunit_symtab
;
2960 /* Return the CU/TU given its index.
2962 This is intended for loops like:
2964 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2965 + dwarf2_per_objfile->n_type_units); ++i)
2967 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
2973 static struct dwarf2_per_cu_data
*
2974 dw2_get_cutu (int index
)
2976 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2978 index
-= dwarf2_per_objfile
->n_comp_units
;
2979 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2980 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2983 return dwarf2_per_objfile
->all_comp_units
[index
];
2986 /* Return the CU given its index.
2987 This differs from dw2_get_cutu in that it's for when you know INDEX
2990 static struct dwarf2_per_cu_data
*
2991 dw2_get_cu (int index
)
2993 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
2995 return dwarf2_per_objfile
->all_comp_units
[index
];
2998 /* A helper for create_cus_from_index that handles a given list of
3002 create_cus_from_index_list (struct objfile
*objfile
,
3003 const gdb_byte
*cu_list
, offset_type n_elements
,
3004 struct dwarf2_section_info
*section
,
3010 for (i
= 0; i
< n_elements
; i
+= 2)
3012 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3014 sect_offset sect_off
3015 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3016 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3019 dwarf2_per_cu_data
*the_cu
3020 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3021 struct dwarf2_per_cu_data
);
3022 the_cu
->sect_off
= sect_off
;
3023 the_cu
->length
= length
;
3024 the_cu
->objfile
= objfile
;
3025 the_cu
->section
= section
;
3026 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3027 struct dwarf2_per_cu_quick_data
);
3028 the_cu
->is_dwz
= is_dwz
;
3029 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
3033 /* Read the CU list from the mapped index, and use it to create all
3034 the CU objects for this objfile. */
3037 create_cus_from_index (struct objfile
*objfile
,
3038 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3039 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3041 struct dwz_file
*dwz
;
3043 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
3044 dwarf2_per_objfile
->all_comp_units
=
3045 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
3046 dwarf2_per_objfile
->n_comp_units
);
3048 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
3049 &dwarf2_per_objfile
->info
, 0, 0);
3051 if (dwz_elements
== 0)
3054 dwz
= dwarf2_get_dwz_file ();
3055 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
3056 cu_list_elements
/ 2);
3059 /* Create the signatured type hash table from the index. */
3062 create_signatured_type_table_from_index (struct objfile
*objfile
,
3063 struct dwarf2_section_info
*section
,
3064 const gdb_byte
*bytes
,
3065 offset_type elements
)
3068 htab_t sig_types_hash
;
3070 dwarf2_per_objfile
->n_type_units
3071 = dwarf2_per_objfile
->n_allocated_type_units
3073 dwarf2_per_objfile
->all_type_units
=
3074 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3076 sig_types_hash
= allocate_signatured_type_table (objfile
);
3078 for (i
= 0; i
< elements
; i
+= 3)
3080 struct signatured_type
*sig_type
;
3083 cu_offset type_offset_in_tu
;
3085 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3086 sect_offset sect_off
3087 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3089 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3091 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3094 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3095 struct signatured_type
);
3096 sig_type
->signature
= signature
;
3097 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3098 sig_type
->per_cu
.is_debug_types
= 1;
3099 sig_type
->per_cu
.section
= section
;
3100 sig_type
->per_cu
.sect_off
= sect_off
;
3101 sig_type
->per_cu
.objfile
= objfile
;
3102 sig_type
->per_cu
.v
.quick
3103 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3104 struct dwarf2_per_cu_quick_data
);
3106 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3109 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
3112 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3115 /* Read the address map data from the mapped index, and use it to
3116 populate the objfile's psymtabs_addrmap. */
3119 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
3121 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3122 const gdb_byte
*iter
, *end
;
3123 struct addrmap
*mutable_map
;
3126 auto_obstack temp_obstack
;
3128 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3130 iter
= index
->address_table
;
3131 end
= iter
+ index
->address_table_size
;
3133 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3137 ULONGEST hi
, lo
, cu_index
;
3138 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3140 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3142 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3147 complaint (&symfile_complaints
,
3148 _(".gdb_index address table has invalid range (%s - %s)"),
3149 hex_string (lo
), hex_string (hi
));
3153 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
3155 complaint (&symfile_complaints
,
3156 _(".gdb_index address table has invalid CU number %u"),
3157 (unsigned) cu_index
);
3161 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3162 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3163 addrmap_set_empty (mutable_map
, lo
, hi
- 1, dw2_get_cutu (cu_index
));
3166 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3167 &objfile
->objfile_obstack
);
3170 /* The hash function for strings in the mapped index. This is the same as
3171 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
3172 implementation. This is necessary because the hash function is tied to the
3173 format of the mapped index file. The hash values do not have to match with
3176 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
3179 mapped_index_string_hash (int index_version
, const void *p
)
3181 const unsigned char *str
= (const unsigned char *) p
;
3185 while ((c
= *str
++) != 0)
3187 if (index_version
>= 5)
3189 r
= r
* 67 + c
- 113;
3195 /* Find a slot in the mapped index INDEX for the object named NAME.
3196 If NAME is found, set *VEC_OUT to point to the CU vector in the
3197 constant pool and return true. If NAME cannot be found, return
3201 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3202 offset_type
**vec_out
)
3205 offset_type slot
, step
;
3206 int (*cmp
) (const char *, const char *);
3208 gdb::unique_xmalloc_ptr
<char> without_params
;
3209 if (current_language
->la_language
== language_cplus
3210 || current_language
->la_language
== language_fortran
3211 || current_language
->la_language
== language_d
)
3213 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3216 if (strchr (name
, '(') != NULL
)
3218 without_params
= cp_remove_params (name
);
3220 if (without_params
!= NULL
)
3221 name
= without_params
.get ();
3225 /* Index version 4 did not support case insensitive searches. But the
3226 indices for case insensitive languages are built in lowercase, therefore
3227 simulate our NAME being searched is also lowercased. */
3228 hash
= mapped_index_string_hash ((index
->version
== 4
3229 && case_sensitivity
== case_sensitive_off
3230 ? 5 : index
->version
),
3233 slot
= hash
& (index
->symbol_table_slots
- 1);
3234 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
3235 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3239 /* Convert a slot number to an offset into the table. */
3240 offset_type i
= 2 * slot
;
3242 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
3245 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
3246 if (!cmp (name
, str
))
3248 *vec_out
= (offset_type
*) (index
->constant_pool
3249 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
3253 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
3257 /* A helper function that reads the .gdb_index from SECTION and fills
3258 in MAP. FILENAME is the name of the file containing the section;
3259 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3260 ok to use deprecated sections.
3262 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3263 out parameters that are filled in with information about the CU and
3264 TU lists in the section.
3266 Returns 1 if all went well, 0 otherwise. */
3269 read_index_from_section (struct objfile
*objfile
,
3270 const char *filename
,
3272 struct dwarf2_section_info
*section
,
3273 struct mapped_index
*map
,
3274 const gdb_byte
**cu_list
,
3275 offset_type
*cu_list_elements
,
3276 const gdb_byte
**types_list
,
3277 offset_type
*types_list_elements
)
3279 const gdb_byte
*addr
;
3280 offset_type version
;
3281 offset_type
*metadata
;
3284 if (dwarf2_section_empty_p (section
))
3287 /* Older elfutils strip versions could keep the section in the main
3288 executable while splitting it for the separate debug info file. */
3289 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3292 dwarf2_read_section (objfile
, section
);
3294 addr
= section
->buffer
;
3295 /* Version check. */
3296 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3297 /* Versions earlier than 3 emitted every copy of a psymbol. This
3298 causes the index to behave very poorly for certain requests. Version 3
3299 contained incomplete addrmap. So, it seems better to just ignore such
3303 static int warning_printed
= 0;
3304 if (!warning_printed
)
3306 warning (_("Skipping obsolete .gdb_index section in %s."),
3308 warning_printed
= 1;
3312 /* Index version 4 uses a different hash function than index version
3315 Versions earlier than 6 did not emit psymbols for inlined
3316 functions. Using these files will cause GDB not to be able to
3317 set breakpoints on inlined functions by name, so we ignore these
3318 indices unless the user has done
3319 "set use-deprecated-index-sections on". */
3320 if (version
< 6 && !deprecated_ok
)
3322 static int warning_printed
= 0;
3323 if (!warning_printed
)
3326 Skipping deprecated .gdb_index section in %s.\n\
3327 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3328 to use the section anyway."),
3330 warning_printed
= 1;
3334 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3335 of the TU (for symbols coming from TUs),
3336 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3337 Plus gold-generated indices can have duplicate entries for global symbols,
3338 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3339 These are just performance bugs, and we can't distinguish gdb-generated
3340 indices from gold-generated ones, so issue no warning here. */
3342 /* Indexes with higher version than the one supported by GDB may be no
3343 longer backward compatible. */
3347 map
->version
= version
;
3348 map
->total_size
= section
->size
;
3350 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3353 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3354 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3358 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3359 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3360 - MAYBE_SWAP (metadata
[i
]))
3364 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3365 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
3366 - MAYBE_SWAP (metadata
[i
]));
3369 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
3370 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
3371 - MAYBE_SWAP (metadata
[i
]))
3372 / (2 * sizeof (offset_type
)));
3375 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3381 /* Read the index file. If everything went ok, initialize the "quick"
3382 elements of all the CUs and return 1. Otherwise, return 0. */
3385 dwarf2_read_index (struct objfile
*objfile
)
3387 struct mapped_index local_map
, *map
;
3388 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3389 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3390 struct dwz_file
*dwz
;
3392 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3393 use_deprecated_index_sections
,
3394 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3395 &cu_list
, &cu_list_elements
,
3396 &types_list
, &types_list_elements
))
3399 /* Don't use the index if it's empty. */
3400 if (local_map
.symbol_table_slots
== 0)
3403 /* If there is a .dwz file, read it so we can get its CU list as
3405 dwz
= dwarf2_get_dwz_file ();
3408 struct mapped_index dwz_map
;
3409 const gdb_byte
*dwz_types_ignore
;
3410 offset_type dwz_types_elements_ignore
;
3412 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3414 &dwz
->gdb_index
, &dwz_map
,
3415 &dwz_list
, &dwz_list_elements
,
3417 &dwz_types_elements_ignore
))
3419 warning (_("could not read '.gdb_index' section from %s; skipping"),
3420 bfd_get_filename (dwz
->dwz_bfd
));
3425 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3428 if (types_list_elements
)
3430 struct dwarf2_section_info
*section
;
3432 /* We can only handle a single .debug_types when we have an
3434 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3437 section
= VEC_index (dwarf2_section_info_def
,
3438 dwarf2_per_objfile
->types
, 0);
3440 create_signatured_type_table_from_index (objfile
, section
, types_list
,
3441 types_list_elements
);
3444 create_addrmap_from_index (objfile
, &local_map
);
3446 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3449 dwarf2_per_objfile
->index_table
= map
;
3450 dwarf2_per_objfile
->using_index
= 1;
3451 dwarf2_per_objfile
->quick_file_names_table
=
3452 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3457 /* A helper for the "quick" functions which sets the global
3458 dwarf2_per_objfile according to OBJFILE. */
3461 dw2_setup (struct objfile
*objfile
)
3463 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
3464 objfile_data (objfile
, dwarf2_objfile_data_key
));
3465 gdb_assert (dwarf2_per_objfile
);
3468 /* die_reader_func for dw2_get_file_names. */
3471 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3472 const gdb_byte
*info_ptr
,
3473 struct die_info
*comp_unit_die
,
3477 struct dwarf2_cu
*cu
= reader
->cu
;
3478 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3479 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3480 struct dwarf2_per_cu_data
*lh_cu
;
3481 struct attribute
*attr
;
3484 struct quick_file_names
*qfn
;
3486 gdb_assert (! this_cu
->is_debug_types
);
3488 /* Our callers never want to match partial units -- instead they
3489 will match the enclosing full CU. */
3490 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3492 this_cu
->v
.quick
->no_file_data
= 1;
3500 sect_offset line_offset
{};
3502 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3505 struct quick_file_names find_entry
;
3507 line_offset
= (sect_offset
) DW_UNSND (attr
);
3509 /* We may have already read in this line header (TU line header sharing).
3510 If we have we're done. */
3511 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3512 find_entry
.hash
.line_sect_off
= line_offset
;
3513 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3514 &find_entry
, INSERT
);
3517 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3521 lh
= dwarf_decode_line_header (line_offset
, cu
);
3525 lh_cu
->v
.quick
->no_file_data
= 1;
3529 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3530 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3531 qfn
->hash
.line_sect_off
= line_offset
;
3532 gdb_assert (slot
!= NULL
);
3535 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3537 qfn
->num_file_names
= lh
->file_names
.size ();
3539 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
3540 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3541 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3542 qfn
->real_names
= NULL
;
3544 lh_cu
->v
.quick
->file_names
= qfn
;
3547 /* A helper for the "quick" functions which attempts to read the line
3548 table for THIS_CU. */
3550 static struct quick_file_names
*
3551 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3553 /* This should never be called for TUs. */
3554 gdb_assert (! this_cu
->is_debug_types
);
3555 /* Nor type unit groups. */
3556 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3558 if (this_cu
->v
.quick
->file_names
!= NULL
)
3559 return this_cu
->v
.quick
->file_names
;
3560 /* If we know there is no line data, no point in looking again. */
3561 if (this_cu
->v
.quick
->no_file_data
)
3564 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3566 if (this_cu
->v
.quick
->no_file_data
)
3568 return this_cu
->v
.quick
->file_names
;
3571 /* A helper for the "quick" functions which computes and caches the
3572 real path for a given file name from the line table. */
3575 dw2_get_real_path (struct objfile
*objfile
,
3576 struct quick_file_names
*qfn
, int index
)
3578 if (qfn
->real_names
== NULL
)
3579 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3580 qfn
->num_file_names
, const char *);
3582 if (qfn
->real_names
[index
] == NULL
)
3583 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3585 return qfn
->real_names
[index
];
3588 static struct symtab
*
3589 dw2_find_last_source_symtab (struct objfile
*objfile
)
3591 struct compunit_symtab
*cust
;
3594 dw2_setup (objfile
);
3595 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3596 cust
= dw2_instantiate_symtab (dw2_get_cutu (index
));
3599 return compunit_primary_filetab (cust
);
3602 /* Traversal function for dw2_forget_cached_source_info. */
3605 dw2_free_cached_file_names (void **slot
, void *info
)
3607 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3609 if (file_data
->real_names
)
3613 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3615 xfree ((void*) file_data
->real_names
[i
]);
3616 file_data
->real_names
[i
] = NULL
;
3624 dw2_forget_cached_source_info (struct objfile
*objfile
)
3626 dw2_setup (objfile
);
3628 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3629 dw2_free_cached_file_names
, NULL
);
3632 /* Helper function for dw2_map_symtabs_matching_filename that expands
3633 the symtabs and calls the iterator. */
3636 dw2_map_expand_apply (struct objfile
*objfile
,
3637 struct dwarf2_per_cu_data
*per_cu
,
3638 const char *name
, const char *real_path
,
3639 gdb::function_view
<bool (symtab
*)> callback
)
3641 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3643 /* Don't visit already-expanded CUs. */
3644 if (per_cu
->v
.quick
->compunit_symtab
)
3647 /* This may expand more than one symtab, and we want to iterate over
3649 dw2_instantiate_symtab (per_cu
);
3651 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3652 last_made
, callback
);
3655 /* Implementation of the map_symtabs_matching_filename method. */
3658 dw2_map_symtabs_matching_filename
3659 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3660 gdb::function_view
<bool (symtab
*)> callback
)
3663 const char *name_basename
= lbasename (name
);
3665 dw2_setup (objfile
);
3667 /* The rule is CUs specify all the files, including those used by
3668 any TU, so there's no need to scan TUs here. */
3670 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3673 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3674 struct quick_file_names
*file_data
;
3676 /* We only need to look at symtabs not already expanded. */
3677 if (per_cu
->v
.quick
->compunit_symtab
)
3680 file_data
= dw2_get_file_names (per_cu
);
3681 if (file_data
== NULL
)
3684 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3686 const char *this_name
= file_data
->file_names
[j
];
3687 const char *this_real_name
;
3689 if (compare_filenames_for_search (this_name
, name
))
3691 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3697 /* Before we invoke realpath, which can get expensive when many
3698 files are involved, do a quick comparison of the basenames. */
3699 if (! basenames_may_differ
3700 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3703 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3704 if (compare_filenames_for_search (this_real_name
, name
))
3706 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3712 if (real_path
!= NULL
)
3714 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3715 gdb_assert (IS_ABSOLUTE_PATH (name
));
3716 if (this_real_name
!= NULL
3717 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3719 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3731 /* Struct used to manage iterating over all CUs looking for a symbol. */
3733 struct dw2_symtab_iterator
3735 /* The internalized form of .gdb_index. */
3736 struct mapped_index
*index
;
3737 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3738 int want_specific_block
;
3739 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3740 Unused if !WANT_SPECIFIC_BLOCK. */
3742 /* The kind of symbol we're looking for. */
3744 /* The list of CUs from the index entry of the symbol,
3745 or NULL if not found. */
3747 /* The next element in VEC to look at. */
3749 /* The number of elements in VEC, or zero if there is no match. */
3751 /* Have we seen a global version of the symbol?
3752 If so we can ignore all further global instances.
3753 This is to work around gold/15646, inefficient gold-generated
3758 /* Initialize the index symtab iterator ITER.
3759 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3760 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3763 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3764 struct mapped_index
*index
,
3765 int want_specific_block
,
3770 iter
->index
= index
;
3771 iter
->want_specific_block
= want_specific_block
;
3772 iter
->block_index
= block_index
;
3773 iter
->domain
= domain
;
3775 iter
->global_seen
= 0;
3777 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3778 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3786 /* Return the next matching CU or NULL if there are no more. */
3788 static struct dwarf2_per_cu_data
*
3789 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3791 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3793 offset_type cu_index_and_attrs
=
3794 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3795 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3796 struct dwarf2_per_cu_data
*per_cu
;
3797 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3798 /* This value is only valid for index versions >= 7. */
3799 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3800 gdb_index_symbol_kind symbol_kind
=
3801 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3802 /* Only check the symbol attributes if they're present.
3803 Indices prior to version 7 don't record them,
3804 and indices >= 7 may elide them for certain symbols
3805 (gold does this). */
3807 (iter
->index
->version
>= 7
3808 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3810 /* Don't crash on bad data. */
3811 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3812 + dwarf2_per_objfile
->n_type_units
))
3814 complaint (&symfile_complaints
,
3815 _(".gdb_index entry has bad CU index"
3817 objfile_name (dwarf2_per_objfile
->objfile
));
3821 per_cu
= dw2_get_cutu (cu_index
);
3823 /* Skip if already read in. */
3824 if (per_cu
->v
.quick
->compunit_symtab
)
3827 /* Check static vs global. */
3830 if (iter
->want_specific_block
3831 && want_static
!= is_static
)
3833 /* Work around gold/15646. */
3834 if (!is_static
&& iter
->global_seen
)
3837 iter
->global_seen
= 1;
3840 /* Only check the symbol's kind if it has one. */
3843 switch (iter
->domain
)
3846 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3847 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3848 /* Some types are also in VAR_DOMAIN. */
3849 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3853 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3857 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3872 static struct compunit_symtab
*
3873 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3874 const char *name
, domain_enum domain
)
3876 struct compunit_symtab
*stab_best
= NULL
;
3877 struct mapped_index
*index
;
3879 dw2_setup (objfile
);
3881 index
= dwarf2_per_objfile
->index_table
;
3883 /* index is NULL if OBJF_READNOW. */
3886 struct dw2_symtab_iterator iter
;
3887 struct dwarf2_per_cu_data
*per_cu
;
3889 dw2_symtab_iter_init (&iter
, index
, 1, block_index
, domain
, name
);
3891 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3893 struct symbol
*sym
, *with_opaque
= NULL
;
3894 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
3895 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3896 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3898 sym
= block_find_symbol (block
, name
, domain
,
3899 block_find_non_opaque_type_preferred
,
3902 /* Some caution must be observed with overloaded functions
3903 and methods, since the index will not contain any overload
3904 information (but NAME might contain it). */
3907 && SYMBOL_MATCHES_SEARCH_NAME (sym
, name
))
3909 if (with_opaque
!= NULL
3910 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, name
))
3913 /* Keep looking through other CUs. */
3921 dw2_print_stats (struct objfile
*objfile
)
3923 int i
, total
, count
;
3925 dw2_setup (objfile
);
3926 total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
3928 for (i
= 0; i
< total
; ++i
)
3930 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3932 if (!per_cu
->v
.quick
->compunit_symtab
)
3935 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3936 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3939 /* This dumps minimal information about the index.
3940 It is called via "mt print objfiles".
3941 One use is to verify .gdb_index has been loaded by the
3942 gdb.dwarf2/gdb-index.exp testcase. */
3945 dw2_dump (struct objfile
*objfile
)
3947 dw2_setup (objfile
);
3948 gdb_assert (dwarf2_per_objfile
->using_index
);
3949 printf_filtered (".gdb_index:");
3950 if (dwarf2_per_objfile
->index_table
!= NULL
)
3952 printf_filtered (" version %d\n",
3953 dwarf2_per_objfile
->index_table
->version
);
3956 printf_filtered (" faked for \"readnow\"\n");
3957 printf_filtered ("\n");
3961 dw2_relocate (struct objfile
*objfile
,
3962 const struct section_offsets
*new_offsets
,
3963 const struct section_offsets
*delta
)
3965 /* There's nothing to relocate here. */
3969 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3970 const char *func_name
)
3972 struct mapped_index
*index
;
3974 dw2_setup (objfile
);
3976 index
= dwarf2_per_objfile
->index_table
;
3978 /* index is NULL if OBJF_READNOW. */
3981 struct dw2_symtab_iterator iter
;
3982 struct dwarf2_per_cu_data
*per_cu
;
3984 /* Note: It doesn't matter what we pass for block_index here. */
3985 dw2_symtab_iter_init (&iter
, index
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
3988 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3989 dw2_instantiate_symtab (per_cu
);
3994 dw2_expand_all_symtabs (struct objfile
*objfile
)
3998 dw2_setup (objfile
);
4000 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
4001 + dwarf2_per_objfile
->n_type_units
); ++i
)
4003 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4005 dw2_instantiate_symtab (per_cu
);
4010 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4011 const char *fullname
)
4015 dw2_setup (objfile
);
4017 /* We don't need to consider type units here.
4018 This is only called for examining code, e.g. expand_line_sal.
4019 There can be an order of magnitude (or more) more type units
4020 than comp units, and we avoid them if we can. */
4022 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4025 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4026 struct quick_file_names
*file_data
;
4028 /* We only need to look at symtabs not already expanded. */
4029 if (per_cu
->v
.quick
->compunit_symtab
)
4032 file_data
= dw2_get_file_names (per_cu
);
4033 if (file_data
== NULL
)
4036 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4038 const char *this_fullname
= file_data
->file_names
[j
];
4040 if (filename_cmp (this_fullname
, fullname
) == 0)
4042 dw2_instantiate_symtab (per_cu
);
4050 dw2_map_matching_symbols (struct objfile
*objfile
,
4051 const char * name
, domain_enum domain
,
4053 int (*callback
) (struct block
*,
4054 struct symbol
*, void *),
4055 void *data
, symbol_compare_ftype
*match
,
4056 symbol_compare_ftype
*ordered_compare
)
4058 /* Currently unimplemented; used for Ada. The function can be called if the
4059 current language is Ada for a non-Ada objfile using GNU index. As Ada
4060 does not look for non-Ada symbols this function should just return. */
4064 dw2_expand_symtabs_matching
4065 (struct objfile
*objfile
,
4066 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4067 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4068 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4069 enum search_domain kind
)
4073 struct mapped_index
*index
;
4075 dw2_setup (objfile
);
4077 /* index_table is NULL if OBJF_READNOW. */
4078 if (!dwarf2_per_objfile
->index_table
)
4080 index
= dwarf2_per_objfile
->index_table
;
4082 if (file_matcher
!= NULL
)
4084 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4086 NULL
, xcalloc
, xfree
));
4087 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4089 NULL
, xcalloc
, xfree
));
4091 /* The rule is CUs specify all the files, including those used by
4092 any TU, so there's no need to scan TUs here. */
4094 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4097 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4098 struct quick_file_names
*file_data
;
4103 per_cu
->v
.quick
->mark
= 0;
4105 /* We only need to look at symtabs not already expanded. */
4106 if (per_cu
->v
.quick
->compunit_symtab
)
4109 file_data
= dw2_get_file_names (per_cu
);
4110 if (file_data
== NULL
)
4113 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4115 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4117 per_cu
->v
.quick
->mark
= 1;
4121 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4123 const char *this_real_name
;
4125 if (file_matcher (file_data
->file_names
[j
], false))
4127 per_cu
->v
.quick
->mark
= 1;
4131 /* Before we invoke realpath, which can get expensive when many
4132 files are involved, do a quick comparison of the basenames. */
4133 if (!basenames_may_differ
4134 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4138 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4139 if (file_matcher (this_real_name
, false))
4141 per_cu
->v
.quick
->mark
= 1;
4146 slot
= htab_find_slot (per_cu
->v
.quick
->mark
4147 ? visited_found
.get ()
4148 : visited_not_found
.get (),
4154 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
4156 offset_type idx
= 2 * iter
;
4158 offset_type
*vec
, vec_len
, vec_idx
;
4159 int global_seen
= 0;
4163 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
4166 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
4168 if (!symbol_matcher (name
))
4171 /* The name was matched, now expand corresponding CUs that were
4173 vec
= (offset_type
*) (index
->constant_pool
4174 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
4175 vec_len
= MAYBE_SWAP (vec
[0]);
4176 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4178 struct dwarf2_per_cu_data
*per_cu
;
4179 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4180 /* This value is only valid for index versions >= 7. */
4181 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4182 gdb_index_symbol_kind symbol_kind
=
4183 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4184 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4185 /* Only check the symbol attributes if they're present.
4186 Indices prior to version 7 don't record them,
4187 and indices >= 7 may elide them for certain symbols
4188 (gold does this). */
4190 (index
->version
>= 7
4191 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4193 /* Work around gold/15646. */
4196 if (!is_static
&& global_seen
)
4202 /* Only check the symbol's kind if it has one. */
4207 case VARIABLES_DOMAIN
:
4208 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4211 case FUNCTIONS_DOMAIN
:
4212 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4216 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4224 /* Don't crash on bad data. */
4225 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
4226 + dwarf2_per_objfile
->n_type_units
))
4228 complaint (&symfile_complaints
,
4229 _(".gdb_index entry has bad CU index"
4230 " [in module %s]"), objfile_name (objfile
));
4234 per_cu
= dw2_get_cutu (cu_index
);
4235 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4237 int symtab_was_null
=
4238 (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4240 dw2_instantiate_symtab (per_cu
);
4242 if (expansion_notify
!= NULL
4244 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4246 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4253 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4256 static struct compunit_symtab
*
4257 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4262 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4263 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4266 if (cust
->includes
== NULL
)
4269 for (i
= 0; cust
->includes
[i
]; ++i
)
4271 struct compunit_symtab
*s
= cust
->includes
[i
];
4273 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4281 static struct compunit_symtab
*
4282 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4283 struct bound_minimal_symbol msymbol
,
4285 struct obj_section
*section
,
4288 struct dwarf2_per_cu_data
*data
;
4289 struct compunit_symtab
*result
;
4291 dw2_setup (objfile
);
4293 if (!objfile
->psymtabs_addrmap
)
4296 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
4301 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4302 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4303 paddress (get_objfile_arch (objfile
), pc
));
4306 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
4308 gdb_assert (result
!= NULL
);
4313 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4314 void *data
, int need_fullname
)
4316 dw2_setup (objfile
);
4318 if (!dwarf2_per_objfile
->filenames_cache
)
4320 dwarf2_per_objfile
->filenames_cache
.emplace ();
4322 htab_up
visited (htab_create_alloc (10,
4323 htab_hash_pointer
, htab_eq_pointer
,
4324 NULL
, xcalloc
, xfree
));
4326 /* The rule is CUs specify all the files, including those used
4327 by any TU, so there's no need to scan TUs here. We can
4328 ignore file names coming from already-expanded CUs. */
4330 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4332 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4334 if (per_cu
->v
.quick
->compunit_symtab
)
4336 void **slot
= htab_find_slot (visited
.get (),
4337 per_cu
->v
.quick
->file_names
,
4340 *slot
= per_cu
->v
.quick
->file_names
;
4344 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4347 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4348 struct quick_file_names
*file_data
;
4351 /* We only need to look at symtabs not already expanded. */
4352 if (per_cu
->v
.quick
->compunit_symtab
)
4355 file_data
= dw2_get_file_names (per_cu
);
4356 if (file_data
== NULL
)
4359 slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4362 /* Already visited. */
4367 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4369 const char *filename
= file_data
->file_names
[j
];
4370 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4375 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4377 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4380 this_real_name
= gdb_realpath (filename
);
4381 (*fun
) (filename
, this_real_name
.get (), data
);
4386 dw2_has_symbols (struct objfile
*objfile
)
4391 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4394 dw2_find_last_source_symtab
,
4395 dw2_forget_cached_source_info
,
4396 dw2_map_symtabs_matching_filename
,
4401 dw2_expand_symtabs_for_function
,
4402 dw2_expand_all_symtabs
,
4403 dw2_expand_symtabs_with_fullname
,
4404 dw2_map_matching_symbols
,
4405 dw2_expand_symtabs_matching
,
4406 dw2_find_pc_sect_compunit_symtab
,
4407 dw2_map_symbol_filenames
4410 /* Initialize for reading DWARF for this objfile. Return 0 if this
4411 file will use psymtabs, or 1 if using the GNU index. */
4414 dwarf2_initialize_objfile (struct objfile
*objfile
)
4416 /* If we're about to read full symbols, don't bother with the
4417 indices. In this case we also don't care if some other debug
4418 format is making psymtabs, because they are all about to be
4420 if ((objfile
->flags
& OBJF_READNOW
))
4424 dwarf2_per_objfile
->using_index
= 1;
4425 create_all_comp_units (objfile
);
4426 create_all_type_units (objfile
);
4427 dwarf2_per_objfile
->quick_file_names_table
=
4428 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
4430 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
4431 + dwarf2_per_objfile
->n_type_units
); ++i
)
4433 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4435 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4436 struct dwarf2_per_cu_quick_data
);
4439 /* Return 1 so that gdb sees the "quick" functions. However,
4440 these functions will be no-ops because we will have expanded
4445 if (dwarf2_read_index (objfile
))
4453 /* Build a partial symbol table. */
4456 dwarf2_build_psymtabs (struct objfile
*objfile
)
4459 if (objfile
->global_psymbols
.capacity () == 0
4460 && objfile
->static_psymbols
.capacity () == 0)
4461 init_psymbol_list (objfile
, 1024);
4465 /* This isn't really ideal: all the data we allocate on the
4466 objfile's obstack is still uselessly kept around. However,
4467 freeing it seems unsafe. */
4468 psymtab_discarder
psymtabs (objfile
);
4469 dwarf2_build_psymtabs_hard (objfile
);
4472 CATCH (except
, RETURN_MASK_ERROR
)
4474 exception_print (gdb_stderr
, except
);
4479 /* Return the total length of the CU described by HEADER. */
4482 get_cu_length (const struct comp_unit_head
*header
)
4484 return header
->initial_length_size
+ header
->length
;
4487 /* Return TRUE if SECT_OFF is within CU_HEADER. */
4490 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
4492 sect_offset bottom
= cu_header
->sect_off
;
4493 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
4495 return sect_off
>= bottom
&& sect_off
< top
;
4498 /* Find the base address of the compilation unit for range lists and
4499 location lists. It will normally be specified by DW_AT_low_pc.
4500 In DWARF-3 draft 4, the base address could be overridden by
4501 DW_AT_entry_pc. It's been removed, but GCC still uses this for
4502 compilation units with discontinuous ranges. */
4505 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
4507 struct attribute
*attr
;
4510 cu
->base_address
= 0;
4512 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
4515 cu
->base_address
= attr_value_as_address (attr
);
4520 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4523 cu
->base_address
= attr_value_as_address (attr
);
4529 /* Read in the comp unit header information from the debug_info at info_ptr.
4530 Use rcuh_kind::COMPILE as the default type if not known by the caller.
4531 NOTE: This leaves members offset, first_die_offset to be filled in
4534 static const gdb_byte
*
4535 read_comp_unit_head (struct comp_unit_head
*cu_header
,
4536 const gdb_byte
*info_ptr
,
4537 struct dwarf2_section_info
*section
,
4538 rcuh_kind section_kind
)
4541 unsigned int bytes_read
;
4542 const char *filename
= get_section_file_name (section
);
4543 bfd
*abfd
= get_section_bfd_owner (section
);
4545 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
4546 cu_header
->initial_length_size
= bytes_read
;
4547 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
4548 info_ptr
+= bytes_read
;
4549 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
4551 if (cu_header
->version
< 5)
4552 switch (section_kind
)
4554 case rcuh_kind::COMPILE
:
4555 cu_header
->unit_type
= DW_UT_compile
;
4557 case rcuh_kind::TYPE
:
4558 cu_header
->unit_type
= DW_UT_type
;
4561 internal_error (__FILE__
, __LINE__
,
4562 _("read_comp_unit_head: invalid section_kind"));
4566 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
4567 (read_1_byte (abfd
, info_ptr
));
4569 switch (cu_header
->unit_type
)
4572 if (section_kind
!= rcuh_kind::COMPILE
)
4573 error (_("Dwarf Error: wrong unit_type in compilation unit header "
4574 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
4578 section_kind
= rcuh_kind::TYPE
;
4581 error (_("Dwarf Error: wrong unit_type in compilation unit header "
4582 "(is %d, should be %d or %d) [in module %s]"),
4583 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
4586 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
4589 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
4592 info_ptr
+= bytes_read
;
4593 if (cu_header
->version
< 5)
4595 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
4598 signed_addr
= bfd_get_sign_extend_vma (abfd
);
4599 if (signed_addr
< 0)
4600 internal_error (__FILE__
, __LINE__
,
4601 _("read_comp_unit_head: dwarf from non elf file"));
4602 cu_header
->signed_addr_p
= signed_addr
;
4604 if (section_kind
== rcuh_kind::TYPE
)
4606 LONGEST type_offset
;
4608 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
4611 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
4612 info_ptr
+= bytes_read
;
4613 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
4614 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
4615 error (_("Dwarf Error: Too big type_offset in compilation unit "
4616 "header (is %s) [in module %s]"), plongest (type_offset
),
4623 /* Helper function that returns the proper abbrev section for
4626 static struct dwarf2_section_info
*
4627 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
4629 struct dwarf2_section_info
*abbrev
;
4631 if (this_cu
->is_dwz
)
4632 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
4634 abbrev
= &dwarf2_per_objfile
->abbrev
;
4639 /* Subroutine of read_and_check_comp_unit_head and
4640 read_and_check_type_unit_head to simplify them.
4641 Perform various error checking on the header. */
4644 error_check_comp_unit_head (struct comp_unit_head
*header
,
4645 struct dwarf2_section_info
*section
,
4646 struct dwarf2_section_info
*abbrev_section
)
4648 const char *filename
= get_section_file_name (section
);
4650 if (header
->version
< 2 || header
->version
> 5)
4651 error (_("Dwarf Error: wrong version in compilation unit header "
4652 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
4655 if (to_underlying (header
->abbrev_sect_off
)
4656 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
4657 error (_("Dwarf Error: bad offset (0x%x) in compilation unit header "
4658 "(offset 0x%x + 6) [in module %s]"),
4659 to_underlying (header
->abbrev_sect_off
),
4660 to_underlying (header
->sect_off
),
4663 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
4664 avoid potential 32-bit overflow. */
4665 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
4667 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
4668 "(offset 0x%x + 0) [in module %s]"),
4669 header
->length
, to_underlying (header
->sect_off
),
4673 /* Read in a CU/TU header and perform some basic error checking.
4674 The contents of the header are stored in HEADER.
4675 The result is a pointer to the start of the first DIE. */
4677 static const gdb_byte
*
4678 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
4679 struct dwarf2_section_info
*section
,
4680 struct dwarf2_section_info
*abbrev_section
,
4681 const gdb_byte
*info_ptr
,
4682 rcuh_kind section_kind
)
4684 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
4685 bfd
*abfd
= get_section_bfd_owner (section
);
4687 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
4689 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
4691 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
4693 error_check_comp_unit_head (header
, section
, abbrev_section
);
4698 /* Fetch the abbreviation table offset from a comp or type unit header. */
4701 read_abbrev_offset (struct dwarf2_section_info
*section
,
4702 sect_offset sect_off
)
4704 bfd
*abfd
= get_section_bfd_owner (section
);
4705 const gdb_byte
*info_ptr
;
4706 unsigned int initial_length_size
, offset_size
;
4709 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
4710 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
4711 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
4712 offset_size
= initial_length_size
== 4 ? 4 : 8;
4713 info_ptr
+= initial_length_size
;
4715 version
= read_2_bytes (abfd
, info_ptr
);
4719 /* Skip unit type and address size. */
4723 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
4726 /* Allocate a new partial symtab for file named NAME and mark this new
4727 partial symtab as being an include of PST. */
4730 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
4731 struct objfile
*objfile
)
4733 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
4735 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
4737 /* It shares objfile->objfile_obstack. */
4738 subpst
->dirname
= pst
->dirname
;
4741 subpst
->textlow
= 0;
4742 subpst
->texthigh
= 0;
4744 subpst
->dependencies
4745 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
4746 subpst
->dependencies
[0] = pst
;
4747 subpst
->number_of_dependencies
= 1;
4749 subpst
->globals_offset
= 0;
4750 subpst
->n_global_syms
= 0;
4751 subpst
->statics_offset
= 0;
4752 subpst
->n_static_syms
= 0;
4753 subpst
->compunit_symtab
= NULL
;
4754 subpst
->read_symtab
= pst
->read_symtab
;
4757 /* No private part is necessary for include psymtabs. This property
4758 can be used to differentiate between such include psymtabs and
4759 the regular ones. */
4760 subpst
->read_symtab_private
= NULL
;
4763 /* Read the Line Number Program data and extract the list of files
4764 included by the source file represented by PST. Build an include
4765 partial symtab for each of these included files. */
4768 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4769 struct die_info
*die
,
4770 struct partial_symtab
*pst
)
4773 struct attribute
*attr
;
4775 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4777 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
4779 return; /* No linetable, so no includes. */
4781 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4782 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
4786 hash_signatured_type (const void *item
)
4788 const struct signatured_type
*sig_type
4789 = (const struct signatured_type
*) item
;
4791 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4792 return sig_type
->signature
;
4796 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4798 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
4799 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
4801 return lhs
->signature
== rhs
->signature
;
4804 /* Allocate a hash table for signatured types. */
4807 allocate_signatured_type_table (struct objfile
*objfile
)
4809 return htab_create_alloc_ex (41,
4810 hash_signatured_type
,
4813 &objfile
->objfile_obstack
,
4814 hashtab_obstack_allocate
,
4815 dummy_obstack_deallocate
);
4818 /* A helper function to add a signatured type CU to a table. */
4821 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4823 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
4824 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
4832 /* A helper for create_debug_types_hash_table. Read types from SECTION
4833 and fill them into TYPES_HTAB. It will process only type units,
4834 therefore DW_UT_type. */
4837 create_debug_type_hash_table (struct dwo_file
*dwo_file
,
4838 dwarf2_section_info
*section
, htab_t
&types_htab
,
4839 rcuh_kind section_kind
)
4841 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4842 struct dwarf2_section_info
*abbrev_section
;
4844 const gdb_byte
*info_ptr
, *end_ptr
;
4846 abbrev_section
= (dwo_file
!= NULL
4847 ? &dwo_file
->sections
.abbrev
4848 : &dwarf2_per_objfile
->abbrev
);
4850 if (dwarf_read_debug
)
4851 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
4852 get_section_name (section
),
4853 get_section_file_name (abbrev_section
));
4855 dwarf2_read_section (objfile
, section
);
4856 info_ptr
= section
->buffer
;
4858 if (info_ptr
== NULL
)
4861 /* We can't set abfd until now because the section may be empty or
4862 not present, in which case the bfd is unknown. */
4863 abfd
= get_section_bfd_owner (section
);
4865 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4866 because we don't need to read any dies: the signature is in the
4869 end_ptr
= info_ptr
+ section
->size
;
4870 while (info_ptr
< end_ptr
)
4872 struct signatured_type
*sig_type
;
4873 struct dwo_unit
*dwo_tu
;
4875 const gdb_byte
*ptr
= info_ptr
;
4876 struct comp_unit_head header
;
4877 unsigned int length
;
4879 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
4881 /* Initialize it due to a false compiler warning. */
4882 header
.signature
= -1;
4883 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
4885 /* We need to read the type's signature in order to build the hash
4886 table, but we don't need anything else just yet. */
4888 ptr
= read_and_check_comp_unit_head (&header
, section
,
4889 abbrev_section
, ptr
, section_kind
);
4891 length
= get_cu_length (&header
);
4893 /* Skip dummy type units. */
4894 if (ptr
>= info_ptr
+ length
4895 || peek_abbrev_code (abfd
, ptr
) == 0
4896 || header
.unit_type
!= DW_UT_type
)
4902 if (types_htab
== NULL
)
4905 types_htab
= allocate_dwo_unit_table (objfile
);
4907 types_htab
= allocate_signatured_type_table (objfile
);
4913 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4915 dwo_tu
->dwo_file
= dwo_file
;
4916 dwo_tu
->signature
= header
.signature
;
4917 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
4918 dwo_tu
->section
= section
;
4919 dwo_tu
->sect_off
= sect_off
;
4920 dwo_tu
->length
= length
;
4924 /* N.B.: type_offset is not usable if this type uses a DWO file.
4925 The real type_offset is in the DWO file. */
4927 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4928 struct signatured_type
);
4929 sig_type
->signature
= header
.signature
;
4930 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
4931 sig_type
->per_cu
.objfile
= objfile
;
4932 sig_type
->per_cu
.is_debug_types
= 1;
4933 sig_type
->per_cu
.section
= section
;
4934 sig_type
->per_cu
.sect_off
= sect_off
;
4935 sig_type
->per_cu
.length
= length
;
4938 slot
= htab_find_slot (types_htab
,
4939 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4941 gdb_assert (slot
!= NULL
);
4944 sect_offset dup_sect_off
;
4948 const struct dwo_unit
*dup_tu
4949 = (const struct dwo_unit
*) *slot
;
4951 dup_sect_off
= dup_tu
->sect_off
;
4955 const struct signatured_type
*dup_tu
4956 = (const struct signatured_type
*) *slot
;
4958 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
4961 complaint (&symfile_complaints
,
4962 _("debug type entry at offset 0x%x is duplicate to"
4963 " the entry at offset 0x%x, signature %s"),
4964 to_underlying (sect_off
), to_underlying (dup_sect_off
),
4965 hex_string (header
.signature
));
4967 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4969 if (dwarf_read_debug
> 1)
4970 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature %s\n",
4971 to_underlying (sect_off
),
4972 hex_string (header
.signature
));
4978 /* Create the hash table of all entries in the .debug_types
4979 (or .debug_types.dwo) section(s).
4980 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
4981 otherwise it is NULL.
4983 The result is a pointer to the hash table or NULL if there are no types.
4985 Note: This function processes DWO files only, not DWP files. */
4988 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4989 VEC (dwarf2_section_info_def
) *types
,
4993 struct dwarf2_section_info
*section
;
4995 if (VEC_empty (dwarf2_section_info_def
, types
))
4999 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
5001 create_debug_type_hash_table (dwo_file
, section
, types_htab
,
5005 /* Create the hash table of all entries in the .debug_types section,
5006 and initialize all_type_units.
5007 The result is zero if there is an error (e.g. missing .debug_types section),
5008 otherwise non-zero. */
5011 create_all_type_units (struct objfile
*objfile
)
5013 htab_t types_htab
= NULL
;
5014 struct signatured_type
**iter
;
5016 create_debug_type_hash_table (NULL
, &dwarf2_per_objfile
->info
, types_htab
,
5017 rcuh_kind::COMPILE
);
5018 create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
, types_htab
);
5019 if (types_htab
== NULL
)
5021 dwarf2_per_objfile
->signatured_types
= NULL
;
5025 dwarf2_per_objfile
->signatured_types
= types_htab
;
5027 dwarf2_per_objfile
->n_type_units
5028 = dwarf2_per_objfile
->n_allocated_type_units
5029 = htab_elements (types_htab
);
5030 dwarf2_per_objfile
->all_type_units
=
5031 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
5032 iter
= &dwarf2_per_objfile
->all_type_units
[0];
5033 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
5034 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
5035 == dwarf2_per_objfile
->n_type_units
);
5040 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
5041 If SLOT is non-NULL, it is the entry to use in the hash table.
5042 Otherwise we find one. */
5044 static struct signatured_type
*
5045 add_type_unit (ULONGEST sig
, void **slot
)
5047 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5048 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
5049 struct signatured_type
*sig_type
;
5051 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
5053 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
5055 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
5056 dwarf2_per_objfile
->n_allocated_type_units
= 1;
5057 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
5058 dwarf2_per_objfile
->all_type_units
5059 = XRESIZEVEC (struct signatured_type
*,
5060 dwarf2_per_objfile
->all_type_units
,
5061 dwarf2_per_objfile
->n_allocated_type_units
);
5062 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
5064 dwarf2_per_objfile
->n_type_units
= n_type_units
;
5066 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5067 struct signatured_type
);
5068 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
5069 sig_type
->signature
= sig
;
5070 sig_type
->per_cu
.is_debug_types
= 1;
5071 if (dwarf2_per_objfile
->using_index
)
5073 sig_type
->per_cu
.v
.quick
=
5074 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5075 struct dwarf2_per_cu_quick_data
);
5080 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5083 gdb_assert (*slot
== NULL
);
5085 /* The rest of sig_type must be filled in by the caller. */
5089 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
5090 Fill in SIG_ENTRY with DWO_ENTRY. */
5093 fill_in_sig_entry_from_dwo_entry (struct objfile
*objfile
,
5094 struct signatured_type
*sig_entry
,
5095 struct dwo_unit
*dwo_entry
)
5097 /* Make sure we're not clobbering something we don't expect to. */
5098 gdb_assert (! sig_entry
->per_cu
.queued
);
5099 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
5100 if (dwarf2_per_objfile
->using_index
)
5102 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
5103 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
5106 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
5107 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
5108 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
5109 gdb_assert (sig_entry
->type_unit_group
== NULL
);
5110 gdb_assert (sig_entry
->dwo_unit
== NULL
);
5112 sig_entry
->per_cu
.section
= dwo_entry
->section
;
5113 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
5114 sig_entry
->per_cu
.length
= dwo_entry
->length
;
5115 sig_entry
->per_cu
.reading_dwo_directly
= 1;
5116 sig_entry
->per_cu
.objfile
= objfile
;
5117 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
5118 sig_entry
->dwo_unit
= dwo_entry
;
5121 /* Subroutine of lookup_signatured_type.
5122 If we haven't read the TU yet, create the signatured_type data structure
5123 for a TU to be read in directly from a DWO file, bypassing the stub.
5124 This is the "Stay in DWO Optimization": When there is no DWP file and we're
5125 using .gdb_index, then when reading a CU we want to stay in the DWO file
5126 containing that CU. Otherwise we could end up reading several other DWO
5127 files (due to comdat folding) to process the transitive closure of all the
5128 mentioned TUs, and that can be slow. The current DWO file will have every
5129 type signature that it needs.
5130 We only do this for .gdb_index because in the psymtab case we already have
5131 to read all the DWOs to build the type unit groups. */
5133 static struct signatured_type
*
5134 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5136 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5137 struct dwo_file
*dwo_file
;
5138 struct dwo_unit find_dwo_entry
, *dwo_entry
;
5139 struct signatured_type find_sig_entry
, *sig_entry
;
5142 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
5144 /* If TU skeletons have been removed then we may not have read in any
5146 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5148 dwarf2_per_objfile
->signatured_types
5149 = allocate_signatured_type_table (objfile
);
5152 /* We only ever need to read in one copy of a signatured type.
5153 Use the global signatured_types array to do our own comdat-folding
5154 of types. If this is the first time we're reading this TU, and
5155 the TU has an entry in .gdb_index, replace the recorded data from
5156 .gdb_index with this TU. */
5158 find_sig_entry
.signature
= sig
;
5159 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5160 &find_sig_entry
, INSERT
);
5161 sig_entry
= (struct signatured_type
*) *slot
;
5163 /* We can get here with the TU already read, *or* in the process of being
5164 read. Don't reassign the global entry to point to this DWO if that's
5165 the case. Also note that if the TU is already being read, it may not
5166 have come from a DWO, the program may be a mix of Fission-compiled
5167 code and non-Fission-compiled code. */
5169 /* Have we already tried to read this TU?
5170 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5171 needn't exist in the global table yet). */
5172 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
5175 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
5176 dwo_unit of the TU itself. */
5177 dwo_file
= cu
->dwo_unit
->dwo_file
;
5179 /* Ok, this is the first time we're reading this TU. */
5180 if (dwo_file
->tus
== NULL
)
5182 find_dwo_entry
.signature
= sig
;
5183 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
5184 if (dwo_entry
== NULL
)
5187 /* If the global table doesn't have an entry for this TU, add one. */
5188 if (sig_entry
== NULL
)
5189 sig_entry
= add_type_unit (sig
, slot
);
5191 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
5192 sig_entry
->per_cu
.tu_read
= 1;
5196 /* Subroutine of lookup_signatured_type.
5197 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
5198 then try the DWP file. If the TU stub (skeleton) has been removed then
5199 it won't be in .gdb_index. */
5201 static struct signatured_type
*
5202 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5204 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5205 struct dwp_file
*dwp_file
= get_dwp_file ();
5206 struct dwo_unit
*dwo_entry
;
5207 struct signatured_type find_sig_entry
, *sig_entry
;
5210 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
5211 gdb_assert (dwp_file
!= NULL
);
5213 /* If TU skeletons have been removed then we may not have read in any
5215 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5217 dwarf2_per_objfile
->signatured_types
5218 = allocate_signatured_type_table (objfile
);
5221 find_sig_entry
.signature
= sig
;
5222 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5223 &find_sig_entry
, INSERT
);
5224 sig_entry
= (struct signatured_type
*) *slot
;
5226 /* Have we already tried to read this TU?
5227 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5228 needn't exist in the global table yet). */
5229 if (sig_entry
!= NULL
)
5232 if (dwp_file
->tus
== NULL
)
5234 dwo_entry
= lookup_dwo_unit_in_dwp (dwp_file
, NULL
,
5235 sig
, 1 /* is_debug_types */);
5236 if (dwo_entry
== NULL
)
5239 sig_entry
= add_type_unit (sig
, slot
);
5240 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
5245 /* Lookup a signature based type for DW_FORM_ref_sig8.
5246 Returns NULL if signature SIG is not present in the table.
5247 It is up to the caller to complain about this. */
5249 static struct signatured_type
*
5250 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5253 && dwarf2_per_objfile
->using_index
)
5255 /* We're in a DWO/DWP file, and we're using .gdb_index.
5256 These cases require special processing. */
5257 if (get_dwp_file () == NULL
)
5258 return lookup_dwo_signatured_type (cu
, sig
);
5260 return lookup_dwp_signatured_type (cu
, sig
);
5264 struct signatured_type find_entry
, *entry
;
5266 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5268 find_entry
.signature
= sig
;
5269 entry
= ((struct signatured_type
*)
5270 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
5275 /* Low level DIE reading support. */
5277 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
5280 init_cu_die_reader (struct die_reader_specs
*reader
,
5281 struct dwarf2_cu
*cu
,
5282 struct dwarf2_section_info
*section
,
5283 struct dwo_file
*dwo_file
)
5285 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
5286 reader
->abfd
= get_section_bfd_owner (section
);
5288 reader
->dwo_file
= dwo_file
;
5289 reader
->die_section
= section
;
5290 reader
->buffer
= section
->buffer
;
5291 reader
->buffer_end
= section
->buffer
+ section
->size
;
5292 reader
->comp_dir
= NULL
;
5295 /* Subroutine of init_cutu_and_read_dies to simplify it.
5296 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
5297 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
5300 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
5301 from it to the DIE in the DWO. If NULL we are skipping the stub.
5302 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
5303 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
5304 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
5305 STUB_COMP_DIR may be non-NULL.
5306 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
5307 are filled in with the info of the DIE from the DWO file.
5308 ABBREV_TABLE_PROVIDED is non-zero if the caller of init_cutu_and_read_dies
5309 provided an abbrev table to use.
5310 The result is non-zero if a valid (non-dummy) DIE was found. */
5313 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
5314 struct dwo_unit
*dwo_unit
,
5315 int abbrev_table_provided
,
5316 struct die_info
*stub_comp_unit_die
,
5317 const char *stub_comp_dir
,
5318 struct die_reader_specs
*result_reader
,
5319 const gdb_byte
**result_info_ptr
,
5320 struct die_info
**result_comp_unit_die
,
5321 int *result_has_children
)
5323 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5324 struct dwarf2_cu
*cu
= this_cu
->cu
;
5325 struct dwarf2_section_info
*section
;
5327 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5328 ULONGEST signature
; /* Or dwo_id. */
5329 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
5330 int i
,num_extra_attrs
;
5331 struct dwarf2_section_info
*dwo_abbrev_section
;
5332 struct attribute
*attr
;
5333 struct die_info
*comp_unit_die
;
5335 /* At most one of these may be provided. */
5336 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
5338 /* These attributes aren't processed until later:
5339 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
5340 DW_AT_comp_dir is used now, to find the DWO file, but it is also
5341 referenced later. However, these attributes are found in the stub
5342 which we won't have later. In order to not impose this complication
5343 on the rest of the code, we read them here and copy them to the
5352 if (stub_comp_unit_die
!= NULL
)
5354 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
5356 if (! this_cu
->is_debug_types
)
5357 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
5358 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
5359 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
5360 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
5361 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
5363 /* There should be a DW_AT_addr_base attribute here (if needed).
5364 We need the value before we can process DW_FORM_GNU_addr_index. */
5366 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
5368 cu
->addr_base
= DW_UNSND (attr
);
5370 /* There should be a DW_AT_ranges_base attribute here (if needed).
5371 We need the value before we can process DW_AT_ranges. */
5372 cu
->ranges_base
= 0;
5373 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
5375 cu
->ranges_base
= DW_UNSND (attr
);
5377 else if (stub_comp_dir
!= NULL
)
5379 /* Reconstruct the comp_dir attribute to simplify the code below. */
5380 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
5381 comp_dir
->name
= DW_AT_comp_dir
;
5382 comp_dir
->form
= DW_FORM_string
;
5383 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
5384 DW_STRING (comp_dir
) = stub_comp_dir
;
5387 /* Set up for reading the DWO CU/TU. */
5388 cu
->dwo_unit
= dwo_unit
;
5389 section
= dwo_unit
->section
;
5390 dwarf2_read_section (objfile
, section
);
5391 abfd
= get_section_bfd_owner (section
);
5392 begin_info_ptr
= info_ptr
= (section
->buffer
5393 + to_underlying (dwo_unit
->sect_off
));
5394 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
5395 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
);
5397 if (this_cu
->is_debug_types
)
5399 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
5401 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5403 info_ptr
, rcuh_kind::TYPE
);
5404 /* This is not an assert because it can be caused by bad debug info. */
5405 if (sig_type
->signature
!= cu
->header
.signature
)
5407 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
5408 " TU at offset 0x%x [in module %s]"),
5409 hex_string (sig_type
->signature
),
5410 hex_string (cu
->header
.signature
),
5411 to_underlying (dwo_unit
->sect_off
),
5412 bfd_get_filename (abfd
));
5414 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
5415 /* For DWOs coming from DWP files, we don't know the CU length
5416 nor the type's offset in the TU until now. */
5417 dwo_unit
->length
= get_cu_length (&cu
->header
);
5418 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
5420 /* Establish the type offset that can be used to lookup the type.
5421 For DWO files, we don't know it until now. */
5422 sig_type
->type_offset_in_section
5423 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
5427 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5429 info_ptr
, rcuh_kind::COMPILE
);
5430 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
5431 /* For DWOs coming from DWP files, we don't know the CU length
5433 dwo_unit
->length
= get_cu_length (&cu
->header
);
5436 /* Replace the CU's original abbrev table with the DWO's.
5437 Reminder: We can't read the abbrev table until we've read the header. */
5438 if (abbrev_table_provided
)
5440 /* Don't free the provided abbrev table, the caller of
5441 init_cutu_and_read_dies owns it. */
5442 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5443 /* Ensure the DWO abbrev table gets freed. */
5444 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5448 dwarf2_free_abbrev_table (cu
);
5449 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5450 /* Leave any existing abbrev table cleanup as is. */
5453 /* Read in the die, but leave space to copy over the attributes
5454 from the stub. This has the benefit of simplifying the rest of
5455 the code - all the work to maintain the illusion of a single
5456 DW_TAG_{compile,type}_unit DIE is done here. */
5457 num_extra_attrs
= ((stmt_list
!= NULL
)
5461 + (comp_dir
!= NULL
));
5462 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
5463 result_has_children
, num_extra_attrs
);
5465 /* Copy over the attributes from the stub to the DIE we just read in. */
5466 comp_unit_die
= *result_comp_unit_die
;
5467 i
= comp_unit_die
->num_attrs
;
5468 if (stmt_list
!= NULL
)
5469 comp_unit_die
->attrs
[i
++] = *stmt_list
;
5471 comp_unit_die
->attrs
[i
++] = *low_pc
;
5472 if (high_pc
!= NULL
)
5473 comp_unit_die
->attrs
[i
++] = *high_pc
;
5475 comp_unit_die
->attrs
[i
++] = *ranges
;
5476 if (comp_dir
!= NULL
)
5477 comp_unit_die
->attrs
[i
++] = *comp_dir
;
5478 comp_unit_die
->num_attrs
+= num_extra_attrs
;
5480 if (dwarf_die_debug
)
5482 fprintf_unfiltered (gdb_stdlog
,
5483 "Read die from %s@0x%x of %s:\n",
5484 get_section_name (section
),
5485 (unsigned) (begin_info_ptr
- section
->buffer
),
5486 bfd_get_filename (abfd
));
5487 dump_die (comp_unit_die
, dwarf_die_debug
);
5490 /* Save the comp_dir attribute. If there is no DWP file then we'll read
5491 TUs by skipping the stub and going directly to the entry in the DWO file.
5492 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
5493 to get it via circuitous means. Blech. */
5494 if (comp_dir
!= NULL
)
5495 result_reader
->comp_dir
= DW_STRING (comp_dir
);
5497 /* Skip dummy compilation units. */
5498 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
5499 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5502 *result_info_ptr
= info_ptr
;
5506 /* Subroutine of init_cutu_and_read_dies to simplify it.
5507 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
5508 Returns NULL if the specified DWO unit cannot be found. */
5510 static struct dwo_unit
*
5511 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
5512 struct die_info
*comp_unit_die
)
5514 struct dwarf2_cu
*cu
= this_cu
->cu
;
5515 struct attribute
*attr
;
5517 struct dwo_unit
*dwo_unit
;
5518 const char *comp_dir
, *dwo_name
;
5520 gdb_assert (cu
!= NULL
);
5522 /* Yeah, we look dwo_name up again, but it simplifies the code. */
5523 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5524 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
5526 if (this_cu
->is_debug_types
)
5528 struct signatured_type
*sig_type
;
5530 /* Since this_cu is the first member of struct signatured_type,
5531 we can go from a pointer to one to a pointer to the other. */
5532 sig_type
= (struct signatured_type
*) this_cu
;
5533 signature
= sig_type
->signature
;
5534 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
5538 struct attribute
*attr
;
5540 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
5542 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
5544 dwo_name
, objfile_name (this_cu
->objfile
));
5545 signature
= DW_UNSND (attr
);
5546 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
5553 /* Subroutine of init_cutu_and_read_dies to simplify it.
5554 See it for a description of the parameters.
5555 Read a TU directly from a DWO file, bypassing the stub.
5557 Note: This function could be a little bit simpler if we shared cleanups
5558 with our caller, init_cutu_and_read_dies. That's generally a fragile thing
5559 to do, so we keep this function self-contained. Or we could move this
5560 into our caller, but it's complex enough already. */
5563 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
5564 int use_existing_cu
, int keep
,
5565 die_reader_func_ftype
*die_reader_func
,
5568 struct dwarf2_cu
*cu
;
5569 struct signatured_type
*sig_type
;
5570 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5571 struct die_reader_specs reader
;
5572 const gdb_byte
*info_ptr
;
5573 struct die_info
*comp_unit_die
;
5576 /* Verify we can do the following downcast, and that we have the
5578 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
5579 sig_type
= (struct signatured_type
*) this_cu
;
5580 gdb_assert (sig_type
->dwo_unit
!= NULL
);
5582 cleanups
= make_cleanup (null_cleanup
, NULL
);
5584 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5586 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
5588 /* There's no need to do the rereading_dwo_cu handling that
5589 init_cutu_and_read_dies does since we don't read the stub. */
5593 /* If !use_existing_cu, this_cu->cu must be NULL. */
5594 gdb_assert (this_cu
->cu
== NULL
);
5595 cu
= XNEW (struct dwarf2_cu
);
5596 init_one_comp_unit (cu
, this_cu
);
5597 /* If an error occurs while loading, release our storage. */
5598 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5601 /* A future optimization, if needed, would be to use an existing
5602 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
5603 could share abbrev tables. */
5605 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
5606 0 /* abbrev_table_provided */,
5607 NULL
/* stub_comp_unit_die */,
5608 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
5610 &comp_unit_die
, &has_children
) == 0)
5613 do_cleanups (cleanups
);
5617 /* All the "real" work is done here. */
5618 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5620 /* This duplicates the code in init_cutu_and_read_dies,
5621 but the alternative is making the latter more complex.
5622 This function is only for the special case of using DWO files directly:
5623 no point in overly complicating the general case just to handle this. */
5624 if (free_cu_cleanup
!= NULL
)
5628 /* We've successfully allocated this compilation unit. Let our
5629 caller clean it up when finished with it. */
5630 discard_cleanups (free_cu_cleanup
);
5632 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5633 So we have to manually free the abbrev table. */
5634 dwarf2_free_abbrev_table (cu
);
5636 /* Link this CU into read_in_chain. */
5637 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5638 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5641 do_cleanups (free_cu_cleanup
);
5644 do_cleanups (cleanups
);
5647 /* Initialize a CU (or TU) and read its DIEs.
5648 If the CU defers to a DWO file, read the DWO file as well.
5650 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
5651 Otherwise the table specified in the comp unit header is read in and used.
5652 This is an optimization for when we already have the abbrev table.
5654 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
5655 Otherwise, a new CU is allocated with xmalloc.
5657 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
5658 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
5660 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5661 linker) then DIE_READER_FUNC will not get called. */
5664 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
5665 struct abbrev_table
*abbrev_table
,
5666 int use_existing_cu
, int keep
,
5667 die_reader_func_ftype
*die_reader_func
,
5670 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5671 struct dwarf2_section_info
*section
= this_cu
->section
;
5672 bfd
*abfd
= get_section_bfd_owner (section
);
5673 struct dwarf2_cu
*cu
;
5674 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5675 struct die_reader_specs reader
;
5676 struct die_info
*comp_unit_die
;
5678 struct attribute
*attr
;
5679 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5680 struct signatured_type
*sig_type
= NULL
;
5681 struct dwarf2_section_info
*abbrev_section
;
5682 /* Non-zero if CU currently points to a DWO file and we need to
5683 reread it. When this happens we need to reread the skeleton die
5684 before we can reread the DWO file (this only applies to CUs, not TUs). */
5685 int rereading_dwo_cu
= 0;
5687 if (dwarf_die_debug
)
5688 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5689 this_cu
->is_debug_types
? "type" : "comp",
5690 to_underlying (this_cu
->sect_off
));
5692 if (use_existing_cu
)
5695 /* If we're reading a TU directly from a DWO file, including a virtual DWO
5696 file (instead of going through the stub), short-circuit all of this. */
5697 if (this_cu
->reading_dwo_directly
)
5699 /* Narrow down the scope of possibilities to have to understand. */
5700 gdb_assert (this_cu
->is_debug_types
);
5701 gdb_assert (abbrev_table
== NULL
);
5702 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
5703 die_reader_func
, data
);
5707 cleanups
= make_cleanup (null_cleanup
, NULL
);
5709 /* This is cheap if the section is already read in. */
5710 dwarf2_read_section (objfile
, section
);
5712 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
5714 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
5716 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5719 /* If this CU is from a DWO file we need to start over, we need to
5720 refetch the attributes from the skeleton CU.
5721 This could be optimized by retrieving those attributes from when we
5722 were here the first time: the previous comp_unit_die was stored in
5723 comp_unit_obstack. But there's no data yet that we need this
5725 if (cu
->dwo_unit
!= NULL
)
5726 rereading_dwo_cu
= 1;
5730 /* If !use_existing_cu, this_cu->cu must be NULL. */
5731 gdb_assert (this_cu
->cu
== NULL
);
5732 cu
= XNEW (struct dwarf2_cu
);
5733 init_one_comp_unit (cu
, this_cu
);
5734 /* If an error occurs while loading, release our storage. */
5735 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5738 /* Get the header. */
5739 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
5741 /* We already have the header, there's no need to read it in again. */
5742 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
5746 if (this_cu
->is_debug_types
)
5748 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5749 abbrev_section
, info_ptr
,
5752 /* Since per_cu is the first member of struct signatured_type,
5753 we can go from a pointer to one to a pointer to the other. */
5754 sig_type
= (struct signatured_type
*) this_cu
;
5755 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
5756 gdb_assert (sig_type
->type_offset_in_tu
5757 == cu
->header
.type_cu_offset_in_tu
);
5758 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
5760 /* LENGTH has not been set yet for type units if we're
5761 using .gdb_index. */
5762 this_cu
->length
= get_cu_length (&cu
->header
);
5764 /* Establish the type offset that can be used to lookup the type. */
5765 sig_type
->type_offset_in_section
=
5766 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
5768 this_cu
->dwarf_version
= cu
->header
.version
;
5772 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5775 rcuh_kind::COMPILE
);
5777 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
5778 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
5779 this_cu
->dwarf_version
= cu
->header
.version
;
5783 /* Skip dummy compilation units. */
5784 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5785 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5787 do_cleanups (cleanups
);
5791 /* If we don't have them yet, read the abbrevs for this compilation unit.
5792 And if we need to read them now, make sure they're freed when we're
5793 done. Note that it's important that if the CU had an abbrev table
5794 on entry we don't free it when we're done: Somewhere up the call stack
5795 it may be in use. */
5796 if (abbrev_table
!= NULL
)
5798 gdb_assert (cu
->abbrev_table
== NULL
);
5799 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
5800 cu
->abbrev_table
= abbrev_table
;
5802 else if (cu
->abbrev_table
== NULL
)
5804 dwarf2_read_abbrevs (cu
, abbrev_section
);
5805 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5807 else if (rereading_dwo_cu
)
5809 dwarf2_free_abbrev_table (cu
);
5810 dwarf2_read_abbrevs (cu
, abbrev_section
);
5813 /* Read the top level CU/TU die. */
5814 init_cu_die_reader (&reader
, cu
, section
, NULL
);
5815 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5817 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
5819 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
5820 DWO CU, that this test will fail (the attribute will not be present). */
5821 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5824 struct dwo_unit
*dwo_unit
;
5825 struct die_info
*dwo_comp_unit_die
;
5829 complaint (&symfile_complaints
,
5830 _("compilation unit with DW_AT_GNU_dwo_name"
5831 " has children (offset 0x%x) [in module %s]"),
5832 to_underlying (this_cu
->sect_off
), bfd_get_filename (abfd
));
5834 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
5835 if (dwo_unit
!= NULL
)
5837 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
5838 abbrev_table
!= NULL
,
5839 comp_unit_die
, NULL
,
5841 &dwo_comp_unit_die
, &has_children
) == 0)
5844 do_cleanups (cleanups
);
5847 comp_unit_die
= dwo_comp_unit_die
;
5851 /* Yikes, we couldn't find the rest of the DIE, we only have
5852 the stub. A complaint has already been logged. There's
5853 not much more we can do except pass on the stub DIE to
5854 die_reader_func. We don't want to throw an error on bad
5859 /* All of the above is setup for this call. Yikes. */
5860 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5862 /* Done, clean up. */
5863 if (free_cu_cleanup
!= NULL
)
5867 /* We've successfully allocated this compilation unit. Let our
5868 caller clean it up when finished with it. */
5869 discard_cleanups (free_cu_cleanup
);
5871 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5872 So we have to manually free the abbrev table. */
5873 dwarf2_free_abbrev_table (cu
);
5875 /* Link this CU into read_in_chain. */
5876 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5877 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5880 do_cleanups (free_cu_cleanup
);
5883 do_cleanups (cleanups
);
5886 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
5887 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
5888 to have already done the lookup to find the DWO file).
5890 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
5891 THIS_CU->is_debug_types, but nothing else.
5893 We fill in THIS_CU->length.
5895 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5896 linker) then DIE_READER_FUNC will not get called.
5898 THIS_CU->cu is always freed when done.
5899 This is done in order to not leave THIS_CU->cu in a state where we have
5900 to care whether it refers to the "main" CU or the DWO CU. */
5903 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
5904 struct dwo_file
*dwo_file
,
5905 die_reader_func_ftype
*die_reader_func
,
5908 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5909 struct dwarf2_section_info
*section
= this_cu
->section
;
5910 bfd
*abfd
= get_section_bfd_owner (section
);
5911 struct dwarf2_section_info
*abbrev_section
;
5912 struct dwarf2_cu cu
;
5913 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5914 struct die_reader_specs reader
;
5915 struct cleanup
*cleanups
;
5916 struct die_info
*comp_unit_die
;
5919 if (dwarf_die_debug
)
5920 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5921 this_cu
->is_debug_types
? "type" : "comp",
5922 to_underlying (this_cu
->sect_off
));
5924 gdb_assert (this_cu
->cu
== NULL
);
5926 abbrev_section
= (dwo_file
!= NULL
5927 ? &dwo_file
->sections
.abbrev
5928 : get_abbrev_section_for_cu (this_cu
));
5930 /* This is cheap if the section is already read in. */
5931 dwarf2_read_section (objfile
, section
);
5933 init_one_comp_unit (&cu
, this_cu
);
5935 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
5937 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
5938 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
5939 abbrev_section
, info_ptr
,
5940 (this_cu
->is_debug_types
5942 : rcuh_kind::COMPILE
));
5944 this_cu
->length
= get_cu_length (&cu
.header
);
5946 /* Skip dummy compilation units. */
5947 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5948 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5950 do_cleanups (cleanups
);
5954 dwarf2_read_abbrevs (&cu
, abbrev_section
);
5955 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
5957 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
5958 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5960 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5962 do_cleanups (cleanups
);
5965 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
5966 does not lookup the specified DWO file.
5967 This cannot be used to read DWO files.
5969 THIS_CU->cu is always freed when done.
5970 This is done in order to not leave THIS_CU->cu in a state where we have
5971 to care whether it refers to the "main" CU or the DWO CU.
5972 We can revisit this if the data shows there's a performance issue. */
5975 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
5976 die_reader_func_ftype
*die_reader_func
,
5979 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
5982 /* Type Unit Groups.
5984 Type Unit Groups are a way to collapse the set of all TUs (type units) into
5985 a more manageable set. The grouping is done by DW_AT_stmt_list entry
5986 so that all types coming from the same compilation (.o file) are grouped
5987 together. A future step could be to put the types in the same symtab as
5988 the CU the types ultimately came from. */
5991 hash_type_unit_group (const void *item
)
5993 const struct type_unit_group
*tu_group
5994 = (const struct type_unit_group
*) item
;
5996 return hash_stmt_list_entry (&tu_group
->hash
);
6000 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6002 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6003 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6005 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6008 /* Allocate a hash table for type unit groups. */
6011 allocate_type_unit_groups_table (void)
6013 return htab_create_alloc_ex (3,
6014 hash_type_unit_group
,
6017 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
6018 hashtab_obstack_allocate
,
6019 dummy_obstack_deallocate
);
6022 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6023 partial symtabs. We combine several TUs per psymtab to not let the size
6024 of any one psymtab grow too big. */
6025 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6026 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6028 /* Helper routine for get_type_unit_group.
6029 Create the type_unit_group object used to hold one or more TUs. */
6031 static struct type_unit_group
*
6032 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6034 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6035 struct dwarf2_per_cu_data
*per_cu
;
6036 struct type_unit_group
*tu_group
;
6038 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6039 struct type_unit_group
);
6040 per_cu
= &tu_group
->per_cu
;
6041 per_cu
->objfile
= objfile
;
6043 if (dwarf2_per_objfile
->using_index
)
6045 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6046 struct dwarf2_per_cu_quick_data
);
6050 unsigned int line_offset
= to_underlying (line_offset_struct
);
6051 struct partial_symtab
*pst
;
6054 /* Give the symtab a useful name for debug purposes. */
6055 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
6056 name
= xstrprintf ("<type_units_%d>",
6057 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
6059 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
6061 pst
= create_partial_symtab (per_cu
, name
);
6067 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6068 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6073 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6074 STMT_LIST is a DW_AT_stmt_list attribute. */
6076 static struct type_unit_group
*
6077 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6079 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6080 struct type_unit_group
*tu_group
;
6082 unsigned int line_offset
;
6083 struct type_unit_group type_unit_group_for_lookup
;
6085 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
6087 dwarf2_per_objfile
->type_unit_groups
=
6088 allocate_type_unit_groups_table ();
6091 /* Do we need to create a new group, or can we use an existing one? */
6095 line_offset
= DW_UNSND (stmt_list
);
6096 ++tu_stats
->nr_symtab_sharers
;
6100 /* Ugh, no stmt_list. Rare, but we have to handle it.
6101 We can do various things here like create one group per TU or
6102 spread them over multiple groups to split up the expansion work.
6103 To avoid worst case scenarios (too many groups or too large groups)
6104 we, umm, group them in bunches. */
6105 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6106 | (tu_stats
->nr_stmt_less_type_units
6107 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6108 ++tu_stats
->nr_stmt_less_type_units
;
6111 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6112 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6113 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
6114 &type_unit_group_for_lookup
, INSERT
);
6117 tu_group
= (struct type_unit_group
*) *slot
;
6118 gdb_assert (tu_group
!= NULL
);
6122 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6123 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
6125 ++tu_stats
->nr_symtabs
;
6131 /* Partial symbol tables. */
6133 /* Create a psymtab named NAME and assign it to PER_CU.
6135 The caller must fill in the following details:
6136 dirname, textlow, texthigh. */
6138 static struct partial_symtab
*
6139 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
6141 struct objfile
*objfile
= per_cu
->objfile
;
6142 struct partial_symtab
*pst
;
6144 pst
= start_psymtab_common (objfile
, name
, 0,
6145 objfile
->global_psymbols
,
6146 objfile
->static_psymbols
);
6148 pst
->psymtabs_addrmap_supported
= 1;
6150 /* This is the glue that links PST into GDB's symbol API. */
6151 pst
->read_symtab_private
= per_cu
;
6152 pst
->read_symtab
= dwarf2_read_symtab
;
6153 per_cu
->v
.psymtab
= pst
;
6158 /* The DATA object passed to process_psymtab_comp_unit_reader has this
6161 struct process_psymtab_comp_unit_data
6163 /* True if we are reading a DW_TAG_partial_unit. */
6165 int want_partial_unit
;
6167 /* The "pretend" language that is used if the CU doesn't declare a
6170 enum language pretend_language
;
6173 /* die_reader_func for process_psymtab_comp_unit. */
6176 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6177 const gdb_byte
*info_ptr
,
6178 struct die_info
*comp_unit_die
,
6182 struct dwarf2_cu
*cu
= reader
->cu
;
6183 struct objfile
*objfile
= cu
->objfile
;
6184 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6185 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6187 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6188 struct partial_symtab
*pst
;
6189 enum pc_bounds_kind cu_bounds_kind
;
6190 const char *filename
;
6191 struct process_psymtab_comp_unit_data
*info
6192 = (struct process_psymtab_comp_unit_data
*) data
;
6194 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
6197 gdb_assert (! per_cu
->is_debug_types
);
6199 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
6201 cu
->list_in_scope
= &file_symbols
;
6203 /* Allocate a new partial symbol table structure. */
6204 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
6205 if (filename
== NULL
)
6208 pst
= create_partial_symtab (per_cu
, filename
);
6210 /* This must be done before calling dwarf2_build_include_psymtabs. */
6211 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6213 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6215 dwarf2_find_base_address (comp_unit_die
, cu
);
6217 /* Possibly set the default values of LOWPC and HIGHPC from
6219 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
6220 &best_highpc
, cu
, pst
);
6221 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
6222 /* Store the contiguous range if it is not empty; it can be empty for
6223 CUs with no code. */
6224 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6225 gdbarch_adjust_dwarf2_addr (gdbarch
,
6226 best_lowpc
+ baseaddr
),
6227 gdbarch_adjust_dwarf2_addr (gdbarch
,
6228 best_highpc
+ baseaddr
) - 1,
6231 /* Check if comp unit has_children.
6232 If so, read the rest of the partial symbols from this comp unit.
6233 If not, there's no more debug_info for this comp unit. */
6236 struct partial_die_info
*first_die
;
6237 CORE_ADDR lowpc
, highpc
;
6239 lowpc
= ((CORE_ADDR
) -1);
6240 highpc
= ((CORE_ADDR
) 0);
6242 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6244 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
6245 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
6247 /* If we didn't find a lowpc, set it to highpc to avoid
6248 complaints from `maint check'. */
6249 if (lowpc
== ((CORE_ADDR
) -1))
6252 /* If the compilation unit didn't have an explicit address range,
6253 then use the information extracted from its child dies. */
6254 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
6257 best_highpc
= highpc
;
6260 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
6261 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
6263 end_psymtab_common (objfile
, pst
);
6265 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
6268 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6269 struct dwarf2_per_cu_data
*iter
;
6271 /* Fill in 'dependencies' here; we fill in 'users' in a
6273 pst
->number_of_dependencies
= len
;
6275 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6277 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
6280 pst
->dependencies
[i
] = iter
->v
.psymtab
;
6282 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6285 /* Get the list of files included in the current compilation unit,
6286 and build a psymtab for each of them. */
6287 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
6289 if (dwarf_read_debug
)
6291 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6293 fprintf_unfiltered (gdb_stdlog
,
6294 "Psymtab for %s unit @0x%x: %s - %s"
6295 ", %d global, %d static syms\n",
6296 per_cu
->is_debug_types
? "type" : "comp",
6297 to_underlying (per_cu
->sect_off
),
6298 paddress (gdbarch
, pst
->textlow
),
6299 paddress (gdbarch
, pst
->texthigh
),
6300 pst
->n_global_syms
, pst
->n_static_syms
);
6304 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6305 Process compilation unit THIS_CU for a psymtab. */
6308 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6309 int want_partial_unit
,
6310 enum language pretend_language
)
6312 /* If this compilation unit was already read in, free the
6313 cached copy in order to read it in again. This is
6314 necessary because we skipped some symbols when we first
6315 read in the compilation unit (see load_partial_dies).
6316 This problem could be avoided, but the benefit is unclear. */
6317 if (this_cu
->cu
!= NULL
)
6318 free_one_cached_comp_unit (this_cu
);
6320 if (this_cu
->is_debug_types
)
6321 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, build_type_psymtabs_reader
,
6325 process_psymtab_comp_unit_data info
;
6326 info
.want_partial_unit
= want_partial_unit
;
6327 info
.pretend_language
= pretend_language
;
6328 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
6329 process_psymtab_comp_unit_reader
, &info
);
6332 /* Age out any secondary CUs. */
6333 age_cached_comp_units ();
6336 /* Reader function for build_type_psymtabs. */
6339 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
6340 const gdb_byte
*info_ptr
,
6341 struct die_info
*type_unit_die
,
6345 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6346 struct dwarf2_cu
*cu
= reader
->cu
;
6347 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6348 struct signatured_type
*sig_type
;
6349 struct type_unit_group
*tu_group
;
6350 struct attribute
*attr
;
6351 struct partial_die_info
*first_die
;
6352 CORE_ADDR lowpc
, highpc
;
6353 struct partial_symtab
*pst
;
6355 gdb_assert (data
== NULL
);
6356 gdb_assert (per_cu
->is_debug_types
);
6357 sig_type
= (struct signatured_type
*) per_cu
;
6362 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
6363 tu_group
= get_type_unit_group (cu
, attr
);
6365 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
6367 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
6368 cu
->list_in_scope
= &file_symbols
;
6369 pst
= create_partial_symtab (per_cu
, "");
6372 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6374 lowpc
= (CORE_ADDR
) -1;
6375 highpc
= (CORE_ADDR
) 0;
6376 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
6378 end_psymtab_common (objfile
, pst
);
6381 /* Struct used to sort TUs by their abbreviation table offset. */
6383 struct tu_abbrev_offset
6385 struct signatured_type
*sig_type
;
6386 sect_offset abbrev_offset
;
6389 /* Helper routine for build_type_psymtabs_1, passed to qsort. */
6392 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
6394 const struct tu_abbrev_offset
* const *a
6395 = (const struct tu_abbrev_offset
* const*) ap
;
6396 const struct tu_abbrev_offset
* const *b
6397 = (const struct tu_abbrev_offset
* const*) bp
;
6398 sect_offset aoff
= (*a
)->abbrev_offset
;
6399 sect_offset boff
= (*b
)->abbrev_offset
;
6401 return (aoff
> boff
) - (aoff
< boff
);
6404 /* Efficiently read all the type units.
6405 This does the bulk of the work for build_type_psymtabs.
6407 The efficiency is because we sort TUs by the abbrev table they use and
6408 only read each abbrev table once. In one program there are 200K TUs
6409 sharing 8K abbrev tables.
6411 The main purpose of this function is to support building the
6412 dwarf2_per_objfile->type_unit_groups table.
6413 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
6414 can collapse the search space by grouping them by stmt_list.
6415 The savings can be significant, in the same program from above the 200K TUs
6416 share 8K stmt_list tables.
6418 FUNC is expected to call get_type_unit_group, which will create the
6419 struct type_unit_group if necessary and add it to
6420 dwarf2_per_objfile->type_unit_groups. */
6423 build_type_psymtabs_1 (void)
6425 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6426 struct cleanup
*cleanups
;
6427 struct abbrev_table
*abbrev_table
;
6428 sect_offset abbrev_offset
;
6429 struct tu_abbrev_offset
*sorted_by_abbrev
;
6432 /* It's up to the caller to not call us multiple times. */
6433 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
6435 if (dwarf2_per_objfile
->n_type_units
== 0)
6438 /* TUs typically share abbrev tables, and there can be way more TUs than
6439 abbrev tables. Sort by abbrev table to reduce the number of times we
6440 read each abbrev table in.
6441 Alternatives are to punt or to maintain a cache of abbrev tables.
6442 This is simpler and efficient enough for now.
6444 Later we group TUs by their DW_AT_stmt_list value (as this defines the
6445 symtab to use). Typically TUs with the same abbrev offset have the same
6446 stmt_list value too so in practice this should work well.
6448 The basic algorithm here is:
6450 sort TUs by abbrev table
6451 for each TU with same abbrev table:
6452 read abbrev table if first user
6453 read TU top level DIE
6454 [IWBN if DWO skeletons had DW_AT_stmt_list]
6457 if (dwarf_read_debug
)
6458 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
6460 /* Sort in a separate table to maintain the order of all_type_units
6461 for .gdb_index: TU indices directly index all_type_units. */
6462 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
6463 dwarf2_per_objfile
->n_type_units
);
6464 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6466 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
6468 sorted_by_abbrev
[i
].sig_type
= sig_type
;
6469 sorted_by_abbrev
[i
].abbrev_offset
=
6470 read_abbrev_offset (sig_type
->per_cu
.section
,
6471 sig_type
->per_cu
.sect_off
);
6473 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
6474 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
6475 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
6477 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
6478 abbrev_table
= NULL
;
6479 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
6481 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6483 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
6485 /* Switch to the next abbrev table if necessary. */
6486 if (abbrev_table
== NULL
6487 || tu
->abbrev_offset
!= abbrev_offset
)
6489 if (abbrev_table
!= NULL
)
6491 abbrev_table_free (abbrev_table
);
6492 /* Reset to NULL in case abbrev_table_read_table throws
6493 an error: abbrev_table_free_cleanup will get called. */
6494 abbrev_table
= NULL
;
6496 abbrev_offset
= tu
->abbrev_offset
;
6498 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
6500 ++tu_stats
->nr_uniq_abbrev_tables
;
6503 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
6504 build_type_psymtabs_reader
, NULL
);
6507 do_cleanups (cleanups
);
6510 /* Print collected type unit statistics. */
6513 print_tu_stats (void)
6515 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6517 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
6518 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
6519 dwarf2_per_objfile
->n_type_units
);
6520 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
6521 tu_stats
->nr_uniq_abbrev_tables
);
6522 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
6523 tu_stats
->nr_symtabs
);
6524 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
6525 tu_stats
->nr_symtab_sharers
);
6526 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
6527 tu_stats
->nr_stmt_less_type_units
);
6528 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
6529 tu_stats
->nr_all_type_units_reallocs
);
6532 /* Traversal function for build_type_psymtabs. */
6535 build_type_psymtab_dependencies (void **slot
, void *info
)
6537 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6538 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
6539 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
6540 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6541 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
6542 struct signatured_type
*iter
;
6545 gdb_assert (len
> 0);
6546 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
6548 pst
->number_of_dependencies
= len
;
6550 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6552 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
6555 gdb_assert (iter
->per_cu
.is_debug_types
);
6556 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
6557 iter
->type_unit_group
= tu_group
;
6560 VEC_free (sig_type_ptr
, tu_group
->tus
);
6565 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6566 Build partial symbol tables for the .debug_types comp-units. */
6569 build_type_psymtabs (struct objfile
*objfile
)
6571 if (! create_all_type_units (objfile
))
6574 build_type_psymtabs_1 ();
6577 /* Traversal function for process_skeletonless_type_unit.
6578 Read a TU in a DWO file and build partial symbols for it. */
6581 process_skeletonless_type_unit (void **slot
, void *info
)
6583 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
6584 struct objfile
*objfile
= (struct objfile
*) info
;
6585 struct signatured_type find_entry
, *entry
;
6587 /* If this TU doesn't exist in the global table, add it and read it in. */
6589 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6591 dwarf2_per_objfile
->signatured_types
6592 = allocate_signatured_type_table (objfile
);
6595 find_entry
.signature
= dwo_unit
->signature
;
6596 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
6598 /* If we've already seen this type there's nothing to do. What's happening
6599 is we're doing our own version of comdat-folding here. */
6603 /* This does the job that create_all_type_units would have done for
6605 entry
= add_type_unit (dwo_unit
->signature
, slot
);
6606 fill_in_sig_entry_from_dwo_entry (objfile
, entry
, dwo_unit
);
6609 /* This does the job that build_type_psymtabs_1 would have done. */
6610 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
6611 build_type_psymtabs_reader
, NULL
);
6616 /* Traversal function for process_skeletonless_type_units. */
6619 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
6621 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
6623 if (dwo_file
->tus
!= NULL
)
6625 htab_traverse_noresize (dwo_file
->tus
,
6626 process_skeletonless_type_unit
, info
);
6632 /* Scan all TUs of DWO files, verifying we've processed them.
6633 This is needed in case a TU was emitted without its skeleton.
6634 Note: This can't be done until we know what all the DWO files are. */
6637 process_skeletonless_type_units (struct objfile
*objfile
)
6639 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
6640 if (get_dwp_file () == NULL
6641 && dwarf2_per_objfile
->dwo_files
!= NULL
)
6643 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
6644 process_dwo_file_for_skeletonless_type_units
,
6649 /* Compute the 'user' field for each psymtab in OBJFILE. */
6652 set_partial_user (struct objfile
*objfile
)
6656 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6658 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6659 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6665 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
6667 /* Set the 'user' field only if it is not already set. */
6668 if (pst
->dependencies
[j
]->user
== NULL
)
6669 pst
->dependencies
[j
]->user
= pst
;
6674 /* Build the partial symbol table by doing a quick pass through the
6675 .debug_info and .debug_abbrev sections. */
6678 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
6680 struct cleanup
*back_to
;
6683 if (dwarf_read_debug
)
6685 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
6686 objfile_name (objfile
));
6689 dwarf2_per_objfile
->reading_partial_symbols
= 1;
6691 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
6693 /* Any cached compilation units will be linked by the per-objfile
6694 read_in_chain. Make sure to free them when we're done. */
6695 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
6697 build_type_psymtabs (objfile
);
6699 create_all_comp_units (objfile
);
6701 /* Create a temporary address map on a temporary obstack. We later
6702 copy this to the final obstack. */
6703 auto_obstack temp_obstack
;
6705 scoped_restore save_psymtabs_addrmap
6706 = make_scoped_restore (&objfile
->psymtabs_addrmap
,
6707 addrmap_create_mutable (&temp_obstack
));
6709 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6711 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6713 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
6716 /* This has to wait until we read the CUs, we need the list of DWOs. */
6717 process_skeletonless_type_units (objfile
);
6719 /* Now that all TUs have been processed we can fill in the dependencies. */
6720 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
6722 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
6723 build_type_psymtab_dependencies
, NULL
);
6726 if (dwarf_read_debug
)
6729 set_partial_user (objfile
);
6731 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
6732 &objfile
->objfile_obstack
);
6733 /* At this point we want to keep the address map. */
6734 save_psymtabs_addrmap
.release ();
6736 do_cleanups (back_to
);
6738 if (dwarf_read_debug
)
6739 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
6740 objfile_name (objfile
));
6743 /* die_reader_func for load_partial_comp_unit. */
6746 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
6747 const gdb_byte
*info_ptr
,
6748 struct die_info
*comp_unit_die
,
6752 struct dwarf2_cu
*cu
= reader
->cu
;
6754 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
6756 /* Check if comp unit has_children.
6757 If so, read the rest of the partial symbols from this comp unit.
6758 If not, there's no more debug_info for this comp unit. */
6760 load_partial_dies (reader
, info_ptr
, 0);
6763 /* Load the partial DIEs for a secondary CU into memory.
6764 This is also used when rereading a primary CU with load_all_dies. */
6767 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
6769 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6770 load_partial_comp_unit_reader
, NULL
);
6774 read_comp_units_from_section (struct objfile
*objfile
,
6775 struct dwarf2_section_info
*section
,
6776 struct dwarf2_section_info
*abbrev_section
,
6777 unsigned int is_dwz
,
6780 struct dwarf2_per_cu_data
***all_comp_units
)
6782 const gdb_byte
*info_ptr
;
6783 bfd
*abfd
= get_section_bfd_owner (section
);
6785 if (dwarf_read_debug
)
6786 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
6787 get_section_name (section
),
6788 get_section_file_name (section
));
6790 dwarf2_read_section (objfile
, section
);
6792 info_ptr
= section
->buffer
;
6794 while (info_ptr
< section
->buffer
+ section
->size
)
6796 struct dwarf2_per_cu_data
*this_cu
;
6798 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
6800 comp_unit_head cu_header
;
6801 read_and_check_comp_unit_head (&cu_header
, section
, abbrev_section
,
6802 info_ptr
, rcuh_kind::COMPILE
);
6804 /* Save the compilation unit for later lookup. */
6805 if (cu_header
.unit_type
!= DW_UT_type
)
6807 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
6808 struct dwarf2_per_cu_data
);
6809 memset (this_cu
, 0, sizeof (*this_cu
));
6813 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
6814 struct signatured_type
);
6815 memset (sig_type
, 0, sizeof (*sig_type
));
6816 sig_type
->signature
= cu_header
.signature
;
6817 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
6818 this_cu
= &sig_type
->per_cu
;
6820 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
6821 this_cu
->sect_off
= sect_off
;
6822 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
6823 this_cu
->is_dwz
= is_dwz
;
6824 this_cu
->objfile
= objfile
;
6825 this_cu
->section
= section
;
6827 if (*n_comp_units
== *n_allocated
)
6830 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
6831 *all_comp_units
, *n_allocated
);
6833 (*all_comp_units
)[*n_comp_units
] = this_cu
;
6836 info_ptr
= info_ptr
+ this_cu
->length
;
6840 /* Create a list of all compilation units in OBJFILE.
6841 This is only done for -readnow and building partial symtabs. */
6844 create_all_comp_units (struct objfile
*objfile
)
6848 struct dwarf2_per_cu_data
**all_comp_units
;
6849 struct dwz_file
*dwz
;
6853 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
6855 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
,
6856 &dwarf2_per_objfile
->abbrev
, 0,
6857 &n_allocated
, &n_comp_units
, &all_comp_units
);
6859 dwz
= dwarf2_get_dwz_file ();
6861 read_comp_units_from_section (objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
6862 &n_allocated
, &n_comp_units
,
6865 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
6866 struct dwarf2_per_cu_data
*,
6868 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
6869 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
6870 xfree (all_comp_units
);
6871 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
6874 /* Process all loaded DIEs for compilation unit CU, starting at
6875 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
6876 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
6877 DW_AT_ranges). See the comments of add_partial_subprogram on how
6878 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
6881 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
6882 CORE_ADDR
*highpc
, int set_addrmap
,
6883 struct dwarf2_cu
*cu
)
6885 struct partial_die_info
*pdi
;
6887 /* Now, march along the PDI's, descending into ones which have
6888 interesting children but skipping the children of the other ones,
6889 until we reach the end of the compilation unit. */
6895 fixup_partial_die (pdi
, cu
);
6897 /* Anonymous namespaces or modules have no name but have interesting
6898 children, so we need to look at them. Ditto for anonymous
6901 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
6902 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
6903 || pdi
->tag
== DW_TAG_imported_unit
)
6907 case DW_TAG_subprogram
:
6908 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6910 case DW_TAG_constant
:
6911 case DW_TAG_variable
:
6912 case DW_TAG_typedef
:
6913 case DW_TAG_union_type
:
6914 if (!pdi
->is_declaration
)
6916 add_partial_symbol (pdi
, cu
);
6919 case DW_TAG_class_type
:
6920 case DW_TAG_interface_type
:
6921 case DW_TAG_structure_type
:
6922 if (!pdi
->is_declaration
)
6924 add_partial_symbol (pdi
, cu
);
6926 if (cu
->language
== language_rust
&& pdi
->has_children
)
6927 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
6930 case DW_TAG_enumeration_type
:
6931 if (!pdi
->is_declaration
)
6932 add_partial_enumeration (pdi
, cu
);
6934 case DW_TAG_base_type
:
6935 case DW_TAG_subrange_type
:
6936 /* File scope base type definitions are added to the partial
6938 add_partial_symbol (pdi
, cu
);
6940 case DW_TAG_namespace
:
6941 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6944 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6946 case DW_TAG_imported_unit
:
6948 struct dwarf2_per_cu_data
*per_cu
;
6950 /* For now we don't handle imported units in type units. */
6951 if (cu
->per_cu
->is_debug_types
)
6953 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6954 " supported in type units [in module %s]"),
6955 objfile_name (cu
->objfile
));
6958 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.sect_off
,
6962 /* Go read the partial unit, if needed. */
6963 if (per_cu
->v
.psymtab
== NULL
)
6964 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
6966 VEC_safe_push (dwarf2_per_cu_ptr
,
6967 cu
->per_cu
->imported_symtabs
, per_cu
);
6970 case DW_TAG_imported_declaration
:
6971 add_partial_symbol (pdi
, cu
);
6978 /* If the die has a sibling, skip to the sibling. */
6980 pdi
= pdi
->die_sibling
;
6984 /* Functions used to compute the fully scoped name of a partial DIE.
6986 Normally, this is simple. For C++, the parent DIE's fully scoped
6987 name is concatenated with "::" and the partial DIE's name.
6988 Enumerators are an exception; they use the scope of their parent
6989 enumeration type, i.e. the name of the enumeration type is not
6990 prepended to the enumerator.
6992 There are two complexities. One is DW_AT_specification; in this
6993 case "parent" means the parent of the target of the specification,
6994 instead of the direct parent of the DIE. The other is compilers
6995 which do not emit DW_TAG_namespace; in this case we try to guess
6996 the fully qualified name of structure types from their members'
6997 linkage names. This must be done using the DIE's children rather
6998 than the children of any DW_AT_specification target. We only need
6999 to do this for structures at the top level, i.e. if the target of
7000 any DW_AT_specification (if any; otherwise the DIE itself) does not
7003 /* Compute the scope prefix associated with PDI's parent, in
7004 compilation unit CU. The result will be allocated on CU's
7005 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7006 field. NULL is returned if no prefix is necessary. */
7008 partial_die_parent_scope (struct partial_die_info
*pdi
,
7009 struct dwarf2_cu
*cu
)
7011 const char *grandparent_scope
;
7012 struct partial_die_info
*parent
, *real_pdi
;
7014 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7015 then this means the parent of the specification DIE. */
7018 while (real_pdi
->has_specification
)
7019 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
7020 real_pdi
->spec_is_dwz
, cu
);
7022 parent
= real_pdi
->die_parent
;
7026 if (parent
->scope_set
)
7027 return parent
->scope
;
7029 fixup_partial_die (parent
, cu
);
7031 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7033 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7034 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7035 Work around this problem here. */
7036 if (cu
->language
== language_cplus
7037 && parent
->tag
== DW_TAG_namespace
7038 && strcmp (parent
->name
, "::") == 0
7039 && grandparent_scope
== NULL
)
7041 parent
->scope
= NULL
;
7042 parent
->scope_set
= 1;
7046 if (pdi
->tag
== DW_TAG_enumerator
)
7047 /* Enumerators should not get the name of the enumeration as a prefix. */
7048 parent
->scope
= grandparent_scope
;
7049 else if (parent
->tag
== DW_TAG_namespace
7050 || parent
->tag
== DW_TAG_module
7051 || parent
->tag
== DW_TAG_structure_type
7052 || parent
->tag
== DW_TAG_class_type
7053 || parent
->tag
== DW_TAG_interface_type
7054 || parent
->tag
== DW_TAG_union_type
7055 || parent
->tag
== DW_TAG_enumeration_type
)
7057 if (grandparent_scope
== NULL
)
7058 parent
->scope
= parent
->name
;
7060 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7062 parent
->name
, 0, cu
);
7066 /* FIXME drow/2004-04-01: What should we be doing with
7067 function-local names? For partial symbols, we should probably be
7069 complaint (&symfile_complaints
,
7070 _("unhandled containing DIE tag %d for DIE at %d"),
7071 parent
->tag
, to_underlying (pdi
->sect_off
));
7072 parent
->scope
= grandparent_scope
;
7075 parent
->scope_set
= 1;
7076 return parent
->scope
;
7079 /* Return the fully scoped name associated with PDI, from compilation unit
7080 CU. The result will be allocated with malloc. */
7083 partial_die_full_name (struct partial_die_info
*pdi
,
7084 struct dwarf2_cu
*cu
)
7086 const char *parent_scope
;
7088 /* If this is a template instantiation, we can not work out the
7089 template arguments from partial DIEs. So, unfortunately, we have
7090 to go through the full DIEs. At least any work we do building
7091 types here will be reused if full symbols are loaded later. */
7092 if (pdi
->has_template_arguments
)
7094 fixup_partial_die (pdi
, cu
);
7096 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
7098 struct die_info
*die
;
7099 struct attribute attr
;
7100 struct dwarf2_cu
*ref_cu
= cu
;
7102 /* DW_FORM_ref_addr is using section offset. */
7103 attr
.name
= (enum dwarf_attribute
) 0;
7104 attr
.form
= DW_FORM_ref_addr
;
7105 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7106 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7108 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7112 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7113 if (parent_scope
== NULL
)
7116 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
7120 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7122 struct objfile
*objfile
= cu
->objfile
;
7123 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7125 const char *actual_name
= NULL
;
7127 char *built_actual_name
;
7129 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7131 built_actual_name
= partial_die_full_name (pdi
, cu
);
7132 if (built_actual_name
!= NULL
)
7133 actual_name
= built_actual_name
;
7135 if (actual_name
== NULL
)
7136 actual_name
= pdi
->name
;
7140 case DW_TAG_subprogram
:
7141 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
7142 if (pdi
->is_external
|| cu
->language
== language_ada
)
7144 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
7145 of the global scope. But in Ada, we want to be able to access
7146 nested procedures globally. So all Ada subprograms are stored
7147 in the global scope. */
7148 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7149 built_actual_name
!= NULL
,
7150 VAR_DOMAIN
, LOC_BLOCK
,
7151 &objfile
->global_psymbols
,
7152 addr
, cu
->language
, objfile
);
7156 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7157 built_actual_name
!= NULL
,
7158 VAR_DOMAIN
, LOC_BLOCK
,
7159 &objfile
->static_psymbols
,
7160 addr
, cu
->language
, objfile
);
7163 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7164 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
7166 case DW_TAG_constant
:
7168 std::vector
<partial_symbol
*> *list
;
7170 if (pdi
->is_external
)
7171 list
= &objfile
->global_psymbols
;
7173 list
= &objfile
->static_psymbols
;
7174 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7175 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
7176 list
, 0, cu
->language
, objfile
);
7179 case DW_TAG_variable
:
7181 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7185 && !dwarf2_per_objfile
->has_section_at_zero
)
7187 /* A global or static variable may also have been stripped
7188 out by the linker if unused, in which case its address
7189 will be nullified; do not add such variables into partial
7190 symbol table then. */
7192 else if (pdi
->is_external
)
7195 Don't enter into the minimal symbol tables as there is
7196 a minimal symbol table entry from the ELF symbols already.
7197 Enter into partial symbol table if it has a location
7198 descriptor or a type.
7199 If the location descriptor is missing, new_symbol will create
7200 a LOC_UNRESOLVED symbol, the address of the variable will then
7201 be determined from the minimal symbol table whenever the variable
7203 The address for the partial symbol table entry is not
7204 used by GDB, but it comes in handy for debugging partial symbol
7207 if (pdi
->d
.locdesc
|| pdi
->has_type
)
7208 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7209 built_actual_name
!= NULL
,
7210 VAR_DOMAIN
, LOC_STATIC
,
7211 &objfile
->global_psymbols
,
7213 cu
->language
, objfile
);
7217 int has_loc
= pdi
->d
.locdesc
!= NULL
;
7219 /* Static Variable. Skip symbols whose value we cannot know (those
7220 without location descriptors or constant values). */
7221 if (!has_loc
&& !pdi
->has_const_value
)
7223 xfree (built_actual_name
);
7227 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7228 built_actual_name
!= NULL
,
7229 VAR_DOMAIN
, LOC_STATIC
,
7230 &objfile
->static_psymbols
,
7231 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
7232 cu
->language
, objfile
);
7235 case DW_TAG_typedef
:
7236 case DW_TAG_base_type
:
7237 case DW_TAG_subrange_type
:
7238 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7239 built_actual_name
!= NULL
,
7240 VAR_DOMAIN
, LOC_TYPEDEF
,
7241 &objfile
->static_psymbols
,
7242 0, cu
->language
, objfile
);
7244 case DW_TAG_imported_declaration
:
7245 case DW_TAG_namespace
:
7246 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7247 built_actual_name
!= NULL
,
7248 VAR_DOMAIN
, LOC_TYPEDEF
,
7249 &objfile
->global_psymbols
,
7250 0, cu
->language
, objfile
);
7253 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7254 built_actual_name
!= NULL
,
7255 MODULE_DOMAIN
, LOC_TYPEDEF
,
7256 &objfile
->global_psymbols
,
7257 0, cu
->language
, objfile
);
7259 case DW_TAG_class_type
:
7260 case DW_TAG_interface_type
:
7261 case DW_TAG_structure_type
:
7262 case DW_TAG_union_type
:
7263 case DW_TAG_enumeration_type
:
7264 /* Skip external references. The DWARF standard says in the section
7265 about "Structure, Union, and Class Type Entries": "An incomplete
7266 structure, union or class type is represented by a structure,
7267 union or class entry that does not have a byte size attribute
7268 and that has a DW_AT_declaration attribute." */
7269 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
7271 xfree (built_actual_name
);
7275 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
7276 static vs. global. */
7277 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7278 built_actual_name
!= NULL
,
7279 STRUCT_DOMAIN
, LOC_TYPEDEF
,
7280 cu
->language
== language_cplus
7281 ? &objfile
->global_psymbols
7282 : &objfile
->static_psymbols
,
7283 0, cu
->language
, objfile
);
7286 case DW_TAG_enumerator
:
7287 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7288 built_actual_name
!= NULL
,
7289 VAR_DOMAIN
, LOC_CONST
,
7290 cu
->language
== language_cplus
7291 ? &objfile
->global_psymbols
7292 : &objfile
->static_psymbols
,
7293 0, cu
->language
, objfile
);
7299 xfree (built_actual_name
);
7302 /* Read a partial die corresponding to a namespace; also, add a symbol
7303 corresponding to that namespace to the symbol table. NAMESPACE is
7304 the name of the enclosing namespace. */
7307 add_partial_namespace (struct partial_die_info
*pdi
,
7308 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7309 int set_addrmap
, struct dwarf2_cu
*cu
)
7311 /* Add a symbol for the namespace. */
7313 add_partial_symbol (pdi
, cu
);
7315 /* Now scan partial symbols in that namespace. */
7317 if (pdi
->has_children
)
7318 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7321 /* Read a partial die corresponding to a Fortran module. */
7324 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
7325 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
7327 /* Add a symbol for the namespace. */
7329 add_partial_symbol (pdi
, cu
);
7331 /* Now scan partial symbols in that module. */
7333 if (pdi
->has_children
)
7334 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7337 /* Read a partial die corresponding to a subprogram and create a partial
7338 symbol for that subprogram. When the CU language allows it, this
7339 routine also defines a partial symbol for each nested subprogram
7340 that this subprogram contains. If SET_ADDRMAP is true, record the
7341 covered ranges in the addrmap. Set *LOWPC and *HIGHPC to the lowest
7342 and highest PC values found in PDI.
7344 PDI may also be a lexical block, in which case we simply search
7345 recursively for subprograms defined inside that lexical block.
7346 Again, this is only performed when the CU language allows this
7347 type of definitions. */
7350 add_partial_subprogram (struct partial_die_info
*pdi
,
7351 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7352 int set_addrmap
, struct dwarf2_cu
*cu
)
7354 if (pdi
->tag
== DW_TAG_subprogram
)
7356 if (pdi
->has_pc_info
)
7358 if (pdi
->lowpc
< *lowpc
)
7359 *lowpc
= pdi
->lowpc
;
7360 if (pdi
->highpc
> *highpc
)
7361 *highpc
= pdi
->highpc
;
7364 struct objfile
*objfile
= cu
->objfile
;
7365 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7370 baseaddr
= ANOFFSET (objfile
->section_offsets
,
7371 SECT_OFF_TEXT (objfile
));
7372 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7373 pdi
->lowpc
+ baseaddr
);
7374 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7375 pdi
->highpc
+ baseaddr
);
7376 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
7377 cu
->per_cu
->v
.psymtab
);
7381 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
7383 if (!pdi
->is_declaration
)
7384 /* Ignore subprogram DIEs that do not have a name, they are
7385 illegal. Do not emit a complaint at this point, we will
7386 do so when we convert this psymtab into a symtab. */
7388 add_partial_symbol (pdi
, cu
);
7392 if (! pdi
->has_children
)
7395 if (cu
->language
== language_ada
)
7397 pdi
= pdi
->die_child
;
7400 fixup_partial_die (pdi
, cu
);
7401 if (pdi
->tag
== DW_TAG_subprogram
7402 || pdi
->tag
== DW_TAG_lexical_block
)
7403 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7404 pdi
= pdi
->die_sibling
;
7409 /* Read a partial die corresponding to an enumeration type. */
7412 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
7413 struct dwarf2_cu
*cu
)
7415 struct partial_die_info
*pdi
;
7417 if (enum_pdi
->name
!= NULL
)
7418 add_partial_symbol (enum_pdi
, cu
);
7420 pdi
= enum_pdi
->die_child
;
7423 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
7424 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
7426 add_partial_symbol (pdi
, cu
);
7427 pdi
= pdi
->die_sibling
;
7431 /* Return the initial uleb128 in the die at INFO_PTR. */
7434 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
7436 unsigned int bytes_read
;
7438 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7441 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
7442 Return the corresponding abbrev, or NULL if the number is zero (indicating
7443 an empty DIE). In either case *BYTES_READ will be set to the length of
7444 the initial number. */
7446 static struct abbrev_info
*
7447 peek_die_abbrev (const gdb_byte
*info_ptr
, unsigned int *bytes_read
,
7448 struct dwarf2_cu
*cu
)
7450 bfd
*abfd
= cu
->objfile
->obfd
;
7451 unsigned int abbrev_number
;
7452 struct abbrev_info
*abbrev
;
7454 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
7456 if (abbrev_number
== 0)
7459 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
7462 error (_("Dwarf Error: Could not find abbrev number %d in %s"
7463 " at offset 0x%x [in module %s]"),
7464 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
7465 to_underlying (cu
->header
.sect_off
), bfd_get_filename (abfd
));
7471 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7472 Returns a pointer to the end of a series of DIEs, terminated by an empty
7473 DIE. Any children of the skipped DIEs will also be skipped. */
7475 static const gdb_byte
*
7476 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
7478 struct dwarf2_cu
*cu
= reader
->cu
;
7479 struct abbrev_info
*abbrev
;
7480 unsigned int bytes_read
;
7484 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
7486 return info_ptr
+ bytes_read
;
7488 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
7492 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7493 INFO_PTR should point just after the initial uleb128 of a DIE, and the
7494 abbrev corresponding to that skipped uleb128 should be passed in
7495 ABBREV. Returns a pointer to this DIE's sibling, skipping any
7498 static const gdb_byte
*
7499 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
7500 struct abbrev_info
*abbrev
)
7502 unsigned int bytes_read
;
7503 struct attribute attr
;
7504 bfd
*abfd
= reader
->abfd
;
7505 struct dwarf2_cu
*cu
= reader
->cu
;
7506 const gdb_byte
*buffer
= reader
->buffer
;
7507 const gdb_byte
*buffer_end
= reader
->buffer_end
;
7508 unsigned int form
, i
;
7510 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
7512 /* The only abbrev we care about is DW_AT_sibling. */
7513 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
7515 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
7516 if (attr
.form
== DW_FORM_ref_addr
)
7517 complaint (&symfile_complaints
,
7518 _("ignoring absolute DW_AT_sibling"));
7521 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
7522 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
7524 if (sibling_ptr
< info_ptr
)
7525 complaint (&symfile_complaints
,
7526 _("DW_AT_sibling points backwards"));
7527 else if (sibling_ptr
> reader
->buffer_end
)
7528 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
7534 /* If it isn't DW_AT_sibling, skip this attribute. */
7535 form
= abbrev
->attrs
[i
].form
;
7539 case DW_FORM_ref_addr
:
7540 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
7541 and later it is offset sized. */
7542 if (cu
->header
.version
== 2)
7543 info_ptr
+= cu
->header
.addr_size
;
7545 info_ptr
+= cu
->header
.offset_size
;
7547 case DW_FORM_GNU_ref_alt
:
7548 info_ptr
+= cu
->header
.offset_size
;
7551 info_ptr
+= cu
->header
.addr_size
;
7558 case DW_FORM_flag_present
:
7559 case DW_FORM_implicit_const
:
7571 case DW_FORM_ref_sig8
:
7574 case DW_FORM_data16
:
7577 case DW_FORM_string
:
7578 read_direct_string (abfd
, info_ptr
, &bytes_read
);
7579 info_ptr
+= bytes_read
;
7581 case DW_FORM_sec_offset
:
7583 case DW_FORM_GNU_strp_alt
:
7584 info_ptr
+= cu
->header
.offset_size
;
7586 case DW_FORM_exprloc
:
7588 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7589 info_ptr
+= bytes_read
;
7591 case DW_FORM_block1
:
7592 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
7594 case DW_FORM_block2
:
7595 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
7597 case DW_FORM_block4
:
7598 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
7602 case DW_FORM_ref_udata
:
7603 case DW_FORM_GNU_addr_index
:
7604 case DW_FORM_GNU_str_index
:
7605 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
7607 case DW_FORM_indirect
:
7608 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7609 info_ptr
+= bytes_read
;
7610 /* We need to continue parsing from here, so just go back to
7612 goto skip_attribute
;
7615 error (_("Dwarf Error: Cannot handle %s "
7616 "in DWARF reader [in module %s]"),
7617 dwarf_form_name (form
),
7618 bfd_get_filename (abfd
));
7622 if (abbrev
->has_children
)
7623 return skip_children (reader
, info_ptr
);
7628 /* Locate ORIG_PDI's sibling.
7629 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
7631 static const gdb_byte
*
7632 locate_pdi_sibling (const struct die_reader_specs
*reader
,
7633 struct partial_die_info
*orig_pdi
,
7634 const gdb_byte
*info_ptr
)
7636 /* Do we know the sibling already? */
7638 if (orig_pdi
->sibling
)
7639 return orig_pdi
->sibling
;
7641 /* Are there any children to deal with? */
7643 if (!orig_pdi
->has_children
)
7646 /* Skip the children the long way. */
7648 return skip_children (reader
, info_ptr
);
7651 /* Expand this partial symbol table into a full symbol table. SELF is
7655 dwarf2_read_symtab (struct partial_symtab
*self
,
7656 struct objfile
*objfile
)
7660 warning (_("bug: psymtab for %s is already read in."),
7667 printf_filtered (_("Reading in symbols for %s..."),
7669 gdb_flush (gdb_stdout
);
7672 /* Restore our global data. */
7674 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
7675 dwarf2_objfile_data_key
);
7677 /* If this psymtab is constructed from a debug-only objfile, the
7678 has_section_at_zero flag will not necessarily be correct. We
7679 can get the correct value for this flag by looking at the data
7680 associated with the (presumably stripped) associated objfile. */
7681 if (objfile
->separate_debug_objfile_backlink
)
7683 struct dwarf2_per_objfile
*dpo_backlink
7684 = ((struct dwarf2_per_objfile
*)
7685 objfile_data (objfile
->separate_debug_objfile_backlink
,
7686 dwarf2_objfile_data_key
));
7688 dwarf2_per_objfile
->has_section_at_zero
7689 = dpo_backlink
->has_section_at_zero
;
7692 dwarf2_per_objfile
->reading_partial_symbols
= 0;
7694 psymtab_to_symtab_1 (self
);
7696 /* Finish up the debug error message. */
7698 printf_filtered (_("done.\n"));
7701 process_cu_includes ();
7704 /* Reading in full CUs. */
7706 /* Add PER_CU to the queue. */
7709 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
7710 enum language pretend_language
)
7712 struct dwarf2_queue_item
*item
;
7715 item
= XNEW (struct dwarf2_queue_item
);
7716 item
->per_cu
= per_cu
;
7717 item
->pretend_language
= pretend_language
;
7720 if (dwarf2_queue
== NULL
)
7721 dwarf2_queue
= item
;
7723 dwarf2_queue_tail
->next
= item
;
7725 dwarf2_queue_tail
= item
;
7728 /* If PER_CU is not yet queued, add it to the queue.
7729 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
7731 The result is non-zero if PER_CU was queued, otherwise the result is zero
7732 meaning either PER_CU is already queued or it is already loaded.
7734 N.B. There is an invariant here that if a CU is queued then it is loaded.
7735 The caller is required to load PER_CU if we return non-zero. */
7738 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
7739 struct dwarf2_per_cu_data
*per_cu
,
7740 enum language pretend_language
)
7742 /* We may arrive here during partial symbol reading, if we need full
7743 DIEs to process an unusual case (e.g. template arguments). Do
7744 not queue PER_CU, just tell our caller to load its DIEs. */
7745 if (dwarf2_per_objfile
->reading_partial_symbols
)
7747 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
7752 /* Mark the dependence relation so that we don't flush PER_CU
7754 if (dependent_cu
!= NULL
)
7755 dwarf2_add_dependence (dependent_cu
, per_cu
);
7757 /* If it's already on the queue, we have nothing to do. */
7761 /* If the compilation unit is already loaded, just mark it as
7763 if (per_cu
->cu
!= NULL
)
7765 per_cu
->cu
->last_used
= 0;
7769 /* Add it to the queue. */
7770 queue_comp_unit (per_cu
, pretend_language
);
7775 /* Process the queue. */
7778 process_queue (void)
7780 struct dwarf2_queue_item
*item
, *next_item
;
7782 if (dwarf_read_debug
)
7784 fprintf_unfiltered (gdb_stdlog
,
7785 "Expanding one or more symtabs of objfile %s ...\n",
7786 objfile_name (dwarf2_per_objfile
->objfile
));
7789 /* The queue starts out with one item, but following a DIE reference
7790 may load a new CU, adding it to the end of the queue. */
7791 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
7793 if ((dwarf2_per_objfile
->using_index
7794 ? !item
->per_cu
->v
.quick
->compunit_symtab
7795 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
7796 /* Skip dummy CUs. */
7797 && item
->per_cu
->cu
!= NULL
)
7799 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
7800 unsigned int debug_print_threshold
;
7803 if (per_cu
->is_debug_types
)
7805 struct signatured_type
*sig_type
=
7806 (struct signatured_type
*) per_cu
;
7808 sprintf (buf
, "TU %s at offset 0x%x",
7809 hex_string (sig_type
->signature
),
7810 to_underlying (per_cu
->sect_off
));
7811 /* There can be 100s of TUs.
7812 Only print them in verbose mode. */
7813 debug_print_threshold
= 2;
7817 sprintf (buf
, "CU at offset 0x%x",
7818 to_underlying (per_cu
->sect_off
));
7819 debug_print_threshold
= 1;
7822 if (dwarf_read_debug
>= debug_print_threshold
)
7823 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
7825 if (per_cu
->is_debug_types
)
7826 process_full_type_unit (per_cu
, item
->pretend_language
);
7828 process_full_comp_unit (per_cu
, item
->pretend_language
);
7830 if (dwarf_read_debug
>= debug_print_threshold
)
7831 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
7834 item
->per_cu
->queued
= 0;
7835 next_item
= item
->next
;
7839 dwarf2_queue_tail
= NULL
;
7841 if (dwarf_read_debug
)
7843 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
7844 objfile_name (dwarf2_per_objfile
->objfile
));
7848 /* Free all allocated queue entries. This function only releases anything if
7849 an error was thrown; if the queue was processed then it would have been
7850 freed as we went along. */
7853 dwarf2_release_queue (void *dummy
)
7855 struct dwarf2_queue_item
*item
, *last
;
7857 item
= dwarf2_queue
;
7860 /* Anything still marked queued is likely to be in an
7861 inconsistent state, so discard it. */
7862 if (item
->per_cu
->queued
)
7864 if (item
->per_cu
->cu
!= NULL
)
7865 free_one_cached_comp_unit (item
->per_cu
);
7866 item
->per_cu
->queued
= 0;
7874 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
7877 /* Read in full symbols for PST, and anything it depends on. */
7880 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
7882 struct dwarf2_per_cu_data
*per_cu
;
7888 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
7889 if (!pst
->dependencies
[i
]->readin
7890 && pst
->dependencies
[i
]->user
== NULL
)
7892 /* Inform about additional files that need to be read in. */
7895 /* FIXME: i18n: Need to make this a single string. */
7896 fputs_filtered (" ", gdb_stdout
);
7898 fputs_filtered ("and ", gdb_stdout
);
7900 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
7901 wrap_here (""); /* Flush output. */
7902 gdb_flush (gdb_stdout
);
7904 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
7907 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
7911 /* It's an include file, no symbols to read for it.
7912 Everything is in the parent symtab. */
7917 dw2_do_instantiate_symtab (per_cu
);
7920 /* Trivial hash function for die_info: the hash value of a DIE
7921 is its offset in .debug_info for this objfile. */
7924 die_hash (const void *item
)
7926 const struct die_info
*die
= (const struct die_info
*) item
;
7928 return to_underlying (die
->sect_off
);
7931 /* Trivial comparison function for die_info structures: two DIEs
7932 are equal if they have the same offset. */
7935 die_eq (const void *item_lhs
, const void *item_rhs
)
7937 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
7938 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
7940 return die_lhs
->sect_off
== die_rhs
->sect_off
;
7943 /* die_reader_func for load_full_comp_unit.
7944 This is identical to read_signatured_type_reader,
7945 but is kept separate for now. */
7948 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
7949 const gdb_byte
*info_ptr
,
7950 struct die_info
*comp_unit_die
,
7954 struct dwarf2_cu
*cu
= reader
->cu
;
7955 enum language
*language_ptr
= (enum language
*) data
;
7957 gdb_assert (cu
->die_hash
== NULL
);
7959 htab_create_alloc_ex (cu
->header
.length
/ 12,
7963 &cu
->comp_unit_obstack
,
7964 hashtab_obstack_allocate
,
7965 dummy_obstack_deallocate
);
7968 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
7969 &info_ptr
, comp_unit_die
);
7970 cu
->dies
= comp_unit_die
;
7971 /* comp_unit_die is not stored in die_hash, no need. */
7973 /* We try not to read any attributes in this function, because not
7974 all CUs needed for references have been loaded yet, and symbol
7975 table processing isn't initialized. But we have to set the CU language,
7976 or we won't be able to build types correctly.
7977 Similarly, if we do not read the producer, we can not apply
7978 producer-specific interpretation. */
7979 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
7982 /* Load the DIEs associated with PER_CU into memory. */
7985 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7986 enum language pretend_language
)
7988 gdb_assert (! this_cu
->is_debug_types
);
7990 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
7991 load_full_comp_unit_reader
, &pretend_language
);
7994 /* Add a DIE to the delayed physname list. */
7997 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
7998 const char *name
, struct die_info
*die
,
7999 struct dwarf2_cu
*cu
)
8001 struct delayed_method_info mi
;
8003 mi
.fnfield_index
= fnfield_index
;
8007 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
8010 /* A cleanup for freeing the delayed method list. */
8013 free_delayed_list (void *ptr
)
8015 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
8016 if (cu
->method_list
!= NULL
)
8018 VEC_free (delayed_method_info
, cu
->method_list
);
8019 cu
->method_list
= NULL
;
8023 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8024 "const" / "volatile". If so, decrements LEN by the length of the
8025 modifier and return true. Otherwise return false. */
8029 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8031 size_t mod_len
= sizeof (mod
) - 1;
8032 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8040 /* Compute the physnames of any methods on the CU's method list.
8042 The computation of method physnames is delayed in order to avoid the
8043 (bad) condition that one of the method's formal parameters is of an as yet
8047 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8050 struct delayed_method_info
*mi
;
8052 /* Only C++ delays computing physnames. */
8053 if (VEC_empty (delayed_method_info
, cu
->method_list
))
8055 gdb_assert (cu
->language
== language_cplus
);
8057 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
8059 const char *physname
;
8060 struct fn_fieldlist
*fn_flp
8061 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
8062 physname
= dwarf2_physname (mi
->name
, mi
->die
, cu
);
8063 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
->index
)
8064 = physname
? physname
: "";
8066 /* Since there's no tag to indicate whether a method is a
8067 const/volatile overload, extract that information out of the
8069 if (physname
!= NULL
)
8071 size_t len
= strlen (physname
);
8075 if (physname
[len
] == ')') /* shortcut */
8077 else if (check_modifier (physname
, len
, " const"))
8078 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
->index
) = 1;
8079 else if (check_modifier (physname
, len
, " volatile"))
8080 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
->index
) = 1;
8088 /* Go objects should be embedded in a DW_TAG_module DIE,
8089 and it's not clear if/how imported objects will appear.
8090 To keep Go support simple until that's worked out,
8091 go back through what we've read and create something usable.
8092 We could do this while processing each DIE, and feels kinda cleaner,
8093 but that way is more invasive.
8094 This is to, for example, allow the user to type "p var" or "b main"
8095 without having to specify the package name, and allow lookups
8096 of module.object to work in contexts that use the expression
8100 fixup_go_packaging (struct dwarf2_cu
*cu
)
8102 char *package_name
= NULL
;
8103 struct pending
*list
;
8106 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
8108 for (i
= 0; i
< list
->nsyms
; ++i
)
8110 struct symbol
*sym
= list
->symbol
[i
];
8112 if (SYMBOL_LANGUAGE (sym
) == language_go
8113 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8115 char *this_package_name
= go_symbol_package_name (sym
);
8117 if (this_package_name
== NULL
)
8119 if (package_name
== NULL
)
8120 package_name
= this_package_name
;
8123 if (strcmp (package_name
, this_package_name
) != 0)
8124 complaint (&symfile_complaints
,
8125 _("Symtab %s has objects from two different Go packages: %s and %s"),
8126 (symbol_symtab (sym
) != NULL
8127 ? symtab_to_filename_for_display
8128 (symbol_symtab (sym
))
8129 : objfile_name (cu
->objfile
)),
8130 this_package_name
, package_name
);
8131 xfree (this_package_name
);
8137 if (package_name
!= NULL
)
8139 struct objfile
*objfile
= cu
->objfile
;
8140 const char *saved_package_name
8141 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8143 strlen (package_name
));
8144 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8145 saved_package_name
);
8148 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8150 sym
= allocate_symbol (objfile
);
8151 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
8152 SYMBOL_SET_NAMES (sym
, saved_package_name
,
8153 strlen (saved_package_name
), 0, objfile
);
8154 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8155 e.g., "main" finds the "main" module and not C's main(). */
8156 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8157 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
8158 SYMBOL_TYPE (sym
) = type
;
8160 add_symbol_to_list (sym
, &global_symbols
);
8162 xfree (package_name
);
8166 /* Return the symtab for PER_CU. This works properly regardless of
8167 whether we're using the index or psymtabs. */
8169 static struct compunit_symtab
*
8170 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
8172 return (dwarf2_per_objfile
->using_index
8173 ? per_cu
->v
.quick
->compunit_symtab
8174 : per_cu
->v
.psymtab
->compunit_symtab
);
8177 /* A helper function for computing the list of all symbol tables
8178 included by PER_CU. */
8181 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
8182 htab_t all_children
, htab_t all_type_symtabs
,
8183 struct dwarf2_per_cu_data
*per_cu
,
8184 struct compunit_symtab
*immediate_parent
)
8188 struct compunit_symtab
*cust
;
8189 struct dwarf2_per_cu_data
*iter
;
8191 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
8194 /* This inclusion and its children have been processed. */
8199 /* Only add a CU if it has a symbol table. */
8200 cust
= get_compunit_symtab (per_cu
);
8203 /* If this is a type unit only add its symbol table if we haven't
8204 seen it yet (type unit per_cu's can share symtabs). */
8205 if (per_cu
->is_debug_types
)
8207 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
8211 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
8212 if (cust
->user
== NULL
)
8213 cust
->user
= immediate_parent
;
8218 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
8219 if (cust
->user
== NULL
)
8220 cust
->user
= immediate_parent
;
8225 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
8228 recursively_compute_inclusions (result
, all_children
,
8229 all_type_symtabs
, iter
, cust
);
8233 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
8237 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
8239 gdb_assert (! per_cu
->is_debug_types
);
8241 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
8244 struct dwarf2_per_cu_data
*per_cu_iter
;
8245 struct compunit_symtab
*compunit_symtab_iter
;
8246 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
8247 htab_t all_children
, all_type_symtabs
;
8248 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
8250 /* If we don't have a symtab, we can just skip this case. */
8254 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
8255 NULL
, xcalloc
, xfree
);
8256 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
8257 NULL
, xcalloc
, xfree
);
8260 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
8264 recursively_compute_inclusions (&result_symtabs
, all_children
,
8265 all_type_symtabs
, per_cu_iter
,
8269 /* Now we have a transitive closure of all the included symtabs. */
8270 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
8272 = XOBNEWVEC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
8273 struct compunit_symtab
*, len
+ 1);
8275 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
8276 compunit_symtab_iter
);
8278 cust
->includes
[ix
] = compunit_symtab_iter
;
8279 cust
->includes
[len
] = NULL
;
8281 VEC_free (compunit_symtab_ptr
, result_symtabs
);
8282 htab_delete (all_children
);
8283 htab_delete (all_type_symtabs
);
8287 /* Compute the 'includes' field for the symtabs of all the CUs we just
8291 process_cu_includes (void)
8294 struct dwarf2_per_cu_data
*iter
;
8297 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
8301 if (! iter
->is_debug_types
)
8302 compute_compunit_symtab_includes (iter
);
8305 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
8308 /* Generate full symbol information for PER_CU, whose DIEs have
8309 already been loaded into memory. */
8312 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8313 enum language pretend_language
)
8315 struct dwarf2_cu
*cu
= per_cu
->cu
;
8316 struct objfile
*objfile
= per_cu
->objfile
;
8317 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8318 CORE_ADDR lowpc
, highpc
;
8319 struct compunit_symtab
*cust
;
8320 struct cleanup
*delayed_list_cleanup
;
8322 struct block
*static_block
;
8325 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8328 scoped_free_pendings free_pending
;
8329 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8331 cu
->list_in_scope
= &file_symbols
;
8333 cu
->language
= pretend_language
;
8334 cu
->language_defn
= language_def (cu
->language
);
8336 /* Do line number decoding in read_file_scope () */
8337 process_die (cu
->dies
, cu
);
8339 /* For now fudge the Go package. */
8340 if (cu
->language
== language_go
)
8341 fixup_go_packaging (cu
);
8343 /* Now that we have processed all the DIEs in the CU, all the types
8344 should be complete, and it should now be safe to compute all of the
8346 compute_delayed_physnames (cu
);
8347 do_cleanups (delayed_list_cleanup
);
8349 /* Some compilers don't define a DW_AT_high_pc attribute for the
8350 compilation unit. If the DW_AT_high_pc is missing, synthesize
8351 it, by scanning the DIE's below the compilation unit. */
8352 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
8354 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
8355 static_block
= end_symtab_get_static_block (addr
, 0, 1);
8357 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
8358 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
8359 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
8360 addrmap to help ensure it has an accurate map of pc values belonging to
8362 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
8364 cust
= end_symtab_from_static_block (static_block
,
8365 SECT_OFF_TEXT (objfile
), 0);
8369 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
8371 /* Set symtab language to language from DW_AT_language. If the
8372 compilation is from a C file generated by language preprocessors, do
8373 not set the language if it was already deduced by start_subfile. */
8374 if (!(cu
->language
== language_c
8375 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
8376 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8378 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
8379 produce DW_AT_location with location lists but it can be possibly
8380 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
8381 there were bugs in prologue debug info, fixed later in GCC-4.5
8382 by "unwind info for epilogues" patch (which is not directly related).
8384 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
8385 needed, it would be wrong due to missing DW_AT_producer there.
8387 Still one can confuse GDB by using non-standard GCC compilation
8388 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
8390 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
8391 cust
->locations_valid
= 1;
8393 if (gcc_4_minor
>= 5)
8394 cust
->epilogue_unwind_valid
= 1;
8396 cust
->call_site_htab
= cu
->call_site_htab
;
8399 if (dwarf2_per_objfile
->using_index
)
8400 per_cu
->v
.quick
->compunit_symtab
= cust
;
8403 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8404 pst
->compunit_symtab
= cust
;
8408 /* Push it for inclusion processing later. */
8409 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
8412 /* Generate full symbol information for type unit PER_CU, whose DIEs have
8413 already been loaded into memory. */
8416 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
8417 enum language pretend_language
)
8419 struct dwarf2_cu
*cu
= per_cu
->cu
;
8420 struct objfile
*objfile
= per_cu
->objfile
;
8421 struct compunit_symtab
*cust
;
8422 struct cleanup
*delayed_list_cleanup
;
8423 struct signatured_type
*sig_type
;
8425 gdb_assert (per_cu
->is_debug_types
);
8426 sig_type
= (struct signatured_type
*) per_cu
;
8429 scoped_free_pendings free_pending
;
8430 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8432 cu
->list_in_scope
= &file_symbols
;
8434 cu
->language
= pretend_language
;
8435 cu
->language_defn
= language_def (cu
->language
);
8437 /* The symbol tables are set up in read_type_unit_scope. */
8438 process_die (cu
->dies
, cu
);
8440 /* For now fudge the Go package. */
8441 if (cu
->language
== language_go
)
8442 fixup_go_packaging (cu
);
8444 /* Now that we have processed all the DIEs in the CU, all the types
8445 should be complete, and it should now be safe to compute all of the
8447 compute_delayed_physnames (cu
);
8448 do_cleanups (delayed_list_cleanup
);
8450 /* TUs share symbol tables.
8451 If this is the first TU to use this symtab, complete the construction
8452 of it with end_expandable_symtab. Otherwise, complete the addition of
8453 this TU's symbols to the existing symtab. */
8454 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
8456 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
8457 sig_type
->type_unit_group
->compunit_symtab
= cust
;
8461 /* Set symtab language to language from DW_AT_language. If the
8462 compilation is from a C file generated by language preprocessors,
8463 do not set the language if it was already deduced by
8465 if (!(cu
->language
== language_c
8466 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
8467 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8472 augment_type_symtab ();
8473 cust
= sig_type
->type_unit_group
->compunit_symtab
;
8476 if (dwarf2_per_objfile
->using_index
)
8477 per_cu
->v
.quick
->compunit_symtab
= cust
;
8480 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8481 pst
->compunit_symtab
= cust
;
8486 /* Process an imported unit DIE. */
8489 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8491 struct attribute
*attr
;
8493 /* For now we don't handle imported units in type units. */
8494 if (cu
->per_cu
->is_debug_types
)
8496 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8497 " supported in type units [in module %s]"),
8498 objfile_name (cu
->objfile
));
8501 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8504 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
8505 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
8506 dwarf2_per_cu_data
*per_cu
8507 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, cu
->objfile
);
8509 /* If necessary, add it to the queue and load its DIEs. */
8510 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
8511 load_full_comp_unit (per_cu
, cu
->language
);
8513 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8518 /* RAII object that represents a process_die scope: i.e.,
8519 starts/finishes processing a DIE. */
8520 class process_die_scope
8523 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
8524 : m_die (die
), m_cu (cu
)
8526 /* We should only be processing DIEs not already in process. */
8527 gdb_assert (!m_die
->in_process
);
8528 m_die
->in_process
= true;
8531 ~process_die_scope ()
8533 m_die
->in_process
= false;
8535 /* If we're done processing the DIE for the CU that owns the line
8536 header, we don't need the line header anymore. */
8537 if (m_cu
->line_header_die_owner
== m_die
)
8539 delete m_cu
->line_header
;
8540 m_cu
->line_header
= NULL
;
8541 m_cu
->line_header_die_owner
= NULL
;
8550 /* Process a die and its children. */
8553 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8555 process_die_scope
scope (die
, cu
);
8559 case DW_TAG_padding
:
8561 case DW_TAG_compile_unit
:
8562 case DW_TAG_partial_unit
:
8563 read_file_scope (die
, cu
);
8565 case DW_TAG_type_unit
:
8566 read_type_unit_scope (die
, cu
);
8568 case DW_TAG_subprogram
:
8569 case DW_TAG_inlined_subroutine
:
8570 read_func_scope (die
, cu
);
8572 case DW_TAG_lexical_block
:
8573 case DW_TAG_try_block
:
8574 case DW_TAG_catch_block
:
8575 read_lexical_block_scope (die
, cu
);
8577 case DW_TAG_call_site
:
8578 case DW_TAG_GNU_call_site
:
8579 read_call_site_scope (die
, cu
);
8581 case DW_TAG_class_type
:
8582 case DW_TAG_interface_type
:
8583 case DW_TAG_structure_type
:
8584 case DW_TAG_union_type
:
8585 process_structure_scope (die
, cu
);
8587 case DW_TAG_enumeration_type
:
8588 process_enumeration_scope (die
, cu
);
8591 /* These dies have a type, but processing them does not create
8592 a symbol or recurse to process the children. Therefore we can
8593 read them on-demand through read_type_die. */
8594 case DW_TAG_subroutine_type
:
8595 case DW_TAG_set_type
:
8596 case DW_TAG_array_type
:
8597 case DW_TAG_pointer_type
:
8598 case DW_TAG_ptr_to_member_type
:
8599 case DW_TAG_reference_type
:
8600 case DW_TAG_rvalue_reference_type
:
8601 case DW_TAG_string_type
:
8604 case DW_TAG_base_type
:
8605 case DW_TAG_subrange_type
:
8606 case DW_TAG_typedef
:
8607 /* Add a typedef symbol for the type definition, if it has a
8609 new_symbol (die
, read_type_die (die
, cu
), cu
);
8611 case DW_TAG_common_block
:
8612 read_common_block (die
, cu
);
8614 case DW_TAG_common_inclusion
:
8616 case DW_TAG_namespace
:
8617 cu
->processing_has_namespace_info
= 1;
8618 read_namespace (die
, cu
);
8621 cu
->processing_has_namespace_info
= 1;
8622 read_module (die
, cu
);
8624 case DW_TAG_imported_declaration
:
8625 cu
->processing_has_namespace_info
= 1;
8626 if (read_namespace_alias (die
, cu
))
8628 /* The declaration is not a global namespace alias: fall through. */
8629 case DW_TAG_imported_module
:
8630 cu
->processing_has_namespace_info
= 1;
8631 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
8632 || cu
->language
!= language_fortran
))
8633 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
8634 dwarf_tag_name (die
->tag
));
8635 read_import_statement (die
, cu
);
8638 case DW_TAG_imported_unit
:
8639 process_imported_unit_die (die
, cu
);
8643 new_symbol (die
, NULL
, cu
);
8648 /* DWARF name computation. */
8650 /* A helper function for dwarf2_compute_name which determines whether DIE
8651 needs to have the name of the scope prepended to the name listed in the
8655 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8657 struct attribute
*attr
;
8661 case DW_TAG_namespace
:
8662 case DW_TAG_typedef
:
8663 case DW_TAG_class_type
:
8664 case DW_TAG_interface_type
:
8665 case DW_TAG_structure_type
:
8666 case DW_TAG_union_type
:
8667 case DW_TAG_enumeration_type
:
8668 case DW_TAG_enumerator
:
8669 case DW_TAG_subprogram
:
8670 case DW_TAG_inlined_subroutine
:
8672 case DW_TAG_imported_declaration
:
8675 case DW_TAG_variable
:
8676 case DW_TAG_constant
:
8677 /* We only need to prefix "globally" visible variables. These include
8678 any variable marked with DW_AT_external or any variable that
8679 lives in a namespace. [Variables in anonymous namespaces
8680 require prefixing, but they are not DW_AT_external.] */
8682 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
8684 struct dwarf2_cu
*spec_cu
= cu
;
8686 return die_needs_namespace (die_specification (die
, &spec_cu
),
8690 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8691 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
8692 && die
->parent
->tag
!= DW_TAG_module
)
8694 /* A variable in a lexical block of some kind does not need a
8695 namespace, even though in C++ such variables may be external
8696 and have a mangled name. */
8697 if (die
->parent
->tag
== DW_TAG_lexical_block
8698 || die
->parent
->tag
== DW_TAG_try_block
8699 || die
->parent
->tag
== DW_TAG_catch_block
8700 || die
->parent
->tag
== DW_TAG_subprogram
)
8709 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
8710 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
8711 defined for the given DIE. */
8713 static struct attribute
*
8714 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
8716 struct attribute
*attr
;
8718 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
8720 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8725 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
8726 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
8727 defined for the given DIE. */
8730 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8732 const char *linkage_name
;
8734 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
8735 if (linkage_name
== NULL
)
8736 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8738 return linkage_name
;
8741 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
8742 compute the physname for the object, which include a method's:
8743 - formal parameters (C++),
8744 - receiver type (Go),
8746 The term "physname" is a bit confusing.
8747 For C++, for example, it is the demangled name.
8748 For Go, for example, it's the mangled name.
8750 For Ada, return the DIE's linkage name rather than the fully qualified
8751 name. PHYSNAME is ignored..
8753 The result is allocated on the objfile_obstack and canonicalized. */
8756 dwarf2_compute_name (const char *name
,
8757 struct die_info
*die
, struct dwarf2_cu
*cu
,
8760 struct objfile
*objfile
= cu
->objfile
;
8763 name
= dwarf2_name (die
, cu
);
8765 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
8766 but otherwise compute it by typename_concat inside GDB.
8767 FIXME: Actually this is not really true, or at least not always true.
8768 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
8769 Fortran names because there is no mangling standard. So new_symbol_full
8770 will set the demangled name to the result of dwarf2_full_name, and it is
8771 the demangled name that GDB uses if it exists. */
8772 if (cu
->language
== language_ada
8773 || (cu
->language
== language_fortran
&& physname
))
8775 /* For Ada unit, we prefer the linkage name over the name, as
8776 the former contains the exported name, which the user expects
8777 to be able to reference. Ideally, we want the user to be able
8778 to reference this entity using either natural or linkage name,
8779 but we haven't started looking at this enhancement yet. */
8780 const char *linkage_name
= dw2_linkage_name (die
, cu
);
8782 if (linkage_name
!= NULL
)
8783 return linkage_name
;
8786 /* These are the only languages we know how to qualify names in. */
8788 && (cu
->language
== language_cplus
8789 || cu
->language
== language_fortran
|| cu
->language
== language_d
8790 || cu
->language
== language_rust
))
8792 if (die_needs_namespace (die
, cu
))
8796 const char *canonical_name
= NULL
;
8800 prefix
= determine_prefix (die
, cu
);
8801 if (*prefix
!= '\0')
8803 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
8806 buf
.puts (prefixed_name
);
8807 xfree (prefixed_name
);
8812 /* Template parameters may be specified in the DIE's DW_AT_name, or
8813 as children with DW_TAG_template_type_param or
8814 DW_TAG_value_type_param. If the latter, add them to the name
8815 here. If the name already has template parameters, then
8816 skip this step; some versions of GCC emit both, and
8817 it is more efficient to use the pre-computed name.
8819 Something to keep in mind about this process: it is very
8820 unlikely, or in some cases downright impossible, to produce
8821 something that will match the mangled name of a function.
8822 If the definition of the function has the same debug info,
8823 we should be able to match up with it anyway. But fallbacks
8824 using the minimal symbol, for instance to find a method
8825 implemented in a stripped copy of libstdc++, will not work.
8826 If we do not have debug info for the definition, we will have to
8827 match them up some other way.
8829 When we do name matching there is a related problem with function
8830 templates; two instantiated function templates are allowed to
8831 differ only by their return types, which we do not add here. */
8833 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
8835 struct attribute
*attr
;
8836 struct die_info
*child
;
8839 die
->building_fullname
= 1;
8841 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
8845 const gdb_byte
*bytes
;
8846 struct dwarf2_locexpr_baton
*baton
;
8849 if (child
->tag
!= DW_TAG_template_type_param
8850 && child
->tag
!= DW_TAG_template_value_param
)
8861 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
8864 complaint (&symfile_complaints
,
8865 _("template parameter missing DW_AT_type"));
8866 buf
.puts ("UNKNOWN_TYPE");
8869 type
= die_type (child
, cu
);
8871 if (child
->tag
== DW_TAG_template_type_param
)
8873 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
8877 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
8880 complaint (&symfile_complaints
,
8881 _("template parameter missing "
8882 "DW_AT_const_value"));
8883 buf
.puts ("UNKNOWN_VALUE");
8887 dwarf2_const_value_attr (attr
, type
, name
,
8888 &cu
->comp_unit_obstack
, cu
,
8889 &value
, &bytes
, &baton
);
8891 if (TYPE_NOSIGN (type
))
8892 /* GDB prints characters as NUMBER 'CHAR'. If that's
8893 changed, this can use value_print instead. */
8894 c_printchar (value
, type
, &buf
);
8897 struct value_print_options opts
;
8900 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
8904 else if (bytes
!= NULL
)
8906 v
= allocate_value (type
);
8907 memcpy (value_contents_writeable (v
), bytes
,
8908 TYPE_LENGTH (type
));
8911 v
= value_from_longest (type
, value
);
8913 /* Specify decimal so that we do not depend on
8915 get_formatted_print_options (&opts
, 'd');
8917 value_print (v
, &buf
, &opts
);
8923 die
->building_fullname
= 0;
8927 /* Close the argument list, with a space if necessary
8928 (nested templates). */
8929 if (!buf
.empty () && buf
.string ().back () == '>')
8936 /* For C++ methods, append formal parameter type
8937 information, if PHYSNAME. */
8939 if (physname
&& die
->tag
== DW_TAG_subprogram
8940 && cu
->language
== language_cplus
)
8942 struct type
*type
= read_type_die (die
, cu
);
8944 c_type_print_args (type
, &buf
, 1, cu
->language
,
8945 &type_print_raw_options
);
8947 if (cu
->language
== language_cplus
)
8949 /* Assume that an artificial first parameter is
8950 "this", but do not crash if it is not. RealView
8951 marks unnamed (and thus unused) parameters as
8952 artificial; there is no way to differentiate
8954 if (TYPE_NFIELDS (type
) > 0
8955 && TYPE_FIELD_ARTIFICIAL (type
, 0)
8956 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
8957 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
8959 buf
.puts (" const");
8963 const std::string
&intermediate_name
= buf
.string ();
8965 if (cu
->language
== language_cplus
)
8967 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
8968 &objfile
->per_bfd
->storage_obstack
);
8970 /* If we only computed INTERMEDIATE_NAME, or if
8971 INTERMEDIATE_NAME is already canonical, then we need to
8972 copy it to the appropriate obstack. */
8973 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
8974 name
= ((const char *)
8975 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8976 intermediate_name
.c_str (),
8977 intermediate_name
.length ()));
8979 name
= canonical_name
;
8986 /* Return the fully qualified name of DIE, based on its DW_AT_name.
8987 If scope qualifiers are appropriate they will be added. The result
8988 will be allocated on the storage_obstack, or NULL if the DIE does
8989 not have a name. NAME may either be from a previous call to
8990 dwarf2_name or NULL.
8992 The output string will be canonicalized (if C++). */
8995 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8997 return dwarf2_compute_name (name
, die
, cu
, 0);
9000 /* Construct a physname for the given DIE in CU. NAME may either be
9001 from a previous call to dwarf2_name or NULL. The result will be
9002 allocated on the objfile_objstack or NULL if the DIE does not have a
9005 The output string will be canonicalized (if C++). */
9008 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
9010 struct objfile
*objfile
= cu
->objfile
;
9011 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
9014 /* In this case dwarf2_compute_name is just a shortcut not building anything
9016 if (!die_needs_namespace (die
, cu
))
9017 return dwarf2_compute_name (name
, die
, cu
, 1);
9019 mangled
= dw2_linkage_name (die
, cu
);
9021 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9022 See https://github.com/rust-lang/rust/issues/32925. */
9023 if (cu
->language
== language_rust
&& mangled
!= NULL
9024 && strchr (mangled
, '{') != NULL
)
9027 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
9029 gdb::unique_xmalloc_ptr
<char> demangled
;
9030 if (mangled
!= NULL
)
9032 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
9033 type. It is easier for GDB users to search for such functions as
9034 `name(params)' than `long name(params)'. In such case the minimal
9035 symbol names do not match the full symbol names but for template
9036 functions there is never a need to look up their definition from their
9037 declaration so the only disadvantage remains the minimal symbol
9038 variant `long name(params)' does not have the proper inferior type.
9041 if (cu
->language
== language_go
)
9043 /* This is a lie, but we already lie to the caller new_symbol_full.
9044 new_symbol_full assumes we return the mangled name.
9045 This just undoes that lie until things are cleaned up. */
9049 demangled
.reset (gdb_demangle (mangled
,
9050 (DMGL_PARAMS
| DMGL_ANSI
9054 canon
= demangled
.get ();
9062 if (canon
== NULL
|| check_physname
)
9064 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
9066 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
9068 /* It may not mean a bug in GDB. The compiler could also
9069 compute DW_AT_linkage_name incorrectly. But in such case
9070 GDB would need to be bug-to-bug compatible. */
9072 complaint (&symfile_complaints
,
9073 _("Computed physname <%s> does not match demangled <%s> "
9074 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
9075 physname
, canon
, mangled
, to_underlying (die
->sect_off
),
9076 objfile_name (objfile
));
9078 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
9079 is available here - over computed PHYSNAME. It is safer
9080 against both buggy GDB and buggy compilers. */
9094 retval
= ((const char *)
9095 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
9096 retval
, strlen (retval
)));
9101 /* Inspect DIE in CU for a namespace alias. If one exists, record
9102 a new symbol for it.
9104 Returns 1 if a namespace alias was recorded, 0 otherwise. */
9107 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
9109 struct attribute
*attr
;
9111 /* If the die does not have a name, this is not a namespace
9113 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
9117 struct die_info
*d
= die
;
9118 struct dwarf2_cu
*imported_cu
= cu
;
9120 /* If the compiler has nested DW_AT_imported_declaration DIEs,
9121 keep inspecting DIEs until we hit the underlying import. */
9122 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
9123 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
9125 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
9129 d
= follow_die_ref (d
, attr
, &imported_cu
);
9130 if (d
->tag
!= DW_TAG_imported_declaration
)
9134 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
9136 complaint (&symfile_complaints
,
9137 _("DIE at 0x%x has too many recursively imported "
9138 "declarations"), to_underlying (d
->sect_off
));
9145 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9147 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
9148 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
9150 /* This declaration is a global namespace alias. Add
9151 a symbol for it whose type is the aliased namespace. */
9152 new_symbol (die
, type
, cu
);
9161 /* Return the using directives repository (global or local?) to use in the
9162 current context for LANGUAGE.
9164 For Ada, imported declarations can materialize renamings, which *may* be
9165 global. However it is impossible (for now?) in DWARF to distinguish
9166 "external" imported declarations and "static" ones. As all imported
9167 declarations seem to be static in all other languages, make them all CU-wide
9168 global only in Ada. */
9170 static struct using_direct
**
9171 using_directives (enum language language
)
9173 if (language
== language_ada
&& context_stack_depth
== 0)
9174 return &global_using_directives
;
9176 return &local_using_directives
;
9179 /* Read the import statement specified by the given die and record it. */
9182 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
9184 struct objfile
*objfile
= cu
->objfile
;
9185 struct attribute
*import_attr
;
9186 struct die_info
*imported_die
, *child_die
;
9187 struct dwarf2_cu
*imported_cu
;
9188 const char *imported_name
;
9189 const char *imported_name_prefix
;
9190 const char *canonical_name
;
9191 const char *import_alias
;
9192 const char *imported_declaration
= NULL
;
9193 const char *import_prefix
;
9194 std::vector
<const char *> excludes
;
9196 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9197 if (import_attr
== NULL
)
9199 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
9200 dwarf_tag_name (die
->tag
));
9205 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
9206 imported_name
= dwarf2_name (imported_die
, imported_cu
);
9207 if (imported_name
== NULL
)
9209 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
9211 The import in the following code:
9225 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
9226 <52> DW_AT_decl_file : 1
9227 <53> DW_AT_decl_line : 6
9228 <54> DW_AT_import : <0x75>
9229 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
9231 <5b> DW_AT_decl_file : 1
9232 <5c> DW_AT_decl_line : 2
9233 <5d> DW_AT_type : <0x6e>
9235 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
9236 <76> DW_AT_byte_size : 4
9237 <77> DW_AT_encoding : 5 (signed)
9239 imports the wrong die ( 0x75 instead of 0x58 ).
9240 This case will be ignored until the gcc bug is fixed. */
9244 /* Figure out the local name after import. */
9245 import_alias
= dwarf2_name (die
, cu
);
9247 /* Figure out where the statement is being imported to. */
9248 import_prefix
= determine_prefix (die
, cu
);
9250 /* Figure out what the scope of the imported die is and prepend it
9251 to the name of the imported die. */
9252 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
9254 if (imported_die
->tag
!= DW_TAG_namespace
9255 && imported_die
->tag
!= DW_TAG_module
)
9257 imported_declaration
= imported_name
;
9258 canonical_name
= imported_name_prefix
;
9260 else if (strlen (imported_name_prefix
) > 0)
9261 canonical_name
= obconcat (&objfile
->objfile_obstack
,
9262 imported_name_prefix
,
9263 (cu
->language
== language_d
? "." : "::"),
9264 imported_name
, (char *) NULL
);
9266 canonical_name
= imported_name
;
9268 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
9269 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
9270 child_die
= sibling_die (child_die
))
9272 /* DWARF-4: A Fortran use statement with a “rename list” may be
9273 represented by an imported module entry with an import attribute
9274 referring to the module and owned entries corresponding to those
9275 entities that are renamed as part of being imported. */
9277 if (child_die
->tag
!= DW_TAG_imported_declaration
)
9279 complaint (&symfile_complaints
,
9280 _("child DW_TAG_imported_declaration expected "
9281 "- DIE at 0x%x [in module %s]"),
9282 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
9286 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
9287 if (import_attr
== NULL
)
9289 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
9290 dwarf_tag_name (child_die
->tag
));
9295 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
9297 imported_name
= dwarf2_name (imported_die
, imported_cu
);
9298 if (imported_name
== NULL
)
9300 complaint (&symfile_complaints
,
9301 _("child DW_TAG_imported_declaration has unknown "
9302 "imported name - DIE at 0x%x [in module %s]"),
9303 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
9307 excludes
.push_back (imported_name
);
9309 process_die (child_die
, cu
);
9312 add_using_directive (using_directives (cu
->language
),
9316 imported_declaration
,
9319 &objfile
->objfile_obstack
);
9322 /* ICC<14 does not output the required DW_AT_declaration on incomplete
9323 types, but gives them a size of zero. Starting with version 14,
9324 ICC is compatible with GCC. */
9327 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
9329 if (!cu
->checked_producer
)
9330 check_producer (cu
);
9332 return cu
->producer_is_icc_lt_14
;
9335 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
9336 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
9337 this, it was first present in GCC release 4.3.0. */
9340 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
9342 if (!cu
->checked_producer
)
9343 check_producer (cu
);
9345 return cu
->producer_is_gcc_lt_4_3
;
9348 static file_and_directory
9349 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
9351 file_and_directory res
;
9353 /* Find the filename. Do not use dwarf2_name here, since the filename
9354 is not a source language identifier. */
9355 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
9356 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
9358 if (res
.comp_dir
== NULL
9359 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
9360 && IS_ABSOLUTE_PATH (res
.name
))
9362 res
.comp_dir_storage
= ldirname (res
.name
);
9363 if (!res
.comp_dir_storage
.empty ())
9364 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
9366 if (res
.comp_dir
!= NULL
)
9368 /* Irix 6.2 native cc prepends <machine>.: to the compilation
9369 directory, get rid of it. */
9370 const char *cp
= strchr (res
.comp_dir
, ':');
9372 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
9373 res
.comp_dir
= cp
+ 1;
9376 if (res
.name
== NULL
)
9377 res
.name
= "<unknown>";
9382 /* Handle DW_AT_stmt_list for a compilation unit.
9383 DIE is the DW_TAG_compile_unit die for CU.
9384 COMP_DIR is the compilation directory. LOWPC is passed to
9385 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
9388 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
9389 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
9391 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9392 struct attribute
*attr
;
9393 struct line_header line_header_local
;
9394 hashval_t line_header_local_hash
;
9399 gdb_assert (! cu
->per_cu
->is_debug_types
);
9401 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9405 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
9407 /* The line header hash table is only created if needed (it exists to
9408 prevent redundant reading of the line table for partial_units).
9409 If we're given a partial_unit, we'll need it. If we're given a
9410 compile_unit, then use the line header hash table if it's already
9411 created, but don't create one just yet. */
9413 if (dwarf2_per_objfile
->line_header_hash
== NULL
9414 && die
->tag
== DW_TAG_partial_unit
)
9416 dwarf2_per_objfile
->line_header_hash
9417 = htab_create_alloc_ex (127, line_header_hash_voidp
,
9418 line_header_eq_voidp
,
9419 free_line_header_voidp
,
9420 &objfile
->objfile_obstack
,
9421 hashtab_obstack_allocate
,
9422 dummy_obstack_deallocate
);
9425 line_header_local
.sect_off
= line_offset
;
9426 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
9427 line_header_local_hash
= line_header_hash (&line_header_local
);
9428 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
9430 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9432 line_header_local_hash
, NO_INSERT
);
9434 /* For DW_TAG_compile_unit we need info like symtab::linetable which
9435 is not present in *SLOT (since if there is something in *SLOT then
9436 it will be for a partial_unit). */
9437 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
9439 gdb_assert (*slot
!= NULL
);
9440 cu
->line_header
= (struct line_header
*) *slot
;
9445 /* dwarf_decode_line_header does not yet provide sufficient information.
9446 We always have to call also dwarf_decode_lines for it. */
9447 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
9451 cu
->line_header
= lh
.release ();
9452 cu
->line_header_die_owner
= die
;
9454 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
9458 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9460 line_header_local_hash
, INSERT
);
9461 gdb_assert (slot
!= NULL
);
9463 if (slot
!= NULL
&& *slot
== NULL
)
9465 /* This newly decoded line number information unit will be owned
9466 by line_header_hash hash table. */
9467 *slot
= cu
->line_header
;
9468 cu
->line_header_die_owner
= NULL
;
9472 /* We cannot free any current entry in (*slot) as that struct line_header
9473 may be already used by multiple CUs. Create only temporary decoded
9474 line_header for this CU - it may happen at most once for each line
9475 number information unit. And if we're not using line_header_hash
9476 then this is what we want as well. */
9477 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
9479 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
9480 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
9485 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
9488 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9490 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9491 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9492 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
9493 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
9494 struct attribute
*attr
;
9495 struct die_info
*child_die
;
9498 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9500 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
9502 /* If we didn't find a lowpc, set it to highpc to avoid complaints
9503 from finish_block. */
9504 if (lowpc
== ((CORE_ADDR
) -1))
9506 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
9508 file_and_directory fnd
= find_file_and_directory (die
, cu
);
9510 prepare_one_comp_unit (cu
, die
, cu
->language
);
9512 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
9513 standardised yet. As a workaround for the language detection we fall
9514 back to the DW_AT_producer string. */
9515 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
9516 cu
->language
= language_opencl
;
9518 /* Similar hack for Go. */
9519 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
9520 set_cu_language (DW_LANG_Go
, cu
);
9522 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
9524 /* Decode line number information if present. We do this before
9525 processing child DIEs, so that the line header table is available
9526 for DW_AT_decl_file. */
9527 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
9529 /* Process all dies in compilation unit. */
9530 if (die
->child
!= NULL
)
9532 child_die
= die
->child
;
9533 while (child_die
&& child_die
->tag
)
9535 process_die (child_die
, cu
);
9536 child_die
= sibling_die (child_die
);
9540 /* Decode macro information, if present. Dwarf 2 macro information
9541 refers to information in the line number info statement program
9542 header, so we can only read it if we've read the header
9544 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
9546 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
9547 if (attr
&& cu
->line_header
)
9549 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
9550 complaint (&symfile_complaints
,
9551 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
9553 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
9557 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
9558 if (attr
&& cu
->line_header
)
9560 unsigned int macro_offset
= DW_UNSND (attr
);
9562 dwarf_decode_macros (cu
, macro_offset
, 0);
9567 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
9568 Create the set of symtabs used by this TU, or if this TU is sharing
9569 symtabs with another TU and the symtabs have already been created
9570 then restore those symtabs in the line header.
9571 We don't need the pc/line-number mapping for type units. */
9574 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
9576 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
9577 struct type_unit_group
*tu_group
;
9579 struct attribute
*attr
;
9581 struct signatured_type
*sig_type
;
9583 gdb_assert (per_cu
->is_debug_types
);
9584 sig_type
= (struct signatured_type
*) per_cu
;
9586 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9588 /* If we're using .gdb_index (includes -readnow) then
9589 per_cu->type_unit_group may not have been set up yet. */
9590 if (sig_type
->type_unit_group
== NULL
)
9591 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
9592 tu_group
= sig_type
->type_unit_group
;
9594 /* If we've already processed this stmt_list there's no real need to
9595 do it again, we could fake it and just recreate the part we need
9596 (file name,index -> symtab mapping). If data shows this optimization
9597 is useful we can do it then. */
9598 first_time
= tu_group
->compunit_symtab
== NULL
;
9600 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
9605 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
9606 lh
= dwarf_decode_line_header (line_offset
, cu
);
9611 dwarf2_start_symtab (cu
, "", NULL
, 0);
9614 gdb_assert (tu_group
->symtabs
== NULL
);
9615 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9620 cu
->line_header
= lh
.release ();
9621 cu
->line_header_die_owner
= die
;
9625 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
9627 /* Note: We don't assign tu_group->compunit_symtab yet because we're
9628 still initializing it, and our caller (a few levels up)
9629 process_full_type_unit still needs to know if this is the first
9632 tu_group
->num_symtabs
= cu
->line_header
->file_names
.size ();
9633 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
9634 cu
->line_header
->file_names
.size ());
9636 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
9638 file_entry
&fe
= cu
->line_header
->file_names
[i
];
9640 dwarf2_start_subfile (fe
.name
, fe
.include_dir (cu
->line_header
));
9642 if (current_subfile
->symtab
== NULL
)
9644 /* NOTE: start_subfile will recognize when it's been
9645 passed a file it has already seen. So we can't
9646 assume there's a simple mapping from
9647 cu->line_header->file_names to subfiles, plus
9648 cu->line_header->file_names may contain dups. */
9649 current_subfile
->symtab
9650 = allocate_symtab (cust
, current_subfile
->name
);
9653 fe
.symtab
= current_subfile
->symtab
;
9654 tu_group
->symtabs
[i
] = fe
.symtab
;
9659 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9661 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
9663 file_entry
&fe
= cu
->line_header
->file_names
[i
];
9665 fe
.symtab
= tu_group
->symtabs
[i
];
9669 /* The main symtab is allocated last. Type units don't have DW_AT_name
9670 so they don't have a "real" (so to speak) symtab anyway.
9671 There is later code that will assign the main symtab to all symbols
9672 that don't have one. We need to handle the case of a symbol with a
9673 missing symtab (DW_AT_decl_file) anyway. */
9676 /* Process DW_TAG_type_unit.
9677 For TUs we want to skip the first top level sibling if it's not the
9678 actual type being defined by this TU. In this case the first top
9679 level sibling is there to provide context only. */
9682 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9684 struct die_info
*child_die
;
9686 prepare_one_comp_unit (cu
, die
, language_minimal
);
9688 /* Initialize (or reinitialize) the machinery for building symtabs.
9689 We do this before processing child DIEs, so that the line header table
9690 is available for DW_AT_decl_file. */
9691 setup_type_unit_groups (die
, cu
);
9693 if (die
->child
!= NULL
)
9695 child_die
= die
->child
;
9696 while (child_die
&& child_die
->tag
)
9698 process_die (child_die
, cu
);
9699 child_die
= sibling_die (child_die
);
9706 http://gcc.gnu.org/wiki/DebugFission
9707 http://gcc.gnu.org/wiki/DebugFissionDWP
9709 To simplify handling of both DWO files ("object" files with the DWARF info)
9710 and DWP files (a file with the DWOs packaged up into one file), we treat
9711 DWP files as having a collection of virtual DWO files. */
9714 hash_dwo_file (const void *item
)
9716 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
9719 hash
= htab_hash_string (dwo_file
->dwo_name
);
9720 if (dwo_file
->comp_dir
!= NULL
)
9721 hash
+= htab_hash_string (dwo_file
->comp_dir
);
9726 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
9728 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
9729 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
9731 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
9733 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
9734 return lhs
->comp_dir
== rhs
->comp_dir
;
9735 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
9738 /* Allocate a hash table for DWO files. */
9741 allocate_dwo_file_hash_table (void)
9743 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9745 return htab_create_alloc_ex (41,
9749 &objfile
->objfile_obstack
,
9750 hashtab_obstack_allocate
,
9751 dummy_obstack_deallocate
);
9754 /* Lookup DWO file DWO_NAME. */
9757 lookup_dwo_file_slot (const char *dwo_name
, const char *comp_dir
)
9759 struct dwo_file find_entry
;
9762 if (dwarf2_per_objfile
->dwo_files
== NULL
)
9763 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
9765 memset (&find_entry
, 0, sizeof (find_entry
));
9766 find_entry
.dwo_name
= dwo_name
;
9767 find_entry
.comp_dir
= comp_dir
;
9768 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
9774 hash_dwo_unit (const void *item
)
9776 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
9778 /* This drops the top 32 bits of the id, but is ok for a hash. */
9779 return dwo_unit
->signature
;
9783 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
9785 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
9786 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
9788 /* The signature is assumed to be unique within the DWO file.
9789 So while object file CU dwo_id's always have the value zero,
9790 that's OK, assuming each object file DWO file has only one CU,
9791 and that's the rule for now. */
9792 return lhs
->signature
== rhs
->signature
;
9795 /* Allocate a hash table for DWO CUs,TUs.
9796 There is one of these tables for each of CUs,TUs for each DWO file. */
9799 allocate_dwo_unit_table (struct objfile
*objfile
)
9801 /* Start out with a pretty small number.
9802 Generally DWO files contain only one CU and maybe some TUs. */
9803 return htab_create_alloc_ex (3,
9807 &objfile
->objfile_obstack
,
9808 hashtab_obstack_allocate
,
9809 dummy_obstack_deallocate
);
9812 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
9814 struct create_dwo_cu_data
9816 struct dwo_file
*dwo_file
;
9817 struct dwo_unit dwo_unit
;
9820 /* die_reader_func for create_dwo_cu. */
9823 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
9824 const gdb_byte
*info_ptr
,
9825 struct die_info
*comp_unit_die
,
9829 struct dwarf2_cu
*cu
= reader
->cu
;
9830 sect_offset sect_off
= cu
->per_cu
->sect_off
;
9831 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
9832 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
9833 struct dwo_file
*dwo_file
= data
->dwo_file
;
9834 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
9835 struct attribute
*attr
;
9837 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
9840 complaint (&symfile_complaints
,
9841 _("Dwarf Error: debug entry at offset 0x%x is missing"
9842 " its dwo_id [in module %s]"),
9843 to_underlying (sect_off
), dwo_file
->dwo_name
);
9847 dwo_unit
->dwo_file
= dwo_file
;
9848 dwo_unit
->signature
= DW_UNSND (attr
);
9849 dwo_unit
->section
= section
;
9850 dwo_unit
->sect_off
= sect_off
;
9851 dwo_unit
->length
= cu
->per_cu
->length
;
9853 if (dwarf_read_debug
)
9854 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id %s\n",
9855 to_underlying (sect_off
),
9856 hex_string (dwo_unit
->signature
));
9859 /* Create the dwo_units for the CUs in a DWO_FILE.
9860 Note: This function processes DWO files only, not DWP files. */
9863 create_cus_hash_table (struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
9866 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9867 const struct dwarf2_section_info
*abbrev_section
= &dwo_file
.sections
.abbrev
;
9868 const gdb_byte
*info_ptr
, *end_ptr
;
9870 dwarf2_read_section (objfile
, §ion
);
9871 info_ptr
= section
.buffer
;
9873 if (info_ptr
== NULL
)
9876 if (dwarf_read_debug
)
9878 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
9879 get_section_name (§ion
),
9880 get_section_file_name (§ion
));
9883 end_ptr
= info_ptr
+ section
.size
;
9884 while (info_ptr
< end_ptr
)
9886 struct dwarf2_per_cu_data per_cu
;
9887 struct create_dwo_cu_data create_dwo_cu_data
;
9888 struct dwo_unit
*dwo_unit
;
9890 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
9892 memset (&create_dwo_cu_data
.dwo_unit
, 0,
9893 sizeof (create_dwo_cu_data
.dwo_unit
));
9894 memset (&per_cu
, 0, sizeof (per_cu
));
9895 per_cu
.objfile
= objfile
;
9896 per_cu
.is_debug_types
= 0;
9897 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
9898 per_cu
.section
= §ion
;
9899 create_dwo_cu_data
.dwo_file
= &dwo_file
;
9901 init_cutu_and_read_dies_no_follow (
9902 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
9903 info_ptr
+= per_cu
.length
;
9905 // If the unit could not be parsed, skip it.
9906 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
9909 if (cus_htab
== NULL
)
9910 cus_htab
= allocate_dwo_unit_table (objfile
);
9912 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
9913 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
9914 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
9915 gdb_assert (slot
!= NULL
);
9918 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
9919 sect_offset dup_sect_off
= dup_cu
->sect_off
;
9921 complaint (&symfile_complaints
,
9922 _("debug cu entry at offset 0x%x is duplicate to"
9923 " the entry at offset 0x%x, signature %s"),
9924 to_underlying (sect_off
), to_underlying (dup_sect_off
),
9925 hex_string (dwo_unit
->signature
));
9927 *slot
= (void *)dwo_unit
;
9931 /* DWP file .debug_{cu,tu}_index section format:
9932 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
9936 Both index sections have the same format, and serve to map a 64-bit
9937 signature to a set of section numbers. Each section begins with a header,
9938 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
9939 indexes, and a pool of 32-bit section numbers. The index sections will be
9940 aligned at 8-byte boundaries in the file.
9942 The index section header consists of:
9944 V, 32 bit version number
9946 N, 32 bit number of compilation units or type units in the index
9947 M, 32 bit number of slots in the hash table
9949 Numbers are recorded using the byte order of the application binary.
9951 The hash table begins at offset 16 in the section, and consists of an array
9952 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
9953 order of the application binary). Unused slots in the hash table are 0.
9954 (We rely on the extreme unlikeliness of a signature being exactly 0.)
9956 The parallel table begins immediately after the hash table
9957 (at offset 16 + 8 * M from the beginning of the section), and consists of an
9958 array of 32-bit indexes (using the byte order of the application binary),
9959 corresponding 1-1 with slots in the hash table. Each entry in the parallel
9960 table contains a 32-bit index into the pool of section numbers. For unused
9961 hash table slots, the corresponding entry in the parallel table will be 0.
9963 The pool of section numbers begins immediately following the hash table
9964 (at offset 16 + 12 * M from the beginning of the section). The pool of
9965 section numbers consists of an array of 32-bit words (using the byte order
9966 of the application binary). Each item in the array is indexed starting
9967 from 0. The hash table entry provides the index of the first section
9968 number in the set. Additional section numbers in the set follow, and the
9969 set is terminated by a 0 entry (section number 0 is not used in ELF).
9971 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
9972 section must be the first entry in the set, and the .debug_abbrev.dwo must
9973 be the second entry. Other members of the set may follow in any order.
9979 DWP Version 2 combines all the .debug_info, etc. sections into one,
9980 and the entries in the index tables are now offsets into these sections.
9981 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
9984 Index Section Contents:
9986 Hash Table of Signatures dwp_hash_table.hash_table
9987 Parallel Table of Indices dwp_hash_table.unit_table
9988 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
9989 Table of Section Sizes dwp_hash_table.v2.sizes
9991 The index section header consists of:
9993 V, 32 bit version number
9994 L, 32 bit number of columns in the table of section offsets
9995 N, 32 bit number of compilation units or type units in the index
9996 M, 32 bit number of slots in the hash table
9998 Numbers are recorded using the byte order of the application binary.
10000 The hash table has the same format as version 1.
10001 The parallel table of indices has the same format as version 1,
10002 except that the entries are origin-1 indices into the table of sections
10003 offsets and the table of section sizes.
10005 The table of offsets begins immediately following the parallel table
10006 (at offset 16 + 12 * M from the beginning of the section). The table is
10007 a two-dimensional array of 32-bit words (using the byte order of the
10008 application binary), with L columns and N+1 rows, in row-major order.
10009 Each row in the array is indexed starting from 0. The first row provides
10010 a key to the remaining rows: each column in this row provides an identifier
10011 for a debug section, and the offsets in the same column of subsequent rows
10012 refer to that section. The section identifiers are:
10014 DW_SECT_INFO 1 .debug_info.dwo
10015 DW_SECT_TYPES 2 .debug_types.dwo
10016 DW_SECT_ABBREV 3 .debug_abbrev.dwo
10017 DW_SECT_LINE 4 .debug_line.dwo
10018 DW_SECT_LOC 5 .debug_loc.dwo
10019 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
10020 DW_SECT_MACINFO 7 .debug_macinfo.dwo
10021 DW_SECT_MACRO 8 .debug_macro.dwo
10023 The offsets provided by the CU and TU index sections are the base offsets
10024 for the contributions made by each CU or TU to the corresponding section
10025 in the package file. Each CU and TU header contains an abbrev_offset
10026 field, used to find the abbreviations table for that CU or TU within the
10027 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
10028 be interpreted as relative to the base offset given in the index section.
10029 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
10030 should be interpreted as relative to the base offset for .debug_line.dwo,
10031 and offsets into other debug sections obtained from DWARF attributes should
10032 also be interpreted as relative to the corresponding base offset.
10034 The table of sizes begins immediately following the table of offsets.
10035 Like the table of offsets, it is a two-dimensional array of 32-bit words,
10036 with L columns and N rows, in row-major order. Each row in the array is
10037 indexed starting from 1 (row 0 is shared by the two tables).
10041 Hash table lookup is handled the same in version 1 and 2:
10043 We assume that N and M will not exceed 2^32 - 1.
10044 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
10046 Given a 64-bit compilation unit signature or a type signature S, an entry
10047 in the hash table is located as follows:
10049 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
10050 the low-order k bits all set to 1.
10052 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
10054 3) If the hash table entry at index H matches the signature, use that
10055 entry. If the hash table entry at index H is unused (all zeroes),
10056 terminate the search: the signature is not present in the table.
10058 4) Let H = (H + H') modulo M. Repeat at Step 3.
10060 Because M > N and H' and M are relatively prime, the search is guaranteed
10061 to stop at an unused slot or find the match. */
10063 /* Create a hash table to map DWO IDs to their CU/TU entry in
10064 .debug_{info,types}.dwo in DWP_FILE.
10065 Returns NULL if there isn't one.
10066 Note: This function processes DWP files only, not DWO files. */
10068 static struct dwp_hash_table
*
10069 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
10071 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10072 bfd
*dbfd
= dwp_file
->dbfd
;
10073 const gdb_byte
*index_ptr
, *index_end
;
10074 struct dwarf2_section_info
*index
;
10075 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
10076 struct dwp_hash_table
*htab
;
10078 if (is_debug_types
)
10079 index
= &dwp_file
->sections
.tu_index
;
10081 index
= &dwp_file
->sections
.cu_index
;
10083 if (dwarf2_section_empty_p (index
))
10085 dwarf2_read_section (objfile
, index
);
10087 index_ptr
= index
->buffer
;
10088 index_end
= index_ptr
+ index
->size
;
10090 version
= read_4_bytes (dbfd
, index_ptr
);
10093 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
10097 nr_units
= read_4_bytes (dbfd
, index_ptr
);
10099 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
10102 if (version
!= 1 && version
!= 2)
10104 error (_("Dwarf Error: unsupported DWP file version (%s)"
10105 " [in module %s]"),
10106 pulongest (version
), dwp_file
->name
);
10108 if (nr_slots
!= (nr_slots
& -nr_slots
))
10110 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
10111 " is not power of 2 [in module %s]"),
10112 pulongest (nr_slots
), dwp_file
->name
);
10115 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
10116 htab
->version
= version
;
10117 htab
->nr_columns
= nr_columns
;
10118 htab
->nr_units
= nr_units
;
10119 htab
->nr_slots
= nr_slots
;
10120 htab
->hash_table
= index_ptr
;
10121 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
10123 /* Exit early if the table is empty. */
10124 if (nr_slots
== 0 || nr_units
== 0
10125 || (version
== 2 && nr_columns
== 0))
10127 /* All must be zero. */
10128 if (nr_slots
!= 0 || nr_units
!= 0
10129 || (version
== 2 && nr_columns
!= 0))
10131 complaint (&symfile_complaints
,
10132 _("Empty DWP but nr_slots,nr_units,nr_columns not"
10133 " all zero [in modules %s]"),
10141 htab
->section_pool
.v1
.indices
=
10142 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
10143 /* It's harder to decide whether the section is too small in v1.
10144 V1 is deprecated anyway so we punt. */
10148 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
10149 int *ids
= htab
->section_pool
.v2
.section_ids
;
10150 /* Reverse map for error checking. */
10151 int ids_seen
[DW_SECT_MAX
+ 1];
10154 if (nr_columns
< 2)
10156 error (_("Dwarf Error: bad DWP hash table, too few columns"
10157 " in section table [in module %s]"),
10160 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
10162 error (_("Dwarf Error: bad DWP hash table, too many columns"
10163 " in section table [in module %s]"),
10166 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
10167 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
10168 for (i
= 0; i
< nr_columns
; ++i
)
10170 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
10172 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
10174 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
10175 " in section table [in module %s]"),
10176 id
, dwp_file
->name
);
10178 if (ids_seen
[id
] != -1)
10180 error (_("Dwarf Error: bad DWP hash table, duplicate section"
10181 " id %d in section table [in module %s]"),
10182 id
, dwp_file
->name
);
10187 /* Must have exactly one info or types section. */
10188 if (((ids_seen
[DW_SECT_INFO
] != -1)
10189 + (ids_seen
[DW_SECT_TYPES
] != -1))
10192 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
10193 " DWO info/types section [in module %s]"),
10196 /* Must have an abbrev section. */
10197 if (ids_seen
[DW_SECT_ABBREV
] == -1)
10199 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
10200 " section [in module %s]"),
10203 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
10204 htab
->section_pool
.v2
.sizes
=
10205 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
10206 * nr_units
* nr_columns
);
10207 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
10208 * nr_units
* nr_columns
))
10211 error (_("Dwarf Error: DWP index section is corrupt (too small)"
10212 " [in module %s]"),
10220 /* Update SECTIONS with the data from SECTP.
10222 This function is like the other "locate" section routines that are
10223 passed to bfd_map_over_sections, but in this context the sections to
10224 read comes from the DWP V1 hash table, not the full ELF section table.
10226 The result is non-zero for success, or zero if an error was found. */
10229 locate_v1_virtual_dwo_sections (asection
*sectp
,
10230 struct virtual_v1_dwo_sections
*sections
)
10232 const struct dwop_section_names
*names
= &dwop_section_names
;
10234 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10236 /* There can be only one. */
10237 if (sections
->abbrev
.s
.section
!= NULL
)
10239 sections
->abbrev
.s
.section
= sectp
;
10240 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10242 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
10243 || section_is_p (sectp
->name
, &names
->types_dwo
))
10245 /* There can be only one. */
10246 if (sections
->info_or_types
.s
.section
!= NULL
)
10248 sections
->info_or_types
.s
.section
= sectp
;
10249 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
10251 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10253 /* There can be only one. */
10254 if (sections
->line
.s
.section
!= NULL
)
10256 sections
->line
.s
.section
= sectp
;
10257 sections
->line
.size
= bfd_get_section_size (sectp
);
10259 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10261 /* There can be only one. */
10262 if (sections
->loc
.s
.section
!= NULL
)
10264 sections
->loc
.s
.section
= sectp
;
10265 sections
->loc
.size
= bfd_get_section_size (sectp
);
10267 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10269 /* There can be only one. */
10270 if (sections
->macinfo
.s
.section
!= NULL
)
10272 sections
->macinfo
.s
.section
= sectp
;
10273 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10275 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10277 /* There can be only one. */
10278 if (sections
->macro
.s
.section
!= NULL
)
10280 sections
->macro
.s
.section
= sectp
;
10281 sections
->macro
.size
= bfd_get_section_size (sectp
);
10283 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10285 /* There can be only one. */
10286 if (sections
->str_offsets
.s
.section
!= NULL
)
10288 sections
->str_offsets
.s
.section
= sectp
;
10289 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10293 /* No other kind of section is valid. */
10300 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10301 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10302 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10303 This is for DWP version 1 files. */
10305 static struct dwo_unit
*
10306 create_dwo_unit_in_dwp_v1 (struct dwp_file
*dwp_file
,
10307 uint32_t unit_index
,
10308 const char *comp_dir
,
10309 ULONGEST signature
, int is_debug_types
)
10311 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10312 const struct dwp_hash_table
*dwp_htab
=
10313 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10314 bfd
*dbfd
= dwp_file
->dbfd
;
10315 const char *kind
= is_debug_types
? "TU" : "CU";
10316 struct dwo_file
*dwo_file
;
10317 struct dwo_unit
*dwo_unit
;
10318 struct virtual_v1_dwo_sections sections
;
10319 void **dwo_file_slot
;
10322 gdb_assert (dwp_file
->version
== 1);
10324 if (dwarf_read_debug
)
10326 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
10328 pulongest (unit_index
), hex_string (signature
),
10332 /* Fetch the sections of this DWO unit.
10333 Put a limit on the number of sections we look for so that bad data
10334 doesn't cause us to loop forever. */
10336 #define MAX_NR_V1_DWO_SECTIONS \
10337 (1 /* .debug_info or .debug_types */ \
10338 + 1 /* .debug_abbrev */ \
10339 + 1 /* .debug_line */ \
10340 + 1 /* .debug_loc */ \
10341 + 1 /* .debug_str_offsets */ \
10342 + 1 /* .debug_macro or .debug_macinfo */ \
10343 + 1 /* trailing zero */)
10345 memset (§ions
, 0, sizeof (sections
));
10347 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
10350 uint32_t section_nr
=
10351 read_4_bytes (dbfd
,
10352 dwp_htab
->section_pool
.v1
.indices
10353 + (unit_index
+ i
) * sizeof (uint32_t));
10355 if (section_nr
== 0)
10357 if (section_nr
>= dwp_file
->num_sections
)
10359 error (_("Dwarf Error: bad DWP hash table, section number too large"
10360 " [in module %s]"),
10364 sectp
= dwp_file
->elf_sections
[section_nr
];
10365 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
10367 error (_("Dwarf Error: bad DWP hash table, invalid section found"
10368 " [in module %s]"),
10374 || dwarf2_section_empty_p (§ions
.info_or_types
)
10375 || dwarf2_section_empty_p (§ions
.abbrev
))
10377 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
10378 " [in module %s]"),
10381 if (i
== MAX_NR_V1_DWO_SECTIONS
)
10383 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
10384 " [in module %s]"),
10388 /* It's easier for the rest of the code if we fake a struct dwo_file and
10389 have dwo_unit "live" in that. At least for now.
10391 The DWP file can be made up of a random collection of CUs and TUs.
10392 However, for each CU + set of TUs that came from the same original DWO
10393 file, we can combine them back into a virtual DWO file to save space
10394 (fewer struct dwo_file objects to allocate). Remember that for really
10395 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10397 std::string virtual_dwo_name
=
10398 string_printf ("virtual-dwo/%d-%d-%d-%d",
10399 get_section_id (§ions
.abbrev
),
10400 get_section_id (§ions
.line
),
10401 get_section_id (§ions
.loc
),
10402 get_section_id (§ions
.str_offsets
));
10403 /* Can we use an existing virtual DWO file? */
10404 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
.c_str (), comp_dir
);
10405 /* Create one if necessary. */
10406 if (*dwo_file_slot
== NULL
)
10408 if (dwarf_read_debug
)
10410 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10411 virtual_dwo_name
.c_str ());
10413 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10415 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
10416 virtual_dwo_name
.c_str (),
10417 virtual_dwo_name
.size ());
10418 dwo_file
->comp_dir
= comp_dir
;
10419 dwo_file
->sections
.abbrev
= sections
.abbrev
;
10420 dwo_file
->sections
.line
= sections
.line
;
10421 dwo_file
->sections
.loc
= sections
.loc
;
10422 dwo_file
->sections
.macinfo
= sections
.macinfo
;
10423 dwo_file
->sections
.macro
= sections
.macro
;
10424 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
10425 /* The "str" section is global to the entire DWP file. */
10426 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10427 /* The info or types section is assigned below to dwo_unit,
10428 there's no need to record it in dwo_file.
10429 Also, we can't simply record type sections in dwo_file because
10430 we record a pointer into the vector in dwo_unit. As we collect more
10431 types we'll grow the vector and eventually have to reallocate space
10432 for it, invalidating all copies of pointers into the previous
10434 *dwo_file_slot
= dwo_file
;
10438 if (dwarf_read_debug
)
10440 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10441 virtual_dwo_name
.c_str ());
10443 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10446 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10447 dwo_unit
->dwo_file
= dwo_file
;
10448 dwo_unit
->signature
= signature
;
10449 dwo_unit
->section
=
10450 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
10451 *dwo_unit
->section
= sections
.info_or_types
;
10452 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10457 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
10458 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
10459 piece within that section used by a TU/CU, return a virtual section
10460 of just that piece. */
10462 static struct dwarf2_section_info
10463 create_dwp_v2_section (struct dwarf2_section_info
*section
,
10464 bfd_size_type offset
, bfd_size_type size
)
10466 struct dwarf2_section_info result
;
10469 gdb_assert (section
!= NULL
);
10470 gdb_assert (!section
->is_virtual
);
10472 memset (&result
, 0, sizeof (result
));
10473 result
.s
.containing_section
= section
;
10474 result
.is_virtual
= 1;
10479 sectp
= get_section_bfd_section (section
);
10481 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
10482 bounds of the real section. This is a pretty-rare event, so just
10483 flag an error (easier) instead of a warning and trying to cope. */
10485 || offset
+ size
> bfd_get_section_size (sectp
))
10487 bfd
*abfd
= sectp
->owner
;
10489 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
10490 " in section %s [in module %s]"),
10491 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
10492 objfile_name (dwarf2_per_objfile
->objfile
));
10495 result
.virtual_offset
= offset
;
10496 result
.size
= size
;
10500 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10501 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10502 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10503 This is for DWP version 2 files. */
10505 static struct dwo_unit
*
10506 create_dwo_unit_in_dwp_v2 (struct dwp_file
*dwp_file
,
10507 uint32_t unit_index
,
10508 const char *comp_dir
,
10509 ULONGEST signature
, int is_debug_types
)
10511 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10512 const struct dwp_hash_table
*dwp_htab
=
10513 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10514 bfd
*dbfd
= dwp_file
->dbfd
;
10515 const char *kind
= is_debug_types
? "TU" : "CU";
10516 struct dwo_file
*dwo_file
;
10517 struct dwo_unit
*dwo_unit
;
10518 struct virtual_v2_dwo_sections sections
;
10519 void **dwo_file_slot
;
10522 gdb_assert (dwp_file
->version
== 2);
10524 if (dwarf_read_debug
)
10526 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
10528 pulongest (unit_index
), hex_string (signature
),
10532 /* Fetch the section offsets of this DWO unit. */
10534 memset (§ions
, 0, sizeof (sections
));
10536 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
10538 uint32_t offset
= read_4_bytes (dbfd
,
10539 dwp_htab
->section_pool
.v2
.offsets
10540 + (((unit_index
- 1) * dwp_htab
->nr_columns
10542 * sizeof (uint32_t)));
10543 uint32_t size
= read_4_bytes (dbfd
,
10544 dwp_htab
->section_pool
.v2
.sizes
10545 + (((unit_index
- 1) * dwp_htab
->nr_columns
10547 * sizeof (uint32_t)));
10549 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
10552 case DW_SECT_TYPES
:
10553 sections
.info_or_types_offset
= offset
;
10554 sections
.info_or_types_size
= size
;
10556 case DW_SECT_ABBREV
:
10557 sections
.abbrev_offset
= offset
;
10558 sections
.abbrev_size
= size
;
10561 sections
.line_offset
= offset
;
10562 sections
.line_size
= size
;
10565 sections
.loc_offset
= offset
;
10566 sections
.loc_size
= size
;
10568 case DW_SECT_STR_OFFSETS
:
10569 sections
.str_offsets_offset
= offset
;
10570 sections
.str_offsets_size
= size
;
10572 case DW_SECT_MACINFO
:
10573 sections
.macinfo_offset
= offset
;
10574 sections
.macinfo_size
= size
;
10576 case DW_SECT_MACRO
:
10577 sections
.macro_offset
= offset
;
10578 sections
.macro_size
= size
;
10583 /* It's easier for the rest of the code if we fake a struct dwo_file and
10584 have dwo_unit "live" in that. At least for now.
10586 The DWP file can be made up of a random collection of CUs and TUs.
10587 However, for each CU + set of TUs that came from the same original DWO
10588 file, we can combine them back into a virtual DWO file to save space
10589 (fewer struct dwo_file objects to allocate). Remember that for really
10590 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10592 std::string virtual_dwo_name
=
10593 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
10594 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
10595 (long) (sections
.line_size
? sections
.line_offset
: 0),
10596 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
10597 (long) (sections
.str_offsets_size
10598 ? sections
.str_offsets_offset
: 0));
10599 /* Can we use an existing virtual DWO file? */
10600 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
.c_str (), comp_dir
);
10601 /* Create one if necessary. */
10602 if (*dwo_file_slot
== NULL
)
10604 if (dwarf_read_debug
)
10606 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10607 virtual_dwo_name
.c_str ());
10609 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10611 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
10612 virtual_dwo_name
.c_str (),
10613 virtual_dwo_name
.size ());
10614 dwo_file
->comp_dir
= comp_dir
;
10615 dwo_file
->sections
.abbrev
=
10616 create_dwp_v2_section (&dwp_file
->sections
.abbrev
,
10617 sections
.abbrev_offset
, sections
.abbrev_size
);
10618 dwo_file
->sections
.line
=
10619 create_dwp_v2_section (&dwp_file
->sections
.line
,
10620 sections
.line_offset
, sections
.line_size
);
10621 dwo_file
->sections
.loc
=
10622 create_dwp_v2_section (&dwp_file
->sections
.loc
,
10623 sections
.loc_offset
, sections
.loc_size
);
10624 dwo_file
->sections
.macinfo
=
10625 create_dwp_v2_section (&dwp_file
->sections
.macinfo
,
10626 sections
.macinfo_offset
, sections
.macinfo_size
);
10627 dwo_file
->sections
.macro
=
10628 create_dwp_v2_section (&dwp_file
->sections
.macro
,
10629 sections
.macro_offset
, sections
.macro_size
);
10630 dwo_file
->sections
.str_offsets
=
10631 create_dwp_v2_section (&dwp_file
->sections
.str_offsets
,
10632 sections
.str_offsets_offset
,
10633 sections
.str_offsets_size
);
10634 /* The "str" section is global to the entire DWP file. */
10635 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10636 /* The info or types section is assigned below to dwo_unit,
10637 there's no need to record it in dwo_file.
10638 Also, we can't simply record type sections in dwo_file because
10639 we record a pointer into the vector in dwo_unit. As we collect more
10640 types we'll grow the vector and eventually have to reallocate space
10641 for it, invalidating all copies of pointers into the previous
10643 *dwo_file_slot
= dwo_file
;
10647 if (dwarf_read_debug
)
10649 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10650 virtual_dwo_name
.c_str ());
10652 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10655 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10656 dwo_unit
->dwo_file
= dwo_file
;
10657 dwo_unit
->signature
= signature
;
10658 dwo_unit
->section
=
10659 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
10660 *dwo_unit
->section
= create_dwp_v2_section (is_debug_types
10661 ? &dwp_file
->sections
.types
10662 : &dwp_file
->sections
.info
,
10663 sections
.info_or_types_offset
,
10664 sections
.info_or_types_size
);
10665 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10670 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
10671 Returns NULL if the signature isn't found. */
10673 static struct dwo_unit
*
10674 lookup_dwo_unit_in_dwp (struct dwp_file
*dwp_file
, const char *comp_dir
,
10675 ULONGEST signature
, int is_debug_types
)
10677 const struct dwp_hash_table
*dwp_htab
=
10678 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10679 bfd
*dbfd
= dwp_file
->dbfd
;
10680 uint32_t mask
= dwp_htab
->nr_slots
- 1;
10681 uint32_t hash
= signature
& mask
;
10682 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
10685 struct dwo_unit find_dwo_cu
;
10687 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
10688 find_dwo_cu
.signature
= signature
;
10689 slot
= htab_find_slot (is_debug_types
10690 ? dwp_file
->loaded_tus
10691 : dwp_file
->loaded_cus
,
10692 &find_dwo_cu
, INSERT
);
10695 return (struct dwo_unit
*) *slot
;
10697 /* Use a for loop so that we don't loop forever on bad debug info. */
10698 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
10700 ULONGEST signature_in_table
;
10702 signature_in_table
=
10703 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
10704 if (signature_in_table
== signature
)
10706 uint32_t unit_index
=
10707 read_4_bytes (dbfd
,
10708 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
10710 if (dwp_file
->version
== 1)
10712 *slot
= create_dwo_unit_in_dwp_v1 (dwp_file
, unit_index
,
10713 comp_dir
, signature
,
10718 *slot
= create_dwo_unit_in_dwp_v2 (dwp_file
, unit_index
,
10719 comp_dir
, signature
,
10722 return (struct dwo_unit
*) *slot
;
10724 if (signature_in_table
== 0)
10726 hash
= (hash
+ hash2
) & mask
;
10729 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
10730 " [in module %s]"),
10734 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
10735 Open the file specified by FILE_NAME and hand it off to BFD for
10736 preliminary analysis. Return a newly initialized bfd *, which
10737 includes a canonicalized copy of FILE_NAME.
10738 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
10739 SEARCH_CWD is true if the current directory is to be searched.
10740 It will be searched before debug-file-directory.
10741 If successful, the file is added to the bfd include table of the
10742 objfile's bfd (see gdb_bfd_record_inclusion).
10743 If unable to find/open the file, return NULL.
10744 NOTE: This function is derived from symfile_bfd_open. */
10746 static gdb_bfd_ref_ptr
10747 try_open_dwop_file (const char *file_name
, int is_dwp
, int search_cwd
)
10750 char *absolute_name
;
10751 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
10752 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
10753 to debug_file_directory. */
10755 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
10759 if (*debug_file_directory
!= '\0')
10760 search_path
= concat (".", dirname_separator_string
,
10761 debug_file_directory
, (char *) NULL
);
10763 search_path
= xstrdup (".");
10766 search_path
= xstrdup (debug_file_directory
);
10768 flags
= OPF_RETURN_REALPATH
;
10770 flags
|= OPF_SEARCH_IN_PATH
;
10771 desc
= openp (search_path
, flags
, file_name
,
10772 O_RDONLY
| O_BINARY
, &absolute_name
);
10773 xfree (search_path
);
10777 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
, gnutarget
, desc
));
10778 xfree (absolute_name
);
10779 if (sym_bfd
== NULL
)
10781 bfd_set_cacheable (sym_bfd
.get (), 1);
10783 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
10786 /* Success. Record the bfd as having been included by the objfile's bfd.
10787 This is important because things like demangled_names_hash lives in the
10788 objfile's per_bfd space and may have references to things like symbol
10789 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
10790 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
10795 /* Try to open DWO file FILE_NAME.
10796 COMP_DIR is the DW_AT_comp_dir attribute.
10797 The result is the bfd handle of the file.
10798 If there is a problem finding or opening the file, return NULL.
10799 Upon success, the canonicalized path of the file is stored in the bfd,
10800 same as symfile_bfd_open. */
10802 static gdb_bfd_ref_ptr
10803 open_dwo_file (const char *file_name
, const char *comp_dir
)
10805 if (IS_ABSOLUTE_PATH (file_name
))
10806 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 0 /*search_cwd*/);
10808 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
10810 if (comp_dir
!= NULL
)
10812 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
10813 file_name
, (char *) NULL
);
10815 /* NOTE: If comp_dir is a relative path, this will also try the
10816 search path, which seems useful. */
10817 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (path_to_try
, 0 /*is_dwp*/,
10818 1 /*search_cwd*/));
10819 xfree (path_to_try
);
10824 /* That didn't work, try debug-file-directory, which, despite its name,
10825 is a list of paths. */
10827 if (*debug_file_directory
== '\0')
10830 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 1 /*search_cwd*/);
10833 /* This function is mapped across the sections and remembers the offset and
10834 size of each of the DWO debugging sections we are interested in. */
10837 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
10839 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
10840 const struct dwop_section_names
*names
= &dwop_section_names
;
10842 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10844 dwo_sections
->abbrev
.s
.section
= sectp
;
10845 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10847 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10849 dwo_sections
->info
.s
.section
= sectp
;
10850 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
10852 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10854 dwo_sections
->line
.s
.section
= sectp
;
10855 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
10857 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10859 dwo_sections
->loc
.s
.section
= sectp
;
10860 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
10862 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10864 dwo_sections
->macinfo
.s
.section
= sectp
;
10865 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10867 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10869 dwo_sections
->macro
.s
.section
= sectp
;
10870 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
10872 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
10874 dwo_sections
->str
.s
.section
= sectp
;
10875 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
10877 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10879 dwo_sections
->str_offsets
.s
.section
= sectp
;
10880 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10882 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10884 struct dwarf2_section_info type_section
;
10886 memset (&type_section
, 0, sizeof (type_section
));
10887 type_section
.s
.section
= sectp
;
10888 type_section
.size
= bfd_get_section_size (sectp
);
10889 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
10894 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
10895 by PER_CU. This is for the non-DWP case.
10896 The result is NULL if DWO_NAME can't be found. */
10898 static struct dwo_file
*
10899 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
10900 const char *dwo_name
, const char *comp_dir
)
10902 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10903 struct dwo_file
*dwo_file
;
10904 struct cleanup
*cleanups
;
10906 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwo_name
, comp_dir
));
10909 if (dwarf_read_debug
)
10910 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
10913 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10914 dwo_file
->dwo_name
= dwo_name
;
10915 dwo_file
->comp_dir
= comp_dir
;
10916 dwo_file
->dbfd
= dbfd
.release ();
10918 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
10920 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
10921 &dwo_file
->sections
);
10923 create_cus_hash_table (*dwo_file
, dwo_file
->sections
.info
, dwo_file
->cus
);
10925 create_debug_types_hash_table (dwo_file
, dwo_file
->sections
.types
,
10928 discard_cleanups (cleanups
);
10930 if (dwarf_read_debug
)
10931 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
10936 /* This function is mapped across the sections and remembers the offset and
10937 size of each of the DWP debugging sections common to version 1 and 2 that
10938 we are interested in. */
10941 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
10942 void *dwp_file_ptr
)
10944 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
10945 const struct dwop_section_names
*names
= &dwop_section_names
;
10946 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10948 /* Record the ELF section number for later lookup: this is what the
10949 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10950 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10951 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10953 /* Look for specific sections that we need. */
10954 if (section_is_p (sectp
->name
, &names
->str_dwo
))
10956 dwp_file
->sections
.str
.s
.section
= sectp
;
10957 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
10959 else if (section_is_p (sectp
->name
, &names
->cu_index
))
10961 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
10962 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
10964 else if (section_is_p (sectp
->name
, &names
->tu_index
))
10966 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
10967 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
10971 /* This function is mapped across the sections and remembers the offset and
10972 size of each of the DWP version 2 debugging sections that we are interested
10973 in. This is split into a separate function because we don't know if we
10974 have version 1 or 2 until we parse the cu_index/tu_index sections. */
10977 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
10979 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
10980 const struct dwop_section_names
*names
= &dwop_section_names
;
10981 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10983 /* Record the ELF section number for later lookup: this is what the
10984 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10985 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10986 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10988 /* Look for specific sections that we need. */
10989 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10991 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
10992 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
10994 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10996 dwp_file
->sections
.info
.s
.section
= sectp
;
10997 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
10999 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11001 dwp_file
->sections
.line
.s
.section
= sectp
;
11002 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
11004 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11006 dwp_file
->sections
.loc
.s
.section
= sectp
;
11007 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
11009 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11011 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
11012 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
11014 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11016 dwp_file
->sections
.macro
.s
.section
= sectp
;
11017 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
11019 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11021 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
11022 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
11024 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
11026 dwp_file
->sections
.types
.s
.section
= sectp
;
11027 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
11031 /* Hash function for dwp_file loaded CUs/TUs. */
11034 hash_dwp_loaded_cutus (const void *item
)
11036 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11038 /* This drops the top 32 bits of the signature, but is ok for a hash. */
11039 return dwo_unit
->signature
;
11042 /* Equality function for dwp_file loaded CUs/TUs. */
11045 eq_dwp_loaded_cutus (const void *a
, const void *b
)
11047 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
11048 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
11050 return dua
->signature
== dub
->signature
;
11053 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
11056 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
11058 return htab_create_alloc_ex (3,
11059 hash_dwp_loaded_cutus
,
11060 eq_dwp_loaded_cutus
,
11062 &objfile
->objfile_obstack
,
11063 hashtab_obstack_allocate
,
11064 dummy_obstack_deallocate
);
11067 /* Try to open DWP file FILE_NAME.
11068 The result is the bfd handle of the file.
11069 If there is a problem finding or opening the file, return NULL.
11070 Upon success, the canonicalized path of the file is stored in the bfd,
11071 same as symfile_bfd_open. */
11073 static gdb_bfd_ref_ptr
11074 open_dwp_file (const char *file_name
)
11076 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (file_name
, 1 /*is_dwp*/,
11077 1 /*search_cwd*/));
11081 /* Work around upstream bug 15652.
11082 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
11083 [Whether that's a "bug" is debatable, but it is getting in our way.]
11084 We have no real idea where the dwp file is, because gdb's realpath-ing
11085 of the executable's path may have discarded the needed info.
11086 [IWBN if the dwp file name was recorded in the executable, akin to
11087 .gnu_debuglink, but that doesn't exist yet.]
11088 Strip the directory from FILE_NAME and search again. */
11089 if (*debug_file_directory
!= '\0')
11091 /* Don't implicitly search the current directory here.
11092 If the user wants to search "." to handle this case,
11093 it must be added to debug-file-directory. */
11094 return try_open_dwop_file (lbasename (file_name
), 1 /*is_dwp*/,
11101 /* Initialize the use of the DWP file for the current objfile.
11102 By convention the name of the DWP file is ${objfile}.dwp.
11103 The result is NULL if it can't be found. */
11105 static struct dwp_file
*
11106 open_and_init_dwp_file (void)
11108 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11109 struct dwp_file
*dwp_file
;
11111 /* Try to find first .dwp for the binary file before any symbolic links
11114 /* If the objfile is a debug file, find the name of the real binary
11115 file and get the name of dwp file from there. */
11116 std::string dwp_name
;
11117 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
11119 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
11120 const char *backlink_basename
= lbasename (backlink
->original_name
);
11122 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
11125 dwp_name
= objfile
->original_name
;
11127 dwp_name
+= ".dwp";
11129 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwp_name
.c_str ()));
11131 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
11133 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
11134 dwp_name
= objfile_name (objfile
);
11135 dwp_name
+= ".dwp";
11136 dbfd
= open_dwp_file (dwp_name
.c_str ());
11141 if (dwarf_read_debug
)
11142 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
11145 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
11146 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
11147 dwp_file
->dbfd
= dbfd
.release ();
11149 /* +1: section 0 is unused */
11150 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
11151 dwp_file
->elf_sections
=
11152 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
11153 dwp_file
->num_sections
, asection
*);
11155 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
11158 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
11160 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
11162 /* The DWP file version is stored in the hash table. Oh well. */
11163 if (dwp_file
->cus
&& dwp_file
->tus
11164 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
11166 /* Technically speaking, we should try to limp along, but this is
11167 pretty bizarre. We use pulongest here because that's the established
11168 portability solution (e.g, we cannot use %u for uint32_t). */
11169 error (_("Dwarf Error: DWP file CU version %s doesn't match"
11170 " TU version %s [in DWP file %s]"),
11171 pulongest (dwp_file
->cus
->version
),
11172 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
11176 dwp_file
->version
= dwp_file
->cus
->version
;
11177 else if (dwp_file
->tus
)
11178 dwp_file
->version
= dwp_file
->tus
->version
;
11180 dwp_file
->version
= 2;
11182 if (dwp_file
->version
== 2)
11183 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
11186 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
11187 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
11189 if (dwarf_read_debug
)
11191 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
11192 fprintf_unfiltered (gdb_stdlog
,
11193 " %s CUs, %s TUs\n",
11194 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
11195 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
11201 /* Wrapper around open_and_init_dwp_file, only open it once. */
11203 static struct dwp_file
*
11204 get_dwp_file (void)
11206 if (! dwarf2_per_objfile
->dwp_checked
)
11208 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file ();
11209 dwarf2_per_objfile
->dwp_checked
= 1;
11211 return dwarf2_per_objfile
->dwp_file
;
11214 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
11215 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
11216 or in the DWP file for the objfile, referenced by THIS_UNIT.
11217 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
11218 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
11220 This is called, for example, when wanting to read a variable with a
11221 complex location. Therefore we don't want to do file i/o for every call.
11222 Therefore we don't want to look for a DWO file on every call.
11223 Therefore we first see if we've already seen SIGNATURE in a DWP file,
11224 then we check if we've already seen DWO_NAME, and only THEN do we check
11227 The result is a pointer to the dwo_unit object or NULL if we didn't find it
11228 (dwo_id mismatch or couldn't find the DWO/DWP file). */
11230 static struct dwo_unit
*
11231 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
11232 const char *dwo_name
, const char *comp_dir
,
11233 ULONGEST signature
, int is_debug_types
)
11235 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11236 const char *kind
= is_debug_types
? "TU" : "CU";
11237 void **dwo_file_slot
;
11238 struct dwo_file
*dwo_file
;
11239 struct dwp_file
*dwp_file
;
11241 /* First see if there's a DWP file.
11242 If we have a DWP file but didn't find the DWO inside it, don't
11243 look for the original DWO file. It makes gdb behave differently
11244 depending on whether one is debugging in the build tree. */
11246 dwp_file
= get_dwp_file ();
11247 if (dwp_file
!= NULL
)
11249 const struct dwp_hash_table
*dwp_htab
=
11250 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11252 if (dwp_htab
!= NULL
)
11254 struct dwo_unit
*dwo_cutu
=
11255 lookup_dwo_unit_in_dwp (dwp_file
, comp_dir
,
11256 signature
, is_debug_types
);
11258 if (dwo_cutu
!= NULL
)
11260 if (dwarf_read_debug
)
11262 fprintf_unfiltered (gdb_stdlog
,
11263 "Virtual DWO %s %s found: @%s\n",
11264 kind
, hex_string (signature
),
11265 host_address_to_string (dwo_cutu
));
11273 /* No DWP file, look for the DWO file. */
11275 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
, comp_dir
);
11276 if (*dwo_file_slot
== NULL
)
11278 /* Read in the file and build a table of the CUs/TUs it contains. */
11279 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
11281 /* NOTE: This will be NULL if unable to open the file. */
11282 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11284 if (dwo_file
!= NULL
)
11286 struct dwo_unit
*dwo_cutu
= NULL
;
11288 if (is_debug_types
&& dwo_file
->tus
)
11290 struct dwo_unit find_dwo_cutu
;
11292 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
11293 find_dwo_cutu
.signature
= signature
;
11295 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
11297 else if (!is_debug_types
&& dwo_file
->cus
)
11299 struct dwo_unit find_dwo_cutu
;
11301 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
11302 find_dwo_cutu
.signature
= signature
;
11303 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
11307 if (dwo_cutu
!= NULL
)
11309 if (dwarf_read_debug
)
11311 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
11312 kind
, dwo_name
, hex_string (signature
),
11313 host_address_to_string (dwo_cutu
));
11320 /* We didn't find it. This could mean a dwo_id mismatch, or
11321 someone deleted the DWO/DWP file, or the search path isn't set up
11322 correctly to find the file. */
11324 if (dwarf_read_debug
)
11326 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
11327 kind
, dwo_name
, hex_string (signature
));
11330 /* This is a warning and not a complaint because it can be caused by
11331 pilot error (e.g., user accidentally deleting the DWO). */
11333 /* Print the name of the DWP file if we looked there, helps the user
11334 better diagnose the problem. */
11335 std::string dwp_text
;
11337 if (dwp_file
!= NULL
)
11338 dwp_text
= string_printf (" [in DWP file %s]",
11339 lbasename (dwp_file
->name
));
11341 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset 0x%x"
11342 " [in module %s]"),
11343 kind
, dwo_name
, hex_string (signature
),
11345 this_unit
->is_debug_types
? "TU" : "CU",
11346 to_underlying (this_unit
->sect_off
), objfile_name (objfile
));
11351 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
11352 See lookup_dwo_cutu_unit for details. */
11354 static struct dwo_unit
*
11355 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
11356 const char *dwo_name
, const char *comp_dir
,
11357 ULONGEST signature
)
11359 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
11362 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
11363 See lookup_dwo_cutu_unit for details. */
11365 static struct dwo_unit
*
11366 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
11367 const char *dwo_name
, const char *comp_dir
)
11369 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
11372 /* Traversal function for queue_and_load_all_dwo_tus. */
11375 queue_and_load_dwo_tu (void **slot
, void *info
)
11377 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
11378 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
11379 ULONGEST signature
= dwo_unit
->signature
;
11380 struct signatured_type
*sig_type
=
11381 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
11383 if (sig_type
!= NULL
)
11385 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
11387 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
11388 a real dependency of PER_CU on SIG_TYPE. That is detected later
11389 while processing PER_CU. */
11390 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
11391 load_full_type_unit (sig_cu
);
11392 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
11398 /* Queue all TUs contained in the DWO of PER_CU to be read in.
11399 The DWO may have the only definition of the type, though it may not be
11400 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
11401 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
11404 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
11406 struct dwo_unit
*dwo_unit
;
11407 struct dwo_file
*dwo_file
;
11409 gdb_assert (!per_cu
->is_debug_types
);
11410 gdb_assert (get_dwp_file () == NULL
);
11411 gdb_assert (per_cu
->cu
!= NULL
);
11413 dwo_unit
= per_cu
->cu
->dwo_unit
;
11414 gdb_assert (dwo_unit
!= NULL
);
11416 dwo_file
= dwo_unit
->dwo_file
;
11417 if (dwo_file
->tus
!= NULL
)
11418 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
11421 /* Free all resources associated with DWO_FILE.
11422 Close the DWO file and munmap the sections.
11423 All memory should be on the objfile obstack. */
11426 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
11429 /* Note: dbfd is NULL for virtual DWO files. */
11430 gdb_bfd_unref (dwo_file
->dbfd
);
11432 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
11435 /* Wrapper for free_dwo_file for use in cleanups. */
11438 free_dwo_file_cleanup (void *arg
)
11440 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
11441 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11443 free_dwo_file (dwo_file
, objfile
);
11446 /* Traversal function for free_dwo_files. */
11449 free_dwo_file_from_slot (void **slot
, void *info
)
11451 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
11452 struct objfile
*objfile
= (struct objfile
*) info
;
11454 free_dwo_file (dwo_file
, objfile
);
11459 /* Free all resources associated with DWO_FILES. */
11462 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
11464 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
11467 /* Read in various DIEs. */
11469 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
11470 Inherit only the children of the DW_AT_abstract_origin DIE not being
11471 already referenced by DW_AT_abstract_origin from the children of the
11475 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
11477 struct die_info
*child_die
;
11478 sect_offset
*offsetp
;
11479 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
11480 struct die_info
*origin_die
;
11481 /* Iterator of the ORIGIN_DIE children. */
11482 struct die_info
*origin_child_die
;
11483 struct attribute
*attr
;
11484 struct dwarf2_cu
*origin_cu
;
11485 struct pending
**origin_previous_list_in_scope
;
11487 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11491 /* Note that following die references may follow to a die in a
11495 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
11497 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
11499 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
11500 origin_cu
->list_in_scope
= cu
->list_in_scope
;
11502 if (die
->tag
!= origin_die
->tag
11503 && !(die
->tag
== DW_TAG_inlined_subroutine
11504 && origin_die
->tag
== DW_TAG_subprogram
))
11505 complaint (&symfile_complaints
,
11506 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
11507 to_underlying (die
->sect_off
),
11508 to_underlying (origin_die
->sect_off
));
11510 std::vector
<sect_offset
> offsets
;
11512 for (child_die
= die
->child
;
11513 child_die
&& child_die
->tag
;
11514 child_die
= sibling_die (child_die
))
11516 struct die_info
*child_origin_die
;
11517 struct dwarf2_cu
*child_origin_cu
;
11519 /* We are trying to process concrete instance entries:
11520 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
11521 it's not relevant to our analysis here. i.e. detecting DIEs that are
11522 present in the abstract instance but not referenced in the concrete
11524 if (child_die
->tag
== DW_TAG_call_site
11525 || child_die
->tag
== DW_TAG_GNU_call_site
)
11528 /* For each CHILD_DIE, find the corresponding child of
11529 ORIGIN_DIE. If there is more than one layer of
11530 DW_AT_abstract_origin, follow them all; there shouldn't be,
11531 but GCC versions at least through 4.4 generate this (GCC PR
11533 child_origin_die
= child_die
;
11534 child_origin_cu
= cu
;
11537 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
11541 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
11545 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
11546 counterpart may exist. */
11547 if (child_origin_die
!= child_die
)
11549 if (child_die
->tag
!= child_origin_die
->tag
11550 && !(child_die
->tag
== DW_TAG_inlined_subroutine
11551 && child_origin_die
->tag
== DW_TAG_subprogram
))
11552 complaint (&symfile_complaints
,
11553 _("Child DIE 0x%x and its abstract origin 0x%x have "
11555 to_underlying (child_die
->sect_off
),
11556 to_underlying (child_origin_die
->sect_off
));
11557 if (child_origin_die
->parent
!= origin_die
)
11558 complaint (&symfile_complaints
,
11559 _("Child DIE 0x%x and its abstract origin 0x%x have "
11560 "different parents"),
11561 to_underlying (child_die
->sect_off
),
11562 to_underlying (child_origin_die
->sect_off
));
11564 offsets
.push_back (child_origin_die
->sect_off
);
11567 std::sort (offsets
.begin (), offsets
.end ());
11568 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
11569 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
11570 if (offsetp
[-1] == *offsetp
)
11571 complaint (&symfile_complaints
,
11572 _("Multiple children of DIE 0x%x refer "
11573 "to DIE 0x%x as their abstract origin"),
11574 to_underlying (die
->sect_off
), to_underlying (*offsetp
));
11576 offsetp
= offsets
.data ();
11577 origin_child_die
= origin_die
->child
;
11578 while (origin_child_die
&& origin_child_die
->tag
)
11580 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
11581 while (offsetp
< offsets_end
11582 && *offsetp
< origin_child_die
->sect_off
)
11584 if (offsetp
>= offsets_end
11585 || *offsetp
> origin_child_die
->sect_off
)
11587 /* Found that ORIGIN_CHILD_DIE is really not referenced.
11588 Check whether we're already processing ORIGIN_CHILD_DIE.
11589 This can happen with mutually referenced abstract_origins.
11591 if (!origin_child_die
->in_process
)
11592 process_die (origin_child_die
, origin_cu
);
11594 origin_child_die
= sibling_die (origin_child_die
);
11596 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
11600 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11602 struct objfile
*objfile
= cu
->objfile
;
11603 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11604 struct context_stack
*newobj
;
11607 struct die_info
*child_die
;
11608 struct attribute
*attr
, *call_line
, *call_file
;
11610 CORE_ADDR baseaddr
;
11611 struct block
*block
;
11612 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11613 VEC (symbolp
) *template_args
= NULL
;
11614 struct template_symbol
*templ_func
= NULL
;
11618 /* If we do not have call site information, we can't show the
11619 caller of this inlined function. That's too confusing, so
11620 only use the scope for local variables. */
11621 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
11622 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
11623 if (call_line
== NULL
|| call_file
== NULL
)
11625 read_lexical_block_scope (die
, cu
);
11630 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11632 name
= dwarf2_name (die
, cu
);
11634 /* Ignore functions with missing or empty names. These are actually
11635 illegal according to the DWARF standard. */
11638 complaint (&symfile_complaints
,
11639 _("missing name for subprogram DIE at %d"),
11640 to_underlying (die
->sect_off
));
11644 /* Ignore functions with missing or invalid low and high pc attributes. */
11645 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
11646 <= PC_BOUNDS_INVALID
)
11648 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
11649 if (!attr
|| !DW_UNSND (attr
))
11650 complaint (&symfile_complaints
,
11651 _("cannot get low and high bounds "
11652 "for subprogram DIE at %d"),
11653 to_underlying (die
->sect_off
));
11657 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11658 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11660 /* If we have any template arguments, then we must allocate a
11661 different sort of symbol. */
11662 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
11664 if (child_die
->tag
== DW_TAG_template_type_param
11665 || child_die
->tag
== DW_TAG_template_value_param
)
11667 templ_func
= allocate_template_symbol (objfile
);
11668 templ_func
->base
.is_cplus_template_function
= 1;
11673 newobj
= push_context (0, lowpc
);
11674 newobj
->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
11675 (struct symbol
*) templ_func
);
11677 /* If there is a location expression for DW_AT_frame_base, record
11679 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
11681 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
11683 /* If there is a location for the static link, record it. */
11684 newobj
->static_link
= NULL
;
11685 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
11688 newobj
->static_link
11689 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
11690 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
11693 cu
->list_in_scope
= &local_symbols
;
11695 if (die
->child
!= NULL
)
11697 child_die
= die
->child
;
11698 while (child_die
&& child_die
->tag
)
11700 if (child_die
->tag
== DW_TAG_template_type_param
11701 || child_die
->tag
== DW_TAG_template_value_param
)
11703 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
11706 VEC_safe_push (symbolp
, template_args
, arg
);
11709 process_die (child_die
, cu
);
11710 child_die
= sibling_die (child_die
);
11714 inherit_abstract_dies (die
, cu
);
11716 /* If we have a DW_AT_specification, we might need to import using
11717 directives from the context of the specification DIE. See the
11718 comment in determine_prefix. */
11719 if (cu
->language
== language_cplus
11720 && dwarf2_attr (die
, DW_AT_specification
, cu
))
11722 struct dwarf2_cu
*spec_cu
= cu
;
11723 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
11727 child_die
= spec_die
->child
;
11728 while (child_die
&& child_die
->tag
)
11730 if (child_die
->tag
== DW_TAG_imported_module
)
11731 process_die (child_die
, spec_cu
);
11732 child_die
= sibling_die (child_die
);
11735 /* In some cases, GCC generates specification DIEs that
11736 themselves contain DW_AT_specification attributes. */
11737 spec_die
= die_specification (spec_die
, &spec_cu
);
11741 newobj
= pop_context ();
11742 /* Make a block for the local symbols within. */
11743 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
11744 newobj
->static_link
, lowpc
, highpc
);
11746 /* For C++, set the block's scope. */
11747 if ((cu
->language
== language_cplus
11748 || cu
->language
== language_fortran
11749 || cu
->language
== language_d
11750 || cu
->language
== language_rust
)
11751 && cu
->processing_has_namespace_info
)
11752 block_set_scope (block
, determine_prefix (die
, cu
),
11753 &objfile
->objfile_obstack
);
11755 /* If we have address ranges, record them. */
11756 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11758 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
11760 /* Attach template arguments to function. */
11761 if (! VEC_empty (symbolp
, template_args
))
11763 gdb_assert (templ_func
!= NULL
);
11765 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
11766 templ_func
->template_arguments
11767 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
11768 templ_func
->n_template_arguments
);
11769 memcpy (templ_func
->template_arguments
,
11770 VEC_address (symbolp
, template_args
),
11771 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
11772 VEC_free (symbolp
, template_args
);
11775 /* In C++, we can have functions nested inside functions (e.g., when
11776 a function declares a class that has methods). This means that
11777 when we finish processing a function scope, we may need to go
11778 back to building a containing block's symbol lists. */
11779 local_symbols
= newobj
->locals
;
11780 local_using_directives
= newobj
->local_using_directives
;
11782 /* If we've finished processing a top-level function, subsequent
11783 symbols go in the file symbol list. */
11784 if (outermost_context_p ())
11785 cu
->list_in_scope
= &file_symbols
;
11788 /* Process all the DIES contained within a lexical block scope. Start
11789 a new scope, process the dies, and then close the scope. */
11792 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11794 struct objfile
*objfile
= cu
->objfile
;
11795 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11796 struct context_stack
*newobj
;
11797 CORE_ADDR lowpc
, highpc
;
11798 struct die_info
*child_die
;
11799 CORE_ADDR baseaddr
;
11801 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11803 /* Ignore blocks with missing or invalid low and high pc attributes. */
11804 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
11805 as multiple lexical blocks? Handling children in a sane way would
11806 be nasty. Might be easier to properly extend generic blocks to
11807 describe ranges. */
11808 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
11810 case PC_BOUNDS_NOT_PRESENT
:
11811 /* DW_TAG_lexical_block has no attributes, process its children as if
11812 there was no wrapping by that DW_TAG_lexical_block.
11813 GCC does no longer produces such DWARF since GCC r224161. */
11814 for (child_die
= die
->child
;
11815 child_die
!= NULL
&& child_die
->tag
;
11816 child_die
= sibling_die (child_die
))
11817 process_die (child_die
, cu
);
11819 case PC_BOUNDS_INVALID
:
11822 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11823 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11825 push_context (0, lowpc
);
11826 if (die
->child
!= NULL
)
11828 child_die
= die
->child
;
11829 while (child_die
&& child_die
->tag
)
11831 process_die (child_die
, cu
);
11832 child_die
= sibling_die (child_die
);
11835 inherit_abstract_dies (die
, cu
);
11836 newobj
= pop_context ();
11838 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
11840 struct block
*block
11841 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
11842 newobj
->start_addr
, highpc
);
11844 /* Note that recording ranges after traversing children, as we
11845 do here, means that recording a parent's ranges entails
11846 walking across all its children's ranges as they appear in
11847 the address map, which is quadratic behavior.
11849 It would be nicer to record the parent's ranges before
11850 traversing its children, simply overriding whatever you find
11851 there. But since we don't even decide whether to create a
11852 block until after we've traversed its children, that's hard
11854 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11856 local_symbols
= newobj
->locals
;
11857 local_using_directives
= newobj
->local_using_directives
;
11860 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
11863 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11865 struct objfile
*objfile
= cu
->objfile
;
11866 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11867 CORE_ADDR pc
, baseaddr
;
11868 struct attribute
*attr
;
11869 struct call_site
*call_site
, call_site_local
;
11872 struct die_info
*child_die
;
11874 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11876 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
11879 /* This was a pre-DWARF-5 GNU extension alias
11880 for DW_AT_call_return_pc. */
11881 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11885 complaint (&symfile_complaints
,
11886 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
11887 "DIE 0x%x [in module %s]"),
11888 to_underlying (die
->sect_off
), objfile_name (objfile
));
11891 pc
= attr_value_as_address (attr
) + baseaddr
;
11892 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
11894 if (cu
->call_site_htab
== NULL
)
11895 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
11896 NULL
, &objfile
->objfile_obstack
,
11897 hashtab_obstack_allocate
, NULL
);
11898 call_site_local
.pc
= pc
;
11899 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
11902 complaint (&symfile_complaints
,
11903 _("Duplicate PC %s for DW_TAG_call_site "
11904 "DIE 0x%x [in module %s]"),
11905 paddress (gdbarch
, pc
), to_underlying (die
->sect_off
),
11906 objfile_name (objfile
));
11910 /* Count parameters at the caller. */
11913 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11914 child_die
= sibling_die (child_die
))
11916 if (child_die
->tag
!= DW_TAG_call_site_parameter
11917 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11919 complaint (&symfile_complaints
,
11920 _("Tag %d is not DW_TAG_call_site_parameter in "
11921 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
11922 child_die
->tag
, to_underlying (child_die
->sect_off
),
11923 objfile_name (objfile
));
11931 = ((struct call_site
*)
11932 obstack_alloc (&objfile
->objfile_obstack
,
11933 sizeof (*call_site
)
11934 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
11936 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
11937 call_site
->pc
= pc
;
11939 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
11940 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
11942 struct die_info
*func_die
;
11944 /* Skip also over DW_TAG_inlined_subroutine. */
11945 for (func_die
= die
->parent
;
11946 func_die
&& func_die
->tag
!= DW_TAG_subprogram
11947 && func_die
->tag
!= DW_TAG_subroutine_type
;
11948 func_die
= func_die
->parent
);
11950 /* DW_AT_call_all_calls is a superset
11951 of DW_AT_call_all_tail_calls. */
11953 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
11954 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
11955 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
11956 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
11958 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
11959 not complete. But keep CALL_SITE for look ups via call_site_htab,
11960 both the initial caller containing the real return address PC and
11961 the final callee containing the current PC of a chain of tail
11962 calls do not need to have the tail call list complete. But any
11963 function candidate for a virtual tail call frame searched via
11964 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
11965 determined unambiguously. */
11969 struct type
*func_type
= NULL
;
11972 func_type
= get_die_type (func_die
, cu
);
11973 if (func_type
!= NULL
)
11975 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
11977 /* Enlist this call site to the function. */
11978 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
11979 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
11982 complaint (&symfile_complaints
,
11983 _("Cannot find function owning DW_TAG_call_site "
11984 "DIE 0x%x [in module %s]"),
11985 to_underlying (die
->sect_off
), objfile_name (objfile
));
11989 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
11991 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
11993 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
11996 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
11997 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11999 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
12000 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
12001 /* Keep NULL DWARF_BLOCK. */;
12002 else if (attr_form_is_block (attr
))
12004 struct dwarf2_locexpr_baton
*dlbaton
;
12006 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
12007 dlbaton
->data
= DW_BLOCK (attr
)->data
;
12008 dlbaton
->size
= DW_BLOCK (attr
)->size
;
12009 dlbaton
->per_cu
= cu
->per_cu
;
12011 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
12013 else if (attr_form_is_ref (attr
))
12015 struct dwarf2_cu
*target_cu
= cu
;
12016 struct die_info
*target_die
;
12018 target_die
= follow_die_ref (die
, attr
, &target_cu
);
12019 gdb_assert (target_cu
->objfile
== objfile
);
12020 if (die_is_declaration (target_die
, target_cu
))
12022 const char *target_physname
;
12024 /* Prefer the mangled name; otherwise compute the demangled one. */
12025 target_physname
= dw2_linkage_name (target_die
, target_cu
);
12026 if (target_physname
== NULL
)
12027 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
12028 if (target_physname
== NULL
)
12029 complaint (&symfile_complaints
,
12030 _("DW_AT_call_target target DIE has invalid "
12031 "physname, for referencing DIE 0x%x [in module %s]"),
12032 to_underlying (die
->sect_off
), objfile_name (objfile
));
12034 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
12040 /* DW_AT_entry_pc should be preferred. */
12041 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
12042 <= PC_BOUNDS_INVALID
)
12043 complaint (&symfile_complaints
,
12044 _("DW_AT_call_target target DIE has invalid "
12045 "low pc, for referencing DIE 0x%x [in module %s]"),
12046 to_underlying (die
->sect_off
), objfile_name (objfile
));
12049 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12050 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
12055 complaint (&symfile_complaints
,
12056 _("DW_TAG_call_site DW_AT_call_target is neither "
12057 "block nor reference, for DIE 0x%x [in module %s]"),
12058 to_underlying (die
->sect_off
), objfile_name (objfile
));
12060 call_site
->per_cu
= cu
->per_cu
;
12062 for (child_die
= die
->child
;
12063 child_die
&& child_die
->tag
;
12064 child_die
= sibling_die (child_die
))
12066 struct call_site_parameter
*parameter
;
12067 struct attribute
*loc
, *origin
;
12069 if (child_die
->tag
!= DW_TAG_call_site_parameter
12070 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
12072 /* Already printed the complaint above. */
12076 gdb_assert (call_site
->parameter_count
< nparams
);
12077 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
12079 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
12080 specifies DW_TAG_formal_parameter. Value of the data assumed for the
12081 register is contained in DW_AT_call_value. */
12083 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
12084 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
12085 if (origin
== NULL
)
12087 /* This was a pre-DWARF-5 GNU extension alias
12088 for DW_AT_call_parameter. */
12089 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
12091 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
12093 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
12095 sect_offset sect_off
12096 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
12097 if (!offset_in_cu_p (&cu
->header
, sect_off
))
12099 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
12100 binding can be done only inside one CU. Such referenced DIE
12101 therefore cannot be even moved to DW_TAG_partial_unit. */
12102 complaint (&symfile_complaints
,
12103 _("DW_AT_call_parameter offset is not in CU for "
12104 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12105 to_underlying (child_die
->sect_off
),
12106 objfile_name (objfile
));
12109 parameter
->u
.param_cu_off
12110 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
12112 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
12114 complaint (&symfile_complaints
,
12115 _("No DW_FORM_block* DW_AT_location for "
12116 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12117 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
12122 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
12123 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
12124 if (parameter
->u
.dwarf_reg
!= -1)
12125 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
12126 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
12127 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
12128 ¶meter
->u
.fb_offset
))
12129 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
12132 complaint (&symfile_complaints
,
12133 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
12134 "for DW_FORM_block* DW_AT_location is supported for "
12135 "DW_TAG_call_site child DIE 0x%x "
12137 to_underlying (child_die
->sect_off
),
12138 objfile_name (objfile
));
12143 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
12145 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
12146 if (!attr_form_is_block (attr
))
12148 complaint (&symfile_complaints
,
12149 _("No DW_FORM_block* DW_AT_call_value for "
12150 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12151 to_underlying (child_die
->sect_off
),
12152 objfile_name (objfile
));
12155 parameter
->value
= DW_BLOCK (attr
)->data
;
12156 parameter
->value_size
= DW_BLOCK (attr
)->size
;
12158 /* Parameters are not pre-cleared by memset above. */
12159 parameter
->data_value
= NULL
;
12160 parameter
->data_value_size
= 0;
12161 call_site
->parameter_count
++;
12163 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
12165 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
12168 if (!attr_form_is_block (attr
))
12169 complaint (&symfile_complaints
,
12170 _("No DW_FORM_block* DW_AT_call_data_value for "
12171 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12172 to_underlying (child_die
->sect_off
),
12173 objfile_name (objfile
));
12176 parameter
->data_value
= DW_BLOCK (attr
)->data
;
12177 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
12183 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
12184 reading .debug_rnglists.
12185 Callback's type should be:
12186 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
12187 Return true if the attributes are present and valid, otherwise,
12190 template <typename Callback
>
12192 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
12193 Callback
&&callback
)
12195 struct objfile
*objfile
= cu
->objfile
;
12196 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12197 struct comp_unit_head
*cu_header
= &cu
->header
;
12198 bfd
*obfd
= objfile
->obfd
;
12199 unsigned int addr_size
= cu_header
->addr_size
;
12200 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12201 /* Base address selection entry. */
12204 unsigned int dummy
;
12205 const gdb_byte
*buffer
;
12207 CORE_ADDR high
= 0;
12208 CORE_ADDR baseaddr
;
12209 bool overflow
= false;
12211 found_base
= cu
->base_known
;
12212 base
= cu
->base_address
;
12214 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
12215 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
12217 complaint (&symfile_complaints
,
12218 _("Offset %d out of bounds for DW_AT_ranges attribute"),
12222 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
12224 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12228 /* Initialize it due to a false compiler warning. */
12229 CORE_ADDR range_beginning
= 0, range_end
= 0;
12230 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
12231 + dwarf2_per_objfile
->rnglists
.size
);
12232 unsigned int bytes_read
;
12234 if (buffer
== buf_end
)
12239 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
12242 case DW_RLE_end_of_list
:
12244 case DW_RLE_base_address
:
12245 if (buffer
+ cu
->header
.addr_size
> buf_end
)
12250 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12252 buffer
+= bytes_read
;
12254 case DW_RLE_start_length
:
12255 if (buffer
+ cu
->header
.addr_size
> buf_end
)
12260 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12261 buffer
+= bytes_read
;
12262 range_end
= (range_beginning
12263 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
12264 buffer
+= bytes_read
;
12265 if (buffer
> buf_end
)
12271 case DW_RLE_offset_pair
:
12272 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12273 buffer
+= bytes_read
;
12274 if (buffer
> buf_end
)
12279 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12280 buffer
+= bytes_read
;
12281 if (buffer
> buf_end
)
12287 case DW_RLE_start_end
:
12288 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
12293 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12294 buffer
+= bytes_read
;
12295 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12296 buffer
+= bytes_read
;
12299 complaint (&symfile_complaints
,
12300 _("Invalid .debug_rnglists data (no base address)"));
12303 if (rlet
== DW_RLE_end_of_list
|| overflow
)
12305 if (rlet
== DW_RLE_base_address
)
12310 /* We have no valid base address for the ranges
12312 complaint (&symfile_complaints
,
12313 _("Invalid .debug_rnglists data (no base address)"));
12317 if (range_beginning
> range_end
)
12319 /* Inverted range entries are invalid. */
12320 complaint (&symfile_complaints
,
12321 _("Invalid .debug_rnglists data (inverted range)"));
12325 /* Empty range entries have no effect. */
12326 if (range_beginning
== range_end
)
12329 range_beginning
+= base
;
12332 /* A not-uncommon case of bad debug info.
12333 Don't pollute the addrmap with bad data. */
12334 if (range_beginning
+ baseaddr
== 0
12335 && !dwarf2_per_objfile
->has_section_at_zero
)
12337 complaint (&symfile_complaints
,
12338 _(".debug_rnglists entry has start address of zero"
12339 " [in module %s]"), objfile_name (objfile
));
12343 callback (range_beginning
, range_end
);
12348 complaint (&symfile_complaints
,
12349 _("Offset %d is not terminated "
12350 "for DW_AT_ranges attribute"),
12358 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
12359 Callback's type should be:
12360 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
12361 Return 1 if the attributes are present and valid, otherwise, return 0. */
12363 template <typename Callback
>
12365 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
12366 Callback
&&callback
)
12368 struct objfile
*objfile
= cu
->objfile
;
12369 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12370 struct comp_unit_head
*cu_header
= &cu
->header
;
12371 bfd
*obfd
= objfile
->obfd
;
12372 unsigned int addr_size
= cu_header
->addr_size
;
12373 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12374 /* Base address selection entry. */
12377 unsigned int dummy
;
12378 const gdb_byte
*buffer
;
12379 CORE_ADDR baseaddr
;
12381 if (cu_header
->version
>= 5)
12382 return dwarf2_rnglists_process (offset
, cu
, callback
);
12384 found_base
= cu
->base_known
;
12385 base
= cu
->base_address
;
12387 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
12388 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
12390 complaint (&symfile_complaints
,
12391 _("Offset %d out of bounds for DW_AT_ranges attribute"),
12395 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
12397 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12401 CORE_ADDR range_beginning
, range_end
;
12403 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
12404 buffer
+= addr_size
;
12405 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
12406 buffer
+= addr_size
;
12407 offset
+= 2 * addr_size
;
12409 /* An end of list marker is a pair of zero addresses. */
12410 if (range_beginning
== 0 && range_end
== 0)
12411 /* Found the end of list entry. */
12414 /* Each base address selection entry is a pair of 2 values.
12415 The first is the largest possible address, the second is
12416 the base address. Check for a base address here. */
12417 if ((range_beginning
& mask
) == mask
)
12419 /* If we found the largest possible address, then we already
12420 have the base address in range_end. */
12428 /* We have no valid base address for the ranges
12430 complaint (&symfile_complaints
,
12431 _("Invalid .debug_ranges data (no base address)"));
12435 if (range_beginning
> range_end
)
12437 /* Inverted range entries are invalid. */
12438 complaint (&symfile_complaints
,
12439 _("Invalid .debug_ranges data (inverted range)"));
12443 /* Empty range entries have no effect. */
12444 if (range_beginning
== range_end
)
12447 range_beginning
+= base
;
12450 /* A not-uncommon case of bad debug info.
12451 Don't pollute the addrmap with bad data. */
12452 if (range_beginning
+ baseaddr
== 0
12453 && !dwarf2_per_objfile
->has_section_at_zero
)
12455 complaint (&symfile_complaints
,
12456 _(".debug_ranges entry has start address of zero"
12457 " [in module %s]"), objfile_name (objfile
));
12461 callback (range_beginning
, range_end
);
12467 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
12468 Return 1 if the attributes are present and valid, otherwise, return 0.
12469 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
12472 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
12473 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
12474 struct partial_symtab
*ranges_pst
)
12476 struct objfile
*objfile
= cu
->objfile
;
12477 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12478 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
12479 SECT_OFF_TEXT (objfile
));
12482 CORE_ADDR high
= 0;
12485 retval
= dwarf2_ranges_process (offset
, cu
,
12486 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
12488 if (ranges_pst
!= NULL
)
12493 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
12494 range_beginning
+ baseaddr
);
12495 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
12496 range_end
+ baseaddr
);
12497 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
12501 /* FIXME: This is recording everything as a low-high
12502 segment of consecutive addresses. We should have a
12503 data structure for discontiguous block ranges
12507 low
= range_beginning
;
12513 if (range_beginning
< low
)
12514 low
= range_beginning
;
12515 if (range_end
> high
)
12523 /* If the first entry is an end-of-list marker, the range
12524 describes an empty scope, i.e. no instructions. */
12530 *high_return
= high
;
12534 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
12535 definition for the return value. *LOWPC and *HIGHPC are set iff
12536 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
12538 static enum pc_bounds_kind
12539 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
12540 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
12541 struct partial_symtab
*pst
)
12543 struct attribute
*attr
;
12544 struct attribute
*attr_high
;
12546 CORE_ADDR high
= 0;
12547 enum pc_bounds_kind ret
;
12549 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12552 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12555 low
= attr_value_as_address (attr
);
12556 high
= attr_value_as_address (attr_high
);
12557 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12561 /* Found high w/o low attribute. */
12562 return PC_BOUNDS_INVALID
;
12564 /* Found consecutive range of addresses. */
12565 ret
= PC_BOUNDS_HIGH_LOW
;
12569 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12572 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12573 We take advantage of the fact that DW_AT_ranges does not appear
12574 in DW_TAG_compile_unit of DWO files. */
12575 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12576 unsigned int ranges_offset
= (DW_UNSND (attr
)
12577 + (need_ranges_base
12581 /* Value of the DW_AT_ranges attribute is the offset in the
12582 .debug_ranges section. */
12583 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
12584 return PC_BOUNDS_INVALID
;
12585 /* Found discontinuous range of addresses. */
12586 ret
= PC_BOUNDS_RANGES
;
12589 return PC_BOUNDS_NOT_PRESENT
;
12592 /* read_partial_die has also the strict LOW < HIGH requirement. */
12594 return PC_BOUNDS_INVALID
;
12596 /* When using the GNU linker, .gnu.linkonce. sections are used to
12597 eliminate duplicate copies of functions and vtables and such.
12598 The linker will arbitrarily choose one and discard the others.
12599 The AT_*_pc values for such functions refer to local labels in
12600 these sections. If the section from that file was discarded, the
12601 labels are not in the output, so the relocs get a value of 0.
12602 If this is a discarded function, mark the pc bounds as invalid,
12603 so that GDB will ignore it. */
12604 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12605 return PC_BOUNDS_INVALID
;
12613 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
12614 its low and high PC addresses. Do nothing if these addresses could not
12615 be determined. Otherwise, set LOWPC to the low address if it is smaller,
12616 and HIGHPC to the high address if greater than HIGHPC. */
12619 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
12620 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12621 struct dwarf2_cu
*cu
)
12623 CORE_ADDR low
, high
;
12624 struct die_info
*child
= die
->child
;
12626 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
12628 *lowpc
= std::min (*lowpc
, low
);
12629 *highpc
= std::max (*highpc
, high
);
12632 /* If the language does not allow nested subprograms (either inside
12633 subprograms or lexical blocks), we're done. */
12634 if (cu
->language
!= language_ada
)
12637 /* Check all the children of the given DIE. If it contains nested
12638 subprograms, then check their pc bounds. Likewise, we need to
12639 check lexical blocks as well, as they may also contain subprogram
12641 while (child
&& child
->tag
)
12643 if (child
->tag
== DW_TAG_subprogram
12644 || child
->tag
== DW_TAG_lexical_block
)
12645 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
12646 child
= sibling_die (child
);
12650 /* Get the low and high pc's represented by the scope DIE, and store
12651 them in *LOWPC and *HIGHPC. If the correct values can't be
12652 determined, set *LOWPC to -1 and *HIGHPC to 0. */
12655 get_scope_pc_bounds (struct die_info
*die
,
12656 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12657 struct dwarf2_cu
*cu
)
12659 CORE_ADDR best_low
= (CORE_ADDR
) -1;
12660 CORE_ADDR best_high
= (CORE_ADDR
) 0;
12661 CORE_ADDR current_low
, current_high
;
12663 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
12664 >= PC_BOUNDS_RANGES
)
12666 best_low
= current_low
;
12667 best_high
= current_high
;
12671 struct die_info
*child
= die
->child
;
12673 while (child
&& child
->tag
)
12675 switch (child
->tag
) {
12676 case DW_TAG_subprogram
:
12677 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
12679 case DW_TAG_namespace
:
12680 case DW_TAG_module
:
12681 /* FIXME: carlton/2004-01-16: Should we do this for
12682 DW_TAG_class_type/DW_TAG_structure_type, too? I think
12683 that current GCC's always emit the DIEs corresponding
12684 to definitions of methods of classes as children of a
12685 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
12686 the DIEs giving the declarations, which could be
12687 anywhere). But I don't see any reason why the
12688 standards says that they have to be there. */
12689 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
12691 if (current_low
!= ((CORE_ADDR
) -1))
12693 best_low
= std::min (best_low
, current_low
);
12694 best_high
= std::max (best_high
, current_high
);
12702 child
= sibling_die (child
);
12707 *highpc
= best_high
;
12710 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
12714 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
12715 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
12717 struct objfile
*objfile
= cu
->objfile
;
12718 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12719 struct attribute
*attr
;
12720 struct attribute
*attr_high
;
12722 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12725 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12728 CORE_ADDR low
= attr_value_as_address (attr
);
12729 CORE_ADDR high
= attr_value_as_address (attr_high
);
12731 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12734 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
12735 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
12736 record_block_range (block
, low
, high
- 1);
12740 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12743 bfd
*obfd
= objfile
->obfd
;
12744 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12745 We take advantage of the fact that DW_AT_ranges does not appear
12746 in DW_TAG_compile_unit of DWO files. */
12747 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12749 /* The value of the DW_AT_ranges attribute is the offset of the
12750 address range list in the .debug_ranges section. */
12751 unsigned long offset
= (DW_UNSND (attr
)
12752 + (need_ranges_base
? cu
->ranges_base
: 0));
12753 const gdb_byte
*buffer
;
12755 /* For some target architectures, but not others, the
12756 read_address function sign-extends the addresses it returns.
12757 To recognize base address selection entries, we need a
12759 unsigned int addr_size
= cu
->header
.addr_size
;
12760 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12762 /* The base address, to which the next pair is relative. Note
12763 that this 'base' is a DWARF concept: most entries in a range
12764 list are relative, to reduce the number of relocs against the
12765 debugging information. This is separate from this function's
12766 'baseaddr' argument, which GDB uses to relocate debugging
12767 information from a shared library based on the address at
12768 which the library was loaded. */
12769 CORE_ADDR base
= cu
->base_address
;
12770 int base_known
= cu
->base_known
;
12772 dwarf2_ranges_process (offset
, cu
,
12773 [&] (CORE_ADDR start
, CORE_ADDR end
)
12777 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
12778 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
12779 record_block_range (block
, start
, end
- 1);
12784 /* Check whether the producer field indicates either of GCC < 4.6, or the
12785 Intel C/C++ compiler, and cache the result in CU. */
12788 check_producer (struct dwarf2_cu
*cu
)
12792 if (cu
->producer
== NULL
)
12794 /* For unknown compilers expect their behavior is DWARF version
12797 GCC started to support .debug_types sections by -gdwarf-4 since
12798 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
12799 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
12800 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
12801 interpreted incorrectly by GDB now - GCC PR debug/48229. */
12803 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
12805 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
12806 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
12808 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
12809 cu
->producer_is_icc_lt_14
= major
< 14;
12812 /* For other non-GCC compilers, expect their behavior is DWARF version
12816 cu
->checked_producer
= 1;
12819 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
12820 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
12821 during 4.6.0 experimental. */
12824 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
12826 if (!cu
->checked_producer
)
12827 check_producer (cu
);
12829 return cu
->producer_is_gxx_lt_4_6
;
12832 /* Return the default accessibility type if it is not overriden by
12833 DW_AT_accessibility. */
12835 static enum dwarf_access_attribute
12836 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
12838 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
12840 /* The default DWARF 2 accessibility for members is public, the default
12841 accessibility for inheritance is private. */
12843 if (die
->tag
!= DW_TAG_inheritance
)
12844 return DW_ACCESS_public
;
12846 return DW_ACCESS_private
;
12850 /* DWARF 3+ defines the default accessibility a different way. The same
12851 rules apply now for DW_TAG_inheritance as for the members and it only
12852 depends on the container kind. */
12854 if (die
->parent
->tag
== DW_TAG_class_type
)
12855 return DW_ACCESS_private
;
12857 return DW_ACCESS_public
;
12861 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
12862 offset. If the attribute was not found return 0, otherwise return
12863 1. If it was found but could not properly be handled, set *OFFSET
12867 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
12870 struct attribute
*attr
;
12872 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
12877 /* Note that we do not check for a section offset first here.
12878 This is because DW_AT_data_member_location is new in DWARF 4,
12879 so if we see it, we can assume that a constant form is really
12880 a constant and not a section offset. */
12881 if (attr_form_is_constant (attr
))
12882 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
12883 else if (attr_form_is_section_offset (attr
))
12884 dwarf2_complex_location_expr_complaint ();
12885 else if (attr_form_is_block (attr
))
12886 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
12888 dwarf2_complex_location_expr_complaint ();
12896 /* Add an aggregate field to the field list. */
12899 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
12900 struct dwarf2_cu
*cu
)
12902 struct objfile
*objfile
= cu
->objfile
;
12903 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12904 struct nextfield
*new_field
;
12905 struct attribute
*attr
;
12907 const char *fieldname
= "";
12909 /* Allocate a new field list entry and link it in. */
12910 new_field
= XNEW (struct nextfield
);
12911 make_cleanup (xfree
, new_field
);
12912 memset (new_field
, 0, sizeof (struct nextfield
));
12914 if (die
->tag
== DW_TAG_inheritance
)
12916 new_field
->next
= fip
->baseclasses
;
12917 fip
->baseclasses
= new_field
;
12921 new_field
->next
= fip
->fields
;
12922 fip
->fields
= new_field
;
12926 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
12928 new_field
->accessibility
= DW_UNSND (attr
);
12930 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
12931 if (new_field
->accessibility
!= DW_ACCESS_public
)
12932 fip
->non_public_fields
= 1;
12934 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
12936 new_field
->virtuality
= DW_UNSND (attr
);
12938 new_field
->virtuality
= DW_VIRTUALITY_none
;
12940 fp
= &new_field
->field
;
12942 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
12946 /* Data member other than a C++ static data member. */
12948 /* Get type of field. */
12949 fp
->type
= die_type (die
, cu
);
12951 SET_FIELD_BITPOS (*fp
, 0);
12953 /* Get bit size of field (zero if none). */
12954 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
12957 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
12961 FIELD_BITSIZE (*fp
) = 0;
12964 /* Get bit offset of field. */
12965 if (handle_data_member_location (die
, cu
, &offset
))
12966 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12967 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
12970 if (gdbarch_bits_big_endian (gdbarch
))
12972 /* For big endian bits, the DW_AT_bit_offset gives the
12973 additional bit offset from the MSB of the containing
12974 anonymous object to the MSB of the field. We don't
12975 have to do anything special since we don't need to
12976 know the size of the anonymous object. */
12977 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
12981 /* For little endian bits, compute the bit offset to the
12982 MSB of the anonymous object, subtract off the number of
12983 bits from the MSB of the field to the MSB of the
12984 object, and then subtract off the number of bits of
12985 the field itself. The result is the bit offset of
12986 the LSB of the field. */
12987 int anonymous_size
;
12988 int bit_offset
= DW_UNSND (attr
);
12990 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12993 /* The size of the anonymous object containing
12994 the bit field is explicit, so use the
12995 indicated size (in bytes). */
12996 anonymous_size
= DW_UNSND (attr
);
13000 /* The size of the anonymous object containing
13001 the bit field must be inferred from the type
13002 attribute of the data member containing the
13004 anonymous_size
= TYPE_LENGTH (fp
->type
);
13006 SET_FIELD_BITPOS (*fp
,
13007 (FIELD_BITPOS (*fp
)
13008 + anonymous_size
* bits_per_byte
13009 - bit_offset
- FIELD_BITSIZE (*fp
)));
13012 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
13014 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
13015 + dwarf2_get_attr_constant_value (attr
, 0)));
13017 /* Get name of field. */
13018 fieldname
= dwarf2_name (die
, cu
);
13019 if (fieldname
== NULL
)
13022 /* The name is already allocated along with this objfile, so we don't
13023 need to duplicate it for the type. */
13024 fp
->name
= fieldname
;
13026 /* Change accessibility for artificial fields (e.g. virtual table
13027 pointer or virtual base class pointer) to private. */
13028 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
13030 FIELD_ARTIFICIAL (*fp
) = 1;
13031 new_field
->accessibility
= DW_ACCESS_private
;
13032 fip
->non_public_fields
= 1;
13035 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
13037 /* C++ static member. */
13039 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
13040 is a declaration, but all versions of G++ as of this writing
13041 (so through at least 3.2.1) incorrectly generate
13042 DW_TAG_variable tags. */
13044 const char *physname
;
13046 /* Get name of field. */
13047 fieldname
= dwarf2_name (die
, cu
);
13048 if (fieldname
== NULL
)
13051 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13053 /* Only create a symbol if this is an external value.
13054 new_symbol checks this and puts the value in the global symbol
13055 table, which we want. If it is not external, new_symbol
13056 will try to put the value in cu->list_in_scope which is wrong. */
13057 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
13059 /* A static const member, not much different than an enum as far as
13060 we're concerned, except that we can support more types. */
13061 new_symbol (die
, NULL
, cu
);
13064 /* Get physical name. */
13065 physname
= dwarf2_physname (fieldname
, die
, cu
);
13067 /* The name is already allocated along with this objfile, so we don't
13068 need to duplicate it for the type. */
13069 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
13070 FIELD_TYPE (*fp
) = die_type (die
, cu
);
13071 FIELD_NAME (*fp
) = fieldname
;
13073 else if (die
->tag
== DW_TAG_inheritance
)
13077 /* C++ base class field. */
13078 if (handle_data_member_location (die
, cu
, &offset
))
13079 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
13080 FIELD_BITSIZE (*fp
) = 0;
13081 FIELD_TYPE (*fp
) = die_type (die
, cu
);
13082 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
13083 fip
->nbaseclasses
++;
13087 /* Add a typedef defined in the scope of the FIP's class. */
13090 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
13091 struct dwarf2_cu
*cu
)
13093 struct typedef_field_list
*new_field
;
13094 struct typedef_field
*fp
;
13096 /* Allocate a new field list entry and link it in. */
13097 new_field
= XCNEW (struct typedef_field_list
);
13098 make_cleanup (xfree
, new_field
);
13100 gdb_assert (die
->tag
== DW_TAG_typedef
);
13102 fp
= &new_field
->field
;
13104 /* Get name of field. */
13105 fp
->name
= dwarf2_name (die
, cu
);
13106 if (fp
->name
== NULL
)
13109 fp
->type
= read_type_die (die
, cu
);
13111 /* Save accessibility. */
13112 enum dwarf_access_attribute accessibility
;
13113 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
13115 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
13117 accessibility
= dwarf2_default_access_attribute (die
, cu
);
13118 switch (accessibility
)
13120 case DW_ACCESS_public
:
13121 /* The assumed value if neither private nor protected. */
13123 case DW_ACCESS_private
:
13124 fp
->is_private
= 1;
13126 case DW_ACCESS_protected
:
13127 fp
->is_protected
= 1;
13130 complaint (&symfile_complaints
,
13131 _("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
13134 new_field
->next
= fip
->typedef_field_list
;
13135 fip
->typedef_field_list
= new_field
;
13136 fip
->typedef_field_list_count
++;
13139 /* Create the vector of fields, and attach it to the type. */
13142 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
13143 struct dwarf2_cu
*cu
)
13145 int nfields
= fip
->nfields
;
13147 /* Record the field count, allocate space for the array of fields,
13148 and create blank accessibility bitfields if necessary. */
13149 TYPE_NFIELDS (type
) = nfields
;
13150 TYPE_FIELDS (type
) = (struct field
*)
13151 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
13152 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
13154 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
13156 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13158 TYPE_FIELD_PRIVATE_BITS (type
) =
13159 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
13160 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
13162 TYPE_FIELD_PROTECTED_BITS (type
) =
13163 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
13164 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
13166 TYPE_FIELD_IGNORE_BITS (type
) =
13167 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
13168 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
13171 /* If the type has baseclasses, allocate and clear a bit vector for
13172 TYPE_FIELD_VIRTUAL_BITS. */
13173 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
13175 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
13176 unsigned char *pointer
;
13178 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13179 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
13180 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
13181 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
13182 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
13185 /* Copy the saved-up fields into the field vector. Start from the head of
13186 the list, adding to the tail of the field array, so that they end up in
13187 the same order in the array in which they were added to the list. */
13188 while (nfields
-- > 0)
13190 struct nextfield
*fieldp
;
13194 fieldp
= fip
->fields
;
13195 fip
->fields
= fieldp
->next
;
13199 fieldp
= fip
->baseclasses
;
13200 fip
->baseclasses
= fieldp
->next
;
13203 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
13204 switch (fieldp
->accessibility
)
13206 case DW_ACCESS_private
:
13207 if (cu
->language
!= language_ada
)
13208 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
13211 case DW_ACCESS_protected
:
13212 if (cu
->language
!= language_ada
)
13213 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
13216 case DW_ACCESS_public
:
13220 /* Unknown accessibility. Complain and treat it as public. */
13222 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
13223 fieldp
->accessibility
);
13227 if (nfields
< fip
->nbaseclasses
)
13229 switch (fieldp
->virtuality
)
13231 case DW_VIRTUALITY_virtual
:
13232 case DW_VIRTUALITY_pure_virtual
:
13233 if (cu
->language
== language_ada
)
13234 error (_("unexpected virtuality in component of Ada type"));
13235 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
13242 /* Return true if this member function is a constructor, false
13246 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
13248 const char *fieldname
;
13249 const char *type_name
;
13252 if (die
->parent
== NULL
)
13255 if (die
->parent
->tag
!= DW_TAG_structure_type
13256 && die
->parent
->tag
!= DW_TAG_union_type
13257 && die
->parent
->tag
!= DW_TAG_class_type
)
13260 fieldname
= dwarf2_name (die
, cu
);
13261 type_name
= dwarf2_name (die
->parent
, cu
);
13262 if (fieldname
== NULL
|| type_name
== NULL
)
13265 len
= strlen (fieldname
);
13266 return (strncmp (fieldname
, type_name
, len
) == 0
13267 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
13270 /* Add a member function to the proper fieldlist. */
13273 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
13274 struct type
*type
, struct dwarf2_cu
*cu
)
13276 struct objfile
*objfile
= cu
->objfile
;
13277 struct attribute
*attr
;
13278 struct fnfieldlist
*flp
;
13280 struct fn_field
*fnp
;
13281 const char *fieldname
;
13282 struct nextfnfield
*new_fnfield
;
13283 struct type
*this_type
;
13284 enum dwarf_access_attribute accessibility
;
13286 if (cu
->language
== language_ada
)
13287 error (_("unexpected member function in Ada type"));
13289 /* Get name of member function. */
13290 fieldname
= dwarf2_name (die
, cu
);
13291 if (fieldname
== NULL
)
13294 /* Look up member function name in fieldlist. */
13295 for (i
= 0; i
< fip
->nfnfields
; i
++)
13297 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
13301 /* Create new list element if necessary. */
13302 if (i
< fip
->nfnfields
)
13303 flp
= &fip
->fnfieldlists
[i
];
13306 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
13308 fip
->fnfieldlists
= (struct fnfieldlist
*)
13309 xrealloc (fip
->fnfieldlists
,
13310 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
13311 * sizeof (struct fnfieldlist
));
13312 if (fip
->nfnfields
== 0)
13313 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
13315 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
13316 flp
->name
= fieldname
;
13319 i
= fip
->nfnfields
++;
13322 /* Create a new member function field and chain it to the field list
13324 new_fnfield
= XNEW (struct nextfnfield
);
13325 make_cleanup (xfree
, new_fnfield
);
13326 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
13327 new_fnfield
->next
= flp
->head
;
13328 flp
->head
= new_fnfield
;
13331 /* Fill in the member function field info. */
13332 fnp
= &new_fnfield
->fnfield
;
13334 /* Delay processing of the physname until later. */
13335 if (cu
->language
== language_cplus
)
13337 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
13342 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
13343 fnp
->physname
= physname
? physname
: "";
13346 fnp
->type
= alloc_type (objfile
);
13347 this_type
= read_type_die (die
, cu
);
13348 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
13350 int nparams
= TYPE_NFIELDS (this_type
);
13352 /* TYPE is the domain of this method, and THIS_TYPE is the type
13353 of the method itself (TYPE_CODE_METHOD). */
13354 smash_to_method_type (fnp
->type
, type
,
13355 TYPE_TARGET_TYPE (this_type
),
13356 TYPE_FIELDS (this_type
),
13357 TYPE_NFIELDS (this_type
),
13358 TYPE_VARARGS (this_type
));
13360 /* Handle static member functions.
13361 Dwarf2 has no clean way to discern C++ static and non-static
13362 member functions. G++ helps GDB by marking the first
13363 parameter for non-static member functions (which is the this
13364 pointer) as artificial. We obtain this information from
13365 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
13366 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
13367 fnp
->voffset
= VOFFSET_STATIC
;
13370 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
13371 dwarf2_full_name (fieldname
, die
, cu
));
13373 /* Get fcontext from DW_AT_containing_type if present. */
13374 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
13375 fnp
->fcontext
= die_containing_type (die
, cu
);
13377 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
13378 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
13380 /* Get accessibility. */
13381 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
13383 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
13385 accessibility
= dwarf2_default_access_attribute (die
, cu
);
13386 switch (accessibility
)
13388 case DW_ACCESS_private
:
13389 fnp
->is_private
= 1;
13391 case DW_ACCESS_protected
:
13392 fnp
->is_protected
= 1;
13396 /* Check for artificial methods. */
13397 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
13398 if (attr
&& DW_UNSND (attr
) != 0)
13399 fnp
->is_artificial
= 1;
13401 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
13403 /* Get index in virtual function table if it is a virtual member
13404 function. For older versions of GCC, this is an offset in the
13405 appropriate virtual table, as specified by DW_AT_containing_type.
13406 For everyone else, it is an expression to be evaluated relative
13407 to the object address. */
13409 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
13412 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
13414 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
13416 /* Old-style GCC. */
13417 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
13419 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
13420 || (DW_BLOCK (attr
)->size
> 1
13421 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
13422 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
13424 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
13425 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
13426 dwarf2_complex_location_expr_complaint ();
13428 fnp
->voffset
/= cu
->header
.addr_size
;
13432 dwarf2_complex_location_expr_complaint ();
13434 if (!fnp
->fcontext
)
13436 /* If there is no `this' field and no DW_AT_containing_type,
13437 we cannot actually find a base class context for the
13439 if (TYPE_NFIELDS (this_type
) == 0
13440 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
13442 complaint (&symfile_complaints
,
13443 _("cannot determine context for virtual member "
13444 "function \"%s\" (offset %d)"),
13445 fieldname
, to_underlying (die
->sect_off
));
13450 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
13454 else if (attr_form_is_section_offset (attr
))
13456 dwarf2_complex_location_expr_complaint ();
13460 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
13466 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
13467 if (attr
&& DW_UNSND (attr
))
13469 /* GCC does this, as of 2008-08-25; PR debug/37237. */
13470 complaint (&symfile_complaints
,
13471 _("Member function \"%s\" (offset %d) is virtual "
13472 "but the vtable offset is not specified"),
13473 fieldname
, to_underlying (die
->sect_off
));
13474 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13475 TYPE_CPLUS_DYNAMIC (type
) = 1;
13480 /* Create the vector of member function fields, and attach it to the type. */
13483 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
13484 struct dwarf2_cu
*cu
)
13486 struct fnfieldlist
*flp
;
13489 if (cu
->language
== language_ada
)
13490 error (_("unexpected member functions in Ada type"));
13492 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13493 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
13494 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
13496 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
13498 struct nextfnfield
*nfp
= flp
->head
;
13499 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
13502 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
13503 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
13504 fn_flp
->fn_fields
= (struct fn_field
*)
13505 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
13506 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
13507 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
13510 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
13513 /* Returns non-zero if NAME is the name of a vtable member in CU's
13514 language, zero otherwise. */
13516 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
13518 static const char vptr
[] = "_vptr";
13519 static const char vtable
[] = "vtable";
13521 /* Look for the C++ form of the vtable. */
13522 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
13528 /* GCC outputs unnamed structures that are really pointers to member
13529 functions, with the ABI-specified layout. If TYPE describes
13530 such a structure, smash it into a member function type.
13532 GCC shouldn't do this; it should just output pointer to member DIEs.
13533 This is GCC PR debug/28767. */
13536 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
13538 struct type
*pfn_type
, *self_type
, *new_type
;
13540 /* Check for a structure with no name and two children. */
13541 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
13544 /* Check for __pfn and __delta members. */
13545 if (TYPE_FIELD_NAME (type
, 0) == NULL
13546 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
13547 || TYPE_FIELD_NAME (type
, 1) == NULL
13548 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
13551 /* Find the type of the method. */
13552 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
13553 if (pfn_type
== NULL
13554 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
13555 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
13558 /* Look for the "this" argument. */
13559 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
13560 if (TYPE_NFIELDS (pfn_type
) == 0
13561 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
13562 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
13565 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
13566 new_type
= alloc_type (objfile
);
13567 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
13568 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
13569 TYPE_VARARGS (pfn_type
));
13570 smash_to_methodptr_type (type
, new_type
);
13574 /* Called when we find the DIE that starts a structure or union scope
13575 (definition) to create a type for the structure or union. Fill in
13576 the type's name and general properties; the members will not be
13577 processed until process_structure_scope. A symbol table entry for
13578 the type will also not be done until process_structure_scope (assuming
13579 the type has a name).
13581 NOTE: we need to call these functions regardless of whether or not the
13582 DIE has a DW_AT_name attribute, since it might be an anonymous
13583 structure or union. This gets the type entered into our set of
13584 user defined types. */
13586 static struct type
*
13587 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13589 struct objfile
*objfile
= cu
->objfile
;
13591 struct attribute
*attr
;
13594 /* If the definition of this type lives in .debug_types, read that type.
13595 Don't follow DW_AT_specification though, that will take us back up
13596 the chain and we want to go down. */
13597 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
13600 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13602 /* The type's CU may not be the same as CU.
13603 Ensure TYPE is recorded with CU in die_type_hash. */
13604 return set_die_type (die
, type
, cu
);
13607 type
= alloc_type (objfile
);
13608 INIT_CPLUS_SPECIFIC (type
);
13610 name
= dwarf2_name (die
, cu
);
13613 if (cu
->language
== language_cplus
13614 || cu
->language
== language_d
13615 || cu
->language
== language_rust
)
13617 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
13619 /* dwarf2_full_name might have already finished building the DIE's
13620 type. If so, there is no need to continue. */
13621 if (get_die_type (die
, cu
) != NULL
)
13622 return get_die_type (die
, cu
);
13624 TYPE_TAG_NAME (type
) = full_name
;
13625 if (die
->tag
== DW_TAG_structure_type
13626 || die
->tag
== DW_TAG_class_type
)
13627 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13631 /* The name is already allocated along with this objfile, so
13632 we don't need to duplicate it for the type. */
13633 TYPE_TAG_NAME (type
) = name
;
13634 if (die
->tag
== DW_TAG_class_type
)
13635 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13639 if (die
->tag
== DW_TAG_structure_type
)
13641 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13643 else if (die
->tag
== DW_TAG_union_type
)
13645 TYPE_CODE (type
) = TYPE_CODE_UNION
;
13649 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13652 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
13653 TYPE_DECLARED_CLASS (type
) = 1;
13655 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13658 if (attr_form_is_constant (attr
))
13659 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13662 /* For the moment, dynamic type sizes are not supported
13663 by GDB's struct type. The actual size is determined
13664 on-demand when resolving the type of a given object,
13665 so set the type's length to zero for now. Otherwise,
13666 we record an expression as the length, and that expression
13667 could lead to a very large value, which could eventually
13668 lead to us trying to allocate that much memory when creating
13669 a value of that type. */
13670 TYPE_LENGTH (type
) = 0;
13675 TYPE_LENGTH (type
) = 0;
13678 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
13680 /* ICC<14 does not output the required DW_AT_declaration on
13681 incomplete types, but gives them a size of zero. */
13682 TYPE_STUB (type
) = 1;
13685 TYPE_STUB_SUPPORTED (type
) = 1;
13687 if (die_is_declaration (die
, cu
))
13688 TYPE_STUB (type
) = 1;
13689 else if (attr
== NULL
&& die
->child
== NULL
13690 && producer_is_realview (cu
->producer
))
13691 /* RealView does not output the required DW_AT_declaration
13692 on incomplete types. */
13693 TYPE_STUB (type
) = 1;
13695 /* We need to add the type field to the die immediately so we don't
13696 infinitely recurse when dealing with pointers to the structure
13697 type within the structure itself. */
13698 set_die_type (die
, type
, cu
);
13700 /* set_die_type should be already done. */
13701 set_descriptive_type (type
, die
, cu
);
13706 /* Finish creating a structure or union type, including filling in
13707 its members and creating a symbol for it. */
13710 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13712 struct objfile
*objfile
= cu
->objfile
;
13713 struct die_info
*child_die
;
13716 type
= get_die_type (die
, cu
);
13718 type
= read_structure_type (die
, cu
);
13720 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
13722 struct field_info fi
;
13723 VEC (symbolp
) *template_args
= NULL
;
13724 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
13726 memset (&fi
, 0, sizeof (struct field_info
));
13728 child_die
= die
->child
;
13730 while (child_die
&& child_die
->tag
)
13732 if (child_die
->tag
== DW_TAG_member
13733 || child_die
->tag
== DW_TAG_variable
)
13735 /* NOTE: carlton/2002-11-05: A C++ static data member
13736 should be a DW_TAG_member that is a declaration, but
13737 all versions of G++ as of this writing (so through at
13738 least 3.2.1) incorrectly generate DW_TAG_variable
13739 tags for them instead. */
13740 dwarf2_add_field (&fi
, child_die
, cu
);
13742 else if (child_die
->tag
== DW_TAG_subprogram
)
13744 /* Rust doesn't have member functions in the C++ sense.
13745 However, it does emit ordinary functions as children
13746 of a struct DIE. */
13747 if (cu
->language
== language_rust
)
13748 read_func_scope (child_die
, cu
);
13751 /* C++ member function. */
13752 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
13755 else if (child_die
->tag
== DW_TAG_inheritance
)
13757 /* C++ base class field. */
13758 dwarf2_add_field (&fi
, child_die
, cu
);
13760 else if (child_die
->tag
== DW_TAG_typedef
)
13761 dwarf2_add_typedef (&fi
, child_die
, cu
);
13762 else if (child_die
->tag
== DW_TAG_template_type_param
13763 || child_die
->tag
== DW_TAG_template_value_param
)
13765 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13768 VEC_safe_push (symbolp
, template_args
, arg
);
13771 child_die
= sibling_die (child_die
);
13774 /* Attach template arguments to type. */
13775 if (! VEC_empty (symbolp
, template_args
))
13777 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13778 TYPE_N_TEMPLATE_ARGUMENTS (type
)
13779 = VEC_length (symbolp
, template_args
);
13780 TYPE_TEMPLATE_ARGUMENTS (type
)
13781 = XOBNEWVEC (&objfile
->objfile_obstack
,
13783 TYPE_N_TEMPLATE_ARGUMENTS (type
));
13784 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
13785 VEC_address (symbolp
, template_args
),
13786 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
13787 * sizeof (struct symbol
*)));
13788 VEC_free (symbolp
, template_args
);
13791 /* Attach fields and member functions to the type. */
13793 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
13796 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
13798 /* Get the type which refers to the base class (possibly this
13799 class itself) which contains the vtable pointer for the current
13800 class from the DW_AT_containing_type attribute. This use of
13801 DW_AT_containing_type is a GNU extension. */
13803 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
13805 struct type
*t
= die_containing_type (die
, cu
);
13807 set_type_vptr_basetype (type
, t
);
13812 /* Our own class provides vtbl ptr. */
13813 for (i
= TYPE_NFIELDS (t
) - 1;
13814 i
>= TYPE_N_BASECLASSES (t
);
13817 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
13819 if (is_vtable_name (fieldname
, cu
))
13821 set_type_vptr_fieldno (type
, i
);
13826 /* Complain if virtual function table field not found. */
13827 if (i
< TYPE_N_BASECLASSES (t
))
13828 complaint (&symfile_complaints
,
13829 _("virtual function table pointer "
13830 "not found when defining class '%s'"),
13831 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
13836 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
13839 else if (cu
->producer
13840 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
13842 /* The IBM XLC compiler does not provide direct indication
13843 of the containing type, but the vtable pointer is
13844 always named __vfp. */
13848 for (i
= TYPE_NFIELDS (type
) - 1;
13849 i
>= TYPE_N_BASECLASSES (type
);
13852 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
13854 set_type_vptr_fieldno (type
, i
);
13855 set_type_vptr_basetype (type
, type
);
13862 /* Copy fi.typedef_field_list linked list elements content into the
13863 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
13864 if (fi
.typedef_field_list
)
13866 int i
= fi
.typedef_field_list_count
;
13868 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13869 TYPE_TYPEDEF_FIELD_ARRAY (type
)
13870 = ((struct typedef_field
*)
13871 TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
));
13872 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
13874 /* Reverse the list order to keep the debug info elements order. */
13877 struct typedef_field
*dest
, *src
;
13879 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
13880 src
= &fi
.typedef_field_list
->field
;
13881 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
13886 do_cleanups (back_to
);
13889 quirk_gcc_member_function_pointer (type
, objfile
);
13891 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
13892 snapshots) has been known to create a die giving a declaration
13893 for a class that has, as a child, a die giving a definition for a
13894 nested class. So we have to process our children even if the
13895 current die is a declaration. Normally, of course, a declaration
13896 won't have any children at all. */
13898 child_die
= die
->child
;
13900 while (child_die
!= NULL
&& child_die
->tag
)
13902 if (child_die
->tag
== DW_TAG_member
13903 || child_die
->tag
== DW_TAG_variable
13904 || child_die
->tag
== DW_TAG_inheritance
13905 || child_die
->tag
== DW_TAG_template_value_param
13906 || child_die
->tag
== DW_TAG_template_type_param
)
13911 process_die (child_die
, cu
);
13913 child_die
= sibling_die (child_die
);
13916 /* Do not consider external references. According to the DWARF standard,
13917 these DIEs are identified by the fact that they have no byte_size
13918 attribute, and a declaration attribute. */
13919 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
13920 || !die_is_declaration (die
, cu
))
13921 new_symbol (die
, type
, cu
);
13924 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
13925 update TYPE using some information only available in DIE's children. */
13928 update_enumeration_type_from_children (struct die_info
*die
,
13930 struct dwarf2_cu
*cu
)
13932 struct die_info
*child_die
;
13933 int unsigned_enum
= 1;
13937 auto_obstack obstack
;
13939 for (child_die
= die
->child
;
13940 child_die
!= NULL
&& child_die
->tag
;
13941 child_die
= sibling_die (child_die
))
13943 struct attribute
*attr
;
13945 const gdb_byte
*bytes
;
13946 struct dwarf2_locexpr_baton
*baton
;
13949 if (child_die
->tag
!= DW_TAG_enumerator
)
13952 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
13956 name
= dwarf2_name (child_die
, cu
);
13958 name
= "<anonymous enumerator>";
13960 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
13961 &value
, &bytes
, &baton
);
13967 else if ((mask
& value
) != 0)
13972 /* If we already know that the enum type is neither unsigned, nor
13973 a flag type, no need to look at the rest of the enumerates. */
13974 if (!unsigned_enum
&& !flag_enum
)
13979 TYPE_UNSIGNED (type
) = 1;
13981 TYPE_FLAG_ENUM (type
) = 1;
13984 /* Given a DW_AT_enumeration_type die, set its type. We do not
13985 complete the type's fields yet, or create any symbols. */
13987 static struct type
*
13988 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13990 struct objfile
*objfile
= cu
->objfile
;
13992 struct attribute
*attr
;
13995 /* If the definition of this type lives in .debug_types, read that type.
13996 Don't follow DW_AT_specification though, that will take us back up
13997 the chain and we want to go down. */
13998 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
14001 type
= get_DW_AT_signature_type (die
, attr
, cu
);
14003 /* The type's CU may not be the same as CU.
14004 Ensure TYPE is recorded with CU in die_type_hash. */
14005 return set_die_type (die
, type
, cu
);
14008 type
= alloc_type (objfile
);
14010 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
14011 name
= dwarf2_full_name (NULL
, die
, cu
);
14013 TYPE_TAG_NAME (type
) = name
;
14015 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14018 struct type
*underlying_type
= die_type (die
, cu
);
14020 TYPE_TARGET_TYPE (type
) = underlying_type
;
14023 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14026 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14030 TYPE_LENGTH (type
) = 0;
14033 /* The enumeration DIE can be incomplete. In Ada, any type can be
14034 declared as private in the package spec, and then defined only
14035 inside the package body. Such types are known as Taft Amendment
14036 Types. When another package uses such a type, an incomplete DIE
14037 may be generated by the compiler. */
14038 if (die_is_declaration (die
, cu
))
14039 TYPE_STUB (type
) = 1;
14041 /* Finish the creation of this type by using the enum's children.
14042 We must call this even when the underlying type has been provided
14043 so that we can determine if we're looking at a "flag" enum. */
14044 update_enumeration_type_from_children (die
, type
, cu
);
14046 /* If this type has an underlying type that is not a stub, then we
14047 may use its attributes. We always use the "unsigned" attribute
14048 in this situation, because ordinarily we guess whether the type
14049 is unsigned -- but the guess can be wrong and the underlying type
14050 can tell us the reality. However, we defer to a local size
14051 attribute if one exists, because this lets the compiler override
14052 the underlying type if needed. */
14053 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
14055 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
14056 if (TYPE_LENGTH (type
) == 0)
14057 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
14060 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
14062 return set_die_type (die
, type
, cu
);
14065 /* Given a pointer to a die which begins an enumeration, process all
14066 the dies that define the members of the enumeration, and create the
14067 symbol for the enumeration type.
14069 NOTE: We reverse the order of the element list. */
14072 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14074 struct type
*this_type
;
14076 this_type
= get_die_type (die
, cu
);
14077 if (this_type
== NULL
)
14078 this_type
= read_enumeration_type (die
, cu
);
14080 if (die
->child
!= NULL
)
14082 struct die_info
*child_die
;
14083 struct symbol
*sym
;
14084 struct field
*fields
= NULL
;
14085 int num_fields
= 0;
14088 child_die
= die
->child
;
14089 while (child_die
&& child_die
->tag
)
14091 if (child_die
->tag
!= DW_TAG_enumerator
)
14093 process_die (child_die
, cu
);
14097 name
= dwarf2_name (child_die
, cu
);
14100 sym
= new_symbol (child_die
, this_type
, cu
);
14102 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
14104 fields
= (struct field
*)
14106 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
14107 * sizeof (struct field
));
14110 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
14111 FIELD_TYPE (fields
[num_fields
]) = NULL
;
14112 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
14113 FIELD_BITSIZE (fields
[num_fields
]) = 0;
14119 child_die
= sibling_die (child_die
);
14124 TYPE_NFIELDS (this_type
) = num_fields
;
14125 TYPE_FIELDS (this_type
) = (struct field
*)
14126 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
14127 memcpy (TYPE_FIELDS (this_type
), fields
,
14128 sizeof (struct field
) * num_fields
);
14133 /* If we are reading an enum from a .debug_types unit, and the enum
14134 is a declaration, and the enum is not the signatured type in the
14135 unit, then we do not want to add a symbol for it. Adding a
14136 symbol would in some cases obscure the true definition of the
14137 enum, giving users an incomplete type when the definition is
14138 actually available. Note that we do not want to do this for all
14139 enums which are just declarations, because C++0x allows forward
14140 enum declarations. */
14141 if (cu
->per_cu
->is_debug_types
14142 && die_is_declaration (die
, cu
))
14144 struct signatured_type
*sig_type
;
14146 sig_type
= (struct signatured_type
*) cu
->per_cu
;
14147 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
14148 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
14152 new_symbol (die
, this_type
, cu
);
14155 /* Extract all information from a DW_TAG_array_type DIE and put it in
14156 the DIE's type field. For now, this only handles one dimensional
14159 static struct type
*
14160 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14162 struct objfile
*objfile
= cu
->objfile
;
14163 struct die_info
*child_die
;
14165 struct type
*element_type
, *range_type
, *index_type
;
14166 struct attribute
*attr
;
14168 unsigned int bit_stride
= 0;
14170 element_type
= die_type (die
, cu
);
14172 /* The die_type call above may have already set the type for this DIE. */
14173 type
= get_die_type (die
, cu
);
14177 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
14179 bit_stride
= DW_UNSND (attr
) * 8;
14181 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
14183 bit_stride
= DW_UNSND (attr
);
14185 /* Irix 6.2 native cc creates array types without children for
14186 arrays with unspecified length. */
14187 if (die
->child
== NULL
)
14189 index_type
= objfile_type (objfile
)->builtin_int
;
14190 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
14191 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
14193 return set_die_type (die
, type
, cu
);
14196 std::vector
<struct type
*> range_types
;
14197 child_die
= die
->child
;
14198 while (child_die
&& child_die
->tag
)
14200 if (child_die
->tag
== DW_TAG_subrange_type
)
14202 struct type
*child_type
= read_type_die (child_die
, cu
);
14204 if (child_type
!= NULL
)
14206 /* The range type was succesfully read. Save it for the
14207 array type creation. */
14208 range_types
.push_back (child_type
);
14211 child_die
= sibling_die (child_die
);
14214 /* Dwarf2 dimensions are output from left to right, create the
14215 necessary array types in backwards order. */
14217 type
= element_type
;
14219 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
14223 while (i
< range_types
.size ())
14224 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
14229 size_t ndim
= range_types
.size ();
14231 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
14235 /* Understand Dwarf2 support for vector types (like they occur on
14236 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
14237 array type. This is not part of the Dwarf2/3 standard yet, but a
14238 custom vendor extension. The main difference between a regular
14239 array and the vector variant is that vectors are passed by value
14241 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
14243 make_vector_type (type
);
14245 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
14246 implementation may choose to implement triple vectors using this
14248 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14251 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
14252 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14254 complaint (&symfile_complaints
,
14255 _("DW_AT_byte_size for array type smaller "
14256 "than the total size of elements"));
14259 name
= dwarf2_name (die
, cu
);
14261 TYPE_NAME (type
) = name
;
14263 /* Install the type in the die. */
14264 set_die_type (die
, type
, cu
);
14266 /* set_die_type should be already done. */
14267 set_descriptive_type (type
, die
, cu
);
14272 static enum dwarf_array_dim_ordering
14273 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
14275 struct attribute
*attr
;
14277 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
14280 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
14282 /* GNU F77 is a special case, as at 08/2004 array type info is the
14283 opposite order to the dwarf2 specification, but data is still
14284 laid out as per normal fortran.
14286 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
14287 version checking. */
14289 if (cu
->language
== language_fortran
14290 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
14292 return DW_ORD_row_major
;
14295 switch (cu
->language_defn
->la_array_ordering
)
14297 case array_column_major
:
14298 return DW_ORD_col_major
;
14299 case array_row_major
:
14301 return DW_ORD_row_major
;
14305 /* Extract all information from a DW_TAG_set_type DIE and put it in
14306 the DIE's type field. */
14308 static struct type
*
14309 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14311 struct type
*domain_type
, *set_type
;
14312 struct attribute
*attr
;
14314 domain_type
= die_type (die
, cu
);
14316 /* The die_type call above may have already set the type for this DIE. */
14317 set_type
= get_die_type (die
, cu
);
14321 set_type
= create_set_type (NULL
, domain_type
);
14323 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14325 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
14327 return set_die_type (die
, set_type
, cu
);
14330 /* A helper for read_common_block that creates a locexpr baton.
14331 SYM is the symbol which we are marking as computed.
14332 COMMON_DIE is the DIE for the common block.
14333 COMMON_LOC is the location expression attribute for the common
14335 MEMBER_LOC is the location expression attribute for the particular
14336 member of the common block that we are processing.
14337 CU is the CU from which the above come. */
14340 mark_common_block_symbol_computed (struct symbol
*sym
,
14341 struct die_info
*common_die
,
14342 struct attribute
*common_loc
,
14343 struct attribute
*member_loc
,
14344 struct dwarf2_cu
*cu
)
14346 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14347 struct dwarf2_locexpr_baton
*baton
;
14349 unsigned int cu_off
;
14350 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
14351 LONGEST offset
= 0;
14353 gdb_assert (common_loc
&& member_loc
);
14354 gdb_assert (attr_form_is_block (common_loc
));
14355 gdb_assert (attr_form_is_block (member_loc
)
14356 || attr_form_is_constant (member_loc
));
14358 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14359 baton
->per_cu
= cu
->per_cu
;
14360 gdb_assert (baton
->per_cu
);
14362 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
14364 if (attr_form_is_constant (member_loc
))
14366 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
14367 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
14370 baton
->size
+= DW_BLOCK (member_loc
)->size
;
14372 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
14375 *ptr
++ = DW_OP_call4
;
14376 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
14377 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
14380 if (attr_form_is_constant (member_loc
))
14382 *ptr
++ = DW_OP_addr
;
14383 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
14384 ptr
+= cu
->header
.addr_size
;
14388 /* We have to copy the data here, because DW_OP_call4 will only
14389 use a DW_AT_location attribute. */
14390 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
14391 ptr
+= DW_BLOCK (member_loc
)->size
;
14394 *ptr
++ = DW_OP_plus
;
14395 gdb_assert (ptr
- baton
->data
== baton
->size
);
14397 SYMBOL_LOCATION_BATON (sym
) = baton
;
14398 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
14401 /* Create appropriate locally-scoped variables for all the
14402 DW_TAG_common_block entries. Also create a struct common_block
14403 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
14404 is used to sepate the common blocks name namespace from regular
14408 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
14410 struct attribute
*attr
;
14412 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14415 /* Support the .debug_loc offsets. */
14416 if (attr_form_is_block (attr
))
14420 else if (attr_form_is_section_offset (attr
))
14422 dwarf2_complex_location_expr_complaint ();
14427 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
14428 "common block member");
14433 if (die
->child
!= NULL
)
14435 struct objfile
*objfile
= cu
->objfile
;
14436 struct die_info
*child_die
;
14437 size_t n_entries
= 0, size
;
14438 struct common_block
*common_block
;
14439 struct symbol
*sym
;
14441 for (child_die
= die
->child
;
14442 child_die
&& child_die
->tag
;
14443 child_die
= sibling_die (child_die
))
14446 size
= (sizeof (struct common_block
)
14447 + (n_entries
- 1) * sizeof (struct symbol
*));
14449 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
14451 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
14452 common_block
->n_entries
= 0;
14454 for (child_die
= die
->child
;
14455 child_die
&& child_die
->tag
;
14456 child_die
= sibling_die (child_die
))
14458 /* Create the symbol in the DW_TAG_common_block block in the current
14460 sym
= new_symbol (child_die
, NULL
, cu
);
14463 struct attribute
*member_loc
;
14465 common_block
->contents
[common_block
->n_entries
++] = sym
;
14467 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
14471 /* GDB has handled this for a long time, but it is
14472 not specified by DWARF. It seems to have been
14473 emitted by gfortran at least as recently as:
14474 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
14475 complaint (&symfile_complaints
,
14476 _("Variable in common block has "
14477 "DW_AT_data_member_location "
14478 "- DIE at 0x%x [in module %s]"),
14479 to_underlying (child_die
->sect_off
),
14480 objfile_name (cu
->objfile
));
14482 if (attr_form_is_section_offset (member_loc
))
14483 dwarf2_complex_location_expr_complaint ();
14484 else if (attr_form_is_constant (member_loc
)
14485 || attr_form_is_block (member_loc
))
14488 mark_common_block_symbol_computed (sym
, die
, attr
,
14492 dwarf2_complex_location_expr_complaint ();
14497 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
14498 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
14502 /* Create a type for a C++ namespace. */
14504 static struct type
*
14505 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14507 struct objfile
*objfile
= cu
->objfile
;
14508 const char *previous_prefix
, *name
;
14512 /* For extensions, reuse the type of the original namespace. */
14513 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
14515 struct die_info
*ext_die
;
14516 struct dwarf2_cu
*ext_cu
= cu
;
14518 ext_die
= dwarf2_extension (die
, &ext_cu
);
14519 type
= read_type_die (ext_die
, ext_cu
);
14521 /* EXT_CU may not be the same as CU.
14522 Ensure TYPE is recorded with CU in die_type_hash. */
14523 return set_die_type (die
, type
, cu
);
14526 name
= namespace_name (die
, &is_anonymous
, cu
);
14528 /* Now build the name of the current namespace. */
14530 previous_prefix
= determine_prefix (die
, cu
);
14531 if (previous_prefix
[0] != '\0')
14532 name
= typename_concat (&objfile
->objfile_obstack
,
14533 previous_prefix
, name
, 0, cu
);
14535 /* Create the type. */
14536 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
14537 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14539 return set_die_type (die
, type
, cu
);
14542 /* Read a namespace scope. */
14545 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
14547 struct objfile
*objfile
= cu
->objfile
;
14550 /* Add a symbol associated to this if we haven't seen the namespace
14551 before. Also, add a using directive if it's an anonymous
14554 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
14558 type
= read_type_die (die
, cu
);
14559 new_symbol (die
, type
, cu
);
14561 namespace_name (die
, &is_anonymous
, cu
);
14564 const char *previous_prefix
= determine_prefix (die
, cu
);
14566 std::vector
<const char *> excludes
;
14567 add_using_directive (using_directives (cu
->language
),
14568 previous_prefix
, TYPE_NAME (type
), NULL
,
14569 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
14573 if (die
->child
!= NULL
)
14575 struct die_info
*child_die
= die
->child
;
14577 while (child_die
&& child_die
->tag
)
14579 process_die (child_die
, cu
);
14580 child_die
= sibling_die (child_die
);
14585 /* Read a Fortran module as type. This DIE can be only a declaration used for
14586 imported module. Still we need that type as local Fortran "use ... only"
14587 declaration imports depend on the created type in determine_prefix. */
14589 static struct type
*
14590 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14592 struct objfile
*objfile
= cu
->objfile
;
14593 const char *module_name
;
14596 module_name
= dwarf2_name (die
, cu
);
14598 complaint (&symfile_complaints
,
14599 _("DW_TAG_module has no name, offset 0x%x"),
14600 to_underlying (die
->sect_off
));
14601 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
14603 /* determine_prefix uses TYPE_TAG_NAME. */
14604 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14606 return set_die_type (die
, type
, cu
);
14609 /* Read a Fortran module. */
14612 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
14614 struct die_info
*child_die
= die
->child
;
14617 type
= read_type_die (die
, cu
);
14618 new_symbol (die
, type
, cu
);
14620 while (child_die
&& child_die
->tag
)
14622 process_die (child_die
, cu
);
14623 child_die
= sibling_die (child_die
);
14627 /* Return the name of the namespace represented by DIE. Set
14628 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
14631 static const char *
14632 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
14634 struct die_info
*current_die
;
14635 const char *name
= NULL
;
14637 /* Loop through the extensions until we find a name. */
14639 for (current_die
= die
;
14640 current_die
!= NULL
;
14641 current_die
= dwarf2_extension (die
, &cu
))
14643 /* We don't use dwarf2_name here so that we can detect the absence
14644 of a name -> anonymous namespace. */
14645 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
14651 /* Is it an anonymous namespace? */
14653 *is_anonymous
= (name
== NULL
);
14655 name
= CP_ANONYMOUS_NAMESPACE_STR
;
14660 /* Extract all information from a DW_TAG_pointer_type DIE and add to
14661 the user defined type vector. */
14663 static struct type
*
14664 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14666 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
14667 struct comp_unit_head
*cu_header
= &cu
->header
;
14669 struct attribute
*attr_byte_size
;
14670 struct attribute
*attr_address_class
;
14671 int byte_size
, addr_class
;
14672 struct type
*target_type
;
14674 target_type
= die_type (die
, cu
);
14676 /* The die_type call above may have already set the type for this DIE. */
14677 type
= get_die_type (die
, cu
);
14681 type
= lookup_pointer_type (target_type
);
14683 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14684 if (attr_byte_size
)
14685 byte_size
= DW_UNSND (attr_byte_size
);
14687 byte_size
= cu_header
->addr_size
;
14689 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
14690 if (attr_address_class
)
14691 addr_class
= DW_UNSND (attr_address_class
);
14693 addr_class
= DW_ADDR_none
;
14695 /* If the pointer size or address class is different than the
14696 default, create a type variant marked as such and set the
14697 length accordingly. */
14698 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
14700 if (gdbarch_address_class_type_flags_p (gdbarch
))
14704 type_flags
= gdbarch_address_class_type_flags
14705 (gdbarch
, byte_size
, addr_class
);
14706 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
14708 type
= make_type_with_address_space (type
, type_flags
);
14710 else if (TYPE_LENGTH (type
) != byte_size
)
14712 complaint (&symfile_complaints
,
14713 _("invalid pointer size %d"), byte_size
);
14717 /* Should we also complain about unhandled address classes? */
14721 TYPE_LENGTH (type
) = byte_size
;
14722 return set_die_type (die
, type
, cu
);
14725 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
14726 the user defined type vector. */
14728 static struct type
*
14729 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14732 struct type
*to_type
;
14733 struct type
*domain
;
14735 to_type
= die_type (die
, cu
);
14736 domain
= die_containing_type (die
, cu
);
14738 /* The calls above may have already set the type for this DIE. */
14739 type
= get_die_type (die
, cu
);
14743 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
14744 type
= lookup_methodptr_type (to_type
);
14745 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
14747 struct type
*new_type
= alloc_type (cu
->objfile
);
14749 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
14750 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
14751 TYPE_VARARGS (to_type
));
14752 type
= lookup_methodptr_type (new_type
);
14755 type
= lookup_memberptr_type (to_type
, domain
);
14757 return set_die_type (die
, type
, cu
);
14760 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
14761 the user defined type vector. */
14763 static struct type
*
14764 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
14765 enum type_code refcode
)
14767 struct comp_unit_head
*cu_header
= &cu
->header
;
14768 struct type
*type
, *target_type
;
14769 struct attribute
*attr
;
14771 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
14773 target_type
= die_type (die
, cu
);
14775 /* The die_type call above may have already set the type for this DIE. */
14776 type
= get_die_type (die
, cu
);
14780 type
= lookup_reference_type (target_type
, refcode
);
14781 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14784 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14788 TYPE_LENGTH (type
) = cu_header
->addr_size
;
14790 return set_die_type (die
, type
, cu
);
14793 /* Add the given cv-qualifiers to the element type of the array. GCC
14794 outputs DWARF type qualifiers that apply to an array, not the
14795 element type. But GDB relies on the array element type to carry
14796 the cv-qualifiers. This mimics section 6.7.3 of the C99
14799 static struct type
*
14800 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
14801 struct type
*base_type
, int cnst
, int voltl
)
14803 struct type
*el_type
, *inner_array
;
14805 base_type
= copy_type (base_type
);
14806 inner_array
= base_type
;
14808 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
14810 TYPE_TARGET_TYPE (inner_array
) =
14811 copy_type (TYPE_TARGET_TYPE (inner_array
));
14812 inner_array
= TYPE_TARGET_TYPE (inner_array
);
14815 el_type
= TYPE_TARGET_TYPE (inner_array
);
14816 cnst
|= TYPE_CONST (el_type
);
14817 voltl
|= TYPE_VOLATILE (el_type
);
14818 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
14820 return set_die_type (die
, base_type
, cu
);
14823 static struct type
*
14824 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14826 struct type
*base_type
, *cv_type
;
14828 base_type
= die_type (die
, cu
);
14830 /* The die_type call above may have already set the type for this DIE. */
14831 cv_type
= get_die_type (die
, cu
);
14835 /* In case the const qualifier is applied to an array type, the element type
14836 is so qualified, not the array type (section 6.7.3 of C99). */
14837 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
14838 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
14840 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
14841 return set_die_type (die
, cv_type
, cu
);
14844 static struct type
*
14845 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14847 struct type
*base_type
, *cv_type
;
14849 base_type
= die_type (die
, cu
);
14851 /* The die_type call above may have already set the type for this DIE. */
14852 cv_type
= get_die_type (die
, cu
);
14856 /* In case the volatile qualifier is applied to an array type, the
14857 element type is so qualified, not the array type (section 6.7.3
14859 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
14860 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
14862 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
14863 return set_die_type (die
, cv_type
, cu
);
14866 /* Handle DW_TAG_restrict_type. */
14868 static struct type
*
14869 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14871 struct type
*base_type
, *cv_type
;
14873 base_type
= die_type (die
, cu
);
14875 /* The die_type call above may have already set the type for this DIE. */
14876 cv_type
= get_die_type (die
, cu
);
14880 cv_type
= make_restrict_type (base_type
);
14881 return set_die_type (die
, cv_type
, cu
);
14884 /* Handle DW_TAG_atomic_type. */
14886 static struct type
*
14887 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14889 struct type
*base_type
, *cv_type
;
14891 base_type
= die_type (die
, cu
);
14893 /* The die_type call above may have already set the type for this DIE. */
14894 cv_type
= get_die_type (die
, cu
);
14898 cv_type
= make_atomic_type (base_type
);
14899 return set_die_type (die
, cv_type
, cu
);
14902 /* Extract all information from a DW_TAG_string_type DIE and add to
14903 the user defined type vector. It isn't really a user defined type,
14904 but it behaves like one, with other DIE's using an AT_user_def_type
14905 attribute to reference it. */
14907 static struct type
*
14908 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14910 struct objfile
*objfile
= cu
->objfile
;
14911 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14912 struct type
*type
, *range_type
, *index_type
, *char_type
;
14913 struct attribute
*attr
;
14914 unsigned int length
;
14916 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
14919 length
= DW_UNSND (attr
);
14923 /* Check for the DW_AT_byte_size attribute. */
14924 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14927 length
= DW_UNSND (attr
);
14935 index_type
= objfile_type (objfile
)->builtin_int
;
14936 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
14937 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
14938 type
= create_string_type (NULL
, char_type
, range_type
);
14940 return set_die_type (die
, type
, cu
);
14943 /* Assuming that DIE corresponds to a function, returns nonzero
14944 if the function is prototyped. */
14947 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
14949 struct attribute
*attr
;
14951 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
14952 if (attr
&& (DW_UNSND (attr
) != 0))
14955 /* The DWARF standard implies that the DW_AT_prototyped attribute
14956 is only meaninful for C, but the concept also extends to other
14957 languages that allow unprototyped functions (Eg: Objective C).
14958 For all other languages, assume that functions are always
14960 if (cu
->language
!= language_c
14961 && cu
->language
!= language_objc
14962 && cu
->language
!= language_opencl
)
14965 /* RealView does not emit DW_AT_prototyped. We can not distinguish
14966 prototyped and unprototyped functions; default to prototyped,
14967 since that is more common in modern code (and RealView warns
14968 about unprototyped functions). */
14969 if (producer_is_realview (cu
->producer
))
14975 /* Handle DIES due to C code like:
14979 int (*funcp)(int a, long l);
14983 ('funcp' generates a DW_TAG_subroutine_type DIE). */
14985 static struct type
*
14986 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14988 struct objfile
*objfile
= cu
->objfile
;
14989 struct type
*type
; /* Type that this function returns. */
14990 struct type
*ftype
; /* Function that returns above type. */
14991 struct attribute
*attr
;
14993 type
= die_type (die
, cu
);
14995 /* The die_type call above may have already set the type for this DIE. */
14996 ftype
= get_die_type (die
, cu
);
15000 ftype
= lookup_function_type (type
);
15002 if (prototyped_function_p (die
, cu
))
15003 TYPE_PROTOTYPED (ftype
) = 1;
15005 /* Store the calling convention in the type if it's available in
15006 the subroutine die. Otherwise set the calling convention to
15007 the default value DW_CC_normal. */
15008 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15010 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
15011 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
15012 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
15014 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
15016 /* Record whether the function returns normally to its caller or not
15017 if the DWARF producer set that information. */
15018 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
15019 if (attr
&& (DW_UNSND (attr
) != 0))
15020 TYPE_NO_RETURN (ftype
) = 1;
15022 /* We need to add the subroutine type to the die immediately so
15023 we don't infinitely recurse when dealing with parameters
15024 declared as the same subroutine type. */
15025 set_die_type (die
, ftype
, cu
);
15027 if (die
->child
!= NULL
)
15029 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
15030 struct die_info
*child_die
;
15031 int nparams
, iparams
;
15033 /* Count the number of parameters.
15034 FIXME: GDB currently ignores vararg functions, but knows about
15035 vararg member functions. */
15037 child_die
= die
->child
;
15038 while (child_die
&& child_die
->tag
)
15040 if (child_die
->tag
== DW_TAG_formal_parameter
)
15042 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
15043 TYPE_VARARGS (ftype
) = 1;
15044 child_die
= sibling_die (child_die
);
15047 /* Allocate storage for parameters and fill them in. */
15048 TYPE_NFIELDS (ftype
) = nparams
;
15049 TYPE_FIELDS (ftype
) = (struct field
*)
15050 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
15052 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
15053 even if we error out during the parameters reading below. */
15054 for (iparams
= 0; iparams
< nparams
; iparams
++)
15055 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
15058 child_die
= die
->child
;
15059 while (child_die
&& child_die
->tag
)
15061 if (child_die
->tag
== DW_TAG_formal_parameter
)
15063 struct type
*arg_type
;
15065 /* DWARF version 2 has no clean way to discern C++
15066 static and non-static member functions. G++ helps
15067 GDB by marking the first parameter for non-static
15068 member functions (which is the this pointer) as
15069 artificial. We pass this information to
15070 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
15072 DWARF version 3 added DW_AT_object_pointer, which GCC
15073 4.5 does not yet generate. */
15074 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
15076 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
15078 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
15079 arg_type
= die_type (child_die
, cu
);
15081 /* RealView does not mark THIS as const, which the testsuite
15082 expects. GCC marks THIS as const in method definitions,
15083 but not in the class specifications (GCC PR 43053). */
15084 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
15085 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
15088 struct dwarf2_cu
*arg_cu
= cu
;
15089 const char *name
= dwarf2_name (child_die
, cu
);
15091 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
15094 /* If the compiler emits this, use it. */
15095 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
15098 else if (name
&& strcmp (name
, "this") == 0)
15099 /* Function definitions will have the argument names. */
15101 else if (name
== NULL
&& iparams
== 0)
15102 /* Declarations may not have the names, so like
15103 elsewhere in GDB, assume an artificial first
15104 argument is "this". */
15108 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
15112 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
15115 child_die
= sibling_die (child_die
);
15122 static struct type
*
15123 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
15125 struct objfile
*objfile
= cu
->objfile
;
15126 const char *name
= NULL
;
15127 struct type
*this_type
, *target_type
;
15129 name
= dwarf2_full_name (NULL
, die
, cu
);
15130 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
15131 TYPE_TARGET_STUB (this_type
) = 1;
15132 set_die_type (die
, this_type
, cu
);
15133 target_type
= die_type (die
, cu
);
15134 if (target_type
!= this_type
)
15135 TYPE_TARGET_TYPE (this_type
) = target_type
;
15138 /* Self-referential typedefs are, it seems, not allowed by the DWARF
15139 spec and cause infinite loops in GDB. */
15140 complaint (&symfile_complaints
,
15141 _("Self-referential DW_TAG_typedef "
15142 "- DIE at 0x%x [in module %s]"),
15143 to_underlying (die
->sect_off
), objfile_name (objfile
));
15144 TYPE_TARGET_TYPE (this_type
) = NULL
;
15149 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
15150 (which may be different from NAME) to the architecture back-end to allow
15151 it to guess the correct format if necessary. */
15153 static struct type
*
15154 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
15155 const char *name_hint
)
15157 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15158 const struct floatformat
**format
;
15161 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
15163 type
= init_float_type (objfile
, bits
, name
, format
);
15165 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
15170 /* Find a representation of a given base type and install
15171 it in the TYPE field of the die. */
15173 static struct type
*
15174 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15176 struct objfile
*objfile
= cu
->objfile
;
15178 struct attribute
*attr
;
15179 int encoding
= 0, bits
= 0;
15182 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
15185 encoding
= DW_UNSND (attr
);
15187 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15190 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
15192 name
= dwarf2_name (die
, cu
);
15195 complaint (&symfile_complaints
,
15196 _("DW_AT_name missing from DW_TAG_base_type"));
15201 case DW_ATE_address
:
15202 /* Turn DW_ATE_address into a void * pointer. */
15203 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
15204 type
= init_pointer_type (objfile
, bits
, name
, type
);
15206 case DW_ATE_boolean
:
15207 type
= init_boolean_type (objfile
, bits
, 1, name
);
15209 case DW_ATE_complex_float
:
15210 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
15211 type
= init_complex_type (objfile
, name
, type
);
15213 case DW_ATE_decimal_float
:
15214 type
= init_decfloat_type (objfile
, bits
, name
);
15217 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
15219 case DW_ATE_signed
:
15220 type
= init_integer_type (objfile
, bits
, 0, name
);
15222 case DW_ATE_unsigned
:
15223 if (cu
->language
== language_fortran
15225 && startswith (name
, "character("))
15226 type
= init_character_type (objfile
, bits
, 1, name
);
15228 type
= init_integer_type (objfile
, bits
, 1, name
);
15230 case DW_ATE_signed_char
:
15231 if (cu
->language
== language_ada
|| cu
->language
== language_m2
15232 || cu
->language
== language_pascal
15233 || cu
->language
== language_fortran
)
15234 type
= init_character_type (objfile
, bits
, 0, name
);
15236 type
= init_integer_type (objfile
, bits
, 0, name
);
15238 case DW_ATE_unsigned_char
:
15239 if (cu
->language
== language_ada
|| cu
->language
== language_m2
15240 || cu
->language
== language_pascal
15241 || cu
->language
== language_fortran
15242 || cu
->language
== language_rust
)
15243 type
= init_character_type (objfile
, bits
, 1, name
);
15245 type
= init_integer_type (objfile
, bits
, 1, name
);
15249 gdbarch
*arch
= get_objfile_arch (objfile
);
15252 type
= builtin_type (arch
)->builtin_char16
;
15253 else if (bits
== 32)
15254 type
= builtin_type (arch
)->builtin_char32
;
15257 complaint (&symfile_complaints
,
15258 _("unsupported DW_ATE_UTF bit size: '%d'"),
15260 type
= init_integer_type (objfile
, bits
, 1, name
);
15262 return set_die_type (die
, type
, cu
);
15267 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
15268 dwarf_type_encoding_name (encoding
));
15269 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
15273 if (name
&& strcmp (name
, "char") == 0)
15274 TYPE_NOSIGN (type
) = 1;
15276 return set_die_type (die
, type
, cu
);
15279 /* Parse dwarf attribute if it's a block, reference or constant and put the
15280 resulting value of the attribute into struct bound_prop.
15281 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
15284 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
15285 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
15287 struct dwarf2_property_baton
*baton
;
15288 struct obstack
*obstack
= &cu
->objfile
->objfile_obstack
;
15290 if (attr
== NULL
|| prop
== NULL
)
15293 if (attr_form_is_block (attr
))
15295 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15296 baton
->referenced_type
= NULL
;
15297 baton
->locexpr
.per_cu
= cu
->per_cu
;
15298 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
15299 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
15300 prop
->data
.baton
= baton
;
15301 prop
->kind
= PROP_LOCEXPR
;
15302 gdb_assert (prop
->data
.baton
!= NULL
);
15304 else if (attr_form_is_ref (attr
))
15306 struct dwarf2_cu
*target_cu
= cu
;
15307 struct die_info
*target_die
;
15308 struct attribute
*target_attr
;
15310 target_die
= follow_die_ref (die
, attr
, &target_cu
);
15311 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
15312 if (target_attr
== NULL
)
15313 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
15315 if (target_attr
== NULL
)
15318 switch (target_attr
->name
)
15320 case DW_AT_location
:
15321 if (attr_form_is_section_offset (target_attr
))
15323 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15324 baton
->referenced_type
= die_type (target_die
, target_cu
);
15325 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
15326 prop
->data
.baton
= baton
;
15327 prop
->kind
= PROP_LOCLIST
;
15328 gdb_assert (prop
->data
.baton
!= NULL
);
15330 else if (attr_form_is_block (target_attr
))
15332 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15333 baton
->referenced_type
= die_type (target_die
, target_cu
);
15334 baton
->locexpr
.per_cu
= cu
->per_cu
;
15335 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
15336 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
15337 prop
->data
.baton
= baton
;
15338 prop
->kind
= PROP_LOCEXPR
;
15339 gdb_assert (prop
->data
.baton
!= NULL
);
15343 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15344 "dynamic property");
15348 case DW_AT_data_member_location
:
15352 if (!handle_data_member_location (target_die
, target_cu
,
15356 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15357 baton
->referenced_type
= read_type_die (target_die
->parent
,
15359 baton
->offset_info
.offset
= offset
;
15360 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
15361 prop
->data
.baton
= baton
;
15362 prop
->kind
= PROP_ADDR_OFFSET
;
15367 else if (attr_form_is_constant (attr
))
15369 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
15370 prop
->kind
= PROP_CONST
;
15374 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
15375 dwarf2_name (die
, cu
));
15382 /* Read the given DW_AT_subrange DIE. */
15384 static struct type
*
15385 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15387 struct type
*base_type
, *orig_base_type
;
15388 struct type
*range_type
;
15389 struct attribute
*attr
;
15390 struct dynamic_prop low
, high
;
15391 int low_default_is_valid
;
15392 int high_bound_is_count
= 0;
15394 LONGEST negative_mask
;
15396 orig_base_type
= die_type (die
, cu
);
15397 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
15398 whereas the real type might be. So, we use ORIG_BASE_TYPE when
15399 creating the range type, but we use the result of check_typedef
15400 when examining properties of the type. */
15401 base_type
= check_typedef (orig_base_type
);
15403 /* The die_type call above may have already set the type for this DIE. */
15404 range_type
= get_die_type (die
, cu
);
15408 low
.kind
= PROP_CONST
;
15409 high
.kind
= PROP_CONST
;
15410 high
.data
.const_val
= 0;
15412 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
15413 omitting DW_AT_lower_bound. */
15414 switch (cu
->language
)
15417 case language_cplus
:
15418 low
.data
.const_val
= 0;
15419 low_default_is_valid
= 1;
15421 case language_fortran
:
15422 low
.data
.const_val
= 1;
15423 low_default_is_valid
= 1;
15426 case language_objc
:
15427 case language_rust
:
15428 low
.data
.const_val
= 0;
15429 low_default_is_valid
= (cu
->header
.version
>= 4);
15433 case language_pascal
:
15434 low
.data
.const_val
= 1;
15435 low_default_is_valid
= (cu
->header
.version
>= 4);
15438 low
.data
.const_val
= 0;
15439 low_default_is_valid
= 0;
15443 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
15445 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
15446 else if (!low_default_is_valid
)
15447 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
15448 "- DIE at 0x%x [in module %s]"),
15449 to_underlying (die
->sect_off
), objfile_name (cu
->objfile
));
15451 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
15452 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
15454 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
15455 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
15457 /* If bounds are constant do the final calculation here. */
15458 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
15459 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
15461 high_bound_is_count
= 1;
15465 /* Dwarf-2 specifications explicitly allows to create subrange types
15466 without specifying a base type.
15467 In that case, the base type must be set to the type of
15468 the lower bound, upper bound or count, in that order, if any of these
15469 three attributes references an object that has a type.
15470 If no base type is found, the Dwarf-2 specifications say that
15471 a signed integer type of size equal to the size of an address should
15473 For the following C code: `extern char gdb_int [];'
15474 GCC produces an empty range DIE.
15475 FIXME: muller/2010-05-28: Possible references to object for low bound,
15476 high bound or count are not yet handled by this code. */
15477 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
15479 struct objfile
*objfile
= cu
->objfile
;
15480 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15481 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
15482 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
15484 /* Test "int", "long int", and "long long int" objfile types,
15485 and select the first one having a size above or equal to the
15486 architecture address size. */
15487 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15488 base_type
= int_type
;
15491 int_type
= objfile_type (objfile
)->builtin_long
;
15492 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15493 base_type
= int_type
;
15496 int_type
= objfile_type (objfile
)->builtin_long_long
;
15497 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15498 base_type
= int_type
;
15503 /* Normally, the DWARF producers are expected to use a signed
15504 constant form (Eg. DW_FORM_sdata) to express negative bounds.
15505 But this is unfortunately not always the case, as witnessed
15506 with GCC, for instance, where the ambiguous DW_FORM_dataN form
15507 is used instead. To work around that ambiguity, we treat
15508 the bounds as signed, and thus sign-extend their values, when
15509 the base type is signed. */
15511 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
15512 if (low
.kind
== PROP_CONST
15513 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
15514 low
.data
.const_val
|= negative_mask
;
15515 if (high
.kind
== PROP_CONST
15516 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
15517 high
.data
.const_val
|= negative_mask
;
15519 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
15521 if (high_bound_is_count
)
15522 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
15524 /* Ada expects an empty array on no boundary attributes. */
15525 if (attr
== NULL
&& cu
->language
!= language_ada
)
15526 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
15528 name
= dwarf2_name (die
, cu
);
15530 TYPE_NAME (range_type
) = name
;
15532 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15534 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
15536 set_die_type (die
, range_type
, cu
);
15538 /* set_die_type should be already done. */
15539 set_descriptive_type (range_type
, die
, cu
);
15544 static struct type
*
15545 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15549 /* For now, we only support the C meaning of an unspecified type: void. */
15551 type
= init_type (cu
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
15552 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
15554 return set_die_type (die
, type
, cu
);
15557 /* Read a single die and all its descendents. Set the die's sibling
15558 field to NULL; set other fields in the die correctly, and set all
15559 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
15560 location of the info_ptr after reading all of those dies. PARENT
15561 is the parent of the die in question. */
15563 static struct die_info
*
15564 read_die_and_children (const struct die_reader_specs
*reader
,
15565 const gdb_byte
*info_ptr
,
15566 const gdb_byte
**new_info_ptr
,
15567 struct die_info
*parent
)
15569 struct die_info
*die
;
15570 const gdb_byte
*cur_ptr
;
15573 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
15576 *new_info_ptr
= cur_ptr
;
15579 store_in_ref_table (die
, reader
->cu
);
15582 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
15586 *new_info_ptr
= cur_ptr
;
15589 die
->sibling
= NULL
;
15590 die
->parent
= parent
;
15594 /* Read a die, all of its descendents, and all of its siblings; set
15595 all of the fields of all of the dies correctly. Arguments are as
15596 in read_die_and_children. */
15598 static struct die_info
*
15599 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
15600 const gdb_byte
*info_ptr
,
15601 const gdb_byte
**new_info_ptr
,
15602 struct die_info
*parent
)
15604 struct die_info
*first_die
, *last_sibling
;
15605 const gdb_byte
*cur_ptr
;
15607 cur_ptr
= info_ptr
;
15608 first_die
= last_sibling
= NULL
;
15612 struct die_info
*die
15613 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
15617 *new_info_ptr
= cur_ptr
;
15624 last_sibling
->sibling
= die
;
15626 last_sibling
= die
;
15630 /* Read a die, all of its descendents, and all of its siblings; set
15631 all of the fields of all of the dies correctly. Arguments are as
15632 in read_die_and_children.
15633 This the main entry point for reading a DIE and all its children. */
15635 static struct die_info
*
15636 read_die_and_siblings (const struct die_reader_specs
*reader
,
15637 const gdb_byte
*info_ptr
,
15638 const gdb_byte
**new_info_ptr
,
15639 struct die_info
*parent
)
15641 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
15642 new_info_ptr
, parent
);
15644 if (dwarf_die_debug
)
15646 fprintf_unfiltered (gdb_stdlog
,
15647 "Read die from %s@0x%x of %s:\n",
15648 get_section_name (reader
->die_section
),
15649 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15650 bfd_get_filename (reader
->abfd
));
15651 dump_die (die
, dwarf_die_debug
);
15657 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
15659 The caller is responsible for filling in the extra attributes
15660 and updating (*DIEP)->num_attrs.
15661 Set DIEP to point to a newly allocated die with its information,
15662 except for its child, sibling, and parent fields.
15663 Set HAS_CHILDREN to tell whether the die has children or not. */
15665 static const gdb_byte
*
15666 read_full_die_1 (const struct die_reader_specs
*reader
,
15667 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15668 int *has_children
, int num_extra_attrs
)
15670 unsigned int abbrev_number
, bytes_read
, i
;
15671 struct abbrev_info
*abbrev
;
15672 struct die_info
*die
;
15673 struct dwarf2_cu
*cu
= reader
->cu
;
15674 bfd
*abfd
= reader
->abfd
;
15676 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
15677 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15678 info_ptr
+= bytes_read
;
15679 if (!abbrev_number
)
15686 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
15688 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
15690 bfd_get_filename (abfd
));
15692 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
15693 die
->sect_off
= sect_off
;
15694 die
->tag
= abbrev
->tag
;
15695 die
->abbrev
= abbrev_number
;
15697 /* Make the result usable.
15698 The caller needs to update num_attrs after adding the extra
15700 die
->num_attrs
= abbrev
->num_attrs
;
15702 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
15703 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
15707 *has_children
= abbrev
->has_children
;
15711 /* Read a die and all its attributes.
15712 Set DIEP to point to a newly allocated die with its information,
15713 except for its child, sibling, and parent fields.
15714 Set HAS_CHILDREN to tell whether the die has children or not. */
15716 static const gdb_byte
*
15717 read_full_die (const struct die_reader_specs
*reader
,
15718 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15721 const gdb_byte
*result
;
15723 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
15725 if (dwarf_die_debug
)
15727 fprintf_unfiltered (gdb_stdlog
,
15728 "Read die from %s@0x%x of %s:\n",
15729 get_section_name (reader
->die_section
),
15730 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15731 bfd_get_filename (reader
->abfd
));
15732 dump_die (*diep
, dwarf_die_debug
);
15738 /* Abbreviation tables.
15740 In DWARF version 2, the description of the debugging information is
15741 stored in a separate .debug_abbrev section. Before we read any
15742 dies from a section we read in all abbreviations and install them
15743 in a hash table. */
15745 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
15747 static struct abbrev_info
*
15748 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
15750 struct abbrev_info
*abbrev
;
15752 abbrev
= XOBNEW (&abbrev_table
->abbrev_obstack
, struct abbrev_info
);
15753 memset (abbrev
, 0, sizeof (struct abbrev_info
));
15758 /* Add an abbreviation to the table. */
15761 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
15762 unsigned int abbrev_number
,
15763 struct abbrev_info
*abbrev
)
15765 unsigned int hash_number
;
15767 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
15768 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
15769 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
15772 /* Look up an abbrev in the table.
15773 Returns NULL if the abbrev is not found. */
15775 static struct abbrev_info
*
15776 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
15777 unsigned int abbrev_number
)
15779 unsigned int hash_number
;
15780 struct abbrev_info
*abbrev
;
15782 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
15783 abbrev
= abbrev_table
->abbrevs
[hash_number
];
15787 if (abbrev
->number
== abbrev_number
)
15789 abbrev
= abbrev
->next
;
15794 /* Read in an abbrev table. */
15796 static struct abbrev_table
*
15797 abbrev_table_read_table (struct dwarf2_section_info
*section
,
15798 sect_offset sect_off
)
15800 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15801 bfd
*abfd
= get_section_bfd_owner (section
);
15802 struct abbrev_table
*abbrev_table
;
15803 const gdb_byte
*abbrev_ptr
;
15804 struct abbrev_info
*cur_abbrev
;
15805 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
15806 unsigned int abbrev_form
;
15807 struct attr_abbrev
*cur_attrs
;
15808 unsigned int allocated_attrs
;
15810 abbrev_table
= XNEW (struct abbrev_table
);
15811 abbrev_table
->sect_off
= sect_off
;
15812 obstack_init (&abbrev_table
->abbrev_obstack
);
15813 abbrev_table
->abbrevs
=
15814 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct abbrev_info
*,
15816 memset (abbrev_table
->abbrevs
, 0,
15817 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
15819 dwarf2_read_section (objfile
, section
);
15820 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
15821 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15822 abbrev_ptr
+= bytes_read
;
15824 allocated_attrs
= ATTR_ALLOC_CHUNK
;
15825 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
15827 /* Loop until we reach an abbrev number of 0. */
15828 while (abbrev_number
)
15830 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
15832 /* read in abbrev header */
15833 cur_abbrev
->number
= abbrev_number
;
15835 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15836 abbrev_ptr
+= bytes_read
;
15837 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
15840 /* now read in declarations */
15843 LONGEST implicit_const
;
15845 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15846 abbrev_ptr
+= bytes_read
;
15847 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15848 abbrev_ptr
+= bytes_read
;
15849 if (abbrev_form
== DW_FORM_implicit_const
)
15851 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
15853 abbrev_ptr
+= bytes_read
;
15857 /* Initialize it due to a false compiler warning. */
15858 implicit_const
= -1;
15861 if (abbrev_name
== 0)
15864 if (cur_abbrev
->num_attrs
== allocated_attrs
)
15866 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
15868 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
15871 cur_attrs
[cur_abbrev
->num_attrs
].name
15872 = (enum dwarf_attribute
) abbrev_name
;
15873 cur_attrs
[cur_abbrev
->num_attrs
].form
15874 = (enum dwarf_form
) abbrev_form
;
15875 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
15876 ++cur_abbrev
->num_attrs
;
15879 cur_abbrev
->attrs
=
15880 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
15881 cur_abbrev
->num_attrs
);
15882 memcpy (cur_abbrev
->attrs
, cur_attrs
,
15883 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
15885 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
15887 /* Get next abbreviation.
15888 Under Irix6 the abbreviations for a compilation unit are not
15889 always properly terminated with an abbrev number of 0.
15890 Exit loop if we encounter an abbreviation which we have
15891 already read (which means we are about to read the abbreviations
15892 for the next compile unit) or if the end of the abbreviation
15893 table is reached. */
15894 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
15896 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15897 abbrev_ptr
+= bytes_read
;
15898 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
15903 return abbrev_table
;
15906 /* Free the resources held by ABBREV_TABLE. */
15909 abbrev_table_free (struct abbrev_table
*abbrev_table
)
15911 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
15912 xfree (abbrev_table
);
15915 /* Same as abbrev_table_free but as a cleanup.
15916 We pass in a pointer to the pointer to the table so that we can
15917 set the pointer to NULL when we're done. It also simplifies
15918 build_type_psymtabs_1. */
15921 abbrev_table_free_cleanup (void *table_ptr
)
15923 struct abbrev_table
**abbrev_table_ptr
= (struct abbrev_table
**) table_ptr
;
15925 if (*abbrev_table_ptr
!= NULL
)
15926 abbrev_table_free (*abbrev_table_ptr
);
15927 *abbrev_table_ptr
= NULL
;
15930 /* Read the abbrev table for CU from ABBREV_SECTION. */
15933 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
15934 struct dwarf2_section_info
*abbrev_section
)
15937 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_sect_off
);
15940 /* Release the memory used by the abbrev table for a compilation unit. */
15943 dwarf2_free_abbrev_table (void *ptr_to_cu
)
15945 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr_to_cu
;
15947 if (cu
->abbrev_table
!= NULL
)
15948 abbrev_table_free (cu
->abbrev_table
);
15949 /* Set this to NULL so that we SEGV if we try to read it later,
15950 and also because free_comp_unit verifies this is NULL. */
15951 cu
->abbrev_table
= NULL
;
15954 /* Returns nonzero if TAG represents a type that we might generate a partial
15958 is_type_tag_for_partial (int tag
)
15963 /* Some types that would be reasonable to generate partial symbols for,
15964 that we don't at present. */
15965 case DW_TAG_array_type
:
15966 case DW_TAG_file_type
:
15967 case DW_TAG_ptr_to_member_type
:
15968 case DW_TAG_set_type
:
15969 case DW_TAG_string_type
:
15970 case DW_TAG_subroutine_type
:
15972 case DW_TAG_base_type
:
15973 case DW_TAG_class_type
:
15974 case DW_TAG_interface_type
:
15975 case DW_TAG_enumeration_type
:
15976 case DW_TAG_structure_type
:
15977 case DW_TAG_subrange_type
:
15978 case DW_TAG_typedef
:
15979 case DW_TAG_union_type
:
15986 /* Load all DIEs that are interesting for partial symbols into memory. */
15988 static struct partial_die_info
*
15989 load_partial_dies (const struct die_reader_specs
*reader
,
15990 const gdb_byte
*info_ptr
, int building_psymtab
)
15992 struct dwarf2_cu
*cu
= reader
->cu
;
15993 struct objfile
*objfile
= cu
->objfile
;
15994 struct partial_die_info
*part_die
;
15995 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
15996 struct abbrev_info
*abbrev
;
15997 unsigned int bytes_read
;
15998 unsigned int load_all
= 0;
15999 int nesting_level
= 1;
16004 gdb_assert (cu
->per_cu
!= NULL
);
16005 if (cu
->per_cu
->load_all_dies
)
16009 = htab_create_alloc_ex (cu
->header
.length
/ 12,
16013 &cu
->comp_unit_obstack
,
16014 hashtab_obstack_allocate
,
16015 dummy_obstack_deallocate
);
16017 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
16021 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
16023 /* A NULL abbrev means the end of a series of children. */
16024 if (abbrev
== NULL
)
16026 if (--nesting_level
== 0)
16028 /* PART_DIE was probably the last thing allocated on the
16029 comp_unit_obstack, so we could call obstack_free
16030 here. We don't do that because the waste is small,
16031 and will be cleaned up when we're done with this
16032 compilation unit. This way, we're also more robust
16033 against other users of the comp_unit_obstack. */
16036 info_ptr
+= bytes_read
;
16037 last_die
= parent_die
;
16038 parent_die
= parent_die
->die_parent
;
16042 /* Check for template arguments. We never save these; if
16043 they're seen, we just mark the parent, and go on our way. */
16044 if (parent_die
!= NULL
16045 && cu
->language
== language_cplus
16046 && (abbrev
->tag
== DW_TAG_template_type_param
16047 || abbrev
->tag
== DW_TAG_template_value_param
))
16049 parent_die
->has_template_arguments
= 1;
16053 /* We don't need a partial DIE for the template argument. */
16054 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
16059 /* We only recurse into c++ subprograms looking for template arguments.
16060 Skip their other children. */
16062 && cu
->language
== language_cplus
16063 && parent_die
!= NULL
16064 && parent_die
->tag
== DW_TAG_subprogram
)
16066 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
16070 /* Check whether this DIE is interesting enough to save. Normally
16071 we would not be interested in members here, but there may be
16072 later variables referencing them via DW_AT_specification (for
16073 static members). */
16075 && !is_type_tag_for_partial (abbrev
->tag
)
16076 && abbrev
->tag
!= DW_TAG_constant
16077 && abbrev
->tag
!= DW_TAG_enumerator
16078 && abbrev
->tag
!= DW_TAG_subprogram
16079 && abbrev
->tag
!= DW_TAG_lexical_block
16080 && abbrev
->tag
!= DW_TAG_variable
16081 && abbrev
->tag
!= DW_TAG_namespace
16082 && abbrev
->tag
!= DW_TAG_module
16083 && abbrev
->tag
!= DW_TAG_member
16084 && abbrev
->tag
!= DW_TAG_imported_unit
16085 && abbrev
->tag
!= DW_TAG_imported_declaration
)
16087 /* Otherwise we skip to the next sibling, if any. */
16088 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
16092 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
16095 /* This two-pass algorithm for processing partial symbols has a
16096 high cost in cache pressure. Thus, handle some simple cases
16097 here which cover the majority of C partial symbols. DIEs
16098 which neither have specification tags in them, nor could have
16099 specification tags elsewhere pointing at them, can simply be
16100 processed and discarded.
16102 This segment is also optional; scan_partial_symbols and
16103 add_partial_symbol will handle these DIEs if we chain
16104 them in normally. When compilers which do not emit large
16105 quantities of duplicate debug information are more common,
16106 this code can probably be removed. */
16108 /* Any complete simple types at the top level (pretty much all
16109 of them, for a language without namespaces), can be processed
16111 if (parent_die
== NULL
16112 && part_die
->has_specification
== 0
16113 && part_die
->is_declaration
== 0
16114 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
16115 || part_die
->tag
== DW_TAG_base_type
16116 || part_die
->tag
== DW_TAG_subrange_type
))
16118 if (building_psymtab
&& part_die
->name
!= NULL
)
16119 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
16120 VAR_DOMAIN
, LOC_TYPEDEF
,
16121 &objfile
->static_psymbols
,
16122 0, cu
->language
, objfile
);
16123 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
16127 /* The exception for DW_TAG_typedef with has_children above is
16128 a workaround of GCC PR debug/47510. In the case of this complaint
16129 type_name_no_tag_or_error will error on such types later.
16131 GDB skipped children of DW_TAG_typedef by the shortcut above and then
16132 it could not find the child DIEs referenced later, this is checked
16133 above. In correct DWARF DW_TAG_typedef should have no children. */
16135 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
16136 complaint (&symfile_complaints
,
16137 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
16138 "- DIE at 0x%x [in module %s]"),
16139 to_underlying (part_die
->sect_off
), objfile_name (objfile
));
16141 /* If we're at the second level, and we're an enumerator, and
16142 our parent has no specification (meaning possibly lives in a
16143 namespace elsewhere), then we can add the partial symbol now
16144 instead of queueing it. */
16145 if (part_die
->tag
== DW_TAG_enumerator
16146 && parent_die
!= NULL
16147 && parent_die
->die_parent
== NULL
16148 && parent_die
->tag
== DW_TAG_enumeration_type
16149 && parent_die
->has_specification
== 0)
16151 if (part_die
->name
== NULL
)
16152 complaint (&symfile_complaints
,
16153 _("malformed enumerator DIE ignored"));
16154 else if (building_psymtab
)
16155 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
16156 VAR_DOMAIN
, LOC_CONST
,
16157 cu
->language
== language_cplus
16158 ? &objfile
->global_psymbols
16159 : &objfile
->static_psymbols
,
16160 0, cu
->language
, objfile
);
16162 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
16166 /* We'll save this DIE so link it in. */
16167 part_die
->die_parent
= parent_die
;
16168 part_die
->die_sibling
= NULL
;
16169 part_die
->die_child
= NULL
;
16171 if (last_die
&& last_die
== parent_die
)
16172 last_die
->die_child
= part_die
;
16174 last_die
->die_sibling
= part_die
;
16176 last_die
= part_die
;
16178 if (first_die
== NULL
)
16179 first_die
= part_die
;
16181 /* Maybe add the DIE to the hash table. Not all DIEs that we
16182 find interesting need to be in the hash table, because we
16183 also have the parent/sibling/child chains; only those that we
16184 might refer to by offset later during partial symbol reading.
16186 For now this means things that might have be the target of a
16187 DW_AT_specification, DW_AT_abstract_origin, or
16188 DW_AT_extension. DW_AT_extension will refer only to
16189 namespaces; DW_AT_abstract_origin refers to functions (and
16190 many things under the function DIE, but we do not recurse
16191 into function DIEs during partial symbol reading) and
16192 possibly variables as well; DW_AT_specification refers to
16193 declarations. Declarations ought to have the DW_AT_declaration
16194 flag. It happens that GCC forgets to put it in sometimes, but
16195 only for functions, not for types.
16197 Adding more things than necessary to the hash table is harmless
16198 except for the performance cost. Adding too few will result in
16199 wasted time in find_partial_die, when we reread the compilation
16200 unit with load_all_dies set. */
16203 || abbrev
->tag
== DW_TAG_constant
16204 || abbrev
->tag
== DW_TAG_subprogram
16205 || abbrev
->tag
== DW_TAG_variable
16206 || abbrev
->tag
== DW_TAG_namespace
16207 || part_die
->is_declaration
)
16211 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
16212 to_underlying (part_die
->sect_off
),
16217 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
16219 /* For some DIEs we want to follow their children (if any). For C
16220 we have no reason to follow the children of structures; for other
16221 languages we have to, so that we can get at method physnames
16222 to infer fully qualified class names, for DW_AT_specification,
16223 and for C++ template arguments. For C++, we also look one level
16224 inside functions to find template arguments (if the name of the
16225 function does not already contain the template arguments).
16227 For Ada, we need to scan the children of subprograms and lexical
16228 blocks as well because Ada allows the definition of nested
16229 entities that could be interesting for the debugger, such as
16230 nested subprograms for instance. */
16231 if (last_die
->has_children
16233 || last_die
->tag
== DW_TAG_namespace
16234 || last_die
->tag
== DW_TAG_module
16235 || last_die
->tag
== DW_TAG_enumeration_type
16236 || (cu
->language
== language_cplus
16237 && last_die
->tag
== DW_TAG_subprogram
16238 && (last_die
->name
== NULL
16239 || strchr (last_die
->name
, '<') == NULL
))
16240 || (cu
->language
!= language_c
16241 && (last_die
->tag
== DW_TAG_class_type
16242 || last_die
->tag
== DW_TAG_interface_type
16243 || last_die
->tag
== DW_TAG_structure_type
16244 || last_die
->tag
== DW_TAG_union_type
))
16245 || (cu
->language
== language_ada
16246 && (last_die
->tag
== DW_TAG_subprogram
16247 || last_die
->tag
== DW_TAG_lexical_block
))))
16250 parent_die
= last_die
;
16254 /* Otherwise we skip to the next sibling, if any. */
16255 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
16257 /* Back to the top, do it again. */
16261 /* Read a minimal amount of information into the minimal die structure. */
16263 static const gdb_byte
*
16264 read_partial_die (const struct die_reader_specs
*reader
,
16265 struct partial_die_info
*part_die
,
16266 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
16267 const gdb_byte
*info_ptr
)
16269 struct dwarf2_cu
*cu
= reader
->cu
;
16270 struct objfile
*objfile
= cu
->objfile
;
16271 const gdb_byte
*buffer
= reader
->buffer
;
16273 struct attribute attr
;
16274 int has_low_pc_attr
= 0;
16275 int has_high_pc_attr
= 0;
16276 int high_pc_relative
= 0;
16278 memset (part_die
, 0, sizeof (struct partial_die_info
));
16280 part_die
->sect_off
= (sect_offset
) (info_ptr
- buffer
);
16282 info_ptr
+= abbrev_len
;
16284 if (abbrev
== NULL
)
16287 part_die
->tag
= abbrev
->tag
;
16288 part_die
->has_children
= abbrev
->has_children
;
16290 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
16292 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
16294 /* Store the data if it is of an attribute we want to keep in a
16295 partial symbol table. */
16299 switch (part_die
->tag
)
16301 case DW_TAG_compile_unit
:
16302 case DW_TAG_partial_unit
:
16303 case DW_TAG_type_unit
:
16304 /* Compilation units have a DW_AT_name that is a filename, not
16305 a source language identifier. */
16306 case DW_TAG_enumeration_type
:
16307 case DW_TAG_enumerator
:
16308 /* These tags always have simple identifiers already; no need
16309 to canonicalize them. */
16310 part_die
->name
= DW_STRING (&attr
);
16314 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
16315 &objfile
->per_bfd
->storage_obstack
);
16319 case DW_AT_linkage_name
:
16320 case DW_AT_MIPS_linkage_name
:
16321 /* Note that both forms of linkage name might appear. We
16322 assume they will be the same, and we only store the last
16324 if (cu
->language
== language_ada
)
16325 part_die
->name
= DW_STRING (&attr
);
16326 part_die
->linkage_name
= DW_STRING (&attr
);
16329 has_low_pc_attr
= 1;
16330 part_die
->lowpc
= attr_value_as_address (&attr
);
16332 case DW_AT_high_pc
:
16333 has_high_pc_attr
= 1;
16334 part_die
->highpc
= attr_value_as_address (&attr
);
16335 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
16336 high_pc_relative
= 1;
16338 case DW_AT_location
:
16339 /* Support the .debug_loc offsets. */
16340 if (attr_form_is_block (&attr
))
16342 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
16344 else if (attr_form_is_section_offset (&attr
))
16346 dwarf2_complex_location_expr_complaint ();
16350 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16351 "partial symbol information");
16354 case DW_AT_external
:
16355 part_die
->is_external
= DW_UNSND (&attr
);
16357 case DW_AT_declaration
:
16358 part_die
->is_declaration
= DW_UNSND (&attr
);
16361 part_die
->has_type
= 1;
16363 case DW_AT_abstract_origin
:
16364 case DW_AT_specification
:
16365 case DW_AT_extension
:
16366 part_die
->has_specification
= 1;
16367 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
16368 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
16369 || cu
->per_cu
->is_dwz
);
16371 case DW_AT_sibling
:
16372 /* Ignore absolute siblings, they might point outside of
16373 the current compile unit. */
16374 if (attr
.form
== DW_FORM_ref_addr
)
16375 complaint (&symfile_complaints
,
16376 _("ignoring absolute DW_AT_sibling"));
16379 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
16380 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
16382 if (sibling_ptr
< info_ptr
)
16383 complaint (&symfile_complaints
,
16384 _("DW_AT_sibling points backwards"));
16385 else if (sibling_ptr
> reader
->buffer_end
)
16386 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
16388 part_die
->sibling
= sibling_ptr
;
16391 case DW_AT_byte_size
:
16392 part_die
->has_byte_size
= 1;
16394 case DW_AT_const_value
:
16395 part_die
->has_const_value
= 1;
16397 case DW_AT_calling_convention
:
16398 /* DWARF doesn't provide a way to identify a program's source-level
16399 entry point. DW_AT_calling_convention attributes are only meant
16400 to describe functions' calling conventions.
16402 However, because it's a necessary piece of information in
16403 Fortran, and before DWARF 4 DW_CC_program was the only
16404 piece of debugging information whose definition refers to
16405 a 'main program' at all, several compilers marked Fortran
16406 main programs with DW_CC_program --- even when those
16407 functions use the standard calling conventions.
16409 Although DWARF now specifies a way to provide this
16410 information, we support this practice for backward
16412 if (DW_UNSND (&attr
) == DW_CC_program
16413 && cu
->language
== language_fortran
)
16414 part_die
->main_subprogram
= 1;
16417 if (DW_UNSND (&attr
) == DW_INL_inlined
16418 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
16419 part_die
->may_be_inlined
= 1;
16423 if (part_die
->tag
== DW_TAG_imported_unit
)
16425 part_die
->d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
16426 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
16427 || cu
->per_cu
->is_dwz
);
16431 case DW_AT_main_subprogram
:
16432 part_die
->main_subprogram
= DW_UNSND (&attr
);
16440 if (high_pc_relative
)
16441 part_die
->highpc
+= part_die
->lowpc
;
16443 if (has_low_pc_attr
&& has_high_pc_attr
)
16445 /* When using the GNU linker, .gnu.linkonce. sections are used to
16446 eliminate duplicate copies of functions and vtables and such.
16447 The linker will arbitrarily choose one and discard the others.
16448 The AT_*_pc values for such functions refer to local labels in
16449 these sections. If the section from that file was discarded, the
16450 labels are not in the output, so the relocs get a value of 0.
16451 If this is a discarded function, mark the pc bounds as invalid,
16452 so that GDB will ignore it. */
16453 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
16455 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16457 complaint (&symfile_complaints
,
16458 _("DW_AT_low_pc %s is zero "
16459 "for DIE at 0x%x [in module %s]"),
16460 paddress (gdbarch
, part_die
->lowpc
),
16461 to_underlying (part_die
->sect_off
), objfile_name (objfile
));
16463 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
16464 else if (part_die
->lowpc
>= part_die
->highpc
)
16466 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16468 complaint (&symfile_complaints
,
16469 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
16470 "for DIE at 0x%x [in module %s]"),
16471 paddress (gdbarch
, part_die
->lowpc
),
16472 paddress (gdbarch
, part_die
->highpc
),
16473 to_underlying (part_die
->sect_off
),
16474 objfile_name (objfile
));
16477 part_die
->has_pc_info
= 1;
16483 /* Find a cached partial DIE at OFFSET in CU. */
16485 static struct partial_die_info
*
16486 find_partial_die_in_comp_unit (sect_offset sect_off
, struct dwarf2_cu
*cu
)
16488 struct partial_die_info
*lookup_die
= NULL
;
16489 struct partial_die_info part_die
;
16491 part_die
.sect_off
= sect_off
;
16492 lookup_die
= ((struct partial_die_info
*)
16493 htab_find_with_hash (cu
->partial_dies
, &part_die
,
16494 to_underlying (sect_off
)));
16499 /* Find a partial DIE at OFFSET, which may or may not be in CU,
16500 except in the case of .debug_types DIEs which do not reference
16501 outside their CU (they do however referencing other types via
16502 DW_FORM_ref_sig8). */
16504 static struct partial_die_info
*
16505 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
16507 struct objfile
*objfile
= cu
->objfile
;
16508 struct dwarf2_per_cu_data
*per_cu
= NULL
;
16509 struct partial_die_info
*pd
= NULL
;
16511 if (offset_in_dwz
== cu
->per_cu
->is_dwz
16512 && offset_in_cu_p (&cu
->header
, sect_off
))
16514 pd
= find_partial_die_in_comp_unit (sect_off
, cu
);
16517 /* We missed recording what we needed.
16518 Load all dies and try again. */
16519 per_cu
= cu
->per_cu
;
16523 /* TUs don't reference other CUs/TUs (except via type signatures). */
16524 if (cu
->per_cu
->is_debug_types
)
16526 error (_("Dwarf Error: Type Unit at offset 0x%x contains"
16527 " external reference to offset 0x%x [in module %s].\n"),
16528 to_underlying (cu
->header
.sect_off
), to_underlying (sect_off
),
16529 bfd_get_filename (objfile
->obfd
));
16531 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
16534 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
16535 load_partial_comp_unit (per_cu
);
16537 per_cu
->cu
->last_used
= 0;
16538 pd
= find_partial_die_in_comp_unit (sect_off
, per_cu
->cu
);
16541 /* If we didn't find it, and not all dies have been loaded,
16542 load them all and try again. */
16544 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
16546 per_cu
->load_all_dies
= 1;
16548 /* This is nasty. When we reread the DIEs, somewhere up the call chain
16549 THIS_CU->cu may already be in use. So we can't just free it and
16550 replace its DIEs with the ones we read in. Instead, we leave those
16551 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
16552 and clobber THIS_CU->cu->partial_dies with the hash table for the new
16554 load_partial_comp_unit (per_cu
);
16556 pd
= find_partial_die_in_comp_unit (sect_off
, per_cu
->cu
);
16560 internal_error (__FILE__
, __LINE__
,
16561 _("could not find partial DIE 0x%x "
16562 "in cache [from module %s]\n"),
16563 to_underlying (sect_off
), bfd_get_filename (objfile
->obfd
));
16567 /* See if we can figure out if the class lives in a namespace. We do
16568 this by looking for a member function; its demangled name will
16569 contain namespace info, if there is any. */
16572 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
16573 struct dwarf2_cu
*cu
)
16575 /* NOTE: carlton/2003-10-07: Getting the info this way changes
16576 what template types look like, because the demangler
16577 frequently doesn't give the same name as the debug info. We
16578 could fix this by only using the demangled name to get the
16579 prefix (but see comment in read_structure_type). */
16581 struct partial_die_info
*real_pdi
;
16582 struct partial_die_info
*child_pdi
;
16584 /* If this DIE (this DIE's specification, if any) has a parent, then
16585 we should not do this. We'll prepend the parent's fully qualified
16586 name when we create the partial symbol. */
16588 real_pdi
= struct_pdi
;
16589 while (real_pdi
->has_specification
)
16590 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
16591 real_pdi
->spec_is_dwz
, cu
);
16593 if (real_pdi
->die_parent
!= NULL
)
16596 for (child_pdi
= struct_pdi
->die_child
;
16598 child_pdi
= child_pdi
->die_sibling
)
16600 if (child_pdi
->tag
== DW_TAG_subprogram
16601 && child_pdi
->linkage_name
!= NULL
)
16603 char *actual_class_name
16604 = language_class_name_from_physname (cu
->language_defn
,
16605 child_pdi
->linkage_name
);
16606 if (actual_class_name
!= NULL
)
16610 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16612 strlen (actual_class_name
)));
16613 xfree (actual_class_name
);
16620 /* Adjust PART_DIE before generating a symbol for it. This function
16621 may set the is_external flag or change the DIE's name. */
16624 fixup_partial_die (struct partial_die_info
*part_die
,
16625 struct dwarf2_cu
*cu
)
16627 /* Once we've fixed up a die, there's no point in doing so again.
16628 This also avoids a memory leak if we were to call
16629 guess_partial_die_structure_name multiple times. */
16630 if (part_die
->fixup_called
)
16633 /* If we found a reference attribute and the DIE has no name, try
16634 to find a name in the referred to DIE. */
16636 if (part_die
->name
== NULL
&& part_die
->has_specification
)
16638 struct partial_die_info
*spec_die
;
16640 spec_die
= find_partial_die (part_die
->spec_offset
,
16641 part_die
->spec_is_dwz
, cu
);
16643 fixup_partial_die (spec_die
, cu
);
16645 if (spec_die
->name
)
16647 part_die
->name
= spec_die
->name
;
16649 /* Copy DW_AT_external attribute if it is set. */
16650 if (spec_die
->is_external
)
16651 part_die
->is_external
= spec_die
->is_external
;
16655 /* Set default names for some unnamed DIEs. */
16657 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
16658 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
16660 /* If there is no parent die to provide a namespace, and there are
16661 children, see if we can determine the namespace from their linkage
16663 if (cu
->language
== language_cplus
16664 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
16665 && part_die
->die_parent
== NULL
16666 && part_die
->has_children
16667 && (part_die
->tag
== DW_TAG_class_type
16668 || part_die
->tag
== DW_TAG_structure_type
16669 || part_die
->tag
== DW_TAG_union_type
))
16670 guess_partial_die_structure_name (part_die
, cu
);
16672 /* GCC might emit a nameless struct or union that has a linkage
16673 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16674 if (part_die
->name
== NULL
16675 && (part_die
->tag
== DW_TAG_class_type
16676 || part_die
->tag
== DW_TAG_interface_type
16677 || part_die
->tag
== DW_TAG_structure_type
16678 || part_die
->tag
== DW_TAG_union_type
)
16679 && part_die
->linkage_name
!= NULL
)
16683 demangled
= gdb_demangle (part_die
->linkage_name
, DMGL_TYPES
);
16688 /* Strip any leading namespaces/classes, keep only the base name.
16689 DW_AT_name for named DIEs does not contain the prefixes. */
16690 base
= strrchr (demangled
, ':');
16691 if (base
&& base
> demangled
&& base
[-1] == ':')
16698 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16699 base
, strlen (base
)));
16704 part_die
->fixup_called
= 1;
16707 /* Read an attribute value described by an attribute form. */
16709 static const gdb_byte
*
16710 read_attribute_value (const struct die_reader_specs
*reader
,
16711 struct attribute
*attr
, unsigned form
,
16712 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
16714 struct dwarf2_cu
*cu
= reader
->cu
;
16715 struct objfile
*objfile
= cu
->objfile
;
16716 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16717 bfd
*abfd
= reader
->abfd
;
16718 struct comp_unit_head
*cu_header
= &cu
->header
;
16719 unsigned int bytes_read
;
16720 struct dwarf_block
*blk
;
16722 attr
->form
= (enum dwarf_form
) form
;
16725 case DW_FORM_ref_addr
:
16726 if (cu
->header
.version
== 2)
16727 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
16729 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
16730 &cu
->header
, &bytes_read
);
16731 info_ptr
+= bytes_read
;
16733 case DW_FORM_GNU_ref_alt
:
16734 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
16735 info_ptr
+= bytes_read
;
16738 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
16739 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
16740 info_ptr
+= bytes_read
;
16742 case DW_FORM_block2
:
16743 blk
= dwarf_alloc_block (cu
);
16744 blk
->size
= read_2_bytes (abfd
, info_ptr
);
16746 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16747 info_ptr
+= blk
->size
;
16748 DW_BLOCK (attr
) = blk
;
16750 case DW_FORM_block4
:
16751 blk
= dwarf_alloc_block (cu
);
16752 blk
->size
= read_4_bytes (abfd
, info_ptr
);
16754 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16755 info_ptr
+= blk
->size
;
16756 DW_BLOCK (attr
) = blk
;
16758 case DW_FORM_data2
:
16759 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
16762 case DW_FORM_data4
:
16763 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
16766 case DW_FORM_data8
:
16767 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
16770 case DW_FORM_data16
:
16771 blk
= dwarf_alloc_block (cu
);
16773 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
16775 DW_BLOCK (attr
) = blk
;
16777 case DW_FORM_sec_offset
:
16778 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
16779 info_ptr
+= bytes_read
;
16781 case DW_FORM_string
:
16782 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
16783 DW_STRING_IS_CANONICAL (attr
) = 0;
16784 info_ptr
+= bytes_read
;
16787 if (!cu
->per_cu
->is_dwz
)
16789 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
16791 DW_STRING_IS_CANONICAL (attr
) = 0;
16792 info_ptr
+= bytes_read
;
16796 case DW_FORM_line_strp
:
16797 if (!cu
->per_cu
->is_dwz
)
16799 DW_STRING (attr
) = read_indirect_line_string (abfd
, info_ptr
,
16800 cu_header
, &bytes_read
);
16801 DW_STRING_IS_CANONICAL (attr
) = 0;
16802 info_ptr
+= bytes_read
;
16806 case DW_FORM_GNU_strp_alt
:
16808 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
16809 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
16812 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
16813 DW_STRING_IS_CANONICAL (attr
) = 0;
16814 info_ptr
+= bytes_read
;
16817 case DW_FORM_exprloc
:
16818 case DW_FORM_block
:
16819 blk
= dwarf_alloc_block (cu
);
16820 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16821 info_ptr
+= bytes_read
;
16822 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16823 info_ptr
+= blk
->size
;
16824 DW_BLOCK (attr
) = blk
;
16826 case DW_FORM_block1
:
16827 blk
= dwarf_alloc_block (cu
);
16828 blk
->size
= read_1_byte (abfd
, info_ptr
);
16830 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16831 info_ptr
+= blk
->size
;
16832 DW_BLOCK (attr
) = blk
;
16834 case DW_FORM_data1
:
16835 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
16839 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
16842 case DW_FORM_flag_present
:
16843 DW_UNSND (attr
) = 1;
16845 case DW_FORM_sdata
:
16846 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
16847 info_ptr
+= bytes_read
;
16849 case DW_FORM_udata
:
16850 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16851 info_ptr
+= bytes_read
;
16854 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
16855 + read_1_byte (abfd
, info_ptr
));
16859 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
16860 + read_2_bytes (abfd
, info_ptr
));
16864 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
16865 + read_4_bytes (abfd
, info_ptr
));
16869 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
16870 + read_8_bytes (abfd
, info_ptr
));
16873 case DW_FORM_ref_sig8
:
16874 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
16877 case DW_FORM_ref_udata
:
16878 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
16879 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
16880 info_ptr
+= bytes_read
;
16882 case DW_FORM_indirect
:
16883 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16884 info_ptr
+= bytes_read
;
16885 if (form
== DW_FORM_implicit_const
)
16887 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
16888 info_ptr
+= bytes_read
;
16890 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
16893 case DW_FORM_implicit_const
:
16894 DW_SND (attr
) = implicit_const
;
16896 case DW_FORM_GNU_addr_index
:
16897 if (reader
->dwo_file
== NULL
)
16899 /* For now flag a hard error.
16900 Later we can turn this into a complaint. */
16901 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
16902 dwarf_form_name (form
),
16903 bfd_get_filename (abfd
));
16905 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
16906 info_ptr
+= bytes_read
;
16908 case DW_FORM_GNU_str_index
:
16909 if (reader
->dwo_file
== NULL
)
16911 /* For now flag a hard error.
16912 Later we can turn this into a complaint if warranted. */
16913 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
16914 dwarf_form_name (form
),
16915 bfd_get_filename (abfd
));
16918 ULONGEST str_index
=
16919 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16921 DW_STRING (attr
) = read_str_index (reader
, str_index
);
16922 DW_STRING_IS_CANONICAL (attr
) = 0;
16923 info_ptr
+= bytes_read
;
16927 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
16928 dwarf_form_name (form
),
16929 bfd_get_filename (abfd
));
16933 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
16934 attr
->form
= DW_FORM_GNU_ref_alt
;
16936 /* We have seen instances where the compiler tried to emit a byte
16937 size attribute of -1 which ended up being encoded as an unsigned
16938 0xffffffff. Although 0xffffffff is technically a valid size value,
16939 an object of this size seems pretty unlikely so we can relatively
16940 safely treat these cases as if the size attribute was invalid and
16941 treat them as zero by default. */
16942 if (attr
->name
== DW_AT_byte_size
16943 && form
== DW_FORM_data4
16944 && DW_UNSND (attr
) >= 0xffffffff)
16947 (&symfile_complaints
,
16948 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
16949 hex_string (DW_UNSND (attr
)));
16950 DW_UNSND (attr
) = 0;
16956 /* Read an attribute described by an abbreviated attribute. */
16958 static const gdb_byte
*
16959 read_attribute (const struct die_reader_specs
*reader
,
16960 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
16961 const gdb_byte
*info_ptr
)
16963 attr
->name
= abbrev
->name
;
16964 return read_attribute_value (reader
, attr
, abbrev
->form
,
16965 abbrev
->implicit_const
, info_ptr
);
16968 /* Read dwarf information from a buffer. */
16970 static unsigned int
16971 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
16973 return bfd_get_8 (abfd
, buf
);
16977 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
16979 return bfd_get_signed_8 (abfd
, buf
);
16982 static unsigned int
16983 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16985 return bfd_get_16 (abfd
, buf
);
16989 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16991 return bfd_get_signed_16 (abfd
, buf
);
16994 static unsigned int
16995 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16997 return bfd_get_32 (abfd
, buf
);
17001 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
17003 return bfd_get_signed_32 (abfd
, buf
);
17007 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
17009 return bfd_get_64 (abfd
, buf
);
17013 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
17014 unsigned int *bytes_read
)
17016 struct comp_unit_head
*cu_header
= &cu
->header
;
17017 CORE_ADDR retval
= 0;
17019 if (cu_header
->signed_addr_p
)
17021 switch (cu_header
->addr_size
)
17024 retval
= bfd_get_signed_16 (abfd
, buf
);
17027 retval
= bfd_get_signed_32 (abfd
, buf
);
17030 retval
= bfd_get_signed_64 (abfd
, buf
);
17033 internal_error (__FILE__
, __LINE__
,
17034 _("read_address: bad switch, signed [in module %s]"),
17035 bfd_get_filename (abfd
));
17040 switch (cu_header
->addr_size
)
17043 retval
= bfd_get_16 (abfd
, buf
);
17046 retval
= bfd_get_32 (abfd
, buf
);
17049 retval
= bfd_get_64 (abfd
, buf
);
17052 internal_error (__FILE__
, __LINE__
,
17053 _("read_address: bad switch, "
17054 "unsigned [in module %s]"),
17055 bfd_get_filename (abfd
));
17059 *bytes_read
= cu_header
->addr_size
;
17063 /* Read the initial length from a section. The (draft) DWARF 3
17064 specification allows the initial length to take up either 4 bytes
17065 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
17066 bytes describe the length and all offsets will be 8 bytes in length
17069 An older, non-standard 64-bit format is also handled by this
17070 function. The older format in question stores the initial length
17071 as an 8-byte quantity without an escape value. Lengths greater
17072 than 2^32 aren't very common which means that the initial 4 bytes
17073 is almost always zero. Since a length value of zero doesn't make
17074 sense for the 32-bit format, this initial zero can be considered to
17075 be an escape value which indicates the presence of the older 64-bit
17076 format. As written, the code can't detect (old format) lengths
17077 greater than 4GB. If it becomes necessary to handle lengths
17078 somewhat larger than 4GB, we could allow other small values (such
17079 as the non-sensical values of 1, 2, and 3) to also be used as
17080 escape values indicating the presence of the old format.
17082 The value returned via bytes_read should be used to increment the
17083 relevant pointer after calling read_initial_length().
17085 [ Note: read_initial_length() and read_offset() are based on the
17086 document entitled "DWARF Debugging Information Format", revision
17087 3, draft 8, dated November 19, 2001. This document was obtained
17090 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
17092 This document is only a draft and is subject to change. (So beware.)
17094 Details regarding the older, non-standard 64-bit format were
17095 determined empirically by examining 64-bit ELF files produced by
17096 the SGI toolchain on an IRIX 6.5 machine.
17098 - Kevin, July 16, 2002
17102 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
17104 LONGEST length
= bfd_get_32 (abfd
, buf
);
17106 if (length
== 0xffffffff)
17108 length
= bfd_get_64 (abfd
, buf
+ 4);
17111 else if (length
== 0)
17113 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
17114 length
= bfd_get_64 (abfd
, buf
);
17125 /* Cover function for read_initial_length.
17126 Returns the length of the object at BUF, and stores the size of the
17127 initial length in *BYTES_READ and stores the size that offsets will be in
17129 If the initial length size is not equivalent to that specified in
17130 CU_HEADER then issue a complaint.
17131 This is useful when reading non-comp-unit headers. */
17134 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
17135 const struct comp_unit_head
*cu_header
,
17136 unsigned int *bytes_read
,
17137 unsigned int *offset_size
)
17139 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
17141 gdb_assert (cu_header
->initial_length_size
== 4
17142 || cu_header
->initial_length_size
== 8
17143 || cu_header
->initial_length_size
== 12);
17145 if (cu_header
->initial_length_size
!= *bytes_read
)
17146 complaint (&symfile_complaints
,
17147 _("intermixed 32-bit and 64-bit DWARF sections"));
17149 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
17153 /* Read an offset from the data stream. The size of the offset is
17154 given by cu_header->offset_size. */
17157 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
17158 const struct comp_unit_head
*cu_header
,
17159 unsigned int *bytes_read
)
17161 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
17163 *bytes_read
= cu_header
->offset_size
;
17167 /* Read an offset from the data stream. */
17170 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
17172 LONGEST retval
= 0;
17174 switch (offset_size
)
17177 retval
= bfd_get_32 (abfd
, buf
);
17180 retval
= bfd_get_64 (abfd
, buf
);
17183 internal_error (__FILE__
, __LINE__
,
17184 _("read_offset_1: bad switch [in module %s]"),
17185 bfd_get_filename (abfd
));
17191 static const gdb_byte
*
17192 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
17194 /* If the size of a host char is 8 bits, we can return a pointer
17195 to the buffer, otherwise we have to copy the data to a buffer
17196 allocated on the temporary obstack. */
17197 gdb_assert (HOST_CHAR_BIT
== 8);
17201 static const char *
17202 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
17203 unsigned int *bytes_read_ptr
)
17205 /* If the size of a host char is 8 bits, we can return a pointer
17206 to the string, otherwise we have to copy the string to a buffer
17207 allocated on the temporary obstack. */
17208 gdb_assert (HOST_CHAR_BIT
== 8);
17211 *bytes_read_ptr
= 1;
17214 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
17215 return (const char *) buf
;
17218 /* Return pointer to string at section SECT offset STR_OFFSET with error
17219 reporting strings FORM_NAME and SECT_NAME. */
17221 static const char *
17222 read_indirect_string_at_offset_from (bfd
*abfd
, LONGEST str_offset
,
17223 struct dwarf2_section_info
*sect
,
17224 const char *form_name
,
17225 const char *sect_name
)
17227 dwarf2_read_section (dwarf2_per_objfile
->objfile
, sect
);
17228 if (sect
->buffer
== NULL
)
17229 error (_("%s used without %s section [in module %s]"),
17230 form_name
, sect_name
, bfd_get_filename (abfd
));
17231 if (str_offset
>= sect
->size
)
17232 error (_("%s pointing outside of %s section [in module %s]"),
17233 form_name
, sect_name
, bfd_get_filename (abfd
));
17234 gdb_assert (HOST_CHAR_BIT
== 8);
17235 if (sect
->buffer
[str_offset
] == '\0')
17237 return (const char *) (sect
->buffer
+ str_offset
);
17240 /* Return pointer to string at .debug_str offset STR_OFFSET. */
17242 static const char *
17243 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
17245 return read_indirect_string_at_offset_from (abfd
, str_offset
,
17246 &dwarf2_per_objfile
->str
,
17247 "DW_FORM_strp", ".debug_str");
17250 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
17252 static const char *
17253 read_indirect_line_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
17255 return read_indirect_string_at_offset_from (abfd
, str_offset
,
17256 &dwarf2_per_objfile
->line_str
,
17257 "DW_FORM_line_strp",
17258 ".debug_line_str");
17261 /* Read a string at offset STR_OFFSET in the .debug_str section from
17262 the .dwz file DWZ. Throw an error if the offset is too large. If
17263 the string consists of a single NUL byte, return NULL; otherwise
17264 return a pointer to the string. */
17266 static const char *
17267 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
17269 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
17271 if (dwz
->str
.buffer
== NULL
)
17272 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
17273 "section [in module %s]"),
17274 bfd_get_filename (dwz
->dwz_bfd
));
17275 if (str_offset
>= dwz
->str
.size
)
17276 error (_("DW_FORM_GNU_strp_alt pointing outside of "
17277 ".debug_str section [in module %s]"),
17278 bfd_get_filename (dwz
->dwz_bfd
));
17279 gdb_assert (HOST_CHAR_BIT
== 8);
17280 if (dwz
->str
.buffer
[str_offset
] == '\0')
17282 return (const char *) (dwz
->str
.buffer
+ str_offset
);
17285 /* Return pointer to string at .debug_str offset as read from BUF.
17286 BUF is assumed to be in a compilation unit described by CU_HEADER.
17287 Return *BYTES_READ_PTR count of bytes read from BUF. */
17289 static const char *
17290 read_indirect_string (bfd
*abfd
, const gdb_byte
*buf
,
17291 const struct comp_unit_head
*cu_header
,
17292 unsigned int *bytes_read_ptr
)
17294 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
17296 return read_indirect_string_at_offset (abfd
, str_offset
);
17299 /* Return pointer to string at .debug_line_str offset as read from BUF.
17300 BUF is assumed to be in a compilation unit described by CU_HEADER.
17301 Return *BYTES_READ_PTR count of bytes read from BUF. */
17303 static const char *
17304 read_indirect_line_string (bfd
*abfd
, const gdb_byte
*buf
,
17305 const struct comp_unit_head
*cu_header
,
17306 unsigned int *bytes_read_ptr
)
17308 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
17310 return read_indirect_line_string_at_offset (abfd
, str_offset
);
17314 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
17315 unsigned int *bytes_read_ptr
)
17318 unsigned int num_read
;
17320 unsigned char byte
;
17327 byte
= bfd_get_8 (abfd
, buf
);
17330 result
|= ((ULONGEST
) (byte
& 127) << shift
);
17331 if ((byte
& 128) == 0)
17337 *bytes_read_ptr
= num_read
;
17342 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
17343 unsigned int *bytes_read_ptr
)
17346 int shift
, num_read
;
17347 unsigned char byte
;
17354 byte
= bfd_get_8 (abfd
, buf
);
17357 result
|= ((LONGEST
) (byte
& 127) << shift
);
17359 if ((byte
& 128) == 0)
17364 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
17365 result
|= -(((LONGEST
) 1) << shift
);
17366 *bytes_read_ptr
= num_read
;
17370 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
17371 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
17372 ADDR_SIZE is the size of addresses from the CU header. */
17375 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
17377 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17378 bfd
*abfd
= objfile
->obfd
;
17379 const gdb_byte
*info_ptr
;
17381 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
17382 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
17383 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
17384 objfile_name (objfile
));
17385 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
17386 error (_("DW_FORM_addr_index pointing outside of "
17387 ".debug_addr section [in module %s]"),
17388 objfile_name (objfile
));
17389 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
17390 + addr_base
+ addr_index
* addr_size
);
17391 if (addr_size
== 4)
17392 return bfd_get_32 (abfd
, info_ptr
);
17394 return bfd_get_64 (abfd
, info_ptr
);
17397 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
17400 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
17402 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
17405 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
17408 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
17409 unsigned int *bytes_read
)
17411 bfd
*abfd
= cu
->objfile
->obfd
;
17412 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
17414 return read_addr_index (cu
, addr_index
);
17417 /* Data structure to pass results from dwarf2_read_addr_index_reader
17418 back to dwarf2_read_addr_index. */
17420 struct dwarf2_read_addr_index_data
17422 ULONGEST addr_base
;
17426 /* die_reader_func for dwarf2_read_addr_index. */
17429 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
17430 const gdb_byte
*info_ptr
,
17431 struct die_info
*comp_unit_die
,
17435 struct dwarf2_cu
*cu
= reader
->cu
;
17436 struct dwarf2_read_addr_index_data
*aidata
=
17437 (struct dwarf2_read_addr_index_data
*) data
;
17439 aidata
->addr_base
= cu
->addr_base
;
17440 aidata
->addr_size
= cu
->header
.addr_size
;
17443 /* Given an index in .debug_addr, fetch the value.
17444 NOTE: This can be called during dwarf expression evaluation,
17445 long after the debug information has been read, and thus per_cu->cu
17446 may no longer exist. */
17449 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
17450 unsigned int addr_index
)
17452 struct objfile
*objfile
= per_cu
->objfile
;
17453 struct dwarf2_cu
*cu
= per_cu
->cu
;
17454 ULONGEST addr_base
;
17457 /* This is intended to be called from outside this file. */
17458 dw2_setup (objfile
);
17460 /* We need addr_base and addr_size.
17461 If we don't have PER_CU->cu, we have to get it.
17462 Nasty, but the alternative is storing the needed info in PER_CU,
17463 which at this point doesn't seem justified: it's not clear how frequently
17464 it would get used and it would increase the size of every PER_CU.
17465 Entry points like dwarf2_per_cu_addr_size do a similar thing
17466 so we're not in uncharted territory here.
17467 Alas we need to be a bit more complicated as addr_base is contained
17470 We don't need to read the entire CU(/TU).
17471 We just need the header and top level die.
17473 IWBN to use the aging mechanism to let us lazily later discard the CU.
17474 For now we skip this optimization. */
17478 addr_base
= cu
->addr_base
;
17479 addr_size
= cu
->header
.addr_size
;
17483 struct dwarf2_read_addr_index_data aidata
;
17485 /* Note: We can't use init_cutu_and_read_dies_simple here,
17486 we need addr_base. */
17487 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
17488 dwarf2_read_addr_index_reader
, &aidata
);
17489 addr_base
= aidata
.addr_base
;
17490 addr_size
= aidata
.addr_size
;
17493 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
17496 /* Given a DW_FORM_GNU_str_index, fetch the string.
17497 This is only used by the Fission support. */
17499 static const char *
17500 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
17502 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17503 const char *objf_name
= objfile_name (objfile
);
17504 bfd
*abfd
= objfile
->obfd
;
17505 struct dwarf2_cu
*cu
= reader
->cu
;
17506 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
17507 struct dwarf2_section_info
*str_offsets_section
=
17508 &reader
->dwo_file
->sections
.str_offsets
;
17509 const gdb_byte
*info_ptr
;
17510 ULONGEST str_offset
;
17511 static const char form_name
[] = "DW_FORM_GNU_str_index";
17513 dwarf2_read_section (objfile
, str_section
);
17514 dwarf2_read_section (objfile
, str_offsets_section
);
17515 if (str_section
->buffer
== NULL
)
17516 error (_("%s used without .debug_str.dwo section"
17517 " in CU at offset 0x%x [in module %s]"),
17518 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
17519 if (str_offsets_section
->buffer
== NULL
)
17520 error (_("%s used without .debug_str_offsets.dwo section"
17521 " in CU at offset 0x%x [in module %s]"),
17522 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
17523 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
17524 error (_("%s pointing outside of .debug_str_offsets.dwo"
17525 " section in CU at offset 0x%x [in module %s]"),
17526 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
17527 info_ptr
= (str_offsets_section
->buffer
17528 + str_index
* cu
->header
.offset_size
);
17529 if (cu
->header
.offset_size
== 4)
17530 str_offset
= bfd_get_32 (abfd
, info_ptr
);
17532 str_offset
= bfd_get_64 (abfd
, info_ptr
);
17533 if (str_offset
>= str_section
->size
)
17534 error (_("Offset from %s pointing outside of"
17535 " .debug_str.dwo section in CU at offset 0x%x [in module %s]"),
17536 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
17537 return (const char *) (str_section
->buffer
+ str_offset
);
17540 /* Return the length of an LEB128 number in BUF. */
17543 leb128_size (const gdb_byte
*buf
)
17545 const gdb_byte
*begin
= buf
;
17551 if ((byte
& 128) == 0)
17552 return buf
- begin
;
17557 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
17566 cu
->language
= language_c
;
17569 case DW_LANG_C_plus_plus
:
17570 case DW_LANG_C_plus_plus_11
:
17571 case DW_LANG_C_plus_plus_14
:
17572 cu
->language
= language_cplus
;
17575 cu
->language
= language_d
;
17577 case DW_LANG_Fortran77
:
17578 case DW_LANG_Fortran90
:
17579 case DW_LANG_Fortran95
:
17580 case DW_LANG_Fortran03
:
17581 case DW_LANG_Fortran08
:
17582 cu
->language
= language_fortran
;
17585 cu
->language
= language_go
;
17587 case DW_LANG_Mips_Assembler
:
17588 cu
->language
= language_asm
;
17590 case DW_LANG_Ada83
:
17591 case DW_LANG_Ada95
:
17592 cu
->language
= language_ada
;
17594 case DW_LANG_Modula2
:
17595 cu
->language
= language_m2
;
17597 case DW_LANG_Pascal83
:
17598 cu
->language
= language_pascal
;
17601 cu
->language
= language_objc
;
17604 case DW_LANG_Rust_old
:
17605 cu
->language
= language_rust
;
17607 case DW_LANG_Cobol74
:
17608 case DW_LANG_Cobol85
:
17610 cu
->language
= language_minimal
;
17613 cu
->language_defn
= language_def (cu
->language
);
17616 /* Return the named attribute or NULL if not there. */
17618 static struct attribute
*
17619 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17624 struct attribute
*spec
= NULL
;
17626 for (i
= 0; i
< die
->num_attrs
; ++i
)
17628 if (die
->attrs
[i
].name
== name
)
17629 return &die
->attrs
[i
];
17630 if (die
->attrs
[i
].name
== DW_AT_specification
17631 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
17632 spec
= &die
->attrs
[i
];
17638 die
= follow_die_ref (die
, spec
, &cu
);
17644 /* Return the named attribute or NULL if not there,
17645 but do not follow DW_AT_specification, etc.
17646 This is for use in contexts where we're reading .debug_types dies.
17647 Following DW_AT_specification, DW_AT_abstract_origin will take us
17648 back up the chain, and we want to go down. */
17650 static struct attribute
*
17651 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
17655 for (i
= 0; i
< die
->num_attrs
; ++i
)
17656 if (die
->attrs
[i
].name
== name
)
17657 return &die
->attrs
[i
];
17662 /* Return the string associated with a string-typed attribute, or NULL if it
17663 is either not found or is of an incorrect type. */
17665 static const char *
17666 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17668 struct attribute
*attr
;
17669 const char *str
= NULL
;
17671 attr
= dwarf2_attr (die
, name
, cu
);
17675 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
17676 || attr
->form
== DW_FORM_string
17677 || attr
->form
== DW_FORM_GNU_str_index
17678 || attr
->form
== DW_FORM_GNU_strp_alt
)
17679 str
= DW_STRING (attr
);
17681 complaint (&symfile_complaints
,
17682 _("string type expected for attribute %s for "
17683 "DIE at 0x%x in module %s"),
17684 dwarf_attr_name (name
), to_underlying (die
->sect_off
),
17685 objfile_name (cu
->objfile
));
17691 /* Return non-zero iff the attribute NAME is defined for the given DIE,
17692 and holds a non-zero value. This function should only be used for
17693 DW_FORM_flag or DW_FORM_flag_present attributes. */
17696 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
17698 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
17700 return (attr
&& DW_UNSND (attr
));
17704 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
17706 /* A DIE is a declaration if it has a DW_AT_declaration attribute
17707 which value is non-zero. However, we have to be careful with
17708 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
17709 (via dwarf2_flag_true_p) follows this attribute. So we may
17710 end up accidently finding a declaration attribute that belongs
17711 to a different DIE referenced by the specification attribute,
17712 even though the given DIE does not have a declaration attribute. */
17713 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
17714 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
17717 /* Return the die giving the specification for DIE, if there is
17718 one. *SPEC_CU is the CU containing DIE on input, and the CU
17719 containing the return value on output. If there is no
17720 specification, but there is an abstract origin, that is
17723 static struct die_info
*
17724 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
17726 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
17729 if (spec_attr
== NULL
)
17730 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
17732 if (spec_attr
== NULL
)
17735 return follow_die_ref (die
, spec_attr
, spec_cu
);
17738 /* Stub for free_line_header to match void * callback types. */
17741 free_line_header_voidp (void *arg
)
17743 struct line_header
*lh
= (struct line_header
*) arg
;
17749 line_header::add_include_dir (const char *include_dir
)
17751 if (dwarf_line_debug
>= 2)
17752 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
17753 include_dirs
.size () + 1, include_dir
);
17755 include_dirs
.push_back (include_dir
);
17759 line_header::add_file_name (const char *name
,
17761 unsigned int mod_time
,
17762 unsigned int length
)
17764 if (dwarf_line_debug
>= 2)
17765 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
17766 (unsigned) file_names
.size () + 1, name
);
17768 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
17771 /* A convenience function to find the proper .debug_line section for a CU. */
17773 static struct dwarf2_section_info
*
17774 get_debug_line_section (struct dwarf2_cu
*cu
)
17776 struct dwarf2_section_info
*section
;
17778 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
17780 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17781 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
17782 else if (cu
->per_cu
->is_dwz
)
17784 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
17786 section
= &dwz
->line
;
17789 section
= &dwarf2_per_objfile
->line
;
17794 /* Read directory or file name entry format, starting with byte of
17795 format count entries, ULEB128 pairs of entry formats, ULEB128 of
17796 entries count and the entries themselves in the described entry
17800 read_formatted_entries (bfd
*abfd
, const gdb_byte
**bufp
,
17801 struct line_header
*lh
,
17802 const struct comp_unit_head
*cu_header
,
17803 void (*callback
) (struct line_header
*lh
,
17806 unsigned int mod_time
,
17807 unsigned int length
))
17809 gdb_byte format_count
, formati
;
17810 ULONGEST data_count
, datai
;
17811 const gdb_byte
*buf
= *bufp
;
17812 const gdb_byte
*format_header_data
;
17814 unsigned int bytes_read
;
17816 format_count
= read_1_byte (abfd
, buf
);
17818 format_header_data
= buf
;
17819 for (formati
= 0; formati
< format_count
; formati
++)
17821 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17823 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17827 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17829 for (datai
= 0; datai
< data_count
; datai
++)
17831 const gdb_byte
*format
= format_header_data
;
17832 struct file_entry fe
;
17834 for (formati
= 0; formati
< format_count
; formati
++)
17836 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
17837 format
+= bytes_read
;
17839 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
17840 format
+= bytes_read
;
17842 gdb::optional
<const char *> string
;
17843 gdb::optional
<unsigned int> uint
;
17847 case DW_FORM_string
:
17848 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
17852 case DW_FORM_line_strp
:
17853 string
.emplace (read_indirect_line_string (abfd
, buf
,
17859 case DW_FORM_data1
:
17860 uint
.emplace (read_1_byte (abfd
, buf
));
17864 case DW_FORM_data2
:
17865 uint
.emplace (read_2_bytes (abfd
, buf
));
17869 case DW_FORM_data4
:
17870 uint
.emplace (read_4_bytes (abfd
, buf
));
17874 case DW_FORM_data8
:
17875 uint
.emplace (read_8_bytes (abfd
, buf
));
17879 case DW_FORM_udata
:
17880 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
17884 case DW_FORM_block
:
17885 /* It is valid only for DW_LNCT_timestamp which is ignored by
17890 switch (content_type
)
17893 if (string
.has_value ())
17896 case DW_LNCT_directory_index
:
17897 if (uint
.has_value ())
17898 fe
.d_index
= (dir_index
) *uint
;
17900 case DW_LNCT_timestamp
:
17901 if (uint
.has_value ())
17902 fe
.mod_time
= *uint
;
17905 if (uint
.has_value ())
17911 complaint (&symfile_complaints
,
17912 _("Unknown format content type %s"),
17913 pulongest (content_type
));
17917 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
17923 /* Read the statement program header starting at OFFSET in
17924 .debug_line, or .debug_line.dwo. Return a pointer
17925 to a struct line_header, allocated using xmalloc.
17926 Returns NULL if there is a problem reading the header, e.g., if it
17927 has a version we don't understand.
17929 NOTE: the strings in the include directory and file name tables of
17930 the returned object point into the dwarf line section buffer,
17931 and must not be freed. */
17933 static line_header_up
17934 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
17936 const gdb_byte
*line_ptr
;
17937 unsigned int bytes_read
, offset_size
;
17939 const char *cur_dir
, *cur_file
;
17940 struct dwarf2_section_info
*section
;
17943 section
= get_debug_line_section (cu
);
17944 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
17945 if (section
->buffer
== NULL
)
17947 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17948 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
17950 complaint (&symfile_complaints
, _("missing .debug_line section"));
17954 /* We can't do this until we know the section is non-empty.
17955 Only then do we know we have such a section. */
17956 abfd
= get_section_bfd_owner (section
);
17958 /* Make sure that at least there's room for the total_length field.
17959 That could be 12 bytes long, but we're just going to fudge that. */
17960 if (to_underlying (sect_off
) + 4 >= section
->size
)
17962 dwarf2_statement_list_fits_in_line_number_section_complaint ();
17966 line_header_up
lh (new line_header ());
17968 lh
->sect_off
= sect_off
;
17969 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
17971 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
17973 /* Read in the header. */
17975 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
17976 &bytes_read
, &offset_size
);
17977 line_ptr
+= bytes_read
;
17978 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
17980 dwarf2_statement_list_fits_in_line_number_section_complaint ();
17983 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
17984 lh
->version
= read_2_bytes (abfd
, line_ptr
);
17986 if (lh
->version
> 5)
17988 /* This is a version we don't understand. The format could have
17989 changed in ways we don't handle properly so just punt. */
17990 complaint (&symfile_complaints
,
17991 _("unsupported version in .debug_line section"));
17994 if (lh
->version
>= 5)
17996 gdb_byte segment_selector_size
;
17998 /* Skip address size. */
17999 read_1_byte (abfd
, line_ptr
);
18002 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
18004 if (segment_selector_size
!= 0)
18006 complaint (&symfile_complaints
,
18007 _("unsupported segment selector size %u "
18008 "in .debug_line section"),
18009 segment_selector_size
);
18013 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
18014 line_ptr
+= offset_size
;
18015 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
18017 if (lh
->version
>= 4)
18019 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
18023 lh
->maximum_ops_per_instruction
= 1;
18025 if (lh
->maximum_ops_per_instruction
== 0)
18027 lh
->maximum_ops_per_instruction
= 1;
18028 complaint (&symfile_complaints
,
18029 _("invalid maximum_ops_per_instruction "
18030 "in `.debug_line' section"));
18033 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
18035 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
18037 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
18039 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
18041 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
18043 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
18044 for (i
= 1; i
< lh
->opcode_base
; ++i
)
18046 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
18050 if (lh
->version
>= 5)
18052 /* Read directory table. */
18053 read_formatted_entries (abfd
, &line_ptr
, lh
.get (), &cu
->header
,
18054 [] (struct line_header
*lh
, const char *name
,
18055 dir_index d_index
, unsigned int mod_time
,
18056 unsigned int length
)
18058 lh
->add_include_dir (name
);
18061 /* Read file name table. */
18062 read_formatted_entries (abfd
, &line_ptr
, lh
.get (), &cu
->header
,
18063 [] (struct line_header
*lh
, const char *name
,
18064 dir_index d_index
, unsigned int mod_time
,
18065 unsigned int length
)
18067 lh
->add_file_name (name
, d_index
, mod_time
, length
);
18072 /* Read directory table. */
18073 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
18075 line_ptr
+= bytes_read
;
18076 lh
->add_include_dir (cur_dir
);
18078 line_ptr
+= bytes_read
;
18080 /* Read file name table. */
18081 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
18083 unsigned int mod_time
, length
;
18086 line_ptr
+= bytes_read
;
18087 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18088 line_ptr
+= bytes_read
;
18089 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18090 line_ptr
+= bytes_read
;
18091 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18092 line_ptr
+= bytes_read
;
18094 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
18096 line_ptr
+= bytes_read
;
18098 lh
->statement_program_start
= line_ptr
;
18100 if (line_ptr
> (section
->buffer
+ section
->size
))
18101 complaint (&symfile_complaints
,
18102 _("line number info header doesn't "
18103 "fit in `.debug_line' section"));
18108 /* Subroutine of dwarf_decode_lines to simplify it.
18109 Return the file name of the psymtab for included file FILE_INDEX
18110 in line header LH of PST.
18111 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
18112 If space for the result is malloc'd, it will be freed by a cleanup.
18113 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
18115 The function creates dangling cleanup registration. */
18117 static const char *
18118 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
18119 const struct partial_symtab
*pst
,
18120 const char *comp_dir
)
18122 const file_entry
&fe
= lh
->file_names
[file_index
];
18123 const char *include_name
= fe
.name
;
18124 const char *include_name_to_compare
= include_name
;
18125 const char *pst_filename
;
18126 char *copied_name
= NULL
;
18129 const char *dir_name
= fe
.include_dir (lh
);
18131 if (!IS_ABSOLUTE_PATH (include_name
)
18132 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
18134 /* Avoid creating a duplicate psymtab for PST.
18135 We do this by comparing INCLUDE_NAME and PST_FILENAME.
18136 Before we do the comparison, however, we need to account
18137 for DIR_NAME and COMP_DIR.
18138 First prepend dir_name (if non-NULL). If we still don't
18139 have an absolute path prepend comp_dir (if non-NULL).
18140 However, the directory we record in the include-file's
18141 psymtab does not contain COMP_DIR (to match the
18142 corresponding symtab(s)).
18147 bash$ gcc -g ./hello.c
18148 include_name = "hello.c"
18150 DW_AT_comp_dir = comp_dir = "/tmp"
18151 DW_AT_name = "./hello.c"
18155 if (dir_name
!= NULL
)
18157 char *tem
= concat (dir_name
, SLASH_STRING
,
18158 include_name
, (char *)NULL
);
18160 make_cleanup (xfree
, tem
);
18161 include_name
= tem
;
18162 include_name_to_compare
= include_name
;
18164 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
18166 char *tem
= concat (comp_dir
, SLASH_STRING
,
18167 include_name
, (char *)NULL
);
18169 make_cleanup (xfree
, tem
);
18170 include_name_to_compare
= tem
;
18174 pst_filename
= pst
->filename
;
18175 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
18177 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
18178 pst_filename
, (char *)NULL
);
18179 pst_filename
= copied_name
;
18182 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
18184 if (copied_name
!= NULL
)
18185 xfree (copied_name
);
18189 return include_name
;
18192 /* State machine to track the state of the line number program. */
18194 class lnp_state_machine
18197 /* Initialize a machine state for the start of a line number
18199 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
18201 file_entry
*current_file ()
18203 /* lh->file_names is 0-based, but the file name numbers in the
18204 statement program are 1-based. */
18205 return m_line_header
->file_name_at (m_file
);
18208 /* Record the line in the state machine. END_SEQUENCE is true if
18209 we're processing the end of a sequence. */
18210 void record_line (bool end_sequence
);
18212 /* Check address and if invalid nop-out the rest of the lines in this
18214 void check_line_address (struct dwarf2_cu
*cu
,
18215 const gdb_byte
*line_ptr
,
18216 CORE_ADDR lowpc
, CORE_ADDR address
);
18218 void handle_set_discriminator (unsigned int discriminator
)
18220 m_discriminator
= discriminator
;
18221 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
18224 /* Handle DW_LNE_set_address. */
18225 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
18228 address
+= baseaddr
;
18229 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
18232 /* Handle DW_LNS_advance_pc. */
18233 void handle_advance_pc (CORE_ADDR adjust
);
18235 /* Handle a special opcode. */
18236 void handle_special_opcode (unsigned char op_code
);
18238 /* Handle DW_LNS_advance_line. */
18239 void handle_advance_line (int line_delta
)
18241 advance_line (line_delta
);
18244 /* Handle DW_LNS_set_file. */
18245 void handle_set_file (file_name_index file
);
18247 /* Handle DW_LNS_negate_stmt. */
18248 void handle_negate_stmt ()
18250 m_is_stmt
= !m_is_stmt
;
18253 /* Handle DW_LNS_const_add_pc. */
18254 void handle_const_add_pc ();
18256 /* Handle DW_LNS_fixed_advance_pc. */
18257 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
18259 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18263 /* Handle DW_LNS_copy. */
18264 void handle_copy ()
18266 record_line (false);
18267 m_discriminator
= 0;
18270 /* Handle DW_LNE_end_sequence. */
18271 void handle_end_sequence ()
18273 m_record_line_callback
= ::record_line
;
18277 /* Advance the line by LINE_DELTA. */
18278 void advance_line (int line_delta
)
18280 m_line
+= line_delta
;
18282 if (line_delta
!= 0)
18283 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
18286 gdbarch
*m_gdbarch
;
18288 /* True if we're recording lines.
18289 Otherwise we're building partial symtabs and are just interested in
18290 finding include files mentioned by the line number program. */
18291 bool m_record_lines_p
;
18293 /* The line number header. */
18294 line_header
*m_line_header
;
18296 /* These are part of the standard DWARF line number state machine,
18297 and initialized according to the DWARF spec. */
18299 unsigned char m_op_index
= 0;
18300 /* The line table index (1-based) of the current file. */
18301 file_name_index m_file
= (file_name_index
) 1;
18302 unsigned int m_line
= 1;
18304 /* These are initialized in the constructor. */
18306 CORE_ADDR m_address
;
18308 unsigned int m_discriminator
;
18310 /* Additional bits of state we need to track. */
18312 /* The last file that we called dwarf2_start_subfile for.
18313 This is only used for TLLs. */
18314 unsigned int m_last_file
= 0;
18315 /* The last file a line number was recorded for. */
18316 struct subfile
*m_last_subfile
= NULL
;
18318 /* The function to call to record a line. */
18319 record_line_ftype
*m_record_line_callback
= NULL
;
18321 /* The last line number that was recorded, used to coalesce
18322 consecutive entries for the same line. This can happen, for
18323 example, when discriminators are present. PR 17276. */
18324 unsigned int m_last_line
= 0;
18325 bool m_line_has_non_zero_discriminator
= false;
18329 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
18331 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
18332 / m_line_header
->maximum_ops_per_instruction
)
18333 * m_line_header
->minimum_instruction_length
);
18334 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18335 m_op_index
= ((m_op_index
+ adjust
)
18336 % m_line_header
->maximum_ops_per_instruction
);
18340 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
18342 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
18343 CORE_ADDR addr_adj
= (((m_op_index
18344 + (adj_opcode
/ m_line_header
->line_range
))
18345 / m_line_header
->maximum_ops_per_instruction
)
18346 * m_line_header
->minimum_instruction_length
);
18347 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18348 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
18349 % m_line_header
->maximum_ops_per_instruction
);
18351 int line_delta
= (m_line_header
->line_base
18352 + (adj_opcode
% m_line_header
->line_range
));
18353 advance_line (line_delta
);
18354 record_line (false);
18355 m_discriminator
= 0;
18359 lnp_state_machine::handle_set_file (file_name_index file
)
18363 const file_entry
*fe
= current_file ();
18365 dwarf2_debug_line_missing_file_complaint ();
18366 else if (m_record_lines_p
)
18368 const char *dir
= fe
->include_dir (m_line_header
);
18370 m_last_subfile
= current_subfile
;
18371 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
18372 dwarf2_start_subfile (fe
->name
, dir
);
18377 lnp_state_machine::handle_const_add_pc ()
18380 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
18383 = (((m_op_index
+ adjust
)
18384 / m_line_header
->maximum_ops_per_instruction
)
18385 * m_line_header
->minimum_instruction_length
);
18387 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18388 m_op_index
= ((m_op_index
+ adjust
)
18389 % m_line_header
->maximum_ops_per_instruction
);
18392 /* Ignore this record_line request. */
18395 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
18400 /* Return non-zero if we should add LINE to the line number table.
18401 LINE is the line to add, LAST_LINE is the last line that was added,
18402 LAST_SUBFILE is the subfile for LAST_LINE.
18403 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
18404 had a non-zero discriminator.
18406 We have to be careful in the presence of discriminators.
18407 E.g., for this line:
18409 for (i = 0; i < 100000; i++);
18411 clang can emit four line number entries for that one line,
18412 each with a different discriminator.
18413 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
18415 However, we want gdb to coalesce all four entries into one.
18416 Otherwise the user could stepi into the middle of the line and
18417 gdb would get confused about whether the pc really was in the
18418 middle of the line.
18420 Things are further complicated by the fact that two consecutive
18421 line number entries for the same line is a heuristic used by gcc
18422 to denote the end of the prologue. So we can't just discard duplicate
18423 entries, we have to be selective about it. The heuristic we use is
18424 that we only collapse consecutive entries for the same line if at least
18425 one of those entries has a non-zero discriminator. PR 17276.
18427 Note: Addresses in the line number state machine can never go backwards
18428 within one sequence, thus this coalescing is ok. */
18431 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
18432 int line_has_non_zero_discriminator
,
18433 struct subfile
*last_subfile
)
18435 if (current_subfile
!= last_subfile
)
18437 if (line
!= last_line
)
18439 /* Same line for the same file that we've seen already.
18440 As a last check, for pr 17276, only record the line if the line
18441 has never had a non-zero discriminator. */
18442 if (!line_has_non_zero_discriminator
)
18447 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
18448 in the line table of subfile SUBFILE. */
18451 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
18452 unsigned int line
, CORE_ADDR address
,
18453 record_line_ftype p_record_line
)
18455 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
18457 if (dwarf_line_debug
)
18459 fprintf_unfiltered (gdb_stdlog
,
18460 "Recording line %u, file %s, address %s\n",
18461 line
, lbasename (subfile
->name
),
18462 paddress (gdbarch
, address
));
18465 (*p_record_line
) (subfile
, line
, addr
);
18468 /* Subroutine of dwarf_decode_lines_1 to simplify it.
18469 Mark the end of a set of line number records.
18470 The arguments are the same as for dwarf_record_line_1.
18471 If SUBFILE is NULL the request is ignored. */
18474 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
18475 CORE_ADDR address
, record_line_ftype p_record_line
)
18477 if (subfile
== NULL
)
18480 if (dwarf_line_debug
)
18482 fprintf_unfiltered (gdb_stdlog
,
18483 "Finishing current line, file %s, address %s\n",
18484 lbasename (subfile
->name
),
18485 paddress (gdbarch
, address
));
18488 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
18492 lnp_state_machine::record_line (bool end_sequence
)
18494 if (dwarf_line_debug
)
18496 fprintf_unfiltered (gdb_stdlog
,
18497 "Processing actual line %u: file %u,"
18498 " address %s, is_stmt %u, discrim %u\n",
18499 m_line
, to_underlying (m_file
),
18500 paddress (m_gdbarch
, m_address
),
18501 m_is_stmt
, m_discriminator
);
18504 file_entry
*fe
= current_file ();
18507 dwarf2_debug_line_missing_file_complaint ();
18508 /* For now we ignore lines not starting on an instruction boundary.
18509 But not when processing end_sequence for compatibility with the
18510 previous version of the code. */
18511 else if (m_op_index
== 0 || end_sequence
)
18513 fe
->included_p
= 1;
18514 if (m_record_lines_p
&& m_is_stmt
)
18516 if (m_last_subfile
!= current_subfile
|| end_sequence
)
18518 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
18519 m_address
, m_record_line_callback
);
18524 if (dwarf_record_line_p (m_line
, m_last_line
,
18525 m_line_has_non_zero_discriminator
,
18528 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
18530 m_record_line_callback
);
18532 m_last_subfile
= current_subfile
;
18533 m_last_line
= m_line
;
18539 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
18540 bool record_lines_p
)
18543 m_record_lines_p
= record_lines_p
;
18544 m_line_header
= lh
;
18546 m_record_line_callback
= ::record_line
;
18548 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
18549 was a line entry for it so that the backend has a chance to adjust it
18550 and also record it in case it needs it. This is currently used by MIPS
18551 code, cf. `mips_adjust_dwarf2_line'. */
18552 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
18553 m_is_stmt
= lh
->default_is_stmt
;
18554 m_discriminator
= 0;
18558 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
18559 const gdb_byte
*line_ptr
,
18560 CORE_ADDR lowpc
, CORE_ADDR address
)
18562 /* If address < lowpc then it's not a usable value, it's outside the
18563 pc range of the CU. However, we restrict the test to only address
18564 values of zero to preserve GDB's previous behaviour which is to
18565 handle the specific case of a function being GC'd by the linker. */
18567 if (address
== 0 && address
< lowpc
)
18569 /* This line table is for a function which has been
18570 GCd by the linker. Ignore it. PR gdb/12528 */
18572 struct objfile
*objfile
= cu
->objfile
;
18573 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
18575 complaint (&symfile_complaints
,
18576 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
18577 line_offset
, objfile_name (objfile
));
18578 m_record_line_callback
= noop_record_line
;
18579 /* Note: record_line_callback is left as noop_record_line until
18580 we see DW_LNE_end_sequence. */
18584 /* Subroutine of dwarf_decode_lines to simplify it.
18585 Process the line number information in LH.
18586 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
18587 program in order to set included_p for every referenced header. */
18590 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
18591 const int decode_for_pst_p
, CORE_ADDR lowpc
)
18593 const gdb_byte
*line_ptr
, *extended_end
;
18594 const gdb_byte
*line_end
;
18595 unsigned int bytes_read
, extended_len
;
18596 unsigned char op_code
, extended_op
;
18597 CORE_ADDR baseaddr
;
18598 struct objfile
*objfile
= cu
->objfile
;
18599 bfd
*abfd
= objfile
->obfd
;
18600 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18601 /* True if we're recording line info (as opposed to building partial
18602 symtabs and just interested in finding include files mentioned by
18603 the line number program). */
18604 bool record_lines_p
= !decode_for_pst_p
;
18606 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18608 line_ptr
= lh
->statement_program_start
;
18609 line_end
= lh
->statement_program_end
;
18611 /* Read the statement sequences until there's nothing left. */
18612 while (line_ptr
< line_end
)
18614 /* The DWARF line number program state machine. Reset the state
18615 machine at the start of each sequence. */
18616 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
18617 bool end_sequence
= false;
18619 if (record_lines_p
)
18621 /* Start a subfile for the current file of the state
18623 const file_entry
*fe
= state_machine
.current_file ();
18626 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
18629 /* Decode the table. */
18630 while (line_ptr
< line_end
&& !end_sequence
)
18632 op_code
= read_1_byte (abfd
, line_ptr
);
18635 if (op_code
>= lh
->opcode_base
)
18637 /* Special opcode. */
18638 state_machine
.handle_special_opcode (op_code
);
18640 else switch (op_code
)
18642 case DW_LNS_extended_op
:
18643 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
18645 line_ptr
+= bytes_read
;
18646 extended_end
= line_ptr
+ extended_len
;
18647 extended_op
= read_1_byte (abfd
, line_ptr
);
18649 switch (extended_op
)
18651 case DW_LNE_end_sequence
:
18652 state_machine
.handle_end_sequence ();
18653 end_sequence
= true;
18655 case DW_LNE_set_address
:
18658 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
18659 line_ptr
+= bytes_read
;
18661 state_machine
.check_line_address (cu
, line_ptr
,
18663 state_machine
.handle_set_address (baseaddr
, address
);
18666 case DW_LNE_define_file
:
18668 const char *cur_file
;
18669 unsigned int mod_time
, length
;
18672 cur_file
= read_direct_string (abfd
, line_ptr
,
18674 line_ptr
+= bytes_read
;
18675 dindex
= (dir_index
)
18676 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18677 line_ptr
+= bytes_read
;
18679 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18680 line_ptr
+= bytes_read
;
18682 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18683 line_ptr
+= bytes_read
;
18684 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
18687 case DW_LNE_set_discriminator
:
18689 /* The discriminator is not interesting to the
18690 debugger; just ignore it. We still need to
18691 check its value though:
18692 if there are consecutive entries for the same
18693 (non-prologue) line we want to coalesce them.
18696 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18697 line_ptr
+= bytes_read
;
18699 state_machine
.handle_set_discriminator (discr
);
18703 complaint (&symfile_complaints
,
18704 _("mangled .debug_line section"));
18707 /* Make sure that we parsed the extended op correctly. If e.g.
18708 we expected a different address size than the producer used,
18709 we may have read the wrong number of bytes. */
18710 if (line_ptr
!= extended_end
)
18712 complaint (&symfile_complaints
,
18713 _("mangled .debug_line section"));
18718 state_machine
.handle_copy ();
18720 case DW_LNS_advance_pc
:
18723 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18724 line_ptr
+= bytes_read
;
18726 state_machine
.handle_advance_pc (adjust
);
18729 case DW_LNS_advance_line
:
18732 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
18733 line_ptr
+= bytes_read
;
18735 state_machine
.handle_advance_line (line_delta
);
18738 case DW_LNS_set_file
:
18740 file_name_index file
18741 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
18743 line_ptr
+= bytes_read
;
18745 state_machine
.handle_set_file (file
);
18748 case DW_LNS_set_column
:
18749 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18750 line_ptr
+= bytes_read
;
18752 case DW_LNS_negate_stmt
:
18753 state_machine
.handle_negate_stmt ();
18755 case DW_LNS_set_basic_block
:
18757 /* Add to the address register of the state machine the
18758 address increment value corresponding to special opcode
18759 255. I.e., this value is scaled by the minimum
18760 instruction length since special opcode 255 would have
18761 scaled the increment. */
18762 case DW_LNS_const_add_pc
:
18763 state_machine
.handle_const_add_pc ();
18765 case DW_LNS_fixed_advance_pc
:
18767 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
18770 state_machine
.handle_fixed_advance_pc (addr_adj
);
18775 /* Unknown standard opcode, ignore it. */
18778 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
18780 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18781 line_ptr
+= bytes_read
;
18788 dwarf2_debug_line_missing_end_sequence_complaint ();
18790 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
18791 in which case we still finish recording the last line). */
18792 state_machine
.record_line (true);
18796 /* Decode the Line Number Program (LNP) for the given line_header
18797 structure and CU. The actual information extracted and the type
18798 of structures created from the LNP depends on the value of PST.
18800 1. If PST is NULL, then this procedure uses the data from the program
18801 to create all necessary symbol tables, and their linetables.
18803 2. If PST is not NULL, this procedure reads the program to determine
18804 the list of files included by the unit represented by PST, and
18805 builds all the associated partial symbol tables.
18807 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
18808 It is used for relative paths in the line table.
18809 NOTE: When processing partial symtabs (pst != NULL),
18810 comp_dir == pst->dirname.
18812 NOTE: It is important that psymtabs have the same file name (via strcmp)
18813 as the corresponding symtab. Since COMP_DIR is not used in the name of the
18814 symtab we don't use it in the name of the psymtabs we create.
18815 E.g. expand_line_sal requires this when finding psymtabs to expand.
18816 A good testcase for this is mb-inline.exp.
18818 LOWPC is the lowest address in CU (or 0 if not known).
18820 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
18821 for its PC<->lines mapping information. Otherwise only the filename
18822 table is read in. */
18825 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
18826 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
18827 CORE_ADDR lowpc
, int decode_mapping
)
18829 struct objfile
*objfile
= cu
->objfile
;
18830 const int decode_for_pst_p
= (pst
!= NULL
);
18832 if (decode_mapping
)
18833 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
18835 if (decode_for_pst_p
)
18839 /* Now that we're done scanning the Line Header Program, we can
18840 create the psymtab of each included file. */
18841 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
18842 if (lh
->file_names
[file_index
].included_p
== 1)
18844 const char *include_name
=
18845 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
18846 if (include_name
!= NULL
)
18847 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
18852 /* Make sure a symtab is created for every file, even files
18853 which contain only variables (i.e. no code with associated
18855 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
18858 for (i
= 0; i
< lh
->file_names
.size (); i
++)
18860 file_entry
&fe
= lh
->file_names
[i
];
18862 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
18864 if (current_subfile
->symtab
== NULL
)
18866 current_subfile
->symtab
18867 = allocate_symtab (cust
, current_subfile
->name
);
18869 fe
.symtab
= current_subfile
->symtab
;
18874 /* Start a subfile for DWARF. FILENAME is the name of the file and
18875 DIRNAME the name of the source directory which contains FILENAME
18876 or NULL if not known.
18877 This routine tries to keep line numbers from identical absolute and
18878 relative file names in a common subfile.
18880 Using the `list' example from the GDB testsuite, which resides in
18881 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
18882 of /srcdir/list0.c yields the following debugging information for list0.c:
18884 DW_AT_name: /srcdir/list0.c
18885 DW_AT_comp_dir: /compdir
18886 files.files[0].name: list0.h
18887 files.files[0].dir: /srcdir
18888 files.files[1].name: list0.c
18889 files.files[1].dir: /srcdir
18891 The line number information for list0.c has to end up in a single
18892 subfile, so that `break /srcdir/list0.c:1' works as expected.
18893 start_subfile will ensure that this happens provided that we pass the
18894 concatenation of files.files[1].dir and files.files[1].name as the
18898 dwarf2_start_subfile (const char *filename
, const char *dirname
)
18902 /* In order not to lose the line information directory,
18903 we concatenate it to the filename when it makes sense.
18904 Note that the Dwarf3 standard says (speaking of filenames in line
18905 information): ``The directory index is ignored for file names
18906 that represent full path names''. Thus ignoring dirname in the
18907 `else' branch below isn't an issue. */
18909 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
18911 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
18915 start_subfile (filename
);
18921 /* Start a symtab for DWARF.
18922 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
18924 static struct compunit_symtab
*
18925 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
18926 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
18928 struct compunit_symtab
*cust
18929 = start_symtab (cu
->objfile
, name
, comp_dir
, low_pc
);
18931 record_debugformat ("DWARF 2");
18932 record_producer (cu
->producer
);
18934 /* We assume that we're processing GCC output. */
18935 processing_gcc_compilation
= 2;
18937 cu
->processing_has_namespace_info
= 0;
18943 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
18944 struct dwarf2_cu
*cu
)
18946 struct objfile
*objfile
= cu
->objfile
;
18947 struct comp_unit_head
*cu_header
= &cu
->header
;
18949 /* NOTE drow/2003-01-30: There used to be a comment and some special
18950 code here to turn a symbol with DW_AT_external and a
18951 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
18952 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
18953 with some versions of binutils) where shared libraries could have
18954 relocations against symbols in their debug information - the
18955 minimal symbol would have the right address, but the debug info
18956 would not. It's no longer necessary, because we will explicitly
18957 apply relocations when we read in the debug information now. */
18959 /* A DW_AT_location attribute with no contents indicates that a
18960 variable has been optimized away. */
18961 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
18963 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
18967 /* Handle one degenerate form of location expression specially, to
18968 preserve GDB's previous behavior when section offsets are
18969 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
18970 then mark this symbol as LOC_STATIC. */
18972 if (attr_form_is_block (attr
)
18973 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
18974 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
18975 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
18976 && (DW_BLOCK (attr
)->size
18977 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
18979 unsigned int dummy
;
18981 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
18982 SYMBOL_VALUE_ADDRESS (sym
) =
18983 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
18985 SYMBOL_VALUE_ADDRESS (sym
) =
18986 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
18987 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
18988 fixup_symbol_section (sym
, objfile
);
18989 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
18990 SYMBOL_SECTION (sym
));
18994 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
18995 expression evaluator, and use LOC_COMPUTED only when necessary
18996 (i.e. when the value of a register or memory location is
18997 referenced, or a thread-local block, etc.). Then again, it might
18998 not be worthwhile. I'm assuming that it isn't unless performance
18999 or memory numbers show me otherwise. */
19001 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
19003 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
19004 cu
->has_loclist
= 1;
19007 /* Given a pointer to a DWARF information entry, figure out if we need
19008 to make a symbol table entry for it, and if so, create a new entry
19009 and return a pointer to it.
19010 If TYPE is NULL, determine symbol type from the die, otherwise
19011 used the passed type.
19012 If SPACE is not NULL, use it to hold the new symbol. If it is
19013 NULL, allocate a new symbol on the objfile's obstack. */
19015 static struct symbol
*
19016 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
19017 struct symbol
*space
)
19019 struct objfile
*objfile
= cu
->objfile
;
19020 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19021 struct symbol
*sym
= NULL
;
19023 struct attribute
*attr
= NULL
;
19024 struct attribute
*attr2
= NULL
;
19025 CORE_ADDR baseaddr
;
19026 struct pending
**list_to_add
= NULL
;
19028 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
19030 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19032 name
= dwarf2_name (die
, cu
);
19035 const char *linkagename
;
19036 int suppress_add
= 0;
19041 sym
= allocate_symbol (objfile
);
19042 OBJSTAT (objfile
, n_syms
++);
19044 /* Cache this symbol's name and the name's demangled form (if any). */
19045 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
19046 linkagename
= dwarf2_physname (name
, die
, cu
);
19047 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
19049 /* Fortran does not have mangling standard and the mangling does differ
19050 between gfortran, iFort etc. */
19051 if (cu
->language
== language_fortran
19052 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
19053 symbol_set_demangled_name (&(sym
->ginfo
),
19054 dwarf2_full_name (name
, die
, cu
),
19057 /* Default assumptions.
19058 Use the passed type or decode it from the die. */
19059 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19060 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
19062 SYMBOL_TYPE (sym
) = type
;
19064 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
19065 attr
= dwarf2_attr (die
,
19066 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
19070 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
19073 attr
= dwarf2_attr (die
,
19074 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
19078 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
19079 struct file_entry
*fe
;
19081 if (cu
->line_header
!= NULL
)
19082 fe
= cu
->line_header
->file_name_at (file_index
);
19087 complaint (&symfile_complaints
,
19088 _("file index out of range"));
19090 symbol_set_symtab (sym
, fe
->symtab
);
19096 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
19101 addr
= attr_value_as_address (attr
);
19102 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
19103 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
19105 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
19106 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
19107 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
19108 add_symbol_to_list (sym
, cu
->list_in_scope
);
19110 case DW_TAG_subprogram
:
19111 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
19113 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
19114 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19115 if ((attr2
&& (DW_UNSND (attr2
) != 0))
19116 || cu
->language
== language_ada
)
19118 /* Subprograms marked external are stored as a global symbol.
19119 Ada subprograms, whether marked external or not, are always
19120 stored as a global symbol, because we want to be able to
19121 access them globally. For instance, we want to be able
19122 to break on a nested subprogram without having to
19123 specify the context. */
19124 list_to_add
= &global_symbols
;
19128 list_to_add
= cu
->list_in_scope
;
19131 case DW_TAG_inlined_subroutine
:
19132 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
19134 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
19135 SYMBOL_INLINED (sym
) = 1;
19136 list_to_add
= cu
->list_in_scope
;
19138 case DW_TAG_template_value_param
:
19140 /* Fall through. */
19141 case DW_TAG_constant
:
19142 case DW_TAG_variable
:
19143 case DW_TAG_member
:
19144 /* Compilation with minimal debug info may result in
19145 variables with missing type entries. Change the
19146 misleading `void' type to something sensible. */
19147 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
19148 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
19150 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19151 /* In the case of DW_TAG_member, we should only be called for
19152 static const members. */
19153 if (die
->tag
== DW_TAG_member
)
19155 /* dwarf2_add_field uses die_is_declaration,
19156 so we do the same. */
19157 gdb_assert (die_is_declaration (die
, cu
));
19162 dwarf2_const_value (attr
, sym
, cu
);
19163 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19166 if (attr2
&& (DW_UNSND (attr2
) != 0))
19167 list_to_add
= &global_symbols
;
19169 list_to_add
= cu
->list_in_scope
;
19173 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
19176 var_decode_location (attr
, sym
, cu
);
19177 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19179 /* Fortran explicitly imports any global symbols to the local
19180 scope by DW_TAG_common_block. */
19181 if (cu
->language
== language_fortran
&& die
->parent
19182 && die
->parent
->tag
== DW_TAG_common_block
)
19185 if (SYMBOL_CLASS (sym
) == LOC_STATIC
19186 && SYMBOL_VALUE_ADDRESS (sym
) == 0
19187 && !dwarf2_per_objfile
->has_section_at_zero
)
19189 /* When a static variable is eliminated by the linker,
19190 the corresponding debug information is not stripped
19191 out, but the variable address is set to null;
19192 do not add such variables into symbol table. */
19194 else if (attr2
&& (DW_UNSND (attr2
) != 0))
19196 /* Workaround gfortran PR debug/40040 - it uses
19197 DW_AT_location for variables in -fPIC libraries which may
19198 get overriden by other libraries/executable and get
19199 a different address. Resolve it by the minimal symbol
19200 which may come from inferior's executable using copy
19201 relocation. Make this workaround only for gfortran as for
19202 other compilers GDB cannot guess the minimal symbol
19203 Fortran mangling kind. */
19204 if (cu
->language
== language_fortran
&& die
->parent
19205 && die
->parent
->tag
== DW_TAG_module
19207 && startswith (cu
->producer
, "GNU Fortran"))
19208 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
19210 /* A variable with DW_AT_external is never static,
19211 but it may be block-scoped. */
19212 list_to_add
= (cu
->list_in_scope
== &file_symbols
19213 ? &global_symbols
: cu
->list_in_scope
);
19216 list_to_add
= cu
->list_in_scope
;
19220 /* We do not know the address of this symbol.
19221 If it is an external symbol and we have type information
19222 for it, enter the symbol as a LOC_UNRESOLVED symbol.
19223 The address of the variable will then be determined from
19224 the minimal symbol table whenever the variable is
19226 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19228 /* Fortran explicitly imports any global symbols to the local
19229 scope by DW_TAG_common_block. */
19230 if (cu
->language
== language_fortran
&& die
->parent
19231 && die
->parent
->tag
== DW_TAG_common_block
)
19233 /* SYMBOL_CLASS doesn't matter here because
19234 read_common_block is going to reset it. */
19236 list_to_add
= cu
->list_in_scope
;
19238 else if (attr2
&& (DW_UNSND (attr2
) != 0)
19239 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
19241 /* A variable with DW_AT_external is never static, but it
19242 may be block-scoped. */
19243 list_to_add
= (cu
->list_in_scope
== &file_symbols
19244 ? &global_symbols
: cu
->list_in_scope
);
19246 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
19248 else if (!die_is_declaration (die
, cu
))
19250 /* Use the default LOC_OPTIMIZED_OUT class. */
19251 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
19253 list_to_add
= cu
->list_in_scope
;
19257 case DW_TAG_formal_parameter
:
19258 /* If we are inside a function, mark this as an argument. If
19259 not, we might be looking at an argument to an inlined function
19260 when we do not have enough information to show inlined frames;
19261 pretend it's a local variable in that case so that the user can
19263 if (context_stack_depth
> 0
19264 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
19265 SYMBOL_IS_ARGUMENT (sym
) = 1;
19266 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
19269 var_decode_location (attr
, sym
, cu
);
19271 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19274 dwarf2_const_value (attr
, sym
, cu
);
19277 list_to_add
= cu
->list_in_scope
;
19279 case DW_TAG_unspecified_parameters
:
19280 /* From varargs functions; gdb doesn't seem to have any
19281 interest in this information, so just ignore it for now.
19284 case DW_TAG_template_type_param
:
19286 /* Fall through. */
19287 case DW_TAG_class_type
:
19288 case DW_TAG_interface_type
:
19289 case DW_TAG_structure_type
:
19290 case DW_TAG_union_type
:
19291 case DW_TAG_set_type
:
19292 case DW_TAG_enumeration_type
:
19293 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19294 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
19297 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
19298 really ever be static objects: otherwise, if you try
19299 to, say, break of a class's method and you're in a file
19300 which doesn't mention that class, it won't work unless
19301 the check for all static symbols in lookup_symbol_aux
19302 saves you. See the OtherFileClass tests in
19303 gdb.c++/namespace.exp. */
19307 list_to_add
= (cu
->list_in_scope
== &file_symbols
19308 && cu
->language
== language_cplus
19309 ? &global_symbols
: cu
->list_in_scope
);
19311 /* The semantics of C++ state that "struct foo {
19312 ... }" also defines a typedef for "foo". */
19313 if (cu
->language
== language_cplus
19314 || cu
->language
== language_ada
19315 || cu
->language
== language_d
19316 || cu
->language
== language_rust
)
19318 /* The symbol's name is already allocated along
19319 with this objfile, so we don't need to
19320 duplicate it for the type. */
19321 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
19322 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
19327 case DW_TAG_typedef
:
19328 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19329 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19330 list_to_add
= cu
->list_in_scope
;
19332 case DW_TAG_base_type
:
19333 case DW_TAG_subrange_type
:
19334 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19335 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19336 list_to_add
= cu
->list_in_scope
;
19338 case DW_TAG_enumerator
:
19339 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19342 dwarf2_const_value (attr
, sym
, cu
);
19345 /* NOTE: carlton/2003-11-10: See comment above in the
19346 DW_TAG_class_type, etc. block. */
19348 list_to_add
= (cu
->list_in_scope
== &file_symbols
19349 && cu
->language
== language_cplus
19350 ? &global_symbols
: cu
->list_in_scope
);
19353 case DW_TAG_imported_declaration
:
19354 case DW_TAG_namespace
:
19355 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19356 list_to_add
= &global_symbols
;
19358 case DW_TAG_module
:
19359 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19360 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
19361 list_to_add
= &global_symbols
;
19363 case DW_TAG_common_block
:
19364 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
19365 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
19366 add_symbol_to_list (sym
, cu
->list_in_scope
);
19369 /* Not a tag we recognize. Hopefully we aren't processing
19370 trash data, but since we must specifically ignore things
19371 we don't recognize, there is nothing else we should do at
19373 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
19374 dwarf_tag_name (die
->tag
));
19380 sym
->hash_next
= objfile
->template_symbols
;
19381 objfile
->template_symbols
= sym
;
19382 list_to_add
= NULL
;
19385 if (list_to_add
!= NULL
)
19386 add_symbol_to_list (sym
, list_to_add
);
19388 /* For the benefit of old versions of GCC, check for anonymous
19389 namespaces based on the demangled name. */
19390 if (!cu
->processing_has_namespace_info
19391 && cu
->language
== language_cplus
)
19392 cp_scan_for_anonymous_namespaces (sym
, objfile
);
19397 /* A wrapper for new_symbol_full that always allocates a new symbol. */
19399 static struct symbol
*
19400 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
19402 return new_symbol_full (die
, type
, cu
, NULL
);
19405 /* Given an attr with a DW_FORM_dataN value in host byte order,
19406 zero-extend it as appropriate for the symbol's type. The DWARF
19407 standard (v4) is not entirely clear about the meaning of using
19408 DW_FORM_dataN for a constant with a signed type, where the type is
19409 wider than the data. The conclusion of a discussion on the DWARF
19410 list was that this is unspecified. We choose to always zero-extend
19411 because that is the interpretation long in use by GCC. */
19414 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
19415 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
19417 struct objfile
*objfile
= cu
->objfile
;
19418 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
19419 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
19420 LONGEST l
= DW_UNSND (attr
);
19422 if (bits
< sizeof (*value
) * 8)
19424 l
&= ((LONGEST
) 1 << bits
) - 1;
19427 else if (bits
== sizeof (*value
) * 8)
19431 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
19432 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
19439 /* Read a constant value from an attribute. Either set *VALUE, or if
19440 the value does not fit in *VALUE, set *BYTES - either already
19441 allocated on the objfile obstack, or newly allocated on OBSTACK,
19442 or, set *BATON, if we translated the constant to a location
19446 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
19447 const char *name
, struct obstack
*obstack
,
19448 struct dwarf2_cu
*cu
,
19449 LONGEST
*value
, const gdb_byte
**bytes
,
19450 struct dwarf2_locexpr_baton
**baton
)
19452 struct objfile
*objfile
= cu
->objfile
;
19453 struct comp_unit_head
*cu_header
= &cu
->header
;
19454 struct dwarf_block
*blk
;
19455 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
19456 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
19462 switch (attr
->form
)
19465 case DW_FORM_GNU_addr_index
:
19469 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
19470 dwarf2_const_value_length_mismatch_complaint (name
,
19471 cu_header
->addr_size
,
19472 TYPE_LENGTH (type
));
19473 /* Symbols of this form are reasonably rare, so we just
19474 piggyback on the existing location code rather than writing
19475 a new implementation of symbol_computed_ops. */
19476 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
19477 (*baton
)->per_cu
= cu
->per_cu
;
19478 gdb_assert ((*baton
)->per_cu
);
19480 (*baton
)->size
= 2 + cu_header
->addr_size
;
19481 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
19482 (*baton
)->data
= data
;
19484 data
[0] = DW_OP_addr
;
19485 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
19486 byte_order
, DW_ADDR (attr
));
19487 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
19490 case DW_FORM_string
:
19492 case DW_FORM_GNU_str_index
:
19493 case DW_FORM_GNU_strp_alt
:
19494 /* DW_STRING is already allocated on the objfile obstack, point
19496 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
19498 case DW_FORM_block1
:
19499 case DW_FORM_block2
:
19500 case DW_FORM_block4
:
19501 case DW_FORM_block
:
19502 case DW_FORM_exprloc
:
19503 case DW_FORM_data16
:
19504 blk
= DW_BLOCK (attr
);
19505 if (TYPE_LENGTH (type
) != blk
->size
)
19506 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
19507 TYPE_LENGTH (type
));
19508 *bytes
= blk
->data
;
19511 /* The DW_AT_const_value attributes are supposed to carry the
19512 symbol's value "represented as it would be on the target
19513 architecture." By the time we get here, it's already been
19514 converted to host endianness, so we just need to sign- or
19515 zero-extend it as appropriate. */
19516 case DW_FORM_data1
:
19517 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
19519 case DW_FORM_data2
:
19520 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
19522 case DW_FORM_data4
:
19523 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
19525 case DW_FORM_data8
:
19526 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
19529 case DW_FORM_sdata
:
19530 case DW_FORM_implicit_const
:
19531 *value
= DW_SND (attr
);
19534 case DW_FORM_udata
:
19535 *value
= DW_UNSND (attr
);
19539 complaint (&symfile_complaints
,
19540 _("unsupported const value attribute form: '%s'"),
19541 dwarf_form_name (attr
->form
));
19548 /* Copy constant value from an attribute to a symbol. */
19551 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
19552 struct dwarf2_cu
*cu
)
19554 struct objfile
*objfile
= cu
->objfile
;
19556 const gdb_byte
*bytes
;
19557 struct dwarf2_locexpr_baton
*baton
;
19559 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
19560 SYMBOL_PRINT_NAME (sym
),
19561 &objfile
->objfile_obstack
, cu
,
19562 &value
, &bytes
, &baton
);
19566 SYMBOL_LOCATION_BATON (sym
) = baton
;
19567 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
19569 else if (bytes
!= NULL
)
19571 SYMBOL_VALUE_BYTES (sym
) = bytes
;
19572 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
19576 SYMBOL_VALUE (sym
) = value
;
19577 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
19581 /* Return the type of the die in question using its DW_AT_type attribute. */
19583 static struct type
*
19584 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19586 struct attribute
*type_attr
;
19588 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
19591 /* A missing DW_AT_type represents a void type. */
19592 return objfile_type (cu
->objfile
)->builtin_void
;
19595 return lookup_die_type (die
, type_attr
, cu
);
19598 /* True iff CU's producer generates GNAT Ada auxiliary information
19599 that allows to find parallel types through that information instead
19600 of having to do expensive parallel lookups by type name. */
19603 need_gnat_info (struct dwarf2_cu
*cu
)
19605 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
19606 of GNAT produces this auxiliary information, without any indication
19607 that it is produced. Part of enhancing the FSF version of GNAT
19608 to produce that information will be to put in place an indicator
19609 that we can use in order to determine whether the descriptive type
19610 info is available or not. One suggestion that has been made is
19611 to use a new attribute, attached to the CU die. For now, assume
19612 that the descriptive type info is not available. */
19616 /* Return the auxiliary type of the die in question using its
19617 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
19618 attribute is not present. */
19620 static struct type
*
19621 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19623 struct attribute
*type_attr
;
19625 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
19629 return lookup_die_type (die
, type_attr
, cu
);
19632 /* If DIE has a descriptive_type attribute, then set the TYPE's
19633 descriptive type accordingly. */
19636 set_descriptive_type (struct type
*type
, struct die_info
*die
,
19637 struct dwarf2_cu
*cu
)
19639 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
19641 if (descriptive_type
)
19643 ALLOCATE_GNAT_AUX_TYPE (type
);
19644 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
19648 /* Return the containing type of the die in question using its
19649 DW_AT_containing_type attribute. */
19651 static struct type
*
19652 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19654 struct attribute
*type_attr
;
19656 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
19658 error (_("Dwarf Error: Problem turning containing type into gdb type "
19659 "[in module %s]"), objfile_name (cu
->objfile
));
19661 return lookup_die_type (die
, type_attr
, cu
);
19664 /* Return an error marker type to use for the ill formed type in DIE/CU. */
19666 static struct type
*
19667 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
19669 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19670 char *message
, *saved
;
19672 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
19673 objfile_name (objfile
),
19674 to_underlying (cu
->header
.sect_off
),
19675 to_underlying (die
->sect_off
));
19676 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
19677 message
, strlen (message
));
19680 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
19683 /* Look up the type of DIE in CU using its type attribute ATTR.
19684 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
19685 DW_AT_containing_type.
19686 If there is no type substitute an error marker. */
19688 static struct type
*
19689 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
19690 struct dwarf2_cu
*cu
)
19692 struct objfile
*objfile
= cu
->objfile
;
19693 struct type
*this_type
;
19695 gdb_assert (attr
->name
== DW_AT_type
19696 || attr
->name
== DW_AT_GNAT_descriptive_type
19697 || attr
->name
== DW_AT_containing_type
);
19699 /* First see if we have it cached. */
19701 if (attr
->form
== DW_FORM_GNU_ref_alt
)
19703 struct dwarf2_per_cu_data
*per_cu
;
19704 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
19706 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, cu
->objfile
);
19707 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
19709 else if (attr_form_is_ref (attr
))
19711 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
19713 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
19715 else if (attr
->form
== DW_FORM_ref_sig8
)
19717 ULONGEST signature
= DW_SIGNATURE (attr
);
19719 return get_signatured_type (die
, signature
, cu
);
19723 complaint (&symfile_complaints
,
19724 _("Dwarf Error: Bad type attribute %s in DIE"
19725 " at 0x%x [in module %s]"),
19726 dwarf_attr_name (attr
->name
), to_underlying (die
->sect_off
),
19727 objfile_name (objfile
));
19728 return build_error_marker_type (cu
, die
);
19731 /* If not cached we need to read it in. */
19733 if (this_type
== NULL
)
19735 struct die_info
*type_die
= NULL
;
19736 struct dwarf2_cu
*type_cu
= cu
;
19738 if (attr_form_is_ref (attr
))
19739 type_die
= follow_die_ref (die
, attr
, &type_cu
);
19740 if (type_die
== NULL
)
19741 return build_error_marker_type (cu
, die
);
19742 /* If we find the type now, it's probably because the type came
19743 from an inter-CU reference and the type's CU got expanded before
19745 this_type
= read_type_die (type_die
, type_cu
);
19748 /* If we still don't have a type use an error marker. */
19750 if (this_type
== NULL
)
19751 return build_error_marker_type (cu
, die
);
19756 /* Return the type in DIE, CU.
19757 Returns NULL for invalid types.
19759 This first does a lookup in die_type_hash,
19760 and only reads the die in if necessary.
19762 NOTE: This can be called when reading in partial or full symbols. */
19764 static struct type
*
19765 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
19767 struct type
*this_type
;
19769 this_type
= get_die_type (die
, cu
);
19773 return read_type_die_1 (die
, cu
);
19776 /* Read the type in DIE, CU.
19777 Returns NULL for invalid types. */
19779 static struct type
*
19780 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
19782 struct type
*this_type
= NULL
;
19786 case DW_TAG_class_type
:
19787 case DW_TAG_interface_type
:
19788 case DW_TAG_structure_type
:
19789 case DW_TAG_union_type
:
19790 this_type
= read_structure_type (die
, cu
);
19792 case DW_TAG_enumeration_type
:
19793 this_type
= read_enumeration_type (die
, cu
);
19795 case DW_TAG_subprogram
:
19796 case DW_TAG_subroutine_type
:
19797 case DW_TAG_inlined_subroutine
:
19798 this_type
= read_subroutine_type (die
, cu
);
19800 case DW_TAG_array_type
:
19801 this_type
= read_array_type (die
, cu
);
19803 case DW_TAG_set_type
:
19804 this_type
= read_set_type (die
, cu
);
19806 case DW_TAG_pointer_type
:
19807 this_type
= read_tag_pointer_type (die
, cu
);
19809 case DW_TAG_ptr_to_member_type
:
19810 this_type
= read_tag_ptr_to_member_type (die
, cu
);
19812 case DW_TAG_reference_type
:
19813 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
19815 case DW_TAG_rvalue_reference_type
:
19816 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
19818 case DW_TAG_const_type
:
19819 this_type
= read_tag_const_type (die
, cu
);
19821 case DW_TAG_volatile_type
:
19822 this_type
= read_tag_volatile_type (die
, cu
);
19824 case DW_TAG_restrict_type
:
19825 this_type
= read_tag_restrict_type (die
, cu
);
19827 case DW_TAG_string_type
:
19828 this_type
= read_tag_string_type (die
, cu
);
19830 case DW_TAG_typedef
:
19831 this_type
= read_typedef (die
, cu
);
19833 case DW_TAG_subrange_type
:
19834 this_type
= read_subrange_type (die
, cu
);
19836 case DW_TAG_base_type
:
19837 this_type
= read_base_type (die
, cu
);
19839 case DW_TAG_unspecified_type
:
19840 this_type
= read_unspecified_type (die
, cu
);
19842 case DW_TAG_namespace
:
19843 this_type
= read_namespace_type (die
, cu
);
19845 case DW_TAG_module
:
19846 this_type
= read_module_type (die
, cu
);
19848 case DW_TAG_atomic_type
:
19849 this_type
= read_tag_atomic_type (die
, cu
);
19852 complaint (&symfile_complaints
,
19853 _("unexpected tag in read_type_die: '%s'"),
19854 dwarf_tag_name (die
->tag
));
19861 /* See if we can figure out if the class lives in a namespace. We do
19862 this by looking for a member function; its demangled name will
19863 contain namespace info, if there is any.
19864 Return the computed name or NULL.
19865 Space for the result is allocated on the objfile's obstack.
19866 This is the full-die version of guess_partial_die_structure_name.
19867 In this case we know DIE has no useful parent. */
19870 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19872 struct die_info
*spec_die
;
19873 struct dwarf2_cu
*spec_cu
;
19874 struct die_info
*child
;
19877 spec_die
= die_specification (die
, &spec_cu
);
19878 if (spec_die
!= NULL
)
19884 for (child
= die
->child
;
19886 child
= child
->sibling
)
19888 if (child
->tag
== DW_TAG_subprogram
)
19890 const char *linkage_name
= dw2_linkage_name (child
, cu
);
19892 if (linkage_name
!= NULL
)
19895 = language_class_name_from_physname (cu
->language_defn
,
19899 if (actual_name
!= NULL
)
19901 const char *die_name
= dwarf2_name (die
, cu
);
19903 if (die_name
!= NULL
19904 && strcmp (die_name
, actual_name
) != 0)
19906 /* Strip off the class name from the full name.
19907 We want the prefix. */
19908 int die_name_len
= strlen (die_name
);
19909 int actual_name_len
= strlen (actual_name
);
19911 /* Test for '::' as a sanity check. */
19912 if (actual_name_len
> die_name_len
+ 2
19913 && actual_name
[actual_name_len
19914 - die_name_len
- 1] == ':')
19915 name
= (char *) obstack_copy0 (
19916 &cu
->objfile
->per_bfd
->storage_obstack
,
19917 actual_name
, actual_name_len
- die_name_len
- 2);
19920 xfree (actual_name
);
19929 /* GCC might emit a nameless typedef that has a linkage name. Determine the
19930 prefix part in such case. See
19931 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19933 static const char *
19934 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19936 struct attribute
*attr
;
19939 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
19940 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
19943 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
19946 attr
= dw2_linkage_name_attr (die
, cu
);
19947 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
19950 /* dwarf2_name had to be already called. */
19951 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
19953 /* Strip the base name, keep any leading namespaces/classes. */
19954 base
= strrchr (DW_STRING (attr
), ':');
19955 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
19958 return (char *) obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
19960 &base
[-1] - DW_STRING (attr
));
19963 /* Return the name of the namespace/class that DIE is defined within,
19964 or "" if we can't tell. The caller should not xfree the result.
19966 For example, if we're within the method foo() in the following
19976 then determine_prefix on foo's die will return "N::C". */
19978 static const char *
19979 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19981 struct die_info
*parent
, *spec_die
;
19982 struct dwarf2_cu
*spec_cu
;
19983 struct type
*parent_type
;
19984 const char *retval
;
19986 if (cu
->language
!= language_cplus
19987 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
19988 && cu
->language
!= language_rust
)
19991 retval
= anonymous_struct_prefix (die
, cu
);
19995 /* We have to be careful in the presence of DW_AT_specification.
19996 For example, with GCC 3.4, given the code
20000 // Definition of N::foo.
20004 then we'll have a tree of DIEs like this:
20006 1: DW_TAG_compile_unit
20007 2: DW_TAG_namespace // N
20008 3: DW_TAG_subprogram // declaration of N::foo
20009 4: DW_TAG_subprogram // definition of N::foo
20010 DW_AT_specification // refers to die #3
20012 Thus, when processing die #4, we have to pretend that we're in
20013 the context of its DW_AT_specification, namely the contex of die
20016 spec_die
= die_specification (die
, &spec_cu
);
20017 if (spec_die
== NULL
)
20018 parent
= die
->parent
;
20021 parent
= spec_die
->parent
;
20025 if (parent
== NULL
)
20027 else if (parent
->building_fullname
)
20030 const char *parent_name
;
20032 /* It has been seen on RealView 2.2 built binaries,
20033 DW_TAG_template_type_param types actually _defined_ as
20034 children of the parent class:
20037 template class <class Enum> Class{};
20038 Class<enum E> class_e;
20040 1: DW_TAG_class_type (Class)
20041 2: DW_TAG_enumeration_type (E)
20042 3: DW_TAG_enumerator (enum1:0)
20043 3: DW_TAG_enumerator (enum2:1)
20045 2: DW_TAG_template_type_param
20046 DW_AT_type DW_FORM_ref_udata (E)
20048 Besides being broken debug info, it can put GDB into an
20049 infinite loop. Consider:
20051 When we're building the full name for Class<E>, we'll start
20052 at Class, and go look over its template type parameters,
20053 finding E. We'll then try to build the full name of E, and
20054 reach here. We're now trying to build the full name of E,
20055 and look over the parent DIE for containing scope. In the
20056 broken case, if we followed the parent DIE of E, we'd again
20057 find Class, and once again go look at its template type
20058 arguments, etc., etc. Simply don't consider such parent die
20059 as source-level parent of this die (it can't be, the language
20060 doesn't allow it), and break the loop here. */
20061 name
= dwarf2_name (die
, cu
);
20062 parent_name
= dwarf2_name (parent
, cu
);
20063 complaint (&symfile_complaints
,
20064 _("template param type '%s' defined within parent '%s'"),
20065 name
? name
: "<unknown>",
20066 parent_name
? parent_name
: "<unknown>");
20070 switch (parent
->tag
)
20072 case DW_TAG_namespace
:
20073 parent_type
= read_type_die (parent
, cu
);
20074 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
20075 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
20076 Work around this problem here. */
20077 if (cu
->language
== language_cplus
20078 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
20080 /* We give a name to even anonymous namespaces. */
20081 return TYPE_TAG_NAME (parent_type
);
20082 case DW_TAG_class_type
:
20083 case DW_TAG_interface_type
:
20084 case DW_TAG_structure_type
:
20085 case DW_TAG_union_type
:
20086 case DW_TAG_module
:
20087 parent_type
= read_type_die (parent
, cu
);
20088 if (TYPE_TAG_NAME (parent_type
) != NULL
)
20089 return TYPE_TAG_NAME (parent_type
);
20091 /* An anonymous structure is only allowed non-static data
20092 members; no typedefs, no member functions, et cetera.
20093 So it does not need a prefix. */
20095 case DW_TAG_compile_unit
:
20096 case DW_TAG_partial_unit
:
20097 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
20098 if (cu
->language
== language_cplus
20099 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
20100 && die
->child
!= NULL
20101 && (die
->tag
== DW_TAG_class_type
20102 || die
->tag
== DW_TAG_structure_type
20103 || die
->tag
== DW_TAG_union_type
))
20105 char *name
= guess_full_die_structure_name (die
, cu
);
20110 case DW_TAG_enumeration_type
:
20111 parent_type
= read_type_die (parent
, cu
);
20112 if (TYPE_DECLARED_CLASS (parent_type
))
20114 if (TYPE_TAG_NAME (parent_type
) != NULL
)
20115 return TYPE_TAG_NAME (parent_type
);
20118 /* Fall through. */
20120 return determine_prefix (parent
, cu
);
20124 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
20125 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
20126 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
20127 an obconcat, otherwise allocate storage for the result. The CU argument is
20128 used to determine the language and hence, the appropriate separator. */
20130 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
20133 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
20134 int physname
, struct dwarf2_cu
*cu
)
20136 const char *lead
= "";
20139 if (suffix
== NULL
|| suffix
[0] == '\0'
20140 || prefix
== NULL
|| prefix
[0] == '\0')
20142 else if (cu
->language
== language_d
)
20144 /* For D, the 'main' function could be defined in any module, but it
20145 should never be prefixed. */
20146 if (strcmp (suffix
, "D main") == 0)
20154 else if (cu
->language
== language_fortran
&& physname
)
20156 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
20157 DW_AT_MIPS_linkage_name is preferred and used instead. */
20165 if (prefix
== NULL
)
20167 if (suffix
== NULL
)
20174 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
20176 strcpy (retval
, lead
);
20177 strcat (retval
, prefix
);
20178 strcat (retval
, sep
);
20179 strcat (retval
, suffix
);
20184 /* We have an obstack. */
20185 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
20189 /* Return sibling of die, NULL if no sibling. */
20191 static struct die_info
*
20192 sibling_die (struct die_info
*die
)
20194 return die
->sibling
;
20197 /* Get name of a die, return NULL if not found. */
20199 static const char *
20200 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
20201 struct obstack
*obstack
)
20203 if (name
&& cu
->language
== language_cplus
)
20205 std::string canon_name
= cp_canonicalize_string (name
);
20207 if (!canon_name
.empty ())
20209 if (canon_name
!= name
)
20210 name
= (const char *) obstack_copy0 (obstack
,
20211 canon_name
.c_str (),
20212 canon_name
.length ());
20219 /* Get name of a die, return NULL if not found.
20220 Anonymous namespaces are converted to their magic string. */
20222 static const char *
20223 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20225 struct attribute
*attr
;
20227 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
20228 if ((!attr
|| !DW_STRING (attr
))
20229 && die
->tag
!= DW_TAG_namespace
20230 && die
->tag
!= DW_TAG_class_type
20231 && die
->tag
!= DW_TAG_interface_type
20232 && die
->tag
!= DW_TAG_structure_type
20233 && die
->tag
!= DW_TAG_union_type
)
20238 case DW_TAG_compile_unit
:
20239 case DW_TAG_partial_unit
:
20240 /* Compilation units have a DW_AT_name that is a filename, not
20241 a source language identifier. */
20242 case DW_TAG_enumeration_type
:
20243 case DW_TAG_enumerator
:
20244 /* These tags always have simple identifiers already; no need
20245 to canonicalize them. */
20246 return DW_STRING (attr
);
20248 case DW_TAG_namespace
:
20249 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
20250 return DW_STRING (attr
);
20251 return CP_ANONYMOUS_NAMESPACE_STR
;
20253 case DW_TAG_class_type
:
20254 case DW_TAG_interface_type
:
20255 case DW_TAG_structure_type
:
20256 case DW_TAG_union_type
:
20257 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
20258 structures or unions. These were of the form "._%d" in GCC 4.1,
20259 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
20260 and GCC 4.4. We work around this problem by ignoring these. */
20261 if (attr
&& DW_STRING (attr
)
20262 && (startswith (DW_STRING (attr
), "._")
20263 || startswith (DW_STRING (attr
), "<anonymous")))
20266 /* GCC might emit a nameless typedef that has a linkage name. See
20267 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20268 if (!attr
|| DW_STRING (attr
) == NULL
)
20270 char *demangled
= NULL
;
20272 attr
= dw2_linkage_name_attr (die
, cu
);
20273 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
20276 /* Avoid demangling DW_STRING (attr) the second time on a second
20277 call for the same DIE. */
20278 if (!DW_STRING_IS_CANONICAL (attr
))
20279 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
20285 /* FIXME: we already did this for the partial symbol... */
20288 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
20289 demangled
, strlen (demangled
)));
20290 DW_STRING_IS_CANONICAL (attr
) = 1;
20293 /* Strip any leading namespaces/classes, keep only the base name.
20294 DW_AT_name for named DIEs does not contain the prefixes. */
20295 base
= strrchr (DW_STRING (attr
), ':');
20296 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
20299 return DW_STRING (attr
);
20308 if (!DW_STRING_IS_CANONICAL (attr
))
20311 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
20312 &cu
->objfile
->per_bfd
->storage_obstack
);
20313 DW_STRING_IS_CANONICAL (attr
) = 1;
20315 return DW_STRING (attr
);
20318 /* Return the die that this die in an extension of, or NULL if there
20319 is none. *EXT_CU is the CU containing DIE on input, and the CU
20320 containing the return value on output. */
20322 static struct die_info
*
20323 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
20325 struct attribute
*attr
;
20327 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
20331 return follow_die_ref (die
, attr
, ext_cu
);
20334 /* Convert a DIE tag into its string name. */
20336 static const char *
20337 dwarf_tag_name (unsigned tag
)
20339 const char *name
= get_DW_TAG_name (tag
);
20342 return "DW_TAG_<unknown>";
20347 /* Convert a DWARF attribute code into its string name. */
20349 static const char *
20350 dwarf_attr_name (unsigned attr
)
20354 #ifdef MIPS /* collides with DW_AT_HP_block_index */
20355 if (attr
== DW_AT_MIPS_fde
)
20356 return "DW_AT_MIPS_fde";
20358 if (attr
== DW_AT_HP_block_index
)
20359 return "DW_AT_HP_block_index";
20362 name
= get_DW_AT_name (attr
);
20365 return "DW_AT_<unknown>";
20370 /* Convert a DWARF value form code into its string name. */
20372 static const char *
20373 dwarf_form_name (unsigned form
)
20375 const char *name
= get_DW_FORM_name (form
);
20378 return "DW_FORM_<unknown>";
20383 static const char *
20384 dwarf_bool_name (unsigned mybool
)
20392 /* Convert a DWARF type code into its string name. */
20394 static const char *
20395 dwarf_type_encoding_name (unsigned enc
)
20397 const char *name
= get_DW_ATE_name (enc
);
20400 return "DW_ATE_<unknown>";
20406 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
20410 print_spaces (indent
, f
);
20411 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
20412 dwarf_tag_name (die
->tag
), die
->abbrev
,
20413 to_underlying (die
->sect_off
));
20415 if (die
->parent
!= NULL
)
20417 print_spaces (indent
, f
);
20418 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
20419 to_underlying (die
->parent
->sect_off
));
20422 print_spaces (indent
, f
);
20423 fprintf_unfiltered (f
, " has children: %s\n",
20424 dwarf_bool_name (die
->child
!= NULL
));
20426 print_spaces (indent
, f
);
20427 fprintf_unfiltered (f
, " attributes:\n");
20429 for (i
= 0; i
< die
->num_attrs
; ++i
)
20431 print_spaces (indent
, f
);
20432 fprintf_unfiltered (f
, " %s (%s) ",
20433 dwarf_attr_name (die
->attrs
[i
].name
),
20434 dwarf_form_name (die
->attrs
[i
].form
));
20436 switch (die
->attrs
[i
].form
)
20439 case DW_FORM_GNU_addr_index
:
20440 fprintf_unfiltered (f
, "address: ");
20441 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
20443 case DW_FORM_block2
:
20444 case DW_FORM_block4
:
20445 case DW_FORM_block
:
20446 case DW_FORM_block1
:
20447 fprintf_unfiltered (f
, "block: size %s",
20448 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
20450 case DW_FORM_exprloc
:
20451 fprintf_unfiltered (f
, "expression: size %s",
20452 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
20454 case DW_FORM_data16
:
20455 fprintf_unfiltered (f
, "constant of 16 bytes");
20457 case DW_FORM_ref_addr
:
20458 fprintf_unfiltered (f
, "ref address: ");
20459 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
20461 case DW_FORM_GNU_ref_alt
:
20462 fprintf_unfiltered (f
, "alt ref address: ");
20463 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
20469 case DW_FORM_ref_udata
:
20470 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
20471 (long) (DW_UNSND (&die
->attrs
[i
])));
20473 case DW_FORM_data1
:
20474 case DW_FORM_data2
:
20475 case DW_FORM_data4
:
20476 case DW_FORM_data8
:
20477 case DW_FORM_udata
:
20478 case DW_FORM_sdata
:
20479 fprintf_unfiltered (f
, "constant: %s",
20480 pulongest (DW_UNSND (&die
->attrs
[i
])));
20482 case DW_FORM_sec_offset
:
20483 fprintf_unfiltered (f
, "section offset: %s",
20484 pulongest (DW_UNSND (&die
->attrs
[i
])));
20486 case DW_FORM_ref_sig8
:
20487 fprintf_unfiltered (f
, "signature: %s",
20488 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
20490 case DW_FORM_string
:
20492 case DW_FORM_line_strp
:
20493 case DW_FORM_GNU_str_index
:
20494 case DW_FORM_GNU_strp_alt
:
20495 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
20496 DW_STRING (&die
->attrs
[i
])
20497 ? DW_STRING (&die
->attrs
[i
]) : "",
20498 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
20501 if (DW_UNSND (&die
->attrs
[i
]))
20502 fprintf_unfiltered (f
, "flag: TRUE");
20504 fprintf_unfiltered (f
, "flag: FALSE");
20506 case DW_FORM_flag_present
:
20507 fprintf_unfiltered (f
, "flag: TRUE");
20509 case DW_FORM_indirect
:
20510 /* The reader will have reduced the indirect form to
20511 the "base form" so this form should not occur. */
20512 fprintf_unfiltered (f
,
20513 "unexpected attribute form: DW_FORM_indirect");
20515 case DW_FORM_implicit_const
:
20516 fprintf_unfiltered (f
, "constant: %s",
20517 plongest (DW_SND (&die
->attrs
[i
])));
20520 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
20521 die
->attrs
[i
].form
);
20524 fprintf_unfiltered (f
, "\n");
20529 dump_die_for_error (struct die_info
*die
)
20531 dump_die_shallow (gdb_stderr
, 0, die
);
20535 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
20537 int indent
= level
* 4;
20539 gdb_assert (die
!= NULL
);
20541 if (level
>= max_level
)
20544 dump_die_shallow (f
, indent
, die
);
20546 if (die
->child
!= NULL
)
20548 print_spaces (indent
, f
);
20549 fprintf_unfiltered (f
, " Children:");
20550 if (level
+ 1 < max_level
)
20552 fprintf_unfiltered (f
, "\n");
20553 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
20557 fprintf_unfiltered (f
,
20558 " [not printed, max nesting level reached]\n");
20562 if (die
->sibling
!= NULL
&& level
> 0)
20564 dump_die_1 (f
, level
, max_level
, die
->sibling
);
20568 /* This is called from the pdie macro in gdbinit.in.
20569 It's not static so gcc will keep a copy callable from gdb. */
20572 dump_die (struct die_info
*die
, int max_level
)
20574 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
20578 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
20582 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
20583 to_underlying (die
->sect_off
),
20589 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
20593 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
20595 if (attr_form_is_ref (attr
))
20596 return (sect_offset
) DW_UNSND (attr
);
20598 complaint (&symfile_complaints
,
20599 _("unsupported die ref attribute form: '%s'"),
20600 dwarf_form_name (attr
->form
));
20604 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
20605 * the value held by the attribute is not constant. */
20608 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
20610 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
20611 return DW_SND (attr
);
20612 else if (attr
->form
== DW_FORM_udata
20613 || attr
->form
== DW_FORM_data1
20614 || attr
->form
== DW_FORM_data2
20615 || attr
->form
== DW_FORM_data4
20616 || attr
->form
== DW_FORM_data8
)
20617 return DW_UNSND (attr
);
20620 /* For DW_FORM_data16 see attr_form_is_constant. */
20621 complaint (&symfile_complaints
,
20622 _("Attribute value is not a constant (%s)"),
20623 dwarf_form_name (attr
->form
));
20624 return default_value
;
20628 /* Follow reference or signature attribute ATTR of SRC_DIE.
20629 On entry *REF_CU is the CU of SRC_DIE.
20630 On exit *REF_CU is the CU of the result. */
20632 static struct die_info
*
20633 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20634 struct dwarf2_cu
**ref_cu
)
20636 struct die_info
*die
;
20638 if (attr_form_is_ref (attr
))
20639 die
= follow_die_ref (src_die
, attr
, ref_cu
);
20640 else if (attr
->form
== DW_FORM_ref_sig8
)
20641 die
= follow_die_sig (src_die
, attr
, ref_cu
);
20644 dump_die_for_error (src_die
);
20645 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
20646 objfile_name ((*ref_cu
)->objfile
));
20652 /* Follow reference OFFSET.
20653 On entry *REF_CU is the CU of the source die referencing OFFSET.
20654 On exit *REF_CU is the CU of the result.
20655 Returns NULL if OFFSET is invalid. */
20657 static struct die_info
*
20658 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
20659 struct dwarf2_cu
**ref_cu
)
20661 struct die_info temp_die
;
20662 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
20664 gdb_assert (cu
->per_cu
!= NULL
);
20668 if (cu
->per_cu
->is_debug_types
)
20670 /* .debug_types CUs cannot reference anything outside their CU.
20671 If they need to, they have to reference a signatured type via
20672 DW_FORM_ref_sig8. */
20673 if (!offset_in_cu_p (&cu
->header
, sect_off
))
20676 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
20677 || !offset_in_cu_p (&cu
->header
, sect_off
))
20679 struct dwarf2_per_cu_data
*per_cu
;
20681 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
20684 /* If necessary, add it to the queue and load its DIEs. */
20685 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
20686 load_full_comp_unit (per_cu
, cu
->language
);
20688 target_cu
= per_cu
->cu
;
20690 else if (cu
->dies
== NULL
)
20692 /* We're loading full DIEs during partial symbol reading. */
20693 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
20694 load_full_comp_unit (cu
->per_cu
, language_minimal
);
20697 *ref_cu
= target_cu
;
20698 temp_die
.sect_off
= sect_off
;
20699 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
20701 to_underlying (sect_off
));
20704 /* Follow reference attribute ATTR of SRC_DIE.
20705 On entry *REF_CU is the CU of SRC_DIE.
20706 On exit *REF_CU is the CU of the result. */
20708 static struct die_info
*
20709 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
20710 struct dwarf2_cu
**ref_cu
)
20712 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
20713 struct dwarf2_cu
*cu
= *ref_cu
;
20714 struct die_info
*die
;
20716 die
= follow_die_offset (sect_off
,
20717 (attr
->form
== DW_FORM_GNU_ref_alt
20718 || cu
->per_cu
->is_dwz
),
20721 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
20722 "at 0x%x [in module %s]"),
20723 to_underlying (sect_off
), to_underlying (src_die
->sect_off
),
20724 objfile_name (cu
->objfile
));
20729 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
20730 Returned value is intended for DW_OP_call*. Returned
20731 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
20733 struct dwarf2_locexpr_baton
20734 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
20735 struct dwarf2_per_cu_data
*per_cu
,
20736 CORE_ADDR (*get_frame_pc
) (void *baton
),
20739 struct dwarf2_cu
*cu
;
20740 struct die_info
*die
;
20741 struct attribute
*attr
;
20742 struct dwarf2_locexpr_baton retval
;
20744 dw2_setup (per_cu
->objfile
);
20746 if (per_cu
->cu
== NULL
)
20751 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20752 Instead just throw an error, not much else we can do. */
20753 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
20754 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
20757 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
20759 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
20760 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
20762 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20765 /* DWARF: "If there is no such attribute, then there is no effect.".
20766 DATA is ignored if SIZE is 0. */
20768 retval
.data
= NULL
;
20771 else if (attr_form_is_section_offset (attr
))
20773 struct dwarf2_loclist_baton loclist_baton
;
20774 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
20777 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
20779 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
20781 retval
.size
= size
;
20785 if (!attr_form_is_block (attr
))
20786 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
20787 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
20788 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
20790 retval
.data
= DW_BLOCK (attr
)->data
;
20791 retval
.size
= DW_BLOCK (attr
)->size
;
20793 retval
.per_cu
= cu
->per_cu
;
20795 age_cached_comp_units ();
20800 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
20803 struct dwarf2_locexpr_baton
20804 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
20805 struct dwarf2_per_cu_data
*per_cu
,
20806 CORE_ADDR (*get_frame_pc
) (void *baton
),
20809 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
20811 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
20814 /* Write a constant of a given type as target-ordered bytes into
20817 static const gdb_byte
*
20818 write_constant_as_bytes (struct obstack
*obstack
,
20819 enum bfd_endian byte_order
,
20826 *len
= TYPE_LENGTH (type
);
20827 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20828 store_unsigned_integer (result
, *len
, byte_order
, value
);
20833 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
20834 pointer to the constant bytes and set LEN to the length of the
20835 data. If memory is needed, allocate it on OBSTACK. If the DIE
20836 does not have a DW_AT_const_value, return NULL. */
20839 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
20840 struct dwarf2_per_cu_data
*per_cu
,
20841 struct obstack
*obstack
,
20844 struct dwarf2_cu
*cu
;
20845 struct die_info
*die
;
20846 struct attribute
*attr
;
20847 const gdb_byte
*result
= NULL
;
20850 enum bfd_endian byte_order
;
20852 dw2_setup (per_cu
->objfile
);
20854 if (per_cu
->cu
== NULL
)
20859 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20860 Instead just throw an error, not much else we can do. */
20861 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
20862 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
20865 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
20867 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
20868 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
20871 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20875 byte_order
= (bfd_big_endian (per_cu
->objfile
->obfd
)
20876 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20878 switch (attr
->form
)
20881 case DW_FORM_GNU_addr_index
:
20885 *len
= cu
->header
.addr_size
;
20886 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20887 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
20891 case DW_FORM_string
:
20893 case DW_FORM_GNU_str_index
:
20894 case DW_FORM_GNU_strp_alt
:
20895 /* DW_STRING is already allocated on the objfile obstack, point
20897 result
= (const gdb_byte
*) DW_STRING (attr
);
20898 *len
= strlen (DW_STRING (attr
));
20900 case DW_FORM_block1
:
20901 case DW_FORM_block2
:
20902 case DW_FORM_block4
:
20903 case DW_FORM_block
:
20904 case DW_FORM_exprloc
:
20905 case DW_FORM_data16
:
20906 result
= DW_BLOCK (attr
)->data
;
20907 *len
= DW_BLOCK (attr
)->size
;
20910 /* The DW_AT_const_value attributes are supposed to carry the
20911 symbol's value "represented as it would be on the target
20912 architecture." By the time we get here, it's already been
20913 converted to host endianness, so we just need to sign- or
20914 zero-extend it as appropriate. */
20915 case DW_FORM_data1
:
20916 type
= die_type (die
, cu
);
20917 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
20918 if (result
== NULL
)
20919 result
= write_constant_as_bytes (obstack
, byte_order
,
20922 case DW_FORM_data2
:
20923 type
= die_type (die
, cu
);
20924 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
20925 if (result
== NULL
)
20926 result
= write_constant_as_bytes (obstack
, byte_order
,
20929 case DW_FORM_data4
:
20930 type
= die_type (die
, cu
);
20931 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
20932 if (result
== NULL
)
20933 result
= write_constant_as_bytes (obstack
, byte_order
,
20936 case DW_FORM_data8
:
20937 type
= die_type (die
, cu
);
20938 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
20939 if (result
== NULL
)
20940 result
= write_constant_as_bytes (obstack
, byte_order
,
20944 case DW_FORM_sdata
:
20945 case DW_FORM_implicit_const
:
20946 type
= die_type (die
, cu
);
20947 result
= write_constant_as_bytes (obstack
, byte_order
,
20948 type
, DW_SND (attr
), len
);
20951 case DW_FORM_udata
:
20952 type
= die_type (die
, cu
);
20953 result
= write_constant_as_bytes (obstack
, byte_order
,
20954 type
, DW_UNSND (attr
), len
);
20958 complaint (&symfile_complaints
,
20959 _("unsupported const value attribute form: '%s'"),
20960 dwarf_form_name (attr
->form
));
20967 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
20968 valid type for this die is found. */
20971 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
20972 struct dwarf2_per_cu_data
*per_cu
)
20974 struct dwarf2_cu
*cu
;
20975 struct die_info
*die
;
20977 dw2_setup (per_cu
->objfile
);
20979 if (per_cu
->cu
== NULL
)
20985 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
20989 return die_type (die
, cu
);
20992 /* Return the type of the DIE at DIE_OFFSET in the CU named by
20996 dwarf2_get_die_type (cu_offset die_offset
,
20997 struct dwarf2_per_cu_data
*per_cu
)
20999 dw2_setup (per_cu
->objfile
);
21001 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
21002 return get_die_type_at_offset (die_offset_sect
, per_cu
);
21005 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
21006 On entry *REF_CU is the CU of SRC_DIE.
21007 On exit *REF_CU is the CU of the result.
21008 Returns NULL if the referenced DIE isn't found. */
21010 static struct die_info
*
21011 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
21012 struct dwarf2_cu
**ref_cu
)
21014 struct die_info temp_die
;
21015 struct dwarf2_cu
*sig_cu
;
21016 struct die_info
*die
;
21018 /* While it might be nice to assert sig_type->type == NULL here,
21019 we can get here for DW_AT_imported_declaration where we need
21020 the DIE not the type. */
21022 /* If necessary, add it to the queue and load its DIEs. */
21024 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
21025 read_signatured_type (sig_type
);
21027 sig_cu
= sig_type
->per_cu
.cu
;
21028 gdb_assert (sig_cu
!= NULL
);
21029 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
21030 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
21031 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
21032 to_underlying (temp_die
.sect_off
));
21035 /* For .gdb_index version 7 keep track of included TUs.
21036 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
21037 if (dwarf2_per_objfile
->index_table
!= NULL
21038 && dwarf2_per_objfile
->index_table
->version
<= 7)
21040 VEC_safe_push (dwarf2_per_cu_ptr
,
21041 (*ref_cu
)->per_cu
->imported_symtabs
,
21052 /* Follow signatured type referenced by ATTR in SRC_DIE.
21053 On entry *REF_CU is the CU of SRC_DIE.
21054 On exit *REF_CU is the CU of the result.
21055 The result is the DIE of the type.
21056 If the referenced type cannot be found an error is thrown. */
21058 static struct die_info
*
21059 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21060 struct dwarf2_cu
**ref_cu
)
21062 ULONGEST signature
= DW_SIGNATURE (attr
);
21063 struct signatured_type
*sig_type
;
21064 struct die_info
*die
;
21066 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
21068 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
21069 /* sig_type will be NULL if the signatured type is missing from
21071 if (sig_type
== NULL
)
21073 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
21074 " from DIE at 0x%x [in module %s]"),
21075 hex_string (signature
), to_underlying (src_die
->sect_off
),
21076 objfile_name ((*ref_cu
)->objfile
));
21079 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
21082 dump_die_for_error (src_die
);
21083 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
21084 " from DIE at 0x%x [in module %s]"),
21085 hex_string (signature
), to_underlying (src_die
->sect_off
),
21086 objfile_name ((*ref_cu
)->objfile
));
21092 /* Get the type specified by SIGNATURE referenced in DIE/CU,
21093 reading in and processing the type unit if necessary. */
21095 static struct type
*
21096 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
21097 struct dwarf2_cu
*cu
)
21099 struct signatured_type
*sig_type
;
21100 struct dwarf2_cu
*type_cu
;
21101 struct die_info
*type_die
;
21104 sig_type
= lookup_signatured_type (cu
, signature
);
21105 /* sig_type will be NULL if the signatured type is missing from
21107 if (sig_type
== NULL
)
21109 complaint (&symfile_complaints
,
21110 _("Dwarf Error: Cannot find signatured DIE %s referenced"
21111 " from DIE at 0x%x [in module %s]"),
21112 hex_string (signature
), to_underlying (die
->sect_off
),
21113 objfile_name (dwarf2_per_objfile
->objfile
));
21114 return build_error_marker_type (cu
, die
);
21117 /* If we already know the type we're done. */
21118 if (sig_type
->type
!= NULL
)
21119 return sig_type
->type
;
21122 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
21123 if (type_die
!= NULL
)
21125 /* N.B. We need to call get_die_type to ensure only one type for this DIE
21126 is created. This is important, for example, because for c++ classes
21127 we need TYPE_NAME set which is only done by new_symbol. Blech. */
21128 type
= read_type_die (type_die
, type_cu
);
21131 complaint (&symfile_complaints
,
21132 _("Dwarf Error: Cannot build signatured type %s"
21133 " referenced from DIE at 0x%x [in module %s]"),
21134 hex_string (signature
), to_underlying (die
->sect_off
),
21135 objfile_name (dwarf2_per_objfile
->objfile
));
21136 type
= build_error_marker_type (cu
, die
);
21141 complaint (&symfile_complaints
,
21142 _("Dwarf Error: Problem reading signatured DIE %s referenced"
21143 " from DIE at 0x%x [in module %s]"),
21144 hex_string (signature
), to_underlying (die
->sect_off
),
21145 objfile_name (dwarf2_per_objfile
->objfile
));
21146 type
= build_error_marker_type (cu
, die
);
21148 sig_type
->type
= type
;
21153 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
21154 reading in and processing the type unit if necessary. */
21156 static struct type
*
21157 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
21158 struct dwarf2_cu
*cu
) /* ARI: editCase function */
21160 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
21161 if (attr_form_is_ref (attr
))
21163 struct dwarf2_cu
*type_cu
= cu
;
21164 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
21166 return read_type_die (type_die
, type_cu
);
21168 else if (attr
->form
== DW_FORM_ref_sig8
)
21170 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
21174 complaint (&symfile_complaints
,
21175 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
21176 " at 0x%x [in module %s]"),
21177 dwarf_form_name (attr
->form
), to_underlying (die
->sect_off
),
21178 objfile_name (dwarf2_per_objfile
->objfile
));
21179 return build_error_marker_type (cu
, die
);
21183 /* Load the DIEs associated with type unit PER_CU into memory. */
21186 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
21188 struct signatured_type
*sig_type
;
21190 /* Caller is responsible for ensuring type_unit_groups don't get here. */
21191 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
21193 /* We have the per_cu, but we need the signatured_type.
21194 Fortunately this is an easy translation. */
21195 gdb_assert (per_cu
->is_debug_types
);
21196 sig_type
= (struct signatured_type
*) per_cu
;
21198 gdb_assert (per_cu
->cu
== NULL
);
21200 read_signatured_type (sig_type
);
21202 gdb_assert (per_cu
->cu
!= NULL
);
21205 /* die_reader_func for read_signatured_type.
21206 This is identical to load_full_comp_unit_reader,
21207 but is kept separate for now. */
21210 read_signatured_type_reader (const struct die_reader_specs
*reader
,
21211 const gdb_byte
*info_ptr
,
21212 struct die_info
*comp_unit_die
,
21216 struct dwarf2_cu
*cu
= reader
->cu
;
21218 gdb_assert (cu
->die_hash
== NULL
);
21220 htab_create_alloc_ex (cu
->header
.length
/ 12,
21224 &cu
->comp_unit_obstack
,
21225 hashtab_obstack_allocate
,
21226 dummy_obstack_deallocate
);
21229 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
21230 &info_ptr
, comp_unit_die
);
21231 cu
->dies
= comp_unit_die
;
21232 /* comp_unit_die is not stored in die_hash, no need. */
21234 /* We try not to read any attributes in this function, because not
21235 all CUs needed for references have been loaded yet, and symbol
21236 table processing isn't initialized. But we have to set the CU language,
21237 or we won't be able to build types correctly.
21238 Similarly, if we do not read the producer, we can not apply
21239 producer-specific interpretation. */
21240 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
21243 /* Read in a signatured type and build its CU and DIEs.
21244 If the type is a stub for the real type in a DWO file,
21245 read in the real type from the DWO file as well. */
21248 read_signatured_type (struct signatured_type
*sig_type
)
21250 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
21252 gdb_assert (per_cu
->is_debug_types
);
21253 gdb_assert (per_cu
->cu
== NULL
);
21255 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
21256 read_signatured_type_reader
, NULL
);
21257 sig_type
->per_cu
.tu_read
= 1;
21260 /* Decode simple location descriptions.
21261 Given a pointer to a dwarf block that defines a location, compute
21262 the location and return the value.
21264 NOTE drow/2003-11-18: This function is called in two situations
21265 now: for the address of static or global variables (partial symbols
21266 only) and for offsets into structures which are expected to be
21267 (more or less) constant. The partial symbol case should go away,
21268 and only the constant case should remain. That will let this
21269 function complain more accurately. A few special modes are allowed
21270 without complaint for global variables (for instance, global
21271 register values and thread-local values).
21273 A location description containing no operations indicates that the
21274 object is optimized out. The return value is 0 for that case.
21275 FIXME drow/2003-11-16: No callers check for this case any more; soon all
21276 callers will only want a very basic result and this can become a
21279 Note that stack[0] is unused except as a default error return. */
21282 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
21284 struct objfile
*objfile
= cu
->objfile
;
21286 size_t size
= blk
->size
;
21287 const gdb_byte
*data
= blk
->data
;
21288 CORE_ADDR stack
[64];
21290 unsigned int bytes_read
, unsnd
;
21296 stack
[++stacki
] = 0;
21335 stack
[++stacki
] = op
- DW_OP_lit0
;
21370 stack
[++stacki
] = op
- DW_OP_reg0
;
21372 dwarf2_complex_location_expr_complaint ();
21376 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
21378 stack
[++stacki
] = unsnd
;
21380 dwarf2_complex_location_expr_complaint ();
21384 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
21389 case DW_OP_const1u
:
21390 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
21394 case DW_OP_const1s
:
21395 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
21399 case DW_OP_const2u
:
21400 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
21404 case DW_OP_const2s
:
21405 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
21409 case DW_OP_const4u
:
21410 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
21414 case DW_OP_const4s
:
21415 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
21419 case DW_OP_const8u
:
21420 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
21425 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
21431 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
21436 stack
[stacki
+ 1] = stack
[stacki
];
21441 stack
[stacki
- 1] += stack
[stacki
];
21445 case DW_OP_plus_uconst
:
21446 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
21452 stack
[stacki
- 1] -= stack
[stacki
];
21457 /* If we're not the last op, then we definitely can't encode
21458 this using GDB's address_class enum. This is valid for partial
21459 global symbols, although the variable's address will be bogus
21462 dwarf2_complex_location_expr_complaint ();
21465 case DW_OP_GNU_push_tls_address
:
21466 case DW_OP_form_tls_address
:
21467 /* The top of the stack has the offset from the beginning
21468 of the thread control block at which the variable is located. */
21469 /* Nothing should follow this operator, so the top of stack would
21471 /* This is valid for partial global symbols, but the variable's
21472 address will be bogus in the psymtab. Make it always at least
21473 non-zero to not look as a variable garbage collected by linker
21474 which have DW_OP_addr 0. */
21476 dwarf2_complex_location_expr_complaint ();
21480 case DW_OP_GNU_uninit
:
21483 case DW_OP_GNU_addr_index
:
21484 case DW_OP_GNU_const_index
:
21485 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
21492 const char *name
= get_DW_OP_name (op
);
21495 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
21498 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
21502 return (stack
[stacki
]);
21505 /* Enforce maximum stack depth of SIZE-1 to avoid writing
21506 outside of the allocated space. Also enforce minimum>0. */
21507 if (stacki
>= ARRAY_SIZE (stack
) - 1)
21509 complaint (&symfile_complaints
,
21510 _("location description stack overflow"));
21516 complaint (&symfile_complaints
,
21517 _("location description stack underflow"));
21521 return (stack
[stacki
]);
21524 /* memory allocation interface */
21526 static struct dwarf_block
*
21527 dwarf_alloc_block (struct dwarf2_cu
*cu
)
21529 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
21532 static struct die_info
*
21533 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
21535 struct die_info
*die
;
21536 size_t size
= sizeof (struct die_info
);
21539 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
21541 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
21542 memset (die
, 0, sizeof (struct die_info
));
21547 /* Macro support. */
21549 /* Return file name relative to the compilation directory of file number I in
21550 *LH's file name table. The result is allocated using xmalloc; the caller is
21551 responsible for freeing it. */
21554 file_file_name (int file
, struct line_header
*lh
)
21556 /* Is the file number a valid index into the line header's file name
21557 table? Remember that file numbers start with one, not zero. */
21558 if (1 <= file
&& file
<= lh
->file_names
.size ())
21560 const file_entry
&fe
= lh
->file_names
[file
- 1];
21562 if (!IS_ABSOLUTE_PATH (fe
.name
))
21564 const char *dir
= fe
.include_dir (lh
);
21566 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
21568 return xstrdup (fe
.name
);
21572 /* The compiler produced a bogus file number. We can at least
21573 record the macro definitions made in the file, even if we
21574 won't be able to find the file by name. */
21575 char fake_name
[80];
21577 xsnprintf (fake_name
, sizeof (fake_name
),
21578 "<bad macro file number %d>", file
);
21580 complaint (&symfile_complaints
,
21581 _("bad file number in macro information (%d)"),
21584 return xstrdup (fake_name
);
21588 /* Return the full name of file number I in *LH's file name table.
21589 Use COMP_DIR as the name of the current directory of the
21590 compilation. The result is allocated using xmalloc; the caller is
21591 responsible for freeing it. */
21593 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
21595 /* Is the file number a valid index into the line header's file name
21596 table? Remember that file numbers start with one, not zero. */
21597 if (1 <= file
&& file
<= lh
->file_names
.size ())
21599 char *relative
= file_file_name (file
, lh
);
21601 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
21603 return reconcat (relative
, comp_dir
, SLASH_STRING
,
21604 relative
, (char *) NULL
);
21607 return file_file_name (file
, lh
);
21611 static struct macro_source_file
*
21612 macro_start_file (int file
, int line
,
21613 struct macro_source_file
*current_file
,
21614 struct line_header
*lh
)
21616 /* File name relative to the compilation directory of this source file. */
21617 char *file_name
= file_file_name (file
, lh
);
21619 if (! current_file
)
21621 /* Note: We don't create a macro table for this compilation unit
21622 at all until we actually get a filename. */
21623 struct macro_table
*macro_table
= get_macro_table ();
21625 /* If we have no current file, then this must be the start_file
21626 directive for the compilation unit's main source file. */
21627 current_file
= macro_set_main (macro_table
, file_name
);
21628 macro_define_special (macro_table
);
21631 current_file
= macro_include (current_file
, line
, file_name
);
21635 return current_file
;
21638 static const char *
21639 consume_improper_spaces (const char *p
, const char *body
)
21643 complaint (&symfile_complaints
,
21644 _("macro definition contains spaces "
21645 "in formal argument list:\n`%s'"),
21657 parse_macro_definition (struct macro_source_file
*file
, int line
,
21662 /* The body string takes one of two forms. For object-like macro
21663 definitions, it should be:
21665 <macro name> " " <definition>
21667 For function-like macro definitions, it should be:
21669 <macro name> "() " <definition>
21671 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
21673 Spaces may appear only where explicitly indicated, and in the
21676 The Dwarf 2 spec says that an object-like macro's name is always
21677 followed by a space, but versions of GCC around March 2002 omit
21678 the space when the macro's definition is the empty string.
21680 The Dwarf 2 spec says that there should be no spaces between the
21681 formal arguments in a function-like macro's formal argument list,
21682 but versions of GCC around March 2002 include spaces after the
21686 /* Find the extent of the macro name. The macro name is terminated
21687 by either a space or null character (for an object-like macro) or
21688 an opening paren (for a function-like macro). */
21689 for (p
= body
; *p
; p
++)
21690 if (*p
== ' ' || *p
== '(')
21693 if (*p
== ' ' || *p
== '\0')
21695 /* It's an object-like macro. */
21696 int name_len
= p
- body
;
21697 char *name
= savestring (body
, name_len
);
21698 const char *replacement
;
21701 replacement
= body
+ name_len
+ 1;
21704 dwarf2_macro_malformed_definition_complaint (body
);
21705 replacement
= body
+ name_len
;
21708 macro_define_object (file
, line
, name
, replacement
);
21712 else if (*p
== '(')
21714 /* It's a function-like macro. */
21715 char *name
= savestring (body
, p
- body
);
21718 char **argv
= XNEWVEC (char *, argv_size
);
21722 p
= consume_improper_spaces (p
, body
);
21724 /* Parse the formal argument list. */
21725 while (*p
&& *p
!= ')')
21727 /* Find the extent of the current argument name. */
21728 const char *arg_start
= p
;
21730 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
21733 if (! *p
|| p
== arg_start
)
21734 dwarf2_macro_malformed_definition_complaint (body
);
21737 /* Make sure argv has room for the new argument. */
21738 if (argc
>= argv_size
)
21741 argv
= XRESIZEVEC (char *, argv
, argv_size
);
21744 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
21747 p
= consume_improper_spaces (p
, body
);
21749 /* Consume the comma, if present. */
21754 p
= consume_improper_spaces (p
, body
);
21763 /* Perfectly formed definition, no complaints. */
21764 macro_define_function (file
, line
, name
,
21765 argc
, (const char **) argv
,
21767 else if (*p
== '\0')
21769 /* Complain, but do define it. */
21770 dwarf2_macro_malformed_definition_complaint (body
);
21771 macro_define_function (file
, line
, name
,
21772 argc
, (const char **) argv
,
21776 /* Just complain. */
21777 dwarf2_macro_malformed_definition_complaint (body
);
21780 /* Just complain. */
21781 dwarf2_macro_malformed_definition_complaint (body
);
21787 for (i
= 0; i
< argc
; i
++)
21793 dwarf2_macro_malformed_definition_complaint (body
);
21796 /* Skip some bytes from BYTES according to the form given in FORM.
21797 Returns the new pointer. */
21799 static const gdb_byte
*
21800 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
21801 enum dwarf_form form
,
21802 unsigned int offset_size
,
21803 struct dwarf2_section_info
*section
)
21805 unsigned int bytes_read
;
21809 case DW_FORM_data1
:
21814 case DW_FORM_data2
:
21818 case DW_FORM_data4
:
21822 case DW_FORM_data8
:
21826 case DW_FORM_data16
:
21830 case DW_FORM_string
:
21831 read_direct_string (abfd
, bytes
, &bytes_read
);
21832 bytes
+= bytes_read
;
21835 case DW_FORM_sec_offset
:
21837 case DW_FORM_GNU_strp_alt
:
21838 bytes
+= offset_size
;
21841 case DW_FORM_block
:
21842 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
21843 bytes
+= bytes_read
;
21846 case DW_FORM_block1
:
21847 bytes
+= 1 + read_1_byte (abfd
, bytes
);
21849 case DW_FORM_block2
:
21850 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
21852 case DW_FORM_block4
:
21853 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
21856 case DW_FORM_sdata
:
21857 case DW_FORM_udata
:
21858 case DW_FORM_GNU_addr_index
:
21859 case DW_FORM_GNU_str_index
:
21860 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
21863 dwarf2_section_buffer_overflow_complaint (section
);
21868 case DW_FORM_implicit_const
:
21874 complaint (&symfile_complaints
,
21875 _("invalid form 0x%x in `%s'"),
21876 form
, get_section_name (section
));
21884 /* A helper for dwarf_decode_macros that handles skipping an unknown
21885 opcode. Returns an updated pointer to the macro data buffer; or,
21886 on error, issues a complaint and returns NULL. */
21888 static const gdb_byte
*
21889 skip_unknown_opcode (unsigned int opcode
,
21890 const gdb_byte
**opcode_definitions
,
21891 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
21893 unsigned int offset_size
,
21894 struct dwarf2_section_info
*section
)
21896 unsigned int bytes_read
, i
;
21898 const gdb_byte
*defn
;
21900 if (opcode_definitions
[opcode
] == NULL
)
21902 complaint (&symfile_complaints
,
21903 _("unrecognized DW_MACFINO opcode 0x%x"),
21908 defn
= opcode_definitions
[opcode
];
21909 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
21910 defn
+= bytes_read
;
21912 for (i
= 0; i
< arg
; ++i
)
21914 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
21915 (enum dwarf_form
) defn
[i
], offset_size
,
21917 if (mac_ptr
== NULL
)
21919 /* skip_form_bytes already issued the complaint. */
21927 /* A helper function which parses the header of a macro section.
21928 If the macro section is the extended (for now called "GNU") type,
21929 then this updates *OFFSET_SIZE. Returns a pointer to just after
21930 the header, or issues a complaint and returns NULL on error. */
21932 static const gdb_byte
*
21933 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
21935 const gdb_byte
*mac_ptr
,
21936 unsigned int *offset_size
,
21937 int section_is_gnu
)
21939 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
21941 if (section_is_gnu
)
21943 unsigned int version
, flags
;
21945 version
= read_2_bytes (abfd
, mac_ptr
);
21946 if (version
!= 4 && version
!= 5)
21948 complaint (&symfile_complaints
,
21949 _("unrecognized version `%d' in .debug_macro section"),
21955 flags
= read_1_byte (abfd
, mac_ptr
);
21957 *offset_size
= (flags
& 1) ? 8 : 4;
21959 if ((flags
& 2) != 0)
21960 /* We don't need the line table offset. */
21961 mac_ptr
+= *offset_size
;
21963 /* Vendor opcode descriptions. */
21964 if ((flags
& 4) != 0)
21966 unsigned int i
, count
;
21968 count
= read_1_byte (abfd
, mac_ptr
);
21970 for (i
= 0; i
< count
; ++i
)
21972 unsigned int opcode
, bytes_read
;
21975 opcode
= read_1_byte (abfd
, mac_ptr
);
21977 opcode_definitions
[opcode
] = mac_ptr
;
21978 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21979 mac_ptr
+= bytes_read
;
21988 /* A helper for dwarf_decode_macros that handles the GNU extensions,
21989 including DW_MACRO_import. */
21992 dwarf_decode_macro_bytes (bfd
*abfd
,
21993 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
21994 struct macro_source_file
*current_file
,
21995 struct line_header
*lh
,
21996 struct dwarf2_section_info
*section
,
21997 int section_is_gnu
, int section_is_dwz
,
21998 unsigned int offset_size
,
21999 htab_t include_hash
)
22001 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22002 enum dwarf_macro_record_type macinfo_type
;
22003 int at_commandline
;
22004 const gdb_byte
*opcode_definitions
[256];
22006 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
22007 &offset_size
, section_is_gnu
);
22008 if (mac_ptr
== NULL
)
22010 /* We already issued a complaint. */
22014 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
22015 GDB is still reading the definitions from command line. First
22016 DW_MACINFO_start_file will need to be ignored as it was already executed
22017 to create CURRENT_FILE for the main source holding also the command line
22018 definitions. On first met DW_MACINFO_start_file this flag is reset to
22019 normally execute all the remaining DW_MACINFO_start_file macinfos. */
22021 at_commandline
= 1;
22025 /* Do we at least have room for a macinfo type byte? */
22026 if (mac_ptr
>= mac_end
)
22028 dwarf2_section_buffer_overflow_complaint (section
);
22032 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
22035 /* Note that we rely on the fact that the corresponding GNU and
22036 DWARF constants are the same. */
22037 switch (macinfo_type
)
22039 /* A zero macinfo type indicates the end of the macro
22044 case DW_MACRO_define
:
22045 case DW_MACRO_undef
:
22046 case DW_MACRO_define_strp
:
22047 case DW_MACRO_undef_strp
:
22048 case DW_MACRO_define_sup
:
22049 case DW_MACRO_undef_sup
:
22051 unsigned int bytes_read
;
22056 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22057 mac_ptr
+= bytes_read
;
22059 if (macinfo_type
== DW_MACRO_define
22060 || macinfo_type
== DW_MACRO_undef
)
22062 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22063 mac_ptr
+= bytes_read
;
22067 LONGEST str_offset
;
22069 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
22070 mac_ptr
+= offset_size
;
22072 if (macinfo_type
== DW_MACRO_define_sup
22073 || macinfo_type
== DW_MACRO_undef_sup
22076 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
22078 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
22081 body
= read_indirect_string_at_offset (abfd
, str_offset
);
22084 is_define
= (macinfo_type
== DW_MACRO_define
22085 || macinfo_type
== DW_MACRO_define_strp
22086 || macinfo_type
== DW_MACRO_define_sup
);
22087 if (! current_file
)
22089 /* DWARF violation as no main source is present. */
22090 complaint (&symfile_complaints
,
22091 _("debug info with no main source gives macro %s "
22093 is_define
? _("definition") : _("undefinition"),
22097 if ((line
== 0 && !at_commandline
)
22098 || (line
!= 0 && at_commandline
))
22099 complaint (&symfile_complaints
,
22100 _("debug info gives %s macro %s with %s line %d: %s"),
22101 at_commandline
? _("command-line") : _("in-file"),
22102 is_define
? _("definition") : _("undefinition"),
22103 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
22106 parse_macro_definition (current_file
, line
, body
);
22109 gdb_assert (macinfo_type
== DW_MACRO_undef
22110 || macinfo_type
== DW_MACRO_undef_strp
22111 || macinfo_type
== DW_MACRO_undef_sup
);
22112 macro_undef (current_file
, line
, body
);
22117 case DW_MACRO_start_file
:
22119 unsigned int bytes_read
;
22122 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22123 mac_ptr
+= bytes_read
;
22124 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22125 mac_ptr
+= bytes_read
;
22127 if ((line
== 0 && !at_commandline
)
22128 || (line
!= 0 && at_commandline
))
22129 complaint (&symfile_complaints
,
22130 _("debug info gives source %d included "
22131 "from %s at %s line %d"),
22132 file
, at_commandline
? _("command-line") : _("file"),
22133 line
== 0 ? _("zero") : _("non-zero"), line
);
22135 if (at_commandline
)
22137 /* This DW_MACRO_start_file was executed in the
22139 at_commandline
= 0;
22142 current_file
= macro_start_file (file
, line
, current_file
, lh
);
22146 case DW_MACRO_end_file
:
22147 if (! current_file
)
22148 complaint (&symfile_complaints
,
22149 _("macro debug info has an unmatched "
22150 "`close_file' directive"));
22153 current_file
= current_file
->included_by
;
22154 if (! current_file
)
22156 enum dwarf_macro_record_type next_type
;
22158 /* GCC circa March 2002 doesn't produce the zero
22159 type byte marking the end of the compilation
22160 unit. Complain if it's not there, but exit no
22163 /* Do we at least have room for a macinfo type byte? */
22164 if (mac_ptr
>= mac_end
)
22166 dwarf2_section_buffer_overflow_complaint (section
);
22170 /* We don't increment mac_ptr here, so this is just
22173 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
22175 if (next_type
!= 0)
22176 complaint (&symfile_complaints
,
22177 _("no terminating 0-type entry for "
22178 "macros in `.debug_macinfo' section"));
22185 case DW_MACRO_import
:
22186 case DW_MACRO_import_sup
:
22190 bfd
*include_bfd
= abfd
;
22191 struct dwarf2_section_info
*include_section
= section
;
22192 const gdb_byte
*include_mac_end
= mac_end
;
22193 int is_dwz
= section_is_dwz
;
22194 const gdb_byte
*new_mac_ptr
;
22196 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
22197 mac_ptr
+= offset_size
;
22199 if (macinfo_type
== DW_MACRO_import_sup
)
22201 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
22203 dwarf2_read_section (objfile
, &dwz
->macro
);
22205 include_section
= &dwz
->macro
;
22206 include_bfd
= get_section_bfd_owner (include_section
);
22207 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
22211 new_mac_ptr
= include_section
->buffer
+ offset
;
22212 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
22216 /* This has actually happened; see
22217 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
22218 complaint (&symfile_complaints
,
22219 _("recursive DW_MACRO_import in "
22220 ".debug_macro section"));
22224 *slot
= (void *) new_mac_ptr
;
22226 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
22227 include_mac_end
, current_file
, lh
,
22228 section
, section_is_gnu
, is_dwz
,
22229 offset_size
, include_hash
);
22231 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
22236 case DW_MACINFO_vendor_ext
:
22237 if (!section_is_gnu
)
22239 unsigned int bytes_read
;
22241 /* This reads the constant, but since we don't recognize
22242 any vendor extensions, we ignore it. */
22243 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22244 mac_ptr
+= bytes_read
;
22245 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22246 mac_ptr
+= bytes_read
;
22248 /* We don't recognize any vendor extensions. */
22254 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
22255 mac_ptr
, mac_end
, abfd
, offset_size
,
22257 if (mac_ptr
== NULL
)
22261 } while (macinfo_type
!= 0);
22265 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22266 int section_is_gnu
)
22268 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22269 struct line_header
*lh
= cu
->line_header
;
22271 const gdb_byte
*mac_ptr
, *mac_end
;
22272 struct macro_source_file
*current_file
= 0;
22273 enum dwarf_macro_record_type macinfo_type
;
22274 unsigned int offset_size
= cu
->header
.offset_size
;
22275 const gdb_byte
*opcode_definitions
[256];
22277 struct dwarf2_section_info
*section
;
22278 const char *section_name
;
22280 if (cu
->dwo_unit
!= NULL
)
22282 if (section_is_gnu
)
22284 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22285 section_name
= ".debug_macro.dwo";
22289 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22290 section_name
= ".debug_macinfo.dwo";
22295 if (section_is_gnu
)
22297 section
= &dwarf2_per_objfile
->macro
;
22298 section_name
= ".debug_macro";
22302 section
= &dwarf2_per_objfile
->macinfo
;
22303 section_name
= ".debug_macinfo";
22307 dwarf2_read_section (objfile
, section
);
22308 if (section
->buffer
== NULL
)
22310 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
22313 abfd
= get_section_bfd_owner (section
);
22315 /* First pass: Find the name of the base filename.
22316 This filename is needed in order to process all macros whose definition
22317 (or undefinition) comes from the command line. These macros are defined
22318 before the first DW_MACINFO_start_file entry, and yet still need to be
22319 associated to the base file.
22321 To determine the base file name, we scan the macro definitions until we
22322 reach the first DW_MACINFO_start_file entry. We then initialize
22323 CURRENT_FILE accordingly so that any macro definition found before the
22324 first DW_MACINFO_start_file can still be associated to the base file. */
22326 mac_ptr
= section
->buffer
+ offset
;
22327 mac_end
= section
->buffer
+ section
->size
;
22329 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
22330 &offset_size
, section_is_gnu
);
22331 if (mac_ptr
== NULL
)
22333 /* We already issued a complaint. */
22339 /* Do we at least have room for a macinfo type byte? */
22340 if (mac_ptr
>= mac_end
)
22342 /* Complaint is printed during the second pass as GDB will probably
22343 stop the first pass earlier upon finding
22344 DW_MACINFO_start_file. */
22348 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
22351 /* Note that we rely on the fact that the corresponding GNU and
22352 DWARF constants are the same. */
22353 switch (macinfo_type
)
22355 /* A zero macinfo type indicates the end of the macro
22360 case DW_MACRO_define
:
22361 case DW_MACRO_undef
:
22362 /* Only skip the data by MAC_PTR. */
22364 unsigned int bytes_read
;
22366 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22367 mac_ptr
+= bytes_read
;
22368 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22369 mac_ptr
+= bytes_read
;
22373 case DW_MACRO_start_file
:
22375 unsigned int bytes_read
;
22378 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22379 mac_ptr
+= bytes_read
;
22380 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22381 mac_ptr
+= bytes_read
;
22383 current_file
= macro_start_file (file
, line
, current_file
, lh
);
22387 case DW_MACRO_end_file
:
22388 /* No data to skip by MAC_PTR. */
22391 case DW_MACRO_define_strp
:
22392 case DW_MACRO_undef_strp
:
22393 case DW_MACRO_define_sup
:
22394 case DW_MACRO_undef_sup
:
22396 unsigned int bytes_read
;
22398 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22399 mac_ptr
+= bytes_read
;
22400 mac_ptr
+= offset_size
;
22404 case DW_MACRO_import
:
22405 case DW_MACRO_import_sup
:
22406 /* Note that, according to the spec, a transparent include
22407 chain cannot call DW_MACRO_start_file. So, we can just
22408 skip this opcode. */
22409 mac_ptr
+= offset_size
;
22412 case DW_MACINFO_vendor_ext
:
22413 /* Only skip the data by MAC_PTR. */
22414 if (!section_is_gnu
)
22416 unsigned int bytes_read
;
22418 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22419 mac_ptr
+= bytes_read
;
22420 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22421 mac_ptr
+= bytes_read
;
22426 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
22427 mac_ptr
, mac_end
, abfd
, offset_size
,
22429 if (mac_ptr
== NULL
)
22433 } while (macinfo_type
!= 0 && current_file
== NULL
);
22435 /* Second pass: Process all entries.
22437 Use the AT_COMMAND_LINE flag to determine whether we are still processing
22438 command-line macro definitions/undefinitions. This flag is unset when we
22439 reach the first DW_MACINFO_start_file entry. */
22441 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
22443 NULL
, xcalloc
, xfree
));
22444 mac_ptr
= section
->buffer
+ offset
;
22445 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
22446 *slot
= (void *) mac_ptr
;
22447 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
22448 current_file
, lh
, section
,
22449 section_is_gnu
, 0, offset_size
,
22450 include_hash
.get ());
22453 /* Check if the attribute's form is a DW_FORM_block*
22454 if so return true else false. */
22457 attr_form_is_block (const struct attribute
*attr
)
22459 return (attr
== NULL
? 0 :
22460 attr
->form
== DW_FORM_block1
22461 || attr
->form
== DW_FORM_block2
22462 || attr
->form
== DW_FORM_block4
22463 || attr
->form
== DW_FORM_block
22464 || attr
->form
== DW_FORM_exprloc
);
22467 /* Return non-zero if ATTR's value is a section offset --- classes
22468 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
22469 You may use DW_UNSND (attr) to retrieve such offsets.
22471 Section 7.5.4, "Attribute Encodings", explains that no attribute
22472 may have a value that belongs to more than one of these classes; it
22473 would be ambiguous if we did, because we use the same forms for all
22477 attr_form_is_section_offset (const struct attribute
*attr
)
22479 return (attr
->form
== DW_FORM_data4
22480 || attr
->form
== DW_FORM_data8
22481 || attr
->form
== DW_FORM_sec_offset
);
22484 /* Return non-zero if ATTR's value falls in the 'constant' class, or
22485 zero otherwise. When this function returns true, you can apply
22486 dwarf2_get_attr_constant_value to it.
22488 However, note that for some attributes you must check
22489 attr_form_is_section_offset before using this test. DW_FORM_data4
22490 and DW_FORM_data8 are members of both the constant class, and of
22491 the classes that contain offsets into other debug sections
22492 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
22493 that, if an attribute's can be either a constant or one of the
22494 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
22495 taken as section offsets, not constants.
22497 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
22498 cannot handle that. */
22501 attr_form_is_constant (const struct attribute
*attr
)
22503 switch (attr
->form
)
22505 case DW_FORM_sdata
:
22506 case DW_FORM_udata
:
22507 case DW_FORM_data1
:
22508 case DW_FORM_data2
:
22509 case DW_FORM_data4
:
22510 case DW_FORM_data8
:
22511 case DW_FORM_implicit_const
:
22519 /* DW_ADDR is always stored already as sect_offset; despite for the forms
22520 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
22523 attr_form_is_ref (const struct attribute
*attr
)
22525 switch (attr
->form
)
22527 case DW_FORM_ref_addr
:
22532 case DW_FORM_ref_udata
:
22533 case DW_FORM_GNU_ref_alt
:
22540 /* Return the .debug_loc section to use for CU.
22541 For DWO files use .debug_loc.dwo. */
22543 static struct dwarf2_section_info
*
22544 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22548 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22550 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22552 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22553 : &dwarf2_per_objfile
->loc
);
22556 /* A helper function that fills in a dwarf2_loclist_baton. */
22559 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22560 struct dwarf2_loclist_baton
*baton
,
22561 const struct attribute
*attr
)
22563 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22565 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
22567 baton
->per_cu
= cu
->per_cu
;
22568 gdb_assert (baton
->per_cu
);
22569 /* We don't know how long the location list is, but make sure we
22570 don't run off the edge of the section. */
22571 baton
->size
= section
->size
- DW_UNSND (attr
);
22572 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22573 baton
->base_address
= cu
->base_address
;
22574 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22578 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22579 struct dwarf2_cu
*cu
, int is_block
)
22581 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22582 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22584 if (attr_form_is_section_offset (attr
)
22585 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22586 the section. If so, fall through to the complaint in the
22588 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
22590 struct dwarf2_loclist_baton
*baton
;
22592 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22594 fill_in_loclist_baton (cu
, baton
, attr
);
22596 if (cu
->base_known
== 0)
22597 complaint (&symfile_complaints
,
22598 _("Location list used without "
22599 "specifying the CU base address."));
22601 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22602 ? dwarf2_loclist_block_index
22603 : dwarf2_loclist_index
);
22604 SYMBOL_LOCATION_BATON (sym
) = baton
;
22608 struct dwarf2_locexpr_baton
*baton
;
22610 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22611 baton
->per_cu
= cu
->per_cu
;
22612 gdb_assert (baton
->per_cu
);
22614 if (attr_form_is_block (attr
))
22616 /* Note that we're just copying the block's data pointer
22617 here, not the actual data. We're still pointing into the
22618 info_buffer for SYM's objfile; right now we never release
22619 that buffer, but when we do clean up properly this may
22621 baton
->size
= DW_BLOCK (attr
)->size
;
22622 baton
->data
= DW_BLOCK (attr
)->data
;
22626 dwarf2_invalid_attrib_class_complaint ("location description",
22627 SYMBOL_NATURAL_NAME (sym
));
22631 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22632 ? dwarf2_locexpr_block_index
22633 : dwarf2_locexpr_index
);
22634 SYMBOL_LOCATION_BATON (sym
) = baton
;
22638 /* Return the OBJFILE associated with the compilation unit CU. If CU
22639 came from a separate debuginfo file, then the master objfile is
22643 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
22645 struct objfile
*objfile
= per_cu
->objfile
;
22647 /* Return the master objfile, so that we can report and look up the
22648 correct file containing this variable. */
22649 if (objfile
->separate_debug_objfile_backlink
)
22650 objfile
= objfile
->separate_debug_objfile_backlink
;
22655 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22656 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22657 CU_HEADERP first. */
22659 static const struct comp_unit_head
*
22660 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22661 struct dwarf2_per_cu_data
*per_cu
)
22663 const gdb_byte
*info_ptr
;
22666 return &per_cu
->cu
->header
;
22668 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
22670 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22671 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22672 rcuh_kind::COMPILE
);
22677 /* Return the address size given in the compilation unit header for CU. */
22680 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
22682 struct comp_unit_head cu_header_local
;
22683 const struct comp_unit_head
*cu_headerp
;
22685 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22687 return cu_headerp
->addr_size
;
22690 /* Return the offset size given in the compilation unit header for CU. */
22693 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
22695 struct comp_unit_head cu_header_local
;
22696 const struct comp_unit_head
*cu_headerp
;
22698 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22700 return cu_headerp
->offset_size
;
22703 /* See its dwarf2loc.h declaration. */
22706 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
22708 struct comp_unit_head cu_header_local
;
22709 const struct comp_unit_head
*cu_headerp
;
22711 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22713 if (cu_headerp
->version
== 2)
22714 return cu_headerp
->addr_size
;
22716 return cu_headerp
->offset_size
;
22719 /* Return the text offset of the CU. The returned offset comes from
22720 this CU's objfile. If this objfile came from a separate debuginfo
22721 file, then the offset may be different from the corresponding
22722 offset in the parent objfile. */
22725 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
22727 struct objfile
*objfile
= per_cu
->objfile
;
22729 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
22732 /* Return DWARF version number of PER_CU. */
22735 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
22737 return per_cu
->dwarf_version
;
22740 /* Locate the .debug_info compilation unit from CU's objfile which contains
22741 the DIE at OFFSET. Raises an error on failure. */
22743 static struct dwarf2_per_cu_data
*
22744 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
22745 unsigned int offset_in_dwz
,
22746 struct objfile
*objfile
)
22748 struct dwarf2_per_cu_data
*this_cu
;
22750 const sect_offset
*cu_off
;
22753 high
= dwarf2_per_objfile
->n_comp_units
- 1;
22756 struct dwarf2_per_cu_data
*mid_cu
;
22757 int mid
= low
+ (high
- low
) / 2;
22759 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
22760 cu_off
= &mid_cu
->sect_off
;
22761 if (mid_cu
->is_dwz
> offset_in_dwz
22762 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
22767 gdb_assert (low
== high
);
22768 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
22769 cu_off
= &this_cu
->sect_off
;
22770 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
22772 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
22773 error (_("Dwarf Error: could not find partial DIE containing "
22774 "offset 0x%x [in module %s]"),
22775 to_underlying (sect_off
), bfd_get_filename (objfile
->obfd
));
22777 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
22779 return dwarf2_per_objfile
->all_comp_units
[low
-1];
22783 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
22784 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
22785 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
22786 error (_("invalid dwarf2 offset %u"), to_underlying (sect_off
));
22787 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
22792 /* Initialize dwarf2_cu CU, owned by PER_CU. */
22795 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
22797 memset (cu
, 0, sizeof (*cu
));
22799 cu
->per_cu
= per_cu
;
22800 cu
->objfile
= per_cu
->objfile
;
22801 obstack_init (&cu
->comp_unit_obstack
);
22804 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
22807 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
22808 enum language pretend_language
)
22810 struct attribute
*attr
;
22812 /* Set the language we're debugging. */
22813 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
22815 set_cu_language (DW_UNSND (attr
), cu
);
22818 cu
->language
= pretend_language
;
22819 cu
->language_defn
= language_def (cu
->language
);
22822 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
22825 /* Release one cached compilation unit, CU. We unlink it from the tree
22826 of compilation units, but we don't remove it from the read_in_chain;
22827 the caller is responsible for that.
22828 NOTE: DATA is a void * because this function is also used as a
22829 cleanup routine. */
22832 free_heap_comp_unit (void *data
)
22834 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
22836 gdb_assert (cu
->per_cu
!= NULL
);
22837 cu
->per_cu
->cu
= NULL
;
22840 obstack_free (&cu
->comp_unit_obstack
, NULL
);
22845 /* This cleanup function is passed the address of a dwarf2_cu on the stack
22846 when we're finished with it. We can't free the pointer itself, but be
22847 sure to unlink it from the cache. Also release any associated storage. */
22850 free_stack_comp_unit (void *data
)
22852 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
22854 gdb_assert (cu
->per_cu
!= NULL
);
22855 cu
->per_cu
->cu
= NULL
;
22858 obstack_free (&cu
->comp_unit_obstack
, NULL
);
22859 cu
->partial_dies
= NULL
;
22862 /* Free all cached compilation units. */
22865 free_cached_comp_units (void *data
)
22867 dwarf2_per_objfile
->free_cached_comp_units ();
22870 /* Increase the age counter on each cached compilation unit, and free
22871 any that are too old. */
22874 age_cached_comp_units (void)
22876 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22878 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
22879 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22880 while (per_cu
!= NULL
)
22882 per_cu
->cu
->last_used
++;
22883 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
22884 dwarf2_mark (per_cu
->cu
);
22885 per_cu
= per_cu
->cu
->read_in_chain
;
22888 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22889 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22890 while (per_cu
!= NULL
)
22892 struct dwarf2_per_cu_data
*next_cu
;
22894 next_cu
= per_cu
->cu
->read_in_chain
;
22896 if (!per_cu
->cu
->mark
)
22898 free_heap_comp_unit (per_cu
->cu
);
22899 *last_chain
= next_cu
;
22902 last_chain
= &per_cu
->cu
->read_in_chain
;
22908 /* Remove a single compilation unit from the cache. */
22911 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
22913 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22915 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22916 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22917 while (per_cu
!= NULL
)
22919 struct dwarf2_per_cu_data
*next_cu
;
22921 next_cu
= per_cu
->cu
->read_in_chain
;
22923 if (per_cu
== target_per_cu
)
22925 free_heap_comp_unit (per_cu
->cu
);
22927 *last_chain
= next_cu
;
22931 last_chain
= &per_cu
->cu
->read_in_chain
;
22937 /* Release all extra memory associated with OBJFILE. */
22940 dwarf2_free_objfile (struct objfile
*objfile
)
22943 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
22944 dwarf2_objfile_data_key
);
22946 if (dwarf2_per_objfile
== NULL
)
22949 dwarf2_per_objfile
->~dwarf2_per_objfile ();
22952 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
22953 We store these in a hash table separate from the DIEs, and preserve them
22954 when the DIEs are flushed out of cache.
22956 The CU "per_cu" pointer is needed because offset alone is not enough to
22957 uniquely identify the type. A file may have multiple .debug_types sections,
22958 or the type may come from a DWO file. Furthermore, while it's more logical
22959 to use per_cu->section+offset, with Fission the section with the data is in
22960 the DWO file but we don't know that section at the point we need it.
22961 We have to use something in dwarf2_per_cu_data (or the pointer to it)
22962 because we can enter the lookup routine, get_die_type_at_offset, from
22963 outside this file, and thus won't necessarily have PER_CU->cu.
22964 Fortunately, PER_CU is stable for the life of the objfile. */
22966 struct dwarf2_per_cu_offset_and_type
22968 const struct dwarf2_per_cu_data
*per_cu
;
22969 sect_offset sect_off
;
22973 /* Hash function for a dwarf2_per_cu_offset_and_type. */
22976 per_cu_offset_and_type_hash (const void *item
)
22978 const struct dwarf2_per_cu_offset_and_type
*ofs
22979 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
22981 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
22984 /* Equality function for a dwarf2_per_cu_offset_and_type. */
22987 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
22989 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
22990 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
22991 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
22992 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
22994 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
22995 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
22998 /* Set the type associated with DIE to TYPE. Save it in CU's hash
22999 table if necessary. For convenience, return TYPE.
23001 The DIEs reading must have careful ordering to:
23002 * Not cause infite loops trying to read in DIEs as a prerequisite for
23003 reading current DIE.
23004 * Not trying to dereference contents of still incompletely read in types
23005 while reading in other DIEs.
23006 * Enable referencing still incompletely read in types just by a pointer to
23007 the type without accessing its fields.
23009 Therefore caller should follow these rules:
23010 * Try to fetch any prerequisite types we may need to build this DIE type
23011 before building the type and calling set_die_type.
23012 * After building type call set_die_type for current DIE as soon as
23013 possible before fetching more types to complete the current type.
23014 * Make the type as complete as possible before fetching more types. */
23016 static struct type
*
23017 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23019 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23020 struct objfile
*objfile
= cu
->objfile
;
23021 struct attribute
*attr
;
23022 struct dynamic_prop prop
;
23024 /* For Ada types, make sure that the gnat-specific data is always
23025 initialized (if not already set). There are a few types where
23026 we should not be doing so, because the type-specific area is
23027 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23028 where the type-specific area is used to store the floatformat).
23029 But this is not a problem, because the gnat-specific information
23030 is actually not needed for these types. */
23031 if (need_gnat_info (cu
)
23032 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23033 && TYPE_CODE (type
) != TYPE_CODE_FLT
23034 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23035 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23036 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23037 && !HAVE_GNAT_AUX_INFO (type
))
23038 INIT_GNAT_SPECIFIC (type
);
23040 /* Read DW_AT_allocated and set in type. */
23041 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23042 if (attr_form_is_block (attr
))
23044 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
23045 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
, objfile
);
23047 else if (attr
!= NULL
)
23049 complaint (&symfile_complaints
,
23050 _("DW_AT_allocated has the wrong form (%s) at DIE 0x%x"),
23051 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23052 to_underlying (die
->sect_off
));
23055 /* Read DW_AT_associated and set in type. */
23056 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23057 if (attr_form_is_block (attr
))
23059 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
23060 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
, objfile
);
23062 else if (attr
!= NULL
)
23064 complaint (&symfile_complaints
,
23065 _("DW_AT_associated has the wrong form (%s) at DIE 0x%x"),
23066 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23067 to_underlying (die
->sect_off
));
23070 /* Read DW_AT_data_location and set in type. */
23071 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23072 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
23073 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
, objfile
);
23075 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23077 dwarf2_per_objfile
->die_type_hash
=
23078 htab_create_alloc_ex (127,
23079 per_cu_offset_and_type_hash
,
23080 per_cu_offset_and_type_eq
,
23082 &objfile
->objfile_obstack
,
23083 hashtab_obstack_allocate
,
23084 dummy_obstack_deallocate
);
23087 ofs
.per_cu
= cu
->per_cu
;
23088 ofs
.sect_off
= die
->sect_off
;
23090 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23091 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
23093 complaint (&symfile_complaints
,
23094 _("A problem internal to GDB: DIE 0x%x has type already set"),
23095 to_underlying (die
->sect_off
));
23096 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23097 struct dwarf2_per_cu_offset_and_type
);
23102 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23103 or return NULL if the die does not have a saved type. */
23105 static struct type
*
23106 get_die_type_at_offset (sect_offset sect_off
,
23107 struct dwarf2_per_cu_data
*per_cu
)
23109 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23111 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23114 ofs
.per_cu
= per_cu
;
23115 ofs
.sect_off
= sect_off
;
23116 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23117 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
23124 /* Look up the type for DIE in CU in die_type_hash,
23125 or return NULL if DIE does not have a saved type. */
23127 static struct type
*
23128 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23130 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23133 /* Add a dependence relationship from CU to REF_PER_CU. */
23136 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23137 struct dwarf2_per_cu_data
*ref_per_cu
)
23141 if (cu
->dependencies
== NULL
)
23143 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23144 NULL
, &cu
->comp_unit_obstack
,
23145 hashtab_obstack_allocate
,
23146 dummy_obstack_deallocate
);
23148 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23150 *slot
= ref_per_cu
;
23153 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23154 Set the mark field in every compilation unit in the
23155 cache that we must keep because we are keeping CU. */
23158 dwarf2_mark_helper (void **slot
, void *data
)
23160 struct dwarf2_per_cu_data
*per_cu
;
23162 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23164 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23165 reading of the chain. As such dependencies remain valid it is not much
23166 useful to track and undo them during QUIT cleanups. */
23167 if (per_cu
->cu
== NULL
)
23170 if (per_cu
->cu
->mark
)
23172 per_cu
->cu
->mark
= 1;
23174 if (per_cu
->cu
->dependencies
!= NULL
)
23175 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23180 /* Set the mark field in CU and in every other compilation unit in the
23181 cache that we must keep because we are keeping CU. */
23184 dwarf2_mark (struct dwarf2_cu
*cu
)
23189 if (cu
->dependencies
!= NULL
)
23190 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23194 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23198 per_cu
->cu
->mark
= 0;
23199 per_cu
= per_cu
->cu
->read_in_chain
;
23203 /* Trivial hash function for partial_die_info: the hash value of a DIE
23204 is its offset in .debug_info for this objfile. */
23207 partial_die_hash (const void *item
)
23209 const struct partial_die_info
*part_die
23210 = (const struct partial_die_info
*) item
;
23212 return to_underlying (part_die
->sect_off
);
23215 /* Trivial comparison function for partial_die_info structures: two DIEs
23216 are equal if they have the same offset. */
23219 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23221 const struct partial_die_info
*part_die_lhs
23222 = (const struct partial_die_info
*) item_lhs
;
23223 const struct partial_die_info
*part_die_rhs
23224 = (const struct partial_die_info
*) item_rhs
;
23226 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23229 static struct cmd_list_element
*set_dwarf_cmdlist
;
23230 static struct cmd_list_element
*show_dwarf_cmdlist
;
23233 set_dwarf_cmd (const char *args
, int from_tty
)
23235 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23240 show_dwarf_cmd (const char *args
, int from_tty
)
23242 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23245 /* Free data associated with OBJFILE, if necessary. */
23248 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
23250 struct dwarf2_per_objfile
*data
= (struct dwarf2_per_objfile
*) d
;
23253 /* Make sure we don't accidentally use dwarf2_per_objfile while
23255 dwarf2_per_objfile
= NULL
;
23257 for (ix
= 0; ix
< data
->n_comp_units
; ++ix
)
23258 VEC_free (dwarf2_per_cu_ptr
, data
->all_comp_units
[ix
]->imported_symtabs
);
23260 for (ix
= 0; ix
< data
->n_type_units
; ++ix
)
23261 VEC_free (dwarf2_per_cu_ptr
,
23262 data
->all_type_units
[ix
]->per_cu
.imported_symtabs
);
23263 xfree (data
->all_type_units
);
23265 VEC_free (dwarf2_section_info_def
, data
->types
);
23267 if (data
->dwo_files
)
23268 free_dwo_files (data
->dwo_files
, objfile
);
23269 if (data
->dwp_file
)
23270 gdb_bfd_unref (data
->dwp_file
->dbfd
);
23272 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
23273 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
23277 /* The "save gdb-index" command. */
23279 /* In-memory buffer to prepare data to be written later to a file. */
23283 /* Copy DATA to the end of the buffer. */
23284 template<typename T
>
23285 void append_data (const T
&data
)
23287 std::copy (reinterpret_cast<const gdb_byte
*> (&data
),
23288 reinterpret_cast<const gdb_byte
*> (&data
+ 1),
23289 grow (sizeof (data
)));
23292 /* Copy CSTR (a zero-terminated string) to the end of buffer. The
23293 terminating zero is appended too. */
23294 void append_cstr0 (const char *cstr
)
23296 const size_t size
= strlen (cstr
) + 1;
23297 std::copy (cstr
, cstr
+ size
, grow (size
));
23300 /* Accept a host-format integer in VAL and append it to the buffer
23301 as a target-format integer which is LEN bytes long. */
23302 void append_uint (size_t len
, bfd_endian byte_order
, ULONGEST val
)
23304 ::store_unsigned_integer (grow (len
), len
, byte_order
, val
);
23307 /* Return the size of the buffer. */
23308 size_t size () const
23310 return m_vec
.size ();
23313 /* Write the buffer to FILE. */
23314 void file_write (FILE *file
) const
23316 if (::fwrite (m_vec
.data (), 1, m_vec
.size (), file
) != m_vec
.size ())
23317 error (_("couldn't write data to file"));
23321 /* Grow SIZE bytes at the end of the buffer. Returns a pointer to
23322 the start of the new block. */
23323 gdb_byte
*grow (size_t size
)
23325 m_vec
.resize (m_vec
.size () + size
);
23326 return &*m_vec
.end () - size
;
23329 gdb::byte_vector m_vec
;
23332 /* An entry in the symbol table. */
23333 struct symtab_index_entry
23335 /* The name of the symbol. */
23337 /* The offset of the name in the constant pool. */
23338 offset_type index_offset
;
23339 /* A sorted vector of the indices of all the CUs that hold an object
23341 std::vector
<offset_type
> cu_indices
;
23344 /* The symbol table. This is a power-of-2-sized hash table. */
23345 struct mapped_symtab
23349 data
.resize (1024);
23352 offset_type n_elements
= 0;
23353 std::vector
<symtab_index_entry
> data
;
23356 /* Find a slot in SYMTAB for the symbol NAME. Returns a reference to
23359 Function is used only during write_hash_table so no index format backward
23360 compatibility is needed. */
23362 static symtab_index_entry
&
23363 find_slot (struct mapped_symtab
*symtab
, const char *name
)
23365 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
23367 index
= hash
& (symtab
->data
.size () - 1);
23368 step
= ((hash
* 17) & (symtab
->data
.size () - 1)) | 1;
23372 if (symtab
->data
[index
].name
== NULL
23373 || strcmp (name
, symtab
->data
[index
].name
) == 0)
23374 return symtab
->data
[index
];
23375 index
= (index
+ step
) & (symtab
->data
.size () - 1);
23379 /* Expand SYMTAB's hash table. */
23382 hash_expand (struct mapped_symtab
*symtab
)
23384 auto old_entries
= std::move (symtab
->data
);
23386 symtab
->data
.clear ();
23387 symtab
->data
.resize (old_entries
.size () * 2);
23389 for (auto &it
: old_entries
)
23390 if (it
.name
!= NULL
)
23392 auto &ref
= find_slot (symtab
, it
.name
);
23393 ref
= std::move (it
);
23397 /* Add an entry to SYMTAB. NAME is the name of the symbol.
23398 CU_INDEX is the index of the CU in which the symbol appears.
23399 IS_STATIC is one if the symbol is static, otherwise zero (global). */
23402 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
23403 int is_static
, gdb_index_symbol_kind kind
,
23404 offset_type cu_index
)
23406 offset_type cu_index_and_attrs
;
23408 ++symtab
->n_elements
;
23409 if (4 * symtab
->n_elements
/ 3 >= symtab
->data
.size ())
23410 hash_expand (symtab
);
23412 symtab_index_entry
&slot
= find_slot (symtab
, name
);
23413 if (slot
.name
== NULL
)
23416 /* index_offset is set later. */
23419 cu_index_and_attrs
= 0;
23420 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
23421 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
23422 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
23424 /* We don't want to record an index value twice as we want to avoid the
23426 We process all global symbols and then all static symbols
23427 (which would allow us to avoid the duplication by only having to check
23428 the last entry pushed), but a symbol could have multiple kinds in one CU.
23429 To keep things simple we don't worry about the duplication here and
23430 sort and uniqufy the list after we've processed all symbols. */
23431 slot
.cu_indices
.push_back (cu_index_and_attrs
);
23434 /* Sort and remove duplicates of all symbols' cu_indices lists. */
23437 uniquify_cu_indices (struct mapped_symtab
*symtab
)
23439 for (auto &entry
: symtab
->data
)
23441 if (entry
.name
!= NULL
&& !entry
.cu_indices
.empty ())
23443 auto &cu_indices
= entry
.cu_indices
;
23444 std::sort (cu_indices
.begin (), cu_indices
.end ());
23445 auto from
= std::unique (cu_indices
.begin (), cu_indices
.end ());
23446 cu_indices
.erase (from
, cu_indices
.end ());
23451 /* A form of 'const char *' suitable for container keys. Only the
23452 pointer is stored. The strings themselves are compared, not the
23457 c_str_view (const char *cstr
)
23461 bool operator== (const c_str_view
&other
) const
23463 return strcmp (m_cstr
, other
.m_cstr
) == 0;
23467 friend class c_str_view_hasher
;
23468 const char *const m_cstr
;
23471 /* A std::unordered_map::hasher for c_str_view that uses the right
23472 hash function for strings in a mapped index. */
23473 class c_str_view_hasher
23476 size_t operator () (const c_str_view
&x
) const
23478 return mapped_index_string_hash (INT_MAX
, x
.m_cstr
);
23482 /* A std::unordered_map::hasher for std::vector<>. */
23483 template<typename T
>
23484 class vector_hasher
23487 size_t operator () (const std::vector
<T
> &key
) const
23489 return iterative_hash (key
.data (),
23490 sizeof (key
.front ()) * key
.size (), 0);
23494 /* Write the mapped hash table SYMTAB to the data buffer OUTPUT, with
23495 constant pool entries going into the data buffer CPOOL. */
23498 write_hash_table (mapped_symtab
*symtab
, data_buf
&output
, data_buf
&cpool
)
23501 /* Elements are sorted vectors of the indices of all the CUs that
23502 hold an object of this name. */
23503 std::unordered_map
<std::vector
<offset_type
>, offset_type
,
23504 vector_hasher
<offset_type
>>
23507 /* We add all the index vectors to the constant pool first, to
23508 ensure alignment is ok. */
23509 for (symtab_index_entry
&entry
: symtab
->data
)
23511 if (entry
.name
== NULL
)
23513 gdb_assert (entry
.index_offset
== 0);
23515 /* Finding before inserting is faster than always trying to
23516 insert, because inserting always allocates a node, does the
23517 lookup, and then destroys the new node if another node
23518 already had the same key. C++17 try_emplace will avoid
23521 = symbol_hash_table
.find (entry
.cu_indices
);
23522 if (found
!= symbol_hash_table
.end ())
23524 entry
.index_offset
= found
->second
;
23528 symbol_hash_table
.emplace (entry
.cu_indices
, cpool
.size ());
23529 entry
.index_offset
= cpool
.size ();
23530 cpool
.append_data (MAYBE_SWAP (entry
.cu_indices
.size ()));
23531 for (const auto index
: entry
.cu_indices
)
23532 cpool
.append_data (MAYBE_SWAP (index
));
23536 /* Now write out the hash table. */
23537 std::unordered_map
<c_str_view
, offset_type
, c_str_view_hasher
> str_table
;
23538 for (const auto &entry
: symtab
->data
)
23540 offset_type str_off
, vec_off
;
23542 if (entry
.name
!= NULL
)
23544 const auto insertpair
= str_table
.emplace (entry
.name
, cpool
.size ());
23545 if (insertpair
.second
)
23546 cpool
.append_cstr0 (entry
.name
);
23547 str_off
= insertpair
.first
->second
;
23548 vec_off
= entry
.index_offset
;
23552 /* While 0 is a valid constant pool index, it is not valid
23553 to have 0 for both offsets. */
23558 output
.append_data (MAYBE_SWAP (str_off
));
23559 output
.append_data (MAYBE_SWAP (vec_off
));
23563 typedef std::unordered_map
<partial_symtab
*, unsigned int> psym_index_map
;
23565 /* Helper struct for building the address table. */
23566 struct addrmap_index_data
23568 addrmap_index_data (data_buf
&addr_vec_
, psym_index_map
&cu_index_htab_
)
23569 : addr_vec (addr_vec_
), cu_index_htab (cu_index_htab_
)
23572 struct objfile
*objfile
;
23573 data_buf
&addr_vec
;
23574 psym_index_map
&cu_index_htab
;
23576 /* Non-zero if the previous_* fields are valid.
23577 We can't write an entry until we see the next entry (since it is only then
23578 that we know the end of the entry). */
23579 int previous_valid
;
23580 /* Index of the CU in the table of all CUs in the index file. */
23581 unsigned int previous_cu_index
;
23582 /* Start address of the CU. */
23583 CORE_ADDR previous_cu_start
;
23586 /* Write an address entry to ADDR_VEC. */
23589 add_address_entry (struct objfile
*objfile
, data_buf
&addr_vec
,
23590 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
23592 CORE_ADDR baseaddr
;
23594 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23596 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
23597 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
23598 addr_vec
.append_data (MAYBE_SWAP (cu_index
));
23601 /* Worker function for traversing an addrmap to build the address table. */
23604 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
23606 struct addrmap_index_data
*data
= (struct addrmap_index_data
*) datap
;
23607 struct partial_symtab
*pst
= (struct partial_symtab
*) obj
;
23609 if (data
->previous_valid
)
23610 add_address_entry (data
->objfile
, data
->addr_vec
,
23611 data
->previous_cu_start
, start_addr
,
23612 data
->previous_cu_index
);
23614 data
->previous_cu_start
= start_addr
;
23617 const auto it
= data
->cu_index_htab
.find (pst
);
23618 gdb_assert (it
!= data
->cu_index_htab
.cend ());
23619 data
->previous_cu_index
= it
->second
;
23620 data
->previous_valid
= 1;
23623 data
->previous_valid
= 0;
23628 /* Write OBJFILE's address map to ADDR_VEC.
23629 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
23630 in the index file. */
23633 write_address_map (struct objfile
*objfile
, data_buf
&addr_vec
,
23634 psym_index_map
&cu_index_htab
)
23636 struct addrmap_index_data
addrmap_index_data (addr_vec
, cu_index_htab
);
23638 /* When writing the address table, we have to cope with the fact that
23639 the addrmap iterator only provides the start of a region; we have to
23640 wait until the next invocation to get the start of the next region. */
23642 addrmap_index_data
.objfile
= objfile
;
23643 addrmap_index_data
.previous_valid
= 0;
23645 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
23646 &addrmap_index_data
);
23648 /* It's highly unlikely the last entry (end address = 0xff...ff)
23649 is valid, but we should still handle it.
23650 The end address is recorded as the start of the next region, but that
23651 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
23653 if (addrmap_index_data
.previous_valid
)
23654 add_address_entry (objfile
, addr_vec
,
23655 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
23656 addrmap_index_data
.previous_cu_index
);
23659 /* Return the symbol kind of PSYM. */
23661 static gdb_index_symbol_kind
23662 symbol_kind (struct partial_symbol
*psym
)
23664 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
23665 enum address_class aclass
= PSYMBOL_CLASS (psym
);
23673 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
23675 return GDB_INDEX_SYMBOL_KIND_TYPE
;
23677 case LOC_CONST_BYTES
:
23678 case LOC_OPTIMIZED_OUT
:
23680 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
23682 /* Note: It's currently impossible to recognize psyms as enum values
23683 short of reading the type info. For now punt. */
23684 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
23686 /* There are other LOC_FOO values that one might want to classify
23687 as variables, but dwarf2read.c doesn't currently use them. */
23688 return GDB_INDEX_SYMBOL_KIND_OTHER
;
23690 case STRUCT_DOMAIN
:
23691 return GDB_INDEX_SYMBOL_KIND_TYPE
;
23693 return GDB_INDEX_SYMBOL_KIND_OTHER
;
23697 /* Add a list of partial symbols to SYMTAB. */
23700 write_psymbols (struct mapped_symtab
*symtab
,
23701 std::unordered_set
<partial_symbol
*> &psyms_seen
,
23702 struct partial_symbol
**psymp
,
23704 offset_type cu_index
,
23707 for (; count
-- > 0; ++psymp
)
23709 struct partial_symbol
*psym
= *psymp
;
23711 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
23712 error (_("Ada is not currently supported by the index"));
23714 /* Only add a given psymbol once. */
23715 if (psyms_seen
.insert (psym
).second
)
23717 gdb_index_symbol_kind kind
= symbol_kind (psym
);
23719 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
23720 is_static
, kind
, cu_index
);
23725 /* A helper struct used when iterating over debug_types. */
23726 struct signatured_type_index_data
23728 signatured_type_index_data (data_buf
&types_list_
,
23729 std::unordered_set
<partial_symbol
*> &psyms_seen_
)
23730 : types_list (types_list_
), psyms_seen (psyms_seen_
)
23733 struct objfile
*objfile
;
23734 struct mapped_symtab
*symtab
;
23735 data_buf
&types_list
;
23736 std::unordered_set
<partial_symbol
*> &psyms_seen
;
23740 /* A helper function that writes a single signatured_type to an
23744 write_one_signatured_type (void **slot
, void *d
)
23746 struct signatured_type_index_data
*info
23747 = (struct signatured_type_index_data
*) d
;
23748 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
23749 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
23751 write_psymbols (info
->symtab
,
23753 &info
->objfile
->global_psymbols
[psymtab
->globals_offset
],
23754 psymtab
->n_global_syms
, info
->cu_index
,
23756 write_psymbols (info
->symtab
,
23758 &info
->objfile
->static_psymbols
[psymtab
->statics_offset
],
23759 psymtab
->n_static_syms
, info
->cu_index
,
23762 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
23763 to_underlying (entry
->per_cu
.sect_off
));
23764 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
23765 to_underlying (entry
->type_offset_in_tu
));
23766 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
, entry
->signature
);
23773 /* Recurse into all "included" dependencies and count their symbols as
23774 if they appeared in this psymtab. */
23777 recursively_count_psymbols (struct partial_symtab
*psymtab
,
23778 size_t &psyms_seen
)
23780 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
23781 if (psymtab
->dependencies
[i
]->user
!= NULL
)
23782 recursively_count_psymbols (psymtab
->dependencies
[i
],
23785 psyms_seen
+= psymtab
->n_global_syms
;
23786 psyms_seen
+= psymtab
->n_static_syms
;
23789 /* Recurse into all "included" dependencies and write their symbols as
23790 if they appeared in this psymtab. */
23793 recursively_write_psymbols (struct objfile
*objfile
,
23794 struct partial_symtab
*psymtab
,
23795 struct mapped_symtab
*symtab
,
23796 std::unordered_set
<partial_symbol
*> &psyms_seen
,
23797 offset_type cu_index
)
23801 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
23802 if (psymtab
->dependencies
[i
]->user
!= NULL
)
23803 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
23804 symtab
, psyms_seen
, cu_index
);
23806 write_psymbols (symtab
,
23808 &objfile
->global_psymbols
[psymtab
->globals_offset
],
23809 psymtab
->n_global_syms
, cu_index
,
23811 write_psymbols (symtab
,
23813 &objfile
->static_psymbols
[psymtab
->statics_offset
],
23814 psymtab
->n_static_syms
, cu_index
,
23818 /* Create an index file for OBJFILE in the directory DIR. */
23821 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
23823 if (dwarf2_per_objfile
->using_index
)
23824 error (_("Cannot use an index to create the index"));
23826 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
23827 error (_("Cannot make an index when the file has multiple .debug_types sections"));
23829 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
23833 if (stat (objfile_name (objfile
), &st
) < 0)
23834 perror_with_name (objfile_name (objfile
));
23836 std::string
filename (std::string (dir
) + SLASH_STRING
23837 + lbasename (objfile_name (objfile
)) + INDEX_SUFFIX
);
23839 FILE *out_file
= gdb_fopen_cloexec (filename
.c_str (), "wb").release ();
23841 error (_("Can't open `%s' for writing"), filename
.c_str ());
23843 /* Order matters here; we want FILE to be closed before FILENAME is
23844 unlinked, because on MS-Windows one cannot delete a file that is
23845 still open. (Don't call anything here that might throw until
23846 file_closer is created.) */
23847 gdb::unlinker
unlink_file (filename
.c_str ());
23848 gdb_file_up
close_out_file (out_file
);
23850 mapped_symtab symtab
;
23853 /* While we're scanning CU's create a table that maps a psymtab pointer
23854 (which is what addrmap records) to its index (which is what is recorded
23855 in the index file). This will later be needed to write the address
23857 psym_index_map cu_index_htab
;
23858 cu_index_htab
.reserve (dwarf2_per_objfile
->n_comp_units
);
23860 /* The CU list is already sorted, so we don't need to do additional
23861 work here. Also, the debug_types entries do not appear in
23862 all_comp_units, but only in their own hash table. */
23864 /* The psyms_seen set is potentially going to be largish (~40k
23865 elements when indexing a -g3 build of GDB itself). Estimate the
23866 number of elements in order to avoid too many rehashes, which
23867 require rebuilding buckets and thus many trips to
23869 size_t psyms_count
= 0;
23870 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
23872 struct dwarf2_per_cu_data
*per_cu
23873 = dwarf2_per_objfile
->all_comp_units
[i
];
23874 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
23876 if (psymtab
!= NULL
&& psymtab
->user
== NULL
)
23877 recursively_count_psymbols (psymtab
, psyms_count
);
23879 /* Generating an index for gdb itself shows a ratio of
23880 TOTAL_SEEN_SYMS/UNIQUE_SYMS or ~5. 4 seems like a good bet. */
23881 std::unordered_set
<partial_symbol
*> psyms_seen (psyms_count
/ 4);
23882 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
23884 struct dwarf2_per_cu_data
*per_cu
23885 = dwarf2_per_objfile
->all_comp_units
[i
];
23886 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
23888 /* CU of a shared file from 'dwz -m' may be unused by this main file.
23889 It may be referenced from a local scope but in such case it does not
23890 need to be present in .gdb_index. */
23891 if (psymtab
== NULL
)
23894 if (psymtab
->user
== NULL
)
23895 recursively_write_psymbols (objfile
, psymtab
, &symtab
,
23898 const auto insertpair
= cu_index_htab
.emplace (psymtab
, i
);
23899 gdb_assert (insertpair
.second
);
23901 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
23902 to_underlying (per_cu
->sect_off
));
23903 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
23906 /* Dump the address map. */
23908 write_address_map (objfile
, addr_vec
, cu_index_htab
);
23910 /* Write out the .debug_type entries, if any. */
23911 data_buf types_cu_list
;
23912 if (dwarf2_per_objfile
->signatured_types
)
23914 signatured_type_index_data
sig_data (types_cu_list
,
23917 sig_data
.objfile
= objfile
;
23918 sig_data
.symtab
= &symtab
;
23919 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
23920 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
23921 write_one_signatured_type
, &sig_data
);
23924 /* Now that we've processed all symbols we can shrink their cu_indices
23926 uniquify_cu_indices (&symtab
);
23928 data_buf symtab_vec
, constant_pool
;
23929 write_hash_table (&symtab
, symtab_vec
, constant_pool
);
23932 const offset_type size_of_contents
= 6 * sizeof (offset_type
);
23933 offset_type total_len
= size_of_contents
;
23935 /* The version number. */
23936 contents
.append_data (MAYBE_SWAP (8));
23938 /* The offset of the CU list from the start of the file. */
23939 contents
.append_data (MAYBE_SWAP (total_len
));
23940 total_len
+= cu_list
.size ();
23942 /* The offset of the types CU list from the start of the file. */
23943 contents
.append_data (MAYBE_SWAP (total_len
));
23944 total_len
+= types_cu_list
.size ();
23946 /* The offset of the address table from the start of the file. */
23947 contents
.append_data (MAYBE_SWAP (total_len
));
23948 total_len
+= addr_vec
.size ();
23950 /* The offset of the symbol table from the start of the file. */
23951 contents
.append_data (MAYBE_SWAP (total_len
));
23952 total_len
+= symtab_vec
.size ();
23954 /* The offset of the constant pool from the start of the file. */
23955 contents
.append_data (MAYBE_SWAP (total_len
));
23956 total_len
+= constant_pool
.size ();
23958 gdb_assert (contents
.size () == size_of_contents
);
23960 contents
.file_write (out_file
);
23961 cu_list
.file_write (out_file
);
23962 types_cu_list
.file_write (out_file
);
23963 addr_vec
.file_write (out_file
);
23964 symtab_vec
.file_write (out_file
);
23965 constant_pool
.file_write (out_file
);
23967 /* We want to keep the file. */
23968 unlink_file
.keep ();
23971 /* Implementation of the `save gdb-index' command.
23973 Note that the file format used by this command is documented in the
23974 GDB manual. Any changes here must be documented there. */
23977 save_gdb_index_command (const char *arg
, int from_tty
)
23979 struct objfile
*objfile
;
23982 error (_("usage: save gdb-index DIRECTORY"));
23984 ALL_OBJFILES (objfile
)
23988 /* If the objfile does not correspond to an actual file, skip it. */
23989 if (stat (objfile_name (objfile
), &st
) < 0)
23993 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
23994 dwarf2_objfile_data_key
);
23995 if (dwarf2_per_objfile
)
24000 write_psymtabs_to_index (objfile
, arg
);
24002 CATCH (except
, RETURN_MASK_ERROR
)
24004 exception_fprintf (gdb_stderr
, except
,
24005 _("Error while writing index for `%s': "),
24006 objfile_name (objfile
));
24015 int dwarf_always_disassemble
;
24018 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
24019 struct cmd_list_element
*c
, const char *value
)
24021 fprintf_filtered (file
,
24022 _("Whether to always disassemble "
24023 "DWARF expressions is %s.\n"),
24028 show_check_physname (struct ui_file
*file
, int from_tty
,
24029 struct cmd_list_element
*c
, const char *value
)
24031 fprintf_filtered (file
,
24032 _("Whether to check \"physname\" is %s.\n"),
24037 _initialize_dwarf2_read (void)
24039 struct cmd_list_element
*c
;
24041 dwarf2_objfile_data_key
24042 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
24044 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
24045 Set DWARF specific variables.\n\
24046 Configure DWARF variables such as the cache size"),
24047 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24048 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24050 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
24051 Show DWARF specific variables\n\
24052 Show DWARF variables such as the cache size"),
24053 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24054 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24056 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24057 &dwarf_max_cache_age
, _("\
24058 Set the upper bound on the age of cached DWARF compilation units."), _("\
24059 Show the upper bound on the age of cached DWARF compilation units."), _("\
24060 A higher limit means that cached compilation units will be stored\n\
24061 in memory longer, and more total memory will be used. Zero disables\n\
24062 caching, which can slow down startup."),
24064 show_dwarf_max_cache_age
,
24065 &set_dwarf_cmdlist
,
24066 &show_dwarf_cmdlist
);
24068 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
24069 &dwarf_always_disassemble
, _("\
24070 Set whether `info address' always disassembles DWARF expressions."), _("\
24071 Show whether `info address' always disassembles DWARF expressions."), _("\
24072 When enabled, DWARF expressions are always printed in an assembly-like\n\
24073 syntax. When disabled, expressions will be printed in a more\n\
24074 conversational style, when possible."),
24076 show_dwarf_always_disassemble
,
24077 &set_dwarf_cmdlist
,
24078 &show_dwarf_cmdlist
);
24080 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24081 Set debugging of the DWARF reader."), _("\
24082 Show debugging of the DWARF reader."), _("\
24083 When enabled (non-zero), debugging messages are printed during DWARF\n\
24084 reading and symtab expansion. A value of 1 (one) provides basic\n\
24085 information. A value greater than 1 provides more verbose information."),
24088 &setdebuglist
, &showdebuglist
);
24090 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24091 Set debugging of the DWARF DIE reader."), _("\
24092 Show debugging of the DWARF DIE reader."), _("\
24093 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24094 The value is the maximum depth to print."),
24097 &setdebuglist
, &showdebuglist
);
24099 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24100 Set debugging of the dwarf line reader."), _("\
24101 Show debugging of the dwarf line reader."), _("\
24102 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24103 A value of 1 (one) provides basic information.\n\
24104 A value greater than 1 provides more verbose information."),
24107 &setdebuglist
, &showdebuglist
);
24109 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24110 Set cross-checking of \"physname\" code against demangler."), _("\
24111 Show cross-checking of \"physname\" code against demangler."), _("\
24112 When enabled, GDB's internal \"physname\" code is checked against\n\
24114 NULL
, show_check_physname
,
24115 &setdebuglist
, &showdebuglist
);
24117 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24118 no_class
, &use_deprecated_index_sections
, _("\
24119 Set whether to use deprecated gdb_index sections."), _("\
24120 Show whether to use deprecated gdb_index sections."), _("\
24121 When enabled, deprecated .gdb_index sections are used anyway.\n\
24122 Normally they are ignored either because of a missing feature or\n\
24123 performance issue.\n\
24124 Warning: This option must be enabled before gdb reads the file."),
24127 &setlist
, &showlist
);
24129 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
24131 Save a gdb-index file.\n\
24132 Usage: save gdb-index DIRECTORY"),
24134 set_cmd_completer (c
, filename_completer
);
24136 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24137 &dwarf2_locexpr_funcs
);
24138 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24139 &dwarf2_loclist_funcs
);
24141 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24142 &dwarf2_block_frame_base_locexpr_funcs
);
24143 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24144 &dwarf2_block_frame_base_loclist_funcs
);