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"
76 #include <sys/types.h>
79 typedef struct symbol
*symbolp
;
82 /* When == 1, print basic high level tracing messages.
83 When > 1, be more verbose.
84 This is in contrast to the low level DIE reading of dwarf_die_debug. */
85 static unsigned int dwarf_read_debug
= 0;
87 /* When non-zero, dump DIEs after they are read in. */
88 static unsigned int dwarf_die_debug
= 0;
90 /* When non-zero, dump line number entries as they are read in. */
91 static unsigned int dwarf_line_debug
= 0;
93 /* When non-zero, cross-check physname against demangler. */
94 static int check_physname
= 0;
96 /* When non-zero, do not reject deprecated .gdb_index sections. */
97 static int use_deprecated_index_sections
= 0;
99 static const struct objfile_data
*dwarf2_objfile_data_key
;
101 /* The "aclass" indices for various kinds of computed DWARF symbols. */
103 static int dwarf2_locexpr_index
;
104 static int dwarf2_loclist_index
;
105 static int dwarf2_locexpr_block_index
;
106 static int dwarf2_loclist_block_index
;
108 /* A descriptor for dwarf sections.
110 S.ASECTION, SIZE are typically initialized when the objfile is first
111 scanned. BUFFER, READIN are filled in later when the section is read.
112 If the section contained compressed data then SIZE is updated to record
113 the uncompressed size of the section.
115 DWP file format V2 introduces a wrinkle that is easiest to handle by
116 creating the concept of virtual sections contained within a real section.
117 In DWP V2 the sections of the input DWO files are concatenated together
118 into one section, but section offsets are kept relative to the original
120 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
121 the real section this "virtual" section is contained in, and BUFFER,SIZE
122 describe the virtual section. */
124 struct dwarf2_section_info
128 /* If this is a real section, the bfd section. */
130 /* If this is a virtual section, pointer to the containing ("real")
132 struct dwarf2_section_info
*containing_section
;
134 /* Pointer to section data, only valid if readin. */
135 const gdb_byte
*buffer
;
136 /* The size of the section, real or virtual. */
138 /* If this is a virtual section, the offset in the real section.
139 Only valid if is_virtual. */
140 bfd_size_type virtual_offset
;
141 /* True if we have tried to read this section. */
143 /* True if this is a virtual section, False otherwise.
144 This specifies which of s.section and s.containing_section to use. */
148 typedef struct dwarf2_section_info dwarf2_section_info_def
;
149 DEF_VEC_O (dwarf2_section_info_def
);
151 /* All offsets in the index are of this type. It must be
152 architecture-independent. */
153 typedef uint32_t offset_type
;
155 DEF_VEC_I (offset_type
);
157 /* Ensure only legit values are used. */
158 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
160 gdb_assert ((unsigned int) (value) <= 1); \
161 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
164 /* Ensure only legit values are used. */
165 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
167 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
168 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
169 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
172 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
173 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
175 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
176 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
179 /* A description of the mapped index. The file format is described in
180 a comment by the code that writes the index. */
183 /* Index data format version. */
186 /* The total length of the buffer. */
189 /* A pointer to the address table data. */
190 const gdb_byte
*address_table
;
192 /* Size of the address table data in bytes. */
193 offset_type address_table_size
;
195 /* The symbol table, implemented as a hash table. */
196 const offset_type
*symbol_table
;
198 /* Size in slots, each slot is 2 offset_types. */
199 offset_type symbol_table_slots
;
201 /* A pointer to the constant pool. */
202 const char *constant_pool
;
205 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
206 DEF_VEC_P (dwarf2_per_cu_ptr
);
210 int nr_uniq_abbrev_tables
;
212 int nr_symtab_sharers
;
213 int nr_stmt_less_type_units
;
214 int nr_all_type_units_reallocs
;
217 /* Collection of data recorded per objfile.
218 This hangs off of dwarf2_objfile_data_key. */
220 struct dwarf2_per_objfile
222 struct dwarf2_section_info info
;
223 struct dwarf2_section_info abbrev
;
224 struct dwarf2_section_info line
;
225 struct dwarf2_section_info loc
;
226 struct dwarf2_section_info loclists
;
227 struct dwarf2_section_info macinfo
;
228 struct dwarf2_section_info macro
;
229 struct dwarf2_section_info str
;
230 struct dwarf2_section_info line_str
;
231 struct dwarf2_section_info ranges
;
232 struct dwarf2_section_info rnglists
;
233 struct dwarf2_section_info addr
;
234 struct dwarf2_section_info frame
;
235 struct dwarf2_section_info eh_frame
;
236 struct dwarf2_section_info gdb_index
;
238 VEC (dwarf2_section_info_def
) *types
;
241 struct objfile
*objfile
;
243 /* Table of all the compilation units. This is used to locate
244 the target compilation unit of a particular reference. */
245 struct dwarf2_per_cu_data
**all_comp_units
;
247 /* The number of compilation units in ALL_COMP_UNITS. */
250 /* The number of .debug_types-related CUs. */
253 /* The number of elements allocated in all_type_units.
254 If there are skeleton-less TUs, we add them to all_type_units lazily. */
255 int n_allocated_type_units
;
257 /* The .debug_types-related CUs (TUs).
258 This is stored in malloc space because we may realloc it. */
259 struct signatured_type
**all_type_units
;
261 /* Table of struct type_unit_group objects.
262 The hash key is the DW_AT_stmt_list value. */
263 htab_t type_unit_groups
;
265 /* A table mapping .debug_types signatures to its signatured_type entry.
266 This is NULL if the .debug_types section hasn't been read in yet. */
267 htab_t signatured_types
;
269 /* Type unit statistics, to see how well the scaling improvements
271 struct tu_stats tu_stats
;
273 /* A chain of compilation units that are currently read in, so that
274 they can be freed later. */
275 struct dwarf2_per_cu_data
*read_in_chain
;
277 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
278 This is NULL if the table hasn't been allocated yet. */
281 /* Non-zero if we've check for whether there is a DWP file. */
284 /* The DWP file if there is one, or NULL. */
285 struct dwp_file
*dwp_file
;
287 /* The shared '.dwz' file, if one exists. This is used when the
288 original data was compressed using 'dwz -m'. */
289 struct dwz_file
*dwz_file
;
291 /* A flag indicating wether this objfile has a section loaded at a
293 int has_section_at_zero
;
295 /* True if we are using the mapped index,
296 or we are faking it for OBJF_READNOW's sake. */
297 unsigned char using_index
;
299 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
300 struct mapped_index
*index_table
;
302 /* When using index_table, this keeps track of all quick_file_names entries.
303 TUs typically share line table entries with a CU, so we maintain a
304 separate table of all line table entries to support the sharing.
305 Note that while there can be way more TUs than CUs, we've already
306 sorted all the TUs into "type unit groups", grouped by their
307 DW_AT_stmt_list value. Therefore the only sharing done here is with a
308 CU and its associated TU group if there is one. */
309 htab_t quick_file_names_table
;
311 /* Set during partial symbol reading, to prevent queueing of full
313 int reading_partial_symbols
;
315 /* Table mapping type DIEs to their struct type *.
316 This is NULL if not allocated yet.
317 The mapping is done via (CU/TU + DIE offset) -> type. */
318 htab_t die_type_hash
;
320 /* The CUs we recently read. */
321 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
323 /* Table containing line_header indexed by offset and offset_in_dwz. */
324 htab_t line_header_hash
;
327 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
329 /* Default names of the debugging sections. */
331 /* Note that if the debugging section has been compressed, it might
332 have a name like .zdebug_info. */
334 static const struct dwarf2_debug_sections dwarf2_elf_names
=
336 { ".debug_info", ".zdebug_info" },
337 { ".debug_abbrev", ".zdebug_abbrev" },
338 { ".debug_line", ".zdebug_line" },
339 { ".debug_loc", ".zdebug_loc" },
340 { ".debug_loclists", ".zdebug_loclists" },
341 { ".debug_macinfo", ".zdebug_macinfo" },
342 { ".debug_macro", ".zdebug_macro" },
343 { ".debug_str", ".zdebug_str" },
344 { ".debug_line_str", ".zdebug_line_str" },
345 { ".debug_ranges", ".zdebug_ranges" },
346 { ".debug_rnglists", ".zdebug_rnglists" },
347 { ".debug_types", ".zdebug_types" },
348 { ".debug_addr", ".zdebug_addr" },
349 { ".debug_frame", ".zdebug_frame" },
350 { ".eh_frame", NULL
},
351 { ".gdb_index", ".zgdb_index" },
355 /* List of DWO/DWP sections. */
357 static const struct dwop_section_names
359 struct dwarf2_section_names abbrev_dwo
;
360 struct dwarf2_section_names info_dwo
;
361 struct dwarf2_section_names line_dwo
;
362 struct dwarf2_section_names loc_dwo
;
363 struct dwarf2_section_names loclists_dwo
;
364 struct dwarf2_section_names macinfo_dwo
;
365 struct dwarf2_section_names macro_dwo
;
366 struct dwarf2_section_names str_dwo
;
367 struct dwarf2_section_names str_offsets_dwo
;
368 struct dwarf2_section_names types_dwo
;
369 struct dwarf2_section_names cu_index
;
370 struct dwarf2_section_names tu_index
;
374 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
375 { ".debug_info.dwo", ".zdebug_info.dwo" },
376 { ".debug_line.dwo", ".zdebug_line.dwo" },
377 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
378 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
379 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
380 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
381 { ".debug_str.dwo", ".zdebug_str.dwo" },
382 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
383 { ".debug_types.dwo", ".zdebug_types.dwo" },
384 { ".debug_cu_index", ".zdebug_cu_index" },
385 { ".debug_tu_index", ".zdebug_tu_index" },
388 /* local data types */
390 /* The data in a compilation unit header, after target2host
391 translation, looks like this. */
392 struct comp_unit_head
396 unsigned char addr_size
;
397 unsigned char signed_addr_p
;
398 sect_offset abbrev_offset
;
400 /* Size of file offsets; either 4 or 8. */
401 unsigned int offset_size
;
403 /* Size of the length field; either 4 or 12. */
404 unsigned int initial_length_size
;
406 enum dwarf_unit_type unit_type
;
408 /* Offset to the first byte of this compilation unit header in the
409 .debug_info section, for resolving relative reference dies. */
412 /* Offset to first die in this cu from the start of the cu.
413 This will be the first byte following the compilation unit header. */
414 cu_offset first_die_offset
;
416 /* 64-bit signature of this type unit - it is valid only for
417 UNIT_TYPE DW_UT_type. */
420 /* For types, offset in the type's DIE of the type defined by this TU. */
421 cu_offset type_offset_in_tu
;
424 /* Type used for delaying computation of method physnames.
425 See comments for compute_delayed_physnames. */
426 struct delayed_method_info
428 /* The type to which the method is attached, i.e., its parent class. */
431 /* The index of the method in the type's function fieldlists. */
434 /* The index of the method in the fieldlist. */
437 /* The name of the DIE. */
440 /* The DIE associated with this method. */
441 struct die_info
*die
;
444 typedef struct delayed_method_info delayed_method_info
;
445 DEF_VEC_O (delayed_method_info
);
447 /* Internal state when decoding a particular compilation unit. */
450 /* The objfile containing this compilation unit. */
451 struct objfile
*objfile
;
453 /* The header of the compilation unit. */
454 struct comp_unit_head header
;
456 /* Base address of this compilation unit. */
457 CORE_ADDR base_address
;
459 /* Non-zero if base_address has been set. */
462 /* The language we are debugging. */
463 enum language language
;
464 const struct language_defn
*language_defn
;
466 const char *producer
;
468 /* The generic symbol table building routines have separate lists for
469 file scope symbols and all all other scopes (local scopes). So
470 we need to select the right one to pass to add_symbol_to_list().
471 We do it by keeping a pointer to the correct list in list_in_scope.
473 FIXME: The original dwarf code just treated the file scope as the
474 first local scope, and all other local scopes as nested local
475 scopes, and worked fine. Check to see if we really need to
476 distinguish these in buildsym.c. */
477 struct pending
**list_in_scope
;
479 /* The abbrev table for this CU.
480 Normally this points to the abbrev table in the objfile.
481 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
482 struct abbrev_table
*abbrev_table
;
484 /* Hash table holding all the loaded partial DIEs
485 with partial_die->offset.SECT_OFF as hash. */
488 /* Storage for things with the same lifetime as this read-in compilation
489 unit, including partial DIEs. */
490 struct obstack comp_unit_obstack
;
492 /* When multiple dwarf2_cu structures are living in memory, this field
493 chains them all together, so that they can be released efficiently.
494 We will probably also want a generation counter so that most-recently-used
495 compilation units are cached... */
496 struct dwarf2_per_cu_data
*read_in_chain
;
498 /* Backlink to our per_cu entry. */
499 struct dwarf2_per_cu_data
*per_cu
;
501 /* How many compilation units ago was this CU last referenced? */
504 /* A hash table of DIE cu_offset for following references with
505 die_info->offset.sect_off as hash. */
508 /* Full DIEs if read in. */
509 struct die_info
*dies
;
511 /* A set of pointers to dwarf2_per_cu_data objects for compilation
512 units referenced by this one. Only set during full symbol processing;
513 partial symbol tables do not have dependencies. */
516 /* Header data from the line table, during full symbol processing. */
517 struct line_header
*line_header
;
519 /* A list of methods which need to have physnames computed
520 after all type information has been read. */
521 VEC (delayed_method_info
) *method_list
;
523 /* To be copied to symtab->call_site_htab. */
524 htab_t call_site_htab
;
526 /* Non-NULL if this CU came from a DWO file.
527 There is an invariant here that is important to remember:
528 Except for attributes copied from the top level DIE in the "main"
529 (or "stub") file in preparation for reading the DWO file
530 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
531 Either there isn't a DWO file (in which case this is NULL and the point
532 is moot), or there is and either we're not going to read it (in which
533 case this is NULL) or there is and we are reading it (in which case this
535 struct dwo_unit
*dwo_unit
;
537 /* The DW_AT_addr_base attribute if present, zero otherwise
538 (zero is a valid value though).
539 Note this value comes from the Fission stub CU/TU's DIE. */
542 /* The DW_AT_ranges_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.
545 Also note that the value is zero in the non-DWO case so this value can
546 be used without needing to know whether DWO files are in use or not.
547 N.B. This does not apply to DW_AT_ranges appearing in
548 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
549 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
550 DW_AT_ranges_base *would* have to be applied, and we'd have to care
551 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
552 ULONGEST ranges_base
;
554 /* Mark used when releasing cached dies. */
555 unsigned int mark
: 1;
557 /* This CU references .debug_loc. See the symtab->locations_valid field.
558 This test is imperfect as there may exist optimized debug code not using
559 any location list and still facing inlining issues if handled as
560 unoptimized code. For a future better test see GCC PR other/32998. */
561 unsigned int has_loclist
: 1;
563 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
564 if all the producer_is_* fields are valid. This information is cached
565 because profiling CU expansion showed excessive time spent in
566 producer_is_gxx_lt_4_6. */
567 unsigned int checked_producer
: 1;
568 unsigned int producer_is_gxx_lt_4_6
: 1;
569 unsigned int producer_is_gcc_lt_4_3
: 1;
570 unsigned int producer_is_icc
: 1;
572 /* When set, the file that we're processing is known to have
573 debugging info for C++ namespaces. GCC 3.3.x did not produce
574 this information, but later versions do. */
576 unsigned int processing_has_namespace_info
: 1;
579 /* Persistent data held for a compilation unit, even when not
580 processing it. We put a pointer to this structure in the
581 read_symtab_private field of the psymtab. */
583 struct dwarf2_per_cu_data
585 /* The start offset and length of this compilation unit.
586 NOTE: Unlike comp_unit_head.length, this length includes
588 If the DIE refers to a DWO file, this is always of the original die,
593 /* DWARF standard version this data has been read from (such as 4 or 5). */
596 /* Flag indicating this compilation unit will be read in before
597 any of the current compilation units are processed. */
598 unsigned int queued
: 1;
600 /* This flag will be set when reading partial DIEs if we need to load
601 absolutely all DIEs for this compilation unit, instead of just the ones
602 we think are interesting. It gets set if we look for a DIE in the
603 hash table and don't find it. */
604 unsigned int load_all_dies
: 1;
606 /* Non-zero if this CU is from .debug_types.
607 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
609 unsigned int is_debug_types
: 1;
611 /* Non-zero if this CU is from the .dwz file. */
612 unsigned int is_dwz
: 1;
614 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
615 This flag is only valid if is_debug_types is true.
616 We can't read a CU directly from a DWO file: There are required
617 attributes in the stub. */
618 unsigned int reading_dwo_directly
: 1;
620 /* Non-zero if the TU has been read.
621 This is used to assist the "Stay in DWO Optimization" for Fission:
622 When reading a DWO, it's faster to read TUs from the DWO instead of
623 fetching them from random other DWOs (due to comdat folding).
624 If the TU has already been read, the optimization is unnecessary
625 (and unwise - we don't want to change where gdb thinks the TU lives
627 This flag is only valid if is_debug_types is true. */
628 unsigned int tu_read
: 1;
630 /* The section this CU/TU lives in.
631 If the DIE refers to a DWO file, this is always the original die,
633 struct dwarf2_section_info
*section
;
635 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
636 of the CU cache it gets reset to NULL again. This is left as NULL for
637 dummy CUs (a CU header, but nothing else). */
638 struct dwarf2_cu
*cu
;
640 /* The corresponding objfile.
641 Normally we can get the objfile from dwarf2_per_objfile.
642 However we can enter this file with just a "per_cu" handle. */
643 struct objfile
*objfile
;
645 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
646 is active. Otherwise, the 'psymtab' field is active. */
649 /* The partial symbol table associated with this compilation unit,
650 or NULL for unread partial units. */
651 struct partial_symtab
*psymtab
;
653 /* Data needed by the "quick" functions. */
654 struct dwarf2_per_cu_quick_data
*quick
;
657 /* The CUs we import using DW_TAG_imported_unit. This is filled in
658 while reading psymtabs, used to compute the psymtab dependencies,
659 and then cleared. Then it is filled in again while reading full
660 symbols, and only deleted when the objfile is destroyed.
662 This is also used to work around a difference between the way gold
663 generates .gdb_index version <=7 and the way gdb does. Arguably this
664 is a gold bug. For symbols coming from TUs, gold records in the index
665 the CU that includes the TU instead of the TU itself. This breaks
666 dw2_lookup_symbol: It assumes that if the index says symbol X lives
667 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
668 will find X. Alas TUs live in their own symtab, so after expanding CU Y
669 we need to look in TU Z to find X. Fortunately, this is akin to
670 DW_TAG_imported_unit, so we just use the same mechanism: For
671 .gdb_index version <=7 this also records the TUs that the CU referred
672 to. Concurrently with this change gdb was modified to emit version 8
673 indices so we only pay a price for gold generated indices.
674 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
675 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
678 /* Entry in the signatured_types hash table. */
680 struct signatured_type
682 /* The "per_cu" object of this type.
683 This struct is used iff per_cu.is_debug_types.
684 N.B.: This is the first member so that it's easy to convert pointers
686 struct dwarf2_per_cu_data per_cu
;
688 /* The type's signature. */
691 /* Offset in the TU of the type's DIE, as read from the TU header.
692 If this TU is a DWO stub and the definition lives in a DWO file
693 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
694 cu_offset type_offset_in_tu
;
696 /* Offset in the section of the type's DIE.
697 If the definition lives in a DWO file, this is the offset in the
698 .debug_types.dwo section.
699 The value is zero until the actual value is known.
700 Zero is otherwise not a valid section offset. */
701 sect_offset type_offset_in_section
;
703 /* Type units are grouped by their DW_AT_stmt_list entry so that they
704 can share them. This points to the containing symtab. */
705 struct type_unit_group
*type_unit_group
;
708 The first time we encounter this type we fully read it in and install it
709 in the symbol tables. Subsequent times we only need the type. */
712 /* Containing DWO unit.
713 This field is valid iff per_cu.reading_dwo_directly. */
714 struct dwo_unit
*dwo_unit
;
717 typedef struct signatured_type
*sig_type_ptr
;
718 DEF_VEC_P (sig_type_ptr
);
720 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
721 This includes type_unit_group and quick_file_names. */
723 struct stmt_list_hash
725 /* The DWO unit this table is from or NULL if there is none. */
726 struct dwo_unit
*dwo_unit
;
728 /* Offset in .debug_line or .debug_line.dwo. */
729 sect_offset line_offset
;
732 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
733 an object of this type. */
735 struct type_unit_group
737 /* dwarf2read.c's main "handle" on a TU symtab.
738 To simplify things we create an artificial CU that "includes" all the
739 type units using this stmt_list so that the rest of the code still has
740 a "per_cu" handle on the symtab.
741 This PER_CU is recognized by having no section. */
742 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
743 struct dwarf2_per_cu_data per_cu
;
745 /* The TUs that share this DW_AT_stmt_list entry.
746 This is added to while parsing type units to build partial symtabs,
747 and is deleted afterwards and not used again. */
748 VEC (sig_type_ptr
) *tus
;
750 /* The compunit symtab.
751 Type units in a group needn't all be defined in the same source file,
752 so we create an essentially anonymous symtab as the compunit symtab. */
753 struct compunit_symtab
*compunit_symtab
;
755 /* The data used to construct the hash key. */
756 struct stmt_list_hash hash
;
758 /* The number of symtabs from the line header.
759 The value here must match line_header.num_file_names. */
760 unsigned int num_symtabs
;
762 /* The symbol tables for this TU (obtained from the files listed in
764 WARNING: The order of entries here must match the order of entries
765 in the line header. After the first TU using this type_unit_group, the
766 line header for the subsequent TUs is recreated from this. This is done
767 because we need to use the same symtabs for each TU using the same
768 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
769 there's no guarantee the line header doesn't have duplicate entries. */
770 struct symtab
**symtabs
;
773 /* These sections are what may appear in a (real or virtual) DWO file. */
777 struct dwarf2_section_info abbrev
;
778 struct dwarf2_section_info line
;
779 struct dwarf2_section_info loc
;
780 struct dwarf2_section_info loclists
;
781 struct dwarf2_section_info macinfo
;
782 struct dwarf2_section_info macro
;
783 struct dwarf2_section_info str
;
784 struct dwarf2_section_info str_offsets
;
785 /* In the case of a virtual DWO file, these two are unused. */
786 struct dwarf2_section_info info
;
787 VEC (dwarf2_section_info_def
) *types
;
790 /* CUs/TUs in DWP/DWO files. */
794 /* Backlink to the containing struct dwo_file. */
795 struct dwo_file
*dwo_file
;
797 /* The "id" that distinguishes this CU/TU.
798 .debug_info calls this "dwo_id", .debug_types calls this "signature".
799 Since signatures came first, we stick with it for consistency. */
802 /* The section this CU/TU lives in, in the DWO file. */
803 struct dwarf2_section_info
*section
;
805 /* Same as dwarf2_per_cu_data:{offset,length} but in the DWO section. */
809 /* For types, offset in the type's DIE of the type defined by this TU. */
810 cu_offset type_offset_in_tu
;
813 /* include/dwarf2.h defines the DWP section codes.
814 It defines a max value but it doesn't define a min value, which we
815 use for error checking, so provide one. */
817 enum dwp_v2_section_ids
822 /* Data for one DWO file.
824 This includes virtual DWO files (a virtual DWO file is a DWO file as it
825 appears in a DWP file). DWP files don't really have DWO files per se -
826 comdat folding of types "loses" the DWO file they came from, and from
827 a high level view DWP files appear to contain a mass of random types.
828 However, to maintain consistency with the non-DWP case we pretend DWP
829 files contain virtual DWO files, and we assign each TU with one virtual
830 DWO file (generally based on the line and abbrev section offsets -
831 a heuristic that seems to work in practice). */
835 /* The DW_AT_GNU_dwo_name attribute.
836 For virtual DWO files the name is constructed from the section offsets
837 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
838 from related CU+TUs. */
839 const char *dwo_name
;
841 /* The DW_AT_comp_dir attribute. */
842 const char *comp_dir
;
844 /* The bfd, when the file is open. Otherwise this is NULL.
845 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
848 /* The sections that make up this DWO file.
849 Remember that for virtual DWO files in DWP V2, these are virtual
850 sections (for lack of a better name). */
851 struct dwo_sections sections
;
853 /* The CU in the file.
854 We only support one because having more than one requires hacking the
855 dwo_name of each to match, which is highly unlikely to happen.
856 Doing this means all TUs can share comp_dir: We also assume that
857 DW_AT_comp_dir across all TUs in a DWO file will be identical. */
860 /* Table of TUs in the file.
861 Each element is a struct dwo_unit. */
865 /* These sections are what may appear in a DWP file. */
869 /* These are used by both DWP version 1 and 2. */
870 struct dwarf2_section_info str
;
871 struct dwarf2_section_info cu_index
;
872 struct dwarf2_section_info tu_index
;
874 /* These are only used by DWP version 2 files.
875 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
876 sections are referenced by section number, and are not recorded here.
877 In DWP version 2 there is at most one copy of all these sections, each
878 section being (effectively) comprised of the concatenation of all of the
879 individual sections that exist in the version 1 format.
880 To keep the code simple we treat each of these concatenated pieces as a
881 section itself (a virtual section?). */
882 struct dwarf2_section_info abbrev
;
883 struct dwarf2_section_info info
;
884 struct dwarf2_section_info line
;
885 struct dwarf2_section_info loc
;
886 struct dwarf2_section_info macinfo
;
887 struct dwarf2_section_info macro
;
888 struct dwarf2_section_info str_offsets
;
889 struct dwarf2_section_info types
;
892 /* These sections are what may appear in a virtual DWO file in DWP version 1.
893 A virtual DWO file is a DWO file as it appears in a DWP file. */
895 struct virtual_v1_dwo_sections
897 struct dwarf2_section_info abbrev
;
898 struct dwarf2_section_info line
;
899 struct dwarf2_section_info loc
;
900 struct dwarf2_section_info macinfo
;
901 struct dwarf2_section_info macro
;
902 struct dwarf2_section_info str_offsets
;
903 /* Each DWP hash table entry records one CU or one TU.
904 That is recorded here, and copied to dwo_unit.section. */
905 struct dwarf2_section_info info_or_types
;
908 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
909 In version 2, the sections of the DWO files are concatenated together
910 and stored in one section of that name. Thus each ELF section contains
911 several "virtual" sections. */
913 struct virtual_v2_dwo_sections
915 bfd_size_type abbrev_offset
;
916 bfd_size_type abbrev_size
;
918 bfd_size_type line_offset
;
919 bfd_size_type line_size
;
921 bfd_size_type loc_offset
;
922 bfd_size_type loc_size
;
924 bfd_size_type macinfo_offset
;
925 bfd_size_type macinfo_size
;
927 bfd_size_type macro_offset
;
928 bfd_size_type macro_size
;
930 bfd_size_type str_offsets_offset
;
931 bfd_size_type str_offsets_size
;
933 /* Each DWP hash table entry records one CU or one TU.
934 That is recorded here, and copied to dwo_unit.section. */
935 bfd_size_type info_or_types_offset
;
936 bfd_size_type info_or_types_size
;
939 /* Contents of DWP hash tables. */
941 struct dwp_hash_table
943 uint32_t version
, nr_columns
;
944 uint32_t nr_units
, nr_slots
;
945 const gdb_byte
*hash_table
, *unit_table
;
950 const gdb_byte
*indices
;
954 /* This is indexed by column number and gives the id of the section
956 #define MAX_NR_V2_DWO_SECTIONS \
957 (1 /* .debug_info or .debug_types */ \
958 + 1 /* .debug_abbrev */ \
959 + 1 /* .debug_line */ \
960 + 1 /* .debug_loc */ \
961 + 1 /* .debug_str_offsets */ \
962 + 1 /* .debug_macro or .debug_macinfo */)
963 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
964 const gdb_byte
*offsets
;
965 const gdb_byte
*sizes
;
970 /* Data for one DWP file. */
974 /* Name of the file. */
977 /* File format version. */
983 /* Section info for this file. */
984 struct dwp_sections sections
;
986 /* Table of CUs in the file. */
987 const struct dwp_hash_table
*cus
;
989 /* Table of TUs in the file. */
990 const struct dwp_hash_table
*tus
;
992 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
996 /* Table to map ELF section numbers to their sections.
997 This is only needed for the DWP V1 file format. */
998 unsigned int num_sections
;
999 asection
**elf_sections
;
1002 /* This represents a '.dwz' file. */
1006 /* A dwz file can only contain a few sections. */
1007 struct dwarf2_section_info abbrev
;
1008 struct dwarf2_section_info info
;
1009 struct dwarf2_section_info str
;
1010 struct dwarf2_section_info line
;
1011 struct dwarf2_section_info macro
;
1012 struct dwarf2_section_info gdb_index
;
1014 /* The dwz's BFD. */
1018 /* Struct used to pass misc. parameters to read_die_and_children, et
1019 al. which are used for both .debug_info and .debug_types dies.
1020 All parameters here are unchanging for the life of the call. This
1021 struct exists to abstract away the constant parameters of die reading. */
1023 struct die_reader_specs
1025 /* The bfd of die_section. */
1028 /* The CU of the DIE we are parsing. */
1029 struct dwarf2_cu
*cu
;
1031 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1032 struct dwo_file
*dwo_file
;
1034 /* The section the die comes from.
1035 This is either .debug_info or .debug_types, or the .dwo variants. */
1036 struct dwarf2_section_info
*die_section
;
1038 /* die_section->buffer. */
1039 const gdb_byte
*buffer
;
1041 /* The end of the buffer. */
1042 const gdb_byte
*buffer_end
;
1044 /* The value of the DW_AT_comp_dir attribute. */
1045 const char *comp_dir
;
1048 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1049 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1050 const gdb_byte
*info_ptr
,
1051 struct die_info
*comp_unit_die
,
1058 unsigned int dir_index
;
1059 unsigned int mod_time
;
1060 unsigned int length
;
1061 /* Non-zero if referenced by the Line Number Program. */
1063 /* The associated symbol table, if any. */
1064 struct symtab
*symtab
;
1067 /* The line number information for a compilation unit (found in the
1068 .debug_line section) begins with a "statement program header",
1069 which contains the following information. */
1072 /* Offset of line number information in .debug_line section. */
1075 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1076 unsigned offset_in_dwz
: 1;
1078 unsigned int total_length
;
1079 unsigned short version
;
1080 unsigned int header_length
;
1081 unsigned char minimum_instruction_length
;
1082 unsigned char maximum_ops_per_instruction
;
1083 unsigned char default_is_stmt
;
1085 unsigned char line_range
;
1086 unsigned char opcode_base
;
1088 /* standard_opcode_lengths[i] is the number of operands for the
1089 standard opcode whose value is i. This means that
1090 standard_opcode_lengths[0] is unused, and the last meaningful
1091 element is standard_opcode_lengths[opcode_base - 1]. */
1092 unsigned char *standard_opcode_lengths
;
1094 /* The include_directories table. NOTE! These strings are not
1095 allocated with xmalloc; instead, they are pointers into
1096 debug_line_buffer. If you try to free them, `free' will get
1098 unsigned int num_include_dirs
, include_dirs_size
;
1099 const char **include_dirs
;
1101 /* The file_names table. NOTE! These strings are not allocated
1102 with xmalloc; instead, they are pointers into debug_line_buffer.
1103 Don't try to free them directly. */
1104 unsigned int num_file_names
, file_names_size
;
1105 struct file_entry
*file_names
;
1107 /* The start and end of the statement program following this
1108 header. These point into dwarf2_per_objfile->line_buffer. */
1109 const gdb_byte
*statement_program_start
, *statement_program_end
;
1112 /* When we construct a partial symbol table entry we only
1113 need this much information. */
1114 struct partial_die_info
1116 /* Offset of this DIE. */
1119 /* DWARF-2 tag for this DIE. */
1120 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1122 /* Assorted flags describing the data found in this DIE. */
1123 unsigned int has_children
: 1;
1124 unsigned int is_external
: 1;
1125 unsigned int is_declaration
: 1;
1126 unsigned int has_type
: 1;
1127 unsigned int has_specification
: 1;
1128 unsigned int has_pc_info
: 1;
1129 unsigned int may_be_inlined
: 1;
1131 /* This DIE has been marked DW_AT_main_subprogram. */
1132 unsigned int main_subprogram
: 1;
1134 /* Flag set if the SCOPE field of this structure has been
1136 unsigned int scope_set
: 1;
1138 /* Flag set if the DIE has a byte_size attribute. */
1139 unsigned int has_byte_size
: 1;
1141 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1142 unsigned int has_const_value
: 1;
1144 /* Flag set if any of the DIE's children are template arguments. */
1145 unsigned int has_template_arguments
: 1;
1147 /* Flag set if fixup_partial_die has been called on this die. */
1148 unsigned int fixup_called
: 1;
1150 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1151 unsigned int is_dwz
: 1;
1153 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1154 unsigned int spec_is_dwz
: 1;
1156 /* The name of this DIE. Normally the value of DW_AT_name, but
1157 sometimes a default name for unnamed DIEs. */
1160 /* The linkage name, if present. */
1161 const char *linkage_name
;
1163 /* The scope to prepend to our children. This is generally
1164 allocated on the comp_unit_obstack, so will disappear
1165 when this compilation unit leaves the cache. */
1168 /* Some data associated with the partial DIE. The tag determines
1169 which field is live. */
1172 /* The location description associated with this DIE, if any. */
1173 struct dwarf_block
*locdesc
;
1174 /* The offset of an import, for DW_TAG_imported_unit. */
1178 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1182 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1183 DW_AT_sibling, if any. */
1184 /* NOTE: This member isn't strictly necessary, read_partial_die could
1185 return DW_AT_sibling values to its caller load_partial_dies. */
1186 const gdb_byte
*sibling
;
1188 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1189 DW_AT_specification (or DW_AT_abstract_origin or
1190 DW_AT_extension). */
1191 sect_offset spec_offset
;
1193 /* Pointers to this DIE's parent, first child, and next sibling,
1195 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
1198 /* This data structure holds the information of an abbrev. */
1201 unsigned int number
; /* number identifying abbrev */
1202 enum dwarf_tag tag
; /* dwarf tag */
1203 unsigned short has_children
; /* boolean */
1204 unsigned short num_attrs
; /* number of attributes */
1205 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1206 struct abbrev_info
*next
; /* next in chain */
1211 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1212 ENUM_BITFIELD(dwarf_form
) form
: 16;
1214 /* It is valid only if FORM is DW_FORM_implicit_const. */
1215 LONGEST implicit_const
;
1218 /* Size of abbrev_table.abbrev_hash_table. */
1219 #define ABBREV_HASH_SIZE 121
1221 /* Top level data structure to contain an abbreviation table. */
1225 /* Where the abbrev table came from.
1226 This is used as a sanity check when the table is used. */
1229 /* Storage for the abbrev table. */
1230 struct obstack abbrev_obstack
;
1232 /* Hash table of abbrevs.
1233 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1234 It could be statically allocated, but the previous code didn't so we
1236 struct abbrev_info
**abbrevs
;
1239 /* Attributes have a name and a value. */
1242 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1243 ENUM_BITFIELD(dwarf_form
) form
: 15;
1245 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1246 field should be in u.str (existing only for DW_STRING) but it is kept
1247 here for better struct attribute alignment. */
1248 unsigned int string_is_canonical
: 1;
1253 struct dwarf_block
*blk
;
1262 /* This data structure holds a complete die structure. */
1265 /* DWARF-2 tag for this DIE. */
1266 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1268 /* Number of attributes */
1269 unsigned char num_attrs
;
1271 /* True if we're presently building the full type name for the
1272 type derived from this DIE. */
1273 unsigned char building_fullname
: 1;
1275 /* True if this die is in process. PR 16581. */
1276 unsigned char in_process
: 1;
1279 unsigned int abbrev
;
1281 /* Offset in .debug_info or .debug_types section. */
1284 /* The dies in a compilation unit form an n-ary tree. PARENT
1285 points to this die's parent; CHILD points to the first child of
1286 this node; and all the children of a given node are chained
1287 together via their SIBLING fields. */
1288 struct die_info
*child
; /* Its first child, if any. */
1289 struct die_info
*sibling
; /* Its next sibling, if any. */
1290 struct die_info
*parent
; /* Its parent, if any. */
1292 /* An array of attributes, with NUM_ATTRS elements. There may be
1293 zero, but it's not common and zero-sized arrays are not
1294 sufficiently portable C. */
1295 struct attribute attrs
[1];
1298 /* Get at parts of an attribute structure. */
1300 #define DW_STRING(attr) ((attr)->u.str)
1301 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1302 #define DW_UNSND(attr) ((attr)->u.unsnd)
1303 #define DW_BLOCK(attr) ((attr)->u.blk)
1304 #define DW_SND(attr) ((attr)->u.snd)
1305 #define DW_ADDR(attr) ((attr)->u.addr)
1306 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1308 /* Blocks are a bunch of untyped bytes. */
1313 /* Valid only if SIZE is not zero. */
1314 const gdb_byte
*data
;
1317 #ifndef ATTR_ALLOC_CHUNK
1318 #define ATTR_ALLOC_CHUNK 4
1321 /* Allocate fields for structs, unions and enums in this size. */
1322 #ifndef DW_FIELD_ALLOC_CHUNK
1323 #define DW_FIELD_ALLOC_CHUNK 4
1326 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1327 but this would require a corresponding change in unpack_field_as_long
1329 static int bits_per_byte
= 8;
1333 struct nextfield
*next
;
1341 struct nextfnfield
*next
;
1342 struct fn_field fnfield
;
1349 struct nextfnfield
*head
;
1352 struct typedef_field_list
1354 struct typedef_field field
;
1355 struct typedef_field_list
*next
;
1358 /* The routines that read and process dies for a C struct or C++ class
1359 pass lists of data member fields and lists of member function fields
1360 in an instance of a field_info structure, as defined below. */
1363 /* List of data member and baseclasses fields. */
1364 struct nextfield
*fields
, *baseclasses
;
1366 /* Number of fields (including baseclasses). */
1369 /* Number of baseclasses. */
1372 /* Set if the accesibility of one of the fields is not public. */
1373 int non_public_fields
;
1375 /* Member function fields array, entries are allocated in the order they
1376 are encountered in the object file. */
1377 struct nextfnfield
*fnfields
;
1379 /* Member function fieldlist array, contains name of possibly overloaded
1380 member function, number of overloaded member functions and a pointer
1381 to the head of the member function field chain. */
1382 struct fnfieldlist
*fnfieldlists
;
1384 /* Number of entries in the fnfieldlists array. */
1387 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1388 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1389 struct typedef_field_list
*typedef_field_list
;
1390 unsigned typedef_field_list_count
;
1393 /* One item on the queue of compilation units to read in full symbols
1395 struct dwarf2_queue_item
1397 struct dwarf2_per_cu_data
*per_cu
;
1398 enum language pretend_language
;
1399 struct dwarf2_queue_item
*next
;
1402 /* The current queue. */
1403 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1405 /* Loaded secondary compilation units are kept in memory until they
1406 have not been referenced for the processing of this many
1407 compilation units. Set this to zero to disable caching. Cache
1408 sizes of up to at least twenty will improve startup time for
1409 typical inter-CU-reference binaries, at an obvious memory cost. */
1410 static int dwarf_max_cache_age
= 5;
1412 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1413 struct cmd_list_element
*c
, const char *value
)
1415 fprintf_filtered (file
, _("The upper bound on the age of cached "
1416 "DWARF compilation units is %s.\n"),
1420 /* local function prototypes */
1422 static const char *get_section_name (const struct dwarf2_section_info
*);
1424 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1426 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1428 static void dwarf2_find_base_address (struct die_info
*die
,
1429 struct dwarf2_cu
*cu
);
1431 static struct partial_symtab
*create_partial_symtab
1432 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1434 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1436 static void scan_partial_symbols (struct partial_die_info
*,
1437 CORE_ADDR
*, CORE_ADDR
*,
1438 int, struct dwarf2_cu
*);
1440 static void add_partial_symbol (struct partial_die_info
*,
1441 struct dwarf2_cu
*);
1443 static void add_partial_namespace (struct partial_die_info
*pdi
,
1444 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1445 int set_addrmap
, struct dwarf2_cu
*cu
);
1447 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1448 CORE_ADDR
*highpc
, int set_addrmap
,
1449 struct dwarf2_cu
*cu
);
1451 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1452 struct dwarf2_cu
*cu
);
1454 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1455 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1456 int need_pc
, struct dwarf2_cu
*cu
);
1458 static void dwarf2_read_symtab (struct partial_symtab
*,
1461 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1463 static struct abbrev_info
*abbrev_table_lookup_abbrev
1464 (const struct abbrev_table
*, unsigned int);
1466 static struct abbrev_table
*abbrev_table_read_table
1467 (struct dwarf2_section_info
*, sect_offset
);
1469 static void abbrev_table_free (struct abbrev_table
*);
1471 static void abbrev_table_free_cleanup (void *);
1473 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1474 struct dwarf2_section_info
*);
1476 static void dwarf2_free_abbrev_table (void *);
1478 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1480 static struct partial_die_info
*load_partial_dies
1481 (const struct die_reader_specs
*, const gdb_byte
*, int);
1483 static const gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1484 struct partial_die_info
*,
1485 struct abbrev_info
*,
1489 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1490 struct dwarf2_cu
*);
1492 static void fixup_partial_die (struct partial_die_info
*,
1493 struct dwarf2_cu
*);
1495 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1496 struct attribute
*, struct attr_abbrev
*,
1499 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1501 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1503 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1505 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1507 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1509 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1512 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1514 static LONGEST read_checked_initial_length_and_offset
1515 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1516 unsigned int *, unsigned int *);
1518 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1519 const struct comp_unit_head
*,
1522 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1524 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1527 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1529 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1531 static const char *read_indirect_string (bfd
*, const gdb_byte
*,
1532 const struct comp_unit_head
*,
1535 static const char *read_indirect_line_string (bfd
*, const gdb_byte
*,
1536 const struct comp_unit_head
*,
1539 static const char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1541 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1543 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1547 static const char *read_str_index (const struct die_reader_specs
*reader
,
1548 ULONGEST str_index
);
1550 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1552 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1553 struct dwarf2_cu
*);
1555 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1558 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1559 struct dwarf2_cu
*cu
);
1561 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1562 struct dwarf2_cu
*cu
);
1564 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1566 static struct die_info
*die_specification (struct die_info
*die
,
1567 struct dwarf2_cu
**);
1569 static void free_line_header (struct line_header
*lh
);
1571 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1572 struct dwarf2_cu
*cu
);
1574 static void dwarf_decode_lines (struct line_header
*, const char *,
1575 struct dwarf2_cu
*, struct partial_symtab
*,
1576 CORE_ADDR
, int decode_mapping
);
1578 static void dwarf2_start_subfile (const char *, const char *);
1580 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1581 const char *, const char *,
1584 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1585 struct dwarf2_cu
*);
1587 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1588 struct dwarf2_cu
*, struct symbol
*);
1590 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1591 struct dwarf2_cu
*);
1593 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1596 struct obstack
*obstack
,
1597 struct dwarf2_cu
*cu
, LONGEST
*value
,
1598 const gdb_byte
**bytes
,
1599 struct dwarf2_locexpr_baton
**baton
);
1601 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1603 static int need_gnat_info (struct dwarf2_cu
*);
1605 static struct type
*die_descriptive_type (struct die_info
*,
1606 struct dwarf2_cu
*);
1608 static void set_descriptive_type (struct type
*, struct die_info
*,
1609 struct dwarf2_cu
*);
1611 static struct type
*die_containing_type (struct die_info
*,
1612 struct dwarf2_cu
*);
1614 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1615 struct dwarf2_cu
*);
1617 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1619 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1621 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1623 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1624 const char *suffix
, int physname
,
1625 struct dwarf2_cu
*cu
);
1627 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1629 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1631 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1633 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1635 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1637 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1638 struct dwarf2_cu
*, struct partial_symtab
*);
1640 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1641 values. Keep the items ordered with increasing constraints compliance. */
1644 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1645 PC_BOUNDS_NOT_PRESENT
,
1647 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1648 were present but they do not form a valid range of PC addresses. */
1651 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1654 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1658 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1659 CORE_ADDR
*, CORE_ADDR
*,
1661 struct partial_symtab
*);
1663 static void get_scope_pc_bounds (struct die_info
*,
1664 CORE_ADDR
*, CORE_ADDR
*,
1665 struct dwarf2_cu
*);
1667 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1668 CORE_ADDR
, struct dwarf2_cu
*);
1670 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1671 struct dwarf2_cu
*);
1673 static void dwarf2_attach_fields_to_type (struct field_info
*,
1674 struct type
*, struct dwarf2_cu
*);
1676 static void dwarf2_add_member_fn (struct field_info
*,
1677 struct die_info
*, struct type
*,
1678 struct dwarf2_cu
*);
1680 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1682 struct dwarf2_cu
*);
1684 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1686 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1688 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1690 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1692 static struct using_direct
**using_directives (enum language
);
1694 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1696 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1698 static struct type
*read_module_type (struct die_info
*die
,
1699 struct dwarf2_cu
*cu
);
1701 static const char *namespace_name (struct die_info
*die
,
1702 int *is_anonymous
, struct dwarf2_cu
*);
1704 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1706 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1708 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1709 struct dwarf2_cu
*);
1711 static struct die_info
*read_die_and_siblings_1
1712 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1715 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1716 const gdb_byte
*info_ptr
,
1717 const gdb_byte
**new_info_ptr
,
1718 struct die_info
*parent
);
1720 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1721 struct die_info
**, const gdb_byte
*,
1724 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1725 struct die_info
**, const gdb_byte
*,
1728 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1730 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1733 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1735 static const char *dwarf2_full_name (const char *name
,
1736 struct die_info
*die
,
1737 struct dwarf2_cu
*cu
);
1739 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1740 struct dwarf2_cu
*cu
);
1742 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1743 struct dwarf2_cu
**);
1745 static const char *dwarf_tag_name (unsigned int);
1747 static const char *dwarf_attr_name (unsigned int);
1749 static const char *dwarf_form_name (unsigned int);
1751 static char *dwarf_bool_name (unsigned int);
1753 static const char *dwarf_type_encoding_name (unsigned int);
1755 static struct die_info
*sibling_die (struct die_info
*);
1757 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1759 static void dump_die_for_error (struct die_info
*);
1761 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1764 /*static*/ void dump_die (struct die_info
*, int max_level
);
1766 static void store_in_ref_table (struct die_info
*,
1767 struct dwarf2_cu
*);
1769 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1771 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1773 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1774 const struct attribute
*,
1775 struct dwarf2_cu
**);
1777 static struct die_info
*follow_die_ref (struct die_info
*,
1778 const struct attribute
*,
1779 struct dwarf2_cu
**);
1781 static struct die_info
*follow_die_sig (struct die_info
*,
1782 const struct attribute
*,
1783 struct dwarf2_cu
**);
1785 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1786 struct dwarf2_cu
*);
1788 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1789 const struct attribute
*,
1790 struct dwarf2_cu
*);
1792 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1794 static void read_signatured_type (struct signatured_type
*);
1796 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1797 struct die_info
*die
, struct dwarf2_cu
*cu
,
1798 struct dynamic_prop
*prop
);
1800 /* memory allocation interface */
1802 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1804 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1806 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1808 static int attr_form_is_block (const struct attribute
*);
1810 static int attr_form_is_section_offset (const struct attribute
*);
1812 static int attr_form_is_constant (const struct attribute
*);
1814 static int attr_form_is_ref (const struct attribute
*);
1816 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1817 struct dwarf2_loclist_baton
*baton
,
1818 const struct attribute
*attr
);
1820 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1822 struct dwarf2_cu
*cu
,
1825 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1826 const gdb_byte
*info_ptr
,
1827 struct abbrev_info
*abbrev
);
1829 static void free_stack_comp_unit (void *);
1831 static hashval_t
partial_die_hash (const void *item
);
1833 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1835 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1836 (sect_offset offset
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1838 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1839 struct dwarf2_per_cu_data
*per_cu
);
1841 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1842 struct die_info
*comp_unit_die
,
1843 enum language pretend_language
);
1845 static void free_heap_comp_unit (void *);
1847 static void free_cached_comp_units (void *);
1849 static void age_cached_comp_units (void);
1851 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1853 static struct type
*set_die_type (struct die_info
*, struct type
*,
1854 struct dwarf2_cu
*);
1856 static void create_all_comp_units (struct objfile
*);
1858 static int create_all_type_units (struct objfile
*);
1860 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1863 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1866 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1869 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1870 struct dwarf2_per_cu_data
*);
1872 static void dwarf2_mark (struct dwarf2_cu
*);
1874 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1876 static struct type
*get_die_type_at_offset (sect_offset
,
1877 struct dwarf2_per_cu_data
*);
1879 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1881 static void dwarf2_release_queue (void *dummy
);
1883 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1884 enum language pretend_language
);
1886 static void process_queue (void);
1888 static void find_file_and_directory (struct die_info
*die
,
1889 struct dwarf2_cu
*cu
,
1890 const char **name
, const char **comp_dir
);
1892 static char *file_full_name (int file
, struct line_header
*lh
,
1893 const char *comp_dir
);
1895 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1896 enum class rcuh_kind
{ COMPILE
, TYPE
};
1898 static const gdb_byte
*read_and_check_comp_unit_head
1899 (struct comp_unit_head
*header
,
1900 struct dwarf2_section_info
*section
,
1901 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1902 rcuh_kind section_kind
);
1904 static void init_cutu_and_read_dies
1905 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1906 int use_existing_cu
, int keep
,
1907 die_reader_func_ftype
*die_reader_func
, void *data
);
1909 static void init_cutu_and_read_dies_simple
1910 (struct dwarf2_per_cu_data
*this_cu
,
1911 die_reader_func_ftype
*die_reader_func
, void *data
);
1913 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1915 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1917 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1918 (struct dwp_file
*dwp_file
, const char *comp_dir
,
1919 ULONGEST signature
, int is_debug_types
);
1921 static struct dwp_file
*get_dwp_file (void);
1923 static struct dwo_unit
*lookup_dwo_comp_unit
1924 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1926 static struct dwo_unit
*lookup_dwo_type_unit
1927 (struct signatured_type
*, const char *, const char *);
1929 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1931 static void free_dwo_file_cleanup (void *);
1933 static void process_cu_includes (void);
1935 static void check_producer (struct dwarf2_cu
*cu
);
1937 static void free_line_header_voidp (void *arg
);
1939 /* Various complaints about symbol reading that don't abort the process. */
1942 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1944 complaint (&symfile_complaints
,
1945 _("statement list doesn't fit in .debug_line section"));
1949 dwarf2_debug_line_missing_file_complaint (void)
1951 complaint (&symfile_complaints
,
1952 _(".debug_line section has line data without a file"));
1956 dwarf2_debug_line_missing_end_sequence_complaint (void)
1958 complaint (&symfile_complaints
,
1959 _(".debug_line section has line "
1960 "program sequence without an end"));
1964 dwarf2_complex_location_expr_complaint (void)
1966 complaint (&symfile_complaints
, _("location expression too complex"));
1970 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1973 complaint (&symfile_complaints
,
1974 _("const value length mismatch for '%s', got %d, expected %d"),
1979 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1981 complaint (&symfile_complaints
,
1982 _("debug info runs off end of %s section"
1984 get_section_name (section
),
1985 get_section_file_name (section
));
1989 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1991 complaint (&symfile_complaints
,
1992 _("macro debug info contains a "
1993 "malformed macro definition:\n`%s'"),
1998 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2000 complaint (&symfile_complaints
,
2001 _("invalid attribute class or form for '%s' in '%s'"),
2005 /* Hash function for line_header_hash. */
2008 line_header_hash (const struct line_header
*ofs
)
2010 return ofs
->offset
.sect_off
^ ofs
->offset_in_dwz
;
2013 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2016 line_header_hash_voidp (const void *item
)
2018 const struct line_header
*ofs
= (const struct line_header
*) item
;
2020 return line_header_hash (ofs
);
2023 /* Equality function for line_header_hash. */
2026 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2028 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2029 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2031 return (ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
2032 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2038 /* Convert VALUE between big- and little-endian. */
2040 byte_swap (offset_type value
)
2044 result
= (value
& 0xff) << 24;
2045 result
|= (value
& 0xff00) << 8;
2046 result
|= (value
& 0xff0000) >> 8;
2047 result
|= (value
& 0xff000000) >> 24;
2051 #define MAYBE_SWAP(V) byte_swap (V)
2054 #define MAYBE_SWAP(V) (V)
2055 #endif /* WORDS_BIGENDIAN */
2057 /* Read the given attribute value as an address, taking the attribute's
2058 form into account. */
2061 attr_value_as_address (struct attribute
*attr
)
2065 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2067 /* Aside from a few clearly defined exceptions, attributes that
2068 contain an address must always be in DW_FORM_addr form.
2069 Unfortunately, some compilers happen to be violating this
2070 requirement by encoding addresses using other forms, such
2071 as DW_FORM_data4 for example. For those broken compilers,
2072 we try to do our best, without any guarantee of success,
2073 to interpret the address correctly. It would also be nice
2074 to generate a complaint, but that would require us to maintain
2075 a list of legitimate cases where a non-address form is allowed,
2076 as well as update callers to pass in at least the CU's DWARF
2077 version. This is more overhead than what we're willing to
2078 expand for a pretty rare case. */
2079 addr
= DW_UNSND (attr
);
2082 addr
= DW_ADDR (attr
);
2087 /* The suffix for an index file. */
2088 #define INDEX_SUFFIX ".gdb-index"
2090 /* Try to locate the sections we need for DWARF 2 debugging
2091 information and return true if we have enough to do something.
2092 NAMES points to the dwarf2 section names, or is NULL if the standard
2093 ELF names are used. */
2096 dwarf2_has_info (struct objfile
*objfile
,
2097 const struct dwarf2_debug_sections
*names
)
2099 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
2100 objfile_data (objfile
, dwarf2_objfile_data_key
));
2101 if (!dwarf2_per_objfile
)
2103 /* Initialize per-objfile state. */
2104 struct dwarf2_per_objfile
*data
2105 = XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_objfile
);
2107 memset (data
, 0, sizeof (*data
));
2108 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
2109 dwarf2_per_objfile
= data
;
2111 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
2113 dwarf2_per_objfile
->objfile
= objfile
;
2115 return (!dwarf2_per_objfile
->info
.is_virtual
2116 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2117 && !dwarf2_per_objfile
->abbrev
.is_virtual
2118 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2121 /* Return the containing section of virtual section SECTION. */
2123 static struct dwarf2_section_info
*
2124 get_containing_section (const struct dwarf2_section_info
*section
)
2126 gdb_assert (section
->is_virtual
);
2127 return section
->s
.containing_section
;
2130 /* Return the bfd owner of SECTION. */
2133 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2135 if (section
->is_virtual
)
2137 section
= get_containing_section (section
);
2138 gdb_assert (!section
->is_virtual
);
2140 return section
->s
.section
->owner
;
2143 /* Return the bfd section of SECTION.
2144 Returns NULL if the section is not present. */
2147 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2149 if (section
->is_virtual
)
2151 section
= get_containing_section (section
);
2152 gdb_assert (!section
->is_virtual
);
2154 return section
->s
.section
;
2157 /* Return the name of SECTION. */
2160 get_section_name (const struct dwarf2_section_info
*section
)
2162 asection
*sectp
= get_section_bfd_section (section
);
2164 gdb_assert (sectp
!= NULL
);
2165 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2168 /* Return the name of the file SECTION is in. */
2171 get_section_file_name (const struct dwarf2_section_info
*section
)
2173 bfd
*abfd
= get_section_bfd_owner (section
);
2175 return bfd_get_filename (abfd
);
2178 /* Return the id of SECTION.
2179 Returns 0 if SECTION doesn't exist. */
2182 get_section_id (const struct dwarf2_section_info
*section
)
2184 asection
*sectp
= get_section_bfd_section (section
);
2191 /* Return the flags of SECTION.
2192 SECTION (or containing section if this is a virtual section) must exist. */
2195 get_section_flags (const struct dwarf2_section_info
*section
)
2197 asection
*sectp
= get_section_bfd_section (section
);
2199 gdb_assert (sectp
!= NULL
);
2200 return bfd_get_section_flags (sectp
->owner
, sectp
);
2203 /* When loading sections, we look either for uncompressed section or for
2204 compressed section names. */
2207 section_is_p (const char *section_name
,
2208 const struct dwarf2_section_names
*names
)
2210 if (names
->normal
!= NULL
2211 && strcmp (section_name
, names
->normal
) == 0)
2213 if (names
->compressed
!= NULL
2214 && strcmp (section_name
, names
->compressed
) == 0)
2219 /* This function is mapped across the sections and remembers the
2220 offset and size of each of the debugging sections we are interested
2224 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
2226 const struct dwarf2_debug_sections
*names
;
2227 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2230 names
= &dwarf2_elf_names
;
2232 names
= (const struct dwarf2_debug_sections
*) vnames
;
2234 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2237 else if (section_is_p (sectp
->name
, &names
->info
))
2239 dwarf2_per_objfile
->info
.s
.section
= sectp
;
2240 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
2242 else if (section_is_p (sectp
->name
, &names
->abbrev
))
2244 dwarf2_per_objfile
->abbrev
.s
.section
= sectp
;
2245 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
2247 else if (section_is_p (sectp
->name
, &names
->line
))
2249 dwarf2_per_objfile
->line
.s
.section
= sectp
;
2250 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
2252 else if (section_is_p (sectp
->name
, &names
->loc
))
2254 dwarf2_per_objfile
->loc
.s
.section
= sectp
;
2255 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
2257 else if (section_is_p (sectp
->name
, &names
->loclists
))
2259 dwarf2_per_objfile
->loclists
.s
.section
= sectp
;
2260 dwarf2_per_objfile
->loclists
.size
= bfd_get_section_size (sectp
);
2262 else if (section_is_p (sectp
->name
, &names
->macinfo
))
2264 dwarf2_per_objfile
->macinfo
.s
.section
= sectp
;
2265 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
2267 else if (section_is_p (sectp
->name
, &names
->macro
))
2269 dwarf2_per_objfile
->macro
.s
.section
= sectp
;
2270 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
2272 else if (section_is_p (sectp
->name
, &names
->str
))
2274 dwarf2_per_objfile
->str
.s
.section
= sectp
;
2275 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
2277 else if (section_is_p (sectp
->name
, &names
->line_str
))
2279 dwarf2_per_objfile
->line_str
.s
.section
= sectp
;
2280 dwarf2_per_objfile
->line_str
.size
= bfd_get_section_size (sectp
);
2282 else if (section_is_p (sectp
->name
, &names
->addr
))
2284 dwarf2_per_objfile
->addr
.s
.section
= sectp
;
2285 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
2287 else if (section_is_p (sectp
->name
, &names
->frame
))
2289 dwarf2_per_objfile
->frame
.s
.section
= sectp
;
2290 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
2292 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
2294 dwarf2_per_objfile
->eh_frame
.s
.section
= sectp
;
2295 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
2297 else if (section_is_p (sectp
->name
, &names
->ranges
))
2299 dwarf2_per_objfile
->ranges
.s
.section
= sectp
;
2300 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
2302 else if (section_is_p (sectp
->name
, &names
->rnglists
))
2304 dwarf2_per_objfile
->rnglists
.s
.section
= sectp
;
2305 dwarf2_per_objfile
->rnglists
.size
= bfd_get_section_size (sectp
);
2307 else if (section_is_p (sectp
->name
, &names
->types
))
2309 struct dwarf2_section_info type_section
;
2311 memset (&type_section
, 0, sizeof (type_section
));
2312 type_section
.s
.section
= sectp
;
2313 type_section
.size
= bfd_get_section_size (sectp
);
2315 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
2318 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
2320 dwarf2_per_objfile
->gdb_index
.s
.section
= sectp
;
2321 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
2324 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2325 && bfd_section_vma (abfd
, sectp
) == 0)
2326 dwarf2_per_objfile
->has_section_at_zero
= 1;
2329 /* A helper function that decides whether a section is empty,
2333 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2335 if (section
->is_virtual
)
2336 return section
->size
== 0;
2337 return section
->s
.section
== NULL
|| section
->size
== 0;
2340 /* Read the contents of the section INFO.
2341 OBJFILE is the main object file, but not necessarily the file where
2342 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2344 If the section is compressed, uncompress it before returning. */
2347 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2351 gdb_byte
*buf
, *retbuf
;
2355 info
->buffer
= NULL
;
2358 if (dwarf2_section_empty_p (info
))
2361 sectp
= get_section_bfd_section (info
);
2363 /* If this is a virtual section we need to read in the real one first. */
2364 if (info
->is_virtual
)
2366 struct dwarf2_section_info
*containing_section
=
2367 get_containing_section (info
);
2369 gdb_assert (sectp
!= NULL
);
2370 if ((sectp
->flags
& SEC_RELOC
) != 0)
2372 error (_("Dwarf Error: DWP format V2 with relocations is not"
2373 " supported in section %s [in module %s]"),
2374 get_section_name (info
), get_section_file_name (info
));
2376 dwarf2_read_section (objfile
, containing_section
);
2377 /* Other code should have already caught virtual sections that don't
2379 gdb_assert (info
->virtual_offset
+ info
->size
2380 <= containing_section
->size
);
2381 /* If the real section is empty or there was a problem reading the
2382 section we shouldn't get here. */
2383 gdb_assert (containing_section
->buffer
!= NULL
);
2384 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2388 /* If the section has relocations, we must read it ourselves.
2389 Otherwise we attach it to the BFD. */
2390 if ((sectp
->flags
& SEC_RELOC
) == 0)
2392 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2396 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2399 /* When debugging .o files, we may need to apply relocations; see
2400 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2401 We never compress sections in .o files, so we only need to
2402 try this when the section is not compressed. */
2403 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2406 info
->buffer
= retbuf
;
2410 abfd
= get_section_bfd_owner (info
);
2411 gdb_assert (abfd
!= NULL
);
2413 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2414 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2416 error (_("Dwarf Error: Can't read DWARF data"
2417 " in section %s [in module %s]"),
2418 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2422 /* A helper function that returns the size of a section in a safe way.
2423 If you are positive that the section has been read before using the
2424 size, then it is safe to refer to the dwarf2_section_info object's
2425 "size" field directly. In other cases, you must call this
2426 function, because for compressed sections the size field is not set
2427 correctly until the section has been read. */
2429 static bfd_size_type
2430 dwarf2_section_size (struct objfile
*objfile
,
2431 struct dwarf2_section_info
*info
)
2434 dwarf2_read_section (objfile
, info
);
2438 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2442 dwarf2_get_section_info (struct objfile
*objfile
,
2443 enum dwarf2_section_enum sect
,
2444 asection
**sectp
, const gdb_byte
**bufp
,
2445 bfd_size_type
*sizep
)
2447 struct dwarf2_per_objfile
*data
2448 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2449 dwarf2_objfile_data_key
);
2450 struct dwarf2_section_info
*info
;
2452 /* We may see an objfile without any DWARF, in which case we just
2463 case DWARF2_DEBUG_FRAME
:
2464 info
= &data
->frame
;
2466 case DWARF2_EH_FRAME
:
2467 info
= &data
->eh_frame
;
2470 gdb_assert_not_reached ("unexpected section");
2473 dwarf2_read_section (objfile
, info
);
2475 *sectp
= get_section_bfd_section (info
);
2476 *bufp
= info
->buffer
;
2477 *sizep
= info
->size
;
2480 /* A helper function to find the sections for a .dwz file. */
2483 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2485 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2487 /* Note that we only support the standard ELF names, because .dwz
2488 is ELF-only (at the time of writing). */
2489 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2491 dwz_file
->abbrev
.s
.section
= sectp
;
2492 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2494 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2496 dwz_file
->info
.s
.section
= sectp
;
2497 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2499 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2501 dwz_file
->str
.s
.section
= sectp
;
2502 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2504 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2506 dwz_file
->line
.s
.section
= sectp
;
2507 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2509 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2511 dwz_file
->macro
.s
.section
= sectp
;
2512 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2514 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2516 dwz_file
->gdb_index
.s
.section
= sectp
;
2517 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2521 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2522 there is no .gnu_debugaltlink section in the file. Error if there
2523 is such a section but the file cannot be found. */
2525 static struct dwz_file
*
2526 dwarf2_get_dwz_file (void)
2529 struct cleanup
*cleanup
;
2530 const char *filename
;
2531 struct dwz_file
*result
;
2532 bfd_size_type buildid_len_arg
;
2536 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2537 return dwarf2_per_objfile
->dwz_file
;
2539 bfd_set_error (bfd_error_no_error
);
2540 data
= bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2541 &buildid_len_arg
, &buildid
);
2544 if (bfd_get_error () == bfd_error_no_error
)
2546 error (_("could not read '.gnu_debugaltlink' section: %s"),
2547 bfd_errmsg (bfd_get_error ()));
2549 cleanup
= make_cleanup (xfree
, data
);
2550 make_cleanup (xfree
, buildid
);
2552 buildid_len
= (size_t) buildid_len_arg
;
2554 filename
= (const char *) data
;
2555 if (!IS_ABSOLUTE_PATH (filename
))
2557 char *abs
= gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2560 make_cleanup (xfree
, abs
);
2561 abs
= ldirname (abs
);
2562 make_cleanup (xfree
, abs
);
2564 rel
= concat (abs
, SLASH_STRING
, filename
, (char *) NULL
);
2565 make_cleanup (xfree
, rel
);
2569 /* First try the file name given in the section. If that doesn't
2570 work, try to use the build-id instead. */
2571 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2572 if (dwz_bfd
!= NULL
)
2574 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2578 if (dwz_bfd
== NULL
)
2579 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2581 if (dwz_bfd
== NULL
)
2582 error (_("could not find '.gnu_debugaltlink' file for %s"),
2583 objfile_name (dwarf2_per_objfile
->objfile
));
2585 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2587 result
->dwz_bfd
= dwz_bfd
.release ();
2589 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
2591 do_cleanups (cleanup
);
2593 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
2594 dwarf2_per_objfile
->dwz_file
= result
;
2598 /* DWARF quick_symbols_functions support. */
2600 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2601 unique line tables, so we maintain a separate table of all .debug_line
2602 derived entries to support the sharing.
2603 All the quick functions need is the list of file names. We discard the
2604 line_header when we're done and don't need to record it here. */
2605 struct quick_file_names
2607 /* The data used to construct the hash key. */
2608 struct stmt_list_hash hash
;
2610 /* The number of entries in file_names, real_names. */
2611 unsigned int num_file_names
;
2613 /* The file names from the line table, after being run through
2615 const char **file_names
;
2617 /* The file names from the line table after being run through
2618 gdb_realpath. These are computed lazily. */
2619 const char **real_names
;
2622 /* When using the index (and thus not using psymtabs), each CU has an
2623 object of this type. This is used to hold information needed by
2624 the various "quick" methods. */
2625 struct dwarf2_per_cu_quick_data
2627 /* The file table. This can be NULL if there was no file table
2628 or it's currently not read in.
2629 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2630 struct quick_file_names
*file_names
;
2632 /* The corresponding symbol table. This is NULL if symbols for this
2633 CU have not yet been read. */
2634 struct compunit_symtab
*compunit_symtab
;
2636 /* A temporary mark bit used when iterating over all CUs in
2637 expand_symtabs_matching. */
2638 unsigned int mark
: 1;
2640 /* True if we've tried to read the file table and found there isn't one.
2641 There will be no point in trying to read it again next time. */
2642 unsigned int no_file_data
: 1;
2645 /* Utility hash function for a stmt_list_hash. */
2648 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2652 if (stmt_list_hash
->dwo_unit
!= NULL
)
2653 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2654 v
+= stmt_list_hash
->line_offset
.sect_off
;
2658 /* Utility equality function for a stmt_list_hash. */
2661 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2662 const struct stmt_list_hash
*rhs
)
2664 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2666 if (lhs
->dwo_unit
!= NULL
2667 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2670 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2673 /* Hash function for a quick_file_names. */
2676 hash_file_name_entry (const void *e
)
2678 const struct quick_file_names
*file_data
2679 = (const struct quick_file_names
*) e
;
2681 return hash_stmt_list_entry (&file_data
->hash
);
2684 /* Equality function for a quick_file_names. */
2687 eq_file_name_entry (const void *a
, const void *b
)
2689 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2690 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2692 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2695 /* Delete function for a quick_file_names. */
2698 delete_file_name_entry (void *e
)
2700 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2703 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2705 xfree ((void*) file_data
->file_names
[i
]);
2706 if (file_data
->real_names
)
2707 xfree ((void*) file_data
->real_names
[i
]);
2710 /* The space for the struct itself lives on objfile_obstack,
2711 so we don't free it here. */
2714 /* Create a quick_file_names hash table. */
2717 create_quick_file_names_table (unsigned int nr_initial_entries
)
2719 return htab_create_alloc (nr_initial_entries
,
2720 hash_file_name_entry
, eq_file_name_entry
,
2721 delete_file_name_entry
, xcalloc
, xfree
);
2724 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2725 have to be created afterwards. You should call age_cached_comp_units after
2726 processing PER_CU->CU. dw2_setup must have been already called. */
2729 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2731 if (per_cu
->is_debug_types
)
2732 load_full_type_unit (per_cu
);
2734 load_full_comp_unit (per_cu
, language_minimal
);
2736 if (per_cu
->cu
== NULL
)
2737 return; /* Dummy CU. */
2739 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2742 /* Read in the symbols for PER_CU. */
2745 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2747 struct cleanup
*back_to
;
2749 /* Skip type_unit_groups, reading the type units they contain
2750 is handled elsewhere. */
2751 if (IS_TYPE_UNIT_GROUP (per_cu
))
2754 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2756 if (dwarf2_per_objfile
->using_index
2757 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2758 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2760 queue_comp_unit (per_cu
, language_minimal
);
2763 /* If we just loaded a CU from a DWO, and we're working with an index
2764 that may badly handle TUs, load all the TUs in that DWO as well.
2765 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2766 if (!per_cu
->is_debug_types
2767 && per_cu
->cu
!= NULL
2768 && per_cu
->cu
->dwo_unit
!= NULL
2769 && dwarf2_per_objfile
->index_table
!= NULL
2770 && dwarf2_per_objfile
->index_table
->version
<= 7
2771 /* DWP files aren't supported yet. */
2772 && get_dwp_file () == NULL
)
2773 queue_and_load_all_dwo_tus (per_cu
);
2778 /* Age the cache, releasing compilation units that have not
2779 been used recently. */
2780 age_cached_comp_units ();
2782 do_cleanups (back_to
);
2785 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2786 the objfile from which this CU came. Returns the resulting symbol
2789 static struct compunit_symtab
*
2790 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2792 gdb_assert (dwarf2_per_objfile
->using_index
);
2793 if (!per_cu
->v
.quick
->compunit_symtab
)
2795 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2796 increment_reading_symtab ();
2797 dw2_do_instantiate_symtab (per_cu
);
2798 process_cu_includes ();
2799 do_cleanups (back_to
);
2802 return per_cu
->v
.quick
->compunit_symtab
;
2805 /* Return the CU/TU given its index.
2807 This is intended for loops like:
2809 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2810 + dwarf2_per_objfile->n_type_units); ++i)
2812 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
2818 static struct dwarf2_per_cu_data
*
2819 dw2_get_cutu (int index
)
2821 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2823 index
-= dwarf2_per_objfile
->n_comp_units
;
2824 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2825 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2828 return dwarf2_per_objfile
->all_comp_units
[index
];
2831 /* Return the CU given its index.
2832 This differs from dw2_get_cutu in that it's for when you know INDEX
2835 static struct dwarf2_per_cu_data
*
2836 dw2_get_cu (int index
)
2838 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
2840 return dwarf2_per_objfile
->all_comp_units
[index
];
2843 /* A helper for create_cus_from_index that handles a given list of
2847 create_cus_from_index_list (struct objfile
*objfile
,
2848 const gdb_byte
*cu_list
, offset_type n_elements
,
2849 struct dwarf2_section_info
*section
,
2855 for (i
= 0; i
< n_elements
; i
+= 2)
2857 struct dwarf2_per_cu_data
*the_cu
;
2858 ULONGEST offset
, length
;
2860 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2861 offset
= extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2862 length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2865 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2866 struct dwarf2_per_cu_data
);
2867 the_cu
->offset
.sect_off
= offset
;
2868 the_cu
->length
= length
;
2869 the_cu
->objfile
= objfile
;
2870 the_cu
->section
= section
;
2871 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2872 struct dwarf2_per_cu_quick_data
);
2873 the_cu
->is_dwz
= is_dwz
;
2874 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2878 /* Read the CU list from the mapped index, and use it to create all
2879 the CU objects for this objfile. */
2882 create_cus_from_index (struct objfile
*objfile
,
2883 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2884 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2886 struct dwz_file
*dwz
;
2888 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2889 dwarf2_per_objfile
->all_comp_units
=
2890 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
2891 dwarf2_per_objfile
->n_comp_units
);
2893 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2894 &dwarf2_per_objfile
->info
, 0, 0);
2896 if (dwz_elements
== 0)
2899 dwz
= dwarf2_get_dwz_file ();
2900 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
2901 cu_list_elements
/ 2);
2904 /* Create the signatured type hash table from the index. */
2907 create_signatured_type_table_from_index (struct objfile
*objfile
,
2908 struct dwarf2_section_info
*section
,
2909 const gdb_byte
*bytes
,
2910 offset_type elements
)
2913 htab_t sig_types_hash
;
2915 dwarf2_per_objfile
->n_type_units
2916 = dwarf2_per_objfile
->n_allocated_type_units
2918 dwarf2_per_objfile
->all_type_units
=
2919 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
2921 sig_types_hash
= allocate_signatured_type_table (objfile
);
2923 for (i
= 0; i
< elements
; i
+= 3)
2925 struct signatured_type
*sig_type
;
2926 ULONGEST offset
, type_offset_in_tu
, signature
;
2929 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2930 offset
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2931 type_offset_in_tu
= extract_unsigned_integer (bytes
+ 8, 8,
2933 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2936 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2937 struct signatured_type
);
2938 sig_type
->signature
= signature
;
2939 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2940 sig_type
->per_cu
.is_debug_types
= 1;
2941 sig_type
->per_cu
.section
= section
;
2942 sig_type
->per_cu
.offset
.sect_off
= offset
;
2943 sig_type
->per_cu
.objfile
= objfile
;
2944 sig_type
->per_cu
.v
.quick
2945 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2946 struct dwarf2_per_cu_quick_data
);
2948 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2951 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2954 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2957 /* Read the address map data from the mapped index, and use it to
2958 populate the objfile's psymtabs_addrmap. */
2961 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2963 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2964 const gdb_byte
*iter
, *end
;
2965 struct obstack temp_obstack
;
2966 struct addrmap
*mutable_map
;
2967 struct cleanup
*cleanup
;
2970 obstack_init (&temp_obstack
);
2971 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2972 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2974 iter
= index
->address_table
;
2975 end
= iter
+ index
->address_table_size
;
2977 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2981 ULONGEST hi
, lo
, cu_index
;
2982 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2984 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2986 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2991 complaint (&symfile_complaints
,
2992 _(".gdb_index address table has invalid range (%s - %s)"),
2993 hex_string (lo
), hex_string (hi
));
2997 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
2999 complaint (&symfile_complaints
,
3000 _(".gdb_index address table has invalid CU number %u"),
3001 (unsigned) cu_index
);
3005 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3006 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3007 addrmap_set_empty (mutable_map
, lo
, hi
- 1, dw2_get_cutu (cu_index
));
3010 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3011 &objfile
->objfile_obstack
);
3012 do_cleanups (cleanup
);
3015 /* The hash function for strings in the mapped index. This is the same as
3016 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
3017 implementation. This is necessary because the hash function is tied to the
3018 format of the mapped index file. The hash values do not have to match with
3021 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
3024 mapped_index_string_hash (int index_version
, const void *p
)
3026 const unsigned char *str
= (const unsigned char *) p
;
3030 while ((c
= *str
++) != 0)
3032 if (index_version
>= 5)
3034 r
= r
* 67 + c
- 113;
3040 /* Find a slot in the mapped index INDEX for the object named NAME.
3041 If NAME is found, set *VEC_OUT to point to the CU vector in the
3042 constant pool and return 1. If NAME cannot be found, return 0. */
3045 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3046 offset_type
**vec_out
)
3048 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3050 offset_type slot
, step
;
3051 int (*cmp
) (const char *, const char *);
3053 if (current_language
->la_language
== language_cplus
3054 || current_language
->la_language
== language_fortran
3055 || current_language
->la_language
== language_d
)
3057 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3060 if (strchr (name
, '(') != NULL
)
3062 char *without_params
= cp_remove_params (name
);
3064 if (without_params
!= NULL
)
3066 make_cleanup (xfree
, without_params
);
3067 name
= without_params
;
3072 /* Index version 4 did not support case insensitive searches. But the
3073 indices for case insensitive languages are built in lowercase, therefore
3074 simulate our NAME being searched is also lowercased. */
3075 hash
= mapped_index_string_hash ((index
->version
== 4
3076 && case_sensitivity
== case_sensitive_off
3077 ? 5 : index
->version
),
3080 slot
= hash
& (index
->symbol_table_slots
- 1);
3081 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
3082 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3086 /* Convert a slot number to an offset into the table. */
3087 offset_type i
= 2 * slot
;
3089 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
3091 do_cleanups (back_to
);
3095 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
3096 if (!cmp (name
, str
))
3098 *vec_out
= (offset_type
*) (index
->constant_pool
3099 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
3100 do_cleanups (back_to
);
3104 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
3108 /* A helper function that reads the .gdb_index from SECTION and fills
3109 in MAP. FILENAME is the name of the file containing the section;
3110 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3111 ok to use deprecated sections.
3113 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3114 out parameters that are filled in with information about the CU and
3115 TU lists in the section.
3117 Returns 1 if all went well, 0 otherwise. */
3120 read_index_from_section (struct objfile
*objfile
,
3121 const char *filename
,
3123 struct dwarf2_section_info
*section
,
3124 struct mapped_index
*map
,
3125 const gdb_byte
**cu_list
,
3126 offset_type
*cu_list_elements
,
3127 const gdb_byte
**types_list
,
3128 offset_type
*types_list_elements
)
3130 const gdb_byte
*addr
;
3131 offset_type version
;
3132 offset_type
*metadata
;
3135 if (dwarf2_section_empty_p (section
))
3138 /* Older elfutils strip versions could keep the section in the main
3139 executable while splitting it for the separate debug info file. */
3140 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3143 dwarf2_read_section (objfile
, section
);
3145 addr
= section
->buffer
;
3146 /* Version check. */
3147 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3148 /* Versions earlier than 3 emitted every copy of a psymbol. This
3149 causes the index to behave very poorly for certain requests. Version 3
3150 contained incomplete addrmap. So, it seems better to just ignore such
3154 static int warning_printed
= 0;
3155 if (!warning_printed
)
3157 warning (_("Skipping obsolete .gdb_index section in %s."),
3159 warning_printed
= 1;
3163 /* Index version 4 uses a different hash function than index version
3166 Versions earlier than 6 did not emit psymbols for inlined
3167 functions. Using these files will cause GDB not to be able to
3168 set breakpoints on inlined functions by name, so we ignore these
3169 indices unless the user has done
3170 "set use-deprecated-index-sections on". */
3171 if (version
< 6 && !deprecated_ok
)
3173 static int warning_printed
= 0;
3174 if (!warning_printed
)
3177 Skipping deprecated .gdb_index section in %s.\n\
3178 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3179 to use the section anyway."),
3181 warning_printed
= 1;
3185 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3186 of the TU (for symbols coming from TUs),
3187 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3188 Plus gold-generated indices can have duplicate entries for global symbols,
3189 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3190 These are just performance bugs, and we can't distinguish gdb-generated
3191 indices from gold-generated ones, so issue no warning here. */
3193 /* Indexes with higher version than the one supported by GDB may be no
3194 longer backward compatible. */
3198 map
->version
= version
;
3199 map
->total_size
= section
->size
;
3201 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3204 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3205 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3209 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3210 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3211 - MAYBE_SWAP (metadata
[i
]))
3215 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3216 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
3217 - MAYBE_SWAP (metadata
[i
]));
3220 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
3221 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
3222 - MAYBE_SWAP (metadata
[i
]))
3223 / (2 * sizeof (offset_type
)));
3226 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3232 /* Read the index file. If everything went ok, initialize the "quick"
3233 elements of all the CUs and return 1. Otherwise, return 0. */
3236 dwarf2_read_index (struct objfile
*objfile
)
3238 struct mapped_index local_map
, *map
;
3239 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3240 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3241 struct dwz_file
*dwz
;
3243 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3244 use_deprecated_index_sections
,
3245 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3246 &cu_list
, &cu_list_elements
,
3247 &types_list
, &types_list_elements
))
3250 /* Don't use the index if it's empty. */
3251 if (local_map
.symbol_table_slots
== 0)
3254 /* If there is a .dwz file, read it so we can get its CU list as
3256 dwz
= dwarf2_get_dwz_file ();
3259 struct mapped_index dwz_map
;
3260 const gdb_byte
*dwz_types_ignore
;
3261 offset_type dwz_types_elements_ignore
;
3263 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3265 &dwz
->gdb_index
, &dwz_map
,
3266 &dwz_list
, &dwz_list_elements
,
3268 &dwz_types_elements_ignore
))
3270 warning (_("could not read '.gdb_index' section from %s; skipping"),
3271 bfd_get_filename (dwz
->dwz_bfd
));
3276 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3279 if (types_list_elements
)
3281 struct dwarf2_section_info
*section
;
3283 /* We can only handle a single .debug_types when we have an
3285 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3288 section
= VEC_index (dwarf2_section_info_def
,
3289 dwarf2_per_objfile
->types
, 0);
3291 create_signatured_type_table_from_index (objfile
, section
, types_list
,
3292 types_list_elements
);
3295 create_addrmap_from_index (objfile
, &local_map
);
3297 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3300 dwarf2_per_objfile
->index_table
= map
;
3301 dwarf2_per_objfile
->using_index
= 1;
3302 dwarf2_per_objfile
->quick_file_names_table
=
3303 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3308 /* A helper for the "quick" functions which sets the global
3309 dwarf2_per_objfile according to OBJFILE. */
3312 dw2_setup (struct objfile
*objfile
)
3314 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
3315 objfile_data (objfile
, dwarf2_objfile_data_key
));
3316 gdb_assert (dwarf2_per_objfile
);
3319 /* die_reader_func for dw2_get_file_names. */
3322 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3323 const gdb_byte
*info_ptr
,
3324 struct die_info
*comp_unit_die
,
3328 struct dwarf2_cu
*cu
= reader
->cu
;
3329 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3330 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3331 struct dwarf2_per_cu_data
*lh_cu
;
3332 struct line_header
*lh
;
3333 struct attribute
*attr
;
3335 const char *name
, *comp_dir
;
3337 struct quick_file_names
*qfn
;
3338 unsigned int line_offset
;
3340 gdb_assert (! this_cu
->is_debug_types
);
3342 /* Our callers never want to match partial units -- instead they
3343 will match the enclosing full CU. */
3344 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3346 this_cu
->v
.quick
->no_file_data
= 1;
3355 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3358 struct quick_file_names find_entry
;
3360 line_offset
= DW_UNSND (attr
);
3362 /* We may have already read in this line header (TU line header sharing).
3363 If we have we're done. */
3364 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3365 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
3366 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3367 &find_entry
, INSERT
);
3370 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3374 lh
= dwarf_decode_line_header (line_offset
, cu
);
3378 lh_cu
->v
.quick
->no_file_data
= 1;
3382 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3383 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3384 qfn
->hash
.line_offset
.sect_off
= line_offset
;
3385 gdb_assert (slot
!= NULL
);
3388 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
3390 qfn
->num_file_names
= lh
->num_file_names
;
3392 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->num_file_names
);
3393 for (i
= 0; i
< lh
->num_file_names
; ++i
)
3394 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
3395 qfn
->real_names
= NULL
;
3397 free_line_header (lh
);
3399 lh_cu
->v
.quick
->file_names
= qfn
;
3402 /* A helper for the "quick" functions which attempts to read the line
3403 table for THIS_CU. */
3405 static struct quick_file_names
*
3406 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3408 /* This should never be called for TUs. */
3409 gdb_assert (! this_cu
->is_debug_types
);
3410 /* Nor type unit groups. */
3411 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3413 if (this_cu
->v
.quick
->file_names
!= NULL
)
3414 return this_cu
->v
.quick
->file_names
;
3415 /* If we know there is no line data, no point in looking again. */
3416 if (this_cu
->v
.quick
->no_file_data
)
3419 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3421 if (this_cu
->v
.quick
->no_file_data
)
3423 return this_cu
->v
.quick
->file_names
;
3426 /* A helper for the "quick" functions which computes and caches the
3427 real path for a given file name from the line table. */
3430 dw2_get_real_path (struct objfile
*objfile
,
3431 struct quick_file_names
*qfn
, int index
)
3433 if (qfn
->real_names
== NULL
)
3434 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3435 qfn
->num_file_names
, const char *);
3437 if (qfn
->real_names
[index
] == NULL
)
3438 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
3440 return qfn
->real_names
[index
];
3443 static struct symtab
*
3444 dw2_find_last_source_symtab (struct objfile
*objfile
)
3446 struct compunit_symtab
*cust
;
3449 dw2_setup (objfile
);
3450 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3451 cust
= dw2_instantiate_symtab (dw2_get_cutu (index
));
3454 return compunit_primary_filetab (cust
);
3457 /* Traversal function for dw2_forget_cached_source_info. */
3460 dw2_free_cached_file_names (void **slot
, void *info
)
3462 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3464 if (file_data
->real_names
)
3468 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3470 xfree ((void*) file_data
->real_names
[i
]);
3471 file_data
->real_names
[i
] = NULL
;
3479 dw2_forget_cached_source_info (struct objfile
*objfile
)
3481 dw2_setup (objfile
);
3483 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3484 dw2_free_cached_file_names
, NULL
);
3487 /* Helper function for dw2_map_symtabs_matching_filename that expands
3488 the symtabs and calls the iterator. */
3491 dw2_map_expand_apply (struct objfile
*objfile
,
3492 struct dwarf2_per_cu_data
*per_cu
,
3493 const char *name
, const char *real_path
,
3494 gdb::function_view
<bool (symtab
*)> callback
)
3496 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3498 /* Don't visit already-expanded CUs. */
3499 if (per_cu
->v
.quick
->compunit_symtab
)
3502 /* This may expand more than one symtab, and we want to iterate over
3504 dw2_instantiate_symtab (per_cu
);
3506 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3507 last_made
, callback
);
3510 /* Implementation of the map_symtabs_matching_filename method. */
3513 dw2_map_symtabs_matching_filename
3514 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3515 gdb::function_view
<bool (symtab
*)> callback
)
3518 const char *name_basename
= lbasename (name
);
3520 dw2_setup (objfile
);
3522 /* The rule is CUs specify all the files, including those used by
3523 any TU, so there's no need to scan TUs here. */
3525 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3528 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3529 struct quick_file_names
*file_data
;
3531 /* We only need to look at symtabs not already expanded. */
3532 if (per_cu
->v
.quick
->compunit_symtab
)
3535 file_data
= dw2_get_file_names (per_cu
);
3536 if (file_data
== NULL
)
3539 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3541 const char *this_name
= file_data
->file_names
[j
];
3542 const char *this_real_name
;
3544 if (compare_filenames_for_search (this_name
, name
))
3546 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3552 /* Before we invoke realpath, which can get expensive when many
3553 files are involved, do a quick comparison of the basenames. */
3554 if (! basenames_may_differ
3555 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3558 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3559 if (compare_filenames_for_search (this_real_name
, name
))
3561 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3567 if (real_path
!= NULL
)
3569 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3570 gdb_assert (IS_ABSOLUTE_PATH (name
));
3571 if (this_real_name
!= NULL
3572 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3574 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3586 /* Struct used to manage iterating over all CUs looking for a symbol. */
3588 struct dw2_symtab_iterator
3590 /* The internalized form of .gdb_index. */
3591 struct mapped_index
*index
;
3592 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3593 int want_specific_block
;
3594 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3595 Unused if !WANT_SPECIFIC_BLOCK. */
3597 /* The kind of symbol we're looking for. */
3599 /* The list of CUs from the index entry of the symbol,
3600 or NULL if not found. */
3602 /* The next element in VEC to look at. */
3604 /* The number of elements in VEC, or zero if there is no match. */
3606 /* Have we seen a global version of the symbol?
3607 If so we can ignore all further global instances.
3608 This is to work around gold/15646, inefficient gold-generated
3613 /* Initialize the index symtab iterator ITER.
3614 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3615 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3618 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3619 struct mapped_index
*index
,
3620 int want_specific_block
,
3625 iter
->index
= index
;
3626 iter
->want_specific_block
= want_specific_block
;
3627 iter
->block_index
= block_index
;
3628 iter
->domain
= domain
;
3630 iter
->global_seen
= 0;
3632 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3633 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3641 /* Return the next matching CU or NULL if there are no more. */
3643 static struct dwarf2_per_cu_data
*
3644 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3646 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3648 offset_type cu_index_and_attrs
=
3649 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3650 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3651 struct dwarf2_per_cu_data
*per_cu
;
3652 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3653 /* This value is only valid for index versions >= 7. */
3654 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3655 gdb_index_symbol_kind symbol_kind
=
3656 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3657 /* Only check the symbol attributes if they're present.
3658 Indices prior to version 7 don't record them,
3659 and indices >= 7 may elide them for certain symbols
3660 (gold does this). */
3662 (iter
->index
->version
>= 7
3663 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3665 /* Don't crash on bad data. */
3666 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3667 + dwarf2_per_objfile
->n_type_units
))
3669 complaint (&symfile_complaints
,
3670 _(".gdb_index entry has bad CU index"
3672 objfile_name (dwarf2_per_objfile
->objfile
));
3676 per_cu
= dw2_get_cutu (cu_index
);
3678 /* Skip if already read in. */
3679 if (per_cu
->v
.quick
->compunit_symtab
)
3682 /* Check static vs global. */
3685 if (iter
->want_specific_block
3686 && want_static
!= is_static
)
3688 /* Work around gold/15646. */
3689 if (!is_static
&& iter
->global_seen
)
3692 iter
->global_seen
= 1;
3695 /* Only check the symbol's kind if it has one. */
3698 switch (iter
->domain
)
3701 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3702 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3703 /* Some types are also in VAR_DOMAIN. */
3704 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3708 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3712 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3727 static struct compunit_symtab
*
3728 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3729 const char *name
, domain_enum domain
)
3731 struct compunit_symtab
*stab_best
= NULL
;
3732 struct mapped_index
*index
;
3734 dw2_setup (objfile
);
3736 index
= dwarf2_per_objfile
->index_table
;
3738 /* index is NULL if OBJF_READNOW. */
3741 struct dw2_symtab_iterator iter
;
3742 struct dwarf2_per_cu_data
*per_cu
;
3744 dw2_symtab_iter_init (&iter
, index
, 1, block_index
, domain
, name
);
3746 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3748 struct symbol
*sym
, *with_opaque
= NULL
;
3749 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
3750 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3751 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3753 sym
= block_find_symbol (block
, name
, domain
,
3754 block_find_non_opaque_type_preferred
,
3757 /* Some caution must be observed with overloaded functions
3758 and methods, since the index will not contain any overload
3759 information (but NAME might contain it). */
3762 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
3764 if (with_opaque
!= NULL
3765 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
3768 /* Keep looking through other CUs. */
3776 dw2_print_stats (struct objfile
*objfile
)
3778 int i
, total
, count
;
3780 dw2_setup (objfile
);
3781 total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
3783 for (i
= 0; i
< total
; ++i
)
3785 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3787 if (!per_cu
->v
.quick
->compunit_symtab
)
3790 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3791 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3794 /* This dumps minimal information about the index.
3795 It is called via "mt print objfiles".
3796 One use is to verify .gdb_index has been loaded by the
3797 gdb.dwarf2/gdb-index.exp testcase. */
3800 dw2_dump (struct objfile
*objfile
)
3802 dw2_setup (objfile
);
3803 gdb_assert (dwarf2_per_objfile
->using_index
);
3804 printf_filtered (".gdb_index:");
3805 if (dwarf2_per_objfile
->index_table
!= NULL
)
3807 printf_filtered (" version %d\n",
3808 dwarf2_per_objfile
->index_table
->version
);
3811 printf_filtered (" faked for \"readnow\"\n");
3812 printf_filtered ("\n");
3816 dw2_relocate (struct objfile
*objfile
,
3817 const struct section_offsets
*new_offsets
,
3818 const struct section_offsets
*delta
)
3820 /* There's nothing to relocate here. */
3824 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3825 const char *func_name
)
3827 struct mapped_index
*index
;
3829 dw2_setup (objfile
);
3831 index
= dwarf2_per_objfile
->index_table
;
3833 /* index is NULL if OBJF_READNOW. */
3836 struct dw2_symtab_iterator iter
;
3837 struct dwarf2_per_cu_data
*per_cu
;
3839 /* Note: It doesn't matter what we pass for block_index here. */
3840 dw2_symtab_iter_init (&iter
, index
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
3843 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3844 dw2_instantiate_symtab (per_cu
);
3849 dw2_expand_all_symtabs (struct objfile
*objfile
)
3853 dw2_setup (objfile
);
3855 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3856 + dwarf2_per_objfile
->n_type_units
); ++i
)
3858 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3860 dw2_instantiate_symtab (per_cu
);
3865 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3866 const char *fullname
)
3870 dw2_setup (objfile
);
3872 /* We don't need to consider type units here.
3873 This is only called for examining code, e.g. expand_line_sal.
3874 There can be an order of magnitude (or more) more type units
3875 than comp units, and we avoid them if we can. */
3877 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3880 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3881 struct quick_file_names
*file_data
;
3883 /* We only need to look at symtabs not already expanded. */
3884 if (per_cu
->v
.quick
->compunit_symtab
)
3887 file_data
= dw2_get_file_names (per_cu
);
3888 if (file_data
== NULL
)
3891 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3893 const char *this_fullname
= file_data
->file_names
[j
];
3895 if (filename_cmp (this_fullname
, fullname
) == 0)
3897 dw2_instantiate_symtab (per_cu
);
3905 dw2_map_matching_symbols (struct objfile
*objfile
,
3906 const char * name
, domain_enum domain
,
3908 int (*callback
) (struct block
*,
3909 struct symbol
*, void *),
3910 void *data
, symbol_compare_ftype
*match
,
3911 symbol_compare_ftype
*ordered_compare
)
3913 /* Currently unimplemented; used for Ada. The function can be called if the
3914 current language is Ada for a non-Ada objfile using GNU index. As Ada
3915 does not look for non-Ada symbols this function should just return. */
3919 dw2_expand_symtabs_matching
3920 (struct objfile
*objfile
,
3921 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3922 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3923 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
3924 enum search_domain kind
)
3928 struct mapped_index
*index
;
3930 dw2_setup (objfile
);
3932 /* index_table is NULL if OBJF_READNOW. */
3933 if (!dwarf2_per_objfile
->index_table
)
3935 index
= dwarf2_per_objfile
->index_table
;
3937 if (file_matcher
!= NULL
)
3939 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
3941 NULL
, xcalloc
, xfree
));
3942 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
3944 NULL
, xcalloc
, xfree
));
3946 /* The rule is CUs specify all the files, including those used by
3947 any TU, so there's no need to scan TUs here. */
3949 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3952 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3953 struct quick_file_names
*file_data
;
3958 per_cu
->v
.quick
->mark
= 0;
3960 /* We only need to look at symtabs not already expanded. */
3961 if (per_cu
->v
.quick
->compunit_symtab
)
3964 file_data
= dw2_get_file_names (per_cu
);
3965 if (file_data
== NULL
)
3968 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
3970 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
3972 per_cu
->v
.quick
->mark
= 1;
3976 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3978 const char *this_real_name
;
3980 if (file_matcher (file_data
->file_names
[j
], false))
3982 per_cu
->v
.quick
->mark
= 1;
3986 /* Before we invoke realpath, which can get expensive when many
3987 files are involved, do a quick comparison of the basenames. */
3988 if (!basenames_may_differ
3989 && !file_matcher (lbasename (file_data
->file_names
[j
]),
3993 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3994 if (file_matcher (this_real_name
, false))
3996 per_cu
->v
.quick
->mark
= 1;
4001 slot
= htab_find_slot (per_cu
->v
.quick
->mark
4002 ? visited_found
.get ()
4003 : visited_not_found
.get (),
4009 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
4011 offset_type idx
= 2 * iter
;
4013 offset_type
*vec
, vec_len
, vec_idx
;
4014 int global_seen
= 0;
4018 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
4021 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
4023 if (!symbol_matcher (name
))
4026 /* The name was matched, now expand corresponding CUs that were
4028 vec
= (offset_type
*) (index
->constant_pool
4029 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
4030 vec_len
= MAYBE_SWAP (vec
[0]);
4031 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4033 struct dwarf2_per_cu_data
*per_cu
;
4034 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4035 /* This value is only valid for index versions >= 7. */
4036 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4037 gdb_index_symbol_kind symbol_kind
=
4038 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4039 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4040 /* Only check the symbol attributes if they're present.
4041 Indices prior to version 7 don't record them,
4042 and indices >= 7 may elide them for certain symbols
4043 (gold does this). */
4045 (index
->version
>= 7
4046 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4048 /* Work around gold/15646. */
4051 if (!is_static
&& global_seen
)
4057 /* Only check the symbol's kind if it has one. */
4062 case VARIABLES_DOMAIN
:
4063 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4066 case FUNCTIONS_DOMAIN
:
4067 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4071 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4079 /* Don't crash on bad data. */
4080 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
4081 + dwarf2_per_objfile
->n_type_units
))
4083 complaint (&symfile_complaints
,
4084 _(".gdb_index entry has bad CU index"
4085 " [in module %s]"), objfile_name (objfile
));
4089 per_cu
= dw2_get_cutu (cu_index
);
4090 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4092 int symtab_was_null
=
4093 (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4095 dw2_instantiate_symtab (per_cu
);
4097 if (expansion_notify
!= NULL
4099 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4101 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4108 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4111 static struct compunit_symtab
*
4112 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4117 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4118 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4121 if (cust
->includes
== NULL
)
4124 for (i
= 0; cust
->includes
[i
]; ++i
)
4126 struct compunit_symtab
*s
= cust
->includes
[i
];
4128 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4136 static struct compunit_symtab
*
4137 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4138 struct bound_minimal_symbol msymbol
,
4140 struct obj_section
*section
,
4143 struct dwarf2_per_cu_data
*data
;
4144 struct compunit_symtab
*result
;
4146 dw2_setup (objfile
);
4148 if (!objfile
->psymtabs_addrmap
)
4151 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
4156 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4157 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4158 paddress (get_objfile_arch (objfile
), pc
));
4161 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
4163 gdb_assert (result
!= NULL
);
4168 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4169 void *data
, int need_fullname
)
4172 htab_up
visited (htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
4173 NULL
, xcalloc
, xfree
));
4175 dw2_setup (objfile
);
4177 /* The rule is CUs specify all the files, including those used by
4178 any TU, so there's no need to scan TUs here.
4179 We can ignore file names coming from already-expanded CUs. */
4181 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4183 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4185 if (per_cu
->v
.quick
->compunit_symtab
)
4187 void **slot
= htab_find_slot (visited
.get (),
4188 per_cu
->v
.quick
->file_names
,
4191 *slot
= per_cu
->v
.quick
->file_names
;
4195 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4198 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4199 struct quick_file_names
*file_data
;
4202 /* We only need to look at symtabs not already expanded. */
4203 if (per_cu
->v
.quick
->compunit_symtab
)
4206 file_data
= dw2_get_file_names (per_cu
);
4207 if (file_data
== NULL
)
4210 slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4213 /* Already visited. */
4218 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4220 const char *this_real_name
;
4223 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4225 this_real_name
= NULL
;
4226 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
4232 dw2_has_symbols (struct objfile
*objfile
)
4237 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4240 dw2_find_last_source_symtab
,
4241 dw2_forget_cached_source_info
,
4242 dw2_map_symtabs_matching_filename
,
4247 dw2_expand_symtabs_for_function
,
4248 dw2_expand_all_symtabs
,
4249 dw2_expand_symtabs_with_fullname
,
4250 dw2_map_matching_symbols
,
4251 dw2_expand_symtabs_matching
,
4252 dw2_find_pc_sect_compunit_symtab
,
4253 dw2_map_symbol_filenames
4256 /* Initialize for reading DWARF for this objfile. Return 0 if this
4257 file will use psymtabs, or 1 if using the GNU index. */
4260 dwarf2_initialize_objfile (struct objfile
*objfile
)
4262 /* If we're about to read full symbols, don't bother with the
4263 indices. In this case we also don't care if some other debug
4264 format is making psymtabs, because they are all about to be
4266 if ((objfile
->flags
& OBJF_READNOW
))
4270 dwarf2_per_objfile
->using_index
= 1;
4271 create_all_comp_units (objfile
);
4272 create_all_type_units (objfile
);
4273 dwarf2_per_objfile
->quick_file_names_table
=
4274 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
4276 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
4277 + dwarf2_per_objfile
->n_type_units
); ++i
)
4279 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4281 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4282 struct dwarf2_per_cu_quick_data
);
4285 /* Return 1 so that gdb sees the "quick" functions. However,
4286 these functions will be no-ops because we will have expanded
4291 if (dwarf2_read_index (objfile
))
4299 /* Build a partial symbol table. */
4302 dwarf2_build_psymtabs (struct objfile
*objfile
)
4305 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
4307 init_psymbol_list (objfile
, 1024);
4312 /* This isn't really ideal: all the data we allocate on the
4313 objfile's obstack is still uselessly kept around. However,
4314 freeing it seems unsafe. */
4315 psymtab_discarder
psymtabs (objfile
);
4316 dwarf2_build_psymtabs_hard (objfile
);
4319 CATCH (except
, RETURN_MASK_ERROR
)
4321 exception_print (gdb_stderr
, except
);
4326 /* Return the total length of the CU described by HEADER. */
4329 get_cu_length (const struct comp_unit_head
*header
)
4331 return header
->initial_length_size
+ header
->length
;
4334 /* Return TRUE if OFFSET is within CU_HEADER. */
4337 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
4339 sect_offset bottom
= { cu_header
->offset
.sect_off
};
4340 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
4342 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
4345 /* Find the base address of the compilation unit for range lists and
4346 location lists. It will normally be specified by DW_AT_low_pc.
4347 In DWARF-3 draft 4, the base address could be overridden by
4348 DW_AT_entry_pc. It's been removed, but GCC still uses this for
4349 compilation units with discontinuous ranges. */
4352 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
4354 struct attribute
*attr
;
4357 cu
->base_address
= 0;
4359 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
4362 cu
->base_address
= attr_value_as_address (attr
);
4367 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4370 cu
->base_address
= attr_value_as_address (attr
);
4376 /* Read in the comp unit header information from the debug_info at info_ptr.
4377 Use rcuh_kind::COMPILE as the default type if not known by the caller.
4378 NOTE: This leaves members offset, first_die_offset to be filled in
4381 static const gdb_byte
*
4382 read_comp_unit_head (struct comp_unit_head
*cu_header
,
4383 const gdb_byte
*info_ptr
,
4384 struct dwarf2_section_info
*section
,
4385 rcuh_kind section_kind
)
4388 unsigned int bytes_read
;
4389 const char *filename
= get_section_file_name (section
);
4390 bfd
*abfd
= get_section_bfd_owner (section
);
4392 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
4393 cu_header
->initial_length_size
= bytes_read
;
4394 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
4395 info_ptr
+= bytes_read
;
4396 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
4398 if (cu_header
->version
< 5)
4399 switch (section_kind
)
4401 case rcuh_kind::COMPILE
:
4402 cu_header
->unit_type
= DW_UT_compile
;
4404 case rcuh_kind::TYPE
:
4405 cu_header
->unit_type
= DW_UT_type
;
4408 internal_error (__FILE__
, __LINE__
,
4409 _("read_comp_unit_head: invalid section_kind"));
4413 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
4414 (read_1_byte (abfd
, info_ptr
));
4416 switch (cu_header
->unit_type
)
4419 if (section_kind
!= rcuh_kind::COMPILE
)
4420 error (_("Dwarf Error: wrong unit_type in compilation unit header "
4421 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
4425 section_kind
= rcuh_kind::TYPE
;
4428 error (_("Dwarf Error: wrong unit_type in compilation unit header "
4429 "(is %d, should be %d or %d) [in module %s]"),
4430 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
4433 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
4436 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
4438 info_ptr
+= bytes_read
;
4439 if (cu_header
->version
< 5)
4441 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
4444 signed_addr
= bfd_get_sign_extend_vma (abfd
);
4445 if (signed_addr
< 0)
4446 internal_error (__FILE__
, __LINE__
,
4447 _("read_comp_unit_head: dwarf from non elf file"));
4448 cu_header
->signed_addr_p
= signed_addr
;
4450 if (section_kind
== rcuh_kind::TYPE
)
4452 LONGEST type_offset
;
4454 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
4457 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
4458 info_ptr
+= bytes_read
;
4459 cu_header
->type_offset_in_tu
.cu_off
= type_offset
;
4460 if (cu_header
->type_offset_in_tu
.cu_off
!= type_offset
)
4461 error (_("Dwarf Error: Too big type_offset in compilation unit "
4462 "header (is %s) [in module %s]"), plongest (type_offset
),
4469 /* Helper function that returns the proper abbrev section for
4472 static struct dwarf2_section_info
*
4473 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
4475 struct dwarf2_section_info
*abbrev
;
4477 if (this_cu
->is_dwz
)
4478 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
4480 abbrev
= &dwarf2_per_objfile
->abbrev
;
4485 /* Subroutine of read_and_check_comp_unit_head and
4486 read_and_check_type_unit_head to simplify them.
4487 Perform various error checking on the header. */
4490 error_check_comp_unit_head (struct comp_unit_head
*header
,
4491 struct dwarf2_section_info
*section
,
4492 struct dwarf2_section_info
*abbrev_section
)
4494 const char *filename
= get_section_file_name (section
);
4496 if (header
->version
< 2 || header
->version
> 5)
4497 error (_("Dwarf Error: wrong version in compilation unit header "
4498 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
4501 if (header
->abbrev_offset
.sect_off
4502 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
4503 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
4504 "(offset 0x%lx + 6) [in module %s]"),
4505 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
4508 /* Cast to unsigned long to use 64-bit arithmetic when possible to
4509 avoid potential 32-bit overflow. */
4510 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
4512 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
4513 "(offset 0x%lx + 0) [in module %s]"),
4514 (long) header
->length
, (long) header
->offset
.sect_off
,
4518 /* Read in a CU/TU header and perform some basic error checking.
4519 The contents of the header are stored in HEADER.
4520 The result is a pointer to the start of the first DIE. */
4522 static const gdb_byte
*
4523 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
4524 struct dwarf2_section_info
*section
,
4525 struct dwarf2_section_info
*abbrev_section
,
4526 const gdb_byte
*info_ptr
,
4527 rcuh_kind section_kind
)
4529 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
4530 bfd
*abfd
= get_section_bfd_owner (section
);
4532 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4534 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
4536 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4538 error_check_comp_unit_head (header
, section
, abbrev_section
);
4543 /* Fetch the abbreviation table offset from a comp or type unit header. */
4546 read_abbrev_offset (struct dwarf2_section_info
*section
,
4549 bfd
*abfd
= get_section_bfd_owner (section
);
4550 const gdb_byte
*info_ptr
;
4551 unsigned int initial_length_size
, offset_size
;
4552 sect_offset abbrev_offset
;
4555 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
4556 info_ptr
= section
->buffer
+ offset
.sect_off
;
4557 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
4558 offset_size
= initial_length_size
== 4 ? 4 : 8;
4559 info_ptr
+= initial_length_size
;
4561 version
= read_2_bytes (abfd
, info_ptr
);
4565 /* Skip unit type and address size. */
4569 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
4570 return abbrev_offset
;
4573 /* Allocate a new partial symtab for file named NAME and mark this new
4574 partial symtab as being an include of PST. */
4577 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
4578 struct objfile
*objfile
)
4580 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
4582 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
4584 /* It shares objfile->objfile_obstack. */
4585 subpst
->dirname
= pst
->dirname
;
4588 subpst
->textlow
= 0;
4589 subpst
->texthigh
= 0;
4591 subpst
->dependencies
4592 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
4593 subpst
->dependencies
[0] = pst
;
4594 subpst
->number_of_dependencies
= 1;
4596 subpst
->globals_offset
= 0;
4597 subpst
->n_global_syms
= 0;
4598 subpst
->statics_offset
= 0;
4599 subpst
->n_static_syms
= 0;
4600 subpst
->compunit_symtab
= NULL
;
4601 subpst
->read_symtab
= pst
->read_symtab
;
4604 /* No private part is necessary for include psymtabs. This property
4605 can be used to differentiate between such include psymtabs and
4606 the regular ones. */
4607 subpst
->read_symtab_private
= NULL
;
4610 /* Read the Line Number Program data and extract the list of files
4611 included by the source file represented by PST. Build an include
4612 partial symtab for each of these included files. */
4615 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4616 struct die_info
*die
,
4617 struct partial_symtab
*pst
)
4619 struct line_header
*lh
= NULL
;
4620 struct attribute
*attr
;
4622 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4624 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
4626 return; /* No linetable, so no includes. */
4628 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4629 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
4631 free_line_header (lh
);
4635 hash_signatured_type (const void *item
)
4637 const struct signatured_type
*sig_type
4638 = (const struct signatured_type
*) item
;
4640 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4641 return sig_type
->signature
;
4645 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4647 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
4648 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
4650 return lhs
->signature
== rhs
->signature
;
4653 /* Allocate a hash table for signatured types. */
4656 allocate_signatured_type_table (struct objfile
*objfile
)
4658 return htab_create_alloc_ex (41,
4659 hash_signatured_type
,
4662 &objfile
->objfile_obstack
,
4663 hashtab_obstack_allocate
,
4664 dummy_obstack_deallocate
);
4667 /* A helper function to add a signatured type CU to a table. */
4670 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4672 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
4673 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
4681 /* A helper for create_debug_types_hash_table. Read types from SECTION
4682 and fill them into TYPES_HTAB. It will process only type units,
4683 therefore DW_UT_type. */
4686 create_debug_type_hash_table (struct dwo_file
*dwo_file
,
4687 dwarf2_section_info
*section
, htab_t
&types_htab
,
4688 rcuh_kind section_kind
)
4690 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4691 struct dwarf2_section_info
*abbrev_section
;
4693 const gdb_byte
*info_ptr
, *end_ptr
;
4695 abbrev_section
= (dwo_file
!= NULL
4696 ? &dwo_file
->sections
.abbrev
4697 : &dwarf2_per_objfile
->abbrev
);
4699 if (dwarf_read_debug
)
4700 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
4701 get_section_name (section
),
4702 get_section_file_name (abbrev_section
));
4704 dwarf2_read_section (objfile
, section
);
4705 info_ptr
= section
->buffer
;
4707 if (info_ptr
== NULL
)
4710 /* We can't set abfd until now because the section may be empty or
4711 not present, in which case the bfd is unknown. */
4712 abfd
= get_section_bfd_owner (section
);
4714 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4715 because we don't need to read any dies: the signature is in the
4718 end_ptr
= info_ptr
+ section
->size
;
4719 while (info_ptr
< end_ptr
)
4722 struct signatured_type
*sig_type
;
4723 struct dwo_unit
*dwo_tu
;
4725 const gdb_byte
*ptr
= info_ptr
;
4726 struct comp_unit_head header
;
4727 unsigned int length
;
4729 offset
.sect_off
= ptr
- section
->buffer
;
4731 /* Initialize it due to a false compiler warning. */
4732 header
.signature
= -1;
4733 header
.type_offset_in_tu
.cu_off
= -1;
4735 /* We need to read the type's signature in order to build the hash
4736 table, but we don't need anything else just yet. */
4738 ptr
= read_and_check_comp_unit_head (&header
, section
,
4739 abbrev_section
, ptr
, section_kind
);
4741 length
= get_cu_length (&header
);
4743 /* Skip dummy type units. */
4744 if (ptr
>= info_ptr
+ length
4745 || peek_abbrev_code (abfd
, ptr
) == 0
4746 || header
.unit_type
!= DW_UT_type
)
4752 if (types_htab
== NULL
)
4755 types_htab
= allocate_dwo_unit_table (objfile
);
4757 types_htab
= allocate_signatured_type_table (objfile
);
4763 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4765 dwo_tu
->dwo_file
= dwo_file
;
4766 dwo_tu
->signature
= header
.signature
;
4767 dwo_tu
->type_offset_in_tu
= header
.type_offset_in_tu
;
4768 dwo_tu
->section
= section
;
4769 dwo_tu
->offset
= offset
;
4770 dwo_tu
->length
= length
;
4774 /* N.B.: type_offset is not usable if this type uses a DWO file.
4775 The real type_offset is in the DWO file. */
4777 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4778 struct signatured_type
);
4779 sig_type
->signature
= header
.signature
;
4780 sig_type
->type_offset_in_tu
= header
.type_offset_in_tu
;
4781 sig_type
->per_cu
.objfile
= objfile
;
4782 sig_type
->per_cu
.is_debug_types
= 1;
4783 sig_type
->per_cu
.section
= section
;
4784 sig_type
->per_cu
.offset
= offset
;
4785 sig_type
->per_cu
.length
= length
;
4788 slot
= htab_find_slot (types_htab
,
4789 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4791 gdb_assert (slot
!= NULL
);
4794 sect_offset dup_offset
;
4798 const struct dwo_unit
*dup_tu
4799 = (const struct dwo_unit
*) *slot
;
4801 dup_offset
= dup_tu
->offset
;
4805 const struct signatured_type
*dup_tu
4806 = (const struct signatured_type
*) *slot
;
4808 dup_offset
= dup_tu
->per_cu
.offset
;
4811 complaint (&symfile_complaints
,
4812 _("debug type entry at offset 0x%x is duplicate to"
4813 " the entry at offset 0x%x, signature %s"),
4814 offset
.sect_off
, dup_offset
.sect_off
,
4815 hex_string (header
.signature
));
4817 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4819 if (dwarf_read_debug
> 1)
4820 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature %s\n",
4822 hex_string (header
.signature
));
4828 /* Create the hash table of all entries in the .debug_types
4829 (or .debug_types.dwo) section(s).
4830 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
4831 otherwise it is NULL.
4833 The result is a pointer to the hash table or NULL if there are no types.
4835 Note: This function processes DWO files only, not DWP files. */
4838 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4839 VEC (dwarf2_section_info_def
) *types
,
4843 struct dwarf2_section_info
*section
;
4845 if (VEC_empty (dwarf2_section_info_def
, types
))
4849 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4851 create_debug_type_hash_table (dwo_file
, section
, types_htab
,
4855 /* Create the hash table of all entries in the .debug_types section,
4856 and initialize all_type_units.
4857 The result is zero if there is an error (e.g. missing .debug_types section),
4858 otherwise non-zero. */
4861 create_all_type_units (struct objfile
*objfile
)
4863 htab_t types_htab
= NULL
;
4864 struct signatured_type
**iter
;
4866 create_debug_type_hash_table (NULL
, &dwarf2_per_objfile
->info
, types_htab
,
4867 rcuh_kind::COMPILE
);
4868 create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
, types_htab
);
4869 if (types_htab
== NULL
)
4871 dwarf2_per_objfile
->signatured_types
= NULL
;
4875 dwarf2_per_objfile
->signatured_types
= types_htab
;
4877 dwarf2_per_objfile
->n_type_units
4878 = dwarf2_per_objfile
->n_allocated_type_units
4879 = htab_elements (types_htab
);
4880 dwarf2_per_objfile
->all_type_units
=
4881 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
4882 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4883 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4884 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4885 == dwarf2_per_objfile
->n_type_units
);
4890 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
4891 If SLOT is non-NULL, it is the entry to use in the hash table.
4892 Otherwise we find one. */
4894 static struct signatured_type
*
4895 add_type_unit (ULONGEST sig
, void **slot
)
4897 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4898 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
4899 struct signatured_type
*sig_type
;
4901 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
4903 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
4905 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
4906 dwarf2_per_objfile
->n_allocated_type_units
= 1;
4907 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
4908 dwarf2_per_objfile
->all_type_units
4909 = XRESIZEVEC (struct signatured_type
*,
4910 dwarf2_per_objfile
->all_type_units
,
4911 dwarf2_per_objfile
->n_allocated_type_units
);
4912 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
4914 dwarf2_per_objfile
->n_type_units
= n_type_units
;
4916 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4917 struct signatured_type
);
4918 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
4919 sig_type
->signature
= sig
;
4920 sig_type
->per_cu
.is_debug_types
= 1;
4921 if (dwarf2_per_objfile
->using_index
)
4923 sig_type
->per_cu
.v
.quick
=
4924 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4925 struct dwarf2_per_cu_quick_data
);
4930 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
4933 gdb_assert (*slot
== NULL
);
4935 /* The rest of sig_type must be filled in by the caller. */
4939 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
4940 Fill in SIG_ENTRY with DWO_ENTRY. */
4943 fill_in_sig_entry_from_dwo_entry (struct objfile
*objfile
,
4944 struct signatured_type
*sig_entry
,
4945 struct dwo_unit
*dwo_entry
)
4947 /* Make sure we're not clobbering something we don't expect to. */
4948 gdb_assert (! sig_entry
->per_cu
.queued
);
4949 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
4950 if (dwarf2_per_objfile
->using_index
)
4952 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
4953 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
4956 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
4957 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
4958 gdb_assert (sig_entry
->type_offset_in_section
.sect_off
== 0);
4959 gdb_assert (sig_entry
->type_unit_group
== NULL
);
4960 gdb_assert (sig_entry
->dwo_unit
== NULL
);
4962 sig_entry
->per_cu
.section
= dwo_entry
->section
;
4963 sig_entry
->per_cu
.offset
= dwo_entry
->offset
;
4964 sig_entry
->per_cu
.length
= dwo_entry
->length
;
4965 sig_entry
->per_cu
.reading_dwo_directly
= 1;
4966 sig_entry
->per_cu
.objfile
= objfile
;
4967 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
4968 sig_entry
->dwo_unit
= dwo_entry
;
4971 /* Subroutine of lookup_signatured_type.
4972 If we haven't read the TU yet, create the signatured_type data structure
4973 for a TU to be read in directly from a DWO file, bypassing the stub.
4974 This is the "Stay in DWO Optimization": When there is no DWP file and we're
4975 using .gdb_index, then when reading a CU we want to stay in the DWO file
4976 containing that CU. Otherwise we could end up reading several other DWO
4977 files (due to comdat folding) to process the transitive closure of all the
4978 mentioned TUs, and that can be slow. The current DWO file will have every
4979 type signature that it needs.
4980 We only do this for .gdb_index because in the psymtab case we already have
4981 to read all the DWOs to build the type unit groups. */
4983 static struct signatured_type
*
4984 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
4986 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4987 struct dwo_file
*dwo_file
;
4988 struct dwo_unit find_dwo_entry
, *dwo_entry
;
4989 struct signatured_type find_sig_entry
, *sig_entry
;
4992 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
4994 /* If TU skeletons have been removed then we may not have read in any
4996 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4998 dwarf2_per_objfile
->signatured_types
4999 = allocate_signatured_type_table (objfile
);
5002 /* We only ever need to read in one copy of a signatured type.
5003 Use the global signatured_types array to do our own comdat-folding
5004 of types. If this is the first time we're reading this TU, and
5005 the TU has an entry in .gdb_index, replace the recorded data from
5006 .gdb_index with this TU. */
5008 find_sig_entry
.signature
= sig
;
5009 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5010 &find_sig_entry
, INSERT
);
5011 sig_entry
= (struct signatured_type
*) *slot
;
5013 /* We can get here with the TU already read, *or* in the process of being
5014 read. Don't reassign the global entry to point to this DWO if that's
5015 the case. Also note that if the TU is already being read, it may not
5016 have come from a DWO, the program may be a mix of Fission-compiled
5017 code and non-Fission-compiled code. */
5019 /* Have we already tried to read this TU?
5020 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5021 needn't exist in the global table yet). */
5022 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
5025 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
5026 dwo_unit of the TU itself. */
5027 dwo_file
= cu
->dwo_unit
->dwo_file
;
5029 /* Ok, this is the first time we're reading this TU. */
5030 if (dwo_file
->tus
== NULL
)
5032 find_dwo_entry
.signature
= sig
;
5033 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
5034 if (dwo_entry
== NULL
)
5037 /* If the global table doesn't have an entry for this TU, add one. */
5038 if (sig_entry
== NULL
)
5039 sig_entry
= add_type_unit (sig
, slot
);
5041 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
5042 sig_entry
->per_cu
.tu_read
= 1;
5046 /* Subroutine of lookup_signatured_type.
5047 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
5048 then try the DWP file. If the TU stub (skeleton) has been removed then
5049 it won't be in .gdb_index. */
5051 static struct signatured_type
*
5052 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5054 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5055 struct dwp_file
*dwp_file
= get_dwp_file ();
5056 struct dwo_unit
*dwo_entry
;
5057 struct signatured_type find_sig_entry
, *sig_entry
;
5060 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
5061 gdb_assert (dwp_file
!= NULL
);
5063 /* If TU skeletons have been removed then we may not have read in any
5065 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5067 dwarf2_per_objfile
->signatured_types
5068 = allocate_signatured_type_table (objfile
);
5071 find_sig_entry
.signature
= sig
;
5072 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5073 &find_sig_entry
, INSERT
);
5074 sig_entry
= (struct signatured_type
*) *slot
;
5076 /* Have we already tried to read this TU?
5077 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5078 needn't exist in the global table yet). */
5079 if (sig_entry
!= NULL
)
5082 if (dwp_file
->tus
== NULL
)
5084 dwo_entry
= lookup_dwo_unit_in_dwp (dwp_file
, NULL
,
5085 sig
, 1 /* is_debug_types */);
5086 if (dwo_entry
== NULL
)
5089 sig_entry
= add_type_unit (sig
, slot
);
5090 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
5095 /* Lookup a signature based type for DW_FORM_ref_sig8.
5096 Returns NULL if signature SIG is not present in the table.
5097 It is up to the caller to complain about this. */
5099 static struct signatured_type
*
5100 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5103 && dwarf2_per_objfile
->using_index
)
5105 /* We're in a DWO/DWP file, and we're using .gdb_index.
5106 These cases require special processing. */
5107 if (get_dwp_file () == NULL
)
5108 return lookup_dwo_signatured_type (cu
, sig
);
5110 return lookup_dwp_signatured_type (cu
, sig
);
5114 struct signatured_type find_entry
, *entry
;
5116 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5118 find_entry
.signature
= sig
;
5119 entry
= ((struct signatured_type
*)
5120 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
5125 /* Low level DIE reading support. */
5127 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
5130 init_cu_die_reader (struct die_reader_specs
*reader
,
5131 struct dwarf2_cu
*cu
,
5132 struct dwarf2_section_info
*section
,
5133 struct dwo_file
*dwo_file
)
5135 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
5136 reader
->abfd
= get_section_bfd_owner (section
);
5138 reader
->dwo_file
= dwo_file
;
5139 reader
->die_section
= section
;
5140 reader
->buffer
= section
->buffer
;
5141 reader
->buffer_end
= section
->buffer
+ section
->size
;
5142 reader
->comp_dir
= NULL
;
5145 /* Subroutine of init_cutu_and_read_dies to simplify it.
5146 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
5147 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
5150 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
5151 from it to the DIE in the DWO. If NULL we are skipping the stub.
5152 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
5153 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
5154 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
5155 STUB_COMP_DIR may be non-NULL.
5156 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
5157 are filled in with the info of the DIE from the DWO file.
5158 ABBREV_TABLE_PROVIDED is non-zero if the caller of init_cutu_and_read_dies
5159 provided an abbrev table to use.
5160 The result is non-zero if a valid (non-dummy) DIE was found. */
5163 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
5164 struct dwo_unit
*dwo_unit
,
5165 int abbrev_table_provided
,
5166 struct die_info
*stub_comp_unit_die
,
5167 const char *stub_comp_dir
,
5168 struct die_reader_specs
*result_reader
,
5169 const gdb_byte
**result_info_ptr
,
5170 struct die_info
**result_comp_unit_die
,
5171 int *result_has_children
)
5173 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5174 struct dwarf2_cu
*cu
= this_cu
->cu
;
5175 struct dwarf2_section_info
*section
;
5177 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5178 ULONGEST signature
; /* Or dwo_id. */
5179 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
5180 int i
,num_extra_attrs
;
5181 struct dwarf2_section_info
*dwo_abbrev_section
;
5182 struct attribute
*attr
;
5183 struct die_info
*comp_unit_die
;
5185 /* At most one of these may be provided. */
5186 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
5188 /* These attributes aren't processed until later:
5189 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
5190 DW_AT_comp_dir is used now, to find the DWO file, but it is also
5191 referenced later. However, these attributes are found in the stub
5192 which we won't have later. In order to not impose this complication
5193 on the rest of the code, we read them here and copy them to the
5202 if (stub_comp_unit_die
!= NULL
)
5204 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
5206 if (! this_cu
->is_debug_types
)
5207 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
5208 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
5209 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
5210 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
5211 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
5213 /* There should be a DW_AT_addr_base attribute here (if needed).
5214 We need the value before we can process DW_FORM_GNU_addr_index. */
5216 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
5218 cu
->addr_base
= DW_UNSND (attr
);
5220 /* There should be a DW_AT_ranges_base attribute here (if needed).
5221 We need the value before we can process DW_AT_ranges. */
5222 cu
->ranges_base
= 0;
5223 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
5225 cu
->ranges_base
= DW_UNSND (attr
);
5227 else if (stub_comp_dir
!= NULL
)
5229 /* Reconstruct the comp_dir attribute to simplify the code below. */
5230 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
5231 comp_dir
->name
= DW_AT_comp_dir
;
5232 comp_dir
->form
= DW_FORM_string
;
5233 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
5234 DW_STRING (comp_dir
) = stub_comp_dir
;
5237 /* Set up for reading the DWO CU/TU. */
5238 cu
->dwo_unit
= dwo_unit
;
5239 section
= dwo_unit
->section
;
5240 dwarf2_read_section (objfile
, section
);
5241 abfd
= get_section_bfd_owner (section
);
5242 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
5243 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
5244 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
);
5246 if (this_cu
->is_debug_types
)
5248 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
5250 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5252 info_ptr
, rcuh_kind::TYPE
);
5253 /* This is not an assert because it can be caused by bad debug info. */
5254 if (sig_type
->signature
!= cu
->header
.signature
)
5256 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
5257 " TU at offset 0x%x [in module %s]"),
5258 hex_string (sig_type
->signature
),
5259 hex_string (cu
->header
.signature
),
5260 dwo_unit
->offset
.sect_off
,
5261 bfd_get_filename (abfd
));
5263 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5264 /* For DWOs coming from DWP files, we don't know the CU length
5265 nor the type's offset in the TU until now. */
5266 dwo_unit
->length
= get_cu_length (&cu
->header
);
5267 dwo_unit
->type_offset_in_tu
= cu
->header
.type_offset_in_tu
;
5269 /* Establish the type offset that can be used to lookup the type.
5270 For DWO files, we don't know it until now. */
5271 sig_type
->type_offset_in_section
.sect_off
=
5272 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
5276 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5278 info_ptr
, rcuh_kind::COMPILE
);
5279 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5280 /* For DWOs coming from DWP files, we don't know the CU length
5282 dwo_unit
->length
= get_cu_length (&cu
->header
);
5285 /* Replace the CU's original abbrev table with the DWO's.
5286 Reminder: We can't read the abbrev table until we've read the header. */
5287 if (abbrev_table_provided
)
5289 /* Don't free the provided abbrev table, the caller of
5290 init_cutu_and_read_dies owns it. */
5291 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5292 /* Ensure the DWO abbrev table gets freed. */
5293 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5297 dwarf2_free_abbrev_table (cu
);
5298 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5299 /* Leave any existing abbrev table cleanup as is. */
5302 /* Read in the die, but leave space to copy over the attributes
5303 from the stub. This has the benefit of simplifying the rest of
5304 the code - all the work to maintain the illusion of a single
5305 DW_TAG_{compile,type}_unit DIE is done here. */
5306 num_extra_attrs
= ((stmt_list
!= NULL
)
5310 + (comp_dir
!= NULL
));
5311 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
5312 result_has_children
, num_extra_attrs
);
5314 /* Copy over the attributes from the stub to the DIE we just read in. */
5315 comp_unit_die
= *result_comp_unit_die
;
5316 i
= comp_unit_die
->num_attrs
;
5317 if (stmt_list
!= NULL
)
5318 comp_unit_die
->attrs
[i
++] = *stmt_list
;
5320 comp_unit_die
->attrs
[i
++] = *low_pc
;
5321 if (high_pc
!= NULL
)
5322 comp_unit_die
->attrs
[i
++] = *high_pc
;
5324 comp_unit_die
->attrs
[i
++] = *ranges
;
5325 if (comp_dir
!= NULL
)
5326 comp_unit_die
->attrs
[i
++] = *comp_dir
;
5327 comp_unit_die
->num_attrs
+= num_extra_attrs
;
5329 if (dwarf_die_debug
)
5331 fprintf_unfiltered (gdb_stdlog
,
5332 "Read die from %s@0x%x of %s:\n",
5333 get_section_name (section
),
5334 (unsigned) (begin_info_ptr
- section
->buffer
),
5335 bfd_get_filename (abfd
));
5336 dump_die (comp_unit_die
, dwarf_die_debug
);
5339 /* Save the comp_dir attribute. If there is no DWP file then we'll read
5340 TUs by skipping the stub and going directly to the entry in the DWO file.
5341 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
5342 to get it via circuitous means. Blech. */
5343 if (comp_dir
!= NULL
)
5344 result_reader
->comp_dir
= DW_STRING (comp_dir
);
5346 /* Skip dummy compilation units. */
5347 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
5348 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5351 *result_info_ptr
= info_ptr
;
5355 /* Subroutine of init_cutu_and_read_dies to simplify it.
5356 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
5357 Returns NULL if the specified DWO unit cannot be found. */
5359 static struct dwo_unit
*
5360 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
5361 struct die_info
*comp_unit_die
)
5363 struct dwarf2_cu
*cu
= this_cu
->cu
;
5364 struct attribute
*attr
;
5366 struct dwo_unit
*dwo_unit
;
5367 const char *comp_dir
, *dwo_name
;
5369 gdb_assert (cu
!= NULL
);
5371 /* Yeah, we look dwo_name up again, but it simplifies the code. */
5372 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5373 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
5375 if (this_cu
->is_debug_types
)
5377 struct signatured_type
*sig_type
;
5379 /* Since this_cu is the first member of struct signatured_type,
5380 we can go from a pointer to one to a pointer to the other. */
5381 sig_type
= (struct signatured_type
*) this_cu
;
5382 signature
= sig_type
->signature
;
5383 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
5387 struct attribute
*attr
;
5389 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
5391 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
5393 dwo_name
, objfile_name (this_cu
->objfile
));
5394 signature
= DW_UNSND (attr
);
5395 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
5402 /* Subroutine of init_cutu_and_read_dies to simplify it.
5403 See it for a description of the parameters.
5404 Read a TU directly from a DWO file, bypassing the stub.
5406 Note: This function could be a little bit simpler if we shared cleanups
5407 with our caller, init_cutu_and_read_dies. That's generally a fragile thing
5408 to do, so we keep this function self-contained. Or we could move this
5409 into our caller, but it's complex enough already. */
5412 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
5413 int use_existing_cu
, int keep
,
5414 die_reader_func_ftype
*die_reader_func
,
5417 struct dwarf2_cu
*cu
;
5418 struct signatured_type
*sig_type
;
5419 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5420 struct die_reader_specs reader
;
5421 const gdb_byte
*info_ptr
;
5422 struct die_info
*comp_unit_die
;
5425 /* Verify we can do the following downcast, and that we have the
5427 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
5428 sig_type
= (struct signatured_type
*) this_cu
;
5429 gdb_assert (sig_type
->dwo_unit
!= NULL
);
5431 cleanups
= make_cleanup (null_cleanup
, NULL
);
5433 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5435 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
5437 /* There's no need to do the rereading_dwo_cu handling that
5438 init_cutu_and_read_dies does since we don't read the stub. */
5442 /* If !use_existing_cu, this_cu->cu must be NULL. */
5443 gdb_assert (this_cu
->cu
== NULL
);
5444 cu
= XNEW (struct dwarf2_cu
);
5445 init_one_comp_unit (cu
, this_cu
);
5446 /* If an error occurs while loading, release our storage. */
5447 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5450 /* A future optimization, if needed, would be to use an existing
5451 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
5452 could share abbrev tables. */
5454 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
5455 0 /* abbrev_table_provided */,
5456 NULL
/* stub_comp_unit_die */,
5457 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
5459 &comp_unit_die
, &has_children
) == 0)
5462 do_cleanups (cleanups
);
5466 /* All the "real" work is done here. */
5467 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5469 /* This duplicates the code in init_cutu_and_read_dies,
5470 but the alternative is making the latter more complex.
5471 This function is only for the special case of using DWO files directly:
5472 no point in overly complicating the general case just to handle this. */
5473 if (free_cu_cleanup
!= NULL
)
5477 /* We've successfully allocated this compilation unit. Let our
5478 caller clean it up when finished with it. */
5479 discard_cleanups (free_cu_cleanup
);
5481 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5482 So we have to manually free the abbrev table. */
5483 dwarf2_free_abbrev_table (cu
);
5485 /* Link this CU into read_in_chain. */
5486 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5487 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5490 do_cleanups (free_cu_cleanup
);
5493 do_cleanups (cleanups
);
5496 /* Initialize a CU (or TU) and read its DIEs.
5497 If the CU defers to a DWO file, read the DWO file as well.
5499 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
5500 Otherwise the table specified in the comp unit header is read in and used.
5501 This is an optimization for when we already have the abbrev table.
5503 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
5504 Otherwise, a new CU is allocated with xmalloc.
5506 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
5507 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
5509 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5510 linker) then DIE_READER_FUNC will not get called. */
5513 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
5514 struct abbrev_table
*abbrev_table
,
5515 int use_existing_cu
, int keep
,
5516 die_reader_func_ftype
*die_reader_func
,
5519 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5520 struct dwarf2_section_info
*section
= this_cu
->section
;
5521 bfd
*abfd
= get_section_bfd_owner (section
);
5522 struct dwarf2_cu
*cu
;
5523 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5524 struct die_reader_specs reader
;
5525 struct die_info
*comp_unit_die
;
5527 struct attribute
*attr
;
5528 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5529 struct signatured_type
*sig_type
= NULL
;
5530 struct dwarf2_section_info
*abbrev_section
;
5531 /* Non-zero if CU currently points to a DWO file and we need to
5532 reread it. When this happens we need to reread the skeleton die
5533 before we can reread the DWO file (this only applies to CUs, not TUs). */
5534 int rereading_dwo_cu
= 0;
5536 if (dwarf_die_debug
)
5537 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5538 this_cu
->is_debug_types
? "type" : "comp",
5539 this_cu
->offset
.sect_off
);
5541 if (use_existing_cu
)
5544 /* If we're reading a TU directly from a DWO file, including a virtual DWO
5545 file (instead of going through the stub), short-circuit all of this. */
5546 if (this_cu
->reading_dwo_directly
)
5548 /* Narrow down the scope of possibilities to have to understand. */
5549 gdb_assert (this_cu
->is_debug_types
);
5550 gdb_assert (abbrev_table
== NULL
);
5551 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
5552 die_reader_func
, data
);
5556 cleanups
= make_cleanup (null_cleanup
, NULL
);
5558 /* This is cheap if the section is already read in. */
5559 dwarf2_read_section (objfile
, section
);
5561 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
5563 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
5565 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5568 /* If this CU is from a DWO file we need to start over, we need to
5569 refetch the attributes from the skeleton CU.
5570 This could be optimized by retrieving those attributes from when we
5571 were here the first time: the previous comp_unit_die was stored in
5572 comp_unit_obstack. But there's no data yet that we need this
5574 if (cu
->dwo_unit
!= NULL
)
5575 rereading_dwo_cu
= 1;
5579 /* If !use_existing_cu, this_cu->cu must be NULL. */
5580 gdb_assert (this_cu
->cu
== NULL
);
5581 cu
= XNEW (struct dwarf2_cu
);
5582 init_one_comp_unit (cu
, this_cu
);
5583 /* If an error occurs while loading, release our storage. */
5584 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5587 /* Get the header. */
5588 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
5590 /* We already have the header, there's no need to read it in again. */
5591 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
5595 if (this_cu
->is_debug_types
)
5597 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5598 abbrev_section
, info_ptr
,
5601 /* Since per_cu is the first member of struct signatured_type,
5602 we can go from a pointer to one to a pointer to the other. */
5603 sig_type
= (struct signatured_type
*) this_cu
;
5604 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
5605 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
5606 == cu
->header
.type_offset_in_tu
.cu_off
);
5607 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5609 /* LENGTH has not been set yet for type units if we're
5610 using .gdb_index. */
5611 this_cu
->length
= get_cu_length (&cu
->header
);
5613 /* Establish the type offset that can be used to lookup the type. */
5614 sig_type
->type_offset_in_section
.sect_off
=
5615 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
5617 this_cu
->dwarf_version
= cu
->header
.version
;
5621 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5624 rcuh_kind::COMPILE
);
5626 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5627 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
5628 this_cu
->dwarf_version
= cu
->header
.version
;
5632 /* Skip dummy compilation units. */
5633 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5634 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5636 do_cleanups (cleanups
);
5640 /* If we don't have them yet, read the abbrevs for this compilation unit.
5641 And if we need to read them now, make sure they're freed when we're
5642 done. Note that it's important that if the CU had an abbrev table
5643 on entry we don't free it when we're done: Somewhere up the call stack
5644 it may be in use. */
5645 if (abbrev_table
!= NULL
)
5647 gdb_assert (cu
->abbrev_table
== NULL
);
5648 gdb_assert (cu
->header
.abbrev_offset
.sect_off
5649 == abbrev_table
->offset
.sect_off
);
5650 cu
->abbrev_table
= abbrev_table
;
5652 else if (cu
->abbrev_table
== NULL
)
5654 dwarf2_read_abbrevs (cu
, abbrev_section
);
5655 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5657 else if (rereading_dwo_cu
)
5659 dwarf2_free_abbrev_table (cu
);
5660 dwarf2_read_abbrevs (cu
, abbrev_section
);
5663 /* Read the top level CU/TU die. */
5664 init_cu_die_reader (&reader
, cu
, section
, NULL
);
5665 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5667 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
5669 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
5670 DWO CU, that this test will fail (the attribute will not be present). */
5671 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5674 struct dwo_unit
*dwo_unit
;
5675 struct die_info
*dwo_comp_unit_die
;
5679 complaint (&symfile_complaints
,
5680 _("compilation unit with DW_AT_GNU_dwo_name"
5681 " has children (offset 0x%x) [in module %s]"),
5682 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
5684 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
5685 if (dwo_unit
!= NULL
)
5687 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
5688 abbrev_table
!= NULL
,
5689 comp_unit_die
, NULL
,
5691 &dwo_comp_unit_die
, &has_children
) == 0)
5694 do_cleanups (cleanups
);
5697 comp_unit_die
= dwo_comp_unit_die
;
5701 /* Yikes, we couldn't find the rest of the DIE, we only have
5702 the stub. A complaint has already been logged. There's
5703 not much more we can do except pass on the stub DIE to
5704 die_reader_func. We don't want to throw an error on bad
5709 /* All of the above is setup for this call. Yikes. */
5710 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5712 /* Done, clean up. */
5713 if (free_cu_cleanup
!= NULL
)
5717 /* We've successfully allocated this compilation unit. Let our
5718 caller clean it up when finished with it. */
5719 discard_cleanups (free_cu_cleanup
);
5721 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5722 So we have to manually free the abbrev table. */
5723 dwarf2_free_abbrev_table (cu
);
5725 /* Link this CU into read_in_chain. */
5726 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5727 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5730 do_cleanups (free_cu_cleanup
);
5733 do_cleanups (cleanups
);
5736 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
5737 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
5738 to have already done the lookup to find the DWO file).
5740 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
5741 THIS_CU->is_debug_types, but nothing else.
5743 We fill in THIS_CU->length.
5745 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5746 linker) then DIE_READER_FUNC will not get called.
5748 THIS_CU->cu is always freed when done.
5749 This is done in order to not leave THIS_CU->cu in a state where we have
5750 to care whether it refers to the "main" CU or the DWO CU. */
5753 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
5754 struct dwo_file
*dwo_file
,
5755 die_reader_func_ftype
*die_reader_func
,
5758 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5759 struct dwarf2_section_info
*section
= this_cu
->section
;
5760 bfd
*abfd
= get_section_bfd_owner (section
);
5761 struct dwarf2_section_info
*abbrev_section
;
5762 struct dwarf2_cu cu
;
5763 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5764 struct die_reader_specs reader
;
5765 struct cleanup
*cleanups
;
5766 struct die_info
*comp_unit_die
;
5769 if (dwarf_die_debug
)
5770 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5771 this_cu
->is_debug_types
? "type" : "comp",
5772 this_cu
->offset
.sect_off
);
5774 gdb_assert (this_cu
->cu
== NULL
);
5776 abbrev_section
= (dwo_file
!= NULL
5777 ? &dwo_file
->sections
.abbrev
5778 : get_abbrev_section_for_cu (this_cu
));
5780 /* This is cheap if the section is already read in. */
5781 dwarf2_read_section (objfile
, section
);
5783 init_one_comp_unit (&cu
, this_cu
);
5785 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
5787 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
5788 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
5789 abbrev_section
, info_ptr
,
5790 (this_cu
->is_debug_types
5792 : rcuh_kind::COMPILE
));
5794 this_cu
->length
= get_cu_length (&cu
.header
);
5796 /* Skip dummy compilation units. */
5797 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5798 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5800 do_cleanups (cleanups
);
5804 dwarf2_read_abbrevs (&cu
, abbrev_section
);
5805 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
5807 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
5808 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5810 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5812 do_cleanups (cleanups
);
5815 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
5816 does not lookup the specified DWO file.
5817 This cannot be used to read DWO files.
5819 THIS_CU->cu is always freed when done.
5820 This is done in order to not leave THIS_CU->cu in a state where we have
5821 to care whether it refers to the "main" CU or the DWO CU.
5822 We can revisit this if the data shows there's a performance issue. */
5825 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
5826 die_reader_func_ftype
*die_reader_func
,
5829 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
5832 /* Type Unit Groups.
5834 Type Unit Groups are a way to collapse the set of all TUs (type units) into
5835 a more manageable set. The grouping is done by DW_AT_stmt_list entry
5836 so that all types coming from the same compilation (.o file) are grouped
5837 together. A future step could be to put the types in the same symtab as
5838 the CU the types ultimately came from. */
5841 hash_type_unit_group (const void *item
)
5843 const struct type_unit_group
*tu_group
5844 = (const struct type_unit_group
*) item
;
5846 return hash_stmt_list_entry (&tu_group
->hash
);
5850 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
5852 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
5853 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
5855 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
5858 /* Allocate a hash table for type unit groups. */
5861 allocate_type_unit_groups_table (void)
5863 return htab_create_alloc_ex (3,
5864 hash_type_unit_group
,
5867 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
5868 hashtab_obstack_allocate
,
5869 dummy_obstack_deallocate
);
5872 /* Type units that don't have DW_AT_stmt_list are grouped into their own
5873 partial symtabs. We combine several TUs per psymtab to not let the size
5874 of any one psymtab grow too big. */
5875 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
5876 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5878 /* Helper routine for get_type_unit_group.
5879 Create the type_unit_group object used to hold one or more TUs. */
5881 static struct type_unit_group
*
5882 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
5884 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5885 struct dwarf2_per_cu_data
*per_cu
;
5886 struct type_unit_group
*tu_group
;
5888 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5889 struct type_unit_group
);
5890 per_cu
= &tu_group
->per_cu
;
5891 per_cu
->objfile
= objfile
;
5893 if (dwarf2_per_objfile
->using_index
)
5895 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5896 struct dwarf2_per_cu_quick_data
);
5900 unsigned int line_offset
= line_offset_struct
.sect_off
;
5901 struct partial_symtab
*pst
;
5904 /* Give the symtab a useful name for debug purposes. */
5905 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
5906 name
= xstrprintf ("<type_units_%d>",
5907 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
5909 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
5911 pst
= create_partial_symtab (per_cu
, name
);
5917 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
5918 tu_group
->hash
.line_offset
= line_offset_struct
;
5923 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5924 STMT_LIST is a DW_AT_stmt_list attribute. */
5926 static struct type_unit_group
*
5927 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
5929 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5930 struct type_unit_group
*tu_group
;
5932 unsigned int line_offset
;
5933 struct type_unit_group type_unit_group_for_lookup
;
5935 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
5937 dwarf2_per_objfile
->type_unit_groups
=
5938 allocate_type_unit_groups_table ();
5941 /* Do we need to create a new group, or can we use an existing one? */
5945 line_offset
= DW_UNSND (stmt_list
);
5946 ++tu_stats
->nr_symtab_sharers
;
5950 /* Ugh, no stmt_list. Rare, but we have to handle it.
5951 We can do various things here like create one group per TU or
5952 spread them over multiple groups to split up the expansion work.
5953 To avoid worst case scenarios (too many groups or too large groups)
5954 we, umm, group them in bunches. */
5955 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5956 | (tu_stats
->nr_stmt_less_type_units
5957 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
5958 ++tu_stats
->nr_stmt_less_type_units
;
5961 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
5962 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
5963 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
5964 &type_unit_group_for_lookup
, INSERT
);
5967 tu_group
= (struct type_unit_group
*) *slot
;
5968 gdb_assert (tu_group
!= NULL
);
5972 sect_offset line_offset_struct
;
5974 line_offset_struct
.sect_off
= line_offset
;
5975 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
5977 ++tu_stats
->nr_symtabs
;
5983 /* Partial symbol tables. */
5985 /* Create a psymtab named NAME and assign it to PER_CU.
5987 The caller must fill in the following details:
5988 dirname, textlow, texthigh. */
5990 static struct partial_symtab
*
5991 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
5993 struct objfile
*objfile
= per_cu
->objfile
;
5994 struct partial_symtab
*pst
;
5996 pst
= start_psymtab_common (objfile
, name
, 0,
5997 objfile
->global_psymbols
.next
,
5998 objfile
->static_psymbols
.next
);
6000 pst
->psymtabs_addrmap_supported
= 1;
6002 /* This is the glue that links PST into GDB's symbol API. */
6003 pst
->read_symtab_private
= per_cu
;
6004 pst
->read_symtab
= dwarf2_read_symtab
;
6005 per_cu
->v
.psymtab
= pst
;
6010 /* The DATA object passed to process_psymtab_comp_unit_reader has this
6013 struct process_psymtab_comp_unit_data
6015 /* True if we are reading a DW_TAG_partial_unit. */
6017 int want_partial_unit
;
6019 /* The "pretend" language that is used if the CU doesn't declare a
6022 enum language pretend_language
;
6025 /* die_reader_func for process_psymtab_comp_unit. */
6028 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6029 const gdb_byte
*info_ptr
,
6030 struct die_info
*comp_unit_die
,
6034 struct dwarf2_cu
*cu
= reader
->cu
;
6035 struct objfile
*objfile
= cu
->objfile
;
6036 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6037 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6039 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6040 struct partial_symtab
*pst
;
6041 enum pc_bounds_kind cu_bounds_kind
;
6042 const char *filename
;
6043 struct process_psymtab_comp_unit_data
*info
6044 = (struct process_psymtab_comp_unit_data
*) data
;
6046 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
6049 gdb_assert (! per_cu
->is_debug_types
);
6051 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
6053 cu
->list_in_scope
= &file_symbols
;
6055 /* Allocate a new partial symbol table structure. */
6056 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
6057 if (filename
== NULL
)
6060 pst
= create_partial_symtab (per_cu
, filename
);
6062 /* This must be done before calling dwarf2_build_include_psymtabs. */
6063 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6065 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6067 dwarf2_find_base_address (comp_unit_die
, cu
);
6069 /* Possibly set the default values of LOWPC and HIGHPC from
6071 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
6072 &best_highpc
, cu
, pst
);
6073 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
6074 /* Store the contiguous range if it is not empty; it can be empty for
6075 CUs with no code. */
6076 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6077 gdbarch_adjust_dwarf2_addr (gdbarch
,
6078 best_lowpc
+ baseaddr
),
6079 gdbarch_adjust_dwarf2_addr (gdbarch
,
6080 best_highpc
+ baseaddr
) - 1,
6083 /* Check if comp unit has_children.
6084 If so, read the rest of the partial symbols from this comp unit.
6085 If not, there's no more debug_info for this comp unit. */
6088 struct partial_die_info
*first_die
;
6089 CORE_ADDR lowpc
, highpc
;
6091 lowpc
= ((CORE_ADDR
) -1);
6092 highpc
= ((CORE_ADDR
) 0);
6094 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6096 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
6097 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
6099 /* If we didn't find a lowpc, set it to highpc to avoid
6100 complaints from `maint check'. */
6101 if (lowpc
== ((CORE_ADDR
) -1))
6104 /* If the compilation unit didn't have an explicit address range,
6105 then use the information extracted from its child dies. */
6106 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
6109 best_highpc
= highpc
;
6112 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
6113 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
6115 end_psymtab_common (objfile
, pst
);
6117 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
6120 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6121 struct dwarf2_per_cu_data
*iter
;
6123 /* Fill in 'dependencies' here; we fill in 'users' in a
6125 pst
->number_of_dependencies
= len
;
6127 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6129 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
6132 pst
->dependencies
[i
] = iter
->v
.psymtab
;
6134 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6137 /* Get the list of files included in the current compilation unit,
6138 and build a psymtab for each of them. */
6139 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
6141 if (dwarf_read_debug
)
6143 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6145 fprintf_unfiltered (gdb_stdlog
,
6146 "Psymtab for %s unit @0x%x: %s - %s"
6147 ", %d global, %d static syms\n",
6148 per_cu
->is_debug_types
? "type" : "comp",
6149 per_cu
->offset
.sect_off
,
6150 paddress (gdbarch
, pst
->textlow
),
6151 paddress (gdbarch
, pst
->texthigh
),
6152 pst
->n_global_syms
, pst
->n_static_syms
);
6156 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6157 Process compilation unit THIS_CU for a psymtab. */
6160 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6161 int want_partial_unit
,
6162 enum language pretend_language
)
6164 struct process_psymtab_comp_unit_data info
;
6166 /* If this compilation unit was already read in, free the
6167 cached copy in order to read it in again. This is
6168 necessary because we skipped some symbols when we first
6169 read in the compilation unit (see load_partial_dies).
6170 This problem could be avoided, but the benefit is unclear. */
6171 if (this_cu
->cu
!= NULL
)
6172 free_one_cached_comp_unit (this_cu
);
6174 gdb_assert (! this_cu
->is_debug_types
);
6175 info
.want_partial_unit
= want_partial_unit
;
6176 info
.pretend_language
= pretend_language
;
6177 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
6178 process_psymtab_comp_unit_reader
,
6181 /* Age out any secondary CUs. */
6182 age_cached_comp_units ();
6185 /* Reader function for build_type_psymtabs. */
6188 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
6189 const gdb_byte
*info_ptr
,
6190 struct die_info
*type_unit_die
,
6194 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6195 struct dwarf2_cu
*cu
= reader
->cu
;
6196 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6197 struct signatured_type
*sig_type
;
6198 struct type_unit_group
*tu_group
;
6199 struct attribute
*attr
;
6200 struct partial_die_info
*first_die
;
6201 CORE_ADDR lowpc
, highpc
;
6202 struct partial_symtab
*pst
;
6204 gdb_assert (data
== NULL
);
6205 gdb_assert (per_cu
->is_debug_types
);
6206 sig_type
= (struct signatured_type
*) per_cu
;
6211 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
6212 tu_group
= get_type_unit_group (cu
, attr
);
6214 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
6216 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
6217 cu
->list_in_scope
= &file_symbols
;
6218 pst
= create_partial_symtab (per_cu
, "");
6221 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6223 lowpc
= (CORE_ADDR
) -1;
6224 highpc
= (CORE_ADDR
) 0;
6225 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
6227 end_psymtab_common (objfile
, pst
);
6230 /* Struct used to sort TUs by their abbreviation table offset. */
6232 struct tu_abbrev_offset
6234 struct signatured_type
*sig_type
;
6235 sect_offset abbrev_offset
;
6238 /* Helper routine for build_type_psymtabs_1, passed to qsort. */
6241 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
6243 const struct tu_abbrev_offset
* const *a
6244 = (const struct tu_abbrev_offset
* const*) ap
;
6245 const struct tu_abbrev_offset
* const *b
6246 = (const struct tu_abbrev_offset
* const*) bp
;
6247 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
6248 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
6250 return (aoff
> boff
) - (aoff
< boff
);
6253 /* Efficiently read all the type units.
6254 This does the bulk of the work for build_type_psymtabs.
6256 The efficiency is because we sort TUs by the abbrev table they use and
6257 only read each abbrev table once. In one program there are 200K TUs
6258 sharing 8K abbrev tables.
6260 The main purpose of this function is to support building the
6261 dwarf2_per_objfile->type_unit_groups table.
6262 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
6263 can collapse the search space by grouping them by stmt_list.
6264 The savings can be significant, in the same program from above the 200K TUs
6265 share 8K stmt_list tables.
6267 FUNC is expected to call get_type_unit_group, which will create the
6268 struct type_unit_group if necessary and add it to
6269 dwarf2_per_objfile->type_unit_groups. */
6272 build_type_psymtabs_1 (void)
6274 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6275 struct cleanup
*cleanups
;
6276 struct abbrev_table
*abbrev_table
;
6277 sect_offset abbrev_offset
;
6278 struct tu_abbrev_offset
*sorted_by_abbrev
;
6281 /* It's up to the caller to not call us multiple times. */
6282 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
6284 if (dwarf2_per_objfile
->n_type_units
== 0)
6287 /* TUs typically share abbrev tables, and there can be way more TUs than
6288 abbrev tables. Sort by abbrev table to reduce the number of times we
6289 read each abbrev table in.
6290 Alternatives are to punt or to maintain a cache of abbrev tables.
6291 This is simpler and efficient enough for now.
6293 Later we group TUs by their DW_AT_stmt_list value (as this defines the
6294 symtab to use). Typically TUs with the same abbrev offset have the same
6295 stmt_list value too so in practice this should work well.
6297 The basic algorithm here is:
6299 sort TUs by abbrev table
6300 for each TU with same abbrev table:
6301 read abbrev table if first user
6302 read TU top level DIE
6303 [IWBN if DWO skeletons had DW_AT_stmt_list]
6306 if (dwarf_read_debug
)
6307 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
6309 /* Sort in a separate table to maintain the order of all_type_units
6310 for .gdb_index: TU indices directly index all_type_units. */
6311 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
6312 dwarf2_per_objfile
->n_type_units
);
6313 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6315 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
6317 sorted_by_abbrev
[i
].sig_type
= sig_type
;
6318 sorted_by_abbrev
[i
].abbrev_offset
=
6319 read_abbrev_offset (sig_type
->per_cu
.section
,
6320 sig_type
->per_cu
.offset
);
6322 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
6323 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
6324 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
6326 abbrev_offset
.sect_off
= ~(unsigned) 0;
6327 abbrev_table
= NULL
;
6328 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
6330 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6332 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
6334 /* Switch to the next abbrev table if necessary. */
6335 if (abbrev_table
== NULL
6336 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
6338 if (abbrev_table
!= NULL
)
6340 abbrev_table_free (abbrev_table
);
6341 /* Reset to NULL in case abbrev_table_read_table throws
6342 an error: abbrev_table_free_cleanup will get called. */
6343 abbrev_table
= NULL
;
6345 abbrev_offset
= tu
->abbrev_offset
;
6347 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
6349 ++tu_stats
->nr_uniq_abbrev_tables
;
6352 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
6353 build_type_psymtabs_reader
, NULL
);
6356 do_cleanups (cleanups
);
6359 /* Print collected type unit statistics. */
6362 print_tu_stats (void)
6364 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6366 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
6367 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
6368 dwarf2_per_objfile
->n_type_units
);
6369 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
6370 tu_stats
->nr_uniq_abbrev_tables
);
6371 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
6372 tu_stats
->nr_symtabs
);
6373 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
6374 tu_stats
->nr_symtab_sharers
);
6375 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
6376 tu_stats
->nr_stmt_less_type_units
);
6377 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
6378 tu_stats
->nr_all_type_units_reallocs
);
6381 /* Traversal function for build_type_psymtabs. */
6384 build_type_psymtab_dependencies (void **slot
, void *info
)
6386 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6387 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
6388 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
6389 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6390 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
6391 struct signatured_type
*iter
;
6394 gdb_assert (len
> 0);
6395 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
6397 pst
->number_of_dependencies
= len
;
6399 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6401 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
6404 gdb_assert (iter
->per_cu
.is_debug_types
);
6405 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
6406 iter
->type_unit_group
= tu_group
;
6409 VEC_free (sig_type_ptr
, tu_group
->tus
);
6414 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6415 Build partial symbol tables for the .debug_types comp-units. */
6418 build_type_psymtabs (struct objfile
*objfile
)
6420 if (! create_all_type_units (objfile
))
6423 build_type_psymtabs_1 ();
6426 /* Traversal function for process_skeletonless_type_unit.
6427 Read a TU in a DWO file and build partial symbols for it. */
6430 process_skeletonless_type_unit (void **slot
, void *info
)
6432 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
6433 struct objfile
*objfile
= (struct objfile
*) info
;
6434 struct signatured_type find_entry
, *entry
;
6436 /* If this TU doesn't exist in the global table, add it and read it in. */
6438 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6440 dwarf2_per_objfile
->signatured_types
6441 = allocate_signatured_type_table (objfile
);
6444 find_entry
.signature
= dwo_unit
->signature
;
6445 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
6447 /* If we've already seen this type there's nothing to do. What's happening
6448 is we're doing our own version of comdat-folding here. */
6452 /* This does the job that create_all_type_units would have done for
6454 entry
= add_type_unit (dwo_unit
->signature
, slot
);
6455 fill_in_sig_entry_from_dwo_entry (objfile
, entry
, dwo_unit
);
6458 /* This does the job that build_type_psymtabs_1 would have done. */
6459 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
6460 build_type_psymtabs_reader
, NULL
);
6465 /* Traversal function for process_skeletonless_type_units. */
6468 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
6470 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
6472 if (dwo_file
->tus
!= NULL
)
6474 htab_traverse_noresize (dwo_file
->tus
,
6475 process_skeletonless_type_unit
, info
);
6481 /* Scan all TUs of DWO files, verifying we've processed them.
6482 This is needed in case a TU was emitted without its skeleton.
6483 Note: This can't be done until we know what all the DWO files are. */
6486 process_skeletonless_type_units (struct objfile
*objfile
)
6488 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
6489 if (get_dwp_file () == NULL
6490 && dwarf2_per_objfile
->dwo_files
!= NULL
)
6492 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
6493 process_dwo_file_for_skeletonless_type_units
,
6498 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
6501 psymtabs_addrmap_cleanup (void *o
)
6503 struct objfile
*objfile
= (struct objfile
*) o
;
6505 objfile
->psymtabs_addrmap
= NULL
;
6508 /* Compute the 'user' field for each psymtab in OBJFILE. */
6511 set_partial_user (struct objfile
*objfile
)
6515 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6517 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6518 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6524 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
6526 /* Set the 'user' field only if it is not already set. */
6527 if (pst
->dependencies
[j
]->user
== NULL
)
6528 pst
->dependencies
[j
]->user
= pst
;
6533 /* Build the partial symbol table by doing a quick pass through the
6534 .debug_info and .debug_abbrev sections. */
6537 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
6539 struct cleanup
*back_to
, *addrmap_cleanup
;
6540 struct obstack temp_obstack
;
6543 if (dwarf_read_debug
)
6545 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
6546 objfile_name (objfile
));
6549 dwarf2_per_objfile
->reading_partial_symbols
= 1;
6551 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
6553 /* Any cached compilation units will be linked by the per-objfile
6554 read_in_chain. Make sure to free them when we're done. */
6555 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
6557 build_type_psymtabs (objfile
);
6559 create_all_comp_units (objfile
);
6561 /* Create a temporary address map on a temporary obstack. We later
6562 copy this to the final obstack. */
6563 obstack_init (&temp_obstack
);
6564 make_cleanup_obstack_free (&temp_obstack
);
6565 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
6566 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
6568 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6570 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6572 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
6575 /* This has to wait until we read the CUs, we need the list of DWOs. */
6576 process_skeletonless_type_units (objfile
);
6578 /* Now that all TUs have been processed we can fill in the dependencies. */
6579 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
6581 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
6582 build_type_psymtab_dependencies
, NULL
);
6585 if (dwarf_read_debug
)
6588 set_partial_user (objfile
);
6590 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
6591 &objfile
->objfile_obstack
);
6592 discard_cleanups (addrmap_cleanup
);
6594 do_cleanups (back_to
);
6596 if (dwarf_read_debug
)
6597 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
6598 objfile_name (objfile
));
6601 /* die_reader_func for load_partial_comp_unit. */
6604 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
6605 const gdb_byte
*info_ptr
,
6606 struct die_info
*comp_unit_die
,
6610 struct dwarf2_cu
*cu
= reader
->cu
;
6612 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
6614 /* Check if comp unit has_children.
6615 If so, read the rest of the partial symbols from this comp unit.
6616 If not, there's no more debug_info for this comp unit. */
6618 load_partial_dies (reader
, info_ptr
, 0);
6621 /* Load the partial DIEs for a secondary CU into memory.
6622 This is also used when rereading a primary CU with load_all_dies. */
6625 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
6627 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6628 load_partial_comp_unit_reader
, NULL
);
6632 read_comp_units_from_section (struct objfile
*objfile
,
6633 struct dwarf2_section_info
*section
,
6634 unsigned int is_dwz
,
6637 struct dwarf2_per_cu_data
***all_comp_units
)
6639 const gdb_byte
*info_ptr
;
6640 bfd
*abfd
= get_section_bfd_owner (section
);
6642 if (dwarf_read_debug
)
6643 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
6644 get_section_name (section
),
6645 get_section_file_name (section
));
6647 dwarf2_read_section (objfile
, section
);
6649 info_ptr
= section
->buffer
;
6651 while (info_ptr
< section
->buffer
+ section
->size
)
6653 unsigned int length
, initial_length_size
;
6654 struct dwarf2_per_cu_data
*this_cu
;
6657 offset
.sect_off
= info_ptr
- section
->buffer
;
6659 /* Read just enough information to find out where the next
6660 compilation unit is. */
6661 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6663 /* Save the compilation unit for later lookup. */
6664 this_cu
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
);
6665 memset (this_cu
, 0, sizeof (*this_cu
));
6666 this_cu
->offset
= offset
;
6667 this_cu
->length
= length
+ initial_length_size
;
6668 this_cu
->is_dwz
= is_dwz
;
6669 this_cu
->objfile
= objfile
;
6670 this_cu
->section
= section
;
6672 if (*n_comp_units
== *n_allocated
)
6675 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
6676 *all_comp_units
, *n_allocated
);
6678 (*all_comp_units
)[*n_comp_units
] = this_cu
;
6681 info_ptr
= info_ptr
+ this_cu
->length
;
6685 /* Create a list of all compilation units in OBJFILE.
6686 This is only done for -readnow and building partial symtabs. */
6689 create_all_comp_units (struct objfile
*objfile
)
6693 struct dwarf2_per_cu_data
**all_comp_units
;
6694 struct dwz_file
*dwz
;
6698 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
6700 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
6701 &n_allocated
, &n_comp_units
, &all_comp_units
);
6703 dwz
= dwarf2_get_dwz_file ();
6705 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
6706 &n_allocated
, &n_comp_units
,
6709 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
6710 struct dwarf2_per_cu_data
*,
6712 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
6713 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
6714 xfree (all_comp_units
);
6715 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
6718 /* Process all loaded DIEs for compilation unit CU, starting at
6719 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
6720 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
6721 DW_AT_ranges). See the comments of add_partial_subprogram on how
6722 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
6725 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
6726 CORE_ADDR
*highpc
, int set_addrmap
,
6727 struct dwarf2_cu
*cu
)
6729 struct partial_die_info
*pdi
;
6731 /* Now, march along the PDI's, descending into ones which have
6732 interesting children but skipping the children of the other ones,
6733 until we reach the end of the compilation unit. */
6739 fixup_partial_die (pdi
, cu
);
6741 /* Anonymous namespaces or modules have no name but have interesting
6742 children, so we need to look at them. Ditto for anonymous
6745 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
6746 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
6747 || pdi
->tag
== DW_TAG_imported_unit
)
6751 case DW_TAG_subprogram
:
6752 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6754 case DW_TAG_constant
:
6755 case DW_TAG_variable
:
6756 case DW_TAG_typedef
:
6757 case DW_TAG_union_type
:
6758 if (!pdi
->is_declaration
)
6760 add_partial_symbol (pdi
, cu
);
6763 case DW_TAG_class_type
:
6764 case DW_TAG_interface_type
:
6765 case DW_TAG_structure_type
:
6766 if (!pdi
->is_declaration
)
6768 add_partial_symbol (pdi
, cu
);
6770 if (cu
->language
== language_rust
&& pdi
->has_children
)
6771 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
6774 case DW_TAG_enumeration_type
:
6775 if (!pdi
->is_declaration
)
6776 add_partial_enumeration (pdi
, cu
);
6778 case DW_TAG_base_type
:
6779 case DW_TAG_subrange_type
:
6780 /* File scope base type definitions are added to the partial
6782 add_partial_symbol (pdi
, cu
);
6784 case DW_TAG_namespace
:
6785 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6788 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6790 case DW_TAG_imported_unit
:
6792 struct dwarf2_per_cu_data
*per_cu
;
6794 /* For now we don't handle imported units in type units. */
6795 if (cu
->per_cu
->is_debug_types
)
6797 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6798 " supported in type units [in module %s]"),
6799 objfile_name (cu
->objfile
));
6802 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
6806 /* Go read the partial unit, if needed. */
6807 if (per_cu
->v
.psymtab
== NULL
)
6808 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
6810 VEC_safe_push (dwarf2_per_cu_ptr
,
6811 cu
->per_cu
->imported_symtabs
, per_cu
);
6814 case DW_TAG_imported_declaration
:
6815 add_partial_symbol (pdi
, cu
);
6822 /* If the die has a sibling, skip to the sibling. */
6824 pdi
= pdi
->die_sibling
;
6828 /* Functions used to compute the fully scoped name of a partial DIE.
6830 Normally, this is simple. For C++, the parent DIE's fully scoped
6831 name is concatenated with "::" and the partial DIE's name.
6832 Enumerators are an exception; they use the scope of their parent
6833 enumeration type, i.e. the name of the enumeration type is not
6834 prepended to the enumerator.
6836 There are two complexities. One is DW_AT_specification; in this
6837 case "parent" means the parent of the target of the specification,
6838 instead of the direct parent of the DIE. The other is compilers
6839 which do not emit DW_TAG_namespace; in this case we try to guess
6840 the fully qualified name of structure types from their members'
6841 linkage names. This must be done using the DIE's children rather
6842 than the children of any DW_AT_specification target. We only need
6843 to do this for structures at the top level, i.e. if the target of
6844 any DW_AT_specification (if any; otherwise the DIE itself) does not
6847 /* Compute the scope prefix associated with PDI's parent, in
6848 compilation unit CU. The result will be allocated on CU's
6849 comp_unit_obstack, or a copy of the already allocated PDI->NAME
6850 field. NULL is returned if no prefix is necessary. */
6852 partial_die_parent_scope (struct partial_die_info
*pdi
,
6853 struct dwarf2_cu
*cu
)
6855 const char *grandparent_scope
;
6856 struct partial_die_info
*parent
, *real_pdi
;
6858 /* We need to look at our parent DIE; if we have a DW_AT_specification,
6859 then this means the parent of the specification DIE. */
6862 while (real_pdi
->has_specification
)
6863 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
6864 real_pdi
->spec_is_dwz
, cu
);
6866 parent
= real_pdi
->die_parent
;
6870 if (parent
->scope_set
)
6871 return parent
->scope
;
6873 fixup_partial_die (parent
, cu
);
6875 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
6877 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
6878 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
6879 Work around this problem here. */
6880 if (cu
->language
== language_cplus
6881 && parent
->tag
== DW_TAG_namespace
6882 && strcmp (parent
->name
, "::") == 0
6883 && grandparent_scope
== NULL
)
6885 parent
->scope
= NULL
;
6886 parent
->scope_set
= 1;
6890 if (pdi
->tag
== DW_TAG_enumerator
)
6891 /* Enumerators should not get the name of the enumeration as a prefix. */
6892 parent
->scope
= grandparent_scope
;
6893 else if (parent
->tag
== DW_TAG_namespace
6894 || parent
->tag
== DW_TAG_module
6895 || parent
->tag
== DW_TAG_structure_type
6896 || parent
->tag
== DW_TAG_class_type
6897 || parent
->tag
== DW_TAG_interface_type
6898 || parent
->tag
== DW_TAG_union_type
6899 || parent
->tag
== DW_TAG_enumeration_type
)
6901 if (grandparent_scope
== NULL
)
6902 parent
->scope
= parent
->name
;
6904 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
6906 parent
->name
, 0, cu
);
6910 /* FIXME drow/2004-04-01: What should we be doing with
6911 function-local names? For partial symbols, we should probably be
6913 complaint (&symfile_complaints
,
6914 _("unhandled containing DIE tag %d for DIE at %d"),
6915 parent
->tag
, pdi
->offset
.sect_off
);
6916 parent
->scope
= grandparent_scope
;
6919 parent
->scope_set
= 1;
6920 return parent
->scope
;
6923 /* Return the fully scoped name associated with PDI, from compilation unit
6924 CU. The result will be allocated with malloc. */
6927 partial_die_full_name (struct partial_die_info
*pdi
,
6928 struct dwarf2_cu
*cu
)
6930 const char *parent_scope
;
6932 /* If this is a template instantiation, we can not work out the
6933 template arguments from partial DIEs. So, unfortunately, we have
6934 to go through the full DIEs. At least any work we do building
6935 types here will be reused if full symbols are loaded later. */
6936 if (pdi
->has_template_arguments
)
6938 fixup_partial_die (pdi
, cu
);
6940 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
6942 struct die_info
*die
;
6943 struct attribute attr
;
6944 struct dwarf2_cu
*ref_cu
= cu
;
6946 /* DW_FORM_ref_addr is using section offset. */
6947 attr
.name
= (enum dwarf_attribute
) 0;
6948 attr
.form
= DW_FORM_ref_addr
;
6949 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
6950 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
6952 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
6956 parent_scope
= partial_die_parent_scope (pdi
, cu
);
6957 if (parent_scope
== NULL
)
6960 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
6964 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
6966 struct objfile
*objfile
= cu
->objfile
;
6967 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6969 const char *actual_name
= NULL
;
6971 char *built_actual_name
;
6973 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6975 built_actual_name
= partial_die_full_name (pdi
, cu
);
6976 if (built_actual_name
!= NULL
)
6977 actual_name
= built_actual_name
;
6979 if (actual_name
== NULL
)
6980 actual_name
= pdi
->name
;
6984 case DW_TAG_subprogram
:
6985 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
6986 if (pdi
->is_external
|| cu
->language
== language_ada
)
6988 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
6989 of the global scope. But in Ada, we want to be able to access
6990 nested procedures globally. So all Ada subprograms are stored
6991 in the global scope. */
6992 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6993 built_actual_name
!= NULL
,
6994 VAR_DOMAIN
, LOC_BLOCK
,
6995 &objfile
->global_psymbols
,
6996 addr
, cu
->language
, objfile
);
7000 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7001 built_actual_name
!= NULL
,
7002 VAR_DOMAIN
, LOC_BLOCK
,
7003 &objfile
->static_psymbols
,
7004 addr
, cu
->language
, objfile
);
7007 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7008 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
7010 case DW_TAG_constant
:
7012 struct psymbol_allocation_list
*list
;
7014 if (pdi
->is_external
)
7015 list
= &objfile
->global_psymbols
;
7017 list
= &objfile
->static_psymbols
;
7018 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7019 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
7020 list
, 0, cu
->language
, objfile
);
7023 case DW_TAG_variable
:
7025 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7029 && !dwarf2_per_objfile
->has_section_at_zero
)
7031 /* A global or static variable may also have been stripped
7032 out by the linker if unused, in which case its address
7033 will be nullified; do not add such variables into partial
7034 symbol table then. */
7036 else if (pdi
->is_external
)
7039 Don't enter into the minimal symbol tables as there is
7040 a minimal symbol table entry from the ELF symbols already.
7041 Enter into partial symbol table if it has a location
7042 descriptor or a type.
7043 If the location descriptor is missing, new_symbol will create
7044 a LOC_UNRESOLVED symbol, the address of the variable will then
7045 be determined from the minimal symbol table whenever the variable
7047 The address for the partial symbol table entry is not
7048 used by GDB, but it comes in handy for debugging partial symbol
7051 if (pdi
->d
.locdesc
|| pdi
->has_type
)
7052 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7053 built_actual_name
!= NULL
,
7054 VAR_DOMAIN
, LOC_STATIC
,
7055 &objfile
->global_psymbols
,
7057 cu
->language
, objfile
);
7061 int has_loc
= pdi
->d
.locdesc
!= NULL
;
7063 /* Static Variable. Skip symbols whose value we cannot know (those
7064 without location descriptors or constant values). */
7065 if (!has_loc
&& !pdi
->has_const_value
)
7067 xfree (built_actual_name
);
7071 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7072 built_actual_name
!= NULL
,
7073 VAR_DOMAIN
, LOC_STATIC
,
7074 &objfile
->static_psymbols
,
7075 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
7076 cu
->language
, objfile
);
7079 case DW_TAG_typedef
:
7080 case DW_TAG_base_type
:
7081 case DW_TAG_subrange_type
:
7082 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7083 built_actual_name
!= NULL
,
7084 VAR_DOMAIN
, LOC_TYPEDEF
,
7085 &objfile
->static_psymbols
,
7086 0, cu
->language
, objfile
);
7088 case DW_TAG_imported_declaration
:
7089 case DW_TAG_namespace
:
7090 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7091 built_actual_name
!= NULL
,
7092 VAR_DOMAIN
, LOC_TYPEDEF
,
7093 &objfile
->global_psymbols
,
7094 0, cu
->language
, objfile
);
7097 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7098 built_actual_name
!= NULL
,
7099 MODULE_DOMAIN
, LOC_TYPEDEF
,
7100 &objfile
->global_psymbols
,
7101 0, cu
->language
, objfile
);
7103 case DW_TAG_class_type
:
7104 case DW_TAG_interface_type
:
7105 case DW_TAG_structure_type
:
7106 case DW_TAG_union_type
:
7107 case DW_TAG_enumeration_type
:
7108 /* Skip external references. The DWARF standard says in the section
7109 about "Structure, Union, and Class Type Entries": "An incomplete
7110 structure, union or class type is represented by a structure,
7111 union or class entry that does not have a byte size attribute
7112 and that has a DW_AT_declaration attribute." */
7113 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
7115 xfree (built_actual_name
);
7119 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
7120 static vs. global. */
7121 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7122 built_actual_name
!= NULL
,
7123 STRUCT_DOMAIN
, LOC_TYPEDEF
,
7124 cu
->language
== language_cplus
7125 ? &objfile
->global_psymbols
7126 : &objfile
->static_psymbols
,
7127 0, cu
->language
, objfile
);
7130 case DW_TAG_enumerator
:
7131 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7132 built_actual_name
!= NULL
,
7133 VAR_DOMAIN
, LOC_CONST
,
7134 cu
->language
== language_cplus
7135 ? &objfile
->global_psymbols
7136 : &objfile
->static_psymbols
,
7137 0, cu
->language
, objfile
);
7143 xfree (built_actual_name
);
7146 /* Read a partial die corresponding to a namespace; also, add a symbol
7147 corresponding to that namespace to the symbol table. NAMESPACE is
7148 the name of the enclosing namespace. */
7151 add_partial_namespace (struct partial_die_info
*pdi
,
7152 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7153 int set_addrmap
, struct dwarf2_cu
*cu
)
7155 /* Add a symbol for the namespace. */
7157 add_partial_symbol (pdi
, cu
);
7159 /* Now scan partial symbols in that namespace. */
7161 if (pdi
->has_children
)
7162 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7165 /* Read a partial die corresponding to a Fortran module. */
7168 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
7169 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
7171 /* Add a symbol for the namespace. */
7173 add_partial_symbol (pdi
, cu
);
7175 /* Now scan partial symbols in that module. */
7177 if (pdi
->has_children
)
7178 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7181 /* Read a partial die corresponding to a subprogram and create a partial
7182 symbol for that subprogram. When the CU language allows it, this
7183 routine also defines a partial symbol for each nested subprogram
7184 that this subprogram contains. If SET_ADDRMAP is true, record the
7185 covered ranges in the addrmap. Set *LOWPC and *HIGHPC to the lowest
7186 and highest PC values found in PDI.
7188 PDI may also be a lexical block, in which case we simply search
7189 recursively for subprograms defined inside that lexical block.
7190 Again, this is only performed when the CU language allows this
7191 type of definitions. */
7194 add_partial_subprogram (struct partial_die_info
*pdi
,
7195 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7196 int set_addrmap
, struct dwarf2_cu
*cu
)
7198 if (pdi
->tag
== DW_TAG_subprogram
)
7200 if (pdi
->has_pc_info
)
7202 if (pdi
->lowpc
< *lowpc
)
7203 *lowpc
= pdi
->lowpc
;
7204 if (pdi
->highpc
> *highpc
)
7205 *highpc
= pdi
->highpc
;
7208 struct objfile
*objfile
= cu
->objfile
;
7209 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7214 baseaddr
= ANOFFSET (objfile
->section_offsets
,
7215 SECT_OFF_TEXT (objfile
));
7216 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7217 pdi
->lowpc
+ baseaddr
);
7218 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7219 pdi
->highpc
+ baseaddr
);
7220 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
7221 cu
->per_cu
->v
.psymtab
);
7225 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
7227 if (!pdi
->is_declaration
)
7228 /* Ignore subprogram DIEs that do not have a name, they are
7229 illegal. Do not emit a complaint at this point, we will
7230 do so when we convert this psymtab into a symtab. */
7232 add_partial_symbol (pdi
, cu
);
7236 if (! pdi
->has_children
)
7239 if (cu
->language
== language_ada
)
7241 pdi
= pdi
->die_child
;
7244 fixup_partial_die (pdi
, cu
);
7245 if (pdi
->tag
== DW_TAG_subprogram
7246 || pdi
->tag
== DW_TAG_lexical_block
)
7247 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7248 pdi
= pdi
->die_sibling
;
7253 /* Read a partial die corresponding to an enumeration type. */
7256 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
7257 struct dwarf2_cu
*cu
)
7259 struct partial_die_info
*pdi
;
7261 if (enum_pdi
->name
!= NULL
)
7262 add_partial_symbol (enum_pdi
, cu
);
7264 pdi
= enum_pdi
->die_child
;
7267 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
7268 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
7270 add_partial_symbol (pdi
, cu
);
7271 pdi
= pdi
->die_sibling
;
7275 /* Return the initial uleb128 in the die at INFO_PTR. */
7278 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
7280 unsigned int bytes_read
;
7282 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7285 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
7286 Return the corresponding abbrev, or NULL if the number is zero (indicating
7287 an empty DIE). In either case *BYTES_READ will be set to the length of
7288 the initial number. */
7290 static struct abbrev_info
*
7291 peek_die_abbrev (const gdb_byte
*info_ptr
, unsigned int *bytes_read
,
7292 struct dwarf2_cu
*cu
)
7294 bfd
*abfd
= cu
->objfile
->obfd
;
7295 unsigned int abbrev_number
;
7296 struct abbrev_info
*abbrev
;
7298 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
7300 if (abbrev_number
== 0)
7303 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
7306 error (_("Dwarf Error: Could not find abbrev number %d in %s"
7307 " at offset 0x%x [in module %s]"),
7308 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
7309 cu
->header
.offset
.sect_off
, bfd_get_filename (abfd
));
7315 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7316 Returns a pointer to the end of a series of DIEs, terminated by an empty
7317 DIE. Any children of the skipped DIEs will also be skipped. */
7319 static const gdb_byte
*
7320 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
7322 struct dwarf2_cu
*cu
= reader
->cu
;
7323 struct abbrev_info
*abbrev
;
7324 unsigned int bytes_read
;
7328 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
7330 return info_ptr
+ bytes_read
;
7332 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
7336 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7337 INFO_PTR should point just after the initial uleb128 of a DIE, and the
7338 abbrev corresponding to that skipped uleb128 should be passed in
7339 ABBREV. Returns a pointer to this DIE's sibling, skipping any
7342 static const gdb_byte
*
7343 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
7344 struct abbrev_info
*abbrev
)
7346 unsigned int bytes_read
;
7347 struct attribute attr
;
7348 bfd
*abfd
= reader
->abfd
;
7349 struct dwarf2_cu
*cu
= reader
->cu
;
7350 const gdb_byte
*buffer
= reader
->buffer
;
7351 const gdb_byte
*buffer_end
= reader
->buffer_end
;
7352 unsigned int form
, i
;
7354 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
7356 /* The only abbrev we care about is DW_AT_sibling. */
7357 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
7359 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
7360 if (attr
.form
== DW_FORM_ref_addr
)
7361 complaint (&symfile_complaints
,
7362 _("ignoring absolute DW_AT_sibling"));
7365 unsigned int off
= dwarf2_get_ref_die_offset (&attr
).sect_off
;
7366 const gdb_byte
*sibling_ptr
= buffer
+ off
;
7368 if (sibling_ptr
< info_ptr
)
7369 complaint (&symfile_complaints
,
7370 _("DW_AT_sibling points backwards"));
7371 else if (sibling_ptr
> reader
->buffer_end
)
7372 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
7378 /* If it isn't DW_AT_sibling, skip this attribute. */
7379 form
= abbrev
->attrs
[i
].form
;
7383 case DW_FORM_ref_addr
:
7384 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
7385 and later it is offset sized. */
7386 if (cu
->header
.version
== 2)
7387 info_ptr
+= cu
->header
.addr_size
;
7389 info_ptr
+= cu
->header
.offset_size
;
7391 case DW_FORM_GNU_ref_alt
:
7392 info_ptr
+= cu
->header
.offset_size
;
7395 info_ptr
+= cu
->header
.addr_size
;
7402 case DW_FORM_flag_present
:
7403 case DW_FORM_implicit_const
:
7415 case DW_FORM_ref_sig8
:
7418 case DW_FORM_data16
:
7421 case DW_FORM_string
:
7422 read_direct_string (abfd
, info_ptr
, &bytes_read
);
7423 info_ptr
+= bytes_read
;
7425 case DW_FORM_sec_offset
:
7427 case DW_FORM_GNU_strp_alt
:
7428 info_ptr
+= cu
->header
.offset_size
;
7430 case DW_FORM_exprloc
:
7432 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7433 info_ptr
+= bytes_read
;
7435 case DW_FORM_block1
:
7436 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
7438 case DW_FORM_block2
:
7439 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
7441 case DW_FORM_block4
:
7442 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
7446 case DW_FORM_ref_udata
:
7447 case DW_FORM_GNU_addr_index
:
7448 case DW_FORM_GNU_str_index
:
7449 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
7451 case DW_FORM_indirect
:
7452 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7453 info_ptr
+= bytes_read
;
7454 /* We need to continue parsing from here, so just go back to
7456 goto skip_attribute
;
7459 error (_("Dwarf Error: Cannot handle %s "
7460 "in DWARF reader [in module %s]"),
7461 dwarf_form_name (form
),
7462 bfd_get_filename (abfd
));
7466 if (abbrev
->has_children
)
7467 return skip_children (reader
, info_ptr
);
7472 /* Locate ORIG_PDI's sibling.
7473 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
7475 static const gdb_byte
*
7476 locate_pdi_sibling (const struct die_reader_specs
*reader
,
7477 struct partial_die_info
*orig_pdi
,
7478 const gdb_byte
*info_ptr
)
7480 /* Do we know the sibling already? */
7482 if (orig_pdi
->sibling
)
7483 return orig_pdi
->sibling
;
7485 /* Are there any children to deal with? */
7487 if (!orig_pdi
->has_children
)
7490 /* Skip the children the long way. */
7492 return skip_children (reader
, info_ptr
);
7495 /* Expand this partial symbol table into a full symbol table. SELF is
7499 dwarf2_read_symtab (struct partial_symtab
*self
,
7500 struct objfile
*objfile
)
7504 warning (_("bug: psymtab for %s is already read in."),
7511 printf_filtered (_("Reading in symbols for %s..."),
7513 gdb_flush (gdb_stdout
);
7516 /* Restore our global data. */
7518 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
7519 dwarf2_objfile_data_key
);
7521 /* If this psymtab is constructed from a debug-only objfile, the
7522 has_section_at_zero flag will not necessarily be correct. We
7523 can get the correct value for this flag by looking at the data
7524 associated with the (presumably stripped) associated objfile. */
7525 if (objfile
->separate_debug_objfile_backlink
)
7527 struct dwarf2_per_objfile
*dpo_backlink
7528 = ((struct dwarf2_per_objfile
*)
7529 objfile_data (objfile
->separate_debug_objfile_backlink
,
7530 dwarf2_objfile_data_key
));
7532 dwarf2_per_objfile
->has_section_at_zero
7533 = dpo_backlink
->has_section_at_zero
;
7536 dwarf2_per_objfile
->reading_partial_symbols
= 0;
7538 psymtab_to_symtab_1 (self
);
7540 /* Finish up the debug error message. */
7542 printf_filtered (_("done.\n"));
7545 process_cu_includes ();
7548 /* Reading in full CUs. */
7550 /* Add PER_CU to the queue. */
7553 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
7554 enum language pretend_language
)
7556 struct dwarf2_queue_item
*item
;
7559 item
= XNEW (struct dwarf2_queue_item
);
7560 item
->per_cu
= per_cu
;
7561 item
->pretend_language
= pretend_language
;
7564 if (dwarf2_queue
== NULL
)
7565 dwarf2_queue
= item
;
7567 dwarf2_queue_tail
->next
= item
;
7569 dwarf2_queue_tail
= item
;
7572 /* If PER_CU is not yet queued, add it to the queue.
7573 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
7575 The result is non-zero if PER_CU was queued, otherwise the result is zero
7576 meaning either PER_CU is already queued or it is already loaded.
7578 N.B. There is an invariant here that if a CU is queued then it is loaded.
7579 The caller is required to load PER_CU if we return non-zero. */
7582 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
7583 struct dwarf2_per_cu_data
*per_cu
,
7584 enum language pretend_language
)
7586 /* We may arrive here during partial symbol reading, if we need full
7587 DIEs to process an unusual case (e.g. template arguments). Do
7588 not queue PER_CU, just tell our caller to load its DIEs. */
7589 if (dwarf2_per_objfile
->reading_partial_symbols
)
7591 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
7596 /* Mark the dependence relation so that we don't flush PER_CU
7598 if (dependent_cu
!= NULL
)
7599 dwarf2_add_dependence (dependent_cu
, per_cu
);
7601 /* If it's already on the queue, we have nothing to do. */
7605 /* If the compilation unit is already loaded, just mark it as
7607 if (per_cu
->cu
!= NULL
)
7609 per_cu
->cu
->last_used
= 0;
7613 /* Add it to the queue. */
7614 queue_comp_unit (per_cu
, pretend_language
);
7619 /* Process the queue. */
7622 process_queue (void)
7624 struct dwarf2_queue_item
*item
, *next_item
;
7626 if (dwarf_read_debug
)
7628 fprintf_unfiltered (gdb_stdlog
,
7629 "Expanding one or more symtabs of objfile %s ...\n",
7630 objfile_name (dwarf2_per_objfile
->objfile
));
7633 /* The queue starts out with one item, but following a DIE reference
7634 may load a new CU, adding it to the end of the queue. */
7635 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
7637 if ((dwarf2_per_objfile
->using_index
7638 ? !item
->per_cu
->v
.quick
->compunit_symtab
7639 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
7640 /* Skip dummy CUs. */
7641 && item
->per_cu
->cu
!= NULL
)
7643 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
7644 unsigned int debug_print_threshold
;
7647 if (per_cu
->is_debug_types
)
7649 struct signatured_type
*sig_type
=
7650 (struct signatured_type
*) per_cu
;
7652 sprintf (buf
, "TU %s at offset 0x%x",
7653 hex_string (sig_type
->signature
),
7654 per_cu
->offset
.sect_off
);
7655 /* There can be 100s of TUs.
7656 Only print them in verbose mode. */
7657 debug_print_threshold
= 2;
7661 sprintf (buf
, "CU at offset 0x%x", per_cu
->offset
.sect_off
);
7662 debug_print_threshold
= 1;
7665 if (dwarf_read_debug
>= debug_print_threshold
)
7666 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
7668 if (per_cu
->is_debug_types
)
7669 process_full_type_unit (per_cu
, item
->pretend_language
);
7671 process_full_comp_unit (per_cu
, item
->pretend_language
);
7673 if (dwarf_read_debug
>= debug_print_threshold
)
7674 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
7677 item
->per_cu
->queued
= 0;
7678 next_item
= item
->next
;
7682 dwarf2_queue_tail
= NULL
;
7684 if (dwarf_read_debug
)
7686 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
7687 objfile_name (dwarf2_per_objfile
->objfile
));
7691 /* Free all allocated queue entries. This function only releases anything if
7692 an error was thrown; if the queue was processed then it would have been
7693 freed as we went along. */
7696 dwarf2_release_queue (void *dummy
)
7698 struct dwarf2_queue_item
*item
, *last
;
7700 item
= dwarf2_queue
;
7703 /* Anything still marked queued is likely to be in an
7704 inconsistent state, so discard it. */
7705 if (item
->per_cu
->queued
)
7707 if (item
->per_cu
->cu
!= NULL
)
7708 free_one_cached_comp_unit (item
->per_cu
);
7709 item
->per_cu
->queued
= 0;
7717 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
7720 /* Read in full symbols for PST, and anything it depends on. */
7723 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
7725 struct dwarf2_per_cu_data
*per_cu
;
7731 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
7732 if (!pst
->dependencies
[i
]->readin
7733 && pst
->dependencies
[i
]->user
== NULL
)
7735 /* Inform about additional files that need to be read in. */
7738 /* FIXME: i18n: Need to make this a single string. */
7739 fputs_filtered (" ", gdb_stdout
);
7741 fputs_filtered ("and ", gdb_stdout
);
7743 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
7744 wrap_here (""); /* Flush output. */
7745 gdb_flush (gdb_stdout
);
7747 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
7750 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
7754 /* It's an include file, no symbols to read for it.
7755 Everything is in the parent symtab. */
7760 dw2_do_instantiate_symtab (per_cu
);
7763 /* Trivial hash function for die_info: the hash value of a DIE
7764 is its offset in .debug_info for this objfile. */
7767 die_hash (const void *item
)
7769 const struct die_info
*die
= (const struct die_info
*) item
;
7771 return die
->offset
.sect_off
;
7774 /* Trivial comparison function for die_info structures: two DIEs
7775 are equal if they have the same offset. */
7778 die_eq (const void *item_lhs
, const void *item_rhs
)
7780 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
7781 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
7783 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
7786 /* die_reader_func for load_full_comp_unit.
7787 This is identical to read_signatured_type_reader,
7788 but is kept separate for now. */
7791 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
7792 const gdb_byte
*info_ptr
,
7793 struct die_info
*comp_unit_die
,
7797 struct dwarf2_cu
*cu
= reader
->cu
;
7798 enum language
*language_ptr
= (enum language
*) data
;
7800 gdb_assert (cu
->die_hash
== NULL
);
7802 htab_create_alloc_ex (cu
->header
.length
/ 12,
7806 &cu
->comp_unit_obstack
,
7807 hashtab_obstack_allocate
,
7808 dummy_obstack_deallocate
);
7811 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
7812 &info_ptr
, comp_unit_die
);
7813 cu
->dies
= comp_unit_die
;
7814 /* comp_unit_die is not stored in die_hash, no need. */
7816 /* We try not to read any attributes in this function, because not
7817 all CUs needed for references have been loaded yet, and symbol
7818 table processing isn't initialized. But we have to set the CU language,
7819 or we won't be able to build types correctly.
7820 Similarly, if we do not read the producer, we can not apply
7821 producer-specific interpretation. */
7822 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
7825 /* Load the DIEs associated with PER_CU into memory. */
7828 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7829 enum language pretend_language
)
7831 gdb_assert (! this_cu
->is_debug_types
);
7833 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
7834 load_full_comp_unit_reader
, &pretend_language
);
7837 /* Add a DIE to the delayed physname list. */
7840 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
7841 const char *name
, struct die_info
*die
,
7842 struct dwarf2_cu
*cu
)
7844 struct delayed_method_info mi
;
7846 mi
.fnfield_index
= fnfield_index
;
7850 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
7853 /* A cleanup for freeing the delayed method list. */
7856 free_delayed_list (void *ptr
)
7858 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
7859 if (cu
->method_list
!= NULL
)
7861 VEC_free (delayed_method_info
, cu
->method_list
);
7862 cu
->method_list
= NULL
;
7866 /* Compute the physnames of any methods on the CU's method list.
7868 The computation of method physnames is delayed in order to avoid the
7869 (bad) condition that one of the method's formal parameters is of an as yet
7873 compute_delayed_physnames (struct dwarf2_cu
*cu
)
7876 struct delayed_method_info
*mi
;
7877 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
7879 const char *physname
;
7880 struct fn_fieldlist
*fn_flp
7881 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
7882 physname
= dwarf2_physname (mi
->name
, mi
->die
, cu
);
7883 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
->index
)
7884 = physname
? physname
: "";
7888 /* Go objects should be embedded in a DW_TAG_module DIE,
7889 and it's not clear if/how imported objects will appear.
7890 To keep Go support simple until that's worked out,
7891 go back through what we've read and create something usable.
7892 We could do this while processing each DIE, and feels kinda cleaner,
7893 but that way is more invasive.
7894 This is to, for example, allow the user to type "p var" or "b main"
7895 without having to specify the package name, and allow lookups
7896 of module.object to work in contexts that use the expression
7900 fixup_go_packaging (struct dwarf2_cu
*cu
)
7902 char *package_name
= NULL
;
7903 struct pending
*list
;
7906 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
7908 for (i
= 0; i
< list
->nsyms
; ++i
)
7910 struct symbol
*sym
= list
->symbol
[i
];
7912 if (SYMBOL_LANGUAGE (sym
) == language_go
7913 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
7915 char *this_package_name
= go_symbol_package_name (sym
);
7917 if (this_package_name
== NULL
)
7919 if (package_name
== NULL
)
7920 package_name
= this_package_name
;
7923 if (strcmp (package_name
, this_package_name
) != 0)
7924 complaint (&symfile_complaints
,
7925 _("Symtab %s has objects from two different Go packages: %s and %s"),
7926 (symbol_symtab (sym
) != NULL
7927 ? symtab_to_filename_for_display
7928 (symbol_symtab (sym
))
7929 : objfile_name (cu
->objfile
)),
7930 this_package_name
, package_name
);
7931 xfree (this_package_name
);
7937 if (package_name
!= NULL
)
7939 struct objfile
*objfile
= cu
->objfile
;
7940 const char *saved_package_name
7941 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
7943 strlen (package_name
));
7944 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
7945 saved_package_name
);
7948 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7950 sym
= allocate_symbol (objfile
);
7951 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
7952 SYMBOL_SET_NAMES (sym
, saved_package_name
,
7953 strlen (saved_package_name
), 0, objfile
);
7954 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
7955 e.g., "main" finds the "main" module and not C's main(). */
7956 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7957 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
7958 SYMBOL_TYPE (sym
) = type
;
7960 add_symbol_to_list (sym
, &global_symbols
);
7962 xfree (package_name
);
7966 /* Return the symtab for PER_CU. This works properly regardless of
7967 whether we're using the index or psymtabs. */
7969 static struct compunit_symtab
*
7970 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
7972 return (dwarf2_per_objfile
->using_index
7973 ? per_cu
->v
.quick
->compunit_symtab
7974 : per_cu
->v
.psymtab
->compunit_symtab
);
7977 /* A helper function for computing the list of all symbol tables
7978 included by PER_CU. */
7981 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
7982 htab_t all_children
, htab_t all_type_symtabs
,
7983 struct dwarf2_per_cu_data
*per_cu
,
7984 struct compunit_symtab
*immediate_parent
)
7988 struct compunit_symtab
*cust
;
7989 struct dwarf2_per_cu_data
*iter
;
7991 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
7994 /* This inclusion and its children have been processed. */
7999 /* Only add a CU if it has a symbol table. */
8000 cust
= get_compunit_symtab (per_cu
);
8003 /* If this is a type unit only add its symbol table if we haven't
8004 seen it yet (type unit per_cu's can share symtabs). */
8005 if (per_cu
->is_debug_types
)
8007 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
8011 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
8012 if (cust
->user
== NULL
)
8013 cust
->user
= immediate_parent
;
8018 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
8019 if (cust
->user
== NULL
)
8020 cust
->user
= immediate_parent
;
8025 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
8028 recursively_compute_inclusions (result
, all_children
,
8029 all_type_symtabs
, iter
, cust
);
8033 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
8037 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
8039 gdb_assert (! per_cu
->is_debug_types
);
8041 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
8044 struct dwarf2_per_cu_data
*per_cu_iter
;
8045 struct compunit_symtab
*compunit_symtab_iter
;
8046 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
8047 htab_t all_children
, all_type_symtabs
;
8048 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
8050 /* If we don't have a symtab, we can just skip this case. */
8054 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
8055 NULL
, xcalloc
, xfree
);
8056 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
8057 NULL
, xcalloc
, xfree
);
8060 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
8064 recursively_compute_inclusions (&result_symtabs
, all_children
,
8065 all_type_symtabs
, per_cu_iter
,
8069 /* Now we have a transitive closure of all the included symtabs. */
8070 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
8072 = XOBNEWVEC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
8073 struct compunit_symtab
*, len
+ 1);
8075 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
8076 compunit_symtab_iter
);
8078 cust
->includes
[ix
] = compunit_symtab_iter
;
8079 cust
->includes
[len
] = NULL
;
8081 VEC_free (compunit_symtab_ptr
, result_symtabs
);
8082 htab_delete (all_children
);
8083 htab_delete (all_type_symtabs
);
8087 /* Compute the 'includes' field for the symtabs of all the CUs we just
8091 process_cu_includes (void)
8094 struct dwarf2_per_cu_data
*iter
;
8097 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
8101 if (! iter
->is_debug_types
)
8102 compute_compunit_symtab_includes (iter
);
8105 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
8108 /* Generate full symbol information for PER_CU, whose DIEs have
8109 already been loaded into memory. */
8112 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8113 enum language pretend_language
)
8115 struct dwarf2_cu
*cu
= per_cu
->cu
;
8116 struct objfile
*objfile
= per_cu
->objfile
;
8117 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8118 CORE_ADDR lowpc
, highpc
;
8119 struct compunit_symtab
*cust
;
8120 struct cleanup
*back_to
, *delayed_list_cleanup
;
8122 struct block
*static_block
;
8125 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8128 back_to
= make_cleanup (really_free_pendings
, NULL
);
8129 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8131 cu
->list_in_scope
= &file_symbols
;
8133 cu
->language
= pretend_language
;
8134 cu
->language_defn
= language_def (cu
->language
);
8136 /* Do line number decoding in read_file_scope () */
8137 process_die (cu
->dies
, cu
);
8139 /* For now fudge the Go package. */
8140 if (cu
->language
== language_go
)
8141 fixup_go_packaging (cu
);
8143 /* Now that we have processed all the DIEs in the CU, all the types
8144 should be complete, and it should now be safe to compute all of the
8146 compute_delayed_physnames (cu
);
8147 do_cleanups (delayed_list_cleanup
);
8149 /* Some compilers don't define a DW_AT_high_pc attribute for the
8150 compilation unit. If the DW_AT_high_pc is missing, synthesize
8151 it, by scanning the DIE's below the compilation unit. */
8152 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
8154 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
8155 static_block
= end_symtab_get_static_block (addr
, 0, 1);
8157 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
8158 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
8159 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
8160 addrmap to help ensure it has an accurate map of pc values belonging to
8162 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
8164 cust
= end_symtab_from_static_block (static_block
,
8165 SECT_OFF_TEXT (objfile
), 0);
8169 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
8171 /* Set symtab language to language from DW_AT_language. If the
8172 compilation is from a C file generated by language preprocessors, do
8173 not set the language if it was already deduced by start_subfile. */
8174 if (!(cu
->language
== language_c
8175 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
8176 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8178 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
8179 produce DW_AT_location with location lists but it can be possibly
8180 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
8181 there were bugs in prologue debug info, fixed later in GCC-4.5
8182 by "unwind info for epilogues" patch (which is not directly related).
8184 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
8185 needed, it would be wrong due to missing DW_AT_producer there.
8187 Still one can confuse GDB by using non-standard GCC compilation
8188 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
8190 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
8191 cust
->locations_valid
= 1;
8193 if (gcc_4_minor
>= 5)
8194 cust
->epilogue_unwind_valid
= 1;
8196 cust
->call_site_htab
= cu
->call_site_htab
;
8199 if (dwarf2_per_objfile
->using_index
)
8200 per_cu
->v
.quick
->compunit_symtab
= cust
;
8203 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8204 pst
->compunit_symtab
= cust
;
8208 /* Push it for inclusion processing later. */
8209 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
8211 do_cleanups (back_to
);
8214 /* Generate full symbol information for type unit PER_CU, whose DIEs have
8215 already been loaded into memory. */
8218 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
8219 enum language pretend_language
)
8221 struct dwarf2_cu
*cu
= per_cu
->cu
;
8222 struct objfile
*objfile
= per_cu
->objfile
;
8223 struct compunit_symtab
*cust
;
8224 struct cleanup
*back_to
, *delayed_list_cleanup
;
8225 struct signatured_type
*sig_type
;
8227 gdb_assert (per_cu
->is_debug_types
);
8228 sig_type
= (struct signatured_type
*) per_cu
;
8231 back_to
= make_cleanup (really_free_pendings
, NULL
);
8232 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8234 cu
->list_in_scope
= &file_symbols
;
8236 cu
->language
= pretend_language
;
8237 cu
->language_defn
= language_def (cu
->language
);
8239 /* The symbol tables are set up in read_type_unit_scope. */
8240 process_die (cu
->dies
, cu
);
8242 /* For now fudge the Go package. */
8243 if (cu
->language
== language_go
)
8244 fixup_go_packaging (cu
);
8246 /* Now that we have processed all the DIEs in the CU, all the types
8247 should be complete, and it should now be safe to compute all of the
8249 compute_delayed_physnames (cu
);
8250 do_cleanups (delayed_list_cleanup
);
8252 /* TUs share symbol tables.
8253 If this is the first TU to use this symtab, complete the construction
8254 of it with end_expandable_symtab. Otherwise, complete the addition of
8255 this TU's symbols to the existing symtab. */
8256 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
8258 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
8259 sig_type
->type_unit_group
->compunit_symtab
= cust
;
8263 /* Set symtab language to language from DW_AT_language. If the
8264 compilation is from a C file generated by language preprocessors,
8265 do not set the language if it was already deduced by
8267 if (!(cu
->language
== language_c
8268 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
8269 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8274 augment_type_symtab ();
8275 cust
= sig_type
->type_unit_group
->compunit_symtab
;
8278 if (dwarf2_per_objfile
->using_index
)
8279 per_cu
->v
.quick
->compunit_symtab
= cust
;
8282 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8283 pst
->compunit_symtab
= cust
;
8287 do_cleanups (back_to
);
8290 /* Process an imported unit DIE. */
8293 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8295 struct attribute
*attr
;
8297 /* For now we don't handle imported units in type units. */
8298 if (cu
->per_cu
->is_debug_types
)
8300 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8301 " supported in type units [in module %s]"),
8302 objfile_name (cu
->objfile
));
8305 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8308 struct dwarf2_per_cu_data
*per_cu
;
8312 offset
= dwarf2_get_ref_die_offset (attr
);
8313 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
8314 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
8316 /* If necessary, add it to the queue and load its DIEs. */
8317 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
8318 load_full_comp_unit (per_cu
, cu
->language
);
8320 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8325 /* Reset the in_process bit of a die. */
8328 reset_die_in_process (void *arg
)
8330 struct die_info
*die
= (struct die_info
*) arg
;
8332 die
->in_process
= 0;
8335 /* Process a die and its children. */
8338 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8340 struct cleanup
*in_process
;
8342 /* We should only be processing those not already in process. */
8343 gdb_assert (!die
->in_process
);
8345 die
->in_process
= 1;
8346 in_process
= make_cleanup (reset_die_in_process
,die
);
8350 case DW_TAG_padding
:
8352 case DW_TAG_compile_unit
:
8353 case DW_TAG_partial_unit
:
8354 read_file_scope (die
, cu
);
8356 case DW_TAG_type_unit
:
8357 read_type_unit_scope (die
, cu
);
8359 case DW_TAG_subprogram
:
8360 case DW_TAG_inlined_subroutine
:
8361 read_func_scope (die
, cu
);
8363 case DW_TAG_lexical_block
:
8364 case DW_TAG_try_block
:
8365 case DW_TAG_catch_block
:
8366 read_lexical_block_scope (die
, cu
);
8368 case DW_TAG_call_site
:
8369 case DW_TAG_GNU_call_site
:
8370 read_call_site_scope (die
, cu
);
8372 case DW_TAG_class_type
:
8373 case DW_TAG_interface_type
:
8374 case DW_TAG_structure_type
:
8375 case DW_TAG_union_type
:
8376 process_structure_scope (die
, cu
);
8378 case DW_TAG_enumeration_type
:
8379 process_enumeration_scope (die
, cu
);
8382 /* These dies have a type, but processing them does not create
8383 a symbol or recurse to process the children. Therefore we can
8384 read them on-demand through read_type_die. */
8385 case DW_TAG_subroutine_type
:
8386 case DW_TAG_set_type
:
8387 case DW_TAG_array_type
:
8388 case DW_TAG_pointer_type
:
8389 case DW_TAG_ptr_to_member_type
:
8390 case DW_TAG_reference_type
:
8391 case DW_TAG_string_type
:
8394 case DW_TAG_base_type
:
8395 case DW_TAG_subrange_type
:
8396 case DW_TAG_typedef
:
8397 /* Add a typedef symbol for the type definition, if it has a
8399 new_symbol (die
, read_type_die (die
, cu
), cu
);
8401 case DW_TAG_common_block
:
8402 read_common_block (die
, cu
);
8404 case DW_TAG_common_inclusion
:
8406 case DW_TAG_namespace
:
8407 cu
->processing_has_namespace_info
= 1;
8408 read_namespace (die
, cu
);
8411 cu
->processing_has_namespace_info
= 1;
8412 read_module (die
, cu
);
8414 case DW_TAG_imported_declaration
:
8415 cu
->processing_has_namespace_info
= 1;
8416 if (read_namespace_alias (die
, cu
))
8418 /* The declaration is not a global namespace alias: fall through. */
8419 case DW_TAG_imported_module
:
8420 cu
->processing_has_namespace_info
= 1;
8421 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
8422 || cu
->language
!= language_fortran
))
8423 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
8424 dwarf_tag_name (die
->tag
));
8425 read_import_statement (die
, cu
);
8428 case DW_TAG_imported_unit
:
8429 process_imported_unit_die (die
, cu
);
8433 new_symbol (die
, NULL
, cu
);
8437 do_cleanups (in_process
);
8440 /* DWARF name computation. */
8442 /* A helper function for dwarf2_compute_name which determines whether DIE
8443 needs to have the name of the scope prepended to the name listed in the
8447 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8449 struct attribute
*attr
;
8453 case DW_TAG_namespace
:
8454 case DW_TAG_typedef
:
8455 case DW_TAG_class_type
:
8456 case DW_TAG_interface_type
:
8457 case DW_TAG_structure_type
:
8458 case DW_TAG_union_type
:
8459 case DW_TAG_enumeration_type
:
8460 case DW_TAG_enumerator
:
8461 case DW_TAG_subprogram
:
8462 case DW_TAG_inlined_subroutine
:
8464 case DW_TAG_imported_declaration
:
8467 case DW_TAG_variable
:
8468 case DW_TAG_constant
:
8469 /* We only need to prefix "globally" visible variables. These include
8470 any variable marked with DW_AT_external or any variable that
8471 lives in a namespace. [Variables in anonymous namespaces
8472 require prefixing, but they are not DW_AT_external.] */
8474 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
8476 struct dwarf2_cu
*spec_cu
= cu
;
8478 return die_needs_namespace (die_specification (die
, &spec_cu
),
8482 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8483 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
8484 && die
->parent
->tag
!= DW_TAG_module
)
8486 /* A variable in a lexical block of some kind does not need a
8487 namespace, even though in C++ such variables may be external
8488 and have a mangled name. */
8489 if (die
->parent
->tag
== DW_TAG_lexical_block
8490 || die
->parent
->tag
== DW_TAG_try_block
8491 || die
->parent
->tag
== DW_TAG_catch_block
8492 || die
->parent
->tag
== DW_TAG_subprogram
)
8501 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
8502 compute the physname for the object, which include a method's:
8503 - formal parameters (C++),
8504 - receiver type (Go),
8506 The term "physname" is a bit confusing.
8507 For C++, for example, it is the demangled name.
8508 For Go, for example, it's the mangled name.
8510 For Ada, return the DIE's linkage name rather than the fully qualified
8511 name. PHYSNAME is ignored..
8513 The result is allocated on the objfile_obstack and canonicalized. */
8516 dwarf2_compute_name (const char *name
,
8517 struct die_info
*die
, struct dwarf2_cu
*cu
,
8520 struct objfile
*objfile
= cu
->objfile
;
8523 name
= dwarf2_name (die
, cu
);
8525 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
8526 but otherwise compute it by typename_concat inside GDB.
8527 FIXME: Actually this is not really true, or at least not always true.
8528 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
8529 Fortran names because there is no mangling standard. So new_symbol_full
8530 will set the demangled name to the result of dwarf2_full_name, and it is
8531 the demangled name that GDB uses if it exists. */
8532 if (cu
->language
== language_ada
8533 || (cu
->language
== language_fortran
&& physname
))
8535 /* For Ada unit, we prefer the linkage name over the name, as
8536 the former contains the exported name, which the user expects
8537 to be able to reference. Ideally, we want the user to be able
8538 to reference this entity using either natural or linkage name,
8539 but we haven't started looking at this enhancement yet. */
8540 const char *linkage_name
;
8542 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
8543 if (linkage_name
== NULL
)
8544 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8545 if (linkage_name
!= NULL
)
8546 return linkage_name
;
8549 /* These are the only languages we know how to qualify names in. */
8551 && (cu
->language
== language_cplus
8552 || cu
->language
== language_fortran
|| cu
->language
== language_d
8553 || cu
->language
== language_rust
))
8555 if (die_needs_namespace (die
, cu
))
8559 const char *canonical_name
= NULL
;
8563 prefix
= determine_prefix (die
, cu
);
8564 if (*prefix
!= '\0')
8566 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
8569 buf
.puts (prefixed_name
);
8570 xfree (prefixed_name
);
8575 /* Template parameters may be specified in the DIE's DW_AT_name, or
8576 as children with DW_TAG_template_type_param or
8577 DW_TAG_value_type_param. If the latter, add them to the name
8578 here. If the name already has template parameters, then
8579 skip this step; some versions of GCC emit both, and
8580 it is more efficient to use the pre-computed name.
8582 Something to keep in mind about this process: it is very
8583 unlikely, or in some cases downright impossible, to produce
8584 something that will match the mangled name of a function.
8585 If the definition of the function has the same debug info,
8586 we should be able to match up with it anyway. But fallbacks
8587 using the minimal symbol, for instance to find a method
8588 implemented in a stripped copy of libstdc++, will not work.
8589 If we do not have debug info for the definition, we will have to
8590 match them up some other way.
8592 When we do name matching there is a related problem with function
8593 templates; two instantiated function templates are allowed to
8594 differ only by their return types, which we do not add here. */
8596 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
8598 struct attribute
*attr
;
8599 struct die_info
*child
;
8602 die
->building_fullname
= 1;
8604 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
8608 const gdb_byte
*bytes
;
8609 struct dwarf2_locexpr_baton
*baton
;
8612 if (child
->tag
!= DW_TAG_template_type_param
8613 && child
->tag
!= DW_TAG_template_value_param
)
8624 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
8627 complaint (&symfile_complaints
,
8628 _("template parameter missing DW_AT_type"));
8629 buf
.puts ("UNKNOWN_TYPE");
8632 type
= die_type (child
, cu
);
8634 if (child
->tag
== DW_TAG_template_type_param
)
8636 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
8640 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
8643 complaint (&symfile_complaints
,
8644 _("template parameter missing "
8645 "DW_AT_const_value"));
8646 buf
.puts ("UNKNOWN_VALUE");
8650 dwarf2_const_value_attr (attr
, type
, name
,
8651 &cu
->comp_unit_obstack
, cu
,
8652 &value
, &bytes
, &baton
);
8654 if (TYPE_NOSIGN (type
))
8655 /* GDB prints characters as NUMBER 'CHAR'. If that's
8656 changed, this can use value_print instead. */
8657 c_printchar (value
, type
, &buf
);
8660 struct value_print_options opts
;
8663 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
8667 else if (bytes
!= NULL
)
8669 v
= allocate_value (type
);
8670 memcpy (value_contents_writeable (v
), bytes
,
8671 TYPE_LENGTH (type
));
8674 v
= value_from_longest (type
, value
);
8676 /* Specify decimal so that we do not depend on
8678 get_formatted_print_options (&opts
, 'd');
8680 value_print (v
, &buf
, &opts
);
8686 die
->building_fullname
= 0;
8690 /* Close the argument list, with a space if necessary
8691 (nested templates). */
8692 if (!buf
.empty () && buf
.string ().back () == '>')
8699 /* For C++ methods, append formal parameter type
8700 information, if PHYSNAME. */
8702 if (physname
&& die
->tag
== DW_TAG_subprogram
8703 && cu
->language
== language_cplus
)
8705 struct type
*type
= read_type_die (die
, cu
);
8707 c_type_print_args (type
, &buf
, 1, cu
->language
,
8708 &type_print_raw_options
);
8710 if (cu
->language
== language_cplus
)
8712 /* Assume that an artificial first parameter is
8713 "this", but do not crash if it is not. RealView
8714 marks unnamed (and thus unused) parameters as
8715 artificial; there is no way to differentiate
8717 if (TYPE_NFIELDS (type
) > 0
8718 && TYPE_FIELD_ARTIFICIAL (type
, 0)
8719 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
8720 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
8722 buf
.puts (" const");
8726 const std::string
&intermediate_name
= buf
.string ();
8728 if (cu
->language
== language_cplus
)
8730 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
8731 &objfile
->per_bfd
->storage_obstack
);
8733 /* If we only computed INTERMEDIATE_NAME, or if
8734 INTERMEDIATE_NAME is already canonical, then we need to
8735 copy it to the appropriate obstack. */
8736 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
8737 name
= ((const char *)
8738 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8739 intermediate_name
.c_str (),
8740 intermediate_name
.length ()));
8742 name
= canonical_name
;
8749 /* Return the fully qualified name of DIE, based on its DW_AT_name.
8750 If scope qualifiers are appropriate they will be added. The result
8751 will be allocated on the storage_obstack, or NULL if the DIE does
8752 not have a name. NAME may either be from a previous call to
8753 dwarf2_name or NULL.
8755 The output string will be canonicalized (if C++). */
8758 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8760 return dwarf2_compute_name (name
, die
, cu
, 0);
8763 /* Construct a physname for the given DIE in CU. NAME may either be
8764 from a previous call to dwarf2_name or NULL. The result will be
8765 allocated on the objfile_objstack or NULL if the DIE does not have a
8768 The output string will be canonicalized (if C++). */
8771 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8773 struct objfile
*objfile
= cu
->objfile
;
8774 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
8775 struct cleanup
*back_to
;
8778 /* In this case dwarf2_compute_name is just a shortcut not building anything
8780 if (!die_needs_namespace (die
, cu
))
8781 return dwarf2_compute_name (name
, die
, cu
, 1);
8783 back_to
= make_cleanup (null_cleanup
, NULL
);
8785 mangled
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
8786 if (mangled
== NULL
)
8787 mangled
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8789 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
8790 See https://github.com/rust-lang/rust/issues/32925. */
8791 if (cu
->language
== language_rust
&& mangled
!= NULL
8792 && strchr (mangled
, '{') != NULL
)
8795 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
8797 if (mangled
!= NULL
)
8801 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
8802 type. It is easier for GDB users to search for such functions as
8803 `name(params)' than `long name(params)'. In such case the minimal
8804 symbol names do not match the full symbol names but for template
8805 functions there is never a need to look up their definition from their
8806 declaration so the only disadvantage remains the minimal symbol
8807 variant `long name(params)' does not have the proper inferior type.
8810 if (cu
->language
== language_go
)
8812 /* This is a lie, but we already lie to the caller new_symbol_full.
8813 new_symbol_full assumes we return the mangled name.
8814 This just undoes that lie until things are cleaned up. */
8819 demangled
= gdb_demangle (mangled
,
8820 (DMGL_PARAMS
| DMGL_ANSI
| DMGL_RET_DROP
));
8824 make_cleanup (xfree
, demangled
);
8834 if (canon
== NULL
|| check_physname
)
8836 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
8838 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
8840 /* It may not mean a bug in GDB. The compiler could also
8841 compute DW_AT_linkage_name incorrectly. But in such case
8842 GDB would need to be bug-to-bug compatible. */
8844 complaint (&symfile_complaints
,
8845 _("Computed physname <%s> does not match demangled <%s> "
8846 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
8847 physname
, canon
, mangled
, die
->offset
.sect_off
,
8848 objfile_name (objfile
));
8850 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
8851 is available here - over computed PHYSNAME. It is safer
8852 against both buggy GDB and buggy compilers. */
8866 retval
= ((const char *)
8867 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8868 retval
, strlen (retval
)));
8870 do_cleanups (back_to
);
8874 /* Inspect DIE in CU for a namespace alias. If one exists, record
8875 a new symbol for it.
8877 Returns 1 if a namespace alias was recorded, 0 otherwise. */
8880 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
8882 struct attribute
*attr
;
8884 /* If the die does not have a name, this is not a namespace
8886 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8890 struct die_info
*d
= die
;
8891 struct dwarf2_cu
*imported_cu
= cu
;
8893 /* If the compiler has nested DW_AT_imported_declaration DIEs,
8894 keep inspecting DIEs until we hit the underlying import. */
8895 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
8896 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
8898 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
8902 d
= follow_die_ref (d
, attr
, &imported_cu
);
8903 if (d
->tag
!= DW_TAG_imported_declaration
)
8907 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
8909 complaint (&symfile_complaints
,
8910 _("DIE at 0x%x has too many recursively imported "
8911 "declarations"), d
->offset
.sect_off
);
8918 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
8920 type
= get_die_type_at_offset (offset
, cu
->per_cu
);
8921 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
8923 /* This declaration is a global namespace alias. Add
8924 a symbol for it whose type is the aliased namespace. */
8925 new_symbol (die
, type
, cu
);
8934 /* Return the using directives repository (global or local?) to use in the
8935 current context for LANGUAGE.
8937 For Ada, imported declarations can materialize renamings, which *may* be
8938 global. However it is impossible (for now?) in DWARF to distinguish
8939 "external" imported declarations and "static" ones. As all imported
8940 declarations seem to be static in all other languages, make them all CU-wide
8941 global only in Ada. */
8943 static struct using_direct
**
8944 using_directives (enum language language
)
8946 if (language
== language_ada
&& context_stack_depth
== 0)
8947 return &global_using_directives
;
8949 return &local_using_directives
;
8952 /* Read the import statement specified by the given die and record it. */
8955 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
8957 struct objfile
*objfile
= cu
->objfile
;
8958 struct attribute
*import_attr
;
8959 struct die_info
*imported_die
, *child_die
;
8960 struct dwarf2_cu
*imported_cu
;
8961 const char *imported_name
;
8962 const char *imported_name_prefix
;
8963 const char *canonical_name
;
8964 const char *import_alias
;
8965 const char *imported_declaration
= NULL
;
8966 const char *import_prefix
;
8967 VEC (const_char_ptr
) *excludes
= NULL
;
8968 struct cleanup
*cleanups
;
8970 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8971 if (import_attr
== NULL
)
8973 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
8974 dwarf_tag_name (die
->tag
));
8979 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
8980 imported_name
= dwarf2_name (imported_die
, imported_cu
);
8981 if (imported_name
== NULL
)
8983 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
8985 The import in the following code:
8999 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
9000 <52> DW_AT_decl_file : 1
9001 <53> DW_AT_decl_line : 6
9002 <54> DW_AT_import : <0x75>
9003 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
9005 <5b> DW_AT_decl_file : 1
9006 <5c> DW_AT_decl_line : 2
9007 <5d> DW_AT_type : <0x6e>
9009 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
9010 <76> DW_AT_byte_size : 4
9011 <77> DW_AT_encoding : 5 (signed)
9013 imports the wrong die ( 0x75 instead of 0x58 ).
9014 This case will be ignored until the gcc bug is fixed. */
9018 /* Figure out the local name after import. */
9019 import_alias
= dwarf2_name (die
, cu
);
9021 /* Figure out where the statement is being imported to. */
9022 import_prefix
= determine_prefix (die
, cu
);
9024 /* Figure out what the scope of the imported die is and prepend it
9025 to the name of the imported die. */
9026 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
9028 if (imported_die
->tag
!= DW_TAG_namespace
9029 && imported_die
->tag
!= DW_TAG_module
)
9031 imported_declaration
= imported_name
;
9032 canonical_name
= imported_name_prefix
;
9034 else if (strlen (imported_name_prefix
) > 0)
9035 canonical_name
= obconcat (&objfile
->objfile_obstack
,
9036 imported_name_prefix
,
9037 (cu
->language
== language_d
? "." : "::"),
9038 imported_name
, (char *) NULL
);
9040 canonical_name
= imported_name
;
9042 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
9044 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
9045 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
9046 child_die
= sibling_die (child_die
))
9048 /* DWARF-4: A Fortran use statement with a “rename list” may be
9049 represented by an imported module entry with an import attribute
9050 referring to the module and owned entries corresponding to those
9051 entities that are renamed as part of being imported. */
9053 if (child_die
->tag
!= DW_TAG_imported_declaration
)
9055 complaint (&symfile_complaints
,
9056 _("child DW_TAG_imported_declaration expected "
9057 "- DIE at 0x%x [in module %s]"),
9058 child_die
->offset
.sect_off
, objfile_name (objfile
));
9062 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
9063 if (import_attr
== NULL
)
9065 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
9066 dwarf_tag_name (child_die
->tag
));
9071 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
9073 imported_name
= dwarf2_name (imported_die
, imported_cu
);
9074 if (imported_name
== NULL
)
9076 complaint (&symfile_complaints
,
9077 _("child DW_TAG_imported_declaration has unknown "
9078 "imported name - DIE at 0x%x [in module %s]"),
9079 child_die
->offset
.sect_off
, objfile_name (objfile
));
9083 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
9085 process_die (child_die
, cu
);
9088 add_using_directive (using_directives (cu
->language
),
9092 imported_declaration
,
9095 &objfile
->objfile_obstack
);
9097 do_cleanups (cleanups
);
9100 /* Cleanup function for handle_DW_AT_stmt_list. */
9103 free_cu_line_header (void *arg
)
9105 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) arg
;
9107 free_line_header (cu
->line_header
);
9108 cu
->line_header
= NULL
;
9111 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
9112 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
9113 this, it was first present in GCC release 4.3.0. */
9116 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
9118 if (!cu
->checked_producer
)
9119 check_producer (cu
);
9121 return cu
->producer_is_gcc_lt_4_3
;
9125 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
9126 const char **name
, const char **comp_dir
)
9128 /* Find the filename. Do not use dwarf2_name here, since the filename
9129 is not a source language identifier. */
9130 *name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
9131 *comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
9133 if (*comp_dir
== NULL
9134 && producer_is_gcc_lt_4_3 (cu
) && *name
!= NULL
9135 && IS_ABSOLUTE_PATH (*name
))
9137 char *d
= ldirname (*name
);
9141 make_cleanup (xfree
, d
);
9143 if (*comp_dir
!= NULL
)
9145 /* Irix 6.2 native cc prepends <machine>.: to the compilation
9146 directory, get rid of it. */
9147 const char *cp
= strchr (*comp_dir
, ':');
9149 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
9154 *name
= "<unknown>";
9157 /* Handle DW_AT_stmt_list for a compilation unit.
9158 DIE is the DW_TAG_compile_unit die for CU.
9159 COMP_DIR is the compilation directory. LOWPC is passed to
9160 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
9163 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
9164 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
9166 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9167 struct attribute
*attr
;
9168 unsigned int line_offset
;
9169 struct line_header line_header_local
;
9170 hashval_t line_header_local_hash
;
9175 gdb_assert (! cu
->per_cu
->is_debug_types
);
9177 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9181 line_offset
= DW_UNSND (attr
);
9183 /* The line header hash table is only created if needed (it exists to
9184 prevent redundant reading of the line table for partial_units).
9185 If we're given a partial_unit, we'll need it. If we're given a
9186 compile_unit, then use the line header hash table if it's already
9187 created, but don't create one just yet. */
9189 if (dwarf2_per_objfile
->line_header_hash
== NULL
9190 && die
->tag
== DW_TAG_partial_unit
)
9192 dwarf2_per_objfile
->line_header_hash
9193 = htab_create_alloc_ex (127, line_header_hash_voidp
,
9194 line_header_eq_voidp
,
9195 free_line_header_voidp
,
9196 &objfile
->objfile_obstack
,
9197 hashtab_obstack_allocate
,
9198 dummy_obstack_deallocate
);
9201 line_header_local
.offset
.sect_off
= line_offset
;
9202 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
9203 line_header_local_hash
= line_header_hash (&line_header_local
);
9204 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
9206 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9208 line_header_local_hash
, NO_INSERT
);
9210 /* For DW_TAG_compile_unit we need info like symtab::linetable which
9211 is not present in *SLOT (since if there is something in *SLOT then
9212 it will be for a partial_unit). */
9213 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
9215 gdb_assert (*slot
!= NULL
);
9216 cu
->line_header
= (struct line_header
*) *slot
;
9221 /* dwarf_decode_line_header does not yet provide sufficient information.
9222 We always have to call also dwarf_decode_lines for it. */
9223 cu
->line_header
= dwarf_decode_line_header (line_offset
, cu
);
9224 if (cu
->line_header
== NULL
)
9227 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
9231 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9233 line_header_local_hash
, INSERT
);
9234 gdb_assert (slot
!= NULL
);
9236 if (slot
!= NULL
&& *slot
== NULL
)
9238 /* This newly decoded line number information unit will be owned
9239 by line_header_hash hash table. */
9240 *slot
= cu
->line_header
;
9244 /* We cannot free any current entry in (*slot) as that struct line_header
9245 may be already used by multiple CUs. Create only temporary decoded
9246 line_header for this CU - it may happen at most once for each line
9247 number information unit. And if we're not using line_header_hash
9248 then this is what we want as well. */
9249 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
9250 make_cleanup (free_cu_line_header
, cu
);
9252 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
9253 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
9257 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
9260 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9262 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9263 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9264 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
9265 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
9266 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
9267 struct attribute
*attr
;
9268 const char *name
= NULL
;
9269 const char *comp_dir
= NULL
;
9270 struct die_info
*child_die
;
9273 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9275 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
9277 /* If we didn't find a lowpc, set it to highpc to avoid complaints
9278 from finish_block. */
9279 if (lowpc
== ((CORE_ADDR
) -1))
9281 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
9283 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
9285 prepare_one_comp_unit (cu
, die
, cu
->language
);
9287 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
9288 standardised yet. As a workaround for the language detection we fall
9289 back to the DW_AT_producer string. */
9290 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
9291 cu
->language
= language_opencl
;
9293 /* Similar hack for Go. */
9294 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
9295 set_cu_language (DW_LANG_Go
, cu
);
9297 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
9299 /* Decode line number information if present. We do this before
9300 processing child DIEs, so that the line header table is available
9301 for DW_AT_decl_file. */
9302 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, lowpc
);
9304 /* Process all dies in compilation unit. */
9305 if (die
->child
!= NULL
)
9307 child_die
= die
->child
;
9308 while (child_die
&& child_die
->tag
)
9310 process_die (child_die
, cu
);
9311 child_die
= sibling_die (child_die
);
9315 /* Decode macro information, if present. Dwarf 2 macro information
9316 refers to information in the line number info statement program
9317 header, so we can only read it if we've read the header
9319 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
9321 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
9322 if (attr
&& cu
->line_header
)
9324 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
9325 complaint (&symfile_complaints
,
9326 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
9328 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
9332 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
9333 if (attr
&& cu
->line_header
)
9335 unsigned int macro_offset
= DW_UNSND (attr
);
9337 dwarf_decode_macros (cu
, macro_offset
, 0);
9341 do_cleanups (back_to
);
9344 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
9345 Create the set of symtabs used by this TU, or if this TU is sharing
9346 symtabs with another TU and the symtabs have already been created
9347 then restore those symtabs in the line header.
9348 We don't need the pc/line-number mapping for type units. */
9351 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
9353 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
9354 struct type_unit_group
*tu_group
;
9356 struct line_header
*lh
;
9357 struct attribute
*attr
;
9358 unsigned int i
, line_offset
;
9359 struct signatured_type
*sig_type
;
9361 gdb_assert (per_cu
->is_debug_types
);
9362 sig_type
= (struct signatured_type
*) per_cu
;
9364 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9366 /* If we're using .gdb_index (includes -readnow) then
9367 per_cu->type_unit_group may not have been set up yet. */
9368 if (sig_type
->type_unit_group
== NULL
)
9369 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
9370 tu_group
= sig_type
->type_unit_group
;
9372 /* If we've already processed this stmt_list there's no real need to
9373 do it again, we could fake it and just recreate the part we need
9374 (file name,index -> symtab mapping). If data shows this optimization
9375 is useful we can do it then. */
9376 first_time
= tu_group
->compunit_symtab
== NULL
;
9378 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
9383 line_offset
= DW_UNSND (attr
);
9384 lh
= dwarf_decode_line_header (line_offset
, cu
);
9389 dwarf2_start_symtab (cu
, "", NULL
, 0);
9392 gdb_assert (tu_group
->symtabs
== NULL
);
9393 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9398 cu
->line_header
= lh
;
9399 make_cleanup (free_cu_line_header
, cu
);
9403 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
9405 /* Note: We don't assign tu_group->compunit_symtab yet because we're
9406 still initializing it, and our caller (a few levels up)
9407 process_full_type_unit still needs to know if this is the first
9410 tu_group
->num_symtabs
= lh
->num_file_names
;
9411 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
9413 for (i
= 0; i
< lh
->num_file_names
; ++i
)
9415 const char *dir
= NULL
;
9416 struct file_entry
*fe
= &lh
->file_names
[i
];
9418 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
9419 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9420 dwarf2_start_subfile (fe
->name
, dir
);
9422 if (current_subfile
->symtab
== NULL
)
9424 /* NOTE: start_subfile will recognize when it's been passed
9425 a file it has already seen. So we can't assume there's a
9426 simple mapping from lh->file_names to subfiles, plus
9427 lh->file_names may contain dups. */
9428 current_subfile
->symtab
9429 = allocate_symtab (cust
, current_subfile
->name
);
9432 fe
->symtab
= current_subfile
->symtab
;
9433 tu_group
->symtabs
[i
] = fe
->symtab
;
9438 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9440 for (i
= 0; i
< lh
->num_file_names
; ++i
)
9442 struct file_entry
*fe
= &lh
->file_names
[i
];
9444 fe
->symtab
= tu_group
->symtabs
[i
];
9448 /* The main symtab is allocated last. Type units don't have DW_AT_name
9449 so they don't have a "real" (so to speak) symtab anyway.
9450 There is later code that will assign the main symtab to all symbols
9451 that don't have one. We need to handle the case of a symbol with a
9452 missing symtab (DW_AT_decl_file) anyway. */
9455 /* Process DW_TAG_type_unit.
9456 For TUs we want to skip the first top level sibling if it's not the
9457 actual type being defined by this TU. In this case the first top
9458 level sibling is there to provide context only. */
9461 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9463 struct die_info
*child_die
;
9465 prepare_one_comp_unit (cu
, die
, language_minimal
);
9467 /* Initialize (or reinitialize) the machinery for building symtabs.
9468 We do this before processing child DIEs, so that the line header table
9469 is available for DW_AT_decl_file. */
9470 setup_type_unit_groups (die
, cu
);
9472 if (die
->child
!= NULL
)
9474 child_die
= die
->child
;
9475 while (child_die
&& child_die
->tag
)
9477 process_die (child_die
, cu
);
9478 child_die
= sibling_die (child_die
);
9485 http://gcc.gnu.org/wiki/DebugFission
9486 http://gcc.gnu.org/wiki/DebugFissionDWP
9488 To simplify handling of both DWO files ("object" files with the DWARF info)
9489 and DWP files (a file with the DWOs packaged up into one file), we treat
9490 DWP files as having a collection of virtual DWO files. */
9493 hash_dwo_file (const void *item
)
9495 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
9498 hash
= htab_hash_string (dwo_file
->dwo_name
);
9499 if (dwo_file
->comp_dir
!= NULL
)
9500 hash
+= htab_hash_string (dwo_file
->comp_dir
);
9505 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
9507 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
9508 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
9510 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
9512 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
9513 return lhs
->comp_dir
== rhs
->comp_dir
;
9514 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
9517 /* Allocate a hash table for DWO files. */
9520 allocate_dwo_file_hash_table (void)
9522 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9524 return htab_create_alloc_ex (41,
9528 &objfile
->objfile_obstack
,
9529 hashtab_obstack_allocate
,
9530 dummy_obstack_deallocate
);
9533 /* Lookup DWO file DWO_NAME. */
9536 lookup_dwo_file_slot (const char *dwo_name
, const char *comp_dir
)
9538 struct dwo_file find_entry
;
9541 if (dwarf2_per_objfile
->dwo_files
== NULL
)
9542 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
9544 memset (&find_entry
, 0, sizeof (find_entry
));
9545 find_entry
.dwo_name
= dwo_name
;
9546 find_entry
.comp_dir
= comp_dir
;
9547 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
9553 hash_dwo_unit (const void *item
)
9555 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
9557 /* This drops the top 32 bits of the id, but is ok for a hash. */
9558 return dwo_unit
->signature
;
9562 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
9564 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
9565 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
9567 /* The signature is assumed to be unique within the DWO file.
9568 So while object file CU dwo_id's always have the value zero,
9569 that's OK, assuming each object file DWO file has only one CU,
9570 and that's the rule for now. */
9571 return lhs
->signature
== rhs
->signature
;
9574 /* Allocate a hash table for DWO CUs,TUs.
9575 There is one of these tables for each of CUs,TUs for each DWO file. */
9578 allocate_dwo_unit_table (struct objfile
*objfile
)
9580 /* Start out with a pretty small number.
9581 Generally DWO files contain only one CU and maybe some TUs. */
9582 return htab_create_alloc_ex (3,
9586 &objfile
->objfile_obstack
,
9587 hashtab_obstack_allocate
,
9588 dummy_obstack_deallocate
);
9591 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
9593 struct create_dwo_cu_data
9595 struct dwo_file
*dwo_file
;
9596 struct dwo_unit dwo_unit
;
9599 /* die_reader_func for create_dwo_cu. */
9602 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
9603 const gdb_byte
*info_ptr
,
9604 struct die_info
*comp_unit_die
,
9608 struct dwarf2_cu
*cu
= reader
->cu
;
9609 sect_offset offset
= cu
->per_cu
->offset
;
9610 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
9611 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
9612 struct dwo_file
*dwo_file
= data
->dwo_file
;
9613 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
9614 struct attribute
*attr
;
9616 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
9619 complaint (&symfile_complaints
,
9620 _("Dwarf Error: debug entry at offset 0x%x is missing"
9621 " its dwo_id [in module %s]"),
9622 offset
.sect_off
, dwo_file
->dwo_name
);
9626 dwo_unit
->dwo_file
= dwo_file
;
9627 dwo_unit
->signature
= DW_UNSND (attr
);
9628 dwo_unit
->section
= section
;
9629 dwo_unit
->offset
= offset
;
9630 dwo_unit
->length
= cu
->per_cu
->length
;
9632 if (dwarf_read_debug
)
9633 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id %s\n",
9634 offset
.sect_off
, hex_string (dwo_unit
->signature
));
9637 /* Create the dwo_unit for the lone CU in DWO_FILE.
9638 Note: This function processes DWO files only, not DWP files. */
9640 static struct dwo_unit
*
9641 create_dwo_cu (struct dwo_file
*dwo_file
)
9643 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9644 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
9645 const gdb_byte
*info_ptr
, *end_ptr
;
9646 struct create_dwo_cu_data create_dwo_cu_data
;
9647 struct dwo_unit
*dwo_unit
;
9649 dwarf2_read_section (objfile
, section
);
9650 info_ptr
= section
->buffer
;
9652 if (info_ptr
== NULL
)
9655 if (dwarf_read_debug
)
9657 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
9658 get_section_name (section
),
9659 get_section_file_name (section
));
9662 create_dwo_cu_data
.dwo_file
= dwo_file
;
9665 end_ptr
= info_ptr
+ section
->size
;
9666 while (info_ptr
< end_ptr
)
9668 struct dwarf2_per_cu_data per_cu
;
9670 memset (&create_dwo_cu_data
.dwo_unit
, 0,
9671 sizeof (create_dwo_cu_data
.dwo_unit
));
9672 memset (&per_cu
, 0, sizeof (per_cu
));
9673 per_cu
.objfile
= objfile
;
9674 per_cu
.is_debug_types
= 0;
9675 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
9676 per_cu
.section
= section
;
9678 init_cutu_and_read_dies_no_follow (&per_cu
, dwo_file
,
9679 create_dwo_cu_reader
,
9680 &create_dwo_cu_data
);
9682 if (create_dwo_cu_data
.dwo_unit
.dwo_file
!= NULL
)
9684 /* If we've already found one, complain. We only support one
9685 because having more than one requires hacking the dwo_name of
9686 each to match, which is highly unlikely to happen. */
9687 if (dwo_unit
!= NULL
)
9689 complaint (&symfile_complaints
,
9690 _("Multiple CUs in DWO file %s [in module %s]"),
9691 dwo_file
->dwo_name
, objfile_name (objfile
));
9695 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
9696 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
9699 info_ptr
+= per_cu
.length
;
9705 /* DWP file .debug_{cu,tu}_index section format:
9706 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
9710 Both index sections have the same format, and serve to map a 64-bit
9711 signature to a set of section numbers. Each section begins with a header,
9712 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
9713 indexes, and a pool of 32-bit section numbers. The index sections will be
9714 aligned at 8-byte boundaries in the file.
9716 The index section header consists of:
9718 V, 32 bit version number
9720 N, 32 bit number of compilation units or type units in the index
9721 M, 32 bit number of slots in the hash table
9723 Numbers are recorded using the byte order of the application binary.
9725 The hash table begins at offset 16 in the section, and consists of an array
9726 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
9727 order of the application binary). Unused slots in the hash table are 0.
9728 (We rely on the extreme unlikeliness of a signature being exactly 0.)
9730 The parallel table begins immediately after the hash table
9731 (at offset 16 + 8 * M from the beginning of the section), and consists of an
9732 array of 32-bit indexes (using the byte order of the application binary),
9733 corresponding 1-1 with slots in the hash table. Each entry in the parallel
9734 table contains a 32-bit index into the pool of section numbers. For unused
9735 hash table slots, the corresponding entry in the parallel table will be 0.
9737 The pool of section numbers begins immediately following the hash table
9738 (at offset 16 + 12 * M from the beginning of the section). The pool of
9739 section numbers consists of an array of 32-bit words (using the byte order
9740 of the application binary). Each item in the array is indexed starting
9741 from 0. The hash table entry provides the index of the first section
9742 number in the set. Additional section numbers in the set follow, and the
9743 set is terminated by a 0 entry (section number 0 is not used in ELF).
9745 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
9746 section must be the first entry in the set, and the .debug_abbrev.dwo must
9747 be the second entry. Other members of the set may follow in any order.
9753 DWP Version 2 combines all the .debug_info, etc. sections into one,
9754 and the entries in the index tables are now offsets into these sections.
9755 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
9758 Index Section Contents:
9760 Hash Table of Signatures dwp_hash_table.hash_table
9761 Parallel Table of Indices dwp_hash_table.unit_table
9762 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
9763 Table of Section Sizes dwp_hash_table.v2.sizes
9765 The index section header consists of:
9767 V, 32 bit version number
9768 L, 32 bit number of columns in the table of section offsets
9769 N, 32 bit number of compilation units or type units in the index
9770 M, 32 bit number of slots in the hash table
9772 Numbers are recorded using the byte order of the application binary.
9774 The hash table has the same format as version 1.
9775 The parallel table of indices has the same format as version 1,
9776 except that the entries are origin-1 indices into the table of sections
9777 offsets and the table of section sizes.
9779 The table of offsets begins immediately following the parallel table
9780 (at offset 16 + 12 * M from the beginning of the section). The table is
9781 a two-dimensional array of 32-bit words (using the byte order of the
9782 application binary), with L columns and N+1 rows, in row-major order.
9783 Each row in the array is indexed starting from 0. The first row provides
9784 a key to the remaining rows: each column in this row provides an identifier
9785 for a debug section, and the offsets in the same column of subsequent rows
9786 refer to that section. The section identifiers are:
9788 DW_SECT_INFO 1 .debug_info.dwo
9789 DW_SECT_TYPES 2 .debug_types.dwo
9790 DW_SECT_ABBREV 3 .debug_abbrev.dwo
9791 DW_SECT_LINE 4 .debug_line.dwo
9792 DW_SECT_LOC 5 .debug_loc.dwo
9793 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
9794 DW_SECT_MACINFO 7 .debug_macinfo.dwo
9795 DW_SECT_MACRO 8 .debug_macro.dwo
9797 The offsets provided by the CU and TU index sections are the base offsets
9798 for the contributions made by each CU or TU to the corresponding section
9799 in the package file. Each CU and TU header contains an abbrev_offset
9800 field, used to find the abbreviations table for that CU or TU within the
9801 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
9802 be interpreted as relative to the base offset given in the index section.
9803 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
9804 should be interpreted as relative to the base offset for .debug_line.dwo,
9805 and offsets into other debug sections obtained from DWARF attributes should
9806 also be interpreted as relative to the corresponding base offset.
9808 The table of sizes begins immediately following the table of offsets.
9809 Like the table of offsets, it is a two-dimensional array of 32-bit words,
9810 with L columns and N rows, in row-major order. Each row in the array is
9811 indexed starting from 1 (row 0 is shared by the two tables).
9815 Hash table lookup is handled the same in version 1 and 2:
9817 We assume that N and M will not exceed 2^32 - 1.
9818 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
9820 Given a 64-bit compilation unit signature or a type signature S, an entry
9821 in the hash table is located as follows:
9823 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
9824 the low-order k bits all set to 1.
9826 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
9828 3) If the hash table entry at index H matches the signature, use that
9829 entry. If the hash table entry at index H is unused (all zeroes),
9830 terminate the search: the signature is not present in the table.
9832 4) Let H = (H + H') modulo M. Repeat at Step 3.
9834 Because M > N and H' and M are relatively prime, the search is guaranteed
9835 to stop at an unused slot or find the match. */
9837 /* Create a hash table to map DWO IDs to their CU/TU entry in
9838 .debug_{info,types}.dwo in DWP_FILE.
9839 Returns NULL if there isn't one.
9840 Note: This function processes DWP files only, not DWO files. */
9842 static struct dwp_hash_table
*
9843 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
9845 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9846 bfd
*dbfd
= dwp_file
->dbfd
;
9847 const gdb_byte
*index_ptr
, *index_end
;
9848 struct dwarf2_section_info
*index
;
9849 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
9850 struct dwp_hash_table
*htab
;
9853 index
= &dwp_file
->sections
.tu_index
;
9855 index
= &dwp_file
->sections
.cu_index
;
9857 if (dwarf2_section_empty_p (index
))
9859 dwarf2_read_section (objfile
, index
);
9861 index_ptr
= index
->buffer
;
9862 index_end
= index_ptr
+ index
->size
;
9864 version
= read_4_bytes (dbfd
, index_ptr
);
9867 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
9871 nr_units
= read_4_bytes (dbfd
, index_ptr
);
9873 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
9876 if (version
!= 1 && version
!= 2)
9878 error (_("Dwarf Error: unsupported DWP file version (%s)"
9880 pulongest (version
), dwp_file
->name
);
9882 if (nr_slots
!= (nr_slots
& -nr_slots
))
9884 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
9885 " is not power of 2 [in module %s]"),
9886 pulongest (nr_slots
), dwp_file
->name
);
9889 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
9890 htab
->version
= version
;
9891 htab
->nr_columns
= nr_columns
;
9892 htab
->nr_units
= nr_units
;
9893 htab
->nr_slots
= nr_slots
;
9894 htab
->hash_table
= index_ptr
;
9895 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
9897 /* Exit early if the table is empty. */
9898 if (nr_slots
== 0 || nr_units
== 0
9899 || (version
== 2 && nr_columns
== 0))
9901 /* All must be zero. */
9902 if (nr_slots
!= 0 || nr_units
!= 0
9903 || (version
== 2 && nr_columns
!= 0))
9905 complaint (&symfile_complaints
,
9906 _("Empty DWP but nr_slots,nr_units,nr_columns not"
9907 " all zero [in modules %s]"),
9915 htab
->section_pool
.v1
.indices
=
9916 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9917 /* It's harder to decide whether the section is too small in v1.
9918 V1 is deprecated anyway so we punt. */
9922 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9923 int *ids
= htab
->section_pool
.v2
.section_ids
;
9924 /* Reverse map for error checking. */
9925 int ids_seen
[DW_SECT_MAX
+ 1];
9930 error (_("Dwarf Error: bad DWP hash table, too few columns"
9931 " in section table [in module %s]"),
9934 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
9936 error (_("Dwarf Error: bad DWP hash table, too many columns"
9937 " in section table [in module %s]"),
9940 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
9941 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
9942 for (i
= 0; i
< nr_columns
; ++i
)
9944 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
9946 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
9948 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
9949 " in section table [in module %s]"),
9950 id
, dwp_file
->name
);
9952 if (ids_seen
[id
] != -1)
9954 error (_("Dwarf Error: bad DWP hash table, duplicate section"
9955 " id %d in section table [in module %s]"),
9956 id
, dwp_file
->name
);
9961 /* Must have exactly one info or types section. */
9962 if (((ids_seen
[DW_SECT_INFO
] != -1)
9963 + (ids_seen
[DW_SECT_TYPES
] != -1))
9966 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
9967 " DWO info/types section [in module %s]"),
9970 /* Must have an abbrev section. */
9971 if (ids_seen
[DW_SECT_ABBREV
] == -1)
9973 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
9974 " section [in module %s]"),
9977 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
9978 htab
->section_pool
.v2
.sizes
=
9979 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
9980 * nr_units
* nr_columns
);
9981 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
9982 * nr_units
* nr_columns
))
9985 error (_("Dwarf Error: DWP index section is corrupt (too small)"
9994 /* Update SECTIONS with the data from SECTP.
9996 This function is like the other "locate" section routines that are
9997 passed to bfd_map_over_sections, but in this context the sections to
9998 read comes from the DWP V1 hash table, not the full ELF section table.
10000 The result is non-zero for success, or zero if an error was found. */
10003 locate_v1_virtual_dwo_sections (asection
*sectp
,
10004 struct virtual_v1_dwo_sections
*sections
)
10006 const struct dwop_section_names
*names
= &dwop_section_names
;
10008 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10010 /* There can be only one. */
10011 if (sections
->abbrev
.s
.section
!= NULL
)
10013 sections
->abbrev
.s
.section
= sectp
;
10014 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10016 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
10017 || section_is_p (sectp
->name
, &names
->types_dwo
))
10019 /* There can be only one. */
10020 if (sections
->info_or_types
.s
.section
!= NULL
)
10022 sections
->info_or_types
.s
.section
= sectp
;
10023 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
10025 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10027 /* There can be only one. */
10028 if (sections
->line
.s
.section
!= NULL
)
10030 sections
->line
.s
.section
= sectp
;
10031 sections
->line
.size
= bfd_get_section_size (sectp
);
10033 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10035 /* There can be only one. */
10036 if (sections
->loc
.s
.section
!= NULL
)
10038 sections
->loc
.s
.section
= sectp
;
10039 sections
->loc
.size
= bfd_get_section_size (sectp
);
10041 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10043 /* There can be only one. */
10044 if (sections
->macinfo
.s
.section
!= NULL
)
10046 sections
->macinfo
.s
.section
= sectp
;
10047 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10049 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10051 /* There can be only one. */
10052 if (sections
->macro
.s
.section
!= NULL
)
10054 sections
->macro
.s
.section
= sectp
;
10055 sections
->macro
.size
= bfd_get_section_size (sectp
);
10057 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10059 /* There can be only one. */
10060 if (sections
->str_offsets
.s
.section
!= NULL
)
10062 sections
->str_offsets
.s
.section
= sectp
;
10063 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10067 /* No other kind of section is valid. */
10074 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10075 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10076 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10077 This is for DWP version 1 files. */
10079 static struct dwo_unit
*
10080 create_dwo_unit_in_dwp_v1 (struct dwp_file
*dwp_file
,
10081 uint32_t unit_index
,
10082 const char *comp_dir
,
10083 ULONGEST signature
, int is_debug_types
)
10085 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10086 const struct dwp_hash_table
*dwp_htab
=
10087 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10088 bfd
*dbfd
= dwp_file
->dbfd
;
10089 const char *kind
= is_debug_types
? "TU" : "CU";
10090 struct dwo_file
*dwo_file
;
10091 struct dwo_unit
*dwo_unit
;
10092 struct virtual_v1_dwo_sections sections
;
10093 void **dwo_file_slot
;
10094 char *virtual_dwo_name
;
10095 struct cleanup
*cleanups
;
10098 gdb_assert (dwp_file
->version
== 1);
10100 if (dwarf_read_debug
)
10102 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
10104 pulongest (unit_index
), hex_string (signature
),
10108 /* Fetch the sections of this DWO unit.
10109 Put a limit on the number of sections we look for so that bad data
10110 doesn't cause us to loop forever. */
10112 #define MAX_NR_V1_DWO_SECTIONS \
10113 (1 /* .debug_info or .debug_types */ \
10114 + 1 /* .debug_abbrev */ \
10115 + 1 /* .debug_line */ \
10116 + 1 /* .debug_loc */ \
10117 + 1 /* .debug_str_offsets */ \
10118 + 1 /* .debug_macro or .debug_macinfo */ \
10119 + 1 /* trailing zero */)
10121 memset (§ions
, 0, sizeof (sections
));
10122 cleanups
= make_cleanup (null_cleanup
, 0);
10124 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
10127 uint32_t section_nr
=
10128 read_4_bytes (dbfd
,
10129 dwp_htab
->section_pool
.v1
.indices
10130 + (unit_index
+ i
) * sizeof (uint32_t));
10132 if (section_nr
== 0)
10134 if (section_nr
>= dwp_file
->num_sections
)
10136 error (_("Dwarf Error: bad DWP hash table, section number too large"
10137 " [in module %s]"),
10141 sectp
= dwp_file
->elf_sections
[section_nr
];
10142 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
10144 error (_("Dwarf Error: bad DWP hash table, invalid section found"
10145 " [in module %s]"),
10151 || dwarf2_section_empty_p (§ions
.info_or_types
)
10152 || dwarf2_section_empty_p (§ions
.abbrev
))
10154 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
10155 " [in module %s]"),
10158 if (i
== MAX_NR_V1_DWO_SECTIONS
)
10160 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
10161 " [in module %s]"),
10165 /* It's easier for the rest of the code if we fake a struct dwo_file and
10166 have dwo_unit "live" in that. At least for now.
10168 The DWP file can be made up of a random collection of CUs and TUs.
10169 However, for each CU + set of TUs that came from the same original DWO
10170 file, we can combine them back into a virtual DWO file to save space
10171 (fewer struct dwo_file objects to allocate). Remember that for really
10172 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10175 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
10176 get_section_id (§ions
.abbrev
),
10177 get_section_id (§ions
.line
),
10178 get_section_id (§ions
.loc
),
10179 get_section_id (§ions
.str_offsets
));
10180 make_cleanup (xfree
, virtual_dwo_name
);
10181 /* Can we use an existing virtual DWO file? */
10182 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
10183 /* Create one if necessary. */
10184 if (*dwo_file_slot
== NULL
)
10186 if (dwarf_read_debug
)
10188 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10191 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10193 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
10195 strlen (virtual_dwo_name
));
10196 dwo_file
->comp_dir
= comp_dir
;
10197 dwo_file
->sections
.abbrev
= sections
.abbrev
;
10198 dwo_file
->sections
.line
= sections
.line
;
10199 dwo_file
->sections
.loc
= sections
.loc
;
10200 dwo_file
->sections
.macinfo
= sections
.macinfo
;
10201 dwo_file
->sections
.macro
= sections
.macro
;
10202 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
10203 /* The "str" section is global to the entire DWP file. */
10204 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10205 /* The info or types section is assigned below to dwo_unit,
10206 there's no need to record it in dwo_file.
10207 Also, we can't simply record type sections in dwo_file because
10208 we record a pointer into the vector in dwo_unit. As we collect more
10209 types we'll grow the vector and eventually have to reallocate space
10210 for it, invalidating all copies of pointers into the previous
10212 *dwo_file_slot
= dwo_file
;
10216 if (dwarf_read_debug
)
10218 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10221 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10223 do_cleanups (cleanups
);
10225 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10226 dwo_unit
->dwo_file
= dwo_file
;
10227 dwo_unit
->signature
= signature
;
10228 dwo_unit
->section
=
10229 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
10230 *dwo_unit
->section
= sections
.info_or_types
;
10231 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10236 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
10237 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
10238 piece within that section used by a TU/CU, return a virtual section
10239 of just that piece. */
10241 static struct dwarf2_section_info
10242 create_dwp_v2_section (struct dwarf2_section_info
*section
,
10243 bfd_size_type offset
, bfd_size_type size
)
10245 struct dwarf2_section_info result
;
10248 gdb_assert (section
!= NULL
);
10249 gdb_assert (!section
->is_virtual
);
10251 memset (&result
, 0, sizeof (result
));
10252 result
.s
.containing_section
= section
;
10253 result
.is_virtual
= 1;
10258 sectp
= get_section_bfd_section (section
);
10260 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
10261 bounds of the real section. This is a pretty-rare event, so just
10262 flag an error (easier) instead of a warning and trying to cope. */
10264 || offset
+ size
> bfd_get_section_size (sectp
))
10266 bfd
*abfd
= sectp
->owner
;
10268 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
10269 " in section %s [in module %s]"),
10270 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
10271 objfile_name (dwarf2_per_objfile
->objfile
));
10274 result
.virtual_offset
= offset
;
10275 result
.size
= size
;
10279 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10280 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10281 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10282 This is for DWP version 2 files. */
10284 static struct dwo_unit
*
10285 create_dwo_unit_in_dwp_v2 (struct dwp_file
*dwp_file
,
10286 uint32_t unit_index
,
10287 const char *comp_dir
,
10288 ULONGEST signature
, int is_debug_types
)
10290 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10291 const struct dwp_hash_table
*dwp_htab
=
10292 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10293 bfd
*dbfd
= dwp_file
->dbfd
;
10294 const char *kind
= is_debug_types
? "TU" : "CU";
10295 struct dwo_file
*dwo_file
;
10296 struct dwo_unit
*dwo_unit
;
10297 struct virtual_v2_dwo_sections sections
;
10298 void **dwo_file_slot
;
10299 char *virtual_dwo_name
;
10300 struct cleanup
*cleanups
;
10303 gdb_assert (dwp_file
->version
== 2);
10305 if (dwarf_read_debug
)
10307 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
10309 pulongest (unit_index
), hex_string (signature
),
10313 /* Fetch the section offsets of this DWO unit. */
10315 memset (§ions
, 0, sizeof (sections
));
10316 cleanups
= make_cleanup (null_cleanup
, 0);
10318 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
10320 uint32_t offset
= read_4_bytes (dbfd
,
10321 dwp_htab
->section_pool
.v2
.offsets
10322 + (((unit_index
- 1) * dwp_htab
->nr_columns
10324 * sizeof (uint32_t)));
10325 uint32_t size
= read_4_bytes (dbfd
,
10326 dwp_htab
->section_pool
.v2
.sizes
10327 + (((unit_index
- 1) * dwp_htab
->nr_columns
10329 * sizeof (uint32_t)));
10331 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
10334 case DW_SECT_TYPES
:
10335 sections
.info_or_types_offset
= offset
;
10336 sections
.info_or_types_size
= size
;
10338 case DW_SECT_ABBREV
:
10339 sections
.abbrev_offset
= offset
;
10340 sections
.abbrev_size
= size
;
10343 sections
.line_offset
= offset
;
10344 sections
.line_size
= size
;
10347 sections
.loc_offset
= offset
;
10348 sections
.loc_size
= size
;
10350 case DW_SECT_STR_OFFSETS
:
10351 sections
.str_offsets_offset
= offset
;
10352 sections
.str_offsets_size
= size
;
10354 case DW_SECT_MACINFO
:
10355 sections
.macinfo_offset
= offset
;
10356 sections
.macinfo_size
= size
;
10358 case DW_SECT_MACRO
:
10359 sections
.macro_offset
= offset
;
10360 sections
.macro_size
= size
;
10365 /* It's easier for the rest of the code if we fake a struct dwo_file and
10366 have dwo_unit "live" in that. At least for now.
10368 The DWP file can be made up of a random collection of CUs and TUs.
10369 However, for each CU + set of TUs that came from the same original DWO
10370 file, we can combine them back into a virtual DWO file to save space
10371 (fewer struct dwo_file objects to allocate). Remember that for really
10372 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10375 xstrprintf ("virtual-dwo/%ld-%ld-%ld-%ld",
10376 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
10377 (long) (sections
.line_size
? sections
.line_offset
: 0),
10378 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
10379 (long) (sections
.str_offsets_size
10380 ? sections
.str_offsets_offset
: 0));
10381 make_cleanup (xfree
, virtual_dwo_name
);
10382 /* Can we use an existing virtual DWO file? */
10383 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
10384 /* Create one if necessary. */
10385 if (*dwo_file_slot
== NULL
)
10387 if (dwarf_read_debug
)
10389 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10392 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10394 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
10396 strlen (virtual_dwo_name
));
10397 dwo_file
->comp_dir
= comp_dir
;
10398 dwo_file
->sections
.abbrev
=
10399 create_dwp_v2_section (&dwp_file
->sections
.abbrev
,
10400 sections
.abbrev_offset
, sections
.abbrev_size
);
10401 dwo_file
->sections
.line
=
10402 create_dwp_v2_section (&dwp_file
->sections
.line
,
10403 sections
.line_offset
, sections
.line_size
);
10404 dwo_file
->sections
.loc
=
10405 create_dwp_v2_section (&dwp_file
->sections
.loc
,
10406 sections
.loc_offset
, sections
.loc_size
);
10407 dwo_file
->sections
.macinfo
=
10408 create_dwp_v2_section (&dwp_file
->sections
.macinfo
,
10409 sections
.macinfo_offset
, sections
.macinfo_size
);
10410 dwo_file
->sections
.macro
=
10411 create_dwp_v2_section (&dwp_file
->sections
.macro
,
10412 sections
.macro_offset
, sections
.macro_size
);
10413 dwo_file
->sections
.str_offsets
=
10414 create_dwp_v2_section (&dwp_file
->sections
.str_offsets
,
10415 sections
.str_offsets_offset
,
10416 sections
.str_offsets_size
);
10417 /* The "str" section is global to the entire DWP file. */
10418 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10419 /* The info or types section is assigned below to dwo_unit,
10420 there's no need to record it in dwo_file.
10421 Also, we can't simply record type sections in dwo_file because
10422 we record a pointer into the vector in dwo_unit. As we collect more
10423 types we'll grow the vector and eventually have to reallocate space
10424 for it, invalidating all copies of pointers into the previous
10426 *dwo_file_slot
= dwo_file
;
10430 if (dwarf_read_debug
)
10432 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10435 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10437 do_cleanups (cleanups
);
10439 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10440 dwo_unit
->dwo_file
= dwo_file
;
10441 dwo_unit
->signature
= signature
;
10442 dwo_unit
->section
=
10443 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
10444 *dwo_unit
->section
= create_dwp_v2_section (is_debug_types
10445 ? &dwp_file
->sections
.types
10446 : &dwp_file
->sections
.info
,
10447 sections
.info_or_types_offset
,
10448 sections
.info_or_types_size
);
10449 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10454 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
10455 Returns NULL if the signature isn't found. */
10457 static struct dwo_unit
*
10458 lookup_dwo_unit_in_dwp (struct dwp_file
*dwp_file
, const char *comp_dir
,
10459 ULONGEST signature
, int is_debug_types
)
10461 const struct dwp_hash_table
*dwp_htab
=
10462 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10463 bfd
*dbfd
= dwp_file
->dbfd
;
10464 uint32_t mask
= dwp_htab
->nr_slots
- 1;
10465 uint32_t hash
= signature
& mask
;
10466 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
10469 struct dwo_unit find_dwo_cu
;
10471 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
10472 find_dwo_cu
.signature
= signature
;
10473 slot
= htab_find_slot (is_debug_types
10474 ? dwp_file
->loaded_tus
10475 : dwp_file
->loaded_cus
,
10476 &find_dwo_cu
, INSERT
);
10479 return (struct dwo_unit
*) *slot
;
10481 /* Use a for loop so that we don't loop forever on bad debug info. */
10482 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
10484 ULONGEST signature_in_table
;
10486 signature_in_table
=
10487 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
10488 if (signature_in_table
== signature
)
10490 uint32_t unit_index
=
10491 read_4_bytes (dbfd
,
10492 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
10494 if (dwp_file
->version
== 1)
10496 *slot
= create_dwo_unit_in_dwp_v1 (dwp_file
, unit_index
,
10497 comp_dir
, signature
,
10502 *slot
= create_dwo_unit_in_dwp_v2 (dwp_file
, unit_index
,
10503 comp_dir
, signature
,
10506 return (struct dwo_unit
*) *slot
;
10508 if (signature_in_table
== 0)
10510 hash
= (hash
+ hash2
) & mask
;
10513 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
10514 " [in module %s]"),
10518 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
10519 Open the file specified by FILE_NAME and hand it off to BFD for
10520 preliminary analysis. Return a newly initialized bfd *, which
10521 includes a canonicalized copy of FILE_NAME.
10522 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
10523 SEARCH_CWD is true if the current directory is to be searched.
10524 It will be searched before debug-file-directory.
10525 If successful, the file is added to the bfd include table of the
10526 objfile's bfd (see gdb_bfd_record_inclusion).
10527 If unable to find/open the file, return NULL.
10528 NOTE: This function is derived from symfile_bfd_open. */
10530 static gdb_bfd_ref_ptr
10531 try_open_dwop_file (const char *file_name
, int is_dwp
, int search_cwd
)
10534 char *absolute_name
;
10535 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
10536 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
10537 to debug_file_directory. */
10539 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
10543 if (*debug_file_directory
!= '\0')
10544 search_path
= concat (".", dirname_separator_string
,
10545 debug_file_directory
, (char *) NULL
);
10547 search_path
= xstrdup (".");
10550 search_path
= xstrdup (debug_file_directory
);
10552 flags
= OPF_RETURN_REALPATH
;
10554 flags
|= OPF_SEARCH_IN_PATH
;
10555 desc
= openp (search_path
, flags
, file_name
,
10556 O_RDONLY
| O_BINARY
, &absolute_name
);
10557 xfree (search_path
);
10561 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
, gnutarget
, desc
));
10562 xfree (absolute_name
);
10563 if (sym_bfd
== NULL
)
10565 bfd_set_cacheable (sym_bfd
.get (), 1);
10567 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
10570 /* Success. Record the bfd as having been included by the objfile's bfd.
10571 This is important because things like demangled_names_hash lives in the
10572 objfile's per_bfd space and may have references to things like symbol
10573 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
10574 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
10579 /* Try to open DWO file FILE_NAME.
10580 COMP_DIR is the DW_AT_comp_dir attribute.
10581 The result is the bfd handle of the file.
10582 If there is a problem finding or opening the file, return NULL.
10583 Upon success, the canonicalized path of the file is stored in the bfd,
10584 same as symfile_bfd_open. */
10586 static gdb_bfd_ref_ptr
10587 open_dwo_file (const char *file_name
, const char *comp_dir
)
10589 if (IS_ABSOLUTE_PATH (file_name
))
10590 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 0 /*search_cwd*/);
10592 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
10594 if (comp_dir
!= NULL
)
10596 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
10597 file_name
, (char *) NULL
);
10599 /* NOTE: If comp_dir is a relative path, this will also try the
10600 search path, which seems useful. */
10601 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (path_to_try
, 0 /*is_dwp*/,
10602 1 /*search_cwd*/));
10603 xfree (path_to_try
);
10608 /* That didn't work, try debug-file-directory, which, despite its name,
10609 is a list of paths. */
10611 if (*debug_file_directory
== '\0')
10614 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 1 /*search_cwd*/);
10617 /* This function is mapped across the sections and remembers the offset and
10618 size of each of the DWO debugging sections we are interested in. */
10621 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
10623 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
10624 const struct dwop_section_names
*names
= &dwop_section_names
;
10626 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10628 dwo_sections
->abbrev
.s
.section
= sectp
;
10629 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10631 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10633 dwo_sections
->info
.s
.section
= sectp
;
10634 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
10636 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10638 dwo_sections
->line
.s
.section
= sectp
;
10639 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
10641 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10643 dwo_sections
->loc
.s
.section
= sectp
;
10644 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
10646 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10648 dwo_sections
->macinfo
.s
.section
= sectp
;
10649 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10651 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10653 dwo_sections
->macro
.s
.section
= sectp
;
10654 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
10656 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
10658 dwo_sections
->str
.s
.section
= sectp
;
10659 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
10661 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10663 dwo_sections
->str_offsets
.s
.section
= sectp
;
10664 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10666 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10668 struct dwarf2_section_info type_section
;
10670 memset (&type_section
, 0, sizeof (type_section
));
10671 type_section
.s
.section
= sectp
;
10672 type_section
.size
= bfd_get_section_size (sectp
);
10673 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
10678 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
10679 by PER_CU. This is for the non-DWP case.
10680 The result is NULL if DWO_NAME can't be found. */
10682 static struct dwo_file
*
10683 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
10684 const char *dwo_name
, const char *comp_dir
)
10686 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10687 struct dwo_file
*dwo_file
;
10688 struct cleanup
*cleanups
;
10690 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwo_name
, comp_dir
));
10693 if (dwarf_read_debug
)
10694 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
10697 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10698 dwo_file
->dwo_name
= dwo_name
;
10699 dwo_file
->comp_dir
= comp_dir
;
10700 dwo_file
->dbfd
= dbfd
.release ();
10702 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
10704 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
10705 &dwo_file
->sections
);
10707 dwo_file
->cu
= create_dwo_cu (dwo_file
);
10709 create_debug_types_hash_table (dwo_file
, dwo_file
->sections
.types
,
10712 discard_cleanups (cleanups
);
10714 if (dwarf_read_debug
)
10715 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
10720 /* This function is mapped across the sections and remembers the offset and
10721 size of each of the DWP debugging sections common to version 1 and 2 that
10722 we are interested in. */
10725 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
10726 void *dwp_file_ptr
)
10728 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
10729 const struct dwop_section_names
*names
= &dwop_section_names
;
10730 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10732 /* Record the ELF section number for later lookup: this is what the
10733 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10734 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10735 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10737 /* Look for specific sections that we need. */
10738 if (section_is_p (sectp
->name
, &names
->str_dwo
))
10740 dwp_file
->sections
.str
.s
.section
= sectp
;
10741 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
10743 else if (section_is_p (sectp
->name
, &names
->cu_index
))
10745 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
10746 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
10748 else if (section_is_p (sectp
->name
, &names
->tu_index
))
10750 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
10751 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
10755 /* This function is mapped across the sections and remembers the offset and
10756 size of each of the DWP version 2 debugging sections that we are interested
10757 in. This is split into a separate function because we don't know if we
10758 have version 1 or 2 until we parse the cu_index/tu_index sections. */
10761 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
10763 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
10764 const struct dwop_section_names
*names
= &dwop_section_names
;
10765 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10767 /* Record the ELF section number for later lookup: this is what the
10768 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10769 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10770 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10772 /* Look for specific sections that we need. */
10773 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10775 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
10776 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
10778 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10780 dwp_file
->sections
.info
.s
.section
= sectp
;
10781 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
10783 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10785 dwp_file
->sections
.line
.s
.section
= sectp
;
10786 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
10788 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10790 dwp_file
->sections
.loc
.s
.section
= sectp
;
10791 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
10793 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10795 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
10796 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
10798 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10800 dwp_file
->sections
.macro
.s
.section
= sectp
;
10801 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
10803 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10805 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
10806 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
10808 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10810 dwp_file
->sections
.types
.s
.section
= sectp
;
10811 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
10815 /* Hash function for dwp_file loaded CUs/TUs. */
10818 hash_dwp_loaded_cutus (const void *item
)
10820 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10822 /* This drops the top 32 bits of the signature, but is ok for a hash. */
10823 return dwo_unit
->signature
;
10826 /* Equality function for dwp_file loaded CUs/TUs. */
10829 eq_dwp_loaded_cutus (const void *a
, const void *b
)
10831 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
10832 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
10834 return dua
->signature
== dub
->signature
;
10837 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
10840 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
10842 return htab_create_alloc_ex (3,
10843 hash_dwp_loaded_cutus
,
10844 eq_dwp_loaded_cutus
,
10846 &objfile
->objfile_obstack
,
10847 hashtab_obstack_allocate
,
10848 dummy_obstack_deallocate
);
10851 /* Try to open DWP file FILE_NAME.
10852 The result is the bfd handle of the file.
10853 If there is a problem finding or opening the file, return NULL.
10854 Upon success, the canonicalized path of the file is stored in the bfd,
10855 same as symfile_bfd_open. */
10857 static gdb_bfd_ref_ptr
10858 open_dwp_file (const char *file_name
)
10860 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (file_name
, 1 /*is_dwp*/,
10861 1 /*search_cwd*/));
10865 /* Work around upstream bug 15652.
10866 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
10867 [Whether that's a "bug" is debatable, but it is getting in our way.]
10868 We have no real idea where the dwp file is, because gdb's realpath-ing
10869 of the executable's path may have discarded the needed info.
10870 [IWBN if the dwp file name was recorded in the executable, akin to
10871 .gnu_debuglink, but that doesn't exist yet.]
10872 Strip the directory from FILE_NAME and search again. */
10873 if (*debug_file_directory
!= '\0')
10875 /* Don't implicitly search the current directory here.
10876 If the user wants to search "." to handle this case,
10877 it must be added to debug-file-directory. */
10878 return try_open_dwop_file (lbasename (file_name
), 1 /*is_dwp*/,
10885 /* Initialize the use of the DWP file for the current objfile.
10886 By convention the name of the DWP file is ${objfile}.dwp.
10887 The result is NULL if it can't be found. */
10889 static struct dwp_file
*
10890 open_and_init_dwp_file (void)
10892 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10893 struct dwp_file
*dwp_file
;
10895 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, 0);
10897 /* Try to find first .dwp for the binary file before any symbolic links
10900 /* If the objfile is a debug file, find the name of the real binary
10901 file and get the name of dwp file from there. */
10902 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
10904 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
10905 const char *backlink_basename
= lbasename (backlink
->original_name
);
10906 char *debug_dirname
= ldirname (objfile
->original_name
);
10908 make_cleanup (xfree
, debug_dirname
);
10909 dwp_name
= xstrprintf ("%s%s%s.dwp", debug_dirname
,
10910 SLASH_STRING
, backlink_basename
);
10913 dwp_name
= xstrprintf ("%s.dwp", objfile
->original_name
);
10914 make_cleanup (xfree
, dwp_name
);
10916 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwp_name
));
10918 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
10920 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
10921 dwp_name
= xstrprintf ("%s.dwp", objfile_name (objfile
));
10922 make_cleanup (xfree
, dwp_name
);
10923 dbfd
= open_dwp_file (dwp_name
);
10928 if (dwarf_read_debug
)
10929 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
);
10930 do_cleanups (cleanups
);
10933 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
10934 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
10935 dwp_file
->dbfd
= dbfd
.release ();
10936 do_cleanups (cleanups
);
10938 /* +1: section 0 is unused */
10939 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
10940 dwp_file
->elf_sections
=
10941 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
10942 dwp_file
->num_sections
, asection
*);
10944 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
10947 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
10949 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
10951 /* The DWP file version is stored in the hash table. Oh well. */
10952 if (dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
10954 /* Technically speaking, we should try to limp along, but this is
10955 pretty bizarre. We use pulongest here because that's the established
10956 portability solution (e.g, we cannot use %u for uint32_t). */
10957 error (_("Dwarf Error: DWP file CU version %s doesn't match"
10958 " TU version %s [in DWP file %s]"),
10959 pulongest (dwp_file
->cus
->version
),
10960 pulongest (dwp_file
->tus
->version
), dwp_name
);
10962 dwp_file
->version
= dwp_file
->cus
->version
;
10964 if (dwp_file
->version
== 2)
10965 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
10968 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
10969 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
10971 if (dwarf_read_debug
)
10973 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
10974 fprintf_unfiltered (gdb_stdlog
,
10975 " %s CUs, %s TUs\n",
10976 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
10977 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
10983 /* Wrapper around open_and_init_dwp_file, only open it once. */
10985 static struct dwp_file
*
10986 get_dwp_file (void)
10988 if (! dwarf2_per_objfile
->dwp_checked
)
10990 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file ();
10991 dwarf2_per_objfile
->dwp_checked
= 1;
10993 return dwarf2_per_objfile
->dwp_file
;
10996 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
10997 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
10998 or in the DWP file for the objfile, referenced by THIS_UNIT.
10999 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
11000 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
11002 This is called, for example, when wanting to read a variable with a
11003 complex location. Therefore we don't want to do file i/o for every call.
11004 Therefore we don't want to look for a DWO file on every call.
11005 Therefore we first see if we've already seen SIGNATURE in a DWP file,
11006 then we check if we've already seen DWO_NAME, and only THEN do we check
11009 The result is a pointer to the dwo_unit object or NULL if we didn't find it
11010 (dwo_id mismatch or couldn't find the DWO/DWP file). */
11012 static struct dwo_unit
*
11013 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
11014 const char *dwo_name
, const char *comp_dir
,
11015 ULONGEST signature
, int is_debug_types
)
11017 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11018 const char *kind
= is_debug_types
? "TU" : "CU";
11019 void **dwo_file_slot
;
11020 struct dwo_file
*dwo_file
;
11021 struct dwp_file
*dwp_file
;
11023 /* First see if there's a DWP file.
11024 If we have a DWP file but didn't find the DWO inside it, don't
11025 look for the original DWO file. It makes gdb behave differently
11026 depending on whether one is debugging in the build tree. */
11028 dwp_file
= get_dwp_file ();
11029 if (dwp_file
!= NULL
)
11031 const struct dwp_hash_table
*dwp_htab
=
11032 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11034 if (dwp_htab
!= NULL
)
11036 struct dwo_unit
*dwo_cutu
=
11037 lookup_dwo_unit_in_dwp (dwp_file
, comp_dir
,
11038 signature
, is_debug_types
);
11040 if (dwo_cutu
!= NULL
)
11042 if (dwarf_read_debug
)
11044 fprintf_unfiltered (gdb_stdlog
,
11045 "Virtual DWO %s %s found: @%s\n",
11046 kind
, hex_string (signature
),
11047 host_address_to_string (dwo_cutu
));
11055 /* No DWP file, look for the DWO file. */
11057 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
, comp_dir
);
11058 if (*dwo_file_slot
== NULL
)
11060 /* Read in the file and build a table of the CUs/TUs it contains. */
11061 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
11063 /* NOTE: This will be NULL if unable to open the file. */
11064 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11066 if (dwo_file
!= NULL
)
11068 struct dwo_unit
*dwo_cutu
= NULL
;
11070 if (is_debug_types
&& dwo_file
->tus
)
11072 struct dwo_unit find_dwo_cutu
;
11074 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
11075 find_dwo_cutu
.signature
= signature
;
11077 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
11079 else if (!is_debug_types
&& dwo_file
->cu
)
11081 if (signature
== dwo_file
->cu
->signature
)
11082 dwo_cutu
= dwo_file
->cu
;
11085 if (dwo_cutu
!= NULL
)
11087 if (dwarf_read_debug
)
11089 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
11090 kind
, dwo_name
, hex_string (signature
),
11091 host_address_to_string (dwo_cutu
));
11098 /* We didn't find it. This could mean a dwo_id mismatch, or
11099 someone deleted the DWO/DWP file, or the search path isn't set up
11100 correctly to find the file. */
11102 if (dwarf_read_debug
)
11104 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
11105 kind
, dwo_name
, hex_string (signature
));
11108 /* This is a warning and not a complaint because it can be caused by
11109 pilot error (e.g., user accidentally deleting the DWO). */
11111 /* Print the name of the DWP file if we looked there, helps the user
11112 better diagnose the problem. */
11113 char *dwp_text
= NULL
;
11114 struct cleanup
*cleanups
;
11116 if (dwp_file
!= NULL
)
11117 dwp_text
= xstrprintf (" [in DWP file %s]", lbasename (dwp_file
->name
));
11118 cleanups
= make_cleanup (xfree
, dwp_text
);
11120 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset 0x%x"
11121 " [in module %s]"),
11122 kind
, dwo_name
, hex_string (signature
),
11123 dwp_text
!= NULL
? dwp_text
: "",
11124 this_unit
->is_debug_types
? "TU" : "CU",
11125 this_unit
->offset
.sect_off
, objfile_name (objfile
));
11127 do_cleanups (cleanups
);
11132 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
11133 See lookup_dwo_cutu_unit for details. */
11135 static struct dwo_unit
*
11136 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
11137 const char *dwo_name
, const char *comp_dir
,
11138 ULONGEST signature
)
11140 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
11143 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
11144 See lookup_dwo_cutu_unit for details. */
11146 static struct dwo_unit
*
11147 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
11148 const char *dwo_name
, const char *comp_dir
)
11150 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
11153 /* Traversal function for queue_and_load_all_dwo_tus. */
11156 queue_and_load_dwo_tu (void **slot
, void *info
)
11158 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
11159 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
11160 ULONGEST signature
= dwo_unit
->signature
;
11161 struct signatured_type
*sig_type
=
11162 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
11164 if (sig_type
!= NULL
)
11166 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
11168 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
11169 a real dependency of PER_CU on SIG_TYPE. That is detected later
11170 while processing PER_CU. */
11171 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
11172 load_full_type_unit (sig_cu
);
11173 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
11179 /* Queue all TUs contained in the DWO of PER_CU to be read in.
11180 The DWO may have the only definition of the type, though it may not be
11181 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
11182 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
11185 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
11187 struct dwo_unit
*dwo_unit
;
11188 struct dwo_file
*dwo_file
;
11190 gdb_assert (!per_cu
->is_debug_types
);
11191 gdb_assert (get_dwp_file () == NULL
);
11192 gdb_assert (per_cu
->cu
!= NULL
);
11194 dwo_unit
= per_cu
->cu
->dwo_unit
;
11195 gdb_assert (dwo_unit
!= NULL
);
11197 dwo_file
= dwo_unit
->dwo_file
;
11198 if (dwo_file
->tus
!= NULL
)
11199 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
11202 /* Free all resources associated with DWO_FILE.
11203 Close the DWO file and munmap the sections.
11204 All memory should be on the objfile obstack. */
11207 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
11210 /* Note: dbfd is NULL for virtual DWO files. */
11211 gdb_bfd_unref (dwo_file
->dbfd
);
11213 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
11216 /* Wrapper for free_dwo_file for use in cleanups. */
11219 free_dwo_file_cleanup (void *arg
)
11221 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
11222 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11224 free_dwo_file (dwo_file
, objfile
);
11227 /* Traversal function for free_dwo_files. */
11230 free_dwo_file_from_slot (void **slot
, void *info
)
11232 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
11233 struct objfile
*objfile
= (struct objfile
*) info
;
11235 free_dwo_file (dwo_file
, objfile
);
11240 /* Free all resources associated with DWO_FILES. */
11243 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
11245 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
11248 /* Read in various DIEs. */
11250 /* qsort helper for inherit_abstract_dies. */
11253 unsigned_int_compar (const void *ap
, const void *bp
)
11255 unsigned int a
= *(unsigned int *) ap
;
11256 unsigned int b
= *(unsigned int *) bp
;
11258 return (a
> b
) - (b
> a
);
11261 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
11262 Inherit only the children of the DW_AT_abstract_origin DIE not being
11263 already referenced by DW_AT_abstract_origin from the children of the
11267 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
11269 struct die_info
*child_die
;
11270 unsigned die_children_count
;
11271 /* CU offsets which were referenced by children of the current DIE. */
11272 sect_offset
*offsets
;
11273 sect_offset
*offsets_end
, *offsetp
;
11274 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
11275 struct die_info
*origin_die
;
11276 /* Iterator of the ORIGIN_DIE children. */
11277 struct die_info
*origin_child_die
;
11278 struct cleanup
*cleanups
;
11279 struct attribute
*attr
;
11280 struct dwarf2_cu
*origin_cu
;
11281 struct pending
**origin_previous_list_in_scope
;
11283 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11287 /* Note that following die references may follow to a die in a
11291 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
11293 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
11295 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
11296 origin_cu
->list_in_scope
= cu
->list_in_scope
;
11298 if (die
->tag
!= origin_die
->tag
11299 && !(die
->tag
== DW_TAG_inlined_subroutine
11300 && origin_die
->tag
== DW_TAG_subprogram
))
11301 complaint (&symfile_complaints
,
11302 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
11303 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
11305 child_die
= die
->child
;
11306 die_children_count
= 0;
11307 while (child_die
&& child_die
->tag
)
11309 child_die
= sibling_die (child_die
);
11310 die_children_count
++;
11312 offsets
= XNEWVEC (sect_offset
, die_children_count
);
11313 cleanups
= make_cleanup (xfree
, offsets
);
11315 offsets_end
= offsets
;
11316 for (child_die
= die
->child
;
11317 child_die
&& child_die
->tag
;
11318 child_die
= sibling_die (child_die
))
11320 struct die_info
*child_origin_die
;
11321 struct dwarf2_cu
*child_origin_cu
;
11323 /* We are trying to process concrete instance entries:
11324 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
11325 it's not relevant to our analysis here. i.e. detecting DIEs that are
11326 present in the abstract instance but not referenced in the concrete
11328 if (child_die
->tag
== DW_TAG_call_site
11329 || child_die
->tag
== DW_TAG_GNU_call_site
)
11332 /* For each CHILD_DIE, find the corresponding child of
11333 ORIGIN_DIE. If there is more than one layer of
11334 DW_AT_abstract_origin, follow them all; there shouldn't be,
11335 but GCC versions at least through 4.4 generate this (GCC PR
11337 child_origin_die
= child_die
;
11338 child_origin_cu
= cu
;
11341 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
11345 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
11349 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
11350 counterpart may exist. */
11351 if (child_origin_die
!= child_die
)
11353 if (child_die
->tag
!= child_origin_die
->tag
11354 && !(child_die
->tag
== DW_TAG_inlined_subroutine
11355 && child_origin_die
->tag
== DW_TAG_subprogram
))
11356 complaint (&symfile_complaints
,
11357 _("Child DIE 0x%x and its abstract origin 0x%x have "
11358 "different tags"), child_die
->offset
.sect_off
,
11359 child_origin_die
->offset
.sect_off
);
11360 if (child_origin_die
->parent
!= origin_die
)
11361 complaint (&symfile_complaints
,
11362 _("Child DIE 0x%x and its abstract origin 0x%x have "
11363 "different parents"), child_die
->offset
.sect_off
,
11364 child_origin_die
->offset
.sect_off
);
11366 *offsets_end
++ = child_origin_die
->offset
;
11369 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
11370 unsigned_int_compar
);
11371 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
11372 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
11373 complaint (&symfile_complaints
,
11374 _("Multiple children of DIE 0x%x refer "
11375 "to DIE 0x%x as their abstract origin"),
11376 die
->offset
.sect_off
, offsetp
->sect_off
);
11379 origin_child_die
= origin_die
->child
;
11380 while (origin_child_die
&& origin_child_die
->tag
)
11382 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
11383 while (offsetp
< offsets_end
11384 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
11386 if (offsetp
>= offsets_end
11387 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
11389 /* Found that ORIGIN_CHILD_DIE is really not referenced.
11390 Check whether we're already processing ORIGIN_CHILD_DIE.
11391 This can happen with mutually referenced abstract_origins.
11393 if (!origin_child_die
->in_process
)
11394 process_die (origin_child_die
, origin_cu
);
11396 origin_child_die
= sibling_die (origin_child_die
);
11398 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
11400 do_cleanups (cleanups
);
11404 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11406 struct objfile
*objfile
= cu
->objfile
;
11407 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11408 struct context_stack
*newobj
;
11411 struct die_info
*child_die
;
11412 struct attribute
*attr
, *call_line
, *call_file
;
11414 CORE_ADDR baseaddr
;
11415 struct block
*block
;
11416 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11417 VEC (symbolp
) *template_args
= NULL
;
11418 struct template_symbol
*templ_func
= NULL
;
11422 /* If we do not have call site information, we can't show the
11423 caller of this inlined function. That's too confusing, so
11424 only use the scope for local variables. */
11425 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
11426 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
11427 if (call_line
== NULL
|| call_file
== NULL
)
11429 read_lexical_block_scope (die
, cu
);
11434 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11436 name
= dwarf2_name (die
, cu
);
11438 /* Ignore functions with missing or empty names. These are actually
11439 illegal according to the DWARF standard. */
11442 complaint (&symfile_complaints
,
11443 _("missing name for subprogram DIE at %d"),
11444 die
->offset
.sect_off
);
11448 /* Ignore functions with missing or invalid low and high pc attributes. */
11449 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
11450 <= PC_BOUNDS_INVALID
)
11452 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
11453 if (!attr
|| !DW_UNSND (attr
))
11454 complaint (&symfile_complaints
,
11455 _("cannot get low and high bounds "
11456 "for subprogram DIE at %d"),
11457 die
->offset
.sect_off
);
11461 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11462 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11464 /* If we have any template arguments, then we must allocate a
11465 different sort of symbol. */
11466 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
11468 if (child_die
->tag
== DW_TAG_template_type_param
11469 || child_die
->tag
== DW_TAG_template_value_param
)
11471 templ_func
= allocate_template_symbol (objfile
);
11472 templ_func
->base
.is_cplus_template_function
= 1;
11477 newobj
= push_context (0, lowpc
);
11478 newobj
->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
11479 (struct symbol
*) templ_func
);
11481 /* If there is a location expression for DW_AT_frame_base, record
11483 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
11485 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
11487 /* If there is a location for the static link, record it. */
11488 newobj
->static_link
= NULL
;
11489 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
11492 newobj
->static_link
11493 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
11494 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
11497 cu
->list_in_scope
= &local_symbols
;
11499 if (die
->child
!= NULL
)
11501 child_die
= die
->child
;
11502 while (child_die
&& child_die
->tag
)
11504 if (child_die
->tag
== DW_TAG_template_type_param
11505 || child_die
->tag
== DW_TAG_template_value_param
)
11507 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
11510 VEC_safe_push (symbolp
, template_args
, arg
);
11513 process_die (child_die
, cu
);
11514 child_die
= sibling_die (child_die
);
11518 inherit_abstract_dies (die
, cu
);
11520 /* If we have a DW_AT_specification, we might need to import using
11521 directives from the context of the specification DIE. See the
11522 comment in determine_prefix. */
11523 if (cu
->language
== language_cplus
11524 && dwarf2_attr (die
, DW_AT_specification
, cu
))
11526 struct dwarf2_cu
*spec_cu
= cu
;
11527 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
11531 child_die
= spec_die
->child
;
11532 while (child_die
&& child_die
->tag
)
11534 if (child_die
->tag
== DW_TAG_imported_module
)
11535 process_die (child_die
, spec_cu
);
11536 child_die
= sibling_die (child_die
);
11539 /* In some cases, GCC generates specification DIEs that
11540 themselves contain DW_AT_specification attributes. */
11541 spec_die
= die_specification (spec_die
, &spec_cu
);
11545 newobj
= pop_context ();
11546 /* Make a block for the local symbols within. */
11547 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
11548 newobj
->static_link
, lowpc
, highpc
);
11550 /* For C++, set the block's scope. */
11551 if ((cu
->language
== language_cplus
11552 || cu
->language
== language_fortran
11553 || cu
->language
== language_d
11554 || cu
->language
== language_rust
)
11555 && cu
->processing_has_namespace_info
)
11556 block_set_scope (block
, determine_prefix (die
, cu
),
11557 &objfile
->objfile_obstack
);
11559 /* If we have address ranges, record them. */
11560 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11562 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
11564 /* Attach template arguments to function. */
11565 if (! VEC_empty (symbolp
, template_args
))
11567 gdb_assert (templ_func
!= NULL
);
11569 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
11570 templ_func
->template_arguments
11571 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
11572 templ_func
->n_template_arguments
);
11573 memcpy (templ_func
->template_arguments
,
11574 VEC_address (symbolp
, template_args
),
11575 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
11576 VEC_free (symbolp
, template_args
);
11579 /* In C++, we can have functions nested inside functions (e.g., when
11580 a function declares a class that has methods). This means that
11581 when we finish processing a function scope, we may need to go
11582 back to building a containing block's symbol lists. */
11583 local_symbols
= newobj
->locals
;
11584 local_using_directives
= newobj
->local_using_directives
;
11586 /* If we've finished processing a top-level function, subsequent
11587 symbols go in the file symbol list. */
11588 if (outermost_context_p ())
11589 cu
->list_in_scope
= &file_symbols
;
11592 /* Process all the DIES contained within a lexical block scope. Start
11593 a new scope, process the dies, and then close the scope. */
11596 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11598 struct objfile
*objfile
= cu
->objfile
;
11599 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11600 struct context_stack
*newobj
;
11601 CORE_ADDR lowpc
, highpc
;
11602 struct die_info
*child_die
;
11603 CORE_ADDR baseaddr
;
11605 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11607 /* Ignore blocks with missing or invalid low and high pc attributes. */
11608 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
11609 as multiple lexical blocks? Handling children in a sane way would
11610 be nasty. Might be easier to properly extend generic blocks to
11611 describe ranges. */
11612 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
11614 case PC_BOUNDS_NOT_PRESENT
:
11615 /* DW_TAG_lexical_block has no attributes, process its children as if
11616 there was no wrapping by that DW_TAG_lexical_block.
11617 GCC does no longer produces such DWARF since GCC r224161. */
11618 for (child_die
= die
->child
;
11619 child_die
!= NULL
&& child_die
->tag
;
11620 child_die
= sibling_die (child_die
))
11621 process_die (child_die
, cu
);
11623 case PC_BOUNDS_INVALID
:
11626 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11627 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11629 push_context (0, lowpc
);
11630 if (die
->child
!= NULL
)
11632 child_die
= die
->child
;
11633 while (child_die
&& child_die
->tag
)
11635 process_die (child_die
, cu
);
11636 child_die
= sibling_die (child_die
);
11639 inherit_abstract_dies (die
, cu
);
11640 newobj
= pop_context ();
11642 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
11644 struct block
*block
11645 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
11646 newobj
->start_addr
, highpc
);
11648 /* Note that recording ranges after traversing children, as we
11649 do here, means that recording a parent's ranges entails
11650 walking across all its children's ranges as they appear in
11651 the address map, which is quadratic behavior.
11653 It would be nicer to record the parent's ranges before
11654 traversing its children, simply overriding whatever you find
11655 there. But since we don't even decide whether to create a
11656 block until after we've traversed its children, that's hard
11658 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11660 local_symbols
= newobj
->locals
;
11661 local_using_directives
= newobj
->local_using_directives
;
11664 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
11667 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11669 struct objfile
*objfile
= cu
->objfile
;
11670 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11671 CORE_ADDR pc
, baseaddr
;
11672 struct attribute
*attr
;
11673 struct call_site
*call_site
, call_site_local
;
11676 struct die_info
*child_die
;
11678 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11680 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
11683 /* This was a pre-DWARF-5 GNU extension alias
11684 for DW_AT_call_return_pc. */
11685 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11689 complaint (&symfile_complaints
,
11690 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
11691 "DIE 0x%x [in module %s]"),
11692 die
->offset
.sect_off
, objfile_name (objfile
));
11695 pc
= attr_value_as_address (attr
) + baseaddr
;
11696 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
11698 if (cu
->call_site_htab
== NULL
)
11699 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
11700 NULL
, &objfile
->objfile_obstack
,
11701 hashtab_obstack_allocate
, NULL
);
11702 call_site_local
.pc
= pc
;
11703 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
11706 complaint (&symfile_complaints
,
11707 _("Duplicate PC %s for DW_TAG_call_site "
11708 "DIE 0x%x [in module %s]"),
11709 paddress (gdbarch
, pc
), die
->offset
.sect_off
,
11710 objfile_name (objfile
));
11714 /* Count parameters at the caller. */
11717 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11718 child_die
= sibling_die (child_die
))
11720 if (child_die
->tag
!= DW_TAG_call_site_parameter
11721 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11723 complaint (&symfile_complaints
,
11724 _("Tag %d is not DW_TAG_call_site_parameter in "
11725 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
11726 child_die
->tag
, child_die
->offset
.sect_off
,
11727 objfile_name (objfile
));
11735 = ((struct call_site
*)
11736 obstack_alloc (&objfile
->objfile_obstack
,
11737 sizeof (*call_site
)
11738 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
11740 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
11741 call_site
->pc
= pc
;
11743 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
11744 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
11746 struct die_info
*func_die
;
11748 /* Skip also over DW_TAG_inlined_subroutine. */
11749 for (func_die
= die
->parent
;
11750 func_die
&& func_die
->tag
!= DW_TAG_subprogram
11751 && func_die
->tag
!= DW_TAG_subroutine_type
;
11752 func_die
= func_die
->parent
);
11754 /* DW_AT_call_all_calls is a superset
11755 of DW_AT_call_all_tail_calls. */
11757 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
11758 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
11759 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
11760 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
11762 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
11763 not complete. But keep CALL_SITE for look ups via call_site_htab,
11764 both the initial caller containing the real return address PC and
11765 the final callee containing the current PC of a chain of tail
11766 calls do not need to have the tail call list complete. But any
11767 function candidate for a virtual tail call frame searched via
11768 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
11769 determined unambiguously. */
11773 struct type
*func_type
= NULL
;
11776 func_type
= get_die_type (func_die
, cu
);
11777 if (func_type
!= NULL
)
11779 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
11781 /* Enlist this call site to the function. */
11782 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
11783 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
11786 complaint (&symfile_complaints
,
11787 _("Cannot find function owning DW_TAG_call_site "
11788 "DIE 0x%x [in module %s]"),
11789 die
->offset
.sect_off
, objfile_name (objfile
));
11793 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
11795 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
11797 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
11800 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
11801 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11803 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
11804 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
11805 /* Keep NULL DWARF_BLOCK. */;
11806 else if (attr_form_is_block (attr
))
11808 struct dwarf2_locexpr_baton
*dlbaton
;
11810 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
11811 dlbaton
->data
= DW_BLOCK (attr
)->data
;
11812 dlbaton
->size
= DW_BLOCK (attr
)->size
;
11813 dlbaton
->per_cu
= cu
->per_cu
;
11815 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
11817 else if (attr_form_is_ref (attr
))
11819 struct dwarf2_cu
*target_cu
= cu
;
11820 struct die_info
*target_die
;
11822 target_die
= follow_die_ref (die
, attr
, &target_cu
);
11823 gdb_assert (target_cu
->objfile
== objfile
);
11824 if (die_is_declaration (target_die
, target_cu
))
11826 const char *target_physname
;
11828 /* Prefer the mangled name; otherwise compute the demangled one. */
11829 target_physname
= dwarf2_string_attr (target_die
,
11830 DW_AT_linkage_name
,
11832 if (target_physname
== NULL
)
11833 target_physname
= dwarf2_string_attr (target_die
,
11834 DW_AT_MIPS_linkage_name
,
11836 if (target_physname
== NULL
)
11837 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
11838 if (target_physname
== NULL
)
11839 complaint (&symfile_complaints
,
11840 _("DW_AT_call_target target DIE has invalid "
11841 "physname, for referencing DIE 0x%x [in module %s]"),
11842 die
->offset
.sect_off
, objfile_name (objfile
));
11844 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
11850 /* DW_AT_entry_pc should be preferred. */
11851 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
11852 <= PC_BOUNDS_INVALID
)
11853 complaint (&symfile_complaints
,
11854 _("DW_AT_call_target target DIE has invalid "
11855 "low pc, for referencing DIE 0x%x [in module %s]"),
11856 die
->offset
.sect_off
, objfile_name (objfile
));
11859 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11860 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
11865 complaint (&symfile_complaints
,
11866 _("DW_TAG_call_site DW_AT_call_target is neither "
11867 "block nor reference, for DIE 0x%x [in module %s]"),
11868 die
->offset
.sect_off
, objfile_name (objfile
));
11870 call_site
->per_cu
= cu
->per_cu
;
11872 for (child_die
= die
->child
;
11873 child_die
&& child_die
->tag
;
11874 child_die
= sibling_die (child_die
))
11876 struct call_site_parameter
*parameter
;
11877 struct attribute
*loc
, *origin
;
11879 if (child_die
->tag
!= DW_TAG_call_site_parameter
11880 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11882 /* Already printed the complaint above. */
11886 gdb_assert (call_site
->parameter_count
< nparams
);
11887 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
11889 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
11890 specifies DW_TAG_formal_parameter. Value of the data assumed for the
11891 register is contained in DW_AT_call_value. */
11893 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
11894 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
11895 if (origin
== NULL
)
11897 /* This was a pre-DWARF-5 GNU extension alias
11898 for DW_AT_call_parameter. */
11899 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
11901 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
11903 sect_offset offset
;
11905 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
11906 offset
= dwarf2_get_ref_die_offset (origin
);
11907 if (!offset_in_cu_p (&cu
->header
, offset
))
11909 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
11910 binding can be done only inside one CU. Such referenced DIE
11911 therefore cannot be even moved to DW_TAG_partial_unit. */
11912 complaint (&symfile_complaints
,
11913 _("DW_AT_call_parameter offset is not in CU for "
11914 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
11915 child_die
->offset
.sect_off
, objfile_name (objfile
));
11918 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
11919 - cu
->header
.offset
.sect_off
);
11921 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
11923 complaint (&symfile_complaints
,
11924 _("No DW_FORM_block* DW_AT_location for "
11925 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
11926 child_die
->offset
.sect_off
, objfile_name (objfile
));
11931 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
11932 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
11933 if (parameter
->u
.dwarf_reg
!= -1)
11934 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
11935 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
11936 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
11937 ¶meter
->u
.fb_offset
))
11938 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
11941 complaint (&symfile_complaints
,
11942 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
11943 "for DW_FORM_block* DW_AT_location is supported for "
11944 "DW_TAG_call_site child DIE 0x%x "
11946 child_die
->offset
.sect_off
, objfile_name (objfile
));
11951 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
11953 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
11954 if (!attr_form_is_block (attr
))
11956 complaint (&symfile_complaints
,
11957 _("No DW_FORM_block* DW_AT_call_value for "
11958 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
11959 child_die
->offset
.sect_off
, objfile_name (objfile
));
11962 parameter
->value
= DW_BLOCK (attr
)->data
;
11963 parameter
->value_size
= DW_BLOCK (attr
)->size
;
11965 /* Parameters are not pre-cleared by memset above. */
11966 parameter
->data_value
= NULL
;
11967 parameter
->data_value_size
= 0;
11968 call_site
->parameter_count
++;
11970 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
11972 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
11975 if (!attr_form_is_block (attr
))
11976 complaint (&symfile_complaints
,
11977 _("No DW_FORM_block* DW_AT_call_data_value for "
11978 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
11979 child_die
->offset
.sect_off
, objfile_name (objfile
));
11982 parameter
->data_value
= DW_BLOCK (attr
)->data
;
11983 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
11989 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
11990 reading .debug_rnglists.
11991 Callback's type should be:
11992 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
11993 Return true if the attributes are present and valid, otherwise,
11996 template <typename Callback
>
11998 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
11999 Callback
&&callback
)
12001 struct objfile
*objfile
= cu
->objfile
;
12002 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12003 struct comp_unit_head
*cu_header
= &cu
->header
;
12004 bfd
*obfd
= objfile
->obfd
;
12005 unsigned int addr_size
= cu_header
->addr_size
;
12006 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12007 /* Base address selection entry. */
12010 unsigned int dummy
;
12011 const gdb_byte
*buffer
;
12013 CORE_ADDR high
= 0;
12014 CORE_ADDR baseaddr
;
12015 bool overflow
= false;
12017 found_base
= cu
->base_known
;
12018 base
= cu
->base_address
;
12020 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
12021 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
12023 complaint (&symfile_complaints
,
12024 _("Offset %d out of bounds for DW_AT_ranges attribute"),
12028 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
12030 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12034 /* Initialize it due to a false compiler warning. */
12035 CORE_ADDR range_beginning
= 0, range_end
= 0;
12036 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
12037 + dwarf2_per_objfile
->rnglists
.size
);
12038 unsigned int bytes_read
;
12040 if (buffer
== buf_end
)
12045 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
12048 case DW_RLE_end_of_list
:
12050 case DW_RLE_base_address
:
12051 if (buffer
+ cu
->header
.addr_size
> buf_end
)
12056 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12058 buffer
+= bytes_read
;
12060 case DW_RLE_start_length
:
12061 if (buffer
+ cu
->header
.addr_size
> buf_end
)
12066 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12067 buffer
+= bytes_read
;
12068 range_end
= (range_beginning
12069 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
12070 buffer
+= bytes_read
;
12071 if (buffer
> buf_end
)
12077 case DW_RLE_offset_pair
:
12078 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12079 buffer
+= bytes_read
;
12080 if (buffer
> buf_end
)
12085 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12086 buffer
+= bytes_read
;
12087 if (buffer
> buf_end
)
12093 case DW_RLE_start_end
:
12094 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
12099 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12100 buffer
+= bytes_read
;
12101 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12102 buffer
+= bytes_read
;
12105 complaint (&symfile_complaints
,
12106 _("Invalid .debug_rnglists data (no base address)"));
12109 if (rlet
== DW_RLE_end_of_list
|| overflow
)
12111 if (rlet
== DW_RLE_base_address
)
12116 /* We have no valid base address for the ranges
12118 complaint (&symfile_complaints
,
12119 _("Invalid .debug_rnglists data (no base address)"));
12123 if (range_beginning
> range_end
)
12125 /* Inverted range entries are invalid. */
12126 complaint (&symfile_complaints
,
12127 _("Invalid .debug_rnglists data (inverted range)"));
12131 /* Empty range entries have no effect. */
12132 if (range_beginning
== range_end
)
12135 range_beginning
+= base
;
12138 /* A not-uncommon case of bad debug info.
12139 Don't pollute the addrmap with bad data. */
12140 if (range_beginning
+ baseaddr
== 0
12141 && !dwarf2_per_objfile
->has_section_at_zero
)
12143 complaint (&symfile_complaints
,
12144 _(".debug_rnglists entry has start address of zero"
12145 " [in module %s]"), objfile_name (objfile
));
12149 callback (range_beginning
, range_end
);
12154 complaint (&symfile_complaints
,
12155 _("Offset %d is not terminated "
12156 "for DW_AT_ranges attribute"),
12164 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
12165 Callback's type should be:
12166 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
12167 Return 1 if the attributes are present and valid, otherwise, return 0. */
12169 template <typename Callback
>
12171 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
12172 Callback
&&callback
)
12174 struct objfile
*objfile
= cu
->objfile
;
12175 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12176 struct comp_unit_head
*cu_header
= &cu
->header
;
12177 bfd
*obfd
= objfile
->obfd
;
12178 unsigned int addr_size
= cu_header
->addr_size
;
12179 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12180 /* Base address selection entry. */
12183 unsigned int dummy
;
12184 const gdb_byte
*buffer
;
12185 CORE_ADDR baseaddr
;
12187 if (cu_header
->version
>= 5)
12188 return dwarf2_rnglists_process (offset
, cu
, callback
);
12190 found_base
= cu
->base_known
;
12191 base
= cu
->base_address
;
12193 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
12194 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
12196 complaint (&symfile_complaints
,
12197 _("Offset %d out of bounds for DW_AT_ranges attribute"),
12201 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
12203 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12207 CORE_ADDR range_beginning
, range_end
;
12209 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
12210 buffer
+= addr_size
;
12211 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
12212 buffer
+= addr_size
;
12213 offset
+= 2 * addr_size
;
12215 /* An end of list marker is a pair of zero addresses. */
12216 if (range_beginning
== 0 && range_end
== 0)
12217 /* Found the end of list entry. */
12220 /* Each base address selection entry is a pair of 2 values.
12221 The first is the largest possible address, the second is
12222 the base address. Check for a base address here. */
12223 if ((range_beginning
& mask
) == mask
)
12225 /* If we found the largest possible address, then we already
12226 have the base address in range_end. */
12234 /* We have no valid base address for the ranges
12236 complaint (&symfile_complaints
,
12237 _("Invalid .debug_ranges data (no base address)"));
12241 if (range_beginning
> range_end
)
12243 /* Inverted range entries are invalid. */
12244 complaint (&symfile_complaints
,
12245 _("Invalid .debug_ranges data (inverted range)"));
12249 /* Empty range entries have no effect. */
12250 if (range_beginning
== range_end
)
12253 range_beginning
+= base
;
12256 /* A not-uncommon case of bad debug info.
12257 Don't pollute the addrmap with bad data. */
12258 if (range_beginning
+ baseaddr
== 0
12259 && !dwarf2_per_objfile
->has_section_at_zero
)
12261 complaint (&symfile_complaints
,
12262 _(".debug_ranges entry has start address of zero"
12263 " [in module %s]"), objfile_name (objfile
));
12267 callback (range_beginning
, range_end
);
12273 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
12274 Return 1 if the attributes are present and valid, otherwise, return 0.
12275 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
12278 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
12279 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
12280 struct partial_symtab
*ranges_pst
)
12282 struct objfile
*objfile
= cu
->objfile
;
12283 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12284 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
12285 SECT_OFF_TEXT (objfile
));
12288 CORE_ADDR high
= 0;
12291 retval
= dwarf2_ranges_process (offset
, cu
,
12292 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
12294 if (ranges_pst
!= NULL
)
12299 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
12300 range_beginning
+ baseaddr
);
12301 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
12302 range_end
+ baseaddr
);
12303 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
12307 /* FIXME: This is recording everything as a low-high
12308 segment of consecutive addresses. We should have a
12309 data structure for discontiguous block ranges
12313 low
= range_beginning
;
12319 if (range_beginning
< low
)
12320 low
= range_beginning
;
12321 if (range_end
> high
)
12329 /* If the first entry is an end-of-list marker, the range
12330 describes an empty scope, i.e. no instructions. */
12336 *high_return
= high
;
12340 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
12341 definition for the return value. *LOWPC and *HIGHPC are set iff
12342 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
12344 static enum pc_bounds_kind
12345 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
12346 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
12347 struct partial_symtab
*pst
)
12349 struct attribute
*attr
;
12350 struct attribute
*attr_high
;
12352 CORE_ADDR high
= 0;
12353 enum pc_bounds_kind ret
;
12355 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12358 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12361 low
= attr_value_as_address (attr
);
12362 high
= attr_value_as_address (attr_high
);
12363 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12367 /* Found high w/o low attribute. */
12368 return PC_BOUNDS_INVALID
;
12370 /* Found consecutive range of addresses. */
12371 ret
= PC_BOUNDS_HIGH_LOW
;
12375 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12378 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12379 We take advantage of the fact that DW_AT_ranges does not appear
12380 in DW_TAG_compile_unit of DWO files. */
12381 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12382 unsigned int ranges_offset
= (DW_UNSND (attr
)
12383 + (need_ranges_base
12387 /* Value of the DW_AT_ranges attribute is the offset in the
12388 .debug_ranges section. */
12389 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
12390 return PC_BOUNDS_INVALID
;
12391 /* Found discontinuous range of addresses. */
12392 ret
= PC_BOUNDS_RANGES
;
12395 return PC_BOUNDS_NOT_PRESENT
;
12398 /* read_partial_die has also the strict LOW < HIGH requirement. */
12400 return PC_BOUNDS_INVALID
;
12402 /* When using the GNU linker, .gnu.linkonce. sections are used to
12403 eliminate duplicate copies of functions and vtables and such.
12404 The linker will arbitrarily choose one and discard the others.
12405 The AT_*_pc values for such functions refer to local labels in
12406 these sections. If the section from that file was discarded, the
12407 labels are not in the output, so the relocs get a value of 0.
12408 If this is a discarded function, mark the pc bounds as invalid,
12409 so that GDB will ignore it. */
12410 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12411 return PC_BOUNDS_INVALID
;
12419 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
12420 its low and high PC addresses. Do nothing if these addresses could not
12421 be determined. Otherwise, set LOWPC to the low address if it is smaller,
12422 and HIGHPC to the high address if greater than HIGHPC. */
12425 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
12426 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12427 struct dwarf2_cu
*cu
)
12429 CORE_ADDR low
, high
;
12430 struct die_info
*child
= die
->child
;
12432 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
12434 *lowpc
= std::min (*lowpc
, low
);
12435 *highpc
= std::max (*highpc
, high
);
12438 /* If the language does not allow nested subprograms (either inside
12439 subprograms or lexical blocks), we're done. */
12440 if (cu
->language
!= language_ada
)
12443 /* Check all the children of the given DIE. If it contains nested
12444 subprograms, then check their pc bounds. Likewise, we need to
12445 check lexical blocks as well, as they may also contain subprogram
12447 while (child
&& child
->tag
)
12449 if (child
->tag
== DW_TAG_subprogram
12450 || child
->tag
== DW_TAG_lexical_block
)
12451 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
12452 child
= sibling_die (child
);
12456 /* Get the low and high pc's represented by the scope DIE, and store
12457 them in *LOWPC and *HIGHPC. If the correct values can't be
12458 determined, set *LOWPC to -1 and *HIGHPC to 0. */
12461 get_scope_pc_bounds (struct die_info
*die
,
12462 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12463 struct dwarf2_cu
*cu
)
12465 CORE_ADDR best_low
= (CORE_ADDR
) -1;
12466 CORE_ADDR best_high
= (CORE_ADDR
) 0;
12467 CORE_ADDR current_low
, current_high
;
12469 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
12470 >= PC_BOUNDS_RANGES
)
12472 best_low
= current_low
;
12473 best_high
= current_high
;
12477 struct die_info
*child
= die
->child
;
12479 while (child
&& child
->tag
)
12481 switch (child
->tag
) {
12482 case DW_TAG_subprogram
:
12483 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
12485 case DW_TAG_namespace
:
12486 case DW_TAG_module
:
12487 /* FIXME: carlton/2004-01-16: Should we do this for
12488 DW_TAG_class_type/DW_TAG_structure_type, too? I think
12489 that current GCC's always emit the DIEs corresponding
12490 to definitions of methods of classes as children of a
12491 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
12492 the DIEs giving the declarations, which could be
12493 anywhere). But I don't see any reason why the
12494 standards says that they have to be there. */
12495 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
12497 if (current_low
!= ((CORE_ADDR
) -1))
12499 best_low
= std::min (best_low
, current_low
);
12500 best_high
= std::max (best_high
, current_high
);
12508 child
= sibling_die (child
);
12513 *highpc
= best_high
;
12516 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
12520 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
12521 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
12523 struct objfile
*objfile
= cu
->objfile
;
12524 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12525 struct attribute
*attr
;
12526 struct attribute
*attr_high
;
12528 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12531 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12534 CORE_ADDR low
= attr_value_as_address (attr
);
12535 CORE_ADDR high
= attr_value_as_address (attr_high
);
12537 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12540 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
12541 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
12542 record_block_range (block
, low
, high
- 1);
12546 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12549 bfd
*obfd
= objfile
->obfd
;
12550 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12551 We take advantage of the fact that DW_AT_ranges does not appear
12552 in DW_TAG_compile_unit of DWO files. */
12553 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12555 /* The value of the DW_AT_ranges attribute is the offset of the
12556 address range list in the .debug_ranges section. */
12557 unsigned long offset
= (DW_UNSND (attr
)
12558 + (need_ranges_base
? cu
->ranges_base
: 0));
12559 const gdb_byte
*buffer
;
12561 /* For some target architectures, but not others, the
12562 read_address function sign-extends the addresses it returns.
12563 To recognize base address selection entries, we need a
12565 unsigned int addr_size
= cu
->header
.addr_size
;
12566 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12568 /* The base address, to which the next pair is relative. Note
12569 that this 'base' is a DWARF concept: most entries in a range
12570 list are relative, to reduce the number of relocs against the
12571 debugging information. This is separate from this function's
12572 'baseaddr' argument, which GDB uses to relocate debugging
12573 information from a shared library based on the address at
12574 which the library was loaded. */
12575 CORE_ADDR base
= cu
->base_address
;
12576 int base_known
= cu
->base_known
;
12578 dwarf2_ranges_process (offset
, cu
,
12579 [&] (CORE_ADDR start
, CORE_ADDR end
)
12583 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
12584 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
12585 record_block_range (block
, start
, end
- 1);
12590 /* Check whether the producer field indicates either of GCC < 4.6, or the
12591 Intel C/C++ compiler, and cache the result in CU. */
12594 check_producer (struct dwarf2_cu
*cu
)
12598 if (cu
->producer
== NULL
)
12600 /* For unknown compilers expect their behavior is DWARF version
12603 GCC started to support .debug_types sections by -gdwarf-4 since
12604 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
12605 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
12606 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
12607 interpreted incorrectly by GDB now - GCC PR debug/48229. */
12609 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
12611 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
12612 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
12614 else if (startswith (cu
->producer
, "Intel(R) C"))
12615 cu
->producer_is_icc
= 1;
12618 /* For other non-GCC compilers, expect their behavior is DWARF version
12622 cu
->checked_producer
= 1;
12625 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
12626 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
12627 during 4.6.0 experimental. */
12630 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
12632 if (!cu
->checked_producer
)
12633 check_producer (cu
);
12635 return cu
->producer_is_gxx_lt_4_6
;
12638 /* Return the default accessibility type if it is not overriden by
12639 DW_AT_accessibility. */
12641 static enum dwarf_access_attribute
12642 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
12644 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
12646 /* The default DWARF 2 accessibility for members is public, the default
12647 accessibility for inheritance is private. */
12649 if (die
->tag
!= DW_TAG_inheritance
)
12650 return DW_ACCESS_public
;
12652 return DW_ACCESS_private
;
12656 /* DWARF 3+ defines the default accessibility a different way. The same
12657 rules apply now for DW_TAG_inheritance as for the members and it only
12658 depends on the container kind. */
12660 if (die
->parent
->tag
== DW_TAG_class_type
)
12661 return DW_ACCESS_private
;
12663 return DW_ACCESS_public
;
12667 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
12668 offset. If the attribute was not found return 0, otherwise return
12669 1. If it was found but could not properly be handled, set *OFFSET
12673 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
12676 struct attribute
*attr
;
12678 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
12683 /* Note that we do not check for a section offset first here.
12684 This is because DW_AT_data_member_location is new in DWARF 4,
12685 so if we see it, we can assume that a constant form is really
12686 a constant and not a section offset. */
12687 if (attr_form_is_constant (attr
))
12688 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
12689 else if (attr_form_is_section_offset (attr
))
12690 dwarf2_complex_location_expr_complaint ();
12691 else if (attr_form_is_block (attr
))
12692 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
12694 dwarf2_complex_location_expr_complaint ();
12702 /* Add an aggregate field to the field list. */
12705 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
12706 struct dwarf2_cu
*cu
)
12708 struct objfile
*objfile
= cu
->objfile
;
12709 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12710 struct nextfield
*new_field
;
12711 struct attribute
*attr
;
12713 const char *fieldname
= "";
12715 /* Allocate a new field list entry and link it in. */
12716 new_field
= XNEW (struct nextfield
);
12717 make_cleanup (xfree
, new_field
);
12718 memset (new_field
, 0, sizeof (struct nextfield
));
12720 if (die
->tag
== DW_TAG_inheritance
)
12722 new_field
->next
= fip
->baseclasses
;
12723 fip
->baseclasses
= new_field
;
12727 new_field
->next
= fip
->fields
;
12728 fip
->fields
= new_field
;
12732 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
12734 new_field
->accessibility
= DW_UNSND (attr
);
12736 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
12737 if (new_field
->accessibility
!= DW_ACCESS_public
)
12738 fip
->non_public_fields
= 1;
12740 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
12742 new_field
->virtuality
= DW_UNSND (attr
);
12744 new_field
->virtuality
= DW_VIRTUALITY_none
;
12746 fp
= &new_field
->field
;
12748 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
12752 /* Data member other than a C++ static data member. */
12754 /* Get type of field. */
12755 fp
->type
= die_type (die
, cu
);
12757 SET_FIELD_BITPOS (*fp
, 0);
12759 /* Get bit size of field (zero if none). */
12760 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
12763 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
12767 FIELD_BITSIZE (*fp
) = 0;
12770 /* Get bit offset of field. */
12771 if (handle_data_member_location (die
, cu
, &offset
))
12772 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12773 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
12776 if (gdbarch_bits_big_endian (gdbarch
))
12778 /* For big endian bits, the DW_AT_bit_offset gives the
12779 additional bit offset from the MSB of the containing
12780 anonymous object to the MSB of the field. We don't
12781 have to do anything special since we don't need to
12782 know the size of the anonymous object. */
12783 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
12787 /* For little endian bits, compute the bit offset to the
12788 MSB of the anonymous object, subtract off the number of
12789 bits from the MSB of the field to the MSB of the
12790 object, and then subtract off the number of bits of
12791 the field itself. The result is the bit offset of
12792 the LSB of the field. */
12793 int anonymous_size
;
12794 int bit_offset
= DW_UNSND (attr
);
12796 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12799 /* The size of the anonymous object containing
12800 the bit field is explicit, so use the
12801 indicated size (in bytes). */
12802 anonymous_size
= DW_UNSND (attr
);
12806 /* The size of the anonymous object containing
12807 the bit field must be inferred from the type
12808 attribute of the data member containing the
12810 anonymous_size
= TYPE_LENGTH (fp
->type
);
12812 SET_FIELD_BITPOS (*fp
,
12813 (FIELD_BITPOS (*fp
)
12814 + anonymous_size
* bits_per_byte
12815 - bit_offset
- FIELD_BITSIZE (*fp
)));
12818 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
12820 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
12821 + dwarf2_get_attr_constant_value (attr
, 0)));
12823 /* Get name of field. */
12824 fieldname
= dwarf2_name (die
, cu
);
12825 if (fieldname
== NULL
)
12828 /* The name is already allocated along with this objfile, so we don't
12829 need to duplicate it for the type. */
12830 fp
->name
= fieldname
;
12832 /* Change accessibility for artificial fields (e.g. virtual table
12833 pointer or virtual base class pointer) to private. */
12834 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
12836 FIELD_ARTIFICIAL (*fp
) = 1;
12837 new_field
->accessibility
= DW_ACCESS_private
;
12838 fip
->non_public_fields
= 1;
12841 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
12843 /* C++ static member. */
12845 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
12846 is a declaration, but all versions of G++ as of this writing
12847 (so through at least 3.2.1) incorrectly generate
12848 DW_TAG_variable tags. */
12850 const char *physname
;
12852 /* Get name of field. */
12853 fieldname
= dwarf2_name (die
, cu
);
12854 if (fieldname
== NULL
)
12857 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12859 /* Only create a symbol if this is an external value.
12860 new_symbol checks this and puts the value in the global symbol
12861 table, which we want. If it is not external, new_symbol
12862 will try to put the value in cu->list_in_scope which is wrong. */
12863 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
12865 /* A static const member, not much different than an enum as far as
12866 we're concerned, except that we can support more types. */
12867 new_symbol (die
, NULL
, cu
);
12870 /* Get physical name. */
12871 physname
= dwarf2_physname (fieldname
, die
, cu
);
12873 /* The name is already allocated along with this objfile, so we don't
12874 need to duplicate it for the type. */
12875 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
12876 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12877 FIELD_NAME (*fp
) = fieldname
;
12879 else if (die
->tag
== DW_TAG_inheritance
)
12883 /* C++ base class field. */
12884 if (handle_data_member_location (die
, cu
, &offset
))
12885 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12886 FIELD_BITSIZE (*fp
) = 0;
12887 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12888 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
12889 fip
->nbaseclasses
++;
12893 /* Add a typedef defined in the scope of the FIP's class. */
12896 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
12897 struct dwarf2_cu
*cu
)
12899 struct typedef_field_list
*new_field
;
12900 struct typedef_field
*fp
;
12902 /* Allocate a new field list entry and link it in. */
12903 new_field
= XCNEW (struct typedef_field_list
);
12904 make_cleanup (xfree
, new_field
);
12906 gdb_assert (die
->tag
== DW_TAG_typedef
);
12908 fp
= &new_field
->field
;
12910 /* Get name of field. */
12911 fp
->name
= dwarf2_name (die
, cu
);
12912 if (fp
->name
== NULL
)
12915 fp
->type
= read_type_die (die
, cu
);
12917 new_field
->next
= fip
->typedef_field_list
;
12918 fip
->typedef_field_list
= new_field
;
12919 fip
->typedef_field_list_count
++;
12922 /* Create the vector of fields, and attach it to the type. */
12925 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
12926 struct dwarf2_cu
*cu
)
12928 int nfields
= fip
->nfields
;
12930 /* Record the field count, allocate space for the array of fields,
12931 and create blank accessibility bitfields if necessary. */
12932 TYPE_NFIELDS (type
) = nfields
;
12933 TYPE_FIELDS (type
) = (struct field
*)
12934 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
12935 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
12937 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
12939 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12941 TYPE_FIELD_PRIVATE_BITS (type
) =
12942 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12943 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
12945 TYPE_FIELD_PROTECTED_BITS (type
) =
12946 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12947 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
12949 TYPE_FIELD_IGNORE_BITS (type
) =
12950 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12951 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
12954 /* If the type has baseclasses, allocate and clear a bit vector for
12955 TYPE_FIELD_VIRTUAL_BITS. */
12956 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
12958 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
12959 unsigned char *pointer
;
12961 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12962 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
12963 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
12964 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
12965 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
12968 /* Copy the saved-up fields into the field vector. Start from the head of
12969 the list, adding to the tail of the field array, so that they end up in
12970 the same order in the array in which they were added to the list. */
12971 while (nfields
-- > 0)
12973 struct nextfield
*fieldp
;
12977 fieldp
= fip
->fields
;
12978 fip
->fields
= fieldp
->next
;
12982 fieldp
= fip
->baseclasses
;
12983 fip
->baseclasses
= fieldp
->next
;
12986 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
12987 switch (fieldp
->accessibility
)
12989 case DW_ACCESS_private
:
12990 if (cu
->language
!= language_ada
)
12991 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
12994 case DW_ACCESS_protected
:
12995 if (cu
->language
!= language_ada
)
12996 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
12999 case DW_ACCESS_public
:
13003 /* Unknown accessibility. Complain and treat it as public. */
13005 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
13006 fieldp
->accessibility
);
13010 if (nfields
< fip
->nbaseclasses
)
13012 switch (fieldp
->virtuality
)
13014 case DW_VIRTUALITY_virtual
:
13015 case DW_VIRTUALITY_pure_virtual
:
13016 if (cu
->language
== language_ada
)
13017 error (_("unexpected virtuality in component of Ada type"));
13018 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
13025 /* Return true if this member function is a constructor, false
13029 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
13031 const char *fieldname
;
13032 const char *type_name
;
13035 if (die
->parent
== NULL
)
13038 if (die
->parent
->tag
!= DW_TAG_structure_type
13039 && die
->parent
->tag
!= DW_TAG_union_type
13040 && die
->parent
->tag
!= DW_TAG_class_type
)
13043 fieldname
= dwarf2_name (die
, cu
);
13044 type_name
= dwarf2_name (die
->parent
, cu
);
13045 if (fieldname
== NULL
|| type_name
== NULL
)
13048 len
= strlen (fieldname
);
13049 return (strncmp (fieldname
, type_name
, len
) == 0
13050 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
13053 /* Add a member function to the proper fieldlist. */
13056 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
13057 struct type
*type
, struct dwarf2_cu
*cu
)
13059 struct objfile
*objfile
= cu
->objfile
;
13060 struct attribute
*attr
;
13061 struct fnfieldlist
*flp
;
13063 struct fn_field
*fnp
;
13064 const char *fieldname
;
13065 struct nextfnfield
*new_fnfield
;
13066 struct type
*this_type
;
13067 enum dwarf_access_attribute accessibility
;
13069 if (cu
->language
== language_ada
)
13070 error (_("unexpected member function in Ada type"));
13072 /* Get name of member function. */
13073 fieldname
= dwarf2_name (die
, cu
);
13074 if (fieldname
== NULL
)
13077 /* Look up member function name in fieldlist. */
13078 for (i
= 0; i
< fip
->nfnfields
; i
++)
13080 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
13084 /* Create new list element if necessary. */
13085 if (i
< fip
->nfnfields
)
13086 flp
= &fip
->fnfieldlists
[i
];
13089 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
13091 fip
->fnfieldlists
= (struct fnfieldlist
*)
13092 xrealloc (fip
->fnfieldlists
,
13093 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
13094 * sizeof (struct fnfieldlist
));
13095 if (fip
->nfnfields
== 0)
13096 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
13098 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
13099 flp
->name
= fieldname
;
13102 i
= fip
->nfnfields
++;
13105 /* Create a new member function field and chain it to the field list
13107 new_fnfield
= XNEW (struct nextfnfield
);
13108 make_cleanup (xfree
, new_fnfield
);
13109 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
13110 new_fnfield
->next
= flp
->head
;
13111 flp
->head
= new_fnfield
;
13114 /* Fill in the member function field info. */
13115 fnp
= &new_fnfield
->fnfield
;
13117 /* Delay processing of the physname until later. */
13118 if (cu
->language
== language_cplus
)
13120 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
13125 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
13126 fnp
->physname
= physname
? physname
: "";
13129 fnp
->type
= alloc_type (objfile
);
13130 this_type
= read_type_die (die
, cu
);
13131 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
13133 int nparams
= TYPE_NFIELDS (this_type
);
13135 /* TYPE is the domain of this method, and THIS_TYPE is the type
13136 of the method itself (TYPE_CODE_METHOD). */
13137 smash_to_method_type (fnp
->type
, type
,
13138 TYPE_TARGET_TYPE (this_type
),
13139 TYPE_FIELDS (this_type
),
13140 TYPE_NFIELDS (this_type
),
13141 TYPE_VARARGS (this_type
));
13143 /* Handle static member functions.
13144 Dwarf2 has no clean way to discern C++ static and non-static
13145 member functions. G++ helps GDB by marking the first
13146 parameter for non-static member functions (which is the this
13147 pointer) as artificial. We obtain this information from
13148 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
13149 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
13150 fnp
->voffset
= VOFFSET_STATIC
;
13153 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
13154 dwarf2_full_name (fieldname
, die
, cu
));
13156 /* Get fcontext from DW_AT_containing_type if present. */
13157 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
13158 fnp
->fcontext
= die_containing_type (die
, cu
);
13160 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
13161 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
13163 /* Get accessibility. */
13164 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
13166 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
13168 accessibility
= dwarf2_default_access_attribute (die
, cu
);
13169 switch (accessibility
)
13171 case DW_ACCESS_private
:
13172 fnp
->is_private
= 1;
13174 case DW_ACCESS_protected
:
13175 fnp
->is_protected
= 1;
13179 /* Check for artificial methods. */
13180 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
13181 if (attr
&& DW_UNSND (attr
) != 0)
13182 fnp
->is_artificial
= 1;
13184 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
13186 /* Get index in virtual function table if it is a virtual member
13187 function. For older versions of GCC, this is an offset in the
13188 appropriate virtual table, as specified by DW_AT_containing_type.
13189 For everyone else, it is an expression to be evaluated relative
13190 to the object address. */
13192 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
13195 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
13197 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
13199 /* Old-style GCC. */
13200 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
13202 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
13203 || (DW_BLOCK (attr
)->size
> 1
13204 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
13205 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
13207 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
13208 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
13209 dwarf2_complex_location_expr_complaint ();
13211 fnp
->voffset
/= cu
->header
.addr_size
;
13215 dwarf2_complex_location_expr_complaint ();
13217 if (!fnp
->fcontext
)
13219 /* If there is no `this' field and no DW_AT_containing_type,
13220 we cannot actually find a base class context for the
13222 if (TYPE_NFIELDS (this_type
) == 0
13223 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
13225 complaint (&symfile_complaints
,
13226 _("cannot determine context for virtual member "
13227 "function \"%s\" (offset %d)"),
13228 fieldname
, die
->offset
.sect_off
);
13233 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
13237 else if (attr_form_is_section_offset (attr
))
13239 dwarf2_complex_location_expr_complaint ();
13243 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
13249 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
13250 if (attr
&& DW_UNSND (attr
))
13252 /* GCC does this, as of 2008-08-25; PR debug/37237. */
13253 complaint (&symfile_complaints
,
13254 _("Member function \"%s\" (offset %d) is virtual "
13255 "but the vtable offset is not specified"),
13256 fieldname
, die
->offset
.sect_off
);
13257 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13258 TYPE_CPLUS_DYNAMIC (type
) = 1;
13263 /* Create the vector of member function fields, and attach it to the type. */
13266 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
13267 struct dwarf2_cu
*cu
)
13269 struct fnfieldlist
*flp
;
13272 if (cu
->language
== language_ada
)
13273 error (_("unexpected member functions in Ada type"));
13275 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13276 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
13277 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
13279 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
13281 struct nextfnfield
*nfp
= flp
->head
;
13282 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
13285 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
13286 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
13287 fn_flp
->fn_fields
= (struct fn_field
*)
13288 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
13289 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
13290 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
13293 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
13296 /* Returns non-zero if NAME is the name of a vtable member in CU's
13297 language, zero otherwise. */
13299 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
13301 static const char vptr
[] = "_vptr";
13302 static const char vtable
[] = "vtable";
13304 /* Look for the C++ form of the vtable. */
13305 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
13311 /* GCC outputs unnamed structures that are really pointers to member
13312 functions, with the ABI-specified layout. If TYPE describes
13313 such a structure, smash it into a member function type.
13315 GCC shouldn't do this; it should just output pointer to member DIEs.
13316 This is GCC PR debug/28767. */
13319 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
13321 struct type
*pfn_type
, *self_type
, *new_type
;
13323 /* Check for a structure with no name and two children. */
13324 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
13327 /* Check for __pfn and __delta members. */
13328 if (TYPE_FIELD_NAME (type
, 0) == NULL
13329 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
13330 || TYPE_FIELD_NAME (type
, 1) == NULL
13331 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
13334 /* Find the type of the method. */
13335 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
13336 if (pfn_type
== NULL
13337 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
13338 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
13341 /* Look for the "this" argument. */
13342 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
13343 if (TYPE_NFIELDS (pfn_type
) == 0
13344 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
13345 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
13348 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
13349 new_type
= alloc_type (objfile
);
13350 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
13351 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
13352 TYPE_VARARGS (pfn_type
));
13353 smash_to_methodptr_type (type
, new_type
);
13356 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
13360 producer_is_icc (struct dwarf2_cu
*cu
)
13362 if (!cu
->checked_producer
)
13363 check_producer (cu
);
13365 return cu
->producer_is_icc
;
13368 /* Called when we find the DIE that starts a structure or union scope
13369 (definition) to create a type for the structure or union. Fill in
13370 the type's name and general properties; the members will not be
13371 processed until process_structure_scope. A symbol table entry for
13372 the type will also not be done until process_structure_scope (assuming
13373 the type has a name).
13375 NOTE: we need to call these functions regardless of whether or not the
13376 DIE has a DW_AT_name attribute, since it might be an anonymous
13377 structure or union. This gets the type entered into our set of
13378 user defined types. */
13380 static struct type
*
13381 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13383 struct objfile
*objfile
= cu
->objfile
;
13385 struct attribute
*attr
;
13388 /* If the definition of this type lives in .debug_types, read that type.
13389 Don't follow DW_AT_specification though, that will take us back up
13390 the chain and we want to go down. */
13391 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
13394 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13396 /* The type's CU may not be the same as CU.
13397 Ensure TYPE is recorded with CU in die_type_hash. */
13398 return set_die_type (die
, type
, cu
);
13401 type
= alloc_type (objfile
);
13402 INIT_CPLUS_SPECIFIC (type
);
13404 name
= dwarf2_name (die
, cu
);
13407 if (cu
->language
== language_cplus
13408 || cu
->language
== language_d
13409 || cu
->language
== language_rust
)
13411 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
13413 /* dwarf2_full_name might have already finished building the DIE's
13414 type. If so, there is no need to continue. */
13415 if (get_die_type (die
, cu
) != NULL
)
13416 return get_die_type (die
, cu
);
13418 TYPE_TAG_NAME (type
) = full_name
;
13419 if (die
->tag
== DW_TAG_structure_type
13420 || die
->tag
== DW_TAG_class_type
)
13421 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13425 /* The name is already allocated along with this objfile, so
13426 we don't need to duplicate it for the type. */
13427 TYPE_TAG_NAME (type
) = name
;
13428 if (die
->tag
== DW_TAG_class_type
)
13429 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13433 if (die
->tag
== DW_TAG_structure_type
)
13435 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13437 else if (die
->tag
== DW_TAG_union_type
)
13439 TYPE_CODE (type
) = TYPE_CODE_UNION
;
13443 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13446 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
13447 TYPE_DECLARED_CLASS (type
) = 1;
13449 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13452 if (attr_form_is_constant (attr
))
13453 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13456 /* For the moment, dynamic type sizes are not supported
13457 by GDB's struct type. The actual size is determined
13458 on-demand when resolving the type of a given object,
13459 so set the type's length to zero for now. Otherwise,
13460 we record an expression as the length, and that expression
13461 could lead to a very large value, which could eventually
13462 lead to us trying to allocate that much memory when creating
13463 a value of that type. */
13464 TYPE_LENGTH (type
) = 0;
13469 TYPE_LENGTH (type
) = 0;
13472 if (producer_is_icc (cu
) && (TYPE_LENGTH (type
) == 0))
13474 /* ICC does not output the required DW_AT_declaration
13475 on incomplete types, but gives them a size of zero. */
13476 TYPE_STUB (type
) = 1;
13479 TYPE_STUB_SUPPORTED (type
) = 1;
13481 if (die_is_declaration (die
, cu
))
13482 TYPE_STUB (type
) = 1;
13483 else if (attr
== NULL
&& die
->child
== NULL
13484 && producer_is_realview (cu
->producer
))
13485 /* RealView does not output the required DW_AT_declaration
13486 on incomplete types. */
13487 TYPE_STUB (type
) = 1;
13489 /* We need to add the type field to the die immediately so we don't
13490 infinitely recurse when dealing with pointers to the structure
13491 type within the structure itself. */
13492 set_die_type (die
, type
, cu
);
13494 /* set_die_type should be already done. */
13495 set_descriptive_type (type
, die
, cu
);
13500 /* Finish creating a structure or union type, including filling in
13501 its members and creating a symbol for it. */
13504 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13506 struct objfile
*objfile
= cu
->objfile
;
13507 struct die_info
*child_die
;
13510 type
= get_die_type (die
, cu
);
13512 type
= read_structure_type (die
, cu
);
13514 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
13516 struct field_info fi
;
13517 VEC (symbolp
) *template_args
= NULL
;
13518 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
13520 memset (&fi
, 0, sizeof (struct field_info
));
13522 child_die
= die
->child
;
13524 while (child_die
&& child_die
->tag
)
13526 if (child_die
->tag
== DW_TAG_member
13527 || child_die
->tag
== DW_TAG_variable
)
13529 /* NOTE: carlton/2002-11-05: A C++ static data member
13530 should be a DW_TAG_member that is a declaration, but
13531 all versions of G++ as of this writing (so through at
13532 least 3.2.1) incorrectly generate DW_TAG_variable
13533 tags for them instead. */
13534 dwarf2_add_field (&fi
, child_die
, cu
);
13536 else if (child_die
->tag
== DW_TAG_subprogram
)
13538 /* Rust doesn't have member functions in the C++ sense.
13539 However, it does emit ordinary functions as children
13540 of a struct DIE. */
13541 if (cu
->language
== language_rust
)
13542 read_func_scope (child_die
, cu
);
13545 /* C++ member function. */
13546 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
13549 else if (child_die
->tag
== DW_TAG_inheritance
)
13551 /* C++ base class field. */
13552 dwarf2_add_field (&fi
, child_die
, cu
);
13554 else if (child_die
->tag
== DW_TAG_typedef
)
13555 dwarf2_add_typedef (&fi
, child_die
, cu
);
13556 else if (child_die
->tag
== DW_TAG_template_type_param
13557 || child_die
->tag
== DW_TAG_template_value_param
)
13559 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13562 VEC_safe_push (symbolp
, template_args
, arg
);
13565 child_die
= sibling_die (child_die
);
13568 /* Attach template arguments to type. */
13569 if (! VEC_empty (symbolp
, template_args
))
13571 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13572 TYPE_N_TEMPLATE_ARGUMENTS (type
)
13573 = VEC_length (symbolp
, template_args
);
13574 TYPE_TEMPLATE_ARGUMENTS (type
)
13575 = XOBNEWVEC (&objfile
->objfile_obstack
,
13577 TYPE_N_TEMPLATE_ARGUMENTS (type
));
13578 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
13579 VEC_address (symbolp
, template_args
),
13580 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
13581 * sizeof (struct symbol
*)));
13582 VEC_free (symbolp
, template_args
);
13585 /* Attach fields and member functions to the type. */
13587 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
13590 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
13592 /* Get the type which refers to the base class (possibly this
13593 class itself) which contains the vtable pointer for the current
13594 class from the DW_AT_containing_type attribute. This use of
13595 DW_AT_containing_type is a GNU extension. */
13597 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
13599 struct type
*t
= die_containing_type (die
, cu
);
13601 set_type_vptr_basetype (type
, t
);
13606 /* Our own class provides vtbl ptr. */
13607 for (i
= TYPE_NFIELDS (t
) - 1;
13608 i
>= TYPE_N_BASECLASSES (t
);
13611 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
13613 if (is_vtable_name (fieldname
, cu
))
13615 set_type_vptr_fieldno (type
, i
);
13620 /* Complain if virtual function table field not found. */
13621 if (i
< TYPE_N_BASECLASSES (t
))
13622 complaint (&symfile_complaints
,
13623 _("virtual function table pointer "
13624 "not found when defining class '%s'"),
13625 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
13630 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
13633 else if (cu
->producer
13634 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
13636 /* The IBM XLC compiler does not provide direct indication
13637 of the containing type, but the vtable pointer is
13638 always named __vfp. */
13642 for (i
= TYPE_NFIELDS (type
) - 1;
13643 i
>= TYPE_N_BASECLASSES (type
);
13646 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
13648 set_type_vptr_fieldno (type
, i
);
13649 set_type_vptr_basetype (type
, type
);
13656 /* Copy fi.typedef_field_list linked list elements content into the
13657 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
13658 if (fi
.typedef_field_list
)
13660 int i
= fi
.typedef_field_list_count
;
13662 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13663 TYPE_TYPEDEF_FIELD_ARRAY (type
)
13664 = ((struct typedef_field
*)
13665 TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
));
13666 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
13668 /* Reverse the list order to keep the debug info elements order. */
13671 struct typedef_field
*dest
, *src
;
13673 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
13674 src
= &fi
.typedef_field_list
->field
;
13675 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
13680 do_cleanups (back_to
);
13683 quirk_gcc_member_function_pointer (type
, objfile
);
13685 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
13686 snapshots) has been known to create a die giving a declaration
13687 for a class that has, as a child, a die giving a definition for a
13688 nested class. So we have to process our children even if the
13689 current die is a declaration. Normally, of course, a declaration
13690 won't have any children at all. */
13692 child_die
= die
->child
;
13694 while (child_die
!= NULL
&& child_die
->tag
)
13696 if (child_die
->tag
== DW_TAG_member
13697 || child_die
->tag
== DW_TAG_variable
13698 || child_die
->tag
== DW_TAG_inheritance
13699 || child_die
->tag
== DW_TAG_template_value_param
13700 || child_die
->tag
== DW_TAG_template_type_param
)
13705 process_die (child_die
, cu
);
13707 child_die
= sibling_die (child_die
);
13710 /* Do not consider external references. According to the DWARF standard,
13711 these DIEs are identified by the fact that they have no byte_size
13712 attribute, and a declaration attribute. */
13713 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
13714 || !die_is_declaration (die
, cu
))
13715 new_symbol (die
, type
, cu
);
13718 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
13719 update TYPE using some information only available in DIE's children. */
13722 update_enumeration_type_from_children (struct die_info
*die
,
13724 struct dwarf2_cu
*cu
)
13726 struct obstack obstack
;
13727 struct die_info
*child_die
;
13728 int unsigned_enum
= 1;
13731 struct cleanup
*old_chain
;
13733 obstack_init (&obstack
);
13734 old_chain
= make_cleanup_obstack_free (&obstack
);
13736 for (child_die
= die
->child
;
13737 child_die
!= NULL
&& child_die
->tag
;
13738 child_die
= sibling_die (child_die
))
13740 struct attribute
*attr
;
13742 const gdb_byte
*bytes
;
13743 struct dwarf2_locexpr_baton
*baton
;
13746 if (child_die
->tag
!= DW_TAG_enumerator
)
13749 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
13753 name
= dwarf2_name (child_die
, cu
);
13755 name
= "<anonymous enumerator>";
13757 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
13758 &value
, &bytes
, &baton
);
13764 else if ((mask
& value
) != 0)
13769 /* If we already know that the enum type is neither unsigned, nor
13770 a flag type, no need to look at the rest of the enumerates. */
13771 if (!unsigned_enum
&& !flag_enum
)
13776 TYPE_UNSIGNED (type
) = 1;
13778 TYPE_FLAG_ENUM (type
) = 1;
13780 do_cleanups (old_chain
);
13783 /* Given a DW_AT_enumeration_type die, set its type. We do not
13784 complete the type's fields yet, or create any symbols. */
13786 static struct type
*
13787 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13789 struct objfile
*objfile
= cu
->objfile
;
13791 struct attribute
*attr
;
13794 /* If the definition of this type lives in .debug_types, read that type.
13795 Don't follow DW_AT_specification though, that will take us back up
13796 the chain and we want to go down. */
13797 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
13800 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13802 /* The type's CU may not be the same as CU.
13803 Ensure TYPE is recorded with CU in die_type_hash. */
13804 return set_die_type (die
, type
, cu
);
13807 type
= alloc_type (objfile
);
13809 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
13810 name
= dwarf2_full_name (NULL
, die
, cu
);
13812 TYPE_TAG_NAME (type
) = name
;
13814 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13817 struct type
*underlying_type
= die_type (die
, cu
);
13819 TYPE_TARGET_TYPE (type
) = underlying_type
;
13822 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13825 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13829 TYPE_LENGTH (type
) = 0;
13832 /* The enumeration DIE can be incomplete. In Ada, any type can be
13833 declared as private in the package spec, and then defined only
13834 inside the package body. Such types are known as Taft Amendment
13835 Types. When another package uses such a type, an incomplete DIE
13836 may be generated by the compiler. */
13837 if (die_is_declaration (die
, cu
))
13838 TYPE_STUB (type
) = 1;
13840 /* Finish the creation of this type by using the enum's children.
13841 We must call this even when the underlying type has been provided
13842 so that we can determine if we're looking at a "flag" enum. */
13843 update_enumeration_type_from_children (die
, type
, cu
);
13845 /* If this type has an underlying type that is not a stub, then we
13846 may use its attributes. We always use the "unsigned" attribute
13847 in this situation, because ordinarily we guess whether the type
13848 is unsigned -- but the guess can be wrong and the underlying type
13849 can tell us the reality. However, we defer to a local size
13850 attribute if one exists, because this lets the compiler override
13851 the underlying type if needed. */
13852 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
13854 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
13855 if (TYPE_LENGTH (type
) == 0)
13856 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
13859 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
13861 return set_die_type (die
, type
, cu
);
13864 /* Given a pointer to a die which begins an enumeration, process all
13865 the dies that define the members of the enumeration, and create the
13866 symbol for the enumeration type.
13868 NOTE: We reverse the order of the element list. */
13871 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13873 struct type
*this_type
;
13875 this_type
= get_die_type (die
, cu
);
13876 if (this_type
== NULL
)
13877 this_type
= read_enumeration_type (die
, cu
);
13879 if (die
->child
!= NULL
)
13881 struct die_info
*child_die
;
13882 struct symbol
*sym
;
13883 struct field
*fields
= NULL
;
13884 int num_fields
= 0;
13887 child_die
= die
->child
;
13888 while (child_die
&& child_die
->tag
)
13890 if (child_die
->tag
!= DW_TAG_enumerator
)
13892 process_die (child_die
, cu
);
13896 name
= dwarf2_name (child_die
, cu
);
13899 sym
= new_symbol (child_die
, this_type
, cu
);
13901 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
13903 fields
= (struct field
*)
13905 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
13906 * sizeof (struct field
));
13909 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
13910 FIELD_TYPE (fields
[num_fields
]) = NULL
;
13911 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
13912 FIELD_BITSIZE (fields
[num_fields
]) = 0;
13918 child_die
= sibling_die (child_die
);
13923 TYPE_NFIELDS (this_type
) = num_fields
;
13924 TYPE_FIELDS (this_type
) = (struct field
*)
13925 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
13926 memcpy (TYPE_FIELDS (this_type
), fields
,
13927 sizeof (struct field
) * num_fields
);
13932 /* If we are reading an enum from a .debug_types unit, and the enum
13933 is a declaration, and the enum is not the signatured type in the
13934 unit, then we do not want to add a symbol for it. Adding a
13935 symbol would in some cases obscure the true definition of the
13936 enum, giving users an incomplete type when the definition is
13937 actually available. Note that we do not want to do this for all
13938 enums which are just declarations, because C++0x allows forward
13939 enum declarations. */
13940 if (cu
->per_cu
->is_debug_types
13941 && die_is_declaration (die
, cu
))
13943 struct signatured_type
*sig_type
;
13945 sig_type
= (struct signatured_type
*) cu
->per_cu
;
13946 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
13947 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
13951 new_symbol (die
, this_type
, cu
);
13954 /* Extract all information from a DW_TAG_array_type DIE and put it in
13955 the DIE's type field. For now, this only handles one dimensional
13958 static struct type
*
13959 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13961 struct objfile
*objfile
= cu
->objfile
;
13962 struct die_info
*child_die
;
13964 struct type
*element_type
, *range_type
, *index_type
;
13965 struct type
**range_types
= NULL
;
13966 struct attribute
*attr
;
13968 struct cleanup
*back_to
;
13970 unsigned int bit_stride
= 0;
13972 element_type
= die_type (die
, cu
);
13974 /* The die_type call above may have already set the type for this DIE. */
13975 type
= get_die_type (die
, cu
);
13979 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
13981 bit_stride
= DW_UNSND (attr
) * 8;
13983 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
13985 bit_stride
= DW_UNSND (attr
);
13987 /* Irix 6.2 native cc creates array types without children for
13988 arrays with unspecified length. */
13989 if (die
->child
== NULL
)
13991 index_type
= objfile_type (objfile
)->builtin_int
;
13992 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
13993 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
13995 return set_die_type (die
, type
, cu
);
13998 back_to
= make_cleanup (null_cleanup
, NULL
);
13999 child_die
= die
->child
;
14000 while (child_die
&& child_die
->tag
)
14002 if (child_die
->tag
== DW_TAG_subrange_type
)
14004 struct type
*child_type
= read_type_die (child_die
, cu
);
14006 if (child_type
!= NULL
)
14008 /* The range type was succesfully read. Save it for the
14009 array type creation. */
14010 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
14012 range_types
= (struct type
**)
14013 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
14014 * sizeof (struct type
*));
14016 make_cleanup (free_current_contents
, &range_types
);
14018 range_types
[ndim
++] = child_type
;
14021 child_die
= sibling_die (child_die
);
14024 /* Dwarf2 dimensions are output from left to right, create the
14025 necessary array types in backwards order. */
14027 type
= element_type
;
14029 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
14034 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
14040 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
14044 /* Understand Dwarf2 support for vector types (like they occur on
14045 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
14046 array type. This is not part of the Dwarf2/3 standard yet, but a
14047 custom vendor extension. The main difference between a regular
14048 array and the vector variant is that vectors are passed by value
14050 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
14052 make_vector_type (type
);
14054 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
14055 implementation may choose to implement triple vectors using this
14057 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14060 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
14061 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14063 complaint (&symfile_complaints
,
14064 _("DW_AT_byte_size for array type smaller "
14065 "than the total size of elements"));
14068 name
= dwarf2_name (die
, cu
);
14070 TYPE_NAME (type
) = name
;
14072 /* Install the type in the die. */
14073 set_die_type (die
, type
, cu
);
14075 /* set_die_type should be already done. */
14076 set_descriptive_type (type
, die
, cu
);
14078 do_cleanups (back_to
);
14083 static enum dwarf_array_dim_ordering
14084 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
14086 struct attribute
*attr
;
14088 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
14091 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
14093 /* GNU F77 is a special case, as at 08/2004 array type info is the
14094 opposite order to the dwarf2 specification, but data is still
14095 laid out as per normal fortran.
14097 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
14098 version checking. */
14100 if (cu
->language
== language_fortran
14101 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
14103 return DW_ORD_row_major
;
14106 switch (cu
->language_defn
->la_array_ordering
)
14108 case array_column_major
:
14109 return DW_ORD_col_major
;
14110 case array_row_major
:
14112 return DW_ORD_row_major
;
14116 /* Extract all information from a DW_TAG_set_type DIE and put it in
14117 the DIE's type field. */
14119 static struct type
*
14120 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14122 struct type
*domain_type
, *set_type
;
14123 struct attribute
*attr
;
14125 domain_type
= die_type (die
, cu
);
14127 /* The die_type call above may have already set the type for this DIE. */
14128 set_type
= get_die_type (die
, cu
);
14132 set_type
= create_set_type (NULL
, domain_type
);
14134 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14136 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
14138 return set_die_type (die
, set_type
, cu
);
14141 /* A helper for read_common_block that creates a locexpr baton.
14142 SYM is the symbol which we are marking as computed.
14143 COMMON_DIE is the DIE for the common block.
14144 COMMON_LOC is the location expression attribute for the common
14146 MEMBER_LOC is the location expression attribute for the particular
14147 member of the common block that we are processing.
14148 CU is the CU from which the above come. */
14151 mark_common_block_symbol_computed (struct symbol
*sym
,
14152 struct die_info
*common_die
,
14153 struct attribute
*common_loc
,
14154 struct attribute
*member_loc
,
14155 struct dwarf2_cu
*cu
)
14157 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14158 struct dwarf2_locexpr_baton
*baton
;
14160 unsigned int cu_off
;
14161 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
14162 LONGEST offset
= 0;
14164 gdb_assert (common_loc
&& member_loc
);
14165 gdb_assert (attr_form_is_block (common_loc
));
14166 gdb_assert (attr_form_is_block (member_loc
)
14167 || attr_form_is_constant (member_loc
));
14169 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14170 baton
->per_cu
= cu
->per_cu
;
14171 gdb_assert (baton
->per_cu
);
14173 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
14175 if (attr_form_is_constant (member_loc
))
14177 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
14178 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
14181 baton
->size
+= DW_BLOCK (member_loc
)->size
;
14183 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
14186 *ptr
++ = DW_OP_call4
;
14187 cu_off
= common_die
->offset
.sect_off
- cu
->per_cu
->offset
.sect_off
;
14188 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
14191 if (attr_form_is_constant (member_loc
))
14193 *ptr
++ = DW_OP_addr
;
14194 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
14195 ptr
+= cu
->header
.addr_size
;
14199 /* We have to copy the data here, because DW_OP_call4 will only
14200 use a DW_AT_location attribute. */
14201 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
14202 ptr
+= DW_BLOCK (member_loc
)->size
;
14205 *ptr
++ = DW_OP_plus
;
14206 gdb_assert (ptr
- baton
->data
== baton
->size
);
14208 SYMBOL_LOCATION_BATON (sym
) = baton
;
14209 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
14212 /* Create appropriate locally-scoped variables for all the
14213 DW_TAG_common_block entries. Also create a struct common_block
14214 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
14215 is used to sepate the common blocks name namespace from regular
14219 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
14221 struct attribute
*attr
;
14223 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14226 /* Support the .debug_loc offsets. */
14227 if (attr_form_is_block (attr
))
14231 else if (attr_form_is_section_offset (attr
))
14233 dwarf2_complex_location_expr_complaint ();
14238 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
14239 "common block member");
14244 if (die
->child
!= NULL
)
14246 struct objfile
*objfile
= cu
->objfile
;
14247 struct die_info
*child_die
;
14248 size_t n_entries
= 0, size
;
14249 struct common_block
*common_block
;
14250 struct symbol
*sym
;
14252 for (child_die
= die
->child
;
14253 child_die
&& child_die
->tag
;
14254 child_die
= sibling_die (child_die
))
14257 size
= (sizeof (struct common_block
)
14258 + (n_entries
- 1) * sizeof (struct symbol
*));
14260 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
14262 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
14263 common_block
->n_entries
= 0;
14265 for (child_die
= die
->child
;
14266 child_die
&& child_die
->tag
;
14267 child_die
= sibling_die (child_die
))
14269 /* Create the symbol in the DW_TAG_common_block block in the current
14271 sym
= new_symbol (child_die
, NULL
, cu
);
14274 struct attribute
*member_loc
;
14276 common_block
->contents
[common_block
->n_entries
++] = sym
;
14278 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
14282 /* GDB has handled this for a long time, but it is
14283 not specified by DWARF. It seems to have been
14284 emitted by gfortran at least as recently as:
14285 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
14286 complaint (&symfile_complaints
,
14287 _("Variable in common block has "
14288 "DW_AT_data_member_location "
14289 "- DIE at 0x%x [in module %s]"),
14290 child_die
->offset
.sect_off
,
14291 objfile_name (cu
->objfile
));
14293 if (attr_form_is_section_offset (member_loc
))
14294 dwarf2_complex_location_expr_complaint ();
14295 else if (attr_form_is_constant (member_loc
)
14296 || attr_form_is_block (member_loc
))
14299 mark_common_block_symbol_computed (sym
, die
, attr
,
14303 dwarf2_complex_location_expr_complaint ();
14308 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
14309 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
14313 /* Create a type for a C++ namespace. */
14315 static struct type
*
14316 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14318 struct objfile
*objfile
= cu
->objfile
;
14319 const char *previous_prefix
, *name
;
14323 /* For extensions, reuse the type of the original namespace. */
14324 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
14326 struct die_info
*ext_die
;
14327 struct dwarf2_cu
*ext_cu
= cu
;
14329 ext_die
= dwarf2_extension (die
, &ext_cu
);
14330 type
= read_type_die (ext_die
, ext_cu
);
14332 /* EXT_CU may not be the same as CU.
14333 Ensure TYPE is recorded with CU in die_type_hash. */
14334 return set_die_type (die
, type
, cu
);
14337 name
= namespace_name (die
, &is_anonymous
, cu
);
14339 /* Now build the name of the current namespace. */
14341 previous_prefix
= determine_prefix (die
, cu
);
14342 if (previous_prefix
[0] != '\0')
14343 name
= typename_concat (&objfile
->objfile_obstack
,
14344 previous_prefix
, name
, 0, cu
);
14346 /* Create the type. */
14347 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
14348 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14350 return set_die_type (die
, type
, cu
);
14353 /* Read a namespace scope. */
14356 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
14358 struct objfile
*objfile
= cu
->objfile
;
14361 /* Add a symbol associated to this if we haven't seen the namespace
14362 before. Also, add a using directive if it's an anonymous
14365 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
14369 type
= read_type_die (die
, cu
);
14370 new_symbol (die
, type
, cu
);
14372 namespace_name (die
, &is_anonymous
, cu
);
14375 const char *previous_prefix
= determine_prefix (die
, cu
);
14377 add_using_directive (using_directives (cu
->language
),
14378 previous_prefix
, TYPE_NAME (type
), NULL
,
14379 NULL
, NULL
, 0, &objfile
->objfile_obstack
);
14383 if (die
->child
!= NULL
)
14385 struct die_info
*child_die
= die
->child
;
14387 while (child_die
&& child_die
->tag
)
14389 process_die (child_die
, cu
);
14390 child_die
= sibling_die (child_die
);
14395 /* Read a Fortran module as type. This DIE can be only a declaration used for
14396 imported module. Still we need that type as local Fortran "use ... only"
14397 declaration imports depend on the created type in determine_prefix. */
14399 static struct type
*
14400 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14402 struct objfile
*objfile
= cu
->objfile
;
14403 const char *module_name
;
14406 module_name
= dwarf2_name (die
, cu
);
14408 complaint (&symfile_complaints
,
14409 _("DW_TAG_module has no name, offset 0x%x"),
14410 die
->offset
.sect_off
);
14411 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
14413 /* determine_prefix uses TYPE_TAG_NAME. */
14414 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14416 return set_die_type (die
, type
, cu
);
14419 /* Read a Fortran module. */
14422 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
14424 struct die_info
*child_die
= die
->child
;
14427 type
= read_type_die (die
, cu
);
14428 new_symbol (die
, type
, cu
);
14430 while (child_die
&& child_die
->tag
)
14432 process_die (child_die
, cu
);
14433 child_die
= sibling_die (child_die
);
14437 /* Return the name of the namespace represented by DIE. Set
14438 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
14441 static const char *
14442 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
14444 struct die_info
*current_die
;
14445 const char *name
= NULL
;
14447 /* Loop through the extensions until we find a name. */
14449 for (current_die
= die
;
14450 current_die
!= NULL
;
14451 current_die
= dwarf2_extension (die
, &cu
))
14453 /* We don't use dwarf2_name here so that we can detect the absence
14454 of a name -> anonymous namespace. */
14455 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
14461 /* Is it an anonymous namespace? */
14463 *is_anonymous
= (name
== NULL
);
14465 name
= CP_ANONYMOUS_NAMESPACE_STR
;
14470 /* Extract all information from a DW_TAG_pointer_type DIE and add to
14471 the user defined type vector. */
14473 static struct type
*
14474 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14476 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
14477 struct comp_unit_head
*cu_header
= &cu
->header
;
14479 struct attribute
*attr_byte_size
;
14480 struct attribute
*attr_address_class
;
14481 int byte_size
, addr_class
;
14482 struct type
*target_type
;
14484 target_type
= die_type (die
, cu
);
14486 /* The die_type call above may have already set the type for this DIE. */
14487 type
= get_die_type (die
, cu
);
14491 type
= lookup_pointer_type (target_type
);
14493 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14494 if (attr_byte_size
)
14495 byte_size
= DW_UNSND (attr_byte_size
);
14497 byte_size
= cu_header
->addr_size
;
14499 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
14500 if (attr_address_class
)
14501 addr_class
= DW_UNSND (attr_address_class
);
14503 addr_class
= DW_ADDR_none
;
14505 /* If the pointer size or address class is different than the
14506 default, create a type variant marked as such and set the
14507 length accordingly. */
14508 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
14510 if (gdbarch_address_class_type_flags_p (gdbarch
))
14514 type_flags
= gdbarch_address_class_type_flags
14515 (gdbarch
, byte_size
, addr_class
);
14516 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
14518 type
= make_type_with_address_space (type
, type_flags
);
14520 else if (TYPE_LENGTH (type
) != byte_size
)
14522 complaint (&symfile_complaints
,
14523 _("invalid pointer size %d"), byte_size
);
14527 /* Should we also complain about unhandled address classes? */
14531 TYPE_LENGTH (type
) = byte_size
;
14532 return set_die_type (die
, type
, cu
);
14535 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
14536 the user defined type vector. */
14538 static struct type
*
14539 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14542 struct type
*to_type
;
14543 struct type
*domain
;
14545 to_type
= die_type (die
, cu
);
14546 domain
= die_containing_type (die
, cu
);
14548 /* The calls above may have already set the type for this DIE. */
14549 type
= get_die_type (die
, cu
);
14553 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
14554 type
= lookup_methodptr_type (to_type
);
14555 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
14557 struct type
*new_type
= alloc_type (cu
->objfile
);
14559 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
14560 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
14561 TYPE_VARARGS (to_type
));
14562 type
= lookup_methodptr_type (new_type
);
14565 type
= lookup_memberptr_type (to_type
, domain
);
14567 return set_die_type (die
, type
, cu
);
14570 /* Extract all information from a DW_TAG_reference_type DIE and add to
14571 the user defined type vector. */
14573 static struct type
*
14574 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14576 struct comp_unit_head
*cu_header
= &cu
->header
;
14577 struct type
*type
, *target_type
;
14578 struct attribute
*attr
;
14580 target_type
= die_type (die
, cu
);
14582 /* The die_type call above may have already set the type for this DIE. */
14583 type
= get_die_type (die
, cu
);
14587 type
= lookup_reference_type (target_type
);
14588 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14591 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14595 TYPE_LENGTH (type
) = cu_header
->addr_size
;
14597 return set_die_type (die
, type
, cu
);
14600 /* Add the given cv-qualifiers to the element type of the array. GCC
14601 outputs DWARF type qualifiers that apply to an array, not the
14602 element type. But GDB relies on the array element type to carry
14603 the cv-qualifiers. This mimics section 6.7.3 of the C99
14606 static struct type
*
14607 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
14608 struct type
*base_type
, int cnst
, int voltl
)
14610 struct type
*el_type
, *inner_array
;
14612 base_type
= copy_type (base_type
);
14613 inner_array
= base_type
;
14615 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
14617 TYPE_TARGET_TYPE (inner_array
) =
14618 copy_type (TYPE_TARGET_TYPE (inner_array
));
14619 inner_array
= TYPE_TARGET_TYPE (inner_array
);
14622 el_type
= TYPE_TARGET_TYPE (inner_array
);
14623 cnst
|= TYPE_CONST (el_type
);
14624 voltl
|= TYPE_VOLATILE (el_type
);
14625 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
14627 return set_die_type (die
, base_type
, cu
);
14630 static struct type
*
14631 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14633 struct type
*base_type
, *cv_type
;
14635 base_type
= die_type (die
, cu
);
14637 /* The die_type call above may have already set the type for this DIE. */
14638 cv_type
= get_die_type (die
, cu
);
14642 /* In case the const qualifier is applied to an array type, the element type
14643 is so qualified, not the array type (section 6.7.3 of C99). */
14644 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
14645 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
14647 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
14648 return set_die_type (die
, cv_type
, cu
);
14651 static struct type
*
14652 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14654 struct type
*base_type
, *cv_type
;
14656 base_type
= die_type (die
, cu
);
14658 /* The die_type call above may have already set the type for this DIE. */
14659 cv_type
= get_die_type (die
, cu
);
14663 /* In case the volatile qualifier is applied to an array type, the
14664 element type is so qualified, not the array type (section 6.7.3
14666 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
14667 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
14669 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
14670 return set_die_type (die
, cv_type
, cu
);
14673 /* Handle DW_TAG_restrict_type. */
14675 static struct type
*
14676 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14678 struct type
*base_type
, *cv_type
;
14680 base_type
= die_type (die
, cu
);
14682 /* The die_type call above may have already set the type for this DIE. */
14683 cv_type
= get_die_type (die
, cu
);
14687 cv_type
= make_restrict_type (base_type
);
14688 return set_die_type (die
, cv_type
, cu
);
14691 /* Handle DW_TAG_atomic_type. */
14693 static struct type
*
14694 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14696 struct type
*base_type
, *cv_type
;
14698 base_type
= die_type (die
, cu
);
14700 /* The die_type call above may have already set the type for this DIE. */
14701 cv_type
= get_die_type (die
, cu
);
14705 cv_type
= make_atomic_type (base_type
);
14706 return set_die_type (die
, cv_type
, cu
);
14709 /* Extract all information from a DW_TAG_string_type DIE and add to
14710 the user defined type vector. It isn't really a user defined type,
14711 but it behaves like one, with other DIE's using an AT_user_def_type
14712 attribute to reference it. */
14714 static struct type
*
14715 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14717 struct objfile
*objfile
= cu
->objfile
;
14718 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14719 struct type
*type
, *range_type
, *index_type
, *char_type
;
14720 struct attribute
*attr
;
14721 unsigned int length
;
14723 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
14726 length
= DW_UNSND (attr
);
14730 /* Check for the DW_AT_byte_size attribute. */
14731 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14734 length
= DW_UNSND (attr
);
14742 index_type
= objfile_type (objfile
)->builtin_int
;
14743 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
14744 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
14745 type
= create_string_type (NULL
, char_type
, range_type
);
14747 return set_die_type (die
, type
, cu
);
14750 /* Assuming that DIE corresponds to a function, returns nonzero
14751 if the function is prototyped. */
14754 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
14756 struct attribute
*attr
;
14758 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
14759 if (attr
&& (DW_UNSND (attr
) != 0))
14762 /* The DWARF standard implies that the DW_AT_prototyped attribute
14763 is only meaninful for C, but the concept also extends to other
14764 languages that allow unprototyped functions (Eg: Objective C).
14765 For all other languages, assume that functions are always
14767 if (cu
->language
!= language_c
14768 && cu
->language
!= language_objc
14769 && cu
->language
!= language_opencl
)
14772 /* RealView does not emit DW_AT_prototyped. We can not distinguish
14773 prototyped and unprototyped functions; default to prototyped,
14774 since that is more common in modern code (and RealView warns
14775 about unprototyped functions). */
14776 if (producer_is_realview (cu
->producer
))
14782 /* Handle DIES due to C code like:
14786 int (*funcp)(int a, long l);
14790 ('funcp' generates a DW_TAG_subroutine_type DIE). */
14792 static struct type
*
14793 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14795 struct objfile
*objfile
= cu
->objfile
;
14796 struct type
*type
; /* Type that this function returns. */
14797 struct type
*ftype
; /* Function that returns above type. */
14798 struct attribute
*attr
;
14800 type
= die_type (die
, cu
);
14802 /* The die_type call above may have already set the type for this DIE. */
14803 ftype
= get_die_type (die
, cu
);
14807 ftype
= lookup_function_type (type
);
14809 if (prototyped_function_p (die
, cu
))
14810 TYPE_PROTOTYPED (ftype
) = 1;
14812 /* Store the calling convention in the type if it's available in
14813 the subroutine die. Otherwise set the calling convention to
14814 the default value DW_CC_normal. */
14815 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
14817 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
14818 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
14819 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
14821 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
14823 /* Record whether the function returns normally to its caller or not
14824 if the DWARF producer set that information. */
14825 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
14826 if (attr
&& (DW_UNSND (attr
) != 0))
14827 TYPE_NO_RETURN (ftype
) = 1;
14829 /* We need to add the subroutine type to the die immediately so
14830 we don't infinitely recurse when dealing with parameters
14831 declared as the same subroutine type. */
14832 set_die_type (die
, ftype
, cu
);
14834 if (die
->child
!= NULL
)
14836 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
14837 struct die_info
*child_die
;
14838 int nparams
, iparams
;
14840 /* Count the number of parameters.
14841 FIXME: GDB currently ignores vararg functions, but knows about
14842 vararg member functions. */
14844 child_die
= die
->child
;
14845 while (child_die
&& child_die
->tag
)
14847 if (child_die
->tag
== DW_TAG_formal_parameter
)
14849 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
14850 TYPE_VARARGS (ftype
) = 1;
14851 child_die
= sibling_die (child_die
);
14854 /* Allocate storage for parameters and fill them in. */
14855 TYPE_NFIELDS (ftype
) = nparams
;
14856 TYPE_FIELDS (ftype
) = (struct field
*)
14857 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
14859 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
14860 even if we error out during the parameters reading below. */
14861 for (iparams
= 0; iparams
< nparams
; iparams
++)
14862 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
14865 child_die
= die
->child
;
14866 while (child_die
&& child_die
->tag
)
14868 if (child_die
->tag
== DW_TAG_formal_parameter
)
14870 struct type
*arg_type
;
14872 /* DWARF version 2 has no clean way to discern C++
14873 static and non-static member functions. G++ helps
14874 GDB by marking the first parameter for non-static
14875 member functions (which is the this pointer) as
14876 artificial. We pass this information to
14877 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
14879 DWARF version 3 added DW_AT_object_pointer, which GCC
14880 4.5 does not yet generate. */
14881 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
14883 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
14885 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
14886 arg_type
= die_type (child_die
, cu
);
14888 /* RealView does not mark THIS as const, which the testsuite
14889 expects. GCC marks THIS as const in method definitions,
14890 but not in the class specifications (GCC PR 43053). */
14891 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
14892 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
14895 struct dwarf2_cu
*arg_cu
= cu
;
14896 const char *name
= dwarf2_name (child_die
, cu
);
14898 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
14901 /* If the compiler emits this, use it. */
14902 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
14905 else if (name
&& strcmp (name
, "this") == 0)
14906 /* Function definitions will have the argument names. */
14908 else if (name
== NULL
&& iparams
== 0)
14909 /* Declarations may not have the names, so like
14910 elsewhere in GDB, assume an artificial first
14911 argument is "this". */
14915 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
14919 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
14922 child_die
= sibling_die (child_die
);
14929 static struct type
*
14930 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
14932 struct objfile
*objfile
= cu
->objfile
;
14933 const char *name
= NULL
;
14934 struct type
*this_type
, *target_type
;
14936 name
= dwarf2_full_name (NULL
, die
, cu
);
14937 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
14938 TYPE_TARGET_STUB (this_type
) = 1;
14939 set_die_type (die
, this_type
, cu
);
14940 target_type
= die_type (die
, cu
);
14941 if (target_type
!= this_type
)
14942 TYPE_TARGET_TYPE (this_type
) = target_type
;
14945 /* Self-referential typedefs are, it seems, not allowed by the DWARF
14946 spec and cause infinite loops in GDB. */
14947 complaint (&symfile_complaints
,
14948 _("Self-referential DW_TAG_typedef "
14949 "- DIE at 0x%x [in module %s]"),
14950 die
->offset
.sect_off
, objfile_name (objfile
));
14951 TYPE_TARGET_TYPE (this_type
) = NULL
;
14956 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
14957 (which may be different from NAME) to the architecture back-end to allow
14958 it to guess the correct format if necessary. */
14960 static struct type
*
14961 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
14962 const char *name_hint
)
14964 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14965 const struct floatformat
**format
;
14968 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
14970 type
= init_float_type (objfile
, bits
, name
, format
);
14972 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
/ TARGET_CHAR_BIT
, name
);
14977 /* Find a representation of a given base type and install
14978 it in the TYPE field of the die. */
14980 static struct type
*
14981 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14983 struct objfile
*objfile
= cu
->objfile
;
14985 struct attribute
*attr
;
14986 int encoding
= 0, bits
= 0;
14989 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
14992 encoding
= DW_UNSND (attr
);
14994 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14997 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
14999 name
= dwarf2_name (die
, cu
);
15002 complaint (&symfile_complaints
,
15003 _("DW_AT_name missing from DW_TAG_base_type"));
15008 case DW_ATE_address
:
15009 /* Turn DW_ATE_address into a void * pointer. */
15010 type
= init_type (objfile
, TYPE_CODE_VOID
, 1, NULL
);
15011 type
= init_pointer_type (objfile
, bits
, name
, type
);
15013 case DW_ATE_boolean
:
15014 type
= init_boolean_type (objfile
, bits
, 1, name
);
15016 case DW_ATE_complex_float
:
15017 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
15018 type
= init_complex_type (objfile
, name
, type
);
15020 case DW_ATE_decimal_float
:
15021 type
= init_decfloat_type (objfile
, bits
, name
);
15024 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
15026 case DW_ATE_signed
:
15027 type
= init_integer_type (objfile
, bits
, 0, name
);
15029 case DW_ATE_unsigned
:
15030 if (cu
->language
== language_fortran
15032 && startswith (name
, "character("))
15033 type
= init_character_type (objfile
, bits
, 1, name
);
15035 type
= init_integer_type (objfile
, bits
, 1, name
);
15037 case DW_ATE_signed_char
:
15038 if (cu
->language
== language_ada
|| cu
->language
== language_m2
15039 || cu
->language
== language_pascal
15040 || cu
->language
== language_fortran
)
15041 type
= init_character_type (objfile
, bits
, 0, name
);
15043 type
= init_integer_type (objfile
, bits
, 0, name
);
15045 case DW_ATE_unsigned_char
:
15046 if (cu
->language
== language_ada
|| cu
->language
== language_m2
15047 || cu
->language
== language_pascal
15048 || cu
->language
== language_fortran
15049 || cu
->language
== language_rust
)
15050 type
= init_character_type (objfile
, bits
, 1, name
);
15052 type
= init_integer_type (objfile
, bits
, 1, name
);
15055 /* We just treat this as an integer and then recognize the
15056 type by name elsewhere. */
15057 type
= init_integer_type (objfile
, bits
, 0, name
);
15061 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
15062 dwarf_type_encoding_name (encoding
));
15063 type
= init_type (objfile
, TYPE_CODE_ERROR
,
15064 bits
/ TARGET_CHAR_BIT
, name
);
15068 if (name
&& strcmp (name
, "char") == 0)
15069 TYPE_NOSIGN (type
) = 1;
15071 return set_die_type (die
, type
, cu
);
15074 /* Parse dwarf attribute if it's a block, reference or constant and put the
15075 resulting value of the attribute into struct bound_prop.
15076 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
15079 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
15080 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
15082 struct dwarf2_property_baton
*baton
;
15083 struct obstack
*obstack
= &cu
->objfile
->objfile_obstack
;
15085 if (attr
== NULL
|| prop
== NULL
)
15088 if (attr_form_is_block (attr
))
15090 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15091 baton
->referenced_type
= NULL
;
15092 baton
->locexpr
.per_cu
= cu
->per_cu
;
15093 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
15094 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
15095 prop
->data
.baton
= baton
;
15096 prop
->kind
= PROP_LOCEXPR
;
15097 gdb_assert (prop
->data
.baton
!= NULL
);
15099 else if (attr_form_is_ref (attr
))
15101 struct dwarf2_cu
*target_cu
= cu
;
15102 struct die_info
*target_die
;
15103 struct attribute
*target_attr
;
15105 target_die
= follow_die_ref (die
, attr
, &target_cu
);
15106 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
15107 if (target_attr
== NULL
)
15108 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
15110 if (target_attr
== NULL
)
15113 switch (target_attr
->name
)
15115 case DW_AT_location
:
15116 if (attr_form_is_section_offset (target_attr
))
15118 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15119 baton
->referenced_type
= die_type (target_die
, target_cu
);
15120 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
15121 prop
->data
.baton
= baton
;
15122 prop
->kind
= PROP_LOCLIST
;
15123 gdb_assert (prop
->data
.baton
!= NULL
);
15125 else if (attr_form_is_block (target_attr
))
15127 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15128 baton
->referenced_type
= die_type (target_die
, target_cu
);
15129 baton
->locexpr
.per_cu
= cu
->per_cu
;
15130 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
15131 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
15132 prop
->data
.baton
= baton
;
15133 prop
->kind
= PROP_LOCEXPR
;
15134 gdb_assert (prop
->data
.baton
!= NULL
);
15138 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15139 "dynamic property");
15143 case DW_AT_data_member_location
:
15147 if (!handle_data_member_location (target_die
, target_cu
,
15151 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15152 baton
->referenced_type
= read_type_die (target_die
->parent
,
15154 baton
->offset_info
.offset
= offset
;
15155 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
15156 prop
->data
.baton
= baton
;
15157 prop
->kind
= PROP_ADDR_OFFSET
;
15162 else if (attr_form_is_constant (attr
))
15164 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
15165 prop
->kind
= PROP_CONST
;
15169 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
15170 dwarf2_name (die
, cu
));
15177 /* Read the given DW_AT_subrange DIE. */
15179 static struct type
*
15180 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15182 struct type
*base_type
, *orig_base_type
;
15183 struct type
*range_type
;
15184 struct attribute
*attr
;
15185 struct dynamic_prop low
, high
;
15186 int low_default_is_valid
;
15187 int high_bound_is_count
= 0;
15189 LONGEST negative_mask
;
15191 orig_base_type
= die_type (die
, cu
);
15192 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
15193 whereas the real type might be. So, we use ORIG_BASE_TYPE when
15194 creating the range type, but we use the result of check_typedef
15195 when examining properties of the type. */
15196 base_type
= check_typedef (orig_base_type
);
15198 /* The die_type call above may have already set the type for this DIE. */
15199 range_type
= get_die_type (die
, cu
);
15203 low
.kind
= PROP_CONST
;
15204 high
.kind
= PROP_CONST
;
15205 high
.data
.const_val
= 0;
15207 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
15208 omitting DW_AT_lower_bound. */
15209 switch (cu
->language
)
15212 case language_cplus
:
15213 low
.data
.const_val
= 0;
15214 low_default_is_valid
= 1;
15216 case language_fortran
:
15217 low
.data
.const_val
= 1;
15218 low_default_is_valid
= 1;
15221 case language_objc
:
15222 case language_rust
:
15223 low
.data
.const_val
= 0;
15224 low_default_is_valid
= (cu
->header
.version
>= 4);
15228 case language_pascal
:
15229 low
.data
.const_val
= 1;
15230 low_default_is_valid
= (cu
->header
.version
>= 4);
15233 low
.data
.const_val
= 0;
15234 low_default_is_valid
= 0;
15238 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
15240 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
15241 else if (!low_default_is_valid
)
15242 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
15243 "- DIE at 0x%x [in module %s]"),
15244 die
->offset
.sect_off
, objfile_name (cu
->objfile
));
15246 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
15247 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
15249 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
15250 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
15252 /* If bounds are constant do the final calculation here. */
15253 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
15254 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
15256 high_bound_is_count
= 1;
15260 /* Dwarf-2 specifications explicitly allows to create subrange types
15261 without specifying a base type.
15262 In that case, the base type must be set to the type of
15263 the lower bound, upper bound or count, in that order, if any of these
15264 three attributes references an object that has a type.
15265 If no base type is found, the Dwarf-2 specifications say that
15266 a signed integer type of size equal to the size of an address should
15268 For the following C code: `extern char gdb_int [];'
15269 GCC produces an empty range DIE.
15270 FIXME: muller/2010-05-28: Possible references to object for low bound,
15271 high bound or count are not yet handled by this code. */
15272 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
15274 struct objfile
*objfile
= cu
->objfile
;
15275 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15276 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
15277 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
15279 /* Test "int", "long int", and "long long int" objfile types,
15280 and select the first one having a size above or equal to the
15281 architecture address size. */
15282 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15283 base_type
= int_type
;
15286 int_type
= objfile_type (objfile
)->builtin_long
;
15287 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15288 base_type
= int_type
;
15291 int_type
= objfile_type (objfile
)->builtin_long_long
;
15292 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15293 base_type
= int_type
;
15298 /* Normally, the DWARF producers are expected to use a signed
15299 constant form (Eg. DW_FORM_sdata) to express negative bounds.
15300 But this is unfortunately not always the case, as witnessed
15301 with GCC, for instance, where the ambiguous DW_FORM_dataN form
15302 is used instead. To work around that ambiguity, we treat
15303 the bounds as signed, and thus sign-extend their values, when
15304 the base type is signed. */
15306 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
15307 if (low
.kind
== PROP_CONST
15308 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
15309 low
.data
.const_val
|= negative_mask
;
15310 if (high
.kind
== PROP_CONST
15311 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
15312 high
.data
.const_val
|= negative_mask
;
15314 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
15316 if (high_bound_is_count
)
15317 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
15319 /* Ada expects an empty array on no boundary attributes. */
15320 if (attr
== NULL
&& cu
->language
!= language_ada
)
15321 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
15323 name
= dwarf2_name (die
, cu
);
15325 TYPE_NAME (range_type
) = name
;
15327 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15329 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
15331 set_die_type (die
, range_type
, cu
);
15333 /* set_die_type should be already done. */
15334 set_descriptive_type (range_type
, die
, cu
);
15339 static struct type
*
15340 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15344 /* For now, we only support the C meaning of an unspecified type: void. */
15346 type
= init_type (cu
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
15347 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
15349 return set_die_type (die
, type
, cu
);
15352 /* Read a single die and all its descendents. Set the die's sibling
15353 field to NULL; set other fields in the die correctly, and set all
15354 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
15355 location of the info_ptr after reading all of those dies. PARENT
15356 is the parent of the die in question. */
15358 static struct die_info
*
15359 read_die_and_children (const struct die_reader_specs
*reader
,
15360 const gdb_byte
*info_ptr
,
15361 const gdb_byte
**new_info_ptr
,
15362 struct die_info
*parent
)
15364 struct die_info
*die
;
15365 const gdb_byte
*cur_ptr
;
15368 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
15371 *new_info_ptr
= cur_ptr
;
15374 store_in_ref_table (die
, reader
->cu
);
15377 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
15381 *new_info_ptr
= cur_ptr
;
15384 die
->sibling
= NULL
;
15385 die
->parent
= parent
;
15389 /* Read a die, all of its descendents, and all of its siblings; set
15390 all of the fields of all of the dies correctly. Arguments are as
15391 in read_die_and_children. */
15393 static struct die_info
*
15394 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
15395 const gdb_byte
*info_ptr
,
15396 const gdb_byte
**new_info_ptr
,
15397 struct die_info
*parent
)
15399 struct die_info
*first_die
, *last_sibling
;
15400 const gdb_byte
*cur_ptr
;
15402 cur_ptr
= info_ptr
;
15403 first_die
= last_sibling
= NULL
;
15407 struct die_info
*die
15408 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
15412 *new_info_ptr
= cur_ptr
;
15419 last_sibling
->sibling
= die
;
15421 last_sibling
= die
;
15425 /* Read a die, all of its descendents, and all of its siblings; set
15426 all of the fields of all of the dies correctly. Arguments are as
15427 in read_die_and_children.
15428 This the main entry point for reading a DIE and all its children. */
15430 static struct die_info
*
15431 read_die_and_siblings (const struct die_reader_specs
*reader
,
15432 const gdb_byte
*info_ptr
,
15433 const gdb_byte
**new_info_ptr
,
15434 struct die_info
*parent
)
15436 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
15437 new_info_ptr
, parent
);
15439 if (dwarf_die_debug
)
15441 fprintf_unfiltered (gdb_stdlog
,
15442 "Read die from %s@0x%x of %s:\n",
15443 get_section_name (reader
->die_section
),
15444 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15445 bfd_get_filename (reader
->abfd
));
15446 dump_die (die
, dwarf_die_debug
);
15452 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
15454 The caller is responsible for filling in the extra attributes
15455 and updating (*DIEP)->num_attrs.
15456 Set DIEP to point to a newly allocated die with its information,
15457 except for its child, sibling, and parent fields.
15458 Set HAS_CHILDREN to tell whether the die has children or not. */
15460 static const gdb_byte
*
15461 read_full_die_1 (const struct die_reader_specs
*reader
,
15462 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15463 int *has_children
, int num_extra_attrs
)
15465 unsigned int abbrev_number
, bytes_read
, i
;
15466 sect_offset offset
;
15467 struct abbrev_info
*abbrev
;
15468 struct die_info
*die
;
15469 struct dwarf2_cu
*cu
= reader
->cu
;
15470 bfd
*abfd
= reader
->abfd
;
15472 offset
.sect_off
= info_ptr
- reader
->buffer
;
15473 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15474 info_ptr
+= bytes_read
;
15475 if (!abbrev_number
)
15482 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
15484 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
15486 bfd_get_filename (abfd
));
15488 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
15489 die
->offset
= offset
;
15490 die
->tag
= abbrev
->tag
;
15491 die
->abbrev
= abbrev_number
;
15493 /* Make the result usable.
15494 The caller needs to update num_attrs after adding the extra
15496 die
->num_attrs
= abbrev
->num_attrs
;
15498 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
15499 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
15503 *has_children
= abbrev
->has_children
;
15507 /* Read a die and all its attributes.
15508 Set DIEP to point to a newly allocated die with its information,
15509 except for its child, sibling, and parent fields.
15510 Set HAS_CHILDREN to tell whether the die has children or not. */
15512 static const gdb_byte
*
15513 read_full_die (const struct die_reader_specs
*reader
,
15514 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15517 const gdb_byte
*result
;
15519 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
15521 if (dwarf_die_debug
)
15523 fprintf_unfiltered (gdb_stdlog
,
15524 "Read die from %s@0x%x of %s:\n",
15525 get_section_name (reader
->die_section
),
15526 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15527 bfd_get_filename (reader
->abfd
));
15528 dump_die (*diep
, dwarf_die_debug
);
15534 /* Abbreviation tables.
15536 In DWARF version 2, the description of the debugging information is
15537 stored in a separate .debug_abbrev section. Before we read any
15538 dies from a section we read in all abbreviations and install them
15539 in a hash table. */
15541 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
15543 static struct abbrev_info
*
15544 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
15546 struct abbrev_info
*abbrev
;
15548 abbrev
= XOBNEW (&abbrev_table
->abbrev_obstack
, struct abbrev_info
);
15549 memset (abbrev
, 0, sizeof (struct abbrev_info
));
15554 /* Add an abbreviation to the table. */
15557 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
15558 unsigned int abbrev_number
,
15559 struct abbrev_info
*abbrev
)
15561 unsigned int hash_number
;
15563 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
15564 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
15565 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
15568 /* Look up an abbrev in the table.
15569 Returns NULL if the abbrev is not found. */
15571 static struct abbrev_info
*
15572 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
15573 unsigned int abbrev_number
)
15575 unsigned int hash_number
;
15576 struct abbrev_info
*abbrev
;
15578 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
15579 abbrev
= abbrev_table
->abbrevs
[hash_number
];
15583 if (abbrev
->number
== abbrev_number
)
15585 abbrev
= abbrev
->next
;
15590 /* Read in an abbrev table. */
15592 static struct abbrev_table
*
15593 abbrev_table_read_table (struct dwarf2_section_info
*section
,
15594 sect_offset offset
)
15596 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15597 bfd
*abfd
= get_section_bfd_owner (section
);
15598 struct abbrev_table
*abbrev_table
;
15599 const gdb_byte
*abbrev_ptr
;
15600 struct abbrev_info
*cur_abbrev
;
15601 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
15602 unsigned int abbrev_form
;
15603 struct attr_abbrev
*cur_attrs
;
15604 unsigned int allocated_attrs
;
15606 abbrev_table
= XNEW (struct abbrev_table
);
15607 abbrev_table
->offset
= offset
;
15608 obstack_init (&abbrev_table
->abbrev_obstack
);
15609 abbrev_table
->abbrevs
=
15610 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct abbrev_info
*,
15612 memset (abbrev_table
->abbrevs
, 0,
15613 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
15615 dwarf2_read_section (objfile
, section
);
15616 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
15617 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15618 abbrev_ptr
+= bytes_read
;
15620 allocated_attrs
= ATTR_ALLOC_CHUNK
;
15621 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
15623 /* Loop until we reach an abbrev number of 0. */
15624 while (abbrev_number
)
15626 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
15628 /* read in abbrev header */
15629 cur_abbrev
->number
= abbrev_number
;
15631 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15632 abbrev_ptr
+= bytes_read
;
15633 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
15636 /* now read in declarations */
15639 LONGEST implicit_const
;
15641 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15642 abbrev_ptr
+= bytes_read
;
15643 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15644 abbrev_ptr
+= bytes_read
;
15645 if (abbrev_form
== DW_FORM_implicit_const
)
15647 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
15649 abbrev_ptr
+= bytes_read
;
15653 /* Initialize it due to a false compiler warning. */
15654 implicit_const
= -1;
15657 if (abbrev_name
== 0)
15660 if (cur_abbrev
->num_attrs
== allocated_attrs
)
15662 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
15664 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
15667 cur_attrs
[cur_abbrev
->num_attrs
].name
15668 = (enum dwarf_attribute
) abbrev_name
;
15669 cur_attrs
[cur_abbrev
->num_attrs
].form
15670 = (enum dwarf_form
) abbrev_form
;
15671 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
15672 ++cur_abbrev
->num_attrs
;
15675 cur_abbrev
->attrs
=
15676 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
15677 cur_abbrev
->num_attrs
);
15678 memcpy (cur_abbrev
->attrs
, cur_attrs
,
15679 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
15681 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
15683 /* Get next abbreviation.
15684 Under Irix6 the abbreviations for a compilation unit are not
15685 always properly terminated with an abbrev number of 0.
15686 Exit loop if we encounter an abbreviation which we have
15687 already read (which means we are about to read the abbreviations
15688 for the next compile unit) or if the end of the abbreviation
15689 table is reached. */
15690 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
15692 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15693 abbrev_ptr
+= bytes_read
;
15694 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
15699 return abbrev_table
;
15702 /* Free the resources held by ABBREV_TABLE. */
15705 abbrev_table_free (struct abbrev_table
*abbrev_table
)
15707 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
15708 xfree (abbrev_table
);
15711 /* Same as abbrev_table_free but as a cleanup.
15712 We pass in a pointer to the pointer to the table so that we can
15713 set the pointer to NULL when we're done. It also simplifies
15714 build_type_psymtabs_1. */
15717 abbrev_table_free_cleanup (void *table_ptr
)
15719 struct abbrev_table
**abbrev_table_ptr
= (struct abbrev_table
**) table_ptr
;
15721 if (*abbrev_table_ptr
!= NULL
)
15722 abbrev_table_free (*abbrev_table_ptr
);
15723 *abbrev_table_ptr
= NULL
;
15726 /* Read the abbrev table for CU from ABBREV_SECTION. */
15729 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
15730 struct dwarf2_section_info
*abbrev_section
)
15733 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
15736 /* Release the memory used by the abbrev table for a compilation unit. */
15739 dwarf2_free_abbrev_table (void *ptr_to_cu
)
15741 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr_to_cu
;
15743 if (cu
->abbrev_table
!= NULL
)
15744 abbrev_table_free (cu
->abbrev_table
);
15745 /* Set this to NULL so that we SEGV if we try to read it later,
15746 and also because free_comp_unit verifies this is NULL. */
15747 cu
->abbrev_table
= NULL
;
15750 /* Returns nonzero if TAG represents a type that we might generate a partial
15754 is_type_tag_for_partial (int tag
)
15759 /* Some types that would be reasonable to generate partial symbols for,
15760 that we don't at present. */
15761 case DW_TAG_array_type
:
15762 case DW_TAG_file_type
:
15763 case DW_TAG_ptr_to_member_type
:
15764 case DW_TAG_set_type
:
15765 case DW_TAG_string_type
:
15766 case DW_TAG_subroutine_type
:
15768 case DW_TAG_base_type
:
15769 case DW_TAG_class_type
:
15770 case DW_TAG_interface_type
:
15771 case DW_TAG_enumeration_type
:
15772 case DW_TAG_structure_type
:
15773 case DW_TAG_subrange_type
:
15774 case DW_TAG_typedef
:
15775 case DW_TAG_union_type
:
15782 /* Load all DIEs that are interesting for partial symbols into memory. */
15784 static struct partial_die_info
*
15785 load_partial_dies (const struct die_reader_specs
*reader
,
15786 const gdb_byte
*info_ptr
, int building_psymtab
)
15788 struct dwarf2_cu
*cu
= reader
->cu
;
15789 struct objfile
*objfile
= cu
->objfile
;
15790 struct partial_die_info
*part_die
;
15791 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
15792 struct abbrev_info
*abbrev
;
15793 unsigned int bytes_read
;
15794 unsigned int load_all
= 0;
15795 int nesting_level
= 1;
15800 gdb_assert (cu
->per_cu
!= NULL
);
15801 if (cu
->per_cu
->load_all_dies
)
15805 = htab_create_alloc_ex (cu
->header
.length
/ 12,
15809 &cu
->comp_unit_obstack
,
15810 hashtab_obstack_allocate
,
15811 dummy_obstack_deallocate
);
15813 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
15817 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
15819 /* A NULL abbrev means the end of a series of children. */
15820 if (abbrev
== NULL
)
15822 if (--nesting_level
== 0)
15824 /* PART_DIE was probably the last thing allocated on the
15825 comp_unit_obstack, so we could call obstack_free
15826 here. We don't do that because the waste is small,
15827 and will be cleaned up when we're done with this
15828 compilation unit. This way, we're also more robust
15829 against other users of the comp_unit_obstack. */
15832 info_ptr
+= bytes_read
;
15833 last_die
= parent_die
;
15834 parent_die
= parent_die
->die_parent
;
15838 /* Check for template arguments. We never save these; if
15839 they're seen, we just mark the parent, and go on our way. */
15840 if (parent_die
!= NULL
15841 && cu
->language
== language_cplus
15842 && (abbrev
->tag
== DW_TAG_template_type_param
15843 || abbrev
->tag
== DW_TAG_template_value_param
))
15845 parent_die
->has_template_arguments
= 1;
15849 /* We don't need a partial DIE for the template argument. */
15850 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15855 /* We only recurse into c++ subprograms looking for template arguments.
15856 Skip their other children. */
15858 && cu
->language
== language_cplus
15859 && parent_die
!= NULL
15860 && parent_die
->tag
== DW_TAG_subprogram
)
15862 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15866 /* Check whether this DIE is interesting enough to save. Normally
15867 we would not be interested in members here, but there may be
15868 later variables referencing them via DW_AT_specification (for
15869 static members). */
15871 && !is_type_tag_for_partial (abbrev
->tag
)
15872 && abbrev
->tag
!= DW_TAG_constant
15873 && abbrev
->tag
!= DW_TAG_enumerator
15874 && abbrev
->tag
!= DW_TAG_subprogram
15875 && abbrev
->tag
!= DW_TAG_lexical_block
15876 && abbrev
->tag
!= DW_TAG_variable
15877 && abbrev
->tag
!= DW_TAG_namespace
15878 && abbrev
->tag
!= DW_TAG_module
15879 && abbrev
->tag
!= DW_TAG_member
15880 && abbrev
->tag
!= DW_TAG_imported_unit
15881 && abbrev
->tag
!= DW_TAG_imported_declaration
)
15883 /* Otherwise we skip to the next sibling, if any. */
15884 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15888 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
15891 /* This two-pass algorithm for processing partial symbols has a
15892 high cost in cache pressure. Thus, handle some simple cases
15893 here which cover the majority of C partial symbols. DIEs
15894 which neither have specification tags in them, nor could have
15895 specification tags elsewhere pointing at them, can simply be
15896 processed and discarded.
15898 This segment is also optional; scan_partial_symbols and
15899 add_partial_symbol will handle these DIEs if we chain
15900 them in normally. When compilers which do not emit large
15901 quantities of duplicate debug information are more common,
15902 this code can probably be removed. */
15904 /* Any complete simple types at the top level (pretty much all
15905 of them, for a language without namespaces), can be processed
15907 if (parent_die
== NULL
15908 && part_die
->has_specification
== 0
15909 && part_die
->is_declaration
== 0
15910 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
15911 || part_die
->tag
== DW_TAG_base_type
15912 || part_die
->tag
== DW_TAG_subrange_type
))
15914 if (building_psymtab
&& part_die
->name
!= NULL
)
15915 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
15916 VAR_DOMAIN
, LOC_TYPEDEF
,
15917 &objfile
->static_psymbols
,
15918 0, cu
->language
, objfile
);
15919 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
15923 /* The exception for DW_TAG_typedef with has_children above is
15924 a workaround of GCC PR debug/47510. In the case of this complaint
15925 type_name_no_tag_or_error will error on such types later.
15927 GDB skipped children of DW_TAG_typedef by the shortcut above and then
15928 it could not find the child DIEs referenced later, this is checked
15929 above. In correct DWARF DW_TAG_typedef should have no children. */
15931 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
15932 complaint (&symfile_complaints
,
15933 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
15934 "- DIE at 0x%x [in module %s]"),
15935 part_die
->offset
.sect_off
, objfile_name (objfile
));
15937 /* If we're at the second level, and we're an enumerator, and
15938 our parent has no specification (meaning possibly lives in a
15939 namespace elsewhere), then we can add the partial symbol now
15940 instead of queueing it. */
15941 if (part_die
->tag
== DW_TAG_enumerator
15942 && parent_die
!= NULL
15943 && parent_die
->die_parent
== NULL
15944 && parent_die
->tag
== DW_TAG_enumeration_type
15945 && parent_die
->has_specification
== 0)
15947 if (part_die
->name
== NULL
)
15948 complaint (&symfile_complaints
,
15949 _("malformed enumerator DIE ignored"));
15950 else if (building_psymtab
)
15951 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
15952 VAR_DOMAIN
, LOC_CONST
,
15953 cu
->language
== language_cplus
15954 ? &objfile
->global_psymbols
15955 : &objfile
->static_psymbols
,
15956 0, cu
->language
, objfile
);
15958 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
15962 /* We'll save this DIE so link it in. */
15963 part_die
->die_parent
= parent_die
;
15964 part_die
->die_sibling
= NULL
;
15965 part_die
->die_child
= NULL
;
15967 if (last_die
&& last_die
== parent_die
)
15968 last_die
->die_child
= part_die
;
15970 last_die
->die_sibling
= part_die
;
15972 last_die
= part_die
;
15974 if (first_die
== NULL
)
15975 first_die
= part_die
;
15977 /* Maybe add the DIE to the hash table. Not all DIEs that we
15978 find interesting need to be in the hash table, because we
15979 also have the parent/sibling/child chains; only those that we
15980 might refer to by offset later during partial symbol reading.
15982 For now this means things that might have be the target of a
15983 DW_AT_specification, DW_AT_abstract_origin, or
15984 DW_AT_extension. DW_AT_extension will refer only to
15985 namespaces; DW_AT_abstract_origin refers to functions (and
15986 many things under the function DIE, but we do not recurse
15987 into function DIEs during partial symbol reading) and
15988 possibly variables as well; DW_AT_specification refers to
15989 declarations. Declarations ought to have the DW_AT_declaration
15990 flag. It happens that GCC forgets to put it in sometimes, but
15991 only for functions, not for types.
15993 Adding more things than necessary to the hash table is harmless
15994 except for the performance cost. Adding too few will result in
15995 wasted time in find_partial_die, when we reread the compilation
15996 unit with load_all_dies set. */
15999 || abbrev
->tag
== DW_TAG_constant
16000 || abbrev
->tag
== DW_TAG_subprogram
16001 || abbrev
->tag
== DW_TAG_variable
16002 || abbrev
->tag
== DW_TAG_namespace
16003 || part_die
->is_declaration
)
16007 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
16008 part_die
->offset
.sect_off
, INSERT
);
16012 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
16014 /* For some DIEs we want to follow their children (if any). For C
16015 we have no reason to follow the children of structures; for other
16016 languages we have to, so that we can get at method physnames
16017 to infer fully qualified class names, for DW_AT_specification,
16018 and for C++ template arguments. For C++, we also look one level
16019 inside functions to find template arguments (if the name of the
16020 function does not already contain the template arguments).
16022 For Ada, we need to scan the children of subprograms and lexical
16023 blocks as well because Ada allows the definition of nested
16024 entities that could be interesting for the debugger, such as
16025 nested subprograms for instance. */
16026 if (last_die
->has_children
16028 || last_die
->tag
== DW_TAG_namespace
16029 || last_die
->tag
== DW_TAG_module
16030 || last_die
->tag
== DW_TAG_enumeration_type
16031 || (cu
->language
== language_cplus
16032 && last_die
->tag
== DW_TAG_subprogram
16033 && (last_die
->name
== NULL
16034 || strchr (last_die
->name
, '<') == NULL
))
16035 || (cu
->language
!= language_c
16036 && (last_die
->tag
== DW_TAG_class_type
16037 || last_die
->tag
== DW_TAG_interface_type
16038 || last_die
->tag
== DW_TAG_structure_type
16039 || last_die
->tag
== DW_TAG_union_type
))
16040 || (cu
->language
== language_ada
16041 && (last_die
->tag
== DW_TAG_subprogram
16042 || last_die
->tag
== DW_TAG_lexical_block
))))
16045 parent_die
= last_die
;
16049 /* Otherwise we skip to the next sibling, if any. */
16050 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
16052 /* Back to the top, do it again. */
16056 /* Read a minimal amount of information into the minimal die structure. */
16058 static const gdb_byte
*
16059 read_partial_die (const struct die_reader_specs
*reader
,
16060 struct partial_die_info
*part_die
,
16061 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
16062 const gdb_byte
*info_ptr
)
16064 struct dwarf2_cu
*cu
= reader
->cu
;
16065 struct objfile
*objfile
= cu
->objfile
;
16066 const gdb_byte
*buffer
= reader
->buffer
;
16068 struct attribute attr
;
16069 int has_low_pc_attr
= 0;
16070 int has_high_pc_attr
= 0;
16071 int high_pc_relative
= 0;
16073 memset (part_die
, 0, sizeof (struct partial_die_info
));
16075 part_die
->offset
.sect_off
= info_ptr
- buffer
;
16077 info_ptr
+= abbrev_len
;
16079 if (abbrev
== NULL
)
16082 part_die
->tag
= abbrev
->tag
;
16083 part_die
->has_children
= abbrev
->has_children
;
16085 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
16087 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
16089 /* Store the data if it is of an attribute we want to keep in a
16090 partial symbol table. */
16094 switch (part_die
->tag
)
16096 case DW_TAG_compile_unit
:
16097 case DW_TAG_partial_unit
:
16098 case DW_TAG_type_unit
:
16099 /* Compilation units have a DW_AT_name that is a filename, not
16100 a source language identifier. */
16101 case DW_TAG_enumeration_type
:
16102 case DW_TAG_enumerator
:
16103 /* These tags always have simple identifiers already; no need
16104 to canonicalize them. */
16105 part_die
->name
= DW_STRING (&attr
);
16109 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
16110 &objfile
->per_bfd
->storage_obstack
);
16114 case DW_AT_linkage_name
:
16115 case DW_AT_MIPS_linkage_name
:
16116 /* Note that both forms of linkage name might appear. We
16117 assume they will be the same, and we only store the last
16119 if (cu
->language
== language_ada
)
16120 part_die
->name
= DW_STRING (&attr
);
16121 part_die
->linkage_name
= DW_STRING (&attr
);
16124 has_low_pc_attr
= 1;
16125 part_die
->lowpc
= attr_value_as_address (&attr
);
16127 case DW_AT_high_pc
:
16128 has_high_pc_attr
= 1;
16129 part_die
->highpc
= attr_value_as_address (&attr
);
16130 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
16131 high_pc_relative
= 1;
16133 case DW_AT_location
:
16134 /* Support the .debug_loc offsets. */
16135 if (attr_form_is_block (&attr
))
16137 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
16139 else if (attr_form_is_section_offset (&attr
))
16141 dwarf2_complex_location_expr_complaint ();
16145 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16146 "partial symbol information");
16149 case DW_AT_external
:
16150 part_die
->is_external
= DW_UNSND (&attr
);
16152 case DW_AT_declaration
:
16153 part_die
->is_declaration
= DW_UNSND (&attr
);
16156 part_die
->has_type
= 1;
16158 case DW_AT_abstract_origin
:
16159 case DW_AT_specification
:
16160 case DW_AT_extension
:
16161 part_die
->has_specification
= 1;
16162 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
16163 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
16164 || cu
->per_cu
->is_dwz
);
16166 case DW_AT_sibling
:
16167 /* Ignore absolute siblings, they might point outside of
16168 the current compile unit. */
16169 if (attr
.form
== DW_FORM_ref_addr
)
16170 complaint (&symfile_complaints
,
16171 _("ignoring absolute DW_AT_sibling"));
16174 unsigned int off
= dwarf2_get_ref_die_offset (&attr
).sect_off
;
16175 const gdb_byte
*sibling_ptr
= buffer
+ off
;
16177 if (sibling_ptr
< info_ptr
)
16178 complaint (&symfile_complaints
,
16179 _("DW_AT_sibling points backwards"));
16180 else if (sibling_ptr
> reader
->buffer_end
)
16181 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
16183 part_die
->sibling
= sibling_ptr
;
16186 case DW_AT_byte_size
:
16187 part_die
->has_byte_size
= 1;
16189 case DW_AT_const_value
:
16190 part_die
->has_const_value
= 1;
16192 case DW_AT_calling_convention
:
16193 /* DWARF doesn't provide a way to identify a program's source-level
16194 entry point. DW_AT_calling_convention attributes are only meant
16195 to describe functions' calling conventions.
16197 However, because it's a necessary piece of information in
16198 Fortran, and before DWARF 4 DW_CC_program was the only
16199 piece of debugging information whose definition refers to
16200 a 'main program' at all, several compilers marked Fortran
16201 main programs with DW_CC_program --- even when those
16202 functions use the standard calling conventions.
16204 Although DWARF now specifies a way to provide this
16205 information, we support this practice for backward
16207 if (DW_UNSND (&attr
) == DW_CC_program
16208 && cu
->language
== language_fortran
)
16209 part_die
->main_subprogram
= 1;
16212 if (DW_UNSND (&attr
) == DW_INL_inlined
16213 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
16214 part_die
->may_be_inlined
= 1;
16218 if (part_die
->tag
== DW_TAG_imported_unit
)
16220 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
16221 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
16222 || cu
->per_cu
->is_dwz
);
16226 case DW_AT_main_subprogram
:
16227 part_die
->main_subprogram
= DW_UNSND (&attr
);
16235 if (high_pc_relative
)
16236 part_die
->highpc
+= part_die
->lowpc
;
16238 if (has_low_pc_attr
&& has_high_pc_attr
)
16240 /* When using the GNU linker, .gnu.linkonce. sections are used to
16241 eliminate duplicate copies of functions and vtables and such.
16242 The linker will arbitrarily choose one and discard the others.
16243 The AT_*_pc values for such functions refer to local labels in
16244 these sections. If the section from that file was discarded, the
16245 labels are not in the output, so the relocs get a value of 0.
16246 If this is a discarded function, mark the pc bounds as invalid,
16247 so that GDB will ignore it. */
16248 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
16250 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16252 complaint (&symfile_complaints
,
16253 _("DW_AT_low_pc %s is zero "
16254 "for DIE at 0x%x [in module %s]"),
16255 paddress (gdbarch
, part_die
->lowpc
),
16256 part_die
->offset
.sect_off
, objfile_name (objfile
));
16258 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
16259 else if (part_die
->lowpc
>= part_die
->highpc
)
16261 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16263 complaint (&symfile_complaints
,
16264 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
16265 "for DIE at 0x%x [in module %s]"),
16266 paddress (gdbarch
, part_die
->lowpc
),
16267 paddress (gdbarch
, part_die
->highpc
),
16268 part_die
->offset
.sect_off
, objfile_name (objfile
));
16271 part_die
->has_pc_info
= 1;
16277 /* Find a cached partial DIE at OFFSET in CU. */
16279 static struct partial_die_info
*
16280 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
16282 struct partial_die_info
*lookup_die
= NULL
;
16283 struct partial_die_info part_die
;
16285 part_die
.offset
= offset
;
16286 lookup_die
= ((struct partial_die_info
*)
16287 htab_find_with_hash (cu
->partial_dies
, &part_die
,
16293 /* Find a partial DIE at OFFSET, which may or may not be in CU,
16294 except in the case of .debug_types DIEs which do not reference
16295 outside their CU (they do however referencing other types via
16296 DW_FORM_ref_sig8). */
16298 static struct partial_die_info
*
16299 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
16301 struct objfile
*objfile
= cu
->objfile
;
16302 struct dwarf2_per_cu_data
*per_cu
= NULL
;
16303 struct partial_die_info
*pd
= NULL
;
16305 if (offset_in_dwz
== cu
->per_cu
->is_dwz
16306 && offset_in_cu_p (&cu
->header
, offset
))
16308 pd
= find_partial_die_in_comp_unit (offset
, cu
);
16311 /* We missed recording what we needed.
16312 Load all dies and try again. */
16313 per_cu
= cu
->per_cu
;
16317 /* TUs don't reference other CUs/TUs (except via type signatures). */
16318 if (cu
->per_cu
->is_debug_types
)
16320 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
16321 " external reference to offset 0x%lx [in module %s].\n"),
16322 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
16323 bfd_get_filename (objfile
->obfd
));
16325 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
16328 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
16329 load_partial_comp_unit (per_cu
);
16331 per_cu
->cu
->last_used
= 0;
16332 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
16335 /* If we didn't find it, and not all dies have been loaded,
16336 load them all and try again. */
16338 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
16340 per_cu
->load_all_dies
= 1;
16342 /* This is nasty. When we reread the DIEs, somewhere up the call chain
16343 THIS_CU->cu may already be in use. So we can't just free it and
16344 replace its DIEs with the ones we read in. Instead, we leave those
16345 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
16346 and clobber THIS_CU->cu->partial_dies with the hash table for the new
16348 load_partial_comp_unit (per_cu
);
16350 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
16354 internal_error (__FILE__
, __LINE__
,
16355 _("could not find partial DIE 0x%x "
16356 "in cache [from module %s]\n"),
16357 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16361 /* See if we can figure out if the class lives in a namespace. We do
16362 this by looking for a member function; its demangled name will
16363 contain namespace info, if there is any. */
16366 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
16367 struct dwarf2_cu
*cu
)
16369 /* NOTE: carlton/2003-10-07: Getting the info this way changes
16370 what template types look like, because the demangler
16371 frequently doesn't give the same name as the debug info. We
16372 could fix this by only using the demangled name to get the
16373 prefix (but see comment in read_structure_type). */
16375 struct partial_die_info
*real_pdi
;
16376 struct partial_die_info
*child_pdi
;
16378 /* If this DIE (this DIE's specification, if any) has a parent, then
16379 we should not do this. We'll prepend the parent's fully qualified
16380 name when we create the partial symbol. */
16382 real_pdi
= struct_pdi
;
16383 while (real_pdi
->has_specification
)
16384 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
16385 real_pdi
->spec_is_dwz
, cu
);
16387 if (real_pdi
->die_parent
!= NULL
)
16390 for (child_pdi
= struct_pdi
->die_child
;
16392 child_pdi
= child_pdi
->die_sibling
)
16394 if (child_pdi
->tag
== DW_TAG_subprogram
16395 && child_pdi
->linkage_name
!= NULL
)
16397 char *actual_class_name
16398 = language_class_name_from_physname (cu
->language_defn
,
16399 child_pdi
->linkage_name
);
16400 if (actual_class_name
!= NULL
)
16404 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16406 strlen (actual_class_name
)));
16407 xfree (actual_class_name
);
16414 /* Adjust PART_DIE before generating a symbol for it. This function
16415 may set the is_external flag or change the DIE's name. */
16418 fixup_partial_die (struct partial_die_info
*part_die
,
16419 struct dwarf2_cu
*cu
)
16421 /* Once we've fixed up a die, there's no point in doing so again.
16422 This also avoids a memory leak if we were to call
16423 guess_partial_die_structure_name multiple times. */
16424 if (part_die
->fixup_called
)
16427 /* If we found a reference attribute and the DIE has no name, try
16428 to find a name in the referred to DIE. */
16430 if (part_die
->name
== NULL
&& part_die
->has_specification
)
16432 struct partial_die_info
*spec_die
;
16434 spec_die
= find_partial_die (part_die
->spec_offset
,
16435 part_die
->spec_is_dwz
, cu
);
16437 fixup_partial_die (spec_die
, cu
);
16439 if (spec_die
->name
)
16441 part_die
->name
= spec_die
->name
;
16443 /* Copy DW_AT_external attribute if it is set. */
16444 if (spec_die
->is_external
)
16445 part_die
->is_external
= spec_die
->is_external
;
16449 /* Set default names for some unnamed DIEs. */
16451 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
16452 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
16454 /* If there is no parent die to provide a namespace, and there are
16455 children, see if we can determine the namespace from their linkage
16457 if (cu
->language
== language_cplus
16458 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
16459 && part_die
->die_parent
== NULL
16460 && part_die
->has_children
16461 && (part_die
->tag
== DW_TAG_class_type
16462 || part_die
->tag
== DW_TAG_structure_type
16463 || part_die
->tag
== DW_TAG_union_type
))
16464 guess_partial_die_structure_name (part_die
, cu
);
16466 /* GCC might emit a nameless struct or union that has a linkage
16467 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16468 if (part_die
->name
== NULL
16469 && (part_die
->tag
== DW_TAG_class_type
16470 || part_die
->tag
== DW_TAG_interface_type
16471 || part_die
->tag
== DW_TAG_structure_type
16472 || part_die
->tag
== DW_TAG_union_type
)
16473 && part_die
->linkage_name
!= NULL
)
16477 demangled
= gdb_demangle (part_die
->linkage_name
, DMGL_TYPES
);
16482 /* Strip any leading namespaces/classes, keep only the base name.
16483 DW_AT_name for named DIEs does not contain the prefixes. */
16484 base
= strrchr (demangled
, ':');
16485 if (base
&& base
> demangled
&& base
[-1] == ':')
16492 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16493 base
, strlen (base
)));
16498 part_die
->fixup_called
= 1;
16501 /* Read an attribute value described by an attribute form. */
16503 static const gdb_byte
*
16504 read_attribute_value (const struct die_reader_specs
*reader
,
16505 struct attribute
*attr
, unsigned form
,
16506 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
16508 struct dwarf2_cu
*cu
= reader
->cu
;
16509 struct objfile
*objfile
= cu
->objfile
;
16510 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16511 bfd
*abfd
= reader
->abfd
;
16512 struct comp_unit_head
*cu_header
= &cu
->header
;
16513 unsigned int bytes_read
;
16514 struct dwarf_block
*blk
;
16516 attr
->form
= (enum dwarf_form
) form
;
16519 case DW_FORM_ref_addr
:
16520 if (cu
->header
.version
== 2)
16521 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
16523 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
16524 &cu
->header
, &bytes_read
);
16525 info_ptr
+= bytes_read
;
16527 case DW_FORM_GNU_ref_alt
:
16528 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
16529 info_ptr
+= bytes_read
;
16532 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
16533 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
16534 info_ptr
+= bytes_read
;
16536 case DW_FORM_block2
:
16537 blk
= dwarf_alloc_block (cu
);
16538 blk
->size
= read_2_bytes (abfd
, info_ptr
);
16540 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16541 info_ptr
+= blk
->size
;
16542 DW_BLOCK (attr
) = blk
;
16544 case DW_FORM_block4
:
16545 blk
= dwarf_alloc_block (cu
);
16546 blk
->size
= read_4_bytes (abfd
, info_ptr
);
16548 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16549 info_ptr
+= blk
->size
;
16550 DW_BLOCK (attr
) = blk
;
16552 case DW_FORM_data2
:
16553 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
16556 case DW_FORM_data4
:
16557 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
16560 case DW_FORM_data8
:
16561 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
16564 case DW_FORM_data16
:
16565 blk
= dwarf_alloc_block (cu
);
16567 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
16569 DW_BLOCK (attr
) = blk
;
16571 case DW_FORM_sec_offset
:
16572 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
16573 info_ptr
+= bytes_read
;
16575 case DW_FORM_string
:
16576 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
16577 DW_STRING_IS_CANONICAL (attr
) = 0;
16578 info_ptr
+= bytes_read
;
16581 if (!cu
->per_cu
->is_dwz
)
16583 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
16585 DW_STRING_IS_CANONICAL (attr
) = 0;
16586 info_ptr
+= bytes_read
;
16590 case DW_FORM_line_strp
:
16591 if (!cu
->per_cu
->is_dwz
)
16593 DW_STRING (attr
) = read_indirect_line_string (abfd
, info_ptr
,
16594 cu_header
, &bytes_read
);
16595 DW_STRING_IS_CANONICAL (attr
) = 0;
16596 info_ptr
+= bytes_read
;
16600 case DW_FORM_GNU_strp_alt
:
16602 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
16603 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
16606 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
16607 DW_STRING_IS_CANONICAL (attr
) = 0;
16608 info_ptr
+= bytes_read
;
16611 case DW_FORM_exprloc
:
16612 case DW_FORM_block
:
16613 blk
= dwarf_alloc_block (cu
);
16614 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16615 info_ptr
+= bytes_read
;
16616 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16617 info_ptr
+= blk
->size
;
16618 DW_BLOCK (attr
) = blk
;
16620 case DW_FORM_block1
:
16621 blk
= dwarf_alloc_block (cu
);
16622 blk
->size
= read_1_byte (abfd
, info_ptr
);
16624 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16625 info_ptr
+= blk
->size
;
16626 DW_BLOCK (attr
) = blk
;
16628 case DW_FORM_data1
:
16629 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
16633 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
16636 case DW_FORM_flag_present
:
16637 DW_UNSND (attr
) = 1;
16639 case DW_FORM_sdata
:
16640 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
16641 info_ptr
+= bytes_read
;
16643 case DW_FORM_udata
:
16644 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16645 info_ptr
+= bytes_read
;
16648 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16649 + read_1_byte (abfd
, info_ptr
));
16653 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16654 + read_2_bytes (abfd
, info_ptr
));
16658 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16659 + read_4_bytes (abfd
, info_ptr
));
16663 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16664 + read_8_bytes (abfd
, info_ptr
));
16667 case DW_FORM_ref_sig8
:
16668 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
16671 case DW_FORM_ref_udata
:
16672 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16673 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
16674 info_ptr
+= bytes_read
;
16676 case DW_FORM_indirect
:
16677 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16678 info_ptr
+= bytes_read
;
16679 if (form
== DW_FORM_implicit_const
)
16681 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
16682 info_ptr
+= bytes_read
;
16684 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
16687 case DW_FORM_implicit_const
:
16688 DW_SND (attr
) = implicit_const
;
16690 case DW_FORM_GNU_addr_index
:
16691 if (reader
->dwo_file
== NULL
)
16693 /* For now flag a hard error.
16694 Later we can turn this into a complaint. */
16695 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
16696 dwarf_form_name (form
),
16697 bfd_get_filename (abfd
));
16699 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
16700 info_ptr
+= bytes_read
;
16702 case DW_FORM_GNU_str_index
:
16703 if (reader
->dwo_file
== NULL
)
16705 /* For now flag a hard error.
16706 Later we can turn this into a complaint if warranted. */
16707 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
16708 dwarf_form_name (form
),
16709 bfd_get_filename (abfd
));
16712 ULONGEST str_index
=
16713 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16715 DW_STRING (attr
) = read_str_index (reader
, str_index
);
16716 DW_STRING_IS_CANONICAL (attr
) = 0;
16717 info_ptr
+= bytes_read
;
16721 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
16722 dwarf_form_name (form
),
16723 bfd_get_filename (abfd
));
16727 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
16728 attr
->form
= DW_FORM_GNU_ref_alt
;
16730 /* We have seen instances where the compiler tried to emit a byte
16731 size attribute of -1 which ended up being encoded as an unsigned
16732 0xffffffff. Although 0xffffffff is technically a valid size value,
16733 an object of this size seems pretty unlikely so we can relatively
16734 safely treat these cases as if the size attribute was invalid and
16735 treat them as zero by default. */
16736 if (attr
->name
== DW_AT_byte_size
16737 && form
== DW_FORM_data4
16738 && DW_UNSND (attr
) >= 0xffffffff)
16741 (&symfile_complaints
,
16742 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
16743 hex_string (DW_UNSND (attr
)));
16744 DW_UNSND (attr
) = 0;
16750 /* Read an attribute described by an abbreviated attribute. */
16752 static const gdb_byte
*
16753 read_attribute (const struct die_reader_specs
*reader
,
16754 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
16755 const gdb_byte
*info_ptr
)
16757 attr
->name
= abbrev
->name
;
16758 return read_attribute_value (reader
, attr
, abbrev
->form
,
16759 abbrev
->implicit_const
, info_ptr
);
16762 /* Read dwarf information from a buffer. */
16764 static unsigned int
16765 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
16767 return bfd_get_8 (abfd
, buf
);
16771 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
16773 return bfd_get_signed_8 (abfd
, buf
);
16776 static unsigned int
16777 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16779 return bfd_get_16 (abfd
, buf
);
16783 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16785 return bfd_get_signed_16 (abfd
, buf
);
16788 static unsigned int
16789 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16791 return bfd_get_32 (abfd
, buf
);
16795 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16797 return bfd_get_signed_32 (abfd
, buf
);
16801 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16803 return bfd_get_64 (abfd
, buf
);
16807 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
16808 unsigned int *bytes_read
)
16810 struct comp_unit_head
*cu_header
= &cu
->header
;
16811 CORE_ADDR retval
= 0;
16813 if (cu_header
->signed_addr_p
)
16815 switch (cu_header
->addr_size
)
16818 retval
= bfd_get_signed_16 (abfd
, buf
);
16821 retval
= bfd_get_signed_32 (abfd
, buf
);
16824 retval
= bfd_get_signed_64 (abfd
, buf
);
16827 internal_error (__FILE__
, __LINE__
,
16828 _("read_address: bad switch, signed [in module %s]"),
16829 bfd_get_filename (abfd
));
16834 switch (cu_header
->addr_size
)
16837 retval
= bfd_get_16 (abfd
, buf
);
16840 retval
= bfd_get_32 (abfd
, buf
);
16843 retval
= bfd_get_64 (abfd
, buf
);
16846 internal_error (__FILE__
, __LINE__
,
16847 _("read_address: bad switch, "
16848 "unsigned [in module %s]"),
16849 bfd_get_filename (abfd
));
16853 *bytes_read
= cu_header
->addr_size
;
16857 /* Read the initial length from a section. The (draft) DWARF 3
16858 specification allows the initial length to take up either 4 bytes
16859 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
16860 bytes describe the length and all offsets will be 8 bytes in length
16863 An older, non-standard 64-bit format is also handled by this
16864 function. The older format in question stores the initial length
16865 as an 8-byte quantity without an escape value. Lengths greater
16866 than 2^32 aren't very common which means that the initial 4 bytes
16867 is almost always zero. Since a length value of zero doesn't make
16868 sense for the 32-bit format, this initial zero can be considered to
16869 be an escape value which indicates the presence of the older 64-bit
16870 format. As written, the code can't detect (old format) lengths
16871 greater than 4GB. If it becomes necessary to handle lengths
16872 somewhat larger than 4GB, we could allow other small values (such
16873 as the non-sensical values of 1, 2, and 3) to also be used as
16874 escape values indicating the presence of the old format.
16876 The value returned via bytes_read should be used to increment the
16877 relevant pointer after calling read_initial_length().
16879 [ Note: read_initial_length() and read_offset() are based on the
16880 document entitled "DWARF Debugging Information Format", revision
16881 3, draft 8, dated November 19, 2001. This document was obtained
16884 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
16886 This document is only a draft and is subject to change. (So beware.)
16888 Details regarding the older, non-standard 64-bit format were
16889 determined empirically by examining 64-bit ELF files produced by
16890 the SGI toolchain on an IRIX 6.5 machine.
16892 - Kevin, July 16, 2002
16896 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
16898 LONGEST length
= bfd_get_32 (abfd
, buf
);
16900 if (length
== 0xffffffff)
16902 length
= bfd_get_64 (abfd
, buf
+ 4);
16905 else if (length
== 0)
16907 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
16908 length
= bfd_get_64 (abfd
, buf
);
16919 /* Cover function for read_initial_length.
16920 Returns the length of the object at BUF, and stores the size of the
16921 initial length in *BYTES_READ and stores the size that offsets will be in
16923 If the initial length size is not equivalent to that specified in
16924 CU_HEADER then issue a complaint.
16925 This is useful when reading non-comp-unit headers. */
16928 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
16929 const struct comp_unit_head
*cu_header
,
16930 unsigned int *bytes_read
,
16931 unsigned int *offset_size
)
16933 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
16935 gdb_assert (cu_header
->initial_length_size
== 4
16936 || cu_header
->initial_length_size
== 8
16937 || cu_header
->initial_length_size
== 12);
16939 if (cu_header
->initial_length_size
!= *bytes_read
)
16940 complaint (&symfile_complaints
,
16941 _("intermixed 32-bit and 64-bit DWARF sections"));
16943 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
16947 /* Read an offset from the data stream. The size of the offset is
16948 given by cu_header->offset_size. */
16951 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
16952 const struct comp_unit_head
*cu_header
,
16953 unsigned int *bytes_read
)
16955 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
16957 *bytes_read
= cu_header
->offset_size
;
16961 /* Read an offset from the data stream. */
16964 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
16966 LONGEST retval
= 0;
16968 switch (offset_size
)
16971 retval
= bfd_get_32 (abfd
, buf
);
16974 retval
= bfd_get_64 (abfd
, buf
);
16977 internal_error (__FILE__
, __LINE__
,
16978 _("read_offset_1: bad switch [in module %s]"),
16979 bfd_get_filename (abfd
));
16985 static const gdb_byte
*
16986 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
16988 /* If the size of a host char is 8 bits, we can return a pointer
16989 to the buffer, otherwise we have to copy the data to a buffer
16990 allocated on the temporary obstack. */
16991 gdb_assert (HOST_CHAR_BIT
== 8);
16995 static const char *
16996 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
16997 unsigned int *bytes_read_ptr
)
16999 /* If the size of a host char is 8 bits, we can return a pointer
17000 to the string, otherwise we have to copy the string to a buffer
17001 allocated on the temporary obstack. */
17002 gdb_assert (HOST_CHAR_BIT
== 8);
17005 *bytes_read_ptr
= 1;
17008 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
17009 return (const char *) buf
;
17012 /* Return pointer to string at section SECT offset STR_OFFSET with error
17013 reporting strings FORM_NAME and SECT_NAME. */
17015 static const char *
17016 read_indirect_string_at_offset_from (bfd
*abfd
, LONGEST str_offset
,
17017 struct dwarf2_section_info
*sect
,
17018 const char *form_name
,
17019 const char *sect_name
)
17021 dwarf2_read_section (dwarf2_per_objfile
->objfile
, sect
);
17022 if (sect
->buffer
== NULL
)
17023 error (_("%s used without %s section [in module %s]"),
17024 form_name
, sect_name
, bfd_get_filename (abfd
));
17025 if (str_offset
>= sect
->size
)
17026 error (_("%s pointing outside of %s section [in module %s]"),
17027 form_name
, sect_name
, bfd_get_filename (abfd
));
17028 gdb_assert (HOST_CHAR_BIT
== 8);
17029 if (sect
->buffer
[str_offset
] == '\0')
17031 return (const char *) (sect
->buffer
+ str_offset
);
17034 /* Return pointer to string at .debug_str offset STR_OFFSET. */
17036 static const char *
17037 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
17039 return read_indirect_string_at_offset_from (abfd
, str_offset
,
17040 &dwarf2_per_objfile
->str
,
17041 "DW_FORM_strp", ".debug_str");
17044 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
17046 static const char *
17047 read_indirect_line_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
17049 return read_indirect_string_at_offset_from (abfd
, str_offset
,
17050 &dwarf2_per_objfile
->line_str
,
17051 "DW_FORM_line_strp",
17052 ".debug_line_str");
17055 /* Read a string at offset STR_OFFSET in the .debug_str section from
17056 the .dwz file DWZ. Throw an error if the offset is too large. If
17057 the string consists of a single NUL byte, return NULL; otherwise
17058 return a pointer to the string. */
17060 static const char *
17061 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
17063 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
17065 if (dwz
->str
.buffer
== NULL
)
17066 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
17067 "section [in module %s]"),
17068 bfd_get_filename (dwz
->dwz_bfd
));
17069 if (str_offset
>= dwz
->str
.size
)
17070 error (_("DW_FORM_GNU_strp_alt pointing outside of "
17071 ".debug_str section [in module %s]"),
17072 bfd_get_filename (dwz
->dwz_bfd
));
17073 gdb_assert (HOST_CHAR_BIT
== 8);
17074 if (dwz
->str
.buffer
[str_offset
] == '\0')
17076 return (const char *) (dwz
->str
.buffer
+ str_offset
);
17079 /* Return pointer to string at .debug_str offset as read from BUF.
17080 BUF is assumed to be in a compilation unit described by CU_HEADER.
17081 Return *BYTES_READ_PTR count of bytes read from BUF. */
17083 static const char *
17084 read_indirect_string (bfd
*abfd
, const gdb_byte
*buf
,
17085 const struct comp_unit_head
*cu_header
,
17086 unsigned int *bytes_read_ptr
)
17088 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
17090 return read_indirect_string_at_offset (abfd
, str_offset
);
17093 /* Return pointer to string at .debug_line_str offset as read from BUF.
17094 BUF is assumed to be in a compilation unit described by CU_HEADER.
17095 Return *BYTES_READ_PTR count of bytes read from BUF. */
17097 static const char *
17098 read_indirect_line_string (bfd
*abfd
, const gdb_byte
*buf
,
17099 const struct comp_unit_head
*cu_header
,
17100 unsigned int *bytes_read_ptr
)
17102 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
17104 return read_indirect_line_string_at_offset (abfd
, str_offset
);
17108 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
17109 unsigned int *bytes_read_ptr
)
17112 unsigned int num_read
;
17114 unsigned char byte
;
17121 byte
= bfd_get_8 (abfd
, buf
);
17124 result
|= ((ULONGEST
) (byte
& 127) << shift
);
17125 if ((byte
& 128) == 0)
17131 *bytes_read_ptr
= num_read
;
17136 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
17137 unsigned int *bytes_read_ptr
)
17140 int shift
, num_read
;
17141 unsigned char byte
;
17148 byte
= bfd_get_8 (abfd
, buf
);
17151 result
|= ((LONGEST
) (byte
& 127) << shift
);
17153 if ((byte
& 128) == 0)
17158 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
17159 result
|= -(((LONGEST
) 1) << shift
);
17160 *bytes_read_ptr
= num_read
;
17164 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
17165 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
17166 ADDR_SIZE is the size of addresses from the CU header. */
17169 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
17171 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17172 bfd
*abfd
= objfile
->obfd
;
17173 const gdb_byte
*info_ptr
;
17175 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
17176 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
17177 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
17178 objfile_name (objfile
));
17179 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
17180 error (_("DW_FORM_addr_index pointing outside of "
17181 ".debug_addr section [in module %s]"),
17182 objfile_name (objfile
));
17183 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
17184 + addr_base
+ addr_index
* addr_size
);
17185 if (addr_size
== 4)
17186 return bfd_get_32 (abfd
, info_ptr
);
17188 return bfd_get_64 (abfd
, info_ptr
);
17191 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
17194 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
17196 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
17199 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
17202 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
17203 unsigned int *bytes_read
)
17205 bfd
*abfd
= cu
->objfile
->obfd
;
17206 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
17208 return read_addr_index (cu
, addr_index
);
17211 /* Data structure to pass results from dwarf2_read_addr_index_reader
17212 back to dwarf2_read_addr_index. */
17214 struct dwarf2_read_addr_index_data
17216 ULONGEST addr_base
;
17220 /* die_reader_func for dwarf2_read_addr_index. */
17223 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
17224 const gdb_byte
*info_ptr
,
17225 struct die_info
*comp_unit_die
,
17229 struct dwarf2_cu
*cu
= reader
->cu
;
17230 struct dwarf2_read_addr_index_data
*aidata
=
17231 (struct dwarf2_read_addr_index_data
*) data
;
17233 aidata
->addr_base
= cu
->addr_base
;
17234 aidata
->addr_size
= cu
->header
.addr_size
;
17237 /* Given an index in .debug_addr, fetch the value.
17238 NOTE: This can be called during dwarf expression evaluation,
17239 long after the debug information has been read, and thus per_cu->cu
17240 may no longer exist. */
17243 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
17244 unsigned int addr_index
)
17246 struct objfile
*objfile
= per_cu
->objfile
;
17247 struct dwarf2_cu
*cu
= per_cu
->cu
;
17248 ULONGEST addr_base
;
17251 /* This is intended to be called from outside this file. */
17252 dw2_setup (objfile
);
17254 /* We need addr_base and addr_size.
17255 If we don't have PER_CU->cu, we have to get it.
17256 Nasty, but the alternative is storing the needed info in PER_CU,
17257 which at this point doesn't seem justified: it's not clear how frequently
17258 it would get used and it would increase the size of every PER_CU.
17259 Entry points like dwarf2_per_cu_addr_size do a similar thing
17260 so we're not in uncharted territory here.
17261 Alas we need to be a bit more complicated as addr_base is contained
17264 We don't need to read the entire CU(/TU).
17265 We just need the header and top level die.
17267 IWBN to use the aging mechanism to let us lazily later discard the CU.
17268 For now we skip this optimization. */
17272 addr_base
= cu
->addr_base
;
17273 addr_size
= cu
->header
.addr_size
;
17277 struct dwarf2_read_addr_index_data aidata
;
17279 /* Note: We can't use init_cutu_and_read_dies_simple here,
17280 we need addr_base. */
17281 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
17282 dwarf2_read_addr_index_reader
, &aidata
);
17283 addr_base
= aidata
.addr_base
;
17284 addr_size
= aidata
.addr_size
;
17287 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
17290 /* Given a DW_FORM_GNU_str_index, fetch the string.
17291 This is only used by the Fission support. */
17293 static const char *
17294 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
17296 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17297 const char *objf_name
= objfile_name (objfile
);
17298 bfd
*abfd
= objfile
->obfd
;
17299 struct dwarf2_cu
*cu
= reader
->cu
;
17300 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
17301 struct dwarf2_section_info
*str_offsets_section
=
17302 &reader
->dwo_file
->sections
.str_offsets
;
17303 const gdb_byte
*info_ptr
;
17304 ULONGEST str_offset
;
17305 static const char form_name
[] = "DW_FORM_GNU_str_index";
17307 dwarf2_read_section (objfile
, str_section
);
17308 dwarf2_read_section (objfile
, str_offsets_section
);
17309 if (str_section
->buffer
== NULL
)
17310 error (_("%s used without .debug_str.dwo section"
17311 " in CU at offset 0x%lx [in module %s]"),
17312 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
17313 if (str_offsets_section
->buffer
== NULL
)
17314 error (_("%s used without .debug_str_offsets.dwo section"
17315 " in CU at offset 0x%lx [in module %s]"),
17316 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
17317 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
17318 error (_("%s pointing outside of .debug_str_offsets.dwo"
17319 " section in CU at offset 0x%lx [in module %s]"),
17320 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
17321 info_ptr
= (str_offsets_section
->buffer
17322 + str_index
* cu
->header
.offset_size
);
17323 if (cu
->header
.offset_size
== 4)
17324 str_offset
= bfd_get_32 (abfd
, info_ptr
);
17326 str_offset
= bfd_get_64 (abfd
, info_ptr
);
17327 if (str_offset
>= str_section
->size
)
17328 error (_("Offset from %s pointing outside of"
17329 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
17330 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
17331 return (const char *) (str_section
->buffer
+ str_offset
);
17334 /* Return the length of an LEB128 number in BUF. */
17337 leb128_size (const gdb_byte
*buf
)
17339 const gdb_byte
*begin
= buf
;
17345 if ((byte
& 128) == 0)
17346 return buf
- begin
;
17351 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
17360 cu
->language
= language_c
;
17363 case DW_LANG_C_plus_plus
:
17364 case DW_LANG_C_plus_plus_11
:
17365 case DW_LANG_C_plus_plus_14
:
17366 cu
->language
= language_cplus
;
17369 cu
->language
= language_d
;
17371 case DW_LANG_Fortran77
:
17372 case DW_LANG_Fortran90
:
17373 case DW_LANG_Fortran95
:
17374 case DW_LANG_Fortran03
:
17375 case DW_LANG_Fortran08
:
17376 cu
->language
= language_fortran
;
17379 cu
->language
= language_go
;
17381 case DW_LANG_Mips_Assembler
:
17382 cu
->language
= language_asm
;
17384 case DW_LANG_Ada83
:
17385 case DW_LANG_Ada95
:
17386 cu
->language
= language_ada
;
17388 case DW_LANG_Modula2
:
17389 cu
->language
= language_m2
;
17391 case DW_LANG_Pascal83
:
17392 cu
->language
= language_pascal
;
17395 cu
->language
= language_objc
;
17398 case DW_LANG_Rust_old
:
17399 cu
->language
= language_rust
;
17401 case DW_LANG_Cobol74
:
17402 case DW_LANG_Cobol85
:
17404 cu
->language
= language_minimal
;
17407 cu
->language_defn
= language_def (cu
->language
);
17410 /* Return the named attribute or NULL if not there. */
17412 static struct attribute
*
17413 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17418 struct attribute
*spec
= NULL
;
17420 for (i
= 0; i
< die
->num_attrs
; ++i
)
17422 if (die
->attrs
[i
].name
== name
)
17423 return &die
->attrs
[i
];
17424 if (die
->attrs
[i
].name
== DW_AT_specification
17425 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
17426 spec
= &die
->attrs
[i
];
17432 die
= follow_die_ref (die
, spec
, &cu
);
17438 /* Return the named attribute or NULL if not there,
17439 but do not follow DW_AT_specification, etc.
17440 This is for use in contexts where we're reading .debug_types dies.
17441 Following DW_AT_specification, DW_AT_abstract_origin will take us
17442 back up the chain, and we want to go down. */
17444 static struct attribute
*
17445 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
17449 for (i
= 0; i
< die
->num_attrs
; ++i
)
17450 if (die
->attrs
[i
].name
== name
)
17451 return &die
->attrs
[i
];
17456 /* Return the string associated with a string-typed attribute, or NULL if it
17457 is either not found or is of an incorrect type. */
17459 static const char *
17460 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17462 struct attribute
*attr
;
17463 const char *str
= NULL
;
17465 attr
= dwarf2_attr (die
, name
, cu
);
17469 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
17470 || attr
->form
== DW_FORM_string
|| attr
->form
== DW_FORM_GNU_strp_alt
)
17471 str
= DW_STRING (attr
);
17473 complaint (&symfile_complaints
,
17474 _("string type expected for attribute %s for "
17475 "DIE at 0x%x in module %s"),
17476 dwarf_attr_name (name
), die
->offset
.sect_off
,
17477 objfile_name (cu
->objfile
));
17483 /* Return non-zero iff the attribute NAME is defined for the given DIE,
17484 and holds a non-zero value. This function should only be used for
17485 DW_FORM_flag or DW_FORM_flag_present attributes. */
17488 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
17490 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
17492 return (attr
&& DW_UNSND (attr
));
17496 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
17498 /* A DIE is a declaration if it has a DW_AT_declaration attribute
17499 which value is non-zero. However, we have to be careful with
17500 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
17501 (via dwarf2_flag_true_p) follows this attribute. So we may
17502 end up accidently finding a declaration attribute that belongs
17503 to a different DIE referenced by the specification attribute,
17504 even though the given DIE does not have a declaration attribute. */
17505 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
17506 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
17509 /* Return the die giving the specification for DIE, if there is
17510 one. *SPEC_CU is the CU containing DIE on input, and the CU
17511 containing the return value on output. If there is no
17512 specification, but there is an abstract origin, that is
17515 static struct die_info
*
17516 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
17518 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
17521 if (spec_attr
== NULL
)
17522 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
17524 if (spec_attr
== NULL
)
17527 return follow_die_ref (die
, spec_attr
, spec_cu
);
17530 /* Free the line_header structure *LH, and any arrays and strings it
17532 NOTE: This is also used as a "cleanup" function. */
17535 free_line_header (struct line_header
*lh
)
17537 if (lh
->standard_opcode_lengths
)
17538 xfree (lh
->standard_opcode_lengths
);
17540 /* Remember that all the lh->file_names[i].name pointers are
17541 pointers into debug_line_buffer, and don't need to be freed. */
17542 if (lh
->file_names
)
17543 xfree (lh
->file_names
);
17545 /* Similarly for the include directory names. */
17546 if (lh
->include_dirs
)
17547 xfree (lh
->include_dirs
);
17552 /* Stub for free_line_header to match void * callback types. */
17555 free_line_header_voidp (void *arg
)
17557 struct line_header
*lh
= (struct line_header
*) arg
;
17559 free_line_header (lh
);
17562 /* Add an entry to LH's include directory table. */
17565 add_include_dir (struct line_header
*lh
, const char *include_dir
)
17567 if (dwarf_line_debug
>= 2)
17568 fprintf_unfiltered (gdb_stdlog
, "Adding dir %u: %s\n",
17569 lh
->num_include_dirs
+ 1, include_dir
);
17571 /* Grow the array if necessary. */
17572 if (lh
->include_dirs_size
== 0)
17574 lh
->include_dirs_size
= 1; /* for testing */
17575 lh
->include_dirs
= XNEWVEC (const char *, lh
->include_dirs_size
);
17577 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
17579 lh
->include_dirs_size
*= 2;
17580 lh
->include_dirs
= XRESIZEVEC (const char *, lh
->include_dirs
,
17581 lh
->include_dirs_size
);
17584 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
17587 /* Add an entry to LH's file name table. */
17590 add_file_name (struct line_header
*lh
,
17592 unsigned int dir_index
,
17593 unsigned int mod_time
,
17594 unsigned int length
)
17596 struct file_entry
*fe
;
17598 if (dwarf_line_debug
>= 2)
17599 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
17600 lh
->num_file_names
+ 1, name
);
17602 /* Grow the array if necessary. */
17603 if (lh
->file_names_size
== 0)
17605 lh
->file_names_size
= 1; /* for testing */
17606 lh
->file_names
= XNEWVEC (struct file_entry
, lh
->file_names_size
);
17608 else if (lh
->num_file_names
>= lh
->file_names_size
)
17610 lh
->file_names_size
*= 2;
17612 = XRESIZEVEC (struct file_entry
, lh
->file_names
, lh
->file_names_size
);
17615 fe
= &lh
->file_names
[lh
->num_file_names
++];
17617 fe
->dir_index
= dir_index
;
17618 fe
->mod_time
= mod_time
;
17619 fe
->length
= length
;
17620 fe
->included_p
= 0;
17624 /* A convenience function to find the proper .debug_line section for a CU. */
17626 static struct dwarf2_section_info
*
17627 get_debug_line_section (struct dwarf2_cu
*cu
)
17629 struct dwarf2_section_info
*section
;
17631 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
17633 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17634 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
17635 else if (cu
->per_cu
->is_dwz
)
17637 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
17639 section
= &dwz
->line
;
17642 section
= &dwarf2_per_objfile
->line
;
17647 /* Forwarding function for read_formatted_entries. */
17650 add_include_dir_stub (struct line_header
*lh
, const char *name
,
17651 unsigned int dir_index
, unsigned int mod_time
,
17652 unsigned int length
)
17654 add_include_dir (lh
, name
);
17657 /* Read directory or file name entry format, starting with byte of
17658 format count entries, ULEB128 pairs of entry formats, ULEB128 of
17659 entries count and the entries themselves in the described entry
17663 read_formatted_entries (bfd
*abfd
, const gdb_byte
**bufp
,
17664 struct line_header
*lh
,
17665 const struct comp_unit_head
*cu_header
,
17666 void (*callback
) (struct line_header
*lh
,
17668 unsigned int dir_index
,
17669 unsigned int mod_time
,
17670 unsigned int length
))
17672 gdb_byte format_count
, formati
;
17673 ULONGEST data_count
, datai
;
17674 const gdb_byte
*buf
= *bufp
;
17675 const gdb_byte
*format_header_data
;
17677 unsigned int bytes_read
;
17679 format_count
= read_1_byte (abfd
, buf
);
17681 format_header_data
= buf
;
17682 for (formati
= 0; formati
< format_count
; formati
++)
17684 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17686 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17690 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17692 for (datai
= 0; datai
< data_count
; datai
++)
17694 const gdb_byte
*format
= format_header_data
;
17695 struct file_entry fe
;
17697 memset (&fe
, 0, sizeof (fe
));
17699 for (formati
= 0; formati
< format_count
; formati
++)
17701 ULONGEST content_type
, form
;
17702 const char *string_trash
;
17703 const char **stringp
= &string_trash
;
17704 unsigned int uint_trash
, *uintp
= &uint_trash
;
17706 content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
17707 format
+= bytes_read
;
17708 switch (content_type
)
17711 stringp
= &fe
.name
;
17713 case DW_LNCT_directory_index
:
17714 uintp
= &fe
.dir_index
;
17716 case DW_LNCT_timestamp
:
17717 uintp
= &fe
.mod_time
;
17720 uintp
= &fe
.length
;
17725 complaint (&symfile_complaints
,
17726 _("Unknown format content type %s"),
17727 pulongest (content_type
));
17730 form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
17731 format
+= bytes_read
;
17734 case DW_FORM_string
:
17735 *stringp
= read_direct_string (abfd
, buf
, &bytes_read
);
17739 case DW_FORM_line_strp
:
17740 *stringp
= read_indirect_line_string (abfd
, buf
, cu_header
, &bytes_read
);
17744 case DW_FORM_data1
:
17745 *uintp
= read_1_byte (abfd
, buf
);
17749 case DW_FORM_data2
:
17750 *uintp
= read_2_bytes (abfd
, buf
);
17754 case DW_FORM_data4
:
17755 *uintp
= read_4_bytes (abfd
, buf
);
17759 case DW_FORM_data8
:
17760 *uintp
= read_8_bytes (abfd
, buf
);
17764 case DW_FORM_udata
:
17765 *uintp
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17769 case DW_FORM_block
:
17770 /* It is valid only for DW_LNCT_timestamp which is ignored by
17776 callback (lh
, fe
.name
, fe
.dir_index
, fe
.mod_time
, fe
.length
);
17782 /* Read the statement program header starting at OFFSET in
17783 .debug_line, or .debug_line.dwo. Return a pointer
17784 to a struct line_header, allocated using xmalloc.
17785 Returns NULL if there is a problem reading the header, e.g., if it
17786 has a version we don't understand.
17788 NOTE: the strings in the include directory and file name tables of
17789 the returned object point into the dwarf line section buffer,
17790 and must not be freed. */
17792 static struct line_header
*
17793 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
17795 struct cleanup
*back_to
;
17796 struct line_header
*lh
;
17797 const gdb_byte
*line_ptr
;
17798 unsigned int bytes_read
, offset_size
;
17800 const char *cur_dir
, *cur_file
;
17801 struct dwarf2_section_info
*section
;
17804 section
= get_debug_line_section (cu
);
17805 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
17806 if (section
->buffer
== NULL
)
17808 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17809 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
17811 complaint (&symfile_complaints
, _("missing .debug_line section"));
17815 /* We can't do this until we know the section is non-empty.
17816 Only then do we know we have such a section. */
17817 abfd
= get_section_bfd_owner (section
);
17819 /* Make sure that at least there's room for the total_length field.
17820 That could be 12 bytes long, but we're just going to fudge that. */
17821 if (offset
+ 4 >= section
->size
)
17823 dwarf2_statement_list_fits_in_line_number_section_complaint ();
17827 lh
= XNEW (struct line_header
);
17828 memset (lh
, 0, sizeof (*lh
));
17829 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
17832 lh
->offset
.sect_off
= offset
;
17833 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
17835 line_ptr
= section
->buffer
+ offset
;
17837 /* Read in the header. */
17839 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
17840 &bytes_read
, &offset_size
);
17841 line_ptr
+= bytes_read
;
17842 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
17844 dwarf2_statement_list_fits_in_line_number_section_complaint ();
17845 do_cleanups (back_to
);
17848 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
17849 lh
->version
= read_2_bytes (abfd
, line_ptr
);
17851 if (lh
->version
> 5)
17853 /* This is a version we don't understand. The format could have
17854 changed in ways we don't handle properly so just punt. */
17855 complaint (&symfile_complaints
,
17856 _("unsupported version in .debug_line section"));
17859 if (lh
->version
>= 5)
17861 gdb_byte segment_selector_size
;
17863 /* Skip address size. */
17864 read_1_byte (abfd
, line_ptr
);
17867 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
17869 if (segment_selector_size
!= 0)
17871 complaint (&symfile_complaints
,
17872 _("unsupported segment selector size %u "
17873 "in .debug_line section"),
17874 segment_selector_size
);
17878 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
17879 line_ptr
+= offset_size
;
17880 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
17882 if (lh
->version
>= 4)
17884 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
17888 lh
->maximum_ops_per_instruction
= 1;
17890 if (lh
->maximum_ops_per_instruction
== 0)
17892 lh
->maximum_ops_per_instruction
= 1;
17893 complaint (&symfile_complaints
,
17894 _("invalid maximum_ops_per_instruction "
17895 "in `.debug_line' section"));
17898 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
17900 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
17902 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
17904 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
17906 lh
->standard_opcode_lengths
= XNEWVEC (unsigned char, lh
->opcode_base
);
17908 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
17909 for (i
= 1; i
< lh
->opcode_base
; ++i
)
17911 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
17915 if (lh
->version
>= 5)
17917 /* Read directory table. */
17918 read_formatted_entries (abfd
, &line_ptr
, lh
, &cu
->header
,
17919 add_include_dir_stub
);
17921 /* Read file name table. */
17922 read_formatted_entries (abfd
, &line_ptr
, lh
, &cu
->header
, add_file_name
);
17926 /* Read directory table. */
17927 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
17929 line_ptr
+= bytes_read
;
17930 add_include_dir (lh
, cur_dir
);
17932 line_ptr
+= bytes_read
;
17934 /* Read file name table. */
17935 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
17937 unsigned int dir_index
, mod_time
, length
;
17939 line_ptr
+= bytes_read
;
17940 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17941 line_ptr
+= bytes_read
;
17942 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17943 line_ptr
+= bytes_read
;
17944 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17945 line_ptr
+= bytes_read
;
17947 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
17949 line_ptr
+= bytes_read
;
17951 lh
->statement_program_start
= line_ptr
;
17953 if (line_ptr
> (section
->buffer
+ section
->size
))
17954 complaint (&symfile_complaints
,
17955 _("line number info header doesn't "
17956 "fit in `.debug_line' section"));
17958 discard_cleanups (back_to
);
17962 /* Subroutine of dwarf_decode_lines to simplify it.
17963 Return the file name of the psymtab for included file FILE_INDEX
17964 in line header LH of PST.
17965 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
17966 If space for the result is malloc'd, it will be freed by a cleanup.
17967 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
17969 The function creates dangling cleanup registration. */
17971 static const char *
17972 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
17973 const struct partial_symtab
*pst
,
17974 const char *comp_dir
)
17976 const struct file_entry fe
= lh
->file_names
[file_index
];
17977 const char *include_name
= fe
.name
;
17978 const char *include_name_to_compare
= include_name
;
17979 const char *dir_name
= NULL
;
17980 const char *pst_filename
;
17981 char *copied_name
= NULL
;
17984 if (fe
.dir_index
&& lh
->include_dirs
!= NULL
)
17985 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
17987 if (!IS_ABSOLUTE_PATH (include_name
)
17988 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
17990 /* Avoid creating a duplicate psymtab for PST.
17991 We do this by comparing INCLUDE_NAME and PST_FILENAME.
17992 Before we do the comparison, however, we need to account
17993 for DIR_NAME and COMP_DIR.
17994 First prepend dir_name (if non-NULL). If we still don't
17995 have an absolute path prepend comp_dir (if non-NULL).
17996 However, the directory we record in the include-file's
17997 psymtab does not contain COMP_DIR (to match the
17998 corresponding symtab(s)).
18003 bash$ gcc -g ./hello.c
18004 include_name = "hello.c"
18006 DW_AT_comp_dir = comp_dir = "/tmp"
18007 DW_AT_name = "./hello.c"
18011 if (dir_name
!= NULL
)
18013 char *tem
= concat (dir_name
, SLASH_STRING
,
18014 include_name
, (char *)NULL
);
18016 make_cleanup (xfree
, tem
);
18017 include_name
= tem
;
18018 include_name_to_compare
= include_name
;
18020 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
18022 char *tem
= concat (comp_dir
, SLASH_STRING
,
18023 include_name
, (char *)NULL
);
18025 make_cleanup (xfree
, tem
);
18026 include_name_to_compare
= tem
;
18030 pst_filename
= pst
->filename
;
18031 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
18033 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
18034 pst_filename
, (char *)NULL
);
18035 pst_filename
= copied_name
;
18038 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
18040 if (copied_name
!= NULL
)
18041 xfree (copied_name
);
18045 return include_name
;
18048 /* State machine to track the state of the line number program. */
18052 /* These are part of the standard DWARF line number state machine. */
18054 unsigned char op_index
;
18059 unsigned int discriminator
;
18061 /* Additional bits of state we need to track. */
18063 /* The last file that we called dwarf2_start_subfile for.
18064 This is only used for TLLs. */
18065 unsigned int last_file
;
18066 /* The last file a line number was recorded for. */
18067 struct subfile
*last_subfile
;
18069 /* The function to call to record a line. */
18070 record_line_ftype
*record_line
;
18072 /* The last line number that was recorded, used to coalesce
18073 consecutive entries for the same line. This can happen, for
18074 example, when discriminators are present. PR 17276. */
18075 unsigned int last_line
;
18076 int line_has_non_zero_discriminator
;
18077 } lnp_state_machine
;
18079 /* There's a lot of static state to pass to dwarf_record_line.
18080 This keeps it all together. */
18085 struct gdbarch
*gdbarch
;
18087 /* The line number header. */
18088 struct line_header
*line_header
;
18090 /* Non-zero if we're recording lines.
18091 Otherwise we're building partial symtabs and are just interested in
18092 finding include files mentioned by the line number program. */
18093 int record_lines_p
;
18094 } lnp_reader_state
;
18096 /* Ignore this record_line request. */
18099 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
18104 /* Return non-zero if we should add LINE to the line number table.
18105 LINE is the line to add, LAST_LINE is the last line that was added,
18106 LAST_SUBFILE is the subfile for LAST_LINE.
18107 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
18108 had a non-zero discriminator.
18110 We have to be careful in the presence of discriminators.
18111 E.g., for this line:
18113 for (i = 0; i < 100000; i++);
18115 clang can emit four line number entries for that one line,
18116 each with a different discriminator.
18117 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
18119 However, we want gdb to coalesce all four entries into one.
18120 Otherwise the user could stepi into the middle of the line and
18121 gdb would get confused about whether the pc really was in the
18122 middle of the line.
18124 Things are further complicated by the fact that two consecutive
18125 line number entries for the same line is a heuristic used by gcc
18126 to denote the end of the prologue. So we can't just discard duplicate
18127 entries, we have to be selective about it. The heuristic we use is
18128 that we only collapse consecutive entries for the same line if at least
18129 one of those entries has a non-zero discriminator. PR 17276.
18131 Note: Addresses in the line number state machine can never go backwards
18132 within one sequence, thus this coalescing is ok. */
18135 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
18136 int line_has_non_zero_discriminator
,
18137 struct subfile
*last_subfile
)
18139 if (current_subfile
!= last_subfile
)
18141 if (line
!= last_line
)
18143 /* Same line for the same file that we've seen already.
18144 As a last check, for pr 17276, only record the line if the line
18145 has never had a non-zero discriminator. */
18146 if (!line_has_non_zero_discriminator
)
18151 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
18152 in the line table of subfile SUBFILE. */
18155 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
18156 unsigned int line
, CORE_ADDR address
,
18157 record_line_ftype p_record_line
)
18159 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
18161 if (dwarf_line_debug
)
18163 fprintf_unfiltered (gdb_stdlog
,
18164 "Recording line %u, file %s, address %s\n",
18165 line
, lbasename (subfile
->name
),
18166 paddress (gdbarch
, address
));
18169 (*p_record_line
) (subfile
, line
, addr
);
18172 /* Subroutine of dwarf_decode_lines_1 to simplify it.
18173 Mark the end of a set of line number records.
18174 The arguments are the same as for dwarf_record_line_1.
18175 If SUBFILE is NULL the request is ignored. */
18178 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
18179 CORE_ADDR address
, record_line_ftype p_record_line
)
18181 if (subfile
== NULL
)
18184 if (dwarf_line_debug
)
18186 fprintf_unfiltered (gdb_stdlog
,
18187 "Finishing current line, file %s, address %s\n",
18188 lbasename (subfile
->name
),
18189 paddress (gdbarch
, address
));
18192 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
18195 /* Record the line in STATE.
18196 END_SEQUENCE is non-zero if we're processing the end of a sequence. */
18199 dwarf_record_line (lnp_reader_state
*reader
, lnp_state_machine
*state
,
18202 const struct line_header
*lh
= reader
->line_header
;
18203 unsigned int file
, line
, discriminator
;
18206 file
= state
->file
;
18207 line
= state
->line
;
18208 is_stmt
= state
->is_stmt
;
18209 discriminator
= state
->discriminator
;
18211 if (dwarf_line_debug
)
18213 fprintf_unfiltered (gdb_stdlog
,
18214 "Processing actual line %u: file %u,"
18215 " address %s, is_stmt %u, discrim %u\n",
18217 paddress (reader
->gdbarch
, state
->address
),
18218 is_stmt
, discriminator
);
18221 if (file
== 0 || file
- 1 >= lh
->num_file_names
)
18222 dwarf2_debug_line_missing_file_complaint ();
18223 /* For now we ignore lines not starting on an instruction boundary.
18224 But not when processing end_sequence for compatibility with the
18225 previous version of the code. */
18226 else if (state
->op_index
== 0 || end_sequence
)
18228 lh
->file_names
[file
- 1].included_p
= 1;
18229 if (reader
->record_lines_p
&& is_stmt
)
18231 if (state
->last_subfile
!= current_subfile
|| end_sequence
)
18233 dwarf_finish_line (reader
->gdbarch
, state
->last_subfile
,
18234 state
->address
, state
->record_line
);
18239 if (dwarf_record_line_p (line
, state
->last_line
,
18240 state
->line_has_non_zero_discriminator
,
18241 state
->last_subfile
))
18243 dwarf_record_line_1 (reader
->gdbarch
, current_subfile
,
18244 line
, state
->address
,
18245 state
->record_line
);
18247 state
->last_subfile
= current_subfile
;
18248 state
->last_line
= line
;
18254 /* Initialize STATE for the start of a line number program. */
18257 init_lnp_state_machine (lnp_state_machine
*state
,
18258 const lnp_reader_state
*reader
)
18260 memset (state
, 0, sizeof (*state
));
18262 /* Just starting, there is no "last file". */
18263 state
->last_file
= 0;
18264 state
->last_subfile
= NULL
;
18266 state
->record_line
= record_line
;
18268 state
->last_line
= 0;
18269 state
->line_has_non_zero_discriminator
= 0;
18271 /* Initialize these according to the DWARF spec. */
18272 state
->op_index
= 0;
18275 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
18276 was a line entry for it so that the backend has a chance to adjust it
18277 and also record it in case it needs it. This is currently used by MIPS
18278 code, cf. `mips_adjust_dwarf2_line'. */
18279 state
->address
= gdbarch_adjust_dwarf2_line (reader
->gdbarch
, 0, 0);
18280 state
->is_stmt
= reader
->line_header
->default_is_stmt
;
18281 state
->discriminator
= 0;
18284 /* Check address and if invalid nop-out the rest of the lines in this
18288 check_line_address (struct dwarf2_cu
*cu
, lnp_state_machine
*state
,
18289 const gdb_byte
*line_ptr
,
18290 CORE_ADDR lowpc
, CORE_ADDR address
)
18292 /* If address < lowpc then it's not a usable value, it's outside the
18293 pc range of the CU. However, we restrict the test to only address
18294 values of zero to preserve GDB's previous behaviour which is to
18295 handle the specific case of a function being GC'd by the linker. */
18297 if (address
== 0 && address
< lowpc
)
18299 /* This line table is for a function which has been
18300 GCd by the linker. Ignore it. PR gdb/12528 */
18302 struct objfile
*objfile
= cu
->objfile
;
18303 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
18305 complaint (&symfile_complaints
,
18306 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
18307 line_offset
, objfile_name (objfile
));
18308 state
->record_line
= noop_record_line
;
18309 /* Note: sm.record_line is left as noop_record_line
18310 until we see DW_LNE_end_sequence. */
18314 /* Subroutine of dwarf_decode_lines to simplify it.
18315 Process the line number information in LH.
18316 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
18317 program in order to set included_p for every referenced header. */
18320 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
18321 const int decode_for_pst_p
, CORE_ADDR lowpc
)
18323 const gdb_byte
*line_ptr
, *extended_end
;
18324 const gdb_byte
*line_end
;
18325 unsigned int bytes_read
, extended_len
;
18326 unsigned char op_code
, extended_op
;
18327 CORE_ADDR baseaddr
;
18328 struct objfile
*objfile
= cu
->objfile
;
18329 bfd
*abfd
= objfile
->obfd
;
18330 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18331 /* Non-zero if we're recording line info (as opposed to building partial
18333 int record_lines_p
= !decode_for_pst_p
;
18334 /* A collection of things we need to pass to dwarf_record_line. */
18335 lnp_reader_state reader_state
;
18337 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18339 line_ptr
= lh
->statement_program_start
;
18340 line_end
= lh
->statement_program_end
;
18342 reader_state
.gdbarch
= gdbarch
;
18343 reader_state
.line_header
= lh
;
18344 reader_state
.record_lines_p
= record_lines_p
;
18346 /* Read the statement sequences until there's nothing left. */
18347 while (line_ptr
< line_end
)
18349 /* The DWARF line number program state machine. */
18350 lnp_state_machine state_machine
;
18351 int end_sequence
= 0;
18353 /* Reset the state machine at the start of each sequence. */
18354 init_lnp_state_machine (&state_machine
, &reader_state
);
18356 if (record_lines_p
&& lh
->num_file_names
>= state_machine
.file
)
18358 /* Start a subfile for the current file of the state machine. */
18359 /* lh->include_dirs and lh->file_names are 0-based, but the
18360 directory and file name numbers in the statement program
18362 struct file_entry
*fe
= &lh
->file_names
[state_machine
.file
- 1];
18363 const char *dir
= NULL
;
18365 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
18366 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
18368 dwarf2_start_subfile (fe
->name
, dir
);
18371 /* Decode the table. */
18372 while (line_ptr
< line_end
&& !end_sequence
)
18374 op_code
= read_1_byte (abfd
, line_ptr
);
18377 if (op_code
>= lh
->opcode_base
)
18379 /* Special opcode. */
18380 unsigned char adj_opcode
;
18381 CORE_ADDR addr_adj
;
18384 adj_opcode
= op_code
- lh
->opcode_base
;
18385 addr_adj
= (((state_machine
.op_index
18386 + (adj_opcode
/ lh
->line_range
))
18387 / lh
->maximum_ops_per_instruction
)
18388 * lh
->minimum_instruction_length
);
18389 state_machine
.address
18390 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
18391 state_machine
.op_index
= ((state_machine
.op_index
18392 + (adj_opcode
/ lh
->line_range
))
18393 % lh
->maximum_ops_per_instruction
);
18394 line_delta
= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
18395 state_machine
.line
+= line_delta
;
18396 if (line_delta
!= 0)
18397 state_machine
.line_has_non_zero_discriminator
18398 = state_machine
.discriminator
!= 0;
18400 dwarf_record_line (&reader_state
, &state_machine
, 0);
18401 state_machine
.discriminator
= 0;
18403 else switch (op_code
)
18405 case DW_LNS_extended_op
:
18406 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
18408 line_ptr
+= bytes_read
;
18409 extended_end
= line_ptr
+ extended_len
;
18410 extended_op
= read_1_byte (abfd
, line_ptr
);
18412 switch (extended_op
)
18414 case DW_LNE_end_sequence
:
18415 state_machine
.record_line
= record_line
;
18418 case DW_LNE_set_address
:
18421 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
18423 line_ptr
+= bytes_read
;
18424 check_line_address (cu
, &state_machine
, line_ptr
,
18426 state_machine
.op_index
= 0;
18427 address
+= baseaddr
;
18428 state_machine
.address
18429 = gdbarch_adjust_dwarf2_line (gdbarch
, address
, 0);
18432 case DW_LNE_define_file
:
18434 const char *cur_file
;
18435 unsigned int dir_index
, mod_time
, length
;
18437 cur_file
= read_direct_string (abfd
, line_ptr
,
18439 line_ptr
+= bytes_read
;
18441 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18442 line_ptr
+= bytes_read
;
18444 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18445 line_ptr
+= bytes_read
;
18447 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18448 line_ptr
+= bytes_read
;
18449 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
18452 case DW_LNE_set_discriminator
:
18453 /* The discriminator is not interesting to the debugger;
18454 just ignore it. We still need to check its value though:
18455 if there are consecutive entries for the same
18456 (non-prologue) line we want to coalesce them.
18458 state_machine
.discriminator
18459 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18460 state_machine
.line_has_non_zero_discriminator
18461 |= state_machine
.discriminator
!= 0;
18462 line_ptr
+= bytes_read
;
18465 complaint (&symfile_complaints
,
18466 _("mangled .debug_line section"));
18469 /* Make sure that we parsed the extended op correctly. If e.g.
18470 we expected a different address size than the producer used,
18471 we may have read the wrong number of bytes. */
18472 if (line_ptr
!= extended_end
)
18474 complaint (&symfile_complaints
,
18475 _("mangled .debug_line section"));
18480 dwarf_record_line (&reader_state
, &state_machine
, 0);
18481 state_machine
.discriminator
= 0;
18483 case DW_LNS_advance_pc
:
18486 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18487 CORE_ADDR addr_adj
;
18489 addr_adj
= (((state_machine
.op_index
+ adjust
)
18490 / lh
->maximum_ops_per_instruction
)
18491 * lh
->minimum_instruction_length
);
18492 state_machine
.address
18493 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
18494 state_machine
.op_index
= ((state_machine
.op_index
+ adjust
)
18495 % lh
->maximum_ops_per_instruction
);
18496 line_ptr
+= bytes_read
;
18499 case DW_LNS_advance_line
:
18502 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
18504 state_machine
.line
+= line_delta
;
18505 if (line_delta
!= 0)
18506 state_machine
.line_has_non_zero_discriminator
18507 = state_machine
.discriminator
!= 0;
18508 line_ptr
+= bytes_read
;
18511 case DW_LNS_set_file
:
18513 /* The arrays lh->include_dirs and lh->file_names are
18514 0-based, but the directory and file name numbers in
18515 the statement program are 1-based. */
18516 struct file_entry
*fe
;
18517 const char *dir
= NULL
;
18519 state_machine
.file
= read_unsigned_leb128 (abfd
, line_ptr
,
18521 line_ptr
+= bytes_read
;
18522 if (state_machine
.file
== 0
18523 || state_machine
.file
- 1 >= lh
->num_file_names
)
18524 dwarf2_debug_line_missing_file_complaint ();
18527 fe
= &lh
->file_names
[state_machine
.file
- 1];
18528 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
18529 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
18530 if (record_lines_p
)
18532 state_machine
.last_subfile
= current_subfile
;
18533 state_machine
.line_has_non_zero_discriminator
18534 = state_machine
.discriminator
!= 0;
18535 dwarf2_start_subfile (fe
->name
, dir
);
18540 case DW_LNS_set_column
:
18541 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18542 line_ptr
+= bytes_read
;
18544 case DW_LNS_negate_stmt
:
18545 state_machine
.is_stmt
= (!state_machine
.is_stmt
);
18547 case DW_LNS_set_basic_block
:
18549 /* Add to the address register of the state machine the
18550 address increment value corresponding to special opcode
18551 255. I.e., this value is scaled by the minimum
18552 instruction length since special opcode 255 would have
18553 scaled the increment. */
18554 case DW_LNS_const_add_pc
:
18556 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
18557 CORE_ADDR addr_adj
;
18559 addr_adj
= (((state_machine
.op_index
+ adjust
)
18560 / lh
->maximum_ops_per_instruction
)
18561 * lh
->minimum_instruction_length
);
18562 state_machine
.address
18563 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
18564 state_machine
.op_index
= ((state_machine
.op_index
+ adjust
)
18565 % lh
->maximum_ops_per_instruction
);
18568 case DW_LNS_fixed_advance_pc
:
18570 CORE_ADDR addr_adj
;
18572 addr_adj
= read_2_bytes (abfd
, line_ptr
);
18573 state_machine
.address
18574 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
18575 state_machine
.op_index
= 0;
18581 /* Unknown standard opcode, ignore it. */
18584 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
18586 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18587 line_ptr
+= bytes_read
;
18594 dwarf2_debug_line_missing_end_sequence_complaint ();
18596 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
18597 in which case we still finish recording the last line). */
18598 dwarf_record_line (&reader_state
, &state_machine
, 1);
18602 /* Decode the Line Number Program (LNP) for the given line_header
18603 structure and CU. The actual information extracted and the type
18604 of structures created from the LNP depends on the value of PST.
18606 1. If PST is NULL, then this procedure uses the data from the program
18607 to create all necessary symbol tables, and their linetables.
18609 2. If PST is not NULL, this procedure reads the program to determine
18610 the list of files included by the unit represented by PST, and
18611 builds all the associated partial symbol tables.
18613 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
18614 It is used for relative paths in the line table.
18615 NOTE: When processing partial symtabs (pst != NULL),
18616 comp_dir == pst->dirname.
18618 NOTE: It is important that psymtabs have the same file name (via strcmp)
18619 as the corresponding symtab. Since COMP_DIR is not used in the name of the
18620 symtab we don't use it in the name of the psymtabs we create.
18621 E.g. expand_line_sal requires this when finding psymtabs to expand.
18622 A good testcase for this is mb-inline.exp.
18624 LOWPC is the lowest address in CU (or 0 if not known).
18626 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
18627 for its PC<->lines mapping information. Otherwise only the filename
18628 table is read in. */
18631 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
18632 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
18633 CORE_ADDR lowpc
, int decode_mapping
)
18635 struct objfile
*objfile
= cu
->objfile
;
18636 const int decode_for_pst_p
= (pst
!= NULL
);
18638 if (decode_mapping
)
18639 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
18641 if (decode_for_pst_p
)
18645 /* Now that we're done scanning the Line Header Program, we can
18646 create the psymtab of each included file. */
18647 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
18648 if (lh
->file_names
[file_index
].included_p
== 1)
18650 const char *include_name
=
18651 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
18652 if (include_name
!= NULL
)
18653 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
18658 /* Make sure a symtab is created for every file, even files
18659 which contain only variables (i.e. no code with associated
18661 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
18664 for (i
= 0; i
< lh
->num_file_names
; i
++)
18666 const char *dir
= NULL
;
18667 struct file_entry
*fe
;
18669 fe
= &lh
->file_names
[i
];
18670 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
18671 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
18672 dwarf2_start_subfile (fe
->name
, dir
);
18674 if (current_subfile
->symtab
== NULL
)
18676 current_subfile
->symtab
18677 = allocate_symtab (cust
, current_subfile
->name
);
18679 fe
->symtab
= current_subfile
->symtab
;
18684 /* Start a subfile for DWARF. FILENAME is the name of the file and
18685 DIRNAME the name of the source directory which contains FILENAME
18686 or NULL if not known.
18687 This routine tries to keep line numbers from identical absolute and
18688 relative file names in a common subfile.
18690 Using the `list' example from the GDB testsuite, which resides in
18691 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
18692 of /srcdir/list0.c yields the following debugging information for list0.c:
18694 DW_AT_name: /srcdir/list0.c
18695 DW_AT_comp_dir: /compdir
18696 files.files[0].name: list0.h
18697 files.files[0].dir: /srcdir
18698 files.files[1].name: list0.c
18699 files.files[1].dir: /srcdir
18701 The line number information for list0.c has to end up in a single
18702 subfile, so that `break /srcdir/list0.c:1' works as expected.
18703 start_subfile will ensure that this happens provided that we pass the
18704 concatenation of files.files[1].dir and files.files[1].name as the
18708 dwarf2_start_subfile (const char *filename
, const char *dirname
)
18712 /* In order not to lose the line information directory,
18713 we concatenate it to the filename when it makes sense.
18714 Note that the Dwarf3 standard says (speaking of filenames in line
18715 information): ``The directory index is ignored for file names
18716 that represent full path names''. Thus ignoring dirname in the
18717 `else' branch below isn't an issue. */
18719 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
18721 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
18725 start_subfile (filename
);
18731 /* Start a symtab for DWARF.
18732 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
18734 static struct compunit_symtab
*
18735 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
18736 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
18738 struct compunit_symtab
*cust
18739 = start_symtab (cu
->objfile
, name
, comp_dir
, low_pc
);
18741 record_debugformat ("DWARF 2");
18742 record_producer (cu
->producer
);
18744 /* We assume that we're processing GCC output. */
18745 processing_gcc_compilation
= 2;
18747 cu
->processing_has_namespace_info
= 0;
18753 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
18754 struct dwarf2_cu
*cu
)
18756 struct objfile
*objfile
= cu
->objfile
;
18757 struct comp_unit_head
*cu_header
= &cu
->header
;
18759 /* NOTE drow/2003-01-30: There used to be a comment and some special
18760 code here to turn a symbol with DW_AT_external and a
18761 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
18762 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
18763 with some versions of binutils) where shared libraries could have
18764 relocations against symbols in their debug information - the
18765 minimal symbol would have the right address, but the debug info
18766 would not. It's no longer necessary, because we will explicitly
18767 apply relocations when we read in the debug information now. */
18769 /* A DW_AT_location attribute with no contents indicates that a
18770 variable has been optimized away. */
18771 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
18773 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
18777 /* Handle one degenerate form of location expression specially, to
18778 preserve GDB's previous behavior when section offsets are
18779 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
18780 then mark this symbol as LOC_STATIC. */
18782 if (attr_form_is_block (attr
)
18783 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
18784 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
18785 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
18786 && (DW_BLOCK (attr
)->size
18787 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
18789 unsigned int dummy
;
18791 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
18792 SYMBOL_VALUE_ADDRESS (sym
) =
18793 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
18795 SYMBOL_VALUE_ADDRESS (sym
) =
18796 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
18797 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
18798 fixup_symbol_section (sym
, objfile
);
18799 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
18800 SYMBOL_SECTION (sym
));
18804 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
18805 expression evaluator, and use LOC_COMPUTED only when necessary
18806 (i.e. when the value of a register or memory location is
18807 referenced, or a thread-local block, etc.). Then again, it might
18808 not be worthwhile. I'm assuming that it isn't unless performance
18809 or memory numbers show me otherwise. */
18811 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
18813 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
18814 cu
->has_loclist
= 1;
18817 /* Given a pointer to a DWARF information entry, figure out if we need
18818 to make a symbol table entry for it, and if so, create a new entry
18819 and return a pointer to it.
18820 If TYPE is NULL, determine symbol type from the die, otherwise
18821 used the passed type.
18822 If SPACE is not NULL, use it to hold the new symbol. If it is
18823 NULL, allocate a new symbol on the objfile's obstack. */
18825 static struct symbol
*
18826 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
18827 struct symbol
*space
)
18829 struct objfile
*objfile
= cu
->objfile
;
18830 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18831 struct symbol
*sym
= NULL
;
18833 struct attribute
*attr
= NULL
;
18834 struct attribute
*attr2
= NULL
;
18835 CORE_ADDR baseaddr
;
18836 struct pending
**list_to_add
= NULL
;
18838 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
18840 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18842 name
= dwarf2_name (die
, cu
);
18845 const char *linkagename
;
18846 int suppress_add
= 0;
18851 sym
= allocate_symbol (objfile
);
18852 OBJSTAT (objfile
, n_syms
++);
18854 /* Cache this symbol's name and the name's demangled form (if any). */
18855 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
18856 linkagename
= dwarf2_physname (name
, die
, cu
);
18857 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
18859 /* Fortran does not have mangling standard and the mangling does differ
18860 between gfortran, iFort etc. */
18861 if (cu
->language
== language_fortran
18862 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
18863 symbol_set_demangled_name (&(sym
->ginfo
),
18864 dwarf2_full_name (name
, die
, cu
),
18867 /* Default assumptions.
18868 Use the passed type or decode it from the die. */
18869 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
18870 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
18872 SYMBOL_TYPE (sym
) = type
;
18874 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
18875 attr
= dwarf2_attr (die
,
18876 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
18880 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
18883 attr
= dwarf2_attr (die
,
18884 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
18888 int file_index
= DW_UNSND (attr
);
18890 if (cu
->line_header
== NULL
18891 || file_index
> cu
->line_header
->num_file_names
)
18892 complaint (&symfile_complaints
,
18893 _("file index out of range"));
18894 else if (file_index
> 0)
18896 struct file_entry
*fe
;
18898 fe
= &cu
->line_header
->file_names
[file_index
- 1];
18899 symbol_set_symtab (sym
, fe
->symtab
);
18906 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
18911 addr
= attr_value_as_address (attr
);
18912 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
18913 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
18915 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
18916 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
18917 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
18918 add_symbol_to_list (sym
, cu
->list_in_scope
);
18920 case DW_TAG_subprogram
:
18921 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
18923 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
18924 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18925 if ((attr2
&& (DW_UNSND (attr2
) != 0))
18926 || cu
->language
== language_ada
)
18928 /* Subprograms marked external are stored as a global symbol.
18929 Ada subprograms, whether marked external or not, are always
18930 stored as a global symbol, because we want to be able to
18931 access them globally. For instance, we want to be able
18932 to break on a nested subprogram without having to
18933 specify the context. */
18934 list_to_add
= &global_symbols
;
18938 list_to_add
= cu
->list_in_scope
;
18941 case DW_TAG_inlined_subroutine
:
18942 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
18944 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
18945 SYMBOL_INLINED (sym
) = 1;
18946 list_to_add
= cu
->list_in_scope
;
18948 case DW_TAG_template_value_param
:
18950 /* Fall through. */
18951 case DW_TAG_constant
:
18952 case DW_TAG_variable
:
18953 case DW_TAG_member
:
18954 /* Compilation with minimal debug info may result in
18955 variables with missing type entries. Change the
18956 misleading `void' type to something sensible. */
18957 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
18959 = objfile_type (objfile
)->nodebug_data_symbol
;
18961 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
18962 /* In the case of DW_TAG_member, we should only be called for
18963 static const members. */
18964 if (die
->tag
== DW_TAG_member
)
18966 /* dwarf2_add_field uses die_is_declaration,
18967 so we do the same. */
18968 gdb_assert (die_is_declaration (die
, cu
));
18973 dwarf2_const_value (attr
, sym
, cu
);
18974 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18977 if (attr2
&& (DW_UNSND (attr2
) != 0))
18978 list_to_add
= &global_symbols
;
18980 list_to_add
= cu
->list_in_scope
;
18984 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
18987 var_decode_location (attr
, sym
, cu
);
18988 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18990 /* Fortran explicitly imports any global symbols to the local
18991 scope by DW_TAG_common_block. */
18992 if (cu
->language
== language_fortran
&& die
->parent
18993 && die
->parent
->tag
== DW_TAG_common_block
)
18996 if (SYMBOL_CLASS (sym
) == LOC_STATIC
18997 && SYMBOL_VALUE_ADDRESS (sym
) == 0
18998 && !dwarf2_per_objfile
->has_section_at_zero
)
19000 /* When a static variable is eliminated by the linker,
19001 the corresponding debug information is not stripped
19002 out, but the variable address is set to null;
19003 do not add such variables into symbol table. */
19005 else if (attr2
&& (DW_UNSND (attr2
) != 0))
19007 /* Workaround gfortran PR debug/40040 - it uses
19008 DW_AT_location for variables in -fPIC libraries which may
19009 get overriden by other libraries/executable and get
19010 a different address. Resolve it by the minimal symbol
19011 which may come from inferior's executable using copy
19012 relocation. Make this workaround only for gfortran as for
19013 other compilers GDB cannot guess the minimal symbol
19014 Fortran mangling kind. */
19015 if (cu
->language
== language_fortran
&& die
->parent
19016 && die
->parent
->tag
== DW_TAG_module
19018 && startswith (cu
->producer
, "GNU Fortran"))
19019 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
19021 /* A variable with DW_AT_external is never static,
19022 but it may be block-scoped. */
19023 list_to_add
= (cu
->list_in_scope
== &file_symbols
19024 ? &global_symbols
: cu
->list_in_scope
);
19027 list_to_add
= cu
->list_in_scope
;
19031 /* We do not know the address of this symbol.
19032 If it is an external symbol and we have type information
19033 for it, enter the symbol as a LOC_UNRESOLVED symbol.
19034 The address of the variable will then be determined from
19035 the minimal symbol table whenever the variable is
19037 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19039 /* Fortran explicitly imports any global symbols to the local
19040 scope by DW_TAG_common_block. */
19041 if (cu
->language
== language_fortran
&& die
->parent
19042 && die
->parent
->tag
== DW_TAG_common_block
)
19044 /* SYMBOL_CLASS doesn't matter here because
19045 read_common_block is going to reset it. */
19047 list_to_add
= cu
->list_in_scope
;
19049 else if (attr2
&& (DW_UNSND (attr2
) != 0)
19050 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
19052 /* A variable with DW_AT_external is never static, but it
19053 may be block-scoped. */
19054 list_to_add
= (cu
->list_in_scope
== &file_symbols
19055 ? &global_symbols
: cu
->list_in_scope
);
19057 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
19059 else if (!die_is_declaration (die
, cu
))
19061 /* Use the default LOC_OPTIMIZED_OUT class. */
19062 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
19064 list_to_add
= cu
->list_in_scope
;
19068 case DW_TAG_formal_parameter
:
19069 /* If we are inside a function, mark this as an argument. If
19070 not, we might be looking at an argument to an inlined function
19071 when we do not have enough information to show inlined frames;
19072 pretend it's a local variable in that case so that the user can
19074 if (context_stack_depth
> 0
19075 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
19076 SYMBOL_IS_ARGUMENT (sym
) = 1;
19077 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
19080 var_decode_location (attr
, sym
, cu
);
19082 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19085 dwarf2_const_value (attr
, sym
, cu
);
19088 list_to_add
= cu
->list_in_scope
;
19090 case DW_TAG_unspecified_parameters
:
19091 /* From varargs functions; gdb doesn't seem to have any
19092 interest in this information, so just ignore it for now.
19095 case DW_TAG_template_type_param
:
19097 /* Fall through. */
19098 case DW_TAG_class_type
:
19099 case DW_TAG_interface_type
:
19100 case DW_TAG_structure_type
:
19101 case DW_TAG_union_type
:
19102 case DW_TAG_set_type
:
19103 case DW_TAG_enumeration_type
:
19104 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19105 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
19108 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
19109 really ever be static objects: otherwise, if you try
19110 to, say, break of a class's method and you're in a file
19111 which doesn't mention that class, it won't work unless
19112 the check for all static symbols in lookup_symbol_aux
19113 saves you. See the OtherFileClass tests in
19114 gdb.c++/namespace.exp. */
19118 list_to_add
= (cu
->list_in_scope
== &file_symbols
19119 && cu
->language
== language_cplus
19120 ? &global_symbols
: cu
->list_in_scope
);
19122 /* The semantics of C++ state that "struct foo {
19123 ... }" also defines a typedef for "foo". */
19124 if (cu
->language
== language_cplus
19125 || cu
->language
== language_ada
19126 || cu
->language
== language_d
19127 || cu
->language
== language_rust
)
19129 /* The symbol's name is already allocated along
19130 with this objfile, so we don't need to
19131 duplicate it for the type. */
19132 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
19133 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
19138 case DW_TAG_typedef
:
19139 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19140 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19141 list_to_add
= cu
->list_in_scope
;
19143 case DW_TAG_base_type
:
19144 case DW_TAG_subrange_type
:
19145 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19146 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19147 list_to_add
= cu
->list_in_scope
;
19149 case DW_TAG_enumerator
:
19150 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19153 dwarf2_const_value (attr
, sym
, cu
);
19156 /* NOTE: carlton/2003-11-10: See comment above in the
19157 DW_TAG_class_type, etc. block. */
19159 list_to_add
= (cu
->list_in_scope
== &file_symbols
19160 && cu
->language
== language_cplus
19161 ? &global_symbols
: cu
->list_in_scope
);
19164 case DW_TAG_imported_declaration
:
19165 case DW_TAG_namespace
:
19166 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19167 list_to_add
= &global_symbols
;
19169 case DW_TAG_module
:
19170 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19171 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
19172 list_to_add
= &global_symbols
;
19174 case DW_TAG_common_block
:
19175 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
19176 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
19177 add_symbol_to_list (sym
, cu
->list_in_scope
);
19180 /* Not a tag we recognize. Hopefully we aren't processing
19181 trash data, but since we must specifically ignore things
19182 we don't recognize, there is nothing else we should do at
19184 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
19185 dwarf_tag_name (die
->tag
));
19191 sym
->hash_next
= objfile
->template_symbols
;
19192 objfile
->template_symbols
= sym
;
19193 list_to_add
= NULL
;
19196 if (list_to_add
!= NULL
)
19197 add_symbol_to_list (sym
, list_to_add
);
19199 /* For the benefit of old versions of GCC, check for anonymous
19200 namespaces based on the demangled name. */
19201 if (!cu
->processing_has_namespace_info
19202 && cu
->language
== language_cplus
)
19203 cp_scan_for_anonymous_namespaces (sym
, objfile
);
19208 /* A wrapper for new_symbol_full that always allocates a new symbol. */
19210 static struct symbol
*
19211 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
19213 return new_symbol_full (die
, type
, cu
, NULL
);
19216 /* Given an attr with a DW_FORM_dataN value in host byte order,
19217 zero-extend it as appropriate for the symbol's type. The DWARF
19218 standard (v4) is not entirely clear about the meaning of using
19219 DW_FORM_dataN for a constant with a signed type, where the type is
19220 wider than the data. The conclusion of a discussion on the DWARF
19221 list was that this is unspecified. We choose to always zero-extend
19222 because that is the interpretation long in use by GCC. */
19225 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
19226 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
19228 struct objfile
*objfile
= cu
->objfile
;
19229 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
19230 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
19231 LONGEST l
= DW_UNSND (attr
);
19233 if (bits
< sizeof (*value
) * 8)
19235 l
&= ((LONGEST
) 1 << bits
) - 1;
19238 else if (bits
== sizeof (*value
) * 8)
19242 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
19243 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
19250 /* Read a constant value from an attribute. Either set *VALUE, or if
19251 the value does not fit in *VALUE, set *BYTES - either already
19252 allocated on the objfile obstack, or newly allocated on OBSTACK,
19253 or, set *BATON, if we translated the constant to a location
19257 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
19258 const char *name
, struct obstack
*obstack
,
19259 struct dwarf2_cu
*cu
,
19260 LONGEST
*value
, const gdb_byte
**bytes
,
19261 struct dwarf2_locexpr_baton
**baton
)
19263 struct objfile
*objfile
= cu
->objfile
;
19264 struct comp_unit_head
*cu_header
= &cu
->header
;
19265 struct dwarf_block
*blk
;
19266 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
19267 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
19273 switch (attr
->form
)
19276 case DW_FORM_GNU_addr_index
:
19280 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
19281 dwarf2_const_value_length_mismatch_complaint (name
,
19282 cu_header
->addr_size
,
19283 TYPE_LENGTH (type
));
19284 /* Symbols of this form are reasonably rare, so we just
19285 piggyback on the existing location code rather than writing
19286 a new implementation of symbol_computed_ops. */
19287 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
19288 (*baton
)->per_cu
= cu
->per_cu
;
19289 gdb_assert ((*baton
)->per_cu
);
19291 (*baton
)->size
= 2 + cu_header
->addr_size
;
19292 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
19293 (*baton
)->data
= data
;
19295 data
[0] = DW_OP_addr
;
19296 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
19297 byte_order
, DW_ADDR (attr
));
19298 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
19301 case DW_FORM_string
:
19303 case DW_FORM_GNU_str_index
:
19304 case DW_FORM_GNU_strp_alt
:
19305 /* DW_STRING is already allocated on the objfile obstack, point
19307 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
19309 case DW_FORM_block1
:
19310 case DW_FORM_block2
:
19311 case DW_FORM_block4
:
19312 case DW_FORM_block
:
19313 case DW_FORM_exprloc
:
19314 case DW_FORM_data16
:
19315 blk
= DW_BLOCK (attr
);
19316 if (TYPE_LENGTH (type
) != blk
->size
)
19317 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
19318 TYPE_LENGTH (type
));
19319 *bytes
= blk
->data
;
19322 /* The DW_AT_const_value attributes are supposed to carry the
19323 symbol's value "represented as it would be on the target
19324 architecture." By the time we get here, it's already been
19325 converted to host endianness, so we just need to sign- or
19326 zero-extend it as appropriate. */
19327 case DW_FORM_data1
:
19328 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
19330 case DW_FORM_data2
:
19331 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
19333 case DW_FORM_data4
:
19334 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
19336 case DW_FORM_data8
:
19337 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
19340 case DW_FORM_sdata
:
19341 *value
= DW_SND (attr
);
19344 case DW_FORM_udata
:
19345 *value
= DW_UNSND (attr
);
19349 complaint (&symfile_complaints
,
19350 _("unsupported const value attribute form: '%s'"),
19351 dwarf_form_name (attr
->form
));
19358 /* Copy constant value from an attribute to a symbol. */
19361 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
19362 struct dwarf2_cu
*cu
)
19364 struct objfile
*objfile
= cu
->objfile
;
19366 const gdb_byte
*bytes
;
19367 struct dwarf2_locexpr_baton
*baton
;
19369 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
19370 SYMBOL_PRINT_NAME (sym
),
19371 &objfile
->objfile_obstack
, cu
,
19372 &value
, &bytes
, &baton
);
19376 SYMBOL_LOCATION_BATON (sym
) = baton
;
19377 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
19379 else if (bytes
!= NULL
)
19381 SYMBOL_VALUE_BYTES (sym
) = bytes
;
19382 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
19386 SYMBOL_VALUE (sym
) = value
;
19387 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
19391 /* Return the type of the die in question using its DW_AT_type attribute. */
19393 static struct type
*
19394 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19396 struct attribute
*type_attr
;
19398 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
19401 /* A missing DW_AT_type represents a void type. */
19402 return objfile_type (cu
->objfile
)->builtin_void
;
19405 return lookup_die_type (die
, type_attr
, cu
);
19408 /* True iff CU's producer generates GNAT Ada auxiliary information
19409 that allows to find parallel types through that information instead
19410 of having to do expensive parallel lookups by type name. */
19413 need_gnat_info (struct dwarf2_cu
*cu
)
19415 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
19416 of GNAT produces this auxiliary information, without any indication
19417 that it is produced. Part of enhancing the FSF version of GNAT
19418 to produce that information will be to put in place an indicator
19419 that we can use in order to determine whether the descriptive type
19420 info is available or not. One suggestion that has been made is
19421 to use a new attribute, attached to the CU die. For now, assume
19422 that the descriptive type info is not available. */
19426 /* Return the auxiliary type of the die in question using its
19427 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
19428 attribute is not present. */
19430 static struct type
*
19431 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19433 struct attribute
*type_attr
;
19435 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
19439 return lookup_die_type (die
, type_attr
, cu
);
19442 /* If DIE has a descriptive_type attribute, then set the TYPE's
19443 descriptive type accordingly. */
19446 set_descriptive_type (struct type
*type
, struct die_info
*die
,
19447 struct dwarf2_cu
*cu
)
19449 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
19451 if (descriptive_type
)
19453 ALLOCATE_GNAT_AUX_TYPE (type
);
19454 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
19458 /* Return the containing type of the die in question using its
19459 DW_AT_containing_type attribute. */
19461 static struct type
*
19462 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19464 struct attribute
*type_attr
;
19466 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
19468 error (_("Dwarf Error: Problem turning containing type into gdb type "
19469 "[in module %s]"), objfile_name (cu
->objfile
));
19471 return lookup_die_type (die
, type_attr
, cu
);
19474 /* Return an error marker type to use for the ill formed type in DIE/CU. */
19476 static struct type
*
19477 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
19479 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19480 char *message
, *saved
;
19482 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
19483 objfile_name (objfile
),
19484 cu
->header
.offset
.sect_off
,
19485 die
->offset
.sect_off
);
19486 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
19487 message
, strlen (message
));
19490 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
19493 /* Look up the type of DIE in CU using its type attribute ATTR.
19494 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
19495 DW_AT_containing_type.
19496 If there is no type substitute an error marker. */
19498 static struct type
*
19499 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
19500 struct dwarf2_cu
*cu
)
19502 struct objfile
*objfile
= cu
->objfile
;
19503 struct type
*this_type
;
19505 gdb_assert (attr
->name
== DW_AT_type
19506 || attr
->name
== DW_AT_GNAT_descriptive_type
19507 || attr
->name
== DW_AT_containing_type
);
19509 /* First see if we have it cached. */
19511 if (attr
->form
== DW_FORM_GNU_ref_alt
)
19513 struct dwarf2_per_cu_data
*per_cu
;
19514 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
19516 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
19517 this_type
= get_die_type_at_offset (offset
, per_cu
);
19519 else if (attr_form_is_ref (attr
))
19521 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
19523 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
19525 else if (attr
->form
== DW_FORM_ref_sig8
)
19527 ULONGEST signature
= DW_SIGNATURE (attr
);
19529 return get_signatured_type (die
, signature
, cu
);
19533 complaint (&symfile_complaints
,
19534 _("Dwarf Error: Bad type attribute %s in DIE"
19535 " at 0x%x [in module %s]"),
19536 dwarf_attr_name (attr
->name
), die
->offset
.sect_off
,
19537 objfile_name (objfile
));
19538 return build_error_marker_type (cu
, die
);
19541 /* If not cached we need to read it in. */
19543 if (this_type
== NULL
)
19545 struct die_info
*type_die
= NULL
;
19546 struct dwarf2_cu
*type_cu
= cu
;
19548 if (attr_form_is_ref (attr
))
19549 type_die
= follow_die_ref (die
, attr
, &type_cu
);
19550 if (type_die
== NULL
)
19551 return build_error_marker_type (cu
, die
);
19552 /* If we find the type now, it's probably because the type came
19553 from an inter-CU reference and the type's CU got expanded before
19555 this_type
= read_type_die (type_die
, type_cu
);
19558 /* If we still don't have a type use an error marker. */
19560 if (this_type
== NULL
)
19561 return build_error_marker_type (cu
, die
);
19566 /* Return the type in DIE, CU.
19567 Returns NULL for invalid types.
19569 This first does a lookup in die_type_hash,
19570 and only reads the die in if necessary.
19572 NOTE: This can be called when reading in partial or full symbols. */
19574 static struct type
*
19575 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
19577 struct type
*this_type
;
19579 this_type
= get_die_type (die
, cu
);
19583 return read_type_die_1 (die
, cu
);
19586 /* Read the type in DIE, CU.
19587 Returns NULL for invalid types. */
19589 static struct type
*
19590 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
19592 struct type
*this_type
= NULL
;
19596 case DW_TAG_class_type
:
19597 case DW_TAG_interface_type
:
19598 case DW_TAG_structure_type
:
19599 case DW_TAG_union_type
:
19600 this_type
= read_structure_type (die
, cu
);
19602 case DW_TAG_enumeration_type
:
19603 this_type
= read_enumeration_type (die
, cu
);
19605 case DW_TAG_subprogram
:
19606 case DW_TAG_subroutine_type
:
19607 case DW_TAG_inlined_subroutine
:
19608 this_type
= read_subroutine_type (die
, cu
);
19610 case DW_TAG_array_type
:
19611 this_type
= read_array_type (die
, cu
);
19613 case DW_TAG_set_type
:
19614 this_type
= read_set_type (die
, cu
);
19616 case DW_TAG_pointer_type
:
19617 this_type
= read_tag_pointer_type (die
, cu
);
19619 case DW_TAG_ptr_to_member_type
:
19620 this_type
= read_tag_ptr_to_member_type (die
, cu
);
19622 case DW_TAG_reference_type
:
19623 this_type
= read_tag_reference_type (die
, cu
);
19625 case DW_TAG_const_type
:
19626 this_type
= read_tag_const_type (die
, cu
);
19628 case DW_TAG_volatile_type
:
19629 this_type
= read_tag_volatile_type (die
, cu
);
19631 case DW_TAG_restrict_type
:
19632 this_type
= read_tag_restrict_type (die
, cu
);
19634 case DW_TAG_string_type
:
19635 this_type
= read_tag_string_type (die
, cu
);
19637 case DW_TAG_typedef
:
19638 this_type
= read_typedef (die
, cu
);
19640 case DW_TAG_subrange_type
:
19641 this_type
= read_subrange_type (die
, cu
);
19643 case DW_TAG_base_type
:
19644 this_type
= read_base_type (die
, cu
);
19646 case DW_TAG_unspecified_type
:
19647 this_type
= read_unspecified_type (die
, cu
);
19649 case DW_TAG_namespace
:
19650 this_type
= read_namespace_type (die
, cu
);
19652 case DW_TAG_module
:
19653 this_type
= read_module_type (die
, cu
);
19655 case DW_TAG_atomic_type
:
19656 this_type
= read_tag_atomic_type (die
, cu
);
19659 complaint (&symfile_complaints
,
19660 _("unexpected tag in read_type_die: '%s'"),
19661 dwarf_tag_name (die
->tag
));
19668 /* See if we can figure out if the class lives in a namespace. We do
19669 this by looking for a member function; its demangled name will
19670 contain namespace info, if there is any.
19671 Return the computed name or NULL.
19672 Space for the result is allocated on the objfile's obstack.
19673 This is the full-die version of guess_partial_die_structure_name.
19674 In this case we know DIE has no useful parent. */
19677 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19679 struct die_info
*spec_die
;
19680 struct dwarf2_cu
*spec_cu
;
19681 struct die_info
*child
;
19684 spec_die
= die_specification (die
, &spec_cu
);
19685 if (spec_die
!= NULL
)
19691 for (child
= die
->child
;
19693 child
= child
->sibling
)
19695 if (child
->tag
== DW_TAG_subprogram
)
19697 const char *linkage_name
;
19699 linkage_name
= dwarf2_string_attr (child
, DW_AT_linkage_name
, cu
);
19700 if (linkage_name
== NULL
)
19701 linkage_name
= dwarf2_string_attr (child
, DW_AT_MIPS_linkage_name
,
19703 if (linkage_name
!= NULL
)
19706 = language_class_name_from_physname (cu
->language_defn
,
19710 if (actual_name
!= NULL
)
19712 const char *die_name
= dwarf2_name (die
, cu
);
19714 if (die_name
!= NULL
19715 && strcmp (die_name
, actual_name
) != 0)
19717 /* Strip off the class name from the full name.
19718 We want the prefix. */
19719 int die_name_len
= strlen (die_name
);
19720 int actual_name_len
= strlen (actual_name
);
19722 /* Test for '::' as a sanity check. */
19723 if (actual_name_len
> die_name_len
+ 2
19724 && actual_name
[actual_name_len
19725 - die_name_len
- 1] == ':')
19726 name
= (char *) obstack_copy0 (
19727 &cu
->objfile
->per_bfd
->storage_obstack
,
19728 actual_name
, actual_name_len
- die_name_len
- 2);
19731 xfree (actual_name
);
19740 /* GCC might emit a nameless typedef that has a linkage name. Determine the
19741 prefix part in such case. See
19742 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19745 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19747 struct attribute
*attr
;
19750 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
19751 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
19754 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
19757 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
19759 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
19760 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
19763 /* dwarf2_name had to be already called. */
19764 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
19766 /* Strip the base name, keep any leading namespaces/classes. */
19767 base
= strrchr (DW_STRING (attr
), ':');
19768 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
19771 return (char *) obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
19773 &base
[-1] - DW_STRING (attr
));
19776 /* Return the name of the namespace/class that DIE is defined within,
19777 or "" if we can't tell. The caller should not xfree the result.
19779 For example, if we're within the method foo() in the following
19789 then determine_prefix on foo's die will return "N::C". */
19791 static const char *
19792 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19794 struct die_info
*parent
, *spec_die
;
19795 struct dwarf2_cu
*spec_cu
;
19796 struct type
*parent_type
;
19799 if (cu
->language
!= language_cplus
19800 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
19801 && cu
->language
!= language_rust
)
19804 retval
= anonymous_struct_prefix (die
, cu
);
19808 /* We have to be careful in the presence of DW_AT_specification.
19809 For example, with GCC 3.4, given the code
19813 // Definition of N::foo.
19817 then we'll have a tree of DIEs like this:
19819 1: DW_TAG_compile_unit
19820 2: DW_TAG_namespace // N
19821 3: DW_TAG_subprogram // declaration of N::foo
19822 4: DW_TAG_subprogram // definition of N::foo
19823 DW_AT_specification // refers to die #3
19825 Thus, when processing die #4, we have to pretend that we're in
19826 the context of its DW_AT_specification, namely the contex of die
19829 spec_die
= die_specification (die
, &spec_cu
);
19830 if (spec_die
== NULL
)
19831 parent
= die
->parent
;
19834 parent
= spec_die
->parent
;
19838 if (parent
== NULL
)
19840 else if (parent
->building_fullname
)
19843 const char *parent_name
;
19845 /* It has been seen on RealView 2.2 built binaries,
19846 DW_TAG_template_type_param types actually _defined_ as
19847 children of the parent class:
19850 template class <class Enum> Class{};
19851 Class<enum E> class_e;
19853 1: DW_TAG_class_type (Class)
19854 2: DW_TAG_enumeration_type (E)
19855 3: DW_TAG_enumerator (enum1:0)
19856 3: DW_TAG_enumerator (enum2:1)
19858 2: DW_TAG_template_type_param
19859 DW_AT_type DW_FORM_ref_udata (E)
19861 Besides being broken debug info, it can put GDB into an
19862 infinite loop. Consider:
19864 When we're building the full name for Class<E>, we'll start
19865 at Class, and go look over its template type parameters,
19866 finding E. We'll then try to build the full name of E, and
19867 reach here. We're now trying to build the full name of E,
19868 and look over the parent DIE for containing scope. In the
19869 broken case, if we followed the parent DIE of E, we'd again
19870 find Class, and once again go look at its template type
19871 arguments, etc., etc. Simply don't consider such parent die
19872 as source-level parent of this die (it can't be, the language
19873 doesn't allow it), and break the loop here. */
19874 name
= dwarf2_name (die
, cu
);
19875 parent_name
= dwarf2_name (parent
, cu
);
19876 complaint (&symfile_complaints
,
19877 _("template param type '%s' defined within parent '%s'"),
19878 name
? name
: "<unknown>",
19879 parent_name
? parent_name
: "<unknown>");
19883 switch (parent
->tag
)
19885 case DW_TAG_namespace
:
19886 parent_type
= read_type_die (parent
, cu
);
19887 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
19888 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
19889 Work around this problem here. */
19890 if (cu
->language
== language_cplus
19891 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
19893 /* We give a name to even anonymous namespaces. */
19894 return TYPE_TAG_NAME (parent_type
);
19895 case DW_TAG_class_type
:
19896 case DW_TAG_interface_type
:
19897 case DW_TAG_structure_type
:
19898 case DW_TAG_union_type
:
19899 case DW_TAG_module
:
19900 parent_type
= read_type_die (parent
, cu
);
19901 if (TYPE_TAG_NAME (parent_type
) != NULL
)
19902 return TYPE_TAG_NAME (parent_type
);
19904 /* An anonymous structure is only allowed non-static data
19905 members; no typedefs, no member functions, et cetera.
19906 So it does not need a prefix. */
19908 case DW_TAG_compile_unit
:
19909 case DW_TAG_partial_unit
:
19910 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
19911 if (cu
->language
== language_cplus
19912 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
19913 && die
->child
!= NULL
19914 && (die
->tag
== DW_TAG_class_type
19915 || die
->tag
== DW_TAG_structure_type
19916 || die
->tag
== DW_TAG_union_type
))
19918 char *name
= guess_full_die_structure_name (die
, cu
);
19923 case DW_TAG_enumeration_type
:
19924 parent_type
= read_type_die (parent
, cu
);
19925 if (TYPE_DECLARED_CLASS (parent_type
))
19927 if (TYPE_TAG_NAME (parent_type
) != NULL
)
19928 return TYPE_TAG_NAME (parent_type
);
19931 /* Fall through. */
19933 return determine_prefix (parent
, cu
);
19937 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
19938 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
19939 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
19940 an obconcat, otherwise allocate storage for the result. The CU argument is
19941 used to determine the language and hence, the appropriate separator. */
19943 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
19946 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
19947 int physname
, struct dwarf2_cu
*cu
)
19949 const char *lead
= "";
19952 if (suffix
== NULL
|| suffix
[0] == '\0'
19953 || prefix
== NULL
|| prefix
[0] == '\0')
19955 else if (cu
->language
== language_d
)
19957 /* For D, the 'main' function could be defined in any module, but it
19958 should never be prefixed. */
19959 if (strcmp (suffix
, "D main") == 0)
19967 else if (cu
->language
== language_fortran
&& physname
)
19969 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
19970 DW_AT_MIPS_linkage_name is preferred and used instead. */
19978 if (prefix
== NULL
)
19980 if (suffix
== NULL
)
19987 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
19989 strcpy (retval
, lead
);
19990 strcat (retval
, prefix
);
19991 strcat (retval
, sep
);
19992 strcat (retval
, suffix
);
19997 /* We have an obstack. */
19998 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
20002 /* Return sibling of die, NULL if no sibling. */
20004 static struct die_info
*
20005 sibling_die (struct die_info
*die
)
20007 return die
->sibling
;
20010 /* Get name of a die, return NULL if not found. */
20012 static const char *
20013 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
20014 struct obstack
*obstack
)
20016 if (name
&& cu
->language
== language_cplus
)
20018 std::string canon_name
= cp_canonicalize_string (name
);
20020 if (!canon_name
.empty ())
20022 if (canon_name
!= name
)
20023 name
= (const char *) obstack_copy0 (obstack
,
20024 canon_name
.c_str (),
20025 canon_name
.length ());
20032 /* Get name of a die, return NULL if not found.
20033 Anonymous namespaces are converted to their magic string. */
20035 static const char *
20036 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20038 struct attribute
*attr
;
20040 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
20041 if ((!attr
|| !DW_STRING (attr
))
20042 && die
->tag
!= DW_TAG_namespace
20043 && die
->tag
!= DW_TAG_class_type
20044 && die
->tag
!= DW_TAG_interface_type
20045 && die
->tag
!= DW_TAG_structure_type
20046 && die
->tag
!= DW_TAG_union_type
)
20051 case DW_TAG_compile_unit
:
20052 case DW_TAG_partial_unit
:
20053 /* Compilation units have a DW_AT_name that is a filename, not
20054 a source language identifier. */
20055 case DW_TAG_enumeration_type
:
20056 case DW_TAG_enumerator
:
20057 /* These tags always have simple identifiers already; no need
20058 to canonicalize them. */
20059 return DW_STRING (attr
);
20061 case DW_TAG_namespace
:
20062 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
20063 return DW_STRING (attr
);
20064 return CP_ANONYMOUS_NAMESPACE_STR
;
20066 case DW_TAG_class_type
:
20067 case DW_TAG_interface_type
:
20068 case DW_TAG_structure_type
:
20069 case DW_TAG_union_type
:
20070 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
20071 structures or unions. These were of the form "._%d" in GCC 4.1,
20072 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
20073 and GCC 4.4. We work around this problem by ignoring these. */
20074 if (attr
&& DW_STRING (attr
)
20075 && (startswith (DW_STRING (attr
), "._")
20076 || startswith (DW_STRING (attr
), "<anonymous")))
20079 /* GCC might emit a nameless typedef that has a linkage name. See
20080 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20081 if (!attr
|| DW_STRING (attr
) == NULL
)
20083 char *demangled
= NULL
;
20085 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
20087 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
20089 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
20092 /* Avoid demangling DW_STRING (attr) the second time on a second
20093 call for the same DIE. */
20094 if (!DW_STRING_IS_CANONICAL (attr
))
20095 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
20101 /* FIXME: we already did this for the partial symbol... */
20104 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
20105 demangled
, strlen (demangled
)));
20106 DW_STRING_IS_CANONICAL (attr
) = 1;
20109 /* Strip any leading namespaces/classes, keep only the base name.
20110 DW_AT_name for named DIEs does not contain the prefixes. */
20111 base
= strrchr (DW_STRING (attr
), ':');
20112 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
20115 return DW_STRING (attr
);
20124 if (!DW_STRING_IS_CANONICAL (attr
))
20127 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
20128 &cu
->objfile
->per_bfd
->storage_obstack
);
20129 DW_STRING_IS_CANONICAL (attr
) = 1;
20131 return DW_STRING (attr
);
20134 /* Return the die that this die in an extension of, or NULL if there
20135 is none. *EXT_CU is the CU containing DIE on input, and the CU
20136 containing the return value on output. */
20138 static struct die_info
*
20139 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
20141 struct attribute
*attr
;
20143 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
20147 return follow_die_ref (die
, attr
, ext_cu
);
20150 /* Convert a DIE tag into its string name. */
20152 static const char *
20153 dwarf_tag_name (unsigned tag
)
20155 const char *name
= get_DW_TAG_name (tag
);
20158 return "DW_TAG_<unknown>";
20163 /* Convert a DWARF attribute code into its string name. */
20165 static const char *
20166 dwarf_attr_name (unsigned attr
)
20170 #ifdef MIPS /* collides with DW_AT_HP_block_index */
20171 if (attr
== DW_AT_MIPS_fde
)
20172 return "DW_AT_MIPS_fde";
20174 if (attr
== DW_AT_HP_block_index
)
20175 return "DW_AT_HP_block_index";
20178 name
= get_DW_AT_name (attr
);
20181 return "DW_AT_<unknown>";
20186 /* Convert a DWARF value form code into its string name. */
20188 static const char *
20189 dwarf_form_name (unsigned form
)
20191 const char *name
= get_DW_FORM_name (form
);
20194 return "DW_FORM_<unknown>";
20200 dwarf_bool_name (unsigned mybool
)
20208 /* Convert a DWARF type code into its string name. */
20210 static const char *
20211 dwarf_type_encoding_name (unsigned enc
)
20213 const char *name
= get_DW_ATE_name (enc
);
20216 return "DW_ATE_<unknown>";
20222 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
20226 print_spaces (indent
, f
);
20227 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
20228 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
20230 if (die
->parent
!= NULL
)
20232 print_spaces (indent
, f
);
20233 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
20234 die
->parent
->offset
.sect_off
);
20237 print_spaces (indent
, f
);
20238 fprintf_unfiltered (f
, " has children: %s\n",
20239 dwarf_bool_name (die
->child
!= NULL
));
20241 print_spaces (indent
, f
);
20242 fprintf_unfiltered (f
, " attributes:\n");
20244 for (i
= 0; i
< die
->num_attrs
; ++i
)
20246 print_spaces (indent
, f
);
20247 fprintf_unfiltered (f
, " %s (%s) ",
20248 dwarf_attr_name (die
->attrs
[i
].name
),
20249 dwarf_form_name (die
->attrs
[i
].form
));
20251 switch (die
->attrs
[i
].form
)
20254 case DW_FORM_GNU_addr_index
:
20255 fprintf_unfiltered (f
, "address: ");
20256 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
20258 case DW_FORM_block2
:
20259 case DW_FORM_block4
:
20260 case DW_FORM_block
:
20261 case DW_FORM_block1
:
20262 fprintf_unfiltered (f
, "block: size %s",
20263 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
20265 case DW_FORM_exprloc
:
20266 fprintf_unfiltered (f
, "expression: size %s",
20267 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
20269 case DW_FORM_data16
:
20270 fprintf_unfiltered (f
, "constant of 16 bytes");
20272 case DW_FORM_ref_addr
:
20273 fprintf_unfiltered (f
, "ref address: ");
20274 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
20276 case DW_FORM_GNU_ref_alt
:
20277 fprintf_unfiltered (f
, "alt ref address: ");
20278 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
20284 case DW_FORM_ref_udata
:
20285 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
20286 (long) (DW_UNSND (&die
->attrs
[i
])));
20288 case DW_FORM_data1
:
20289 case DW_FORM_data2
:
20290 case DW_FORM_data4
:
20291 case DW_FORM_data8
:
20292 case DW_FORM_udata
:
20293 case DW_FORM_sdata
:
20294 fprintf_unfiltered (f
, "constant: %s",
20295 pulongest (DW_UNSND (&die
->attrs
[i
])));
20297 case DW_FORM_sec_offset
:
20298 fprintf_unfiltered (f
, "section offset: %s",
20299 pulongest (DW_UNSND (&die
->attrs
[i
])));
20301 case DW_FORM_ref_sig8
:
20302 fprintf_unfiltered (f
, "signature: %s",
20303 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
20305 case DW_FORM_string
:
20307 case DW_FORM_line_strp
:
20308 case DW_FORM_GNU_str_index
:
20309 case DW_FORM_GNU_strp_alt
:
20310 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
20311 DW_STRING (&die
->attrs
[i
])
20312 ? DW_STRING (&die
->attrs
[i
]) : "",
20313 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
20316 if (DW_UNSND (&die
->attrs
[i
]))
20317 fprintf_unfiltered (f
, "flag: TRUE");
20319 fprintf_unfiltered (f
, "flag: FALSE");
20321 case DW_FORM_flag_present
:
20322 fprintf_unfiltered (f
, "flag: TRUE");
20324 case DW_FORM_indirect
:
20325 /* The reader will have reduced the indirect form to
20326 the "base form" so this form should not occur. */
20327 fprintf_unfiltered (f
,
20328 "unexpected attribute form: DW_FORM_indirect");
20331 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
20332 die
->attrs
[i
].form
);
20335 fprintf_unfiltered (f
, "\n");
20340 dump_die_for_error (struct die_info
*die
)
20342 dump_die_shallow (gdb_stderr
, 0, die
);
20346 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
20348 int indent
= level
* 4;
20350 gdb_assert (die
!= NULL
);
20352 if (level
>= max_level
)
20355 dump_die_shallow (f
, indent
, die
);
20357 if (die
->child
!= NULL
)
20359 print_spaces (indent
, f
);
20360 fprintf_unfiltered (f
, " Children:");
20361 if (level
+ 1 < max_level
)
20363 fprintf_unfiltered (f
, "\n");
20364 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
20368 fprintf_unfiltered (f
,
20369 " [not printed, max nesting level reached]\n");
20373 if (die
->sibling
!= NULL
&& level
> 0)
20375 dump_die_1 (f
, level
, max_level
, die
->sibling
);
20379 /* This is called from the pdie macro in gdbinit.in.
20380 It's not static so gcc will keep a copy callable from gdb. */
20383 dump_die (struct die_info
*die
, int max_level
)
20385 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
20389 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
20393 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
20399 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
20403 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
20405 sect_offset retval
= { DW_UNSND (attr
) };
20407 if (attr_form_is_ref (attr
))
20410 retval
.sect_off
= 0;
20411 complaint (&symfile_complaints
,
20412 _("unsupported die ref attribute form: '%s'"),
20413 dwarf_form_name (attr
->form
));
20417 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
20418 * the value held by the attribute is not constant. */
20421 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
20423 if (attr
->form
== DW_FORM_sdata
)
20424 return DW_SND (attr
);
20425 else if (attr
->form
== DW_FORM_udata
20426 || attr
->form
== DW_FORM_data1
20427 || attr
->form
== DW_FORM_data2
20428 || attr
->form
== DW_FORM_data4
20429 || attr
->form
== DW_FORM_data8
)
20430 return DW_UNSND (attr
);
20433 /* For DW_FORM_data16 see attr_form_is_constant. */
20434 complaint (&symfile_complaints
,
20435 _("Attribute value is not a constant (%s)"),
20436 dwarf_form_name (attr
->form
));
20437 return default_value
;
20441 /* Follow reference or signature attribute ATTR of SRC_DIE.
20442 On entry *REF_CU is the CU of SRC_DIE.
20443 On exit *REF_CU is the CU of the result. */
20445 static struct die_info
*
20446 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20447 struct dwarf2_cu
**ref_cu
)
20449 struct die_info
*die
;
20451 if (attr_form_is_ref (attr
))
20452 die
= follow_die_ref (src_die
, attr
, ref_cu
);
20453 else if (attr
->form
== DW_FORM_ref_sig8
)
20454 die
= follow_die_sig (src_die
, attr
, ref_cu
);
20457 dump_die_for_error (src_die
);
20458 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
20459 objfile_name ((*ref_cu
)->objfile
));
20465 /* Follow reference OFFSET.
20466 On entry *REF_CU is the CU of the source die referencing OFFSET.
20467 On exit *REF_CU is the CU of the result.
20468 Returns NULL if OFFSET is invalid. */
20470 static struct die_info
*
20471 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
20472 struct dwarf2_cu
**ref_cu
)
20474 struct die_info temp_die
;
20475 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
20477 gdb_assert (cu
->per_cu
!= NULL
);
20481 if (cu
->per_cu
->is_debug_types
)
20483 /* .debug_types CUs cannot reference anything outside their CU.
20484 If they need to, they have to reference a signatured type via
20485 DW_FORM_ref_sig8. */
20486 if (! offset_in_cu_p (&cu
->header
, offset
))
20489 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
20490 || ! offset_in_cu_p (&cu
->header
, offset
))
20492 struct dwarf2_per_cu_data
*per_cu
;
20494 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
20497 /* If necessary, add it to the queue and load its DIEs. */
20498 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
20499 load_full_comp_unit (per_cu
, cu
->language
);
20501 target_cu
= per_cu
->cu
;
20503 else if (cu
->dies
== NULL
)
20505 /* We're loading full DIEs during partial symbol reading. */
20506 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
20507 load_full_comp_unit (cu
->per_cu
, language_minimal
);
20510 *ref_cu
= target_cu
;
20511 temp_die
.offset
= offset
;
20512 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
20513 &temp_die
, offset
.sect_off
);
20516 /* Follow reference attribute ATTR of SRC_DIE.
20517 On entry *REF_CU is the CU of SRC_DIE.
20518 On exit *REF_CU is the CU of the result. */
20520 static struct die_info
*
20521 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
20522 struct dwarf2_cu
**ref_cu
)
20524 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
20525 struct dwarf2_cu
*cu
= *ref_cu
;
20526 struct die_info
*die
;
20528 die
= follow_die_offset (offset
,
20529 (attr
->form
== DW_FORM_GNU_ref_alt
20530 || cu
->per_cu
->is_dwz
),
20533 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
20534 "at 0x%x [in module %s]"),
20535 offset
.sect_off
, src_die
->offset
.sect_off
,
20536 objfile_name (cu
->objfile
));
20541 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
20542 Returned value is intended for DW_OP_call*. Returned
20543 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
20545 struct dwarf2_locexpr_baton
20546 dwarf2_fetch_die_loc_sect_off (sect_offset offset
,
20547 struct dwarf2_per_cu_data
*per_cu
,
20548 CORE_ADDR (*get_frame_pc
) (void *baton
),
20551 struct dwarf2_cu
*cu
;
20552 struct die_info
*die
;
20553 struct attribute
*attr
;
20554 struct dwarf2_locexpr_baton retval
;
20556 dw2_setup (per_cu
->objfile
);
20558 if (per_cu
->cu
== NULL
)
20563 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20564 Instead just throw an error, not much else we can do. */
20565 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
20566 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20569 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
20571 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
20572 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20574 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20577 /* DWARF: "If there is no such attribute, then there is no effect.".
20578 DATA is ignored if SIZE is 0. */
20580 retval
.data
= NULL
;
20583 else if (attr_form_is_section_offset (attr
))
20585 struct dwarf2_loclist_baton loclist_baton
;
20586 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
20589 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
20591 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
20593 retval
.size
= size
;
20597 if (!attr_form_is_block (attr
))
20598 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
20599 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
20600 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20602 retval
.data
= DW_BLOCK (attr
)->data
;
20603 retval
.size
= DW_BLOCK (attr
)->size
;
20605 retval
.per_cu
= cu
->per_cu
;
20607 age_cached_comp_units ();
20612 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
20615 struct dwarf2_locexpr_baton
20616 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
20617 struct dwarf2_per_cu_data
*per_cu
,
20618 CORE_ADDR (*get_frame_pc
) (void *baton
),
20621 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
20623 return dwarf2_fetch_die_loc_sect_off (offset
, per_cu
, get_frame_pc
, baton
);
20626 /* Write a constant of a given type as target-ordered bytes into
20629 static const gdb_byte
*
20630 write_constant_as_bytes (struct obstack
*obstack
,
20631 enum bfd_endian byte_order
,
20638 *len
= TYPE_LENGTH (type
);
20639 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20640 store_unsigned_integer (result
, *len
, byte_order
, value
);
20645 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
20646 pointer to the constant bytes and set LEN to the length of the
20647 data. If memory is needed, allocate it on OBSTACK. If the DIE
20648 does not have a DW_AT_const_value, return NULL. */
20651 dwarf2_fetch_constant_bytes (sect_offset offset
,
20652 struct dwarf2_per_cu_data
*per_cu
,
20653 struct obstack
*obstack
,
20656 struct dwarf2_cu
*cu
;
20657 struct die_info
*die
;
20658 struct attribute
*attr
;
20659 const gdb_byte
*result
= NULL
;
20662 enum bfd_endian byte_order
;
20664 dw2_setup (per_cu
->objfile
);
20666 if (per_cu
->cu
== NULL
)
20671 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20672 Instead just throw an error, not much else we can do. */
20673 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
20674 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20677 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
20679 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
20680 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20683 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20687 byte_order
= (bfd_big_endian (per_cu
->objfile
->obfd
)
20688 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20690 switch (attr
->form
)
20693 case DW_FORM_GNU_addr_index
:
20697 *len
= cu
->header
.addr_size
;
20698 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20699 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
20703 case DW_FORM_string
:
20705 case DW_FORM_GNU_str_index
:
20706 case DW_FORM_GNU_strp_alt
:
20707 /* DW_STRING is already allocated on the objfile obstack, point
20709 result
= (const gdb_byte
*) DW_STRING (attr
);
20710 *len
= strlen (DW_STRING (attr
));
20712 case DW_FORM_block1
:
20713 case DW_FORM_block2
:
20714 case DW_FORM_block4
:
20715 case DW_FORM_block
:
20716 case DW_FORM_exprloc
:
20717 case DW_FORM_data16
:
20718 result
= DW_BLOCK (attr
)->data
;
20719 *len
= DW_BLOCK (attr
)->size
;
20722 /* The DW_AT_const_value attributes are supposed to carry the
20723 symbol's value "represented as it would be on the target
20724 architecture." By the time we get here, it's already been
20725 converted to host endianness, so we just need to sign- or
20726 zero-extend it as appropriate. */
20727 case DW_FORM_data1
:
20728 type
= die_type (die
, cu
);
20729 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
20730 if (result
== NULL
)
20731 result
= write_constant_as_bytes (obstack
, byte_order
,
20734 case DW_FORM_data2
:
20735 type
= die_type (die
, cu
);
20736 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
20737 if (result
== NULL
)
20738 result
= write_constant_as_bytes (obstack
, byte_order
,
20741 case DW_FORM_data4
:
20742 type
= die_type (die
, cu
);
20743 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
20744 if (result
== NULL
)
20745 result
= write_constant_as_bytes (obstack
, byte_order
,
20748 case DW_FORM_data8
:
20749 type
= die_type (die
, cu
);
20750 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
20751 if (result
== NULL
)
20752 result
= write_constant_as_bytes (obstack
, byte_order
,
20756 case DW_FORM_sdata
:
20757 type
= die_type (die
, cu
);
20758 result
= write_constant_as_bytes (obstack
, byte_order
,
20759 type
, DW_SND (attr
), len
);
20762 case DW_FORM_udata
:
20763 type
= die_type (die
, cu
);
20764 result
= write_constant_as_bytes (obstack
, byte_order
,
20765 type
, DW_UNSND (attr
), len
);
20769 complaint (&symfile_complaints
,
20770 _("unsupported const value attribute form: '%s'"),
20771 dwarf_form_name (attr
->form
));
20778 /* Return the type of the DIE at DIE_OFFSET in the CU named by
20782 dwarf2_get_die_type (cu_offset die_offset
,
20783 struct dwarf2_per_cu_data
*per_cu
)
20785 sect_offset die_offset_sect
;
20787 dw2_setup (per_cu
->objfile
);
20789 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
20790 return get_die_type_at_offset (die_offset_sect
, per_cu
);
20793 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
20794 On entry *REF_CU is the CU of SRC_DIE.
20795 On exit *REF_CU is the CU of the result.
20796 Returns NULL if the referenced DIE isn't found. */
20798 static struct die_info
*
20799 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
20800 struct dwarf2_cu
**ref_cu
)
20802 struct die_info temp_die
;
20803 struct dwarf2_cu
*sig_cu
;
20804 struct die_info
*die
;
20806 /* While it might be nice to assert sig_type->type == NULL here,
20807 we can get here for DW_AT_imported_declaration where we need
20808 the DIE not the type. */
20810 /* If necessary, add it to the queue and load its DIEs. */
20812 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
20813 read_signatured_type (sig_type
);
20815 sig_cu
= sig_type
->per_cu
.cu
;
20816 gdb_assert (sig_cu
!= NULL
);
20817 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
20818 temp_die
.offset
= sig_type
->type_offset_in_section
;
20819 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
20820 temp_die
.offset
.sect_off
);
20823 /* For .gdb_index version 7 keep track of included TUs.
20824 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
20825 if (dwarf2_per_objfile
->index_table
!= NULL
20826 && dwarf2_per_objfile
->index_table
->version
<= 7)
20828 VEC_safe_push (dwarf2_per_cu_ptr
,
20829 (*ref_cu
)->per_cu
->imported_symtabs
,
20840 /* Follow signatured type referenced by ATTR in SRC_DIE.
20841 On entry *REF_CU is the CU of SRC_DIE.
20842 On exit *REF_CU is the CU of the result.
20843 The result is the DIE of the type.
20844 If the referenced type cannot be found an error is thrown. */
20846 static struct die_info
*
20847 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20848 struct dwarf2_cu
**ref_cu
)
20850 ULONGEST signature
= DW_SIGNATURE (attr
);
20851 struct signatured_type
*sig_type
;
20852 struct die_info
*die
;
20854 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
20856 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
20857 /* sig_type will be NULL if the signatured type is missing from
20859 if (sig_type
== NULL
)
20861 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
20862 " from DIE at 0x%x [in module %s]"),
20863 hex_string (signature
), src_die
->offset
.sect_off
,
20864 objfile_name ((*ref_cu
)->objfile
));
20867 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
20870 dump_die_for_error (src_die
);
20871 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
20872 " from DIE at 0x%x [in module %s]"),
20873 hex_string (signature
), src_die
->offset
.sect_off
,
20874 objfile_name ((*ref_cu
)->objfile
));
20880 /* Get the type specified by SIGNATURE referenced in DIE/CU,
20881 reading in and processing the type unit if necessary. */
20883 static struct type
*
20884 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
20885 struct dwarf2_cu
*cu
)
20887 struct signatured_type
*sig_type
;
20888 struct dwarf2_cu
*type_cu
;
20889 struct die_info
*type_die
;
20892 sig_type
= lookup_signatured_type (cu
, signature
);
20893 /* sig_type will be NULL if the signatured type is missing from
20895 if (sig_type
== NULL
)
20897 complaint (&symfile_complaints
,
20898 _("Dwarf Error: Cannot find signatured DIE %s referenced"
20899 " from DIE at 0x%x [in module %s]"),
20900 hex_string (signature
), die
->offset
.sect_off
,
20901 objfile_name (dwarf2_per_objfile
->objfile
));
20902 return build_error_marker_type (cu
, die
);
20905 /* If we already know the type we're done. */
20906 if (sig_type
->type
!= NULL
)
20907 return sig_type
->type
;
20910 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
20911 if (type_die
!= NULL
)
20913 /* N.B. We need to call get_die_type to ensure only one type for this DIE
20914 is created. This is important, for example, because for c++ classes
20915 we need TYPE_NAME set which is only done by new_symbol. Blech. */
20916 type
= read_type_die (type_die
, type_cu
);
20919 complaint (&symfile_complaints
,
20920 _("Dwarf Error: Cannot build signatured type %s"
20921 " referenced from DIE at 0x%x [in module %s]"),
20922 hex_string (signature
), die
->offset
.sect_off
,
20923 objfile_name (dwarf2_per_objfile
->objfile
));
20924 type
= build_error_marker_type (cu
, die
);
20929 complaint (&symfile_complaints
,
20930 _("Dwarf Error: Problem reading signatured DIE %s referenced"
20931 " from DIE at 0x%x [in module %s]"),
20932 hex_string (signature
), die
->offset
.sect_off
,
20933 objfile_name (dwarf2_per_objfile
->objfile
));
20934 type
= build_error_marker_type (cu
, die
);
20936 sig_type
->type
= type
;
20941 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
20942 reading in and processing the type unit if necessary. */
20944 static struct type
*
20945 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
20946 struct dwarf2_cu
*cu
) /* ARI: editCase function */
20948 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
20949 if (attr_form_is_ref (attr
))
20951 struct dwarf2_cu
*type_cu
= cu
;
20952 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
20954 return read_type_die (type_die
, type_cu
);
20956 else if (attr
->form
== DW_FORM_ref_sig8
)
20958 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
20962 complaint (&symfile_complaints
,
20963 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
20964 " at 0x%x [in module %s]"),
20965 dwarf_form_name (attr
->form
), die
->offset
.sect_off
,
20966 objfile_name (dwarf2_per_objfile
->objfile
));
20967 return build_error_marker_type (cu
, die
);
20971 /* Load the DIEs associated with type unit PER_CU into memory. */
20974 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
20976 struct signatured_type
*sig_type
;
20978 /* Caller is responsible for ensuring type_unit_groups don't get here. */
20979 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
20981 /* We have the per_cu, but we need the signatured_type.
20982 Fortunately this is an easy translation. */
20983 gdb_assert (per_cu
->is_debug_types
);
20984 sig_type
= (struct signatured_type
*) per_cu
;
20986 gdb_assert (per_cu
->cu
== NULL
);
20988 read_signatured_type (sig_type
);
20990 gdb_assert (per_cu
->cu
!= NULL
);
20993 /* die_reader_func for read_signatured_type.
20994 This is identical to load_full_comp_unit_reader,
20995 but is kept separate for now. */
20998 read_signatured_type_reader (const struct die_reader_specs
*reader
,
20999 const gdb_byte
*info_ptr
,
21000 struct die_info
*comp_unit_die
,
21004 struct dwarf2_cu
*cu
= reader
->cu
;
21006 gdb_assert (cu
->die_hash
== NULL
);
21008 htab_create_alloc_ex (cu
->header
.length
/ 12,
21012 &cu
->comp_unit_obstack
,
21013 hashtab_obstack_allocate
,
21014 dummy_obstack_deallocate
);
21017 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
21018 &info_ptr
, comp_unit_die
);
21019 cu
->dies
= comp_unit_die
;
21020 /* comp_unit_die is not stored in die_hash, no need. */
21022 /* We try not to read any attributes in this function, because not
21023 all CUs needed for references have been loaded yet, and symbol
21024 table processing isn't initialized. But we have to set the CU language,
21025 or we won't be able to build types correctly.
21026 Similarly, if we do not read the producer, we can not apply
21027 producer-specific interpretation. */
21028 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
21031 /* Read in a signatured type and build its CU and DIEs.
21032 If the type is a stub for the real type in a DWO file,
21033 read in the real type from the DWO file as well. */
21036 read_signatured_type (struct signatured_type
*sig_type
)
21038 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
21040 gdb_assert (per_cu
->is_debug_types
);
21041 gdb_assert (per_cu
->cu
== NULL
);
21043 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
21044 read_signatured_type_reader
, NULL
);
21045 sig_type
->per_cu
.tu_read
= 1;
21048 /* Decode simple location descriptions.
21049 Given a pointer to a dwarf block that defines a location, compute
21050 the location and return the value.
21052 NOTE drow/2003-11-18: This function is called in two situations
21053 now: for the address of static or global variables (partial symbols
21054 only) and for offsets into structures which are expected to be
21055 (more or less) constant. The partial symbol case should go away,
21056 and only the constant case should remain. That will let this
21057 function complain more accurately. A few special modes are allowed
21058 without complaint for global variables (for instance, global
21059 register values and thread-local values).
21061 A location description containing no operations indicates that the
21062 object is optimized out. The return value is 0 for that case.
21063 FIXME drow/2003-11-16: No callers check for this case any more; soon all
21064 callers will only want a very basic result and this can become a
21067 Note that stack[0] is unused except as a default error return. */
21070 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
21072 struct objfile
*objfile
= cu
->objfile
;
21074 size_t size
= blk
->size
;
21075 const gdb_byte
*data
= blk
->data
;
21076 CORE_ADDR stack
[64];
21078 unsigned int bytes_read
, unsnd
;
21084 stack
[++stacki
] = 0;
21123 stack
[++stacki
] = op
- DW_OP_lit0
;
21158 stack
[++stacki
] = op
- DW_OP_reg0
;
21160 dwarf2_complex_location_expr_complaint ();
21164 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
21166 stack
[++stacki
] = unsnd
;
21168 dwarf2_complex_location_expr_complaint ();
21172 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
21177 case DW_OP_const1u
:
21178 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
21182 case DW_OP_const1s
:
21183 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
21187 case DW_OP_const2u
:
21188 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
21192 case DW_OP_const2s
:
21193 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
21197 case DW_OP_const4u
:
21198 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
21202 case DW_OP_const4s
:
21203 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
21207 case DW_OP_const8u
:
21208 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
21213 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
21219 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
21224 stack
[stacki
+ 1] = stack
[stacki
];
21229 stack
[stacki
- 1] += stack
[stacki
];
21233 case DW_OP_plus_uconst
:
21234 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
21240 stack
[stacki
- 1] -= stack
[stacki
];
21245 /* If we're not the last op, then we definitely can't encode
21246 this using GDB's address_class enum. This is valid for partial
21247 global symbols, although the variable's address will be bogus
21250 dwarf2_complex_location_expr_complaint ();
21253 case DW_OP_GNU_push_tls_address
:
21254 case DW_OP_form_tls_address
:
21255 /* The top of the stack has the offset from the beginning
21256 of the thread control block at which the variable is located. */
21257 /* Nothing should follow this operator, so the top of stack would
21259 /* This is valid for partial global symbols, but the variable's
21260 address will be bogus in the psymtab. Make it always at least
21261 non-zero to not look as a variable garbage collected by linker
21262 which have DW_OP_addr 0. */
21264 dwarf2_complex_location_expr_complaint ();
21268 case DW_OP_GNU_uninit
:
21271 case DW_OP_GNU_addr_index
:
21272 case DW_OP_GNU_const_index
:
21273 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
21280 const char *name
= get_DW_OP_name (op
);
21283 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
21286 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
21290 return (stack
[stacki
]);
21293 /* Enforce maximum stack depth of SIZE-1 to avoid writing
21294 outside of the allocated space. Also enforce minimum>0. */
21295 if (stacki
>= ARRAY_SIZE (stack
) - 1)
21297 complaint (&symfile_complaints
,
21298 _("location description stack overflow"));
21304 complaint (&symfile_complaints
,
21305 _("location description stack underflow"));
21309 return (stack
[stacki
]);
21312 /* memory allocation interface */
21314 static struct dwarf_block
*
21315 dwarf_alloc_block (struct dwarf2_cu
*cu
)
21317 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
21320 static struct die_info
*
21321 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
21323 struct die_info
*die
;
21324 size_t size
= sizeof (struct die_info
);
21327 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
21329 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
21330 memset (die
, 0, sizeof (struct die_info
));
21335 /* Macro support. */
21337 /* Return file name relative to the compilation directory of file number I in
21338 *LH's file name table. The result is allocated using xmalloc; the caller is
21339 responsible for freeing it. */
21342 file_file_name (int file
, struct line_header
*lh
)
21344 /* Is the file number a valid index into the line header's file name
21345 table? Remember that file numbers start with one, not zero. */
21346 if (1 <= file
&& file
<= lh
->num_file_names
)
21348 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
21350 if (IS_ABSOLUTE_PATH (fe
->name
) || fe
->dir_index
== 0
21351 || lh
->include_dirs
== NULL
)
21352 return xstrdup (fe
->name
);
21353 return concat (lh
->include_dirs
[fe
->dir_index
- 1], SLASH_STRING
,
21354 fe
->name
, (char *) NULL
);
21358 /* The compiler produced a bogus file number. We can at least
21359 record the macro definitions made in the file, even if we
21360 won't be able to find the file by name. */
21361 char fake_name
[80];
21363 xsnprintf (fake_name
, sizeof (fake_name
),
21364 "<bad macro file number %d>", file
);
21366 complaint (&symfile_complaints
,
21367 _("bad file number in macro information (%d)"),
21370 return xstrdup (fake_name
);
21374 /* Return the full name of file number I in *LH's file name table.
21375 Use COMP_DIR as the name of the current directory of the
21376 compilation. The result is allocated using xmalloc; the caller is
21377 responsible for freeing it. */
21379 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
21381 /* Is the file number a valid index into the line header's file name
21382 table? Remember that file numbers start with one, not zero. */
21383 if (1 <= file
&& file
<= lh
->num_file_names
)
21385 char *relative
= file_file_name (file
, lh
);
21387 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
21389 return reconcat (relative
, comp_dir
, SLASH_STRING
,
21390 relative
, (char *) NULL
);
21393 return file_file_name (file
, lh
);
21397 static struct macro_source_file
*
21398 macro_start_file (int file
, int line
,
21399 struct macro_source_file
*current_file
,
21400 struct line_header
*lh
)
21402 /* File name relative to the compilation directory of this source file. */
21403 char *file_name
= file_file_name (file
, lh
);
21405 if (! current_file
)
21407 /* Note: We don't create a macro table for this compilation unit
21408 at all until we actually get a filename. */
21409 struct macro_table
*macro_table
= get_macro_table ();
21411 /* If we have no current file, then this must be the start_file
21412 directive for the compilation unit's main source file. */
21413 current_file
= macro_set_main (macro_table
, file_name
);
21414 macro_define_special (macro_table
);
21417 current_file
= macro_include (current_file
, line
, file_name
);
21421 return current_file
;
21425 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
21426 followed by a null byte. */
21428 copy_string (const char *buf
, int len
)
21430 char *s
= (char *) xmalloc (len
+ 1);
21432 memcpy (s
, buf
, len
);
21438 static const char *
21439 consume_improper_spaces (const char *p
, const char *body
)
21443 complaint (&symfile_complaints
,
21444 _("macro definition contains spaces "
21445 "in formal argument list:\n`%s'"),
21457 parse_macro_definition (struct macro_source_file
*file
, int line
,
21462 /* The body string takes one of two forms. For object-like macro
21463 definitions, it should be:
21465 <macro name> " " <definition>
21467 For function-like macro definitions, it should be:
21469 <macro name> "() " <definition>
21471 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
21473 Spaces may appear only where explicitly indicated, and in the
21476 The Dwarf 2 spec says that an object-like macro's name is always
21477 followed by a space, but versions of GCC around March 2002 omit
21478 the space when the macro's definition is the empty string.
21480 The Dwarf 2 spec says that there should be no spaces between the
21481 formal arguments in a function-like macro's formal argument list,
21482 but versions of GCC around March 2002 include spaces after the
21486 /* Find the extent of the macro name. The macro name is terminated
21487 by either a space or null character (for an object-like macro) or
21488 an opening paren (for a function-like macro). */
21489 for (p
= body
; *p
; p
++)
21490 if (*p
== ' ' || *p
== '(')
21493 if (*p
== ' ' || *p
== '\0')
21495 /* It's an object-like macro. */
21496 int name_len
= p
- body
;
21497 char *name
= copy_string (body
, name_len
);
21498 const char *replacement
;
21501 replacement
= body
+ name_len
+ 1;
21504 dwarf2_macro_malformed_definition_complaint (body
);
21505 replacement
= body
+ name_len
;
21508 macro_define_object (file
, line
, name
, replacement
);
21512 else if (*p
== '(')
21514 /* It's a function-like macro. */
21515 char *name
= copy_string (body
, p
- body
);
21518 char **argv
= XNEWVEC (char *, argv_size
);
21522 p
= consume_improper_spaces (p
, body
);
21524 /* Parse the formal argument list. */
21525 while (*p
&& *p
!= ')')
21527 /* Find the extent of the current argument name. */
21528 const char *arg_start
= p
;
21530 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
21533 if (! *p
|| p
== arg_start
)
21534 dwarf2_macro_malformed_definition_complaint (body
);
21537 /* Make sure argv has room for the new argument. */
21538 if (argc
>= argv_size
)
21541 argv
= XRESIZEVEC (char *, argv
, argv_size
);
21544 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
21547 p
= consume_improper_spaces (p
, body
);
21549 /* Consume the comma, if present. */
21554 p
= consume_improper_spaces (p
, body
);
21563 /* Perfectly formed definition, no complaints. */
21564 macro_define_function (file
, line
, name
,
21565 argc
, (const char **) argv
,
21567 else if (*p
== '\0')
21569 /* Complain, but do define it. */
21570 dwarf2_macro_malformed_definition_complaint (body
);
21571 macro_define_function (file
, line
, name
,
21572 argc
, (const char **) argv
,
21576 /* Just complain. */
21577 dwarf2_macro_malformed_definition_complaint (body
);
21580 /* Just complain. */
21581 dwarf2_macro_malformed_definition_complaint (body
);
21587 for (i
= 0; i
< argc
; i
++)
21593 dwarf2_macro_malformed_definition_complaint (body
);
21596 /* Skip some bytes from BYTES according to the form given in FORM.
21597 Returns the new pointer. */
21599 static const gdb_byte
*
21600 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
21601 enum dwarf_form form
,
21602 unsigned int offset_size
,
21603 struct dwarf2_section_info
*section
)
21605 unsigned int bytes_read
;
21609 case DW_FORM_data1
:
21614 case DW_FORM_data2
:
21618 case DW_FORM_data4
:
21622 case DW_FORM_data8
:
21626 case DW_FORM_data16
:
21630 case DW_FORM_string
:
21631 read_direct_string (abfd
, bytes
, &bytes_read
);
21632 bytes
+= bytes_read
;
21635 case DW_FORM_sec_offset
:
21637 case DW_FORM_GNU_strp_alt
:
21638 bytes
+= offset_size
;
21641 case DW_FORM_block
:
21642 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
21643 bytes
+= bytes_read
;
21646 case DW_FORM_block1
:
21647 bytes
+= 1 + read_1_byte (abfd
, bytes
);
21649 case DW_FORM_block2
:
21650 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
21652 case DW_FORM_block4
:
21653 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
21656 case DW_FORM_sdata
:
21657 case DW_FORM_udata
:
21658 case DW_FORM_GNU_addr_index
:
21659 case DW_FORM_GNU_str_index
:
21660 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
21663 dwarf2_section_buffer_overflow_complaint (section
);
21671 complaint (&symfile_complaints
,
21672 _("invalid form 0x%x in `%s'"),
21673 form
, get_section_name (section
));
21681 /* A helper for dwarf_decode_macros that handles skipping an unknown
21682 opcode. Returns an updated pointer to the macro data buffer; or,
21683 on error, issues a complaint and returns NULL. */
21685 static const gdb_byte
*
21686 skip_unknown_opcode (unsigned int opcode
,
21687 const gdb_byte
**opcode_definitions
,
21688 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
21690 unsigned int offset_size
,
21691 struct dwarf2_section_info
*section
)
21693 unsigned int bytes_read
, i
;
21695 const gdb_byte
*defn
;
21697 if (opcode_definitions
[opcode
] == NULL
)
21699 complaint (&symfile_complaints
,
21700 _("unrecognized DW_MACFINO opcode 0x%x"),
21705 defn
= opcode_definitions
[opcode
];
21706 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
21707 defn
+= bytes_read
;
21709 for (i
= 0; i
< arg
; ++i
)
21711 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
21712 (enum dwarf_form
) defn
[i
], offset_size
,
21714 if (mac_ptr
== NULL
)
21716 /* skip_form_bytes already issued the complaint. */
21724 /* A helper function which parses the header of a macro section.
21725 If the macro section is the extended (for now called "GNU") type,
21726 then this updates *OFFSET_SIZE. Returns a pointer to just after
21727 the header, or issues a complaint and returns NULL on error. */
21729 static const gdb_byte
*
21730 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
21732 const gdb_byte
*mac_ptr
,
21733 unsigned int *offset_size
,
21734 int section_is_gnu
)
21736 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
21738 if (section_is_gnu
)
21740 unsigned int version
, flags
;
21742 version
= read_2_bytes (abfd
, mac_ptr
);
21743 if (version
!= 4 && version
!= 5)
21745 complaint (&symfile_complaints
,
21746 _("unrecognized version `%d' in .debug_macro section"),
21752 flags
= read_1_byte (abfd
, mac_ptr
);
21754 *offset_size
= (flags
& 1) ? 8 : 4;
21756 if ((flags
& 2) != 0)
21757 /* We don't need the line table offset. */
21758 mac_ptr
+= *offset_size
;
21760 /* Vendor opcode descriptions. */
21761 if ((flags
& 4) != 0)
21763 unsigned int i
, count
;
21765 count
= read_1_byte (abfd
, mac_ptr
);
21767 for (i
= 0; i
< count
; ++i
)
21769 unsigned int opcode
, bytes_read
;
21772 opcode
= read_1_byte (abfd
, mac_ptr
);
21774 opcode_definitions
[opcode
] = mac_ptr
;
21775 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21776 mac_ptr
+= bytes_read
;
21785 /* A helper for dwarf_decode_macros that handles the GNU extensions,
21786 including DW_MACRO_import. */
21789 dwarf_decode_macro_bytes (bfd
*abfd
,
21790 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
21791 struct macro_source_file
*current_file
,
21792 struct line_header
*lh
,
21793 struct dwarf2_section_info
*section
,
21794 int section_is_gnu
, int section_is_dwz
,
21795 unsigned int offset_size
,
21796 htab_t include_hash
)
21798 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21799 enum dwarf_macro_record_type macinfo_type
;
21800 int at_commandline
;
21801 const gdb_byte
*opcode_definitions
[256];
21803 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
21804 &offset_size
, section_is_gnu
);
21805 if (mac_ptr
== NULL
)
21807 /* We already issued a complaint. */
21811 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
21812 GDB is still reading the definitions from command line. First
21813 DW_MACINFO_start_file will need to be ignored as it was already executed
21814 to create CURRENT_FILE for the main source holding also the command line
21815 definitions. On first met DW_MACINFO_start_file this flag is reset to
21816 normally execute all the remaining DW_MACINFO_start_file macinfos. */
21818 at_commandline
= 1;
21822 /* Do we at least have room for a macinfo type byte? */
21823 if (mac_ptr
>= mac_end
)
21825 dwarf2_section_buffer_overflow_complaint (section
);
21829 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
21832 /* Note that we rely on the fact that the corresponding GNU and
21833 DWARF constants are the same. */
21834 switch (macinfo_type
)
21836 /* A zero macinfo type indicates the end of the macro
21841 case DW_MACRO_define
:
21842 case DW_MACRO_undef
:
21843 case DW_MACRO_define_strp
:
21844 case DW_MACRO_undef_strp
:
21845 case DW_MACRO_define_sup
:
21846 case DW_MACRO_undef_sup
:
21848 unsigned int bytes_read
;
21853 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21854 mac_ptr
+= bytes_read
;
21856 if (macinfo_type
== DW_MACRO_define
21857 || macinfo_type
== DW_MACRO_undef
)
21859 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21860 mac_ptr
+= bytes_read
;
21864 LONGEST str_offset
;
21866 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
21867 mac_ptr
+= offset_size
;
21869 if (macinfo_type
== DW_MACRO_define_sup
21870 || macinfo_type
== DW_MACRO_undef_sup
21873 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
21875 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
21878 body
= read_indirect_string_at_offset (abfd
, str_offset
);
21881 is_define
= (macinfo_type
== DW_MACRO_define
21882 || macinfo_type
== DW_MACRO_define_strp
21883 || macinfo_type
== DW_MACRO_define_sup
);
21884 if (! current_file
)
21886 /* DWARF violation as no main source is present. */
21887 complaint (&symfile_complaints
,
21888 _("debug info with no main source gives macro %s "
21890 is_define
? _("definition") : _("undefinition"),
21894 if ((line
== 0 && !at_commandline
)
21895 || (line
!= 0 && at_commandline
))
21896 complaint (&symfile_complaints
,
21897 _("debug info gives %s macro %s with %s line %d: %s"),
21898 at_commandline
? _("command-line") : _("in-file"),
21899 is_define
? _("definition") : _("undefinition"),
21900 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
21903 parse_macro_definition (current_file
, line
, body
);
21906 gdb_assert (macinfo_type
== DW_MACRO_undef
21907 || macinfo_type
== DW_MACRO_undef_strp
21908 || macinfo_type
== DW_MACRO_undef_sup
);
21909 macro_undef (current_file
, line
, body
);
21914 case DW_MACRO_start_file
:
21916 unsigned int bytes_read
;
21919 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21920 mac_ptr
+= bytes_read
;
21921 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21922 mac_ptr
+= bytes_read
;
21924 if ((line
== 0 && !at_commandline
)
21925 || (line
!= 0 && at_commandline
))
21926 complaint (&symfile_complaints
,
21927 _("debug info gives source %d included "
21928 "from %s at %s line %d"),
21929 file
, at_commandline
? _("command-line") : _("file"),
21930 line
== 0 ? _("zero") : _("non-zero"), line
);
21932 if (at_commandline
)
21934 /* This DW_MACRO_start_file was executed in the
21936 at_commandline
= 0;
21939 current_file
= macro_start_file (file
, line
, current_file
, lh
);
21943 case DW_MACRO_end_file
:
21944 if (! current_file
)
21945 complaint (&symfile_complaints
,
21946 _("macro debug info has an unmatched "
21947 "`close_file' directive"));
21950 current_file
= current_file
->included_by
;
21951 if (! current_file
)
21953 enum dwarf_macro_record_type next_type
;
21955 /* GCC circa March 2002 doesn't produce the zero
21956 type byte marking the end of the compilation
21957 unit. Complain if it's not there, but exit no
21960 /* Do we at least have room for a macinfo type byte? */
21961 if (mac_ptr
>= mac_end
)
21963 dwarf2_section_buffer_overflow_complaint (section
);
21967 /* We don't increment mac_ptr here, so this is just
21970 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
21972 if (next_type
!= 0)
21973 complaint (&symfile_complaints
,
21974 _("no terminating 0-type entry for "
21975 "macros in `.debug_macinfo' section"));
21982 case DW_MACRO_import
:
21983 case DW_MACRO_import_sup
:
21987 bfd
*include_bfd
= abfd
;
21988 struct dwarf2_section_info
*include_section
= section
;
21989 const gdb_byte
*include_mac_end
= mac_end
;
21990 int is_dwz
= section_is_dwz
;
21991 const gdb_byte
*new_mac_ptr
;
21993 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
21994 mac_ptr
+= offset_size
;
21996 if (macinfo_type
== DW_MACRO_import_sup
)
21998 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
22000 dwarf2_read_section (objfile
, &dwz
->macro
);
22002 include_section
= &dwz
->macro
;
22003 include_bfd
= get_section_bfd_owner (include_section
);
22004 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
22008 new_mac_ptr
= include_section
->buffer
+ offset
;
22009 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
22013 /* This has actually happened; see
22014 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
22015 complaint (&symfile_complaints
,
22016 _("recursive DW_MACRO_import in "
22017 ".debug_macro section"));
22021 *slot
= (void *) new_mac_ptr
;
22023 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
22024 include_mac_end
, current_file
, lh
,
22025 section
, section_is_gnu
, is_dwz
,
22026 offset_size
, include_hash
);
22028 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
22033 case DW_MACINFO_vendor_ext
:
22034 if (!section_is_gnu
)
22036 unsigned int bytes_read
;
22038 /* This reads the constant, but since we don't recognize
22039 any vendor extensions, we ignore it. */
22040 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22041 mac_ptr
+= bytes_read
;
22042 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22043 mac_ptr
+= bytes_read
;
22045 /* We don't recognize any vendor extensions. */
22051 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
22052 mac_ptr
, mac_end
, abfd
, offset_size
,
22054 if (mac_ptr
== NULL
)
22058 } while (macinfo_type
!= 0);
22062 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22063 int section_is_gnu
)
22065 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22066 struct line_header
*lh
= cu
->line_header
;
22068 const gdb_byte
*mac_ptr
, *mac_end
;
22069 struct macro_source_file
*current_file
= 0;
22070 enum dwarf_macro_record_type macinfo_type
;
22071 unsigned int offset_size
= cu
->header
.offset_size
;
22072 const gdb_byte
*opcode_definitions
[256];
22073 struct cleanup
*cleanup
;
22075 struct dwarf2_section_info
*section
;
22076 const char *section_name
;
22078 if (cu
->dwo_unit
!= NULL
)
22080 if (section_is_gnu
)
22082 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22083 section_name
= ".debug_macro.dwo";
22087 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22088 section_name
= ".debug_macinfo.dwo";
22093 if (section_is_gnu
)
22095 section
= &dwarf2_per_objfile
->macro
;
22096 section_name
= ".debug_macro";
22100 section
= &dwarf2_per_objfile
->macinfo
;
22101 section_name
= ".debug_macinfo";
22105 dwarf2_read_section (objfile
, section
);
22106 if (section
->buffer
== NULL
)
22108 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
22111 abfd
= get_section_bfd_owner (section
);
22113 /* First pass: Find the name of the base filename.
22114 This filename is needed in order to process all macros whose definition
22115 (or undefinition) comes from the command line. These macros are defined
22116 before the first DW_MACINFO_start_file entry, and yet still need to be
22117 associated to the base file.
22119 To determine the base file name, we scan the macro definitions until we
22120 reach the first DW_MACINFO_start_file entry. We then initialize
22121 CURRENT_FILE accordingly so that any macro definition found before the
22122 first DW_MACINFO_start_file can still be associated to the base file. */
22124 mac_ptr
= section
->buffer
+ offset
;
22125 mac_end
= section
->buffer
+ section
->size
;
22127 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
22128 &offset_size
, section_is_gnu
);
22129 if (mac_ptr
== NULL
)
22131 /* We already issued a complaint. */
22137 /* Do we at least have room for a macinfo type byte? */
22138 if (mac_ptr
>= mac_end
)
22140 /* Complaint is printed during the second pass as GDB will probably
22141 stop the first pass earlier upon finding
22142 DW_MACINFO_start_file. */
22146 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
22149 /* Note that we rely on the fact that the corresponding GNU and
22150 DWARF constants are the same. */
22151 switch (macinfo_type
)
22153 /* A zero macinfo type indicates the end of the macro
22158 case DW_MACRO_define
:
22159 case DW_MACRO_undef
:
22160 /* Only skip the data by MAC_PTR. */
22162 unsigned int bytes_read
;
22164 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22165 mac_ptr
+= bytes_read
;
22166 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22167 mac_ptr
+= bytes_read
;
22171 case DW_MACRO_start_file
:
22173 unsigned int bytes_read
;
22176 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22177 mac_ptr
+= bytes_read
;
22178 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22179 mac_ptr
+= bytes_read
;
22181 current_file
= macro_start_file (file
, line
, current_file
, lh
);
22185 case DW_MACRO_end_file
:
22186 /* No data to skip by MAC_PTR. */
22189 case DW_MACRO_define_strp
:
22190 case DW_MACRO_undef_strp
:
22191 case DW_MACRO_define_sup
:
22192 case DW_MACRO_undef_sup
:
22194 unsigned int bytes_read
;
22196 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22197 mac_ptr
+= bytes_read
;
22198 mac_ptr
+= offset_size
;
22202 case DW_MACRO_import
:
22203 case DW_MACRO_import_sup
:
22204 /* Note that, according to the spec, a transparent include
22205 chain cannot call DW_MACRO_start_file. So, we can just
22206 skip this opcode. */
22207 mac_ptr
+= offset_size
;
22210 case DW_MACINFO_vendor_ext
:
22211 /* Only skip the data by MAC_PTR. */
22212 if (!section_is_gnu
)
22214 unsigned int bytes_read
;
22216 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22217 mac_ptr
+= bytes_read
;
22218 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22219 mac_ptr
+= bytes_read
;
22224 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
22225 mac_ptr
, mac_end
, abfd
, offset_size
,
22227 if (mac_ptr
== NULL
)
22231 } while (macinfo_type
!= 0 && current_file
== NULL
);
22233 /* Second pass: Process all entries.
22235 Use the AT_COMMAND_LINE flag to determine whether we are still processing
22236 command-line macro definitions/undefinitions. This flag is unset when we
22237 reach the first DW_MACINFO_start_file entry. */
22239 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
22241 NULL
, xcalloc
, xfree
));
22242 mac_ptr
= section
->buffer
+ offset
;
22243 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
22244 *slot
= (void *) mac_ptr
;
22245 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
22246 current_file
, lh
, section
,
22247 section_is_gnu
, 0, offset_size
,
22248 include_hash
.get ());
22251 /* Check if the attribute's form is a DW_FORM_block*
22252 if so return true else false. */
22255 attr_form_is_block (const struct attribute
*attr
)
22257 return (attr
== NULL
? 0 :
22258 attr
->form
== DW_FORM_block1
22259 || attr
->form
== DW_FORM_block2
22260 || attr
->form
== DW_FORM_block4
22261 || attr
->form
== DW_FORM_block
22262 || attr
->form
== DW_FORM_exprloc
);
22265 /* Return non-zero if ATTR's value is a section offset --- classes
22266 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
22267 You may use DW_UNSND (attr) to retrieve such offsets.
22269 Section 7.5.4, "Attribute Encodings", explains that no attribute
22270 may have a value that belongs to more than one of these classes; it
22271 would be ambiguous if we did, because we use the same forms for all
22275 attr_form_is_section_offset (const struct attribute
*attr
)
22277 return (attr
->form
== DW_FORM_data4
22278 || attr
->form
== DW_FORM_data8
22279 || attr
->form
== DW_FORM_sec_offset
);
22282 /* Return non-zero if ATTR's value falls in the 'constant' class, or
22283 zero otherwise. When this function returns true, you can apply
22284 dwarf2_get_attr_constant_value to it.
22286 However, note that for some attributes you must check
22287 attr_form_is_section_offset before using this test. DW_FORM_data4
22288 and DW_FORM_data8 are members of both the constant class, and of
22289 the classes that contain offsets into other debug sections
22290 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
22291 that, if an attribute's can be either a constant or one of the
22292 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
22293 taken as section offsets, not constants.
22295 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
22296 cannot handle that. */
22299 attr_form_is_constant (const struct attribute
*attr
)
22301 switch (attr
->form
)
22303 case DW_FORM_sdata
:
22304 case DW_FORM_udata
:
22305 case DW_FORM_data1
:
22306 case DW_FORM_data2
:
22307 case DW_FORM_data4
:
22308 case DW_FORM_data8
:
22316 /* DW_ADDR is always stored already as sect_offset; despite for the forms
22317 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
22320 attr_form_is_ref (const struct attribute
*attr
)
22322 switch (attr
->form
)
22324 case DW_FORM_ref_addr
:
22329 case DW_FORM_ref_udata
:
22330 case DW_FORM_GNU_ref_alt
:
22337 /* Return the .debug_loc section to use for CU.
22338 For DWO files use .debug_loc.dwo. */
22340 static struct dwarf2_section_info
*
22341 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22345 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22347 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22349 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22350 : &dwarf2_per_objfile
->loc
);
22353 /* A helper function that fills in a dwarf2_loclist_baton. */
22356 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22357 struct dwarf2_loclist_baton
*baton
,
22358 const struct attribute
*attr
)
22360 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22362 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
22364 baton
->per_cu
= cu
->per_cu
;
22365 gdb_assert (baton
->per_cu
);
22366 /* We don't know how long the location list is, but make sure we
22367 don't run off the edge of the section. */
22368 baton
->size
= section
->size
- DW_UNSND (attr
);
22369 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22370 baton
->base_address
= cu
->base_address
;
22371 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22375 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22376 struct dwarf2_cu
*cu
, int is_block
)
22378 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22379 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22381 if (attr_form_is_section_offset (attr
)
22382 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22383 the section. If so, fall through to the complaint in the
22385 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
22387 struct dwarf2_loclist_baton
*baton
;
22389 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22391 fill_in_loclist_baton (cu
, baton
, attr
);
22393 if (cu
->base_known
== 0)
22394 complaint (&symfile_complaints
,
22395 _("Location list used without "
22396 "specifying the CU base address."));
22398 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22399 ? dwarf2_loclist_block_index
22400 : dwarf2_loclist_index
);
22401 SYMBOL_LOCATION_BATON (sym
) = baton
;
22405 struct dwarf2_locexpr_baton
*baton
;
22407 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22408 baton
->per_cu
= cu
->per_cu
;
22409 gdb_assert (baton
->per_cu
);
22411 if (attr_form_is_block (attr
))
22413 /* Note that we're just copying the block's data pointer
22414 here, not the actual data. We're still pointing into the
22415 info_buffer for SYM's objfile; right now we never release
22416 that buffer, but when we do clean up properly this may
22418 baton
->size
= DW_BLOCK (attr
)->size
;
22419 baton
->data
= DW_BLOCK (attr
)->data
;
22423 dwarf2_invalid_attrib_class_complaint ("location description",
22424 SYMBOL_NATURAL_NAME (sym
));
22428 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22429 ? dwarf2_locexpr_block_index
22430 : dwarf2_locexpr_index
);
22431 SYMBOL_LOCATION_BATON (sym
) = baton
;
22435 /* Return the OBJFILE associated with the compilation unit CU. If CU
22436 came from a separate debuginfo file, then the master objfile is
22440 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
22442 struct objfile
*objfile
= per_cu
->objfile
;
22444 /* Return the master objfile, so that we can report and look up the
22445 correct file containing this variable. */
22446 if (objfile
->separate_debug_objfile_backlink
)
22447 objfile
= objfile
->separate_debug_objfile_backlink
;
22452 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22453 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22454 CU_HEADERP first. */
22456 static const struct comp_unit_head
*
22457 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22458 struct dwarf2_per_cu_data
*per_cu
)
22460 const gdb_byte
*info_ptr
;
22463 return &per_cu
->cu
->header
;
22465 info_ptr
= per_cu
->section
->buffer
+ per_cu
->offset
.sect_off
;
22467 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22468 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22469 rcuh_kind::COMPILE
);
22474 /* Return the address size given in the compilation unit header for CU. */
22477 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
22479 struct comp_unit_head cu_header_local
;
22480 const struct comp_unit_head
*cu_headerp
;
22482 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22484 return cu_headerp
->addr_size
;
22487 /* Return the offset size given in the compilation unit header for CU. */
22490 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
22492 struct comp_unit_head cu_header_local
;
22493 const struct comp_unit_head
*cu_headerp
;
22495 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22497 return cu_headerp
->offset_size
;
22500 /* See its dwarf2loc.h declaration. */
22503 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
22505 struct comp_unit_head cu_header_local
;
22506 const struct comp_unit_head
*cu_headerp
;
22508 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22510 if (cu_headerp
->version
== 2)
22511 return cu_headerp
->addr_size
;
22513 return cu_headerp
->offset_size
;
22516 /* Return the text offset of the CU. The returned offset comes from
22517 this CU's objfile. If this objfile came from a separate debuginfo
22518 file, then the offset may be different from the corresponding
22519 offset in the parent objfile. */
22522 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
22524 struct objfile
*objfile
= per_cu
->objfile
;
22526 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
22529 /* Return DWARF version number of PER_CU. */
22532 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
22534 return per_cu
->dwarf_version
;
22537 /* Locate the .debug_info compilation unit from CU's objfile which contains
22538 the DIE at OFFSET. Raises an error on failure. */
22540 static struct dwarf2_per_cu_data
*
22541 dwarf2_find_containing_comp_unit (sect_offset offset
,
22542 unsigned int offset_in_dwz
,
22543 struct objfile
*objfile
)
22545 struct dwarf2_per_cu_data
*this_cu
;
22547 const sect_offset
*cu_off
;
22550 high
= dwarf2_per_objfile
->n_comp_units
- 1;
22553 struct dwarf2_per_cu_data
*mid_cu
;
22554 int mid
= low
+ (high
- low
) / 2;
22556 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
22557 cu_off
= &mid_cu
->offset
;
22558 if (mid_cu
->is_dwz
> offset_in_dwz
22559 || (mid_cu
->is_dwz
== offset_in_dwz
22560 && cu_off
->sect_off
>= offset
.sect_off
))
22565 gdb_assert (low
== high
);
22566 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
22567 cu_off
= &this_cu
->offset
;
22568 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
22570 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
22571 error (_("Dwarf Error: could not find partial DIE containing "
22572 "offset 0x%lx [in module %s]"),
22573 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
22575 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
22576 <= offset
.sect_off
);
22577 return dwarf2_per_objfile
->all_comp_units
[low
-1];
22581 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
22582 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
22583 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
22584 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
22585 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
22590 /* Initialize dwarf2_cu CU, owned by PER_CU. */
22593 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
22595 memset (cu
, 0, sizeof (*cu
));
22597 cu
->per_cu
= per_cu
;
22598 cu
->objfile
= per_cu
->objfile
;
22599 obstack_init (&cu
->comp_unit_obstack
);
22602 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
22605 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
22606 enum language pretend_language
)
22608 struct attribute
*attr
;
22610 /* Set the language we're debugging. */
22611 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
22613 set_cu_language (DW_UNSND (attr
), cu
);
22616 cu
->language
= pretend_language
;
22617 cu
->language_defn
= language_def (cu
->language
);
22620 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
22623 /* Release one cached compilation unit, CU. We unlink it from the tree
22624 of compilation units, but we don't remove it from the read_in_chain;
22625 the caller is responsible for that.
22626 NOTE: DATA is a void * because this function is also used as a
22627 cleanup routine. */
22630 free_heap_comp_unit (void *data
)
22632 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
22634 gdb_assert (cu
->per_cu
!= NULL
);
22635 cu
->per_cu
->cu
= NULL
;
22638 obstack_free (&cu
->comp_unit_obstack
, NULL
);
22643 /* This cleanup function is passed the address of a dwarf2_cu on the stack
22644 when we're finished with it. We can't free the pointer itself, but be
22645 sure to unlink it from the cache. Also release any associated storage. */
22648 free_stack_comp_unit (void *data
)
22650 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
22652 gdb_assert (cu
->per_cu
!= NULL
);
22653 cu
->per_cu
->cu
= NULL
;
22656 obstack_free (&cu
->comp_unit_obstack
, NULL
);
22657 cu
->partial_dies
= NULL
;
22660 /* Free all cached compilation units. */
22663 free_cached_comp_units (void *data
)
22665 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22667 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22668 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22669 while (per_cu
!= NULL
)
22671 struct dwarf2_per_cu_data
*next_cu
;
22673 next_cu
= per_cu
->cu
->read_in_chain
;
22675 free_heap_comp_unit (per_cu
->cu
);
22676 *last_chain
= next_cu
;
22682 /* Increase the age counter on each cached compilation unit, and free
22683 any that are too old. */
22686 age_cached_comp_units (void)
22688 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22690 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
22691 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22692 while (per_cu
!= NULL
)
22694 per_cu
->cu
->last_used
++;
22695 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
22696 dwarf2_mark (per_cu
->cu
);
22697 per_cu
= per_cu
->cu
->read_in_chain
;
22700 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22701 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22702 while (per_cu
!= NULL
)
22704 struct dwarf2_per_cu_data
*next_cu
;
22706 next_cu
= per_cu
->cu
->read_in_chain
;
22708 if (!per_cu
->cu
->mark
)
22710 free_heap_comp_unit (per_cu
->cu
);
22711 *last_chain
= next_cu
;
22714 last_chain
= &per_cu
->cu
->read_in_chain
;
22720 /* Remove a single compilation unit from the cache. */
22723 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
22725 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22727 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22728 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22729 while (per_cu
!= NULL
)
22731 struct dwarf2_per_cu_data
*next_cu
;
22733 next_cu
= per_cu
->cu
->read_in_chain
;
22735 if (per_cu
== target_per_cu
)
22737 free_heap_comp_unit (per_cu
->cu
);
22739 *last_chain
= next_cu
;
22743 last_chain
= &per_cu
->cu
->read_in_chain
;
22749 /* Release all extra memory associated with OBJFILE. */
22752 dwarf2_free_objfile (struct objfile
*objfile
)
22755 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
22756 dwarf2_objfile_data_key
);
22758 if (dwarf2_per_objfile
== NULL
)
22761 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
22762 free_cached_comp_units (NULL
);
22764 if (dwarf2_per_objfile
->quick_file_names_table
)
22765 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
22767 if (dwarf2_per_objfile
->line_header_hash
)
22768 htab_delete (dwarf2_per_objfile
->line_header_hash
);
22770 /* Everything else should be on the objfile obstack. */
22773 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
22774 We store these in a hash table separate from the DIEs, and preserve them
22775 when the DIEs are flushed out of cache.
22777 The CU "per_cu" pointer is needed because offset alone is not enough to
22778 uniquely identify the type. A file may have multiple .debug_types sections,
22779 or the type may come from a DWO file. Furthermore, while it's more logical
22780 to use per_cu->section+offset, with Fission the section with the data is in
22781 the DWO file but we don't know that section at the point we need it.
22782 We have to use something in dwarf2_per_cu_data (or the pointer to it)
22783 because we can enter the lookup routine, get_die_type_at_offset, from
22784 outside this file, and thus won't necessarily have PER_CU->cu.
22785 Fortunately, PER_CU is stable for the life of the objfile. */
22787 struct dwarf2_per_cu_offset_and_type
22789 const struct dwarf2_per_cu_data
*per_cu
;
22790 sect_offset offset
;
22794 /* Hash function for a dwarf2_per_cu_offset_and_type. */
22797 per_cu_offset_and_type_hash (const void *item
)
22799 const struct dwarf2_per_cu_offset_and_type
*ofs
22800 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
22802 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
22805 /* Equality function for a dwarf2_per_cu_offset_and_type. */
22808 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
22810 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
22811 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
22812 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
22813 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
22815 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
22816 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
22819 /* Set the type associated with DIE to TYPE. Save it in CU's hash
22820 table if necessary. For convenience, return TYPE.
22822 The DIEs reading must have careful ordering to:
22823 * Not cause infite loops trying to read in DIEs as a prerequisite for
22824 reading current DIE.
22825 * Not trying to dereference contents of still incompletely read in types
22826 while reading in other DIEs.
22827 * Enable referencing still incompletely read in types just by a pointer to
22828 the type without accessing its fields.
22830 Therefore caller should follow these rules:
22831 * Try to fetch any prerequisite types we may need to build this DIE type
22832 before building the type and calling set_die_type.
22833 * After building type call set_die_type for current DIE as soon as
22834 possible before fetching more types to complete the current type.
22835 * Make the type as complete as possible before fetching more types. */
22837 static struct type
*
22838 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
22840 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
22841 struct objfile
*objfile
= cu
->objfile
;
22842 struct attribute
*attr
;
22843 struct dynamic_prop prop
;
22845 /* For Ada types, make sure that the gnat-specific data is always
22846 initialized (if not already set). There are a few types where
22847 we should not be doing so, because the type-specific area is
22848 already used to hold some other piece of info (eg: TYPE_CODE_FLT
22849 where the type-specific area is used to store the floatformat).
22850 But this is not a problem, because the gnat-specific information
22851 is actually not needed for these types. */
22852 if (need_gnat_info (cu
)
22853 && TYPE_CODE (type
) != TYPE_CODE_FUNC
22854 && TYPE_CODE (type
) != TYPE_CODE_FLT
22855 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
22856 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
22857 && TYPE_CODE (type
) != TYPE_CODE_METHOD
22858 && !HAVE_GNAT_AUX_INFO (type
))
22859 INIT_GNAT_SPECIFIC (type
);
22861 /* Read DW_AT_allocated and set in type. */
22862 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
22863 if (attr_form_is_block (attr
))
22865 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22866 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
, objfile
);
22868 else if (attr
!= NULL
)
22870 complaint (&symfile_complaints
,
22871 _("DW_AT_allocated has the wrong form (%s) at DIE 0x%x"),
22872 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
22873 die
->offset
.sect_off
);
22876 /* Read DW_AT_associated and set in type. */
22877 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
22878 if (attr_form_is_block (attr
))
22880 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22881 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
, objfile
);
22883 else if (attr
!= NULL
)
22885 complaint (&symfile_complaints
,
22886 _("DW_AT_associated has the wrong form (%s) at DIE 0x%x"),
22887 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
22888 die
->offset
.sect_off
);
22891 /* Read DW_AT_data_location and set in type. */
22892 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
22893 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22894 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
, objfile
);
22896 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
22898 dwarf2_per_objfile
->die_type_hash
=
22899 htab_create_alloc_ex (127,
22900 per_cu_offset_and_type_hash
,
22901 per_cu_offset_and_type_eq
,
22903 &objfile
->objfile_obstack
,
22904 hashtab_obstack_allocate
,
22905 dummy_obstack_deallocate
);
22908 ofs
.per_cu
= cu
->per_cu
;
22909 ofs
.offset
= die
->offset
;
22911 slot
= (struct dwarf2_per_cu_offset_and_type
**)
22912 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
22914 complaint (&symfile_complaints
,
22915 _("A problem internal to GDB: DIE 0x%x has type already set"),
22916 die
->offset
.sect_off
);
22917 *slot
= XOBNEW (&objfile
->objfile_obstack
,
22918 struct dwarf2_per_cu_offset_and_type
);
22923 /* Look up the type for the die at OFFSET in PER_CU in die_type_hash,
22924 or return NULL if the die does not have a saved type. */
22926 static struct type
*
22927 get_die_type_at_offset (sect_offset offset
,
22928 struct dwarf2_per_cu_data
*per_cu
)
22930 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
22932 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
22935 ofs
.per_cu
= per_cu
;
22936 ofs
.offset
= offset
;
22937 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
22938 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
22945 /* Look up the type for DIE in CU in die_type_hash,
22946 or return NULL if DIE does not have a saved type. */
22948 static struct type
*
22949 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22951 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
22954 /* Add a dependence relationship from CU to REF_PER_CU. */
22957 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
22958 struct dwarf2_per_cu_data
*ref_per_cu
)
22962 if (cu
->dependencies
== NULL
)
22964 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
22965 NULL
, &cu
->comp_unit_obstack
,
22966 hashtab_obstack_allocate
,
22967 dummy_obstack_deallocate
);
22969 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
22971 *slot
= ref_per_cu
;
22974 /* Subroutine of dwarf2_mark to pass to htab_traverse.
22975 Set the mark field in every compilation unit in the
22976 cache that we must keep because we are keeping CU. */
22979 dwarf2_mark_helper (void **slot
, void *data
)
22981 struct dwarf2_per_cu_data
*per_cu
;
22983 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
22985 /* cu->dependencies references may not yet have been ever read if QUIT aborts
22986 reading of the chain. As such dependencies remain valid it is not much
22987 useful to track and undo them during QUIT cleanups. */
22988 if (per_cu
->cu
== NULL
)
22991 if (per_cu
->cu
->mark
)
22993 per_cu
->cu
->mark
= 1;
22995 if (per_cu
->cu
->dependencies
!= NULL
)
22996 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23001 /* Set the mark field in CU and in every other compilation unit in the
23002 cache that we must keep because we are keeping CU. */
23005 dwarf2_mark (struct dwarf2_cu
*cu
)
23010 if (cu
->dependencies
!= NULL
)
23011 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23015 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23019 per_cu
->cu
->mark
= 0;
23020 per_cu
= per_cu
->cu
->read_in_chain
;
23024 /* Trivial hash function for partial_die_info: the hash value of a DIE
23025 is its offset in .debug_info for this objfile. */
23028 partial_die_hash (const void *item
)
23030 const struct partial_die_info
*part_die
23031 = (const struct partial_die_info
*) item
;
23033 return part_die
->offset
.sect_off
;
23036 /* Trivial comparison function for partial_die_info structures: two DIEs
23037 are equal if they have the same offset. */
23040 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23042 const struct partial_die_info
*part_die_lhs
23043 = (const struct partial_die_info
*) item_lhs
;
23044 const struct partial_die_info
*part_die_rhs
23045 = (const struct partial_die_info
*) item_rhs
;
23047 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
23050 static struct cmd_list_element
*set_dwarf_cmdlist
;
23051 static struct cmd_list_element
*show_dwarf_cmdlist
;
23054 set_dwarf_cmd (char *args
, int from_tty
)
23056 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23061 show_dwarf_cmd (char *args
, int from_tty
)
23063 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23066 /* Free data associated with OBJFILE, if necessary. */
23069 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
23071 struct dwarf2_per_objfile
*data
= (struct dwarf2_per_objfile
*) d
;
23074 /* Make sure we don't accidentally use dwarf2_per_objfile while
23076 dwarf2_per_objfile
= NULL
;
23078 for (ix
= 0; ix
< data
->n_comp_units
; ++ix
)
23079 VEC_free (dwarf2_per_cu_ptr
, data
->all_comp_units
[ix
]->imported_symtabs
);
23081 for (ix
= 0; ix
< data
->n_type_units
; ++ix
)
23082 VEC_free (dwarf2_per_cu_ptr
,
23083 data
->all_type_units
[ix
]->per_cu
.imported_symtabs
);
23084 xfree (data
->all_type_units
);
23086 VEC_free (dwarf2_section_info_def
, data
->types
);
23088 if (data
->dwo_files
)
23089 free_dwo_files (data
->dwo_files
, objfile
);
23090 if (data
->dwp_file
)
23091 gdb_bfd_unref (data
->dwp_file
->dbfd
);
23093 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
23094 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
23098 /* The "save gdb-index" command. */
23100 /* The contents of the hash table we create when building the string
23102 struct strtab_entry
23104 offset_type offset
;
23108 /* Hash function for a strtab_entry.
23110 Function is used only during write_hash_table so no index format backward
23111 compatibility is needed. */
23114 hash_strtab_entry (const void *e
)
23116 const struct strtab_entry
*entry
= (const struct strtab_entry
*) e
;
23117 return mapped_index_string_hash (INT_MAX
, entry
->str
);
23120 /* Equality function for a strtab_entry. */
23123 eq_strtab_entry (const void *a
, const void *b
)
23125 const struct strtab_entry
*ea
= (const struct strtab_entry
*) a
;
23126 const struct strtab_entry
*eb
= (const struct strtab_entry
*) b
;
23127 return !strcmp (ea
->str
, eb
->str
);
23130 /* Create a strtab_entry hash table. */
23133 create_strtab (void)
23135 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
23136 xfree
, xcalloc
, xfree
);
23139 /* Add a string to the constant pool. Return the string's offset in
23143 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
23146 struct strtab_entry entry
;
23147 struct strtab_entry
*result
;
23150 slot
= htab_find_slot (table
, &entry
, INSERT
);
23152 result
= (struct strtab_entry
*) *slot
;
23155 result
= XNEW (struct strtab_entry
);
23156 result
->offset
= obstack_object_size (cpool
);
23158 obstack_grow_str0 (cpool
, str
);
23161 return result
->offset
;
23164 /* An entry in the symbol table. */
23165 struct symtab_index_entry
23167 /* The name of the symbol. */
23169 /* The offset of the name in the constant pool. */
23170 offset_type index_offset
;
23171 /* A sorted vector of the indices of all the CUs that hold an object
23173 VEC (offset_type
) *cu_indices
;
23176 /* The symbol table. This is a power-of-2-sized hash table. */
23177 struct mapped_symtab
23179 offset_type n_elements
;
23181 struct symtab_index_entry
**data
;
23184 /* Hash function for a symtab_index_entry. */
23187 hash_symtab_entry (const void *e
)
23189 const struct symtab_index_entry
*entry
23190 = (const struct symtab_index_entry
*) e
;
23191 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
23192 sizeof (offset_type
) * VEC_length (offset_type
,
23193 entry
->cu_indices
),
23197 /* Equality function for a symtab_index_entry. */
23200 eq_symtab_entry (const void *a
, const void *b
)
23202 const struct symtab_index_entry
*ea
= (const struct symtab_index_entry
*) a
;
23203 const struct symtab_index_entry
*eb
= (const struct symtab_index_entry
*) b
;
23204 int len
= VEC_length (offset_type
, ea
->cu_indices
);
23205 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
23207 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
23208 VEC_address (offset_type
, eb
->cu_indices
),
23209 sizeof (offset_type
) * len
);
23212 /* Destroy a symtab_index_entry. */
23215 delete_symtab_entry (void *p
)
23217 struct symtab_index_entry
*entry
= (struct symtab_index_entry
*) p
;
23218 VEC_free (offset_type
, entry
->cu_indices
);
23222 /* Create a hash table holding symtab_index_entry objects. */
23225 create_symbol_hash_table (void)
23227 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
23228 delete_symtab_entry
, xcalloc
, xfree
);
23231 /* Create a new mapped symtab object. */
23233 static struct mapped_symtab
*
23234 create_mapped_symtab (void)
23236 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
23237 symtab
->n_elements
= 0;
23238 symtab
->size
= 1024;
23239 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
23243 /* Destroy a mapped_symtab. */
23246 cleanup_mapped_symtab (void *p
)
23248 struct mapped_symtab
*symtab
= (struct mapped_symtab
*) p
;
23249 /* The contents of the array are freed when the other hash table is
23251 xfree (symtab
->data
);
23255 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
23258 Function is used only during write_hash_table so no index format backward
23259 compatibility is needed. */
23261 static struct symtab_index_entry
**
23262 find_slot (struct mapped_symtab
*symtab
, const char *name
)
23264 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
23266 index
= hash
& (symtab
->size
- 1);
23267 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
23271 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
23272 return &symtab
->data
[index
];
23273 index
= (index
+ step
) & (symtab
->size
- 1);
23277 /* Expand SYMTAB's hash table. */
23280 hash_expand (struct mapped_symtab
*symtab
)
23282 offset_type old_size
= symtab
->size
;
23284 struct symtab_index_entry
**old_entries
= symtab
->data
;
23287 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
23289 for (i
= 0; i
< old_size
; ++i
)
23291 if (old_entries
[i
])
23293 struct symtab_index_entry
**slot
= find_slot (symtab
,
23294 old_entries
[i
]->name
);
23295 *slot
= old_entries
[i
];
23299 xfree (old_entries
);
23302 /* Add an entry to SYMTAB. NAME is the name of the symbol.
23303 CU_INDEX is the index of the CU in which the symbol appears.
23304 IS_STATIC is one if the symbol is static, otherwise zero (global). */
23307 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
23308 int is_static
, gdb_index_symbol_kind kind
,
23309 offset_type cu_index
)
23311 struct symtab_index_entry
**slot
;
23312 offset_type cu_index_and_attrs
;
23314 ++symtab
->n_elements
;
23315 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
23316 hash_expand (symtab
);
23318 slot
= find_slot (symtab
, name
);
23321 *slot
= XNEW (struct symtab_index_entry
);
23322 (*slot
)->name
= name
;
23323 /* index_offset is set later. */
23324 (*slot
)->cu_indices
= NULL
;
23327 cu_index_and_attrs
= 0;
23328 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
23329 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
23330 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
23332 /* We don't want to record an index value twice as we want to avoid the
23334 We process all global symbols and then all static symbols
23335 (which would allow us to avoid the duplication by only having to check
23336 the last entry pushed), but a symbol could have multiple kinds in one CU.
23337 To keep things simple we don't worry about the duplication here and
23338 sort and uniqufy the list after we've processed all symbols. */
23339 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
23342 /* qsort helper routine for uniquify_cu_indices. */
23345 offset_type_compare (const void *ap
, const void *bp
)
23347 offset_type a
= *(offset_type
*) ap
;
23348 offset_type b
= *(offset_type
*) bp
;
23350 return (a
> b
) - (b
> a
);
23353 /* Sort and remove duplicates of all symbols' cu_indices lists. */
23356 uniquify_cu_indices (struct mapped_symtab
*symtab
)
23360 for (i
= 0; i
< symtab
->size
; ++i
)
23362 struct symtab_index_entry
*entry
= symtab
->data
[i
];
23365 && entry
->cu_indices
!= NULL
)
23367 unsigned int next_to_insert
, next_to_check
;
23368 offset_type last_value
;
23370 qsort (VEC_address (offset_type
, entry
->cu_indices
),
23371 VEC_length (offset_type
, entry
->cu_indices
),
23372 sizeof (offset_type
), offset_type_compare
);
23374 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
23375 next_to_insert
= 1;
23376 for (next_to_check
= 1;
23377 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
23380 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
23383 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
23385 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
23390 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
23395 /* Add a vector of indices to the constant pool. */
23398 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
23399 struct symtab_index_entry
*entry
)
23403 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
23406 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
23407 offset_type val
= MAYBE_SWAP (len
);
23412 entry
->index_offset
= obstack_object_size (cpool
);
23414 obstack_grow (cpool
, &val
, sizeof (val
));
23416 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
23419 val
= MAYBE_SWAP (iter
);
23420 obstack_grow (cpool
, &val
, sizeof (val
));
23425 struct symtab_index_entry
*old_entry
23426 = (struct symtab_index_entry
*) *slot
;
23427 entry
->index_offset
= old_entry
->index_offset
;
23430 return entry
->index_offset
;
23433 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
23434 constant pool entries going into the obstack CPOOL. */
23437 write_hash_table (struct mapped_symtab
*symtab
,
23438 struct obstack
*output
, struct obstack
*cpool
)
23441 htab_t symbol_hash_table
;
23444 symbol_hash_table
= create_symbol_hash_table ();
23445 str_table
= create_strtab ();
23447 /* We add all the index vectors to the constant pool first, to
23448 ensure alignment is ok. */
23449 for (i
= 0; i
< symtab
->size
; ++i
)
23451 if (symtab
->data
[i
])
23452 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
23455 /* Now write out the hash table. */
23456 for (i
= 0; i
< symtab
->size
; ++i
)
23458 offset_type str_off
, vec_off
;
23460 if (symtab
->data
[i
])
23462 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
23463 vec_off
= symtab
->data
[i
]->index_offset
;
23467 /* While 0 is a valid constant pool index, it is not valid
23468 to have 0 for both offsets. */
23473 str_off
= MAYBE_SWAP (str_off
);
23474 vec_off
= MAYBE_SWAP (vec_off
);
23476 obstack_grow (output
, &str_off
, sizeof (str_off
));
23477 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
23480 htab_delete (str_table
);
23481 htab_delete (symbol_hash_table
);
23484 /* Struct to map psymtab to CU index in the index file. */
23485 struct psymtab_cu_index_map
23487 struct partial_symtab
*psymtab
;
23488 unsigned int cu_index
;
23492 hash_psymtab_cu_index (const void *item
)
23494 const struct psymtab_cu_index_map
*map
23495 = (const struct psymtab_cu_index_map
*) item
;
23497 return htab_hash_pointer (map
->psymtab
);
23501 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
23503 const struct psymtab_cu_index_map
*lhs
23504 = (const struct psymtab_cu_index_map
*) item_lhs
;
23505 const struct psymtab_cu_index_map
*rhs
23506 = (const struct psymtab_cu_index_map
*) item_rhs
;
23508 return lhs
->psymtab
== rhs
->psymtab
;
23511 /* Helper struct for building the address table. */
23512 struct addrmap_index_data
23514 struct objfile
*objfile
;
23515 struct obstack
*addr_obstack
;
23516 htab_t cu_index_htab
;
23518 /* Non-zero if the previous_* fields are valid.
23519 We can't write an entry until we see the next entry (since it is only then
23520 that we know the end of the entry). */
23521 int previous_valid
;
23522 /* Index of the CU in the table of all CUs in the index file. */
23523 unsigned int previous_cu_index
;
23524 /* Start address of the CU. */
23525 CORE_ADDR previous_cu_start
;
23528 /* Write an address entry to OBSTACK. */
23531 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
23532 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
23534 offset_type cu_index_to_write
;
23536 CORE_ADDR baseaddr
;
23538 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23540 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
23541 obstack_grow (obstack
, addr
, 8);
23542 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
23543 obstack_grow (obstack
, addr
, 8);
23544 cu_index_to_write
= MAYBE_SWAP (cu_index
);
23545 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
23548 /* Worker function for traversing an addrmap to build the address table. */
23551 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
23553 struct addrmap_index_data
*data
= (struct addrmap_index_data
*) datap
;
23554 struct partial_symtab
*pst
= (struct partial_symtab
*) obj
;
23556 if (data
->previous_valid
)
23557 add_address_entry (data
->objfile
, data
->addr_obstack
,
23558 data
->previous_cu_start
, start_addr
,
23559 data
->previous_cu_index
);
23561 data
->previous_cu_start
= start_addr
;
23564 struct psymtab_cu_index_map find_map
, *map
;
23565 find_map
.psymtab
= pst
;
23566 map
= ((struct psymtab_cu_index_map
*)
23567 htab_find (data
->cu_index_htab
, &find_map
));
23568 gdb_assert (map
!= NULL
);
23569 data
->previous_cu_index
= map
->cu_index
;
23570 data
->previous_valid
= 1;
23573 data
->previous_valid
= 0;
23578 /* Write OBJFILE's address map to OBSTACK.
23579 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
23580 in the index file. */
23583 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
23584 htab_t cu_index_htab
)
23586 struct addrmap_index_data addrmap_index_data
;
23588 /* When writing the address table, we have to cope with the fact that
23589 the addrmap iterator only provides the start of a region; we have to
23590 wait until the next invocation to get the start of the next region. */
23592 addrmap_index_data
.objfile
= objfile
;
23593 addrmap_index_data
.addr_obstack
= obstack
;
23594 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
23595 addrmap_index_data
.previous_valid
= 0;
23597 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
23598 &addrmap_index_data
);
23600 /* It's highly unlikely the last entry (end address = 0xff...ff)
23601 is valid, but we should still handle it.
23602 The end address is recorded as the start of the next region, but that
23603 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
23605 if (addrmap_index_data
.previous_valid
)
23606 add_address_entry (objfile
, obstack
,
23607 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
23608 addrmap_index_data
.previous_cu_index
);
23611 /* Return the symbol kind of PSYM. */
23613 static gdb_index_symbol_kind
23614 symbol_kind (struct partial_symbol
*psym
)
23616 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
23617 enum address_class aclass
= PSYMBOL_CLASS (psym
);
23625 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
23627 return GDB_INDEX_SYMBOL_KIND_TYPE
;
23629 case LOC_CONST_BYTES
:
23630 case LOC_OPTIMIZED_OUT
:
23632 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
23634 /* Note: It's currently impossible to recognize psyms as enum values
23635 short of reading the type info. For now punt. */
23636 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
23638 /* There are other LOC_FOO values that one might want to classify
23639 as variables, but dwarf2read.c doesn't currently use them. */
23640 return GDB_INDEX_SYMBOL_KIND_OTHER
;
23642 case STRUCT_DOMAIN
:
23643 return GDB_INDEX_SYMBOL_KIND_TYPE
;
23645 return GDB_INDEX_SYMBOL_KIND_OTHER
;
23649 /* Add a list of partial symbols to SYMTAB. */
23652 write_psymbols (struct mapped_symtab
*symtab
,
23654 struct partial_symbol
**psymp
,
23656 offset_type cu_index
,
23659 for (; count
-- > 0; ++psymp
)
23661 struct partial_symbol
*psym
= *psymp
;
23664 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
23665 error (_("Ada is not currently supported by the index"));
23667 /* Only add a given psymbol once. */
23668 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
23671 gdb_index_symbol_kind kind
= symbol_kind (psym
);
23674 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
23675 is_static
, kind
, cu_index
);
23680 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
23681 exception if there is an error. */
23684 write_obstack (FILE *file
, struct obstack
*obstack
)
23686 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
23688 != obstack_object_size (obstack
))
23689 error (_("couldn't data write to file"));
23692 /* A helper struct used when iterating over debug_types. */
23693 struct signatured_type_index_data
23695 struct objfile
*objfile
;
23696 struct mapped_symtab
*symtab
;
23697 struct obstack
*types_list
;
23702 /* A helper function that writes a single signatured_type to an
23706 write_one_signatured_type (void **slot
, void *d
)
23708 struct signatured_type_index_data
*info
23709 = (struct signatured_type_index_data
*) d
;
23710 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
23711 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
23714 write_psymbols (info
->symtab
,
23716 info
->objfile
->global_psymbols
.list
23717 + psymtab
->globals_offset
,
23718 psymtab
->n_global_syms
, info
->cu_index
,
23720 write_psymbols (info
->symtab
,
23722 info
->objfile
->static_psymbols
.list
23723 + psymtab
->statics_offset
,
23724 psymtab
->n_static_syms
, info
->cu_index
,
23727 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23728 entry
->per_cu
.offset
.sect_off
);
23729 obstack_grow (info
->types_list
, val
, 8);
23730 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23731 entry
->type_offset_in_tu
.cu_off
);
23732 obstack_grow (info
->types_list
, val
, 8);
23733 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
23734 obstack_grow (info
->types_list
, val
, 8);
23741 /* Recurse into all "included" dependencies and write their symbols as
23742 if they appeared in this psymtab. */
23745 recursively_write_psymbols (struct objfile
*objfile
,
23746 struct partial_symtab
*psymtab
,
23747 struct mapped_symtab
*symtab
,
23749 offset_type cu_index
)
23753 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
23754 if (psymtab
->dependencies
[i
]->user
!= NULL
)
23755 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
23756 symtab
, psyms_seen
, cu_index
);
23758 write_psymbols (symtab
,
23760 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
23761 psymtab
->n_global_syms
, cu_index
,
23763 write_psymbols (symtab
,
23765 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
23766 psymtab
->n_static_syms
, cu_index
,
23770 /* Create an index file for OBJFILE in the directory DIR. */
23773 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
23775 struct cleanup
*cleanup
;
23777 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
23778 struct obstack cu_list
, types_cu_list
;
23781 struct mapped_symtab
*symtab
;
23782 offset_type val
, size_of_contents
, total_len
;
23784 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
23786 if (dwarf2_per_objfile
->using_index
)
23787 error (_("Cannot use an index to create the index"));
23789 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
23790 error (_("Cannot make an index when the file has multiple .debug_types sections"));
23792 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
23795 if (stat (objfile_name (objfile
), &st
) < 0)
23796 perror_with_name (objfile_name (objfile
));
23798 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile_name (objfile
)),
23799 INDEX_SUFFIX
, (char *) NULL
);
23800 cleanup
= make_cleanup (xfree
, filename
);
23802 out_file
= gdb_fopen_cloexec (filename
, "wb");
23804 error (_("Can't open `%s' for writing"), filename
);
23806 gdb::unlinker
unlink_file (filename
);
23808 symtab
= create_mapped_symtab ();
23809 make_cleanup (cleanup_mapped_symtab
, symtab
);
23811 obstack_init (&addr_obstack
);
23812 make_cleanup_obstack_free (&addr_obstack
);
23814 obstack_init (&cu_list
);
23815 make_cleanup_obstack_free (&cu_list
);
23817 obstack_init (&types_cu_list
);
23818 make_cleanup_obstack_free (&types_cu_list
);
23820 htab_up
psyms_seen (htab_create_alloc (100, htab_hash_pointer
,
23822 NULL
, xcalloc
, xfree
));
23824 /* While we're scanning CU's create a table that maps a psymtab pointer
23825 (which is what addrmap records) to its index (which is what is recorded
23826 in the index file). This will later be needed to write the address
23828 htab_up
cu_index_htab (htab_create_alloc (100,
23829 hash_psymtab_cu_index
,
23830 eq_psymtab_cu_index
,
23831 NULL
, xcalloc
, xfree
));
23832 psymtab_cu_index_map
= XNEWVEC (struct psymtab_cu_index_map
,
23833 dwarf2_per_objfile
->n_comp_units
);
23834 make_cleanup (xfree
, psymtab_cu_index_map
);
23836 /* The CU list is already sorted, so we don't need to do additional
23837 work here. Also, the debug_types entries do not appear in
23838 all_comp_units, but only in their own hash table. */
23839 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
23841 struct dwarf2_per_cu_data
*per_cu
23842 = dwarf2_per_objfile
->all_comp_units
[i
];
23843 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
23845 struct psymtab_cu_index_map
*map
;
23848 /* CU of a shared file from 'dwz -m' may be unused by this main file.
23849 It may be referenced from a local scope but in such case it does not
23850 need to be present in .gdb_index. */
23851 if (psymtab
== NULL
)
23854 if (psymtab
->user
== NULL
)
23855 recursively_write_psymbols (objfile
, psymtab
, symtab
,
23856 psyms_seen
.get (), i
);
23858 map
= &psymtab_cu_index_map
[i
];
23859 map
->psymtab
= psymtab
;
23861 slot
= htab_find_slot (cu_index_htab
.get (), map
, INSERT
);
23862 gdb_assert (slot
!= NULL
);
23863 gdb_assert (*slot
== NULL
);
23866 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23867 per_cu
->offset
.sect_off
);
23868 obstack_grow (&cu_list
, val
, 8);
23869 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
23870 obstack_grow (&cu_list
, val
, 8);
23873 /* Dump the address map. */
23874 write_address_map (objfile
, &addr_obstack
, cu_index_htab
.get ());
23876 /* Write out the .debug_type entries, if any. */
23877 if (dwarf2_per_objfile
->signatured_types
)
23879 struct signatured_type_index_data sig_data
;
23881 sig_data
.objfile
= objfile
;
23882 sig_data
.symtab
= symtab
;
23883 sig_data
.types_list
= &types_cu_list
;
23884 sig_data
.psyms_seen
= psyms_seen
.get ();
23885 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
23886 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
23887 write_one_signatured_type
, &sig_data
);
23890 /* Now that we've processed all symbols we can shrink their cu_indices
23892 uniquify_cu_indices (symtab
);
23894 obstack_init (&constant_pool
);
23895 make_cleanup_obstack_free (&constant_pool
);
23896 obstack_init (&symtab_obstack
);
23897 make_cleanup_obstack_free (&symtab_obstack
);
23898 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
23900 obstack_init (&contents
);
23901 make_cleanup_obstack_free (&contents
);
23902 size_of_contents
= 6 * sizeof (offset_type
);
23903 total_len
= size_of_contents
;
23905 /* The version number. */
23906 val
= MAYBE_SWAP (8);
23907 obstack_grow (&contents
, &val
, sizeof (val
));
23909 /* The offset of the CU list from the start of the file. */
23910 val
= MAYBE_SWAP (total_len
);
23911 obstack_grow (&contents
, &val
, sizeof (val
));
23912 total_len
+= obstack_object_size (&cu_list
);
23914 /* The offset of the types CU list from the start of the file. */
23915 val
= MAYBE_SWAP (total_len
);
23916 obstack_grow (&contents
, &val
, sizeof (val
));
23917 total_len
+= obstack_object_size (&types_cu_list
);
23919 /* The offset of the address table from the start of the file. */
23920 val
= MAYBE_SWAP (total_len
);
23921 obstack_grow (&contents
, &val
, sizeof (val
));
23922 total_len
+= obstack_object_size (&addr_obstack
);
23924 /* The offset of the symbol table from the start of the file. */
23925 val
= MAYBE_SWAP (total_len
);
23926 obstack_grow (&contents
, &val
, sizeof (val
));
23927 total_len
+= obstack_object_size (&symtab_obstack
);
23929 /* The offset of the constant pool from the start of the file. */
23930 val
= MAYBE_SWAP (total_len
);
23931 obstack_grow (&contents
, &val
, sizeof (val
));
23932 total_len
+= obstack_object_size (&constant_pool
);
23934 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
23936 write_obstack (out_file
, &contents
);
23937 write_obstack (out_file
, &cu_list
);
23938 write_obstack (out_file
, &types_cu_list
);
23939 write_obstack (out_file
, &addr_obstack
);
23940 write_obstack (out_file
, &symtab_obstack
);
23941 write_obstack (out_file
, &constant_pool
);
23945 /* We want to keep the file. */
23946 unlink_file
.keep ();
23948 do_cleanups (cleanup
);
23951 /* Implementation of the `save gdb-index' command.
23953 Note that the file format used by this command is documented in the
23954 GDB manual. Any changes here must be documented there. */
23957 save_gdb_index_command (char *arg
, int from_tty
)
23959 struct objfile
*objfile
;
23962 error (_("usage: save gdb-index DIRECTORY"));
23964 ALL_OBJFILES (objfile
)
23968 /* If the objfile does not correspond to an actual file, skip it. */
23969 if (stat (objfile_name (objfile
), &st
) < 0)
23973 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
23974 dwarf2_objfile_data_key
);
23975 if (dwarf2_per_objfile
)
23980 write_psymtabs_to_index (objfile
, arg
);
23982 CATCH (except
, RETURN_MASK_ERROR
)
23984 exception_fprintf (gdb_stderr
, except
,
23985 _("Error while writing index for `%s': "),
23986 objfile_name (objfile
));
23995 int dwarf_always_disassemble
;
23998 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
23999 struct cmd_list_element
*c
, const char *value
)
24001 fprintf_filtered (file
,
24002 _("Whether to always disassemble "
24003 "DWARF expressions is %s.\n"),
24008 show_check_physname (struct ui_file
*file
, int from_tty
,
24009 struct cmd_list_element
*c
, const char *value
)
24011 fprintf_filtered (file
,
24012 _("Whether to check \"physname\" is %s.\n"),
24016 void _initialize_dwarf2_read (void);
24019 _initialize_dwarf2_read (void)
24021 struct cmd_list_element
*c
;
24023 dwarf2_objfile_data_key
24024 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
24026 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
24027 Set DWARF specific variables.\n\
24028 Configure DWARF variables such as the cache size"),
24029 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24030 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24032 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
24033 Show DWARF specific variables\n\
24034 Show DWARF variables such as the cache size"),
24035 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24036 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24038 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24039 &dwarf_max_cache_age
, _("\
24040 Set the upper bound on the age of cached DWARF compilation units."), _("\
24041 Show the upper bound on the age of cached DWARF compilation units."), _("\
24042 A higher limit means that cached compilation units will be stored\n\
24043 in memory longer, and more total memory will be used. Zero disables\n\
24044 caching, which can slow down startup."),
24046 show_dwarf_max_cache_age
,
24047 &set_dwarf_cmdlist
,
24048 &show_dwarf_cmdlist
);
24050 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
24051 &dwarf_always_disassemble
, _("\
24052 Set whether `info address' always disassembles DWARF expressions."), _("\
24053 Show whether `info address' always disassembles DWARF expressions."), _("\
24054 When enabled, DWARF expressions are always printed in an assembly-like\n\
24055 syntax. When disabled, expressions will be printed in a more\n\
24056 conversational style, when possible."),
24058 show_dwarf_always_disassemble
,
24059 &set_dwarf_cmdlist
,
24060 &show_dwarf_cmdlist
);
24062 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24063 Set debugging of the DWARF reader."), _("\
24064 Show debugging of the DWARF reader."), _("\
24065 When enabled (non-zero), debugging messages are printed during DWARF\n\
24066 reading and symtab expansion. A value of 1 (one) provides basic\n\
24067 information. A value greater than 1 provides more verbose information."),
24070 &setdebuglist
, &showdebuglist
);
24072 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24073 Set debugging of the DWARF DIE reader."), _("\
24074 Show debugging of the DWARF DIE reader."), _("\
24075 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24076 The value is the maximum depth to print."),
24079 &setdebuglist
, &showdebuglist
);
24081 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24082 Set debugging of the dwarf line reader."), _("\
24083 Show debugging of the dwarf line reader."), _("\
24084 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24085 A value of 1 (one) provides basic information.\n\
24086 A value greater than 1 provides more verbose information."),
24089 &setdebuglist
, &showdebuglist
);
24091 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24092 Set cross-checking of \"physname\" code against demangler."), _("\
24093 Show cross-checking of \"physname\" code against demangler."), _("\
24094 When enabled, GDB's internal \"physname\" code is checked against\n\
24096 NULL
, show_check_physname
,
24097 &setdebuglist
, &showdebuglist
);
24099 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24100 no_class
, &use_deprecated_index_sections
, _("\
24101 Set whether to use deprecated gdb_index sections."), _("\
24102 Show whether to use deprecated gdb_index sections."), _("\
24103 When enabled, deprecated .gdb_index sections are used anyway.\n\
24104 Normally they are ignored either because of a missing feature or\n\
24105 performance issue.\n\
24106 Warning: This option must be enabled before gdb reads the file."),
24109 &setlist
, &showlist
);
24111 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
24113 Save a gdb-index file.\n\
24114 Usage: save gdb-index DIRECTORY"),
24116 set_cmd_completer (c
, filename_completer
);
24118 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24119 &dwarf2_locexpr_funcs
);
24120 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24121 &dwarf2_loclist_funcs
);
24123 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24124 &dwarf2_block_frame_base_locexpr_funcs
);
24125 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24126 &dwarf2_block_frame_base_loclist_funcs
);