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"
75 #include <sys/types.h>
78 typedef struct symbol
*symbolp
;
81 /* When == 1, print basic high level tracing messages.
82 When > 1, be more verbose.
83 This is in contrast to the low level DIE reading of dwarf_die_debug. */
84 static unsigned int dwarf_read_debug
= 0;
86 /* When non-zero, dump DIEs after they are read in. */
87 static unsigned int dwarf_die_debug
= 0;
89 /* When non-zero, dump line number entries as they are read in. */
90 static unsigned int dwarf_line_debug
= 0;
92 /* When non-zero, cross-check physname against demangler. */
93 static int check_physname
= 0;
95 /* When non-zero, do not reject deprecated .gdb_index sections. */
96 static int use_deprecated_index_sections
= 0;
98 static const struct objfile_data
*dwarf2_objfile_data_key
;
100 /* The "aclass" indices for various kinds of computed DWARF symbols. */
102 static int dwarf2_locexpr_index
;
103 static int dwarf2_loclist_index
;
104 static int dwarf2_locexpr_block_index
;
105 static int dwarf2_loclist_block_index
;
107 /* A descriptor for dwarf sections.
109 S.ASECTION, SIZE are typically initialized when the objfile is first
110 scanned. BUFFER, READIN are filled in later when the section is read.
111 If the section contained compressed data then SIZE is updated to record
112 the uncompressed size of the section.
114 DWP file format V2 introduces a wrinkle that is easiest to handle by
115 creating the concept of virtual sections contained within a real section.
116 In DWP V2 the sections of the input DWO files are concatenated together
117 into one section, but section offsets are kept relative to the original
119 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
120 the real section this "virtual" section is contained in, and BUFFER,SIZE
121 describe the virtual section. */
123 struct dwarf2_section_info
127 /* If this is a real section, the bfd section. */
129 /* If this is a virtual section, pointer to the containing ("real")
131 struct dwarf2_section_info
*containing_section
;
133 /* Pointer to section data, only valid if readin. */
134 const gdb_byte
*buffer
;
135 /* The size of the section, real or virtual. */
137 /* If this is a virtual section, the offset in the real section.
138 Only valid if is_virtual. */
139 bfd_size_type virtual_offset
;
140 /* True if we have tried to read this section. */
142 /* True if this is a virtual section, False otherwise.
143 This specifies which of s.section and s.containing_section to use. */
147 typedef struct dwarf2_section_info dwarf2_section_info_def
;
148 DEF_VEC_O (dwarf2_section_info_def
);
150 /* All offsets in the index are of this type. It must be
151 architecture-independent. */
152 typedef uint32_t offset_type
;
154 DEF_VEC_I (offset_type
);
156 /* Ensure only legit values are used. */
157 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
159 gdb_assert ((unsigned int) (value) <= 1); \
160 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
163 /* Ensure only legit values are used. */
164 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
166 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
167 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
168 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
171 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
172 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
174 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
175 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
178 /* A description of the mapped index. The file format is described in
179 a comment by the code that writes the index. */
182 /* Index data format version. */
185 /* The total length of the buffer. */
188 /* A pointer to the address table data. */
189 const gdb_byte
*address_table
;
191 /* Size of the address table data in bytes. */
192 offset_type address_table_size
;
194 /* The symbol table, implemented as a hash table. */
195 const offset_type
*symbol_table
;
197 /* Size in slots, each slot is 2 offset_types. */
198 offset_type symbol_table_slots
;
200 /* A pointer to the constant pool. */
201 const char *constant_pool
;
204 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
205 DEF_VEC_P (dwarf2_per_cu_ptr
);
209 int nr_uniq_abbrev_tables
;
211 int nr_symtab_sharers
;
212 int nr_stmt_less_type_units
;
213 int nr_all_type_units_reallocs
;
216 /* Collection of data recorded per objfile.
217 This hangs off of dwarf2_objfile_data_key. */
219 struct dwarf2_per_objfile
221 struct dwarf2_section_info info
;
222 struct dwarf2_section_info abbrev
;
223 struct dwarf2_section_info line
;
224 struct dwarf2_section_info loc
;
225 struct dwarf2_section_info macinfo
;
226 struct dwarf2_section_info macro
;
227 struct dwarf2_section_info str
;
228 struct dwarf2_section_info ranges
;
229 struct dwarf2_section_info addr
;
230 struct dwarf2_section_info frame
;
231 struct dwarf2_section_info eh_frame
;
232 struct dwarf2_section_info gdb_index
;
234 VEC (dwarf2_section_info_def
) *types
;
237 struct objfile
*objfile
;
239 /* Table of all the compilation units. This is used to locate
240 the target compilation unit of a particular reference. */
241 struct dwarf2_per_cu_data
**all_comp_units
;
243 /* The number of compilation units in ALL_COMP_UNITS. */
246 /* The number of .debug_types-related CUs. */
249 /* The number of elements allocated in all_type_units.
250 If there are skeleton-less TUs, we add them to all_type_units lazily. */
251 int n_allocated_type_units
;
253 /* The .debug_types-related CUs (TUs).
254 This is stored in malloc space because we may realloc it. */
255 struct signatured_type
**all_type_units
;
257 /* Table of struct type_unit_group objects.
258 The hash key is the DW_AT_stmt_list value. */
259 htab_t type_unit_groups
;
261 /* A table mapping .debug_types signatures to its signatured_type entry.
262 This is NULL if the .debug_types section hasn't been read in yet. */
263 htab_t signatured_types
;
265 /* Type unit statistics, to see how well the scaling improvements
267 struct tu_stats tu_stats
;
269 /* A chain of compilation units that are currently read in, so that
270 they can be freed later. */
271 struct dwarf2_per_cu_data
*read_in_chain
;
273 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
274 This is NULL if the table hasn't been allocated yet. */
277 /* Non-zero if we've check for whether there is a DWP file. */
280 /* The DWP file if there is one, or NULL. */
281 struct dwp_file
*dwp_file
;
283 /* The shared '.dwz' file, if one exists. This is used when the
284 original data was compressed using 'dwz -m'. */
285 struct dwz_file
*dwz_file
;
287 /* A flag indicating wether this objfile has a section loaded at a
289 int has_section_at_zero
;
291 /* True if we are using the mapped index,
292 or we are faking it for OBJF_READNOW's sake. */
293 unsigned char using_index
;
295 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
296 struct mapped_index
*index_table
;
298 /* When using index_table, this keeps track of all quick_file_names entries.
299 TUs typically share line table entries with a CU, so we maintain a
300 separate table of all line table entries to support the sharing.
301 Note that while there can be way more TUs than CUs, we've already
302 sorted all the TUs into "type unit groups", grouped by their
303 DW_AT_stmt_list value. Therefore the only sharing done here is with a
304 CU and its associated TU group if there is one. */
305 htab_t quick_file_names_table
;
307 /* Set during partial symbol reading, to prevent queueing of full
309 int reading_partial_symbols
;
311 /* Table mapping type DIEs to their struct type *.
312 This is NULL if not allocated yet.
313 The mapping is done via (CU/TU + DIE offset) -> type. */
314 htab_t die_type_hash
;
316 /* The CUs we recently read. */
317 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
319 /* Table containing line_header indexed by offset and offset_in_dwz. */
320 htab_t line_header_hash
;
323 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
325 /* Default names of the debugging sections. */
327 /* Note that if the debugging section has been compressed, it might
328 have a name like .zdebug_info. */
330 static const struct dwarf2_debug_sections dwarf2_elf_names
=
332 { ".debug_info", ".zdebug_info" },
333 { ".debug_abbrev", ".zdebug_abbrev" },
334 { ".debug_line", ".zdebug_line" },
335 { ".debug_loc", ".zdebug_loc" },
336 { ".debug_macinfo", ".zdebug_macinfo" },
337 { ".debug_macro", ".zdebug_macro" },
338 { ".debug_str", ".zdebug_str" },
339 { ".debug_ranges", ".zdebug_ranges" },
340 { ".debug_types", ".zdebug_types" },
341 { ".debug_addr", ".zdebug_addr" },
342 { ".debug_frame", ".zdebug_frame" },
343 { ".eh_frame", NULL
},
344 { ".gdb_index", ".zgdb_index" },
348 /* List of DWO/DWP sections. */
350 static const struct dwop_section_names
352 struct dwarf2_section_names abbrev_dwo
;
353 struct dwarf2_section_names info_dwo
;
354 struct dwarf2_section_names line_dwo
;
355 struct dwarf2_section_names loc_dwo
;
356 struct dwarf2_section_names macinfo_dwo
;
357 struct dwarf2_section_names macro_dwo
;
358 struct dwarf2_section_names str_dwo
;
359 struct dwarf2_section_names str_offsets_dwo
;
360 struct dwarf2_section_names types_dwo
;
361 struct dwarf2_section_names cu_index
;
362 struct dwarf2_section_names tu_index
;
366 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
367 { ".debug_info.dwo", ".zdebug_info.dwo" },
368 { ".debug_line.dwo", ".zdebug_line.dwo" },
369 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
370 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
371 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
372 { ".debug_str.dwo", ".zdebug_str.dwo" },
373 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
374 { ".debug_types.dwo", ".zdebug_types.dwo" },
375 { ".debug_cu_index", ".zdebug_cu_index" },
376 { ".debug_tu_index", ".zdebug_tu_index" },
379 /* local data types */
381 /* The data in a compilation unit header, after target2host
382 translation, looks like this. */
383 struct comp_unit_head
387 unsigned char addr_size
;
388 unsigned char signed_addr_p
;
389 sect_offset abbrev_offset
;
391 /* Size of file offsets; either 4 or 8. */
392 unsigned int offset_size
;
394 /* Size of the length field; either 4 or 12. */
395 unsigned int initial_length_size
;
397 /* Offset to the first byte of this compilation unit header in the
398 .debug_info section, for resolving relative reference dies. */
401 /* Offset to first die in this cu from the start of the cu.
402 This will be the first byte following the compilation unit header. */
403 cu_offset first_die_offset
;
406 /* Type used for delaying computation of method physnames.
407 See comments for compute_delayed_physnames. */
408 struct delayed_method_info
410 /* The type to which the method is attached, i.e., its parent class. */
413 /* The index of the method in the type's function fieldlists. */
416 /* The index of the method in the fieldlist. */
419 /* The name of the DIE. */
422 /* The DIE associated with this method. */
423 struct die_info
*die
;
426 typedef struct delayed_method_info delayed_method_info
;
427 DEF_VEC_O (delayed_method_info
);
429 /* Internal state when decoding a particular compilation unit. */
432 /* The objfile containing this compilation unit. */
433 struct objfile
*objfile
;
435 /* The header of the compilation unit. */
436 struct comp_unit_head header
;
438 /* Base address of this compilation unit. */
439 CORE_ADDR base_address
;
441 /* Non-zero if base_address has been set. */
444 /* The language we are debugging. */
445 enum language language
;
446 const struct language_defn
*language_defn
;
448 const char *producer
;
450 /* The generic symbol table building routines have separate lists for
451 file scope symbols and all all other scopes (local scopes). So
452 we need to select the right one to pass to add_symbol_to_list().
453 We do it by keeping a pointer to the correct list in list_in_scope.
455 FIXME: The original dwarf code just treated the file scope as the
456 first local scope, and all other local scopes as nested local
457 scopes, and worked fine. Check to see if we really need to
458 distinguish these in buildsym.c. */
459 struct pending
**list_in_scope
;
461 /* The abbrev table for this CU.
462 Normally this points to the abbrev table in the objfile.
463 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
464 struct abbrev_table
*abbrev_table
;
466 /* Hash table holding all the loaded partial DIEs
467 with partial_die->offset.SECT_OFF as hash. */
470 /* Storage for things with the same lifetime as this read-in compilation
471 unit, including partial DIEs. */
472 struct obstack comp_unit_obstack
;
474 /* When multiple dwarf2_cu structures are living in memory, this field
475 chains them all together, so that they can be released efficiently.
476 We will probably also want a generation counter so that most-recently-used
477 compilation units are cached... */
478 struct dwarf2_per_cu_data
*read_in_chain
;
480 /* Backlink to our per_cu entry. */
481 struct dwarf2_per_cu_data
*per_cu
;
483 /* How many compilation units ago was this CU last referenced? */
486 /* A hash table of DIE cu_offset for following references with
487 die_info->offset.sect_off as hash. */
490 /* Full DIEs if read in. */
491 struct die_info
*dies
;
493 /* A set of pointers to dwarf2_per_cu_data objects for compilation
494 units referenced by this one. Only set during full symbol processing;
495 partial symbol tables do not have dependencies. */
498 /* Header data from the line table, during full symbol processing. */
499 struct line_header
*line_header
;
501 /* A list of methods which need to have physnames computed
502 after all type information has been read. */
503 VEC (delayed_method_info
) *method_list
;
505 /* To be copied to symtab->call_site_htab. */
506 htab_t call_site_htab
;
508 /* Non-NULL if this CU came from a DWO file.
509 There is an invariant here that is important to remember:
510 Except for attributes copied from the top level DIE in the "main"
511 (or "stub") file in preparation for reading the DWO file
512 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
513 Either there isn't a DWO file (in which case this is NULL and the point
514 is moot), or there is and either we're not going to read it (in which
515 case this is NULL) or there is and we are reading it (in which case this
517 struct dwo_unit
*dwo_unit
;
519 /* The DW_AT_addr_base attribute if present, zero otherwise
520 (zero is a valid value though).
521 Note this value comes from the Fission stub CU/TU's DIE. */
524 /* The DW_AT_ranges_base attribute if present, zero otherwise
525 (zero is a valid value though).
526 Note this value comes from the Fission stub CU/TU's DIE.
527 Also note that the value is zero in the non-DWO case so this value can
528 be used without needing to know whether DWO files are in use or not.
529 N.B. This does not apply to DW_AT_ranges appearing in
530 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
531 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
532 DW_AT_ranges_base *would* have to be applied, and we'd have to care
533 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
534 ULONGEST ranges_base
;
536 /* Mark used when releasing cached dies. */
537 unsigned int mark
: 1;
539 /* This CU references .debug_loc. See the symtab->locations_valid field.
540 This test is imperfect as there may exist optimized debug code not using
541 any location list and still facing inlining issues if handled as
542 unoptimized code. For a future better test see GCC PR other/32998. */
543 unsigned int has_loclist
: 1;
545 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
546 if all the producer_is_* fields are valid. This information is cached
547 because profiling CU expansion showed excessive time spent in
548 producer_is_gxx_lt_4_6. */
549 unsigned int checked_producer
: 1;
550 unsigned int producer_is_gxx_lt_4_6
: 1;
551 unsigned int producer_is_gcc_lt_4_3
: 1;
552 unsigned int producer_is_icc
: 1;
554 /* When set, the file that we're processing is known to have
555 debugging info for C++ namespaces. GCC 3.3.x did not produce
556 this information, but later versions do. */
558 unsigned int processing_has_namespace_info
: 1;
561 /* Persistent data held for a compilation unit, even when not
562 processing it. We put a pointer to this structure in the
563 read_symtab_private field of the psymtab. */
565 struct dwarf2_per_cu_data
567 /* The start offset and length of this compilation unit.
568 NOTE: Unlike comp_unit_head.length, this length includes
570 If the DIE refers to a DWO file, this is always of the original die,
575 /* Flag indicating this compilation unit will be read in before
576 any of the current compilation units are processed. */
577 unsigned int queued
: 1;
579 /* This flag will be set when reading partial DIEs if we need to load
580 absolutely all DIEs for this compilation unit, instead of just the ones
581 we think are interesting. It gets set if we look for a DIE in the
582 hash table and don't find it. */
583 unsigned int load_all_dies
: 1;
585 /* Non-zero if this CU is from .debug_types.
586 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
588 unsigned int is_debug_types
: 1;
590 /* Non-zero if this CU is from the .dwz file. */
591 unsigned int is_dwz
: 1;
593 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
594 This flag is only valid if is_debug_types is true.
595 We can't read a CU directly from a DWO file: There are required
596 attributes in the stub. */
597 unsigned int reading_dwo_directly
: 1;
599 /* Non-zero if the TU has been read.
600 This is used to assist the "Stay in DWO Optimization" for Fission:
601 When reading a DWO, it's faster to read TUs from the DWO instead of
602 fetching them from random other DWOs (due to comdat folding).
603 If the TU has already been read, the optimization is unnecessary
604 (and unwise - we don't want to change where gdb thinks the TU lives
606 This flag is only valid if is_debug_types is true. */
607 unsigned int tu_read
: 1;
609 /* The section this CU/TU lives in.
610 If the DIE refers to a DWO file, this is always the original die,
612 struct dwarf2_section_info
*section
;
614 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
615 of the CU cache it gets reset to NULL again. This is left as NULL for
616 dummy CUs (a CU header, but nothing else). */
617 struct dwarf2_cu
*cu
;
619 /* The corresponding objfile.
620 Normally we can get the objfile from dwarf2_per_objfile.
621 However we can enter this file with just a "per_cu" handle. */
622 struct objfile
*objfile
;
624 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
625 is active. Otherwise, the 'psymtab' field is active. */
628 /* The partial symbol table associated with this compilation unit,
629 or NULL for unread partial units. */
630 struct partial_symtab
*psymtab
;
632 /* Data needed by the "quick" functions. */
633 struct dwarf2_per_cu_quick_data
*quick
;
636 /* The CUs we import using DW_TAG_imported_unit. This is filled in
637 while reading psymtabs, used to compute the psymtab dependencies,
638 and then cleared. Then it is filled in again while reading full
639 symbols, and only deleted when the objfile is destroyed.
641 This is also used to work around a difference between the way gold
642 generates .gdb_index version <=7 and the way gdb does. Arguably this
643 is a gold bug. For symbols coming from TUs, gold records in the index
644 the CU that includes the TU instead of the TU itself. This breaks
645 dw2_lookup_symbol: It assumes that if the index says symbol X lives
646 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
647 will find X. Alas TUs live in their own symtab, so after expanding CU Y
648 we need to look in TU Z to find X. Fortunately, this is akin to
649 DW_TAG_imported_unit, so we just use the same mechanism: For
650 .gdb_index version <=7 this also records the TUs that the CU referred
651 to. Concurrently with this change gdb was modified to emit version 8
652 indices so we only pay a price for gold generated indices.
653 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
654 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
657 /* Entry in the signatured_types hash table. */
659 struct signatured_type
661 /* The "per_cu" object of this type.
662 This struct is used iff per_cu.is_debug_types.
663 N.B.: This is the first member so that it's easy to convert pointers
665 struct dwarf2_per_cu_data per_cu
;
667 /* The type's signature. */
670 /* Offset in the TU of the type's DIE, as read from the TU header.
671 If this TU is a DWO stub and the definition lives in a DWO file
672 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
673 cu_offset type_offset_in_tu
;
675 /* Offset in the section of the type's DIE.
676 If the definition lives in a DWO file, this is the offset in the
677 .debug_types.dwo section.
678 The value is zero until the actual value is known.
679 Zero is otherwise not a valid section offset. */
680 sect_offset type_offset_in_section
;
682 /* Type units are grouped by their DW_AT_stmt_list entry so that they
683 can share them. This points to the containing symtab. */
684 struct type_unit_group
*type_unit_group
;
687 The first time we encounter this type we fully read it in and install it
688 in the symbol tables. Subsequent times we only need the type. */
691 /* Containing DWO unit.
692 This field is valid iff per_cu.reading_dwo_directly. */
693 struct dwo_unit
*dwo_unit
;
696 typedef struct signatured_type
*sig_type_ptr
;
697 DEF_VEC_P (sig_type_ptr
);
699 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
700 This includes type_unit_group and quick_file_names. */
702 struct stmt_list_hash
704 /* The DWO unit this table is from or NULL if there is none. */
705 struct dwo_unit
*dwo_unit
;
707 /* Offset in .debug_line or .debug_line.dwo. */
708 sect_offset line_offset
;
711 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
712 an object of this type. */
714 struct type_unit_group
716 /* dwarf2read.c's main "handle" on a TU symtab.
717 To simplify things we create an artificial CU that "includes" all the
718 type units using this stmt_list so that the rest of the code still has
719 a "per_cu" handle on the symtab.
720 This PER_CU is recognized by having no section. */
721 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
722 struct dwarf2_per_cu_data per_cu
;
724 /* The TUs that share this DW_AT_stmt_list entry.
725 This is added to while parsing type units to build partial symtabs,
726 and is deleted afterwards and not used again. */
727 VEC (sig_type_ptr
) *tus
;
729 /* The compunit symtab.
730 Type units in a group needn't all be defined in the same source file,
731 so we create an essentially anonymous symtab as the compunit symtab. */
732 struct compunit_symtab
*compunit_symtab
;
734 /* The data used to construct the hash key. */
735 struct stmt_list_hash hash
;
737 /* The number of symtabs from the line header.
738 The value here must match line_header.num_file_names. */
739 unsigned int num_symtabs
;
741 /* The symbol tables for this TU (obtained from the files listed in
743 WARNING: The order of entries here must match the order of entries
744 in the line header. After the first TU using this type_unit_group, the
745 line header for the subsequent TUs is recreated from this. This is done
746 because we need to use the same symtabs for each TU using the same
747 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
748 there's no guarantee the line header doesn't have duplicate entries. */
749 struct symtab
**symtabs
;
752 /* These sections are what may appear in a (real or virtual) DWO file. */
756 struct dwarf2_section_info abbrev
;
757 struct dwarf2_section_info line
;
758 struct dwarf2_section_info loc
;
759 struct dwarf2_section_info macinfo
;
760 struct dwarf2_section_info macro
;
761 struct dwarf2_section_info str
;
762 struct dwarf2_section_info str_offsets
;
763 /* In the case of a virtual DWO file, these two are unused. */
764 struct dwarf2_section_info info
;
765 VEC (dwarf2_section_info_def
) *types
;
768 /* CUs/TUs in DWP/DWO files. */
772 /* Backlink to the containing struct dwo_file. */
773 struct dwo_file
*dwo_file
;
775 /* The "id" that distinguishes this CU/TU.
776 .debug_info calls this "dwo_id", .debug_types calls this "signature".
777 Since signatures came first, we stick with it for consistency. */
780 /* The section this CU/TU lives in, in the DWO file. */
781 struct dwarf2_section_info
*section
;
783 /* Same as dwarf2_per_cu_data:{offset,length} but in the DWO section. */
787 /* For types, offset in the type's DIE of the type defined by this TU. */
788 cu_offset type_offset_in_tu
;
791 /* include/dwarf2.h defines the DWP section codes.
792 It defines a max value but it doesn't define a min value, which we
793 use for error checking, so provide one. */
795 enum dwp_v2_section_ids
800 /* Data for one DWO file.
802 This includes virtual DWO files (a virtual DWO file is a DWO file as it
803 appears in a DWP file). DWP files don't really have DWO files per se -
804 comdat folding of types "loses" the DWO file they came from, and from
805 a high level view DWP files appear to contain a mass of random types.
806 However, to maintain consistency with the non-DWP case we pretend DWP
807 files contain virtual DWO files, and we assign each TU with one virtual
808 DWO file (generally based on the line and abbrev section offsets -
809 a heuristic that seems to work in practice). */
813 /* The DW_AT_GNU_dwo_name attribute.
814 For virtual DWO files the name is constructed from the section offsets
815 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
816 from related CU+TUs. */
817 const char *dwo_name
;
819 /* The DW_AT_comp_dir attribute. */
820 const char *comp_dir
;
822 /* The bfd, when the file is open. Otherwise this is NULL.
823 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
826 /* The sections that make up this DWO file.
827 Remember that for virtual DWO files in DWP V2, these are virtual
828 sections (for lack of a better name). */
829 struct dwo_sections sections
;
831 /* The CU in the file.
832 We only support one because having more than one requires hacking the
833 dwo_name of each to match, which is highly unlikely to happen.
834 Doing this means all TUs can share comp_dir: We also assume that
835 DW_AT_comp_dir across all TUs in a DWO file will be identical. */
838 /* Table of TUs in the file.
839 Each element is a struct dwo_unit. */
843 /* These sections are what may appear in a DWP file. */
847 /* These are used by both DWP version 1 and 2. */
848 struct dwarf2_section_info str
;
849 struct dwarf2_section_info cu_index
;
850 struct dwarf2_section_info tu_index
;
852 /* These are only used by DWP version 2 files.
853 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
854 sections are referenced by section number, and are not recorded here.
855 In DWP version 2 there is at most one copy of all these sections, each
856 section being (effectively) comprised of the concatenation of all of the
857 individual sections that exist in the version 1 format.
858 To keep the code simple we treat each of these concatenated pieces as a
859 section itself (a virtual section?). */
860 struct dwarf2_section_info abbrev
;
861 struct dwarf2_section_info info
;
862 struct dwarf2_section_info line
;
863 struct dwarf2_section_info loc
;
864 struct dwarf2_section_info macinfo
;
865 struct dwarf2_section_info macro
;
866 struct dwarf2_section_info str_offsets
;
867 struct dwarf2_section_info types
;
870 /* These sections are what may appear in a virtual DWO file in DWP version 1.
871 A virtual DWO file is a DWO file as it appears in a DWP file. */
873 struct virtual_v1_dwo_sections
875 struct dwarf2_section_info abbrev
;
876 struct dwarf2_section_info line
;
877 struct dwarf2_section_info loc
;
878 struct dwarf2_section_info macinfo
;
879 struct dwarf2_section_info macro
;
880 struct dwarf2_section_info str_offsets
;
881 /* Each DWP hash table entry records one CU or one TU.
882 That is recorded here, and copied to dwo_unit.section. */
883 struct dwarf2_section_info info_or_types
;
886 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
887 In version 2, the sections of the DWO files are concatenated together
888 and stored in one section of that name. Thus each ELF section contains
889 several "virtual" sections. */
891 struct virtual_v2_dwo_sections
893 bfd_size_type abbrev_offset
;
894 bfd_size_type abbrev_size
;
896 bfd_size_type line_offset
;
897 bfd_size_type line_size
;
899 bfd_size_type loc_offset
;
900 bfd_size_type loc_size
;
902 bfd_size_type macinfo_offset
;
903 bfd_size_type macinfo_size
;
905 bfd_size_type macro_offset
;
906 bfd_size_type macro_size
;
908 bfd_size_type str_offsets_offset
;
909 bfd_size_type str_offsets_size
;
911 /* Each DWP hash table entry records one CU or one TU.
912 That is recorded here, and copied to dwo_unit.section. */
913 bfd_size_type info_or_types_offset
;
914 bfd_size_type info_or_types_size
;
917 /* Contents of DWP hash tables. */
919 struct dwp_hash_table
921 uint32_t version
, nr_columns
;
922 uint32_t nr_units
, nr_slots
;
923 const gdb_byte
*hash_table
, *unit_table
;
928 const gdb_byte
*indices
;
932 /* This is indexed by column number and gives the id of the section
934 #define MAX_NR_V2_DWO_SECTIONS \
935 (1 /* .debug_info or .debug_types */ \
936 + 1 /* .debug_abbrev */ \
937 + 1 /* .debug_line */ \
938 + 1 /* .debug_loc */ \
939 + 1 /* .debug_str_offsets */ \
940 + 1 /* .debug_macro or .debug_macinfo */)
941 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
942 const gdb_byte
*offsets
;
943 const gdb_byte
*sizes
;
948 /* Data for one DWP file. */
952 /* Name of the file. */
955 /* File format version. */
961 /* Section info for this file. */
962 struct dwp_sections sections
;
964 /* Table of CUs in the file. */
965 const struct dwp_hash_table
*cus
;
967 /* Table of TUs in the file. */
968 const struct dwp_hash_table
*tus
;
970 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
974 /* Table to map ELF section numbers to their sections.
975 This is only needed for the DWP V1 file format. */
976 unsigned int num_sections
;
977 asection
**elf_sections
;
980 /* This represents a '.dwz' file. */
984 /* A dwz file can only contain a few sections. */
985 struct dwarf2_section_info abbrev
;
986 struct dwarf2_section_info info
;
987 struct dwarf2_section_info str
;
988 struct dwarf2_section_info line
;
989 struct dwarf2_section_info macro
;
990 struct dwarf2_section_info gdb_index
;
996 /* Struct used to pass misc. parameters to read_die_and_children, et
997 al. which are used for both .debug_info and .debug_types dies.
998 All parameters here are unchanging for the life of the call. This
999 struct exists to abstract away the constant parameters of die reading. */
1001 struct die_reader_specs
1003 /* The bfd of die_section. */
1006 /* The CU of the DIE we are parsing. */
1007 struct dwarf2_cu
*cu
;
1009 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1010 struct dwo_file
*dwo_file
;
1012 /* The section the die comes from.
1013 This is either .debug_info or .debug_types, or the .dwo variants. */
1014 struct dwarf2_section_info
*die_section
;
1016 /* die_section->buffer. */
1017 const gdb_byte
*buffer
;
1019 /* The end of the buffer. */
1020 const gdb_byte
*buffer_end
;
1022 /* The value of the DW_AT_comp_dir attribute. */
1023 const char *comp_dir
;
1026 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1027 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1028 const gdb_byte
*info_ptr
,
1029 struct die_info
*comp_unit_die
,
1036 unsigned int dir_index
;
1037 unsigned int mod_time
;
1038 unsigned int length
;
1039 /* Non-zero if referenced by the Line Number Program. */
1041 /* The associated symbol table, if any. */
1042 struct symtab
*symtab
;
1045 /* The line number information for a compilation unit (found in the
1046 .debug_line section) begins with a "statement program header",
1047 which contains the following information. */
1050 /* Offset of line number information in .debug_line section. */
1053 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1054 unsigned offset_in_dwz
: 1;
1056 unsigned int total_length
;
1057 unsigned short version
;
1058 unsigned int header_length
;
1059 unsigned char minimum_instruction_length
;
1060 unsigned char maximum_ops_per_instruction
;
1061 unsigned char default_is_stmt
;
1063 unsigned char line_range
;
1064 unsigned char opcode_base
;
1066 /* standard_opcode_lengths[i] is the number of operands for the
1067 standard opcode whose value is i. This means that
1068 standard_opcode_lengths[0] is unused, and the last meaningful
1069 element is standard_opcode_lengths[opcode_base - 1]. */
1070 unsigned char *standard_opcode_lengths
;
1072 /* The include_directories table. NOTE! These strings are not
1073 allocated with xmalloc; instead, they are pointers into
1074 debug_line_buffer. If you try to free them, `free' will get
1076 unsigned int num_include_dirs
, include_dirs_size
;
1077 const char **include_dirs
;
1079 /* The file_names table. NOTE! These strings are not allocated
1080 with xmalloc; instead, they are pointers into debug_line_buffer.
1081 Don't try to free them directly. */
1082 unsigned int num_file_names
, file_names_size
;
1083 struct file_entry
*file_names
;
1085 /* The start and end of the statement program following this
1086 header. These point into dwarf2_per_objfile->line_buffer. */
1087 const gdb_byte
*statement_program_start
, *statement_program_end
;
1090 /* When we construct a partial symbol table entry we only
1091 need this much information. */
1092 struct partial_die_info
1094 /* Offset of this DIE. */
1097 /* DWARF-2 tag for this DIE. */
1098 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1100 /* Assorted flags describing the data found in this DIE. */
1101 unsigned int has_children
: 1;
1102 unsigned int is_external
: 1;
1103 unsigned int is_declaration
: 1;
1104 unsigned int has_type
: 1;
1105 unsigned int has_specification
: 1;
1106 unsigned int has_pc_info
: 1;
1107 unsigned int may_be_inlined
: 1;
1109 /* This DIE has been marked DW_AT_main_subprogram. */
1110 unsigned int main_subprogram
: 1;
1112 /* Flag set if the SCOPE field of this structure has been
1114 unsigned int scope_set
: 1;
1116 /* Flag set if the DIE has a byte_size attribute. */
1117 unsigned int has_byte_size
: 1;
1119 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1120 unsigned int has_const_value
: 1;
1122 /* Flag set if any of the DIE's children are template arguments. */
1123 unsigned int has_template_arguments
: 1;
1125 /* Flag set if fixup_partial_die has been called on this die. */
1126 unsigned int fixup_called
: 1;
1128 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1129 unsigned int is_dwz
: 1;
1131 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1132 unsigned int spec_is_dwz
: 1;
1134 /* The name of this DIE. Normally the value of DW_AT_name, but
1135 sometimes a default name for unnamed DIEs. */
1138 /* The linkage name, if present. */
1139 const char *linkage_name
;
1141 /* The scope to prepend to our children. This is generally
1142 allocated on the comp_unit_obstack, so will disappear
1143 when this compilation unit leaves the cache. */
1146 /* Some data associated with the partial DIE. The tag determines
1147 which field is live. */
1150 /* The location description associated with this DIE, if any. */
1151 struct dwarf_block
*locdesc
;
1152 /* The offset of an import, for DW_TAG_imported_unit. */
1156 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1160 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1161 DW_AT_sibling, if any. */
1162 /* NOTE: This member isn't strictly necessary, read_partial_die could
1163 return DW_AT_sibling values to its caller load_partial_dies. */
1164 const gdb_byte
*sibling
;
1166 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1167 DW_AT_specification (or DW_AT_abstract_origin or
1168 DW_AT_extension). */
1169 sect_offset spec_offset
;
1171 /* Pointers to this DIE's parent, first child, and next sibling,
1173 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
1176 /* This data structure holds the information of an abbrev. */
1179 unsigned int number
; /* number identifying abbrev */
1180 enum dwarf_tag tag
; /* dwarf tag */
1181 unsigned short has_children
; /* boolean */
1182 unsigned short num_attrs
; /* number of attributes */
1183 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1184 struct abbrev_info
*next
; /* next in chain */
1189 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1190 ENUM_BITFIELD(dwarf_form
) form
: 16;
1193 /* Size of abbrev_table.abbrev_hash_table. */
1194 #define ABBREV_HASH_SIZE 121
1196 /* Top level data structure to contain an abbreviation table. */
1200 /* Where the abbrev table came from.
1201 This is used as a sanity check when the table is used. */
1204 /* Storage for the abbrev table. */
1205 struct obstack abbrev_obstack
;
1207 /* Hash table of abbrevs.
1208 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1209 It could be statically allocated, but the previous code didn't so we
1211 struct abbrev_info
**abbrevs
;
1214 /* Attributes have a name and a value. */
1217 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1218 ENUM_BITFIELD(dwarf_form
) form
: 15;
1220 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1221 field should be in u.str (existing only for DW_STRING) but it is kept
1222 here for better struct attribute alignment. */
1223 unsigned int string_is_canonical
: 1;
1228 struct dwarf_block
*blk
;
1237 /* This data structure holds a complete die structure. */
1240 /* DWARF-2 tag for this DIE. */
1241 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1243 /* Number of attributes */
1244 unsigned char num_attrs
;
1246 /* True if we're presently building the full type name for the
1247 type derived from this DIE. */
1248 unsigned char building_fullname
: 1;
1250 /* True if this die is in process. PR 16581. */
1251 unsigned char in_process
: 1;
1254 unsigned int abbrev
;
1256 /* Offset in .debug_info or .debug_types section. */
1259 /* The dies in a compilation unit form an n-ary tree. PARENT
1260 points to this die's parent; CHILD points to the first child of
1261 this node; and all the children of a given node are chained
1262 together via their SIBLING fields. */
1263 struct die_info
*child
; /* Its first child, if any. */
1264 struct die_info
*sibling
; /* Its next sibling, if any. */
1265 struct die_info
*parent
; /* Its parent, if any. */
1267 /* An array of attributes, with NUM_ATTRS elements. There may be
1268 zero, but it's not common and zero-sized arrays are not
1269 sufficiently portable C. */
1270 struct attribute attrs
[1];
1273 /* Get at parts of an attribute structure. */
1275 #define DW_STRING(attr) ((attr)->u.str)
1276 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1277 #define DW_UNSND(attr) ((attr)->u.unsnd)
1278 #define DW_BLOCK(attr) ((attr)->u.blk)
1279 #define DW_SND(attr) ((attr)->u.snd)
1280 #define DW_ADDR(attr) ((attr)->u.addr)
1281 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1283 /* Blocks are a bunch of untyped bytes. */
1288 /* Valid only if SIZE is not zero. */
1289 const gdb_byte
*data
;
1292 #ifndef ATTR_ALLOC_CHUNK
1293 #define ATTR_ALLOC_CHUNK 4
1296 /* Allocate fields for structs, unions and enums in this size. */
1297 #ifndef DW_FIELD_ALLOC_CHUNK
1298 #define DW_FIELD_ALLOC_CHUNK 4
1301 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1302 but this would require a corresponding change in unpack_field_as_long
1304 static int bits_per_byte
= 8;
1308 struct nextfield
*next
;
1316 struct nextfnfield
*next
;
1317 struct fn_field fnfield
;
1324 struct nextfnfield
*head
;
1327 struct typedef_field_list
1329 struct typedef_field field
;
1330 struct typedef_field_list
*next
;
1333 /* The routines that read and process dies for a C struct or C++ class
1334 pass lists of data member fields and lists of member function fields
1335 in an instance of a field_info structure, as defined below. */
1338 /* List of data member and baseclasses fields. */
1339 struct nextfield
*fields
, *baseclasses
;
1341 /* Number of fields (including baseclasses). */
1344 /* Number of baseclasses. */
1347 /* Set if the accesibility of one of the fields is not public. */
1348 int non_public_fields
;
1350 /* Member function fields array, entries are allocated in the order they
1351 are encountered in the object file. */
1352 struct nextfnfield
*fnfields
;
1354 /* Member function fieldlist array, contains name of possibly overloaded
1355 member function, number of overloaded member functions and a pointer
1356 to the head of the member function field chain. */
1357 struct fnfieldlist
*fnfieldlists
;
1359 /* Number of entries in the fnfieldlists array. */
1362 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1363 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1364 struct typedef_field_list
*typedef_field_list
;
1365 unsigned typedef_field_list_count
;
1368 /* One item on the queue of compilation units to read in full symbols
1370 struct dwarf2_queue_item
1372 struct dwarf2_per_cu_data
*per_cu
;
1373 enum language pretend_language
;
1374 struct dwarf2_queue_item
*next
;
1377 /* The current queue. */
1378 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1380 /* Loaded secondary compilation units are kept in memory until they
1381 have not been referenced for the processing of this many
1382 compilation units. Set this to zero to disable caching. Cache
1383 sizes of up to at least twenty will improve startup time for
1384 typical inter-CU-reference binaries, at an obvious memory cost. */
1385 static int dwarf_max_cache_age
= 5;
1387 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1388 struct cmd_list_element
*c
, const char *value
)
1390 fprintf_filtered (file
, _("The upper bound on the age of cached "
1391 "DWARF compilation units is %s.\n"),
1395 /* local function prototypes */
1397 static const char *get_section_name (const struct dwarf2_section_info
*);
1399 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1401 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1403 static void dwarf2_find_base_address (struct die_info
*die
,
1404 struct dwarf2_cu
*cu
);
1406 static struct partial_symtab
*create_partial_symtab
1407 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1409 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1411 static void scan_partial_symbols (struct partial_die_info
*,
1412 CORE_ADDR
*, CORE_ADDR
*,
1413 int, struct dwarf2_cu
*);
1415 static void add_partial_symbol (struct partial_die_info
*,
1416 struct dwarf2_cu
*);
1418 static void add_partial_namespace (struct partial_die_info
*pdi
,
1419 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1420 int set_addrmap
, struct dwarf2_cu
*cu
);
1422 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1423 CORE_ADDR
*highpc
, int set_addrmap
,
1424 struct dwarf2_cu
*cu
);
1426 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1427 struct dwarf2_cu
*cu
);
1429 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1430 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1431 int need_pc
, struct dwarf2_cu
*cu
);
1433 static void dwarf2_read_symtab (struct partial_symtab
*,
1436 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1438 static struct abbrev_info
*abbrev_table_lookup_abbrev
1439 (const struct abbrev_table
*, unsigned int);
1441 static struct abbrev_table
*abbrev_table_read_table
1442 (struct dwarf2_section_info
*, sect_offset
);
1444 static void abbrev_table_free (struct abbrev_table
*);
1446 static void abbrev_table_free_cleanup (void *);
1448 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1449 struct dwarf2_section_info
*);
1451 static void dwarf2_free_abbrev_table (void *);
1453 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1455 static struct partial_die_info
*load_partial_dies
1456 (const struct die_reader_specs
*, const gdb_byte
*, int);
1458 static const gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1459 struct partial_die_info
*,
1460 struct abbrev_info
*,
1464 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1465 struct dwarf2_cu
*);
1467 static void fixup_partial_die (struct partial_die_info
*,
1468 struct dwarf2_cu
*);
1470 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1471 struct attribute
*, struct attr_abbrev
*,
1474 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1476 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1478 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1480 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1482 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1484 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1487 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1489 static LONGEST read_checked_initial_length_and_offset
1490 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1491 unsigned int *, unsigned int *);
1493 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1494 const struct comp_unit_head
*,
1497 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1499 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1502 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1504 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1506 static const char *read_indirect_string (bfd
*, const gdb_byte
*,
1507 const struct comp_unit_head
*,
1510 static const char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1512 static ULONGEST
read_unsigned_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1514 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1516 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1520 static const char *read_str_index (const struct die_reader_specs
*reader
,
1521 ULONGEST str_index
);
1523 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1525 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1526 struct dwarf2_cu
*);
1528 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1531 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1532 struct dwarf2_cu
*cu
);
1534 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1535 struct dwarf2_cu
*cu
);
1537 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1539 static struct die_info
*die_specification (struct die_info
*die
,
1540 struct dwarf2_cu
**);
1542 static void free_line_header (struct line_header
*lh
);
1544 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1545 struct dwarf2_cu
*cu
);
1547 static void dwarf_decode_lines (struct line_header
*, const char *,
1548 struct dwarf2_cu
*, struct partial_symtab
*,
1549 CORE_ADDR
, int decode_mapping
);
1551 static void dwarf2_start_subfile (const char *, const char *);
1553 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1554 const char *, const char *,
1557 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1558 struct dwarf2_cu
*);
1560 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1561 struct dwarf2_cu
*, struct symbol
*);
1563 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1564 struct dwarf2_cu
*);
1566 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1569 struct obstack
*obstack
,
1570 struct dwarf2_cu
*cu
, LONGEST
*value
,
1571 const gdb_byte
**bytes
,
1572 struct dwarf2_locexpr_baton
**baton
);
1574 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1576 static int need_gnat_info (struct dwarf2_cu
*);
1578 static struct type
*die_descriptive_type (struct die_info
*,
1579 struct dwarf2_cu
*);
1581 static void set_descriptive_type (struct type
*, struct die_info
*,
1582 struct dwarf2_cu
*);
1584 static struct type
*die_containing_type (struct die_info
*,
1585 struct dwarf2_cu
*);
1587 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1588 struct dwarf2_cu
*);
1590 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1592 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1594 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1596 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1597 const char *suffix
, int physname
,
1598 struct dwarf2_cu
*cu
);
1600 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1602 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1604 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1606 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1608 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1610 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1611 struct dwarf2_cu
*, struct partial_symtab
*);
1613 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1614 values. Keep the items ordered with increasing constraints compliance. */
1617 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1618 PC_BOUNDS_NOT_PRESENT
,
1620 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1621 were present but they do not form a valid range of PC addresses. */
1624 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1627 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1631 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1632 CORE_ADDR
*, CORE_ADDR
*,
1634 struct partial_symtab
*);
1636 static void get_scope_pc_bounds (struct die_info
*,
1637 CORE_ADDR
*, CORE_ADDR
*,
1638 struct dwarf2_cu
*);
1640 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1641 CORE_ADDR
, struct dwarf2_cu
*);
1643 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1644 struct dwarf2_cu
*);
1646 static void dwarf2_attach_fields_to_type (struct field_info
*,
1647 struct type
*, struct dwarf2_cu
*);
1649 static void dwarf2_add_member_fn (struct field_info
*,
1650 struct die_info
*, struct type
*,
1651 struct dwarf2_cu
*);
1653 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1655 struct dwarf2_cu
*);
1657 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1659 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1661 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1663 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1665 static struct using_direct
**using_directives (enum language
);
1667 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1669 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1671 static struct type
*read_module_type (struct die_info
*die
,
1672 struct dwarf2_cu
*cu
);
1674 static const char *namespace_name (struct die_info
*die
,
1675 int *is_anonymous
, struct dwarf2_cu
*);
1677 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1679 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1681 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1682 struct dwarf2_cu
*);
1684 static struct die_info
*read_die_and_siblings_1
1685 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1688 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1689 const gdb_byte
*info_ptr
,
1690 const gdb_byte
**new_info_ptr
,
1691 struct die_info
*parent
);
1693 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1694 struct die_info
**, const gdb_byte
*,
1697 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1698 struct die_info
**, const gdb_byte
*,
1701 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1703 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1706 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1708 static const char *dwarf2_full_name (const char *name
,
1709 struct die_info
*die
,
1710 struct dwarf2_cu
*cu
);
1712 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1713 struct dwarf2_cu
*cu
);
1715 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1716 struct dwarf2_cu
**);
1718 static const char *dwarf_tag_name (unsigned int);
1720 static const char *dwarf_attr_name (unsigned int);
1722 static const char *dwarf_form_name (unsigned int);
1724 static char *dwarf_bool_name (unsigned int);
1726 static const char *dwarf_type_encoding_name (unsigned int);
1728 static struct die_info
*sibling_die (struct die_info
*);
1730 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1732 static void dump_die_for_error (struct die_info
*);
1734 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1737 /*static*/ void dump_die (struct die_info
*, int max_level
);
1739 static void store_in_ref_table (struct die_info
*,
1740 struct dwarf2_cu
*);
1742 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1744 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1746 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1747 const struct attribute
*,
1748 struct dwarf2_cu
**);
1750 static struct die_info
*follow_die_ref (struct die_info
*,
1751 const struct attribute
*,
1752 struct dwarf2_cu
**);
1754 static struct die_info
*follow_die_sig (struct die_info
*,
1755 const struct attribute
*,
1756 struct dwarf2_cu
**);
1758 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1759 struct dwarf2_cu
*);
1761 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1762 const struct attribute
*,
1763 struct dwarf2_cu
*);
1765 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1767 static void read_signatured_type (struct signatured_type
*);
1769 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1770 struct die_info
*die
, struct dwarf2_cu
*cu
,
1771 struct dynamic_prop
*prop
);
1773 /* memory allocation interface */
1775 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1777 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1779 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1781 static int attr_form_is_block (const struct attribute
*);
1783 static int attr_form_is_section_offset (const struct attribute
*);
1785 static int attr_form_is_constant (const struct attribute
*);
1787 static int attr_form_is_ref (const struct attribute
*);
1789 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1790 struct dwarf2_loclist_baton
*baton
,
1791 const struct attribute
*attr
);
1793 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1795 struct dwarf2_cu
*cu
,
1798 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1799 const gdb_byte
*info_ptr
,
1800 struct abbrev_info
*abbrev
);
1802 static void free_stack_comp_unit (void *);
1804 static hashval_t
partial_die_hash (const void *item
);
1806 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1808 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1809 (sect_offset offset
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1811 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1812 struct dwarf2_per_cu_data
*per_cu
);
1814 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1815 struct die_info
*comp_unit_die
,
1816 enum language pretend_language
);
1818 static void free_heap_comp_unit (void *);
1820 static void free_cached_comp_units (void *);
1822 static void age_cached_comp_units (void);
1824 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1826 static struct type
*set_die_type (struct die_info
*, struct type
*,
1827 struct dwarf2_cu
*);
1829 static void create_all_comp_units (struct objfile
*);
1831 static int create_all_type_units (struct objfile
*);
1833 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1836 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1839 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1842 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1843 struct dwarf2_per_cu_data
*);
1845 static void dwarf2_mark (struct dwarf2_cu
*);
1847 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1849 static struct type
*get_die_type_at_offset (sect_offset
,
1850 struct dwarf2_per_cu_data
*);
1852 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1854 static void dwarf2_release_queue (void *dummy
);
1856 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1857 enum language pretend_language
);
1859 static void process_queue (void);
1861 static void find_file_and_directory (struct die_info
*die
,
1862 struct dwarf2_cu
*cu
,
1863 const char **name
, const char **comp_dir
);
1865 static char *file_full_name (int file
, struct line_header
*lh
,
1866 const char *comp_dir
);
1868 static const gdb_byte
*read_and_check_comp_unit_head
1869 (struct comp_unit_head
*header
,
1870 struct dwarf2_section_info
*section
,
1871 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1872 int is_debug_types_section
);
1874 static void init_cutu_and_read_dies
1875 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1876 int use_existing_cu
, int keep
,
1877 die_reader_func_ftype
*die_reader_func
, void *data
);
1879 static void init_cutu_and_read_dies_simple
1880 (struct dwarf2_per_cu_data
*this_cu
,
1881 die_reader_func_ftype
*die_reader_func
, void *data
);
1883 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1885 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1887 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1888 (struct dwp_file
*dwp_file
, const char *comp_dir
,
1889 ULONGEST signature
, int is_debug_types
);
1891 static struct dwp_file
*get_dwp_file (void);
1893 static struct dwo_unit
*lookup_dwo_comp_unit
1894 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1896 static struct dwo_unit
*lookup_dwo_type_unit
1897 (struct signatured_type
*, const char *, const char *);
1899 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1901 static void free_dwo_file_cleanup (void *);
1903 static void process_cu_includes (void);
1905 static void check_producer (struct dwarf2_cu
*cu
);
1907 static void free_line_header_voidp (void *arg
);
1909 /* Various complaints about symbol reading that don't abort the process. */
1912 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1914 complaint (&symfile_complaints
,
1915 _("statement list doesn't fit in .debug_line section"));
1919 dwarf2_debug_line_missing_file_complaint (void)
1921 complaint (&symfile_complaints
,
1922 _(".debug_line section has line data without a file"));
1926 dwarf2_debug_line_missing_end_sequence_complaint (void)
1928 complaint (&symfile_complaints
,
1929 _(".debug_line section has line "
1930 "program sequence without an end"));
1934 dwarf2_complex_location_expr_complaint (void)
1936 complaint (&symfile_complaints
, _("location expression too complex"));
1940 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1943 complaint (&symfile_complaints
,
1944 _("const value length mismatch for '%s', got %d, expected %d"),
1949 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1951 complaint (&symfile_complaints
,
1952 _("debug info runs off end of %s section"
1954 get_section_name (section
),
1955 get_section_file_name (section
));
1959 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1961 complaint (&symfile_complaints
,
1962 _("macro debug info contains a "
1963 "malformed macro definition:\n`%s'"),
1968 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1970 complaint (&symfile_complaints
,
1971 _("invalid attribute class or form for '%s' in '%s'"),
1975 /* Hash function for line_header_hash. */
1978 line_header_hash (const struct line_header
*ofs
)
1980 return ofs
->offset
.sect_off
^ ofs
->offset_in_dwz
;
1983 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1986 line_header_hash_voidp (const void *item
)
1988 const struct line_header
*ofs
= (const struct line_header
*) item
;
1990 return line_header_hash (ofs
);
1993 /* Equality function for line_header_hash. */
1996 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1998 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1999 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2001 return (ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
2002 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2008 /* Convert VALUE between big- and little-endian. */
2010 byte_swap (offset_type value
)
2014 result
= (value
& 0xff) << 24;
2015 result
|= (value
& 0xff00) << 8;
2016 result
|= (value
& 0xff0000) >> 8;
2017 result
|= (value
& 0xff000000) >> 24;
2021 #define MAYBE_SWAP(V) byte_swap (V)
2024 #define MAYBE_SWAP(V) (V)
2025 #endif /* WORDS_BIGENDIAN */
2027 /* Read the given attribute value as an address, taking the attribute's
2028 form into account. */
2031 attr_value_as_address (struct attribute
*attr
)
2035 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2037 /* Aside from a few clearly defined exceptions, attributes that
2038 contain an address must always be in DW_FORM_addr form.
2039 Unfortunately, some compilers happen to be violating this
2040 requirement by encoding addresses using other forms, such
2041 as DW_FORM_data4 for example. For those broken compilers,
2042 we try to do our best, without any guarantee of success,
2043 to interpret the address correctly. It would also be nice
2044 to generate a complaint, but that would require us to maintain
2045 a list of legitimate cases where a non-address form is allowed,
2046 as well as update callers to pass in at least the CU's DWARF
2047 version. This is more overhead than what we're willing to
2048 expand for a pretty rare case. */
2049 addr
= DW_UNSND (attr
);
2052 addr
= DW_ADDR (attr
);
2057 /* The suffix for an index file. */
2058 #define INDEX_SUFFIX ".gdb-index"
2060 /* Try to locate the sections we need for DWARF 2 debugging
2061 information and return true if we have enough to do something.
2062 NAMES points to the dwarf2 section names, or is NULL if the standard
2063 ELF names are used. */
2066 dwarf2_has_info (struct objfile
*objfile
,
2067 const struct dwarf2_debug_sections
*names
)
2069 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
2070 objfile_data (objfile
, dwarf2_objfile_data_key
));
2071 if (!dwarf2_per_objfile
)
2073 /* Initialize per-objfile state. */
2074 struct dwarf2_per_objfile
*data
2075 = XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_objfile
);
2077 memset (data
, 0, sizeof (*data
));
2078 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
2079 dwarf2_per_objfile
= data
;
2081 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
2083 dwarf2_per_objfile
->objfile
= objfile
;
2085 return (!dwarf2_per_objfile
->info
.is_virtual
2086 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2087 && !dwarf2_per_objfile
->abbrev
.is_virtual
2088 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2091 /* Return the containing section of virtual section SECTION. */
2093 static struct dwarf2_section_info
*
2094 get_containing_section (const struct dwarf2_section_info
*section
)
2096 gdb_assert (section
->is_virtual
);
2097 return section
->s
.containing_section
;
2100 /* Return the bfd owner of SECTION. */
2103 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2105 if (section
->is_virtual
)
2107 section
= get_containing_section (section
);
2108 gdb_assert (!section
->is_virtual
);
2110 return section
->s
.section
->owner
;
2113 /* Return the bfd section of SECTION.
2114 Returns NULL if the section is not present. */
2117 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2119 if (section
->is_virtual
)
2121 section
= get_containing_section (section
);
2122 gdb_assert (!section
->is_virtual
);
2124 return section
->s
.section
;
2127 /* Return the name of SECTION. */
2130 get_section_name (const struct dwarf2_section_info
*section
)
2132 asection
*sectp
= get_section_bfd_section (section
);
2134 gdb_assert (sectp
!= NULL
);
2135 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2138 /* Return the name of the file SECTION is in. */
2141 get_section_file_name (const struct dwarf2_section_info
*section
)
2143 bfd
*abfd
= get_section_bfd_owner (section
);
2145 return bfd_get_filename (abfd
);
2148 /* Return the id of SECTION.
2149 Returns 0 if SECTION doesn't exist. */
2152 get_section_id (const struct dwarf2_section_info
*section
)
2154 asection
*sectp
= get_section_bfd_section (section
);
2161 /* Return the flags of SECTION.
2162 SECTION (or containing section if this is a virtual section) must exist. */
2165 get_section_flags (const struct dwarf2_section_info
*section
)
2167 asection
*sectp
= get_section_bfd_section (section
);
2169 gdb_assert (sectp
!= NULL
);
2170 return bfd_get_section_flags (sectp
->owner
, sectp
);
2173 /* When loading sections, we look either for uncompressed section or for
2174 compressed section names. */
2177 section_is_p (const char *section_name
,
2178 const struct dwarf2_section_names
*names
)
2180 if (names
->normal
!= NULL
2181 && strcmp (section_name
, names
->normal
) == 0)
2183 if (names
->compressed
!= NULL
2184 && strcmp (section_name
, names
->compressed
) == 0)
2189 /* This function is mapped across the sections and remembers the
2190 offset and size of each of the debugging sections we are interested
2194 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
2196 const struct dwarf2_debug_sections
*names
;
2197 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2200 names
= &dwarf2_elf_names
;
2202 names
= (const struct dwarf2_debug_sections
*) vnames
;
2204 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2207 else if (section_is_p (sectp
->name
, &names
->info
))
2209 dwarf2_per_objfile
->info
.s
.section
= sectp
;
2210 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
2212 else if (section_is_p (sectp
->name
, &names
->abbrev
))
2214 dwarf2_per_objfile
->abbrev
.s
.section
= sectp
;
2215 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
2217 else if (section_is_p (sectp
->name
, &names
->line
))
2219 dwarf2_per_objfile
->line
.s
.section
= sectp
;
2220 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
2222 else if (section_is_p (sectp
->name
, &names
->loc
))
2224 dwarf2_per_objfile
->loc
.s
.section
= sectp
;
2225 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
2227 else if (section_is_p (sectp
->name
, &names
->macinfo
))
2229 dwarf2_per_objfile
->macinfo
.s
.section
= sectp
;
2230 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
2232 else if (section_is_p (sectp
->name
, &names
->macro
))
2234 dwarf2_per_objfile
->macro
.s
.section
= sectp
;
2235 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
2237 else if (section_is_p (sectp
->name
, &names
->str
))
2239 dwarf2_per_objfile
->str
.s
.section
= sectp
;
2240 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
2242 else if (section_is_p (sectp
->name
, &names
->addr
))
2244 dwarf2_per_objfile
->addr
.s
.section
= sectp
;
2245 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
2247 else if (section_is_p (sectp
->name
, &names
->frame
))
2249 dwarf2_per_objfile
->frame
.s
.section
= sectp
;
2250 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
2252 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
2254 dwarf2_per_objfile
->eh_frame
.s
.section
= sectp
;
2255 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
2257 else if (section_is_p (sectp
->name
, &names
->ranges
))
2259 dwarf2_per_objfile
->ranges
.s
.section
= sectp
;
2260 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
2262 else if (section_is_p (sectp
->name
, &names
->types
))
2264 struct dwarf2_section_info type_section
;
2266 memset (&type_section
, 0, sizeof (type_section
));
2267 type_section
.s
.section
= sectp
;
2268 type_section
.size
= bfd_get_section_size (sectp
);
2270 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
2273 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
2275 dwarf2_per_objfile
->gdb_index
.s
.section
= sectp
;
2276 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
2279 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2280 && bfd_section_vma (abfd
, sectp
) == 0)
2281 dwarf2_per_objfile
->has_section_at_zero
= 1;
2284 /* A helper function that decides whether a section is empty,
2288 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2290 if (section
->is_virtual
)
2291 return section
->size
== 0;
2292 return section
->s
.section
== NULL
|| section
->size
== 0;
2295 /* Read the contents of the section INFO.
2296 OBJFILE is the main object file, but not necessarily the file where
2297 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2299 If the section is compressed, uncompress it before returning. */
2302 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2306 gdb_byte
*buf
, *retbuf
;
2310 info
->buffer
= NULL
;
2313 if (dwarf2_section_empty_p (info
))
2316 sectp
= get_section_bfd_section (info
);
2318 /* If this is a virtual section we need to read in the real one first. */
2319 if (info
->is_virtual
)
2321 struct dwarf2_section_info
*containing_section
=
2322 get_containing_section (info
);
2324 gdb_assert (sectp
!= NULL
);
2325 if ((sectp
->flags
& SEC_RELOC
) != 0)
2327 error (_("Dwarf Error: DWP format V2 with relocations is not"
2328 " supported in section %s [in module %s]"),
2329 get_section_name (info
), get_section_file_name (info
));
2331 dwarf2_read_section (objfile
, containing_section
);
2332 /* Other code should have already caught virtual sections that don't
2334 gdb_assert (info
->virtual_offset
+ info
->size
2335 <= containing_section
->size
);
2336 /* If the real section is empty or there was a problem reading the
2337 section we shouldn't get here. */
2338 gdb_assert (containing_section
->buffer
!= NULL
);
2339 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2343 /* If the section has relocations, we must read it ourselves.
2344 Otherwise we attach it to the BFD. */
2345 if ((sectp
->flags
& SEC_RELOC
) == 0)
2347 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2351 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2354 /* When debugging .o files, we may need to apply relocations; see
2355 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2356 We never compress sections in .o files, so we only need to
2357 try this when the section is not compressed. */
2358 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2361 info
->buffer
= retbuf
;
2365 abfd
= get_section_bfd_owner (info
);
2366 gdb_assert (abfd
!= NULL
);
2368 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2369 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2371 error (_("Dwarf Error: Can't read DWARF data"
2372 " in section %s [in module %s]"),
2373 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2377 /* A helper function that returns the size of a section in a safe way.
2378 If you are positive that the section has been read before using the
2379 size, then it is safe to refer to the dwarf2_section_info object's
2380 "size" field directly. In other cases, you must call this
2381 function, because for compressed sections the size field is not set
2382 correctly until the section has been read. */
2384 static bfd_size_type
2385 dwarf2_section_size (struct objfile
*objfile
,
2386 struct dwarf2_section_info
*info
)
2389 dwarf2_read_section (objfile
, info
);
2393 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2397 dwarf2_get_section_info (struct objfile
*objfile
,
2398 enum dwarf2_section_enum sect
,
2399 asection
**sectp
, const gdb_byte
**bufp
,
2400 bfd_size_type
*sizep
)
2402 struct dwarf2_per_objfile
*data
2403 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2404 dwarf2_objfile_data_key
);
2405 struct dwarf2_section_info
*info
;
2407 /* We may see an objfile without any DWARF, in which case we just
2418 case DWARF2_DEBUG_FRAME
:
2419 info
= &data
->frame
;
2421 case DWARF2_EH_FRAME
:
2422 info
= &data
->eh_frame
;
2425 gdb_assert_not_reached ("unexpected section");
2428 dwarf2_read_section (objfile
, info
);
2430 *sectp
= get_section_bfd_section (info
);
2431 *bufp
= info
->buffer
;
2432 *sizep
= info
->size
;
2435 /* A helper function to find the sections for a .dwz file. */
2438 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2440 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2442 /* Note that we only support the standard ELF names, because .dwz
2443 is ELF-only (at the time of writing). */
2444 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2446 dwz_file
->abbrev
.s
.section
= sectp
;
2447 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2449 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2451 dwz_file
->info
.s
.section
= sectp
;
2452 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2454 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2456 dwz_file
->str
.s
.section
= sectp
;
2457 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2459 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2461 dwz_file
->line
.s
.section
= sectp
;
2462 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2464 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2466 dwz_file
->macro
.s
.section
= sectp
;
2467 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2469 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2471 dwz_file
->gdb_index
.s
.section
= sectp
;
2472 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2476 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2477 there is no .gnu_debugaltlink section in the file. Error if there
2478 is such a section but the file cannot be found. */
2480 static struct dwz_file
*
2481 dwarf2_get_dwz_file (void)
2484 struct cleanup
*cleanup
;
2485 const char *filename
;
2486 struct dwz_file
*result
;
2487 bfd_size_type buildid_len_arg
;
2491 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2492 return dwarf2_per_objfile
->dwz_file
;
2494 bfd_set_error (bfd_error_no_error
);
2495 data
= bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2496 &buildid_len_arg
, &buildid
);
2499 if (bfd_get_error () == bfd_error_no_error
)
2501 error (_("could not read '.gnu_debugaltlink' section: %s"),
2502 bfd_errmsg (bfd_get_error ()));
2504 cleanup
= make_cleanup (xfree
, data
);
2505 make_cleanup (xfree
, buildid
);
2507 buildid_len
= (size_t) buildid_len_arg
;
2509 filename
= (const char *) data
;
2510 if (!IS_ABSOLUTE_PATH (filename
))
2512 char *abs
= gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2515 make_cleanup (xfree
, abs
);
2516 abs
= ldirname (abs
);
2517 make_cleanup (xfree
, abs
);
2519 rel
= concat (abs
, SLASH_STRING
, filename
, (char *) NULL
);
2520 make_cleanup (xfree
, rel
);
2524 /* First try the file name given in the section. If that doesn't
2525 work, try to use the build-id instead. */
2526 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2527 if (dwz_bfd
!= NULL
)
2529 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2533 if (dwz_bfd
== NULL
)
2534 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2536 if (dwz_bfd
== NULL
)
2537 error (_("could not find '.gnu_debugaltlink' file for %s"),
2538 objfile_name (dwarf2_per_objfile
->objfile
));
2540 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2542 result
->dwz_bfd
= dwz_bfd
.release ();
2544 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
2546 do_cleanups (cleanup
);
2548 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
2549 dwarf2_per_objfile
->dwz_file
= result
;
2553 /* DWARF quick_symbols_functions support. */
2555 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2556 unique line tables, so we maintain a separate table of all .debug_line
2557 derived entries to support the sharing.
2558 All the quick functions need is the list of file names. We discard the
2559 line_header when we're done and don't need to record it here. */
2560 struct quick_file_names
2562 /* The data used to construct the hash key. */
2563 struct stmt_list_hash hash
;
2565 /* The number of entries in file_names, real_names. */
2566 unsigned int num_file_names
;
2568 /* The file names from the line table, after being run through
2570 const char **file_names
;
2572 /* The file names from the line table after being run through
2573 gdb_realpath. These are computed lazily. */
2574 const char **real_names
;
2577 /* When using the index (and thus not using psymtabs), each CU has an
2578 object of this type. This is used to hold information needed by
2579 the various "quick" methods. */
2580 struct dwarf2_per_cu_quick_data
2582 /* The file table. This can be NULL if there was no file table
2583 or it's currently not read in.
2584 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2585 struct quick_file_names
*file_names
;
2587 /* The corresponding symbol table. This is NULL if symbols for this
2588 CU have not yet been read. */
2589 struct compunit_symtab
*compunit_symtab
;
2591 /* A temporary mark bit used when iterating over all CUs in
2592 expand_symtabs_matching. */
2593 unsigned int mark
: 1;
2595 /* True if we've tried to read the file table and found there isn't one.
2596 There will be no point in trying to read it again next time. */
2597 unsigned int no_file_data
: 1;
2600 /* Utility hash function for a stmt_list_hash. */
2603 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2607 if (stmt_list_hash
->dwo_unit
!= NULL
)
2608 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2609 v
+= stmt_list_hash
->line_offset
.sect_off
;
2613 /* Utility equality function for a stmt_list_hash. */
2616 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2617 const struct stmt_list_hash
*rhs
)
2619 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2621 if (lhs
->dwo_unit
!= NULL
2622 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2625 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2628 /* Hash function for a quick_file_names. */
2631 hash_file_name_entry (const void *e
)
2633 const struct quick_file_names
*file_data
2634 = (const struct quick_file_names
*) e
;
2636 return hash_stmt_list_entry (&file_data
->hash
);
2639 /* Equality function for a quick_file_names. */
2642 eq_file_name_entry (const void *a
, const void *b
)
2644 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2645 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2647 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2650 /* Delete function for a quick_file_names. */
2653 delete_file_name_entry (void *e
)
2655 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2658 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2660 xfree ((void*) file_data
->file_names
[i
]);
2661 if (file_data
->real_names
)
2662 xfree ((void*) file_data
->real_names
[i
]);
2665 /* The space for the struct itself lives on objfile_obstack,
2666 so we don't free it here. */
2669 /* Create a quick_file_names hash table. */
2672 create_quick_file_names_table (unsigned int nr_initial_entries
)
2674 return htab_create_alloc (nr_initial_entries
,
2675 hash_file_name_entry
, eq_file_name_entry
,
2676 delete_file_name_entry
, xcalloc
, xfree
);
2679 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2680 have to be created afterwards. You should call age_cached_comp_units after
2681 processing PER_CU->CU. dw2_setup must have been already called. */
2684 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2686 if (per_cu
->is_debug_types
)
2687 load_full_type_unit (per_cu
);
2689 load_full_comp_unit (per_cu
, language_minimal
);
2691 if (per_cu
->cu
== NULL
)
2692 return; /* Dummy CU. */
2694 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2697 /* Read in the symbols for PER_CU. */
2700 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2702 struct cleanup
*back_to
;
2704 /* Skip type_unit_groups, reading the type units they contain
2705 is handled elsewhere. */
2706 if (IS_TYPE_UNIT_GROUP (per_cu
))
2709 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2711 if (dwarf2_per_objfile
->using_index
2712 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2713 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2715 queue_comp_unit (per_cu
, language_minimal
);
2718 /* If we just loaded a CU from a DWO, and we're working with an index
2719 that may badly handle TUs, load all the TUs in that DWO as well.
2720 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2721 if (!per_cu
->is_debug_types
2722 && per_cu
->cu
!= NULL
2723 && per_cu
->cu
->dwo_unit
!= NULL
2724 && dwarf2_per_objfile
->index_table
!= NULL
2725 && dwarf2_per_objfile
->index_table
->version
<= 7
2726 /* DWP files aren't supported yet. */
2727 && get_dwp_file () == NULL
)
2728 queue_and_load_all_dwo_tus (per_cu
);
2733 /* Age the cache, releasing compilation units that have not
2734 been used recently. */
2735 age_cached_comp_units ();
2737 do_cleanups (back_to
);
2740 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2741 the objfile from which this CU came. Returns the resulting symbol
2744 static struct compunit_symtab
*
2745 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2747 gdb_assert (dwarf2_per_objfile
->using_index
);
2748 if (!per_cu
->v
.quick
->compunit_symtab
)
2750 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2751 increment_reading_symtab ();
2752 dw2_do_instantiate_symtab (per_cu
);
2753 process_cu_includes ();
2754 do_cleanups (back_to
);
2757 return per_cu
->v
.quick
->compunit_symtab
;
2760 /* Return the CU/TU given its index.
2762 This is intended for loops like:
2764 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2765 + dwarf2_per_objfile->n_type_units); ++i)
2767 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
2773 static struct dwarf2_per_cu_data
*
2774 dw2_get_cutu (int index
)
2776 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2778 index
-= dwarf2_per_objfile
->n_comp_units
;
2779 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2780 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2783 return dwarf2_per_objfile
->all_comp_units
[index
];
2786 /* Return the CU given its index.
2787 This differs from dw2_get_cutu in that it's for when you know INDEX
2790 static struct dwarf2_per_cu_data
*
2791 dw2_get_cu (int index
)
2793 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
2795 return dwarf2_per_objfile
->all_comp_units
[index
];
2798 /* A helper for create_cus_from_index that handles a given list of
2802 create_cus_from_index_list (struct objfile
*objfile
,
2803 const gdb_byte
*cu_list
, offset_type n_elements
,
2804 struct dwarf2_section_info
*section
,
2810 for (i
= 0; i
< n_elements
; i
+= 2)
2812 struct dwarf2_per_cu_data
*the_cu
;
2813 ULONGEST offset
, length
;
2815 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2816 offset
= extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2817 length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2820 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2821 struct dwarf2_per_cu_data
);
2822 the_cu
->offset
.sect_off
= offset
;
2823 the_cu
->length
= length
;
2824 the_cu
->objfile
= objfile
;
2825 the_cu
->section
= section
;
2826 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2827 struct dwarf2_per_cu_quick_data
);
2828 the_cu
->is_dwz
= is_dwz
;
2829 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2833 /* Read the CU list from the mapped index, and use it to create all
2834 the CU objects for this objfile. */
2837 create_cus_from_index (struct objfile
*objfile
,
2838 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2839 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2841 struct dwz_file
*dwz
;
2843 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2844 dwarf2_per_objfile
->all_comp_units
=
2845 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
2846 dwarf2_per_objfile
->n_comp_units
);
2848 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2849 &dwarf2_per_objfile
->info
, 0, 0);
2851 if (dwz_elements
== 0)
2854 dwz
= dwarf2_get_dwz_file ();
2855 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
2856 cu_list_elements
/ 2);
2859 /* Create the signatured type hash table from the index. */
2862 create_signatured_type_table_from_index (struct objfile
*objfile
,
2863 struct dwarf2_section_info
*section
,
2864 const gdb_byte
*bytes
,
2865 offset_type elements
)
2868 htab_t sig_types_hash
;
2870 dwarf2_per_objfile
->n_type_units
2871 = dwarf2_per_objfile
->n_allocated_type_units
2873 dwarf2_per_objfile
->all_type_units
=
2874 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
2876 sig_types_hash
= allocate_signatured_type_table (objfile
);
2878 for (i
= 0; i
< elements
; i
+= 3)
2880 struct signatured_type
*sig_type
;
2881 ULONGEST offset
, type_offset_in_tu
, signature
;
2884 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2885 offset
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2886 type_offset_in_tu
= extract_unsigned_integer (bytes
+ 8, 8,
2888 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2891 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2892 struct signatured_type
);
2893 sig_type
->signature
= signature
;
2894 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2895 sig_type
->per_cu
.is_debug_types
= 1;
2896 sig_type
->per_cu
.section
= section
;
2897 sig_type
->per_cu
.offset
.sect_off
= offset
;
2898 sig_type
->per_cu
.objfile
= objfile
;
2899 sig_type
->per_cu
.v
.quick
2900 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2901 struct dwarf2_per_cu_quick_data
);
2903 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2906 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2909 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2912 /* Read the address map data from the mapped index, and use it to
2913 populate the objfile's psymtabs_addrmap. */
2916 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2918 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2919 const gdb_byte
*iter
, *end
;
2920 struct obstack temp_obstack
;
2921 struct addrmap
*mutable_map
;
2922 struct cleanup
*cleanup
;
2925 obstack_init (&temp_obstack
);
2926 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2927 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2929 iter
= index
->address_table
;
2930 end
= iter
+ index
->address_table_size
;
2932 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2936 ULONGEST hi
, lo
, cu_index
;
2937 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2939 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2941 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2946 complaint (&symfile_complaints
,
2947 _(".gdb_index address table has invalid range (%s - %s)"),
2948 hex_string (lo
), hex_string (hi
));
2952 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
2954 complaint (&symfile_complaints
,
2955 _(".gdb_index address table has invalid CU number %u"),
2956 (unsigned) cu_index
);
2960 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
2961 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
2962 addrmap_set_empty (mutable_map
, lo
, hi
- 1, dw2_get_cutu (cu_index
));
2965 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2966 &objfile
->objfile_obstack
);
2967 do_cleanups (cleanup
);
2970 /* The hash function for strings in the mapped index. This is the same as
2971 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2972 implementation. This is necessary because the hash function is tied to the
2973 format of the mapped index file. The hash values do not have to match with
2976 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2979 mapped_index_string_hash (int index_version
, const void *p
)
2981 const unsigned char *str
= (const unsigned char *) p
;
2985 while ((c
= *str
++) != 0)
2987 if (index_version
>= 5)
2989 r
= r
* 67 + c
- 113;
2995 /* Find a slot in the mapped index INDEX for the object named NAME.
2996 If NAME is found, set *VEC_OUT to point to the CU vector in the
2997 constant pool and return 1. If NAME cannot be found, return 0. */
3000 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3001 offset_type
**vec_out
)
3003 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3005 offset_type slot
, step
;
3006 int (*cmp
) (const char *, const char *);
3008 if (current_language
->la_language
== language_cplus
3009 || current_language
->la_language
== language_fortran
3010 || current_language
->la_language
== language_d
)
3012 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3015 if (strchr (name
, '(') != NULL
)
3017 char *without_params
= cp_remove_params (name
);
3019 if (without_params
!= NULL
)
3021 make_cleanup (xfree
, without_params
);
3022 name
= without_params
;
3027 /* Index version 4 did not support case insensitive searches. But the
3028 indices for case insensitive languages are built in lowercase, therefore
3029 simulate our NAME being searched is also lowercased. */
3030 hash
= mapped_index_string_hash ((index
->version
== 4
3031 && case_sensitivity
== case_sensitive_off
3032 ? 5 : index
->version
),
3035 slot
= hash
& (index
->symbol_table_slots
- 1);
3036 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
3037 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3041 /* Convert a slot number to an offset into the table. */
3042 offset_type i
= 2 * slot
;
3044 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
3046 do_cleanups (back_to
);
3050 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
3051 if (!cmp (name
, str
))
3053 *vec_out
= (offset_type
*) (index
->constant_pool
3054 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
3055 do_cleanups (back_to
);
3059 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
3063 /* A helper function that reads the .gdb_index from SECTION and fills
3064 in MAP. FILENAME is the name of the file containing the section;
3065 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3066 ok to use deprecated sections.
3068 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3069 out parameters that are filled in with information about the CU and
3070 TU lists in the section.
3072 Returns 1 if all went well, 0 otherwise. */
3075 read_index_from_section (struct objfile
*objfile
,
3076 const char *filename
,
3078 struct dwarf2_section_info
*section
,
3079 struct mapped_index
*map
,
3080 const gdb_byte
**cu_list
,
3081 offset_type
*cu_list_elements
,
3082 const gdb_byte
**types_list
,
3083 offset_type
*types_list_elements
)
3085 const gdb_byte
*addr
;
3086 offset_type version
;
3087 offset_type
*metadata
;
3090 if (dwarf2_section_empty_p (section
))
3093 /* Older elfutils strip versions could keep the section in the main
3094 executable while splitting it for the separate debug info file. */
3095 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3098 dwarf2_read_section (objfile
, section
);
3100 addr
= section
->buffer
;
3101 /* Version check. */
3102 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3103 /* Versions earlier than 3 emitted every copy of a psymbol. This
3104 causes the index to behave very poorly for certain requests. Version 3
3105 contained incomplete addrmap. So, it seems better to just ignore such
3109 static int warning_printed
= 0;
3110 if (!warning_printed
)
3112 warning (_("Skipping obsolete .gdb_index section in %s."),
3114 warning_printed
= 1;
3118 /* Index version 4 uses a different hash function than index version
3121 Versions earlier than 6 did not emit psymbols for inlined
3122 functions. Using these files will cause GDB not to be able to
3123 set breakpoints on inlined functions by name, so we ignore these
3124 indices unless the user has done
3125 "set use-deprecated-index-sections on". */
3126 if (version
< 6 && !deprecated_ok
)
3128 static int warning_printed
= 0;
3129 if (!warning_printed
)
3132 Skipping deprecated .gdb_index section in %s.\n\
3133 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3134 to use the section anyway."),
3136 warning_printed
= 1;
3140 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3141 of the TU (for symbols coming from TUs),
3142 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3143 Plus gold-generated indices can have duplicate entries for global symbols,
3144 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3145 These are just performance bugs, and we can't distinguish gdb-generated
3146 indices from gold-generated ones, so issue no warning here. */
3148 /* Indexes with higher version than the one supported by GDB may be no
3149 longer backward compatible. */
3153 map
->version
= version
;
3154 map
->total_size
= section
->size
;
3156 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3159 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3160 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3164 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3165 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3166 - MAYBE_SWAP (metadata
[i
]))
3170 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3171 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
3172 - MAYBE_SWAP (metadata
[i
]));
3175 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
3176 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
3177 - MAYBE_SWAP (metadata
[i
]))
3178 / (2 * sizeof (offset_type
)));
3181 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3187 /* Read the index file. If everything went ok, initialize the "quick"
3188 elements of all the CUs and return 1. Otherwise, return 0. */
3191 dwarf2_read_index (struct objfile
*objfile
)
3193 struct mapped_index local_map
, *map
;
3194 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3195 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3196 struct dwz_file
*dwz
;
3198 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3199 use_deprecated_index_sections
,
3200 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3201 &cu_list
, &cu_list_elements
,
3202 &types_list
, &types_list_elements
))
3205 /* Don't use the index if it's empty. */
3206 if (local_map
.symbol_table_slots
== 0)
3209 /* If there is a .dwz file, read it so we can get its CU list as
3211 dwz
= dwarf2_get_dwz_file ();
3214 struct mapped_index dwz_map
;
3215 const gdb_byte
*dwz_types_ignore
;
3216 offset_type dwz_types_elements_ignore
;
3218 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3220 &dwz
->gdb_index
, &dwz_map
,
3221 &dwz_list
, &dwz_list_elements
,
3223 &dwz_types_elements_ignore
))
3225 warning (_("could not read '.gdb_index' section from %s; skipping"),
3226 bfd_get_filename (dwz
->dwz_bfd
));
3231 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3234 if (types_list_elements
)
3236 struct dwarf2_section_info
*section
;
3238 /* We can only handle a single .debug_types when we have an
3240 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3243 section
= VEC_index (dwarf2_section_info_def
,
3244 dwarf2_per_objfile
->types
, 0);
3246 create_signatured_type_table_from_index (objfile
, section
, types_list
,
3247 types_list_elements
);
3250 create_addrmap_from_index (objfile
, &local_map
);
3252 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3255 dwarf2_per_objfile
->index_table
= map
;
3256 dwarf2_per_objfile
->using_index
= 1;
3257 dwarf2_per_objfile
->quick_file_names_table
=
3258 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3263 /* A helper for the "quick" functions which sets the global
3264 dwarf2_per_objfile according to OBJFILE. */
3267 dw2_setup (struct objfile
*objfile
)
3269 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
3270 objfile_data (objfile
, dwarf2_objfile_data_key
));
3271 gdb_assert (dwarf2_per_objfile
);
3274 /* die_reader_func for dw2_get_file_names. */
3277 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3278 const gdb_byte
*info_ptr
,
3279 struct die_info
*comp_unit_die
,
3283 struct dwarf2_cu
*cu
= reader
->cu
;
3284 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3285 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3286 struct dwarf2_per_cu_data
*lh_cu
;
3287 struct line_header
*lh
;
3288 struct attribute
*attr
;
3290 const char *name
, *comp_dir
;
3292 struct quick_file_names
*qfn
;
3293 unsigned int line_offset
;
3295 gdb_assert (! this_cu
->is_debug_types
);
3297 /* Our callers never want to match partial units -- instead they
3298 will match the enclosing full CU. */
3299 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3301 this_cu
->v
.quick
->no_file_data
= 1;
3310 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3313 struct quick_file_names find_entry
;
3315 line_offset
= DW_UNSND (attr
);
3317 /* We may have already read in this line header (TU line header sharing).
3318 If we have we're done. */
3319 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3320 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
3321 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3322 &find_entry
, INSERT
);
3325 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3329 lh
= dwarf_decode_line_header (line_offset
, cu
);
3333 lh_cu
->v
.quick
->no_file_data
= 1;
3337 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3338 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3339 qfn
->hash
.line_offset
.sect_off
= line_offset
;
3340 gdb_assert (slot
!= NULL
);
3343 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
3345 qfn
->num_file_names
= lh
->num_file_names
;
3347 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->num_file_names
);
3348 for (i
= 0; i
< lh
->num_file_names
; ++i
)
3349 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
3350 qfn
->real_names
= NULL
;
3352 free_line_header (lh
);
3354 lh_cu
->v
.quick
->file_names
= qfn
;
3357 /* A helper for the "quick" functions which attempts to read the line
3358 table for THIS_CU. */
3360 static struct quick_file_names
*
3361 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3363 /* This should never be called for TUs. */
3364 gdb_assert (! this_cu
->is_debug_types
);
3365 /* Nor type unit groups. */
3366 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3368 if (this_cu
->v
.quick
->file_names
!= NULL
)
3369 return this_cu
->v
.quick
->file_names
;
3370 /* If we know there is no line data, no point in looking again. */
3371 if (this_cu
->v
.quick
->no_file_data
)
3374 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3376 if (this_cu
->v
.quick
->no_file_data
)
3378 return this_cu
->v
.quick
->file_names
;
3381 /* A helper for the "quick" functions which computes and caches the
3382 real path for a given file name from the line table. */
3385 dw2_get_real_path (struct objfile
*objfile
,
3386 struct quick_file_names
*qfn
, int index
)
3388 if (qfn
->real_names
== NULL
)
3389 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3390 qfn
->num_file_names
, const char *);
3392 if (qfn
->real_names
[index
] == NULL
)
3393 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
3395 return qfn
->real_names
[index
];
3398 static struct symtab
*
3399 dw2_find_last_source_symtab (struct objfile
*objfile
)
3401 struct compunit_symtab
*cust
;
3404 dw2_setup (objfile
);
3405 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3406 cust
= dw2_instantiate_symtab (dw2_get_cutu (index
));
3409 return compunit_primary_filetab (cust
);
3412 /* Traversal function for dw2_forget_cached_source_info. */
3415 dw2_free_cached_file_names (void **slot
, void *info
)
3417 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3419 if (file_data
->real_names
)
3423 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3425 xfree ((void*) file_data
->real_names
[i
]);
3426 file_data
->real_names
[i
] = NULL
;
3434 dw2_forget_cached_source_info (struct objfile
*objfile
)
3436 dw2_setup (objfile
);
3438 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3439 dw2_free_cached_file_names
, NULL
);
3442 /* Helper function for dw2_map_symtabs_matching_filename that expands
3443 the symtabs and calls the iterator. */
3446 dw2_map_expand_apply (struct objfile
*objfile
,
3447 struct dwarf2_per_cu_data
*per_cu
,
3448 const char *name
, const char *real_path
,
3449 int (*callback
) (struct symtab
*, void *),
3452 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3454 /* Don't visit already-expanded CUs. */
3455 if (per_cu
->v
.quick
->compunit_symtab
)
3458 /* This may expand more than one symtab, and we want to iterate over
3460 dw2_instantiate_symtab (per_cu
);
3462 return iterate_over_some_symtabs (name
, real_path
, callback
, data
,
3463 objfile
->compunit_symtabs
, last_made
);
3466 /* Implementation of the map_symtabs_matching_filename method. */
3469 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
3470 const char *real_path
,
3471 int (*callback
) (struct symtab
*, void *),
3475 const char *name_basename
= lbasename (name
);
3477 dw2_setup (objfile
);
3479 /* The rule is CUs specify all the files, including those used by
3480 any TU, so there's no need to scan TUs here. */
3482 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3485 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3486 struct quick_file_names
*file_data
;
3488 /* We only need to look at symtabs not already expanded. */
3489 if (per_cu
->v
.quick
->compunit_symtab
)
3492 file_data
= dw2_get_file_names (per_cu
);
3493 if (file_data
== NULL
)
3496 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3498 const char *this_name
= file_data
->file_names
[j
];
3499 const char *this_real_name
;
3501 if (compare_filenames_for_search (this_name
, name
))
3503 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3509 /* Before we invoke realpath, which can get expensive when many
3510 files are involved, do a quick comparison of the basenames. */
3511 if (! basenames_may_differ
3512 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3515 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3516 if (compare_filenames_for_search (this_real_name
, name
))
3518 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3524 if (real_path
!= NULL
)
3526 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3527 gdb_assert (IS_ABSOLUTE_PATH (name
));
3528 if (this_real_name
!= NULL
3529 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3531 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3543 /* Struct used to manage iterating over all CUs looking for a symbol. */
3545 struct dw2_symtab_iterator
3547 /* The internalized form of .gdb_index. */
3548 struct mapped_index
*index
;
3549 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3550 int want_specific_block
;
3551 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3552 Unused if !WANT_SPECIFIC_BLOCK. */
3554 /* The kind of symbol we're looking for. */
3556 /* The list of CUs from the index entry of the symbol,
3557 or NULL if not found. */
3559 /* The next element in VEC to look at. */
3561 /* The number of elements in VEC, or zero if there is no match. */
3563 /* Have we seen a global version of the symbol?
3564 If so we can ignore all further global instances.
3565 This is to work around gold/15646, inefficient gold-generated
3570 /* Initialize the index symtab iterator ITER.
3571 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3572 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3575 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3576 struct mapped_index
*index
,
3577 int want_specific_block
,
3582 iter
->index
= index
;
3583 iter
->want_specific_block
= want_specific_block
;
3584 iter
->block_index
= block_index
;
3585 iter
->domain
= domain
;
3587 iter
->global_seen
= 0;
3589 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3590 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3598 /* Return the next matching CU or NULL if there are no more. */
3600 static struct dwarf2_per_cu_data
*
3601 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3603 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3605 offset_type cu_index_and_attrs
=
3606 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3607 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3608 struct dwarf2_per_cu_data
*per_cu
;
3609 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3610 /* This value is only valid for index versions >= 7. */
3611 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3612 gdb_index_symbol_kind symbol_kind
=
3613 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3614 /* Only check the symbol attributes if they're present.
3615 Indices prior to version 7 don't record them,
3616 and indices >= 7 may elide them for certain symbols
3617 (gold does this). */
3619 (iter
->index
->version
>= 7
3620 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3622 /* Don't crash on bad data. */
3623 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3624 + dwarf2_per_objfile
->n_type_units
))
3626 complaint (&symfile_complaints
,
3627 _(".gdb_index entry has bad CU index"
3629 objfile_name (dwarf2_per_objfile
->objfile
));
3633 per_cu
= dw2_get_cutu (cu_index
);
3635 /* Skip if already read in. */
3636 if (per_cu
->v
.quick
->compunit_symtab
)
3639 /* Check static vs global. */
3642 if (iter
->want_specific_block
3643 && want_static
!= is_static
)
3645 /* Work around gold/15646. */
3646 if (!is_static
&& iter
->global_seen
)
3649 iter
->global_seen
= 1;
3652 /* Only check the symbol's kind if it has one. */
3655 switch (iter
->domain
)
3658 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3659 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3660 /* Some types are also in VAR_DOMAIN. */
3661 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3665 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3669 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3684 static struct compunit_symtab
*
3685 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3686 const char *name
, domain_enum domain
)
3688 struct compunit_symtab
*stab_best
= NULL
;
3689 struct mapped_index
*index
;
3691 dw2_setup (objfile
);
3693 index
= dwarf2_per_objfile
->index_table
;
3695 /* index is NULL if OBJF_READNOW. */
3698 struct dw2_symtab_iterator iter
;
3699 struct dwarf2_per_cu_data
*per_cu
;
3701 dw2_symtab_iter_init (&iter
, index
, 1, block_index
, domain
, name
);
3703 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3705 struct symbol
*sym
, *with_opaque
= NULL
;
3706 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
3707 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3708 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3710 sym
= block_find_symbol (block
, name
, domain
,
3711 block_find_non_opaque_type_preferred
,
3714 /* Some caution must be observed with overloaded functions
3715 and methods, since the index will not contain any overload
3716 information (but NAME might contain it). */
3719 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
3721 if (with_opaque
!= NULL
3722 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
3725 /* Keep looking through other CUs. */
3733 dw2_print_stats (struct objfile
*objfile
)
3735 int i
, total
, count
;
3737 dw2_setup (objfile
);
3738 total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
3740 for (i
= 0; i
< total
; ++i
)
3742 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3744 if (!per_cu
->v
.quick
->compunit_symtab
)
3747 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3748 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3751 /* This dumps minimal information about the index.
3752 It is called via "mt print objfiles".
3753 One use is to verify .gdb_index has been loaded by the
3754 gdb.dwarf2/gdb-index.exp testcase. */
3757 dw2_dump (struct objfile
*objfile
)
3759 dw2_setup (objfile
);
3760 gdb_assert (dwarf2_per_objfile
->using_index
);
3761 printf_filtered (".gdb_index:");
3762 if (dwarf2_per_objfile
->index_table
!= NULL
)
3764 printf_filtered (" version %d\n",
3765 dwarf2_per_objfile
->index_table
->version
);
3768 printf_filtered (" faked for \"readnow\"\n");
3769 printf_filtered ("\n");
3773 dw2_relocate (struct objfile
*objfile
,
3774 const struct section_offsets
*new_offsets
,
3775 const struct section_offsets
*delta
)
3777 /* There's nothing to relocate here. */
3781 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3782 const char *func_name
)
3784 struct mapped_index
*index
;
3786 dw2_setup (objfile
);
3788 index
= dwarf2_per_objfile
->index_table
;
3790 /* index is NULL if OBJF_READNOW. */
3793 struct dw2_symtab_iterator iter
;
3794 struct dwarf2_per_cu_data
*per_cu
;
3796 /* Note: It doesn't matter what we pass for block_index here. */
3797 dw2_symtab_iter_init (&iter
, index
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
3800 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3801 dw2_instantiate_symtab (per_cu
);
3806 dw2_expand_all_symtabs (struct objfile
*objfile
)
3810 dw2_setup (objfile
);
3812 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3813 + dwarf2_per_objfile
->n_type_units
); ++i
)
3815 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3817 dw2_instantiate_symtab (per_cu
);
3822 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3823 const char *fullname
)
3827 dw2_setup (objfile
);
3829 /* We don't need to consider type units here.
3830 This is only called for examining code, e.g. expand_line_sal.
3831 There can be an order of magnitude (or more) more type units
3832 than comp units, and we avoid them if we can. */
3834 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3837 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3838 struct quick_file_names
*file_data
;
3840 /* We only need to look at symtabs not already expanded. */
3841 if (per_cu
->v
.quick
->compunit_symtab
)
3844 file_data
= dw2_get_file_names (per_cu
);
3845 if (file_data
== NULL
)
3848 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3850 const char *this_fullname
= file_data
->file_names
[j
];
3852 if (filename_cmp (this_fullname
, fullname
) == 0)
3854 dw2_instantiate_symtab (per_cu
);
3862 dw2_map_matching_symbols (struct objfile
*objfile
,
3863 const char * name
, domain_enum domain
,
3865 int (*callback
) (struct block
*,
3866 struct symbol
*, void *),
3867 void *data
, symbol_compare_ftype
*match
,
3868 symbol_compare_ftype
*ordered_compare
)
3870 /* Currently unimplemented; used for Ada. The function can be called if the
3871 current language is Ada for a non-Ada objfile using GNU index. As Ada
3872 does not look for non-Ada symbols this function should just return. */
3876 dw2_expand_symtabs_matching
3877 (struct objfile
*objfile
,
3878 expand_symtabs_file_matcher_ftype
*file_matcher
,
3879 expand_symtabs_symbol_matcher_ftype
*symbol_matcher
,
3880 expand_symtabs_exp_notify_ftype
*expansion_notify
,
3881 enum search_domain kind
,
3886 struct mapped_index
*index
;
3888 dw2_setup (objfile
);
3890 /* index_table is NULL if OBJF_READNOW. */
3891 if (!dwarf2_per_objfile
->index_table
)
3893 index
= dwarf2_per_objfile
->index_table
;
3895 if (file_matcher
!= NULL
)
3897 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
3899 NULL
, xcalloc
, xfree
));
3900 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
3902 NULL
, xcalloc
, xfree
));
3904 /* The rule is CUs specify all the files, including those used by
3905 any TU, so there's no need to scan TUs here. */
3907 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3910 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3911 struct quick_file_names
*file_data
;
3916 per_cu
->v
.quick
->mark
= 0;
3918 /* We only need to look at symtabs not already expanded. */
3919 if (per_cu
->v
.quick
->compunit_symtab
)
3922 file_data
= dw2_get_file_names (per_cu
);
3923 if (file_data
== NULL
)
3926 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
3928 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
3930 per_cu
->v
.quick
->mark
= 1;
3934 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3936 const char *this_real_name
;
3938 if (file_matcher (file_data
->file_names
[j
], data
, 0))
3940 per_cu
->v
.quick
->mark
= 1;
3944 /* Before we invoke realpath, which can get expensive when many
3945 files are involved, do a quick comparison of the basenames. */
3946 if (!basenames_may_differ
3947 && !file_matcher (lbasename (file_data
->file_names
[j
]),
3951 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3952 if (file_matcher (this_real_name
, data
, 0))
3954 per_cu
->v
.quick
->mark
= 1;
3959 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3960 ? visited_found
.get ()
3961 : visited_not_found
.get (),
3967 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3969 offset_type idx
= 2 * iter
;
3971 offset_type
*vec
, vec_len
, vec_idx
;
3972 int global_seen
= 0;
3976 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3979 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3981 if (! (*symbol_matcher
) (name
, data
))
3984 /* The name was matched, now expand corresponding CUs that were
3986 vec
= (offset_type
*) (index
->constant_pool
3987 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3988 vec_len
= MAYBE_SWAP (vec
[0]);
3989 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3991 struct dwarf2_per_cu_data
*per_cu
;
3992 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3993 /* This value is only valid for index versions >= 7. */
3994 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3995 gdb_index_symbol_kind symbol_kind
=
3996 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3997 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3998 /* Only check the symbol attributes if they're present.
3999 Indices prior to version 7 don't record them,
4000 and indices >= 7 may elide them for certain symbols
4001 (gold does this). */
4003 (index
->version
>= 7
4004 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4006 /* Work around gold/15646. */
4009 if (!is_static
&& global_seen
)
4015 /* Only check the symbol's kind if it has one. */
4020 case VARIABLES_DOMAIN
:
4021 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4024 case FUNCTIONS_DOMAIN
:
4025 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4029 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4037 /* Don't crash on bad data. */
4038 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
4039 + dwarf2_per_objfile
->n_type_units
))
4041 complaint (&symfile_complaints
,
4042 _(".gdb_index entry has bad CU index"
4043 " [in module %s]"), objfile_name (objfile
));
4047 per_cu
= dw2_get_cutu (cu_index
);
4048 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4050 int symtab_was_null
=
4051 (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4053 dw2_instantiate_symtab (per_cu
);
4055 if (expansion_notify
!= NULL
4057 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4059 expansion_notify (per_cu
->v
.quick
->compunit_symtab
,
4067 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4070 static struct compunit_symtab
*
4071 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4076 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4077 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4080 if (cust
->includes
== NULL
)
4083 for (i
= 0; cust
->includes
[i
]; ++i
)
4085 struct compunit_symtab
*s
= cust
->includes
[i
];
4087 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4095 static struct compunit_symtab
*
4096 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4097 struct bound_minimal_symbol msymbol
,
4099 struct obj_section
*section
,
4102 struct dwarf2_per_cu_data
*data
;
4103 struct compunit_symtab
*result
;
4105 dw2_setup (objfile
);
4107 if (!objfile
->psymtabs_addrmap
)
4110 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
4115 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4116 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4117 paddress (get_objfile_arch (objfile
), pc
));
4120 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
4122 gdb_assert (result
!= NULL
);
4127 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4128 void *data
, int need_fullname
)
4131 htab_up
visited (htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
4132 NULL
, xcalloc
, xfree
));
4134 dw2_setup (objfile
);
4136 /* The rule is CUs specify all the files, including those used by
4137 any TU, so there's no need to scan TUs here.
4138 We can ignore file names coming from already-expanded CUs. */
4140 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4142 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4144 if (per_cu
->v
.quick
->compunit_symtab
)
4146 void **slot
= htab_find_slot (visited
.get (),
4147 per_cu
->v
.quick
->file_names
,
4150 *slot
= per_cu
->v
.quick
->file_names
;
4154 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4157 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4158 struct quick_file_names
*file_data
;
4161 /* We only need to look at symtabs not already expanded. */
4162 if (per_cu
->v
.quick
->compunit_symtab
)
4165 file_data
= dw2_get_file_names (per_cu
);
4166 if (file_data
== NULL
)
4169 slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4172 /* Already visited. */
4177 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4179 const char *this_real_name
;
4182 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4184 this_real_name
= NULL
;
4185 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
4191 dw2_has_symbols (struct objfile
*objfile
)
4196 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4199 dw2_find_last_source_symtab
,
4200 dw2_forget_cached_source_info
,
4201 dw2_map_symtabs_matching_filename
,
4206 dw2_expand_symtabs_for_function
,
4207 dw2_expand_all_symtabs
,
4208 dw2_expand_symtabs_with_fullname
,
4209 dw2_map_matching_symbols
,
4210 dw2_expand_symtabs_matching
,
4211 dw2_find_pc_sect_compunit_symtab
,
4212 dw2_map_symbol_filenames
4215 /* Initialize for reading DWARF for this objfile. Return 0 if this
4216 file will use psymtabs, or 1 if using the GNU index. */
4219 dwarf2_initialize_objfile (struct objfile
*objfile
)
4221 /* If we're about to read full symbols, don't bother with the
4222 indices. In this case we also don't care if some other debug
4223 format is making psymtabs, because they are all about to be
4225 if ((objfile
->flags
& OBJF_READNOW
))
4229 dwarf2_per_objfile
->using_index
= 1;
4230 create_all_comp_units (objfile
);
4231 create_all_type_units (objfile
);
4232 dwarf2_per_objfile
->quick_file_names_table
=
4233 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
4235 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
4236 + dwarf2_per_objfile
->n_type_units
); ++i
)
4238 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4240 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4241 struct dwarf2_per_cu_quick_data
);
4244 /* Return 1 so that gdb sees the "quick" functions. However,
4245 these functions will be no-ops because we will have expanded
4250 if (dwarf2_read_index (objfile
))
4258 /* Build a partial symbol table. */
4261 dwarf2_build_psymtabs (struct objfile
*objfile
)
4264 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
4266 init_psymbol_list (objfile
, 1024);
4271 /* This isn't really ideal: all the data we allocate on the
4272 objfile's obstack is still uselessly kept around. However,
4273 freeing it seems unsafe. */
4274 psymtab_discarder
psymtabs (objfile
);
4275 dwarf2_build_psymtabs_hard (objfile
);
4278 CATCH (except
, RETURN_MASK_ERROR
)
4280 exception_print (gdb_stderr
, except
);
4285 /* Return the total length of the CU described by HEADER. */
4288 get_cu_length (const struct comp_unit_head
*header
)
4290 return header
->initial_length_size
+ header
->length
;
4293 /* Return TRUE if OFFSET is within CU_HEADER. */
4296 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
4298 sect_offset bottom
= { cu_header
->offset
.sect_off
};
4299 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
4301 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
4304 /* Find the base address of the compilation unit for range lists and
4305 location lists. It will normally be specified by DW_AT_low_pc.
4306 In DWARF-3 draft 4, the base address could be overridden by
4307 DW_AT_entry_pc. It's been removed, but GCC still uses this for
4308 compilation units with discontinuous ranges. */
4311 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
4313 struct attribute
*attr
;
4316 cu
->base_address
= 0;
4318 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
4321 cu
->base_address
= attr_value_as_address (attr
);
4326 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4329 cu
->base_address
= attr_value_as_address (attr
);
4335 /* Read in the comp unit header information from the debug_info at info_ptr.
4336 NOTE: This leaves members offset, first_die_offset to be filled in
4339 static const gdb_byte
*
4340 read_comp_unit_head (struct comp_unit_head
*cu_header
,
4341 const gdb_byte
*info_ptr
, bfd
*abfd
)
4344 unsigned int bytes_read
;
4346 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
4347 cu_header
->initial_length_size
= bytes_read
;
4348 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
4349 info_ptr
+= bytes_read
;
4350 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
4352 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
4354 info_ptr
+= bytes_read
;
4355 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
4357 signed_addr
= bfd_get_sign_extend_vma (abfd
);
4358 if (signed_addr
< 0)
4359 internal_error (__FILE__
, __LINE__
,
4360 _("read_comp_unit_head: dwarf from non elf file"));
4361 cu_header
->signed_addr_p
= signed_addr
;
4366 /* Helper function that returns the proper abbrev section for
4369 static struct dwarf2_section_info
*
4370 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
4372 struct dwarf2_section_info
*abbrev
;
4374 if (this_cu
->is_dwz
)
4375 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
4377 abbrev
= &dwarf2_per_objfile
->abbrev
;
4382 /* Subroutine of read_and_check_comp_unit_head and
4383 read_and_check_type_unit_head to simplify them.
4384 Perform various error checking on the header. */
4387 error_check_comp_unit_head (struct comp_unit_head
*header
,
4388 struct dwarf2_section_info
*section
,
4389 struct dwarf2_section_info
*abbrev_section
)
4391 const char *filename
= get_section_file_name (section
);
4393 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
4394 error (_("Dwarf Error: wrong version in compilation unit header "
4395 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
4398 if (header
->abbrev_offset
.sect_off
4399 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
4400 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
4401 "(offset 0x%lx + 6) [in module %s]"),
4402 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
4405 /* Cast to unsigned long to use 64-bit arithmetic when possible to
4406 avoid potential 32-bit overflow. */
4407 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
4409 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
4410 "(offset 0x%lx + 0) [in module %s]"),
4411 (long) header
->length
, (long) header
->offset
.sect_off
,
4415 /* Read in a CU/TU header and perform some basic error checking.
4416 The contents of the header are stored in HEADER.
4417 The result is a pointer to the start of the first DIE. */
4419 static const gdb_byte
*
4420 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
4421 struct dwarf2_section_info
*section
,
4422 struct dwarf2_section_info
*abbrev_section
,
4423 const gdb_byte
*info_ptr
,
4424 int is_debug_types_section
)
4426 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
4427 bfd
*abfd
= get_section_bfd_owner (section
);
4429 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4431 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
4433 /* If we're reading a type unit, skip over the signature and
4434 type_offset fields. */
4435 if (is_debug_types_section
)
4436 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
4438 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4440 error_check_comp_unit_head (header
, section
, abbrev_section
);
4445 /* Read in the types comp unit header information from .debug_types entry at
4446 types_ptr. The result is a pointer to one past the end of the header. */
4448 static const gdb_byte
*
4449 read_and_check_type_unit_head (struct comp_unit_head
*header
,
4450 struct dwarf2_section_info
*section
,
4451 struct dwarf2_section_info
*abbrev_section
,
4452 const gdb_byte
*info_ptr
,
4453 ULONGEST
*signature
,
4454 cu_offset
*type_offset_in_tu
)
4456 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
4457 bfd
*abfd
= get_section_bfd_owner (section
);
4459 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4461 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
4463 /* If we're reading a type unit, skip over the signature and
4464 type_offset fields. */
4465 if (signature
!= NULL
)
4466 *signature
= read_8_bytes (abfd
, info_ptr
);
4468 if (type_offset_in_tu
!= NULL
)
4469 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
4470 header
->offset_size
);
4471 info_ptr
+= header
->offset_size
;
4473 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4475 error_check_comp_unit_head (header
, section
, abbrev_section
);
4480 /* Fetch the abbreviation table offset from a comp or type unit header. */
4483 read_abbrev_offset (struct dwarf2_section_info
*section
,
4486 bfd
*abfd
= get_section_bfd_owner (section
);
4487 const gdb_byte
*info_ptr
;
4488 unsigned int initial_length_size
, offset_size
;
4489 sect_offset abbrev_offset
;
4491 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
4492 info_ptr
= section
->buffer
+ offset
.sect_off
;
4493 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
4494 offset_size
= initial_length_size
== 4 ? 4 : 8;
4495 info_ptr
+= initial_length_size
+ 2 /*version*/;
4496 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
4497 return abbrev_offset
;
4500 /* Allocate a new partial symtab for file named NAME and mark this new
4501 partial symtab as being an include of PST. */
4504 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
4505 struct objfile
*objfile
)
4507 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
4509 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
4511 /* It shares objfile->objfile_obstack. */
4512 subpst
->dirname
= pst
->dirname
;
4515 subpst
->textlow
= 0;
4516 subpst
->texthigh
= 0;
4518 subpst
->dependencies
4519 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
4520 subpst
->dependencies
[0] = pst
;
4521 subpst
->number_of_dependencies
= 1;
4523 subpst
->globals_offset
= 0;
4524 subpst
->n_global_syms
= 0;
4525 subpst
->statics_offset
= 0;
4526 subpst
->n_static_syms
= 0;
4527 subpst
->compunit_symtab
= NULL
;
4528 subpst
->read_symtab
= pst
->read_symtab
;
4531 /* No private part is necessary for include psymtabs. This property
4532 can be used to differentiate between such include psymtabs and
4533 the regular ones. */
4534 subpst
->read_symtab_private
= NULL
;
4537 /* Read the Line Number Program data and extract the list of files
4538 included by the source file represented by PST. Build an include
4539 partial symtab for each of these included files. */
4542 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4543 struct die_info
*die
,
4544 struct partial_symtab
*pst
)
4546 struct line_header
*lh
= NULL
;
4547 struct attribute
*attr
;
4549 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4551 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
4553 return; /* No linetable, so no includes. */
4555 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4556 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
4558 free_line_header (lh
);
4562 hash_signatured_type (const void *item
)
4564 const struct signatured_type
*sig_type
4565 = (const struct signatured_type
*) item
;
4567 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4568 return sig_type
->signature
;
4572 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4574 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
4575 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
4577 return lhs
->signature
== rhs
->signature
;
4580 /* Allocate a hash table for signatured types. */
4583 allocate_signatured_type_table (struct objfile
*objfile
)
4585 return htab_create_alloc_ex (41,
4586 hash_signatured_type
,
4589 &objfile
->objfile_obstack
,
4590 hashtab_obstack_allocate
,
4591 dummy_obstack_deallocate
);
4594 /* A helper function to add a signatured type CU to a table. */
4597 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4599 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
4600 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
4608 /* Create the hash table of all entries in the .debug_types
4609 (or .debug_types.dwo) section(s).
4610 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
4611 otherwise it is NULL.
4613 The result is a pointer to the hash table or NULL if there are no types.
4615 Note: This function processes DWO files only, not DWP files. */
4618 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4619 VEC (dwarf2_section_info_def
) *types
)
4621 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4622 htab_t types_htab
= NULL
;
4624 struct dwarf2_section_info
*section
;
4625 struct dwarf2_section_info
*abbrev_section
;
4627 if (VEC_empty (dwarf2_section_info_def
, types
))
4630 abbrev_section
= (dwo_file
!= NULL
4631 ? &dwo_file
->sections
.abbrev
4632 : &dwarf2_per_objfile
->abbrev
);
4634 if (dwarf_read_debug
)
4635 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
4636 dwo_file
? ".dwo" : "",
4637 get_section_file_name (abbrev_section
));
4640 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4644 const gdb_byte
*info_ptr
, *end_ptr
;
4646 dwarf2_read_section (objfile
, section
);
4647 info_ptr
= section
->buffer
;
4649 if (info_ptr
== NULL
)
4652 /* We can't set abfd until now because the section may be empty or
4653 not present, in which case the bfd is unknown. */
4654 abfd
= get_section_bfd_owner (section
);
4656 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4657 because we don't need to read any dies: the signature is in the
4660 end_ptr
= info_ptr
+ section
->size
;
4661 while (info_ptr
< end_ptr
)
4664 cu_offset type_offset_in_tu
;
4666 struct signatured_type
*sig_type
;
4667 struct dwo_unit
*dwo_tu
;
4669 const gdb_byte
*ptr
= info_ptr
;
4670 struct comp_unit_head header
;
4671 unsigned int length
;
4673 offset
.sect_off
= ptr
- section
->buffer
;
4675 /* We need to read the type's signature in order to build the hash
4676 table, but we don't need anything else just yet. */
4678 ptr
= read_and_check_type_unit_head (&header
, section
,
4679 abbrev_section
, ptr
,
4680 &signature
, &type_offset_in_tu
);
4682 length
= get_cu_length (&header
);
4684 /* Skip dummy type units. */
4685 if (ptr
>= info_ptr
+ length
4686 || peek_abbrev_code (abfd
, ptr
) == 0)
4692 if (types_htab
== NULL
)
4695 types_htab
= allocate_dwo_unit_table (objfile
);
4697 types_htab
= allocate_signatured_type_table (objfile
);
4703 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4705 dwo_tu
->dwo_file
= dwo_file
;
4706 dwo_tu
->signature
= signature
;
4707 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
4708 dwo_tu
->section
= section
;
4709 dwo_tu
->offset
= offset
;
4710 dwo_tu
->length
= length
;
4714 /* N.B.: type_offset is not usable if this type uses a DWO file.
4715 The real type_offset is in the DWO file. */
4717 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4718 struct signatured_type
);
4719 sig_type
->signature
= signature
;
4720 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
4721 sig_type
->per_cu
.objfile
= objfile
;
4722 sig_type
->per_cu
.is_debug_types
= 1;
4723 sig_type
->per_cu
.section
= section
;
4724 sig_type
->per_cu
.offset
= offset
;
4725 sig_type
->per_cu
.length
= length
;
4728 slot
= htab_find_slot (types_htab
,
4729 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4731 gdb_assert (slot
!= NULL
);
4734 sect_offset dup_offset
;
4738 const struct dwo_unit
*dup_tu
4739 = (const struct dwo_unit
*) *slot
;
4741 dup_offset
= dup_tu
->offset
;
4745 const struct signatured_type
*dup_tu
4746 = (const struct signatured_type
*) *slot
;
4748 dup_offset
= dup_tu
->per_cu
.offset
;
4751 complaint (&symfile_complaints
,
4752 _("debug type entry at offset 0x%x is duplicate to"
4753 " the entry at offset 0x%x, signature %s"),
4754 offset
.sect_off
, dup_offset
.sect_off
,
4755 hex_string (signature
));
4757 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4759 if (dwarf_read_debug
> 1)
4760 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature %s\n",
4762 hex_string (signature
));
4771 /* Create the hash table of all entries in the .debug_types section,
4772 and initialize all_type_units.
4773 The result is zero if there is an error (e.g. missing .debug_types section),
4774 otherwise non-zero. */
4777 create_all_type_units (struct objfile
*objfile
)
4780 struct signatured_type
**iter
;
4782 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4783 if (types_htab
== NULL
)
4785 dwarf2_per_objfile
->signatured_types
= NULL
;
4789 dwarf2_per_objfile
->signatured_types
= types_htab
;
4791 dwarf2_per_objfile
->n_type_units
4792 = dwarf2_per_objfile
->n_allocated_type_units
4793 = htab_elements (types_htab
);
4794 dwarf2_per_objfile
->all_type_units
=
4795 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
4796 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4797 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4798 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4799 == dwarf2_per_objfile
->n_type_units
);
4804 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
4805 If SLOT is non-NULL, it is the entry to use in the hash table.
4806 Otherwise we find one. */
4808 static struct signatured_type
*
4809 add_type_unit (ULONGEST sig
, void **slot
)
4811 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4812 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
4813 struct signatured_type
*sig_type
;
4815 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
4817 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
4819 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
4820 dwarf2_per_objfile
->n_allocated_type_units
= 1;
4821 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
4822 dwarf2_per_objfile
->all_type_units
4823 = XRESIZEVEC (struct signatured_type
*,
4824 dwarf2_per_objfile
->all_type_units
,
4825 dwarf2_per_objfile
->n_allocated_type_units
);
4826 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
4828 dwarf2_per_objfile
->n_type_units
= n_type_units
;
4830 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4831 struct signatured_type
);
4832 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
4833 sig_type
->signature
= sig
;
4834 sig_type
->per_cu
.is_debug_types
= 1;
4835 if (dwarf2_per_objfile
->using_index
)
4837 sig_type
->per_cu
.v
.quick
=
4838 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4839 struct dwarf2_per_cu_quick_data
);
4844 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
4847 gdb_assert (*slot
== NULL
);
4849 /* The rest of sig_type must be filled in by the caller. */
4853 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
4854 Fill in SIG_ENTRY with DWO_ENTRY. */
4857 fill_in_sig_entry_from_dwo_entry (struct objfile
*objfile
,
4858 struct signatured_type
*sig_entry
,
4859 struct dwo_unit
*dwo_entry
)
4861 /* Make sure we're not clobbering something we don't expect to. */
4862 gdb_assert (! sig_entry
->per_cu
.queued
);
4863 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
4864 if (dwarf2_per_objfile
->using_index
)
4866 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
4867 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
4870 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
4871 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
4872 gdb_assert (sig_entry
->type_offset_in_section
.sect_off
== 0);
4873 gdb_assert (sig_entry
->type_unit_group
== NULL
);
4874 gdb_assert (sig_entry
->dwo_unit
== NULL
);
4876 sig_entry
->per_cu
.section
= dwo_entry
->section
;
4877 sig_entry
->per_cu
.offset
= dwo_entry
->offset
;
4878 sig_entry
->per_cu
.length
= dwo_entry
->length
;
4879 sig_entry
->per_cu
.reading_dwo_directly
= 1;
4880 sig_entry
->per_cu
.objfile
= objfile
;
4881 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
4882 sig_entry
->dwo_unit
= dwo_entry
;
4885 /* Subroutine of lookup_signatured_type.
4886 If we haven't read the TU yet, create the signatured_type data structure
4887 for a TU to be read in directly from a DWO file, bypassing the stub.
4888 This is the "Stay in DWO Optimization": When there is no DWP file and we're
4889 using .gdb_index, then when reading a CU we want to stay in the DWO file
4890 containing that CU. Otherwise we could end up reading several other DWO
4891 files (due to comdat folding) to process the transitive closure of all the
4892 mentioned TUs, and that can be slow. The current DWO file will have every
4893 type signature that it needs.
4894 We only do this for .gdb_index because in the psymtab case we already have
4895 to read all the DWOs to build the type unit groups. */
4897 static struct signatured_type
*
4898 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
4900 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4901 struct dwo_file
*dwo_file
;
4902 struct dwo_unit find_dwo_entry
, *dwo_entry
;
4903 struct signatured_type find_sig_entry
, *sig_entry
;
4906 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
4908 /* If TU skeletons have been removed then we may not have read in any
4910 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4912 dwarf2_per_objfile
->signatured_types
4913 = allocate_signatured_type_table (objfile
);
4916 /* We only ever need to read in one copy of a signatured type.
4917 Use the global signatured_types array to do our own comdat-folding
4918 of types. If this is the first time we're reading this TU, and
4919 the TU has an entry in .gdb_index, replace the recorded data from
4920 .gdb_index with this TU. */
4922 find_sig_entry
.signature
= sig
;
4923 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
4924 &find_sig_entry
, INSERT
);
4925 sig_entry
= (struct signatured_type
*) *slot
;
4927 /* We can get here with the TU already read, *or* in the process of being
4928 read. Don't reassign the global entry to point to this DWO if that's
4929 the case. Also note that if the TU is already being read, it may not
4930 have come from a DWO, the program may be a mix of Fission-compiled
4931 code and non-Fission-compiled code. */
4933 /* Have we already tried to read this TU?
4934 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
4935 needn't exist in the global table yet). */
4936 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
4939 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
4940 dwo_unit of the TU itself. */
4941 dwo_file
= cu
->dwo_unit
->dwo_file
;
4943 /* Ok, this is the first time we're reading this TU. */
4944 if (dwo_file
->tus
== NULL
)
4946 find_dwo_entry
.signature
= sig
;
4947 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
4948 if (dwo_entry
== NULL
)
4951 /* If the global table doesn't have an entry for this TU, add one. */
4952 if (sig_entry
== NULL
)
4953 sig_entry
= add_type_unit (sig
, slot
);
4955 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
4956 sig_entry
->per_cu
.tu_read
= 1;
4960 /* Subroutine of lookup_signatured_type.
4961 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
4962 then try the DWP file. If the TU stub (skeleton) has been removed then
4963 it won't be in .gdb_index. */
4965 static struct signatured_type
*
4966 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
4968 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4969 struct dwp_file
*dwp_file
= get_dwp_file ();
4970 struct dwo_unit
*dwo_entry
;
4971 struct signatured_type find_sig_entry
, *sig_entry
;
4974 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
4975 gdb_assert (dwp_file
!= NULL
);
4977 /* If TU skeletons have been removed then we may not have read in any
4979 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4981 dwarf2_per_objfile
->signatured_types
4982 = allocate_signatured_type_table (objfile
);
4985 find_sig_entry
.signature
= sig
;
4986 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
4987 &find_sig_entry
, INSERT
);
4988 sig_entry
= (struct signatured_type
*) *slot
;
4990 /* Have we already tried to read this TU?
4991 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
4992 needn't exist in the global table yet). */
4993 if (sig_entry
!= NULL
)
4996 if (dwp_file
->tus
== NULL
)
4998 dwo_entry
= lookup_dwo_unit_in_dwp (dwp_file
, NULL
,
4999 sig
, 1 /* is_debug_types */);
5000 if (dwo_entry
== NULL
)
5003 sig_entry
= add_type_unit (sig
, slot
);
5004 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
5009 /* Lookup a signature based type for DW_FORM_ref_sig8.
5010 Returns NULL if signature SIG is not present in the table.
5011 It is up to the caller to complain about this. */
5013 static struct signatured_type
*
5014 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5017 && dwarf2_per_objfile
->using_index
)
5019 /* We're in a DWO/DWP file, and we're using .gdb_index.
5020 These cases require special processing. */
5021 if (get_dwp_file () == NULL
)
5022 return lookup_dwo_signatured_type (cu
, sig
);
5024 return lookup_dwp_signatured_type (cu
, sig
);
5028 struct signatured_type find_entry
, *entry
;
5030 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5032 find_entry
.signature
= sig
;
5033 entry
= ((struct signatured_type
*)
5034 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
5039 /* Low level DIE reading support. */
5041 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
5044 init_cu_die_reader (struct die_reader_specs
*reader
,
5045 struct dwarf2_cu
*cu
,
5046 struct dwarf2_section_info
*section
,
5047 struct dwo_file
*dwo_file
)
5049 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
5050 reader
->abfd
= get_section_bfd_owner (section
);
5052 reader
->dwo_file
= dwo_file
;
5053 reader
->die_section
= section
;
5054 reader
->buffer
= section
->buffer
;
5055 reader
->buffer_end
= section
->buffer
+ section
->size
;
5056 reader
->comp_dir
= NULL
;
5059 /* Subroutine of init_cutu_and_read_dies to simplify it.
5060 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
5061 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
5064 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
5065 from it to the DIE in the DWO. If NULL we are skipping the stub.
5066 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
5067 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
5068 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
5069 STUB_COMP_DIR may be non-NULL.
5070 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
5071 are filled in with the info of the DIE from the DWO file.
5072 ABBREV_TABLE_PROVIDED is non-zero if the caller of init_cutu_and_read_dies
5073 provided an abbrev table to use.
5074 The result is non-zero if a valid (non-dummy) DIE was found. */
5077 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
5078 struct dwo_unit
*dwo_unit
,
5079 int abbrev_table_provided
,
5080 struct die_info
*stub_comp_unit_die
,
5081 const char *stub_comp_dir
,
5082 struct die_reader_specs
*result_reader
,
5083 const gdb_byte
**result_info_ptr
,
5084 struct die_info
**result_comp_unit_die
,
5085 int *result_has_children
)
5087 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5088 struct dwarf2_cu
*cu
= this_cu
->cu
;
5089 struct dwarf2_section_info
*section
;
5091 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5092 ULONGEST signature
; /* Or dwo_id. */
5093 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
5094 int i
,num_extra_attrs
;
5095 struct dwarf2_section_info
*dwo_abbrev_section
;
5096 struct attribute
*attr
;
5097 struct die_info
*comp_unit_die
;
5099 /* At most one of these may be provided. */
5100 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
5102 /* These attributes aren't processed until later:
5103 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
5104 DW_AT_comp_dir is used now, to find the DWO file, but it is also
5105 referenced later. However, these attributes are found in the stub
5106 which we won't have later. In order to not impose this complication
5107 on the rest of the code, we read them here and copy them to the
5116 if (stub_comp_unit_die
!= NULL
)
5118 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
5120 if (! this_cu
->is_debug_types
)
5121 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
5122 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
5123 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
5124 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
5125 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
5127 /* There should be a DW_AT_addr_base attribute here (if needed).
5128 We need the value before we can process DW_FORM_GNU_addr_index. */
5130 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
5132 cu
->addr_base
= DW_UNSND (attr
);
5134 /* There should be a DW_AT_ranges_base attribute here (if needed).
5135 We need the value before we can process DW_AT_ranges. */
5136 cu
->ranges_base
= 0;
5137 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
5139 cu
->ranges_base
= DW_UNSND (attr
);
5141 else if (stub_comp_dir
!= NULL
)
5143 /* Reconstruct the comp_dir attribute to simplify the code below. */
5144 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
5145 comp_dir
->name
= DW_AT_comp_dir
;
5146 comp_dir
->form
= DW_FORM_string
;
5147 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
5148 DW_STRING (comp_dir
) = stub_comp_dir
;
5151 /* Set up for reading the DWO CU/TU. */
5152 cu
->dwo_unit
= dwo_unit
;
5153 section
= dwo_unit
->section
;
5154 dwarf2_read_section (objfile
, section
);
5155 abfd
= get_section_bfd_owner (section
);
5156 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
5157 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
5158 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
);
5160 if (this_cu
->is_debug_types
)
5162 ULONGEST header_signature
;
5163 cu_offset type_offset_in_tu
;
5164 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
5166 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
5170 &type_offset_in_tu
);
5171 /* This is not an assert because it can be caused by bad debug info. */
5172 if (sig_type
->signature
!= header_signature
)
5174 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
5175 " TU at offset 0x%x [in module %s]"),
5176 hex_string (sig_type
->signature
),
5177 hex_string (header_signature
),
5178 dwo_unit
->offset
.sect_off
,
5179 bfd_get_filename (abfd
));
5181 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5182 /* For DWOs coming from DWP files, we don't know the CU length
5183 nor the type's offset in the TU until now. */
5184 dwo_unit
->length
= get_cu_length (&cu
->header
);
5185 dwo_unit
->type_offset_in_tu
= type_offset_in_tu
;
5187 /* Establish the type offset that can be used to lookup the type.
5188 For DWO files, we don't know it until now. */
5189 sig_type
->type_offset_in_section
.sect_off
=
5190 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
5194 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5197 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5198 /* For DWOs coming from DWP files, we don't know the CU length
5200 dwo_unit
->length
= get_cu_length (&cu
->header
);
5203 /* Replace the CU's original abbrev table with the DWO's.
5204 Reminder: We can't read the abbrev table until we've read the header. */
5205 if (abbrev_table_provided
)
5207 /* Don't free the provided abbrev table, the caller of
5208 init_cutu_and_read_dies owns it. */
5209 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5210 /* Ensure the DWO abbrev table gets freed. */
5211 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5215 dwarf2_free_abbrev_table (cu
);
5216 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5217 /* Leave any existing abbrev table cleanup as is. */
5220 /* Read in the die, but leave space to copy over the attributes
5221 from the stub. This has the benefit of simplifying the rest of
5222 the code - all the work to maintain the illusion of a single
5223 DW_TAG_{compile,type}_unit DIE is done here. */
5224 num_extra_attrs
= ((stmt_list
!= NULL
)
5228 + (comp_dir
!= NULL
));
5229 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
5230 result_has_children
, num_extra_attrs
);
5232 /* Copy over the attributes from the stub to the DIE we just read in. */
5233 comp_unit_die
= *result_comp_unit_die
;
5234 i
= comp_unit_die
->num_attrs
;
5235 if (stmt_list
!= NULL
)
5236 comp_unit_die
->attrs
[i
++] = *stmt_list
;
5238 comp_unit_die
->attrs
[i
++] = *low_pc
;
5239 if (high_pc
!= NULL
)
5240 comp_unit_die
->attrs
[i
++] = *high_pc
;
5242 comp_unit_die
->attrs
[i
++] = *ranges
;
5243 if (comp_dir
!= NULL
)
5244 comp_unit_die
->attrs
[i
++] = *comp_dir
;
5245 comp_unit_die
->num_attrs
+= num_extra_attrs
;
5247 if (dwarf_die_debug
)
5249 fprintf_unfiltered (gdb_stdlog
,
5250 "Read die from %s@0x%x of %s:\n",
5251 get_section_name (section
),
5252 (unsigned) (begin_info_ptr
- section
->buffer
),
5253 bfd_get_filename (abfd
));
5254 dump_die (comp_unit_die
, dwarf_die_debug
);
5257 /* Save the comp_dir attribute. If there is no DWP file then we'll read
5258 TUs by skipping the stub and going directly to the entry in the DWO file.
5259 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
5260 to get it via circuitous means. Blech. */
5261 if (comp_dir
!= NULL
)
5262 result_reader
->comp_dir
= DW_STRING (comp_dir
);
5264 /* Skip dummy compilation units. */
5265 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
5266 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5269 *result_info_ptr
= info_ptr
;
5273 /* Subroutine of init_cutu_and_read_dies to simplify it.
5274 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
5275 Returns NULL if the specified DWO unit cannot be found. */
5277 static struct dwo_unit
*
5278 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
5279 struct die_info
*comp_unit_die
)
5281 struct dwarf2_cu
*cu
= this_cu
->cu
;
5282 struct attribute
*attr
;
5284 struct dwo_unit
*dwo_unit
;
5285 const char *comp_dir
, *dwo_name
;
5287 gdb_assert (cu
!= NULL
);
5289 /* Yeah, we look dwo_name up again, but it simplifies the code. */
5290 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5291 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
5293 if (this_cu
->is_debug_types
)
5295 struct signatured_type
*sig_type
;
5297 /* Since this_cu is the first member of struct signatured_type,
5298 we can go from a pointer to one to a pointer to the other. */
5299 sig_type
= (struct signatured_type
*) this_cu
;
5300 signature
= sig_type
->signature
;
5301 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
5305 struct attribute
*attr
;
5307 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
5309 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
5311 dwo_name
, objfile_name (this_cu
->objfile
));
5312 signature
= DW_UNSND (attr
);
5313 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
5320 /* Subroutine of init_cutu_and_read_dies to simplify it.
5321 See it for a description of the parameters.
5322 Read a TU directly from a DWO file, bypassing the stub.
5324 Note: This function could be a little bit simpler if we shared cleanups
5325 with our caller, init_cutu_and_read_dies. That's generally a fragile thing
5326 to do, so we keep this function self-contained. Or we could move this
5327 into our caller, but it's complex enough already. */
5330 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
5331 int use_existing_cu
, int keep
,
5332 die_reader_func_ftype
*die_reader_func
,
5335 struct dwarf2_cu
*cu
;
5336 struct signatured_type
*sig_type
;
5337 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5338 struct die_reader_specs reader
;
5339 const gdb_byte
*info_ptr
;
5340 struct die_info
*comp_unit_die
;
5343 /* Verify we can do the following downcast, and that we have the
5345 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
5346 sig_type
= (struct signatured_type
*) this_cu
;
5347 gdb_assert (sig_type
->dwo_unit
!= NULL
);
5349 cleanups
= make_cleanup (null_cleanup
, NULL
);
5351 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5353 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
5355 /* There's no need to do the rereading_dwo_cu handling that
5356 init_cutu_and_read_dies does since we don't read the stub. */
5360 /* If !use_existing_cu, this_cu->cu must be NULL. */
5361 gdb_assert (this_cu
->cu
== NULL
);
5362 cu
= XNEW (struct dwarf2_cu
);
5363 init_one_comp_unit (cu
, this_cu
);
5364 /* If an error occurs while loading, release our storage. */
5365 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5368 /* A future optimization, if needed, would be to use an existing
5369 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
5370 could share abbrev tables. */
5372 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
5373 0 /* abbrev_table_provided */,
5374 NULL
/* stub_comp_unit_die */,
5375 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
5377 &comp_unit_die
, &has_children
) == 0)
5380 do_cleanups (cleanups
);
5384 /* All the "real" work is done here. */
5385 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5387 /* This duplicates the code in init_cutu_and_read_dies,
5388 but the alternative is making the latter more complex.
5389 This function is only for the special case of using DWO files directly:
5390 no point in overly complicating the general case just to handle this. */
5391 if (free_cu_cleanup
!= NULL
)
5395 /* We've successfully allocated this compilation unit. Let our
5396 caller clean it up when finished with it. */
5397 discard_cleanups (free_cu_cleanup
);
5399 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5400 So we have to manually free the abbrev table. */
5401 dwarf2_free_abbrev_table (cu
);
5403 /* Link this CU into read_in_chain. */
5404 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5405 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5408 do_cleanups (free_cu_cleanup
);
5411 do_cleanups (cleanups
);
5414 /* Initialize a CU (or TU) and read its DIEs.
5415 If the CU defers to a DWO file, read the DWO file as well.
5417 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
5418 Otherwise the table specified in the comp unit header is read in and used.
5419 This is an optimization for when we already have the abbrev table.
5421 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
5422 Otherwise, a new CU is allocated with xmalloc.
5424 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
5425 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
5427 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5428 linker) then DIE_READER_FUNC will not get called. */
5431 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
5432 struct abbrev_table
*abbrev_table
,
5433 int use_existing_cu
, int keep
,
5434 die_reader_func_ftype
*die_reader_func
,
5437 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5438 struct dwarf2_section_info
*section
= this_cu
->section
;
5439 bfd
*abfd
= get_section_bfd_owner (section
);
5440 struct dwarf2_cu
*cu
;
5441 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5442 struct die_reader_specs reader
;
5443 struct die_info
*comp_unit_die
;
5445 struct attribute
*attr
;
5446 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5447 struct signatured_type
*sig_type
= NULL
;
5448 struct dwarf2_section_info
*abbrev_section
;
5449 /* Non-zero if CU currently points to a DWO file and we need to
5450 reread it. When this happens we need to reread the skeleton die
5451 before we can reread the DWO file (this only applies to CUs, not TUs). */
5452 int rereading_dwo_cu
= 0;
5454 if (dwarf_die_debug
)
5455 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5456 this_cu
->is_debug_types
? "type" : "comp",
5457 this_cu
->offset
.sect_off
);
5459 if (use_existing_cu
)
5462 /* If we're reading a TU directly from a DWO file, including a virtual DWO
5463 file (instead of going through the stub), short-circuit all of this. */
5464 if (this_cu
->reading_dwo_directly
)
5466 /* Narrow down the scope of possibilities to have to understand. */
5467 gdb_assert (this_cu
->is_debug_types
);
5468 gdb_assert (abbrev_table
== NULL
);
5469 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
5470 die_reader_func
, data
);
5474 cleanups
= make_cleanup (null_cleanup
, NULL
);
5476 /* This is cheap if the section is already read in. */
5477 dwarf2_read_section (objfile
, section
);
5479 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
5481 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
5483 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5486 /* If this CU is from a DWO file we need to start over, we need to
5487 refetch the attributes from the skeleton CU.
5488 This could be optimized by retrieving those attributes from when we
5489 were here the first time: the previous comp_unit_die was stored in
5490 comp_unit_obstack. But there's no data yet that we need this
5492 if (cu
->dwo_unit
!= NULL
)
5493 rereading_dwo_cu
= 1;
5497 /* If !use_existing_cu, this_cu->cu must be NULL. */
5498 gdb_assert (this_cu
->cu
== NULL
);
5499 cu
= XNEW (struct dwarf2_cu
);
5500 init_one_comp_unit (cu
, this_cu
);
5501 /* If an error occurs while loading, release our storage. */
5502 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5505 /* Get the header. */
5506 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
5508 /* We already have the header, there's no need to read it in again. */
5509 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
5513 if (this_cu
->is_debug_types
)
5516 cu_offset type_offset_in_tu
;
5518 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
5519 abbrev_section
, info_ptr
,
5521 &type_offset_in_tu
);
5523 /* Since per_cu is the first member of struct signatured_type,
5524 we can go from a pointer to one to a pointer to the other. */
5525 sig_type
= (struct signatured_type
*) this_cu
;
5526 gdb_assert (sig_type
->signature
== signature
);
5527 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
5528 == type_offset_in_tu
.cu_off
);
5529 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5531 /* LENGTH has not been set yet for type units if we're
5532 using .gdb_index. */
5533 this_cu
->length
= get_cu_length (&cu
->header
);
5535 /* Establish the type offset that can be used to lookup the type. */
5536 sig_type
->type_offset_in_section
.sect_off
=
5537 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
5541 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5545 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5546 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
5550 /* Skip dummy compilation units. */
5551 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5552 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5554 do_cleanups (cleanups
);
5558 /* If we don't have them yet, read the abbrevs for this compilation unit.
5559 And if we need to read them now, make sure they're freed when we're
5560 done. Note that it's important that if the CU had an abbrev table
5561 on entry we don't free it when we're done: Somewhere up the call stack
5562 it may be in use. */
5563 if (abbrev_table
!= NULL
)
5565 gdb_assert (cu
->abbrev_table
== NULL
);
5566 gdb_assert (cu
->header
.abbrev_offset
.sect_off
5567 == abbrev_table
->offset
.sect_off
);
5568 cu
->abbrev_table
= abbrev_table
;
5570 else if (cu
->abbrev_table
== NULL
)
5572 dwarf2_read_abbrevs (cu
, abbrev_section
);
5573 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5575 else if (rereading_dwo_cu
)
5577 dwarf2_free_abbrev_table (cu
);
5578 dwarf2_read_abbrevs (cu
, abbrev_section
);
5581 /* Read the top level CU/TU die. */
5582 init_cu_die_reader (&reader
, cu
, section
, NULL
);
5583 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5585 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
5587 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
5588 DWO CU, that this test will fail (the attribute will not be present). */
5589 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5592 struct dwo_unit
*dwo_unit
;
5593 struct die_info
*dwo_comp_unit_die
;
5597 complaint (&symfile_complaints
,
5598 _("compilation unit with DW_AT_GNU_dwo_name"
5599 " has children (offset 0x%x) [in module %s]"),
5600 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
5602 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
5603 if (dwo_unit
!= NULL
)
5605 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
5606 abbrev_table
!= NULL
,
5607 comp_unit_die
, NULL
,
5609 &dwo_comp_unit_die
, &has_children
) == 0)
5612 do_cleanups (cleanups
);
5615 comp_unit_die
= dwo_comp_unit_die
;
5619 /* Yikes, we couldn't find the rest of the DIE, we only have
5620 the stub. A complaint has already been logged. There's
5621 not much more we can do except pass on the stub DIE to
5622 die_reader_func. We don't want to throw an error on bad
5627 /* All of the above is setup for this call. Yikes. */
5628 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5630 /* Done, clean up. */
5631 if (free_cu_cleanup
!= NULL
)
5635 /* We've successfully allocated this compilation unit. Let our
5636 caller clean it up when finished with it. */
5637 discard_cleanups (free_cu_cleanup
);
5639 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5640 So we have to manually free the abbrev table. */
5641 dwarf2_free_abbrev_table (cu
);
5643 /* Link this CU into read_in_chain. */
5644 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5645 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5648 do_cleanups (free_cu_cleanup
);
5651 do_cleanups (cleanups
);
5654 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
5655 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
5656 to have already done the lookup to find the DWO file).
5658 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
5659 THIS_CU->is_debug_types, but nothing else.
5661 We fill in THIS_CU->length.
5663 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5664 linker) then DIE_READER_FUNC will not get called.
5666 THIS_CU->cu is always freed when done.
5667 This is done in order to not leave THIS_CU->cu in a state where we have
5668 to care whether it refers to the "main" CU or the DWO CU. */
5671 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
5672 struct dwo_file
*dwo_file
,
5673 die_reader_func_ftype
*die_reader_func
,
5676 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5677 struct dwarf2_section_info
*section
= this_cu
->section
;
5678 bfd
*abfd
= get_section_bfd_owner (section
);
5679 struct dwarf2_section_info
*abbrev_section
;
5680 struct dwarf2_cu cu
;
5681 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5682 struct die_reader_specs reader
;
5683 struct cleanup
*cleanups
;
5684 struct die_info
*comp_unit_die
;
5687 if (dwarf_die_debug
)
5688 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5689 this_cu
->is_debug_types
? "type" : "comp",
5690 this_cu
->offset
.sect_off
);
5692 gdb_assert (this_cu
->cu
== NULL
);
5694 abbrev_section
= (dwo_file
!= NULL
5695 ? &dwo_file
->sections
.abbrev
5696 : get_abbrev_section_for_cu (this_cu
));
5698 /* This is cheap if the section is already read in. */
5699 dwarf2_read_section (objfile
, section
);
5701 init_one_comp_unit (&cu
, this_cu
);
5703 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
5705 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
5706 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
5707 abbrev_section
, info_ptr
,
5708 this_cu
->is_debug_types
);
5710 this_cu
->length
= get_cu_length (&cu
.header
);
5712 /* Skip dummy compilation units. */
5713 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5714 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5716 do_cleanups (cleanups
);
5720 dwarf2_read_abbrevs (&cu
, abbrev_section
);
5721 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
5723 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
5724 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5726 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5728 do_cleanups (cleanups
);
5731 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
5732 does not lookup the specified DWO file.
5733 This cannot be used to read DWO files.
5735 THIS_CU->cu is always freed when done.
5736 This is done in order to not leave THIS_CU->cu in a state where we have
5737 to care whether it refers to the "main" CU or the DWO CU.
5738 We can revisit this if the data shows there's a performance issue. */
5741 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
5742 die_reader_func_ftype
*die_reader_func
,
5745 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
5748 /* Type Unit Groups.
5750 Type Unit Groups are a way to collapse the set of all TUs (type units) into
5751 a more manageable set. The grouping is done by DW_AT_stmt_list entry
5752 so that all types coming from the same compilation (.o file) are grouped
5753 together. A future step could be to put the types in the same symtab as
5754 the CU the types ultimately came from. */
5757 hash_type_unit_group (const void *item
)
5759 const struct type_unit_group
*tu_group
5760 = (const struct type_unit_group
*) item
;
5762 return hash_stmt_list_entry (&tu_group
->hash
);
5766 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
5768 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
5769 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
5771 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
5774 /* Allocate a hash table for type unit groups. */
5777 allocate_type_unit_groups_table (void)
5779 return htab_create_alloc_ex (3,
5780 hash_type_unit_group
,
5783 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
5784 hashtab_obstack_allocate
,
5785 dummy_obstack_deallocate
);
5788 /* Type units that don't have DW_AT_stmt_list are grouped into their own
5789 partial symtabs. We combine several TUs per psymtab to not let the size
5790 of any one psymtab grow too big. */
5791 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
5792 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5794 /* Helper routine for get_type_unit_group.
5795 Create the type_unit_group object used to hold one or more TUs. */
5797 static struct type_unit_group
*
5798 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
5800 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5801 struct dwarf2_per_cu_data
*per_cu
;
5802 struct type_unit_group
*tu_group
;
5804 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5805 struct type_unit_group
);
5806 per_cu
= &tu_group
->per_cu
;
5807 per_cu
->objfile
= objfile
;
5809 if (dwarf2_per_objfile
->using_index
)
5811 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5812 struct dwarf2_per_cu_quick_data
);
5816 unsigned int line_offset
= line_offset_struct
.sect_off
;
5817 struct partial_symtab
*pst
;
5820 /* Give the symtab a useful name for debug purposes. */
5821 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
5822 name
= xstrprintf ("<type_units_%d>",
5823 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
5825 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
5827 pst
= create_partial_symtab (per_cu
, name
);
5833 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
5834 tu_group
->hash
.line_offset
= line_offset_struct
;
5839 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5840 STMT_LIST is a DW_AT_stmt_list attribute. */
5842 static struct type_unit_group
*
5843 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
5845 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5846 struct type_unit_group
*tu_group
;
5848 unsigned int line_offset
;
5849 struct type_unit_group type_unit_group_for_lookup
;
5851 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
5853 dwarf2_per_objfile
->type_unit_groups
=
5854 allocate_type_unit_groups_table ();
5857 /* Do we need to create a new group, or can we use an existing one? */
5861 line_offset
= DW_UNSND (stmt_list
);
5862 ++tu_stats
->nr_symtab_sharers
;
5866 /* Ugh, no stmt_list. Rare, but we have to handle it.
5867 We can do various things here like create one group per TU or
5868 spread them over multiple groups to split up the expansion work.
5869 To avoid worst case scenarios (too many groups or too large groups)
5870 we, umm, group them in bunches. */
5871 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5872 | (tu_stats
->nr_stmt_less_type_units
5873 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
5874 ++tu_stats
->nr_stmt_less_type_units
;
5877 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
5878 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
5879 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
5880 &type_unit_group_for_lookup
, INSERT
);
5883 tu_group
= (struct type_unit_group
*) *slot
;
5884 gdb_assert (tu_group
!= NULL
);
5888 sect_offset line_offset_struct
;
5890 line_offset_struct
.sect_off
= line_offset
;
5891 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
5893 ++tu_stats
->nr_symtabs
;
5899 /* Partial symbol tables. */
5901 /* Create a psymtab named NAME and assign it to PER_CU.
5903 The caller must fill in the following details:
5904 dirname, textlow, texthigh. */
5906 static struct partial_symtab
*
5907 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
5909 struct objfile
*objfile
= per_cu
->objfile
;
5910 struct partial_symtab
*pst
;
5912 pst
= start_psymtab_common (objfile
, name
, 0,
5913 objfile
->global_psymbols
.next
,
5914 objfile
->static_psymbols
.next
);
5916 pst
->psymtabs_addrmap_supported
= 1;
5918 /* This is the glue that links PST into GDB's symbol API. */
5919 pst
->read_symtab_private
= per_cu
;
5920 pst
->read_symtab
= dwarf2_read_symtab
;
5921 per_cu
->v
.psymtab
= pst
;
5926 /* The DATA object passed to process_psymtab_comp_unit_reader has this
5929 struct process_psymtab_comp_unit_data
5931 /* True if we are reading a DW_TAG_partial_unit. */
5933 int want_partial_unit
;
5935 /* The "pretend" language that is used if the CU doesn't declare a
5938 enum language pretend_language
;
5941 /* die_reader_func for process_psymtab_comp_unit. */
5944 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
5945 const gdb_byte
*info_ptr
,
5946 struct die_info
*comp_unit_die
,
5950 struct dwarf2_cu
*cu
= reader
->cu
;
5951 struct objfile
*objfile
= cu
->objfile
;
5952 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5953 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5955 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
5956 struct partial_symtab
*pst
;
5957 enum pc_bounds_kind cu_bounds_kind
;
5958 const char *filename
;
5959 struct process_psymtab_comp_unit_data
*info
5960 = (struct process_psymtab_comp_unit_data
*) data
;
5962 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
5965 gdb_assert (! per_cu
->is_debug_types
);
5967 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
5969 cu
->list_in_scope
= &file_symbols
;
5971 /* Allocate a new partial symbol table structure. */
5972 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
5973 if (filename
== NULL
)
5976 pst
= create_partial_symtab (per_cu
, filename
);
5978 /* This must be done before calling dwarf2_build_include_psymtabs. */
5979 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
5981 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5983 dwarf2_find_base_address (comp_unit_die
, cu
);
5985 /* Possibly set the default values of LOWPC and HIGHPC from
5987 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
5988 &best_highpc
, cu
, pst
);
5989 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
5990 /* Store the contiguous range if it is not empty; it can be empty for
5991 CUs with no code. */
5992 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5993 gdbarch_adjust_dwarf2_addr (gdbarch
,
5994 best_lowpc
+ baseaddr
),
5995 gdbarch_adjust_dwarf2_addr (gdbarch
,
5996 best_highpc
+ baseaddr
) - 1,
5999 /* Check if comp unit has_children.
6000 If so, read the rest of the partial symbols from this comp unit.
6001 If not, there's no more debug_info for this comp unit. */
6004 struct partial_die_info
*first_die
;
6005 CORE_ADDR lowpc
, highpc
;
6007 lowpc
= ((CORE_ADDR
) -1);
6008 highpc
= ((CORE_ADDR
) 0);
6010 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6012 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
6013 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
6015 /* If we didn't find a lowpc, set it to highpc to avoid
6016 complaints from `maint check'. */
6017 if (lowpc
== ((CORE_ADDR
) -1))
6020 /* If the compilation unit didn't have an explicit address range,
6021 then use the information extracted from its child dies. */
6022 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
6025 best_highpc
= highpc
;
6028 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
6029 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
6031 end_psymtab_common (objfile
, pst
);
6033 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
6036 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6037 struct dwarf2_per_cu_data
*iter
;
6039 /* Fill in 'dependencies' here; we fill in 'users' in a
6041 pst
->number_of_dependencies
= len
;
6043 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6045 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
6048 pst
->dependencies
[i
] = iter
->v
.psymtab
;
6050 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6053 /* Get the list of files included in the current compilation unit,
6054 and build a psymtab for each of them. */
6055 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
6057 if (dwarf_read_debug
)
6059 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6061 fprintf_unfiltered (gdb_stdlog
,
6062 "Psymtab for %s unit @0x%x: %s - %s"
6063 ", %d global, %d static syms\n",
6064 per_cu
->is_debug_types
? "type" : "comp",
6065 per_cu
->offset
.sect_off
,
6066 paddress (gdbarch
, pst
->textlow
),
6067 paddress (gdbarch
, pst
->texthigh
),
6068 pst
->n_global_syms
, pst
->n_static_syms
);
6072 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6073 Process compilation unit THIS_CU for a psymtab. */
6076 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6077 int want_partial_unit
,
6078 enum language pretend_language
)
6080 struct process_psymtab_comp_unit_data info
;
6082 /* If this compilation unit was already read in, free the
6083 cached copy in order to read it in again. This is
6084 necessary because we skipped some symbols when we first
6085 read in the compilation unit (see load_partial_dies).
6086 This problem could be avoided, but the benefit is unclear. */
6087 if (this_cu
->cu
!= NULL
)
6088 free_one_cached_comp_unit (this_cu
);
6090 gdb_assert (! this_cu
->is_debug_types
);
6091 info
.want_partial_unit
= want_partial_unit
;
6092 info
.pretend_language
= pretend_language
;
6093 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
6094 process_psymtab_comp_unit_reader
,
6097 /* Age out any secondary CUs. */
6098 age_cached_comp_units ();
6101 /* Reader function for build_type_psymtabs. */
6104 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
6105 const gdb_byte
*info_ptr
,
6106 struct die_info
*type_unit_die
,
6110 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6111 struct dwarf2_cu
*cu
= reader
->cu
;
6112 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6113 struct signatured_type
*sig_type
;
6114 struct type_unit_group
*tu_group
;
6115 struct attribute
*attr
;
6116 struct partial_die_info
*first_die
;
6117 CORE_ADDR lowpc
, highpc
;
6118 struct partial_symtab
*pst
;
6120 gdb_assert (data
== NULL
);
6121 gdb_assert (per_cu
->is_debug_types
);
6122 sig_type
= (struct signatured_type
*) per_cu
;
6127 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
6128 tu_group
= get_type_unit_group (cu
, attr
);
6130 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
6132 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
6133 cu
->list_in_scope
= &file_symbols
;
6134 pst
= create_partial_symtab (per_cu
, "");
6137 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6139 lowpc
= (CORE_ADDR
) -1;
6140 highpc
= (CORE_ADDR
) 0;
6141 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
6143 end_psymtab_common (objfile
, pst
);
6146 /* Struct used to sort TUs by their abbreviation table offset. */
6148 struct tu_abbrev_offset
6150 struct signatured_type
*sig_type
;
6151 sect_offset abbrev_offset
;
6154 /* Helper routine for build_type_psymtabs_1, passed to qsort. */
6157 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
6159 const struct tu_abbrev_offset
* const *a
6160 = (const struct tu_abbrev_offset
* const*) ap
;
6161 const struct tu_abbrev_offset
* const *b
6162 = (const struct tu_abbrev_offset
* const*) bp
;
6163 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
6164 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
6166 return (aoff
> boff
) - (aoff
< boff
);
6169 /* Efficiently read all the type units.
6170 This does the bulk of the work for build_type_psymtabs.
6172 The efficiency is because we sort TUs by the abbrev table they use and
6173 only read each abbrev table once. In one program there are 200K TUs
6174 sharing 8K abbrev tables.
6176 The main purpose of this function is to support building the
6177 dwarf2_per_objfile->type_unit_groups table.
6178 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
6179 can collapse the search space by grouping them by stmt_list.
6180 The savings can be significant, in the same program from above the 200K TUs
6181 share 8K stmt_list tables.
6183 FUNC is expected to call get_type_unit_group, which will create the
6184 struct type_unit_group if necessary and add it to
6185 dwarf2_per_objfile->type_unit_groups. */
6188 build_type_psymtabs_1 (void)
6190 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6191 struct cleanup
*cleanups
;
6192 struct abbrev_table
*abbrev_table
;
6193 sect_offset abbrev_offset
;
6194 struct tu_abbrev_offset
*sorted_by_abbrev
;
6197 /* It's up to the caller to not call us multiple times. */
6198 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
6200 if (dwarf2_per_objfile
->n_type_units
== 0)
6203 /* TUs typically share abbrev tables, and there can be way more TUs than
6204 abbrev tables. Sort by abbrev table to reduce the number of times we
6205 read each abbrev table in.
6206 Alternatives are to punt or to maintain a cache of abbrev tables.
6207 This is simpler and efficient enough for now.
6209 Later we group TUs by their DW_AT_stmt_list value (as this defines the
6210 symtab to use). Typically TUs with the same abbrev offset have the same
6211 stmt_list value too so in practice this should work well.
6213 The basic algorithm here is:
6215 sort TUs by abbrev table
6216 for each TU with same abbrev table:
6217 read abbrev table if first user
6218 read TU top level DIE
6219 [IWBN if DWO skeletons had DW_AT_stmt_list]
6222 if (dwarf_read_debug
)
6223 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
6225 /* Sort in a separate table to maintain the order of all_type_units
6226 for .gdb_index: TU indices directly index all_type_units. */
6227 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
6228 dwarf2_per_objfile
->n_type_units
);
6229 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6231 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
6233 sorted_by_abbrev
[i
].sig_type
= sig_type
;
6234 sorted_by_abbrev
[i
].abbrev_offset
=
6235 read_abbrev_offset (sig_type
->per_cu
.section
,
6236 sig_type
->per_cu
.offset
);
6238 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
6239 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
6240 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
6242 abbrev_offset
.sect_off
= ~(unsigned) 0;
6243 abbrev_table
= NULL
;
6244 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
6246 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6248 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
6250 /* Switch to the next abbrev table if necessary. */
6251 if (abbrev_table
== NULL
6252 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
6254 if (abbrev_table
!= NULL
)
6256 abbrev_table_free (abbrev_table
);
6257 /* Reset to NULL in case abbrev_table_read_table throws
6258 an error: abbrev_table_free_cleanup will get called. */
6259 abbrev_table
= NULL
;
6261 abbrev_offset
= tu
->abbrev_offset
;
6263 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
6265 ++tu_stats
->nr_uniq_abbrev_tables
;
6268 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
6269 build_type_psymtabs_reader
, NULL
);
6272 do_cleanups (cleanups
);
6275 /* Print collected type unit statistics. */
6278 print_tu_stats (void)
6280 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6282 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
6283 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
6284 dwarf2_per_objfile
->n_type_units
);
6285 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
6286 tu_stats
->nr_uniq_abbrev_tables
);
6287 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
6288 tu_stats
->nr_symtabs
);
6289 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
6290 tu_stats
->nr_symtab_sharers
);
6291 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
6292 tu_stats
->nr_stmt_less_type_units
);
6293 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
6294 tu_stats
->nr_all_type_units_reallocs
);
6297 /* Traversal function for build_type_psymtabs. */
6300 build_type_psymtab_dependencies (void **slot
, void *info
)
6302 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6303 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
6304 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
6305 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6306 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
6307 struct signatured_type
*iter
;
6310 gdb_assert (len
> 0);
6311 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
6313 pst
->number_of_dependencies
= len
;
6315 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6317 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
6320 gdb_assert (iter
->per_cu
.is_debug_types
);
6321 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
6322 iter
->type_unit_group
= tu_group
;
6325 VEC_free (sig_type_ptr
, tu_group
->tus
);
6330 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6331 Build partial symbol tables for the .debug_types comp-units. */
6334 build_type_psymtabs (struct objfile
*objfile
)
6336 if (! create_all_type_units (objfile
))
6339 build_type_psymtabs_1 ();
6342 /* Traversal function for process_skeletonless_type_unit.
6343 Read a TU in a DWO file and build partial symbols for it. */
6346 process_skeletonless_type_unit (void **slot
, void *info
)
6348 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
6349 struct objfile
*objfile
= (struct objfile
*) info
;
6350 struct signatured_type find_entry
, *entry
;
6352 /* If this TU doesn't exist in the global table, add it and read it in. */
6354 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6356 dwarf2_per_objfile
->signatured_types
6357 = allocate_signatured_type_table (objfile
);
6360 find_entry
.signature
= dwo_unit
->signature
;
6361 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
6363 /* If we've already seen this type there's nothing to do. What's happening
6364 is we're doing our own version of comdat-folding here. */
6368 /* This does the job that create_all_type_units would have done for
6370 entry
= add_type_unit (dwo_unit
->signature
, slot
);
6371 fill_in_sig_entry_from_dwo_entry (objfile
, entry
, dwo_unit
);
6374 /* This does the job that build_type_psymtabs_1 would have done. */
6375 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
6376 build_type_psymtabs_reader
, NULL
);
6381 /* Traversal function for process_skeletonless_type_units. */
6384 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
6386 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
6388 if (dwo_file
->tus
!= NULL
)
6390 htab_traverse_noresize (dwo_file
->tus
,
6391 process_skeletonless_type_unit
, info
);
6397 /* Scan all TUs of DWO files, verifying we've processed them.
6398 This is needed in case a TU was emitted without its skeleton.
6399 Note: This can't be done until we know what all the DWO files are. */
6402 process_skeletonless_type_units (struct objfile
*objfile
)
6404 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
6405 if (get_dwp_file () == NULL
6406 && dwarf2_per_objfile
->dwo_files
!= NULL
)
6408 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
6409 process_dwo_file_for_skeletonless_type_units
,
6414 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
6417 psymtabs_addrmap_cleanup (void *o
)
6419 struct objfile
*objfile
= (struct objfile
*) o
;
6421 objfile
->psymtabs_addrmap
= NULL
;
6424 /* Compute the 'user' field for each psymtab in OBJFILE. */
6427 set_partial_user (struct objfile
*objfile
)
6431 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6433 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6434 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6440 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
6442 /* Set the 'user' field only if it is not already set. */
6443 if (pst
->dependencies
[j
]->user
== NULL
)
6444 pst
->dependencies
[j
]->user
= pst
;
6449 /* Build the partial symbol table by doing a quick pass through the
6450 .debug_info and .debug_abbrev sections. */
6453 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
6455 struct cleanup
*back_to
, *addrmap_cleanup
;
6456 struct obstack temp_obstack
;
6459 if (dwarf_read_debug
)
6461 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
6462 objfile_name (objfile
));
6465 dwarf2_per_objfile
->reading_partial_symbols
= 1;
6467 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
6469 /* Any cached compilation units will be linked by the per-objfile
6470 read_in_chain. Make sure to free them when we're done. */
6471 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
6473 build_type_psymtabs (objfile
);
6475 create_all_comp_units (objfile
);
6477 /* Create a temporary address map on a temporary obstack. We later
6478 copy this to the final obstack. */
6479 obstack_init (&temp_obstack
);
6480 make_cleanup_obstack_free (&temp_obstack
);
6481 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
6482 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
6484 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6486 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6488 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
6491 /* This has to wait until we read the CUs, we need the list of DWOs. */
6492 process_skeletonless_type_units (objfile
);
6494 /* Now that all TUs have been processed we can fill in the dependencies. */
6495 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
6497 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
6498 build_type_psymtab_dependencies
, NULL
);
6501 if (dwarf_read_debug
)
6504 set_partial_user (objfile
);
6506 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
6507 &objfile
->objfile_obstack
);
6508 discard_cleanups (addrmap_cleanup
);
6510 do_cleanups (back_to
);
6512 if (dwarf_read_debug
)
6513 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
6514 objfile_name (objfile
));
6517 /* die_reader_func for load_partial_comp_unit. */
6520 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
6521 const gdb_byte
*info_ptr
,
6522 struct die_info
*comp_unit_die
,
6526 struct dwarf2_cu
*cu
= reader
->cu
;
6528 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
6530 /* Check if comp unit has_children.
6531 If so, read the rest of the partial symbols from this comp unit.
6532 If not, there's no more debug_info for this comp unit. */
6534 load_partial_dies (reader
, info_ptr
, 0);
6537 /* Load the partial DIEs for a secondary CU into memory.
6538 This is also used when rereading a primary CU with load_all_dies. */
6541 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
6543 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6544 load_partial_comp_unit_reader
, NULL
);
6548 read_comp_units_from_section (struct objfile
*objfile
,
6549 struct dwarf2_section_info
*section
,
6550 unsigned int is_dwz
,
6553 struct dwarf2_per_cu_data
***all_comp_units
)
6555 const gdb_byte
*info_ptr
;
6556 bfd
*abfd
= get_section_bfd_owner (section
);
6558 if (dwarf_read_debug
)
6559 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
6560 get_section_name (section
),
6561 get_section_file_name (section
));
6563 dwarf2_read_section (objfile
, section
);
6565 info_ptr
= section
->buffer
;
6567 while (info_ptr
< section
->buffer
+ section
->size
)
6569 unsigned int length
, initial_length_size
;
6570 struct dwarf2_per_cu_data
*this_cu
;
6573 offset
.sect_off
= info_ptr
- section
->buffer
;
6575 /* Read just enough information to find out where the next
6576 compilation unit is. */
6577 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6579 /* Save the compilation unit for later lookup. */
6580 this_cu
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
);
6581 memset (this_cu
, 0, sizeof (*this_cu
));
6582 this_cu
->offset
= offset
;
6583 this_cu
->length
= length
+ initial_length_size
;
6584 this_cu
->is_dwz
= is_dwz
;
6585 this_cu
->objfile
= objfile
;
6586 this_cu
->section
= section
;
6588 if (*n_comp_units
== *n_allocated
)
6591 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
6592 *all_comp_units
, *n_allocated
);
6594 (*all_comp_units
)[*n_comp_units
] = this_cu
;
6597 info_ptr
= info_ptr
+ this_cu
->length
;
6601 /* Create a list of all compilation units in OBJFILE.
6602 This is only done for -readnow and building partial symtabs. */
6605 create_all_comp_units (struct objfile
*objfile
)
6609 struct dwarf2_per_cu_data
**all_comp_units
;
6610 struct dwz_file
*dwz
;
6614 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
6616 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
6617 &n_allocated
, &n_comp_units
, &all_comp_units
);
6619 dwz
= dwarf2_get_dwz_file ();
6621 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
6622 &n_allocated
, &n_comp_units
,
6625 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
6626 struct dwarf2_per_cu_data
*,
6628 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
6629 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
6630 xfree (all_comp_units
);
6631 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
6634 /* Process all loaded DIEs for compilation unit CU, starting at
6635 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
6636 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
6637 DW_AT_ranges). See the comments of add_partial_subprogram on how
6638 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
6641 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
6642 CORE_ADDR
*highpc
, int set_addrmap
,
6643 struct dwarf2_cu
*cu
)
6645 struct partial_die_info
*pdi
;
6647 /* Now, march along the PDI's, descending into ones which have
6648 interesting children but skipping the children of the other ones,
6649 until we reach the end of the compilation unit. */
6655 fixup_partial_die (pdi
, cu
);
6657 /* Anonymous namespaces or modules have no name but have interesting
6658 children, so we need to look at them. Ditto for anonymous
6661 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
6662 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
6663 || pdi
->tag
== DW_TAG_imported_unit
)
6667 case DW_TAG_subprogram
:
6668 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6670 case DW_TAG_constant
:
6671 case DW_TAG_variable
:
6672 case DW_TAG_typedef
:
6673 case DW_TAG_union_type
:
6674 if (!pdi
->is_declaration
)
6676 add_partial_symbol (pdi
, cu
);
6679 case DW_TAG_class_type
:
6680 case DW_TAG_interface_type
:
6681 case DW_TAG_structure_type
:
6682 if (!pdi
->is_declaration
)
6684 add_partial_symbol (pdi
, cu
);
6686 if (cu
->language
== language_rust
&& pdi
->has_children
)
6687 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
6690 case DW_TAG_enumeration_type
:
6691 if (!pdi
->is_declaration
)
6692 add_partial_enumeration (pdi
, cu
);
6694 case DW_TAG_base_type
:
6695 case DW_TAG_subrange_type
:
6696 /* File scope base type definitions are added to the partial
6698 add_partial_symbol (pdi
, cu
);
6700 case DW_TAG_namespace
:
6701 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6704 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6706 case DW_TAG_imported_unit
:
6708 struct dwarf2_per_cu_data
*per_cu
;
6710 /* For now we don't handle imported units in type units. */
6711 if (cu
->per_cu
->is_debug_types
)
6713 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6714 " supported in type units [in module %s]"),
6715 objfile_name (cu
->objfile
));
6718 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
6722 /* Go read the partial unit, if needed. */
6723 if (per_cu
->v
.psymtab
== NULL
)
6724 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
6726 VEC_safe_push (dwarf2_per_cu_ptr
,
6727 cu
->per_cu
->imported_symtabs
, per_cu
);
6730 case DW_TAG_imported_declaration
:
6731 add_partial_symbol (pdi
, cu
);
6738 /* If the die has a sibling, skip to the sibling. */
6740 pdi
= pdi
->die_sibling
;
6744 /* Functions used to compute the fully scoped name of a partial DIE.
6746 Normally, this is simple. For C++, the parent DIE's fully scoped
6747 name is concatenated with "::" and the partial DIE's name.
6748 Enumerators are an exception; they use the scope of their parent
6749 enumeration type, i.e. the name of the enumeration type is not
6750 prepended to the enumerator.
6752 There are two complexities. One is DW_AT_specification; in this
6753 case "parent" means the parent of the target of the specification,
6754 instead of the direct parent of the DIE. The other is compilers
6755 which do not emit DW_TAG_namespace; in this case we try to guess
6756 the fully qualified name of structure types from their members'
6757 linkage names. This must be done using the DIE's children rather
6758 than the children of any DW_AT_specification target. We only need
6759 to do this for structures at the top level, i.e. if the target of
6760 any DW_AT_specification (if any; otherwise the DIE itself) does not
6763 /* Compute the scope prefix associated with PDI's parent, in
6764 compilation unit CU. The result will be allocated on CU's
6765 comp_unit_obstack, or a copy of the already allocated PDI->NAME
6766 field. NULL is returned if no prefix is necessary. */
6768 partial_die_parent_scope (struct partial_die_info
*pdi
,
6769 struct dwarf2_cu
*cu
)
6771 const char *grandparent_scope
;
6772 struct partial_die_info
*parent
, *real_pdi
;
6774 /* We need to look at our parent DIE; if we have a DW_AT_specification,
6775 then this means the parent of the specification DIE. */
6778 while (real_pdi
->has_specification
)
6779 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
6780 real_pdi
->spec_is_dwz
, cu
);
6782 parent
= real_pdi
->die_parent
;
6786 if (parent
->scope_set
)
6787 return parent
->scope
;
6789 fixup_partial_die (parent
, cu
);
6791 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
6793 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
6794 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
6795 Work around this problem here. */
6796 if (cu
->language
== language_cplus
6797 && parent
->tag
== DW_TAG_namespace
6798 && strcmp (parent
->name
, "::") == 0
6799 && grandparent_scope
== NULL
)
6801 parent
->scope
= NULL
;
6802 parent
->scope_set
= 1;
6806 if (pdi
->tag
== DW_TAG_enumerator
)
6807 /* Enumerators should not get the name of the enumeration as a prefix. */
6808 parent
->scope
= grandparent_scope
;
6809 else if (parent
->tag
== DW_TAG_namespace
6810 || parent
->tag
== DW_TAG_module
6811 || parent
->tag
== DW_TAG_structure_type
6812 || parent
->tag
== DW_TAG_class_type
6813 || parent
->tag
== DW_TAG_interface_type
6814 || parent
->tag
== DW_TAG_union_type
6815 || parent
->tag
== DW_TAG_enumeration_type
)
6817 if (grandparent_scope
== NULL
)
6818 parent
->scope
= parent
->name
;
6820 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
6822 parent
->name
, 0, cu
);
6826 /* FIXME drow/2004-04-01: What should we be doing with
6827 function-local names? For partial symbols, we should probably be
6829 complaint (&symfile_complaints
,
6830 _("unhandled containing DIE tag %d for DIE at %d"),
6831 parent
->tag
, pdi
->offset
.sect_off
);
6832 parent
->scope
= grandparent_scope
;
6835 parent
->scope_set
= 1;
6836 return parent
->scope
;
6839 /* Return the fully scoped name associated with PDI, from compilation unit
6840 CU. The result will be allocated with malloc. */
6843 partial_die_full_name (struct partial_die_info
*pdi
,
6844 struct dwarf2_cu
*cu
)
6846 const char *parent_scope
;
6848 /* If this is a template instantiation, we can not work out the
6849 template arguments from partial DIEs. So, unfortunately, we have
6850 to go through the full DIEs. At least any work we do building
6851 types here will be reused if full symbols are loaded later. */
6852 if (pdi
->has_template_arguments
)
6854 fixup_partial_die (pdi
, cu
);
6856 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
6858 struct die_info
*die
;
6859 struct attribute attr
;
6860 struct dwarf2_cu
*ref_cu
= cu
;
6862 /* DW_FORM_ref_addr is using section offset. */
6863 attr
.name
= (enum dwarf_attribute
) 0;
6864 attr
.form
= DW_FORM_ref_addr
;
6865 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
6866 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
6868 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
6872 parent_scope
= partial_die_parent_scope (pdi
, cu
);
6873 if (parent_scope
== NULL
)
6876 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
6880 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
6882 struct objfile
*objfile
= cu
->objfile
;
6883 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6885 const char *actual_name
= NULL
;
6887 char *built_actual_name
;
6889 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6891 built_actual_name
= partial_die_full_name (pdi
, cu
);
6892 if (built_actual_name
!= NULL
)
6893 actual_name
= built_actual_name
;
6895 if (actual_name
== NULL
)
6896 actual_name
= pdi
->name
;
6900 case DW_TAG_subprogram
:
6901 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
6902 if (pdi
->is_external
|| cu
->language
== language_ada
)
6904 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
6905 of the global scope. But in Ada, we want to be able to access
6906 nested procedures globally. So all Ada subprograms are stored
6907 in the global scope. */
6908 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6909 built_actual_name
!= NULL
,
6910 VAR_DOMAIN
, LOC_BLOCK
,
6911 &objfile
->global_psymbols
,
6912 addr
, cu
->language
, objfile
);
6916 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6917 built_actual_name
!= NULL
,
6918 VAR_DOMAIN
, LOC_BLOCK
,
6919 &objfile
->static_psymbols
,
6920 addr
, cu
->language
, objfile
);
6923 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
6924 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
6926 case DW_TAG_constant
:
6928 struct psymbol_allocation_list
*list
;
6930 if (pdi
->is_external
)
6931 list
= &objfile
->global_psymbols
;
6933 list
= &objfile
->static_psymbols
;
6934 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6935 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
6936 list
, 0, cu
->language
, objfile
);
6939 case DW_TAG_variable
:
6941 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
6945 && !dwarf2_per_objfile
->has_section_at_zero
)
6947 /* A global or static variable may also have been stripped
6948 out by the linker if unused, in which case its address
6949 will be nullified; do not add such variables into partial
6950 symbol table then. */
6952 else if (pdi
->is_external
)
6955 Don't enter into the minimal symbol tables as there is
6956 a minimal symbol table entry from the ELF symbols already.
6957 Enter into partial symbol table if it has a location
6958 descriptor or a type.
6959 If the location descriptor is missing, new_symbol will create
6960 a LOC_UNRESOLVED symbol, the address of the variable will then
6961 be determined from the minimal symbol table whenever the variable
6963 The address for the partial symbol table entry is not
6964 used by GDB, but it comes in handy for debugging partial symbol
6967 if (pdi
->d
.locdesc
|| pdi
->has_type
)
6968 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6969 built_actual_name
!= NULL
,
6970 VAR_DOMAIN
, LOC_STATIC
,
6971 &objfile
->global_psymbols
,
6973 cu
->language
, objfile
);
6977 int has_loc
= pdi
->d
.locdesc
!= NULL
;
6979 /* Static Variable. Skip symbols whose value we cannot know (those
6980 without location descriptors or constant values). */
6981 if (!has_loc
&& !pdi
->has_const_value
)
6983 xfree (built_actual_name
);
6987 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6988 built_actual_name
!= NULL
,
6989 VAR_DOMAIN
, LOC_STATIC
,
6990 &objfile
->static_psymbols
,
6991 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
6992 cu
->language
, objfile
);
6995 case DW_TAG_typedef
:
6996 case DW_TAG_base_type
:
6997 case DW_TAG_subrange_type
:
6998 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6999 built_actual_name
!= NULL
,
7000 VAR_DOMAIN
, LOC_TYPEDEF
,
7001 &objfile
->static_psymbols
,
7002 0, cu
->language
, objfile
);
7004 case DW_TAG_imported_declaration
:
7005 case DW_TAG_namespace
:
7006 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7007 built_actual_name
!= NULL
,
7008 VAR_DOMAIN
, LOC_TYPEDEF
,
7009 &objfile
->global_psymbols
,
7010 0, cu
->language
, objfile
);
7013 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7014 built_actual_name
!= NULL
,
7015 MODULE_DOMAIN
, LOC_TYPEDEF
,
7016 &objfile
->global_psymbols
,
7017 0, cu
->language
, objfile
);
7019 case DW_TAG_class_type
:
7020 case DW_TAG_interface_type
:
7021 case DW_TAG_structure_type
:
7022 case DW_TAG_union_type
:
7023 case DW_TAG_enumeration_type
:
7024 /* Skip external references. The DWARF standard says in the section
7025 about "Structure, Union, and Class Type Entries": "An incomplete
7026 structure, union or class type is represented by a structure,
7027 union or class entry that does not have a byte size attribute
7028 and that has a DW_AT_declaration attribute." */
7029 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
7031 xfree (built_actual_name
);
7035 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
7036 static vs. global. */
7037 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7038 built_actual_name
!= NULL
,
7039 STRUCT_DOMAIN
, LOC_TYPEDEF
,
7040 cu
->language
== language_cplus
7041 ? &objfile
->global_psymbols
7042 : &objfile
->static_psymbols
,
7043 0, cu
->language
, objfile
);
7046 case DW_TAG_enumerator
:
7047 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7048 built_actual_name
!= NULL
,
7049 VAR_DOMAIN
, LOC_CONST
,
7050 cu
->language
== language_cplus
7051 ? &objfile
->global_psymbols
7052 : &objfile
->static_psymbols
,
7053 0, cu
->language
, objfile
);
7059 xfree (built_actual_name
);
7062 /* Read a partial die corresponding to a namespace; also, add a symbol
7063 corresponding to that namespace to the symbol table. NAMESPACE is
7064 the name of the enclosing namespace. */
7067 add_partial_namespace (struct partial_die_info
*pdi
,
7068 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7069 int set_addrmap
, struct dwarf2_cu
*cu
)
7071 /* Add a symbol for the namespace. */
7073 add_partial_symbol (pdi
, cu
);
7075 /* Now scan partial symbols in that namespace. */
7077 if (pdi
->has_children
)
7078 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7081 /* Read a partial die corresponding to a Fortran module. */
7084 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
7085 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
7087 /* Add a symbol for the namespace. */
7089 add_partial_symbol (pdi
, cu
);
7091 /* Now scan partial symbols in that module. */
7093 if (pdi
->has_children
)
7094 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7097 /* Read a partial die corresponding to a subprogram and create a partial
7098 symbol for that subprogram. When the CU language allows it, this
7099 routine also defines a partial symbol for each nested subprogram
7100 that this subprogram contains. If SET_ADDRMAP is true, record the
7101 covered ranges in the addrmap. Set *LOWPC and *HIGHPC to the lowest
7102 and highest PC values found in PDI.
7104 PDI may also be a lexical block, in which case we simply search
7105 recursively for subprograms defined inside that lexical block.
7106 Again, this is only performed when the CU language allows this
7107 type of definitions. */
7110 add_partial_subprogram (struct partial_die_info
*pdi
,
7111 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7112 int set_addrmap
, struct dwarf2_cu
*cu
)
7114 if (pdi
->tag
== DW_TAG_subprogram
)
7116 if (pdi
->has_pc_info
)
7118 if (pdi
->lowpc
< *lowpc
)
7119 *lowpc
= pdi
->lowpc
;
7120 if (pdi
->highpc
> *highpc
)
7121 *highpc
= pdi
->highpc
;
7124 struct objfile
*objfile
= cu
->objfile
;
7125 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7130 baseaddr
= ANOFFSET (objfile
->section_offsets
,
7131 SECT_OFF_TEXT (objfile
));
7132 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7133 pdi
->lowpc
+ baseaddr
);
7134 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7135 pdi
->highpc
+ baseaddr
);
7136 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
7137 cu
->per_cu
->v
.psymtab
);
7141 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
7143 if (!pdi
->is_declaration
)
7144 /* Ignore subprogram DIEs that do not have a name, they are
7145 illegal. Do not emit a complaint at this point, we will
7146 do so when we convert this psymtab into a symtab. */
7148 add_partial_symbol (pdi
, cu
);
7152 if (! pdi
->has_children
)
7155 if (cu
->language
== language_ada
)
7157 pdi
= pdi
->die_child
;
7160 fixup_partial_die (pdi
, cu
);
7161 if (pdi
->tag
== DW_TAG_subprogram
7162 || pdi
->tag
== DW_TAG_lexical_block
)
7163 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7164 pdi
= pdi
->die_sibling
;
7169 /* Read a partial die corresponding to an enumeration type. */
7172 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
7173 struct dwarf2_cu
*cu
)
7175 struct partial_die_info
*pdi
;
7177 if (enum_pdi
->name
!= NULL
)
7178 add_partial_symbol (enum_pdi
, cu
);
7180 pdi
= enum_pdi
->die_child
;
7183 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
7184 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
7186 add_partial_symbol (pdi
, cu
);
7187 pdi
= pdi
->die_sibling
;
7191 /* Return the initial uleb128 in the die at INFO_PTR. */
7194 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
7196 unsigned int bytes_read
;
7198 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7201 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
7202 Return the corresponding abbrev, or NULL if the number is zero (indicating
7203 an empty DIE). In either case *BYTES_READ will be set to the length of
7204 the initial number. */
7206 static struct abbrev_info
*
7207 peek_die_abbrev (const gdb_byte
*info_ptr
, unsigned int *bytes_read
,
7208 struct dwarf2_cu
*cu
)
7210 bfd
*abfd
= cu
->objfile
->obfd
;
7211 unsigned int abbrev_number
;
7212 struct abbrev_info
*abbrev
;
7214 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
7216 if (abbrev_number
== 0)
7219 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
7222 error (_("Dwarf Error: Could not find abbrev number %d in %s"
7223 " at offset 0x%x [in module %s]"),
7224 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
7225 cu
->header
.offset
.sect_off
, bfd_get_filename (abfd
));
7231 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7232 Returns a pointer to the end of a series of DIEs, terminated by an empty
7233 DIE. Any children of the skipped DIEs will also be skipped. */
7235 static const gdb_byte
*
7236 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
7238 struct dwarf2_cu
*cu
= reader
->cu
;
7239 struct abbrev_info
*abbrev
;
7240 unsigned int bytes_read
;
7244 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
7246 return info_ptr
+ bytes_read
;
7248 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
7252 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7253 INFO_PTR should point just after the initial uleb128 of a DIE, and the
7254 abbrev corresponding to that skipped uleb128 should be passed in
7255 ABBREV. Returns a pointer to this DIE's sibling, skipping any
7258 static const gdb_byte
*
7259 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
7260 struct abbrev_info
*abbrev
)
7262 unsigned int bytes_read
;
7263 struct attribute attr
;
7264 bfd
*abfd
= reader
->abfd
;
7265 struct dwarf2_cu
*cu
= reader
->cu
;
7266 const gdb_byte
*buffer
= reader
->buffer
;
7267 const gdb_byte
*buffer_end
= reader
->buffer_end
;
7268 unsigned int form
, i
;
7270 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
7272 /* The only abbrev we care about is DW_AT_sibling. */
7273 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
7275 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
7276 if (attr
.form
== DW_FORM_ref_addr
)
7277 complaint (&symfile_complaints
,
7278 _("ignoring absolute DW_AT_sibling"));
7281 unsigned int off
= dwarf2_get_ref_die_offset (&attr
).sect_off
;
7282 const gdb_byte
*sibling_ptr
= buffer
+ off
;
7284 if (sibling_ptr
< info_ptr
)
7285 complaint (&symfile_complaints
,
7286 _("DW_AT_sibling points backwards"));
7287 else if (sibling_ptr
> reader
->buffer_end
)
7288 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
7294 /* If it isn't DW_AT_sibling, skip this attribute. */
7295 form
= abbrev
->attrs
[i
].form
;
7299 case DW_FORM_ref_addr
:
7300 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
7301 and later it is offset sized. */
7302 if (cu
->header
.version
== 2)
7303 info_ptr
+= cu
->header
.addr_size
;
7305 info_ptr
+= cu
->header
.offset_size
;
7307 case DW_FORM_GNU_ref_alt
:
7308 info_ptr
+= cu
->header
.offset_size
;
7311 info_ptr
+= cu
->header
.addr_size
;
7318 case DW_FORM_flag_present
:
7330 case DW_FORM_ref_sig8
:
7333 case DW_FORM_string
:
7334 read_direct_string (abfd
, info_ptr
, &bytes_read
);
7335 info_ptr
+= bytes_read
;
7337 case DW_FORM_sec_offset
:
7339 case DW_FORM_GNU_strp_alt
:
7340 info_ptr
+= cu
->header
.offset_size
;
7342 case DW_FORM_exprloc
:
7344 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7345 info_ptr
+= bytes_read
;
7347 case DW_FORM_block1
:
7348 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
7350 case DW_FORM_block2
:
7351 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
7353 case DW_FORM_block4
:
7354 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
7358 case DW_FORM_ref_udata
:
7359 case DW_FORM_GNU_addr_index
:
7360 case DW_FORM_GNU_str_index
:
7361 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
7363 case DW_FORM_indirect
:
7364 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7365 info_ptr
+= bytes_read
;
7366 /* We need to continue parsing from here, so just go back to
7368 goto skip_attribute
;
7371 error (_("Dwarf Error: Cannot handle %s "
7372 "in DWARF reader [in module %s]"),
7373 dwarf_form_name (form
),
7374 bfd_get_filename (abfd
));
7378 if (abbrev
->has_children
)
7379 return skip_children (reader
, info_ptr
);
7384 /* Locate ORIG_PDI's sibling.
7385 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
7387 static const gdb_byte
*
7388 locate_pdi_sibling (const struct die_reader_specs
*reader
,
7389 struct partial_die_info
*orig_pdi
,
7390 const gdb_byte
*info_ptr
)
7392 /* Do we know the sibling already? */
7394 if (orig_pdi
->sibling
)
7395 return orig_pdi
->sibling
;
7397 /* Are there any children to deal with? */
7399 if (!orig_pdi
->has_children
)
7402 /* Skip the children the long way. */
7404 return skip_children (reader
, info_ptr
);
7407 /* Expand this partial symbol table into a full symbol table. SELF is
7411 dwarf2_read_symtab (struct partial_symtab
*self
,
7412 struct objfile
*objfile
)
7416 warning (_("bug: psymtab for %s is already read in."),
7423 printf_filtered (_("Reading in symbols for %s..."),
7425 gdb_flush (gdb_stdout
);
7428 /* Restore our global data. */
7430 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
7431 dwarf2_objfile_data_key
);
7433 /* If this psymtab is constructed from a debug-only objfile, the
7434 has_section_at_zero flag will not necessarily be correct. We
7435 can get the correct value for this flag by looking at the data
7436 associated with the (presumably stripped) associated objfile. */
7437 if (objfile
->separate_debug_objfile_backlink
)
7439 struct dwarf2_per_objfile
*dpo_backlink
7440 = ((struct dwarf2_per_objfile
*)
7441 objfile_data (objfile
->separate_debug_objfile_backlink
,
7442 dwarf2_objfile_data_key
));
7444 dwarf2_per_objfile
->has_section_at_zero
7445 = dpo_backlink
->has_section_at_zero
;
7448 dwarf2_per_objfile
->reading_partial_symbols
= 0;
7450 psymtab_to_symtab_1 (self
);
7452 /* Finish up the debug error message. */
7454 printf_filtered (_("done.\n"));
7457 process_cu_includes ();
7460 /* Reading in full CUs. */
7462 /* Add PER_CU to the queue. */
7465 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
7466 enum language pretend_language
)
7468 struct dwarf2_queue_item
*item
;
7471 item
= XNEW (struct dwarf2_queue_item
);
7472 item
->per_cu
= per_cu
;
7473 item
->pretend_language
= pretend_language
;
7476 if (dwarf2_queue
== NULL
)
7477 dwarf2_queue
= item
;
7479 dwarf2_queue_tail
->next
= item
;
7481 dwarf2_queue_tail
= item
;
7484 /* If PER_CU is not yet queued, add it to the queue.
7485 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
7487 The result is non-zero if PER_CU was queued, otherwise the result is zero
7488 meaning either PER_CU is already queued or it is already loaded.
7490 N.B. There is an invariant here that if a CU is queued then it is loaded.
7491 The caller is required to load PER_CU if we return non-zero. */
7494 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
7495 struct dwarf2_per_cu_data
*per_cu
,
7496 enum language pretend_language
)
7498 /* We may arrive here during partial symbol reading, if we need full
7499 DIEs to process an unusual case (e.g. template arguments). Do
7500 not queue PER_CU, just tell our caller to load its DIEs. */
7501 if (dwarf2_per_objfile
->reading_partial_symbols
)
7503 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
7508 /* Mark the dependence relation so that we don't flush PER_CU
7510 if (dependent_cu
!= NULL
)
7511 dwarf2_add_dependence (dependent_cu
, per_cu
);
7513 /* If it's already on the queue, we have nothing to do. */
7517 /* If the compilation unit is already loaded, just mark it as
7519 if (per_cu
->cu
!= NULL
)
7521 per_cu
->cu
->last_used
= 0;
7525 /* Add it to the queue. */
7526 queue_comp_unit (per_cu
, pretend_language
);
7531 /* Process the queue. */
7534 process_queue (void)
7536 struct dwarf2_queue_item
*item
, *next_item
;
7538 if (dwarf_read_debug
)
7540 fprintf_unfiltered (gdb_stdlog
,
7541 "Expanding one or more symtabs of objfile %s ...\n",
7542 objfile_name (dwarf2_per_objfile
->objfile
));
7545 /* The queue starts out with one item, but following a DIE reference
7546 may load a new CU, adding it to the end of the queue. */
7547 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
7549 if ((dwarf2_per_objfile
->using_index
7550 ? !item
->per_cu
->v
.quick
->compunit_symtab
7551 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
7552 /* Skip dummy CUs. */
7553 && item
->per_cu
->cu
!= NULL
)
7555 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
7556 unsigned int debug_print_threshold
;
7559 if (per_cu
->is_debug_types
)
7561 struct signatured_type
*sig_type
=
7562 (struct signatured_type
*) per_cu
;
7564 sprintf (buf
, "TU %s at offset 0x%x",
7565 hex_string (sig_type
->signature
),
7566 per_cu
->offset
.sect_off
);
7567 /* There can be 100s of TUs.
7568 Only print them in verbose mode. */
7569 debug_print_threshold
= 2;
7573 sprintf (buf
, "CU at offset 0x%x", per_cu
->offset
.sect_off
);
7574 debug_print_threshold
= 1;
7577 if (dwarf_read_debug
>= debug_print_threshold
)
7578 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
7580 if (per_cu
->is_debug_types
)
7581 process_full_type_unit (per_cu
, item
->pretend_language
);
7583 process_full_comp_unit (per_cu
, item
->pretend_language
);
7585 if (dwarf_read_debug
>= debug_print_threshold
)
7586 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
7589 item
->per_cu
->queued
= 0;
7590 next_item
= item
->next
;
7594 dwarf2_queue_tail
= NULL
;
7596 if (dwarf_read_debug
)
7598 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
7599 objfile_name (dwarf2_per_objfile
->objfile
));
7603 /* Free all allocated queue entries. This function only releases anything if
7604 an error was thrown; if the queue was processed then it would have been
7605 freed as we went along. */
7608 dwarf2_release_queue (void *dummy
)
7610 struct dwarf2_queue_item
*item
, *last
;
7612 item
= dwarf2_queue
;
7615 /* Anything still marked queued is likely to be in an
7616 inconsistent state, so discard it. */
7617 if (item
->per_cu
->queued
)
7619 if (item
->per_cu
->cu
!= NULL
)
7620 free_one_cached_comp_unit (item
->per_cu
);
7621 item
->per_cu
->queued
= 0;
7629 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
7632 /* Read in full symbols for PST, and anything it depends on. */
7635 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
7637 struct dwarf2_per_cu_data
*per_cu
;
7643 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
7644 if (!pst
->dependencies
[i
]->readin
7645 && pst
->dependencies
[i
]->user
== NULL
)
7647 /* Inform about additional files that need to be read in. */
7650 /* FIXME: i18n: Need to make this a single string. */
7651 fputs_filtered (" ", gdb_stdout
);
7653 fputs_filtered ("and ", gdb_stdout
);
7655 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
7656 wrap_here (""); /* Flush output. */
7657 gdb_flush (gdb_stdout
);
7659 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
7662 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
7666 /* It's an include file, no symbols to read for it.
7667 Everything is in the parent symtab. */
7672 dw2_do_instantiate_symtab (per_cu
);
7675 /* Trivial hash function for die_info: the hash value of a DIE
7676 is its offset in .debug_info for this objfile. */
7679 die_hash (const void *item
)
7681 const struct die_info
*die
= (const struct die_info
*) item
;
7683 return die
->offset
.sect_off
;
7686 /* Trivial comparison function for die_info structures: two DIEs
7687 are equal if they have the same offset. */
7690 die_eq (const void *item_lhs
, const void *item_rhs
)
7692 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
7693 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
7695 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
7698 /* die_reader_func for load_full_comp_unit.
7699 This is identical to read_signatured_type_reader,
7700 but is kept separate for now. */
7703 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
7704 const gdb_byte
*info_ptr
,
7705 struct die_info
*comp_unit_die
,
7709 struct dwarf2_cu
*cu
= reader
->cu
;
7710 enum language
*language_ptr
= (enum language
*) data
;
7712 gdb_assert (cu
->die_hash
== NULL
);
7714 htab_create_alloc_ex (cu
->header
.length
/ 12,
7718 &cu
->comp_unit_obstack
,
7719 hashtab_obstack_allocate
,
7720 dummy_obstack_deallocate
);
7723 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
7724 &info_ptr
, comp_unit_die
);
7725 cu
->dies
= comp_unit_die
;
7726 /* comp_unit_die is not stored in die_hash, no need. */
7728 /* We try not to read any attributes in this function, because not
7729 all CUs needed for references have been loaded yet, and symbol
7730 table processing isn't initialized. But we have to set the CU language,
7731 or we won't be able to build types correctly.
7732 Similarly, if we do not read the producer, we can not apply
7733 producer-specific interpretation. */
7734 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
7737 /* Load the DIEs associated with PER_CU into memory. */
7740 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7741 enum language pretend_language
)
7743 gdb_assert (! this_cu
->is_debug_types
);
7745 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
7746 load_full_comp_unit_reader
, &pretend_language
);
7749 /* Add a DIE to the delayed physname list. */
7752 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
7753 const char *name
, struct die_info
*die
,
7754 struct dwarf2_cu
*cu
)
7756 struct delayed_method_info mi
;
7758 mi
.fnfield_index
= fnfield_index
;
7762 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
7765 /* A cleanup for freeing the delayed method list. */
7768 free_delayed_list (void *ptr
)
7770 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
7771 if (cu
->method_list
!= NULL
)
7773 VEC_free (delayed_method_info
, cu
->method_list
);
7774 cu
->method_list
= NULL
;
7778 /* Compute the physnames of any methods on the CU's method list.
7780 The computation of method physnames is delayed in order to avoid the
7781 (bad) condition that one of the method's formal parameters is of an as yet
7785 compute_delayed_physnames (struct dwarf2_cu
*cu
)
7788 struct delayed_method_info
*mi
;
7789 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
7791 const char *physname
;
7792 struct fn_fieldlist
*fn_flp
7793 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
7794 physname
= dwarf2_physname (mi
->name
, mi
->die
, cu
);
7795 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
->index
)
7796 = physname
? physname
: "";
7800 /* Go objects should be embedded in a DW_TAG_module DIE,
7801 and it's not clear if/how imported objects will appear.
7802 To keep Go support simple until that's worked out,
7803 go back through what we've read and create something usable.
7804 We could do this while processing each DIE, and feels kinda cleaner,
7805 but that way is more invasive.
7806 This is to, for example, allow the user to type "p var" or "b main"
7807 without having to specify the package name, and allow lookups
7808 of module.object to work in contexts that use the expression
7812 fixup_go_packaging (struct dwarf2_cu
*cu
)
7814 char *package_name
= NULL
;
7815 struct pending
*list
;
7818 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
7820 for (i
= 0; i
< list
->nsyms
; ++i
)
7822 struct symbol
*sym
= list
->symbol
[i
];
7824 if (SYMBOL_LANGUAGE (sym
) == language_go
7825 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
7827 char *this_package_name
= go_symbol_package_name (sym
);
7829 if (this_package_name
== NULL
)
7831 if (package_name
== NULL
)
7832 package_name
= this_package_name
;
7835 if (strcmp (package_name
, this_package_name
) != 0)
7836 complaint (&symfile_complaints
,
7837 _("Symtab %s has objects from two different Go packages: %s and %s"),
7838 (symbol_symtab (sym
) != NULL
7839 ? symtab_to_filename_for_display
7840 (symbol_symtab (sym
))
7841 : objfile_name (cu
->objfile
)),
7842 this_package_name
, package_name
);
7843 xfree (this_package_name
);
7849 if (package_name
!= NULL
)
7851 struct objfile
*objfile
= cu
->objfile
;
7852 const char *saved_package_name
7853 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
7855 strlen (package_name
));
7856 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
7857 saved_package_name
);
7860 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7862 sym
= allocate_symbol (objfile
);
7863 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
7864 SYMBOL_SET_NAMES (sym
, saved_package_name
,
7865 strlen (saved_package_name
), 0, objfile
);
7866 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
7867 e.g., "main" finds the "main" module and not C's main(). */
7868 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7869 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
7870 SYMBOL_TYPE (sym
) = type
;
7872 add_symbol_to_list (sym
, &global_symbols
);
7874 xfree (package_name
);
7878 /* Return the symtab for PER_CU. This works properly regardless of
7879 whether we're using the index or psymtabs. */
7881 static struct compunit_symtab
*
7882 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
7884 return (dwarf2_per_objfile
->using_index
7885 ? per_cu
->v
.quick
->compunit_symtab
7886 : per_cu
->v
.psymtab
->compunit_symtab
);
7889 /* A helper function for computing the list of all symbol tables
7890 included by PER_CU. */
7893 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
7894 htab_t all_children
, htab_t all_type_symtabs
,
7895 struct dwarf2_per_cu_data
*per_cu
,
7896 struct compunit_symtab
*immediate_parent
)
7900 struct compunit_symtab
*cust
;
7901 struct dwarf2_per_cu_data
*iter
;
7903 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
7906 /* This inclusion and its children have been processed. */
7911 /* Only add a CU if it has a symbol table. */
7912 cust
= get_compunit_symtab (per_cu
);
7915 /* If this is a type unit only add its symbol table if we haven't
7916 seen it yet (type unit per_cu's can share symtabs). */
7917 if (per_cu
->is_debug_types
)
7919 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
7923 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
7924 if (cust
->user
== NULL
)
7925 cust
->user
= immediate_parent
;
7930 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
7931 if (cust
->user
== NULL
)
7932 cust
->user
= immediate_parent
;
7937 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
7940 recursively_compute_inclusions (result
, all_children
,
7941 all_type_symtabs
, iter
, cust
);
7945 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
7949 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
7951 gdb_assert (! per_cu
->is_debug_types
);
7953 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
7956 struct dwarf2_per_cu_data
*per_cu_iter
;
7957 struct compunit_symtab
*compunit_symtab_iter
;
7958 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
7959 htab_t all_children
, all_type_symtabs
;
7960 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
7962 /* If we don't have a symtab, we can just skip this case. */
7966 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
7967 NULL
, xcalloc
, xfree
);
7968 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
7969 NULL
, xcalloc
, xfree
);
7972 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
7976 recursively_compute_inclusions (&result_symtabs
, all_children
,
7977 all_type_symtabs
, per_cu_iter
,
7981 /* Now we have a transitive closure of all the included symtabs. */
7982 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
7984 = XOBNEWVEC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
7985 struct compunit_symtab
*, len
+ 1);
7987 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
7988 compunit_symtab_iter
);
7990 cust
->includes
[ix
] = compunit_symtab_iter
;
7991 cust
->includes
[len
] = NULL
;
7993 VEC_free (compunit_symtab_ptr
, result_symtabs
);
7994 htab_delete (all_children
);
7995 htab_delete (all_type_symtabs
);
7999 /* Compute the 'includes' field for the symtabs of all the CUs we just
8003 process_cu_includes (void)
8006 struct dwarf2_per_cu_data
*iter
;
8009 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
8013 if (! iter
->is_debug_types
)
8014 compute_compunit_symtab_includes (iter
);
8017 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
8020 /* Generate full symbol information for PER_CU, whose DIEs have
8021 already been loaded into memory. */
8024 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8025 enum language pretend_language
)
8027 struct dwarf2_cu
*cu
= per_cu
->cu
;
8028 struct objfile
*objfile
= per_cu
->objfile
;
8029 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8030 CORE_ADDR lowpc
, highpc
;
8031 struct compunit_symtab
*cust
;
8032 struct cleanup
*back_to
, *delayed_list_cleanup
;
8034 struct block
*static_block
;
8037 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8040 back_to
= make_cleanup (really_free_pendings
, NULL
);
8041 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8043 cu
->list_in_scope
= &file_symbols
;
8045 cu
->language
= pretend_language
;
8046 cu
->language_defn
= language_def (cu
->language
);
8048 /* Do line number decoding in read_file_scope () */
8049 process_die (cu
->dies
, cu
);
8051 /* For now fudge the Go package. */
8052 if (cu
->language
== language_go
)
8053 fixup_go_packaging (cu
);
8055 /* Now that we have processed all the DIEs in the CU, all the types
8056 should be complete, and it should now be safe to compute all of the
8058 compute_delayed_physnames (cu
);
8059 do_cleanups (delayed_list_cleanup
);
8061 /* Some compilers don't define a DW_AT_high_pc attribute for the
8062 compilation unit. If the DW_AT_high_pc is missing, synthesize
8063 it, by scanning the DIE's below the compilation unit. */
8064 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
8066 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
8067 static_block
= end_symtab_get_static_block (addr
, 0, 1);
8069 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
8070 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
8071 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
8072 addrmap to help ensure it has an accurate map of pc values belonging to
8074 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
8076 cust
= end_symtab_from_static_block (static_block
,
8077 SECT_OFF_TEXT (objfile
), 0);
8081 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
8083 /* Set symtab language to language from DW_AT_language. If the
8084 compilation is from a C file generated by language preprocessors, do
8085 not set the language if it was already deduced by start_subfile. */
8086 if (!(cu
->language
== language_c
8087 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
8088 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8090 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
8091 produce DW_AT_location with location lists but it can be possibly
8092 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
8093 there were bugs in prologue debug info, fixed later in GCC-4.5
8094 by "unwind info for epilogues" patch (which is not directly related).
8096 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
8097 needed, it would be wrong due to missing DW_AT_producer there.
8099 Still one can confuse GDB by using non-standard GCC compilation
8100 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
8102 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
8103 cust
->locations_valid
= 1;
8105 if (gcc_4_minor
>= 5)
8106 cust
->epilogue_unwind_valid
= 1;
8108 cust
->call_site_htab
= cu
->call_site_htab
;
8111 if (dwarf2_per_objfile
->using_index
)
8112 per_cu
->v
.quick
->compunit_symtab
= cust
;
8115 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8116 pst
->compunit_symtab
= cust
;
8120 /* Push it for inclusion processing later. */
8121 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
8123 do_cleanups (back_to
);
8126 /* Generate full symbol information for type unit PER_CU, whose DIEs have
8127 already been loaded into memory. */
8130 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
8131 enum language pretend_language
)
8133 struct dwarf2_cu
*cu
= per_cu
->cu
;
8134 struct objfile
*objfile
= per_cu
->objfile
;
8135 struct compunit_symtab
*cust
;
8136 struct cleanup
*back_to
, *delayed_list_cleanup
;
8137 struct signatured_type
*sig_type
;
8139 gdb_assert (per_cu
->is_debug_types
);
8140 sig_type
= (struct signatured_type
*) per_cu
;
8143 back_to
= make_cleanup (really_free_pendings
, NULL
);
8144 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8146 cu
->list_in_scope
= &file_symbols
;
8148 cu
->language
= pretend_language
;
8149 cu
->language_defn
= language_def (cu
->language
);
8151 /* The symbol tables are set up in read_type_unit_scope. */
8152 process_die (cu
->dies
, cu
);
8154 /* For now fudge the Go package. */
8155 if (cu
->language
== language_go
)
8156 fixup_go_packaging (cu
);
8158 /* Now that we have processed all the DIEs in the CU, all the types
8159 should be complete, and it should now be safe to compute all of the
8161 compute_delayed_physnames (cu
);
8162 do_cleanups (delayed_list_cleanup
);
8164 /* TUs share symbol tables.
8165 If this is the first TU to use this symtab, complete the construction
8166 of it with end_expandable_symtab. Otherwise, complete the addition of
8167 this TU's symbols to the existing symtab. */
8168 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
8170 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
8171 sig_type
->type_unit_group
->compunit_symtab
= cust
;
8175 /* Set symtab language to language from DW_AT_language. If the
8176 compilation is from a C file generated by language preprocessors,
8177 do not set the language if it was already deduced by
8179 if (!(cu
->language
== language_c
8180 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
8181 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8186 augment_type_symtab ();
8187 cust
= sig_type
->type_unit_group
->compunit_symtab
;
8190 if (dwarf2_per_objfile
->using_index
)
8191 per_cu
->v
.quick
->compunit_symtab
= cust
;
8194 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8195 pst
->compunit_symtab
= cust
;
8199 do_cleanups (back_to
);
8202 /* Process an imported unit DIE. */
8205 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8207 struct attribute
*attr
;
8209 /* For now we don't handle imported units in type units. */
8210 if (cu
->per_cu
->is_debug_types
)
8212 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8213 " supported in type units [in module %s]"),
8214 objfile_name (cu
->objfile
));
8217 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8220 struct dwarf2_per_cu_data
*per_cu
;
8224 offset
= dwarf2_get_ref_die_offset (attr
);
8225 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
8226 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
8228 /* If necessary, add it to the queue and load its DIEs. */
8229 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
8230 load_full_comp_unit (per_cu
, cu
->language
);
8232 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8237 /* Reset the in_process bit of a die. */
8240 reset_die_in_process (void *arg
)
8242 struct die_info
*die
= (struct die_info
*) arg
;
8244 die
->in_process
= 0;
8247 /* Process a die and its children. */
8250 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8252 struct cleanup
*in_process
;
8254 /* We should only be processing those not already in process. */
8255 gdb_assert (!die
->in_process
);
8257 die
->in_process
= 1;
8258 in_process
= make_cleanup (reset_die_in_process
,die
);
8262 case DW_TAG_padding
:
8264 case DW_TAG_compile_unit
:
8265 case DW_TAG_partial_unit
:
8266 read_file_scope (die
, cu
);
8268 case DW_TAG_type_unit
:
8269 read_type_unit_scope (die
, cu
);
8271 case DW_TAG_subprogram
:
8272 case DW_TAG_inlined_subroutine
:
8273 read_func_scope (die
, cu
);
8275 case DW_TAG_lexical_block
:
8276 case DW_TAG_try_block
:
8277 case DW_TAG_catch_block
:
8278 read_lexical_block_scope (die
, cu
);
8280 case DW_TAG_GNU_call_site
:
8281 read_call_site_scope (die
, cu
);
8283 case DW_TAG_class_type
:
8284 case DW_TAG_interface_type
:
8285 case DW_TAG_structure_type
:
8286 case DW_TAG_union_type
:
8287 process_structure_scope (die
, cu
);
8289 case DW_TAG_enumeration_type
:
8290 process_enumeration_scope (die
, cu
);
8293 /* These dies have a type, but processing them does not create
8294 a symbol or recurse to process the children. Therefore we can
8295 read them on-demand through read_type_die. */
8296 case DW_TAG_subroutine_type
:
8297 case DW_TAG_set_type
:
8298 case DW_TAG_array_type
:
8299 case DW_TAG_pointer_type
:
8300 case DW_TAG_ptr_to_member_type
:
8301 case DW_TAG_reference_type
:
8302 case DW_TAG_string_type
:
8305 case DW_TAG_base_type
:
8306 case DW_TAG_subrange_type
:
8307 case DW_TAG_typedef
:
8308 /* Add a typedef symbol for the type definition, if it has a
8310 new_symbol (die
, read_type_die (die
, cu
), cu
);
8312 case DW_TAG_common_block
:
8313 read_common_block (die
, cu
);
8315 case DW_TAG_common_inclusion
:
8317 case DW_TAG_namespace
:
8318 cu
->processing_has_namespace_info
= 1;
8319 read_namespace (die
, cu
);
8322 cu
->processing_has_namespace_info
= 1;
8323 read_module (die
, cu
);
8325 case DW_TAG_imported_declaration
:
8326 cu
->processing_has_namespace_info
= 1;
8327 if (read_namespace_alias (die
, cu
))
8329 /* The declaration is not a global namespace alias: fall through. */
8330 case DW_TAG_imported_module
:
8331 cu
->processing_has_namespace_info
= 1;
8332 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
8333 || cu
->language
!= language_fortran
))
8334 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
8335 dwarf_tag_name (die
->tag
));
8336 read_import_statement (die
, cu
);
8339 case DW_TAG_imported_unit
:
8340 process_imported_unit_die (die
, cu
);
8344 new_symbol (die
, NULL
, cu
);
8348 do_cleanups (in_process
);
8351 /* DWARF name computation. */
8353 /* A helper function for dwarf2_compute_name which determines whether DIE
8354 needs to have the name of the scope prepended to the name listed in the
8358 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8360 struct attribute
*attr
;
8364 case DW_TAG_namespace
:
8365 case DW_TAG_typedef
:
8366 case DW_TAG_class_type
:
8367 case DW_TAG_interface_type
:
8368 case DW_TAG_structure_type
:
8369 case DW_TAG_union_type
:
8370 case DW_TAG_enumeration_type
:
8371 case DW_TAG_enumerator
:
8372 case DW_TAG_subprogram
:
8373 case DW_TAG_inlined_subroutine
:
8375 case DW_TAG_imported_declaration
:
8378 case DW_TAG_variable
:
8379 case DW_TAG_constant
:
8380 /* We only need to prefix "globally" visible variables. These include
8381 any variable marked with DW_AT_external or any variable that
8382 lives in a namespace. [Variables in anonymous namespaces
8383 require prefixing, but they are not DW_AT_external.] */
8385 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
8387 struct dwarf2_cu
*spec_cu
= cu
;
8389 return die_needs_namespace (die_specification (die
, &spec_cu
),
8393 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8394 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
8395 && die
->parent
->tag
!= DW_TAG_module
)
8397 /* A variable in a lexical block of some kind does not need a
8398 namespace, even though in C++ such variables may be external
8399 and have a mangled name. */
8400 if (die
->parent
->tag
== DW_TAG_lexical_block
8401 || die
->parent
->tag
== DW_TAG_try_block
8402 || die
->parent
->tag
== DW_TAG_catch_block
8403 || die
->parent
->tag
== DW_TAG_subprogram
)
8412 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
8413 compute the physname for the object, which include a method's:
8414 - formal parameters (C++),
8415 - receiver type (Go),
8417 The term "physname" is a bit confusing.
8418 For C++, for example, it is the demangled name.
8419 For Go, for example, it's the mangled name.
8421 For Ada, return the DIE's linkage name rather than the fully qualified
8422 name. PHYSNAME is ignored..
8424 The result is allocated on the objfile_obstack and canonicalized. */
8427 dwarf2_compute_name (const char *name
,
8428 struct die_info
*die
, struct dwarf2_cu
*cu
,
8431 struct objfile
*objfile
= cu
->objfile
;
8434 name
= dwarf2_name (die
, cu
);
8436 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
8437 but otherwise compute it by typename_concat inside GDB.
8438 FIXME: Actually this is not really true, or at least not always true.
8439 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
8440 Fortran names because there is no mangling standard. So new_symbol_full
8441 will set the demangled name to the result of dwarf2_full_name, and it is
8442 the demangled name that GDB uses if it exists. */
8443 if (cu
->language
== language_ada
8444 || (cu
->language
== language_fortran
&& physname
))
8446 /* For Ada unit, we prefer the linkage name over the name, as
8447 the former contains the exported name, which the user expects
8448 to be able to reference. Ideally, we want the user to be able
8449 to reference this entity using either natural or linkage name,
8450 but we haven't started looking at this enhancement yet. */
8451 const char *linkage_name
;
8453 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
8454 if (linkage_name
== NULL
)
8455 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8456 if (linkage_name
!= NULL
)
8457 return linkage_name
;
8460 /* These are the only languages we know how to qualify names in. */
8462 && (cu
->language
== language_cplus
8463 || cu
->language
== language_fortran
|| cu
->language
== language_d
8464 || cu
->language
== language_rust
))
8466 if (die_needs_namespace (die
, cu
))
8470 const char *canonical_name
= NULL
;
8474 prefix
= determine_prefix (die
, cu
);
8475 if (*prefix
!= '\0')
8477 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
8480 buf
.puts (prefixed_name
);
8481 xfree (prefixed_name
);
8486 /* Template parameters may be specified in the DIE's DW_AT_name, or
8487 as children with DW_TAG_template_type_param or
8488 DW_TAG_value_type_param. If the latter, add them to the name
8489 here. If the name already has template parameters, then
8490 skip this step; some versions of GCC emit both, and
8491 it is more efficient to use the pre-computed name.
8493 Something to keep in mind about this process: it is very
8494 unlikely, or in some cases downright impossible, to produce
8495 something that will match the mangled name of a function.
8496 If the definition of the function has the same debug info,
8497 we should be able to match up with it anyway. But fallbacks
8498 using the minimal symbol, for instance to find a method
8499 implemented in a stripped copy of libstdc++, will not work.
8500 If we do not have debug info for the definition, we will have to
8501 match them up some other way.
8503 When we do name matching there is a related problem with function
8504 templates; two instantiated function templates are allowed to
8505 differ only by their return types, which we do not add here. */
8507 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
8509 struct attribute
*attr
;
8510 struct die_info
*child
;
8513 die
->building_fullname
= 1;
8515 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
8519 const gdb_byte
*bytes
;
8520 struct dwarf2_locexpr_baton
*baton
;
8523 if (child
->tag
!= DW_TAG_template_type_param
8524 && child
->tag
!= DW_TAG_template_value_param
)
8535 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
8538 complaint (&symfile_complaints
,
8539 _("template parameter missing DW_AT_type"));
8540 buf
.puts ("UNKNOWN_TYPE");
8543 type
= die_type (child
, cu
);
8545 if (child
->tag
== DW_TAG_template_type_param
)
8547 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
8551 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
8554 complaint (&symfile_complaints
,
8555 _("template parameter missing "
8556 "DW_AT_const_value"));
8557 buf
.puts ("UNKNOWN_VALUE");
8561 dwarf2_const_value_attr (attr
, type
, name
,
8562 &cu
->comp_unit_obstack
, cu
,
8563 &value
, &bytes
, &baton
);
8565 if (TYPE_NOSIGN (type
))
8566 /* GDB prints characters as NUMBER 'CHAR'. If that's
8567 changed, this can use value_print instead. */
8568 c_printchar (value
, type
, &buf
);
8571 struct value_print_options opts
;
8574 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
8578 else if (bytes
!= NULL
)
8580 v
= allocate_value (type
);
8581 memcpy (value_contents_writeable (v
), bytes
,
8582 TYPE_LENGTH (type
));
8585 v
= value_from_longest (type
, value
);
8587 /* Specify decimal so that we do not depend on
8589 get_formatted_print_options (&opts
, 'd');
8591 value_print (v
, &buf
, &opts
);
8597 die
->building_fullname
= 0;
8601 /* Close the argument list, with a space if necessary
8602 (nested templates). */
8603 if (!buf
.empty () && buf
.string ().back () == '>')
8610 /* For C++ methods, append formal parameter type
8611 information, if PHYSNAME. */
8613 if (physname
&& die
->tag
== DW_TAG_subprogram
8614 && cu
->language
== language_cplus
)
8616 struct type
*type
= read_type_die (die
, cu
);
8618 c_type_print_args (type
, &buf
, 1, cu
->language
,
8619 &type_print_raw_options
);
8621 if (cu
->language
== language_cplus
)
8623 /* Assume that an artificial first parameter is
8624 "this", but do not crash if it is not. RealView
8625 marks unnamed (and thus unused) parameters as
8626 artificial; there is no way to differentiate
8628 if (TYPE_NFIELDS (type
) > 0
8629 && TYPE_FIELD_ARTIFICIAL (type
, 0)
8630 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
8631 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
8633 buf
.puts (" const");
8637 const std::string
&intermediate_name
= buf
.string ();
8639 if (cu
->language
== language_cplus
)
8641 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
8642 &objfile
->per_bfd
->storage_obstack
);
8644 /* If we only computed INTERMEDIATE_NAME, or if
8645 INTERMEDIATE_NAME is already canonical, then we need to
8646 copy it to the appropriate obstack. */
8647 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
8648 name
= ((const char *)
8649 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8650 intermediate_name
.c_str (),
8651 intermediate_name
.length ()));
8653 name
= canonical_name
;
8660 /* Return the fully qualified name of DIE, based on its DW_AT_name.
8661 If scope qualifiers are appropriate they will be added. The result
8662 will be allocated on the storage_obstack, or NULL if the DIE does
8663 not have a name. NAME may either be from a previous call to
8664 dwarf2_name or NULL.
8666 The output string will be canonicalized (if C++). */
8669 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8671 return dwarf2_compute_name (name
, die
, cu
, 0);
8674 /* Construct a physname for the given DIE in CU. NAME may either be
8675 from a previous call to dwarf2_name or NULL. The result will be
8676 allocated on the objfile_objstack or NULL if the DIE does not have a
8679 The output string will be canonicalized (if C++). */
8682 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8684 struct objfile
*objfile
= cu
->objfile
;
8685 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
8686 struct cleanup
*back_to
;
8689 /* In this case dwarf2_compute_name is just a shortcut not building anything
8691 if (!die_needs_namespace (die
, cu
))
8692 return dwarf2_compute_name (name
, die
, cu
, 1);
8694 back_to
= make_cleanup (null_cleanup
, NULL
);
8696 mangled
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
8697 if (mangled
== NULL
)
8698 mangled
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8700 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
8701 See https://github.com/rust-lang/rust/issues/32925. */
8702 if (cu
->language
== language_rust
&& mangled
!= NULL
8703 && strchr (mangled
, '{') != NULL
)
8706 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
8708 if (mangled
!= NULL
)
8712 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
8713 type. It is easier for GDB users to search for such functions as
8714 `name(params)' than `long name(params)'. In such case the minimal
8715 symbol names do not match the full symbol names but for template
8716 functions there is never a need to look up their definition from their
8717 declaration so the only disadvantage remains the minimal symbol
8718 variant `long name(params)' does not have the proper inferior type.
8721 if (cu
->language
== language_go
)
8723 /* This is a lie, but we already lie to the caller new_symbol_full.
8724 new_symbol_full assumes we return the mangled name.
8725 This just undoes that lie until things are cleaned up. */
8730 demangled
= gdb_demangle (mangled
,
8731 (DMGL_PARAMS
| DMGL_ANSI
| DMGL_RET_DROP
));
8735 make_cleanup (xfree
, demangled
);
8745 if (canon
== NULL
|| check_physname
)
8747 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
8749 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
8751 /* It may not mean a bug in GDB. The compiler could also
8752 compute DW_AT_linkage_name incorrectly. But in such case
8753 GDB would need to be bug-to-bug compatible. */
8755 complaint (&symfile_complaints
,
8756 _("Computed physname <%s> does not match demangled <%s> "
8757 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
8758 physname
, canon
, mangled
, die
->offset
.sect_off
,
8759 objfile_name (objfile
));
8761 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
8762 is available here - over computed PHYSNAME. It is safer
8763 against both buggy GDB and buggy compilers. */
8777 retval
= ((const char *)
8778 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8779 retval
, strlen (retval
)));
8781 do_cleanups (back_to
);
8785 /* Inspect DIE in CU for a namespace alias. If one exists, record
8786 a new symbol for it.
8788 Returns 1 if a namespace alias was recorded, 0 otherwise. */
8791 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
8793 struct attribute
*attr
;
8795 /* If the die does not have a name, this is not a namespace
8797 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8801 struct die_info
*d
= die
;
8802 struct dwarf2_cu
*imported_cu
= cu
;
8804 /* If the compiler has nested DW_AT_imported_declaration DIEs,
8805 keep inspecting DIEs until we hit the underlying import. */
8806 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
8807 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
8809 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
8813 d
= follow_die_ref (d
, attr
, &imported_cu
);
8814 if (d
->tag
!= DW_TAG_imported_declaration
)
8818 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
8820 complaint (&symfile_complaints
,
8821 _("DIE at 0x%x has too many recursively imported "
8822 "declarations"), d
->offset
.sect_off
);
8829 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
8831 type
= get_die_type_at_offset (offset
, cu
->per_cu
);
8832 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
8834 /* This declaration is a global namespace alias. Add
8835 a symbol for it whose type is the aliased namespace. */
8836 new_symbol (die
, type
, cu
);
8845 /* Return the using directives repository (global or local?) to use in the
8846 current context for LANGUAGE.
8848 For Ada, imported declarations can materialize renamings, which *may* be
8849 global. However it is impossible (for now?) in DWARF to distinguish
8850 "external" imported declarations and "static" ones. As all imported
8851 declarations seem to be static in all other languages, make them all CU-wide
8852 global only in Ada. */
8854 static struct using_direct
**
8855 using_directives (enum language language
)
8857 if (language
== language_ada
&& context_stack_depth
== 0)
8858 return &global_using_directives
;
8860 return &local_using_directives
;
8863 /* Read the import statement specified by the given die and record it. */
8866 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
8868 struct objfile
*objfile
= cu
->objfile
;
8869 struct attribute
*import_attr
;
8870 struct die_info
*imported_die
, *child_die
;
8871 struct dwarf2_cu
*imported_cu
;
8872 const char *imported_name
;
8873 const char *imported_name_prefix
;
8874 const char *canonical_name
;
8875 const char *import_alias
;
8876 const char *imported_declaration
= NULL
;
8877 const char *import_prefix
;
8878 VEC (const_char_ptr
) *excludes
= NULL
;
8879 struct cleanup
*cleanups
;
8881 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8882 if (import_attr
== NULL
)
8884 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
8885 dwarf_tag_name (die
->tag
));
8890 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
8891 imported_name
= dwarf2_name (imported_die
, imported_cu
);
8892 if (imported_name
== NULL
)
8894 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
8896 The import in the following code:
8910 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
8911 <52> DW_AT_decl_file : 1
8912 <53> DW_AT_decl_line : 6
8913 <54> DW_AT_import : <0x75>
8914 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
8916 <5b> DW_AT_decl_file : 1
8917 <5c> DW_AT_decl_line : 2
8918 <5d> DW_AT_type : <0x6e>
8920 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
8921 <76> DW_AT_byte_size : 4
8922 <77> DW_AT_encoding : 5 (signed)
8924 imports the wrong die ( 0x75 instead of 0x58 ).
8925 This case will be ignored until the gcc bug is fixed. */
8929 /* Figure out the local name after import. */
8930 import_alias
= dwarf2_name (die
, cu
);
8932 /* Figure out where the statement is being imported to. */
8933 import_prefix
= determine_prefix (die
, cu
);
8935 /* Figure out what the scope of the imported die is and prepend it
8936 to the name of the imported die. */
8937 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
8939 if (imported_die
->tag
!= DW_TAG_namespace
8940 && imported_die
->tag
!= DW_TAG_module
)
8942 imported_declaration
= imported_name
;
8943 canonical_name
= imported_name_prefix
;
8945 else if (strlen (imported_name_prefix
) > 0)
8946 canonical_name
= obconcat (&objfile
->objfile_obstack
,
8947 imported_name_prefix
,
8948 (cu
->language
== language_d
? "." : "::"),
8949 imported_name
, (char *) NULL
);
8951 canonical_name
= imported_name
;
8953 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
8955 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
8956 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
8957 child_die
= sibling_die (child_die
))
8959 /* DWARF-4: A Fortran use statement with a “rename list” may be
8960 represented by an imported module entry with an import attribute
8961 referring to the module and owned entries corresponding to those
8962 entities that are renamed as part of being imported. */
8964 if (child_die
->tag
!= DW_TAG_imported_declaration
)
8966 complaint (&symfile_complaints
,
8967 _("child DW_TAG_imported_declaration expected "
8968 "- DIE at 0x%x [in module %s]"),
8969 child_die
->offset
.sect_off
, objfile_name (objfile
));
8973 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
8974 if (import_attr
== NULL
)
8976 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
8977 dwarf_tag_name (child_die
->tag
));
8982 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
8984 imported_name
= dwarf2_name (imported_die
, imported_cu
);
8985 if (imported_name
== NULL
)
8987 complaint (&symfile_complaints
,
8988 _("child DW_TAG_imported_declaration has unknown "
8989 "imported name - DIE at 0x%x [in module %s]"),
8990 child_die
->offset
.sect_off
, objfile_name (objfile
));
8994 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
8996 process_die (child_die
, cu
);
8999 add_using_directive (using_directives (cu
->language
),
9003 imported_declaration
,
9006 &objfile
->objfile_obstack
);
9008 do_cleanups (cleanups
);
9011 /* Cleanup function for handle_DW_AT_stmt_list. */
9014 free_cu_line_header (void *arg
)
9016 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) arg
;
9018 free_line_header (cu
->line_header
);
9019 cu
->line_header
= NULL
;
9022 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
9023 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
9024 this, it was first present in GCC release 4.3.0. */
9027 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
9029 if (!cu
->checked_producer
)
9030 check_producer (cu
);
9032 return cu
->producer_is_gcc_lt_4_3
;
9036 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
9037 const char **name
, const char **comp_dir
)
9039 /* Find the filename. Do not use dwarf2_name here, since the filename
9040 is not a source language identifier. */
9041 *name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
9042 *comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
9044 if (*comp_dir
== NULL
9045 && producer_is_gcc_lt_4_3 (cu
) && *name
!= NULL
9046 && IS_ABSOLUTE_PATH (*name
))
9048 char *d
= ldirname (*name
);
9052 make_cleanup (xfree
, d
);
9054 if (*comp_dir
!= NULL
)
9056 /* Irix 6.2 native cc prepends <machine>.: to the compilation
9057 directory, get rid of it. */
9058 const char *cp
= strchr (*comp_dir
, ':');
9060 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
9065 *name
= "<unknown>";
9068 /* Handle DW_AT_stmt_list for a compilation unit.
9069 DIE is the DW_TAG_compile_unit die for CU.
9070 COMP_DIR is the compilation directory. LOWPC is passed to
9071 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
9074 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
9075 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
9077 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9078 struct attribute
*attr
;
9079 unsigned int line_offset
;
9080 struct line_header line_header_local
;
9081 hashval_t line_header_local_hash
;
9086 gdb_assert (! cu
->per_cu
->is_debug_types
);
9088 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9092 line_offset
= DW_UNSND (attr
);
9094 /* The line header hash table is only created if needed (it exists to
9095 prevent redundant reading of the line table for partial_units).
9096 If we're given a partial_unit, we'll need it. If we're given a
9097 compile_unit, then use the line header hash table if it's already
9098 created, but don't create one just yet. */
9100 if (dwarf2_per_objfile
->line_header_hash
== NULL
9101 && die
->tag
== DW_TAG_partial_unit
)
9103 dwarf2_per_objfile
->line_header_hash
9104 = htab_create_alloc_ex (127, line_header_hash_voidp
,
9105 line_header_eq_voidp
,
9106 free_line_header_voidp
,
9107 &objfile
->objfile_obstack
,
9108 hashtab_obstack_allocate
,
9109 dummy_obstack_deallocate
);
9112 line_header_local
.offset
.sect_off
= line_offset
;
9113 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
9114 line_header_local_hash
= line_header_hash (&line_header_local
);
9115 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
9117 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9119 line_header_local_hash
, NO_INSERT
);
9121 /* For DW_TAG_compile_unit we need info like symtab::linetable which
9122 is not present in *SLOT (since if there is something in *SLOT then
9123 it will be for a partial_unit). */
9124 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
9126 gdb_assert (*slot
!= NULL
);
9127 cu
->line_header
= (struct line_header
*) *slot
;
9132 /* dwarf_decode_line_header does not yet provide sufficient information.
9133 We always have to call also dwarf_decode_lines for it. */
9134 cu
->line_header
= dwarf_decode_line_header (line_offset
, cu
);
9135 if (cu
->line_header
== NULL
)
9138 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
9142 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9144 line_header_local_hash
, INSERT
);
9145 gdb_assert (slot
!= NULL
);
9147 if (slot
!= NULL
&& *slot
== NULL
)
9149 /* This newly decoded line number information unit will be owned
9150 by line_header_hash hash table. */
9151 *slot
= cu
->line_header
;
9155 /* We cannot free any current entry in (*slot) as that struct line_header
9156 may be already used by multiple CUs. Create only temporary decoded
9157 line_header for this CU - it may happen at most once for each line
9158 number information unit. And if we're not using line_header_hash
9159 then this is what we want as well. */
9160 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
9161 make_cleanup (free_cu_line_header
, cu
);
9163 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
9164 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
9168 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
9171 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9173 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9174 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9175 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
9176 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
9177 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
9178 struct attribute
*attr
;
9179 const char *name
= NULL
;
9180 const char *comp_dir
= NULL
;
9181 struct die_info
*child_die
;
9184 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9186 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
9188 /* If we didn't find a lowpc, set it to highpc to avoid complaints
9189 from finish_block. */
9190 if (lowpc
== ((CORE_ADDR
) -1))
9192 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
9194 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
9196 prepare_one_comp_unit (cu
, die
, cu
->language
);
9198 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
9199 standardised yet. As a workaround for the language detection we fall
9200 back to the DW_AT_producer string. */
9201 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
9202 cu
->language
= language_opencl
;
9204 /* Similar hack for Go. */
9205 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
9206 set_cu_language (DW_LANG_Go
, cu
);
9208 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
9210 /* Decode line number information if present. We do this before
9211 processing child DIEs, so that the line header table is available
9212 for DW_AT_decl_file. */
9213 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, lowpc
);
9215 /* Process all dies in compilation unit. */
9216 if (die
->child
!= NULL
)
9218 child_die
= die
->child
;
9219 while (child_die
&& child_die
->tag
)
9221 process_die (child_die
, cu
);
9222 child_die
= sibling_die (child_die
);
9226 /* Decode macro information, if present. Dwarf 2 macro information
9227 refers to information in the line number info statement program
9228 header, so we can only read it if we've read the header
9230 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
9231 if (attr
&& cu
->line_header
)
9233 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
9234 complaint (&symfile_complaints
,
9235 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
9237 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
9241 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
9242 if (attr
&& cu
->line_header
)
9244 unsigned int macro_offset
= DW_UNSND (attr
);
9246 dwarf_decode_macros (cu
, macro_offset
, 0);
9250 do_cleanups (back_to
);
9253 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
9254 Create the set of symtabs used by this TU, or if this TU is sharing
9255 symtabs with another TU and the symtabs have already been created
9256 then restore those symtabs in the line header.
9257 We don't need the pc/line-number mapping for type units. */
9260 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
9262 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
9263 struct type_unit_group
*tu_group
;
9265 struct line_header
*lh
;
9266 struct attribute
*attr
;
9267 unsigned int i
, line_offset
;
9268 struct signatured_type
*sig_type
;
9270 gdb_assert (per_cu
->is_debug_types
);
9271 sig_type
= (struct signatured_type
*) per_cu
;
9273 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9275 /* If we're using .gdb_index (includes -readnow) then
9276 per_cu->type_unit_group may not have been set up yet. */
9277 if (sig_type
->type_unit_group
== NULL
)
9278 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
9279 tu_group
= sig_type
->type_unit_group
;
9281 /* If we've already processed this stmt_list there's no real need to
9282 do it again, we could fake it and just recreate the part we need
9283 (file name,index -> symtab mapping). If data shows this optimization
9284 is useful we can do it then. */
9285 first_time
= tu_group
->compunit_symtab
== NULL
;
9287 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
9292 line_offset
= DW_UNSND (attr
);
9293 lh
= dwarf_decode_line_header (line_offset
, cu
);
9298 dwarf2_start_symtab (cu
, "", NULL
, 0);
9301 gdb_assert (tu_group
->symtabs
== NULL
);
9302 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9307 cu
->line_header
= lh
;
9308 make_cleanup (free_cu_line_header
, cu
);
9312 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
9314 /* Note: We don't assign tu_group->compunit_symtab yet because we're
9315 still initializing it, and our caller (a few levels up)
9316 process_full_type_unit still needs to know if this is the first
9319 tu_group
->num_symtabs
= lh
->num_file_names
;
9320 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
9322 for (i
= 0; i
< lh
->num_file_names
; ++i
)
9324 const char *dir
= NULL
;
9325 struct file_entry
*fe
= &lh
->file_names
[i
];
9327 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
9328 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9329 dwarf2_start_subfile (fe
->name
, dir
);
9331 if (current_subfile
->symtab
== NULL
)
9333 /* NOTE: start_subfile will recognize when it's been passed
9334 a file it has already seen. So we can't assume there's a
9335 simple mapping from lh->file_names to subfiles, plus
9336 lh->file_names may contain dups. */
9337 current_subfile
->symtab
9338 = allocate_symtab (cust
, current_subfile
->name
);
9341 fe
->symtab
= current_subfile
->symtab
;
9342 tu_group
->symtabs
[i
] = fe
->symtab
;
9347 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9349 for (i
= 0; i
< lh
->num_file_names
; ++i
)
9351 struct file_entry
*fe
= &lh
->file_names
[i
];
9353 fe
->symtab
= tu_group
->symtabs
[i
];
9357 /* The main symtab is allocated last. Type units don't have DW_AT_name
9358 so they don't have a "real" (so to speak) symtab anyway.
9359 There is later code that will assign the main symtab to all symbols
9360 that don't have one. We need to handle the case of a symbol with a
9361 missing symtab (DW_AT_decl_file) anyway. */
9364 /* Process DW_TAG_type_unit.
9365 For TUs we want to skip the first top level sibling if it's not the
9366 actual type being defined by this TU. In this case the first top
9367 level sibling is there to provide context only. */
9370 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9372 struct die_info
*child_die
;
9374 prepare_one_comp_unit (cu
, die
, language_minimal
);
9376 /* Initialize (or reinitialize) the machinery for building symtabs.
9377 We do this before processing child DIEs, so that the line header table
9378 is available for DW_AT_decl_file. */
9379 setup_type_unit_groups (die
, cu
);
9381 if (die
->child
!= NULL
)
9383 child_die
= die
->child
;
9384 while (child_die
&& child_die
->tag
)
9386 process_die (child_die
, cu
);
9387 child_die
= sibling_die (child_die
);
9394 http://gcc.gnu.org/wiki/DebugFission
9395 http://gcc.gnu.org/wiki/DebugFissionDWP
9397 To simplify handling of both DWO files ("object" files with the DWARF info)
9398 and DWP files (a file with the DWOs packaged up into one file), we treat
9399 DWP files as having a collection of virtual DWO files. */
9402 hash_dwo_file (const void *item
)
9404 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
9407 hash
= htab_hash_string (dwo_file
->dwo_name
);
9408 if (dwo_file
->comp_dir
!= NULL
)
9409 hash
+= htab_hash_string (dwo_file
->comp_dir
);
9414 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
9416 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
9417 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
9419 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
9421 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
9422 return lhs
->comp_dir
== rhs
->comp_dir
;
9423 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
9426 /* Allocate a hash table for DWO files. */
9429 allocate_dwo_file_hash_table (void)
9431 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9433 return htab_create_alloc_ex (41,
9437 &objfile
->objfile_obstack
,
9438 hashtab_obstack_allocate
,
9439 dummy_obstack_deallocate
);
9442 /* Lookup DWO file DWO_NAME. */
9445 lookup_dwo_file_slot (const char *dwo_name
, const char *comp_dir
)
9447 struct dwo_file find_entry
;
9450 if (dwarf2_per_objfile
->dwo_files
== NULL
)
9451 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
9453 memset (&find_entry
, 0, sizeof (find_entry
));
9454 find_entry
.dwo_name
= dwo_name
;
9455 find_entry
.comp_dir
= comp_dir
;
9456 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
9462 hash_dwo_unit (const void *item
)
9464 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
9466 /* This drops the top 32 bits of the id, but is ok for a hash. */
9467 return dwo_unit
->signature
;
9471 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
9473 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
9474 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
9476 /* The signature is assumed to be unique within the DWO file.
9477 So while object file CU dwo_id's always have the value zero,
9478 that's OK, assuming each object file DWO file has only one CU,
9479 and that's the rule for now. */
9480 return lhs
->signature
== rhs
->signature
;
9483 /* Allocate a hash table for DWO CUs,TUs.
9484 There is one of these tables for each of CUs,TUs for each DWO file. */
9487 allocate_dwo_unit_table (struct objfile
*objfile
)
9489 /* Start out with a pretty small number.
9490 Generally DWO files contain only one CU and maybe some TUs. */
9491 return htab_create_alloc_ex (3,
9495 &objfile
->objfile_obstack
,
9496 hashtab_obstack_allocate
,
9497 dummy_obstack_deallocate
);
9500 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
9502 struct create_dwo_cu_data
9504 struct dwo_file
*dwo_file
;
9505 struct dwo_unit dwo_unit
;
9508 /* die_reader_func for create_dwo_cu. */
9511 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
9512 const gdb_byte
*info_ptr
,
9513 struct die_info
*comp_unit_die
,
9517 struct dwarf2_cu
*cu
= reader
->cu
;
9518 sect_offset offset
= cu
->per_cu
->offset
;
9519 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
9520 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
9521 struct dwo_file
*dwo_file
= data
->dwo_file
;
9522 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
9523 struct attribute
*attr
;
9525 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
9528 complaint (&symfile_complaints
,
9529 _("Dwarf Error: debug entry at offset 0x%x is missing"
9530 " its dwo_id [in module %s]"),
9531 offset
.sect_off
, dwo_file
->dwo_name
);
9535 dwo_unit
->dwo_file
= dwo_file
;
9536 dwo_unit
->signature
= DW_UNSND (attr
);
9537 dwo_unit
->section
= section
;
9538 dwo_unit
->offset
= offset
;
9539 dwo_unit
->length
= cu
->per_cu
->length
;
9541 if (dwarf_read_debug
)
9542 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id %s\n",
9543 offset
.sect_off
, hex_string (dwo_unit
->signature
));
9546 /* Create the dwo_unit for the lone CU in DWO_FILE.
9547 Note: This function processes DWO files only, not DWP files. */
9549 static struct dwo_unit
*
9550 create_dwo_cu (struct dwo_file
*dwo_file
)
9552 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9553 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
9554 const gdb_byte
*info_ptr
, *end_ptr
;
9555 struct create_dwo_cu_data create_dwo_cu_data
;
9556 struct dwo_unit
*dwo_unit
;
9558 dwarf2_read_section (objfile
, section
);
9559 info_ptr
= section
->buffer
;
9561 if (info_ptr
== NULL
)
9564 if (dwarf_read_debug
)
9566 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
9567 get_section_name (section
),
9568 get_section_file_name (section
));
9571 create_dwo_cu_data
.dwo_file
= dwo_file
;
9574 end_ptr
= info_ptr
+ section
->size
;
9575 while (info_ptr
< end_ptr
)
9577 struct dwarf2_per_cu_data per_cu
;
9579 memset (&create_dwo_cu_data
.dwo_unit
, 0,
9580 sizeof (create_dwo_cu_data
.dwo_unit
));
9581 memset (&per_cu
, 0, sizeof (per_cu
));
9582 per_cu
.objfile
= objfile
;
9583 per_cu
.is_debug_types
= 0;
9584 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
9585 per_cu
.section
= section
;
9587 init_cutu_and_read_dies_no_follow (&per_cu
, dwo_file
,
9588 create_dwo_cu_reader
,
9589 &create_dwo_cu_data
);
9591 if (create_dwo_cu_data
.dwo_unit
.dwo_file
!= NULL
)
9593 /* If we've already found one, complain. We only support one
9594 because having more than one requires hacking the dwo_name of
9595 each to match, which is highly unlikely to happen. */
9596 if (dwo_unit
!= NULL
)
9598 complaint (&symfile_complaints
,
9599 _("Multiple CUs in DWO file %s [in module %s]"),
9600 dwo_file
->dwo_name
, objfile_name (objfile
));
9604 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
9605 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
9608 info_ptr
+= per_cu
.length
;
9614 /* DWP file .debug_{cu,tu}_index section format:
9615 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
9619 Both index sections have the same format, and serve to map a 64-bit
9620 signature to a set of section numbers. Each section begins with a header,
9621 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
9622 indexes, and a pool of 32-bit section numbers. The index sections will be
9623 aligned at 8-byte boundaries in the file.
9625 The index section header consists of:
9627 V, 32 bit version number
9629 N, 32 bit number of compilation units or type units in the index
9630 M, 32 bit number of slots in the hash table
9632 Numbers are recorded using the byte order of the application binary.
9634 The hash table begins at offset 16 in the section, and consists of an array
9635 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
9636 order of the application binary). Unused slots in the hash table are 0.
9637 (We rely on the extreme unlikeliness of a signature being exactly 0.)
9639 The parallel table begins immediately after the hash table
9640 (at offset 16 + 8 * M from the beginning of the section), and consists of an
9641 array of 32-bit indexes (using the byte order of the application binary),
9642 corresponding 1-1 with slots in the hash table. Each entry in the parallel
9643 table contains a 32-bit index into the pool of section numbers. For unused
9644 hash table slots, the corresponding entry in the parallel table will be 0.
9646 The pool of section numbers begins immediately following the hash table
9647 (at offset 16 + 12 * M from the beginning of the section). The pool of
9648 section numbers consists of an array of 32-bit words (using the byte order
9649 of the application binary). Each item in the array is indexed starting
9650 from 0. The hash table entry provides the index of the first section
9651 number in the set. Additional section numbers in the set follow, and the
9652 set is terminated by a 0 entry (section number 0 is not used in ELF).
9654 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
9655 section must be the first entry in the set, and the .debug_abbrev.dwo must
9656 be the second entry. Other members of the set may follow in any order.
9662 DWP Version 2 combines all the .debug_info, etc. sections into one,
9663 and the entries in the index tables are now offsets into these sections.
9664 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
9667 Index Section Contents:
9669 Hash Table of Signatures dwp_hash_table.hash_table
9670 Parallel Table of Indices dwp_hash_table.unit_table
9671 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
9672 Table of Section Sizes dwp_hash_table.v2.sizes
9674 The index section header consists of:
9676 V, 32 bit version number
9677 L, 32 bit number of columns in the table of section offsets
9678 N, 32 bit number of compilation units or type units in the index
9679 M, 32 bit number of slots in the hash table
9681 Numbers are recorded using the byte order of the application binary.
9683 The hash table has the same format as version 1.
9684 The parallel table of indices has the same format as version 1,
9685 except that the entries are origin-1 indices into the table of sections
9686 offsets and the table of section sizes.
9688 The table of offsets begins immediately following the parallel table
9689 (at offset 16 + 12 * M from the beginning of the section). The table is
9690 a two-dimensional array of 32-bit words (using the byte order of the
9691 application binary), with L columns and N+1 rows, in row-major order.
9692 Each row in the array is indexed starting from 0. The first row provides
9693 a key to the remaining rows: each column in this row provides an identifier
9694 for a debug section, and the offsets in the same column of subsequent rows
9695 refer to that section. The section identifiers are:
9697 DW_SECT_INFO 1 .debug_info.dwo
9698 DW_SECT_TYPES 2 .debug_types.dwo
9699 DW_SECT_ABBREV 3 .debug_abbrev.dwo
9700 DW_SECT_LINE 4 .debug_line.dwo
9701 DW_SECT_LOC 5 .debug_loc.dwo
9702 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
9703 DW_SECT_MACINFO 7 .debug_macinfo.dwo
9704 DW_SECT_MACRO 8 .debug_macro.dwo
9706 The offsets provided by the CU and TU index sections are the base offsets
9707 for the contributions made by each CU or TU to the corresponding section
9708 in the package file. Each CU and TU header contains an abbrev_offset
9709 field, used to find the abbreviations table for that CU or TU within the
9710 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
9711 be interpreted as relative to the base offset given in the index section.
9712 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
9713 should be interpreted as relative to the base offset for .debug_line.dwo,
9714 and offsets into other debug sections obtained from DWARF attributes should
9715 also be interpreted as relative to the corresponding base offset.
9717 The table of sizes begins immediately following the table of offsets.
9718 Like the table of offsets, it is a two-dimensional array of 32-bit words,
9719 with L columns and N rows, in row-major order. Each row in the array is
9720 indexed starting from 1 (row 0 is shared by the two tables).
9724 Hash table lookup is handled the same in version 1 and 2:
9726 We assume that N and M will not exceed 2^32 - 1.
9727 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
9729 Given a 64-bit compilation unit signature or a type signature S, an entry
9730 in the hash table is located as follows:
9732 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
9733 the low-order k bits all set to 1.
9735 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
9737 3) If the hash table entry at index H matches the signature, use that
9738 entry. If the hash table entry at index H is unused (all zeroes),
9739 terminate the search: the signature is not present in the table.
9741 4) Let H = (H + H') modulo M. Repeat at Step 3.
9743 Because M > N and H' and M are relatively prime, the search is guaranteed
9744 to stop at an unused slot or find the match. */
9746 /* Create a hash table to map DWO IDs to their CU/TU entry in
9747 .debug_{info,types}.dwo in DWP_FILE.
9748 Returns NULL if there isn't one.
9749 Note: This function processes DWP files only, not DWO files. */
9751 static struct dwp_hash_table
*
9752 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
9754 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9755 bfd
*dbfd
= dwp_file
->dbfd
;
9756 const gdb_byte
*index_ptr
, *index_end
;
9757 struct dwarf2_section_info
*index
;
9758 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
9759 struct dwp_hash_table
*htab
;
9762 index
= &dwp_file
->sections
.tu_index
;
9764 index
= &dwp_file
->sections
.cu_index
;
9766 if (dwarf2_section_empty_p (index
))
9768 dwarf2_read_section (objfile
, index
);
9770 index_ptr
= index
->buffer
;
9771 index_end
= index_ptr
+ index
->size
;
9773 version
= read_4_bytes (dbfd
, index_ptr
);
9776 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
9780 nr_units
= read_4_bytes (dbfd
, index_ptr
);
9782 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
9785 if (version
!= 1 && version
!= 2)
9787 error (_("Dwarf Error: unsupported DWP file version (%s)"
9789 pulongest (version
), dwp_file
->name
);
9791 if (nr_slots
!= (nr_slots
& -nr_slots
))
9793 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
9794 " is not power of 2 [in module %s]"),
9795 pulongest (nr_slots
), dwp_file
->name
);
9798 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
9799 htab
->version
= version
;
9800 htab
->nr_columns
= nr_columns
;
9801 htab
->nr_units
= nr_units
;
9802 htab
->nr_slots
= nr_slots
;
9803 htab
->hash_table
= index_ptr
;
9804 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
9806 /* Exit early if the table is empty. */
9807 if (nr_slots
== 0 || nr_units
== 0
9808 || (version
== 2 && nr_columns
== 0))
9810 /* All must be zero. */
9811 if (nr_slots
!= 0 || nr_units
!= 0
9812 || (version
== 2 && nr_columns
!= 0))
9814 complaint (&symfile_complaints
,
9815 _("Empty DWP but nr_slots,nr_units,nr_columns not"
9816 " all zero [in modules %s]"),
9824 htab
->section_pool
.v1
.indices
=
9825 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9826 /* It's harder to decide whether the section is too small in v1.
9827 V1 is deprecated anyway so we punt. */
9831 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9832 int *ids
= htab
->section_pool
.v2
.section_ids
;
9833 /* Reverse map for error checking. */
9834 int ids_seen
[DW_SECT_MAX
+ 1];
9839 error (_("Dwarf Error: bad DWP hash table, too few columns"
9840 " in section table [in module %s]"),
9843 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
9845 error (_("Dwarf Error: bad DWP hash table, too many columns"
9846 " in section table [in module %s]"),
9849 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
9850 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
9851 for (i
= 0; i
< nr_columns
; ++i
)
9853 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
9855 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
9857 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
9858 " in section table [in module %s]"),
9859 id
, dwp_file
->name
);
9861 if (ids_seen
[id
] != -1)
9863 error (_("Dwarf Error: bad DWP hash table, duplicate section"
9864 " id %d in section table [in module %s]"),
9865 id
, dwp_file
->name
);
9870 /* Must have exactly one info or types section. */
9871 if (((ids_seen
[DW_SECT_INFO
] != -1)
9872 + (ids_seen
[DW_SECT_TYPES
] != -1))
9875 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
9876 " DWO info/types section [in module %s]"),
9879 /* Must have an abbrev section. */
9880 if (ids_seen
[DW_SECT_ABBREV
] == -1)
9882 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
9883 " section [in module %s]"),
9886 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
9887 htab
->section_pool
.v2
.sizes
=
9888 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
9889 * nr_units
* nr_columns
);
9890 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
9891 * nr_units
* nr_columns
))
9894 error (_("Dwarf Error: DWP index section is corrupt (too small)"
9903 /* Update SECTIONS with the data from SECTP.
9905 This function is like the other "locate" section routines that are
9906 passed to bfd_map_over_sections, but in this context the sections to
9907 read comes from the DWP V1 hash table, not the full ELF section table.
9909 The result is non-zero for success, or zero if an error was found. */
9912 locate_v1_virtual_dwo_sections (asection
*sectp
,
9913 struct virtual_v1_dwo_sections
*sections
)
9915 const struct dwop_section_names
*names
= &dwop_section_names
;
9917 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
9919 /* There can be only one. */
9920 if (sections
->abbrev
.s
.section
!= NULL
)
9922 sections
->abbrev
.s
.section
= sectp
;
9923 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
9925 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
9926 || section_is_p (sectp
->name
, &names
->types_dwo
))
9928 /* There can be only one. */
9929 if (sections
->info_or_types
.s
.section
!= NULL
)
9931 sections
->info_or_types
.s
.section
= sectp
;
9932 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
9934 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
9936 /* There can be only one. */
9937 if (sections
->line
.s
.section
!= NULL
)
9939 sections
->line
.s
.section
= sectp
;
9940 sections
->line
.size
= bfd_get_section_size (sectp
);
9942 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
9944 /* There can be only one. */
9945 if (sections
->loc
.s
.section
!= NULL
)
9947 sections
->loc
.s
.section
= sectp
;
9948 sections
->loc
.size
= bfd_get_section_size (sectp
);
9950 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
9952 /* There can be only one. */
9953 if (sections
->macinfo
.s
.section
!= NULL
)
9955 sections
->macinfo
.s
.section
= sectp
;
9956 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
9958 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
9960 /* There can be only one. */
9961 if (sections
->macro
.s
.section
!= NULL
)
9963 sections
->macro
.s
.section
= sectp
;
9964 sections
->macro
.size
= bfd_get_section_size (sectp
);
9966 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
9968 /* There can be only one. */
9969 if (sections
->str_offsets
.s
.section
!= NULL
)
9971 sections
->str_offsets
.s
.section
= sectp
;
9972 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
9976 /* No other kind of section is valid. */
9983 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
9984 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
9985 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
9986 This is for DWP version 1 files. */
9988 static struct dwo_unit
*
9989 create_dwo_unit_in_dwp_v1 (struct dwp_file
*dwp_file
,
9990 uint32_t unit_index
,
9991 const char *comp_dir
,
9992 ULONGEST signature
, int is_debug_types
)
9994 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9995 const struct dwp_hash_table
*dwp_htab
=
9996 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9997 bfd
*dbfd
= dwp_file
->dbfd
;
9998 const char *kind
= is_debug_types
? "TU" : "CU";
9999 struct dwo_file
*dwo_file
;
10000 struct dwo_unit
*dwo_unit
;
10001 struct virtual_v1_dwo_sections sections
;
10002 void **dwo_file_slot
;
10003 char *virtual_dwo_name
;
10004 struct cleanup
*cleanups
;
10007 gdb_assert (dwp_file
->version
== 1);
10009 if (dwarf_read_debug
)
10011 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
10013 pulongest (unit_index
), hex_string (signature
),
10017 /* Fetch the sections of this DWO unit.
10018 Put a limit on the number of sections we look for so that bad data
10019 doesn't cause us to loop forever. */
10021 #define MAX_NR_V1_DWO_SECTIONS \
10022 (1 /* .debug_info or .debug_types */ \
10023 + 1 /* .debug_abbrev */ \
10024 + 1 /* .debug_line */ \
10025 + 1 /* .debug_loc */ \
10026 + 1 /* .debug_str_offsets */ \
10027 + 1 /* .debug_macro or .debug_macinfo */ \
10028 + 1 /* trailing zero */)
10030 memset (§ions
, 0, sizeof (sections
));
10031 cleanups
= make_cleanup (null_cleanup
, 0);
10033 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
10036 uint32_t section_nr
=
10037 read_4_bytes (dbfd
,
10038 dwp_htab
->section_pool
.v1
.indices
10039 + (unit_index
+ i
) * sizeof (uint32_t));
10041 if (section_nr
== 0)
10043 if (section_nr
>= dwp_file
->num_sections
)
10045 error (_("Dwarf Error: bad DWP hash table, section number too large"
10046 " [in module %s]"),
10050 sectp
= dwp_file
->elf_sections
[section_nr
];
10051 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
10053 error (_("Dwarf Error: bad DWP hash table, invalid section found"
10054 " [in module %s]"),
10060 || dwarf2_section_empty_p (§ions
.info_or_types
)
10061 || dwarf2_section_empty_p (§ions
.abbrev
))
10063 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
10064 " [in module %s]"),
10067 if (i
== MAX_NR_V1_DWO_SECTIONS
)
10069 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
10070 " [in module %s]"),
10074 /* It's easier for the rest of the code if we fake a struct dwo_file and
10075 have dwo_unit "live" in that. At least for now.
10077 The DWP file can be made up of a random collection of CUs and TUs.
10078 However, for each CU + set of TUs that came from the same original DWO
10079 file, we can combine them back into a virtual DWO file to save space
10080 (fewer struct dwo_file objects to allocate). Remember that for really
10081 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10084 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
10085 get_section_id (§ions
.abbrev
),
10086 get_section_id (§ions
.line
),
10087 get_section_id (§ions
.loc
),
10088 get_section_id (§ions
.str_offsets
));
10089 make_cleanup (xfree
, virtual_dwo_name
);
10090 /* Can we use an existing virtual DWO file? */
10091 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
10092 /* Create one if necessary. */
10093 if (*dwo_file_slot
== NULL
)
10095 if (dwarf_read_debug
)
10097 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10100 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10102 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
10104 strlen (virtual_dwo_name
));
10105 dwo_file
->comp_dir
= comp_dir
;
10106 dwo_file
->sections
.abbrev
= sections
.abbrev
;
10107 dwo_file
->sections
.line
= sections
.line
;
10108 dwo_file
->sections
.loc
= sections
.loc
;
10109 dwo_file
->sections
.macinfo
= sections
.macinfo
;
10110 dwo_file
->sections
.macro
= sections
.macro
;
10111 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
10112 /* The "str" section is global to the entire DWP file. */
10113 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10114 /* The info or types section is assigned below to dwo_unit,
10115 there's no need to record it in dwo_file.
10116 Also, we can't simply record type sections in dwo_file because
10117 we record a pointer into the vector in dwo_unit. As we collect more
10118 types we'll grow the vector and eventually have to reallocate space
10119 for it, invalidating all copies of pointers into the previous
10121 *dwo_file_slot
= dwo_file
;
10125 if (dwarf_read_debug
)
10127 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10130 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10132 do_cleanups (cleanups
);
10134 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10135 dwo_unit
->dwo_file
= dwo_file
;
10136 dwo_unit
->signature
= signature
;
10137 dwo_unit
->section
=
10138 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
10139 *dwo_unit
->section
= sections
.info_or_types
;
10140 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10145 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
10146 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
10147 piece within that section used by a TU/CU, return a virtual section
10148 of just that piece. */
10150 static struct dwarf2_section_info
10151 create_dwp_v2_section (struct dwarf2_section_info
*section
,
10152 bfd_size_type offset
, bfd_size_type size
)
10154 struct dwarf2_section_info result
;
10157 gdb_assert (section
!= NULL
);
10158 gdb_assert (!section
->is_virtual
);
10160 memset (&result
, 0, sizeof (result
));
10161 result
.s
.containing_section
= section
;
10162 result
.is_virtual
= 1;
10167 sectp
= get_section_bfd_section (section
);
10169 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
10170 bounds of the real section. This is a pretty-rare event, so just
10171 flag an error (easier) instead of a warning and trying to cope. */
10173 || offset
+ size
> bfd_get_section_size (sectp
))
10175 bfd
*abfd
= sectp
->owner
;
10177 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
10178 " in section %s [in module %s]"),
10179 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
10180 objfile_name (dwarf2_per_objfile
->objfile
));
10183 result
.virtual_offset
= offset
;
10184 result
.size
= size
;
10188 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10189 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10190 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10191 This is for DWP version 2 files. */
10193 static struct dwo_unit
*
10194 create_dwo_unit_in_dwp_v2 (struct dwp_file
*dwp_file
,
10195 uint32_t unit_index
,
10196 const char *comp_dir
,
10197 ULONGEST signature
, int is_debug_types
)
10199 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10200 const struct dwp_hash_table
*dwp_htab
=
10201 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10202 bfd
*dbfd
= dwp_file
->dbfd
;
10203 const char *kind
= is_debug_types
? "TU" : "CU";
10204 struct dwo_file
*dwo_file
;
10205 struct dwo_unit
*dwo_unit
;
10206 struct virtual_v2_dwo_sections sections
;
10207 void **dwo_file_slot
;
10208 char *virtual_dwo_name
;
10209 struct cleanup
*cleanups
;
10212 gdb_assert (dwp_file
->version
== 2);
10214 if (dwarf_read_debug
)
10216 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
10218 pulongest (unit_index
), hex_string (signature
),
10222 /* Fetch the section offsets of this DWO unit. */
10224 memset (§ions
, 0, sizeof (sections
));
10225 cleanups
= make_cleanup (null_cleanup
, 0);
10227 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
10229 uint32_t offset
= read_4_bytes (dbfd
,
10230 dwp_htab
->section_pool
.v2
.offsets
10231 + (((unit_index
- 1) * dwp_htab
->nr_columns
10233 * sizeof (uint32_t)));
10234 uint32_t size
= read_4_bytes (dbfd
,
10235 dwp_htab
->section_pool
.v2
.sizes
10236 + (((unit_index
- 1) * dwp_htab
->nr_columns
10238 * sizeof (uint32_t)));
10240 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
10243 case DW_SECT_TYPES
:
10244 sections
.info_or_types_offset
= offset
;
10245 sections
.info_or_types_size
= size
;
10247 case DW_SECT_ABBREV
:
10248 sections
.abbrev_offset
= offset
;
10249 sections
.abbrev_size
= size
;
10252 sections
.line_offset
= offset
;
10253 sections
.line_size
= size
;
10256 sections
.loc_offset
= offset
;
10257 sections
.loc_size
= size
;
10259 case DW_SECT_STR_OFFSETS
:
10260 sections
.str_offsets_offset
= offset
;
10261 sections
.str_offsets_size
= size
;
10263 case DW_SECT_MACINFO
:
10264 sections
.macinfo_offset
= offset
;
10265 sections
.macinfo_size
= size
;
10267 case DW_SECT_MACRO
:
10268 sections
.macro_offset
= offset
;
10269 sections
.macro_size
= size
;
10274 /* It's easier for the rest of the code if we fake a struct dwo_file and
10275 have dwo_unit "live" in that. At least for now.
10277 The DWP file can be made up of a random collection of CUs and TUs.
10278 However, for each CU + set of TUs that came from the same original DWO
10279 file, we can combine them back into a virtual DWO file to save space
10280 (fewer struct dwo_file objects to allocate). Remember that for really
10281 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10284 xstrprintf ("virtual-dwo/%ld-%ld-%ld-%ld",
10285 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
10286 (long) (sections
.line_size
? sections
.line_offset
: 0),
10287 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
10288 (long) (sections
.str_offsets_size
10289 ? sections
.str_offsets_offset
: 0));
10290 make_cleanup (xfree
, virtual_dwo_name
);
10291 /* Can we use an existing virtual DWO file? */
10292 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
10293 /* Create one if necessary. */
10294 if (*dwo_file_slot
== NULL
)
10296 if (dwarf_read_debug
)
10298 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10301 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10303 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
10305 strlen (virtual_dwo_name
));
10306 dwo_file
->comp_dir
= comp_dir
;
10307 dwo_file
->sections
.abbrev
=
10308 create_dwp_v2_section (&dwp_file
->sections
.abbrev
,
10309 sections
.abbrev_offset
, sections
.abbrev_size
);
10310 dwo_file
->sections
.line
=
10311 create_dwp_v2_section (&dwp_file
->sections
.line
,
10312 sections
.line_offset
, sections
.line_size
);
10313 dwo_file
->sections
.loc
=
10314 create_dwp_v2_section (&dwp_file
->sections
.loc
,
10315 sections
.loc_offset
, sections
.loc_size
);
10316 dwo_file
->sections
.macinfo
=
10317 create_dwp_v2_section (&dwp_file
->sections
.macinfo
,
10318 sections
.macinfo_offset
, sections
.macinfo_size
);
10319 dwo_file
->sections
.macro
=
10320 create_dwp_v2_section (&dwp_file
->sections
.macro
,
10321 sections
.macro_offset
, sections
.macro_size
);
10322 dwo_file
->sections
.str_offsets
=
10323 create_dwp_v2_section (&dwp_file
->sections
.str_offsets
,
10324 sections
.str_offsets_offset
,
10325 sections
.str_offsets_size
);
10326 /* The "str" section is global to the entire DWP file. */
10327 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10328 /* The info or types section is assigned below to dwo_unit,
10329 there's no need to record it in dwo_file.
10330 Also, we can't simply record type sections in dwo_file because
10331 we record a pointer into the vector in dwo_unit. As we collect more
10332 types we'll grow the vector and eventually have to reallocate space
10333 for it, invalidating all copies of pointers into the previous
10335 *dwo_file_slot
= dwo_file
;
10339 if (dwarf_read_debug
)
10341 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10344 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10346 do_cleanups (cleanups
);
10348 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10349 dwo_unit
->dwo_file
= dwo_file
;
10350 dwo_unit
->signature
= signature
;
10351 dwo_unit
->section
=
10352 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
10353 *dwo_unit
->section
= create_dwp_v2_section (is_debug_types
10354 ? &dwp_file
->sections
.types
10355 : &dwp_file
->sections
.info
,
10356 sections
.info_or_types_offset
,
10357 sections
.info_or_types_size
);
10358 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10363 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
10364 Returns NULL if the signature isn't found. */
10366 static struct dwo_unit
*
10367 lookup_dwo_unit_in_dwp (struct dwp_file
*dwp_file
, const char *comp_dir
,
10368 ULONGEST signature
, int is_debug_types
)
10370 const struct dwp_hash_table
*dwp_htab
=
10371 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10372 bfd
*dbfd
= dwp_file
->dbfd
;
10373 uint32_t mask
= dwp_htab
->nr_slots
- 1;
10374 uint32_t hash
= signature
& mask
;
10375 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
10378 struct dwo_unit find_dwo_cu
;
10380 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
10381 find_dwo_cu
.signature
= signature
;
10382 slot
= htab_find_slot (is_debug_types
10383 ? dwp_file
->loaded_tus
10384 : dwp_file
->loaded_cus
,
10385 &find_dwo_cu
, INSERT
);
10388 return (struct dwo_unit
*) *slot
;
10390 /* Use a for loop so that we don't loop forever on bad debug info. */
10391 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
10393 ULONGEST signature_in_table
;
10395 signature_in_table
=
10396 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
10397 if (signature_in_table
== signature
)
10399 uint32_t unit_index
=
10400 read_4_bytes (dbfd
,
10401 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
10403 if (dwp_file
->version
== 1)
10405 *slot
= create_dwo_unit_in_dwp_v1 (dwp_file
, unit_index
,
10406 comp_dir
, signature
,
10411 *slot
= create_dwo_unit_in_dwp_v2 (dwp_file
, unit_index
,
10412 comp_dir
, signature
,
10415 return (struct dwo_unit
*) *slot
;
10417 if (signature_in_table
== 0)
10419 hash
= (hash
+ hash2
) & mask
;
10422 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
10423 " [in module %s]"),
10427 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
10428 Open the file specified by FILE_NAME and hand it off to BFD for
10429 preliminary analysis. Return a newly initialized bfd *, which
10430 includes a canonicalized copy of FILE_NAME.
10431 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
10432 SEARCH_CWD is true if the current directory is to be searched.
10433 It will be searched before debug-file-directory.
10434 If successful, the file is added to the bfd include table of the
10435 objfile's bfd (see gdb_bfd_record_inclusion).
10436 If unable to find/open the file, return NULL.
10437 NOTE: This function is derived from symfile_bfd_open. */
10439 static gdb_bfd_ref_ptr
10440 try_open_dwop_file (const char *file_name
, int is_dwp
, int search_cwd
)
10443 char *absolute_name
;
10444 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
10445 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
10446 to debug_file_directory. */
10448 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
10452 if (*debug_file_directory
!= '\0')
10453 search_path
= concat (".", dirname_separator_string
,
10454 debug_file_directory
, (char *) NULL
);
10456 search_path
= xstrdup (".");
10459 search_path
= xstrdup (debug_file_directory
);
10461 flags
= OPF_RETURN_REALPATH
;
10463 flags
|= OPF_SEARCH_IN_PATH
;
10464 desc
= openp (search_path
, flags
, file_name
,
10465 O_RDONLY
| O_BINARY
, &absolute_name
);
10466 xfree (search_path
);
10470 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
, gnutarget
, desc
));
10471 xfree (absolute_name
);
10472 if (sym_bfd
== NULL
)
10474 bfd_set_cacheable (sym_bfd
.get (), 1);
10476 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
10479 /* Success. Record the bfd as having been included by the objfile's bfd.
10480 This is important because things like demangled_names_hash lives in the
10481 objfile's per_bfd space and may have references to things like symbol
10482 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
10483 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
10488 /* Try to open DWO file FILE_NAME.
10489 COMP_DIR is the DW_AT_comp_dir attribute.
10490 The result is the bfd handle of the file.
10491 If there is a problem finding or opening the file, return NULL.
10492 Upon success, the canonicalized path of the file is stored in the bfd,
10493 same as symfile_bfd_open. */
10495 static gdb_bfd_ref_ptr
10496 open_dwo_file (const char *file_name
, const char *comp_dir
)
10498 if (IS_ABSOLUTE_PATH (file_name
))
10499 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 0 /*search_cwd*/);
10501 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
10503 if (comp_dir
!= NULL
)
10505 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
10506 file_name
, (char *) NULL
);
10508 /* NOTE: If comp_dir is a relative path, this will also try the
10509 search path, which seems useful. */
10510 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (path_to_try
, 0 /*is_dwp*/,
10511 1 /*search_cwd*/));
10512 xfree (path_to_try
);
10517 /* That didn't work, try debug-file-directory, which, despite its name,
10518 is a list of paths. */
10520 if (*debug_file_directory
== '\0')
10523 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 1 /*search_cwd*/);
10526 /* This function is mapped across the sections and remembers the offset and
10527 size of each of the DWO debugging sections we are interested in. */
10530 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
10532 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
10533 const struct dwop_section_names
*names
= &dwop_section_names
;
10535 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10537 dwo_sections
->abbrev
.s
.section
= sectp
;
10538 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10540 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10542 dwo_sections
->info
.s
.section
= sectp
;
10543 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
10545 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10547 dwo_sections
->line
.s
.section
= sectp
;
10548 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
10550 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10552 dwo_sections
->loc
.s
.section
= sectp
;
10553 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
10555 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10557 dwo_sections
->macinfo
.s
.section
= sectp
;
10558 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10560 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10562 dwo_sections
->macro
.s
.section
= sectp
;
10563 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
10565 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
10567 dwo_sections
->str
.s
.section
= sectp
;
10568 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
10570 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10572 dwo_sections
->str_offsets
.s
.section
= sectp
;
10573 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10575 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10577 struct dwarf2_section_info type_section
;
10579 memset (&type_section
, 0, sizeof (type_section
));
10580 type_section
.s
.section
= sectp
;
10581 type_section
.size
= bfd_get_section_size (sectp
);
10582 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
10587 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
10588 by PER_CU. This is for the non-DWP case.
10589 The result is NULL if DWO_NAME can't be found. */
10591 static struct dwo_file
*
10592 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
10593 const char *dwo_name
, const char *comp_dir
)
10595 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10596 struct dwo_file
*dwo_file
;
10597 struct cleanup
*cleanups
;
10599 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwo_name
, comp_dir
));
10602 if (dwarf_read_debug
)
10603 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
10606 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10607 dwo_file
->dwo_name
= dwo_name
;
10608 dwo_file
->comp_dir
= comp_dir
;
10609 dwo_file
->dbfd
= dbfd
.release ();
10611 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
10613 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
10614 &dwo_file
->sections
);
10616 dwo_file
->cu
= create_dwo_cu (dwo_file
);
10618 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
10619 dwo_file
->sections
.types
);
10621 discard_cleanups (cleanups
);
10623 if (dwarf_read_debug
)
10624 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
10629 /* This function is mapped across the sections and remembers the offset and
10630 size of each of the DWP debugging sections common to version 1 and 2 that
10631 we are interested in. */
10634 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
10635 void *dwp_file_ptr
)
10637 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
10638 const struct dwop_section_names
*names
= &dwop_section_names
;
10639 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10641 /* Record the ELF section number for later lookup: this is what the
10642 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10643 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10644 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10646 /* Look for specific sections that we need. */
10647 if (section_is_p (sectp
->name
, &names
->str_dwo
))
10649 dwp_file
->sections
.str
.s
.section
= sectp
;
10650 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
10652 else if (section_is_p (sectp
->name
, &names
->cu_index
))
10654 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
10655 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
10657 else if (section_is_p (sectp
->name
, &names
->tu_index
))
10659 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
10660 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
10664 /* This function is mapped across the sections and remembers the offset and
10665 size of each of the DWP version 2 debugging sections that we are interested
10666 in. This is split into a separate function because we don't know if we
10667 have version 1 or 2 until we parse the cu_index/tu_index sections. */
10670 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
10672 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
10673 const struct dwop_section_names
*names
= &dwop_section_names
;
10674 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10676 /* Record the ELF section number for later lookup: this is what the
10677 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10678 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10679 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10681 /* Look for specific sections that we need. */
10682 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10684 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
10685 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
10687 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10689 dwp_file
->sections
.info
.s
.section
= sectp
;
10690 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
10692 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10694 dwp_file
->sections
.line
.s
.section
= sectp
;
10695 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
10697 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10699 dwp_file
->sections
.loc
.s
.section
= sectp
;
10700 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
10702 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10704 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
10705 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
10707 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10709 dwp_file
->sections
.macro
.s
.section
= sectp
;
10710 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
10712 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10714 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
10715 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
10717 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10719 dwp_file
->sections
.types
.s
.section
= sectp
;
10720 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
10724 /* Hash function for dwp_file loaded CUs/TUs. */
10727 hash_dwp_loaded_cutus (const void *item
)
10729 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10731 /* This drops the top 32 bits of the signature, but is ok for a hash. */
10732 return dwo_unit
->signature
;
10735 /* Equality function for dwp_file loaded CUs/TUs. */
10738 eq_dwp_loaded_cutus (const void *a
, const void *b
)
10740 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
10741 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
10743 return dua
->signature
== dub
->signature
;
10746 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
10749 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
10751 return htab_create_alloc_ex (3,
10752 hash_dwp_loaded_cutus
,
10753 eq_dwp_loaded_cutus
,
10755 &objfile
->objfile_obstack
,
10756 hashtab_obstack_allocate
,
10757 dummy_obstack_deallocate
);
10760 /* Try to open DWP file FILE_NAME.
10761 The result is the bfd handle of the file.
10762 If there is a problem finding or opening the file, return NULL.
10763 Upon success, the canonicalized path of the file is stored in the bfd,
10764 same as symfile_bfd_open. */
10766 static gdb_bfd_ref_ptr
10767 open_dwp_file (const char *file_name
)
10769 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (file_name
, 1 /*is_dwp*/,
10770 1 /*search_cwd*/));
10774 /* Work around upstream bug 15652.
10775 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
10776 [Whether that's a "bug" is debatable, but it is getting in our way.]
10777 We have no real idea where the dwp file is, because gdb's realpath-ing
10778 of the executable's path may have discarded the needed info.
10779 [IWBN if the dwp file name was recorded in the executable, akin to
10780 .gnu_debuglink, but that doesn't exist yet.]
10781 Strip the directory from FILE_NAME and search again. */
10782 if (*debug_file_directory
!= '\0')
10784 /* Don't implicitly search the current directory here.
10785 If the user wants to search "." to handle this case,
10786 it must be added to debug-file-directory. */
10787 return try_open_dwop_file (lbasename (file_name
), 1 /*is_dwp*/,
10794 /* Initialize the use of the DWP file for the current objfile.
10795 By convention the name of the DWP file is ${objfile}.dwp.
10796 The result is NULL if it can't be found. */
10798 static struct dwp_file
*
10799 open_and_init_dwp_file (void)
10801 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10802 struct dwp_file
*dwp_file
;
10804 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, 0);
10806 /* Try to find first .dwp for the binary file before any symbolic links
10809 /* If the objfile is a debug file, find the name of the real binary
10810 file and get the name of dwp file from there. */
10811 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
10813 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
10814 const char *backlink_basename
= lbasename (backlink
->original_name
);
10815 char *debug_dirname
= ldirname (objfile
->original_name
);
10817 make_cleanup (xfree
, debug_dirname
);
10818 dwp_name
= xstrprintf ("%s%s%s.dwp", debug_dirname
,
10819 SLASH_STRING
, backlink_basename
);
10822 dwp_name
= xstrprintf ("%s.dwp", objfile
->original_name
);
10823 make_cleanup (xfree
, dwp_name
);
10825 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwp_name
));
10827 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
10829 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
10830 dwp_name
= xstrprintf ("%s.dwp", objfile_name (objfile
));
10831 make_cleanup (xfree
, dwp_name
);
10832 dbfd
= open_dwp_file (dwp_name
);
10837 if (dwarf_read_debug
)
10838 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
);
10839 do_cleanups (cleanups
);
10842 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
10843 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
10844 dwp_file
->dbfd
= dbfd
.release ();
10845 do_cleanups (cleanups
);
10847 /* +1: section 0 is unused */
10848 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
10849 dwp_file
->elf_sections
=
10850 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
10851 dwp_file
->num_sections
, asection
*);
10853 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
10856 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
10858 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
10860 /* The DWP file version is stored in the hash table. Oh well. */
10861 if (dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
10863 /* Technically speaking, we should try to limp along, but this is
10864 pretty bizarre. We use pulongest here because that's the established
10865 portability solution (e.g, we cannot use %u for uint32_t). */
10866 error (_("Dwarf Error: DWP file CU version %s doesn't match"
10867 " TU version %s [in DWP file %s]"),
10868 pulongest (dwp_file
->cus
->version
),
10869 pulongest (dwp_file
->tus
->version
), dwp_name
);
10871 dwp_file
->version
= dwp_file
->cus
->version
;
10873 if (dwp_file
->version
== 2)
10874 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
10877 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
10878 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
10880 if (dwarf_read_debug
)
10882 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
10883 fprintf_unfiltered (gdb_stdlog
,
10884 " %s CUs, %s TUs\n",
10885 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
10886 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
10892 /* Wrapper around open_and_init_dwp_file, only open it once. */
10894 static struct dwp_file
*
10895 get_dwp_file (void)
10897 if (! dwarf2_per_objfile
->dwp_checked
)
10899 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file ();
10900 dwarf2_per_objfile
->dwp_checked
= 1;
10902 return dwarf2_per_objfile
->dwp_file
;
10905 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
10906 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
10907 or in the DWP file for the objfile, referenced by THIS_UNIT.
10908 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
10909 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
10911 This is called, for example, when wanting to read a variable with a
10912 complex location. Therefore we don't want to do file i/o for every call.
10913 Therefore we don't want to look for a DWO file on every call.
10914 Therefore we first see if we've already seen SIGNATURE in a DWP file,
10915 then we check if we've already seen DWO_NAME, and only THEN do we check
10918 The result is a pointer to the dwo_unit object or NULL if we didn't find it
10919 (dwo_id mismatch or couldn't find the DWO/DWP file). */
10921 static struct dwo_unit
*
10922 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
10923 const char *dwo_name
, const char *comp_dir
,
10924 ULONGEST signature
, int is_debug_types
)
10926 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10927 const char *kind
= is_debug_types
? "TU" : "CU";
10928 void **dwo_file_slot
;
10929 struct dwo_file
*dwo_file
;
10930 struct dwp_file
*dwp_file
;
10932 /* First see if there's a DWP file.
10933 If we have a DWP file but didn't find the DWO inside it, don't
10934 look for the original DWO file. It makes gdb behave differently
10935 depending on whether one is debugging in the build tree. */
10937 dwp_file
= get_dwp_file ();
10938 if (dwp_file
!= NULL
)
10940 const struct dwp_hash_table
*dwp_htab
=
10941 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10943 if (dwp_htab
!= NULL
)
10945 struct dwo_unit
*dwo_cutu
=
10946 lookup_dwo_unit_in_dwp (dwp_file
, comp_dir
,
10947 signature
, is_debug_types
);
10949 if (dwo_cutu
!= NULL
)
10951 if (dwarf_read_debug
)
10953 fprintf_unfiltered (gdb_stdlog
,
10954 "Virtual DWO %s %s found: @%s\n",
10955 kind
, hex_string (signature
),
10956 host_address_to_string (dwo_cutu
));
10964 /* No DWP file, look for the DWO file. */
10966 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
, comp_dir
);
10967 if (*dwo_file_slot
== NULL
)
10969 /* Read in the file and build a table of the CUs/TUs it contains. */
10970 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
10972 /* NOTE: This will be NULL if unable to open the file. */
10973 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10975 if (dwo_file
!= NULL
)
10977 struct dwo_unit
*dwo_cutu
= NULL
;
10979 if (is_debug_types
&& dwo_file
->tus
)
10981 struct dwo_unit find_dwo_cutu
;
10983 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
10984 find_dwo_cutu
.signature
= signature
;
10986 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
10988 else if (!is_debug_types
&& dwo_file
->cu
)
10990 if (signature
== dwo_file
->cu
->signature
)
10991 dwo_cutu
= dwo_file
->cu
;
10994 if (dwo_cutu
!= NULL
)
10996 if (dwarf_read_debug
)
10998 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
10999 kind
, dwo_name
, hex_string (signature
),
11000 host_address_to_string (dwo_cutu
));
11007 /* We didn't find it. This could mean a dwo_id mismatch, or
11008 someone deleted the DWO/DWP file, or the search path isn't set up
11009 correctly to find the file. */
11011 if (dwarf_read_debug
)
11013 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
11014 kind
, dwo_name
, hex_string (signature
));
11017 /* This is a warning and not a complaint because it can be caused by
11018 pilot error (e.g., user accidentally deleting the DWO). */
11020 /* Print the name of the DWP file if we looked there, helps the user
11021 better diagnose the problem. */
11022 char *dwp_text
= NULL
;
11023 struct cleanup
*cleanups
;
11025 if (dwp_file
!= NULL
)
11026 dwp_text
= xstrprintf (" [in DWP file %s]", lbasename (dwp_file
->name
));
11027 cleanups
= make_cleanup (xfree
, dwp_text
);
11029 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset 0x%x"
11030 " [in module %s]"),
11031 kind
, dwo_name
, hex_string (signature
),
11032 dwp_text
!= NULL
? dwp_text
: "",
11033 this_unit
->is_debug_types
? "TU" : "CU",
11034 this_unit
->offset
.sect_off
, objfile_name (objfile
));
11036 do_cleanups (cleanups
);
11041 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
11042 See lookup_dwo_cutu_unit for details. */
11044 static struct dwo_unit
*
11045 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
11046 const char *dwo_name
, const char *comp_dir
,
11047 ULONGEST signature
)
11049 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
11052 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
11053 See lookup_dwo_cutu_unit for details. */
11055 static struct dwo_unit
*
11056 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
11057 const char *dwo_name
, const char *comp_dir
)
11059 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
11062 /* Traversal function for queue_and_load_all_dwo_tus. */
11065 queue_and_load_dwo_tu (void **slot
, void *info
)
11067 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
11068 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
11069 ULONGEST signature
= dwo_unit
->signature
;
11070 struct signatured_type
*sig_type
=
11071 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
11073 if (sig_type
!= NULL
)
11075 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
11077 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
11078 a real dependency of PER_CU on SIG_TYPE. That is detected later
11079 while processing PER_CU. */
11080 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
11081 load_full_type_unit (sig_cu
);
11082 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
11088 /* Queue all TUs contained in the DWO of PER_CU to be read in.
11089 The DWO may have the only definition of the type, though it may not be
11090 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
11091 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
11094 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
11096 struct dwo_unit
*dwo_unit
;
11097 struct dwo_file
*dwo_file
;
11099 gdb_assert (!per_cu
->is_debug_types
);
11100 gdb_assert (get_dwp_file () == NULL
);
11101 gdb_assert (per_cu
->cu
!= NULL
);
11103 dwo_unit
= per_cu
->cu
->dwo_unit
;
11104 gdb_assert (dwo_unit
!= NULL
);
11106 dwo_file
= dwo_unit
->dwo_file
;
11107 if (dwo_file
->tus
!= NULL
)
11108 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
11111 /* Free all resources associated with DWO_FILE.
11112 Close the DWO file and munmap the sections.
11113 All memory should be on the objfile obstack. */
11116 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
11119 /* Note: dbfd is NULL for virtual DWO files. */
11120 gdb_bfd_unref (dwo_file
->dbfd
);
11122 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
11125 /* Wrapper for free_dwo_file for use in cleanups. */
11128 free_dwo_file_cleanup (void *arg
)
11130 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
11131 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11133 free_dwo_file (dwo_file
, objfile
);
11136 /* Traversal function for free_dwo_files. */
11139 free_dwo_file_from_slot (void **slot
, void *info
)
11141 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
11142 struct objfile
*objfile
= (struct objfile
*) info
;
11144 free_dwo_file (dwo_file
, objfile
);
11149 /* Free all resources associated with DWO_FILES. */
11152 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
11154 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
11157 /* Read in various DIEs. */
11159 /* qsort helper for inherit_abstract_dies. */
11162 unsigned_int_compar (const void *ap
, const void *bp
)
11164 unsigned int a
= *(unsigned int *) ap
;
11165 unsigned int b
= *(unsigned int *) bp
;
11167 return (a
> b
) - (b
> a
);
11170 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
11171 Inherit only the children of the DW_AT_abstract_origin DIE not being
11172 already referenced by DW_AT_abstract_origin from the children of the
11176 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
11178 struct die_info
*child_die
;
11179 unsigned die_children_count
;
11180 /* CU offsets which were referenced by children of the current DIE. */
11181 sect_offset
*offsets
;
11182 sect_offset
*offsets_end
, *offsetp
;
11183 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
11184 struct die_info
*origin_die
;
11185 /* Iterator of the ORIGIN_DIE children. */
11186 struct die_info
*origin_child_die
;
11187 struct cleanup
*cleanups
;
11188 struct attribute
*attr
;
11189 struct dwarf2_cu
*origin_cu
;
11190 struct pending
**origin_previous_list_in_scope
;
11192 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11196 /* Note that following die references may follow to a die in a
11200 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
11202 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
11204 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
11205 origin_cu
->list_in_scope
= cu
->list_in_scope
;
11207 if (die
->tag
!= origin_die
->tag
11208 && !(die
->tag
== DW_TAG_inlined_subroutine
11209 && origin_die
->tag
== DW_TAG_subprogram
))
11210 complaint (&symfile_complaints
,
11211 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
11212 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
11214 child_die
= die
->child
;
11215 die_children_count
= 0;
11216 while (child_die
&& child_die
->tag
)
11218 child_die
= sibling_die (child_die
);
11219 die_children_count
++;
11221 offsets
= XNEWVEC (sect_offset
, die_children_count
);
11222 cleanups
= make_cleanup (xfree
, offsets
);
11224 offsets_end
= offsets
;
11225 for (child_die
= die
->child
;
11226 child_die
&& child_die
->tag
;
11227 child_die
= sibling_die (child_die
))
11229 struct die_info
*child_origin_die
;
11230 struct dwarf2_cu
*child_origin_cu
;
11232 /* We are trying to process concrete instance entries:
11233 DW_TAG_GNU_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
11234 it's not relevant to our analysis here. i.e. detecting DIEs that are
11235 present in the abstract instance but not referenced in the concrete
11237 if (child_die
->tag
== DW_TAG_GNU_call_site
)
11240 /* For each CHILD_DIE, find the corresponding child of
11241 ORIGIN_DIE. If there is more than one layer of
11242 DW_AT_abstract_origin, follow them all; there shouldn't be,
11243 but GCC versions at least through 4.4 generate this (GCC PR
11245 child_origin_die
= child_die
;
11246 child_origin_cu
= cu
;
11249 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
11253 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
11257 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
11258 counterpart may exist. */
11259 if (child_origin_die
!= child_die
)
11261 if (child_die
->tag
!= child_origin_die
->tag
11262 && !(child_die
->tag
== DW_TAG_inlined_subroutine
11263 && child_origin_die
->tag
== DW_TAG_subprogram
))
11264 complaint (&symfile_complaints
,
11265 _("Child DIE 0x%x and its abstract origin 0x%x have "
11266 "different tags"), child_die
->offset
.sect_off
,
11267 child_origin_die
->offset
.sect_off
);
11268 if (child_origin_die
->parent
!= origin_die
)
11269 complaint (&symfile_complaints
,
11270 _("Child DIE 0x%x and its abstract origin 0x%x have "
11271 "different parents"), child_die
->offset
.sect_off
,
11272 child_origin_die
->offset
.sect_off
);
11274 *offsets_end
++ = child_origin_die
->offset
;
11277 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
11278 unsigned_int_compar
);
11279 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
11280 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
11281 complaint (&symfile_complaints
,
11282 _("Multiple children of DIE 0x%x refer "
11283 "to DIE 0x%x as their abstract origin"),
11284 die
->offset
.sect_off
, offsetp
->sect_off
);
11287 origin_child_die
= origin_die
->child
;
11288 while (origin_child_die
&& origin_child_die
->tag
)
11290 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
11291 while (offsetp
< offsets_end
11292 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
11294 if (offsetp
>= offsets_end
11295 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
11297 /* Found that ORIGIN_CHILD_DIE is really not referenced.
11298 Check whether we're already processing ORIGIN_CHILD_DIE.
11299 This can happen with mutually referenced abstract_origins.
11301 if (!origin_child_die
->in_process
)
11302 process_die (origin_child_die
, origin_cu
);
11304 origin_child_die
= sibling_die (origin_child_die
);
11306 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
11308 do_cleanups (cleanups
);
11312 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11314 struct objfile
*objfile
= cu
->objfile
;
11315 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11316 struct context_stack
*newobj
;
11319 struct die_info
*child_die
;
11320 struct attribute
*attr
, *call_line
, *call_file
;
11322 CORE_ADDR baseaddr
;
11323 struct block
*block
;
11324 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11325 VEC (symbolp
) *template_args
= NULL
;
11326 struct template_symbol
*templ_func
= NULL
;
11330 /* If we do not have call site information, we can't show the
11331 caller of this inlined function. That's too confusing, so
11332 only use the scope for local variables. */
11333 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
11334 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
11335 if (call_line
== NULL
|| call_file
== NULL
)
11337 read_lexical_block_scope (die
, cu
);
11342 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11344 name
= dwarf2_name (die
, cu
);
11346 /* Ignore functions with missing or empty names. These are actually
11347 illegal according to the DWARF standard. */
11350 complaint (&symfile_complaints
,
11351 _("missing name for subprogram DIE at %d"),
11352 die
->offset
.sect_off
);
11356 /* Ignore functions with missing or invalid low and high pc attributes. */
11357 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
11358 <= PC_BOUNDS_INVALID
)
11360 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
11361 if (!attr
|| !DW_UNSND (attr
))
11362 complaint (&symfile_complaints
,
11363 _("cannot get low and high bounds "
11364 "for subprogram DIE at %d"),
11365 die
->offset
.sect_off
);
11369 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11370 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11372 /* If we have any template arguments, then we must allocate a
11373 different sort of symbol. */
11374 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
11376 if (child_die
->tag
== DW_TAG_template_type_param
11377 || child_die
->tag
== DW_TAG_template_value_param
)
11379 templ_func
= allocate_template_symbol (objfile
);
11380 templ_func
->base
.is_cplus_template_function
= 1;
11385 newobj
= push_context (0, lowpc
);
11386 newobj
->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
11387 (struct symbol
*) templ_func
);
11389 /* If there is a location expression for DW_AT_frame_base, record
11391 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
11393 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
11395 /* If there is a location for the static link, record it. */
11396 newobj
->static_link
= NULL
;
11397 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
11400 newobj
->static_link
11401 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
11402 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
11405 cu
->list_in_scope
= &local_symbols
;
11407 if (die
->child
!= NULL
)
11409 child_die
= die
->child
;
11410 while (child_die
&& child_die
->tag
)
11412 if (child_die
->tag
== DW_TAG_template_type_param
11413 || child_die
->tag
== DW_TAG_template_value_param
)
11415 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
11418 VEC_safe_push (symbolp
, template_args
, arg
);
11421 process_die (child_die
, cu
);
11422 child_die
= sibling_die (child_die
);
11426 inherit_abstract_dies (die
, cu
);
11428 /* If we have a DW_AT_specification, we might need to import using
11429 directives from the context of the specification DIE. See the
11430 comment in determine_prefix. */
11431 if (cu
->language
== language_cplus
11432 && dwarf2_attr (die
, DW_AT_specification
, cu
))
11434 struct dwarf2_cu
*spec_cu
= cu
;
11435 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
11439 child_die
= spec_die
->child
;
11440 while (child_die
&& child_die
->tag
)
11442 if (child_die
->tag
== DW_TAG_imported_module
)
11443 process_die (child_die
, spec_cu
);
11444 child_die
= sibling_die (child_die
);
11447 /* In some cases, GCC generates specification DIEs that
11448 themselves contain DW_AT_specification attributes. */
11449 spec_die
= die_specification (spec_die
, &spec_cu
);
11453 newobj
= pop_context ();
11454 /* Make a block for the local symbols within. */
11455 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
11456 newobj
->static_link
, lowpc
, highpc
);
11458 /* For C++, set the block's scope. */
11459 if ((cu
->language
== language_cplus
11460 || cu
->language
== language_fortran
11461 || cu
->language
== language_d
11462 || cu
->language
== language_rust
)
11463 && cu
->processing_has_namespace_info
)
11464 block_set_scope (block
, determine_prefix (die
, cu
),
11465 &objfile
->objfile_obstack
);
11467 /* If we have address ranges, record them. */
11468 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11470 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
11472 /* Attach template arguments to function. */
11473 if (! VEC_empty (symbolp
, template_args
))
11475 gdb_assert (templ_func
!= NULL
);
11477 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
11478 templ_func
->template_arguments
11479 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
11480 templ_func
->n_template_arguments
);
11481 memcpy (templ_func
->template_arguments
,
11482 VEC_address (symbolp
, template_args
),
11483 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
11484 VEC_free (symbolp
, template_args
);
11487 /* In C++, we can have functions nested inside functions (e.g., when
11488 a function declares a class that has methods). This means that
11489 when we finish processing a function scope, we may need to go
11490 back to building a containing block's symbol lists. */
11491 local_symbols
= newobj
->locals
;
11492 local_using_directives
= newobj
->local_using_directives
;
11494 /* If we've finished processing a top-level function, subsequent
11495 symbols go in the file symbol list. */
11496 if (outermost_context_p ())
11497 cu
->list_in_scope
= &file_symbols
;
11500 /* Process all the DIES contained within a lexical block scope. Start
11501 a new scope, process the dies, and then close the scope. */
11504 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11506 struct objfile
*objfile
= cu
->objfile
;
11507 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11508 struct context_stack
*newobj
;
11509 CORE_ADDR lowpc
, highpc
;
11510 struct die_info
*child_die
;
11511 CORE_ADDR baseaddr
;
11513 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11515 /* Ignore blocks with missing or invalid low and high pc attributes. */
11516 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
11517 as multiple lexical blocks? Handling children in a sane way would
11518 be nasty. Might be easier to properly extend generic blocks to
11519 describe ranges. */
11520 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
11522 case PC_BOUNDS_NOT_PRESENT
:
11523 /* DW_TAG_lexical_block has no attributes, process its children as if
11524 there was no wrapping by that DW_TAG_lexical_block.
11525 GCC does no longer produces such DWARF since GCC r224161. */
11526 for (child_die
= die
->child
;
11527 child_die
!= NULL
&& child_die
->tag
;
11528 child_die
= sibling_die (child_die
))
11529 process_die (child_die
, cu
);
11531 case PC_BOUNDS_INVALID
:
11534 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11535 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11537 push_context (0, lowpc
);
11538 if (die
->child
!= NULL
)
11540 child_die
= die
->child
;
11541 while (child_die
&& child_die
->tag
)
11543 process_die (child_die
, cu
);
11544 child_die
= sibling_die (child_die
);
11547 inherit_abstract_dies (die
, cu
);
11548 newobj
= pop_context ();
11550 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
11552 struct block
*block
11553 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
11554 newobj
->start_addr
, highpc
);
11556 /* Note that recording ranges after traversing children, as we
11557 do here, means that recording a parent's ranges entails
11558 walking across all its children's ranges as they appear in
11559 the address map, which is quadratic behavior.
11561 It would be nicer to record the parent's ranges before
11562 traversing its children, simply overriding whatever you find
11563 there. But since we don't even decide whether to create a
11564 block until after we've traversed its children, that's hard
11566 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11568 local_symbols
= newobj
->locals
;
11569 local_using_directives
= newobj
->local_using_directives
;
11572 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
11575 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11577 struct objfile
*objfile
= cu
->objfile
;
11578 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11579 CORE_ADDR pc
, baseaddr
;
11580 struct attribute
*attr
;
11581 struct call_site
*call_site
, call_site_local
;
11584 struct die_info
*child_die
;
11586 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11588 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11591 complaint (&symfile_complaints
,
11592 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
11593 "DIE 0x%x [in module %s]"),
11594 die
->offset
.sect_off
, objfile_name (objfile
));
11597 pc
= attr_value_as_address (attr
) + baseaddr
;
11598 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
11600 if (cu
->call_site_htab
== NULL
)
11601 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
11602 NULL
, &objfile
->objfile_obstack
,
11603 hashtab_obstack_allocate
, NULL
);
11604 call_site_local
.pc
= pc
;
11605 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
11608 complaint (&symfile_complaints
,
11609 _("Duplicate PC %s for DW_TAG_GNU_call_site "
11610 "DIE 0x%x [in module %s]"),
11611 paddress (gdbarch
, pc
), die
->offset
.sect_off
,
11612 objfile_name (objfile
));
11616 /* Count parameters at the caller. */
11619 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11620 child_die
= sibling_die (child_die
))
11622 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11624 complaint (&symfile_complaints
,
11625 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
11626 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11627 child_die
->tag
, child_die
->offset
.sect_off
,
11628 objfile_name (objfile
));
11636 = ((struct call_site
*)
11637 obstack_alloc (&objfile
->objfile_obstack
,
11638 sizeof (*call_site
)
11639 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
11641 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
11642 call_site
->pc
= pc
;
11644 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
11646 struct die_info
*func_die
;
11648 /* Skip also over DW_TAG_inlined_subroutine. */
11649 for (func_die
= die
->parent
;
11650 func_die
&& func_die
->tag
!= DW_TAG_subprogram
11651 && func_die
->tag
!= DW_TAG_subroutine_type
;
11652 func_die
= func_die
->parent
);
11654 /* DW_AT_GNU_all_call_sites is a superset
11655 of DW_AT_GNU_all_tail_call_sites. */
11657 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
11658 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
11660 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
11661 not complete. But keep CALL_SITE for look ups via call_site_htab,
11662 both the initial caller containing the real return address PC and
11663 the final callee containing the current PC of a chain of tail
11664 calls do not need to have the tail call list complete. But any
11665 function candidate for a virtual tail call frame searched via
11666 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
11667 determined unambiguously. */
11671 struct type
*func_type
= NULL
;
11674 func_type
= get_die_type (func_die
, cu
);
11675 if (func_type
!= NULL
)
11677 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
11679 /* Enlist this call site to the function. */
11680 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
11681 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
11684 complaint (&symfile_complaints
,
11685 _("Cannot find function owning DW_TAG_GNU_call_site "
11686 "DIE 0x%x [in module %s]"),
11687 die
->offset
.sect_off
, objfile_name (objfile
));
11691 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
11693 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11694 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
11695 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
11696 /* Keep NULL DWARF_BLOCK. */;
11697 else if (attr_form_is_block (attr
))
11699 struct dwarf2_locexpr_baton
*dlbaton
;
11701 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
11702 dlbaton
->data
= DW_BLOCK (attr
)->data
;
11703 dlbaton
->size
= DW_BLOCK (attr
)->size
;
11704 dlbaton
->per_cu
= cu
->per_cu
;
11706 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
11708 else if (attr_form_is_ref (attr
))
11710 struct dwarf2_cu
*target_cu
= cu
;
11711 struct die_info
*target_die
;
11713 target_die
= follow_die_ref (die
, attr
, &target_cu
);
11714 gdb_assert (target_cu
->objfile
== objfile
);
11715 if (die_is_declaration (target_die
, target_cu
))
11717 const char *target_physname
;
11719 /* Prefer the mangled name; otherwise compute the demangled one. */
11720 target_physname
= dwarf2_string_attr (target_die
,
11721 DW_AT_linkage_name
,
11723 if (target_physname
== NULL
)
11724 target_physname
= dwarf2_string_attr (target_die
,
11725 DW_AT_MIPS_linkage_name
,
11727 if (target_physname
== NULL
)
11728 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
11729 if (target_physname
== NULL
)
11730 complaint (&symfile_complaints
,
11731 _("DW_AT_GNU_call_site_target target DIE has invalid "
11732 "physname, for referencing DIE 0x%x [in module %s]"),
11733 die
->offset
.sect_off
, objfile_name (objfile
));
11735 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
11741 /* DW_AT_entry_pc should be preferred. */
11742 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
11743 <= PC_BOUNDS_INVALID
)
11744 complaint (&symfile_complaints
,
11745 _("DW_AT_GNU_call_site_target target DIE has invalid "
11746 "low pc, for referencing DIE 0x%x [in module %s]"),
11747 die
->offset
.sect_off
, objfile_name (objfile
));
11750 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11751 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
11756 complaint (&symfile_complaints
,
11757 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
11758 "block nor reference, for DIE 0x%x [in module %s]"),
11759 die
->offset
.sect_off
, objfile_name (objfile
));
11761 call_site
->per_cu
= cu
->per_cu
;
11763 for (child_die
= die
->child
;
11764 child_die
&& child_die
->tag
;
11765 child_die
= sibling_die (child_die
))
11767 struct call_site_parameter
*parameter
;
11768 struct attribute
*loc
, *origin
;
11770 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11772 /* Already printed the complaint above. */
11776 gdb_assert (call_site
->parameter_count
< nparams
);
11777 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
11779 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
11780 specifies DW_TAG_formal_parameter. Value of the data assumed for the
11781 register is contained in DW_AT_GNU_call_site_value. */
11783 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
11784 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
11785 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
11787 sect_offset offset
;
11789 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
11790 offset
= dwarf2_get_ref_die_offset (origin
);
11791 if (!offset_in_cu_p (&cu
->header
, offset
))
11793 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
11794 binding can be done only inside one CU. Such referenced DIE
11795 therefore cannot be even moved to DW_TAG_partial_unit. */
11796 complaint (&symfile_complaints
,
11797 _("DW_AT_abstract_origin offset is not in CU for "
11798 "DW_TAG_GNU_call_site child DIE 0x%x "
11800 child_die
->offset
.sect_off
, objfile_name (objfile
));
11803 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
11804 - cu
->header
.offset
.sect_off
);
11806 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
11808 complaint (&symfile_complaints
,
11809 _("No DW_FORM_block* DW_AT_location for "
11810 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11811 child_die
->offset
.sect_off
, objfile_name (objfile
));
11816 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
11817 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
11818 if (parameter
->u
.dwarf_reg
!= -1)
11819 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
11820 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
11821 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
11822 ¶meter
->u
.fb_offset
))
11823 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
11826 complaint (&symfile_complaints
,
11827 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
11828 "for DW_FORM_block* DW_AT_location is supported for "
11829 "DW_TAG_GNU_call_site child DIE 0x%x "
11831 child_die
->offset
.sect_off
, objfile_name (objfile
));
11836 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
11837 if (!attr_form_is_block (attr
))
11839 complaint (&symfile_complaints
,
11840 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
11841 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11842 child_die
->offset
.sect_off
, objfile_name (objfile
));
11845 parameter
->value
= DW_BLOCK (attr
)->data
;
11846 parameter
->value_size
= DW_BLOCK (attr
)->size
;
11848 /* Parameters are not pre-cleared by memset above. */
11849 parameter
->data_value
= NULL
;
11850 parameter
->data_value_size
= 0;
11851 call_site
->parameter_count
++;
11853 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
11856 if (!attr_form_is_block (attr
))
11857 complaint (&symfile_complaints
,
11858 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
11859 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11860 child_die
->offset
.sect_off
, objfile_name (objfile
));
11863 parameter
->data_value
= DW_BLOCK (attr
)->data
;
11864 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
11870 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
11871 Return 1 if the attributes are present and valid, otherwise, return 0.
11872 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
11875 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
11876 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
11877 struct partial_symtab
*ranges_pst
)
11879 struct objfile
*objfile
= cu
->objfile
;
11880 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11881 struct comp_unit_head
*cu_header
= &cu
->header
;
11882 bfd
*obfd
= objfile
->obfd
;
11883 unsigned int addr_size
= cu_header
->addr_size
;
11884 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
11885 /* Base address selection entry. */
11888 unsigned int dummy
;
11889 const gdb_byte
*buffer
;
11892 CORE_ADDR high
= 0;
11893 CORE_ADDR baseaddr
;
11895 found_base
= cu
->base_known
;
11896 base
= cu
->base_address
;
11898 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
11899 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
11901 complaint (&symfile_complaints
,
11902 _("Offset %d out of bounds for DW_AT_ranges attribute"),
11906 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
11910 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11914 CORE_ADDR range_beginning
, range_end
;
11916 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
11917 buffer
+= addr_size
;
11918 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
11919 buffer
+= addr_size
;
11920 offset
+= 2 * addr_size
;
11922 /* An end of list marker is a pair of zero addresses. */
11923 if (range_beginning
== 0 && range_end
== 0)
11924 /* Found the end of list entry. */
11927 /* Each base address selection entry is a pair of 2 values.
11928 The first is the largest possible address, the second is
11929 the base address. Check for a base address here. */
11930 if ((range_beginning
& mask
) == mask
)
11932 /* If we found the largest possible address, then we already
11933 have the base address in range_end. */
11941 /* We have no valid base address for the ranges
11943 complaint (&symfile_complaints
,
11944 _("Invalid .debug_ranges data (no base address)"));
11948 if (range_beginning
> range_end
)
11950 /* Inverted range entries are invalid. */
11951 complaint (&symfile_complaints
,
11952 _("Invalid .debug_ranges data (inverted range)"));
11956 /* Empty range entries have no effect. */
11957 if (range_beginning
== range_end
)
11960 range_beginning
+= base
;
11963 /* A not-uncommon case of bad debug info.
11964 Don't pollute the addrmap with bad data. */
11965 if (range_beginning
+ baseaddr
== 0
11966 && !dwarf2_per_objfile
->has_section_at_zero
)
11968 complaint (&symfile_complaints
,
11969 _(".debug_ranges entry has start address of zero"
11970 " [in module %s]"), objfile_name (objfile
));
11974 if (ranges_pst
!= NULL
)
11979 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
11980 range_beginning
+ baseaddr
);
11981 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
11982 range_end
+ baseaddr
);
11983 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
11987 /* FIXME: This is recording everything as a low-high
11988 segment of consecutive addresses. We should have a
11989 data structure for discontiguous block ranges
11993 low
= range_beginning
;
11999 if (range_beginning
< low
)
12000 low
= range_beginning
;
12001 if (range_end
> high
)
12007 /* If the first entry is an end-of-list marker, the range
12008 describes an empty scope, i.e. no instructions. */
12014 *high_return
= high
;
12018 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
12019 definition for the return value. *LOWPC and *HIGHPC are set iff
12020 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
12022 static enum pc_bounds_kind
12023 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
12024 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
12025 struct partial_symtab
*pst
)
12027 struct attribute
*attr
;
12028 struct attribute
*attr_high
;
12030 CORE_ADDR high
= 0;
12031 enum pc_bounds_kind ret
;
12033 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12036 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12039 low
= attr_value_as_address (attr
);
12040 high
= attr_value_as_address (attr_high
);
12041 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12045 /* Found high w/o low attribute. */
12046 return PC_BOUNDS_INVALID
;
12048 /* Found consecutive range of addresses. */
12049 ret
= PC_BOUNDS_HIGH_LOW
;
12053 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12056 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12057 We take advantage of the fact that DW_AT_ranges does not appear
12058 in DW_TAG_compile_unit of DWO files. */
12059 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12060 unsigned int ranges_offset
= (DW_UNSND (attr
)
12061 + (need_ranges_base
12065 /* Value of the DW_AT_ranges attribute is the offset in the
12066 .debug_ranges section. */
12067 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
12068 return PC_BOUNDS_INVALID
;
12069 /* Found discontinuous range of addresses. */
12070 ret
= PC_BOUNDS_RANGES
;
12073 return PC_BOUNDS_NOT_PRESENT
;
12076 /* read_partial_die has also the strict LOW < HIGH requirement. */
12078 return PC_BOUNDS_INVALID
;
12080 /* When using the GNU linker, .gnu.linkonce. sections are used to
12081 eliminate duplicate copies of functions and vtables and such.
12082 The linker will arbitrarily choose one and discard the others.
12083 The AT_*_pc values for such functions refer to local labels in
12084 these sections. If the section from that file was discarded, the
12085 labels are not in the output, so the relocs get a value of 0.
12086 If this is a discarded function, mark the pc bounds as invalid,
12087 so that GDB will ignore it. */
12088 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12089 return PC_BOUNDS_INVALID
;
12097 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
12098 its low and high PC addresses. Do nothing if these addresses could not
12099 be determined. Otherwise, set LOWPC to the low address if it is smaller,
12100 and HIGHPC to the high address if greater than HIGHPC. */
12103 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
12104 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12105 struct dwarf2_cu
*cu
)
12107 CORE_ADDR low
, high
;
12108 struct die_info
*child
= die
->child
;
12110 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
12112 *lowpc
= std::min (*lowpc
, low
);
12113 *highpc
= std::max (*highpc
, high
);
12116 /* If the language does not allow nested subprograms (either inside
12117 subprograms or lexical blocks), we're done. */
12118 if (cu
->language
!= language_ada
)
12121 /* Check all the children of the given DIE. If it contains nested
12122 subprograms, then check their pc bounds. Likewise, we need to
12123 check lexical blocks as well, as they may also contain subprogram
12125 while (child
&& child
->tag
)
12127 if (child
->tag
== DW_TAG_subprogram
12128 || child
->tag
== DW_TAG_lexical_block
)
12129 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
12130 child
= sibling_die (child
);
12134 /* Get the low and high pc's represented by the scope DIE, and store
12135 them in *LOWPC and *HIGHPC. If the correct values can't be
12136 determined, set *LOWPC to -1 and *HIGHPC to 0. */
12139 get_scope_pc_bounds (struct die_info
*die
,
12140 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12141 struct dwarf2_cu
*cu
)
12143 CORE_ADDR best_low
= (CORE_ADDR
) -1;
12144 CORE_ADDR best_high
= (CORE_ADDR
) 0;
12145 CORE_ADDR current_low
, current_high
;
12147 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
12148 >= PC_BOUNDS_RANGES
)
12150 best_low
= current_low
;
12151 best_high
= current_high
;
12155 struct die_info
*child
= die
->child
;
12157 while (child
&& child
->tag
)
12159 switch (child
->tag
) {
12160 case DW_TAG_subprogram
:
12161 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
12163 case DW_TAG_namespace
:
12164 case DW_TAG_module
:
12165 /* FIXME: carlton/2004-01-16: Should we do this for
12166 DW_TAG_class_type/DW_TAG_structure_type, too? I think
12167 that current GCC's always emit the DIEs corresponding
12168 to definitions of methods of classes as children of a
12169 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
12170 the DIEs giving the declarations, which could be
12171 anywhere). But I don't see any reason why the
12172 standards says that they have to be there. */
12173 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
12175 if (current_low
!= ((CORE_ADDR
) -1))
12177 best_low
= std::min (best_low
, current_low
);
12178 best_high
= std::max (best_high
, current_high
);
12186 child
= sibling_die (child
);
12191 *highpc
= best_high
;
12194 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
12198 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
12199 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
12201 struct objfile
*objfile
= cu
->objfile
;
12202 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12203 struct attribute
*attr
;
12204 struct attribute
*attr_high
;
12206 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12209 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12212 CORE_ADDR low
= attr_value_as_address (attr
);
12213 CORE_ADDR high
= attr_value_as_address (attr_high
);
12215 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12218 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
12219 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
12220 record_block_range (block
, low
, high
- 1);
12224 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12227 bfd
*obfd
= objfile
->obfd
;
12228 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12229 We take advantage of the fact that DW_AT_ranges does not appear
12230 in DW_TAG_compile_unit of DWO files. */
12231 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12233 /* The value of the DW_AT_ranges attribute is the offset of the
12234 address range list in the .debug_ranges section. */
12235 unsigned long offset
= (DW_UNSND (attr
)
12236 + (need_ranges_base
? cu
->ranges_base
: 0));
12237 const gdb_byte
*buffer
;
12239 /* For some target architectures, but not others, the
12240 read_address function sign-extends the addresses it returns.
12241 To recognize base address selection entries, we need a
12243 unsigned int addr_size
= cu
->header
.addr_size
;
12244 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12246 /* The base address, to which the next pair is relative. Note
12247 that this 'base' is a DWARF concept: most entries in a range
12248 list are relative, to reduce the number of relocs against the
12249 debugging information. This is separate from this function's
12250 'baseaddr' argument, which GDB uses to relocate debugging
12251 information from a shared library based on the address at
12252 which the library was loaded. */
12253 CORE_ADDR base
= cu
->base_address
;
12254 int base_known
= cu
->base_known
;
12256 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
12257 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
12259 complaint (&symfile_complaints
,
12260 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
12264 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
12268 unsigned int bytes_read
;
12269 CORE_ADDR start
, end
;
12271 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12272 buffer
+= bytes_read
;
12273 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12274 buffer
+= bytes_read
;
12276 /* Did we find the end of the range list? */
12277 if (start
== 0 && end
== 0)
12280 /* Did we find a base address selection entry? */
12281 else if ((start
& base_select_mask
) == base_select_mask
)
12287 /* We found an ordinary address range. */
12292 complaint (&symfile_complaints
,
12293 _("Invalid .debug_ranges data "
12294 "(no base address)"));
12300 /* Inverted range entries are invalid. */
12301 complaint (&symfile_complaints
,
12302 _("Invalid .debug_ranges data "
12303 "(inverted range)"));
12307 /* Empty range entries have no effect. */
12311 start
+= base
+ baseaddr
;
12312 end
+= base
+ baseaddr
;
12314 /* A not-uncommon case of bad debug info.
12315 Don't pollute the addrmap with bad data. */
12316 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12318 complaint (&symfile_complaints
,
12319 _(".debug_ranges entry has start address of zero"
12320 " [in module %s]"), objfile_name (objfile
));
12324 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
12325 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
12326 record_block_range (block
, start
, end
- 1);
12332 /* Check whether the producer field indicates either of GCC < 4.6, or the
12333 Intel C/C++ compiler, and cache the result in CU. */
12336 check_producer (struct dwarf2_cu
*cu
)
12340 if (cu
->producer
== NULL
)
12342 /* For unknown compilers expect their behavior is DWARF version
12345 GCC started to support .debug_types sections by -gdwarf-4 since
12346 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
12347 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
12348 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
12349 interpreted incorrectly by GDB now - GCC PR debug/48229. */
12351 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
12353 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
12354 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
12356 else if (startswith (cu
->producer
, "Intel(R) C"))
12357 cu
->producer_is_icc
= 1;
12360 /* For other non-GCC compilers, expect their behavior is DWARF version
12364 cu
->checked_producer
= 1;
12367 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
12368 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
12369 during 4.6.0 experimental. */
12372 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
12374 if (!cu
->checked_producer
)
12375 check_producer (cu
);
12377 return cu
->producer_is_gxx_lt_4_6
;
12380 /* Return the default accessibility type if it is not overriden by
12381 DW_AT_accessibility. */
12383 static enum dwarf_access_attribute
12384 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
12386 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
12388 /* The default DWARF 2 accessibility for members is public, the default
12389 accessibility for inheritance is private. */
12391 if (die
->tag
!= DW_TAG_inheritance
)
12392 return DW_ACCESS_public
;
12394 return DW_ACCESS_private
;
12398 /* DWARF 3+ defines the default accessibility a different way. The same
12399 rules apply now for DW_TAG_inheritance as for the members and it only
12400 depends on the container kind. */
12402 if (die
->parent
->tag
== DW_TAG_class_type
)
12403 return DW_ACCESS_private
;
12405 return DW_ACCESS_public
;
12409 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
12410 offset. If the attribute was not found return 0, otherwise return
12411 1. If it was found but could not properly be handled, set *OFFSET
12415 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
12418 struct attribute
*attr
;
12420 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
12425 /* Note that we do not check for a section offset first here.
12426 This is because DW_AT_data_member_location is new in DWARF 4,
12427 so if we see it, we can assume that a constant form is really
12428 a constant and not a section offset. */
12429 if (attr_form_is_constant (attr
))
12430 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
12431 else if (attr_form_is_section_offset (attr
))
12432 dwarf2_complex_location_expr_complaint ();
12433 else if (attr_form_is_block (attr
))
12434 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
12436 dwarf2_complex_location_expr_complaint ();
12444 /* Add an aggregate field to the field list. */
12447 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
12448 struct dwarf2_cu
*cu
)
12450 struct objfile
*objfile
= cu
->objfile
;
12451 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12452 struct nextfield
*new_field
;
12453 struct attribute
*attr
;
12455 const char *fieldname
= "";
12457 /* Allocate a new field list entry and link it in. */
12458 new_field
= XNEW (struct nextfield
);
12459 make_cleanup (xfree
, new_field
);
12460 memset (new_field
, 0, sizeof (struct nextfield
));
12462 if (die
->tag
== DW_TAG_inheritance
)
12464 new_field
->next
= fip
->baseclasses
;
12465 fip
->baseclasses
= new_field
;
12469 new_field
->next
= fip
->fields
;
12470 fip
->fields
= new_field
;
12474 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
12476 new_field
->accessibility
= DW_UNSND (attr
);
12478 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
12479 if (new_field
->accessibility
!= DW_ACCESS_public
)
12480 fip
->non_public_fields
= 1;
12482 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
12484 new_field
->virtuality
= DW_UNSND (attr
);
12486 new_field
->virtuality
= DW_VIRTUALITY_none
;
12488 fp
= &new_field
->field
;
12490 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
12494 /* Data member other than a C++ static data member. */
12496 /* Get type of field. */
12497 fp
->type
= die_type (die
, cu
);
12499 SET_FIELD_BITPOS (*fp
, 0);
12501 /* Get bit size of field (zero if none). */
12502 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
12505 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
12509 FIELD_BITSIZE (*fp
) = 0;
12512 /* Get bit offset of field. */
12513 if (handle_data_member_location (die
, cu
, &offset
))
12514 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12515 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
12518 if (gdbarch_bits_big_endian (gdbarch
))
12520 /* For big endian bits, the DW_AT_bit_offset gives the
12521 additional bit offset from the MSB of the containing
12522 anonymous object to the MSB of the field. We don't
12523 have to do anything special since we don't need to
12524 know the size of the anonymous object. */
12525 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
12529 /* For little endian bits, compute the bit offset to the
12530 MSB of the anonymous object, subtract off the number of
12531 bits from the MSB of the field to the MSB of the
12532 object, and then subtract off the number of bits of
12533 the field itself. The result is the bit offset of
12534 the LSB of the field. */
12535 int anonymous_size
;
12536 int bit_offset
= DW_UNSND (attr
);
12538 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12541 /* The size of the anonymous object containing
12542 the bit field is explicit, so use the
12543 indicated size (in bytes). */
12544 anonymous_size
= DW_UNSND (attr
);
12548 /* The size of the anonymous object containing
12549 the bit field must be inferred from the type
12550 attribute of the data member containing the
12552 anonymous_size
= TYPE_LENGTH (fp
->type
);
12554 SET_FIELD_BITPOS (*fp
,
12555 (FIELD_BITPOS (*fp
)
12556 + anonymous_size
* bits_per_byte
12557 - bit_offset
- FIELD_BITSIZE (*fp
)));
12560 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
12562 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
12563 + dwarf2_get_attr_constant_value (attr
, 0)));
12565 /* Get name of field. */
12566 fieldname
= dwarf2_name (die
, cu
);
12567 if (fieldname
== NULL
)
12570 /* The name is already allocated along with this objfile, so we don't
12571 need to duplicate it for the type. */
12572 fp
->name
= fieldname
;
12574 /* Change accessibility for artificial fields (e.g. virtual table
12575 pointer or virtual base class pointer) to private. */
12576 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
12578 FIELD_ARTIFICIAL (*fp
) = 1;
12579 new_field
->accessibility
= DW_ACCESS_private
;
12580 fip
->non_public_fields
= 1;
12583 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
12585 /* C++ static member. */
12587 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
12588 is a declaration, but all versions of G++ as of this writing
12589 (so through at least 3.2.1) incorrectly generate
12590 DW_TAG_variable tags. */
12592 const char *physname
;
12594 /* Get name of field. */
12595 fieldname
= dwarf2_name (die
, cu
);
12596 if (fieldname
== NULL
)
12599 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12601 /* Only create a symbol if this is an external value.
12602 new_symbol checks this and puts the value in the global symbol
12603 table, which we want. If it is not external, new_symbol
12604 will try to put the value in cu->list_in_scope which is wrong. */
12605 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
12607 /* A static const member, not much different than an enum as far as
12608 we're concerned, except that we can support more types. */
12609 new_symbol (die
, NULL
, cu
);
12612 /* Get physical name. */
12613 physname
= dwarf2_physname (fieldname
, die
, cu
);
12615 /* The name is already allocated along with this objfile, so we don't
12616 need to duplicate it for the type. */
12617 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
12618 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12619 FIELD_NAME (*fp
) = fieldname
;
12621 else if (die
->tag
== DW_TAG_inheritance
)
12625 /* C++ base class field. */
12626 if (handle_data_member_location (die
, cu
, &offset
))
12627 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12628 FIELD_BITSIZE (*fp
) = 0;
12629 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12630 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
12631 fip
->nbaseclasses
++;
12635 /* Add a typedef defined in the scope of the FIP's class. */
12638 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
12639 struct dwarf2_cu
*cu
)
12641 struct typedef_field_list
*new_field
;
12642 struct typedef_field
*fp
;
12644 /* Allocate a new field list entry and link it in. */
12645 new_field
= XCNEW (struct typedef_field_list
);
12646 make_cleanup (xfree
, new_field
);
12648 gdb_assert (die
->tag
== DW_TAG_typedef
);
12650 fp
= &new_field
->field
;
12652 /* Get name of field. */
12653 fp
->name
= dwarf2_name (die
, cu
);
12654 if (fp
->name
== NULL
)
12657 fp
->type
= read_type_die (die
, cu
);
12659 new_field
->next
= fip
->typedef_field_list
;
12660 fip
->typedef_field_list
= new_field
;
12661 fip
->typedef_field_list_count
++;
12664 /* Create the vector of fields, and attach it to the type. */
12667 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
12668 struct dwarf2_cu
*cu
)
12670 int nfields
= fip
->nfields
;
12672 /* Record the field count, allocate space for the array of fields,
12673 and create blank accessibility bitfields if necessary. */
12674 TYPE_NFIELDS (type
) = nfields
;
12675 TYPE_FIELDS (type
) = (struct field
*)
12676 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
12677 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
12679 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
12681 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12683 TYPE_FIELD_PRIVATE_BITS (type
) =
12684 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12685 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
12687 TYPE_FIELD_PROTECTED_BITS (type
) =
12688 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12689 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
12691 TYPE_FIELD_IGNORE_BITS (type
) =
12692 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12693 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
12696 /* If the type has baseclasses, allocate and clear a bit vector for
12697 TYPE_FIELD_VIRTUAL_BITS. */
12698 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
12700 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
12701 unsigned char *pointer
;
12703 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12704 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
12705 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
12706 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
12707 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
12710 /* Copy the saved-up fields into the field vector. Start from the head of
12711 the list, adding to the tail of the field array, so that they end up in
12712 the same order in the array in which they were added to the list. */
12713 while (nfields
-- > 0)
12715 struct nextfield
*fieldp
;
12719 fieldp
= fip
->fields
;
12720 fip
->fields
= fieldp
->next
;
12724 fieldp
= fip
->baseclasses
;
12725 fip
->baseclasses
= fieldp
->next
;
12728 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
12729 switch (fieldp
->accessibility
)
12731 case DW_ACCESS_private
:
12732 if (cu
->language
!= language_ada
)
12733 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
12736 case DW_ACCESS_protected
:
12737 if (cu
->language
!= language_ada
)
12738 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
12741 case DW_ACCESS_public
:
12745 /* Unknown accessibility. Complain and treat it as public. */
12747 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
12748 fieldp
->accessibility
);
12752 if (nfields
< fip
->nbaseclasses
)
12754 switch (fieldp
->virtuality
)
12756 case DW_VIRTUALITY_virtual
:
12757 case DW_VIRTUALITY_pure_virtual
:
12758 if (cu
->language
== language_ada
)
12759 error (_("unexpected virtuality in component of Ada type"));
12760 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
12767 /* Return true if this member function is a constructor, false
12771 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
12773 const char *fieldname
;
12774 const char *type_name
;
12777 if (die
->parent
== NULL
)
12780 if (die
->parent
->tag
!= DW_TAG_structure_type
12781 && die
->parent
->tag
!= DW_TAG_union_type
12782 && die
->parent
->tag
!= DW_TAG_class_type
)
12785 fieldname
= dwarf2_name (die
, cu
);
12786 type_name
= dwarf2_name (die
->parent
, cu
);
12787 if (fieldname
== NULL
|| type_name
== NULL
)
12790 len
= strlen (fieldname
);
12791 return (strncmp (fieldname
, type_name
, len
) == 0
12792 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
12795 /* Add a member function to the proper fieldlist. */
12798 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
12799 struct type
*type
, struct dwarf2_cu
*cu
)
12801 struct objfile
*objfile
= cu
->objfile
;
12802 struct attribute
*attr
;
12803 struct fnfieldlist
*flp
;
12805 struct fn_field
*fnp
;
12806 const char *fieldname
;
12807 struct nextfnfield
*new_fnfield
;
12808 struct type
*this_type
;
12809 enum dwarf_access_attribute accessibility
;
12811 if (cu
->language
== language_ada
)
12812 error (_("unexpected member function in Ada type"));
12814 /* Get name of member function. */
12815 fieldname
= dwarf2_name (die
, cu
);
12816 if (fieldname
== NULL
)
12819 /* Look up member function name in fieldlist. */
12820 for (i
= 0; i
< fip
->nfnfields
; i
++)
12822 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
12826 /* Create new list element if necessary. */
12827 if (i
< fip
->nfnfields
)
12828 flp
= &fip
->fnfieldlists
[i
];
12831 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
12833 fip
->fnfieldlists
= (struct fnfieldlist
*)
12834 xrealloc (fip
->fnfieldlists
,
12835 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
12836 * sizeof (struct fnfieldlist
));
12837 if (fip
->nfnfields
== 0)
12838 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
12840 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
12841 flp
->name
= fieldname
;
12844 i
= fip
->nfnfields
++;
12847 /* Create a new member function field and chain it to the field list
12849 new_fnfield
= XNEW (struct nextfnfield
);
12850 make_cleanup (xfree
, new_fnfield
);
12851 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
12852 new_fnfield
->next
= flp
->head
;
12853 flp
->head
= new_fnfield
;
12856 /* Fill in the member function field info. */
12857 fnp
= &new_fnfield
->fnfield
;
12859 /* Delay processing of the physname until later. */
12860 if (cu
->language
== language_cplus
)
12862 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
12867 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
12868 fnp
->physname
= physname
? physname
: "";
12871 fnp
->type
= alloc_type (objfile
);
12872 this_type
= read_type_die (die
, cu
);
12873 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
12875 int nparams
= TYPE_NFIELDS (this_type
);
12877 /* TYPE is the domain of this method, and THIS_TYPE is the type
12878 of the method itself (TYPE_CODE_METHOD). */
12879 smash_to_method_type (fnp
->type
, type
,
12880 TYPE_TARGET_TYPE (this_type
),
12881 TYPE_FIELDS (this_type
),
12882 TYPE_NFIELDS (this_type
),
12883 TYPE_VARARGS (this_type
));
12885 /* Handle static member functions.
12886 Dwarf2 has no clean way to discern C++ static and non-static
12887 member functions. G++ helps GDB by marking the first
12888 parameter for non-static member functions (which is the this
12889 pointer) as artificial. We obtain this information from
12890 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
12891 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
12892 fnp
->voffset
= VOFFSET_STATIC
;
12895 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
12896 dwarf2_full_name (fieldname
, die
, cu
));
12898 /* Get fcontext from DW_AT_containing_type if present. */
12899 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
12900 fnp
->fcontext
= die_containing_type (die
, cu
);
12902 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
12903 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
12905 /* Get accessibility. */
12906 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
12908 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
12910 accessibility
= dwarf2_default_access_attribute (die
, cu
);
12911 switch (accessibility
)
12913 case DW_ACCESS_private
:
12914 fnp
->is_private
= 1;
12916 case DW_ACCESS_protected
:
12917 fnp
->is_protected
= 1;
12921 /* Check for artificial methods. */
12922 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
12923 if (attr
&& DW_UNSND (attr
) != 0)
12924 fnp
->is_artificial
= 1;
12926 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
12928 /* Get index in virtual function table if it is a virtual member
12929 function. For older versions of GCC, this is an offset in the
12930 appropriate virtual table, as specified by DW_AT_containing_type.
12931 For everyone else, it is an expression to be evaluated relative
12932 to the object address. */
12934 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
12937 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
12939 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
12941 /* Old-style GCC. */
12942 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
12944 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
12945 || (DW_BLOCK (attr
)->size
> 1
12946 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
12947 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
12949 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
12950 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
12951 dwarf2_complex_location_expr_complaint ();
12953 fnp
->voffset
/= cu
->header
.addr_size
;
12957 dwarf2_complex_location_expr_complaint ();
12959 if (!fnp
->fcontext
)
12961 /* If there is no `this' field and no DW_AT_containing_type,
12962 we cannot actually find a base class context for the
12964 if (TYPE_NFIELDS (this_type
) == 0
12965 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
12967 complaint (&symfile_complaints
,
12968 _("cannot determine context for virtual member "
12969 "function \"%s\" (offset %d)"),
12970 fieldname
, die
->offset
.sect_off
);
12975 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
12979 else if (attr_form_is_section_offset (attr
))
12981 dwarf2_complex_location_expr_complaint ();
12985 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
12991 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
12992 if (attr
&& DW_UNSND (attr
))
12994 /* GCC does this, as of 2008-08-25; PR debug/37237. */
12995 complaint (&symfile_complaints
,
12996 _("Member function \"%s\" (offset %d) is virtual "
12997 "but the vtable offset is not specified"),
12998 fieldname
, die
->offset
.sect_off
);
12999 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13000 TYPE_CPLUS_DYNAMIC (type
) = 1;
13005 /* Create the vector of member function fields, and attach it to the type. */
13008 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
13009 struct dwarf2_cu
*cu
)
13011 struct fnfieldlist
*flp
;
13014 if (cu
->language
== language_ada
)
13015 error (_("unexpected member functions in Ada type"));
13017 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13018 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
13019 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
13021 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
13023 struct nextfnfield
*nfp
= flp
->head
;
13024 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
13027 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
13028 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
13029 fn_flp
->fn_fields
= (struct fn_field
*)
13030 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
13031 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
13032 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
13035 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
13038 /* Returns non-zero if NAME is the name of a vtable member in CU's
13039 language, zero otherwise. */
13041 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
13043 static const char vptr
[] = "_vptr";
13044 static const char vtable
[] = "vtable";
13046 /* Look for the C++ form of the vtable. */
13047 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
13053 /* GCC outputs unnamed structures that are really pointers to member
13054 functions, with the ABI-specified layout. If TYPE describes
13055 such a structure, smash it into a member function type.
13057 GCC shouldn't do this; it should just output pointer to member DIEs.
13058 This is GCC PR debug/28767. */
13061 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
13063 struct type
*pfn_type
, *self_type
, *new_type
;
13065 /* Check for a structure with no name and two children. */
13066 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
13069 /* Check for __pfn and __delta members. */
13070 if (TYPE_FIELD_NAME (type
, 0) == NULL
13071 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
13072 || TYPE_FIELD_NAME (type
, 1) == NULL
13073 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
13076 /* Find the type of the method. */
13077 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
13078 if (pfn_type
== NULL
13079 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
13080 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
13083 /* Look for the "this" argument. */
13084 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
13085 if (TYPE_NFIELDS (pfn_type
) == 0
13086 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
13087 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
13090 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
13091 new_type
= alloc_type (objfile
);
13092 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
13093 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
13094 TYPE_VARARGS (pfn_type
));
13095 smash_to_methodptr_type (type
, new_type
);
13098 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
13102 producer_is_icc (struct dwarf2_cu
*cu
)
13104 if (!cu
->checked_producer
)
13105 check_producer (cu
);
13107 return cu
->producer_is_icc
;
13110 /* Called when we find the DIE that starts a structure or union scope
13111 (definition) to create a type for the structure or union. Fill in
13112 the type's name and general properties; the members will not be
13113 processed until process_structure_scope. A symbol table entry for
13114 the type will also not be done until process_structure_scope (assuming
13115 the type has a name).
13117 NOTE: we need to call these functions regardless of whether or not the
13118 DIE has a DW_AT_name attribute, since it might be an anonymous
13119 structure or union. This gets the type entered into our set of
13120 user defined types. */
13122 static struct type
*
13123 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13125 struct objfile
*objfile
= cu
->objfile
;
13127 struct attribute
*attr
;
13130 /* If the definition of this type lives in .debug_types, read that type.
13131 Don't follow DW_AT_specification though, that will take us back up
13132 the chain and we want to go down. */
13133 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
13136 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13138 /* The type's CU may not be the same as CU.
13139 Ensure TYPE is recorded with CU in die_type_hash. */
13140 return set_die_type (die
, type
, cu
);
13143 type
= alloc_type (objfile
);
13144 INIT_CPLUS_SPECIFIC (type
);
13146 name
= dwarf2_name (die
, cu
);
13149 if (cu
->language
== language_cplus
13150 || cu
->language
== language_d
13151 || cu
->language
== language_rust
)
13153 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
13155 /* dwarf2_full_name might have already finished building the DIE's
13156 type. If so, there is no need to continue. */
13157 if (get_die_type (die
, cu
) != NULL
)
13158 return get_die_type (die
, cu
);
13160 TYPE_TAG_NAME (type
) = full_name
;
13161 if (die
->tag
== DW_TAG_structure_type
13162 || die
->tag
== DW_TAG_class_type
)
13163 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13167 /* The name is already allocated along with this objfile, so
13168 we don't need to duplicate it for the type. */
13169 TYPE_TAG_NAME (type
) = name
;
13170 if (die
->tag
== DW_TAG_class_type
)
13171 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13175 if (die
->tag
== DW_TAG_structure_type
)
13177 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13179 else if (die
->tag
== DW_TAG_union_type
)
13181 TYPE_CODE (type
) = TYPE_CODE_UNION
;
13185 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13188 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
13189 TYPE_DECLARED_CLASS (type
) = 1;
13191 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13194 if (attr_form_is_constant (attr
))
13195 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13198 /* For the moment, dynamic type sizes are not supported
13199 by GDB's struct type. The actual size is determined
13200 on-demand when resolving the type of a given object,
13201 so set the type's length to zero for now. Otherwise,
13202 we record an expression as the length, and that expression
13203 could lead to a very large value, which could eventually
13204 lead to us trying to allocate that much memory when creating
13205 a value of that type. */
13206 TYPE_LENGTH (type
) = 0;
13211 TYPE_LENGTH (type
) = 0;
13214 if (producer_is_icc (cu
) && (TYPE_LENGTH (type
) == 0))
13216 /* ICC does not output the required DW_AT_declaration
13217 on incomplete types, but gives them a size of zero. */
13218 TYPE_STUB (type
) = 1;
13221 TYPE_STUB_SUPPORTED (type
) = 1;
13223 if (die_is_declaration (die
, cu
))
13224 TYPE_STUB (type
) = 1;
13225 else if (attr
== NULL
&& die
->child
== NULL
13226 && producer_is_realview (cu
->producer
))
13227 /* RealView does not output the required DW_AT_declaration
13228 on incomplete types. */
13229 TYPE_STUB (type
) = 1;
13231 /* We need to add the type field to the die immediately so we don't
13232 infinitely recurse when dealing with pointers to the structure
13233 type within the structure itself. */
13234 set_die_type (die
, type
, cu
);
13236 /* set_die_type should be already done. */
13237 set_descriptive_type (type
, die
, cu
);
13242 /* Finish creating a structure or union type, including filling in
13243 its members and creating a symbol for it. */
13246 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13248 struct objfile
*objfile
= cu
->objfile
;
13249 struct die_info
*child_die
;
13252 type
= get_die_type (die
, cu
);
13254 type
= read_structure_type (die
, cu
);
13256 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
13258 struct field_info fi
;
13259 VEC (symbolp
) *template_args
= NULL
;
13260 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
13262 memset (&fi
, 0, sizeof (struct field_info
));
13264 child_die
= die
->child
;
13266 while (child_die
&& child_die
->tag
)
13268 if (child_die
->tag
== DW_TAG_member
13269 || child_die
->tag
== DW_TAG_variable
)
13271 /* NOTE: carlton/2002-11-05: A C++ static data member
13272 should be a DW_TAG_member that is a declaration, but
13273 all versions of G++ as of this writing (so through at
13274 least 3.2.1) incorrectly generate DW_TAG_variable
13275 tags for them instead. */
13276 dwarf2_add_field (&fi
, child_die
, cu
);
13278 else if (child_die
->tag
== DW_TAG_subprogram
)
13280 /* Rust doesn't have member functions in the C++ sense.
13281 However, it does emit ordinary functions as children
13282 of a struct DIE. */
13283 if (cu
->language
== language_rust
)
13284 read_func_scope (child_die
, cu
);
13287 /* C++ member function. */
13288 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
13291 else if (child_die
->tag
== DW_TAG_inheritance
)
13293 /* C++ base class field. */
13294 dwarf2_add_field (&fi
, child_die
, cu
);
13296 else if (child_die
->tag
== DW_TAG_typedef
)
13297 dwarf2_add_typedef (&fi
, child_die
, cu
);
13298 else if (child_die
->tag
== DW_TAG_template_type_param
13299 || child_die
->tag
== DW_TAG_template_value_param
)
13301 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13304 VEC_safe_push (symbolp
, template_args
, arg
);
13307 child_die
= sibling_die (child_die
);
13310 /* Attach template arguments to type. */
13311 if (! VEC_empty (symbolp
, template_args
))
13313 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13314 TYPE_N_TEMPLATE_ARGUMENTS (type
)
13315 = VEC_length (symbolp
, template_args
);
13316 TYPE_TEMPLATE_ARGUMENTS (type
)
13317 = XOBNEWVEC (&objfile
->objfile_obstack
,
13319 TYPE_N_TEMPLATE_ARGUMENTS (type
));
13320 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
13321 VEC_address (symbolp
, template_args
),
13322 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
13323 * sizeof (struct symbol
*)));
13324 VEC_free (symbolp
, template_args
);
13327 /* Attach fields and member functions to the type. */
13329 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
13332 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
13334 /* Get the type which refers to the base class (possibly this
13335 class itself) which contains the vtable pointer for the current
13336 class from the DW_AT_containing_type attribute. This use of
13337 DW_AT_containing_type is a GNU extension. */
13339 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
13341 struct type
*t
= die_containing_type (die
, cu
);
13343 set_type_vptr_basetype (type
, t
);
13348 /* Our own class provides vtbl ptr. */
13349 for (i
= TYPE_NFIELDS (t
) - 1;
13350 i
>= TYPE_N_BASECLASSES (t
);
13353 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
13355 if (is_vtable_name (fieldname
, cu
))
13357 set_type_vptr_fieldno (type
, i
);
13362 /* Complain if virtual function table field not found. */
13363 if (i
< TYPE_N_BASECLASSES (t
))
13364 complaint (&symfile_complaints
,
13365 _("virtual function table pointer "
13366 "not found when defining class '%s'"),
13367 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
13372 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
13375 else if (cu
->producer
13376 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
13378 /* The IBM XLC compiler does not provide direct indication
13379 of the containing type, but the vtable pointer is
13380 always named __vfp. */
13384 for (i
= TYPE_NFIELDS (type
) - 1;
13385 i
>= TYPE_N_BASECLASSES (type
);
13388 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
13390 set_type_vptr_fieldno (type
, i
);
13391 set_type_vptr_basetype (type
, type
);
13398 /* Copy fi.typedef_field_list linked list elements content into the
13399 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
13400 if (fi
.typedef_field_list
)
13402 int i
= fi
.typedef_field_list_count
;
13404 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13405 TYPE_TYPEDEF_FIELD_ARRAY (type
)
13406 = ((struct typedef_field
*)
13407 TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
));
13408 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
13410 /* Reverse the list order to keep the debug info elements order. */
13413 struct typedef_field
*dest
, *src
;
13415 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
13416 src
= &fi
.typedef_field_list
->field
;
13417 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
13422 do_cleanups (back_to
);
13425 quirk_gcc_member_function_pointer (type
, objfile
);
13427 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
13428 snapshots) has been known to create a die giving a declaration
13429 for a class that has, as a child, a die giving a definition for a
13430 nested class. So we have to process our children even if the
13431 current die is a declaration. Normally, of course, a declaration
13432 won't have any children at all. */
13434 child_die
= die
->child
;
13436 while (child_die
!= NULL
&& child_die
->tag
)
13438 if (child_die
->tag
== DW_TAG_member
13439 || child_die
->tag
== DW_TAG_variable
13440 || child_die
->tag
== DW_TAG_inheritance
13441 || child_die
->tag
== DW_TAG_template_value_param
13442 || child_die
->tag
== DW_TAG_template_type_param
)
13447 process_die (child_die
, cu
);
13449 child_die
= sibling_die (child_die
);
13452 /* Do not consider external references. According to the DWARF standard,
13453 these DIEs are identified by the fact that they have no byte_size
13454 attribute, and a declaration attribute. */
13455 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
13456 || !die_is_declaration (die
, cu
))
13457 new_symbol (die
, type
, cu
);
13460 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
13461 update TYPE using some information only available in DIE's children. */
13464 update_enumeration_type_from_children (struct die_info
*die
,
13466 struct dwarf2_cu
*cu
)
13468 struct obstack obstack
;
13469 struct die_info
*child_die
;
13470 int unsigned_enum
= 1;
13473 struct cleanup
*old_chain
;
13475 obstack_init (&obstack
);
13476 old_chain
= make_cleanup_obstack_free (&obstack
);
13478 for (child_die
= die
->child
;
13479 child_die
!= NULL
&& child_die
->tag
;
13480 child_die
= sibling_die (child_die
))
13482 struct attribute
*attr
;
13484 const gdb_byte
*bytes
;
13485 struct dwarf2_locexpr_baton
*baton
;
13488 if (child_die
->tag
!= DW_TAG_enumerator
)
13491 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
13495 name
= dwarf2_name (child_die
, cu
);
13497 name
= "<anonymous enumerator>";
13499 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
13500 &value
, &bytes
, &baton
);
13506 else if ((mask
& value
) != 0)
13511 /* If we already know that the enum type is neither unsigned, nor
13512 a flag type, no need to look at the rest of the enumerates. */
13513 if (!unsigned_enum
&& !flag_enum
)
13518 TYPE_UNSIGNED (type
) = 1;
13520 TYPE_FLAG_ENUM (type
) = 1;
13522 do_cleanups (old_chain
);
13525 /* Given a DW_AT_enumeration_type die, set its type. We do not
13526 complete the type's fields yet, or create any symbols. */
13528 static struct type
*
13529 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13531 struct objfile
*objfile
= cu
->objfile
;
13533 struct attribute
*attr
;
13536 /* If the definition of this type lives in .debug_types, read that type.
13537 Don't follow DW_AT_specification though, that will take us back up
13538 the chain and we want to go down. */
13539 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
13542 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13544 /* The type's CU may not be the same as CU.
13545 Ensure TYPE is recorded with CU in die_type_hash. */
13546 return set_die_type (die
, type
, cu
);
13549 type
= alloc_type (objfile
);
13551 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
13552 name
= dwarf2_full_name (NULL
, die
, cu
);
13554 TYPE_TAG_NAME (type
) = name
;
13556 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13559 struct type
*underlying_type
= die_type (die
, cu
);
13561 TYPE_TARGET_TYPE (type
) = underlying_type
;
13564 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13567 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13571 TYPE_LENGTH (type
) = 0;
13574 /* The enumeration DIE can be incomplete. In Ada, any type can be
13575 declared as private in the package spec, and then defined only
13576 inside the package body. Such types are known as Taft Amendment
13577 Types. When another package uses such a type, an incomplete DIE
13578 may be generated by the compiler. */
13579 if (die_is_declaration (die
, cu
))
13580 TYPE_STUB (type
) = 1;
13582 /* Finish the creation of this type by using the enum's children.
13583 We must call this even when the underlying type has been provided
13584 so that we can determine if we're looking at a "flag" enum. */
13585 update_enumeration_type_from_children (die
, type
, cu
);
13587 /* If this type has an underlying type that is not a stub, then we
13588 may use its attributes. We always use the "unsigned" attribute
13589 in this situation, because ordinarily we guess whether the type
13590 is unsigned -- but the guess can be wrong and the underlying type
13591 can tell us the reality. However, we defer to a local size
13592 attribute if one exists, because this lets the compiler override
13593 the underlying type if needed. */
13594 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
13596 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
13597 if (TYPE_LENGTH (type
) == 0)
13598 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
13601 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
13603 return set_die_type (die
, type
, cu
);
13606 /* Given a pointer to a die which begins an enumeration, process all
13607 the dies that define the members of the enumeration, and create the
13608 symbol for the enumeration type.
13610 NOTE: We reverse the order of the element list. */
13613 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13615 struct type
*this_type
;
13617 this_type
= get_die_type (die
, cu
);
13618 if (this_type
== NULL
)
13619 this_type
= read_enumeration_type (die
, cu
);
13621 if (die
->child
!= NULL
)
13623 struct die_info
*child_die
;
13624 struct symbol
*sym
;
13625 struct field
*fields
= NULL
;
13626 int num_fields
= 0;
13629 child_die
= die
->child
;
13630 while (child_die
&& child_die
->tag
)
13632 if (child_die
->tag
!= DW_TAG_enumerator
)
13634 process_die (child_die
, cu
);
13638 name
= dwarf2_name (child_die
, cu
);
13641 sym
= new_symbol (child_die
, this_type
, cu
);
13643 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
13645 fields
= (struct field
*)
13647 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
13648 * sizeof (struct field
));
13651 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
13652 FIELD_TYPE (fields
[num_fields
]) = NULL
;
13653 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
13654 FIELD_BITSIZE (fields
[num_fields
]) = 0;
13660 child_die
= sibling_die (child_die
);
13665 TYPE_NFIELDS (this_type
) = num_fields
;
13666 TYPE_FIELDS (this_type
) = (struct field
*)
13667 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
13668 memcpy (TYPE_FIELDS (this_type
), fields
,
13669 sizeof (struct field
) * num_fields
);
13674 /* If we are reading an enum from a .debug_types unit, and the enum
13675 is a declaration, and the enum is not the signatured type in the
13676 unit, then we do not want to add a symbol for it. Adding a
13677 symbol would in some cases obscure the true definition of the
13678 enum, giving users an incomplete type when the definition is
13679 actually available. Note that we do not want to do this for all
13680 enums which are just declarations, because C++0x allows forward
13681 enum declarations. */
13682 if (cu
->per_cu
->is_debug_types
13683 && die_is_declaration (die
, cu
))
13685 struct signatured_type
*sig_type
;
13687 sig_type
= (struct signatured_type
*) cu
->per_cu
;
13688 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
13689 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
13693 new_symbol (die
, this_type
, cu
);
13696 /* Extract all information from a DW_TAG_array_type DIE and put it in
13697 the DIE's type field. For now, this only handles one dimensional
13700 static struct type
*
13701 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13703 struct objfile
*objfile
= cu
->objfile
;
13704 struct die_info
*child_die
;
13706 struct type
*element_type
, *range_type
, *index_type
;
13707 struct type
**range_types
= NULL
;
13708 struct attribute
*attr
;
13710 struct cleanup
*back_to
;
13712 unsigned int bit_stride
= 0;
13714 element_type
= die_type (die
, cu
);
13716 /* The die_type call above may have already set the type for this DIE. */
13717 type
= get_die_type (die
, cu
);
13721 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
13723 bit_stride
= DW_UNSND (attr
) * 8;
13725 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
13727 bit_stride
= DW_UNSND (attr
);
13729 /* Irix 6.2 native cc creates array types without children for
13730 arrays with unspecified length. */
13731 if (die
->child
== NULL
)
13733 index_type
= objfile_type (objfile
)->builtin_int
;
13734 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
13735 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
13737 return set_die_type (die
, type
, cu
);
13740 back_to
= make_cleanup (null_cleanup
, NULL
);
13741 child_die
= die
->child
;
13742 while (child_die
&& child_die
->tag
)
13744 if (child_die
->tag
== DW_TAG_subrange_type
)
13746 struct type
*child_type
= read_type_die (child_die
, cu
);
13748 if (child_type
!= NULL
)
13750 /* The range type was succesfully read. Save it for the
13751 array type creation. */
13752 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
13754 range_types
= (struct type
**)
13755 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
13756 * sizeof (struct type
*));
13758 make_cleanup (free_current_contents
, &range_types
);
13760 range_types
[ndim
++] = child_type
;
13763 child_die
= sibling_die (child_die
);
13766 /* Dwarf2 dimensions are output from left to right, create the
13767 necessary array types in backwards order. */
13769 type
= element_type
;
13771 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
13776 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
13782 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
13786 /* Understand Dwarf2 support for vector types (like they occur on
13787 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
13788 array type. This is not part of the Dwarf2/3 standard yet, but a
13789 custom vendor extension. The main difference between a regular
13790 array and the vector variant is that vectors are passed by value
13792 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
13794 make_vector_type (type
);
13796 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
13797 implementation may choose to implement triple vectors using this
13799 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13802 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
13803 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13805 complaint (&symfile_complaints
,
13806 _("DW_AT_byte_size for array type smaller "
13807 "than the total size of elements"));
13810 name
= dwarf2_name (die
, cu
);
13812 TYPE_NAME (type
) = name
;
13814 /* Install the type in the die. */
13815 set_die_type (die
, type
, cu
);
13817 /* set_die_type should be already done. */
13818 set_descriptive_type (type
, die
, cu
);
13820 do_cleanups (back_to
);
13825 static enum dwarf_array_dim_ordering
13826 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
13828 struct attribute
*attr
;
13830 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
13833 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
13835 /* GNU F77 is a special case, as at 08/2004 array type info is the
13836 opposite order to the dwarf2 specification, but data is still
13837 laid out as per normal fortran.
13839 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
13840 version checking. */
13842 if (cu
->language
== language_fortran
13843 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
13845 return DW_ORD_row_major
;
13848 switch (cu
->language_defn
->la_array_ordering
)
13850 case array_column_major
:
13851 return DW_ORD_col_major
;
13852 case array_row_major
:
13854 return DW_ORD_row_major
;
13858 /* Extract all information from a DW_TAG_set_type DIE and put it in
13859 the DIE's type field. */
13861 static struct type
*
13862 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13864 struct type
*domain_type
, *set_type
;
13865 struct attribute
*attr
;
13867 domain_type
= die_type (die
, cu
);
13869 /* The die_type call above may have already set the type for this DIE. */
13870 set_type
= get_die_type (die
, cu
);
13874 set_type
= create_set_type (NULL
, domain_type
);
13876 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13878 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
13880 return set_die_type (die
, set_type
, cu
);
13883 /* A helper for read_common_block that creates a locexpr baton.
13884 SYM is the symbol which we are marking as computed.
13885 COMMON_DIE is the DIE for the common block.
13886 COMMON_LOC is the location expression attribute for the common
13888 MEMBER_LOC is the location expression attribute for the particular
13889 member of the common block that we are processing.
13890 CU is the CU from which the above come. */
13893 mark_common_block_symbol_computed (struct symbol
*sym
,
13894 struct die_info
*common_die
,
13895 struct attribute
*common_loc
,
13896 struct attribute
*member_loc
,
13897 struct dwarf2_cu
*cu
)
13899 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13900 struct dwarf2_locexpr_baton
*baton
;
13902 unsigned int cu_off
;
13903 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
13904 LONGEST offset
= 0;
13906 gdb_assert (common_loc
&& member_loc
);
13907 gdb_assert (attr_form_is_block (common_loc
));
13908 gdb_assert (attr_form_is_block (member_loc
)
13909 || attr_form_is_constant (member_loc
));
13911 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13912 baton
->per_cu
= cu
->per_cu
;
13913 gdb_assert (baton
->per_cu
);
13915 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
13917 if (attr_form_is_constant (member_loc
))
13919 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
13920 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
13923 baton
->size
+= DW_BLOCK (member_loc
)->size
;
13925 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
13928 *ptr
++ = DW_OP_call4
;
13929 cu_off
= common_die
->offset
.sect_off
- cu
->per_cu
->offset
.sect_off
;
13930 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
13933 if (attr_form_is_constant (member_loc
))
13935 *ptr
++ = DW_OP_addr
;
13936 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
13937 ptr
+= cu
->header
.addr_size
;
13941 /* We have to copy the data here, because DW_OP_call4 will only
13942 use a DW_AT_location attribute. */
13943 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
13944 ptr
+= DW_BLOCK (member_loc
)->size
;
13947 *ptr
++ = DW_OP_plus
;
13948 gdb_assert (ptr
- baton
->data
== baton
->size
);
13950 SYMBOL_LOCATION_BATON (sym
) = baton
;
13951 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
13954 /* Create appropriate locally-scoped variables for all the
13955 DW_TAG_common_block entries. Also create a struct common_block
13956 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
13957 is used to sepate the common blocks name namespace from regular
13961 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
13963 struct attribute
*attr
;
13965 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13968 /* Support the .debug_loc offsets. */
13969 if (attr_form_is_block (attr
))
13973 else if (attr_form_is_section_offset (attr
))
13975 dwarf2_complex_location_expr_complaint ();
13980 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
13981 "common block member");
13986 if (die
->child
!= NULL
)
13988 struct objfile
*objfile
= cu
->objfile
;
13989 struct die_info
*child_die
;
13990 size_t n_entries
= 0, size
;
13991 struct common_block
*common_block
;
13992 struct symbol
*sym
;
13994 for (child_die
= die
->child
;
13995 child_die
&& child_die
->tag
;
13996 child_die
= sibling_die (child_die
))
13999 size
= (sizeof (struct common_block
)
14000 + (n_entries
- 1) * sizeof (struct symbol
*));
14002 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
14004 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
14005 common_block
->n_entries
= 0;
14007 for (child_die
= die
->child
;
14008 child_die
&& child_die
->tag
;
14009 child_die
= sibling_die (child_die
))
14011 /* Create the symbol in the DW_TAG_common_block block in the current
14013 sym
= new_symbol (child_die
, NULL
, cu
);
14016 struct attribute
*member_loc
;
14018 common_block
->contents
[common_block
->n_entries
++] = sym
;
14020 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
14024 /* GDB has handled this for a long time, but it is
14025 not specified by DWARF. It seems to have been
14026 emitted by gfortran at least as recently as:
14027 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
14028 complaint (&symfile_complaints
,
14029 _("Variable in common block has "
14030 "DW_AT_data_member_location "
14031 "- DIE at 0x%x [in module %s]"),
14032 child_die
->offset
.sect_off
,
14033 objfile_name (cu
->objfile
));
14035 if (attr_form_is_section_offset (member_loc
))
14036 dwarf2_complex_location_expr_complaint ();
14037 else if (attr_form_is_constant (member_loc
)
14038 || attr_form_is_block (member_loc
))
14041 mark_common_block_symbol_computed (sym
, die
, attr
,
14045 dwarf2_complex_location_expr_complaint ();
14050 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
14051 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
14055 /* Create a type for a C++ namespace. */
14057 static struct type
*
14058 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14060 struct objfile
*objfile
= cu
->objfile
;
14061 const char *previous_prefix
, *name
;
14065 /* For extensions, reuse the type of the original namespace. */
14066 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
14068 struct die_info
*ext_die
;
14069 struct dwarf2_cu
*ext_cu
= cu
;
14071 ext_die
= dwarf2_extension (die
, &ext_cu
);
14072 type
= read_type_die (ext_die
, ext_cu
);
14074 /* EXT_CU may not be the same as CU.
14075 Ensure TYPE is recorded with CU in die_type_hash. */
14076 return set_die_type (die
, type
, cu
);
14079 name
= namespace_name (die
, &is_anonymous
, cu
);
14081 /* Now build the name of the current namespace. */
14083 previous_prefix
= determine_prefix (die
, cu
);
14084 if (previous_prefix
[0] != '\0')
14085 name
= typename_concat (&objfile
->objfile_obstack
,
14086 previous_prefix
, name
, 0, cu
);
14088 /* Create the type. */
14089 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
14090 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14092 return set_die_type (die
, type
, cu
);
14095 /* Read a namespace scope. */
14098 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
14100 struct objfile
*objfile
= cu
->objfile
;
14103 /* Add a symbol associated to this if we haven't seen the namespace
14104 before. Also, add a using directive if it's an anonymous
14107 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
14111 type
= read_type_die (die
, cu
);
14112 new_symbol (die
, type
, cu
);
14114 namespace_name (die
, &is_anonymous
, cu
);
14117 const char *previous_prefix
= determine_prefix (die
, cu
);
14119 add_using_directive (using_directives (cu
->language
),
14120 previous_prefix
, TYPE_NAME (type
), NULL
,
14121 NULL
, NULL
, 0, &objfile
->objfile_obstack
);
14125 if (die
->child
!= NULL
)
14127 struct die_info
*child_die
= die
->child
;
14129 while (child_die
&& child_die
->tag
)
14131 process_die (child_die
, cu
);
14132 child_die
= sibling_die (child_die
);
14137 /* Read a Fortran module as type. This DIE can be only a declaration used for
14138 imported module. Still we need that type as local Fortran "use ... only"
14139 declaration imports depend on the created type in determine_prefix. */
14141 static struct type
*
14142 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14144 struct objfile
*objfile
= cu
->objfile
;
14145 const char *module_name
;
14148 module_name
= dwarf2_name (die
, cu
);
14150 complaint (&symfile_complaints
,
14151 _("DW_TAG_module has no name, offset 0x%x"),
14152 die
->offset
.sect_off
);
14153 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
14155 /* determine_prefix uses TYPE_TAG_NAME. */
14156 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14158 return set_die_type (die
, type
, cu
);
14161 /* Read a Fortran module. */
14164 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
14166 struct die_info
*child_die
= die
->child
;
14169 type
= read_type_die (die
, cu
);
14170 new_symbol (die
, type
, cu
);
14172 while (child_die
&& child_die
->tag
)
14174 process_die (child_die
, cu
);
14175 child_die
= sibling_die (child_die
);
14179 /* Return the name of the namespace represented by DIE. Set
14180 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
14183 static const char *
14184 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
14186 struct die_info
*current_die
;
14187 const char *name
= NULL
;
14189 /* Loop through the extensions until we find a name. */
14191 for (current_die
= die
;
14192 current_die
!= NULL
;
14193 current_die
= dwarf2_extension (die
, &cu
))
14195 /* We don't use dwarf2_name here so that we can detect the absence
14196 of a name -> anonymous namespace. */
14197 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
14203 /* Is it an anonymous namespace? */
14205 *is_anonymous
= (name
== NULL
);
14207 name
= CP_ANONYMOUS_NAMESPACE_STR
;
14212 /* Extract all information from a DW_TAG_pointer_type DIE and add to
14213 the user defined type vector. */
14215 static struct type
*
14216 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14218 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
14219 struct comp_unit_head
*cu_header
= &cu
->header
;
14221 struct attribute
*attr_byte_size
;
14222 struct attribute
*attr_address_class
;
14223 int byte_size
, addr_class
;
14224 struct type
*target_type
;
14226 target_type
= die_type (die
, cu
);
14228 /* The die_type call above may have already set the type for this DIE. */
14229 type
= get_die_type (die
, cu
);
14233 type
= lookup_pointer_type (target_type
);
14235 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14236 if (attr_byte_size
)
14237 byte_size
= DW_UNSND (attr_byte_size
);
14239 byte_size
= cu_header
->addr_size
;
14241 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
14242 if (attr_address_class
)
14243 addr_class
= DW_UNSND (attr_address_class
);
14245 addr_class
= DW_ADDR_none
;
14247 /* If the pointer size or address class is different than the
14248 default, create a type variant marked as such and set the
14249 length accordingly. */
14250 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
14252 if (gdbarch_address_class_type_flags_p (gdbarch
))
14256 type_flags
= gdbarch_address_class_type_flags
14257 (gdbarch
, byte_size
, addr_class
);
14258 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
14260 type
= make_type_with_address_space (type
, type_flags
);
14262 else if (TYPE_LENGTH (type
) != byte_size
)
14264 complaint (&symfile_complaints
,
14265 _("invalid pointer size %d"), byte_size
);
14269 /* Should we also complain about unhandled address classes? */
14273 TYPE_LENGTH (type
) = byte_size
;
14274 return set_die_type (die
, type
, cu
);
14277 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
14278 the user defined type vector. */
14280 static struct type
*
14281 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14284 struct type
*to_type
;
14285 struct type
*domain
;
14287 to_type
= die_type (die
, cu
);
14288 domain
= die_containing_type (die
, cu
);
14290 /* The calls above may have already set the type for this DIE. */
14291 type
= get_die_type (die
, cu
);
14295 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
14296 type
= lookup_methodptr_type (to_type
);
14297 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
14299 struct type
*new_type
= alloc_type (cu
->objfile
);
14301 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
14302 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
14303 TYPE_VARARGS (to_type
));
14304 type
= lookup_methodptr_type (new_type
);
14307 type
= lookup_memberptr_type (to_type
, domain
);
14309 return set_die_type (die
, type
, cu
);
14312 /* Extract all information from a DW_TAG_reference_type DIE and add to
14313 the user defined type vector. */
14315 static struct type
*
14316 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14318 struct comp_unit_head
*cu_header
= &cu
->header
;
14319 struct type
*type
, *target_type
;
14320 struct attribute
*attr
;
14322 target_type
= die_type (die
, cu
);
14324 /* The die_type call above may have already set the type for this DIE. */
14325 type
= get_die_type (die
, cu
);
14329 type
= lookup_reference_type (target_type
);
14330 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14333 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14337 TYPE_LENGTH (type
) = cu_header
->addr_size
;
14339 return set_die_type (die
, type
, cu
);
14342 /* Add the given cv-qualifiers to the element type of the array. GCC
14343 outputs DWARF type qualifiers that apply to an array, not the
14344 element type. But GDB relies on the array element type to carry
14345 the cv-qualifiers. This mimics section 6.7.3 of the C99
14348 static struct type
*
14349 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
14350 struct type
*base_type
, int cnst
, int voltl
)
14352 struct type
*el_type
, *inner_array
;
14354 base_type
= copy_type (base_type
);
14355 inner_array
= base_type
;
14357 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
14359 TYPE_TARGET_TYPE (inner_array
) =
14360 copy_type (TYPE_TARGET_TYPE (inner_array
));
14361 inner_array
= TYPE_TARGET_TYPE (inner_array
);
14364 el_type
= TYPE_TARGET_TYPE (inner_array
);
14365 cnst
|= TYPE_CONST (el_type
);
14366 voltl
|= TYPE_VOLATILE (el_type
);
14367 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
14369 return set_die_type (die
, base_type
, cu
);
14372 static struct type
*
14373 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14375 struct type
*base_type
, *cv_type
;
14377 base_type
= die_type (die
, cu
);
14379 /* The die_type call above may have already set the type for this DIE. */
14380 cv_type
= get_die_type (die
, cu
);
14384 /* In case the const qualifier is applied to an array type, the element type
14385 is so qualified, not the array type (section 6.7.3 of C99). */
14386 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
14387 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
14389 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
14390 return set_die_type (die
, cv_type
, cu
);
14393 static struct type
*
14394 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14396 struct type
*base_type
, *cv_type
;
14398 base_type
= die_type (die
, cu
);
14400 /* The die_type call above may have already set the type for this DIE. */
14401 cv_type
= get_die_type (die
, cu
);
14405 /* In case the volatile qualifier is applied to an array type, the
14406 element type is so qualified, not the array type (section 6.7.3
14408 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
14409 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
14411 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
14412 return set_die_type (die
, cv_type
, cu
);
14415 /* Handle DW_TAG_restrict_type. */
14417 static struct type
*
14418 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14420 struct type
*base_type
, *cv_type
;
14422 base_type
= die_type (die
, cu
);
14424 /* The die_type call above may have already set the type for this DIE. */
14425 cv_type
= get_die_type (die
, cu
);
14429 cv_type
= make_restrict_type (base_type
);
14430 return set_die_type (die
, cv_type
, cu
);
14433 /* Handle DW_TAG_atomic_type. */
14435 static struct type
*
14436 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14438 struct type
*base_type
, *cv_type
;
14440 base_type
= die_type (die
, cu
);
14442 /* The die_type call above may have already set the type for this DIE. */
14443 cv_type
= get_die_type (die
, cu
);
14447 cv_type
= make_atomic_type (base_type
);
14448 return set_die_type (die
, cv_type
, cu
);
14451 /* Extract all information from a DW_TAG_string_type DIE and add to
14452 the user defined type vector. It isn't really a user defined type,
14453 but it behaves like one, with other DIE's using an AT_user_def_type
14454 attribute to reference it. */
14456 static struct type
*
14457 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14459 struct objfile
*objfile
= cu
->objfile
;
14460 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14461 struct type
*type
, *range_type
, *index_type
, *char_type
;
14462 struct attribute
*attr
;
14463 unsigned int length
;
14465 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
14468 length
= DW_UNSND (attr
);
14472 /* Check for the DW_AT_byte_size attribute. */
14473 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14476 length
= DW_UNSND (attr
);
14484 index_type
= objfile_type (objfile
)->builtin_int
;
14485 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
14486 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
14487 type
= create_string_type (NULL
, char_type
, range_type
);
14489 return set_die_type (die
, type
, cu
);
14492 /* Assuming that DIE corresponds to a function, returns nonzero
14493 if the function is prototyped. */
14496 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
14498 struct attribute
*attr
;
14500 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
14501 if (attr
&& (DW_UNSND (attr
) != 0))
14504 /* The DWARF standard implies that the DW_AT_prototyped attribute
14505 is only meaninful for C, but the concept also extends to other
14506 languages that allow unprototyped functions (Eg: Objective C).
14507 For all other languages, assume that functions are always
14509 if (cu
->language
!= language_c
14510 && cu
->language
!= language_objc
14511 && cu
->language
!= language_opencl
)
14514 /* RealView does not emit DW_AT_prototyped. We can not distinguish
14515 prototyped and unprototyped functions; default to prototyped,
14516 since that is more common in modern code (and RealView warns
14517 about unprototyped functions). */
14518 if (producer_is_realview (cu
->producer
))
14524 /* Handle DIES due to C code like:
14528 int (*funcp)(int a, long l);
14532 ('funcp' generates a DW_TAG_subroutine_type DIE). */
14534 static struct type
*
14535 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14537 struct objfile
*objfile
= cu
->objfile
;
14538 struct type
*type
; /* Type that this function returns. */
14539 struct type
*ftype
; /* Function that returns above type. */
14540 struct attribute
*attr
;
14542 type
= die_type (die
, cu
);
14544 /* The die_type call above may have already set the type for this DIE. */
14545 ftype
= get_die_type (die
, cu
);
14549 ftype
= lookup_function_type (type
);
14551 if (prototyped_function_p (die
, cu
))
14552 TYPE_PROTOTYPED (ftype
) = 1;
14554 /* Store the calling convention in the type if it's available in
14555 the subroutine die. Otherwise set the calling convention to
14556 the default value DW_CC_normal. */
14557 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
14559 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
14560 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
14561 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
14563 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
14565 /* Record whether the function returns normally to its caller or not
14566 if the DWARF producer set that information. */
14567 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
14568 if (attr
&& (DW_UNSND (attr
) != 0))
14569 TYPE_NO_RETURN (ftype
) = 1;
14571 /* We need to add the subroutine type to the die immediately so
14572 we don't infinitely recurse when dealing with parameters
14573 declared as the same subroutine type. */
14574 set_die_type (die
, ftype
, cu
);
14576 if (die
->child
!= NULL
)
14578 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
14579 struct die_info
*child_die
;
14580 int nparams
, iparams
;
14582 /* Count the number of parameters.
14583 FIXME: GDB currently ignores vararg functions, but knows about
14584 vararg member functions. */
14586 child_die
= die
->child
;
14587 while (child_die
&& child_die
->tag
)
14589 if (child_die
->tag
== DW_TAG_formal_parameter
)
14591 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
14592 TYPE_VARARGS (ftype
) = 1;
14593 child_die
= sibling_die (child_die
);
14596 /* Allocate storage for parameters and fill them in. */
14597 TYPE_NFIELDS (ftype
) = nparams
;
14598 TYPE_FIELDS (ftype
) = (struct field
*)
14599 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
14601 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
14602 even if we error out during the parameters reading below. */
14603 for (iparams
= 0; iparams
< nparams
; iparams
++)
14604 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
14607 child_die
= die
->child
;
14608 while (child_die
&& child_die
->tag
)
14610 if (child_die
->tag
== DW_TAG_formal_parameter
)
14612 struct type
*arg_type
;
14614 /* DWARF version 2 has no clean way to discern C++
14615 static and non-static member functions. G++ helps
14616 GDB by marking the first parameter for non-static
14617 member functions (which is the this pointer) as
14618 artificial. We pass this information to
14619 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
14621 DWARF version 3 added DW_AT_object_pointer, which GCC
14622 4.5 does not yet generate. */
14623 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
14625 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
14627 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
14628 arg_type
= die_type (child_die
, cu
);
14630 /* RealView does not mark THIS as const, which the testsuite
14631 expects. GCC marks THIS as const in method definitions,
14632 but not in the class specifications (GCC PR 43053). */
14633 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
14634 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
14637 struct dwarf2_cu
*arg_cu
= cu
;
14638 const char *name
= dwarf2_name (child_die
, cu
);
14640 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
14643 /* If the compiler emits this, use it. */
14644 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
14647 else if (name
&& strcmp (name
, "this") == 0)
14648 /* Function definitions will have the argument names. */
14650 else if (name
== NULL
&& iparams
== 0)
14651 /* Declarations may not have the names, so like
14652 elsewhere in GDB, assume an artificial first
14653 argument is "this". */
14657 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
14661 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
14664 child_die
= sibling_die (child_die
);
14671 static struct type
*
14672 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
14674 struct objfile
*objfile
= cu
->objfile
;
14675 const char *name
= NULL
;
14676 struct type
*this_type
, *target_type
;
14678 name
= dwarf2_full_name (NULL
, die
, cu
);
14679 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
14680 TYPE_TARGET_STUB (this_type
) = 1;
14681 set_die_type (die
, this_type
, cu
);
14682 target_type
= die_type (die
, cu
);
14683 if (target_type
!= this_type
)
14684 TYPE_TARGET_TYPE (this_type
) = target_type
;
14687 /* Self-referential typedefs are, it seems, not allowed by the DWARF
14688 spec and cause infinite loops in GDB. */
14689 complaint (&symfile_complaints
,
14690 _("Self-referential DW_TAG_typedef "
14691 "- DIE at 0x%x [in module %s]"),
14692 die
->offset
.sect_off
, objfile_name (objfile
));
14693 TYPE_TARGET_TYPE (this_type
) = NULL
;
14698 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
14699 (which may be different from NAME) to the architecture back-end to allow
14700 it to guess the correct format if necessary. */
14702 static struct type
*
14703 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
14704 const char *name_hint
)
14706 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14707 const struct floatformat
**format
;
14710 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
14712 type
= init_float_type (objfile
, bits
, name
, format
);
14714 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
/ TARGET_CHAR_BIT
, name
);
14719 /* Find a representation of a given base type and install
14720 it in the TYPE field of the die. */
14722 static struct type
*
14723 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14725 struct objfile
*objfile
= cu
->objfile
;
14727 struct attribute
*attr
;
14728 int encoding
= 0, bits
= 0;
14731 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
14734 encoding
= DW_UNSND (attr
);
14736 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14739 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
14741 name
= dwarf2_name (die
, cu
);
14744 complaint (&symfile_complaints
,
14745 _("DW_AT_name missing from DW_TAG_base_type"));
14750 case DW_ATE_address
:
14751 /* Turn DW_ATE_address into a void * pointer. */
14752 type
= init_type (objfile
, TYPE_CODE_VOID
, 1, NULL
);
14753 type
= init_pointer_type (objfile
, bits
, name
, type
);
14755 case DW_ATE_boolean
:
14756 type
= init_boolean_type (objfile
, bits
, 1, name
);
14758 case DW_ATE_complex_float
:
14759 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
14760 type
= init_complex_type (objfile
, name
, type
);
14762 case DW_ATE_decimal_float
:
14763 type
= init_decfloat_type (objfile
, bits
, name
);
14766 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
14768 case DW_ATE_signed
:
14769 type
= init_integer_type (objfile
, bits
, 0, name
);
14771 case DW_ATE_unsigned
:
14772 if (cu
->language
== language_fortran
14774 && startswith (name
, "character("))
14775 type
= init_character_type (objfile
, bits
, 1, name
);
14777 type
= init_integer_type (objfile
, bits
, 1, name
);
14779 case DW_ATE_signed_char
:
14780 if (cu
->language
== language_ada
|| cu
->language
== language_m2
14781 || cu
->language
== language_pascal
14782 || cu
->language
== language_fortran
)
14783 type
= init_character_type (objfile
, bits
, 0, name
);
14785 type
= init_integer_type (objfile
, bits
, 0, name
);
14787 case DW_ATE_unsigned_char
:
14788 if (cu
->language
== language_ada
|| cu
->language
== language_m2
14789 || cu
->language
== language_pascal
14790 || cu
->language
== language_fortran
14791 || cu
->language
== language_rust
)
14792 type
= init_character_type (objfile
, bits
, 1, name
);
14794 type
= init_integer_type (objfile
, bits
, 1, name
);
14797 /* We just treat this as an integer and then recognize the
14798 type by name elsewhere. */
14799 type
= init_integer_type (objfile
, bits
, 0, name
);
14803 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
14804 dwarf_type_encoding_name (encoding
));
14805 type
= init_type (objfile
, TYPE_CODE_ERROR
,
14806 bits
/ TARGET_CHAR_BIT
, name
);
14810 if (name
&& strcmp (name
, "char") == 0)
14811 TYPE_NOSIGN (type
) = 1;
14813 return set_die_type (die
, type
, cu
);
14816 /* Parse dwarf attribute if it's a block, reference or constant and put the
14817 resulting value of the attribute into struct bound_prop.
14818 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
14821 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
14822 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
14824 struct dwarf2_property_baton
*baton
;
14825 struct obstack
*obstack
= &cu
->objfile
->objfile_obstack
;
14827 if (attr
== NULL
|| prop
== NULL
)
14830 if (attr_form_is_block (attr
))
14832 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
14833 baton
->referenced_type
= NULL
;
14834 baton
->locexpr
.per_cu
= cu
->per_cu
;
14835 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
14836 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
14837 prop
->data
.baton
= baton
;
14838 prop
->kind
= PROP_LOCEXPR
;
14839 gdb_assert (prop
->data
.baton
!= NULL
);
14841 else if (attr_form_is_ref (attr
))
14843 struct dwarf2_cu
*target_cu
= cu
;
14844 struct die_info
*target_die
;
14845 struct attribute
*target_attr
;
14847 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14848 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
14849 if (target_attr
== NULL
)
14850 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
14852 if (target_attr
== NULL
)
14855 switch (target_attr
->name
)
14857 case DW_AT_location
:
14858 if (attr_form_is_section_offset (target_attr
))
14860 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
14861 baton
->referenced_type
= die_type (target_die
, target_cu
);
14862 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
14863 prop
->data
.baton
= baton
;
14864 prop
->kind
= PROP_LOCLIST
;
14865 gdb_assert (prop
->data
.baton
!= NULL
);
14867 else if (attr_form_is_block (target_attr
))
14869 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
14870 baton
->referenced_type
= die_type (target_die
, target_cu
);
14871 baton
->locexpr
.per_cu
= cu
->per_cu
;
14872 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
14873 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
14874 prop
->data
.baton
= baton
;
14875 prop
->kind
= PROP_LOCEXPR
;
14876 gdb_assert (prop
->data
.baton
!= NULL
);
14880 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
14881 "dynamic property");
14885 case DW_AT_data_member_location
:
14889 if (!handle_data_member_location (target_die
, target_cu
,
14893 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
14894 baton
->referenced_type
= read_type_die (target_die
->parent
,
14896 baton
->offset_info
.offset
= offset
;
14897 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
14898 prop
->data
.baton
= baton
;
14899 prop
->kind
= PROP_ADDR_OFFSET
;
14904 else if (attr_form_is_constant (attr
))
14906 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
14907 prop
->kind
= PROP_CONST
;
14911 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
14912 dwarf2_name (die
, cu
));
14919 /* Read the given DW_AT_subrange DIE. */
14921 static struct type
*
14922 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14924 struct type
*base_type
, *orig_base_type
;
14925 struct type
*range_type
;
14926 struct attribute
*attr
;
14927 struct dynamic_prop low
, high
;
14928 int low_default_is_valid
;
14929 int high_bound_is_count
= 0;
14931 LONGEST negative_mask
;
14933 orig_base_type
= die_type (die
, cu
);
14934 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
14935 whereas the real type might be. So, we use ORIG_BASE_TYPE when
14936 creating the range type, but we use the result of check_typedef
14937 when examining properties of the type. */
14938 base_type
= check_typedef (orig_base_type
);
14940 /* The die_type call above may have already set the type for this DIE. */
14941 range_type
= get_die_type (die
, cu
);
14945 low
.kind
= PROP_CONST
;
14946 high
.kind
= PROP_CONST
;
14947 high
.data
.const_val
= 0;
14949 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
14950 omitting DW_AT_lower_bound. */
14951 switch (cu
->language
)
14954 case language_cplus
:
14955 low
.data
.const_val
= 0;
14956 low_default_is_valid
= 1;
14958 case language_fortran
:
14959 low
.data
.const_val
= 1;
14960 low_default_is_valid
= 1;
14963 case language_objc
:
14964 case language_rust
:
14965 low
.data
.const_val
= 0;
14966 low_default_is_valid
= (cu
->header
.version
>= 4);
14970 case language_pascal
:
14971 low
.data
.const_val
= 1;
14972 low_default_is_valid
= (cu
->header
.version
>= 4);
14975 low
.data
.const_val
= 0;
14976 low_default_is_valid
= 0;
14980 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
14982 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
14983 else if (!low_default_is_valid
)
14984 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
14985 "- DIE at 0x%x [in module %s]"),
14986 die
->offset
.sect_off
, objfile_name (cu
->objfile
));
14988 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
14989 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
14991 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
14992 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
14994 /* If bounds are constant do the final calculation here. */
14995 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
14996 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
14998 high_bound_is_count
= 1;
15002 /* Dwarf-2 specifications explicitly allows to create subrange types
15003 without specifying a base type.
15004 In that case, the base type must be set to the type of
15005 the lower bound, upper bound or count, in that order, if any of these
15006 three attributes references an object that has a type.
15007 If no base type is found, the Dwarf-2 specifications say that
15008 a signed integer type of size equal to the size of an address should
15010 For the following C code: `extern char gdb_int [];'
15011 GCC produces an empty range DIE.
15012 FIXME: muller/2010-05-28: Possible references to object for low bound,
15013 high bound or count are not yet handled by this code. */
15014 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
15016 struct objfile
*objfile
= cu
->objfile
;
15017 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15018 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
15019 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
15021 /* Test "int", "long int", and "long long int" objfile types,
15022 and select the first one having a size above or equal to the
15023 architecture address size. */
15024 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15025 base_type
= int_type
;
15028 int_type
= objfile_type (objfile
)->builtin_long
;
15029 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15030 base_type
= int_type
;
15033 int_type
= objfile_type (objfile
)->builtin_long_long
;
15034 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15035 base_type
= int_type
;
15040 /* Normally, the DWARF producers are expected to use a signed
15041 constant form (Eg. DW_FORM_sdata) to express negative bounds.
15042 But this is unfortunately not always the case, as witnessed
15043 with GCC, for instance, where the ambiguous DW_FORM_dataN form
15044 is used instead. To work around that ambiguity, we treat
15045 the bounds as signed, and thus sign-extend their values, when
15046 the base type is signed. */
15048 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
15049 if (low
.kind
== PROP_CONST
15050 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
15051 low
.data
.const_val
|= negative_mask
;
15052 if (high
.kind
== PROP_CONST
15053 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
15054 high
.data
.const_val
|= negative_mask
;
15056 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
15058 if (high_bound_is_count
)
15059 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
15061 /* Ada expects an empty array on no boundary attributes. */
15062 if (attr
== NULL
&& cu
->language
!= language_ada
)
15063 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
15065 name
= dwarf2_name (die
, cu
);
15067 TYPE_NAME (range_type
) = name
;
15069 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15071 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
15073 set_die_type (die
, range_type
, cu
);
15075 /* set_die_type should be already done. */
15076 set_descriptive_type (range_type
, die
, cu
);
15081 static struct type
*
15082 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15086 /* For now, we only support the C meaning of an unspecified type: void. */
15088 type
= init_type (cu
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
15089 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
15091 return set_die_type (die
, type
, cu
);
15094 /* Read a single die and all its descendents. Set the die's sibling
15095 field to NULL; set other fields in the die correctly, and set all
15096 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
15097 location of the info_ptr after reading all of those dies. PARENT
15098 is the parent of the die in question. */
15100 static struct die_info
*
15101 read_die_and_children (const struct die_reader_specs
*reader
,
15102 const gdb_byte
*info_ptr
,
15103 const gdb_byte
**new_info_ptr
,
15104 struct die_info
*parent
)
15106 struct die_info
*die
;
15107 const gdb_byte
*cur_ptr
;
15110 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
15113 *new_info_ptr
= cur_ptr
;
15116 store_in_ref_table (die
, reader
->cu
);
15119 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
15123 *new_info_ptr
= cur_ptr
;
15126 die
->sibling
= NULL
;
15127 die
->parent
= parent
;
15131 /* Read a die, all of its descendents, and all of its siblings; set
15132 all of the fields of all of the dies correctly. Arguments are as
15133 in read_die_and_children. */
15135 static struct die_info
*
15136 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
15137 const gdb_byte
*info_ptr
,
15138 const gdb_byte
**new_info_ptr
,
15139 struct die_info
*parent
)
15141 struct die_info
*first_die
, *last_sibling
;
15142 const gdb_byte
*cur_ptr
;
15144 cur_ptr
= info_ptr
;
15145 first_die
= last_sibling
= NULL
;
15149 struct die_info
*die
15150 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
15154 *new_info_ptr
= cur_ptr
;
15161 last_sibling
->sibling
= die
;
15163 last_sibling
= die
;
15167 /* Read a die, all of its descendents, and all of its siblings; set
15168 all of the fields of all of the dies correctly. Arguments are as
15169 in read_die_and_children.
15170 This the main entry point for reading a DIE and all its children. */
15172 static struct die_info
*
15173 read_die_and_siblings (const struct die_reader_specs
*reader
,
15174 const gdb_byte
*info_ptr
,
15175 const gdb_byte
**new_info_ptr
,
15176 struct die_info
*parent
)
15178 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
15179 new_info_ptr
, parent
);
15181 if (dwarf_die_debug
)
15183 fprintf_unfiltered (gdb_stdlog
,
15184 "Read die from %s@0x%x of %s:\n",
15185 get_section_name (reader
->die_section
),
15186 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15187 bfd_get_filename (reader
->abfd
));
15188 dump_die (die
, dwarf_die_debug
);
15194 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
15196 The caller is responsible for filling in the extra attributes
15197 and updating (*DIEP)->num_attrs.
15198 Set DIEP to point to a newly allocated die with its information,
15199 except for its child, sibling, and parent fields.
15200 Set HAS_CHILDREN to tell whether the die has children or not. */
15202 static const gdb_byte
*
15203 read_full_die_1 (const struct die_reader_specs
*reader
,
15204 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15205 int *has_children
, int num_extra_attrs
)
15207 unsigned int abbrev_number
, bytes_read
, i
;
15208 sect_offset offset
;
15209 struct abbrev_info
*abbrev
;
15210 struct die_info
*die
;
15211 struct dwarf2_cu
*cu
= reader
->cu
;
15212 bfd
*abfd
= reader
->abfd
;
15214 offset
.sect_off
= info_ptr
- reader
->buffer
;
15215 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15216 info_ptr
+= bytes_read
;
15217 if (!abbrev_number
)
15224 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
15226 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
15228 bfd_get_filename (abfd
));
15230 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
15231 die
->offset
= offset
;
15232 die
->tag
= abbrev
->tag
;
15233 die
->abbrev
= abbrev_number
;
15235 /* Make the result usable.
15236 The caller needs to update num_attrs after adding the extra
15238 die
->num_attrs
= abbrev
->num_attrs
;
15240 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
15241 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
15245 *has_children
= abbrev
->has_children
;
15249 /* Read a die and all its attributes.
15250 Set DIEP to point to a newly allocated die with its information,
15251 except for its child, sibling, and parent fields.
15252 Set HAS_CHILDREN to tell whether the die has children or not. */
15254 static const gdb_byte
*
15255 read_full_die (const struct die_reader_specs
*reader
,
15256 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15259 const gdb_byte
*result
;
15261 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
15263 if (dwarf_die_debug
)
15265 fprintf_unfiltered (gdb_stdlog
,
15266 "Read die from %s@0x%x of %s:\n",
15267 get_section_name (reader
->die_section
),
15268 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15269 bfd_get_filename (reader
->abfd
));
15270 dump_die (*diep
, dwarf_die_debug
);
15276 /* Abbreviation tables.
15278 In DWARF version 2, the description of the debugging information is
15279 stored in a separate .debug_abbrev section. Before we read any
15280 dies from a section we read in all abbreviations and install them
15281 in a hash table. */
15283 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
15285 static struct abbrev_info
*
15286 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
15288 struct abbrev_info
*abbrev
;
15290 abbrev
= XOBNEW (&abbrev_table
->abbrev_obstack
, struct abbrev_info
);
15291 memset (abbrev
, 0, sizeof (struct abbrev_info
));
15296 /* Add an abbreviation to the table. */
15299 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
15300 unsigned int abbrev_number
,
15301 struct abbrev_info
*abbrev
)
15303 unsigned int hash_number
;
15305 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
15306 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
15307 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
15310 /* Look up an abbrev in the table.
15311 Returns NULL if the abbrev is not found. */
15313 static struct abbrev_info
*
15314 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
15315 unsigned int abbrev_number
)
15317 unsigned int hash_number
;
15318 struct abbrev_info
*abbrev
;
15320 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
15321 abbrev
= abbrev_table
->abbrevs
[hash_number
];
15325 if (abbrev
->number
== abbrev_number
)
15327 abbrev
= abbrev
->next
;
15332 /* Read in an abbrev table. */
15334 static struct abbrev_table
*
15335 abbrev_table_read_table (struct dwarf2_section_info
*section
,
15336 sect_offset offset
)
15338 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15339 bfd
*abfd
= get_section_bfd_owner (section
);
15340 struct abbrev_table
*abbrev_table
;
15341 const gdb_byte
*abbrev_ptr
;
15342 struct abbrev_info
*cur_abbrev
;
15343 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
15344 unsigned int abbrev_form
;
15345 struct attr_abbrev
*cur_attrs
;
15346 unsigned int allocated_attrs
;
15348 abbrev_table
= XNEW (struct abbrev_table
);
15349 abbrev_table
->offset
= offset
;
15350 obstack_init (&abbrev_table
->abbrev_obstack
);
15351 abbrev_table
->abbrevs
=
15352 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct abbrev_info
*,
15354 memset (abbrev_table
->abbrevs
, 0,
15355 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
15357 dwarf2_read_section (objfile
, section
);
15358 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
15359 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15360 abbrev_ptr
+= bytes_read
;
15362 allocated_attrs
= ATTR_ALLOC_CHUNK
;
15363 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
15365 /* Loop until we reach an abbrev number of 0. */
15366 while (abbrev_number
)
15368 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
15370 /* read in abbrev header */
15371 cur_abbrev
->number
= abbrev_number
;
15373 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15374 abbrev_ptr
+= bytes_read
;
15375 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
15378 /* now read in declarations */
15379 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15380 abbrev_ptr
+= bytes_read
;
15381 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15382 abbrev_ptr
+= bytes_read
;
15383 while (abbrev_name
)
15385 if (cur_abbrev
->num_attrs
== allocated_attrs
)
15387 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
15389 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
15392 cur_attrs
[cur_abbrev
->num_attrs
].name
15393 = (enum dwarf_attribute
) abbrev_name
;
15394 cur_attrs
[cur_abbrev
->num_attrs
++].form
15395 = (enum dwarf_form
) abbrev_form
;
15396 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15397 abbrev_ptr
+= bytes_read
;
15398 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15399 abbrev_ptr
+= bytes_read
;
15402 cur_abbrev
->attrs
=
15403 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
15404 cur_abbrev
->num_attrs
);
15405 memcpy (cur_abbrev
->attrs
, cur_attrs
,
15406 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
15408 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
15410 /* Get next abbreviation.
15411 Under Irix6 the abbreviations for a compilation unit are not
15412 always properly terminated with an abbrev number of 0.
15413 Exit loop if we encounter an abbreviation which we have
15414 already read (which means we are about to read the abbreviations
15415 for the next compile unit) or if the end of the abbreviation
15416 table is reached. */
15417 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
15419 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15420 abbrev_ptr
+= bytes_read
;
15421 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
15426 return abbrev_table
;
15429 /* Free the resources held by ABBREV_TABLE. */
15432 abbrev_table_free (struct abbrev_table
*abbrev_table
)
15434 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
15435 xfree (abbrev_table
);
15438 /* Same as abbrev_table_free but as a cleanup.
15439 We pass in a pointer to the pointer to the table so that we can
15440 set the pointer to NULL when we're done. It also simplifies
15441 build_type_psymtabs_1. */
15444 abbrev_table_free_cleanup (void *table_ptr
)
15446 struct abbrev_table
**abbrev_table_ptr
= (struct abbrev_table
**) table_ptr
;
15448 if (*abbrev_table_ptr
!= NULL
)
15449 abbrev_table_free (*abbrev_table_ptr
);
15450 *abbrev_table_ptr
= NULL
;
15453 /* Read the abbrev table for CU from ABBREV_SECTION. */
15456 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
15457 struct dwarf2_section_info
*abbrev_section
)
15460 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
15463 /* Release the memory used by the abbrev table for a compilation unit. */
15466 dwarf2_free_abbrev_table (void *ptr_to_cu
)
15468 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr_to_cu
;
15470 if (cu
->abbrev_table
!= NULL
)
15471 abbrev_table_free (cu
->abbrev_table
);
15472 /* Set this to NULL so that we SEGV if we try to read it later,
15473 and also because free_comp_unit verifies this is NULL. */
15474 cu
->abbrev_table
= NULL
;
15477 /* Returns nonzero if TAG represents a type that we might generate a partial
15481 is_type_tag_for_partial (int tag
)
15486 /* Some types that would be reasonable to generate partial symbols for,
15487 that we don't at present. */
15488 case DW_TAG_array_type
:
15489 case DW_TAG_file_type
:
15490 case DW_TAG_ptr_to_member_type
:
15491 case DW_TAG_set_type
:
15492 case DW_TAG_string_type
:
15493 case DW_TAG_subroutine_type
:
15495 case DW_TAG_base_type
:
15496 case DW_TAG_class_type
:
15497 case DW_TAG_interface_type
:
15498 case DW_TAG_enumeration_type
:
15499 case DW_TAG_structure_type
:
15500 case DW_TAG_subrange_type
:
15501 case DW_TAG_typedef
:
15502 case DW_TAG_union_type
:
15509 /* Load all DIEs that are interesting for partial symbols into memory. */
15511 static struct partial_die_info
*
15512 load_partial_dies (const struct die_reader_specs
*reader
,
15513 const gdb_byte
*info_ptr
, int building_psymtab
)
15515 struct dwarf2_cu
*cu
= reader
->cu
;
15516 struct objfile
*objfile
= cu
->objfile
;
15517 struct partial_die_info
*part_die
;
15518 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
15519 struct abbrev_info
*abbrev
;
15520 unsigned int bytes_read
;
15521 unsigned int load_all
= 0;
15522 int nesting_level
= 1;
15527 gdb_assert (cu
->per_cu
!= NULL
);
15528 if (cu
->per_cu
->load_all_dies
)
15532 = htab_create_alloc_ex (cu
->header
.length
/ 12,
15536 &cu
->comp_unit_obstack
,
15537 hashtab_obstack_allocate
,
15538 dummy_obstack_deallocate
);
15540 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
15544 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
15546 /* A NULL abbrev means the end of a series of children. */
15547 if (abbrev
== NULL
)
15549 if (--nesting_level
== 0)
15551 /* PART_DIE was probably the last thing allocated on the
15552 comp_unit_obstack, so we could call obstack_free
15553 here. We don't do that because the waste is small,
15554 and will be cleaned up when we're done with this
15555 compilation unit. This way, we're also more robust
15556 against other users of the comp_unit_obstack. */
15559 info_ptr
+= bytes_read
;
15560 last_die
= parent_die
;
15561 parent_die
= parent_die
->die_parent
;
15565 /* Check for template arguments. We never save these; if
15566 they're seen, we just mark the parent, and go on our way. */
15567 if (parent_die
!= NULL
15568 && cu
->language
== language_cplus
15569 && (abbrev
->tag
== DW_TAG_template_type_param
15570 || abbrev
->tag
== DW_TAG_template_value_param
))
15572 parent_die
->has_template_arguments
= 1;
15576 /* We don't need a partial DIE for the template argument. */
15577 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15582 /* We only recurse into c++ subprograms looking for template arguments.
15583 Skip their other children. */
15585 && cu
->language
== language_cplus
15586 && parent_die
!= NULL
15587 && parent_die
->tag
== DW_TAG_subprogram
)
15589 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15593 /* Check whether this DIE is interesting enough to save. Normally
15594 we would not be interested in members here, but there may be
15595 later variables referencing them via DW_AT_specification (for
15596 static members). */
15598 && !is_type_tag_for_partial (abbrev
->tag
)
15599 && abbrev
->tag
!= DW_TAG_constant
15600 && abbrev
->tag
!= DW_TAG_enumerator
15601 && abbrev
->tag
!= DW_TAG_subprogram
15602 && abbrev
->tag
!= DW_TAG_lexical_block
15603 && abbrev
->tag
!= DW_TAG_variable
15604 && abbrev
->tag
!= DW_TAG_namespace
15605 && abbrev
->tag
!= DW_TAG_module
15606 && abbrev
->tag
!= DW_TAG_member
15607 && abbrev
->tag
!= DW_TAG_imported_unit
15608 && abbrev
->tag
!= DW_TAG_imported_declaration
)
15610 /* Otherwise we skip to the next sibling, if any. */
15611 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15615 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
15618 /* This two-pass algorithm for processing partial symbols has a
15619 high cost in cache pressure. Thus, handle some simple cases
15620 here which cover the majority of C partial symbols. DIEs
15621 which neither have specification tags in them, nor could have
15622 specification tags elsewhere pointing at them, can simply be
15623 processed and discarded.
15625 This segment is also optional; scan_partial_symbols and
15626 add_partial_symbol will handle these DIEs if we chain
15627 them in normally. When compilers which do not emit large
15628 quantities of duplicate debug information are more common,
15629 this code can probably be removed. */
15631 /* Any complete simple types at the top level (pretty much all
15632 of them, for a language without namespaces), can be processed
15634 if (parent_die
== NULL
15635 && part_die
->has_specification
== 0
15636 && part_die
->is_declaration
== 0
15637 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
15638 || part_die
->tag
== DW_TAG_base_type
15639 || part_die
->tag
== DW_TAG_subrange_type
))
15641 if (building_psymtab
&& part_die
->name
!= NULL
)
15642 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
15643 VAR_DOMAIN
, LOC_TYPEDEF
,
15644 &objfile
->static_psymbols
,
15645 0, cu
->language
, objfile
);
15646 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
15650 /* The exception for DW_TAG_typedef with has_children above is
15651 a workaround of GCC PR debug/47510. In the case of this complaint
15652 type_name_no_tag_or_error will error on such types later.
15654 GDB skipped children of DW_TAG_typedef by the shortcut above and then
15655 it could not find the child DIEs referenced later, this is checked
15656 above. In correct DWARF DW_TAG_typedef should have no children. */
15658 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
15659 complaint (&symfile_complaints
,
15660 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
15661 "- DIE at 0x%x [in module %s]"),
15662 part_die
->offset
.sect_off
, objfile_name (objfile
));
15664 /* If we're at the second level, and we're an enumerator, and
15665 our parent has no specification (meaning possibly lives in a
15666 namespace elsewhere), then we can add the partial symbol now
15667 instead of queueing it. */
15668 if (part_die
->tag
== DW_TAG_enumerator
15669 && parent_die
!= NULL
15670 && parent_die
->die_parent
== NULL
15671 && parent_die
->tag
== DW_TAG_enumeration_type
15672 && parent_die
->has_specification
== 0)
15674 if (part_die
->name
== NULL
)
15675 complaint (&symfile_complaints
,
15676 _("malformed enumerator DIE ignored"));
15677 else if (building_psymtab
)
15678 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
15679 VAR_DOMAIN
, LOC_CONST
,
15680 cu
->language
== language_cplus
15681 ? &objfile
->global_psymbols
15682 : &objfile
->static_psymbols
,
15683 0, cu
->language
, objfile
);
15685 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
15689 /* We'll save this DIE so link it in. */
15690 part_die
->die_parent
= parent_die
;
15691 part_die
->die_sibling
= NULL
;
15692 part_die
->die_child
= NULL
;
15694 if (last_die
&& last_die
== parent_die
)
15695 last_die
->die_child
= part_die
;
15697 last_die
->die_sibling
= part_die
;
15699 last_die
= part_die
;
15701 if (first_die
== NULL
)
15702 first_die
= part_die
;
15704 /* Maybe add the DIE to the hash table. Not all DIEs that we
15705 find interesting need to be in the hash table, because we
15706 also have the parent/sibling/child chains; only those that we
15707 might refer to by offset later during partial symbol reading.
15709 For now this means things that might have be the target of a
15710 DW_AT_specification, DW_AT_abstract_origin, or
15711 DW_AT_extension. DW_AT_extension will refer only to
15712 namespaces; DW_AT_abstract_origin refers to functions (and
15713 many things under the function DIE, but we do not recurse
15714 into function DIEs during partial symbol reading) and
15715 possibly variables as well; DW_AT_specification refers to
15716 declarations. Declarations ought to have the DW_AT_declaration
15717 flag. It happens that GCC forgets to put it in sometimes, but
15718 only for functions, not for types.
15720 Adding more things than necessary to the hash table is harmless
15721 except for the performance cost. Adding too few will result in
15722 wasted time in find_partial_die, when we reread the compilation
15723 unit with load_all_dies set. */
15726 || abbrev
->tag
== DW_TAG_constant
15727 || abbrev
->tag
== DW_TAG_subprogram
15728 || abbrev
->tag
== DW_TAG_variable
15729 || abbrev
->tag
== DW_TAG_namespace
15730 || part_die
->is_declaration
)
15734 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
15735 part_die
->offset
.sect_off
, INSERT
);
15739 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
15741 /* For some DIEs we want to follow their children (if any). For C
15742 we have no reason to follow the children of structures; for other
15743 languages we have to, so that we can get at method physnames
15744 to infer fully qualified class names, for DW_AT_specification,
15745 and for C++ template arguments. For C++, we also look one level
15746 inside functions to find template arguments (if the name of the
15747 function does not already contain the template arguments).
15749 For Ada, we need to scan the children of subprograms and lexical
15750 blocks as well because Ada allows the definition of nested
15751 entities that could be interesting for the debugger, such as
15752 nested subprograms for instance. */
15753 if (last_die
->has_children
15755 || last_die
->tag
== DW_TAG_namespace
15756 || last_die
->tag
== DW_TAG_module
15757 || last_die
->tag
== DW_TAG_enumeration_type
15758 || (cu
->language
== language_cplus
15759 && last_die
->tag
== DW_TAG_subprogram
15760 && (last_die
->name
== NULL
15761 || strchr (last_die
->name
, '<') == NULL
))
15762 || (cu
->language
!= language_c
15763 && (last_die
->tag
== DW_TAG_class_type
15764 || last_die
->tag
== DW_TAG_interface_type
15765 || last_die
->tag
== DW_TAG_structure_type
15766 || last_die
->tag
== DW_TAG_union_type
))
15767 || (cu
->language
== language_ada
15768 && (last_die
->tag
== DW_TAG_subprogram
15769 || last_die
->tag
== DW_TAG_lexical_block
))))
15772 parent_die
= last_die
;
15776 /* Otherwise we skip to the next sibling, if any. */
15777 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
15779 /* Back to the top, do it again. */
15783 /* Read a minimal amount of information into the minimal die structure. */
15785 static const gdb_byte
*
15786 read_partial_die (const struct die_reader_specs
*reader
,
15787 struct partial_die_info
*part_die
,
15788 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
15789 const gdb_byte
*info_ptr
)
15791 struct dwarf2_cu
*cu
= reader
->cu
;
15792 struct objfile
*objfile
= cu
->objfile
;
15793 const gdb_byte
*buffer
= reader
->buffer
;
15795 struct attribute attr
;
15796 int has_low_pc_attr
= 0;
15797 int has_high_pc_attr
= 0;
15798 int high_pc_relative
= 0;
15800 memset (part_die
, 0, sizeof (struct partial_die_info
));
15802 part_die
->offset
.sect_off
= info_ptr
- buffer
;
15804 info_ptr
+= abbrev_len
;
15806 if (abbrev
== NULL
)
15809 part_die
->tag
= abbrev
->tag
;
15810 part_die
->has_children
= abbrev
->has_children
;
15812 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
15814 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
15816 /* Store the data if it is of an attribute we want to keep in a
15817 partial symbol table. */
15821 switch (part_die
->tag
)
15823 case DW_TAG_compile_unit
:
15824 case DW_TAG_partial_unit
:
15825 case DW_TAG_type_unit
:
15826 /* Compilation units have a DW_AT_name that is a filename, not
15827 a source language identifier. */
15828 case DW_TAG_enumeration_type
:
15829 case DW_TAG_enumerator
:
15830 /* These tags always have simple identifiers already; no need
15831 to canonicalize them. */
15832 part_die
->name
= DW_STRING (&attr
);
15836 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
15837 &objfile
->per_bfd
->storage_obstack
);
15841 case DW_AT_linkage_name
:
15842 case DW_AT_MIPS_linkage_name
:
15843 /* Note that both forms of linkage name might appear. We
15844 assume they will be the same, and we only store the last
15846 if (cu
->language
== language_ada
)
15847 part_die
->name
= DW_STRING (&attr
);
15848 part_die
->linkage_name
= DW_STRING (&attr
);
15851 has_low_pc_attr
= 1;
15852 part_die
->lowpc
= attr_value_as_address (&attr
);
15854 case DW_AT_high_pc
:
15855 has_high_pc_attr
= 1;
15856 part_die
->highpc
= attr_value_as_address (&attr
);
15857 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
15858 high_pc_relative
= 1;
15860 case DW_AT_location
:
15861 /* Support the .debug_loc offsets. */
15862 if (attr_form_is_block (&attr
))
15864 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
15866 else if (attr_form_is_section_offset (&attr
))
15868 dwarf2_complex_location_expr_complaint ();
15872 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15873 "partial symbol information");
15876 case DW_AT_external
:
15877 part_die
->is_external
= DW_UNSND (&attr
);
15879 case DW_AT_declaration
:
15880 part_die
->is_declaration
= DW_UNSND (&attr
);
15883 part_die
->has_type
= 1;
15885 case DW_AT_abstract_origin
:
15886 case DW_AT_specification
:
15887 case DW_AT_extension
:
15888 part_die
->has_specification
= 1;
15889 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
15890 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
15891 || cu
->per_cu
->is_dwz
);
15893 case DW_AT_sibling
:
15894 /* Ignore absolute siblings, they might point outside of
15895 the current compile unit. */
15896 if (attr
.form
== DW_FORM_ref_addr
)
15897 complaint (&symfile_complaints
,
15898 _("ignoring absolute DW_AT_sibling"));
15901 unsigned int off
= dwarf2_get_ref_die_offset (&attr
).sect_off
;
15902 const gdb_byte
*sibling_ptr
= buffer
+ off
;
15904 if (sibling_ptr
< info_ptr
)
15905 complaint (&symfile_complaints
,
15906 _("DW_AT_sibling points backwards"));
15907 else if (sibling_ptr
> reader
->buffer_end
)
15908 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
15910 part_die
->sibling
= sibling_ptr
;
15913 case DW_AT_byte_size
:
15914 part_die
->has_byte_size
= 1;
15916 case DW_AT_const_value
:
15917 part_die
->has_const_value
= 1;
15919 case DW_AT_calling_convention
:
15920 /* DWARF doesn't provide a way to identify a program's source-level
15921 entry point. DW_AT_calling_convention attributes are only meant
15922 to describe functions' calling conventions.
15924 However, because it's a necessary piece of information in
15925 Fortran, and before DWARF 4 DW_CC_program was the only
15926 piece of debugging information whose definition refers to
15927 a 'main program' at all, several compilers marked Fortran
15928 main programs with DW_CC_program --- even when those
15929 functions use the standard calling conventions.
15931 Although DWARF now specifies a way to provide this
15932 information, we support this practice for backward
15934 if (DW_UNSND (&attr
) == DW_CC_program
15935 && cu
->language
== language_fortran
)
15936 part_die
->main_subprogram
= 1;
15939 if (DW_UNSND (&attr
) == DW_INL_inlined
15940 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
15941 part_die
->may_be_inlined
= 1;
15945 if (part_die
->tag
== DW_TAG_imported_unit
)
15947 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
15948 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
15949 || cu
->per_cu
->is_dwz
);
15953 case DW_AT_main_subprogram
:
15954 part_die
->main_subprogram
= DW_UNSND (&attr
);
15962 if (high_pc_relative
)
15963 part_die
->highpc
+= part_die
->lowpc
;
15965 if (has_low_pc_attr
&& has_high_pc_attr
)
15967 /* When using the GNU linker, .gnu.linkonce. sections are used to
15968 eliminate duplicate copies of functions and vtables and such.
15969 The linker will arbitrarily choose one and discard the others.
15970 The AT_*_pc values for such functions refer to local labels in
15971 these sections. If the section from that file was discarded, the
15972 labels are not in the output, so the relocs get a value of 0.
15973 If this is a discarded function, mark the pc bounds as invalid,
15974 so that GDB will ignore it. */
15975 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
15977 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15979 complaint (&symfile_complaints
,
15980 _("DW_AT_low_pc %s is zero "
15981 "for DIE at 0x%x [in module %s]"),
15982 paddress (gdbarch
, part_die
->lowpc
),
15983 part_die
->offset
.sect_off
, objfile_name (objfile
));
15985 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
15986 else if (part_die
->lowpc
>= part_die
->highpc
)
15988 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15990 complaint (&symfile_complaints
,
15991 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
15992 "for DIE at 0x%x [in module %s]"),
15993 paddress (gdbarch
, part_die
->lowpc
),
15994 paddress (gdbarch
, part_die
->highpc
),
15995 part_die
->offset
.sect_off
, objfile_name (objfile
));
15998 part_die
->has_pc_info
= 1;
16004 /* Find a cached partial DIE at OFFSET in CU. */
16006 static struct partial_die_info
*
16007 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
16009 struct partial_die_info
*lookup_die
= NULL
;
16010 struct partial_die_info part_die
;
16012 part_die
.offset
= offset
;
16013 lookup_die
= ((struct partial_die_info
*)
16014 htab_find_with_hash (cu
->partial_dies
, &part_die
,
16020 /* Find a partial DIE at OFFSET, which may or may not be in CU,
16021 except in the case of .debug_types DIEs which do not reference
16022 outside their CU (they do however referencing other types via
16023 DW_FORM_ref_sig8). */
16025 static struct partial_die_info
*
16026 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
16028 struct objfile
*objfile
= cu
->objfile
;
16029 struct dwarf2_per_cu_data
*per_cu
= NULL
;
16030 struct partial_die_info
*pd
= NULL
;
16032 if (offset_in_dwz
== cu
->per_cu
->is_dwz
16033 && offset_in_cu_p (&cu
->header
, offset
))
16035 pd
= find_partial_die_in_comp_unit (offset
, cu
);
16038 /* We missed recording what we needed.
16039 Load all dies and try again. */
16040 per_cu
= cu
->per_cu
;
16044 /* TUs don't reference other CUs/TUs (except via type signatures). */
16045 if (cu
->per_cu
->is_debug_types
)
16047 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
16048 " external reference to offset 0x%lx [in module %s].\n"),
16049 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
16050 bfd_get_filename (objfile
->obfd
));
16052 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
16055 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
16056 load_partial_comp_unit (per_cu
);
16058 per_cu
->cu
->last_used
= 0;
16059 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
16062 /* If we didn't find it, and not all dies have been loaded,
16063 load them all and try again. */
16065 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
16067 per_cu
->load_all_dies
= 1;
16069 /* This is nasty. When we reread the DIEs, somewhere up the call chain
16070 THIS_CU->cu may already be in use. So we can't just free it and
16071 replace its DIEs with the ones we read in. Instead, we leave those
16072 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
16073 and clobber THIS_CU->cu->partial_dies with the hash table for the new
16075 load_partial_comp_unit (per_cu
);
16077 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
16081 internal_error (__FILE__
, __LINE__
,
16082 _("could not find partial DIE 0x%x "
16083 "in cache [from module %s]\n"),
16084 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16088 /* See if we can figure out if the class lives in a namespace. We do
16089 this by looking for a member function; its demangled name will
16090 contain namespace info, if there is any. */
16093 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
16094 struct dwarf2_cu
*cu
)
16096 /* NOTE: carlton/2003-10-07: Getting the info this way changes
16097 what template types look like, because the demangler
16098 frequently doesn't give the same name as the debug info. We
16099 could fix this by only using the demangled name to get the
16100 prefix (but see comment in read_structure_type). */
16102 struct partial_die_info
*real_pdi
;
16103 struct partial_die_info
*child_pdi
;
16105 /* If this DIE (this DIE's specification, if any) has a parent, then
16106 we should not do this. We'll prepend the parent's fully qualified
16107 name when we create the partial symbol. */
16109 real_pdi
= struct_pdi
;
16110 while (real_pdi
->has_specification
)
16111 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
16112 real_pdi
->spec_is_dwz
, cu
);
16114 if (real_pdi
->die_parent
!= NULL
)
16117 for (child_pdi
= struct_pdi
->die_child
;
16119 child_pdi
= child_pdi
->die_sibling
)
16121 if (child_pdi
->tag
== DW_TAG_subprogram
16122 && child_pdi
->linkage_name
!= NULL
)
16124 char *actual_class_name
16125 = language_class_name_from_physname (cu
->language_defn
,
16126 child_pdi
->linkage_name
);
16127 if (actual_class_name
!= NULL
)
16131 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16133 strlen (actual_class_name
)));
16134 xfree (actual_class_name
);
16141 /* Adjust PART_DIE before generating a symbol for it. This function
16142 may set the is_external flag or change the DIE's name. */
16145 fixup_partial_die (struct partial_die_info
*part_die
,
16146 struct dwarf2_cu
*cu
)
16148 /* Once we've fixed up a die, there's no point in doing so again.
16149 This also avoids a memory leak if we were to call
16150 guess_partial_die_structure_name multiple times. */
16151 if (part_die
->fixup_called
)
16154 /* If we found a reference attribute and the DIE has no name, try
16155 to find a name in the referred to DIE. */
16157 if (part_die
->name
== NULL
&& part_die
->has_specification
)
16159 struct partial_die_info
*spec_die
;
16161 spec_die
= find_partial_die (part_die
->spec_offset
,
16162 part_die
->spec_is_dwz
, cu
);
16164 fixup_partial_die (spec_die
, cu
);
16166 if (spec_die
->name
)
16168 part_die
->name
= spec_die
->name
;
16170 /* Copy DW_AT_external attribute if it is set. */
16171 if (spec_die
->is_external
)
16172 part_die
->is_external
= spec_die
->is_external
;
16176 /* Set default names for some unnamed DIEs. */
16178 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
16179 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
16181 /* If there is no parent die to provide a namespace, and there are
16182 children, see if we can determine the namespace from their linkage
16184 if (cu
->language
== language_cplus
16185 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
16186 && part_die
->die_parent
== NULL
16187 && part_die
->has_children
16188 && (part_die
->tag
== DW_TAG_class_type
16189 || part_die
->tag
== DW_TAG_structure_type
16190 || part_die
->tag
== DW_TAG_union_type
))
16191 guess_partial_die_structure_name (part_die
, cu
);
16193 /* GCC might emit a nameless struct or union that has a linkage
16194 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16195 if (part_die
->name
== NULL
16196 && (part_die
->tag
== DW_TAG_class_type
16197 || part_die
->tag
== DW_TAG_interface_type
16198 || part_die
->tag
== DW_TAG_structure_type
16199 || part_die
->tag
== DW_TAG_union_type
)
16200 && part_die
->linkage_name
!= NULL
)
16204 demangled
= gdb_demangle (part_die
->linkage_name
, DMGL_TYPES
);
16209 /* Strip any leading namespaces/classes, keep only the base name.
16210 DW_AT_name for named DIEs does not contain the prefixes. */
16211 base
= strrchr (demangled
, ':');
16212 if (base
&& base
> demangled
&& base
[-1] == ':')
16219 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16220 base
, strlen (base
)));
16225 part_die
->fixup_called
= 1;
16228 /* Read an attribute value described by an attribute form. */
16230 static const gdb_byte
*
16231 read_attribute_value (const struct die_reader_specs
*reader
,
16232 struct attribute
*attr
, unsigned form
,
16233 const gdb_byte
*info_ptr
)
16235 struct dwarf2_cu
*cu
= reader
->cu
;
16236 struct objfile
*objfile
= cu
->objfile
;
16237 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16238 bfd
*abfd
= reader
->abfd
;
16239 struct comp_unit_head
*cu_header
= &cu
->header
;
16240 unsigned int bytes_read
;
16241 struct dwarf_block
*blk
;
16243 attr
->form
= (enum dwarf_form
) form
;
16246 case DW_FORM_ref_addr
:
16247 if (cu
->header
.version
== 2)
16248 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
16250 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
16251 &cu
->header
, &bytes_read
);
16252 info_ptr
+= bytes_read
;
16254 case DW_FORM_GNU_ref_alt
:
16255 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
16256 info_ptr
+= bytes_read
;
16259 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
16260 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
16261 info_ptr
+= bytes_read
;
16263 case DW_FORM_block2
:
16264 blk
= dwarf_alloc_block (cu
);
16265 blk
->size
= read_2_bytes (abfd
, info_ptr
);
16267 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16268 info_ptr
+= blk
->size
;
16269 DW_BLOCK (attr
) = blk
;
16271 case DW_FORM_block4
:
16272 blk
= dwarf_alloc_block (cu
);
16273 blk
->size
= read_4_bytes (abfd
, info_ptr
);
16275 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16276 info_ptr
+= blk
->size
;
16277 DW_BLOCK (attr
) = blk
;
16279 case DW_FORM_data2
:
16280 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
16283 case DW_FORM_data4
:
16284 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
16287 case DW_FORM_data8
:
16288 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
16291 case DW_FORM_sec_offset
:
16292 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
16293 info_ptr
+= bytes_read
;
16295 case DW_FORM_string
:
16296 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
16297 DW_STRING_IS_CANONICAL (attr
) = 0;
16298 info_ptr
+= bytes_read
;
16301 if (!cu
->per_cu
->is_dwz
)
16303 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
16305 DW_STRING_IS_CANONICAL (attr
) = 0;
16306 info_ptr
+= bytes_read
;
16310 case DW_FORM_GNU_strp_alt
:
16312 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
16313 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
16316 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
16317 DW_STRING_IS_CANONICAL (attr
) = 0;
16318 info_ptr
+= bytes_read
;
16321 case DW_FORM_exprloc
:
16322 case DW_FORM_block
:
16323 blk
= dwarf_alloc_block (cu
);
16324 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16325 info_ptr
+= bytes_read
;
16326 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16327 info_ptr
+= blk
->size
;
16328 DW_BLOCK (attr
) = blk
;
16330 case DW_FORM_block1
:
16331 blk
= dwarf_alloc_block (cu
);
16332 blk
->size
= read_1_byte (abfd
, info_ptr
);
16334 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16335 info_ptr
+= blk
->size
;
16336 DW_BLOCK (attr
) = blk
;
16338 case DW_FORM_data1
:
16339 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
16343 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
16346 case DW_FORM_flag_present
:
16347 DW_UNSND (attr
) = 1;
16349 case DW_FORM_sdata
:
16350 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
16351 info_ptr
+= bytes_read
;
16353 case DW_FORM_udata
:
16354 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16355 info_ptr
+= bytes_read
;
16358 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16359 + read_1_byte (abfd
, info_ptr
));
16363 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16364 + read_2_bytes (abfd
, info_ptr
));
16368 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16369 + read_4_bytes (abfd
, info_ptr
));
16373 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16374 + read_8_bytes (abfd
, info_ptr
));
16377 case DW_FORM_ref_sig8
:
16378 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
16381 case DW_FORM_ref_udata
:
16382 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16383 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
16384 info_ptr
+= bytes_read
;
16386 case DW_FORM_indirect
:
16387 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16388 info_ptr
+= bytes_read
;
16389 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
16391 case DW_FORM_GNU_addr_index
:
16392 if (reader
->dwo_file
== NULL
)
16394 /* For now flag a hard error.
16395 Later we can turn this into a complaint. */
16396 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
16397 dwarf_form_name (form
),
16398 bfd_get_filename (abfd
));
16400 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
16401 info_ptr
+= bytes_read
;
16403 case DW_FORM_GNU_str_index
:
16404 if (reader
->dwo_file
== NULL
)
16406 /* For now flag a hard error.
16407 Later we can turn this into a complaint if warranted. */
16408 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
16409 dwarf_form_name (form
),
16410 bfd_get_filename (abfd
));
16413 ULONGEST str_index
=
16414 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16416 DW_STRING (attr
) = read_str_index (reader
, str_index
);
16417 DW_STRING_IS_CANONICAL (attr
) = 0;
16418 info_ptr
+= bytes_read
;
16422 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
16423 dwarf_form_name (form
),
16424 bfd_get_filename (abfd
));
16428 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
16429 attr
->form
= DW_FORM_GNU_ref_alt
;
16431 /* We have seen instances where the compiler tried to emit a byte
16432 size attribute of -1 which ended up being encoded as an unsigned
16433 0xffffffff. Although 0xffffffff is technically a valid size value,
16434 an object of this size seems pretty unlikely so we can relatively
16435 safely treat these cases as if the size attribute was invalid and
16436 treat them as zero by default. */
16437 if (attr
->name
== DW_AT_byte_size
16438 && form
== DW_FORM_data4
16439 && DW_UNSND (attr
) >= 0xffffffff)
16442 (&symfile_complaints
,
16443 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
16444 hex_string (DW_UNSND (attr
)));
16445 DW_UNSND (attr
) = 0;
16451 /* Read an attribute described by an abbreviated attribute. */
16453 static const gdb_byte
*
16454 read_attribute (const struct die_reader_specs
*reader
,
16455 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
16456 const gdb_byte
*info_ptr
)
16458 attr
->name
= abbrev
->name
;
16459 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
16462 /* Read dwarf information from a buffer. */
16464 static unsigned int
16465 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
16467 return bfd_get_8 (abfd
, buf
);
16471 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
16473 return bfd_get_signed_8 (abfd
, buf
);
16476 static unsigned int
16477 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16479 return bfd_get_16 (abfd
, buf
);
16483 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16485 return bfd_get_signed_16 (abfd
, buf
);
16488 static unsigned int
16489 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16491 return bfd_get_32 (abfd
, buf
);
16495 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16497 return bfd_get_signed_32 (abfd
, buf
);
16501 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16503 return bfd_get_64 (abfd
, buf
);
16507 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
16508 unsigned int *bytes_read
)
16510 struct comp_unit_head
*cu_header
= &cu
->header
;
16511 CORE_ADDR retval
= 0;
16513 if (cu_header
->signed_addr_p
)
16515 switch (cu_header
->addr_size
)
16518 retval
= bfd_get_signed_16 (abfd
, buf
);
16521 retval
= bfd_get_signed_32 (abfd
, buf
);
16524 retval
= bfd_get_signed_64 (abfd
, buf
);
16527 internal_error (__FILE__
, __LINE__
,
16528 _("read_address: bad switch, signed [in module %s]"),
16529 bfd_get_filename (abfd
));
16534 switch (cu_header
->addr_size
)
16537 retval
= bfd_get_16 (abfd
, buf
);
16540 retval
= bfd_get_32 (abfd
, buf
);
16543 retval
= bfd_get_64 (abfd
, buf
);
16546 internal_error (__FILE__
, __LINE__
,
16547 _("read_address: bad switch, "
16548 "unsigned [in module %s]"),
16549 bfd_get_filename (abfd
));
16553 *bytes_read
= cu_header
->addr_size
;
16557 /* Read the initial length from a section. The (draft) DWARF 3
16558 specification allows the initial length to take up either 4 bytes
16559 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
16560 bytes describe the length and all offsets will be 8 bytes in length
16563 An older, non-standard 64-bit format is also handled by this
16564 function. The older format in question stores the initial length
16565 as an 8-byte quantity without an escape value. Lengths greater
16566 than 2^32 aren't very common which means that the initial 4 bytes
16567 is almost always zero. Since a length value of zero doesn't make
16568 sense for the 32-bit format, this initial zero can be considered to
16569 be an escape value which indicates the presence of the older 64-bit
16570 format. As written, the code can't detect (old format) lengths
16571 greater than 4GB. If it becomes necessary to handle lengths
16572 somewhat larger than 4GB, we could allow other small values (such
16573 as the non-sensical values of 1, 2, and 3) to also be used as
16574 escape values indicating the presence of the old format.
16576 The value returned via bytes_read should be used to increment the
16577 relevant pointer after calling read_initial_length().
16579 [ Note: read_initial_length() and read_offset() are based on the
16580 document entitled "DWARF Debugging Information Format", revision
16581 3, draft 8, dated November 19, 2001. This document was obtained
16584 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
16586 This document is only a draft and is subject to change. (So beware.)
16588 Details regarding the older, non-standard 64-bit format were
16589 determined empirically by examining 64-bit ELF files produced by
16590 the SGI toolchain on an IRIX 6.5 machine.
16592 - Kevin, July 16, 2002
16596 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
16598 LONGEST length
= bfd_get_32 (abfd
, buf
);
16600 if (length
== 0xffffffff)
16602 length
= bfd_get_64 (abfd
, buf
+ 4);
16605 else if (length
== 0)
16607 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
16608 length
= bfd_get_64 (abfd
, buf
);
16619 /* Cover function for read_initial_length.
16620 Returns the length of the object at BUF, and stores the size of the
16621 initial length in *BYTES_READ and stores the size that offsets will be in
16623 If the initial length size is not equivalent to that specified in
16624 CU_HEADER then issue a complaint.
16625 This is useful when reading non-comp-unit headers. */
16628 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
16629 const struct comp_unit_head
*cu_header
,
16630 unsigned int *bytes_read
,
16631 unsigned int *offset_size
)
16633 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
16635 gdb_assert (cu_header
->initial_length_size
== 4
16636 || cu_header
->initial_length_size
== 8
16637 || cu_header
->initial_length_size
== 12);
16639 if (cu_header
->initial_length_size
!= *bytes_read
)
16640 complaint (&symfile_complaints
,
16641 _("intermixed 32-bit and 64-bit DWARF sections"));
16643 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
16647 /* Read an offset from the data stream. The size of the offset is
16648 given by cu_header->offset_size. */
16651 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
16652 const struct comp_unit_head
*cu_header
,
16653 unsigned int *bytes_read
)
16655 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
16657 *bytes_read
= cu_header
->offset_size
;
16661 /* Read an offset from the data stream. */
16664 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
16666 LONGEST retval
= 0;
16668 switch (offset_size
)
16671 retval
= bfd_get_32 (abfd
, buf
);
16674 retval
= bfd_get_64 (abfd
, buf
);
16677 internal_error (__FILE__
, __LINE__
,
16678 _("read_offset_1: bad switch [in module %s]"),
16679 bfd_get_filename (abfd
));
16685 static const gdb_byte
*
16686 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
16688 /* If the size of a host char is 8 bits, we can return a pointer
16689 to the buffer, otherwise we have to copy the data to a buffer
16690 allocated on the temporary obstack. */
16691 gdb_assert (HOST_CHAR_BIT
== 8);
16695 static const char *
16696 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
16697 unsigned int *bytes_read_ptr
)
16699 /* If the size of a host char is 8 bits, we can return a pointer
16700 to the string, otherwise we have to copy the string to a buffer
16701 allocated on the temporary obstack. */
16702 gdb_assert (HOST_CHAR_BIT
== 8);
16705 *bytes_read_ptr
= 1;
16708 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
16709 return (const char *) buf
;
16712 static const char *
16713 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
16715 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
16716 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
16717 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
16718 bfd_get_filename (abfd
));
16719 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
16720 error (_("DW_FORM_strp pointing outside of "
16721 ".debug_str section [in module %s]"),
16722 bfd_get_filename (abfd
));
16723 gdb_assert (HOST_CHAR_BIT
== 8);
16724 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
16726 return (const char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
16729 /* Read a string at offset STR_OFFSET in the .debug_str section from
16730 the .dwz file DWZ. Throw an error if the offset is too large. If
16731 the string consists of a single NUL byte, return NULL; otherwise
16732 return a pointer to the string. */
16734 static const char *
16735 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
16737 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
16739 if (dwz
->str
.buffer
== NULL
)
16740 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
16741 "section [in module %s]"),
16742 bfd_get_filename (dwz
->dwz_bfd
));
16743 if (str_offset
>= dwz
->str
.size
)
16744 error (_("DW_FORM_GNU_strp_alt pointing outside of "
16745 ".debug_str section [in module %s]"),
16746 bfd_get_filename (dwz
->dwz_bfd
));
16747 gdb_assert (HOST_CHAR_BIT
== 8);
16748 if (dwz
->str
.buffer
[str_offset
] == '\0')
16750 return (const char *) (dwz
->str
.buffer
+ str_offset
);
16753 static const char *
16754 read_indirect_string (bfd
*abfd
, const gdb_byte
*buf
,
16755 const struct comp_unit_head
*cu_header
,
16756 unsigned int *bytes_read_ptr
)
16758 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
16760 return read_indirect_string_at_offset (abfd
, str_offset
);
16764 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
16765 unsigned int *bytes_read_ptr
)
16768 unsigned int num_read
;
16770 unsigned char byte
;
16777 byte
= bfd_get_8 (abfd
, buf
);
16780 result
|= ((ULONGEST
) (byte
& 127) << shift
);
16781 if ((byte
& 128) == 0)
16787 *bytes_read_ptr
= num_read
;
16792 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
16793 unsigned int *bytes_read_ptr
)
16796 int shift
, num_read
;
16797 unsigned char byte
;
16804 byte
= bfd_get_8 (abfd
, buf
);
16807 result
|= ((LONGEST
) (byte
& 127) << shift
);
16809 if ((byte
& 128) == 0)
16814 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
16815 result
|= -(((LONGEST
) 1) << shift
);
16816 *bytes_read_ptr
= num_read
;
16820 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
16821 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
16822 ADDR_SIZE is the size of addresses from the CU header. */
16825 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
16827 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16828 bfd
*abfd
= objfile
->obfd
;
16829 const gdb_byte
*info_ptr
;
16831 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
16832 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
16833 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
16834 objfile_name (objfile
));
16835 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
16836 error (_("DW_FORM_addr_index pointing outside of "
16837 ".debug_addr section [in module %s]"),
16838 objfile_name (objfile
));
16839 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
16840 + addr_base
+ addr_index
* addr_size
);
16841 if (addr_size
== 4)
16842 return bfd_get_32 (abfd
, info_ptr
);
16844 return bfd_get_64 (abfd
, info_ptr
);
16847 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
16850 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
16852 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
16855 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
16858 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
16859 unsigned int *bytes_read
)
16861 bfd
*abfd
= cu
->objfile
->obfd
;
16862 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
16864 return read_addr_index (cu
, addr_index
);
16867 /* Data structure to pass results from dwarf2_read_addr_index_reader
16868 back to dwarf2_read_addr_index. */
16870 struct dwarf2_read_addr_index_data
16872 ULONGEST addr_base
;
16876 /* die_reader_func for dwarf2_read_addr_index. */
16879 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
16880 const gdb_byte
*info_ptr
,
16881 struct die_info
*comp_unit_die
,
16885 struct dwarf2_cu
*cu
= reader
->cu
;
16886 struct dwarf2_read_addr_index_data
*aidata
=
16887 (struct dwarf2_read_addr_index_data
*) data
;
16889 aidata
->addr_base
= cu
->addr_base
;
16890 aidata
->addr_size
= cu
->header
.addr_size
;
16893 /* Given an index in .debug_addr, fetch the value.
16894 NOTE: This can be called during dwarf expression evaluation,
16895 long after the debug information has been read, and thus per_cu->cu
16896 may no longer exist. */
16899 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
16900 unsigned int addr_index
)
16902 struct objfile
*objfile
= per_cu
->objfile
;
16903 struct dwarf2_cu
*cu
= per_cu
->cu
;
16904 ULONGEST addr_base
;
16907 /* This is intended to be called from outside this file. */
16908 dw2_setup (objfile
);
16910 /* We need addr_base and addr_size.
16911 If we don't have PER_CU->cu, we have to get it.
16912 Nasty, but the alternative is storing the needed info in PER_CU,
16913 which at this point doesn't seem justified: it's not clear how frequently
16914 it would get used and it would increase the size of every PER_CU.
16915 Entry points like dwarf2_per_cu_addr_size do a similar thing
16916 so we're not in uncharted territory here.
16917 Alas we need to be a bit more complicated as addr_base is contained
16920 We don't need to read the entire CU(/TU).
16921 We just need the header and top level die.
16923 IWBN to use the aging mechanism to let us lazily later discard the CU.
16924 For now we skip this optimization. */
16928 addr_base
= cu
->addr_base
;
16929 addr_size
= cu
->header
.addr_size
;
16933 struct dwarf2_read_addr_index_data aidata
;
16935 /* Note: We can't use init_cutu_and_read_dies_simple here,
16936 we need addr_base. */
16937 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
16938 dwarf2_read_addr_index_reader
, &aidata
);
16939 addr_base
= aidata
.addr_base
;
16940 addr_size
= aidata
.addr_size
;
16943 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
16946 /* Given a DW_FORM_GNU_str_index, fetch the string.
16947 This is only used by the Fission support. */
16949 static const char *
16950 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
16952 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16953 const char *objf_name
= objfile_name (objfile
);
16954 bfd
*abfd
= objfile
->obfd
;
16955 struct dwarf2_cu
*cu
= reader
->cu
;
16956 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
16957 struct dwarf2_section_info
*str_offsets_section
=
16958 &reader
->dwo_file
->sections
.str_offsets
;
16959 const gdb_byte
*info_ptr
;
16960 ULONGEST str_offset
;
16961 static const char form_name
[] = "DW_FORM_GNU_str_index";
16963 dwarf2_read_section (objfile
, str_section
);
16964 dwarf2_read_section (objfile
, str_offsets_section
);
16965 if (str_section
->buffer
== NULL
)
16966 error (_("%s used without .debug_str.dwo section"
16967 " in CU at offset 0x%lx [in module %s]"),
16968 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
16969 if (str_offsets_section
->buffer
== NULL
)
16970 error (_("%s used without .debug_str_offsets.dwo section"
16971 " in CU at offset 0x%lx [in module %s]"),
16972 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
16973 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
16974 error (_("%s pointing outside of .debug_str_offsets.dwo"
16975 " section in CU at offset 0x%lx [in module %s]"),
16976 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
16977 info_ptr
= (str_offsets_section
->buffer
16978 + str_index
* cu
->header
.offset_size
);
16979 if (cu
->header
.offset_size
== 4)
16980 str_offset
= bfd_get_32 (abfd
, info_ptr
);
16982 str_offset
= bfd_get_64 (abfd
, info_ptr
);
16983 if (str_offset
>= str_section
->size
)
16984 error (_("Offset from %s pointing outside of"
16985 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
16986 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
16987 return (const char *) (str_section
->buffer
+ str_offset
);
16990 /* Return the length of an LEB128 number in BUF. */
16993 leb128_size (const gdb_byte
*buf
)
16995 const gdb_byte
*begin
= buf
;
17001 if ((byte
& 128) == 0)
17002 return buf
- begin
;
17007 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
17016 cu
->language
= language_c
;
17019 case DW_LANG_C_plus_plus
:
17020 case DW_LANG_C_plus_plus_11
:
17021 case DW_LANG_C_plus_plus_14
:
17022 cu
->language
= language_cplus
;
17025 cu
->language
= language_d
;
17027 case DW_LANG_Fortran77
:
17028 case DW_LANG_Fortran90
:
17029 case DW_LANG_Fortran95
:
17030 case DW_LANG_Fortran03
:
17031 case DW_LANG_Fortran08
:
17032 cu
->language
= language_fortran
;
17035 cu
->language
= language_go
;
17037 case DW_LANG_Mips_Assembler
:
17038 cu
->language
= language_asm
;
17040 case DW_LANG_Ada83
:
17041 case DW_LANG_Ada95
:
17042 cu
->language
= language_ada
;
17044 case DW_LANG_Modula2
:
17045 cu
->language
= language_m2
;
17047 case DW_LANG_Pascal83
:
17048 cu
->language
= language_pascal
;
17051 cu
->language
= language_objc
;
17054 case DW_LANG_Rust_old
:
17055 cu
->language
= language_rust
;
17057 case DW_LANG_Cobol74
:
17058 case DW_LANG_Cobol85
:
17060 cu
->language
= language_minimal
;
17063 cu
->language_defn
= language_def (cu
->language
);
17066 /* Return the named attribute or NULL if not there. */
17068 static struct attribute
*
17069 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17074 struct attribute
*spec
= NULL
;
17076 for (i
= 0; i
< die
->num_attrs
; ++i
)
17078 if (die
->attrs
[i
].name
== name
)
17079 return &die
->attrs
[i
];
17080 if (die
->attrs
[i
].name
== DW_AT_specification
17081 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
17082 spec
= &die
->attrs
[i
];
17088 die
= follow_die_ref (die
, spec
, &cu
);
17094 /* Return the named attribute or NULL if not there,
17095 but do not follow DW_AT_specification, etc.
17096 This is for use in contexts where we're reading .debug_types dies.
17097 Following DW_AT_specification, DW_AT_abstract_origin will take us
17098 back up the chain, and we want to go down. */
17100 static struct attribute
*
17101 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
17105 for (i
= 0; i
< die
->num_attrs
; ++i
)
17106 if (die
->attrs
[i
].name
== name
)
17107 return &die
->attrs
[i
];
17112 /* Return the string associated with a string-typed attribute, or NULL if it
17113 is either not found or is of an incorrect type. */
17115 static const char *
17116 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17118 struct attribute
*attr
;
17119 const char *str
= NULL
;
17121 attr
= dwarf2_attr (die
, name
, cu
);
17125 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_string
17126 || attr
->form
== DW_FORM_GNU_strp_alt
)
17127 str
= DW_STRING (attr
);
17129 complaint (&symfile_complaints
,
17130 _("string type expected for attribute %s for "
17131 "DIE at 0x%x in module %s"),
17132 dwarf_attr_name (name
), die
->offset
.sect_off
,
17133 objfile_name (cu
->objfile
));
17139 /* Return non-zero iff the attribute NAME is defined for the given DIE,
17140 and holds a non-zero value. This function should only be used for
17141 DW_FORM_flag or DW_FORM_flag_present attributes. */
17144 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
17146 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
17148 return (attr
&& DW_UNSND (attr
));
17152 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
17154 /* A DIE is a declaration if it has a DW_AT_declaration attribute
17155 which value is non-zero. However, we have to be careful with
17156 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
17157 (via dwarf2_flag_true_p) follows this attribute. So we may
17158 end up accidently finding a declaration attribute that belongs
17159 to a different DIE referenced by the specification attribute,
17160 even though the given DIE does not have a declaration attribute. */
17161 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
17162 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
17165 /* Return the die giving the specification for DIE, if there is
17166 one. *SPEC_CU is the CU containing DIE on input, and the CU
17167 containing the return value on output. If there is no
17168 specification, but there is an abstract origin, that is
17171 static struct die_info
*
17172 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
17174 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
17177 if (spec_attr
== NULL
)
17178 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
17180 if (spec_attr
== NULL
)
17183 return follow_die_ref (die
, spec_attr
, spec_cu
);
17186 /* Free the line_header structure *LH, and any arrays and strings it
17188 NOTE: This is also used as a "cleanup" function. */
17191 free_line_header (struct line_header
*lh
)
17193 if (lh
->standard_opcode_lengths
)
17194 xfree (lh
->standard_opcode_lengths
);
17196 /* Remember that all the lh->file_names[i].name pointers are
17197 pointers into debug_line_buffer, and don't need to be freed. */
17198 if (lh
->file_names
)
17199 xfree (lh
->file_names
);
17201 /* Similarly for the include directory names. */
17202 if (lh
->include_dirs
)
17203 xfree (lh
->include_dirs
);
17208 /* Stub for free_line_header to match void * callback types. */
17211 free_line_header_voidp (void *arg
)
17213 struct line_header
*lh
= (struct line_header
*) arg
;
17215 free_line_header (lh
);
17218 /* Add an entry to LH's include directory table. */
17221 add_include_dir (struct line_header
*lh
, const char *include_dir
)
17223 if (dwarf_line_debug
>= 2)
17224 fprintf_unfiltered (gdb_stdlog
, "Adding dir %u: %s\n",
17225 lh
->num_include_dirs
+ 1, include_dir
);
17227 /* Grow the array if necessary. */
17228 if (lh
->include_dirs_size
== 0)
17230 lh
->include_dirs_size
= 1; /* for testing */
17231 lh
->include_dirs
= XNEWVEC (const char *, lh
->include_dirs_size
);
17233 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
17235 lh
->include_dirs_size
*= 2;
17236 lh
->include_dirs
= XRESIZEVEC (const char *, lh
->include_dirs
,
17237 lh
->include_dirs_size
);
17240 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
17243 /* Add an entry to LH's file name table. */
17246 add_file_name (struct line_header
*lh
,
17248 unsigned int dir_index
,
17249 unsigned int mod_time
,
17250 unsigned int length
)
17252 struct file_entry
*fe
;
17254 if (dwarf_line_debug
>= 2)
17255 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
17256 lh
->num_file_names
+ 1, name
);
17258 /* Grow the array if necessary. */
17259 if (lh
->file_names_size
== 0)
17261 lh
->file_names_size
= 1; /* for testing */
17262 lh
->file_names
= XNEWVEC (struct file_entry
, lh
->file_names_size
);
17264 else if (lh
->num_file_names
>= lh
->file_names_size
)
17266 lh
->file_names_size
*= 2;
17268 = XRESIZEVEC (struct file_entry
, lh
->file_names
, lh
->file_names_size
);
17271 fe
= &lh
->file_names
[lh
->num_file_names
++];
17273 fe
->dir_index
= dir_index
;
17274 fe
->mod_time
= mod_time
;
17275 fe
->length
= length
;
17276 fe
->included_p
= 0;
17280 /* A convenience function to find the proper .debug_line section for a CU. */
17282 static struct dwarf2_section_info
*
17283 get_debug_line_section (struct dwarf2_cu
*cu
)
17285 struct dwarf2_section_info
*section
;
17287 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
17289 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17290 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
17291 else if (cu
->per_cu
->is_dwz
)
17293 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
17295 section
= &dwz
->line
;
17298 section
= &dwarf2_per_objfile
->line
;
17303 /* Read the statement program header starting at OFFSET in
17304 .debug_line, or .debug_line.dwo. Return a pointer
17305 to a struct line_header, allocated using xmalloc.
17306 Returns NULL if there is a problem reading the header, e.g., if it
17307 has a version we don't understand.
17309 NOTE: the strings in the include directory and file name tables of
17310 the returned object point into the dwarf line section buffer,
17311 and must not be freed. */
17313 static struct line_header
*
17314 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
17316 struct cleanup
*back_to
;
17317 struct line_header
*lh
;
17318 const gdb_byte
*line_ptr
;
17319 unsigned int bytes_read
, offset_size
;
17321 const char *cur_dir
, *cur_file
;
17322 struct dwarf2_section_info
*section
;
17325 section
= get_debug_line_section (cu
);
17326 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
17327 if (section
->buffer
== NULL
)
17329 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17330 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
17332 complaint (&symfile_complaints
, _("missing .debug_line section"));
17336 /* We can't do this until we know the section is non-empty.
17337 Only then do we know we have such a section. */
17338 abfd
= get_section_bfd_owner (section
);
17340 /* Make sure that at least there's room for the total_length field.
17341 That could be 12 bytes long, but we're just going to fudge that. */
17342 if (offset
+ 4 >= section
->size
)
17344 dwarf2_statement_list_fits_in_line_number_section_complaint ();
17348 lh
= XNEW (struct line_header
);
17349 memset (lh
, 0, sizeof (*lh
));
17350 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
17353 lh
->offset
.sect_off
= offset
;
17354 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
17356 line_ptr
= section
->buffer
+ offset
;
17358 /* Read in the header. */
17360 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
17361 &bytes_read
, &offset_size
);
17362 line_ptr
+= bytes_read
;
17363 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
17365 dwarf2_statement_list_fits_in_line_number_section_complaint ();
17366 do_cleanups (back_to
);
17369 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
17370 lh
->version
= read_2_bytes (abfd
, line_ptr
);
17372 if (lh
->version
> 4)
17374 /* This is a version we don't understand. The format could have
17375 changed in ways we don't handle properly so just punt. */
17376 complaint (&symfile_complaints
,
17377 _("unsupported version in .debug_line section"));
17380 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
17381 line_ptr
+= offset_size
;
17382 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
17384 if (lh
->version
>= 4)
17386 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
17390 lh
->maximum_ops_per_instruction
= 1;
17392 if (lh
->maximum_ops_per_instruction
== 0)
17394 lh
->maximum_ops_per_instruction
= 1;
17395 complaint (&symfile_complaints
,
17396 _("invalid maximum_ops_per_instruction "
17397 "in `.debug_line' section"));
17400 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
17402 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
17404 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
17406 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
17408 lh
->standard_opcode_lengths
= XNEWVEC (unsigned char, lh
->opcode_base
);
17410 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
17411 for (i
= 1; i
< lh
->opcode_base
; ++i
)
17413 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
17417 /* Read directory table. */
17418 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
17420 line_ptr
+= bytes_read
;
17421 add_include_dir (lh
, cur_dir
);
17423 line_ptr
+= bytes_read
;
17425 /* Read file name table. */
17426 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
17428 unsigned int dir_index
, mod_time
, length
;
17430 line_ptr
+= bytes_read
;
17431 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17432 line_ptr
+= bytes_read
;
17433 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17434 line_ptr
+= bytes_read
;
17435 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17436 line_ptr
+= bytes_read
;
17438 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
17440 line_ptr
+= bytes_read
;
17441 lh
->statement_program_start
= line_ptr
;
17443 if (line_ptr
> (section
->buffer
+ section
->size
))
17444 complaint (&symfile_complaints
,
17445 _("line number info header doesn't "
17446 "fit in `.debug_line' section"));
17448 discard_cleanups (back_to
);
17452 /* Subroutine of dwarf_decode_lines to simplify it.
17453 Return the file name of the psymtab for included file FILE_INDEX
17454 in line header LH of PST.
17455 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
17456 If space for the result is malloc'd, it will be freed by a cleanup.
17457 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
17459 The function creates dangling cleanup registration. */
17461 static const char *
17462 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
17463 const struct partial_symtab
*pst
,
17464 const char *comp_dir
)
17466 const struct file_entry fe
= lh
->file_names
[file_index
];
17467 const char *include_name
= fe
.name
;
17468 const char *include_name_to_compare
= include_name
;
17469 const char *dir_name
= NULL
;
17470 const char *pst_filename
;
17471 char *copied_name
= NULL
;
17474 if (fe
.dir_index
&& lh
->include_dirs
!= NULL
)
17475 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
17477 if (!IS_ABSOLUTE_PATH (include_name
)
17478 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
17480 /* Avoid creating a duplicate psymtab for PST.
17481 We do this by comparing INCLUDE_NAME and PST_FILENAME.
17482 Before we do the comparison, however, we need to account
17483 for DIR_NAME and COMP_DIR.
17484 First prepend dir_name (if non-NULL). If we still don't
17485 have an absolute path prepend comp_dir (if non-NULL).
17486 However, the directory we record in the include-file's
17487 psymtab does not contain COMP_DIR (to match the
17488 corresponding symtab(s)).
17493 bash$ gcc -g ./hello.c
17494 include_name = "hello.c"
17496 DW_AT_comp_dir = comp_dir = "/tmp"
17497 DW_AT_name = "./hello.c"
17501 if (dir_name
!= NULL
)
17503 char *tem
= concat (dir_name
, SLASH_STRING
,
17504 include_name
, (char *)NULL
);
17506 make_cleanup (xfree
, tem
);
17507 include_name
= tem
;
17508 include_name_to_compare
= include_name
;
17510 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
17512 char *tem
= concat (comp_dir
, SLASH_STRING
,
17513 include_name
, (char *)NULL
);
17515 make_cleanup (xfree
, tem
);
17516 include_name_to_compare
= tem
;
17520 pst_filename
= pst
->filename
;
17521 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
17523 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
17524 pst_filename
, (char *)NULL
);
17525 pst_filename
= copied_name
;
17528 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
17530 if (copied_name
!= NULL
)
17531 xfree (copied_name
);
17535 return include_name
;
17538 /* State machine to track the state of the line number program. */
17542 /* These are part of the standard DWARF line number state machine. */
17544 unsigned char op_index
;
17549 unsigned int discriminator
;
17551 /* Additional bits of state we need to track. */
17553 /* The last file that we called dwarf2_start_subfile for.
17554 This is only used for TLLs. */
17555 unsigned int last_file
;
17556 /* The last file a line number was recorded for. */
17557 struct subfile
*last_subfile
;
17559 /* The function to call to record a line. */
17560 record_line_ftype
*record_line
;
17562 /* The last line number that was recorded, used to coalesce
17563 consecutive entries for the same line. This can happen, for
17564 example, when discriminators are present. PR 17276. */
17565 unsigned int last_line
;
17566 int line_has_non_zero_discriminator
;
17567 } lnp_state_machine
;
17569 /* There's a lot of static state to pass to dwarf_record_line.
17570 This keeps it all together. */
17575 struct gdbarch
*gdbarch
;
17577 /* The line number header. */
17578 struct line_header
*line_header
;
17580 /* Non-zero if we're recording lines.
17581 Otherwise we're building partial symtabs and are just interested in
17582 finding include files mentioned by the line number program. */
17583 int record_lines_p
;
17584 } lnp_reader_state
;
17586 /* Ignore this record_line request. */
17589 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
17594 /* Return non-zero if we should add LINE to the line number table.
17595 LINE is the line to add, LAST_LINE is the last line that was added,
17596 LAST_SUBFILE is the subfile for LAST_LINE.
17597 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
17598 had a non-zero discriminator.
17600 We have to be careful in the presence of discriminators.
17601 E.g., for this line:
17603 for (i = 0; i < 100000; i++);
17605 clang can emit four line number entries for that one line,
17606 each with a different discriminator.
17607 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
17609 However, we want gdb to coalesce all four entries into one.
17610 Otherwise the user could stepi into the middle of the line and
17611 gdb would get confused about whether the pc really was in the
17612 middle of the line.
17614 Things are further complicated by the fact that two consecutive
17615 line number entries for the same line is a heuristic used by gcc
17616 to denote the end of the prologue. So we can't just discard duplicate
17617 entries, we have to be selective about it. The heuristic we use is
17618 that we only collapse consecutive entries for the same line if at least
17619 one of those entries has a non-zero discriminator. PR 17276.
17621 Note: Addresses in the line number state machine can never go backwards
17622 within one sequence, thus this coalescing is ok. */
17625 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
17626 int line_has_non_zero_discriminator
,
17627 struct subfile
*last_subfile
)
17629 if (current_subfile
!= last_subfile
)
17631 if (line
!= last_line
)
17633 /* Same line for the same file that we've seen already.
17634 As a last check, for pr 17276, only record the line if the line
17635 has never had a non-zero discriminator. */
17636 if (!line_has_non_zero_discriminator
)
17641 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
17642 in the line table of subfile SUBFILE. */
17645 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
17646 unsigned int line
, CORE_ADDR address
,
17647 record_line_ftype p_record_line
)
17649 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
17651 if (dwarf_line_debug
)
17653 fprintf_unfiltered (gdb_stdlog
,
17654 "Recording line %u, file %s, address %s\n",
17655 line
, lbasename (subfile
->name
),
17656 paddress (gdbarch
, address
));
17659 (*p_record_line
) (subfile
, line
, addr
);
17662 /* Subroutine of dwarf_decode_lines_1 to simplify it.
17663 Mark the end of a set of line number records.
17664 The arguments are the same as for dwarf_record_line_1.
17665 If SUBFILE is NULL the request is ignored. */
17668 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
17669 CORE_ADDR address
, record_line_ftype p_record_line
)
17671 if (subfile
== NULL
)
17674 if (dwarf_line_debug
)
17676 fprintf_unfiltered (gdb_stdlog
,
17677 "Finishing current line, file %s, address %s\n",
17678 lbasename (subfile
->name
),
17679 paddress (gdbarch
, address
));
17682 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
17685 /* Record the line in STATE.
17686 END_SEQUENCE is non-zero if we're processing the end of a sequence. */
17689 dwarf_record_line (lnp_reader_state
*reader
, lnp_state_machine
*state
,
17692 const struct line_header
*lh
= reader
->line_header
;
17693 unsigned int file
, line
, discriminator
;
17696 file
= state
->file
;
17697 line
= state
->line
;
17698 is_stmt
= state
->is_stmt
;
17699 discriminator
= state
->discriminator
;
17701 if (dwarf_line_debug
)
17703 fprintf_unfiltered (gdb_stdlog
,
17704 "Processing actual line %u: file %u,"
17705 " address %s, is_stmt %u, discrim %u\n",
17707 paddress (reader
->gdbarch
, state
->address
),
17708 is_stmt
, discriminator
);
17711 if (file
== 0 || file
- 1 >= lh
->num_file_names
)
17712 dwarf2_debug_line_missing_file_complaint ();
17713 /* For now we ignore lines not starting on an instruction boundary.
17714 But not when processing end_sequence for compatibility with the
17715 previous version of the code. */
17716 else if (state
->op_index
== 0 || end_sequence
)
17718 lh
->file_names
[file
- 1].included_p
= 1;
17719 if (reader
->record_lines_p
&& is_stmt
)
17721 if (state
->last_subfile
!= current_subfile
|| end_sequence
)
17723 dwarf_finish_line (reader
->gdbarch
, state
->last_subfile
,
17724 state
->address
, state
->record_line
);
17729 if (dwarf_record_line_p (line
, state
->last_line
,
17730 state
->line_has_non_zero_discriminator
,
17731 state
->last_subfile
))
17733 dwarf_record_line_1 (reader
->gdbarch
, current_subfile
,
17734 line
, state
->address
,
17735 state
->record_line
);
17737 state
->last_subfile
= current_subfile
;
17738 state
->last_line
= line
;
17744 /* Initialize STATE for the start of a line number program. */
17747 init_lnp_state_machine (lnp_state_machine
*state
,
17748 const lnp_reader_state
*reader
)
17750 memset (state
, 0, sizeof (*state
));
17752 /* Just starting, there is no "last file". */
17753 state
->last_file
= 0;
17754 state
->last_subfile
= NULL
;
17756 state
->record_line
= record_line
;
17758 state
->last_line
= 0;
17759 state
->line_has_non_zero_discriminator
= 0;
17761 /* Initialize these according to the DWARF spec. */
17762 state
->op_index
= 0;
17765 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
17766 was a line entry for it so that the backend has a chance to adjust it
17767 and also record it in case it needs it. This is currently used by MIPS
17768 code, cf. `mips_adjust_dwarf2_line'. */
17769 state
->address
= gdbarch_adjust_dwarf2_line (reader
->gdbarch
, 0, 0);
17770 state
->is_stmt
= reader
->line_header
->default_is_stmt
;
17771 state
->discriminator
= 0;
17774 /* Check address and if invalid nop-out the rest of the lines in this
17778 check_line_address (struct dwarf2_cu
*cu
, lnp_state_machine
*state
,
17779 const gdb_byte
*line_ptr
,
17780 CORE_ADDR lowpc
, CORE_ADDR address
)
17782 /* If address < lowpc then it's not a usable value, it's outside the
17783 pc range of the CU. However, we restrict the test to only address
17784 values of zero to preserve GDB's previous behaviour which is to
17785 handle the specific case of a function being GC'd by the linker. */
17787 if (address
== 0 && address
< lowpc
)
17789 /* This line table is for a function which has been
17790 GCd by the linker. Ignore it. PR gdb/12528 */
17792 struct objfile
*objfile
= cu
->objfile
;
17793 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
17795 complaint (&symfile_complaints
,
17796 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
17797 line_offset
, objfile_name (objfile
));
17798 state
->record_line
= noop_record_line
;
17799 /* Note: sm.record_line is left as noop_record_line
17800 until we see DW_LNE_end_sequence. */
17804 /* Subroutine of dwarf_decode_lines to simplify it.
17805 Process the line number information in LH.
17806 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
17807 program in order to set included_p for every referenced header. */
17810 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
17811 const int decode_for_pst_p
, CORE_ADDR lowpc
)
17813 const gdb_byte
*line_ptr
, *extended_end
;
17814 const gdb_byte
*line_end
;
17815 unsigned int bytes_read
, extended_len
;
17816 unsigned char op_code
, extended_op
;
17817 CORE_ADDR baseaddr
;
17818 struct objfile
*objfile
= cu
->objfile
;
17819 bfd
*abfd
= objfile
->obfd
;
17820 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17821 /* Non-zero if we're recording line info (as opposed to building partial
17823 int record_lines_p
= !decode_for_pst_p
;
17824 /* A collection of things we need to pass to dwarf_record_line. */
17825 lnp_reader_state reader_state
;
17827 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17829 line_ptr
= lh
->statement_program_start
;
17830 line_end
= lh
->statement_program_end
;
17832 reader_state
.gdbarch
= gdbarch
;
17833 reader_state
.line_header
= lh
;
17834 reader_state
.record_lines_p
= record_lines_p
;
17836 /* Read the statement sequences until there's nothing left. */
17837 while (line_ptr
< line_end
)
17839 /* The DWARF line number program state machine. */
17840 lnp_state_machine state_machine
;
17841 int end_sequence
= 0;
17843 /* Reset the state machine at the start of each sequence. */
17844 init_lnp_state_machine (&state_machine
, &reader_state
);
17846 if (record_lines_p
&& lh
->num_file_names
>= state_machine
.file
)
17848 /* Start a subfile for the current file of the state machine. */
17849 /* lh->include_dirs and lh->file_names are 0-based, but the
17850 directory and file name numbers in the statement program
17852 struct file_entry
*fe
= &lh
->file_names
[state_machine
.file
- 1];
17853 const char *dir
= NULL
;
17855 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
17856 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
17858 dwarf2_start_subfile (fe
->name
, dir
);
17861 /* Decode the table. */
17862 while (line_ptr
< line_end
&& !end_sequence
)
17864 op_code
= read_1_byte (abfd
, line_ptr
);
17867 if (op_code
>= lh
->opcode_base
)
17869 /* Special opcode. */
17870 unsigned char adj_opcode
;
17871 CORE_ADDR addr_adj
;
17874 adj_opcode
= op_code
- lh
->opcode_base
;
17875 addr_adj
= (((state_machine
.op_index
17876 + (adj_opcode
/ lh
->line_range
))
17877 / lh
->maximum_ops_per_instruction
)
17878 * lh
->minimum_instruction_length
);
17879 state_machine
.address
17880 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
17881 state_machine
.op_index
= ((state_machine
.op_index
17882 + (adj_opcode
/ lh
->line_range
))
17883 % lh
->maximum_ops_per_instruction
);
17884 line_delta
= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
17885 state_machine
.line
+= line_delta
;
17886 if (line_delta
!= 0)
17887 state_machine
.line_has_non_zero_discriminator
17888 = state_machine
.discriminator
!= 0;
17890 dwarf_record_line (&reader_state
, &state_machine
, 0);
17891 state_machine
.discriminator
= 0;
17893 else switch (op_code
)
17895 case DW_LNS_extended_op
:
17896 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
17898 line_ptr
+= bytes_read
;
17899 extended_end
= line_ptr
+ extended_len
;
17900 extended_op
= read_1_byte (abfd
, line_ptr
);
17902 switch (extended_op
)
17904 case DW_LNE_end_sequence
:
17905 state_machine
.record_line
= record_line
;
17908 case DW_LNE_set_address
:
17911 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
17913 line_ptr
+= bytes_read
;
17914 check_line_address (cu
, &state_machine
, line_ptr
,
17916 state_machine
.op_index
= 0;
17917 address
+= baseaddr
;
17918 state_machine
.address
17919 = gdbarch_adjust_dwarf2_line (gdbarch
, address
, 0);
17922 case DW_LNE_define_file
:
17924 const char *cur_file
;
17925 unsigned int dir_index
, mod_time
, length
;
17927 cur_file
= read_direct_string (abfd
, line_ptr
,
17929 line_ptr
+= bytes_read
;
17931 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17932 line_ptr
+= bytes_read
;
17934 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17935 line_ptr
+= bytes_read
;
17937 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17938 line_ptr
+= bytes_read
;
17939 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
17942 case DW_LNE_set_discriminator
:
17943 /* The discriminator is not interesting to the debugger;
17944 just ignore it. We still need to check its value though:
17945 if there are consecutive entries for the same
17946 (non-prologue) line we want to coalesce them.
17948 state_machine
.discriminator
17949 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17950 state_machine
.line_has_non_zero_discriminator
17951 |= state_machine
.discriminator
!= 0;
17952 line_ptr
+= bytes_read
;
17955 complaint (&symfile_complaints
,
17956 _("mangled .debug_line section"));
17959 /* Make sure that we parsed the extended op correctly. If e.g.
17960 we expected a different address size than the producer used,
17961 we may have read the wrong number of bytes. */
17962 if (line_ptr
!= extended_end
)
17964 complaint (&symfile_complaints
,
17965 _("mangled .debug_line section"));
17970 dwarf_record_line (&reader_state
, &state_machine
, 0);
17971 state_machine
.discriminator
= 0;
17973 case DW_LNS_advance_pc
:
17976 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17977 CORE_ADDR addr_adj
;
17979 addr_adj
= (((state_machine
.op_index
+ adjust
)
17980 / lh
->maximum_ops_per_instruction
)
17981 * lh
->minimum_instruction_length
);
17982 state_machine
.address
17983 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
17984 state_machine
.op_index
= ((state_machine
.op_index
+ adjust
)
17985 % lh
->maximum_ops_per_instruction
);
17986 line_ptr
+= bytes_read
;
17989 case DW_LNS_advance_line
:
17992 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
17994 state_machine
.line
+= line_delta
;
17995 if (line_delta
!= 0)
17996 state_machine
.line_has_non_zero_discriminator
17997 = state_machine
.discriminator
!= 0;
17998 line_ptr
+= bytes_read
;
18001 case DW_LNS_set_file
:
18003 /* The arrays lh->include_dirs and lh->file_names are
18004 0-based, but the directory and file name numbers in
18005 the statement program are 1-based. */
18006 struct file_entry
*fe
;
18007 const char *dir
= NULL
;
18009 state_machine
.file
= read_unsigned_leb128 (abfd
, line_ptr
,
18011 line_ptr
+= bytes_read
;
18012 if (state_machine
.file
== 0
18013 || state_machine
.file
- 1 >= lh
->num_file_names
)
18014 dwarf2_debug_line_missing_file_complaint ();
18017 fe
= &lh
->file_names
[state_machine
.file
- 1];
18018 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
18019 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
18020 if (record_lines_p
)
18022 state_machine
.last_subfile
= current_subfile
;
18023 state_machine
.line_has_non_zero_discriminator
18024 = state_machine
.discriminator
!= 0;
18025 dwarf2_start_subfile (fe
->name
, dir
);
18030 case DW_LNS_set_column
:
18031 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18032 line_ptr
+= bytes_read
;
18034 case DW_LNS_negate_stmt
:
18035 state_machine
.is_stmt
= (!state_machine
.is_stmt
);
18037 case DW_LNS_set_basic_block
:
18039 /* Add to the address register of the state machine the
18040 address increment value corresponding to special opcode
18041 255. I.e., this value is scaled by the minimum
18042 instruction length since special opcode 255 would have
18043 scaled the increment. */
18044 case DW_LNS_const_add_pc
:
18046 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
18047 CORE_ADDR addr_adj
;
18049 addr_adj
= (((state_machine
.op_index
+ adjust
)
18050 / lh
->maximum_ops_per_instruction
)
18051 * lh
->minimum_instruction_length
);
18052 state_machine
.address
18053 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
18054 state_machine
.op_index
= ((state_machine
.op_index
+ adjust
)
18055 % lh
->maximum_ops_per_instruction
);
18058 case DW_LNS_fixed_advance_pc
:
18060 CORE_ADDR addr_adj
;
18062 addr_adj
= read_2_bytes (abfd
, line_ptr
);
18063 state_machine
.address
18064 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
18065 state_machine
.op_index
= 0;
18071 /* Unknown standard opcode, ignore it. */
18074 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
18076 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18077 line_ptr
+= bytes_read
;
18084 dwarf2_debug_line_missing_end_sequence_complaint ();
18086 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
18087 in which case we still finish recording the last line). */
18088 dwarf_record_line (&reader_state
, &state_machine
, 1);
18092 /* Decode the Line Number Program (LNP) for the given line_header
18093 structure and CU. The actual information extracted and the type
18094 of structures created from the LNP depends on the value of PST.
18096 1. If PST is NULL, then this procedure uses the data from the program
18097 to create all necessary symbol tables, and their linetables.
18099 2. If PST is not NULL, this procedure reads the program to determine
18100 the list of files included by the unit represented by PST, and
18101 builds all the associated partial symbol tables.
18103 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
18104 It is used for relative paths in the line table.
18105 NOTE: When processing partial symtabs (pst != NULL),
18106 comp_dir == pst->dirname.
18108 NOTE: It is important that psymtabs have the same file name (via strcmp)
18109 as the corresponding symtab. Since COMP_DIR is not used in the name of the
18110 symtab we don't use it in the name of the psymtabs we create.
18111 E.g. expand_line_sal requires this when finding psymtabs to expand.
18112 A good testcase for this is mb-inline.exp.
18114 LOWPC is the lowest address in CU (or 0 if not known).
18116 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
18117 for its PC<->lines mapping information. Otherwise only the filename
18118 table is read in. */
18121 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
18122 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
18123 CORE_ADDR lowpc
, int decode_mapping
)
18125 struct objfile
*objfile
= cu
->objfile
;
18126 const int decode_for_pst_p
= (pst
!= NULL
);
18128 if (decode_mapping
)
18129 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
18131 if (decode_for_pst_p
)
18135 /* Now that we're done scanning the Line Header Program, we can
18136 create the psymtab of each included file. */
18137 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
18138 if (lh
->file_names
[file_index
].included_p
== 1)
18140 const char *include_name
=
18141 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
18142 if (include_name
!= NULL
)
18143 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
18148 /* Make sure a symtab is created for every file, even files
18149 which contain only variables (i.e. no code with associated
18151 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
18154 for (i
= 0; i
< lh
->num_file_names
; i
++)
18156 const char *dir
= NULL
;
18157 struct file_entry
*fe
;
18159 fe
= &lh
->file_names
[i
];
18160 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
18161 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
18162 dwarf2_start_subfile (fe
->name
, dir
);
18164 if (current_subfile
->symtab
== NULL
)
18166 current_subfile
->symtab
18167 = allocate_symtab (cust
, current_subfile
->name
);
18169 fe
->symtab
= current_subfile
->symtab
;
18174 /* Start a subfile for DWARF. FILENAME is the name of the file and
18175 DIRNAME the name of the source directory which contains FILENAME
18176 or NULL if not known.
18177 This routine tries to keep line numbers from identical absolute and
18178 relative file names in a common subfile.
18180 Using the `list' example from the GDB testsuite, which resides in
18181 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
18182 of /srcdir/list0.c yields the following debugging information for list0.c:
18184 DW_AT_name: /srcdir/list0.c
18185 DW_AT_comp_dir: /compdir
18186 files.files[0].name: list0.h
18187 files.files[0].dir: /srcdir
18188 files.files[1].name: list0.c
18189 files.files[1].dir: /srcdir
18191 The line number information for list0.c has to end up in a single
18192 subfile, so that `break /srcdir/list0.c:1' works as expected.
18193 start_subfile will ensure that this happens provided that we pass the
18194 concatenation of files.files[1].dir and files.files[1].name as the
18198 dwarf2_start_subfile (const char *filename
, const char *dirname
)
18202 /* In order not to lose the line information directory,
18203 we concatenate it to the filename when it makes sense.
18204 Note that the Dwarf3 standard says (speaking of filenames in line
18205 information): ``The directory index is ignored for file names
18206 that represent full path names''. Thus ignoring dirname in the
18207 `else' branch below isn't an issue. */
18209 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
18211 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
18215 start_subfile (filename
);
18221 /* Start a symtab for DWARF.
18222 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
18224 static struct compunit_symtab
*
18225 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
18226 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
18228 struct compunit_symtab
*cust
18229 = start_symtab (cu
->objfile
, name
, comp_dir
, low_pc
);
18231 record_debugformat ("DWARF 2");
18232 record_producer (cu
->producer
);
18234 /* We assume that we're processing GCC output. */
18235 processing_gcc_compilation
= 2;
18237 cu
->processing_has_namespace_info
= 0;
18243 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
18244 struct dwarf2_cu
*cu
)
18246 struct objfile
*objfile
= cu
->objfile
;
18247 struct comp_unit_head
*cu_header
= &cu
->header
;
18249 /* NOTE drow/2003-01-30: There used to be a comment and some special
18250 code here to turn a symbol with DW_AT_external and a
18251 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
18252 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
18253 with some versions of binutils) where shared libraries could have
18254 relocations against symbols in their debug information - the
18255 minimal symbol would have the right address, but the debug info
18256 would not. It's no longer necessary, because we will explicitly
18257 apply relocations when we read in the debug information now. */
18259 /* A DW_AT_location attribute with no contents indicates that a
18260 variable has been optimized away. */
18261 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
18263 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
18267 /* Handle one degenerate form of location expression specially, to
18268 preserve GDB's previous behavior when section offsets are
18269 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
18270 then mark this symbol as LOC_STATIC. */
18272 if (attr_form_is_block (attr
)
18273 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
18274 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
18275 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
18276 && (DW_BLOCK (attr
)->size
18277 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
18279 unsigned int dummy
;
18281 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
18282 SYMBOL_VALUE_ADDRESS (sym
) =
18283 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
18285 SYMBOL_VALUE_ADDRESS (sym
) =
18286 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
18287 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
18288 fixup_symbol_section (sym
, objfile
);
18289 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
18290 SYMBOL_SECTION (sym
));
18294 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
18295 expression evaluator, and use LOC_COMPUTED only when necessary
18296 (i.e. when the value of a register or memory location is
18297 referenced, or a thread-local block, etc.). Then again, it might
18298 not be worthwhile. I'm assuming that it isn't unless performance
18299 or memory numbers show me otherwise. */
18301 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
18303 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
18304 cu
->has_loclist
= 1;
18307 /* Given a pointer to a DWARF information entry, figure out if we need
18308 to make a symbol table entry for it, and if so, create a new entry
18309 and return a pointer to it.
18310 If TYPE is NULL, determine symbol type from the die, otherwise
18311 used the passed type.
18312 If SPACE is not NULL, use it to hold the new symbol. If it is
18313 NULL, allocate a new symbol on the objfile's obstack. */
18315 static struct symbol
*
18316 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
18317 struct symbol
*space
)
18319 struct objfile
*objfile
= cu
->objfile
;
18320 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18321 struct symbol
*sym
= NULL
;
18323 struct attribute
*attr
= NULL
;
18324 struct attribute
*attr2
= NULL
;
18325 CORE_ADDR baseaddr
;
18326 struct pending
**list_to_add
= NULL
;
18328 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
18330 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18332 name
= dwarf2_name (die
, cu
);
18335 const char *linkagename
;
18336 int suppress_add
= 0;
18341 sym
= allocate_symbol (objfile
);
18342 OBJSTAT (objfile
, n_syms
++);
18344 /* Cache this symbol's name and the name's demangled form (if any). */
18345 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
18346 linkagename
= dwarf2_physname (name
, die
, cu
);
18347 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
18349 /* Fortran does not have mangling standard and the mangling does differ
18350 between gfortran, iFort etc. */
18351 if (cu
->language
== language_fortran
18352 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
18353 symbol_set_demangled_name (&(sym
->ginfo
),
18354 dwarf2_full_name (name
, die
, cu
),
18357 /* Default assumptions.
18358 Use the passed type or decode it from the die. */
18359 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
18360 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
18362 SYMBOL_TYPE (sym
) = type
;
18364 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
18365 attr
= dwarf2_attr (die
,
18366 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
18370 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
18373 attr
= dwarf2_attr (die
,
18374 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
18378 int file_index
= DW_UNSND (attr
);
18380 if (cu
->line_header
== NULL
18381 || file_index
> cu
->line_header
->num_file_names
)
18382 complaint (&symfile_complaints
,
18383 _("file index out of range"));
18384 else if (file_index
> 0)
18386 struct file_entry
*fe
;
18388 fe
= &cu
->line_header
->file_names
[file_index
- 1];
18389 symbol_set_symtab (sym
, fe
->symtab
);
18396 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
18401 addr
= attr_value_as_address (attr
);
18402 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
18403 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
18405 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
18406 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
18407 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
18408 add_symbol_to_list (sym
, cu
->list_in_scope
);
18410 case DW_TAG_subprogram
:
18411 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
18413 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
18414 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18415 if ((attr2
&& (DW_UNSND (attr2
) != 0))
18416 || cu
->language
== language_ada
)
18418 /* Subprograms marked external are stored as a global symbol.
18419 Ada subprograms, whether marked external or not, are always
18420 stored as a global symbol, because we want to be able to
18421 access them globally. For instance, we want to be able
18422 to break on a nested subprogram without having to
18423 specify the context. */
18424 list_to_add
= &global_symbols
;
18428 list_to_add
= cu
->list_in_scope
;
18431 case DW_TAG_inlined_subroutine
:
18432 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
18434 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
18435 SYMBOL_INLINED (sym
) = 1;
18436 list_to_add
= cu
->list_in_scope
;
18438 case DW_TAG_template_value_param
:
18440 /* Fall through. */
18441 case DW_TAG_constant
:
18442 case DW_TAG_variable
:
18443 case DW_TAG_member
:
18444 /* Compilation with minimal debug info may result in
18445 variables with missing type entries. Change the
18446 misleading `void' type to something sensible. */
18447 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
18449 = objfile_type (objfile
)->nodebug_data_symbol
;
18451 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
18452 /* In the case of DW_TAG_member, we should only be called for
18453 static const members. */
18454 if (die
->tag
== DW_TAG_member
)
18456 /* dwarf2_add_field uses die_is_declaration,
18457 so we do the same. */
18458 gdb_assert (die_is_declaration (die
, cu
));
18463 dwarf2_const_value (attr
, sym
, cu
);
18464 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18467 if (attr2
&& (DW_UNSND (attr2
) != 0))
18468 list_to_add
= &global_symbols
;
18470 list_to_add
= cu
->list_in_scope
;
18474 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
18477 var_decode_location (attr
, sym
, cu
);
18478 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18480 /* Fortran explicitly imports any global symbols to the local
18481 scope by DW_TAG_common_block. */
18482 if (cu
->language
== language_fortran
&& die
->parent
18483 && die
->parent
->tag
== DW_TAG_common_block
)
18486 if (SYMBOL_CLASS (sym
) == LOC_STATIC
18487 && SYMBOL_VALUE_ADDRESS (sym
) == 0
18488 && !dwarf2_per_objfile
->has_section_at_zero
)
18490 /* When a static variable is eliminated by the linker,
18491 the corresponding debug information is not stripped
18492 out, but the variable address is set to null;
18493 do not add such variables into symbol table. */
18495 else if (attr2
&& (DW_UNSND (attr2
) != 0))
18497 /* Workaround gfortran PR debug/40040 - it uses
18498 DW_AT_location for variables in -fPIC libraries which may
18499 get overriden by other libraries/executable and get
18500 a different address. Resolve it by the minimal symbol
18501 which may come from inferior's executable using copy
18502 relocation. Make this workaround only for gfortran as for
18503 other compilers GDB cannot guess the minimal symbol
18504 Fortran mangling kind. */
18505 if (cu
->language
== language_fortran
&& die
->parent
18506 && die
->parent
->tag
== DW_TAG_module
18508 && startswith (cu
->producer
, "GNU Fortran"))
18509 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
18511 /* A variable with DW_AT_external is never static,
18512 but it may be block-scoped. */
18513 list_to_add
= (cu
->list_in_scope
== &file_symbols
18514 ? &global_symbols
: cu
->list_in_scope
);
18517 list_to_add
= cu
->list_in_scope
;
18521 /* We do not know the address of this symbol.
18522 If it is an external symbol and we have type information
18523 for it, enter the symbol as a LOC_UNRESOLVED symbol.
18524 The address of the variable will then be determined from
18525 the minimal symbol table whenever the variable is
18527 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18529 /* Fortran explicitly imports any global symbols to the local
18530 scope by DW_TAG_common_block. */
18531 if (cu
->language
== language_fortran
&& die
->parent
18532 && die
->parent
->tag
== DW_TAG_common_block
)
18534 /* SYMBOL_CLASS doesn't matter here because
18535 read_common_block is going to reset it. */
18537 list_to_add
= cu
->list_in_scope
;
18539 else if (attr2
&& (DW_UNSND (attr2
) != 0)
18540 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
18542 /* A variable with DW_AT_external is never static, but it
18543 may be block-scoped. */
18544 list_to_add
= (cu
->list_in_scope
== &file_symbols
18545 ? &global_symbols
: cu
->list_in_scope
);
18547 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
18549 else if (!die_is_declaration (die
, cu
))
18551 /* Use the default LOC_OPTIMIZED_OUT class. */
18552 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
18554 list_to_add
= cu
->list_in_scope
;
18558 case DW_TAG_formal_parameter
:
18559 /* If we are inside a function, mark this as an argument. If
18560 not, we might be looking at an argument to an inlined function
18561 when we do not have enough information to show inlined frames;
18562 pretend it's a local variable in that case so that the user can
18564 if (context_stack_depth
> 0
18565 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
18566 SYMBOL_IS_ARGUMENT (sym
) = 1;
18567 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
18570 var_decode_location (attr
, sym
, cu
);
18572 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
18575 dwarf2_const_value (attr
, sym
, cu
);
18578 list_to_add
= cu
->list_in_scope
;
18580 case DW_TAG_unspecified_parameters
:
18581 /* From varargs functions; gdb doesn't seem to have any
18582 interest in this information, so just ignore it for now.
18585 case DW_TAG_template_type_param
:
18587 /* Fall through. */
18588 case DW_TAG_class_type
:
18589 case DW_TAG_interface_type
:
18590 case DW_TAG_structure_type
:
18591 case DW_TAG_union_type
:
18592 case DW_TAG_set_type
:
18593 case DW_TAG_enumeration_type
:
18594 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
18595 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
18598 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
18599 really ever be static objects: otherwise, if you try
18600 to, say, break of a class's method and you're in a file
18601 which doesn't mention that class, it won't work unless
18602 the check for all static symbols in lookup_symbol_aux
18603 saves you. See the OtherFileClass tests in
18604 gdb.c++/namespace.exp. */
18608 list_to_add
= (cu
->list_in_scope
== &file_symbols
18609 && cu
->language
== language_cplus
18610 ? &global_symbols
: cu
->list_in_scope
);
18612 /* The semantics of C++ state that "struct foo {
18613 ... }" also defines a typedef for "foo". */
18614 if (cu
->language
== language_cplus
18615 || cu
->language
== language_ada
18616 || cu
->language
== language_d
18617 || cu
->language
== language_rust
)
18619 /* The symbol's name is already allocated along
18620 with this objfile, so we don't need to
18621 duplicate it for the type. */
18622 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
18623 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
18628 case DW_TAG_typedef
:
18629 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
18630 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
18631 list_to_add
= cu
->list_in_scope
;
18633 case DW_TAG_base_type
:
18634 case DW_TAG_subrange_type
:
18635 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
18636 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
18637 list_to_add
= cu
->list_in_scope
;
18639 case DW_TAG_enumerator
:
18640 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
18643 dwarf2_const_value (attr
, sym
, cu
);
18646 /* NOTE: carlton/2003-11-10: See comment above in the
18647 DW_TAG_class_type, etc. block. */
18649 list_to_add
= (cu
->list_in_scope
== &file_symbols
18650 && cu
->language
== language_cplus
18651 ? &global_symbols
: cu
->list_in_scope
);
18654 case DW_TAG_imported_declaration
:
18655 case DW_TAG_namespace
:
18656 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
18657 list_to_add
= &global_symbols
;
18659 case DW_TAG_module
:
18660 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
18661 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
18662 list_to_add
= &global_symbols
;
18664 case DW_TAG_common_block
:
18665 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
18666 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
18667 add_symbol_to_list (sym
, cu
->list_in_scope
);
18670 /* Not a tag we recognize. Hopefully we aren't processing
18671 trash data, but since we must specifically ignore things
18672 we don't recognize, there is nothing else we should do at
18674 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
18675 dwarf_tag_name (die
->tag
));
18681 sym
->hash_next
= objfile
->template_symbols
;
18682 objfile
->template_symbols
= sym
;
18683 list_to_add
= NULL
;
18686 if (list_to_add
!= NULL
)
18687 add_symbol_to_list (sym
, list_to_add
);
18689 /* For the benefit of old versions of GCC, check for anonymous
18690 namespaces based on the demangled name. */
18691 if (!cu
->processing_has_namespace_info
18692 && cu
->language
== language_cplus
)
18693 cp_scan_for_anonymous_namespaces (sym
, objfile
);
18698 /* A wrapper for new_symbol_full that always allocates a new symbol. */
18700 static struct symbol
*
18701 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
18703 return new_symbol_full (die
, type
, cu
, NULL
);
18706 /* Given an attr with a DW_FORM_dataN value in host byte order,
18707 zero-extend it as appropriate for the symbol's type. The DWARF
18708 standard (v4) is not entirely clear about the meaning of using
18709 DW_FORM_dataN for a constant with a signed type, where the type is
18710 wider than the data. The conclusion of a discussion on the DWARF
18711 list was that this is unspecified. We choose to always zero-extend
18712 because that is the interpretation long in use by GCC. */
18715 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
18716 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
18718 struct objfile
*objfile
= cu
->objfile
;
18719 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
18720 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
18721 LONGEST l
= DW_UNSND (attr
);
18723 if (bits
< sizeof (*value
) * 8)
18725 l
&= ((LONGEST
) 1 << bits
) - 1;
18728 else if (bits
== sizeof (*value
) * 8)
18732 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
18733 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
18740 /* Read a constant value from an attribute. Either set *VALUE, or if
18741 the value does not fit in *VALUE, set *BYTES - either already
18742 allocated on the objfile obstack, or newly allocated on OBSTACK,
18743 or, set *BATON, if we translated the constant to a location
18747 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
18748 const char *name
, struct obstack
*obstack
,
18749 struct dwarf2_cu
*cu
,
18750 LONGEST
*value
, const gdb_byte
**bytes
,
18751 struct dwarf2_locexpr_baton
**baton
)
18753 struct objfile
*objfile
= cu
->objfile
;
18754 struct comp_unit_head
*cu_header
= &cu
->header
;
18755 struct dwarf_block
*blk
;
18756 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
18757 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
18763 switch (attr
->form
)
18766 case DW_FORM_GNU_addr_index
:
18770 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
18771 dwarf2_const_value_length_mismatch_complaint (name
,
18772 cu_header
->addr_size
,
18773 TYPE_LENGTH (type
));
18774 /* Symbols of this form are reasonably rare, so we just
18775 piggyback on the existing location code rather than writing
18776 a new implementation of symbol_computed_ops. */
18777 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
18778 (*baton
)->per_cu
= cu
->per_cu
;
18779 gdb_assert ((*baton
)->per_cu
);
18781 (*baton
)->size
= 2 + cu_header
->addr_size
;
18782 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
18783 (*baton
)->data
= data
;
18785 data
[0] = DW_OP_addr
;
18786 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
18787 byte_order
, DW_ADDR (attr
));
18788 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
18791 case DW_FORM_string
:
18793 case DW_FORM_GNU_str_index
:
18794 case DW_FORM_GNU_strp_alt
:
18795 /* DW_STRING is already allocated on the objfile obstack, point
18797 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
18799 case DW_FORM_block1
:
18800 case DW_FORM_block2
:
18801 case DW_FORM_block4
:
18802 case DW_FORM_block
:
18803 case DW_FORM_exprloc
:
18804 blk
= DW_BLOCK (attr
);
18805 if (TYPE_LENGTH (type
) != blk
->size
)
18806 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
18807 TYPE_LENGTH (type
));
18808 *bytes
= blk
->data
;
18811 /* The DW_AT_const_value attributes are supposed to carry the
18812 symbol's value "represented as it would be on the target
18813 architecture." By the time we get here, it's already been
18814 converted to host endianness, so we just need to sign- or
18815 zero-extend it as appropriate. */
18816 case DW_FORM_data1
:
18817 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
18819 case DW_FORM_data2
:
18820 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
18822 case DW_FORM_data4
:
18823 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
18825 case DW_FORM_data8
:
18826 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
18829 case DW_FORM_sdata
:
18830 *value
= DW_SND (attr
);
18833 case DW_FORM_udata
:
18834 *value
= DW_UNSND (attr
);
18838 complaint (&symfile_complaints
,
18839 _("unsupported const value attribute form: '%s'"),
18840 dwarf_form_name (attr
->form
));
18847 /* Copy constant value from an attribute to a symbol. */
18850 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
18851 struct dwarf2_cu
*cu
)
18853 struct objfile
*objfile
= cu
->objfile
;
18855 const gdb_byte
*bytes
;
18856 struct dwarf2_locexpr_baton
*baton
;
18858 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
18859 SYMBOL_PRINT_NAME (sym
),
18860 &objfile
->objfile_obstack
, cu
,
18861 &value
, &bytes
, &baton
);
18865 SYMBOL_LOCATION_BATON (sym
) = baton
;
18866 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
18868 else if (bytes
!= NULL
)
18870 SYMBOL_VALUE_BYTES (sym
) = bytes
;
18871 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
18875 SYMBOL_VALUE (sym
) = value
;
18876 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
18880 /* Return the type of the die in question using its DW_AT_type attribute. */
18882 static struct type
*
18883 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18885 struct attribute
*type_attr
;
18887 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
18890 /* A missing DW_AT_type represents a void type. */
18891 return objfile_type (cu
->objfile
)->builtin_void
;
18894 return lookup_die_type (die
, type_attr
, cu
);
18897 /* True iff CU's producer generates GNAT Ada auxiliary information
18898 that allows to find parallel types through that information instead
18899 of having to do expensive parallel lookups by type name. */
18902 need_gnat_info (struct dwarf2_cu
*cu
)
18904 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
18905 of GNAT produces this auxiliary information, without any indication
18906 that it is produced. Part of enhancing the FSF version of GNAT
18907 to produce that information will be to put in place an indicator
18908 that we can use in order to determine whether the descriptive type
18909 info is available or not. One suggestion that has been made is
18910 to use a new attribute, attached to the CU die. For now, assume
18911 that the descriptive type info is not available. */
18915 /* Return the auxiliary type of the die in question using its
18916 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
18917 attribute is not present. */
18919 static struct type
*
18920 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18922 struct attribute
*type_attr
;
18924 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
18928 return lookup_die_type (die
, type_attr
, cu
);
18931 /* If DIE has a descriptive_type attribute, then set the TYPE's
18932 descriptive type accordingly. */
18935 set_descriptive_type (struct type
*type
, struct die_info
*die
,
18936 struct dwarf2_cu
*cu
)
18938 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
18940 if (descriptive_type
)
18942 ALLOCATE_GNAT_AUX_TYPE (type
);
18943 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
18947 /* Return the containing type of the die in question using its
18948 DW_AT_containing_type attribute. */
18950 static struct type
*
18951 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18953 struct attribute
*type_attr
;
18955 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
18957 error (_("Dwarf Error: Problem turning containing type into gdb type "
18958 "[in module %s]"), objfile_name (cu
->objfile
));
18960 return lookup_die_type (die
, type_attr
, cu
);
18963 /* Return an error marker type to use for the ill formed type in DIE/CU. */
18965 static struct type
*
18966 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
18968 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18969 char *message
, *saved
;
18971 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
18972 objfile_name (objfile
),
18973 cu
->header
.offset
.sect_off
,
18974 die
->offset
.sect_off
);
18975 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
18976 message
, strlen (message
));
18979 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
18982 /* Look up the type of DIE in CU using its type attribute ATTR.
18983 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
18984 DW_AT_containing_type.
18985 If there is no type substitute an error marker. */
18987 static struct type
*
18988 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
18989 struct dwarf2_cu
*cu
)
18991 struct objfile
*objfile
= cu
->objfile
;
18992 struct type
*this_type
;
18994 gdb_assert (attr
->name
== DW_AT_type
18995 || attr
->name
== DW_AT_GNAT_descriptive_type
18996 || attr
->name
== DW_AT_containing_type
);
18998 /* First see if we have it cached. */
19000 if (attr
->form
== DW_FORM_GNU_ref_alt
)
19002 struct dwarf2_per_cu_data
*per_cu
;
19003 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
19005 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
19006 this_type
= get_die_type_at_offset (offset
, per_cu
);
19008 else if (attr_form_is_ref (attr
))
19010 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
19012 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
19014 else if (attr
->form
== DW_FORM_ref_sig8
)
19016 ULONGEST signature
= DW_SIGNATURE (attr
);
19018 return get_signatured_type (die
, signature
, cu
);
19022 complaint (&symfile_complaints
,
19023 _("Dwarf Error: Bad type attribute %s in DIE"
19024 " at 0x%x [in module %s]"),
19025 dwarf_attr_name (attr
->name
), die
->offset
.sect_off
,
19026 objfile_name (objfile
));
19027 return build_error_marker_type (cu
, die
);
19030 /* If not cached we need to read it in. */
19032 if (this_type
== NULL
)
19034 struct die_info
*type_die
= NULL
;
19035 struct dwarf2_cu
*type_cu
= cu
;
19037 if (attr_form_is_ref (attr
))
19038 type_die
= follow_die_ref (die
, attr
, &type_cu
);
19039 if (type_die
== NULL
)
19040 return build_error_marker_type (cu
, die
);
19041 /* If we find the type now, it's probably because the type came
19042 from an inter-CU reference and the type's CU got expanded before
19044 this_type
= read_type_die (type_die
, type_cu
);
19047 /* If we still don't have a type use an error marker. */
19049 if (this_type
== NULL
)
19050 return build_error_marker_type (cu
, die
);
19055 /* Return the type in DIE, CU.
19056 Returns NULL for invalid types.
19058 This first does a lookup in die_type_hash,
19059 and only reads the die in if necessary.
19061 NOTE: This can be called when reading in partial or full symbols. */
19063 static struct type
*
19064 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
19066 struct type
*this_type
;
19068 this_type
= get_die_type (die
, cu
);
19072 return read_type_die_1 (die
, cu
);
19075 /* Read the type in DIE, CU.
19076 Returns NULL for invalid types. */
19078 static struct type
*
19079 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
19081 struct type
*this_type
= NULL
;
19085 case DW_TAG_class_type
:
19086 case DW_TAG_interface_type
:
19087 case DW_TAG_structure_type
:
19088 case DW_TAG_union_type
:
19089 this_type
= read_structure_type (die
, cu
);
19091 case DW_TAG_enumeration_type
:
19092 this_type
= read_enumeration_type (die
, cu
);
19094 case DW_TAG_subprogram
:
19095 case DW_TAG_subroutine_type
:
19096 case DW_TAG_inlined_subroutine
:
19097 this_type
= read_subroutine_type (die
, cu
);
19099 case DW_TAG_array_type
:
19100 this_type
= read_array_type (die
, cu
);
19102 case DW_TAG_set_type
:
19103 this_type
= read_set_type (die
, cu
);
19105 case DW_TAG_pointer_type
:
19106 this_type
= read_tag_pointer_type (die
, cu
);
19108 case DW_TAG_ptr_to_member_type
:
19109 this_type
= read_tag_ptr_to_member_type (die
, cu
);
19111 case DW_TAG_reference_type
:
19112 this_type
= read_tag_reference_type (die
, cu
);
19114 case DW_TAG_const_type
:
19115 this_type
= read_tag_const_type (die
, cu
);
19117 case DW_TAG_volatile_type
:
19118 this_type
= read_tag_volatile_type (die
, cu
);
19120 case DW_TAG_restrict_type
:
19121 this_type
= read_tag_restrict_type (die
, cu
);
19123 case DW_TAG_string_type
:
19124 this_type
= read_tag_string_type (die
, cu
);
19126 case DW_TAG_typedef
:
19127 this_type
= read_typedef (die
, cu
);
19129 case DW_TAG_subrange_type
:
19130 this_type
= read_subrange_type (die
, cu
);
19132 case DW_TAG_base_type
:
19133 this_type
= read_base_type (die
, cu
);
19135 case DW_TAG_unspecified_type
:
19136 this_type
= read_unspecified_type (die
, cu
);
19138 case DW_TAG_namespace
:
19139 this_type
= read_namespace_type (die
, cu
);
19141 case DW_TAG_module
:
19142 this_type
= read_module_type (die
, cu
);
19144 case DW_TAG_atomic_type
:
19145 this_type
= read_tag_atomic_type (die
, cu
);
19148 complaint (&symfile_complaints
,
19149 _("unexpected tag in read_type_die: '%s'"),
19150 dwarf_tag_name (die
->tag
));
19157 /* See if we can figure out if the class lives in a namespace. We do
19158 this by looking for a member function; its demangled name will
19159 contain namespace info, if there is any.
19160 Return the computed name or NULL.
19161 Space for the result is allocated on the objfile's obstack.
19162 This is the full-die version of guess_partial_die_structure_name.
19163 In this case we know DIE has no useful parent. */
19166 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19168 struct die_info
*spec_die
;
19169 struct dwarf2_cu
*spec_cu
;
19170 struct die_info
*child
;
19173 spec_die
= die_specification (die
, &spec_cu
);
19174 if (spec_die
!= NULL
)
19180 for (child
= die
->child
;
19182 child
= child
->sibling
)
19184 if (child
->tag
== DW_TAG_subprogram
)
19186 const char *linkage_name
;
19188 linkage_name
= dwarf2_string_attr (child
, DW_AT_linkage_name
, cu
);
19189 if (linkage_name
== NULL
)
19190 linkage_name
= dwarf2_string_attr (child
, DW_AT_MIPS_linkage_name
,
19192 if (linkage_name
!= NULL
)
19195 = language_class_name_from_physname (cu
->language_defn
,
19199 if (actual_name
!= NULL
)
19201 const char *die_name
= dwarf2_name (die
, cu
);
19203 if (die_name
!= NULL
19204 && strcmp (die_name
, actual_name
) != 0)
19206 /* Strip off the class name from the full name.
19207 We want the prefix. */
19208 int die_name_len
= strlen (die_name
);
19209 int actual_name_len
= strlen (actual_name
);
19211 /* Test for '::' as a sanity check. */
19212 if (actual_name_len
> die_name_len
+ 2
19213 && actual_name
[actual_name_len
19214 - die_name_len
- 1] == ':')
19215 name
= (char *) obstack_copy0 (
19216 &cu
->objfile
->per_bfd
->storage_obstack
,
19217 actual_name
, actual_name_len
- die_name_len
- 2);
19220 xfree (actual_name
);
19229 /* GCC might emit a nameless typedef that has a linkage name. Determine the
19230 prefix part in such case. See
19231 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19234 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19236 struct attribute
*attr
;
19239 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
19240 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
19243 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
19246 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
19248 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
19249 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
19252 /* dwarf2_name had to be already called. */
19253 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
19255 /* Strip the base name, keep any leading namespaces/classes. */
19256 base
= strrchr (DW_STRING (attr
), ':');
19257 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
19260 return (char *) obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
19262 &base
[-1] - DW_STRING (attr
));
19265 /* Return the name of the namespace/class that DIE is defined within,
19266 or "" if we can't tell. The caller should not xfree the result.
19268 For example, if we're within the method foo() in the following
19278 then determine_prefix on foo's die will return "N::C". */
19280 static const char *
19281 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19283 struct die_info
*parent
, *spec_die
;
19284 struct dwarf2_cu
*spec_cu
;
19285 struct type
*parent_type
;
19288 if (cu
->language
!= language_cplus
19289 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
19290 && cu
->language
!= language_rust
)
19293 retval
= anonymous_struct_prefix (die
, cu
);
19297 /* We have to be careful in the presence of DW_AT_specification.
19298 For example, with GCC 3.4, given the code
19302 // Definition of N::foo.
19306 then we'll have a tree of DIEs like this:
19308 1: DW_TAG_compile_unit
19309 2: DW_TAG_namespace // N
19310 3: DW_TAG_subprogram // declaration of N::foo
19311 4: DW_TAG_subprogram // definition of N::foo
19312 DW_AT_specification // refers to die #3
19314 Thus, when processing die #4, we have to pretend that we're in
19315 the context of its DW_AT_specification, namely the contex of die
19318 spec_die
= die_specification (die
, &spec_cu
);
19319 if (spec_die
== NULL
)
19320 parent
= die
->parent
;
19323 parent
= spec_die
->parent
;
19327 if (parent
== NULL
)
19329 else if (parent
->building_fullname
)
19332 const char *parent_name
;
19334 /* It has been seen on RealView 2.2 built binaries,
19335 DW_TAG_template_type_param types actually _defined_ as
19336 children of the parent class:
19339 template class <class Enum> Class{};
19340 Class<enum E> class_e;
19342 1: DW_TAG_class_type (Class)
19343 2: DW_TAG_enumeration_type (E)
19344 3: DW_TAG_enumerator (enum1:0)
19345 3: DW_TAG_enumerator (enum2:1)
19347 2: DW_TAG_template_type_param
19348 DW_AT_type DW_FORM_ref_udata (E)
19350 Besides being broken debug info, it can put GDB into an
19351 infinite loop. Consider:
19353 When we're building the full name for Class<E>, we'll start
19354 at Class, and go look over its template type parameters,
19355 finding E. We'll then try to build the full name of E, and
19356 reach here. We're now trying to build the full name of E,
19357 and look over the parent DIE for containing scope. In the
19358 broken case, if we followed the parent DIE of E, we'd again
19359 find Class, and once again go look at its template type
19360 arguments, etc., etc. Simply don't consider such parent die
19361 as source-level parent of this die (it can't be, the language
19362 doesn't allow it), and break the loop here. */
19363 name
= dwarf2_name (die
, cu
);
19364 parent_name
= dwarf2_name (parent
, cu
);
19365 complaint (&symfile_complaints
,
19366 _("template param type '%s' defined within parent '%s'"),
19367 name
? name
: "<unknown>",
19368 parent_name
? parent_name
: "<unknown>");
19372 switch (parent
->tag
)
19374 case DW_TAG_namespace
:
19375 parent_type
= read_type_die (parent
, cu
);
19376 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
19377 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
19378 Work around this problem here. */
19379 if (cu
->language
== language_cplus
19380 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
19382 /* We give a name to even anonymous namespaces. */
19383 return TYPE_TAG_NAME (parent_type
);
19384 case DW_TAG_class_type
:
19385 case DW_TAG_interface_type
:
19386 case DW_TAG_structure_type
:
19387 case DW_TAG_union_type
:
19388 case DW_TAG_module
:
19389 parent_type
= read_type_die (parent
, cu
);
19390 if (TYPE_TAG_NAME (parent_type
) != NULL
)
19391 return TYPE_TAG_NAME (parent_type
);
19393 /* An anonymous structure is only allowed non-static data
19394 members; no typedefs, no member functions, et cetera.
19395 So it does not need a prefix. */
19397 case DW_TAG_compile_unit
:
19398 case DW_TAG_partial_unit
:
19399 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
19400 if (cu
->language
== language_cplus
19401 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
19402 && die
->child
!= NULL
19403 && (die
->tag
== DW_TAG_class_type
19404 || die
->tag
== DW_TAG_structure_type
19405 || die
->tag
== DW_TAG_union_type
))
19407 char *name
= guess_full_die_structure_name (die
, cu
);
19412 case DW_TAG_enumeration_type
:
19413 parent_type
= read_type_die (parent
, cu
);
19414 if (TYPE_DECLARED_CLASS (parent_type
))
19416 if (TYPE_TAG_NAME (parent_type
) != NULL
)
19417 return TYPE_TAG_NAME (parent_type
);
19420 /* Fall through. */
19422 return determine_prefix (parent
, cu
);
19426 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
19427 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
19428 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
19429 an obconcat, otherwise allocate storage for the result. The CU argument is
19430 used to determine the language and hence, the appropriate separator. */
19432 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
19435 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
19436 int physname
, struct dwarf2_cu
*cu
)
19438 const char *lead
= "";
19441 if (suffix
== NULL
|| suffix
[0] == '\0'
19442 || prefix
== NULL
|| prefix
[0] == '\0')
19444 else if (cu
->language
== language_d
)
19446 /* For D, the 'main' function could be defined in any module, but it
19447 should never be prefixed. */
19448 if (strcmp (suffix
, "D main") == 0)
19456 else if (cu
->language
== language_fortran
&& physname
)
19458 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
19459 DW_AT_MIPS_linkage_name is preferred and used instead. */
19467 if (prefix
== NULL
)
19469 if (suffix
== NULL
)
19476 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
19478 strcpy (retval
, lead
);
19479 strcat (retval
, prefix
);
19480 strcat (retval
, sep
);
19481 strcat (retval
, suffix
);
19486 /* We have an obstack. */
19487 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
19491 /* Return sibling of die, NULL if no sibling. */
19493 static struct die_info
*
19494 sibling_die (struct die_info
*die
)
19496 return die
->sibling
;
19499 /* Get name of a die, return NULL if not found. */
19501 static const char *
19502 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
19503 struct obstack
*obstack
)
19505 if (name
&& cu
->language
== language_cplus
)
19507 std::string canon_name
= cp_canonicalize_string (name
);
19509 if (!canon_name
.empty ())
19511 if (canon_name
!= name
)
19512 name
= (const char *) obstack_copy0 (obstack
,
19513 canon_name
.c_str (),
19514 canon_name
.length ());
19521 /* Get name of a die, return NULL if not found.
19522 Anonymous namespaces are converted to their magic string. */
19524 static const char *
19525 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19527 struct attribute
*attr
;
19529 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
19530 if ((!attr
|| !DW_STRING (attr
))
19531 && die
->tag
!= DW_TAG_namespace
19532 && die
->tag
!= DW_TAG_class_type
19533 && die
->tag
!= DW_TAG_interface_type
19534 && die
->tag
!= DW_TAG_structure_type
19535 && die
->tag
!= DW_TAG_union_type
)
19540 case DW_TAG_compile_unit
:
19541 case DW_TAG_partial_unit
:
19542 /* Compilation units have a DW_AT_name that is a filename, not
19543 a source language identifier. */
19544 case DW_TAG_enumeration_type
:
19545 case DW_TAG_enumerator
:
19546 /* These tags always have simple identifiers already; no need
19547 to canonicalize them. */
19548 return DW_STRING (attr
);
19550 case DW_TAG_namespace
:
19551 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
19552 return DW_STRING (attr
);
19553 return CP_ANONYMOUS_NAMESPACE_STR
;
19555 case DW_TAG_class_type
:
19556 case DW_TAG_interface_type
:
19557 case DW_TAG_structure_type
:
19558 case DW_TAG_union_type
:
19559 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
19560 structures or unions. These were of the form "._%d" in GCC 4.1,
19561 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
19562 and GCC 4.4. We work around this problem by ignoring these. */
19563 if (attr
&& DW_STRING (attr
)
19564 && (startswith (DW_STRING (attr
), "._")
19565 || startswith (DW_STRING (attr
), "<anonymous")))
19568 /* GCC might emit a nameless typedef that has a linkage name. See
19569 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19570 if (!attr
|| DW_STRING (attr
) == NULL
)
19572 char *demangled
= NULL
;
19574 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
19576 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
19578 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
19581 /* Avoid demangling DW_STRING (attr) the second time on a second
19582 call for the same DIE. */
19583 if (!DW_STRING_IS_CANONICAL (attr
))
19584 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
19590 /* FIXME: we already did this for the partial symbol... */
19593 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
19594 demangled
, strlen (demangled
)));
19595 DW_STRING_IS_CANONICAL (attr
) = 1;
19598 /* Strip any leading namespaces/classes, keep only the base name.
19599 DW_AT_name for named DIEs does not contain the prefixes. */
19600 base
= strrchr (DW_STRING (attr
), ':');
19601 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
19604 return DW_STRING (attr
);
19613 if (!DW_STRING_IS_CANONICAL (attr
))
19616 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
19617 &cu
->objfile
->per_bfd
->storage_obstack
);
19618 DW_STRING_IS_CANONICAL (attr
) = 1;
19620 return DW_STRING (attr
);
19623 /* Return the die that this die in an extension of, or NULL if there
19624 is none. *EXT_CU is the CU containing DIE on input, and the CU
19625 containing the return value on output. */
19627 static struct die_info
*
19628 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
19630 struct attribute
*attr
;
19632 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
19636 return follow_die_ref (die
, attr
, ext_cu
);
19639 /* Convert a DIE tag into its string name. */
19641 static const char *
19642 dwarf_tag_name (unsigned tag
)
19644 const char *name
= get_DW_TAG_name (tag
);
19647 return "DW_TAG_<unknown>";
19652 /* Convert a DWARF attribute code into its string name. */
19654 static const char *
19655 dwarf_attr_name (unsigned attr
)
19659 #ifdef MIPS /* collides with DW_AT_HP_block_index */
19660 if (attr
== DW_AT_MIPS_fde
)
19661 return "DW_AT_MIPS_fde";
19663 if (attr
== DW_AT_HP_block_index
)
19664 return "DW_AT_HP_block_index";
19667 name
= get_DW_AT_name (attr
);
19670 return "DW_AT_<unknown>";
19675 /* Convert a DWARF value form code into its string name. */
19677 static const char *
19678 dwarf_form_name (unsigned form
)
19680 const char *name
= get_DW_FORM_name (form
);
19683 return "DW_FORM_<unknown>";
19689 dwarf_bool_name (unsigned mybool
)
19697 /* Convert a DWARF type code into its string name. */
19699 static const char *
19700 dwarf_type_encoding_name (unsigned enc
)
19702 const char *name
= get_DW_ATE_name (enc
);
19705 return "DW_ATE_<unknown>";
19711 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
19715 print_spaces (indent
, f
);
19716 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
19717 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
19719 if (die
->parent
!= NULL
)
19721 print_spaces (indent
, f
);
19722 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
19723 die
->parent
->offset
.sect_off
);
19726 print_spaces (indent
, f
);
19727 fprintf_unfiltered (f
, " has children: %s\n",
19728 dwarf_bool_name (die
->child
!= NULL
));
19730 print_spaces (indent
, f
);
19731 fprintf_unfiltered (f
, " attributes:\n");
19733 for (i
= 0; i
< die
->num_attrs
; ++i
)
19735 print_spaces (indent
, f
);
19736 fprintf_unfiltered (f
, " %s (%s) ",
19737 dwarf_attr_name (die
->attrs
[i
].name
),
19738 dwarf_form_name (die
->attrs
[i
].form
));
19740 switch (die
->attrs
[i
].form
)
19743 case DW_FORM_GNU_addr_index
:
19744 fprintf_unfiltered (f
, "address: ");
19745 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
19747 case DW_FORM_block2
:
19748 case DW_FORM_block4
:
19749 case DW_FORM_block
:
19750 case DW_FORM_block1
:
19751 fprintf_unfiltered (f
, "block: size %s",
19752 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
19754 case DW_FORM_exprloc
:
19755 fprintf_unfiltered (f
, "expression: size %s",
19756 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
19758 case DW_FORM_ref_addr
:
19759 fprintf_unfiltered (f
, "ref address: ");
19760 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
19762 case DW_FORM_GNU_ref_alt
:
19763 fprintf_unfiltered (f
, "alt ref address: ");
19764 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
19770 case DW_FORM_ref_udata
:
19771 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
19772 (long) (DW_UNSND (&die
->attrs
[i
])));
19774 case DW_FORM_data1
:
19775 case DW_FORM_data2
:
19776 case DW_FORM_data4
:
19777 case DW_FORM_data8
:
19778 case DW_FORM_udata
:
19779 case DW_FORM_sdata
:
19780 fprintf_unfiltered (f
, "constant: %s",
19781 pulongest (DW_UNSND (&die
->attrs
[i
])));
19783 case DW_FORM_sec_offset
:
19784 fprintf_unfiltered (f
, "section offset: %s",
19785 pulongest (DW_UNSND (&die
->attrs
[i
])));
19787 case DW_FORM_ref_sig8
:
19788 fprintf_unfiltered (f
, "signature: %s",
19789 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
19791 case DW_FORM_string
:
19793 case DW_FORM_GNU_str_index
:
19794 case DW_FORM_GNU_strp_alt
:
19795 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
19796 DW_STRING (&die
->attrs
[i
])
19797 ? DW_STRING (&die
->attrs
[i
]) : "",
19798 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
19801 if (DW_UNSND (&die
->attrs
[i
]))
19802 fprintf_unfiltered (f
, "flag: TRUE");
19804 fprintf_unfiltered (f
, "flag: FALSE");
19806 case DW_FORM_flag_present
:
19807 fprintf_unfiltered (f
, "flag: TRUE");
19809 case DW_FORM_indirect
:
19810 /* The reader will have reduced the indirect form to
19811 the "base form" so this form should not occur. */
19812 fprintf_unfiltered (f
,
19813 "unexpected attribute form: DW_FORM_indirect");
19816 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
19817 die
->attrs
[i
].form
);
19820 fprintf_unfiltered (f
, "\n");
19825 dump_die_for_error (struct die_info
*die
)
19827 dump_die_shallow (gdb_stderr
, 0, die
);
19831 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
19833 int indent
= level
* 4;
19835 gdb_assert (die
!= NULL
);
19837 if (level
>= max_level
)
19840 dump_die_shallow (f
, indent
, die
);
19842 if (die
->child
!= NULL
)
19844 print_spaces (indent
, f
);
19845 fprintf_unfiltered (f
, " Children:");
19846 if (level
+ 1 < max_level
)
19848 fprintf_unfiltered (f
, "\n");
19849 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
19853 fprintf_unfiltered (f
,
19854 " [not printed, max nesting level reached]\n");
19858 if (die
->sibling
!= NULL
&& level
> 0)
19860 dump_die_1 (f
, level
, max_level
, die
->sibling
);
19864 /* This is called from the pdie macro in gdbinit.in.
19865 It's not static so gcc will keep a copy callable from gdb. */
19868 dump_die (struct die_info
*die
, int max_level
)
19870 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
19874 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
19878 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
19884 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
19888 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
19890 sect_offset retval
= { DW_UNSND (attr
) };
19892 if (attr_form_is_ref (attr
))
19895 retval
.sect_off
= 0;
19896 complaint (&symfile_complaints
,
19897 _("unsupported die ref attribute form: '%s'"),
19898 dwarf_form_name (attr
->form
));
19902 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
19903 * the value held by the attribute is not constant. */
19906 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
19908 if (attr
->form
== DW_FORM_sdata
)
19909 return DW_SND (attr
);
19910 else if (attr
->form
== DW_FORM_udata
19911 || attr
->form
== DW_FORM_data1
19912 || attr
->form
== DW_FORM_data2
19913 || attr
->form
== DW_FORM_data4
19914 || attr
->form
== DW_FORM_data8
)
19915 return DW_UNSND (attr
);
19918 complaint (&symfile_complaints
,
19919 _("Attribute value is not a constant (%s)"),
19920 dwarf_form_name (attr
->form
));
19921 return default_value
;
19925 /* Follow reference or signature attribute ATTR of SRC_DIE.
19926 On entry *REF_CU is the CU of SRC_DIE.
19927 On exit *REF_CU is the CU of the result. */
19929 static struct die_info
*
19930 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
19931 struct dwarf2_cu
**ref_cu
)
19933 struct die_info
*die
;
19935 if (attr_form_is_ref (attr
))
19936 die
= follow_die_ref (src_die
, attr
, ref_cu
);
19937 else if (attr
->form
== DW_FORM_ref_sig8
)
19938 die
= follow_die_sig (src_die
, attr
, ref_cu
);
19941 dump_die_for_error (src_die
);
19942 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
19943 objfile_name ((*ref_cu
)->objfile
));
19949 /* Follow reference OFFSET.
19950 On entry *REF_CU is the CU of the source die referencing OFFSET.
19951 On exit *REF_CU is the CU of the result.
19952 Returns NULL if OFFSET is invalid. */
19954 static struct die_info
*
19955 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
19956 struct dwarf2_cu
**ref_cu
)
19958 struct die_info temp_die
;
19959 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
19961 gdb_assert (cu
->per_cu
!= NULL
);
19965 if (cu
->per_cu
->is_debug_types
)
19967 /* .debug_types CUs cannot reference anything outside their CU.
19968 If they need to, they have to reference a signatured type via
19969 DW_FORM_ref_sig8. */
19970 if (! offset_in_cu_p (&cu
->header
, offset
))
19973 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
19974 || ! offset_in_cu_p (&cu
->header
, offset
))
19976 struct dwarf2_per_cu_data
*per_cu
;
19978 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
19981 /* If necessary, add it to the queue and load its DIEs. */
19982 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
19983 load_full_comp_unit (per_cu
, cu
->language
);
19985 target_cu
= per_cu
->cu
;
19987 else if (cu
->dies
== NULL
)
19989 /* We're loading full DIEs during partial symbol reading. */
19990 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
19991 load_full_comp_unit (cu
->per_cu
, language_minimal
);
19994 *ref_cu
= target_cu
;
19995 temp_die
.offset
= offset
;
19996 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
19997 &temp_die
, offset
.sect_off
);
20000 /* Follow reference attribute ATTR of SRC_DIE.
20001 On entry *REF_CU is the CU of SRC_DIE.
20002 On exit *REF_CU is the CU of the result. */
20004 static struct die_info
*
20005 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
20006 struct dwarf2_cu
**ref_cu
)
20008 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
20009 struct dwarf2_cu
*cu
= *ref_cu
;
20010 struct die_info
*die
;
20012 die
= follow_die_offset (offset
,
20013 (attr
->form
== DW_FORM_GNU_ref_alt
20014 || cu
->per_cu
->is_dwz
),
20017 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
20018 "at 0x%x [in module %s]"),
20019 offset
.sect_off
, src_die
->offset
.sect_off
,
20020 objfile_name (cu
->objfile
));
20025 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
20026 Returned value is intended for DW_OP_call*. Returned
20027 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
20029 struct dwarf2_locexpr_baton
20030 dwarf2_fetch_die_loc_sect_off (sect_offset offset
,
20031 struct dwarf2_per_cu_data
*per_cu
,
20032 CORE_ADDR (*get_frame_pc
) (void *baton
),
20035 struct dwarf2_cu
*cu
;
20036 struct die_info
*die
;
20037 struct attribute
*attr
;
20038 struct dwarf2_locexpr_baton retval
;
20040 dw2_setup (per_cu
->objfile
);
20042 if (per_cu
->cu
== NULL
)
20047 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20048 Instead just throw an error, not much else we can do. */
20049 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
20050 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20053 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
20055 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
20056 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20058 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20061 /* DWARF: "If there is no such attribute, then there is no effect.".
20062 DATA is ignored if SIZE is 0. */
20064 retval
.data
= NULL
;
20067 else if (attr_form_is_section_offset (attr
))
20069 struct dwarf2_loclist_baton loclist_baton
;
20070 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
20073 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
20075 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
20077 retval
.size
= size
;
20081 if (!attr_form_is_block (attr
))
20082 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
20083 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
20084 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20086 retval
.data
= DW_BLOCK (attr
)->data
;
20087 retval
.size
= DW_BLOCK (attr
)->size
;
20089 retval
.per_cu
= cu
->per_cu
;
20091 age_cached_comp_units ();
20096 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
20099 struct dwarf2_locexpr_baton
20100 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
20101 struct dwarf2_per_cu_data
*per_cu
,
20102 CORE_ADDR (*get_frame_pc
) (void *baton
),
20105 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
20107 return dwarf2_fetch_die_loc_sect_off (offset
, per_cu
, get_frame_pc
, baton
);
20110 /* Write a constant of a given type as target-ordered bytes into
20113 static const gdb_byte
*
20114 write_constant_as_bytes (struct obstack
*obstack
,
20115 enum bfd_endian byte_order
,
20122 *len
= TYPE_LENGTH (type
);
20123 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20124 store_unsigned_integer (result
, *len
, byte_order
, value
);
20129 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
20130 pointer to the constant bytes and set LEN to the length of the
20131 data. If memory is needed, allocate it on OBSTACK. If the DIE
20132 does not have a DW_AT_const_value, return NULL. */
20135 dwarf2_fetch_constant_bytes (sect_offset offset
,
20136 struct dwarf2_per_cu_data
*per_cu
,
20137 struct obstack
*obstack
,
20140 struct dwarf2_cu
*cu
;
20141 struct die_info
*die
;
20142 struct attribute
*attr
;
20143 const gdb_byte
*result
= NULL
;
20146 enum bfd_endian byte_order
;
20148 dw2_setup (per_cu
->objfile
);
20150 if (per_cu
->cu
== NULL
)
20155 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20156 Instead just throw an error, not much else we can do. */
20157 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
20158 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20161 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
20163 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
20164 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20167 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20171 byte_order
= (bfd_big_endian (per_cu
->objfile
->obfd
)
20172 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20174 switch (attr
->form
)
20177 case DW_FORM_GNU_addr_index
:
20181 *len
= cu
->header
.addr_size
;
20182 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20183 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
20187 case DW_FORM_string
:
20189 case DW_FORM_GNU_str_index
:
20190 case DW_FORM_GNU_strp_alt
:
20191 /* DW_STRING is already allocated on the objfile obstack, point
20193 result
= (const gdb_byte
*) DW_STRING (attr
);
20194 *len
= strlen (DW_STRING (attr
));
20196 case DW_FORM_block1
:
20197 case DW_FORM_block2
:
20198 case DW_FORM_block4
:
20199 case DW_FORM_block
:
20200 case DW_FORM_exprloc
:
20201 result
= DW_BLOCK (attr
)->data
;
20202 *len
= DW_BLOCK (attr
)->size
;
20205 /* The DW_AT_const_value attributes are supposed to carry the
20206 symbol's value "represented as it would be on the target
20207 architecture." By the time we get here, it's already been
20208 converted to host endianness, so we just need to sign- or
20209 zero-extend it as appropriate. */
20210 case DW_FORM_data1
:
20211 type
= die_type (die
, cu
);
20212 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
20213 if (result
== NULL
)
20214 result
= write_constant_as_bytes (obstack
, byte_order
,
20217 case DW_FORM_data2
:
20218 type
= die_type (die
, cu
);
20219 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
20220 if (result
== NULL
)
20221 result
= write_constant_as_bytes (obstack
, byte_order
,
20224 case DW_FORM_data4
:
20225 type
= die_type (die
, cu
);
20226 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
20227 if (result
== NULL
)
20228 result
= write_constant_as_bytes (obstack
, byte_order
,
20231 case DW_FORM_data8
:
20232 type
= die_type (die
, cu
);
20233 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
20234 if (result
== NULL
)
20235 result
= write_constant_as_bytes (obstack
, byte_order
,
20239 case DW_FORM_sdata
:
20240 type
= die_type (die
, cu
);
20241 result
= write_constant_as_bytes (obstack
, byte_order
,
20242 type
, DW_SND (attr
), len
);
20245 case DW_FORM_udata
:
20246 type
= die_type (die
, cu
);
20247 result
= write_constant_as_bytes (obstack
, byte_order
,
20248 type
, DW_UNSND (attr
), len
);
20252 complaint (&symfile_complaints
,
20253 _("unsupported const value attribute form: '%s'"),
20254 dwarf_form_name (attr
->form
));
20261 /* Return the type of the DIE at DIE_OFFSET in the CU named by
20265 dwarf2_get_die_type (cu_offset die_offset
,
20266 struct dwarf2_per_cu_data
*per_cu
)
20268 sect_offset die_offset_sect
;
20270 dw2_setup (per_cu
->objfile
);
20272 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
20273 return get_die_type_at_offset (die_offset_sect
, per_cu
);
20276 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
20277 On entry *REF_CU is the CU of SRC_DIE.
20278 On exit *REF_CU is the CU of the result.
20279 Returns NULL if the referenced DIE isn't found. */
20281 static struct die_info
*
20282 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
20283 struct dwarf2_cu
**ref_cu
)
20285 struct die_info temp_die
;
20286 struct dwarf2_cu
*sig_cu
;
20287 struct die_info
*die
;
20289 /* While it might be nice to assert sig_type->type == NULL here,
20290 we can get here for DW_AT_imported_declaration where we need
20291 the DIE not the type. */
20293 /* If necessary, add it to the queue and load its DIEs. */
20295 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
20296 read_signatured_type (sig_type
);
20298 sig_cu
= sig_type
->per_cu
.cu
;
20299 gdb_assert (sig_cu
!= NULL
);
20300 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
20301 temp_die
.offset
= sig_type
->type_offset_in_section
;
20302 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
20303 temp_die
.offset
.sect_off
);
20306 /* For .gdb_index version 7 keep track of included TUs.
20307 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
20308 if (dwarf2_per_objfile
->index_table
!= NULL
20309 && dwarf2_per_objfile
->index_table
->version
<= 7)
20311 VEC_safe_push (dwarf2_per_cu_ptr
,
20312 (*ref_cu
)->per_cu
->imported_symtabs
,
20323 /* Follow signatured type referenced by ATTR in SRC_DIE.
20324 On entry *REF_CU is the CU of SRC_DIE.
20325 On exit *REF_CU is the CU of the result.
20326 The result is the DIE of the type.
20327 If the referenced type cannot be found an error is thrown. */
20329 static struct die_info
*
20330 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20331 struct dwarf2_cu
**ref_cu
)
20333 ULONGEST signature
= DW_SIGNATURE (attr
);
20334 struct signatured_type
*sig_type
;
20335 struct die_info
*die
;
20337 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
20339 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
20340 /* sig_type will be NULL if the signatured type is missing from
20342 if (sig_type
== NULL
)
20344 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
20345 " from DIE at 0x%x [in module %s]"),
20346 hex_string (signature
), src_die
->offset
.sect_off
,
20347 objfile_name ((*ref_cu
)->objfile
));
20350 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
20353 dump_die_for_error (src_die
);
20354 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
20355 " from DIE at 0x%x [in module %s]"),
20356 hex_string (signature
), src_die
->offset
.sect_off
,
20357 objfile_name ((*ref_cu
)->objfile
));
20363 /* Get the type specified by SIGNATURE referenced in DIE/CU,
20364 reading in and processing the type unit if necessary. */
20366 static struct type
*
20367 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
20368 struct dwarf2_cu
*cu
)
20370 struct signatured_type
*sig_type
;
20371 struct dwarf2_cu
*type_cu
;
20372 struct die_info
*type_die
;
20375 sig_type
= lookup_signatured_type (cu
, signature
);
20376 /* sig_type will be NULL if the signatured type is missing from
20378 if (sig_type
== NULL
)
20380 complaint (&symfile_complaints
,
20381 _("Dwarf Error: Cannot find signatured DIE %s referenced"
20382 " from DIE at 0x%x [in module %s]"),
20383 hex_string (signature
), die
->offset
.sect_off
,
20384 objfile_name (dwarf2_per_objfile
->objfile
));
20385 return build_error_marker_type (cu
, die
);
20388 /* If we already know the type we're done. */
20389 if (sig_type
->type
!= NULL
)
20390 return sig_type
->type
;
20393 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
20394 if (type_die
!= NULL
)
20396 /* N.B. We need to call get_die_type to ensure only one type for this DIE
20397 is created. This is important, for example, because for c++ classes
20398 we need TYPE_NAME set which is only done by new_symbol. Blech. */
20399 type
= read_type_die (type_die
, type_cu
);
20402 complaint (&symfile_complaints
,
20403 _("Dwarf Error: Cannot build signatured type %s"
20404 " referenced from DIE at 0x%x [in module %s]"),
20405 hex_string (signature
), die
->offset
.sect_off
,
20406 objfile_name (dwarf2_per_objfile
->objfile
));
20407 type
= build_error_marker_type (cu
, die
);
20412 complaint (&symfile_complaints
,
20413 _("Dwarf Error: Problem reading signatured DIE %s referenced"
20414 " from DIE at 0x%x [in module %s]"),
20415 hex_string (signature
), die
->offset
.sect_off
,
20416 objfile_name (dwarf2_per_objfile
->objfile
));
20417 type
= build_error_marker_type (cu
, die
);
20419 sig_type
->type
= type
;
20424 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
20425 reading in and processing the type unit if necessary. */
20427 static struct type
*
20428 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
20429 struct dwarf2_cu
*cu
) /* ARI: editCase function */
20431 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
20432 if (attr_form_is_ref (attr
))
20434 struct dwarf2_cu
*type_cu
= cu
;
20435 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
20437 return read_type_die (type_die
, type_cu
);
20439 else if (attr
->form
== DW_FORM_ref_sig8
)
20441 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
20445 complaint (&symfile_complaints
,
20446 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
20447 " at 0x%x [in module %s]"),
20448 dwarf_form_name (attr
->form
), die
->offset
.sect_off
,
20449 objfile_name (dwarf2_per_objfile
->objfile
));
20450 return build_error_marker_type (cu
, die
);
20454 /* Load the DIEs associated with type unit PER_CU into memory. */
20457 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
20459 struct signatured_type
*sig_type
;
20461 /* Caller is responsible for ensuring type_unit_groups don't get here. */
20462 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
20464 /* We have the per_cu, but we need the signatured_type.
20465 Fortunately this is an easy translation. */
20466 gdb_assert (per_cu
->is_debug_types
);
20467 sig_type
= (struct signatured_type
*) per_cu
;
20469 gdb_assert (per_cu
->cu
== NULL
);
20471 read_signatured_type (sig_type
);
20473 gdb_assert (per_cu
->cu
!= NULL
);
20476 /* die_reader_func for read_signatured_type.
20477 This is identical to load_full_comp_unit_reader,
20478 but is kept separate for now. */
20481 read_signatured_type_reader (const struct die_reader_specs
*reader
,
20482 const gdb_byte
*info_ptr
,
20483 struct die_info
*comp_unit_die
,
20487 struct dwarf2_cu
*cu
= reader
->cu
;
20489 gdb_assert (cu
->die_hash
== NULL
);
20491 htab_create_alloc_ex (cu
->header
.length
/ 12,
20495 &cu
->comp_unit_obstack
,
20496 hashtab_obstack_allocate
,
20497 dummy_obstack_deallocate
);
20500 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
20501 &info_ptr
, comp_unit_die
);
20502 cu
->dies
= comp_unit_die
;
20503 /* comp_unit_die is not stored in die_hash, no need. */
20505 /* We try not to read any attributes in this function, because not
20506 all CUs needed for references have been loaded yet, and symbol
20507 table processing isn't initialized. But we have to set the CU language,
20508 or we won't be able to build types correctly.
20509 Similarly, if we do not read the producer, we can not apply
20510 producer-specific interpretation. */
20511 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
20514 /* Read in a signatured type and build its CU and DIEs.
20515 If the type is a stub for the real type in a DWO file,
20516 read in the real type from the DWO file as well. */
20519 read_signatured_type (struct signatured_type
*sig_type
)
20521 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
20523 gdb_assert (per_cu
->is_debug_types
);
20524 gdb_assert (per_cu
->cu
== NULL
);
20526 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
20527 read_signatured_type_reader
, NULL
);
20528 sig_type
->per_cu
.tu_read
= 1;
20531 /* Decode simple location descriptions.
20532 Given a pointer to a dwarf block that defines a location, compute
20533 the location and return the value.
20535 NOTE drow/2003-11-18: This function is called in two situations
20536 now: for the address of static or global variables (partial symbols
20537 only) and for offsets into structures which are expected to be
20538 (more or less) constant. The partial symbol case should go away,
20539 and only the constant case should remain. That will let this
20540 function complain more accurately. A few special modes are allowed
20541 without complaint for global variables (for instance, global
20542 register values and thread-local values).
20544 A location description containing no operations indicates that the
20545 object is optimized out. The return value is 0 for that case.
20546 FIXME drow/2003-11-16: No callers check for this case any more; soon all
20547 callers will only want a very basic result and this can become a
20550 Note that stack[0] is unused except as a default error return. */
20553 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
20555 struct objfile
*objfile
= cu
->objfile
;
20557 size_t size
= blk
->size
;
20558 const gdb_byte
*data
= blk
->data
;
20559 CORE_ADDR stack
[64];
20561 unsigned int bytes_read
, unsnd
;
20567 stack
[++stacki
] = 0;
20606 stack
[++stacki
] = op
- DW_OP_lit0
;
20641 stack
[++stacki
] = op
- DW_OP_reg0
;
20643 dwarf2_complex_location_expr_complaint ();
20647 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
20649 stack
[++stacki
] = unsnd
;
20651 dwarf2_complex_location_expr_complaint ();
20655 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
20660 case DW_OP_const1u
:
20661 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
20665 case DW_OP_const1s
:
20666 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
20670 case DW_OP_const2u
:
20671 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
20675 case DW_OP_const2s
:
20676 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
20680 case DW_OP_const4u
:
20681 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
20685 case DW_OP_const4s
:
20686 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
20690 case DW_OP_const8u
:
20691 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
20696 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
20702 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
20707 stack
[stacki
+ 1] = stack
[stacki
];
20712 stack
[stacki
- 1] += stack
[stacki
];
20716 case DW_OP_plus_uconst
:
20717 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
20723 stack
[stacki
- 1] -= stack
[stacki
];
20728 /* If we're not the last op, then we definitely can't encode
20729 this using GDB's address_class enum. This is valid for partial
20730 global symbols, although the variable's address will be bogus
20733 dwarf2_complex_location_expr_complaint ();
20736 case DW_OP_GNU_push_tls_address
:
20737 case DW_OP_form_tls_address
:
20738 /* The top of the stack has the offset from the beginning
20739 of the thread control block at which the variable is located. */
20740 /* Nothing should follow this operator, so the top of stack would
20742 /* This is valid for partial global symbols, but the variable's
20743 address will be bogus in the psymtab. Make it always at least
20744 non-zero to not look as a variable garbage collected by linker
20745 which have DW_OP_addr 0. */
20747 dwarf2_complex_location_expr_complaint ();
20751 case DW_OP_GNU_uninit
:
20754 case DW_OP_GNU_addr_index
:
20755 case DW_OP_GNU_const_index
:
20756 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
20763 const char *name
= get_DW_OP_name (op
);
20766 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
20769 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
20773 return (stack
[stacki
]);
20776 /* Enforce maximum stack depth of SIZE-1 to avoid writing
20777 outside of the allocated space. Also enforce minimum>0. */
20778 if (stacki
>= ARRAY_SIZE (stack
) - 1)
20780 complaint (&symfile_complaints
,
20781 _("location description stack overflow"));
20787 complaint (&symfile_complaints
,
20788 _("location description stack underflow"));
20792 return (stack
[stacki
]);
20795 /* memory allocation interface */
20797 static struct dwarf_block
*
20798 dwarf_alloc_block (struct dwarf2_cu
*cu
)
20800 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
20803 static struct die_info
*
20804 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
20806 struct die_info
*die
;
20807 size_t size
= sizeof (struct die_info
);
20810 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
20812 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
20813 memset (die
, 0, sizeof (struct die_info
));
20818 /* Macro support. */
20820 /* Return file name relative to the compilation directory of file number I in
20821 *LH's file name table. The result is allocated using xmalloc; the caller is
20822 responsible for freeing it. */
20825 file_file_name (int file
, struct line_header
*lh
)
20827 /* Is the file number a valid index into the line header's file name
20828 table? Remember that file numbers start with one, not zero. */
20829 if (1 <= file
&& file
<= lh
->num_file_names
)
20831 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
20833 if (IS_ABSOLUTE_PATH (fe
->name
) || fe
->dir_index
== 0
20834 || lh
->include_dirs
== NULL
)
20835 return xstrdup (fe
->name
);
20836 return concat (lh
->include_dirs
[fe
->dir_index
- 1], SLASH_STRING
,
20837 fe
->name
, (char *) NULL
);
20841 /* The compiler produced a bogus file number. We can at least
20842 record the macro definitions made in the file, even if we
20843 won't be able to find the file by name. */
20844 char fake_name
[80];
20846 xsnprintf (fake_name
, sizeof (fake_name
),
20847 "<bad macro file number %d>", file
);
20849 complaint (&symfile_complaints
,
20850 _("bad file number in macro information (%d)"),
20853 return xstrdup (fake_name
);
20857 /* Return the full name of file number I in *LH's file name table.
20858 Use COMP_DIR as the name of the current directory of the
20859 compilation. The result is allocated using xmalloc; the caller is
20860 responsible for freeing it. */
20862 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
20864 /* Is the file number a valid index into the line header's file name
20865 table? Remember that file numbers start with one, not zero. */
20866 if (1 <= file
&& file
<= lh
->num_file_names
)
20868 char *relative
= file_file_name (file
, lh
);
20870 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
20872 return reconcat (relative
, comp_dir
, SLASH_STRING
,
20873 relative
, (char *) NULL
);
20876 return file_file_name (file
, lh
);
20880 static struct macro_source_file
*
20881 macro_start_file (int file
, int line
,
20882 struct macro_source_file
*current_file
,
20883 struct line_header
*lh
)
20885 /* File name relative to the compilation directory of this source file. */
20886 char *file_name
= file_file_name (file
, lh
);
20888 if (! current_file
)
20890 /* Note: We don't create a macro table for this compilation unit
20891 at all until we actually get a filename. */
20892 struct macro_table
*macro_table
= get_macro_table ();
20894 /* If we have no current file, then this must be the start_file
20895 directive for the compilation unit's main source file. */
20896 current_file
= macro_set_main (macro_table
, file_name
);
20897 macro_define_special (macro_table
);
20900 current_file
= macro_include (current_file
, line
, file_name
);
20904 return current_file
;
20908 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
20909 followed by a null byte. */
20911 copy_string (const char *buf
, int len
)
20913 char *s
= (char *) xmalloc (len
+ 1);
20915 memcpy (s
, buf
, len
);
20921 static const char *
20922 consume_improper_spaces (const char *p
, const char *body
)
20926 complaint (&symfile_complaints
,
20927 _("macro definition contains spaces "
20928 "in formal argument list:\n`%s'"),
20940 parse_macro_definition (struct macro_source_file
*file
, int line
,
20945 /* The body string takes one of two forms. For object-like macro
20946 definitions, it should be:
20948 <macro name> " " <definition>
20950 For function-like macro definitions, it should be:
20952 <macro name> "() " <definition>
20954 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
20956 Spaces may appear only where explicitly indicated, and in the
20959 The Dwarf 2 spec says that an object-like macro's name is always
20960 followed by a space, but versions of GCC around March 2002 omit
20961 the space when the macro's definition is the empty string.
20963 The Dwarf 2 spec says that there should be no spaces between the
20964 formal arguments in a function-like macro's formal argument list,
20965 but versions of GCC around March 2002 include spaces after the
20969 /* Find the extent of the macro name. The macro name is terminated
20970 by either a space or null character (for an object-like macro) or
20971 an opening paren (for a function-like macro). */
20972 for (p
= body
; *p
; p
++)
20973 if (*p
== ' ' || *p
== '(')
20976 if (*p
== ' ' || *p
== '\0')
20978 /* It's an object-like macro. */
20979 int name_len
= p
- body
;
20980 char *name
= copy_string (body
, name_len
);
20981 const char *replacement
;
20984 replacement
= body
+ name_len
+ 1;
20987 dwarf2_macro_malformed_definition_complaint (body
);
20988 replacement
= body
+ name_len
;
20991 macro_define_object (file
, line
, name
, replacement
);
20995 else if (*p
== '(')
20997 /* It's a function-like macro. */
20998 char *name
= copy_string (body
, p
- body
);
21001 char **argv
= XNEWVEC (char *, argv_size
);
21005 p
= consume_improper_spaces (p
, body
);
21007 /* Parse the formal argument list. */
21008 while (*p
&& *p
!= ')')
21010 /* Find the extent of the current argument name. */
21011 const char *arg_start
= p
;
21013 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
21016 if (! *p
|| p
== arg_start
)
21017 dwarf2_macro_malformed_definition_complaint (body
);
21020 /* Make sure argv has room for the new argument. */
21021 if (argc
>= argv_size
)
21024 argv
= XRESIZEVEC (char *, argv
, argv_size
);
21027 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
21030 p
= consume_improper_spaces (p
, body
);
21032 /* Consume the comma, if present. */
21037 p
= consume_improper_spaces (p
, body
);
21046 /* Perfectly formed definition, no complaints. */
21047 macro_define_function (file
, line
, name
,
21048 argc
, (const char **) argv
,
21050 else if (*p
== '\0')
21052 /* Complain, but do define it. */
21053 dwarf2_macro_malformed_definition_complaint (body
);
21054 macro_define_function (file
, line
, name
,
21055 argc
, (const char **) argv
,
21059 /* Just complain. */
21060 dwarf2_macro_malformed_definition_complaint (body
);
21063 /* Just complain. */
21064 dwarf2_macro_malformed_definition_complaint (body
);
21070 for (i
= 0; i
< argc
; i
++)
21076 dwarf2_macro_malformed_definition_complaint (body
);
21079 /* Skip some bytes from BYTES according to the form given in FORM.
21080 Returns the new pointer. */
21082 static const gdb_byte
*
21083 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
21084 enum dwarf_form form
,
21085 unsigned int offset_size
,
21086 struct dwarf2_section_info
*section
)
21088 unsigned int bytes_read
;
21092 case DW_FORM_data1
:
21097 case DW_FORM_data2
:
21101 case DW_FORM_data4
:
21105 case DW_FORM_data8
:
21109 case DW_FORM_string
:
21110 read_direct_string (abfd
, bytes
, &bytes_read
);
21111 bytes
+= bytes_read
;
21114 case DW_FORM_sec_offset
:
21116 case DW_FORM_GNU_strp_alt
:
21117 bytes
+= offset_size
;
21120 case DW_FORM_block
:
21121 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
21122 bytes
+= bytes_read
;
21125 case DW_FORM_block1
:
21126 bytes
+= 1 + read_1_byte (abfd
, bytes
);
21128 case DW_FORM_block2
:
21129 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
21131 case DW_FORM_block4
:
21132 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
21135 case DW_FORM_sdata
:
21136 case DW_FORM_udata
:
21137 case DW_FORM_GNU_addr_index
:
21138 case DW_FORM_GNU_str_index
:
21139 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
21142 dwarf2_section_buffer_overflow_complaint (section
);
21150 complaint (&symfile_complaints
,
21151 _("invalid form 0x%x in `%s'"),
21152 form
, get_section_name (section
));
21160 /* A helper for dwarf_decode_macros that handles skipping an unknown
21161 opcode. Returns an updated pointer to the macro data buffer; or,
21162 on error, issues a complaint and returns NULL. */
21164 static const gdb_byte
*
21165 skip_unknown_opcode (unsigned int opcode
,
21166 const gdb_byte
**opcode_definitions
,
21167 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
21169 unsigned int offset_size
,
21170 struct dwarf2_section_info
*section
)
21172 unsigned int bytes_read
, i
;
21174 const gdb_byte
*defn
;
21176 if (opcode_definitions
[opcode
] == NULL
)
21178 complaint (&symfile_complaints
,
21179 _("unrecognized DW_MACFINO opcode 0x%x"),
21184 defn
= opcode_definitions
[opcode
];
21185 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
21186 defn
+= bytes_read
;
21188 for (i
= 0; i
< arg
; ++i
)
21190 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
21191 (enum dwarf_form
) defn
[i
], offset_size
,
21193 if (mac_ptr
== NULL
)
21195 /* skip_form_bytes already issued the complaint. */
21203 /* A helper function which parses the header of a macro section.
21204 If the macro section is the extended (for now called "GNU") type,
21205 then this updates *OFFSET_SIZE. Returns a pointer to just after
21206 the header, or issues a complaint and returns NULL on error. */
21208 static const gdb_byte
*
21209 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
21211 const gdb_byte
*mac_ptr
,
21212 unsigned int *offset_size
,
21213 int section_is_gnu
)
21215 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
21217 if (section_is_gnu
)
21219 unsigned int version
, flags
;
21221 version
= read_2_bytes (abfd
, mac_ptr
);
21224 complaint (&symfile_complaints
,
21225 _("unrecognized version `%d' in .debug_macro section"),
21231 flags
= read_1_byte (abfd
, mac_ptr
);
21233 *offset_size
= (flags
& 1) ? 8 : 4;
21235 if ((flags
& 2) != 0)
21236 /* We don't need the line table offset. */
21237 mac_ptr
+= *offset_size
;
21239 /* Vendor opcode descriptions. */
21240 if ((flags
& 4) != 0)
21242 unsigned int i
, count
;
21244 count
= read_1_byte (abfd
, mac_ptr
);
21246 for (i
= 0; i
< count
; ++i
)
21248 unsigned int opcode
, bytes_read
;
21251 opcode
= read_1_byte (abfd
, mac_ptr
);
21253 opcode_definitions
[opcode
] = mac_ptr
;
21254 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21255 mac_ptr
+= bytes_read
;
21264 /* A helper for dwarf_decode_macros that handles the GNU extensions,
21265 including DW_MACRO_GNU_transparent_include. */
21268 dwarf_decode_macro_bytes (bfd
*abfd
,
21269 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
21270 struct macro_source_file
*current_file
,
21271 struct line_header
*lh
,
21272 struct dwarf2_section_info
*section
,
21273 int section_is_gnu
, int section_is_dwz
,
21274 unsigned int offset_size
,
21275 htab_t include_hash
)
21277 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21278 enum dwarf_macro_record_type macinfo_type
;
21279 int at_commandline
;
21280 const gdb_byte
*opcode_definitions
[256];
21282 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
21283 &offset_size
, section_is_gnu
);
21284 if (mac_ptr
== NULL
)
21286 /* We already issued a complaint. */
21290 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
21291 GDB is still reading the definitions from command line. First
21292 DW_MACINFO_start_file will need to be ignored as it was already executed
21293 to create CURRENT_FILE for the main source holding also the command line
21294 definitions. On first met DW_MACINFO_start_file this flag is reset to
21295 normally execute all the remaining DW_MACINFO_start_file macinfos. */
21297 at_commandline
= 1;
21301 /* Do we at least have room for a macinfo type byte? */
21302 if (mac_ptr
>= mac_end
)
21304 dwarf2_section_buffer_overflow_complaint (section
);
21308 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
21311 /* Note that we rely on the fact that the corresponding GNU and
21312 DWARF constants are the same. */
21313 switch (macinfo_type
)
21315 /* A zero macinfo type indicates the end of the macro
21320 case DW_MACRO_GNU_define
:
21321 case DW_MACRO_GNU_undef
:
21322 case DW_MACRO_GNU_define_indirect
:
21323 case DW_MACRO_GNU_undef_indirect
:
21324 case DW_MACRO_GNU_define_indirect_alt
:
21325 case DW_MACRO_GNU_undef_indirect_alt
:
21327 unsigned int bytes_read
;
21332 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21333 mac_ptr
+= bytes_read
;
21335 if (macinfo_type
== DW_MACRO_GNU_define
21336 || macinfo_type
== DW_MACRO_GNU_undef
)
21338 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21339 mac_ptr
+= bytes_read
;
21343 LONGEST str_offset
;
21345 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
21346 mac_ptr
+= offset_size
;
21348 if (macinfo_type
== DW_MACRO_GNU_define_indirect_alt
21349 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
21352 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
21354 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
21357 body
= read_indirect_string_at_offset (abfd
, str_offset
);
21360 is_define
= (macinfo_type
== DW_MACRO_GNU_define
21361 || macinfo_type
== DW_MACRO_GNU_define_indirect
21362 || macinfo_type
== DW_MACRO_GNU_define_indirect_alt
);
21363 if (! current_file
)
21365 /* DWARF violation as no main source is present. */
21366 complaint (&symfile_complaints
,
21367 _("debug info with no main source gives macro %s "
21369 is_define
? _("definition") : _("undefinition"),
21373 if ((line
== 0 && !at_commandline
)
21374 || (line
!= 0 && at_commandline
))
21375 complaint (&symfile_complaints
,
21376 _("debug info gives %s macro %s with %s line %d: %s"),
21377 at_commandline
? _("command-line") : _("in-file"),
21378 is_define
? _("definition") : _("undefinition"),
21379 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
21382 parse_macro_definition (current_file
, line
, body
);
21385 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
21386 || macinfo_type
== DW_MACRO_GNU_undef_indirect
21387 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
);
21388 macro_undef (current_file
, line
, body
);
21393 case DW_MACRO_GNU_start_file
:
21395 unsigned int bytes_read
;
21398 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21399 mac_ptr
+= bytes_read
;
21400 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21401 mac_ptr
+= bytes_read
;
21403 if ((line
== 0 && !at_commandline
)
21404 || (line
!= 0 && at_commandline
))
21405 complaint (&symfile_complaints
,
21406 _("debug info gives source %d included "
21407 "from %s at %s line %d"),
21408 file
, at_commandline
? _("command-line") : _("file"),
21409 line
== 0 ? _("zero") : _("non-zero"), line
);
21411 if (at_commandline
)
21413 /* This DW_MACRO_GNU_start_file was executed in the
21415 at_commandline
= 0;
21418 current_file
= macro_start_file (file
, line
, current_file
, lh
);
21422 case DW_MACRO_GNU_end_file
:
21423 if (! current_file
)
21424 complaint (&symfile_complaints
,
21425 _("macro debug info has an unmatched "
21426 "`close_file' directive"));
21429 current_file
= current_file
->included_by
;
21430 if (! current_file
)
21432 enum dwarf_macro_record_type next_type
;
21434 /* GCC circa March 2002 doesn't produce the zero
21435 type byte marking the end of the compilation
21436 unit. Complain if it's not there, but exit no
21439 /* Do we at least have room for a macinfo type byte? */
21440 if (mac_ptr
>= mac_end
)
21442 dwarf2_section_buffer_overflow_complaint (section
);
21446 /* We don't increment mac_ptr here, so this is just
21449 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
21451 if (next_type
!= 0)
21452 complaint (&symfile_complaints
,
21453 _("no terminating 0-type entry for "
21454 "macros in `.debug_macinfo' section"));
21461 case DW_MACRO_GNU_transparent_include
:
21462 case DW_MACRO_GNU_transparent_include_alt
:
21466 bfd
*include_bfd
= abfd
;
21467 struct dwarf2_section_info
*include_section
= section
;
21468 const gdb_byte
*include_mac_end
= mac_end
;
21469 int is_dwz
= section_is_dwz
;
21470 const gdb_byte
*new_mac_ptr
;
21472 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
21473 mac_ptr
+= offset_size
;
21475 if (macinfo_type
== DW_MACRO_GNU_transparent_include_alt
)
21477 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
21479 dwarf2_read_section (objfile
, &dwz
->macro
);
21481 include_section
= &dwz
->macro
;
21482 include_bfd
= get_section_bfd_owner (include_section
);
21483 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
21487 new_mac_ptr
= include_section
->buffer
+ offset
;
21488 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
21492 /* This has actually happened; see
21493 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
21494 complaint (&symfile_complaints
,
21495 _("recursive DW_MACRO_GNU_transparent_include in "
21496 ".debug_macro section"));
21500 *slot
= (void *) new_mac_ptr
;
21502 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
21503 include_mac_end
, current_file
, lh
,
21504 section
, section_is_gnu
, is_dwz
,
21505 offset_size
, include_hash
);
21507 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
21512 case DW_MACINFO_vendor_ext
:
21513 if (!section_is_gnu
)
21515 unsigned int bytes_read
;
21517 /* This reads the constant, but since we don't recognize
21518 any vendor extensions, we ignore it. */
21519 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21520 mac_ptr
+= bytes_read
;
21521 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21522 mac_ptr
+= bytes_read
;
21524 /* We don't recognize any vendor extensions. */
21530 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
21531 mac_ptr
, mac_end
, abfd
, offset_size
,
21533 if (mac_ptr
== NULL
)
21537 } while (macinfo_type
!= 0);
21541 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
21542 int section_is_gnu
)
21544 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21545 struct line_header
*lh
= cu
->line_header
;
21547 const gdb_byte
*mac_ptr
, *mac_end
;
21548 struct macro_source_file
*current_file
= 0;
21549 enum dwarf_macro_record_type macinfo_type
;
21550 unsigned int offset_size
= cu
->header
.offset_size
;
21551 const gdb_byte
*opcode_definitions
[256];
21552 struct cleanup
*cleanup
;
21554 struct dwarf2_section_info
*section
;
21555 const char *section_name
;
21557 if (cu
->dwo_unit
!= NULL
)
21559 if (section_is_gnu
)
21561 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
21562 section_name
= ".debug_macro.dwo";
21566 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
21567 section_name
= ".debug_macinfo.dwo";
21572 if (section_is_gnu
)
21574 section
= &dwarf2_per_objfile
->macro
;
21575 section_name
= ".debug_macro";
21579 section
= &dwarf2_per_objfile
->macinfo
;
21580 section_name
= ".debug_macinfo";
21584 dwarf2_read_section (objfile
, section
);
21585 if (section
->buffer
== NULL
)
21587 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
21590 abfd
= get_section_bfd_owner (section
);
21592 /* First pass: Find the name of the base filename.
21593 This filename is needed in order to process all macros whose definition
21594 (or undefinition) comes from the command line. These macros are defined
21595 before the first DW_MACINFO_start_file entry, and yet still need to be
21596 associated to the base file.
21598 To determine the base file name, we scan the macro definitions until we
21599 reach the first DW_MACINFO_start_file entry. We then initialize
21600 CURRENT_FILE accordingly so that any macro definition found before the
21601 first DW_MACINFO_start_file can still be associated to the base file. */
21603 mac_ptr
= section
->buffer
+ offset
;
21604 mac_end
= section
->buffer
+ section
->size
;
21606 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
21607 &offset_size
, section_is_gnu
);
21608 if (mac_ptr
== NULL
)
21610 /* We already issued a complaint. */
21616 /* Do we at least have room for a macinfo type byte? */
21617 if (mac_ptr
>= mac_end
)
21619 /* Complaint is printed during the second pass as GDB will probably
21620 stop the first pass earlier upon finding
21621 DW_MACINFO_start_file. */
21625 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
21628 /* Note that we rely on the fact that the corresponding GNU and
21629 DWARF constants are the same. */
21630 switch (macinfo_type
)
21632 /* A zero macinfo type indicates the end of the macro
21637 case DW_MACRO_GNU_define
:
21638 case DW_MACRO_GNU_undef
:
21639 /* Only skip the data by MAC_PTR. */
21641 unsigned int bytes_read
;
21643 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21644 mac_ptr
+= bytes_read
;
21645 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21646 mac_ptr
+= bytes_read
;
21650 case DW_MACRO_GNU_start_file
:
21652 unsigned int bytes_read
;
21655 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21656 mac_ptr
+= bytes_read
;
21657 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21658 mac_ptr
+= bytes_read
;
21660 current_file
= macro_start_file (file
, line
, current_file
, lh
);
21664 case DW_MACRO_GNU_end_file
:
21665 /* No data to skip by MAC_PTR. */
21668 case DW_MACRO_GNU_define_indirect
:
21669 case DW_MACRO_GNU_undef_indirect
:
21670 case DW_MACRO_GNU_define_indirect_alt
:
21671 case DW_MACRO_GNU_undef_indirect_alt
:
21673 unsigned int bytes_read
;
21675 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21676 mac_ptr
+= bytes_read
;
21677 mac_ptr
+= offset_size
;
21681 case DW_MACRO_GNU_transparent_include
:
21682 case DW_MACRO_GNU_transparent_include_alt
:
21683 /* Note that, according to the spec, a transparent include
21684 chain cannot call DW_MACRO_GNU_start_file. So, we can just
21685 skip this opcode. */
21686 mac_ptr
+= offset_size
;
21689 case DW_MACINFO_vendor_ext
:
21690 /* Only skip the data by MAC_PTR. */
21691 if (!section_is_gnu
)
21693 unsigned int bytes_read
;
21695 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21696 mac_ptr
+= bytes_read
;
21697 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21698 mac_ptr
+= bytes_read
;
21703 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
21704 mac_ptr
, mac_end
, abfd
, offset_size
,
21706 if (mac_ptr
== NULL
)
21710 } while (macinfo_type
!= 0 && current_file
== NULL
);
21712 /* Second pass: Process all entries.
21714 Use the AT_COMMAND_LINE flag to determine whether we are still processing
21715 command-line macro definitions/undefinitions. This flag is unset when we
21716 reach the first DW_MACINFO_start_file entry. */
21718 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
21720 NULL
, xcalloc
, xfree
));
21721 mac_ptr
= section
->buffer
+ offset
;
21722 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
21723 *slot
= (void *) mac_ptr
;
21724 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
21725 current_file
, lh
, section
,
21726 section_is_gnu
, 0, offset_size
,
21727 include_hash
.get ());
21730 /* Check if the attribute's form is a DW_FORM_block*
21731 if so return true else false. */
21734 attr_form_is_block (const struct attribute
*attr
)
21736 return (attr
== NULL
? 0 :
21737 attr
->form
== DW_FORM_block1
21738 || attr
->form
== DW_FORM_block2
21739 || attr
->form
== DW_FORM_block4
21740 || attr
->form
== DW_FORM_block
21741 || attr
->form
== DW_FORM_exprloc
);
21744 /* Return non-zero if ATTR's value is a section offset --- classes
21745 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
21746 You may use DW_UNSND (attr) to retrieve such offsets.
21748 Section 7.5.4, "Attribute Encodings", explains that no attribute
21749 may have a value that belongs to more than one of these classes; it
21750 would be ambiguous if we did, because we use the same forms for all
21754 attr_form_is_section_offset (const struct attribute
*attr
)
21756 return (attr
->form
== DW_FORM_data4
21757 || attr
->form
== DW_FORM_data8
21758 || attr
->form
== DW_FORM_sec_offset
);
21761 /* Return non-zero if ATTR's value falls in the 'constant' class, or
21762 zero otherwise. When this function returns true, you can apply
21763 dwarf2_get_attr_constant_value to it.
21765 However, note that for some attributes you must check
21766 attr_form_is_section_offset before using this test. DW_FORM_data4
21767 and DW_FORM_data8 are members of both the constant class, and of
21768 the classes that contain offsets into other debug sections
21769 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
21770 that, if an attribute's can be either a constant or one of the
21771 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
21772 taken as section offsets, not constants. */
21775 attr_form_is_constant (const struct attribute
*attr
)
21777 switch (attr
->form
)
21779 case DW_FORM_sdata
:
21780 case DW_FORM_udata
:
21781 case DW_FORM_data1
:
21782 case DW_FORM_data2
:
21783 case DW_FORM_data4
:
21784 case DW_FORM_data8
:
21792 /* DW_ADDR is always stored already as sect_offset; despite for the forms
21793 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
21796 attr_form_is_ref (const struct attribute
*attr
)
21798 switch (attr
->form
)
21800 case DW_FORM_ref_addr
:
21805 case DW_FORM_ref_udata
:
21806 case DW_FORM_GNU_ref_alt
:
21813 /* Return the .debug_loc section to use for CU.
21814 For DWO files use .debug_loc.dwo. */
21816 static struct dwarf2_section_info
*
21817 cu_debug_loc_section (struct dwarf2_cu
*cu
)
21820 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
21821 return &dwarf2_per_objfile
->loc
;
21824 /* A helper function that fills in a dwarf2_loclist_baton. */
21827 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
21828 struct dwarf2_loclist_baton
*baton
,
21829 const struct attribute
*attr
)
21831 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
21833 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
21835 baton
->per_cu
= cu
->per_cu
;
21836 gdb_assert (baton
->per_cu
);
21837 /* We don't know how long the location list is, but make sure we
21838 don't run off the edge of the section. */
21839 baton
->size
= section
->size
- DW_UNSND (attr
);
21840 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
21841 baton
->base_address
= cu
->base_address
;
21842 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
21846 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
21847 struct dwarf2_cu
*cu
, int is_block
)
21849 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21850 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
21852 if (attr_form_is_section_offset (attr
)
21853 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
21854 the section. If so, fall through to the complaint in the
21856 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
21858 struct dwarf2_loclist_baton
*baton
;
21860 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
21862 fill_in_loclist_baton (cu
, baton
, attr
);
21864 if (cu
->base_known
== 0)
21865 complaint (&symfile_complaints
,
21866 _("Location list used without "
21867 "specifying the CU base address."));
21869 SYMBOL_ACLASS_INDEX (sym
) = (is_block
21870 ? dwarf2_loclist_block_index
21871 : dwarf2_loclist_index
);
21872 SYMBOL_LOCATION_BATON (sym
) = baton
;
21876 struct dwarf2_locexpr_baton
*baton
;
21878 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
21879 baton
->per_cu
= cu
->per_cu
;
21880 gdb_assert (baton
->per_cu
);
21882 if (attr_form_is_block (attr
))
21884 /* Note that we're just copying the block's data pointer
21885 here, not the actual data. We're still pointing into the
21886 info_buffer for SYM's objfile; right now we never release
21887 that buffer, but when we do clean up properly this may
21889 baton
->size
= DW_BLOCK (attr
)->size
;
21890 baton
->data
= DW_BLOCK (attr
)->data
;
21894 dwarf2_invalid_attrib_class_complaint ("location description",
21895 SYMBOL_NATURAL_NAME (sym
));
21899 SYMBOL_ACLASS_INDEX (sym
) = (is_block
21900 ? dwarf2_locexpr_block_index
21901 : dwarf2_locexpr_index
);
21902 SYMBOL_LOCATION_BATON (sym
) = baton
;
21906 /* Return the OBJFILE associated with the compilation unit CU. If CU
21907 came from a separate debuginfo file, then the master objfile is
21911 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
21913 struct objfile
*objfile
= per_cu
->objfile
;
21915 /* Return the master objfile, so that we can report and look up the
21916 correct file containing this variable. */
21917 if (objfile
->separate_debug_objfile_backlink
)
21918 objfile
= objfile
->separate_debug_objfile_backlink
;
21923 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
21924 (CU_HEADERP is unused in such case) or prepare a temporary copy at
21925 CU_HEADERP first. */
21927 static const struct comp_unit_head
*
21928 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
21929 struct dwarf2_per_cu_data
*per_cu
)
21931 const gdb_byte
*info_ptr
;
21934 return &per_cu
->cu
->header
;
21936 info_ptr
= per_cu
->section
->buffer
+ per_cu
->offset
.sect_off
;
21938 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
21939 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
21944 /* Return the address size given in the compilation unit header for CU. */
21947 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
21949 struct comp_unit_head cu_header_local
;
21950 const struct comp_unit_head
*cu_headerp
;
21952 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
21954 return cu_headerp
->addr_size
;
21957 /* Return the offset size given in the compilation unit header for CU. */
21960 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
21962 struct comp_unit_head cu_header_local
;
21963 const struct comp_unit_head
*cu_headerp
;
21965 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
21967 return cu_headerp
->offset_size
;
21970 /* See its dwarf2loc.h declaration. */
21973 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
21975 struct comp_unit_head cu_header_local
;
21976 const struct comp_unit_head
*cu_headerp
;
21978 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
21980 if (cu_headerp
->version
== 2)
21981 return cu_headerp
->addr_size
;
21983 return cu_headerp
->offset_size
;
21986 /* Return the text offset of the CU. The returned offset comes from
21987 this CU's objfile. If this objfile came from a separate debuginfo
21988 file, then the offset may be different from the corresponding
21989 offset in the parent objfile. */
21992 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
21994 struct objfile
*objfile
= per_cu
->objfile
;
21996 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21999 /* Locate the .debug_info compilation unit from CU's objfile which contains
22000 the DIE at OFFSET. Raises an error on failure. */
22002 static struct dwarf2_per_cu_data
*
22003 dwarf2_find_containing_comp_unit (sect_offset offset
,
22004 unsigned int offset_in_dwz
,
22005 struct objfile
*objfile
)
22007 struct dwarf2_per_cu_data
*this_cu
;
22009 const sect_offset
*cu_off
;
22012 high
= dwarf2_per_objfile
->n_comp_units
- 1;
22015 struct dwarf2_per_cu_data
*mid_cu
;
22016 int mid
= low
+ (high
- low
) / 2;
22018 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
22019 cu_off
= &mid_cu
->offset
;
22020 if (mid_cu
->is_dwz
> offset_in_dwz
22021 || (mid_cu
->is_dwz
== offset_in_dwz
22022 && cu_off
->sect_off
>= offset
.sect_off
))
22027 gdb_assert (low
== high
);
22028 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
22029 cu_off
= &this_cu
->offset
;
22030 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
22032 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
22033 error (_("Dwarf Error: could not find partial DIE containing "
22034 "offset 0x%lx [in module %s]"),
22035 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
22037 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
22038 <= offset
.sect_off
);
22039 return dwarf2_per_objfile
->all_comp_units
[low
-1];
22043 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
22044 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
22045 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
22046 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
22047 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
22052 /* Initialize dwarf2_cu CU, owned by PER_CU. */
22055 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
22057 memset (cu
, 0, sizeof (*cu
));
22059 cu
->per_cu
= per_cu
;
22060 cu
->objfile
= per_cu
->objfile
;
22061 obstack_init (&cu
->comp_unit_obstack
);
22064 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
22067 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
22068 enum language pretend_language
)
22070 struct attribute
*attr
;
22072 /* Set the language we're debugging. */
22073 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
22075 set_cu_language (DW_UNSND (attr
), cu
);
22078 cu
->language
= pretend_language
;
22079 cu
->language_defn
= language_def (cu
->language
);
22082 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
22085 /* Release one cached compilation unit, CU. We unlink it from the tree
22086 of compilation units, but we don't remove it from the read_in_chain;
22087 the caller is responsible for that.
22088 NOTE: DATA is a void * because this function is also used as a
22089 cleanup routine. */
22092 free_heap_comp_unit (void *data
)
22094 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
22096 gdb_assert (cu
->per_cu
!= NULL
);
22097 cu
->per_cu
->cu
= NULL
;
22100 obstack_free (&cu
->comp_unit_obstack
, NULL
);
22105 /* This cleanup function is passed the address of a dwarf2_cu on the stack
22106 when we're finished with it. We can't free the pointer itself, but be
22107 sure to unlink it from the cache. Also release any associated storage. */
22110 free_stack_comp_unit (void *data
)
22112 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
22114 gdb_assert (cu
->per_cu
!= NULL
);
22115 cu
->per_cu
->cu
= NULL
;
22118 obstack_free (&cu
->comp_unit_obstack
, NULL
);
22119 cu
->partial_dies
= NULL
;
22122 /* Free all cached compilation units. */
22125 free_cached_comp_units (void *data
)
22127 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22129 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22130 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22131 while (per_cu
!= NULL
)
22133 struct dwarf2_per_cu_data
*next_cu
;
22135 next_cu
= per_cu
->cu
->read_in_chain
;
22137 free_heap_comp_unit (per_cu
->cu
);
22138 *last_chain
= next_cu
;
22144 /* Increase the age counter on each cached compilation unit, and free
22145 any that are too old. */
22148 age_cached_comp_units (void)
22150 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22152 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
22153 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22154 while (per_cu
!= NULL
)
22156 per_cu
->cu
->last_used
++;
22157 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
22158 dwarf2_mark (per_cu
->cu
);
22159 per_cu
= per_cu
->cu
->read_in_chain
;
22162 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22163 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22164 while (per_cu
!= NULL
)
22166 struct dwarf2_per_cu_data
*next_cu
;
22168 next_cu
= per_cu
->cu
->read_in_chain
;
22170 if (!per_cu
->cu
->mark
)
22172 free_heap_comp_unit (per_cu
->cu
);
22173 *last_chain
= next_cu
;
22176 last_chain
= &per_cu
->cu
->read_in_chain
;
22182 /* Remove a single compilation unit from the cache. */
22185 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
22187 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22189 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22190 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22191 while (per_cu
!= NULL
)
22193 struct dwarf2_per_cu_data
*next_cu
;
22195 next_cu
= per_cu
->cu
->read_in_chain
;
22197 if (per_cu
== target_per_cu
)
22199 free_heap_comp_unit (per_cu
->cu
);
22201 *last_chain
= next_cu
;
22205 last_chain
= &per_cu
->cu
->read_in_chain
;
22211 /* Release all extra memory associated with OBJFILE. */
22214 dwarf2_free_objfile (struct objfile
*objfile
)
22217 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
22218 dwarf2_objfile_data_key
);
22220 if (dwarf2_per_objfile
== NULL
)
22223 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
22224 free_cached_comp_units (NULL
);
22226 if (dwarf2_per_objfile
->quick_file_names_table
)
22227 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
22229 if (dwarf2_per_objfile
->line_header_hash
)
22230 htab_delete (dwarf2_per_objfile
->line_header_hash
);
22232 /* Everything else should be on the objfile obstack. */
22235 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
22236 We store these in a hash table separate from the DIEs, and preserve them
22237 when the DIEs are flushed out of cache.
22239 The CU "per_cu" pointer is needed because offset alone is not enough to
22240 uniquely identify the type. A file may have multiple .debug_types sections,
22241 or the type may come from a DWO file. Furthermore, while it's more logical
22242 to use per_cu->section+offset, with Fission the section with the data is in
22243 the DWO file but we don't know that section at the point we need it.
22244 We have to use something in dwarf2_per_cu_data (or the pointer to it)
22245 because we can enter the lookup routine, get_die_type_at_offset, from
22246 outside this file, and thus won't necessarily have PER_CU->cu.
22247 Fortunately, PER_CU is stable for the life of the objfile. */
22249 struct dwarf2_per_cu_offset_and_type
22251 const struct dwarf2_per_cu_data
*per_cu
;
22252 sect_offset offset
;
22256 /* Hash function for a dwarf2_per_cu_offset_and_type. */
22259 per_cu_offset_and_type_hash (const void *item
)
22261 const struct dwarf2_per_cu_offset_and_type
*ofs
22262 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
22264 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
22267 /* Equality function for a dwarf2_per_cu_offset_and_type. */
22270 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
22272 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
22273 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
22274 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
22275 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
22277 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
22278 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
22281 /* Set the type associated with DIE to TYPE. Save it in CU's hash
22282 table if necessary. For convenience, return TYPE.
22284 The DIEs reading must have careful ordering to:
22285 * Not cause infite loops trying to read in DIEs as a prerequisite for
22286 reading current DIE.
22287 * Not trying to dereference contents of still incompletely read in types
22288 while reading in other DIEs.
22289 * Enable referencing still incompletely read in types just by a pointer to
22290 the type without accessing its fields.
22292 Therefore caller should follow these rules:
22293 * Try to fetch any prerequisite types we may need to build this DIE type
22294 before building the type and calling set_die_type.
22295 * After building type call set_die_type for current DIE as soon as
22296 possible before fetching more types to complete the current type.
22297 * Make the type as complete as possible before fetching more types. */
22299 static struct type
*
22300 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
22302 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
22303 struct objfile
*objfile
= cu
->objfile
;
22304 struct attribute
*attr
;
22305 struct dynamic_prop prop
;
22307 /* For Ada types, make sure that the gnat-specific data is always
22308 initialized (if not already set). There are a few types where
22309 we should not be doing so, because the type-specific area is
22310 already used to hold some other piece of info (eg: TYPE_CODE_FLT
22311 where the type-specific area is used to store the floatformat).
22312 But this is not a problem, because the gnat-specific information
22313 is actually not needed for these types. */
22314 if (need_gnat_info (cu
)
22315 && TYPE_CODE (type
) != TYPE_CODE_FUNC
22316 && TYPE_CODE (type
) != TYPE_CODE_FLT
22317 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
22318 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
22319 && TYPE_CODE (type
) != TYPE_CODE_METHOD
22320 && !HAVE_GNAT_AUX_INFO (type
))
22321 INIT_GNAT_SPECIFIC (type
);
22323 /* Read DW_AT_allocated and set in type. */
22324 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
22325 if (attr_form_is_block (attr
))
22327 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22328 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
, objfile
);
22330 else if (attr
!= NULL
)
22332 complaint (&symfile_complaints
,
22333 _("DW_AT_allocated has the wrong form (%s) at DIE 0x%x"),
22334 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
22335 die
->offset
.sect_off
);
22338 /* Read DW_AT_associated and set in type. */
22339 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
22340 if (attr_form_is_block (attr
))
22342 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22343 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
, objfile
);
22345 else if (attr
!= NULL
)
22347 complaint (&symfile_complaints
,
22348 _("DW_AT_associated has the wrong form (%s) at DIE 0x%x"),
22349 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
22350 die
->offset
.sect_off
);
22353 /* Read DW_AT_data_location and set in type. */
22354 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
22355 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22356 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
, objfile
);
22358 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
22360 dwarf2_per_objfile
->die_type_hash
=
22361 htab_create_alloc_ex (127,
22362 per_cu_offset_and_type_hash
,
22363 per_cu_offset_and_type_eq
,
22365 &objfile
->objfile_obstack
,
22366 hashtab_obstack_allocate
,
22367 dummy_obstack_deallocate
);
22370 ofs
.per_cu
= cu
->per_cu
;
22371 ofs
.offset
= die
->offset
;
22373 slot
= (struct dwarf2_per_cu_offset_and_type
**)
22374 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
22376 complaint (&symfile_complaints
,
22377 _("A problem internal to GDB: DIE 0x%x has type already set"),
22378 die
->offset
.sect_off
);
22379 *slot
= XOBNEW (&objfile
->objfile_obstack
,
22380 struct dwarf2_per_cu_offset_and_type
);
22385 /* Look up the type for the die at OFFSET in PER_CU in die_type_hash,
22386 or return NULL if the die does not have a saved type. */
22388 static struct type
*
22389 get_die_type_at_offset (sect_offset offset
,
22390 struct dwarf2_per_cu_data
*per_cu
)
22392 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
22394 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
22397 ofs
.per_cu
= per_cu
;
22398 ofs
.offset
= offset
;
22399 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
22400 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
22407 /* Look up the type for DIE in CU in die_type_hash,
22408 or return NULL if DIE does not have a saved type. */
22410 static struct type
*
22411 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22413 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
22416 /* Add a dependence relationship from CU to REF_PER_CU. */
22419 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
22420 struct dwarf2_per_cu_data
*ref_per_cu
)
22424 if (cu
->dependencies
== NULL
)
22426 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
22427 NULL
, &cu
->comp_unit_obstack
,
22428 hashtab_obstack_allocate
,
22429 dummy_obstack_deallocate
);
22431 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
22433 *slot
= ref_per_cu
;
22436 /* Subroutine of dwarf2_mark to pass to htab_traverse.
22437 Set the mark field in every compilation unit in the
22438 cache that we must keep because we are keeping CU. */
22441 dwarf2_mark_helper (void **slot
, void *data
)
22443 struct dwarf2_per_cu_data
*per_cu
;
22445 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
22447 /* cu->dependencies references may not yet have been ever read if QUIT aborts
22448 reading of the chain. As such dependencies remain valid it is not much
22449 useful to track and undo them during QUIT cleanups. */
22450 if (per_cu
->cu
== NULL
)
22453 if (per_cu
->cu
->mark
)
22455 per_cu
->cu
->mark
= 1;
22457 if (per_cu
->cu
->dependencies
!= NULL
)
22458 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
22463 /* Set the mark field in CU and in every other compilation unit in the
22464 cache that we must keep because we are keeping CU. */
22467 dwarf2_mark (struct dwarf2_cu
*cu
)
22472 if (cu
->dependencies
!= NULL
)
22473 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
22477 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
22481 per_cu
->cu
->mark
= 0;
22482 per_cu
= per_cu
->cu
->read_in_chain
;
22486 /* Trivial hash function for partial_die_info: the hash value of a DIE
22487 is its offset in .debug_info for this objfile. */
22490 partial_die_hash (const void *item
)
22492 const struct partial_die_info
*part_die
22493 = (const struct partial_die_info
*) item
;
22495 return part_die
->offset
.sect_off
;
22498 /* Trivial comparison function for partial_die_info structures: two DIEs
22499 are equal if they have the same offset. */
22502 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
22504 const struct partial_die_info
*part_die_lhs
22505 = (const struct partial_die_info
*) item_lhs
;
22506 const struct partial_die_info
*part_die_rhs
22507 = (const struct partial_die_info
*) item_rhs
;
22509 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
22512 static struct cmd_list_element
*set_dwarf_cmdlist
;
22513 static struct cmd_list_element
*show_dwarf_cmdlist
;
22516 set_dwarf_cmd (char *args
, int from_tty
)
22518 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
22523 show_dwarf_cmd (char *args
, int from_tty
)
22525 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
22528 /* Free data associated with OBJFILE, if necessary. */
22531 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
22533 struct dwarf2_per_objfile
*data
= (struct dwarf2_per_objfile
*) d
;
22536 /* Make sure we don't accidentally use dwarf2_per_objfile while
22538 dwarf2_per_objfile
= NULL
;
22540 for (ix
= 0; ix
< data
->n_comp_units
; ++ix
)
22541 VEC_free (dwarf2_per_cu_ptr
, data
->all_comp_units
[ix
]->imported_symtabs
);
22543 for (ix
= 0; ix
< data
->n_type_units
; ++ix
)
22544 VEC_free (dwarf2_per_cu_ptr
,
22545 data
->all_type_units
[ix
]->per_cu
.imported_symtabs
);
22546 xfree (data
->all_type_units
);
22548 VEC_free (dwarf2_section_info_def
, data
->types
);
22550 if (data
->dwo_files
)
22551 free_dwo_files (data
->dwo_files
, objfile
);
22552 if (data
->dwp_file
)
22553 gdb_bfd_unref (data
->dwp_file
->dbfd
);
22555 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
22556 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
22560 /* The "save gdb-index" command. */
22562 /* The contents of the hash table we create when building the string
22564 struct strtab_entry
22566 offset_type offset
;
22570 /* Hash function for a strtab_entry.
22572 Function is used only during write_hash_table so no index format backward
22573 compatibility is needed. */
22576 hash_strtab_entry (const void *e
)
22578 const struct strtab_entry
*entry
= (const struct strtab_entry
*) e
;
22579 return mapped_index_string_hash (INT_MAX
, entry
->str
);
22582 /* Equality function for a strtab_entry. */
22585 eq_strtab_entry (const void *a
, const void *b
)
22587 const struct strtab_entry
*ea
= (const struct strtab_entry
*) a
;
22588 const struct strtab_entry
*eb
= (const struct strtab_entry
*) b
;
22589 return !strcmp (ea
->str
, eb
->str
);
22592 /* Create a strtab_entry hash table. */
22595 create_strtab (void)
22597 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
22598 xfree
, xcalloc
, xfree
);
22601 /* Add a string to the constant pool. Return the string's offset in
22605 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
22608 struct strtab_entry entry
;
22609 struct strtab_entry
*result
;
22612 slot
= htab_find_slot (table
, &entry
, INSERT
);
22614 result
= (struct strtab_entry
*) *slot
;
22617 result
= XNEW (struct strtab_entry
);
22618 result
->offset
= obstack_object_size (cpool
);
22620 obstack_grow_str0 (cpool
, str
);
22623 return result
->offset
;
22626 /* An entry in the symbol table. */
22627 struct symtab_index_entry
22629 /* The name of the symbol. */
22631 /* The offset of the name in the constant pool. */
22632 offset_type index_offset
;
22633 /* A sorted vector of the indices of all the CUs that hold an object
22635 VEC (offset_type
) *cu_indices
;
22638 /* The symbol table. This is a power-of-2-sized hash table. */
22639 struct mapped_symtab
22641 offset_type n_elements
;
22643 struct symtab_index_entry
**data
;
22646 /* Hash function for a symtab_index_entry. */
22649 hash_symtab_entry (const void *e
)
22651 const struct symtab_index_entry
*entry
22652 = (const struct symtab_index_entry
*) e
;
22653 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
22654 sizeof (offset_type
) * VEC_length (offset_type
,
22655 entry
->cu_indices
),
22659 /* Equality function for a symtab_index_entry. */
22662 eq_symtab_entry (const void *a
, const void *b
)
22664 const struct symtab_index_entry
*ea
= (const struct symtab_index_entry
*) a
;
22665 const struct symtab_index_entry
*eb
= (const struct symtab_index_entry
*) b
;
22666 int len
= VEC_length (offset_type
, ea
->cu_indices
);
22667 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
22669 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
22670 VEC_address (offset_type
, eb
->cu_indices
),
22671 sizeof (offset_type
) * len
);
22674 /* Destroy a symtab_index_entry. */
22677 delete_symtab_entry (void *p
)
22679 struct symtab_index_entry
*entry
= (struct symtab_index_entry
*) p
;
22680 VEC_free (offset_type
, entry
->cu_indices
);
22684 /* Create a hash table holding symtab_index_entry objects. */
22687 create_symbol_hash_table (void)
22689 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
22690 delete_symtab_entry
, xcalloc
, xfree
);
22693 /* Create a new mapped symtab object. */
22695 static struct mapped_symtab
*
22696 create_mapped_symtab (void)
22698 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
22699 symtab
->n_elements
= 0;
22700 symtab
->size
= 1024;
22701 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
22705 /* Destroy a mapped_symtab. */
22708 cleanup_mapped_symtab (void *p
)
22710 struct mapped_symtab
*symtab
= (struct mapped_symtab
*) p
;
22711 /* The contents of the array are freed when the other hash table is
22713 xfree (symtab
->data
);
22717 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
22720 Function is used only during write_hash_table so no index format backward
22721 compatibility is needed. */
22723 static struct symtab_index_entry
**
22724 find_slot (struct mapped_symtab
*symtab
, const char *name
)
22726 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
22728 index
= hash
& (symtab
->size
- 1);
22729 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
22733 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
22734 return &symtab
->data
[index
];
22735 index
= (index
+ step
) & (symtab
->size
- 1);
22739 /* Expand SYMTAB's hash table. */
22742 hash_expand (struct mapped_symtab
*symtab
)
22744 offset_type old_size
= symtab
->size
;
22746 struct symtab_index_entry
**old_entries
= symtab
->data
;
22749 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
22751 for (i
= 0; i
< old_size
; ++i
)
22753 if (old_entries
[i
])
22755 struct symtab_index_entry
**slot
= find_slot (symtab
,
22756 old_entries
[i
]->name
);
22757 *slot
= old_entries
[i
];
22761 xfree (old_entries
);
22764 /* Add an entry to SYMTAB. NAME is the name of the symbol.
22765 CU_INDEX is the index of the CU in which the symbol appears.
22766 IS_STATIC is one if the symbol is static, otherwise zero (global). */
22769 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
22770 int is_static
, gdb_index_symbol_kind kind
,
22771 offset_type cu_index
)
22773 struct symtab_index_entry
**slot
;
22774 offset_type cu_index_and_attrs
;
22776 ++symtab
->n_elements
;
22777 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
22778 hash_expand (symtab
);
22780 slot
= find_slot (symtab
, name
);
22783 *slot
= XNEW (struct symtab_index_entry
);
22784 (*slot
)->name
= name
;
22785 /* index_offset is set later. */
22786 (*slot
)->cu_indices
= NULL
;
22789 cu_index_and_attrs
= 0;
22790 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
22791 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
22792 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
22794 /* We don't want to record an index value twice as we want to avoid the
22796 We process all global symbols and then all static symbols
22797 (which would allow us to avoid the duplication by only having to check
22798 the last entry pushed), but a symbol could have multiple kinds in one CU.
22799 To keep things simple we don't worry about the duplication here and
22800 sort and uniqufy the list after we've processed all symbols. */
22801 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
22804 /* qsort helper routine for uniquify_cu_indices. */
22807 offset_type_compare (const void *ap
, const void *bp
)
22809 offset_type a
= *(offset_type
*) ap
;
22810 offset_type b
= *(offset_type
*) bp
;
22812 return (a
> b
) - (b
> a
);
22815 /* Sort and remove duplicates of all symbols' cu_indices lists. */
22818 uniquify_cu_indices (struct mapped_symtab
*symtab
)
22822 for (i
= 0; i
< symtab
->size
; ++i
)
22824 struct symtab_index_entry
*entry
= symtab
->data
[i
];
22827 && entry
->cu_indices
!= NULL
)
22829 unsigned int next_to_insert
, next_to_check
;
22830 offset_type last_value
;
22832 qsort (VEC_address (offset_type
, entry
->cu_indices
),
22833 VEC_length (offset_type
, entry
->cu_indices
),
22834 sizeof (offset_type
), offset_type_compare
);
22836 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
22837 next_to_insert
= 1;
22838 for (next_to_check
= 1;
22839 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
22842 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
22845 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
22847 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
22852 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
22857 /* Add a vector of indices to the constant pool. */
22860 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
22861 struct symtab_index_entry
*entry
)
22865 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
22868 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
22869 offset_type val
= MAYBE_SWAP (len
);
22874 entry
->index_offset
= obstack_object_size (cpool
);
22876 obstack_grow (cpool
, &val
, sizeof (val
));
22878 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
22881 val
= MAYBE_SWAP (iter
);
22882 obstack_grow (cpool
, &val
, sizeof (val
));
22887 struct symtab_index_entry
*old_entry
22888 = (struct symtab_index_entry
*) *slot
;
22889 entry
->index_offset
= old_entry
->index_offset
;
22892 return entry
->index_offset
;
22895 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
22896 constant pool entries going into the obstack CPOOL. */
22899 write_hash_table (struct mapped_symtab
*symtab
,
22900 struct obstack
*output
, struct obstack
*cpool
)
22903 htab_t symbol_hash_table
;
22906 symbol_hash_table
= create_symbol_hash_table ();
22907 str_table
= create_strtab ();
22909 /* We add all the index vectors to the constant pool first, to
22910 ensure alignment is ok. */
22911 for (i
= 0; i
< symtab
->size
; ++i
)
22913 if (symtab
->data
[i
])
22914 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
22917 /* Now write out the hash table. */
22918 for (i
= 0; i
< symtab
->size
; ++i
)
22920 offset_type str_off
, vec_off
;
22922 if (symtab
->data
[i
])
22924 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
22925 vec_off
= symtab
->data
[i
]->index_offset
;
22929 /* While 0 is a valid constant pool index, it is not valid
22930 to have 0 for both offsets. */
22935 str_off
= MAYBE_SWAP (str_off
);
22936 vec_off
= MAYBE_SWAP (vec_off
);
22938 obstack_grow (output
, &str_off
, sizeof (str_off
));
22939 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
22942 htab_delete (str_table
);
22943 htab_delete (symbol_hash_table
);
22946 /* Struct to map psymtab to CU index in the index file. */
22947 struct psymtab_cu_index_map
22949 struct partial_symtab
*psymtab
;
22950 unsigned int cu_index
;
22954 hash_psymtab_cu_index (const void *item
)
22956 const struct psymtab_cu_index_map
*map
22957 = (const struct psymtab_cu_index_map
*) item
;
22959 return htab_hash_pointer (map
->psymtab
);
22963 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
22965 const struct psymtab_cu_index_map
*lhs
22966 = (const struct psymtab_cu_index_map
*) item_lhs
;
22967 const struct psymtab_cu_index_map
*rhs
22968 = (const struct psymtab_cu_index_map
*) item_rhs
;
22970 return lhs
->psymtab
== rhs
->psymtab
;
22973 /* Helper struct for building the address table. */
22974 struct addrmap_index_data
22976 struct objfile
*objfile
;
22977 struct obstack
*addr_obstack
;
22978 htab_t cu_index_htab
;
22980 /* Non-zero if the previous_* fields are valid.
22981 We can't write an entry until we see the next entry (since it is only then
22982 that we know the end of the entry). */
22983 int previous_valid
;
22984 /* Index of the CU in the table of all CUs in the index file. */
22985 unsigned int previous_cu_index
;
22986 /* Start address of the CU. */
22987 CORE_ADDR previous_cu_start
;
22990 /* Write an address entry to OBSTACK. */
22993 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
22994 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
22996 offset_type cu_index_to_write
;
22998 CORE_ADDR baseaddr
;
23000 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23002 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
23003 obstack_grow (obstack
, addr
, 8);
23004 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
23005 obstack_grow (obstack
, addr
, 8);
23006 cu_index_to_write
= MAYBE_SWAP (cu_index
);
23007 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
23010 /* Worker function for traversing an addrmap to build the address table. */
23013 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
23015 struct addrmap_index_data
*data
= (struct addrmap_index_data
*) datap
;
23016 struct partial_symtab
*pst
= (struct partial_symtab
*) obj
;
23018 if (data
->previous_valid
)
23019 add_address_entry (data
->objfile
, data
->addr_obstack
,
23020 data
->previous_cu_start
, start_addr
,
23021 data
->previous_cu_index
);
23023 data
->previous_cu_start
= start_addr
;
23026 struct psymtab_cu_index_map find_map
, *map
;
23027 find_map
.psymtab
= pst
;
23028 map
= ((struct psymtab_cu_index_map
*)
23029 htab_find (data
->cu_index_htab
, &find_map
));
23030 gdb_assert (map
!= NULL
);
23031 data
->previous_cu_index
= map
->cu_index
;
23032 data
->previous_valid
= 1;
23035 data
->previous_valid
= 0;
23040 /* Write OBJFILE's address map to OBSTACK.
23041 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
23042 in the index file. */
23045 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
23046 htab_t cu_index_htab
)
23048 struct addrmap_index_data addrmap_index_data
;
23050 /* When writing the address table, we have to cope with the fact that
23051 the addrmap iterator only provides the start of a region; we have to
23052 wait until the next invocation to get the start of the next region. */
23054 addrmap_index_data
.objfile
= objfile
;
23055 addrmap_index_data
.addr_obstack
= obstack
;
23056 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
23057 addrmap_index_data
.previous_valid
= 0;
23059 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
23060 &addrmap_index_data
);
23062 /* It's highly unlikely the last entry (end address = 0xff...ff)
23063 is valid, but we should still handle it.
23064 The end address is recorded as the start of the next region, but that
23065 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
23067 if (addrmap_index_data
.previous_valid
)
23068 add_address_entry (objfile
, obstack
,
23069 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
23070 addrmap_index_data
.previous_cu_index
);
23073 /* Return the symbol kind of PSYM. */
23075 static gdb_index_symbol_kind
23076 symbol_kind (struct partial_symbol
*psym
)
23078 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
23079 enum address_class aclass
= PSYMBOL_CLASS (psym
);
23087 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
23089 return GDB_INDEX_SYMBOL_KIND_TYPE
;
23091 case LOC_CONST_BYTES
:
23092 case LOC_OPTIMIZED_OUT
:
23094 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
23096 /* Note: It's currently impossible to recognize psyms as enum values
23097 short of reading the type info. For now punt. */
23098 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
23100 /* There are other LOC_FOO values that one might want to classify
23101 as variables, but dwarf2read.c doesn't currently use them. */
23102 return GDB_INDEX_SYMBOL_KIND_OTHER
;
23104 case STRUCT_DOMAIN
:
23105 return GDB_INDEX_SYMBOL_KIND_TYPE
;
23107 return GDB_INDEX_SYMBOL_KIND_OTHER
;
23111 /* Add a list of partial symbols to SYMTAB. */
23114 write_psymbols (struct mapped_symtab
*symtab
,
23116 struct partial_symbol
**psymp
,
23118 offset_type cu_index
,
23121 for (; count
-- > 0; ++psymp
)
23123 struct partial_symbol
*psym
= *psymp
;
23126 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
23127 error (_("Ada is not currently supported by the index"));
23129 /* Only add a given psymbol once. */
23130 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
23133 gdb_index_symbol_kind kind
= symbol_kind (psym
);
23136 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
23137 is_static
, kind
, cu_index
);
23142 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
23143 exception if there is an error. */
23146 write_obstack (FILE *file
, struct obstack
*obstack
)
23148 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
23150 != obstack_object_size (obstack
))
23151 error (_("couldn't data write to file"));
23154 /* A helper struct used when iterating over debug_types. */
23155 struct signatured_type_index_data
23157 struct objfile
*objfile
;
23158 struct mapped_symtab
*symtab
;
23159 struct obstack
*types_list
;
23164 /* A helper function that writes a single signatured_type to an
23168 write_one_signatured_type (void **slot
, void *d
)
23170 struct signatured_type_index_data
*info
23171 = (struct signatured_type_index_data
*) d
;
23172 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
23173 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
23176 write_psymbols (info
->symtab
,
23178 info
->objfile
->global_psymbols
.list
23179 + psymtab
->globals_offset
,
23180 psymtab
->n_global_syms
, info
->cu_index
,
23182 write_psymbols (info
->symtab
,
23184 info
->objfile
->static_psymbols
.list
23185 + psymtab
->statics_offset
,
23186 psymtab
->n_static_syms
, info
->cu_index
,
23189 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23190 entry
->per_cu
.offset
.sect_off
);
23191 obstack_grow (info
->types_list
, val
, 8);
23192 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23193 entry
->type_offset_in_tu
.cu_off
);
23194 obstack_grow (info
->types_list
, val
, 8);
23195 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
23196 obstack_grow (info
->types_list
, val
, 8);
23203 /* Recurse into all "included" dependencies and write their symbols as
23204 if they appeared in this psymtab. */
23207 recursively_write_psymbols (struct objfile
*objfile
,
23208 struct partial_symtab
*psymtab
,
23209 struct mapped_symtab
*symtab
,
23211 offset_type cu_index
)
23215 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
23216 if (psymtab
->dependencies
[i
]->user
!= NULL
)
23217 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
23218 symtab
, psyms_seen
, cu_index
);
23220 write_psymbols (symtab
,
23222 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
23223 psymtab
->n_global_syms
, cu_index
,
23225 write_psymbols (symtab
,
23227 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
23228 psymtab
->n_static_syms
, cu_index
,
23232 /* Create an index file for OBJFILE in the directory DIR. */
23235 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
23237 struct cleanup
*cleanup
;
23239 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
23240 struct obstack cu_list
, types_cu_list
;
23243 struct mapped_symtab
*symtab
;
23244 offset_type val
, size_of_contents
, total_len
;
23246 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
23248 if (dwarf2_per_objfile
->using_index
)
23249 error (_("Cannot use an index to create the index"));
23251 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
23252 error (_("Cannot make an index when the file has multiple .debug_types sections"));
23254 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
23257 if (stat (objfile_name (objfile
), &st
) < 0)
23258 perror_with_name (objfile_name (objfile
));
23260 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile_name (objfile
)),
23261 INDEX_SUFFIX
, (char *) NULL
);
23262 cleanup
= make_cleanup (xfree
, filename
);
23264 out_file
= gdb_fopen_cloexec (filename
, "wb");
23266 error (_("Can't open `%s' for writing"), filename
);
23268 gdb::unlinker
unlink_file (filename
);
23270 symtab
= create_mapped_symtab ();
23271 make_cleanup (cleanup_mapped_symtab
, symtab
);
23273 obstack_init (&addr_obstack
);
23274 make_cleanup_obstack_free (&addr_obstack
);
23276 obstack_init (&cu_list
);
23277 make_cleanup_obstack_free (&cu_list
);
23279 obstack_init (&types_cu_list
);
23280 make_cleanup_obstack_free (&types_cu_list
);
23282 htab_up
psyms_seen (htab_create_alloc (100, htab_hash_pointer
,
23284 NULL
, xcalloc
, xfree
));
23286 /* While we're scanning CU's create a table that maps a psymtab pointer
23287 (which is what addrmap records) to its index (which is what is recorded
23288 in the index file). This will later be needed to write the address
23290 htab_up
cu_index_htab (htab_create_alloc (100,
23291 hash_psymtab_cu_index
,
23292 eq_psymtab_cu_index
,
23293 NULL
, xcalloc
, xfree
));
23294 psymtab_cu_index_map
= XNEWVEC (struct psymtab_cu_index_map
,
23295 dwarf2_per_objfile
->n_comp_units
);
23296 make_cleanup (xfree
, psymtab_cu_index_map
);
23298 /* The CU list is already sorted, so we don't need to do additional
23299 work here. Also, the debug_types entries do not appear in
23300 all_comp_units, but only in their own hash table. */
23301 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
23303 struct dwarf2_per_cu_data
*per_cu
23304 = dwarf2_per_objfile
->all_comp_units
[i
];
23305 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
23307 struct psymtab_cu_index_map
*map
;
23310 /* CU of a shared file from 'dwz -m' may be unused by this main file.
23311 It may be referenced from a local scope but in such case it does not
23312 need to be present in .gdb_index. */
23313 if (psymtab
== NULL
)
23316 if (psymtab
->user
== NULL
)
23317 recursively_write_psymbols (objfile
, psymtab
, symtab
,
23318 psyms_seen
.get (), i
);
23320 map
= &psymtab_cu_index_map
[i
];
23321 map
->psymtab
= psymtab
;
23323 slot
= htab_find_slot (cu_index_htab
.get (), map
, INSERT
);
23324 gdb_assert (slot
!= NULL
);
23325 gdb_assert (*slot
== NULL
);
23328 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23329 per_cu
->offset
.sect_off
);
23330 obstack_grow (&cu_list
, val
, 8);
23331 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
23332 obstack_grow (&cu_list
, val
, 8);
23335 /* Dump the address map. */
23336 write_address_map (objfile
, &addr_obstack
, cu_index_htab
.get ());
23338 /* Write out the .debug_type entries, if any. */
23339 if (dwarf2_per_objfile
->signatured_types
)
23341 struct signatured_type_index_data sig_data
;
23343 sig_data
.objfile
= objfile
;
23344 sig_data
.symtab
= symtab
;
23345 sig_data
.types_list
= &types_cu_list
;
23346 sig_data
.psyms_seen
= psyms_seen
.get ();
23347 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
23348 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
23349 write_one_signatured_type
, &sig_data
);
23352 /* Now that we've processed all symbols we can shrink their cu_indices
23354 uniquify_cu_indices (symtab
);
23356 obstack_init (&constant_pool
);
23357 make_cleanup_obstack_free (&constant_pool
);
23358 obstack_init (&symtab_obstack
);
23359 make_cleanup_obstack_free (&symtab_obstack
);
23360 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
23362 obstack_init (&contents
);
23363 make_cleanup_obstack_free (&contents
);
23364 size_of_contents
= 6 * sizeof (offset_type
);
23365 total_len
= size_of_contents
;
23367 /* The version number. */
23368 val
= MAYBE_SWAP (8);
23369 obstack_grow (&contents
, &val
, sizeof (val
));
23371 /* The offset of the CU list from the start of the file. */
23372 val
= MAYBE_SWAP (total_len
);
23373 obstack_grow (&contents
, &val
, sizeof (val
));
23374 total_len
+= obstack_object_size (&cu_list
);
23376 /* The offset of the types CU list from the start of the file. */
23377 val
= MAYBE_SWAP (total_len
);
23378 obstack_grow (&contents
, &val
, sizeof (val
));
23379 total_len
+= obstack_object_size (&types_cu_list
);
23381 /* The offset of the address table from the start of the file. */
23382 val
= MAYBE_SWAP (total_len
);
23383 obstack_grow (&contents
, &val
, sizeof (val
));
23384 total_len
+= obstack_object_size (&addr_obstack
);
23386 /* The offset of the symbol table from the start of the file. */
23387 val
= MAYBE_SWAP (total_len
);
23388 obstack_grow (&contents
, &val
, sizeof (val
));
23389 total_len
+= obstack_object_size (&symtab_obstack
);
23391 /* The offset of the constant pool from the start of the file. */
23392 val
= MAYBE_SWAP (total_len
);
23393 obstack_grow (&contents
, &val
, sizeof (val
));
23394 total_len
+= obstack_object_size (&constant_pool
);
23396 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
23398 write_obstack (out_file
, &contents
);
23399 write_obstack (out_file
, &cu_list
);
23400 write_obstack (out_file
, &types_cu_list
);
23401 write_obstack (out_file
, &addr_obstack
);
23402 write_obstack (out_file
, &symtab_obstack
);
23403 write_obstack (out_file
, &constant_pool
);
23407 /* We want to keep the file. */
23408 unlink_file
.keep ();
23410 do_cleanups (cleanup
);
23413 /* Implementation of the `save gdb-index' command.
23415 Note that the file format used by this command is documented in the
23416 GDB manual. Any changes here must be documented there. */
23419 save_gdb_index_command (char *arg
, int from_tty
)
23421 struct objfile
*objfile
;
23424 error (_("usage: save gdb-index DIRECTORY"));
23426 ALL_OBJFILES (objfile
)
23430 /* If the objfile does not correspond to an actual file, skip it. */
23431 if (stat (objfile_name (objfile
), &st
) < 0)
23435 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
23436 dwarf2_objfile_data_key
);
23437 if (dwarf2_per_objfile
)
23442 write_psymtabs_to_index (objfile
, arg
);
23444 CATCH (except
, RETURN_MASK_ERROR
)
23446 exception_fprintf (gdb_stderr
, except
,
23447 _("Error while writing index for `%s': "),
23448 objfile_name (objfile
));
23457 int dwarf_always_disassemble
;
23460 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
23461 struct cmd_list_element
*c
, const char *value
)
23463 fprintf_filtered (file
,
23464 _("Whether to always disassemble "
23465 "DWARF expressions is %s.\n"),
23470 show_check_physname (struct ui_file
*file
, int from_tty
,
23471 struct cmd_list_element
*c
, const char *value
)
23473 fprintf_filtered (file
,
23474 _("Whether to check \"physname\" is %s.\n"),
23478 void _initialize_dwarf2_read (void);
23481 _initialize_dwarf2_read (void)
23483 struct cmd_list_element
*c
;
23485 dwarf2_objfile_data_key
23486 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
23488 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23489 Set DWARF specific variables.\n\
23490 Configure DWARF variables such as the cache size"),
23491 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23492 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23494 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23495 Show DWARF specific variables\n\
23496 Show DWARF variables such as the cache size"),
23497 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23498 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23500 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23501 &dwarf_max_cache_age
, _("\
23502 Set the upper bound on the age of cached DWARF compilation units."), _("\
23503 Show the upper bound on the age of cached DWARF compilation units."), _("\
23504 A higher limit means that cached compilation units will be stored\n\
23505 in memory longer, and more total memory will be used. Zero disables\n\
23506 caching, which can slow down startup."),
23508 show_dwarf_max_cache_age
,
23509 &set_dwarf_cmdlist
,
23510 &show_dwarf_cmdlist
);
23512 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
23513 &dwarf_always_disassemble
, _("\
23514 Set whether `info address' always disassembles DWARF expressions."), _("\
23515 Show whether `info address' always disassembles DWARF expressions."), _("\
23516 When enabled, DWARF expressions are always printed in an assembly-like\n\
23517 syntax. When disabled, expressions will be printed in a more\n\
23518 conversational style, when possible."),
23520 show_dwarf_always_disassemble
,
23521 &set_dwarf_cmdlist
,
23522 &show_dwarf_cmdlist
);
23524 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23525 Set debugging of the DWARF reader."), _("\
23526 Show debugging of the DWARF reader."), _("\
23527 When enabled (non-zero), debugging messages are printed during DWARF\n\
23528 reading and symtab expansion. A value of 1 (one) provides basic\n\
23529 information. A value greater than 1 provides more verbose information."),
23532 &setdebuglist
, &showdebuglist
);
23534 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23535 Set debugging of the DWARF DIE reader."), _("\
23536 Show debugging of the DWARF DIE reader."), _("\
23537 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23538 The value is the maximum depth to print."),
23541 &setdebuglist
, &showdebuglist
);
23543 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23544 Set debugging of the dwarf line reader."), _("\
23545 Show debugging of the dwarf line reader."), _("\
23546 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23547 A value of 1 (one) provides basic information.\n\
23548 A value greater than 1 provides more verbose information."),
23551 &setdebuglist
, &showdebuglist
);
23553 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23554 Set cross-checking of \"physname\" code against demangler."), _("\
23555 Show cross-checking of \"physname\" code against demangler."), _("\
23556 When enabled, GDB's internal \"physname\" code is checked against\n\
23558 NULL
, show_check_physname
,
23559 &setdebuglist
, &showdebuglist
);
23561 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23562 no_class
, &use_deprecated_index_sections
, _("\
23563 Set whether to use deprecated gdb_index sections."), _("\
23564 Show whether to use deprecated gdb_index sections."), _("\
23565 When enabled, deprecated .gdb_index sections are used anyway.\n\
23566 Normally they are ignored either because of a missing feature or\n\
23567 performance issue.\n\
23568 Warning: This option must be enabled before gdb reads the file."),
23571 &setlist
, &showlist
);
23573 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
23575 Save a gdb-index file.\n\
23576 Usage: save gdb-index DIRECTORY"),
23578 set_cmd_completer (c
, filename_completer
);
23580 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23581 &dwarf2_locexpr_funcs
);
23582 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23583 &dwarf2_loclist_funcs
);
23585 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23586 &dwarf2_block_frame_base_locexpr_funcs
);
23587 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23588 &dwarf2_block_frame_base_loclist_funcs
);