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 loclists
;
226 struct dwarf2_section_info macinfo
;
227 struct dwarf2_section_info macro
;
228 struct dwarf2_section_info str
;
229 struct dwarf2_section_info line_str
;
230 struct dwarf2_section_info ranges
;
231 struct dwarf2_section_info rnglists
;
232 struct dwarf2_section_info addr
;
233 struct dwarf2_section_info frame
;
234 struct dwarf2_section_info eh_frame
;
235 struct dwarf2_section_info gdb_index
;
237 VEC (dwarf2_section_info_def
) *types
;
240 struct objfile
*objfile
;
242 /* Table of all the compilation units. This is used to locate
243 the target compilation unit of a particular reference. */
244 struct dwarf2_per_cu_data
**all_comp_units
;
246 /* The number of compilation units in ALL_COMP_UNITS. */
249 /* The number of .debug_types-related CUs. */
252 /* The number of elements allocated in all_type_units.
253 If there are skeleton-less TUs, we add them to all_type_units lazily. */
254 int n_allocated_type_units
;
256 /* The .debug_types-related CUs (TUs).
257 This is stored in malloc space because we may realloc it. */
258 struct signatured_type
**all_type_units
;
260 /* Table of struct type_unit_group objects.
261 The hash key is the DW_AT_stmt_list value. */
262 htab_t type_unit_groups
;
264 /* A table mapping .debug_types signatures to its signatured_type entry.
265 This is NULL if the .debug_types section hasn't been read in yet. */
266 htab_t signatured_types
;
268 /* Type unit statistics, to see how well the scaling improvements
270 struct tu_stats tu_stats
;
272 /* A chain of compilation units that are currently read in, so that
273 they can be freed later. */
274 struct dwarf2_per_cu_data
*read_in_chain
;
276 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
277 This is NULL if the table hasn't been allocated yet. */
280 /* Non-zero if we've check for whether there is a DWP file. */
283 /* The DWP file if there is one, or NULL. */
284 struct dwp_file
*dwp_file
;
286 /* The shared '.dwz' file, if one exists. This is used when the
287 original data was compressed using 'dwz -m'. */
288 struct dwz_file
*dwz_file
;
290 /* A flag indicating wether this objfile has a section loaded at a
292 int has_section_at_zero
;
294 /* True if we are using the mapped index,
295 or we are faking it for OBJF_READNOW's sake. */
296 unsigned char using_index
;
298 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
299 struct mapped_index
*index_table
;
301 /* When using index_table, this keeps track of all quick_file_names entries.
302 TUs typically share line table entries with a CU, so we maintain a
303 separate table of all line table entries to support the sharing.
304 Note that while there can be way more TUs than CUs, we've already
305 sorted all the TUs into "type unit groups", grouped by their
306 DW_AT_stmt_list value. Therefore the only sharing done here is with a
307 CU and its associated TU group if there is one. */
308 htab_t quick_file_names_table
;
310 /* Set during partial symbol reading, to prevent queueing of full
312 int reading_partial_symbols
;
314 /* Table mapping type DIEs to their struct type *.
315 This is NULL if not allocated yet.
316 The mapping is done via (CU/TU + DIE offset) -> type. */
317 htab_t die_type_hash
;
319 /* The CUs we recently read. */
320 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
322 /* Table containing line_header indexed by offset and offset_in_dwz. */
323 htab_t line_header_hash
;
326 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
328 /* Default names of the debugging sections. */
330 /* Note that if the debugging section has been compressed, it might
331 have a name like .zdebug_info. */
333 static const struct dwarf2_debug_sections dwarf2_elf_names
=
335 { ".debug_info", ".zdebug_info" },
336 { ".debug_abbrev", ".zdebug_abbrev" },
337 { ".debug_line", ".zdebug_line" },
338 { ".debug_loc", ".zdebug_loc" },
339 { ".debug_loclists", ".zdebug_loclists" },
340 { ".debug_macinfo", ".zdebug_macinfo" },
341 { ".debug_macro", ".zdebug_macro" },
342 { ".debug_str", ".zdebug_str" },
343 { ".debug_line_str", ".zdebug_line_str" },
344 { ".debug_ranges", ".zdebug_ranges" },
345 { ".debug_rnglists", ".zdebug_rnglists" },
346 { ".debug_types", ".zdebug_types" },
347 { ".debug_addr", ".zdebug_addr" },
348 { ".debug_frame", ".zdebug_frame" },
349 { ".eh_frame", NULL
},
350 { ".gdb_index", ".zgdb_index" },
354 /* List of DWO/DWP sections. */
356 static const struct dwop_section_names
358 struct dwarf2_section_names abbrev_dwo
;
359 struct dwarf2_section_names info_dwo
;
360 struct dwarf2_section_names line_dwo
;
361 struct dwarf2_section_names loc_dwo
;
362 struct dwarf2_section_names loclists_dwo
;
363 struct dwarf2_section_names macinfo_dwo
;
364 struct dwarf2_section_names macro_dwo
;
365 struct dwarf2_section_names str_dwo
;
366 struct dwarf2_section_names str_offsets_dwo
;
367 struct dwarf2_section_names types_dwo
;
368 struct dwarf2_section_names cu_index
;
369 struct dwarf2_section_names tu_index
;
373 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
374 { ".debug_info.dwo", ".zdebug_info.dwo" },
375 { ".debug_line.dwo", ".zdebug_line.dwo" },
376 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
377 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
378 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
379 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
380 { ".debug_str.dwo", ".zdebug_str.dwo" },
381 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
382 { ".debug_types.dwo", ".zdebug_types.dwo" },
383 { ".debug_cu_index", ".zdebug_cu_index" },
384 { ".debug_tu_index", ".zdebug_tu_index" },
387 /* local data types */
389 /* The data in a compilation unit header, after target2host
390 translation, looks like this. */
391 struct comp_unit_head
395 unsigned char addr_size
;
396 unsigned char signed_addr_p
;
397 sect_offset abbrev_offset
;
399 /* Size of file offsets; either 4 or 8. */
400 unsigned int offset_size
;
402 /* Size of the length field; either 4 or 12. */
403 unsigned int initial_length_size
;
405 enum dwarf_unit_type unit_type
;
407 /* Offset to the first byte of this compilation unit header in the
408 .debug_info section, for resolving relative reference dies. */
411 /* Offset to first die in this cu from the start of the cu.
412 This will be the first byte following the compilation unit header. */
413 cu_offset first_die_offset
;
415 /* 64-bit signature of this type unit - it is valid only for
416 UNIT_TYPE DW_UT_type. */
419 /* For types, offset in the type's DIE of the type defined by this TU. */
420 cu_offset type_offset_in_tu
;
423 /* Type used for delaying computation of method physnames.
424 See comments for compute_delayed_physnames. */
425 struct delayed_method_info
427 /* The type to which the method is attached, i.e., its parent class. */
430 /* The index of the method in the type's function fieldlists. */
433 /* The index of the method in the fieldlist. */
436 /* The name of the DIE. */
439 /* The DIE associated with this method. */
440 struct die_info
*die
;
443 typedef struct delayed_method_info delayed_method_info
;
444 DEF_VEC_O (delayed_method_info
);
446 /* Internal state when decoding a particular compilation unit. */
449 /* The objfile containing this compilation unit. */
450 struct objfile
*objfile
;
452 /* The header of the compilation unit. */
453 struct comp_unit_head header
;
455 /* Base address of this compilation unit. */
456 CORE_ADDR base_address
;
458 /* Non-zero if base_address has been set. */
461 /* The language we are debugging. */
462 enum language language
;
463 const struct language_defn
*language_defn
;
465 const char *producer
;
467 /* The generic symbol table building routines have separate lists for
468 file scope symbols and all all other scopes (local scopes). So
469 we need to select the right one to pass to add_symbol_to_list().
470 We do it by keeping a pointer to the correct list in list_in_scope.
472 FIXME: The original dwarf code just treated the file scope as the
473 first local scope, and all other local scopes as nested local
474 scopes, and worked fine. Check to see if we really need to
475 distinguish these in buildsym.c. */
476 struct pending
**list_in_scope
;
478 /* The abbrev table for this CU.
479 Normally this points to the abbrev table in the objfile.
480 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
481 struct abbrev_table
*abbrev_table
;
483 /* Hash table holding all the loaded partial DIEs
484 with partial_die->offset.SECT_OFF as hash. */
487 /* Storage for things with the same lifetime as this read-in compilation
488 unit, including partial DIEs. */
489 struct obstack comp_unit_obstack
;
491 /* When multiple dwarf2_cu structures are living in memory, this field
492 chains them all together, so that they can be released efficiently.
493 We will probably also want a generation counter so that most-recently-used
494 compilation units are cached... */
495 struct dwarf2_per_cu_data
*read_in_chain
;
497 /* Backlink to our per_cu entry. */
498 struct dwarf2_per_cu_data
*per_cu
;
500 /* How many compilation units ago was this CU last referenced? */
503 /* A hash table of DIE cu_offset for following references with
504 die_info->offset.sect_off as hash. */
507 /* Full DIEs if read in. */
508 struct die_info
*dies
;
510 /* A set of pointers to dwarf2_per_cu_data objects for compilation
511 units referenced by this one. Only set during full symbol processing;
512 partial symbol tables do not have dependencies. */
515 /* Header data from the line table, during full symbol processing. */
516 struct line_header
*line_header
;
518 /* A list of methods which need to have physnames computed
519 after all type information has been read. */
520 VEC (delayed_method_info
) *method_list
;
522 /* To be copied to symtab->call_site_htab. */
523 htab_t call_site_htab
;
525 /* Non-NULL if this CU came from a DWO file.
526 There is an invariant here that is important to remember:
527 Except for attributes copied from the top level DIE in the "main"
528 (or "stub") file in preparation for reading the DWO file
529 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
530 Either there isn't a DWO file (in which case this is NULL and the point
531 is moot), or there is and either we're not going to read it (in which
532 case this is NULL) or there is and we are reading it (in which case this
534 struct dwo_unit
*dwo_unit
;
536 /* The DW_AT_addr_base attribute if present, zero otherwise
537 (zero is a valid value though).
538 Note this value comes from the Fission stub CU/TU's DIE. */
541 /* The DW_AT_ranges_base attribute if present, zero otherwise
542 (zero is a valid value though).
543 Note this value comes from the Fission stub CU/TU's DIE.
544 Also note that the value is zero in the non-DWO case so this value can
545 be used without needing to know whether DWO files are in use or not.
546 N.B. This does not apply to DW_AT_ranges appearing in
547 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
548 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
549 DW_AT_ranges_base *would* have to be applied, and we'd have to care
550 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
551 ULONGEST ranges_base
;
553 /* Mark used when releasing cached dies. */
554 unsigned int mark
: 1;
556 /* This CU references .debug_loc. See the symtab->locations_valid field.
557 This test is imperfect as there may exist optimized debug code not using
558 any location list and still facing inlining issues if handled as
559 unoptimized code. For a future better test see GCC PR other/32998. */
560 unsigned int has_loclist
: 1;
562 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
563 if all the producer_is_* fields are valid. This information is cached
564 because profiling CU expansion showed excessive time spent in
565 producer_is_gxx_lt_4_6. */
566 unsigned int checked_producer
: 1;
567 unsigned int producer_is_gxx_lt_4_6
: 1;
568 unsigned int producer_is_gcc_lt_4_3
: 1;
569 unsigned int producer_is_icc
: 1;
571 /* When set, the file that we're processing is known to have
572 debugging info for C++ namespaces. GCC 3.3.x did not produce
573 this information, but later versions do. */
575 unsigned int processing_has_namespace_info
: 1;
578 /* Persistent data held for a compilation unit, even when not
579 processing it. We put a pointer to this structure in the
580 read_symtab_private field of the psymtab. */
582 struct dwarf2_per_cu_data
584 /* The start offset and length of this compilation unit.
585 NOTE: Unlike comp_unit_head.length, this length includes
587 If the DIE refers to a DWO file, this is always of the original die,
592 /* DWARF standard version this data has been read from (such as 4 or 5). */
595 /* Flag indicating this compilation unit will be read in before
596 any of the current compilation units are processed. */
597 unsigned int queued
: 1;
599 /* This flag will be set when reading partial DIEs if we need to load
600 absolutely all DIEs for this compilation unit, instead of just the ones
601 we think are interesting. It gets set if we look for a DIE in the
602 hash table and don't find it. */
603 unsigned int load_all_dies
: 1;
605 /* Non-zero if this CU is from .debug_types.
606 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
608 unsigned int is_debug_types
: 1;
610 /* Non-zero if this CU is from the .dwz file. */
611 unsigned int is_dwz
: 1;
613 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
614 This flag is only valid if is_debug_types is true.
615 We can't read a CU directly from a DWO file: There are required
616 attributes in the stub. */
617 unsigned int reading_dwo_directly
: 1;
619 /* Non-zero if the TU has been read.
620 This is used to assist the "Stay in DWO Optimization" for Fission:
621 When reading a DWO, it's faster to read TUs from the DWO instead of
622 fetching them from random other DWOs (due to comdat folding).
623 If the TU has already been read, the optimization is unnecessary
624 (and unwise - we don't want to change where gdb thinks the TU lives
626 This flag is only valid if is_debug_types is true. */
627 unsigned int tu_read
: 1;
629 /* The section this CU/TU lives in.
630 If the DIE refers to a DWO file, this is always the original die,
632 struct dwarf2_section_info
*section
;
634 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
635 of the CU cache it gets reset to NULL again. This is left as NULL for
636 dummy CUs (a CU header, but nothing else). */
637 struct dwarf2_cu
*cu
;
639 /* The corresponding objfile.
640 Normally we can get the objfile from dwarf2_per_objfile.
641 However we can enter this file with just a "per_cu" handle. */
642 struct objfile
*objfile
;
644 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
645 is active. Otherwise, the 'psymtab' field is active. */
648 /* The partial symbol table associated with this compilation unit,
649 or NULL for unread partial units. */
650 struct partial_symtab
*psymtab
;
652 /* Data needed by the "quick" functions. */
653 struct dwarf2_per_cu_quick_data
*quick
;
656 /* The CUs we import using DW_TAG_imported_unit. This is filled in
657 while reading psymtabs, used to compute the psymtab dependencies,
658 and then cleared. Then it is filled in again while reading full
659 symbols, and only deleted when the objfile is destroyed.
661 This is also used to work around a difference between the way gold
662 generates .gdb_index version <=7 and the way gdb does. Arguably this
663 is a gold bug. For symbols coming from TUs, gold records in the index
664 the CU that includes the TU instead of the TU itself. This breaks
665 dw2_lookup_symbol: It assumes that if the index says symbol X lives
666 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
667 will find X. Alas TUs live in their own symtab, so after expanding CU Y
668 we need to look in TU Z to find X. Fortunately, this is akin to
669 DW_TAG_imported_unit, so we just use the same mechanism: For
670 .gdb_index version <=7 this also records the TUs that the CU referred
671 to. Concurrently with this change gdb was modified to emit version 8
672 indices so we only pay a price for gold generated indices.
673 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
674 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
677 /* Entry in the signatured_types hash table. */
679 struct signatured_type
681 /* The "per_cu" object of this type.
682 This struct is used iff per_cu.is_debug_types.
683 N.B.: This is the first member so that it's easy to convert pointers
685 struct dwarf2_per_cu_data per_cu
;
687 /* The type's signature. */
690 /* Offset in the TU of the type's DIE, as read from the TU header.
691 If this TU is a DWO stub and the definition lives in a DWO file
692 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
693 cu_offset type_offset_in_tu
;
695 /* Offset in the section of the type's DIE.
696 If the definition lives in a DWO file, this is the offset in the
697 .debug_types.dwo section.
698 The value is zero until the actual value is known.
699 Zero is otherwise not a valid section offset. */
700 sect_offset type_offset_in_section
;
702 /* Type units are grouped by their DW_AT_stmt_list entry so that they
703 can share them. This points to the containing symtab. */
704 struct type_unit_group
*type_unit_group
;
707 The first time we encounter this type we fully read it in and install it
708 in the symbol tables. Subsequent times we only need the type. */
711 /* Containing DWO unit.
712 This field is valid iff per_cu.reading_dwo_directly. */
713 struct dwo_unit
*dwo_unit
;
716 typedef struct signatured_type
*sig_type_ptr
;
717 DEF_VEC_P (sig_type_ptr
);
719 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
720 This includes type_unit_group and quick_file_names. */
722 struct stmt_list_hash
724 /* The DWO unit this table is from or NULL if there is none. */
725 struct dwo_unit
*dwo_unit
;
727 /* Offset in .debug_line or .debug_line.dwo. */
728 sect_offset line_offset
;
731 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
732 an object of this type. */
734 struct type_unit_group
736 /* dwarf2read.c's main "handle" on a TU symtab.
737 To simplify things we create an artificial CU that "includes" all the
738 type units using this stmt_list so that the rest of the code still has
739 a "per_cu" handle on the symtab.
740 This PER_CU is recognized by having no section. */
741 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
742 struct dwarf2_per_cu_data per_cu
;
744 /* The TUs that share this DW_AT_stmt_list entry.
745 This is added to while parsing type units to build partial symtabs,
746 and is deleted afterwards and not used again. */
747 VEC (sig_type_ptr
) *tus
;
749 /* The compunit symtab.
750 Type units in a group needn't all be defined in the same source file,
751 so we create an essentially anonymous symtab as the compunit symtab. */
752 struct compunit_symtab
*compunit_symtab
;
754 /* The data used to construct the hash key. */
755 struct stmt_list_hash hash
;
757 /* The number of symtabs from the line header.
758 The value here must match line_header.num_file_names. */
759 unsigned int num_symtabs
;
761 /* The symbol tables for this TU (obtained from the files listed in
763 WARNING: The order of entries here must match the order of entries
764 in the line header. After the first TU using this type_unit_group, the
765 line header for the subsequent TUs is recreated from this. This is done
766 because we need to use the same symtabs for each TU using the same
767 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
768 there's no guarantee the line header doesn't have duplicate entries. */
769 struct symtab
**symtabs
;
772 /* These sections are what may appear in a (real or virtual) DWO file. */
776 struct dwarf2_section_info abbrev
;
777 struct dwarf2_section_info line
;
778 struct dwarf2_section_info loc
;
779 struct dwarf2_section_info loclists
;
780 struct dwarf2_section_info macinfo
;
781 struct dwarf2_section_info macro
;
782 struct dwarf2_section_info str
;
783 struct dwarf2_section_info str_offsets
;
784 /* In the case of a virtual DWO file, these two are unused. */
785 struct dwarf2_section_info info
;
786 VEC (dwarf2_section_info_def
) *types
;
789 /* CUs/TUs in DWP/DWO files. */
793 /* Backlink to the containing struct dwo_file. */
794 struct dwo_file
*dwo_file
;
796 /* The "id" that distinguishes this CU/TU.
797 .debug_info calls this "dwo_id", .debug_types calls this "signature".
798 Since signatures came first, we stick with it for consistency. */
801 /* The section this CU/TU lives in, in the DWO file. */
802 struct dwarf2_section_info
*section
;
804 /* Same as dwarf2_per_cu_data:{offset,length} but in the DWO section. */
808 /* For types, offset in the type's DIE of the type defined by this TU. */
809 cu_offset type_offset_in_tu
;
812 /* include/dwarf2.h defines the DWP section codes.
813 It defines a max value but it doesn't define a min value, which we
814 use for error checking, so provide one. */
816 enum dwp_v2_section_ids
821 /* Data for one DWO file.
823 This includes virtual DWO files (a virtual DWO file is a DWO file as it
824 appears in a DWP file). DWP files don't really have DWO files per se -
825 comdat folding of types "loses" the DWO file they came from, and from
826 a high level view DWP files appear to contain a mass of random types.
827 However, to maintain consistency with the non-DWP case we pretend DWP
828 files contain virtual DWO files, and we assign each TU with one virtual
829 DWO file (generally based on the line and abbrev section offsets -
830 a heuristic that seems to work in practice). */
834 /* The DW_AT_GNU_dwo_name attribute.
835 For virtual DWO files the name is constructed from the section offsets
836 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
837 from related CU+TUs. */
838 const char *dwo_name
;
840 /* The DW_AT_comp_dir attribute. */
841 const char *comp_dir
;
843 /* The bfd, when the file is open. Otherwise this is NULL.
844 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
847 /* The sections that make up this DWO file.
848 Remember that for virtual DWO files in DWP V2, these are virtual
849 sections (for lack of a better name). */
850 struct dwo_sections sections
;
852 /* The CU in the file.
853 We only support one because having more than one requires hacking the
854 dwo_name of each to match, which is highly unlikely to happen.
855 Doing this means all TUs can share comp_dir: We also assume that
856 DW_AT_comp_dir across all TUs in a DWO file will be identical. */
859 /* Table of TUs in the file.
860 Each element is a struct dwo_unit. */
864 /* These sections are what may appear in a DWP file. */
868 /* These are used by both DWP version 1 and 2. */
869 struct dwarf2_section_info str
;
870 struct dwarf2_section_info cu_index
;
871 struct dwarf2_section_info tu_index
;
873 /* These are only used by DWP version 2 files.
874 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
875 sections are referenced by section number, and are not recorded here.
876 In DWP version 2 there is at most one copy of all these sections, each
877 section being (effectively) comprised of the concatenation of all of the
878 individual sections that exist in the version 1 format.
879 To keep the code simple we treat each of these concatenated pieces as a
880 section itself (a virtual section?). */
881 struct dwarf2_section_info abbrev
;
882 struct dwarf2_section_info info
;
883 struct dwarf2_section_info line
;
884 struct dwarf2_section_info loc
;
885 struct dwarf2_section_info macinfo
;
886 struct dwarf2_section_info macro
;
887 struct dwarf2_section_info str_offsets
;
888 struct dwarf2_section_info types
;
891 /* These sections are what may appear in a virtual DWO file in DWP version 1.
892 A virtual DWO file is a DWO file as it appears in a DWP file. */
894 struct virtual_v1_dwo_sections
896 struct dwarf2_section_info abbrev
;
897 struct dwarf2_section_info line
;
898 struct dwarf2_section_info loc
;
899 struct dwarf2_section_info macinfo
;
900 struct dwarf2_section_info macro
;
901 struct dwarf2_section_info str_offsets
;
902 /* Each DWP hash table entry records one CU or one TU.
903 That is recorded here, and copied to dwo_unit.section. */
904 struct dwarf2_section_info info_or_types
;
907 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
908 In version 2, the sections of the DWO files are concatenated together
909 and stored in one section of that name. Thus each ELF section contains
910 several "virtual" sections. */
912 struct virtual_v2_dwo_sections
914 bfd_size_type abbrev_offset
;
915 bfd_size_type abbrev_size
;
917 bfd_size_type line_offset
;
918 bfd_size_type line_size
;
920 bfd_size_type loc_offset
;
921 bfd_size_type loc_size
;
923 bfd_size_type macinfo_offset
;
924 bfd_size_type macinfo_size
;
926 bfd_size_type macro_offset
;
927 bfd_size_type macro_size
;
929 bfd_size_type str_offsets_offset
;
930 bfd_size_type str_offsets_size
;
932 /* Each DWP hash table entry records one CU or one TU.
933 That is recorded here, and copied to dwo_unit.section. */
934 bfd_size_type info_or_types_offset
;
935 bfd_size_type info_or_types_size
;
938 /* Contents of DWP hash tables. */
940 struct dwp_hash_table
942 uint32_t version
, nr_columns
;
943 uint32_t nr_units
, nr_slots
;
944 const gdb_byte
*hash_table
, *unit_table
;
949 const gdb_byte
*indices
;
953 /* This is indexed by column number and gives the id of the section
955 #define MAX_NR_V2_DWO_SECTIONS \
956 (1 /* .debug_info or .debug_types */ \
957 + 1 /* .debug_abbrev */ \
958 + 1 /* .debug_line */ \
959 + 1 /* .debug_loc */ \
960 + 1 /* .debug_str_offsets */ \
961 + 1 /* .debug_macro or .debug_macinfo */)
962 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
963 const gdb_byte
*offsets
;
964 const gdb_byte
*sizes
;
969 /* Data for one DWP file. */
973 /* Name of the file. */
976 /* File format version. */
982 /* Section info for this file. */
983 struct dwp_sections sections
;
985 /* Table of CUs in the file. */
986 const struct dwp_hash_table
*cus
;
988 /* Table of TUs in the file. */
989 const struct dwp_hash_table
*tus
;
991 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
995 /* Table to map ELF section numbers to their sections.
996 This is only needed for the DWP V1 file format. */
997 unsigned int num_sections
;
998 asection
**elf_sections
;
1001 /* This represents a '.dwz' file. */
1005 /* A dwz file can only contain a few sections. */
1006 struct dwarf2_section_info abbrev
;
1007 struct dwarf2_section_info info
;
1008 struct dwarf2_section_info str
;
1009 struct dwarf2_section_info line
;
1010 struct dwarf2_section_info macro
;
1011 struct dwarf2_section_info gdb_index
;
1013 /* The dwz's BFD. */
1017 /* Struct used to pass misc. parameters to read_die_and_children, et
1018 al. which are used for both .debug_info and .debug_types dies.
1019 All parameters here are unchanging for the life of the call. This
1020 struct exists to abstract away the constant parameters of die reading. */
1022 struct die_reader_specs
1024 /* The bfd of die_section. */
1027 /* The CU of the DIE we are parsing. */
1028 struct dwarf2_cu
*cu
;
1030 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1031 struct dwo_file
*dwo_file
;
1033 /* The section the die comes from.
1034 This is either .debug_info or .debug_types, or the .dwo variants. */
1035 struct dwarf2_section_info
*die_section
;
1037 /* die_section->buffer. */
1038 const gdb_byte
*buffer
;
1040 /* The end of the buffer. */
1041 const gdb_byte
*buffer_end
;
1043 /* The value of the DW_AT_comp_dir attribute. */
1044 const char *comp_dir
;
1047 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1048 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1049 const gdb_byte
*info_ptr
,
1050 struct die_info
*comp_unit_die
,
1057 unsigned int dir_index
;
1058 unsigned int mod_time
;
1059 unsigned int length
;
1060 /* Non-zero if referenced by the Line Number Program. */
1062 /* The associated symbol table, if any. */
1063 struct symtab
*symtab
;
1066 /* The line number information for a compilation unit (found in the
1067 .debug_line section) begins with a "statement program header",
1068 which contains the following information. */
1071 /* Offset of line number information in .debug_line section. */
1074 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1075 unsigned offset_in_dwz
: 1;
1077 unsigned int total_length
;
1078 unsigned short version
;
1079 unsigned int header_length
;
1080 unsigned char minimum_instruction_length
;
1081 unsigned char maximum_ops_per_instruction
;
1082 unsigned char default_is_stmt
;
1084 unsigned char line_range
;
1085 unsigned char opcode_base
;
1087 /* standard_opcode_lengths[i] is the number of operands for the
1088 standard opcode whose value is i. This means that
1089 standard_opcode_lengths[0] is unused, and the last meaningful
1090 element is standard_opcode_lengths[opcode_base - 1]. */
1091 unsigned char *standard_opcode_lengths
;
1093 /* The include_directories table. NOTE! These strings are not
1094 allocated with xmalloc; instead, they are pointers into
1095 debug_line_buffer. If you try to free them, `free' will get
1097 unsigned int num_include_dirs
, include_dirs_size
;
1098 const char **include_dirs
;
1100 /* The file_names table. NOTE! These strings are not allocated
1101 with xmalloc; instead, they are pointers into debug_line_buffer.
1102 Don't try to free them directly. */
1103 unsigned int num_file_names
, file_names_size
;
1104 struct file_entry
*file_names
;
1106 /* The start and end of the statement program following this
1107 header. These point into dwarf2_per_objfile->line_buffer. */
1108 const gdb_byte
*statement_program_start
, *statement_program_end
;
1111 /* When we construct a partial symbol table entry we only
1112 need this much information. */
1113 struct partial_die_info
1115 /* Offset of this DIE. */
1118 /* DWARF-2 tag for this DIE. */
1119 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1121 /* Assorted flags describing the data found in this DIE. */
1122 unsigned int has_children
: 1;
1123 unsigned int is_external
: 1;
1124 unsigned int is_declaration
: 1;
1125 unsigned int has_type
: 1;
1126 unsigned int has_specification
: 1;
1127 unsigned int has_pc_info
: 1;
1128 unsigned int may_be_inlined
: 1;
1130 /* This DIE has been marked DW_AT_main_subprogram. */
1131 unsigned int main_subprogram
: 1;
1133 /* Flag set if the SCOPE field of this structure has been
1135 unsigned int scope_set
: 1;
1137 /* Flag set if the DIE has a byte_size attribute. */
1138 unsigned int has_byte_size
: 1;
1140 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1141 unsigned int has_const_value
: 1;
1143 /* Flag set if any of the DIE's children are template arguments. */
1144 unsigned int has_template_arguments
: 1;
1146 /* Flag set if fixup_partial_die has been called on this die. */
1147 unsigned int fixup_called
: 1;
1149 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1150 unsigned int is_dwz
: 1;
1152 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1153 unsigned int spec_is_dwz
: 1;
1155 /* The name of this DIE. Normally the value of DW_AT_name, but
1156 sometimes a default name for unnamed DIEs. */
1159 /* The linkage name, if present. */
1160 const char *linkage_name
;
1162 /* The scope to prepend to our children. This is generally
1163 allocated on the comp_unit_obstack, so will disappear
1164 when this compilation unit leaves the cache. */
1167 /* Some data associated with the partial DIE. The tag determines
1168 which field is live. */
1171 /* The location description associated with this DIE, if any. */
1172 struct dwarf_block
*locdesc
;
1173 /* The offset of an import, for DW_TAG_imported_unit. */
1177 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1181 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1182 DW_AT_sibling, if any. */
1183 /* NOTE: This member isn't strictly necessary, read_partial_die could
1184 return DW_AT_sibling values to its caller load_partial_dies. */
1185 const gdb_byte
*sibling
;
1187 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1188 DW_AT_specification (or DW_AT_abstract_origin or
1189 DW_AT_extension). */
1190 sect_offset spec_offset
;
1192 /* Pointers to this DIE's parent, first child, and next sibling,
1194 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
1197 /* This data structure holds the information of an abbrev. */
1200 unsigned int number
; /* number identifying abbrev */
1201 enum dwarf_tag tag
; /* dwarf tag */
1202 unsigned short has_children
; /* boolean */
1203 unsigned short num_attrs
; /* number of attributes */
1204 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1205 struct abbrev_info
*next
; /* next in chain */
1210 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1211 ENUM_BITFIELD(dwarf_form
) form
: 16;
1213 /* It is valid only if FORM is DW_FORM_implicit_const. */
1214 LONGEST implicit_const
;
1217 /* Size of abbrev_table.abbrev_hash_table. */
1218 #define ABBREV_HASH_SIZE 121
1220 /* Top level data structure to contain an abbreviation table. */
1224 /* Where the abbrev table came from.
1225 This is used as a sanity check when the table is used. */
1228 /* Storage for the abbrev table. */
1229 struct obstack abbrev_obstack
;
1231 /* Hash table of abbrevs.
1232 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1233 It could be statically allocated, but the previous code didn't so we
1235 struct abbrev_info
**abbrevs
;
1238 /* Attributes have a name and a value. */
1241 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1242 ENUM_BITFIELD(dwarf_form
) form
: 15;
1244 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1245 field should be in u.str (existing only for DW_STRING) but it is kept
1246 here for better struct attribute alignment. */
1247 unsigned int string_is_canonical
: 1;
1252 struct dwarf_block
*blk
;
1261 /* This data structure holds a complete die structure. */
1264 /* DWARF-2 tag for this DIE. */
1265 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1267 /* Number of attributes */
1268 unsigned char num_attrs
;
1270 /* True if we're presently building the full type name for the
1271 type derived from this DIE. */
1272 unsigned char building_fullname
: 1;
1274 /* True if this die is in process. PR 16581. */
1275 unsigned char in_process
: 1;
1278 unsigned int abbrev
;
1280 /* Offset in .debug_info or .debug_types section. */
1283 /* The dies in a compilation unit form an n-ary tree. PARENT
1284 points to this die's parent; CHILD points to the first child of
1285 this node; and all the children of a given node are chained
1286 together via their SIBLING fields. */
1287 struct die_info
*child
; /* Its first child, if any. */
1288 struct die_info
*sibling
; /* Its next sibling, if any. */
1289 struct die_info
*parent
; /* Its parent, if any. */
1291 /* An array of attributes, with NUM_ATTRS elements. There may be
1292 zero, but it's not common and zero-sized arrays are not
1293 sufficiently portable C. */
1294 struct attribute attrs
[1];
1297 /* Get at parts of an attribute structure. */
1299 #define DW_STRING(attr) ((attr)->u.str)
1300 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1301 #define DW_UNSND(attr) ((attr)->u.unsnd)
1302 #define DW_BLOCK(attr) ((attr)->u.blk)
1303 #define DW_SND(attr) ((attr)->u.snd)
1304 #define DW_ADDR(attr) ((attr)->u.addr)
1305 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1307 /* Blocks are a bunch of untyped bytes. */
1312 /* Valid only if SIZE is not zero. */
1313 const gdb_byte
*data
;
1316 #ifndef ATTR_ALLOC_CHUNK
1317 #define ATTR_ALLOC_CHUNK 4
1320 /* Allocate fields for structs, unions and enums in this size. */
1321 #ifndef DW_FIELD_ALLOC_CHUNK
1322 #define DW_FIELD_ALLOC_CHUNK 4
1325 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1326 but this would require a corresponding change in unpack_field_as_long
1328 static int bits_per_byte
= 8;
1332 struct nextfield
*next
;
1340 struct nextfnfield
*next
;
1341 struct fn_field fnfield
;
1348 struct nextfnfield
*head
;
1351 struct typedef_field_list
1353 struct typedef_field field
;
1354 struct typedef_field_list
*next
;
1357 /* The routines that read and process dies for a C struct or C++ class
1358 pass lists of data member fields and lists of member function fields
1359 in an instance of a field_info structure, as defined below. */
1362 /* List of data member and baseclasses fields. */
1363 struct nextfield
*fields
, *baseclasses
;
1365 /* Number of fields (including baseclasses). */
1368 /* Number of baseclasses. */
1371 /* Set if the accesibility of one of the fields is not public. */
1372 int non_public_fields
;
1374 /* Member function fields array, entries are allocated in the order they
1375 are encountered in the object file. */
1376 struct nextfnfield
*fnfields
;
1378 /* Member function fieldlist array, contains name of possibly overloaded
1379 member function, number of overloaded member functions and a pointer
1380 to the head of the member function field chain. */
1381 struct fnfieldlist
*fnfieldlists
;
1383 /* Number of entries in the fnfieldlists array. */
1386 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1387 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1388 struct typedef_field_list
*typedef_field_list
;
1389 unsigned typedef_field_list_count
;
1392 /* One item on the queue of compilation units to read in full symbols
1394 struct dwarf2_queue_item
1396 struct dwarf2_per_cu_data
*per_cu
;
1397 enum language pretend_language
;
1398 struct dwarf2_queue_item
*next
;
1401 /* The current queue. */
1402 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1404 /* Loaded secondary compilation units are kept in memory until they
1405 have not been referenced for the processing of this many
1406 compilation units. Set this to zero to disable caching. Cache
1407 sizes of up to at least twenty will improve startup time for
1408 typical inter-CU-reference binaries, at an obvious memory cost. */
1409 static int dwarf_max_cache_age
= 5;
1411 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1412 struct cmd_list_element
*c
, const char *value
)
1414 fprintf_filtered (file
, _("The upper bound on the age of cached "
1415 "DWARF compilation units is %s.\n"),
1419 /* local function prototypes */
1421 static const char *get_section_name (const struct dwarf2_section_info
*);
1423 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1425 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1427 static void dwarf2_find_base_address (struct die_info
*die
,
1428 struct dwarf2_cu
*cu
);
1430 static struct partial_symtab
*create_partial_symtab
1431 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1433 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1435 static void scan_partial_symbols (struct partial_die_info
*,
1436 CORE_ADDR
*, CORE_ADDR
*,
1437 int, struct dwarf2_cu
*);
1439 static void add_partial_symbol (struct partial_die_info
*,
1440 struct dwarf2_cu
*);
1442 static void add_partial_namespace (struct partial_die_info
*pdi
,
1443 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1444 int set_addrmap
, struct dwarf2_cu
*cu
);
1446 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1447 CORE_ADDR
*highpc
, int set_addrmap
,
1448 struct dwarf2_cu
*cu
);
1450 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1451 struct dwarf2_cu
*cu
);
1453 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1454 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1455 int need_pc
, struct dwarf2_cu
*cu
);
1457 static void dwarf2_read_symtab (struct partial_symtab
*,
1460 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1462 static struct abbrev_info
*abbrev_table_lookup_abbrev
1463 (const struct abbrev_table
*, unsigned int);
1465 static struct abbrev_table
*abbrev_table_read_table
1466 (struct dwarf2_section_info
*, sect_offset
);
1468 static void abbrev_table_free (struct abbrev_table
*);
1470 static void abbrev_table_free_cleanup (void *);
1472 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1473 struct dwarf2_section_info
*);
1475 static void dwarf2_free_abbrev_table (void *);
1477 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1479 static struct partial_die_info
*load_partial_dies
1480 (const struct die_reader_specs
*, const gdb_byte
*, int);
1482 static const gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1483 struct partial_die_info
*,
1484 struct abbrev_info
*,
1488 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1489 struct dwarf2_cu
*);
1491 static void fixup_partial_die (struct partial_die_info
*,
1492 struct dwarf2_cu
*);
1494 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1495 struct attribute
*, struct attr_abbrev
*,
1498 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1500 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1502 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1504 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1506 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1508 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1511 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1513 static LONGEST read_checked_initial_length_and_offset
1514 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1515 unsigned int *, unsigned int *);
1517 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1518 const struct comp_unit_head
*,
1521 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1523 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1526 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1528 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1530 static const char *read_indirect_string (bfd
*, const gdb_byte
*,
1531 const struct comp_unit_head
*,
1534 static const char *read_indirect_line_string (bfd
*, const gdb_byte
*,
1535 const struct comp_unit_head
*,
1538 static const char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1540 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1542 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1546 static const char *read_str_index (const struct die_reader_specs
*reader
,
1547 ULONGEST str_index
);
1549 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1551 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1552 struct dwarf2_cu
*);
1554 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1557 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1558 struct dwarf2_cu
*cu
);
1560 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1561 struct dwarf2_cu
*cu
);
1563 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1565 static struct die_info
*die_specification (struct die_info
*die
,
1566 struct dwarf2_cu
**);
1568 static void free_line_header (struct line_header
*lh
);
1570 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1571 struct dwarf2_cu
*cu
);
1573 static void dwarf_decode_lines (struct line_header
*, const char *,
1574 struct dwarf2_cu
*, struct partial_symtab
*,
1575 CORE_ADDR
, int decode_mapping
);
1577 static void dwarf2_start_subfile (const char *, const char *);
1579 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1580 const char *, const char *,
1583 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1584 struct dwarf2_cu
*);
1586 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1587 struct dwarf2_cu
*, struct symbol
*);
1589 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1590 struct dwarf2_cu
*);
1592 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1595 struct obstack
*obstack
,
1596 struct dwarf2_cu
*cu
, LONGEST
*value
,
1597 const gdb_byte
**bytes
,
1598 struct dwarf2_locexpr_baton
**baton
);
1600 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1602 static int need_gnat_info (struct dwarf2_cu
*);
1604 static struct type
*die_descriptive_type (struct die_info
*,
1605 struct dwarf2_cu
*);
1607 static void set_descriptive_type (struct type
*, struct die_info
*,
1608 struct dwarf2_cu
*);
1610 static struct type
*die_containing_type (struct die_info
*,
1611 struct dwarf2_cu
*);
1613 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1614 struct dwarf2_cu
*);
1616 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1618 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1620 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1622 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1623 const char *suffix
, int physname
,
1624 struct dwarf2_cu
*cu
);
1626 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1628 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1630 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1632 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1634 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1636 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1637 struct dwarf2_cu
*, struct partial_symtab
*);
1639 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1640 values. Keep the items ordered with increasing constraints compliance. */
1643 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1644 PC_BOUNDS_NOT_PRESENT
,
1646 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1647 were present but they do not form a valid range of PC addresses. */
1650 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1653 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1657 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1658 CORE_ADDR
*, CORE_ADDR
*,
1660 struct partial_symtab
*);
1662 static void get_scope_pc_bounds (struct die_info
*,
1663 CORE_ADDR
*, CORE_ADDR
*,
1664 struct dwarf2_cu
*);
1666 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1667 CORE_ADDR
, struct dwarf2_cu
*);
1669 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1670 struct dwarf2_cu
*);
1672 static void dwarf2_attach_fields_to_type (struct field_info
*,
1673 struct type
*, struct dwarf2_cu
*);
1675 static void dwarf2_add_member_fn (struct field_info
*,
1676 struct die_info
*, struct type
*,
1677 struct dwarf2_cu
*);
1679 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1681 struct dwarf2_cu
*);
1683 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1685 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1687 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1689 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1691 static struct using_direct
**using_directives (enum language
);
1693 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1695 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1697 static struct type
*read_module_type (struct die_info
*die
,
1698 struct dwarf2_cu
*cu
);
1700 static const char *namespace_name (struct die_info
*die
,
1701 int *is_anonymous
, struct dwarf2_cu
*);
1703 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1705 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1707 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1708 struct dwarf2_cu
*);
1710 static struct die_info
*read_die_and_siblings_1
1711 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1714 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1715 const gdb_byte
*info_ptr
,
1716 const gdb_byte
**new_info_ptr
,
1717 struct die_info
*parent
);
1719 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1720 struct die_info
**, const gdb_byte
*,
1723 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1724 struct die_info
**, const gdb_byte
*,
1727 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1729 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1732 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1734 static const char *dwarf2_full_name (const char *name
,
1735 struct die_info
*die
,
1736 struct dwarf2_cu
*cu
);
1738 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1739 struct dwarf2_cu
*cu
);
1741 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1742 struct dwarf2_cu
**);
1744 static const char *dwarf_tag_name (unsigned int);
1746 static const char *dwarf_attr_name (unsigned int);
1748 static const char *dwarf_form_name (unsigned int);
1750 static char *dwarf_bool_name (unsigned int);
1752 static const char *dwarf_type_encoding_name (unsigned int);
1754 static struct die_info
*sibling_die (struct die_info
*);
1756 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1758 static void dump_die_for_error (struct die_info
*);
1760 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1763 /*static*/ void dump_die (struct die_info
*, int max_level
);
1765 static void store_in_ref_table (struct die_info
*,
1766 struct dwarf2_cu
*);
1768 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1770 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1772 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1773 const struct attribute
*,
1774 struct dwarf2_cu
**);
1776 static struct die_info
*follow_die_ref (struct die_info
*,
1777 const struct attribute
*,
1778 struct dwarf2_cu
**);
1780 static struct die_info
*follow_die_sig (struct die_info
*,
1781 const struct attribute
*,
1782 struct dwarf2_cu
**);
1784 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1785 struct dwarf2_cu
*);
1787 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1788 const struct attribute
*,
1789 struct dwarf2_cu
*);
1791 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1793 static void read_signatured_type (struct signatured_type
*);
1795 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1796 struct die_info
*die
, struct dwarf2_cu
*cu
,
1797 struct dynamic_prop
*prop
);
1799 /* memory allocation interface */
1801 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1803 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1805 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1807 static int attr_form_is_block (const struct attribute
*);
1809 static int attr_form_is_section_offset (const struct attribute
*);
1811 static int attr_form_is_constant (const struct attribute
*);
1813 static int attr_form_is_ref (const struct attribute
*);
1815 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1816 struct dwarf2_loclist_baton
*baton
,
1817 const struct attribute
*attr
);
1819 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1821 struct dwarf2_cu
*cu
,
1824 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1825 const gdb_byte
*info_ptr
,
1826 struct abbrev_info
*abbrev
);
1828 static void free_stack_comp_unit (void *);
1830 static hashval_t
partial_die_hash (const void *item
);
1832 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1834 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1835 (sect_offset offset
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1837 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1838 struct dwarf2_per_cu_data
*per_cu
);
1840 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1841 struct die_info
*comp_unit_die
,
1842 enum language pretend_language
);
1844 static void free_heap_comp_unit (void *);
1846 static void free_cached_comp_units (void *);
1848 static void age_cached_comp_units (void);
1850 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1852 static struct type
*set_die_type (struct die_info
*, struct type
*,
1853 struct dwarf2_cu
*);
1855 static void create_all_comp_units (struct objfile
*);
1857 static int create_all_type_units (struct objfile
*);
1859 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1862 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1865 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1868 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1869 struct dwarf2_per_cu_data
*);
1871 static void dwarf2_mark (struct dwarf2_cu
*);
1873 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1875 static struct type
*get_die_type_at_offset (sect_offset
,
1876 struct dwarf2_per_cu_data
*);
1878 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1880 static void dwarf2_release_queue (void *dummy
);
1882 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1883 enum language pretend_language
);
1885 static void process_queue (void);
1887 static void find_file_and_directory (struct die_info
*die
,
1888 struct dwarf2_cu
*cu
,
1889 const char **name
, const char **comp_dir
);
1891 static char *file_full_name (int file
, struct line_header
*lh
,
1892 const char *comp_dir
);
1894 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1895 enum class rcuh_kind
{ COMPILE
, TYPE
};
1897 static const gdb_byte
*read_and_check_comp_unit_head
1898 (struct comp_unit_head
*header
,
1899 struct dwarf2_section_info
*section
,
1900 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1901 rcuh_kind section_kind
);
1903 static void init_cutu_and_read_dies
1904 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1905 int use_existing_cu
, int keep
,
1906 die_reader_func_ftype
*die_reader_func
, void *data
);
1908 static void init_cutu_and_read_dies_simple
1909 (struct dwarf2_per_cu_data
*this_cu
,
1910 die_reader_func_ftype
*die_reader_func
, void *data
);
1912 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1914 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1916 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1917 (struct dwp_file
*dwp_file
, const char *comp_dir
,
1918 ULONGEST signature
, int is_debug_types
);
1920 static struct dwp_file
*get_dwp_file (void);
1922 static struct dwo_unit
*lookup_dwo_comp_unit
1923 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1925 static struct dwo_unit
*lookup_dwo_type_unit
1926 (struct signatured_type
*, const char *, const char *);
1928 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1930 static void free_dwo_file_cleanup (void *);
1932 static void process_cu_includes (void);
1934 static void check_producer (struct dwarf2_cu
*cu
);
1936 static void free_line_header_voidp (void *arg
);
1938 /* Various complaints about symbol reading that don't abort the process. */
1941 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1943 complaint (&symfile_complaints
,
1944 _("statement list doesn't fit in .debug_line section"));
1948 dwarf2_debug_line_missing_file_complaint (void)
1950 complaint (&symfile_complaints
,
1951 _(".debug_line section has line data without a file"));
1955 dwarf2_debug_line_missing_end_sequence_complaint (void)
1957 complaint (&symfile_complaints
,
1958 _(".debug_line section has line "
1959 "program sequence without an end"));
1963 dwarf2_complex_location_expr_complaint (void)
1965 complaint (&symfile_complaints
, _("location expression too complex"));
1969 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1972 complaint (&symfile_complaints
,
1973 _("const value length mismatch for '%s', got %d, expected %d"),
1978 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1980 complaint (&symfile_complaints
,
1981 _("debug info runs off end of %s section"
1983 get_section_name (section
),
1984 get_section_file_name (section
));
1988 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1990 complaint (&symfile_complaints
,
1991 _("macro debug info contains a "
1992 "malformed macro definition:\n`%s'"),
1997 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1999 complaint (&symfile_complaints
,
2000 _("invalid attribute class or form for '%s' in '%s'"),
2004 /* Hash function for line_header_hash. */
2007 line_header_hash (const struct line_header
*ofs
)
2009 return ofs
->offset
.sect_off
^ ofs
->offset_in_dwz
;
2012 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2015 line_header_hash_voidp (const void *item
)
2017 const struct line_header
*ofs
= (const struct line_header
*) item
;
2019 return line_header_hash (ofs
);
2022 /* Equality function for line_header_hash. */
2025 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2027 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2028 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2030 return (ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
2031 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2037 /* Convert VALUE between big- and little-endian. */
2039 byte_swap (offset_type value
)
2043 result
= (value
& 0xff) << 24;
2044 result
|= (value
& 0xff00) << 8;
2045 result
|= (value
& 0xff0000) >> 8;
2046 result
|= (value
& 0xff000000) >> 24;
2050 #define MAYBE_SWAP(V) byte_swap (V)
2053 #define MAYBE_SWAP(V) (V)
2054 #endif /* WORDS_BIGENDIAN */
2056 /* Read the given attribute value as an address, taking the attribute's
2057 form into account. */
2060 attr_value_as_address (struct attribute
*attr
)
2064 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2066 /* Aside from a few clearly defined exceptions, attributes that
2067 contain an address must always be in DW_FORM_addr form.
2068 Unfortunately, some compilers happen to be violating this
2069 requirement by encoding addresses using other forms, such
2070 as DW_FORM_data4 for example. For those broken compilers,
2071 we try to do our best, without any guarantee of success,
2072 to interpret the address correctly. It would also be nice
2073 to generate a complaint, but that would require us to maintain
2074 a list of legitimate cases where a non-address form is allowed,
2075 as well as update callers to pass in at least the CU's DWARF
2076 version. This is more overhead than what we're willing to
2077 expand for a pretty rare case. */
2078 addr
= DW_UNSND (attr
);
2081 addr
= DW_ADDR (attr
);
2086 /* The suffix for an index file. */
2087 #define INDEX_SUFFIX ".gdb-index"
2089 /* Try to locate the sections we need for DWARF 2 debugging
2090 information and return true if we have enough to do something.
2091 NAMES points to the dwarf2 section names, or is NULL if the standard
2092 ELF names are used. */
2095 dwarf2_has_info (struct objfile
*objfile
,
2096 const struct dwarf2_debug_sections
*names
)
2098 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
2099 objfile_data (objfile
, dwarf2_objfile_data_key
));
2100 if (!dwarf2_per_objfile
)
2102 /* Initialize per-objfile state. */
2103 struct dwarf2_per_objfile
*data
2104 = XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_objfile
);
2106 memset (data
, 0, sizeof (*data
));
2107 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
2108 dwarf2_per_objfile
= data
;
2110 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
2112 dwarf2_per_objfile
->objfile
= objfile
;
2114 return (!dwarf2_per_objfile
->info
.is_virtual
2115 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2116 && !dwarf2_per_objfile
->abbrev
.is_virtual
2117 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2120 /* Return the containing section of virtual section SECTION. */
2122 static struct dwarf2_section_info
*
2123 get_containing_section (const struct dwarf2_section_info
*section
)
2125 gdb_assert (section
->is_virtual
);
2126 return section
->s
.containing_section
;
2129 /* Return the bfd owner of SECTION. */
2132 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2134 if (section
->is_virtual
)
2136 section
= get_containing_section (section
);
2137 gdb_assert (!section
->is_virtual
);
2139 return section
->s
.section
->owner
;
2142 /* Return the bfd section of SECTION.
2143 Returns NULL if the section is not present. */
2146 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2148 if (section
->is_virtual
)
2150 section
= get_containing_section (section
);
2151 gdb_assert (!section
->is_virtual
);
2153 return section
->s
.section
;
2156 /* Return the name of SECTION. */
2159 get_section_name (const struct dwarf2_section_info
*section
)
2161 asection
*sectp
= get_section_bfd_section (section
);
2163 gdb_assert (sectp
!= NULL
);
2164 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2167 /* Return the name of the file SECTION is in. */
2170 get_section_file_name (const struct dwarf2_section_info
*section
)
2172 bfd
*abfd
= get_section_bfd_owner (section
);
2174 return bfd_get_filename (abfd
);
2177 /* Return the id of SECTION.
2178 Returns 0 if SECTION doesn't exist. */
2181 get_section_id (const struct dwarf2_section_info
*section
)
2183 asection
*sectp
= get_section_bfd_section (section
);
2190 /* Return the flags of SECTION.
2191 SECTION (or containing section if this is a virtual section) must exist. */
2194 get_section_flags (const struct dwarf2_section_info
*section
)
2196 asection
*sectp
= get_section_bfd_section (section
);
2198 gdb_assert (sectp
!= NULL
);
2199 return bfd_get_section_flags (sectp
->owner
, sectp
);
2202 /* When loading sections, we look either for uncompressed section or for
2203 compressed section names. */
2206 section_is_p (const char *section_name
,
2207 const struct dwarf2_section_names
*names
)
2209 if (names
->normal
!= NULL
2210 && strcmp (section_name
, names
->normal
) == 0)
2212 if (names
->compressed
!= NULL
2213 && strcmp (section_name
, names
->compressed
) == 0)
2218 /* This function is mapped across the sections and remembers the
2219 offset and size of each of the debugging sections we are interested
2223 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
2225 const struct dwarf2_debug_sections
*names
;
2226 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2229 names
= &dwarf2_elf_names
;
2231 names
= (const struct dwarf2_debug_sections
*) vnames
;
2233 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2236 else if (section_is_p (sectp
->name
, &names
->info
))
2238 dwarf2_per_objfile
->info
.s
.section
= sectp
;
2239 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
2241 else if (section_is_p (sectp
->name
, &names
->abbrev
))
2243 dwarf2_per_objfile
->abbrev
.s
.section
= sectp
;
2244 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
2246 else if (section_is_p (sectp
->name
, &names
->line
))
2248 dwarf2_per_objfile
->line
.s
.section
= sectp
;
2249 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
2251 else if (section_is_p (sectp
->name
, &names
->loc
))
2253 dwarf2_per_objfile
->loc
.s
.section
= sectp
;
2254 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
2256 else if (section_is_p (sectp
->name
, &names
->loclists
))
2258 dwarf2_per_objfile
->loclists
.s
.section
= sectp
;
2259 dwarf2_per_objfile
->loclists
.size
= bfd_get_section_size (sectp
);
2261 else if (section_is_p (sectp
->name
, &names
->macinfo
))
2263 dwarf2_per_objfile
->macinfo
.s
.section
= sectp
;
2264 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
2266 else if (section_is_p (sectp
->name
, &names
->macro
))
2268 dwarf2_per_objfile
->macro
.s
.section
= sectp
;
2269 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
2271 else if (section_is_p (sectp
->name
, &names
->str
))
2273 dwarf2_per_objfile
->str
.s
.section
= sectp
;
2274 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
2276 else if (section_is_p (sectp
->name
, &names
->line_str
))
2278 dwarf2_per_objfile
->line_str
.s
.section
= sectp
;
2279 dwarf2_per_objfile
->line_str
.size
= bfd_get_section_size (sectp
);
2281 else if (section_is_p (sectp
->name
, &names
->addr
))
2283 dwarf2_per_objfile
->addr
.s
.section
= sectp
;
2284 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
2286 else if (section_is_p (sectp
->name
, &names
->frame
))
2288 dwarf2_per_objfile
->frame
.s
.section
= sectp
;
2289 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
2291 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
2293 dwarf2_per_objfile
->eh_frame
.s
.section
= sectp
;
2294 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
2296 else if (section_is_p (sectp
->name
, &names
->ranges
))
2298 dwarf2_per_objfile
->ranges
.s
.section
= sectp
;
2299 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
2301 else if (section_is_p (sectp
->name
, &names
->rnglists
))
2303 dwarf2_per_objfile
->rnglists
.s
.section
= sectp
;
2304 dwarf2_per_objfile
->rnglists
.size
= bfd_get_section_size (sectp
);
2306 else if (section_is_p (sectp
->name
, &names
->types
))
2308 struct dwarf2_section_info type_section
;
2310 memset (&type_section
, 0, sizeof (type_section
));
2311 type_section
.s
.section
= sectp
;
2312 type_section
.size
= bfd_get_section_size (sectp
);
2314 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
2317 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
2319 dwarf2_per_objfile
->gdb_index
.s
.section
= sectp
;
2320 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
2323 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2324 && bfd_section_vma (abfd
, sectp
) == 0)
2325 dwarf2_per_objfile
->has_section_at_zero
= 1;
2328 /* A helper function that decides whether a section is empty,
2332 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2334 if (section
->is_virtual
)
2335 return section
->size
== 0;
2336 return section
->s
.section
== NULL
|| section
->size
== 0;
2339 /* Read the contents of the section INFO.
2340 OBJFILE is the main object file, but not necessarily the file where
2341 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2343 If the section is compressed, uncompress it before returning. */
2346 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2350 gdb_byte
*buf
, *retbuf
;
2354 info
->buffer
= NULL
;
2357 if (dwarf2_section_empty_p (info
))
2360 sectp
= get_section_bfd_section (info
);
2362 /* If this is a virtual section we need to read in the real one first. */
2363 if (info
->is_virtual
)
2365 struct dwarf2_section_info
*containing_section
=
2366 get_containing_section (info
);
2368 gdb_assert (sectp
!= NULL
);
2369 if ((sectp
->flags
& SEC_RELOC
) != 0)
2371 error (_("Dwarf Error: DWP format V2 with relocations is not"
2372 " supported in section %s [in module %s]"),
2373 get_section_name (info
), get_section_file_name (info
));
2375 dwarf2_read_section (objfile
, containing_section
);
2376 /* Other code should have already caught virtual sections that don't
2378 gdb_assert (info
->virtual_offset
+ info
->size
2379 <= containing_section
->size
);
2380 /* If the real section is empty or there was a problem reading the
2381 section we shouldn't get here. */
2382 gdb_assert (containing_section
->buffer
!= NULL
);
2383 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2387 /* If the section has relocations, we must read it ourselves.
2388 Otherwise we attach it to the BFD. */
2389 if ((sectp
->flags
& SEC_RELOC
) == 0)
2391 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2395 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2398 /* When debugging .o files, we may need to apply relocations; see
2399 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2400 We never compress sections in .o files, so we only need to
2401 try this when the section is not compressed. */
2402 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2405 info
->buffer
= retbuf
;
2409 abfd
= get_section_bfd_owner (info
);
2410 gdb_assert (abfd
!= NULL
);
2412 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2413 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2415 error (_("Dwarf Error: Can't read DWARF data"
2416 " in section %s [in module %s]"),
2417 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2421 /* A helper function that returns the size of a section in a safe way.
2422 If you are positive that the section has been read before using the
2423 size, then it is safe to refer to the dwarf2_section_info object's
2424 "size" field directly. In other cases, you must call this
2425 function, because for compressed sections the size field is not set
2426 correctly until the section has been read. */
2428 static bfd_size_type
2429 dwarf2_section_size (struct objfile
*objfile
,
2430 struct dwarf2_section_info
*info
)
2433 dwarf2_read_section (objfile
, info
);
2437 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2441 dwarf2_get_section_info (struct objfile
*objfile
,
2442 enum dwarf2_section_enum sect
,
2443 asection
**sectp
, const gdb_byte
**bufp
,
2444 bfd_size_type
*sizep
)
2446 struct dwarf2_per_objfile
*data
2447 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2448 dwarf2_objfile_data_key
);
2449 struct dwarf2_section_info
*info
;
2451 /* We may see an objfile without any DWARF, in which case we just
2462 case DWARF2_DEBUG_FRAME
:
2463 info
= &data
->frame
;
2465 case DWARF2_EH_FRAME
:
2466 info
= &data
->eh_frame
;
2469 gdb_assert_not_reached ("unexpected section");
2472 dwarf2_read_section (objfile
, info
);
2474 *sectp
= get_section_bfd_section (info
);
2475 *bufp
= info
->buffer
;
2476 *sizep
= info
->size
;
2479 /* A helper function to find the sections for a .dwz file. */
2482 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2484 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2486 /* Note that we only support the standard ELF names, because .dwz
2487 is ELF-only (at the time of writing). */
2488 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2490 dwz_file
->abbrev
.s
.section
= sectp
;
2491 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2493 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2495 dwz_file
->info
.s
.section
= sectp
;
2496 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2498 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2500 dwz_file
->str
.s
.section
= sectp
;
2501 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2503 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2505 dwz_file
->line
.s
.section
= sectp
;
2506 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2508 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2510 dwz_file
->macro
.s
.section
= sectp
;
2511 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2513 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2515 dwz_file
->gdb_index
.s
.section
= sectp
;
2516 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2520 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2521 there is no .gnu_debugaltlink section in the file. Error if there
2522 is such a section but the file cannot be found. */
2524 static struct dwz_file
*
2525 dwarf2_get_dwz_file (void)
2528 struct cleanup
*cleanup
;
2529 const char *filename
;
2530 struct dwz_file
*result
;
2531 bfd_size_type buildid_len_arg
;
2535 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2536 return dwarf2_per_objfile
->dwz_file
;
2538 bfd_set_error (bfd_error_no_error
);
2539 data
= bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2540 &buildid_len_arg
, &buildid
);
2543 if (bfd_get_error () == bfd_error_no_error
)
2545 error (_("could not read '.gnu_debugaltlink' section: %s"),
2546 bfd_errmsg (bfd_get_error ()));
2548 cleanup
= make_cleanup (xfree
, data
);
2549 make_cleanup (xfree
, buildid
);
2551 buildid_len
= (size_t) buildid_len_arg
;
2553 filename
= (const char *) data
;
2554 if (!IS_ABSOLUTE_PATH (filename
))
2556 char *abs
= gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2559 make_cleanup (xfree
, abs
);
2560 abs
= ldirname (abs
);
2561 make_cleanup (xfree
, abs
);
2563 rel
= concat (abs
, SLASH_STRING
, filename
, (char *) NULL
);
2564 make_cleanup (xfree
, rel
);
2568 /* First try the file name given in the section. If that doesn't
2569 work, try to use the build-id instead. */
2570 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2571 if (dwz_bfd
!= NULL
)
2573 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2577 if (dwz_bfd
== NULL
)
2578 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2580 if (dwz_bfd
== NULL
)
2581 error (_("could not find '.gnu_debugaltlink' file for %s"),
2582 objfile_name (dwarf2_per_objfile
->objfile
));
2584 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2586 result
->dwz_bfd
= dwz_bfd
.release ();
2588 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
2590 do_cleanups (cleanup
);
2592 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
2593 dwarf2_per_objfile
->dwz_file
= result
;
2597 /* DWARF quick_symbols_functions support. */
2599 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2600 unique line tables, so we maintain a separate table of all .debug_line
2601 derived entries to support the sharing.
2602 All the quick functions need is the list of file names. We discard the
2603 line_header when we're done and don't need to record it here. */
2604 struct quick_file_names
2606 /* The data used to construct the hash key. */
2607 struct stmt_list_hash hash
;
2609 /* The number of entries in file_names, real_names. */
2610 unsigned int num_file_names
;
2612 /* The file names from the line table, after being run through
2614 const char **file_names
;
2616 /* The file names from the line table after being run through
2617 gdb_realpath. These are computed lazily. */
2618 const char **real_names
;
2621 /* When using the index (and thus not using psymtabs), each CU has an
2622 object of this type. This is used to hold information needed by
2623 the various "quick" methods. */
2624 struct dwarf2_per_cu_quick_data
2626 /* The file table. This can be NULL if there was no file table
2627 or it's currently not read in.
2628 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2629 struct quick_file_names
*file_names
;
2631 /* The corresponding symbol table. This is NULL if symbols for this
2632 CU have not yet been read. */
2633 struct compunit_symtab
*compunit_symtab
;
2635 /* A temporary mark bit used when iterating over all CUs in
2636 expand_symtabs_matching. */
2637 unsigned int mark
: 1;
2639 /* True if we've tried to read the file table and found there isn't one.
2640 There will be no point in trying to read it again next time. */
2641 unsigned int no_file_data
: 1;
2644 /* Utility hash function for a stmt_list_hash. */
2647 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2651 if (stmt_list_hash
->dwo_unit
!= NULL
)
2652 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2653 v
+= stmt_list_hash
->line_offset
.sect_off
;
2657 /* Utility equality function for a stmt_list_hash. */
2660 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2661 const struct stmt_list_hash
*rhs
)
2663 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2665 if (lhs
->dwo_unit
!= NULL
2666 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2669 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2672 /* Hash function for a quick_file_names. */
2675 hash_file_name_entry (const void *e
)
2677 const struct quick_file_names
*file_data
2678 = (const struct quick_file_names
*) e
;
2680 return hash_stmt_list_entry (&file_data
->hash
);
2683 /* Equality function for a quick_file_names. */
2686 eq_file_name_entry (const void *a
, const void *b
)
2688 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2689 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2691 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2694 /* Delete function for a quick_file_names. */
2697 delete_file_name_entry (void *e
)
2699 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2702 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2704 xfree ((void*) file_data
->file_names
[i
]);
2705 if (file_data
->real_names
)
2706 xfree ((void*) file_data
->real_names
[i
]);
2709 /* The space for the struct itself lives on objfile_obstack,
2710 so we don't free it here. */
2713 /* Create a quick_file_names hash table. */
2716 create_quick_file_names_table (unsigned int nr_initial_entries
)
2718 return htab_create_alloc (nr_initial_entries
,
2719 hash_file_name_entry
, eq_file_name_entry
,
2720 delete_file_name_entry
, xcalloc
, xfree
);
2723 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2724 have to be created afterwards. You should call age_cached_comp_units after
2725 processing PER_CU->CU. dw2_setup must have been already called. */
2728 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2730 if (per_cu
->is_debug_types
)
2731 load_full_type_unit (per_cu
);
2733 load_full_comp_unit (per_cu
, language_minimal
);
2735 if (per_cu
->cu
== NULL
)
2736 return; /* Dummy CU. */
2738 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2741 /* Read in the symbols for PER_CU. */
2744 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2746 struct cleanup
*back_to
;
2748 /* Skip type_unit_groups, reading the type units they contain
2749 is handled elsewhere. */
2750 if (IS_TYPE_UNIT_GROUP (per_cu
))
2753 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2755 if (dwarf2_per_objfile
->using_index
2756 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2757 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2759 queue_comp_unit (per_cu
, language_minimal
);
2762 /* If we just loaded a CU from a DWO, and we're working with an index
2763 that may badly handle TUs, load all the TUs in that DWO as well.
2764 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2765 if (!per_cu
->is_debug_types
2766 && per_cu
->cu
!= NULL
2767 && per_cu
->cu
->dwo_unit
!= NULL
2768 && dwarf2_per_objfile
->index_table
!= NULL
2769 && dwarf2_per_objfile
->index_table
->version
<= 7
2770 /* DWP files aren't supported yet. */
2771 && get_dwp_file () == NULL
)
2772 queue_and_load_all_dwo_tus (per_cu
);
2777 /* Age the cache, releasing compilation units that have not
2778 been used recently. */
2779 age_cached_comp_units ();
2781 do_cleanups (back_to
);
2784 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2785 the objfile from which this CU came. Returns the resulting symbol
2788 static struct compunit_symtab
*
2789 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2791 gdb_assert (dwarf2_per_objfile
->using_index
);
2792 if (!per_cu
->v
.quick
->compunit_symtab
)
2794 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2795 increment_reading_symtab ();
2796 dw2_do_instantiate_symtab (per_cu
);
2797 process_cu_includes ();
2798 do_cleanups (back_to
);
2801 return per_cu
->v
.quick
->compunit_symtab
;
2804 /* Return the CU/TU given its index.
2806 This is intended for loops like:
2808 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2809 + dwarf2_per_objfile->n_type_units); ++i)
2811 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
2817 static struct dwarf2_per_cu_data
*
2818 dw2_get_cutu (int index
)
2820 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2822 index
-= dwarf2_per_objfile
->n_comp_units
;
2823 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2824 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2827 return dwarf2_per_objfile
->all_comp_units
[index
];
2830 /* Return the CU given its index.
2831 This differs from dw2_get_cutu in that it's for when you know INDEX
2834 static struct dwarf2_per_cu_data
*
2835 dw2_get_cu (int index
)
2837 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
2839 return dwarf2_per_objfile
->all_comp_units
[index
];
2842 /* A helper for create_cus_from_index that handles a given list of
2846 create_cus_from_index_list (struct objfile
*objfile
,
2847 const gdb_byte
*cu_list
, offset_type n_elements
,
2848 struct dwarf2_section_info
*section
,
2854 for (i
= 0; i
< n_elements
; i
+= 2)
2856 struct dwarf2_per_cu_data
*the_cu
;
2857 ULONGEST offset
, length
;
2859 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2860 offset
= extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2861 length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2864 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2865 struct dwarf2_per_cu_data
);
2866 the_cu
->offset
.sect_off
= offset
;
2867 the_cu
->length
= length
;
2868 the_cu
->objfile
= objfile
;
2869 the_cu
->section
= section
;
2870 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2871 struct dwarf2_per_cu_quick_data
);
2872 the_cu
->is_dwz
= is_dwz
;
2873 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2877 /* Read the CU list from the mapped index, and use it to create all
2878 the CU objects for this objfile. */
2881 create_cus_from_index (struct objfile
*objfile
,
2882 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2883 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2885 struct dwz_file
*dwz
;
2887 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2888 dwarf2_per_objfile
->all_comp_units
=
2889 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
2890 dwarf2_per_objfile
->n_comp_units
);
2892 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2893 &dwarf2_per_objfile
->info
, 0, 0);
2895 if (dwz_elements
== 0)
2898 dwz
= dwarf2_get_dwz_file ();
2899 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
2900 cu_list_elements
/ 2);
2903 /* Create the signatured type hash table from the index. */
2906 create_signatured_type_table_from_index (struct objfile
*objfile
,
2907 struct dwarf2_section_info
*section
,
2908 const gdb_byte
*bytes
,
2909 offset_type elements
)
2912 htab_t sig_types_hash
;
2914 dwarf2_per_objfile
->n_type_units
2915 = dwarf2_per_objfile
->n_allocated_type_units
2917 dwarf2_per_objfile
->all_type_units
=
2918 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
2920 sig_types_hash
= allocate_signatured_type_table (objfile
);
2922 for (i
= 0; i
< elements
; i
+= 3)
2924 struct signatured_type
*sig_type
;
2925 ULONGEST offset
, type_offset_in_tu
, signature
;
2928 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2929 offset
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2930 type_offset_in_tu
= extract_unsigned_integer (bytes
+ 8, 8,
2932 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2935 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2936 struct signatured_type
);
2937 sig_type
->signature
= signature
;
2938 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2939 sig_type
->per_cu
.is_debug_types
= 1;
2940 sig_type
->per_cu
.section
= section
;
2941 sig_type
->per_cu
.offset
.sect_off
= offset
;
2942 sig_type
->per_cu
.objfile
= objfile
;
2943 sig_type
->per_cu
.v
.quick
2944 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2945 struct dwarf2_per_cu_quick_data
);
2947 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2950 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2953 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2956 /* Read the address map data from the mapped index, and use it to
2957 populate the objfile's psymtabs_addrmap. */
2960 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2962 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2963 const gdb_byte
*iter
, *end
;
2964 struct obstack temp_obstack
;
2965 struct addrmap
*mutable_map
;
2966 struct cleanup
*cleanup
;
2969 obstack_init (&temp_obstack
);
2970 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2971 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2973 iter
= index
->address_table
;
2974 end
= iter
+ index
->address_table_size
;
2976 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2980 ULONGEST hi
, lo
, cu_index
;
2981 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2983 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2985 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2990 complaint (&symfile_complaints
,
2991 _(".gdb_index address table has invalid range (%s - %s)"),
2992 hex_string (lo
), hex_string (hi
));
2996 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
2998 complaint (&symfile_complaints
,
2999 _(".gdb_index address table has invalid CU number %u"),
3000 (unsigned) cu_index
);
3004 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3005 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3006 addrmap_set_empty (mutable_map
, lo
, hi
- 1, dw2_get_cutu (cu_index
));
3009 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3010 &objfile
->objfile_obstack
);
3011 do_cleanups (cleanup
);
3014 /* The hash function for strings in the mapped index. This is the same as
3015 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
3016 implementation. This is necessary because the hash function is tied to the
3017 format of the mapped index file. The hash values do not have to match with
3020 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
3023 mapped_index_string_hash (int index_version
, const void *p
)
3025 const unsigned char *str
= (const unsigned char *) p
;
3029 while ((c
= *str
++) != 0)
3031 if (index_version
>= 5)
3033 r
= r
* 67 + c
- 113;
3039 /* Find a slot in the mapped index INDEX for the object named NAME.
3040 If NAME is found, set *VEC_OUT to point to the CU vector in the
3041 constant pool and return 1. If NAME cannot be found, return 0. */
3044 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3045 offset_type
**vec_out
)
3047 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3049 offset_type slot
, step
;
3050 int (*cmp
) (const char *, const char *);
3052 if (current_language
->la_language
== language_cplus
3053 || current_language
->la_language
== language_fortran
3054 || current_language
->la_language
== language_d
)
3056 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3059 if (strchr (name
, '(') != NULL
)
3061 char *without_params
= cp_remove_params (name
);
3063 if (without_params
!= NULL
)
3065 make_cleanup (xfree
, without_params
);
3066 name
= without_params
;
3071 /* Index version 4 did not support case insensitive searches. But the
3072 indices for case insensitive languages are built in lowercase, therefore
3073 simulate our NAME being searched is also lowercased. */
3074 hash
= mapped_index_string_hash ((index
->version
== 4
3075 && case_sensitivity
== case_sensitive_off
3076 ? 5 : index
->version
),
3079 slot
= hash
& (index
->symbol_table_slots
- 1);
3080 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
3081 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3085 /* Convert a slot number to an offset into the table. */
3086 offset_type i
= 2 * slot
;
3088 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
3090 do_cleanups (back_to
);
3094 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
3095 if (!cmp (name
, str
))
3097 *vec_out
= (offset_type
*) (index
->constant_pool
3098 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
3099 do_cleanups (back_to
);
3103 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
3107 /* A helper function that reads the .gdb_index from SECTION and fills
3108 in MAP. FILENAME is the name of the file containing the section;
3109 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3110 ok to use deprecated sections.
3112 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3113 out parameters that are filled in with information about the CU and
3114 TU lists in the section.
3116 Returns 1 if all went well, 0 otherwise. */
3119 read_index_from_section (struct objfile
*objfile
,
3120 const char *filename
,
3122 struct dwarf2_section_info
*section
,
3123 struct mapped_index
*map
,
3124 const gdb_byte
**cu_list
,
3125 offset_type
*cu_list_elements
,
3126 const gdb_byte
**types_list
,
3127 offset_type
*types_list_elements
)
3129 const gdb_byte
*addr
;
3130 offset_type version
;
3131 offset_type
*metadata
;
3134 if (dwarf2_section_empty_p (section
))
3137 /* Older elfutils strip versions could keep the section in the main
3138 executable while splitting it for the separate debug info file. */
3139 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3142 dwarf2_read_section (objfile
, section
);
3144 addr
= section
->buffer
;
3145 /* Version check. */
3146 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3147 /* Versions earlier than 3 emitted every copy of a psymbol. This
3148 causes the index to behave very poorly for certain requests. Version 3
3149 contained incomplete addrmap. So, it seems better to just ignore such
3153 static int warning_printed
= 0;
3154 if (!warning_printed
)
3156 warning (_("Skipping obsolete .gdb_index section in %s."),
3158 warning_printed
= 1;
3162 /* Index version 4 uses a different hash function than index version
3165 Versions earlier than 6 did not emit psymbols for inlined
3166 functions. Using these files will cause GDB not to be able to
3167 set breakpoints on inlined functions by name, so we ignore these
3168 indices unless the user has done
3169 "set use-deprecated-index-sections on". */
3170 if (version
< 6 && !deprecated_ok
)
3172 static int warning_printed
= 0;
3173 if (!warning_printed
)
3176 Skipping deprecated .gdb_index section in %s.\n\
3177 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3178 to use the section anyway."),
3180 warning_printed
= 1;
3184 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3185 of the TU (for symbols coming from TUs),
3186 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3187 Plus gold-generated indices can have duplicate entries for global symbols,
3188 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3189 These are just performance bugs, and we can't distinguish gdb-generated
3190 indices from gold-generated ones, so issue no warning here. */
3192 /* Indexes with higher version than the one supported by GDB may be no
3193 longer backward compatible. */
3197 map
->version
= version
;
3198 map
->total_size
= section
->size
;
3200 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3203 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3204 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3208 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3209 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3210 - MAYBE_SWAP (metadata
[i
]))
3214 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3215 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
3216 - MAYBE_SWAP (metadata
[i
]));
3219 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
3220 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
3221 - MAYBE_SWAP (metadata
[i
]))
3222 / (2 * sizeof (offset_type
)));
3225 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3231 /* Read the index file. If everything went ok, initialize the "quick"
3232 elements of all the CUs and return 1. Otherwise, return 0. */
3235 dwarf2_read_index (struct objfile
*objfile
)
3237 struct mapped_index local_map
, *map
;
3238 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3239 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3240 struct dwz_file
*dwz
;
3242 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3243 use_deprecated_index_sections
,
3244 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3245 &cu_list
, &cu_list_elements
,
3246 &types_list
, &types_list_elements
))
3249 /* Don't use the index if it's empty. */
3250 if (local_map
.symbol_table_slots
== 0)
3253 /* If there is a .dwz file, read it so we can get its CU list as
3255 dwz
= dwarf2_get_dwz_file ();
3258 struct mapped_index dwz_map
;
3259 const gdb_byte
*dwz_types_ignore
;
3260 offset_type dwz_types_elements_ignore
;
3262 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3264 &dwz
->gdb_index
, &dwz_map
,
3265 &dwz_list
, &dwz_list_elements
,
3267 &dwz_types_elements_ignore
))
3269 warning (_("could not read '.gdb_index' section from %s; skipping"),
3270 bfd_get_filename (dwz
->dwz_bfd
));
3275 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3278 if (types_list_elements
)
3280 struct dwarf2_section_info
*section
;
3282 /* We can only handle a single .debug_types when we have an
3284 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3287 section
= VEC_index (dwarf2_section_info_def
,
3288 dwarf2_per_objfile
->types
, 0);
3290 create_signatured_type_table_from_index (objfile
, section
, types_list
,
3291 types_list_elements
);
3294 create_addrmap_from_index (objfile
, &local_map
);
3296 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3299 dwarf2_per_objfile
->index_table
= map
;
3300 dwarf2_per_objfile
->using_index
= 1;
3301 dwarf2_per_objfile
->quick_file_names_table
=
3302 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3307 /* A helper for the "quick" functions which sets the global
3308 dwarf2_per_objfile according to OBJFILE. */
3311 dw2_setup (struct objfile
*objfile
)
3313 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
3314 objfile_data (objfile
, dwarf2_objfile_data_key
));
3315 gdb_assert (dwarf2_per_objfile
);
3318 /* die_reader_func for dw2_get_file_names. */
3321 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3322 const gdb_byte
*info_ptr
,
3323 struct die_info
*comp_unit_die
,
3327 struct dwarf2_cu
*cu
= reader
->cu
;
3328 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3329 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3330 struct dwarf2_per_cu_data
*lh_cu
;
3331 struct line_header
*lh
;
3332 struct attribute
*attr
;
3334 const char *name
, *comp_dir
;
3336 struct quick_file_names
*qfn
;
3337 unsigned int line_offset
;
3339 gdb_assert (! this_cu
->is_debug_types
);
3341 /* Our callers never want to match partial units -- instead they
3342 will match the enclosing full CU. */
3343 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3345 this_cu
->v
.quick
->no_file_data
= 1;
3354 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3357 struct quick_file_names find_entry
;
3359 line_offset
= DW_UNSND (attr
);
3361 /* We may have already read in this line header (TU line header sharing).
3362 If we have we're done. */
3363 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3364 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
3365 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3366 &find_entry
, INSERT
);
3369 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3373 lh
= dwarf_decode_line_header (line_offset
, cu
);
3377 lh_cu
->v
.quick
->no_file_data
= 1;
3381 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3382 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3383 qfn
->hash
.line_offset
.sect_off
= line_offset
;
3384 gdb_assert (slot
!= NULL
);
3387 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
3389 qfn
->num_file_names
= lh
->num_file_names
;
3391 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->num_file_names
);
3392 for (i
= 0; i
< lh
->num_file_names
; ++i
)
3393 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
3394 qfn
->real_names
= NULL
;
3396 free_line_header (lh
);
3398 lh_cu
->v
.quick
->file_names
= qfn
;
3401 /* A helper for the "quick" functions which attempts to read the line
3402 table for THIS_CU. */
3404 static struct quick_file_names
*
3405 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3407 /* This should never be called for TUs. */
3408 gdb_assert (! this_cu
->is_debug_types
);
3409 /* Nor type unit groups. */
3410 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3412 if (this_cu
->v
.quick
->file_names
!= NULL
)
3413 return this_cu
->v
.quick
->file_names
;
3414 /* If we know there is no line data, no point in looking again. */
3415 if (this_cu
->v
.quick
->no_file_data
)
3418 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3420 if (this_cu
->v
.quick
->no_file_data
)
3422 return this_cu
->v
.quick
->file_names
;
3425 /* A helper for the "quick" functions which computes and caches the
3426 real path for a given file name from the line table. */
3429 dw2_get_real_path (struct objfile
*objfile
,
3430 struct quick_file_names
*qfn
, int index
)
3432 if (qfn
->real_names
== NULL
)
3433 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3434 qfn
->num_file_names
, const char *);
3436 if (qfn
->real_names
[index
] == NULL
)
3437 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
3439 return qfn
->real_names
[index
];
3442 static struct symtab
*
3443 dw2_find_last_source_symtab (struct objfile
*objfile
)
3445 struct compunit_symtab
*cust
;
3448 dw2_setup (objfile
);
3449 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3450 cust
= dw2_instantiate_symtab (dw2_get_cutu (index
));
3453 return compunit_primary_filetab (cust
);
3456 /* Traversal function for dw2_forget_cached_source_info. */
3459 dw2_free_cached_file_names (void **slot
, void *info
)
3461 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3463 if (file_data
->real_names
)
3467 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3469 xfree ((void*) file_data
->real_names
[i
]);
3470 file_data
->real_names
[i
] = NULL
;
3478 dw2_forget_cached_source_info (struct objfile
*objfile
)
3480 dw2_setup (objfile
);
3482 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3483 dw2_free_cached_file_names
, NULL
);
3486 /* Helper function for dw2_map_symtabs_matching_filename that expands
3487 the symtabs and calls the iterator. */
3490 dw2_map_expand_apply (struct objfile
*objfile
,
3491 struct dwarf2_per_cu_data
*per_cu
,
3492 const char *name
, const char *real_path
,
3493 int (*callback
) (struct symtab
*, void *),
3496 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3498 /* Don't visit already-expanded CUs. */
3499 if (per_cu
->v
.quick
->compunit_symtab
)
3502 /* This may expand more than one symtab, and we want to iterate over
3504 dw2_instantiate_symtab (per_cu
);
3506 return iterate_over_some_symtabs (name
, real_path
, callback
, data
,
3507 objfile
->compunit_symtabs
, last_made
);
3510 /* Implementation of the map_symtabs_matching_filename method. */
3513 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
3514 const char *real_path
,
3515 int (*callback
) (struct symtab
*, void *),
3519 const char *name_basename
= lbasename (name
);
3521 dw2_setup (objfile
);
3523 /* The rule is CUs specify all the files, including those used by
3524 any TU, so there's no need to scan TUs here. */
3526 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3529 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3530 struct quick_file_names
*file_data
;
3532 /* We only need to look at symtabs not already expanded. */
3533 if (per_cu
->v
.quick
->compunit_symtab
)
3536 file_data
= dw2_get_file_names (per_cu
);
3537 if (file_data
== NULL
)
3540 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3542 const char *this_name
= file_data
->file_names
[j
];
3543 const char *this_real_name
;
3545 if (compare_filenames_for_search (this_name
, name
))
3547 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3553 /* Before we invoke realpath, which can get expensive when many
3554 files are involved, do a quick comparison of the basenames. */
3555 if (! basenames_may_differ
3556 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3559 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3560 if (compare_filenames_for_search (this_real_name
, name
))
3562 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3568 if (real_path
!= NULL
)
3570 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3571 gdb_assert (IS_ABSOLUTE_PATH (name
));
3572 if (this_real_name
!= NULL
3573 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3575 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3587 /* Struct used to manage iterating over all CUs looking for a symbol. */
3589 struct dw2_symtab_iterator
3591 /* The internalized form of .gdb_index. */
3592 struct mapped_index
*index
;
3593 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3594 int want_specific_block
;
3595 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3596 Unused if !WANT_SPECIFIC_BLOCK. */
3598 /* The kind of symbol we're looking for. */
3600 /* The list of CUs from the index entry of the symbol,
3601 or NULL if not found. */
3603 /* The next element in VEC to look at. */
3605 /* The number of elements in VEC, or zero if there is no match. */
3607 /* Have we seen a global version of the symbol?
3608 If so we can ignore all further global instances.
3609 This is to work around gold/15646, inefficient gold-generated
3614 /* Initialize the index symtab iterator ITER.
3615 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3616 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3619 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3620 struct mapped_index
*index
,
3621 int want_specific_block
,
3626 iter
->index
= index
;
3627 iter
->want_specific_block
= want_specific_block
;
3628 iter
->block_index
= block_index
;
3629 iter
->domain
= domain
;
3631 iter
->global_seen
= 0;
3633 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3634 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3642 /* Return the next matching CU or NULL if there are no more. */
3644 static struct dwarf2_per_cu_data
*
3645 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3647 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3649 offset_type cu_index_and_attrs
=
3650 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3651 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3652 struct dwarf2_per_cu_data
*per_cu
;
3653 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3654 /* This value is only valid for index versions >= 7. */
3655 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3656 gdb_index_symbol_kind symbol_kind
=
3657 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3658 /* Only check the symbol attributes if they're present.
3659 Indices prior to version 7 don't record them,
3660 and indices >= 7 may elide them for certain symbols
3661 (gold does this). */
3663 (iter
->index
->version
>= 7
3664 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3666 /* Don't crash on bad data. */
3667 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3668 + dwarf2_per_objfile
->n_type_units
))
3670 complaint (&symfile_complaints
,
3671 _(".gdb_index entry has bad CU index"
3673 objfile_name (dwarf2_per_objfile
->objfile
));
3677 per_cu
= dw2_get_cutu (cu_index
);
3679 /* Skip if already read in. */
3680 if (per_cu
->v
.quick
->compunit_symtab
)
3683 /* Check static vs global. */
3686 if (iter
->want_specific_block
3687 && want_static
!= is_static
)
3689 /* Work around gold/15646. */
3690 if (!is_static
&& iter
->global_seen
)
3693 iter
->global_seen
= 1;
3696 /* Only check the symbol's kind if it has one. */
3699 switch (iter
->domain
)
3702 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3703 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3704 /* Some types are also in VAR_DOMAIN. */
3705 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3709 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3713 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3728 static struct compunit_symtab
*
3729 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3730 const char *name
, domain_enum domain
)
3732 struct compunit_symtab
*stab_best
= NULL
;
3733 struct mapped_index
*index
;
3735 dw2_setup (objfile
);
3737 index
= dwarf2_per_objfile
->index_table
;
3739 /* index is NULL if OBJF_READNOW. */
3742 struct dw2_symtab_iterator iter
;
3743 struct dwarf2_per_cu_data
*per_cu
;
3745 dw2_symtab_iter_init (&iter
, index
, 1, block_index
, domain
, name
);
3747 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3749 struct symbol
*sym
, *with_opaque
= NULL
;
3750 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
3751 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3752 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3754 sym
= block_find_symbol (block
, name
, domain
,
3755 block_find_non_opaque_type_preferred
,
3758 /* Some caution must be observed with overloaded functions
3759 and methods, since the index will not contain any overload
3760 information (but NAME might contain it). */
3763 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
3765 if (with_opaque
!= NULL
3766 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
3769 /* Keep looking through other CUs. */
3777 dw2_print_stats (struct objfile
*objfile
)
3779 int i
, total
, count
;
3781 dw2_setup (objfile
);
3782 total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
3784 for (i
= 0; i
< total
; ++i
)
3786 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3788 if (!per_cu
->v
.quick
->compunit_symtab
)
3791 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3792 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3795 /* This dumps minimal information about the index.
3796 It is called via "mt print objfiles".
3797 One use is to verify .gdb_index has been loaded by the
3798 gdb.dwarf2/gdb-index.exp testcase. */
3801 dw2_dump (struct objfile
*objfile
)
3803 dw2_setup (objfile
);
3804 gdb_assert (dwarf2_per_objfile
->using_index
);
3805 printf_filtered (".gdb_index:");
3806 if (dwarf2_per_objfile
->index_table
!= NULL
)
3808 printf_filtered (" version %d\n",
3809 dwarf2_per_objfile
->index_table
->version
);
3812 printf_filtered (" faked for \"readnow\"\n");
3813 printf_filtered ("\n");
3817 dw2_relocate (struct objfile
*objfile
,
3818 const struct section_offsets
*new_offsets
,
3819 const struct section_offsets
*delta
)
3821 /* There's nothing to relocate here. */
3825 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3826 const char *func_name
)
3828 struct mapped_index
*index
;
3830 dw2_setup (objfile
);
3832 index
= dwarf2_per_objfile
->index_table
;
3834 /* index is NULL if OBJF_READNOW. */
3837 struct dw2_symtab_iterator iter
;
3838 struct dwarf2_per_cu_data
*per_cu
;
3840 /* Note: It doesn't matter what we pass for block_index here. */
3841 dw2_symtab_iter_init (&iter
, index
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
3844 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3845 dw2_instantiate_symtab (per_cu
);
3850 dw2_expand_all_symtabs (struct objfile
*objfile
)
3854 dw2_setup (objfile
);
3856 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3857 + dwarf2_per_objfile
->n_type_units
); ++i
)
3859 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3861 dw2_instantiate_symtab (per_cu
);
3866 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3867 const char *fullname
)
3871 dw2_setup (objfile
);
3873 /* We don't need to consider type units here.
3874 This is only called for examining code, e.g. expand_line_sal.
3875 There can be an order of magnitude (or more) more type units
3876 than comp units, and we avoid them if we can. */
3878 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3881 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3882 struct quick_file_names
*file_data
;
3884 /* We only need to look at symtabs not already expanded. */
3885 if (per_cu
->v
.quick
->compunit_symtab
)
3888 file_data
= dw2_get_file_names (per_cu
);
3889 if (file_data
== NULL
)
3892 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3894 const char *this_fullname
= file_data
->file_names
[j
];
3896 if (filename_cmp (this_fullname
, fullname
) == 0)
3898 dw2_instantiate_symtab (per_cu
);
3906 dw2_map_matching_symbols (struct objfile
*objfile
,
3907 const char * name
, domain_enum domain
,
3909 int (*callback
) (struct block
*,
3910 struct symbol
*, void *),
3911 void *data
, symbol_compare_ftype
*match
,
3912 symbol_compare_ftype
*ordered_compare
)
3914 /* Currently unimplemented; used for Ada. The function can be called if the
3915 current language is Ada for a non-Ada objfile using GNU index. As Ada
3916 does not look for non-Ada symbols this function should just return. */
3920 dw2_expand_symtabs_matching
3921 (struct objfile
*objfile
,
3922 expand_symtabs_file_matcher_ftype
*file_matcher
,
3923 expand_symtabs_symbol_matcher_ftype
*symbol_matcher
,
3924 expand_symtabs_exp_notify_ftype
*expansion_notify
,
3925 enum search_domain kind
,
3930 struct mapped_index
*index
;
3932 dw2_setup (objfile
);
3934 /* index_table is NULL if OBJF_READNOW. */
3935 if (!dwarf2_per_objfile
->index_table
)
3937 index
= dwarf2_per_objfile
->index_table
;
3939 if (file_matcher
!= NULL
)
3941 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
3943 NULL
, xcalloc
, xfree
));
3944 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
3946 NULL
, xcalloc
, xfree
));
3948 /* The rule is CUs specify all the files, including those used by
3949 any TU, so there's no need to scan TUs here. */
3951 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3954 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3955 struct quick_file_names
*file_data
;
3960 per_cu
->v
.quick
->mark
= 0;
3962 /* We only need to look at symtabs not already expanded. */
3963 if (per_cu
->v
.quick
->compunit_symtab
)
3966 file_data
= dw2_get_file_names (per_cu
);
3967 if (file_data
== NULL
)
3970 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
3972 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
3974 per_cu
->v
.quick
->mark
= 1;
3978 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3980 const char *this_real_name
;
3982 if (file_matcher (file_data
->file_names
[j
], data
, 0))
3984 per_cu
->v
.quick
->mark
= 1;
3988 /* Before we invoke realpath, which can get expensive when many
3989 files are involved, do a quick comparison of the basenames. */
3990 if (!basenames_may_differ
3991 && !file_matcher (lbasename (file_data
->file_names
[j
]),
3995 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3996 if (file_matcher (this_real_name
, data
, 0))
3998 per_cu
->v
.quick
->mark
= 1;
4003 slot
= htab_find_slot (per_cu
->v
.quick
->mark
4004 ? visited_found
.get ()
4005 : visited_not_found
.get (),
4011 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
4013 offset_type idx
= 2 * iter
;
4015 offset_type
*vec
, vec_len
, vec_idx
;
4016 int global_seen
= 0;
4020 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
4023 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
4025 if (! (*symbol_matcher
) (name
, data
))
4028 /* The name was matched, now expand corresponding CUs that were
4030 vec
= (offset_type
*) (index
->constant_pool
4031 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
4032 vec_len
= MAYBE_SWAP (vec
[0]);
4033 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4035 struct dwarf2_per_cu_data
*per_cu
;
4036 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4037 /* This value is only valid for index versions >= 7. */
4038 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4039 gdb_index_symbol_kind symbol_kind
=
4040 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4041 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4042 /* Only check the symbol attributes if they're present.
4043 Indices prior to version 7 don't record them,
4044 and indices >= 7 may elide them for certain symbols
4045 (gold does this). */
4047 (index
->version
>= 7
4048 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4050 /* Work around gold/15646. */
4053 if (!is_static
&& global_seen
)
4059 /* Only check the symbol's kind if it has one. */
4064 case VARIABLES_DOMAIN
:
4065 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4068 case FUNCTIONS_DOMAIN
:
4069 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4073 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4081 /* Don't crash on bad data. */
4082 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
4083 + dwarf2_per_objfile
->n_type_units
))
4085 complaint (&symfile_complaints
,
4086 _(".gdb_index entry has bad CU index"
4087 " [in module %s]"), objfile_name (objfile
));
4091 per_cu
= dw2_get_cutu (cu_index
);
4092 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4094 int symtab_was_null
=
4095 (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4097 dw2_instantiate_symtab (per_cu
);
4099 if (expansion_notify
!= NULL
4101 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4103 expansion_notify (per_cu
->v
.quick
->compunit_symtab
,
4111 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4114 static struct compunit_symtab
*
4115 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4120 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4121 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4124 if (cust
->includes
== NULL
)
4127 for (i
= 0; cust
->includes
[i
]; ++i
)
4129 struct compunit_symtab
*s
= cust
->includes
[i
];
4131 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4139 static struct compunit_symtab
*
4140 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4141 struct bound_minimal_symbol msymbol
,
4143 struct obj_section
*section
,
4146 struct dwarf2_per_cu_data
*data
;
4147 struct compunit_symtab
*result
;
4149 dw2_setup (objfile
);
4151 if (!objfile
->psymtabs_addrmap
)
4154 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
4159 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4160 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4161 paddress (get_objfile_arch (objfile
), pc
));
4164 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
4166 gdb_assert (result
!= NULL
);
4171 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4172 void *data
, int need_fullname
)
4175 htab_up
visited (htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
4176 NULL
, xcalloc
, xfree
));
4178 dw2_setup (objfile
);
4180 /* The rule is CUs specify all the files, including those used by
4181 any TU, so there's no need to scan TUs here.
4182 We can ignore file names coming from already-expanded CUs. */
4184 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4186 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4188 if (per_cu
->v
.quick
->compunit_symtab
)
4190 void **slot
= htab_find_slot (visited
.get (),
4191 per_cu
->v
.quick
->file_names
,
4194 *slot
= per_cu
->v
.quick
->file_names
;
4198 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4201 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4202 struct quick_file_names
*file_data
;
4205 /* We only need to look at symtabs not already expanded. */
4206 if (per_cu
->v
.quick
->compunit_symtab
)
4209 file_data
= dw2_get_file_names (per_cu
);
4210 if (file_data
== NULL
)
4213 slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4216 /* Already visited. */
4221 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4223 const char *this_real_name
;
4226 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4228 this_real_name
= NULL
;
4229 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
4235 dw2_has_symbols (struct objfile
*objfile
)
4240 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4243 dw2_find_last_source_symtab
,
4244 dw2_forget_cached_source_info
,
4245 dw2_map_symtabs_matching_filename
,
4250 dw2_expand_symtabs_for_function
,
4251 dw2_expand_all_symtabs
,
4252 dw2_expand_symtabs_with_fullname
,
4253 dw2_map_matching_symbols
,
4254 dw2_expand_symtabs_matching
,
4255 dw2_find_pc_sect_compunit_symtab
,
4256 dw2_map_symbol_filenames
4259 /* Initialize for reading DWARF for this objfile. Return 0 if this
4260 file will use psymtabs, or 1 if using the GNU index. */
4263 dwarf2_initialize_objfile (struct objfile
*objfile
)
4265 /* If we're about to read full symbols, don't bother with the
4266 indices. In this case we also don't care if some other debug
4267 format is making psymtabs, because they are all about to be
4269 if ((objfile
->flags
& OBJF_READNOW
))
4273 dwarf2_per_objfile
->using_index
= 1;
4274 create_all_comp_units (objfile
);
4275 create_all_type_units (objfile
);
4276 dwarf2_per_objfile
->quick_file_names_table
=
4277 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
4279 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
4280 + dwarf2_per_objfile
->n_type_units
); ++i
)
4282 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4284 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4285 struct dwarf2_per_cu_quick_data
);
4288 /* Return 1 so that gdb sees the "quick" functions. However,
4289 these functions will be no-ops because we will have expanded
4294 if (dwarf2_read_index (objfile
))
4302 /* Build a partial symbol table. */
4305 dwarf2_build_psymtabs (struct objfile
*objfile
)
4308 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
4310 init_psymbol_list (objfile
, 1024);
4315 /* This isn't really ideal: all the data we allocate on the
4316 objfile's obstack is still uselessly kept around. However,
4317 freeing it seems unsafe. */
4318 psymtab_discarder
psymtabs (objfile
);
4319 dwarf2_build_psymtabs_hard (objfile
);
4322 CATCH (except
, RETURN_MASK_ERROR
)
4324 exception_print (gdb_stderr
, except
);
4329 /* Return the total length of the CU described by HEADER. */
4332 get_cu_length (const struct comp_unit_head
*header
)
4334 return header
->initial_length_size
+ header
->length
;
4337 /* Return TRUE if OFFSET is within CU_HEADER. */
4340 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
4342 sect_offset bottom
= { cu_header
->offset
.sect_off
};
4343 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
4345 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
4348 /* Find the base address of the compilation unit for range lists and
4349 location lists. It will normally be specified by DW_AT_low_pc.
4350 In DWARF-3 draft 4, the base address could be overridden by
4351 DW_AT_entry_pc. It's been removed, but GCC still uses this for
4352 compilation units with discontinuous ranges. */
4355 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
4357 struct attribute
*attr
;
4360 cu
->base_address
= 0;
4362 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
4365 cu
->base_address
= attr_value_as_address (attr
);
4370 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4373 cu
->base_address
= attr_value_as_address (attr
);
4379 /* Read in the comp unit header information from the debug_info at info_ptr.
4380 Use rcuh_kind::COMPILE as the default type if not known by the caller.
4381 NOTE: This leaves members offset, first_die_offset to be filled in
4384 static const gdb_byte
*
4385 read_comp_unit_head (struct comp_unit_head
*cu_header
,
4386 const gdb_byte
*info_ptr
,
4387 struct dwarf2_section_info
*section
,
4388 rcuh_kind section_kind
)
4391 unsigned int bytes_read
;
4392 const char *filename
= get_section_file_name (section
);
4393 bfd
*abfd
= get_section_bfd_owner (section
);
4395 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
4396 cu_header
->initial_length_size
= bytes_read
;
4397 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
4398 info_ptr
+= bytes_read
;
4399 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
4401 if (cu_header
->version
< 5)
4402 switch (section_kind
)
4404 case rcuh_kind::COMPILE
:
4405 cu_header
->unit_type
= DW_UT_compile
;
4407 case rcuh_kind::TYPE
:
4408 cu_header
->unit_type
= DW_UT_type
;
4411 internal_error (__FILE__
, __LINE__
,
4412 _("read_comp_unit_head: invalid section_kind"));
4416 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
4417 (read_1_byte (abfd
, info_ptr
));
4419 switch (cu_header
->unit_type
)
4422 if (section_kind
!= rcuh_kind::COMPILE
)
4423 error (_("Dwarf Error: wrong unit_type in compilation unit header "
4424 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
4428 section_kind
= rcuh_kind::TYPE
;
4431 error (_("Dwarf Error: wrong unit_type in compilation unit header "
4432 "(is %d, should be %d or %d) [in module %s]"),
4433 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
4436 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
4439 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
4441 info_ptr
+= bytes_read
;
4442 if (cu_header
->version
< 5)
4444 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
4447 signed_addr
= bfd_get_sign_extend_vma (abfd
);
4448 if (signed_addr
< 0)
4449 internal_error (__FILE__
, __LINE__
,
4450 _("read_comp_unit_head: dwarf from non elf file"));
4451 cu_header
->signed_addr_p
= signed_addr
;
4453 if (section_kind
== rcuh_kind::TYPE
)
4455 LONGEST type_offset
;
4457 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
4460 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
4461 info_ptr
+= bytes_read
;
4462 cu_header
->type_offset_in_tu
.cu_off
= type_offset
;
4463 if (cu_header
->type_offset_in_tu
.cu_off
!= type_offset
)
4464 error (_("Dwarf Error: Too big type_offset in compilation unit "
4465 "header (is %s) [in module %s]"), plongest (type_offset
),
4472 /* Helper function that returns the proper abbrev section for
4475 static struct dwarf2_section_info
*
4476 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
4478 struct dwarf2_section_info
*abbrev
;
4480 if (this_cu
->is_dwz
)
4481 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
4483 abbrev
= &dwarf2_per_objfile
->abbrev
;
4488 /* Subroutine of read_and_check_comp_unit_head and
4489 read_and_check_type_unit_head to simplify them.
4490 Perform various error checking on the header. */
4493 error_check_comp_unit_head (struct comp_unit_head
*header
,
4494 struct dwarf2_section_info
*section
,
4495 struct dwarf2_section_info
*abbrev_section
)
4497 const char *filename
= get_section_file_name (section
);
4499 if (header
->version
< 2 || header
->version
> 5)
4500 error (_("Dwarf Error: wrong version in compilation unit header "
4501 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
4504 if (header
->abbrev_offset
.sect_off
4505 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
4506 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
4507 "(offset 0x%lx + 6) [in module %s]"),
4508 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
4511 /* Cast to unsigned long to use 64-bit arithmetic when possible to
4512 avoid potential 32-bit overflow. */
4513 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
4515 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
4516 "(offset 0x%lx + 0) [in module %s]"),
4517 (long) header
->length
, (long) header
->offset
.sect_off
,
4521 /* Read in a CU/TU header and perform some basic error checking.
4522 The contents of the header are stored in HEADER.
4523 The result is a pointer to the start of the first DIE. */
4525 static const gdb_byte
*
4526 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
4527 struct dwarf2_section_info
*section
,
4528 struct dwarf2_section_info
*abbrev_section
,
4529 const gdb_byte
*info_ptr
,
4530 rcuh_kind section_kind
)
4532 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
4533 bfd
*abfd
= get_section_bfd_owner (section
);
4535 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4537 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
4539 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4541 error_check_comp_unit_head (header
, section
, abbrev_section
);
4546 /* Fetch the abbreviation table offset from a comp or type unit header. */
4549 read_abbrev_offset (struct dwarf2_section_info
*section
,
4552 bfd
*abfd
= get_section_bfd_owner (section
);
4553 const gdb_byte
*info_ptr
;
4554 unsigned int initial_length_size
, offset_size
;
4555 sect_offset abbrev_offset
;
4558 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
4559 info_ptr
= section
->buffer
+ offset
.sect_off
;
4560 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
4561 offset_size
= initial_length_size
== 4 ? 4 : 8;
4562 info_ptr
+= initial_length_size
;
4564 version
= read_2_bytes (abfd
, info_ptr
);
4568 /* Skip unit type and address size. */
4572 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
4573 return abbrev_offset
;
4576 /* Allocate a new partial symtab for file named NAME and mark this new
4577 partial symtab as being an include of PST. */
4580 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
4581 struct objfile
*objfile
)
4583 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
4585 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
4587 /* It shares objfile->objfile_obstack. */
4588 subpst
->dirname
= pst
->dirname
;
4591 subpst
->textlow
= 0;
4592 subpst
->texthigh
= 0;
4594 subpst
->dependencies
4595 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
4596 subpst
->dependencies
[0] = pst
;
4597 subpst
->number_of_dependencies
= 1;
4599 subpst
->globals_offset
= 0;
4600 subpst
->n_global_syms
= 0;
4601 subpst
->statics_offset
= 0;
4602 subpst
->n_static_syms
= 0;
4603 subpst
->compunit_symtab
= NULL
;
4604 subpst
->read_symtab
= pst
->read_symtab
;
4607 /* No private part is necessary for include psymtabs. This property
4608 can be used to differentiate between such include psymtabs and
4609 the regular ones. */
4610 subpst
->read_symtab_private
= NULL
;
4613 /* Read the Line Number Program data and extract the list of files
4614 included by the source file represented by PST. Build an include
4615 partial symtab for each of these included files. */
4618 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4619 struct die_info
*die
,
4620 struct partial_symtab
*pst
)
4622 struct line_header
*lh
= NULL
;
4623 struct attribute
*attr
;
4625 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4627 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
4629 return; /* No linetable, so no includes. */
4631 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4632 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
4634 free_line_header (lh
);
4638 hash_signatured_type (const void *item
)
4640 const struct signatured_type
*sig_type
4641 = (const struct signatured_type
*) item
;
4643 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4644 return sig_type
->signature
;
4648 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4650 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
4651 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
4653 return lhs
->signature
== rhs
->signature
;
4656 /* Allocate a hash table for signatured types. */
4659 allocate_signatured_type_table (struct objfile
*objfile
)
4661 return htab_create_alloc_ex (41,
4662 hash_signatured_type
,
4665 &objfile
->objfile_obstack
,
4666 hashtab_obstack_allocate
,
4667 dummy_obstack_deallocate
);
4670 /* A helper function to add a signatured type CU to a table. */
4673 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4675 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
4676 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
4684 /* A helper for create_debug_types_hash_table. Read types from SECTION
4685 and fill them into TYPES_HTAB. It will process only type units,
4686 therefore DW_UT_type. */
4689 create_debug_type_hash_table (struct dwo_file
*dwo_file
,
4690 dwarf2_section_info
*section
, htab_t
&types_htab
,
4691 rcuh_kind section_kind
)
4693 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4694 struct dwarf2_section_info
*abbrev_section
;
4696 const gdb_byte
*info_ptr
, *end_ptr
;
4698 abbrev_section
= (dwo_file
!= NULL
4699 ? &dwo_file
->sections
.abbrev
4700 : &dwarf2_per_objfile
->abbrev
);
4702 if (dwarf_read_debug
)
4703 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
4704 get_section_name (section
),
4705 get_section_file_name (abbrev_section
));
4707 dwarf2_read_section (objfile
, section
);
4708 info_ptr
= section
->buffer
;
4710 if (info_ptr
== NULL
)
4713 /* We can't set abfd until now because the section may be empty or
4714 not present, in which case the bfd is unknown. */
4715 abfd
= get_section_bfd_owner (section
);
4717 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4718 because we don't need to read any dies: the signature is in the
4721 end_ptr
= info_ptr
+ section
->size
;
4722 while (info_ptr
< end_ptr
)
4725 struct signatured_type
*sig_type
;
4726 struct dwo_unit
*dwo_tu
;
4728 const gdb_byte
*ptr
= info_ptr
;
4729 struct comp_unit_head header
;
4730 unsigned int length
;
4732 offset
.sect_off
= ptr
- section
->buffer
;
4734 /* We need to read the type's signature in order to build the hash
4735 table, but we don't need anything else just yet. */
4737 ptr
= read_and_check_comp_unit_head (&header
, section
,
4738 abbrev_section
, ptr
, section_kind
);
4740 length
= get_cu_length (&header
);
4742 /* Skip dummy type units. */
4743 if (ptr
>= info_ptr
+ length
4744 || peek_abbrev_code (abfd
, ptr
) == 0
4745 || header
.unit_type
!= DW_UT_type
)
4751 if (types_htab
== NULL
)
4754 types_htab
= allocate_dwo_unit_table (objfile
);
4756 types_htab
= allocate_signatured_type_table (objfile
);
4762 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4764 dwo_tu
->dwo_file
= dwo_file
;
4765 dwo_tu
->signature
= header
.signature
;
4766 dwo_tu
->type_offset_in_tu
= header
.type_offset_in_tu
;
4767 dwo_tu
->section
= section
;
4768 dwo_tu
->offset
= offset
;
4769 dwo_tu
->length
= length
;
4773 /* N.B.: type_offset is not usable if this type uses a DWO file.
4774 The real type_offset is in the DWO file. */
4776 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4777 struct signatured_type
);
4778 sig_type
->signature
= header
.signature
;
4779 sig_type
->type_offset_in_tu
= header
.type_offset_in_tu
;
4780 sig_type
->per_cu
.objfile
= objfile
;
4781 sig_type
->per_cu
.is_debug_types
= 1;
4782 sig_type
->per_cu
.section
= section
;
4783 sig_type
->per_cu
.offset
= offset
;
4784 sig_type
->per_cu
.length
= length
;
4787 slot
= htab_find_slot (types_htab
,
4788 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4790 gdb_assert (slot
!= NULL
);
4793 sect_offset dup_offset
;
4797 const struct dwo_unit
*dup_tu
4798 = (const struct dwo_unit
*) *slot
;
4800 dup_offset
= dup_tu
->offset
;
4804 const struct signatured_type
*dup_tu
4805 = (const struct signatured_type
*) *slot
;
4807 dup_offset
= dup_tu
->per_cu
.offset
;
4810 complaint (&symfile_complaints
,
4811 _("debug type entry at offset 0x%x is duplicate to"
4812 " the entry at offset 0x%x, signature %s"),
4813 offset
.sect_off
, dup_offset
.sect_off
,
4814 hex_string (header
.signature
));
4816 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4818 if (dwarf_read_debug
> 1)
4819 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature %s\n",
4821 hex_string (header
.signature
));
4827 /* Create the hash table of all entries in the .debug_types
4828 (or .debug_types.dwo) section(s).
4829 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
4830 otherwise it is NULL.
4832 The result is a pointer to the hash table or NULL if there are no types.
4834 Note: This function processes DWO files only, not DWP files. */
4837 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4838 VEC (dwarf2_section_info_def
) *types
,
4842 struct dwarf2_section_info
*section
;
4844 if (VEC_empty (dwarf2_section_info_def
, types
))
4848 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4850 create_debug_type_hash_table (dwo_file
, section
, types_htab
,
4854 /* Create the hash table of all entries in the .debug_types section,
4855 and initialize all_type_units.
4856 The result is zero if there is an error (e.g. missing .debug_types section),
4857 otherwise non-zero. */
4860 create_all_type_units (struct objfile
*objfile
)
4862 htab_t types_htab
= NULL
;
4863 struct signatured_type
**iter
;
4865 create_debug_type_hash_table (NULL
, &dwarf2_per_objfile
->info
, types_htab
,
4866 rcuh_kind::COMPILE
);
4867 create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
, types_htab
);
4868 if (types_htab
== NULL
)
4870 dwarf2_per_objfile
->signatured_types
= NULL
;
4874 dwarf2_per_objfile
->signatured_types
= types_htab
;
4876 dwarf2_per_objfile
->n_type_units
4877 = dwarf2_per_objfile
->n_allocated_type_units
4878 = htab_elements (types_htab
);
4879 dwarf2_per_objfile
->all_type_units
=
4880 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
4881 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4882 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4883 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4884 == dwarf2_per_objfile
->n_type_units
);
4889 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
4890 If SLOT is non-NULL, it is the entry to use in the hash table.
4891 Otherwise we find one. */
4893 static struct signatured_type
*
4894 add_type_unit (ULONGEST sig
, void **slot
)
4896 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4897 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
4898 struct signatured_type
*sig_type
;
4900 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
4902 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
4904 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
4905 dwarf2_per_objfile
->n_allocated_type_units
= 1;
4906 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
4907 dwarf2_per_objfile
->all_type_units
4908 = XRESIZEVEC (struct signatured_type
*,
4909 dwarf2_per_objfile
->all_type_units
,
4910 dwarf2_per_objfile
->n_allocated_type_units
);
4911 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
4913 dwarf2_per_objfile
->n_type_units
= n_type_units
;
4915 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4916 struct signatured_type
);
4917 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
4918 sig_type
->signature
= sig
;
4919 sig_type
->per_cu
.is_debug_types
= 1;
4920 if (dwarf2_per_objfile
->using_index
)
4922 sig_type
->per_cu
.v
.quick
=
4923 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4924 struct dwarf2_per_cu_quick_data
);
4929 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
4932 gdb_assert (*slot
== NULL
);
4934 /* The rest of sig_type must be filled in by the caller. */
4938 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
4939 Fill in SIG_ENTRY with DWO_ENTRY. */
4942 fill_in_sig_entry_from_dwo_entry (struct objfile
*objfile
,
4943 struct signatured_type
*sig_entry
,
4944 struct dwo_unit
*dwo_entry
)
4946 /* Make sure we're not clobbering something we don't expect to. */
4947 gdb_assert (! sig_entry
->per_cu
.queued
);
4948 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
4949 if (dwarf2_per_objfile
->using_index
)
4951 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
4952 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
4955 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
4956 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
4957 gdb_assert (sig_entry
->type_offset_in_section
.sect_off
== 0);
4958 gdb_assert (sig_entry
->type_unit_group
== NULL
);
4959 gdb_assert (sig_entry
->dwo_unit
== NULL
);
4961 sig_entry
->per_cu
.section
= dwo_entry
->section
;
4962 sig_entry
->per_cu
.offset
= dwo_entry
->offset
;
4963 sig_entry
->per_cu
.length
= dwo_entry
->length
;
4964 sig_entry
->per_cu
.reading_dwo_directly
= 1;
4965 sig_entry
->per_cu
.objfile
= objfile
;
4966 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
4967 sig_entry
->dwo_unit
= dwo_entry
;
4970 /* Subroutine of lookup_signatured_type.
4971 If we haven't read the TU yet, create the signatured_type data structure
4972 for a TU to be read in directly from a DWO file, bypassing the stub.
4973 This is the "Stay in DWO Optimization": When there is no DWP file and we're
4974 using .gdb_index, then when reading a CU we want to stay in the DWO file
4975 containing that CU. Otherwise we could end up reading several other DWO
4976 files (due to comdat folding) to process the transitive closure of all the
4977 mentioned TUs, and that can be slow. The current DWO file will have every
4978 type signature that it needs.
4979 We only do this for .gdb_index because in the psymtab case we already have
4980 to read all the DWOs to build the type unit groups. */
4982 static struct signatured_type
*
4983 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
4985 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4986 struct dwo_file
*dwo_file
;
4987 struct dwo_unit find_dwo_entry
, *dwo_entry
;
4988 struct signatured_type find_sig_entry
, *sig_entry
;
4991 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
4993 /* If TU skeletons have been removed then we may not have read in any
4995 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4997 dwarf2_per_objfile
->signatured_types
4998 = allocate_signatured_type_table (objfile
);
5001 /* We only ever need to read in one copy of a signatured type.
5002 Use the global signatured_types array to do our own comdat-folding
5003 of types. If this is the first time we're reading this TU, and
5004 the TU has an entry in .gdb_index, replace the recorded data from
5005 .gdb_index with this TU. */
5007 find_sig_entry
.signature
= sig
;
5008 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5009 &find_sig_entry
, INSERT
);
5010 sig_entry
= (struct signatured_type
*) *slot
;
5012 /* We can get here with the TU already read, *or* in the process of being
5013 read. Don't reassign the global entry to point to this DWO if that's
5014 the case. Also note that if the TU is already being read, it may not
5015 have come from a DWO, the program may be a mix of Fission-compiled
5016 code and non-Fission-compiled code. */
5018 /* Have we already tried to read this TU?
5019 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5020 needn't exist in the global table yet). */
5021 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
5024 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
5025 dwo_unit of the TU itself. */
5026 dwo_file
= cu
->dwo_unit
->dwo_file
;
5028 /* Ok, this is the first time we're reading this TU. */
5029 if (dwo_file
->tus
== NULL
)
5031 find_dwo_entry
.signature
= sig
;
5032 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
5033 if (dwo_entry
== NULL
)
5036 /* If the global table doesn't have an entry for this TU, add one. */
5037 if (sig_entry
== NULL
)
5038 sig_entry
= add_type_unit (sig
, slot
);
5040 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
5041 sig_entry
->per_cu
.tu_read
= 1;
5045 /* Subroutine of lookup_signatured_type.
5046 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
5047 then try the DWP file. If the TU stub (skeleton) has been removed then
5048 it won't be in .gdb_index. */
5050 static struct signatured_type
*
5051 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5053 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5054 struct dwp_file
*dwp_file
= get_dwp_file ();
5055 struct dwo_unit
*dwo_entry
;
5056 struct signatured_type find_sig_entry
, *sig_entry
;
5059 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
5060 gdb_assert (dwp_file
!= NULL
);
5062 /* If TU skeletons have been removed then we may not have read in any
5064 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5066 dwarf2_per_objfile
->signatured_types
5067 = allocate_signatured_type_table (objfile
);
5070 find_sig_entry
.signature
= sig
;
5071 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5072 &find_sig_entry
, INSERT
);
5073 sig_entry
= (struct signatured_type
*) *slot
;
5075 /* Have we already tried to read this TU?
5076 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5077 needn't exist in the global table yet). */
5078 if (sig_entry
!= NULL
)
5081 if (dwp_file
->tus
== NULL
)
5083 dwo_entry
= lookup_dwo_unit_in_dwp (dwp_file
, NULL
,
5084 sig
, 1 /* is_debug_types */);
5085 if (dwo_entry
== NULL
)
5088 sig_entry
= add_type_unit (sig
, slot
);
5089 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
5094 /* Lookup a signature based type for DW_FORM_ref_sig8.
5095 Returns NULL if signature SIG is not present in the table.
5096 It is up to the caller to complain about this. */
5098 static struct signatured_type
*
5099 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5102 && dwarf2_per_objfile
->using_index
)
5104 /* We're in a DWO/DWP file, and we're using .gdb_index.
5105 These cases require special processing. */
5106 if (get_dwp_file () == NULL
)
5107 return lookup_dwo_signatured_type (cu
, sig
);
5109 return lookup_dwp_signatured_type (cu
, sig
);
5113 struct signatured_type find_entry
, *entry
;
5115 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5117 find_entry
.signature
= sig
;
5118 entry
= ((struct signatured_type
*)
5119 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
5124 /* Low level DIE reading support. */
5126 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
5129 init_cu_die_reader (struct die_reader_specs
*reader
,
5130 struct dwarf2_cu
*cu
,
5131 struct dwarf2_section_info
*section
,
5132 struct dwo_file
*dwo_file
)
5134 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
5135 reader
->abfd
= get_section_bfd_owner (section
);
5137 reader
->dwo_file
= dwo_file
;
5138 reader
->die_section
= section
;
5139 reader
->buffer
= section
->buffer
;
5140 reader
->buffer_end
= section
->buffer
+ section
->size
;
5141 reader
->comp_dir
= NULL
;
5144 /* Subroutine of init_cutu_and_read_dies to simplify it.
5145 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
5146 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
5149 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
5150 from it to the DIE in the DWO. If NULL we are skipping the stub.
5151 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
5152 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
5153 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
5154 STUB_COMP_DIR may be non-NULL.
5155 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
5156 are filled in with the info of the DIE from the DWO file.
5157 ABBREV_TABLE_PROVIDED is non-zero if the caller of init_cutu_and_read_dies
5158 provided an abbrev table to use.
5159 The result is non-zero if a valid (non-dummy) DIE was found. */
5162 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
5163 struct dwo_unit
*dwo_unit
,
5164 int abbrev_table_provided
,
5165 struct die_info
*stub_comp_unit_die
,
5166 const char *stub_comp_dir
,
5167 struct die_reader_specs
*result_reader
,
5168 const gdb_byte
**result_info_ptr
,
5169 struct die_info
**result_comp_unit_die
,
5170 int *result_has_children
)
5172 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5173 struct dwarf2_cu
*cu
= this_cu
->cu
;
5174 struct dwarf2_section_info
*section
;
5176 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5177 ULONGEST signature
; /* Or dwo_id. */
5178 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
5179 int i
,num_extra_attrs
;
5180 struct dwarf2_section_info
*dwo_abbrev_section
;
5181 struct attribute
*attr
;
5182 struct die_info
*comp_unit_die
;
5184 /* At most one of these may be provided. */
5185 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
5187 /* These attributes aren't processed until later:
5188 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
5189 DW_AT_comp_dir is used now, to find the DWO file, but it is also
5190 referenced later. However, these attributes are found in the stub
5191 which we won't have later. In order to not impose this complication
5192 on the rest of the code, we read them here and copy them to the
5201 if (stub_comp_unit_die
!= NULL
)
5203 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
5205 if (! this_cu
->is_debug_types
)
5206 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
5207 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
5208 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
5209 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
5210 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
5212 /* There should be a DW_AT_addr_base attribute here (if needed).
5213 We need the value before we can process DW_FORM_GNU_addr_index. */
5215 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
5217 cu
->addr_base
= DW_UNSND (attr
);
5219 /* There should be a DW_AT_ranges_base attribute here (if needed).
5220 We need the value before we can process DW_AT_ranges. */
5221 cu
->ranges_base
= 0;
5222 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
5224 cu
->ranges_base
= DW_UNSND (attr
);
5226 else if (stub_comp_dir
!= NULL
)
5228 /* Reconstruct the comp_dir attribute to simplify the code below. */
5229 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
5230 comp_dir
->name
= DW_AT_comp_dir
;
5231 comp_dir
->form
= DW_FORM_string
;
5232 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
5233 DW_STRING (comp_dir
) = stub_comp_dir
;
5236 /* Set up for reading the DWO CU/TU. */
5237 cu
->dwo_unit
= dwo_unit
;
5238 section
= dwo_unit
->section
;
5239 dwarf2_read_section (objfile
, section
);
5240 abfd
= get_section_bfd_owner (section
);
5241 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
5242 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
5243 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
);
5245 if (this_cu
->is_debug_types
)
5247 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
5249 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5251 info_ptr
, rcuh_kind::TYPE
);
5252 /* This is not an assert because it can be caused by bad debug info. */
5253 if (sig_type
->signature
!= cu
->header
.signature
)
5255 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
5256 " TU at offset 0x%x [in module %s]"),
5257 hex_string (sig_type
->signature
),
5258 hex_string (cu
->header
.signature
),
5259 dwo_unit
->offset
.sect_off
,
5260 bfd_get_filename (abfd
));
5262 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5263 /* For DWOs coming from DWP files, we don't know the CU length
5264 nor the type's offset in the TU until now. */
5265 dwo_unit
->length
= get_cu_length (&cu
->header
);
5266 dwo_unit
->type_offset_in_tu
= cu
->header
.type_offset_in_tu
;
5268 /* Establish the type offset that can be used to lookup the type.
5269 For DWO files, we don't know it until now. */
5270 sig_type
->type_offset_in_section
.sect_off
=
5271 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
5275 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5277 info_ptr
, rcuh_kind::COMPILE
);
5278 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5279 /* For DWOs coming from DWP files, we don't know the CU length
5281 dwo_unit
->length
= get_cu_length (&cu
->header
);
5284 /* Replace the CU's original abbrev table with the DWO's.
5285 Reminder: We can't read the abbrev table until we've read the header. */
5286 if (abbrev_table_provided
)
5288 /* Don't free the provided abbrev table, the caller of
5289 init_cutu_and_read_dies owns it. */
5290 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5291 /* Ensure the DWO abbrev table gets freed. */
5292 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5296 dwarf2_free_abbrev_table (cu
);
5297 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5298 /* Leave any existing abbrev table cleanup as is. */
5301 /* Read in the die, but leave space to copy over the attributes
5302 from the stub. This has the benefit of simplifying the rest of
5303 the code - all the work to maintain the illusion of a single
5304 DW_TAG_{compile,type}_unit DIE is done here. */
5305 num_extra_attrs
= ((stmt_list
!= NULL
)
5309 + (comp_dir
!= NULL
));
5310 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
5311 result_has_children
, num_extra_attrs
);
5313 /* Copy over the attributes from the stub to the DIE we just read in. */
5314 comp_unit_die
= *result_comp_unit_die
;
5315 i
= comp_unit_die
->num_attrs
;
5316 if (stmt_list
!= NULL
)
5317 comp_unit_die
->attrs
[i
++] = *stmt_list
;
5319 comp_unit_die
->attrs
[i
++] = *low_pc
;
5320 if (high_pc
!= NULL
)
5321 comp_unit_die
->attrs
[i
++] = *high_pc
;
5323 comp_unit_die
->attrs
[i
++] = *ranges
;
5324 if (comp_dir
!= NULL
)
5325 comp_unit_die
->attrs
[i
++] = *comp_dir
;
5326 comp_unit_die
->num_attrs
+= num_extra_attrs
;
5328 if (dwarf_die_debug
)
5330 fprintf_unfiltered (gdb_stdlog
,
5331 "Read die from %s@0x%x of %s:\n",
5332 get_section_name (section
),
5333 (unsigned) (begin_info_ptr
- section
->buffer
),
5334 bfd_get_filename (abfd
));
5335 dump_die (comp_unit_die
, dwarf_die_debug
);
5338 /* Save the comp_dir attribute. If there is no DWP file then we'll read
5339 TUs by skipping the stub and going directly to the entry in the DWO file.
5340 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
5341 to get it via circuitous means. Blech. */
5342 if (comp_dir
!= NULL
)
5343 result_reader
->comp_dir
= DW_STRING (comp_dir
);
5345 /* Skip dummy compilation units. */
5346 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
5347 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5350 *result_info_ptr
= info_ptr
;
5354 /* Subroutine of init_cutu_and_read_dies to simplify it.
5355 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
5356 Returns NULL if the specified DWO unit cannot be found. */
5358 static struct dwo_unit
*
5359 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
5360 struct die_info
*comp_unit_die
)
5362 struct dwarf2_cu
*cu
= this_cu
->cu
;
5363 struct attribute
*attr
;
5365 struct dwo_unit
*dwo_unit
;
5366 const char *comp_dir
, *dwo_name
;
5368 gdb_assert (cu
!= NULL
);
5370 /* Yeah, we look dwo_name up again, but it simplifies the code. */
5371 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5372 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
5374 if (this_cu
->is_debug_types
)
5376 struct signatured_type
*sig_type
;
5378 /* Since this_cu is the first member of struct signatured_type,
5379 we can go from a pointer to one to a pointer to the other. */
5380 sig_type
= (struct signatured_type
*) this_cu
;
5381 signature
= sig_type
->signature
;
5382 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
5386 struct attribute
*attr
;
5388 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
5390 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
5392 dwo_name
, objfile_name (this_cu
->objfile
));
5393 signature
= DW_UNSND (attr
);
5394 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
5401 /* Subroutine of init_cutu_and_read_dies to simplify it.
5402 See it for a description of the parameters.
5403 Read a TU directly from a DWO file, bypassing the stub.
5405 Note: This function could be a little bit simpler if we shared cleanups
5406 with our caller, init_cutu_and_read_dies. That's generally a fragile thing
5407 to do, so we keep this function self-contained. Or we could move this
5408 into our caller, but it's complex enough already. */
5411 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
5412 int use_existing_cu
, int keep
,
5413 die_reader_func_ftype
*die_reader_func
,
5416 struct dwarf2_cu
*cu
;
5417 struct signatured_type
*sig_type
;
5418 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5419 struct die_reader_specs reader
;
5420 const gdb_byte
*info_ptr
;
5421 struct die_info
*comp_unit_die
;
5424 /* Verify we can do the following downcast, and that we have the
5426 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
5427 sig_type
= (struct signatured_type
*) this_cu
;
5428 gdb_assert (sig_type
->dwo_unit
!= NULL
);
5430 cleanups
= make_cleanup (null_cleanup
, NULL
);
5432 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5434 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
5436 /* There's no need to do the rereading_dwo_cu handling that
5437 init_cutu_and_read_dies does since we don't read the stub. */
5441 /* If !use_existing_cu, this_cu->cu must be NULL. */
5442 gdb_assert (this_cu
->cu
== NULL
);
5443 cu
= XNEW (struct dwarf2_cu
);
5444 init_one_comp_unit (cu
, this_cu
);
5445 /* If an error occurs while loading, release our storage. */
5446 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5449 /* A future optimization, if needed, would be to use an existing
5450 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
5451 could share abbrev tables. */
5453 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
5454 0 /* abbrev_table_provided */,
5455 NULL
/* stub_comp_unit_die */,
5456 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
5458 &comp_unit_die
, &has_children
) == 0)
5461 do_cleanups (cleanups
);
5465 /* All the "real" work is done here. */
5466 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5468 /* This duplicates the code in init_cutu_and_read_dies,
5469 but the alternative is making the latter more complex.
5470 This function is only for the special case of using DWO files directly:
5471 no point in overly complicating the general case just to handle this. */
5472 if (free_cu_cleanup
!= NULL
)
5476 /* We've successfully allocated this compilation unit. Let our
5477 caller clean it up when finished with it. */
5478 discard_cleanups (free_cu_cleanup
);
5480 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5481 So we have to manually free the abbrev table. */
5482 dwarf2_free_abbrev_table (cu
);
5484 /* Link this CU into read_in_chain. */
5485 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5486 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5489 do_cleanups (free_cu_cleanup
);
5492 do_cleanups (cleanups
);
5495 /* Initialize a CU (or TU) and read its DIEs.
5496 If the CU defers to a DWO file, read the DWO file as well.
5498 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
5499 Otherwise the table specified in the comp unit header is read in and used.
5500 This is an optimization for when we already have the abbrev table.
5502 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
5503 Otherwise, a new CU is allocated with xmalloc.
5505 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
5506 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
5508 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5509 linker) then DIE_READER_FUNC will not get called. */
5512 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
5513 struct abbrev_table
*abbrev_table
,
5514 int use_existing_cu
, int keep
,
5515 die_reader_func_ftype
*die_reader_func
,
5518 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5519 struct dwarf2_section_info
*section
= this_cu
->section
;
5520 bfd
*abfd
= get_section_bfd_owner (section
);
5521 struct dwarf2_cu
*cu
;
5522 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5523 struct die_reader_specs reader
;
5524 struct die_info
*comp_unit_die
;
5526 struct attribute
*attr
;
5527 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5528 struct signatured_type
*sig_type
= NULL
;
5529 struct dwarf2_section_info
*abbrev_section
;
5530 /* Non-zero if CU currently points to a DWO file and we need to
5531 reread it. When this happens we need to reread the skeleton die
5532 before we can reread the DWO file (this only applies to CUs, not TUs). */
5533 int rereading_dwo_cu
= 0;
5535 if (dwarf_die_debug
)
5536 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5537 this_cu
->is_debug_types
? "type" : "comp",
5538 this_cu
->offset
.sect_off
);
5540 if (use_existing_cu
)
5543 /* If we're reading a TU directly from a DWO file, including a virtual DWO
5544 file (instead of going through the stub), short-circuit all of this. */
5545 if (this_cu
->reading_dwo_directly
)
5547 /* Narrow down the scope of possibilities to have to understand. */
5548 gdb_assert (this_cu
->is_debug_types
);
5549 gdb_assert (abbrev_table
== NULL
);
5550 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
5551 die_reader_func
, data
);
5555 cleanups
= make_cleanup (null_cleanup
, NULL
);
5557 /* This is cheap if the section is already read in. */
5558 dwarf2_read_section (objfile
, section
);
5560 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
5562 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
5564 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5567 /* If this CU is from a DWO file we need to start over, we need to
5568 refetch the attributes from the skeleton CU.
5569 This could be optimized by retrieving those attributes from when we
5570 were here the first time: the previous comp_unit_die was stored in
5571 comp_unit_obstack. But there's no data yet that we need this
5573 if (cu
->dwo_unit
!= NULL
)
5574 rereading_dwo_cu
= 1;
5578 /* If !use_existing_cu, this_cu->cu must be NULL. */
5579 gdb_assert (this_cu
->cu
== NULL
);
5580 cu
= XNEW (struct dwarf2_cu
);
5581 init_one_comp_unit (cu
, this_cu
);
5582 /* If an error occurs while loading, release our storage. */
5583 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5586 /* Get the header. */
5587 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
5589 /* We already have the header, there's no need to read it in again. */
5590 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
5594 if (this_cu
->is_debug_types
)
5596 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5597 abbrev_section
, info_ptr
,
5600 /* Since per_cu is the first member of struct signatured_type,
5601 we can go from a pointer to one to a pointer to the other. */
5602 sig_type
= (struct signatured_type
*) this_cu
;
5603 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
5604 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
5605 == cu
->header
.type_offset_in_tu
.cu_off
);
5606 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5608 /* LENGTH has not been set yet for type units if we're
5609 using .gdb_index. */
5610 this_cu
->length
= get_cu_length (&cu
->header
);
5612 /* Establish the type offset that can be used to lookup the type. */
5613 sig_type
->type_offset_in_section
.sect_off
=
5614 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
5616 this_cu
->dwarf_version
= cu
->header
.version
;
5620 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5623 rcuh_kind::COMPILE
);
5625 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5626 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
5627 this_cu
->dwarf_version
= cu
->header
.version
;
5631 /* Skip dummy compilation units. */
5632 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5633 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5635 do_cleanups (cleanups
);
5639 /* If we don't have them yet, read the abbrevs for this compilation unit.
5640 And if we need to read them now, make sure they're freed when we're
5641 done. Note that it's important that if the CU had an abbrev table
5642 on entry we don't free it when we're done: Somewhere up the call stack
5643 it may be in use. */
5644 if (abbrev_table
!= NULL
)
5646 gdb_assert (cu
->abbrev_table
== NULL
);
5647 gdb_assert (cu
->header
.abbrev_offset
.sect_off
5648 == abbrev_table
->offset
.sect_off
);
5649 cu
->abbrev_table
= abbrev_table
;
5651 else if (cu
->abbrev_table
== NULL
)
5653 dwarf2_read_abbrevs (cu
, abbrev_section
);
5654 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5656 else if (rereading_dwo_cu
)
5658 dwarf2_free_abbrev_table (cu
);
5659 dwarf2_read_abbrevs (cu
, abbrev_section
);
5662 /* Read the top level CU/TU die. */
5663 init_cu_die_reader (&reader
, cu
, section
, NULL
);
5664 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5666 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
5668 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
5669 DWO CU, that this test will fail (the attribute will not be present). */
5670 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5673 struct dwo_unit
*dwo_unit
;
5674 struct die_info
*dwo_comp_unit_die
;
5678 complaint (&symfile_complaints
,
5679 _("compilation unit with DW_AT_GNU_dwo_name"
5680 " has children (offset 0x%x) [in module %s]"),
5681 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
5683 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
5684 if (dwo_unit
!= NULL
)
5686 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
5687 abbrev_table
!= NULL
,
5688 comp_unit_die
, NULL
,
5690 &dwo_comp_unit_die
, &has_children
) == 0)
5693 do_cleanups (cleanups
);
5696 comp_unit_die
= dwo_comp_unit_die
;
5700 /* Yikes, we couldn't find the rest of the DIE, we only have
5701 the stub. A complaint has already been logged. There's
5702 not much more we can do except pass on the stub DIE to
5703 die_reader_func. We don't want to throw an error on bad
5708 /* All of the above is setup for this call. Yikes. */
5709 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5711 /* Done, clean up. */
5712 if (free_cu_cleanup
!= NULL
)
5716 /* We've successfully allocated this compilation unit. Let our
5717 caller clean it up when finished with it. */
5718 discard_cleanups (free_cu_cleanup
);
5720 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5721 So we have to manually free the abbrev table. */
5722 dwarf2_free_abbrev_table (cu
);
5724 /* Link this CU into read_in_chain. */
5725 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5726 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5729 do_cleanups (free_cu_cleanup
);
5732 do_cleanups (cleanups
);
5735 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
5736 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
5737 to have already done the lookup to find the DWO file).
5739 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
5740 THIS_CU->is_debug_types, but nothing else.
5742 We fill in THIS_CU->length.
5744 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5745 linker) then DIE_READER_FUNC will not get called.
5747 THIS_CU->cu is always freed when done.
5748 This is done in order to not leave THIS_CU->cu in a state where we have
5749 to care whether it refers to the "main" CU or the DWO CU. */
5752 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
5753 struct dwo_file
*dwo_file
,
5754 die_reader_func_ftype
*die_reader_func
,
5757 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5758 struct dwarf2_section_info
*section
= this_cu
->section
;
5759 bfd
*abfd
= get_section_bfd_owner (section
);
5760 struct dwarf2_section_info
*abbrev_section
;
5761 struct dwarf2_cu cu
;
5762 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5763 struct die_reader_specs reader
;
5764 struct cleanup
*cleanups
;
5765 struct die_info
*comp_unit_die
;
5768 if (dwarf_die_debug
)
5769 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5770 this_cu
->is_debug_types
? "type" : "comp",
5771 this_cu
->offset
.sect_off
);
5773 gdb_assert (this_cu
->cu
== NULL
);
5775 abbrev_section
= (dwo_file
!= NULL
5776 ? &dwo_file
->sections
.abbrev
5777 : get_abbrev_section_for_cu (this_cu
));
5779 /* This is cheap if the section is already read in. */
5780 dwarf2_read_section (objfile
, section
);
5782 init_one_comp_unit (&cu
, this_cu
);
5784 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
5786 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
5787 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
5788 abbrev_section
, info_ptr
,
5789 (this_cu
->is_debug_types
5791 : rcuh_kind::COMPILE
));
5793 this_cu
->length
= get_cu_length (&cu
.header
);
5795 /* Skip dummy compilation units. */
5796 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5797 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5799 do_cleanups (cleanups
);
5803 dwarf2_read_abbrevs (&cu
, abbrev_section
);
5804 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
5806 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
5807 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5809 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5811 do_cleanups (cleanups
);
5814 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
5815 does not lookup the specified DWO file.
5816 This cannot be used to read DWO files.
5818 THIS_CU->cu is always freed when done.
5819 This is done in order to not leave THIS_CU->cu in a state where we have
5820 to care whether it refers to the "main" CU or the DWO CU.
5821 We can revisit this if the data shows there's a performance issue. */
5824 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
5825 die_reader_func_ftype
*die_reader_func
,
5828 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
5831 /* Type Unit Groups.
5833 Type Unit Groups are a way to collapse the set of all TUs (type units) into
5834 a more manageable set. The grouping is done by DW_AT_stmt_list entry
5835 so that all types coming from the same compilation (.o file) are grouped
5836 together. A future step could be to put the types in the same symtab as
5837 the CU the types ultimately came from. */
5840 hash_type_unit_group (const void *item
)
5842 const struct type_unit_group
*tu_group
5843 = (const struct type_unit_group
*) item
;
5845 return hash_stmt_list_entry (&tu_group
->hash
);
5849 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
5851 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
5852 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
5854 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
5857 /* Allocate a hash table for type unit groups. */
5860 allocate_type_unit_groups_table (void)
5862 return htab_create_alloc_ex (3,
5863 hash_type_unit_group
,
5866 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
5867 hashtab_obstack_allocate
,
5868 dummy_obstack_deallocate
);
5871 /* Type units that don't have DW_AT_stmt_list are grouped into their own
5872 partial symtabs. We combine several TUs per psymtab to not let the size
5873 of any one psymtab grow too big. */
5874 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
5875 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5877 /* Helper routine for get_type_unit_group.
5878 Create the type_unit_group object used to hold one or more TUs. */
5880 static struct type_unit_group
*
5881 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
5883 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5884 struct dwarf2_per_cu_data
*per_cu
;
5885 struct type_unit_group
*tu_group
;
5887 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5888 struct type_unit_group
);
5889 per_cu
= &tu_group
->per_cu
;
5890 per_cu
->objfile
= objfile
;
5892 if (dwarf2_per_objfile
->using_index
)
5894 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5895 struct dwarf2_per_cu_quick_data
);
5899 unsigned int line_offset
= line_offset_struct
.sect_off
;
5900 struct partial_symtab
*pst
;
5903 /* Give the symtab a useful name for debug purposes. */
5904 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
5905 name
= xstrprintf ("<type_units_%d>",
5906 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
5908 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
5910 pst
= create_partial_symtab (per_cu
, name
);
5916 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
5917 tu_group
->hash
.line_offset
= line_offset_struct
;
5922 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5923 STMT_LIST is a DW_AT_stmt_list attribute. */
5925 static struct type_unit_group
*
5926 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
5928 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5929 struct type_unit_group
*tu_group
;
5931 unsigned int line_offset
;
5932 struct type_unit_group type_unit_group_for_lookup
;
5934 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
5936 dwarf2_per_objfile
->type_unit_groups
=
5937 allocate_type_unit_groups_table ();
5940 /* Do we need to create a new group, or can we use an existing one? */
5944 line_offset
= DW_UNSND (stmt_list
);
5945 ++tu_stats
->nr_symtab_sharers
;
5949 /* Ugh, no stmt_list. Rare, but we have to handle it.
5950 We can do various things here like create one group per TU or
5951 spread them over multiple groups to split up the expansion work.
5952 To avoid worst case scenarios (too many groups or too large groups)
5953 we, umm, group them in bunches. */
5954 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5955 | (tu_stats
->nr_stmt_less_type_units
5956 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
5957 ++tu_stats
->nr_stmt_less_type_units
;
5960 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
5961 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
5962 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
5963 &type_unit_group_for_lookup
, INSERT
);
5966 tu_group
= (struct type_unit_group
*) *slot
;
5967 gdb_assert (tu_group
!= NULL
);
5971 sect_offset line_offset_struct
;
5973 line_offset_struct
.sect_off
= line_offset
;
5974 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
5976 ++tu_stats
->nr_symtabs
;
5982 /* Partial symbol tables. */
5984 /* Create a psymtab named NAME and assign it to PER_CU.
5986 The caller must fill in the following details:
5987 dirname, textlow, texthigh. */
5989 static struct partial_symtab
*
5990 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
5992 struct objfile
*objfile
= per_cu
->objfile
;
5993 struct partial_symtab
*pst
;
5995 pst
= start_psymtab_common (objfile
, name
, 0,
5996 objfile
->global_psymbols
.next
,
5997 objfile
->static_psymbols
.next
);
5999 pst
->psymtabs_addrmap_supported
= 1;
6001 /* This is the glue that links PST into GDB's symbol API. */
6002 pst
->read_symtab_private
= per_cu
;
6003 pst
->read_symtab
= dwarf2_read_symtab
;
6004 per_cu
->v
.psymtab
= pst
;
6009 /* The DATA object passed to process_psymtab_comp_unit_reader has this
6012 struct process_psymtab_comp_unit_data
6014 /* True if we are reading a DW_TAG_partial_unit. */
6016 int want_partial_unit
;
6018 /* The "pretend" language that is used if the CU doesn't declare a
6021 enum language pretend_language
;
6024 /* die_reader_func for process_psymtab_comp_unit. */
6027 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6028 const gdb_byte
*info_ptr
,
6029 struct die_info
*comp_unit_die
,
6033 struct dwarf2_cu
*cu
= reader
->cu
;
6034 struct objfile
*objfile
= cu
->objfile
;
6035 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6036 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6038 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6039 struct partial_symtab
*pst
;
6040 enum pc_bounds_kind cu_bounds_kind
;
6041 const char *filename
;
6042 struct process_psymtab_comp_unit_data
*info
6043 = (struct process_psymtab_comp_unit_data
*) data
;
6045 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
6048 gdb_assert (! per_cu
->is_debug_types
);
6050 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
6052 cu
->list_in_scope
= &file_symbols
;
6054 /* Allocate a new partial symbol table structure. */
6055 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
6056 if (filename
== NULL
)
6059 pst
= create_partial_symtab (per_cu
, filename
);
6061 /* This must be done before calling dwarf2_build_include_psymtabs. */
6062 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6064 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6066 dwarf2_find_base_address (comp_unit_die
, cu
);
6068 /* Possibly set the default values of LOWPC and HIGHPC from
6070 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
6071 &best_highpc
, cu
, pst
);
6072 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
6073 /* Store the contiguous range if it is not empty; it can be empty for
6074 CUs with no code. */
6075 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6076 gdbarch_adjust_dwarf2_addr (gdbarch
,
6077 best_lowpc
+ baseaddr
),
6078 gdbarch_adjust_dwarf2_addr (gdbarch
,
6079 best_highpc
+ baseaddr
) - 1,
6082 /* Check if comp unit has_children.
6083 If so, read the rest of the partial symbols from this comp unit.
6084 If not, there's no more debug_info for this comp unit. */
6087 struct partial_die_info
*first_die
;
6088 CORE_ADDR lowpc
, highpc
;
6090 lowpc
= ((CORE_ADDR
) -1);
6091 highpc
= ((CORE_ADDR
) 0);
6093 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6095 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
6096 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
6098 /* If we didn't find a lowpc, set it to highpc to avoid
6099 complaints from `maint check'. */
6100 if (lowpc
== ((CORE_ADDR
) -1))
6103 /* If the compilation unit didn't have an explicit address range,
6104 then use the information extracted from its child dies. */
6105 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
6108 best_highpc
= highpc
;
6111 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
6112 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
6114 end_psymtab_common (objfile
, pst
);
6116 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
6119 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6120 struct dwarf2_per_cu_data
*iter
;
6122 /* Fill in 'dependencies' here; we fill in 'users' in a
6124 pst
->number_of_dependencies
= len
;
6126 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6128 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
6131 pst
->dependencies
[i
] = iter
->v
.psymtab
;
6133 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6136 /* Get the list of files included in the current compilation unit,
6137 and build a psymtab for each of them. */
6138 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
6140 if (dwarf_read_debug
)
6142 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6144 fprintf_unfiltered (gdb_stdlog
,
6145 "Psymtab for %s unit @0x%x: %s - %s"
6146 ", %d global, %d static syms\n",
6147 per_cu
->is_debug_types
? "type" : "comp",
6148 per_cu
->offset
.sect_off
,
6149 paddress (gdbarch
, pst
->textlow
),
6150 paddress (gdbarch
, pst
->texthigh
),
6151 pst
->n_global_syms
, pst
->n_static_syms
);
6155 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6156 Process compilation unit THIS_CU for a psymtab. */
6159 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6160 int want_partial_unit
,
6161 enum language pretend_language
)
6163 struct process_psymtab_comp_unit_data info
;
6165 /* If this compilation unit was already read in, free the
6166 cached copy in order to read it in again. This is
6167 necessary because we skipped some symbols when we first
6168 read in the compilation unit (see load_partial_dies).
6169 This problem could be avoided, but the benefit is unclear. */
6170 if (this_cu
->cu
!= NULL
)
6171 free_one_cached_comp_unit (this_cu
);
6173 gdb_assert (! this_cu
->is_debug_types
);
6174 info
.want_partial_unit
= want_partial_unit
;
6175 info
.pretend_language
= pretend_language
;
6176 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
6177 process_psymtab_comp_unit_reader
,
6180 /* Age out any secondary CUs. */
6181 age_cached_comp_units ();
6184 /* Reader function for build_type_psymtabs. */
6187 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
6188 const gdb_byte
*info_ptr
,
6189 struct die_info
*type_unit_die
,
6193 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6194 struct dwarf2_cu
*cu
= reader
->cu
;
6195 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6196 struct signatured_type
*sig_type
;
6197 struct type_unit_group
*tu_group
;
6198 struct attribute
*attr
;
6199 struct partial_die_info
*first_die
;
6200 CORE_ADDR lowpc
, highpc
;
6201 struct partial_symtab
*pst
;
6203 gdb_assert (data
== NULL
);
6204 gdb_assert (per_cu
->is_debug_types
);
6205 sig_type
= (struct signatured_type
*) per_cu
;
6210 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
6211 tu_group
= get_type_unit_group (cu
, attr
);
6213 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
6215 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
6216 cu
->list_in_scope
= &file_symbols
;
6217 pst
= create_partial_symtab (per_cu
, "");
6220 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6222 lowpc
= (CORE_ADDR
) -1;
6223 highpc
= (CORE_ADDR
) 0;
6224 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
6226 end_psymtab_common (objfile
, pst
);
6229 /* Struct used to sort TUs by their abbreviation table offset. */
6231 struct tu_abbrev_offset
6233 struct signatured_type
*sig_type
;
6234 sect_offset abbrev_offset
;
6237 /* Helper routine for build_type_psymtabs_1, passed to qsort. */
6240 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
6242 const struct tu_abbrev_offset
* const *a
6243 = (const struct tu_abbrev_offset
* const*) ap
;
6244 const struct tu_abbrev_offset
* const *b
6245 = (const struct tu_abbrev_offset
* const*) bp
;
6246 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
6247 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
6249 return (aoff
> boff
) - (aoff
< boff
);
6252 /* Efficiently read all the type units.
6253 This does the bulk of the work for build_type_psymtabs.
6255 The efficiency is because we sort TUs by the abbrev table they use and
6256 only read each abbrev table once. In one program there are 200K TUs
6257 sharing 8K abbrev tables.
6259 The main purpose of this function is to support building the
6260 dwarf2_per_objfile->type_unit_groups table.
6261 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
6262 can collapse the search space by grouping them by stmt_list.
6263 The savings can be significant, in the same program from above the 200K TUs
6264 share 8K stmt_list tables.
6266 FUNC is expected to call get_type_unit_group, which will create the
6267 struct type_unit_group if necessary and add it to
6268 dwarf2_per_objfile->type_unit_groups. */
6271 build_type_psymtabs_1 (void)
6273 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6274 struct cleanup
*cleanups
;
6275 struct abbrev_table
*abbrev_table
;
6276 sect_offset abbrev_offset
;
6277 struct tu_abbrev_offset
*sorted_by_abbrev
;
6280 /* It's up to the caller to not call us multiple times. */
6281 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
6283 if (dwarf2_per_objfile
->n_type_units
== 0)
6286 /* TUs typically share abbrev tables, and there can be way more TUs than
6287 abbrev tables. Sort by abbrev table to reduce the number of times we
6288 read each abbrev table in.
6289 Alternatives are to punt or to maintain a cache of abbrev tables.
6290 This is simpler and efficient enough for now.
6292 Later we group TUs by their DW_AT_stmt_list value (as this defines the
6293 symtab to use). Typically TUs with the same abbrev offset have the same
6294 stmt_list value too so in practice this should work well.
6296 The basic algorithm here is:
6298 sort TUs by abbrev table
6299 for each TU with same abbrev table:
6300 read abbrev table if first user
6301 read TU top level DIE
6302 [IWBN if DWO skeletons had DW_AT_stmt_list]
6305 if (dwarf_read_debug
)
6306 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
6308 /* Sort in a separate table to maintain the order of all_type_units
6309 for .gdb_index: TU indices directly index all_type_units. */
6310 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
6311 dwarf2_per_objfile
->n_type_units
);
6312 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6314 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
6316 sorted_by_abbrev
[i
].sig_type
= sig_type
;
6317 sorted_by_abbrev
[i
].abbrev_offset
=
6318 read_abbrev_offset (sig_type
->per_cu
.section
,
6319 sig_type
->per_cu
.offset
);
6321 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
6322 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
6323 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
6325 abbrev_offset
.sect_off
= ~(unsigned) 0;
6326 abbrev_table
= NULL
;
6327 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
6329 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6331 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
6333 /* Switch to the next abbrev table if necessary. */
6334 if (abbrev_table
== NULL
6335 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
6337 if (abbrev_table
!= NULL
)
6339 abbrev_table_free (abbrev_table
);
6340 /* Reset to NULL in case abbrev_table_read_table throws
6341 an error: abbrev_table_free_cleanup will get called. */
6342 abbrev_table
= NULL
;
6344 abbrev_offset
= tu
->abbrev_offset
;
6346 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
6348 ++tu_stats
->nr_uniq_abbrev_tables
;
6351 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
6352 build_type_psymtabs_reader
, NULL
);
6355 do_cleanups (cleanups
);
6358 /* Print collected type unit statistics. */
6361 print_tu_stats (void)
6363 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6365 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
6366 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
6367 dwarf2_per_objfile
->n_type_units
);
6368 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
6369 tu_stats
->nr_uniq_abbrev_tables
);
6370 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
6371 tu_stats
->nr_symtabs
);
6372 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
6373 tu_stats
->nr_symtab_sharers
);
6374 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
6375 tu_stats
->nr_stmt_less_type_units
);
6376 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
6377 tu_stats
->nr_all_type_units_reallocs
);
6380 /* Traversal function for build_type_psymtabs. */
6383 build_type_psymtab_dependencies (void **slot
, void *info
)
6385 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6386 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
6387 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
6388 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6389 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
6390 struct signatured_type
*iter
;
6393 gdb_assert (len
> 0);
6394 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
6396 pst
->number_of_dependencies
= len
;
6398 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6400 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
6403 gdb_assert (iter
->per_cu
.is_debug_types
);
6404 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
6405 iter
->type_unit_group
= tu_group
;
6408 VEC_free (sig_type_ptr
, tu_group
->tus
);
6413 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6414 Build partial symbol tables for the .debug_types comp-units. */
6417 build_type_psymtabs (struct objfile
*objfile
)
6419 if (! create_all_type_units (objfile
))
6422 build_type_psymtabs_1 ();
6425 /* Traversal function for process_skeletonless_type_unit.
6426 Read a TU in a DWO file and build partial symbols for it. */
6429 process_skeletonless_type_unit (void **slot
, void *info
)
6431 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
6432 struct objfile
*objfile
= (struct objfile
*) info
;
6433 struct signatured_type find_entry
, *entry
;
6435 /* If this TU doesn't exist in the global table, add it and read it in. */
6437 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6439 dwarf2_per_objfile
->signatured_types
6440 = allocate_signatured_type_table (objfile
);
6443 find_entry
.signature
= dwo_unit
->signature
;
6444 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
6446 /* If we've already seen this type there's nothing to do. What's happening
6447 is we're doing our own version of comdat-folding here. */
6451 /* This does the job that create_all_type_units would have done for
6453 entry
= add_type_unit (dwo_unit
->signature
, slot
);
6454 fill_in_sig_entry_from_dwo_entry (objfile
, entry
, dwo_unit
);
6457 /* This does the job that build_type_psymtabs_1 would have done. */
6458 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
6459 build_type_psymtabs_reader
, NULL
);
6464 /* Traversal function for process_skeletonless_type_units. */
6467 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
6469 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
6471 if (dwo_file
->tus
!= NULL
)
6473 htab_traverse_noresize (dwo_file
->tus
,
6474 process_skeletonless_type_unit
, info
);
6480 /* Scan all TUs of DWO files, verifying we've processed them.
6481 This is needed in case a TU was emitted without its skeleton.
6482 Note: This can't be done until we know what all the DWO files are. */
6485 process_skeletonless_type_units (struct objfile
*objfile
)
6487 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
6488 if (get_dwp_file () == NULL
6489 && dwarf2_per_objfile
->dwo_files
!= NULL
)
6491 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
6492 process_dwo_file_for_skeletonless_type_units
,
6497 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
6500 psymtabs_addrmap_cleanup (void *o
)
6502 struct objfile
*objfile
= (struct objfile
*) o
;
6504 objfile
->psymtabs_addrmap
= NULL
;
6507 /* Compute the 'user' field for each psymtab in OBJFILE. */
6510 set_partial_user (struct objfile
*objfile
)
6514 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6516 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6517 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6523 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
6525 /* Set the 'user' field only if it is not already set. */
6526 if (pst
->dependencies
[j
]->user
== NULL
)
6527 pst
->dependencies
[j
]->user
= pst
;
6532 /* Build the partial symbol table by doing a quick pass through the
6533 .debug_info and .debug_abbrev sections. */
6536 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
6538 struct cleanup
*back_to
, *addrmap_cleanup
;
6539 struct obstack temp_obstack
;
6542 if (dwarf_read_debug
)
6544 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
6545 objfile_name (objfile
));
6548 dwarf2_per_objfile
->reading_partial_symbols
= 1;
6550 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
6552 /* Any cached compilation units will be linked by the per-objfile
6553 read_in_chain. Make sure to free them when we're done. */
6554 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
6556 build_type_psymtabs (objfile
);
6558 create_all_comp_units (objfile
);
6560 /* Create a temporary address map on a temporary obstack. We later
6561 copy this to the final obstack. */
6562 obstack_init (&temp_obstack
);
6563 make_cleanup_obstack_free (&temp_obstack
);
6564 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
6565 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
6567 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6569 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6571 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
6574 /* This has to wait until we read the CUs, we need the list of DWOs. */
6575 process_skeletonless_type_units (objfile
);
6577 /* Now that all TUs have been processed we can fill in the dependencies. */
6578 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
6580 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
6581 build_type_psymtab_dependencies
, NULL
);
6584 if (dwarf_read_debug
)
6587 set_partial_user (objfile
);
6589 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
6590 &objfile
->objfile_obstack
);
6591 discard_cleanups (addrmap_cleanup
);
6593 do_cleanups (back_to
);
6595 if (dwarf_read_debug
)
6596 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
6597 objfile_name (objfile
));
6600 /* die_reader_func for load_partial_comp_unit. */
6603 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
6604 const gdb_byte
*info_ptr
,
6605 struct die_info
*comp_unit_die
,
6609 struct dwarf2_cu
*cu
= reader
->cu
;
6611 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
6613 /* Check if comp unit has_children.
6614 If so, read the rest of the partial symbols from this comp unit.
6615 If not, there's no more debug_info for this comp unit. */
6617 load_partial_dies (reader
, info_ptr
, 0);
6620 /* Load the partial DIEs for a secondary CU into memory.
6621 This is also used when rereading a primary CU with load_all_dies. */
6624 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
6626 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6627 load_partial_comp_unit_reader
, NULL
);
6631 read_comp_units_from_section (struct objfile
*objfile
,
6632 struct dwarf2_section_info
*section
,
6633 unsigned int is_dwz
,
6636 struct dwarf2_per_cu_data
***all_comp_units
)
6638 const gdb_byte
*info_ptr
;
6639 bfd
*abfd
= get_section_bfd_owner (section
);
6641 if (dwarf_read_debug
)
6642 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
6643 get_section_name (section
),
6644 get_section_file_name (section
));
6646 dwarf2_read_section (objfile
, section
);
6648 info_ptr
= section
->buffer
;
6650 while (info_ptr
< section
->buffer
+ section
->size
)
6652 unsigned int length
, initial_length_size
;
6653 struct dwarf2_per_cu_data
*this_cu
;
6656 offset
.sect_off
= info_ptr
- section
->buffer
;
6658 /* Read just enough information to find out where the next
6659 compilation unit is. */
6660 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6662 /* Save the compilation unit for later lookup. */
6663 this_cu
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
);
6664 memset (this_cu
, 0, sizeof (*this_cu
));
6665 this_cu
->offset
= offset
;
6666 this_cu
->length
= length
+ initial_length_size
;
6667 this_cu
->is_dwz
= is_dwz
;
6668 this_cu
->objfile
= objfile
;
6669 this_cu
->section
= section
;
6671 if (*n_comp_units
== *n_allocated
)
6674 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
6675 *all_comp_units
, *n_allocated
);
6677 (*all_comp_units
)[*n_comp_units
] = this_cu
;
6680 info_ptr
= info_ptr
+ this_cu
->length
;
6684 /* Create a list of all compilation units in OBJFILE.
6685 This is only done for -readnow and building partial symtabs. */
6688 create_all_comp_units (struct objfile
*objfile
)
6692 struct dwarf2_per_cu_data
**all_comp_units
;
6693 struct dwz_file
*dwz
;
6697 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
6699 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
6700 &n_allocated
, &n_comp_units
, &all_comp_units
);
6702 dwz
= dwarf2_get_dwz_file ();
6704 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
6705 &n_allocated
, &n_comp_units
,
6708 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
6709 struct dwarf2_per_cu_data
*,
6711 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
6712 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
6713 xfree (all_comp_units
);
6714 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
6717 /* Process all loaded DIEs for compilation unit CU, starting at
6718 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
6719 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
6720 DW_AT_ranges). See the comments of add_partial_subprogram on how
6721 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
6724 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
6725 CORE_ADDR
*highpc
, int set_addrmap
,
6726 struct dwarf2_cu
*cu
)
6728 struct partial_die_info
*pdi
;
6730 /* Now, march along the PDI's, descending into ones which have
6731 interesting children but skipping the children of the other ones,
6732 until we reach the end of the compilation unit. */
6738 fixup_partial_die (pdi
, cu
);
6740 /* Anonymous namespaces or modules have no name but have interesting
6741 children, so we need to look at them. Ditto for anonymous
6744 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
6745 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
6746 || pdi
->tag
== DW_TAG_imported_unit
)
6750 case DW_TAG_subprogram
:
6751 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6753 case DW_TAG_constant
:
6754 case DW_TAG_variable
:
6755 case DW_TAG_typedef
:
6756 case DW_TAG_union_type
:
6757 if (!pdi
->is_declaration
)
6759 add_partial_symbol (pdi
, cu
);
6762 case DW_TAG_class_type
:
6763 case DW_TAG_interface_type
:
6764 case DW_TAG_structure_type
:
6765 if (!pdi
->is_declaration
)
6767 add_partial_symbol (pdi
, cu
);
6769 if (cu
->language
== language_rust
&& pdi
->has_children
)
6770 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
6773 case DW_TAG_enumeration_type
:
6774 if (!pdi
->is_declaration
)
6775 add_partial_enumeration (pdi
, cu
);
6777 case DW_TAG_base_type
:
6778 case DW_TAG_subrange_type
:
6779 /* File scope base type definitions are added to the partial
6781 add_partial_symbol (pdi
, cu
);
6783 case DW_TAG_namespace
:
6784 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6787 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6789 case DW_TAG_imported_unit
:
6791 struct dwarf2_per_cu_data
*per_cu
;
6793 /* For now we don't handle imported units in type units. */
6794 if (cu
->per_cu
->is_debug_types
)
6796 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6797 " supported in type units [in module %s]"),
6798 objfile_name (cu
->objfile
));
6801 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
6805 /* Go read the partial unit, if needed. */
6806 if (per_cu
->v
.psymtab
== NULL
)
6807 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
6809 VEC_safe_push (dwarf2_per_cu_ptr
,
6810 cu
->per_cu
->imported_symtabs
, per_cu
);
6813 case DW_TAG_imported_declaration
:
6814 add_partial_symbol (pdi
, cu
);
6821 /* If the die has a sibling, skip to the sibling. */
6823 pdi
= pdi
->die_sibling
;
6827 /* Functions used to compute the fully scoped name of a partial DIE.
6829 Normally, this is simple. For C++, the parent DIE's fully scoped
6830 name is concatenated with "::" and the partial DIE's name.
6831 Enumerators are an exception; they use the scope of their parent
6832 enumeration type, i.e. the name of the enumeration type is not
6833 prepended to the enumerator.
6835 There are two complexities. One is DW_AT_specification; in this
6836 case "parent" means the parent of the target of the specification,
6837 instead of the direct parent of the DIE. The other is compilers
6838 which do not emit DW_TAG_namespace; in this case we try to guess
6839 the fully qualified name of structure types from their members'
6840 linkage names. This must be done using the DIE's children rather
6841 than the children of any DW_AT_specification target. We only need
6842 to do this for structures at the top level, i.e. if the target of
6843 any DW_AT_specification (if any; otherwise the DIE itself) does not
6846 /* Compute the scope prefix associated with PDI's parent, in
6847 compilation unit CU. The result will be allocated on CU's
6848 comp_unit_obstack, or a copy of the already allocated PDI->NAME
6849 field. NULL is returned if no prefix is necessary. */
6851 partial_die_parent_scope (struct partial_die_info
*pdi
,
6852 struct dwarf2_cu
*cu
)
6854 const char *grandparent_scope
;
6855 struct partial_die_info
*parent
, *real_pdi
;
6857 /* We need to look at our parent DIE; if we have a DW_AT_specification,
6858 then this means the parent of the specification DIE. */
6861 while (real_pdi
->has_specification
)
6862 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
6863 real_pdi
->spec_is_dwz
, cu
);
6865 parent
= real_pdi
->die_parent
;
6869 if (parent
->scope_set
)
6870 return parent
->scope
;
6872 fixup_partial_die (parent
, cu
);
6874 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
6876 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
6877 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
6878 Work around this problem here. */
6879 if (cu
->language
== language_cplus
6880 && parent
->tag
== DW_TAG_namespace
6881 && strcmp (parent
->name
, "::") == 0
6882 && grandparent_scope
== NULL
)
6884 parent
->scope
= NULL
;
6885 parent
->scope_set
= 1;
6889 if (pdi
->tag
== DW_TAG_enumerator
)
6890 /* Enumerators should not get the name of the enumeration as a prefix. */
6891 parent
->scope
= grandparent_scope
;
6892 else if (parent
->tag
== DW_TAG_namespace
6893 || parent
->tag
== DW_TAG_module
6894 || parent
->tag
== DW_TAG_structure_type
6895 || parent
->tag
== DW_TAG_class_type
6896 || parent
->tag
== DW_TAG_interface_type
6897 || parent
->tag
== DW_TAG_union_type
6898 || parent
->tag
== DW_TAG_enumeration_type
)
6900 if (grandparent_scope
== NULL
)
6901 parent
->scope
= parent
->name
;
6903 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
6905 parent
->name
, 0, cu
);
6909 /* FIXME drow/2004-04-01: What should we be doing with
6910 function-local names? For partial symbols, we should probably be
6912 complaint (&symfile_complaints
,
6913 _("unhandled containing DIE tag %d for DIE at %d"),
6914 parent
->tag
, pdi
->offset
.sect_off
);
6915 parent
->scope
= grandparent_scope
;
6918 parent
->scope_set
= 1;
6919 return parent
->scope
;
6922 /* Return the fully scoped name associated with PDI, from compilation unit
6923 CU. The result will be allocated with malloc. */
6926 partial_die_full_name (struct partial_die_info
*pdi
,
6927 struct dwarf2_cu
*cu
)
6929 const char *parent_scope
;
6931 /* If this is a template instantiation, we can not work out the
6932 template arguments from partial DIEs. So, unfortunately, we have
6933 to go through the full DIEs. At least any work we do building
6934 types here will be reused if full symbols are loaded later. */
6935 if (pdi
->has_template_arguments
)
6937 fixup_partial_die (pdi
, cu
);
6939 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
6941 struct die_info
*die
;
6942 struct attribute attr
;
6943 struct dwarf2_cu
*ref_cu
= cu
;
6945 /* DW_FORM_ref_addr is using section offset. */
6946 attr
.name
= (enum dwarf_attribute
) 0;
6947 attr
.form
= DW_FORM_ref_addr
;
6948 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
6949 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
6951 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
6955 parent_scope
= partial_die_parent_scope (pdi
, cu
);
6956 if (parent_scope
== NULL
)
6959 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
6963 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
6965 struct objfile
*objfile
= cu
->objfile
;
6966 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6968 const char *actual_name
= NULL
;
6970 char *built_actual_name
;
6972 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6974 built_actual_name
= partial_die_full_name (pdi
, cu
);
6975 if (built_actual_name
!= NULL
)
6976 actual_name
= built_actual_name
;
6978 if (actual_name
== NULL
)
6979 actual_name
= pdi
->name
;
6983 case DW_TAG_subprogram
:
6984 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
6985 if (pdi
->is_external
|| cu
->language
== language_ada
)
6987 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
6988 of the global scope. But in Ada, we want to be able to access
6989 nested procedures globally. So all Ada subprograms are stored
6990 in the global scope. */
6991 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6992 built_actual_name
!= NULL
,
6993 VAR_DOMAIN
, LOC_BLOCK
,
6994 &objfile
->global_psymbols
,
6995 addr
, cu
->language
, objfile
);
6999 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7000 built_actual_name
!= NULL
,
7001 VAR_DOMAIN
, LOC_BLOCK
,
7002 &objfile
->static_psymbols
,
7003 addr
, cu
->language
, objfile
);
7006 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7007 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
7009 case DW_TAG_constant
:
7011 struct psymbol_allocation_list
*list
;
7013 if (pdi
->is_external
)
7014 list
= &objfile
->global_psymbols
;
7016 list
= &objfile
->static_psymbols
;
7017 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7018 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
7019 list
, 0, cu
->language
, objfile
);
7022 case DW_TAG_variable
:
7024 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7028 && !dwarf2_per_objfile
->has_section_at_zero
)
7030 /* A global or static variable may also have been stripped
7031 out by the linker if unused, in which case its address
7032 will be nullified; do not add such variables into partial
7033 symbol table then. */
7035 else if (pdi
->is_external
)
7038 Don't enter into the minimal symbol tables as there is
7039 a minimal symbol table entry from the ELF symbols already.
7040 Enter into partial symbol table if it has a location
7041 descriptor or a type.
7042 If the location descriptor is missing, new_symbol will create
7043 a LOC_UNRESOLVED symbol, the address of the variable will then
7044 be determined from the minimal symbol table whenever the variable
7046 The address for the partial symbol table entry is not
7047 used by GDB, but it comes in handy for debugging partial symbol
7050 if (pdi
->d
.locdesc
|| pdi
->has_type
)
7051 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7052 built_actual_name
!= NULL
,
7053 VAR_DOMAIN
, LOC_STATIC
,
7054 &objfile
->global_psymbols
,
7056 cu
->language
, objfile
);
7060 int has_loc
= pdi
->d
.locdesc
!= NULL
;
7062 /* Static Variable. Skip symbols whose value we cannot know (those
7063 without location descriptors or constant values). */
7064 if (!has_loc
&& !pdi
->has_const_value
)
7066 xfree (built_actual_name
);
7070 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7071 built_actual_name
!= NULL
,
7072 VAR_DOMAIN
, LOC_STATIC
,
7073 &objfile
->static_psymbols
,
7074 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
7075 cu
->language
, objfile
);
7078 case DW_TAG_typedef
:
7079 case DW_TAG_base_type
:
7080 case DW_TAG_subrange_type
:
7081 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7082 built_actual_name
!= NULL
,
7083 VAR_DOMAIN
, LOC_TYPEDEF
,
7084 &objfile
->static_psymbols
,
7085 0, cu
->language
, objfile
);
7087 case DW_TAG_imported_declaration
:
7088 case DW_TAG_namespace
:
7089 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7090 built_actual_name
!= NULL
,
7091 VAR_DOMAIN
, LOC_TYPEDEF
,
7092 &objfile
->global_psymbols
,
7093 0, cu
->language
, objfile
);
7096 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7097 built_actual_name
!= NULL
,
7098 MODULE_DOMAIN
, LOC_TYPEDEF
,
7099 &objfile
->global_psymbols
,
7100 0, cu
->language
, objfile
);
7102 case DW_TAG_class_type
:
7103 case DW_TAG_interface_type
:
7104 case DW_TAG_structure_type
:
7105 case DW_TAG_union_type
:
7106 case DW_TAG_enumeration_type
:
7107 /* Skip external references. The DWARF standard says in the section
7108 about "Structure, Union, and Class Type Entries": "An incomplete
7109 structure, union or class type is represented by a structure,
7110 union or class entry that does not have a byte size attribute
7111 and that has a DW_AT_declaration attribute." */
7112 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
7114 xfree (built_actual_name
);
7118 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
7119 static vs. global. */
7120 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7121 built_actual_name
!= NULL
,
7122 STRUCT_DOMAIN
, LOC_TYPEDEF
,
7123 cu
->language
== language_cplus
7124 ? &objfile
->global_psymbols
7125 : &objfile
->static_psymbols
,
7126 0, cu
->language
, objfile
);
7129 case DW_TAG_enumerator
:
7130 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7131 built_actual_name
!= NULL
,
7132 VAR_DOMAIN
, LOC_CONST
,
7133 cu
->language
== language_cplus
7134 ? &objfile
->global_psymbols
7135 : &objfile
->static_psymbols
,
7136 0, cu
->language
, objfile
);
7142 xfree (built_actual_name
);
7145 /* Read a partial die corresponding to a namespace; also, add a symbol
7146 corresponding to that namespace to the symbol table. NAMESPACE is
7147 the name of the enclosing namespace. */
7150 add_partial_namespace (struct partial_die_info
*pdi
,
7151 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7152 int set_addrmap
, struct dwarf2_cu
*cu
)
7154 /* Add a symbol for the namespace. */
7156 add_partial_symbol (pdi
, cu
);
7158 /* Now scan partial symbols in that namespace. */
7160 if (pdi
->has_children
)
7161 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7164 /* Read a partial die corresponding to a Fortran module. */
7167 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
7168 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
7170 /* Add a symbol for the namespace. */
7172 add_partial_symbol (pdi
, cu
);
7174 /* Now scan partial symbols in that module. */
7176 if (pdi
->has_children
)
7177 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7180 /* Read a partial die corresponding to a subprogram and create a partial
7181 symbol for that subprogram. When the CU language allows it, this
7182 routine also defines a partial symbol for each nested subprogram
7183 that this subprogram contains. If SET_ADDRMAP is true, record the
7184 covered ranges in the addrmap. Set *LOWPC and *HIGHPC to the lowest
7185 and highest PC values found in PDI.
7187 PDI may also be a lexical block, in which case we simply search
7188 recursively for subprograms defined inside that lexical block.
7189 Again, this is only performed when the CU language allows this
7190 type of definitions. */
7193 add_partial_subprogram (struct partial_die_info
*pdi
,
7194 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7195 int set_addrmap
, struct dwarf2_cu
*cu
)
7197 if (pdi
->tag
== DW_TAG_subprogram
)
7199 if (pdi
->has_pc_info
)
7201 if (pdi
->lowpc
< *lowpc
)
7202 *lowpc
= pdi
->lowpc
;
7203 if (pdi
->highpc
> *highpc
)
7204 *highpc
= pdi
->highpc
;
7207 struct objfile
*objfile
= cu
->objfile
;
7208 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7213 baseaddr
= ANOFFSET (objfile
->section_offsets
,
7214 SECT_OFF_TEXT (objfile
));
7215 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7216 pdi
->lowpc
+ baseaddr
);
7217 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7218 pdi
->highpc
+ baseaddr
);
7219 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
7220 cu
->per_cu
->v
.psymtab
);
7224 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
7226 if (!pdi
->is_declaration
)
7227 /* Ignore subprogram DIEs that do not have a name, they are
7228 illegal. Do not emit a complaint at this point, we will
7229 do so when we convert this psymtab into a symtab. */
7231 add_partial_symbol (pdi
, cu
);
7235 if (! pdi
->has_children
)
7238 if (cu
->language
== language_ada
)
7240 pdi
= pdi
->die_child
;
7243 fixup_partial_die (pdi
, cu
);
7244 if (pdi
->tag
== DW_TAG_subprogram
7245 || pdi
->tag
== DW_TAG_lexical_block
)
7246 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7247 pdi
= pdi
->die_sibling
;
7252 /* Read a partial die corresponding to an enumeration type. */
7255 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
7256 struct dwarf2_cu
*cu
)
7258 struct partial_die_info
*pdi
;
7260 if (enum_pdi
->name
!= NULL
)
7261 add_partial_symbol (enum_pdi
, cu
);
7263 pdi
= enum_pdi
->die_child
;
7266 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
7267 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
7269 add_partial_symbol (pdi
, cu
);
7270 pdi
= pdi
->die_sibling
;
7274 /* Return the initial uleb128 in the die at INFO_PTR. */
7277 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
7279 unsigned int bytes_read
;
7281 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7284 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
7285 Return the corresponding abbrev, or NULL if the number is zero (indicating
7286 an empty DIE). In either case *BYTES_READ will be set to the length of
7287 the initial number. */
7289 static struct abbrev_info
*
7290 peek_die_abbrev (const gdb_byte
*info_ptr
, unsigned int *bytes_read
,
7291 struct dwarf2_cu
*cu
)
7293 bfd
*abfd
= cu
->objfile
->obfd
;
7294 unsigned int abbrev_number
;
7295 struct abbrev_info
*abbrev
;
7297 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
7299 if (abbrev_number
== 0)
7302 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
7305 error (_("Dwarf Error: Could not find abbrev number %d in %s"
7306 " at offset 0x%x [in module %s]"),
7307 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
7308 cu
->header
.offset
.sect_off
, bfd_get_filename (abfd
));
7314 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7315 Returns a pointer to the end of a series of DIEs, terminated by an empty
7316 DIE. Any children of the skipped DIEs will also be skipped. */
7318 static const gdb_byte
*
7319 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
7321 struct dwarf2_cu
*cu
= reader
->cu
;
7322 struct abbrev_info
*abbrev
;
7323 unsigned int bytes_read
;
7327 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
7329 return info_ptr
+ bytes_read
;
7331 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
7335 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7336 INFO_PTR should point just after the initial uleb128 of a DIE, and the
7337 abbrev corresponding to that skipped uleb128 should be passed in
7338 ABBREV. Returns a pointer to this DIE's sibling, skipping any
7341 static const gdb_byte
*
7342 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
7343 struct abbrev_info
*abbrev
)
7345 unsigned int bytes_read
;
7346 struct attribute attr
;
7347 bfd
*abfd
= reader
->abfd
;
7348 struct dwarf2_cu
*cu
= reader
->cu
;
7349 const gdb_byte
*buffer
= reader
->buffer
;
7350 const gdb_byte
*buffer_end
= reader
->buffer_end
;
7351 unsigned int form
, i
;
7353 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
7355 /* The only abbrev we care about is DW_AT_sibling. */
7356 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
7358 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
7359 if (attr
.form
== DW_FORM_ref_addr
)
7360 complaint (&symfile_complaints
,
7361 _("ignoring absolute DW_AT_sibling"));
7364 unsigned int off
= dwarf2_get_ref_die_offset (&attr
).sect_off
;
7365 const gdb_byte
*sibling_ptr
= buffer
+ off
;
7367 if (sibling_ptr
< info_ptr
)
7368 complaint (&symfile_complaints
,
7369 _("DW_AT_sibling points backwards"));
7370 else if (sibling_ptr
> reader
->buffer_end
)
7371 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
7377 /* If it isn't DW_AT_sibling, skip this attribute. */
7378 form
= abbrev
->attrs
[i
].form
;
7382 case DW_FORM_ref_addr
:
7383 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
7384 and later it is offset sized. */
7385 if (cu
->header
.version
== 2)
7386 info_ptr
+= cu
->header
.addr_size
;
7388 info_ptr
+= cu
->header
.offset_size
;
7390 case DW_FORM_GNU_ref_alt
:
7391 info_ptr
+= cu
->header
.offset_size
;
7394 info_ptr
+= cu
->header
.addr_size
;
7401 case DW_FORM_flag_present
:
7402 case DW_FORM_implicit_const
:
7414 case DW_FORM_ref_sig8
:
7417 case DW_FORM_string
:
7418 read_direct_string (abfd
, info_ptr
, &bytes_read
);
7419 info_ptr
+= bytes_read
;
7421 case DW_FORM_sec_offset
:
7423 case DW_FORM_GNU_strp_alt
:
7424 info_ptr
+= cu
->header
.offset_size
;
7426 case DW_FORM_exprloc
:
7428 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7429 info_ptr
+= bytes_read
;
7431 case DW_FORM_block1
:
7432 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
7434 case DW_FORM_block2
:
7435 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
7437 case DW_FORM_block4
:
7438 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
7442 case DW_FORM_ref_udata
:
7443 case DW_FORM_GNU_addr_index
:
7444 case DW_FORM_GNU_str_index
:
7445 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
7447 case DW_FORM_indirect
:
7448 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7449 info_ptr
+= bytes_read
;
7450 /* We need to continue parsing from here, so just go back to
7452 goto skip_attribute
;
7455 error (_("Dwarf Error: Cannot handle %s "
7456 "in DWARF reader [in module %s]"),
7457 dwarf_form_name (form
),
7458 bfd_get_filename (abfd
));
7462 if (abbrev
->has_children
)
7463 return skip_children (reader
, info_ptr
);
7468 /* Locate ORIG_PDI's sibling.
7469 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
7471 static const gdb_byte
*
7472 locate_pdi_sibling (const struct die_reader_specs
*reader
,
7473 struct partial_die_info
*orig_pdi
,
7474 const gdb_byte
*info_ptr
)
7476 /* Do we know the sibling already? */
7478 if (orig_pdi
->sibling
)
7479 return orig_pdi
->sibling
;
7481 /* Are there any children to deal with? */
7483 if (!orig_pdi
->has_children
)
7486 /* Skip the children the long way. */
7488 return skip_children (reader
, info_ptr
);
7491 /* Expand this partial symbol table into a full symbol table. SELF is
7495 dwarf2_read_symtab (struct partial_symtab
*self
,
7496 struct objfile
*objfile
)
7500 warning (_("bug: psymtab for %s is already read in."),
7507 printf_filtered (_("Reading in symbols for %s..."),
7509 gdb_flush (gdb_stdout
);
7512 /* Restore our global data. */
7514 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
7515 dwarf2_objfile_data_key
);
7517 /* If this psymtab is constructed from a debug-only objfile, the
7518 has_section_at_zero flag will not necessarily be correct. We
7519 can get the correct value for this flag by looking at the data
7520 associated with the (presumably stripped) associated objfile. */
7521 if (objfile
->separate_debug_objfile_backlink
)
7523 struct dwarf2_per_objfile
*dpo_backlink
7524 = ((struct dwarf2_per_objfile
*)
7525 objfile_data (objfile
->separate_debug_objfile_backlink
,
7526 dwarf2_objfile_data_key
));
7528 dwarf2_per_objfile
->has_section_at_zero
7529 = dpo_backlink
->has_section_at_zero
;
7532 dwarf2_per_objfile
->reading_partial_symbols
= 0;
7534 psymtab_to_symtab_1 (self
);
7536 /* Finish up the debug error message. */
7538 printf_filtered (_("done.\n"));
7541 process_cu_includes ();
7544 /* Reading in full CUs. */
7546 /* Add PER_CU to the queue. */
7549 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
7550 enum language pretend_language
)
7552 struct dwarf2_queue_item
*item
;
7555 item
= XNEW (struct dwarf2_queue_item
);
7556 item
->per_cu
= per_cu
;
7557 item
->pretend_language
= pretend_language
;
7560 if (dwarf2_queue
== NULL
)
7561 dwarf2_queue
= item
;
7563 dwarf2_queue_tail
->next
= item
;
7565 dwarf2_queue_tail
= item
;
7568 /* If PER_CU is not yet queued, add it to the queue.
7569 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
7571 The result is non-zero if PER_CU was queued, otherwise the result is zero
7572 meaning either PER_CU is already queued or it is already loaded.
7574 N.B. There is an invariant here that if a CU is queued then it is loaded.
7575 The caller is required to load PER_CU if we return non-zero. */
7578 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
7579 struct dwarf2_per_cu_data
*per_cu
,
7580 enum language pretend_language
)
7582 /* We may arrive here during partial symbol reading, if we need full
7583 DIEs to process an unusual case (e.g. template arguments). Do
7584 not queue PER_CU, just tell our caller to load its DIEs. */
7585 if (dwarf2_per_objfile
->reading_partial_symbols
)
7587 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
7592 /* Mark the dependence relation so that we don't flush PER_CU
7594 if (dependent_cu
!= NULL
)
7595 dwarf2_add_dependence (dependent_cu
, per_cu
);
7597 /* If it's already on the queue, we have nothing to do. */
7601 /* If the compilation unit is already loaded, just mark it as
7603 if (per_cu
->cu
!= NULL
)
7605 per_cu
->cu
->last_used
= 0;
7609 /* Add it to the queue. */
7610 queue_comp_unit (per_cu
, pretend_language
);
7615 /* Process the queue. */
7618 process_queue (void)
7620 struct dwarf2_queue_item
*item
, *next_item
;
7622 if (dwarf_read_debug
)
7624 fprintf_unfiltered (gdb_stdlog
,
7625 "Expanding one or more symtabs of objfile %s ...\n",
7626 objfile_name (dwarf2_per_objfile
->objfile
));
7629 /* The queue starts out with one item, but following a DIE reference
7630 may load a new CU, adding it to the end of the queue. */
7631 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
7633 if ((dwarf2_per_objfile
->using_index
7634 ? !item
->per_cu
->v
.quick
->compunit_symtab
7635 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
7636 /* Skip dummy CUs. */
7637 && item
->per_cu
->cu
!= NULL
)
7639 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
7640 unsigned int debug_print_threshold
;
7643 if (per_cu
->is_debug_types
)
7645 struct signatured_type
*sig_type
=
7646 (struct signatured_type
*) per_cu
;
7648 sprintf (buf
, "TU %s at offset 0x%x",
7649 hex_string (sig_type
->signature
),
7650 per_cu
->offset
.sect_off
);
7651 /* There can be 100s of TUs.
7652 Only print them in verbose mode. */
7653 debug_print_threshold
= 2;
7657 sprintf (buf
, "CU at offset 0x%x", per_cu
->offset
.sect_off
);
7658 debug_print_threshold
= 1;
7661 if (dwarf_read_debug
>= debug_print_threshold
)
7662 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
7664 if (per_cu
->is_debug_types
)
7665 process_full_type_unit (per_cu
, item
->pretend_language
);
7667 process_full_comp_unit (per_cu
, item
->pretend_language
);
7669 if (dwarf_read_debug
>= debug_print_threshold
)
7670 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
7673 item
->per_cu
->queued
= 0;
7674 next_item
= item
->next
;
7678 dwarf2_queue_tail
= NULL
;
7680 if (dwarf_read_debug
)
7682 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
7683 objfile_name (dwarf2_per_objfile
->objfile
));
7687 /* Free all allocated queue entries. This function only releases anything if
7688 an error was thrown; if the queue was processed then it would have been
7689 freed as we went along. */
7692 dwarf2_release_queue (void *dummy
)
7694 struct dwarf2_queue_item
*item
, *last
;
7696 item
= dwarf2_queue
;
7699 /* Anything still marked queued is likely to be in an
7700 inconsistent state, so discard it. */
7701 if (item
->per_cu
->queued
)
7703 if (item
->per_cu
->cu
!= NULL
)
7704 free_one_cached_comp_unit (item
->per_cu
);
7705 item
->per_cu
->queued
= 0;
7713 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
7716 /* Read in full symbols for PST, and anything it depends on. */
7719 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
7721 struct dwarf2_per_cu_data
*per_cu
;
7727 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
7728 if (!pst
->dependencies
[i
]->readin
7729 && pst
->dependencies
[i
]->user
== NULL
)
7731 /* Inform about additional files that need to be read in. */
7734 /* FIXME: i18n: Need to make this a single string. */
7735 fputs_filtered (" ", gdb_stdout
);
7737 fputs_filtered ("and ", gdb_stdout
);
7739 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
7740 wrap_here (""); /* Flush output. */
7741 gdb_flush (gdb_stdout
);
7743 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
7746 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
7750 /* It's an include file, no symbols to read for it.
7751 Everything is in the parent symtab. */
7756 dw2_do_instantiate_symtab (per_cu
);
7759 /* Trivial hash function for die_info: the hash value of a DIE
7760 is its offset in .debug_info for this objfile. */
7763 die_hash (const void *item
)
7765 const struct die_info
*die
= (const struct die_info
*) item
;
7767 return die
->offset
.sect_off
;
7770 /* Trivial comparison function for die_info structures: two DIEs
7771 are equal if they have the same offset. */
7774 die_eq (const void *item_lhs
, const void *item_rhs
)
7776 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
7777 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
7779 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
7782 /* die_reader_func for load_full_comp_unit.
7783 This is identical to read_signatured_type_reader,
7784 but is kept separate for now. */
7787 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
7788 const gdb_byte
*info_ptr
,
7789 struct die_info
*comp_unit_die
,
7793 struct dwarf2_cu
*cu
= reader
->cu
;
7794 enum language
*language_ptr
= (enum language
*) data
;
7796 gdb_assert (cu
->die_hash
== NULL
);
7798 htab_create_alloc_ex (cu
->header
.length
/ 12,
7802 &cu
->comp_unit_obstack
,
7803 hashtab_obstack_allocate
,
7804 dummy_obstack_deallocate
);
7807 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
7808 &info_ptr
, comp_unit_die
);
7809 cu
->dies
= comp_unit_die
;
7810 /* comp_unit_die is not stored in die_hash, no need. */
7812 /* We try not to read any attributes in this function, because not
7813 all CUs needed for references have been loaded yet, and symbol
7814 table processing isn't initialized. But we have to set the CU language,
7815 or we won't be able to build types correctly.
7816 Similarly, if we do not read the producer, we can not apply
7817 producer-specific interpretation. */
7818 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
7821 /* Load the DIEs associated with PER_CU into memory. */
7824 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7825 enum language pretend_language
)
7827 gdb_assert (! this_cu
->is_debug_types
);
7829 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
7830 load_full_comp_unit_reader
, &pretend_language
);
7833 /* Add a DIE to the delayed physname list. */
7836 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
7837 const char *name
, struct die_info
*die
,
7838 struct dwarf2_cu
*cu
)
7840 struct delayed_method_info mi
;
7842 mi
.fnfield_index
= fnfield_index
;
7846 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
7849 /* A cleanup for freeing the delayed method list. */
7852 free_delayed_list (void *ptr
)
7854 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
7855 if (cu
->method_list
!= NULL
)
7857 VEC_free (delayed_method_info
, cu
->method_list
);
7858 cu
->method_list
= NULL
;
7862 /* Compute the physnames of any methods on the CU's method list.
7864 The computation of method physnames is delayed in order to avoid the
7865 (bad) condition that one of the method's formal parameters is of an as yet
7869 compute_delayed_physnames (struct dwarf2_cu
*cu
)
7872 struct delayed_method_info
*mi
;
7873 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
7875 const char *physname
;
7876 struct fn_fieldlist
*fn_flp
7877 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
7878 physname
= dwarf2_physname (mi
->name
, mi
->die
, cu
);
7879 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
->index
)
7880 = physname
? physname
: "";
7884 /* Go objects should be embedded in a DW_TAG_module DIE,
7885 and it's not clear if/how imported objects will appear.
7886 To keep Go support simple until that's worked out,
7887 go back through what we've read and create something usable.
7888 We could do this while processing each DIE, and feels kinda cleaner,
7889 but that way is more invasive.
7890 This is to, for example, allow the user to type "p var" or "b main"
7891 without having to specify the package name, and allow lookups
7892 of module.object to work in contexts that use the expression
7896 fixup_go_packaging (struct dwarf2_cu
*cu
)
7898 char *package_name
= NULL
;
7899 struct pending
*list
;
7902 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
7904 for (i
= 0; i
< list
->nsyms
; ++i
)
7906 struct symbol
*sym
= list
->symbol
[i
];
7908 if (SYMBOL_LANGUAGE (sym
) == language_go
7909 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
7911 char *this_package_name
= go_symbol_package_name (sym
);
7913 if (this_package_name
== NULL
)
7915 if (package_name
== NULL
)
7916 package_name
= this_package_name
;
7919 if (strcmp (package_name
, this_package_name
) != 0)
7920 complaint (&symfile_complaints
,
7921 _("Symtab %s has objects from two different Go packages: %s and %s"),
7922 (symbol_symtab (sym
) != NULL
7923 ? symtab_to_filename_for_display
7924 (symbol_symtab (sym
))
7925 : objfile_name (cu
->objfile
)),
7926 this_package_name
, package_name
);
7927 xfree (this_package_name
);
7933 if (package_name
!= NULL
)
7935 struct objfile
*objfile
= cu
->objfile
;
7936 const char *saved_package_name
7937 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
7939 strlen (package_name
));
7940 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
7941 saved_package_name
);
7944 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7946 sym
= allocate_symbol (objfile
);
7947 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
7948 SYMBOL_SET_NAMES (sym
, saved_package_name
,
7949 strlen (saved_package_name
), 0, objfile
);
7950 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
7951 e.g., "main" finds the "main" module and not C's main(). */
7952 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7953 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
7954 SYMBOL_TYPE (sym
) = type
;
7956 add_symbol_to_list (sym
, &global_symbols
);
7958 xfree (package_name
);
7962 /* Return the symtab for PER_CU. This works properly regardless of
7963 whether we're using the index or psymtabs. */
7965 static struct compunit_symtab
*
7966 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
7968 return (dwarf2_per_objfile
->using_index
7969 ? per_cu
->v
.quick
->compunit_symtab
7970 : per_cu
->v
.psymtab
->compunit_symtab
);
7973 /* A helper function for computing the list of all symbol tables
7974 included by PER_CU. */
7977 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
7978 htab_t all_children
, htab_t all_type_symtabs
,
7979 struct dwarf2_per_cu_data
*per_cu
,
7980 struct compunit_symtab
*immediate_parent
)
7984 struct compunit_symtab
*cust
;
7985 struct dwarf2_per_cu_data
*iter
;
7987 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
7990 /* This inclusion and its children have been processed. */
7995 /* Only add a CU if it has a symbol table. */
7996 cust
= get_compunit_symtab (per_cu
);
7999 /* If this is a type unit only add its symbol table if we haven't
8000 seen it yet (type unit per_cu's can share symtabs). */
8001 if (per_cu
->is_debug_types
)
8003 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
8007 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
8008 if (cust
->user
== NULL
)
8009 cust
->user
= immediate_parent
;
8014 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
8015 if (cust
->user
== NULL
)
8016 cust
->user
= immediate_parent
;
8021 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
8024 recursively_compute_inclusions (result
, all_children
,
8025 all_type_symtabs
, iter
, cust
);
8029 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
8033 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
8035 gdb_assert (! per_cu
->is_debug_types
);
8037 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
8040 struct dwarf2_per_cu_data
*per_cu_iter
;
8041 struct compunit_symtab
*compunit_symtab_iter
;
8042 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
8043 htab_t all_children
, all_type_symtabs
;
8044 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
8046 /* If we don't have a symtab, we can just skip this case. */
8050 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
8051 NULL
, xcalloc
, xfree
);
8052 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
8053 NULL
, xcalloc
, xfree
);
8056 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
8060 recursively_compute_inclusions (&result_symtabs
, all_children
,
8061 all_type_symtabs
, per_cu_iter
,
8065 /* Now we have a transitive closure of all the included symtabs. */
8066 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
8068 = XOBNEWVEC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
8069 struct compunit_symtab
*, len
+ 1);
8071 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
8072 compunit_symtab_iter
);
8074 cust
->includes
[ix
] = compunit_symtab_iter
;
8075 cust
->includes
[len
] = NULL
;
8077 VEC_free (compunit_symtab_ptr
, result_symtabs
);
8078 htab_delete (all_children
);
8079 htab_delete (all_type_symtabs
);
8083 /* Compute the 'includes' field for the symtabs of all the CUs we just
8087 process_cu_includes (void)
8090 struct dwarf2_per_cu_data
*iter
;
8093 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
8097 if (! iter
->is_debug_types
)
8098 compute_compunit_symtab_includes (iter
);
8101 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
8104 /* Generate full symbol information for PER_CU, whose DIEs have
8105 already been loaded into memory. */
8108 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8109 enum language pretend_language
)
8111 struct dwarf2_cu
*cu
= per_cu
->cu
;
8112 struct objfile
*objfile
= per_cu
->objfile
;
8113 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8114 CORE_ADDR lowpc
, highpc
;
8115 struct compunit_symtab
*cust
;
8116 struct cleanup
*back_to
, *delayed_list_cleanup
;
8118 struct block
*static_block
;
8121 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8124 back_to
= make_cleanup (really_free_pendings
, NULL
);
8125 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8127 cu
->list_in_scope
= &file_symbols
;
8129 cu
->language
= pretend_language
;
8130 cu
->language_defn
= language_def (cu
->language
);
8132 /* Do line number decoding in read_file_scope () */
8133 process_die (cu
->dies
, cu
);
8135 /* For now fudge the Go package. */
8136 if (cu
->language
== language_go
)
8137 fixup_go_packaging (cu
);
8139 /* Now that we have processed all the DIEs in the CU, all the types
8140 should be complete, and it should now be safe to compute all of the
8142 compute_delayed_physnames (cu
);
8143 do_cleanups (delayed_list_cleanup
);
8145 /* Some compilers don't define a DW_AT_high_pc attribute for the
8146 compilation unit. If the DW_AT_high_pc is missing, synthesize
8147 it, by scanning the DIE's below the compilation unit. */
8148 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
8150 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
8151 static_block
= end_symtab_get_static_block (addr
, 0, 1);
8153 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
8154 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
8155 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
8156 addrmap to help ensure it has an accurate map of pc values belonging to
8158 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
8160 cust
= end_symtab_from_static_block (static_block
,
8161 SECT_OFF_TEXT (objfile
), 0);
8165 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
8167 /* Set symtab language to language from DW_AT_language. If the
8168 compilation is from a C file generated by language preprocessors, do
8169 not set the language if it was already deduced by start_subfile. */
8170 if (!(cu
->language
== language_c
8171 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
8172 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8174 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
8175 produce DW_AT_location with location lists but it can be possibly
8176 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
8177 there were bugs in prologue debug info, fixed later in GCC-4.5
8178 by "unwind info for epilogues" patch (which is not directly related).
8180 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
8181 needed, it would be wrong due to missing DW_AT_producer there.
8183 Still one can confuse GDB by using non-standard GCC compilation
8184 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
8186 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
8187 cust
->locations_valid
= 1;
8189 if (gcc_4_minor
>= 5)
8190 cust
->epilogue_unwind_valid
= 1;
8192 cust
->call_site_htab
= cu
->call_site_htab
;
8195 if (dwarf2_per_objfile
->using_index
)
8196 per_cu
->v
.quick
->compunit_symtab
= cust
;
8199 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8200 pst
->compunit_symtab
= cust
;
8204 /* Push it for inclusion processing later. */
8205 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
8207 do_cleanups (back_to
);
8210 /* Generate full symbol information for type unit PER_CU, whose DIEs have
8211 already been loaded into memory. */
8214 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
8215 enum language pretend_language
)
8217 struct dwarf2_cu
*cu
= per_cu
->cu
;
8218 struct objfile
*objfile
= per_cu
->objfile
;
8219 struct compunit_symtab
*cust
;
8220 struct cleanup
*back_to
, *delayed_list_cleanup
;
8221 struct signatured_type
*sig_type
;
8223 gdb_assert (per_cu
->is_debug_types
);
8224 sig_type
= (struct signatured_type
*) per_cu
;
8227 back_to
= make_cleanup (really_free_pendings
, NULL
);
8228 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8230 cu
->list_in_scope
= &file_symbols
;
8232 cu
->language
= pretend_language
;
8233 cu
->language_defn
= language_def (cu
->language
);
8235 /* The symbol tables are set up in read_type_unit_scope. */
8236 process_die (cu
->dies
, cu
);
8238 /* For now fudge the Go package. */
8239 if (cu
->language
== language_go
)
8240 fixup_go_packaging (cu
);
8242 /* Now that we have processed all the DIEs in the CU, all the types
8243 should be complete, and it should now be safe to compute all of the
8245 compute_delayed_physnames (cu
);
8246 do_cleanups (delayed_list_cleanup
);
8248 /* TUs share symbol tables.
8249 If this is the first TU to use this symtab, complete the construction
8250 of it with end_expandable_symtab. Otherwise, complete the addition of
8251 this TU's symbols to the existing symtab. */
8252 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
8254 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
8255 sig_type
->type_unit_group
->compunit_symtab
= cust
;
8259 /* Set symtab language to language from DW_AT_language. If the
8260 compilation is from a C file generated by language preprocessors,
8261 do not set the language if it was already deduced by
8263 if (!(cu
->language
== language_c
8264 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
8265 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8270 augment_type_symtab ();
8271 cust
= sig_type
->type_unit_group
->compunit_symtab
;
8274 if (dwarf2_per_objfile
->using_index
)
8275 per_cu
->v
.quick
->compunit_symtab
= cust
;
8278 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8279 pst
->compunit_symtab
= cust
;
8283 do_cleanups (back_to
);
8286 /* Process an imported unit DIE. */
8289 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8291 struct attribute
*attr
;
8293 /* For now we don't handle imported units in type units. */
8294 if (cu
->per_cu
->is_debug_types
)
8296 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8297 " supported in type units [in module %s]"),
8298 objfile_name (cu
->objfile
));
8301 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8304 struct dwarf2_per_cu_data
*per_cu
;
8308 offset
= dwarf2_get_ref_die_offset (attr
);
8309 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
8310 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
8312 /* If necessary, add it to the queue and load its DIEs. */
8313 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
8314 load_full_comp_unit (per_cu
, cu
->language
);
8316 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8321 /* Reset the in_process bit of a die. */
8324 reset_die_in_process (void *arg
)
8326 struct die_info
*die
= (struct die_info
*) arg
;
8328 die
->in_process
= 0;
8331 /* Process a die and its children. */
8334 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8336 struct cleanup
*in_process
;
8338 /* We should only be processing those not already in process. */
8339 gdb_assert (!die
->in_process
);
8341 die
->in_process
= 1;
8342 in_process
= make_cleanup (reset_die_in_process
,die
);
8346 case DW_TAG_padding
:
8348 case DW_TAG_compile_unit
:
8349 case DW_TAG_partial_unit
:
8350 read_file_scope (die
, cu
);
8352 case DW_TAG_type_unit
:
8353 read_type_unit_scope (die
, cu
);
8355 case DW_TAG_subprogram
:
8356 case DW_TAG_inlined_subroutine
:
8357 read_func_scope (die
, cu
);
8359 case DW_TAG_lexical_block
:
8360 case DW_TAG_try_block
:
8361 case DW_TAG_catch_block
:
8362 read_lexical_block_scope (die
, cu
);
8364 case DW_TAG_GNU_call_site
:
8365 read_call_site_scope (die
, cu
);
8367 case DW_TAG_class_type
:
8368 case DW_TAG_interface_type
:
8369 case DW_TAG_structure_type
:
8370 case DW_TAG_union_type
:
8371 process_structure_scope (die
, cu
);
8373 case DW_TAG_enumeration_type
:
8374 process_enumeration_scope (die
, cu
);
8377 /* These dies have a type, but processing them does not create
8378 a symbol or recurse to process the children. Therefore we can
8379 read them on-demand through read_type_die. */
8380 case DW_TAG_subroutine_type
:
8381 case DW_TAG_set_type
:
8382 case DW_TAG_array_type
:
8383 case DW_TAG_pointer_type
:
8384 case DW_TAG_ptr_to_member_type
:
8385 case DW_TAG_reference_type
:
8386 case DW_TAG_string_type
:
8389 case DW_TAG_base_type
:
8390 case DW_TAG_subrange_type
:
8391 case DW_TAG_typedef
:
8392 /* Add a typedef symbol for the type definition, if it has a
8394 new_symbol (die
, read_type_die (die
, cu
), cu
);
8396 case DW_TAG_common_block
:
8397 read_common_block (die
, cu
);
8399 case DW_TAG_common_inclusion
:
8401 case DW_TAG_namespace
:
8402 cu
->processing_has_namespace_info
= 1;
8403 read_namespace (die
, cu
);
8406 cu
->processing_has_namespace_info
= 1;
8407 read_module (die
, cu
);
8409 case DW_TAG_imported_declaration
:
8410 cu
->processing_has_namespace_info
= 1;
8411 if (read_namespace_alias (die
, cu
))
8413 /* The declaration is not a global namespace alias: fall through. */
8414 case DW_TAG_imported_module
:
8415 cu
->processing_has_namespace_info
= 1;
8416 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
8417 || cu
->language
!= language_fortran
))
8418 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
8419 dwarf_tag_name (die
->tag
));
8420 read_import_statement (die
, cu
);
8423 case DW_TAG_imported_unit
:
8424 process_imported_unit_die (die
, cu
);
8428 new_symbol (die
, NULL
, cu
);
8432 do_cleanups (in_process
);
8435 /* DWARF name computation. */
8437 /* A helper function for dwarf2_compute_name which determines whether DIE
8438 needs to have the name of the scope prepended to the name listed in the
8442 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8444 struct attribute
*attr
;
8448 case DW_TAG_namespace
:
8449 case DW_TAG_typedef
:
8450 case DW_TAG_class_type
:
8451 case DW_TAG_interface_type
:
8452 case DW_TAG_structure_type
:
8453 case DW_TAG_union_type
:
8454 case DW_TAG_enumeration_type
:
8455 case DW_TAG_enumerator
:
8456 case DW_TAG_subprogram
:
8457 case DW_TAG_inlined_subroutine
:
8459 case DW_TAG_imported_declaration
:
8462 case DW_TAG_variable
:
8463 case DW_TAG_constant
:
8464 /* We only need to prefix "globally" visible variables. These include
8465 any variable marked with DW_AT_external or any variable that
8466 lives in a namespace. [Variables in anonymous namespaces
8467 require prefixing, but they are not DW_AT_external.] */
8469 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
8471 struct dwarf2_cu
*spec_cu
= cu
;
8473 return die_needs_namespace (die_specification (die
, &spec_cu
),
8477 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8478 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
8479 && die
->parent
->tag
!= DW_TAG_module
)
8481 /* A variable in a lexical block of some kind does not need a
8482 namespace, even though in C++ such variables may be external
8483 and have a mangled name. */
8484 if (die
->parent
->tag
== DW_TAG_lexical_block
8485 || die
->parent
->tag
== DW_TAG_try_block
8486 || die
->parent
->tag
== DW_TAG_catch_block
8487 || die
->parent
->tag
== DW_TAG_subprogram
)
8496 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
8497 compute the physname for the object, which include a method's:
8498 - formal parameters (C++),
8499 - receiver type (Go),
8501 The term "physname" is a bit confusing.
8502 For C++, for example, it is the demangled name.
8503 For Go, for example, it's the mangled name.
8505 For Ada, return the DIE's linkage name rather than the fully qualified
8506 name. PHYSNAME is ignored..
8508 The result is allocated on the objfile_obstack and canonicalized. */
8511 dwarf2_compute_name (const char *name
,
8512 struct die_info
*die
, struct dwarf2_cu
*cu
,
8515 struct objfile
*objfile
= cu
->objfile
;
8518 name
= dwarf2_name (die
, cu
);
8520 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
8521 but otherwise compute it by typename_concat inside GDB.
8522 FIXME: Actually this is not really true, or at least not always true.
8523 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
8524 Fortran names because there is no mangling standard. So new_symbol_full
8525 will set the demangled name to the result of dwarf2_full_name, and it is
8526 the demangled name that GDB uses if it exists. */
8527 if (cu
->language
== language_ada
8528 || (cu
->language
== language_fortran
&& physname
))
8530 /* For Ada unit, we prefer the linkage name over the name, as
8531 the former contains the exported name, which the user expects
8532 to be able to reference. Ideally, we want the user to be able
8533 to reference this entity using either natural or linkage name,
8534 but we haven't started looking at this enhancement yet. */
8535 const char *linkage_name
;
8537 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
8538 if (linkage_name
== NULL
)
8539 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8540 if (linkage_name
!= NULL
)
8541 return linkage_name
;
8544 /* These are the only languages we know how to qualify names in. */
8546 && (cu
->language
== language_cplus
8547 || cu
->language
== language_fortran
|| cu
->language
== language_d
8548 || cu
->language
== language_rust
))
8550 if (die_needs_namespace (die
, cu
))
8554 const char *canonical_name
= NULL
;
8558 prefix
= determine_prefix (die
, cu
);
8559 if (*prefix
!= '\0')
8561 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
8564 buf
.puts (prefixed_name
);
8565 xfree (prefixed_name
);
8570 /* Template parameters may be specified in the DIE's DW_AT_name, or
8571 as children with DW_TAG_template_type_param or
8572 DW_TAG_value_type_param. If the latter, add them to the name
8573 here. If the name already has template parameters, then
8574 skip this step; some versions of GCC emit both, and
8575 it is more efficient to use the pre-computed name.
8577 Something to keep in mind about this process: it is very
8578 unlikely, or in some cases downright impossible, to produce
8579 something that will match the mangled name of a function.
8580 If the definition of the function has the same debug info,
8581 we should be able to match up with it anyway. But fallbacks
8582 using the minimal symbol, for instance to find a method
8583 implemented in a stripped copy of libstdc++, will not work.
8584 If we do not have debug info for the definition, we will have to
8585 match them up some other way.
8587 When we do name matching there is a related problem with function
8588 templates; two instantiated function templates are allowed to
8589 differ only by their return types, which we do not add here. */
8591 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
8593 struct attribute
*attr
;
8594 struct die_info
*child
;
8597 die
->building_fullname
= 1;
8599 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
8603 const gdb_byte
*bytes
;
8604 struct dwarf2_locexpr_baton
*baton
;
8607 if (child
->tag
!= DW_TAG_template_type_param
8608 && child
->tag
!= DW_TAG_template_value_param
)
8619 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
8622 complaint (&symfile_complaints
,
8623 _("template parameter missing DW_AT_type"));
8624 buf
.puts ("UNKNOWN_TYPE");
8627 type
= die_type (child
, cu
);
8629 if (child
->tag
== DW_TAG_template_type_param
)
8631 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
8635 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
8638 complaint (&symfile_complaints
,
8639 _("template parameter missing "
8640 "DW_AT_const_value"));
8641 buf
.puts ("UNKNOWN_VALUE");
8645 dwarf2_const_value_attr (attr
, type
, name
,
8646 &cu
->comp_unit_obstack
, cu
,
8647 &value
, &bytes
, &baton
);
8649 if (TYPE_NOSIGN (type
))
8650 /* GDB prints characters as NUMBER 'CHAR'. If that's
8651 changed, this can use value_print instead. */
8652 c_printchar (value
, type
, &buf
);
8655 struct value_print_options opts
;
8658 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
8662 else if (bytes
!= NULL
)
8664 v
= allocate_value (type
);
8665 memcpy (value_contents_writeable (v
), bytes
,
8666 TYPE_LENGTH (type
));
8669 v
= value_from_longest (type
, value
);
8671 /* Specify decimal so that we do not depend on
8673 get_formatted_print_options (&opts
, 'd');
8675 value_print (v
, &buf
, &opts
);
8681 die
->building_fullname
= 0;
8685 /* Close the argument list, with a space if necessary
8686 (nested templates). */
8687 if (!buf
.empty () && buf
.string ().back () == '>')
8694 /* For C++ methods, append formal parameter type
8695 information, if PHYSNAME. */
8697 if (physname
&& die
->tag
== DW_TAG_subprogram
8698 && cu
->language
== language_cplus
)
8700 struct type
*type
= read_type_die (die
, cu
);
8702 c_type_print_args (type
, &buf
, 1, cu
->language
,
8703 &type_print_raw_options
);
8705 if (cu
->language
== language_cplus
)
8707 /* Assume that an artificial first parameter is
8708 "this", but do not crash if it is not. RealView
8709 marks unnamed (and thus unused) parameters as
8710 artificial; there is no way to differentiate
8712 if (TYPE_NFIELDS (type
) > 0
8713 && TYPE_FIELD_ARTIFICIAL (type
, 0)
8714 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
8715 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
8717 buf
.puts (" const");
8721 const std::string
&intermediate_name
= buf
.string ();
8723 if (cu
->language
== language_cplus
)
8725 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
8726 &objfile
->per_bfd
->storage_obstack
);
8728 /* If we only computed INTERMEDIATE_NAME, or if
8729 INTERMEDIATE_NAME is already canonical, then we need to
8730 copy it to the appropriate obstack. */
8731 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
8732 name
= ((const char *)
8733 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8734 intermediate_name
.c_str (),
8735 intermediate_name
.length ()));
8737 name
= canonical_name
;
8744 /* Return the fully qualified name of DIE, based on its DW_AT_name.
8745 If scope qualifiers are appropriate they will be added. The result
8746 will be allocated on the storage_obstack, or NULL if the DIE does
8747 not have a name. NAME may either be from a previous call to
8748 dwarf2_name or NULL.
8750 The output string will be canonicalized (if C++). */
8753 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8755 return dwarf2_compute_name (name
, die
, cu
, 0);
8758 /* Construct a physname for the given DIE in CU. NAME may either be
8759 from a previous call to dwarf2_name or NULL. The result will be
8760 allocated on the objfile_objstack or NULL if the DIE does not have a
8763 The output string will be canonicalized (if C++). */
8766 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8768 struct objfile
*objfile
= cu
->objfile
;
8769 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
8770 struct cleanup
*back_to
;
8773 /* In this case dwarf2_compute_name is just a shortcut not building anything
8775 if (!die_needs_namespace (die
, cu
))
8776 return dwarf2_compute_name (name
, die
, cu
, 1);
8778 back_to
= make_cleanup (null_cleanup
, NULL
);
8780 mangled
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
8781 if (mangled
== NULL
)
8782 mangled
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8784 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
8785 See https://github.com/rust-lang/rust/issues/32925. */
8786 if (cu
->language
== language_rust
&& mangled
!= NULL
8787 && strchr (mangled
, '{') != NULL
)
8790 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
8792 if (mangled
!= NULL
)
8796 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
8797 type. It is easier for GDB users to search for such functions as
8798 `name(params)' than `long name(params)'. In such case the minimal
8799 symbol names do not match the full symbol names but for template
8800 functions there is never a need to look up their definition from their
8801 declaration so the only disadvantage remains the minimal symbol
8802 variant `long name(params)' does not have the proper inferior type.
8805 if (cu
->language
== language_go
)
8807 /* This is a lie, but we already lie to the caller new_symbol_full.
8808 new_symbol_full assumes we return the mangled name.
8809 This just undoes that lie until things are cleaned up. */
8814 demangled
= gdb_demangle (mangled
,
8815 (DMGL_PARAMS
| DMGL_ANSI
| DMGL_RET_DROP
));
8819 make_cleanup (xfree
, demangled
);
8829 if (canon
== NULL
|| check_physname
)
8831 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
8833 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
8835 /* It may not mean a bug in GDB. The compiler could also
8836 compute DW_AT_linkage_name incorrectly. But in such case
8837 GDB would need to be bug-to-bug compatible. */
8839 complaint (&symfile_complaints
,
8840 _("Computed physname <%s> does not match demangled <%s> "
8841 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
8842 physname
, canon
, mangled
, die
->offset
.sect_off
,
8843 objfile_name (objfile
));
8845 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
8846 is available here - over computed PHYSNAME. It is safer
8847 against both buggy GDB and buggy compilers. */
8861 retval
= ((const char *)
8862 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8863 retval
, strlen (retval
)));
8865 do_cleanups (back_to
);
8869 /* Inspect DIE in CU for a namespace alias. If one exists, record
8870 a new symbol for it.
8872 Returns 1 if a namespace alias was recorded, 0 otherwise. */
8875 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
8877 struct attribute
*attr
;
8879 /* If the die does not have a name, this is not a namespace
8881 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8885 struct die_info
*d
= die
;
8886 struct dwarf2_cu
*imported_cu
= cu
;
8888 /* If the compiler has nested DW_AT_imported_declaration DIEs,
8889 keep inspecting DIEs until we hit the underlying import. */
8890 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
8891 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
8893 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
8897 d
= follow_die_ref (d
, attr
, &imported_cu
);
8898 if (d
->tag
!= DW_TAG_imported_declaration
)
8902 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
8904 complaint (&symfile_complaints
,
8905 _("DIE at 0x%x has too many recursively imported "
8906 "declarations"), d
->offset
.sect_off
);
8913 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
8915 type
= get_die_type_at_offset (offset
, cu
->per_cu
);
8916 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
8918 /* This declaration is a global namespace alias. Add
8919 a symbol for it whose type is the aliased namespace. */
8920 new_symbol (die
, type
, cu
);
8929 /* Return the using directives repository (global or local?) to use in the
8930 current context for LANGUAGE.
8932 For Ada, imported declarations can materialize renamings, which *may* be
8933 global. However it is impossible (for now?) in DWARF to distinguish
8934 "external" imported declarations and "static" ones. As all imported
8935 declarations seem to be static in all other languages, make them all CU-wide
8936 global only in Ada. */
8938 static struct using_direct
**
8939 using_directives (enum language language
)
8941 if (language
== language_ada
&& context_stack_depth
== 0)
8942 return &global_using_directives
;
8944 return &local_using_directives
;
8947 /* Read the import statement specified by the given die and record it. */
8950 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
8952 struct objfile
*objfile
= cu
->objfile
;
8953 struct attribute
*import_attr
;
8954 struct die_info
*imported_die
, *child_die
;
8955 struct dwarf2_cu
*imported_cu
;
8956 const char *imported_name
;
8957 const char *imported_name_prefix
;
8958 const char *canonical_name
;
8959 const char *import_alias
;
8960 const char *imported_declaration
= NULL
;
8961 const char *import_prefix
;
8962 VEC (const_char_ptr
) *excludes
= NULL
;
8963 struct cleanup
*cleanups
;
8965 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8966 if (import_attr
== NULL
)
8968 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
8969 dwarf_tag_name (die
->tag
));
8974 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
8975 imported_name
= dwarf2_name (imported_die
, imported_cu
);
8976 if (imported_name
== NULL
)
8978 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
8980 The import in the following code:
8994 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
8995 <52> DW_AT_decl_file : 1
8996 <53> DW_AT_decl_line : 6
8997 <54> DW_AT_import : <0x75>
8998 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
9000 <5b> DW_AT_decl_file : 1
9001 <5c> DW_AT_decl_line : 2
9002 <5d> DW_AT_type : <0x6e>
9004 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
9005 <76> DW_AT_byte_size : 4
9006 <77> DW_AT_encoding : 5 (signed)
9008 imports the wrong die ( 0x75 instead of 0x58 ).
9009 This case will be ignored until the gcc bug is fixed. */
9013 /* Figure out the local name after import. */
9014 import_alias
= dwarf2_name (die
, cu
);
9016 /* Figure out where the statement is being imported to. */
9017 import_prefix
= determine_prefix (die
, cu
);
9019 /* Figure out what the scope of the imported die is and prepend it
9020 to the name of the imported die. */
9021 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
9023 if (imported_die
->tag
!= DW_TAG_namespace
9024 && imported_die
->tag
!= DW_TAG_module
)
9026 imported_declaration
= imported_name
;
9027 canonical_name
= imported_name_prefix
;
9029 else if (strlen (imported_name_prefix
) > 0)
9030 canonical_name
= obconcat (&objfile
->objfile_obstack
,
9031 imported_name_prefix
,
9032 (cu
->language
== language_d
? "." : "::"),
9033 imported_name
, (char *) NULL
);
9035 canonical_name
= imported_name
;
9037 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
9039 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
9040 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
9041 child_die
= sibling_die (child_die
))
9043 /* DWARF-4: A Fortran use statement with a “rename list” may be
9044 represented by an imported module entry with an import attribute
9045 referring to the module and owned entries corresponding to those
9046 entities that are renamed as part of being imported. */
9048 if (child_die
->tag
!= DW_TAG_imported_declaration
)
9050 complaint (&symfile_complaints
,
9051 _("child DW_TAG_imported_declaration expected "
9052 "- DIE at 0x%x [in module %s]"),
9053 child_die
->offset
.sect_off
, objfile_name (objfile
));
9057 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
9058 if (import_attr
== NULL
)
9060 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
9061 dwarf_tag_name (child_die
->tag
));
9066 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
9068 imported_name
= dwarf2_name (imported_die
, imported_cu
);
9069 if (imported_name
== NULL
)
9071 complaint (&symfile_complaints
,
9072 _("child DW_TAG_imported_declaration has unknown "
9073 "imported name - DIE at 0x%x [in module %s]"),
9074 child_die
->offset
.sect_off
, objfile_name (objfile
));
9078 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
9080 process_die (child_die
, cu
);
9083 add_using_directive (using_directives (cu
->language
),
9087 imported_declaration
,
9090 &objfile
->objfile_obstack
);
9092 do_cleanups (cleanups
);
9095 /* Cleanup function for handle_DW_AT_stmt_list. */
9098 free_cu_line_header (void *arg
)
9100 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) arg
;
9102 free_line_header (cu
->line_header
);
9103 cu
->line_header
= NULL
;
9106 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
9107 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
9108 this, it was first present in GCC release 4.3.0. */
9111 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
9113 if (!cu
->checked_producer
)
9114 check_producer (cu
);
9116 return cu
->producer_is_gcc_lt_4_3
;
9120 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
9121 const char **name
, const char **comp_dir
)
9123 /* Find the filename. Do not use dwarf2_name here, since the filename
9124 is not a source language identifier. */
9125 *name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
9126 *comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
9128 if (*comp_dir
== NULL
9129 && producer_is_gcc_lt_4_3 (cu
) && *name
!= NULL
9130 && IS_ABSOLUTE_PATH (*name
))
9132 char *d
= ldirname (*name
);
9136 make_cleanup (xfree
, d
);
9138 if (*comp_dir
!= NULL
)
9140 /* Irix 6.2 native cc prepends <machine>.: to the compilation
9141 directory, get rid of it. */
9142 const char *cp
= strchr (*comp_dir
, ':');
9144 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
9149 *name
= "<unknown>";
9152 /* Handle DW_AT_stmt_list for a compilation unit.
9153 DIE is the DW_TAG_compile_unit die for CU.
9154 COMP_DIR is the compilation directory. LOWPC is passed to
9155 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
9158 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
9159 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
9161 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9162 struct attribute
*attr
;
9163 unsigned int line_offset
;
9164 struct line_header line_header_local
;
9165 hashval_t line_header_local_hash
;
9170 gdb_assert (! cu
->per_cu
->is_debug_types
);
9172 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9176 line_offset
= DW_UNSND (attr
);
9178 /* The line header hash table is only created if needed (it exists to
9179 prevent redundant reading of the line table for partial_units).
9180 If we're given a partial_unit, we'll need it. If we're given a
9181 compile_unit, then use the line header hash table if it's already
9182 created, but don't create one just yet. */
9184 if (dwarf2_per_objfile
->line_header_hash
== NULL
9185 && die
->tag
== DW_TAG_partial_unit
)
9187 dwarf2_per_objfile
->line_header_hash
9188 = htab_create_alloc_ex (127, line_header_hash_voidp
,
9189 line_header_eq_voidp
,
9190 free_line_header_voidp
,
9191 &objfile
->objfile_obstack
,
9192 hashtab_obstack_allocate
,
9193 dummy_obstack_deallocate
);
9196 line_header_local
.offset
.sect_off
= line_offset
;
9197 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
9198 line_header_local_hash
= line_header_hash (&line_header_local
);
9199 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
9201 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9203 line_header_local_hash
, NO_INSERT
);
9205 /* For DW_TAG_compile_unit we need info like symtab::linetable which
9206 is not present in *SLOT (since if there is something in *SLOT then
9207 it will be for a partial_unit). */
9208 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
9210 gdb_assert (*slot
!= NULL
);
9211 cu
->line_header
= (struct line_header
*) *slot
;
9216 /* dwarf_decode_line_header does not yet provide sufficient information.
9217 We always have to call also dwarf_decode_lines for it. */
9218 cu
->line_header
= dwarf_decode_line_header (line_offset
, cu
);
9219 if (cu
->line_header
== NULL
)
9222 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
9226 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9228 line_header_local_hash
, INSERT
);
9229 gdb_assert (slot
!= NULL
);
9231 if (slot
!= NULL
&& *slot
== NULL
)
9233 /* This newly decoded line number information unit will be owned
9234 by line_header_hash hash table. */
9235 *slot
= cu
->line_header
;
9239 /* We cannot free any current entry in (*slot) as that struct line_header
9240 may be already used by multiple CUs. Create only temporary decoded
9241 line_header for this CU - it may happen at most once for each line
9242 number information unit. And if we're not using line_header_hash
9243 then this is what we want as well. */
9244 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
9245 make_cleanup (free_cu_line_header
, cu
);
9247 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
9248 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
9252 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
9255 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9257 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9258 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9259 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
9260 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
9261 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
9262 struct attribute
*attr
;
9263 const char *name
= NULL
;
9264 const char *comp_dir
= NULL
;
9265 struct die_info
*child_die
;
9268 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9270 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
9272 /* If we didn't find a lowpc, set it to highpc to avoid complaints
9273 from finish_block. */
9274 if (lowpc
== ((CORE_ADDR
) -1))
9276 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
9278 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
9280 prepare_one_comp_unit (cu
, die
, cu
->language
);
9282 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
9283 standardised yet. As a workaround for the language detection we fall
9284 back to the DW_AT_producer string. */
9285 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
9286 cu
->language
= language_opencl
;
9288 /* Similar hack for Go. */
9289 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
9290 set_cu_language (DW_LANG_Go
, cu
);
9292 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
9294 /* Decode line number information if present. We do this before
9295 processing child DIEs, so that the line header table is available
9296 for DW_AT_decl_file. */
9297 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, lowpc
);
9299 /* Process all dies in compilation unit. */
9300 if (die
->child
!= NULL
)
9302 child_die
= die
->child
;
9303 while (child_die
&& child_die
->tag
)
9305 process_die (child_die
, cu
);
9306 child_die
= sibling_die (child_die
);
9310 /* Decode macro information, if present. Dwarf 2 macro information
9311 refers to information in the line number info statement program
9312 header, so we can only read it if we've read the header
9314 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
9315 if (attr
&& cu
->line_header
)
9317 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
9318 complaint (&symfile_complaints
,
9319 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
9321 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
9325 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
9326 if (attr
&& cu
->line_header
)
9328 unsigned int macro_offset
= DW_UNSND (attr
);
9330 dwarf_decode_macros (cu
, macro_offset
, 0);
9334 do_cleanups (back_to
);
9337 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
9338 Create the set of symtabs used by this TU, or if this TU is sharing
9339 symtabs with another TU and the symtabs have already been created
9340 then restore those symtabs in the line header.
9341 We don't need the pc/line-number mapping for type units. */
9344 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
9346 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
9347 struct type_unit_group
*tu_group
;
9349 struct line_header
*lh
;
9350 struct attribute
*attr
;
9351 unsigned int i
, line_offset
;
9352 struct signatured_type
*sig_type
;
9354 gdb_assert (per_cu
->is_debug_types
);
9355 sig_type
= (struct signatured_type
*) per_cu
;
9357 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9359 /* If we're using .gdb_index (includes -readnow) then
9360 per_cu->type_unit_group may not have been set up yet. */
9361 if (sig_type
->type_unit_group
== NULL
)
9362 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
9363 tu_group
= sig_type
->type_unit_group
;
9365 /* If we've already processed this stmt_list there's no real need to
9366 do it again, we could fake it and just recreate the part we need
9367 (file name,index -> symtab mapping). If data shows this optimization
9368 is useful we can do it then. */
9369 first_time
= tu_group
->compunit_symtab
== NULL
;
9371 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
9376 line_offset
= DW_UNSND (attr
);
9377 lh
= dwarf_decode_line_header (line_offset
, cu
);
9382 dwarf2_start_symtab (cu
, "", NULL
, 0);
9385 gdb_assert (tu_group
->symtabs
== NULL
);
9386 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9391 cu
->line_header
= lh
;
9392 make_cleanup (free_cu_line_header
, cu
);
9396 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
9398 /* Note: We don't assign tu_group->compunit_symtab yet because we're
9399 still initializing it, and our caller (a few levels up)
9400 process_full_type_unit still needs to know if this is the first
9403 tu_group
->num_symtabs
= lh
->num_file_names
;
9404 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
9406 for (i
= 0; i
< lh
->num_file_names
; ++i
)
9408 const char *dir
= NULL
;
9409 struct file_entry
*fe
= &lh
->file_names
[i
];
9411 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
9412 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9413 dwarf2_start_subfile (fe
->name
, dir
);
9415 if (current_subfile
->symtab
== NULL
)
9417 /* NOTE: start_subfile will recognize when it's been passed
9418 a file it has already seen. So we can't assume there's a
9419 simple mapping from lh->file_names to subfiles, plus
9420 lh->file_names may contain dups. */
9421 current_subfile
->symtab
9422 = allocate_symtab (cust
, current_subfile
->name
);
9425 fe
->symtab
= current_subfile
->symtab
;
9426 tu_group
->symtabs
[i
] = fe
->symtab
;
9431 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9433 for (i
= 0; i
< lh
->num_file_names
; ++i
)
9435 struct file_entry
*fe
= &lh
->file_names
[i
];
9437 fe
->symtab
= tu_group
->symtabs
[i
];
9441 /* The main symtab is allocated last. Type units don't have DW_AT_name
9442 so they don't have a "real" (so to speak) symtab anyway.
9443 There is later code that will assign the main symtab to all symbols
9444 that don't have one. We need to handle the case of a symbol with a
9445 missing symtab (DW_AT_decl_file) anyway. */
9448 /* Process DW_TAG_type_unit.
9449 For TUs we want to skip the first top level sibling if it's not the
9450 actual type being defined by this TU. In this case the first top
9451 level sibling is there to provide context only. */
9454 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9456 struct die_info
*child_die
;
9458 prepare_one_comp_unit (cu
, die
, language_minimal
);
9460 /* Initialize (or reinitialize) the machinery for building symtabs.
9461 We do this before processing child DIEs, so that the line header table
9462 is available for DW_AT_decl_file. */
9463 setup_type_unit_groups (die
, cu
);
9465 if (die
->child
!= NULL
)
9467 child_die
= die
->child
;
9468 while (child_die
&& child_die
->tag
)
9470 process_die (child_die
, cu
);
9471 child_die
= sibling_die (child_die
);
9478 http://gcc.gnu.org/wiki/DebugFission
9479 http://gcc.gnu.org/wiki/DebugFissionDWP
9481 To simplify handling of both DWO files ("object" files with the DWARF info)
9482 and DWP files (a file with the DWOs packaged up into one file), we treat
9483 DWP files as having a collection of virtual DWO files. */
9486 hash_dwo_file (const void *item
)
9488 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
9491 hash
= htab_hash_string (dwo_file
->dwo_name
);
9492 if (dwo_file
->comp_dir
!= NULL
)
9493 hash
+= htab_hash_string (dwo_file
->comp_dir
);
9498 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
9500 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
9501 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
9503 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
9505 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
9506 return lhs
->comp_dir
== rhs
->comp_dir
;
9507 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
9510 /* Allocate a hash table for DWO files. */
9513 allocate_dwo_file_hash_table (void)
9515 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9517 return htab_create_alloc_ex (41,
9521 &objfile
->objfile_obstack
,
9522 hashtab_obstack_allocate
,
9523 dummy_obstack_deallocate
);
9526 /* Lookup DWO file DWO_NAME. */
9529 lookup_dwo_file_slot (const char *dwo_name
, const char *comp_dir
)
9531 struct dwo_file find_entry
;
9534 if (dwarf2_per_objfile
->dwo_files
== NULL
)
9535 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
9537 memset (&find_entry
, 0, sizeof (find_entry
));
9538 find_entry
.dwo_name
= dwo_name
;
9539 find_entry
.comp_dir
= comp_dir
;
9540 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
9546 hash_dwo_unit (const void *item
)
9548 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
9550 /* This drops the top 32 bits of the id, but is ok for a hash. */
9551 return dwo_unit
->signature
;
9555 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
9557 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
9558 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
9560 /* The signature is assumed to be unique within the DWO file.
9561 So while object file CU dwo_id's always have the value zero,
9562 that's OK, assuming each object file DWO file has only one CU,
9563 and that's the rule for now. */
9564 return lhs
->signature
== rhs
->signature
;
9567 /* Allocate a hash table for DWO CUs,TUs.
9568 There is one of these tables for each of CUs,TUs for each DWO file. */
9571 allocate_dwo_unit_table (struct objfile
*objfile
)
9573 /* Start out with a pretty small number.
9574 Generally DWO files contain only one CU and maybe some TUs. */
9575 return htab_create_alloc_ex (3,
9579 &objfile
->objfile_obstack
,
9580 hashtab_obstack_allocate
,
9581 dummy_obstack_deallocate
);
9584 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
9586 struct create_dwo_cu_data
9588 struct dwo_file
*dwo_file
;
9589 struct dwo_unit dwo_unit
;
9592 /* die_reader_func for create_dwo_cu. */
9595 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
9596 const gdb_byte
*info_ptr
,
9597 struct die_info
*comp_unit_die
,
9601 struct dwarf2_cu
*cu
= reader
->cu
;
9602 sect_offset offset
= cu
->per_cu
->offset
;
9603 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
9604 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
9605 struct dwo_file
*dwo_file
= data
->dwo_file
;
9606 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
9607 struct attribute
*attr
;
9609 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
9612 complaint (&symfile_complaints
,
9613 _("Dwarf Error: debug entry at offset 0x%x is missing"
9614 " its dwo_id [in module %s]"),
9615 offset
.sect_off
, dwo_file
->dwo_name
);
9619 dwo_unit
->dwo_file
= dwo_file
;
9620 dwo_unit
->signature
= DW_UNSND (attr
);
9621 dwo_unit
->section
= section
;
9622 dwo_unit
->offset
= offset
;
9623 dwo_unit
->length
= cu
->per_cu
->length
;
9625 if (dwarf_read_debug
)
9626 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id %s\n",
9627 offset
.sect_off
, hex_string (dwo_unit
->signature
));
9630 /* Create the dwo_unit for the lone CU in DWO_FILE.
9631 Note: This function processes DWO files only, not DWP files. */
9633 static struct dwo_unit
*
9634 create_dwo_cu (struct dwo_file
*dwo_file
)
9636 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9637 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
9638 const gdb_byte
*info_ptr
, *end_ptr
;
9639 struct create_dwo_cu_data create_dwo_cu_data
;
9640 struct dwo_unit
*dwo_unit
;
9642 dwarf2_read_section (objfile
, section
);
9643 info_ptr
= section
->buffer
;
9645 if (info_ptr
== NULL
)
9648 if (dwarf_read_debug
)
9650 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
9651 get_section_name (section
),
9652 get_section_file_name (section
));
9655 create_dwo_cu_data
.dwo_file
= dwo_file
;
9658 end_ptr
= info_ptr
+ section
->size
;
9659 while (info_ptr
< end_ptr
)
9661 struct dwarf2_per_cu_data per_cu
;
9663 memset (&create_dwo_cu_data
.dwo_unit
, 0,
9664 sizeof (create_dwo_cu_data
.dwo_unit
));
9665 memset (&per_cu
, 0, sizeof (per_cu
));
9666 per_cu
.objfile
= objfile
;
9667 per_cu
.is_debug_types
= 0;
9668 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
9669 per_cu
.section
= section
;
9671 init_cutu_and_read_dies_no_follow (&per_cu
, dwo_file
,
9672 create_dwo_cu_reader
,
9673 &create_dwo_cu_data
);
9675 if (create_dwo_cu_data
.dwo_unit
.dwo_file
!= NULL
)
9677 /* If we've already found one, complain. We only support one
9678 because having more than one requires hacking the dwo_name of
9679 each to match, which is highly unlikely to happen. */
9680 if (dwo_unit
!= NULL
)
9682 complaint (&symfile_complaints
,
9683 _("Multiple CUs in DWO file %s [in module %s]"),
9684 dwo_file
->dwo_name
, objfile_name (objfile
));
9688 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
9689 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
9692 info_ptr
+= per_cu
.length
;
9698 /* DWP file .debug_{cu,tu}_index section format:
9699 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
9703 Both index sections have the same format, and serve to map a 64-bit
9704 signature to a set of section numbers. Each section begins with a header,
9705 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
9706 indexes, and a pool of 32-bit section numbers. The index sections will be
9707 aligned at 8-byte boundaries in the file.
9709 The index section header consists of:
9711 V, 32 bit version number
9713 N, 32 bit number of compilation units or type units in the index
9714 M, 32 bit number of slots in the hash table
9716 Numbers are recorded using the byte order of the application binary.
9718 The hash table begins at offset 16 in the section, and consists of an array
9719 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
9720 order of the application binary). Unused slots in the hash table are 0.
9721 (We rely on the extreme unlikeliness of a signature being exactly 0.)
9723 The parallel table begins immediately after the hash table
9724 (at offset 16 + 8 * M from the beginning of the section), and consists of an
9725 array of 32-bit indexes (using the byte order of the application binary),
9726 corresponding 1-1 with slots in the hash table. Each entry in the parallel
9727 table contains a 32-bit index into the pool of section numbers. For unused
9728 hash table slots, the corresponding entry in the parallel table will be 0.
9730 The pool of section numbers begins immediately following the hash table
9731 (at offset 16 + 12 * M from the beginning of the section). The pool of
9732 section numbers consists of an array of 32-bit words (using the byte order
9733 of the application binary). Each item in the array is indexed starting
9734 from 0. The hash table entry provides the index of the first section
9735 number in the set. Additional section numbers in the set follow, and the
9736 set is terminated by a 0 entry (section number 0 is not used in ELF).
9738 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
9739 section must be the first entry in the set, and the .debug_abbrev.dwo must
9740 be the second entry. Other members of the set may follow in any order.
9746 DWP Version 2 combines all the .debug_info, etc. sections into one,
9747 and the entries in the index tables are now offsets into these sections.
9748 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
9751 Index Section Contents:
9753 Hash Table of Signatures dwp_hash_table.hash_table
9754 Parallel Table of Indices dwp_hash_table.unit_table
9755 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
9756 Table of Section Sizes dwp_hash_table.v2.sizes
9758 The index section header consists of:
9760 V, 32 bit version number
9761 L, 32 bit number of columns in the table of section offsets
9762 N, 32 bit number of compilation units or type units in the index
9763 M, 32 bit number of slots in the hash table
9765 Numbers are recorded using the byte order of the application binary.
9767 The hash table has the same format as version 1.
9768 The parallel table of indices has the same format as version 1,
9769 except that the entries are origin-1 indices into the table of sections
9770 offsets and the table of section sizes.
9772 The table of offsets begins immediately following the parallel table
9773 (at offset 16 + 12 * M from the beginning of the section). The table is
9774 a two-dimensional array of 32-bit words (using the byte order of the
9775 application binary), with L columns and N+1 rows, in row-major order.
9776 Each row in the array is indexed starting from 0. The first row provides
9777 a key to the remaining rows: each column in this row provides an identifier
9778 for a debug section, and the offsets in the same column of subsequent rows
9779 refer to that section. The section identifiers are:
9781 DW_SECT_INFO 1 .debug_info.dwo
9782 DW_SECT_TYPES 2 .debug_types.dwo
9783 DW_SECT_ABBREV 3 .debug_abbrev.dwo
9784 DW_SECT_LINE 4 .debug_line.dwo
9785 DW_SECT_LOC 5 .debug_loc.dwo
9786 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
9787 DW_SECT_MACINFO 7 .debug_macinfo.dwo
9788 DW_SECT_MACRO 8 .debug_macro.dwo
9790 The offsets provided by the CU and TU index sections are the base offsets
9791 for the contributions made by each CU or TU to the corresponding section
9792 in the package file. Each CU and TU header contains an abbrev_offset
9793 field, used to find the abbreviations table for that CU or TU within the
9794 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
9795 be interpreted as relative to the base offset given in the index section.
9796 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
9797 should be interpreted as relative to the base offset for .debug_line.dwo,
9798 and offsets into other debug sections obtained from DWARF attributes should
9799 also be interpreted as relative to the corresponding base offset.
9801 The table of sizes begins immediately following the table of offsets.
9802 Like the table of offsets, it is a two-dimensional array of 32-bit words,
9803 with L columns and N rows, in row-major order. Each row in the array is
9804 indexed starting from 1 (row 0 is shared by the two tables).
9808 Hash table lookup is handled the same in version 1 and 2:
9810 We assume that N and M will not exceed 2^32 - 1.
9811 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
9813 Given a 64-bit compilation unit signature or a type signature S, an entry
9814 in the hash table is located as follows:
9816 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
9817 the low-order k bits all set to 1.
9819 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
9821 3) If the hash table entry at index H matches the signature, use that
9822 entry. If the hash table entry at index H is unused (all zeroes),
9823 terminate the search: the signature is not present in the table.
9825 4) Let H = (H + H') modulo M. Repeat at Step 3.
9827 Because M > N and H' and M are relatively prime, the search is guaranteed
9828 to stop at an unused slot or find the match. */
9830 /* Create a hash table to map DWO IDs to their CU/TU entry in
9831 .debug_{info,types}.dwo in DWP_FILE.
9832 Returns NULL if there isn't one.
9833 Note: This function processes DWP files only, not DWO files. */
9835 static struct dwp_hash_table
*
9836 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
9838 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9839 bfd
*dbfd
= dwp_file
->dbfd
;
9840 const gdb_byte
*index_ptr
, *index_end
;
9841 struct dwarf2_section_info
*index
;
9842 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
9843 struct dwp_hash_table
*htab
;
9846 index
= &dwp_file
->sections
.tu_index
;
9848 index
= &dwp_file
->sections
.cu_index
;
9850 if (dwarf2_section_empty_p (index
))
9852 dwarf2_read_section (objfile
, index
);
9854 index_ptr
= index
->buffer
;
9855 index_end
= index_ptr
+ index
->size
;
9857 version
= read_4_bytes (dbfd
, index_ptr
);
9860 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
9864 nr_units
= read_4_bytes (dbfd
, index_ptr
);
9866 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
9869 if (version
!= 1 && version
!= 2)
9871 error (_("Dwarf Error: unsupported DWP file version (%s)"
9873 pulongest (version
), dwp_file
->name
);
9875 if (nr_slots
!= (nr_slots
& -nr_slots
))
9877 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
9878 " is not power of 2 [in module %s]"),
9879 pulongest (nr_slots
), dwp_file
->name
);
9882 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
9883 htab
->version
= version
;
9884 htab
->nr_columns
= nr_columns
;
9885 htab
->nr_units
= nr_units
;
9886 htab
->nr_slots
= nr_slots
;
9887 htab
->hash_table
= index_ptr
;
9888 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
9890 /* Exit early if the table is empty. */
9891 if (nr_slots
== 0 || nr_units
== 0
9892 || (version
== 2 && nr_columns
== 0))
9894 /* All must be zero. */
9895 if (nr_slots
!= 0 || nr_units
!= 0
9896 || (version
== 2 && nr_columns
!= 0))
9898 complaint (&symfile_complaints
,
9899 _("Empty DWP but nr_slots,nr_units,nr_columns not"
9900 " all zero [in modules %s]"),
9908 htab
->section_pool
.v1
.indices
=
9909 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9910 /* It's harder to decide whether the section is too small in v1.
9911 V1 is deprecated anyway so we punt. */
9915 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9916 int *ids
= htab
->section_pool
.v2
.section_ids
;
9917 /* Reverse map for error checking. */
9918 int ids_seen
[DW_SECT_MAX
+ 1];
9923 error (_("Dwarf Error: bad DWP hash table, too few columns"
9924 " in section table [in module %s]"),
9927 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
9929 error (_("Dwarf Error: bad DWP hash table, too many columns"
9930 " in section table [in module %s]"),
9933 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
9934 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
9935 for (i
= 0; i
< nr_columns
; ++i
)
9937 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
9939 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
9941 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
9942 " in section table [in module %s]"),
9943 id
, dwp_file
->name
);
9945 if (ids_seen
[id
] != -1)
9947 error (_("Dwarf Error: bad DWP hash table, duplicate section"
9948 " id %d in section table [in module %s]"),
9949 id
, dwp_file
->name
);
9954 /* Must have exactly one info or types section. */
9955 if (((ids_seen
[DW_SECT_INFO
] != -1)
9956 + (ids_seen
[DW_SECT_TYPES
] != -1))
9959 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
9960 " DWO info/types section [in module %s]"),
9963 /* Must have an abbrev section. */
9964 if (ids_seen
[DW_SECT_ABBREV
] == -1)
9966 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
9967 " section [in module %s]"),
9970 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
9971 htab
->section_pool
.v2
.sizes
=
9972 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
9973 * nr_units
* nr_columns
);
9974 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
9975 * nr_units
* nr_columns
))
9978 error (_("Dwarf Error: DWP index section is corrupt (too small)"
9987 /* Update SECTIONS with the data from SECTP.
9989 This function is like the other "locate" section routines that are
9990 passed to bfd_map_over_sections, but in this context the sections to
9991 read comes from the DWP V1 hash table, not the full ELF section table.
9993 The result is non-zero for success, or zero if an error was found. */
9996 locate_v1_virtual_dwo_sections (asection
*sectp
,
9997 struct virtual_v1_dwo_sections
*sections
)
9999 const struct dwop_section_names
*names
= &dwop_section_names
;
10001 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10003 /* There can be only one. */
10004 if (sections
->abbrev
.s
.section
!= NULL
)
10006 sections
->abbrev
.s
.section
= sectp
;
10007 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10009 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
10010 || section_is_p (sectp
->name
, &names
->types_dwo
))
10012 /* There can be only one. */
10013 if (sections
->info_or_types
.s
.section
!= NULL
)
10015 sections
->info_or_types
.s
.section
= sectp
;
10016 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
10018 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10020 /* There can be only one. */
10021 if (sections
->line
.s
.section
!= NULL
)
10023 sections
->line
.s
.section
= sectp
;
10024 sections
->line
.size
= bfd_get_section_size (sectp
);
10026 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10028 /* There can be only one. */
10029 if (sections
->loc
.s
.section
!= NULL
)
10031 sections
->loc
.s
.section
= sectp
;
10032 sections
->loc
.size
= bfd_get_section_size (sectp
);
10034 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10036 /* There can be only one. */
10037 if (sections
->macinfo
.s
.section
!= NULL
)
10039 sections
->macinfo
.s
.section
= sectp
;
10040 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10042 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10044 /* There can be only one. */
10045 if (sections
->macro
.s
.section
!= NULL
)
10047 sections
->macro
.s
.section
= sectp
;
10048 sections
->macro
.size
= bfd_get_section_size (sectp
);
10050 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10052 /* There can be only one. */
10053 if (sections
->str_offsets
.s
.section
!= NULL
)
10055 sections
->str_offsets
.s
.section
= sectp
;
10056 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10060 /* No other kind of section is valid. */
10067 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10068 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10069 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10070 This is for DWP version 1 files. */
10072 static struct dwo_unit
*
10073 create_dwo_unit_in_dwp_v1 (struct dwp_file
*dwp_file
,
10074 uint32_t unit_index
,
10075 const char *comp_dir
,
10076 ULONGEST signature
, int is_debug_types
)
10078 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10079 const struct dwp_hash_table
*dwp_htab
=
10080 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10081 bfd
*dbfd
= dwp_file
->dbfd
;
10082 const char *kind
= is_debug_types
? "TU" : "CU";
10083 struct dwo_file
*dwo_file
;
10084 struct dwo_unit
*dwo_unit
;
10085 struct virtual_v1_dwo_sections sections
;
10086 void **dwo_file_slot
;
10087 char *virtual_dwo_name
;
10088 struct cleanup
*cleanups
;
10091 gdb_assert (dwp_file
->version
== 1);
10093 if (dwarf_read_debug
)
10095 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
10097 pulongest (unit_index
), hex_string (signature
),
10101 /* Fetch the sections of this DWO unit.
10102 Put a limit on the number of sections we look for so that bad data
10103 doesn't cause us to loop forever. */
10105 #define MAX_NR_V1_DWO_SECTIONS \
10106 (1 /* .debug_info or .debug_types */ \
10107 + 1 /* .debug_abbrev */ \
10108 + 1 /* .debug_line */ \
10109 + 1 /* .debug_loc */ \
10110 + 1 /* .debug_str_offsets */ \
10111 + 1 /* .debug_macro or .debug_macinfo */ \
10112 + 1 /* trailing zero */)
10114 memset (§ions
, 0, sizeof (sections
));
10115 cleanups
= make_cleanup (null_cleanup
, 0);
10117 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
10120 uint32_t section_nr
=
10121 read_4_bytes (dbfd
,
10122 dwp_htab
->section_pool
.v1
.indices
10123 + (unit_index
+ i
) * sizeof (uint32_t));
10125 if (section_nr
== 0)
10127 if (section_nr
>= dwp_file
->num_sections
)
10129 error (_("Dwarf Error: bad DWP hash table, section number too large"
10130 " [in module %s]"),
10134 sectp
= dwp_file
->elf_sections
[section_nr
];
10135 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
10137 error (_("Dwarf Error: bad DWP hash table, invalid section found"
10138 " [in module %s]"),
10144 || dwarf2_section_empty_p (§ions
.info_or_types
)
10145 || dwarf2_section_empty_p (§ions
.abbrev
))
10147 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
10148 " [in module %s]"),
10151 if (i
== MAX_NR_V1_DWO_SECTIONS
)
10153 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
10154 " [in module %s]"),
10158 /* It's easier for the rest of the code if we fake a struct dwo_file and
10159 have dwo_unit "live" in that. At least for now.
10161 The DWP file can be made up of a random collection of CUs and TUs.
10162 However, for each CU + set of TUs that came from the same original DWO
10163 file, we can combine them back into a virtual DWO file to save space
10164 (fewer struct dwo_file objects to allocate). Remember that for really
10165 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10168 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
10169 get_section_id (§ions
.abbrev
),
10170 get_section_id (§ions
.line
),
10171 get_section_id (§ions
.loc
),
10172 get_section_id (§ions
.str_offsets
));
10173 make_cleanup (xfree
, virtual_dwo_name
);
10174 /* Can we use an existing virtual DWO file? */
10175 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
10176 /* Create one if necessary. */
10177 if (*dwo_file_slot
== NULL
)
10179 if (dwarf_read_debug
)
10181 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10184 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10186 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
10188 strlen (virtual_dwo_name
));
10189 dwo_file
->comp_dir
= comp_dir
;
10190 dwo_file
->sections
.abbrev
= sections
.abbrev
;
10191 dwo_file
->sections
.line
= sections
.line
;
10192 dwo_file
->sections
.loc
= sections
.loc
;
10193 dwo_file
->sections
.macinfo
= sections
.macinfo
;
10194 dwo_file
->sections
.macro
= sections
.macro
;
10195 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
10196 /* The "str" section is global to the entire DWP file. */
10197 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10198 /* The info or types section is assigned below to dwo_unit,
10199 there's no need to record it in dwo_file.
10200 Also, we can't simply record type sections in dwo_file because
10201 we record a pointer into the vector in dwo_unit. As we collect more
10202 types we'll grow the vector and eventually have to reallocate space
10203 for it, invalidating all copies of pointers into the previous
10205 *dwo_file_slot
= dwo_file
;
10209 if (dwarf_read_debug
)
10211 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10214 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10216 do_cleanups (cleanups
);
10218 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10219 dwo_unit
->dwo_file
= dwo_file
;
10220 dwo_unit
->signature
= signature
;
10221 dwo_unit
->section
=
10222 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
10223 *dwo_unit
->section
= sections
.info_or_types
;
10224 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10229 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
10230 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
10231 piece within that section used by a TU/CU, return a virtual section
10232 of just that piece. */
10234 static struct dwarf2_section_info
10235 create_dwp_v2_section (struct dwarf2_section_info
*section
,
10236 bfd_size_type offset
, bfd_size_type size
)
10238 struct dwarf2_section_info result
;
10241 gdb_assert (section
!= NULL
);
10242 gdb_assert (!section
->is_virtual
);
10244 memset (&result
, 0, sizeof (result
));
10245 result
.s
.containing_section
= section
;
10246 result
.is_virtual
= 1;
10251 sectp
= get_section_bfd_section (section
);
10253 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
10254 bounds of the real section. This is a pretty-rare event, so just
10255 flag an error (easier) instead of a warning and trying to cope. */
10257 || offset
+ size
> bfd_get_section_size (sectp
))
10259 bfd
*abfd
= sectp
->owner
;
10261 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
10262 " in section %s [in module %s]"),
10263 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
10264 objfile_name (dwarf2_per_objfile
->objfile
));
10267 result
.virtual_offset
= offset
;
10268 result
.size
= size
;
10272 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10273 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10274 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10275 This is for DWP version 2 files. */
10277 static struct dwo_unit
*
10278 create_dwo_unit_in_dwp_v2 (struct dwp_file
*dwp_file
,
10279 uint32_t unit_index
,
10280 const char *comp_dir
,
10281 ULONGEST signature
, int is_debug_types
)
10283 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10284 const struct dwp_hash_table
*dwp_htab
=
10285 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10286 bfd
*dbfd
= dwp_file
->dbfd
;
10287 const char *kind
= is_debug_types
? "TU" : "CU";
10288 struct dwo_file
*dwo_file
;
10289 struct dwo_unit
*dwo_unit
;
10290 struct virtual_v2_dwo_sections sections
;
10291 void **dwo_file_slot
;
10292 char *virtual_dwo_name
;
10293 struct cleanup
*cleanups
;
10296 gdb_assert (dwp_file
->version
== 2);
10298 if (dwarf_read_debug
)
10300 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
10302 pulongest (unit_index
), hex_string (signature
),
10306 /* Fetch the section offsets of this DWO unit. */
10308 memset (§ions
, 0, sizeof (sections
));
10309 cleanups
= make_cleanup (null_cleanup
, 0);
10311 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
10313 uint32_t offset
= read_4_bytes (dbfd
,
10314 dwp_htab
->section_pool
.v2
.offsets
10315 + (((unit_index
- 1) * dwp_htab
->nr_columns
10317 * sizeof (uint32_t)));
10318 uint32_t size
= read_4_bytes (dbfd
,
10319 dwp_htab
->section_pool
.v2
.sizes
10320 + (((unit_index
- 1) * dwp_htab
->nr_columns
10322 * sizeof (uint32_t)));
10324 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
10327 case DW_SECT_TYPES
:
10328 sections
.info_or_types_offset
= offset
;
10329 sections
.info_or_types_size
= size
;
10331 case DW_SECT_ABBREV
:
10332 sections
.abbrev_offset
= offset
;
10333 sections
.abbrev_size
= size
;
10336 sections
.line_offset
= offset
;
10337 sections
.line_size
= size
;
10340 sections
.loc_offset
= offset
;
10341 sections
.loc_size
= size
;
10343 case DW_SECT_STR_OFFSETS
:
10344 sections
.str_offsets_offset
= offset
;
10345 sections
.str_offsets_size
= size
;
10347 case DW_SECT_MACINFO
:
10348 sections
.macinfo_offset
= offset
;
10349 sections
.macinfo_size
= size
;
10351 case DW_SECT_MACRO
:
10352 sections
.macro_offset
= offset
;
10353 sections
.macro_size
= size
;
10358 /* It's easier for the rest of the code if we fake a struct dwo_file and
10359 have dwo_unit "live" in that. At least for now.
10361 The DWP file can be made up of a random collection of CUs and TUs.
10362 However, for each CU + set of TUs that came from the same original DWO
10363 file, we can combine them back into a virtual DWO file to save space
10364 (fewer struct dwo_file objects to allocate). Remember that for really
10365 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10368 xstrprintf ("virtual-dwo/%ld-%ld-%ld-%ld",
10369 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
10370 (long) (sections
.line_size
? sections
.line_offset
: 0),
10371 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
10372 (long) (sections
.str_offsets_size
10373 ? sections
.str_offsets_offset
: 0));
10374 make_cleanup (xfree
, virtual_dwo_name
);
10375 /* Can we use an existing virtual DWO file? */
10376 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
10377 /* Create one if necessary. */
10378 if (*dwo_file_slot
== NULL
)
10380 if (dwarf_read_debug
)
10382 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10385 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10387 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
10389 strlen (virtual_dwo_name
));
10390 dwo_file
->comp_dir
= comp_dir
;
10391 dwo_file
->sections
.abbrev
=
10392 create_dwp_v2_section (&dwp_file
->sections
.abbrev
,
10393 sections
.abbrev_offset
, sections
.abbrev_size
);
10394 dwo_file
->sections
.line
=
10395 create_dwp_v2_section (&dwp_file
->sections
.line
,
10396 sections
.line_offset
, sections
.line_size
);
10397 dwo_file
->sections
.loc
=
10398 create_dwp_v2_section (&dwp_file
->sections
.loc
,
10399 sections
.loc_offset
, sections
.loc_size
);
10400 dwo_file
->sections
.macinfo
=
10401 create_dwp_v2_section (&dwp_file
->sections
.macinfo
,
10402 sections
.macinfo_offset
, sections
.macinfo_size
);
10403 dwo_file
->sections
.macro
=
10404 create_dwp_v2_section (&dwp_file
->sections
.macro
,
10405 sections
.macro_offset
, sections
.macro_size
);
10406 dwo_file
->sections
.str_offsets
=
10407 create_dwp_v2_section (&dwp_file
->sections
.str_offsets
,
10408 sections
.str_offsets_offset
,
10409 sections
.str_offsets_size
);
10410 /* The "str" section is global to the entire DWP file. */
10411 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10412 /* The info or types section is assigned below to dwo_unit,
10413 there's no need to record it in dwo_file.
10414 Also, we can't simply record type sections in dwo_file because
10415 we record a pointer into the vector in dwo_unit. As we collect more
10416 types we'll grow the vector and eventually have to reallocate space
10417 for it, invalidating all copies of pointers into the previous
10419 *dwo_file_slot
= dwo_file
;
10423 if (dwarf_read_debug
)
10425 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10428 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10430 do_cleanups (cleanups
);
10432 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10433 dwo_unit
->dwo_file
= dwo_file
;
10434 dwo_unit
->signature
= signature
;
10435 dwo_unit
->section
=
10436 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
10437 *dwo_unit
->section
= create_dwp_v2_section (is_debug_types
10438 ? &dwp_file
->sections
.types
10439 : &dwp_file
->sections
.info
,
10440 sections
.info_or_types_offset
,
10441 sections
.info_or_types_size
);
10442 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10447 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
10448 Returns NULL if the signature isn't found. */
10450 static struct dwo_unit
*
10451 lookup_dwo_unit_in_dwp (struct dwp_file
*dwp_file
, const char *comp_dir
,
10452 ULONGEST signature
, int is_debug_types
)
10454 const struct dwp_hash_table
*dwp_htab
=
10455 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10456 bfd
*dbfd
= dwp_file
->dbfd
;
10457 uint32_t mask
= dwp_htab
->nr_slots
- 1;
10458 uint32_t hash
= signature
& mask
;
10459 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
10462 struct dwo_unit find_dwo_cu
;
10464 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
10465 find_dwo_cu
.signature
= signature
;
10466 slot
= htab_find_slot (is_debug_types
10467 ? dwp_file
->loaded_tus
10468 : dwp_file
->loaded_cus
,
10469 &find_dwo_cu
, INSERT
);
10472 return (struct dwo_unit
*) *slot
;
10474 /* Use a for loop so that we don't loop forever on bad debug info. */
10475 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
10477 ULONGEST signature_in_table
;
10479 signature_in_table
=
10480 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
10481 if (signature_in_table
== signature
)
10483 uint32_t unit_index
=
10484 read_4_bytes (dbfd
,
10485 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
10487 if (dwp_file
->version
== 1)
10489 *slot
= create_dwo_unit_in_dwp_v1 (dwp_file
, unit_index
,
10490 comp_dir
, signature
,
10495 *slot
= create_dwo_unit_in_dwp_v2 (dwp_file
, unit_index
,
10496 comp_dir
, signature
,
10499 return (struct dwo_unit
*) *slot
;
10501 if (signature_in_table
== 0)
10503 hash
= (hash
+ hash2
) & mask
;
10506 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
10507 " [in module %s]"),
10511 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
10512 Open the file specified by FILE_NAME and hand it off to BFD for
10513 preliminary analysis. Return a newly initialized bfd *, which
10514 includes a canonicalized copy of FILE_NAME.
10515 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
10516 SEARCH_CWD is true if the current directory is to be searched.
10517 It will be searched before debug-file-directory.
10518 If successful, the file is added to the bfd include table of the
10519 objfile's bfd (see gdb_bfd_record_inclusion).
10520 If unable to find/open the file, return NULL.
10521 NOTE: This function is derived from symfile_bfd_open. */
10523 static gdb_bfd_ref_ptr
10524 try_open_dwop_file (const char *file_name
, int is_dwp
, int search_cwd
)
10527 char *absolute_name
;
10528 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
10529 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
10530 to debug_file_directory. */
10532 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
10536 if (*debug_file_directory
!= '\0')
10537 search_path
= concat (".", dirname_separator_string
,
10538 debug_file_directory
, (char *) NULL
);
10540 search_path
= xstrdup (".");
10543 search_path
= xstrdup (debug_file_directory
);
10545 flags
= OPF_RETURN_REALPATH
;
10547 flags
|= OPF_SEARCH_IN_PATH
;
10548 desc
= openp (search_path
, flags
, file_name
,
10549 O_RDONLY
| O_BINARY
, &absolute_name
);
10550 xfree (search_path
);
10554 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
, gnutarget
, desc
));
10555 xfree (absolute_name
);
10556 if (sym_bfd
== NULL
)
10558 bfd_set_cacheable (sym_bfd
.get (), 1);
10560 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
10563 /* Success. Record the bfd as having been included by the objfile's bfd.
10564 This is important because things like demangled_names_hash lives in the
10565 objfile's per_bfd space and may have references to things like symbol
10566 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
10567 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
10572 /* Try to open DWO file FILE_NAME.
10573 COMP_DIR is the DW_AT_comp_dir attribute.
10574 The result is the bfd handle of the file.
10575 If there is a problem finding or opening the file, return NULL.
10576 Upon success, the canonicalized path of the file is stored in the bfd,
10577 same as symfile_bfd_open. */
10579 static gdb_bfd_ref_ptr
10580 open_dwo_file (const char *file_name
, const char *comp_dir
)
10582 if (IS_ABSOLUTE_PATH (file_name
))
10583 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 0 /*search_cwd*/);
10585 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
10587 if (comp_dir
!= NULL
)
10589 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
10590 file_name
, (char *) NULL
);
10592 /* NOTE: If comp_dir is a relative path, this will also try the
10593 search path, which seems useful. */
10594 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (path_to_try
, 0 /*is_dwp*/,
10595 1 /*search_cwd*/));
10596 xfree (path_to_try
);
10601 /* That didn't work, try debug-file-directory, which, despite its name,
10602 is a list of paths. */
10604 if (*debug_file_directory
== '\0')
10607 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 1 /*search_cwd*/);
10610 /* This function is mapped across the sections and remembers the offset and
10611 size of each of the DWO debugging sections we are interested in. */
10614 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
10616 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
10617 const struct dwop_section_names
*names
= &dwop_section_names
;
10619 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10621 dwo_sections
->abbrev
.s
.section
= sectp
;
10622 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10624 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10626 dwo_sections
->info
.s
.section
= sectp
;
10627 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
10629 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10631 dwo_sections
->line
.s
.section
= sectp
;
10632 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
10634 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10636 dwo_sections
->loc
.s
.section
= sectp
;
10637 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
10639 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10641 dwo_sections
->macinfo
.s
.section
= sectp
;
10642 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10644 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10646 dwo_sections
->macro
.s
.section
= sectp
;
10647 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
10649 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
10651 dwo_sections
->str
.s
.section
= sectp
;
10652 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
10654 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10656 dwo_sections
->str_offsets
.s
.section
= sectp
;
10657 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10659 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10661 struct dwarf2_section_info type_section
;
10663 memset (&type_section
, 0, sizeof (type_section
));
10664 type_section
.s
.section
= sectp
;
10665 type_section
.size
= bfd_get_section_size (sectp
);
10666 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
10671 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
10672 by PER_CU. This is for the non-DWP case.
10673 The result is NULL if DWO_NAME can't be found. */
10675 static struct dwo_file
*
10676 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
10677 const char *dwo_name
, const char *comp_dir
)
10679 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10680 struct dwo_file
*dwo_file
;
10681 struct cleanup
*cleanups
;
10683 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwo_name
, comp_dir
));
10686 if (dwarf_read_debug
)
10687 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
10690 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10691 dwo_file
->dwo_name
= dwo_name
;
10692 dwo_file
->comp_dir
= comp_dir
;
10693 dwo_file
->dbfd
= dbfd
.release ();
10695 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
10697 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
10698 &dwo_file
->sections
);
10700 dwo_file
->cu
= create_dwo_cu (dwo_file
);
10702 create_debug_types_hash_table (dwo_file
, dwo_file
->sections
.types
,
10705 discard_cleanups (cleanups
);
10707 if (dwarf_read_debug
)
10708 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
10713 /* This function is mapped across the sections and remembers the offset and
10714 size of each of the DWP debugging sections common to version 1 and 2 that
10715 we are interested in. */
10718 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
10719 void *dwp_file_ptr
)
10721 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
10722 const struct dwop_section_names
*names
= &dwop_section_names
;
10723 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10725 /* Record the ELF section number for later lookup: this is what the
10726 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10727 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10728 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10730 /* Look for specific sections that we need. */
10731 if (section_is_p (sectp
->name
, &names
->str_dwo
))
10733 dwp_file
->sections
.str
.s
.section
= sectp
;
10734 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
10736 else if (section_is_p (sectp
->name
, &names
->cu_index
))
10738 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
10739 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
10741 else if (section_is_p (sectp
->name
, &names
->tu_index
))
10743 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
10744 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
10748 /* This function is mapped across the sections and remembers the offset and
10749 size of each of the DWP version 2 debugging sections that we are interested
10750 in. This is split into a separate function because we don't know if we
10751 have version 1 or 2 until we parse the cu_index/tu_index sections. */
10754 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
10756 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
10757 const struct dwop_section_names
*names
= &dwop_section_names
;
10758 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10760 /* Record the ELF section number for later lookup: this is what the
10761 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10762 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10763 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10765 /* Look for specific sections that we need. */
10766 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10768 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
10769 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
10771 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10773 dwp_file
->sections
.info
.s
.section
= sectp
;
10774 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
10776 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10778 dwp_file
->sections
.line
.s
.section
= sectp
;
10779 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
10781 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10783 dwp_file
->sections
.loc
.s
.section
= sectp
;
10784 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
10786 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10788 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
10789 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
10791 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10793 dwp_file
->sections
.macro
.s
.section
= sectp
;
10794 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
10796 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10798 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
10799 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
10801 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10803 dwp_file
->sections
.types
.s
.section
= sectp
;
10804 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
10808 /* Hash function for dwp_file loaded CUs/TUs. */
10811 hash_dwp_loaded_cutus (const void *item
)
10813 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10815 /* This drops the top 32 bits of the signature, but is ok for a hash. */
10816 return dwo_unit
->signature
;
10819 /* Equality function for dwp_file loaded CUs/TUs. */
10822 eq_dwp_loaded_cutus (const void *a
, const void *b
)
10824 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
10825 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
10827 return dua
->signature
== dub
->signature
;
10830 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
10833 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
10835 return htab_create_alloc_ex (3,
10836 hash_dwp_loaded_cutus
,
10837 eq_dwp_loaded_cutus
,
10839 &objfile
->objfile_obstack
,
10840 hashtab_obstack_allocate
,
10841 dummy_obstack_deallocate
);
10844 /* Try to open DWP file FILE_NAME.
10845 The result is the bfd handle of the file.
10846 If there is a problem finding or opening the file, return NULL.
10847 Upon success, the canonicalized path of the file is stored in the bfd,
10848 same as symfile_bfd_open. */
10850 static gdb_bfd_ref_ptr
10851 open_dwp_file (const char *file_name
)
10853 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (file_name
, 1 /*is_dwp*/,
10854 1 /*search_cwd*/));
10858 /* Work around upstream bug 15652.
10859 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
10860 [Whether that's a "bug" is debatable, but it is getting in our way.]
10861 We have no real idea where the dwp file is, because gdb's realpath-ing
10862 of the executable's path may have discarded the needed info.
10863 [IWBN if the dwp file name was recorded in the executable, akin to
10864 .gnu_debuglink, but that doesn't exist yet.]
10865 Strip the directory from FILE_NAME and search again. */
10866 if (*debug_file_directory
!= '\0')
10868 /* Don't implicitly search the current directory here.
10869 If the user wants to search "." to handle this case,
10870 it must be added to debug-file-directory. */
10871 return try_open_dwop_file (lbasename (file_name
), 1 /*is_dwp*/,
10878 /* Initialize the use of the DWP file for the current objfile.
10879 By convention the name of the DWP file is ${objfile}.dwp.
10880 The result is NULL if it can't be found. */
10882 static struct dwp_file
*
10883 open_and_init_dwp_file (void)
10885 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10886 struct dwp_file
*dwp_file
;
10888 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, 0);
10890 /* Try to find first .dwp for the binary file before any symbolic links
10893 /* If the objfile is a debug file, find the name of the real binary
10894 file and get the name of dwp file from there. */
10895 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
10897 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
10898 const char *backlink_basename
= lbasename (backlink
->original_name
);
10899 char *debug_dirname
= ldirname (objfile
->original_name
);
10901 make_cleanup (xfree
, debug_dirname
);
10902 dwp_name
= xstrprintf ("%s%s%s.dwp", debug_dirname
,
10903 SLASH_STRING
, backlink_basename
);
10906 dwp_name
= xstrprintf ("%s.dwp", objfile
->original_name
);
10907 make_cleanup (xfree
, dwp_name
);
10909 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwp_name
));
10911 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
10913 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
10914 dwp_name
= xstrprintf ("%s.dwp", objfile_name (objfile
));
10915 make_cleanup (xfree
, dwp_name
);
10916 dbfd
= open_dwp_file (dwp_name
);
10921 if (dwarf_read_debug
)
10922 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
);
10923 do_cleanups (cleanups
);
10926 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
10927 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
10928 dwp_file
->dbfd
= dbfd
.release ();
10929 do_cleanups (cleanups
);
10931 /* +1: section 0 is unused */
10932 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
10933 dwp_file
->elf_sections
=
10934 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
10935 dwp_file
->num_sections
, asection
*);
10937 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
10940 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
10942 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
10944 /* The DWP file version is stored in the hash table. Oh well. */
10945 if (dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
10947 /* Technically speaking, we should try to limp along, but this is
10948 pretty bizarre. We use pulongest here because that's the established
10949 portability solution (e.g, we cannot use %u for uint32_t). */
10950 error (_("Dwarf Error: DWP file CU version %s doesn't match"
10951 " TU version %s [in DWP file %s]"),
10952 pulongest (dwp_file
->cus
->version
),
10953 pulongest (dwp_file
->tus
->version
), dwp_name
);
10955 dwp_file
->version
= dwp_file
->cus
->version
;
10957 if (dwp_file
->version
== 2)
10958 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
10961 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
10962 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
10964 if (dwarf_read_debug
)
10966 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
10967 fprintf_unfiltered (gdb_stdlog
,
10968 " %s CUs, %s TUs\n",
10969 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
10970 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
10976 /* Wrapper around open_and_init_dwp_file, only open it once. */
10978 static struct dwp_file
*
10979 get_dwp_file (void)
10981 if (! dwarf2_per_objfile
->dwp_checked
)
10983 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file ();
10984 dwarf2_per_objfile
->dwp_checked
= 1;
10986 return dwarf2_per_objfile
->dwp_file
;
10989 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
10990 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
10991 or in the DWP file for the objfile, referenced by THIS_UNIT.
10992 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
10993 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
10995 This is called, for example, when wanting to read a variable with a
10996 complex location. Therefore we don't want to do file i/o for every call.
10997 Therefore we don't want to look for a DWO file on every call.
10998 Therefore we first see if we've already seen SIGNATURE in a DWP file,
10999 then we check if we've already seen DWO_NAME, and only THEN do we check
11002 The result is a pointer to the dwo_unit object or NULL if we didn't find it
11003 (dwo_id mismatch or couldn't find the DWO/DWP file). */
11005 static struct dwo_unit
*
11006 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
11007 const char *dwo_name
, const char *comp_dir
,
11008 ULONGEST signature
, int is_debug_types
)
11010 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11011 const char *kind
= is_debug_types
? "TU" : "CU";
11012 void **dwo_file_slot
;
11013 struct dwo_file
*dwo_file
;
11014 struct dwp_file
*dwp_file
;
11016 /* First see if there's a DWP file.
11017 If we have a DWP file but didn't find the DWO inside it, don't
11018 look for the original DWO file. It makes gdb behave differently
11019 depending on whether one is debugging in the build tree. */
11021 dwp_file
= get_dwp_file ();
11022 if (dwp_file
!= NULL
)
11024 const struct dwp_hash_table
*dwp_htab
=
11025 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11027 if (dwp_htab
!= NULL
)
11029 struct dwo_unit
*dwo_cutu
=
11030 lookup_dwo_unit_in_dwp (dwp_file
, comp_dir
,
11031 signature
, is_debug_types
);
11033 if (dwo_cutu
!= NULL
)
11035 if (dwarf_read_debug
)
11037 fprintf_unfiltered (gdb_stdlog
,
11038 "Virtual DWO %s %s found: @%s\n",
11039 kind
, hex_string (signature
),
11040 host_address_to_string (dwo_cutu
));
11048 /* No DWP file, look for the DWO file. */
11050 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
, comp_dir
);
11051 if (*dwo_file_slot
== NULL
)
11053 /* Read in the file and build a table of the CUs/TUs it contains. */
11054 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
11056 /* NOTE: This will be NULL if unable to open the file. */
11057 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11059 if (dwo_file
!= NULL
)
11061 struct dwo_unit
*dwo_cutu
= NULL
;
11063 if (is_debug_types
&& dwo_file
->tus
)
11065 struct dwo_unit find_dwo_cutu
;
11067 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
11068 find_dwo_cutu
.signature
= signature
;
11070 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
11072 else if (!is_debug_types
&& dwo_file
->cu
)
11074 if (signature
== dwo_file
->cu
->signature
)
11075 dwo_cutu
= dwo_file
->cu
;
11078 if (dwo_cutu
!= NULL
)
11080 if (dwarf_read_debug
)
11082 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
11083 kind
, dwo_name
, hex_string (signature
),
11084 host_address_to_string (dwo_cutu
));
11091 /* We didn't find it. This could mean a dwo_id mismatch, or
11092 someone deleted the DWO/DWP file, or the search path isn't set up
11093 correctly to find the file. */
11095 if (dwarf_read_debug
)
11097 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
11098 kind
, dwo_name
, hex_string (signature
));
11101 /* This is a warning and not a complaint because it can be caused by
11102 pilot error (e.g., user accidentally deleting the DWO). */
11104 /* Print the name of the DWP file if we looked there, helps the user
11105 better diagnose the problem. */
11106 char *dwp_text
= NULL
;
11107 struct cleanup
*cleanups
;
11109 if (dwp_file
!= NULL
)
11110 dwp_text
= xstrprintf (" [in DWP file %s]", lbasename (dwp_file
->name
));
11111 cleanups
= make_cleanup (xfree
, dwp_text
);
11113 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset 0x%x"
11114 " [in module %s]"),
11115 kind
, dwo_name
, hex_string (signature
),
11116 dwp_text
!= NULL
? dwp_text
: "",
11117 this_unit
->is_debug_types
? "TU" : "CU",
11118 this_unit
->offset
.sect_off
, objfile_name (objfile
));
11120 do_cleanups (cleanups
);
11125 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
11126 See lookup_dwo_cutu_unit for details. */
11128 static struct dwo_unit
*
11129 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
11130 const char *dwo_name
, const char *comp_dir
,
11131 ULONGEST signature
)
11133 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
11136 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
11137 See lookup_dwo_cutu_unit for details. */
11139 static struct dwo_unit
*
11140 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
11141 const char *dwo_name
, const char *comp_dir
)
11143 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
11146 /* Traversal function for queue_and_load_all_dwo_tus. */
11149 queue_and_load_dwo_tu (void **slot
, void *info
)
11151 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
11152 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
11153 ULONGEST signature
= dwo_unit
->signature
;
11154 struct signatured_type
*sig_type
=
11155 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
11157 if (sig_type
!= NULL
)
11159 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
11161 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
11162 a real dependency of PER_CU on SIG_TYPE. That is detected later
11163 while processing PER_CU. */
11164 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
11165 load_full_type_unit (sig_cu
);
11166 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
11172 /* Queue all TUs contained in the DWO of PER_CU to be read in.
11173 The DWO may have the only definition of the type, though it may not be
11174 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
11175 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
11178 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
11180 struct dwo_unit
*dwo_unit
;
11181 struct dwo_file
*dwo_file
;
11183 gdb_assert (!per_cu
->is_debug_types
);
11184 gdb_assert (get_dwp_file () == NULL
);
11185 gdb_assert (per_cu
->cu
!= NULL
);
11187 dwo_unit
= per_cu
->cu
->dwo_unit
;
11188 gdb_assert (dwo_unit
!= NULL
);
11190 dwo_file
= dwo_unit
->dwo_file
;
11191 if (dwo_file
->tus
!= NULL
)
11192 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
11195 /* Free all resources associated with DWO_FILE.
11196 Close the DWO file and munmap the sections.
11197 All memory should be on the objfile obstack. */
11200 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
11203 /* Note: dbfd is NULL for virtual DWO files. */
11204 gdb_bfd_unref (dwo_file
->dbfd
);
11206 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
11209 /* Wrapper for free_dwo_file for use in cleanups. */
11212 free_dwo_file_cleanup (void *arg
)
11214 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
11215 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11217 free_dwo_file (dwo_file
, objfile
);
11220 /* Traversal function for free_dwo_files. */
11223 free_dwo_file_from_slot (void **slot
, void *info
)
11225 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
11226 struct objfile
*objfile
= (struct objfile
*) info
;
11228 free_dwo_file (dwo_file
, objfile
);
11233 /* Free all resources associated with DWO_FILES. */
11236 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
11238 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
11241 /* Read in various DIEs. */
11243 /* qsort helper for inherit_abstract_dies. */
11246 unsigned_int_compar (const void *ap
, const void *bp
)
11248 unsigned int a
= *(unsigned int *) ap
;
11249 unsigned int b
= *(unsigned int *) bp
;
11251 return (a
> b
) - (b
> a
);
11254 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
11255 Inherit only the children of the DW_AT_abstract_origin DIE not being
11256 already referenced by DW_AT_abstract_origin from the children of the
11260 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
11262 struct die_info
*child_die
;
11263 unsigned die_children_count
;
11264 /* CU offsets which were referenced by children of the current DIE. */
11265 sect_offset
*offsets
;
11266 sect_offset
*offsets_end
, *offsetp
;
11267 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
11268 struct die_info
*origin_die
;
11269 /* Iterator of the ORIGIN_DIE children. */
11270 struct die_info
*origin_child_die
;
11271 struct cleanup
*cleanups
;
11272 struct attribute
*attr
;
11273 struct dwarf2_cu
*origin_cu
;
11274 struct pending
**origin_previous_list_in_scope
;
11276 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11280 /* Note that following die references may follow to a die in a
11284 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
11286 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
11288 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
11289 origin_cu
->list_in_scope
= cu
->list_in_scope
;
11291 if (die
->tag
!= origin_die
->tag
11292 && !(die
->tag
== DW_TAG_inlined_subroutine
11293 && origin_die
->tag
== DW_TAG_subprogram
))
11294 complaint (&symfile_complaints
,
11295 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
11296 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
11298 child_die
= die
->child
;
11299 die_children_count
= 0;
11300 while (child_die
&& child_die
->tag
)
11302 child_die
= sibling_die (child_die
);
11303 die_children_count
++;
11305 offsets
= XNEWVEC (sect_offset
, die_children_count
);
11306 cleanups
= make_cleanup (xfree
, offsets
);
11308 offsets_end
= offsets
;
11309 for (child_die
= die
->child
;
11310 child_die
&& child_die
->tag
;
11311 child_die
= sibling_die (child_die
))
11313 struct die_info
*child_origin_die
;
11314 struct dwarf2_cu
*child_origin_cu
;
11316 /* We are trying to process concrete instance entries:
11317 DW_TAG_GNU_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
11318 it's not relevant to our analysis here. i.e. detecting DIEs that are
11319 present in the abstract instance but not referenced in the concrete
11321 if (child_die
->tag
== DW_TAG_GNU_call_site
)
11324 /* For each CHILD_DIE, find the corresponding child of
11325 ORIGIN_DIE. If there is more than one layer of
11326 DW_AT_abstract_origin, follow them all; there shouldn't be,
11327 but GCC versions at least through 4.4 generate this (GCC PR
11329 child_origin_die
= child_die
;
11330 child_origin_cu
= cu
;
11333 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
11337 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
11341 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
11342 counterpart may exist. */
11343 if (child_origin_die
!= child_die
)
11345 if (child_die
->tag
!= child_origin_die
->tag
11346 && !(child_die
->tag
== DW_TAG_inlined_subroutine
11347 && child_origin_die
->tag
== DW_TAG_subprogram
))
11348 complaint (&symfile_complaints
,
11349 _("Child DIE 0x%x and its abstract origin 0x%x have "
11350 "different tags"), child_die
->offset
.sect_off
,
11351 child_origin_die
->offset
.sect_off
);
11352 if (child_origin_die
->parent
!= origin_die
)
11353 complaint (&symfile_complaints
,
11354 _("Child DIE 0x%x and its abstract origin 0x%x have "
11355 "different parents"), child_die
->offset
.sect_off
,
11356 child_origin_die
->offset
.sect_off
);
11358 *offsets_end
++ = child_origin_die
->offset
;
11361 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
11362 unsigned_int_compar
);
11363 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
11364 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
11365 complaint (&symfile_complaints
,
11366 _("Multiple children of DIE 0x%x refer "
11367 "to DIE 0x%x as their abstract origin"),
11368 die
->offset
.sect_off
, offsetp
->sect_off
);
11371 origin_child_die
= origin_die
->child
;
11372 while (origin_child_die
&& origin_child_die
->tag
)
11374 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
11375 while (offsetp
< offsets_end
11376 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
11378 if (offsetp
>= offsets_end
11379 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
11381 /* Found that ORIGIN_CHILD_DIE is really not referenced.
11382 Check whether we're already processing ORIGIN_CHILD_DIE.
11383 This can happen with mutually referenced abstract_origins.
11385 if (!origin_child_die
->in_process
)
11386 process_die (origin_child_die
, origin_cu
);
11388 origin_child_die
= sibling_die (origin_child_die
);
11390 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
11392 do_cleanups (cleanups
);
11396 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11398 struct objfile
*objfile
= cu
->objfile
;
11399 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11400 struct context_stack
*newobj
;
11403 struct die_info
*child_die
;
11404 struct attribute
*attr
, *call_line
, *call_file
;
11406 CORE_ADDR baseaddr
;
11407 struct block
*block
;
11408 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11409 VEC (symbolp
) *template_args
= NULL
;
11410 struct template_symbol
*templ_func
= NULL
;
11414 /* If we do not have call site information, we can't show the
11415 caller of this inlined function. That's too confusing, so
11416 only use the scope for local variables. */
11417 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
11418 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
11419 if (call_line
== NULL
|| call_file
== NULL
)
11421 read_lexical_block_scope (die
, cu
);
11426 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11428 name
= dwarf2_name (die
, cu
);
11430 /* Ignore functions with missing or empty names. These are actually
11431 illegal according to the DWARF standard. */
11434 complaint (&symfile_complaints
,
11435 _("missing name for subprogram DIE at %d"),
11436 die
->offset
.sect_off
);
11440 /* Ignore functions with missing or invalid low and high pc attributes. */
11441 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
11442 <= PC_BOUNDS_INVALID
)
11444 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
11445 if (!attr
|| !DW_UNSND (attr
))
11446 complaint (&symfile_complaints
,
11447 _("cannot get low and high bounds "
11448 "for subprogram DIE at %d"),
11449 die
->offset
.sect_off
);
11453 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11454 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11456 /* If we have any template arguments, then we must allocate a
11457 different sort of symbol. */
11458 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
11460 if (child_die
->tag
== DW_TAG_template_type_param
11461 || child_die
->tag
== DW_TAG_template_value_param
)
11463 templ_func
= allocate_template_symbol (objfile
);
11464 templ_func
->base
.is_cplus_template_function
= 1;
11469 newobj
= push_context (0, lowpc
);
11470 newobj
->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
11471 (struct symbol
*) templ_func
);
11473 /* If there is a location expression for DW_AT_frame_base, record
11475 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
11477 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
11479 /* If there is a location for the static link, record it. */
11480 newobj
->static_link
= NULL
;
11481 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
11484 newobj
->static_link
11485 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
11486 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
11489 cu
->list_in_scope
= &local_symbols
;
11491 if (die
->child
!= NULL
)
11493 child_die
= die
->child
;
11494 while (child_die
&& child_die
->tag
)
11496 if (child_die
->tag
== DW_TAG_template_type_param
11497 || child_die
->tag
== DW_TAG_template_value_param
)
11499 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
11502 VEC_safe_push (symbolp
, template_args
, arg
);
11505 process_die (child_die
, cu
);
11506 child_die
= sibling_die (child_die
);
11510 inherit_abstract_dies (die
, cu
);
11512 /* If we have a DW_AT_specification, we might need to import using
11513 directives from the context of the specification DIE. See the
11514 comment in determine_prefix. */
11515 if (cu
->language
== language_cplus
11516 && dwarf2_attr (die
, DW_AT_specification
, cu
))
11518 struct dwarf2_cu
*spec_cu
= cu
;
11519 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
11523 child_die
= spec_die
->child
;
11524 while (child_die
&& child_die
->tag
)
11526 if (child_die
->tag
== DW_TAG_imported_module
)
11527 process_die (child_die
, spec_cu
);
11528 child_die
= sibling_die (child_die
);
11531 /* In some cases, GCC generates specification DIEs that
11532 themselves contain DW_AT_specification attributes. */
11533 spec_die
= die_specification (spec_die
, &spec_cu
);
11537 newobj
= pop_context ();
11538 /* Make a block for the local symbols within. */
11539 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
11540 newobj
->static_link
, lowpc
, highpc
);
11542 /* For C++, set the block's scope. */
11543 if ((cu
->language
== language_cplus
11544 || cu
->language
== language_fortran
11545 || cu
->language
== language_d
11546 || cu
->language
== language_rust
)
11547 && cu
->processing_has_namespace_info
)
11548 block_set_scope (block
, determine_prefix (die
, cu
),
11549 &objfile
->objfile_obstack
);
11551 /* If we have address ranges, record them. */
11552 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11554 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
11556 /* Attach template arguments to function. */
11557 if (! VEC_empty (symbolp
, template_args
))
11559 gdb_assert (templ_func
!= NULL
);
11561 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
11562 templ_func
->template_arguments
11563 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
11564 templ_func
->n_template_arguments
);
11565 memcpy (templ_func
->template_arguments
,
11566 VEC_address (symbolp
, template_args
),
11567 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
11568 VEC_free (symbolp
, template_args
);
11571 /* In C++, we can have functions nested inside functions (e.g., when
11572 a function declares a class that has methods). This means that
11573 when we finish processing a function scope, we may need to go
11574 back to building a containing block's symbol lists. */
11575 local_symbols
= newobj
->locals
;
11576 local_using_directives
= newobj
->local_using_directives
;
11578 /* If we've finished processing a top-level function, subsequent
11579 symbols go in the file symbol list. */
11580 if (outermost_context_p ())
11581 cu
->list_in_scope
= &file_symbols
;
11584 /* Process all the DIES contained within a lexical block scope. Start
11585 a new scope, process the dies, and then close the scope. */
11588 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11590 struct objfile
*objfile
= cu
->objfile
;
11591 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11592 struct context_stack
*newobj
;
11593 CORE_ADDR lowpc
, highpc
;
11594 struct die_info
*child_die
;
11595 CORE_ADDR baseaddr
;
11597 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11599 /* Ignore blocks with missing or invalid low and high pc attributes. */
11600 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
11601 as multiple lexical blocks? Handling children in a sane way would
11602 be nasty. Might be easier to properly extend generic blocks to
11603 describe ranges. */
11604 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
11606 case PC_BOUNDS_NOT_PRESENT
:
11607 /* DW_TAG_lexical_block has no attributes, process its children as if
11608 there was no wrapping by that DW_TAG_lexical_block.
11609 GCC does no longer produces such DWARF since GCC r224161. */
11610 for (child_die
= die
->child
;
11611 child_die
!= NULL
&& child_die
->tag
;
11612 child_die
= sibling_die (child_die
))
11613 process_die (child_die
, cu
);
11615 case PC_BOUNDS_INVALID
:
11618 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11619 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11621 push_context (0, lowpc
);
11622 if (die
->child
!= NULL
)
11624 child_die
= die
->child
;
11625 while (child_die
&& child_die
->tag
)
11627 process_die (child_die
, cu
);
11628 child_die
= sibling_die (child_die
);
11631 inherit_abstract_dies (die
, cu
);
11632 newobj
= pop_context ();
11634 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
11636 struct block
*block
11637 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
11638 newobj
->start_addr
, highpc
);
11640 /* Note that recording ranges after traversing children, as we
11641 do here, means that recording a parent's ranges entails
11642 walking across all its children's ranges as they appear in
11643 the address map, which is quadratic behavior.
11645 It would be nicer to record the parent's ranges before
11646 traversing its children, simply overriding whatever you find
11647 there. But since we don't even decide whether to create a
11648 block until after we've traversed its children, that's hard
11650 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11652 local_symbols
= newobj
->locals
;
11653 local_using_directives
= newobj
->local_using_directives
;
11656 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
11659 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11661 struct objfile
*objfile
= cu
->objfile
;
11662 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11663 CORE_ADDR pc
, baseaddr
;
11664 struct attribute
*attr
;
11665 struct call_site
*call_site
, call_site_local
;
11668 struct die_info
*child_die
;
11670 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11672 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11675 complaint (&symfile_complaints
,
11676 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
11677 "DIE 0x%x [in module %s]"),
11678 die
->offset
.sect_off
, objfile_name (objfile
));
11681 pc
= attr_value_as_address (attr
) + baseaddr
;
11682 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
11684 if (cu
->call_site_htab
== NULL
)
11685 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
11686 NULL
, &objfile
->objfile_obstack
,
11687 hashtab_obstack_allocate
, NULL
);
11688 call_site_local
.pc
= pc
;
11689 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
11692 complaint (&symfile_complaints
,
11693 _("Duplicate PC %s for DW_TAG_GNU_call_site "
11694 "DIE 0x%x [in module %s]"),
11695 paddress (gdbarch
, pc
), die
->offset
.sect_off
,
11696 objfile_name (objfile
));
11700 /* Count parameters at the caller. */
11703 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11704 child_die
= sibling_die (child_die
))
11706 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11708 complaint (&symfile_complaints
,
11709 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
11710 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11711 child_die
->tag
, child_die
->offset
.sect_off
,
11712 objfile_name (objfile
));
11720 = ((struct call_site
*)
11721 obstack_alloc (&objfile
->objfile_obstack
,
11722 sizeof (*call_site
)
11723 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
11725 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
11726 call_site
->pc
= pc
;
11728 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
11730 struct die_info
*func_die
;
11732 /* Skip also over DW_TAG_inlined_subroutine. */
11733 for (func_die
= die
->parent
;
11734 func_die
&& func_die
->tag
!= DW_TAG_subprogram
11735 && func_die
->tag
!= DW_TAG_subroutine_type
;
11736 func_die
= func_die
->parent
);
11738 /* DW_AT_GNU_all_call_sites is a superset
11739 of DW_AT_GNU_all_tail_call_sites. */
11741 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
11742 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
11744 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
11745 not complete. But keep CALL_SITE for look ups via call_site_htab,
11746 both the initial caller containing the real return address PC and
11747 the final callee containing the current PC of a chain of tail
11748 calls do not need to have the tail call list complete. But any
11749 function candidate for a virtual tail call frame searched via
11750 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
11751 determined unambiguously. */
11755 struct type
*func_type
= NULL
;
11758 func_type
= get_die_type (func_die
, cu
);
11759 if (func_type
!= NULL
)
11761 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
11763 /* Enlist this call site to the function. */
11764 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
11765 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
11768 complaint (&symfile_complaints
,
11769 _("Cannot find function owning DW_TAG_GNU_call_site "
11770 "DIE 0x%x [in module %s]"),
11771 die
->offset
.sect_off
, objfile_name (objfile
));
11775 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
11777 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11778 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
11779 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
11780 /* Keep NULL DWARF_BLOCK. */;
11781 else if (attr_form_is_block (attr
))
11783 struct dwarf2_locexpr_baton
*dlbaton
;
11785 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
11786 dlbaton
->data
= DW_BLOCK (attr
)->data
;
11787 dlbaton
->size
= DW_BLOCK (attr
)->size
;
11788 dlbaton
->per_cu
= cu
->per_cu
;
11790 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
11792 else if (attr_form_is_ref (attr
))
11794 struct dwarf2_cu
*target_cu
= cu
;
11795 struct die_info
*target_die
;
11797 target_die
= follow_die_ref (die
, attr
, &target_cu
);
11798 gdb_assert (target_cu
->objfile
== objfile
);
11799 if (die_is_declaration (target_die
, target_cu
))
11801 const char *target_physname
;
11803 /* Prefer the mangled name; otherwise compute the demangled one. */
11804 target_physname
= dwarf2_string_attr (target_die
,
11805 DW_AT_linkage_name
,
11807 if (target_physname
== NULL
)
11808 target_physname
= dwarf2_string_attr (target_die
,
11809 DW_AT_MIPS_linkage_name
,
11811 if (target_physname
== NULL
)
11812 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
11813 if (target_physname
== NULL
)
11814 complaint (&symfile_complaints
,
11815 _("DW_AT_GNU_call_site_target target DIE has invalid "
11816 "physname, for referencing DIE 0x%x [in module %s]"),
11817 die
->offset
.sect_off
, objfile_name (objfile
));
11819 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
11825 /* DW_AT_entry_pc should be preferred. */
11826 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
11827 <= PC_BOUNDS_INVALID
)
11828 complaint (&symfile_complaints
,
11829 _("DW_AT_GNU_call_site_target target DIE has invalid "
11830 "low pc, for referencing DIE 0x%x [in module %s]"),
11831 die
->offset
.sect_off
, objfile_name (objfile
));
11834 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11835 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
11840 complaint (&symfile_complaints
,
11841 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
11842 "block nor reference, for DIE 0x%x [in module %s]"),
11843 die
->offset
.sect_off
, objfile_name (objfile
));
11845 call_site
->per_cu
= cu
->per_cu
;
11847 for (child_die
= die
->child
;
11848 child_die
&& child_die
->tag
;
11849 child_die
= sibling_die (child_die
))
11851 struct call_site_parameter
*parameter
;
11852 struct attribute
*loc
, *origin
;
11854 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11856 /* Already printed the complaint above. */
11860 gdb_assert (call_site
->parameter_count
< nparams
);
11861 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
11863 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
11864 specifies DW_TAG_formal_parameter. Value of the data assumed for the
11865 register is contained in DW_AT_GNU_call_site_value. */
11867 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
11868 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
11869 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
11871 sect_offset offset
;
11873 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
11874 offset
= dwarf2_get_ref_die_offset (origin
);
11875 if (!offset_in_cu_p (&cu
->header
, offset
))
11877 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
11878 binding can be done only inside one CU. Such referenced DIE
11879 therefore cannot be even moved to DW_TAG_partial_unit. */
11880 complaint (&symfile_complaints
,
11881 _("DW_AT_abstract_origin offset is not in CU for "
11882 "DW_TAG_GNU_call_site child DIE 0x%x "
11884 child_die
->offset
.sect_off
, objfile_name (objfile
));
11887 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
11888 - cu
->header
.offset
.sect_off
);
11890 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
11892 complaint (&symfile_complaints
,
11893 _("No DW_FORM_block* DW_AT_location for "
11894 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11895 child_die
->offset
.sect_off
, objfile_name (objfile
));
11900 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
11901 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
11902 if (parameter
->u
.dwarf_reg
!= -1)
11903 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
11904 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
11905 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
11906 ¶meter
->u
.fb_offset
))
11907 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
11910 complaint (&symfile_complaints
,
11911 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
11912 "for DW_FORM_block* DW_AT_location is supported for "
11913 "DW_TAG_GNU_call_site child DIE 0x%x "
11915 child_die
->offset
.sect_off
, objfile_name (objfile
));
11920 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
11921 if (!attr_form_is_block (attr
))
11923 complaint (&symfile_complaints
,
11924 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
11925 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11926 child_die
->offset
.sect_off
, objfile_name (objfile
));
11929 parameter
->value
= DW_BLOCK (attr
)->data
;
11930 parameter
->value_size
= DW_BLOCK (attr
)->size
;
11932 /* Parameters are not pre-cleared by memset above. */
11933 parameter
->data_value
= NULL
;
11934 parameter
->data_value_size
= 0;
11935 call_site
->parameter_count
++;
11937 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
11940 if (!attr_form_is_block (attr
))
11941 complaint (&symfile_complaints
,
11942 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
11943 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11944 child_die
->offset
.sect_off
, objfile_name (objfile
));
11947 parameter
->data_value
= DW_BLOCK (attr
)->data
;
11948 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
11954 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
11955 reading .debug_rnglists.
11956 Callback's type should be:
11957 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
11958 Return true if the attributes are present and valid, otherwise,
11961 template <typename Callback
>
11963 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
11964 Callback
&&callback
)
11966 struct objfile
*objfile
= cu
->objfile
;
11967 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11968 struct comp_unit_head
*cu_header
= &cu
->header
;
11969 bfd
*obfd
= objfile
->obfd
;
11970 unsigned int addr_size
= cu_header
->addr_size
;
11971 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
11972 /* Base address selection entry. */
11975 unsigned int dummy
;
11976 const gdb_byte
*buffer
;
11978 CORE_ADDR high
= 0;
11979 CORE_ADDR baseaddr
;
11980 bool overflow
= false;
11982 found_base
= cu
->base_known
;
11983 base
= cu
->base_address
;
11985 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
11986 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
11988 complaint (&symfile_complaints
,
11989 _("Offset %d out of bounds for DW_AT_ranges attribute"),
11993 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
11995 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11999 CORE_ADDR range_beginning
, range_end
;
12000 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
12001 + dwarf2_per_objfile
->rnglists
.size
);
12002 unsigned int bytes_read
;
12004 if (buffer
== buf_end
)
12009 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
12012 case DW_RLE_end_of_list
:
12014 case DW_RLE_base_address
:
12015 if (buffer
+ cu
->header
.addr_size
> buf_end
)
12020 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12022 buffer
+= bytes_read
;
12024 case DW_RLE_start_length
:
12025 if (buffer
+ cu
->header
.addr_size
> buf_end
)
12030 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12031 buffer
+= bytes_read
;
12032 range_end
= (range_beginning
12033 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
12034 buffer
+= bytes_read
;
12035 if (buffer
> buf_end
)
12041 case DW_RLE_offset_pair
:
12042 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12043 buffer
+= bytes_read
;
12044 if (buffer
> buf_end
)
12049 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12050 buffer
+= bytes_read
;
12051 if (buffer
> buf_end
)
12057 case DW_RLE_start_end
:
12058 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
12063 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12064 buffer
+= bytes_read
;
12065 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12066 buffer
+= bytes_read
;
12069 complaint (&symfile_complaints
,
12070 _("Invalid .debug_rnglists data (no base address)"));
12073 if (rlet
== DW_RLE_end_of_list
|| overflow
)
12075 if (rlet
== DW_RLE_base_address
)
12080 /* We have no valid base address for the ranges
12082 complaint (&symfile_complaints
,
12083 _("Invalid .debug_rnglists data (no base address)"));
12087 if (range_beginning
> range_end
)
12089 /* Inverted range entries are invalid. */
12090 complaint (&symfile_complaints
,
12091 _("Invalid .debug_rnglists data (inverted range)"));
12095 /* Empty range entries have no effect. */
12096 if (range_beginning
== range_end
)
12099 range_beginning
+= base
;
12102 /* A not-uncommon case of bad debug info.
12103 Don't pollute the addrmap with bad data. */
12104 if (range_beginning
+ baseaddr
== 0
12105 && !dwarf2_per_objfile
->has_section_at_zero
)
12107 complaint (&symfile_complaints
,
12108 _(".debug_rnglists entry has start address of zero"
12109 " [in module %s]"), objfile_name (objfile
));
12113 callback (range_beginning
, range_end
);
12118 complaint (&symfile_complaints
,
12119 _("Offset %d is not terminated "
12120 "for DW_AT_ranges attribute"),
12128 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
12129 Callback's type should be:
12130 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
12131 Return 1 if the attributes are present and valid, otherwise, return 0. */
12133 template <typename Callback
>
12135 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
12136 Callback
&&callback
)
12138 struct objfile
*objfile
= cu
->objfile
;
12139 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12140 struct comp_unit_head
*cu_header
= &cu
->header
;
12141 bfd
*obfd
= objfile
->obfd
;
12142 unsigned int addr_size
= cu_header
->addr_size
;
12143 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12144 /* Base address selection entry. */
12147 unsigned int dummy
;
12148 const gdb_byte
*buffer
;
12149 CORE_ADDR baseaddr
;
12151 if (cu_header
->version
>= 5)
12152 return dwarf2_rnglists_process (offset
, cu
, callback
);
12154 found_base
= cu
->base_known
;
12155 base
= cu
->base_address
;
12157 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
12158 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
12160 complaint (&symfile_complaints
,
12161 _("Offset %d out of bounds for DW_AT_ranges attribute"),
12165 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
12167 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12171 CORE_ADDR range_beginning
, range_end
;
12173 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
12174 buffer
+= addr_size
;
12175 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
12176 buffer
+= addr_size
;
12177 offset
+= 2 * addr_size
;
12179 /* An end of list marker is a pair of zero addresses. */
12180 if (range_beginning
== 0 && range_end
== 0)
12181 /* Found the end of list entry. */
12184 /* Each base address selection entry is a pair of 2 values.
12185 The first is the largest possible address, the second is
12186 the base address. Check for a base address here. */
12187 if ((range_beginning
& mask
) == mask
)
12189 /* If we found the largest possible address, then we already
12190 have the base address in range_end. */
12198 /* We have no valid base address for the ranges
12200 complaint (&symfile_complaints
,
12201 _("Invalid .debug_ranges data (no base address)"));
12205 if (range_beginning
> range_end
)
12207 /* Inverted range entries are invalid. */
12208 complaint (&symfile_complaints
,
12209 _("Invalid .debug_ranges data (inverted range)"));
12213 /* Empty range entries have no effect. */
12214 if (range_beginning
== range_end
)
12217 range_beginning
+= base
;
12220 /* A not-uncommon case of bad debug info.
12221 Don't pollute the addrmap with bad data. */
12222 if (range_beginning
+ baseaddr
== 0
12223 && !dwarf2_per_objfile
->has_section_at_zero
)
12225 complaint (&symfile_complaints
,
12226 _(".debug_ranges entry has start address of zero"
12227 " [in module %s]"), objfile_name (objfile
));
12231 callback (range_beginning
, range_end
);
12237 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
12238 Return 1 if the attributes are present and valid, otherwise, return 0.
12239 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
12242 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
12243 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
12244 struct partial_symtab
*ranges_pst
)
12246 struct objfile
*objfile
= cu
->objfile
;
12247 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12248 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
12249 SECT_OFF_TEXT (objfile
));
12252 CORE_ADDR high
= 0;
12255 retval
= dwarf2_ranges_process (offset
, cu
,
12256 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
12258 if (ranges_pst
!= NULL
)
12263 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
12264 range_beginning
+ baseaddr
);
12265 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
12266 range_end
+ baseaddr
);
12267 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
12271 /* FIXME: This is recording everything as a low-high
12272 segment of consecutive addresses. We should have a
12273 data structure for discontiguous block ranges
12277 low
= range_beginning
;
12283 if (range_beginning
< low
)
12284 low
= range_beginning
;
12285 if (range_end
> high
)
12293 /* If the first entry is an end-of-list marker, the range
12294 describes an empty scope, i.e. no instructions. */
12300 *high_return
= high
;
12304 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
12305 definition for the return value. *LOWPC and *HIGHPC are set iff
12306 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
12308 static enum pc_bounds_kind
12309 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
12310 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
12311 struct partial_symtab
*pst
)
12313 struct attribute
*attr
;
12314 struct attribute
*attr_high
;
12316 CORE_ADDR high
= 0;
12317 enum pc_bounds_kind ret
;
12319 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12322 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12325 low
= attr_value_as_address (attr
);
12326 high
= attr_value_as_address (attr_high
);
12327 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12331 /* Found high w/o low attribute. */
12332 return PC_BOUNDS_INVALID
;
12334 /* Found consecutive range of addresses. */
12335 ret
= PC_BOUNDS_HIGH_LOW
;
12339 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12342 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12343 We take advantage of the fact that DW_AT_ranges does not appear
12344 in DW_TAG_compile_unit of DWO files. */
12345 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12346 unsigned int ranges_offset
= (DW_UNSND (attr
)
12347 + (need_ranges_base
12351 /* Value of the DW_AT_ranges attribute is the offset in the
12352 .debug_ranges section. */
12353 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
12354 return PC_BOUNDS_INVALID
;
12355 /* Found discontinuous range of addresses. */
12356 ret
= PC_BOUNDS_RANGES
;
12359 return PC_BOUNDS_NOT_PRESENT
;
12362 /* read_partial_die has also the strict LOW < HIGH requirement. */
12364 return PC_BOUNDS_INVALID
;
12366 /* When using the GNU linker, .gnu.linkonce. sections are used to
12367 eliminate duplicate copies of functions and vtables and such.
12368 The linker will arbitrarily choose one and discard the others.
12369 The AT_*_pc values for such functions refer to local labels in
12370 these sections. If the section from that file was discarded, the
12371 labels are not in the output, so the relocs get a value of 0.
12372 If this is a discarded function, mark the pc bounds as invalid,
12373 so that GDB will ignore it. */
12374 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12375 return PC_BOUNDS_INVALID
;
12383 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
12384 its low and high PC addresses. Do nothing if these addresses could not
12385 be determined. Otherwise, set LOWPC to the low address if it is smaller,
12386 and HIGHPC to the high address if greater than HIGHPC. */
12389 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
12390 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12391 struct dwarf2_cu
*cu
)
12393 CORE_ADDR low
, high
;
12394 struct die_info
*child
= die
->child
;
12396 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
12398 *lowpc
= std::min (*lowpc
, low
);
12399 *highpc
= std::max (*highpc
, high
);
12402 /* If the language does not allow nested subprograms (either inside
12403 subprograms or lexical blocks), we're done. */
12404 if (cu
->language
!= language_ada
)
12407 /* Check all the children of the given DIE. If it contains nested
12408 subprograms, then check their pc bounds. Likewise, we need to
12409 check lexical blocks as well, as they may also contain subprogram
12411 while (child
&& child
->tag
)
12413 if (child
->tag
== DW_TAG_subprogram
12414 || child
->tag
== DW_TAG_lexical_block
)
12415 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
12416 child
= sibling_die (child
);
12420 /* Get the low and high pc's represented by the scope DIE, and store
12421 them in *LOWPC and *HIGHPC. If the correct values can't be
12422 determined, set *LOWPC to -1 and *HIGHPC to 0. */
12425 get_scope_pc_bounds (struct die_info
*die
,
12426 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12427 struct dwarf2_cu
*cu
)
12429 CORE_ADDR best_low
= (CORE_ADDR
) -1;
12430 CORE_ADDR best_high
= (CORE_ADDR
) 0;
12431 CORE_ADDR current_low
, current_high
;
12433 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
12434 >= PC_BOUNDS_RANGES
)
12436 best_low
= current_low
;
12437 best_high
= current_high
;
12441 struct die_info
*child
= die
->child
;
12443 while (child
&& child
->tag
)
12445 switch (child
->tag
) {
12446 case DW_TAG_subprogram
:
12447 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
12449 case DW_TAG_namespace
:
12450 case DW_TAG_module
:
12451 /* FIXME: carlton/2004-01-16: Should we do this for
12452 DW_TAG_class_type/DW_TAG_structure_type, too? I think
12453 that current GCC's always emit the DIEs corresponding
12454 to definitions of methods of classes as children of a
12455 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
12456 the DIEs giving the declarations, which could be
12457 anywhere). But I don't see any reason why the
12458 standards says that they have to be there. */
12459 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
12461 if (current_low
!= ((CORE_ADDR
) -1))
12463 best_low
= std::min (best_low
, current_low
);
12464 best_high
= std::max (best_high
, current_high
);
12472 child
= sibling_die (child
);
12477 *highpc
= best_high
;
12480 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
12484 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
12485 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
12487 struct objfile
*objfile
= cu
->objfile
;
12488 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12489 struct attribute
*attr
;
12490 struct attribute
*attr_high
;
12492 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12495 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12498 CORE_ADDR low
= attr_value_as_address (attr
);
12499 CORE_ADDR high
= attr_value_as_address (attr_high
);
12501 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12504 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
12505 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
12506 record_block_range (block
, low
, high
- 1);
12510 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12513 bfd
*obfd
= objfile
->obfd
;
12514 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12515 We take advantage of the fact that DW_AT_ranges does not appear
12516 in DW_TAG_compile_unit of DWO files. */
12517 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12519 /* The value of the DW_AT_ranges attribute is the offset of the
12520 address range list in the .debug_ranges section. */
12521 unsigned long offset
= (DW_UNSND (attr
)
12522 + (need_ranges_base
? cu
->ranges_base
: 0));
12523 const gdb_byte
*buffer
;
12525 /* For some target architectures, but not others, the
12526 read_address function sign-extends the addresses it returns.
12527 To recognize base address selection entries, we need a
12529 unsigned int addr_size
= cu
->header
.addr_size
;
12530 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12532 /* The base address, to which the next pair is relative. Note
12533 that this 'base' is a DWARF concept: most entries in a range
12534 list are relative, to reduce the number of relocs against the
12535 debugging information. This is separate from this function's
12536 'baseaddr' argument, which GDB uses to relocate debugging
12537 information from a shared library based on the address at
12538 which the library was loaded. */
12539 CORE_ADDR base
= cu
->base_address
;
12540 int base_known
= cu
->base_known
;
12542 dwarf2_ranges_process (offset
, cu
,
12543 [&] (CORE_ADDR start
, CORE_ADDR end
)
12545 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
12546 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
12547 record_block_range (block
, start
, end
- 1);
12552 /* Check whether the producer field indicates either of GCC < 4.6, or the
12553 Intel C/C++ compiler, and cache the result in CU. */
12556 check_producer (struct dwarf2_cu
*cu
)
12560 if (cu
->producer
== NULL
)
12562 /* For unknown compilers expect their behavior is DWARF version
12565 GCC started to support .debug_types sections by -gdwarf-4 since
12566 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
12567 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
12568 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
12569 interpreted incorrectly by GDB now - GCC PR debug/48229. */
12571 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
12573 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
12574 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
12576 else if (startswith (cu
->producer
, "Intel(R) C"))
12577 cu
->producer_is_icc
= 1;
12580 /* For other non-GCC compilers, expect their behavior is DWARF version
12584 cu
->checked_producer
= 1;
12587 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
12588 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
12589 during 4.6.0 experimental. */
12592 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
12594 if (!cu
->checked_producer
)
12595 check_producer (cu
);
12597 return cu
->producer_is_gxx_lt_4_6
;
12600 /* Return the default accessibility type if it is not overriden by
12601 DW_AT_accessibility. */
12603 static enum dwarf_access_attribute
12604 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
12606 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
12608 /* The default DWARF 2 accessibility for members is public, the default
12609 accessibility for inheritance is private. */
12611 if (die
->tag
!= DW_TAG_inheritance
)
12612 return DW_ACCESS_public
;
12614 return DW_ACCESS_private
;
12618 /* DWARF 3+ defines the default accessibility a different way. The same
12619 rules apply now for DW_TAG_inheritance as for the members and it only
12620 depends on the container kind. */
12622 if (die
->parent
->tag
== DW_TAG_class_type
)
12623 return DW_ACCESS_private
;
12625 return DW_ACCESS_public
;
12629 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
12630 offset. If the attribute was not found return 0, otherwise return
12631 1. If it was found but could not properly be handled, set *OFFSET
12635 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
12638 struct attribute
*attr
;
12640 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
12645 /* Note that we do not check for a section offset first here.
12646 This is because DW_AT_data_member_location is new in DWARF 4,
12647 so if we see it, we can assume that a constant form is really
12648 a constant and not a section offset. */
12649 if (attr_form_is_constant (attr
))
12650 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
12651 else if (attr_form_is_section_offset (attr
))
12652 dwarf2_complex_location_expr_complaint ();
12653 else if (attr_form_is_block (attr
))
12654 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
12656 dwarf2_complex_location_expr_complaint ();
12664 /* Add an aggregate field to the field list. */
12667 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
12668 struct dwarf2_cu
*cu
)
12670 struct objfile
*objfile
= cu
->objfile
;
12671 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12672 struct nextfield
*new_field
;
12673 struct attribute
*attr
;
12675 const char *fieldname
= "";
12677 /* Allocate a new field list entry and link it in. */
12678 new_field
= XNEW (struct nextfield
);
12679 make_cleanup (xfree
, new_field
);
12680 memset (new_field
, 0, sizeof (struct nextfield
));
12682 if (die
->tag
== DW_TAG_inheritance
)
12684 new_field
->next
= fip
->baseclasses
;
12685 fip
->baseclasses
= new_field
;
12689 new_field
->next
= fip
->fields
;
12690 fip
->fields
= new_field
;
12694 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
12696 new_field
->accessibility
= DW_UNSND (attr
);
12698 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
12699 if (new_field
->accessibility
!= DW_ACCESS_public
)
12700 fip
->non_public_fields
= 1;
12702 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
12704 new_field
->virtuality
= DW_UNSND (attr
);
12706 new_field
->virtuality
= DW_VIRTUALITY_none
;
12708 fp
= &new_field
->field
;
12710 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
12714 /* Data member other than a C++ static data member. */
12716 /* Get type of field. */
12717 fp
->type
= die_type (die
, cu
);
12719 SET_FIELD_BITPOS (*fp
, 0);
12721 /* Get bit size of field (zero if none). */
12722 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
12725 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
12729 FIELD_BITSIZE (*fp
) = 0;
12732 /* Get bit offset of field. */
12733 if (handle_data_member_location (die
, cu
, &offset
))
12734 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12735 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
12738 if (gdbarch_bits_big_endian (gdbarch
))
12740 /* For big endian bits, the DW_AT_bit_offset gives the
12741 additional bit offset from the MSB of the containing
12742 anonymous object to the MSB of the field. We don't
12743 have to do anything special since we don't need to
12744 know the size of the anonymous object. */
12745 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
12749 /* For little endian bits, compute the bit offset to the
12750 MSB of the anonymous object, subtract off the number of
12751 bits from the MSB of the field to the MSB of the
12752 object, and then subtract off the number of bits of
12753 the field itself. The result is the bit offset of
12754 the LSB of the field. */
12755 int anonymous_size
;
12756 int bit_offset
= DW_UNSND (attr
);
12758 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12761 /* The size of the anonymous object containing
12762 the bit field is explicit, so use the
12763 indicated size (in bytes). */
12764 anonymous_size
= DW_UNSND (attr
);
12768 /* The size of the anonymous object containing
12769 the bit field must be inferred from the type
12770 attribute of the data member containing the
12772 anonymous_size
= TYPE_LENGTH (fp
->type
);
12774 SET_FIELD_BITPOS (*fp
,
12775 (FIELD_BITPOS (*fp
)
12776 + anonymous_size
* bits_per_byte
12777 - bit_offset
- FIELD_BITSIZE (*fp
)));
12780 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
12782 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
12783 + dwarf2_get_attr_constant_value (attr
, 0)));
12785 /* Get name of field. */
12786 fieldname
= dwarf2_name (die
, cu
);
12787 if (fieldname
== NULL
)
12790 /* The name is already allocated along with this objfile, so we don't
12791 need to duplicate it for the type. */
12792 fp
->name
= fieldname
;
12794 /* Change accessibility for artificial fields (e.g. virtual table
12795 pointer or virtual base class pointer) to private. */
12796 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
12798 FIELD_ARTIFICIAL (*fp
) = 1;
12799 new_field
->accessibility
= DW_ACCESS_private
;
12800 fip
->non_public_fields
= 1;
12803 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
12805 /* C++ static member. */
12807 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
12808 is a declaration, but all versions of G++ as of this writing
12809 (so through at least 3.2.1) incorrectly generate
12810 DW_TAG_variable tags. */
12812 const char *physname
;
12814 /* Get name of field. */
12815 fieldname
= dwarf2_name (die
, cu
);
12816 if (fieldname
== NULL
)
12819 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12821 /* Only create a symbol if this is an external value.
12822 new_symbol checks this and puts the value in the global symbol
12823 table, which we want. If it is not external, new_symbol
12824 will try to put the value in cu->list_in_scope which is wrong. */
12825 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
12827 /* A static const member, not much different than an enum as far as
12828 we're concerned, except that we can support more types. */
12829 new_symbol (die
, NULL
, cu
);
12832 /* Get physical name. */
12833 physname
= dwarf2_physname (fieldname
, die
, cu
);
12835 /* The name is already allocated along with this objfile, so we don't
12836 need to duplicate it for the type. */
12837 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
12838 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12839 FIELD_NAME (*fp
) = fieldname
;
12841 else if (die
->tag
== DW_TAG_inheritance
)
12845 /* C++ base class field. */
12846 if (handle_data_member_location (die
, cu
, &offset
))
12847 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12848 FIELD_BITSIZE (*fp
) = 0;
12849 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12850 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
12851 fip
->nbaseclasses
++;
12855 /* Add a typedef defined in the scope of the FIP's class. */
12858 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
12859 struct dwarf2_cu
*cu
)
12861 struct typedef_field_list
*new_field
;
12862 struct typedef_field
*fp
;
12864 /* Allocate a new field list entry and link it in. */
12865 new_field
= XCNEW (struct typedef_field_list
);
12866 make_cleanup (xfree
, new_field
);
12868 gdb_assert (die
->tag
== DW_TAG_typedef
);
12870 fp
= &new_field
->field
;
12872 /* Get name of field. */
12873 fp
->name
= dwarf2_name (die
, cu
);
12874 if (fp
->name
== NULL
)
12877 fp
->type
= read_type_die (die
, cu
);
12879 new_field
->next
= fip
->typedef_field_list
;
12880 fip
->typedef_field_list
= new_field
;
12881 fip
->typedef_field_list_count
++;
12884 /* Create the vector of fields, and attach it to the type. */
12887 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
12888 struct dwarf2_cu
*cu
)
12890 int nfields
= fip
->nfields
;
12892 /* Record the field count, allocate space for the array of fields,
12893 and create blank accessibility bitfields if necessary. */
12894 TYPE_NFIELDS (type
) = nfields
;
12895 TYPE_FIELDS (type
) = (struct field
*)
12896 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
12897 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
12899 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
12901 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12903 TYPE_FIELD_PRIVATE_BITS (type
) =
12904 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12905 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
12907 TYPE_FIELD_PROTECTED_BITS (type
) =
12908 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12909 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
12911 TYPE_FIELD_IGNORE_BITS (type
) =
12912 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12913 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
12916 /* If the type has baseclasses, allocate and clear a bit vector for
12917 TYPE_FIELD_VIRTUAL_BITS. */
12918 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
12920 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
12921 unsigned char *pointer
;
12923 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12924 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
12925 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
12926 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
12927 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
12930 /* Copy the saved-up fields into the field vector. Start from the head of
12931 the list, adding to the tail of the field array, so that they end up in
12932 the same order in the array in which they were added to the list. */
12933 while (nfields
-- > 0)
12935 struct nextfield
*fieldp
;
12939 fieldp
= fip
->fields
;
12940 fip
->fields
= fieldp
->next
;
12944 fieldp
= fip
->baseclasses
;
12945 fip
->baseclasses
= fieldp
->next
;
12948 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
12949 switch (fieldp
->accessibility
)
12951 case DW_ACCESS_private
:
12952 if (cu
->language
!= language_ada
)
12953 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
12956 case DW_ACCESS_protected
:
12957 if (cu
->language
!= language_ada
)
12958 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
12961 case DW_ACCESS_public
:
12965 /* Unknown accessibility. Complain and treat it as public. */
12967 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
12968 fieldp
->accessibility
);
12972 if (nfields
< fip
->nbaseclasses
)
12974 switch (fieldp
->virtuality
)
12976 case DW_VIRTUALITY_virtual
:
12977 case DW_VIRTUALITY_pure_virtual
:
12978 if (cu
->language
== language_ada
)
12979 error (_("unexpected virtuality in component of Ada type"));
12980 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
12987 /* Return true if this member function is a constructor, false
12991 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
12993 const char *fieldname
;
12994 const char *type_name
;
12997 if (die
->parent
== NULL
)
13000 if (die
->parent
->tag
!= DW_TAG_structure_type
13001 && die
->parent
->tag
!= DW_TAG_union_type
13002 && die
->parent
->tag
!= DW_TAG_class_type
)
13005 fieldname
= dwarf2_name (die
, cu
);
13006 type_name
= dwarf2_name (die
->parent
, cu
);
13007 if (fieldname
== NULL
|| type_name
== NULL
)
13010 len
= strlen (fieldname
);
13011 return (strncmp (fieldname
, type_name
, len
) == 0
13012 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
13015 /* Add a member function to the proper fieldlist. */
13018 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
13019 struct type
*type
, struct dwarf2_cu
*cu
)
13021 struct objfile
*objfile
= cu
->objfile
;
13022 struct attribute
*attr
;
13023 struct fnfieldlist
*flp
;
13025 struct fn_field
*fnp
;
13026 const char *fieldname
;
13027 struct nextfnfield
*new_fnfield
;
13028 struct type
*this_type
;
13029 enum dwarf_access_attribute accessibility
;
13031 if (cu
->language
== language_ada
)
13032 error (_("unexpected member function in Ada type"));
13034 /* Get name of member function. */
13035 fieldname
= dwarf2_name (die
, cu
);
13036 if (fieldname
== NULL
)
13039 /* Look up member function name in fieldlist. */
13040 for (i
= 0; i
< fip
->nfnfields
; i
++)
13042 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
13046 /* Create new list element if necessary. */
13047 if (i
< fip
->nfnfields
)
13048 flp
= &fip
->fnfieldlists
[i
];
13051 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
13053 fip
->fnfieldlists
= (struct fnfieldlist
*)
13054 xrealloc (fip
->fnfieldlists
,
13055 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
13056 * sizeof (struct fnfieldlist
));
13057 if (fip
->nfnfields
== 0)
13058 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
13060 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
13061 flp
->name
= fieldname
;
13064 i
= fip
->nfnfields
++;
13067 /* Create a new member function field and chain it to the field list
13069 new_fnfield
= XNEW (struct nextfnfield
);
13070 make_cleanup (xfree
, new_fnfield
);
13071 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
13072 new_fnfield
->next
= flp
->head
;
13073 flp
->head
= new_fnfield
;
13076 /* Fill in the member function field info. */
13077 fnp
= &new_fnfield
->fnfield
;
13079 /* Delay processing of the physname until later. */
13080 if (cu
->language
== language_cplus
)
13082 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
13087 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
13088 fnp
->physname
= physname
? physname
: "";
13091 fnp
->type
= alloc_type (objfile
);
13092 this_type
= read_type_die (die
, cu
);
13093 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
13095 int nparams
= TYPE_NFIELDS (this_type
);
13097 /* TYPE is the domain of this method, and THIS_TYPE is the type
13098 of the method itself (TYPE_CODE_METHOD). */
13099 smash_to_method_type (fnp
->type
, type
,
13100 TYPE_TARGET_TYPE (this_type
),
13101 TYPE_FIELDS (this_type
),
13102 TYPE_NFIELDS (this_type
),
13103 TYPE_VARARGS (this_type
));
13105 /* Handle static member functions.
13106 Dwarf2 has no clean way to discern C++ static and non-static
13107 member functions. G++ helps GDB by marking the first
13108 parameter for non-static member functions (which is the this
13109 pointer) as artificial. We obtain this information from
13110 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
13111 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
13112 fnp
->voffset
= VOFFSET_STATIC
;
13115 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
13116 dwarf2_full_name (fieldname
, die
, cu
));
13118 /* Get fcontext from DW_AT_containing_type if present. */
13119 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
13120 fnp
->fcontext
= die_containing_type (die
, cu
);
13122 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
13123 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
13125 /* Get accessibility. */
13126 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
13128 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
13130 accessibility
= dwarf2_default_access_attribute (die
, cu
);
13131 switch (accessibility
)
13133 case DW_ACCESS_private
:
13134 fnp
->is_private
= 1;
13136 case DW_ACCESS_protected
:
13137 fnp
->is_protected
= 1;
13141 /* Check for artificial methods. */
13142 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
13143 if (attr
&& DW_UNSND (attr
) != 0)
13144 fnp
->is_artificial
= 1;
13146 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
13148 /* Get index in virtual function table if it is a virtual member
13149 function. For older versions of GCC, this is an offset in the
13150 appropriate virtual table, as specified by DW_AT_containing_type.
13151 For everyone else, it is an expression to be evaluated relative
13152 to the object address. */
13154 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
13157 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
13159 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
13161 /* Old-style GCC. */
13162 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
13164 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
13165 || (DW_BLOCK (attr
)->size
> 1
13166 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
13167 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
13169 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
13170 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
13171 dwarf2_complex_location_expr_complaint ();
13173 fnp
->voffset
/= cu
->header
.addr_size
;
13177 dwarf2_complex_location_expr_complaint ();
13179 if (!fnp
->fcontext
)
13181 /* If there is no `this' field and no DW_AT_containing_type,
13182 we cannot actually find a base class context for the
13184 if (TYPE_NFIELDS (this_type
) == 0
13185 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
13187 complaint (&symfile_complaints
,
13188 _("cannot determine context for virtual member "
13189 "function \"%s\" (offset %d)"),
13190 fieldname
, die
->offset
.sect_off
);
13195 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
13199 else if (attr_form_is_section_offset (attr
))
13201 dwarf2_complex_location_expr_complaint ();
13205 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
13211 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
13212 if (attr
&& DW_UNSND (attr
))
13214 /* GCC does this, as of 2008-08-25; PR debug/37237. */
13215 complaint (&symfile_complaints
,
13216 _("Member function \"%s\" (offset %d) is virtual "
13217 "but the vtable offset is not specified"),
13218 fieldname
, die
->offset
.sect_off
);
13219 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13220 TYPE_CPLUS_DYNAMIC (type
) = 1;
13225 /* Create the vector of member function fields, and attach it to the type. */
13228 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
13229 struct dwarf2_cu
*cu
)
13231 struct fnfieldlist
*flp
;
13234 if (cu
->language
== language_ada
)
13235 error (_("unexpected member functions in Ada type"));
13237 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13238 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
13239 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
13241 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
13243 struct nextfnfield
*nfp
= flp
->head
;
13244 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
13247 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
13248 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
13249 fn_flp
->fn_fields
= (struct fn_field
*)
13250 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
13251 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
13252 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
13255 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
13258 /* Returns non-zero if NAME is the name of a vtable member in CU's
13259 language, zero otherwise. */
13261 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
13263 static const char vptr
[] = "_vptr";
13264 static const char vtable
[] = "vtable";
13266 /* Look for the C++ form of the vtable. */
13267 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
13273 /* GCC outputs unnamed structures that are really pointers to member
13274 functions, with the ABI-specified layout. If TYPE describes
13275 such a structure, smash it into a member function type.
13277 GCC shouldn't do this; it should just output pointer to member DIEs.
13278 This is GCC PR debug/28767. */
13281 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
13283 struct type
*pfn_type
, *self_type
, *new_type
;
13285 /* Check for a structure with no name and two children. */
13286 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
13289 /* Check for __pfn and __delta members. */
13290 if (TYPE_FIELD_NAME (type
, 0) == NULL
13291 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
13292 || TYPE_FIELD_NAME (type
, 1) == NULL
13293 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
13296 /* Find the type of the method. */
13297 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
13298 if (pfn_type
== NULL
13299 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
13300 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
13303 /* Look for the "this" argument. */
13304 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
13305 if (TYPE_NFIELDS (pfn_type
) == 0
13306 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
13307 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
13310 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
13311 new_type
= alloc_type (objfile
);
13312 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
13313 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
13314 TYPE_VARARGS (pfn_type
));
13315 smash_to_methodptr_type (type
, new_type
);
13318 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
13322 producer_is_icc (struct dwarf2_cu
*cu
)
13324 if (!cu
->checked_producer
)
13325 check_producer (cu
);
13327 return cu
->producer_is_icc
;
13330 /* Called when we find the DIE that starts a structure or union scope
13331 (definition) to create a type for the structure or union. Fill in
13332 the type's name and general properties; the members will not be
13333 processed until process_structure_scope. A symbol table entry for
13334 the type will also not be done until process_structure_scope (assuming
13335 the type has a name).
13337 NOTE: we need to call these functions regardless of whether or not the
13338 DIE has a DW_AT_name attribute, since it might be an anonymous
13339 structure or union. This gets the type entered into our set of
13340 user defined types. */
13342 static struct type
*
13343 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13345 struct objfile
*objfile
= cu
->objfile
;
13347 struct attribute
*attr
;
13350 /* If the definition of this type lives in .debug_types, read that type.
13351 Don't follow DW_AT_specification though, that will take us back up
13352 the chain and we want to go down. */
13353 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
13356 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13358 /* The type's CU may not be the same as CU.
13359 Ensure TYPE is recorded with CU in die_type_hash. */
13360 return set_die_type (die
, type
, cu
);
13363 type
= alloc_type (objfile
);
13364 INIT_CPLUS_SPECIFIC (type
);
13366 name
= dwarf2_name (die
, cu
);
13369 if (cu
->language
== language_cplus
13370 || cu
->language
== language_d
13371 || cu
->language
== language_rust
)
13373 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
13375 /* dwarf2_full_name might have already finished building the DIE's
13376 type. If so, there is no need to continue. */
13377 if (get_die_type (die
, cu
) != NULL
)
13378 return get_die_type (die
, cu
);
13380 TYPE_TAG_NAME (type
) = full_name
;
13381 if (die
->tag
== DW_TAG_structure_type
13382 || die
->tag
== DW_TAG_class_type
)
13383 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13387 /* The name is already allocated along with this objfile, so
13388 we don't need to duplicate it for the type. */
13389 TYPE_TAG_NAME (type
) = name
;
13390 if (die
->tag
== DW_TAG_class_type
)
13391 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13395 if (die
->tag
== DW_TAG_structure_type
)
13397 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13399 else if (die
->tag
== DW_TAG_union_type
)
13401 TYPE_CODE (type
) = TYPE_CODE_UNION
;
13405 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13408 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
13409 TYPE_DECLARED_CLASS (type
) = 1;
13411 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13414 if (attr_form_is_constant (attr
))
13415 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13418 /* For the moment, dynamic type sizes are not supported
13419 by GDB's struct type. The actual size is determined
13420 on-demand when resolving the type of a given object,
13421 so set the type's length to zero for now. Otherwise,
13422 we record an expression as the length, and that expression
13423 could lead to a very large value, which could eventually
13424 lead to us trying to allocate that much memory when creating
13425 a value of that type. */
13426 TYPE_LENGTH (type
) = 0;
13431 TYPE_LENGTH (type
) = 0;
13434 if (producer_is_icc (cu
) && (TYPE_LENGTH (type
) == 0))
13436 /* ICC does not output the required DW_AT_declaration
13437 on incomplete types, but gives them a size of zero. */
13438 TYPE_STUB (type
) = 1;
13441 TYPE_STUB_SUPPORTED (type
) = 1;
13443 if (die_is_declaration (die
, cu
))
13444 TYPE_STUB (type
) = 1;
13445 else if (attr
== NULL
&& die
->child
== NULL
13446 && producer_is_realview (cu
->producer
))
13447 /* RealView does not output the required DW_AT_declaration
13448 on incomplete types. */
13449 TYPE_STUB (type
) = 1;
13451 /* We need to add the type field to the die immediately so we don't
13452 infinitely recurse when dealing with pointers to the structure
13453 type within the structure itself. */
13454 set_die_type (die
, type
, cu
);
13456 /* set_die_type should be already done. */
13457 set_descriptive_type (type
, die
, cu
);
13462 /* Finish creating a structure or union type, including filling in
13463 its members and creating a symbol for it. */
13466 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13468 struct objfile
*objfile
= cu
->objfile
;
13469 struct die_info
*child_die
;
13472 type
= get_die_type (die
, cu
);
13474 type
= read_structure_type (die
, cu
);
13476 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
13478 struct field_info fi
;
13479 VEC (symbolp
) *template_args
= NULL
;
13480 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
13482 memset (&fi
, 0, sizeof (struct field_info
));
13484 child_die
= die
->child
;
13486 while (child_die
&& child_die
->tag
)
13488 if (child_die
->tag
== DW_TAG_member
13489 || child_die
->tag
== DW_TAG_variable
)
13491 /* NOTE: carlton/2002-11-05: A C++ static data member
13492 should be a DW_TAG_member that is a declaration, but
13493 all versions of G++ as of this writing (so through at
13494 least 3.2.1) incorrectly generate DW_TAG_variable
13495 tags for them instead. */
13496 dwarf2_add_field (&fi
, child_die
, cu
);
13498 else if (child_die
->tag
== DW_TAG_subprogram
)
13500 /* Rust doesn't have member functions in the C++ sense.
13501 However, it does emit ordinary functions as children
13502 of a struct DIE. */
13503 if (cu
->language
== language_rust
)
13504 read_func_scope (child_die
, cu
);
13507 /* C++ member function. */
13508 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
13511 else if (child_die
->tag
== DW_TAG_inheritance
)
13513 /* C++ base class field. */
13514 dwarf2_add_field (&fi
, child_die
, cu
);
13516 else if (child_die
->tag
== DW_TAG_typedef
)
13517 dwarf2_add_typedef (&fi
, child_die
, cu
);
13518 else if (child_die
->tag
== DW_TAG_template_type_param
13519 || child_die
->tag
== DW_TAG_template_value_param
)
13521 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13524 VEC_safe_push (symbolp
, template_args
, arg
);
13527 child_die
= sibling_die (child_die
);
13530 /* Attach template arguments to type. */
13531 if (! VEC_empty (symbolp
, template_args
))
13533 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13534 TYPE_N_TEMPLATE_ARGUMENTS (type
)
13535 = VEC_length (symbolp
, template_args
);
13536 TYPE_TEMPLATE_ARGUMENTS (type
)
13537 = XOBNEWVEC (&objfile
->objfile_obstack
,
13539 TYPE_N_TEMPLATE_ARGUMENTS (type
));
13540 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
13541 VEC_address (symbolp
, template_args
),
13542 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
13543 * sizeof (struct symbol
*)));
13544 VEC_free (symbolp
, template_args
);
13547 /* Attach fields and member functions to the type. */
13549 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
13552 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
13554 /* Get the type which refers to the base class (possibly this
13555 class itself) which contains the vtable pointer for the current
13556 class from the DW_AT_containing_type attribute. This use of
13557 DW_AT_containing_type is a GNU extension. */
13559 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
13561 struct type
*t
= die_containing_type (die
, cu
);
13563 set_type_vptr_basetype (type
, t
);
13568 /* Our own class provides vtbl ptr. */
13569 for (i
= TYPE_NFIELDS (t
) - 1;
13570 i
>= TYPE_N_BASECLASSES (t
);
13573 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
13575 if (is_vtable_name (fieldname
, cu
))
13577 set_type_vptr_fieldno (type
, i
);
13582 /* Complain if virtual function table field not found. */
13583 if (i
< TYPE_N_BASECLASSES (t
))
13584 complaint (&symfile_complaints
,
13585 _("virtual function table pointer "
13586 "not found when defining class '%s'"),
13587 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
13592 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
13595 else if (cu
->producer
13596 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
13598 /* The IBM XLC compiler does not provide direct indication
13599 of the containing type, but the vtable pointer is
13600 always named __vfp. */
13604 for (i
= TYPE_NFIELDS (type
) - 1;
13605 i
>= TYPE_N_BASECLASSES (type
);
13608 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
13610 set_type_vptr_fieldno (type
, i
);
13611 set_type_vptr_basetype (type
, type
);
13618 /* Copy fi.typedef_field_list linked list elements content into the
13619 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
13620 if (fi
.typedef_field_list
)
13622 int i
= fi
.typedef_field_list_count
;
13624 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13625 TYPE_TYPEDEF_FIELD_ARRAY (type
)
13626 = ((struct typedef_field
*)
13627 TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
));
13628 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
13630 /* Reverse the list order to keep the debug info elements order. */
13633 struct typedef_field
*dest
, *src
;
13635 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
13636 src
= &fi
.typedef_field_list
->field
;
13637 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
13642 do_cleanups (back_to
);
13645 quirk_gcc_member_function_pointer (type
, objfile
);
13647 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
13648 snapshots) has been known to create a die giving a declaration
13649 for a class that has, as a child, a die giving a definition for a
13650 nested class. So we have to process our children even if the
13651 current die is a declaration. Normally, of course, a declaration
13652 won't have any children at all. */
13654 child_die
= die
->child
;
13656 while (child_die
!= NULL
&& child_die
->tag
)
13658 if (child_die
->tag
== DW_TAG_member
13659 || child_die
->tag
== DW_TAG_variable
13660 || child_die
->tag
== DW_TAG_inheritance
13661 || child_die
->tag
== DW_TAG_template_value_param
13662 || child_die
->tag
== DW_TAG_template_type_param
)
13667 process_die (child_die
, cu
);
13669 child_die
= sibling_die (child_die
);
13672 /* Do not consider external references. According to the DWARF standard,
13673 these DIEs are identified by the fact that they have no byte_size
13674 attribute, and a declaration attribute. */
13675 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
13676 || !die_is_declaration (die
, cu
))
13677 new_symbol (die
, type
, cu
);
13680 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
13681 update TYPE using some information only available in DIE's children. */
13684 update_enumeration_type_from_children (struct die_info
*die
,
13686 struct dwarf2_cu
*cu
)
13688 struct obstack obstack
;
13689 struct die_info
*child_die
;
13690 int unsigned_enum
= 1;
13693 struct cleanup
*old_chain
;
13695 obstack_init (&obstack
);
13696 old_chain
= make_cleanup_obstack_free (&obstack
);
13698 for (child_die
= die
->child
;
13699 child_die
!= NULL
&& child_die
->tag
;
13700 child_die
= sibling_die (child_die
))
13702 struct attribute
*attr
;
13704 const gdb_byte
*bytes
;
13705 struct dwarf2_locexpr_baton
*baton
;
13708 if (child_die
->tag
!= DW_TAG_enumerator
)
13711 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
13715 name
= dwarf2_name (child_die
, cu
);
13717 name
= "<anonymous enumerator>";
13719 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
13720 &value
, &bytes
, &baton
);
13726 else if ((mask
& value
) != 0)
13731 /* If we already know that the enum type is neither unsigned, nor
13732 a flag type, no need to look at the rest of the enumerates. */
13733 if (!unsigned_enum
&& !flag_enum
)
13738 TYPE_UNSIGNED (type
) = 1;
13740 TYPE_FLAG_ENUM (type
) = 1;
13742 do_cleanups (old_chain
);
13745 /* Given a DW_AT_enumeration_type die, set its type. We do not
13746 complete the type's fields yet, or create any symbols. */
13748 static struct type
*
13749 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13751 struct objfile
*objfile
= cu
->objfile
;
13753 struct attribute
*attr
;
13756 /* If the definition of this type lives in .debug_types, read that type.
13757 Don't follow DW_AT_specification though, that will take us back up
13758 the chain and we want to go down. */
13759 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
13762 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13764 /* The type's CU may not be the same as CU.
13765 Ensure TYPE is recorded with CU in die_type_hash. */
13766 return set_die_type (die
, type
, cu
);
13769 type
= alloc_type (objfile
);
13771 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
13772 name
= dwarf2_full_name (NULL
, die
, cu
);
13774 TYPE_TAG_NAME (type
) = name
;
13776 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13779 struct type
*underlying_type
= die_type (die
, cu
);
13781 TYPE_TARGET_TYPE (type
) = underlying_type
;
13784 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13787 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13791 TYPE_LENGTH (type
) = 0;
13794 /* The enumeration DIE can be incomplete. In Ada, any type can be
13795 declared as private in the package spec, and then defined only
13796 inside the package body. Such types are known as Taft Amendment
13797 Types. When another package uses such a type, an incomplete DIE
13798 may be generated by the compiler. */
13799 if (die_is_declaration (die
, cu
))
13800 TYPE_STUB (type
) = 1;
13802 /* Finish the creation of this type by using the enum's children.
13803 We must call this even when the underlying type has been provided
13804 so that we can determine if we're looking at a "flag" enum. */
13805 update_enumeration_type_from_children (die
, type
, cu
);
13807 /* If this type has an underlying type that is not a stub, then we
13808 may use its attributes. We always use the "unsigned" attribute
13809 in this situation, because ordinarily we guess whether the type
13810 is unsigned -- but the guess can be wrong and the underlying type
13811 can tell us the reality. However, we defer to a local size
13812 attribute if one exists, because this lets the compiler override
13813 the underlying type if needed. */
13814 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
13816 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
13817 if (TYPE_LENGTH (type
) == 0)
13818 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
13821 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
13823 return set_die_type (die
, type
, cu
);
13826 /* Given a pointer to a die which begins an enumeration, process all
13827 the dies that define the members of the enumeration, and create the
13828 symbol for the enumeration type.
13830 NOTE: We reverse the order of the element list. */
13833 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13835 struct type
*this_type
;
13837 this_type
= get_die_type (die
, cu
);
13838 if (this_type
== NULL
)
13839 this_type
= read_enumeration_type (die
, cu
);
13841 if (die
->child
!= NULL
)
13843 struct die_info
*child_die
;
13844 struct symbol
*sym
;
13845 struct field
*fields
= NULL
;
13846 int num_fields
= 0;
13849 child_die
= die
->child
;
13850 while (child_die
&& child_die
->tag
)
13852 if (child_die
->tag
!= DW_TAG_enumerator
)
13854 process_die (child_die
, cu
);
13858 name
= dwarf2_name (child_die
, cu
);
13861 sym
= new_symbol (child_die
, this_type
, cu
);
13863 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
13865 fields
= (struct field
*)
13867 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
13868 * sizeof (struct field
));
13871 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
13872 FIELD_TYPE (fields
[num_fields
]) = NULL
;
13873 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
13874 FIELD_BITSIZE (fields
[num_fields
]) = 0;
13880 child_die
= sibling_die (child_die
);
13885 TYPE_NFIELDS (this_type
) = num_fields
;
13886 TYPE_FIELDS (this_type
) = (struct field
*)
13887 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
13888 memcpy (TYPE_FIELDS (this_type
), fields
,
13889 sizeof (struct field
) * num_fields
);
13894 /* If we are reading an enum from a .debug_types unit, and the enum
13895 is a declaration, and the enum is not the signatured type in the
13896 unit, then we do not want to add a symbol for it. Adding a
13897 symbol would in some cases obscure the true definition of the
13898 enum, giving users an incomplete type when the definition is
13899 actually available. Note that we do not want to do this for all
13900 enums which are just declarations, because C++0x allows forward
13901 enum declarations. */
13902 if (cu
->per_cu
->is_debug_types
13903 && die_is_declaration (die
, cu
))
13905 struct signatured_type
*sig_type
;
13907 sig_type
= (struct signatured_type
*) cu
->per_cu
;
13908 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
13909 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
13913 new_symbol (die
, this_type
, cu
);
13916 /* Extract all information from a DW_TAG_array_type DIE and put it in
13917 the DIE's type field. For now, this only handles one dimensional
13920 static struct type
*
13921 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13923 struct objfile
*objfile
= cu
->objfile
;
13924 struct die_info
*child_die
;
13926 struct type
*element_type
, *range_type
, *index_type
;
13927 struct type
**range_types
= NULL
;
13928 struct attribute
*attr
;
13930 struct cleanup
*back_to
;
13932 unsigned int bit_stride
= 0;
13934 element_type
= die_type (die
, cu
);
13936 /* The die_type call above may have already set the type for this DIE. */
13937 type
= get_die_type (die
, cu
);
13941 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
13943 bit_stride
= DW_UNSND (attr
) * 8;
13945 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
13947 bit_stride
= DW_UNSND (attr
);
13949 /* Irix 6.2 native cc creates array types without children for
13950 arrays with unspecified length. */
13951 if (die
->child
== NULL
)
13953 index_type
= objfile_type (objfile
)->builtin_int
;
13954 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
13955 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
13957 return set_die_type (die
, type
, cu
);
13960 back_to
= make_cleanup (null_cleanup
, NULL
);
13961 child_die
= die
->child
;
13962 while (child_die
&& child_die
->tag
)
13964 if (child_die
->tag
== DW_TAG_subrange_type
)
13966 struct type
*child_type
= read_type_die (child_die
, cu
);
13968 if (child_type
!= NULL
)
13970 /* The range type was succesfully read. Save it for the
13971 array type creation. */
13972 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
13974 range_types
= (struct type
**)
13975 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
13976 * sizeof (struct type
*));
13978 make_cleanup (free_current_contents
, &range_types
);
13980 range_types
[ndim
++] = child_type
;
13983 child_die
= sibling_die (child_die
);
13986 /* Dwarf2 dimensions are output from left to right, create the
13987 necessary array types in backwards order. */
13989 type
= element_type
;
13991 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
13996 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
14002 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
14006 /* Understand Dwarf2 support for vector types (like they occur on
14007 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
14008 array type. This is not part of the Dwarf2/3 standard yet, but a
14009 custom vendor extension. The main difference between a regular
14010 array and the vector variant is that vectors are passed by value
14012 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
14014 make_vector_type (type
);
14016 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
14017 implementation may choose to implement triple vectors using this
14019 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14022 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
14023 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14025 complaint (&symfile_complaints
,
14026 _("DW_AT_byte_size for array type smaller "
14027 "than the total size of elements"));
14030 name
= dwarf2_name (die
, cu
);
14032 TYPE_NAME (type
) = name
;
14034 /* Install the type in the die. */
14035 set_die_type (die
, type
, cu
);
14037 /* set_die_type should be already done. */
14038 set_descriptive_type (type
, die
, cu
);
14040 do_cleanups (back_to
);
14045 static enum dwarf_array_dim_ordering
14046 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
14048 struct attribute
*attr
;
14050 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
14053 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
14055 /* GNU F77 is a special case, as at 08/2004 array type info is the
14056 opposite order to the dwarf2 specification, but data is still
14057 laid out as per normal fortran.
14059 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
14060 version checking. */
14062 if (cu
->language
== language_fortran
14063 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
14065 return DW_ORD_row_major
;
14068 switch (cu
->language_defn
->la_array_ordering
)
14070 case array_column_major
:
14071 return DW_ORD_col_major
;
14072 case array_row_major
:
14074 return DW_ORD_row_major
;
14078 /* Extract all information from a DW_TAG_set_type DIE and put it in
14079 the DIE's type field. */
14081 static struct type
*
14082 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14084 struct type
*domain_type
, *set_type
;
14085 struct attribute
*attr
;
14087 domain_type
= die_type (die
, cu
);
14089 /* The die_type call above may have already set the type for this DIE. */
14090 set_type
= get_die_type (die
, cu
);
14094 set_type
= create_set_type (NULL
, domain_type
);
14096 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14098 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
14100 return set_die_type (die
, set_type
, cu
);
14103 /* A helper for read_common_block that creates a locexpr baton.
14104 SYM is the symbol which we are marking as computed.
14105 COMMON_DIE is the DIE for the common block.
14106 COMMON_LOC is the location expression attribute for the common
14108 MEMBER_LOC is the location expression attribute for the particular
14109 member of the common block that we are processing.
14110 CU is the CU from which the above come. */
14113 mark_common_block_symbol_computed (struct symbol
*sym
,
14114 struct die_info
*common_die
,
14115 struct attribute
*common_loc
,
14116 struct attribute
*member_loc
,
14117 struct dwarf2_cu
*cu
)
14119 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14120 struct dwarf2_locexpr_baton
*baton
;
14122 unsigned int cu_off
;
14123 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
14124 LONGEST offset
= 0;
14126 gdb_assert (common_loc
&& member_loc
);
14127 gdb_assert (attr_form_is_block (common_loc
));
14128 gdb_assert (attr_form_is_block (member_loc
)
14129 || attr_form_is_constant (member_loc
));
14131 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14132 baton
->per_cu
= cu
->per_cu
;
14133 gdb_assert (baton
->per_cu
);
14135 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
14137 if (attr_form_is_constant (member_loc
))
14139 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
14140 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
14143 baton
->size
+= DW_BLOCK (member_loc
)->size
;
14145 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
14148 *ptr
++ = DW_OP_call4
;
14149 cu_off
= common_die
->offset
.sect_off
- cu
->per_cu
->offset
.sect_off
;
14150 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
14153 if (attr_form_is_constant (member_loc
))
14155 *ptr
++ = DW_OP_addr
;
14156 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
14157 ptr
+= cu
->header
.addr_size
;
14161 /* We have to copy the data here, because DW_OP_call4 will only
14162 use a DW_AT_location attribute. */
14163 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
14164 ptr
+= DW_BLOCK (member_loc
)->size
;
14167 *ptr
++ = DW_OP_plus
;
14168 gdb_assert (ptr
- baton
->data
== baton
->size
);
14170 SYMBOL_LOCATION_BATON (sym
) = baton
;
14171 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
14174 /* Create appropriate locally-scoped variables for all the
14175 DW_TAG_common_block entries. Also create a struct common_block
14176 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
14177 is used to sepate the common blocks name namespace from regular
14181 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
14183 struct attribute
*attr
;
14185 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14188 /* Support the .debug_loc offsets. */
14189 if (attr_form_is_block (attr
))
14193 else if (attr_form_is_section_offset (attr
))
14195 dwarf2_complex_location_expr_complaint ();
14200 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
14201 "common block member");
14206 if (die
->child
!= NULL
)
14208 struct objfile
*objfile
= cu
->objfile
;
14209 struct die_info
*child_die
;
14210 size_t n_entries
= 0, size
;
14211 struct common_block
*common_block
;
14212 struct symbol
*sym
;
14214 for (child_die
= die
->child
;
14215 child_die
&& child_die
->tag
;
14216 child_die
= sibling_die (child_die
))
14219 size
= (sizeof (struct common_block
)
14220 + (n_entries
- 1) * sizeof (struct symbol
*));
14222 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
14224 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
14225 common_block
->n_entries
= 0;
14227 for (child_die
= die
->child
;
14228 child_die
&& child_die
->tag
;
14229 child_die
= sibling_die (child_die
))
14231 /* Create the symbol in the DW_TAG_common_block block in the current
14233 sym
= new_symbol (child_die
, NULL
, cu
);
14236 struct attribute
*member_loc
;
14238 common_block
->contents
[common_block
->n_entries
++] = sym
;
14240 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
14244 /* GDB has handled this for a long time, but it is
14245 not specified by DWARF. It seems to have been
14246 emitted by gfortran at least as recently as:
14247 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
14248 complaint (&symfile_complaints
,
14249 _("Variable in common block has "
14250 "DW_AT_data_member_location "
14251 "- DIE at 0x%x [in module %s]"),
14252 child_die
->offset
.sect_off
,
14253 objfile_name (cu
->objfile
));
14255 if (attr_form_is_section_offset (member_loc
))
14256 dwarf2_complex_location_expr_complaint ();
14257 else if (attr_form_is_constant (member_loc
)
14258 || attr_form_is_block (member_loc
))
14261 mark_common_block_symbol_computed (sym
, die
, attr
,
14265 dwarf2_complex_location_expr_complaint ();
14270 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
14271 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
14275 /* Create a type for a C++ namespace. */
14277 static struct type
*
14278 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14280 struct objfile
*objfile
= cu
->objfile
;
14281 const char *previous_prefix
, *name
;
14285 /* For extensions, reuse the type of the original namespace. */
14286 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
14288 struct die_info
*ext_die
;
14289 struct dwarf2_cu
*ext_cu
= cu
;
14291 ext_die
= dwarf2_extension (die
, &ext_cu
);
14292 type
= read_type_die (ext_die
, ext_cu
);
14294 /* EXT_CU may not be the same as CU.
14295 Ensure TYPE is recorded with CU in die_type_hash. */
14296 return set_die_type (die
, type
, cu
);
14299 name
= namespace_name (die
, &is_anonymous
, cu
);
14301 /* Now build the name of the current namespace. */
14303 previous_prefix
= determine_prefix (die
, cu
);
14304 if (previous_prefix
[0] != '\0')
14305 name
= typename_concat (&objfile
->objfile_obstack
,
14306 previous_prefix
, name
, 0, cu
);
14308 /* Create the type. */
14309 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
14310 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14312 return set_die_type (die
, type
, cu
);
14315 /* Read a namespace scope. */
14318 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
14320 struct objfile
*objfile
= cu
->objfile
;
14323 /* Add a symbol associated to this if we haven't seen the namespace
14324 before. Also, add a using directive if it's an anonymous
14327 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
14331 type
= read_type_die (die
, cu
);
14332 new_symbol (die
, type
, cu
);
14334 namespace_name (die
, &is_anonymous
, cu
);
14337 const char *previous_prefix
= determine_prefix (die
, cu
);
14339 add_using_directive (using_directives (cu
->language
),
14340 previous_prefix
, TYPE_NAME (type
), NULL
,
14341 NULL
, NULL
, 0, &objfile
->objfile_obstack
);
14345 if (die
->child
!= NULL
)
14347 struct die_info
*child_die
= die
->child
;
14349 while (child_die
&& child_die
->tag
)
14351 process_die (child_die
, cu
);
14352 child_die
= sibling_die (child_die
);
14357 /* Read a Fortran module as type. This DIE can be only a declaration used for
14358 imported module. Still we need that type as local Fortran "use ... only"
14359 declaration imports depend on the created type in determine_prefix. */
14361 static struct type
*
14362 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14364 struct objfile
*objfile
= cu
->objfile
;
14365 const char *module_name
;
14368 module_name
= dwarf2_name (die
, cu
);
14370 complaint (&symfile_complaints
,
14371 _("DW_TAG_module has no name, offset 0x%x"),
14372 die
->offset
.sect_off
);
14373 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
14375 /* determine_prefix uses TYPE_TAG_NAME. */
14376 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14378 return set_die_type (die
, type
, cu
);
14381 /* Read a Fortran module. */
14384 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
14386 struct die_info
*child_die
= die
->child
;
14389 type
= read_type_die (die
, cu
);
14390 new_symbol (die
, type
, cu
);
14392 while (child_die
&& child_die
->tag
)
14394 process_die (child_die
, cu
);
14395 child_die
= sibling_die (child_die
);
14399 /* Return the name of the namespace represented by DIE. Set
14400 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
14403 static const char *
14404 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
14406 struct die_info
*current_die
;
14407 const char *name
= NULL
;
14409 /* Loop through the extensions until we find a name. */
14411 for (current_die
= die
;
14412 current_die
!= NULL
;
14413 current_die
= dwarf2_extension (die
, &cu
))
14415 /* We don't use dwarf2_name here so that we can detect the absence
14416 of a name -> anonymous namespace. */
14417 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
14423 /* Is it an anonymous namespace? */
14425 *is_anonymous
= (name
== NULL
);
14427 name
= CP_ANONYMOUS_NAMESPACE_STR
;
14432 /* Extract all information from a DW_TAG_pointer_type DIE and add to
14433 the user defined type vector. */
14435 static struct type
*
14436 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14438 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
14439 struct comp_unit_head
*cu_header
= &cu
->header
;
14441 struct attribute
*attr_byte_size
;
14442 struct attribute
*attr_address_class
;
14443 int byte_size
, addr_class
;
14444 struct type
*target_type
;
14446 target_type
= die_type (die
, cu
);
14448 /* The die_type call above may have already set the type for this DIE. */
14449 type
= get_die_type (die
, cu
);
14453 type
= lookup_pointer_type (target_type
);
14455 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14456 if (attr_byte_size
)
14457 byte_size
= DW_UNSND (attr_byte_size
);
14459 byte_size
= cu_header
->addr_size
;
14461 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
14462 if (attr_address_class
)
14463 addr_class
= DW_UNSND (attr_address_class
);
14465 addr_class
= DW_ADDR_none
;
14467 /* If the pointer size or address class is different than the
14468 default, create a type variant marked as such and set the
14469 length accordingly. */
14470 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
14472 if (gdbarch_address_class_type_flags_p (gdbarch
))
14476 type_flags
= gdbarch_address_class_type_flags
14477 (gdbarch
, byte_size
, addr_class
);
14478 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
14480 type
= make_type_with_address_space (type
, type_flags
);
14482 else if (TYPE_LENGTH (type
) != byte_size
)
14484 complaint (&symfile_complaints
,
14485 _("invalid pointer size %d"), byte_size
);
14489 /* Should we also complain about unhandled address classes? */
14493 TYPE_LENGTH (type
) = byte_size
;
14494 return set_die_type (die
, type
, cu
);
14497 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
14498 the user defined type vector. */
14500 static struct type
*
14501 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14504 struct type
*to_type
;
14505 struct type
*domain
;
14507 to_type
= die_type (die
, cu
);
14508 domain
= die_containing_type (die
, cu
);
14510 /* The calls above may have already set the type for this DIE. */
14511 type
= get_die_type (die
, cu
);
14515 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
14516 type
= lookup_methodptr_type (to_type
);
14517 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
14519 struct type
*new_type
= alloc_type (cu
->objfile
);
14521 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
14522 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
14523 TYPE_VARARGS (to_type
));
14524 type
= lookup_methodptr_type (new_type
);
14527 type
= lookup_memberptr_type (to_type
, domain
);
14529 return set_die_type (die
, type
, cu
);
14532 /* Extract all information from a DW_TAG_reference_type DIE and add to
14533 the user defined type vector. */
14535 static struct type
*
14536 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14538 struct comp_unit_head
*cu_header
= &cu
->header
;
14539 struct type
*type
, *target_type
;
14540 struct attribute
*attr
;
14542 target_type
= die_type (die
, cu
);
14544 /* The die_type call above may have already set the type for this DIE. */
14545 type
= get_die_type (die
, cu
);
14549 type
= lookup_reference_type (target_type
);
14550 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14553 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14557 TYPE_LENGTH (type
) = cu_header
->addr_size
;
14559 return set_die_type (die
, type
, cu
);
14562 /* Add the given cv-qualifiers to the element type of the array. GCC
14563 outputs DWARF type qualifiers that apply to an array, not the
14564 element type. But GDB relies on the array element type to carry
14565 the cv-qualifiers. This mimics section 6.7.3 of the C99
14568 static struct type
*
14569 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
14570 struct type
*base_type
, int cnst
, int voltl
)
14572 struct type
*el_type
, *inner_array
;
14574 base_type
= copy_type (base_type
);
14575 inner_array
= base_type
;
14577 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
14579 TYPE_TARGET_TYPE (inner_array
) =
14580 copy_type (TYPE_TARGET_TYPE (inner_array
));
14581 inner_array
= TYPE_TARGET_TYPE (inner_array
);
14584 el_type
= TYPE_TARGET_TYPE (inner_array
);
14585 cnst
|= TYPE_CONST (el_type
);
14586 voltl
|= TYPE_VOLATILE (el_type
);
14587 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
14589 return set_die_type (die
, base_type
, cu
);
14592 static struct type
*
14593 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14595 struct type
*base_type
, *cv_type
;
14597 base_type
= die_type (die
, cu
);
14599 /* The die_type call above may have already set the type for this DIE. */
14600 cv_type
= get_die_type (die
, cu
);
14604 /* In case the const qualifier is applied to an array type, the element type
14605 is so qualified, not the array type (section 6.7.3 of C99). */
14606 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
14607 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
14609 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
14610 return set_die_type (die
, cv_type
, cu
);
14613 static struct type
*
14614 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14616 struct type
*base_type
, *cv_type
;
14618 base_type
= die_type (die
, cu
);
14620 /* The die_type call above may have already set the type for this DIE. */
14621 cv_type
= get_die_type (die
, cu
);
14625 /* In case the volatile qualifier is applied to an array type, the
14626 element type is so qualified, not the array type (section 6.7.3
14628 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
14629 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
14631 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
14632 return set_die_type (die
, cv_type
, cu
);
14635 /* Handle DW_TAG_restrict_type. */
14637 static struct type
*
14638 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14640 struct type
*base_type
, *cv_type
;
14642 base_type
= die_type (die
, cu
);
14644 /* The die_type call above may have already set the type for this DIE. */
14645 cv_type
= get_die_type (die
, cu
);
14649 cv_type
= make_restrict_type (base_type
);
14650 return set_die_type (die
, cv_type
, cu
);
14653 /* Handle DW_TAG_atomic_type. */
14655 static struct type
*
14656 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14658 struct type
*base_type
, *cv_type
;
14660 base_type
= die_type (die
, cu
);
14662 /* The die_type call above may have already set the type for this DIE. */
14663 cv_type
= get_die_type (die
, cu
);
14667 cv_type
= make_atomic_type (base_type
);
14668 return set_die_type (die
, cv_type
, cu
);
14671 /* Extract all information from a DW_TAG_string_type DIE and add to
14672 the user defined type vector. It isn't really a user defined type,
14673 but it behaves like one, with other DIE's using an AT_user_def_type
14674 attribute to reference it. */
14676 static struct type
*
14677 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14679 struct objfile
*objfile
= cu
->objfile
;
14680 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14681 struct type
*type
, *range_type
, *index_type
, *char_type
;
14682 struct attribute
*attr
;
14683 unsigned int length
;
14685 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
14688 length
= DW_UNSND (attr
);
14692 /* Check for the DW_AT_byte_size attribute. */
14693 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14696 length
= DW_UNSND (attr
);
14704 index_type
= objfile_type (objfile
)->builtin_int
;
14705 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
14706 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
14707 type
= create_string_type (NULL
, char_type
, range_type
);
14709 return set_die_type (die
, type
, cu
);
14712 /* Assuming that DIE corresponds to a function, returns nonzero
14713 if the function is prototyped. */
14716 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
14718 struct attribute
*attr
;
14720 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
14721 if (attr
&& (DW_UNSND (attr
) != 0))
14724 /* The DWARF standard implies that the DW_AT_prototyped attribute
14725 is only meaninful for C, but the concept also extends to other
14726 languages that allow unprototyped functions (Eg: Objective C).
14727 For all other languages, assume that functions are always
14729 if (cu
->language
!= language_c
14730 && cu
->language
!= language_objc
14731 && cu
->language
!= language_opencl
)
14734 /* RealView does not emit DW_AT_prototyped. We can not distinguish
14735 prototyped and unprototyped functions; default to prototyped,
14736 since that is more common in modern code (and RealView warns
14737 about unprototyped functions). */
14738 if (producer_is_realview (cu
->producer
))
14744 /* Handle DIES due to C code like:
14748 int (*funcp)(int a, long l);
14752 ('funcp' generates a DW_TAG_subroutine_type DIE). */
14754 static struct type
*
14755 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14757 struct objfile
*objfile
= cu
->objfile
;
14758 struct type
*type
; /* Type that this function returns. */
14759 struct type
*ftype
; /* Function that returns above type. */
14760 struct attribute
*attr
;
14762 type
= die_type (die
, cu
);
14764 /* The die_type call above may have already set the type for this DIE. */
14765 ftype
= get_die_type (die
, cu
);
14769 ftype
= lookup_function_type (type
);
14771 if (prototyped_function_p (die
, cu
))
14772 TYPE_PROTOTYPED (ftype
) = 1;
14774 /* Store the calling convention in the type if it's available in
14775 the subroutine die. Otherwise set the calling convention to
14776 the default value DW_CC_normal. */
14777 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
14779 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
14780 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
14781 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
14783 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
14785 /* Record whether the function returns normally to its caller or not
14786 if the DWARF producer set that information. */
14787 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
14788 if (attr
&& (DW_UNSND (attr
) != 0))
14789 TYPE_NO_RETURN (ftype
) = 1;
14791 /* We need to add the subroutine type to the die immediately so
14792 we don't infinitely recurse when dealing with parameters
14793 declared as the same subroutine type. */
14794 set_die_type (die
, ftype
, cu
);
14796 if (die
->child
!= NULL
)
14798 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
14799 struct die_info
*child_die
;
14800 int nparams
, iparams
;
14802 /* Count the number of parameters.
14803 FIXME: GDB currently ignores vararg functions, but knows about
14804 vararg member functions. */
14806 child_die
= die
->child
;
14807 while (child_die
&& child_die
->tag
)
14809 if (child_die
->tag
== DW_TAG_formal_parameter
)
14811 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
14812 TYPE_VARARGS (ftype
) = 1;
14813 child_die
= sibling_die (child_die
);
14816 /* Allocate storage for parameters and fill them in. */
14817 TYPE_NFIELDS (ftype
) = nparams
;
14818 TYPE_FIELDS (ftype
) = (struct field
*)
14819 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
14821 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
14822 even if we error out during the parameters reading below. */
14823 for (iparams
= 0; iparams
< nparams
; iparams
++)
14824 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
14827 child_die
= die
->child
;
14828 while (child_die
&& child_die
->tag
)
14830 if (child_die
->tag
== DW_TAG_formal_parameter
)
14832 struct type
*arg_type
;
14834 /* DWARF version 2 has no clean way to discern C++
14835 static and non-static member functions. G++ helps
14836 GDB by marking the first parameter for non-static
14837 member functions (which is the this pointer) as
14838 artificial. We pass this information to
14839 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
14841 DWARF version 3 added DW_AT_object_pointer, which GCC
14842 4.5 does not yet generate. */
14843 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
14845 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
14847 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
14848 arg_type
= die_type (child_die
, cu
);
14850 /* RealView does not mark THIS as const, which the testsuite
14851 expects. GCC marks THIS as const in method definitions,
14852 but not in the class specifications (GCC PR 43053). */
14853 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
14854 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
14857 struct dwarf2_cu
*arg_cu
= cu
;
14858 const char *name
= dwarf2_name (child_die
, cu
);
14860 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
14863 /* If the compiler emits this, use it. */
14864 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
14867 else if (name
&& strcmp (name
, "this") == 0)
14868 /* Function definitions will have the argument names. */
14870 else if (name
== NULL
&& iparams
== 0)
14871 /* Declarations may not have the names, so like
14872 elsewhere in GDB, assume an artificial first
14873 argument is "this". */
14877 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
14881 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
14884 child_die
= sibling_die (child_die
);
14891 static struct type
*
14892 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
14894 struct objfile
*objfile
= cu
->objfile
;
14895 const char *name
= NULL
;
14896 struct type
*this_type
, *target_type
;
14898 name
= dwarf2_full_name (NULL
, die
, cu
);
14899 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
14900 TYPE_TARGET_STUB (this_type
) = 1;
14901 set_die_type (die
, this_type
, cu
);
14902 target_type
= die_type (die
, cu
);
14903 if (target_type
!= this_type
)
14904 TYPE_TARGET_TYPE (this_type
) = target_type
;
14907 /* Self-referential typedefs are, it seems, not allowed by the DWARF
14908 spec and cause infinite loops in GDB. */
14909 complaint (&symfile_complaints
,
14910 _("Self-referential DW_TAG_typedef "
14911 "- DIE at 0x%x [in module %s]"),
14912 die
->offset
.sect_off
, objfile_name (objfile
));
14913 TYPE_TARGET_TYPE (this_type
) = NULL
;
14918 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
14919 (which may be different from NAME) to the architecture back-end to allow
14920 it to guess the correct format if necessary. */
14922 static struct type
*
14923 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
14924 const char *name_hint
)
14926 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14927 const struct floatformat
**format
;
14930 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
14932 type
= init_float_type (objfile
, bits
, name
, format
);
14934 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
/ TARGET_CHAR_BIT
, name
);
14939 /* Find a representation of a given base type and install
14940 it in the TYPE field of the die. */
14942 static struct type
*
14943 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14945 struct objfile
*objfile
= cu
->objfile
;
14947 struct attribute
*attr
;
14948 int encoding
= 0, bits
= 0;
14951 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
14954 encoding
= DW_UNSND (attr
);
14956 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14959 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
14961 name
= dwarf2_name (die
, cu
);
14964 complaint (&symfile_complaints
,
14965 _("DW_AT_name missing from DW_TAG_base_type"));
14970 case DW_ATE_address
:
14971 /* Turn DW_ATE_address into a void * pointer. */
14972 type
= init_type (objfile
, TYPE_CODE_VOID
, 1, NULL
);
14973 type
= init_pointer_type (objfile
, bits
, name
, type
);
14975 case DW_ATE_boolean
:
14976 type
= init_boolean_type (objfile
, bits
, 1, name
);
14978 case DW_ATE_complex_float
:
14979 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
14980 type
= init_complex_type (objfile
, name
, type
);
14982 case DW_ATE_decimal_float
:
14983 type
= init_decfloat_type (objfile
, bits
, name
);
14986 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
14988 case DW_ATE_signed
:
14989 type
= init_integer_type (objfile
, bits
, 0, name
);
14991 case DW_ATE_unsigned
:
14992 if (cu
->language
== language_fortran
14994 && startswith (name
, "character("))
14995 type
= init_character_type (objfile
, bits
, 1, name
);
14997 type
= init_integer_type (objfile
, bits
, 1, name
);
14999 case DW_ATE_signed_char
:
15000 if (cu
->language
== language_ada
|| cu
->language
== language_m2
15001 || cu
->language
== language_pascal
15002 || cu
->language
== language_fortran
)
15003 type
= init_character_type (objfile
, bits
, 0, name
);
15005 type
= init_integer_type (objfile
, bits
, 0, name
);
15007 case DW_ATE_unsigned_char
:
15008 if (cu
->language
== language_ada
|| cu
->language
== language_m2
15009 || cu
->language
== language_pascal
15010 || cu
->language
== language_fortran
15011 || cu
->language
== language_rust
)
15012 type
= init_character_type (objfile
, bits
, 1, name
);
15014 type
= init_integer_type (objfile
, bits
, 1, name
);
15017 /* We just treat this as an integer and then recognize the
15018 type by name elsewhere. */
15019 type
= init_integer_type (objfile
, bits
, 0, name
);
15023 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
15024 dwarf_type_encoding_name (encoding
));
15025 type
= init_type (objfile
, TYPE_CODE_ERROR
,
15026 bits
/ TARGET_CHAR_BIT
, name
);
15030 if (name
&& strcmp (name
, "char") == 0)
15031 TYPE_NOSIGN (type
) = 1;
15033 return set_die_type (die
, type
, cu
);
15036 /* Parse dwarf attribute if it's a block, reference or constant and put the
15037 resulting value of the attribute into struct bound_prop.
15038 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
15041 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
15042 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
15044 struct dwarf2_property_baton
*baton
;
15045 struct obstack
*obstack
= &cu
->objfile
->objfile_obstack
;
15047 if (attr
== NULL
|| prop
== NULL
)
15050 if (attr_form_is_block (attr
))
15052 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15053 baton
->referenced_type
= NULL
;
15054 baton
->locexpr
.per_cu
= cu
->per_cu
;
15055 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
15056 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
15057 prop
->data
.baton
= baton
;
15058 prop
->kind
= PROP_LOCEXPR
;
15059 gdb_assert (prop
->data
.baton
!= NULL
);
15061 else if (attr_form_is_ref (attr
))
15063 struct dwarf2_cu
*target_cu
= cu
;
15064 struct die_info
*target_die
;
15065 struct attribute
*target_attr
;
15067 target_die
= follow_die_ref (die
, attr
, &target_cu
);
15068 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
15069 if (target_attr
== NULL
)
15070 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
15072 if (target_attr
== NULL
)
15075 switch (target_attr
->name
)
15077 case DW_AT_location
:
15078 if (attr_form_is_section_offset (target_attr
))
15080 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15081 baton
->referenced_type
= die_type (target_die
, target_cu
);
15082 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
15083 prop
->data
.baton
= baton
;
15084 prop
->kind
= PROP_LOCLIST
;
15085 gdb_assert (prop
->data
.baton
!= NULL
);
15087 else if (attr_form_is_block (target_attr
))
15089 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15090 baton
->referenced_type
= die_type (target_die
, target_cu
);
15091 baton
->locexpr
.per_cu
= cu
->per_cu
;
15092 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
15093 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
15094 prop
->data
.baton
= baton
;
15095 prop
->kind
= PROP_LOCEXPR
;
15096 gdb_assert (prop
->data
.baton
!= NULL
);
15100 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15101 "dynamic property");
15105 case DW_AT_data_member_location
:
15109 if (!handle_data_member_location (target_die
, target_cu
,
15113 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15114 baton
->referenced_type
= read_type_die (target_die
->parent
,
15116 baton
->offset_info
.offset
= offset
;
15117 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
15118 prop
->data
.baton
= baton
;
15119 prop
->kind
= PROP_ADDR_OFFSET
;
15124 else if (attr_form_is_constant (attr
))
15126 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
15127 prop
->kind
= PROP_CONST
;
15131 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
15132 dwarf2_name (die
, cu
));
15139 /* Read the given DW_AT_subrange DIE. */
15141 static struct type
*
15142 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15144 struct type
*base_type
, *orig_base_type
;
15145 struct type
*range_type
;
15146 struct attribute
*attr
;
15147 struct dynamic_prop low
, high
;
15148 int low_default_is_valid
;
15149 int high_bound_is_count
= 0;
15151 LONGEST negative_mask
;
15153 orig_base_type
= die_type (die
, cu
);
15154 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
15155 whereas the real type might be. So, we use ORIG_BASE_TYPE when
15156 creating the range type, but we use the result of check_typedef
15157 when examining properties of the type. */
15158 base_type
= check_typedef (orig_base_type
);
15160 /* The die_type call above may have already set the type for this DIE. */
15161 range_type
= get_die_type (die
, cu
);
15165 low
.kind
= PROP_CONST
;
15166 high
.kind
= PROP_CONST
;
15167 high
.data
.const_val
= 0;
15169 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
15170 omitting DW_AT_lower_bound. */
15171 switch (cu
->language
)
15174 case language_cplus
:
15175 low
.data
.const_val
= 0;
15176 low_default_is_valid
= 1;
15178 case language_fortran
:
15179 low
.data
.const_val
= 1;
15180 low_default_is_valid
= 1;
15183 case language_objc
:
15184 case language_rust
:
15185 low
.data
.const_val
= 0;
15186 low_default_is_valid
= (cu
->header
.version
>= 4);
15190 case language_pascal
:
15191 low
.data
.const_val
= 1;
15192 low_default_is_valid
= (cu
->header
.version
>= 4);
15195 low
.data
.const_val
= 0;
15196 low_default_is_valid
= 0;
15200 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
15202 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
15203 else if (!low_default_is_valid
)
15204 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
15205 "- DIE at 0x%x [in module %s]"),
15206 die
->offset
.sect_off
, objfile_name (cu
->objfile
));
15208 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
15209 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
15211 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
15212 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
15214 /* If bounds are constant do the final calculation here. */
15215 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
15216 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
15218 high_bound_is_count
= 1;
15222 /* Dwarf-2 specifications explicitly allows to create subrange types
15223 without specifying a base type.
15224 In that case, the base type must be set to the type of
15225 the lower bound, upper bound or count, in that order, if any of these
15226 three attributes references an object that has a type.
15227 If no base type is found, the Dwarf-2 specifications say that
15228 a signed integer type of size equal to the size of an address should
15230 For the following C code: `extern char gdb_int [];'
15231 GCC produces an empty range DIE.
15232 FIXME: muller/2010-05-28: Possible references to object for low bound,
15233 high bound or count are not yet handled by this code. */
15234 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
15236 struct objfile
*objfile
= cu
->objfile
;
15237 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15238 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
15239 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
15241 /* Test "int", "long int", and "long long int" objfile types,
15242 and select the first one having a size above or equal to the
15243 architecture address size. */
15244 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15245 base_type
= int_type
;
15248 int_type
= objfile_type (objfile
)->builtin_long
;
15249 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15250 base_type
= int_type
;
15253 int_type
= objfile_type (objfile
)->builtin_long_long
;
15254 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15255 base_type
= int_type
;
15260 /* Normally, the DWARF producers are expected to use a signed
15261 constant form (Eg. DW_FORM_sdata) to express negative bounds.
15262 But this is unfortunately not always the case, as witnessed
15263 with GCC, for instance, where the ambiguous DW_FORM_dataN form
15264 is used instead. To work around that ambiguity, we treat
15265 the bounds as signed, and thus sign-extend their values, when
15266 the base type is signed. */
15268 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
15269 if (low
.kind
== PROP_CONST
15270 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
15271 low
.data
.const_val
|= negative_mask
;
15272 if (high
.kind
== PROP_CONST
15273 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
15274 high
.data
.const_val
|= negative_mask
;
15276 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
15278 if (high_bound_is_count
)
15279 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
15281 /* Ada expects an empty array on no boundary attributes. */
15282 if (attr
== NULL
&& cu
->language
!= language_ada
)
15283 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
15285 name
= dwarf2_name (die
, cu
);
15287 TYPE_NAME (range_type
) = name
;
15289 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15291 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
15293 set_die_type (die
, range_type
, cu
);
15295 /* set_die_type should be already done. */
15296 set_descriptive_type (range_type
, die
, cu
);
15301 static struct type
*
15302 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15306 /* For now, we only support the C meaning of an unspecified type: void. */
15308 type
= init_type (cu
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
15309 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
15311 return set_die_type (die
, type
, cu
);
15314 /* Read a single die and all its descendents. Set the die's sibling
15315 field to NULL; set other fields in the die correctly, and set all
15316 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
15317 location of the info_ptr after reading all of those dies. PARENT
15318 is the parent of the die in question. */
15320 static struct die_info
*
15321 read_die_and_children (const struct die_reader_specs
*reader
,
15322 const gdb_byte
*info_ptr
,
15323 const gdb_byte
**new_info_ptr
,
15324 struct die_info
*parent
)
15326 struct die_info
*die
;
15327 const gdb_byte
*cur_ptr
;
15330 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
15333 *new_info_ptr
= cur_ptr
;
15336 store_in_ref_table (die
, reader
->cu
);
15339 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
15343 *new_info_ptr
= cur_ptr
;
15346 die
->sibling
= NULL
;
15347 die
->parent
= parent
;
15351 /* Read a die, all of its descendents, and all of its siblings; set
15352 all of the fields of all of the dies correctly. Arguments are as
15353 in read_die_and_children. */
15355 static struct die_info
*
15356 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
15357 const gdb_byte
*info_ptr
,
15358 const gdb_byte
**new_info_ptr
,
15359 struct die_info
*parent
)
15361 struct die_info
*first_die
, *last_sibling
;
15362 const gdb_byte
*cur_ptr
;
15364 cur_ptr
= info_ptr
;
15365 first_die
= last_sibling
= NULL
;
15369 struct die_info
*die
15370 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
15374 *new_info_ptr
= cur_ptr
;
15381 last_sibling
->sibling
= die
;
15383 last_sibling
= die
;
15387 /* Read a die, all of its descendents, and all of its siblings; set
15388 all of the fields of all of the dies correctly. Arguments are as
15389 in read_die_and_children.
15390 This the main entry point for reading a DIE and all its children. */
15392 static struct die_info
*
15393 read_die_and_siblings (const struct die_reader_specs
*reader
,
15394 const gdb_byte
*info_ptr
,
15395 const gdb_byte
**new_info_ptr
,
15396 struct die_info
*parent
)
15398 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
15399 new_info_ptr
, parent
);
15401 if (dwarf_die_debug
)
15403 fprintf_unfiltered (gdb_stdlog
,
15404 "Read die from %s@0x%x of %s:\n",
15405 get_section_name (reader
->die_section
),
15406 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15407 bfd_get_filename (reader
->abfd
));
15408 dump_die (die
, dwarf_die_debug
);
15414 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
15416 The caller is responsible for filling in the extra attributes
15417 and updating (*DIEP)->num_attrs.
15418 Set DIEP to point to a newly allocated die with its information,
15419 except for its child, sibling, and parent fields.
15420 Set HAS_CHILDREN to tell whether the die has children or not. */
15422 static const gdb_byte
*
15423 read_full_die_1 (const struct die_reader_specs
*reader
,
15424 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15425 int *has_children
, int num_extra_attrs
)
15427 unsigned int abbrev_number
, bytes_read
, i
;
15428 sect_offset offset
;
15429 struct abbrev_info
*abbrev
;
15430 struct die_info
*die
;
15431 struct dwarf2_cu
*cu
= reader
->cu
;
15432 bfd
*abfd
= reader
->abfd
;
15434 offset
.sect_off
= info_ptr
- reader
->buffer
;
15435 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15436 info_ptr
+= bytes_read
;
15437 if (!abbrev_number
)
15444 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
15446 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
15448 bfd_get_filename (abfd
));
15450 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
15451 die
->offset
= offset
;
15452 die
->tag
= abbrev
->tag
;
15453 die
->abbrev
= abbrev_number
;
15455 /* Make the result usable.
15456 The caller needs to update num_attrs after adding the extra
15458 die
->num_attrs
= abbrev
->num_attrs
;
15460 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
15461 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
15465 *has_children
= abbrev
->has_children
;
15469 /* Read a die and all its attributes.
15470 Set DIEP to point to a newly allocated die with its information,
15471 except for its child, sibling, and parent fields.
15472 Set HAS_CHILDREN to tell whether the die has children or not. */
15474 static const gdb_byte
*
15475 read_full_die (const struct die_reader_specs
*reader
,
15476 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15479 const gdb_byte
*result
;
15481 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
15483 if (dwarf_die_debug
)
15485 fprintf_unfiltered (gdb_stdlog
,
15486 "Read die from %s@0x%x of %s:\n",
15487 get_section_name (reader
->die_section
),
15488 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15489 bfd_get_filename (reader
->abfd
));
15490 dump_die (*diep
, dwarf_die_debug
);
15496 /* Abbreviation tables.
15498 In DWARF version 2, the description of the debugging information is
15499 stored in a separate .debug_abbrev section. Before we read any
15500 dies from a section we read in all abbreviations and install them
15501 in a hash table. */
15503 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
15505 static struct abbrev_info
*
15506 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
15508 struct abbrev_info
*abbrev
;
15510 abbrev
= XOBNEW (&abbrev_table
->abbrev_obstack
, struct abbrev_info
);
15511 memset (abbrev
, 0, sizeof (struct abbrev_info
));
15516 /* Add an abbreviation to the table. */
15519 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
15520 unsigned int abbrev_number
,
15521 struct abbrev_info
*abbrev
)
15523 unsigned int hash_number
;
15525 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
15526 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
15527 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
15530 /* Look up an abbrev in the table.
15531 Returns NULL if the abbrev is not found. */
15533 static struct abbrev_info
*
15534 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
15535 unsigned int abbrev_number
)
15537 unsigned int hash_number
;
15538 struct abbrev_info
*abbrev
;
15540 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
15541 abbrev
= abbrev_table
->abbrevs
[hash_number
];
15545 if (abbrev
->number
== abbrev_number
)
15547 abbrev
= abbrev
->next
;
15552 /* Read in an abbrev table. */
15554 static struct abbrev_table
*
15555 abbrev_table_read_table (struct dwarf2_section_info
*section
,
15556 sect_offset offset
)
15558 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15559 bfd
*abfd
= get_section_bfd_owner (section
);
15560 struct abbrev_table
*abbrev_table
;
15561 const gdb_byte
*abbrev_ptr
;
15562 struct abbrev_info
*cur_abbrev
;
15563 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
15564 unsigned int abbrev_form
;
15565 struct attr_abbrev
*cur_attrs
;
15566 unsigned int allocated_attrs
;
15568 abbrev_table
= XNEW (struct abbrev_table
);
15569 abbrev_table
->offset
= offset
;
15570 obstack_init (&abbrev_table
->abbrev_obstack
);
15571 abbrev_table
->abbrevs
=
15572 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct abbrev_info
*,
15574 memset (abbrev_table
->abbrevs
, 0,
15575 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
15577 dwarf2_read_section (objfile
, section
);
15578 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
15579 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15580 abbrev_ptr
+= bytes_read
;
15582 allocated_attrs
= ATTR_ALLOC_CHUNK
;
15583 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
15585 /* Loop until we reach an abbrev number of 0. */
15586 while (abbrev_number
)
15588 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
15590 /* read in abbrev header */
15591 cur_abbrev
->number
= abbrev_number
;
15593 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15594 abbrev_ptr
+= bytes_read
;
15595 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
15598 /* now read in declarations */
15601 LONGEST implicit_const
;
15603 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15604 abbrev_ptr
+= bytes_read
;
15605 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15606 abbrev_ptr
+= bytes_read
;
15607 if (abbrev_form
== DW_FORM_implicit_const
)
15609 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
15611 abbrev_ptr
+= bytes_read
;
15615 /* Initialize it due to a false compiler warning. */
15616 implicit_const
= -1;
15619 if (abbrev_name
== 0)
15622 if (cur_abbrev
->num_attrs
== allocated_attrs
)
15624 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
15626 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
15629 cur_attrs
[cur_abbrev
->num_attrs
].name
15630 = (enum dwarf_attribute
) abbrev_name
;
15631 cur_attrs
[cur_abbrev
->num_attrs
].form
15632 = (enum dwarf_form
) abbrev_form
;
15633 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
15634 ++cur_abbrev
->num_attrs
;
15637 cur_abbrev
->attrs
=
15638 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
15639 cur_abbrev
->num_attrs
);
15640 memcpy (cur_abbrev
->attrs
, cur_attrs
,
15641 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
15643 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
15645 /* Get next abbreviation.
15646 Under Irix6 the abbreviations for a compilation unit are not
15647 always properly terminated with an abbrev number of 0.
15648 Exit loop if we encounter an abbreviation which we have
15649 already read (which means we are about to read the abbreviations
15650 for the next compile unit) or if the end of the abbreviation
15651 table is reached. */
15652 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
15654 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15655 abbrev_ptr
+= bytes_read
;
15656 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
15661 return abbrev_table
;
15664 /* Free the resources held by ABBREV_TABLE. */
15667 abbrev_table_free (struct abbrev_table
*abbrev_table
)
15669 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
15670 xfree (abbrev_table
);
15673 /* Same as abbrev_table_free but as a cleanup.
15674 We pass in a pointer to the pointer to the table so that we can
15675 set the pointer to NULL when we're done. It also simplifies
15676 build_type_psymtabs_1. */
15679 abbrev_table_free_cleanup (void *table_ptr
)
15681 struct abbrev_table
**abbrev_table_ptr
= (struct abbrev_table
**) table_ptr
;
15683 if (*abbrev_table_ptr
!= NULL
)
15684 abbrev_table_free (*abbrev_table_ptr
);
15685 *abbrev_table_ptr
= NULL
;
15688 /* Read the abbrev table for CU from ABBREV_SECTION. */
15691 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
15692 struct dwarf2_section_info
*abbrev_section
)
15695 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
15698 /* Release the memory used by the abbrev table for a compilation unit. */
15701 dwarf2_free_abbrev_table (void *ptr_to_cu
)
15703 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr_to_cu
;
15705 if (cu
->abbrev_table
!= NULL
)
15706 abbrev_table_free (cu
->abbrev_table
);
15707 /* Set this to NULL so that we SEGV if we try to read it later,
15708 and also because free_comp_unit verifies this is NULL. */
15709 cu
->abbrev_table
= NULL
;
15712 /* Returns nonzero if TAG represents a type that we might generate a partial
15716 is_type_tag_for_partial (int tag
)
15721 /* Some types that would be reasonable to generate partial symbols for,
15722 that we don't at present. */
15723 case DW_TAG_array_type
:
15724 case DW_TAG_file_type
:
15725 case DW_TAG_ptr_to_member_type
:
15726 case DW_TAG_set_type
:
15727 case DW_TAG_string_type
:
15728 case DW_TAG_subroutine_type
:
15730 case DW_TAG_base_type
:
15731 case DW_TAG_class_type
:
15732 case DW_TAG_interface_type
:
15733 case DW_TAG_enumeration_type
:
15734 case DW_TAG_structure_type
:
15735 case DW_TAG_subrange_type
:
15736 case DW_TAG_typedef
:
15737 case DW_TAG_union_type
:
15744 /* Load all DIEs that are interesting for partial symbols into memory. */
15746 static struct partial_die_info
*
15747 load_partial_dies (const struct die_reader_specs
*reader
,
15748 const gdb_byte
*info_ptr
, int building_psymtab
)
15750 struct dwarf2_cu
*cu
= reader
->cu
;
15751 struct objfile
*objfile
= cu
->objfile
;
15752 struct partial_die_info
*part_die
;
15753 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
15754 struct abbrev_info
*abbrev
;
15755 unsigned int bytes_read
;
15756 unsigned int load_all
= 0;
15757 int nesting_level
= 1;
15762 gdb_assert (cu
->per_cu
!= NULL
);
15763 if (cu
->per_cu
->load_all_dies
)
15767 = htab_create_alloc_ex (cu
->header
.length
/ 12,
15771 &cu
->comp_unit_obstack
,
15772 hashtab_obstack_allocate
,
15773 dummy_obstack_deallocate
);
15775 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
15779 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
15781 /* A NULL abbrev means the end of a series of children. */
15782 if (abbrev
== NULL
)
15784 if (--nesting_level
== 0)
15786 /* PART_DIE was probably the last thing allocated on the
15787 comp_unit_obstack, so we could call obstack_free
15788 here. We don't do that because the waste is small,
15789 and will be cleaned up when we're done with this
15790 compilation unit. This way, we're also more robust
15791 against other users of the comp_unit_obstack. */
15794 info_ptr
+= bytes_read
;
15795 last_die
= parent_die
;
15796 parent_die
= parent_die
->die_parent
;
15800 /* Check for template arguments. We never save these; if
15801 they're seen, we just mark the parent, and go on our way. */
15802 if (parent_die
!= NULL
15803 && cu
->language
== language_cplus
15804 && (abbrev
->tag
== DW_TAG_template_type_param
15805 || abbrev
->tag
== DW_TAG_template_value_param
))
15807 parent_die
->has_template_arguments
= 1;
15811 /* We don't need a partial DIE for the template argument. */
15812 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15817 /* We only recurse into c++ subprograms looking for template arguments.
15818 Skip their other children. */
15820 && cu
->language
== language_cplus
15821 && parent_die
!= NULL
15822 && parent_die
->tag
== DW_TAG_subprogram
)
15824 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15828 /* Check whether this DIE is interesting enough to save. Normally
15829 we would not be interested in members here, but there may be
15830 later variables referencing them via DW_AT_specification (for
15831 static members). */
15833 && !is_type_tag_for_partial (abbrev
->tag
)
15834 && abbrev
->tag
!= DW_TAG_constant
15835 && abbrev
->tag
!= DW_TAG_enumerator
15836 && abbrev
->tag
!= DW_TAG_subprogram
15837 && abbrev
->tag
!= DW_TAG_lexical_block
15838 && abbrev
->tag
!= DW_TAG_variable
15839 && abbrev
->tag
!= DW_TAG_namespace
15840 && abbrev
->tag
!= DW_TAG_module
15841 && abbrev
->tag
!= DW_TAG_member
15842 && abbrev
->tag
!= DW_TAG_imported_unit
15843 && abbrev
->tag
!= DW_TAG_imported_declaration
)
15845 /* Otherwise we skip to the next sibling, if any. */
15846 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15850 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
15853 /* This two-pass algorithm for processing partial symbols has a
15854 high cost in cache pressure. Thus, handle some simple cases
15855 here which cover the majority of C partial symbols. DIEs
15856 which neither have specification tags in them, nor could have
15857 specification tags elsewhere pointing at them, can simply be
15858 processed and discarded.
15860 This segment is also optional; scan_partial_symbols and
15861 add_partial_symbol will handle these DIEs if we chain
15862 them in normally. When compilers which do not emit large
15863 quantities of duplicate debug information are more common,
15864 this code can probably be removed. */
15866 /* Any complete simple types at the top level (pretty much all
15867 of them, for a language without namespaces), can be processed
15869 if (parent_die
== NULL
15870 && part_die
->has_specification
== 0
15871 && part_die
->is_declaration
== 0
15872 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
15873 || part_die
->tag
== DW_TAG_base_type
15874 || part_die
->tag
== DW_TAG_subrange_type
))
15876 if (building_psymtab
&& part_die
->name
!= NULL
)
15877 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
15878 VAR_DOMAIN
, LOC_TYPEDEF
,
15879 &objfile
->static_psymbols
,
15880 0, cu
->language
, objfile
);
15881 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
15885 /* The exception for DW_TAG_typedef with has_children above is
15886 a workaround of GCC PR debug/47510. In the case of this complaint
15887 type_name_no_tag_or_error will error on such types later.
15889 GDB skipped children of DW_TAG_typedef by the shortcut above and then
15890 it could not find the child DIEs referenced later, this is checked
15891 above. In correct DWARF DW_TAG_typedef should have no children. */
15893 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
15894 complaint (&symfile_complaints
,
15895 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
15896 "- DIE at 0x%x [in module %s]"),
15897 part_die
->offset
.sect_off
, objfile_name (objfile
));
15899 /* If we're at the second level, and we're an enumerator, and
15900 our parent has no specification (meaning possibly lives in a
15901 namespace elsewhere), then we can add the partial symbol now
15902 instead of queueing it. */
15903 if (part_die
->tag
== DW_TAG_enumerator
15904 && parent_die
!= NULL
15905 && parent_die
->die_parent
== NULL
15906 && parent_die
->tag
== DW_TAG_enumeration_type
15907 && parent_die
->has_specification
== 0)
15909 if (part_die
->name
== NULL
)
15910 complaint (&symfile_complaints
,
15911 _("malformed enumerator DIE ignored"));
15912 else if (building_psymtab
)
15913 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
15914 VAR_DOMAIN
, LOC_CONST
,
15915 cu
->language
== language_cplus
15916 ? &objfile
->global_psymbols
15917 : &objfile
->static_psymbols
,
15918 0, cu
->language
, objfile
);
15920 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
15924 /* We'll save this DIE so link it in. */
15925 part_die
->die_parent
= parent_die
;
15926 part_die
->die_sibling
= NULL
;
15927 part_die
->die_child
= NULL
;
15929 if (last_die
&& last_die
== parent_die
)
15930 last_die
->die_child
= part_die
;
15932 last_die
->die_sibling
= part_die
;
15934 last_die
= part_die
;
15936 if (first_die
== NULL
)
15937 first_die
= part_die
;
15939 /* Maybe add the DIE to the hash table. Not all DIEs that we
15940 find interesting need to be in the hash table, because we
15941 also have the parent/sibling/child chains; only those that we
15942 might refer to by offset later during partial symbol reading.
15944 For now this means things that might have be the target of a
15945 DW_AT_specification, DW_AT_abstract_origin, or
15946 DW_AT_extension. DW_AT_extension will refer only to
15947 namespaces; DW_AT_abstract_origin refers to functions (and
15948 many things under the function DIE, but we do not recurse
15949 into function DIEs during partial symbol reading) and
15950 possibly variables as well; DW_AT_specification refers to
15951 declarations. Declarations ought to have the DW_AT_declaration
15952 flag. It happens that GCC forgets to put it in sometimes, but
15953 only for functions, not for types.
15955 Adding more things than necessary to the hash table is harmless
15956 except for the performance cost. Adding too few will result in
15957 wasted time in find_partial_die, when we reread the compilation
15958 unit with load_all_dies set. */
15961 || abbrev
->tag
== DW_TAG_constant
15962 || abbrev
->tag
== DW_TAG_subprogram
15963 || abbrev
->tag
== DW_TAG_variable
15964 || abbrev
->tag
== DW_TAG_namespace
15965 || part_die
->is_declaration
)
15969 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
15970 part_die
->offset
.sect_off
, INSERT
);
15974 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
15976 /* For some DIEs we want to follow their children (if any). For C
15977 we have no reason to follow the children of structures; for other
15978 languages we have to, so that we can get at method physnames
15979 to infer fully qualified class names, for DW_AT_specification,
15980 and for C++ template arguments. For C++, we also look one level
15981 inside functions to find template arguments (if the name of the
15982 function does not already contain the template arguments).
15984 For Ada, we need to scan the children of subprograms and lexical
15985 blocks as well because Ada allows the definition of nested
15986 entities that could be interesting for the debugger, such as
15987 nested subprograms for instance. */
15988 if (last_die
->has_children
15990 || last_die
->tag
== DW_TAG_namespace
15991 || last_die
->tag
== DW_TAG_module
15992 || last_die
->tag
== DW_TAG_enumeration_type
15993 || (cu
->language
== language_cplus
15994 && last_die
->tag
== DW_TAG_subprogram
15995 && (last_die
->name
== NULL
15996 || strchr (last_die
->name
, '<') == NULL
))
15997 || (cu
->language
!= language_c
15998 && (last_die
->tag
== DW_TAG_class_type
15999 || last_die
->tag
== DW_TAG_interface_type
16000 || last_die
->tag
== DW_TAG_structure_type
16001 || last_die
->tag
== DW_TAG_union_type
))
16002 || (cu
->language
== language_ada
16003 && (last_die
->tag
== DW_TAG_subprogram
16004 || last_die
->tag
== DW_TAG_lexical_block
))))
16007 parent_die
= last_die
;
16011 /* Otherwise we skip to the next sibling, if any. */
16012 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
16014 /* Back to the top, do it again. */
16018 /* Read a minimal amount of information into the minimal die structure. */
16020 static const gdb_byte
*
16021 read_partial_die (const struct die_reader_specs
*reader
,
16022 struct partial_die_info
*part_die
,
16023 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
16024 const gdb_byte
*info_ptr
)
16026 struct dwarf2_cu
*cu
= reader
->cu
;
16027 struct objfile
*objfile
= cu
->objfile
;
16028 const gdb_byte
*buffer
= reader
->buffer
;
16030 struct attribute attr
;
16031 int has_low_pc_attr
= 0;
16032 int has_high_pc_attr
= 0;
16033 int high_pc_relative
= 0;
16035 memset (part_die
, 0, sizeof (struct partial_die_info
));
16037 part_die
->offset
.sect_off
= info_ptr
- buffer
;
16039 info_ptr
+= abbrev_len
;
16041 if (abbrev
== NULL
)
16044 part_die
->tag
= abbrev
->tag
;
16045 part_die
->has_children
= abbrev
->has_children
;
16047 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
16049 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
16051 /* Store the data if it is of an attribute we want to keep in a
16052 partial symbol table. */
16056 switch (part_die
->tag
)
16058 case DW_TAG_compile_unit
:
16059 case DW_TAG_partial_unit
:
16060 case DW_TAG_type_unit
:
16061 /* Compilation units have a DW_AT_name that is a filename, not
16062 a source language identifier. */
16063 case DW_TAG_enumeration_type
:
16064 case DW_TAG_enumerator
:
16065 /* These tags always have simple identifiers already; no need
16066 to canonicalize them. */
16067 part_die
->name
= DW_STRING (&attr
);
16071 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
16072 &objfile
->per_bfd
->storage_obstack
);
16076 case DW_AT_linkage_name
:
16077 case DW_AT_MIPS_linkage_name
:
16078 /* Note that both forms of linkage name might appear. We
16079 assume they will be the same, and we only store the last
16081 if (cu
->language
== language_ada
)
16082 part_die
->name
= DW_STRING (&attr
);
16083 part_die
->linkage_name
= DW_STRING (&attr
);
16086 has_low_pc_attr
= 1;
16087 part_die
->lowpc
= attr_value_as_address (&attr
);
16089 case DW_AT_high_pc
:
16090 has_high_pc_attr
= 1;
16091 part_die
->highpc
= attr_value_as_address (&attr
);
16092 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
16093 high_pc_relative
= 1;
16095 case DW_AT_location
:
16096 /* Support the .debug_loc offsets. */
16097 if (attr_form_is_block (&attr
))
16099 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
16101 else if (attr_form_is_section_offset (&attr
))
16103 dwarf2_complex_location_expr_complaint ();
16107 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16108 "partial symbol information");
16111 case DW_AT_external
:
16112 part_die
->is_external
= DW_UNSND (&attr
);
16114 case DW_AT_declaration
:
16115 part_die
->is_declaration
= DW_UNSND (&attr
);
16118 part_die
->has_type
= 1;
16120 case DW_AT_abstract_origin
:
16121 case DW_AT_specification
:
16122 case DW_AT_extension
:
16123 part_die
->has_specification
= 1;
16124 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
16125 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
16126 || cu
->per_cu
->is_dwz
);
16128 case DW_AT_sibling
:
16129 /* Ignore absolute siblings, they might point outside of
16130 the current compile unit. */
16131 if (attr
.form
== DW_FORM_ref_addr
)
16132 complaint (&symfile_complaints
,
16133 _("ignoring absolute DW_AT_sibling"));
16136 unsigned int off
= dwarf2_get_ref_die_offset (&attr
).sect_off
;
16137 const gdb_byte
*sibling_ptr
= buffer
+ off
;
16139 if (sibling_ptr
< info_ptr
)
16140 complaint (&symfile_complaints
,
16141 _("DW_AT_sibling points backwards"));
16142 else if (sibling_ptr
> reader
->buffer_end
)
16143 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
16145 part_die
->sibling
= sibling_ptr
;
16148 case DW_AT_byte_size
:
16149 part_die
->has_byte_size
= 1;
16151 case DW_AT_const_value
:
16152 part_die
->has_const_value
= 1;
16154 case DW_AT_calling_convention
:
16155 /* DWARF doesn't provide a way to identify a program's source-level
16156 entry point. DW_AT_calling_convention attributes are only meant
16157 to describe functions' calling conventions.
16159 However, because it's a necessary piece of information in
16160 Fortran, and before DWARF 4 DW_CC_program was the only
16161 piece of debugging information whose definition refers to
16162 a 'main program' at all, several compilers marked Fortran
16163 main programs with DW_CC_program --- even when those
16164 functions use the standard calling conventions.
16166 Although DWARF now specifies a way to provide this
16167 information, we support this practice for backward
16169 if (DW_UNSND (&attr
) == DW_CC_program
16170 && cu
->language
== language_fortran
)
16171 part_die
->main_subprogram
= 1;
16174 if (DW_UNSND (&attr
) == DW_INL_inlined
16175 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
16176 part_die
->may_be_inlined
= 1;
16180 if (part_die
->tag
== DW_TAG_imported_unit
)
16182 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
16183 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
16184 || cu
->per_cu
->is_dwz
);
16188 case DW_AT_main_subprogram
:
16189 part_die
->main_subprogram
= DW_UNSND (&attr
);
16197 if (high_pc_relative
)
16198 part_die
->highpc
+= part_die
->lowpc
;
16200 if (has_low_pc_attr
&& has_high_pc_attr
)
16202 /* When using the GNU linker, .gnu.linkonce. sections are used to
16203 eliminate duplicate copies of functions and vtables and such.
16204 The linker will arbitrarily choose one and discard the others.
16205 The AT_*_pc values for such functions refer to local labels in
16206 these sections. If the section from that file was discarded, the
16207 labels are not in the output, so the relocs get a value of 0.
16208 If this is a discarded function, mark the pc bounds as invalid,
16209 so that GDB will ignore it. */
16210 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
16212 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16214 complaint (&symfile_complaints
,
16215 _("DW_AT_low_pc %s is zero "
16216 "for DIE at 0x%x [in module %s]"),
16217 paddress (gdbarch
, part_die
->lowpc
),
16218 part_die
->offset
.sect_off
, objfile_name (objfile
));
16220 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
16221 else if (part_die
->lowpc
>= part_die
->highpc
)
16223 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16225 complaint (&symfile_complaints
,
16226 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
16227 "for DIE at 0x%x [in module %s]"),
16228 paddress (gdbarch
, part_die
->lowpc
),
16229 paddress (gdbarch
, part_die
->highpc
),
16230 part_die
->offset
.sect_off
, objfile_name (objfile
));
16233 part_die
->has_pc_info
= 1;
16239 /* Find a cached partial DIE at OFFSET in CU. */
16241 static struct partial_die_info
*
16242 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
16244 struct partial_die_info
*lookup_die
= NULL
;
16245 struct partial_die_info part_die
;
16247 part_die
.offset
= offset
;
16248 lookup_die
= ((struct partial_die_info
*)
16249 htab_find_with_hash (cu
->partial_dies
, &part_die
,
16255 /* Find a partial DIE at OFFSET, which may or may not be in CU,
16256 except in the case of .debug_types DIEs which do not reference
16257 outside their CU (they do however referencing other types via
16258 DW_FORM_ref_sig8). */
16260 static struct partial_die_info
*
16261 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
16263 struct objfile
*objfile
= cu
->objfile
;
16264 struct dwarf2_per_cu_data
*per_cu
= NULL
;
16265 struct partial_die_info
*pd
= NULL
;
16267 if (offset_in_dwz
== cu
->per_cu
->is_dwz
16268 && offset_in_cu_p (&cu
->header
, offset
))
16270 pd
= find_partial_die_in_comp_unit (offset
, cu
);
16273 /* We missed recording what we needed.
16274 Load all dies and try again. */
16275 per_cu
= cu
->per_cu
;
16279 /* TUs don't reference other CUs/TUs (except via type signatures). */
16280 if (cu
->per_cu
->is_debug_types
)
16282 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
16283 " external reference to offset 0x%lx [in module %s].\n"),
16284 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
16285 bfd_get_filename (objfile
->obfd
));
16287 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
16290 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
16291 load_partial_comp_unit (per_cu
);
16293 per_cu
->cu
->last_used
= 0;
16294 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
16297 /* If we didn't find it, and not all dies have been loaded,
16298 load them all and try again. */
16300 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
16302 per_cu
->load_all_dies
= 1;
16304 /* This is nasty. When we reread the DIEs, somewhere up the call chain
16305 THIS_CU->cu may already be in use. So we can't just free it and
16306 replace its DIEs with the ones we read in. Instead, we leave those
16307 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
16308 and clobber THIS_CU->cu->partial_dies with the hash table for the new
16310 load_partial_comp_unit (per_cu
);
16312 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
16316 internal_error (__FILE__
, __LINE__
,
16317 _("could not find partial DIE 0x%x "
16318 "in cache [from module %s]\n"),
16319 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16323 /* See if we can figure out if the class lives in a namespace. We do
16324 this by looking for a member function; its demangled name will
16325 contain namespace info, if there is any. */
16328 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
16329 struct dwarf2_cu
*cu
)
16331 /* NOTE: carlton/2003-10-07: Getting the info this way changes
16332 what template types look like, because the demangler
16333 frequently doesn't give the same name as the debug info. We
16334 could fix this by only using the demangled name to get the
16335 prefix (but see comment in read_structure_type). */
16337 struct partial_die_info
*real_pdi
;
16338 struct partial_die_info
*child_pdi
;
16340 /* If this DIE (this DIE's specification, if any) has a parent, then
16341 we should not do this. We'll prepend the parent's fully qualified
16342 name when we create the partial symbol. */
16344 real_pdi
= struct_pdi
;
16345 while (real_pdi
->has_specification
)
16346 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
16347 real_pdi
->spec_is_dwz
, cu
);
16349 if (real_pdi
->die_parent
!= NULL
)
16352 for (child_pdi
= struct_pdi
->die_child
;
16354 child_pdi
= child_pdi
->die_sibling
)
16356 if (child_pdi
->tag
== DW_TAG_subprogram
16357 && child_pdi
->linkage_name
!= NULL
)
16359 char *actual_class_name
16360 = language_class_name_from_physname (cu
->language_defn
,
16361 child_pdi
->linkage_name
);
16362 if (actual_class_name
!= NULL
)
16366 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16368 strlen (actual_class_name
)));
16369 xfree (actual_class_name
);
16376 /* Adjust PART_DIE before generating a symbol for it. This function
16377 may set the is_external flag or change the DIE's name. */
16380 fixup_partial_die (struct partial_die_info
*part_die
,
16381 struct dwarf2_cu
*cu
)
16383 /* Once we've fixed up a die, there's no point in doing so again.
16384 This also avoids a memory leak if we were to call
16385 guess_partial_die_structure_name multiple times. */
16386 if (part_die
->fixup_called
)
16389 /* If we found a reference attribute and the DIE has no name, try
16390 to find a name in the referred to DIE. */
16392 if (part_die
->name
== NULL
&& part_die
->has_specification
)
16394 struct partial_die_info
*spec_die
;
16396 spec_die
= find_partial_die (part_die
->spec_offset
,
16397 part_die
->spec_is_dwz
, cu
);
16399 fixup_partial_die (spec_die
, cu
);
16401 if (spec_die
->name
)
16403 part_die
->name
= spec_die
->name
;
16405 /* Copy DW_AT_external attribute if it is set. */
16406 if (spec_die
->is_external
)
16407 part_die
->is_external
= spec_die
->is_external
;
16411 /* Set default names for some unnamed DIEs. */
16413 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
16414 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
16416 /* If there is no parent die to provide a namespace, and there are
16417 children, see if we can determine the namespace from their linkage
16419 if (cu
->language
== language_cplus
16420 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
16421 && part_die
->die_parent
== NULL
16422 && part_die
->has_children
16423 && (part_die
->tag
== DW_TAG_class_type
16424 || part_die
->tag
== DW_TAG_structure_type
16425 || part_die
->tag
== DW_TAG_union_type
))
16426 guess_partial_die_structure_name (part_die
, cu
);
16428 /* GCC might emit a nameless struct or union that has a linkage
16429 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16430 if (part_die
->name
== NULL
16431 && (part_die
->tag
== DW_TAG_class_type
16432 || part_die
->tag
== DW_TAG_interface_type
16433 || part_die
->tag
== DW_TAG_structure_type
16434 || part_die
->tag
== DW_TAG_union_type
)
16435 && part_die
->linkage_name
!= NULL
)
16439 demangled
= gdb_demangle (part_die
->linkage_name
, DMGL_TYPES
);
16444 /* Strip any leading namespaces/classes, keep only the base name.
16445 DW_AT_name for named DIEs does not contain the prefixes. */
16446 base
= strrchr (demangled
, ':');
16447 if (base
&& base
> demangled
&& base
[-1] == ':')
16454 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16455 base
, strlen (base
)));
16460 part_die
->fixup_called
= 1;
16463 /* Read an attribute value described by an attribute form. */
16465 static const gdb_byte
*
16466 read_attribute_value (const struct die_reader_specs
*reader
,
16467 struct attribute
*attr
, unsigned form
,
16468 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
16470 struct dwarf2_cu
*cu
= reader
->cu
;
16471 struct objfile
*objfile
= cu
->objfile
;
16472 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16473 bfd
*abfd
= reader
->abfd
;
16474 struct comp_unit_head
*cu_header
= &cu
->header
;
16475 unsigned int bytes_read
;
16476 struct dwarf_block
*blk
;
16478 attr
->form
= (enum dwarf_form
) form
;
16481 case DW_FORM_ref_addr
:
16482 if (cu
->header
.version
== 2)
16483 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
16485 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
16486 &cu
->header
, &bytes_read
);
16487 info_ptr
+= bytes_read
;
16489 case DW_FORM_GNU_ref_alt
:
16490 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
16491 info_ptr
+= bytes_read
;
16494 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
16495 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
16496 info_ptr
+= bytes_read
;
16498 case DW_FORM_block2
:
16499 blk
= dwarf_alloc_block (cu
);
16500 blk
->size
= read_2_bytes (abfd
, info_ptr
);
16502 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16503 info_ptr
+= blk
->size
;
16504 DW_BLOCK (attr
) = blk
;
16506 case DW_FORM_block4
:
16507 blk
= dwarf_alloc_block (cu
);
16508 blk
->size
= read_4_bytes (abfd
, info_ptr
);
16510 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16511 info_ptr
+= blk
->size
;
16512 DW_BLOCK (attr
) = blk
;
16514 case DW_FORM_data2
:
16515 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
16518 case DW_FORM_data4
:
16519 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
16522 case DW_FORM_data8
:
16523 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
16526 case DW_FORM_sec_offset
:
16527 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
16528 info_ptr
+= bytes_read
;
16530 case DW_FORM_string
:
16531 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
16532 DW_STRING_IS_CANONICAL (attr
) = 0;
16533 info_ptr
+= bytes_read
;
16536 if (!cu
->per_cu
->is_dwz
)
16538 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
16540 DW_STRING_IS_CANONICAL (attr
) = 0;
16541 info_ptr
+= bytes_read
;
16545 case DW_FORM_line_strp
:
16546 if (!cu
->per_cu
->is_dwz
)
16548 DW_STRING (attr
) = read_indirect_line_string (abfd
, info_ptr
,
16549 cu_header
, &bytes_read
);
16550 DW_STRING_IS_CANONICAL (attr
) = 0;
16551 info_ptr
+= bytes_read
;
16555 case DW_FORM_GNU_strp_alt
:
16557 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
16558 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
16561 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
16562 DW_STRING_IS_CANONICAL (attr
) = 0;
16563 info_ptr
+= bytes_read
;
16566 case DW_FORM_exprloc
:
16567 case DW_FORM_block
:
16568 blk
= dwarf_alloc_block (cu
);
16569 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16570 info_ptr
+= bytes_read
;
16571 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16572 info_ptr
+= blk
->size
;
16573 DW_BLOCK (attr
) = blk
;
16575 case DW_FORM_block1
:
16576 blk
= dwarf_alloc_block (cu
);
16577 blk
->size
= read_1_byte (abfd
, info_ptr
);
16579 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16580 info_ptr
+= blk
->size
;
16581 DW_BLOCK (attr
) = blk
;
16583 case DW_FORM_data1
:
16584 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
16588 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
16591 case DW_FORM_flag_present
:
16592 DW_UNSND (attr
) = 1;
16594 case DW_FORM_sdata
:
16595 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
16596 info_ptr
+= bytes_read
;
16598 case DW_FORM_udata
:
16599 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16600 info_ptr
+= bytes_read
;
16603 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16604 + read_1_byte (abfd
, info_ptr
));
16608 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16609 + read_2_bytes (abfd
, info_ptr
));
16613 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16614 + read_4_bytes (abfd
, info_ptr
));
16618 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16619 + read_8_bytes (abfd
, info_ptr
));
16622 case DW_FORM_ref_sig8
:
16623 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
16626 case DW_FORM_ref_udata
:
16627 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16628 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
16629 info_ptr
+= bytes_read
;
16631 case DW_FORM_indirect
:
16632 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16633 info_ptr
+= bytes_read
;
16634 if (form
== DW_FORM_implicit_const
)
16636 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
16637 info_ptr
+= bytes_read
;
16639 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
16642 case DW_FORM_implicit_const
:
16643 DW_SND (attr
) = implicit_const
;
16645 case DW_FORM_GNU_addr_index
:
16646 if (reader
->dwo_file
== NULL
)
16648 /* For now flag a hard error.
16649 Later we can turn this into a complaint. */
16650 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
16651 dwarf_form_name (form
),
16652 bfd_get_filename (abfd
));
16654 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
16655 info_ptr
+= bytes_read
;
16657 case DW_FORM_GNU_str_index
:
16658 if (reader
->dwo_file
== NULL
)
16660 /* For now flag a hard error.
16661 Later we can turn this into a complaint if warranted. */
16662 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
16663 dwarf_form_name (form
),
16664 bfd_get_filename (abfd
));
16667 ULONGEST str_index
=
16668 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16670 DW_STRING (attr
) = read_str_index (reader
, str_index
);
16671 DW_STRING_IS_CANONICAL (attr
) = 0;
16672 info_ptr
+= bytes_read
;
16676 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
16677 dwarf_form_name (form
),
16678 bfd_get_filename (abfd
));
16682 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
16683 attr
->form
= DW_FORM_GNU_ref_alt
;
16685 /* We have seen instances where the compiler tried to emit a byte
16686 size attribute of -1 which ended up being encoded as an unsigned
16687 0xffffffff. Although 0xffffffff is technically a valid size value,
16688 an object of this size seems pretty unlikely so we can relatively
16689 safely treat these cases as if the size attribute was invalid and
16690 treat them as zero by default. */
16691 if (attr
->name
== DW_AT_byte_size
16692 && form
== DW_FORM_data4
16693 && DW_UNSND (attr
) >= 0xffffffff)
16696 (&symfile_complaints
,
16697 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
16698 hex_string (DW_UNSND (attr
)));
16699 DW_UNSND (attr
) = 0;
16705 /* Read an attribute described by an abbreviated attribute. */
16707 static const gdb_byte
*
16708 read_attribute (const struct die_reader_specs
*reader
,
16709 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
16710 const gdb_byte
*info_ptr
)
16712 attr
->name
= abbrev
->name
;
16713 return read_attribute_value (reader
, attr
, abbrev
->form
,
16714 abbrev
->implicit_const
, info_ptr
);
16717 /* Read dwarf information from a buffer. */
16719 static unsigned int
16720 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
16722 return bfd_get_8 (abfd
, buf
);
16726 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
16728 return bfd_get_signed_8 (abfd
, buf
);
16731 static unsigned int
16732 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16734 return bfd_get_16 (abfd
, buf
);
16738 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16740 return bfd_get_signed_16 (abfd
, buf
);
16743 static unsigned int
16744 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16746 return bfd_get_32 (abfd
, buf
);
16750 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16752 return bfd_get_signed_32 (abfd
, buf
);
16756 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16758 return bfd_get_64 (abfd
, buf
);
16762 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
16763 unsigned int *bytes_read
)
16765 struct comp_unit_head
*cu_header
= &cu
->header
;
16766 CORE_ADDR retval
= 0;
16768 if (cu_header
->signed_addr_p
)
16770 switch (cu_header
->addr_size
)
16773 retval
= bfd_get_signed_16 (abfd
, buf
);
16776 retval
= bfd_get_signed_32 (abfd
, buf
);
16779 retval
= bfd_get_signed_64 (abfd
, buf
);
16782 internal_error (__FILE__
, __LINE__
,
16783 _("read_address: bad switch, signed [in module %s]"),
16784 bfd_get_filename (abfd
));
16789 switch (cu_header
->addr_size
)
16792 retval
= bfd_get_16 (abfd
, buf
);
16795 retval
= bfd_get_32 (abfd
, buf
);
16798 retval
= bfd_get_64 (abfd
, buf
);
16801 internal_error (__FILE__
, __LINE__
,
16802 _("read_address: bad switch, "
16803 "unsigned [in module %s]"),
16804 bfd_get_filename (abfd
));
16808 *bytes_read
= cu_header
->addr_size
;
16812 /* Read the initial length from a section. The (draft) DWARF 3
16813 specification allows the initial length to take up either 4 bytes
16814 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
16815 bytes describe the length and all offsets will be 8 bytes in length
16818 An older, non-standard 64-bit format is also handled by this
16819 function. The older format in question stores the initial length
16820 as an 8-byte quantity without an escape value. Lengths greater
16821 than 2^32 aren't very common which means that the initial 4 bytes
16822 is almost always zero. Since a length value of zero doesn't make
16823 sense for the 32-bit format, this initial zero can be considered to
16824 be an escape value which indicates the presence of the older 64-bit
16825 format. As written, the code can't detect (old format) lengths
16826 greater than 4GB. If it becomes necessary to handle lengths
16827 somewhat larger than 4GB, we could allow other small values (such
16828 as the non-sensical values of 1, 2, and 3) to also be used as
16829 escape values indicating the presence of the old format.
16831 The value returned via bytes_read should be used to increment the
16832 relevant pointer after calling read_initial_length().
16834 [ Note: read_initial_length() and read_offset() are based on the
16835 document entitled "DWARF Debugging Information Format", revision
16836 3, draft 8, dated November 19, 2001. This document was obtained
16839 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
16841 This document is only a draft and is subject to change. (So beware.)
16843 Details regarding the older, non-standard 64-bit format were
16844 determined empirically by examining 64-bit ELF files produced by
16845 the SGI toolchain on an IRIX 6.5 machine.
16847 - Kevin, July 16, 2002
16851 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
16853 LONGEST length
= bfd_get_32 (abfd
, buf
);
16855 if (length
== 0xffffffff)
16857 length
= bfd_get_64 (abfd
, buf
+ 4);
16860 else if (length
== 0)
16862 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
16863 length
= bfd_get_64 (abfd
, buf
);
16874 /* Cover function for read_initial_length.
16875 Returns the length of the object at BUF, and stores the size of the
16876 initial length in *BYTES_READ and stores the size that offsets will be in
16878 If the initial length size is not equivalent to that specified in
16879 CU_HEADER then issue a complaint.
16880 This is useful when reading non-comp-unit headers. */
16883 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
16884 const struct comp_unit_head
*cu_header
,
16885 unsigned int *bytes_read
,
16886 unsigned int *offset_size
)
16888 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
16890 gdb_assert (cu_header
->initial_length_size
== 4
16891 || cu_header
->initial_length_size
== 8
16892 || cu_header
->initial_length_size
== 12);
16894 if (cu_header
->initial_length_size
!= *bytes_read
)
16895 complaint (&symfile_complaints
,
16896 _("intermixed 32-bit and 64-bit DWARF sections"));
16898 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
16902 /* Read an offset from the data stream. The size of the offset is
16903 given by cu_header->offset_size. */
16906 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
16907 const struct comp_unit_head
*cu_header
,
16908 unsigned int *bytes_read
)
16910 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
16912 *bytes_read
= cu_header
->offset_size
;
16916 /* Read an offset from the data stream. */
16919 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
16921 LONGEST retval
= 0;
16923 switch (offset_size
)
16926 retval
= bfd_get_32 (abfd
, buf
);
16929 retval
= bfd_get_64 (abfd
, buf
);
16932 internal_error (__FILE__
, __LINE__
,
16933 _("read_offset_1: bad switch [in module %s]"),
16934 bfd_get_filename (abfd
));
16940 static const gdb_byte
*
16941 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
16943 /* If the size of a host char is 8 bits, we can return a pointer
16944 to the buffer, otherwise we have to copy the data to a buffer
16945 allocated on the temporary obstack. */
16946 gdb_assert (HOST_CHAR_BIT
== 8);
16950 static const char *
16951 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
16952 unsigned int *bytes_read_ptr
)
16954 /* If the size of a host char is 8 bits, we can return a pointer
16955 to the string, otherwise we have to copy the string to a buffer
16956 allocated on the temporary obstack. */
16957 gdb_assert (HOST_CHAR_BIT
== 8);
16960 *bytes_read_ptr
= 1;
16963 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
16964 return (const char *) buf
;
16967 /* Return pointer to string at section SECT offset STR_OFFSET with error
16968 reporting strings FORM_NAME and SECT_NAME. */
16970 static const char *
16971 read_indirect_string_at_offset_from (bfd
*abfd
, LONGEST str_offset
,
16972 struct dwarf2_section_info
*sect
,
16973 const char *form_name
,
16974 const char *sect_name
)
16976 dwarf2_read_section (dwarf2_per_objfile
->objfile
, sect
);
16977 if (sect
->buffer
== NULL
)
16978 error (_("%s used without %s section [in module %s]"),
16979 form_name
, sect_name
, bfd_get_filename (abfd
));
16980 if (str_offset
>= sect
->size
)
16981 error (_("%s pointing outside of %s section [in module %s]"),
16982 form_name
, sect_name
, bfd_get_filename (abfd
));
16983 gdb_assert (HOST_CHAR_BIT
== 8);
16984 if (sect
->buffer
[str_offset
] == '\0')
16986 return (const char *) (sect
->buffer
+ str_offset
);
16989 /* Return pointer to string at .debug_str offset STR_OFFSET. */
16991 static const char *
16992 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
16994 return read_indirect_string_at_offset_from (abfd
, str_offset
,
16995 &dwarf2_per_objfile
->str
,
16996 "DW_FORM_strp", ".debug_str");
16999 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
17001 static const char *
17002 read_indirect_line_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
17004 return read_indirect_string_at_offset_from (abfd
, str_offset
,
17005 &dwarf2_per_objfile
->line_str
,
17006 "DW_FORM_line_strp",
17007 ".debug_line_str");
17010 /* Read a string at offset STR_OFFSET in the .debug_str section from
17011 the .dwz file DWZ. Throw an error if the offset is too large. If
17012 the string consists of a single NUL byte, return NULL; otherwise
17013 return a pointer to the string. */
17015 static const char *
17016 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
17018 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
17020 if (dwz
->str
.buffer
== NULL
)
17021 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
17022 "section [in module %s]"),
17023 bfd_get_filename (dwz
->dwz_bfd
));
17024 if (str_offset
>= dwz
->str
.size
)
17025 error (_("DW_FORM_GNU_strp_alt pointing outside of "
17026 ".debug_str section [in module %s]"),
17027 bfd_get_filename (dwz
->dwz_bfd
));
17028 gdb_assert (HOST_CHAR_BIT
== 8);
17029 if (dwz
->str
.buffer
[str_offset
] == '\0')
17031 return (const char *) (dwz
->str
.buffer
+ str_offset
);
17034 /* Return pointer to string at .debug_str offset as read from BUF.
17035 BUF is assumed to be in a compilation unit described by CU_HEADER.
17036 Return *BYTES_READ_PTR count of bytes read from BUF. */
17038 static const char *
17039 read_indirect_string (bfd
*abfd
, const gdb_byte
*buf
,
17040 const struct comp_unit_head
*cu_header
,
17041 unsigned int *bytes_read_ptr
)
17043 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
17045 return read_indirect_string_at_offset (abfd
, str_offset
);
17048 /* Return pointer to string at .debug_line_str offset as read from BUF.
17049 BUF is assumed to be in a compilation unit described by CU_HEADER.
17050 Return *BYTES_READ_PTR count of bytes read from BUF. */
17052 static const char *
17053 read_indirect_line_string (bfd
*abfd
, const gdb_byte
*buf
,
17054 const struct comp_unit_head
*cu_header
,
17055 unsigned int *bytes_read_ptr
)
17057 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
17059 return read_indirect_line_string_at_offset (abfd
, str_offset
);
17063 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
17064 unsigned int *bytes_read_ptr
)
17067 unsigned int num_read
;
17069 unsigned char byte
;
17076 byte
= bfd_get_8 (abfd
, buf
);
17079 result
|= ((ULONGEST
) (byte
& 127) << shift
);
17080 if ((byte
& 128) == 0)
17086 *bytes_read_ptr
= num_read
;
17091 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
17092 unsigned int *bytes_read_ptr
)
17095 int shift
, num_read
;
17096 unsigned char byte
;
17103 byte
= bfd_get_8 (abfd
, buf
);
17106 result
|= ((LONGEST
) (byte
& 127) << shift
);
17108 if ((byte
& 128) == 0)
17113 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
17114 result
|= -(((LONGEST
) 1) << shift
);
17115 *bytes_read_ptr
= num_read
;
17119 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
17120 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
17121 ADDR_SIZE is the size of addresses from the CU header. */
17124 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
17126 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17127 bfd
*abfd
= objfile
->obfd
;
17128 const gdb_byte
*info_ptr
;
17130 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
17131 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
17132 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
17133 objfile_name (objfile
));
17134 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
17135 error (_("DW_FORM_addr_index pointing outside of "
17136 ".debug_addr section [in module %s]"),
17137 objfile_name (objfile
));
17138 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
17139 + addr_base
+ addr_index
* addr_size
);
17140 if (addr_size
== 4)
17141 return bfd_get_32 (abfd
, info_ptr
);
17143 return bfd_get_64 (abfd
, info_ptr
);
17146 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
17149 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
17151 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
17154 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
17157 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
17158 unsigned int *bytes_read
)
17160 bfd
*abfd
= cu
->objfile
->obfd
;
17161 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
17163 return read_addr_index (cu
, addr_index
);
17166 /* Data structure to pass results from dwarf2_read_addr_index_reader
17167 back to dwarf2_read_addr_index. */
17169 struct dwarf2_read_addr_index_data
17171 ULONGEST addr_base
;
17175 /* die_reader_func for dwarf2_read_addr_index. */
17178 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
17179 const gdb_byte
*info_ptr
,
17180 struct die_info
*comp_unit_die
,
17184 struct dwarf2_cu
*cu
= reader
->cu
;
17185 struct dwarf2_read_addr_index_data
*aidata
=
17186 (struct dwarf2_read_addr_index_data
*) data
;
17188 aidata
->addr_base
= cu
->addr_base
;
17189 aidata
->addr_size
= cu
->header
.addr_size
;
17192 /* Given an index in .debug_addr, fetch the value.
17193 NOTE: This can be called during dwarf expression evaluation,
17194 long after the debug information has been read, and thus per_cu->cu
17195 may no longer exist. */
17198 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
17199 unsigned int addr_index
)
17201 struct objfile
*objfile
= per_cu
->objfile
;
17202 struct dwarf2_cu
*cu
= per_cu
->cu
;
17203 ULONGEST addr_base
;
17206 /* This is intended to be called from outside this file. */
17207 dw2_setup (objfile
);
17209 /* We need addr_base and addr_size.
17210 If we don't have PER_CU->cu, we have to get it.
17211 Nasty, but the alternative is storing the needed info in PER_CU,
17212 which at this point doesn't seem justified: it's not clear how frequently
17213 it would get used and it would increase the size of every PER_CU.
17214 Entry points like dwarf2_per_cu_addr_size do a similar thing
17215 so we're not in uncharted territory here.
17216 Alas we need to be a bit more complicated as addr_base is contained
17219 We don't need to read the entire CU(/TU).
17220 We just need the header and top level die.
17222 IWBN to use the aging mechanism to let us lazily later discard the CU.
17223 For now we skip this optimization. */
17227 addr_base
= cu
->addr_base
;
17228 addr_size
= cu
->header
.addr_size
;
17232 struct dwarf2_read_addr_index_data aidata
;
17234 /* Note: We can't use init_cutu_and_read_dies_simple here,
17235 we need addr_base. */
17236 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
17237 dwarf2_read_addr_index_reader
, &aidata
);
17238 addr_base
= aidata
.addr_base
;
17239 addr_size
= aidata
.addr_size
;
17242 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
17245 /* Given a DW_FORM_GNU_str_index, fetch the string.
17246 This is only used by the Fission support. */
17248 static const char *
17249 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
17251 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17252 const char *objf_name
= objfile_name (objfile
);
17253 bfd
*abfd
= objfile
->obfd
;
17254 struct dwarf2_cu
*cu
= reader
->cu
;
17255 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
17256 struct dwarf2_section_info
*str_offsets_section
=
17257 &reader
->dwo_file
->sections
.str_offsets
;
17258 const gdb_byte
*info_ptr
;
17259 ULONGEST str_offset
;
17260 static const char form_name
[] = "DW_FORM_GNU_str_index";
17262 dwarf2_read_section (objfile
, str_section
);
17263 dwarf2_read_section (objfile
, str_offsets_section
);
17264 if (str_section
->buffer
== NULL
)
17265 error (_("%s used without .debug_str.dwo section"
17266 " in CU at offset 0x%lx [in module %s]"),
17267 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
17268 if (str_offsets_section
->buffer
== NULL
)
17269 error (_("%s used without .debug_str_offsets.dwo section"
17270 " in CU at offset 0x%lx [in module %s]"),
17271 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
17272 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
17273 error (_("%s pointing outside of .debug_str_offsets.dwo"
17274 " section in CU at offset 0x%lx [in module %s]"),
17275 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
17276 info_ptr
= (str_offsets_section
->buffer
17277 + str_index
* cu
->header
.offset_size
);
17278 if (cu
->header
.offset_size
== 4)
17279 str_offset
= bfd_get_32 (abfd
, info_ptr
);
17281 str_offset
= bfd_get_64 (abfd
, info_ptr
);
17282 if (str_offset
>= str_section
->size
)
17283 error (_("Offset from %s pointing outside of"
17284 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
17285 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
17286 return (const char *) (str_section
->buffer
+ str_offset
);
17289 /* Return the length of an LEB128 number in BUF. */
17292 leb128_size (const gdb_byte
*buf
)
17294 const gdb_byte
*begin
= buf
;
17300 if ((byte
& 128) == 0)
17301 return buf
- begin
;
17306 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
17315 cu
->language
= language_c
;
17318 case DW_LANG_C_plus_plus
:
17319 case DW_LANG_C_plus_plus_11
:
17320 case DW_LANG_C_plus_plus_14
:
17321 cu
->language
= language_cplus
;
17324 cu
->language
= language_d
;
17326 case DW_LANG_Fortran77
:
17327 case DW_LANG_Fortran90
:
17328 case DW_LANG_Fortran95
:
17329 case DW_LANG_Fortran03
:
17330 case DW_LANG_Fortran08
:
17331 cu
->language
= language_fortran
;
17334 cu
->language
= language_go
;
17336 case DW_LANG_Mips_Assembler
:
17337 cu
->language
= language_asm
;
17339 case DW_LANG_Ada83
:
17340 case DW_LANG_Ada95
:
17341 cu
->language
= language_ada
;
17343 case DW_LANG_Modula2
:
17344 cu
->language
= language_m2
;
17346 case DW_LANG_Pascal83
:
17347 cu
->language
= language_pascal
;
17350 cu
->language
= language_objc
;
17353 case DW_LANG_Rust_old
:
17354 cu
->language
= language_rust
;
17356 case DW_LANG_Cobol74
:
17357 case DW_LANG_Cobol85
:
17359 cu
->language
= language_minimal
;
17362 cu
->language_defn
= language_def (cu
->language
);
17365 /* Return the named attribute or NULL if not there. */
17367 static struct attribute
*
17368 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17373 struct attribute
*spec
= NULL
;
17375 for (i
= 0; i
< die
->num_attrs
; ++i
)
17377 if (die
->attrs
[i
].name
== name
)
17378 return &die
->attrs
[i
];
17379 if (die
->attrs
[i
].name
== DW_AT_specification
17380 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
17381 spec
= &die
->attrs
[i
];
17387 die
= follow_die_ref (die
, spec
, &cu
);
17393 /* Return the named attribute or NULL if not there,
17394 but do not follow DW_AT_specification, etc.
17395 This is for use in contexts where we're reading .debug_types dies.
17396 Following DW_AT_specification, DW_AT_abstract_origin will take us
17397 back up the chain, and we want to go down. */
17399 static struct attribute
*
17400 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
17404 for (i
= 0; i
< die
->num_attrs
; ++i
)
17405 if (die
->attrs
[i
].name
== name
)
17406 return &die
->attrs
[i
];
17411 /* Return the string associated with a string-typed attribute, or NULL if it
17412 is either not found or is of an incorrect type. */
17414 static const char *
17415 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17417 struct attribute
*attr
;
17418 const char *str
= NULL
;
17420 attr
= dwarf2_attr (die
, name
, cu
);
17424 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
17425 || attr
->form
== DW_FORM_string
|| attr
->form
== DW_FORM_GNU_strp_alt
)
17426 str
= DW_STRING (attr
);
17428 complaint (&symfile_complaints
,
17429 _("string type expected for attribute %s for "
17430 "DIE at 0x%x in module %s"),
17431 dwarf_attr_name (name
), die
->offset
.sect_off
,
17432 objfile_name (cu
->objfile
));
17438 /* Return non-zero iff the attribute NAME is defined for the given DIE,
17439 and holds a non-zero value. This function should only be used for
17440 DW_FORM_flag or DW_FORM_flag_present attributes. */
17443 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
17445 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
17447 return (attr
&& DW_UNSND (attr
));
17451 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
17453 /* A DIE is a declaration if it has a DW_AT_declaration attribute
17454 which value is non-zero. However, we have to be careful with
17455 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
17456 (via dwarf2_flag_true_p) follows this attribute. So we may
17457 end up accidently finding a declaration attribute that belongs
17458 to a different DIE referenced by the specification attribute,
17459 even though the given DIE does not have a declaration attribute. */
17460 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
17461 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
17464 /* Return the die giving the specification for DIE, if there is
17465 one. *SPEC_CU is the CU containing DIE on input, and the CU
17466 containing the return value on output. If there is no
17467 specification, but there is an abstract origin, that is
17470 static struct die_info
*
17471 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
17473 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
17476 if (spec_attr
== NULL
)
17477 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
17479 if (spec_attr
== NULL
)
17482 return follow_die_ref (die
, spec_attr
, spec_cu
);
17485 /* Free the line_header structure *LH, and any arrays and strings it
17487 NOTE: This is also used as a "cleanup" function. */
17490 free_line_header (struct line_header
*lh
)
17492 if (lh
->standard_opcode_lengths
)
17493 xfree (lh
->standard_opcode_lengths
);
17495 /* Remember that all the lh->file_names[i].name pointers are
17496 pointers into debug_line_buffer, and don't need to be freed. */
17497 if (lh
->file_names
)
17498 xfree (lh
->file_names
);
17500 /* Similarly for the include directory names. */
17501 if (lh
->include_dirs
)
17502 xfree (lh
->include_dirs
);
17507 /* Stub for free_line_header to match void * callback types. */
17510 free_line_header_voidp (void *arg
)
17512 struct line_header
*lh
= (struct line_header
*) arg
;
17514 free_line_header (lh
);
17517 /* Add an entry to LH's include directory table. */
17520 add_include_dir (struct line_header
*lh
, const char *include_dir
)
17522 if (dwarf_line_debug
>= 2)
17523 fprintf_unfiltered (gdb_stdlog
, "Adding dir %u: %s\n",
17524 lh
->num_include_dirs
+ 1, include_dir
);
17526 /* Grow the array if necessary. */
17527 if (lh
->include_dirs_size
== 0)
17529 lh
->include_dirs_size
= 1; /* for testing */
17530 lh
->include_dirs
= XNEWVEC (const char *, lh
->include_dirs_size
);
17532 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
17534 lh
->include_dirs_size
*= 2;
17535 lh
->include_dirs
= XRESIZEVEC (const char *, lh
->include_dirs
,
17536 lh
->include_dirs_size
);
17539 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
17542 /* Add an entry to LH's file name table. */
17545 add_file_name (struct line_header
*lh
,
17547 unsigned int dir_index
,
17548 unsigned int mod_time
,
17549 unsigned int length
)
17551 struct file_entry
*fe
;
17553 if (dwarf_line_debug
>= 2)
17554 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
17555 lh
->num_file_names
+ 1, name
);
17557 /* Grow the array if necessary. */
17558 if (lh
->file_names_size
== 0)
17560 lh
->file_names_size
= 1; /* for testing */
17561 lh
->file_names
= XNEWVEC (struct file_entry
, lh
->file_names_size
);
17563 else if (lh
->num_file_names
>= lh
->file_names_size
)
17565 lh
->file_names_size
*= 2;
17567 = XRESIZEVEC (struct file_entry
, lh
->file_names
, lh
->file_names_size
);
17570 fe
= &lh
->file_names
[lh
->num_file_names
++];
17572 fe
->dir_index
= dir_index
;
17573 fe
->mod_time
= mod_time
;
17574 fe
->length
= length
;
17575 fe
->included_p
= 0;
17579 /* A convenience function to find the proper .debug_line section for a CU. */
17581 static struct dwarf2_section_info
*
17582 get_debug_line_section (struct dwarf2_cu
*cu
)
17584 struct dwarf2_section_info
*section
;
17586 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
17588 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17589 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
17590 else if (cu
->per_cu
->is_dwz
)
17592 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
17594 section
= &dwz
->line
;
17597 section
= &dwarf2_per_objfile
->line
;
17602 /* Forwarding function for read_formatted_entries. */
17605 add_include_dir_stub (struct line_header
*lh
, const char *name
,
17606 unsigned int dir_index
, unsigned int mod_time
,
17607 unsigned int length
)
17609 add_include_dir (lh
, name
);
17612 /* Read directory or file name entry format, starting with byte of
17613 format count entries, ULEB128 pairs of entry formats, ULEB128 of
17614 entries count and the entries themselves in the described entry
17618 read_formatted_entries (bfd
*abfd
, const gdb_byte
**bufp
,
17619 struct line_header
*lh
,
17620 const struct comp_unit_head
*cu_header
,
17621 void (*callback
) (struct line_header
*lh
,
17623 unsigned int dir_index
,
17624 unsigned int mod_time
,
17625 unsigned int length
))
17627 gdb_byte format_count
, formati
;
17628 ULONGEST data_count
, datai
;
17629 const gdb_byte
*buf
= *bufp
;
17630 const gdb_byte
*format_header_data
;
17632 unsigned int bytes_read
;
17634 format_count
= read_1_byte (abfd
, buf
);
17636 format_header_data
= buf
;
17637 for (formati
= 0; formati
< format_count
; formati
++)
17639 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17641 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17645 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17647 for (datai
= 0; datai
< data_count
; datai
++)
17649 const gdb_byte
*format
= format_header_data
;
17650 struct file_entry fe
;
17652 memset (&fe
, 0, sizeof (fe
));
17654 for (formati
= 0; formati
< format_count
; formati
++)
17656 ULONGEST content_type
, form
;
17657 const char *string_trash
;
17658 const char **stringp
= &string_trash
;
17659 unsigned int uint_trash
, *uintp
= &uint_trash
;
17661 content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
17662 format
+= bytes_read
;
17663 switch (content_type
)
17666 stringp
= &fe
.name
;
17668 case DW_LNCT_directory_index
:
17669 uintp
= &fe
.dir_index
;
17671 case DW_LNCT_timestamp
:
17672 uintp
= &fe
.mod_time
;
17675 uintp
= &fe
.length
;
17680 complaint (&symfile_complaints
,
17681 _("Unknown format content type %s"),
17682 pulongest (content_type
));
17685 form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
17686 format
+= bytes_read
;
17689 case DW_FORM_string
:
17690 *stringp
= read_direct_string (abfd
, buf
, &bytes_read
);
17694 case DW_FORM_line_strp
:
17695 *stringp
= read_indirect_line_string (abfd
, buf
, cu_header
, &bytes_read
);
17699 case DW_FORM_data1
:
17700 *uintp
= read_1_byte (abfd
, buf
);
17704 case DW_FORM_data2
:
17705 *uintp
= read_2_bytes (abfd
, buf
);
17709 case DW_FORM_data4
:
17710 *uintp
= read_4_bytes (abfd
, buf
);
17714 case DW_FORM_data8
:
17715 *uintp
= read_8_bytes (abfd
, buf
);
17719 case DW_FORM_udata
:
17720 *uintp
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17724 case DW_FORM_block
:
17725 /* It is valid only for DW_LNCT_timestamp which is ignored by
17731 callback (lh
, fe
.name
, fe
.dir_index
, fe
.mod_time
, fe
.length
);
17737 /* Read the statement program header starting at OFFSET in
17738 .debug_line, or .debug_line.dwo. Return a pointer
17739 to a struct line_header, allocated using xmalloc.
17740 Returns NULL if there is a problem reading the header, e.g., if it
17741 has a version we don't understand.
17743 NOTE: the strings in the include directory and file name tables of
17744 the returned object point into the dwarf line section buffer,
17745 and must not be freed. */
17747 static struct line_header
*
17748 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
17750 struct cleanup
*back_to
;
17751 struct line_header
*lh
;
17752 const gdb_byte
*line_ptr
;
17753 unsigned int bytes_read
, offset_size
;
17755 const char *cur_dir
, *cur_file
;
17756 struct dwarf2_section_info
*section
;
17759 section
= get_debug_line_section (cu
);
17760 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
17761 if (section
->buffer
== NULL
)
17763 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17764 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
17766 complaint (&symfile_complaints
, _("missing .debug_line section"));
17770 /* We can't do this until we know the section is non-empty.
17771 Only then do we know we have such a section. */
17772 abfd
= get_section_bfd_owner (section
);
17774 /* Make sure that at least there's room for the total_length field.
17775 That could be 12 bytes long, but we're just going to fudge that. */
17776 if (offset
+ 4 >= section
->size
)
17778 dwarf2_statement_list_fits_in_line_number_section_complaint ();
17782 lh
= XNEW (struct line_header
);
17783 memset (lh
, 0, sizeof (*lh
));
17784 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
17787 lh
->offset
.sect_off
= offset
;
17788 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
17790 line_ptr
= section
->buffer
+ offset
;
17792 /* Read in the header. */
17794 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
17795 &bytes_read
, &offset_size
);
17796 line_ptr
+= bytes_read
;
17797 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
17799 dwarf2_statement_list_fits_in_line_number_section_complaint ();
17800 do_cleanups (back_to
);
17803 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
17804 lh
->version
= read_2_bytes (abfd
, line_ptr
);
17806 if (lh
->version
> 5)
17808 /* This is a version we don't understand. The format could have
17809 changed in ways we don't handle properly so just punt. */
17810 complaint (&symfile_complaints
,
17811 _("unsupported version in .debug_line section"));
17814 if (lh
->version
>= 5)
17816 gdb_byte segment_selector_size
;
17818 /* Skip address size. */
17819 read_1_byte (abfd
, line_ptr
);
17822 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
17824 if (segment_selector_size
!= 0)
17826 complaint (&symfile_complaints
,
17827 _("unsupported segment selector size %u "
17828 "in .debug_line section"),
17829 segment_selector_size
);
17833 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
17834 line_ptr
+= offset_size
;
17835 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
17837 if (lh
->version
>= 4)
17839 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
17843 lh
->maximum_ops_per_instruction
= 1;
17845 if (lh
->maximum_ops_per_instruction
== 0)
17847 lh
->maximum_ops_per_instruction
= 1;
17848 complaint (&symfile_complaints
,
17849 _("invalid maximum_ops_per_instruction "
17850 "in `.debug_line' section"));
17853 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
17855 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
17857 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
17859 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
17861 lh
->standard_opcode_lengths
= XNEWVEC (unsigned char, lh
->opcode_base
);
17863 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
17864 for (i
= 1; i
< lh
->opcode_base
; ++i
)
17866 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
17870 if (lh
->version
>= 5)
17872 /* Read directory table. */
17873 read_formatted_entries (abfd
, &line_ptr
, lh
, &cu
->header
,
17874 add_include_dir_stub
);
17876 /* Read file name table. */
17877 read_formatted_entries (abfd
, &line_ptr
, lh
, &cu
->header
, add_file_name
);
17881 /* Read directory table. */
17882 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
17884 line_ptr
+= bytes_read
;
17885 add_include_dir (lh
, cur_dir
);
17887 line_ptr
+= bytes_read
;
17889 /* Read file name table. */
17890 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
17892 unsigned int dir_index
, mod_time
, length
;
17894 line_ptr
+= bytes_read
;
17895 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17896 line_ptr
+= bytes_read
;
17897 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17898 line_ptr
+= bytes_read
;
17899 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17900 line_ptr
+= bytes_read
;
17902 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
17904 line_ptr
+= bytes_read
;
17906 lh
->statement_program_start
= line_ptr
;
17908 if (line_ptr
> (section
->buffer
+ section
->size
))
17909 complaint (&symfile_complaints
,
17910 _("line number info header doesn't "
17911 "fit in `.debug_line' section"));
17913 discard_cleanups (back_to
);
17917 /* Subroutine of dwarf_decode_lines to simplify it.
17918 Return the file name of the psymtab for included file FILE_INDEX
17919 in line header LH of PST.
17920 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
17921 If space for the result is malloc'd, it will be freed by a cleanup.
17922 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
17924 The function creates dangling cleanup registration. */
17926 static const char *
17927 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
17928 const struct partial_symtab
*pst
,
17929 const char *comp_dir
)
17931 const struct file_entry fe
= lh
->file_names
[file_index
];
17932 const char *include_name
= fe
.name
;
17933 const char *include_name_to_compare
= include_name
;
17934 const char *dir_name
= NULL
;
17935 const char *pst_filename
;
17936 char *copied_name
= NULL
;
17939 if (fe
.dir_index
&& lh
->include_dirs
!= NULL
)
17940 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
17942 if (!IS_ABSOLUTE_PATH (include_name
)
17943 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
17945 /* Avoid creating a duplicate psymtab for PST.
17946 We do this by comparing INCLUDE_NAME and PST_FILENAME.
17947 Before we do the comparison, however, we need to account
17948 for DIR_NAME and COMP_DIR.
17949 First prepend dir_name (if non-NULL). If we still don't
17950 have an absolute path prepend comp_dir (if non-NULL).
17951 However, the directory we record in the include-file's
17952 psymtab does not contain COMP_DIR (to match the
17953 corresponding symtab(s)).
17958 bash$ gcc -g ./hello.c
17959 include_name = "hello.c"
17961 DW_AT_comp_dir = comp_dir = "/tmp"
17962 DW_AT_name = "./hello.c"
17966 if (dir_name
!= NULL
)
17968 char *tem
= concat (dir_name
, SLASH_STRING
,
17969 include_name
, (char *)NULL
);
17971 make_cleanup (xfree
, tem
);
17972 include_name
= tem
;
17973 include_name_to_compare
= include_name
;
17975 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
17977 char *tem
= concat (comp_dir
, SLASH_STRING
,
17978 include_name
, (char *)NULL
);
17980 make_cleanup (xfree
, tem
);
17981 include_name_to_compare
= tem
;
17985 pst_filename
= pst
->filename
;
17986 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
17988 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
17989 pst_filename
, (char *)NULL
);
17990 pst_filename
= copied_name
;
17993 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
17995 if (copied_name
!= NULL
)
17996 xfree (copied_name
);
18000 return include_name
;
18003 /* State machine to track the state of the line number program. */
18007 /* These are part of the standard DWARF line number state machine. */
18009 unsigned char op_index
;
18014 unsigned int discriminator
;
18016 /* Additional bits of state we need to track. */
18018 /* The last file that we called dwarf2_start_subfile for.
18019 This is only used for TLLs. */
18020 unsigned int last_file
;
18021 /* The last file a line number was recorded for. */
18022 struct subfile
*last_subfile
;
18024 /* The function to call to record a line. */
18025 record_line_ftype
*record_line
;
18027 /* The last line number that was recorded, used to coalesce
18028 consecutive entries for the same line. This can happen, for
18029 example, when discriminators are present. PR 17276. */
18030 unsigned int last_line
;
18031 int line_has_non_zero_discriminator
;
18032 } lnp_state_machine
;
18034 /* There's a lot of static state to pass to dwarf_record_line.
18035 This keeps it all together. */
18040 struct gdbarch
*gdbarch
;
18042 /* The line number header. */
18043 struct line_header
*line_header
;
18045 /* Non-zero if we're recording lines.
18046 Otherwise we're building partial symtabs and are just interested in
18047 finding include files mentioned by the line number program. */
18048 int record_lines_p
;
18049 } lnp_reader_state
;
18051 /* Ignore this record_line request. */
18054 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
18059 /* Return non-zero if we should add LINE to the line number table.
18060 LINE is the line to add, LAST_LINE is the last line that was added,
18061 LAST_SUBFILE is the subfile for LAST_LINE.
18062 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
18063 had a non-zero discriminator.
18065 We have to be careful in the presence of discriminators.
18066 E.g., for this line:
18068 for (i = 0; i < 100000; i++);
18070 clang can emit four line number entries for that one line,
18071 each with a different discriminator.
18072 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
18074 However, we want gdb to coalesce all four entries into one.
18075 Otherwise the user could stepi into the middle of the line and
18076 gdb would get confused about whether the pc really was in the
18077 middle of the line.
18079 Things are further complicated by the fact that two consecutive
18080 line number entries for the same line is a heuristic used by gcc
18081 to denote the end of the prologue. So we can't just discard duplicate
18082 entries, we have to be selective about it. The heuristic we use is
18083 that we only collapse consecutive entries for the same line if at least
18084 one of those entries has a non-zero discriminator. PR 17276.
18086 Note: Addresses in the line number state machine can never go backwards
18087 within one sequence, thus this coalescing is ok. */
18090 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
18091 int line_has_non_zero_discriminator
,
18092 struct subfile
*last_subfile
)
18094 if (current_subfile
!= last_subfile
)
18096 if (line
!= last_line
)
18098 /* Same line for the same file that we've seen already.
18099 As a last check, for pr 17276, only record the line if the line
18100 has never had a non-zero discriminator. */
18101 if (!line_has_non_zero_discriminator
)
18106 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
18107 in the line table of subfile SUBFILE. */
18110 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
18111 unsigned int line
, CORE_ADDR address
,
18112 record_line_ftype p_record_line
)
18114 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
18116 if (dwarf_line_debug
)
18118 fprintf_unfiltered (gdb_stdlog
,
18119 "Recording line %u, file %s, address %s\n",
18120 line
, lbasename (subfile
->name
),
18121 paddress (gdbarch
, address
));
18124 (*p_record_line
) (subfile
, line
, addr
);
18127 /* Subroutine of dwarf_decode_lines_1 to simplify it.
18128 Mark the end of a set of line number records.
18129 The arguments are the same as for dwarf_record_line_1.
18130 If SUBFILE is NULL the request is ignored. */
18133 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
18134 CORE_ADDR address
, record_line_ftype p_record_line
)
18136 if (subfile
== NULL
)
18139 if (dwarf_line_debug
)
18141 fprintf_unfiltered (gdb_stdlog
,
18142 "Finishing current line, file %s, address %s\n",
18143 lbasename (subfile
->name
),
18144 paddress (gdbarch
, address
));
18147 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
18150 /* Record the line in STATE.
18151 END_SEQUENCE is non-zero if we're processing the end of a sequence. */
18154 dwarf_record_line (lnp_reader_state
*reader
, lnp_state_machine
*state
,
18157 const struct line_header
*lh
= reader
->line_header
;
18158 unsigned int file
, line
, discriminator
;
18161 file
= state
->file
;
18162 line
= state
->line
;
18163 is_stmt
= state
->is_stmt
;
18164 discriminator
= state
->discriminator
;
18166 if (dwarf_line_debug
)
18168 fprintf_unfiltered (gdb_stdlog
,
18169 "Processing actual line %u: file %u,"
18170 " address %s, is_stmt %u, discrim %u\n",
18172 paddress (reader
->gdbarch
, state
->address
),
18173 is_stmt
, discriminator
);
18176 if (file
== 0 || file
- 1 >= lh
->num_file_names
)
18177 dwarf2_debug_line_missing_file_complaint ();
18178 /* For now we ignore lines not starting on an instruction boundary.
18179 But not when processing end_sequence for compatibility with the
18180 previous version of the code. */
18181 else if (state
->op_index
== 0 || end_sequence
)
18183 lh
->file_names
[file
- 1].included_p
= 1;
18184 if (reader
->record_lines_p
&& is_stmt
)
18186 if (state
->last_subfile
!= current_subfile
|| end_sequence
)
18188 dwarf_finish_line (reader
->gdbarch
, state
->last_subfile
,
18189 state
->address
, state
->record_line
);
18194 if (dwarf_record_line_p (line
, state
->last_line
,
18195 state
->line_has_non_zero_discriminator
,
18196 state
->last_subfile
))
18198 dwarf_record_line_1 (reader
->gdbarch
, current_subfile
,
18199 line
, state
->address
,
18200 state
->record_line
);
18202 state
->last_subfile
= current_subfile
;
18203 state
->last_line
= line
;
18209 /* Initialize STATE for the start of a line number program. */
18212 init_lnp_state_machine (lnp_state_machine
*state
,
18213 const lnp_reader_state
*reader
)
18215 memset (state
, 0, sizeof (*state
));
18217 /* Just starting, there is no "last file". */
18218 state
->last_file
= 0;
18219 state
->last_subfile
= NULL
;
18221 state
->record_line
= record_line
;
18223 state
->last_line
= 0;
18224 state
->line_has_non_zero_discriminator
= 0;
18226 /* Initialize these according to the DWARF spec. */
18227 state
->op_index
= 0;
18230 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
18231 was a line entry for it so that the backend has a chance to adjust it
18232 and also record it in case it needs it. This is currently used by MIPS
18233 code, cf. `mips_adjust_dwarf2_line'. */
18234 state
->address
= gdbarch_adjust_dwarf2_line (reader
->gdbarch
, 0, 0);
18235 state
->is_stmt
= reader
->line_header
->default_is_stmt
;
18236 state
->discriminator
= 0;
18239 /* Check address and if invalid nop-out the rest of the lines in this
18243 check_line_address (struct dwarf2_cu
*cu
, lnp_state_machine
*state
,
18244 const gdb_byte
*line_ptr
,
18245 CORE_ADDR lowpc
, CORE_ADDR address
)
18247 /* If address < lowpc then it's not a usable value, it's outside the
18248 pc range of the CU. However, we restrict the test to only address
18249 values of zero to preserve GDB's previous behaviour which is to
18250 handle the specific case of a function being GC'd by the linker. */
18252 if (address
== 0 && address
< lowpc
)
18254 /* This line table is for a function which has been
18255 GCd by the linker. Ignore it. PR gdb/12528 */
18257 struct objfile
*objfile
= cu
->objfile
;
18258 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
18260 complaint (&symfile_complaints
,
18261 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
18262 line_offset
, objfile_name (objfile
));
18263 state
->record_line
= noop_record_line
;
18264 /* Note: sm.record_line is left as noop_record_line
18265 until we see DW_LNE_end_sequence. */
18269 /* Subroutine of dwarf_decode_lines to simplify it.
18270 Process the line number information in LH.
18271 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
18272 program in order to set included_p for every referenced header. */
18275 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
18276 const int decode_for_pst_p
, CORE_ADDR lowpc
)
18278 const gdb_byte
*line_ptr
, *extended_end
;
18279 const gdb_byte
*line_end
;
18280 unsigned int bytes_read
, extended_len
;
18281 unsigned char op_code
, extended_op
;
18282 CORE_ADDR baseaddr
;
18283 struct objfile
*objfile
= cu
->objfile
;
18284 bfd
*abfd
= objfile
->obfd
;
18285 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18286 /* Non-zero if we're recording line info (as opposed to building partial
18288 int record_lines_p
= !decode_for_pst_p
;
18289 /* A collection of things we need to pass to dwarf_record_line. */
18290 lnp_reader_state reader_state
;
18292 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18294 line_ptr
= lh
->statement_program_start
;
18295 line_end
= lh
->statement_program_end
;
18297 reader_state
.gdbarch
= gdbarch
;
18298 reader_state
.line_header
= lh
;
18299 reader_state
.record_lines_p
= record_lines_p
;
18301 /* Read the statement sequences until there's nothing left. */
18302 while (line_ptr
< line_end
)
18304 /* The DWARF line number program state machine. */
18305 lnp_state_machine state_machine
;
18306 int end_sequence
= 0;
18308 /* Reset the state machine at the start of each sequence. */
18309 init_lnp_state_machine (&state_machine
, &reader_state
);
18311 if (record_lines_p
&& lh
->num_file_names
>= state_machine
.file
)
18313 /* Start a subfile for the current file of the state machine. */
18314 /* lh->include_dirs and lh->file_names are 0-based, but the
18315 directory and file name numbers in the statement program
18317 struct file_entry
*fe
= &lh
->file_names
[state_machine
.file
- 1];
18318 const char *dir
= NULL
;
18320 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
18321 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
18323 dwarf2_start_subfile (fe
->name
, dir
);
18326 /* Decode the table. */
18327 while (line_ptr
< line_end
&& !end_sequence
)
18329 op_code
= read_1_byte (abfd
, line_ptr
);
18332 if (op_code
>= lh
->opcode_base
)
18334 /* Special opcode. */
18335 unsigned char adj_opcode
;
18336 CORE_ADDR addr_adj
;
18339 adj_opcode
= op_code
- lh
->opcode_base
;
18340 addr_adj
= (((state_machine
.op_index
18341 + (adj_opcode
/ lh
->line_range
))
18342 / lh
->maximum_ops_per_instruction
)
18343 * lh
->minimum_instruction_length
);
18344 state_machine
.address
18345 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
18346 state_machine
.op_index
= ((state_machine
.op_index
18347 + (adj_opcode
/ lh
->line_range
))
18348 % lh
->maximum_ops_per_instruction
);
18349 line_delta
= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
18350 state_machine
.line
+= line_delta
;
18351 if (line_delta
!= 0)
18352 state_machine
.line_has_non_zero_discriminator
18353 = state_machine
.discriminator
!= 0;
18355 dwarf_record_line (&reader_state
, &state_machine
, 0);
18356 state_machine
.discriminator
= 0;
18358 else switch (op_code
)
18360 case DW_LNS_extended_op
:
18361 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
18363 line_ptr
+= bytes_read
;
18364 extended_end
= line_ptr
+ extended_len
;
18365 extended_op
= read_1_byte (abfd
, line_ptr
);
18367 switch (extended_op
)
18369 case DW_LNE_end_sequence
:
18370 state_machine
.record_line
= record_line
;
18373 case DW_LNE_set_address
:
18376 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
18378 line_ptr
+= bytes_read
;
18379 check_line_address (cu
, &state_machine
, line_ptr
,
18381 state_machine
.op_index
= 0;
18382 address
+= baseaddr
;
18383 state_machine
.address
18384 = gdbarch_adjust_dwarf2_line (gdbarch
, address
, 0);
18387 case DW_LNE_define_file
:
18389 const char *cur_file
;
18390 unsigned int dir_index
, mod_time
, length
;
18392 cur_file
= read_direct_string (abfd
, line_ptr
,
18394 line_ptr
+= bytes_read
;
18396 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18397 line_ptr
+= bytes_read
;
18399 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18400 line_ptr
+= bytes_read
;
18402 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18403 line_ptr
+= bytes_read
;
18404 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
18407 case DW_LNE_set_discriminator
:
18408 /* The discriminator is not interesting to the debugger;
18409 just ignore it. We still need to check its value though:
18410 if there are consecutive entries for the same
18411 (non-prologue) line we want to coalesce them.
18413 state_machine
.discriminator
18414 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18415 state_machine
.line_has_non_zero_discriminator
18416 |= state_machine
.discriminator
!= 0;
18417 line_ptr
+= bytes_read
;
18420 complaint (&symfile_complaints
,
18421 _("mangled .debug_line section"));
18424 /* Make sure that we parsed the extended op correctly. If e.g.
18425 we expected a different address size than the producer used,
18426 we may have read the wrong number of bytes. */
18427 if (line_ptr
!= extended_end
)
18429 complaint (&symfile_complaints
,
18430 _("mangled .debug_line section"));
18435 dwarf_record_line (&reader_state
, &state_machine
, 0);
18436 state_machine
.discriminator
= 0;
18438 case DW_LNS_advance_pc
:
18441 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18442 CORE_ADDR addr_adj
;
18444 addr_adj
= (((state_machine
.op_index
+ adjust
)
18445 / lh
->maximum_ops_per_instruction
)
18446 * lh
->minimum_instruction_length
);
18447 state_machine
.address
18448 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
18449 state_machine
.op_index
= ((state_machine
.op_index
+ adjust
)
18450 % lh
->maximum_ops_per_instruction
);
18451 line_ptr
+= bytes_read
;
18454 case DW_LNS_advance_line
:
18457 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
18459 state_machine
.line
+= line_delta
;
18460 if (line_delta
!= 0)
18461 state_machine
.line_has_non_zero_discriminator
18462 = state_machine
.discriminator
!= 0;
18463 line_ptr
+= bytes_read
;
18466 case DW_LNS_set_file
:
18468 /* The arrays lh->include_dirs and lh->file_names are
18469 0-based, but the directory and file name numbers in
18470 the statement program are 1-based. */
18471 struct file_entry
*fe
;
18472 const char *dir
= NULL
;
18474 state_machine
.file
= read_unsigned_leb128 (abfd
, line_ptr
,
18476 line_ptr
+= bytes_read
;
18477 if (state_machine
.file
== 0
18478 || state_machine
.file
- 1 >= lh
->num_file_names
)
18479 dwarf2_debug_line_missing_file_complaint ();
18482 fe
= &lh
->file_names
[state_machine
.file
- 1];
18483 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
18484 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
18485 if (record_lines_p
)
18487 state_machine
.last_subfile
= current_subfile
;
18488 state_machine
.line_has_non_zero_discriminator
18489 = state_machine
.discriminator
!= 0;
18490 dwarf2_start_subfile (fe
->name
, dir
);
18495 case DW_LNS_set_column
:
18496 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18497 line_ptr
+= bytes_read
;
18499 case DW_LNS_negate_stmt
:
18500 state_machine
.is_stmt
= (!state_machine
.is_stmt
);
18502 case DW_LNS_set_basic_block
:
18504 /* Add to the address register of the state machine the
18505 address increment value corresponding to special opcode
18506 255. I.e., this value is scaled by the minimum
18507 instruction length since special opcode 255 would have
18508 scaled the increment. */
18509 case DW_LNS_const_add_pc
:
18511 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
18512 CORE_ADDR addr_adj
;
18514 addr_adj
= (((state_machine
.op_index
+ adjust
)
18515 / lh
->maximum_ops_per_instruction
)
18516 * lh
->minimum_instruction_length
);
18517 state_machine
.address
18518 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
18519 state_machine
.op_index
= ((state_machine
.op_index
+ adjust
)
18520 % lh
->maximum_ops_per_instruction
);
18523 case DW_LNS_fixed_advance_pc
:
18525 CORE_ADDR addr_adj
;
18527 addr_adj
= read_2_bytes (abfd
, line_ptr
);
18528 state_machine
.address
18529 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
18530 state_machine
.op_index
= 0;
18536 /* Unknown standard opcode, ignore it. */
18539 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
18541 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18542 line_ptr
+= bytes_read
;
18549 dwarf2_debug_line_missing_end_sequence_complaint ();
18551 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
18552 in which case we still finish recording the last line). */
18553 dwarf_record_line (&reader_state
, &state_machine
, 1);
18557 /* Decode the Line Number Program (LNP) for the given line_header
18558 structure and CU. The actual information extracted and the type
18559 of structures created from the LNP depends on the value of PST.
18561 1. If PST is NULL, then this procedure uses the data from the program
18562 to create all necessary symbol tables, and their linetables.
18564 2. If PST is not NULL, this procedure reads the program to determine
18565 the list of files included by the unit represented by PST, and
18566 builds all the associated partial symbol tables.
18568 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
18569 It is used for relative paths in the line table.
18570 NOTE: When processing partial symtabs (pst != NULL),
18571 comp_dir == pst->dirname.
18573 NOTE: It is important that psymtabs have the same file name (via strcmp)
18574 as the corresponding symtab. Since COMP_DIR is not used in the name of the
18575 symtab we don't use it in the name of the psymtabs we create.
18576 E.g. expand_line_sal requires this when finding psymtabs to expand.
18577 A good testcase for this is mb-inline.exp.
18579 LOWPC is the lowest address in CU (or 0 if not known).
18581 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
18582 for its PC<->lines mapping information. Otherwise only the filename
18583 table is read in. */
18586 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
18587 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
18588 CORE_ADDR lowpc
, int decode_mapping
)
18590 struct objfile
*objfile
= cu
->objfile
;
18591 const int decode_for_pst_p
= (pst
!= NULL
);
18593 if (decode_mapping
)
18594 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
18596 if (decode_for_pst_p
)
18600 /* Now that we're done scanning the Line Header Program, we can
18601 create the psymtab of each included file. */
18602 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
18603 if (lh
->file_names
[file_index
].included_p
== 1)
18605 const char *include_name
=
18606 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
18607 if (include_name
!= NULL
)
18608 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
18613 /* Make sure a symtab is created for every file, even files
18614 which contain only variables (i.e. no code with associated
18616 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
18619 for (i
= 0; i
< lh
->num_file_names
; i
++)
18621 const char *dir
= NULL
;
18622 struct file_entry
*fe
;
18624 fe
= &lh
->file_names
[i
];
18625 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
18626 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
18627 dwarf2_start_subfile (fe
->name
, dir
);
18629 if (current_subfile
->symtab
== NULL
)
18631 current_subfile
->symtab
18632 = allocate_symtab (cust
, current_subfile
->name
);
18634 fe
->symtab
= current_subfile
->symtab
;
18639 /* Start a subfile for DWARF. FILENAME is the name of the file and
18640 DIRNAME the name of the source directory which contains FILENAME
18641 or NULL if not known.
18642 This routine tries to keep line numbers from identical absolute and
18643 relative file names in a common subfile.
18645 Using the `list' example from the GDB testsuite, which resides in
18646 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
18647 of /srcdir/list0.c yields the following debugging information for list0.c:
18649 DW_AT_name: /srcdir/list0.c
18650 DW_AT_comp_dir: /compdir
18651 files.files[0].name: list0.h
18652 files.files[0].dir: /srcdir
18653 files.files[1].name: list0.c
18654 files.files[1].dir: /srcdir
18656 The line number information for list0.c has to end up in a single
18657 subfile, so that `break /srcdir/list0.c:1' works as expected.
18658 start_subfile will ensure that this happens provided that we pass the
18659 concatenation of files.files[1].dir and files.files[1].name as the
18663 dwarf2_start_subfile (const char *filename
, const char *dirname
)
18667 /* In order not to lose the line information directory,
18668 we concatenate it to the filename when it makes sense.
18669 Note that the Dwarf3 standard says (speaking of filenames in line
18670 information): ``The directory index is ignored for file names
18671 that represent full path names''. Thus ignoring dirname in the
18672 `else' branch below isn't an issue. */
18674 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
18676 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
18680 start_subfile (filename
);
18686 /* Start a symtab for DWARF.
18687 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
18689 static struct compunit_symtab
*
18690 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
18691 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
18693 struct compunit_symtab
*cust
18694 = start_symtab (cu
->objfile
, name
, comp_dir
, low_pc
);
18696 record_debugformat ("DWARF 2");
18697 record_producer (cu
->producer
);
18699 /* We assume that we're processing GCC output. */
18700 processing_gcc_compilation
= 2;
18702 cu
->processing_has_namespace_info
= 0;
18708 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
18709 struct dwarf2_cu
*cu
)
18711 struct objfile
*objfile
= cu
->objfile
;
18712 struct comp_unit_head
*cu_header
= &cu
->header
;
18714 /* NOTE drow/2003-01-30: There used to be a comment and some special
18715 code here to turn a symbol with DW_AT_external and a
18716 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
18717 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
18718 with some versions of binutils) where shared libraries could have
18719 relocations against symbols in their debug information - the
18720 minimal symbol would have the right address, but the debug info
18721 would not. It's no longer necessary, because we will explicitly
18722 apply relocations when we read in the debug information now. */
18724 /* A DW_AT_location attribute with no contents indicates that a
18725 variable has been optimized away. */
18726 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
18728 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
18732 /* Handle one degenerate form of location expression specially, to
18733 preserve GDB's previous behavior when section offsets are
18734 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
18735 then mark this symbol as LOC_STATIC. */
18737 if (attr_form_is_block (attr
)
18738 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
18739 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
18740 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
18741 && (DW_BLOCK (attr
)->size
18742 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
18744 unsigned int dummy
;
18746 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
18747 SYMBOL_VALUE_ADDRESS (sym
) =
18748 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
18750 SYMBOL_VALUE_ADDRESS (sym
) =
18751 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
18752 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
18753 fixup_symbol_section (sym
, objfile
);
18754 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
18755 SYMBOL_SECTION (sym
));
18759 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
18760 expression evaluator, and use LOC_COMPUTED only when necessary
18761 (i.e. when the value of a register or memory location is
18762 referenced, or a thread-local block, etc.). Then again, it might
18763 not be worthwhile. I'm assuming that it isn't unless performance
18764 or memory numbers show me otherwise. */
18766 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
18768 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
18769 cu
->has_loclist
= 1;
18772 /* Given a pointer to a DWARF information entry, figure out if we need
18773 to make a symbol table entry for it, and if so, create a new entry
18774 and return a pointer to it.
18775 If TYPE is NULL, determine symbol type from the die, otherwise
18776 used the passed type.
18777 If SPACE is not NULL, use it to hold the new symbol. If it is
18778 NULL, allocate a new symbol on the objfile's obstack. */
18780 static struct symbol
*
18781 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
18782 struct symbol
*space
)
18784 struct objfile
*objfile
= cu
->objfile
;
18785 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18786 struct symbol
*sym
= NULL
;
18788 struct attribute
*attr
= NULL
;
18789 struct attribute
*attr2
= NULL
;
18790 CORE_ADDR baseaddr
;
18791 struct pending
**list_to_add
= NULL
;
18793 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
18795 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18797 name
= dwarf2_name (die
, cu
);
18800 const char *linkagename
;
18801 int suppress_add
= 0;
18806 sym
= allocate_symbol (objfile
);
18807 OBJSTAT (objfile
, n_syms
++);
18809 /* Cache this symbol's name and the name's demangled form (if any). */
18810 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
18811 linkagename
= dwarf2_physname (name
, die
, cu
);
18812 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
18814 /* Fortran does not have mangling standard and the mangling does differ
18815 between gfortran, iFort etc. */
18816 if (cu
->language
== language_fortran
18817 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
18818 symbol_set_demangled_name (&(sym
->ginfo
),
18819 dwarf2_full_name (name
, die
, cu
),
18822 /* Default assumptions.
18823 Use the passed type or decode it from the die. */
18824 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
18825 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
18827 SYMBOL_TYPE (sym
) = type
;
18829 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
18830 attr
= dwarf2_attr (die
,
18831 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
18835 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
18838 attr
= dwarf2_attr (die
,
18839 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
18843 int file_index
= DW_UNSND (attr
);
18845 if (cu
->line_header
== NULL
18846 || file_index
> cu
->line_header
->num_file_names
)
18847 complaint (&symfile_complaints
,
18848 _("file index out of range"));
18849 else if (file_index
> 0)
18851 struct file_entry
*fe
;
18853 fe
= &cu
->line_header
->file_names
[file_index
- 1];
18854 symbol_set_symtab (sym
, fe
->symtab
);
18861 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
18866 addr
= attr_value_as_address (attr
);
18867 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
18868 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
18870 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
18871 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
18872 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
18873 add_symbol_to_list (sym
, cu
->list_in_scope
);
18875 case DW_TAG_subprogram
:
18876 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
18878 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
18879 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18880 if ((attr2
&& (DW_UNSND (attr2
) != 0))
18881 || cu
->language
== language_ada
)
18883 /* Subprograms marked external are stored as a global symbol.
18884 Ada subprograms, whether marked external or not, are always
18885 stored as a global symbol, because we want to be able to
18886 access them globally. For instance, we want to be able
18887 to break on a nested subprogram without having to
18888 specify the context. */
18889 list_to_add
= &global_symbols
;
18893 list_to_add
= cu
->list_in_scope
;
18896 case DW_TAG_inlined_subroutine
:
18897 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
18899 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
18900 SYMBOL_INLINED (sym
) = 1;
18901 list_to_add
= cu
->list_in_scope
;
18903 case DW_TAG_template_value_param
:
18905 /* Fall through. */
18906 case DW_TAG_constant
:
18907 case DW_TAG_variable
:
18908 case DW_TAG_member
:
18909 /* Compilation with minimal debug info may result in
18910 variables with missing type entries. Change the
18911 misleading `void' type to something sensible. */
18912 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
18914 = objfile_type (objfile
)->nodebug_data_symbol
;
18916 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
18917 /* In the case of DW_TAG_member, we should only be called for
18918 static const members. */
18919 if (die
->tag
== DW_TAG_member
)
18921 /* dwarf2_add_field uses die_is_declaration,
18922 so we do the same. */
18923 gdb_assert (die_is_declaration (die
, cu
));
18928 dwarf2_const_value (attr
, sym
, cu
);
18929 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18932 if (attr2
&& (DW_UNSND (attr2
) != 0))
18933 list_to_add
= &global_symbols
;
18935 list_to_add
= cu
->list_in_scope
;
18939 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
18942 var_decode_location (attr
, sym
, cu
);
18943 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18945 /* Fortran explicitly imports any global symbols to the local
18946 scope by DW_TAG_common_block. */
18947 if (cu
->language
== language_fortran
&& die
->parent
18948 && die
->parent
->tag
== DW_TAG_common_block
)
18951 if (SYMBOL_CLASS (sym
) == LOC_STATIC
18952 && SYMBOL_VALUE_ADDRESS (sym
) == 0
18953 && !dwarf2_per_objfile
->has_section_at_zero
)
18955 /* When a static variable is eliminated by the linker,
18956 the corresponding debug information is not stripped
18957 out, but the variable address is set to null;
18958 do not add such variables into symbol table. */
18960 else if (attr2
&& (DW_UNSND (attr2
) != 0))
18962 /* Workaround gfortran PR debug/40040 - it uses
18963 DW_AT_location for variables in -fPIC libraries which may
18964 get overriden by other libraries/executable and get
18965 a different address. Resolve it by the minimal symbol
18966 which may come from inferior's executable using copy
18967 relocation. Make this workaround only for gfortran as for
18968 other compilers GDB cannot guess the minimal symbol
18969 Fortran mangling kind. */
18970 if (cu
->language
== language_fortran
&& die
->parent
18971 && die
->parent
->tag
== DW_TAG_module
18973 && startswith (cu
->producer
, "GNU Fortran"))
18974 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
18976 /* A variable with DW_AT_external is never static,
18977 but it may be block-scoped. */
18978 list_to_add
= (cu
->list_in_scope
== &file_symbols
18979 ? &global_symbols
: cu
->list_in_scope
);
18982 list_to_add
= cu
->list_in_scope
;
18986 /* We do not know the address of this symbol.
18987 If it is an external symbol and we have type information
18988 for it, enter the symbol as a LOC_UNRESOLVED symbol.
18989 The address of the variable will then be determined from
18990 the minimal symbol table whenever the variable is
18992 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18994 /* Fortran explicitly imports any global symbols to the local
18995 scope by DW_TAG_common_block. */
18996 if (cu
->language
== language_fortran
&& die
->parent
18997 && die
->parent
->tag
== DW_TAG_common_block
)
18999 /* SYMBOL_CLASS doesn't matter here because
19000 read_common_block is going to reset it. */
19002 list_to_add
= cu
->list_in_scope
;
19004 else if (attr2
&& (DW_UNSND (attr2
) != 0)
19005 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
19007 /* A variable with DW_AT_external is never static, but it
19008 may be block-scoped. */
19009 list_to_add
= (cu
->list_in_scope
== &file_symbols
19010 ? &global_symbols
: cu
->list_in_scope
);
19012 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
19014 else if (!die_is_declaration (die
, cu
))
19016 /* Use the default LOC_OPTIMIZED_OUT class. */
19017 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
19019 list_to_add
= cu
->list_in_scope
;
19023 case DW_TAG_formal_parameter
:
19024 /* If we are inside a function, mark this as an argument. If
19025 not, we might be looking at an argument to an inlined function
19026 when we do not have enough information to show inlined frames;
19027 pretend it's a local variable in that case so that the user can
19029 if (context_stack_depth
> 0
19030 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
19031 SYMBOL_IS_ARGUMENT (sym
) = 1;
19032 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
19035 var_decode_location (attr
, sym
, cu
);
19037 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19040 dwarf2_const_value (attr
, sym
, cu
);
19043 list_to_add
= cu
->list_in_scope
;
19045 case DW_TAG_unspecified_parameters
:
19046 /* From varargs functions; gdb doesn't seem to have any
19047 interest in this information, so just ignore it for now.
19050 case DW_TAG_template_type_param
:
19052 /* Fall through. */
19053 case DW_TAG_class_type
:
19054 case DW_TAG_interface_type
:
19055 case DW_TAG_structure_type
:
19056 case DW_TAG_union_type
:
19057 case DW_TAG_set_type
:
19058 case DW_TAG_enumeration_type
:
19059 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19060 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
19063 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
19064 really ever be static objects: otherwise, if you try
19065 to, say, break of a class's method and you're in a file
19066 which doesn't mention that class, it won't work unless
19067 the check for all static symbols in lookup_symbol_aux
19068 saves you. See the OtherFileClass tests in
19069 gdb.c++/namespace.exp. */
19073 list_to_add
= (cu
->list_in_scope
== &file_symbols
19074 && cu
->language
== language_cplus
19075 ? &global_symbols
: cu
->list_in_scope
);
19077 /* The semantics of C++ state that "struct foo {
19078 ... }" also defines a typedef for "foo". */
19079 if (cu
->language
== language_cplus
19080 || cu
->language
== language_ada
19081 || cu
->language
== language_d
19082 || cu
->language
== language_rust
)
19084 /* The symbol's name is already allocated along
19085 with this objfile, so we don't need to
19086 duplicate it for the type. */
19087 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
19088 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
19093 case DW_TAG_typedef
:
19094 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19095 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19096 list_to_add
= cu
->list_in_scope
;
19098 case DW_TAG_base_type
:
19099 case DW_TAG_subrange_type
:
19100 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19101 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19102 list_to_add
= cu
->list_in_scope
;
19104 case DW_TAG_enumerator
:
19105 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19108 dwarf2_const_value (attr
, sym
, cu
);
19111 /* NOTE: carlton/2003-11-10: See comment above in the
19112 DW_TAG_class_type, etc. block. */
19114 list_to_add
= (cu
->list_in_scope
== &file_symbols
19115 && cu
->language
== language_cplus
19116 ? &global_symbols
: cu
->list_in_scope
);
19119 case DW_TAG_imported_declaration
:
19120 case DW_TAG_namespace
:
19121 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19122 list_to_add
= &global_symbols
;
19124 case DW_TAG_module
:
19125 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19126 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
19127 list_to_add
= &global_symbols
;
19129 case DW_TAG_common_block
:
19130 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
19131 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
19132 add_symbol_to_list (sym
, cu
->list_in_scope
);
19135 /* Not a tag we recognize. Hopefully we aren't processing
19136 trash data, but since we must specifically ignore things
19137 we don't recognize, there is nothing else we should do at
19139 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
19140 dwarf_tag_name (die
->tag
));
19146 sym
->hash_next
= objfile
->template_symbols
;
19147 objfile
->template_symbols
= sym
;
19148 list_to_add
= NULL
;
19151 if (list_to_add
!= NULL
)
19152 add_symbol_to_list (sym
, list_to_add
);
19154 /* For the benefit of old versions of GCC, check for anonymous
19155 namespaces based on the demangled name. */
19156 if (!cu
->processing_has_namespace_info
19157 && cu
->language
== language_cplus
)
19158 cp_scan_for_anonymous_namespaces (sym
, objfile
);
19163 /* A wrapper for new_symbol_full that always allocates a new symbol. */
19165 static struct symbol
*
19166 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
19168 return new_symbol_full (die
, type
, cu
, NULL
);
19171 /* Given an attr with a DW_FORM_dataN value in host byte order,
19172 zero-extend it as appropriate for the symbol's type. The DWARF
19173 standard (v4) is not entirely clear about the meaning of using
19174 DW_FORM_dataN for a constant with a signed type, where the type is
19175 wider than the data. The conclusion of a discussion on the DWARF
19176 list was that this is unspecified. We choose to always zero-extend
19177 because that is the interpretation long in use by GCC. */
19180 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
19181 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
19183 struct objfile
*objfile
= cu
->objfile
;
19184 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
19185 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
19186 LONGEST l
= DW_UNSND (attr
);
19188 if (bits
< sizeof (*value
) * 8)
19190 l
&= ((LONGEST
) 1 << bits
) - 1;
19193 else if (bits
== sizeof (*value
) * 8)
19197 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
19198 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
19205 /* Read a constant value from an attribute. Either set *VALUE, or if
19206 the value does not fit in *VALUE, set *BYTES - either already
19207 allocated on the objfile obstack, or newly allocated on OBSTACK,
19208 or, set *BATON, if we translated the constant to a location
19212 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
19213 const char *name
, struct obstack
*obstack
,
19214 struct dwarf2_cu
*cu
,
19215 LONGEST
*value
, const gdb_byte
**bytes
,
19216 struct dwarf2_locexpr_baton
**baton
)
19218 struct objfile
*objfile
= cu
->objfile
;
19219 struct comp_unit_head
*cu_header
= &cu
->header
;
19220 struct dwarf_block
*blk
;
19221 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
19222 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
19228 switch (attr
->form
)
19231 case DW_FORM_GNU_addr_index
:
19235 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
19236 dwarf2_const_value_length_mismatch_complaint (name
,
19237 cu_header
->addr_size
,
19238 TYPE_LENGTH (type
));
19239 /* Symbols of this form are reasonably rare, so we just
19240 piggyback on the existing location code rather than writing
19241 a new implementation of symbol_computed_ops. */
19242 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
19243 (*baton
)->per_cu
= cu
->per_cu
;
19244 gdb_assert ((*baton
)->per_cu
);
19246 (*baton
)->size
= 2 + cu_header
->addr_size
;
19247 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
19248 (*baton
)->data
= data
;
19250 data
[0] = DW_OP_addr
;
19251 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
19252 byte_order
, DW_ADDR (attr
));
19253 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
19256 case DW_FORM_string
:
19258 case DW_FORM_GNU_str_index
:
19259 case DW_FORM_GNU_strp_alt
:
19260 /* DW_STRING is already allocated on the objfile obstack, point
19262 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
19264 case DW_FORM_block1
:
19265 case DW_FORM_block2
:
19266 case DW_FORM_block4
:
19267 case DW_FORM_block
:
19268 case DW_FORM_exprloc
:
19269 blk
= DW_BLOCK (attr
);
19270 if (TYPE_LENGTH (type
) != blk
->size
)
19271 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
19272 TYPE_LENGTH (type
));
19273 *bytes
= blk
->data
;
19276 /* The DW_AT_const_value attributes are supposed to carry the
19277 symbol's value "represented as it would be on the target
19278 architecture." By the time we get here, it's already been
19279 converted to host endianness, so we just need to sign- or
19280 zero-extend it as appropriate. */
19281 case DW_FORM_data1
:
19282 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
19284 case DW_FORM_data2
:
19285 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
19287 case DW_FORM_data4
:
19288 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
19290 case DW_FORM_data8
:
19291 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
19294 case DW_FORM_sdata
:
19295 *value
= DW_SND (attr
);
19298 case DW_FORM_udata
:
19299 *value
= DW_UNSND (attr
);
19303 complaint (&symfile_complaints
,
19304 _("unsupported const value attribute form: '%s'"),
19305 dwarf_form_name (attr
->form
));
19312 /* Copy constant value from an attribute to a symbol. */
19315 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
19316 struct dwarf2_cu
*cu
)
19318 struct objfile
*objfile
= cu
->objfile
;
19320 const gdb_byte
*bytes
;
19321 struct dwarf2_locexpr_baton
*baton
;
19323 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
19324 SYMBOL_PRINT_NAME (sym
),
19325 &objfile
->objfile_obstack
, cu
,
19326 &value
, &bytes
, &baton
);
19330 SYMBOL_LOCATION_BATON (sym
) = baton
;
19331 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
19333 else if (bytes
!= NULL
)
19335 SYMBOL_VALUE_BYTES (sym
) = bytes
;
19336 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
19340 SYMBOL_VALUE (sym
) = value
;
19341 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
19345 /* Return the type of the die in question using its DW_AT_type attribute. */
19347 static struct type
*
19348 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19350 struct attribute
*type_attr
;
19352 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
19355 /* A missing DW_AT_type represents a void type. */
19356 return objfile_type (cu
->objfile
)->builtin_void
;
19359 return lookup_die_type (die
, type_attr
, cu
);
19362 /* True iff CU's producer generates GNAT Ada auxiliary information
19363 that allows to find parallel types through that information instead
19364 of having to do expensive parallel lookups by type name. */
19367 need_gnat_info (struct dwarf2_cu
*cu
)
19369 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
19370 of GNAT produces this auxiliary information, without any indication
19371 that it is produced. Part of enhancing the FSF version of GNAT
19372 to produce that information will be to put in place an indicator
19373 that we can use in order to determine whether the descriptive type
19374 info is available or not. One suggestion that has been made is
19375 to use a new attribute, attached to the CU die. For now, assume
19376 that the descriptive type info is not available. */
19380 /* Return the auxiliary type of the die in question using its
19381 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
19382 attribute is not present. */
19384 static struct type
*
19385 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19387 struct attribute
*type_attr
;
19389 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
19393 return lookup_die_type (die
, type_attr
, cu
);
19396 /* If DIE has a descriptive_type attribute, then set the TYPE's
19397 descriptive type accordingly. */
19400 set_descriptive_type (struct type
*type
, struct die_info
*die
,
19401 struct dwarf2_cu
*cu
)
19403 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
19405 if (descriptive_type
)
19407 ALLOCATE_GNAT_AUX_TYPE (type
);
19408 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
19412 /* Return the containing type of the die in question using its
19413 DW_AT_containing_type attribute. */
19415 static struct type
*
19416 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19418 struct attribute
*type_attr
;
19420 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
19422 error (_("Dwarf Error: Problem turning containing type into gdb type "
19423 "[in module %s]"), objfile_name (cu
->objfile
));
19425 return lookup_die_type (die
, type_attr
, cu
);
19428 /* Return an error marker type to use for the ill formed type in DIE/CU. */
19430 static struct type
*
19431 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
19433 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19434 char *message
, *saved
;
19436 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
19437 objfile_name (objfile
),
19438 cu
->header
.offset
.sect_off
,
19439 die
->offset
.sect_off
);
19440 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
19441 message
, strlen (message
));
19444 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
19447 /* Look up the type of DIE in CU using its type attribute ATTR.
19448 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
19449 DW_AT_containing_type.
19450 If there is no type substitute an error marker. */
19452 static struct type
*
19453 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
19454 struct dwarf2_cu
*cu
)
19456 struct objfile
*objfile
= cu
->objfile
;
19457 struct type
*this_type
;
19459 gdb_assert (attr
->name
== DW_AT_type
19460 || attr
->name
== DW_AT_GNAT_descriptive_type
19461 || attr
->name
== DW_AT_containing_type
);
19463 /* First see if we have it cached. */
19465 if (attr
->form
== DW_FORM_GNU_ref_alt
)
19467 struct dwarf2_per_cu_data
*per_cu
;
19468 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
19470 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
19471 this_type
= get_die_type_at_offset (offset
, per_cu
);
19473 else if (attr_form_is_ref (attr
))
19475 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
19477 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
19479 else if (attr
->form
== DW_FORM_ref_sig8
)
19481 ULONGEST signature
= DW_SIGNATURE (attr
);
19483 return get_signatured_type (die
, signature
, cu
);
19487 complaint (&symfile_complaints
,
19488 _("Dwarf Error: Bad type attribute %s in DIE"
19489 " at 0x%x [in module %s]"),
19490 dwarf_attr_name (attr
->name
), die
->offset
.sect_off
,
19491 objfile_name (objfile
));
19492 return build_error_marker_type (cu
, die
);
19495 /* If not cached we need to read it in. */
19497 if (this_type
== NULL
)
19499 struct die_info
*type_die
= NULL
;
19500 struct dwarf2_cu
*type_cu
= cu
;
19502 if (attr_form_is_ref (attr
))
19503 type_die
= follow_die_ref (die
, attr
, &type_cu
);
19504 if (type_die
== NULL
)
19505 return build_error_marker_type (cu
, die
);
19506 /* If we find the type now, it's probably because the type came
19507 from an inter-CU reference and the type's CU got expanded before
19509 this_type
= read_type_die (type_die
, type_cu
);
19512 /* If we still don't have a type use an error marker. */
19514 if (this_type
== NULL
)
19515 return build_error_marker_type (cu
, die
);
19520 /* Return the type in DIE, CU.
19521 Returns NULL for invalid types.
19523 This first does a lookup in die_type_hash,
19524 and only reads the die in if necessary.
19526 NOTE: This can be called when reading in partial or full symbols. */
19528 static struct type
*
19529 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
19531 struct type
*this_type
;
19533 this_type
= get_die_type (die
, cu
);
19537 return read_type_die_1 (die
, cu
);
19540 /* Read the type in DIE, CU.
19541 Returns NULL for invalid types. */
19543 static struct type
*
19544 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
19546 struct type
*this_type
= NULL
;
19550 case DW_TAG_class_type
:
19551 case DW_TAG_interface_type
:
19552 case DW_TAG_structure_type
:
19553 case DW_TAG_union_type
:
19554 this_type
= read_structure_type (die
, cu
);
19556 case DW_TAG_enumeration_type
:
19557 this_type
= read_enumeration_type (die
, cu
);
19559 case DW_TAG_subprogram
:
19560 case DW_TAG_subroutine_type
:
19561 case DW_TAG_inlined_subroutine
:
19562 this_type
= read_subroutine_type (die
, cu
);
19564 case DW_TAG_array_type
:
19565 this_type
= read_array_type (die
, cu
);
19567 case DW_TAG_set_type
:
19568 this_type
= read_set_type (die
, cu
);
19570 case DW_TAG_pointer_type
:
19571 this_type
= read_tag_pointer_type (die
, cu
);
19573 case DW_TAG_ptr_to_member_type
:
19574 this_type
= read_tag_ptr_to_member_type (die
, cu
);
19576 case DW_TAG_reference_type
:
19577 this_type
= read_tag_reference_type (die
, cu
);
19579 case DW_TAG_const_type
:
19580 this_type
= read_tag_const_type (die
, cu
);
19582 case DW_TAG_volatile_type
:
19583 this_type
= read_tag_volatile_type (die
, cu
);
19585 case DW_TAG_restrict_type
:
19586 this_type
= read_tag_restrict_type (die
, cu
);
19588 case DW_TAG_string_type
:
19589 this_type
= read_tag_string_type (die
, cu
);
19591 case DW_TAG_typedef
:
19592 this_type
= read_typedef (die
, cu
);
19594 case DW_TAG_subrange_type
:
19595 this_type
= read_subrange_type (die
, cu
);
19597 case DW_TAG_base_type
:
19598 this_type
= read_base_type (die
, cu
);
19600 case DW_TAG_unspecified_type
:
19601 this_type
= read_unspecified_type (die
, cu
);
19603 case DW_TAG_namespace
:
19604 this_type
= read_namespace_type (die
, cu
);
19606 case DW_TAG_module
:
19607 this_type
= read_module_type (die
, cu
);
19609 case DW_TAG_atomic_type
:
19610 this_type
= read_tag_atomic_type (die
, cu
);
19613 complaint (&symfile_complaints
,
19614 _("unexpected tag in read_type_die: '%s'"),
19615 dwarf_tag_name (die
->tag
));
19622 /* See if we can figure out if the class lives in a namespace. We do
19623 this by looking for a member function; its demangled name will
19624 contain namespace info, if there is any.
19625 Return the computed name or NULL.
19626 Space for the result is allocated on the objfile's obstack.
19627 This is the full-die version of guess_partial_die_structure_name.
19628 In this case we know DIE has no useful parent. */
19631 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19633 struct die_info
*spec_die
;
19634 struct dwarf2_cu
*spec_cu
;
19635 struct die_info
*child
;
19638 spec_die
= die_specification (die
, &spec_cu
);
19639 if (spec_die
!= NULL
)
19645 for (child
= die
->child
;
19647 child
= child
->sibling
)
19649 if (child
->tag
== DW_TAG_subprogram
)
19651 const char *linkage_name
;
19653 linkage_name
= dwarf2_string_attr (child
, DW_AT_linkage_name
, cu
);
19654 if (linkage_name
== NULL
)
19655 linkage_name
= dwarf2_string_attr (child
, DW_AT_MIPS_linkage_name
,
19657 if (linkage_name
!= NULL
)
19660 = language_class_name_from_physname (cu
->language_defn
,
19664 if (actual_name
!= NULL
)
19666 const char *die_name
= dwarf2_name (die
, cu
);
19668 if (die_name
!= NULL
19669 && strcmp (die_name
, actual_name
) != 0)
19671 /* Strip off the class name from the full name.
19672 We want the prefix. */
19673 int die_name_len
= strlen (die_name
);
19674 int actual_name_len
= strlen (actual_name
);
19676 /* Test for '::' as a sanity check. */
19677 if (actual_name_len
> die_name_len
+ 2
19678 && actual_name
[actual_name_len
19679 - die_name_len
- 1] == ':')
19680 name
= (char *) obstack_copy0 (
19681 &cu
->objfile
->per_bfd
->storage_obstack
,
19682 actual_name
, actual_name_len
- die_name_len
- 2);
19685 xfree (actual_name
);
19694 /* GCC might emit a nameless typedef that has a linkage name. Determine the
19695 prefix part in such case. See
19696 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19699 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19701 struct attribute
*attr
;
19704 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
19705 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
19708 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
19711 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
19713 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
19714 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
19717 /* dwarf2_name had to be already called. */
19718 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
19720 /* Strip the base name, keep any leading namespaces/classes. */
19721 base
= strrchr (DW_STRING (attr
), ':');
19722 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
19725 return (char *) obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
19727 &base
[-1] - DW_STRING (attr
));
19730 /* Return the name of the namespace/class that DIE is defined within,
19731 or "" if we can't tell. The caller should not xfree the result.
19733 For example, if we're within the method foo() in the following
19743 then determine_prefix on foo's die will return "N::C". */
19745 static const char *
19746 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19748 struct die_info
*parent
, *spec_die
;
19749 struct dwarf2_cu
*spec_cu
;
19750 struct type
*parent_type
;
19753 if (cu
->language
!= language_cplus
19754 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
19755 && cu
->language
!= language_rust
)
19758 retval
= anonymous_struct_prefix (die
, cu
);
19762 /* We have to be careful in the presence of DW_AT_specification.
19763 For example, with GCC 3.4, given the code
19767 // Definition of N::foo.
19771 then we'll have a tree of DIEs like this:
19773 1: DW_TAG_compile_unit
19774 2: DW_TAG_namespace // N
19775 3: DW_TAG_subprogram // declaration of N::foo
19776 4: DW_TAG_subprogram // definition of N::foo
19777 DW_AT_specification // refers to die #3
19779 Thus, when processing die #4, we have to pretend that we're in
19780 the context of its DW_AT_specification, namely the contex of die
19783 spec_die
= die_specification (die
, &spec_cu
);
19784 if (spec_die
== NULL
)
19785 parent
= die
->parent
;
19788 parent
= spec_die
->parent
;
19792 if (parent
== NULL
)
19794 else if (parent
->building_fullname
)
19797 const char *parent_name
;
19799 /* It has been seen on RealView 2.2 built binaries,
19800 DW_TAG_template_type_param types actually _defined_ as
19801 children of the parent class:
19804 template class <class Enum> Class{};
19805 Class<enum E> class_e;
19807 1: DW_TAG_class_type (Class)
19808 2: DW_TAG_enumeration_type (E)
19809 3: DW_TAG_enumerator (enum1:0)
19810 3: DW_TAG_enumerator (enum2:1)
19812 2: DW_TAG_template_type_param
19813 DW_AT_type DW_FORM_ref_udata (E)
19815 Besides being broken debug info, it can put GDB into an
19816 infinite loop. Consider:
19818 When we're building the full name for Class<E>, we'll start
19819 at Class, and go look over its template type parameters,
19820 finding E. We'll then try to build the full name of E, and
19821 reach here. We're now trying to build the full name of E,
19822 and look over the parent DIE for containing scope. In the
19823 broken case, if we followed the parent DIE of E, we'd again
19824 find Class, and once again go look at its template type
19825 arguments, etc., etc. Simply don't consider such parent die
19826 as source-level parent of this die (it can't be, the language
19827 doesn't allow it), and break the loop here. */
19828 name
= dwarf2_name (die
, cu
);
19829 parent_name
= dwarf2_name (parent
, cu
);
19830 complaint (&symfile_complaints
,
19831 _("template param type '%s' defined within parent '%s'"),
19832 name
? name
: "<unknown>",
19833 parent_name
? parent_name
: "<unknown>");
19837 switch (parent
->tag
)
19839 case DW_TAG_namespace
:
19840 parent_type
= read_type_die (parent
, cu
);
19841 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
19842 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
19843 Work around this problem here. */
19844 if (cu
->language
== language_cplus
19845 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
19847 /* We give a name to even anonymous namespaces. */
19848 return TYPE_TAG_NAME (parent_type
);
19849 case DW_TAG_class_type
:
19850 case DW_TAG_interface_type
:
19851 case DW_TAG_structure_type
:
19852 case DW_TAG_union_type
:
19853 case DW_TAG_module
:
19854 parent_type
= read_type_die (parent
, cu
);
19855 if (TYPE_TAG_NAME (parent_type
) != NULL
)
19856 return TYPE_TAG_NAME (parent_type
);
19858 /* An anonymous structure is only allowed non-static data
19859 members; no typedefs, no member functions, et cetera.
19860 So it does not need a prefix. */
19862 case DW_TAG_compile_unit
:
19863 case DW_TAG_partial_unit
:
19864 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
19865 if (cu
->language
== language_cplus
19866 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
19867 && die
->child
!= NULL
19868 && (die
->tag
== DW_TAG_class_type
19869 || die
->tag
== DW_TAG_structure_type
19870 || die
->tag
== DW_TAG_union_type
))
19872 char *name
= guess_full_die_structure_name (die
, cu
);
19877 case DW_TAG_enumeration_type
:
19878 parent_type
= read_type_die (parent
, cu
);
19879 if (TYPE_DECLARED_CLASS (parent_type
))
19881 if (TYPE_TAG_NAME (parent_type
) != NULL
)
19882 return TYPE_TAG_NAME (parent_type
);
19885 /* Fall through. */
19887 return determine_prefix (parent
, cu
);
19891 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
19892 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
19893 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
19894 an obconcat, otherwise allocate storage for the result. The CU argument is
19895 used to determine the language and hence, the appropriate separator. */
19897 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
19900 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
19901 int physname
, struct dwarf2_cu
*cu
)
19903 const char *lead
= "";
19906 if (suffix
== NULL
|| suffix
[0] == '\0'
19907 || prefix
== NULL
|| prefix
[0] == '\0')
19909 else if (cu
->language
== language_d
)
19911 /* For D, the 'main' function could be defined in any module, but it
19912 should never be prefixed. */
19913 if (strcmp (suffix
, "D main") == 0)
19921 else if (cu
->language
== language_fortran
&& physname
)
19923 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
19924 DW_AT_MIPS_linkage_name is preferred and used instead. */
19932 if (prefix
== NULL
)
19934 if (suffix
== NULL
)
19941 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
19943 strcpy (retval
, lead
);
19944 strcat (retval
, prefix
);
19945 strcat (retval
, sep
);
19946 strcat (retval
, suffix
);
19951 /* We have an obstack. */
19952 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
19956 /* Return sibling of die, NULL if no sibling. */
19958 static struct die_info
*
19959 sibling_die (struct die_info
*die
)
19961 return die
->sibling
;
19964 /* Get name of a die, return NULL if not found. */
19966 static const char *
19967 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
19968 struct obstack
*obstack
)
19970 if (name
&& cu
->language
== language_cplus
)
19972 std::string canon_name
= cp_canonicalize_string (name
);
19974 if (!canon_name
.empty ())
19976 if (canon_name
!= name
)
19977 name
= (const char *) obstack_copy0 (obstack
,
19978 canon_name
.c_str (),
19979 canon_name
.length ());
19986 /* Get name of a die, return NULL if not found.
19987 Anonymous namespaces are converted to their magic string. */
19989 static const char *
19990 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19992 struct attribute
*attr
;
19994 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
19995 if ((!attr
|| !DW_STRING (attr
))
19996 && die
->tag
!= DW_TAG_namespace
19997 && die
->tag
!= DW_TAG_class_type
19998 && die
->tag
!= DW_TAG_interface_type
19999 && die
->tag
!= DW_TAG_structure_type
20000 && die
->tag
!= DW_TAG_union_type
)
20005 case DW_TAG_compile_unit
:
20006 case DW_TAG_partial_unit
:
20007 /* Compilation units have a DW_AT_name that is a filename, not
20008 a source language identifier. */
20009 case DW_TAG_enumeration_type
:
20010 case DW_TAG_enumerator
:
20011 /* These tags always have simple identifiers already; no need
20012 to canonicalize them. */
20013 return DW_STRING (attr
);
20015 case DW_TAG_namespace
:
20016 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
20017 return DW_STRING (attr
);
20018 return CP_ANONYMOUS_NAMESPACE_STR
;
20020 case DW_TAG_class_type
:
20021 case DW_TAG_interface_type
:
20022 case DW_TAG_structure_type
:
20023 case DW_TAG_union_type
:
20024 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
20025 structures or unions. These were of the form "._%d" in GCC 4.1,
20026 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
20027 and GCC 4.4. We work around this problem by ignoring these. */
20028 if (attr
&& DW_STRING (attr
)
20029 && (startswith (DW_STRING (attr
), "._")
20030 || startswith (DW_STRING (attr
), "<anonymous")))
20033 /* GCC might emit a nameless typedef that has a linkage name. See
20034 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20035 if (!attr
|| DW_STRING (attr
) == NULL
)
20037 char *demangled
= NULL
;
20039 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
20041 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
20043 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
20046 /* Avoid demangling DW_STRING (attr) the second time on a second
20047 call for the same DIE. */
20048 if (!DW_STRING_IS_CANONICAL (attr
))
20049 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
20055 /* FIXME: we already did this for the partial symbol... */
20058 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
20059 demangled
, strlen (demangled
)));
20060 DW_STRING_IS_CANONICAL (attr
) = 1;
20063 /* Strip any leading namespaces/classes, keep only the base name.
20064 DW_AT_name for named DIEs does not contain the prefixes. */
20065 base
= strrchr (DW_STRING (attr
), ':');
20066 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
20069 return DW_STRING (attr
);
20078 if (!DW_STRING_IS_CANONICAL (attr
))
20081 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
20082 &cu
->objfile
->per_bfd
->storage_obstack
);
20083 DW_STRING_IS_CANONICAL (attr
) = 1;
20085 return DW_STRING (attr
);
20088 /* Return the die that this die in an extension of, or NULL if there
20089 is none. *EXT_CU is the CU containing DIE on input, and the CU
20090 containing the return value on output. */
20092 static struct die_info
*
20093 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
20095 struct attribute
*attr
;
20097 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
20101 return follow_die_ref (die
, attr
, ext_cu
);
20104 /* Convert a DIE tag into its string name. */
20106 static const char *
20107 dwarf_tag_name (unsigned tag
)
20109 const char *name
= get_DW_TAG_name (tag
);
20112 return "DW_TAG_<unknown>";
20117 /* Convert a DWARF attribute code into its string name. */
20119 static const char *
20120 dwarf_attr_name (unsigned attr
)
20124 #ifdef MIPS /* collides with DW_AT_HP_block_index */
20125 if (attr
== DW_AT_MIPS_fde
)
20126 return "DW_AT_MIPS_fde";
20128 if (attr
== DW_AT_HP_block_index
)
20129 return "DW_AT_HP_block_index";
20132 name
= get_DW_AT_name (attr
);
20135 return "DW_AT_<unknown>";
20140 /* Convert a DWARF value form code into its string name. */
20142 static const char *
20143 dwarf_form_name (unsigned form
)
20145 const char *name
= get_DW_FORM_name (form
);
20148 return "DW_FORM_<unknown>";
20154 dwarf_bool_name (unsigned mybool
)
20162 /* Convert a DWARF type code into its string name. */
20164 static const char *
20165 dwarf_type_encoding_name (unsigned enc
)
20167 const char *name
= get_DW_ATE_name (enc
);
20170 return "DW_ATE_<unknown>";
20176 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
20180 print_spaces (indent
, f
);
20181 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
20182 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
20184 if (die
->parent
!= NULL
)
20186 print_spaces (indent
, f
);
20187 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
20188 die
->parent
->offset
.sect_off
);
20191 print_spaces (indent
, f
);
20192 fprintf_unfiltered (f
, " has children: %s\n",
20193 dwarf_bool_name (die
->child
!= NULL
));
20195 print_spaces (indent
, f
);
20196 fprintf_unfiltered (f
, " attributes:\n");
20198 for (i
= 0; i
< die
->num_attrs
; ++i
)
20200 print_spaces (indent
, f
);
20201 fprintf_unfiltered (f
, " %s (%s) ",
20202 dwarf_attr_name (die
->attrs
[i
].name
),
20203 dwarf_form_name (die
->attrs
[i
].form
));
20205 switch (die
->attrs
[i
].form
)
20208 case DW_FORM_GNU_addr_index
:
20209 fprintf_unfiltered (f
, "address: ");
20210 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
20212 case DW_FORM_block2
:
20213 case DW_FORM_block4
:
20214 case DW_FORM_block
:
20215 case DW_FORM_block1
:
20216 fprintf_unfiltered (f
, "block: size %s",
20217 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
20219 case DW_FORM_exprloc
:
20220 fprintf_unfiltered (f
, "expression: size %s",
20221 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
20223 case DW_FORM_ref_addr
:
20224 fprintf_unfiltered (f
, "ref address: ");
20225 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
20227 case DW_FORM_GNU_ref_alt
:
20228 fprintf_unfiltered (f
, "alt ref address: ");
20229 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
20235 case DW_FORM_ref_udata
:
20236 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
20237 (long) (DW_UNSND (&die
->attrs
[i
])));
20239 case DW_FORM_data1
:
20240 case DW_FORM_data2
:
20241 case DW_FORM_data4
:
20242 case DW_FORM_data8
:
20243 case DW_FORM_udata
:
20244 case DW_FORM_sdata
:
20245 fprintf_unfiltered (f
, "constant: %s",
20246 pulongest (DW_UNSND (&die
->attrs
[i
])));
20248 case DW_FORM_sec_offset
:
20249 fprintf_unfiltered (f
, "section offset: %s",
20250 pulongest (DW_UNSND (&die
->attrs
[i
])));
20252 case DW_FORM_ref_sig8
:
20253 fprintf_unfiltered (f
, "signature: %s",
20254 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
20256 case DW_FORM_string
:
20258 case DW_FORM_line_strp
:
20259 case DW_FORM_GNU_str_index
:
20260 case DW_FORM_GNU_strp_alt
:
20261 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
20262 DW_STRING (&die
->attrs
[i
])
20263 ? DW_STRING (&die
->attrs
[i
]) : "",
20264 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
20267 if (DW_UNSND (&die
->attrs
[i
]))
20268 fprintf_unfiltered (f
, "flag: TRUE");
20270 fprintf_unfiltered (f
, "flag: FALSE");
20272 case DW_FORM_flag_present
:
20273 fprintf_unfiltered (f
, "flag: TRUE");
20275 case DW_FORM_indirect
:
20276 /* The reader will have reduced the indirect form to
20277 the "base form" so this form should not occur. */
20278 fprintf_unfiltered (f
,
20279 "unexpected attribute form: DW_FORM_indirect");
20282 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
20283 die
->attrs
[i
].form
);
20286 fprintf_unfiltered (f
, "\n");
20291 dump_die_for_error (struct die_info
*die
)
20293 dump_die_shallow (gdb_stderr
, 0, die
);
20297 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
20299 int indent
= level
* 4;
20301 gdb_assert (die
!= NULL
);
20303 if (level
>= max_level
)
20306 dump_die_shallow (f
, indent
, die
);
20308 if (die
->child
!= NULL
)
20310 print_spaces (indent
, f
);
20311 fprintf_unfiltered (f
, " Children:");
20312 if (level
+ 1 < max_level
)
20314 fprintf_unfiltered (f
, "\n");
20315 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
20319 fprintf_unfiltered (f
,
20320 " [not printed, max nesting level reached]\n");
20324 if (die
->sibling
!= NULL
&& level
> 0)
20326 dump_die_1 (f
, level
, max_level
, die
->sibling
);
20330 /* This is called from the pdie macro in gdbinit.in.
20331 It's not static so gcc will keep a copy callable from gdb. */
20334 dump_die (struct die_info
*die
, int max_level
)
20336 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
20340 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
20344 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
20350 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
20354 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
20356 sect_offset retval
= { DW_UNSND (attr
) };
20358 if (attr_form_is_ref (attr
))
20361 retval
.sect_off
= 0;
20362 complaint (&symfile_complaints
,
20363 _("unsupported die ref attribute form: '%s'"),
20364 dwarf_form_name (attr
->form
));
20368 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
20369 * the value held by the attribute is not constant. */
20372 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
20374 if (attr
->form
== DW_FORM_sdata
)
20375 return DW_SND (attr
);
20376 else if (attr
->form
== DW_FORM_udata
20377 || attr
->form
== DW_FORM_data1
20378 || attr
->form
== DW_FORM_data2
20379 || attr
->form
== DW_FORM_data4
20380 || attr
->form
== DW_FORM_data8
)
20381 return DW_UNSND (attr
);
20384 complaint (&symfile_complaints
,
20385 _("Attribute value is not a constant (%s)"),
20386 dwarf_form_name (attr
->form
));
20387 return default_value
;
20391 /* Follow reference or signature attribute ATTR of SRC_DIE.
20392 On entry *REF_CU is the CU of SRC_DIE.
20393 On exit *REF_CU is the CU of the result. */
20395 static struct die_info
*
20396 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20397 struct dwarf2_cu
**ref_cu
)
20399 struct die_info
*die
;
20401 if (attr_form_is_ref (attr
))
20402 die
= follow_die_ref (src_die
, attr
, ref_cu
);
20403 else if (attr
->form
== DW_FORM_ref_sig8
)
20404 die
= follow_die_sig (src_die
, attr
, ref_cu
);
20407 dump_die_for_error (src_die
);
20408 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
20409 objfile_name ((*ref_cu
)->objfile
));
20415 /* Follow reference OFFSET.
20416 On entry *REF_CU is the CU of the source die referencing OFFSET.
20417 On exit *REF_CU is the CU of the result.
20418 Returns NULL if OFFSET is invalid. */
20420 static struct die_info
*
20421 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
20422 struct dwarf2_cu
**ref_cu
)
20424 struct die_info temp_die
;
20425 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
20427 gdb_assert (cu
->per_cu
!= NULL
);
20431 if (cu
->per_cu
->is_debug_types
)
20433 /* .debug_types CUs cannot reference anything outside their CU.
20434 If they need to, they have to reference a signatured type via
20435 DW_FORM_ref_sig8. */
20436 if (! offset_in_cu_p (&cu
->header
, offset
))
20439 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
20440 || ! offset_in_cu_p (&cu
->header
, offset
))
20442 struct dwarf2_per_cu_data
*per_cu
;
20444 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
20447 /* If necessary, add it to the queue and load its DIEs. */
20448 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
20449 load_full_comp_unit (per_cu
, cu
->language
);
20451 target_cu
= per_cu
->cu
;
20453 else if (cu
->dies
== NULL
)
20455 /* We're loading full DIEs during partial symbol reading. */
20456 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
20457 load_full_comp_unit (cu
->per_cu
, language_minimal
);
20460 *ref_cu
= target_cu
;
20461 temp_die
.offset
= offset
;
20462 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
20463 &temp_die
, offset
.sect_off
);
20466 /* Follow reference attribute ATTR of SRC_DIE.
20467 On entry *REF_CU is the CU of SRC_DIE.
20468 On exit *REF_CU is the CU of the result. */
20470 static struct die_info
*
20471 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
20472 struct dwarf2_cu
**ref_cu
)
20474 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
20475 struct dwarf2_cu
*cu
= *ref_cu
;
20476 struct die_info
*die
;
20478 die
= follow_die_offset (offset
,
20479 (attr
->form
== DW_FORM_GNU_ref_alt
20480 || cu
->per_cu
->is_dwz
),
20483 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
20484 "at 0x%x [in module %s]"),
20485 offset
.sect_off
, src_die
->offset
.sect_off
,
20486 objfile_name (cu
->objfile
));
20491 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
20492 Returned value is intended for DW_OP_call*. Returned
20493 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
20495 struct dwarf2_locexpr_baton
20496 dwarf2_fetch_die_loc_sect_off (sect_offset offset
,
20497 struct dwarf2_per_cu_data
*per_cu
,
20498 CORE_ADDR (*get_frame_pc
) (void *baton
),
20501 struct dwarf2_cu
*cu
;
20502 struct die_info
*die
;
20503 struct attribute
*attr
;
20504 struct dwarf2_locexpr_baton retval
;
20506 dw2_setup (per_cu
->objfile
);
20508 if (per_cu
->cu
== NULL
)
20513 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20514 Instead just throw an error, not much else we can do. */
20515 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
20516 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20519 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
20521 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
20522 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20524 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20527 /* DWARF: "If there is no such attribute, then there is no effect.".
20528 DATA is ignored if SIZE is 0. */
20530 retval
.data
= NULL
;
20533 else if (attr_form_is_section_offset (attr
))
20535 struct dwarf2_loclist_baton loclist_baton
;
20536 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
20539 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
20541 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
20543 retval
.size
= size
;
20547 if (!attr_form_is_block (attr
))
20548 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
20549 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
20550 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20552 retval
.data
= DW_BLOCK (attr
)->data
;
20553 retval
.size
= DW_BLOCK (attr
)->size
;
20555 retval
.per_cu
= cu
->per_cu
;
20557 age_cached_comp_units ();
20562 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
20565 struct dwarf2_locexpr_baton
20566 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
20567 struct dwarf2_per_cu_data
*per_cu
,
20568 CORE_ADDR (*get_frame_pc
) (void *baton
),
20571 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
20573 return dwarf2_fetch_die_loc_sect_off (offset
, per_cu
, get_frame_pc
, baton
);
20576 /* Write a constant of a given type as target-ordered bytes into
20579 static const gdb_byte
*
20580 write_constant_as_bytes (struct obstack
*obstack
,
20581 enum bfd_endian byte_order
,
20588 *len
= TYPE_LENGTH (type
);
20589 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20590 store_unsigned_integer (result
, *len
, byte_order
, value
);
20595 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
20596 pointer to the constant bytes and set LEN to the length of the
20597 data. If memory is needed, allocate it on OBSTACK. If the DIE
20598 does not have a DW_AT_const_value, return NULL. */
20601 dwarf2_fetch_constant_bytes (sect_offset offset
,
20602 struct dwarf2_per_cu_data
*per_cu
,
20603 struct obstack
*obstack
,
20606 struct dwarf2_cu
*cu
;
20607 struct die_info
*die
;
20608 struct attribute
*attr
;
20609 const gdb_byte
*result
= NULL
;
20612 enum bfd_endian byte_order
;
20614 dw2_setup (per_cu
->objfile
);
20616 if (per_cu
->cu
== NULL
)
20621 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20622 Instead just throw an error, not much else we can do. */
20623 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
20624 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20627 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
20629 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
20630 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20633 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20637 byte_order
= (bfd_big_endian (per_cu
->objfile
->obfd
)
20638 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20640 switch (attr
->form
)
20643 case DW_FORM_GNU_addr_index
:
20647 *len
= cu
->header
.addr_size
;
20648 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20649 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
20653 case DW_FORM_string
:
20655 case DW_FORM_GNU_str_index
:
20656 case DW_FORM_GNU_strp_alt
:
20657 /* DW_STRING is already allocated on the objfile obstack, point
20659 result
= (const gdb_byte
*) DW_STRING (attr
);
20660 *len
= strlen (DW_STRING (attr
));
20662 case DW_FORM_block1
:
20663 case DW_FORM_block2
:
20664 case DW_FORM_block4
:
20665 case DW_FORM_block
:
20666 case DW_FORM_exprloc
:
20667 result
= DW_BLOCK (attr
)->data
;
20668 *len
= DW_BLOCK (attr
)->size
;
20671 /* The DW_AT_const_value attributes are supposed to carry the
20672 symbol's value "represented as it would be on the target
20673 architecture." By the time we get here, it's already been
20674 converted to host endianness, so we just need to sign- or
20675 zero-extend it as appropriate. */
20676 case DW_FORM_data1
:
20677 type
= die_type (die
, cu
);
20678 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
20679 if (result
== NULL
)
20680 result
= write_constant_as_bytes (obstack
, byte_order
,
20683 case DW_FORM_data2
:
20684 type
= die_type (die
, cu
);
20685 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
20686 if (result
== NULL
)
20687 result
= write_constant_as_bytes (obstack
, byte_order
,
20690 case DW_FORM_data4
:
20691 type
= die_type (die
, cu
);
20692 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
20693 if (result
== NULL
)
20694 result
= write_constant_as_bytes (obstack
, byte_order
,
20697 case DW_FORM_data8
:
20698 type
= die_type (die
, cu
);
20699 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
20700 if (result
== NULL
)
20701 result
= write_constant_as_bytes (obstack
, byte_order
,
20705 case DW_FORM_sdata
:
20706 type
= die_type (die
, cu
);
20707 result
= write_constant_as_bytes (obstack
, byte_order
,
20708 type
, DW_SND (attr
), len
);
20711 case DW_FORM_udata
:
20712 type
= die_type (die
, cu
);
20713 result
= write_constant_as_bytes (obstack
, byte_order
,
20714 type
, DW_UNSND (attr
), len
);
20718 complaint (&symfile_complaints
,
20719 _("unsupported const value attribute form: '%s'"),
20720 dwarf_form_name (attr
->form
));
20727 /* Return the type of the DIE at DIE_OFFSET in the CU named by
20731 dwarf2_get_die_type (cu_offset die_offset
,
20732 struct dwarf2_per_cu_data
*per_cu
)
20734 sect_offset die_offset_sect
;
20736 dw2_setup (per_cu
->objfile
);
20738 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
20739 return get_die_type_at_offset (die_offset_sect
, per_cu
);
20742 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
20743 On entry *REF_CU is the CU of SRC_DIE.
20744 On exit *REF_CU is the CU of the result.
20745 Returns NULL if the referenced DIE isn't found. */
20747 static struct die_info
*
20748 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
20749 struct dwarf2_cu
**ref_cu
)
20751 struct die_info temp_die
;
20752 struct dwarf2_cu
*sig_cu
;
20753 struct die_info
*die
;
20755 /* While it might be nice to assert sig_type->type == NULL here,
20756 we can get here for DW_AT_imported_declaration where we need
20757 the DIE not the type. */
20759 /* If necessary, add it to the queue and load its DIEs. */
20761 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
20762 read_signatured_type (sig_type
);
20764 sig_cu
= sig_type
->per_cu
.cu
;
20765 gdb_assert (sig_cu
!= NULL
);
20766 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
20767 temp_die
.offset
= sig_type
->type_offset_in_section
;
20768 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
20769 temp_die
.offset
.sect_off
);
20772 /* For .gdb_index version 7 keep track of included TUs.
20773 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
20774 if (dwarf2_per_objfile
->index_table
!= NULL
20775 && dwarf2_per_objfile
->index_table
->version
<= 7)
20777 VEC_safe_push (dwarf2_per_cu_ptr
,
20778 (*ref_cu
)->per_cu
->imported_symtabs
,
20789 /* Follow signatured type referenced by ATTR in SRC_DIE.
20790 On entry *REF_CU is the CU of SRC_DIE.
20791 On exit *REF_CU is the CU of the result.
20792 The result is the DIE of the type.
20793 If the referenced type cannot be found an error is thrown. */
20795 static struct die_info
*
20796 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20797 struct dwarf2_cu
**ref_cu
)
20799 ULONGEST signature
= DW_SIGNATURE (attr
);
20800 struct signatured_type
*sig_type
;
20801 struct die_info
*die
;
20803 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
20805 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
20806 /* sig_type will be NULL if the signatured type is missing from
20808 if (sig_type
== NULL
)
20810 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
20811 " from DIE at 0x%x [in module %s]"),
20812 hex_string (signature
), src_die
->offset
.sect_off
,
20813 objfile_name ((*ref_cu
)->objfile
));
20816 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
20819 dump_die_for_error (src_die
);
20820 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
20821 " from DIE at 0x%x [in module %s]"),
20822 hex_string (signature
), src_die
->offset
.sect_off
,
20823 objfile_name ((*ref_cu
)->objfile
));
20829 /* Get the type specified by SIGNATURE referenced in DIE/CU,
20830 reading in and processing the type unit if necessary. */
20832 static struct type
*
20833 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
20834 struct dwarf2_cu
*cu
)
20836 struct signatured_type
*sig_type
;
20837 struct dwarf2_cu
*type_cu
;
20838 struct die_info
*type_die
;
20841 sig_type
= lookup_signatured_type (cu
, signature
);
20842 /* sig_type will be NULL if the signatured type is missing from
20844 if (sig_type
== NULL
)
20846 complaint (&symfile_complaints
,
20847 _("Dwarf Error: Cannot find signatured DIE %s referenced"
20848 " from DIE at 0x%x [in module %s]"),
20849 hex_string (signature
), die
->offset
.sect_off
,
20850 objfile_name (dwarf2_per_objfile
->objfile
));
20851 return build_error_marker_type (cu
, die
);
20854 /* If we already know the type we're done. */
20855 if (sig_type
->type
!= NULL
)
20856 return sig_type
->type
;
20859 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
20860 if (type_die
!= NULL
)
20862 /* N.B. We need to call get_die_type to ensure only one type for this DIE
20863 is created. This is important, for example, because for c++ classes
20864 we need TYPE_NAME set which is only done by new_symbol. Blech. */
20865 type
= read_type_die (type_die
, type_cu
);
20868 complaint (&symfile_complaints
,
20869 _("Dwarf Error: Cannot build signatured type %s"
20870 " referenced from DIE at 0x%x [in module %s]"),
20871 hex_string (signature
), die
->offset
.sect_off
,
20872 objfile_name (dwarf2_per_objfile
->objfile
));
20873 type
= build_error_marker_type (cu
, die
);
20878 complaint (&symfile_complaints
,
20879 _("Dwarf Error: Problem reading signatured DIE %s referenced"
20880 " from DIE at 0x%x [in module %s]"),
20881 hex_string (signature
), die
->offset
.sect_off
,
20882 objfile_name (dwarf2_per_objfile
->objfile
));
20883 type
= build_error_marker_type (cu
, die
);
20885 sig_type
->type
= type
;
20890 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
20891 reading in and processing the type unit if necessary. */
20893 static struct type
*
20894 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
20895 struct dwarf2_cu
*cu
) /* ARI: editCase function */
20897 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
20898 if (attr_form_is_ref (attr
))
20900 struct dwarf2_cu
*type_cu
= cu
;
20901 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
20903 return read_type_die (type_die
, type_cu
);
20905 else if (attr
->form
== DW_FORM_ref_sig8
)
20907 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
20911 complaint (&symfile_complaints
,
20912 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
20913 " at 0x%x [in module %s]"),
20914 dwarf_form_name (attr
->form
), die
->offset
.sect_off
,
20915 objfile_name (dwarf2_per_objfile
->objfile
));
20916 return build_error_marker_type (cu
, die
);
20920 /* Load the DIEs associated with type unit PER_CU into memory. */
20923 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
20925 struct signatured_type
*sig_type
;
20927 /* Caller is responsible for ensuring type_unit_groups don't get here. */
20928 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
20930 /* We have the per_cu, but we need the signatured_type.
20931 Fortunately this is an easy translation. */
20932 gdb_assert (per_cu
->is_debug_types
);
20933 sig_type
= (struct signatured_type
*) per_cu
;
20935 gdb_assert (per_cu
->cu
== NULL
);
20937 read_signatured_type (sig_type
);
20939 gdb_assert (per_cu
->cu
!= NULL
);
20942 /* die_reader_func for read_signatured_type.
20943 This is identical to load_full_comp_unit_reader,
20944 but is kept separate for now. */
20947 read_signatured_type_reader (const struct die_reader_specs
*reader
,
20948 const gdb_byte
*info_ptr
,
20949 struct die_info
*comp_unit_die
,
20953 struct dwarf2_cu
*cu
= reader
->cu
;
20955 gdb_assert (cu
->die_hash
== NULL
);
20957 htab_create_alloc_ex (cu
->header
.length
/ 12,
20961 &cu
->comp_unit_obstack
,
20962 hashtab_obstack_allocate
,
20963 dummy_obstack_deallocate
);
20966 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
20967 &info_ptr
, comp_unit_die
);
20968 cu
->dies
= comp_unit_die
;
20969 /* comp_unit_die is not stored in die_hash, no need. */
20971 /* We try not to read any attributes in this function, because not
20972 all CUs needed for references have been loaded yet, and symbol
20973 table processing isn't initialized. But we have to set the CU language,
20974 or we won't be able to build types correctly.
20975 Similarly, if we do not read the producer, we can not apply
20976 producer-specific interpretation. */
20977 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
20980 /* Read in a signatured type and build its CU and DIEs.
20981 If the type is a stub for the real type in a DWO file,
20982 read in the real type from the DWO file as well. */
20985 read_signatured_type (struct signatured_type
*sig_type
)
20987 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
20989 gdb_assert (per_cu
->is_debug_types
);
20990 gdb_assert (per_cu
->cu
== NULL
);
20992 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
20993 read_signatured_type_reader
, NULL
);
20994 sig_type
->per_cu
.tu_read
= 1;
20997 /* Decode simple location descriptions.
20998 Given a pointer to a dwarf block that defines a location, compute
20999 the location and return the value.
21001 NOTE drow/2003-11-18: This function is called in two situations
21002 now: for the address of static or global variables (partial symbols
21003 only) and for offsets into structures which are expected to be
21004 (more or less) constant. The partial symbol case should go away,
21005 and only the constant case should remain. That will let this
21006 function complain more accurately. A few special modes are allowed
21007 without complaint for global variables (for instance, global
21008 register values and thread-local values).
21010 A location description containing no operations indicates that the
21011 object is optimized out. The return value is 0 for that case.
21012 FIXME drow/2003-11-16: No callers check for this case any more; soon all
21013 callers will only want a very basic result and this can become a
21016 Note that stack[0] is unused except as a default error return. */
21019 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
21021 struct objfile
*objfile
= cu
->objfile
;
21023 size_t size
= blk
->size
;
21024 const gdb_byte
*data
= blk
->data
;
21025 CORE_ADDR stack
[64];
21027 unsigned int bytes_read
, unsnd
;
21033 stack
[++stacki
] = 0;
21072 stack
[++stacki
] = op
- DW_OP_lit0
;
21107 stack
[++stacki
] = op
- DW_OP_reg0
;
21109 dwarf2_complex_location_expr_complaint ();
21113 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
21115 stack
[++stacki
] = unsnd
;
21117 dwarf2_complex_location_expr_complaint ();
21121 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
21126 case DW_OP_const1u
:
21127 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
21131 case DW_OP_const1s
:
21132 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
21136 case DW_OP_const2u
:
21137 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
21141 case DW_OP_const2s
:
21142 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
21146 case DW_OP_const4u
:
21147 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
21151 case DW_OP_const4s
:
21152 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
21156 case DW_OP_const8u
:
21157 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
21162 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
21168 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
21173 stack
[stacki
+ 1] = stack
[stacki
];
21178 stack
[stacki
- 1] += stack
[stacki
];
21182 case DW_OP_plus_uconst
:
21183 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
21189 stack
[stacki
- 1] -= stack
[stacki
];
21194 /* If we're not the last op, then we definitely can't encode
21195 this using GDB's address_class enum. This is valid for partial
21196 global symbols, although the variable's address will be bogus
21199 dwarf2_complex_location_expr_complaint ();
21202 case DW_OP_GNU_push_tls_address
:
21203 case DW_OP_form_tls_address
:
21204 /* The top of the stack has the offset from the beginning
21205 of the thread control block at which the variable is located. */
21206 /* Nothing should follow this operator, so the top of stack would
21208 /* This is valid for partial global symbols, but the variable's
21209 address will be bogus in the psymtab. Make it always at least
21210 non-zero to not look as a variable garbage collected by linker
21211 which have DW_OP_addr 0. */
21213 dwarf2_complex_location_expr_complaint ();
21217 case DW_OP_GNU_uninit
:
21220 case DW_OP_GNU_addr_index
:
21221 case DW_OP_GNU_const_index
:
21222 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
21229 const char *name
= get_DW_OP_name (op
);
21232 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
21235 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
21239 return (stack
[stacki
]);
21242 /* Enforce maximum stack depth of SIZE-1 to avoid writing
21243 outside of the allocated space. Also enforce minimum>0. */
21244 if (stacki
>= ARRAY_SIZE (stack
) - 1)
21246 complaint (&symfile_complaints
,
21247 _("location description stack overflow"));
21253 complaint (&symfile_complaints
,
21254 _("location description stack underflow"));
21258 return (stack
[stacki
]);
21261 /* memory allocation interface */
21263 static struct dwarf_block
*
21264 dwarf_alloc_block (struct dwarf2_cu
*cu
)
21266 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
21269 static struct die_info
*
21270 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
21272 struct die_info
*die
;
21273 size_t size
= sizeof (struct die_info
);
21276 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
21278 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
21279 memset (die
, 0, sizeof (struct die_info
));
21284 /* Macro support. */
21286 /* Return file name relative to the compilation directory of file number I in
21287 *LH's file name table. The result is allocated using xmalloc; the caller is
21288 responsible for freeing it. */
21291 file_file_name (int file
, struct line_header
*lh
)
21293 /* Is the file number a valid index into the line header's file name
21294 table? Remember that file numbers start with one, not zero. */
21295 if (1 <= file
&& file
<= lh
->num_file_names
)
21297 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
21299 if (IS_ABSOLUTE_PATH (fe
->name
) || fe
->dir_index
== 0
21300 || lh
->include_dirs
== NULL
)
21301 return xstrdup (fe
->name
);
21302 return concat (lh
->include_dirs
[fe
->dir_index
- 1], SLASH_STRING
,
21303 fe
->name
, (char *) NULL
);
21307 /* The compiler produced a bogus file number. We can at least
21308 record the macro definitions made in the file, even if we
21309 won't be able to find the file by name. */
21310 char fake_name
[80];
21312 xsnprintf (fake_name
, sizeof (fake_name
),
21313 "<bad macro file number %d>", file
);
21315 complaint (&symfile_complaints
,
21316 _("bad file number in macro information (%d)"),
21319 return xstrdup (fake_name
);
21323 /* Return the full name of file number I in *LH's file name table.
21324 Use COMP_DIR as the name of the current directory of the
21325 compilation. The result is allocated using xmalloc; the caller is
21326 responsible for freeing it. */
21328 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
21330 /* Is the file number a valid index into the line header's file name
21331 table? Remember that file numbers start with one, not zero. */
21332 if (1 <= file
&& file
<= lh
->num_file_names
)
21334 char *relative
= file_file_name (file
, lh
);
21336 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
21338 return reconcat (relative
, comp_dir
, SLASH_STRING
,
21339 relative
, (char *) NULL
);
21342 return file_file_name (file
, lh
);
21346 static struct macro_source_file
*
21347 macro_start_file (int file
, int line
,
21348 struct macro_source_file
*current_file
,
21349 struct line_header
*lh
)
21351 /* File name relative to the compilation directory of this source file. */
21352 char *file_name
= file_file_name (file
, lh
);
21354 if (! current_file
)
21356 /* Note: We don't create a macro table for this compilation unit
21357 at all until we actually get a filename. */
21358 struct macro_table
*macro_table
= get_macro_table ();
21360 /* If we have no current file, then this must be the start_file
21361 directive for the compilation unit's main source file. */
21362 current_file
= macro_set_main (macro_table
, file_name
);
21363 macro_define_special (macro_table
);
21366 current_file
= macro_include (current_file
, line
, file_name
);
21370 return current_file
;
21374 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
21375 followed by a null byte. */
21377 copy_string (const char *buf
, int len
)
21379 char *s
= (char *) xmalloc (len
+ 1);
21381 memcpy (s
, buf
, len
);
21387 static const char *
21388 consume_improper_spaces (const char *p
, const char *body
)
21392 complaint (&symfile_complaints
,
21393 _("macro definition contains spaces "
21394 "in formal argument list:\n`%s'"),
21406 parse_macro_definition (struct macro_source_file
*file
, int line
,
21411 /* The body string takes one of two forms. For object-like macro
21412 definitions, it should be:
21414 <macro name> " " <definition>
21416 For function-like macro definitions, it should be:
21418 <macro name> "() " <definition>
21420 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
21422 Spaces may appear only where explicitly indicated, and in the
21425 The Dwarf 2 spec says that an object-like macro's name is always
21426 followed by a space, but versions of GCC around March 2002 omit
21427 the space when the macro's definition is the empty string.
21429 The Dwarf 2 spec says that there should be no spaces between the
21430 formal arguments in a function-like macro's formal argument list,
21431 but versions of GCC around March 2002 include spaces after the
21435 /* Find the extent of the macro name. The macro name is terminated
21436 by either a space or null character (for an object-like macro) or
21437 an opening paren (for a function-like macro). */
21438 for (p
= body
; *p
; p
++)
21439 if (*p
== ' ' || *p
== '(')
21442 if (*p
== ' ' || *p
== '\0')
21444 /* It's an object-like macro. */
21445 int name_len
= p
- body
;
21446 char *name
= copy_string (body
, name_len
);
21447 const char *replacement
;
21450 replacement
= body
+ name_len
+ 1;
21453 dwarf2_macro_malformed_definition_complaint (body
);
21454 replacement
= body
+ name_len
;
21457 macro_define_object (file
, line
, name
, replacement
);
21461 else if (*p
== '(')
21463 /* It's a function-like macro. */
21464 char *name
= copy_string (body
, p
- body
);
21467 char **argv
= XNEWVEC (char *, argv_size
);
21471 p
= consume_improper_spaces (p
, body
);
21473 /* Parse the formal argument list. */
21474 while (*p
&& *p
!= ')')
21476 /* Find the extent of the current argument name. */
21477 const char *arg_start
= p
;
21479 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
21482 if (! *p
|| p
== arg_start
)
21483 dwarf2_macro_malformed_definition_complaint (body
);
21486 /* Make sure argv has room for the new argument. */
21487 if (argc
>= argv_size
)
21490 argv
= XRESIZEVEC (char *, argv
, argv_size
);
21493 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
21496 p
= consume_improper_spaces (p
, body
);
21498 /* Consume the comma, if present. */
21503 p
= consume_improper_spaces (p
, body
);
21512 /* Perfectly formed definition, no complaints. */
21513 macro_define_function (file
, line
, name
,
21514 argc
, (const char **) argv
,
21516 else if (*p
== '\0')
21518 /* Complain, but do define it. */
21519 dwarf2_macro_malformed_definition_complaint (body
);
21520 macro_define_function (file
, line
, name
,
21521 argc
, (const char **) argv
,
21525 /* Just complain. */
21526 dwarf2_macro_malformed_definition_complaint (body
);
21529 /* Just complain. */
21530 dwarf2_macro_malformed_definition_complaint (body
);
21536 for (i
= 0; i
< argc
; i
++)
21542 dwarf2_macro_malformed_definition_complaint (body
);
21545 /* Skip some bytes from BYTES according to the form given in FORM.
21546 Returns the new pointer. */
21548 static const gdb_byte
*
21549 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
21550 enum dwarf_form form
,
21551 unsigned int offset_size
,
21552 struct dwarf2_section_info
*section
)
21554 unsigned int bytes_read
;
21558 case DW_FORM_data1
:
21563 case DW_FORM_data2
:
21567 case DW_FORM_data4
:
21571 case DW_FORM_data8
:
21575 case DW_FORM_string
:
21576 read_direct_string (abfd
, bytes
, &bytes_read
);
21577 bytes
+= bytes_read
;
21580 case DW_FORM_sec_offset
:
21582 case DW_FORM_GNU_strp_alt
:
21583 bytes
+= offset_size
;
21586 case DW_FORM_block
:
21587 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
21588 bytes
+= bytes_read
;
21591 case DW_FORM_block1
:
21592 bytes
+= 1 + read_1_byte (abfd
, bytes
);
21594 case DW_FORM_block2
:
21595 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
21597 case DW_FORM_block4
:
21598 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
21601 case DW_FORM_sdata
:
21602 case DW_FORM_udata
:
21603 case DW_FORM_GNU_addr_index
:
21604 case DW_FORM_GNU_str_index
:
21605 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
21608 dwarf2_section_buffer_overflow_complaint (section
);
21616 complaint (&symfile_complaints
,
21617 _("invalid form 0x%x in `%s'"),
21618 form
, get_section_name (section
));
21626 /* A helper for dwarf_decode_macros that handles skipping an unknown
21627 opcode. Returns an updated pointer to the macro data buffer; or,
21628 on error, issues a complaint and returns NULL. */
21630 static const gdb_byte
*
21631 skip_unknown_opcode (unsigned int opcode
,
21632 const gdb_byte
**opcode_definitions
,
21633 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
21635 unsigned int offset_size
,
21636 struct dwarf2_section_info
*section
)
21638 unsigned int bytes_read
, i
;
21640 const gdb_byte
*defn
;
21642 if (opcode_definitions
[opcode
] == NULL
)
21644 complaint (&symfile_complaints
,
21645 _("unrecognized DW_MACFINO opcode 0x%x"),
21650 defn
= opcode_definitions
[opcode
];
21651 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
21652 defn
+= bytes_read
;
21654 for (i
= 0; i
< arg
; ++i
)
21656 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
21657 (enum dwarf_form
) defn
[i
], offset_size
,
21659 if (mac_ptr
== NULL
)
21661 /* skip_form_bytes already issued the complaint. */
21669 /* A helper function which parses the header of a macro section.
21670 If the macro section is the extended (for now called "GNU") type,
21671 then this updates *OFFSET_SIZE. Returns a pointer to just after
21672 the header, or issues a complaint and returns NULL on error. */
21674 static const gdb_byte
*
21675 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
21677 const gdb_byte
*mac_ptr
,
21678 unsigned int *offset_size
,
21679 int section_is_gnu
)
21681 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
21683 if (section_is_gnu
)
21685 unsigned int version
, flags
;
21687 version
= read_2_bytes (abfd
, mac_ptr
);
21690 complaint (&symfile_complaints
,
21691 _("unrecognized version `%d' in .debug_macro section"),
21697 flags
= read_1_byte (abfd
, mac_ptr
);
21699 *offset_size
= (flags
& 1) ? 8 : 4;
21701 if ((flags
& 2) != 0)
21702 /* We don't need the line table offset. */
21703 mac_ptr
+= *offset_size
;
21705 /* Vendor opcode descriptions. */
21706 if ((flags
& 4) != 0)
21708 unsigned int i
, count
;
21710 count
= read_1_byte (abfd
, mac_ptr
);
21712 for (i
= 0; i
< count
; ++i
)
21714 unsigned int opcode
, bytes_read
;
21717 opcode
= read_1_byte (abfd
, mac_ptr
);
21719 opcode_definitions
[opcode
] = mac_ptr
;
21720 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21721 mac_ptr
+= bytes_read
;
21730 /* A helper for dwarf_decode_macros that handles the GNU extensions,
21731 including DW_MACRO_GNU_transparent_include. */
21734 dwarf_decode_macro_bytes (bfd
*abfd
,
21735 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
21736 struct macro_source_file
*current_file
,
21737 struct line_header
*lh
,
21738 struct dwarf2_section_info
*section
,
21739 int section_is_gnu
, int section_is_dwz
,
21740 unsigned int offset_size
,
21741 htab_t include_hash
)
21743 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21744 enum dwarf_macro_record_type macinfo_type
;
21745 int at_commandline
;
21746 const gdb_byte
*opcode_definitions
[256];
21748 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
21749 &offset_size
, section_is_gnu
);
21750 if (mac_ptr
== NULL
)
21752 /* We already issued a complaint. */
21756 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
21757 GDB is still reading the definitions from command line. First
21758 DW_MACINFO_start_file will need to be ignored as it was already executed
21759 to create CURRENT_FILE for the main source holding also the command line
21760 definitions. On first met DW_MACINFO_start_file this flag is reset to
21761 normally execute all the remaining DW_MACINFO_start_file macinfos. */
21763 at_commandline
= 1;
21767 /* Do we at least have room for a macinfo type byte? */
21768 if (mac_ptr
>= mac_end
)
21770 dwarf2_section_buffer_overflow_complaint (section
);
21774 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
21777 /* Note that we rely on the fact that the corresponding GNU and
21778 DWARF constants are the same. */
21779 switch (macinfo_type
)
21781 /* A zero macinfo type indicates the end of the macro
21786 case DW_MACRO_GNU_define
:
21787 case DW_MACRO_GNU_undef
:
21788 case DW_MACRO_GNU_define_indirect
:
21789 case DW_MACRO_GNU_undef_indirect
:
21790 case DW_MACRO_GNU_define_indirect_alt
:
21791 case DW_MACRO_GNU_undef_indirect_alt
:
21793 unsigned int bytes_read
;
21798 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21799 mac_ptr
+= bytes_read
;
21801 if (macinfo_type
== DW_MACRO_GNU_define
21802 || macinfo_type
== DW_MACRO_GNU_undef
)
21804 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21805 mac_ptr
+= bytes_read
;
21809 LONGEST str_offset
;
21811 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
21812 mac_ptr
+= offset_size
;
21814 if (macinfo_type
== DW_MACRO_GNU_define_indirect_alt
21815 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
21818 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
21820 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
21823 body
= read_indirect_string_at_offset (abfd
, str_offset
);
21826 is_define
= (macinfo_type
== DW_MACRO_GNU_define
21827 || macinfo_type
== DW_MACRO_GNU_define_indirect
21828 || macinfo_type
== DW_MACRO_GNU_define_indirect_alt
);
21829 if (! current_file
)
21831 /* DWARF violation as no main source is present. */
21832 complaint (&symfile_complaints
,
21833 _("debug info with no main source gives macro %s "
21835 is_define
? _("definition") : _("undefinition"),
21839 if ((line
== 0 && !at_commandline
)
21840 || (line
!= 0 && at_commandline
))
21841 complaint (&symfile_complaints
,
21842 _("debug info gives %s macro %s with %s line %d: %s"),
21843 at_commandline
? _("command-line") : _("in-file"),
21844 is_define
? _("definition") : _("undefinition"),
21845 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
21848 parse_macro_definition (current_file
, line
, body
);
21851 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
21852 || macinfo_type
== DW_MACRO_GNU_undef_indirect
21853 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
);
21854 macro_undef (current_file
, line
, body
);
21859 case DW_MACRO_GNU_start_file
:
21861 unsigned int bytes_read
;
21864 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21865 mac_ptr
+= bytes_read
;
21866 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21867 mac_ptr
+= bytes_read
;
21869 if ((line
== 0 && !at_commandline
)
21870 || (line
!= 0 && at_commandline
))
21871 complaint (&symfile_complaints
,
21872 _("debug info gives source %d included "
21873 "from %s at %s line %d"),
21874 file
, at_commandline
? _("command-line") : _("file"),
21875 line
== 0 ? _("zero") : _("non-zero"), line
);
21877 if (at_commandline
)
21879 /* This DW_MACRO_GNU_start_file was executed in the
21881 at_commandline
= 0;
21884 current_file
= macro_start_file (file
, line
, current_file
, lh
);
21888 case DW_MACRO_GNU_end_file
:
21889 if (! current_file
)
21890 complaint (&symfile_complaints
,
21891 _("macro debug info has an unmatched "
21892 "`close_file' directive"));
21895 current_file
= current_file
->included_by
;
21896 if (! current_file
)
21898 enum dwarf_macro_record_type next_type
;
21900 /* GCC circa March 2002 doesn't produce the zero
21901 type byte marking the end of the compilation
21902 unit. Complain if it's not there, but exit no
21905 /* Do we at least have room for a macinfo type byte? */
21906 if (mac_ptr
>= mac_end
)
21908 dwarf2_section_buffer_overflow_complaint (section
);
21912 /* We don't increment mac_ptr here, so this is just
21915 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
21917 if (next_type
!= 0)
21918 complaint (&symfile_complaints
,
21919 _("no terminating 0-type entry for "
21920 "macros in `.debug_macinfo' section"));
21927 case DW_MACRO_GNU_transparent_include
:
21928 case DW_MACRO_GNU_transparent_include_alt
:
21932 bfd
*include_bfd
= abfd
;
21933 struct dwarf2_section_info
*include_section
= section
;
21934 const gdb_byte
*include_mac_end
= mac_end
;
21935 int is_dwz
= section_is_dwz
;
21936 const gdb_byte
*new_mac_ptr
;
21938 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
21939 mac_ptr
+= offset_size
;
21941 if (macinfo_type
== DW_MACRO_GNU_transparent_include_alt
)
21943 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
21945 dwarf2_read_section (objfile
, &dwz
->macro
);
21947 include_section
= &dwz
->macro
;
21948 include_bfd
= get_section_bfd_owner (include_section
);
21949 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
21953 new_mac_ptr
= include_section
->buffer
+ offset
;
21954 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
21958 /* This has actually happened; see
21959 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
21960 complaint (&symfile_complaints
,
21961 _("recursive DW_MACRO_GNU_transparent_include in "
21962 ".debug_macro section"));
21966 *slot
= (void *) new_mac_ptr
;
21968 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
21969 include_mac_end
, current_file
, lh
,
21970 section
, section_is_gnu
, is_dwz
,
21971 offset_size
, include_hash
);
21973 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
21978 case DW_MACINFO_vendor_ext
:
21979 if (!section_is_gnu
)
21981 unsigned int bytes_read
;
21983 /* This reads the constant, but since we don't recognize
21984 any vendor extensions, we ignore it. */
21985 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21986 mac_ptr
+= bytes_read
;
21987 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21988 mac_ptr
+= bytes_read
;
21990 /* We don't recognize any vendor extensions. */
21996 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
21997 mac_ptr
, mac_end
, abfd
, offset_size
,
21999 if (mac_ptr
== NULL
)
22003 } while (macinfo_type
!= 0);
22007 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22008 int section_is_gnu
)
22010 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22011 struct line_header
*lh
= cu
->line_header
;
22013 const gdb_byte
*mac_ptr
, *mac_end
;
22014 struct macro_source_file
*current_file
= 0;
22015 enum dwarf_macro_record_type macinfo_type
;
22016 unsigned int offset_size
= cu
->header
.offset_size
;
22017 const gdb_byte
*opcode_definitions
[256];
22018 struct cleanup
*cleanup
;
22020 struct dwarf2_section_info
*section
;
22021 const char *section_name
;
22023 if (cu
->dwo_unit
!= NULL
)
22025 if (section_is_gnu
)
22027 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22028 section_name
= ".debug_macro.dwo";
22032 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22033 section_name
= ".debug_macinfo.dwo";
22038 if (section_is_gnu
)
22040 section
= &dwarf2_per_objfile
->macro
;
22041 section_name
= ".debug_macro";
22045 section
= &dwarf2_per_objfile
->macinfo
;
22046 section_name
= ".debug_macinfo";
22050 dwarf2_read_section (objfile
, section
);
22051 if (section
->buffer
== NULL
)
22053 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
22056 abfd
= get_section_bfd_owner (section
);
22058 /* First pass: Find the name of the base filename.
22059 This filename is needed in order to process all macros whose definition
22060 (or undefinition) comes from the command line. These macros are defined
22061 before the first DW_MACINFO_start_file entry, and yet still need to be
22062 associated to the base file.
22064 To determine the base file name, we scan the macro definitions until we
22065 reach the first DW_MACINFO_start_file entry. We then initialize
22066 CURRENT_FILE accordingly so that any macro definition found before the
22067 first DW_MACINFO_start_file can still be associated to the base file. */
22069 mac_ptr
= section
->buffer
+ offset
;
22070 mac_end
= section
->buffer
+ section
->size
;
22072 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
22073 &offset_size
, section_is_gnu
);
22074 if (mac_ptr
== NULL
)
22076 /* We already issued a complaint. */
22082 /* Do we at least have room for a macinfo type byte? */
22083 if (mac_ptr
>= mac_end
)
22085 /* Complaint is printed during the second pass as GDB will probably
22086 stop the first pass earlier upon finding
22087 DW_MACINFO_start_file. */
22091 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
22094 /* Note that we rely on the fact that the corresponding GNU and
22095 DWARF constants are the same. */
22096 switch (macinfo_type
)
22098 /* A zero macinfo type indicates the end of the macro
22103 case DW_MACRO_GNU_define
:
22104 case DW_MACRO_GNU_undef
:
22105 /* Only skip the data by MAC_PTR. */
22107 unsigned int bytes_read
;
22109 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22110 mac_ptr
+= bytes_read
;
22111 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22112 mac_ptr
+= bytes_read
;
22116 case DW_MACRO_GNU_start_file
:
22118 unsigned int bytes_read
;
22121 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22122 mac_ptr
+= bytes_read
;
22123 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22124 mac_ptr
+= bytes_read
;
22126 current_file
= macro_start_file (file
, line
, current_file
, lh
);
22130 case DW_MACRO_GNU_end_file
:
22131 /* No data to skip by MAC_PTR. */
22134 case DW_MACRO_GNU_define_indirect
:
22135 case DW_MACRO_GNU_undef_indirect
:
22136 case DW_MACRO_GNU_define_indirect_alt
:
22137 case DW_MACRO_GNU_undef_indirect_alt
:
22139 unsigned int bytes_read
;
22141 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22142 mac_ptr
+= bytes_read
;
22143 mac_ptr
+= offset_size
;
22147 case DW_MACRO_GNU_transparent_include
:
22148 case DW_MACRO_GNU_transparent_include_alt
:
22149 /* Note that, according to the spec, a transparent include
22150 chain cannot call DW_MACRO_GNU_start_file. So, we can just
22151 skip this opcode. */
22152 mac_ptr
+= offset_size
;
22155 case DW_MACINFO_vendor_ext
:
22156 /* Only skip the data by MAC_PTR. */
22157 if (!section_is_gnu
)
22159 unsigned int bytes_read
;
22161 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22162 mac_ptr
+= bytes_read
;
22163 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22164 mac_ptr
+= bytes_read
;
22169 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
22170 mac_ptr
, mac_end
, abfd
, offset_size
,
22172 if (mac_ptr
== NULL
)
22176 } while (macinfo_type
!= 0 && current_file
== NULL
);
22178 /* Second pass: Process all entries.
22180 Use the AT_COMMAND_LINE flag to determine whether we are still processing
22181 command-line macro definitions/undefinitions. This flag is unset when we
22182 reach the first DW_MACINFO_start_file entry. */
22184 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
22186 NULL
, xcalloc
, xfree
));
22187 mac_ptr
= section
->buffer
+ offset
;
22188 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
22189 *slot
= (void *) mac_ptr
;
22190 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
22191 current_file
, lh
, section
,
22192 section_is_gnu
, 0, offset_size
,
22193 include_hash
.get ());
22196 /* Check if the attribute's form is a DW_FORM_block*
22197 if so return true else false. */
22200 attr_form_is_block (const struct attribute
*attr
)
22202 return (attr
== NULL
? 0 :
22203 attr
->form
== DW_FORM_block1
22204 || attr
->form
== DW_FORM_block2
22205 || attr
->form
== DW_FORM_block4
22206 || attr
->form
== DW_FORM_block
22207 || attr
->form
== DW_FORM_exprloc
);
22210 /* Return non-zero if ATTR's value is a section offset --- classes
22211 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
22212 You may use DW_UNSND (attr) to retrieve such offsets.
22214 Section 7.5.4, "Attribute Encodings", explains that no attribute
22215 may have a value that belongs to more than one of these classes; it
22216 would be ambiguous if we did, because we use the same forms for all
22220 attr_form_is_section_offset (const struct attribute
*attr
)
22222 return (attr
->form
== DW_FORM_data4
22223 || attr
->form
== DW_FORM_data8
22224 || attr
->form
== DW_FORM_sec_offset
);
22227 /* Return non-zero if ATTR's value falls in the 'constant' class, or
22228 zero otherwise. When this function returns true, you can apply
22229 dwarf2_get_attr_constant_value to it.
22231 However, note that for some attributes you must check
22232 attr_form_is_section_offset before using this test. DW_FORM_data4
22233 and DW_FORM_data8 are members of both the constant class, and of
22234 the classes that contain offsets into other debug sections
22235 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
22236 that, if an attribute's can be either a constant or one of the
22237 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
22238 taken as section offsets, not constants. */
22241 attr_form_is_constant (const struct attribute
*attr
)
22243 switch (attr
->form
)
22245 case DW_FORM_sdata
:
22246 case DW_FORM_udata
:
22247 case DW_FORM_data1
:
22248 case DW_FORM_data2
:
22249 case DW_FORM_data4
:
22250 case DW_FORM_data8
:
22258 /* DW_ADDR is always stored already as sect_offset; despite for the forms
22259 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
22262 attr_form_is_ref (const struct attribute
*attr
)
22264 switch (attr
->form
)
22266 case DW_FORM_ref_addr
:
22271 case DW_FORM_ref_udata
:
22272 case DW_FORM_GNU_ref_alt
:
22279 /* Return the .debug_loc section to use for CU.
22280 For DWO files use .debug_loc.dwo. */
22282 static struct dwarf2_section_info
*
22283 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22287 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22289 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22291 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22292 : &dwarf2_per_objfile
->loc
);
22295 /* A helper function that fills in a dwarf2_loclist_baton. */
22298 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22299 struct dwarf2_loclist_baton
*baton
,
22300 const struct attribute
*attr
)
22302 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22304 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
22306 baton
->per_cu
= cu
->per_cu
;
22307 gdb_assert (baton
->per_cu
);
22308 /* We don't know how long the location list is, but make sure we
22309 don't run off the edge of the section. */
22310 baton
->size
= section
->size
- DW_UNSND (attr
);
22311 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22312 baton
->base_address
= cu
->base_address
;
22313 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22317 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22318 struct dwarf2_cu
*cu
, int is_block
)
22320 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22321 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22323 if (attr_form_is_section_offset (attr
)
22324 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22325 the section. If so, fall through to the complaint in the
22327 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
22329 struct dwarf2_loclist_baton
*baton
;
22331 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22333 fill_in_loclist_baton (cu
, baton
, attr
);
22335 if (cu
->base_known
== 0)
22336 complaint (&symfile_complaints
,
22337 _("Location list used without "
22338 "specifying the CU base address."));
22340 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22341 ? dwarf2_loclist_block_index
22342 : dwarf2_loclist_index
);
22343 SYMBOL_LOCATION_BATON (sym
) = baton
;
22347 struct dwarf2_locexpr_baton
*baton
;
22349 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22350 baton
->per_cu
= cu
->per_cu
;
22351 gdb_assert (baton
->per_cu
);
22353 if (attr_form_is_block (attr
))
22355 /* Note that we're just copying the block's data pointer
22356 here, not the actual data. We're still pointing into the
22357 info_buffer for SYM's objfile; right now we never release
22358 that buffer, but when we do clean up properly this may
22360 baton
->size
= DW_BLOCK (attr
)->size
;
22361 baton
->data
= DW_BLOCK (attr
)->data
;
22365 dwarf2_invalid_attrib_class_complaint ("location description",
22366 SYMBOL_NATURAL_NAME (sym
));
22370 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22371 ? dwarf2_locexpr_block_index
22372 : dwarf2_locexpr_index
);
22373 SYMBOL_LOCATION_BATON (sym
) = baton
;
22377 /* Return the OBJFILE associated with the compilation unit CU. If CU
22378 came from a separate debuginfo file, then the master objfile is
22382 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
22384 struct objfile
*objfile
= per_cu
->objfile
;
22386 /* Return the master objfile, so that we can report and look up the
22387 correct file containing this variable. */
22388 if (objfile
->separate_debug_objfile_backlink
)
22389 objfile
= objfile
->separate_debug_objfile_backlink
;
22394 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22395 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22396 CU_HEADERP first. */
22398 static const struct comp_unit_head
*
22399 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22400 struct dwarf2_per_cu_data
*per_cu
)
22402 const gdb_byte
*info_ptr
;
22405 return &per_cu
->cu
->header
;
22407 info_ptr
= per_cu
->section
->buffer
+ per_cu
->offset
.sect_off
;
22409 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22410 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22411 rcuh_kind::COMPILE
);
22416 /* Return the address size given in the compilation unit header for CU. */
22419 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
22421 struct comp_unit_head cu_header_local
;
22422 const struct comp_unit_head
*cu_headerp
;
22424 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22426 return cu_headerp
->addr_size
;
22429 /* Return the offset size given in the compilation unit header for CU. */
22432 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
22434 struct comp_unit_head cu_header_local
;
22435 const struct comp_unit_head
*cu_headerp
;
22437 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22439 return cu_headerp
->offset_size
;
22442 /* See its dwarf2loc.h declaration. */
22445 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
22447 struct comp_unit_head cu_header_local
;
22448 const struct comp_unit_head
*cu_headerp
;
22450 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22452 if (cu_headerp
->version
== 2)
22453 return cu_headerp
->addr_size
;
22455 return cu_headerp
->offset_size
;
22458 /* Return the text offset of the CU. The returned offset comes from
22459 this CU's objfile. If this objfile came from a separate debuginfo
22460 file, then the offset may be different from the corresponding
22461 offset in the parent objfile. */
22464 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
22466 struct objfile
*objfile
= per_cu
->objfile
;
22468 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
22471 /* Return DWARF version number of PER_CU. */
22474 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
22476 return per_cu
->dwarf_version
;
22479 /* Locate the .debug_info compilation unit from CU's objfile which contains
22480 the DIE at OFFSET. Raises an error on failure. */
22482 static struct dwarf2_per_cu_data
*
22483 dwarf2_find_containing_comp_unit (sect_offset offset
,
22484 unsigned int offset_in_dwz
,
22485 struct objfile
*objfile
)
22487 struct dwarf2_per_cu_data
*this_cu
;
22489 const sect_offset
*cu_off
;
22492 high
= dwarf2_per_objfile
->n_comp_units
- 1;
22495 struct dwarf2_per_cu_data
*mid_cu
;
22496 int mid
= low
+ (high
- low
) / 2;
22498 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
22499 cu_off
= &mid_cu
->offset
;
22500 if (mid_cu
->is_dwz
> offset_in_dwz
22501 || (mid_cu
->is_dwz
== offset_in_dwz
22502 && cu_off
->sect_off
>= offset
.sect_off
))
22507 gdb_assert (low
== high
);
22508 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
22509 cu_off
= &this_cu
->offset
;
22510 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
22512 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
22513 error (_("Dwarf Error: could not find partial DIE containing "
22514 "offset 0x%lx [in module %s]"),
22515 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
22517 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
22518 <= offset
.sect_off
);
22519 return dwarf2_per_objfile
->all_comp_units
[low
-1];
22523 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
22524 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
22525 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
22526 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
22527 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
22532 /* Initialize dwarf2_cu CU, owned by PER_CU. */
22535 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
22537 memset (cu
, 0, sizeof (*cu
));
22539 cu
->per_cu
= per_cu
;
22540 cu
->objfile
= per_cu
->objfile
;
22541 obstack_init (&cu
->comp_unit_obstack
);
22544 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
22547 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
22548 enum language pretend_language
)
22550 struct attribute
*attr
;
22552 /* Set the language we're debugging. */
22553 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
22555 set_cu_language (DW_UNSND (attr
), cu
);
22558 cu
->language
= pretend_language
;
22559 cu
->language_defn
= language_def (cu
->language
);
22562 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
22565 /* Release one cached compilation unit, CU. We unlink it from the tree
22566 of compilation units, but we don't remove it from the read_in_chain;
22567 the caller is responsible for that.
22568 NOTE: DATA is a void * because this function is also used as a
22569 cleanup routine. */
22572 free_heap_comp_unit (void *data
)
22574 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
22576 gdb_assert (cu
->per_cu
!= NULL
);
22577 cu
->per_cu
->cu
= NULL
;
22580 obstack_free (&cu
->comp_unit_obstack
, NULL
);
22585 /* This cleanup function is passed the address of a dwarf2_cu on the stack
22586 when we're finished with it. We can't free the pointer itself, but be
22587 sure to unlink it from the cache. Also release any associated storage. */
22590 free_stack_comp_unit (void *data
)
22592 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
22594 gdb_assert (cu
->per_cu
!= NULL
);
22595 cu
->per_cu
->cu
= NULL
;
22598 obstack_free (&cu
->comp_unit_obstack
, NULL
);
22599 cu
->partial_dies
= NULL
;
22602 /* Free all cached compilation units. */
22605 free_cached_comp_units (void *data
)
22607 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22609 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22610 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22611 while (per_cu
!= NULL
)
22613 struct dwarf2_per_cu_data
*next_cu
;
22615 next_cu
= per_cu
->cu
->read_in_chain
;
22617 free_heap_comp_unit (per_cu
->cu
);
22618 *last_chain
= next_cu
;
22624 /* Increase the age counter on each cached compilation unit, and free
22625 any that are too old. */
22628 age_cached_comp_units (void)
22630 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22632 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
22633 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22634 while (per_cu
!= NULL
)
22636 per_cu
->cu
->last_used
++;
22637 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
22638 dwarf2_mark (per_cu
->cu
);
22639 per_cu
= per_cu
->cu
->read_in_chain
;
22642 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22643 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22644 while (per_cu
!= NULL
)
22646 struct dwarf2_per_cu_data
*next_cu
;
22648 next_cu
= per_cu
->cu
->read_in_chain
;
22650 if (!per_cu
->cu
->mark
)
22652 free_heap_comp_unit (per_cu
->cu
);
22653 *last_chain
= next_cu
;
22656 last_chain
= &per_cu
->cu
->read_in_chain
;
22662 /* Remove a single compilation unit from the cache. */
22665 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
22667 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22669 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22670 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22671 while (per_cu
!= NULL
)
22673 struct dwarf2_per_cu_data
*next_cu
;
22675 next_cu
= per_cu
->cu
->read_in_chain
;
22677 if (per_cu
== target_per_cu
)
22679 free_heap_comp_unit (per_cu
->cu
);
22681 *last_chain
= next_cu
;
22685 last_chain
= &per_cu
->cu
->read_in_chain
;
22691 /* Release all extra memory associated with OBJFILE. */
22694 dwarf2_free_objfile (struct objfile
*objfile
)
22697 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
22698 dwarf2_objfile_data_key
);
22700 if (dwarf2_per_objfile
== NULL
)
22703 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
22704 free_cached_comp_units (NULL
);
22706 if (dwarf2_per_objfile
->quick_file_names_table
)
22707 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
22709 if (dwarf2_per_objfile
->line_header_hash
)
22710 htab_delete (dwarf2_per_objfile
->line_header_hash
);
22712 /* Everything else should be on the objfile obstack. */
22715 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
22716 We store these in a hash table separate from the DIEs, and preserve them
22717 when the DIEs are flushed out of cache.
22719 The CU "per_cu" pointer is needed because offset alone is not enough to
22720 uniquely identify the type. A file may have multiple .debug_types sections,
22721 or the type may come from a DWO file. Furthermore, while it's more logical
22722 to use per_cu->section+offset, with Fission the section with the data is in
22723 the DWO file but we don't know that section at the point we need it.
22724 We have to use something in dwarf2_per_cu_data (or the pointer to it)
22725 because we can enter the lookup routine, get_die_type_at_offset, from
22726 outside this file, and thus won't necessarily have PER_CU->cu.
22727 Fortunately, PER_CU is stable for the life of the objfile. */
22729 struct dwarf2_per_cu_offset_and_type
22731 const struct dwarf2_per_cu_data
*per_cu
;
22732 sect_offset offset
;
22736 /* Hash function for a dwarf2_per_cu_offset_and_type. */
22739 per_cu_offset_and_type_hash (const void *item
)
22741 const struct dwarf2_per_cu_offset_and_type
*ofs
22742 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
22744 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
22747 /* Equality function for a dwarf2_per_cu_offset_and_type. */
22750 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
22752 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
22753 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
22754 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
22755 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
22757 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
22758 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
22761 /* Set the type associated with DIE to TYPE. Save it in CU's hash
22762 table if necessary. For convenience, return TYPE.
22764 The DIEs reading must have careful ordering to:
22765 * Not cause infite loops trying to read in DIEs as a prerequisite for
22766 reading current DIE.
22767 * Not trying to dereference contents of still incompletely read in types
22768 while reading in other DIEs.
22769 * Enable referencing still incompletely read in types just by a pointer to
22770 the type without accessing its fields.
22772 Therefore caller should follow these rules:
22773 * Try to fetch any prerequisite types we may need to build this DIE type
22774 before building the type and calling set_die_type.
22775 * After building type call set_die_type for current DIE as soon as
22776 possible before fetching more types to complete the current type.
22777 * Make the type as complete as possible before fetching more types. */
22779 static struct type
*
22780 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
22782 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
22783 struct objfile
*objfile
= cu
->objfile
;
22784 struct attribute
*attr
;
22785 struct dynamic_prop prop
;
22787 /* For Ada types, make sure that the gnat-specific data is always
22788 initialized (if not already set). There are a few types where
22789 we should not be doing so, because the type-specific area is
22790 already used to hold some other piece of info (eg: TYPE_CODE_FLT
22791 where the type-specific area is used to store the floatformat).
22792 But this is not a problem, because the gnat-specific information
22793 is actually not needed for these types. */
22794 if (need_gnat_info (cu
)
22795 && TYPE_CODE (type
) != TYPE_CODE_FUNC
22796 && TYPE_CODE (type
) != TYPE_CODE_FLT
22797 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
22798 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
22799 && TYPE_CODE (type
) != TYPE_CODE_METHOD
22800 && !HAVE_GNAT_AUX_INFO (type
))
22801 INIT_GNAT_SPECIFIC (type
);
22803 /* Read DW_AT_allocated and set in type. */
22804 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
22805 if (attr_form_is_block (attr
))
22807 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22808 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
, objfile
);
22810 else if (attr
!= NULL
)
22812 complaint (&symfile_complaints
,
22813 _("DW_AT_allocated has the wrong form (%s) at DIE 0x%x"),
22814 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
22815 die
->offset
.sect_off
);
22818 /* Read DW_AT_associated and set in type. */
22819 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
22820 if (attr_form_is_block (attr
))
22822 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22823 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
, objfile
);
22825 else if (attr
!= NULL
)
22827 complaint (&symfile_complaints
,
22828 _("DW_AT_associated has the wrong form (%s) at DIE 0x%x"),
22829 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
22830 die
->offset
.sect_off
);
22833 /* Read DW_AT_data_location and set in type. */
22834 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
22835 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22836 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
, objfile
);
22838 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
22840 dwarf2_per_objfile
->die_type_hash
=
22841 htab_create_alloc_ex (127,
22842 per_cu_offset_and_type_hash
,
22843 per_cu_offset_and_type_eq
,
22845 &objfile
->objfile_obstack
,
22846 hashtab_obstack_allocate
,
22847 dummy_obstack_deallocate
);
22850 ofs
.per_cu
= cu
->per_cu
;
22851 ofs
.offset
= die
->offset
;
22853 slot
= (struct dwarf2_per_cu_offset_and_type
**)
22854 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
22856 complaint (&symfile_complaints
,
22857 _("A problem internal to GDB: DIE 0x%x has type already set"),
22858 die
->offset
.sect_off
);
22859 *slot
= XOBNEW (&objfile
->objfile_obstack
,
22860 struct dwarf2_per_cu_offset_and_type
);
22865 /* Look up the type for the die at OFFSET in PER_CU in die_type_hash,
22866 or return NULL if the die does not have a saved type. */
22868 static struct type
*
22869 get_die_type_at_offset (sect_offset offset
,
22870 struct dwarf2_per_cu_data
*per_cu
)
22872 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
22874 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
22877 ofs
.per_cu
= per_cu
;
22878 ofs
.offset
= offset
;
22879 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
22880 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
22887 /* Look up the type for DIE in CU in die_type_hash,
22888 or return NULL if DIE does not have a saved type. */
22890 static struct type
*
22891 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22893 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
22896 /* Add a dependence relationship from CU to REF_PER_CU. */
22899 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
22900 struct dwarf2_per_cu_data
*ref_per_cu
)
22904 if (cu
->dependencies
== NULL
)
22906 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
22907 NULL
, &cu
->comp_unit_obstack
,
22908 hashtab_obstack_allocate
,
22909 dummy_obstack_deallocate
);
22911 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
22913 *slot
= ref_per_cu
;
22916 /* Subroutine of dwarf2_mark to pass to htab_traverse.
22917 Set the mark field in every compilation unit in the
22918 cache that we must keep because we are keeping CU. */
22921 dwarf2_mark_helper (void **slot
, void *data
)
22923 struct dwarf2_per_cu_data
*per_cu
;
22925 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
22927 /* cu->dependencies references may not yet have been ever read if QUIT aborts
22928 reading of the chain. As such dependencies remain valid it is not much
22929 useful to track and undo them during QUIT cleanups. */
22930 if (per_cu
->cu
== NULL
)
22933 if (per_cu
->cu
->mark
)
22935 per_cu
->cu
->mark
= 1;
22937 if (per_cu
->cu
->dependencies
!= NULL
)
22938 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
22943 /* Set the mark field in CU and in every other compilation unit in the
22944 cache that we must keep because we are keeping CU. */
22947 dwarf2_mark (struct dwarf2_cu
*cu
)
22952 if (cu
->dependencies
!= NULL
)
22953 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
22957 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
22961 per_cu
->cu
->mark
= 0;
22962 per_cu
= per_cu
->cu
->read_in_chain
;
22966 /* Trivial hash function for partial_die_info: the hash value of a DIE
22967 is its offset in .debug_info for this objfile. */
22970 partial_die_hash (const void *item
)
22972 const struct partial_die_info
*part_die
22973 = (const struct partial_die_info
*) item
;
22975 return part_die
->offset
.sect_off
;
22978 /* Trivial comparison function for partial_die_info structures: two DIEs
22979 are equal if they have the same offset. */
22982 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
22984 const struct partial_die_info
*part_die_lhs
22985 = (const struct partial_die_info
*) item_lhs
;
22986 const struct partial_die_info
*part_die_rhs
22987 = (const struct partial_die_info
*) item_rhs
;
22989 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
22992 static struct cmd_list_element
*set_dwarf_cmdlist
;
22993 static struct cmd_list_element
*show_dwarf_cmdlist
;
22996 set_dwarf_cmd (char *args
, int from_tty
)
22998 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23003 show_dwarf_cmd (char *args
, int from_tty
)
23005 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23008 /* Free data associated with OBJFILE, if necessary. */
23011 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
23013 struct dwarf2_per_objfile
*data
= (struct dwarf2_per_objfile
*) d
;
23016 /* Make sure we don't accidentally use dwarf2_per_objfile while
23018 dwarf2_per_objfile
= NULL
;
23020 for (ix
= 0; ix
< data
->n_comp_units
; ++ix
)
23021 VEC_free (dwarf2_per_cu_ptr
, data
->all_comp_units
[ix
]->imported_symtabs
);
23023 for (ix
= 0; ix
< data
->n_type_units
; ++ix
)
23024 VEC_free (dwarf2_per_cu_ptr
,
23025 data
->all_type_units
[ix
]->per_cu
.imported_symtabs
);
23026 xfree (data
->all_type_units
);
23028 VEC_free (dwarf2_section_info_def
, data
->types
);
23030 if (data
->dwo_files
)
23031 free_dwo_files (data
->dwo_files
, objfile
);
23032 if (data
->dwp_file
)
23033 gdb_bfd_unref (data
->dwp_file
->dbfd
);
23035 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
23036 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
23040 /* The "save gdb-index" command. */
23042 /* The contents of the hash table we create when building the string
23044 struct strtab_entry
23046 offset_type offset
;
23050 /* Hash function for a strtab_entry.
23052 Function is used only during write_hash_table so no index format backward
23053 compatibility is needed. */
23056 hash_strtab_entry (const void *e
)
23058 const struct strtab_entry
*entry
= (const struct strtab_entry
*) e
;
23059 return mapped_index_string_hash (INT_MAX
, entry
->str
);
23062 /* Equality function for a strtab_entry. */
23065 eq_strtab_entry (const void *a
, const void *b
)
23067 const struct strtab_entry
*ea
= (const struct strtab_entry
*) a
;
23068 const struct strtab_entry
*eb
= (const struct strtab_entry
*) b
;
23069 return !strcmp (ea
->str
, eb
->str
);
23072 /* Create a strtab_entry hash table. */
23075 create_strtab (void)
23077 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
23078 xfree
, xcalloc
, xfree
);
23081 /* Add a string to the constant pool. Return the string's offset in
23085 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
23088 struct strtab_entry entry
;
23089 struct strtab_entry
*result
;
23092 slot
= htab_find_slot (table
, &entry
, INSERT
);
23094 result
= (struct strtab_entry
*) *slot
;
23097 result
= XNEW (struct strtab_entry
);
23098 result
->offset
= obstack_object_size (cpool
);
23100 obstack_grow_str0 (cpool
, str
);
23103 return result
->offset
;
23106 /* An entry in the symbol table. */
23107 struct symtab_index_entry
23109 /* The name of the symbol. */
23111 /* The offset of the name in the constant pool. */
23112 offset_type index_offset
;
23113 /* A sorted vector of the indices of all the CUs that hold an object
23115 VEC (offset_type
) *cu_indices
;
23118 /* The symbol table. This is a power-of-2-sized hash table. */
23119 struct mapped_symtab
23121 offset_type n_elements
;
23123 struct symtab_index_entry
**data
;
23126 /* Hash function for a symtab_index_entry. */
23129 hash_symtab_entry (const void *e
)
23131 const struct symtab_index_entry
*entry
23132 = (const struct symtab_index_entry
*) e
;
23133 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
23134 sizeof (offset_type
) * VEC_length (offset_type
,
23135 entry
->cu_indices
),
23139 /* Equality function for a symtab_index_entry. */
23142 eq_symtab_entry (const void *a
, const void *b
)
23144 const struct symtab_index_entry
*ea
= (const struct symtab_index_entry
*) a
;
23145 const struct symtab_index_entry
*eb
= (const struct symtab_index_entry
*) b
;
23146 int len
= VEC_length (offset_type
, ea
->cu_indices
);
23147 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
23149 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
23150 VEC_address (offset_type
, eb
->cu_indices
),
23151 sizeof (offset_type
) * len
);
23154 /* Destroy a symtab_index_entry. */
23157 delete_symtab_entry (void *p
)
23159 struct symtab_index_entry
*entry
= (struct symtab_index_entry
*) p
;
23160 VEC_free (offset_type
, entry
->cu_indices
);
23164 /* Create a hash table holding symtab_index_entry objects. */
23167 create_symbol_hash_table (void)
23169 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
23170 delete_symtab_entry
, xcalloc
, xfree
);
23173 /* Create a new mapped symtab object. */
23175 static struct mapped_symtab
*
23176 create_mapped_symtab (void)
23178 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
23179 symtab
->n_elements
= 0;
23180 symtab
->size
= 1024;
23181 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
23185 /* Destroy a mapped_symtab. */
23188 cleanup_mapped_symtab (void *p
)
23190 struct mapped_symtab
*symtab
= (struct mapped_symtab
*) p
;
23191 /* The contents of the array are freed when the other hash table is
23193 xfree (symtab
->data
);
23197 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
23200 Function is used only during write_hash_table so no index format backward
23201 compatibility is needed. */
23203 static struct symtab_index_entry
**
23204 find_slot (struct mapped_symtab
*symtab
, const char *name
)
23206 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
23208 index
= hash
& (symtab
->size
- 1);
23209 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
23213 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
23214 return &symtab
->data
[index
];
23215 index
= (index
+ step
) & (symtab
->size
- 1);
23219 /* Expand SYMTAB's hash table. */
23222 hash_expand (struct mapped_symtab
*symtab
)
23224 offset_type old_size
= symtab
->size
;
23226 struct symtab_index_entry
**old_entries
= symtab
->data
;
23229 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
23231 for (i
= 0; i
< old_size
; ++i
)
23233 if (old_entries
[i
])
23235 struct symtab_index_entry
**slot
= find_slot (symtab
,
23236 old_entries
[i
]->name
);
23237 *slot
= old_entries
[i
];
23241 xfree (old_entries
);
23244 /* Add an entry to SYMTAB. NAME is the name of the symbol.
23245 CU_INDEX is the index of the CU in which the symbol appears.
23246 IS_STATIC is one if the symbol is static, otherwise zero (global). */
23249 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
23250 int is_static
, gdb_index_symbol_kind kind
,
23251 offset_type cu_index
)
23253 struct symtab_index_entry
**slot
;
23254 offset_type cu_index_and_attrs
;
23256 ++symtab
->n_elements
;
23257 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
23258 hash_expand (symtab
);
23260 slot
= find_slot (symtab
, name
);
23263 *slot
= XNEW (struct symtab_index_entry
);
23264 (*slot
)->name
= name
;
23265 /* index_offset is set later. */
23266 (*slot
)->cu_indices
= NULL
;
23269 cu_index_and_attrs
= 0;
23270 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
23271 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
23272 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
23274 /* We don't want to record an index value twice as we want to avoid the
23276 We process all global symbols and then all static symbols
23277 (which would allow us to avoid the duplication by only having to check
23278 the last entry pushed), but a symbol could have multiple kinds in one CU.
23279 To keep things simple we don't worry about the duplication here and
23280 sort and uniqufy the list after we've processed all symbols. */
23281 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
23284 /* qsort helper routine for uniquify_cu_indices. */
23287 offset_type_compare (const void *ap
, const void *bp
)
23289 offset_type a
= *(offset_type
*) ap
;
23290 offset_type b
= *(offset_type
*) bp
;
23292 return (a
> b
) - (b
> a
);
23295 /* Sort and remove duplicates of all symbols' cu_indices lists. */
23298 uniquify_cu_indices (struct mapped_symtab
*symtab
)
23302 for (i
= 0; i
< symtab
->size
; ++i
)
23304 struct symtab_index_entry
*entry
= symtab
->data
[i
];
23307 && entry
->cu_indices
!= NULL
)
23309 unsigned int next_to_insert
, next_to_check
;
23310 offset_type last_value
;
23312 qsort (VEC_address (offset_type
, entry
->cu_indices
),
23313 VEC_length (offset_type
, entry
->cu_indices
),
23314 sizeof (offset_type
), offset_type_compare
);
23316 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
23317 next_to_insert
= 1;
23318 for (next_to_check
= 1;
23319 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
23322 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
23325 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
23327 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
23332 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
23337 /* Add a vector of indices to the constant pool. */
23340 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
23341 struct symtab_index_entry
*entry
)
23345 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
23348 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
23349 offset_type val
= MAYBE_SWAP (len
);
23354 entry
->index_offset
= obstack_object_size (cpool
);
23356 obstack_grow (cpool
, &val
, sizeof (val
));
23358 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
23361 val
= MAYBE_SWAP (iter
);
23362 obstack_grow (cpool
, &val
, sizeof (val
));
23367 struct symtab_index_entry
*old_entry
23368 = (struct symtab_index_entry
*) *slot
;
23369 entry
->index_offset
= old_entry
->index_offset
;
23372 return entry
->index_offset
;
23375 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
23376 constant pool entries going into the obstack CPOOL. */
23379 write_hash_table (struct mapped_symtab
*symtab
,
23380 struct obstack
*output
, struct obstack
*cpool
)
23383 htab_t symbol_hash_table
;
23386 symbol_hash_table
= create_symbol_hash_table ();
23387 str_table
= create_strtab ();
23389 /* We add all the index vectors to the constant pool first, to
23390 ensure alignment is ok. */
23391 for (i
= 0; i
< symtab
->size
; ++i
)
23393 if (symtab
->data
[i
])
23394 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
23397 /* Now write out the hash table. */
23398 for (i
= 0; i
< symtab
->size
; ++i
)
23400 offset_type str_off
, vec_off
;
23402 if (symtab
->data
[i
])
23404 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
23405 vec_off
= symtab
->data
[i
]->index_offset
;
23409 /* While 0 is a valid constant pool index, it is not valid
23410 to have 0 for both offsets. */
23415 str_off
= MAYBE_SWAP (str_off
);
23416 vec_off
= MAYBE_SWAP (vec_off
);
23418 obstack_grow (output
, &str_off
, sizeof (str_off
));
23419 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
23422 htab_delete (str_table
);
23423 htab_delete (symbol_hash_table
);
23426 /* Struct to map psymtab to CU index in the index file. */
23427 struct psymtab_cu_index_map
23429 struct partial_symtab
*psymtab
;
23430 unsigned int cu_index
;
23434 hash_psymtab_cu_index (const void *item
)
23436 const struct psymtab_cu_index_map
*map
23437 = (const struct psymtab_cu_index_map
*) item
;
23439 return htab_hash_pointer (map
->psymtab
);
23443 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
23445 const struct psymtab_cu_index_map
*lhs
23446 = (const struct psymtab_cu_index_map
*) item_lhs
;
23447 const struct psymtab_cu_index_map
*rhs
23448 = (const struct psymtab_cu_index_map
*) item_rhs
;
23450 return lhs
->psymtab
== rhs
->psymtab
;
23453 /* Helper struct for building the address table. */
23454 struct addrmap_index_data
23456 struct objfile
*objfile
;
23457 struct obstack
*addr_obstack
;
23458 htab_t cu_index_htab
;
23460 /* Non-zero if the previous_* fields are valid.
23461 We can't write an entry until we see the next entry (since it is only then
23462 that we know the end of the entry). */
23463 int previous_valid
;
23464 /* Index of the CU in the table of all CUs in the index file. */
23465 unsigned int previous_cu_index
;
23466 /* Start address of the CU. */
23467 CORE_ADDR previous_cu_start
;
23470 /* Write an address entry to OBSTACK. */
23473 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
23474 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
23476 offset_type cu_index_to_write
;
23478 CORE_ADDR baseaddr
;
23480 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23482 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
23483 obstack_grow (obstack
, addr
, 8);
23484 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
23485 obstack_grow (obstack
, addr
, 8);
23486 cu_index_to_write
= MAYBE_SWAP (cu_index
);
23487 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
23490 /* Worker function for traversing an addrmap to build the address table. */
23493 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
23495 struct addrmap_index_data
*data
= (struct addrmap_index_data
*) datap
;
23496 struct partial_symtab
*pst
= (struct partial_symtab
*) obj
;
23498 if (data
->previous_valid
)
23499 add_address_entry (data
->objfile
, data
->addr_obstack
,
23500 data
->previous_cu_start
, start_addr
,
23501 data
->previous_cu_index
);
23503 data
->previous_cu_start
= start_addr
;
23506 struct psymtab_cu_index_map find_map
, *map
;
23507 find_map
.psymtab
= pst
;
23508 map
= ((struct psymtab_cu_index_map
*)
23509 htab_find (data
->cu_index_htab
, &find_map
));
23510 gdb_assert (map
!= NULL
);
23511 data
->previous_cu_index
= map
->cu_index
;
23512 data
->previous_valid
= 1;
23515 data
->previous_valid
= 0;
23520 /* Write OBJFILE's address map to OBSTACK.
23521 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
23522 in the index file. */
23525 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
23526 htab_t cu_index_htab
)
23528 struct addrmap_index_data addrmap_index_data
;
23530 /* When writing the address table, we have to cope with the fact that
23531 the addrmap iterator only provides the start of a region; we have to
23532 wait until the next invocation to get the start of the next region. */
23534 addrmap_index_data
.objfile
= objfile
;
23535 addrmap_index_data
.addr_obstack
= obstack
;
23536 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
23537 addrmap_index_data
.previous_valid
= 0;
23539 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
23540 &addrmap_index_data
);
23542 /* It's highly unlikely the last entry (end address = 0xff...ff)
23543 is valid, but we should still handle it.
23544 The end address is recorded as the start of the next region, but that
23545 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
23547 if (addrmap_index_data
.previous_valid
)
23548 add_address_entry (objfile
, obstack
,
23549 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
23550 addrmap_index_data
.previous_cu_index
);
23553 /* Return the symbol kind of PSYM. */
23555 static gdb_index_symbol_kind
23556 symbol_kind (struct partial_symbol
*psym
)
23558 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
23559 enum address_class aclass
= PSYMBOL_CLASS (psym
);
23567 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
23569 return GDB_INDEX_SYMBOL_KIND_TYPE
;
23571 case LOC_CONST_BYTES
:
23572 case LOC_OPTIMIZED_OUT
:
23574 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
23576 /* Note: It's currently impossible to recognize psyms as enum values
23577 short of reading the type info. For now punt. */
23578 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
23580 /* There are other LOC_FOO values that one might want to classify
23581 as variables, but dwarf2read.c doesn't currently use them. */
23582 return GDB_INDEX_SYMBOL_KIND_OTHER
;
23584 case STRUCT_DOMAIN
:
23585 return GDB_INDEX_SYMBOL_KIND_TYPE
;
23587 return GDB_INDEX_SYMBOL_KIND_OTHER
;
23591 /* Add a list of partial symbols to SYMTAB. */
23594 write_psymbols (struct mapped_symtab
*symtab
,
23596 struct partial_symbol
**psymp
,
23598 offset_type cu_index
,
23601 for (; count
-- > 0; ++psymp
)
23603 struct partial_symbol
*psym
= *psymp
;
23606 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
23607 error (_("Ada is not currently supported by the index"));
23609 /* Only add a given psymbol once. */
23610 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
23613 gdb_index_symbol_kind kind
= symbol_kind (psym
);
23616 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
23617 is_static
, kind
, cu_index
);
23622 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
23623 exception if there is an error. */
23626 write_obstack (FILE *file
, struct obstack
*obstack
)
23628 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
23630 != obstack_object_size (obstack
))
23631 error (_("couldn't data write to file"));
23634 /* A helper struct used when iterating over debug_types. */
23635 struct signatured_type_index_data
23637 struct objfile
*objfile
;
23638 struct mapped_symtab
*symtab
;
23639 struct obstack
*types_list
;
23644 /* A helper function that writes a single signatured_type to an
23648 write_one_signatured_type (void **slot
, void *d
)
23650 struct signatured_type_index_data
*info
23651 = (struct signatured_type_index_data
*) d
;
23652 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
23653 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
23656 write_psymbols (info
->symtab
,
23658 info
->objfile
->global_psymbols
.list
23659 + psymtab
->globals_offset
,
23660 psymtab
->n_global_syms
, info
->cu_index
,
23662 write_psymbols (info
->symtab
,
23664 info
->objfile
->static_psymbols
.list
23665 + psymtab
->statics_offset
,
23666 psymtab
->n_static_syms
, info
->cu_index
,
23669 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23670 entry
->per_cu
.offset
.sect_off
);
23671 obstack_grow (info
->types_list
, val
, 8);
23672 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23673 entry
->type_offset_in_tu
.cu_off
);
23674 obstack_grow (info
->types_list
, val
, 8);
23675 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
23676 obstack_grow (info
->types_list
, val
, 8);
23683 /* Recurse into all "included" dependencies and write their symbols as
23684 if they appeared in this psymtab. */
23687 recursively_write_psymbols (struct objfile
*objfile
,
23688 struct partial_symtab
*psymtab
,
23689 struct mapped_symtab
*symtab
,
23691 offset_type cu_index
)
23695 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
23696 if (psymtab
->dependencies
[i
]->user
!= NULL
)
23697 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
23698 symtab
, psyms_seen
, cu_index
);
23700 write_psymbols (symtab
,
23702 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
23703 psymtab
->n_global_syms
, cu_index
,
23705 write_psymbols (symtab
,
23707 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
23708 psymtab
->n_static_syms
, cu_index
,
23712 /* Create an index file for OBJFILE in the directory DIR. */
23715 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
23717 struct cleanup
*cleanup
;
23719 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
23720 struct obstack cu_list
, types_cu_list
;
23723 struct mapped_symtab
*symtab
;
23724 offset_type val
, size_of_contents
, total_len
;
23726 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
23728 if (dwarf2_per_objfile
->using_index
)
23729 error (_("Cannot use an index to create the index"));
23731 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
23732 error (_("Cannot make an index when the file has multiple .debug_types sections"));
23734 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
23737 if (stat (objfile_name (objfile
), &st
) < 0)
23738 perror_with_name (objfile_name (objfile
));
23740 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile_name (objfile
)),
23741 INDEX_SUFFIX
, (char *) NULL
);
23742 cleanup
= make_cleanup (xfree
, filename
);
23744 out_file
= gdb_fopen_cloexec (filename
, "wb");
23746 error (_("Can't open `%s' for writing"), filename
);
23748 gdb::unlinker
unlink_file (filename
);
23750 symtab
= create_mapped_symtab ();
23751 make_cleanup (cleanup_mapped_symtab
, symtab
);
23753 obstack_init (&addr_obstack
);
23754 make_cleanup_obstack_free (&addr_obstack
);
23756 obstack_init (&cu_list
);
23757 make_cleanup_obstack_free (&cu_list
);
23759 obstack_init (&types_cu_list
);
23760 make_cleanup_obstack_free (&types_cu_list
);
23762 htab_up
psyms_seen (htab_create_alloc (100, htab_hash_pointer
,
23764 NULL
, xcalloc
, xfree
));
23766 /* While we're scanning CU's create a table that maps a psymtab pointer
23767 (which is what addrmap records) to its index (which is what is recorded
23768 in the index file). This will later be needed to write the address
23770 htab_up
cu_index_htab (htab_create_alloc (100,
23771 hash_psymtab_cu_index
,
23772 eq_psymtab_cu_index
,
23773 NULL
, xcalloc
, xfree
));
23774 psymtab_cu_index_map
= XNEWVEC (struct psymtab_cu_index_map
,
23775 dwarf2_per_objfile
->n_comp_units
);
23776 make_cleanup (xfree
, psymtab_cu_index_map
);
23778 /* The CU list is already sorted, so we don't need to do additional
23779 work here. Also, the debug_types entries do not appear in
23780 all_comp_units, but only in their own hash table. */
23781 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
23783 struct dwarf2_per_cu_data
*per_cu
23784 = dwarf2_per_objfile
->all_comp_units
[i
];
23785 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
23787 struct psymtab_cu_index_map
*map
;
23790 /* CU of a shared file from 'dwz -m' may be unused by this main file.
23791 It may be referenced from a local scope but in such case it does not
23792 need to be present in .gdb_index. */
23793 if (psymtab
== NULL
)
23796 if (psymtab
->user
== NULL
)
23797 recursively_write_psymbols (objfile
, psymtab
, symtab
,
23798 psyms_seen
.get (), i
);
23800 map
= &psymtab_cu_index_map
[i
];
23801 map
->psymtab
= psymtab
;
23803 slot
= htab_find_slot (cu_index_htab
.get (), map
, INSERT
);
23804 gdb_assert (slot
!= NULL
);
23805 gdb_assert (*slot
== NULL
);
23808 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23809 per_cu
->offset
.sect_off
);
23810 obstack_grow (&cu_list
, val
, 8);
23811 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
23812 obstack_grow (&cu_list
, val
, 8);
23815 /* Dump the address map. */
23816 write_address_map (objfile
, &addr_obstack
, cu_index_htab
.get ());
23818 /* Write out the .debug_type entries, if any. */
23819 if (dwarf2_per_objfile
->signatured_types
)
23821 struct signatured_type_index_data sig_data
;
23823 sig_data
.objfile
= objfile
;
23824 sig_data
.symtab
= symtab
;
23825 sig_data
.types_list
= &types_cu_list
;
23826 sig_data
.psyms_seen
= psyms_seen
.get ();
23827 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
23828 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
23829 write_one_signatured_type
, &sig_data
);
23832 /* Now that we've processed all symbols we can shrink their cu_indices
23834 uniquify_cu_indices (symtab
);
23836 obstack_init (&constant_pool
);
23837 make_cleanup_obstack_free (&constant_pool
);
23838 obstack_init (&symtab_obstack
);
23839 make_cleanup_obstack_free (&symtab_obstack
);
23840 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
23842 obstack_init (&contents
);
23843 make_cleanup_obstack_free (&contents
);
23844 size_of_contents
= 6 * sizeof (offset_type
);
23845 total_len
= size_of_contents
;
23847 /* The version number. */
23848 val
= MAYBE_SWAP (8);
23849 obstack_grow (&contents
, &val
, sizeof (val
));
23851 /* The offset of the CU list from the start of the file. */
23852 val
= MAYBE_SWAP (total_len
);
23853 obstack_grow (&contents
, &val
, sizeof (val
));
23854 total_len
+= obstack_object_size (&cu_list
);
23856 /* The offset of the types CU list from the start of the file. */
23857 val
= MAYBE_SWAP (total_len
);
23858 obstack_grow (&contents
, &val
, sizeof (val
));
23859 total_len
+= obstack_object_size (&types_cu_list
);
23861 /* The offset of the address table from the start of the file. */
23862 val
= MAYBE_SWAP (total_len
);
23863 obstack_grow (&contents
, &val
, sizeof (val
));
23864 total_len
+= obstack_object_size (&addr_obstack
);
23866 /* The offset of the symbol table from the start of the file. */
23867 val
= MAYBE_SWAP (total_len
);
23868 obstack_grow (&contents
, &val
, sizeof (val
));
23869 total_len
+= obstack_object_size (&symtab_obstack
);
23871 /* The offset of the constant pool from the start of the file. */
23872 val
= MAYBE_SWAP (total_len
);
23873 obstack_grow (&contents
, &val
, sizeof (val
));
23874 total_len
+= obstack_object_size (&constant_pool
);
23876 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
23878 write_obstack (out_file
, &contents
);
23879 write_obstack (out_file
, &cu_list
);
23880 write_obstack (out_file
, &types_cu_list
);
23881 write_obstack (out_file
, &addr_obstack
);
23882 write_obstack (out_file
, &symtab_obstack
);
23883 write_obstack (out_file
, &constant_pool
);
23887 /* We want to keep the file. */
23888 unlink_file
.keep ();
23890 do_cleanups (cleanup
);
23893 /* Implementation of the `save gdb-index' command.
23895 Note that the file format used by this command is documented in the
23896 GDB manual. Any changes here must be documented there. */
23899 save_gdb_index_command (char *arg
, int from_tty
)
23901 struct objfile
*objfile
;
23904 error (_("usage: save gdb-index DIRECTORY"));
23906 ALL_OBJFILES (objfile
)
23910 /* If the objfile does not correspond to an actual file, skip it. */
23911 if (stat (objfile_name (objfile
), &st
) < 0)
23915 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
23916 dwarf2_objfile_data_key
);
23917 if (dwarf2_per_objfile
)
23922 write_psymtabs_to_index (objfile
, arg
);
23924 CATCH (except
, RETURN_MASK_ERROR
)
23926 exception_fprintf (gdb_stderr
, except
,
23927 _("Error while writing index for `%s': "),
23928 objfile_name (objfile
));
23937 int dwarf_always_disassemble
;
23940 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
23941 struct cmd_list_element
*c
, const char *value
)
23943 fprintf_filtered (file
,
23944 _("Whether to always disassemble "
23945 "DWARF expressions is %s.\n"),
23950 show_check_physname (struct ui_file
*file
, int from_tty
,
23951 struct cmd_list_element
*c
, const char *value
)
23953 fprintf_filtered (file
,
23954 _("Whether to check \"physname\" is %s.\n"),
23958 void _initialize_dwarf2_read (void);
23961 _initialize_dwarf2_read (void)
23963 struct cmd_list_element
*c
;
23965 dwarf2_objfile_data_key
23966 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
23968 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23969 Set DWARF specific variables.\n\
23970 Configure DWARF variables such as the cache size"),
23971 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23972 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23974 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23975 Show DWARF specific variables\n\
23976 Show DWARF variables such as the cache size"),
23977 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23978 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23980 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23981 &dwarf_max_cache_age
, _("\
23982 Set the upper bound on the age of cached DWARF compilation units."), _("\
23983 Show the upper bound on the age of cached DWARF compilation units."), _("\
23984 A higher limit means that cached compilation units will be stored\n\
23985 in memory longer, and more total memory will be used. Zero disables\n\
23986 caching, which can slow down startup."),
23988 show_dwarf_max_cache_age
,
23989 &set_dwarf_cmdlist
,
23990 &show_dwarf_cmdlist
);
23992 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
23993 &dwarf_always_disassemble
, _("\
23994 Set whether `info address' always disassembles DWARF expressions."), _("\
23995 Show whether `info address' always disassembles DWARF expressions."), _("\
23996 When enabled, DWARF expressions are always printed in an assembly-like\n\
23997 syntax. When disabled, expressions will be printed in a more\n\
23998 conversational style, when possible."),
24000 show_dwarf_always_disassemble
,
24001 &set_dwarf_cmdlist
,
24002 &show_dwarf_cmdlist
);
24004 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24005 Set debugging of the DWARF reader."), _("\
24006 Show debugging of the DWARF reader."), _("\
24007 When enabled (non-zero), debugging messages are printed during DWARF\n\
24008 reading and symtab expansion. A value of 1 (one) provides basic\n\
24009 information. A value greater than 1 provides more verbose information."),
24012 &setdebuglist
, &showdebuglist
);
24014 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24015 Set debugging of the DWARF DIE reader."), _("\
24016 Show debugging of the DWARF DIE reader."), _("\
24017 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24018 The value is the maximum depth to print."),
24021 &setdebuglist
, &showdebuglist
);
24023 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24024 Set debugging of the dwarf line reader."), _("\
24025 Show debugging of the dwarf line reader."), _("\
24026 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24027 A value of 1 (one) provides basic information.\n\
24028 A value greater than 1 provides more verbose information."),
24031 &setdebuglist
, &showdebuglist
);
24033 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24034 Set cross-checking of \"physname\" code against demangler."), _("\
24035 Show cross-checking of \"physname\" code against demangler."), _("\
24036 When enabled, GDB's internal \"physname\" code is checked against\n\
24038 NULL
, show_check_physname
,
24039 &setdebuglist
, &showdebuglist
);
24041 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24042 no_class
, &use_deprecated_index_sections
, _("\
24043 Set whether to use deprecated gdb_index sections."), _("\
24044 Show whether to use deprecated gdb_index sections."), _("\
24045 When enabled, deprecated .gdb_index sections are used anyway.\n\
24046 Normally they are ignored either because of a missing feature or\n\
24047 performance issue.\n\
24048 Warning: This option must be enabled before gdb reads the file."),
24051 &setlist
, &showlist
);
24053 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
24055 Save a gdb-index file.\n\
24056 Usage: save gdb-index DIRECTORY"),
24058 set_cmd_completer (c
, filename_completer
);
24060 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24061 &dwarf2_locexpr_funcs
);
24062 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24063 &dwarf2_loclist_funcs
);
24065 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24066 &dwarf2_block_frame_base_locexpr_funcs
);
24067 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24068 &dwarf2_block_frame_base_loclist_funcs
);