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"
79 #include <sys/types.h>
81 #include <unordered_set>
82 #include <unordered_map>
84 typedef struct symbol
*symbolp
;
87 /* When == 1, print basic high level tracing messages.
88 When > 1, be more verbose.
89 This is in contrast to the low level DIE reading of dwarf_die_debug. */
90 static unsigned int dwarf_read_debug
= 0;
92 /* When non-zero, dump DIEs after they are read in. */
93 static unsigned int dwarf_die_debug
= 0;
95 /* When non-zero, dump line number entries as they are read in. */
96 static unsigned int dwarf_line_debug
= 0;
98 /* When non-zero, cross-check physname against demangler. */
99 static int check_physname
= 0;
101 /* When non-zero, do not reject deprecated .gdb_index sections. */
102 static int use_deprecated_index_sections
= 0;
104 static const struct objfile_data
*dwarf2_objfile_data_key
;
106 /* The "aclass" indices for various kinds of computed DWARF symbols. */
108 static int dwarf2_locexpr_index
;
109 static int dwarf2_loclist_index
;
110 static int dwarf2_locexpr_block_index
;
111 static int dwarf2_loclist_block_index
;
113 /* A descriptor for dwarf sections.
115 S.ASECTION, SIZE are typically initialized when the objfile is first
116 scanned. BUFFER, READIN are filled in later when the section is read.
117 If the section contained compressed data then SIZE is updated to record
118 the uncompressed size of the section.
120 DWP file format V2 introduces a wrinkle that is easiest to handle by
121 creating the concept of virtual sections contained within a real section.
122 In DWP V2 the sections of the input DWO files are concatenated together
123 into one section, but section offsets are kept relative to the original
125 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
126 the real section this "virtual" section is contained in, and BUFFER,SIZE
127 describe the virtual section. */
129 struct dwarf2_section_info
133 /* If this is a real section, the bfd section. */
135 /* If this is a virtual section, pointer to the containing ("real")
137 struct dwarf2_section_info
*containing_section
;
139 /* Pointer to section data, only valid if readin. */
140 const gdb_byte
*buffer
;
141 /* The size of the section, real or virtual. */
143 /* If this is a virtual section, the offset in the real section.
144 Only valid if is_virtual. */
145 bfd_size_type virtual_offset
;
146 /* True if we have tried to read this section. */
148 /* True if this is a virtual section, False otherwise.
149 This specifies which of s.section and s.containing_section to use. */
153 typedef struct dwarf2_section_info dwarf2_section_info_def
;
154 DEF_VEC_O (dwarf2_section_info_def
);
156 /* All offsets in the index are of this type. It must be
157 architecture-independent. */
158 typedef uint32_t offset_type
;
160 DEF_VEC_I (offset_type
);
162 /* Ensure only legit values are used. */
163 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
165 gdb_assert ((unsigned int) (value) <= 1); \
166 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
169 /* Ensure only legit values are used. */
170 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
172 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
173 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
174 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
177 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
178 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
180 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
181 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
184 /* A description of the mapped index. The file format is described in
185 a comment by the code that writes the index. */
188 /* Index data format version. */
191 /* The total length of the buffer. */
194 /* A pointer to the address table data. */
195 const gdb_byte
*address_table
;
197 /* Size of the address table data in bytes. */
198 offset_type address_table_size
;
200 /* The symbol table, implemented as a hash table. */
201 const offset_type
*symbol_table
;
203 /* Size in slots, each slot is 2 offset_types. */
204 offset_type symbol_table_slots
;
206 /* A pointer to the constant pool. */
207 const char *constant_pool
;
210 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
211 DEF_VEC_P (dwarf2_per_cu_ptr
);
215 int nr_uniq_abbrev_tables
;
217 int nr_symtab_sharers
;
218 int nr_stmt_less_type_units
;
219 int nr_all_type_units_reallocs
;
222 /* Collection of data recorded per objfile.
223 This hangs off of dwarf2_objfile_data_key. */
225 struct dwarf2_per_objfile
227 struct dwarf2_section_info info
;
228 struct dwarf2_section_info abbrev
;
229 struct dwarf2_section_info line
;
230 struct dwarf2_section_info loc
;
231 struct dwarf2_section_info loclists
;
232 struct dwarf2_section_info macinfo
;
233 struct dwarf2_section_info macro
;
234 struct dwarf2_section_info str
;
235 struct dwarf2_section_info line_str
;
236 struct dwarf2_section_info ranges
;
237 struct dwarf2_section_info rnglists
;
238 struct dwarf2_section_info addr
;
239 struct dwarf2_section_info frame
;
240 struct dwarf2_section_info eh_frame
;
241 struct dwarf2_section_info gdb_index
;
243 VEC (dwarf2_section_info_def
) *types
;
246 struct objfile
*objfile
;
248 /* Table of all the compilation units. This is used to locate
249 the target compilation unit of a particular reference. */
250 struct dwarf2_per_cu_data
**all_comp_units
;
252 /* The number of compilation units in ALL_COMP_UNITS. */
255 /* The number of .debug_types-related CUs. */
258 /* The number of elements allocated in all_type_units.
259 If there are skeleton-less TUs, we add them to all_type_units lazily. */
260 int n_allocated_type_units
;
262 /* The .debug_types-related CUs (TUs).
263 This is stored in malloc space because we may realloc it. */
264 struct signatured_type
**all_type_units
;
266 /* Table of struct type_unit_group objects.
267 The hash key is the DW_AT_stmt_list value. */
268 htab_t type_unit_groups
;
270 /* A table mapping .debug_types signatures to its signatured_type entry.
271 This is NULL if the .debug_types section hasn't been read in yet. */
272 htab_t signatured_types
;
274 /* Type unit statistics, to see how well the scaling improvements
276 struct tu_stats tu_stats
;
278 /* A chain of compilation units that are currently read in, so that
279 they can be freed later. */
280 struct dwarf2_per_cu_data
*read_in_chain
;
282 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
283 This is NULL if the table hasn't been allocated yet. */
286 /* Non-zero if we've check for whether there is a DWP file. */
289 /* The DWP file if there is one, or NULL. */
290 struct dwp_file
*dwp_file
;
292 /* The shared '.dwz' file, if one exists. This is used when the
293 original data was compressed using 'dwz -m'. */
294 struct dwz_file
*dwz_file
;
296 /* A flag indicating wether this objfile has a section loaded at a
298 int has_section_at_zero
;
300 /* True if we are using the mapped index,
301 or we are faking it for OBJF_READNOW's sake. */
302 unsigned char using_index
;
304 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
305 struct mapped_index
*index_table
;
307 /* When using index_table, this keeps track of all quick_file_names entries.
308 TUs typically share line table entries with a CU, so we maintain a
309 separate table of all line table entries to support the sharing.
310 Note that while there can be way more TUs than CUs, we've already
311 sorted all the TUs into "type unit groups", grouped by their
312 DW_AT_stmt_list value. Therefore the only sharing done here is with a
313 CU and its associated TU group if there is one. */
314 htab_t quick_file_names_table
;
316 /* Set during partial symbol reading, to prevent queueing of full
318 int reading_partial_symbols
;
320 /* Table mapping type DIEs to their struct type *.
321 This is NULL if not allocated yet.
322 The mapping is done via (CU/TU + DIE offset) -> type. */
323 htab_t die_type_hash
;
325 /* The CUs we recently read. */
326 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
328 /* Table containing line_header indexed by offset and offset_in_dwz. */
329 htab_t line_header_hash
;
332 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
334 /* Default names of the debugging sections. */
336 /* Note that if the debugging section has been compressed, it might
337 have a name like .zdebug_info. */
339 static const struct dwarf2_debug_sections dwarf2_elf_names
=
341 { ".debug_info", ".zdebug_info" },
342 { ".debug_abbrev", ".zdebug_abbrev" },
343 { ".debug_line", ".zdebug_line" },
344 { ".debug_loc", ".zdebug_loc" },
345 { ".debug_loclists", ".zdebug_loclists" },
346 { ".debug_macinfo", ".zdebug_macinfo" },
347 { ".debug_macro", ".zdebug_macro" },
348 { ".debug_str", ".zdebug_str" },
349 { ".debug_line_str", ".zdebug_line_str" },
350 { ".debug_ranges", ".zdebug_ranges" },
351 { ".debug_rnglists", ".zdebug_rnglists" },
352 { ".debug_types", ".zdebug_types" },
353 { ".debug_addr", ".zdebug_addr" },
354 { ".debug_frame", ".zdebug_frame" },
355 { ".eh_frame", NULL
},
356 { ".gdb_index", ".zgdb_index" },
360 /* List of DWO/DWP sections. */
362 static const struct dwop_section_names
364 struct dwarf2_section_names abbrev_dwo
;
365 struct dwarf2_section_names info_dwo
;
366 struct dwarf2_section_names line_dwo
;
367 struct dwarf2_section_names loc_dwo
;
368 struct dwarf2_section_names loclists_dwo
;
369 struct dwarf2_section_names macinfo_dwo
;
370 struct dwarf2_section_names macro_dwo
;
371 struct dwarf2_section_names str_dwo
;
372 struct dwarf2_section_names str_offsets_dwo
;
373 struct dwarf2_section_names types_dwo
;
374 struct dwarf2_section_names cu_index
;
375 struct dwarf2_section_names tu_index
;
379 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
380 { ".debug_info.dwo", ".zdebug_info.dwo" },
381 { ".debug_line.dwo", ".zdebug_line.dwo" },
382 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
383 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
384 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
385 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
386 { ".debug_str.dwo", ".zdebug_str.dwo" },
387 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
388 { ".debug_types.dwo", ".zdebug_types.dwo" },
389 { ".debug_cu_index", ".zdebug_cu_index" },
390 { ".debug_tu_index", ".zdebug_tu_index" },
393 /* local data types */
395 /* The data in a compilation unit header, after target2host
396 translation, looks like this. */
397 struct comp_unit_head
401 unsigned char addr_size
;
402 unsigned char signed_addr_p
;
403 sect_offset abbrev_sect_off
;
405 /* Size of file offsets; either 4 or 8. */
406 unsigned int offset_size
;
408 /* Size of the length field; either 4 or 12. */
409 unsigned int initial_length_size
;
411 enum dwarf_unit_type unit_type
;
413 /* Offset to the first byte of this compilation unit header in the
414 .debug_info section, for resolving relative reference dies. */
415 sect_offset sect_off
;
417 /* Offset to first die in this cu from the start of the cu.
418 This will be the first byte following the compilation unit header. */
419 cu_offset first_die_cu_offset
;
421 /* 64-bit signature of this type unit - it is valid only for
422 UNIT_TYPE DW_UT_type. */
425 /* For types, offset in the type's DIE of the type defined by this TU. */
426 cu_offset type_cu_offset_in_tu
;
429 /* Type used for delaying computation of method physnames.
430 See comments for compute_delayed_physnames. */
431 struct delayed_method_info
433 /* The type to which the method is attached, i.e., its parent class. */
436 /* The index of the method in the type's function fieldlists. */
439 /* The index of the method in the fieldlist. */
442 /* The name of the DIE. */
445 /* The DIE associated with this method. */
446 struct die_info
*die
;
449 typedef struct delayed_method_info delayed_method_info
;
450 DEF_VEC_O (delayed_method_info
);
452 /* Internal state when decoding a particular compilation unit. */
455 /* The objfile containing this compilation unit. */
456 struct objfile
*objfile
;
458 /* The header of the compilation unit. */
459 struct comp_unit_head header
;
461 /* Base address of this compilation unit. */
462 CORE_ADDR base_address
;
464 /* Non-zero if base_address has been set. */
467 /* The language we are debugging. */
468 enum language language
;
469 const struct language_defn
*language_defn
;
471 const char *producer
;
473 /* The generic symbol table building routines have separate lists for
474 file scope symbols and all all other scopes (local scopes). So
475 we need to select the right one to pass to add_symbol_to_list().
476 We do it by keeping a pointer to the correct list in list_in_scope.
478 FIXME: The original dwarf code just treated the file scope as the
479 first local scope, and all other local scopes as nested local
480 scopes, and worked fine. Check to see if we really need to
481 distinguish these in buildsym.c. */
482 struct pending
**list_in_scope
;
484 /* The abbrev table for this CU.
485 Normally this points to the abbrev table in the objfile.
486 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
487 struct abbrev_table
*abbrev_table
;
489 /* Hash table holding all the loaded partial DIEs
490 with partial_die->offset.SECT_OFF as hash. */
493 /* Storage for things with the same lifetime as this read-in compilation
494 unit, including partial DIEs. */
495 struct obstack comp_unit_obstack
;
497 /* When multiple dwarf2_cu structures are living in memory, this field
498 chains them all together, so that they can be released efficiently.
499 We will probably also want a generation counter so that most-recently-used
500 compilation units are cached... */
501 struct dwarf2_per_cu_data
*read_in_chain
;
503 /* Backlink to our per_cu entry. */
504 struct dwarf2_per_cu_data
*per_cu
;
506 /* How many compilation units ago was this CU last referenced? */
509 /* A hash table of DIE cu_offset for following references with
510 die_info->offset.sect_off as hash. */
513 /* Full DIEs if read in. */
514 struct die_info
*dies
;
516 /* A set of pointers to dwarf2_per_cu_data objects for compilation
517 units referenced by this one. Only set during full symbol processing;
518 partial symbol tables do not have dependencies. */
521 /* Header data from the line table, during full symbol processing. */
522 struct line_header
*line_header
;
524 /* A list of methods which need to have physnames computed
525 after all type information has been read. */
526 VEC (delayed_method_info
) *method_list
;
528 /* To be copied to symtab->call_site_htab. */
529 htab_t call_site_htab
;
531 /* Non-NULL if this CU came from a DWO file.
532 There is an invariant here that is important to remember:
533 Except for attributes copied from the top level DIE in the "main"
534 (or "stub") file in preparation for reading the DWO file
535 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
536 Either there isn't a DWO file (in which case this is NULL and the point
537 is moot), or there is and either we're not going to read it (in which
538 case this is NULL) or there is and we are reading it (in which case this
540 struct dwo_unit
*dwo_unit
;
542 /* The DW_AT_addr_base attribute if present, zero otherwise
543 (zero is a valid value though).
544 Note this value comes from the Fission stub CU/TU's DIE. */
547 /* The DW_AT_ranges_base attribute if present, zero otherwise
548 (zero is a valid value though).
549 Note this value comes from the Fission stub CU/TU's DIE.
550 Also note that the value is zero in the non-DWO case so this value can
551 be used without needing to know whether DWO files are in use or not.
552 N.B. This does not apply to DW_AT_ranges appearing in
553 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
554 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
555 DW_AT_ranges_base *would* have to be applied, and we'd have to care
556 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
557 ULONGEST ranges_base
;
559 /* Mark used when releasing cached dies. */
560 unsigned int mark
: 1;
562 /* This CU references .debug_loc. See the symtab->locations_valid field.
563 This test is imperfect as there may exist optimized debug code not using
564 any location list and still facing inlining issues if handled as
565 unoptimized code. For a future better test see GCC PR other/32998. */
566 unsigned int has_loclist
: 1;
568 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
569 if all the producer_is_* fields are valid. This information is cached
570 because profiling CU expansion showed excessive time spent in
571 producer_is_gxx_lt_4_6. */
572 unsigned int checked_producer
: 1;
573 unsigned int producer_is_gxx_lt_4_6
: 1;
574 unsigned int producer_is_gcc_lt_4_3
: 1;
575 unsigned int producer_is_icc
: 1;
577 /* When set, the file that we're processing is known to have
578 debugging info for C++ namespaces. GCC 3.3.x did not produce
579 this information, but later versions do. */
581 unsigned int processing_has_namespace_info
: 1;
584 /* Persistent data held for a compilation unit, even when not
585 processing it. We put a pointer to this structure in the
586 read_symtab_private field of the psymtab. */
588 struct dwarf2_per_cu_data
590 /* The start offset and length of this compilation unit.
591 NOTE: Unlike comp_unit_head.length, this length includes
593 If the DIE refers to a DWO file, this is always of the original die,
595 sect_offset sect_off
;
598 /* DWARF standard version this data has been read from (such as 4 or 5). */
601 /* Flag indicating this compilation unit will be read in before
602 any of the current compilation units are processed. */
603 unsigned int queued
: 1;
605 /* This flag will be set when reading partial DIEs if we need to load
606 absolutely all DIEs for this compilation unit, instead of just the ones
607 we think are interesting. It gets set if we look for a DIE in the
608 hash table and don't find it. */
609 unsigned int load_all_dies
: 1;
611 /* Non-zero if this CU is from .debug_types.
612 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
614 unsigned int is_debug_types
: 1;
616 /* Non-zero if this CU is from the .dwz file. */
617 unsigned int is_dwz
: 1;
619 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
620 This flag is only valid if is_debug_types is true.
621 We can't read a CU directly from a DWO file: There are required
622 attributes in the stub. */
623 unsigned int reading_dwo_directly
: 1;
625 /* Non-zero if the TU has been read.
626 This is used to assist the "Stay in DWO Optimization" for Fission:
627 When reading a DWO, it's faster to read TUs from the DWO instead of
628 fetching them from random other DWOs (due to comdat folding).
629 If the TU has already been read, the optimization is unnecessary
630 (and unwise - we don't want to change where gdb thinks the TU lives
632 This flag is only valid if is_debug_types is true. */
633 unsigned int tu_read
: 1;
635 /* The section this CU/TU lives in.
636 If the DIE refers to a DWO file, this is always the original die,
638 struct dwarf2_section_info
*section
;
640 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
641 of the CU cache it gets reset to NULL again. This is left as NULL for
642 dummy CUs (a CU header, but nothing else). */
643 struct dwarf2_cu
*cu
;
645 /* The corresponding objfile.
646 Normally we can get the objfile from dwarf2_per_objfile.
647 However we can enter this file with just a "per_cu" handle. */
648 struct objfile
*objfile
;
650 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
651 is active. Otherwise, the 'psymtab' field is active. */
654 /* The partial symbol table associated with this compilation unit,
655 or NULL for unread partial units. */
656 struct partial_symtab
*psymtab
;
658 /* Data needed by the "quick" functions. */
659 struct dwarf2_per_cu_quick_data
*quick
;
662 /* The CUs we import using DW_TAG_imported_unit. This is filled in
663 while reading psymtabs, used to compute the psymtab dependencies,
664 and then cleared. Then it is filled in again while reading full
665 symbols, and only deleted when the objfile is destroyed.
667 This is also used to work around a difference between the way gold
668 generates .gdb_index version <=7 and the way gdb does. Arguably this
669 is a gold bug. For symbols coming from TUs, gold records in the index
670 the CU that includes the TU instead of the TU itself. This breaks
671 dw2_lookup_symbol: It assumes that if the index says symbol X lives
672 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
673 will find X. Alas TUs live in their own symtab, so after expanding CU Y
674 we need to look in TU Z to find X. Fortunately, this is akin to
675 DW_TAG_imported_unit, so we just use the same mechanism: For
676 .gdb_index version <=7 this also records the TUs that the CU referred
677 to. Concurrently with this change gdb was modified to emit version 8
678 indices so we only pay a price for gold generated indices.
679 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
680 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
683 /* Entry in the signatured_types hash table. */
685 struct signatured_type
687 /* The "per_cu" object of this type.
688 This struct is used iff per_cu.is_debug_types.
689 N.B.: This is the first member so that it's easy to convert pointers
691 struct dwarf2_per_cu_data per_cu
;
693 /* The type's signature. */
696 /* Offset in the TU of the type's DIE, as read from the TU header.
697 If this TU is a DWO stub and the definition lives in a DWO file
698 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
699 cu_offset type_offset_in_tu
;
701 /* Offset in the section of the type's DIE.
702 If the definition lives in a DWO file, this is the offset in the
703 .debug_types.dwo section.
704 The value is zero until the actual value is known.
705 Zero is otherwise not a valid section offset. */
706 sect_offset type_offset_in_section
;
708 /* Type units are grouped by their DW_AT_stmt_list entry so that they
709 can share them. This points to the containing symtab. */
710 struct type_unit_group
*type_unit_group
;
713 The first time we encounter this type we fully read it in and install it
714 in the symbol tables. Subsequent times we only need the type. */
717 /* Containing DWO unit.
718 This field is valid iff per_cu.reading_dwo_directly. */
719 struct dwo_unit
*dwo_unit
;
722 typedef struct signatured_type
*sig_type_ptr
;
723 DEF_VEC_P (sig_type_ptr
);
725 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
726 This includes type_unit_group and quick_file_names. */
728 struct stmt_list_hash
730 /* The DWO unit this table is from or NULL if there is none. */
731 struct dwo_unit
*dwo_unit
;
733 /* Offset in .debug_line or .debug_line.dwo. */
734 sect_offset line_sect_off
;
737 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
738 an object of this type. */
740 struct type_unit_group
742 /* dwarf2read.c's main "handle" on a TU symtab.
743 To simplify things we create an artificial CU that "includes" all the
744 type units using this stmt_list so that the rest of the code still has
745 a "per_cu" handle on the symtab.
746 This PER_CU is recognized by having no section. */
747 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
748 struct dwarf2_per_cu_data per_cu
;
750 /* The TUs that share this DW_AT_stmt_list entry.
751 This is added to while parsing type units to build partial symtabs,
752 and is deleted afterwards and not used again. */
753 VEC (sig_type_ptr
) *tus
;
755 /* The compunit symtab.
756 Type units in a group needn't all be defined in the same source file,
757 so we create an essentially anonymous symtab as the compunit symtab. */
758 struct compunit_symtab
*compunit_symtab
;
760 /* The data used to construct the hash key. */
761 struct stmt_list_hash hash
;
763 /* The number of symtabs from the line header.
764 The value here must match line_header.num_file_names. */
765 unsigned int num_symtabs
;
767 /* The symbol tables for this TU (obtained from the files listed in
769 WARNING: The order of entries here must match the order of entries
770 in the line header. After the first TU using this type_unit_group, the
771 line header for the subsequent TUs is recreated from this. This is done
772 because we need to use the same symtabs for each TU using the same
773 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
774 there's no guarantee the line header doesn't have duplicate entries. */
775 struct symtab
**symtabs
;
778 /* These sections are what may appear in a (real or virtual) DWO file. */
782 struct dwarf2_section_info abbrev
;
783 struct dwarf2_section_info line
;
784 struct dwarf2_section_info loc
;
785 struct dwarf2_section_info loclists
;
786 struct dwarf2_section_info macinfo
;
787 struct dwarf2_section_info macro
;
788 struct dwarf2_section_info str
;
789 struct dwarf2_section_info str_offsets
;
790 /* In the case of a virtual DWO file, these two are unused. */
791 struct dwarf2_section_info info
;
792 VEC (dwarf2_section_info_def
) *types
;
795 /* CUs/TUs in DWP/DWO files. */
799 /* Backlink to the containing struct dwo_file. */
800 struct dwo_file
*dwo_file
;
802 /* The "id" that distinguishes this CU/TU.
803 .debug_info calls this "dwo_id", .debug_types calls this "signature".
804 Since signatures came first, we stick with it for consistency. */
807 /* The section this CU/TU lives in, in the DWO file. */
808 struct dwarf2_section_info
*section
;
810 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
811 sect_offset sect_off
;
814 /* For types, offset in the type's DIE of the type defined by this TU. */
815 cu_offset type_offset_in_tu
;
818 /* include/dwarf2.h defines the DWP section codes.
819 It defines a max value but it doesn't define a min value, which we
820 use for error checking, so provide one. */
822 enum dwp_v2_section_ids
827 /* Data for one DWO file.
829 This includes virtual DWO files (a virtual DWO file is a DWO file as it
830 appears in a DWP file). DWP files don't really have DWO files per se -
831 comdat folding of types "loses" the DWO file they came from, and from
832 a high level view DWP files appear to contain a mass of random types.
833 However, to maintain consistency with the non-DWP case we pretend DWP
834 files contain virtual DWO files, and we assign each TU with one virtual
835 DWO file (generally based on the line and abbrev section offsets -
836 a heuristic that seems to work in practice). */
840 /* The DW_AT_GNU_dwo_name attribute.
841 For virtual DWO files the name is constructed from the section offsets
842 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
843 from related CU+TUs. */
844 const char *dwo_name
;
846 /* The DW_AT_comp_dir attribute. */
847 const char *comp_dir
;
849 /* The bfd, when the file is open. Otherwise this is NULL.
850 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
853 /* The sections that make up this DWO file.
854 Remember that for virtual DWO files in DWP V2, these are virtual
855 sections (for lack of a better name). */
856 struct dwo_sections sections
;
858 /* The CUs in the file.
859 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
860 an extension to handle LLVM's Link Time Optimization output (where
861 multiple source files may be compiled into a single object/dwo pair). */
864 /* Table of TUs in the file.
865 Each element is a struct dwo_unit. */
869 /* These sections are what may appear in a DWP file. */
873 /* These are used by both DWP version 1 and 2. */
874 struct dwarf2_section_info str
;
875 struct dwarf2_section_info cu_index
;
876 struct dwarf2_section_info tu_index
;
878 /* These are only used by DWP version 2 files.
879 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
880 sections are referenced by section number, and are not recorded here.
881 In DWP version 2 there is at most one copy of all these sections, each
882 section being (effectively) comprised of the concatenation of all of the
883 individual sections that exist in the version 1 format.
884 To keep the code simple we treat each of these concatenated pieces as a
885 section itself (a virtual section?). */
886 struct dwarf2_section_info abbrev
;
887 struct dwarf2_section_info info
;
888 struct dwarf2_section_info line
;
889 struct dwarf2_section_info loc
;
890 struct dwarf2_section_info macinfo
;
891 struct dwarf2_section_info macro
;
892 struct dwarf2_section_info str_offsets
;
893 struct dwarf2_section_info types
;
896 /* These sections are what may appear in a virtual DWO file in DWP version 1.
897 A virtual DWO file is a DWO file as it appears in a DWP file. */
899 struct virtual_v1_dwo_sections
901 struct dwarf2_section_info abbrev
;
902 struct dwarf2_section_info line
;
903 struct dwarf2_section_info loc
;
904 struct dwarf2_section_info macinfo
;
905 struct dwarf2_section_info macro
;
906 struct dwarf2_section_info str_offsets
;
907 /* Each DWP hash table entry records one CU or one TU.
908 That is recorded here, and copied to dwo_unit.section. */
909 struct dwarf2_section_info info_or_types
;
912 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
913 In version 2, the sections of the DWO files are concatenated together
914 and stored in one section of that name. Thus each ELF section contains
915 several "virtual" sections. */
917 struct virtual_v2_dwo_sections
919 bfd_size_type abbrev_offset
;
920 bfd_size_type abbrev_size
;
922 bfd_size_type line_offset
;
923 bfd_size_type line_size
;
925 bfd_size_type loc_offset
;
926 bfd_size_type loc_size
;
928 bfd_size_type macinfo_offset
;
929 bfd_size_type macinfo_size
;
931 bfd_size_type macro_offset
;
932 bfd_size_type macro_size
;
934 bfd_size_type str_offsets_offset
;
935 bfd_size_type str_offsets_size
;
937 /* Each DWP hash table entry records one CU or one TU.
938 That is recorded here, and copied to dwo_unit.section. */
939 bfd_size_type info_or_types_offset
;
940 bfd_size_type info_or_types_size
;
943 /* Contents of DWP hash tables. */
945 struct dwp_hash_table
947 uint32_t version
, nr_columns
;
948 uint32_t nr_units
, nr_slots
;
949 const gdb_byte
*hash_table
, *unit_table
;
954 const gdb_byte
*indices
;
958 /* This is indexed by column number and gives the id of the section
960 #define MAX_NR_V2_DWO_SECTIONS \
961 (1 /* .debug_info or .debug_types */ \
962 + 1 /* .debug_abbrev */ \
963 + 1 /* .debug_line */ \
964 + 1 /* .debug_loc */ \
965 + 1 /* .debug_str_offsets */ \
966 + 1 /* .debug_macro or .debug_macinfo */)
967 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
968 const gdb_byte
*offsets
;
969 const gdb_byte
*sizes
;
974 /* Data for one DWP file. */
978 /* Name of the file. */
981 /* File format version. */
987 /* Section info for this file. */
988 struct dwp_sections sections
;
990 /* Table of CUs in the file. */
991 const struct dwp_hash_table
*cus
;
993 /* Table of TUs in the file. */
994 const struct dwp_hash_table
*tus
;
996 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
1000 /* Table to map ELF section numbers to their sections.
1001 This is only needed for the DWP V1 file format. */
1002 unsigned int num_sections
;
1003 asection
**elf_sections
;
1006 /* This represents a '.dwz' file. */
1010 /* A dwz file can only contain a few sections. */
1011 struct dwarf2_section_info abbrev
;
1012 struct dwarf2_section_info info
;
1013 struct dwarf2_section_info str
;
1014 struct dwarf2_section_info line
;
1015 struct dwarf2_section_info macro
;
1016 struct dwarf2_section_info gdb_index
;
1018 /* The dwz's BFD. */
1022 /* Struct used to pass misc. parameters to read_die_and_children, et
1023 al. which are used for both .debug_info and .debug_types dies.
1024 All parameters here are unchanging for the life of the call. This
1025 struct exists to abstract away the constant parameters of die reading. */
1027 struct die_reader_specs
1029 /* The bfd of die_section. */
1032 /* The CU of the DIE we are parsing. */
1033 struct dwarf2_cu
*cu
;
1035 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1036 struct dwo_file
*dwo_file
;
1038 /* The section the die comes from.
1039 This is either .debug_info or .debug_types, or the .dwo variants. */
1040 struct dwarf2_section_info
*die_section
;
1042 /* die_section->buffer. */
1043 const gdb_byte
*buffer
;
1045 /* The end of the buffer. */
1046 const gdb_byte
*buffer_end
;
1048 /* The value of the DW_AT_comp_dir attribute. */
1049 const char *comp_dir
;
1052 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1053 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1054 const gdb_byte
*info_ptr
,
1055 struct die_info
*comp_unit_die
,
1059 /* A 1-based directory index. This is a strong typedef to prevent
1060 accidentally using a directory index as a 0-based index into an
1062 enum class dir_index
: unsigned int {};
1064 /* Likewise, a 1-based file name index. */
1065 enum class file_name_index
: unsigned int {};
1069 file_entry () = default;
1071 file_entry (const char *name_
, dir_index d_index_
,
1072 unsigned int mod_time_
, unsigned int length_
)
1075 mod_time (mod_time_
),
1079 /* Return the include directory at D_INDEX stored in LH. Returns
1080 NULL if D_INDEX is out of bounds. */
1081 const char *include_dir (const line_header
*lh
) const;
1083 /* The file name. Note this is an observing pointer. The memory is
1084 owned by debug_line_buffer. */
1085 const char *name
{};
1087 /* The directory index (1-based). */
1088 dir_index d_index
{};
1090 unsigned int mod_time
{};
1092 unsigned int length
{};
1094 /* True if referenced by the Line Number Program. */
1097 /* The associated symbol table, if any. */
1098 struct symtab
*symtab
{};
1101 /* The line number information for a compilation unit (found in the
1102 .debug_line section) begins with a "statement program header",
1103 which contains the following information. */
1110 /* Add an entry to the include directory table. */
1111 void add_include_dir (const char *include_dir
);
1113 /* Add an entry to the file name table. */
1114 void add_file_name (const char *name
, dir_index d_index
,
1115 unsigned int mod_time
, unsigned int length
);
1117 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
1118 is out of bounds. */
1119 const char *include_dir_at (dir_index index
) const
1121 /* Convert directory index number (1-based) to vector index
1123 size_t vec_index
= to_underlying (index
) - 1;
1125 if (vec_index
>= include_dirs
.size ())
1127 return include_dirs
[vec_index
];
1130 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
1131 is out of bounds. */
1132 file_entry
*file_name_at (file_name_index index
)
1134 /* Convert file name index number (1-based) to vector index
1136 size_t vec_index
= to_underlying (index
) - 1;
1138 if (vec_index
>= file_names
.size ())
1140 return &file_names
[vec_index
];
1143 /* Const version of the above. */
1144 const file_entry
*file_name_at (unsigned int index
) const
1146 if (index
>= file_names
.size ())
1148 return &file_names
[index
];
1151 /* Offset of line number information in .debug_line section. */
1152 sect_offset sect_off
{};
1154 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1155 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1157 unsigned int total_length
{};
1158 unsigned short version
{};
1159 unsigned int header_length
{};
1160 unsigned char minimum_instruction_length
{};
1161 unsigned char maximum_ops_per_instruction
{};
1162 unsigned char default_is_stmt
{};
1164 unsigned char line_range
{};
1165 unsigned char opcode_base
{};
1167 /* standard_opcode_lengths[i] is the number of operands for the
1168 standard opcode whose value is i. This means that
1169 standard_opcode_lengths[0] is unused, and the last meaningful
1170 element is standard_opcode_lengths[opcode_base - 1]. */
1171 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1173 /* The include_directories table. Note these are observing
1174 pointers. The memory is owned by debug_line_buffer. */
1175 std::vector
<const char *> include_dirs
;
1177 /* The file_names table. */
1178 std::vector
<file_entry
> file_names
;
1180 /* The start and end of the statement program following this
1181 header. These point into dwarf2_per_objfile->line_buffer. */
1182 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1185 typedef std::unique_ptr
<line_header
> line_header_up
;
1188 file_entry::include_dir (const line_header
*lh
) const
1190 return lh
->include_dir_at (d_index
);
1193 /* When we construct a partial symbol table entry we only
1194 need this much information. */
1195 struct partial_die_info
1197 /* Offset of this DIE. */
1198 sect_offset sect_off
;
1200 /* DWARF-2 tag for this DIE. */
1201 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1203 /* Assorted flags describing the data found in this DIE. */
1204 unsigned int has_children
: 1;
1205 unsigned int is_external
: 1;
1206 unsigned int is_declaration
: 1;
1207 unsigned int has_type
: 1;
1208 unsigned int has_specification
: 1;
1209 unsigned int has_pc_info
: 1;
1210 unsigned int may_be_inlined
: 1;
1212 /* This DIE has been marked DW_AT_main_subprogram. */
1213 unsigned int main_subprogram
: 1;
1215 /* Flag set if the SCOPE field of this structure has been
1217 unsigned int scope_set
: 1;
1219 /* Flag set if the DIE has a byte_size attribute. */
1220 unsigned int has_byte_size
: 1;
1222 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1223 unsigned int has_const_value
: 1;
1225 /* Flag set if any of the DIE's children are template arguments. */
1226 unsigned int has_template_arguments
: 1;
1228 /* Flag set if fixup_partial_die has been called on this die. */
1229 unsigned int fixup_called
: 1;
1231 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1232 unsigned int is_dwz
: 1;
1234 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1235 unsigned int spec_is_dwz
: 1;
1237 /* The name of this DIE. Normally the value of DW_AT_name, but
1238 sometimes a default name for unnamed DIEs. */
1241 /* The linkage name, if present. */
1242 const char *linkage_name
;
1244 /* The scope to prepend to our children. This is generally
1245 allocated on the comp_unit_obstack, so will disappear
1246 when this compilation unit leaves the cache. */
1249 /* Some data associated with the partial DIE. The tag determines
1250 which field is live. */
1253 /* The location description associated with this DIE, if any. */
1254 struct dwarf_block
*locdesc
;
1255 /* The offset of an import, for DW_TAG_imported_unit. */
1256 sect_offset sect_off
;
1259 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1263 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1264 DW_AT_sibling, if any. */
1265 /* NOTE: This member isn't strictly necessary, read_partial_die could
1266 return DW_AT_sibling values to its caller load_partial_dies. */
1267 const gdb_byte
*sibling
;
1269 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1270 DW_AT_specification (or DW_AT_abstract_origin or
1271 DW_AT_extension). */
1272 sect_offset spec_offset
;
1274 /* Pointers to this DIE's parent, first child, and next sibling,
1276 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
1279 /* This data structure holds the information of an abbrev. */
1282 unsigned int number
; /* number identifying abbrev */
1283 enum dwarf_tag tag
; /* dwarf tag */
1284 unsigned short has_children
; /* boolean */
1285 unsigned short num_attrs
; /* number of attributes */
1286 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1287 struct abbrev_info
*next
; /* next in chain */
1292 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1293 ENUM_BITFIELD(dwarf_form
) form
: 16;
1295 /* It is valid only if FORM is DW_FORM_implicit_const. */
1296 LONGEST implicit_const
;
1299 /* Size of abbrev_table.abbrev_hash_table. */
1300 #define ABBREV_HASH_SIZE 121
1302 /* Top level data structure to contain an abbreviation table. */
1306 /* Where the abbrev table came from.
1307 This is used as a sanity check when the table is used. */
1308 sect_offset sect_off
;
1310 /* Storage for the abbrev table. */
1311 struct obstack abbrev_obstack
;
1313 /* Hash table of abbrevs.
1314 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1315 It could be statically allocated, but the previous code didn't so we
1317 struct abbrev_info
**abbrevs
;
1320 /* Attributes have a name and a value. */
1323 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1324 ENUM_BITFIELD(dwarf_form
) form
: 15;
1326 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1327 field should be in u.str (existing only for DW_STRING) but it is kept
1328 here for better struct attribute alignment. */
1329 unsigned int string_is_canonical
: 1;
1334 struct dwarf_block
*blk
;
1343 /* This data structure holds a complete die structure. */
1346 /* DWARF-2 tag for this DIE. */
1347 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1349 /* Number of attributes */
1350 unsigned char num_attrs
;
1352 /* True if we're presently building the full type name for the
1353 type derived from this DIE. */
1354 unsigned char building_fullname
: 1;
1356 /* True if this die is in process. PR 16581. */
1357 unsigned char in_process
: 1;
1360 unsigned int abbrev
;
1362 /* Offset in .debug_info or .debug_types section. */
1363 sect_offset sect_off
;
1365 /* The dies in a compilation unit form an n-ary tree. PARENT
1366 points to this die's parent; CHILD points to the first child of
1367 this node; and all the children of a given node are chained
1368 together via their SIBLING fields. */
1369 struct die_info
*child
; /* Its first child, if any. */
1370 struct die_info
*sibling
; /* Its next sibling, if any. */
1371 struct die_info
*parent
; /* Its parent, if any. */
1373 /* An array of attributes, with NUM_ATTRS elements. There may be
1374 zero, but it's not common and zero-sized arrays are not
1375 sufficiently portable C. */
1376 struct attribute attrs
[1];
1379 /* Get at parts of an attribute structure. */
1381 #define DW_STRING(attr) ((attr)->u.str)
1382 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1383 #define DW_UNSND(attr) ((attr)->u.unsnd)
1384 #define DW_BLOCK(attr) ((attr)->u.blk)
1385 #define DW_SND(attr) ((attr)->u.snd)
1386 #define DW_ADDR(attr) ((attr)->u.addr)
1387 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1389 /* Blocks are a bunch of untyped bytes. */
1394 /* Valid only if SIZE is not zero. */
1395 const gdb_byte
*data
;
1398 #ifndef ATTR_ALLOC_CHUNK
1399 #define ATTR_ALLOC_CHUNK 4
1402 /* Allocate fields for structs, unions and enums in this size. */
1403 #ifndef DW_FIELD_ALLOC_CHUNK
1404 #define DW_FIELD_ALLOC_CHUNK 4
1407 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1408 but this would require a corresponding change in unpack_field_as_long
1410 static int bits_per_byte
= 8;
1414 struct nextfield
*next
;
1422 struct nextfnfield
*next
;
1423 struct fn_field fnfield
;
1430 struct nextfnfield
*head
;
1433 struct typedef_field_list
1435 struct typedef_field field
;
1436 struct typedef_field_list
*next
;
1439 /* The routines that read and process dies for a C struct or C++ class
1440 pass lists of data member fields and lists of member function fields
1441 in an instance of a field_info structure, as defined below. */
1444 /* List of data member and baseclasses fields. */
1445 struct nextfield
*fields
, *baseclasses
;
1447 /* Number of fields (including baseclasses). */
1450 /* Number of baseclasses. */
1453 /* Set if the accesibility of one of the fields is not public. */
1454 int non_public_fields
;
1456 /* Member function fields array, entries are allocated in the order they
1457 are encountered in the object file. */
1458 struct nextfnfield
*fnfields
;
1460 /* Member function fieldlist array, contains name of possibly overloaded
1461 member function, number of overloaded member functions and a pointer
1462 to the head of the member function field chain. */
1463 struct fnfieldlist
*fnfieldlists
;
1465 /* Number of entries in the fnfieldlists array. */
1468 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1469 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1470 struct typedef_field_list
*typedef_field_list
;
1471 unsigned typedef_field_list_count
;
1474 /* One item on the queue of compilation units to read in full symbols
1476 struct dwarf2_queue_item
1478 struct dwarf2_per_cu_data
*per_cu
;
1479 enum language pretend_language
;
1480 struct dwarf2_queue_item
*next
;
1483 /* The current queue. */
1484 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1486 /* Loaded secondary compilation units are kept in memory until they
1487 have not been referenced for the processing of this many
1488 compilation units. Set this to zero to disable caching. Cache
1489 sizes of up to at least twenty will improve startup time for
1490 typical inter-CU-reference binaries, at an obvious memory cost. */
1491 static int dwarf_max_cache_age
= 5;
1493 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1494 struct cmd_list_element
*c
, const char *value
)
1496 fprintf_filtered (file
, _("The upper bound on the age of cached "
1497 "DWARF compilation units is %s.\n"),
1501 /* local function prototypes */
1503 static const char *get_section_name (const struct dwarf2_section_info
*);
1505 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1507 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1509 static void dwarf2_find_base_address (struct die_info
*die
,
1510 struct dwarf2_cu
*cu
);
1512 static struct partial_symtab
*create_partial_symtab
1513 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1515 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1517 static void scan_partial_symbols (struct partial_die_info
*,
1518 CORE_ADDR
*, CORE_ADDR
*,
1519 int, struct dwarf2_cu
*);
1521 static void add_partial_symbol (struct partial_die_info
*,
1522 struct dwarf2_cu
*);
1524 static void add_partial_namespace (struct partial_die_info
*pdi
,
1525 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1526 int set_addrmap
, struct dwarf2_cu
*cu
);
1528 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1529 CORE_ADDR
*highpc
, int set_addrmap
,
1530 struct dwarf2_cu
*cu
);
1532 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1533 struct dwarf2_cu
*cu
);
1535 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1536 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1537 int need_pc
, struct dwarf2_cu
*cu
);
1539 static void dwarf2_read_symtab (struct partial_symtab
*,
1542 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1544 static struct abbrev_info
*abbrev_table_lookup_abbrev
1545 (const struct abbrev_table
*, unsigned int);
1547 static struct abbrev_table
*abbrev_table_read_table
1548 (struct dwarf2_section_info
*, sect_offset
);
1550 static void abbrev_table_free (struct abbrev_table
*);
1552 static void abbrev_table_free_cleanup (void *);
1554 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1555 struct dwarf2_section_info
*);
1557 static void dwarf2_free_abbrev_table (void *);
1559 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1561 static struct partial_die_info
*load_partial_dies
1562 (const struct die_reader_specs
*, const gdb_byte
*, int);
1564 static const gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1565 struct partial_die_info
*,
1566 struct abbrev_info
*,
1570 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1571 struct dwarf2_cu
*);
1573 static void fixup_partial_die (struct partial_die_info
*,
1574 struct dwarf2_cu
*);
1576 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1577 struct attribute
*, struct attr_abbrev
*,
1580 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1582 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1584 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1586 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1588 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1590 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1593 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1595 static LONGEST read_checked_initial_length_and_offset
1596 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1597 unsigned int *, unsigned int *);
1599 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1600 const struct comp_unit_head
*,
1603 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1605 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1608 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1610 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1612 static const char *read_indirect_string (bfd
*, const gdb_byte
*,
1613 const struct comp_unit_head
*,
1616 static const char *read_indirect_line_string (bfd
*, const gdb_byte
*,
1617 const struct comp_unit_head
*,
1620 static const char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1622 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1624 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1628 static const char *read_str_index (const struct die_reader_specs
*reader
,
1629 ULONGEST str_index
);
1631 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1633 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1634 struct dwarf2_cu
*);
1636 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1639 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1640 struct dwarf2_cu
*cu
);
1642 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1643 struct dwarf2_cu
*cu
);
1645 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1647 static struct die_info
*die_specification (struct die_info
*die
,
1648 struct dwarf2_cu
**);
1650 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1651 struct dwarf2_cu
*cu
);
1653 static void dwarf_decode_lines (struct line_header
*, const char *,
1654 struct dwarf2_cu
*, struct partial_symtab
*,
1655 CORE_ADDR
, int decode_mapping
);
1657 static void dwarf2_start_subfile (const char *, const char *);
1659 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1660 const char *, const char *,
1663 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1664 struct dwarf2_cu
*);
1666 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1667 struct dwarf2_cu
*, struct symbol
*);
1669 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1670 struct dwarf2_cu
*);
1672 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1675 struct obstack
*obstack
,
1676 struct dwarf2_cu
*cu
, LONGEST
*value
,
1677 const gdb_byte
**bytes
,
1678 struct dwarf2_locexpr_baton
**baton
);
1680 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1682 static int need_gnat_info (struct dwarf2_cu
*);
1684 static struct type
*die_descriptive_type (struct die_info
*,
1685 struct dwarf2_cu
*);
1687 static void set_descriptive_type (struct type
*, struct die_info
*,
1688 struct dwarf2_cu
*);
1690 static struct type
*die_containing_type (struct die_info
*,
1691 struct dwarf2_cu
*);
1693 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1694 struct dwarf2_cu
*);
1696 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1698 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1700 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1702 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1703 const char *suffix
, int physname
,
1704 struct dwarf2_cu
*cu
);
1706 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1708 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1710 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1712 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1714 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1716 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1717 struct dwarf2_cu
*, struct partial_symtab
*);
1719 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1720 values. Keep the items ordered with increasing constraints compliance. */
1723 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1724 PC_BOUNDS_NOT_PRESENT
,
1726 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1727 were present but they do not form a valid range of PC addresses. */
1730 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1733 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1737 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1738 CORE_ADDR
*, CORE_ADDR
*,
1740 struct partial_symtab
*);
1742 static void get_scope_pc_bounds (struct die_info
*,
1743 CORE_ADDR
*, CORE_ADDR
*,
1744 struct dwarf2_cu
*);
1746 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1747 CORE_ADDR
, struct dwarf2_cu
*);
1749 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1750 struct dwarf2_cu
*);
1752 static void dwarf2_attach_fields_to_type (struct field_info
*,
1753 struct type
*, struct dwarf2_cu
*);
1755 static void dwarf2_add_member_fn (struct field_info
*,
1756 struct die_info
*, struct type
*,
1757 struct dwarf2_cu
*);
1759 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1761 struct dwarf2_cu
*);
1763 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1765 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1767 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1769 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1771 static struct using_direct
**using_directives (enum language
);
1773 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1775 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1777 static struct type
*read_module_type (struct die_info
*die
,
1778 struct dwarf2_cu
*cu
);
1780 static const char *namespace_name (struct die_info
*die
,
1781 int *is_anonymous
, struct dwarf2_cu
*);
1783 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1785 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1787 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1788 struct dwarf2_cu
*);
1790 static struct die_info
*read_die_and_siblings_1
1791 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1794 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1795 const gdb_byte
*info_ptr
,
1796 const gdb_byte
**new_info_ptr
,
1797 struct die_info
*parent
);
1799 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1800 struct die_info
**, const gdb_byte
*,
1803 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1804 struct die_info
**, const gdb_byte
*,
1807 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1809 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1812 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1814 static const char *dwarf2_full_name (const char *name
,
1815 struct die_info
*die
,
1816 struct dwarf2_cu
*cu
);
1818 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1819 struct dwarf2_cu
*cu
);
1821 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1822 struct dwarf2_cu
**);
1824 static const char *dwarf_tag_name (unsigned int);
1826 static const char *dwarf_attr_name (unsigned int);
1828 static const char *dwarf_form_name (unsigned int);
1830 static const char *dwarf_bool_name (unsigned int);
1832 static const char *dwarf_type_encoding_name (unsigned int);
1834 static struct die_info
*sibling_die (struct die_info
*);
1836 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1838 static void dump_die_for_error (struct die_info
*);
1840 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1843 /*static*/ void dump_die (struct die_info
*, int max_level
);
1845 static void store_in_ref_table (struct die_info
*,
1846 struct dwarf2_cu
*);
1848 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1850 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1852 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1853 const struct attribute
*,
1854 struct dwarf2_cu
**);
1856 static struct die_info
*follow_die_ref (struct die_info
*,
1857 const struct attribute
*,
1858 struct dwarf2_cu
**);
1860 static struct die_info
*follow_die_sig (struct die_info
*,
1861 const struct attribute
*,
1862 struct dwarf2_cu
**);
1864 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1865 struct dwarf2_cu
*);
1867 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1868 const struct attribute
*,
1869 struct dwarf2_cu
*);
1871 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1873 static void read_signatured_type (struct signatured_type
*);
1875 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1876 struct die_info
*die
, struct dwarf2_cu
*cu
,
1877 struct dynamic_prop
*prop
);
1879 /* memory allocation interface */
1881 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1883 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1885 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1887 static int attr_form_is_block (const struct attribute
*);
1889 static int attr_form_is_section_offset (const struct attribute
*);
1891 static int attr_form_is_constant (const struct attribute
*);
1893 static int attr_form_is_ref (const struct attribute
*);
1895 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1896 struct dwarf2_loclist_baton
*baton
,
1897 const struct attribute
*attr
);
1899 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1901 struct dwarf2_cu
*cu
,
1904 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1905 const gdb_byte
*info_ptr
,
1906 struct abbrev_info
*abbrev
);
1908 static void free_stack_comp_unit (void *);
1910 static hashval_t
partial_die_hash (const void *item
);
1912 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1914 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1915 (sect_offset sect_off
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1917 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1918 struct dwarf2_per_cu_data
*per_cu
);
1920 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1921 struct die_info
*comp_unit_die
,
1922 enum language pretend_language
);
1924 static void free_heap_comp_unit (void *);
1926 static void free_cached_comp_units (void *);
1928 static void age_cached_comp_units (void);
1930 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1932 static struct type
*set_die_type (struct die_info
*, struct type
*,
1933 struct dwarf2_cu
*);
1935 static void create_all_comp_units (struct objfile
*);
1937 static int create_all_type_units (struct objfile
*);
1939 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1942 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1945 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1948 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1949 struct dwarf2_per_cu_data
*);
1951 static void dwarf2_mark (struct dwarf2_cu
*);
1953 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1955 static struct type
*get_die_type_at_offset (sect_offset
,
1956 struct dwarf2_per_cu_data
*);
1958 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1960 static void dwarf2_release_queue (void *dummy
);
1962 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1963 enum language pretend_language
);
1965 static void process_queue (void);
1967 /* The return type of find_file_and_directory. Note, the enclosed
1968 string pointers are only valid while this object is valid. */
1970 struct file_and_directory
1972 /* The filename. This is never NULL. */
1975 /* The compilation directory. NULL if not known. If we needed to
1976 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1977 points directly to the DW_AT_comp_dir string attribute owned by
1978 the obstack that owns the DIE. */
1979 const char *comp_dir
;
1981 /* If we needed to build a new string for comp_dir, this is what
1982 owns the storage. */
1983 std::string comp_dir_storage
;
1986 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1987 struct dwarf2_cu
*cu
);
1989 static char *file_full_name (int file
, struct line_header
*lh
,
1990 const char *comp_dir
);
1992 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1993 enum class rcuh_kind
{ COMPILE
, TYPE
};
1995 static const gdb_byte
*read_and_check_comp_unit_head
1996 (struct comp_unit_head
*header
,
1997 struct dwarf2_section_info
*section
,
1998 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1999 rcuh_kind section_kind
);
2001 static void init_cutu_and_read_dies
2002 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
2003 int use_existing_cu
, int keep
,
2004 die_reader_func_ftype
*die_reader_func
, void *data
);
2006 static void init_cutu_and_read_dies_simple
2007 (struct dwarf2_per_cu_data
*this_cu
,
2008 die_reader_func_ftype
*die_reader_func
, void *data
);
2010 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2012 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2014 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2015 (struct dwp_file
*dwp_file
, const char *comp_dir
,
2016 ULONGEST signature
, int is_debug_types
);
2018 static struct dwp_file
*get_dwp_file (void);
2020 static struct dwo_unit
*lookup_dwo_comp_unit
2021 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2023 static struct dwo_unit
*lookup_dwo_type_unit
2024 (struct signatured_type
*, const char *, const char *);
2026 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2028 static void free_dwo_file_cleanup (void *);
2030 static void process_cu_includes (void);
2032 static void check_producer (struct dwarf2_cu
*cu
);
2034 static void free_line_header_voidp (void *arg
);
2036 /* Various complaints about symbol reading that don't abort the process. */
2039 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2041 complaint (&symfile_complaints
,
2042 _("statement list doesn't fit in .debug_line section"));
2046 dwarf2_debug_line_missing_file_complaint (void)
2048 complaint (&symfile_complaints
,
2049 _(".debug_line section has line data without a file"));
2053 dwarf2_debug_line_missing_end_sequence_complaint (void)
2055 complaint (&symfile_complaints
,
2056 _(".debug_line section has line "
2057 "program sequence without an end"));
2061 dwarf2_complex_location_expr_complaint (void)
2063 complaint (&symfile_complaints
, _("location expression too complex"));
2067 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2070 complaint (&symfile_complaints
,
2071 _("const value length mismatch for '%s', got %d, expected %d"),
2076 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2078 complaint (&symfile_complaints
,
2079 _("debug info runs off end of %s section"
2081 get_section_name (section
),
2082 get_section_file_name (section
));
2086 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2088 complaint (&symfile_complaints
,
2089 _("macro debug info contains a "
2090 "malformed macro definition:\n`%s'"),
2095 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2097 complaint (&symfile_complaints
,
2098 _("invalid attribute class or form for '%s' in '%s'"),
2102 /* Hash function for line_header_hash. */
2105 line_header_hash (const struct line_header
*ofs
)
2107 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2110 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2113 line_header_hash_voidp (const void *item
)
2115 const struct line_header
*ofs
= (const struct line_header
*) item
;
2117 return line_header_hash (ofs
);
2120 /* Equality function for line_header_hash. */
2123 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2125 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2126 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2128 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2129 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2135 /* Convert VALUE between big- and little-endian. */
2137 byte_swap (offset_type value
)
2141 result
= (value
& 0xff) << 24;
2142 result
|= (value
& 0xff00) << 8;
2143 result
|= (value
& 0xff0000) >> 8;
2144 result
|= (value
& 0xff000000) >> 24;
2148 #define MAYBE_SWAP(V) byte_swap (V)
2151 #define MAYBE_SWAP(V) static_cast<offset_type> (V)
2152 #endif /* WORDS_BIGENDIAN */
2154 /* Read the given attribute value as an address, taking the attribute's
2155 form into account. */
2158 attr_value_as_address (struct attribute
*attr
)
2162 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2164 /* Aside from a few clearly defined exceptions, attributes that
2165 contain an address must always be in DW_FORM_addr form.
2166 Unfortunately, some compilers happen to be violating this
2167 requirement by encoding addresses using other forms, such
2168 as DW_FORM_data4 for example. For those broken compilers,
2169 we try to do our best, without any guarantee of success,
2170 to interpret the address correctly. It would also be nice
2171 to generate a complaint, but that would require us to maintain
2172 a list of legitimate cases where a non-address form is allowed,
2173 as well as update callers to pass in at least the CU's DWARF
2174 version. This is more overhead than what we're willing to
2175 expand for a pretty rare case. */
2176 addr
= DW_UNSND (attr
);
2179 addr
= DW_ADDR (attr
);
2184 /* The suffix for an index file. */
2185 #define INDEX_SUFFIX ".gdb-index"
2187 /* Try to locate the sections we need for DWARF 2 debugging
2188 information and return true if we have enough to do something.
2189 NAMES points to the dwarf2 section names, or is NULL if the standard
2190 ELF names are used. */
2193 dwarf2_has_info (struct objfile
*objfile
,
2194 const struct dwarf2_debug_sections
*names
)
2196 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
2197 objfile_data (objfile
, dwarf2_objfile_data_key
));
2198 if (!dwarf2_per_objfile
)
2200 /* Initialize per-objfile state. */
2201 struct dwarf2_per_objfile
*data
2202 = XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_objfile
);
2204 memset (data
, 0, sizeof (*data
));
2205 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
2206 dwarf2_per_objfile
= data
;
2208 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
2210 dwarf2_per_objfile
->objfile
= objfile
;
2212 return (!dwarf2_per_objfile
->info
.is_virtual
2213 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2214 && !dwarf2_per_objfile
->abbrev
.is_virtual
2215 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2218 /* Return the containing section of virtual section SECTION. */
2220 static struct dwarf2_section_info
*
2221 get_containing_section (const struct dwarf2_section_info
*section
)
2223 gdb_assert (section
->is_virtual
);
2224 return section
->s
.containing_section
;
2227 /* Return the bfd owner of SECTION. */
2230 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2232 if (section
->is_virtual
)
2234 section
= get_containing_section (section
);
2235 gdb_assert (!section
->is_virtual
);
2237 return section
->s
.section
->owner
;
2240 /* Return the bfd section of SECTION.
2241 Returns NULL if the section is not present. */
2244 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2246 if (section
->is_virtual
)
2248 section
= get_containing_section (section
);
2249 gdb_assert (!section
->is_virtual
);
2251 return section
->s
.section
;
2254 /* Return the name of SECTION. */
2257 get_section_name (const struct dwarf2_section_info
*section
)
2259 asection
*sectp
= get_section_bfd_section (section
);
2261 gdb_assert (sectp
!= NULL
);
2262 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2265 /* Return the name of the file SECTION is in. */
2268 get_section_file_name (const struct dwarf2_section_info
*section
)
2270 bfd
*abfd
= get_section_bfd_owner (section
);
2272 return bfd_get_filename (abfd
);
2275 /* Return the id of SECTION.
2276 Returns 0 if SECTION doesn't exist. */
2279 get_section_id (const struct dwarf2_section_info
*section
)
2281 asection
*sectp
= get_section_bfd_section (section
);
2288 /* Return the flags of SECTION.
2289 SECTION (or containing section if this is a virtual section) must exist. */
2292 get_section_flags (const struct dwarf2_section_info
*section
)
2294 asection
*sectp
= get_section_bfd_section (section
);
2296 gdb_assert (sectp
!= NULL
);
2297 return bfd_get_section_flags (sectp
->owner
, sectp
);
2300 /* When loading sections, we look either for uncompressed section or for
2301 compressed section names. */
2304 section_is_p (const char *section_name
,
2305 const struct dwarf2_section_names
*names
)
2307 if (names
->normal
!= NULL
2308 && strcmp (section_name
, names
->normal
) == 0)
2310 if (names
->compressed
!= NULL
2311 && strcmp (section_name
, names
->compressed
) == 0)
2316 /* This function is mapped across the sections and remembers the
2317 offset and size of each of the debugging sections we are interested
2321 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
2323 const struct dwarf2_debug_sections
*names
;
2324 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2327 names
= &dwarf2_elf_names
;
2329 names
= (const struct dwarf2_debug_sections
*) vnames
;
2331 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2334 else if (section_is_p (sectp
->name
, &names
->info
))
2336 dwarf2_per_objfile
->info
.s
.section
= sectp
;
2337 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
2339 else if (section_is_p (sectp
->name
, &names
->abbrev
))
2341 dwarf2_per_objfile
->abbrev
.s
.section
= sectp
;
2342 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
2344 else if (section_is_p (sectp
->name
, &names
->line
))
2346 dwarf2_per_objfile
->line
.s
.section
= sectp
;
2347 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
2349 else if (section_is_p (sectp
->name
, &names
->loc
))
2351 dwarf2_per_objfile
->loc
.s
.section
= sectp
;
2352 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
2354 else if (section_is_p (sectp
->name
, &names
->loclists
))
2356 dwarf2_per_objfile
->loclists
.s
.section
= sectp
;
2357 dwarf2_per_objfile
->loclists
.size
= bfd_get_section_size (sectp
);
2359 else if (section_is_p (sectp
->name
, &names
->macinfo
))
2361 dwarf2_per_objfile
->macinfo
.s
.section
= sectp
;
2362 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
2364 else if (section_is_p (sectp
->name
, &names
->macro
))
2366 dwarf2_per_objfile
->macro
.s
.section
= sectp
;
2367 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
2369 else if (section_is_p (sectp
->name
, &names
->str
))
2371 dwarf2_per_objfile
->str
.s
.section
= sectp
;
2372 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
2374 else if (section_is_p (sectp
->name
, &names
->line_str
))
2376 dwarf2_per_objfile
->line_str
.s
.section
= sectp
;
2377 dwarf2_per_objfile
->line_str
.size
= bfd_get_section_size (sectp
);
2379 else if (section_is_p (sectp
->name
, &names
->addr
))
2381 dwarf2_per_objfile
->addr
.s
.section
= sectp
;
2382 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
2384 else if (section_is_p (sectp
->name
, &names
->frame
))
2386 dwarf2_per_objfile
->frame
.s
.section
= sectp
;
2387 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
2389 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
2391 dwarf2_per_objfile
->eh_frame
.s
.section
= sectp
;
2392 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
2394 else if (section_is_p (sectp
->name
, &names
->ranges
))
2396 dwarf2_per_objfile
->ranges
.s
.section
= sectp
;
2397 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
2399 else if (section_is_p (sectp
->name
, &names
->rnglists
))
2401 dwarf2_per_objfile
->rnglists
.s
.section
= sectp
;
2402 dwarf2_per_objfile
->rnglists
.size
= bfd_get_section_size (sectp
);
2404 else if (section_is_p (sectp
->name
, &names
->types
))
2406 struct dwarf2_section_info type_section
;
2408 memset (&type_section
, 0, sizeof (type_section
));
2409 type_section
.s
.section
= sectp
;
2410 type_section
.size
= bfd_get_section_size (sectp
);
2412 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
2415 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
2417 dwarf2_per_objfile
->gdb_index
.s
.section
= sectp
;
2418 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
2421 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2422 && bfd_section_vma (abfd
, sectp
) == 0)
2423 dwarf2_per_objfile
->has_section_at_zero
= 1;
2426 /* A helper function that decides whether a section is empty,
2430 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2432 if (section
->is_virtual
)
2433 return section
->size
== 0;
2434 return section
->s
.section
== NULL
|| section
->size
== 0;
2437 /* Read the contents of the section INFO.
2438 OBJFILE is the main object file, but not necessarily the file where
2439 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2441 If the section is compressed, uncompress it before returning. */
2444 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2448 gdb_byte
*buf
, *retbuf
;
2452 info
->buffer
= NULL
;
2455 if (dwarf2_section_empty_p (info
))
2458 sectp
= get_section_bfd_section (info
);
2460 /* If this is a virtual section we need to read in the real one first. */
2461 if (info
->is_virtual
)
2463 struct dwarf2_section_info
*containing_section
=
2464 get_containing_section (info
);
2466 gdb_assert (sectp
!= NULL
);
2467 if ((sectp
->flags
& SEC_RELOC
) != 0)
2469 error (_("Dwarf Error: DWP format V2 with relocations is not"
2470 " supported in section %s [in module %s]"),
2471 get_section_name (info
), get_section_file_name (info
));
2473 dwarf2_read_section (objfile
, containing_section
);
2474 /* Other code should have already caught virtual sections that don't
2476 gdb_assert (info
->virtual_offset
+ info
->size
2477 <= containing_section
->size
);
2478 /* If the real section is empty or there was a problem reading the
2479 section we shouldn't get here. */
2480 gdb_assert (containing_section
->buffer
!= NULL
);
2481 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2485 /* If the section has relocations, we must read it ourselves.
2486 Otherwise we attach it to the BFD. */
2487 if ((sectp
->flags
& SEC_RELOC
) == 0)
2489 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2493 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2496 /* When debugging .o files, we may need to apply relocations; see
2497 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2498 We never compress sections in .o files, so we only need to
2499 try this when the section is not compressed. */
2500 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2503 info
->buffer
= retbuf
;
2507 abfd
= get_section_bfd_owner (info
);
2508 gdb_assert (abfd
!= NULL
);
2510 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2511 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2513 error (_("Dwarf Error: Can't read DWARF data"
2514 " in section %s [in module %s]"),
2515 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2519 /* A helper function that returns the size of a section in a safe way.
2520 If you are positive that the section has been read before using the
2521 size, then it is safe to refer to the dwarf2_section_info object's
2522 "size" field directly. In other cases, you must call this
2523 function, because for compressed sections the size field is not set
2524 correctly until the section has been read. */
2526 static bfd_size_type
2527 dwarf2_section_size (struct objfile
*objfile
,
2528 struct dwarf2_section_info
*info
)
2531 dwarf2_read_section (objfile
, info
);
2535 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2539 dwarf2_get_section_info (struct objfile
*objfile
,
2540 enum dwarf2_section_enum sect
,
2541 asection
**sectp
, const gdb_byte
**bufp
,
2542 bfd_size_type
*sizep
)
2544 struct dwarf2_per_objfile
*data
2545 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2546 dwarf2_objfile_data_key
);
2547 struct dwarf2_section_info
*info
;
2549 /* We may see an objfile without any DWARF, in which case we just
2560 case DWARF2_DEBUG_FRAME
:
2561 info
= &data
->frame
;
2563 case DWARF2_EH_FRAME
:
2564 info
= &data
->eh_frame
;
2567 gdb_assert_not_reached ("unexpected section");
2570 dwarf2_read_section (objfile
, info
);
2572 *sectp
= get_section_bfd_section (info
);
2573 *bufp
= info
->buffer
;
2574 *sizep
= info
->size
;
2577 /* A helper function to find the sections for a .dwz file. */
2580 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2582 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2584 /* Note that we only support the standard ELF names, because .dwz
2585 is ELF-only (at the time of writing). */
2586 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2588 dwz_file
->abbrev
.s
.section
= sectp
;
2589 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2591 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2593 dwz_file
->info
.s
.section
= sectp
;
2594 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2596 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2598 dwz_file
->str
.s
.section
= sectp
;
2599 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2601 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2603 dwz_file
->line
.s
.section
= sectp
;
2604 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2606 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2608 dwz_file
->macro
.s
.section
= sectp
;
2609 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2611 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2613 dwz_file
->gdb_index
.s
.section
= sectp
;
2614 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2618 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2619 there is no .gnu_debugaltlink section in the file. Error if there
2620 is such a section but the file cannot be found. */
2622 static struct dwz_file
*
2623 dwarf2_get_dwz_file (void)
2626 struct cleanup
*cleanup
;
2627 const char *filename
;
2628 struct dwz_file
*result
;
2629 bfd_size_type buildid_len_arg
;
2633 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2634 return dwarf2_per_objfile
->dwz_file
;
2636 bfd_set_error (bfd_error_no_error
);
2637 data
= bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2638 &buildid_len_arg
, &buildid
);
2641 if (bfd_get_error () == bfd_error_no_error
)
2643 error (_("could not read '.gnu_debugaltlink' section: %s"),
2644 bfd_errmsg (bfd_get_error ()));
2646 cleanup
= make_cleanup (xfree
, data
);
2647 make_cleanup (xfree
, buildid
);
2649 buildid_len
= (size_t) buildid_len_arg
;
2651 filename
= (const char *) data
;
2653 std::string abs_storage
;
2654 if (!IS_ABSOLUTE_PATH (filename
))
2656 char *abs
= gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2658 make_cleanup (xfree
, abs
);
2659 abs_storage
= ldirname (abs
) + SLASH_STRING
+ filename
;
2660 filename
= abs_storage
.c_str ();
2663 /* First try the file name given in the section. If that doesn't
2664 work, try to use the build-id instead. */
2665 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2666 if (dwz_bfd
!= NULL
)
2668 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2672 if (dwz_bfd
== NULL
)
2673 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2675 if (dwz_bfd
== NULL
)
2676 error (_("could not find '.gnu_debugaltlink' file for %s"),
2677 objfile_name (dwarf2_per_objfile
->objfile
));
2679 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2681 result
->dwz_bfd
= dwz_bfd
.release ();
2683 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
2685 do_cleanups (cleanup
);
2687 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
2688 dwarf2_per_objfile
->dwz_file
= result
;
2692 /* DWARF quick_symbols_functions support. */
2694 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2695 unique line tables, so we maintain a separate table of all .debug_line
2696 derived entries to support the sharing.
2697 All the quick functions need is the list of file names. We discard the
2698 line_header when we're done and don't need to record it here. */
2699 struct quick_file_names
2701 /* The data used to construct the hash key. */
2702 struct stmt_list_hash hash
;
2704 /* The number of entries in file_names, real_names. */
2705 unsigned int num_file_names
;
2707 /* The file names from the line table, after being run through
2709 const char **file_names
;
2711 /* The file names from the line table after being run through
2712 gdb_realpath. These are computed lazily. */
2713 const char **real_names
;
2716 /* When using the index (and thus not using psymtabs), each CU has an
2717 object of this type. This is used to hold information needed by
2718 the various "quick" methods. */
2719 struct dwarf2_per_cu_quick_data
2721 /* The file table. This can be NULL if there was no file table
2722 or it's currently not read in.
2723 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2724 struct quick_file_names
*file_names
;
2726 /* The corresponding symbol table. This is NULL if symbols for this
2727 CU have not yet been read. */
2728 struct compunit_symtab
*compunit_symtab
;
2730 /* A temporary mark bit used when iterating over all CUs in
2731 expand_symtabs_matching. */
2732 unsigned int mark
: 1;
2734 /* True if we've tried to read the file table and found there isn't one.
2735 There will be no point in trying to read it again next time. */
2736 unsigned int no_file_data
: 1;
2739 /* Utility hash function for a stmt_list_hash. */
2742 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2746 if (stmt_list_hash
->dwo_unit
!= NULL
)
2747 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2748 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2752 /* Utility equality function for a stmt_list_hash. */
2755 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2756 const struct stmt_list_hash
*rhs
)
2758 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2760 if (lhs
->dwo_unit
!= NULL
2761 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2764 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2767 /* Hash function for a quick_file_names. */
2770 hash_file_name_entry (const void *e
)
2772 const struct quick_file_names
*file_data
2773 = (const struct quick_file_names
*) e
;
2775 return hash_stmt_list_entry (&file_data
->hash
);
2778 /* Equality function for a quick_file_names. */
2781 eq_file_name_entry (const void *a
, const void *b
)
2783 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2784 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2786 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2789 /* Delete function for a quick_file_names. */
2792 delete_file_name_entry (void *e
)
2794 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2797 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2799 xfree ((void*) file_data
->file_names
[i
]);
2800 if (file_data
->real_names
)
2801 xfree ((void*) file_data
->real_names
[i
]);
2804 /* The space for the struct itself lives on objfile_obstack,
2805 so we don't free it here. */
2808 /* Create a quick_file_names hash table. */
2811 create_quick_file_names_table (unsigned int nr_initial_entries
)
2813 return htab_create_alloc (nr_initial_entries
,
2814 hash_file_name_entry
, eq_file_name_entry
,
2815 delete_file_name_entry
, xcalloc
, xfree
);
2818 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2819 have to be created afterwards. You should call age_cached_comp_units after
2820 processing PER_CU->CU. dw2_setup must have been already called. */
2823 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2825 if (per_cu
->is_debug_types
)
2826 load_full_type_unit (per_cu
);
2828 load_full_comp_unit (per_cu
, language_minimal
);
2830 if (per_cu
->cu
== NULL
)
2831 return; /* Dummy CU. */
2833 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2836 /* Read in the symbols for PER_CU. */
2839 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2841 struct cleanup
*back_to
;
2843 /* Skip type_unit_groups, reading the type units they contain
2844 is handled elsewhere. */
2845 if (IS_TYPE_UNIT_GROUP (per_cu
))
2848 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2850 if (dwarf2_per_objfile
->using_index
2851 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2852 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2854 queue_comp_unit (per_cu
, language_minimal
);
2857 /* If we just loaded a CU from a DWO, and we're working with an index
2858 that may badly handle TUs, load all the TUs in that DWO as well.
2859 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2860 if (!per_cu
->is_debug_types
2861 && per_cu
->cu
!= NULL
2862 && per_cu
->cu
->dwo_unit
!= NULL
2863 && dwarf2_per_objfile
->index_table
!= NULL
2864 && dwarf2_per_objfile
->index_table
->version
<= 7
2865 /* DWP files aren't supported yet. */
2866 && get_dwp_file () == NULL
)
2867 queue_and_load_all_dwo_tus (per_cu
);
2872 /* Age the cache, releasing compilation units that have not
2873 been used recently. */
2874 age_cached_comp_units ();
2876 do_cleanups (back_to
);
2879 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2880 the objfile from which this CU came. Returns the resulting symbol
2883 static struct compunit_symtab
*
2884 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2886 gdb_assert (dwarf2_per_objfile
->using_index
);
2887 if (!per_cu
->v
.quick
->compunit_symtab
)
2889 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2890 scoped_restore decrementer
= increment_reading_symtab ();
2891 dw2_do_instantiate_symtab (per_cu
);
2892 process_cu_includes ();
2893 do_cleanups (back_to
);
2896 return per_cu
->v
.quick
->compunit_symtab
;
2899 /* Return the CU/TU given its index.
2901 This is intended for loops like:
2903 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2904 + dwarf2_per_objfile->n_type_units); ++i)
2906 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
2912 static struct dwarf2_per_cu_data
*
2913 dw2_get_cutu (int index
)
2915 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2917 index
-= dwarf2_per_objfile
->n_comp_units
;
2918 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2919 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2922 return dwarf2_per_objfile
->all_comp_units
[index
];
2925 /* Return the CU given its index.
2926 This differs from dw2_get_cutu in that it's for when you know INDEX
2929 static struct dwarf2_per_cu_data
*
2930 dw2_get_cu (int index
)
2932 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
2934 return dwarf2_per_objfile
->all_comp_units
[index
];
2937 /* A helper for create_cus_from_index that handles a given list of
2941 create_cus_from_index_list (struct objfile
*objfile
,
2942 const gdb_byte
*cu_list
, offset_type n_elements
,
2943 struct dwarf2_section_info
*section
,
2949 for (i
= 0; i
< n_elements
; i
+= 2)
2951 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2953 sect_offset sect_off
2954 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2955 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2958 dwarf2_per_cu_data
*the_cu
2959 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2960 struct dwarf2_per_cu_data
);
2961 the_cu
->sect_off
= sect_off
;
2962 the_cu
->length
= length
;
2963 the_cu
->objfile
= objfile
;
2964 the_cu
->section
= section
;
2965 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2966 struct dwarf2_per_cu_quick_data
);
2967 the_cu
->is_dwz
= is_dwz
;
2968 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2972 /* Read the CU list from the mapped index, and use it to create all
2973 the CU objects for this objfile. */
2976 create_cus_from_index (struct objfile
*objfile
,
2977 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2978 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2980 struct dwz_file
*dwz
;
2982 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2983 dwarf2_per_objfile
->all_comp_units
=
2984 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
2985 dwarf2_per_objfile
->n_comp_units
);
2987 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2988 &dwarf2_per_objfile
->info
, 0, 0);
2990 if (dwz_elements
== 0)
2993 dwz
= dwarf2_get_dwz_file ();
2994 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
2995 cu_list_elements
/ 2);
2998 /* Create the signatured type hash table from the index. */
3001 create_signatured_type_table_from_index (struct objfile
*objfile
,
3002 struct dwarf2_section_info
*section
,
3003 const gdb_byte
*bytes
,
3004 offset_type elements
)
3007 htab_t sig_types_hash
;
3009 dwarf2_per_objfile
->n_type_units
3010 = dwarf2_per_objfile
->n_allocated_type_units
3012 dwarf2_per_objfile
->all_type_units
=
3013 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3015 sig_types_hash
= allocate_signatured_type_table (objfile
);
3017 for (i
= 0; i
< elements
; i
+= 3)
3019 struct signatured_type
*sig_type
;
3022 cu_offset type_offset_in_tu
;
3024 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3025 sect_offset sect_off
3026 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3028 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3030 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3033 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3034 struct signatured_type
);
3035 sig_type
->signature
= signature
;
3036 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3037 sig_type
->per_cu
.is_debug_types
= 1;
3038 sig_type
->per_cu
.section
= section
;
3039 sig_type
->per_cu
.sect_off
= sect_off
;
3040 sig_type
->per_cu
.objfile
= objfile
;
3041 sig_type
->per_cu
.v
.quick
3042 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3043 struct dwarf2_per_cu_quick_data
);
3045 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3048 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
3051 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3054 /* Read the address map data from the mapped index, and use it to
3055 populate the objfile's psymtabs_addrmap. */
3058 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
3060 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3061 const gdb_byte
*iter
, *end
;
3062 struct addrmap
*mutable_map
;
3065 auto_obstack temp_obstack
;
3067 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3069 iter
= index
->address_table
;
3070 end
= iter
+ index
->address_table_size
;
3072 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3076 ULONGEST hi
, lo
, cu_index
;
3077 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3079 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3081 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3086 complaint (&symfile_complaints
,
3087 _(".gdb_index address table has invalid range (%s - %s)"),
3088 hex_string (lo
), hex_string (hi
));
3092 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
3094 complaint (&symfile_complaints
,
3095 _(".gdb_index address table has invalid CU number %u"),
3096 (unsigned) cu_index
);
3100 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3101 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3102 addrmap_set_empty (mutable_map
, lo
, hi
- 1, dw2_get_cutu (cu_index
));
3105 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3106 &objfile
->objfile_obstack
);
3109 /* The hash function for strings in the mapped index. This is the same as
3110 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
3111 implementation. This is necessary because the hash function is tied to the
3112 format of the mapped index file. The hash values do not have to match with
3115 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
3118 mapped_index_string_hash (int index_version
, const void *p
)
3120 const unsigned char *str
= (const unsigned char *) p
;
3124 while ((c
= *str
++) != 0)
3126 if (index_version
>= 5)
3128 r
= r
* 67 + c
- 113;
3134 /* Find a slot in the mapped index INDEX for the object named NAME.
3135 If NAME is found, set *VEC_OUT to point to the CU vector in the
3136 constant pool and return 1. If NAME cannot be found, return 0. */
3139 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3140 offset_type
**vec_out
)
3142 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3144 offset_type slot
, step
;
3145 int (*cmp
) (const char *, const char *);
3147 if (current_language
->la_language
== language_cplus
3148 || current_language
->la_language
== language_fortran
3149 || current_language
->la_language
== language_d
)
3151 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3154 if (strchr (name
, '(') != NULL
)
3156 char *without_params
= cp_remove_params (name
);
3158 if (without_params
!= NULL
)
3160 make_cleanup (xfree
, without_params
);
3161 name
= without_params
;
3166 /* Index version 4 did not support case insensitive searches. But the
3167 indices for case insensitive languages are built in lowercase, therefore
3168 simulate our NAME being searched is also lowercased. */
3169 hash
= mapped_index_string_hash ((index
->version
== 4
3170 && case_sensitivity
== case_sensitive_off
3171 ? 5 : index
->version
),
3174 slot
= hash
& (index
->symbol_table_slots
- 1);
3175 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
3176 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3180 /* Convert a slot number to an offset into the table. */
3181 offset_type i
= 2 * slot
;
3183 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
3185 do_cleanups (back_to
);
3189 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
3190 if (!cmp (name
, str
))
3192 *vec_out
= (offset_type
*) (index
->constant_pool
3193 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
3194 do_cleanups (back_to
);
3198 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
3202 /* A helper function that reads the .gdb_index from SECTION and fills
3203 in MAP. FILENAME is the name of the file containing the section;
3204 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3205 ok to use deprecated sections.
3207 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3208 out parameters that are filled in with information about the CU and
3209 TU lists in the section.
3211 Returns 1 if all went well, 0 otherwise. */
3214 read_index_from_section (struct objfile
*objfile
,
3215 const char *filename
,
3217 struct dwarf2_section_info
*section
,
3218 struct mapped_index
*map
,
3219 const gdb_byte
**cu_list
,
3220 offset_type
*cu_list_elements
,
3221 const gdb_byte
**types_list
,
3222 offset_type
*types_list_elements
)
3224 const gdb_byte
*addr
;
3225 offset_type version
;
3226 offset_type
*metadata
;
3229 if (dwarf2_section_empty_p (section
))
3232 /* Older elfutils strip versions could keep the section in the main
3233 executable while splitting it for the separate debug info file. */
3234 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3237 dwarf2_read_section (objfile
, section
);
3239 addr
= section
->buffer
;
3240 /* Version check. */
3241 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3242 /* Versions earlier than 3 emitted every copy of a psymbol. This
3243 causes the index to behave very poorly for certain requests. Version 3
3244 contained incomplete addrmap. So, it seems better to just ignore such
3248 static int warning_printed
= 0;
3249 if (!warning_printed
)
3251 warning (_("Skipping obsolete .gdb_index section in %s."),
3253 warning_printed
= 1;
3257 /* Index version 4 uses a different hash function than index version
3260 Versions earlier than 6 did not emit psymbols for inlined
3261 functions. Using these files will cause GDB not to be able to
3262 set breakpoints on inlined functions by name, so we ignore these
3263 indices unless the user has done
3264 "set use-deprecated-index-sections on". */
3265 if (version
< 6 && !deprecated_ok
)
3267 static int warning_printed
= 0;
3268 if (!warning_printed
)
3271 Skipping deprecated .gdb_index section in %s.\n\
3272 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3273 to use the section anyway."),
3275 warning_printed
= 1;
3279 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3280 of the TU (for symbols coming from TUs),
3281 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3282 Plus gold-generated indices can have duplicate entries for global symbols,
3283 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3284 These are just performance bugs, and we can't distinguish gdb-generated
3285 indices from gold-generated ones, so issue no warning here. */
3287 /* Indexes with higher version than the one supported by GDB may be no
3288 longer backward compatible. */
3292 map
->version
= version
;
3293 map
->total_size
= section
->size
;
3295 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3298 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3299 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3303 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3304 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3305 - MAYBE_SWAP (metadata
[i
]))
3309 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3310 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
3311 - MAYBE_SWAP (metadata
[i
]));
3314 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
3315 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
3316 - MAYBE_SWAP (metadata
[i
]))
3317 / (2 * sizeof (offset_type
)));
3320 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3326 /* Read the index file. If everything went ok, initialize the "quick"
3327 elements of all the CUs and return 1. Otherwise, return 0. */
3330 dwarf2_read_index (struct objfile
*objfile
)
3332 struct mapped_index local_map
, *map
;
3333 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3334 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3335 struct dwz_file
*dwz
;
3337 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3338 use_deprecated_index_sections
,
3339 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3340 &cu_list
, &cu_list_elements
,
3341 &types_list
, &types_list_elements
))
3344 /* Don't use the index if it's empty. */
3345 if (local_map
.symbol_table_slots
== 0)
3348 /* If there is a .dwz file, read it so we can get its CU list as
3350 dwz
= dwarf2_get_dwz_file ();
3353 struct mapped_index dwz_map
;
3354 const gdb_byte
*dwz_types_ignore
;
3355 offset_type dwz_types_elements_ignore
;
3357 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3359 &dwz
->gdb_index
, &dwz_map
,
3360 &dwz_list
, &dwz_list_elements
,
3362 &dwz_types_elements_ignore
))
3364 warning (_("could not read '.gdb_index' section from %s; skipping"),
3365 bfd_get_filename (dwz
->dwz_bfd
));
3370 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3373 if (types_list_elements
)
3375 struct dwarf2_section_info
*section
;
3377 /* We can only handle a single .debug_types when we have an
3379 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3382 section
= VEC_index (dwarf2_section_info_def
,
3383 dwarf2_per_objfile
->types
, 0);
3385 create_signatured_type_table_from_index (objfile
, section
, types_list
,
3386 types_list_elements
);
3389 create_addrmap_from_index (objfile
, &local_map
);
3391 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3394 dwarf2_per_objfile
->index_table
= map
;
3395 dwarf2_per_objfile
->using_index
= 1;
3396 dwarf2_per_objfile
->quick_file_names_table
=
3397 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3402 /* A helper for the "quick" functions which sets the global
3403 dwarf2_per_objfile according to OBJFILE. */
3406 dw2_setup (struct objfile
*objfile
)
3408 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
3409 objfile_data (objfile
, dwarf2_objfile_data_key
));
3410 gdb_assert (dwarf2_per_objfile
);
3413 /* die_reader_func for dw2_get_file_names. */
3416 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3417 const gdb_byte
*info_ptr
,
3418 struct die_info
*comp_unit_die
,
3422 struct dwarf2_cu
*cu
= reader
->cu
;
3423 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3424 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3425 struct dwarf2_per_cu_data
*lh_cu
;
3426 struct attribute
*attr
;
3429 struct quick_file_names
*qfn
;
3431 gdb_assert (! this_cu
->is_debug_types
);
3433 /* Our callers never want to match partial units -- instead they
3434 will match the enclosing full CU. */
3435 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3437 this_cu
->v
.quick
->no_file_data
= 1;
3445 sect_offset line_offset
{};
3447 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3450 struct quick_file_names find_entry
;
3452 line_offset
= (sect_offset
) DW_UNSND (attr
);
3454 /* We may have already read in this line header (TU line header sharing).
3455 If we have we're done. */
3456 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3457 find_entry
.hash
.line_sect_off
= line_offset
;
3458 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3459 &find_entry
, INSERT
);
3462 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3466 lh
= dwarf_decode_line_header (line_offset
, cu
);
3470 lh_cu
->v
.quick
->no_file_data
= 1;
3474 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3475 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3476 qfn
->hash
.line_sect_off
= line_offset
;
3477 gdb_assert (slot
!= NULL
);
3480 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3482 qfn
->num_file_names
= lh
->file_names
.size ();
3484 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
3485 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3486 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3487 qfn
->real_names
= NULL
;
3489 lh_cu
->v
.quick
->file_names
= qfn
;
3492 /* A helper for the "quick" functions which attempts to read the line
3493 table for THIS_CU. */
3495 static struct quick_file_names
*
3496 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3498 /* This should never be called for TUs. */
3499 gdb_assert (! this_cu
->is_debug_types
);
3500 /* Nor type unit groups. */
3501 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3503 if (this_cu
->v
.quick
->file_names
!= NULL
)
3504 return this_cu
->v
.quick
->file_names
;
3505 /* If we know there is no line data, no point in looking again. */
3506 if (this_cu
->v
.quick
->no_file_data
)
3509 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3511 if (this_cu
->v
.quick
->no_file_data
)
3513 return this_cu
->v
.quick
->file_names
;
3516 /* A helper for the "quick" functions which computes and caches the
3517 real path for a given file name from the line table. */
3520 dw2_get_real_path (struct objfile
*objfile
,
3521 struct quick_file_names
*qfn
, int index
)
3523 if (qfn
->real_names
== NULL
)
3524 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3525 qfn
->num_file_names
, const char *);
3527 if (qfn
->real_names
[index
] == NULL
)
3528 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
3530 return qfn
->real_names
[index
];
3533 static struct symtab
*
3534 dw2_find_last_source_symtab (struct objfile
*objfile
)
3536 struct compunit_symtab
*cust
;
3539 dw2_setup (objfile
);
3540 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3541 cust
= dw2_instantiate_symtab (dw2_get_cutu (index
));
3544 return compunit_primary_filetab (cust
);
3547 /* Traversal function for dw2_forget_cached_source_info. */
3550 dw2_free_cached_file_names (void **slot
, void *info
)
3552 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3554 if (file_data
->real_names
)
3558 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3560 xfree ((void*) file_data
->real_names
[i
]);
3561 file_data
->real_names
[i
] = NULL
;
3569 dw2_forget_cached_source_info (struct objfile
*objfile
)
3571 dw2_setup (objfile
);
3573 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3574 dw2_free_cached_file_names
, NULL
);
3577 /* Helper function for dw2_map_symtabs_matching_filename that expands
3578 the symtabs and calls the iterator. */
3581 dw2_map_expand_apply (struct objfile
*objfile
,
3582 struct dwarf2_per_cu_data
*per_cu
,
3583 const char *name
, const char *real_path
,
3584 gdb::function_view
<bool (symtab
*)> callback
)
3586 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3588 /* Don't visit already-expanded CUs. */
3589 if (per_cu
->v
.quick
->compunit_symtab
)
3592 /* This may expand more than one symtab, and we want to iterate over
3594 dw2_instantiate_symtab (per_cu
);
3596 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3597 last_made
, callback
);
3600 /* Implementation of the map_symtabs_matching_filename method. */
3603 dw2_map_symtabs_matching_filename
3604 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3605 gdb::function_view
<bool (symtab
*)> callback
)
3608 const char *name_basename
= lbasename (name
);
3610 dw2_setup (objfile
);
3612 /* The rule is CUs specify all the files, including those used by
3613 any TU, so there's no need to scan TUs here. */
3615 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3618 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3619 struct quick_file_names
*file_data
;
3621 /* We only need to look at symtabs not already expanded. */
3622 if (per_cu
->v
.quick
->compunit_symtab
)
3625 file_data
= dw2_get_file_names (per_cu
);
3626 if (file_data
== NULL
)
3629 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3631 const char *this_name
= file_data
->file_names
[j
];
3632 const char *this_real_name
;
3634 if (compare_filenames_for_search (this_name
, name
))
3636 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3642 /* Before we invoke realpath, which can get expensive when many
3643 files are involved, do a quick comparison of the basenames. */
3644 if (! basenames_may_differ
3645 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3648 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3649 if (compare_filenames_for_search (this_real_name
, name
))
3651 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3657 if (real_path
!= NULL
)
3659 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3660 gdb_assert (IS_ABSOLUTE_PATH (name
));
3661 if (this_real_name
!= NULL
3662 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3664 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3676 /* Struct used to manage iterating over all CUs looking for a symbol. */
3678 struct dw2_symtab_iterator
3680 /* The internalized form of .gdb_index. */
3681 struct mapped_index
*index
;
3682 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3683 int want_specific_block
;
3684 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3685 Unused if !WANT_SPECIFIC_BLOCK. */
3687 /* The kind of symbol we're looking for. */
3689 /* The list of CUs from the index entry of the symbol,
3690 or NULL if not found. */
3692 /* The next element in VEC to look at. */
3694 /* The number of elements in VEC, or zero if there is no match. */
3696 /* Have we seen a global version of the symbol?
3697 If so we can ignore all further global instances.
3698 This is to work around gold/15646, inefficient gold-generated
3703 /* Initialize the index symtab iterator ITER.
3704 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3705 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3708 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3709 struct mapped_index
*index
,
3710 int want_specific_block
,
3715 iter
->index
= index
;
3716 iter
->want_specific_block
= want_specific_block
;
3717 iter
->block_index
= block_index
;
3718 iter
->domain
= domain
;
3720 iter
->global_seen
= 0;
3722 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3723 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3731 /* Return the next matching CU or NULL if there are no more. */
3733 static struct dwarf2_per_cu_data
*
3734 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3736 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3738 offset_type cu_index_and_attrs
=
3739 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3740 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3741 struct dwarf2_per_cu_data
*per_cu
;
3742 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3743 /* This value is only valid for index versions >= 7. */
3744 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3745 gdb_index_symbol_kind symbol_kind
=
3746 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3747 /* Only check the symbol attributes if they're present.
3748 Indices prior to version 7 don't record them,
3749 and indices >= 7 may elide them for certain symbols
3750 (gold does this). */
3752 (iter
->index
->version
>= 7
3753 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3755 /* Don't crash on bad data. */
3756 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3757 + dwarf2_per_objfile
->n_type_units
))
3759 complaint (&symfile_complaints
,
3760 _(".gdb_index entry has bad CU index"
3762 objfile_name (dwarf2_per_objfile
->objfile
));
3766 per_cu
= dw2_get_cutu (cu_index
);
3768 /* Skip if already read in. */
3769 if (per_cu
->v
.quick
->compunit_symtab
)
3772 /* Check static vs global. */
3775 if (iter
->want_specific_block
3776 && want_static
!= is_static
)
3778 /* Work around gold/15646. */
3779 if (!is_static
&& iter
->global_seen
)
3782 iter
->global_seen
= 1;
3785 /* Only check the symbol's kind if it has one. */
3788 switch (iter
->domain
)
3791 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3792 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3793 /* Some types are also in VAR_DOMAIN. */
3794 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3798 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3802 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3817 static struct compunit_symtab
*
3818 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3819 const char *name
, domain_enum domain
)
3821 struct compunit_symtab
*stab_best
= NULL
;
3822 struct mapped_index
*index
;
3824 dw2_setup (objfile
);
3826 index
= dwarf2_per_objfile
->index_table
;
3828 /* index is NULL if OBJF_READNOW. */
3831 struct dw2_symtab_iterator iter
;
3832 struct dwarf2_per_cu_data
*per_cu
;
3834 dw2_symtab_iter_init (&iter
, index
, 1, block_index
, domain
, name
);
3836 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3838 struct symbol
*sym
, *with_opaque
= NULL
;
3839 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
3840 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3841 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3843 sym
= block_find_symbol (block
, name
, domain
,
3844 block_find_non_opaque_type_preferred
,
3847 /* Some caution must be observed with overloaded functions
3848 and methods, since the index will not contain any overload
3849 information (but NAME might contain it). */
3852 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
3854 if (with_opaque
!= NULL
3855 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
3858 /* Keep looking through other CUs. */
3866 dw2_print_stats (struct objfile
*objfile
)
3868 int i
, total
, count
;
3870 dw2_setup (objfile
);
3871 total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
3873 for (i
= 0; i
< total
; ++i
)
3875 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3877 if (!per_cu
->v
.quick
->compunit_symtab
)
3880 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3881 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3884 /* This dumps minimal information about the index.
3885 It is called via "mt print objfiles".
3886 One use is to verify .gdb_index has been loaded by the
3887 gdb.dwarf2/gdb-index.exp testcase. */
3890 dw2_dump (struct objfile
*objfile
)
3892 dw2_setup (objfile
);
3893 gdb_assert (dwarf2_per_objfile
->using_index
);
3894 printf_filtered (".gdb_index:");
3895 if (dwarf2_per_objfile
->index_table
!= NULL
)
3897 printf_filtered (" version %d\n",
3898 dwarf2_per_objfile
->index_table
->version
);
3901 printf_filtered (" faked for \"readnow\"\n");
3902 printf_filtered ("\n");
3906 dw2_relocate (struct objfile
*objfile
,
3907 const struct section_offsets
*new_offsets
,
3908 const struct section_offsets
*delta
)
3910 /* There's nothing to relocate here. */
3914 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3915 const char *func_name
)
3917 struct mapped_index
*index
;
3919 dw2_setup (objfile
);
3921 index
= dwarf2_per_objfile
->index_table
;
3923 /* index is NULL if OBJF_READNOW. */
3926 struct dw2_symtab_iterator iter
;
3927 struct dwarf2_per_cu_data
*per_cu
;
3929 /* Note: It doesn't matter what we pass for block_index here. */
3930 dw2_symtab_iter_init (&iter
, index
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
3933 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3934 dw2_instantiate_symtab (per_cu
);
3939 dw2_expand_all_symtabs (struct objfile
*objfile
)
3943 dw2_setup (objfile
);
3945 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3946 + dwarf2_per_objfile
->n_type_units
); ++i
)
3948 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3950 dw2_instantiate_symtab (per_cu
);
3955 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3956 const char *fullname
)
3960 dw2_setup (objfile
);
3962 /* We don't need to consider type units here.
3963 This is only called for examining code, e.g. expand_line_sal.
3964 There can be an order of magnitude (or more) more type units
3965 than comp units, and we avoid them if we can. */
3967 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3970 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3971 struct quick_file_names
*file_data
;
3973 /* We only need to look at symtabs not already expanded. */
3974 if (per_cu
->v
.quick
->compunit_symtab
)
3977 file_data
= dw2_get_file_names (per_cu
);
3978 if (file_data
== NULL
)
3981 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3983 const char *this_fullname
= file_data
->file_names
[j
];
3985 if (filename_cmp (this_fullname
, fullname
) == 0)
3987 dw2_instantiate_symtab (per_cu
);
3995 dw2_map_matching_symbols (struct objfile
*objfile
,
3996 const char * name
, domain_enum domain
,
3998 int (*callback
) (struct block
*,
3999 struct symbol
*, void *),
4000 void *data
, symbol_compare_ftype
*match
,
4001 symbol_compare_ftype
*ordered_compare
)
4003 /* Currently unimplemented; used for Ada. The function can be called if the
4004 current language is Ada for a non-Ada objfile using GNU index. As Ada
4005 does not look for non-Ada symbols this function should just return. */
4009 dw2_expand_symtabs_matching
4010 (struct objfile
*objfile
,
4011 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4012 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4013 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4014 enum search_domain kind
)
4018 struct mapped_index
*index
;
4020 dw2_setup (objfile
);
4022 /* index_table is NULL if OBJF_READNOW. */
4023 if (!dwarf2_per_objfile
->index_table
)
4025 index
= dwarf2_per_objfile
->index_table
;
4027 if (file_matcher
!= NULL
)
4029 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4031 NULL
, xcalloc
, xfree
));
4032 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4034 NULL
, xcalloc
, xfree
));
4036 /* The rule is CUs specify all the files, including those used by
4037 any TU, so there's no need to scan TUs here. */
4039 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4042 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4043 struct quick_file_names
*file_data
;
4048 per_cu
->v
.quick
->mark
= 0;
4050 /* We only need to look at symtabs not already expanded. */
4051 if (per_cu
->v
.quick
->compunit_symtab
)
4054 file_data
= dw2_get_file_names (per_cu
);
4055 if (file_data
== NULL
)
4058 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4060 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4062 per_cu
->v
.quick
->mark
= 1;
4066 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4068 const char *this_real_name
;
4070 if (file_matcher (file_data
->file_names
[j
], false))
4072 per_cu
->v
.quick
->mark
= 1;
4076 /* Before we invoke realpath, which can get expensive when many
4077 files are involved, do a quick comparison of the basenames. */
4078 if (!basenames_may_differ
4079 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4083 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4084 if (file_matcher (this_real_name
, false))
4086 per_cu
->v
.quick
->mark
= 1;
4091 slot
= htab_find_slot (per_cu
->v
.quick
->mark
4092 ? visited_found
.get ()
4093 : visited_not_found
.get (),
4099 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
4101 offset_type idx
= 2 * iter
;
4103 offset_type
*vec
, vec_len
, vec_idx
;
4104 int global_seen
= 0;
4108 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
4111 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
4113 if (!symbol_matcher (name
))
4116 /* The name was matched, now expand corresponding CUs that were
4118 vec
= (offset_type
*) (index
->constant_pool
4119 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
4120 vec_len
= MAYBE_SWAP (vec
[0]);
4121 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4123 struct dwarf2_per_cu_data
*per_cu
;
4124 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4125 /* This value is only valid for index versions >= 7. */
4126 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4127 gdb_index_symbol_kind symbol_kind
=
4128 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4129 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4130 /* Only check the symbol attributes if they're present.
4131 Indices prior to version 7 don't record them,
4132 and indices >= 7 may elide them for certain symbols
4133 (gold does this). */
4135 (index
->version
>= 7
4136 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4138 /* Work around gold/15646. */
4141 if (!is_static
&& global_seen
)
4147 /* Only check the symbol's kind if it has one. */
4152 case VARIABLES_DOMAIN
:
4153 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4156 case FUNCTIONS_DOMAIN
:
4157 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4161 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4169 /* Don't crash on bad data. */
4170 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
4171 + dwarf2_per_objfile
->n_type_units
))
4173 complaint (&symfile_complaints
,
4174 _(".gdb_index entry has bad CU index"
4175 " [in module %s]"), objfile_name (objfile
));
4179 per_cu
= dw2_get_cutu (cu_index
);
4180 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4182 int symtab_was_null
=
4183 (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4185 dw2_instantiate_symtab (per_cu
);
4187 if (expansion_notify
!= NULL
4189 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4191 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4198 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4201 static struct compunit_symtab
*
4202 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4207 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4208 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4211 if (cust
->includes
== NULL
)
4214 for (i
= 0; cust
->includes
[i
]; ++i
)
4216 struct compunit_symtab
*s
= cust
->includes
[i
];
4218 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4226 static struct compunit_symtab
*
4227 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4228 struct bound_minimal_symbol msymbol
,
4230 struct obj_section
*section
,
4233 struct dwarf2_per_cu_data
*data
;
4234 struct compunit_symtab
*result
;
4236 dw2_setup (objfile
);
4238 if (!objfile
->psymtabs_addrmap
)
4241 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
4246 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4247 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4248 paddress (get_objfile_arch (objfile
), pc
));
4251 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
4253 gdb_assert (result
!= NULL
);
4258 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4259 void *data
, int need_fullname
)
4262 htab_up
visited (htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
4263 NULL
, xcalloc
, xfree
));
4265 dw2_setup (objfile
);
4267 /* The rule is CUs specify all the files, including those used by
4268 any TU, so there's no need to scan TUs here.
4269 We can ignore file names coming from already-expanded CUs. */
4271 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4273 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4275 if (per_cu
->v
.quick
->compunit_symtab
)
4277 void **slot
= htab_find_slot (visited
.get (),
4278 per_cu
->v
.quick
->file_names
,
4281 *slot
= per_cu
->v
.quick
->file_names
;
4285 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4288 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4289 struct quick_file_names
*file_data
;
4292 /* We only need to look at symtabs not already expanded. */
4293 if (per_cu
->v
.quick
->compunit_symtab
)
4296 file_data
= dw2_get_file_names (per_cu
);
4297 if (file_data
== NULL
)
4300 slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4303 /* Already visited. */
4308 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4310 const char *this_real_name
;
4313 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4315 this_real_name
= NULL
;
4316 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
4322 dw2_has_symbols (struct objfile
*objfile
)
4327 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4330 dw2_find_last_source_symtab
,
4331 dw2_forget_cached_source_info
,
4332 dw2_map_symtabs_matching_filename
,
4337 dw2_expand_symtabs_for_function
,
4338 dw2_expand_all_symtabs
,
4339 dw2_expand_symtabs_with_fullname
,
4340 dw2_map_matching_symbols
,
4341 dw2_expand_symtabs_matching
,
4342 dw2_find_pc_sect_compunit_symtab
,
4343 dw2_map_symbol_filenames
4346 /* Initialize for reading DWARF for this objfile. Return 0 if this
4347 file will use psymtabs, or 1 if using the GNU index. */
4350 dwarf2_initialize_objfile (struct objfile
*objfile
)
4352 /* If we're about to read full symbols, don't bother with the
4353 indices. In this case we also don't care if some other debug
4354 format is making psymtabs, because they are all about to be
4356 if ((objfile
->flags
& OBJF_READNOW
))
4360 dwarf2_per_objfile
->using_index
= 1;
4361 create_all_comp_units (objfile
);
4362 create_all_type_units (objfile
);
4363 dwarf2_per_objfile
->quick_file_names_table
=
4364 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
4366 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
4367 + dwarf2_per_objfile
->n_type_units
); ++i
)
4369 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4371 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4372 struct dwarf2_per_cu_quick_data
);
4375 /* Return 1 so that gdb sees the "quick" functions. However,
4376 these functions will be no-ops because we will have expanded
4381 if (dwarf2_read_index (objfile
))
4389 /* Build a partial symbol table. */
4392 dwarf2_build_psymtabs (struct objfile
*objfile
)
4395 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
4397 init_psymbol_list (objfile
, 1024);
4402 /* This isn't really ideal: all the data we allocate on the
4403 objfile's obstack is still uselessly kept around. However,
4404 freeing it seems unsafe. */
4405 psymtab_discarder
psymtabs (objfile
);
4406 dwarf2_build_psymtabs_hard (objfile
);
4409 CATCH (except
, RETURN_MASK_ERROR
)
4411 exception_print (gdb_stderr
, except
);
4416 /* Return the total length of the CU described by HEADER. */
4419 get_cu_length (const struct comp_unit_head
*header
)
4421 return header
->initial_length_size
+ header
->length
;
4424 /* Return TRUE if SECT_OFF is within CU_HEADER. */
4427 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
4429 sect_offset bottom
= cu_header
->sect_off
;
4430 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
4432 return sect_off
>= bottom
&& sect_off
< top
;
4435 /* Find the base address of the compilation unit for range lists and
4436 location lists. It will normally be specified by DW_AT_low_pc.
4437 In DWARF-3 draft 4, the base address could be overridden by
4438 DW_AT_entry_pc. It's been removed, but GCC still uses this for
4439 compilation units with discontinuous ranges. */
4442 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
4444 struct attribute
*attr
;
4447 cu
->base_address
= 0;
4449 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
4452 cu
->base_address
= attr_value_as_address (attr
);
4457 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4460 cu
->base_address
= attr_value_as_address (attr
);
4466 /* Read in the comp unit header information from the debug_info at info_ptr.
4467 Use rcuh_kind::COMPILE as the default type if not known by the caller.
4468 NOTE: This leaves members offset, first_die_offset to be filled in
4471 static const gdb_byte
*
4472 read_comp_unit_head (struct comp_unit_head
*cu_header
,
4473 const gdb_byte
*info_ptr
,
4474 struct dwarf2_section_info
*section
,
4475 rcuh_kind section_kind
)
4478 unsigned int bytes_read
;
4479 const char *filename
= get_section_file_name (section
);
4480 bfd
*abfd
= get_section_bfd_owner (section
);
4482 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
4483 cu_header
->initial_length_size
= bytes_read
;
4484 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
4485 info_ptr
+= bytes_read
;
4486 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
4488 if (cu_header
->version
< 5)
4489 switch (section_kind
)
4491 case rcuh_kind::COMPILE
:
4492 cu_header
->unit_type
= DW_UT_compile
;
4494 case rcuh_kind::TYPE
:
4495 cu_header
->unit_type
= DW_UT_type
;
4498 internal_error (__FILE__
, __LINE__
,
4499 _("read_comp_unit_head: invalid section_kind"));
4503 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
4504 (read_1_byte (abfd
, info_ptr
));
4506 switch (cu_header
->unit_type
)
4509 if (section_kind
!= rcuh_kind::COMPILE
)
4510 error (_("Dwarf Error: wrong unit_type in compilation unit header "
4511 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
4515 section_kind
= rcuh_kind::TYPE
;
4518 error (_("Dwarf Error: wrong unit_type in compilation unit header "
4519 "(is %d, should be %d or %d) [in module %s]"),
4520 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
4523 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
4526 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
4529 info_ptr
+= bytes_read
;
4530 if (cu_header
->version
< 5)
4532 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
4535 signed_addr
= bfd_get_sign_extend_vma (abfd
);
4536 if (signed_addr
< 0)
4537 internal_error (__FILE__
, __LINE__
,
4538 _("read_comp_unit_head: dwarf from non elf file"));
4539 cu_header
->signed_addr_p
= signed_addr
;
4541 if (section_kind
== rcuh_kind::TYPE
)
4543 LONGEST type_offset
;
4545 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
4548 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
4549 info_ptr
+= bytes_read
;
4550 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
4551 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
4552 error (_("Dwarf Error: Too big type_offset in compilation unit "
4553 "header (is %s) [in module %s]"), plongest (type_offset
),
4560 /* Helper function that returns the proper abbrev section for
4563 static struct dwarf2_section_info
*
4564 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
4566 struct dwarf2_section_info
*abbrev
;
4568 if (this_cu
->is_dwz
)
4569 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
4571 abbrev
= &dwarf2_per_objfile
->abbrev
;
4576 /* Subroutine of read_and_check_comp_unit_head and
4577 read_and_check_type_unit_head to simplify them.
4578 Perform various error checking on the header. */
4581 error_check_comp_unit_head (struct comp_unit_head
*header
,
4582 struct dwarf2_section_info
*section
,
4583 struct dwarf2_section_info
*abbrev_section
)
4585 const char *filename
= get_section_file_name (section
);
4587 if (header
->version
< 2 || header
->version
> 5)
4588 error (_("Dwarf Error: wrong version in compilation unit header "
4589 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
4592 if (to_underlying (header
->abbrev_sect_off
)
4593 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
4594 error (_("Dwarf Error: bad offset (0x%x) in compilation unit header "
4595 "(offset 0x%x + 6) [in module %s]"),
4596 to_underlying (header
->abbrev_sect_off
),
4597 to_underlying (header
->sect_off
),
4600 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
4601 avoid potential 32-bit overflow. */
4602 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
4604 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
4605 "(offset 0x%x + 0) [in module %s]"),
4606 header
->length
, to_underlying (header
->sect_off
),
4610 /* Read in a CU/TU header and perform some basic error checking.
4611 The contents of the header are stored in HEADER.
4612 The result is a pointer to the start of the first DIE. */
4614 static const gdb_byte
*
4615 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
4616 struct dwarf2_section_info
*section
,
4617 struct dwarf2_section_info
*abbrev_section
,
4618 const gdb_byte
*info_ptr
,
4619 rcuh_kind section_kind
)
4621 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
4622 bfd
*abfd
= get_section_bfd_owner (section
);
4624 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
4626 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
4628 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
4630 error_check_comp_unit_head (header
, section
, abbrev_section
);
4635 /* Fetch the abbreviation table offset from a comp or type unit header. */
4638 read_abbrev_offset (struct dwarf2_section_info
*section
,
4639 sect_offset sect_off
)
4641 bfd
*abfd
= get_section_bfd_owner (section
);
4642 const gdb_byte
*info_ptr
;
4643 unsigned int initial_length_size
, offset_size
;
4646 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
4647 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
4648 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
4649 offset_size
= initial_length_size
== 4 ? 4 : 8;
4650 info_ptr
+= initial_length_size
;
4652 version
= read_2_bytes (abfd
, info_ptr
);
4656 /* Skip unit type and address size. */
4660 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
4663 /* Allocate a new partial symtab for file named NAME and mark this new
4664 partial symtab as being an include of PST. */
4667 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
4668 struct objfile
*objfile
)
4670 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
4672 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
4674 /* It shares objfile->objfile_obstack. */
4675 subpst
->dirname
= pst
->dirname
;
4678 subpst
->textlow
= 0;
4679 subpst
->texthigh
= 0;
4681 subpst
->dependencies
4682 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
4683 subpst
->dependencies
[0] = pst
;
4684 subpst
->number_of_dependencies
= 1;
4686 subpst
->globals_offset
= 0;
4687 subpst
->n_global_syms
= 0;
4688 subpst
->statics_offset
= 0;
4689 subpst
->n_static_syms
= 0;
4690 subpst
->compunit_symtab
= NULL
;
4691 subpst
->read_symtab
= pst
->read_symtab
;
4694 /* No private part is necessary for include psymtabs. This property
4695 can be used to differentiate between such include psymtabs and
4696 the regular ones. */
4697 subpst
->read_symtab_private
= NULL
;
4700 /* Read the Line Number Program data and extract the list of files
4701 included by the source file represented by PST. Build an include
4702 partial symtab for each of these included files. */
4705 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4706 struct die_info
*die
,
4707 struct partial_symtab
*pst
)
4710 struct attribute
*attr
;
4712 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4714 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
4716 return; /* No linetable, so no includes. */
4718 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4719 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
4723 hash_signatured_type (const void *item
)
4725 const struct signatured_type
*sig_type
4726 = (const struct signatured_type
*) item
;
4728 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4729 return sig_type
->signature
;
4733 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4735 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
4736 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
4738 return lhs
->signature
== rhs
->signature
;
4741 /* Allocate a hash table for signatured types. */
4744 allocate_signatured_type_table (struct objfile
*objfile
)
4746 return htab_create_alloc_ex (41,
4747 hash_signatured_type
,
4750 &objfile
->objfile_obstack
,
4751 hashtab_obstack_allocate
,
4752 dummy_obstack_deallocate
);
4755 /* A helper function to add a signatured type CU to a table. */
4758 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4760 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
4761 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
4769 /* A helper for create_debug_types_hash_table. Read types from SECTION
4770 and fill them into TYPES_HTAB. It will process only type units,
4771 therefore DW_UT_type. */
4774 create_debug_type_hash_table (struct dwo_file
*dwo_file
,
4775 dwarf2_section_info
*section
, htab_t
&types_htab
,
4776 rcuh_kind section_kind
)
4778 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4779 struct dwarf2_section_info
*abbrev_section
;
4781 const gdb_byte
*info_ptr
, *end_ptr
;
4783 abbrev_section
= (dwo_file
!= NULL
4784 ? &dwo_file
->sections
.abbrev
4785 : &dwarf2_per_objfile
->abbrev
);
4787 if (dwarf_read_debug
)
4788 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
4789 get_section_name (section
),
4790 get_section_file_name (abbrev_section
));
4792 dwarf2_read_section (objfile
, section
);
4793 info_ptr
= section
->buffer
;
4795 if (info_ptr
== NULL
)
4798 /* We can't set abfd until now because the section may be empty or
4799 not present, in which case the bfd is unknown. */
4800 abfd
= get_section_bfd_owner (section
);
4802 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4803 because we don't need to read any dies: the signature is in the
4806 end_ptr
= info_ptr
+ section
->size
;
4807 while (info_ptr
< end_ptr
)
4809 struct signatured_type
*sig_type
;
4810 struct dwo_unit
*dwo_tu
;
4812 const gdb_byte
*ptr
= info_ptr
;
4813 struct comp_unit_head header
;
4814 unsigned int length
;
4816 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
4818 /* Initialize it due to a false compiler warning. */
4819 header
.signature
= -1;
4820 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
4822 /* We need to read the type's signature in order to build the hash
4823 table, but we don't need anything else just yet. */
4825 ptr
= read_and_check_comp_unit_head (&header
, section
,
4826 abbrev_section
, ptr
, section_kind
);
4828 length
= get_cu_length (&header
);
4830 /* Skip dummy type units. */
4831 if (ptr
>= info_ptr
+ length
4832 || peek_abbrev_code (abfd
, ptr
) == 0
4833 || header
.unit_type
!= DW_UT_type
)
4839 if (types_htab
== NULL
)
4842 types_htab
= allocate_dwo_unit_table (objfile
);
4844 types_htab
= allocate_signatured_type_table (objfile
);
4850 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4852 dwo_tu
->dwo_file
= dwo_file
;
4853 dwo_tu
->signature
= header
.signature
;
4854 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
4855 dwo_tu
->section
= section
;
4856 dwo_tu
->sect_off
= sect_off
;
4857 dwo_tu
->length
= length
;
4861 /* N.B.: type_offset is not usable if this type uses a DWO file.
4862 The real type_offset is in the DWO file. */
4864 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4865 struct signatured_type
);
4866 sig_type
->signature
= header
.signature
;
4867 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
4868 sig_type
->per_cu
.objfile
= objfile
;
4869 sig_type
->per_cu
.is_debug_types
= 1;
4870 sig_type
->per_cu
.section
= section
;
4871 sig_type
->per_cu
.sect_off
= sect_off
;
4872 sig_type
->per_cu
.length
= length
;
4875 slot
= htab_find_slot (types_htab
,
4876 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4878 gdb_assert (slot
!= NULL
);
4881 sect_offset dup_sect_off
;
4885 const struct dwo_unit
*dup_tu
4886 = (const struct dwo_unit
*) *slot
;
4888 dup_sect_off
= dup_tu
->sect_off
;
4892 const struct signatured_type
*dup_tu
4893 = (const struct signatured_type
*) *slot
;
4895 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
4898 complaint (&symfile_complaints
,
4899 _("debug type entry at offset 0x%x is duplicate to"
4900 " the entry at offset 0x%x, signature %s"),
4901 to_underlying (sect_off
), to_underlying (dup_sect_off
),
4902 hex_string (header
.signature
));
4904 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4906 if (dwarf_read_debug
> 1)
4907 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature %s\n",
4908 to_underlying (sect_off
),
4909 hex_string (header
.signature
));
4915 /* Create the hash table of all entries in the .debug_types
4916 (or .debug_types.dwo) section(s).
4917 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
4918 otherwise it is NULL.
4920 The result is a pointer to the hash table or NULL if there are no types.
4922 Note: This function processes DWO files only, not DWP files. */
4925 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4926 VEC (dwarf2_section_info_def
) *types
,
4930 struct dwarf2_section_info
*section
;
4932 if (VEC_empty (dwarf2_section_info_def
, types
))
4936 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4938 create_debug_type_hash_table (dwo_file
, section
, types_htab
,
4942 /* Create the hash table of all entries in the .debug_types section,
4943 and initialize all_type_units.
4944 The result is zero if there is an error (e.g. missing .debug_types section),
4945 otherwise non-zero. */
4948 create_all_type_units (struct objfile
*objfile
)
4950 htab_t types_htab
= NULL
;
4951 struct signatured_type
**iter
;
4953 create_debug_type_hash_table (NULL
, &dwarf2_per_objfile
->info
, types_htab
,
4954 rcuh_kind::COMPILE
);
4955 create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
, types_htab
);
4956 if (types_htab
== NULL
)
4958 dwarf2_per_objfile
->signatured_types
= NULL
;
4962 dwarf2_per_objfile
->signatured_types
= types_htab
;
4964 dwarf2_per_objfile
->n_type_units
4965 = dwarf2_per_objfile
->n_allocated_type_units
4966 = htab_elements (types_htab
);
4967 dwarf2_per_objfile
->all_type_units
=
4968 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
4969 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4970 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4971 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4972 == dwarf2_per_objfile
->n_type_units
);
4977 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
4978 If SLOT is non-NULL, it is the entry to use in the hash table.
4979 Otherwise we find one. */
4981 static struct signatured_type
*
4982 add_type_unit (ULONGEST sig
, void **slot
)
4984 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4985 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
4986 struct signatured_type
*sig_type
;
4988 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
4990 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
4992 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
4993 dwarf2_per_objfile
->n_allocated_type_units
= 1;
4994 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
4995 dwarf2_per_objfile
->all_type_units
4996 = XRESIZEVEC (struct signatured_type
*,
4997 dwarf2_per_objfile
->all_type_units
,
4998 dwarf2_per_objfile
->n_allocated_type_units
);
4999 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
5001 dwarf2_per_objfile
->n_type_units
= n_type_units
;
5003 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5004 struct signatured_type
);
5005 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
5006 sig_type
->signature
= sig
;
5007 sig_type
->per_cu
.is_debug_types
= 1;
5008 if (dwarf2_per_objfile
->using_index
)
5010 sig_type
->per_cu
.v
.quick
=
5011 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5012 struct dwarf2_per_cu_quick_data
);
5017 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5020 gdb_assert (*slot
== NULL
);
5022 /* The rest of sig_type must be filled in by the caller. */
5026 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
5027 Fill in SIG_ENTRY with DWO_ENTRY. */
5030 fill_in_sig_entry_from_dwo_entry (struct objfile
*objfile
,
5031 struct signatured_type
*sig_entry
,
5032 struct dwo_unit
*dwo_entry
)
5034 /* Make sure we're not clobbering something we don't expect to. */
5035 gdb_assert (! sig_entry
->per_cu
.queued
);
5036 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
5037 if (dwarf2_per_objfile
->using_index
)
5039 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
5040 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
5043 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
5044 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
5045 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
5046 gdb_assert (sig_entry
->type_unit_group
== NULL
);
5047 gdb_assert (sig_entry
->dwo_unit
== NULL
);
5049 sig_entry
->per_cu
.section
= dwo_entry
->section
;
5050 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
5051 sig_entry
->per_cu
.length
= dwo_entry
->length
;
5052 sig_entry
->per_cu
.reading_dwo_directly
= 1;
5053 sig_entry
->per_cu
.objfile
= objfile
;
5054 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
5055 sig_entry
->dwo_unit
= dwo_entry
;
5058 /* Subroutine of lookup_signatured_type.
5059 If we haven't read the TU yet, create the signatured_type data structure
5060 for a TU to be read in directly from a DWO file, bypassing the stub.
5061 This is the "Stay in DWO Optimization": When there is no DWP file and we're
5062 using .gdb_index, then when reading a CU we want to stay in the DWO file
5063 containing that CU. Otherwise we could end up reading several other DWO
5064 files (due to comdat folding) to process the transitive closure of all the
5065 mentioned TUs, and that can be slow. The current DWO file will have every
5066 type signature that it needs.
5067 We only do this for .gdb_index because in the psymtab case we already have
5068 to read all the DWOs to build the type unit groups. */
5070 static struct signatured_type
*
5071 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5073 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5074 struct dwo_file
*dwo_file
;
5075 struct dwo_unit find_dwo_entry
, *dwo_entry
;
5076 struct signatured_type find_sig_entry
, *sig_entry
;
5079 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
5081 /* If TU skeletons have been removed then we may not have read in any
5083 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5085 dwarf2_per_objfile
->signatured_types
5086 = allocate_signatured_type_table (objfile
);
5089 /* We only ever need to read in one copy of a signatured type.
5090 Use the global signatured_types array to do our own comdat-folding
5091 of types. If this is the first time we're reading this TU, and
5092 the TU has an entry in .gdb_index, replace the recorded data from
5093 .gdb_index with this TU. */
5095 find_sig_entry
.signature
= sig
;
5096 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5097 &find_sig_entry
, INSERT
);
5098 sig_entry
= (struct signatured_type
*) *slot
;
5100 /* We can get here with the TU already read, *or* in the process of being
5101 read. Don't reassign the global entry to point to this DWO if that's
5102 the case. Also note that if the TU is already being read, it may not
5103 have come from a DWO, the program may be a mix of Fission-compiled
5104 code and non-Fission-compiled code. */
5106 /* Have we already tried to read this TU?
5107 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5108 needn't exist in the global table yet). */
5109 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
5112 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
5113 dwo_unit of the TU itself. */
5114 dwo_file
= cu
->dwo_unit
->dwo_file
;
5116 /* Ok, this is the first time we're reading this TU. */
5117 if (dwo_file
->tus
== NULL
)
5119 find_dwo_entry
.signature
= sig
;
5120 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
5121 if (dwo_entry
== NULL
)
5124 /* If the global table doesn't have an entry for this TU, add one. */
5125 if (sig_entry
== NULL
)
5126 sig_entry
= add_type_unit (sig
, slot
);
5128 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
5129 sig_entry
->per_cu
.tu_read
= 1;
5133 /* Subroutine of lookup_signatured_type.
5134 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
5135 then try the DWP file. If the TU stub (skeleton) has been removed then
5136 it won't be in .gdb_index. */
5138 static struct signatured_type
*
5139 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5141 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5142 struct dwp_file
*dwp_file
= get_dwp_file ();
5143 struct dwo_unit
*dwo_entry
;
5144 struct signatured_type find_sig_entry
, *sig_entry
;
5147 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
5148 gdb_assert (dwp_file
!= NULL
);
5150 /* If TU skeletons have been removed then we may not have read in any
5152 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5154 dwarf2_per_objfile
->signatured_types
5155 = allocate_signatured_type_table (objfile
);
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 /* Have we already tried to read this TU?
5164 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5165 needn't exist in the global table yet). */
5166 if (sig_entry
!= NULL
)
5169 if (dwp_file
->tus
== NULL
)
5171 dwo_entry
= lookup_dwo_unit_in_dwp (dwp_file
, NULL
,
5172 sig
, 1 /* is_debug_types */);
5173 if (dwo_entry
== NULL
)
5176 sig_entry
= add_type_unit (sig
, slot
);
5177 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
5182 /* Lookup a signature based type for DW_FORM_ref_sig8.
5183 Returns NULL if signature SIG is not present in the table.
5184 It is up to the caller to complain about this. */
5186 static struct signatured_type
*
5187 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5190 && dwarf2_per_objfile
->using_index
)
5192 /* We're in a DWO/DWP file, and we're using .gdb_index.
5193 These cases require special processing. */
5194 if (get_dwp_file () == NULL
)
5195 return lookup_dwo_signatured_type (cu
, sig
);
5197 return lookup_dwp_signatured_type (cu
, sig
);
5201 struct signatured_type find_entry
, *entry
;
5203 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5205 find_entry
.signature
= sig
;
5206 entry
= ((struct signatured_type
*)
5207 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
5212 /* Low level DIE reading support. */
5214 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
5217 init_cu_die_reader (struct die_reader_specs
*reader
,
5218 struct dwarf2_cu
*cu
,
5219 struct dwarf2_section_info
*section
,
5220 struct dwo_file
*dwo_file
)
5222 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
5223 reader
->abfd
= get_section_bfd_owner (section
);
5225 reader
->dwo_file
= dwo_file
;
5226 reader
->die_section
= section
;
5227 reader
->buffer
= section
->buffer
;
5228 reader
->buffer_end
= section
->buffer
+ section
->size
;
5229 reader
->comp_dir
= NULL
;
5232 /* Subroutine of init_cutu_and_read_dies to simplify it.
5233 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
5234 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
5237 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
5238 from it to the DIE in the DWO. If NULL we are skipping the stub.
5239 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
5240 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
5241 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
5242 STUB_COMP_DIR may be non-NULL.
5243 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
5244 are filled in with the info of the DIE from the DWO file.
5245 ABBREV_TABLE_PROVIDED is non-zero if the caller of init_cutu_and_read_dies
5246 provided an abbrev table to use.
5247 The result is non-zero if a valid (non-dummy) DIE was found. */
5250 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
5251 struct dwo_unit
*dwo_unit
,
5252 int abbrev_table_provided
,
5253 struct die_info
*stub_comp_unit_die
,
5254 const char *stub_comp_dir
,
5255 struct die_reader_specs
*result_reader
,
5256 const gdb_byte
**result_info_ptr
,
5257 struct die_info
**result_comp_unit_die
,
5258 int *result_has_children
)
5260 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5261 struct dwarf2_cu
*cu
= this_cu
->cu
;
5262 struct dwarf2_section_info
*section
;
5264 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5265 ULONGEST signature
; /* Or dwo_id. */
5266 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
5267 int i
,num_extra_attrs
;
5268 struct dwarf2_section_info
*dwo_abbrev_section
;
5269 struct attribute
*attr
;
5270 struct die_info
*comp_unit_die
;
5272 /* At most one of these may be provided. */
5273 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
5275 /* These attributes aren't processed until later:
5276 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
5277 DW_AT_comp_dir is used now, to find the DWO file, but it is also
5278 referenced later. However, these attributes are found in the stub
5279 which we won't have later. In order to not impose this complication
5280 on the rest of the code, we read them here and copy them to the
5289 if (stub_comp_unit_die
!= NULL
)
5291 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
5293 if (! this_cu
->is_debug_types
)
5294 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
5295 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
5296 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
5297 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
5298 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
5300 /* There should be a DW_AT_addr_base attribute here (if needed).
5301 We need the value before we can process DW_FORM_GNU_addr_index. */
5303 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
5305 cu
->addr_base
= DW_UNSND (attr
);
5307 /* There should be a DW_AT_ranges_base attribute here (if needed).
5308 We need the value before we can process DW_AT_ranges. */
5309 cu
->ranges_base
= 0;
5310 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
5312 cu
->ranges_base
= DW_UNSND (attr
);
5314 else if (stub_comp_dir
!= NULL
)
5316 /* Reconstruct the comp_dir attribute to simplify the code below. */
5317 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
5318 comp_dir
->name
= DW_AT_comp_dir
;
5319 comp_dir
->form
= DW_FORM_string
;
5320 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
5321 DW_STRING (comp_dir
) = stub_comp_dir
;
5324 /* Set up for reading the DWO CU/TU. */
5325 cu
->dwo_unit
= dwo_unit
;
5326 section
= dwo_unit
->section
;
5327 dwarf2_read_section (objfile
, section
);
5328 abfd
= get_section_bfd_owner (section
);
5329 begin_info_ptr
= info_ptr
= (section
->buffer
5330 + to_underlying (dwo_unit
->sect_off
));
5331 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
5332 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
);
5334 if (this_cu
->is_debug_types
)
5336 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
5338 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5340 info_ptr
, rcuh_kind::TYPE
);
5341 /* This is not an assert because it can be caused by bad debug info. */
5342 if (sig_type
->signature
!= cu
->header
.signature
)
5344 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
5345 " TU at offset 0x%x [in module %s]"),
5346 hex_string (sig_type
->signature
),
5347 hex_string (cu
->header
.signature
),
5348 to_underlying (dwo_unit
->sect_off
),
5349 bfd_get_filename (abfd
));
5351 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
5352 /* For DWOs coming from DWP files, we don't know the CU length
5353 nor the type's offset in the TU until now. */
5354 dwo_unit
->length
= get_cu_length (&cu
->header
);
5355 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
5357 /* Establish the type offset that can be used to lookup the type.
5358 For DWO files, we don't know it until now. */
5359 sig_type
->type_offset_in_section
5360 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
5364 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5366 info_ptr
, rcuh_kind::COMPILE
);
5367 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
5368 /* For DWOs coming from DWP files, we don't know the CU length
5370 dwo_unit
->length
= get_cu_length (&cu
->header
);
5373 /* Replace the CU's original abbrev table with the DWO's.
5374 Reminder: We can't read the abbrev table until we've read the header. */
5375 if (abbrev_table_provided
)
5377 /* Don't free the provided abbrev table, the caller of
5378 init_cutu_and_read_dies owns it. */
5379 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5380 /* Ensure the DWO abbrev table gets freed. */
5381 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5385 dwarf2_free_abbrev_table (cu
);
5386 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5387 /* Leave any existing abbrev table cleanup as is. */
5390 /* Read in the die, but leave space to copy over the attributes
5391 from the stub. This has the benefit of simplifying the rest of
5392 the code - all the work to maintain the illusion of a single
5393 DW_TAG_{compile,type}_unit DIE is done here. */
5394 num_extra_attrs
= ((stmt_list
!= NULL
)
5398 + (comp_dir
!= NULL
));
5399 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
5400 result_has_children
, num_extra_attrs
);
5402 /* Copy over the attributes from the stub to the DIE we just read in. */
5403 comp_unit_die
= *result_comp_unit_die
;
5404 i
= comp_unit_die
->num_attrs
;
5405 if (stmt_list
!= NULL
)
5406 comp_unit_die
->attrs
[i
++] = *stmt_list
;
5408 comp_unit_die
->attrs
[i
++] = *low_pc
;
5409 if (high_pc
!= NULL
)
5410 comp_unit_die
->attrs
[i
++] = *high_pc
;
5412 comp_unit_die
->attrs
[i
++] = *ranges
;
5413 if (comp_dir
!= NULL
)
5414 comp_unit_die
->attrs
[i
++] = *comp_dir
;
5415 comp_unit_die
->num_attrs
+= num_extra_attrs
;
5417 if (dwarf_die_debug
)
5419 fprintf_unfiltered (gdb_stdlog
,
5420 "Read die from %s@0x%x of %s:\n",
5421 get_section_name (section
),
5422 (unsigned) (begin_info_ptr
- section
->buffer
),
5423 bfd_get_filename (abfd
));
5424 dump_die (comp_unit_die
, dwarf_die_debug
);
5427 /* Save the comp_dir attribute. If there is no DWP file then we'll read
5428 TUs by skipping the stub and going directly to the entry in the DWO file.
5429 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
5430 to get it via circuitous means. Blech. */
5431 if (comp_dir
!= NULL
)
5432 result_reader
->comp_dir
= DW_STRING (comp_dir
);
5434 /* Skip dummy compilation units. */
5435 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
5436 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5439 *result_info_ptr
= info_ptr
;
5443 /* Subroutine of init_cutu_and_read_dies to simplify it.
5444 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
5445 Returns NULL if the specified DWO unit cannot be found. */
5447 static struct dwo_unit
*
5448 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
5449 struct die_info
*comp_unit_die
)
5451 struct dwarf2_cu
*cu
= this_cu
->cu
;
5452 struct attribute
*attr
;
5454 struct dwo_unit
*dwo_unit
;
5455 const char *comp_dir
, *dwo_name
;
5457 gdb_assert (cu
!= NULL
);
5459 /* Yeah, we look dwo_name up again, but it simplifies the code. */
5460 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5461 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
5463 if (this_cu
->is_debug_types
)
5465 struct signatured_type
*sig_type
;
5467 /* Since this_cu is the first member of struct signatured_type,
5468 we can go from a pointer to one to a pointer to the other. */
5469 sig_type
= (struct signatured_type
*) this_cu
;
5470 signature
= sig_type
->signature
;
5471 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
5475 struct attribute
*attr
;
5477 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
5479 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
5481 dwo_name
, objfile_name (this_cu
->objfile
));
5482 signature
= DW_UNSND (attr
);
5483 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
5490 /* Subroutine of init_cutu_and_read_dies to simplify it.
5491 See it for a description of the parameters.
5492 Read a TU directly from a DWO file, bypassing the stub.
5494 Note: This function could be a little bit simpler if we shared cleanups
5495 with our caller, init_cutu_and_read_dies. That's generally a fragile thing
5496 to do, so we keep this function self-contained. Or we could move this
5497 into our caller, but it's complex enough already. */
5500 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
5501 int use_existing_cu
, int keep
,
5502 die_reader_func_ftype
*die_reader_func
,
5505 struct dwarf2_cu
*cu
;
5506 struct signatured_type
*sig_type
;
5507 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5508 struct die_reader_specs reader
;
5509 const gdb_byte
*info_ptr
;
5510 struct die_info
*comp_unit_die
;
5513 /* Verify we can do the following downcast, and that we have the
5515 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
5516 sig_type
= (struct signatured_type
*) this_cu
;
5517 gdb_assert (sig_type
->dwo_unit
!= NULL
);
5519 cleanups
= make_cleanup (null_cleanup
, NULL
);
5521 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5523 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
5525 /* There's no need to do the rereading_dwo_cu handling that
5526 init_cutu_and_read_dies does since we don't read the stub. */
5530 /* If !use_existing_cu, this_cu->cu must be NULL. */
5531 gdb_assert (this_cu
->cu
== NULL
);
5532 cu
= XNEW (struct dwarf2_cu
);
5533 init_one_comp_unit (cu
, this_cu
);
5534 /* If an error occurs while loading, release our storage. */
5535 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5538 /* A future optimization, if needed, would be to use an existing
5539 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
5540 could share abbrev tables. */
5542 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
5543 0 /* abbrev_table_provided */,
5544 NULL
/* stub_comp_unit_die */,
5545 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
5547 &comp_unit_die
, &has_children
) == 0)
5550 do_cleanups (cleanups
);
5554 /* All the "real" work is done here. */
5555 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5557 /* This duplicates the code in init_cutu_and_read_dies,
5558 but the alternative is making the latter more complex.
5559 This function is only for the special case of using DWO files directly:
5560 no point in overly complicating the general case just to handle this. */
5561 if (free_cu_cleanup
!= NULL
)
5565 /* We've successfully allocated this compilation unit. Let our
5566 caller clean it up when finished with it. */
5567 discard_cleanups (free_cu_cleanup
);
5569 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5570 So we have to manually free the abbrev table. */
5571 dwarf2_free_abbrev_table (cu
);
5573 /* Link this CU into read_in_chain. */
5574 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5575 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5578 do_cleanups (free_cu_cleanup
);
5581 do_cleanups (cleanups
);
5584 /* Initialize a CU (or TU) and read its DIEs.
5585 If the CU defers to a DWO file, read the DWO file as well.
5587 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
5588 Otherwise the table specified in the comp unit header is read in and used.
5589 This is an optimization for when we already have the abbrev table.
5591 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
5592 Otherwise, a new CU is allocated with xmalloc.
5594 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
5595 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
5597 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5598 linker) then DIE_READER_FUNC will not get called. */
5601 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
5602 struct abbrev_table
*abbrev_table
,
5603 int use_existing_cu
, int keep
,
5604 die_reader_func_ftype
*die_reader_func
,
5607 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5608 struct dwarf2_section_info
*section
= this_cu
->section
;
5609 bfd
*abfd
= get_section_bfd_owner (section
);
5610 struct dwarf2_cu
*cu
;
5611 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5612 struct die_reader_specs reader
;
5613 struct die_info
*comp_unit_die
;
5615 struct attribute
*attr
;
5616 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5617 struct signatured_type
*sig_type
= NULL
;
5618 struct dwarf2_section_info
*abbrev_section
;
5619 /* Non-zero if CU currently points to a DWO file and we need to
5620 reread it. When this happens we need to reread the skeleton die
5621 before we can reread the DWO file (this only applies to CUs, not TUs). */
5622 int rereading_dwo_cu
= 0;
5624 if (dwarf_die_debug
)
5625 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5626 this_cu
->is_debug_types
? "type" : "comp",
5627 to_underlying (this_cu
->sect_off
));
5629 if (use_existing_cu
)
5632 /* If we're reading a TU directly from a DWO file, including a virtual DWO
5633 file (instead of going through the stub), short-circuit all of this. */
5634 if (this_cu
->reading_dwo_directly
)
5636 /* Narrow down the scope of possibilities to have to understand. */
5637 gdb_assert (this_cu
->is_debug_types
);
5638 gdb_assert (abbrev_table
== NULL
);
5639 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
5640 die_reader_func
, data
);
5644 cleanups
= make_cleanup (null_cleanup
, NULL
);
5646 /* This is cheap if the section is already read in. */
5647 dwarf2_read_section (objfile
, section
);
5649 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
5651 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
5653 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5656 /* If this CU is from a DWO file we need to start over, we need to
5657 refetch the attributes from the skeleton CU.
5658 This could be optimized by retrieving those attributes from when we
5659 were here the first time: the previous comp_unit_die was stored in
5660 comp_unit_obstack. But there's no data yet that we need this
5662 if (cu
->dwo_unit
!= NULL
)
5663 rereading_dwo_cu
= 1;
5667 /* If !use_existing_cu, this_cu->cu must be NULL. */
5668 gdb_assert (this_cu
->cu
== NULL
);
5669 cu
= XNEW (struct dwarf2_cu
);
5670 init_one_comp_unit (cu
, this_cu
);
5671 /* If an error occurs while loading, release our storage. */
5672 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5675 /* Get the header. */
5676 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
5678 /* We already have the header, there's no need to read it in again. */
5679 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
5683 if (this_cu
->is_debug_types
)
5685 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5686 abbrev_section
, info_ptr
,
5689 /* Since per_cu is the first member of struct signatured_type,
5690 we can go from a pointer to one to a pointer to the other. */
5691 sig_type
= (struct signatured_type
*) this_cu
;
5692 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
5693 gdb_assert (sig_type
->type_offset_in_tu
5694 == cu
->header
.type_cu_offset_in_tu
);
5695 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
5697 /* LENGTH has not been set yet for type units if we're
5698 using .gdb_index. */
5699 this_cu
->length
= get_cu_length (&cu
->header
);
5701 /* Establish the type offset that can be used to lookup the type. */
5702 sig_type
->type_offset_in_section
=
5703 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
5705 this_cu
->dwarf_version
= cu
->header
.version
;
5709 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5712 rcuh_kind::COMPILE
);
5714 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
5715 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
5716 this_cu
->dwarf_version
= cu
->header
.version
;
5720 /* Skip dummy compilation units. */
5721 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5722 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5724 do_cleanups (cleanups
);
5728 /* If we don't have them yet, read the abbrevs for this compilation unit.
5729 And if we need to read them now, make sure they're freed when we're
5730 done. Note that it's important that if the CU had an abbrev table
5731 on entry we don't free it when we're done: Somewhere up the call stack
5732 it may be in use. */
5733 if (abbrev_table
!= NULL
)
5735 gdb_assert (cu
->abbrev_table
== NULL
);
5736 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
5737 cu
->abbrev_table
= abbrev_table
;
5739 else if (cu
->abbrev_table
== NULL
)
5741 dwarf2_read_abbrevs (cu
, abbrev_section
);
5742 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5744 else if (rereading_dwo_cu
)
5746 dwarf2_free_abbrev_table (cu
);
5747 dwarf2_read_abbrevs (cu
, abbrev_section
);
5750 /* Read the top level CU/TU die. */
5751 init_cu_die_reader (&reader
, cu
, section
, NULL
);
5752 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5754 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
5756 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
5757 DWO CU, that this test will fail (the attribute will not be present). */
5758 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5761 struct dwo_unit
*dwo_unit
;
5762 struct die_info
*dwo_comp_unit_die
;
5766 complaint (&symfile_complaints
,
5767 _("compilation unit with DW_AT_GNU_dwo_name"
5768 " has children (offset 0x%x) [in module %s]"),
5769 to_underlying (this_cu
->sect_off
), bfd_get_filename (abfd
));
5771 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
5772 if (dwo_unit
!= NULL
)
5774 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
5775 abbrev_table
!= NULL
,
5776 comp_unit_die
, NULL
,
5778 &dwo_comp_unit_die
, &has_children
) == 0)
5781 do_cleanups (cleanups
);
5784 comp_unit_die
= dwo_comp_unit_die
;
5788 /* Yikes, we couldn't find the rest of the DIE, we only have
5789 the stub. A complaint has already been logged. There's
5790 not much more we can do except pass on the stub DIE to
5791 die_reader_func. We don't want to throw an error on bad
5796 /* All of the above is setup for this call. Yikes. */
5797 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5799 /* Done, clean up. */
5800 if (free_cu_cleanup
!= NULL
)
5804 /* We've successfully allocated this compilation unit. Let our
5805 caller clean it up when finished with it. */
5806 discard_cleanups (free_cu_cleanup
);
5808 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5809 So we have to manually free the abbrev table. */
5810 dwarf2_free_abbrev_table (cu
);
5812 /* Link this CU into read_in_chain. */
5813 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5814 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5817 do_cleanups (free_cu_cleanup
);
5820 do_cleanups (cleanups
);
5823 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
5824 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
5825 to have already done the lookup to find the DWO file).
5827 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
5828 THIS_CU->is_debug_types, but nothing else.
5830 We fill in THIS_CU->length.
5832 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5833 linker) then DIE_READER_FUNC will not get called.
5835 THIS_CU->cu is always freed when done.
5836 This is done in order to not leave THIS_CU->cu in a state where we have
5837 to care whether it refers to the "main" CU or the DWO CU. */
5840 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
5841 struct dwo_file
*dwo_file
,
5842 die_reader_func_ftype
*die_reader_func
,
5845 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5846 struct dwarf2_section_info
*section
= this_cu
->section
;
5847 bfd
*abfd
= get_section_bfd_owner (section
);
5848 struct dwarf2_section_info
*abbrev_section
;
5849 struct dwarf2_cu cu
;
5850 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5851 struct die_reader_specs reader
;
5852 struct cleanup
*cleanups
;
5853 struct die_info
*comp_unit_die
;
5856 if (dwarf_die_debug
)
5857 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5858 this_cu
->is_debug_types
? "type" : "comp",
5859 to_underlying (this_cu
->sect_off
));
5861 gdb_assert (this_cu
->cu
== NULL
);
5863 abbrev_section
= (dwo_file
!= NULL
5864 ? &dwo_file
->sections
.abbrev
5865 : get_abbrev_section_for_cu (this_cu
));
5867 /* This is cheap if the section is already read in. */
5868 dwarf2_read_section (objfile
, section
);
5870 init_one_comp_unit (&cu
, this_cu
);
5872 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
5874 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
5875 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
5876 abbrev_section
, info_ptr
,
5877 (this_cu
->is_debug_types
5879 : rcuh_kind::COMPILE
));
5881 this_cu
->length
= get_cu_length (&cu
.header
);
5883 /* Skip dummy compilation units. */
5884 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5885 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5887 do_cleanups (cleanups
);
5891 dwarf2_read_abbrevs (&cu
, abbrev_section
);
5892 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
5894 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
5895 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5897 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5899 do_cleanups (cleanups
);
5902 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
5903 does not lookup the specified DWO file.
5904 This cannot be used to read DWO files.
5906 THIS_CU->cu is always freed when done.
5907 This is done in order to not leave THIS_CU->cu in a state where we have
5908 to care whether it refers to the "main" CU or the DWO CU.
5909 We can revisit this if the data shows there's a performance issue. */
5912 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
5913 die_reader_func_ftype
*die_reader_func
,
5916 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
5919 /* Type Unit Groups.
5921 Type Unit Groups are a way to collapse the set of all TUs (type units) into
5922 a more manageable set. The grouping is done by DW_AT_stmt_list entry
5923 so that all types coming from the same compilation (.o file) are grouped
5924 together. A future step could be to put the types in the same symtab as
5925 the CU the types ultimately came from. */
5928 hash_type_unit_group (const void *item
)
5930 const struct type_unit_group
*tu_group
5931 = (const struct type_unit_group
*) item
;
5933 return hash_stmt_list_entry (&tu_group
->hash
);
5937 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
5939 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
5940 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
5942 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
5945 /* Allocate a hash table for type unit groups. */
5948 allocate_type_unit_groups_table (void)
5950 return htab_create_alloc_ex (3,
5951 hash_type_unit_group
,
5954 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
5955 hashtab_obstack_allocate
,
5956 dummy_obstack_deallocate
);
5959 /* Type units that don't have DW_AT_stmt_list are grouped into their own
5960 partial symtabs. We combine several TUs per psymtab to not let the size
5961 of any one psymtab grow too big. */
5962 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
5963 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5965 /* Helper routine for get_type_unit_group.
5966 Create the type_unit_group object used to hold one or more TUs. */
5968 static struct type_unit_group
*
5969 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
5971 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5972 struct dwarf2_per_cu_data
*per_cu
;
5973 struct type_unit_group
*tu_group
;
5975 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5976 struct type_unit_group
);
5977 per_cu
= &tu_group
->per_cu
;
5978 per_cu
->objfile
= objfile
;
5980 if (dwarf2_per_objfile
->using_index
)
5982 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5983 struct dwarf2_per_cu_quick_data
);
5987 unsigned int line_offset
= to_underlying (line_offset_struct
);
5988 struct partial_symtab
*pst
;
5991 /* Give the symtab a useful name for debug purposes. */
5992 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
5993 name
= xstrprintf ("<type_units_%d>",
5994 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
5996 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
5998 pst
= create_partial_symtab (per_cu
, name
);
6004 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6005 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6010 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6011 STMT_LIST is a DW_AT_stmt_list attribute. */
6013 static struct type_unit_group
*
6014 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6016 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6017 struct type_unit_group
*tu_group
;
6019 unsigned int line_offset
;
6020 struct type_unit_group type_unit_group_for_lookup
;
6022 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
6024 dwarf2_per_objfile
->type_unit_groups
=
6025 allocate_type_unit_groups_table ();
6028 /* Do we need to create a new group, or can we use an existing one? */
6032 line_offset
= DW_UNSND (stmt_list
);
6033 ++tu_stats
->nr_symtab_sharers
;
6037 /* Ugh, no stmt_list. Rare, but we have to handle it.
6038 We can do various things here like create one group per TU or
6039 spread them over multiple groups to split up the expansion work.
6040 To avoid worst case scenarios (too many groups or too large groups)
6041 we, umm, group them in bunches. */
6042 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6043 | (tu_stats
->nr_stmt_less_type_units
6044 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6045 ++tu_stats
->nr_stmt_less_type_units
;
6048 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6049 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6050 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
6051 &type_unit_group_for_lookup
, INSERT
);
6054 tu_group
= (struct type_unit_group
*) *slot
;
6055 gdb_assert (tu_group
!= NULL
);
6059 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6060 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
6062 ++tu_stats
->nr_symtabs
;
6068 /* Partial symbol tables. */
6070 /* Create a psymtab named NAME and assign it to PER_CU.
6072 The caller must fill in the following details:
6073 dirname, textlow, texthigh. */
6075 static struct partial_symtab
*
6076 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
6078 struct objfile
*objfile
= per_cu
->objfile
;
6079 struct partial_symtab
*pst
;
6081 pst
= start_psymtab_common (objfile
, name
, 0,
6082 objfile
->global_psymbols
.next
,
6083 objfile
->static_psymbols
.next
);
6085 pst
->psymtabs_addrmap_supported
= 1;
6087 /* This is the glue that links PST into GDB's symbol API. */
6088 pst
->read_symtab_private
= per_cu
;
6089 pst
->read_symtab
= dwarf2_read_symtab
;
6090 per_cu
->v
.psymtab
= pst
;
6095 /* The DATA object passed to process_psymtab_comp_unit_reader has this
6098 struct process_psymtab_comp_unit_data
6100 /* True if we are reading a DW_TAG_partial_unit. */
6102 int want_partial_unit
;
6104 /* The "pretend" language that is used if the CU doesn't declare a
6107 enum language pretend_language
;
6110 /* die_reader_func for process_psymtab_comp_unit. */
6113 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6114 const gdb_byte
*info_ptr
,
6115 struct die_info
*comp_unit_die
,
6119 struct dwarf2_cu
*cu
= reader
->cu
;
6120 struct objfile
*objfile
= cu
->objfile
;
6121 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6122 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6124 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6125 struct partial_symtab
*pst
;
6126 enum pc_bounds_kind cu_bounds_kind
;
6127 const char *filename
;
6128 struct process_psymtab_comp_unit_data
*info
6129 = (struct process_psymtab_comp_unit_data
*) data
;
6131 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
6134 gdb_assert (! per_cu
->is_debug_types
);
6136 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
6138 cu
->list_in_scope
= &file_symbols
;
6140 /* Allocate a new partial symbol table structure. */
6141 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
6142 if (filename
== NULL
)
6145 pst
= create_partial_symtab (per_cu
, filename
);
6147 /* This must be done before calling dwarf2_build_include_psymtabs. */
6148 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6150 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6152 dwarf2_find_base_address (comp_unit_die
, cu
);
6154 /* Possibly set the default values of LOWPC and HIGHPC from
6156 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
6157 &best_highpc
, cu
, pst
);
6158 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
6159 /* Store the contiguous range if it is not empty; it can be empty for
6160 CUs with no code. */
6161 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6162 gdbarch_adjust_dwarf2_addr (gdbarch
,
6163 best_lowpc
+ baseaddr
),
6164 gdbarch_adjust_dwarf2_addr (gdbarch
,
6165 best_highpc
+ baseaddr
) - 1,
6168 /* Check if comp unit has_children.
6169 If so, read the rest of the partial symbols from this comp unit.
6170 If not, there's no more debug_info for this comp unit. */
6173 struct partial_die_info
*first_die
;
6174 CORE_ADDR lowpc
, highpc
;
6176 lowpc
= ((CORE_ADDR
) -1);
6177 highpc
= ((CORE_ADDR
) 0);
6179 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6181 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
6182 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
6184 /* If we didn't find a lowpc, set it to highpc to avoid
6185 complaints from `maint check'. */
6186 if (lowpc
== ((CORE_ADDR
) -1))
6189 /* If the compilation unit didn't have an explicit address range,
6190 then use the information extracted from its child dies. */
6191 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
6194 best_highpc
= highpc
;
6197 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
6198 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
6200 end_psymtab_common (objfile
, pst
);
6202 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
6205 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6206 struct dwarf2_per_cu_data
*iter
;
6208 /* Fill in 'dependencies' here; we fill in 'users' in a
6210 pst
->number_of_dependencies
= len
;
6212 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6214 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
6217 pst
->dependencies
[i
] = iter
->v
.psymtab
;
6219 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6222 /* Get the list of files included in the current compilation unit,
6223 and build a psymtab for each of them. */
6224 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
6226 if (dwarf_read_debug
)
6228 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6230 fprintf_unfiltered (gdb_stdlog
,
6231 "Psymtab for %s unit @0x%x: %s - %s"
6232 ", %d global, %d static syms\n",
6233 per_cu
->is_debug_types
? "type" : "comp",
6234 to_underlying (per_cu
->sect_off
),
6235 paddress (gdbarch
, pst
->textlow
),
6236 paddress (gdbarch
, pst
->texthigh
),
6237 pst
->n_global_syms
, pst
->n_static_syms
);
6241 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6242 Process compilation unit THIS_CU for a psymtab. */
6245 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6246 int want_partial_unit
,
6247 enum language pretend_language
)
6249 struct process_psymtab_comp_unit_data info
;
6251 /* If this compilation unit was already read in, free the
6252 cached copy in order to read it in again. This is
6253 necessary because we skipped some symbols when we first
6254 read in the compilation unit (see load_partial_dies).
6255 This problem could be avoided, but the benefit is unclear. */
6256 if (this_cu
->cu
!= NULL
)
6257 free_one_cached_comp_unit (this_cu
);
6259 gdb_assert (! this_cu
->is_debug_types
);
6260 info
.want_partial_unit
= want_partial_unit
;
6261 info
.pretend_language
= pretend_language
;
6262 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
6263 process_psymtab_comp_unit_reader
,
6266 /* Age out any secondary CUs. */
6267 age_cached_comp_units ();
6270 /* Reader function for build_type_psymtabs. */
6273 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
6274 const gdb_byte
*info_ptr
,
6275 struct die_info
*type_unit_die
,
6279 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6280 struct dwarf2_cu
*cu
= reader
->cu
;
6281 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6282 struct signatured_type
*sig_type
;
6283 struct type_unit_group
*tu_group
;
6284 struct attribute
*attr
;
6285 struct partial_die_info
*first_die
;
6286 CORE_ADDR lowpc
, highpc
;
6287 struct partial_symtab
*pst
;
6289 gdb_assert (data
== NULL
);
6290 gdb_assert (per_cu
->is_debug_types
);
6291 sig_type
= (struct signatured_type
*) per_cu
;
6296 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
6297 tu_group
= get_type_unit_group (cu
, attr
);
6299 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
6301 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
6302 cu
->list_in_scope
= &file_symbols
;
6303 pst
= create_partial_symtab (per_cu
, "");
6306 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6308 lowpc
= (CORE_ADDR
) -1;
6309 highpc
= (CORE_ADDR
) 0;
6310 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
6312 end_psymtab_common (objfile
, pst
);
6315 /* Struct used to sort TUs by their abbreviation table offset. */
6317 struct tu_abbrev_offset
6319 struct signatured_type
*sig_type
;
6320 sect_offset abbrev_offset
;
6323 /* Helper routine for build_type_psymtabs_1, passed to qsort. */
6326 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
6328 const struct tu_abbrev_offset
* const *a
6329 = (const struct tu_abbrev_offset
* const*) ap
;
6330 const struct tu_abbrev_offset
* const *b
6331 = (const struct tu_abbrev_offset
* const*) bp
;
6332 sect_offset aoff
= (*a
)->abbrev_offset
;
6333 sect_offset boff
= (*b
)->abbrev_offset
;
6335 return (aoff
> boff
) - (aoff
< boff
);
6338 /* Efficiently read all the type units.
6339 This does the bulk of the work for build_type_psymtabs.
6341 The efficiency is because we sort TUs by the abbrev table they use and
6342 only read each abbrev table once. In one program there are 200K TUs
6343 sharing 8K abbrev tables.
6345 The main purpose of this function is to support building the
6346 dwarf2_per_objfile->type_unit_groups table.
6347 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
6348 can collapse the search space by grouping them by stmt_list.
6349 The savings can be significant, in the same program from above the 200K TUs
6350 share 8K stmt_list tables.
6352 FUNC is expected to call get_type_unit_group, which will create the
6353 struct type_unit_group if necessary and add it to
6354 dwarf2_per_objfile->type_unit_groups. */
6357 build_type_psymtabs_1 (void)
6359 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6360 struct cleanup
*cleanups
;
6361 struct abbrev_table
*abbrev_table
;
6362 sect_offset abbrev_offset
;
6363 struct tu_abbrev_offset
*sorted_by_abbrev
;
6366 /* It's up to the caller to not call us multiple times. */
6367 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
6369 if (dwarf2_per_objfile
->n_type_units
== 0)
6372 /* TUs typically share abbrev tables, and there can be way more TUs than
6373 abbrev tables. Sort by abbrev table to reduce the number of times we
6374 read each abbrev table in.
6375 Alternatives are to punt or to maintain a cache of abbrev tables.
6376 This is simpler and efficient enough for now.
6378 Later we group TUs by their DW_AT_stmt_list value (as this defines the
6379 symtab to use). Typically TUs with the same abbrev offset have the same
6380 stmt_list value too so in practice this should work well.
6382 The basic algorithm here is:
6384 sort TUs by abbrev table
6385 for each TU with same abbrev table:
6386 read abbrev table if first user
6387 read TU top level DIE
6388 [IWBN if DWO skeletons had DW_AT_stmt_list]
6391 if (dwarf_read_debug
)
6392 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
6394 /* Sort in a separate table to maintain the order of all_type_units
6395 for .gdb_index: TU indices directly index all_type_units. */
6396 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
6397 dwarf2_per_objfile
->n_type_units
);
6398 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6400 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
6402 sorted_by_abbrev
[i
].sig_type
= sig_type
;
6403 sorted_by_abbrev
[i
].abbrev_offset
=
6404 read_abbrev_offset (sig_type
->per_cu
.section
,
6405 sig_type
->per_cu
.sect_off
);
6407 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
6408 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
6409 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
6411 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
6412 abbrev_table
= NULL
;
6413 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
6415 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6417 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
6419 /* Switch to the next abbrev table if necessary. */
6420 if (abbrev_table
== NULL
6421 || tu
->abbrev_offset
!= abbrev_offset
)
6423 if (abbrev_table
!= NULL
)
6425 abbrev_table_free (abbrev_table
);
6426 /* Reset to NULL in case abbrev_table_read_table throws
6427 an error: abbrev_table_free_cleanup will get called. */
6428 abbrev_table
= NULL
;
6430 abbrev_offset
= tu
->abbrev_offset
;
6432 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
6434 ++tu_stats
->nr_uniq_abbrev_tables
;
6437 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
6438 build_type_psymtabs_reader
, NULL
);
6441 do_cleanups (cleanups
);
6444 /* Print collected type unit statistics. */
6447 print_tu_stats (void)
6449 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6451 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
6452 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
6453 dwarf2_per_objfile
->n_type_units
);
6454 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
6455 tu_stats
->nr_uniq_abbrev_tables
);
6456 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
6457 tu_stats
->nr_symtabs
);
6458 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
6459 tu_stats
->nr_symtab_sharers
);
6460 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
6461 tu_stats
->nr_stmt_less_type_units
);
6462 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
6463 tu_stats
->nr_all_type_units_reallocs
);
6466 /* Traversal function for build_type_psymtabs. */
6469 build_type_psymtab_dependencies (void **slot
, void *info
)
6471 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6472 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
6473 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
6474 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6475 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
6476 struct signatured_type
*iter
;
6479 gdb_assert (len
> 0);
6480 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
6482 pst
->number_of_dependencies
= len
;
6484 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6486 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
6489 gdb_assert (iter
->per_cu
.is_debug_types
);
6490 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
6491 iter
->type_unit_group
= tu_group
;
6494 VEC_free (sig_type_ptr
, tu_group
->tus
);
6499 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6500 Build partial symbol tables for the .debug_types comp-units. */
6503 build_type_psymtabs (struct objfile
*objfile
)
6505 if (! create_all_type_units (objfile
))
6508 build_type_psymtabs_1 ();
6511 /* Traversal function for process_skeletonless_type_unit.
6512 Read a TU in a DWO file and build partial symbols for it. */
6515 process_skeletonless_type_unit (void **slot
, void *info
)
6517 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
6518 struct objfile
*objfile
= (struct objfile
*) info
;
6519 struct signatured_type find_entry
, *entry
;
6521 /* If this TU doesn't exist in the global table, add it and read it in. */
6523 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6525 dwarf2_per_objfile
->signatured_types
6526 = allocate_signatured_type_table (objfile
);
6529 find_entry
.signature
= dwo_unit
->signature
;
6530 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
6532 /* If we've already seen this type there's nothing to do. What's happening
6533 is we're doing our own version of comdat-folding here. */
6537 /* This does the job that create_all_type_units would have done for
6539 entry
= add_type_unit (dwo_unit
->signature
, slot
);
6540 fill_in_sig_entry_from_dwo_entry (objfile
, entry
, dwo_unit
);
6543 /* This does the job that build_type_psymtabs_1 would have done. */
6544 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
6545 build_type_psymtabs_reader
, NULL
);
6550 /* Traversal function for process_skeletonless_type_units. */
6553 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
6555 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
6557 if (dwo_file
->tus
!= NULL
)
6559 htab_traverse_noresize (dwo_file
->tus
,
6560 process_skeletonless_type_unit
, info
);
6566 /* Scan all TUs of DWO files, verifying we've processed them.
6567 This is needed in case a TU was emitted without its skeleton.
6568 Note: This can't be done until we know what all the DWO files are. */
6571 process_skeletonless_type_units (struct objfile
*objfile
)
6573 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
6574 if (get_dwp_file () == NULL
6575 && dwarf2_per_objfile
->dwo_files
!= NULL
)
6577 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
6578 process_dwo_file_for_skeletonless_type_units
,
6583 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
6586 psymtabs_addrmap_cleanup (void *o
)
6588 struct objfile
*objfile
= (struct objfile
*) o
;
6590 objfile
->psymtabs_addrmap
= NULL
;
6593 /* Compute the 'user' field for each psymtab in OBJFILE. */
6596 set_partial_user (struct objfile
*objfile
)
6600 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6602 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6603 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6609 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
6611 /* Set the 'user' field only if it is not already set. */
6612 if (pst
->dependencies
[j
]->user
== NULL
)
6613 pst
->dependencies
[j
]->user
= pst
;
6618 /* Build the partial symbol table by doing a quick pass through the
6619 .debug_info and .debug_abbrev sections. */
6622 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
6624 struct cleanup
*back_to
, *addrmap_cleanup
;
6627 if (dwarf_read_debug
)
6629 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
6630 objfile_name (objfile
));
6633 dwarf2_per_objfile
->reading_partial_symbols
= 1;
6635 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
6637 /* Any cached compilation units will be linked by the per-objfile
6638 read_in_chain. Make sure to free them when we're done. */
6639 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
6641 build_type_psymtabs (objfile
);
6643 create_all_comp_units (objfile
);
6645 /* Create a temporary address map on a temporary obstack. We later
6646 copy this to the final obstack. */
6647 auto_obstack temp_obstack
;
6648 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
6649 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
6651 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6653 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6655 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
6658 /* This has to wait until we read the CUs, we need the list of DWOs. */
6659 process_skeletonless_type_units (objfile
);
6661 /* Now that all TUs have been processed we can fill in the dependencies. */
6662 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
6664 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
6665 build_type_psymtab_dependencies
, NULL
);
6668 if (dwarf_read_debug
)
6671 set_partial_user (objfile
);
6673 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
6674 &objfile
->objfile_obstack
);
6675 discard_cleanups (addrmap_cleanup
);
6677 do_cleanups (back_to
);
6679 if (dwarf_read_debug
)
6680 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
6681 objfile_name (objfile
));
6684 /* die_reader_func for load_partial_comp_unit. */
6687 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
6688 const gdb_byte
*info_ptr
,
6689 struct die_info
*comp_unit_die
,
6693 struct dwarf2_cu
*cu
= reader
->cu
;
6695 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
6697 /* Check if comp unit has_children.
6698 If so, read the rest of the partial symbols from this comp unit.
6699 If not, there's no more debug_info for this comp unit. */
6701 load_partial_dies (reader
, info_ptr
, 0);
6704 /* Load the partial DIEs for a secondary CU into memory.
6705 This is also used when rereading a primary CU with load_all_dies. */
6708 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
6710 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6711 load_partial_comp_unit_reader
, NULL
);
6715 read_comp_units_from_section (struct objfile
*objfile
,
6716 struct dwarf2_section_info
*section
,
6717 unsigned int is_dwz
,
6720 struct dwarf2_per_cu_data
***all_comp_units
)
6722 const gdb_byte
*info_ptr
;
6723 bfd
*abfd
= get_section_bfd_owner (section
);
6725 if (dwarf_read_debug
)
6726 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
6727 get_section_name (section
),
6728 get_section_file_name (section
));
6730 dwarf2_read_section (objfile
, section
);
6732 info_ptr
= section
->buffer
;
6734 while (info_ptr
< section
->buffer
+ section
->size
)
6736 unsigned int length
, initial_length_size
;
6737 struct dwarf2_per_cu_data
*this_cu
;
6739 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
6741 /* Read just enough information to find out where the next
6742 compilation unit is. */
6743 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6745 /* Save the compilation unit for later lookup. */
6746 this_cu
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
);
6747 memset (this_cu
, 0, sizeof (*this_cu
));
6748 this_cu
->sect_off
= sect_off
;
6749 this_cu
->length
= length
+ initial_length_size
;
6750 this_cu
->is_dwz
= is_dwz
;
6751 this_cu
->objfile
= objfile
;
6752 this_cu
->section
= section
;
6754 if (*n_comp_units
== *n_allocated
)
6757 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
6758 *all_comp_units
, *n_allocated
);
6760 (*all_comp_units
)[*n_comp_units
] = this_cu
;
6763 info_ptr
= info_ptr
+ this_cu
->length
;
6767 /* Create a list of all compilation units in OBJFILE.
6768 This is only done for -readnow and building partial symtabs. */
6771 create_all_comp_units (struct objfile
*objfile
)
6775 struct dwarf2_per_cu_data
**all_comp_units
;
6776 struct dwz_file
*dwz
;
6780 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
6782 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
6783 &n_allocated
, &n_comp_units
, &all_comp_units
);
6785 dwz
= dwarf2_get_dwz_file ();
6787 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
6788 &n_allocated
, &n_comp_units
,
6791 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
6792 struct dwarf2_per_cu_data
*,
6794 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
6795 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
6796 xfree (all_comp_units
);
6797 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
6800 /* Process all loaded DIEs for compilation unit CU, starting at
6801 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
6802 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
6803 DW_AT_ranges). See the comments of add_partial_subprogram on how
6804 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
6807 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
6808 CORE_ADDR
*highpc
, int set_addrmap
,
6809 struct dwarf2_cu
*cu
)
6811 struct partial_die_info
*pdi
;
6813 /* Now, march along the PDI's, descending into ones which have
6814 interesting children but skipping the children of the other ones,
6815 until we reach the end of the compilation unit. */
6821 fixup_partial_die (pdi
, cu
);
6823 /* Anonymous namespaces or modules have no name but have interesting
6824 children, so we need to look at them. Ditto for anonymous
6827 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
6828 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
6829 || pdi
->tag
== DW_TAG_imported_unit
)
6833 case DW_TAG_subprogram
:
6834 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6836 case DW_TAG_constant
:
6837 case DW_TAG_variable
:
6838 case DW_TAG_typedef
:
6839 case DW_TAG_union_type
:
6840 if (!pdi
->is_declaration
)
6842 add_partial_symbol (pdi
, cu
);
6845 case DW_TAG_class_type
:
6846 case DW_TAG_interface_type
:
6847 case DW_TAG_structure_type
:
6848 if (!pdi
->is_declaration
)
6850 add_partial_symbol (pdi
, cu
);
6852 if (cu
->language
== language_rust
&& pdi
->has_children
)
6853 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
6856 case DW_TAG_enumeration_type
:
6857 if (!pdi
->is_declaration
)
6858 add_partial_enumeration (pdi
, cu
);
6860 case DW_TAG_base_type
:
6861 case DW_TAG_subrange_type
:
6862 /* File scope base type definitions are added to the partial
6864 add_partial_symbol (pdi
, cu
);
6866 case DW_TAG_namespace
:
6867 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6870 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6872 case DW_TAG_imported_unit
:
6874 struct dwarf2_per_cu_data
*per_cu
;
6876 /* For now we don't handle imported units in type units. */
6877 if (cu
->per_cu
->is_debug_types
)
6879 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6880 " supported in type units [in module %s]"),
6881 objfile_name (cu
->objfile
));
6884 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.sect_off
,
6888 /* Go read the partial unit, if needed. */
6889 if (per_cu
->v
.psymtab
== NULL
)
6890 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
6892 VEC_safe_push (dwarf2_per_cu_ptr
,
6893 cu
->per_cu
->imported_symtabs
, per_cu
);
6896 case DW_TAG_imported_declaration
:
6897 add_partial_symbol (pdi
, cu
);
6904 /* If the die has a sibling, skip to the sibling. */
6906 pdi
= pdi
->die_sibling
;
6910 /* Functions used to compute the fully scoped name of a partial DIE.
6912 Normally, this is simple. For C++, the parent DIE's fully scoped
6913 name is concatenated with "::" and the partial DIE's name.
6914 Enumerators are an exception; they use the scope of their parent
6915 enumeration type, i.e. the name of the enumeration type is not
6916 prepended to the enumerator.
6918 There are two complexities. One is DW_AT_specification; in this
6919 case "parent" means the parent of the target of the specification,
6920 instead of the direct parent of the DIE. The other is compilers
6921 which do not emit DW_TAG_namespace; in this case we try to guess
6922 the fully qualified name of structure types from their members'
6923 linkage names. This must be done using the DIE's children rather
6924 than the children of any DW_AT_specification target. We only need
6925 to do this for structures at the top level, i.e. if the target of
6926 any DW_AT_specification (if any; otherwise the DIE itself) does not
6929 /* Compute the scope prefix associated with PDI's parent, in
6930 compilation unit CU. The result will be allocated on CU's
6931 comp_unit_obstack, or a copy of the already allocated PDI->NAME
6932 field. NULL is returned if no prefix is necessary. */
6934 partial_die_parent_scope (struct partial_die_info
*pdi
,
6935 struct dwarf2_cu
*cu
)
6937 const char *grandparent_scope
;
6938 struct partial_die_info
*parent
, *real_pdi
;
6940 /* We need to look at our parent DIE; if we have a DW_AT_specification,
6941 then this means the parent of the specification DIE. */
6944 while (real_pdi
->has_specification
)
6945 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
6946 real_pdi
->spec_is_dwz
, cu
);
6948 parent
= real_pdi
->die_parent
;
6952 if (parent
->scope_set
)
6953 return parent
->scope
;
6955 fixup_partial_die (parent
, cu
);
6957 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
6959 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
6960 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
6961 Work around this problem here. */
6962 if (cu
->language
== language_cplus
6963 && parent
->tag
== DW_TAG_namespace
6964 && strcmp (parent
->name
, "::") == 0
6965 && grandparent_scope
== NULL
)
6967 parent
->scope
= NULL
;
6968 parent
->scope_set
= 1;
6972 if (pdi
->tag
== DW_TAG_enumerator
)
6973 /* Enumerators should not get the name of the enumeration as a prefix. */
6974 parent
->scope
= grandparent_scope
;
6975 else if (parent
->tag
== DW_TAG_namespace
6976 || parent
->tag
== DW_TAG_module
6977 || parent
->tag
== DW_TAG_structure_type
6978 || parent
->tag
== DW_TAG_class_type
6979 || parent
->tag
== DW_TAG_interface_type
6980 || parent
->tag
== DW_TAG_union_type
6981 || parent
->tag
== DW_TAG_enumeration_type
)
6983 if (grandparent_scope
== NULL
)
6984 parent
->scope
= parent
->name
;
6986 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
6988 parent
->name
, 0, cu
);
6992 /* FIXME drow/2004-04-01: What should we be doing with
6993 function-local names? For partial symbols, we should probably be
6995 complaint (&symfile_complaints
,
6996 _("unhandled containing DIE tag %d for DIE at %d"),
6997 parent
->tag
, to_underlying (pdi
->sect_off
));
6998 parent
->scope
= grandparent_scope
;
7001 parent
->scope_set
= 1;
7002 return parent
->scope
;
7005 /* Return the fully scoped name associated with PDI, from compilation unit
7006 CU. The result will be allocated with malloc. */
7009 partial_die_full_name (struct partial_die_info
*pdi
,
7010 struct dwarf2_cu
*cu
)
7012 const char *parent_scope
;
7014 /* If this is a template instantiation, we can not work out the
7015 template arguments from partial DIEs. So, unfortunately, we have
7016 to go through the full DIEs. At least any work we do building
7017 types here will be reused if full symbols are loaded later. */
7018 if (pdi
->has_template_arguments
)
7020 fixup_partial_die (pdi
, cu
);
7022 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
7024 struct die_info
*die
;
7025 struct attribute attr
;
7026 struct dwarf2_cu
*ref_cu
= cu
;
7028 /* DW_FORM_ref_addr is using section offset. */
7029 attr
.name
= (enum dwarf_attribute
) 0;
7030 attr
.form
= DW_FORM_ref_addr
;
7031 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7032 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7034 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7038 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7039 if (parent_scope
== NULL
)
7042 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
7046 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7048 struct objfile
*objfile
= cu
->objfile
;
7049 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7051 const char *actual_name
= NULL
;
7053 char *built_actual_name
;
7055 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7057 built_actual_name
= partial_die_full_name (pdi
, cu
);
7058 if (built_actual_name
!= NULL
)
7059 actual_name
= built_actual_name
;
7061 if (actual_name
== NULL
)
7062 actual_name
= pdi
->name
;
7066 case DW_TAG_subprogram
:
7067 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
7068 if (pdi
->is_external
|| cu
->language
== language_ada
)
7070 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
7071 of the global scope. But in Ada, we want to be able to access
7072 nested procedures globally. So all Ada subprograms are stored
7073 in the global scope. */
7074 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7075 built_actual_name
!= NULL
,
7076 VAR_DOMAIN
, LOC_BLOCK
,
7077 &objfile
->global_psymbols
,
7078 addr
, cu
->language
, objfile
);
7082 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7083 built_actual_name
!= NULL
,
7084 VAR_DOMAIN
, LOC_BLOCK
,
7085 &objfile
->static_psymbols
,
7086 addr
, cu
->language
, objfile
);
7089 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7090 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
7092 case DW_TAG_constant
:
7094 struct psymbol_allocation_list
*list
;
7096 if (pdi
->is_external
)
7097 list
= &objfile
->global_psymbols
;
7099 list
= &objfile
->static_psymbols
;
7100 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7101 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
7102 list
, 0, cu
->language
, objfile
);
7105 case DW_TAG_variable
:
7107 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7111 && !dwarf2_per_objfile
->has_section_at_zero
)
7113 /* A global or static variable may also have been stripped
7114 out by the linker if unused, in which case its address
7115 will be nullified; do not add such variables into partial
7116 symbol table then. */
7118 else if (pdi
->is_external
)
7121 Don't enter into the minimal symbol tables as there is
7122 a minimal symbol table entry from the ELF symbols already.
7123 Enter into partial symbol table if it has a location
7124 descriptor or a type.
7125 If the location descriptor is missing, new_symbol will create
7126 a LOC_UNRESOLVED symbol, the address of the variable will then
7127 be determined from the minimal symbol table whenever the variable
7129 The address for the partial symbol table entry is not
7130 used by GDB, but it comes in handy for debugging partial symbol
7133 if (pdi
->d
.locdesc
|| pdi
->has_type
)
7134 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7135 built_actual_name
!= NULL
,
7136 VAR_DOMAIN
, LOC_STATIC
,
7137 &objfile
->global_psymbols
,
7139 cu
->language
, objfile
);
7143 int has_loc
= pdi
->d
.locdesc
!= NULL
;
7145 /* Static Variable. Skip symbols whose value we cannot know (those
7146 without location descriptors or constant values). */
7147 if (!has_loc
&& !pdi
->has_const_value
)
7149 xfree (built_actual_name
);
7153 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7154 built_actual_name
!= NULL
,
7155 VAR_DOMAIN
, LOC_STATIC
,
7156 &objfile
->static_psymbols
,
7157 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
7158 cu
->language
, objfile
);
7161 case DW_TAG_typedef
:
7162 case DW_TAG_base_type
:
7163 case DW_TAG_subrange_type
:
7164 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7165 built_actual_name
!= NULL
,
7166 VAR_DOMAIN
, LOC_TYPEDEF
,
7167 &objfile
->static_psymbols
,
7168 0, cu
->language
, objfile
);
7170 case DW_TAG_imported_declaration
:
7171 case DW_TAG_namespace
:
7172 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7173 built_actual_name
!= NULL
,
7174 VAR_DOMAIN
, LOC_TYPEDEF
,
7175 &objfile
->global_psymbols
,
7176 0, cu
->language
, objfile
);
7179 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7180 built_actual_name
!= NULL
,
7181 MODULE_DOMAIN
, LOC_TYPEDEF
,
7182 &objfile
->global_psymbols
,
7183 0, cu
->language
, objfile
);
7185 case DW_TAG_class_type
:
7186 case DW_TAG_interface_type
:
7187 case DW_TAG_structure_type
:
7188 case DW_TAG_union_type
:
7189 case DW_TAG_enumeration_type
:
7190 /* Skip external references. The DWARF standard says in the section
7191 about "Structure, Union, and Class Type Entries": "An incomplete
7192 structure, union or class type is represented by a structure,
7193 union or class entry that does not have a byte size attribute
7194 and that has a DW_AT_declaration attribute." */
7195 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
7197 xfree (built_actual_name
);
7201 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
7202 static vs. global. */
7203 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7204 built_actual_name
!= NULL
,
7205 STRUCT_DOMAIN
, LOC_TYPEDEF
,
7206 cu
->language
== language_cplus
7207 ? &objfile
->global_psymbols
7208 : &objfile
->static_psymbols
,
7209 0, cu
->language
, objfile
);
7212 case DW_TAG_enumerator
:
7213 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7214 built_actual_name
!= NULL
,
7215 VAR_DOMAIN
, LOC_CONST
,
7216 cu
->language
== language_cplus
7217 ? &objfile
->global_psymbols
7218 : &objfile
->static_psymbols
,
7219 0, cu
->language
, objfile
);
7225 xfree (built_actual_name
);
7228 /* Read a partial die corresponding to a namespace; also, add a symbol
7229 corresponding to that namespace to the symbol table. NAMESPACE is
7230 the name of the enclosing namespace. */
7233 add_partial_namespace (struct partial_die_info
*pdi
,
7234 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7235 int set_addrmap
, struct dwarf2_cu
*cu
)
7237 /* Add a symbol for the namespace. */
7239 add_partial_symbol (pdi
, cu
);
7241 /* Now scan partial symbols in that namespace. */
7243 if (pdi
->has_children
)
7244 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7247 /* Read a partial die corresponding to a Fortran module. */
7250 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
7251 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
7253 /* Add a symbol for the namespace. */
7255 add_partial_symbol (pdi
, cu
);
7257 /* Now scan partial symbols in that module. */
7259 if (pdi
->has_children
)
7260 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7263 /* Read a partial die corresponding to a subprogram and create a partial
7264 symbol for that subprogram. When the CU language allows it, this
7265 routine also defines a partial symbol for each nested subprogram
7266 that this subprogram contains. If SET_ADDRMAP is true, record the
7267 covered ranges in the addrmap. Set *LOWPC and *HIGHPC to the lowest
7268 and highest PC values found in PDI.
7270 PDI may also be a lexical block, in which case we simply search
7271 recursively for subprograms defined inside that lexical block.
7272 Again, this is only performed when the CU language allows this
7273 type of definitions. */
7276 add_partial_subprogram (struct partial_die_info
*pdi
,
7277 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7278 int set_addrmap
, struct dwarf2_cu
*cu
)
7280 if (pdi
->tag
== DW_TAG_subprogram
)
7282 if (pdi
->has_pc_info
)
7284 if (pdi
->lowpc
< *lowpc
)
7285 *lowpc
= pdi
->lowpc
;
7286 if (pdi
->highpc
> *highpc
)
7287 *highpc
= pdi
->highpc
;
7290 struct objfile
*objfile
= cu
->objfile
;
7291 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7296 baseaddr
= ANOFFSET (objfile
->section_offsets
,
7297 SECT_OFF_TEXT (objfile
));
7298 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7299 pdi
->lowpc
+ baseaddr
);
7300 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7301 pdi
->highpc
+ baseaddr
);
7302 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
7303 cu
->per_cu
->v
.psymtab
);
7307 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
7309 if (!pdi
->is_declaration
)
7310 /* Ignore subprogram DIEs that do not have a name, they are
7311 illegal. Do not emit a complaint at this point, we will
7312 do so when we convert this psymtab into a symtab. */
7314 add_partial_symbol (pdi
, cu
);
7318 if (! pdi
->has_children
)
7321 if (cu
->language
== language_ada
)
7323 pdi
= pdi
->die_child
;
7326 fixup_partial_die (pdi
, cu
);
7327 if (pdi
->tag
== DW_TAG_subprogram
7328 || pdi
->tag
== DW_TAG_lexical_block
)
7329 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7330 pdi
= pdi
->die_sibling
;
7335 /* Read a partial die corresponding to an enumeration type. */
7338 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
7339 struct dwarf2_cu
*cu
)
7341 struct partial_die_info
*pdi
;
7343 if (enum_pdi
->name
!= NULL
)
7344 add_partial_symbol (enum_pdi
, cu
);
7346 pdi
= enum_pdi
->die_child
;
7349 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
7350 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
7352 add_partial_symbol (pdi
, cu
);
7353 pdi
= pdi
->die_sibling
;
7357 /* Return the initial uleb128 in the die at INFO_PTR. */
7360 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
7362 unsigned int bytes_read
;
7364 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7367 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
7368 Return the corresponding abbrev, or NULL if the number is zero (indicating
7369 an empty DIE). In either case *BYTES_READ will be set to the length of
7370 the initial number. */
7372 static struct abbrev_info
*
7373 peek_die_abbrev (const gdb_byte
*info_ptr
, unsigned int *bytes_read
,
7374 struct dwarf2_cu
*cu
)
7376 bfd
*abfd
= cu
->objfile
->obfd
;
7377 unsigned int abbrev_number
;
7378 struct abbrev_info
*abbrev
;
7380 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
7382 if (abbrev_number
== 0)
7385 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
7388 error (_("Dwarf Error: Could not find abbrev number %d in %s"
7389 " at offset 0x%x [in module %s]"),
7390 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
7391 to_underlying (cu
->header
.sect_off
), bfd_get_filename (abfd
));
7397 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7398 Returns a pointer to the end of a series of DIEs, terminated by an empty
7399 DIE. Any children of the skipped DIEs will also be skipped. */
7401 static const gdb_byte
*
7402 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
7404 struct dwarf2_cu
*cu
= reader
->cu
;
7405 struct abbrev_info
*abbrev
;
7406 unsigned int bytes_read
;
7410 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
7412 return info_ptr
+ bytes_read
;
7414 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
7418 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7419 INFO_PTR should point just after the initial uleb128 of a DIE, and the
7420 abbrev corresponding to that skipped uleb128 should be passed in
7421 ABBREV. Returns a pointer to this DIE's sibling, skipping any
7424 static const gdb_byte
*
7425 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
7426 struct abbrev_info
*abbrev
)
7428 unsigned int bytes_read
;
7429 struct attribute attr
;
7430 bfd
*abfd
= reader
->abfd
;
7431 struct dwarf2_cu
*cu
= reader
->cu
;
7432 const gdb_byte
*buffer
= reader
->buffer
;
7433 const gdb_byte
*buffer_end
= reader
->buffer_end
;
7434 unsigned int form
, i
;
7436 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
7438 /* The only abbrev we care about is DW_AT_sibling. */
7439 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
7441 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
7442 if (attr
.form
== DW_FORM_ref_addr
)
7443 complaint (&symfile_complaints
,
7444 _("ignoring absolute DW_AT_sibling"));
7447 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
7448 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
7450 if (sibling_ptr
< info_ptr
)
7451 complaint (&symfile_complaints
,
7452 _("DW_AT_sibling points backwards"));
7453 else if (sibling_ptr
> reader
->buffer_end
)
7454 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
7460 /* If it isn't DW_AT_sibling, skip this attribute. */
7461 form
= abbrev
->attrs
[i
].form
;
7465 case DW_FORM_ref_addr
:
7466 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
7467 and later it is offset sized. */
7468 if (cu
->header
.version
== 2)
7469 info_ptr
+= cu
->header
.addr_size
;
7471 info_ptr
+= cu
->header
.offset_size
;
7473 case DW_FORM_GNU_ref_alt
:
7474 info_ptr
+= cu
->header
.offset_size
;
7477 info_ptr
+= cu
->header
.addr_size
;
7484 case DW_FORM_flag_present
:
7485 case DW_FORM_implicit_const
:
7497 case DW_FORM_ref_sig8
:
7500 case DW_FORM_data16
:
7503 case DW_FORM_string
:
7504 read_direct_string (abfd
, info_ptr
, &bytes_read
);
7505 info_ptr
+= bytes_read
;
7507 case DW_FORM_sec_offset
:
7509 case DW_FORM_GNU_strp_alt
:
7510 info_ptr
+= cu
->header
.offset_size
;
7512 case DW_FORM_exprloc
:
7514 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7515 info_ptr
+= bytes_read
;
7517 case DW_FORM_block1
:
7518 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
7520 case DW_FORM_block2
:
7521 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
7523 case DW_FORM_block4
:
7524 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
7528 case DW_FORM_ref_udata
:
7529 case DW_FORM_GNU_addr_index
:
7530 case DW_FORM_GNU_str_index
:
7531 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
7533 case DW_FORM_indirect
:
7534 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7535 info_ptr
+= bytes_read
;
7536 /* We need to continue parsing from here, so just go back to
7538 goto skip_attribute
;
7541 error (_("Dwarf Error: Cannot handle %s "
7542 "in DWARF reader [in module %s]"),
7543 dwarf_form_name (form
),
7544 bfd_get_filename (abfd
));
7548 if (abbrev
->has_children
)
7549 return skip_children (reader
, info_ptr
);
7554 /* Locate ORIG_PDI's sibling.
7555 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
7557 static const gdb_byte
*
7558 locate_pdi_sibling (const struct die_reader_specs
*reader
,
7559 struct partial_die_info
*orig_pdi
,
7560 const gdb_byte
*info_ptr
)
7562 /* Do we know the sibling already? */
7564 if (orig_pdi
->sibling
)
7565 return orig_pdi
->sibling
;
7567 /* Are there any children to deal with? */
7569 if (!orig_pdi
->has_children
)
7572 /* Skip the children the long way. */
7574 return skip_children (reader
, info_ptr
);
7577 /* Expand this partial symbol table into a full symbol table. SELF is
7581 dwarf2_read_symtab (struct partial_symtab
*self
,
7582 struct objfile
*objfile
)
7586 warning (_("bug: psymtab for %s is already read in."),
7593 printf_filtered (_("Reading in symbols for %s..."),
7595 gdb_flush (gdb_stdout
);
7598 /* Restore our global data. */
7600 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
7601 dwarf2_objfile_data_key
);
7603 /* If this psymtab is constructed from a debug-only objfile, the
7604 has_section_at_zero flag will not necessarily be correct. We
7605 can get the correct value for this flag by looking at the data
7606 associated with the (presumably stripped) associated objfile. */
7607 if (objfile
->separate_debug_objfile_backlink
)
7609 struct dwarf2_per_objfile
*dpo_backlink
7610 = ((struct dwarf2_per_objfile
*)
7611 objfile_data (objfile
->separate_debug_objfile_backlink
,
7612 dwarf2_objfile_data_key
));
7614 dwarf2_per_objfile
->has_section_at_zero
7615 = dpo_backlink
->has_section_at_zero
;
7618 dwarf2_per_objfile
->reading_partial_symbols
= 0;
7620 psymtab_to_symtab_1 (self
);
7622 /* Finish up the debug error message. */
7624 printf_filtered (_("done.\n"));
7627 process_cu_includes ();
7630 /* Reading in full CUs. */
7632 /* Add PER_CU to the queue. */
7635 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
7636 enum language pretend_language
)
7638 struct dwarf2_queue_item
*item
;
7641 item
= XNEW (struct dwarf2_queue_item
);
7642 item
->per_cu
= per_cu
;
7643 item
->pretend_language
= pretend_language
;
7646 if (dwarf2_queue
== NULL
)
7647 dwarf2_queue
= item
;
7649 dwarf2_queue_tail
->next
= item
;
7651 dwarf2_queue_tail
= item
;
7654 /* If PER_CU is not yet queued, add it to the queue.
7655 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
7657 The result is non-zero if PER_CU was queued, otherwise the result is zero
7658 meaning either PER_CU is already queued or it is already loaded.
7660 N.B. There is an invariant here that if a CU is queued then it is loaded.
7661 The caller is required to load PER_CU if we return non-zero. */
7664 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
7665 struct dwarf2_per_cu_data
*per_cu
,
7666 enum language pretend_language
)
7668 /* We may arrive here during partial symbol reading, if we need full
7669 DIEs to process an unusual case (e.g. template arguments). Do
7670 not queue PER_CU, just tell our caller to load its DIEs. */
7671 if (dwarf2_per_objfile
->reading_partial_symbols
)
7673 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
7678 /* Mark the dependence relation so that we don't flush PER_CU
7680 if (dependent_cu
!= NULL
)
7681 dwarf2_add_dependence (dependent_cu
, per_cu
);
7683 /* If it's already on the queue, we have nothing to do. */
7687 /* If the compilation unit is already loaded, just mark it as
7689 if (per_cu
->cu
!= NULL
)
7691 per_cu
->cu
->last_used
= 0;
7695 /* Add it to the queue. */
7696 queue_comp_unit (per_cu
, pretend_language
);
7701 /* Process the queue. */
7704 process_queue (void)
7706 struct dwarf2_queue_item
*item
, *next_item
;
7708 if (dwarf_read_debug
)
7710 fprintf_unfiltered (gdb_stdlog
,
7711 "Expanding one or more symtabs of objfile %s ...\n",
7712 objfile_name (dwarf2_per_objfile
->objfile
));
7715 /* The queue starts out with one item, but following a DIE reference
7716 may load a new CU, adding it to the end of the queue. */
7717 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
7719 if ((dwarf2_per_objfile
->using_index
7720 ? !item
->per_cu
->v
.quick
->compunit_symtab
7721 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
7722 /* Skip dummy CUs. */
7723 && item
->per_cu
->cu
!= NULL
)
7725 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
7726 unsigned int debug_print_threshold
;
7729 if (per_cu
->is_debug_types
)
7731 struct signatured_type
*sig_type
=
7732 (struct signatured_type
*) per_cu
;
7734 sprintf (buf
, "TU %s at offset 0x%x",
7735 hex_string (sig_type
->signature
),
7736 to_underlying (per_cu
->sect_off
));
7737 /* There can be 100s of TUs.
7738 Only print them in verbose mode. */
7739 debug_print_threshold
= 2;
7743 sprintf (buf
, "CU at offset 0x%x",
7744 to_underlying (per_cu
->sect_off
));
7745 debug_print_threshold
= 1;
7748 if (dwarf_read_debug
>= debug_print_threshold
)
7749 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
7751 if (per_cu
->is_debug_types
)
7752 process_full_type_unit (per_cu
, item
->pretend_language
);
7754 process_full_comp_unit (per_cu
, item
->pretend_language
);
7756 if (dwarf_read_debug
>= debug_print_threshold
)
7757 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
7760 item
->per_cu
->queued
= 0;
7761 next_item
= item
->next
;
7765 dwarf2_queue_tail
= NULL
;
7767 if (dwarf_read_debug
)
7769 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
7770 objfile_name (dwarf2_per_objfile
->objfile
));
7774 /* Free all allocated queue entries. This function only releases anything if
7775 an error was thrown; if the queue was processed then it would have been
7776 freed as we went along. */
7779 dwarf2_release_queue (void *dummy
)
7781 struct dwarf2_queue_item
*item
, *last
;
7783 item
= dwarf2_queue
;
7786 /* Anything still marked queued is likely to be in an
7787 inconsistent state, so discard it. */
7788 if (item
->per_cu
->queued
)
7790 if (item
->per_cu
->cu
!= NULL
)
7791 free_one_cached_comp_unit (item
->per_cu
);
7792 item
->per_cu
->queued
= 0;
7800 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
7803 /* Read in full symbols for PST, and anything it depends on. */
7806 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
7808 struct dwarf2_per_cu_data
*per_cu
;
7814 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
7815 if (!pst
->dependencies
[i
]->readin
7816 && pst
->dependencies
[i
]->user
== NULL
)
7818 /* Inform about additional files that need to be read in. */
7821 /* FIXME: i18n: Need to make this a single string. */
7822 fputs_filtered (" ", gdb_stdout
);
7824 fputs_filtered ("and ", gdb_stdout
);
7826 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
7827 wrap_here (""); /* Flush output. */
7828 gdb_flush (gdb_stdout
);
7830 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
7833 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
7837 /* It's an include file, no symbols to read for it.
7838 Everything is in the parent symtab. */
7843 dw2_do_instantiate_symtab (per_cu
);
7846 /* Trivial hash function for die_info: the hash value of a DIE
7847 is its offset in .debug_info for this objfile. */
7850 die_hash (const void *item
)
7852 const struct die_info
*die
= (const struct die_info
*) item
;
7854 return to_underlying (die
->sect_off
);
7857 /* Trivial comparison function for die_info structures: two DIEs
7858 are equal if they have the same offset. */
7861 die_eq (const void *item_lhs
, const void *item_rhs
)
7863 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
7864 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
7866 return die_lhs
->sect_off
== die_rhs
->sect_off
;
7869 /* die_reader_func for load_full_comp_unit.
7870 This is identical to read_signatured_type_reader,
7871 but is kept separate for now. */
7874 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
7875 const gdb_byte
*info_ptr
,
7876 struct die_info
*comp_unit_die
,
7880 struct dwarf2_cu
*cu
= reader
->cu
;
7881 enum language
*language_ptr
= (enum language
*) data
;
7883 gdb_assert (cu
->die_hash
== NULL
);
7885 htab_create_alloc_ex (cu
->header
.length
/ 12,
7889 &cu
->comp_unit_obstack
,
7890 hashtab_obstack_allocate
,
7891 dummy_obstack_deallocate
);
7894 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
7895 &info_ptr
, comp_unit_die
);
7896 cu
->dies
= comp_unit_die
;
7897 /* comp_unit_die is not stored in die_hash, no need. */
7899 /* We try not to read any attributes in this function, because not
7900 all CUs needed for references have been loaded yet, and symbol
7901 table processing isn't initialized. But we have to set the CU language,
7902 or we won't be able to build types correctly.
7903 Similarly, if we do not read the producer, we can not apply
7904 producer-specific interpretation. */
7905 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
7908 /* Load the DIEs associated with PER_CU into memory. */
7911 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7912 enum language pretend_language
)
7914 gdb_assert (! this_cu
->is_debug_types
);
7916 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
7917 load_full_comp_unit_reader
, &pretend_language
);
7920 /* Add a DIE to the delayed physname list. */
7923 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
7924 const char *name
, struct die_info
*die
,
7925 struct dwarf2_cu
*cu
)
7927 struct delayed_method_info mi
;
7929 mi
.fnfield_index
= fnfield_index
;
7933 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
7936 /* A cleanup for freeing the delayed method list. */
7939 free_delayed_list (void *ptr
)
7941 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
7942 if (cu
->method_list
!= NULL
)
7944 VEC_free (delayed_method_info
, cu
->method_list
);
7945 cu
->method_list
= NULL
;
7949 /* Compute the physnames of any methods on the CU's method list.
7951 The computation of method physnames is delayed in order to avoid the
7952 (bad) condition that one of the method's formal parameters is of an as yet
7956 compute_delayed_physnames (struct dwarf2_cu
*cu
)
7959 struct delayed_method_info
*mi
;
7960 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
7962 const char *physname
;
7963 struct fn_fieldlist
*fn_flp
7964 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
7965 physname
= dwarf2_physname (mi
->name
, mi
->die
, cu
);
7966 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
->index
)
7967 = physname
? physname
: "";
7971 /* Go objects should be embedded in a DW_TAG_module DIE,
7972 and it's not clear if/how imported objects will appear.
7973 To keep Go support simple until that's worked out,
7974 go back through what we've read and create something usable.
7975 We could do this while processing each DIE, and feels kinda cleaner,
7976 but that way is more invasive.
7977 This is to, for example, allow the user to type "p var" or "b main"
7978 without having to specify the package name, and allow lookups
7979 of module.object to work in contexts that use the expression
7983 fixup_go_packaging (struct dwarf2_cu
*cu
)
7985 char *package_name
= NULL
;
7986 struct pending
*list
;
7989 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
7991 for (i
= 0; i
< list
->nsyms
; ++i
)
7993 struct symbol
*sym
= list
->symbol
[i
];
7995 if (SYMBOL_LANGUAGE (sym
) == language_go
7996 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
7998 char *this_package_name
= go_symbol_package_name (sym
);
8000 if (this_package_name
== NULL
)
8002 if (package_name
== NULL
)
8003 package_name
= this_package_name
;
8006 if (strcmp (package_name
, this_package_name
) != 0)
8007 complaint (&symfile_complaints
,
8008 _("Symtab %s has objects from two different Go packages: %s and %s"),
8009 (symbol_symtab (sym
) != NULL
8010 ? symtab_to_filename_for_display
8011 (symbol_symtab (sym
))
8012 : objfile_name (cu
->objfile
)),
8013 this_package_name
, package_name
);
8014 xfree (this_package_name
);
8020 if (package_name
!= NULL
)
8022 struct objfile
*objfile
= cu
->objfile
;
8023 const char *saved_package_name
8024 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8026 strlen (package_name
));
8027 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8028 saved_package_name
);
8031 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8033 sym
= allocate_symbol (objfile
);
8034 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
8035 SYMBOL_SET_NAMES (sym
, saved_package_name
,
8036 strlen (saved_package_name
), 0, objfile
);
8037 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8038 e.g., "main" finds the "main" module and not C's main(). */
8039 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8040 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
8041 SYMBOL_TYPE (sym
) = type
;
8043 add_symbol_to_list (sym
, &global_symbols
);
8045 xfree (package_name
);
8049 /* Return the symtab for PER_CU. This works properly regardless of
8050 whether we're using the index or psymtabs. */
8052 static struct compunit_symtab
*
8053 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
8055 return (dwarf2_per_objfile
->using_index
8056 ? per_cu
->v
.quick
->compunit_symtab
8057 : per_cu
->v
.psymtab
->compunit_symtab
);
8060 /* A helper function for computing the list of all symbol tables
8061 included by PER_CU. */
8064 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
8065 htab_t all_children
, htab_t all_type_symtabs
,
8066 struct dwarf2_per_cu_data
*per_cu
,
8067 struct compunit_symtab
*immediate_parent
)
8071 struct compunit_symtab
*cust
;
8072 struct dwarf2_per_cu_data
*iter
;
8074 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
8077 /* This inclusion and its children have been processed. */
8082 /* Only add a CU if it has a symbol table. */
8083 cust
= get_compunit_symtab (per_cu
);
8086 /* If this is a type unit only add its symbol table if we haven't
8087 seen it yet (type unit per_cu's can share symtabs). */
8088 if (per_cu
->is_debug_types
)
8090 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
8094 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
8095 if (cust
->user
== NULL
)
8096 cust
->user
= immediate_parent
;
8101 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
8102 if (cust
->user
== NULL
)
8103 cust
->user
= immediate_parent
;
8108 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
8111 recursively_compute_inclusions (result
, all_children
,
8112 all_type_symtabs
, iter
, cust
);
8116 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
8120 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
8122 gdb_assert (! per_cu
->is_debug_types
);
8124 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
8127 struct dwarf2_per_cu_data
*per_cu_iter
;
8128 struct compunit_symtab
*compunit_symtab_iter
;
8129 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
8130 htab_t all_children
, all_type_symtabs
;
8131 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
8133 /* If we don't have a symtab, we can just skip this case. */
8137 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
8138 NULL
, xcalloc
, xfree
);
8139 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
8140 NULL
, xcalloc
, xfree
);
8143 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
8147 recursively_compute_inclusions (&result_symtabs
, all_children
,
8148 all_type_symtabs
, per_cu_iter
,
8152 /* Now we have a transitive closure of all the included symtabs. */
8153 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
8155 = XOBNEWVEC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
8156 struct compunit_symtab
*, len
+ 1);
8158 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
8159 compunit_symtab_iter
);
8161 cust
->includes
[ix
] = compunit_symtab_iter
;
8162 cust
->includes
[len
] = NULL
;
8164 VEC_free (compunit_symtab_ptr
, result_symtabs
);
8165 htab_delete (all_children
);
8166 htab_delete (all_type_symtabs
);
8170 /* Compute the 'includes' field for the symtabs of all the CUs we just
8174 process_cu_includes (void)
8177 struct dwarf2_per_cu_data
*iter
;
8180 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
8184 if (! iter
->is_debug_types
)
8185 compute_compunit_symtab_includes (iter
);
8188 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
8191 /* Generate full symbol information for PER_CU, whose DIEs have
8192 already been loaded into memory. */
8195 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8196 enum language pretend_language
)
8198 struct dwarf2_cu
*cu
= per_cu
->cu
;
8199 struct objfile
*objfile
= per_cu
->objfile
;
8200 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8201 CORE_ADDR lowpc
, highpc
;
8202 struct compunit_symtab
*cust
;
8203 struct cleanup
*back_to
, *delayed_list_cleanup
;
8205 struct block
*static_block
;
8208 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8211 back_to
= make_cleanup (really_free_pendings
, NULL
);
8212 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8214 cu
->list_in_scope
= &file_symbols
;
8216 cu
->language
= pretend_language
;
8217 cu
->language_defn
= language_def (cu
->language
);
8219 /* Do line number decoding in read_file_scope () */
8220 process_die (cu
->dies
, cu
);
8222 /* For now fudge the Go package. */
8223 if (cu
->language
== language_go
)
8224 fixup_go_packaging (cu
);
8226 /* Now that we have processed all the DIEs in the CU, all the types
8227 should be complete, and it should now be safe to compute all of the
8229 compute_delayed_physnames (cu
);
8230 do_cleanups (delayed_list_cleanup
);
8232 /* Some compilers don't define a DW_AT_high_pc attribute for the
8233 compilation unit. If the DW_AT_high_pc is missing, synthesize
8234 it, by scanning the DIE's below the compilation unit. */
8235 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
8237 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
8238 static_block
= end_symtab_get_static_block (addr
, 0, 1);
8240 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
8241 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
8242 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
8243 addrmap to help ensure it has an accurate map of pc values belonging to
8245 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
8247 cust
= end_symtab_from_static_block (static_block
,
8248 SECT_OFF_TEXT (objfile
), 0);
8252 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
8254 /* Set symtab language to language from DW_AT_language. If the
8255 compilation is from a C file generated by language preprocessors, do
8256 not set the language if it was already deduced by start_subfile. */
8257 if (!(cu
->language
== language_c
8258 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
8259 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8261 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
8262 produce DW_AT_location with location lists but it can be possibly
8263 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
8264 there were bugs in prologue debug info, fixed later in GCC-4.5
8265 by "unwind info for epilogues" patch (which is not directly related).
8267 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
8268 needed, it would be wrong due to missing DW_AT_producer there.
8270 Still one can confuse GDB by using non-standard GCC compilation
8271 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
8273 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
8274 cust
->locations_valid
= 1;
8276 if (gcc_4_minor
>= 5)
8277 cust
->epilogue_unwind_valid
= 1;
8279 cust
->call_site_htab
= cu
->call_site_htab
;
8282 if (dwarf2_per_objfile
->using_index
)
8283 per_cu
->v
.quick
->compunit_symtab
= cust
;
8286 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8287 pst
->compunit_symtab
= cust
;
8291 /* Push it for inclusion processing later. */
8292 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
8294 do_cleanups (back_to
);
8297 /* Generate full symbol information for type unit PER_CU, whose DIEs have
8298 already been loaded into memory. */
8301 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
8302 enum language pretend_language
)
8304 struct dwarf2_cu
*cu
= per_cu
->cu
;
8305 struct objfile
*objfile
= per_cu
->objfile
;
8306 struct compunit_symtab
*cust
;
8307 struct cleanup
*back_to
, *delayed_list_cleanup
;
8308 struct signatured_type
*sig_type
;
8310 gdb_assert (per_cu
->is_debug_types
);
8311 sig_type
= (struct signatured_type
*) per_cu
;
8314 back_to
= make_cleanup (really_free_pendings
, NULL
);
8315 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8317 cu
->list_in_scope
= &file_symbols
;
8319 cu
->language
= pretend_language
;
8320 cu
->language_defn
= language_def (cu
->language
);
8322 /* The symbol tables are set up in read_type_unit_scope. */
8323 process_die (cu
->dies
, cu
);
8325 /* For now fudge the Go package. */
8326 if (cu
->language
== language_go
)
8327 fixup_go_packaging (cu
);
8329 /* Now that we have processed all the DIEs in the CU, all the types
8330 should be complete, and it should now be safe to compute all of the
8332 compute_delayed_physnames (cu
);
8333 do_cleanups (delayed_list_cleanup
);
8335 /* TUs share symbol tables.
8336 If this is the first TU to use this symtab, complete the construction
8337 of it with end_expandable_symtab. Otherwise, complete the addition of
8338 this TU's symbols to the existing symtab. */
8339 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
8341 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
8342 sig_type
->type_unit_group
->compunit_symtab
= cust
;
8346 /* Set symtab language to language from DW_AT_language. If the
8347 compilation is from a C file generated by language preprocessors,
8348 do not set the language if it was already deduced by
8350 if (!(cu
->language
== language_c
8351 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
8352 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8357 augment_type_symtab ();
8358 cust
= sig_type
->type_unit_group
->compunit_symtab
;
8361 if (dwarf2_per_objfile
->using_index
)
8362 per_cu
->v
.quick
->compunit_symtab
= cust
;
8365 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8366 pst
->compunit_symtab
= cust
;
8370 do_cleanups (back_to
);
8373 /* Process an imported unit DIE. */
8376 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8378 struct attribute
*attr
;
8380 /* For now we don't handle imported units in type units. */
8381 if (cu
->per_cu
->is_debug_types
)
8383 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8384 " supported in type units [in module %s]"),
8385 objfile_name (cu
->objfile
));
8388 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8391 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
8392 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
8393 dwarf2_per_cu_data
*per_cu
8394 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, cu
->objfile
);
8396 /* If necessary, add it to the queue and load its DIEs. */
8397 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
8398 load_full_comp_unit (per_cu
, cu
->language
);
8400 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8405 /* Reset the in_process bit of a die. */
8408 reset_die_in_process (void *arg
)
8410 struct die_info
*die
= (struct die_info
*) arg
;
8412 die
->in_process
= 0;
8415 /* Process a die and its children. */
8418 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8420 struct cleanup
*in_process
;
8422 /* We should only be processing those not already in process. */
8423 gdb_assert (!die
->in_process
);
8425 die
->in_process
= 1;
8426 in_process
= make_cleanup (reset_die_in_process
,die
);
8430 case DW_TAG_padding
:
8432 case DW_TAG_compile_unit
:
8433 case DW_TAG_partial_unit
:
8434 read_file_scope (die
, cu
);
8436 case DW_TAG_type_unit
:
8437 read_type_unit_scope (die
, cu
);
8439 case DW_TAG_subprogram
:
8440 case DW_TAG_inlined_subroutine
:
8441 read_func_scope (die
, cu
);
8443 case DW_TAG_lexical_block
:
8444 case DW_TAG_try_block
:
8445 case DW_TAG_catch_block
:
8446 read_lexical_block_scope (die
, cu
);
8448 case DW_TAG_call_site
:
8449 case DW_TAG_GNU_call_site
:
8450 read_call_site_scope (die
, cu
);
8452 case DW_TAG_class_type
:
8453 case DW_TAG_interface_type
:
8454 case DW_TAG_structure_type
:
8455 case DW_TAG_union_type
:
8456 process_structure_scope (die
, cu
);
8458 case DW_TAG_enumeration_type
:
8459 process_enumeration_scope (die
, cu
);
8462 /* These dies have a type, but processing them does not create
8463 a symbol or recurse to process the children. Therefore we can
8464 read them on-demand through read_type_die. */
8465 case DW_TAG_subroutine_type
:
8466 case DW_TAG_set_type
:
8467 case DW_TAG_array_type
:
8468 case DW_TAG_pointer_type
:
8469 case DW_TAG_ptr_to_member_type
:
8470 case DW_TAG_reference_type
:
8471 case DW_TAG_rvalue_reference_type
:
8472 case DW_TAG_string_type
:
8475 case DW_TAG_base_type
:
8476 case DW_TAG_subrange_type
:
8477 case DW_TAG_typedef
:
8478 /* Add a typedef symbol for the type definition, if it has a
8480 new_symbol (die
, read_type_die (die
, cu
), cu
);
8482 case DW_TAG_common_block
:
8483 read_common_block (die
, cu
);
8485 case DW_TAG_common_inclusion
:
8487 case DW_TAG_namespace
:
8488 cu
->processing_has_namespace_info
= 1;
8489 read_namespace (die
, cu
);
8492 cu
->processing_has_namespace_info
= 1;
8493 read_module (die
, cu
);
8495 case DW_TAG_imported_declaration
:
8496 cu
->processing_has_namespace_info
= 1;
8497 if (read_namespace_alias (die
, cu
))
8499 /* The declaration is not a global namespace alias: fall through. */
8500 case DW_TAG_imported_module
:
8501 cu
->processing_has_namespace_info
= 1;
8502 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
8503 || cu
->language
!= language_fortran
))
8504 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
8505 dwarf_tag_name (die
->tag
));
8506 read_import_statement (die
, cu
);
8509 case DW_TAG_imported_unit
:
8510 process_imported_unit_die (die
, cu
);
8514 new_symbol (die
, NULL
, cu
);
8518 do_cleanups (in_process
);
8521 /* DWARF name computation. */
8523 /* A helper function for dwarf2_compute_name which determines whether DIE
8524 needs to have the name of the scope prepended to the name listed in the
8528 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8530 struct attribute
*attr
;
8534 case DW_TAG_namespace
:
8535 case DW_TAG_typedef
:
8536 case DW_TAG_class_type
:
8537 case DW_TAG_interface_type
:
8538 case DW_TAG_structure_type
:
8539 case DW_TAG_union_type
:
8540 case DW_TAG_enumeration_type
:
8541 case DW_TAG_enumerator
:
8542 case DW_TAG_subprogram
:
8543 case DW_TAG_inlined_subroutine
:
8545 case DW_TAG_imported_declaration
:
8548 case DW_TAG_variable
:
8549 case DW_TAG_constant
:
8550 /* We only need to prefix "globally" visible variables. These include
8551 any variable marked with DW_AT_external or any variable that
8552 lives in a namespace. [Variables in anonymous namespaces
8553 require prefixing, but they are not DW_AT_external.] */
8555 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
8557 struct dwarf2_cu
*spec_cu
= cu
;
8559 return die_needs_namespace (die_specification (die
, &spec_cu
),
8563 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8564 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
8565 && die
->parent
->tag
!= DW_TAG_module
)
8567 /* A variable in a lexical block of some kind does not need a
8568 namespace, even though in C++ such variables may be external
8569 and have a mangled name. */
8570 if (die
->parent
->tag
== DW_TAG_lexical_block
8571 || die
->parent
->tag
== DW_TAG_try_block
8572 || die
->parent
->tag
== DW_TAG_catch_block
8573 || die
->parent
->tag
== DW_TAG_subprogram
)
8582 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
8583 compute the physname for the object, which include a method's:
8584 - formal parameters (C++),
8585 - receiver type (Go),
8587 The term "physname" is a bit confusing.
8588 For C++, for example, it is the demangled name.
8589 For Go, for example, it's the mangled name.
8591 For Ada, return the DIE's linkage name rather than the fully qualified
8592 name. PHYSNAME is ignored..
8594 The result is allocated on the objfile_obstack and canonicalized. */
8597 dwarf2_compute_name (const char *name
,
8598 struct die_info
*die
, struct dwarf2_cu
*cu
,
8601 struct objfile
*objfile
= cu
->objfile
;
8604 name
= dwarf2_name (die
, cu
);
8606 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
8607 but otherwise compute it by typename_concat inside GDB.
8608 FIXME: Actually this is not really true, or at least not always true.
8609 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
8610 Fortran names because there is no mangling standard. So new_symbol_full
8611 will set the demangled name to the result of dwarf2_full_name, and it is
8612 the demangled name that GDB uses if it exists. */
8613 if (cu
->language
== language_ada
8614 || (cu
->language
== language_fortran
&& physname
))
8616 /* For Ada unit, we prefer the linkage name over the name, as
8617 the former contains the exported name, which the user expects
8618 to be able to reference. Ideally, we want the user to be able
8619 to reference this entity using either natural or linkage name,
8620 but we haven't started looking at this enhancement yet. */
8621 const char *linkage_name
;
8623 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
8624 if (linkage_name
== NULL
)
8625 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8626 if (linkage_name
!= NULL
)
8627 return linkage_name
;
8630 /* These are the only languages we know how to qualify names in. */
8632 && (cu
->language
== language_cplus
8633 || cu
->language
== language_fortran
|| cu
->language
== language_d
8634 || cu
->language
== language_rust
))
8636 if (die_needs_namespace (die
, cu
))
8640 const char *canonical_name
= NULL
;
8644 prefix
= determine_prefix (die
, cu
);
8645 if (*prefix
!= '\0')
8647 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
8650 buf
.puts (prefixed_name
);
8651 xfree (prefixed_name
);
8656 /* Template parameters may be specified in the DIE's DW_AT_name, or
8657 as children with DW_TAG_template_type_param or
8658 DW_TAG_value_type_param. If the latter, add them to the name
8659 here. If the name already has template parameters, then
8660 skip this step; some versions of GCC emit both, and
8661 it is more efficient to use the pre-computed name.
8663 Something to keep in mind about this process: it is very
8664 unlikely, or in some cases downright impossible, to produce
8665 something that will match the mangled name of a function.
8666 If the definition of the function has the same debug info,
8667 we should be able to match up with it anyway. But fallbacks
8668 using the minimal symbol, for instance to find a method
8669 implemented in a stripped copy of libstdc++, will not work.
8670 If we do not have debug info for the definition, we will have to
8671 match them up some other way.
8673 When we do name matching there is a related problem with function
8674 templates; two instantiated function templates are allowed to
8675 differ only by their return types, which we do not add here. */
8677 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
8679 struct attribute
*attr
;
8680 struct die_info
*child
;
8683 die
->building_fullname
= 1;
8685 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
8689 const gdb_byte
*bytes
;
8690 struct dwarf2_locexpr_baton
*baton
;
8693 if (child
->tag
!= DW_TAG_template_type_param
8694 && child
->tag
!= DW_TAG_template_value_param
)
8705 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
8708 complaint (&symfile_complaints
,
8709 _("template parameter missing DW_AT_type"));
8710 buf
.puts ("UNKNOWN_TYPE");
8713 type
= die_type (child
, cu
);
8715 if (child
->tag
== DW_TAG_template_type_param
)
8717 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
8721 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
8724 complaint (&symfile_complaints
,
8725 _("template parameter missing "
8726 "DW_AT_const_value"));
8727 buf
.puts ("UNKNOWN_VALUE");
8731 dwarf2_const_value_attr (attr
, type
, name
,
8732 &cu
->comp_unit_obstack
, cu
,
8733 &value
, &bytes
, &baton
);
8735 if (TYPE_NOSIGN (type
))
8736 /* GDB prints characters as NUMBER 'CHAR'. If that's
8737 changed, this can use value_print instead. */
8738 c_printchar (value
, type
, &buf
);
8741 struct value_print_options opts
;
8744 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
8748 else if (bytes
!= NULL
)
8750 v
= allocate_value (type
);
8751 memcpy (value_contents_writeable (v
), bytes
,
8752 TYPE_LENGTH (type
));
8755 v
= value_from_longest (type
, value
);
8757 /* Specify decimal so that we do not depend on
8759 get_formatted_print_options (&opts
, 'd');
8761 value_print (v
, &buf
, &opts
);
8767 die
->building_fullname
= 0;
8771 /* Close the argument list, with a space if necessary
8772 (nested templates). */
8773 if (!buf
.empty () && buf
.string ().back () == '>')
8780 /* For C++ methods, append formal parameter type
8781 information, if PHYSNAME. */
8783 if (physname
&& die
->tag
== DW_TAG_subprogram
8784 && cu
->language
== language_cplus
)
8786 struct type
*type
= read_type_die (die
, cu
);
8788 c_type_print_args (type
, &buf
, 1, cu
->language
,
8789 &type_print_raw_options
);
8791 if (cu
->language
== language_cplus
)
8793 /* Assume that an artificial first parameter is
8794 "this", but do not crash if it is not. RealView
8795 marks unnamed (and thus unused) parameters as
8796 artificial; there is no way to differentiate
8798 if (TYPE_NFIELDS (type
) > 0
8799 && TYPE_FIELD_ARTIFICIAL (type
, 0)
8800 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
8801 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
8803 buf
.puts (" const");
8807 const std::string
&intermediate_name
= buf
.string ();
8809 if (cu
->language
== language_cplus
)
8811 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
8812 &objfile
->per_bfd
->storage_obstack
);
8814 /* If we only computed INTERMEDIATE_NAME, or if
8815 INTERMEDIATE_NAME is already canonical, then we need to
8816 copy it to the appropriate obstack. */
8817 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
8818 name
= ((const char *)
8819 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8820 intermediate_name
.c_str (),
8821 intermediate_name
.length ()));
8823 name
= canonical_name
;
8830 /* Return the fully qualified name of DIE, based on its DW_AT_name.
8831 If scope qualifiers are appropriate they will be added. The result
8832 will be allocated on the storage_obstack, or NULL if the DIE does
8833 not have a name. NAME may either be from a previous call to
8834 dwarf2_name or NULL.
8836 The output string will be canonicalized (if C++). */
8839 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8841 return dwarf2_compute_name (name
, die
, cu
, 0);
8844 /* Construct a physname for the given DIE in CU. NAME may either be
8845 from a previous call to dwarf2_name or NULL. The result will be
8846 allocated on the objfile_objstack or NULL if the DIE does not have a
8849 The output string will be canonicalized (if C++). */
8852 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8854 struct objfile
*objfile
= cu
->objfile
;
8855 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
8856 struct cleanup
*back_to
;
8859 /* In this case dwarf2_compute_name is just a shortcut not building anything
8861 if (!die_needs_namespace (die
, cu
))
8862 return dwarf2_compute_name (name
, die
, cu
, 1);
8864 back_to
= make_cleanup (null_cleanup
, NULL
);
8866 mangled
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
8867 if (mangled
== NULL
)
8868 mangled
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8870 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
8871 See https://github.com/rust-lang/rust/issues/32925. */
8872 if (cu
->language
== language_rust
&& mangled
!= NULL
8873 && strchr (mangled
, '{') != NULL
)
8876 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
8878 if (mangled
!= NULL
)
8882 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
8883 type. It is easier for GDB users to search for such functions as
8884 `name(params)' than `long name(params)'. In such case the minimal
8885 symbol names do not match the full symbol names but for template
8886 functions there is never a need to look up their definition from their
8887 declaration so the only disadvantage remains the minimal symbol
8888 variant `long name(params)' does not have the proper inferior type.
8891 if (cu
->language
== language_go
)
8893 /* This is a lie, but we already lie to the caller new_symbol_full.
8894 new_symbol_full assumes we return the mangled name.
8895 This just undoes that lie until things are cleaned up. */
8900 demangled
= gdb_demangle (mangled
,
8901 (DMGL_PARAMS
| DMGL_ANSI
| DMGL_RET_DROP
));
8905 make_cleanup (xfree
, demangled
);
8915 if (canon
== NULL
|| check_physname
)
8917 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
8919 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
8921 /* It may not mean a bug in GDB. The compiler could also
8922 compute DW_AT_linkage_name incorrectly. But in such case
8923 GDB would need to be bug-to-bug compatible. */
8925 complaint (&symfile_complaints
,
8926 _("Computed physname <%s> does not match demangled <%s> "
8927 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
8928 physname
, canon
, mangled
, to_underlying (die
->sect_off
),
8929 objfile_name (objfile
));
8931 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
8932 is available here - over computed PHYSNAME. It is safer
8933 against both buggy GDB and buggy compilers. */
8947 retval
= ((const char *)
8948 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8949 retval
, strlen (retval
)));
8951 do_cleanups (back_to
);
8955 /* Inspect DIE in CU for a namespace alias. If one exists, record
8956 a new symbol for it.
8958 Returns 1 if a namespace alias was recorded, 0 otherwise. */
8961 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
8963 struct attribute
*attr
;
8965 /* If the die does not have a name, this is not a namespace
8967 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8971 struct die_info
*d
= die
;
8972 struct dwarf2_cu
*imported_cu
= cu
;
8974 /* If the compiler has nested DW_AT_imported_declaration DIEs,
8975 keep inspecting DIEs until we hit the underlying import. */
8976 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
8977 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
8979 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
8983 d
= follow_die_ref (d
, attr
, &imported_cu
);
8984 if (d
->tag
!= DW_TAG_imported_declaration
)
8988 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
8990 complaint (&symfile_complaints
,
8991 _("DIE at 0x%x has too many recursively imported "
8992 "declarations"), to_underlying (d
->sect_off
));
8999 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9001 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
9002 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
9004 /* This declaration is a global namespace alias. Add
9005 a symbol for it whose type is the aliased namespace. */
9006 new_symbol (die
, type
, cu
);
9015 /* Return the using directives repository (global or local?) to use in the
9016 current context for LANGUAGE.
9018 For Ada, imported declarations can materialize renamings, which *may* be
9019 global. However it is impossible (for now?) in DWARF to distinguish
9020 "external" imported declarations and "static" ones. As all imported
9021 declarations seem to be static in all other languages, make them all CU-wide
9022 global only in Ada. */
9024 static struct using_direct
**
9025 using_directives (enum language language
)
9027 if (language
== language_ada
&& context_stack_depth
== 0)
9028 return &global_using_directives
;
9030 return &local_using_directives
;
9033 /* Read the import statement specified by the given die and record it. */
9036 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
9038 struct objfile
*objfile
= cu
->objfile
;
9039 struct attribute
*import_attr
;
9040 struct die_info
*imported_die
, *child_die
;
9041 struct dwarf2_cu
*imported_cu
;
9042 const char *imported_name
;
9043 const char *imported_name_prefix
;
9044 const char *canonical_name
;
9045 const char *import_alias
;
9046 const char *imported_declaration
= NULL
;
9047 const char *import_prefix
;
9048 VEC (const_char_ptr
) *excludes
= NULL
;
9049 struct cleanup
*cleanups
;
9051 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9052 if (import_attr
== NULL
)
9054 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
9055 dwarf_tag_name (die
->tag
));
9060 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
9061 imported_name
= dwarf2_name (imported_die
, imported_cu
);
9062 if (imported_name
== NULL
)
9064 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
9066 The import in the following code:
9080 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
9081 <52> DW_AT_decl_file : 1
9082 <53> DW_AT_decl_line : 6
9083 <54> DW_AT_import : <0x75>
9084 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
9086 <5b> DW_AT_decl_file : 1
9087 <5c> DW_AT_decl_line : 2
9088 <5d> DW_AT_type : <0x6e>
9090 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
9091 <76> DW_AT_byte_size : 4
9092 <77> DW_AT_encoding : 5 (signed)
9094 imports the wrong die ( 0x75 instead of 0x58 ).
9095 This case will be ignored until the gcc bug is fixed. */
9099 /* Figure out the local name after import. */
9100 import_alias
= dwarf2_name (die
, cu
);
9102 /* Figure out where the statement is being imported to. */
9103 import_prefix
= determine_prefix (die
, cu
);
9105 /* Figure out what the scope of the imported die is and prepend it
9106 to the name of the imported die. */
9107 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
9109 if (imported_die
->tag
!= DW_TAG_namespace
9110 && imported_die
->tag
!= DW_TAG_module
)
9112 imported_declaration
= imported_name
;
9113 canonical_name
= imported_name_prefix
;
9115 else if (strlen (imported_name_prefix
) > 0)
9116 canonical_name
= obconcat (&objfile
->objfile_obstack
,
9117 imported_name_prefix
,
9118 (cu
->language
== language_d
? "." : "::"),
9119 imported_name
, (char *) NULL
);
9121 canonical_name
= imported_name
;
9123 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
9125 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
9126 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
9127 child_die
= sibling_die (child_die
))
9129 /* DWARF-4: A Fortran use statement with a “rename list” may be
9130 represented by an imported module entry with an import attribute
9131 referring to the module and owned entries corresponding to those
9132 entities that are renamed as part of being imported. */
9134 if (child_die
->tag
!= DW_TAG_imported_declaration
)
9136 complaint (&symfile_complaints
,
9137 _("child DW_TAG_imported_declaration expected "
9138 "- DIE at 0x%x [in module %s]"),
9139 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
9143 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
9144 if (import_attr
== NULL
)
9146 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
9147 dwarf_tag_name (child_die
->tag
));
9152 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
9154 imported_name
= dwarf2_name (imported_die
, imported_cu
);
9155 if (imported_name
== NULL
)
9157 complaint (&symfile_complaints
,
9158 _("child DW_TAG_imported_declaration has unknown "
9159 "imported name - DIE at 0x%x [in module %s]"),
9160 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
9164 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
9166 process_die (child_die
, cu
);
9169 add_using_directive (using_directives (cu
->language
),
9173 imported_declaration
,
9176 &objfile
->objfile_obstack
);
9178 do_cleanups (cleanups
);
9181 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
9182 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
9183 this, it was first present in GCC release 4.3.0. */
9186 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
9188 if (!cu
->checked_producer
)
9189 check_producer (cu
);
9191 return cu
->producer_is_gcc_lt_4_3
;
9194 static file_and_directory
9195 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
9197 file_and_directory res
;
9199 /* Find the filename. Do not use dwarf2_name here, since the filename
9200 is not a source language identifier. */
9201 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
9202 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
9204 if (res
.comp_dir
== NULL
9205 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
9206 && IS_ABSOLUTE_PATH (res
.name
))
9208 res
.comp_dir_storage
= ldirname (res
.name
);
9209 if (!res
.comp_dir_storage
.empty ())
9210 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
9212 if (res
.comp_dir
!= NULL
)
9214 /* Irix 6.2 native cc prepends <machine>.: to the compilation
9215 directory, get rid of it. */
9216 const char *cp
= strchr (res
.comp_dir
, ':');
9218 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
9219 res
.comp_dir
= cp
+ 1;
9222 if (res
.name
== NULL
)
9223 res
.name
= "<unknown>";
9228 /* Handle DW_AT_stmt_list for a compilation unit.
9229 DIE is the DW_TAG_compile_unit die for CU.
9230 COMP_DIR is the compilation directory. LOWPC is passed to
9231 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
9234 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
9235 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
9237 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9238 struct attribute
*attr
;
9239 struct line_header line_header_local
;
9240 hashval_t line_header_local_hash
;
9245 gdb_assert (! cu
->per_cu
->is_debug_types
);
9247 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9251 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
9253 /* The line header hash table is only created if needed (it exists to
9254 prevent redundant reading of the line table for partial_units).
9255 If we're given a partial_unit, we'll need it. If we're given a
9256 compile_unit, then use the line header hash table if it's already
9257 created, but don't create one just yet. */
9259 if (dwarf2_per_objfile
->line_header_hash
== NULL
9260 && die
->tag
== DW_TAG_partial_unit
)
9262 dwarf2_per_objfile
->line_header_hash
9263 = htab_create_alloc_ex (127, line_header_hash_voidp
,
9264 line_header_eq_voidp
,
9265 free_line_header_voidp
,
9266 &objfile
->objfile_obstack
,
9267 hashtab_obstack_allocate
,
9268 dummy_obstack_deallocate
);
9271 line_header_local
.sect_off
= line_offset
;
9272 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
9273 line_header_local_hash
= line_header_hash (&line_header_local
);
9274 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
9276 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9278 line_header_local_hash
, NO_INSERT
);
9280 /* For DW_TAG_compile_unit we need info like symtab::linetable which
9281 is not present in *SLOT (since if there is something in *SLOT then
9282 it will be for a partial_unit). */
9283 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
9285 gdb_assert (*slot
!= NULL
);
9286 cu
->line_header
= (struct line_header
*) *slot
;
9291 /* dwarf_decode_line_header does not yet provide sufficient information.
9292 We always have to call also dwarf_decode_lines for it. */
9293 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
9296 cu
->line_header
= lh
.get ();
9298 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
9302 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9304 line_header_local_hash
, INSERT
);
9305 gdb_assert (slot
!= NULL
);
9307 if (slot
!= NULL
&& *slot
== NULL
)
9309 /* This newly decoded line number information unit will be owned
9310 by line_header_hash hash table. */
9311 *slot
= cu
->line_header
;
9315 /* We cannot free any current entry in (*slot) as that struct line_header
9316 may be already used by multiple CUs. Create only temporary decoded
9317 line_header for this CU - it may happen at most once for each line
9318 number information unit. And if we're not using line_header_hash
9319 then this is what we want as well. */
9320 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
9322 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
9323 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
9329 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
9332 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9334 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9335 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9336 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
9337 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
9338 struct attribute
*attr
;
9339 struct die_info
*child_die
;
9342 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9344 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
9346 /* If we didn't find a lowpc, set it to highpc to avoid complaints
9347 from finish_block. */
9348 if (lowpc
== ((CORE_ADDR
) -1))
9350 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
9352 file_and_directory fnd
= find_file_and_directory (die
, cu
);
9354 prepare_one_comp_unit (cu
, die
, cu
->language
);
9356 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
9357 standardised yet. As a workaround for the language detection we fall
9358 back to the DW_AT_producer string. */
9359 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
9360 cu
->language
= language_opencl
;
9362 /* Similar hack for Go. */
9363 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
9364 set_cu_language (DW_LANG_Go
, cu
);
9366 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
9368 /* Decode line number information if present. We do this before
9369 processing child DIEs, so that the line header table is available
9370 for DW_AT_decl_file. */
9371 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
9373 /* Process all dies in compilation unit. */
9374 if (die
->child
!= NULL
)
9376 child_die
= die
->child
;
9377 while (child_die
&& child_die
->tag
)
9379 process_die (child_die
, cu
);
9380 child_die
= sibling_die (child_die
);
9384 /* Decode macro information, if present. Dwarf 2 macro information
9385 refers to information in the line number info statement program
9386 header, so we can only read it if we've read the header
9388 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
9390 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
9391 if (attr
&& cu
->line_header
)
9393 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
9394 complaint (&symfile_complaints
,
9395 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
9397 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
9401 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
9402 if (attr
&& cu
->line_header
)
9404 unsigned int macro_offset
= DW_UNSND (attr
);
9406 dwarf_decode_macros (cu
, macro_offset
, 0);
9411 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
9412 Create the set of symtabs used by this TU, or if this TU is sharing
9413 symtabs with another TU and the symtabs have already been created
9414 then restore those symtabs in the line header.
9415 We don't need the pc/line-number mapping for type units. */
9418 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
9420 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
9421 struct type_unit_group
*tu_group
;
9423 struct attribute
*attr
;
9425 struct signatured_type
*sig_type
;
9427 gdb_assert (per_cu
->is_debug_types
);
9428 sig_type
= (struct signatured_type
*) per_cu
;
9430 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9432 /* If we're using .gdb_index (includes -readnow) then
9433 per_cu->type_unit_group may not have been set up yet. */
9434 if (sig_type
->type_unit_group
== NULL
)
9435 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
9436 tu_group
= sig_type
->type_unit_group
;
9438 /* If we've already processed this stmt_list there's no real need to
9439 do it again, we could fake it and just recreate the part we need
9440 (file name,index -> symtab mapping). If data shows this optimization
9441 is useful we can do it then. */
9442 first_time
= tu_group
->compunit_symtab
== NULL
;
9444 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
9449 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
9450 lh
= dwarf_decode_line_header (line_offset
, cu
);
9455 dwarf2_start_symtab (cu
, "", NULL
, 0);
9458 gdb_assert (tu_group
->symtabs
== NULL
);
9459 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9464 cu
->line_header
= lh
.get ();
9468 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
9470 /* Note: We don't assign tu_group->compunit_symtab yet because we're
9471 still initializing it, and our caller (a few levels up)
9472 process_full_type_unit still needs to know if this is the first
9475 tu_group
->num_symtabs
= lh
->file_names
.size ();
9476 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->file_names
.size ());
9478 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
9480 file_entry
&fe
= lh
->file_names
[i
];
9482 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
.get ()));
9484 if (current_subfile
->symtab
== NULL
)
9486 /* NOTE: start_subfile will recognize when it's been passed
9487 a file it has already seen. So we can't assume there's a
9488 simple mapping from lh->file_names to subfiles, plus
9489 lh->file_names may contain dups. */
9490 current_subfile
->symtab
9491 = allocate_symtab (cust
, current_subfile
->name
);
9494 fe
.symtab
= current_subfile
->symtab
;
9495 tu_group
->symtabs
[i
] = fe
.symtab
;
9500 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9502 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
9504 struct file_entry
*fe
= &lh
->file_names
[i
];
9506 fe
->symtab
= tu_group
->symtabs
[i
];
9512 /* The main symtab is allocated last. Type units don't have DW_AT_name
9513 so they don't have a "real" (so to speak) symtab anyway.
9514 There is later code that will assign the main symtab to all symbols
9515 that don't have one. We need to handle the case of a symbol with a
9516 missing symtab (DW_AT_decl_file) anyway. */
9519 /* Process DW_TAG_type_unit.
9520 For TUs we want to skip the first top level sibling if it's not the
9521 actual type being defined by this TU. In this case the first top
9522 level sibling is there to provide context only. */
9525 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9527 struct die_info
*child_die
;
9529 prepare_one_comp_unit (cu
, die
, language_minimal
);
9531 /* Initialize (or reinitialize) the machinery for building symtabs.
9532 We do this before processing child DIEs, so that the line header table
9533 is available for DW_AT_decl_file. */
9534 setup_type_unit_groups (die
, cu
);
9536 if (die
->child
!= NULL
)
9538 child_die
= die
->child
;
9539 while (child_die
&& child_die
->tag
)
9541 process_die (child_die
, cu
);
9542 child_die
= sibling_die (child_die
);
9549 http://gcc.gnu.org/wiki/DebugFission
9550 http://gcc.gnu.org/wiki/DebugFissionDWP
9552 To simplify handling of both DWO files ("object" files with the DWARF info)
9553 and DWP files (a file with the DWOs packaged up into one file), we treat
9554 DWP files as having a collection of virtual DWO files. */
9557 hash_dwo_file (const void *item
)
9559 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
9562 hash
= htab_hash_string (dwo_file
->dwo_name
);
9563 if (dwo_file
->comp_dir
!= NULL
)
9564 hash
+= htab_hash_string (dwo_file
->comp_dir
);
9569 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
9571 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
9572 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
9574 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
9576 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
9577 return lhs
->comp_dir
== rhs
->comp_dir
;
9578 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
9581 /* Allocate a hash table for DWO files. */
9584 allocate_dwo_file_hash_table (void)
9586 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9588 return htab_create_alloc_ex (41,
9592 &objfile
->objfile_obstack
,
9593 hashtab_obstack_allocate
,
9594 dummy_obstack_deallocate
);
9597 /* Lookup DWO file DWO_NAME. */
9600 lookup_dwo_file_slot (const char *dwo_name
, const char *comp_dir
)
9602 struct dwo_file find_entry
;
9605 if (dwarf2_per_objfile
->dwo_files
== NULL
)
9606 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
9608 memset (&find_entry
, 0, sizeof (find_entry
));
9609 find_entry
.dwo_name
= dwo_name
;
9610 find_entry
.comp_dir
= comp_dir
;
9611 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
9617 hash_dwo_unit (const void *item
)
9619 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
9621 /* This drops the top 32 bits of the id, but is ok for a hash. */
9622 return dwo_unit
->signature
;
9626 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
9628 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
9629 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
9631 /* The signature is assumed to be unique within the DWO file.
9632 So while object file CU dwo_id's always have the value zero,
9633 that's OK, assuming each object file DWO file has only one CU,
9634 and that's the rule for now. */
9635 return lhs
->signature
== rhs
->signature
;
9638 /* Allocate a hash table for DWO CUs,TUs.
9639 There is one of these tables for each of CUs,TUs for each DWO file. */
9642 allocate_dwo_unit_table (struct objfile
*objfile
)
9644 /* Start out with a pretty small number.
9645 Generally DWO files contain only one CU and maybe some TUs. */
9646 return htab_create_alloc_ex (3,
9650 &objfile
->objfile_obstack
,
9651 hashtab_obstack_allocate
,
9652 dummy_obstack_deallocate
);
9655 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
9657 struct create_dwo_cu_data
9659 struct dwo_file
*dwo_file
;
9660 struct dwo_unit dwo_unit
;
9663 /* die_reader_func for create_dwo_cu. */
9666 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
9667 const gdb_byte
*info_ptr
,
9668 struct die_info
*comp_unit_die
,
9672 struct dwarf2_cu
*cu
= reader
->cu
;
9673 sect_offset sect_off
= cu
->per_cu
->sect_off
;
9674 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
9675 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
9676 struct dwo_file
*dwo_file
= data
->dwo_file
;
9677 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
9678 struct attribute
*attr
;
9680 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
9683 complaint (&symfile_complaints
,
9684 _("Dwarf Error: debug entry at offset 0x%x is missing"
9685 " its dwo_id [in module %s]"),
9686 to_underlying (sect_off
), dwo_file
->dwo_name
);
9690 dwo_unit
->dwo_file
= dwo_file
;
9691 dwo_unit
->signature
= DW_UNSND (attr
);
9692 dwo_unit
->section
= section
;
9693 dwo_unit
->sect_off
= sect_off
;
9694 dwo_unit
->length
= cu
->per_cu
->length
;
9696 if (dwarf_read_debug
)
9697 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id %s\n",
9698 to_underlying (sect_off
),
9699 hex_string (dwo_unit
->signature
));
9702 /* Create the dwo_units for the CUs in a DWO_FILE.
9703 Note: This function processes DWO files only, not DWP files. */
9706 create_cus_hash_table (struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
9709 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9710 const struct dwarf2_section_info
*abbrev_section
= &dwo_file
.sections
.abbrev
;
9711 const gdb_byte
*info_ptr
, *end_ptr
;
9713 dwarf2_read_section (objfile
, §ion
);
9714 info_ptr
= section
.buffer
;
9716 if (info_ptr
== NULL
)
9719 if (dwarf_read_debug
)
9721 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
9722 get_section_name (§ion
),
9723 get_section_file_name (§ion
));
9726 end_ptr
= info_ptr
+ section
.size
;
9727 while (info_ptr
< end_ptr
)
9729 struct dwarf2_per_cu_data per_cu
;
9730 struct create_dwo_cu_data create_dwo_cu_data
;
9731 struct dwo_unit
*dwo_unit
;
9733 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
9735 memset (&create_dwo_cu_data
.dwo_unit
, 0,
9736 sizeof (create_dwo_cu_data
.dwo_unit
));
9737 memset (&per_cu
, 0, sizeof (per_cu
));
9738 per_cu
.objfile
= objfile
;
9739 per_cu
.is_debug_types
= 0;
9740 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
9741 per_cu
.section
= §ion
;
9743 init_cutu_and_read_dies_no_follow (
9744 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
9745 info_ptr
+= per_cu
.length
;
9747 // If the unit could not be parsed, skip it.
9748 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
9751 if (cus_htab
== NULL
)
9752 cus_htab
= allocate_dwo_unit_table (objfile
);
9754 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
9755 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
9756 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
9757 gdb_assert (slot
!= NULL
);
9760 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
9761 sect_offset dup_sect_off
= dup_cu
->sect_off
;
9763 complaint (&symfile_complaints
,
9764 _("debug cu entry at offset 0x%x is duplicate to"
9765 " the entry at offset 0x%x, signature %s"),
9766 to_underlying (sect_off
), to_underlying (dup_sect_off
),
9767 hex_string (dwo_unit
->signature
));
9769 *slot
= (void *)dwo_unit
;
9773 /* DWP file .debug_{cu,tu}_index section format:
9774 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
9778 Both index sections have the same format, and serve to map a 64-bit
9779 signature to a set of section numbers. Each section begins with a header,
9780 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
9781 indexes, and a pool of 32-bit section numbers. The index sections will be
9782 aligned at 8-byte boundaries in the file.
9784 The index section header consists of:
9786 V, 32 bit version number
9788 N, 32 bit number of compilation units or type units in the index
9789 M, 32 bit number of slots in the hash table
9791 Numbers are recorded using the byte order of the application binary.
9793 The hash table begins at offset 16 in the section, and consists of an array
9794 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
9795 order of the application binary). Unused slots in the hash table are 0.
9796 (We rely on the extreme unlikeliness of a signature being exactly 0.)
9798 The parallel table begins immediately after the hash table
9799 (at offset 16 + 8 * M from the beginning of the section), and consists of an
9800 array of 32-bit indexes (using the byte order of the application binary),
9801 corresponding 1-1 with slots in the hash table. Each entry in the parallel
9802 table contains a 32-bit index into the pool of section numbers. For unused
9803 hash table slots, the corresponding entry in the parallel table will be 0.
9805 The pool of section numbers begins immediately following the hash table
9806 (at offset 16 + 12 * M from the beginning of the section). The pool of
9807 section numbers consists of an array of 32-bit words (using the byte order
9808 of the application binary). Each item in the array is indexed starting
9809 from 0. The hash table entry provides the index of the first section
9810 number in the set. Additional section numbers in the set follow, and the
9811 set is terminated by a 0 entry (section number 0 is not used in ELF).
9813 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
9814 section must be the first entry in the set, and the .debug_abbrev.dwo must
9815 be the second entry. Other members of the set may follow in any order.
9821 DWP Version 2 combines all the .debug_info, etc. sections into one,
9822 and the entries in the index tables are now offsets into these sections.
9823 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
9826 Index Section Contents:
9828 Hash Table of Signatures dwp_hash_table.hash_table
9829 Parallel Table of Indices dwp_hash_table.unit_table
9830 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
9831 Table of Section Sizes dwp_hash_table.v2.sizes
9833 The index section header consists of:
9835 V, 32 bit version number
9836 L, 32 bit number of columns in the table of section offsets
9837 N, 32 bit number of compilation units or type units in the index
9838 M, 32 bit number of slots in the hash table
9840 Numbers are recorded using the byte order of the application binary.
9842 The hash table has the same format as version 1.
9843 The parallel table of indices has the same format as version 1,
9844 except that the entries are origin-1 indices into the table of sections
9845 offsets and the table of section sizes.
9847 The table of offsets begins immediately following the parallel table
9848 (at offset 16 + 12 * M from the beginning of the section). The table is
9849 a two-dimensional array of 32-bit words (using the byte order of the
9850 application binary), with L columns and N+1 rows, in row-major order.
9851 Each row in the array is indexed starting from 0. The first row provides
9852 a key to the remaining rows: each column in this row provides an identifier
9853 for a debug section, and the offsets in the same column of subsequent rows
9854 refer to that section. The section identifiers are:
9856 DW_SECT_INFO 1 .debug_info.dwo
9857 DW_SECT_TYPES 2 .debug_types.dwo
9858 DW_SECT_ABBREV 3 .debug_abbrev.dwo
9859 DW_SECT_LINE 4 .debug_line.dwo
9860 DW_SECT_LOC 5 .debug_loc.dwo
9861 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
9862 DW_SECT_MACINFO 7 .debug_macinfo.dwo
9863 DW_SECT_MACRO 8 .debug_macro.dwo
9865 The offsets provided by the CU and TU index sections are the base offsets
9866 for the contributions made by each CU or TU to the corresponding section
9867 in the package file. Each CU and TU header contains an abbrev_offset
9868 field, used to find the abbreviations table for that CU or TU within the
9869 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
9870 be interpreted as relative to the base offset given in the index section.
9871 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
9872 should be interpreted as relative to the base offset for .debug_line.dwo,
9873 and offsets into other debug sections obtained from DWARF attributes should
9874 also be interpreted as relative to the corresponding base offset.
9876 The table of sizes begins immediately following the table of offsets.
9877 Like the table of offsets, it is a two-dimensional array of 32-bit words,
9878 with L columns and N rows, in row-major order. Each row in the array is
9879 indexed starting from 1 (row 0 is shared by the two tables).
9883 Hash table lookup is handled the same in version 1 and 2:
9885 We assume that N and M will not exceed 2^32 - 1.
9886 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
9888 Given a 64-bit compilation unit signature or a type signature S, an entry
9889 in the hash table is located as follows:
9891 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
9892 the low-order k bits all set to 1.
9894 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
9896 3) If the hash table entry at index H matches the signature, use that
9897 entry. If the hash table entry at index H is unused (all zeroes),
9898 terminate the search: the signature is not present in the table.
9900 4) Let H = (H + H') modulo M. Repeat at Step 3.
9902 Because M > N and H' and M are relatively prime, the search is guaranteed
9903 to stop at an unused slot or find the match. */
9905 /* Create a hash table to map DWO IDs to their CU/TU entry in
9906 .debug_{info,types}.dwo in DWP_FILE.
9907 Returns NULL if there isn't one.
9908 Note: This function processes DWP files only, not DWO files. */
9910 static struct dwp_hash_table
*
9911 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
9913 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9914 bfd
*dbfd
= dwp_file
->dbfd
;
9915 const gdb_byte
*index_ptr
, *index_end
;
9916 struct dwarf2_section_info
*index
;
9917 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
9918 struct dwp_hash_table
*htab
;
9921 index
= &dwp_file
->sections
.tu_index
;
9923 index
= &dwp_file
->sections
.cu_index
;
9925 if (dwarf2_section_empty_p (index
))
9927 dwarf2_read_section (objfile
, index
);
9929 index_ptr
= index
->buffer
;
9930 index_end
= index_ptr
+ index
->size
;
9932 version
= read_4_bytes (dbfd
, index_ptr
);
9935 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
9939 nr_units
= read_4_bytes (dbfd
, index_ptr
);
9941 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
9944 if (version
!= 1 && version
!= 2)
9946 error (_("Dwarf Error: unsupported DWP file version (%s)"
9948 pulongest (version
), dwp_file
->name
);
9950 if (nr_slots
!= (nr_slots
& -nr_slots
))
9952 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
9953 " is not power of 2 [in module %s]"),
9954 pulongest (nr_slots
), dwp_file
->name
);
9957 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
9958 htab
->version
= version
;
9959 htab
->nr_columns
= nr_columns
;
9960 htab
->nr_units
= nr_units
;
9961 htab
->nr_slots
= nr_slots
;
9962 htab
->hash_table
= index_ptr
;
9963 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
9965 /* Exit early if the table is empty. */
9966 if (nr_slots
== 0 || nr_units
== 0
9967 || (version
== 2 && nr_columns
== 0))
9969 /* All must be zero. */
9970 if (nr_slots
!= 0 || nr_units
!= 0
9971 || (version
== 2 && nr_columns
!= 0))
9973 complaint (&symfile_complaints
,
9974 _("Empty DWP but nr_slots,nr_units,nr_columns not"
9975 " all zero [in modules %s]"),
9983 htab
->section_pool
.v1
.indices
=
9984 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9985 /* It's harder to decide whether the section is too small in v1.
9986 V1 is deprecated anyway so we punt. */
9990 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9991 int *ids
= htab
->section_pool
.v2
.section_ids
;
9992 /* Reverse map for error checking. */
9993 int ids_seen
[DW_SECT_MAX
+ 1];
9998 error (_("Dwarf Error: bad DWP hash table, too few columns"
9999 " in section table [in module %s]"),
10002 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
10004 error (_("Dwarf Error: bad DWP hash table, too many columns"
10005 " in section table [in module %s]"),
10008 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
10009 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
10010 for (i
= 0; i
< nr_columns
; ++i
)
10012 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
10014 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
10016 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
10017 " in section table [in module %s]"),
10018 id
, dwp_file
->name
);
10020 if (ids_seen
[id
] != -1)
10022 error (_("Dwarf Error: bad DWP hash table, duplicate section"
10023 " id %d in section table [in module %s]"),
10024 id
, dwp_file
->name
);
10029 /* Must have exactly one info or types section. */
10030 if (((ids_seen
[DW_SECT_INFO
] != -1)
10031 + (ids_seen
[DW_SECT_TYPES
] != -1))
10034 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
10035 " DWO info/types section [in module %s]"),
10038 /* Must have an abbrev section. */
10039 if (ids_seen
[DW_SECT_ABBREV
] == -1)
10041 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
10042 " section [in module %s]"),
10045 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
10046 htab
->section_pool
.v2
.sizes
=
10047 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
10048 * nr_units
* nr_columns
);
10049 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
10050 * nr_units
* nr_columns
))
10053 error (_("Dwarf Error: DWP index section is corrupt (too small)"
10054 " [in module %s]"),
10062 /* Update SECTIONS with the data from SECTP.
10064 This function is like the other "locate" section routines that are
10065 passed to bfd_map_over_sections, but in this context the sections to
10066 read comes from the DWP V1 hash table, not the full ELF section table.
10068 The result is non-zero for success, or zero if an error was found. */
10071 locate_v1_virtual_dwo_sections (asection
*sectp
,
10072 struct virtual_v1_dwo_sections
*sections
)
10074 const struct dwop_section_names
*names
= &dwop_section_names
;
10076 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10078 /* There can be only one. */
10079 if (sections
->abbrev
.s
.section
!= NULL
)
10081 sections
->abbrev
.s
.section
= sectp
;
10082 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10084 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
10085 || section_is_p (sectp
->name
, &names
->types_dwo
))
10087 /* There can be only one. */
10088 if (sections
->info_or_types
.s
.section
!= NULL
)
10090 sections
->info_or_types
.s
.section
= sectp
;
10091 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
10093 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10095 /* There can be only one. */
10096 if (sections
->line
.s
.section
!= NULL
)
10098 sections
->line
.s
.section
= sectp
;
10099 sections
->line
.size
= bfd_get_section_size (sectp
);
10101 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10103 /* There can be only one. */
10104 if (sections
->loc
.s
.section
!= NULL
)
10106 sections
->loc
.s
.section
= sectp
;
10107 sections
->loc
.size
= bfd_get_section_size (sectp
);
10109 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10111 /* There can be only one. */
10112 if (sections
->macinfo
.s
.section
!= NULL
)
10114 sections
->macinfo
.s
.section
= sectp
;
10115 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10117 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10119 /* There can be only one. */
10120 if (sections
->macro
.s
.section
!= NULL
)
10122 sections
->macro
.s
.section
= sectp
;
10123 sections
->macro
.size
= bfd_get_section_size (sectp
);
10125 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10127 /* There can be only one. */
10128 if (sections
->str_offsets
.s
.section
!= NULL
)
10130 sections
->str_offsets
.s
.section
= sectp
;
10131 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10135 /* No other kind of section is valid. */
10142 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10143 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10144 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10145 This is for DWP version 1 files. */
10147 static struct dwo_unit
*
10148 create_dwo_unit_in_dwp_v1 (struct dwp_file
*dwp_file
,
10149 uint32_t unit_index
,
10150 const char *comp_dir
,
10151 ULONGEST signature
, int is_debug_types
)
10153 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10154 const struct dwp_hash_table
*dwp_htab
=
10155 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10156 bfd
*dbfd
= dwp_file
->dbfd
;
10157 const char *kind
= is_debug_types
? "TU" : "CU";
10158 struct dwo_file
*dwo_file
;
10159 struct dwo_unit
*dwo_unit
;
10160 struct virtual_v1_dwo_sections sections
;
10161 void **dwo_file_slot
;
10162 char *virtual_dwo_name
;
10163 struct cleanup
*cleanups
;
10166 gdb_assert (dwp_file
->version
== 1);
10168 if (dwarf_read_debug
)
10170 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
10172 pulongest (unit_index
), hex_string (signature
),
10176 /* Fetch the sections of this DWO unit.
10177 Put a limit on the number of sections we look for so that bad data
10178 doesn't cause us to loop forever. */
10180 #define MAX_NR_V1_DWO_SECTIONS \
10181 (1 /* .debug_info or .debug_types */ \
10182 + 1 /* .debug_abbrev */ \
10183 + 1 /* .debug_line */ \
10184 + 1 /* .debug_loc */ \
10185 + 1 /* .debug_str_offsets */ \
10186 + 1 /* .debug_macro or .debug_macinfo */ \
10187 + 1 /* trailing zero */)
10189 memset (§ions
, 0, sizeof (sections
));
10190 cleanups
= make_cleanup (null_cleanup
, 0);
10192 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
10195 uint32_t section_nr
=
10196 read_4_bytes (dbfd
,
10197 dwp_htab
->section_pool
.v1
.indices
10198 + (unit_index
+ i
) * sizeof (uint32_t));
10200 if (section_nr
== 0)
10202 if (section_nr
>= dwp_file
->num_sections
)
10204 error (_("Dwarf Error: bad DWP hash table, section number too large"
10205 " [in module %s]"),
10209 sectp
= dwp_file
->elf_sections
[section_nr
];
10210 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
10212 error (_("Dwarf Error: bad DWP hash table, invalid section found"
10213 " [in module %s]"),
10219 || dwarf2_section_empty_p (§ions
.info_or_types
)
10220 || dwarf2_section_empty_p (§ions
.abbrev
))
10222 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
10223 " [in module %s]"),
10226 if (i
== MAX_NR_V1_DWO_SECTIONS
)
10228 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
10229 " [in module %s]"),
10233 /* It's easier for the rest of the code if we fake a struct dwo_file and
10234 have dwo_unit "live" in that. At least for now.
10236 The DWP file can be made up of a random collection of CUs and TUs.
10237 However, for each CU + set of TUs that came from the same original DWO
10238 file, we can combine them back into a virtual DWO file to save space
10239 (fewer struct dwo_file objects to allocate). Remember that for really
10240 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10243 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
10244 get_section_id (§ions
.abbrev
),
10245 get_section_id (§ions
.line
),
10246 get_section_id (§ions
.loc
),
10247 get_section_id (§ions
.str_offsets
));
10248 make_cleanup (xfree
, virtual_dwo_name
);
10249 /* Can we use an existing virtual DWO file? */
10250 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
10251 /* Create one if necessary. */
10252 if (*dwo_file_slot
== NULL
)
10254 if (dwarf_read_debug
)
10256 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10259 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10261 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
10263 strlen (virtual_dwo_name
));
10264 dwo_file
->comp_dir
= comp_dir
;
10265 dwo_file
->sections
.abbrev
= sections
.abbrev
;
10266 dwo_file
->sections
.line
= sections
.line
;
10267 dwo_file
->sections
.loc
= sections
.loc
;
10268 dwo_file
->sections
.macinfo
= sections
.macinfo
;
10269 dwo_file
->sections
.macro
= sections
.macro
;
10270 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
10271 /* The "str" section is global to the entire DWP file. */
10272 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10273 /* The info or types section is assigned below to dwo_unit,
10274 there's no need to record it in dwo_file.
10275 Also, we can't simply record type sections in dwo_file because
10276 we record a pointer into the vector in dwo_unit. As we collect more
10277 types we'll grow the vector and eventually have to reallocate space
10278 for it, invalidating all copies of pointers into the previous
10280 *dwo_file_slot
= dwo_file
;
10284 if (dwarf_read_debug
)
10286 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10289 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10291 do_cleanups (cleanups
);
10293 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10294 dwo_unit
->dwo_file
= dwo_file
;
10295 dwo_unit
->signature
= signature
;
10296 dwo_unit
->section
=
10297 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
10298 *dwo_unit
->section
= sections
.info_or_types
;
10299 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10304 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
10305 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
10306 piece within that section used by a TU/CU, return a virtual section
10307 of just that piece. */
10309 static struct dwarf2_section_info
10310 create_dwp_v2_section (struct dwarf2_section_info
*section
,
10311 bfd_size_type offset
, bfd_size_type size
)
10313 struct dwarf2_section_info result
;
10316 gdb_assert (section
!= NULL
);
10317 gdb_assert (!section
->is_virtual
);
10319 memset (&result
, 0, sizeof (result
));
10320 result
.s
.containing_section
= section
;
10321 result
.is_virtual
= 1;
10326 sectp
= get_section_bfd_section (section
);
10328 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
10329 bounds of the real section. This is a pretty-rare event, so just
10330 flag an error (easier) instead of a warning and trying to cope. */
10332 || offset
+ size
> bfd_get_section_size (sectp
))
10334 bfd
*abfd
= sectp
->owner
;
10336 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
10337 " in section %s [in module %s]"),
10338 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
10339 objfile_name (dwarf2_per_objfile
->objfile
));
10342 result
.virtual_offset
= offset
;
10343 result
.size
= size
;
10347 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10348 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10349 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10350 This is for DWP version 2 files. */
10352 static struct dwo_unit
*
10353 create_dwo_unit_in_dwp_v2 (struct dwp_file
*dwp_file
,
10354 uint32_t unit_index
,
10355 const char *comp_dir
,
10356 ULONGEST signature
, int is_debug_types
)
10358 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10359 const struct dwp_hash_table
*dwp_htab
=
10360 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10361 bfd
*dbfd
= dwp_file
->dbfd
;
10362 const char *kind
= is_debug_types
? "TU" : "CU";
10363 struct dwo_file
*dwo_file
;
10364 struct dwo_unit
*dwo_unit
;
10365 struct virtual_v2_dwo_sections sections
;
10366 void **dwo_file_slot
;
10367 char *virtual_dwo_name
;
10368 struct cleanup
*cleanups
;
10371 gdb_assert (dwp_file
->version
== 2);
10373 if (dwarf_read_debug
)
10375 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
10377 pulongest (unit_index
), hex_string (signature
),
10381 /* Fetch the section offsets of this DWO unit. */
10383 memset (§ions
, 0, sizeof (sections
));
10384 cleanups
= make_cleanup (null_cleanup
, 0);
10386 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
10388 uint32_t offset
= read_4_bytes (dbfd
,
10389 dwp_htab
->section_pool
.v2
.offsets
10390 + (((unit_index
- 1) * dwp_htab
->nr_columns
10392 * sizeof (uint32_t)));
10393 uint32_t size
= read_4_bytes (dbfd
,
10394 dwp_htab
->section_pool
.v2
.sizes
10395 + (((unit_index
- 1) * dwp_htab
->nr_columns
10397 * sizeof (uint32_t)));
10399 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
10402 case DW_SECT_TYPES
:
10403 sections
.info_or_types_offset
= offset
;
10404 sections
.info_or_types_size
= size
;
10406 case DW_SECT_ABBREV
:
10407 sections
.abbrev_offset
= offset
;
10408 sections
.abbrev_size
= size
;
10411 sections
.line_offset
= offset
;
10412 sections
.line_size
= size
;
10415 sections
.loc_offset
= offset
;
10416 sections
.loc_size
= size
;
10418 case DW_SECT_STR_OFFSETS
:
10419 sections
.str_offsets_offset
= offset
;
10420 sections
.str_offsets_size
= size
;
10422 case DW_SECT_MACINFO
:
10423 sections
.macinfo_offset
= offset
;
10424 sections
.macinfo_size
= size
;
10426 case DW_SECT_MACRO
:
10427 sections
.macro_offset
= offset
;
10428 sections
.macro_size
= size
;
10433 /* It's easier for the rest of the code if we fake a struct dwo_file and
10434 have dwo_unit "live" in that. At least for now.
10436 The DWP file can be made up of a random collection of CUs and TUs.
10437 However, for each CU + set of TUs that came from the same original DWO
10438 file, we can combine them back into a virtual DWO file to save space
10439 (fewer struct dwo_file objects to allocate). Remember that for really
10440 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10443 xstrprintf ("virtual-dwo/%ld-%ld-%ld-%ld",
10444 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
10445 (long) (sections
.line_size
? sections
.line_offset
: 0),
10446 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
10447 (long) (sections
.str_offsets_size
10448 ? sections
.str_offsets_offset
: 0));
10449 make_cleanup (xfree
, virtual_dwo_name
);
10450 /* Can we use an existing virtual DWO file? */
10451 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
10452 /* Create one if necessary. */
10453 if (*dwo_file_slot
== NULL
)
10455 if (dwarf_read_debug
)
10457 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10460 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10462 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
10464 strlen (virtual_dwo_name
));
10465 dwo_file
->comp_dir
= comp_dir
;
10466 dwo_file
->sections
.abbrev
=
10467 create_dwp_v2_section (&dwp_file
->sections
.abbrev
,
10468 sections
.abbrev_offset
, sections
.abbrev_size
);
10469 dwo_file
->sections
.line
=
10470 create_dwp_v2_section (&dwp_file
->sections
.line
,
10471 sections
.line_offset
, sections
.line_size
);
10472 dwo_file
->sections
.loc
=
10473 create_dwp_v2_section (&dwp_file
->sections
.loc
,
10474 sections
.loc_offset
, sections
.loc_size
);
10475 dwo_file
->sections
.macinfo
=
10476 create_dwp_v2_section (&dwp_file
->sections
.macinfo
,
10477 sections
.macinfo_offset
, sections
.macinfo_size
);
10478 dwo_file
->sections
.macro
=
10479 create_dwp_v2_section (&dwp_file
->sections
.macro
,
10480 sections
.macro_offset
, sections
.macro_size
);
10481 dwo_file
->sections
.str_offsets
=
10482 create_dwp_v2_section (&dwp_file
->sections
.str_offsets
,
10483 sections
.str_offsets_offset
,
10484 sections
.str_offsets_size
);
10485 /* The "str" section is global to the entire DWP file. */
10486 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10487 /* The info or types section is assigned below to dwo_unit,
10488 there's no need to record it in dwo_file.
10489 Also, we can't simply record type sections in dwo_file because
10490 we record a pointer into the vector in dwo_unit. As we collect more
10491 types we'll grow the vector and eventually have to reallocate space
10492 for it, invalidating all copies of pointers into the previous
10494 *dwo_file_slot
= dwo_file
;
10498 if (dwarf_read_debug
)
10500 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10503 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10505 do_cleanups (cleanups
);
10507 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10508 dwo_unit
->dwo_file
= dwo_file
;
10509 dwo_unit
->signature
= signature
;
10510 dwo_unit
->section
=
10511 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
10512 *dwo_unit
->section
= create_dwp_v2_section (is_debug_types
10513 ? &dwp_file
->sections
.types
10514 : &dwp_file
->sections
.info
,
10515 sections
.info_or_types_offset
,
10516 sections
.info_or_types_size
);
10517 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10522 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
10523 Returns NULL if the signature isn't found. */
10525 static struct dwo_unit
*
10526 lookup_dwo_unit_in_dwp (struct dwp_file
*dwp_file
, const char *comp_dir
,
10527 ULONGEST signature
, int is_debug_types
)
10529 const struct dwp_hash_table
*dwp_htab
=
10530 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10531 bfd
*dbfd
= dwp_file
->dbfd
;
10532 uint32_t mask
= dwp_htab
->nr_slots
- 1;
10533 uint32_t hash
= signature
& mask
;
10534 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
10537 struct dwo_unit find_dwo_cu
;
10539 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
10540 find_dwo_cu
.signature
= signature
;
10541 slot
= htab_find_slot (is_debug_types
10542 ? dwp_file
->loaded_tus
10543 : dwp_file
->loaded_cus
,
10544 &find_dwo_cu
, INSERT
);
10547 return (struct dwo_unit
*) *slot
;
10549 /* Use a for loop so that we don't loop forever on bad debug info. */
10550 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
10552 ULONGEST signature_in_table
;
10554 signature_in_table
=
10555 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
10556 if (signature_in_table
== signature
)
10558 uint32_t unit_index
=
10559 read_4_bytes (dbfd
,
10560 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
10562 if (dwp_file
->version
== 1)
10564 *slot
= create_dwo_unit_in_dwp_v1 (dwp_file
, unit_index
,
10565 comp_dir
, signature
,
10570 *slot
= create_dwo_unit_in_dwp_v2 (dwp_file
, unit_index
,
10571 comp_dir
, signature
,
10574 return (struct dwo_unit
*) *slot
;
10576 if (signature_in_table
== 0)
10578 hash
= (hash
+ hash2
) & mask
;
10581 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
10582 " [in module %s]"),
10586 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
10587 Open the file specified by FILE_NAME and hand it off to BFD for
10588 preliminary analysis. Return a newly initialized bfd *, which
10589 includes a canonicalized copy of FILE_NAME.
10590 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
10591 SEARCH_CWD is true if the current directory is to be searched.
10592 It will be searched before debug-file-directory.
10593 If successful, the file is added to the bfd include table of the
10594 objfile's bfd (see gdb_bfd_record_inclusion).
10595 If unable to find/open the file, return NULL.
10596 NOTE: This function is derived from symfile_bfd_open. */
10598 static gdb_bfd_ref_ptr
10599 try_open_dwop_file (const char *file_name
, int is_dwp
, int search_cwd
)
10602 char *absolute_name
;
10603 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
10604 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
10605 to debug_file_directory. */
10607 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
10611 if (*debug_file_directory
!= '\0')
10612 search_path
= concat (".", dirname_separator_string
,
10613 debug_file_directory
, (char *) NULL
);
10615 search_path
= xstrdup (".");
10618 search_path
= xstrdup (debug_file_directory
);
10620 flags
= OPF_RETURN_REALPATH
;
10622 flags
|= OPF_SEARCH_IN_PATH
;
10623 desc
= openp (search_path
, flags
, file_name
,
10624 O_RDONLY
| O_BINARY
, &absolute_name
);
10625 xfree (search_path
);
10629 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
, gnutarget
, desc
));
10630 xfree (absolute_name
);
10631 if (sym_bfd
== NULL
)
10633 bfd_set_cacheable (sym_bfd
.get (), 1);
10635 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
10638 /* Success. Record the bfd as having been included by the objfile's bfd.
10639 This is important because things like demangled_names_hash lives in the
10640 objfile's per_bfd space and may have references to things like symbol
10641 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
10642 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
10647 /* Try to open DWO file FILE_NAME.
10648 COMP_DIR is the DW_AT_comp_dir attribute.
10649 The result is the bfd handle of the file.
10650 If there is a problem finding or opening the file, return NULL.
10651 Upon success, the canonicalized path of the file is stored in the bfd,
10652 same as symfile_bfd_open. */
10654 static gdb_bfd_ref_ptr
10655 open_dwo_file (const char *file_name
, const char *comp_dir
)
10657 if (IS_ABSOLUTE_PATH (file_name
))
10658 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 0 /*search_cwd*/);
10660 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
10662 if (comp_dir
!= NULL
)
10664 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
10665 file_name
, (char *) NULL
);
10667 /* NOTE: If comp_dir is a relative path, this will also try the
10668 search path, which seems useful. */
10669 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (path_to_try
, 0 /*is_dwp*/,
10670 1 /*search_cwd*/));
10671 xfree (path_to_try
);
10676 /* That didn't work, try debug-file-directory, which, despite its name,
10677 is a list of paths. */
10679 if (*debug_file_directory
== '\0')
10682 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 1 /*search_cwd*/);
10685 /* This function is mapped across the sections and remembers the offset and
10686 size of each of the DWO debugging sections we are interested in. */
10689 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
10691 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
10692 const struct dwop_section_names
*names
= &dwop_section_names
;
10694 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10696 dwo_sections
->abbrev
.s
.section
= sectp
;
10697 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10699 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10701 dwo_sections
->info
.s
.section
= sectp
;
10702 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
10704 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10706 dwo_sections
->line
.s
.section
= sectp
;
10707 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
10709 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10711 dwo_sections
->loc
.s
.section
= sectp
;
10712 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
10714 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10716 dwo_sections
->macinfo
.s
.section
= sectp
;
10717 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10719 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10721 dwo_sections
->macro
.s
.section
= sectp
;
10722 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
10724 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
10726 dwo_sections
->str
.s
.section
= sectp
;
10727 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
10729 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10731 dwo_sections
->str_offsets
.s
.section
= sectp
;
10732 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10734 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10736 struct dwarf2_section_info type_section
;
10738 memset (&type_section
, 0, sizeof (type_section
));
10739 type_section
.s
.section
= sectp
;
10740 type_section
.size
= bfd_get_section_size (sectp
);
10741 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
10746 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
10747 by PER_CU. This is for the non-DWP case.
10748 The result is NULL if DWO_NAME can't be found. */
10750 static struct dwo_file
*
10751 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
10752 const char *dwo_name
, const char *comp_dir
)
10754 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10755 struct dwo_file
*dwo_file
;
10756 struct cleanup
*cleanups
;
10758 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwo_name
, comp_dir
));
10761 if (dwarf_read_debug
)
10762 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
10765 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10766 dwo_file
->dwo_name
= dwo_name
;
10767 dwo_file
->comp_dir
= comp_dir
;
10768 dwo_file
->dbfd
= dbfd
.release ();
10770 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
10772 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
10773 &dwo_file
->sections
);
10775 create_cus_hash_table (*dwo_file
, dwo_file
->sections
.info
, dwo_file
->cus
);
10777 create_debug_types_hash_table (dwo_file
, dwo_file
->sections
.types
,
10780 discard_cleanups (cleanups
);
10782 if (dwarf_read_debug
)
10783 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
10788 /* This function is mapped across the sections and remembers the offset and
10789 size of each of the DWP debugging sections common to version 1 and 2 that
10790 we are interested in. */
10793 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
10794 void *dwp_file_ptr
)
10796 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
10797 const struct dwop_section_names
*names
= &dwop_section_names
;
10798 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10800 /* Record the ELF section number for later lookup: this is what the
10801 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10802 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10803 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10805 /* Look for specific sections that we need. */
10806 if (section_is_p (sectp
->name
, &names
->str_dwo
))
10808 dwp_file
->sections
.str
.s
.section
= sectp
;
10809 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
10811 else if (section_is_p (sectp
->name
, &names
->cu_index
))
10813 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
10814 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
10816 else if (section_is_p (sectp
->name
, &names
->tu_index
))
10818 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
10819 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
10823 /* This function is mapped across the sections and remembers the offset and
10824 size of each of the DWP version 2 debugging sections that we are interested
10825 in. This is split into a separate function because we don't know if we
10826 have version 1 or 2 until we parse the cu_index/tu_index sections. */
10829 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
10831 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
10832 const struct dwop_section_names
*names
= &dwop_section_names
;
10833 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10835 /* Record the ELF section number for later lookup: this is what the
10836 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10837 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10838 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10840 /* Look for specific sections that we need. */
10841 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10843 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
10844 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
10846 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10848 dwp_file
->sections
.info
.s
.section
= sectp
;
10849 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
10851 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10853 dwp_file
->sections
.line
.s
.section
= sectp
;
10854 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
10856 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10858 dwp_file
->sections
.loc
.s
.section
= sectp
;
10859 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
10861 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10863 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
10864 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
10866 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10868 dwp_file
->sections
.macro
.s
.section
= sectp
;
10869 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
10871 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10873 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
10874 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
10876 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10878 dwp_file
->sections
.types
.s
.section
= sectp
;
10879 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
10883 /* Hash function for dwp_file loaded CUs/TUs. */
10886 hash_dwp_loaded_cutus (const void *item
)
10888 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10890 /* This drops the top 32 bits of the signature, but is ok for a hash. */
10891 return dwo_unit
->signature
;
10894 /* Equality function for dwp_file loaded CUs/TUs. */
10897 eq_dwp_loaded_cutus (const void *a
, const void *b
)
10899 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
10900 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
10902 return dua
->signature
== dub
->signature
;
10905 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
10908 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
10910 return htab_create_alloc_ex (3,
10911 hash_dwp_loaded_cutus
,
10912 eq_dwp_loaded_cutus
,
10914 &objfile
->objfile_obstack
,
10915 hashtab_obstack_allocate
,
10916 dummy_obstack_deallocate
);
10919 /* Try to open DWP file FILE_NAME.
10920 The result is the bfd handle of the file.
10921 If there is a problem finding or opening the file, return NULL.
10922 Upon success, the canonicalized path of the file is stored in the bfd,
10923 same as symfile_bfd_open. */
10925 static gdb_bfd_ref_ptr
10926 open_dwp_file (const char *file_name
)
10928 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (file_name
, 1 /*is_dwp*/,
10929 1 /*search_cwd*/));
10933 /* Work around upstream bug 15652.
10934 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
10935 [Whether that's a "bug" is debatable, but it is getting in our way.]
10936 We have no real idea where the dwp file is, because gdb's realpath-ing
10937 of the executable's path may have discarded the needed info.
10938 [IWBN if the dwp file name was recorded in the executable, akin to
10939 .gnu_debuglink, but that doesn't exist yet.]
10940 Strip the directory from FILE_NAME and search again. */
10941 if (*debug_file_directory
!= '\0')
10943 /* Don't implicitly search the current directory here.
10944 If the user wants to search "." to handle this case,
10945 it must be added to debug-file-directory. */
10946 return try_open_dwop_file (lbasename (file_name
), 1 /*is_dwp*/,
10953 /* Initialize the use of the DWP file for the current objfile.
10954 By convention the name of the DWP file is ${objfile}.dwp.
10955 The result is NULL if it can't be found. */
10957 static struct dwp_file
*
10958 open_and_init_dwp_file (void)
10960 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10961 struct dwp_file
*dwp_file
;
10963 /* Try to find first .dwp for the binary file before any symbolic links
10966 /* If the objfile is a debug file, find the name of the real binary
10967 file and get the name of dwp file from there. */
10968 std::string dwp_name
;
10969 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
10971 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
10972 const char *backlink_basename
= lbasename (backlink
->original_name
);
10974 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
10977 dwp_name
= objfile
->original_name
;
10979 dwp_name
+= ".dwp";
10981 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwp_name
.c_str ()));
10983 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
10985 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
10986 dwp_name
= objfile_name (objfile
);
10987 dwp_name
+= ".dwp";
10988 dbfd
= open_dwp_file (dwp_name
.c_str ());
10993 if (dwarf_read_debug
)
10994 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
10997 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
10998 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
10999 dwp_file
->dbfd
= dbfd
.release ();
11001 /* +1: section 0 is unused */
11002 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
11003 dwp_file
->elf_sections
=
11004 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
11005 dwp_file
->num_sections
, asection
*);
11007 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
11010 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
11012 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
11014 /* The DWP file version is stored in the hash table. Oh well. */
11015 if (dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
11017 /* Technically speaking, we should try to limp along, but this is
11018 pretty bizarre. We use pulongest here because that's the established
11019 portability solution (e.g, we cannot use %u for uint32_t). */
11020 error (_("Dwarf Error: DWP file CU version %s doesn't match"
11021 " TU version %s [in DWP file %s]"),
11022 pulongest (dwp_file
->cus
->version
),
11023 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
11025 dwp_file
->version
= dwp_file
->cus
->version
;
11027 if (dwp_file
->version
== 2)
11028 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
11031 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
11032 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
11034 if (dwarf_read_debug
)
11036 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
11037 fprintf_unfiltered (gdb_stdlog
,
11038 " %s CUs, %s TUs\n",
11039 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
11040 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
11046 /* Wrapper around open_and_init_dwp_file, only open it once. */
11048 static struct dwp_file
*
11049 get_dwp_file (void)
11051 if (! dwarf2_per_objfile
->dwp_checked
)
11053 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file ();
11054 dwarf2_per_objfile
->dwp_checked
= 1;
11056 return dwarf2_per_objfile
->dwp_file
;
11059 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
11060 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
11061 or in the DWP file for the objfile, referenced by THIS_UNIT.
11062 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
11063 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
11065 This is called, for example, when wanting to read a variable with a
11066 complex location. Therefore we don't want to do file i/o for every call.
11067 Therefore we don't want to look for a DWO file on every call.
11068 Therefore we first see if we've already seen SIGNATURE in a DWP file,
11069 then we check if we've already seen DWO_NAME, and only THEN do we check
11072 The result is a pointer to the dwo_unit object or NULL if we didn't find it
11073 (dwo_id mismatch or couldn't find the DWO/DWP file). */
11075 static struct dwo_unit
*
11076 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
11077 const char *dwo_name
, const char *comp_dir
,
11078 ULONGEST signature
, int is_debug_types
)
11080 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11081 const char *kind
= is_debug_types
? "TU" : "CU";
11082 void **dwo_file_slot
;
11083 struct dwo_file
*dwo_file
;
11084 struct dwp_file
*dwp_file
;
11086 /* First see if there's a DWP file.
11087 If we have a DWP file but didn't find the DWO inside it, don't
11088 look for the original DWO file. It makes gdb behave differently
11089 depending on whether one is debugging in the build tree. */
11091 dwp_file
= get_dwp_file ();
11092 if (dwp_file
!= NULL
)
11094 const struct dwp_hash_table
*dwp_htab
=
11095 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11097 if (dwp_htab
!= NULL
)
11099 struct dwo_unit
*dwo_cutu
=
11100 lookup_dwo_unit_in_dwp (dwp_file
, comp_dir
,
11101 signature
, is_debug_types
);
11103 if (dwo_cutu
!= NULL
)
11105 if (dwarf_read_debug
)
11107 fprintf_unfiltered (gdb_stdlog
,
11108 "Virtual DWO %s %s found: @%s\n",
11109 kind
, hex_string (signature
),
11110 host_address_to_string (dwo_cutu
));
11118 /* No DWP file, look for the DWO file. */
11120 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
, comp_dir
);
11121 if (*dwo_file_slot
== NULL
)
11123 /* Read in the file and build a table of the CUs/TUs it contains. */
11124 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
11126 /* NOTE: This will be NULL if unable to open the file. */
11127 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11129 if (dwo_file
!= NULL
)
11131 struct dwo_unit
*dwo_cutu
= NULL
;
11133 if (is_debug_types
&& dwo_file
->tus
)
11135 struct dwo_unit find_dwo_cutu
;
11137 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
11138 find_dwo_cutu
.signature
= signature
;
11140 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
11142 else if (!is_debug_types
&& dwo_file
->cus
)
11144 struct dwo_unit find_dwo_cutu
;
11146 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
11147 find_dwo_cutu
.signature
= signature
;
11148 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
11152 if (dwo_cutu
!= NULL
)
11154 if (dwarf_read_debug
)
11156 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
11157 kind
, dwo_name
, hex_string (signature
),
11158 host_address_to_string (dwo_cutu
));
11165 /* We didn't find it. This could mean a dwo_id mismatch, or
11166 someone deleted the DWO/DWP file, or the search path isn't set up
11167 correctly to find the file. */
11169 if (dwarf_read_debug
)
11171 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
11172 kind
, dwo_name
, hex_string (signature
));
11175 /* This is a warning and not a complaint because it can be caused by
11176 pilot error (e.g., user accidentally deleting the DWO). */
11178 /* Print the name of the DWP file if we looked there, helps the user
11179 better diagnose the problem. */
11180 char *dwp_text
= NULL
;
11181 struct cleanup
*cleanups
;
11183 if (dwp_file
!= NULL
)
11184 dwp_text
= xstrprintf (" [in DWP file %s]", lbasename (dwp_file
->name
));
11185 cleanups
= make_cleanup (xfree
, dwp_text
);
11187 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset 0x%x"
11188 " [in module %s]"),
11189 kind
, dwo_name
, hex_string (signature
),
11190 dwp_text
!= NULL
? dwp_text
: "",
11191 this_unit
->is_debug_types
? "TU" : "CU",
11192 to_underlying (this_unit
->sect_off
), objfile_name (objfile
));
11194 do_cleanups (cleanups
);
11199 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
11200 See lookup_dwo_cutu_unit for details. */
11202 static struct dwo_unit
*
11203 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
11204 const char *dwo_name
, const char *comp_dir
,
11205 ULONGEST signature
)
11207 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
11210 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
11211 See lookup_dwo_cutu_unit for details. */
11213 static struct dwo_unit
*
11214 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
11215 const char *dwo_name
, const char *comp_dir
)
11217 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
11220 /* Traversal function for queue_and_load_all_dwo_tus. */
11223 queue_and_load_dwo_tu (void **slot
, void *info
)
11225 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
11226 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
11227 ULONGEST signature
= dwo_unit
->signature
;
11228 struct signatured_type
*sig_type
=
11229 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
11231 if (sig_type
!= NULL
)
11233 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
11235 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
11236 a real dependency of PER_CU on SIG_TYPE. That is detected later
11237 while processing PER_CU. */
11238 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
11239 load_full_type_unit (sig_cu
);
11240 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
11246 /* Queue all TUs contained in the DWO of PER_CU to be read in.
11247 The DWO may have the only definition of the type, though it may not be
11248 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
11249 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
11252 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
11254 struct dwo_unit
*dwo_unit
;
11255 struct dwo_file
*dwo_file
;
11257 gdb_assert (!per_cu
->is_debug_types
);
11258 gdb_assert (get_dwp_file () == NULL
);
11259 gdb_assert (per_cu
->cu
!= NULL
);
11261 dwo_unit
= per_cu
->cu
->dwo_unit
;
11262 gdb_assert (dwo_unit
!= NULL
);
11264 dwo_file
= dwo_unit
->dwo_file
;
11265 if (dwo_file
->tus
!= NULL
)
11266 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
11269 /* Free all resources associated with DWO_FILE.
11270 Close the DWO file and munmap the sections.
11271 All memory should be on the objfile obstack. */
11274 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
11277 /* Note: dbfd is NULL for virtual DWO files. */
11278 gdb_bfd_unref (dwo_file
->dbfd
);
11280 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
11283 /* Wrapper for free_dwo_file for use in cleanups. */
11286 free_dwo_file_cleanup (void *arg
)
11288 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
11289 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11291 free_dwo_file (dwo_file
, objfile
);
11294 /* Traversal function for free_dwo_files. */
11297 free_dwo_file_from_slot (void **slot
, void *info
)
11299 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
11300 struct objfile
*objfile
= (struct objfile
*) info
;
11302 free_dwo_file (dwo_file
, objfile
);
11307 /* Free all resources associated with DWO_FILES. */
11310 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
11312 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
11315 /* Read in various DIEs. */
11317 /* qsort helper for inherit_abstract_dies. */
11320 unsigned_int_compar (const void *ap
, const void *bp
)
11322 unsigned int a
= *(unsigned int *) ap
;
11323 unsigned int b
= *(unsigned int *) bp
;
11325 return (a
> b
) - (b
> a
);
11328 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
11329 Inherit only the children of the DW_AT_abstract_origin DIE not being
11330 already referenced by DW_AT_abstract_origin from the children of the
11334 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
11336 struct die_info
*child_die
;
11337 unsigned die_children_count
;
11338 /* CU offsets which were referenced by children of the current DIE. */
11339 sect_offset
*offsets
;
11340 sect_offset
*offsets_end
, *offsetp
;
11341 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
11342 struct die_info
*origin_die
;
11343 /* Iterator of the ORIGIN_DIE children. */
11344 struct die_info
*origin_child_die
;
11345 struct cleanup
*cleanups
;
11346 struct attribute
*attr
;
11347 struct dwarf2_cu
*origin_cu
;
11348 struct pending
**origin_previous_list_in_scope
;
11350 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11354 /* Note that following die references may follow to a die in a
11358 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
11360 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
11362 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
11363 origin_cu
->list_in_scope
= cu
->list_in_scope
;
11365 if (die
->tag
!= origin_die
->tag
11366 && !(die
->tag
== DW_TAG_inlined_subroutine
11367 && origin_die
->tag
== DW_TAG_subprogram
))
11368 complaint (&symfile_complaints
,
11369 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
11370 to_underlying (die
->sect_off
),
11371 to_underlying (origin_die
->sect_off
));
11373 child_die
= die
->child
;
11374 die_children_count
= 0;
11375 while (child_die
&& child_die
->tag
)
11377 child_die
= sibling_die (child_die
);
11378 die_children_count
++;
11380 offsets
= XNEWVEC (sect_offset
, die_children_count
);
11381 cleanups
= make_cleanup (xfree
, offsets
);
11383 offsets_end
= offsets
;
11384 for (child_die
= die
->child
;
11385 child_die
&& child_die
->tag
;
11386 child_die
= sibling_die (child_die
))
11388 struct die_info
*child_origin_die
;
11389 struct dwarf2_cu
*child_origin_cu
;
11391 /* We are trying to process concrete instance entries:
11392 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
11393 it's not relevant to our analysis here. i.e. detecting DIEs that are
11394 present in the abstract instance but not referenced in the concrete
11396 if (child_die
->tag
== DW_TAG_call_site
11397 || child_die
->tag
== DW_TAG_GNU_call_site
)
11400 /* For each CHILD_DIE, find the corresponding child of
11401 ORIGIN_DIE. If there is more than one layer of
11402 DW_AT_abstract_origin, follow them all; there shouldn't be,
11403 but GCC versions at least through 4.4 generate this (GCC PR
11405 child_origin_die
= child_die
;
11406 child_origin_cu
= cu
;
11409 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
11413 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
11417 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
11418 counterpart may exist. */
11419 if (child_origin_die
!= child_die
)
11421 if (child_die
->tag
!= child_origin_die
->tag
11422 && !(child_die
->tag
== DW_TAG_inlined_subroutine
11423 && child_origin_die
->tag
== DW_TAG_subprogram
))
11424 complaint (&symfile_complaints
,
11425 _("Child DIE 0x%x and its abstract origin 0x%x have "
11427 to_underlying (child_die
->sect_off
),
11428 to_underlying (child_origin_die
->sect_off
));
11429 if (child_origin_die
->parent
!= origin_die
)
11430 complaint (&symfile_complaints
,
11431 _("Child DIE 0x%x and its abstract origin 0x%x have "
11432 "different parents"),
11433 to_underlying (child_die
->sect_off
),
11434 to_underlying (child_origin_die
->sect_off
));
11436 *offsets_end
++ = child_origin_die
->sect_off
;
11439 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
11440 unsigned_int_compar
);
11441 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
11442 if (offsetp
[-1] == *offsetp
)
11443 complaint (&symfile_complaints
,
11444 _("Multiple children of DIE 0x%x refer "
11445 "to DIE 0x%x as their abstract origin"),
11446 to_underlying (die
->sect_off
), to_underlying (*offsetp
));
11449 origin_child_die
= origin_die
->child
;
11450 while (origin_child_die
&& origin_child_die
->tag
)
11452 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
11453 while (offsetp
< offsets_end
11454 && *offsetp
< origin_child_die
->sect_off
)
11456 if (offsetp
>= offsets_end
11457 || *offsetp
> origin_child_die
->sect_off
)
11459 /* Found that ORIGIN_CHILD_DIE is really not referenced.
11460 Check whether we're already processing ORIGIN_CHILD_DIE.
11461 This can happen with mutually referenced abstract_origins.
11463 if (!origin_child_die
->in_process
)
11464 process_die (origin_child_die
, origin_cu
);
11466 origin_child_die
= sibling_die (origin_child_die
);
11468 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
11470 do_cleanups (cleanups
);
11474 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11476 struct objfile
*objfile
= cu
->objfile
;
11477 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11478 struct context_stack
*newobj
;
11481 struct die_info
*child_die
;
11482 struct attribute
*attr
, *call_line
, *call_file
;
11484 CORE_ADDR baseaddr
;
11485 struct block
*block
;
11486 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11487 VEC (symbolp
) *template_args
= NULL
;
11488 struct template_symbol
*templ_func
= NULL
;
11492 /* If we do not have call site information, we can't show the
11493 caller of this inlined function. That's too confusing, so
11494 only use the scope for local variables. */
11495 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
11496 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
11497 if (call_line
== NULL
|| call_file
== NULL
)
11499 read_lexical_block_scope (die
, cu
);
11504 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11506 name
= dwarf2_name (die
, cu
);
11508 /* Ignore functions with missing or empty names. These are actually
11509 illegal according to the DWARF standard. */
11512 complaint (&symfile_complaints
,
11513 _("missing name for subprogram DIE at %d"),
11514 to_underlying (die
->sect_off
));
11518 /* Ignore functions with missing or invalid low and high pc attributes. */
11519 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
11520 <= PC_BOUNDS_INVALID
)
11522 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
11523 if (!attr
|| !DW_UNSND (attr
))
11524 complaint (&symfile_complaints
,
11525 _("cannot get low and high bounds "
11526 "for subprogram DIE at %d"),
11527 to_underlying (die
->sect_off
));
11531 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11532 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11534 /* If we have any template arguments, then we must allocate a
11535 different sort of symbol. */
11536 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
11538 if (child_die
->tag
== DW_TAG_template_type_param
11539 || child_die
->tag
== DW_TAG_template_value_param
)
11541 templ_func
= allocate_template_symbol (objfile
);
11542 templ_func
->base
.is_cplus_template_function
= 1;
11547 newobj
= push_context (0, lowpc
);
11548 newobj
->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
11549 (struct symbol
*) templ_func
);
11551 /* If there is a location expression for DW_AT_frame_base, record
11553 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
11555 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
11557 /* If there is a location for the static link, record it. */
11558 newobj
->static_link
= NULL
;
11559 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
11562 newobj
->static_link
11563 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
11564 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
11567 cu
->list_in_scope
= &local_symbols
;
11569 if (die
->child
!= NULL
)
11571 child_die
= die
->child
;
11572 while (child_die
&& child_die
->tag
)
11574 if (child_die
->tag
== DW_TAG_template_type_param
11575 || child_die
->tag
== DW_TAG_template_value_param
)
11577 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
11580 VEC_safe_push (symbolp
, template_args
, arg
);
11583 process_die (child_die
, cu
);
11584 child_die
= sibling_die (child_die
);
11588 inherit_abstract_dies (die
, cu
);
11590 /* If we have a DW_AT_specification, we might need to import using
11591 directives from the context of the specification DIE. See the
11592 comment in determine_prefix. */
11593 if (cu
->language
== language_cplus
11594 && dwarf2_attr (die
, DW_AT_specification
, cu
))
11596 struct dwarf2_cu
*spec_cu
= cu
;
11597 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
11601 child_die
= spec_die
->child
;
11602 while (child_die
&& child_die
->tag
)
11604 if (child_die
->tag
== DW_TAG_imported_module
)
11605 process_die (child_die
, spec_cu
);
11606 child_die
= sibling_die (child_die
);
11609 /* In some cases, GCC generates specification DIEs that
11610 themselves contain DW_AT_specification attributes. */
11611 spec_die
= die_specification (spec_die
, &spec_cu
);
11615 newobj
= pop_context ();
11616 /* Make a block for the local symbols within. */
11617 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
11618 newobj
->static_link
, lowpc
, highpc
);
11620 /* For C++, set the block's scope. */
11621 if ((cu
->language
== language_cplus
11622 || cu
->language
== language_fortran
11623 || cu
->language
== language_d
11624 || cu
->language
== language_rust
)
11625 && cu
->processing_has_namespace_info
)
11626 block_set_scope (block
, determine_prefix (die
, cu
),
11627 &objfile
->objfile_obstack
);
11629 /* If we have address ranges, record them. */
11630 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11632 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
11634 /* Attach template arguments to function. */
11635 if (! VEC_empty (symbolp
, template_args
))
11637 gdb_assert (templ_func
!= NULL
);
11639 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
11640 templ_func
->template_arguments
11641 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
11642 templ_func
->n_template_arguments
);
11643 memcpy (templ_func
->template_arguments
,
11644 VEC_address (symbolp
, template_args
),
11645 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
11646 VEC_free (symbolp
, template_args
);
11649 /* In C++, we can have functions nested inside functions (e.g., when
11650 a function declares a class that has methods). This means that
11651 when we finish processing a function scope, we may need to go
11652 back to building a containing block's symbol lists. */
11653 local_symbols
= newobj
->locals
;
11654 local_using_directives
= newobj
->local_using_directives
;
11656 /* If we've finished processing a top-level function, subsequent
11657 symbols go in the file symbol list. */
11658 if (outermost_context_p ())
11659 cu
->list_in_scope
= &file_symbols
;
11662 /* Process all the DIES contained within a lexical block scope. Start
11663 a new scope, process the dies, and then close the scope. */
11666 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11668 struct objfile
*objfile
= cu
->objfile
;
11669 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11670 struct context_stack
*newobj
;
11671 CORE_ADDR lowpc
, highpc
;
11672 struct die_info
*child_die
;
11673 CORE_ADDR baseaddr
;
11675 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11677 /* Ignore blocks with missing or invalid low and high pc attributes. */
11678 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
11679 as multiple lexical blocks? Handling children in a sane way would
11680 be nasty. Might be easier to properly extend generic blocks to
11681 describe ranges. */
11682 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
11684 case PC_BOUNDS_NOT_PRESENT
:
11685 /* DW_TAG_lexical_block has no attributes, process its children as if
11686 there was no wrapping by that DW_TAG_lexical_block.
11687 GCC does no longer produces such DWARF since GCC r224161. */
11688 for (child_die
= die
->child
;
11689 child_die
!= NULL
&& child_die
->tag
;
11690 child_die
= sibling_die (child_die
))
11691 process_die (child_die
, cu
);
11693 case PC_BOUNDS_INVALID
:
11696 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11697 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11699 push_context (0, lowpc
);
11700 if (die
->child
!= NULL
)
11702 child_die
= die
->child
;
11703 while (child_die
&& child_die
->tag
)
11705 process_die (child_die
, cu
);
11706 child_die
= sibling_die (child_die
);
11709 inherit_abstract_dies (die
, cu
);
11710 newobj
= pop_context ();
11712 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
11714 struct block
*block
11715 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
11716 newobj
->start_addr
, highpc
);
11718 /* Note that recording ranges after traversing children, as we
11719 do here, means that recording a parent's ranges entails
11720 walking across all its children's ranges as they appear in
11721 the address map, which is quadratic behavior.
11723 It would be nicer to record the parent's ranges before
11724 traversing its children, simply overriding whatever you find
11725 there. But since we don't even decide whether to create a
11726 block until after we've traversed its children, that's hard
11728 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11730 local_symbols
= newobj
->locals
;
11731 local_using_directives
= newobj
->local_using_directives
;
11734 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
11737 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11739 struct objfile
*objfile
= cu
->objfile
;
11740 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11741 CORE_ADDR pc
, baseaddr
;
11742 struct attribute
*attr
;
11743 struct call_site
*call_site
, call_site_local
;
11746 struct die_info
*child_die
;
11748 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11750 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
11753 /* This was a pre-DWARF-5 GNU extension alias
11754 for DW_AT_call_return_pc. */
11755 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11759 complaint (&symfile_complaints
,
11760 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
11761 "DIE 0x%x [in module %s]"),
11762 to_underlying (die
->sect_off
), objfile_name (objfile
));
11765 pc
= attr_value_as_address (attr
) + baseaddr
;
11766 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
11768 if (cu
->call_site_htab
== NULL
)
11769 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
11770 NULL
, &objfile
->objfile_obstack
,
11771 hashtab_obstack_allocate
, NULL
);
11772 call_site_local
.pc
= pc
;
11773 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
11776 complaint (&symfile_complaints
,
11777 _("Duplicate PC %s for DW_TAG_call_site "
11778 "DIE 0x%x [in module %s]"),
11779 paddress (gdbarch
, pc
), to_underlying (die
->sect_off
),
11780 objfile_name (objfile
));
11784 /* Count parameters at the caller. */
11787 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11788 child_die
= sibling_die (child_die
))
11790 if (child_die
->tag
!= DW_TAG_call_site_parameter
11791 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11793 complaint (&symfile_complaints
,
11794 _("Tag %d is not DW_TAG_call_site_parameter in "
11795 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
11796 child_die
->tag
, to_underlying (child_die
->sect_off
),
11797 objfile_name (objfile
));
11805 = ((struct call_site
*)
11806 obstack_alloc (&objfile
->objfile_obstack
,
11807 sizeof (*call_site
)
11808 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
11810 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
11811 call_site
->pc
= pc
;
11813 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
11814 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
11816 struct die_info
*func_die
;
11818 /* Skip also over DW_TAG_inlined_subroutine. */
11819 for (func_die
= die
->parent
;
11820 func_die
&& func_die
->tag
!= DW_TAG_subprogram
11821 && func_die
->tag
!= DW_TAG_subroutine_type
;
11822 func_die
= func_die
->parent
);
11824 /* DW_AT_call_all_calls is a superset
11825 of DW_AT_call_all_tail_calls. */
11827 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
11828 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
11829 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
11830 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
11832 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
11833 not complete. But keep CALL_SITE for look ups via call_site_htab,
11834 both the initial caller containing the real return address PC and
11835 the final callee containing the current PC of a chain of tail
11836 calls do not need to have the tail call list complete. But any
11837 function candidate for a virtual tail call frame searched via
11838 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
11839 determined unambiguously. */
11843 struct type
*func_type
= NULL
;
11846 func_type
= get_die_type (func_die
, cu
);
11847 if (func_type
!= NULL
)
11849 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
11851 /* Enlist this call site to the function. */
11852 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
11853 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
11856 complaint (&symfile_complaints
,
11857 _("Cannot find function owning DW_TAG_call_site "
11858 "DIE 0x%x [in module %s]"),
11859 to_underlying (die
->sect_off
), objfile_name (objfile
));
11863 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
11865 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
11867 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
11870 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
11871 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11873 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
11874 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
11875 /* Keep NULL DWARF_BLOCK. */;
11876 else if (attr_form_is_block (attr
))
11878 struct dwarf2_locexpr_baton
*dlbaton
;
11880 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
11881 dlbaton
->data
= DW_BLOCK (attr
)->data
;
11882 dlbaton
->size
= DW_BLOCK (attr
)->size
;
11883 dlbaton
->per_cu
= cu
->per_cu
;
11885 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
11887 else if (attr_form_is_ref (attr
))
11889 struct dwarf2_cu
*target_cu
= cu
;
11890 struct die_info
*target_die
;
11892 target_die
= follow_die_ref (die
, attr
, &target_cu
);
11893 gdb_assert (target_cu
->objfile
== objfile
);
11894 if (die_is_declaration (target_die
, target_cu
))
11896 const char *target_physname
;
11898 /* Prefer the mangled name; otherwise compute the demangled one. */
11899 target_physname
= dwarf2_string_attr (target_die
,
11900 DW_AT_linkage_name
,
11902 if (target_physname
== NULL
)
11903 target_physname
= dwarf2_string_attr (target_die
,
11904 DW_AT_MIPS_linkage_name
,
11906 if (target_physname
== NULL
)
11907 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
11908 if (target_physname
== NULL
)
11909 complaint (&symfile_complaints
,
11910 _("DW_AT_call_target target DIE has invalid "
11911 "physname, for referencing DIE 0x%x [in module %s]"),
11912 to_underlying (die
->sect_off
), objfile_name (objfile
));
11914 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
11920 /* DW_AT_entry_pc should be preferred. */
11921 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
11922 <= PC_BOUNDS_INVALID
)
11923 complaint (&symfile_complaints
,
11924 _("DW_AT_call_target target DIE has invalid "
11925 "low pc, for referencing DIE 0x%x [in module %s]"),
11926 to_underlying (die
->sect_off
), objfile_name (objfile
));
11929 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11930 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
11935 complaint (&symfile_complaints
,
11936 _("DW_TAG_call_site DW_AT_call_target is neither "
11937 "block nor reference, for DIE 0x%x [in module %s]"),
11938 to_underlying (die
->sect_off
), objfile_name (objfile
));
11940 call_site
->per_cu
= cu
->per_cu
;
11942 for (child_die
= die
->child
;
11943 child_die
&& child_die
->tag
;
11944 child_die
= sibling_die (child_die
))
11946 struct call_site_parameter
*parameter
;
11947 struct attribute
*loc
, *origin
;
11949 if (child_die
->tag
!= DW_TAG_call_site_parameter
11950 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11952 /* Already printed the complaint above. */
11956 gdb_assert (call_site
->parameter_count
< nparams
);
11957 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
11959 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
11960 specifies DW_TAG_formal_parameter. Value of the data assumed for the
11961 register is contained in DW_AT_call_value. */
11963 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
11964 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
11965 if (origin
== NULL
)
11967 /* This was a pre-DWARF-5 GNU extension alias
11968 for DW_AT_call_parameter. */
11969 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
11971 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
11973 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
11975 sect_offset sect_off
11976 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
11977 if (!offset_in_cu_p (&cu
->header
, sect_off
))
11979 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
11980 binding can be done only inside one CU. Such referenced DIE
11981 therefore cannot be even moved to DW_TAG_partial_unit. */
11982 complaint (&symfile_complaints
,
11983 _("DW_AT_call_parameter offset is not in CU for "
11984 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
11985 to_underlying (child_die
->sect_off
),
11986 objfile_name (objfile
));
11989 parameter
->u
.param_cu_off
11990 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
11992 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
11994 complaint (&symfile_complaints
,
11995 _("No DW_FORM_block* DW_AT_location for "
11996 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
11997 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
12002 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
12003 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
12004 if (parameter
->u
.dwarf_reg
!= -1)
12005 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
12006 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
12007 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
12008 ¶meter
->u
.fb_offset
))
12009 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
12012 complaint (&symfile_complaints
,
12013 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
12014 "for DW_FORM_block* DW_AT_location is supported for "
12015 "DW_TAG_call_site child DIE 0x%x "
12017 to_underlying (child_die
->sect_off
),
12018 objfile_name (objfile
));
12023 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
12025 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
12026 if (!attr_form_is_block (attr
))
12028 complaint (&symfile_complaints
,
12029 _("No DW_FORM_block* DW_AT_call_value for "
12030 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12031 to_underlying (child_die
->sect_off
),
12032 objfile_name (objfile
));
12035 parameter
->value
= DW_BLOCK (attr
)->data
;
12036 parameter
->value_size
= DW_BLOCK (attr
)->size
;
12038 /* Parameters are not pre-cleared by memset above. */
12039 parameter
->data_value
= NULL
;
12040 parameter
->data_value_size
= 0;
12041 call_site
->parameter_count
++;
12043 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
12045 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
12048 if (!attr_form_is_block (attr
))
12049 complaint (&symfile_complaints
,
12050 _("No DW_FORM_block* DW_AT_call_data_value for "
12051 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12052 to_underlying (child_die
->sect_off
),
12053 objfile_name (objfile
));
12056 parameter
->data_value
= DW_BLOCK (attr
)->data
;
12057 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
12063 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
12064 reading .debug_rnglists.
12065 Callback's type should be:
12066 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
12067 Return true if the attributes are present and valid, otherwise,
12070 template <typename Callback
>
12072 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
12073 Callback
&&callback
)
12075 struct objfile
*objfile
= cu
->objfile
;
12076 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12077 struct comp_unit_head
*cu_header
= &cu
->header
;
12078 bfd
*obfd
= objfile
->obfd
;
12079 unsigned int addr_size
= cu_header
->addr_size
;
12080 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12081 /* Base address selection entry. */
12084 unsigned int dummy
;
12085 const gdb_byte
*buffer
;
12087 CORE_ADDR high
= 0;
12088 CORE_ADDR baseaddr
;
12089 bool overflow
= false;
12091 found_base
= cu
->base_known
;
12092 base
= cu
->base_address
;
12094 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
12095 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
12097 complaint (&symfile_complaints
,
12098 _("Offset %d out of bounds for DW_AT_ranges attribute"),
12102 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
12104 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12108 /* Initialize it due to a false compiler warning. */
12109 CORE_ADDR range_beginning
= 0, range_end
= 0;
12110 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
12111 + dwarf2_per_objfile
->rnglists
.size
);
12112 unsigned int bytes_read
;
12114 if (buffer
== buf_end
)
12119 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
12122 case DW_RLE_end_of_list
:
12124 case DW_RLE_base_address
:
12125 if (buffer
+ cu
->header
.addr_size
> buf_end
)
12130 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12132 buffer
+= bytes_read
;
12134 case DW_RLE_start_length
:
12135 if (buffer
+ cu
->header
.addr_size
> buf_end
)
12140 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12141 buffer
+= bytes_read
;
12142 range_end
= (range_beginning
12143 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
12144 buffer
+= bytes_read
;
12145 if (buffer
> buf_end
)
12151 case DW_RLE_offset_pair
:
12152 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12153 buffer
+= bytes_read
;
12154 if (buffer
> buf_end
)
12159 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12160 buffer
+= bytes_read
;
12161 if (buffer
> buf_end
)
12167 case DW_RLE_start_end
:
12168 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
12173 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12174 buffer
+= bytes_read
;
12175 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12176 buffer
+= bytes_read
;
12179 complaint (&symfile_complaints
,
12180 _("Invalid .debug_rnglists data (no base address)"));
12183 if (rlet
== DW_RLE_end_of_list
|| overflow
)
12185 if (rlet
== DW_RLE_base_address
)
12190 /* We have no valid base address for the ranges
12192 complaint (&symfile_complaints
,
12193 _("Invalid .debug_rnglists data (no base address)"));
12197 if (range_beginning
> range_end
)
12199 /* Inverted range entries are invalid. */
12200 complaint (&symfile_complaints
,
12201 _("Invalid .debug_rnglists data (inverted range)"));
12205 /* Empty range entries have no effect. */
12206 if (range_beginning
== range_end
)
12209 range_beginning
+= base
;
12212 /* A not-uncommon case of bad debug info.
12213 Don't pollute the addrmap with bad data. */
12214 if (range_beginning
+ baseaddr
== 0
12215 && !dwarf2_per_objfile
->has_section_at_zero
)
12217 complaint (&symfile_complaints
,
12218 _(".debug_rnglists entry has start address of zero"
12219 " [in module %s]"), objfile_name (objfile
));
12223 callback (range_beginning
, range_end
);
12228 complaint (&symfile_complaints
,
12229 _("Offset %d is not terminated "
12230 "for DW_AT_ranges attribute"),
12238 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
12239 Callback's type should be:
12240 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
12241 Return 1 if the attributes are present and valid, otherwise, return 0. */
12243 template <typename Callback
>
12245 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
12246 Callback
&&callback
)
12248 struct objfile
*objfile
= cu
->objfile
;
12249 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12250 struct comp_unit_head
*cu_header
= &cu
->header
;
12251 bfd
*obfd
= objfile
->obfd
;
12252 unsigned int addr_size
= cu_header
->addr_size
;
12253 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12254 /* Base address selection entry. */
12257 unsigned int dummy
;
12258 const gdb_byte
*buffer
;
12259 CORE_ADDR baseaddr
;
12261 if (cu_header
->version
>= 5)
12262 return dwarf2_rnglists_process (offset
, cu
, callback
);
12264 found_base
= cu
->base_known
;
12265 base
= cu
->base_address
;
12267 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
12268 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
12270 complaint (&symfile_complaints
,
12271 _("Offset %d out of bounds for DW_AT_ranges attribute"),
12275 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
12277 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12281 CORE_ADDR range_beginning
, range_end
;
12283 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
12284 buffer
+= addr_size
;
12285 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
12286 buffer
+= addr_size
;
12287 offset
+= 2 * addr_size
;
12289 /* An end of list marker is a pair of zero addresses. */
12290 if (range_beginning
== 0 && range_end
== 0)
12291 /* Found the end of list entry. */
12294 /* Each base address selection entry is a pair of 2 values.
12295 The first is the largest possible address, the second is
12296 the base address. Check for a base address here. */
12297 if ((range_beginning
& mask
) == mask
)
12299 /* If we found the largest possible address, then we already
12300 have the base address in range_end. */
12308 /* We have no valid base address for the ranges
12310 complaint (&symfile_complaints
,
12311 _("Invalid .debug_ranges data (no base address)"));
12315 if (range_beginning
> range_end
)
12317 /* Inverted range entries are invalid. */
12318 complaint (&symfile_complaints
,
12319 _("Invalid .debug_ranges data (inverted range)"));
12323 /* Empty range entries have no effect. */
12324 if (range_beginning
== range_end
)
12327 range_beginning
+= base
;
12330 /* A not-uncommon case of bad debug info.
12331 Don't pollute the addrmap with bad data. */
12332 if (range_beginning
+ baseaddr
== 0
12333 && !dwarf2_per_objfile
->has_section_at_zero
)
12335 complaint (&symfile_complaints
,
12336 _(".debug_ranges entry has start address of zero"
12337 " [in module %s]"), objfile_name (objfile
));
12341 callback (range_beginning
, range_end
);
12347 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
12348 Return 1 if the attributes are present and valid, otherwise, return 0.
12349 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
12352 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
12353 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
12354 struct partial_symtab
*ranges_pst
)
12356 struct objfile
*objfile
= cu
->objfile
;
12357 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12358 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
12359 SECT_OFF_TEXT (objfile
));
12362 CORE_ADDR high
= 0;
12365 retval
= dwarf2_ranges_process (offset
, cu
,
12366 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
12368 if (ranges_pst
!= NULL
)
12373 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
12374 range_beginning
+ baseaddr
);
12375 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
12376 range_end
+ baseaddr
);
12377 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
12381 /* FIXME: This is recording everything as a low-high
12382 segment of consecutive addresses. We should have a
12383 data structure for discontiguous block ranges
12387 low
= range_beginning
;
12393 if (range_beginning
< low
)
12394 low
= range_beginning
;
12395 if (range_end
> high
)
12403 /* If the first entry is an end-of-list marker, the range
12404 describes an empty scope, i.e. no instructions. */
12410 *high_return
= high
;
12414 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
12415 definition for the return value. *LOWPC and *HIGHPC are set iff
12416 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
12418 static enum pc_bounds_kind
12419 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
12420 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
12421 struct partial_symtab
*pst
)
12423 struct attribute
*attr
;
12424 struct attribute
*attr_high
;
12426 CORE_ADDR high
= 0;
12427 enum pc_bounds_kind ret
;
12429 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12432 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12435 low
= attr_value_as_address (attr
);
12436 high
= attr_value_as_address (attr_high
);
12437 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12441 /* Found high w/o low attribute. */
12442 return PC_BOUNDS_INVALID
;
12444 /* Found consecutive range of addresses. */
12445 ret
= PC_BOUNDS_HIGH_LOW
;
12449 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12452 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12453 We take advantage of the fact that DW_AT_ranges does not appear
12454 in DW_TAG_compile_unit of DWO files. */
12455 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12456 unsigned int ranges_offset
= (DW_UNSND (attr
)
12457 + (need_ranges_base
12461 /* Value of the DW_AT_ranges attribute is the offset in the
12462 .debug_ranges section. */
12463 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
12464 return PC_BOUNDS_INVALID
;
12465 /* Found discontinuous range of addresses. */
12466 ret
= PC_BOUNDS_RANGES
;
12469 return PC_BOUNDS_NOT_PRESENT
;
12472 /* read_partial_die has also the strict LOW < HIGH requirement. */
12474 return PC_BOUNDS_INVALID
;
12476 /* When using the GNU linker, .gnu.linkonce. sections are used to
12477 eliminate duplicate copies of functions and vtables and such.
12478 The linker will arbitrarily choose one and discard the others.
12479 The AT_*_pc values for such functions refer to local labels in
12480 these sections. If the section from that file was discarded, the
12481 labels are not in the output, so the relocs get a value of 0.
12482 If this is a discarded function, mark the pc bounds as invalid,
12483 so that GDB will ignore it. */
12484 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12485 return PC_BOUNDS_INVALID
;
12493 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
12494 its low and high PC addresses. Do nothing if these addresses could not
12495 be determined. Otherwise, set LOWPC to the low address if it is smaller,
12496 and HIGHPC to the high address if greater than HIGHPC. */
12499 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
12500 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12501 struct dwarf2_cu
*cu
)
12503 CORE_ADDR low
, high
;
12504 struct die_info
*child
= die
->child
;
12506 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
12508 *lowpc
= std::min (*lowpc
, low
);
12509 *highpc
= std::max (*highpc
, high
);
12512 /* If the language does not allow nested subprograms (either inside
12513 subprograms or lexical blocks), we're done. */
12514 if (cu
->language
!= language_ada
)
12517 /* Check all the children of the given DIE. If it contains nested
12518 subprograms, then check their pc bounds. Likewise, we need to
12519 check lexical blocks as well, as they may also contain subprogram
12521 while (child
&& child
->tag
)
12523 if (child
->tag
== DW_TAG_subprogram
12524 || child
->tag
== DW_TAG_lexical_block
)
12525 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
12526 child
= sibling_die (child
);
12530 /* Get the low and high pc's represented by the scope DIE, and store
12531 them in *LOWPC and *HIGHPC. If the correct values can't be
12532 determined, set *LOWPC to -1 and *HIGHPC to 0. */
12535 get_scope_pc_bounds (struct die_info
*die
,
12536 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12537 struct dwarf2_cu
*cu
)
12539 CORE_ADDR best_low
= (CORE_ADDR
) -1;
12540 CORE_ADDR best_high
= (CORE_ADDR
) 0;
12541 CORE_ADDR current_low
, current_high
;
12543 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
12544 >= PC_BOUNDS_RANGES
)
12546 best_low
= current_low
;
12547 best_high
= current_high
;
12551 struct die_info
*child
= die
->child
;
12553 while (child
&& child
->tag
)
12555 switch (child
->tag
) {
12556 case DW_TAG_subprogram
:
12557 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
12559 case DW_TAG_namespace
:
12560 case DW_TAG_module
:
12561 /* FIXME: carlton/2004-01-16: Should we do this for
12562 DW_TAG_class_type/DW_TAG_structure_type, too? I think
12563 that current GCC's always emit the DIEs corresponding
12564 to definitions of methods of classes as children of a
12565 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
12566 the DIEs giving the declarations, which could be
12567 anywhere). But I don't see any reason why the
12568 standards says that they have to be there. */
12569 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
12571 if (current_low
!= ((CORE_ADDR
) -1))
12573 best_low
= std::min (best_low
, current_low
);
12574 best_high
= std::max (best_high
, current_high
);
12582 child
= sibling_die (child
);
12587 *highpc
= best_high
;
12590 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
12594 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
12595 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
12597 struct objfile
*objfile
= cu
->objfile
;
12598 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12599 struct attribute
*attr
;
12600 struct attribute
*attr_high
;
12602 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12605 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12608 CORE_ADDR low
= attr_value_as_address (attr
);
12609 CORE_ADDR high
= attr_value_as_address (attr_high
);
12611 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12614 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
12615 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
12616 record_block_range (block
, low
, high
- 1);
12620 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12623 bfd
*obfd
= objfile
->obfd
;
12624 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12625 We take advantage of the fact that DW_AT_ranges does not appear
12626 in DW_TAG_compile_unit of DWO files. */
12627 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12629 /* The value of the DW_AT_ranges attribute is the offset of the
12630 address range list in the .debug_ranges section. */
12631 unsigned long offset
= (DW_UNSND (attr
)
12632 + (need_ranges_base
? cu
->ranges_base
: 0));
12633 const gdb_byte
*buffer
;
12635 /* For some target architectures, but not others, the
12636 read_address function sign-extends the addresses it returns.
12637 To recognize base address selection entries, we need a
12639 unsigned int addr_size
= cu
->header
.addr_size
;
12640 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12642 /* The base address, to which the next pair is relative. Note
12643 that this 'base' is a DWARF concept: most entries in a range
12644 list are relative, to reduce the number of relocs against the
12645 debugging information. This is separate from this function's
12646 'baseaddr' argument, which GDB uses to relocate debugging
12647 information from a shared library based on the address at
12648 which the library was loaded. */
12649 CORE_ADDR base
= cu
->base_address
;
12650 int base_known
= cu
->base_known
;
12652 dwarf2_ranges_process (offset
, cu
,
12653 [&] (CORE_ADDR start
, CORE_ADDR end
)
12657 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
12658 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
12659 record_block_range (block
, start
, end
- 1);
12664 /* Check whether the producer field indicates either of GCC < 4.6, or the
12665 Intel C/C++ compiler, and cache the result in CU. */
12668 check_producer (struct dwarf2_cu
*cu
)
12672 if (cu
->producer
== NULL
)
12674 /* For unknown compilers expect their behavior is DWARF version
12677 GCC started to support .debug_types sections by -gdwarf-4 since
12678 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
12679 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
12680 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
12681 interpreted incorrectly by GDB now - GCC PR debug/48229. */
12683 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
12685 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
12686 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
12688 else if (startswith (cu
->producer
, "Intel(R) C"))
12689 cu
->producer_is_icc
= 1;
12692 /* For other non-GCC compilers, expect their behavior is DWARF version
12696 cu
->checked_producer
= 1;
12699 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
12700 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
12701 during 4.6.0 experimental. */
12704 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
12706 if (!cu
->checked_producer
)
12707 check_producer (cu
);
12709 return cu
->producer_is_gxx_lt_4_6
;
12712 /* Return the default accessibility type if it is not overriden by
12713 DW_AT_accessibility. */
12715 static enum dwarf_access_attribute
12716 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
12718 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
12720 /* The default DWARF 2 accessibility for members is public, the default
12721 accessibility for inheritance is private. */
12723 if (die
->tag
!= DW_TAG_inheritance
)
12724 return DW_ACCESS_public
;
12726 return DW_ACCESS_private
;
12730 /* DWARF 3+ defines the default accessibility a different way. The same
12731 rules apply now for DW_TAG_inheritance as for the members and it only
12732 depends on the container kind. */
12734 if (die
->parent
->tag
== DW_TAG_class_type
)
12735 return DW_ACCESS_private
;
12737 return DW_ACCESS_public
;
12741 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
12742 offset. If the attribute was not found return 0, otherwise return
12743 1. If it was found but could not properly be handled, set *OFFSET
12747 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
12750 struct attribute
*attr
;
12752 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
12757 /* Note that we do not check for a section offset first here.
12758 This is because DW_AT_data_member_location is new in DWARF 4,
12759 so if we see it, we can assume that a constant form is really
12760 a constant and not a section offset. */
12761 if (attr_form_is_constant (attr
))
12762 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
12763 else if (attr_form_is_section_offset (attr
))
12764 dwarf2_complex_location_expr_complaint ();
12765 else if (attr_form_is_block (attr
))
12766 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
12768 dwarf2_complex_location_expr_complaint ();
12776 /* Add an aggregate field to the field list. */
12779 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
12780 struct dwarf2_cu
*cu
)
12782 struct objfile
*objfile
= cu
->objfile
;
12783 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12784 struct nextfield
*new_field
;
12785 struct attribute
*attr
;
12787 const char *fieldname
= "";
12789 /* Allocate a new field list entry and link it in. */
12790 new_field
= XNEW (struct nextfield
);
12791 make_cleanup (xfree
, new_field
);
12792 memset (new_field
, 0, sizeof (struct nextfield
));
12794 if (die
->tag
== DW_TAG_inheritance
)
12796 new_field
->next
= fip
->baseclasses
;
12797 fip
->baseclasses
= new_field
;
12801 new_field
->next
= fip
->fields
;
12802 fip
->fields
= new_field
;
12806 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
12808 new_field
->accessibility
= DW_UNSND (attr
);
12810 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
12811 if (new_field
->accessibility
!= DW_ACCESS_public
)
12812 fip
->non_public_fields
= 1;
12814 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
12816 new_field
->virtuality
= DW_UNSND (attr
);
12818 new_field
->virtuality
= DW_VIRTUALITY_none
;
12820 fp
= &new_field
->field
;
12822 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
12826 /* Data member other than a C++ static data member. */
12828 /* Get type of field. */
12829 fp
->type
= die_type (die
, cu
);
12831 SET_FIELD_BITPOS (*fp
, 0);
12833 /* Get bit size of field (zero if none). */
12834 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
12837 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
12841 FIELD_BITSIZE (*fp
) = 0;
12844 /* Get bit offset of field. */
12845 if (handle_data_member_location (die
, cu
, &offset
))
12846 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12847 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
12850 if (gdbarch_bits_big_endian (gdbarch
))
12852 /* For big endian bits, the DW_AT_bit_offset gives the
12853 additional bit offset from the MSB of the containing
12854 anonymous object to the MSB of the field. We don't
12855 have to do anything special since we don't need to
12856 know the size of the anonymous object. */
12857 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
12861 /* For little endian bits, compute the bit offset to the
12862 MSB of the anonymous object, subtract off the number of
12863 bits from the MSB of the field to the MSB of the
12864 object, and then subtract off the number of bits of
12865 the field itself. The result is the bit offset of
12866 the LSB of the field. */
12867 int anonymous_size
;
12868 int bit_offset
= DW_UNSND (attr
);
12870 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12873 /* The size of the anonymous object containing
12874 the bit field is explicit, so use the
12875 indicated size (in bytes). */
12876 anonymous_size
= DW_UNSND (attr
);
12880 /* The size of the anonymous object containing
12881 the bit field must be inferred from the type
12882 attribute of the data member containing the
12884 anonymous_size
= TYPE_LENGTH (fp
->type
);
12886 SET_FIELD_BITPOS (*fp
,
12887 (FIELD_BITPOS (*fp
)
12888 + anonymous_size
* bits_per_byte
12889 - bit_offset
- FIELD_BITSIZE (*fp
)));
12892 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
12894 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
12895 + dwarf2_get_attr_constant_value (attr
, 0)));
12897 /* Get name of field. */
12898 fieldname
= dwarf2_name (die
, cu
);
12899 if (fieldname
== NULL
)
12902 /* The name is already allocated along with this objfile, so we don't
12903 need to duplicate it for the type. */
12904 fp
->name
= fieldname
;
12906 /* Change accessibility for artificial fields (e.g. virtual table
12907 pointer or virtual base class pointer) to private. */
12908 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
12910 FIELD_ARTIFICIAL (*fp
) = 1;
12911 new_field
->accessibility
= DW_ACCESS_private
;
12912 fip
->non_public_fields
= 1;
12915 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
12917 /* C++ static member. */
12919 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
12920 is a declaration, but all versions of G++ as of this writing
12921 (so through at least 3.2.1) incorrectly generate
12922 DW_TAG_variable tags. */
12924 const char *physname
;
12926 /* Get name of field. */
12927 fieldname
= dwarf2_name (die
, cu
);
12928 if (fieldname
== NULL
)
12931 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12933 /* Only create a symbol if this is an external value.
12934 new_symbol checks this and puts the value in the global symbol
12935 table, which we want. If it is not external, new_symbol
12936 will try to put the value in cu->list_in_scope which is wrong. */
12937 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
12939 /* A static const member, not much different than an enum as far as
12940 we're concerned, except that we can support more types. */
12941 new_symbol (die
, NULL
, cu
);
12944 /* Get physical name. */
12945 physname
= dwarf2_physname (fieldname
, die
, cu
);
12947 /* The name is already allocated along with this objfile, so we don't
12948 need to duplicate it for the type. */
12949 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
12950 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12951 FIELD_NAME (*fp
) = fieldname
;
12953 else if (die
->tag
== DW_TAG_inheritance
)
12957 /* C++ base class field. */
12958 if (handle_data_member_location (die
, cu
, &offset
))
12959 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12960 FIELD_BITSIZE (*fp
) = 0;
12961 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12962 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
12963 fip
->nbaseclasses
++;
12967 /* Add a typedef defined in the scope of the FIP's class. */
12970 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
12971 struct dwarf2_cu
*cu
)
12973 struct typedef_field_list
*new_field
;
12974 struct typedef_field
*fp
;
12976 /* Allocate a new field list entry and link it in. */
12977 new_field
= XCNEW (struct typedef_field_list
);
12978 make_cleanup (xfree
, new_field
);
12980 gdb_assert (die
->tag
== DW_TAG_typedef
);
12982 fp
= &new_field
->field
;
12984 /* Get name of field. */
12985 fp
->name
= dwarf2_name (die
, cu
);
12986 if (fp
->name
== NULL
)
12989 fp
->type
= read_type_die (die
, cu
);
12991 new_field
->next
= fip
->typedef_field_list
;
12992 fip
->typedef_field_list
= new_field
;
12993 fip
->typedef_field_list_count
++;
12996 /* Create the vector of fields, and attach it to the type. */
12999 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
13000 struct dwarf2_cu
*cu
)
13002 int nfields
= fip
->nfields
;
13004 /* Record the field count, allocate space for the array of fields,
13005 and create blank accessibility bitfields if necessary. */
13006 TYPE_NFIELDS (type
) = nfields
;
13007 TYPE_FIELDS (type
) = (struct field
*)
13008 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
13009 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
13011 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
13013 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13015 TYPE_FIELD_PRIVATE_BITS (type
) =
13016 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
13017 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
13019 TYPE_FIELD_PROTECTED_BITS (type
) =
13020 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
13021 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
13023 TYPE_FIELD_IGNORE_BITS (type
) =
13024 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
13025 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
13028 /* If the type has baseclasses, allocate and clear a bit vector for
13029 TYPE_FIELD_VIRTUAL_BITS. */
13030 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
13032 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
13033 unsigned char *pointer
;
13035 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13036 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
13037 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
13038 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
13039 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
13042 /* Copy the saved-up fields into the field vector. Start from the head of
13043 the list, adding to the tail of the field array, so that they end up in
13044 the same order in the array in which they were added to the list. */
13045 while (nfields
-- > 0)
13047 struct nextfield
*fieldp
;
13051 fieldp
= fip
->fields
;
13052 fip
->fields
= fieldp
->next
;
13056 fieldp
= fip
->baseclasses
;
13057 fip
->baseclasses
= fieldp
->next
;
13060 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
13061 switch (fieldp
->accessibility
)
13063 case DW_ACCESS_private
:
13064 if (cu
->language
!= language_ada
)
13065 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
13068 case DW_ACCESS_protected
:
13069 if (cu
->language
!= language_ada
)
13070 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
13073 case DW_ACCESS_public
:
13077 /* Unknown accessibility. Complain and treat it as public. */
13079 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
13080 fieldp
->accessibility
);
13084 if (nfields
< fip
->nbaseclasses
)
13086 switch (fieldp
->virtuality
)
13088 case DW_VIRTUALITY_virtual
:
13089 case DW_VIRTUALITY_pure_virtual
:
13090 if (cu
->language
== language_ada
)
13091 error (_("unexpected virtuality in component of Ada type"));
13092 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
13099 /* Return true if this member function is a constructor, false
13103 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
13105 const char *fieldname
;
13106 const char *type_name
;
13109 if (die
->parent
== NULL
)
13112 if (die
->parent
->tag
!= DW_TAG_structure_type
13113 && die
->parent
->tag
!= DW_TAG_union_type
13114 && die
->parent
->tag
!= DW_TAG_class_type
)
13117 fieldname
= dwarf2_name (die
, cu
);
13118 type_name
= dwarf2_name (die
->parent
, cu
);
13119 if (fieldname
== NULL
|| type_name
== NULL
)
13122 len
= strlen (fieldname
);
13123 return (strncmp (fieldname
, type_name
, len
) == 0
13124 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
13127 /* Add a member function to the proper fieldlist. */
13130 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
13131 struct type
*type
, struct dwarf2_cu
*cu
)
13133 struct objfile
*objfile
= cu
->objfile
;
13134 struct attribute
*attr
;
13135 struct fnfieldlist
*flp
;
13137 struct fn_field
*fnp
;
13138 const char *fieldname
;
13139 struct nextfnfield
*new_fnfield
;
13140 struct type
*this_type
;
13141 enum dwarf_access_attribute accessibility
;
13143 if (cu
->language
== language_ada
)
13144 error (_("unexpected member function in Ada type"));
13146 /* Get name of member function. */
13147 fieldname
= dwarf2_name (die
, cu
);
13148 if (fieldname
== NULL
)
13151 /* Look up member function name in fieldlist. */
13152 for (i
= 0; i
< fip
->nfnfields
; i
++)
13154 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
13158 /* Create new list element if necessary. */
13159 if (i
< fip
->nfnfields
)
13160 flp
= &fip
->fnfieldlists
[i
];
13163 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
13165 fip
->fnfieldlists
= (struct fnfieldlist
*)
13166 xrealloc (fip
->fnfieldlists
,
13167 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
13168 * sizeof (struct fnfieldlist
));
13169 if (fip
->nfnfields
== 0)
13170 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
13172 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
13173 flp
->name
= fieldname
;
13176 i
= fip
->nfnfields
++;
13179 /* Create a new member function field and chain it to the field list
13181 new_fnfield
= XNEW (struct nextfnfield
);
13182 make_cleanup (xfree
, new_fnfield
);
13183 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
13184 new_fnfield
->next
= flp
->head
;
13185 flp
->head
= new_fnfield
;
13188 /* Fill in the member function field info. */
13189 fnp
= &new_fnfield
->fnfield
;
13191 /* Delay processing of the physname until later. */
13192 if (cu
->language
== language_cplus
)
13194 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
13199 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
13200 fnp
->physname
= physname
? physname
: "";
13203 fnp
->type
= alloc_type (objfile
);
13204 this_type
= read_type_die (die
, cu
);
13205 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
13207 int nparams
= TYPE_NFIELDS (this_type
);
13209 /* TYPE is the domain of this method, and THIS_TYPE is the type
13210 of the method itself (TYPE_CODE_METHOD). */
13211 smash_to_method_type (fnp
->type
, type
,
13212 TYPE_TARGET_TYPE (this_type
),
13213 TYPE_FIELDS (this_type
),
13214 TYPE_NFIELDS (this_type
),
13215 TYPE_VARARGS (this_type
));
13217 /* Handle static member functions.
13218 Dwarf2 has no clean way to discern C++ static and non-static
13219 member functions. G++ helps GDB by marking the first
13220 parameter for non-static member functions (which is the this
13221 pointer) as artificial. We obtain this information from
13222 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
13223 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
13224 fnp
->voffset
= VOFFSET_STATIC
;
13227 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
13228 dwarf2_full_name (fieldname
, die
, cu
));
13230 /* Get fcontext from DW_AT_containing_type if present. */
13231 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
13232 fnp
->fcontext
= die_containing_type (die
, cu
);
13234 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
13235 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
13237 /* Get accessibility. */
13238 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
13240 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
13242 accessibility
= dwarf2_default_access_attribute (die
, cu
);
13243 switch (accessibility
)
13245 case DW_ACCESS_private
:
13246 fnp
->is_private
= 1;
13248 case DW_ACCESS_protected
:
13249 fnp
->is_protected
= 1;
13253 /* Check for artificial methods. */
13254 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
13255 if (attr
&& DW_UNSND (attr
) != 0)
13256 fnp
->is_artificial
= 1;
13258 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
13260 /* Get index in virtual function table if it is a virtual member
13261 function. For older versions of GCC, this is an offset in the
13262 appropriate virtual table, as specified by DW_AT_containing_type.
13263 For everyone else, it is an expression to be evaluated relative
13264 to the object address. */
13266 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
13269 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
13271 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
13273 /* Old-style GCC. */
13274 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
13276 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
13277 || (DW_BLOCK (attr
)->size
> 1
13278 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
13279 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
13281 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
13282 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
13283 dwarf2_complex_location_expr_complaint ();
13285 fnp
->voffset
/= cu
->header
.addr_size
;
13289 dwarf2_complex_location_expr_complaint ();
13291 if (!fnp
->fcontext
)
13293 /* If there is no `this' field and no DW_AT_containing_type,
13294 we cannot actually find a base class context for the
13296 if (TYPE_NFIELDS (this_type
) == 0
13297 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
13299 complaint (&symfile_complaints
,
13300 _("cannot determine context for virtual member "
13301 "function \"%s\" (offset %d)"),
13302 fieldname
, to_underlying (die
->sect_off
));
13307 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
13311 else if (attr_form_is_section_offset (attr
))
13313 dwarf2_complex_location_expr_complaint ();
13317 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
13323 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
13324 if (attr
&& DW_UNSND (attr
))
13326 /* GCC does this, as of 2008-08-25; PR debug/37237. */
13327 complaint (&symfile_complaints
,
13328 _("Member function \"%s\" (offset %d) is virtual "
13329 "but the vtable offset is not specified"),
13330 fieldname
, to_underlying (die
->sect_off
));
13331 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13332 TYPE_CPLUS_DYNAMIC (type
) = 1;
13337 /* Create the vector of member function fields, and attach it to the type. */
13340 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
13341 struct dwarf2_cu
*cu
)
13343 struct fnfieldlist
*flp
;
13346 if (cu
->language
== language_ada
)
13347 error (_("unexpected member functions in Ada type"));
13349 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13350 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
13351 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
13353 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
13355 struct nextfnfield
*nfp
= flp
->head
;
13356 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
13359 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
13360 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
13361 fn_flp
->fn_fields
= (struct fn_field
*)
13362 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
13363 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
13364 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
13367 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
13370 /* Returns non-zero if NAME is the name of a vtable member in CU's
13371 language, zero otherwise. */
13373 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
13375 static const char vptr
[] = "_vptr";
13376 static const char vtable
[] = "vtable";
13378 /* Look for the C++ form of the vtable. */
13379 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
13385 /* GCC outputs unnamed structures that are really pointers to member
13386 functions, with the ABI-specified layout. If TYPE describes
13387 such a structure, smash it into a member function type.
13389 GCC shouldn't do this; it should just output pointer to member DIEs.
13390 This is GCC PR debug/28767. */
13393 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
13395 struct type
*pfn_type
, *self_type
, *new_type
;
13397 /* Check for a structure with no name and two children. */
13398 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
13401 /* Check for __pfn and __delta members. */
13402 if (TYPE_FIELD_NAME (type
, 0) == NULL
13403 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
13404 || TYPE_FIELD_NAME (type
, 1) == NULL
13405 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
13408 /* Find the type of the method. */
13409 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
13410 if (pfn_type
== NULL
13411 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
13412 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
13415 /* Look for the "this" argument. */
13416 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
13417 if (TYPE_NFIELDS (pfn_type
) == 0
13418 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
13419 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
13422 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
13423 new_type
= alloc_type (objfile
);
13424 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
13425 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
13426 TYPE_VARARGS (pfn_type
));
13427 smash_to_methodptr_type (type
, new_type
);
13430 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
13434 producer_is_icc (struct dwarf2_cu
*cu
)
13436 if (!cu
->checked_producer
)
13437 check_producer (cu
);
13439 return cu
->producer_is_icc
;
13442 /* Called when we find the DIE that starts a structure or union scope
13443 (definition) to create a type for the structure or union. Fill in
13444 the type's name and general properties; the members will not be
13445 processed until process_structure_scope. A symbol table entry for
13446 the type will also not be done until process_structure_scope (assuming
13447 the type has a name).
13449 NOTE: we need to call these functions regardless of whether or not the
13450 DIE has a DW_AT_name attribute, since it might be an anonymous
13451 structure or union. This gets the type entered into our set of
13452 user defined types. */
13454 static struct type
*
13455 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13457 struct objfile
*objfile
= cu
->objfile
;
13459 struct attribute
*attr
;
13462 /* If the definition of this type lives in .debug_types, read that type.
13463 Don't follow DW_AT_specification though, that will take us back up
13464 the chain and we want to go down. */
13465 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
13468 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13470 /* The type's CU may not be the same as CU.
13471 Ensure TYPE is recorded with CU in die_type_hash. */
13472 return set_die_type (die
, type
, cu
);
13475 type
= alloc_type (objfile
);
13476 INIT_CPLUS_SPECIFIC (type
);
13478 name
= dwarf2_name (die
, cu
);
13481 if (cu
->language
== language_cplus
13482 || cu
->language
== language_d
13483 || cu
->language
== language_rust
)
13485 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
13487 /* dwarf2_full_name might have already finished building the DIE's
13488 type. If so, there is no need to continue. */
13489 if (get_die_type (die
, cu
) != NULL
)
13490 return get_die_type (die
, cu
);
13492 TYPE_TAG_NAME (type
) = full_name
;
13493 if (die
->tag
== DW_TAG_structure_type
13494 || die
->tag
== DW_TAG_class_type
)
13495 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13499 /* The name is already allocated along with this objfile, so
13500 we don't need to duplicate it for the type. */
13501 TYPE_TAG_NAME (type
) = name
;
13502 if (die
->tag
== DW_TAG_class_type
)
13503 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13507 if (die
->tag
== DW_TAG_structure_type
)
13509 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13511 else if (die
->tag
== DW_TAG_union_type
)
13513 TYPE_CODE (type
) = TYPE_CODE_UNION
;
13517 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13520 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
13521 TYPE_DECLARED_CLASS (type
) = 1;
13523 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13526 if (attr_form_is_constant (attr
))
13527 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13530 /* For the moment, dynamic type sizes are not supported
13531 by GDB's struct type. The actual size is determined
13532 on-demand when resolving the type of a given object,
13533 so set the type's length to zero for now. Otherwise,
13534 we record an expression as the length, and that expression
13535 could lead to a very large value, which could eventually
13536 lead to us trying to allocate that much memory when creating
13537 a value of that type. */
13538 TYPE_LENGTH (type
) = 0;
13543 TYPE_LENGTH (type
) = 0;
13546 if (producer_is_icc (cu
) && (TYPE_LENGTH (type
) == 0))
13548 /* ICC does not output the required DW_AT_declaration
13549 on incomplete types, but gives them a size of zero. */
13550 TYPE_STUB (type
) = 1;
13553 TYPE_STUB_SUPPORTED (type
) = 1;
13555 if (die_is_declaration (die
, cu
))
13556 TYPE_STUB (type
) = 1;
13557 else if (attr
== NULL
&& die
->child
== NULL
13558 && producer_is_realview (cu
->producer
))
13559 /* RealView does not output the required DW_AT_declaration
13560 on incomplete types. */
13561 TYPE_STUB (type
) = 1;
13563 /* We need to add the type field to the die immediately so we don't
13564 infinitely recurse when dealing with pointers to the structure
13565 type within the structure itself. */
13566 set_die_type (die
, type
, cu
);
13568 /* set_die_type should be already done. */
13569 set_descriptive_type (type
, die
, cu
);
13574 /* Finish creating a structure or union type, including filling in
13575 its members and creating a symbol for it. */
13578 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13580 struct objfile
*objfile
= cu
->objfile
;
13581 struct die_info
*child_die
;
13584 type
= get_die_type (die
, cu
);
13586 type
= read_structure_type (die
, cu
);
13588 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
13590 struct field_info fi
;
13591 VEC (symbolp
) *template_args
= NULL
;
13592 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
13594 memset (&fi
, 0, sizeof (struct field_info
));
13596 child_die
= die
->child
;
13598 while (child_die
&& child_die
->tag
)
13600 if (child_die
->tag
== DW_TAG_member
13601 || child_die
->tag
== DW_TAG_variable
)
13603 /* NOTE: carlton/2002-11-05: A C++ static data member
13604 should be a DW_TAG_member that is a declaration, but
13605 all versions of G++ as of this writing (so through at
13606 least 3.2.1) incorrectly generate DW_TAG_variable
13607 tags for them instead. */
13608 dwarf2_add_field (&fi
, child_die
, cu
);
13610 else if (child_die
->tag
== DW_TAG_subprogram
)
13612 /* Rust doesn't have member functions in the C++ sense.
13613 However, it does emit ordinary functions as children
13614 of a struct DIE. */
13615 if (cu
->language
== language_rust
)
13616 read_func_scope (child_die
, cu
);
13619 /* C++ member function. */
13620 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
13623 else if (child_die
->tag
== DW_TAG_inheritance
)
13625 /* C++ base class field. */
13626 dwarf2_add_field (&fi
, child_die
, cu
);
13628 else if (child_die
->tag
== DW_TAG_typedef
)
13629 dwarf2_add_typedef (&fi
, child_die
, cu
);
13630 else if (child_die
->tag
== DW_TAG_template_type_param
13631 || child_die
->tag
== DW_TAG_template_value_param
)
13633 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13636 VEC_safe_push (symbolp
, template_args
, arg
);
13639 child_die
= sibling_die (child_die
);
13642 /* Attach template arguments to type. */
13643 if (! VEC_empty (symbolp
, template_args
))
13645 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13646 TYPE_N_TEMPLATE_ARGUMENTS (type
)
13647 = VEC_length (symbolp
, template_args
);
13648 TYPE_TEMPLATE_ARGUMENTS (type
)
13649 = XOBNEWVEC (&objfile
->objfile_obstack
,
13651 TYPE_N_TEMPLATE_ARGUMENTS (type
));
13652 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
13653 VEC_address (symbolp
, template_args
),
13654 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
13655 * sizeof (struct symbol
*)));
13656 VEC_free (symbolp
, template_args
);
13659 /* Attach fields and member functions to the type. */
13661 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
13664 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
13666 /* Get the type which refers to the base class (possibly this
13667 class itself) which contains the vtable pointer for the current
13668 class from the DW_AT_containing_type attribute. This use of
13669 DW_AT_containing_type is a GNU extension. */
13671 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
13673 struct type
*t
= die_containing_type (die
, cu
);
13675 set_type_vptr_basetype (type
, t
);
13680 /* Our own class provides vtbl ptr. */
13681 for (i
= TYPE_NFIELDS (t
) - 1;
13682 i
>= TYPE_N_BASECLASSES (t
);
13685 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
13687 if (is_vtable_name (fieldname
, cu
))
13689 set_type_vptr_fieldno (type
, i
);
13694 /* Complain if virtual function table field not found. */
13695 if (i
< TYPE_N_BASECLASSES (t
))
13696 complaint (&symfile_complaints
,
13697 _("virtual function table pointer "
13698 "not found when defining class '%s'"),
13699 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
13704 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
13707 else if (cu
->producer
13708 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
13710 /* The IBM XLC compiler does not provide direct indication
13711 of the containing type, but the vtable pointer is
13712 always named __vfp. */
13716 for (i
= TYPE_NFIELDS (type
) - 1;
13717 i
>= TYPE_N_BASECLASSES (type
);
13720 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
13722 set_type_vptr_fieldno (type
, i
);
13723 set_type_vptr_basetype (type
, type
);
13730 /* Copy fi.typedef_field_list linked list elements content into the
13731 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
13732 if (fi
.typedef_field_list
)
13734 int i
= fi
.typedef_field_list_count
;
13736 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13737 TYPE_TYPEDEF_FIELD_ARRAY (type
)
13738 = ((struct typedef_field
*)
13739 TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
));
13740 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
13742 /* Reverse the list order to keep the debug info elements order. */
13745 struct typedef_field
*dest
, *src
;
13747 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
13748 src
= &fi
.typedef_field_list
->field
;
13749 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
13754 do_cleanups (back_to
);
13757 quirk_gcc_member_function_pointer (type
, objfile
);
13759 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
13760 snapshots) has been known to create a die giving a declaration
13761 for a class that has, as a child, a die giving a definition for a
13762 nested class. So we have to process our children even if the
13763 current die is a declaration. Normally, of course, a declaration
13764 won't have any children at all. */
13766 child_die
= die
->child
;
13768 while (child_die
!= NULL
&& child_die
->tag
)
13770 if (child_die
->tag
== DW_TAG_member
13771 || child_die
->tag
== DW_TAG_variable
13772 || child_die
->tag
== DW_TAG_inheritance
13773 || child_die
->tag
== DW_TAG_template_value_param
13774 || child_die
->tag
== DW_TAG_template_type_param
)
13779 process_die (child_die
, cu
);
13781 child_die
= sibling_die (child_die
);
13784 /* Do not consider external references. According to the DWARF standard,
13785 these DIEs are identified by the fact that they have no byte_size
13786 attribute, and a declaration attribute. */
13787 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
13788 || !die_is_declaration (die
, cu
))
13789 new_symbol (die
, type
, cu
);
13792 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
13793 update TYPE using some information only available in DIE's children. */
13796 update_enumeration_type_from_children (struct die_info
*die
,
13798 struct dwarf2_cu
*cu
)
13800 struct die_info
*child_die
;
13801 int unsigned_enum
= 1;
13805 auto_obstack obstack
;
13807 for (child_die
= die
->child
;
13808 child_die
!= NULL
&& child_die
->tag
;
13809 child_die
= sibling_die (child_die
))
13811 struct attribute
*attr
;
13813 const gdb_byte
*bytes
;
13814 struct dwarf2_locexpr_baton
*baton
;
13817 if (child_die
->tag
!= DW_TAG_enumerator
)
13820 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
13824 name
= dwarf2_name (child_die
, cu
);
13826 name
= "<anonymous enumerator>";
13828 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
13829 &value
, &bytes
, &baton
);
13835 else if ((mask
& value
) != 0)
13840 /* If we already know that the enum type is neither unsigned, nor
13841 a flag type, no need to look at the rest of the enumerates. */
13842 if (!unsigned_enum
&& !flag_enum
)
13847 TYPE_UNSIGNED (type
) = 1;
13849 TYPE_FLAG_ENUM (type
) = 1;
13852 /* Given a DW_AT_enumeration_type die, set its type. We do not
13853 complete the type's fields yet, or create any symbols. */
13855 static struct type
*
13856 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13858 struct objfile
*objfile
= cu
->objfile
;
13860 struct attribute
*attr
;
13863 /* If the definition of this type lives in .debug_types, read that type.
13864 Don't follow DW_AT_specification though, that will take us back up
13865 the chain and we want to go down. */
13866 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
13869 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13871 /* The type's CU may not be the same as CU.
13872 Ensure TYPE is recorded with CU in die_type_hash. */
13873 return set_die_type (die
, type
, cu
);
13876 type
= alloc_type (objfile
);
13878 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
13879 name
= dwarf2_full_name (NULL
, die
, cu
);
13881 TYPE_TAG_NAME (type
) = name
;
13883 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13886 struct type
*underlying_type
= die_type (die
, cu
);
13888 TYPE_TARGET_TYPE (type
) = underlying_type
;
13891 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13894 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13898 TYPE_LENGTH (type
) = 0;
13901 /* The enumeration DIE can be incomplete. In Ada, any type can be
13902 declared as private in the package spec, and then defined only
13903 inside the package body. Such types are known as Taft Amendment
13904 Types. When another package uses such a type, an incomplete DIE
13905 may be generated by the compiler. */
13906 if (die_is_declaration (die
, cu
))
13907 TYPE_STUB (type
) = 1;
13909 /* Finish the creation of this type by using the enum's children.
13910 We must call this even when the underlying type has been provided
13911 so that we can determine if we're looking at a "flag" enum. */
13912 update_enumeration_type_from_children (die
, type
, cu
);
13914 /* If this type has an underlying type that is not a stub, then we
13915 may use its attributes. We always use the "unsigned" attribute
13916 in this situation, because ordinarily we guess whether the type
13917 is unsigned -- but the guess can be wrong and the underlying type
13918 can tell us the reality. However, we defer to a local size
13919 attribute if one exists, because this lets the compiler override
13920 the underlying type if needed. */
13921 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
13923 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
13924 if (TYPE_LENGTH (type
) == 0)
13925 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
13928 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
13930 return set_die_type (die
, type
, cu
);
13933 /* Given a pointer to a die which begins an enumeration, process all
13934 the dies that define the members of the enumeration, and create the
13935 symbol for the enumeration type.
13937 NOTE: We reverse the order of the element list. */
13940 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13942 struct type
*this_type
;
13944 this_type
= get_die_type (die
, cu
);
13945 if (this_type
== NULL
)
13946 this_type
= read_enumeration_type (die
, cu
);
13948 if (die
->child
!= NULL
)
13950 struct die_info
*child_die
;
13951 struct symbol
*sym
;
13952 struct field
*fields
= NULL
;
13953 int num_fields
= 0;
13956 child_die
= die
->child
;
13957 while (child_die
&& child_die
->tag
)
13959 if (child_die
->tag
!= DW_TAG_enumerator
)
13961 process_die (child_die
, cu
);
13965 name
= dwarf2_name (child_die
, cu
);
13968 sym
= new_symbol (child_die
, this_type
, cu
);
13970 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
13972 fields
= (struct field
*)
13974 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
13975 * sizeof (struct field
));
13978 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
13979 FIELD_TYPE (fields
[num_fields
]) = NULL
;
13980 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
13981 FIELD_BITSIZE (fields
[num_fields
]) = 0;
13987 child_die
= sibling_die (child_die
);
13992 TYPE_NFIELDS (this_type
) = num_fields
;
13993 TYPE_FIELDS (this_type
) = (struct field
*)
13994 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
13995 memcpy (TYPE_FIELDS (this_type
), fields
,
13996 sizeof (struct field
) * num_fields
);
14001 /* If we are reading an enum from a .debug_types unit, and the enum
14002 is a declaration, and the enum is not the signatured type in the
14003 unit, then we do not want to add a symbol for it. Adding a
14004 symbol would in some cases obscure the true definition of the
14005 enum, giving users an incomplete type when the definition is
14006 actually available. Note that we do not want to do this for all
14007 enums which are just declarations, because C++0x allows forward
14008 enum declarations. */
14009 if (cu
->per_cu
->is_debug_types
14010 && die_is_declaration (die
, cu
))
14012 struct signatured_type
*sig_type
;
14014 sig_type
= (struct signatured_type
*) cu
->per_cu
;
14015 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
14016 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
14020 new_symbol (die
, this_type
, cu
);
14023 /* Extract all information from a DW_TAG_array_type DIE and put it in
14024 the DIE's type field. For now, this only handles one dimensional
14027 static struct type
*
14028 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14030 struct objfile
*objfile
= cu
->objfile
;
14031 struct die_info
*child_die
;
14033 struct type
*element_type
, *range_type
, *index_type
;
14034 struct type
**range_types
= NULL
;
14035 struct attribute
*attr
;
14037 struct cleanup
*back_to
;
14039 unsigned int bit_stride
= 0;
14041 element_type
= die_type (die
, cu
);
14043 /* The die_type call above may have already set the type for this DIE. */
14044 type
= get_die_type (die
, cu
);
14048 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
14050 bit_stride
= DW_UNSND (attr
) * 8;
14052 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
14054 bit_stride
= DW_UNSND (attr
);
14056 /* Irix 6.2 native cc creates array types without children for
14057 arrays with unspecified length. */
14058 if (die
->child
== NULL
)
14060 index_type
= objfile_type (objfile
)->builtin_int
;
14061 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
14062 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
14064 return set_die_type (die
, type
, cu
);
14067 back_to
= make_cleanup (null_cleanup
, NULL
);
14068 child_die
= die
->child
;
14069 while (child_die
&& child_die
->tag
)
14071 if (child_die
->tag
== DW_TAG_subrange_type
)
14073 struct type
*child_type
= read_type_die (child_die
, cu
);
14075 if (child_type
!= NULL
)
14077 /* The range type was succesfully read. Save it for the
14078 array type creation. */
14079 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
14081 range_types
= (struct type
**)
14082 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
14083 * sizeof (struct type
*));
14085 make_cleanup (free_current_contents
, &range_types
);
14087 range_types
[ndim
++] = child_type
;
14090 child_die
= sibling_die (child_die
);
14093 /* Dwarf2 dimensions are output from left to right, create the
14094 necessary array types in backwards order. */
14096 type
= element_type
;
14098 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
14103 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
14109 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
14113 /* Understand Dwarf2 support for vector types (like they occur on
14114 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
14115 array type. This is not part of the Dwarf2/3 standard yet, but a
14116 custom vendor extension. The main difference between a regular
14117 array and the vector variant is that vectors are passed by value
14119 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
14121 make_vector_type (type
);
14123 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
14124 implementation may choose to implement triple vectors using this
14126 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14129 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
14130 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14132 complaint (&symfile_complaints
,
14133 _("DW_AT_byte_size for array type smaller "
14134 "than the total size of elements"));
14137 name
= dwarf2_name (die
, cu
);
14139 TYPE_NAME (type
) = name
;
14141 /* Install the type in the die. */
14142 set_die_type (die
, type
, cu
);
14144 /* set_die_type should be already done. */
14145 set_descriptive_type (type
, die
, cu
);
14147 do_cleanups (back_to
);
14152 static enum dwarf_array_dim_ordering
14153 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
14155 struct attribute
*attr
;
14157 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
14160 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
14162 /* GNU F77 is a special case, as at 08/2004 array type info is the
14163 opposite order to the dwarf2 specification, but data is still
14164 laid out as per normal fortran.
14166 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
14167 version checking. */
14169 if (cu
->language
== language_fortran
14170 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
14172 return DW_ORD_row_major
;
14175 switch (cu
->language_defn
->la_array_ordering
)
14177 case array_column_major
:
14178 return DW_ORD_col_major
;
14179 case array_row_major
:
14181 return DW_ORD_row_major
;
14185 /* Extract all information from a DW_TAG_set_type DIE and put it in
14186 the DIE's type field. */
14188 static struct type
*
14189 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14191 struct type
*domain_type
, *set_type
;
14192 struct attribute
*attr
;
14194 domain_type
= die_type (die
, cu
);
14196 /* The die_type call above may have already set the type for this DIE. */
14197 set_type
= get_die_type (die
, cu
);
14201 set_type
= create_set_type (NULL
, domain_type
);
14203 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14205 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
14207 return set_die_type (die
, set_type
, cu
);
14210 /* A helper for read_common_block that creates a locexpr baton.
14211 SYM is the symbol which we are marking as computed.
14212 COMMON_DIE is the DIE for the common block.
14213 COMMON_LOC is the location expression attribute for the common
14215 MEMBER_LOC is the location expression attribute for the particular
14216 member of the common block that we are processing.
14217 CU is the CU from which the above come. */
14220 mark_common_block_symbol_computed (struct symbol
*sym
,
14221 struct die_info
*common_die
,
14222 struct attribute
*common_loc
,
14223 struct attribute
*member_loc
,
14224 struct dwarf2_cu
*cu
)
14226 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14227 struct dwarf2_locexpr_baton
*baton
;
14229 unsigned int cu_off
;
14230 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
14231 LONGEST offset
= 0;
14233 gdb_assert (common_loc
&& member_loc
);
14234 gdb_assert (attr_form_is_block (common_loc
));
14235 gdb_assert (attr_form_is_block (member_loc
)
14236 || attr_form_is_constant (member_loc
));
14238 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14239 baton
->per_cu
= cu
->per_cu
;
14240 gdb_assert (baton
->per_cu
);
14242 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
14244 if (attr_form_is_constant (member_loc
))
14246 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
14247 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
14250 baton
->size
+= DW_BLOCK (member_loc
)->size
;
14252 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
14255 *ptr
++ = DW_OP_call4
;
14256 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
14257 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
14260 if (attr_form_is_constant (member_loc
))
14262 *ptr
++ = DW_OP_addr
;
14263 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
14264 ptr
+= cu
->header
.addr_size
;
14268 /* We have to copy the data here, because DW_OP_call4 will only
14269 use a DW_AT_location attribute. */
14270 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
14271 ptr
+= DW_BLOCK (member_loc
)->size
;
14274 *ptr
++ = DW_OP_plus
;
14275 gdb_assert (ptr
- baton
->data
== baton
->size
);
14277 SYMBOL_LOCATION_BATON (sym
) = baton
;
14278 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
14281 /* Create appropriate locally-scoped variables for all the
14282 DW_TAG_common_block entries. Also create a struct common_block
14283 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
14284 is used to sepate the common blocks name namespace from regular
14288 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
14290 struct attribute
*attr
;
14292 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14295 /* Support the .debug_loc offsets. */
14296 if (attr_form_is_block (attr
))
14300 else if (attr_form_is_section_offset (attr
))
14302 dwarf2_complex_location_expr_complaint ();
14307 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
14308 "common block member");
14313 if (die
->child
!= NULL
)
14315 struct objfile
*objfile
= cu
->objfile
;
14316 struct die_info
*child_die
;
14317 size_t n_entries
= 0, size
;
14318 struct common_block
*common_block
;
14319 struct symbol
*sym
;
14321 for (child_die
= die
->child
;
14322 child_die
&& child_die
->tag
;
14323 child_die
= sibling_die (child_die
))
14326 size
= (sizeof (struct common_block
)
14327 + (n_entries
- 1) * sizeof (struct symbol
*));
14329 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
14331 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
14332 common_block
->n_entries
= 0;
14334 for (child_die
= die
->child
;
14335 child_die
&& child_die
->tag
;
14336 child_die
= sibling_die (child_die
))
14338 /* Create the symbol in the DW_TAG_common_block block in the current
14340 sym
= new_symbol (child_die
, NULL
, cu
);
14343 struct attribute
*member_loc
;
14345 common_block
->contents
[common_block
->n_entries
++] = sym
;
14347 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
14351 /* GDB has handled this for a long time, but it is
14352 not specified by DWARF. It seems to have been
14353 emitted by gfortran at least as recently as:
14354 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
14355 complaint (&symfile_complaints
,
14356 _("Variable in common block has "
14357 "DW_AT_data_member_location "
14358 "- DIE at 0x%x [in module %s]"),
14359 to_underlying (child_die
->sect_off
),
14360 objfile_name (cu
->objfile
));
14362 if (attr_form_is_section_offset (member_loc
))
14363 dwarf2_complex_location_expr_complaint ();
14364 else if (attr_form_is_constant (member_loc
)
14365 || attr_form_is_block (member_loc
))
14368 mark_common_block_symbol_computed (sym
, die
, attr
,
14372 dwarf2_complex_location_expr_complaint ();
14377 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
14378 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
14382 /* Create a type for a C++ namespace. */
14384 static struct type
*
14385 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14387 struct objfile
*objfile
= cu
->objfile
;
14388 const char *previous_prefix
, *name
;
14392 /* For extensions, reuse the type of the original namespace. */
14393 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
14395 struct die_info
*ext_die
;
14396 struct dwarf2_cu
*ext_cu
= cu
;
14398 ext_die
= dwarf2_extension (die
, &ext_cu
);
14399 type
= read_type_die (ext_die
, ext_cu
);
14401 /* EXT_CU may not be the same as CU.
14402 Ensure TYPE is recorded with CU in die_type_hash. */
14403 return set_die_type (die
, type
, cu
);
14406 name
= namespace_name (die
, &is_anonymous
, cu
);
14408 /* Now build the name of the current namespace. */
14410 previous_prefix
= determine_prefix (die
, cu
);
14411 if (previous_prefix
[0] != '\0')
14412 name
= typename_concat (&objfile
->objfile_obstack
,
14413 previous_prefix
, name
, 0, cu
);
14415 /* Create the type. */
14416 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
14417 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14419 return set_die_type (die
, type
, cu
);
14422 /* Read a namespace scope. */
14425 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
14427 struct objfile
*objfile
= cu
->objfile
;
14430 /* Add a symbol associated to this if we haven't seen the namespace
14431 before. Also, add a using directive if it's an anonymous
14434 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
14438 type
= read_type_die (die
, cu
);
14439 new_symbol (die
, type
, cu
);
14441 namespace_name (die
, &is_anonymous
, cu
);
14444 const char *previous_prefix
= determine_prefix (die
, cu
);
14446 add_using_directive (using_directives (cu
->language
),
14447 previous_prefix
, TYPE_NAME (type
), NULL
,
14448 NULL
, NULL
, 0, &objfile
->objfile_obstack
);
14452 if (die
->child
!= NULL
)
14454 struct die_info
*child_die
= die
->child
;
14456 while (child_die
&& child_die
->tag
)
14458 process_die (child_die
, cu
);
14459 child_die
= sibling_die (child_die
);
14464 /* Read a Fortran module as type. This DIE can be only a declaration used for
14465 imported module. Still we need that type as local Fortran "use ... only"
14466 declaration imports depend on the created type in determine_prefix. */
14468 static struct type
*
14469 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14471 struct objfile
*objfile
= cu
->objfile
;
14472 const char *module_name
;
14475 module_name
= dwarf2_name (die
, cu
);
14477 complaint (&symfile_complaints
,
14478 _("DW_TAG_module has no name, offset 0x%x"),
14479 to_underlying (die
->sect_off
));
14480 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
14482 /* determine_prefix uses TYPE_TAG_NAME. */
14483 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14485 return set_die_type (die
, type
, cu
);
14488 /* Read a Fortran module. */
14491 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
14493 struct die_info
*child_die
= die
->child
;
14496 type
= read_type_die (die
, cu
);
14497 new_symbol (die
, type
, cu
);
14499 while (child_die
&& child_die
->tag
)
14501 process_die (child_die
, cu
);
14502 child_die
= sibling_die (child_die
);
14506 /* Return the name of the namespace represented by DIE. Set
14507 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
14510 static const char *
14511 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
14513 struct die_info
*current_die
;
14514 const char *name
= NULL
;
14516 /* Loop through the extensions until we find a name. */
14518 for (current_die
= die
;
14519 current_die
!= NULL
;
14520 current_die
= dwarf2_extension (die
, &cu
))
14522 /* We don't use dwarf2_name here so that we can detect the absence
14523 of a name -> anonymous namespace. */
14524 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
14530 /* Is it an anonymous namespace? */
14532 *is_anonymous
= (name
== NULL
);
14534 name
= CP_ANONYMOUS_NAMESPACE_STR
;
14539 /* Extract all information from a DW_TAG_pointer_type DIE and add to
14540 the user defined type vector. */
14542 static struct type
*
14543 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14545 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
14546 struct comp_unit_head
*cu_header
= &cu
->header
;
14548 struct attribute
*attr_byte_size
;
14549 struct attribute
*attr_address_class
;
14550 int byte_size
, addr_class
;
14551 struct type
*target_type
;
14553 target_type
= die_type (die
, cu
);
14555 /* The die_type call above may have already set the type for this DIE. */
14556 type
= get_die_type (die
, cu
);
14560 type
= lookup_pointer_type (target_type
);
14562 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14563 if (attr_byte_size
)
14564 byte_size
= DW_UNSND (attr_byte_size
);
14566 byte_size
= cu_header
->addr_size
;
14568 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
14569 if (attr_address_class
)
14570 addr_class
= DW_UNSND (attr_address_class
);
14572 addr_class
= DW_ADDR_none
;
14574 /* If the pointer size or address class is different than the
14575 default, create a type variant marked as such and set the
14576 length accordingly. */
14577 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
14579 if (gdbarch_address_class_type_flags_p (gdbarch
))
14583 type_flags
= gdbarch_address_class_type_flags
14584 (gdbarch
, byte_size
, addr_class
);
14585 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
14587 type
= make_type_with_address_space (type
, type_flags
);
14589 else if (TYPE_LENGTH (type
) != byte_size
)
14591 complaint (&symfile_complaints
,
14592 _("invalid pointer size %d"), byte_size
);
14596 /* Should we also complain about unhandled address classes? */
14600 TYPE_LENGTH (type
) = byte_size
;
14601 return set_die_type (die
, type
, cu
);
14604 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
14605 the user defined type vector. */
14607 static struct type
*
14608 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14611 struct type
*to_type
;
14612 struct type
*domain
;
14614 to_type
= die_type (die
, cu
);
14615 domain
= die_containing_type (die
, cu
);
14617 /* The calls above may have already set the type for this DIE. */
14618 type
= get_die_type (die
, cu
);
14622 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
14623 type
= lookup_methodptr_type (to_type
);
14624 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
14626 struct type
*new_type
= alloc_type (cu
->objfile
);
14628 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
14629 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
14630 TYPE_VARARGS (to_type
));
14631 type
= lookup_methodptr_type (new_type
);
14634 type
= lookup_memberptr_type (to_type
, domain
);
14636 return set_die_type (die
, type
, cu
);
14639 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
14640 the user defined type vector. */
14642 static struct type
*
14643 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
14644 enum type_code refcode
)
14646 struct comp_unit_head
*cu_header
= &cu
->header
;
14647 struct type
*type
, *target_type
;
14648 struct attribute
*attr
;
14650 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
14652 target_type
= die_type (die
, cu
);
14654 /* The die_type call above may have already set the type for this DIE. */
14655 type
= get_die_type (die
, cu
);
14659 type
= lookup_reference_type (target_type
, refcode
);
14660 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14663 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14667 TYPE_LENGTH (type
) = cu_header
->addr_size
;
14669 return set_die_type (die
, type
, cu
);
14672 /* Add the given cv-qualifiers to the element type of the array. GCC
14673 outputs DWARF type qualifiers that apply to an array, not the
14674 element type. But GDB relies on the array element type to carry
14675 the cv-qualifiers. This mimics section 6.7.3 of the C99
14678 static struct type
*
14679 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
14680 struct type
*base_type
, int cnst
, int voltl
)
14682 struct type
*el_type
, *inner_array
;
14684 base_type
= copy_type (base_type
);
14685 inner_array
= base_type
;
14687 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
14689 TYPE_TARGET_TYPE (inner_array
) =
14690 copy_type (TYPE_TARGET_TYPE (inner_array
));
14691 inner_array
= TYPE_TARGET_TYPE (inner_array
);
14694 el_type
= TYPE_TARGET_TYPE (inner_array
);
14695 cnst
|= TYPE_CONST (el_type
);
14696 voltl
|= TYPE_VOLATILE (el_type
);
14697 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
14699 return set_die_type (die
, base_type
, cu
);
14702 static struct type
*
14703 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14705 struct type
*base_type
, *cv_type
;
14707 base_type
= die_type (die
, cu
);
14709 /* The die_type call above may have already set the type for this DIE. */
14710 cv_type
= get_die_type (die
, cu
);
14714 /* In case the const qualifier is applied to an array type, the element type
14715 is so qualified, not the array type (section 6.7.3 of C99). */
14716 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
14717 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
14719 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
14720 return set_die_type (die
, cv_type
, cu
);
14723 static struct type
*
14724 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14726 struct type
*base_type
, *cv_type
;
14728 base_type
= die_type (die
, cu
);
14730 /* The die_type call above may have already set the type for this DIE. */
14731 cv_type
= get_die_type (die
, cu
);
14735 /* In case the volatile qualifier is applied to an array type, the
14736 element type is so qualified, not the array type (section 6.7.3
14738 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
14739 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
14741 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
14742 return set_die_type (die
, cv_type
, cu
);
14745 /* Handle DW_TAG_restrict_type. */
14747 static struct type
*
14748 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14750 struct type
*base_type
, *cv_type
;
14752 base_type
= die_type (die
, cu
);
14754 /* The die_type call above may have already set the type for this DIE. */
14755 cv_type
= get_die_type (die
, cu
);
14759 cv_type
= make_restrict_type (base_type
);
14760 return set_die_type (die
, cv_type
, cu
);
14763 /* Handle DW_TAG_atomic_type. */
14765 static struct type
*
14766 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14768 struct type
*base_type
, *cv_type
;
14770 base_type
= die_type (die
, cu
);
14772 /* The die_type call above may have already set the type for this DIE. */
14773 cv_type
= get_die_type (die
, cu
);
14777 cv_type
= make_atomic_type (base_type
);
14778 return set_die_type (die
, cv_type
, cu
);
14781 /* Extract all information from a DW_TAG_string_type DIE and add to
14782 the user defined type vector. It isn't really a user defined type,
14783 but it behaves like one, with other DIE's using an AT_user_def_type
14784 attribute to reference it. */
14786 static struct type
*
14787 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14789 struct objfile
*objfile
= cu
->objfile
;
14790 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14791 struct type
*type
, *range_type
, *index_type
, *char_type
;
14792 struct attribute
*attr
;
14793 unsigned int length
;
14795 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
14798 length
= DW_UNSND (attr
);
14802 /* Check for the DW_AT_byte_size attribute. */
14803 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14806 length
= DW_UNSND (attr
);
14814 index_type
= objfile_type (objfile
)->builtin_int
;
14815 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
14816 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
14817 type
= create_string_type (NULL
, char_type
, range_type
);
14819 return set_die_type (die
, type
, cu
);
14822 /* Assuming that DIE corresponds to a function, returns nonzero
14823 if the function is prototyped. */
14826 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
14828 struct attribute
*attr
;
14830 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
14831 if (attr
&& (DW_UNSND (attr
) != 0))
14834 /* The DWARF standard implies that the DW_AT_prototyped attribute
14835 is only meaninful for C, but the concept also extends to other
14836 languages that allow unprototyped functions (Eg: Objective C).
14837 For all other languages, assume that functions are always
14839 if (cu
->language
!= language_c
14840 && cu
->language
!= language_objc
14841 && cu
->language
!= language_opencl
)
14844 /* RealView does not emit DW_AT_prototyped. We can not distinguish
14845 prototyped and unprototyped functions; default to prototyped,
14846 since that is more common in modern code (and RealView warns
14847 about unprototyped functions). */
14848 if (producer_is_realview (cu
->producer
))
14854 /* Handle DIES due to C code like:
14858 int (*funcp)(int a, long l);
14862 ('funcp' generates a DW_TAG_subroutine_type DIE). */
14864 static struct type
*
14865 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14867 struct objfile
*objfile
= cu
->objfile
;
14868 struct type
*type
; /* Type that this function returns. */
14869 struct type
*ftype
; /* Function that returns above type. */
14870 struct attribute
*attr
;
14872 type
= die_type (die
, cu
);
14874 /* The die_type call above may have already set the type for this DIE. */
14875 ftype
= get_die_type (die
, cu
);
14879 ftype
= lookup_function_type (type
);
14881 if (prototyped_function_p (die
, cu
))
14882 TYPE_PROTOTYPED (ftype
) = 1;
14884 /* Store the calling convention in the type if it's available in
14885 the subroutine die. Otherwise set the calling convention to
14886 the default value DW_CC_normal. */
14887 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
14889 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
14890 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
14891 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
14893 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
14895 /* Record whether the function returns normally to its caller or not
14896 if the DWARF producer set that information. */
14897 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
14898 if (attr
&& (DW_UNSND (attr
) != 0))
14899 TYPE_NO_RETURN (ftype
) = 1;
14901 /* We need to add the subroutine type to the die immediately so
14902 we don't infinitely recurse when dealing with parameters
14903 declared as the same subroutine type. */
14904 set_die_type (die
, ftype
, cu
);
14906 if (die
->child
!= NULL
)
14908 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
14909 struct die_info
*child_die
;
14910 int nparams
, iparams
;
14912 /* Count the number of parameters.
14913 FIXME: GDB currently ignores vararg functions, but knows about
14914 vararg member functions. */
14916 child_die
= die
->child
;
14917 while (child_die
&& child_die
->tag
)
14919 if (child_die
->tag
== DW_TAG_formal_parameter
)
14921 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
14922 TYPE_VARARGS (ftype
) = 1;
14923 child_die
= sibling_die (child_die
);
14926 /* Allocate storage for parameters and fill them in. */
14927 TYPE_NFIELDS (ftype
) = nparams
;
14928 TYPE_FIELDS (ftype
) = (struct field
*)
14929 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
14931 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
14932 even if we error out during the parameters reading below. */
14933 for (iparams
= 0; iparams
< nparams
; iparams
++)
14934 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
14937 child_die
= die
->child
;
14938 while (child_die
&& child_die
->tag
)
14940 if (child_die
->tag
== DW_TAG_formal_parameter
)
14942 struct type
*arg_type
;
14944 /* DWARF version 2 has no clean way to discern C++
14945 static and non-static member functions. G++ helps
14946 GDB by marking the first parameter for non-static
14947 member functions (which is the this pointer) as
14948 artificial. We pass this information to
14949 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
14951 DWARF version 3 added DW_AT_object_pointer, which GCC
14952 4.5 does not yet generate. */
14953 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
14955 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
14957 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
14958 arg_type
= die_type (child_die
, cu
);
14960 /* RealView does not mark THIS as const, which the testsuite
14961 expects. GCC marks THIS as const in method definitions,
14962 but not in the class specifications (GCC PR 43053). */
14963 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
14964 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
14967 struct dwarf2_cu
*arg_cu
= cu
;
14968 const char *name
= dwarf2_name (child_die
, cu
);
14970 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
14973 /* If the compiler emits this, use it. */
14974 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
14977 else if (name
&& strcmp (name
, "this") == 0)
14978 /* Function definitions will have the argument names. */
14980 else if (name
== NULL
&& iparams
== 0)
14981 /* Declarations may not have the names, so like
14982 elsewhere in GDB, assume an artificial first
14983 argument is "this". */
14987 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
14991 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
14994 child_die
= sibling_die (child_die
);
15001 static struct type
*
15002 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
15004 struct objfile
*objfile
= cu
->objfile
;
15005 const char *name
= NULL
;
15006 struct type
*this_type
, *target_type
;
15008 name
= dwarf2_full_name (NULL
, die
, cu
);
15009 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
15010 TYPE_TARGET_STUB (this_type
) = 1;
15011 set_die_type (die
, this_type
, cu
);
15012 target_type
= die_type (die
, cu
);
15013 if (target_type
!= this_type
)
15014 TYPE_TARGET_TYPE (this_type
) = target_type
;
15017 /* Self-referential typedefs are, it seems, not allowed by the DWARF
15018 spec and cause infinite loops in GDB. */
15019 complaint (&symfile_complaints
,
15020 _("Self-referential DW_TAG_typedef "
15021 "- DIE at 0x%x [in module %s]"),
15022 to_underlying (die
->sect_off
), objfile_name (objfile
));
15023 TYPE_TARGET_TYPE (this_type
) = NULL
;
15028 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
15029 (which may be different from NAME) to the architecture back-end to allow
15030 it to guess the correct format if necessary. */
15032 static struct type
*
15033 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
15034 const char *name_hint
)
15036 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15037 const struct floatformat
**format
;
15040 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
15042 type
= init_float_type (objfile
, bits
, name
, format
);
15044 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
/ TARGET_CHAR_BIT
, name
);
15049 /* Find a representation of a given base type and install
15050 it in the TYPE field of the die. */
15052 static struct type
*
15053 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15055 struct objfile
*objfile
= cu
->objfile
;
15057 struct attribute
*attr
;
15058 int encoding
= 0, bits
= 0;
15061 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
15064 encoding
= DW_UNSND (attr
);
15066 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15069 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
15071 name
= dwarf2_name (die
, cu
);
15074 complaint (&symfile_complaints
,
15075 _("DW_AT_name missing from DW_TAG_base_type"));
15080 case DW_ATE_address
:
15081 /* Turn DW_ATE_address into a void * pointer. */
15082 type
= init_type (objfile
, TYPE_CODE_VOID
, 1, NULL
);
15083 type
= init_pointer_type (objfile
, bits
, name
, type
);
15085 case DW_ATE_boolean
:
15086 type
= init_boolean_type (objfile
, bits
, 1, name
);
15088 case DW_ATE_complex_float
:
15089 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
15090 type
= init_complex_type (objfile
, name
, type
);
15092 case DW_ATE_decimal_float
:
15093 type
= init_decfloat_type (objfile
, bits
, name
);
15096 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
15098 case DW_ATE_signed
:
15099 type
= init_integer_type (objfile
, bits
, 0, name
);
15101 case DW_ATE_unsigned
:
15102 if (cu
->language
== language_fortran
15104 && startswith (name
, "character("))
15105 type
= init_character_type (objfile
, bits
, 1, name
);
15107 type
= init_integer_type (objfile
, bits
, 1, name
);
15109 case DW_ATE_signed_char
:
15110 if (cu
->language
== language_ada
|| cu
->language
== language_m2
15111 || cu
->language
== language_pascal
15112 || cu
->language
== language_fortran
)
15113 type
= init_character_type (objfile
, bits
, 0, name
);
15115 type
= init_integer_type (objfile
, bits
, 0, name
);
15117 case DW_ATE_unsigned_char
:
15118 if (cu
->language
== language_ada
|| cu
->language
== language_m2
15119 || cu
->language
== language_pascal
15120 || cu
->language
== language_fortran
15121 || cu
->language
== language_rust
)
15122 type
= init_character_type (objfile
, bits
, 1, name
);
15124 type
= init_integer_type (objfile
, bits
, 1, name
);
15128 gdbarch
*arch
= get_objfile_arch (objfile
);
15131 type
= builtin_type (arch
)->builtin_char16
;
15132 else if (bits
== 32)
15133 type
= builtin_type (arch
)->builtin_char32
;
15136 complaint (&symfile_complaints
,
15137 _("unsupported DW_ATE_UTF bit size: '%d'"),
15139 type
= init_integer_type (objfile
, bits
, 1, name
);
15141 return set_die_type (die
, type
, cu
);
15146 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
15147 dwarf_type_encoding_name (encoding
));
15148 type
= init_type (objfile
, TYPE_CODE_ERROR
,
15149 bits
/ TARGET_CHAR_BIT
, name
);
15153 if (name
&& strcmp (name
, "char") == 0)
15154 TYPE_NOSIGN (type
) = 1;
15156 return set_die_type (die
, type
, cu
);
15159 /* Parse dwarf attribute if it's a block, reference or constant and put the
15160 resulting value of the attribute into struct bound_prop.
15161 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
15164 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
15165 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
15167 struct dwarf2_property_baton
*baton
;
15168 struct obstack
*obstack
= &cu
->objfile
->objfile_obstack
;
15170 if (attr
== NULL
|| prop
== NULL
)
15173 if (attr_form_is_block (attr
))
15175 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15176 baton
->referenced_type
= NULL
;
15177 baton
->locexpr
.per_cu
= cu
->per_cu
;
15178 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
15179 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
15180 prop
->data
.baton
= baton
;
15181 prop
->kind
= PROP_LOCEXPR
;
15182 gdb_assert (prop
->data
.baton
!= NULL
);
15184 else if (attr_form_is_ref (attr
))
15186 struct dwarf2_cu
*target_cu
= cu
;
15187 struct die_info
*target_die
;
15188 struct attribute
*target_attr
;
15190 target_die
= follow_die_ref (die
, attr
, &target_cu
);
15191 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
15192 if (target_attr
== NULL
)
15193 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
15195 if (target_attr
== NULL
)
15198 switch (target_attr
->name
)
15200 case DW_AT_location
:
15201 if (attr_form_is_section_offset (target_attr
))
15203 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15204 baton
->referenced_type
= die_type (target_die
, target_cu
);
15205 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
15206 prop
->data
.baton
= baton
;
15207 prop
->kind
= PROP_LOCLIST
;
15208 gdb_assert (prop
->data
.baton
!= NULL
);
15210 else if (attr_form_is_block (target_attr
))
15212 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15213 baton
->referenced_type
= die_type (target_die
, target_cu
);
15214 baton
->locexpr
.per_cu
= cu
->per_cu
;
15215 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
15216 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
15217 prop
->data
.baton
= baton
;
15218 prop
->kind
= PROP_LOCEXPR
;
15219 gdb_assert (prop
->data
.baton
!= NULL
);
15223 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15224 "dynamic property");
15228 case DW_AT_data_member_location
:
15232 if (!handle_data_member_location (target_die
, target_cu
,
15236 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15237 baton
->referenced_type
= read_type_die (target_die
->parent
,
15239 baton
->offset_info
.offset
= offset
;
15240 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
15241 prop
->data
.baton
= baton
;
15242 prop
->kind
= PROP_ADDR_OFFSET
;
15247 else if (attr_form_is_constant (attr
))
15249 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
15250 prop
->kind
= PROP_CONST
;
15254 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
15255 dwarf2_name (die
, cu
));
15262 /* Read the given DW_AT_subrange DIE. */
15264 static struct type
*
15265 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15267 struct type
*base_type
, *orig_base_type
;
15268 struct type
*range_type
;
15269 struct attribute
*attr
;
15270 struct dynamic_prop low
, high
;
15271 int low_default_is_valid
;
15272 int high_bound_is_count
= 0;
15274 LONGEST negative_mask
;
15276 orig_base_type
= die_type (die
, cu
);
15277 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
15278 whereas the real type might be. So, we use ORIG_BASE_TYPE when
15279 creating the range type, but we use the result of check_typedef
15280 when examining properties of the type. */
15281 base_type
= check_typedef (orig_base_type
);
15283 /* The die_type call above may have already set the type for this DIE. */
15284 range_type
= get_die_type (die
, cu
);
15288 low
.kind
= PROP_CONST
;
15289 high
.kind
= PROP_CONST
;
15290 high
.data
.const_val
= 0;
15292 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
15293 omitting DW_AT_lower_bound. */
15294 switch (cu
->language
)
15297 case language_cplus
:
15298 low
.data
.const_val
= 0;
15299 low_default_is_valid
= 1;
15301 case language_fortran
:
15302 low
.data
.const_val
= 1;
15303 low_default_is_valid
= 1;
15306 case language_objc
:
15307 case language_rust
:
15308 low
.data
.const_val
= 0;
15309 low_default_is_valid
= (cu
->header
.version
>= 4);
15313 case language_pascal
:
15314 low
.data
.const_val
= 1;
15315 low_default_is_valid
= (cu
->header
.version
>= 4);
15318 low
.data
.const_val
= 0;
15319 low_default_is_valid
= 0;
15323 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
15325 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
15326 else if (!low_default_is_valid
)
15327 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
15328 "- DIE at 0x%x [in module %s]"),
15329 to_underlying (die
->sect_off
), objfile_name (cu
->objfile
));
15331 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
15332 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
15334 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
15335 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
15337 /* If bounds are constant do the final calculation here. */
15338 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
15339 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
15341 high_bound_is_count
= 1;
15345 /* Dwarf-2 specifications explicitly allows to create subrange types
15346 without specifying a base type.
15347 In that case, the base type must be set to the type of
15348 the lower bound, upper bound or count, in that order, if any of these
15349 three attributes references an object that has a type.
15350 If no base type is found, the Dwarf-2 specifications say that
15351 a signed integer type of size equal to the size of an address should
15353 For the following C code: `extern char gdb_int [];'
15354 GCC produces an empty range DIE.
15355 FIXME: muller/2010-05-28: Possible references to object for low bound,
15356 high bound or count are not yet handled by this code. */
15357 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
15359 struct objfile
*objfile
= cu
->objfile
;
15360 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15361 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
15362 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
15364 /* Test "int", "long int", and "long long int" objfile types,
15365 and select the first one having a size above or equal to the
15366 architecture address size. */
15367 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15368 base_type
= int_type
;
15371 int_type
= objfile_type (objfile
)->builtin_long
;
15372 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15373 base_type
= int_type
;
15376 int_type
= objfile_type (objfile
)->builtin_long_long
;
15377 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15378 base_type
= int_type
;
15383 /* Normally, the DWARF producers are expected to use a signed
15384 constant form (Eg. DW_FORM_sdata) to express negative bounds.
15385 But this is unfortunately not always the case, as witnessed
15386 with GCC, for instance, where the ambiguous DW_FORM_dataN form
15387 is used instead. To work around that ambiguity, we treat
15388 the bounds as signed, and thus sign-extend their values, when
15389 the base type is signed. */
15391 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
15392 if (low
.kind
== PROP_CONST
15393 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
15394 low
.data
.const_val
|= negative_mask
;
15395 if (high
.kind
== PROP_CONST
15396 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
15397 high
.data
.const_val
|= negative_mask
;
15399 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
15401 if (high_bound_is_count
)
15402 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
15404 /* Ada expects an empty array on no boundary attributes. */
15405 if (attr
== NULL
&& cu
->language
!= language_ada
)
15406 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
15408 name
= dwarf2_name (die
, cu
);
15410 TYPE_NAME (range_type
) = name
;
15412 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15414 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
15416 set_die_type (die
, range_type
, cu
);
15418 /* set_die_type should be already done. */
15419 set_descriptive_type (range_type
, die
, cu
);
15424 static struct type
*
15425 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15429 /* For now, we only support the C meaning of an unspecified type: void. */
15431 type
= init_type (cu
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
15432 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
15434 return set_die_type (die
, type
, cu
);
15437 /* Read a single die and all its descendents. Set the die's sibling
15438 field to NULL; set other fields in the die correctly, and set all
15439 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
15440 location of the info_ptr after reading all of those dies. PARENT
15441 is the parent of the die in question. */
15443 static struct die_info
*
15444 read_die_and_children (const struct die_reader_specs
*reader
,
15445 const gdb_byte
*info_ptr
,
15446 const gdb_byte
**new_info_ptr
,
15447 struct die_info
*parent
)
15449 struct die_info
*die
;
15450 const gdb_byte
*cur_ptr
;
15453 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
15456 *new_info_ptr
= cur_ptr
;
15459 store_in_ref_table (die
, reader
->cu
);
15462 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
15466 *new_info_ptr
= cur_ptr
;
15469 die
->sibling
= NULL
;
15470 die
->parent
= parent
;
15474 /* Read a die, all of its descendents, and all of its siblings; set
15475 all of the fields of all of the dies correctly. Arguments are as
15476 in read_die_and_children. */
15478 static struct die_info
*
15479 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
15480 const gdb_byte
*info_ptr
,
15481 const gdb_byte
**new_info_ptr
,
15482 struct die_info
*parent
)
15484 struct die_info
*first_die
, *last_sibling
;
15485 const gdb_byte
*cur_ptr
;
15487 cur_ptr
= info_ptr
;
15488 first_die
= last_sibling
= NULL
;
15492 struct die_info
*die
15493 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
15497 *new_info_ptr
= cur_ptr
;
15504 last_sibling
->sibling
= die
;
15506 last_sibling
= die
;
15510 /* Read a die, all of its descendents, and all of its siblings; set
15511 all of the fields of all of the dies correctly. Arguments are as
15512 in read_die_and_children.
15513 This the main entry point for reading a DIE and all its children. */
15515 static struct die_info
*
15516 read_die_and_siblings (const struct die_reader_specs
*reader
,
15517 const gdb_byte
*info_ptr
,
15518 const gdb_byte
**new_info_ptr
,
15519 struct die_info
*parent
)
15521 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
15522 new_info_ptr
, parent
);
15524 if (dwarf_die_debug
)
15526 fprintf_unfiltered (gdb_stdlog
,
15527 "Read die from %s@0x%x of %s:\n",
15528 get_section_name (reader
->die_section
),
15529 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15530 bfd_get_filename (reader
->abfd
));
15531 dump_die (die
, dwarf_die_debug
);
15537 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
15539 The caller is responsible for filling in the extra attributes
15540 and updating (*DIEP)->num_attrs.
15541 Set DIEP to point to a newly allocated die with its information,
15542 except for its child, sibling, and parent fields.
15543 Set HAS_CHILDREN to tell whether the die has children or not. */
15545 static const gdb_byte
*
15546 read_full_die_1 (const struct die_reader_specs
*reader
,
15547 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15548 int *has_children
, int num_extra_attrs
)
15550 unsigned int abbrev_number
, bytes_read
, i
;
15551 struct abbrev_info
*abbrev
;
15552 struct die_info
*die
;
15553 struct dwarf2_cu
*cu
= reader
->cu
;
15554 bfd
*abfd
= reader
->abfd
;
15556 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
15557 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15558 info_ptr
+= bytes_read
;
15559 if (!abbrev_number
)
15566 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
15568 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
15570 bfd_get_filename (abfd
));
15572 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
15573 die
->sect_off
= sect_off
;
15574 die
->tag
= abbrev
->tag
;
15575 die
->abbrev
= abbrev_number
;
15577 /* Make the result usable.
15578 The caller needs to update num_attrs after adding the extra
15580 die
->num_attrs
= abbrev
->num_attrs
;
15582 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
15583 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
15587 *has_children
= abbrev
->has_children
;
15591 /* Read a die and all its attributes.
15592 Set DIEP to point to a newly allocated die with its information,
15593 except for its child, sibling, and parent fields.
15594 Set HAS_CHILDREN to tell whether the die has children or not. */
15596 static const gdb_byte
*
15597 read_full_die (const struct die_reader_specs
*reader
,
15598 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15601 const gdb_byte
*result
;
15603 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
15605 if (dwarf_die_debug
)
15607 fprintf_unfiltered (gdb_stdlog
,
15608 "Read die from %s@0x%x of %s:\n",
15609 get_section_name (reader
->die_section
),
15610 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15611 bfd_get_filename (reader
->abfd
));
15612 dump_die (*diep
, dwarf_die_debug
);
15618 /* Abbreviation tables.
15620 In DWARF version 2, the description of the debugging information is
15621 stored in a separate .debug_abbrev section. Before we read any
15622 dies from a section we read in all abbreviations and install them
15623 in a hash table. */
15625 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
15627 static struct abbrev_info
*
15628 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
15630 struct abbrev_info
*abbrev
;
15632 abbrev
= XOBNEW (&abbrev_table
->abbrev_obstack
, struct abbrev_info
);
15633 memset (abbrev
, 0, sizeof (struct abbrev_info
));
15638 /* Add an abbreviation to the table. */
15641 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
15642 unsigned int abbrev_number
,
15643 struct abbrev_info
*abbrev
)
15645 unsigned int hash_number
;
15647 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
15648 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
15649 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
15652 /* Look up an abbrev in the table.
15653 Returns NULL if the abbrev is not found. */
15655 static struct abbrev_info
*
15656 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
15657 unsigned int abbrev_number
)
15659 unsigned int hash_number
;
15660 struct abbrev_info
*abbrev
;
15662 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
15663 abbrev
= abbrev_table
->abbrevs
[hash_number
];
15667 if (abbrev
->number
== abbrev_number
)
15669 abbrev
= abbrev
->next
;
15674 /* Read in an abbrev table. */
15676 static struct abbrev_table
*
15677 abbrev_table_read_table (struct dwarf2_section_info
*section
,
15678 sect_offset sect_off
)
15680 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15681 bfd
*abfd
= get_section_bfd_owner (section
);
15682 struct abbrev_table
*abbrev_table
;
15683 const gdb_byte
*abbrev_ptr
;
15684 struct abbrev_info
*cur_abbrev
;
15685 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
15686 unsigned int abbrev_form
;
15687 struct attr_abbrev
*cur_attrs
;
15688 unsigned int allocated_attrs
;
15690 abbrev_table
= XNEW (struct abbrev_table
);
15691 abbrev_table
->sect_off
= sect_off
;
15692 obstack_init (&abbrev_table
->abbrev_obstack
);
15693 abbrev_table
->abbrevs
=
15694 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct abbrev_info
*,
15696 memset (abbrev_table
->abbrevs
, 0,
15697 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
15699 dwarf2_read_section (objfile
, section
);
15700 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
15701 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15702 abbrev_ptr
+= bytes_read
;
15704 allocated_attrs
= ATTR_ALLOC_CHUNK
;
15705 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
15707 /* Loop until we reach an abbrev number of 0. */
15708 while (abbrev_number
)
15710 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
15712 /* read in abbrev header */
15713 cur_abbrev
->number
= abbrev_number
;
15715 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15716 abbrev_ptr
+= bytes_read
;
15717 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
15720 /* now read in declarations */
15723 LONGEST implicit_const
;
15725 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15726 abbrev_ptr
+= bytes_read
;
15727 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15728 abbrev_ptr
+= bytes_read
;
15729 if (abbrev_form
== DW_FORM_implicit_const
)
15731 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
15733 abbrev_ptr
+= bytes_read
;
15737 /* Initialize it due to a false compiler warning. */
15738 implicit_const
= -1;
15741 if (abbrev_name
== 0)
15744 if (cur_abbrev
->num_attrs
== allocated_attrs
)
15746 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
15748 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
15751 cur_attrs
[cur_abbrev
->num_attrs
].name
15752 = (enum dwarf_attribute
) abbrev_name
;
15753 cur_attrs
[cur_abbrev
->num_attrs
].form
15754 = (enum dwarf_form
) abbrev_form
;
15755 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
15756 ++cur_abbrev
->num_attrs
;
15759 cur_abbrev
->attrs
=
15760 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
15761 cur_abbrev
->num_attrs
);
15762 memcpy (cur_abbrev
->attrs
, cur_attrs
,
15763 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
15765 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
15767 /* Get next abbreviation.
15768 Under Irix6 the abbreviations for a compilation unit are not
15769 always properly terminated with an abbrev number of 0.
15770 Exit loop if we encounter an abbreviation which we have
15771 already read (which means we are about to read the abbreviations
15772 for the next compile unit) or if the end of the abbreviation
15773 table is reached. */
15774 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
15776 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15777 abbrev_ptr
+= bytes_read
;
15778 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
15783 return abbrev_table
;
15786 /* Free the resources held by ABBREV_TABLE. */
15789 abbrev_table_free (struct abbrev_table
*abbrev_table
)
15791 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
15792 xfree (abbrev_table
);
15795 /* Same as abbrev_table_free but as a cleanup.
15796 We pass in a pointer to the pointer to the table so that we can
15797 set the pointer to NULL when we're done. It also simplifies
15798 build_type_psymtabs_1. */
15801 abbrev_table_free_cleanup (void *table_ptr
)
15803 struct abbrev_table
**abbrev_table_ptr
= (struct abbrev_table
**) table_ptr
;
15805 if (*abbrev_table_ptr
!= NULL
)
15806 abbrev_table_free (*abbrev_table_ptr
);
15807 *abbrev_table_ptr
= NULL
;
15810 /* Read the abbrev table for CU from ABBREV_SECTION. */
15813 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
15814 struct dwarf2_section_info
*abbrev_section
)
15817 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_sect_off
);
15820 /* Release the memory used by the abbrev table for a compilation unit. */
15823 dwarf2_free_abbrev_table (void *ptr_to_cu
)
15825 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr_to_cu
;
15827 if (cu
->abbrev_table
!= NULL
)
15828 abbrev_table_free (cu
->abbrev_table
);
15829 /* Set this to NULL so that we SEGV if we try to read it later,
15830 and also because free_comp_unit verifies this is NULL. */
15831 cu
->abbrev_table
= NULL
;
15834 /* Returns nonzero if TAG represents a type that we might generate a partial
15838 is_type_tag_for_partial (int tag
)
15843 /* Some types that would be reasonable to generate partial symbols for,
15844 that we don't at present. */
15845 case DW_TAG_array_type
:
15846 case DW_TAG_file_type
:
15847 case DW_TAG_ptr_to_member_type
:
15848 case DW_TAG_set_type
:
15849 case DW_TAG_string_type
:
15850 case DW_TAG_subroutine_type
:
15852 case DW_TAG_base_type
:
15853 case DW_TAG_class_type
:
15854 case DW_TAG_interface_type
:
15855 case DW_TAG_enumeration_type
:
15856 case DW_TAG_structure_type
:
15857 case DW_TAG_subrange_type
:
15858 case DW_TAG_typedef
:
15859 case DW_TAG_union_type
:
15866 /* Load all DIEs that are interesting for partial symbols into memory. */
15868 static struct partial_die_info
*
15869 load_partial_dies (const struct die_reader_specs
*reader
,
15870 const gdb_byte
*info_ptr
, int building_psymtab
)
15872 struct dwarf2_cu
*cu
= reader
->cu
;
15873 struct objfile
*objfile
= cu
->objfile
;
15874 struct partial_die_info
*part_die
;
15875 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
15876 struct abbrev_info
*abbrev
;
15877 unsigned int bytes_read
;
15878 unsigned int load_all
= 0;
15879 int nesting_level
= 1;
15884 gdb_assert (cu
->per_cu
!= NULL
);
15885 if (cu
->per_cu
->load_all_dies
)
15889 = htab_create_alloc_ex (cu
->header
.length
/ 12,
15893 &cu
->comp_unit_obstack
,
15894 hashtab_obstack_allocate
,
15895 dummy_obstack_deallocate
);
15897 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
15901 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
15903 /* A NULL abbrev means the end of a series of children. */
15904 if (abbrev
== NULL
)
15906 if (--nesting_level
== 0)
15908 /* PART_DIE was probably the last thing allocated on the
15909 comp_unit_obstack, so we could call obstack_free
15910 here. We don't do that because the waste is small,
15911 and will be cleaned up when we're done with this
15912 compilation unit. This way, we're also more robust
15913 against other users of the comp_unit_obstack. */
15916 info_ptr
+= bytes_read
;
15917 last_die
= parent_die
;
15918 parent_die
= parent_die
->die_parent
;
15922 /* Check for template arguments. We never save these; if
15923 they're seen, we just mark the parent, and go on our way. */
15924 if (parent_die
!= NULL
15925 && cu
->language
== language_cplus
15926 && (abbrev
->tag
== DW_TAG_template_type_param
15927 || abbrev
->tag
== DW_TAG_template_value_param
))
15929 parent_die
->has_template_arguments
= 1;
15933 /* We don't need a partial DIE for the template argument. */
15934 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15939 /* We only recurse into c++ subprograms looking for template arguments.
15940 Skip their other children. */
15942 && cu
->language
== language_cplus
15943 && parent_die
!= NULL
15944 && parent_die
->tag
== DW_TAG_subprogram
)
15946 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15950 /* Check whether this DIE is interesting enough to save. Normally
15951 we would not be interested in members here, but there may be
15952 later variables referencing them via DW_AT_specification (for
15953 static members). */
15955 && !is_type_tag_for_partial (abbrev
->tag
)
15956 && abbrev
->tag
!= DW_TAG_constant
15957 && abbrev
->tag
!= DW_TAG_enumerator
15958 && abbrev
->tag
!= DW_TAG_subprogram
15959 && abbrev
->tag
!= DW_TAG_lexical_block
15960 && abbrev
->tag
!= DW_TAG_variable
15961 && abbrev
->tag
!= DW_TAG_namespace
15962 && abbrev
->tag
!= DW_TAG_module
15963 && abbrev
->tag
!= DW_TAG_member
15964 && abbrev
->tag
!= DW_TAG_imported_unit
15965 && abbrev
->tag
!= DW_TAG_imported_declaration
)
15967 /* Otherwise we skip to the next sibling, if any. */
15968 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15972 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
15975 /* This two-pass algorithm for processing partial symbols has a
15976 high cost in cache pressure. Thus, handle some simple cases
15977 here which cover the majority of C partial symbols. DIEs
15978 which neither have specification tags in them, nor could have
15979 specification tags elsewhere pointing at them, can simply be
15980 processed and discarded.
15982 This segment is also optional; scan_partial_symbols and
15983 add_partial_symbol will handle these DIEs if we chain
15984 them in normally. When compilers which do not emit large
15985 quantities of duplicate debug information are more common,
15986 this code can probably be removed. */
15988 /* Any complete simple types at the top level (pretty much all
15989 of them, for a language without namespaces), can be processed
15991 if (parent_die
== NULL
15992 && part_die
->has_specification
== 0
15993 && part_die
->is_declaration
== 0
15994 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
15995 || part_die
->tag
== DW_TAG_base_type
15996 || part_die
->tag
== DW_TAG_subrange_type
))
15998 if (building_psymtab
&& part_die
->name
!= NULL
)
15999 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
16000 VAR_DOMAIN
, LOC_TYPEDEF
,
16001 &objfile
->static_psymbols
,
16002 0, cu
->language
, objfile
);
16003 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
16007 /* The exception for DW_TAG_typedef with has_children above is
16008 a workaround of GCC PR debug/47510. In the case of this complaint
16009 type_name_no_tag_or_error will error on such types later.
16011 GDB skipped children of DW_TAG_typedef by the shortcut above and then
16012 it could not find the child DIEs referenced later, this is checked
16013 above. In correct DWARF DW_TAG_typedef should have no children. */
16015 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
16016 complaint (&symfile_complaints
,
16017 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
16018 "- DIE at 0x%x [in module %s]"),
16019 to_underlying (part_die
->sect_off
), objfile_name (objfile
));
16021 /* If we're at the second level, and we're an enumerator, and
16022 our parent has no specification (meaning possibly lives in a
16023 namespace elsewhere), then we can add the partial symbol now
16024 instead of queueing it. */
16025 if (part_die
->tag
== DW_TAG_enumerator
16026 && parent_die
!= NULL
16027 && parent_die
->die_parent
== NULL
16028 && parent_die
->tag
== DW_TAG_enumeration_type
16029 && parent_die
->has_specification
== 0)
16031 if (part_die
->name
== NULL
)
16032 complaint (&symfile_complaints
,
16033 _("malformed enumerator DIE ignored"));
16034 else if (building_psymtab
)
16035 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
16036 VAR_DOMAIN
, LOC_CONST
,
16037 cu
->language
== language_cplus
16038 ? &objfile
->global_psymbols
16039 : &objfile
->static_psymbols
,
16040 0, cu
->language
, objfile
);
16042 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
16046 /* We'll save this DIE so link it in. */
16047 part_die
->die_parent
= parent_die
;
16048 part_die
->die_sibling
= NULL
;
16049 part_die
->die_child
= NULL
;
16051 if (last_die
&& last_die
== parent_die
)
16052 last_die
->die_child
= part_die
;
16054 last_die
->die_sibling
= part_die
;
16056 last_die
= part_die
;
16058 if (first_die
== NULL
)
16059 first_die
= part_die
;
16061 /* Maybe add the DIE to the hash table. Not all DIEs that we
16062 find interesting need to be in the hash table, because we
16063 also have the parent/sibling/child chains; only those that we
16064 might refer to by offset later during partial symbol reading.
16066 For now this means things that might have be the target of a
16067 DW_AT_specification, DW_AT_abstract_origin, or
16068 DW_AT_extension. DW_AT_extension will refer only to
16069 namespaces; DW_AT_abstract_origin refers to functions (and
16070 many things under the function DIE, but we do not recurse
16071 into function DIEs during partial symbol reading) and
16072 possibly variables as well; DW_AT_specification refers to
16073 declarations. Declarations ought to have the DW_AT_declaration
16074 flag. It happens that GCC forgets to put it in sometimes, but
16075 only for functions, not for types.
16077 Adding more things than necessary to the hash table is harmless
16078 except for the performance cost. Adding too few will result in
16079 wasted time in find_partial_die, when we reread the compilation
16080 unit with load_all_dies set. */
16083 || abbrev
->tag
== DW_TAG_constant
16084 || abbrev
->tag
== DW_TAG_subprogram
16085 || abbrev
->tag
== DW_TAG_variable
16086 || abbrev
->tag
== DW_TAG_namespace
16087 || part_die
->is_declaration
)
16091 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
16092 to_underlying (part_die
->sect_off
),
16097 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
16099 /* For some DIEs we want to follow their children (if any). For C
16100 we have no reason to follow the children of structures; for other
16101 languages we have to, so that we can get at method physnames
16102 to infer fully qualified class names, for DW_AT_specification,
16103 and for C++ template arguments. For C++, we also look one level
16104 inside functions to find template arguments (if the name of the
16105 function does not already contain the template arguments).
16107 For Ada, we need to scan the children of subprograms and lexical
16108 blocks as well because Ada allows the definition of nested
16109 entities that could be interesting for the debugger, such as
16110 nested subprograms for instance. */
16111 if (last_die
->has_children
16113 || last_die
->tag
== DW_TAG_namespace
16114 || last_die
->tag
== DW_TAG_module
16115 || last_die
->tag
== DW_TAG_enumeration_type
16116 || (cu
->language
== language_cplus
16117 && last_die
->tag
== DW_TAG_subprogram
16118 && (last_die
->name
== NULL
16119 || strchr (last_die
->name
, '<') == NULL
))
16120 || (cu
->language
!= language_c
16121 && (last_die
->tag
== DW_TAG_class_type
16122 || last_die
->tag
== DW_TAG_interface_type
16123 || last_die
->tag
== DW_TAG_structure_type
16124 || last_die
->tag
== DW_TAG_union_type
))
16125 || (cu
->language
== language_ada
16126 && (last_die
->tag
== DW_TAG_subprogram
16127 || last_die
->tag
== DW_TAG_lexical_block
))))
16130 parent_die
= last_die
;
16134 /* Otherwise we skip to the next sibling, if any. */
16135 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
16137 /* Back to the top, do it again. */
16141 /* Read a minimal amount of information into the minimal die structure. */
16143 static const gdb_byte
*
16144 read_partial_die (const struct die_reader_specs
*reader
,
16145 struct partial_die_info
*part_die
,
16146 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
16147 const gdb_byte
*info_ptr
)
16149 struct dwarf2_cu
*cu
= reader
->cu
;
16150 struct objfile
*objfile
= cu
->objfile
;
16151 const gdb_byte
*buffer
= reader
->buffer
;
16153 struct attribute attr
;
16154 int has_low_pc_attr
= 0;
16155 int has_high_pc_attr
= 0;
16156 int high_pc_relative
= 0;
16158 memset (part_die
, 0, sizeof (struct partial_die_info
));
16160 part_die
->sect_off
= (sect_offset
) (info_ptr
- buffer
);
16162 info_ptr
+= abbrev_len
;
16164 if (abbrev
== NULL
)
16167 part_die
->tag
= abbrev
->tag
;
16168 part_die
->has_children
= abbrev
->has_children
;
16170 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
16172 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
16174 /* Store the data if it is of an attribute we want to keep in a
16175 partial symbol table. */
16179 switch (part_die
->tag
)
16181 case DW_TAG_compile_unit
:
16182 case DW_TAG_partial_unit
:
16183 case DW_TAG_type_unit
:
16184 /* Compilation units have a DW_AT_name that is a filename, not
16185 a source language identifier. */
16186 case DW_TAG_enumeration_type
:
16187 case DW_TAG_enumerator
:
16188 /* These tags always have simple identifiers already; no need
16189 to canonicalize them. */
16190 part_die
->name
= DW_STRING (&attr
);
16194 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
16195 &objfile
->per_bfd
->storage_obstack
);
16199 case DW_AT_linkage_name
:
16200 case DW_AT_MIPS_linkage_name
:
16201 /* Note that both forms of linkage name might appear. We
16202 assume they will be the same, and we only store the last
16204 if (cu
->language
== language_ada
)
16205 part_die
->name
= DW_STRING (&attr
);
16206 part_die
->linkage_name
= DW_STRING (&attr
);
16209 has_low_pc_attr
= 1;
16210 part_die
->lowpc
= attr_value_as_address (&attr
);
16212 case DW_AT_high_pc
:
16213 has_high_pc_attr
= 1;
16214 part_die
->highpc
= attr_value_as_address (&attr
);
16215 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
16216 high_pc_relative
= 1;
16218 case DW_AT_location
:
16219 /* Support the .debug_loc offsets. */
16220 if (attr_form_is_block (&attr
))
16222 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
16224 else if (attr_form_is_section_offset (&attr
))
16226 dwarf2_complex_location_expr_complaint ();
16230 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16231 "partial symbol information");
16234 case DW_AT_external
:
16235 part_die
->is_external
= DW_UNSND (&attr
);
16237 case DW_AT_declaration
:
16238 part_die
->is_declaration
= DW_UNSND (&attr
);
16241 part_die
->has_type
= 1;
16243 case DW_AT_abstract_origin
:
16244 case DW_AT_specification
:
16245 case DW_AT_extension
:
16246 part_die
->has_specification
= 1;
16247 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
16248 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
16249 || cu
->per_cu
->is_dwz
);
16251 case DW_AT_sibling
:
16252 /* Ignore absolute siblings, they might point outside of
16253 the current compile unit. */
16254 if (attr
.form
== DW_FORM_ref_addr
)
16255 complaint (&symfile_complaints
,
16256 _("ignoring absolute DW_AT_sibling"));
16259 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
16260 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
16262 if (sibling_ptr
< info_ptr
)
16263 complaint (&symfile_complaints
,
16264 _("DW_AT_sibling points backwards"));
16265 else if (sibling_ptr
> reader
->buffer_end
)
16266 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
16268 part_die
->sibling
= sibling_ptr
;
16271 case DW_AT_byte_size
:
16272 part_die
->has_byte_size
= 1;
16274 case DW_AT_const_value
:
16275 part_die
->has_const_value
= 1;
16277 case DW_AT_calling_convention
:
16278 /* DWARF doesn't provide a way to identify a program's source-level
16279 entry point. DW_AT_calling_convention attributes are only meant
16280 to describe functions' calling conventions.
16282 However, because it's a necessary piece of information in
16283 Fortran, and before DWARF 4 DW_CC_program was the only
16284 piece of debugging information whose definition refers to
16285 a 'main program' at all, several compilers marked Fortran
16286 main programs with DW_CC_program --- even when those
16287 functions use the standard calling conventions.
16289 Although DWARF now specifies a way to provide this
16290 information, we support this practice for backward
16292 if (DW_UNSND (&attr
) == DW_CC_program
16293 && cu
->language
== language_fortran
)
16294 part_die
->main_subprogram
= 1;
16297 if (DW_UNSND (&attr
) == DW_INL_inlined
16298 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
16299 part_die
->may_be_inlined
= 1;
16303 if (part_die
->tag
== DW_TAG_imported_unit
)
16305 part_die
->d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
16306 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
16307 || cu
->per_cu
->is_dwz
);
16311 case DW_AT_main_subprogram
:
16312 part_die
->main_subprogram
= DW_UNSND (&attr
);
16320 if (high_pc_relative
)
16321 part_die
->highpc
+= part_die
->lowpc
;
16323 if (has_low_pc_attr
&& has_high_pc_attr
)
16325 /* When using the GNU linker, .gnu.linkonce. sections are used to
16326 eliminate duplicate copies of functions and vtables and such.
16327 The linker will arbitrarily choose one and discard the others.
16328 The AT_*_pc values for such functions refer to local labels in
16329 these sections. If the section from that file was discarded, the
16330 labels are not in the output, so the relocs get a value of 0.
16331 If this is a discarded function, mark the pc bounds as invalid,
16332 so that GDB will ignore it. */
16333 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
16335 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16337 complaint (&symfile_complaints
,
16338 _("DW_AT_low_pc %s is zero "
16339 "for DIE at 0x%x [in module %s]"),
16340 paddress (gdbarch
, part_die
->lowpc
),
16341 to_underlying (part_die
->sect_off
), objfile_name (objfile
));
16343 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
16344 else if (part_die
->lowpc
>= part_die
->highpc
)
16346 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16348 complaint (&symfile_complaints
,
16349 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
16350 "for DIE at 0x%x [in module %s]"),
16351 paddress (gdbarch
, part_die
->lowpc
),
16352 paddress (gdbarch
, part_die
->highpc
),
16353 to_underlying (part_die
->sect_off
),
16354 objfile_name (objfile
));
16357 part_die
->has_pc_info
= 1;
16363 /* Find a cached partial DIE at OFFSET in CU. */
16365 static struct partial_die_info
*
16366 find_partial_die_in_comp_unit (sect_offset sect_off
, struct dwarf2_cu
*cu
)
16368 struct partial_die_info
*lookup_die
= NULL
;
16369 struct partial_die_info part_die
;
16371 part_die
.sect_off
= sect_off
;
16372 lookup_die
= ((struct partial_die_info
*)
16373 htab_find_with_hash (cu
->partial_dies
, &part_die
,
16374 to_underlying (sect_off
)));
16379 /* Find a partial DIE at OFFSET, which may or may not be in CU,
16380 except in the case of .debug_types DIEs which do not reference
16381 outside their CU (they do however referencing other types via
16382 DW_FORM_ref_sig8). */
16384 static struct partial_die_info
*
16385 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
16387 struct objfile
*objfile
= cu
->objfile
;
16388 struct dwarf2_per_cu_data
*per_cu
= NULL
;
16389 struct partial_die_info
*pd
= NULL
;
16391 if (offset_in_dwz
== cu
->per_cu
->is_dwz
16392 && offset_in_cu_p (&cu
->header
, sect_off
))
16394 pd
= find_partial_die_in_comp_unit (sect_off
, cu
);
16397 /* We missed recording what we needed.
16398 Load all dies and try again. */
16399 per_cu
= cu
->per_cu
;
16403 /* TUs don't reference other CUs/TUs (except via type signatures). */
16404 if (cu
->per_cu
->is_debug_types
)
16406 error (_("Dwarf Error: Type Unit at offset 0x%x contains"
16407 " external reference to offset 0x%x [in module %s].\n"),
16408 to_underlying (cu
->header
.sect_off
), to_underlying (sect_off
),
16409 bfd_get_filename (objfile
->obfd
));
16411 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
16414 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
16415 load_partial_comp_unit (per_cu
);
16417 per_cu
->cu
->last_used
= 0;
16418 pd
= find_partial_die_in_comp_unit (sect_off
, per_cu
->cu
);
16421 /* If we didn't find it, and not all dies have been loaded,
16422 load them all and try again. */
16424 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
16426 per_cu
->load_all_dies
= 1;
16428 /* This is nasty. When we reread the DIEs, somewhere up the call chain
16429 THIS_CU->cu may already be in use. So we can't just free it and
16430 replace its DIEs with the ones we read in. Instead, we leave those
16431 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
16432 and clobber THIS_CU->cu->partial_dies with the hash table for the new
16434 load_partial_comp_unit (per_cu
);
16436 pd
= find_partial_die_in_comp_unit (sect_off
, per_cu
->cu
);
16440 internal_error (__FILE__
, __LINE__
,
16441 _("could not find partial DIE 0x%x "
16442 "in cache [from module %s]\n"),
16443 to_underlying (sect_off
), bfd_get_filename (objfile
->obfd
));
16447 /* See if we can figure out if the class lives in a namespace. We do
16448 this by looking for a member function; its demangled name will
16449 contain namespace info, if there is any. */
16452 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
16453 struct dwarf2_cu
*cu
)
16455 /* NOTE: carlton/2003-10-07: Getting the info this way changes
16456 what template types look like, because the demangler
16457 frequently doesn't give the same name as the debug info. We
16458 could fix this by only using the demangled name to get the
16459 prefix (but see comment in read_structure_type). */
16461 struct partial_die_info
*real_pdi
;
16462 struct partial_die_info
*child_pdi
;
16464 /* If this DIE (this DIE's specification, if any) has a parent, then
16465 we should not do this. We'll prepend the parent's fully qualified
16466 name when we create the partial symbol. */
16468 real_pdi
= struct_pdi
;
16469 while (real_pdi
->has_specification
)
16470 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
16471 real_pdi
->spec_is_dwz
, cu
);
16473 if (real_pdi
->die_parent
!= NULL
)
16476 for (child_pdi
= struct_pdi
->die_child
;
16478 child_pdi
= child_pdi
->die_sibling
)
16480 if (child_pdi
->tag
== DW_TAG_subprogram
16481 && child_pdi
->linkage_name
!= NULL
)
16483 char *actual_class_name
16484 = language_class_name_from_physname (cu
->language_defn
,
16485 child_pdi
->linkage_name
);
16486 if (actual_class_name
!= NULL
)
16490 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16492 strlen (actual_class_name
)));
16493 xfree (actual_class_name
);
16500 /* Adjust PART_DIE before generating a symbol for it. This function
16501 may set the is_external flag or change the DIE's name. */
16504 fixup_partial_die (struct partial_die_info
*part_die
,
16505 struct dwarf2_cu
*cu
)
16507 /* Once we've fixed up a die, there's no point in doing so again.
16508 This also avoids a memory leak if we were to call
16509 guess_partial_die_structure_name multiple times. */
16510 if (part_die
->fixup_called
)
16513 /* If we found a reference attribute and the DIE has no name, try
16514 to find a name in the referred to DIE. */
16516 if (part_die
->name
== NULL
&& part_die
->has_specification
)
16518 struct partial_die_info
*spec_die
;
16520 spec_die
= find_partial_die (part_die
->spec_offset
,
16521 part_die
->spec_is_dwz
, cu
);
16523 fixup_partial_die (spec_die
, cu
);
16525 if (spec_die
->name
)
16527 part_die
->name
= spec_die
->name
;
16529 /* Copy DW_AT_external attribute if it is set. */
16530 if (spec_die
->is_external
)
16531 part_die
->is_external
= spec_die
->is_external
;
16535 /* Set default names for some unnamed DIEs. */
16537 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
16538 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
16540 /* If there is no parent die to provide a namespace, and there are
16541 children, see if we can determine the namespace from their linkage
16543 if (cu
->language
== language_cplus
16544 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
16545 && part_die
->die_parent
== NULL
16546 && part_die
->has_children
16547 && (part_die
->tag
== DW_TAG_class_type
16548 || part_die
->tag
== DW_TAG_structure_type
16549 || part_die
->tag
== DW_TAG_union_type
))
16550 guess_partial_die_structure_name (part_die
, cu
);
16552 /* GCC might emit a nameless struct or union that has a linkage
16553 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16554 if (part_die
->name
== NULL
16555 && (part_die
->tag
== DW_TAG_class_type
16556 || part_die
->tag
== DW_TAG_interface_type
16557 || part_die
->tag
== DW_TAG_structure_type
16558 || part_die
->tag
== DW_TAG_union_type
)
16559 && part_die
->linkage_name
!= NULL
)
16563 demangled
= gdb_demangle (part_die
->linkage_name
, DMGL_TYPES
);
16568 /* Strip any leading namespaces/classes, keep only the base name.
16569 DW_AT_name for named DIEs does not contain the prefixes. */
16570 base
= strrchr (demangled
, ':');
16571 if (base
&& base
> demangled
&& base
[-1] == ':')
16578 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16579 base
, strlen (base
)));
16584 part_die
->fixup_called
= 1;
16587 /* Read an attribute value described by an attribute form. */
16589 static const gdb_byte
*
16590 read_attribute_value (const struct die_reader_specs
*reader
,
16591 struct attribute
*attr
, unsigned form
,
16592 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
16594 struct dwarf2_cu
*cu
= reader
->cu
;
16595 struct objfile
*objfile
= cu
->objfile
;
16596 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16597 bfd
*abfd
= reader
->abfd
;
16598 struct comp_unit_head
*cu_header
= &cu
->header
;
16599 unsigned int bytes_read
;
16600 struct dwarf_block
*blk
;
16602 attr
->form
= (enum dwarf_form
) form
;
16605 case DW_FORM_ref_addr
:
16606 if (cu
->header
.version
== 2)
16607 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
16609 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
16610 &cu
->header
, &bytes_read
);
16611 info_ptr
+= bytes_read
;
16613 case DW_FORM_GNU_ref_alt
:
16614 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
16615 info_ptr
+= bytes_read
;
16618 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
16619 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
16620 info_ptr
+= bytes_read
;
16622 case DW_FORM_block2
:
16623 blk
= dwarf_alloc_block (cu
);
16624 blk
->size
= read_2_bytes (abfd
, info_ptr
);
16626 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16627 info_ptr
+= blk
->size
;
16628 DW_BLOCK (attr
) = blk
;
16630 case DW_FORM_block4
:
16631 blk
= dwarf_alloc_block (cu
);
16632 blk
->size
= read_4_bytes (abfd
, info_ptr
);
16634 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16635 info_ptr
+= blk
->size
;
16636 DW_BLOCK (attr
) = blk
;
16638 case DW_FORM_data2
:
16639 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
16642 case DW_FORM_data4
:
16643 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
16646 case DW_FORM_data8
:
16647 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
16650 case DW_FORM_data16
:
16651 blk
= dwarf_alloc_block (cu
);
16653 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
16655 DW_BLOCK (attr
) = blk
;
16657 case DW_FORM_sec_offset
:
16658 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
16659 info_ptr
+= bytes_read
;
16661 case DW_FORM_string
:
16662 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
16663 DW_STRING_IS_CANONICAL (attr
) = 0;
16664 info_ptr
+= bytes_read
;
16667 if (!cu
->per_cu
->is_dwz
)
16669 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
16671 DW_STRING_IS_CANONICAL (attr
) = 0;
16672 info_ptr
+= bytes_read
;
16676 case DW_FORM_line_strp
:
16677 if (!cu
->per_cu
->is_dwz
)
16679 DW_STRING (attr
) = read_indirect_line_string (abfd
, info_ptr
,
16680 cu_header
, &bytes_read
);
16681 DW_STRING_IS_CANONICAL (attr
) = 0;
16682 info_ptr
+= bytes_read
;
16686 case DW_FORM_GNU_strp_alt
:
16688 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
16689 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
16692 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
16693 DW_STRING_IS_CANONICAL (attr
) = 0;
16694 info_ptr
+= bytes_read
;
16697 case DW_FORM_exprloc
:
16698 case DW_FORM_block
:
16699 blk
= dwarf_alloc_block (cu
);
16700 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16701 info_ptr
+= bytes_read
;
16702 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16703 info_ptr
+= blk
->size
;
16704 DW_BLOCK (attr
) = blk
;
16706 case DW_FORM_block1
:
16707 blk
= dwarf_alloc_block (cu
);
16708 blk
->size
= read_1_byte (abfd
, info_ptr
);
16710 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16711 info_ptr
+= blk
->size
;
16712 DW_BLOCK (attr
) = blk
;
16714 case DW_FORM_data1
:
16715 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
16719 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
16722 case DW_FORM_flag_present
:
16723 DW_UNSND (attr
) = 1;
16725 case DW_FORM_sdata
:
16726 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
16727 info_ptr
+= bytes_read
;
16729 case DW_FORM_udata
:
16730 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16731 info_ptr
+= bytes_read
;
16734 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
16735 + read_1_byte (abfd
, info_ptr
));
16739 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
16740 + read_2_bytes (abfd
, info_ptr
));
16744 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
16745 + read_4_bytes (abfd
, info_ptr
));
16749 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
16750 + read_8_bytes (abfd
, info_ptr
));
16753 case DW_FORM_ref_sig8
:
16754 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
16757 case DW_FORM_ref_udata
:
16758 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
16759 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
16760 info_ptr
+= bytes_read
;
16762 case DW_FORM_indirect
:
16763 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16764 info_ptr
+= bytes_read
;
16765 if (form
== DW_FORM_implicit_const
)
16767 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
16768 info_ptr
+= bytes_read
;
16770 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
16773 case DW_FORM_implicit_const
:
16774 DW_SND (attr
) = implicit_const
;
16776 case DW_FORM_GNU_addr_index
:
16777 if (reader
->dwo_file
== NULL
)
16779 /* For now flag a hard error.
16780 Later we can turn this into a complaint. */
16781 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
16782 dwarf_form_name (form
),
16783 bfd_get_filename (abfd
));
16785 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
16786 info_ptr
+= bytes_read
;
16788 case DW_FORM_GNU_str_index
:
16789 if (reader
->dwo_file
== NULL
)
16791 /* For now flag a hard error.
16792 Later we can turn this into a complaint if warranted. */
16793 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
16794 dwarf_form_name (form
),
16795 bfd_get_filename (abfd
));
16798 ULONGEST str_index
=
16799 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16801 DW_STRING (attr
) = read_str_index (reader
, str_index
);
16802 DW_STRING_IS_CANONICAL (attr
) = 0;
16803 info_ptr
+= bytes_read
;
16807 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
16808 dwarf_form_name (form
),
16809 bfd_get_filename (abfd
));
16813 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
16814 attr
->form
= DW_FORM_GNU_ref_alt
;
16816 /* We have seen instances where the compiler tried to emit a byte
16817 size attribute of -1 which ended up being encoded as an unsigned
16818 0xffffffff. Although 0xffffffff is technically a valid size value,
16819 an object of this size seems pretty unlikely so we can relatively
16820 safely treat these cases as if the size attribute was invalid and
16821 treat them as zero by default. */
16822 if (attr
->name
== DW_AT_byte_size
16823 && form
== DW_FORM_data4
16824 && DW_UNSND (attr
) >= 0xffffffff)
16827 (&symfile_complaints
,
16828 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
16829 hex_string (DW_UNSND (attr
)));
16830 DW_UNSND (attr
) = 0;
16836 /* Read an attribute described by an abbreviated attribute. */
16838 static const gdb_byte
*
16839 read_attribute (const struct die_reader_specs
*reader
,
16840 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
16841 const gdb_byte
*info_ptr
)
16843 attr
->name
= abbrev
->name
;
16844 return read_attribute_value (reader
, attr
, abbrev
->form
,
16845 abbrev
->implicit_const
, info_ptr
);
16848 /* Read dwarf information from a buffer. */
16850 static unsigned int
16851 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
16853 return bfd_get_8 (abfd
, buf
);
16857 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
16859 return bfd_get_signed_8 (abfd
, buf
);
16862 static unsigned int
16863 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16865 return bfd_get_16 (abfd
, buf
);
16869 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16871 return bfd_get_signed_16 (abfd
, buf
);
16874 static unsigned int
16875 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16877 return bfd_get_32 (abfd
, buf
);
16881 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16883 return bfd_get_signed_32 (abfd
, buf
);
16887 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16889 return bfd_get_64 (abfd
, buf
);
16893 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
16894 unsigned int *bytes_read
)
16896 struct comp_unit_head
*cu_header
= &cu
->header
;
16897 CORE_ADDR retval
= 0;
16899 if (cu_header
->signed_addr_p
)
16901 switch (cu_header
->addr_size
)
16904 retval
= bfd_get_signed_16 (abfd
, buf
);
16907 retval
= bfd_get_signed_32 (abfd
, buf
);
16910 retval
= bfd_get_signed_64 (abfd
, buf
);
16913 internal_error (__FILE__
, __LINE__
,
16914 _("read_address: bad switch, signed [in module %s]"),
16915 bfd_get_filename (abfd
));
16920 switch (cu_header
->addr_size
)
16923 retval
= bfd_get_16 (abfd
, buf
);
16926 retval
= bfd_get_32 (abfd
, buf
);
16929 retval
= bfd_get_64 (abfd
, buf
);
16932 internal_error (__FILE__
, __LINE__
,
16933 _("read_address: bad switch, "
16934 "unsigned [in module %s]"),
16935 bfd_get_filename (abfd
));
16939 *bytes_read
= cu_header
->addr_size
;
16943 /* Read the initial length from a section. The (draft) DWARF 3
16944 specification allows the initial length to take up either 4 bytes
16945 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
16946 bytes describe the length and all offsets will be 8 bytes in length
16949 An older, non-standard 64-bit format is also handled by this
16950 function. The older format in question stores the initial length
16951 as an 8-byte quantity without an escape value. Lengths greater
16952 than 2^32 aren't very common which means that the initial 4 bytes
16953 is almost always zero. Since a length value of zero doesn't make
16954 sense for the 32-bit format, this initial zero can be considered to
16955 be an escape value which indicates the presence of the older 64-bit
16956 format. As written, the code can't detect (old format) lengths
16957 greater than 4GB. If it becomes necessary to handle lengths
16958 somewhat larger than 4GB, we could allow other small values (such
16959 as the non-sensical values of 1, 2, and 3) to also be used as
16960 escape values indicating the presence of the old format.
16962 The value returned via bytes_read should be used to increment the
16963 relevant pointer after calling read_initial_length().
16965 [ Note: read_initial_length() and read_offset() are based on the
16966 document entitled "DWARF Debugging Information Format", revision
16967 3, draft 8, dated November 19, 2001. This document was obtained
16970 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
16972 This document is only a draft and is subject to change. (So beware.)
16974 Details regarding the older, non-standard 64-bit format were
16975 determined empirically by examining 64-bit ELF files produced by
16976 the SGI toolchain on an IRIX 6.5 machine.
16978 - Kevin, July 16, 2002
16982 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
16984 LONGEST length
= bfd_get_32 (abfd
, buf
);
16986 if (length
== 0xffffffff)
16988 length
= bfd_get_64 (abfd
, buf
+ 4);
16991 else if (length
== 0)
16993 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
16994 length
= bfd_get_64 (abfd
, buf
);
17005 /* Cover function for read_initial_length.
17006 Returns the length of the object at BUF, and stores the size of the
17007 initial length in *BYTES_READ and stores the size that offsets will be in
17009 If the initial length size is not equivalent to that specified in
17010 CU_HEADER then issue a complaint.
17011 This is useful when reading non-comp-unit headers. */
17014 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
17015 const struct comp_unit_head
*cu_header
,
17016 unsigned int *bytes_read
,
17017 unsigned int *offset_size
)
17019 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
17021 gdb_assert (cu_header
->initial_length_size
== 4
17022 || cu_header
->initial_length_size
== 8
17023 || cu_header
->initial_length_size
== 12);
17025 if (cu_header
->initial_length_size
!= *bytes_read
)
17026 complaint (&symfile_complaints
,
17027 _("intermixed 32-bit and 64-bit DWARF sections"));
17029 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
17033 /* Read an offset from the data stream. The size of the offset is
17034 given by cu_header->offset_size. */
17037 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
17038 const struct comp_unit_head
*cu_header
,
17039 unsigned int *bytes_read
)
17041 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
17043 *bytes_read
= cu_header
->offset_size
;
17047 /* Read an offset from the data stream. */
17050 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
17052 LONGEST retval
= 0;
17054 switch (offset_size
)
17057 retval
= bfd_get_32 (abfd
, buf
);
17060 retval
= bfd_get_64 (abfd
, buf
);
17063 internal_error (__FILE__
, __LINE__
,
17064 _("read_offset_1: bad switch [in module %s]"),
17065 bfd_get_filename (abfd
));
17071 static const gdb_byte
*
17072 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
17074 /* If the size of a host char is 8 bits, we can return a pointer
17075 to the buffer, otherwise we have to copy the data to a buffer
17076 allocated on the temporary obstack. */
17077 gdb_assert (HOST_CHAR_BIT
== 8);
17081 static const char *
17082 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
17083 unsigned int *bytes_read_ptr
)
17085 /* If the size of a host char is 8 bits, we can return a pointer
17086 to the string, otherwise we have to copy the string to a buffer
17087 allocated on the temporary obstack. */
17088 gdb_assert (HOST_CHAR_BIT
== 8);
17091 *bytes_read_ptr
= 1;
17094 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
17095 return (const char *) buf
;
17098 /* Return pointer to string at section SECT offset STR_OFFSET with error
17099 reporting strings FORM_NAME and SECT_NAME. */
17101 static const char *
17102 read_indirect_string_at_offset_from (bfd
*abfd
, LONGEST str_offset
,
17103 struct dwarf2_section_info
*sect
,
17104 const char *form_name
,
17105 const char *sect_name
)
17107 dwarf2_read_section (dwarf2_per_objfile
->objfile
, sect
);
17108 if (sect
->buffer
== NULL
)
17109 error (_("%s used without %s section [in module %s]"),
17110 form_name
, sect_name
, bfd_get_filename (abfd
));
17111 if (str_offset
>= sect
->size
)
17112 error (_("%s pointing outside of %s section [in module %s]"),
17113 form_name
, sect_name
, bfd_get_filename (abfd
));
17114 gdb_assert (HOST_CHAR_BIT
== 8);
17115 if (sect
->buffer
[str_offset
] == '\0')
17117 return (const char *) (sect
->buffer
+ str_offset
);
17120 /* Return pointer to string at .debug_str offset STR_OFFSET. */
17122 static const char *
17123 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
17125 return read_indirect_string_at_offset_from (abfd
, str_offset
,
17126 &dwarf2_per_objfile
->str
,
17127 "DW_FORM_strp", ".debug_str");
17130 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
17132 static const char *
17133 read_indirect_line_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
17135 return read_indirect_string_at_offset_from (abfd
, str_offset
,
17136 &dwarf2_per_objfile
->line_str
,
17137 "DW_FORM_line_strp",
17138 ".debug_line_str");
17141 /* Read a string at offset STR_OFFSET in the .debug_str section from
17142 the .dwz file DWZ. Throw an error if the offset is too large. If
17143 the string consists of a single NUL byte, return NULL; otherwise
17144 return a pointer to the string. */
17146 static const char *
17147 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
17149 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
17151 if (dwz
->str
.buffer
== NULL
)
17152 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
17153 "section [in module %s]"),
17154 bfd_get_filename (dwz
->dwz_bfd
));
17155 if (str_offset
>= dwz
->str
.size
)
17156 error (_("DW_FORM_GNU_strp_alt pointing outside of "
17157 ".debug_str section [in module %s]"),
17158 bfd_get_filename (dwz
->dwz_bfd
));
17159 gdb_assert (HOST_CHAR_BIT
== 8);
17160 if (dwz
->str
.buffer
[str_offset
] == '\0')
17162 return (const char *) (dwz
->str
.buffer
+ str_offset
);
17165 /* Return pointer to string at .debug_str offset as read from BUF.
17166 BUF is assumed to be in a compilation unit described by CU_HEADER.
17167 Return *BYTES_READ_PTR count of bytes read from BUF. */
17169 static const char *
17170 read_indirect_string (bfd
*abfd
, const gdb_byte
*buf
,
17171 const struct comp_unit_head
*cu_header
,
17172 unsigned int *bytes_read_ptr
)
17174 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
17176 return read_indirect_string_at_offset (abfd
, str_offset
);
17179 /* Return pointer to string at .debug_line_str offset as read from BUF.
17180 BUF is assumed to be in a compilation unit described by CU_HEADER.
17181 Return *BYTES_READ_PTR count of bytes read from BUF. */
17183 static const char *
17184 read_indirect_line_string (bfd
*abfd
, const gdb_byte
*buf
,
17185 const struct comp_unit_head
*cu_header
,
17186 unsigned int *bytes_read_ptr
)
17188 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
17190 return read_indirect_line_string_at_offset (abfd
, str_offset
);
17194 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
17195 unsigned int *bytes_read_ptr
)
17198 unsigned int num_read
;
17200 unsigned char byte
;
17207 byte
= bfd_get_8 (abfd
, buf
);
17210 result
|= ((ULONGEST
) (byte
& 127) << shift
);
17211 if ((byte
& 128) == 0)
17217 *bytes_read_ptr
= num_read
;
17222 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
17223 unsigned int *bytes_read_ptr
)
17226 int shift
, num_read
;
17227 unsigned char byte
;
17234 byte
= bfd_get_8 (abfd
, buf
);
17237 result
|= ((LONGEST
) (byte
& 127) << shift
);
17239 if ((byte
& 128) == 0)
17244 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
17245 result
|= -(((LONGEST
) 1) << shift
);
17246 *bytes_read_ptr
= num_read
;
17250 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
17251 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
17252 ADDR_SIZE is the size of addresses from the CU header. */
17255 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
17257 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17258 bfd
*abfd
= objfile
->obfd
;
17259 const gdb_byte
*info_ptr
;
17261 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
17262 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
17263 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
17264 objfile_name (objfile
));
17265 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
17266 error (_("DW_FORM_addr_index pointing outside of "
17267 ".debug_addr section [in module %s]"),
17268 objfile_name (objfile
));
17269 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
17270 + addr_base
+ addr_index
* addr_size
);
17271 if (addr_size
== 4)
17272 return bfd_get_32 (abfd
, info_ptr
);
17274 return bfd_get_64 (abfd
, info_ptr
);
17277 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
17280 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
17282 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
17285 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
17288 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
17289 unsigned int *bytes_read
)
17291 bfd
*abfd
= cu
->objfile
->obfd
;
17292 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
17294 return read_addr_index (cu
, addr_index
);
17297 /* Data structure to pass results from dwarf2_read_addr_index_reader
17298 back to dwarf2_read_addr_index. */
17300 struct dwarf2_read_addr_index_data
17302 ULONGEST addr_base
;
17306 /* die_reader_func for dwarf2_read_addr_index. */
17309 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
17310 const gdb_byte
*info_ptr
,
17311 struct die_info
*comp_unit_die
,
17315 struct dwarf2_cu
*cu
= reader
->cu
;
17316 struct dwarf2_read_addr_index_data
*aidata
=
17317 (struct dwarf2_read_addr_index_data
*) data
;
17319 aidata
->addr_base
= cu
->addr_base
;
17320 aidata
->addr_size
= cu
->header
.addr_size
;
17323 /* Given an index in .debug_addr, fetch the value.
17324 NOTE: This can be called during dwarf expression evaluation,
17325 long after the debug information has been read, and thus per_cu->cu
17326 may no longer exist. */
17329 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
17330 unsigned int addr_index
)
17332 struct objfile
*objfile
= per_cu
->objfile
;
17333 struct dwarf2_cu
*cu
= per_cu
->cu
;
17334 ULONGEST addr_base
;
17337 /* This is intended to be called from outside this file. */
17338 dw2_setup (objfile
);
17340 /* We need addr_base and addr_size.
17341 If we don't have PER_CU->cu, we have to get it.
17342 Nasty, but the alternative is storing the needed info in PER_CU,
17343 which at this point doesn't seem justified: it's not clear how frequently
17344 it would get used and it would increase the size of every PER_CU.
17345 Entry points like dwarf2_per_cu_addr_size do a similar thing
17346 so we're not in uncharted territory here.
17347 Alas we need to be a bit more complicated as addr_base is contained
17350 We don't need to read the entire CU(/TU).
17351 We just need the header and top level die.
17353 IWBN to use the aging mechanism to let us lazily later discard the CU.
17354 For now we skip this optimization. */
17358 addr_base
= cu
->addr_base
;
17359 addr_size
= cu
->header
.addr_size
;
17363 struct dwarf2_read_addr_index_data aidata
;
17365 /* Note: We can't use init_cutu_and_read_dies_simple here,
17366 we need addr_base. */
17367 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
17368 dwarf2_read_addr_index_reader
, &aidata
);
17369 addr_base
= aidata
.addr_base
;
17370 addr_size
= aidata
.addr_size
;
17373 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
17376 /* Given a DW_FORM_GNU_str_index, fetch the string.
17377 This is only used by the Fission support. */
17379 static const char *
17380 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
17382 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17383 const char *objf_name
= objfile_name (objfile
);
17384 bfd
*abfd
= objfile
->obfd
;
17385 struct dwarf2_cu
*cu
= reader
->cu
;
17386 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
17387 struct dwarf2_section_info
*str_offsets_section
=
17388 &reader
->dwo_file
->sections
.str_offsets
;
17389 const gdb_byte
*info_ptr
;
17390 ULONGEST str_offset
;
17391 static const char form_name
[] = "DW_FORM_GNU_str_index";
17393 dwarf2_read_section (objfile
, str_section
);
17394 dwarf2_read_section (objfile
, str_offsets_section
);
17395 if (str_section
->buffer
== NULL
)
17396 error (_("%s used without .debug_str.dwo section"
17397 " in CU at offset 0x%x [in module %s]"),
17398 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
17399 if (str_offsets_section
->buffer
== NULL
)
17400 error (_("%s used without .debug_str_offsets.dwo section"
17401 " in CU at offset 0x%x [in module %s]"),
17402 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
17403 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
17404 error (_("%s pointing outside of .debug_str_offsets.dwo"
17405 " section in CU at offset 0x%x [in module %s]"),
17406 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
17407 info_ptr
= (str_offsets_section
->buffer
17408 + str_index
* cu
->header
.offset_size
);
17409 if (cu
->header
.offset_size
== 4)
17410 str_offset
= bfd_get_32 (abfd
, info_ptr
);
17412 str_offset
= bfd_get_64 (abfd
, info_ptr
);
17413 if (str_offset
>= str_section
->size
)
17414 error (_("Offset from %s pointing outside of"
17415 " .debug_str.dwo section in CU at offset 0x%x [in module %s]"),
17416 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
17417 return (const char *) (str_section
->buffer
+ str_offset
);
17420 /* Return the length of an LEB128 number in BUF. */
17423 leb128_size (const gdb_byte
*buf
)
17425 const gdb_byte
*begin
= buf
;
17431 if ((byte
& 128) == 0)
17432 return buf
- begin
;
17437 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
17446 cu
->language
= language_c
;
17449 case DW_LANG_C_plus_plus
:
17450 case DW_LANG_C_plus_plus_11
:
17451 case DW_LANG_C_plus_plus_14
:
17452 cu
->language
= language_cplus
;
17455 cu
->language
= language_d
;
17457 case DW_LANG_Fortran77
:
17458 case DW_LANG_Fortran90
:
17459 case DW_LANG_Fortran95
:
17460 case DW_LANG_Fortran03
:
17461 case DW_LANG_Fortran08
:
17462 cu
->language
= language_fortran
;
17465 cu
->language
= language_go
;
17467 case DW_LANG_Mips_Assembler
:
17468 cu
->language
= language_asm
;
17470 case DW_LANG_Ada83
:
17471 case DW_LANG_Ada95
:
17472 cu
->language
= language_ada
;
17474 case DW_LANG_Modula2
:
17475 cu
->language
= language_m2
;
17477 case DW_LANG_Pascal83
:
17478 cu
->language
= language_pascal
;
17481 cu
->language
= language_objc
;
17484 case DW_LANG_Rust_old
:
17485 cu
->language
= language_rust
;
17487 case DW_LANG_Cobol74
:
17488 case DW_LANG_Cobol85
:
17490 cu
->language
= language_minimal
;
17493 cu
->language_defn
= language_def (cu
->language
);
17496 /* Return the named attribute or NULL if not there. */
17498 static struct attribute
*
17499 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17504 struct attribute
*spec
= NULL
;
17506 for (i
= 0; i
< die
->num_attrs
; ++i
)
17508 if (die
->attrs
[i
].name
== name
)
17509 return &die
->attrs
[i
];
17510 if (die
->attrs
[i
].name
== DW_AT_specification
17511 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
17512 spec
= &die
->attrs
[i
];
17518 die
= follow_die_ref (die
, spec
, &cu
);
17524 /* Return the named attribute or NULL if not there,
17525 but do not follow DW_AT_specification, etc.
17526 This is for use in contexts where we're reading .debug_types dies.
17527 Following DW_AT_specification, DW_AT_abstract_origin will take us
17528 back up the chain, and we want to go down. */
17530 static struct attribute
*
17531 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
17535 for (i
= 0; i
< die
->num_attrs
; ++i
)
17536 if (die
->attrs
[i
].name
== name
)
17537 return &die
->attrs
[i
];
17542 /* Return the string associated with a string-typed attribute, or NULL if it
17543 is either not found or is of an incorrect type. */
17545 static const char *
17546 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17548 struct attribute
*attr
;
17549 const char *str
= NULL
;
17551 attr
= dwarf2_attr (die
, name
, cu
);
17555 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
17556 || attr
->form
== DW_FORM_string
|| attr
->form
== DW_FORM_GNU_strp_alt
)
17557 str
= DW_STRING (attr
);
17559 complaint (&symfile_complaints
,
17560 _("string type expected for attribute %s for "
17561 "DIE at 0x%x in module %s"),
17562 dwarf_attr_name (name
), to_underlying (die
->sect_off
),
17563 objfile_name (cu
->objfile
));
17569 /* Return non-zero iff the attribute NAME is defined for the given DIE,
17570 and holds a non-zero value. This function should only be used for
17571 DW_FORM_flag or DW_FORM_flag_present attributes. */
17574 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
17576 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
17578 return (attr
&& DW_UNSND (attr
));
17582 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
17584 /* A DIE is a declaration if it has a DW_AT_declaration attribute
17585 which value is non-zero. However, we have to be careful with
17586 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
17587 (via dwarf2_flag_true_p) follows this attribute. So we may
17588 end up accidently finding a declaration attribute that belongs
17589 to a different DIE referenced by the specification attribute,
17590 even though the given DIE does not have a declaration attribute. */
17591 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
17592 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
17595 /* Return the die giving the specification for DIE, if there is
17596 one. *SPEC_CU is the CU containing DIE on input, and the CU
17597 containing the return value on output. If there is no
17598 specification, but there is an abstract origin, that is
17601 static struct die_info
*
17602 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
17604 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
17607 if (spec_attr
== NULL
)
17608 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
17610 if (spec_attr
== NULL
)
17613 return follow_die_ref (die
, spec_attr
, spec_cu
);
17616 /* Stub for free_line_header to match void * callback types. */
17619 free_line_header_voidp (void *arg
)
17621 struct line_header
*lh
= (struct line_header
*) arg
;
17627 line_header::add_include_dir (const char *include_dir
)
17629 if (dwarf_line_debug
>= 2)
17630 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
17631 include_dirs
.size () + 1, include_dir
);
17633 include_dirs
.push_back (include_dir
);
17637 line_header::add_file_name (const char *name
,
17639 unsigned int mod_time
,
17640 unsigned int length
)
17642 if (dwarf_line_debug
>= 2)
17643 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
17644 (unsigned) file_names
.size () + 1, name
);
17646 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
17649 /* A convenience function to find the proper .debug_line section for a CU. */
17651 static struct dwarf2_section_info
*
17652 get_debug_line_section (struct dwarf2_cu
*cu
)
17654 struct dwarf2_section_info
*section
;
17656 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
17658 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17659 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
17660 else if (cu
->per_cu
->is_dwz
)
17662 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
17664 section
= &dwz
->line
;
17667 section
= &dwarf2_per_objfile
->line
;
17672 /* Read directory or file name entry format, starting with byte of
17673 format count entries, ULEB128 pairs of entry formats, ULEB128 of
17674 entries count and the entries themselves in the described entry
17678 read_formatted_entries (bfd
*abfd
, const gdb_byte
**bufp
,
17679 struct line_header
*lh
,
17680 const struct comp_unit_head
*cu_header
,
17681 void (*callback
) (struct line_header
*lh
,
17684 unsigned int mod_time
,
17685 unsigned int length
))
17687 gdb_byte format_count
, formati
;
17688 ULONGEST data_count
, datai
;
17689 const gdb_byte
*buf
= *bufp
;
17690 const gdb_byte
*format_header_data
;
17692 unsigned int bytes_read
;
17694 format_count
= read_1_byte (abfd
, buf
);
17696 format_header_data
= buf
;
17697 for (formati
= 0; formati
< format_count
; formati
++)
17699 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17701 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17705 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17707 for (datai
= 0; datai
< data_count
; datai
++)
17709 const gdb_byte
*format
= format_header_data
;
17710 struct file_entry fe
;
17712 for (formati
= 0; formati
< format_count
; formati
++)
17714 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
17715 format
+= bytes_read
;
17717 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
17718 format
+= bytes_read
;
17720 gdb::optional
<const char *> string
;
17721 gdb::optional
<unsigned int> uint
;
17725 case DW_FORM_string
:
17726 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
17730 case DW_FORM_line_strp
:
17731 string
.emplace (read_indirect_line_string (abfd
, buf
,
17737 case DW_FORM_data1
:
17738 uint
.emplace (read_1_byte (abfd
, buf
));
17742 case DW_FORM_data2
:
17743 uint
.emplace (read_2_bytes (abfd
, buf
));
17747 case DW_FORM_data4
:
17748 uint
.emplace (read_4_bytes (abfd
, buf
));
17752 case DW_FORM_data8
:
17753 uint
.emplace (read_8_bytes (abfd
, buf
));
17757 case DW_FORM_udata
:
17758 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
17762 case DW_FORM_block
:
17763 /* It is valid only for DW_LNCT_timestamp which is ignored by
17768 switch (content_type
)
17771 if (string
.has_value ())
17774 case DW_LNCT_directory_index
:
17775 if (uint
.has_value ())
17776 fe
.d_index
= (dir_index
) *uint
;
17778 case DW_LNCT_timestamp
:
17779 if (uint
.has_value ())
17780 fe
.mod_time
= *uint
;
17783 if (uint
.has_value ())
17789 complaint (&symfile_complaints
,
17790 _("Unknown format content type %s"),
17791 pulongest (content_type
));
17795 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
17801 /* Read the statement program header starting at OFFSET in
17802 .debug_line, or .debug_line.dwo. Return a pointer
17803 to a struct line_header, allocated using xmalloc.
17804 Returns NULL if there is a problem reading the header, e.g., if it
17805 has a version we don't understand.
17807 NOTE: the strings in the include directory and file name tables of
17808 the returned object point into the dwarf line section buffer,
17809 and must not be freed. */
17811 static line_header_up
17812 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
17814 const gdb_byte
*line_ptr
;
17815 unsigned int bytes_read
, offset_size
;
17817 const char *cur_dir
, *cur_file
;
17818 struct dwarf2_section_info
*section
;
17821 section
= get_debug_line_section (cu
);
17822 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
17823 if (section
->buffer
== NULL
)
17825 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17826 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
17828 complaint (&symfile_complaints
, _("missing .debug_line section"));
17832 /* We can't do this until we know the section is non-empty.
17833 Only then do we know we have such a section. */
17834 abfd
= get_section_bfd_owner (section
);
17836 /* Make sure that at least there's room for the total_length field.
17837 That could be 12 bytes long, but we're just going to fudge that. */
17838 if (to_underlying (sect_off
) + 4 >= section
->size
)
17840 dwarf2_statement_list_fits_in_line_number_section_complaint ();
17844 line_header_up
lh (new line_header ());
17846 lh
->sect_off
= sect_off
;
17847 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
17849 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
17851 /* Read in the header. */
17853 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
17854 &bytes_read
, &offset_size
);
17855 line_ptr
+= bytes_read
;
17856 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
17858 dwarf2_statement_list_fits_in_line_number_section_complaint ();
17861 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
17862 lh
->version
= read_2_bytes (abfd
, line_ptr
);
17864 if (lh
->version
> 5)
17866 /* This is a version we don't understand. The format could have
17867 changed in ways we don't handle properly so just punt. */
17868 complaint (&symfile_complaints
,
17869 _("unsupported version in .debug_line section"));
17872 if (lh
->version
>= 5)
17874 gdb_byte segment_selector_size
;
17876 /* Skip address size. */
17877 read_1_byte (abfd
, line_ptr
);
17880 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
17882 if (segment_selector_size
!= 0)
17884 complaint (&symfile_complaints
,
17885 _("unsupported segment selector size %u "
17886 "in .debug_line section"),
17887 segment_selector_size
);
17891 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
17892 line_ptr
+= offset_size
;
17893 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
17895 if (lh
->version
>= 4)
17897 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
17901 lh
->maximum_ops_per_instruction
= 1;
17903 if (lh
->maximum_ops_per_instruction
== 0)
17905 lh
->maximum_ops_per_instruction
= 1;
17906 complaint (&symfile_complaints
,
17907 _("invalid maximum_ops_per_instruction "
17908 "in `.debug_line' section"));
17911 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
17913 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
17915 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
17917 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
17919 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
17921 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
17922 for (i
= 1; i
< lh
->opcode_base
; ++i
)
17924 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
17928 if (lh
->version
>= 5)
17930 /* Read directory table. */
17931 read_formatted_entries (abfd
, &line_ptr
, lh
.get (), &cu
->header
,
17932 [] (struct line_header
*lh
, const char *name
,
17933 dir_index d_index
, unsigned int mod_time
,
17934 unsigned int length
)
17936 lh
->add_include_dir (name
);
17939 /* Read file name table. */
17940 read_formatted_entries (abfd
, &line_ptr
, lh
.get (), &cu
->header
,
17941 [] (struct line_header
*lh
, const char *name
,
17942 dir_index d_index
, unsigned int mod_time
,
17943 unsigned int length
)
17945 lh
->add_file_name (name
, d_index
, mod_time
, length
);
17950 /* Read directory table. */
17951 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
17953 line_ptr
+= bytes_read
;
17954 lh
->add_include_dir (cur_dir
);
17956 line_ptr
+= bytes_read
;
17958 /* Read file name table. */
17959 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
17961 unsigned int mod_time
, length
;
17964 line_ptr
+= bytes_read
;
17965 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17966 line_ptr
+= bytes_read
;
17967 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17968 line_ptr
+= bytes_read
;
17969 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17970 line_ptr
+= bytes_read
;
17972 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
17974 line_ptr
+= bytes_read
;
17976 lh
->statement_program_start
= line_ptr
;
17978 if (line_ptr
> (section
->buffer
+ section
->size
))
17979 complaint (&symfile_complaints
,
17980 _("line number info header doesn't "
17981 "fit in `.debug_line' section"));
17986 /* Subroutine of dwarf_decode_lines to simplify it.
17987 Return the file name of the psymtab for included file FILE_INDEX
17988 in line header LH of PST.
17989 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
17990 If space for the result is malloc'd, it will be freed by a cleanup.
17991 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
17993 The function creates dangling cleanup registration. */
17995 static const char *
17996 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
17997 const struct partial_symtab
*pst
,
17998 const char *comp_dir
)
18000 const file_entry
&fe
= lh
->file_names
[file_index
];
18001 const char *include_name
= fe
.name
;
18002 const char *include_name_to_compare
= include_name
;
18003 const char *pst_filename
;
18004 char *copied_name
= NULL
;
18007 const char *dir_name
= fe
.include_dir (lh
);
18009 if (!IS_ABSOLUTE_PATH (include_name
)
18010 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
18012 /* Avoid creating a duplicate psymtab for PST.
18013 We do this by comparing INCLUDE_NAME and PST_FILENAME.
18014 Before we do the comparison, however, we need to account
18015 for DIR_NAME and COMP_DIR.
18016 First prepend dir_name (if non-NULL). If we still don't
18017 have an absolute path prepend comp_dir (if non-NULL).
18018 However, the directory we record in the include-file's
18019 psymtab does not contain COMP_DIR (to match the
18020 corresponding symtab(s)).
18025 bash$ gcc -g ./hello.c
18026 include_name = "hello.c"
18028 DW_AT_comp_dir = comp_dir = "/tmp"
18029 DW_AT_name = "./hello.c"
18033 if (dir_name
!= NULL
)
18035 char *tem
= concat (dir_name
, SLASH_STRING
,
18036 include_name
, (char *)NULL
);
18038 make_cleanup (xfree
, tem
);
18039 include_name
= tem
;
18040 include_name_to_compare
= include_name
;
18042 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
18044 char *tem
= concat (comp_dir
, SLASH_STRING
,
18045 include_name
, (char *)NULL
);
18047 make_cleanup (xfree
, tem
);
18048 include_name_to_compare
= tem
;
18052 pst_filename
= pst
->filename
;
18053 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
18055 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
18056 pst_filename
, (char *)NULL
);
18057 pst_filename
= copied_name
;
18060 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
18062 if (copied_name
!= NULL
)
18063 xfree (copied_name
);
18067 return include_name
;
18070 /* State machine to track the state of the line number program. */
18072 class lnp_state_machine
18075 /* Initialize a machine state for the start of a line number
18077 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
18079 file_entry
*current_file ()
18081 /* lh->file_names is 0-based, but the file name numbers in the
18082 statement program are 1-based. */
18083 return m_line_header
->file_name_at (m_file
);
18086 /* Record the line in the state machine. END_SEQUENCE is true if
18087 we're processing the end of a sequence. */
18088 void record_line (bool end_sequence
);
18090 /* Check address and if invalid nop-out the rest of the lines in this
18092 void check_line_address (struct dwarf2_cu
*cu
,
18093 const gdb_byte
*line_ptr
,
18094 CORE_ADDR lowpc
, CORE_ADDR address
);
18096 void handle_set_discriminator (unsigned int discriminator
)
18098 m_discriminator
= discriminator
;
18099 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
18102 /* Handle DW_LNE_set_address. */
18103 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
18106 address
+= baseaddr
;
18107 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
18110 /* Handle DW_LNS_advance_pc. */
18111 void handle_advance_pc (CORE_ADDR adjust
);
18113 /* Handle a special opcode. */
18114 void handle_special_opcode (unsigned char op_code
);
18116 /* Handle DW_LNS_advance_line. */
18117 void handle_advance_line (int line_delta
)
18119 advance_line (line_delta
);
18122 /* Handle DW_LNS_set_file. */
18123 void handle_set_file (file_name_index file
);
18125 /* Handle DW_LNS_negate_stmt. */
18126 void handle_negate_stmt ()
18128 m_is_stmt
= !m_is_stmt
;
18131 /* Handle DW_LNS_const_add_pc. */
18132 void handle_const_add_pc ();
18134 /* Handle DW_LNS_fixed_advance_pc. */
18135 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
18137 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18141 /* Handle DW_LNS_copy. */
18142 void handle_copy ()
18144 record_line (false);
18145 m_discriminator
= 0;
18148 /* Handle DW_LNE_end_sequence. */
18149 void handle_end_sequence ()
18151 m_record_line_callback
= ::record_line
;
18155 /* Advance the line by LINE_DELTA. */
18156 void advance_line (int line_delta
)
18158 m_line
+= line_delta
;
18160 if (line_delta
!= 0)
18161 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
18164 gdbarch
*m_gdbarch
;
18166 /* True if we're recording lines.
18167 Otherwise we're building partial symtabs and are just interested in
18168 finding include files mentioned by the line number program. */
18169 bool m_record_lines_p
;
18171 /* The line number header. */
18172 line_header
*m_line_header
;
18174 /* These are part of the standard DWARF line number state machine,
18175 and initialized according to the DWARF spec. */
18177 unsigned char m_op_index
= 0;
18178 /* The line table index (1-based) of the current file. */
18179 file_name_index m_file
= (file_name_index
) 1;
18180 unsigned int m_line
= 1;
18182 /* These are initialized in the constructor. */
18184 CORE_ADDR m_address
;
18186 unsigned int m_discriminator
;
18188 /* Additional bits of state we need to track. */
18190 /* The last file that we called dwarf2_start_subfile for.
18191 This is only used for TLLs. */
18192 unsigned int m_last_file
= 0;
18193 /* The last file a line number was recorded for. */
18194 struct subfile
*m_last_subfile
= NULL
;
18196 /* The function to call to record a line. */
18197 record_line_ftype
*m_record_line_callback
= NULL
;
18199 /* The last line number that was recorded, used to coalesce
18200 consecutive entries for the same line. This can happen, for
18201 example, when discriminators are present. PR 17276. */
18202 unsigned int m_last_line
= 0;
18203 bool m_line_has_non_zero_discriminator
= false;
18207 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
18209 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
18210 / m_line_header
->maximum_ops_per_instruction
)
18211 * m_line_header
->minimum_instruction_length
);
18212 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18213 m_op_index
= ((m_op_index
+ adjust
)
18214 % m_line_header
->maximum_ops_per_instruction
);
18218 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
18220 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
18221 CORE_ADDR addr_adj
= (((m_op_index
18222 + (adj_opcode
/ m_line_header
->line_range
))
18223 / m_line_header
->maximum_ops_per_instruction
)
18224 * m_line_header
->minimum_instruction_length
);
18225 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18226 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
18227 % m_line_header
->maximum_ops_per_instruction
);
18229 int line_delta
= (m_line_header
->line_base
18230 + (adj_opcode
% m_line_header
->line_range
));
18231 advance_line (line_delta
);
18232 record_line (false);
18233 m_discriminator
= 0;
18237 lnp_state_machine::handle_set_file (file_name_index file
)
18241 const file_entry
*fe
= current_file ();
18243 dwarf2_debug_line_missing_file_complaint ();
18244 else if (m_record_lines_p
)
18246 const char *dir
= fe
->include_dir (m_line_header
);
18248 m_last_subfile
= current_subfile
;
18249 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
18250 dwarf2_start_subfile (fe
->name
, dir
);
18255 lnp_state_machine::handle_const_add_pc ()
18258 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
18261 = (((m_op_index
+ adjust
)
18262 / m_line_header
->maximum_ops_per_instruction
)
18263 * m_line_header
->minimum_instruction_length
);
18265 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18266 m_op_index
= ((m_op_index
+ adjust
)
18267 % m_line_header
->maximum_ops_per_instruction
);
18270 /* Ignore this record_line request. */
18273 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
18278 /* Return non-zero if we should add LINE to the line number table.
18279 LINE is the line to add, LAST_LINE is the last line that was added,
18280 LAST_SUBFILE is the subfile for LAST_LINE.
18281 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
18282 had a non-zero discriminator.
18284 We have to be careful in the presence of discriminators.
18285 E.g., for this line:
18287 for (i = 0; i < 100000; i++);
18289 clang can emit four line number entries for that one line,
18290 each with a different discriminator.
18291 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
18293 However, we want gdb to coalesce all four entries into one.
18294 Otherwise the user could stepi into the middle of the line and
18295 gdb would get confused about whether the pc really was in the
18296 middle of the line.
18298 Things are further complicated by the fact that two consecutive
18299 line number entries for the same line is a heuristic used by gcc
18300 to denote the end of the prologue. So we can't just discard duplicate
18301 entries, we have to be selective about it. The heuristic we use is
18302 that we only collapse consecutive entries for the same line if at least
18303 one of those entries has a non-zero discriminator. PR 17276.
18305 Note: Addresses in the line number state machine can never go backwards
18306 within one sequence, thus this coalescing is ok. */
18309 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
18310 int line_has_non_zero_discriminator
,
18311 struct subfile
*last_subfile
)
18313 if (current_subfile
!= last_subfile
)
18315 if (line
!= last_line
)
18317 /* Same line for the same file that we've seen already.
18318 As a last check, for pr 17276, only record the line if the line
18319 has never had a non-zero discriminator. */
18320 if (!line_has_non_zero_discriminator
)
18325 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
18326 in the line table of subfile SUBFILE. */
18329 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
18330 unsigned int line
, CORE_ADDR address
,
18331 record_line_ftype p_record_line
)
18333 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
18335 if (dwarf_line_debug
)
18337 fprintf_unfiltered (gdb_stdlog
,
18338 "Recording line %u, file %s, address %s\n",
18339 line
, lbasename (subfile
->name
),
18340 paddress (gdbarch
, address
));
18343 (*p_record_line
) (subfile
, line
, addr
);
18346 /* Subroutine of dwarf_decode_lines_1 to simplify it.
18347 Mark the end of a set of line number records.
18348 The arguments are the same as for dwarf_record_line_1.
18349 If SUBFILE is NULL the request is ignored. */
18352 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
18353 CORE_ADDR address
, record_line_ftype p_record_line
)
18355 if (subfile
== NULL
)
18358 if (dwarf_line_debug
)
18360 fprintf_unfiltered (gdb_stdlog
,
18361 "Finishing current line, file %s, address %s\n",
18362 lbasename (subfile
->name
),
18363 paddress (gdbarch
, address
));
18366 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
18370 lnp_state_machine::record_line (bool end_sequence
)
18372 if (dwarf_line_debug
)
18374 fprintf_unfiltered (gdb_stdlog
,
18375 "Processing actual line %u: file %u,"
18376 " address %s, is_stmt %u, discrim %u\n",
18377 m_line
, to_underlying (m_file
),
18378 paddress (m_gdbarch
, m_address
),
18379 m_is_stmt
, m_discriminator
);
18382 file_entry
*fe
= current_file ();
18385 dwarf2_debug_line_missing_file_complaint ();
18386 /* For now we ignore lines not starting on an instruction boundary.
18387 But not when processing end_sequence for compatibility with the
18388 previous version of the code. */
18389 else if (m_op_index
== 0 || end_sequence
)
18391 fe
->included_p
= 1;
18392 if (m_record_lines_p
&& m_is_stmt
)
18394 if (m_last_subfile
!= current_subfile
|| end_sequence
)
18396 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
18397 m_address
, m_record_line_callback
);
18402 if (dwarf_record_line_p (m_line
, m_last_line
,
18403 m_line_has_non_zero_discriminator
,
18406 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
18408 m_record_line_callback
);
18410 m_last_subfile
= current_subfile
;
18411 m_last_line
= m_line
;
18417 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
18418 bool record_lines_p
)
18421 m_record_lines_p
= record_lines_p
;
18422 m_line_header
= lh
;
18424 m_record_line_callback
= ::record_line
;
18426 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
18427 was a line entry for it so that the backend has a chance to adjust it
18428 and also record it in case it needs it. This is currently used by MIPS
18429 code, cf. `mips_adjust_dwarf2_line'. */
18430 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
18431 m_is_stmt
= lh
->default_is_stmt
;
18432 m_discriminator
= 0;
18436 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
18437 const gdb_byte
*line_ptr
,
18438 CORE_ADDR lowpc
, CORE_ADDR address
)
18440 /* If address < lowpc then it's not a usable value, it's outside the
18441 pc range of the CU. However, we restrict the test to only address
18442 values of zero to preserve GDB's previous behaviour which is to
18443 handle the specific case of a function being GC'd by the linker. */
18445 if (address
== 0 && address
< lowpc
)
18447 /* This line table is for a function which has been
18448 GCd by the linker. Ignore it. PR gdb/12528 */
18450 struct objfile
*objfile
= cu
->objfile
;
18451 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
18453 complaint (&symfile_complaints
,
18454 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
18455 line_offset
, objfile_name (objfile
));
18456 m_record_line_callback
= noop_record_line
;
18457 /* Note: record_line_callback is left as noop_record_line until
18458 we see DW_LNE_end_sequence. */
18462 /* Subroutine of dwarf_decode_lines to simplify it.
18463 Process the line number information in LH.
18464 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
18465 program in order to set included_p for every referenced header. */
18468 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
18469 const int decode_for_pst_p
, CORE_ADDR lowpc
)
18471 const gdb_byte
*line_ptr
, *extended_end
;
18472 const gdb_byte
*line_end
;
18473 unsigned int bytes_read
, extended_len
;
18474 unsigned char op_code
, extended_op
;
18475 CORE_ADDR baseaddr
;
18476 struct objfile
*objfile
= cu
->objfile
;
18477 bfd
*abfd
= objfile
->obfd
;
18478 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18479 /* True if we're recording line info (as opposed to building partial
18480 symtabs and just interested in finding include files mentioned by
18481 the line number program). */
18482 bool record_lines_p
= !decode_for_pst_p
;
18484 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18486 line_ptr
= lh
->statement_program_start
;
18487 line_end
= lh
->statement_program_end
;
18489 /* Read the statement sequences until there's nothing left. */
18490 while (line_ptr
< line_end
)
18492 /* The DWARF line number program state machine. Reset the state
18493 machine at the start of each sequence. */
18494 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
18495 bool end_sequence
= false;
18497 if (record_lines_p
)
18499 /* Start a subfile for the current file of the state
18501 const file_entry
*fe
= state_machine
.current_file ();
18504 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
18507 /* Decode the table. */
18508 while (line_ptr
< line_end
&& !end_sequence
)
18510 op_code
= read_1_byte (abfd
, line_ptr
);
18513 if (op_code
>= lh
->opcode_base
)
18515 /* Special opcode. */
18516 state_machine
.handle_special_opcode (op_code
);
18518 else switch (op_code
)
18520 case DW_LNS_extended_op
:
18521 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
18523 line_ptr
+= bytes_read
;
18524 extended_end
= line_ptr
+ extended_len
;
18525 extended_op
= read_1_byte (abfd
, line_ptr
);
18527 switch (extended_op
)
18529 case DW_LNE_end_sequence
:
18530 state_machine
.handle_end_sequence ();
18531 end_sequence
= true;
18533 case DW_LNE_set_address
:
18536 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
18537 line_ptr
+= bytes_read
;
18539 state_machine
.check_line_address (cu
, line_ptr
,
18541 state_machine
.handle_set_address (baseaddr
, address
);
18544 case DW_LNE_define_file
:
18546 const char *cur_file
;
18547 unsigned int mod_time
, length
;
18550 cur_file
= read_direct_string (abfd
, line_ptr
,
18552 line_ptr
+= bytes_read
;
18553 dindex
= (dir_index
)
18554 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18555 line_ptr
+= bytes_read
;
18557 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18558 line_ptr
+= bytes_read
;
18560 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18561 line_ptr
+= bytes_read
;
18562 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
18565 case DW_LNE_set_discriminator
:
18567 /* The discriminator is not interesting to the
18568 debugger; just ignore it. We still need to
18569 check its value though:
18570 if there are consecutive entries for the same
18571 (non-prologue) line we want to coalesce them.
18574 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18575 line_ptr
+= bytes_read
;
18577 state_machine
.handle_set_discriminator (discr
);
18581 complaint (&symfile_complaints
,
18582 _("mangled .debug_line section"));
18585 /* Make sure that we parsed the extended op correctly. If e.g.
18586 we expected a different address size than the producer used,
18587 we may have read the wrong number of bytes. */
18588 if (line_ptr
!= extended_end
)
18590 complaint (&symfile_complaints
,
18591 _("mangled .debug_line section"));
18596 state_machine
.handle_copy ();
18598 case DW_LNS_advance_pc
:
18601 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18602 line_ptr
+= bytes_read
;
18604 state_machine
.handle_advance_pc (adjust
);
18607 case DW_LNS_advance_line
:
18610 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
18611 line_ptr
+= bytes_read
;
18613 state_machine
.handle_advance_line (line_delta
);
18616 case DW_LNS_set_file
:
18618 file_name_index file
18619 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
18621 line_ptr
+= bytes_read
;
18623 state_machine
.handle_set_file (file
);
18626 case DW_LNS_set_column
:
18627 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18628 line_ptr
+= bytes_read
;
18630 case DW_LNS_negate_stmt
:
18631 state_machine
.handle_negate_stmt ();
18633 case DW_LNS_set_basic_block
:
18635 /* Add to the address register of the state machine the
18636 address increment value corresponding to special opcode
18637 255. I.e., this value is scaled by the minimum
18638 instruction length since special opcode 255 would have
18639 scaled the increment. */
18640 case DW_LNS_const_add_pc
:
18641 state_machine
.handle_const_add_pc ();
18643 case DW_LNS_fixed_advance_pc
:
18645 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
18648 state_machine
.handle_fixed_advance_pc (addr_adj
);
18653 /* Unknown standard opcode, ignore it. */
18656 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
18658 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18659 line_ptr
+= bytes_read
;
18666 dwarf2_debug_line_missing_end_sequence_complaint ();
18668 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
18669 in which case we still finish recording the last line). */
18670 state_machine
.record_line (true);
18674 /* Decode the Line Number Program (LNP) for the given line_header
18675 structure and CU. The actual information extracted and the type
18676 of structures created from the LNP depends on the value of PST.
18678 1. If PST is NULL, then this procedure uses the data from the program
18679 to create all necessary symbol tables, and their linetables.
18681 2. If PST is not NULL, this procedure reads the program to determine
18682 the list of files included by the unit represented by PST, and
18683 builds all the associated partial symbol tables.
18685 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
18686 It is used for relative paths in the line table.
18687 NOTE: When processing partial symtabs (pst != NULL),
18688 comp_dir == pst->dirname.
18690 NOTE: It is important that psymtabs have the same file name (via strcmp)
18691 as the corresponding symtab. Since COMP_DIR is not used in the name of the
18692 symtab we don't use it in the name of the psymtabs we create.
18693 E.g. expand_line_sal requires this when finding psymtabs to expand.
18694 A good testcase for this is mb-inline.exp.
18696 LOWPC is the lowest address in CU (or 0 if not known).
18698 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
18699 for its PC<->lines mapping information. Otherwise only the filename
18700 table is read in. */
18703 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
18704 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
18705 CORE_ADDR lowpc
, int decode_mapping
)
18707 struct objfile
*objfile
= cu
->objfile
;
18708 const int decode_for_pst_p
= (pst
!= NULL
);
18710 if (decode_mapping
)
18711 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
18713 if (decode_for_pst_p
)
18717 /* Now that we're done scanning the Line Header Program, we can
18718 create the psymtab of each included file. */
18719 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
18720 if (lh
->file_names
[file_index
].included_p
== 1)
18722 const char *include_name
=
18723 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
18724 if (include_name
!= NULL
)
18725 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
18730 /* Make sure a symtab is created for every file, even files
18731 which contain only variables (i.e. no code with associated
18733 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
18736 for (i
= 0; i
< lh
->file_names
.size (); i
++)
18738 file_entry
&fe
= lh
->file_names
[i
];
18740 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
18742 if (current_subfile
->symtab
== NULL
)
18744 current_subfile
->symtab
18745 = allocate_symtab (cust
, current_subfile
->name
);
18747 fe
.symtab
= current_subfile
->symtab
;
18752 /* Start a subfile for DWARF. FILENAME is the name of the file and
18753 DIRNAME the name of the source directory which contains FILENAME
18754 or NULL if not known.
18755 This routine tries to keep line numbers from identical absolute and
18756 relative file names in a common subfile.
18758 Using the `list' example from the GDB testsuite, which resides in
18759 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
18760 of /srcdir/list0.c yields the following debugging information for list0.c:
18762 DW_AT_name: /srcdir/list0.c
18763 DW_AT_comp_dir: /compdir
18764 files.files[0].name: list0.h
18765 files.files[0].dir: /srcdir
18766 files.files[1].name: list0.c
18767 files.files[1].dir: /srcdir
18769 The line number information for list0.c has to end up in a single
18770 subfile, so that `break /srcdir/list0.c:1' works as expected.
18771 start_subfile will ensure that this happens provided that we pass the
18772 concatenation of files.files[1].dir and files.files[1].name as the
18776 dwarf2_start_subfile (const char *filename
, const char *dirname
)
18780 /* In order not to lose the line information directory,
18781 we concatenate it to the filename when it makes sense.
18782 Note that the Dwarf3 standard says (speaking of filenames in line
18783 information): ``The directory index is ignored for file names
18784 that represent full path names''. Thus ignoring dirname in the
18785 `else' branch below isn't an issue. */
18787 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
18789 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
18793 start_subfile (filename
);
18799 /* Start a symtab for DWARF.
18800 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
18802 static struct compunit_symtab
*
18803 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
18804 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
18806 struct compunit_symtab
*cust
18807 = start_symtab (cu
->objfile
, name
, comp_dir
, low_pc
);
18809 record_debugformat ("DWARF 2");
18810 record_producer (cu
->producer
);
18812 /* We assume that we're processing GCC output. */
18813 processing_gcc_compilation
= 2;
18815 cu
->processing_has_namespace_info
= 0;
18821 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
18822 struct dwarf2_cu
*cu
)
18824 struct objfile
*objfile
= cu
->objfile
;
18825 struct comp_unit_head
*cu_header
= &cu
->header
;
18827 /* NOTE drow/2003-01-30: There used to be a comment and some special
18828 code here to turn a symbol with DW_AT_external and a
18829 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
18830 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
18831 with some versions of binutils) where shared libraries could have
18832 relocations against symbols in their debug information - the
18833 minimal symbol would have the right address, but the debug info
18834 would not. It's no longer necessary, because we will explicitly
18835 apply relocations when we read in the debug information now. */
18837 /* A DW_AT_location attribute with no contents indicates that a
18838 variable has been optimized away. */
18839 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
18841 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
18845 /* Handle one degenerate form of location expression specially, to
18846 preserve GDB's previous behavior when section offsets are
18847 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
18848 then mark this symbol as LOC_STATIC. */
18850 if (attr_form_is_block (attr
)
18851 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
18852 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
18853 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
18854 && (DW_BLOCK (attr
)->size
18855 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
18857 unsigned int dummy
;
18859 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
18860 SYMBOL_VALUE_ADDRESS (sym
) =
18861 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
18863 SYMBOL_VALUE_ADDRESS (sym
) =
18864 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
18865 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
18866 fixup_symbol_section (sym
, objfile
);
18867 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
18868 SYMBOL_SECTION (sym
));
18872 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
18873 expression evaluator, and use LOC_COMPUTED only when necessary
18874 (i.e. when the value of a register or memory location is
18875 referenced, or a thread-local block, etc.). Then again, it might
18876 not be worthwhile. I'm assuming that it isn't unless performance
18877 or memory numbers show me otherwise. */
18879 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
18881 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
18882 cu
->has_loclist
= 1;
18885 /* Given a pointer to a DWARF information entry, figure out if we need
18886 to make a symbol table entry for it, and if so, create a new entry
18887 and return a pointer to it.
18888 If TYPE is NULL, determine symbol type from the die, otherwise
18889 used the passed type.
18890 If SPACE is not NULL, use it to hold the new symbol. If it is
18891 NULL, allocate a new symbol on the objfile's obstack. */
18893 static struct symbol
*
18894 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
18895 struct symbol
*space
)
18897 struct objfile
*objfile
= cu
->objfile
;
18898 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18899 struct symbol
*sym
= NULL
;
18901 struct attribute
*attr
= NULL
;
18902 struct attribute
*attr2
= NULL
;
18903 CORE_ADDR baseaddr
;
18904 struct pending
**list_to_add
= NULL
;
18906 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
18908 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18910 name
= dwarf2_name (die
, cu
);
18913 const char *linkagename
;
18914 int suppress_add
= 0;
18919 sym
= allocate_symbol (objfile
);
18920 OBJSTAT (objfile
, n_syms
++);
18922 /* Cache this symbol's name and the name's demangled form (if any). */
18923 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
18924 linkagename
= dwarf2_physname (name
, die
, cu
);
18925 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
18927 /* Fortran does not have mangling standard and the mangling does differ
18928 between gfortran, iFort etc. */
18929 if (cu
->language
== language_fortran
18930 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
18931 symbol_set_demangled_name (&(sym
->ginfo
),
18932 dwarf2_full_name (name
, die
, cu
),
18935 /* Default assumptions.
18936 Use the passed type or decode it from the die. */
18937 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
18938 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
18940 SYMBOL_TYPE (sym
) = type
;
18942 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
18943 attr
= dwarf2_attr (die
,
18944 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
18948 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
18951 attr
= dwarf2_attr (die
,
18952 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
18956 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
18957 struct file_entry
*fe
;
18959 if (cu
->line_header
!= NULL
)
18960 fe
= cu
->line_header
->file_name_at (file_index
);
18965 complaint (&symfile_complaints
,
18966 _("file index out of range"));
18968 symbol_set_symtab (sym
, fe
->symtab
);
18974 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
18979 addr
= attr_value_as_address (attr
);
18980 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
18981 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
18983 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
18984 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
18985 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
18986 add_symbol_to_list (sym
, cu
->list_in_scope
);
18988 case DW_TAG_subprogram
:
18989 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
18991 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
18992 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18993 if ((attr2
&& (DW_UNSND (attr2
) != 0))
18994 || cu
->language
== language_ada
)
18996 /* Subprograms marked external are stored as a global symbol.
18997 Ada subprograms, whether marked external or not, are always
18998 stored as a global symbol, because we want to be able to
18999 access them globally. For instance, we want to be able
19000 to break on a nested subprogram without having to
19001 specify the context. */
19002 list_to_add
= &global_symbols
;
19006 list_to_add
= cu
->list_in_scope
;
19009 case DW_TAG_inlined_subroutine
:
19010 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
19012 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
19013 SYMBOL_INLINED (sym
) = 1;
19014 list_to_add
= cu
->list_in_scope
;
19016 case DW_TAG_template_value_param
:
19018 /* Fall through. */
19019 case DW_TAG_constant
:
19020 case DW_TAG_variable
:
19021 case DW_TAG_member
:
19022 /* Compilation with minimal debug info may result in
19023 variables with missing type entries. Change the
19024 misleading `void' type to something sensible. */
19025 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
19027 = objfile_type (objfile
)->nodebug_data_symbol
;
19029 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19030 /* In the case of DW_TAG_member, we should only be called for
19031 static const members. */
19032 if (die
->tag
== DW_TAG_member
)
19034 /* dwarf2_add_field uses die_is_declaration,
19035 so we do the same. */
19036 gdb_assert (die_is_declaration (die
, cu
));
19041 dwarf2_const_value (attr
, sym
, cu
);
19042 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19045 if (attr2
&& (DW_UNSND (attr2
) != 0))
19046 list_to_add
= &global_symbols
;
19048 list_to_add
= cu
->list_in_scope
;
19052 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
19055 var_decode_location (attr
, sym
, cu
);
19056 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19058 /* Fortran explicitly imports any global symbols to the local
19059 scope by DW_TAG_common_block. */
19060 if (cu
->language
== language_fortran
&& die
->parent
19061 && die
->parent
->tag
== DW_TAG_common_block
)
19064 if (SYMBOL_CLASS (sym
) == LOC_STATIC
19065 && SYMBOL_VALUE_ADDRESS (sym
) == 0
19066 && !dwarf2_per_objfile
->has_section_at_zero
)
19068 /* When a static variable is eliminated by the linker,
19069 the corresponding debug information is not stripped
19070 out, but the variable address is set to null;
19071 do not add such variables into symbol table. */
19073 else if (attr2
&& (DW_UNSND (attr2
) != 0))
19075 /* Workaround gfortran PR debug/40040 - it uses
19076 DW_AT_location for variables in -fPIC libraries which may
19077 get overriden by other libraries/executable and get
19078 a different address. Resolve it by the minimal symbol
19079 which may come from inferior's executable using copy
19080 relocation. Make this workaround only for gfortran as for
19081 other compilers GDB cannot guess the minimal symbol
19082 Fortran mangling kind. */
19083 if (cu
->language
== language_fortran
&& die
->parent
19084 && die
->parent
->tag
== DW_TAG_module
19086 && startswith (cu
->producer
, "GNU Fortran"))
19087 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
19089 /* A variable with DW_AT_external is never static,
19090 but it may be block-scoped. */
19091 list_to_add
= (cu
->list_in_scope
== &file_symbols
19092 ? &global_symbols
: cu
->list_in_scope
);
19095 list_to_add
= cu
->list_in_scope
;
19099 /* We do not know the address of this symbol.
19100 If it is an external symbol and we have type information
19101 for it, enter the symbol as a LOC_UNRESOLVED symbol.
19102 The address of the variable will then be determined from
19103 the minimal symbol table whenever the variable is
19105 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19107 /* Fortran explicitly imports any global symbols to the local
19108 scope by DW_TAG_common_block. */
19109 if (cu
->language
== language_fortran
&& die
->parent
19110 && die
->parent
->tag
== DW_TAG_common_block
)
19112 /* SYMBOL_CLASS doesn't matter here because
19113 read_common_block is going to reset it. */
19115 list_to_add
= cu
->list_in_scope
;
19117 else if (attr2
&& (DW_UNSND (attr2
) != 0)
19118 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
19120 /* A variable with DW_AT_external is never static, but it
19121 may be block-scoped. */
19122 list_to_add
= (cu
->list_in_scope
== &file_symbols
19123 ? &global_symbols
: cu
->list_in_scope
);
19125 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
19127 else if (!die_is_declaration (die
, cu
))
19129 /* Use the default LOC_OPTIMIZED_OUT class. */
19130 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
19132 list_to_add
= cu
->list_in_scope
;
19136 case DW_TAG_formal_parameter
:
19137 /* If we are inside a function, mark this as an argument. If
19138 not, we might be looking at an argument to an inlined function
19139 when we do not have enough information to show inlined frames;
19140 pretend it's a local variable in that case so that the user can
19142 if (context_stack_depth
> 0
19143 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
19144 SYMBOL_IS_ARGUMENT (sym
) = 1;
19145 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
19148 var_decode_location (attr
, sym
, cu
);
19150 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19153 dwarf2_const_value (attr
, sym
, cu
);
19156 list_to_add
= cu
->list_in_scope
;
19158 case DW_TAG_unspecified_parameters
:
19159 /* From varargs functions; gdb doesn't seem to have any
19160 interest in this information, so just ignore it for now.
19163 case DW_TAG_template_type_param
:
19165 /* Fall through. */
19166 case DW_TAG_class_type
:
19167 case DW_TAG_interface_type
:
19168 case DW_TAG_structure_type
:
19169 case DW_TAG_union_type
:
19170 case DW_TAG_set_type
:
19171 case DW_TAG_enumeration_type
:
19172 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19173 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
19176 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
19177 really ever be static objects: otherwise, if you try
19178 to, say, break of a class's method and you're in a file
19179 which doesn't mention that class, it won't work unless
19180 the check for all static symbols in lookup_symbol_aux
19181 saves you. See the OtherFileClass tests in
19182 gdb.c++/namespace.exp. */
19186 list_to_add
= (cu
->list_in_scope
== &file_symbols
19187 && cu
->language
== language_cplus
19188 ? &global_symbols
: cu
->list_in_scope
);
19190 /* The semantics of C++ state that "struct foo {
19191 ... }" also defines a typedef for "foo". */
19192 if (cu
->language
== language_cplus
19193 || cu
->language
== language_ada
19194 || cu
->language
== language_d
19195 || cu
->language
== language_rust
)
19197 /* The symbol's name is already allocated along
19198 with this objfile, so we don't need to
19199 duplicate it for the type. */
19200 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
19201 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
19206 case DW_TAG_typedef
:
19207 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19208 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19209 list_to_add
= cu
->list_in_scope
;
19211 case DW_TAG_base_type
:
19212 case DW_TAG_subrange_type
:
19213 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19214 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19215 list_to_add
= cu
->list_in_scope
;
19217 case DW_TAG_enumerator
:
19218 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19221 dwarf2_const_value (attr
, sym
, cu
);
19224 /* NOTE: carlton/2003-11-10: See comment above in the
19225 DW_TAG_class_type, etc. block. */
19227 list_to_add
= (cu
->list_in_scope
== &file_symbols
19228 && cu
->language
== language_cplus
19229 ? &global_symbols
: cu
->list_in_scope
);
19232 case DW_TAG_imported_declaration
:
19233 case DW_TAG_namespace
:
19234 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19235 list_to_add
= &global_symbols
;
19237 case DW_TAG_module
:
19238 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19239 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
19240 list_to_add
= &global_symbols
;
19242 case DW_TAG_common_block
:
19243 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
19244 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
19245 add_symbol_to_list (sym
, cu
->list_in_scope
);
19248 /* Not a tag we recognize. Hopefully we aren't processing
19249 trash data, but since we must specifically ignore things
19250 we don't recognize, there is nothing else we should do at
19252 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
19253 dwarf_tag_name (die
->tag
));
19259 sym
->hash_next
= objfile
->template_symbols
;
19260 objfile
->template_symbols
= sym
;
19261 list_to_add
= NULL
;
19264 if (list_to_add
!= NULL
)
19265 add_symbol_to_list (sym
, list_to_add
);
19267 /* For the benefit of old versions of GCC, check for anonymous
19268 namespaces based on the demangled name. */
19269 if (!cu
->processing_has_namespace_info
19270 && cu
->language
== language_cplus
)
19271 cp_scan_for_anonymous_namespaces (sym
, objfile
);
19276 /* A wrapper for new_symbol_full that always allocates a new symbol. */
19278 static struct symbol
*
19279 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
19281 return new_symbol_full (die
, type
, cu
, NULL
);
19284 /* Given an attr with a DW_FORM_dataN value in host byte order,
19285 zero-extend it as appropriate for the symbol's type. The DWARF
19286 standard (v4) is not entirely clear about the meaning of using
19287 DW_FORM_dataN for a constant with a signed type, where the type is
19288 wider than the data. The conclusion of a discussion on the DWARF
19289 list was that this is unspecified. We choose to always zero-extend
19290 because that is the interpretation long in use by GCC. */
19293 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
19294 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
19296 struct objfile
*objfile
= cu
->objfile
;
19297 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
19298 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
19299 LONGEST l
= DW_UNSND (attr
);
19301 if (bits
< sizeof (*value
) * 8)
19303 l
&= ((LONGEST
) 1 << bits
) - 1;
19306 else if (bits
== sizeof (*value
) * 8)
19310 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
19311 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
19318 /* Read a constant value from an attribute. Either set *VALUE, or if
19319 the value does not fit in *VALUE, set *BYTES - either already
19320 allocated on the objfile obstack, or newly allocated on OBSTACK,
19321 or, set *BATON, if we translated the constant to a location
19325 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
19326 const char *name
, struct obstack
*obstack
,
19327 struct dwarf2_cu
*cu
,
19328 LONGEST
*value
, const gdb_byte
**bytes
,
19329 struct dwarf2_locexpr_baton
**baton
)
19331 struct objfile
*objfile
= cu
->objfile
;
19332 struct comp_unit_head
*cu_header
= &cu
->header
;
19333 struct dwarf_block
*blk
;
19334 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
19335 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
19341 switch (attr
->form
)
19344 case DW_FORM_GNU_addr_index
:
19348 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
19349 dwarf2_const_value_length_mismatch_complaint (name
,
19350 cu_header
->addr_size
,
19351 TYPE_LENGTH (type
));
19352 /* Symbols of this form are reasonably rare, so we just
19353 piggyback on the existing location code rather than writing
19354 a new implementation of symbol_computed_ops. */
19355 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
19356 (*baton
)->per_cu
= cu
->per_cu
;
19357 gdb_assert ((*baton
)->per_cu
);
19359 (*baton
)->size
= 2 + cu_header
->addr_size
;
19360 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
19361 (*baton
)->data
= data
;
19363 data
[0] = DW_OP_addr
;
19364 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
19365 byte_order
, DW_ADDR (attr
));
19366 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
19369 case DW_FORM_string
:
19371 case DW_FORM_GNU_str_index
:
19372 case DW_FORM_GNU_strp_alt
:
19373 /* DW_STRING is already allocated on the objfile obstack, point
19375 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
19377 case DW_FORM_block1
:
19378 case DW_FORM_block2
:
19379 case DW_FORM_block4
:
19380 case DW_FORM_block
:
19381 case DW_FORM_exprloc
:
19382 case DW_FORM_data16
:
19383 blk
= DW_BLOCK (attr
);
19384 if (TYPE_LENGTH (type
) != blk
->size
)
19385 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
19386 TYPE_LENGTH (type
));
19387 *bytes
= blk
->data
;
19390 /* The DW_AT_const_value attributes are supposed to carry the
19391 symbol's value "represented as it would be on the target
19392 architecture." By the time we get here, it's already been
19393 converted to host endianness, so we just need to sign- or
19394 zero-extend it as appropriate. */
19395 case DW_FORM_data1
:
19396 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
19398 case DW_FORM_data2
:
19399 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
19401 case DW_FORM_data4
:
19402 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
19404 case DW_FORM_data8
:
19405 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
19408 case DW_FORM_sdata
:
19409 *value
= DW_SND (attr
);
19412 case DW_FORM_udata
:
19413 *value
= DW_UNSND (attr
);
19417 complaint (&symfile_complaints
,
19418 _("unsupported const value attribute form: '%s'"),
19419 dwarf_form_name (attr
->form
));
19426 /* Copy constant value from an attribute to a symbol. */
19429 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
19430 struct dwarf2_cu
*cu
)
19432 struct objfile
*objfile
= cu
->objfile
;
19434 const gdb_byte
*bytes
;
19435 struct dwarf2_locexpr_baton
*baton
;
19437 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
19438 SYMBOL_PRINT_NAME (sym
),
19439 &objfile
->objfile_obstack
, cu
,
19440 &value
, &bytes
, &baton
);
19444 SYMBOL_LOCATION_BATON (sym
) = baton
;
19445 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
19447 else if (bytes
!= NULL
)
19449 SYMBOL_VALUE_BYTES (sym
) = bytes
;
19450 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
19454 SYMBOL_VALUE (sym
) = value
;
19455 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
19459 /* Return the type of the die in question using its DW_AT_type attribute. */
19461 static struct type
*
19462 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19464 struct attribute
*type_attr
;
19466 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
19469 /* A missing DW_AT_type represents a void type. */
19470 return objfile_type (cu
->objfile
)->builtin_void
;
19473 return lookup_die_type (die
, type_attr
, cu
);
19476 /* True iff CU's producer generates GNAT Ada auxiliary information
19477 that allows to find parallel types through that information instead
19478 of having to do expensive parallel lookups by type name. */
19481 need_gnat_info (struct dwarf2_cu
*cu
)
19483 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
19484 of GNAT produces this auxiliary information, without any indication
19485 that it is produced. Part of enhancing the FSF version of GNAT
19486 to produce that information will be to put in place an indicator
19487 that we can use in order to determine whether the descriptive type
19488 info is available or not. One suggestion that has been made is
19489 to use a new attribute, attached to the CU die. For now, assume
19490 that the descriptive type info is not available. */
19494 /* Return the auxiliary type of the die in question using its
19495 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
19496 attribute is not present. */
19498 static struct type
*
19499 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19501 struct attribute
*type_attr
;
19503 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
19507 return lookup_die_type (die
, type_attr
, cu
);
19510 /* If DIE has a descriptive_type attribute, then set the TYPE's
19511 descriptive type accordingly. */
19514 set_descriptive_type (struct type
*type
, struct die_info
*die
,
19515 struct dwarf2_cu
*cu
)
19517 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
19519 if (descriptive_type
)
19521 ALLOCATE_GNAT_AUX_TYPE (type
);
19522 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
19526 /* Return the containing type of the die in question using its
19527 DW_AT_containing_type attribute. */
19529 static struct type
*
19530 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19532 struct attribute
*type_attr
;
19534 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
19536 error (_("Dwarf Error: Problem turning containing type into gdb type "
19537 "[in module %s]"), objfile_name (cu
->objfile
));
19539 return lookup_die_type (die
, type_attr
, cu
);
19542 /* Return an error marker type to use for the ill formed type in DIE/CU. */
19544 static struct type
*
19545 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
19547 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19548 char *message
, *saved
;
19550 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
19551 objfile_name (objfile
),
19552 to_underlying (cu
->header
.sect_off
),
19553 to_underlying (die
->sect_off
));
19554 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
19555 message
, strlen (message
));
19558 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
19561 /* Look up the type of DIE in CU using its type attribute ATTR.
19562 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
19563 DW_AT_containing_type.
19564 If there is no type substitute an error marker. */
19566 static struct type
*
19567 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
19568 struct dwarf2_cu
*cu
)
19570 struct objfile
*objfile
= cu
->objfile
;
19571 struct type
*this_type
;
19573 gdb_assert (attr
->name
== DW_AT_type
19574 || attr
->name
== DW_AT_GNAT_descriptive_type
19575 || attr
->name
== DW_AT_containing_type
);
19577 /* First see if we have it cached. */
19579 if (attr
->form
== DW_FORM_GNU_ref_alt
)
19581 struct dwarf2_per_cu_data
*per_cu
;
19582 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
19584 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, cu
->objfile
);
19585 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
19587 else if (attr_form_is_ref (attr
))
19589 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
19591 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
19593 else if (attr
->form
== DW_FORM_ref_sig8
)
19595 ULONGEST signature
= DW_SIGNATURE (attr
);
19597 return get_signatured_type (die
, signature
, cu
);
19601 complaint (&symfile_complaints
,
19602 _("Dwarf Error: Bad type attribute %s in DIE"
19603 " at 0x%x [in module %s]"),
19604 dwarf_attr_name (attr
->name
), to_underlying (die
->sect_off
),
19605 objfile_name (objfile
));
19606 return build_error_marker_type (cu
, die
);
19609 /* If not cached we need to read it in. */
19611 if (this_type
== NULL
)
19613 struct die_info
*type_die
= NULL
;
19614 struct dwarf2_cu
*type_cu
= cu
;
19616 if (attr_form_is_ref (attr
))
19617 type_die
= follow_die_ref (die
, attr
, &type_cu
);
19618 if (type_die
== NULL
)
19619 return build_error_marker_type (cu
, die
);
19620 /* If we find the type now, it's probably because the type came
19621 from an inter-CU reference and the type's CU got expanded before
19623 this_type
= read_type_die (type_die
, type_cu
);
19626 /* If we still don't have a type use an error marker. */
19628 if (this_type
== NULL
)
19629 return build_error_marker_type (cu
, die
);
19634 /* Return the type in DIE, CU.
19635 Returns NULL for invalid types.
19637 This first does a lookup in die_type_hash,
19638 and only reads the die in if necessary.
19640 NOTE: This can be called when reading in partial or full symbols. */
19642 static struct type
*
19643 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
19645 struct type
*this_type
;
19647 this_type
= get_die_type (die
, cu
);
19651 return read_type_die_1 (die
, cu
);
19654 /* Read the type in DIE, CU.
19655 Returns NULL for invalid types. */
19657 static struct type
*
19658 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
19660 struct type
*this_type
= NULL
;
19664 case DW_TAG_class_type
:
19665 case DW_TAG_interface_type
:
19666 case DW_TAG_structure_type
:
19667 case DW_TAG_union_type
:
19668 this_type
= read_structure_type (die
, cu
);
19670 case DW_TAG_enumeration_type
:
19671 this_type
= read_enumeration_type (die
, cu
);
19673 case DW_TAG_subprogram
:
19674 case DW_TAG_subroutine_type
:
19675 case DW_TAG_inlined_subroutine
:
19676 this_type
= read_subroutine_type (die
, cu
);
19678 case DW_TAG_array_type
:
19679 this_type
= read_array_type (die
, cu
);
19681 case DW_TAG_set_type
:
19682 this_type
= read_set_type (die
, cu
);
19684 case DW_TAG_pointer_type
:
19685 this_type
= read_tag_pointer_type (die
, cu
);
19687 case DW_TAG_ptr_to_member_type
:
19688 this_type
= read_tag_ptr_to_member_type (die
, cu
);
19690 case DW_TAG_reference_type
:
19691 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
19693 case DW_TAG_rvalue_reference_type
:
19694 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
19696 case DW_TAG_const_type
:
19697 this_type
= read_tag_const_type (die
, cu
);
19699 case DW_TAG_volatile_type
:
19700 this_type
= read_tag_volatile_type (die
, cu
);
19702 case DW_TAG_restrict_type
:
19703 this_type
= read_tag_restrict_type (die
, cu
);
19705 case DW_TAG_string_type
:
19706 this_type
= read_tag_string_type (die
, cu
);
19708 case DW_TAG_typedef
:
19709 this_type
= read_typedef (die
, cu
);
19711 case DW_TAG_subrange_type
:
19712 this_type
= read_subrange_type (die
, cu
);
19714 case DW_TAG_base_type
:
19715 this_type
= read_base_type (die
, cu
);
19717 case DW_TAG_unspecified_type
:
19718 this_type
= read_unspecified_type (die
, cu
);
19720 case DW_TAG_namespace
:
19721 this_type
= read_namespace_type (die
, cu
);
19723 case DW_TAG_module
:
19724 this_type
= read_module_type (die
, cu
);
19726 case DW_TAG_atomic_type
:
19727 this_type
= read_tag_atomic_type (die
, cu
);
19730 complaint (&symfile_complaints
,
19731 _("unexpected tag in read_type_die: '%s'"),
19732 dwarf_tag_name (die
->tag
));
19739 /* See if we can figure out if the class lives in a namespace. We do
19740 this by looking for a member function; its demangled name will
19741 contain namespace info, if there is any.
19742 Return the computed name or NULL.
19743 Space for the result is allocated on the objfile's obstack.
19744 This is the full-die version of guess_partial_die_structure_name.
19745 In this case we know DIE has no useful parent. */
19748 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19750 struct die_info
*spec_die
;
19751 struct dwarf2_cu
*spec_cu
;
19752 struct die_info
*child
;
19755 spec_die
= die_specification (die
, &spec_cu
);
19756 if (spec_die
!= NULL
)
19762 for (child
= die
->child
;
19764 child
= child
->sibling
)
19766 if (child
->tag
== DW_TAG_subprogram
)
19768 const char *linkage_name
;
19770 linkage_name
= dwarf2_string_attr (child
, DW_AT_linkage_name
, cu
);
19771 if (linkage_name
== NULL
)
19772 linkage_name
= dwarf2_string_attr (child
, DW_AT_MIPS_linkage_name
,
19774 if (linkage_name
!= NULL
)
19777 = language_class_name_from_physname (cu
->language_defn
,
19781 if (actual_name
!= NULL
)
19783 const char *die_name
= dwarf2_name (die
, cu
);
19785 if (die_name
!= NULL
19786 && strcmp (die_name
, actual_name
) != 0)
19788 /* Strip off the class name from the full name.
19789 We want the prefix. */
19790 int die_name_len
= strlen (die_name
);
19791 int actual_name_len
= strlen (actual_name
);
19793 /* Test for '::' as a sanity check. */
19794 if (actual_name_len
> die_name_len
+ 2
19795 && actual_name
[actual_name_len
19796 - die_name_len
- 1] == ':')
19797 name
= (char *) obstack_copy0 (
19798 &cu
->objfile
->per_bfd
->storage_obstack
,
19799 actual_name
, actual_name_len
- die_name_len
- 2);
19802 xfree (actual_name
);
19811 /* GCC might emit a nameless typedef that has a linkage name. Determine the
19812 prefix part in such case. See
19813 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19815 static const char *
19816 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19818 struct attribute
*attr
;
19821 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
19822 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
19825 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
19828 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
19830 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
19831 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
19834 /* dwarf2_name had to be already called. */
19835 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
19837 /* Strip the base name, keep any leading namespaces/classes. */
19838 base
= strrchr (DW_STRING (attr
), ':');
19839 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
19842 return (char *) obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
19844 &base
[-1] - DW_STRING (attr
));
19847 /* Return the name of the namespace/class that DIE is defined within,
19848 or "" if we can't tell. The caller should not xfree the result.
19850 For example, if we're within the method foo() in the following
19860 then determine_prefix on foo's die will return "N::C". */
19862 static const char *
19863 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19865 struct die_info
*parent
, *spec_die
;
19866 struct dwarf2_cu
*spec_cu
;
19867 struct type
*parent_type
;
19868 const char *retval
;
19870 if (cu
->language
!= language_cplus
19871 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
19872 && cu
->language
!= language_rust
)
19875 retval
= anonymous_struct_prefix (die
, cu
);
19879 /* We have to be careful in the presence of DW_AT_specification.
19880 For example, with GCC 3.4, given the code
19884 // Definition of N::foo.
19888 then we'll have a tree of DIEs like this:
19890 1: DW_TAG_compile_unit
19891 2: DW_TAG_namespace // N
19892 3: DW_TAG_subprogram // declaration of N::foo
19893 4: DW_TAG_subprogram // definition of N::foo
19894 DW_AT_specification // refers to die #3
19896 Thus, when processing die #4, we have to pretend that we're in
19897 the context of its DW_AT_specification, namely the contex of die
19900 spec_die
= die_specification (die
, &spec_cu
);
19901 if (spec_die
== NULL
)
19902 parent
= die
->parent
;
19905 parent
= spec_die
->parent
;
19909 if (parent
== NULL
)
19911 else if (parent
->building_fullname
)
19914 const char *parent_name
;
19916 /* It has been seen on RealView 2.2 built binaries,
19917 DW_TAG_template_type_param types actually _defined_ as
19918 children of the parent class:
19921 template class <class Enum> Class{};
19922 Class<enum E> class_e;
19924 1: DW_TAG_class_type (Class)
19925 2: DW_TAG_enumeration_type (E)
19926 3: DW_TAG_enumerator (enum1:0)
19927 3: DW_TAG_enumerator (enum2:1)
19929 2: DW_TAG_template_type_param
19930 DW_AT_type DW_FORM_ref_udata (E)
19932 Besides being broken debug info, it can put GDB into an
19933 infinite loop. Consider:
19935 When we're building the full name for Class<E>, we'll start
19936 at Class, and go look over its template type parameters,
19937 finding E. We'll then try to build the full name of E, and
19938 reach here. We're now trying to build the full name of E,
19939 and look over the parent DIE for containing scope. In the
19940 broken case, if we followed the parent DIE of E, we'd again
19941 find Class, and once again go look at its template type
19942 arguments, etc., etc. Simply don't consider such parent die
19943 as source-level parent of this die (it can't be, the language
19944 doesn't allow it), and break the loop here. */
19945 name
= dwarf2_name (die
, cu
);
19946 parent_name
= dwarf2_name (parent
, cu
);
19947 complaint (&symfile_complaints
,
19948 _("template param type '%s' defined within parent '%s'"),
19949 name
? name
: "<unknown>",
19950 parent_name
? parent_name
: "<unknown>");
19954 switch (parent
->tag
)
19956 case DW_TAG_namespace
:
19957 parent_type
= read_type_die (parent
, cu
);
19958 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
19959 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
19960 Work around this problem here. */
19961 if (cu
->language
== language_cplus
19962 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
19964 /* We give a name to even anonymous namespaces. */
19965 return TYPE_TAG_NAME (parent_type
);
19966 case DW_TAG_class_type
:
19967 case DW_TAG_interface_type
:
19968 case DW_TAG_structure_type
:
19969 case DW_TAG_union_type
:
19970 case DW_TAG_module
:
19971 parent_type
= read_type_die (parent
, cu
);
19972 if (TYPE_TAG_NAME (parent_type
) != NULL
)
19973 return TYPE_TAG_NAME (parent_type
);
19975 /* An anonymous structure is only allowed non-static data
19976 members; no typedefs, no member functions, et cetera.
19977 So it does not need a prefix. */
19979 case DW_TAG_compile_unit
:
19980 case DW_TAG_partial_unit
:
19981 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
19982 if (cu
->language
== language_cplus
19983 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
19984 && die
->child
!= NULL
19985 && (die
->tag
== DW_TAG_class_type
19986 || die
->tag
== DW_TAG_structure_type
19987 || die
->tag
== DW_TAG_union_type
))
19989 char *name
= guess_full_die_structure_name (die
, cu
);
19994 case DW_TAG_enumeration_type
:
19995 parent_type
= read_type_die (parent
, cu
);
19996 if (TYPE_DECLARED_CLASS (parent_type
))
19998 if (TYPE_TAG_NAME (parent_type
) != NULL
)
19999 return TYPE_TAG_NAME (parent_type
);
20002 /* Fall through. */
20004 return determine_prefix (parent
, cu
);
20008 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
20009 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
20010 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
20011 an obconcat, otherwise allocate storage for the result. The CU argument is
20012 used to determine the language and hence, the appropriate separator. */
20014 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
20017 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
20018 int physname
, struct dwarf2_cu
*cu
)
20020 const char *lead
= "";
20023 if (suffix
== NULL
|| suffix
[0] == '\0'
20024 || prefix
== NULL
|| prefix
[0] == '\0')
20026 else if (cu
->language
== language_d
)
20028 /* For D, the 'main' function could be defined in any module, but it
20029 should never be prefixed. */
20030 if (strcmp (suffix
, "D main") == 0)
20038 else if (cu
->language
== language_fortran
&& physname
)
20040 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
20041 DW_AT_MIPS_linkage_name is preferred and used instead. */
20049 if (prefix
== NULL
)
20051 if (suffix
== NULL
)
20058 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
20060 strcpy (retval
, lead
);
20061 strcat (retval
, prefix
);
20062 strcat (retval
, sep
);
20063 strcat (retval
, suffix
);
20068 /* We have an obstack. */
20069 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
20073 /* Return sibling of die, NULL if no sibling. */
20075 static struct die_info
*
20076 sibling_die (struct die_info
*die
)
20078 return die
->sibling
;
20081 /* Get name of a die, return NULL if not found. */
20083 static const char *
20084 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
20085 struct obstack
*obstack
)
20087 if (name
&& cu
->language
== language_cplus
)
20089 std::string canon_name
= cp_canonicalize_string (name
);
20091 if (!canon_name
.empty ())
20093 if (canon_name
!= name
)
20094 name
= (const char *) obstack_copy0 (obstack
,
20095 canon_name
.c_str (),
20096 canon_name
.length ());
20103 /* Get name of a die, return NULL if not found.
20104 Anonymous namespaces are converted to their magic string. */
20106 static const char *
20107 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20109 struct attribute
*attr
;
20111 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
20112 if ((!attr
|| !DW_STRING (attr
))
20113 && die
->tag
!= DW_TAG_namespace
20114 && die
->tag
!= DW_TAG_class_type
20115 && die
->tag
!= DW_TAG_interface_type
20116 && die
->tag
!= DW_TAG_structure_type
20117 && die
->tag
!= DW_TAG_union_type
)
20122 case DW_TAG_compile_unit
:
20123 case DW_TAG_partial_unit
:
20124 /* Compilation units have a DW_AT_name that is a filename, not
20125 a source language identifier. */
20126 case DW_TAG_enumeration_type
:
20127 case DW_TAG_enumerator
:
20128 /* These tags always have simple identifiers already; no need
20129 to canonicalize them. */
20130 return DW_STRING (attr
);
20132 case DW_TAG_namespace
:
20133 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
20134 return DW_STRING (attr
);
20135 return CP_ANONYMOUS_NAMESPACE_STR
;
20137 case DW_TAG_class_type
:
20138 case DW_TAG_interface_type
:
20139 case DW_TAG_structure_type
:
20140 case DW_TAG_union_type
:
20141 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
20142 structures or unions. These were of the form "._%d" in GCC 4.1,
20143 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
20144 and GCC 4.4. We work around this problem by ignoring these. */
20145 if (attr
&& DW_STRING (attr
)
20146 && (startswith (DW_STRING (attr
), "._")
20147 || startswith (DW_STRING (attr
), "<anonymous")))
20150 /* GCC might emit a nameless typedef that has a linkage name. See
20151 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20152 if (!attr
|| DW_STRING (attr
) == NULL
)
20154 char *demangled
= NULL
;
20156 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
20158 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
20160 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
20163 /* Avoid demangling DW_STRING (attr) the second time on a second
20164 call for the same DIE. */
20165 if (!DW_STRING_IS_CANONICAL (attr
))
20166 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
20172 /* FIXME: we already did this for the partial symbol... */
20175 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
20176 demangled
, strlen (demangled
)));
20177 DW_STRING_IS_CANONICAL (attr
) = 1;
20180 /* Strip any leading namespaces/classes, keep only the base name.
20181 DW_AT_name for named DIEs does not contain the prefixes. */
20182 base
= strrchr (DW_STRING (attr
), ':');
20183 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
20186 return DW_STRING (attr
);
20195 if (!DW_STRING_IS_CANONICAL (attr
))
20198 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
20199 &cu
->objfile
->per_bfd
->storage_obstack
);
20200 DW_STRING_IS_CANONICAL (attr
) = 1;
20202 return DW_STRING (attr
);
20205 /* Return the die that this die in an extension of, or NULL if there
20206 is none. *EXT_CU is the CU containing DIE on input, and the CU
20207 containing the return value on output. */
20209 static struct die_info
*
20210 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
20212 struct attribute
*attr
;
20214 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
20218 return follow_die_ref (die
, attr
, ext_cu
);
20221 /* Convert a DIE tag into its string name. */
20223 static const char *
20224 dwarf_tag_name (unsigned tag
)
20226 const char *name
= get_DW_TAG_name (tag
);
20229 return "DW_TAG_<unknown>";
20234 /* Convert a DWARF attribute code into its string name. */
20236 static const char *
20237 dwarf_attr_name (unsigned attr
)
20241 #ifdef MIPS /* collides with DW_AT_HP_block_index */
20242 if (attr
== DW_AT_MIPS_fde
)
20243 return "DW_AT_MIPS_fde";
20245 if (attr
== DW_AT_HP_block_index
)
20246 return "DW_AT_HP_block_index";
20249 name
= get_DW_AT_name (attr
);
20252 return "DW_AT_<unknown>";
20257 /* Convert a DWARF value form code into its string name. */
20259 static const char *
20260 dwarf_form_name (unsigned form
)
20262 const char *name
= get_DW_FORM_name (form
);
20265 return "DW_FORM_<unknown>";
20270 static const char *
20271 dwarf_bool_name (unsigned mybool
)
20279 /* Convert a DWARF type code into its string name. */
20281 static const char *
20282 dwarf_type_encoding_name (unsigned enc
)
20284 const char *name
= get_DW_ATE_name (enc
);
20287 return "DW_ATE_<unknown>";
20293 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
20297 print_spaces (indent
, f
);
20298 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
20299 dwarf_tag_name (die
->tag
), die
->abbrev
,
20300 to_underlying (die
->sect_off
));
20302 if (die
->parent
!= NULL
)
20304 print_spaces (indent
, f
);
20305 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
20306 to_underlying (die
->parent
->sect_off
));
20309 print_spaces (indent
, f
);
20310 fprintf_unfiltered (f
, " has children: %s\n",
20311 dwarf_bool_name (die
->child
!= NULL
));
20313 print_spaces (indent
, f
);
20314 fprintf_unfiltered (f
, " attributes:\n");
20316 for (i
= 0; i
< die
->num_attrs
; ++i
)
20318 print_spaces (indent
, f
);
20319 fprintf_unfiltered (f
, " %s (%s) ",
20320 dwarf_attr_name (die
->attrs
[i
].name
),
20321 dwarf_form_name (die
->attrs
[i
].form
));
20323 switch (die
->attrs
[i
].form
)
20326 case DW_FORM_GNU_addr_index
:
20327 fprintf_unfiltered (f
, "address: ");
20328 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
20330 case DW_FORM_block2
:
20331 case DW_FORM_block4
:
20332 case DW_FORM_block
:
20333 case DW_FORM_block1
:
20334 fprintf_unfiltered (f
, "block: size %s",
20335 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
20337 case DW_FORM_exprloc
:
20338 fprintf_unfiltered (f
, "expression: size %s",
20339 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
20341 case DW_FORM_data16
:
20342 fprintf_unfiltered (f
, "constant of 16 bytes");
20344 case DW_FORM_ref_addr
:
20345 fprintf_unfiltered (f
, "ref address: ");
20346 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
20348 case DW_FORM_GNU_ref_alt
:
20349 fprintf_unfiltered (f
, "alt ref address: ");
20350 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
20356 case DW_FORM_ref_udata
:
20357 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
20358 (long) (DW_UNSND (&die
->attrs
[i
])));
20360 case DW_FORM_data1
:
20361 case DW_FORM_data2
:
20362 case DW_FORM_data4
:
20363 case DW_FORM_data8
:
20364 case DW_FORM_udata
:
20365 case DW_FORM_sdata
:
20366 fprintf_unfiltered (f
, "constant: %s",
20367 pulongest (DW_UNSND (&die
->attrs
[i
])));
20369 case DW_FORM_sec_offset
:
20370 fprintf_unfiltered (f
, "section offset: %s",
20371 pulongest (DW_UNSND (&die
->attrs
[i
])));
20373 case DW_FORM_ref_sig8
:
20374 fprintf_unfiltered (f
, "signature: %s",
20375 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
20377 case DW_FORM_string
:
20379 case DW_FORM_line_strp
:
20380 case DW_FORM_GNU_str_index
:
20381 case DW_FORM_GNU_strp_alt
:
20382 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
20383 DW_STRING (&die
->attrs
[i
])
20384 ? DW_STRING (&die
->attrs
[i
]) : "",
20385 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
20388 if (DW_UNSND (&die
->attrs
[i
]))
20389 fprintf_unfiltered (f
, "flag: TRUE");
20391 fprintf_unfiltered (f
, "flag: FALSE");
20393 case DW_FORM_flag_present
:
20394 fprintf_unfiltered (f
, "flag: TRUE");
20396 case DW_FORM_indirect
:
20397 /* The reader will have reduced the indirect form to
20398 the "base form" so this form should not occur. */
20399 fprintf_unfiltered (f
,
20400 "unexpected attribute form: DW_FORM_indirect");
20403 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
20404 die
->attrs
[i
].form
);
20407 fprintf_unfiltered (f
, "\n");
20412 dump_die_for_error (struct die_info
*die
)
20414 dump_die_shallow (gdb_stderr
, 0, die
);
20418 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
20420 int indent
= level
* 4;
20422 gdb_assert (die
!= NULL
);
20424 if (level
>= max_level
)
20427 dump_die_shallow (f
, indent
, die
);
20429 if (die
->child
!= NULL
)
20431 print_spaces (indent
, f
);
20432 fprintf_unfiltered (f
, " Children:");
20433 if (level
+ 1 < max_level
)
20435 fprintf_unfiltered (f
, "\n");
20436 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
20440 fprintf_unfiltered (f
,
20441 " [not printed, max nesting level reached]\n");
20445 if (die
->sibling
!= NULL
&& level
> 0)
20447 dump_die_1 (f
, level
, max_level
, die
->sibling
);
20451 /* This is called from the pdie macro in gdbinit.in.
20452 It's not static so gcc will keep a copy callable from gdb. */
20455 dump_die (struct die_info
*die
, int max_level
)
20457 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
20461 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
20465 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
20466 to_underlying (die
->sect_off
),
20472 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
20476 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
20478 if (attr_form_is_ref (attr
))
20479 return (sect_offset
) DW_UNSND (attr
);
20481 complaint (&symfile_complaints
,
20482 _("unsupported die ref attribute form: '%s'"),
20483 dwarf_form_name (attr
->form
));
20487 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
20488 * the value held by the attribute is not constant. */
20491 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
20493 if (attr
->form
== DW_FORM_sdata
)
20494 return DW_SND (attr
);
20495 else if (attr
->form
== DW_FORM_udata
20496 || attr
->form
== DW_FORM_data1
20497 || attr
->form
== DW_FORM_data2
20498 || attr
->form
== DW_FORM_data4
20499 || attr
->form
== DW_FORM_data8
)
20500 return DW_UNSND (attr
);
20503 /* For DW_FORM_data16 see attr_form_is_constant. */
20504 complaint (&symfile_complaints
,
20505 _("Attribute value is not a constant (%s)"),
20506 dwarf_form_name (attr
->form
));
20507 return default_value
;
20511 /* Follow reference or signature attribute ATTR of SRC_DIE.
20512 On entry *REF_CU is the CU of SRC_DIE.
20513 On exit *REF_CU is the CU of the result. */
20515 static struct die_info
*
20516 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20517 struct dwarf2_cu
**ref_cu
)
20519 struct die_info
*die
;
20521 if (attr_form_is_ref (attr
))
20522 die
= follow_die_ref (src_die
, attr
, ref_cu
);
20523 else if (attr
->form
== DW_FORM_ref_sig8
)
20524 die
= follow_die_sig (src_die
, attr
, ref_cu
);
20527 dump_die_for_error (src_die
);
20528 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
20529 objfile_name ((*ref_cu
)->objfile
));
20535 /* Follow reference OFFSET.
20536 On entry *REF_CU is the CU of the source die referencing OFFSET.
20537 On exit *REF_CU is the CU of the result.
20538 Returns NULL if OFFSET is invalid. */
20540 static struct die_info
*
20541 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
20542 struct dwarf2_cu
**ref_cu
)
20544 struct die_info temp_die
;
20545 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
20547 gdb_assert (cu
->per_cu
!= NULL
);
20551 if (cu
->per_cu
->is_debug_types
)
20553 /* .debug_types CUs cannot reference anything outside their CU.
20554 If they need to, they have to reference a signatured type via
20555 DW_FORM_ref_sig8. */
20556 if (!offset_in_cu_p (&cu
->header
, sect_off
))
20559 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
20560 || !offset_in_cu_p (&cu
->header
, sect_off
))
20562 struct dwarf2_per_cu_data
*per_cu
;
20564 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
20567 /* If necessary, add it to the queue and load its DIEs. */
20568 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
20569 load_full_comp_unit (per_cu
, cu
->language
);
20571 target_cu
= per_cu
->cu
;
20573 else if (cu
->dies
== NULL
)
20575 /* We're loading full DIEs during partial symbol reading. */
20576 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
20577 load_full_comp_unit (cu
->per_cu
, language_minimal
);
20580 *ref_cu
= target_cu
;
20581 temp_die
.sect_off
= sect_off
;
20582 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
20584 to_underlying (sect_off
));
20587 /* Follow reference attribute ATTR of SRC_DIE.
20588 On entry *REF_CU is the CU of SRC_DIE.
20589 On exit *REF_CU is the CU of the result. */
20591 static struct die_info
*
20592 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
20593 struct dwarf2_cu
**ref_cu
)
20595 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
20596 struct dwarf2_cu
*cu
= *ref_cu
;
20597 struct die_info
*die
;
20599 die
= follow_die_offset (sect_off
,
20600 (attr
->form
== DW_FORM_GNU_ref_alt
20601 || cu
->per_cu
->is_dwz
),
20604 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
20605 "at 0x%x [in module %s]"),
20606 to_underlying (sect_off
), to_underlying (src_die
->sect_off
),
20607 objfile_name (cu
->objfile
));
20612 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
20613 Returned value is intended for DW_OP_call*. Returned
20614 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
20616 struct dwarf2_locexpr_baton
20617 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
20618 struct dwarf2_per_cu_data
*per_cu
,
20619 CORE_ADDR (*get_frame_pc
) (void *baton
),
20622 struct dwarf2_cu
*cu
;
20623 struct die_info
*die
;
20624 struct attribute
*attr
;
20625 struct dwarf2_locexpr_baton retval
;
20627 dw2_setup (per_cu
->objfile
);
20629 if (per_cu
->cu
== NULL
)
20634 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20635 Instead just throw an error, not much else we can do. */
20636 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
20637 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
20640 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
20642 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
20643 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
20645 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20648 /* DWARF: "If there is no such attribute, then there is no effect.".
20649 DATA is ignored if SIZE is 0. */
20651 retval
.data
= NULL
;
20654 else if (attr_form_is_section_offset (attr
))
20656 struct dwarf2_loclist_baton loclist_baton
;
20657 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
20660 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
20662 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
20664 retval
.size
= size
;
20668 if (!attr_form_is_block (attr
))
20669 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
20670 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
20671 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
20673 retval
.data
= DW_BLOCK (attr
)->data
;
20674 retval
.size
= DW_BLOCK (attr
)->size
;
20676 retval
.per_cu
= cu
->per_cu
;
20678 age_cached_comp_units ();
20683 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
20686 struct dwarf2_locexpr_baton
20687 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
20688 struct dwarf2_per_cu_data
*per_cu
,
20689 CORE_ADDR (*get_frame_pc
) (void *baton
),
20692 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
20694 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
20697 /* Write a constant of a given type as target-ordered bytes into
20700 static const gdb_byte
*
20701 write_constant_as_bytes (struct obstack
*obstack
,
20702 enum bfd_endian byte_order
,
20709 *len
= TYPE_LENGTH (type
);
20710 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20711 store_unsigned_integer (result
, *len
, byte_order
, value
);
20716 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
20717 pointer to the constant bytes and set LEN to the length of the
20718 data. If memory is needed, allocate it on OBSTACK. If the DIE
20719 does not have a DW_AT_const_value, return NULL. */
20722 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
20723 struct dwarf2_per_cu_data
*per_cu
,
20724 struct obstack
*obstack
,
20727 struct dwarf2_cu
*cu
;
20728 struct die_info
*die
;
20729 struct attribute
*attr
;
20730 const gdb_byte
*result
= NULL
;
20733 enum bfd_endian byte_order
;
20735 dw2_setup (per_cu
->objfile
);
20737 if (per_cu
->cu
== NULL
)
20742 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20743 Instead just throw an error, not much else we can do. */
20744 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
20745 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
20748 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
20750 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
20751 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
20754 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20758 byte_order
= (bfd_big_endian (per_cu
->objfile
->obfd
)
20759 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20761 switch (attr
->form
)
20764 case DW_FORM_GNU_addr_index
:
20768 *len
= cu
->header
.addr_size
;
20769 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20770 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
20774 case DW_FORM_string
:
20776 case DW_FORM_GNU_str_index
:
20777 case DW_FORM_GNU_strp_alt
:
20778 /* DW_STRING is already allocated on the objfile obstack, point
20780 result
= (const gdb_byte
*) DW_STRING (attr
);
20781 *len
= strlen (DW_STRING (attr
));
20783 case DW_FORM_block1
:
20784 case DW_FORM_block2
:
20785 case DW_FORM_block4
:
20786 case DW_FORM_block
:
20787 case DW_FORM_exprloc
:
20788 case DW_FORM_data16
:
20789 result
= DW_BLOCK (attr
)->data
;
20790 *len
= DW_BLOCK (attr
)->size
;
20793 /* The DW_AT_const_value attributes are supposed to carry the
20794 symbol's value "represented as it would be on the target
20795 architecture." By the time we get here, it's already been
20796 converted to host endianness, so we just need to sign- or
20797 zero-extend it as appropriate. */
20798 case DW_FORM_data1
:
20799 type
= die_type (die
, cu
);
20800 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
20801 if (result
== NULL
)
20802 result
= write_constant_as_bytes (obstack
, byte_order
,
20805 case DW_FORM_data2
:
20806 type
= die_type (die
, cu
);
20807 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
20808 if (result
== NULL
)
20809 result
= write_constant_as_bytes (obstack
, byte_order
,
20812 case DW_FORM_data4
:
20813 type
= die_type (die
, cu
);
20814 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
20815 if (result
== NULL
)
20816 result
= write_constant_as_bytes (obstack
, byte_order
,
20819 case DW_FORM_data8
:
20820 type
= die_type (die
, cu
);
20821 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
20822 if (result
== NULL
)
20823 result
= write_constant_as_bytes (obstack
, byte_order
,
20827 case DW_FORM_sdata
:
20828 type
= die_type (die
, cu
);
20829 result
= write_constant_as_bytes (obstack
, byte_order
,
20830 type
, DW_SND (attr
), len
);
20833 case DW_FORM_udata
:
20834 type
= die_type (die
, cu
);
20835 result
= write_constant_as_bytes (obstack
, byte_order
,
20836 type
, DW_UNSND (attr
), len
);
20840 complaint (&symfile_complaints
,
20841 _("unsupported const value attribute form: '%s'"),
20842 dwarf_form_name (attr
->form
));
20849 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
20850 valid type for this die is found. */
20853 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
20854 struct dwarf2_per_cu_data
*per_cu
)
20856 struct dwarf2_cu
*cu
;
20857 struct die_info
*die
;
20859 dw2_setup (per_cu
->objfile
);
20861 if (per_cu
->cu
== NULL
)
20867 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
20871 return die_type (die
, cu
);
20874 /* Return the type of the DIE at DIE_OFFSET in the CU named by
20878 dwarf2_get_die_type (cu_offset die_offset
,
20879 struct dwarf2_per_cu_data
*per_cu
)
20881 dw2_setup (per_cu
->objfile
);
20883 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
20884 return get_die_type_at_offset (die_offset_sect
, per_cu
);
20887 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
20888 On entry *REF_CU is the CU of SRC_DIE.
20889 On exit *REF_CU is the CU of the result.
20890 Returns NULL if the referenced DIE isn't found. */
20892 static struct die_info
*
20893 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
20894 struct dwarf2_cu
**ref_cu
)
20896 struct die_info temp_die
;
20897 struct dwarf2_cu
*sig_cu
;
20898 struct die_info
*die
;
20900 /* While it might be nice to assert sig_type->type == NULL here,
20901 we can get here for DW_AT_imported_declaration where we need
20902 the DIE not the type. */
20904 /* If necessary, add it to the queue and load its DIEs. */
20906 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
20907 read_signatured_type (sig_type
);
20909 sig_cu
= sig_type
->per_cu
.cu
;
20910 gdb_assert (sig_cu
!= NULL
);
20911 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
20912 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
20913 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
20914 to_underlying (temp_die
.sect_off
));
20917 /* For .gdb_index version 7 keep track of included TUs.
20918 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
20919 if (dwarf2_per_objfile
->index_table
!= NULL
20920 && dwarf2_per_objfile
->index_table
->version
<= 7)
20922 VEC_safe_push (dwarf2_per_cu_ptr
,
20923 (*ref_cu
)->per_cu
->imported_symtabs
,
20934 /* Follow signatured type referenced by ATTR in SRC_DIE.
20935 On entry *REF_CU is the CU of SRC_DIE.
20936 On exit *REF_CU is the CU of the result.
20937 The result is the DIE of the type.
20938 If the referenced type cannot be found an error is thrown. */
20940 static struct die_info
*
20941 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20942 struct dwarf2_cu
**ref_cu
)
20944 ULONGEST signature
= DW_SIGNATURE (attr
);
20945 struct signatured_type
*sig_type
;
20946 struct die_info
*die
;
20948 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
20950 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
20951 /* sig_type will be NULL if the signatured type is missing from
20953 if (sig_type
== NULL
)
20955 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
20956 " from DIE at 0x%x [in module %s]"),
20957 hex_string (signature
), to_underlying (src_die
->sect_off
),
20958 objfile_name ((*ref_cu
)->objfile
));
20961 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
20964 dump_die_for_error (src_die
);
20965 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
20966 " from DIE at 0x%x [in module %s]"),
20967 hex_string (signature
), to_underlying (src_die
->sect_off
),
20968 objfile_name ((*ref_cu
)->objfile
));
20974 /* Get the type specified by SIGNATURE referenced in DIE/CU,
20975 reading in and processing the type unit if necessary. */
20977 static struct type
*
20978 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
20979 struct dwarf2_cu
*cu
)
20981 struct signatured_type
*sig_type
;
20982 struct dwarf2_cu
*type_cu
;
20983 struct die_info
*type_die
;
20986 sig_type
= lookup_signatured_type (cu
, signature
);
20987 /* sig_type will be NULL if the signatured type is missing from
20989 if (sig_type
== NULL
)
20991 complaint (&symfile_complaints
,
20992 _("Dwarf Error: Cannot find signatured DIE %s referenced"
20993 " from DIE at 0x%x [in module %s]"),
20994 hex_string (signature
), to_underlying (die
->sect_off
),
20995 objfile_name (dwarf2_per_objfile
->objfile
));
20996 return build_error_marker_type (cu
, die
);
20999 /* If we already know the type we're done. */
21000 if (sig_type
->type
!= NULL
)
21001 return sig_type
->type
;
21004 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
21005 if (type_die
!= NULL
)
21007 /* N.B. We need to call get_die_type to ensure only one type for this DIE
21008 is created. This is important, for example, because for c++ classes
21009 we need TYPE_NAME set which is only done by new_symbol. Blech. */
21010 type
= read_type_die (type_die
, type_cu
);
21013 complaint (&symfile_complaints
,
21014 _("Dwarf Error: Cannot build signatured type %s"
21015 " referenced from DIE at 0x%x [in module %s]"),
21016 hex_string (signature
), to_underlying (die
->sect_off
),
21017 objfile_name (dwarf2_per_objfile
->objfile
));
21018 type
= build_error_marker_type (cu
, die
);
21023 complaint (&symfile_complaints
,
21024 _("Dwarf Error: Problem reading signatured DIE %s referenced"
21025 " from DIE at 0x%x [in module %s]"),
21026 hex_string (signature
), to_underlying (die
->sect_off
),
21027 objfile_name (dwarf2_per_objfile
->objfile
));
21028 type
= build_error_marker_type (cu
, die
);
21030 sig_type
->type
= type
;
21035 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
21036 reading in and processing the type unit if necessary. */
21038 static struct type
*
21039 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
21040 struct dwarf2_cu
*cu
) /* ARI: editCase function */
21042 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
21043 if (attr_form_is_ref (attr
))
21045 struct dwarf2_cu
*type_cu
= cu
;
21046 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
21048 return read_type_die (type_die
, type_cu
);
21050 else if (attr
->form
== DW_FORM_ref_sig8
)
21052 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
21056 complaint (&symfile_complaints
,
21057 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
21058 " at 0x%x [in module %s]"),
21059 dwarf_form_name (attr
->form
), to_underlying (die
->sect_off
),
21060 objfile_name (dwarf2_per_objfile
->objfile
));
21061 return build_error_marker_type (cu
, die
);
21065 /* Load the DIEs associated with type unit PER_CU into memory. */
21068 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
21070 struct signatured_type
*sig_type
;
21072 /* Caller is responsible for ensuring type_unit_groups don't get here. */
21073 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
21075 /* We have the per_cu, but we need the signatured_type.
21076 Fortunately this is an easy translation. */
21077 gdb_assert (per_cu
->is_debug_types
);
21078 sig_type
= (struct signatured_type
*) per_cu
;
21080 gdb_assert (per_cu
->cu
== NULL
);
21082 read_signatured_type (sig_type
);
21084 gdb_assert (per_cu
->cu
!= NULL
);
21087 /* die_reader_func for read_signatured_type.
21088 This is identical to load_full_comp_unit_reader,
21089 but is kept separate for now. */
21092 read_signatured_type_reader (const struct die_reader_specs
*reader
,
21093 const gdb_byte
*info_ptr
,
21094 struct die_info
*comp_unit_die
,
21098 struct dwarf2_cu
*cu
= reader
->cu
;
21100 gdb_assert (cu
->die_hash
== NULL
);
21102 htab_create_alloc_ex (cu
->header
.length
/ 12,
21106 &cu
->comp_unit_obstack
,
21107 hashtab_obstack_allocate
,
21108 dummy_obstack_deallocate
);
21111 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
21112 &info_ptr
, comp_unit_die
);
21113 cu
->dies
= comp_unit_die
;
21114 /* comp_unit_die is not stored in die_hash, no need. */
21116 /* We try not to read any attributes in this function, because not
21117 all CUs needed for references have been loaded yet, and symbol
21118 table processing isn't initialized. But we have to set the CU language,
21119 or we won't be able to build types correctly.
21120 Similarly, if we do not read the producer, we can not apply
21121 producer-specific interpretation. */
21122 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
21125 /* Read in a signatured type and build its CU and DIEs.
21126 If the type is a stub for the real type in a DWO file,
21127 read in the real type from the DWO file as well. */
21130 read_signatured_type (struct signatured_type
*sig_type
)
21132 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
21134 gdb_assert (per_cu
->is_debug_types
);
21135 gdb_assert (per_cu
->cu
== NULL
);
21137 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
21138 read_signatured_type_reader
, NULL
);
21139 sig_type
->per_cu
.tu_read
= 1;
21142 /* Decode simple location descriptions.
21143 Given a pointer to a dwarf block that defines a location, compute
21144 the location and return the value.
21146 NOTE drow/2003-11-18: This function is called in two situations
21147 now: for the address of static or global variables (partial symbols
21148 only) and for offsets into structures which are expected to be
21149 (more or less) constant. The partial symbol case should go away,
21150 and only the constant case should remain. That will let this
21151 function complain more accurately. A few special modes are allowed
21152 without complaint for global variables (for instance, global
21153 register values and thread-local values).
21155 A location description containing no operations indicates that the
21156 object is optimized out. The return value is 0 for that case.
21157 FIXME drow/2003-11-16: No callers check for this case any more; soon all
21158 callers will only want a very basic result and this can become a
21161 Note that stack[0] is unused except as a default error return. */
21164 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
21166 struct objfile
*objfile
= cu
->objfile
;
21168 size_t size
= blk
->size
;
21169 const gdb_byte
*data
= blk
->data
;
21170 CORE_ADDR stack
[64];
21172 unsigned int bytes_read
, unsnd
;
21178 stack
[++stacki
] = 0;
21217 stack
[++stacki
] = op
- DW_OP_lit0
;
21252 stack
[++stacki
] = op
- DW_OP_reg0
;
21254 dwarf2_complex_location_expr_complaint ();
21258 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
21260 stack
[++stacki
] = unsnd
;
21262 dwarf2_complex_location_expr_complaint ();
21266 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
21271 case DW_OP_const1u
:
21272 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
21276 case DW_OP_const1s
:
21277 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
21281 case DW_OP_const2u
:
21282 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
21286 case DW_OP_const2s
:
21287 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
21291 case DW_OP_const4u
:
21292 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
21296 case DW_OP_const4s
:
21297 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
21301 case DW_OP_const8u
:
21302 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
21307 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
21313 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
21318 stack
[stacki
+ 1] = stack
[stacki
];
21323 stack
[stacki
- 1] += stack
[stacki
];
21327 case DW_OP_plus_uconst
:
21328 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
21334 stack
[stacki
- 1] -= stack
[stacki
];
21339 /* If we're not the last op, then we definitely can't encode
21340 this using GDB's address_class enum. This is valid for partial
21341 global symbols, although the variable's address will be bogus
21344 dwarf2_complex_location_expr_complaint ();
21347 case DW_OP_GNU_push_tls_address
:
21348 case DW_OP_form_tls_address
:
21349 /* The top of the stack has the offset from the beginning
21350 of the thread control block at which the variable is located. */
21351 /* Nothing should follow this operator, so the top of stack would
21353 /* This is valid for partial global symbols, but the variable's
21354 address will be bogus in the psymtab. Make it always at least
21355 non-zero to not look as a variable garbage collected by linker
21356 which have DW_OP_addr 0. */
21358 dwarf2_complex_location_expr_complaint ();
21362 case DW_OP_GNU_uninit
:
21365 case DW_OP_GNU_addr_index
:
21366 case DW_OP_GNU_const_index
:
21367 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
21374 const char *name
= get_DW_OP_name (op
);
21377 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
21380 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
21384 return (stack
[stacki
]);
21387 /* Enforce maximum stack depth of SIZE-1 to avoid writing
21388 outside of the allocated space. Also enforce minimum>0. */
21389 if (stacki
>= ARRAY_SIZE (stack
) - 1)
21391 complaint (&symfile_complaints
,
21392 _("location description stack overflow"));
21398 complaint (&symfile_complaints
,
21399 _("location description stack underflow"));
21403 return (stack
[stacki
]);
21406 /* memory allocation interface */
21408 static struct dwarf_block
*
21409 dwarf_alloc_block (struct dwarf2_cu
*cu
)
21411 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
21414 static struct die_info
*
21415 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
21417 struct die_info
*die
;
21418 size_t size
= sizeof (struct die_info
);
21421 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
21423 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
21424 memset (die
, 0, sizeof (struct die_info
));
21429 /* Macro support. */
21431 /* Return file name relative to the compilation directory of file number I in
21432 *LH's file name table. The result is allocated using xmalloc; the caller is
21433 responsible for freeing it. */
21436 file_file_name (int file
, struct line_header
*lh
)
21438 /* Is the file number a valid index into the line header's file name
21439 table? Remember that file numbers start with one, not zero. */
21440 if (1 <= file
&& file
<= lh
->file_names
.size ())
21442 const file_entry
&fe
= lh
->file_names
[file
- 1];
21444 if (!IS_ABSOLUTE_PATH (fe
.name
))
21446 const char *dir
= fe
.include_dir (lh
);
21448 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
21450 return xstrdup (fe
.name
);
21454 /* The compiler produced a bogus file number. We can at least
21455 record the macro definitions made in the file, even if we
21456 won't be able to find the file by name. */
21457 char fake_name
[80];
21459 xsnprintf (fake_name
, sizeof (fake_name
),
21460 "<bad macro file number %d>", file
);
21462 complaint (&symfile_complaints
,
21463 _("bad file number in macro information (%d)"),
21466 return xstrdup (fake_name
);
21470 /* Return the full name of file number I in *LH's file name table.
21471 Use COMP_DIR as the name of the current directory of the
21472 compilation. The result is allocated using xmalloc; the caller is
21473 responsible for freeing it. */
21475 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
21477 /* Is the file number a valid index into the line header's file name
21478 table? Remember that file numbers start with one, not zero. */
21479 if (1 <= file
&& file
<= lh
->file_names
.size ())
21481 char *relative
= file_file_name (file
, lh
);
21483 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
21485 return reconcat (relative
, comp_dir
, SLASH_STRING
,
21486 relative
, (char *) NULL
);
21489 return file_file_name (file
, lh
);
21493 static struct macro_source_file
*
21494 macro_start_file (int file
, int line
,
21495 struct macro_source_file
*current_file
,
21496 struct line_header
*lh
)
21498 /* File name relative to the compilation directory of this source file. */
21499 char *file_name
= file_file_name (file
, lh
);
21501 if (! current_file
)
21503 /* Note: We don't create a macro table for this compilation unit
21504 at all until we actually get a filename. */
21505 struct macro_table
*macro_table
= get_macro_table ();
21507 /* If we have no current file, then this must be the start_file
21508 directive for the compilation unit's main source file. */
21509 current_file
= macro_set_main (macro_table
, file_name
);
21510 macro_define_special (macro_table
);
21513 current_file
= macro_include (current_file
, line
, file_name
);
21517 return current_file
;
21521 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
21522 followed by a null byte. */
21524 copy_string (const char *buf
, int len
)
21526 char *s
= (char *) xmalloc (len
+ 1);
21528 memcpy (s
, buf
, len
);
21534 static const char *
21535 consume_improper_spaces (const char *p
, const char *body
)
21539 complaint (&symfile_complaints
,
21540 _("macro definition contains spaces "
21541 "in formal argument list:\n`%s'"),
21553 parse_macro_definition (struct macro_source_file
*file
, int line
,
21558 /* The body string takes one of two forms. For object-like macro
21559 definitions, it should be:
21561 <macro name> " " <definition>
21563 For function-like macro definitions, it should be:
21565 <macro name> "() " <definition>
21567 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
21569 Spaces may appear only where explicitly indicated, and in the
21572 The Dwarf 2 spec says that an object-like macro's name is always
21573 followed by a space, but versions of GCC around March 2002 omit
21574 the space when the macro's definition is the empty string.
21576 The Dwarf 2 spec says that there should be no spaces between the
21577 formal arguments in a function-like macro's formal argument list,
21578 but versions of GCC around March 2002 include spaces after the
21582 /* Find the extent of the macro name. The macro name is terminated
21583 by either a space or null character (for an object-like macro) or
21584 an opening paren (for a function-like macro). */
21585 for (p
= body
; *p
; p
++)
21586 if (*p
== ' ' || *p
== '(')
21589 if (*p
== ' ' || *p
== '\0')
21591 /* It's an object-like macro. */
21592 int name_len
= p
- body
;
21593 char *name
= copy_string (body
, name_len
);
21594 const char *replacement
;
21597 replacement
= body
+ name_len
+ 1;
21600 dwarf2_macro_malformed_definition_complaint (body
);
21601 replacement
= body
+ name_len
;
21604 macro_define_object (file
, line
, name
, replacement
);
21608 else if (*p
== '(')
21610 /* It's a function-like macro. */
21611 char *name
= copy_string (body
, p
- body
);
21614 char **argv
= XNEWVEC (char *, argv_size
);
21618 p
= consume_improper_spaces (p
, body
);
21620 /* Parse the formal argument list. */
21621 while (*p
&& *p
!= ')')
21623 /* Find the extent of the current argument name. */
21624 const char *arg_start
= p
;
21626 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
21629 if (! *p
|| p
== arg_start
)
21630 dwarf2_macro_malformed_definition_complaint (body
);
21633 /* Make sure argv has room for the new argument. */
21634 if (argc
>= argv_size
)
21637 argv
= XRESIZEVEC (char *, argv
, argv_size
);
21640 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
21643 p
= consume_improper_spaces (p
, body
);
21645 /* Consume the comma, if present. */
21650 p
= consume_improper_spaces (p
, body
);
21659 /* Perfectly formed definition, no complaints. */
21660 macro_define_function (file
, line
, name
,
21661 argc
, (const char **) argv
,
21663 else if (*p
== '\0')
21665 /* Complain, but do define it. */
21666 dwarf2_macro_malformed_definition_complaint (body
);
21667 macro_define_function (file
, line
, name
,
21668 argc
, (const char **) argv
,
21672 /* Just complain. */
21673 dwarf2_macro_malformed_definition_complaint (body
);
21676 /* Just complain. */
21677 dwarf2_macro_malformed_definition_complaint (body
);
21683 for (i
= 0; i
< argc
; i
++)
21689 dwarf2_macro_malformed_definition_complaint (body
);
21692 /* Skip some bytes from BYTES according to the form given in FORM.
21693 Returns the new pointer. */
21695 static const gdb_byte
*
21696 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
21697 enum dwarf_form form
,
21698 unsigned int offset_size
,
21699 struct dwarf2_section_info
*section
)
21701 unsigned int bytes_read
;
21705 case DW_FORM_data1
:
21710 case DW_FORM_data2
:
21714 case DW_FORM_data4
:
21718 case DW_FORM_data8
:
21722 case DW_FORM_data16
:
21726 case DW_FORM_string
:
21727 read_direct_string (abfd
, bytes
, &bytes_read
);
21728 bytes
+= bytes_read
;
21731 case DW_FORM_sec_offset
:
21733 case DW_FORM_GNU_strp_alt
:
21734 bytes
+= offset_size
;
21737 case DW_FORM_block
:
21738 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
21739 bytes
+= bytes_read
;
21742 case DW_FORM_block1
:
21743 bytes
+= 1 + read_1_byte (abfd
, bytes
);
21745 case DW_FORM_block2
:
21746 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
21748 case DW_FORM_block4
:
21749 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
21752 case DW_FORM_sdata
:
21753 case DW_FORM_udata
:
21754 case DW_FORM_GNU_addr_index
:
21755 case DW_FORM_GNU_str_index
:
21756 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
21759 dwarf2_section_buffer_overflow_complaint (section
);
21767 complaint (&symfile_complaints
,
21768 _("invalid form 0x%x in `%s'"),
21769 form
, get_section_name (section
));
21777 /* A helper for dwarf_decode_macros that handles skipping an unknown
21778 opcode. Returns an updated pointer to the macro data buffer; or,
21779 on error, issues a complaint and returns NULL. */
21781 static const gdb_byte
*
21782 skip_unknown_opcode (unsigned int opcode
,
21783 const gdb_byte
**opcode_definitions
,
21784 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
21786 unsigned int offset_size
,
21787 struct dwarf2_section_info
*section
)
21789 unsigned int bytes_read
, i
;
21791 const gdb_byte
*defn
;
21793 if (opcode_definitions
[opcode
] == NULL
)
21795 complaint (&symfile_complaints
,
21796 _("unrecognized DW_MACFINO opcode 0x%x"),
21801 defn
= opcode_definitions
[opcode
];
21802 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
21803 defn
+= bytes_read
;
21805 for (i
= 0; i
< arg
; ++i
)
21807 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
21808 (enum dwarf_form
) defn
[i
], offset_size
,
21810 if (mac_ptr
== NULL
)
21812 /* skip_form_bytes already issued the complaint. */
21820 /* A helper function which parses the header of a macro section.
21821 If the macro section is the extended (for now called "GNU") type,
21822 then this updates *OFFSET_SIZE. Returns a pointer to just after
21823 the header, or issues a complaint and returns NULL on error. */
21825 static const gdb_byte
*
21826 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
21828 const gdb_byte
*mac_ptr
,
21829 unsigned int *offset_size
,
21830 int section_is_gnu
)
21832 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
21834 if (section_is_gnu
)
21836 unsigned int version
, flags
;
21838 version
= read_2_bytes (abfd
, mac_ptr
);
21839 if (version
!= 4 && version
!= 5)
21841 complaint (&symfile_complaints
,
21842 _("unrecognized version `%d' in .debug_macro section"),
21848 flags
= read_1_byte (abfd
, mac_ptr
);
21850 *offset_size
= (flags
& 1) ? 8 : 4;
21852 if ((flags
& 2) != 0)
21853 /* We don't need the line table offset. */
21854 mac_ptr
+= *offset_size
;
21856 /* Vendor opcode descriptions. */
21857 if ((flags
& 4) != 0)
21859 unsigned int i
, count
;
21861 count
= read_1_byte (abfd
, mac_ptr
);
21863 for (i
= 0; i
< count
; ++i
)
21865 unsigned int opcode
, bytes_read
;
21868 opcode
= read_1_byte (abfd
, mac_ptr
);
21870 opcode_definitions
[opcode
] = mac_ptr
;
21871 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21872 mac_ptr
+= bytes_read
;
21881 /* A helper for dwarf_decode_macros that handles the GNU extensions,
21882 including DW_MACRO_import. */
21885 dwarf_decode_macro_bytes (bfd
*abfd
,
21886 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
21887 struct macro_source_file
*current_file
,
21888 struct line_header
*lh
,
21889 struct dwarf2_section_info
*section
,
21890 int section_is_gnu
, int section_is_dwz
,
21891 unsigned int offset_size
,
21892 htab_t include_hash
)
21894 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21895 enum dwarf_macro_record_type macinfo_type
;
21896 int at_commandline
;
21897 const gdb_byte
*opcode_definitions
[256];
21899 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
21900 &offset_size
, section_is_gnu
);
21901 if (mac_ptr
== NULL
)
21903 /* We already issued a complaint. */
21907 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
21908 GDB is still reading the definitions from command line. First
21909 DW_MACINFO_start_file will need to be ignored as it was already executed
21910 to create CURRENT_FILE for the main source holding also the command line
21911 definitions. On first met DW_MACINFO_start_file this flag is reset to
21912 normally execute all the remaining DW_MACINFO_start_file macinfos. */
21914 at_commandline
= 1;
21918 /* Do we at least have room for a macinfo type byte? */
21919 if (mac_ptr
>= mac_end
)
21921 dwarf2_section_buffer_overflow_complaint (section
);
21925 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
21928 /* Note that we rely on the fact that the corresponding GNU and
21929 DWARF constants are the same. */
21930 switch (macinfo_type
)
21932 /* A zero macinfo type indicates the end of the macro
21937 case DW_MACRO_define
:
21938 case DW_MACRO_undef
:
21939 case DW_MACRO_define_strp
:
21940 case DW_MACRO_undef_strp
:
21941 case DW_MACRO_define_sup
:
21942 case DW_MACRO_undef_sup
:
21944 unsigned int bytes_read
;
21949 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21950 mac_ptr
+= bytes_read
;
21952 if (macinfo_type
== DW_MACRO_define
21953 || macinfo_type
== DW_MACRO_undef
)
21955 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21956 mac_ptr
+= bytes_read
;
21960 LONGEST str_offset
;
21962 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
21963 mac_ptr
+= offset_size
;
21965 if (macinfo_type
== DW_MACRO_define_sup
21966 || macinfo_type
== DW_MACRO_undef_sup
21969 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
21971 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
21974 body
= read_indirect_string_at_offset (abfd
, str_offset
);
21977 is_define
= (macinfo_type
== DW_MACRO_define
21978 || macinfo_type
== DW_MACRO_define_strp
21979 || macinfo_type
== DW_MACRO_define_sup
);
21980 if (! current_file
)
21982 /* DWARF violation as no main source is present. */
21983 complaint (&symfile_complaints
,
21984 _("debug info with no main source gives macro %s "
21986 is_define
? _("definition") : _("undefinition"),
21990 if ((line
== 0 && !at_commandline
)
21991 || (line
!= 0 && at_commandline
))
21992 complaint (&symfile_complaints
,
21993 _("debug info gives %s macro %s with %s line %d: %s"),
21994 at_commandline
? _("command-line") : _("in-file"),
21995 is_define
? _("definition") : _("undefinition"),
21996 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
21999 parse_macro_definition (current_file
, line
, body
);
22002 gdb_assert (macinfo_type
== DW_MACRO_undef
22003 || macinfo_type
== DW_MACRO_undef_strp
22004 || macinfo_type
== DW_MACRO_undef_sup
);
22005 macro_undef (current_file
, line
, body
);
22010 case DW_MACRO_start_file
:
22012 unsigned int bytes_read
;
22015 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22016 mac_ptr
+= bytes_read
;
22017 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22018 mac_ptr
+= bytes_read
;
22020 if ((line
== 0 && !at_commandline
)
22021 || (line
!= 0 && at_commandline
))
22022 complaint (&symfile_complaints
,
22023 _("debug info gives source %d included "
22024 "from %s at %s line %d"),
22025 file
, at_commandline
? _("command-line") : _("file"),
22026 line
== 0 ? _("zero") : _("non-zero"), line
);
22028 if (at_commandline
)
22030 /* This DW_MACRO_start_file was executed in the
22032 at_commandline
= 0;
22035 current_file
= macro_start_file (file
, line
, current_file
, lh
);
22039 case DW_MACRO_end_file
:
22040 if (! current_file
)
22041 complaint (&symfile_complaints
,
22042 _("macro debug info has an unmatched "
22043 "`close_file' directive"));
22046 current_file
= current_file
->included_by
;
22047 if (! current_file
)
22049 enum dwarf_macro_record_type next_type
;
22051 /* GCC circa March 2002 doesn't produce the zero
22052 type byte marking the end of the compilation
22053 unit. Complain if it's not there, but exit no
22056 /* Do we at least have room for a macinfo type byte? */
22057 if (mac_ptr
>= mac_end
)
22059 dwarf2_section_buffer_overflow_complaint (section
);
22063 /* We don't increment mac_ptr here, so this is just
22066 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
22068 if (next_type
!= 0)
22069 complaint (&symfile_complaints
,
22070 _("no terminating 0-type entry for "
22071 "macros in `.debug_macinfo' section"));
22078 case DW_MACRO_import
:
22079 case DW_MACRO_import_sup
:
22083 bfd
*include_bfd
= abfd
;
22084 struct dwarf2_section_info
*include_section
= section
;
22085 const gdb_byte
*include_mac_end
= mac_end
;
22086 int is_dwz
= section_is_dwz
;
22087 const gdb_byte
*new_mac_ptr
;
22089 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
22090 mac_ptr
+= offset_size
;
22092 if (macinfo_type
== DW_MACRO_import_sup
)
22094 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
22096 dwarf2_read_section (objfile
, &dwz
->macro
);
22098 include_section
= &dwz
->macro
;
22099 include_bfd
= get_section_bfd_owner (include_section
);
22100 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
22104 new_mac_ptr
= include_section
->buffer
+ offset
;
22105 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
22109 /* This has actually happened; see
22110 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
22111 complaint (&symfile_complaints
,
22112 _("recursive DW_MACRO_import in "
22113 ".debug_macro section"));
22117 *slot
= (void *) new_mac_ptr
;
22119 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
22120 include_mac_end
, current_file
, lh
,
22121 section
, section_is_gnu
, is_dwz
,
22122 offset_size
, include_hash
);
22124 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
22129 case DW_MACINFO_vendor_ext
:
22130 if (!section_is_gnu
)
22132 unsigned int bytes_read
;
22134 /* This reads the constant, but since we don't recognize
22135 any vendor extensions, we ignore it. */
22136 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22137 mac_ptr
+= bytes_read
;
22138 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22139 mac_ptr
+= bytes_read
;
22141 /* We don't recognize any vendor extensions. */
22147 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
22148 mac_ptr
, mac_end
, abfd
, offset_size
,
22150 if (mac_ptr
== NULL
)
22154 } while (macinfo_type
!= 0);
22158 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22159 int section_is_gnu
)
22161 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22162 struct line_header
*lh
= cu
->line_header
;
22164 const gdb_byte
*mac_ptr
, *mac_end
;
22165 struct macro_source_file
*current_file
= 0;
22166 enum dwarf_macro_record_type macinfo_type
;
22167 unsigned int offset_size
= cu
->header
.offset_size
;
22168 const gdb_byte
*opcode_definitions
[256];
22169 struct cleanup
*cleanup
;
22171 struct dwarf2_section_info
*section
;
22172 const char *section_name
;
22174 if (cu
->dwo_unit
!= NULL
)
22176 if (section_is_gnu
)
22178 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22179 section_name
= ".debug_macro.dwo";
22183 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22184 section_name
= ".debug_macinfo.dwo";
22189 if (section_is_gnu
)
22191 section
= &dwarf2_per_objfile
->macro
;
22192 section_name
= ".debug_macro";
22196 section
= &dwarf2_per_objfile
->macinfo
;
22197 section_name
= ".debug_macinfo";
22201 dwarf2_read_section (objfile
, section
);
22202 if (section
->buffer
== NULL
)
22204 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
22207 abfd
= get_section_bfd_owner (section
);
22209 /* First pass: Find the name of the base filename.
22210 This filename is needed in order to process all macros whose definition
22211 (or undefinition) comes from the command line. These macros are defined
22212 before the first DW_MACINFO_start_file entry, and yet still need to be
22213 associated to the base file.
22215 To determine the base file name, we scan the macro definitions until we
22216 reach the first DW_MACINFO_start_file entry. We then initialize
22217 CURRENT_FILE accordingly so that any macro definition found before the
22218 first DW_MACINFO_start_file can still be associated to the base file. */
22220 mac_ptr
= section
->buffer
+ offset
;
22221 mac_end
= section
->buffer
+ section
->size
;
22223 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
22224 &offset_size
, section_is_gnu
);
22225 if (mac_ptr
== NULL
)
22227 /* We already issued a complaint. */
22233 /* Do we at least have room for a macinfo type byte? */
22234 if (mac_ptr
>= mac_end
)
22236 /* Complaint is printed during the second pass as GDB will probably
22237 stop the first pass earlier upon finding
22238 DW_MACINFO_start_file. */
22242 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
22245 /* Note that we rely on the fact that the corresponding GNU and
22246 DWARF constants are the same. */
22247 switch (macinfo_type
)
22249 /* A zero macinfo type indicates the end of the macro
22254 case DW_MACRO_define
:
22255 case DW_MACRO_undef
:
22256 /* Only skip the data by MAC_PTR. */
22258 unsigned int bytes_read
;
22260 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22261 mac_ptr
+= bytes_read
;
22262 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22263 mac_ptr
+= bytes_read
;
22267 case DW_MACRO_start_file
:
22269 unsigned int bytes_read
;
22272 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22273 mac_ptr
+= bytes_read
;
22274 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22275 mac_ptr
+= bytes_read
;
22277 current_file
= macro_start_file (file
, line
, current_file
, lh
);
22281 case DW_MACRO_end_file
:
22282 /* No data to skip by MAC_PTR. */
22285 case DW_MACRO_define_strp
:
22286 case DW_MACRO_undef_strp
:
22287 case DW_MACRO_define_sup
:
22288 case DW_MACRO_undef_sup
:
22290 unsigned int bytes_read
;
22292 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22293 mac_ptr
+= bytes_read
;
22294 mac_ptr
+= offset_size
;
22298 case DW_MACRO_import
:
22299 case DW_MACRO_import_sup
:
22300 /* Note that, according to the spec, a transparent include
22301 chain cannot call DW_MACRO_start_file. So, we can just
22302 skip this opcode. */
22303 mac_ptr
+= offset_size
;
22306 case DW_MACINFO_vendor_ext
:
22307 /* Only skip the data by MAC_PTR. */
22308 if (!section_is_gnu
)
22310 unsigned int bytes_read
;
22312 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22313 mac_ptr
+= bytes_read
;
22314 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22315 mac_ptr
+= bytes_read
;
22320 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
22321 mac_ptr
, mac_end
, abfd
, offset_size
,
22323 if (mac_ptr
== NULL
)
22327 } while (macinfo_type
!= 0 && current_file
== NULL
);
22329 /* Second pass: Process all entries.
22331 Use the AT_COMMAND_LINE flag to determine whether we are still processing
22332 command-line macro definitions/undefinitions. This flag is unset when we
22333 reach the first DW_MACINFO_start_file entry. */
22335 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
22337 NULL
, xcalloc
, xfree
));
22338 mac_ptr
= section
->buffer
+ offset
;
22339 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
22340 *slot
= (void *) mac_ptr
;
22341 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
22342 current_file
, lh
, section
,
22343 section_is_gnu
, 0, offset_size
,
22344 include_hash
.get ());
22347 /* Check if the attribute's form is a DW_FORM_block*
22348 if so return true else false. */
22351 attr_form_is_block (const struct attribute
*attr
)
22353 return (attr
== NULL
? 0 :
22354 attr
->form
== DW_FORM_block1
22355 || attr
->form
== DW_FORM_block2
22356 || attr
->form
== DW_FORM_block4
22357 || attr
->form
== DW_FORM_block
22358 || attr
->form
== DW_FORM_exprloc
);
22361 /* Return non-zero if ATTR's value is a section offset --- classes
22362 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
22363 You may use DW_UNSND (attr) to retrieve such offsets.
22365 Section 7.5.4, "Attribute Encodings", explains that no attribute
22366 may have a value that belongs to more than one of these classes; it
22367 would be ambiguous if we did, because we use the same forms for all
22371 attr_form_is_section_offset (const struct attribute
*attr
)
22373 return (attr
->form
== DW_FORM_data4
22374 || attr
->form
== DW_FORM_data8
22375 || attr
->form
== DW_FORM_sec_offset
);
22378 /* Return non-zero if ATTR's value falls in the 'constant' class, or
22379 zero otherwise. When this function returns true, you can apply
22380 dwarf2_get_attr_constant_value to it.
22382 However, note that for some attributes you must check
22383 attr_form_is_section_offset before using this test. DW_FORM_data4
22384 and DW_FORM_data8 are members of both the constant class, and of
22385 the classes that contain offsets into other debug sections
22386 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
22387 that, if an attribute's can be either a constant or one of the
22388 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
22389 taken as section offsets, not constants.
22391 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
22392 cannot handle that. */
22395 attr_form_is_constant (const struct attribute
*attr
)
22397 switch (attr
->form
)
22399 case DW_FORM_sdata
:
22400 case DW_FORM_udata
:
22401 case DW_FORM_data1
:
22402 case DW_FORM_data2
:
22403 case DW_FORM_data4
:
22404 case DW_FORM_data8
:
22412 /* DW_ADDR is always stored already as sect_offset; despite for the forms
22413 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
22416 attr_form_is_ref (const struct attribute
*attr
)
22418 switch (attr
->form
)
22420 case DW_FORM_ref_addr
:
22425 case DW_FORM_ref_udata
:
22426 case DW_FORM_GNU_ref_alt
:
22433 /* Return the .debug_loc section to use for CU.
22434 For DWO files use .debug_loc.dwo. */
22436 static struct dwarf2_section_info
*
22437 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22441 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22443 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22445 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22446 : &dwarf2_per_objfile
->loc
);
22449 /* A helper function that fills in a dwarf2_loclist_baton. */
22452 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22453 struct dwarf2_loclist_baton
*baton
,
22454 const struct attribute
*attr
)
22456 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22458 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
22460 baton
->per_cu
= cu
->per_cu
;
22461 gdb_assert (baton
->per_cu
);
22462 /* We don't know how long the location list is, but make sure we
22463 don't run off the edge of the section. */
22464 baton
->size
= section
->size
- DW_UNSND (attr
);
22465 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22466 baton
->base_address
= cu
->base_address
;
22467 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22471 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22472 struct dwarf2_cu
*cu
, int is_block
)
22474 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22475 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22477 if (attr_form_is_section_offset (attr
)
22478 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22479 the section. If so, fall through to the complaint in the
22481 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
22483 struct dwarf2_loclist_baton
*baton
;
22485 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22487 fill_in_loclist_baton (cu
, baton
, attr
);
22489 if (cu
->base_known
== 0)
22490 complaint (&symfile_complaints
,
22491 _("Location list used without "
22492 "specifying the CU base address."));
22494 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22495 ? dwarf2_loclist_block_index
22496 : dwarf2_loclist_index
);
22497 SYMBOL_LOCATION_BATON (sym
) = baton
;
22501 struct dwarf2_locexpr_baton
*baton
;
22503 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22504 baton
->per_cu
= cu
->per_cu
;
22505 gdb_assert (baton
->per_cu
);
22507 if (attr_form_is_block (attr
))
22509 /* Note that we're just copying the block's data pointer
22510 here, not the actual data. We're still pointing into the
22511 info_buffer for SYM's objfile; right now we never release
22512 that buffer, but when we do clean up properly this may
22514 baton
->size
= DW_BLOCK (attr
)->size
;
22515 baton
->data
= DW_BLOCK (attr
)->data
;
22519 dwarf2_invalid_attrib_class_complaint ("location description",
22520 SYMBOL_NATURAL_NAME (sym
));
22524 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22525 ? dwarf2_locexpr_block_index
22526 : dwarf2_locexpr_index
);
22527 SYMBOL_LOCATION_BATON (sym
) = baton
;
22531 /* Return the OBJFILE associated with the compilation unit CU. If CU
22532 came from a separate debuginfo file, then the master objfile is
22536 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
22538 struct objfile
*objfile
= per_cu
->objfile
;
22540 /* Return the master objfile, so that we can report and look up the
22541 correct file containing this variable. */
22542 if (objfile
->separate_debug_objfile_backlink
)
22543 objfile
= objfile
->separate_debug_objfile_backlink
;
22548 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22549 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22550 CU_HEADERP first. */
22552 static const struct comp_unit_head
*
22553 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22554 struct dwarf2_per_cu_data
*per_cu
)
22556 const gdb_byte
*info_ptr
;
22559 return &per_cu
->cu
->header
;
22561 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
22563 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22564 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22565 rcuh_kind::COMPILE
);
22570 /* Return the address size given in the compilation unit header for CU. */
22573 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
22575 struct comp_unit_head cu_header_local
;
22576 const struct comp_unit_head
*cu_headerp
;
22578 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22580 return cu_headerp
->addr_size
;
22583 /* Return the offset size given in the compilation unit header for CU. */
22586 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
22588 struct comp_unit_head cu_header_local
;
22589 const struct comp_unit_head
*cu_headerp
;
22591 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22593 return cu_headerp
->offset_size
;
22596 /* See its dwarf2loc.h declaration. */
22599 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
22601 struct comp_unit_head cu_header_local
;
22602 const struct comp_unit_head
*cu_headerp
;
22604 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22606 if (cu_headerp
->version
== 2)
22607 return cu_headerp
->addr_size
;
22609 return cu_headerp
->offset_size
;
22612 /* Return the text offset of the CU. The returned offset comes from
22613 this CU's objfile. If this objfile came from a separate debuginfo
22614 file, then the offset may be different from the corresponding
22615 offset in the parent objfile. */
22618 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
22620 struct objfile
*objfile
= per_cu
->objfile
;
22622 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
22625 /* Return DWARF version number of PER_CU. */
22628 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
22630 return per_cu
->dwarf_version
;
22633 /* Locate the .debug_info compilation unit from CU's objfile which contains
22634 the DIE at OFFSET. Raises an error on failure. */
22636 static struct dwarf2_per_cu_data
*
22637 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
22638 unsigned int offset_in_dwz
,
22639 struct objfile
*objfile
)
22641 struct dwarf2_per_cu_data
*this_cu
;
22643 const sect_offset
*cu_off
;
22646 high
= dwarf2_per_objfile
->n_comp_units
- 1;
22649 struct dwarf2_per_cu_data
*mid_cu
;
22650 int mid
= low
+ (high
- low
) / 2;
22652 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
22653 cu_off
= &mid_cu
->sect_off
;
22654 if (mid_cu
->is_dwz
> offset_in_dwz
22655 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
22660 gdb_assert (low
== high
);
22661 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
22662 cu_off
= &this_cu
->sect_off
;
22663 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
22665 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
22666 error (_("Dwarf Error: could not find partial DIE containing "
22667 "offset 0x%x [in module %s]"),
22668 to_underlying (sect_off
), bfd_get_filename (objfile
->obfd
));
22670 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
22672 return dwarf2_per_objfile
->all_comp_units
[low
-1];
22676 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
22677 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
22678 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
22679 error (_("invalid dwarf2 offset %u"), to_underlying (sect_off
));
22680 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
22685 /* Initialize dwarf2_cu CU, owned by PER_CU. */
22688 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
22690 memset (cu
, 0, sizeof (*cu
));
22692 cu
->per_cu
= per_cu
;
22693 cu
->objfile
= per_cu
->objfile
;
22694 obstack_init (&cu
->comp_unit_obstack
);
22697 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
22700 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
22701 enum language pretend_language
)
22703 struct attribute
*attr
;
22705 /* Set the language we're debugging. */
22706 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
22708 set_cu_language (DW_UNSND (attr
), cu
);
22711 cu
->language
= pretend_language
;
22712 cu
->language_defn
= language_def (cu
->language
);
22715 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
22718 /* Release one cached compilation unit, CU. We unlink it from the tree
22719 of compilation units, but we don't remove it from the read_in_chain;
22720 the caller is responsible for that.
22721 NOTE: DATA is a void * because this function is also used as a
22722 cleanup routine. */
22725 free_heap_comp_unit (void *data
)
22727 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
22729 gdb_assert (cu
->per_cu
!= NULL
);
22730 cu
->per_cu
->cu
= NULL
;
22733 obstack_free (&cu
->comp_unit_obstack
, NULL
);
22738 /* This cleanup function is passed the address of a dwarf2_cu on the stack
22739 when we're finished with it. We can't free the pointer itself, but be
22740 sure to unlink it from the cache. Also release any associated storage. */
22743 free_stack_comp_unit (void *data
)
22745 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
22747 gdb_assert (cu
->per_cu
!= NULL
);
22748 cu
->per_cu
->cu
= NULL
;
22751 obstack_free (&cu
->comp_unit_obstack
, NULL
);
22752 cu
->partial_dies
= NULL
;
22755 /* Free all cached compilation units. */
22758 free_cached_comp_units (void *data
)
22760 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22762 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22763 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22764 while (per_cu
!= NULL
)
22766 struct dwarf2_per_cu_data
*next_cu
;
22768 next_cu
= per_cu
->cu
->read_in_chain
;
22770 free_heap_comp_unit (per_cu
->cu
);
22771 *last_chain
= next_cu
;
22777 /* Increase the age counter on each cached compilation unit, and free
22778 any that are too old. */
22781 age_cached_comp_units (void)
22783 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22785 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
22786 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22787 while (per_cu
!= NULL
)
22789 per_cu
->cu
->last_used
++;
22790 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
22791 dwarf2_mark (per_cu
->cu
);
22792 per_cu
= per_cu
->cu
->read_in_chain
;
22795 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22796 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22797 while (per_cu
!= NULL
)
22799 struct dwarf2_per_cu_data
*next_cu
;
22801 next_cu
= per_cu
->cu
->read_in_chain
;
22803 if (!per_cu
->cu
->mark
)
22805 free_heap_comp_unit (per_cu
->cu
);
22806 *last_chain
= next_cu
;
22809 last_chain
= &per_cu
->cu
->read_in_chain
;
22815 /* Remove a single compilation unit from the cache. */
22818 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
22820 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22822 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22823 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22824 while (per_cu
!= NULL
)
22826 struct dwarf2_per_cu_data
*next_cu
;
22828 next_cu
= per_cu
->cu
->read_in_chain
;
22830 if (per_cu
== target_per_cu
)
22832 free_heap_comp_unit (per_cu
->cu
);
22834 *last_chain
= next_cu
;
22838 last_chain
= &per_cu
->cu
->read_in_chain
;
22844 /* Release all extra memory associated with OBJFILE. */
22847 dwarf2_free_objfile (struct objfile
*objfile
)
22850 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
22851 dwarf2_objfile_data_key
);
22853 if (dwarf2_per_objfile
== NULL
)
22856 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
22857 free_cached_comp_units (NULL
);
22859 if (dwarf2_per_objfile
->quick_file_names_table
)
22860 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
22862 if (dwarf2_per_objfile
->line_header_hash
)
22863 htab_delete (dwarf2_per_objfile
->line_header_hash
);
22865 /* Everything else should be on the objfile obstack. */
22868 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
22869 We store these in a hash table separate from the DIEs, and preserve them
22870 when the DIEs are flushed out of cache.
22872 The CU "per_cu" pointer is needed because offset alone is not enough to
22873 uniquely identify the type. A file may have multiple .debug_types sections,
22874 or the type may come from a DWO file. Furthermore, while it's more logical
22875 to use per_cu->section+offset, with Fission the section with the data is in
22876 the DWO file but we don't know that section at the point we need it.
22877 We have to use something in dwarf2_per_cu_data (or the pointer to it)
22878 because we can enter the lookup routine, get_die_type_at_offset, from
22879 outside this file, and thus won't necessarily have PER_CU->cu.
22880 Fortunately, PER_CU is stable for the life of the objfile. */
22882 struct dwarf2_per_cu_offset_and_type
22884 const struct dwarf2_per_cu_data
*per_cu
;
22885 sect_offset sect_off
;
22889 /* Hash function for a dwarf2_per_cu_offset_and_type. */
22892 per_cu_offset_and_type_hash (const void *item
)
22894 const struct dwarf2_per_cu_offset_and_type
*ofs
22895 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
22897 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
22900 /* Equality function for a dwarf2_per_cu_offset_and_type. */
22903 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
22905 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
22906 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
22907 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
22908 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
22910 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
22911 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
22914 /* Set the type associated with DIE to TYPE. Save it in CU's hash
22915 table if necessary. For convenience, return TYPE.
22917 The DIEs reading must have careful ordering to:
22918 * Not cause infite loops trying to read in DIEs as a prerequisite for
22919 reading current DIE.
22920 * Not trying to dereference contents of still incompletely read in types
22921 while reading in other DIEs.
22922 * Enable referencing still incompletely read in types just by a pointer to
22923 the type without accessing its fields.
22925 Therefore caller should follow these rules:
22926 * Try to fetch any prerequisite types we may need to build this DIE type
22927 before building the type and calling set_die_type.
22928 * After building type call set_die_type for current DIE as soon as
22929 possible before fetching more types to complete the current type.
22930 * Make the type as complete as possible before fetching more types. */
22932 static struct type
*
22933 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
22935 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
22936 struct objfile
*objfile
= cu
->objfile
;
22937 struct attribute
*attr
;
22938 struct dynamic_prop prop
;
22940 /* For Ada types, make sure that the gnat-specific data is always
22941 initialized (if not already set). There are a few types where
22942 we should not be doing so, because the type-specific area is
22943 already used to hold some other piece of info (eg: TYPE_CODE_FLT
22944 where the type-specific area is used to store the floatformat).
22945 But this is not a problem, because the gnat-specific information
22946 is actually not needed for these types. */
22947 if (need_gnat_info (cu
)
22948 && TYPE_CODE (type
) != TYPE_CODE_FUNC
22949 && TYPE_CODE (type
) != TYPE_CODE_FLT
22950 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
22951 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
22952 && TYPE_CODE (type
) != TYPE_CODE_METHOD
22953 && !HAVE_GNAT_AUX_INFO (type
))
22954 INIT_GNAT_SPECIFIC (type
);
22956 /* Read DW_AT_allocated and set in type. */
22957 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
22958 if (attr_form_is_block (attr
))
22960 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22961 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
, objfile
);
22963 else if (attr
!= NULL
)
22965 complaint (&symfile_complaints
,
22966 _("DW_AT_allocated has the wrong form (%s) at DIE 0x%x"),
22967 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
22968 to_underlying (die
->sect_off
));
22971 /* Read DW_AT_associated and set in type. */
22972 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
22973 if (attr_form_is_block (attr
))
22975 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22976 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
, objfile
);
22978 else if (attr
!= NULL
)
22980 complaint (&symfile_complaints
,
22981 _("DW_AT_associated has the wrong form (%s) at DIE 0x%x"),
22982 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
22983 to_underlying (die
->sect_off
));
22986 /* Read DW_AT_data_location and set in type. */
22987 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
22988 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22989 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
, objfile
);
22991 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
22993 dwarf2_per_objfile
->die_type_hash
=
22994 htab_create_alloc_ex (127,
22995 per_cu_offset_and_type_hash
,
22996 per_cu_offset_and_type_eq
,
22998 &objfile
->objfile_obstack
,
22999 hashtab_obstack_allocate
,
23000 dummy_obstack_deallocate
);
23003 ofs
.per_cu
= cu
->per_cu
;
23004 ofs
.sect_off
= die
->sect_off
;
23006 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23007 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
23009 complaint (&symfile_complaints
,
23010 _("A problem internal to GDB: DIE 0x%x has type already set"),
23011 to_underlying (die
->sect_off
));
23012 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23013 struct dwarf2_per_cu_offset_and_type
);
23018 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23019 or return NULL if the die does not have a saved type. */
23021 static struct type
*
23022 get_die_type_at_offset (sect_offset sect_off
,
23023 struct dwarf2_per_cu_data
*per_cu
)
23025 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23027 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23030 ofs
.per_cu
= per_cu
;
23031 ofs
.sect_off
= sect_off
;
23032 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23033 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
23040 /* Look up the type for DIE in CU in die_type_hash,
23041 or return NULL if DIE does not have a saved type. */
23043 static struct type
*
23044 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23046 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23049 /* Add a dependence relationship from CU to REF_PER_CU. */
23052 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23053 struct dwarf2_per_cu_data
*ref_per_cu
)
23057 if (cu
->dependencies
== NULL
)
23059 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23060 NULL
, &cu
->comp_unit_obstack
,
23061 hashtab_obstack_allocate
,
23062 dummy_obstack_deallocate
);
23064 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23066 *slot
= ref_per_cu
;
23069 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23070 Set the mark field in every compilation unit in the
23071 cache that we must keep because we are keeping CU. */
23074 dwarf2_mark_helper (void **slot
, void *data
)
23076 struct dwarf2_per_cu_data
*per_cu
;
23078 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23080 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23081 reading of the chain. As such dependencies remain valid it is not much
23082 useful to track and undo them during QUIT cleanups. */
23083 if (per_cu
->cu
== NULL
)
23086 if (per_cu
->cu
->mark
)
23088 per_cu
->cu
->mark
= 1;
23090 if (per_cu
->cu
->dependencies
!= NULL
)
23091 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23096 /* Set the mark field in CU and in every other compilation unit in the
23097 cache that we must keep because we are keeping CU. */
23100 dwarf2_mark (struct dwarf2_cu
*cu
)
23105 if (cu
->dependencies
!= NULL
)
23106 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23110 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23114 per_cu
->cu
->mark
= 0;
23115 per_cu
= per_cu
->cu
->read_in_chain
;
23119 /* Trivial hash function for partial_die_info: the hash value of a DIE
23120 is its offset in .debug_info for this objfile. */
23123 partial_die_hash (const void *item
)
23125 const struct partial_die_info
*part_die
23126 = (const struct partial_die_info
*) item
;
23128 return to_underlying (part_die
->sect_off
);
23131 /* Trivial comparison function for partial_die_info structures: two DIEs
23132 are equal if they have the same offset. */
23135 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23137 const struct partial_die_info
*part_die_lhs
23138 = (const struct partial_die_info
*) item_lhs
;
23139 const struct partial_die_info
*part_die_rhs
23140 = (const struct partial_die_info
*) item_rhs
;
23142 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23145 static struct cmd_list_element
*set_dwarf_cmdlist
;
23146 static struct cmd_list_element
*show_dwarf_cmdlist
;
23149 set_dwarf_cmd (char *args
, int from_tty
)
23151 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23156 show_dwarf_cmd (char *args
, int from_tty
)
23158 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23161 /* Free data associated with OBJFILE, if necessary. */
23164 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
23166 struct dwarf2_per_objfile
*data
= (struct dwarf2_per_objfile
*) d
;
23169 /* Make sure we don't accidentally use dwarf2_per_objfile while
23171 dwarf2_per_objfile
= NULL
;
23173 for (ix
= 0; ix
< data
->n_comp_units
; ++ix
)
23174 VEC_free (dwarf2_per_cu_ptr
, data
->all_comp_units
[ix
]->imported_symtabs
);
23176 for (ix
= 0; ix
< data
->n_type_units
; ++ix
)
23177 VEC_free (dwarf2_per_cu_ptr
,
23178 data
->all_type_units
[ix
]->per_cu
.imported_symtabs
);
23179 xfree (data
->all_type_units
);
23181 VEC_free (dwarf2_section_info_def
, data
->types
);
23183 if (data
->dwo_files
)
23184 free_dwo_files (data
->dwo_files
, objfile
);
23185 if (data
->dwp_file
)
23186 gdb_bfd_unref (data
->dwp_file
->dbfd
);
23188 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
23189 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
23193 /* The "save gdb-index" command. */
23195 /* In-memory buffer to prepare data to be written later to a file. */
23199 /* Copy DATA to the end of the buffer. */
23200 template<typename T
>
23201 void append_data (const T
&data
)
23203 std::copy (reinterpret_cast<const gdb_byte
*> (&data
),
23204 reinterpret_cast<const gdb_byte
*> (&data
+ 1),
23205 grow (sizeof (data
)));
23208 /* Copy CSTR (a zero-terminated string) to the end of buffer. The
23209 terminating zero is appended too. */
23210 void append_cstr0 (const char *cstr
)
23212 const size_t size
= strlen (cstr
) + 1;
23213 std::copy (cstr
, cstr
+ size
, grow (size
));
23216 /* Accept a host-format integer in VAL and append it to the buffer
23217 as a target-format integer which is LEN bytes long. */
23218 void append_uint (size_t len
, bfd_endian byte_order
, ULONGEST val
)
23220 ::store_unsigned_integer (grow (len
), len
, byte_order
, val
);
23223 /* Return the size of the buffer. */
23224 size_t size () const
23226 return m_vec
.size ();
23229 /* Write the buffer to FILE. */
23230 void file_write (FILE *file
) const
23232 if (::fwrite (m_vec
.data (), 1, m_vec
.size (), file
) != m_vec
.size ())
23233 error (_("couldn't write data to file"));
23237 /* Grow SIZE bytes at the end of the buffer. Returns a pointer to
23238 the start of the new block. */
23239 gdb_byte
*grow (size_t size
)
23241 m_vec
.resize (m_vec
.size () + size
);
23242 return &*m_vec
.end () - size
;
23245 gdb::byte_vector m_vec
;
23248 /* An entry in the symbol table. */
23249 struct symtab_index_entry
23251 /* The name of the symbol. */
23253 /* The offset of the name in the constant pool. */
23254 offset_type index_offset
;
23255 /* A sorted vector of the indices of all the CUs that hold an object
23257 std::vector
<offset_type
> cu_indices
;
23260 /* The symbol table. This is a power-of-2-sized hash table. */
23261 struct mapped_symtab
23265 data
.resize (1024);
23268 offset_type n_elements
= 0;
23269 std::vector
<symtab_index_entry
> data
;
23272 /* Find a slot in SYMTAB for the symbol NAME. Returns a reference to
23275 Function is used only during write_hash_table so no index format backward
23276 compatibility is needed. */
23278 static symtab_index_entry
&
23279 find_slot (struct mapped_symtab
*symtab
, const char *name
)
23281 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
23283 index
= hash
& (symtab
->data
.size () - 1);
23284 step
= ((hash
* 17) & (symtab
->data
.size () - 1)) | 1;
23288 if (symtab
->data
[index
].name
== NULL
23289 || strcmp (name
, symtab
->data
[index
].name
) == 0)
23290 return symtab
->data
[index
];
23291 index
= (index
+ step
) & (symtab
->data
.size () - 1);
23295 /* Expand SYMTAB's hash table. */
23298 hash_expand (struct mapped_symtab
*symtab
)
23300 auto old_entries
= std::move (symtab
->data
);
23302 symtab
->data
.clear ();
23303 symtab
->data
.resize (old_entries
.size () * 2);
23305 for (auto &it
: old_entries
)
23306 if (it
.name
!= NULL
)
23308 auto &ref
= find_slot (symtab
, it
.name
);
23309 ref
= std::move (it
);
23313 /* Add an entry to SYMTAB. NAME is the name of the symbol.
23314 CU_INDEX is the index of the CU in which the symbol appears.
23315 IS_STATIC is one if the symbol is static, otherwise zero (global). */
23318 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
23319 int is_static
, gdb_index_symbol_kind kind
,
23320 offset_type cu_index
)
23322 offset_type cu_index_and_attrs
;
23324 ++symtab
->n_elements
;
23325 if (4 * symtab
->n_elements
/ 3 >= symtab
->data
.size ())
23326 hash_expand (symtab
);
23328 symtab_index_entry
&slot
= find_slot (symtab
, name
);
23329 if (slot
.name
== NULL
)
23332 /* index_offset is set later. */
23335 cu_index_and_attrs
= 0;
23336 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
23337 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
23338 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
23340 /* We don't want to record an index value twice as we want to avoid the
23342 We process all global symbols and then all static symbols
23343 (which would allow us to avoid the duplication by only having to check
23344 the last entry pushed), but a symbol could have multiple kinds in one CU.
23345 To keep things simple we don't worry about the duplication here and
23346 sort and uniqufy the list after we've processed all symbols. */
23347 slot
.cu_indices
.push_back (cu_index_and_attrs
);
23350 /* Sort and remove duplicates of all symbols' cu_indices lists. */
23353 uniquify_cu_indices (struct mapped_symtab
*symtab
)
23355 for (auto &entry
: symtab
->data
)
23357 if (entry
.name
!= NULL
&& !entry
.cu_indices
.empty ())
23359 auto &cu_indices
= entry
.cu_indices
;
23360 std::sort (cu_indices
.begin (), cu_indices
.end ());
23361 auto from
= std::unique (cu_indices
.begin (), cu_indices
.end ());
23362 cu_indices
.erase (from
, cu_indices
.end ());
23367 /* A form of 'const char *' suitable for container keys. Only the
23368 pointer is stored. The strings themselves are compared, not the
23373 c_str_view (const char *cstr
)
23377 bool operator== (const c_str_view
&other
) const
23379 return strcmp (m_cstr
, other
.m_cstr
) == 0;
23383 friend class c_str_view_hasher
;
23384 const char *const m_cstr
;
23387 /* A std::unordered_map::hasher for c_str_view that uses the right
23388 hash function for strings in a mapped index. */
23389 class c_str_view_hasher
23392 size_t operator () (const c_str_view
&x
) const
23394 return mapped_index_string_hash (INT_MAX
, x
.m_cstr
);
23398 /* A std::unordered_map::hasher for std::vector<>. */
23399 template<typename T
>
23400 class vector_hasher
23403 size_t operator () (const std::vector
<T
> &key
) const
23405 return iterative_hash (key
.data (),
23406 sizeof (key
.front ()) * key
.size (), 0);
23410 /* Write the mapped hash table SYMTAB to the data buffer OUTPUT, with
23411 constant pool entries going into the data buffer CPOOL. */
23414 write_hash_table (mapped_symtab
*symtab
, data_buf
&output
, data_buf
&cpool
)
23417 /* Elements are sorted vectors of the indices of all the CUs that
23418 hold an object of this name. */
23419 std::unordered_map
<std::vector
<offset_type
>, offset_type
,
23420 vector_hasher
<offset_type
>>
23423 /* We add all the index vectors to the constant pool first, to
23424 ensure alignment is ok. */
23425 for (symtab_index_entry
&entry
: symtab
->data
)
23427 if (entry
.name
== NULL
)
23429 gdb_assert (entry
.index_offset
== 0);
23431 /* Finding before inserting is faster than always trying to
23432 insert, because inserting always allocates a node, does the
23433 lookup, and then destroys the new node if another node
23434 already had the same key. C++17 try_emplace will avoid
23437 = symbol_hash_table
.find (entry
.cu_indices
);
23438 if (found
!= symbol_hash_table
.end ())
23440 entry
.index_offset
= found
->second
;
23444 symbol_hash_table
.emplace (entry
.cu_indices
, cpool
.size ());
23445 entry
.index_offset
= cpool
.size ();
23446 cpool
.append_data (MAYBE_SWAP (entry
.cu_indices
.size ()));
23447 for (const auto index
: entry
.cu_indices
)
23448 cpool
.append_data (MAYBE_SWAP (index
));
23452 /* Now write out the hash table. */
23453 std::unordered_map
<c_str_view
, offset_type
, c_str_view_hasher
> str_table
;
23454 for (const auto &entry
: symtab
->data
)
23456 offset_type str_off
, vec_off
;
23458 if (entry
.name
!= NULL
)
23460 const auto insertpair
= str_table
.emplace (entry
.name
, cpool
.size ());
23461 if (insertpair
.second
)
23462 cpool
.append_cstr0 (entry
.name
);
23463 str_off
= insertpair
.first
->second
;
23464 vec_off
= entry
.index_offset
;
23468 /* While 0 is a valid constant pool index, it is not valid
23469 to have 0 for both offsets. */
23474 output
.append_data (MAYBE_SWAP (str_off
));
23475 output
.append_data (MAYBE_SWAP (vec_off
));
23479 typedef std::unordered_map
<partial_symtab
*, unsigned int> psym_index_map
;
23481 /* Helper struct for building the address table. */
23482 struct addrmap_index_data
23484 addrmap_index_data (data_buf
&addr_vec_
, psym_index_map
&cu_index_htab_
)
23485 : addr_vec (addr_vec_
), cu_index_htab (cu_index_htab_
)
23488 struct objfile
*objfile
;
23489 data_buf
&addr_vec
;
23490 psym_index_map
&cu_index_htab
;
23492 /* Non-zero if the previous_* fields are valid.
23493 We can't write an entry until we see the next entry (since it is only then
23494 that we know the end of the entry). */
23495 int previous_valid
;
23496 /* Index of the CU in the table of all CUs in the index file. */
23497 unsigned int previous_cu_index
;
23498 /* Start address of the CU. */
23499 CORE_ADDR previous_cu_start
;
23502 /* Write an address entry to ADDR_VEC. */
23505 add_address_entry (struct objfile
*objfile
, data_buf
&addr_vec
,
23506 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
23508 CORE_ADDR baseaddr
;
23510 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23512 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
23513 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
23514 addr_vec
.append_data (MAYBE_SWAP (cu_index
));
23517 /* Worker function for traversing an addrmap to build the address table. */
23520 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
23522 struct addrmap_index_data
*data
= (struct addrmap_index_data
*) datap
;
23523 struct partial_symtab
*pst
= (struct partial_symtab
*) obj
;
23525 if (data
->previous_valid
)
23526 add_address_entry (data
->objfile
, data
->addr_vec
,
23527 data
->previous_cu_start
, start_addr
,
23528 data
->previous_cu_index
);
23530 data
->previous_cu_start
= start_addr
;
23533 const auto it
= data
->cu_index_htab
.find (pst
);
23534 gdb_assert (it
!= data
->cu_index_htab
.cend ());
23535 data
->previous_cu_index
= it
->second
;
23536 data
->previous_valid
= 1;
23539 data
->previous_valid
= 0;
23544 /* Write OBJFILE's address map to ADDR_VEC.
23545 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
23546 in the index file. */
23549 write_address_map (struct objfile
*objfile
, data_buf
&addr_vec
,
23550 psym_index_map
&cu_index_htab
)
23552 struct addrmap_index_data
addrmap_index_data (addr_vec
, cu_index_htab
);
23554 /* When writing the address table, we have to cope with the fact that
23555 the addrmap iterator only provides the start of a region; we have to
23556 wait until the next invocation to get the start of the next region. */
23558 addrmap_index_data
.objfile
= objfile
;
23559 addrmap_index_data
.previous_valid
= 0;
23561 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
23562 &addrmap_index_data
);
23564 /* It's highly unlikely the last entry (end address = 0xff...ff)
23565 is valid, but we should still handle it.
23566 The end address is recorded as the start of the next region, but that
23567 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
23569 if (addrmap_index_data
.previous_valid
)
23570 add_address_entry (objfile
, addr_vec
,
23571 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
23572 addrmap_index_data
.previous_cu_index
);
23575 /* Return the symbol kind of PSYM. */
23577 static gdb_index_symbol_kind
23578 symbol_kind (struct partial_symbol
*psym
)
23580 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
23581 enum address_class aclass
= PSYMBOL_CLASS (psym
);
23589 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
23591 return GDB_INDEX_SYMBOL_KIND_TYPE
;
23593 case LOC_CONST_BYTES
:
23594 case LOC_OPTIMIZED_OUT
:
23596 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
23598 /* Note: It's currently impossible to recognize psyms as enum values
23599 short of reading the type info. For now punt. */
23600 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
23602 /* There are other LOC_FOO values that one might want to classify
23603 as variables, but dwarf2read.c doesn't currently use them. */
23604 return GDB_INDEX_SYMBOL_KIND_OTHER
;
23606 case STRUCT_DOMAIN
:
23607 return GDB_INDEX_SYMBOL_KIND_TYPE
;
23609 return GDB_INDEX_SYMBOL_KIND_OTHER
;
23613 /* Add a list of partial symbols to SYMTAB. */
23616 write_psymbols (struct mapped_symtab
*symtab
,
23617 std::unordered_set
<partial_symbol
*> &psyms_seen
,
23618 struct partial_symbol
**psymp
,
23620 offset_type cu_index
,
23623 for (; count
-- > 0; ++psymp
)
23625 struct partial_symbol
*psym
= *psymp
;
23627 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
23628 error (_("Ada is not currently supported by the index"));
23630 /* Only add a given psymbol once. */
23631 if (psyms_seen
.insert (psym
).second
)
23633 gdb_index_symbol_kind kind
= symbol_kind (psym
);
23635 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
23636 is_static
, kind
, cu_index
);
23641 /* A helper struct used when iterating over debug_types. */
23642 struct signatured_type_index_data
23644 signatured_type_index_data (data_buf
&types_list_
,
23645 std::unordered_set
<partial_symbol
*> &psyms_seen_
)
23646 : types_list (types_list_
), psyms_seen (psyms_seen_
)
23649 struct objfile
*objfile
;
23650 struct mapped_symtab
*symtab
;
23651 data_buf
&types_list
;
23652 std::unordered_set
<partial_symbol
*> &psyms_seen
;
23656 /* A helper function that writes a single signatured_type to an
23660 write_one_signatured_type (void **slot
, void *d
)
23662 struct signatured_type_index_data
*info
23663 = (struct signatured_type_index_data
*) d
;
23664 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
23665 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
23667 write_psymbols (info
->symtab
,
23669 info
->objfile
->global_psymbols
.list
23670 + psymtab
->globals_offset
,
23671 psymtab
->n_global_syms
, info
->cu_index
,
23673 write_psymbols (info
->symtab
,
23675 info
->objfile
->static_psymbols
.list
23676 + psymtab
->statics_offset
,
23677 psymtab
->n_static_syms
, info
->cu_index
,
23680 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
23681 to_underlying (entry
->per_cu
.sect_off
));
23682 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
23683 to_underlying (entry
->type_offset_in_tu
));
23684 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
, entry
->signature
);
23691 /* Recurse into all "included" dependencies and count their symbols as
23692 if they appeared in this psymtab. */
23695 recursively_count_psymbols (struct partial_symtab
*psymtab
,
23696 size_t &psyms_seen
)
23698 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
23699 if (psymtab
->dependencies
[i
]->user
!= NULL
)
23700 recursively_count_psymbols (psymtab
->dependencies
[i
],
23703 psyms_seen
+= psymtab
->n_global_syms
;
23704 psyms_seen
+= psymtab
->n_static_syms
;
23707 /* Recurse into all "included" dependencies and write their symbols as
23708 if they appeared in this psymtab. */
23711 recursively_write_psymbols (struct objfile
*objfile
,
23712 struct partial_symtab
*psymtab
,
23713 struct mapped_symtab
*symtab
,
23714 std::unordered_set
<partial_symbol
*> &psyms_seen
,
23715 offset_type cu_index
)
23719 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
23720 if (psymtab
->dependencies
[i
]->user
!= NULL
)
23721 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
23722 symtab
, psyms_seen
, cu_index
);
23724 write_psymbols (symtab
,
23726 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
23727 psymtab
->n_global_syms
, cu_index
,
23729 write_psymbols (symtab
,
23731 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
23732 psymtab
->n_static_syms
, cu_index
,
23736 /* Closes FILE on scope exit. */
23739 explicit file_closer (FILE *file
)
23744 { fclose (m_file
); }
23750 /* Create an index file for OBJFILE in the directory DIR. */
23753 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
23755 if (dwarf2_per_objfile
->using_index
)
23756 error (_("Cannot use an index to create the index"));
23758 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
23759 error (_("Cannot make an index when the file has multiple .debug_types sections"));
23761 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
23765 if (stat (objfile_name (objfile
), &st
) < 0)
23766 perror_with_name (objfile_name (objfile
));
23768 std::string
filename (std::string (dir
) + SLASH_STRING
23769 + lbasename (objfile_name (objfile
)) + INDEX_SUFFIX
);
23771 FILE *out_file
= gdb_fopen_cloexec (filename
.c_str (), "wb");
23773 error (_("Can't open `%s' for writing"), filename
.c_str ());
23775 /* Order matters here; we want FILE to be closed before FILENAME is
23776 unlinked, because on MS-Windows one cannot delete a file that is
23777 still open. (Don't call anything here that might throw until
23778 file_closer is created.) */
23779 gdb::unlinker
unlink_file (filename
.c_str ());
23780 file_closer
close_out_file (out_file
);
23782 mapped_symtab symtab
;
23785 /* While we're scanning CU's create a table that maps a psymtab pointer
23786 (which is what addrmap records) to its index (which is what is recorded
23787 in the index file). This will later be needed to write the address
23789 psym_index_map cu_index_htab
;
23790 cu_index_htab
.reserve (dwarf2_per_objfile
->n_comp_units
);
23792 /* The CU list is already sorted, so we don't need to do additional
23793 work here. Also, the debug_types entries do not appear in
23794 all_comp_units, but only in their own hash table. */
23796 /* The psyms_seen set is potentially going to be largish (~40k
23797 elements when indexing a -g3 build of GDB itself). Estimate the
23798 number of elements in order to avoid too many rehashes, which
23799 require rebuilding buckets and thus many trips to
23801 size_t psyms_count
= 0;
23802 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
23804 struct dwarf2_per_cu_data
*per_cu
23805 = dwarf2_per_objfile
->all_comp_units
[i
];
23806 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
23808 if (psymtab
!= NULL
&& psymtab
->user
== NULL
)
23809 recursively_count_psymbols (psymtab
, psyms_count
);
23811 /* Generating an index for gdb itself shows a ratio of
23812 TOTAL_SEEN_SYMS/UNIQUE_SYMS or ~5. 4 seems like a good bet. */
23813 std::unordered_set
<partial_symbol
*> psyms_seen (psyms_count
/ 4);
23814 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
23816 struct dwarf2_per_cu_data
*per_cu
23817 = dwarf2_per_objfile
->all_comp_units
[i
];
23818 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
23820 /* CU of a shared file from 'dwz -m' may be unused by this main file.
23821 It may be referenced from a local scope but in such case it does not
23822 need to be present in .gdb_index. */
23823 if (psymtab
== NULL
)
23826 if (psymtab
->user
== NULL
)
23827 recursively_write_psymbols (objfile
, psymtab
, &symtab
,
23830 const auto insertpair
= cu_index_htab
.emplace (psymtab
, i
);
23831 gdb_assert (insertpair
.second
);
23833 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
23834 to_underlying (per_cu
->sect_off
));
23835 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
23838 /* Dump the address map. */
23840 write_address_map (objfile
, addr_vec
, cu_index_htab
);
23842 /* Write out the .debug_type entries, if any. */
23843 data_buf types_cu_list
;
23844 if (dwarf2_per_objfile
->signatured_types
)
23846 signatured_type_index_data
sig_data (types_cu_list
,
23849 sig_data
.objfile
= objfile
;
23850 sig_data
.symtab
= &symtab
;
23851 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
23852 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
23853 write_one_signatured_type
, &sig_data
);
23856 /* Now that we've processed all symbols we can shrink their cu_indices
23858 uniquify_cu_indices (&symtab
);
23860 data_buf symtab_vec
, constant_pool
;
23861 write_hash_table (&symtab
, symtab_vec
, constant_pool
);
23864 const offset_type size_of_contents
= 6 * sizeof (offset_type
);
23865 offset_type total_len
= size_of_contents
;
23867 /* The version number. */
23868 contents
.append_data (MAYBE_SWAP (8));
23870 /* The offset of the CU list from the start of the file. */
23871 contents
.append_data (MAYBE_SWAP (total_len
));
23872 total_len
+= cu_list
.size ();
23874 /* The offset of the types CU list from the start of the file. */
23875 contents
.append_data (MAYBE_SWAP (total_len
));
23876 total_len
+= types_cu_list
.size ();
23878 /* The offset of the address table from the start of the file. */
23879 contents
.append_data (MAYBE_SWAP (total_len
));
23880 total_len
+= addr_vec
.size ();
23882 /* The offset of the symbol table from the start of the file. */
23883 contents
.append_data (MAYBE_SWAP (total_len
));
23884 total_len
+= symtab_vec
.size ();
23886 /* The offset of the constant pool from the start of the file. */
23887 contents
.append_data (MAYBE_SWAP (total_len
));
23888 total_len
+= constant_pool
.size ();
23890 gdb_assert (contents
.size () == size_of_contents
);
23892 contents
.file_write (out_file
);
23893 cu_list
.file_write (out_file
);
23894 types_cu_list
.file_write (out_file
);
23895 addr_vec
.file_write (out_file
);
23896 symtab_vec
.file_write (out_file
);
23897 constant_pool
.file_write (out_file
);
23899 /* We want to keep the file. */
23900 unlink_file
.keep ();
23903 /* Implementation of the `save gdb-index' command.
23905 Note that the file format used by this command is documented in the
23906 GDB manual. Any changes here must be documented there. */
23909 save_gdb_index_command (char *arg
, int from_tty
)
23911 struct objfile
*objfile
;
23914 error (_("usage: save gdb-index DIRECTORY"));
23916 ALL_OBJFILES (objfile
)
23920 /* If the objfile does not correspond to an actual file, skip it. */
23921 if (stat (objfile_name (objfile
), &st
) < 0)
23925 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
23926 dwarf2_objfile_data_key
);
23927 if (dwarf2_per_objfile
)
23932 write_psymtabs_to_index (objfile
, arg
);
23934 CATCH (except
, RETURN_MASK_ERROR
)
23936 exception_fprintf (gdb_stderr
, except
,
23937 _("Error while writing index for `%s': "),
23938 objfile_name (objfile
));
23947 int dwarf_always_disassemble
;
23950 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
23951 struct cmd_list_element
*c
, const char *value
)
23953 fprintf_filtered (file
,
23954 _("Whether to always disassemble "
23955 "DWARF expressions is %s.\n"),
23960 show_check_physname (struct ui_file
*file
, int from_tty
,
23961 struct cmd_list_element
*c
, const char *value
)
23963 fprintf_filtered (file
,
23964 _("Whether to check \"physname\" is %s.\n"),
23968 void _initialize_dwarf2_read (void);
23971 _initialize_dwarf2_read (void)
23973 struct cmd_list_element
*c
;
23975 dwarf2_objfile_data_key
23976 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
23978 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23979 Set DWARF specific variables.\n\
23980 Configure DWARF variables such as the cache size"),
23981 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23982 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23984 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23985 Show DWARF specific variables\n\
23986 Show DWARF variables such as the cache size"),
23987 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23988 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23990 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23991 &dwarf_max_cache_age
, _("\
23992 Set the upper bound on the age of cached DWARF compilation units."), _("\
23993 Show the upper bound on the age of cached DWARF compilation units."), _("\
23994 A higher limit means that cached compilation units will be stored\n\
23995 in memory longer, and more total memory will be used. Zero disables\n\
23996 caching, which can slow down startup."),
23998 show_dwarf_max_cache_age
,
23999 &set_dwarf_cmdlist
,
24000 &show_dwarf_cmdlist
);
24002 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
24003 &dwarf_always_disassemble
, _("\
24004 Set whether `info address' always disassembles DWARF expressions."), _("\
24005 Show whether `info address' always disassembles DWARF expressions."), _("\
24006 When enabled, DWARF expressions are always printed in an assembly-like\n\
24007 syntax. When disabled, expressions will be printed in a more\n\
24008 conversational style, when possible."),
24010 show_dwarf_always_disassemble
,
24011 &set_dwarf_cmdlist
,
24012 &show_dwarf_cmdlist
);
24014 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24015 Set debugging of the DWARF reader."), _("\
24016 Show debugging of the DWARF reader."), _("\
24017 When enabled (non-zero), debugging messages are printed during DWARF\n\
24018 reading and symtab expansion. A value of 1 (one) provides basic\n\
24019 information. A value greater than 1 provides more verbose information."),
24022 &setdebuglist
, &showdebuglist
);
24024 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24025 Set debugging of the DWARF DIE reader."), _("\
24026 Show debugging of the DWARF DIE reader."), _("\
24027 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24028 The value is the maximum depth to print."),
24031 &setdebuglist
, &showdebuglist
);
24033 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24034 Set debugging of the dwarf line reader."), _("\
24035 Show debugging of the dwarf line reader."), _("\
24036 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24037 A value of 1 (one) provides basic information.\n\
24038 A value greater than 1 provides more verbose information."),
24041 &setdebuglist
, &showdebuglist
);
24043 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24044 Set cross-checking of \"physname\" code against demangler."), _("\
24045 Show cross-checking of \"physname\" code against demangler."), _("\
24046 When enabled, GDB's internal \"physname\" code is checked against\n\
24048 NULL
, show_check_physname
,
24049 &setdebuglist
, &showdebuglist
);
24051 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24052 no_class
, &use_deprecated_index_sections
, _("\
24053 Set whether to use deprecated gdb_index sections."), _("\
24054 Show whether to use deprecated gdb_index sections."), _("\
24055 When enabled, deprecated .gdb_index sections are used anyway.\n\
24056 Normally they are ignored either because of a missing feature or\n\
24057 performance issue.\n\
24058 Warning: This option must be enabled before gdb reads the file."),
24061 &setlist
, &showlist
);
24063 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
24065 Save a gdb-index file.\n\
24066 Usage: save gdb-index DIRECTORY"),
24068 set_cmd_completer (c
, filename_completer
);
24070 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24071 &dwarf2_locexpr_funcs
);
24072 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24073 &dwarf2_loclist_funcs
);
24075 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24076 &dwarf2_block_frame_base_locexpr_funcs
);
24077 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24078 &dwarf2_block_frame_base_loclist_funcs
);