1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2016 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"
59 #include "completer.h"
64 #include "gdbcore.h" /* for gnutarget */
65 #include "gdb/gdb-index.h"
70 #include "filestuff.h"
72 #include "namespace.h"
75 #include <sys/types.h>
78 typedef struct symbol
*symbolp
;
81 /* When == 1, print basic high level tracing messages.
82 When > 1, be more verbose.
83 This is in contrast to the low level DIE reading of dwarf_die_debug. */
84 static unsigned int dwarf_read_debug
= 0;
86 /* When non-zero, dump DIEs after they are read in. */
87 static unsigned int dwarf_die_debug
= 0;
89 /* When non-zero, dump line number entries as they are read in. */
90 static unsigned int dwarf_line_debug
= 0;
92 /* When non-zero, cross-check physname against demangler. */
93 static int check_physname
= 0;
95 /* When non-zero, do not reject deprecated .gdb_index sections. */
96 static int use_deprecated_index_sections
= 0;
98 static const struct objfile_data
*dwarf2_objfile_data_key
;
100 /* The "aclass" indices for various kinds of computed DWARF symbols. */
102 static int dwarf2_locexpr_index
;
103 static int dwarf2_loclist_index
;
104 static int dwarf2_locexpr_block_index
;
105 static int dwarf2_loclist_block_index
;
107 /* A descriptor for dwarf sections.
109 S.ASECTION, SIZE are typically initialized when the objfile is first
110 scanned. BUFFER, READIN are filled in later when the section is read.
111 If the section contained compressed data then SIZE is updated to record
112 the uncompressed size of the section.
114 DWP file format V2 introduces a wrinkle that is easiest to handle by
115 creating the concept of virtual sections contained within a real section.
116 In DWP V2 the sections of the input DWO files are concatenated together
117 into one section, but section offsets are kept relative to the original
119 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
120 the real section this "virtual" section is contained in, and BUFFER,SIZE
121 describe the virtual section. */
123 struct dwarf2_section_info
127 /* If this is a real section, the bfd section. */
129 /* If this is a virtual section, pointer to the containing ("real")
131 struct dwarf2_section_info
*containing_section
;
133 /* Pointer to section data, only valid if readin. */
134 const gdb_byte
*buffer
;
135 /* The size of the section, real or virtual. */
137 /* If this is a virtual section, the offset in the real section.
138 Only valid if is_virtual. */
139 bfd_size_type virtual_offset
;
140 /* True if we have tried to read this section. */
142 /* True if this is a virtual section, False otherwise.
143 This specifies which of s.section and s.containing_section to use. */
147 typedef struct dwarf2_section_info dwarf2_section_info_def
;
148 DEF_VEC_O (dwarf2_section_info_def
);
150 /* All offsets in the index are of this type. It must be
151 architecture-independent. */
152 typedef uint32_t offset_type
;
154 DEF_VEC_I (offset_type
);
156 /* Ensure only legit values are used. */
157 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
159 gdb_assert ((unsigned int) (value) <= 1); \
160 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
163 /* Ensure only legit values are used. */
164 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
166 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
167 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
168 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
171 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
172 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
174 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
175 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
178 /* A description of the mapped index. The file format is described in
179 a comment by the code that writes the index. */
182 /* Index data format version. */
185 /* The total length of the buffer. */
188 /* A pointer to the address table data. */
189 const gdb_byte
*address_table
;
191 /* Size of the address table data in bytes. */
192 offset_type address_table_size
;
194 /* The symbol table, implemented as a hash table. */
195 const offset_type
*symbol_table
;
197 /* Size in slots, each slot is 2 offset_types. */
198 offset_type symbol_table_slots
;
200 /* A pointer to the constant pool. */
201 const char *constant_pool
;
204 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
205 DEF_VEC_P (dwarf2_per_cu_ptr
);
209 int nr_uniq_abbrev_tables
;
211 int nr_symtab_sharers
;
212 int nr_stmt_less_type_units
;
213 int nr_all_type_units_reallocs
;
216 /* Collection of data recorded per objfile.
217 This hangs off of dwarf2_objfile_data_key. */
219 struct dwarf2_per_objfile
221 struct dwarf2_section_info info
;
222 struct dwarf2_section_info abbrev
;
223 struct dwarf2_section_info line
;
224 struct dwarf2_section_info loc
;
225 struct dwarf2_section_info macinfo
;
226 struct dwarf2_section_info macro
;
227 struct dwarf2_section_info str
;
228 struct dwarf2_section_info ranges
;
229 struct dwarf2_section_info addr
;
230 struct dwarf2_section_info frame
;
231 struct dwarf2_section_info eh_frame
;
232 struct dwarf2_section_info gdb_index
;
234 VEC (dwarf2_section_info_def
) *types
;
237 struct objfile
*objfile
;
239 /* Table of all the compilation units. This is used to locate
240 the target compilation unit of a particular reference. */
241 struct dwarf2_per_cu_data
**all_comp_units
;
243 /* The number of compilation units in ALL_COMP_UNITS. */
246 /* The number of .debug_types-related CUs. */
249 /* The number of elements allocated in all_type_units.
250 If there are skeleton-less TUs, we add them to all_type_units lazily. */
251 int n_allocated_type_units
;
253 /* The .debug_types-related CUs (TUs).
254 This is stored in malloc space because we may realloc it. */
255 struct signatured_type
**all_type_units
;
257 /* Table of struct type_unit_group objects.
258 The hash key is the DW_AT_stmt_list value. */
259 htab_t type_unit_groups
;
261 /* A table mapping .debug_types signatures to its signatured_type entry.
262 This is NULL if the .debug_types section hasn't been read in yet. */
263 htab_t signatured_types
;
265 /* Type unit statistics, to see how well the scaling improvements
267 struct tu_stats tu_stats
;
269 /* A chain of compilation units that are currently read in, so that
270 they can be freed later. */
271 struct dwarf2_per_cu_data
*read_in_chain
;
273 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
274 This is NULL if the table hasn't been allocated yet. */
277 /* Non-zero if we've check for whether there is a DWP file. */
280 /* The DWP file if there is one, or NULL. */
281 struct dwp_file
*dwp_file
;
283 /* The shared '.dwz' file, if one exists. This is used when the
284 original data was compressed using 'dwz -m'. */
285 struct dwz_file
*dwz_file
;
287 /* A flag indicating wether this objfile has a section loaded at a
289 int has_section_at_zero
;
291 /* True if we are using the mapped index,
292 or we are faking it for OBJF_READNOW's sake. */
293 unsigned char using_index
;
295 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
296 struct mapped_index
*index_table
;
298 /* When using index_table, this keeps track of all quick_file_names entries.
299 TUs typically share line table entries with a CU, so we maintain a
300 separate table of all line table entries to support the sharing.
301 Note that while there can be way more TUs than CUs, we've already
302 sorted all the TUs into "type unit groups", grouped by their
303 DW_AT_stmt_list value. Therefore the only sharing done here is with a
304 CU and its associated TU group if there is one. */
305 htab_t quick_file_names_table
;
307 /* Set during partial symbol reading, to prevent queueing of full
309 int reading_partial_symbols
;
311 /* Table mapping type DIEs to their struct type *.
312 This is NULL if not allocated yet.
313 The mapping is done via (CU/TU + DIE offset) -> type. */
314 htab_t die_type_hash
;
316 /* The CUs we recently read. */
317 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
319 /* Table containing line_header indexed by offset and offset_in_dwz. */
320 htab_t line_header_hash
;
323 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
325 /* Default names of the debugging sections. */
327 /* Note that if the debugging section has been compressed, it might
328 have a name like .zdebug_info. */
330 static const struct dwarf2_debug_sections dwarf2_elf_names
=
332 { ".debug_info", ".zdebug_info" },
333 { ".debug_abbrev", ".zdebug_abbrev" },
334 { ".debug_line", ".zdebug_line" },
335 { ".debug_loc", ".zdebug_loc" },
336 { ".debug_macinfo", ".zdebug_macinfo" },
337 { ".debug_macro", ".zdebug_macro" },
338 { ".debug_str", ".zdebug_str" },
339 { ".debug_ranges", ".zdebug_ranges" },
340 { ".debug_types", ".zdebug_types" },
341 { ".debug_addr", ".zdebug_addr" },
342 { ".debug_frame", ".zdebug_frame" },
343 { ".eh_frame", NULL
},
344 { ".gdb_index", ".zgdb_index" },
348 /* List of DWO/DWP sections. */
350 static const struct dwop_section_names
352 struct dwarf2_section_names abbrev_dwo
;
353 struct dwarf2_section_names info_dwo
;
354 struct dwarf2_section_names line_dwo
;
355 struct dwarf2_section_names loc_dwo
;
356 struct dwarf2_section_names macinfo_dwo
;
357 struct dwarf2_section_names macro_dwo
;
358 struct dwarf2_section_names str_dwo
;
359 struct dwarf2_section_names str_offsets_dwo
;
360 struct dwarf2_section_names types_dwo
;
361 struct dwarf2_section_names cu_index
;
362 struct dwarf2_section_names tu_index
;
366 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
367 { ".debug_info.dwo", ".zdebug_info.dwo" },
368 { ".debug_line.dwo", ".zdebug_line.dwo" },
369 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
370 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
371 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
372 { ".debug_str.dwo", ".zdebug_str.dwo" },
373 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
374 { ".debug_types.dwo", ".zdebug_types.dwo" },
375 { ".debug_cu_index", ".zdebug_cu_index" },
376 { ".debug_tu_index", ".zdebug_tu_index" },
379 /* local data types */
381 /* The data in a compilation unit header, after target2host
382 translation, looks like this. */
383 struct comp_unit_head
387 unsigned char addr_size
;
388 unsigned char signed_addr_p
;
389 sect_offset abbrev_offset
;
391 /* Size of file offsets; either 4 or 8. */
392 unsigned int offset_size
;
394 /* Size of the length field; either 4 or 12. */
395 unsigned int initial_length_size
;
397 /* Offset to the first byte of this compilation unit header in the
398 .debug_info section, for resolving relative reference dies. */
401 /* Offset to first die in this cu from the start of the cu.
402 This will be the first byte following the compilation unit header. */
403 cu_offset first_die_offset
;
406 /* Type used for delaying computation of method physnames.
407 See comments for compute_delayed_physnames. */
408 struct delayed_method_info
410 /* The type to which the method is attached, i.e., its parent class. */
413 /* The index of the method in the type's function fieldlists. */
416 /* The index of the method in the fieldlist. */
419 /* The name of the DIE. */
422 /* The DIE associated with this method. */
423 struct die_info
*die
;
426 typedef struct delayed_method_info delayed_method_info
;
427 DEF_VEC_O (delayed_method_info
);
429 /* Internal state when decoding a particular compilation unit. */
432 /* The objfile containing this compilation unit. */
433 struct objfile
*objfile
;
435 /* The header of the compilation unit. */
436 struct comp_unit_head header
;
438 /* Base address of this compilation unit. */
439 CORE_ADDR base_address
;
441 /* Non-zero if base_address has been set. */
444 /* The language we are debugging. */
445 enum language language
;
446 const struct language_defn
*language_defn
;
448 const char *producer
;
450 /* The generic symbol table building routines have separate lists for
451 file scope symbols and all all other scopes (local scopes). So
452 we need to select the right one to pass to add_symbol_to_list().
453 We do it by keeping a pointer to the correct list in list_in_scope.
455 FIXME: The original dwarf code just treated the file scope as the
456 first local scope, and all other local scopes as nested local
457 scopes, and worked fine. Check to see if we really need to
458 distinguish these in buildsym.c. */
459 struct pending
**list_in_scope
;
461 /* The abbrev table for this CU.
462 Normally this points to the abbrev table in the objfile.
463 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
464 struct abbrev_table
*abbrev_table
;
466 /* Hash table holding all the loaded partial DIEs
467 with partial_die->offset.SECT_OFF as hash. */
470 /* Storage for things with the same lifetime as this read-in compilation
471 unit, including partial DIEs. */
472 struct obstack comp_unit_obstack
;
474 /* When multiple dwarf2_cu structures are living in memory, this field
475 chains them all together, so that they can be released efficiently.
476 We will probably also want a generation counter so that most-recently-used
477 compilation units are cached... */
478 struct dwarf2_per_cu_data
*read_in_chain
;
480 /* Backlink to our per_cu entry. */
481 struct dwarf2_per_cu_data
*per_cu
;
483 /* How many compilation units ago was this CU last referenced? */
486 /* A hash table of DIE cu_offset for following references with
487 die_info->offset.sect_off as hash. */
490 /* Full DIEs if read in. */
491 struct die_info
*dies
;
493 /* A set of pointers to dwarf2_per_cu_data objects for compilation
494 units referenced by this one. Only set during full symbol processing;
495 partial symbol tables do not have dependencies. */
498 /* Header data from the line table, during full symbol processing. */
499 struct line_header
*line_header
;
501 /* A list of methods which need to have physnames computed
502 after all type information has been read. */
503 VEC (delayed_method_info
) *method_list
;
505 /* To be copied to symtab->call_site_htab. */
506 htab_t call_site_htab
;
508 /* Non-NULL if this CU came from a DWO file.
509 There is an invariant here that is important to remember:
510 Except for attributes copied from the top level DIE in the "main"
511 (or "stub") file in preparation for reading the DWO file
512 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
513 Either there isn't a DWO file (in which case this is NULL and the point
514 is moot), or there is and either we're not going to read it (in which
515 case this is NULL) or there is and we are reading it (in which case this
517 struct dwo_unit
*dwo_unit
;
519 /* The DW_AT_addr_base attribute if present, zero otherwise
520 (zero is a valid value though).
521 Note this value comes from the Fission stub CU/TU's DIE. */
524 /* The DW_AT_ranges_base attribute if present, zero otherwise
525 (zero is a valid value though).
526 Note this value comes from the Fission stub CU/TU's DIE.
527 Also note that the value is zero in the non-DWO case so this value can
528 be used without needing to know whether DWO files are in use or not.
529 N.B. This does not apply to DW_AT_ranges appearing in
530 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
531 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
532 DW_AT_ranges_base *would* have to be applied, and we'd have to care
533 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
534 ULONGEST ranges_base
;
536 /* Mark used when releasing cached dies. */
537 unsigned int mark
: 1;
539 /* This CU references .debug_loc. See the symtab->locations_valid field.
540 This test is imperfect as there may exist optimized debug code not using
541 any location list and still facing inlining issues if handled as
542 unoptimized code. For a future better test see GCC PR other/32998. */
543 unsigned int has_loclist
: 1;
545 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
546 if all the producer_is_* fields are valid. This information is cached
547 because profiling CU expansion showed excessive time spent in
548 producer_is_gxx_lt_4_6. */
549 unsigned int checked_producer
: 1;
550 unsigned int producer_is_gxx_lt_4_6
: 1;
551 unsigned int producer_is_gcc_lt_4_3
: 1;
552 unsigned int producer_is_icc
: 1;
554 /* When set, the file that we're processing is known to have
555 debugging info for C++ namespaces. GCC 3.3.x did not produce
556 this information, but later versions do. */
558 unsigned int processing_has_namespace_info
: 1;
561 /* Persistent data held for a compilation unit, even when not
562 processing it. We put a pointer to this structure in the
563 read_symtab_private field of the psymtab. */
565 struct dwarf2_per_cu_data
567 /* The start offset and length of this compilation unit.
568 NOTE: Unlike comp_unit_head.length, this length includes
570 If the DIE refers to a DWO file, this is always of the original die,
575 /* Flag indicating this compilation unit will be read in before
576 any of the current compilation units are processed. */
577 unsigned int queued
: 1;
579 /* This flag will be set when reading partial DIEs if we need to load
580 absolutely all DIEs for this compilation unit, instead of just the ones
581 we think are interesting. It gets set if we look for a DIE in the
582 hash table and don't find it. */
583 unsigned int load_all_dies
: 1;
585 /* Non-zero if this CU is from .debug_types.
586 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
588 unsigned int is_debug_types
: 1;
590 /* Non-zero if this CU is from the .dwz file. */
591 unsigned int is_dwz
: 1;
593 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
594 This flag is only valid if is_debug_types is true.
595 We can't read a CU directly from a DWO file: There are required
596 attributes in the stub. */
597 unsigned int reading_dwo_directly
: 1;
599 /* Non-zero if the TU has been read.
600 This is used to assist the "Stay in DWO Optimization" for Fission:
601 When reading a DWO, it's faster to read TUs from the DWO instead of
602 fetching them from random other DWOs (due to comdat folding).
603 If the TU has already been read, the optimization is unnecessary
604 (and unwise - we don't want to change where gdb thinks the TU lives
606 This flag is only valid if is_debug_types is true. */
607 unsigned int tu_read
: 1;
609 /* The section this CU/TU lives in.
610 If the DIE refers to a DWO file, this is always the original die,
612 struct dwarf2_section_info
*section
;
614 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
615 of the CU cache it gets reset to NULL again. This is left as NULL for
616 dummy CUs (a CU header, but nothing else). */
617 struct dwarf2_cu
*cu
;
619 /* The corresponding objfile.
620 Normally we can get the objfile from dwarf2_per_objfile.
621 However we can enter this file with just a "per_cu" handle. */
622 struct objfile
*objfile
;
624 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
625 is active. Otherwise, the 'psymtab' field is active. */
628 /* The partial symbol table associated with this compilation unit,
629 or NULL for unread partial units. */
630 struct partial_symtab
*psymtab
;
632 /* Data needed by the "quick" functions. */
633 struct dwarf2_per_cu_quick_data
*quick
;
636 /* The CUs we import using DW_TAG_imported_unit. This is filled in
637 while reading psymtabs, used to compute the psymtab dependencies,
638 and then cleared. Then it is filled in again while reading full
639 symbols, and only deleted when the objfile is destroyed.
641 This is also used to work around a difference between the way gold
642 generates .gdb_index version <=7 and the way gdb does. Arguably this
643 is a gold bug. For symbols coming from TUs, gold records in the index
644 the CU that includes the TU instead of the TU itself. This breaks
645 dw2_lookup_symbol: It assumes that if the index says symbol X lives
646 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
647 will find X. Alas TUs live in their own symtab, so after expanding CU Y
648 we need to look in TU Z to find X. Fortunately, this is akin to
649 DW_TAG_imported_unit, so we just use the same mechanism: For
650 .gdb_index version <=7 this also records the TUs that the CU referred
651 to. Concurrently with this change gdb was modified to emit version 8
652 indices so we only pay a price for gold generated indices.
653 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
654 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
657 /* Entry in the signatured_types hash table. */
659 struct signatured_type
661 /* The "per_cu" object of this type.
662 This struct is used iff per_cu.is_debug_types.
663 N.B.: This is the first member so that it's easy to convert pointers
665 struct dwarf2_per_cu_data per_cu
;
667 /* The type's signature. */
670 /* Offset in the TU of the type's DIE, as read from the TU header.
671 If this TU is a DWO stub and the definition lives in a DWO file
672 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
673 cu_offset type_offset_in_tu
;
675 /* Offset in the section of the type's DIE.
676 If the definition lives in a DWO file, this is the offset in the
677 .debug_types.dwo section.
678 The value is zero until the actual value is known.
679 Zero is otherwise not a valid section offset. */
680 sect_offset type_offset_in_section
;
682 /* Type units are grouped by their DW_AT_stmt_list entry so that they
683 can share them. This points to the containing symtab. */
684 struct type_unit_group
*type_unit_group
;
687 The first time we encounter this type we fully read it in and install it
688 in the symbol tables. Subsequent times we only need the type. */
691 /* Containing DWO unit.
692 This field is valid iff per_cu.reading_dwo_directly. */
693 struct dwo_unit
*dwo_unit
;
696 typedef struct signatured_type
*sig_type_ptr
;
697 DEF_VEC_P (sig_type_ptr
);
699 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
700 This includes type_unit_group and quick_file_names. */
702 struct stmt_list_hash
704 /* The DWO unit this table is from or NULL if there is none. */
705 struct dwo_unit
*dwo_unit
;
707 /* Offset in .debug_line or .debug_line.dwo. */
708 sect_offset line_offset
;
711 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
712 an object of this type. */
714 struct type_unit_group
716 /* dwarf2read.c's main "handle" on a TU symtab.
717 To simplify things we create an artificial CU that "includes" all the
718 type units using this stmt_list so that the rest of the code still has
719 a "per_cu" handle on the symtab.
720 This PER_CU is recognized by having no section. */
721 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
722 struct dwarf2_per_cu_data per_cu
;
724 /* The TUs that share this DW_AT_stmt_list entry.
725 This is added to while parsing type units to build partial symtabs,
726 and is deleted afterwards and not used again. */
727 VEC (sig_type_ptr
) *tus
;
729 /* The compunit symtab.
730 Type units in a group needn't all be defined in the same source file,
731 so we create an essentially anonymous symtab as the compunit symtab. */
732 struct compunit_symtab
*compunit_symtab
;
734 /* The data used to construct the hash key. */
735 struct stmt_list_hash hash
;
737 /* The number of symtabs from the line header.
738 The value here must match line_header.num_file_names. */
739 unsigned int num_symtabs
;
741 /* The symbol tables for this TU (obtained from the files listed in
743 WARNING: The order of entries here must match the order of entries
744 in the line header. After the first TU using this type_unit_group, the
745 line header for the subsequent TUs is recreated from this. This is done
746 because we need to use the same symtabs for each TU using the same
747 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
748 there's no guarantee the line header doesn't have duplicate entries. */
749 struct symtab
**symtabs
;
752 /* These sections are what may appear in a (real or virtual) DWO file. */
756 struct dwarf2_section_info abbrev
;
757 struct dwarf2_section_info line
;
758 struct dwarf2_section_info loc
;
759 struct dwarf2_section_info macinfo
;
760 struct dwarf2_section_info macro
;
761 struct dwarf2_section_info str
;
762 struct dwarf2_section_info str_offsets
;
763 /* In the case of a virtual DWO file, these two are unused. */
764 struct dwarf2_section_info info
;
765 VEC (dwarf2_section_info_def
) *types
;
768 /* CUs/TUs in DWP/DWO files. */
772 /* Backlink to the containing struct dwo_file. */
773 struct dwo_file
*dwo_file
;
775 /* The "id" that distinguishes this CU/TU.
776 .debug_info calls this "dwo_id", .debug_types calls this "signature".
777 Since signatures came first, we stick with it for consistency. */
780 /* The section this CU/TU lives in, in the DWO file. */
781 struct dwarf2_section_info
*section
;
783 /* Same as dwarf2_per_cu_data:{offset,length} but in the DWO section. */
787 /* For types, offset in the type's DIE of the type defined by this TU. */
788 cu_offset type_offset_in_tu
;
791 /* include/dwarf2.h defines the DWP section codes.
792 It defines a max value but it doesn't define a min value, which we
793 use for error checking, so provide one. */
795 enum dwp_v2_section_ids
800 /* Data for one DWO file.
802 This includes virtual DWO files (a virtual DWO file is a DWO file as it
803 appears in a DWP file). DWP files don't really have DWO files per se -
804 comdat folding of types "loses" the DWO file they came from, and from
805 a high level view DWP files appear to contain a mass of random types.
806 However, to maintain consistency with the non-DWP case we pretend DWP
807 files contain virtual DWO files, and we assign each TU with one virtual
808 DWO file (generally based on the line and abbrev section offsets -
809 a heuristic that seems to work in practice). */
813 /* The DW_AT_GNU_dwo_name attribute.
814 For virtual DWO files the name is constructed from the section offsets
815 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
816 from related CU+TUs. */
817 const char *dwo_name
;
819 /* The DW_AT_comp_dir attribute. */
820 const char *comp_dir
;
822 /* The bfd, when the file is open. Otherwise this is NULL.
823 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
826 /* The sections that make up this DWO file.
827 Remember that for virtual DWO files in DWP V2, these are virtual
828 sections (for lack of a better name). */
829 struct dwo_sections sections
;
831 /* The CU in the file.
832 We only support one because having more than one requires hacking the
833 dwo_name of each to match, which is highly unlikely to happen.
834 Doing this means all TUs can share comp_dir: We also assume that
835 DW_AT_comp_dir across all TUs in a DWO file will be identical. */
838 /* Table of TUs in the file.
839 Each element is a struct dwo_unit. */
843 /* These sections are what may appear in a DWP file. */
847 /* These are used by both DWP version 1 and 2. */
848 struct dwarf2_section_info str
;
849 struct dwarf2_section_info cu_index
;
850 struct dwarf2_section_info tu_index
;
852 /* These are only used by DWP version 2 files.
853 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
854 sections are referenced by section number, and are not recorded here.
855 In DWP version 2 there is at most one copy of all these sections, each
856 section being (effectively) comprised of the concatenation of all of the
857 individual sections that exist in the version 1 format.
858 To keep the code simple we treat each of these concatenated pieces as a
859 section itself (a virtual section?). */
860 struct dwarf2_section_info abbrev
;
861 struct dwarf2_section_info info
;
862 struct dwarf2_section_info line
;
863 struct dwarf2_section_info loc
;
864 struct dwarf2_section_info macinfo
;
865 struct dwarf2_section_info macro
;
866 struct dwarf2_section_info str_offsets
;
867 struct dwarf2_section_info types
;
870 /* These sections are what may appear in a virtual DWO file in DWP version 1.
871 A virtual DWO file is a DWO file as it appears in a DWP file. */
873 struct virtual_v1_dwo_sections
875 struct dwarf2_section_info abbrev
;
876 struct dwarf2_section_info line
;
877 struct dwarf2_section_info loc
;
878 struct dwarf2_section_info macinfo
;
879 struct dwarf2_section_info macro
;
880 struct dwarf2_section_info str_offsets
;
881 /* Each DWP hash table entry records one CU or one TU.
882 That is recorded here, and copied to dwo_unit.section. */
883 struct dwarf2_section_info info_or_types
;
886 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
887 In version 2, the sections of the DWO files are concatenated together
888 and stored in one section of that name. Thus each ELF section contains
889 several "virtual" sections. */
891 struct virtual_v2_dwo_sections
893 bfd_size_type abbrev_offset
;
894 bfd_size_type abbrev_size
;
896 bfd_size_type line_offset
;
897 bfd_size_type line_size
;
899 bfd_size_type loc_offset
;
900 bfd_size_type loc_size
;
902 bfd_size_type macinfo_offset
;
903 bfd_size_type macinfo_size
;
905 bfd_size_type macro_offset
;
906 bfd_size_type macro_size
;
908 bfd_size_type str_offsets_offset
;
909 bfd_size_type str_offsets_size
;
911 /* Each DWP hash table entry records one CU or one TU.
912 That is recorded here, and copied to dwo_unit.section. */
913 bfd_size_type info_or_types_offset
;
914 bfd_size_type info_or_types_size
;
917 /* Contents of DWP hash tables. */
919 struct dwp_hash_table
921 uint32_t version
, nr_columns
;
922 uint32_t nr_units
, nr_slots
;
923 const gdb_byte
*hash_table
, *unit_table
;
928 const gdb_byte
*indices
;
932 /* This is indexed by column number and gives the id of the section
934 #define MAX_NR_V2_DWO_SECTIONS \
935 (1 /* .debug_info or .debug_types */ \
936 + 1 /* .debug_abbrev */ \
937 + 1 /* .debug_line */ \
938 + 1 /* .debug_loc */ \
939 + 1 /* .debug_str_offsets */ \
940 + 1 /* .debug_macro or .debug_macinfo */)
941 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
942 const gdb_byte
*offsets
;
943 const gdb_byte
*sizes
;
948 /* Data for one DWP file. */
952 /* Name of the file. */
955 /* File format version. */
961 /* Section info for this file. */
962 struct dwp_sections sections
;
964 /* Table of CUs in the file. */
965 const struct dwp_hash_table
*cus
;
967 /* Table of TUs in the file. */
968 const struct dwp_hash_table
*tus
;
970 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
974 /* Table to map ELF section numbers to their sections.
975 This is only needed for the DWP V1 file format. */
976 unsigned int num_sections
;
977 asection
**elf_sections
;
980 /* This represents a '.dwz' file. */
984 /* A dwz file can only contain a few sections. */
985 struct dwarf2_section_info abbrev
;
986 struct dwarf2_section_info info
;
987 struct dwarf2_section_info str
;
988 struct dwarf2_section_info line
;
989 struct dwarf2_section_info macro
;
990 struct dwarf2_section_info gdb_index
;
996 /* Struct used to pass misc. parameters to read_die_and_children, et
997 al. which are used for both .debug_info and .debug_types dies.
998 All parameters here are unchanging for the life of the call. This
999 struct exists to abstract away the constant parameters of die reading. */
1001 struct die_reader_specs
1003 /* The bfd of die_section. */
1006 /* The CU of the DIE we are parsing. */
1007 struct dwarf2_cu
*cu
;
1009 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1010 struct dwo_file
*dwo_file
;
1012 /* The section the die comes from.
1013 This is either .debug_info or .debug_types, or the .dwo variants. */
1014 struct dwarf2_section_info
*die_section
;
1016 /* die_section->buffer. */
1017 const gdb_byte
*buffer
;
1019 /* The end of the buffer. */
1020 const gdb_byte
*buffer_end
;
1022 /* The value of the DW_AT_comp_dir attribute. */
1023 const char *comp_dir
;
1026 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1027 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1028 const gdb_byte
*info_ptr
,
1029 struct die_info
*comp_unit_die
,
1036 unsigned int dir_index
;
1037 unsigned int mod_time
;
1038 unsigned int length
;
1039 /* Non-zero if referenced by the Line Number Program. */
1041 /* The associated symbol table, if any. */
1042 struct symtab
*symtab
;
1045 /* The line number information for a compilation unit (found in the
1046 .debug_line section) begins with a "statement program header",
1047 which contains the following information. */
1050 /* Offset of line number information in .debug_line section. */
1053 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1054 unsigned offset_in_dwz
: 1;
1056 unsigned int total_length
;
1057 unsigned short version
;
1058 unsigned int header_length
;
1059 unsigned char minimum_instruction_length
;
1060 unsigned char maximum_ops_per_instruction
;
1061 unsigned char default_is_stmt
;
1063 unsigned char line_range
;
1064 unsigned char opcode_base
;
1066 /* standard_opcode_lengths[i] is the number of operands for the
1067 standard opcode whose value is i. This means that
1068 standard_opcode_lengths[0] is unused, and the last meaningful
1069 element is standard_opcode_lengths[opcode_base - 1]. */
1070 unsigned char *standard_opcode_lengths
;
1072 /* The include_directories table. NOTE! These strings are not
1073 allocated with xmalloc; instead, they are pointers into
1074 debug_line_buffer. If you try to free them, `free' will get
1076 unsigned int num_include_dirs
, include_dirs_size
;
1077 const char **include_dirs
;
1079 /* The file_names table. NOTE! These strings are not allocated
1080 with xmalloc; instead, they are pointers into debug_line_buffer.
1081 Don't try to free them directly. */
1082 unsigned int num_file_names
, file_names_size
;
1083 struct file_entry
*file_names
;
1085 /* The start and end of the statement program following this
1086 header. These point into dwarf2_per_objfile->line_buffer. */
1087 const gdb_byte
*statement_program_start
, *statement_program_end
;
1090 /* When we construct a partial symbol table entry we only
1091 need this much information. */
1092 struct partial_die_info
1094 /* Offset of this DIE. */
1097 /* DWARF-2 tag for this DIE. */
1098 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1100 /* Assorted flags describing the data found in this DIE. */
1101 unsigned int has_children
: 1;
1102 unsigned int is_external
: 1;
1103 unsigned int is_declaration
: 1;
1104 unsigned int has_type
: 1;
1105 unsigned int has_specification
: 1;
1106 unsigned int has_pc_info
: 1;
1107 unsigned int may_be_inlined
: 1;
1109 /* Flag set if the SCOPE field of this structure has been
1111 unsigned int scope_set
: 1;
1113 /* Flag set if the DIE has a byte_size attribute. */
1114 unsigned int has_byte_size
: 1;
1116 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1117 unsigned int has_const_value
: 1;
1119 /* Flag set if any of the DIE's children are template arguments. */
1120 unsigned int has_template_arguments
: 1;
1122 /* Flag set if fixup_partial_die has been called on this die. */
1123 unsigned int fixup_called
: 1;
1125 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1126 unsigned int is_dwz
: 1;
1128 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1129 unsigned int spec_is_dwz
: 1;
1131 /* The name of this DIE. Normally the value of DW_AT_name, but
1132 sometimes a default name for unnamed DIEs. */
1135 /* The linkage name, if present. */
1136 const char *linkage_name
;
1138 /* The scope to prepend to our children. This is generally
1139 allocated on the comp_unit_obstack, so will disappear
1140 when this compilation unit leaves the cache. */
1143 /* Some data associated with the partial DIE. The tag determines
1144 which field is live. */
1147 /* The location description associated with this DIE, if any. */
1148 struct dwarf_block
*locdesc
;
1149 /* The offset of an import, for DW_TAG_imported_unit. */
1153 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1157 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1158 DW_AT_sibling, if any. */
1159 /* NOTE: This member isn't strictly necessary, read_partial_die could
1160 return DW_AT_sibling values to its caller load_partial_dies. */
1161 const gdb_byte
*sibling
;
1163 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1164 DW_AT_specification (or DW_AT_abstract_origin or
1165 DW_AT_extension). */
1166 sect_offset spec_offset
;
1168 /* Pointers to this DIE's parent, first child, and next sibling,
1170 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
1173 /* This data structure holds the information of an abbrev. */
1176 unsigned int number
; /* number identifying abbrev */
1177 enum dwarf_tag tag
; /* dwarf tag */
1178 unsigned short has_children
; /* boolean */
1179 unsigned short num_attrs
; /* number of attributes */
1180 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1181 struct abbrev_info
*next
; /* next in chain */
1186 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1187 ENUM_BITFIELD(dwarf_form
) form
: 16;
1190 /* Size of abbrev_table.abbrev_hash_table. */
1191 #define ABBREV_HASH_SIZE 121
1193 /* Top level data structure to contain an abbreviation table. */
1197 /* Where the abbrev table came from.
1198 This is used as a sanity check when the table is used. */
1201 /* Storage for the abbrev table. */
1202 struct obstack abbrev_obstack
;
1204 /* Hash table of abbrevs.
1205 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1206 It could be statically allocated, but the previous code didn't so we
1208 struct abbrev_info
**abbrevs
;
1211 /* Attributes have a name and a value. */
1214 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1215 ENUM_BITFIELD(dwarf_form
) form
: 15;
1217 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1218 field should be in u.str (existing only for DW_STRING) but it is kept
1219 here for better struct attribute alignment. */
1220 unsigned int string_is_canonical
: 1;
1225 struct dwarf_block
*blk
;
1234 /* This data structure holds a complete die structure. */
1237 /* DWARF-2 tag for this DIE. */
1238 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1240 /* Number of attributes */
1241 unsigned char num_attrs
;
1243 /* True if we're presently building the full type name for the
1244 type derived from this DIE. */
1245 unsigned char building_fullname
: 1;
1247 /* True if this die is in process. PR 16581. */
1248 unsigned char in_process
: 1;
1251 unsigned int abbrev
;
1253 /* Offset in .debug_info or .debug_types section. */
1256 /* The dies in a compilation unit form an n-ary tree. PARENT
1257 points to this die's parent; CHILD points to the first child of
1258 this node; and all the children of a given node are chained
1259 together via their SIBLING fields. */
1260 struct die_info
*child
; /* Its first child, if any. */
1261 struct die_info
*sibling
; /* Its next sibling, if any. */
1262 struct die_info
*parent
; /* Its parent, if any. */
1264 /* An array of attributes, with NUM_ATTRS elements. There may be
1265 zero, but it's not common and zero-sized arrays are not
1266 sufficiently portable C. */
1267 struct attribute attrs
[1];
1270 /* Get at parts of an attribute structure. */
1272 #define DW_STRING(attr) ((attr)->u.str)
1273 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1274 #define DW_UNSND(attr) ((attr)->u.unsnd)
1275 #define DW_BLOCK(attr) ((attr)->u.blk)
1276 #define DW_SND(attr) ((attr)->u.snd)
1277 #define DW_ADDR(attr) ((attr)->u.addr)
1278 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1280 /* Blocks are a bunch of untyped bytes. */
1285 /* Valid only if SIZE is not zero. */
1286 const gdb_byte
*data
;
1289 #ifndef ATTR_ALLOC_CHUNK
1290 #define ATTR_ALLOC_CHUNK 4
1293 /* Allocate fields for structs, unions and enums in this size. */
1294 #ifndef DW_FIELD_ALLOC_CHUNK
1295 #define DW_FIELD_ALLOC_CHUNK 4
1298 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1299 but this would require a corresponding change in unpack_field_as_long
1301 static int bits_per_byte
= 8;
1305 struct nextfield
*next
;
1313 struct nextfnfield
*next
;
1314 struct fn_field fnfield
;
1321 struct nextfnfield
*head
;
1324 struct typedef_field_list
1326 struct typedef_field field
;
1327 struct typedef_field_list
*next
;
1330 /* The routines that read and process dies for a C struct or C++ class
1331 pass lists of data member fields and lists of member function fields
1332 in an instance of a field_info structure, as defined below. */
1335 /* List of data member and baseclasses fields. */
1336 struct nextfield
*fields
, *baseclasses
;
1338 /* Number of fields (including baseclasses). */
1341 /* Number of baseclasses. */
1344 /* Set if the accesibility of one of the fields is not public. */
1345 int non_public_fields
;
1347 /* Member function fields array, entries are allocated in the order they
1348 are encountered in the object file. */
1349 struct nextfnfield
*fnfields
;
1351 /* Member function fieldlist array, contains name of possibly overloaded
1352 member function, number of overloaded member functions and a pointer
1353 to the head of the member function field chain. */
1354 struct fnfieldlist
*fnfieldlists
;
1356 /* Number of entries in the fnfieldlists array. */
1359 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1360 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1361 struct typedef_field_list
*typedef_field_list
;
1362 unsigned typedef_field_list_count
;
1365 /* One item on the queue of compilation units to read in full symbols
1367 struct dwarf2_queue_item
1369 struct dwarf2_per_cu_data
*per_cu
;
1370 enum language pretend_language
;
1371 struct dwarf2_queue_item
*next
;
1374 /* The current queue. */
1375 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1377 /* Loaded secondary compilation units are kept in memory until they
1378 have not been referenced for the processing of this many
1379 compilation units. Set this to zero to disable caching. Cache
1380 sizes of up to at least twenty will improve startup time for
1381 typical inter-CU-reference binaries, at an obvious memory cost. */
1382 static int dwarf_max_cache_age
= 5;
1384 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1385 struct cmd_list_element
*c
, const char *value
)
1387 fprintf_filtered (file
, _("The upper bound on the age of cached "
1388 "DWARF compilation units is %s.\n"),
1392 /* local function prototypes */
1394 static const char *get_section_name (const struct dwarf2_section_info
*);
1396 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1398 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1400 static void dwarf2_find_base_address (struct die_info
*die
,
1401 struct dwarf2_cu
*cu
);
1403 static struct partial_symtab
*create_partial_symtab
1404 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1406 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1408 static void scan_partial_symbols (struct partial_die_info
*,
1409 CORE_ADDR
*, CORE_ADDR
*,
1410 int, struct dwarf2_cu
*);
1412 static void add_partial_symbol (struct partial_die_info
*,
1413 struct dwarf2_cu
*);
1415 static void add_partial_namespace (struct partial_die_info
*pdi
,
1416 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1417 int set_addrmap
, struct dwarf2_cu
*cu
);
1419 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1420 CORE_ADDR
*highpc
, int set_addrmap
,
1421 struct dwarf2_cu
*cu
);
1423 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1424 struct dwarf2_cu
*cu
);
1426 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1427 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1428 int need_pc
, struct dwarf2_cu
*cu
);
1430 static void dwarf2_read_symtab (struct partial_symtab
*,
1433 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1435 static struct abbrev_info
*abbrev_table_lookup_abbrev
1436 (const struct abbrev_table
*, unsigned int);
1438 static struct abbrev_table
*abbrev_table_read_table
1439 (struct dwarf2_section_info
*, sect_offset
);
1441 static void abbrev_table_free (struct abbrev_table
*);
1443 static void abbrev_table_free_cleanup (void *);
1445 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1446 struct dwarf2_section_info
*);
1448 static void dwarf2_free_abbrev_table (void *);
1450 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1452 static struct partial_die_info
*load_partial_dies
1453 (const struct die_reader_specs
*, const gdb_byte
*, int);
1455 static const gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1456 struct partial_die_info
*,
1457 struct abbrev_info
*,
1461 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1462 struct dwarf2_cu
*);
1464 static void fixup_partial_die (struct partial_die_info
*,
1465 struct dwarf2_cu
*);
1467 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1468 struct attribute
*, struct attr_abbrev
*,
1471 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1473 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1475 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1477 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1479 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1481 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1484 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1486 static LONGEST read_checked_initial_length_and_offset
1487 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1488 unsigned int *, unsigned int *);
1490 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1491 const struct comp_unit_head
*,
1494 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1496 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1499 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1501 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1503 static const char *read_indirect_string (bfd
*, const gdb_byte
*,
1504 const struct comp_unit_head
*,
1507 static const char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1509 static ULONGEST
read_unsigned_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1511 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1513 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1517 static const char *read_str_index (const struct die_reader_specs
*reader
,
1518 ULONGEST str_index
);
1520 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1522 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1523 struct dwarf2_cu
*);
1525 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1528 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1529 struct dwarf2_cu
*cu
);
1531 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1532 struct dwarf2_cu
*cu
);
1534 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1536 static struct die_info
*die_specification (struct die_info
*die
,
1537 struct dwarf2_cu
**);
1539 static void free_line_header (struct line_header
*lh
);
1541 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1542 struct dwarf2_cu
*cu
);
1544 static void dwarf_decode_lines (struct line_header
*, const char *,
1545 struct dwarf2_cu
*, struct partial_symtab
*,
1546 CORE_ADDR
, int decode_mapping
);
1548 static void dwarf2_start_subfile (const char *, const char *);
1550 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1551 const char *, const char *,
1554 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1555 struct dwarf2_cu
*);
1557 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1558 struct dwarf2_cu
*, struct symbol
*);
1560 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1561 struct dwarf2_cu
*);
1563 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1566 struct obstack
*obstack
,
1567 struct dwarf2_cu
*cu
, LONGEST
*value
,
1568 const gdb_byte
**bytes
,
1569 struct dwarf2_locexpr_baton
**baton
);
1571 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1573 static int need_gnat_info (struct dwarf2_cu
*);
1575 static struct type
*die_descriptive_type (struct die_info
*,
1576 struct dwarf2_cu
*);
1578 static void set_descriptive_type (struct type
*, struct die_info
*,
1579 struct dwarf2_cu
*);
1581 static struct type
*die_containing_type (struct die_info
*,
1582 struct dwarf2_cu
*);
1584 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1585 struct dwarf2_cu
*);
1587 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1589 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1591 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1593 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1594 const char *suffix
, int physname
,
1595 struct dwarf2_cu
*cu
);
1597 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1599 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1601 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1603 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1605 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1607 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1608 struct dwarf2_cu
*, struct partial_symtab
*);
1610 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1611 values. Keep the items ordered with increasing constraints compliance. */
1614 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1615 PC_BOUNDS_NOT_PRESENT
,
1617 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1618 were present but they do not form a valid range of PC addresses. */
1621 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1624 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1628 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1629 CORE_ADDR
*, CORE_ADDR
*,
1631 struct partial_symtab
*);
1633 static void get_scope_pc_bounds (struct die_info
*,
1634 CORE_ADDR
*, CORE_ADDR
*,
1635 struct dwarf2_cu
*);
1637 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1638 CORE_ADDR
, struct dwarf2_cu
*);
1640 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1641 struct dwarf2_cu
*);
1643 static void dwarf2_attach_fields_to_type (struct field_info
*,
1644 struct type
*, struct dwarf2_cu
*);
1646 static void dwarf2_add_member_fn (struct field_info
*,
1647 struct die_info
*, struct type
*,
1648 struct dwarf2_cu
*);
1650 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1652 struct dwarf2_cu
*);
1654 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1656 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1658 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1660 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1662 static struct using_direct
**using_directives (enum language
);
1664 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1666 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1668 static struct type
*read_module_type (struct die_info
*die
,
1669 struct dwarf2_cu
*cu
);
1671 static const char *namespace_name (struct die_info
*die
,
1672 int *is_anonymous
, struct dwarf2_cu
*);
1674 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1676 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1678 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1679 struct dwarf2_cu
*);
1681 static struct die_info
*read_die_and_siblings_1
1682 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1685 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1686 const gdb_byte
*info_ptr
,
1687 const gdb_byte
**new_info_ptr
,
1688 struct die_info
*parent
);
1690 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1691 struct die_info
**, const gdb_byte
*,
1694 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1695 struct die_info
**, const gdb_byte
*,
1698 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1700 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1703 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1705 static const char *dwarf2_full_name (const char *name
,
1706 struct die_info
*die
,
1707 struct dwarf2_cu
*cu
);
1709 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1710 struct dwarf2_cu
*cu
);
1712 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1713 struct dwarf2_cu
**);
1715 static const char *dwarf_tag_name (unsigned int);
1717 static const char *dwarf_attr_name (unsigned int);
1719 static const char *dwarf_form_name (unsigned int);
1721 static char *dwarf_bool_name (unsigned int);
1723 static const char *dwarf_type_encoding_name (unsigned int);
1725 static struct die_info
*sibling_die (struct die_info
*);
1727 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1729 static void dump_die_for_error (struct die_info
*);
1731 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1734 /*static*/ void dump_die (struct die_info
*, int max_level
);
1736 static void store_in_ref_table (struct die_info
*,
1737 struct dwarf2_cu
*);
1739 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1741 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1743 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1744 const struct attribute
*,
1745 struct dwarf2_cu
**);
1747 static struct die_info
*follow_die_ref (struct die_info
*,
1748 const struct attribute
*,
1749 struct dwarf2_cu
**);
1751 static struct die_info
*follow_die_sig (struct die_info
*,
1752 const struct attribute
*,
1753 struct dwarf2_cu
**);
1755 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1756 struct dwarf2_cu
*);
1758 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1759 const struct attribute
*,
1760 struct dwarf2_cu
*);
1762 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1764 static void read_signatured_type (struct signatured_type
*);
1766 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1767 struct die_info
*die
, struct dwarf2_cu
*cu
,
1768 struct dynamic_prop
*prop
);
1770 /* memory allocation interface */
1772 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1774 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1776 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1778 static int attr_form_is_block (const struct attribute
*);
1780 static int attr_form_is_section_offset (const struct attribute
*);
1782 static int attr_form_is_constant (const struct attribute
*);
1784 static int attr_form_is_ref (const struct attribute
*);
1786 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1787 struct dwarf2_loclist_baton
*baton
,
1788 const struct attribute
*attr
);
1790 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1792 struct dwarf2_cu
*cu
,
1795 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1796 const gdb_byte
*info_ptr
,
1797 struct abbrev_info
*abbrev
);
1799 static void free_stack_comp_unit (void *);
1801 static hashval_t
partial_die_hash (const void *item
);
1803 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1805 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1806 (sect_offset offset
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1808 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1809 struct dwarf2_per_cu_data
*per_cu
);
1811 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1812 struct die_info
*comp_unit_die
,
1813 enum language pretend_language
);
1815 static void free_heap_comp_unit (void *);
1817 static void free_cached_comp_units (void *);
1819 static void age_cached_comp_units (void);
1821 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1823 static struct type
*set_die_type (struct die_info
*, struct type
*,
1824 struct dwarf2_cu
*);
1826 static void create_all_comp_units (struct objfile
*);
1828 static int create_all_type_units (struct objfile
*);
1830 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1833 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1836 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1839 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1840 struct dwarf2_per_cu_data
*);
1842 static void dwarf2_mark (struct dwarf2_cu
*);
1844 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1846 static struct type
*get_die_type_at_offset (sect_offset
,
1847 struct dwarf2_per_cu_data
*);
1849 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1851 static void dwarf2_release_queue (void *dummy
);
1853 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1854 enum language pretend_language
);
1856 static void process_queue (void);
1858 static void find_file_and_directory (struct die_info
*die
,
1859 struct dwarf2_cu
*cu
,
1860 const char **name
, const char **comp_dir
);
1862 static char *file_full_name (int file
, struct line_header
*lh
,
1863 const char *comp_dir
);
1865 static const gdb_byte
*read_and_check_comp_unit_head
1866 (struct comp_unit_head
*header
,
1867 struct dwarf2_section_info
*section
,
1868 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1869 int is_debug_types_section
);
1871 static void init_cutu_and_read_dies
1872 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1873 int use_existing_cu
, int keep
,
1874 die_reader_func_ftype
*die_reader_func
, void *data
);
1876 static void init_cutu_and_read_dies_simple
1877 (struct dwarf2_per_cu_data
*this_cu
,
1878 die_reader_func_ftype
*die_reader_func
, void *data
);
1880 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1882 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1884 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1885 (struct dwp_file
*dwp_file
, const char *comp_dir
,
1886 ULONGEST signature
, int is_debug_types
);
1888 static struct dwp_file
*get_dwp_file (void);
1890 static struct dwo_unit
*lookup_dwo_comp_unit
1891 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1893 static struct dwo_unit
*lookup_dwo_type_unit
1894 (struct signatured_type
*, const char *, const char *);
1896 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1898 static void free_dwo_file_cleanup (void *);
1900 static void process_cu_includes (void);
1902 static void check_producer (struct dwarf2_cu
*cu
);
1904 static void free_line_header_voidp (void *arg
);
1906 /* Various complaints about symbol reading that don't abort the process. */
1909 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1911 complaint (&symfile_complaints
,
1912 _("statement list doesn't fit in .debug_line section"));
1916 dwarf2_debug_line_missing_file_complaint (void)
1918 complaint (&symfile_complaints
,
1919 _(".debug_line section has line data without a file"));
1923 dwarf2_debug_line_missing_end_sequence_complaint (void)
1925 complaint (&symfile_complaints
,
1926 _(".debug_line section has line "
1927 "program sequence without an end"));
1931 dwarf2_complex_location_expr_complaint (void)
1933 complaint (&symfile_complaints
, _("location expression too complex"));
1937 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1940 complaint (&symfile_complaints
,
1941 _("const value length mismatch for '%s', got %d, expected %d"),
1946 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1948 complaint (&symfile_complaints
,
1949 _("debug info runs off end of %s section"
1951 get_section_name (section
),
1952 get_section_file_name (section
));
1956 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1958 complaint (&symfile_complaints
,
1959 _("macro debug info contains a "
1960 "malformed macro definition:\n`%s'"),
1965 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1967 complaint (&symfile_complaints
,
1968 _("invalid attribute class or form for '%s' in '%s'"),
1972 /* Hash function for line_header_hash. */
1975 line_header_hash (const struct line_header
*ofs
)
1977 return ofs
->offset
.sect_off
^ ofs
->offset_in_dwz
;
1980 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1983 line_header_hash_voidp (const void *item
)
1985 const struct line_header
*ofs
= (const struct line_header
*) item
;
1987 return line_header_hash (ofs
);
1990 /* Equality function for line_header_hash. */
1993 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1995 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1996 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1998 return (ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
1999 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2005 /* Convert VALUE between big- and little-endian. */
2007 byte_swap (offset_type value
)
2011 result
= (value
& 0xff) << 24;
2012 result
|= (value
& 0xff00) << 8;
2013 result
|= (value
& 0xff0000) >> 8;
2014 result
|= (value
& 0xff000000) >> 24;
2018 #define MAYBE_SWAP(V) byte_swap (V)
2021 #define MAYBE_SWAP(V) (V)
2022 #endif /* WORDS_BIGENDIAN */
2024 /* Read the given attribute value as an address, taking the attribute's
2025 form into account. */
2028 attr_value_as_address (struct attribute
*attr
)
2032 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2034 /* Aside from a few clearly defined exceptions, attributes that
2035 contain an address must always be in DW_FORM_addr form.
2036 Unfortunately, some compilers happen to be violating this
2037 requirement by encoding addresses using other forms, such
2038 as DW_FORM_data4 for example. For those broken compilers,
2039 we try to do our best, without any guarantee of success,
2040 to interpret the address correctly. It would also be nice
2041 to generate a complaint, but that would require us to maintain
2042 a list of legitimate cases where a non-address form is allowed,
2043 as well as update callers to pass in at least the CU's DWARF
2044 version. This is more overhead than what we're willing to
2045 expand for a pretty rare case. */
2046 addr
= DW_UNSND (attr
);
2049 addr
= DW_ADDR (attr
);
2054 /* The suffix for an index file. */
2055 #define INDEX_SUFFIX ".gdb-index"
2057 /* Try to locate the sections we need for DWARF 2 debugging
2058 information and return true if we have enough to do something.
2059 NAMES points to the dwarf2 section names, or is NULL if the standard
2060 ELF names are used. */
2063 dwarf2_has_info (struct objfile
*objfile
,
2064 const struct dwarf2_debug_sections
*names
)
2066 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
2067 objfile_data (objfile
, dwarf2_objfile_data_key
));
2068 if (!dwarf2_per_objfile
)
2070 /* Initialize per-objfile state. */
2071 struct dwarf2_per_objfile
*data
2072 = XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_objfile
);
2074 memset (data
, 0, sizeof (*data
));
2075 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
2076 dwarf2_per_objfile
= data
;
2078 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
2080 dwarf2_per_objfile
->objfile
= objfile
;
2082 return (!dwarf2_per_objfile
->info
.is_virtual
2083 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2084 && !dwarf2_per_objfile
->abbrev
.is_virtual
2085 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2088 /* Return the containing section of virtual section SECTION. */
2090 static struct dwarf2_section_info
*
2091 get_containing_section (const struct dwarf2_section_info
*section
)
2093 gdb_assert (section
->is_virtual
);
2094 return section
->s
.containing_section
;
2097 /* Return the bfd owner of SECTION. */
2100 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2102 if (section
->is_virtual
)
2104 section
= get_containing_section (section
);
2105 gdb_assert (!section
->is_virtual
);
2107 return section
->s
.section
->owner
;
2110 /* Return the bfd section of SECTION.
2111 Returns NULL if the section is not present. */
2114 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2116 if (section
->is_virtual
)
2118 section
= get_containing_section (section
);
2119 gdb_assert (!section
->is_virtual
);
2121 return section
->s
.section
;
2124 /* Return the name of SECTION. */
2127 get_section_name (const struct dwarf2_section_info
*section
)
2129 asection
*sectp
= get_section_bfd_section (section
);
2131 gdb_assert (sectp
!= NULL
);
2132 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2135 /* Return the name of the file SECTION is in. */
2138 get_section_file_name (const struct dwarf2_section_info
*section
)
2140 bfd
*abfd
= get_section_bfd_owner (section
);
2142 return bfd_get_filename (abfd
);
2145 /* Return the id of SECTION.
2146 Returns 0 if SECTION doesn't exist. */
2149 get_section_id (const struct dwarf2_section_info
*section
)
2151 asection
*sectp
= get_section_bfd_section (section
);
2158 /* Return the flags of SECTION.
2159 SECTION (or containing section if this is a virtual section) must exist. */
2162 get_section_flags (const struct dwarf2_section_info
*section
)
2164 asection
*sectp
= get_section_bfd_section (section
);
2166 gdb_assert (sectp
!= NULL
);
2167 return bfd_get_section_flags (sectp
->owner
, sectp
);
2170 /* When loading sections, we look either for uncompressed section or for
2171 compressed section names. */
2174 section_is_p (const char *section_name
,
2175 const struct dwarf2_section_names
*names
)
2177 if (names
->normal
!= NULL
2178 && strcmp (section_name
, names
->normal
) == 0)
2180 if (names
->compressed
!= NULL
2181 && strcmp (section_name
, names
->compressed
) == 0)
2186 /* This function is mapped across the sections and remembers the
2187 offset and size of each of the debugging sections we are interested
2191 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
2193 const struct dwarf2_debug_sections
*names
;
2194 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2197 names
= &dwarf2_elf_names
;
2199 names
= (const struct dwarf2_debug_sections
*) vnames
;
2201 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2204 else if (section_is_p (sectp
->name
, &names
->info
))
2206 dwarf2_per_objfile
->info
.s
.section
= sectp
;
2207 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
2209 else if (section_is_p (sectp
->name
, &names
->abbrev
))
2211 dwarf2_per_objfile
->abbrev
.s
.section
= sectp
;
2212 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
2214 else if (section_is_p (sectp
->name
, &names
->line
))
2216 dwarf2_per_objfile
->line
.s
.section
= sectp
;
2217 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
2219 else if (section_is_p (sectp
->name
, &names
->loc
))
2221 dwarf2_per_objfile
->loc
.s
.section
= sectp
;
2222 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
2224 else if (section_is_p (sectp
->name
, &names
->macinfo
))
2226 dwarf2_per_objfile
->macinfo
.s
.section
= sectp
;
2227 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
2229 else if (section_is_p (sectp
->name
, &names
->macro
))
2231 dwarf2_per_objfile
->macro
.s
.section
= sectp
;
2232 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
2234 else if (section_is_p (sectp
->name
, &names
->str
))
2236 dwarf2_per_objfile
->str
.s
.section
= sectp
;
2237 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
2239 else if (section_is_p (sectp
->name
, &names
->addr
))
2241 dwarf2_per_objfile
->addr
.s
.section
= sectp
;
2242 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
2244 else if (section_is_p (sectp
->name
, &names
->frame
))
2246 dwarf2_per_objfile
->frame
.s
.section
= sectp
;
2247 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
2249 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
2251 dwarf2_per_objfile
->eh_frame
.s
.section
= sectp
;
2252 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
2254 else if (section_is_p (sectp
->name
, &names
->ranges
))
2256 dwarf2_per_objfile
->ranges
.s
.section
= sectp
;
2257 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
2259 else if (section_is_p (sectp
->name
, &names
->types
))
2261 struct dwarf2_section_info type_section
;
2263 memset (&type_section
, 0, sizeof (type_section
));
2264 type_section
.s
.section
= sectp
;
2265 type_section
.size
= bfd_get_section_size (sectp
);
2267 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
2270 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
2272 dwarf2_per_objfile
->gdb_index
.s
.section
= sectp
;
2273 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
2276 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2277 && bfd_section_vma (abfd
, sectp
) == 0)
2278 dwarf2_per_objfile
->has_section_at_zero
= 1;
2281 /* A helper function that decides whether a section is empty,
2285 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2287 if (section
->is_virtual
)
2288 return section
->size
== 0;
2289 return section
->s
.section
== NULL
|| section
->size
== 0;
2292 /* Read the contents of the section INFO.
2293 OBJFILE is the main object file, but not necessarily the file where
2294 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2296 If the section is compressed, uncompress it before returning. */
2299 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2303 gdb_byte
*buf
, *retbuf
;
2307 info
->buffer
= NULL
;
2310 if (dwarf2_section_empty_p (info
))
2313 sectp
= get_section_bfd_section (info
);
2315 /* If this is a virtual section we need to read in the real one first. */
2316 if (info
->is_virtual
)
2318 struct dwarf2_section_info
*containing_section
=
2319 get_containing_section (info
);
2321 gdb_assert (sectp
!= NULL
);
2322 if ((sectp
->flags
& SEC_RELOC
) != 0)
2324 error (_("Dwarf Error: DWP format V2 with relocations is not"
2325 " supported in section %s [in module %s]"),
2326 get_section_name (info
), get_section_file_name (info
));
2328 dwarf2_read_section (objfile
, containing_section
);
2329 /* Other code should have already caught virtual sections that don't
2331 gdb_assert (info
->virtual_offset
+ info
->size
2332 <= containing_section
->size
);
2333 /* If the real section is empty or there was a problem reading the
2334 section we shouldn't get here. */
2335 gdb_assert (containing_section
->buffer
!= NULL
);
2336 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2340 /* If the section has relocations, we must read it ourselves.
2341 Otherwise we attach it to the BFD. */
2342 if ((sectp
->flags
& SEC_RELOC
) == 0)
2344 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2348 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2351 /* When debugging .o files, we may need to apply relocations; see
2352 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2353 We never compress sections in .o files, so we only need to
2354 try this when the section is not compressed. */
2355 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2358 info
->buffer
= retbuf
;
2362 abfd
= get_section_bfd_owner (info
);
2363 gdb_assert (abfd
!= NULL
);
2365 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2366 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2368 error (_("Dwarf Error: Can't read DWARF data"
2369 " in section %s [in module %s]"),
2370 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2374 /* A helper function that returns the size of a section in a safe way.
2375 If you are positive that the section has been read before using the
2376 size, then it is safe to refer to the dwarf2_section_info object's
2377 "size" field directly. In other cases, you must call this
2378 function, because for compressed sections the size field is not set
2379 correctly until the section has been read. */
2381 static bfd_size_type
2382 dwarf2_section_size (struct objfile
*objfile
,
2383 struct dwarf2_section_info
*info
)
2386 dwarf2_read_section (objfile
, info
);
2390 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2394 dwarf2_get_section_info (struct objfile
*objfile
,
2395 enum dwarf2_section_enum sect
,
2396 asection
**sectp
, const gdb_byte
**bufp
,
2397 bfd_size_type
*sizep
)
2399 struct dwarf2_per_objfile
*data
2400 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2401 dwarf2_objfile_data_key
);
2402 struct dwarf2_section_info
*info
;
2404 /* We may see an objfile without any DWARF, in which case we just
2415 case DWARF2_DEBUG_FRAME
:
2416 info
= &data
->frame
;
2418 case DWARF2_EH_FRAME
:
2419 info
= &data
->eh_frame
;
2422 gdb_assert_not_reached ("unexpected section");
2425 dwarf2_read_section (objfile
, info
);
2427 *sectp
= get_section_bfd_section (info
);
2428 *bufp
= info
->buffer
;
2429 *sizep
= info
->size
;
2432 /* A helper function to find the sections for a .dwz file. */
2435 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2437 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2439 /* Note that we only support the standard ELF names, because .dwz
2440 is ELF-only (at the time of writing). */
2441 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2443 dwz_file
->abbrev
.s
.section
= sectp
;
2444 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2446 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2448 dwz_file
->info
.s
.section
= sectp
;
2449 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2451 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2453 dwz_file
->str
.s
.section
= sectp
;
2454 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2456 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2458 dwz_file
->line
.s
.section
= sectp
;
2459 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2461 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2463 dwz_file
->macro
.s
.section
= sectp
;
2464 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2466 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2468 dwz_file
->gdb_index
.s
.section
= sectp
;
2469 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2473 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2474 there is no .gnu_debugaltlink section in the file. Error if there
2475 is such a section but the file cannot be found. */
2477 static struct dwz_file
*
2478 dwarf2_get_dwz_file (void)
2482 struct cleanup
*cleanup
;
2483 const char *filename
;
2484 struct dwz_file
*result
;
2485 bfd_size_type buildid_len_arg
;
2489 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2490 return dwarf2_per_objfile
->dwz_file
;
2492 bfd_set_error (bfd_error_no_error
);
2493 data
= bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2494 &buildid_len_arg
, &buildid
);
2497 if (bfd_get_error () == bfd_error_no_error
)
2499 error (_("could not read '.gnu_debugaltlink' section: %s"),
2500 bfd_errmsg (bfd_get_error ()));
2502 cleanup
= make_cleanup (xfree
, data
);
2503 make_cleanup (xfree
, buildid
);
2505 buildid_len
= (size_t) buildid_len_arg
;
2507 filename
= (const char *) data
;
2508 if (!IS_ABSOLUTE_PATH (filename
))
2510 char *abs
= gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2513 make_cleanup (xfree
, abs
);
2514 abs
= ldirname (abs
);
2515 make_cleanup (xfree
, abs
);
2517 rel
= concat (abs
, SLASH_STRING
, filename
, (char *) NULL
);
2518 make_cleanup (xfree
, rel
);
2522 /* First try the file name given in the section. If that doesn't
2523 work, try to use the build-id instead. */
2524 dwz_bfd
= gdb_bfd_open (filename
, gnutarget
, -1);
2525 if (dwz_bfd
!= NULL
)
2527 if (!build_id_verify (dwz_bfd
, buildid_len
, buildid
))
2529 gdb_bfd_unref (dwz_bfd
);
2534 if (dwz_bfd
== NULL
)
2535 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2537 if (dwz_bfd
== NULL
)
2538 error (_("could not find '.gnu_debugaltlink' file for %s"),
2539 objfile_name (dwarf2_per_objfile
->objfile
));
2541 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2543 result
->dwz_bfd
= dwz_bfd
;
2545 bfd_map_over_sections (dwz_bfd
, locate_dwz_sections
, result
);
2547 do_cleanups (cleanup
);
2549 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, dwz_bfd
);
2550 dwarf2_per_objfile
->dwz_file
= result
;
2554 /* DWARF quick_symbols_functions support. */
2556 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2557 unique line tables, so we maintain a separate table of all .debug_line
2558 derived entries to support the sharing.
2559 All the quick functions need is the list of file names. We discard the
2560 line_header when we're done and don't need to record it here. */
2561 struct quick_file_names
2563 /* The data used to construct the hash key. */
2564 struct stmt_list_hash hash
;
2566 /* The number of entries in file_names, real_names. */
2567 unsigned int num_file_names
;
2569 /* The file names from the line table, after being run through
2571 const char **file_names
;
2573 /* The file names from the line table after being run through
2574 gdb_realpath. These are computed lazily. */
2575 const char **real_names
;
2578 /* When using the index (and thus not using psymtabs), each CU has an
2579 object of this type. This is used to hold information needed by
2580 the various "quick" methods. */
2581 struct dwarf2_per_cu_quick_data
2583 /* The file table. This can be NULL if there was no file table
2584 or it's currently not read in.
2585 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2586 struct quick_file_names
*file_names
;
2588 /* The corresponding symbol table. This is NULL if symbols for this
2589 CU have not yet been read. */
2590 struct compunit_symtab
*compunit_symtab
;
2592 /* A temporary mark bit used when iterating over all CUs in
2593 expand_symtabs_matching. */
2594 unsigned int mark
: 1;
2596 /* True if we've tried to read the file table and found there isn't one.
2597 There will be no point in trying to read it again next time. */
2598 unsigned int no_file_data
: 1;
2601 /* Utility hash function for a stmt_list_hash. */
2604 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2608 if (stmt_list_hash
->dwo_unit
!= NULL
)
2609 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2610 v
+= stmt_list_hash
->line_offset
.sect_off
;
2614 /* Utility equality function for a stmt_list_hash. */
2617 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2618 const struct stmt_list_hash
*rhs
)
2620 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2622 if (lhs
->dwo_unit
!= NULL
2623 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2626 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2629 /* Hash function for a quick_file_names. */
2632 hash_file_name_entry (const void *e
)
2634 const struct quick_file_names
*file_data
2635 = (const struct quick_file_names
*) e
;
2637 return hash_stmt_list_entry (&file_data
->hash
);
2640 /* Equality function for a quick_file_names. */
2643 eq_file_name_entry (const void *a
, const void *b
)
2645 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2646 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2648 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2651 /* Delete function for a quick_file_names. */
2654 delete_file_name_entry (void *e
)
2656 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2659 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2661 xfree ((void*) file_data
->file_names
[i
]);
2662 if (file_data
->real_names
)
2663 xfree ((void*) file_data
->real_names
[i
]);
2666 /* The space for the struct itself lives on objfile_obstack,
2667 so we don't free it here. */
2670 /* Create a quick_file_names hash table. */
2673 create_quick_file_names_table (unsigned int nr_initial_entries
)
2675 return htab_create_alloc (nr_initial_entries
,
2676 hash_file_name_entry
, eq_file_name_entry
,
2677 delete_file_name_entry
, xcalloc
, xfree
);
2680 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2681 have to be created afterwards. You should call age_cached_comp_units after
2682 processing PER_CU->CU. dw2_setup must have been already called. */
2685 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2687 if (per_cu
->is_debug_types
)
2688 load_full_type_unit (per_cu
);
2690 load_full_comp_unit (per_cu
, language_minimal
);
2692 if (per_cu
->cu
== NULL
)
2693 return; /* Dummy CU. */
2695 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2698 /* Read in the symbols for PER_CU. */
2701 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2703 struct cleanup
*back_to
;
2705 /* Skip type_unit_groups, reading the type units they contain
2706 is handled elsewhere. */
2707 if (IS_TYPE_UNIT_GROUP (per_cu
))
2710 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2712 if (dwarf2_per_objfile
->using_index
2713 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2714 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2716 queue_comp_unit (per_cu
, language_minimal
);
2719 /* If we just loaded a CU from a DWO, and we're working with an index
2720 that may badly handle TUs, load all the TUs in that DWO as well.
2721 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2722 if (!per_cu
->is_debug_types
2723 && per_cu
->cu
!= NULL
2724 && per_cu
->cu
->dwo_unit
!= NULL
2725 && dwarf2_per_objfile
->index_table
!= NULL
2726 && dwarf2_per_objfile
->index_table
->version
<= 7
2727 /* DWP files aren't supported yet. */
2728 && get_dwp_file () == NULL
)
2729 queue_and_load_all_dwo_tus (per_cu
);
2734 /* Age the cache, releasing compilation units that have not
2735 been used recently. */
2736 age_cached_comp_units ();
2738 do_cleanups (back_to
);
2741 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2742 the objfile from which this CU came. Returns the resulting symbol
2745 static struct compunit_symtab
*
2746 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2748 gdb_assert (dwarf2_per_objfile
->using_index
);
2749 if (!per_cu
->v
.quick
->compunit_symtab
)
2751 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2752 increment_reading_symtab ();
2753 dw2_do_instantiate_symtab (per_cu
);
2754 process_cu_includes ();
2755 do_cleanups (back_to
);
2758 return per_cu
->v
.quick
->compunit_symtab
;
2761 /* Return the CU/TU given its index.
2763 This is intended for loops like:
2765 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2766 + dwarf2_per_objfile->n_type_units); ++i)
2768 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
2774 static struct dwarf2_per_cu_data
*
2775 dw2_get_cutu (int index
)
2777 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2779 index
-= dwarf2_per_objfile
->n_comp_units
;
2780 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2781 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2784 return dwarf2_per_objfile
->all_comp_units
[index
];
2787 /* Return the CU given its index.
2788 This differs from dw2_get_cutu in that it's for when you know INDEX
2791 static struct dwarf2_per_cu_data
*
2792 dw2_get_cu (int index
)
2794 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
2796 return dwarf2_per_objfile
->all_comp_units
[index
];
2799 /* A helper for create_cus_from_index that handles a given list of
2803 create_cus_from_index_list (struct objfile
*objfile
,
2804 const gdb_byte
*cu_list
, offset_type n_elements
,
2805 struct dwarf2_section_info
*section
,
2811 for (i
= 0; i
< n_elements
; i
+= 2)
2813 struct dwarf2_per_cu_data
*the_cu
;
2814 ULONGEST offset
, length
;
2816 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2817 offset
= extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2818 length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2821 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2822 struct dwarf2_per_cu_data
);
2823 the_cu
->offset
.sect_off
= offset
;
2824 the_cu
->length
= length
;
2825 the_cu
->objfile
= objfile
;
2826 the_cu
->section
= section
;
2827 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2828 struct dwarf2_per_cu_quick_data
);
2829 the_cu
->is_dwz
= is_dwz
;
2830 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2834 /* Read the CU list from the mapped index, and use it to create all
2835 the CU objects for this objfile. */
2838 create_cus_from_index (struct objfile
*objfile
,
2839 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2840 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2842 struct dwz_file
*dwz
;
2844 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2845 dwarf2_per_objfile
->all_comp_units
=
2846 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
2847 dwarf2_per_objfile
->n_comp_units
);
2849 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2850 &dwarf2_per_objfile
->info
, 0, 0);
2852 if (dwz_elements
== 0)
2855 dwz
= dwarf2_get_dwz_file ();
2856 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
2857 cu_list_elements
/ 2);
2860 /* Create the signatured type hash table from the index. */
2863 create_signatured_type_table_from_index (struct objfile
*objfile
,
2864 struct dwarf2_section_info
*section
,
2865 const gdb_byte
*bytes
,
2866 offset_type elements
)
2869 htab_t sig_types_hash
;
2871 dwarf2_per_objfile
->n_type_units
2872 = dwarf2_per_objfile
->n_allocated_type_units
2874 dwarf2_per_objfile
->all_type_units
=
2875 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
2877 sig_types_hash
= allocate_signatured_type_table (objfile
);
2879 for (i
= 0; i
< elements
; i
+= 3)
2881 struct signatured_type
*sig_type
;
2882 ULONGEST offset
, type_offset_in_tu
, signature
;
2885 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2886 offset
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2887 type_offset_in_tu
= extract_unsigned_integer (bytes
+ 8, 8,
2889 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2892 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2893 struct signatured_type
);
2894 sig_type
->signature
= signature
;
2895 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2896 sig_type
->per_cu
.is_debug_types
= 1;
2897 sig_type
->per_cu
.section
= section
;
2898 sig_type
->per_cu
.offset
.sect_off
= offset
;
2899 sig_type
->per_cu
.objfile
= objfile
;
2900 sig_type
->per_cu
.v
.quick
2901 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2902 struct dwarf2_per_cu_quick_data
);
2904 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2907 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2910 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2913 /* Read the address map data from the mapped index, and use it to
2914 populate the objfile's psymtabs_addrmap. */
2917 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2919 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2920 const gdb_byte
*iter
, *end
;
2921 struct obstack temp_obstack
;
2922 struct addrmap
*mutable_map
;
2923 struct cleanup
*cleanup
;
2926 obstack_init (&temp_obstack
);
2927 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2928 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2930 iter
= index
->address_table
;
2931 end
= iter
+ index
->address_table_size
;
2933 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2937 ULONGEST hi
, lo
, cu_index
;
2938 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2940 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2942 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2947 complaint (&symfile_complaints
,
2948 _(".gdb_index address table has invalid range (%s - %s)"),
2949 hex_string (lo
), hex_string (hi
));
2953 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
2955 complaint (&symfile_complaints
,
2956 _(".gdb_index address table has invalid CU number %u"),
2957 (unsigned) cu_index
);
2961 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
2962 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
2963 addrmap_set_empty (mutable_map
, lo
, hi
- 1, dw2_get_cutu (cu_index
));
2966 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2967 &objfile
->objfile_obstack
);
2968 do_cleanups (cleanup
);
2971 /* The hash function for strings in the mapped index. This is the same as
2972 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2973 implementation. This is necessary because the hash function is tied to the
2974 format of the mapped index file. The hash values do not have to match with
2977 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2980 mapped_index_string_hash (int index_version
, const void *p
)
2982 const unsigned char *str
= (const unsigned char *) p
;
2986 while ((c
= *str
++) != 0)
2988 if (index_version
>= 5)
2990 r
= r
* 67 + c
- 113;
2996 /* Find a slot in the mapped index INDEX for the object named NAME.
2997 If NAME is found, set *VEC_OUT to point to the CU vector in the
2998 constant pool and return 1. If NAME cannot be found, return 0. */
3001 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3002 offset_type
**vec_out
)
3004 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3006 offset_type slot
, step
;
3007 int (*cmp
) (const char *, const char *);
3009 if (current_language
->la_language
== language_cplus
3010 || current_language
->la_language
== language_java
3011 || current_language
->la_language
== language_fortran
3012 || current_language
->la_language
== language_d
)
3014 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3017 if (strchr (name
, '(') != NULL
)
3019 char *without_params
= cp_remove_params (name
);
3021 if (without_params
!= NULL
)
3023 make_cleanup (xfree
, without_params
);
3024 name
= without_params
;
3029 /* Index version 4 did not support case insensitive searches. But the
3030 indices for case insensitive languages are built in lowercase, therefore
3031 simulate our NAME being searched is also lowercased. */
3032 hash
= mapped_index_string_hash ((index
->version
== 4
3033 && case_sensitivity
== case_sensitive_off
3034 ? 5 : index
->version
),
3037 slot
= hash
& (index
->symbol_table_slots
- 1);
3038 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
3039 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3043 /* Convert a slot number to an offset into the table. */
3044 offset_type i
= 2 * slot
;
3046 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
3048 do_cleanups (back_to
);
3052 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
3053 if (!cmp (name
, str
))
3055 *vec_out
= (offset_type
*) (index
->constant_pool
3056 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
3057 do_cleanups (back_to
);
3061 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
3065 /* A helper function that reads the .gdb_index from SECTION and fills
3066 in MAP. FILENAME is the name of the file containing the section;
3067 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3068 ok to use deprecated sections.
3070 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3071 out parameters that are filled in with information about the CU and
3072 TU lists in the section.
3074 Returns 1 if all went well, 0 otherwise. */
3077 read_index_from_section (struct objfile
*objfile
,
3078 const char *filename
,
3080 struct dwarf2_section_info
*section
,
3081 struct mapped_index
*map
,
3082 const gdb_byte
**cu_list
,
3083 offset_type
*cu_list_elements
,
3084 const gdb_byte
**types_list
,
3085 offset_type
*types_list_elements
)
3087 const gdb_byte
*addr
;
3088 offset_type version
;
3089 offset_type
*metadata
;
3092 if (dwarf2_section_empty_p (section
))
3095 /* Older elfutils strip versions could keep the section in the main
3096 executable while splitting it for the separate debug info file. */
3097 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3100 dwarf2_read_section (objfile
, section
);
3102 addr
= section
->buffer
;
3103 /* Version check. */
3104 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3105 /* Versions earlier than 3 emitted every copy of a psymbol. This
3106 causes the index to behave very poorly for certain requests. Version 3
3107 contained incomplete addrmap. So, it seems better to just ignore such
3111 static int warning_printed
= 0;
3112 if (!warning_printed
)
3114 warning (_("Skipping obsolete .gdb_index section in %s."),
3116 warning_printed
= 1;
3120 /* Index version 4 uses a different hash function than index version
3123 Versions earlier than 6 did not emit psymbols for inlined
3124 functions. Using these files will cause GDB not to be able to
3125 set breakpoints on inlined functions by name, so we ignore these
3126 indices unless the user has done
3127 "set use-deprecated-index-sections on". */
3128 if (version
< 6 && !deprecated_ok
)
3130 static int warning_printed
= 0;
3131 if (!warning_printed
)
3134 Skipping deprecated .gdb_index section in %s.\n\
3135 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3136 to use the section anyway."),
3138 warning_printed
= 1;
3142 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3143 of the TU (for symbols coming from TUs),
3144 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3145 Plus gold-generated indices can have duplicate entries for global symbols,
3146 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3147 These are just performance bugs, and we can't distinguish gdb-generated
3148 indices from gold-generated ones, so issue no warning here. */
3150 /* Indexes with higher version than the one supported by GDB may be no
3151 longer backward compatible. */
3155 map
->version
= version
;
3156 map
->total_size
= section
->size
;
3158 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3161 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3162 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3166 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3167 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3168 - MAYBE_SWAP (metadata
[i
]))
3172 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3173 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
3174 - MAYBE_SWAP (metadata
[i
]));
3177 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
3178 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
3179 - MAYBE_SWAP (metadata
[i
]))
3180 / (2 * sizeof (offset_type
)));
3183 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3189 /* Read the index file. If everything went ok, initialize the "quick"
3190 elements of all the CUs and return 1. Otherwise, return 0. */
3193 dwarf2_read_index (struct objfile
*objfile
)
3195 struct mapped_index local_map
, *map
;
3196 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3197 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3198 struct dwz_file
*dwz
;
3200 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3201 use_deprecated_index_sections
,
3202 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3203 &cu_list
, &cu_list_elements
,
3204 &types_list
, &types_list_elements
))
3207 /* Don't use the index if it's empty. */
3208 if (local_map
.symbol_table_slots
== 0)
3211 /* If there is a .dwz file, read it so we can get its CU list as
3213 dwz
= dwarf2_get_dwz_file ();
3216 struct mapped_index dwz_map
;
3217 const gdb_byte
*dwz_types_ignore
;
3218 offset_type dwz_types_elements_ignore
;
3220 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3222 &dwz
->gdb_index
, &dwz_map
,
3223 &dwz_list
, &dwz_list_elements
,
3225 &dwz_types_elements_ignore
))
3227 warning (_("could not read '.gdb_index' section from %s; skipping"),
3228 bfd_get_filename (dwz
->dwz_bfd
));
3233 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3236 if (types_list_elements
)
3238 struct dwarf2_section_info
*section
;
3240 /* We can only handle a single .debug_types when we have an
3242 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3245 section
= VEC_index (dwarf2_section_info_def
,
3246 dwarf2_per_objfile
->types
, 0);
3248 create_signatured_type_table_from_index (objfile
, section
, types_list
,
3249 types_list_elements
);
3252 create_addrmap_from_index (objfile
, &local_map
);
3254 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3257 dwarf2_per_objfile
->index_table
= map
;
3258 dwarf2_per_objfile
->using_index
= 1;
3259 dwarf2_per_objfile
->quick_file_names_table
=
3260 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3265 /* A helper for the "quick" functions which sets the global
3266 dwarf2_per_objfile according to OBJFILE. */
3269 dw2_setup (struct objfile
*objfile
)
3271 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
3272 objfile_data (objfile
, dwarf2_objfile_data_key
));
3273 gdb_assert (dwarf2_per_objfile
);
3276 /* die_reader_func for dw2_get_file_names. */
3279 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3280 const gdb_byte
*info_ptr
,
3281 struct die_info
*comp_unit_die
,
3285 struct dwarf2_cu
*cu
= reader
->cu
;
3286 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3287 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3288 struct dwarf2_per_cu_data
*lh_cu
;
3289 struct line_header
*lh
;
3290 struct attribute
*attr
;
3292 const char *name
, *comp_dir
;
3294 struct quick_file_names
*qfn
;
3295 unsigned int line_offset
;
3297 gdb_assert (! this_cu
->is_debug_types
);
3299 /* Our callers never want to match partial units -- instead they
3300 will match the enclosing full CU. */
3301 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3303 this_cu
->v
.quick
->no_file_data
= 1;
3312 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3315 struct quick_file_names find_entry
;
3317 line_offset
= DW_UNSND (attr
);
3319 /* We may have already read in this line header (TU line header sharing).
3320 If we have we're done. */
3321 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3322 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
3323 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3324 &find_entry
, INSERT
);
3327 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3331 lh
= dwarf_decode_line_header (line_offset
, cu
);
3335 lh_cu
->v
.quick
->no_file_data
= 1;
3339 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3340 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3341 qfn
->hash
.line_offset
.sect_off
= line_offset
;
3342 gdb_assert (slot
!= NULL
);
3345 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
3347 qfn
->num_file_names
= lh
->num_file_names
;
3349 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->num_file_names
);
3350 for (i
= 0; i
< lh
->num_file_names
; ++i
)
3351 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
3352 qfn
->real_names
= NULL
;
3354 free_line_header (lh
);
3356 lh_cu
->v
.quick
->file_names
= qfn
;
3359 /* A helper for the "quick" functions which attempts to read the line
3360 table for THIS_CU. */
3362 static struct quick_file_names
*
3363 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3365 /* This should never be called for TUs. */
3366 gdb_assert (! this_cu
->is_debug_types
);
3367 /* Nor type unit groups. */
3368 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3370 if (this_cu
->v
.quick
->file_names
!= NULL
)
3371 return this_cu
->v
.quick
->file_names
;
3372 /* If we know there is no line data, no point in looking again. */
3373 if (this_cu
->v
.quick
->no_file_data
)
3376 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3378 if (this_cu
->v
.quick
->no_file_data
)
3380 return this_cu
->v
.quick
->file_names
;
3383 /* A helper for the "quick" functions which computes and caches the
3384 real path for a given file name from the line table. */
3387 dw2_get_real_path (struct objfile
*objfile
,
3388 struct quick_file_names
*qfn
, int index
)
3390 if (qfn
->real_names
== NULL
)
3391 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3392 qfn
->num_file_names
, const char *);
3394 if (qfn
->real_names
[index
] == NULL
)
3395 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
3397 return qfn
->real_names
[index
];
3400 static struct symtab
*
3401 dw2_find_last_source_symtab (struct objfile
*objfile
)
3403 struct compunit_symtab
*cust
;
3406 dw2_setup (objfile
);
3407 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3408 cust
= dw2_instantiate_symtab (dw2_get_cutu (index
));
3411 return compunit_primary_filetab (cust
);
3414 /* Traversal function for dw2_forget_cached_source_info. */
3417 dw2_free_cached_file_names (void **slot
, void *info
)
3419 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3421 if (file_data
->real_names
)
3425 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3427 xfree ((void*) file_data
->real_names
[i
]);
3428 file_data
->real_names
[i
] = NULL
;
3436 dw2_forget_cached_source_info (struct objfile
*objfile
)
3438 dw2_setup (objfile
);
3440 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3441 dw2_free_cached_file_names
, NULL
);
3444 /* Helper function for dw2_map_symtabs_matching_filename that expands
3445 the symtabs and calls the iterator. */
3448 dw2_map_expand_apply (struct objfile
*objfile
,
3449 struct dwarf2_per_cu_data
*per_cu
,
3450 const char *name
, const char *real_path
,
3451 int (*callback
) (struct symtab
*, void *),
3454 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3456 /* Don't visit already-expanded CUs. */
3457 if (per_cu
->v
.quick
->compunit_symtab
)
3460 /* This may expand more than one symtab, and we want to iterate over
3462 dw2_instantiate_symtab (per_cu
);
3464 return iterate_over_some_symtabs (name
, real_path
, callback
, data
,
3465 objfile
->compunit_symtabs
, last_made
);
3468 /* Implementation of the map_symtabs_matching_filename method. */
3471 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
3472 const char *real_path
,
3473 int (*callback
) (struct symtab
*, void *),
3477 const char *name_basename
= lbasename (name
);
3479 dw2_setup (objfile
);
3481 /* The rule is CUs specify all the files, including those used by
3482 any TU, so there's no need to scan TUs here. */
3484 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3487 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3488 struct quick_file_names
*file_data
;
3490 /* We only need to look at symtabs not already expanded. */
3491 if (per_cu
->v
.quick
->compunit_symtab
)
3494 file_data
= dw2_get_file_names (per_cu
);
3495 if (file_data
== NULL
)
3498 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3500 const char *this_name
= file_data
->file_names
[j
];
3501 const char *this_real_name
;
3503 if (compare_filenames_for_search (this_name
, name
))
3505 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3511 /* Before we invoke realpath, which can get expensive when many
3512 files are involved, do a quick comparison of the basenames. */
3513 if (! basenames_may_differ
3514 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3517 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3518 if (compare_filenames_for_search (this_real_name
, name
))
3520 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3526 if (real_path
!= NULL
)
3528 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3529 gdb_assert (IS_ABSOLUTE_PATH (name
));
3530 if (this_real_name
!= NULL
3531 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3533 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3545 /* Struct used to manage iterating over all CUs looking for a symbol. */
3547 struct dw2_symtab_iterator
3549 /* The internalized form of .gdb_index. */
3550 struct mapped_index
*index
;
3551 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3552 int want_specific_block
;
3553 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3554 Unused if !WANT_SPECIFIC_BLOCK. */
3556 /* The kind of symbol we're looking for. */
3558 /* The list of CUs from the index entry of the symbol,
3559 or NULL if not found. */
3561 /* The next element in VEC to look at. */
3563 /* The number of elements in VEC, or zero if there is no match. */
3565 /* Have we seen a global version of the symbol?
3566 If so we can ignore all further global instances.
3567 This is to work around gold/15646, inefficient gold-generated
3572 /* Initialize the index symtab iterator ITER.
3573 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3574 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3577 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3578 struct mapped_index
*index
,
3579 int want_specific_block
,
3584 iter
->index
= index
;
3585 iter
->want_specific_block
= want_specific_block
;
3586 iter
->block_index
= block_index
;
3587 iter
->domain
= domain
;
3589 iter
->global_seen
= 0;
3591 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3592 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3600 /* Return the next matching CU or NULL if there are no more. */
3602 static struct dwarf2_per_cu_data
*
3603 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3605 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3607 offset_type cu_index_and_attrs
=
3608 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3609 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3610 struct dwarf2_per_cu_data
*per_cu
;
3611 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3612 /* This value is only valid for index versions >= 7. */
3613 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3614 gdb_index_symbol_kind symbol_kind
=
3615 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3616 /* Only check the symbol attributes if they're present.
3617 Indices prior to version 7 don't record them,
3618 and indices >= 7 may elide them for certain symbols
3619 (gold does this). */
3621 (iter
->index
->version
>= 7
3622 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3624 /* Don't crash on bad data. */
3625 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3626 + dwarf2_per_objfile
->n_type_units
))
3628 complaint (&symfile_complaints
,
3629 _(".gdb_index entry has bad CU index"
3631 objfile_name (dwarf2_per_objfile
->objfile
));
3635 per_cu
= dw2_get_cutu (cu_index
);
3637 /* Skip if already read in. */
3638 if (per_cu
->v
.quick
->compunit_symtab
)
3641 /* Check static vs global. */
3644 if (iter
->want_specific_block
3645 && want_static
!= is_static
)
3647 /* Work around gold/15646. */
3648 if (!is_static
&& iter
->global_seen
)
3651 iter
->global_seen
= 1;
3654 /* Only check the symbol's kind if it has one. */
3657 switch (iter
->domain
)
3660 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3661 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3662 /* Some types are also in VAR_DOMAIN. */
3663 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3667 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3671 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3686 static struct compunit_symtab
*
3687 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3688 const char *name
, domain_enum domain
)
3690 struct compunit_symtab
*stab_best
= NULL
;
3691 struct mapped_index
*index
;
3693 dw2_setup (objfile
);
3695 index
= dwarf2_per_objfile
->index_table
;
3697 /* index is NULL if OBJF_READNOW. */
3700 struct dw2_symtab_iterator iter
;
3701 struct dwarf2_per_cu_data
*per_cu
;
3703 dw2_symtab_iter_init (&iter
, index
, 1, block_index
, domain
, name
);
3705 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3707 struct symbol
*sym
, *with_opaque
= NULL
;
3708 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
3709 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3710 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3712 sym
= block_find_symbol (block
, name
, domain
,
3713 block_find_non_opaque_type_preferred
,
3716 /* Some caution must be observed with overloaded functions
3717 and methods, since the index will not contain any overload
3718 information (but NAME might contain it). */
3721 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
3723 if (with_opaque
!= NULL
3724 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
3727 /* Keep looking through other CUs. */
3735 dw2_print_stats (struct objfile
*objfile
)
3737 int i
, total
, count
;
3739 dw2_setup (objfile
);
3740 total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
3742 for (i
= 0; i
< total
; ++i
)
3744 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3746 if (!per_cu
->v
.quick
->compunit_symtab
)
3749 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3750 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3753 /* This dumps minimal information about the index.
3754 It is called via "mt print objfiles".
3755 One use is to verify .gdb_index has been loaded by the
3756 gdb.dwarf2/gdb-index.exp testcase. */
3759 dw2_dump (struct objfile
*objfile
)
3761 dw2_setup (objfile
);
3762 gdb_assert (dwarf2_per_objfile
->using_index
);
3763 printf_filtered (".gdb_index:");
3764 if (dwarf2_per_objfile
->index_table
!= NULL
)
3766 printf_filtered (" version %d\n",
3767 dwarf2_per_objfile
->index_table
->version
);
3770 printf_filtered (" faked for \"readnow\"\n");
3771 printf_filtered ("\n");
3775 dw2_relocate (struct objfile
*objfile
,
3776 const struct section_offsets
*new_offsets
,
3777 const struct section_offsets
*delta
)
3779 /* There's nothing to relocate here. */
3783 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3784 const char *func_name
)
3786 struct mapped_index
*index
;
3788 dw2_setup (objfile
);
3790 index
= dwarf2_per_objfile
->index_table
;
3792 /* index is NULL if OBJF_READNOW. */
3795 struct dw2_symtab_iterator iter
;
3796 struct dwarf2_per_cu_data
*per_cu
;
3798 /* Note: It doesn't matter what we pass for block_index here. */
3799 dw2_symtab_iter_init (&iter
, index
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
3802 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3803 dw2_instantiate_symtab (per_cu
);
3808 dw2_expand_all_symtabs (struct objfile
*objfile
)
3812 dw2_setup (objfile
);
3814 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3815 + dwarf2_per_objfile
->n_type_units
); ++i
)
3817 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3819 dw2_instantiate_symtab (per_cu
);
3824 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3825 const char *fullname
)
3829 dw2_setup (objfile
);
3831 /* We don't need to consider type units here.
3832 This is only called for examining code, e.g. expand_line_sal.
3833 There can be an order of magnitude (or more) more type units
3834 than comp units, and we avoid them if we can. */
3836 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3839 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3840 struct quick_file_names
*file_data
;
3842 /* We only need to look at symtabs not already expanded. */
3843 if (per_cu
->v
.quick
->compunit_symtab
)
3846 file_data
= dw2_get_file_names (per_cu
);
3847 if (file_data
== NULL
)
3850 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3852 const char *this_fullname
= file_data
->file_names
[j
];
3854 if (filename_cmp (this_fullname
, fullname
) == 0)
3856 dw2_instantiate_symtab (per_cu
);
3864 dw2_map_matching_symbols (struct objfile
*objfile
,
3865 const char * name
, domain_enum domain
,
3867 int (*callback
) (struct block
*,
3868 struct symbol
*, void *),
3869 void *data
, symbol_compare_ftype
*match
,
3870 symbol_compare_ftype
*ordered_compare
)
3872 /* Currently unimplemented; used for Ada. The function can be called if the
3873 current language is Ada for a non-Ada objfile using GNU index. As Ada
3874 does not look for non-Ada symbols this function should just return. */
3878 dw2_expand_symtabs_matching
3879 (struct objfile
*objfile
,
3880 expand_symtabs_file_matcher_ftype
*file_matcher
,
3881 expand_symtabs_symbol_matcher_ftype
*symbol_matcher
,
3882 expand_symtabs_exp_notify_ftype
*expansion_notify
,
3883 enum search_domain kind
,
3888 struct mapped_index
*index
;
3890 dw2_setup (objfile
);
3892 /* index_table is NULL if OBJF_READNOW. */
3893 if (!dwarf2_per_objfile
->index_table
)
3895 index
= dwarf2_per_objfile
->index_table
;
3897 if (file_matcher
!= NULL
)
3899 struct cleanup
*cleanup
;
3900 htab_t visited_found
, visited_not_found
;
3902 visited_found
= htab_create_alloc (10,
3903 htab_hash_pointer
, htab_eq_pointer
,
3904 NULL
, xcalloc
, xfree
);
3905 cleanup
= make_cleanup_htab_delete (visited_found
);
3906 visited_not_found
= htab_create_alloc (10,
3907 htab_hash_pointer
, htab_eq_pointer
,
3908 NULL
, xcalloc
, xfree
);
3909 make_cleanup_htab_delete (visited_not_found
);
3911 /* The rule is CUs specify all the files, including those used by
3912 any TU, so there's no need to scan TUs here. */
3914 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3917 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3918 struct quick_file_names
*file_data
;
3923 per_cu
->v
.quick
->mark
= 0;
3925 /* We only need to look at symtabs not already expanded. */
3926 if (per_cu
->v
.quick
->compunit_symtab
)
3929 file_data
= dw2_get_file_names (per_cu
);
3930 if (file_data
== NULL
)
3933 if (htab_find (visited_not_found
, file_data
) != NULL
)
3935 else if (htab_find (visited_found
, file_data
) != NULL
)
3937 per_cu
->v
.quick
->mark
= 1;
3941 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3943 const char *this_real_name
;
3945 if (file_matcher (file_data
->file_names
[j
], data
, 0))
3947 per_cu
->v
.quick
->mark
= 1;
3951 /* Before we invoke realpath, which can get expensive when many
3952 files are involved, do a quick comparison of the basenames. */
3953 if (!basenames_may_differ
3954 && !file_matcher (lbasename (file_data
->file_names
[j
]),
3958 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3959 if (file_matcher (this_real_name
, data
, 0))
3961 per_cu
->v
.quick
->mark
= 1;
3966 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3968 : visited_not_found
,
3973 do_cleanups (cleanup
);
3976 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3978 offset_type idx
= 2 * iter
;
3980 offset_type
*vec
, vec_len
, vec_idx
;
3981 int global_seen
= 0;
3985 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3988 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3990 if (! (*symbol_matcher
) (name
, data
))
3993 /* The name was matched, now expand corresponding CUs that were
3995 vec
= (offset_type
*) (index
->constant_pool
3996 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3997 vec_len
= MAYBE_SWAP (vec
[0]);
3998 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4000 struct dwarf2_per_cu_data
*per_cu
;
4001 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4002 /* This value is only valid for index versions >= 7. */
4003 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4004 gdb_index_symbol_kind symbol_kind
=
4005 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4006 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4007 /* Only check the symbol attributes if they're present.
4008 Indices prior to version 7 don't record them,
4009 and indices >= 7 may elide them for certain symbols
4010 (gold does this). */
4012 (index
->version
>= 7
4013 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4015 /* Work around gold/15646. */
4018 if (!is_static
&& global_seen
)
4024 /* Only check the symbol's kind if it has one. */
4029 case VARIABLES_DOMAIN
:
4030 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4033 case FUNCTIONS_DOMAIN
:
4034 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4038 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4046 /* Don't crash on bad data. */
4047 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
4048 + dwarf2_per_objfile
->n_type_units
))
4050 complaint (&symfile_complaints
,
4051 _(".gdb_index entry has bad CU index"
4052 " [in module %s]"), objfile_name (objfile
));
4056 per_cu
= dw2_get_cutu (cu_index
);
4057 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4059 int symtab_was_null
=
4060 (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4062 dw2_instantiate_symtab (per_cu
);
4064 if (expansion_notify
!= NULL
4066 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4068 expansion_notify (per_cu
->v
.quick
->compunit_symtab
,
4076 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4079 static struct compunit_symtab
*
4080 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4085 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4086 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4089 if (cust
->includes
== NULL
)
4092 for (i
= 0; cust
->includes
[i
]; ++i
)
4094 struct compunit_symtab
*s
= cust
->includes
[i
];
4096 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4104 static struct compunit_symtab
*
4105 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4106 struct bound_minimal_symbol msymbol
,
4108 struct obj_section
*section
,
4111 struct dwarf2_per_cu_data
*data
;
4112 struct compunit_symtab
*result
;
4114 dw2_setup (objfile
);
4116 if (!objfile
->psymtabs_addrmap
)
4119 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
4124 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4125 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4126 paddress (get_objfile_arch (objfile
), pc
));
4129 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
4131 gdb_assert (result
!= NULL
);
4136 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4137 void *data
, int need_fullname
)
4140 struct cleanup
*cleanup
;
4141 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
4142 NULL
, xcalloc
, xfree
);
4144 cleanup
= make_cleanup_htab_delete (visited
);
4145 dw2_setup (objfile
);
4147 /* The rule is CUs specify all the files, including those used by
4148 any TU, so there's no need to scan TUs here.
4149 We can ignore file names coming from already-expanded CUs. */
4151 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4153 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4155 if (per_cu
->v
.quick
->compunit_symtab
)
4157 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
4160 *slot
= per_cu
->v
.quick
->file_names
;
4164 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4167 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4168 struct quick_file_names
*file_data
;
4171 /* We only need to look at symtabs not already expanded. */
4172 if (per_cu
->v
.quick
->compunit_symtab
)
4175 file_data
= dw2_get_file_names (per_cu
);
4176 if (file_data
== NULL
)
4179 slot
= htab_find_slot (visited
, file_data
, INSERT
);
4182 /* Already visited. */
4187 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4189 const char *this_real_name
;
4192 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4194 this_real_name
= NULL
;
4195 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
4199 do_cleanups (cleanup
);
4203 dw2_has_symbols (struct objfile
*objfile
)
4208 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4211 dw2_find_last_source_symtab
,
4212 dw2_forget_cached_source_info
,
4213 dw2_map_symtabs_matching_filename
,
4218 dw2_expand_symtabs_for_function
,
4219 dw2_expand_all_symtabs
,
4220 dw2_expand_symtabs_with_fullname
,
4221 dw2_map_matching_symbols
,
4222 dw2_expand_symtabs_matching
,
4223 dw2_find_pc_sect_compunit_symtab
,
4224 dw2_map_symbol_filenames
4227 /* Initialize for reading DWARF for this objfile. Return 0 if this
4228 file will use psymtabs, or 1 if using the GNU index. */
4231 dwarf2_initialize_objfile (struct objfile
*objfile
)
4233 /* If we're about to read full symbols, don't bother with the
4234 indices. In this case we also don't care if some other debug
4235 format is making psymtabs, because they are all about to be
4237 if ((objfile
->flags
& OBJF_READNOW
))
4241 dwarf2_per_objfile
->using_index
= 1;
4242 create_all_comp_units (objfile
);
4243 create_all_type_units (objfile
);
4244 dwarf2_per_objfile
->quick_file_names_table
=
4245 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
4247 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
4248 + dwarf2_per_objfile
->n_type_units
); ++i
)
4250 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4252 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4253 struct dwarf2_per_cu_quick_data
);
4256 /* Return 1 so that gdb sees the "quick" functions. However,
4257 these functions will be no-ops because we will have expanded
4262 if (dwarf2_read_index (objfile
))
4270 /* Build a partial symbol table. */
4273 dwarf2_build_psymtabs (struct objfile
*objfile
)
4276 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
4278 init_psymbol_list (objfile
, 1024);
4283 /* This isn't really ideal: all the data we allocate on the
4284 objfile's obstack is still uselessly kept around. However,
4285 freeing it seems unsafe. */
4286 struct cleanup
*cleanups
= make_cleanup_discard_psymtabs (objfile
);
4288 dwarf2_build_psymtabs_hard (objfile
);
4289 discard_cleanups (cleanups
);
4291 CATCH (except
, RETURN_MASK_ERROR
)
4293 exception_print (gdb_stderr
, except
);
4298 /* Return the total length of the CU described by HEADER. */
4301 get_cu_length (const struct comp_unit_head
*header
)
4303 return header
->initial_length_size
+ header
->length
;
4306 /* Return TRUE if OFFSET is within CU_HEADER. */
4309 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
4311 sect_offset bottom
= { cu_header
->offset
.sect_off
};
4312 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
4314 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
4317 /* Find the base address of the compilation unit for range lists and
4318 location lists. It will normally be specified by DW_AT_low_pc.
4319 In DWARF-3 draft 4, the base address could be overridden by
4320 DW_AT_entry_pc. It's been removed, but GCC still uses this for
4321 compilation units with discontinuous ranges. */
4324 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
4326 struct attribute
*attr
;
4329 cu
->base_address
= 0;
4331 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
4334 cu
->base_address
= attr_value_as_address (attr
);
4339 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4342 cu
->base_address
= attr_value_as_address (attr
);
4348 /* Read in the comp unit header information from the debug_info at info_ptr.
4349 NOTE: This leaves members offset, first_die_offset to be filled in
4352 static const gdb_byte
*
4353 read_comp_unit_head (struct comp_unit_head
*cu_header
,
4354 const gdb_byte
*info_ptr
, bfd
*abfd
)
4357 unsigned int bytes_read
;
4359 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
4360 cu_header
->initial_length_size
= bytes_read
;
4361 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
4362 info_ptr
+= bytes_read
;
4363 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
4365 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
4367 info_ptr
+= bytes_read
;
4368 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
4370 signed_addr
= bfd_get_sign_extend_vma (abfd
);
4371 if (signed_addr
< 0)
4372 internal_error (__FILE__
, __LINE__
,
4373 _("read_comp_unit_head: dwarf from non elf file"));
4374 cu_header
->signed_addr_p
= signed_addr
;
4379 /* Helper function that returns the proper abbrev section for
4382 static struct dwarf2_section_info
*
4383 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
4385 struct dwarf2_section_info
*abbrev
;
4387 if (this_cu
->is_dwz
)
4388 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
4390 abbrev
= &dwarf2_per_objfile
->abbrev
;
4395 /* Subroutine of read_and_check_comp_unit_head and
4396 read_and_check_type_unit_head to simplify them.
4397 Perform various error checking on the header. */
4400 error_check_comp_unit_head (struct comp_unit_head
*header
,
4401 struct dwarf2_section_info
*section
,
4402 struct dwarf2_section_info
*abbrev_section
)
4404 const char *filename
= get_section_file_name (section
);
4406 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
4407 error (_("Dwarf Error: wrong version in compilation unit header "
4408 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
4411 if (header
->abbrev_offset
.sect_off
4412 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
4413 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
4414 "(offset 0x%lx + 6) [in module %s]"),
4415 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
4418 /* Cast to unsigned long to use 64-bit arithmetic when possible to
4419 avoid potential 32-bit overflow. */
4420 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
4422 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
4423 "(offset 0x%lx + 0) [in module %s]"),
4424 (long) header
->length
, (long) header
->offset
.sect_off
,
4428 /* Read in a CU/TU header and perform some basic error checking.
4429 The contents of the header are stored in HEADER.
4430 The result is a pointer to the start of the first DIE. */
4432 static const gdb_byte
*
4433 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
4434 struct dwarf2_section_info
*section
,
4435 struct dwarf2_section_info
*abbrev_section
,
4436 const gdb_byte
*info_ptr
,
4437 int is_debug_types_section
)
4439 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
4440 bfd
*abfd
= get_section_bfd_owner (section
);
4442 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4444 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
4446 /* If we're reading a type unit, skip over the signature and
4447 type_offset fields. */
4448 if (is_debug_types_section
)
4449 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
4451 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4453 error_check_comp_unit_head (header
, section
, abbrev_section
);
4458 /* Read in the types comp unit header information from .debug_types entry at
4459 types_ptr. The result is a pointer to one past the end of the header. */
4461 static const gdb_byte
*
4462 read_and_check_type_unit_head (struct comp_unit_head
*header
,
4463 struct dwarf2_section_info
*section
,
4464 struct dwarf2_section_info
*abbrev_section
,
4465 const gdb_byte
*info_ptr
,
4466 ULONGEST
*signature
,
4467 cu_offset
*type_offset_in_tu
)
4469 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
4470 bfd
*abfd
= get_section_bfd_owner (section
);
4472 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4474 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
4476 /* If we're reading a type unit, skip over the signature and
4477 type_offset fields. */
4478 if (signature
!= NULL
)
4479 *signature
= read_8_bytes (abfd
, info_ptr
);
4481 if (type_offset_in_tu
!= NULL
)
4482 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
4483 header
->offset_size
);
4484 info_ptr
+= header
->offset_size
;
4486 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4488 error_check_comp_unit_head (header
, section
, abbrev_section
);
4493 /* Fetch the abbreviation table offset from a comp or type unit header. */
4496 read_abbrev_offset (struct dwarf2_section_info
*section
,
4499 bfd
*abfd
= get_section_bfd_owner (section
);
4500 const gdb_byte
*info_ptr
;
4501 unsigned int initial_length_size
, offset_size
;
4502 sect_offset abbrev_offset
;
4504 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
4505 info_ptr
= section
->buffer
+ offset
.sect_off
;
4506 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
4507 offset_size
= initial_length_size
== 4 ? 4 : 8;
4508 info_ptr
+= initial_length_size
+ 2 /*version*/;
4509 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
4510 return abbrev_offset
;
4513 /* Allocate a new partial symtab for file named NAME and mark this new
4514 partial symtab as being an include of PST. */
4517 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
4518 struct objfile
*objfile
)
4520 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
4522 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
4524 /* It shares objfile->objfile_obstack. */
4525 subpst
->dirname
= pst
->dirname
;
4528 subpst
->textlow
= 0;
4529 subpst
->texthigh
= 0;
4531 subpst
->dependencies
4532 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
4533 subpst
->dependencies
[0] = pst
;
4534 subpst
->number_of_dependencies
= 1;
4536 subpst
->globals_offset
= 0;
4537 subpst
->n_global_syms
= 0;
4538 subpst
->statics_offset
= 0;
4539 subpst
->n_static_syms
= 0;
4540 subpst
->compunit_symtab
= NULL
;
4541 subpst
->read_symtab
= pst
->read_symtab
;
4544 /* No private part is necessary for include psymtabs. This property
4545 can be used to differentiate between such include psymtabs and
4546 the regular ones. */
4547 subpst
->read_symtab_private
= NULL
;
4550 /* Read the Line Number Program data and extract the list of files
4551 included by the source file represented by PST. Build an include
4552 partial symtab for each of these included files. */
4555 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4556 struct die_info
*die
,
4557 struct partial_symtab
*pst
)
4559 struct line_header
*lh
= NULL
;
4560 struct attribute
*attr
;
4562 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4564 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
4566 return; /* No linetable, so no includes. */
4568 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4569 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
4571 free_line_header (lh
);
4575 hash_signatured_type (const void *item
)
4577 const struct signatured_type
*sig_type
4578 = (const struct signatured_type
*) item
;
4580 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4581 return sig_type
->signature
;
4585 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4587 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
4588 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
4590 return lhs
->signature
== rhs
->signature
;
4593 /* Allocate a hash table for signatured types. */
4596 allocate_signatured_type_table (struct objfile
*objfile
)
4598 return htab_create_alloc_ex (41,
4599 hash_signatured_type
,
4602 &objfile
->objfile_obstack
,
4603 hashtab_obstack_allocate
,
4604 dummy_obstack_deallocate
);
4607 /* A helper function to add a signatured type CU to a table. */
4610 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4612 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
4613 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
4621 /* Create the hash table of all entries in the .debug_types
4622 (or .debug_types.dwo) section(s).
4623 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
4624 otherwise it is NULL.
4626 The result is a pointer to the hash table or NULL if there are no types.
4628 Note: This function processes DWO files only, not DWP files. */
4631 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4632 VEC (dwarf2_section_info_def
) *types
)
4634 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4635 htab_t types_htab
= NULL
;
4637 struct dwarf2_section_info
*section
;
4638 struct dwarf2_section_info
*abbrev_section
;
4640 if (VEC_empty (dwarf2_section_info_def
, types
))
4643 abbrev_section
= (dwo_file
!= NULL
4644 ? &dwo_file
->sections
.abbrev
4645 : &dwarf2_per_objfile
->abbrev
);
4647 if (dwarf_read_debug
)
4648 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
4649 dwo_file
? ".dwo" : "",
4650 get_section_file_name (abbrev_section
));
4653 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4657 const gdb_byte
*info_ptr
, *end_ptr
;
4659 dwarf2_read_section (objfile
, section
);
4660 info_ptr
= section
->buffer
;
4662 if (info_ptr
== NULL
)
4665 /* We can't set abfd until now because the section may be empty or
4666 not present, in which case the bfd is unknown. */
4667 abfd
= get_section_bfd_owner (section
);
4669 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4670 because we don't need to read any dies: the signature is in the
4673 end_ptr
= info_ptr
+ section
->size
;
4674 while (info_ptr
< end_ptr
)
4677 cu_offset type_offset_in_tu
;
4679 struct signatured_type
*sig_type
;
4680 struct dwo_unit
*dwo_tu
;
4682 const gdb_byte
*ptr
= info_ptr
;
4683 struct comp_unit_head header
;
4684 unsigned int length
;
4686 offset
.sect_off
= ptr
- section
->buffer
;
4688 /* We need to read the type's signature in order to build the hash
4689 table, but we don't need anything else just yet. */
4691 ptr
= read_and_check_type_unit_head (&header
, section
,
4692 abbrev_section
, ptr
,
4693 &signature
, &type_offset_in_tu
);
4695 length
= get_cu_length (&header
);
4697 /* Skip dummy type units. */
4698 if (ptr
>= info_ptr
+ length
4699 || peek_abbrev_code (abfd
, ptr
) == 0)
4705 if (types_htab
== NULL
)
4708 types_htab
= allocate_dwo_unit_table (objfile
);
4710 types_htab
= allocate_signatured_type_table (objfile
);
4716 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4718 dwo_tu
->dwo_file
= dwo_file
;
4719 dwo_tu
->signature
= signature
;
4720 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
4721 dwo_tu
->section
= section
;
4722 dwo_tu
->offset
= offset
;
4723 dwo_tu
->length
= length
;
4727 /* N.B.: type_offset is not usable if this type uses a DWO file.
4728 The real type_offset is in the DWO file. */
4730 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4731 struct signatured_type
);
4732 sig_type
->signature
= signature
;
4733 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
4734 sig_type
->per_cu
.objfile
= objfile
;
4735 sig_type
->per_cu
.is_debug_types
= 1;
4736 sig_type
->per_cu
.section
= section
;
4737 sig_type
->per_cu
.offset
= offset
;
4738 sig_type
->per_cu
.length
= length
;
4741 slot
= htab_find_slot (types_htab
,
4742 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4744 gdb_assert (slot
!= NULL
);
4747 sect_offset dup_offset
;
4751 const struct dwo_unit
*dup_tu
4752 = (const struct dwo_unit
*) *slot
;
4754 dup_offset
= dup_tu
->offset
;
4758 const struct signatured_type
*dup_tu
4759 = (const struct signatured_type
*) *slot
;
4761 dup_offset
= dup_tu
->per_cu
.offset
;
4764 complaint (&symfile_complaints
,
4765 _("debug type entry at offset 0x%x is duplicate to"
4766 " the entry at offset 0x%x, signature %s"),
4767 offset
.sect_off
, dup_offset
.sect_off
,
4768 hex_string (signature
));
4770 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4772 if (dwarf_read_debug
> 1)
4773 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature %s\n",
4775 hex_string (signature
));
4784 /* Create the hash table of all entries in the .debug_types section,
4785 and initialize all_type_units.
4786 The result is zero if there is an error (e.g. missing .debug_types section),
4787 otherwise non-zero. */
4790 create_all_type_units (struct objfile
*objfile
)
4793 struct signatured_type
**iter
;
4795 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4796 if (types_htab
== NULL
)
4798 dwarf2_per_objfile
->signatured_types
= NULL
;
4802 dwarf2_per_objfile
->signatured_types
= types_htab
;
4804 dwarf2_per_objfile
->n_type_units
4805 = dwarf2_per_objfile
->n_allocated_type_units
4806 = htab_elements (types_htab
);
4807 dwarf2_per_objfile
->all_type_units
=
4808 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
4809 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4810 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4811 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4812 == dwarf2_per_objfile
->n_type_units
);
4817 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
4818 If SLOT is non-NULL, it is the entry to use in the hash table.
4819 Otherwise we find one. */
4821 static struct signatured_type
*
4822 add_type_unit (ULONGEST sig
, void **slot
)
4824 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4825 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
4826 struct signatured_type
*sig_type
;
4828 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
4830 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
4832 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
4833 dwarf2_per_objfile
->n_allocated_type_units
= 1;
4834 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
4835 dwarf2_per_objfile
->all_type_units
4836 = XRESIZEVEC (struct signatured_type
*,
4837 dwarf2_per_objfile
->all_type_units
,
4838 dwarf2_per_objfile
->n_allocated_type_units
);
4839 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
4841 dwarf2_per_objfile
->n_type_units
= n_type_units
;
4843 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4844 struct signatured_type
);
4845 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
4846 sig_type
->signature
= sig
;
4847 sig_type
->per_cu
.is_debug_types
= 1;
4848 if (dwarf2_per_objfile
->using_index
)
4850 sig_type
->per_cu
.v
.quick
=
4851 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4852 struct dwarf2_per_cu_quick_data
);
4857 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
4860 gdb_assert (*slot
== NULL
);
4862 /* The rest of sig_type must be filled in by the caller. */
4866 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
4867 Fill in SIG_ENTRY with DWO_ENTRY. */
4870 fill_in_sig_entry_from_dwo_entry (struct objfile
*objfile
,
4871 struct signatured_type
*sig_entry
,
4872 struct dwo_unit
*dwo_entry
)
4874 /* Make sure we're not clobbering something we don't expect to. */
4875 gdb_assert (! sig_entry
->per_cu
.queued
);
4876 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
4877 if (dwarf2_per_objfile
->using_index
)
4879 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
4880 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
4883 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
4884 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
4885 gdb_assert (sig_entry
->type_offset_in_section
.sect_off
== 0);
4886 gdb_assert (sig_entry
->type_unit_group
== NULL
);
4887 gdb_assert (sig_entry
->dwo_unit
== NULL
);
4889 sig_entry
->per_cu
.section
= dwo_entry
->section
;
4890 sig_entry
->per_cu
.offset
= dwo_entry
->offset
;
4891 sig_entry
->per_cu
.length
= dwo_entry
->length
;
4892 sig_entry
->per_cu
.reading_dwo_directly
= 1;
4893 sig_entry
->per_cu
.objfile
= objfile
;
4894 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
4895 sig_entry
->dwo_unit
= dwo_entry
;
4898 /* Subroutine of lookup_signatured_type.
4899 If we haven't read the TU yet, create the signatured_type data structure
4900 for a TU to be read in directly from a DWO file, bypassing the stub.
4901 This is the "Stay in DWO Optimization": When there is no DWP file and we're
4902 using .gdb_index, then when reading a CU we want to stay in the DWO file
4903 containing that CU. Otherwise we could end up reading several other DWO
4904 files (due to comdat folding) to process the transitive closure of all the
4905 mentioned TUs, and that can be slow. The current DWO file will have every
4906 type signature that it needs.
4907 We only do this for .gdb_index because in the psymtab case we already have
4908 to read all the DWOs to build the type unit groups. */
4910 static struct signatured_type
*
4911 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
4913 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4914 struct dwo_file
*dwo_file
;
4915 struct dwo_unit find_dwo_entry
, *dwo_entry
;
4916 struct signatured_type find_sig_entry
, *sig_entry
;
4919 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
4921 /* If TU skeletons have been removed then we may not have read in any
4923 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4925 dwarf2_per_objfile
->signatured_types
4926 = allocate_signatured_type_table (objfile
);
4929 /* We only ever need to read in one copy of a signatured type.
4930 Use the global signatured_types array to do our own comdat-folding
4931 of types. If this is the first time we're reading this TU, and
4932 the TU has an entry in .gdb_index, replace the recorded data from
4933 .gdb_index with this TU. */
4935 find_sig_entry
.signature
= sig
;
4936 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
4937 &find_sig_entry
, INSERT
);
4938 sig_entry
= (struct signatured_type
*) *slot
;
4940 /* We can get here with the TU already read, *or* in the process of being
4941 read. Don't reassign the global entry to point to this DWO if that's
4942 the case. Also note that if the TU is already being read, it may not
4943 have come from a DWO, the program may be a mix of Fission-compiled
4944 code and non-Fission-compiled code. */
4946 /* Have we already tried to read this TU?
4947 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
4948 needn't exist in the global table yet). */
4949 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
4952 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
4953 dwo_unit of the TU itself. */
4954 dwo_file
= cu
->dwo_unit
->dwo_file
;
4956 /* Ok, this is the first time we're reading this TU. */
4957 if (dwo_file
->tus
== NULL
)
4959 find_dwo_entry
.signature
= sig
;
4960 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
4961 if (dwo_entry
== NULL
)
4964 /* If the global table doesn't have an entry for this TU, add one. */
4965 if (sig_entry
== NULL
)
4966 sig_entry
= add_type_unit (sig
, slot
);
4968 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
4969 sig_entry
->per_cu
.tu_read
= 1;
4973 /* Subroutine of lookup_signatured_type.
4974 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
4975 then try the DWP file. If the TU stub (skeleton) has been removed then
4976 it won't be in .gdb_index. */
4978 static struct signatured_type
*
4979 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
4981 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4982 struct dwp_file
*dwp_file
= get_dwp_file ();
4983 struct dwo_unit
*dwo_entry
;
4984 struct signatured_type find_sig_entry
, *sig_entry
;
4987 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
4988 gdb_assert (dwp_file
!= NULL
);
4990 /* If TU skeletons have been removed then we may not have read in any
4992 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4994 dwarf2_per_objfile
->signatured_types
4995 = allocate_signatured_type_table (objfile
);
4998 find_sig_entry
.signature
= sig
;
4999 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5000 &find_sig_entry
, INSERT
);
5001 sig_entry
= (struct signatured_type
*) *slot
;
5003 /* Have we already tried to read this TU?
5004 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5005 needn't exist in the global table yet). */
5006 if (sig_entry
!= NULL
)
5009 if (dwp_file
->tus
== NULL
)
5011 dwo_entry
= lookup_dwo_unit_in_dwp (dwp_file
, NULL
,
5012 sig
, 1 /* is_debug_types */);
5013 if (dwo_entry
== NULL
)
5016 sig_entry
= add_type_unit (sig
, slot
);
5017 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
5022 /* Lookup a signature based type for DW_FORM_ref_sig8.
5023 Returns NULL if signature SIG is not present in the table.
5024 It is up to the caller to complain about this. */
5026 static struct signatured_type
*
5027 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5030 && dwarf2_per_objfile
->using_index
)
5032 /* We're in a DWO/DWP file, and we're using .gdb_index.
5033 These cases require special processing. */
5034 if (get_dwp_file () == NULL
)
5035 return lookup_dwo_signatured_type (cu
, sig
);
5037 return lookup_dwp_signatured_type (cu
, sig
);
5041 struct signatured_type find_entry
, *entry
;
5043 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5045 find_entry
.signature
= sig
;
5046 entry
= ((struct signatured_type
*)
5047 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
5052 /* Low level DIE reading support. */
5054 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
5057 init_cu_die_reader (struct die_reader_specs
*reader
,
5058 struct dwarf2_cu
*cu
,
5059 struct dwarf2_section_info
*section
,
5060 struct dwo_file
*dwo_file
)
5062 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
5063 reader
->abfd
= get_section_bfd_owner (section
);
5065 reader
->dwo_file
= dwo_file
;
5066 reader
->die_section
= section
;
5067 reader
->buffer
= section
->buffer
;
5068 reader
->buffer_end
= section
->buffer
+ section
->size
;
5069 reader
->comp_dir
= NULL
;
5072 /* Subroutine of init_cutu_and_read_dies to simplify it.
5073 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
5074 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
5077 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
5078 from it to the DIE in the DWO. If NULL we are skipping the stub.
5079 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
5080 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
5081 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
5082 STUB_COMP_DIR may be non-NULL.
5083 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
5084 are filled in with the info of the DIE from the DWO file.
5085 ABBREV_TABLE_PROVIDED is non-zero if the caller of init_cutu_and_read_dies
5086 provided an abbrev table to use.
5087 The result is non-zero if a valid (non-dummy) DIE was found. */
5090 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
5091 struct dwo_unit
*dwo_unit
,
5092 int abbrev_table_provided
,
5093 struct die_info
*stub_comp_unit_die
,
5094 const char *stub_comp_dir
,
5095 struct die_reader_specs
*result_reader
,
5096 const gdb_byte
**result_info_ptr
,
5097 struct die_info
**result_comp_unit_die
,
5098 int *result_has_children
)
5100 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5101 struct dwarf2_cu
*cu
= this_cu
->cu
;
5102 struct dwarf2_section_info
*section
;
5104 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5105 ULONGEST signature
; /* Or dwo_id. */
5106 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
5107 int i
,num_extra_attrs
;
5108 struct dwarf2_section_info
*dwo_abbrev_section
;
5109 struct attribute
*attr
;
5110 struct die_info
*comp_unit_die
;
5112 /* At most one of these may be provided. */
5113 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
5115 /* These attributes aren't processed until later:
5116 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
5117 DW_AT_comp_dir is used now, to find the DWO file, but it is also
5118 referenced later. However, these attributes are found in the stub
5119 which we won't have later. In order to not impose this complication
5120 on the rest of the code, we read them here and copy them to the
5129 if (stub_comp_unit_die
!= NULL
)
5131 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
5133 if (! this_cu
->is_debug_types
)
5134 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
5135 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
5136 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
5137 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
5138 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
5140 /* There should be a DW_AT_addr_base attribute here (if needed).
5141 We need the value before we can process DW_FORM_GNU_addr_index. */
5143 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
5145 cu
->addr_base
= DW_UNSND (attr
);
5147 /* There should be a DW_AT_ranges_base attribute here (if needed).
5148 We need the value before we can process DW_AT_ranges. */
5149 cu
->ranges_base
= 0;
5150 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
5152 cu
->ranges_base
= DW_UNSND (attr
);
5154 else if (stub_comp_dir
!= NULL
)
5156 /* Reconstruct the comp_dir attribute to simplify the code below. */
5157 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
5158 comp_dir
->name
= DW_AT_comp_dir
;
5159 comp_dir
->form
= DW_FORM_string
;
5160 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
5161 DW_STRING (comp_dir
) = stub_comp_dir
;
5164 /* Set up for reading the DWO CU/TU. */
5165 cu
->dwo_unit
= dwo_unit
;
5166 section
= dwo_unit
->section
;
5167 dwarf2_read_section (objfile
, section
);
5168 abfd
= get_section_bfd_owner (section
);
5169 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
5170 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
5171 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
);
5173 if (this_cu
->is_debug_types
)
5175 ULONGEST header_signature
;
5176 cu_offset type_offset_in_tu
;
5177 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
5179 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
5183 &type_offset_in_tu
);
5184 /* This is not an assert because it can be caused by bad debug info. */
5185 if (sig_type
->signature
!= header_signature
)
5187 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
5188 " TU at offset 0x%x [in module %s]"),
5189 hex_string (sig_type
->signature
),
5190 hex_string (header_signature
),
5191 dwo_unit
->offset
.sect_off
,
5192 bfd_get_filename (abfd
));
5194 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5195 /* For DWOs coming from DWP files, we don't know the CU length
5196 nor the type's offset in the TU until now. */
5197 dwo_unit
->length
= get_cu_length (&cu
->header
);
5198 dwo_unit
->type_offset_in_tu
= type_offset_in_tu
;
5200 /* Establish the type offset that can be used to lookup the type.
5201 For DWO files, we don't know it until now. */
5202 sig_type
->type_offset_in_section
.sect_off
=
5203 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
5207 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5210 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5211 /* For DWOs coming from DWP files, we don't know the CU length
5213 dwo_unit
->length
= get_cu_length (&cu
->header
);
5216 /* Replace the CU's original abbrev table with the DWO's.
5217 Reminder: We can't read the abbrev table until we've read the header. */
5218 if (abbrev_table_provided
)
5220 /* Don't free the provided abbrev table, the caller of
5221 init_cutu_and_read_dies owns it. */
5222 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5223 /* Ensure the DWO abbrev table gets freed. */
5224 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5228 dwarf2_free_abbrev_table (cu
);
5229 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5230 /* Leave any existing abbrev table cleanup as is. */
5233 /* Read in the die, but leave space to copy over the attributes
5234 from the stub. This has the benefit of simplifying the rest of
5235 the code - all the work to maintain the illusion of a single
5236 DW_TAG_{compile,type}_unit DIE is done here. */
5237 num_extra_attrs
= ((stmt_list
!= NULL
)
5241 + (comp_dir
!= NULL
));
5242 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
5243 result_has_children
, num_extra_attrs
);
5245 /* Copy over the attributes from the stub to the DIE we just read in. */
5246 comp_unit_die
= *result_comp_unit_die
;
5247 i
= comp_unit_die
->num_attrs
;
5248 if (stmt_list
!= NULL
)
5249 comp_unit_die
->attrs
[i
++] = *stmt_list
;
5251 comp_unit_die
->attrs
[i
++] = *low_pc
;
5252 if (high_pc
!= NULL
)
5253 comp_unit_die
->attrs
[i
++] = *high_pc
;
5255 comp_unit_die
->attrs
[i
++] = *ranges
;
5256 if (comp_dir
!= NULL
)
5257 comp_unit_die
->attrs
[i
++] = *comp_dir
;
5258 comp_unit_die
->num_attrs
+= num_extra_attrs
;
5260 if (dwarf_die_debug
)
5262 fprintf_unfiltered (gdb_stdlog
,
5263 "Read die from %s@0x%x of %s:\n",
5264 get_section_name (section
),
5265 (unsigned) (begin_info_ptr
- section
->buffer
),
5266 bfd_get_filename (abfd
));
5267 dump_die (comp_unit_die
, dwarf_die_debug
);
5270 /* Save the comp_dir attribute. If there is no DWP file then we'll read
5271 TUs by skipping the stub and going directly to the entry in the DWO file.
5272 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
5273 to get it via circuitous means. Blech. */
5274 if (comp_dir
!= NULL
)
5275 result_reader
->comp_dir
= DW_STRING (comp_dir
);
5277 /* Skip dummy compilation units. */
5278 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
5279 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5282 *result_info_ptr
= info_ptr
;
5286 /* Subroutine of init_cutu_and_read_dies to simplify it.
5287 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
5288 Returns NULL if the specified DWO unit cannot be found. */
5290 static struct dwo_unit
*
5291 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
5292 struct die_info
*comp_unit_die
)
5294 struct dwarf2_cu
*cu
= this_cu
->cu
;
5295 struct attribute
*attr
;
5297 struct dwo_unit
*dwo_unit
;
5298 const char *comp_dir
, *dwo_name
;
5300 gdb_assert (cu
!= NULL
);
5302 /* Yeah, we look dwo_name up again, but it simplifies the code. */
5303 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5304 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
5306 if (this_cu
->is_debug_types
)
5308 struct signatured_type
*sig_type
;
5310 /* Since this_cu is the first member of struct signatured_type,
5311 we can go from a pointer to one to a pointer to the other. */
5312 sig_type
= (struct signatured_type
*) this_cu
;
5313 signature
= sig_type
->signature
;
5314 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
5318 struct attribute
*attr
;
5320 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
5322 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
5324 dwo_name
, objfile_name (this_cu
->objfile
));
5325 signature
= DW_UNSND (attr
);
5326 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
5333 /* Subroutine of init_cutu_and_read_dies to simplify it.
5334 See it for a description of the parameters.
5335 Read a TU directly from a DWO file, bypassing the stub.
5337 Note: This function could be a little bit simpler if we shared cleanups
5338 with our caller, init_cutu_and_read_dies. That's generally a fragile thing
5339 to do, so we keep this function self-contained. Or we could move this
5340 into our caller, but it's complex enough already. */
5343 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
5344 int use_existing_cu
, int keep
,
5345 die_reader_func_ftype
*die_reader_func
,
5348 struct dwarf2_cu
*cu
;
5349 struct signatured_type
*sig_type
;
5350 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5351 struct die_reader_specs reader
;
5352 const gdb_byte
*info_ptr
;
5353 struct die_info
*comp_unit_die
;
5356 /* Verify we can do the following downcast, and that we have the
5358 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
5359 sig_type
= (struct signatured_type
*) this_cu
;
5360 gdb_assert (sig_type
->dwo_unit
!= NULL
);
5362 cleanups
= make_cleanup (null_cleanup
, NULL
);
5364 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5366 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
5368 /* There's no need to do the rereading_dwo_cu handling that
5369 init_cutu_and_read_dies does since we don't read the stub. */
5373 /* If !use_existing_cu, this_cu->cu must be NULL. */
5374 gdb_assert (this_cu
->cu
== NULL
);
5375 cu
= XNEW (struct dwarf2_cu
);
5376 init_one_comp_unit (cu
, this_cu
);
5377 /* If an error occurs while loading, release our storage. */
5378 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5381 /* A future optimization, if needed, would be to use an existing
5382 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
5383 could share abbrev tables. */
5385 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
5386 0 /* abbrev_table_provided */,
5387 NULL
/* stub_comp_unit_die */,
5388 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
5390 &comp_unit_die
, &has_children
) == 0)
5393 do_cleanups (cleanups
);
5397 /* All the "real" work is done here. */
5398 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5400 /* This duplicates the code in init_cutu_and_read_dies,
5401 but the alternative is making the latter more complex.
5402 This function is only for the special case of using DWO files directly:
5403 no point in overly complicating the general case just to handle this. */
5404 if (free_cu_cleanup
!= NULL
)
5408 /* We've successfully allocated this compilation unit. Let our
5409 caller clean it up when finished with it. */
5410 discard_cleanups (free_cu_cleanup
);
5412 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5413 So we have to manually free the abbrev table. */
5414 dwarf2_free_abbrev_table (cu
);
5416 /* Link this CU into read_in_chain. */
5417 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5418 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5421 do_cleanups (free_cu_cleanup
);
5424 do_cleanups (cleanups
);
5427 /* Initialize a CU (or TU) and read its DIEs.
5428 If the CU defers to a DWO file, read the DWO file as well.
5430 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
5431 Otherwise the table specified in the comp unit header is read in and used.
5432 This is an optimization for when we already have the abbrev table.
5434 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
5435 Otherwise, a new CU is allocated with xmalloc.
5437 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
5438 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
5440 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5441 linker) then DIE_READER_FUNC will not get called. */
5444 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
5445 struct abbrev_table
*abbrev_table
,
5446 int use_existing_cu
, int keep
,
5447 die_reader_func_ftype
*die_reader_func
,
5450 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5451 struct dwarf2_section_info
*section
= this_cu
->section
;
5452 bfd
*abfd
= get_section_bfd_owner (section
);
5453 struct dwarf2_cu
*cu
;
5454 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5455 struct die_reader_specs reader
;
5456 struct die_info
*comp_unit_die
;
5458 struct attribute
*attr
;
5459 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5460 struct signatured_type
*sig_type
= NULL
;
5461 struct dwarf2_section_info
*abbrev_section
;
5462 /* Non-zero if CU currently points to a DWO file and we need to
5463 reread it. When this happens we need to reread the skeleton die
5464 before we can reread the DWO file (this only applies to CUs, not TUs). */
5465 int rereading_dwo_cu
= 0;
5467 if (dwarf_die_debug
)
5468 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5469 this_cu
->is_debug_types
? "type" : "comp",
5470 this_cu
->offset
.sect_off
);
5472 if (use_existing_cu
)
5475 /* If we're reading a TU directly from a DWO file, including a virtual DWO
5476 file (instead of going through the stub), short-circuit all of this. */
5477 if (this_cu
->reading_dwo_directly
)
5479 /* Narrow down the scope of possibilities to have to understand. */
5480 gdb_assert (this_cu
->is_debug_types
);
5481 gdb_assert (abbrev_table
== NULL
);
5482 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
5483 die_reader_func
, data
);
5487 cleanups
= make_cleanup (null_cleanup
, NULL
);
5489 /* This is cheap if the section is already read in. */
5490 dwarf2_read_section (objfile
, section
);
5492 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
5494 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
5496 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5499 /* If this CU is from a DWO file we need to start over, we need to
5500 refetch the attributes from the skeleton CU.
5501 This could be optimized by retrieving those attributes from when we
5502 were here the first time: the previous comp_unit_die was stored in
5503 comp_unit_obstack. But there's no data yet that we need this
5505 if (cu
->dwo_unit
!= NULL
)
5506 rereading_dwo_cu
= 1;
5510 /* If !use_existing_cu, this_cu->cu must be NULL. */
5511 gdb_assert (this_cu
->cu
== NULL
);
5512 cu
= XNEW (struct dwarf2_cu
);
5513 init_one_comp_unit (cu
, this_cu
);
5514 /* If an error occurs while loading, release our storage. */
5515 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5518 /* Get the header. */
5519 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
5521 /* We already have the header, there's no need to read it in again. */
5522 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
5526 if (this_cu
->is_debug_types
)
5529 cu_offset type_offset_in_tu
;
5531 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
5532 abbrev_section
, info_ptr
,
5534 &type_offset_in_tu
);
5536 /* Since per_cu is the first member of struct signatured_type,
5537 we can go from a pointer to one to a pointer to the other. */
5538 sig_type
= (struct signatured_type
*) this_cu
;
5539 gdb_assert (sig_type
->signature
== signature
);
5540 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
5541 == type_offset_in_tu
.cu_off
);
5542 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5544 /* LENGTH has not been set yet for type units if we're
5545 using .gdb_index. */
5546 this_cu
->length
= get_cu_length (&cu
->header
);
5548 /* Establish the type offset that can be used to lookup the type. */
5549 sig_type
->type_offset_in_section
.sect_off
=
5550 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
5554 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5558 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5559 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
5563 /* Skip dummy compilation units. */
5564 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5565 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5567 do_cleanups (cleanups
);
5571 /* If we don't have them yet, read the abbrevs for this compilation unit.
5572 And if we need to read them now, make sure they're freed when we're
5573 done. Note that it's important that if the CU had an abbrev table
5574 on entry we don't free it when we're done: Somewhere up the call stack
5575 it may be in use. */
5576 if (abbrev_table
!= NULL
)
5578 gdb_assert (cu
->abbrev_table
== NULL
);
5579 gdb_assert (cu
->header
.abbrev_offset
.sect_off
5580 == abbrev_table
->offset
.sect_off
);
5581 cu
->abbrev_table
= abbrev_table
;
5583 else if (cu
->abbrev_table
== NULL
)
5585 dwarf2_read_abbrevs (cu
, abbrev_section
);
5586 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5588 else if (rereading_dwo_cu
)
5590 dwarf2_free_abbrev_table (cu
);
5591 dwarf2_read_abbrevs (cu
, abbrev_section
);
5594 /* Read the top level CU/TU die. */
5595 init_cu_die_reader (&reader
, cu
, section
, NULL
);
5596 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5598 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
5600 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
5601 DWO CU, that this test will fail (the attribute will not be present). */
5602 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5605 struct dwo_unit
*dwo_unit
;
5606 struct die_info
*dwo_comp_unit_die
;
5610 complaint (&symfile_complaints
,
5611 _("compilation unit with DW_AT_GNU_dwo_name"
5612 " has children (offset 0x%x) [in module %s]"),
5613 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
5615 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
5616 if (dwo_unit
!= NULL
)
5618 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
5619 abbrev_table
!= NULL
,
5620 comp_unit_die
, NULL
,
5622 &dwo_comp_unit_die
, &has_children
) == 0)
5625 do_cleanups (cleanups
);
5628 comp_unit_die
= dwo_comp_unit_die
;
5632 /* Yikes, we couldn't find the rest of the DIE, we only have
5633 the stub. A complaint has already been logged. There's
5634 not much more we can do except pass on the stub DIE to
5635 die_reader_func. We don't want to throw an error on bad
5640 /* All of the above is setup for this call. Yikes. */
5641 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5643 /* Done, clean up. */
5644 if (free_cu_cleanup
!= NULL
)
5648 /* We've successfully allocated this compilation unit. Let our
5649 caller clean it up when finished with it. */
5650 discard_cleanups (free_cu_cleanup
);
5652 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5653 So we have to manually free the abbrev table. */
5654 dwarf2_free_abbrev_table (cu
);
5656 /* Link this CU into read_in_chain. */
5657 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5658 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5661 do_cleanups (free_cu_cleanup
);
5664 do_cleanups (cleanups
);
5667 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
5668 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
5669 to have already done the lookup to find the DWO file).
5671 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
5672 THIS_CU->is_debug_types, but nothing else.
5674 We fill in THIS_CU->length.
5676 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5677 linker) then DIE_READER_FUNC will not get called.
5679 THIS_CU->cu is always freed when done.
5680 This is done in order to not leave THIS_CU->cu in a state where we have
5681 to care whether it refers to the "main" CU or the DWO CU. */
5684 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
5685 struct dwo_file
*dwo_file
,
5686 die_reader_func_ftype
*die_reader_func
,
5689 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5690 struct dwarf2_section_info
*section
= this_cu
->section
;
5691 bfd
*abfd
= get_section_bfd_owner (section
);
5692 struct dwarf2_section_info
*abbrev_section
;
5693 struct dwarf2_cu cu
;
5694 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5695 struct die_reader_specs reader
;
5696 struct cleanup
*cleanups
;
5697 struct die_info
*comp_unit_die
;
5700 if (dwarf_die_debug
)
5701 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5702 this_cu
->is_debug_types
? "type" : "comp",
5703 this_cu
->offset
.sect_off
);
5705 gdb_assert (this_cu
->cu
== NULL
);
5707 abbrev_section
= (dwo_file
!= NULL
5708 ? &dwo_file
->sections
.abbrev
5709 : get_abbrev_section_for_cu (this_cu
));
5711 /* This is cheap if the section is already read in. */
5712 dwarf2_read_section (objfile
, section
);
5714 init_one_comp_unit (&cu
, this_cu
);
5716 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
5718 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
5719 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
5720 abbrev_section
, info_ptr
,
5721 this_cu
->is_debug_types
);
5723 this_cu
->length
= get_cu_length (&cu
.header
);
5725 /* Skip dummy compilation units. */
5726 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5727 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5729 do_cleanups (cleanups
);
5733 dwarf2_read_abbrevs (&cu
, abbrev_section
);
5734 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
5736 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
5737 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5739 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5741 do_cleanups (cleanups
);
5744 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
5745 does not lookup the specified DWO file.
5746 This cannot be used to read DWO files.
5748 THIS_CU->cu is always freed when done.
5749 This is done in order to not leave THIS_CU->cu in a state where we have
5750 to care whether it refers to the "main" CU or the DWO CU.
5751 We can revisit this if the data shows there's a performance issue. */
5754 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
5755 die_reader_func_ftype
*die_reader_func
,
5758 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
5761 /* Type Unit Groups.
5763 Type Unit Groups are a way to collapse the set of all TUs (type units) into
5764 a more manageable set. The grouping is done by DW_AT_stmt_list entry
5765 so that all types coming from the same compilation (.o file) are grouped
5766 together. A future step could be to put the types in the same symtab as
5767 the CU the types ultimately came from. */
5770 hash_type_unit_group (const void *item
)
5772 const struct type_unit_group
*tu_group
5773 = (const struct type_unit_group
*) item
;
5775 return hash_stmt_list_entry (&tu_group
->hash
);
5779 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
5781 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
5782 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
5784 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
5787 /* Allocate a hash table for type unit groups. */
5790 allocate_type_unit_groups_table (void)
5792 return htab_create_alloc_ex (3,
5793 hash_type_unit_group
,
5796 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
5797 hashtab_obstack_allocate
,
5798 dummy_obstack_deallocate
);
5801 /* Type units that don't have DW_AT_stmt_list are grouped into their own
5802 partial symtabs. We combine several TUs per psymtab to not let the size
5803 of any one psymtab grow too big. */
5804 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
5805 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5807 /* Helper routine for get_type_unit_group.
5808 Create the type_unit_group object used to hold one or more TUs. */
5810 static struct type_unit_group
*
5811 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
5813 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5814 struct dwarf2_per_cu_data
*per_cu
;
5815 struct type_unit_group
*tu_group
;
5817 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5818 struct type_unit_group
);
5819 per_cu
= &tu_group
->per_cu
;
5820 per_cu
->objfile
= objfile
;
5822 if (dwarf2_per_objfile
->using_index
)
5824 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5825 struct dwarf2_per_cu_quick_data
);
5829 unsigned int line_offset
= line_offset_struct
.sect_off
;
5830 struct partial_symtab
*pst
;
5833 /* Give the symtab a useful name for debug purposes. */
5834 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
5835 name
= xstrprintf ("<type_units_%d>",
5836 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
5838 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
5840 pst
= create_partial_symtab (per_cu
, name
);
5846 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
5847 tu_group
->hash
.line_offset
= line_offset_struct
;
5852 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5853 STMT_LIST is a DW_AT_stmt_list attribute. */
5855 static struct type_unit_group
*
5856 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
5858 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5859 struct type_unit_group
*tu_group
;
5861 unsigned int line_offset
;
5862 struct type_unit_group type_unit_group_for_lookup
;
5864 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
5866 dwarf2_per_objfile
->type_unit_groups
=
5867 allocate_type_unit_groups_table ();
5870 /* Do we need to create a new group, or can we use an existing one? */
5874 line_offset
= DW_UNSND (stmt_list
);
5875 ++tu_stats
->nr_symtab_sharers
;
5879 /* Ugh, no stmt_list. Rare, but we have to handle it.
5880 We can do various things here like create one group per TU or
5881 spread them over multiple groups to split up the expansion work.
5882 To avoid worst case scenarios (too many groups or too large groups)
5883 we, umm, group them in bunches. */
5884 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5885 | (tu_stats
->nr_stmt_less_type_units
5886 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
5887 ++tu_stats
->nr_stmt_less_type_units
;
5890 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
5891 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
5892 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
5893 &type_unit_group_for_lookup
, INSERT
);
5896 tu_group
= (struct type_unit_group
*) *slot
;
5897 gdb_assert (tu_group
!= NULL
);
5901 sect_offset line_offset_struct
;
5903 line_offset_struct
.sect_off
= line_offset
;
5904 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
5906 ++tu_stats
->nr_symtabs
;
5912 /* Partial symbol tables. */
5914 /* Create a psymtab named NAME and assign it to PER_CU.
5916 The caller must fill in the following details:
5917 dirname, textlow, texthigh. */
5919 static struct partial_symtab
*
5920 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
5922 struct objfile
*objfile
= per_cu
->objfile
;
5923 struct partial_symtab
*pst
;
5925 pst
= start_psymtab_common (objfile
, name
, 0,
5926 objfile
->global_psymbols
.next
,
5927 objfile
->static_psymbols
.next
);
5929 pst
->psymtabs_addrmap_supported
= 1;
5931 /* This is the glue that links PST into GDB's symbol API. */
5932 pst
->read_symtab_private
= per_cu
;
5933 pst
->read_symtab
= dwarf2_read_symtab
;
5934 per_cu
->v
.psymtab
= pst
;
5939 /* The DATA object passed to process_psymtab_comp_unit_reader has this
5942 struct process_psymtab_comp_unit_data
5944 /* True if we are reading a DW_TAG_partial_unit. */
5946 int want_partial_unit
;
5948 /* The "pretend" language that is used if the CU doesn't declare a
5951 enum language pretend_language
;
5954 /* die_reader_func for process_psymtab_comp_unit. */
5957 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
5958 const gdb_byte
*info_ptr
,
5959 struct die_info
*comp_unit_die
,
5963 struct dwarf2_cu
*cu
= reader
->cu
;
5964 struct objfile
*objfile
= cu
->objfile
;
5965 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5966 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5968 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
5969 struct partial_symtab
*pst
;
5970 enum pc_bounds_kind cu_bounds_kind
;
5971 const char *filename
;
5972 struct process_psymtab_comp_unit_data
*info
5973 = (struct process_psymtab_comp_unit_data
*) data
;
5975 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
5978 gdb_assert (! per_cu
->is_debug_types
);
5980 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
5982 cu
->list_in_scope
= &file_symbols
;
5984 /* Allocate a new partial symbol table structure. */
5985 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
5986 if (filename
== NULL
)
5989 pst
= create_partial_symtab (per_cu
, filename
);
5991 /* This must be done before calling dwarf2_build_include_psymtabs. */
5992 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
5994 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5996 dwarf2_find_base_address (comp_unit_die
, cu
);
5998 /* Possibly set the default values of LOWPC and HIGHPC from
6000 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
6001 &best_highpc
, cu
, pst
);
6002 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
6003 /* Store the contiguous range if it is not empty; it can be empty for
6004 CUs with no code. */
6005 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6006 gdbarch_adjust_dwarf2_addr (gdbarch
,
6007 best_lowpc
+ baseaddr
),
6008 gdbarch_adjust_dwarf2_addr (gdbarch
,
6009 best_highpc
+ baseaddr
) - 1,
6012 /* Check if comp unit has_children.
6013 If so, read the rest of the partial symbols from this comp unit.
6014 If not, there's no more debug_info for this comp unit. */
6017 struct partial_die_info
*first_die
;
6018 CORE_ADDR lowpc
, highpc
;
6020 lowpc
= ((CORE_ADDR
) -1);
6021 highpc
= ((CORE_ADDR
) 0);
6023 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6025 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
6026 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
6028 /* If we didn't find a lowpc, set it to highpc to avoid
6029 complaints from `maint check'. */
6030 if (lowpc
== ((CORE_ADDR
) -1))
6033 /* If the compilation unit didn't have an explicit address range,
6034 then use the information extracted from its child dies. */
6035 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
6038 best_highpc
= highpc
;
6041 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
6042 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
6044 end_psymtab_common (objfile
, pst
);
6046 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
6049 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6050 struct dwarf2_per_cu_data
*iter
;
6052 /* Fill in 'dependencies' here; we fill in 'users' in a
6054 pst
->number_of_dependencies
= len
;
6056 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6058 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
6061 pst
->dependencies
[i
] = iter
->v
.psymtab
;
6063 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6066 /* Get the list of files included in the current compilation unit,
6067 and build a psymtab for each of them. */
6068 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
6070 if (dwarf_read_debug
)
6072 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6074 fprintf_unfiltered (gdb_stdlog
,
6075 "Psymtab for %s unit @0x%x: %s - %s"
6076 ", %d global, %d static syms\n",
6077 per_cu
->is_debug_types
? "type" : "comp",
6078 per_cu
->offset
.sect_off
,
6079 paddress (gdbarch
, pst
->textlow
),
6080 paddress (gdbarch
, pst
->texthigh
),
6081 pst
->n_global_syms
, pst
->n_static_syms
);
6085 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6086 Process compilation unit THIS_CU for a psymtab. */
6089 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6090 int want_partial_unit
,
6091 enum language pretend_language
)
6093 struct process_psymtab_comp_unit_data info
;
6095 /* If this compilation unit was already read in, free the
6096 cached copy in order to read it in again. This is
6097 necessary because we skipped some symbols when we first
6098 read in the compilation unit (see load_partial_dies).
6099 This problem could be avoided, but the benefit is unclear. */
6100 if (this_cu
->cu
!= NULL
)
6101 free_one_cached_comp_unit (this_cu
);
6103 gdb_assert (! this_cu
->is_debug_types
);
6104 info
.want_partial_unit
= want_partial_unit
;
6105 info
.pretend_language
= pretend_language
;
6106 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
6107 process_psymtab_comp_unit_reader
,
6110 /* Age out any secondary CUs. */
6111 age_cached_comp_units ();
6114 /* Reader function for build_type_psymtabs. */
6117 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
6118 const gdb_byte
*info_ptr
,
6119 struct die_info
*type_unit_die
,
6123 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6124 struct dwarf2_cu
*cu
= reader
->cu
;
6125 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6126 struct signatured_type
*sig_type
;
6127 struct type_unit_group
*tu_group
;
6128 struct attribute
*attr
;
6129 struct partial_die_info
*first_die
;
6130 CORE_ADDR lowpc
, highpc
;
6131 struct partial_symtab
*pst
;
6133 gdb_assert (data
== NULL
);
6134 gdb_assert (per_cu
->is_debug_types
);
6135 sig_type
= (struct signatured_type
*) per_cu
;
6140 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
6141 tu_group
= get_type_unit_group (cu
, attr
);
6143 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
6145 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
6146 cu
->list_in_scope
= &file_symbols
;
6147 pst
= create_partial_symtab (per_cu
, "");
6150 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6152 lowpc
= (CORE_ADDR
) -1;
6153 highpc
= (CORE_ADDR
) 0;
6154 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
6156 end_psymtab_common (objfile
, pst
);
6159 /* Struct used to sort TUs by their abbreviation table offset. */
6161 struct tu_abbrev_offset
6163 struct signatured_type
*sig_type
;
6164 sect_offset abbrev_offset
;
6167 /* Helper routine for build_type_psymtabs_1, passed to qsort. */
6170 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
6172 const struct tu_abbrev_offset
* const *a
6173 = (const struct tu_abbrev_offset
* const*) ap
;
6174 const struct tu_abbrev_offset
* const *b
6175 = (const struct tu_abbrev_offset
* const*) bp
;
6176 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
6177 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
6179 return (aoff
> boff
) - (aoff
< boff
);
6182 /* Efficiently read all the type units.
6183 This does the bulk of the work for build_type_psymtabs.
6185 The efficiency is because we sort TUs by the abbrev table they use and
6186 only read each abbrev table once. In one program there are 200K TUs
6187 sharing 8K abbrev tables.
6189 The main purpose of this function is to support building the
6190 dwarf2_per_objfile->type_unit_groups table.
6191 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
6192 can collapse the search space by grouping them by stmt_list.
6193 The savings can be significant, in the same program from above the 200K TUs
6194 share 8K stmt_list tables.
6196 FUNC is expected to call get_type_unit_group, which will create the
6197 struct type_unit_group if necessary and add it to
6198 dwarf2_per_objfile->type_unit_groups. */
6201 build_type_psymtabs_1 (void)
6203 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6204 struct cleanup
*cleanups
;
6205 struct abbrev_table
*abbrev_table
;
6206 sect_offset abbrev_offset
;
6207 struct tu_abbrev_offset
*sorted_by_abbrev
;
6210 /* It's up to the caller to not call us multiple times. */
6211 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
6213 if (dwarf2_per_objfile
->n_type_units
== 0)
6216 /* TUs typically share abbrev tables, and there can be way more TUs than
6217 abbrev tables. Sort by abbrev table to reduce the number of times we
6218 read each abbrev table in.
6219 Alternatives are to punt or to maintain a cache of abbrev tables.
6220 This is simpler and efficient enough for now.
6222 Later we group TUs by their DW_AT_stmt_list value (as this defines the
6223 symtab to use). Typically TUs with the same abbrev offset have the same
6224 stmt_list value too so in practice this should work well.
6226 The basic algorithm here is:
6228 sort TUs by abbrev table
6229 for each TU with same abbrev table:
6230 read abbrev table if first user
6231 read TU top level DIE
6232 [IWBN if DWO skeletons had DW_AT_stmt_list]
6235 if (dwarf_read_debug
)
6236 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
6238 /* Sort in a separate table to maintain the order of all_type_units
6239 for .gdb_index: TU indices directly index all_type_units. */
6240 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
6241 dwarf2_per_objfile
->n_type_units
);
6242 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6244 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
6246 sorted_by_abbrev
[i
].sig_type
= sig_type
;
6247 sorted_by_abbrev
[i
].abbrev_offset
=
6248 read_abbrev_offset (sig_type
->per_cu
.section
,
6249 sig_type
->per_cu
.offset
);
6251 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
6252 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
6253 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
6255 abbrev_offset
.sect_off
= ~(unsigned) 0;
6256 abbrev_table
= NULL
;
6257 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
6259 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6261 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
6263 /* Switch to the next abbrev table if necessary. */
6264 if (abbrev_table
== NULL
6265 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
6267 if (abbrev_table
!= NULL
)
6269 abbrev_table_free (abbrev_table
);
6270 /* Reset to NULL in case abbrev_table_read_table throws
6271 an error: abbrev_table_free_cleanup will get called. */
6272 abbrev_table
= NULL
;
6274 abbrev_offset
= tu
->abbrev_offset
;
6276 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
6278 ++tu_stats
->nr_uniq_abbrev_tables
;
6281 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
6282 build_type_psymtabs_reader
, NULL
);
6285 do_cleanups (cleanups
);
6288 /* Print collected type unit statistics. */
6291 print_tu_stats (void)
6293 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6295 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
6296 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
6297 dwarf2_per_objfile
->n_type_units
);
6298 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
6299 tu_stats
->nr_uniq_abbrev_tables
);
6300 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
6301 tu_stats
->nr_symtabs
);
6302 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
6303 tu_stats
->nr_symtab_sharers
);
6304 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
6305 tu_stats
->nr_stmt_less_type_units
);
6306 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
6307 tu_stats
->nr_all_type_units_reallocs
);
6310 /* Traversal function for build_type_psymtabs. */
6313 build_type_psymtab_dependencies (void **slot
, void *info
)
6315 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6316 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
6317 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
6318 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6319 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
6320 struct signatured_type
*iter
;
6323 gdb_assert (len
> 0);
6324 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
6326 pst
->number_of_dependencies
= len
;
6328 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6330 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
6333 gdb_assert (iter
->per_cu
.is_debug_types
);
6334 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
6335 iter
->type_unit_group
= tu_group
;
6338 VEC_free (sig_type_ptr
, tu_group
->tus
);
6343 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6344 Build partial symbol tables for the .debug_types comp-units. */
6347 build_type_psymtabs (struct objfile
*objfile
)
6349 if (! create_all_type_units (objfile
))
6352 build_type_psymtabs_1 ();
6355 /* Traversal function for process_skeletonless_type_unit.
6356 Read a TU in a DWO file and build partial symbols for it. */
6359 process_skeletonless_type_unit (void **slot
, void *info
)
6361 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
6362 struct objfile
*objfile
= (struct objfile
*) info
;
6363 struct signatured_type find_entry
, *entry
;
6365 /* If this TU doesn't exist in the global table, add it and read it in. */
6367 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6369 dwarf2_per_objfile
->signatured_types
6370 = allocate_signatured_type_table (objfile
);
6373 find_entry
.signature
= dwo_unit
->signature
;
6374 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
6376 /* If we've already seen this type there's nothing to do. What's happening
6377 is we're doing our own version of comdat-folding here. */
6381 /* This does the job that create_all_type_units would have done for
6383 entry
= add_type_unit (dwo_unit
->signature
, slot
);
6384 fill_in_sig_entry_from_dwo_entry (objfile
, entry
, dwo_unit
);
6387 /* This does the job that build_type_psymtabs_1 would have done. */
6388 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
6389 build_type_psymtabs_reader
, NULL
);
6394 /* Traversal function for process_skeletonless_type_units. */
6397 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
6399 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
6401 if (dwo_file
->tus
!= NULL
)
6403 htab_traverse_noresize (dwo_file
->tus
,
6404 process_skeletonless_type_unit
, info
);
6410 /* Scan all TUs of DWO files, verifying we've processed them.
6411 This is needed in case a TU was emitted without its skeleton.
6412 Note: This can't be done until we know what all the DWO files are. */
6415 process_skeletonless_type_units (struct objfile
*objfile
)
6417 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
6418 if (get_dwp_file () == NULL
6419 && dwarf2_per_objfile
->dwo_files
!= NULL
)
6421 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
6422 process_dwo_file_for_skeletonless_type_units
,
6427 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
6430 psymtabs_addrmap_cleanup (void *o
)
6432 struct objfile
*objfile
= (struct objfile
*) o
;
6434 objfile
->psymtabs_addrmap
= NULL
;
6437 /* Compute the 'user' field for each psymtab in OBJFILE. */
6440 set_partial_user (struct objfile
*objfile
)
6444 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6446 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6447 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6453 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
6455 /* Set the 'user' field only if it is not already set. */
6456 if (pst
->dependencies
[j
]->user
== NULL
)
6457 pst
->dependencies
[j
]->user
= pst
;
6462 /* Build the partial symbol table by doing a quick pass through the
6463 .debug_info and .debug_abbrev sections. */
6466 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
6468 struct cleanup
*back_to
, *addrmap_cleanup
;
6469 struct obstack temp_obstack
;
6472 if (dwarf_read_debug
)
6474 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
6475 objfile_name (objfile
));
6478 dwarf2_per_objfile
->reading_partial_symbols
= 1;
6480 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
6482 /* Any cached compilation units will be linked by the per-objfile
6483 read_in_chain. Make sure to free them when we're done. */
6484 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
6486 build_type_psymtabs (objfile
);
6488 create_all_comp_units (objfile
);
6490 /* Create a temporary address map on a temporary obstack. We later
6491 copy this to the final obstack. */
6492 obstack_init (&temp_obstack
);
6493 make_cleanup_obstack_free (&temp_obstack
);
6494 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
6495 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
6497 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6499 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6501 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
6504 /* This has to wait until we read the CUs, we need the list of DWOs. */
6505 process_skeletonless_type_units (objfile
);
6507 /* Now that all TUs have been processed we can fill in the dependencies. */
6508 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
6510 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
6511 build_type_psymtab_dependencies
, NULL
);
6514 if (dwarf_read_debug
)
6517 set_partial_user (objfile
);
6519 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
6520 &objfile
->objfile_obstack
);
6521 discard_cleanups (addrmap_cleanup
);
6523 do_cleanups (back_to
);
6525 if (dwarf_read_debug
)
6526 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
6527 objfile_name (objfile
));
6530 /* die_reader_func for load_partial_comp_unit. */
6533 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
6534 const gdb_byte
*info_ptr
,
6535 struct die_info
*comp_unit_die
,
6539 struct dwarf2_cu
*cu
= reader
->cu
;
6541 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
6543 /* Check if comp unit has_children.
6544 If so, read the rest of the partial symbols from this comp unit.
6545 If not, there's no more debug_info for this comp unit. */
6547 load_partial_dies (reader
, info_ptr
, 0);
6550 /* Load the partial DIEs for a secondary CU into memory.
6551 This is also used when rereading a primary CU with load_all_dies. */
6554 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
6556 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6557 load_partial_comp_unit_reader
, NULL
);
6561 read_comp_units_from_section (struct objfile
*objfile
,
6562 struct dwarf2_section_info
*section
,
6563 unsigned int is_dwz
,
6566 struct dwarf2_per_cu_data
***all_comp_units
)
6568 const gdb_byte
*info_ptr
;
6569 bfd
*abfd
= get_section_bfd_owner (section
);
6571 if (dwarf_read_debug
)
6572 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
6573 get_section_name (section
),
6574 get_section_file_name (section
));
6576 dwarf2_read_section (objfile
, section
);
6578 info_ptr
= section
->buffer
;
6580 while (info_ptr
< section
->buffer
+ section
->size
)
6582 unsigned int length
, initial_length_size
;
6583 struct dwarf2_per_cu_data
*this_cu
;
6586 offset
.sect_off
= info_ptr
- section
->buffer
;
6588 /* Read just enough information to find out where the next
6589 compilation unit is. */
6590 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6592 /* Save the compilation unit for later lookup. */
6593 this_cu
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
);
6594 memset (this_cu
, 0, sizeof (*this_cu
));
6595 this_cu
->offset
= offset
;
6596 this_cu
->length
= length
+ initial_length_size
;
6597 this_cu
->is_dwz
= is_dwz
;
6598 this_cu
->objfile
= objfile
;
6599 this_cu
->section
= section
;
6601 if (*n_comp_units
== *n_allocated
)
6604 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
6605 *all_comp_units
, *n_allocated
);
6607 (*all_comp_units
)[*n_comp_units
] = this_cu
;
6610 info_ptr
= info_ptr
+ this_cu
->length
;
6614 /* Create a list of all compilation units in OBJFILE.
6615 This is only done for -readnow and building partial symtabs. */
6618 create_all_comp_units (struct objfile
*objfile
)
6622 struct dwarf2_per_cu_data
**all_comp_units
;
6623 struct dwz_file
*dwz
;
6627 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
6629 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
6630 &n_allocated
, &n_comp_units
, &all_comp_units
);
6632 dwz
= dwarf2_get_dwz_file ();
6634 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
6635 &n_allocated
, &n_comp_units
,
6638 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
6639 struct dwarf2_per_cu_data
*,
6641 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
6642 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
6643 xfree (all_comp_units
);
6644 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
6647 /* Process all loaded DIEs for compilation unit CU, starting at
6648 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
6649 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
6650 DW_AT_ranges). See the comments of add_partial_subprogram on how
6651 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
6654 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
6655 CORE_ADDR
*highpc
, int set_addrmap
,
6656 struct dwarf2_cu
*cu
)
6658 struct partial_die_info
*pdi
;
6660 /* Now, march along the PDI's, descending into ones which have
6661 interesting children but skipping the children of the other ones,
6662 until we reach the end of the compilation unit. */
6668 fixup_partial_die (pdi
, cu
);
6670 /* Anonymous namespaces or modules have no name but have interesting
6671 children, so we need to look at them. Ditto for anonymous
6674 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
6675 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
6676 || pdi
->tag
== DW_TAG_imported_unit
)
6680 case DW_TAG_subprogram
:
6681 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6683 case DW_TAG_constant
:
6684 case DW_TAG_variable
:
6685 case DW_TAG_typedef
:
6686 case DW_TAG_union_type
:
6687 if (!pdi
->is_declaration
)
6689 add_partial_symbol (pdi
, cu
);
6692 case DW_TAG_class_type
:
6693 case DW_TAG_interface_type
:
6694 case DW_TAG_structure_type
:
6695 if (!pdi
->is_declaration
)
6697 add_partial_symbol (pdi
, cu
);
6699 if (cu
->language
== language_rust
&& pdi
->has_children
)
6700 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
6703 case DW_TAG_enumeration_type
:
6704 if (!pdi
->is_declaration
)
6705 add_partial_enumeration (pdi
, cu
);
6707 case DW_TAG_base_type
:
6708 case DW_TAG_subrange_type
:
6709 /* File scope base type definitions are added to the partial
6711 add_partial_symbol (pdi
, cu
);
6713 case DW_TAG_namespace
:
6714 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6717 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6719 case DW_TAG_imported_unit
:
6721 struct dwarf2_per_cu_data
*per_cu
;
6723 /* For now we don't handle imported units in type units. */
6724 if (cu
->per_cu
->is_debug_types
)
6726 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6727 " supported in type units [in module %s]"),
6728 objfile_name (cu
->objfile
));
6731 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
6735 /* Go read the partial unit, if needed. */
6736 if (per_cu
->v
.psymtab
== NULL
)
6737 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
6739 VEC_safe_push (dwarf2_per_cu_ptr
,
6740 cu
->per_cu
->imported_symtabs
, per_cu
);
6743 case DW_TAG_imported_declaration
:
6744 add_partial_symbol (pdi
, cu
);
6751 /* If the die has a sibling, skip to the sibling. */
6753 pdi
= pdi
->die_sibling
;
6757 /* Functions used to compute the fully scoped name of a partial DIE.
6759 Normally, this is simple. For C++, the parent DIE's fully scoped
6760 name is concatenated with "::" and the partial DIE's name. For
6761 Java, the same thing occurs except that "." is used instead of "::".
6762 Enumerators are an exception; they use the scope of their parent
6763 enumeration type, i.e. the name of the enumeration type is not
6764 prepended to the enumerator.
6766 There are two complexities. One is DW_AT_specification; in this
6767 case "parent" means the parent of the target of the specification,
6768 instead of the direct parent of the DIE. The other is compilers
6769 which do not emit DW_TAG_namespace; in this case we try to guess
6770 the fully qualified name of structure types from their members'
6771 linkage names. This must be done using the DIE's children rather
6772 than the children of any DW_AT_specification target. We only need
6773 to do this for structures at the top level, i.e. if the target of
6774 any DW_AT_specification (if any; otherwise the DIE itself) does not
6777 /* Compute the scope prefix associated with PDI's parent, in
6778 compilation unit CU. The result will be allocated on CU's
6779 comp_unit_obstack, or a copy of the already allocated PDI->NAME
6780 field. NULL is returned if no prefix is necessary. */
6782 partial_die_parent_scope (struct partial_die_info
*pdi
,
6783 struct dwarf2_cu
*cu
)
6785 const char *grandparent_scope
;
6786 struct partial_die_info
*parent
, *real_pdi
;
6788 /* We need to look at our parent DIE; if we have a DW_AT_specification,
6789 then this means the parent of the specification DIE. */
6792 while (real_pdi
->has_specification
)
6793 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
6794 real_pdi
->spec_is_dwz
, cu
);
6796 parent
= real_pdi
->die_parent
;
6800 if (parent
->scope_set
)
6801 return parent
->scope
;
6803 fixup_partial_die (parent
, cu
);
6805 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
6807 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
6808 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
6809 Work around this problem here. */
6810 if (cu
->language
== language_cplus
6811 && parent
->tag
== DW_TAG_namespace
6812 && strcmp (parent
->name
, "::") == 0
6813 && grandparent_scope
== NULL
)
6815 parent
->scope
= NULL
;
6816 parent
->scope_set
= 1;
6820 if (pdi
->tag
== DW_TAG_enumerator
)
6821 /* Enumerators should not get the name of the enumeration as a prefix. */
6822 parent
->scope
= grandparent_scope
;
6823 else if (parent
->tag
== DW_TAG_namespace
6824 || parent
->tag
== DW_TAG_module
6825 || parent
->tag
== DW_TAG_structure_type
6826 || parent
->tag
== DW_TAG_class_type
6827 || parent
->tag
== DW_TAG_interface_type
6828 || parent
->tag
== DW_TAG_union_type
6829 || parent
->tag
== DW_TAG_enumeration_type
)
6831 if (grandparent_scope
== NULL
)
6832 parent
->scope
= parent
->name
;
6834 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
6836 parent
->name
, 0, cu
);
6840 /* FIXME drow/2004-04-01: What should we be doing with
6841 function-local names? For partial symbols, we should probably be
6843 complaint (&symfile_complaints
,
6844 _("unhandled containing DIE tag %d for DIE at %d"),
6845 parent
->tag
, pdi
->offset
.sect_off
);
6846 parent
->scope
= grandparent_scope
;
6849 parent
->scope_set
= 1;
6850 return parent
->scope
;
6853 /* Return the fully scoped name associated with PDI, from compilation unit
6854 CU. The result will be allocated with malloc. */
6857 partial_die_full_name (struct partial_die_info
*pdi
,
6858 struct dwarf2_cu
*cu
)
6860 const char *parent_scope
;
6862 /* If this is a template instantiation, we can not work out the
6863 template arguments from partial DIEs. So, unfortunately, we have
6864 to go through the full DIEs. At least any work we do building
6865 types here will be reused if full symbols are loaded later. */
6866 if (pdi
->has_template_arguments
)
6868 fixup_partial_die (pdi
, cu
);
6870 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
6872 struct die_info
*die
;
6873 struct attribute attr
;
6874 struct dwarf2_cu
*ref_cu
= cu
;
6876 /* DW_FORM_ref_addr is using section offset. */
6877 attr
.name
= (enum dwarf_attribute
) 0;
6878 attr
.form
= DW_FORM_ref_addr
;
6879 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
6880 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
6882 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
6886 parent_scope
= partial_die_parent_scope (pdi
, cu
);
6887 if (parent_scope
== NULL
)
6890 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
6894 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
6896 struct objfile
*objfile
= cu
->objfile
;
6897 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6899 const char *actual_name
= NULL
;
6901 char *built_actual_name
;
6903 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6905 built_actual_name
= partial_die_full_name (pdi
, cu
);
6906 if (built_actual_name
!= NULL
)
6907 actual_name
= built_actual_name
;
6909 if (actual_name
== NULL
)
6910 actual_name
= pdi
->name
;
6914 case DW_TAG_subprogram
:
6915 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
6916 if (pdi
->is_external
|| cu
->language
== language_ada
)
6918 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
6919 of the global scope. But in Ada, we want to be able to access
6920 nested procedures globally. So all Ada subprograms are stored
6921 in the global scope. */
6922 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6923 built_actual_name
!= NULL
,
6924 VAR_DOMAIN
, LOC_BLOCK
,
6925 &objfile
->global_psymbols
,
6926 addr
, cu
->language
, objfile
);
6930 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6931 built_actual_name
!= NULL
,
6932 VAR_DOMAIN
, LOC_BLOCK
,
6933 &objfile
->static_psymbols
,
6934 addr
, cu
->language
, objfile
);
6937 case DW_TAG_constant
:
6939 struct psymbol_allocation_list
*list
;
6941 if (pdi
->is_external
)
6942 list
= &objfile
->global_psymbols
;
6944 list
= &objfile
->static_psymbols
;
6945 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6946 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
6947 list
, 0, cu
->language
, objfile
);
6950 case DW_TAG_variable
:
6952 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
6956 && !dwarf2_per_objfile
->has_section_at_zero
)
6958 /* A global or static variable may also have been stripped
6959 out by the linker if unused, in which case its address
6960 will be nullified; do not add such variables into partial
6961 symbol table then. */
6963 else if (pdi
->is_external
)
6966 Don't enter into the minimal symbol tables as there is
6967 a minimal symbol table entry from the ELF symbols already.
6968 Enter into partial symbol table if it has a location
6969 descriptor or a type.
6970 If the location descriptor is missing, new_symbol will create
6971 a LOC_UNRESOLVED symbol, the address of the variable will then
6972 be determined from the minimal symbol table whenever the variable
6974 The address for the partial symbol table entry is not
6975 used by GDB, but it comes in handy for debugging partial symbol
6978 if (pdi
->d
.locdesc
|| pdi
->has_type
)
6979 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6980 built_actual_name
!= NULL
,
6981 VAR_DOMAIN
, LOC_STATIC
,
6982 &objfile
->global_psymbols
,
6984 cu
->language
, objfile
);
6988 int has_loc
= pdi
->d
.locdesc
!= NULL
;
6990 /* Static Variable. Skip symbols whose value we cannot know (those
6991 without location descriptors or constant values). */
6992 if (!has_loc
&& !pdi
->has_const_value
)
6994 xfree (built_actual_name
);
6998 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6999 built_actual_name
!= NULL
,
7000 VAR_DOMAIN
, LOC_STATIC
,
7001 &objfile
->static_psymbols
,
7002 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
7003 cu
->language
, objfile
);
7006 case DW_TAG_typedef
:
7007 case DW_TAG_base_type
:
7008 case DW_TAG_subrange_type
:
7009 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7010 built_actual_name
!= NULL
,
7011 VAR_DOMAIN
, LOC_TYPEDEF
,
7012 &objfile
->static_psymbols
,
7013 0, cu
->language
, objfile
);
7015 case DW_TAG_imported_declaration
:
7016 case DW_TAG_namespace
:
7017 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7018 built_actual_name
!= NULL
,
7019 VAR_DOMAIN
, LOC_TYPEDEF
,
7020 &objfile
->global_psymbols
,
7021 0, cu
->language
, objfile
);
7024 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7025 built_actual_name
!= NULL
,
7026 MODULE_DOMAIN
, LOC_TYPEDEF
,
7027 &objfile
->global_psymbols
,
7028 0, cu
->language
, objfile
);
7030 case DW_TAG_class_type
:
7031 case DW_TAG_interface_type
:
7032 case DW_TAG_structure_type
:
7033 case DW_TAG_union_type
:
7034 case DW_TAG_enumeration_type
:
7035 /* Skip external references. The DWARF standard says in the section
7036 about "Structure, Union, and Class Type Entries": "An incomplete
7037 structure, union or class type is represented by a structure,
7038 union or class entry that does not have a byte size attribute
7039 and that has a DW_AT_declaration attribute." */
7040 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
7042 xfree (built_actual_name
);
7046 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
7047 static vs. global. */
7048 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7049 built_actual_name
!= NULL
,
7050 STRUCT_DOMAIN
, LOC_TYPEDEF
,
7051 (cu
->language
== language_cplus
7052 || cu
->language
== language_java
)
7053 ? &objfile
->global_psymbols
7054 : &objfile
->static_psymbols
,
7055 0, cu
->language
, objfile
);
7058 case DW_TAG_enumerator
:
7059 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7060 built_actual_name
!= NULL
,
7061 VAR_DOMAIN
, LOC_CONST
,
7062 (cu
->language
== language_cplus
7063 || cu
->language
== language_java
)
7064 ? &objfile
->global_psymbols
7065 : &objfile
->static_psymbols
,
7066 0, cu
->language
, objfile
);
7072 xfree (built_actual_name
);
7075 /* Read a partial die corresponding to a namespace; also, add a symbol
7076 corresponding to that namespace to the symbol table. NAMESPACE is
7077 the name of the enclosing namespace. */
7080 add_partial_namespace (struct partial_die_info
*pdi
,
7081 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7082 int set_addrmap
, struct dwarf2_cu
*cu
)
7084 /* Add a symbol for the namespace. */
7086 add_partial_symbol (pdi
, cu
);
7088 /* Now scan partial symbols in that namespace. */
7090 if (pdi
->has_children
)
7091 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7094 /* Read a partial die corresponding to a Fortran module. */
7097 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
7098 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
7100 /* Add a symbol for the namespace. */
7102 add_partial_symbol (pdi
, cu
);
7104 /* Now scan partial symbols in that module. */
7106 if (pdi
->has_children
)
7107 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7110 /* Read a partial die corresponding to a subprogram and create a partial
7111 symbol for that subprogram. When the CU language allows it, this
7112 routine also defines a partial symbol for each nested subprogram
7113 that this subprogram contains. If SET_ADDRMAP is true, record the
7114 covered ranges in the addrmap. Set *LOWPC and *HIGHPC to the lowest
7115 and highest PC values found in PDI.
7117 PDI may also be a lexical block, in which case we simply search
7118 recursively for subprograms defined inside that lexical block.
7119 Again, this is only performed when the CU language allows this
7120 type of definitions. */
7123 add_partial_subprogram (struct partial_die_info
*pdi
,
7124 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7125 int set_addrmap
, struct dwarf2_cu
*cu
)
7127 if (pdi
->tag
== DW_TAG_subprogram
)
7129 if (pdi
->has_pc_info
)
7131 if (pdi
->lowpc
< *lowpc
)
7132 *lowpc
= pdi
->lowpc
;
7133 if (pdi
->highpc
> *highpc
)
7134 *highpc
= pdi
->highpc
;
7137 struct objfile
*objfile
= cu
->objfile
;
7138 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7143 baseaddr
= ANOFFSET (objfile
->section_offsets
,
7144 SECT_OFF_TEXT (objfile
));
7145 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7146 pdi
->lowpc
+ baseaddr
);
7147 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7148 pdi
->highpc
+ baseaddr
);
7149 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
7150 cu
->per_cu
->v
.psymtab
);
7154 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
7156 if (!pdi
->is_declaration
)
7157 /* Ignore subprogram DIEs that do not have a name, they are
7158 illegal. Do not emit a complaint at this point, we will
7159 do so when we convert this psymtab into a symtab. */
7161 add_partial_symbol (pdi
, cu
);
7165 if (! pdi
->has_children
)
7168 if (cu
->language
== language_ada
)
7170 pdi
= pdi
->die_child
;
7173 fixup_partial_die (pdi
, cu
);
7174 if (pdi
->tag
== DW_TAG_subprogram
7175 || pdi
->tag
== DW_TAG_lexical_block
)
7176 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7177 pdi
= pdi
->die_sibling
;
7182 /* Read a partial die corresponding to an enumeration type. */
7185 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
7186 struct dwarf2_cu
*cu
)
7188 struct partial_die_info
*pdi
;
7190 if (enum_pdi
->name
!= NULL
)
7191 add_partial_symbol (enum_pdi
, cu
);
7193 pdi
= enum_pdi
->die_child
;
7196 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
7197 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
7199 add_partial_symbol (pdi
, cu
);
7200 pdi
= pdi
->die_sibling
;
7204 /* Return the initial uleb128 in the die at INFO_PTR. */
7207 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
7209 unsigned int bytes_read
;
7211 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7214 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
7215 Return the corresponding abbrev, or NULL if the number is zero (indicating
7216 an empty DIE). In either case *BYTES_READ will be set to the length of
7217 the initial number. */
7219 static struct abbrev_info
*
7220 peek_die_abbrev (const gdb_byte
*info_ptr
, unsigned int *bytes_read
,
7221 struct dwarf2_cu
*cu
)
7223 bfd
*abfd
= cu
->objfile
->obfd
;
7224 unsigned int abbrev_number
;
7225 struct abbrev_info
*abbrev
;
7227 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
7229 if (abbrev_number
== 0)
7232 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
7235 error (_("Dwarf Error: Could not find abbrev number %d in %s"
7236 " at offset 0x%x [in module %s]"),
7237 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
7238 cu
->header
.offset
.sect_off
, bfd_get_filename (abfd
));
7244 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7245 Returns a pointer to the end of a series of DIEs, terminated by an empty
7246 DIE. Any children of the skipped DIEs will also be skipped. */
7248 static const gdb_byte
*
7249 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
7251 struct dwarf2_cu
*cu
= reader
->cu
;
7252 struct abbrev_info
*abbrev
;
7253 unsigned int bytes_read
;
7257 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
7259 return info_ptr
+ bytes_read
;
7261 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
7265 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7266 INFO_PTR should point just after the initial uleb128 of a DIE, and the
7267 abbrev corresponding to that skipped uleb128 should be passed in
7268 ABBREV. Returns a pointer to this DIE's sibling, skipping any
7271 static const gdb_byte
*
7272 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
7273 struct abbrev_info
*abbrev
)
7275 unsigned int bytes_read
;
7276 struct attribute attr
;
7277 bfd
*abfd
= reader
->abfd
;
7278 struct dwarf2_cu
*cu
= reader
->cu
;
7279 const gdb_byte
*buffer
= reader
->buffer
;
7280 const gdb_byte
*buffer_end
= reader
->buffer_end
;
7281 unsigned int form
, i
;
7283 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
7285 /* The only abbrev we care about is DW_AT_sibling. */
7286 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
7288 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
7289 if (attr
.form
== DW_FORM_ref_addr
)
7290 complaint (&symfile_complaints
,
7291 _("ignoring absolute DW_AT_sibling"));
7294 unsigned int off
= dwarf2_get_ref_die_offset (&attr
).sect_off
;
7295 const gdb_byte
*sibling_ptr
= buffer
+ off
;
7297 if (sibling_ptr
< info_ptr
)
7298 complaint (&symfile_complaints
,
7299 _("DW_AT_sibling points backwards"));
7300 else if (sibling_ptr
> reader
->buffer_end
)
7301 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
7307 /* If it isn't DW_AT_sibling, skip this attribute. */
7308 form
= abbrev
->attrs
[i
].form
;
7312 case DW_FORM_ref_addr
:
7313 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
7314 and later it is offset sized. */
7315 if (cu
->header
.version
== 2)
7316 info_ptr
+= cu
->header
.addr_size
;
7318 info_ptr
+= cu
->header
.offset_size
;
7320 case DW_FORM_GNU_ref_alt
:
7321 info_ptr
+= cu
->header
.offset_size
;
7324 info_ptr
+= cu
->header
.addr_size
;
7331 case DW_FORM_flag_present
:
7343 case DW_FORM_ref_sig8
:
7346 case DW_FORM_string
:
7347 read_direct_string (abfd
, info_ptr
, &bytes_read
);
7348 info_ptr
+= bytes_read
;
7350 case DW_FORM_sec_offset
:
7352 case DW_FORM_GNU_strp_alt
:
7353 info_ptr
+= cu
->header
.offset_size
;
7355 case DW_FORM_exprloc
:
7357 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7358 info_ptr
+= bytes_read
;
7360 case DW_FORM_block1
:
7361 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
7363 case DW_FORM_block2
:
7364 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
7366 case DW_FORM_block4
:
7367 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
7371 case DW_FORM_ref_udata
:
7372 case DW_FORM_GNU_addr_index
:
7373 case DW_FORM_GNU_str_index
:
7374 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
7376 case DW_FORM_indirect
:
7377 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7378 info_ptr
+= bytes_read
;
7379 /* We need to continue parsing from here, so just go back to
7381 goto skip_attribute
;
7384 error (_("Dwarf Error: Cannot handle %s "
7385 "in DWARF reader [in module %s]"),
7386 dwarf_form_name (form
),
7387 bfd_get_filename (abfd
));
7391 if (abbrev
->has_children
)
7392 return skip_children (reader
, info_ptr
);
7397 /* Locate ORIG_PDI's sibling.
7398 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
7400 static const gdb_byte
*
7401 locate_pdi_sibling (const struct die_reader_specs
*reader
,
7402 struct partial_die_info
*orig_pdi
,
7403 const gdb_byte
*info_ptr
)
7405 /* Do we know the sibling already? */
7407 if (orig_pdi
->sibling
)
7408 return orig_pdi
->sibling
;
7410 /* Are there any children to deal with? */
7412 if (!orig_pdi
->has_children
)
7415 /* Skip the children the long way. */
7417 return skip_children (reader
, info_ptr
);
7420 /* Expand this partial symbol table into a full symbol table. SELF is
7424 dwarf2_read_symtab (struct partial_symtab
*self
,
7425 struct objfile
*objfile
)
7429 warning (_("bug: psymtab for %s is already read in."),
7436 printf_filtered (_("Reading in symbols for %s..."),
7438 gdb_flush (gdb_stdout
);
7441 /* Restore our global data. */
7443 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
7444 dwarf2_objfile_data_key
);
7446 /* If this psymtab is constructed from a debug-only objfile, the
7447 has_section_at_zero flag will not necessarily be correct. We
7448 can get the correct value for this flag by looking at the data
7449 associated with the (presumably stripped) associated objfile. */
7450 if (objfile
->separate_debug_objfile_backlink
)
7452 struct dwarf2_per_objfile
*dpo_backlink
7453 = ((struct dwarf2_per_objfile
*)
7454 objfile_data (objfile
->separate_debug_objfile_backlink
,
7455 dwarf2_objfile_data_key
));
7457 dwarf2_per_objfile
->has_section_at_zero
7458 = dpo_backlink
->has_section_at_zero
;
7461 dwarf2_per_objfile
->reading_partial_symbols
= 0;
7463 psymtab_to_symtab_1 (self
);
7465 /* Finish up the debug error message. */
7467 printf_filtered (_("done.\n"));
7470 process_cu_includes ();
7473 /* Reading in full CUs. */
7475 /* Add PER_CU to the queue. */
7478 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
7479 enum language pretend_language
)
7481 struct dwarf2_queue_item
*item
;
7484 item
= XNEW (struct dwarf2_queue_item
);
7485 item
->per_cu
= per_cu
;
7486 item
->pretend_language
= pretend_language
;
7489 if (dwarf2_queue
== NULL
)
7490 dwarf2_queue
= item
;
7492 dwarf2_queue_tail
->next
= item
;
7494 dwarf2_queue_tail
= item
;
7497 /* If PER_CU is not yet queued, add it to the queue.
7498 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
7500 The result is non-zero if PER_CU was queued, otherwise the result is zero
7501 meaning either PER_CU is already queued or it is already loaded.
7503 N.B. There is an invariant here that if a CU is queued then it is loaded.
7504 The caller is required to load PER_CU if we return non-zero. */
7507 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
7508 struct dwarf2_per_cu_data
*per_cu
,
7509 enum language pretend_language
)
7511 /* We may arrive here during partial symbol reading, if we need full
7512 DIEs to process an unusual case (e.g. template arguments). Do
7513 not queue PER_CU, just tell our caller to load its DIEs. */
7514 if (dwarf2_per_objfile
->reading_partial_symbols
)
7516 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
7521 /* Mark the dependence relation so that we don't flush PER_CU
7523 if (dependent_cu
!= NULL
)
7524 dwarf2_add_dependence (dependent_cu
, per_cu
);
7526 /* If it's already on the queue, we have nothing to do. */
7530 /* If the compilation unit is already loaded, just mark it as
7532 if (per_cu
->cu
!= NULL
)
7534 per_cu
->cu
->last_used
= 0;
7538 /* Add it to the queue. */
7539 queue_comp_unit (per_cu
, pretend_language
);
7544 /* Process the queue. */
7547 process_queue (void)
7549 struct dwarf2_queue_item
*item
, *next_item
;
7551 if (dwarf_read_debug
)
7553 fprintf_unfiltered (gdb_stdlog
,
7554 "Expanding one or more symtabs of objfile %s ...\n",
7555 objfile_name (dwarf2_per_objfile
->objfile
));
7558 /* The queue starts out with one item, but following a DIE reference
7559 may load a new CU, adding it to the end of the queue. */
7560 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
7562 if ((dwarf2_per_objfile
->using_index
7563 ? !item
->per_cu
->v
.quick
->compunit_symtab
7564 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
7565 /* Skip dummy CUs. */
7566 && item
->per_cu
->cu
!= NULL
)
7568 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
7569 unsigned int debug_print_threshold
;
7572 if (per_cu
->is_debug_types
)
7574 struct signatured_type
*sig_type
=
7575 (struct signatured_type
*) per_cu
;
7577 sprintf (buf
, "TU %s at offset 0x%x",
7578 hex_string (sig_type
->signature
),
7579 per_cu
->offset
.sect_off
);
7580 /* There can be 100s of TUs.
7581 Only print them in verbose mode. */
7582 debug_print_threshold
= 2;
7586 sprintf (buf
, "CU at offset 0x%x", per_cu
->offset
.sect_off
);
7587 debug_print_threshold
= 1;
7590 if (dwarf_read_debug
>= debug_print_threshold
)
7591 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
7593 if (per_cu
->is_debug_types
)
7594 process_full_type_unit (per_cu
, item
->pretend_language
);
7596 process_full_comp_unit (per_cu
, item
->pretend_language
);
7598 if (dwarf_read_debug
>= debug_print_threshold
)
7599 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
7602 item
->per_cu
->queued
= 0;
7603 next_item
= item
->next
;
7607 dwarf2_queue_tail
= NULL
;
7609 if (dwarf_read_debug
)
7611 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
7612 objfile_name (dwarf2_per_objfile
->objfile
));
7616 /* Free all allocated queue entries. This function only releases anything if
7617 an error was thrown; if the queue was processed then it would have been
7618 freed as we went along. */
7621 dwarf2_release_queue (void *dummy
)
7623 struct dwarf2_queue_item
*item
, *last
;
7625 item
= dwarf2_queue
;
7628 /* Anything still marked queued is likely to be in an
7629 inconsistent state, so discard it. */
7630 if (item
->per_cu
->queued
)
7632 if (item
->per_cu
->cu
!= NULL
)
7633 free_one_cached_comp_unit (item
->per_cu
);
7634 item
->per_cu
->queued
= 0;
7642 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
7645 /* Read in full symbols for PST, and anything it depends on. */
7648 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
7650 struct dwarf2_per_cu_data
*per_cu
;
7656 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
7657 if (!pst
->dependencies
[i
]->readin
7658 && pst
->dependencies
[i
]->user
== NULL
)
7660 /* Inform about additional files that need to be read in. */
7663 /* FIXME: i18n: Need to make this a single string. */
7664 fputs_filtered (" ", gdb_stdout
);
7666 fputs_filtered ("and ", gdb_stdout
);
7668 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
7669 wrap_here (""); /* Flush output. */
7670 gdb_flush (gdb_stdout
);
7672 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
7675 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
7679 /* It's an include file, no symbols to read for it.
7680 Everything is in the parent symtab. */
7685 dw2_do_instantiate_symtab (per_cu
);
7688 /* Trivial hash function for die_info: the hash value of a DIE
7689 is its offset in .debug_info for this objfile. */
7692 die_hash (const void *item
)
7694 const struct die_info
*die
= (const struct die_info
*) item
;
7696 return die
->offset
.sect_off
;
7699 /* Trivial comparison function for die_info structures: two DIEs
7700 are equal if they have the same offset. */
7703 die_eq (const void *item_lhs
, const void *item_rhs
)
7705 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
7706 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
7708 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
7711 /* die_reader_func for load_full_comp_unit.
7712 This is identical to read_signatured_type_reader,
7713 but is kept separate for now. */
7716 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
7717 const gdb_byte
*info_ptr
,
7718 struct die_info
*comp_unit_die
,
7722 struct dwarf2_cu
*cu
= reader
->cu
;
7723 enum language
*language_ptr
= (enum language
*) data
;
7725 gdb_assert (cu
->die_hash
== NULL
);
7727 htab_create_alloc_ex (cu
->header
.length
/ 12,
7731 &cu
->comp_unit_obstack
,
7732 hashtab_obstack_allocate
,
7733 dummy_obstack_deallocate
);
7736 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
7737 &info_ptr
, comp_unit_die
);
7738 cu
->dies
= comp_unit_die
;
7739 /* comp_unit_die is not stored in die_hash, no need. */
7741 /* We try not to read any attributes in this function, because not
7742 all CUs needed for references have been loaded yet, and symbol
7743 table processing isn't initialized. But we have to set the CU language,
7744 or we won't be able to build types correctly.
7745 Similarly, if we do not read the producer, we can not apply
7746 producer-specific interpretation. */
7747 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
7750 /* Load the DIEs associated with PER_CU into memory. */
7753 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7754 enum language pretend_language
)
7756 gdb_assert (! this_cu
->is_debug_types
);
7758 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
7759 load_full_comp_unit_reader
, &pretend_language
);
7762 /* Add a DIE to the delayed physname list. */
7765 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
7766 const char *name
, struct die_info
*die
,
7767 struct dwarf2_cu
*cu
)
7769 struct delayed_method_info mi
;
7771 mi
.fnfield_index
= fnfield_index
;
7775 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
7778 /* A cleanup for freeing the delayed method list. */
7781 free_delayed_list (void *ptr
)
7783 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
7784 if (cu
->method_list
!= NULL
)
7786 VEC_free (delayed_method_info
, cu
->method_list
);
7787 cu
->method_list
= NULL
;
7791 /* Compute the physnames of any methods on the CU's method list.
7793 The computation of method physnames is delayed in order to avoid the
7794 (bad) condition that one of the method's formal parameters is of an as yet
7798 compute_delayed_physnames (struct dwarf2_cu
*cu
)
7801 struct delayed_method_info
*mi
;
7802 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
7804 const char *physname
;
7805 struct fn_fieldlist
*fn_flp
7806 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
7807 physname
= dwarf2_physname (mi
->name
, mi
->die
, cu
);
7808 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
->index
)
7809 = physname
? physname
: "";
7813 /* Go objects should be embedded in a DW_TAG_module DIE,
7814 and it's not clear if/how imported objects will appear.
7815 To keep Go support simple until that's worked out,
7816 go back through what we've read and create something usable.
7817 We could do this while processing each DIE, and feels kinda cleaner,
7818 but that way is more invasive.
7819 This is to, for example, allow the user to type "p var" or "b main"
7820 without having to specify the package name, and allow lookups
7821 of module.object to work in contexts that use the expression
7825 fixup_go_packaging (struct dwarf2_cu
*cu
)
7827 char *package_name
= NULL
;
7828 struct pending
*list
;
7831 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
7833 for (i
= 0; i
< list
->nsyms
; ++i
)
7835 struct symbol
*sym
= list
->symbol
[i
];
7837 if (SYMBOL_LANGUAGE (sym
) == language_go
7838 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
7840 char *this_package_name
= go_symbol_package_name (sym
);
7842 if (this_package_name
== NULL
)
7844 if (package_name
== NULL
)
7845 package_name
= this_package_name
;
7848 if (strcmp (package_name
, this_package_name
) != 0)
7849 complaint (&symfile_complaints
,
7850 _("Symtab %s has objects from two different Go packages: %s and %s"),
7851 (symbol_symtab (sym
) != NULL
7852 ? symtab_to_filename_for_display
7853 (symbol_symtab (sym
))
7854 : objfile_name (cu
->objfile
)),
7855 this_package_name
, package_name
);
7856 xfree (this_package_name
);
7862 if (package_name
!= NULL
)
7864 struct objfile
*objfile
= cu
->objfile
;
7865 const char *saved_package_name
7866 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
7868 strlen (package_name
));
7869 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
7870 saved_package_name
);
7873 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7875 sym
= allocate_symbol (objfile
);
7876 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
7877 SYMBOL_SET_NAMES (sym
, saved_package_name
,
7878 strlen (saved_package_name
), 0, objfile
);
7879 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
7880 e.g., "main" finds the "main" module and not C's main(). */
7881 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7882 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
7883 SYMBOL_TYPE (sym
) = type
;
7885 add_symbol_to_list (sym
, &global_symbols
);
7887 xfree (package_name
);
7891 /* Return the symtab for PER_CU. This works properly regardless of
7892 whether we're using the index or psymtabs. */
7894 static struct compunit_symtab
*
7895 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
7897 return (dwarf2_per_objfile
->using_index
7898 ? per_cu
->v
.quick
->compunit_symtab
7899 : per_cu
->v
.psymtab
->compunit_symtab
);
7902 /* A helper function for computing the list of all symbol tables
7903 included by PER_CU. */
7906 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
7907 htab_t all_children
, htab_t all_type_symtabs
,
7908 struct dwarf2_per_cu_data
*per_cu
,
7909 struct compunit_symtab
*immediate_parent
)
7913 struct compunit_symtab
*cust
;
7914 struct dwarf2_per_cu_data
*iter
;
7916 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
7919 /* This inclusion and its children have been processed. */
7924 /* Only add a CU if it has a symbol table. */
7925 cust
= get_compunit_symtab (per_cu
);
7928 /* If this is a type unit only add its symbol table if we haven't
7929 seen it yet (type unit per_cu's can share symtabs). */
7930 if (per_cu
->is_debug_types
)
7932 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
7936 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
7937 if (cust
->user
== NULL
)
7938 cust
->user
= immediate_parent
;
7943 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
7944 if (cust
->user
== NULL
)
7945 cust
->user
= immediate_parent
;
7950 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
7953 recursively_compute_inclusions (result
, all_children
,
7954 all_type_symtabs
, iter
, cust
);
7958 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
7962 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
7964 gdb_assert (! per_cu
->is_debug_types
);
7966 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
7969 struct dwarf2_per_cu_data
*per_cu_iter
;
7970 struct compunit_symtab
*compunit_symtab_iter
;
7971 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
7972 htab_t all_children
, all_type_symtabs
;
7973 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
7975 /* If we don't have a symtab, we can just skip this case. */
7979 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
7980 NULL
, xcalloc
, xfree
);
7981 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
7982 NULL
, xcalloc
, xfree
);
7985 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
7989 recursively_compute_inclusions (&result_symtabs
, all_children
,
7990 all_type_symtabs
, per_cu_iter
,
7994 /* Now we have a transitive closure of all the included symtabs. */
7995 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
7997 = XOBNEWVEC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
7998 struct compunit_symtab
*, len
+ 1);
8000 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
8001 compunit_symtab_iter
);
8003 cust
->includes
[ix
] = compunit_symtab_iter
;
8004 cust
->includes
[len
] = NULL
;
8006 VEC_free (compunit_symtab_ptr
, result_symtabs
);
8007 htab_delete (all_children
);
8008 htab_delete (all_type_symtabs
);
8012 /* Compute the 'includes' field for the symtabs of all the CUs we just
8016 process_cu_includes (void)
8019 struct dwarf2_per_cu_data
*iter
;
8022 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
8026 if (! iter
->is_debug_types
)
8027 compute_compunit_symtab_includes (iter
);
8030 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
8033 /* Generate full symbol information for PER_CU, whose DIEs have
8034 already been loaded into memory. */
8037 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8038 enum language pretend_language
)
8040 struct dwarf2_cu
*cu
= per_cu
->cu
;
8041 struct objfile
*objfile
= per_cu
->objfile
;
8042 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8043 CORE_ADDR lowpc
, highpc
;
8044 struct compunit_symtab
*cust
;
8045 struct cleanup
*back_to
, *delayed_list_cleanup
;
8047 struct block
*static_block
;
8050 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8053 back_to
= make_cleanup (really_free_pendings
, NULL
);
8054 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8056 cu
->list_in_scope
= &file_symbols
;
8058 cu
->language
= pretend_language
;
8059 cu
->language_defn
= language_def (cu
->language
);
8061 /* Do line number decoding in read_file_scope () */
8062 process_die (cu
->dies
, cu
);
8064 /* For now fudge the Go package. */
8065 if (cu
->language
== language_go
)
8066 fixup_go_packaging (cu
);
8068 /* Now that we have processed all the DIEs in the CU, all the types
8069 should be complete, and it should now be safe to compute all of the
8071 compute_delayed_physnames (cu
);
8072 do_cleanups (delayed_list_cleanup
);
8074 /* Some compilers don't define a DW_AT_high_pc attribute for the
8075 compilation unit. If the DW_AT_high_pc is missing, synthesize
8076 it, by scanning the DIE's below the compilation unit. */
8077 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
8079 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
8080 static_block
= end_symtab_get_static_block (addr
, 0, 1);
8082 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
8083 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
8084 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
8085 addrmap to help ensure it has an accurate map of pc values belonging to
8087 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
8089 cust
= end_symtab_from_static_block (static_block
,
8090 SECT_OFF_TEXT (objfile
), 0);
8094 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
8096 /* Set symtab language to language from DW_AT_language. If the
8097 compilation is from a C file generated by language preprocessors, do
8098 not set the language if it was already deduced by start_subfile. */
8099 if (!(cu
->language
== language_c
8100 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
8101 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8103 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
8104 produce DW_AT_location with location lists but it can be possibly
8105 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
8106 there were bugs in prologue debug info, fixed later in GCC-4.5
8107 by "unwind info for epilogues" patch (which is not directly related).
8109 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
8110 needed, it would be wrong due to missing DW_AT_producer there.
8112 Still one can confuse GDB by using non-standard GCC compilation
8113 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
8115 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
8116 cust
->locations_valid
= 1;
8118 if (gcc_4_minor
>= 5)
8119 cust
->epilogue_unwind_valid
= 1;
8121 cust
->call_site_htab
= cu
->call_site_htab
;
8124 if (dwarf2_per_objfile
->using_index
)
8125 per_cu
->v
.quick
->compunit_symtab
= cust
;
8128 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8129 pst
->compunit_symtab
= cust
;
8133 /* Push it for inclusion processing later. */
8134 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
8136 do_cleanups (back_to
);
8139 /* Generate full symbol information for type unit PER_CU, whose DIEs have
8140 already been loaded into memory. */
8143 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
8144 enum language pretend_language
)
8146 struct dwarf2_cu
*cu
= per_cu
->cu
;
8147 struct objfile
*objfile
= per_cu
->objfile
;
8148 struct compunit_symtab
*cust
;
8149 struct cleanup
*back_to
, *delayed_list_cleanup
;
8150 struct signatured_type
*sig_type
;
8152 gdb_assert (per_cu
->is_debug_types
);
8153 sig_type
= (struct signatured_type
*) per_cu
;
8156 back_to
= make_cleanup (really_free_pendings
, NULL
);
8157 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8159 cu
->list_in_scope
= &file_symbols
;
8161 cu
->language
= pretend_language
;
8162 cu
->language_defn
= language_def (cu
->language
);
8164 /* The symbol tables are set up in read_type_unit_scope. */
8165 process_die (cu
->dies
, cu
);
8167 /* For now fudge the Go package. */
8168 if (cu
->language
== language_go
)
8169 fixup_go_packaging (cu
);
8171 /* Now that we have processed all the DIEs in the CU, all the types
8172 should be complete, and it should now be safe to compute all of the
8174 compute_delayed_physnames (cu
);
8175 do_cleanups (delayed_list_cleanup
);
8177 /* TUs share symbol tables.
8178 If this is the first TU to use this symtab, complete the construction
8179 of it with end_expandable_symtab. Otherwise, complete the addition of
8180 this TU's symbols to the existing symtab. */
8181 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
8183 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
8184 sig_type
->type_unit_group
->compunit_symtab
= cust
;
8188 /* Set symtab language to language from DW_AT_language. If the
8189 compilation is from a C file generated by language preprocessors,
8190 do not set the language if it was already deduced by
8192 if (!(cu
->language
== language_c
8193 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
8194 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8199 augment_type_symtab ();
8200 cust
= sig_type
->type_unit_group
->compunit_symtab
;
8203 if (dwarf2_per_objfile
->using_index
)
8204 per_cu
->v
.quick
->compunit_symtab
= cust
;
8207 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8208 pst
->compunit_symtab
= cust
;
8212 do_cleanups (back_to
);
8215 /* Process an imported unit DIE. */
8218 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8220 struct attribute
*attr
;
8222 /* For now we don't handle imported units in type units. */
8223 if (cu
->per_cu
->is_debug_types
)
8225 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8226 " supported in type units [in module %s]"),
8227 objfile_name (cu
->objfile
));
8230 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8233 struct dwarf2_per_cu_data
*per_cu
;
8237 offset
= dwarf2_get_ref_die_offset (attr
);
8238 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
8239 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
8241 /* If necessary, add it to the queue and load its DIEs. */
8242 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
8243 load_full_comp_unit (per_cu
, cu
->language
);
8245 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8250 /* Reset the in_process bit of a die. */
8253 reset_die_in_process (void *arg
)
8255 struct die_info
*die
= (struct die_info
*) arg
;
8257 die
->in_process
= 0;
8260 /* Process a die and its children. */
8263 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8265 struct cleanup
*in_process
;
8267 /* We should only be processing those not already in process. */
8268 gdb_assert (!die
->in_process
);
8270 die
->in_process
= 1;
8271 in_process
= make_cleanup (reset_die_in_process
,die
);
8275 case DW_TAG_padding
:
8277 case DW_TAG_compile_unit
:
8278 case DW_TAG_partial_unit
:
8279 read_file_scope (die
, cu
);
8281 case DW_TAG_type_unit
:
8282 read_type_unit_scope (die
, cu
);
8284 case DW_TAG_subprogram
:
8285 case DW_TAG_inlined_subroutine
:
8286 read_func_scope (die
, cu
);
8288 case DW_TAG_lexical_block
:
8289 case DW_TAG_try_block
:
8290 case DW_TAG_catch_block
:
8291 read_lexical_block_scope (die
, cu
);
8293 case DW_TAG_GNU_call_site
:
8294 read_call_site_scope (die
, cu
);
8296 case DW_TAG_class_type
:
8297 case DW_TAG_interface_type
:
8298 case DW_TAG_structure_type
:
8299 case DW_TAG_union_type
:
8300 process_structure_scope (die
, cu
);
8302 case DW_TAG_enumeration_type
:
8303 process_enumeration_scope (die
, cu
);
8306 /* These dies have a type, but processing them does not create
8307 a symbol or recurse to process the children. Therefore we can
8308 read them on-demand through read_type_die. */
8309 case DW_TAG_subroutine_type
:
8310 case DW_TAG_set_type
:
8311 case DW_TAG_array_type
:
8312 case DW_TAG_pointer_type
:
8313 case DW_TAG_ptr_to_member_type
:
8314 case DW_TAG_reference_type
:
8315 case DW_TAG_string_type
:
8318 case DW_TAG_base_type
:
8319 case DW_TAG_subrange_type
:
8320 case DW_TAG_typedef
:
8321 /* Add a typedef symbol for the type definition, if it has a
8323 new_symbol (die
, read_type_die (die
, cu
), cu
);
8325 case DW_TAG_common_block
:
8326 read_common_block (die
, cu
);
8328 case DW_TAG_common_inclusion
:
8330 case DW_TAG_namespace
:
8331 cu
->processing_has_namespace_info
= 1;
8332 read_namespace (die
, cu
);
8335 cu
->processing_has_namespace_info
= 1;
8336 read_module (die
, cu
);
8338 case DW_TAG_imported_declaration
:
8339 cu
->processing_has_namespace_info
= 1;
8340 if (read_namespace_alias (die
, cu
))
8342 /* The declaration is not a global namespace alias: fall through. */
8343 case DW_TAG_imported_module
:
8344 cu
->processing_has_namespace_info
= 1;
8345 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
8346 || cu
->language
!= language_fortran
))
8347 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
8348 dwarf_tag_name (die
->tag
));
8349 read_import_statement (die
, cu
);
8352 case DW_TAG_imported_unit
:
8353 process_imported_unit_die (die
, cu
);
8357 new_symbol (die
, NULL
, cu
);
8361 do_cleanups (in_process
);
8364 /* DWARF name computation. */
8366 /* A helper function for dwarf2_compute_name which determines whether DIE
8367 needs to have the name of the scope prepended to the name listed in the
8371 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8373 struct attribute
*attr
;
8377 case DW_TAG_namespace
:
8378 case DW_TAG_typedef
:
8379 case DW_TAG_class_type
:
8380 case DW_TAG_interface_type
:
8381 case DW_TAG_structure_type
:
8382 case DW_TAG_union_type
:
8383 case DW_TAG_enumeration_type
:
8384 case DW_TAG_enumerator
:
8385 case DW_TAG_subprogram
:
8386 case DW_TAG_inlined_subroutine
:
8388 case DW_TAG_imported_declaration
:
8391 case DW_TAG_variable
:
8392 case DW_TAG_constant
:
8393 /* We only need to prefix "globally" visible variables. These include
8394 any variable marked with DW_AT_external or any variable that
8395 lives in a namespace. [Variables in anonymous namespaces
8396 require prefixing, but they are not DW_AT_external.] */
8398 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
8400 struct dwarf2_cu
*spec_cu
= cu
;
8402 return die_needs_namespace (die_specification (die
, &spec_cu
),
8406 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8407 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
8408 && die
->parent
->tag
!= DW_TAG_module
)
8410 /* A variable in a lexical block of some kind does not need a
8411 namespace, even though in C++ such variables may be external
8412 and have a mangled name. */
8413 if (die
->parent
->tag
== DW_TAG_lexical_block
8414 || die
->parent
->tag
== DW_TAG_try_block
8415 || die
->parent
->tag
== DW_TAG_catch_block
8416 || die
->parent
->tag
== DW_TAG_subprogram
)
8425 /* Retrieve the last character from a mem_file. */
8428 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
8430 char *last_char_p
= (char *) object
;
8433 *last_char_p
= buffer
[length
- 1];
8436 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
8437 compute the physname for the object, which include a method's:
8438 - formal parameters (C++/Java),
8439 - receiver type (Go),
8440 - return type (Java).
8442 The term "physname" is a bit confusing.
8443 For C++, for example, it is the demangled name.
8444 For Go, for example, it's the mangled name.
8446 For Ada, return the DIE's linkage name rather than the fully qualified
8447 name. PHYSNAME is ignored..
8449 The result is allocated on the objfile_obstack and canonicalized. */
8452 dwarf2_compute_name (const char *name
,
8453 struct die_info
*die
, struct dwarf2_cu
*cu
,
8456 struct objfile
*objfile
= cu
->objfile
;
8459 name
= dwarf2_name (die
, cu
);
8461 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
8462 but otherwise compute it by typename_concat inside GDB.
8463 FIXME: Actually this is not really true, or at least not always true.
8464 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
8465 Fortran names because there is no mangling standard. So new_symbol_full
8466 will set the demangled name to the result of dwarf2_full_name, and it is
8467 the demangled name that GDB uses if it exists. */
8468 if (cu
->language
== language_ada
8469 || (cu
->language
== language_fortran
&& physname
))
8471 /* For Ada unit, we prefer the linkage name over the name, as
8472 the former contains the exported name, which the user expects
8473 to be able to reference. Ideally, we want the user to be able
8474 to reference this entity using either natural or linkage name,
8475 but we haven't started looking at this enhancement yet. */
8476 const char *linkage_name
;
8478 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
8479 if (linkage_name
== NULL
)
8480 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8481 if (linkage_name
!= NULL
)
8482 return linkage_name
;
8485 /* These are the only languages we know how to qualify names in. */
8487 && (cu
->language
== language_cplus
|| cu
->language
== language_java
8488 || cu
->language
== language_fortran
|| cu
->language
== language_d
8489 || cu
->language
== language_rust
))
8491 if (die_needs_namespace (die
, cu
))
8495 struct ui_file
*buf
;
8496 char *intermediate_name
;
8497 const char *canonical_name
= NULL
;
8499 prefix
= determine_prefix (die
, cu
);
8500 buf
= mem_fileopen ();
8501 if (*prefix
!= '\0')
8503 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
8506 fputs_unfiltered (prefixed_name
, buf
);
8507 xfree (prefixed_name
);
8510 fputs_unfiltered (name
, buf
);
8512 /* Template parameters may be specified in the DIE's DW_AT_name, or
8513 as children with DW_TAG_template_type_param or
8514 DW_TAG_value_type_param. If the latter, add them to the name
8515 here. If the name already has template parameters, then
8516 skip this step; some versions of GCC emit both, and
8517 it is more efficient to use the pre-computed name.
8519 Something to keep in mind about this process: it is very
8520 unlikely, or in some cases downright impossible, to produce
8521 something that will match the mangled name of a function.
8522 If the definition of the function has the same debug info,
8523 we should be able to match up with it anyway. But fallbacks
8524 using the minimal symbol, for instance to find a method
8525 implemented in a stripped copy of libstdc++, will not work.
8526 If we do not have debug info for the definition, we will have to
8527 match them up some other way.
8529 When we do name matching there is a related problem with function
8530 templates; two instantiated function templates are allowed to
8531 differ only by their return types, which we do not add here. */
8533 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
8535 struct attribute
*attr
;
8536 struct die_info
*child
;
8539 die
->building_fullname
= 1;
8541 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
8545 const gdb_byte
*bytes
;
8546 struct dwarf2_locexpr_baton
*baton
;
8549 if (child
->tag
!= DW_TAG_template_type_param
8550 && child
->tag
!= DW_TAG_template_value_param
)
8555 fputs_unfiltered ("<", buf
);
8559 fputs_unfiltered (", ", buf
);
8561 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
8564 complaint (&symfile_complaints
,
8565 _("template parameter missing DW_AT_type"));
8566 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
8569 type
= die_type (child
, cu
);
8571 if (child
->tag
== DW_TAG_template_type_param
)
8573 c_print_type (type
, "", buf
, -1, 0, &type_print_raw_options
);
8577 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
8580 complaint (&symfile_complaints
,
8581 _("template parameter missing "
8582 "DW_AT_const_value"));
8583 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
8587 dwarf2_const_value_attr (attr
, type
, name
,
8588 &cu
->comp_unit_obstack
, cu
,
8589 &value
, &bytes
, &baton
);
8591 if (TYPE_NOSIGN (type
))
8592 /* GDB prints characters as NUMBER 'CHAR'. If that's
8593 changed, this can use value_print instead. */
8594 c_printchar (value
, type
, buf
);
8597 struct value_print_options opts
;
8600 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
8604 else if (bytes
!= NULL
)
8606 v
= allocate_value (type
);
8607 memcpy (value_contents_writeable (v
), bytes
,
8608 TYPE_LENGTH (type
));
8611 v
= value_from_longest (type
, value
);
8613 /* Specify decimal so that we do not depend on
8615 get_formatted_print_options (&opts
, 'd');
8617 value_print (v
, buf
, &opts
);
8623 die
->building_fullname
= 0;
8627 /* Close the argument list, with a space if necessary
8628 (nested templates). */
8629 char last_char
= '\0';
8630 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
8631 if (last_char
== '>')
8632 fputs_unfiltered (" >", buf
);
8634 fputs_unfiltered (">", buf
);
8638 /* For Java and C++ methods, append formal parameter type
8639 information, if PHYSNAME. */
8641 if (physname
&& die
->tag
== DW_TAG_subprogram
8642 && (cu
->language
== language_cplus
8643 || cu
->language
== language_java
))
8645 struct type
*type
= read_type_die (die
, cu
);
8647 c_type_print_args (type
, buf
, 1, cu
->language
,
8648 &type_print_raw_options
);
8650 if (cu
->language
== language_java
)
8652 /* For java, we must append the return type to method
8654 if (die
->tag
== DW_TAG_subprogram
)
8655 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
8656 0, 0, &type_print_raw_options
);
8658 else if (cu
->language
== language_cplus
)
8660 /* Assume that an artificial first parameter is
8661 "this", but do not crash if it is not. RealView
8662 marks unnamed (and thus unused) parameters as
8663 artificial; there is no way to differentiate
8665 if (TYPE_NFIELDS (type
) > 0
8666 && TYPE_FIELD_ARTIFICIAL (type
, 0)
8667 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
8668 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
8670 fputs_unfiltered (" const", buf
);
8674 intermediate_name
= ui_file_xstrdup (buf
, &length
);
8675 ui_file_delete (buf
);
8677 if (cu
->language
== language_cplus
)
8679 = dwarf2_canonicalize_name (intermediate_name
, cu
,
8680 &objfile
->per_bfd
->storage_obstack
);
8682 /* If we only computed INTERMEDIATE_NAME, or if
8683 INTERMEDIATE_NAME is already canonical, then we need to
8684 copy it to the appropriate obstack. */
8685 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
)
8686 name
= ((const char *)
8687 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8689 strlen (intermediate_name
)));
8691 name
= canonical_name
;
8693 xfree (intermediate_name
);
8700 /* Return the fully qualified name of DIE, based on its DW_AT_name.
8701 If scope qualifiers are appropriate they will be added. The result
8702 will be allocated on the storage_obstack, or NULL if the DIE does
8703 not have a name. NAME may either be from a previous call to
8704 dwarf2_name or NULL.
8706 The output string will be canonicalized (if C++/Java). */
8709 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8711 return dwarf2_compute_name (name
, die
, cu
, 0);
8714 /* Construct a physname for the given DIE in CU. NAME may either be
8715 from a previous call to dwarf2_name or NULL. The result will be
8716 allocated on the objfile_objstack or NULL if the DIE does not have a
8719 The output string will be canonicalized (if C++/Java). */
8722 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8724 struct objfile
*objfile
= cu
->objfile
;
8725 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
8726 struct cleanup
*back_to
;
8729 /* In this case dwarf2_compute_name is just a shortcut not building anything
8731 if (!die_needs_namespace (die
, cu
))
8732 return dwarf2_compute_name (name
, die
, cu
, 1);
8734 back_to
= make_cleanup (null_cleanup
, NULL
);
8736 mangled
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
8737 if (mangled
== NULL
)
8738 mangled
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8740 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
8741 See https://github.com/rust-lang/rust/issues/32925. */
8742 if (cu
->language
== language_rust
&& mangled
!= NULL
8743 && strchr (mangled
, '{') != NULL
)
8746 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
8748 if (mangled
!= NULL
)
8752 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
8753 type. It is easier for GDB users to search for such functions as
8754 `name(params)' than `long name(params)'. In such case the minimal
8755 symbol names do not match the full symbol names but for template
8756 functions there is never a need to look up their definition from their
8757 declaration so the only disadvantage remains the minimal symbol
8758 variant `long name(params)' does not have the proper inferior type.
8761 if (cu
->language
== language_go
)
8763 /* This is a lie, but we already lie to the caller new_symbol_full.
8764 new_symbol_full assumes we return the mangled name.
8765 This just undoes that lie until things are cleaned up. */
8770 demangled
= gdb_demangle (mangled
,
8771 (DMGL_PARAMS
| DMGL_ANSI
8772 | (cu
->language
== language_java
8773 ? DMGL_JAVA
| DMGL_RET_POSTFIX
8778 make_cleanup (xfree
, demangled
);
8788 if (canon
== NULL
|| check_physname
)
8790 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
8792 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
8794 /* It may not mean a bug in GDB. The compiler could also
8795 compute DW_AT_linkage_name incorrectly. But in such case
8796 GDB would need to be bug-to-bug compatible. */
8798 complaint (&symfile_complaints
,
8799 _("Computed physname <%s> does not match demangled <%s> "
8800 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
8801 physname
, canon
, mangled
, die
->offset
.sect_off
,
8802 objfile_name (objfile
));
8804 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
8805 is available here - over computed PHYSNAME. It is safer
8806 against both buggy GDB and buggy compilers. */
8820 retval
= ((const char *)
8821 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8822 retval
, strlen (retval
)));
8824 do_cleanups (back_to
);
8828 /* Inspect DIE in CU for a namespace alias. If one exists, record
8829 a new symbol for it.
8831 Returns 1 if a namespace alias was recorded, 0 otherwise. */
8834 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
8836 struct attribute
*attr
;
8838 /* If the die does not have a name, this is not a namespace
8840 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8844 struct die_info
*d
= die
;
8845 struct dwarf2_cu
*imported_cu
= cu
;
8847 /* If the compiler has nested DW_AT_imported_declaration DIEs,
8848 keep inspecting DIEs until we hit the underlying import. */
8849 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
8850 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
8852 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
8856 d
= follow_die_ref (d
, attr
, &imported_cu
);
8857 if (d
->tag
!= DW_TAG_imported_declaration
)
8861 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
8863 complaint (&symfile_complaints
,
8864 _("DIE at 0x%x has too many recursively imported "
8865 "declarations"), d
->offset
.sect_off
);
8872 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
8874 type
= get_die_type_at_offset (offset
, cu
->per_cu
);
8875 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
8877 /* This declaration is a global namespace alias. Add
8878 a symbol for it whose type is the aliased namespace. */
8879 new_symbol (die
, type
, cu
);
8888 /* Return the using directives repository (global or local?) to use in the
8889 current context for LANGUAGE.
8891 For Ada, imported declarations can materialize renamings, which *may* be
8892 global. However it is impossible (for now?) in DWARF to distinguish
8893 "external" imported declarations and "static" ones. As all imported
8894 declarations seem to be static in all other languages, make them all CU-wide
8895 global only in Ada. */
8897 static struct using_direct
**
8898 using_directives (enum language language
)
8900 if (language
== language_ada
&& context_stack_depth
== 0)
8901 return &global_using_directives
;
8903 return &local_using_directives
;
8906 /* Read the import statement specified by the given die and record it. */
8909 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
8911 struct objfile
*objfile
= cu
->objfile
;
8912 struct attribute
*import_attr
;
8913 struct die_info
*imported_die
, *child_die
;
8914 struct dwarf2_cu
*imported_cu
;
8915 const char *imported_name
;
8916 const char *imported_name_prefix
;
8917 const char *canonical_name
;
8918 const char *import_alias
;
8919 const char *imported_declaration
= NULL
;
8920 const char *import_prefix
;
8921 VEC (const_char_ptr
) *excludes
= NULL
;
8922 struct cleanup
*cleanups
;
8924 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8925 if (import_attr
== NULL
)
8927 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
8928 dwarf_tag_name (die
->tag
));
8933 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
8934 imported_name
= dwarf2_name (imported_die
, imported_cu
);
8935 if (imported_name
== NULL
)
8937 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
8939 The import in the following code:
8953 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
8954 <52> DW_AT_decl_file : 1
8955 <53> DW_AT_decl_line : 6
8956 <54> DW_AT_import : <0x75>
8957 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
8959 <5b> DW_AT_decl_file : 1
8960 <5c> DW_AT_decl_line : 2
8961 <5d> DW_AT_type : <0x6e>
8963 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
8964 <76> DW_AT_byte_size : 4
8965 <77> DW_AT_encoding : 5 (signed)
8967 imports the wrong die ( 0x75 instead of 0x58 ).
8968 This case will be ignored until the gcc bug is fixed. */
8972 /* Figure out the local name after import. */
8973 import_alias
= dwarf2_name (die
, cu
);
8975 /* Figure out where the statement is being imported to. */
8976 import_prefix
= determine_prefix (die
, cu
);
8978 /* Figure out what the scope of the imported die is and prepend it
8979 to the name of the imported die. */
8980 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
8982 if (imported_die
->tag
!= DW_TAG_namespace
8983 && imported_die
->tag
!= DW_TAG_module
)
8985 imported_declaration
= imported_name
;
8986 canonical_name
= imported_name_prefix
;
8988 else if (strlen (imported_name_prefix
) > 0)
8989 canonical_name
= obconcat (&objfile
->objfile_obstack
,
8990 imported_name_prefix
,
8991 (cu
->language
== language_d
? "." : "::"),
8992 imported_name
, (char *) NULL
);
8994 canonical_name
= imported_name
;
8996 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
8998 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
8999 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
9000 child_die
= sibling_die (child_die
))
9002 /* DWARF-4: A Fortran use statement with a “rename list” may be
9003 represented by an imported module entry with an import attribute
9004 referring to the module and owned entries corresponding to those
9005 entities that are renamed as part of being imported. */
9007 if (child_die
->tag
!= DW_TAG_imported_declaration
)
9009 complaint (&symfile_complaints
,
9010 _("child DW_TAG_imported_declaration expected "
9011 "- DIE at 0x%x [in module %s]"),
9012 child_die
->offset
.sect_off
, objfile_name (objfile
));
9016 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
9017 if (import_attr
== NULL
)
9019 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
9020 dwarf_tag_name (child_die
->tag
));
9025 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
9027 imported_name
= dwarf2_name (imported_die
, imported_cu
);
9028 if (imported_name
== NULL
)
9030 complaint (&symfile_complaints
,
9031 _("child DW_TAG_imported_declaration has unknown "
9032 "imported name - DIE at 0x%x [in module %s]"),
9033 child_die
->offset
.sect_off
, objfile_name (objfile
));
9037 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
9039 process_die (child_die
, cu
);
9042 add_using_directive (using_directives (cu
->language
),
9046 imported_declaration
,
9049 &objfile
->objfile_obstack
);
9051 do_cleanups (cleanups
);
9054 /* Cleanup function for handle_DW_AT_stmt_list. */
9057 free_cu_line_header (void *arg
)
9059 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) arg
;
9061 free_line_header (cu
->line_header
);
9062 cu
->line_header
= NULL
;
9065 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
9066 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
9067 this, it was first present in GCC release 4.3.0. */
9070 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
9072 if (!cu
->checked_producer
)
9073 check_producer (cu
);
9075 return cu
->producer_is_gcc_lt_4_3
;
9079 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
9080 const char **name
, const char **comp_dir
)
9082 /* Find the filename. Do not use dwarf2_name here, since the filename
9083 is not a source language identifier. */
9084 *name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
9085 *comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
9087 if (*comp_dir
== NULL
9088 && producer_is_gcc_lt_4_3 (cu
) && *name
!= NULL
9089 && IS_ABSOLUTE_PATH (*name
))
9091 char *d
= ldirname (*name
);
9095 make_cleanup (xfree
, d
);
9097 if (*comp_dir
!= NULL
)
9099 /* Irix 6.2 native cc prepends <machine>.: to the compilation
9100 directory, get rid of it. */
9101 const char *cp
= strchr (*comp_dir
, ':');
9103 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
9108 *name
= "<unknown>";
9111 /* Handle DW_AT_stmt_list for a compilation unit.
9112 DIE is the DW_TAG_compile_unit die for CU.
9113 COMP_DIR is the compilation directory. LOWPC is passed to
9114 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
9117 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
9118 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
9120 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9121 struct attribute
*attr
;
9122 unsigned int line_offset
;
9123 struct line_header line_header_local
;
9124 hashval_t line_header_local_hash
;
9129 gdb_assert (! cu
->per_cu
->is_debug_types
);
9131 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9135 line_offset
= DW_UNSND (attr
);
9137 /* The line header hash table is only created if needed (it exists to
9138 prevent redundant reading of the line table for partial_units).
9139 If we're given a partial_unit, we'll need it. If we're given a
9140 compile_unit, then use the line header hash table if it's already
9141 created, but don't create one just yet. */
9143 if (dwarf2_per_objfile
->line_header_hash
== NULL
9144 && die
->tag
== DW_TAG_partial_unit
)
9146 dwarf2_per_objfile
->line_header_hash
9147 = htab_create_alloc_ex (127, line_header_hash_voidp
,
9148 line_header_eq_voidp
,
9149 free_line_header_voidp
,
9150 &objfile
->objfile_obstack
,
9151 hashtab_obstack_allocate
,
9152 dummy_obstack_deallocate
);
9155 line_header_local
.offset
.sect_off
= line_offset
;
9156 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
9157 line_header_local_hash
= line_header_hash (&line_header_local
);
9158 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
9160 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9162 line_header_local_hash
, NO_INSERT
);
9164 /* For DW_TAG_compile_unit we need info like symtab::linetable which
9165 is not present in *SLOT (since if there is something in *SLOT then
9166 it will be for a partial_unit). */
9167 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
9169 gdb_assert (*slot
!= NULL
);
9170 cu
->line_header
= (struct line_header
*) *slot
;
9175 /* dwarf_decode_line_header does not yet provide sufficient information.
9176 We always have to call also dwarf_decode_lines for it. */
9177 cu
->line_header
= dwarf_decode_line_header (line_offset
, cu
);
9178 if (cu
->line_header
== NULL
)
9181 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
9185 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9187 line_header_local_hash
, INSERT
);
9188 gdb_assert (slot
!= NULL
);
9190 if (slot
!= NULL
&& *slot
== NULL
)
9192 /* This newly decoded line number information unit will be owned
9193 by line_header_hash hash table. */
9194 *slot
= cu
->line_header
;
9198 /* We cannot free any current entry in (*slot) as that struct line_header
9199 may be already used by multiple CUs. Create only temporary decoded
9200 line_header for this CU - it may happen at most once for each line
9201 number information unit. And if we're not using line_header_hash
9202 then this is what we want as well. */
9203 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
9204 make_cleanup (free_cu_line_header
, cu
);
9206 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
9207 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
9211 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
9214 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9216 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9217 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9218 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
9219 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
9220 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
9221 struct attribute
*attr
;
9222 const char *name
= NULL
;
9223 const char *comp_dir
= NULL
;
9224 struct die_info
*child_die
;
9227 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9229 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
9231 /* If we didn't find a lowpc, set it to highpc to avoid complaints
9232 from finish_block. */
9233 if (lowpc
== ((CORE_ADDR
) -1))
9235 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
9237 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
9239 prepare_one_comp_unit (cu
, die
, cu
->language
);
9241 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
9242 standardised yet. As a workaround for the language detection we fall
9243 back to the DW_AT_producer string. */
9244 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
9245 cu
->language
= language_opencl
;
9247 /* Similar hack for Go. */
9248 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
9249 set_cu_language (DW_LANG_Go
, cu
);
9251 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
9253 /* Decode line number information if present. We do this before
9254 processing child DIEs, so that the line header table is available
9255 for DW_AT_decl_file. */
9256 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, lowpc
);
9258 /* Process all dies in compilation unit. */
9259 if (die
->child
!= NULL
)
9261 child_die
= die
->child
;
9262 while (child_die
&& child_die
->tag
)
9264 process_die (child_die
, cu
);
9265 child_die
= sibling_die (child_die
);
9269 /* Decode macro information, if present. Dwarf 2 macro information
9270 refers to information in the line number info statement program
9271 header, so we can only read it if we've read the header
9273 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
9274 if (attr
&& cu
->line_header
)
9276 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
9277 complaint (&symfile_complaints
,
9278 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
9280 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
9284 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
9285 if (attr
&& cu
->line_header
)
9287 unsigned int macro_offset
= DW_UNSND (attr
);
9289 dwarf_decode_macros (cu
, macro_offset
, 0);
9293 do_cleanups (back_to
);
9296 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
9297 Create the set of symtabs used by this TU, or if this TU is sharing
9298 symtabs with another TU and the symtabs have already been created
9299 then restore those symtabs in the line header.
9300 We don't need the pc/line-number mapping for type units. */
9303 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
9305 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
9306 struct type_unit_group
*tu_group
;
9308 struct line_header
*lh
;
9309 struct attribute
*attr
;
9310 unsigned int i
, line_offset
;
9311 struct signatured_type
*sig_type
;
9313 gdb_assert (per_cu
->is_debug_types
);
9314 sig_type
= (struct signatured_type
*) per_cu
;
9316 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9318 /* If we're using .gdb_index (includes -readnow) then
9319 per_cu->type_unit_group may not have been set up yet. */
9320 if (sig_type
->type_unit_group
== NULL
)
9321 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
9322 tu_group
= sig_type
->type_unit_group
;
9324 /* If we've already processed this stmt_list there's no real need to
9325 do it again, we could fake it and just recreate the part we need
9326 (file name,index -> symtab mapping). If data shows this optimization
9327 is useful we can do it then. */
9328 first_time
= tu_group
->compunit_symtab
== NULL
;
9330 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
9335 line_offset
= DW_UNSND (attr
);
9336 lh
= dwarf_decode_line_header (line_offset
, cu
);
9341 dwarf2_start_symtab (cu
, "", NULL
, 0);
9344 gdb_assert (tu_group
->symtabs
== NULL
);
9345 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9350 cu
->line_header
= lh
;
9351 make_cleanup (free_cu_line_header
, cu
);
9355 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
9357 /* Note: We don't assign tu_group->compunit_symtab yet because we're
9358 still initializing it, and our caller (a few levels up)
9359 process_full_type_unit still needs to know if this is the first
9362 tu_group
->num_symtabs
= lh
->num_file_names
;
9363 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
9365 for (i
= 0; i
< lh
->num_file_names
; ++i
)
9367 const char *dir
= NULL
;
9368 struct file_entry
*fe
= &lh
->file_names
[i
];
9370 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
9371 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9372 dwarf2_start_subfile (fe
->name
, dir
);
9374 if (current_subfile
->symtab
== NULL
)
9376 /* NOTE: start_subfile will recognize when it's been passed
9377 a file it has already seen. So we can't assume there's a
9378 simple mapping from lh->file_names to subfiles, plus
9379 lh->file_names may contain dups. */
9380 current_subfile
->symtab
9381 = allocate_symtab (cust
, current_subfile
->name
);
9384 fe
->symtab
= current_subfile
->symtab
;
9385 tu_group
->symtabs
[i
] = fe
->symtab
;
9390 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9392 for (i
= 0; i
< lh
->num_file_names
; ++i
)
9394 struct file_entry
*fe
= &lh
->file_names
[i
];
9396 fe
->symtab
= tu_group
->symtabs
[i
];
9400 /* The main symtab is allocated last. Type units don't have DW_AT_name
9401 so they don't have a "real" (so to speak) symtab anyway.
9402 There is later code that will assign the main symtab to all symbols
9403 that don't have one. We need to handle the case of a symbol with a
9404 missing symtab (DW_AT_decl_file) anyway. */
9407 /* Process DW_TAG_type_unit.
9408 For TUs we want to skip the first top level sibling if it's not the
9409 actual type being defined by this TU. In this case the first top
9410 level sibling is there to provide context only. */
9413 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9415 struct die_info
*child_die
;
9417 prepare_one_comp_unit (cu
, die
, language_minimal
);
9419 /* Initialize (or reinitialize) the machinery for building symtabs.
9420 We do this before processing child DIEs, so that the line header table
9421 is available for DW_AT_decl_file. */
9422 setup_type_unit_groups (die
, cu
);
9424 if (die
->child
!= NULL
)
9426 child_die
= die
->child
;
9427 while (child_die
&& child_die
->tag
)
9429 process_die (child_die
, cu
);
9430 child_die
= sibling_die (child_die
);
9437 http://gcc.gnu.org/wiki/DebugFission
9438 http://gcc.gnu.org/wiki/DebugFissionDWP
9440 To simplify handling of both DWO files ("object" files with the DWARF info)
9441 and DWP files (a file with the DWOs packaged up into one file), we treat
9442 DWP files as having a collection of virtual DWO files. */
9445 hash_dwo_file (const void *item
)
9447 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
9450 hash
= htab_hash_string (dwo_file
->dwo_name
);
9451 if (dwo_file
->comp_dir
!= NULL
)
9452 hash
+= htab_hash_string (dwo_file
->comp_dir
);
9457 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
9459 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
9460 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
9462 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
9464 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
9465 return lhs
->comp_dir
== rhs
->comp_dir
;
9466 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
9469 /* Allocate a hash table for DWO files. */
9472 allocate_dwo_file_hash_table (void)
9474 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9476 return htab_create_alloc_ex (41,
9480 &objfile
->objfile_obstack
,
9481 hashtab_obstack_allocate
,
9482 dummy_obstack_deallocate
);
9485 /* Lookup DWO file DWO_NAME. */
9488 lookup_dwo_file_slot (const char *dwo_name
, const char *comp_dir
)
9490 struct dwo_file find_entry
;
9493 if (dwarf2_per_objfile
->dwo_files
== NULL
)
9494 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
9496 memset (&find_entry
, 0, sizeof (find_entry
));
9497 find_entry
.dwo_name
= dwo_name
;
9498 find_entry
.comp_dir
= comp_dir
;
9499 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
9505 hash_dwo_unit (const void *item
)
9507 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
9509 /* This drops the top 32 bits of the id, but is ok for a hash. */
9510 return dwo_unit
->signature
;
9514 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
9516 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
9517 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
9519 /* The signature is assumed to be unique within the DWO file.
9520 So while object file CU dwo_id's always have the value zero,
9521 that's OK, assuming each object file DWO file has only one CU,
9522 and that's the rule for now. */
9523 return lhs
->signature
== rhs
->signature
;
9526 /* Allocate a hash table for DWO CUs,TUs.
9527 There is one of these tables for each of CUs,TUs for each DWO file. */
9530 allocate_dwo_unit_table (struct objfile
*objfile
)
9532 /* Start out with a pretty small number.
9533 Generally DWO files contain only one CU and maybe some TUs. */
9534 return htab_create_alloc_ex (3,
9538 &objfile
->objfile_obstack
,
9539 hashtab_obstack_allocate
,
9540 dummy_obstack_deallocate
);
9543 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
9545 struct create_dwo_cu_data
9547 struct dwo_file
*dwo_file
;
9548 struct dwo_unit dwo_unit
;
9551 /* die_reader_func for create_dwo_cu. */
9554 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
9555 const gdb_byte
*info_ptr
,
9556 struct die_info
*comp_unit_die
,
9560 struct dwarf2_cu
*cu
= reader
->cu
;
9561 sect_offset offset
= cu
->per_cu
->offset
;
9562 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
9563 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
9564 struct dwo_file
*dwo_file
= data
->dwo_file
;
9565 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
9566 struct attribute
*attr
;
9568 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
9571 complaint (&symfile_complaints
,
9572 _("Dwarf Error: debug entry at offset 0x%x is missing"
9573 " its dwo_id [in module %s]"),
9574 offset
.sect_off
, dwo_file
->dwo_name
);
9578 dwo_unit
->dwo_file
= dwo_file
;
9579 dwo_unit
->signature
= DW_UNSND (attr
);
9580 dwo_unit
->section
= section
;
9581 dwo_unit
->offset
= offset
;
9582 dwo_unit
->length
= cu
->per_cu
->length
;
9584 if (dwarf_read_debug
)
9585 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id %s\n",
9586 offset
.sect_off
, hex_string (dwo_unit
->signature
));
9589 /* Create the dwo_unit for the lone CU in DWO_FILE.
9590 Note: This function processes DWO files only, not DWP files. */
9592 static struct dwo_unit
*
9593 create_dwo_cu (struct dwo_file
*dwo_file
)
9595 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9596 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
9597 const gdb_byte
*info_ptr
, *end_ptr
;
9598 struct create_dwo_cu_data create_dwo_cu_data
;
9599 struct dwo_unit
*dwo_unit
;
9601 dwarf2_read_section (objfile
, section
);
9602 info_ptr
= section
->buffer
;
9604 if (info_ptr
== NULL
)
9607 if (dwarf_read_debug
)
9609 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
9610 get_section_name (section
),
9611 get_section_file_name (section
));
9614 create_dwo_cu_data
.dwo_file
= dwo_file
;
9617 end_ptr
= info_ptr
+ section
->size
;
9618 while (info_ptr
< end_ptr
)
9620 struct dwarf2_per_cu_data per_cu
;
9622 memset (&create_dwo_cu_data
.dwo_unit
, 0,
9623 sizeof (create_dwo_cu_data
.dwo_unit
));
9624 memset (&per_cu
, 0, sizeof (per_cu
));
9625 per_cu
.objfile
= objfile
;
9626 per_cu
.is_debug_types
= 0;
9627 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
9628 per_cu
.section
= section
;
9630 init_cutu_and_read_dies_no_follow (&per_cu
, dwo_file
,
9631 create_dwo_cu_reader
,
9632 &create_dwo_cu_data
);
9634 if (create_dwo_cu_data
.dwo_unit
.dwo_file
!= NULL
)
9636 /* If we've already found one, complain. We only support one
9637 because having more than one requires hacking the dwo_name of
9638 each to match, which is highly unlikely to happen. */
9639 if (dwo_unit
!= NULL
)
9641 complaint (&symfile_complaints
,
9642 _("Multiple CUs in DWO file %s [in module %s]"),
9643 dwo_file
->dwo_name
, objfile_name (objfile
));
9647 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
9648 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
9651 info_ptr
+= per_cu
.length
;
9657 /* DWP file .debug_{cu,tu}_index section format:
9658 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
9662 Both index sections have the same format, and serve to map a 64-bit
9663 signature to a set of section numbers. Each section begins with a header,
9664 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
9665 indexes, and a pool of 32-bit section numbers. The index sections will be
9666 aligned at 8-byte boundaries in the file.
9668 The index section header consists of:
9670 V, 32 bit version number
9672 N, 32 bit number of compilation units or type units in the index
9673 M, 32 bit number of slots in the hash table
9675 Numbers are recorded using the byte order of the application binary.
9677 The hash table begins at offset 16 in the section, and consists of an array
9678 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
9679 order of the application binary). Unused slots in the hash table are 0.
9680 (We rely on the extreme unlikeliness of a signature being exactly 0.)
9682 The parallel table begins immediately after the hash table
9683 (at offset 16 + 8 * M from the beginning of the section), and consists of an
9684 array of 32-bit indexes (using the byte order of the application binary),
9685 corresponding 1-1 with slots in the hash table. Each entry in the parallel
9686 table contains a 32-bit index into the pool of section numbers. For unused
9687 hash table slots, the corresponding entry in the parallel table will be 0.
9689 The pool of section numbers begins immediately following the hash table
9690 (at offset 16 + 12 * M from the beginning of the section). The pool of
9691 section numbers consists of an array of 32-bit words (using the byte order
9692 of the application binary). Each item in the array is indexed starting
9693 from 0. The hash table entry provides the index of the first section
9694 number in the set. Additional section numbers in the set follow, and the
9695 set is terminated by a 0 entry (section number 0 is not used in ELF).
9697 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
9698 section must be the first entry in the set, and the .debug_abbrev.dwo must
9699 be the second entry. Other members of the set may follow in any order.
9705 DWP Version 2 combines all the .debug_info, etc. sections into one,
9706 and the entries in the index tables are now offsets into these sections.
9707 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
9710 Index Section Contents:
9712 Hash Table of Signatures dwp_hash_table.hash_table
9713 Parallel Table of Indices dwp_hash_table.unit_table
9714 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
9715 Table of Section Sizes dwp_hash_table.v2.sizes
9717 The index section header consists of:
9719 V, 32 bit version number
9720 L, 32 bit number of columns in the table of section offsets
9721 N, 32 bit number of compilation units or type units in the index
9722 M, 32 bit number of slots in the hash table
9724 Numbers are recorded using the byte order of the application binary.
9726 The hash table has the same format as version 1.
9727 The parallel table of indices has the same format as version 1,
9728 except that the entries are origin-1 indices into the table of sections
9729 offsets and the table of section sizes.
9731 The table of offsets begins immediately following the parallel table
9732 (at offset 16 + 12 * M from the beginning of the section). The table is
9733 a two-dimensional array of 32-bit words (using the byte order of the
9734 application binary), with L columns and N+1 rows, in row-major order.
9735 Each row in the array is indexed starting from 0. The first row provides
9736 a key to the remaining rows: each column in this row provides an identifier
9737 for a debug section, and the offsets in the same column of subsequent rows
9738 refer to that section. The section identifiers are:
9740 DW_SECT_INFO 1 .debug_info.dwo
9741 DW_SECT_TYPES 2 .debug_types.dwo
9742 DW_SECT_ABBREV 3 .debug_abbrev.dwo
9743 DW_SECT_LINE 4 .debug_line.dwo
9744 DW_SECT_LOC 5 .debug_loc.dwo
9745 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
9746 DW_SECT_MACINFO 7 .debug_macinfo.dwo
9747 DW_SECT_MACRO 8 .debug_macro.dwo
9749 The offsets provided by the CU and TU index sections are the base offsets
9750 for the contributions made by each CU or TU to the corresponding section
9751 in the package file. Each CU and TU header contains an abbrev_offset
9752 field, used to find the abbreviations table for that CU or TU within the
9753 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
9754 be interpreted as relative to the base offset given in the index section.
9755 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
9756 should be interpreted as relative to the base offset for .debug_line.dwo,
9757 and offsets into other debug sections obtained from DWARF attributes should
9758 also be interpreted as relative to the corresponding base offset.
9760 The table of sizes begins immediately following the table of offsets.
9761 Like the table of offsets, it is a two-dimensional array of 32-bit words,
9762 with L columns and N rows, in row-major order. Each row in the array is
9763 indexed starting from 1 (row 0 is shared by the two tables).
9767 Hash table lookup is handled the same in version 1 and 2:
9769 We assume that N and M will not exceed 2^32 - 1.
9770 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
9772 Given a 64-bit compilation unit signature or a type signature S, an entry
9773 in the hash table is located as follows:
9775 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
9776 the low-order k bits all set to 1.
9778 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
9780 3) If the hash table entry at index H matches the signature, use that
9781 entry. If the hash table entry at index H is unused (all zeroes),
9782 terminate the search: the signature is not present in the table.
9784 4) Let H = (H + H') modulo M. Repeat at Step 3.
9786 Because M > N and H' and M are relatively prime, the search is guaranteed
9787 to stop at an unused slot or find the match. */
9789 /* Create a hash table to map DWO IDs to their CU/TU entry in
9790 .debug_{info,types}.dwo in DWP_FILE.
9791 Returns NULL if there isn't one.
9792 Note: This function processes DWP files only, not DWO files. */
9794 static struct dwp_hash_table
*
9795 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
9797 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9798 bfd
*dbfd
= dwp_file
->dbfd
;
9799 const gdb_byte
*index_ptr
, *index_end
;
9800 struct dwarf2_section_info
*index
;
9801 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
9802 struct dwp_hash_table
*htab
;
9805 index
= &dwp_file
->sections
.tu_index
;
9807 index
= &dwp_file
->sections
.cu_index
;
9809 if (dwarf2_section_empty_p (index
))
9811 dwarf2_read_section (objfile
, index
);
9813 index_ptr
= index
->buffer
;
9814 index_end
= index_ptr
+ index
->size
;
9816 version
= read_4_bytes (dbfd
, index_ptr
);
9819 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
9823 nr_units
= read_4_bytes (dbfd
, index_ptr
);
9825 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
9828 if (version
!= 1 && version
!= 2)
9830 error (_("Dwarf Error: unsupported DWP file version (%s)"
9832 pulongest (version
), dwp_file
->name
);
9834 if (nr_slots
!= (nr_slots
& -nr_slots
))
9836 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
9837 " is not power of 2 [in module %s]"),
9838 pulongest (nr_slots
), dwp_file
->name
);
9841 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
9842 htab
->version
= version
;
9843 htab
->nr_columns
= nr_columns
;
9844 htab
->nr_units
= nr_units
;
9845 htab
->nr_slots
= nr_slots
;
9846 htab
->hash_table
= index_ptr
;
9847 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
9849 /* Exit early if the table is empty. */
9850 if (nr_slots
== 0 || nr_units
== 0
9851 || (version
== 2 && nr_columns
== 0))
9853 /* All must be zero. */
9854 if (nr_slots
!= 0 || nr_units
!= 0
9855 || (version
== 2 && nr_columns
!= 0))
9857 complaint (&symfile_complaints
,
9858 _("Empty DWP but nr_slots,nr_units,nr_columns not"
9859 " all zero [in modules %s]"),
9867 htab
->section_pool
.v1
.indices
=
9868 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9869 /* It's harder to decide whether the section is too small in v1.
9870 V1 is deprecated anyway so we punt. */
9874 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9875 int *ids
= htab
->section_pool
.v2
.section_ids
;
9876 /* Reverse map for error checking. */
9877 int ids_seen
[DW_SECT_MAX
+ 1];
9882 error (_("Dwarf Error: bad DWP hash table, too few columns"
9883 " in section table [in module %s]"),
9886 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
9888 error (_("Dwarf Error: bad DWP hash table, too many columns"
9889 " in section table [in module %s]"),
9892 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
9893 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
9894 for (i
= 0; i
< nr_columns
; ++i
)
9896 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
9898 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
9900 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
9901 " in section table [in module %s]"),
9902 id
, dwp_file
->name
);
9904 if (ids_seen
[id
] != -1)
9906 error (_("Dwarf Error: bad DWP hash table, duplicate section"
9907 " id %d in section table [in module %s]"),
9908 id
, dwp_file
->name
);
9913 /* Must have exactly one info or types section. */
9914 if (((ids_seen
[DW_SECT_INFO
] != -1)
9915 + (ids_seen
[DW_SECT_TYPES
] != -1))
9918 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
9919 " DWO info/types section [in module %s]"),
9922 /* Must have an abbrev section. */
9923 if (ids_seen
[DW_SECT_ABBREV
] == -1)
9925 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
9926 " section [in module %s]"),
9929 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
9930 htab
->section_pool
.v2
.sizes
=
9931 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
9932 * nr_units
* nr_columns
);
9933 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
9934 * nr_units
* nr_columns
))
9937 error (_("Dwarf Error: DWP index section is corrupt (too small)"
9946 /* Update SECTIONS with the data from SECTP.
9948 This function is like the other "locate" section routines that are
9949 passed to bfd_map_over_sections, but in this context the sections to
9950 read comes from the DWP V1 hash table, not the full ELF section table.
9952 The result is non-zero for success, or zero if an error was found. */
9955 locate_v1_virtual_dwo_sections (asection
*sectp
,
9956 struct virtual_v1_dwo_sections
*sections
)
9958 const struct dwop_section_names
*names
= &dwop_section_names
;
9960 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
9962 /* There can be only one. */
9963 if (sections
->abbrev
.s
.section
!= NULL
)
9965 sections
->abbrev
.s
.section
= sectp
;
9966 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
9968 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
9969 || section_is_p (sectp
->name
, &names
->types_dwo
))
9971 /* There can be only one. */
9972 if (sections
->info_or_types
.s
.section
!= NULL
)
9974 sections
->info_or_types
.s
.section
= sectp
;
9975 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
9977 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
9979 /* There can be only one. */
9980 if (sections
->line
.s
.section
!= NULL
)
9982 sections
->line
.s
.section
= sectp
;
9983 sections
->line
.size
= bfd_get_section_size (sectp
);
9985 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
9987 /* There can be only one. */
9988 if (sections
->loc
.s
.section
!= NULL
)
9990 sections
->loc
.s
.section
= sectp
;
9991 sections
->loc
.size
= bfd_get_section_size (sectp
);
9993 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
9995 /* There can be only one. */
9996 if (sections
->macinfo
.s
.section
!= NULL
)
9998 sections
->macinfo
.s
.section
= sectp
;
9999 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10001 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10003 /* There can be only one. */
10004 if (sections
->macro
.s
.section
!= NULL
)
10006 sections
->macro
.s
.section
= sectp
;
10007 sections
->macro
.size
= bfd_get_section_size (sectp
);
10009 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10011 /* There can be only one. */
10012 if (sections
->str_offsets
.s
.section
!= NULL
)
10014 sections
->str_offsets
.s
.section
= sectp
;
10015 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10019 /* No other kind of section is valid. */
10026 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10027 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10028 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10029 This is for DWP version 1 files. */
10031 static struct dwo_unit
*
10032 create_dwo_unit_in_dwp_v1 (struct dwp_file
*dwp_file
,
10033 uint32_t unit_index
,
10034 const char *comp_dir
,
10035 ULONGEST signature
, int is_debug_types
)
10037 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10038 const struct dwp_hash_table
*dwp_htab
=
10039 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10040 bfd
*dbfd
= dwp_file
->dbfd
;
10041 const char *kind
= is_debug_types
? "TU" : "CU";
10042 struct dwo_file
*dwo_file
;
10043 struct dwo_unit
*dwo_unit
;
10044 struct virtual_v1_dwo_sections sections
;
10045 void **dwo_file_slot
;
10046 char *virtual_dwo_name
;
10047 struct cleanup
*cleanups
;
10050 gdb_assert (dwp_file
->version
== 1);
10052 if (dwarf_read_debug
)
10054 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
10056 pulongest (unit_index
), hex_string (signature
),
10060 /* Fetch the sections of this DWO unit.
10061 Put a limit on the number of sections we look for so that bad data
10062 doesn't cause us to loop forever. */
10064 #define MAX_NR_V1_DWO_SECTIONS \
10065 (1 /* .debug_info or .debug_types */ \
10066 + 1 /* .debug_abbrev */ \
10067 + 1 /* .debug_line */ \
10068 + 1 /* .debug_loc */ \
10069 + 1 /* .debug_str_offsets */ \
10070 + 1 /* .debug_macro or .debug_macinfo */ \
10071 + 1 /* trailing zero */)
10073 memset (§ions
, 0, sizeof (sections
));
10074 cleanups
= make_cleanup (null_cleanup
, 0);
10076 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
10079 uint32_t section_nr
=
10080 read_4_bytes (dbfd
,
10081 dwp_htab
->section_pool
.v1
.indices
10082 + (unit_index
+ i
) * sizeof (uint32_t));
10084 if (section_nr
== 0)
10086 if (section_nr
>= dwp_file
->num_sections
)
10088 error (_("Dwarf Error: bad DWP hash table, section number too large"
10089 " [in module %s]"),
10093 sectp
= dwp_file
->elf_sections
[section_nr
];
10094 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
10096 error (_("Dwarf Error: bad DWP hash table, invalid section found"
10097 " [in module %s]"),
10103 || dwarf2_section_empty_p (§ions
.info_or_types
)
10104 || dwarf2_section_empty_p (§ions
.abbrev
))
10106 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
10107 " [in module %s]"),
10110 if (i
== MAX_NR_V1_DWO_SECTIONS
)
10112 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
10113 " [in module %s]"),
10117 /* It's easier for the rest of the code if we fake a struct dwo_file and
10118 have dwo_unit "live" in that. At least for now.
10120 The DWP file can be made up of a random collection of CUs and TUs.
10121 However, for each CU + set of TUs that came from the same original DWO
10122 file, we can combine them back into a virtual DWO file to save space
10123 (fewer struct dwo_file objects to allocate). Remember that for really
10124 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10127 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
10128 get_section_id (§ions
.abbrev
),
10129 get_section_id (§ions
.line
),
10130 get_section_id (§ions
.loc
),
10131 get_section_id (§ions
.str_offsets
));
10132 make_cleanup (xfree
, virtual_dwo_name
);
10133 /* Can we use an existing virtual DWO file? */
10134 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
10135 /* Create one if necessary. */
10136 if (*dwo_file_slot
== NULL
)
10138 if (dwarf_read_debug
)
10140 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10143 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10145 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
10147 strlen (virtual_dwo_name
));
10148 dwo_file
->comp_dir
= comp_dir
;
10149 dwo_file
->sections
.abbrev
= sections
.abbrev
;
10150 dwo_file
->sections
.line
= sections
.line
;
10151 dwo_file
->sections
.loc
= sections
.loc
;
10152 dwo_file
->sections
.macinfo
= sections
.macinfo
;
10153 dwo_file
->sections
.macro
= sections
.macro
;
10154 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
10155 /* The "str" section is global to the entire DWP file. */
10156 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10157 /* The info or types section is assigned below to dwo_unit,
10158 there's no need to record it in dwo_file.
10159 Also, we can't simply record type sections in dwo_file because
10160 we record a pointer into the vector in dwo_unit. As we collect more
10161 types we'll grow the vector and eventually have to reallocate space
10162 for it, invalidating all copies of pointers into the previous
10164 *dwo_file_slot
= dwo_file
;
10168 if (dwarf_read_debug
)
10170 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10173 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10175 do_cleanups (cleanups
);
10177 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10178 dwo_unit
->dwo_file
= dwo_file
;
10179 dwo_unit
->signature
= signature
;
10180 dwo_unit
->section
=
10181 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
10182 *dwo_unit
->section
= sections
.info_or_types
;
10183 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10188 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
10189 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
10190 piece within that section used by a TU/CU, return a virtual section
10191 of just that piece. */
10193 static struct dwarf2_section_info
10194 create_dwp_v2_section (struct dwarf2_section_info
*section
,
10195 bfd_size_type offset
, bfd_size_type size
)
10197 struct dwarf2_section_info result
;
10200 gdb_assert (section
!= NULL
);
10201 gdb_assert (!section
->is_virtual
);
10203 memset (&result
, 0, sizeof (result
));
10204 result
.s
.containing_section
= section
;
10205 result
.is_virtual
= 1;
10210 sectp
= get_section_bfd_section (section
);
10212 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
10213 bounds of the real section. This is a pretty-rare event, so just
10214 flag an error (easier) instead of a warning and trying to cope. */
10216 || offset
+ size
> bfd_get_section_size (sectp
))
10218 bfd
*abfd
= sectp
->owner
;
10220 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
10221 " in section %s [in module %s]"),
10222 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
10223 objfile_name (dwarf2_per_objfile
->objfile
));
10226 result
.virtual_offset
= offset
;
10227 result
.size
= size
;
10231 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10232 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10233 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10234 This is for DWP version 2 files. */
10236 static struct dwo_unit
*
10237 create_dwo_unit_in_dwp_v2 (struct dwp_file
*dwp_file
,
10238 uint32_t unit_index
,
10239 const char *comp_dir
,
10240 ULONGEST signature
, int is_debug_types
)
10242 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10243 const struct dwp_hash_table
*dwp_htab
=
10244 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10245 bfd
*dbfd
= dwp_file
->dbfd
;
10246 const char *kind
= is_debug_types
? "TU" : "CU";
10247 struct dwo_file
*dwo_file
;
10248 struct dwo_unit
*dwo_unit
;
10249 struct virtual_v2_dwo_sections sections
;
10250 void **dwo_file_slot
;
10251 char *virtual_dwo_name
;
10252 struct cleanup
*cleanups
;
10255 gdb_assert (dwp_file
->version
== 2);
10257 if (dwarf_read_debug
)
10259 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
10261 pulongest (unit_index
), hex_string (signature
),
10265 /* Fetch the section offsets of this DWO unit. */
10267 memset (§ions
, 0, sizeof (sections
));
10268 cleanups
= make_cleanup (null_cleanup
, 0);
10270 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
10272 uint32_t offset
= read_4_bytes (dbfd
,
10273 dwp_htab
->section_pool
.v2
.offsets
10274 + (((unit_index
- 1) * dwp_htab
->nr_columns
10276 * sizeof (uint32_t)));
10277 uint32_t size
= read_4_bytes (dbfd
,
10278 dwp_htab
->section_pool
.v2
.sizes
10279 + (((unit_index
- 1) * dwp_htab
->nr_columns
10281 * sizeof (uint32_t)));
10283 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
10286 case DW_SECT_TYPES
:
10287 sections
.info_or_types_offset
= offset
;
10288 sections
.info_or_types_size
= size
;
10290 case DW_SECT_ABBREV
:
10291 sections
.abbrev_offset
= offset
;
10292 sections
.abbrev_size
= size
;
10295 sections
.line_offset
= offset
;
10296 sections
.line_size
= size
;
10299 sections
.loc_offset
= offset
;
10300 sections
.loc_size
= size
;
10302 case DW_SECT_STR_OFFSETS
:
10303 sections
.str_offsets_offset
= offset
;
10304 sections
.str_offsets_size
= size
;
10306 case DW_SECT_MACINFO
:
10307 sections
.macinfo_offset
= offset
;
10308 sections
.macinfo_size
= size
;
10310 case DW_SECT_MACRO
:
10311 sections
.macro_offset
= offset
;
10312 sections
.macro_size
= size
;
10317 /* It's easier for the rest of the code if we fake a struct dwo_file and
10318 have dwo_unit "live" in that. At least for now.
10320 The DWP file can be made up of a random collection of CUs and TUs.
10321 However, for each CU + set of TUs that came from the same original DWO
10322 file, we can combine them back into a virtual DWO file to save space
10323 (fewer struct dwo_file objects to allocate). Remember that for really
10324 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10327 xstrprintf ("virtual-dwo/%ld-%ld-%ld-%ld",
10328 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
10329 (long) (sections
.line_size
? sections
.line_offset
: 0),
10330 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
10331 (long) (sections
.str_offsets_size
10332 ? sections
.str_offsets_offset
: 0));
10333 make_cleanup (xfree
, virtual_dwo_name
);
10334 /* Can we use an existing virtual DWO file? */
10335 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
10336 /* Create one if necessary. */
10337 if (*dwo_file_slot
== NULL
)
10339 if (dwarf_read_debug
)
10341 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10344 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10346 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
10348 strlen (virtual_dwo_name
));
10349 dwo_file
->comp_dir
= comp_dir
;
10350 dwo_file
->sections
.abbrev
=
10351 create_dwp_v2_section (&dwp_file
->sections
.abbrev
,
10352 sections
.abbrev_offset
, sections
.abbrev_size
);
10353 dwo_file
->sections
.line
=
10354 create_dwp_v2_section (&dwp_file
->sections
.line
,
10355 sections
.line_offset
, sections
.line_size
);
10356 dwo_file
->sections
.loc
=
10357 create_dwp_v2_section (&dwp_file
->sections
.loc
,
10358 sections
.loc_offset
, sections
.loc_size
);
10359 dwo_file
->sections
.macinfo
=
10360 create_dwp_v2_section (&dwp_file
->sections
.macinfo
,
10361 sections
.macinfo_offset
, sections
.macinfo_size
);
10362 dwo_file
->sections
.macro
=
10363 create_dwp_v2_section (&dwp_file
->sections
.macro
,
10364 sections
.macro_offset
, sections
.macro_size
);
10365 dwo_file
->sections
.str_offsets
=
10366 create_dwp_v2_section (&dwp_file
->sections
.str_offsets
,
10367 sections
.str_offsets_offset
,
10368 sections
.str_offsets_size
);
10369 /* The "str" section is global to the entire DWP file. */
10370 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10371 /* The info or types section is assigned below to dwo_unit,
10372 there's no need to record it in dwo_file.
10373 Also, we can't simply record type sections in dwo_file because
10374 we record a pointer into the vector in dwo_unit. As we collect more
10375 types we'll grow the vector and eventually have to reallocate space
10376 for it, invalidating all copies of pointers into the previous
10378 *dwo_file_slot
= dwo_file
;
10382 if (dwarf_read_debug
)
10384 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10387 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10389 do_cleanups (cleanups
);
10391 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10392 dwo_unit
->dwo_file
= dwo_file
;
10393 dwo_unit
->signature
= signature
;
10394 dwo_unit
->section
=
10395 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
10396 *dwo_unit
->section
= create_dwp_v2_section (is_debug_types
10397 ? &dwp_file
->sections
.types
10398 : &dwp_file
->sections
.info
,
10399 sections
.info_or_types_offset
,
10400 sections
.info_or_types_size
);
10401 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10406 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
10407 Returns NULL if the signature isn't found. */
10409 static struct dwo_unit
*
10410 lookup_dwo_unit_in_dwp (struct dwp_file
*dwp_file
, const char *comp_dir
,
10411 ULONGEST signature
, int is_debug_types
)
10413 const struct dwp_hash_table
*dwp_htab
=
10414 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10415 bfd
*dbfd
= dwp_file
->dbfd
;
10416 uint32_t mask
= dwp_htab
->nr_slots
- 1;
10417 uint32_t hash
= signature
& mask
;
10418 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
10421 struct dwo_unit find_dwo_cu
;
10423 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
10424 find_dwo_cu
.signature
= signature
;
10425 slot
= htab_find_slot (is_debug_types
10426 ? dwp_file
->loaded_tus
10427 : dwp_file
->loaded_cus
,
10428 &find_dwo_cu
, INSERT
);
10431 return (struct dwo_unit
*) *slot
;
10433 /* Use a for loop so that we don't loop forever on bad debug info. */
10434 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
10436 ULONGEST signature_in_table
;
10438 signature_in_table
=
10439 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
10440 if (signature_in_table
== signature
)
10442 uint32_t unit_index
=
10443 read_4_bytes (dbfd
,
10444 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
10446 if (dwp_file
->version
== 1)
10448 *slot
= create_dwo_unit_in_dwp_v1 (dwp_file
, unit_index
,
10449 comp_dir
, signature
,
10454 *slot
= create_dwo_unit_in_dwp_v2 (dwp_file
, unit_index
,
10455 comp_dir
, signature
,
10458 return (struct dwo_unit
*) *slot
;
10460 if (signature_in_table
== 0)
10462 hash
= (hash
+ hash2
) & mask
;
10465 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
10466 " [in module %s]"),
10470 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
10471 Open the file specified by FILE_NAME and hand it off to BFD for
10472 preliminary analysis. Return a newly initialized bfd *, which
10473 includes a canonicalized copy of FILE_NAME.
10474 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
10475 SEARCH_CWD is true if the current directory is to be searched.
10476 It will be searched before debug-file-directory.
10477 If successful, the file is added to the bfd include table of the
10478 objfile's bfd (see gdb_bfd_record_inclusion).
10479 If unable to find/open the file, return NULL.
10480 NOTE: This function is derived from symfile_bfd_open. */
10483 try_open_dwop_file (const char *file_name
, int is_dwp
, int search_cwd
)
10487 char *absolute_name
;
10488 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
10489 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
10490 to debug_file_directory. */
10492 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
10496 if (*debug_file_directory
!= '\0')
10497 search_path
= concat (".", dirname_separator_string
,
10498 debug_file_directory
, (char *) NULL
);
10500 search_path
= xstrdup (".");
10503 search_path
= xstrdup (debug_file_directory
);
10505 flags
= OPF_RETURN_REALPATH
;
10507 flags
|= OPF_SEARCH_IN_PATH
;
10508 desc
= openp (search_path
, flags
, file_name
,
10509 O_RDONLY
| O_BINARY
, &absolute_name
);
10510 xfree (search_path
);
10514 sym_bfd
= gdb_bfd_open (absolute_name
, gnutarget
, desc
);
10515 xfree (absolute_name
);
10516 if (sym_bfd
== NULL
)
10518 bfd_set_cacheable (sym_bfd
, 1);
10520 if (!bfd_check_format (sym_bfd
, bfd_object
))
10522 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
10526 /* Success. Record the bfd as having been included by the objfile's bfd.
10527 This is important because things like demangled_names_hash lives in the
10528 objfile's per_bfd space and may have references to things like symbol
10529 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
10530 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
);
10535 /* Try to open DWO file FILE_NAME.
10536 COMP_DIR is the DW_AT_comp_dir attribute.
10537 The result is the bfd handle of the file.
10538 If there is a problem finding or opening the file, return NULL.
10539 Upon success, the canonicalized path of the file is stored in the bfd,
10540 same as symfile_bfd_open. */
10543 open_dwo_file (const char *file_name
, const char *comp_dir
)
10547 if (IS_ABSOLUTE_PATH (file_name
))
10548 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 0 /*search_cwd*/);
10550 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
10552 if (comp_dir
!= NULL
)
10554 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
10555 file_name
, (char *) NULL
);
10557 /* NOTE: If comp_dir is a relative path, this will also try the
10558 search path, which seems useful. */
10559 abfd
= try_open_dwop_file (path_to_try
, 0 /*is_dwp*/, 1 /*search_cwd*/);
10560 xfree (path_to_try
);
10565 /* That didn't work, try debug-file-directory, which, despite its name,
10566 is a list of paths. */
10568 if (*debug_file_directory
== '\0')
10571 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 1 /*search_cwd*/);
10574 /* This function is mapped across the sections and remembers the offset and
10575 size of each of the DWO debugging sections we are interested in. */
10578 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
10580 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
10581 const struct dwop_section_names
*names
= &dwop_section_names
;
10583 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10585 dwo_sections
->abbrev
.s
.section
= sectp
;
10586 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10588 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10590 dwo_sections
->info
.s
.section
= sectp
;
10591 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
10593 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10595 dwo_sections
->line
.s
.section
= sectp
;
10596 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
10598 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10600 dwo_sections
->loc
.s
.section
= sectp
;
10601 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
10603 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10605 dwo_sections
->macinfo
.s
.section
= sectp
;
10606 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10608 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10610 dwo_sections
->macro
.s
.section
= sectp
;
10611 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
10613 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
10615 dwo_sections
->str
.s
.section
= sectp
;
10616 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
10618 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10620 dwo_sections
->str_offsets
.s
.section
= sectp
;
10621 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10623 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10625 struct dwarf2_section_info type_section
;
10627 memset (&type_section
, 0, sizeof (type_section
));
10628 type_section
.s
.section
= sectp
;
10629 type_section
.size
= bfd_get_section_size (sectp
);
10630 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
10635 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
10636 by PER_CU. This is for the non-DWP case.
10637 The result is NULL if DWO_NAME can't be found. */
10639 static struct dwo_file
*
10640 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
10641 const char *dwo_name
, const char *comp_dir
)
10643 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10644 struct dwo_file
*dwo_file
;
10646 struct cleanup
*cleanups
;
10648 dbfd
= open_dwo_file (dwo_name
, comp_dir
);
10651 if (dwarf_read_debug
)
10652 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
10655 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10656 dwo_file
->dwo_name
= dwo_name
;
10657 dwo_file
->comp_dir
= comp_dir
;
10658 dwo_file
->dbfd
= dbfd
;
10660 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
10662 bfd_map_over_sections (dbfd
, dwarf2_locate_dwo_sections
, &dwo_file
->sections
);
10664 dwo_file
->cu
= create_dwo_cu (dwo_file
);
10666 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
10667 dwo_file
->sections
.types
);
10669 discard_cleanups (cleanups
);
10671 if (dwarf_read_debug
)
10672 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
10677 /* This function is mapped across the sections and remembers the offset and
10678 size of each of the DWP debugging sections common to version 1 and 2 that
10679 we are interested in. */
10682 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
10683 void *dwp_file_ptr
)
10685 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
10686 const struct dwop_section_names
*names
= &dwop_section_names
;
10687 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10689 /* Record the ELF section number for later lookup: this is what the
10690 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10691 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10692 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10694 /* Look for specific sections that we need. */
10695 if (section_is_p (sectp
->name
, &names
->str_dwo
))
10697 dwp_file
->sections
.str
.s
.section
= sectp
;
10698 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
10700 else if (section_is_p (sectp
->name
, &names
->cu_index
))
10702 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
10703 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
10705 else if (section_is_p (sectp
->name
, &names
->tu_index
))
10707 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
10708 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
10712 /* This function is mapped across the sections and remembers the offset and
10713 size of each of the DWP version 2 debugging sections that we are interested
10714 in. This is split into a separate function because we don't know if we
10715 have version 1 or 2 until we parse the cu_index/tu_index sections. */
10718 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
10720 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
10721 const struct dwop_section_names
*names
= &dwop_section_names
;
10722 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10724 /* Record the ELF section number for later lookup: this is what the
10725 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10726 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10727 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10729 /* Look for specific sections that we need. */
10730 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10732 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
10733 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
10735 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10737 dwp_file
->sections
.info
.s
.section
= sectp
;
10738 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
10740 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10742 dwp_file
->sections
.line
.s
.section
= sectp
;
10743 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
10745 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10747 dwp_file
->sections
.loc
.s
.section
= sectp
;
10748 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
10750 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10752 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
10753 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
10755 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10757 dwp_file
->sections
.macro
.s
.section
= sectp
;
10758 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
10760 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10762 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
10763 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
10765 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10767 dwp_file
->sections
.types
.s
.section
= sectp
;
10768 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
10772 /* Hash function for dwp_file loaded CUs/TUs. */
10775 hash_dwp_loaded_cutus (const void *item
)
10777 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10779 /* This drops the top 32 bits of the signature, but is ok for a hash. */
10780 return dwo_unit
->signature
;
10783 /* Equality function for dwp_file loaded CUs/TUs. */
10786 eq_dwp_loaded_cutus (const void *a
, const void *b
)
10788 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
10789 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
10791 return dua
->signature
== dub
->signature
;
10794 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
10797 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
10799 return htab_create_alloc_ex (3,
10800 hash_dwp_loaded_cutus
,
10801 eq_dwp_loaded_cutus
,
10803 &objfile
->objfile_obstack
,
10804 hashtab_obstack_allocate
,
10805 dummy_obstack_deallocate
);
10808 /* Try to open DWP file FILE_NAME.
10809 The result is the bfd handle of the file.
10810 If there is a problem finding or opening the file, return NULL.
10811 Upon success, the canonicalized path of the file is stored in the bfd,
10812 same as symfile_bfd_open. */
10815 open_dwp_file (const char *file_name
)
10819 abfd
= try_open_dwop_file (file_name
, 1 /*is_dwp*/, 1 /*search_cwd*/);
10823 /* Work around upstream bug 15652.
10824 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
10825 [Whether that's a "bug" is debatable, but it is getting in our way.]
10826 We have no real idea where the dwp file is, because gdb's realpath-ing
10827 of the executable's path may have discarded the needed info.
10828 [IWBN if the dwp file name was recorded in the executable, akin to
10829 .gnu_debuglink, but that doesn't exist yet.]
10830 Strip the directory from FILE_NAME and search again. */
10831 if (*debug_file_directory
!= '\0')
10833 /* Don't implicitly search the current directory here.
10834 If the user wants to search "." to handle this case,
10835 it must be added to debug-file-directory. */
10836 return try_open_dwop_file (lbasename (file_name
), 1 /*is_dwp*/,
10843 /* Initialize the use of the DWP file for the current objfile.
10844 By convention the name of the DWP file is ${objfile}.dwp.
10845 The result is NULL if it can't be found. */
10847 static struct dwp_file
*
10848 open_and_init_dwp_file (void)
10850 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10851 struct dwp_file
*dwp_file
;
10854 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, 0);
10856 /* Try to find first .dwp for the binary file before any symbolic links
10859 /* If the objfile is a debug file, find the name of the real binary
10860 file and get the name of dwp file from there. */
10861 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
10863 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
10864 const char *backlink_basename
= lbasename (backlink
->original_name
);
10865 char *debug_dirname
= ldirname (objfile
->original_name
);
10867 make_cleanup (xfree
, debug_dirname
);
10868 dwp_name
= xstrprintf ("%s%s%s.dwp", debug_dirname
,
10869 SLASH_STRING
, backlink_basename
);
10872 dwp_name
= xstrprintf ("%s.dwp", objfile
->original_name
);
10873 make_cleanup (xfree
, dwp_name
);
10875 dbfd
= open_dwp_file (dwp_name
);
10877 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
10879 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
10880 dwp_name
= xstrprintf ("%s.dwp", objfile_name (objfile
));
10881 make_cleanup (xfree
, dwp_name
);
10882 dbfd
= open_dwp_file (dwp_name
);
10887 if (dwarf_read_debug
)
10888 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
);
10889 do_cleanups (cleanups
);
10892 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
10893 dwp_file
->name
= bfd_get_filename (dbfd
);
10894 dwp_file
->dbfd
= dbfd
;
10895 do_cleanups (cleanups
);
10897 /* +1: section 0 is unused */
10898 dwp_file
->num_sections
= bfd_count_sections (dbfd
) + 1;
10899 dwp_file
->elf_sections
=
10900 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
10901 dwp_file
->num_sections
, asection
*);
10903 bfd_map_over_sections (dbfd
, dwarf2_locate_common_dwp_sections
, dwp_file
);
10905 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
10907 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
10909 /* The DWP file version is stored in the hash table. Oh well. */
10910 if (dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
10912 /* Technically speaking, we should try to limp along, but this is
10913 pretty bizarre. We use pulongest here because that's the established
10914 portability solution (e.g, we cannot use %u for uint32_t). */
10915 error (_("Dwarf Error: DWP file CU version %s doesn't match"
10916 " TU version %s [in DWP file %s]"),
10917 pulongest (dwp_file
->cus
->version
),
10918 pulongest (dwp_file
->tus
->version
), dwp_name
);
10920 dwp_file
->version
= dwp_file
->cus
->version
;
10922 if (dwp_file
->version
== 2)
10923 bfd_map_over_sections (dbfd
, dwarf2_locate_v2_dwp_sections
, dwp_file
);
10925 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
10926 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
10928 if (dwarf_read_debug
)
10930 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
10931 fprintf_unfiltered (gdb_stdlog
,
10932 " %s CUs, %s TUs\n",
10933 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
10934 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
10940 /* Wrapper around open_and_init_dwp_file, only open it once. */
10942 static struct dwp_file
*
10943 get_dwp_file (void)
10945 if (! dwarf2_per_objfile
->dwp_checked
)
10947 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file ();
10948 dwarf2_per_objfile
->dwp_checked
= 1;
10950 return dwarf2_per_objfile
->dwp_file
;
10953 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
10954 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
10955 or in the DWP file for the objfile, referenced by THIS_UNIT.
10956 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
10957 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
10959 This is called, for example, when wanting to read a variable with a
10960 complex location. Therefore we don't want to do file i/o for every call.
10961 Therefore we don't want to look for a DWO file on every call.
10962 Therefore we first see if we've already seen SIGNATURE in a DWP file,
10963 then we check if we've already seen DWO_NAME, and only THEN do we check
10966 The result is a pointer to the dwo_unit object or NULL if we didn't find it
10967 (dwo_id mismatch or couldn't find the DWO/DWP file). */
10969 static struct dwo_unit
*
10970 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
10971 const char *dwo_name
, const char *comp_dir
,
10972 ULONGEST signature
, int is_debug_types
)
10974 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10975 const char *kind
= is_debug_types
? "TU" : "CU";
10976 void **dwo_file_slot
;
10977 struct dwo_file
*dwo_file
;
10978 struct dwp_file
*dwp_file
;
10980 /* First see if there's a DWP file.
10981 If we have a DWP file but didn't find the DWO inside it, don't
10982 look for the original DWO file. It makes gdb behave differently
10983 depending on whether one is debugging in the build tree. */
10985 dwp_file
= get_dwp_file ();
10986 if (dwp_file
!= NULL
)
10988 const struct dwp_hash_table
*dwp_htab
=
10989 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10991 if (dwp_htab
!= NULL
)
10993 struct dwo_unit
*dwo_cutu
=
10994 lookup_dwo_unit_in_dwp (dwp_file
, comp_dir
,
10995 signature
, is_debug_types
);
10997 if (dwo_cutu
!= NULL
)
10999 if (dwarf_read_debug
)
11001 fprintf_unfiltered (gdb_stdlog
,
11002 "Virtual DWO %s %s found: @%s\n",
11003 kind
, hex_string (signature
),
11004 host_address_to_string (dwo_cutu
));
11012 /* No DWP file, look for the DWO file. */
11014 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
, comp_dir
);
11015 if (*dwo_file_slot
== NULL
)
11017 /* Read in the file and build a table of the CUs/TUs it contains. */
11018 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
11020 /* NOTE: This will be NULL if unable to open the file. */
11021 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11023 if (dwo_file
!= NULL
)
11025 struct dwo_unit
*dwo_cutu
= NULL
;
11027 if (is_debug_types
&& dwo_file
->tus
)
11029 struct dwo_unit find_dwo_cutu
;
11031 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
11032 find_dwo_cutu
.signature
= signature
;
11034 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
11036 else if (!is_debug_types
&& dwo_file
->cu
)
11038 if (signature
== dwo_file
->cu
->signature
)
11039 dwo_cutu
= dwo_file
->cu
;
11042 if (dwo_cutu
!= NULL
)
11044 if (dwarf_read_debug
)
11046 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
11047 kind
, dwo_name
, hex_string (signature
),
11048 host_address_to_string (dwo_cutu
));
11055 /* We didn't find it. This could mean a dwo_id mismatch, or
11056 someone deleted the DWO/DWP file, or the search path isn't set up
11057 correctly to find the file. */
11059 if (dwarf_read_debug
)
11061 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
11062 kind
, dwo_name
, hex_string (signature
));
11065 /* This is a warning and not a complaint because it can be caused by
11066 pilot error (e.g., user accidentally deleting the DWO). */
11068 /* Print the name of the DWP file if we looked there, helps the user
11069 better diagnose the problem. */
11070 char *dwp_text
= NULL
;
11071 struct cleanup
*cleanups
;
11073 if (dwp_file
!= NULL
)
11074 dwp_text
= xstrprintf (" [in DWP file %s]", lbasename (dwp_file
->name
));
11075 cleanups
= make_cleanup (xfree
, dwp_text
);
11077 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset 0x%x"
11078 " [in module %s]"),
11079 kind
, dwo_name
, hex_string (signature
),
11080 dwp_text
!= NULL
? dwp_text
: "",
11081 this_unit
->is_debug_types
? "TU" : "CU",
11082 this_unit
->offset
.sect_off
, objfile_name (objfile
));
11084 do_cleanups (cleanups
);
11089 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
11090 See lookup_dwo_cutu_unit for details. */
11092 static struct dwo_unit
*
11093 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
11094 const char *dwo_name
, const char *comp_dir
,
11095 ULONGEST signature
)
11097 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
11100 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
11101 See lookup_dwo_cutu_unit for details. */
11103 static struct dwo_unit
*
11104 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
11105 const char *dwo_name
, const char *comp_dir
)
11107 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
11110 /* Traversal function for queue_and_load_all_dwo_tus. */
11113 queue_and_load_dwo_tu (void **slot
, void *info
)
11115 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
11116 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
11117 ULONGEST signature
= dwo_unit
->signature
;
11118 struct signatured_type
*sig_type
=
11119 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
11121 if (sig_type
!= NULL
)
11123 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
11125 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
11126 a real dependency of PER_CU on SIG_TYPE. That is detected later
11127 while processing PER_CU. */
11128 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
11129 load_full_type_unit (sig_cu
);
11130 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
11136 /* Queue all TUs contained in the DWO of PER_CU to be read in.
11137 The DWO may have the only definition of the type, though it may not be
11138 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
11139 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
11142 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
11144 struct dwo_unit
*dwo_unit
;
11145 struct dwo_file
*dwo_file
;
11147 gdb_assert (!per_cu
->is_debug_types
);
11148 gdb_assert (get_dwp_file () == NULL
);
11149 gdb_assert (per_cu
->cu
!= NULL
);
11151 dwo_unit
= per_cu
->cu
->dwo_unit
;
11152 gdb_assert (dwo_unit
!= NULL
);
11154 dwo_file
= dwo_unit
->dwo_file
;
11155 if (dwo_file
->tus
!= NULL
)
11156 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
11159 /* Free all resources associated with DWO_FILE.
11160 Close the DWO file and munmap the sections.
11161 All memory should be on the objfile obstack. */
11164 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
11167 /* Note: dbfd is NULL for virtual DWO files. */
11168 gdb_bfd_unref (dwo_file
->dbfd
);
11170 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
11173 /* Wrapper for free_dwo_file for use in cleanups. */
11176 free_dwo_file_cleanup (void *arg
)
11178 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
11179 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11181 free_dwo_file (dwo_file
, objfile
);
11184 /* Traversal function for free_dwo_files. */
11187 free_dwo_file_from_slot (void **slot
, void *info
)
11189 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
11190 struct objfile
*objfile
= (struct objfile
*) info
;
11192 free_dwo_file (dwo_file
, objfile
);
11197 /* Free all resources associated with DWO_FILES. */
11200 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
11202 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
11205 /* Read in various DIEs. */
11207 /* qsort helper for inherit_abstract_dies. */
11210 unsigned_int_compar (const void *ap
, const void *bp
)
11212 unsigned int a
= *(unsigned int *) ap
;
11213 unsigned int b
= *(unsigned int *) bp
;
11215 return (a
> b
) - (b
> a
);
11218 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
11219 Inherit only the children of the DW_AT_abstract_origin DIE not being
11220 already referenced by DW_AT_abstract_origin from the children of the
11224 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
11226 struct die_info
*child_die
;
11227 unsigned die_children_count
;
11228 /* CU offsets which were referenced by children of the current DIE. */
11229 sect_offset
*offsets
;
11230 sect_offset
*offsets_end
, *offsetp
;
11231 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
11232 struct die_info
*origin_die
;
11233 /* Iterator of the ORIGIN_DIE children. */
11234 struct die_info
*origin_child_die
;
11235 struct cleanup
*cleanups
;
11236 struct attribute
*attr
;
11237 struct dwarf2_cu
*origin_cu
;
11238 struct pending
**origin_previous_list_in_scope
;
11240 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11244 /* Note that following die references may follow to a die in a
11248 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
11250 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
11252 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
11253 origin_cu
->list_in_scope
= cu
->list_in_scope
;
11255 if (die
->tag
!= origin_die
->tag
11256 && !(die
->tag
== DW_TAG_inlined_subroutine
11257 && origin_die
->tag
== DW_TAG_subprogram
))
11258 complaint (&symfile_complaints
,
11259 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
11260 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
11262 child_die
= die
->child
;
11263 die_children_count
= 0;
11264 while (child_die
&& child_die
->tag
)
11266 child_die
= sibling_die (child_die
);
11267 die_children_count
++;
11269 offsets
= XNEWVEC (sect_offset
, die_children_count
);
11270 cleanups
= make_cleanup (xfree
, offsets
);
11272 offsets_end
= offsets
;
11273 for (child_die
= die
->child
;
11274 child_die
&& child_die
->tag
;
11275 child_die
= sibling_die (child_die
))
11277 struct die_info
*child_origin_die
;
11278 struct dwarf2_cu
*child_origin_cu
;
11280 /* We are trying to process concrete instance entries:
11281 DW_TAG_GNU_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
11282 it's not relevant to our analysis here. i.e. detecting DIEs that are
11283 present in the abstract instance but not referenced in the concrete
11285 if (child_die
->tag
== DW_TAG_GNU_call_site
)
11288 /* For each CHILD_DIE, find the corresponding child of
11289 ORIGIN_DIE. If there is more than one layer of
11290 DW_AT_abstract_origin, follow them all; there shouldn't be,
11291 but GCC versions at least through 4.4 generate this (GCC PR
11293 child_origin_die
= child_die
;
11294 child_origin_cu
= cu
;
11297 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
11301 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
11305 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
11306 counterpart may exist. */
11307 if (child_origin_die
!= child_die
)
11309 if (child_die
->tag
!= child_origin_die
->tag
11310 && !(child_die
->tag
== DW_TAG_inlined_subroutine
11311 && child_origin_die
->tag
== DW_TAG_subprogram
))
11312 complaint (&symfile_complaints
,
11313 _("Child DIE 0x%x and its abstract origin 0x%x have "
11314 "different tags"), child_die
->offset
.sect_off
,
11315 child_origin_die
->offset
.sect_off
);
11316 if (child_origin_die
->parent
!= origin_die
)
11317 complaint (&symfile_complaints
,
11318 _("Child DIE 0x%x and its abstract origin 0x%x have "
11319 "different parents"), child_die
->offset
.sect_off
,
11320 child_origin_die
->offset
.sect_off
);
11322 *offsets_end
++ = child_origin_die
->offset
;
11325 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
11326 unsigned_int_compar
);
11327 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
11328 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
11329 complaint (&symfile_complaints
,
11330 _("Multiple children of DIE 0x%x refer "
11331 "to DIE 0x%x as their abstract origin"),
11332 die
->offset
.sect_off
, offsetp
->sect_off
);
11335 origin_child_die
= origin_die
->child
;
11336 while (origin_child_die
&& origin_child_die
->tag
)
11338 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
11339 while (offsetp
< offsets_end
11340 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
11342 if (offsetp
>= offsets_end
11343 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
11345 /* Found that ORIGIN_CHILD_DIE is really not referenced.
11346 Check whether we're already processing ORIGIN_CHILD_DIE.
11347 This can happen with mutually referenced abstract_origins.
11349 if (!origin_child_die
->in_process
)
11350 process_die (origin_child_die
, origin_cu
);
11352 origin_child_die
= sibling_die (origin_child_die
);
11354 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
11356 do_cleanups (cleanups
);
11360 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11362 struct objfile
*objfile
= cu
->objfile
;
11363 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11364 struct context_stack
*newobj
;
11367 struct die_info
*child_die
;
11368 struct attribute
*attr
, *call_line
, *call_file
;
11370 CORE_ADDR baseaddr
;
11371 struct block
*block
;
11372 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11373 VEC (symbolp
) *template_args
= NULL
;
11374 struct template_symbol
*templ_func
= NULL
;
11378 /* If we do not have call site information, we can't show the
11379 caller of this inlined function. That's too confusing, so
11380 only use the scope for local variables. */
11381 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
11382 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
11383 if (call_line
== NULL
|| call_file
== NULL
)
11385 read_lexical_block_scope (die
, cu
);
11390 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11392 name
= dwarf2_name (die
, cu
);
11394 /* Ignore functions with missing or empty names. These are actually
11395 illegal according to the DWARF standard. */
11398 complaint (&symfile_complaints
,
11399 _("missing name for subprogram DIE at %d"),
11400 die
->offset
.sect_off
);
11404 /* Ignore functions with missing or invalid low and high pc attributes. */
11405 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
11406 <= PC_BOUNDS_INVALID
)
11408 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
11409 if (!attr
|| !DW_UNSND (attr
))
11410 complaint (&symfile_complaints
,
11411 _("cannot get low and high bounds "
11412 "for subprogram DIE at %d"),
11413 die
->offset
.sect_off
);
11417 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11418 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11420 /* If we have any template arguments, then we must allocate a
11421 different sort of symbol. */
11422 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
11424 if (child_die
->tag
== DW_TAG_template_type_param
11425 || child_die
->tag
== DW_TAG_template_value_param
)
11427 templ_func
= allocate_template_symbol (objfile
);
11428 templ_func
->base
.is_cplus_template_function
= 1;
11433 newobj
= push_context (0, lowpc
);
11434 newobj
->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
11435 (struct symbol
*) templ_func
);
11437 /* If there is a location expression for DW_AT_frame_base, record
11439 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
11441 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
11443 /* If there is a location for the static link, record it. */
11444 newobj
->static_link
= NULL
;
11445 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
11448 newobj
->static_link
11449 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
11450 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
11453 cu
->list_in_scope
= &local_symbols
;
11455 if (die
->child
!= NULL
)
11457 child_die
= die
->child
;
11458 while (child_die
&& child_die
->tag
)
11460 if (child_die
->tag
== DW_TAG_template_type_param
11461 || child_die
->tag
== DW_TAG_template_value_param
)
11463 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
11466 VEC_safe_push (symbolp
, template_args
, arg
);
11469 process_die (child_die
, cu
);
11470 child_die
= sibling_die (child_die
);
11474 inherit_abstract_dies (die
, cu
);
11476 /* If we have a DW_AT_specification, we might need to import using
11477 directives from the context of the specification DIE. See the
11478 comment in determine_prefix. */
11479 if (cu
->language
== language_cplus
11480 && dwarf2_attr (die
, DW_AT_specification
, cu
))
11482 struct dwarf2_cu
*spec_cu
= cu
;
11483 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
11487 child_die
= spec_die
->child
;
11488 while (child_die
&& child_die
->tag
)
11490 if (child_die
->tag
== DW_TAG_imported_module
)
11491 process_die (child_die
, spec_cu
);
11492 child_die
= sibling_die (child_die
);
11495 /* In some cases, GCC generates specification DIEs that
11496 themselves contain DW_AT_specification attributes. */
11497 spec_die
= die_specification (spec_die
, &spec_cu
);
11501 newobj
= pop_context ();
11502 /* Make a block for the local symbols within. */
11503 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
11504 newobj
->static_link
, lowpc
, highpc
);
11506 /* For C++, set the block's scope. */
11507 if ((cu
->language
== language_cplus
11508 || cu
->language
== language_fortran
11509 || cu
->language
== language_d
11510 || cu
->language
== language_rust
)
11511 && cu
->processing_has_namespace_info
)
11512 block_set_scope (block
, determine_prefix (die
, cu
),
11513 &objfile
->objfile_obstack
);
11515 /* If we have address ranges, record them. */
11516 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11518 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
11520 /* Attach template arguments to function. */
11521 if (! VEC_empty (symbolp
, template_args
))
11523 gdb_assert (templ_func
!= NULL
);
11525 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
11526 templ_func
->template_arguments
11527 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
11528 templ_func
->n_template_arguments
);
11529 memcpy (templ_func
->template_arguments
,
11530 VEC_address (symbolp
, template_args
),
11531 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
11532 VEC_free (symbolp
, template_args
);
11535 /* In C++, we can have functions nested inside functions (e.g., when
11536 a function declares a class that has methods). This means that
11537 when we finish processing a function scope, we may need to go
11538 back to building a containing block's symbol lists. */
11539 local_symbols
= newobj
->locals
;
11540 local_using_directives
= newobj
->local_using_directives
;
11542 /* If we've finished processing a top-level function, subsequent
11543 symbols go in the file symbol list. */
11544 if (outermost_context_p ())
11545 cu
->list_in_scope
= &file_symbols
;
11548 /* Process all the DIES contained within a lexical block scope. Start
11549 a new scope, process the dies, and then close the scope. */
11552 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11554 struct objfile
*objfile
= cu
->objfile
;
11555 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11556 struct context_stack
*newobj
;
11557 CORE_ADDR lowpc
, highpc
;
11558 struct die_info
*child_die
;
11559 CORE_ADDR baseaddr
;
11561 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11563 /* Ignore blocks with missing or invalid low and high pc attributes. */
11564 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
11565 as multiple lexical blocks? Handling children in a sane way would
11566 be nasty. Might be easier to properly extend generic blocks to
11567 describe ranges. */
11568 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
11570 case PC_BOUNDS_NOT_PRESENT
:
11571 /* DW_TAG_lexical_block has no attributes, process its children as if
11572 there was no wrapping by that DW_TAG_lexical_block.
11573 GCC does no longer produces such DWARF since GCC r224161. */
11574 for (child_die
= die
->child
;
11575 child_die
!= NULL
&& child_die
->tag
;
11576 child_die
= sibling_die (child_die
))
11577 process_die (child_die
, cu
);
11579 case PC_BOUNDS_INVALID
:
11582 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11583 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11585 push_context (0, lowpc
);
11586 if (die
->child
!= NULL
)
11588 child_die
= die
->child
;
11589 while (child_die
&& child_die
->tag
)
11591 process_die (child_die
, cu
);
11592 child_die
= sibling_die (child_die
);
11595 inherit_abstract_dies (die
, cu
);
11596 newobj
= pop_context ();
11598 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
11600 struct block
*block
11601 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
11602 newobj
->start_addr
, highpc
);
11604 /* Note that recording ranges after traversing children, as we
11605 do here, means that recording a parent's ranges entails
11606 walking across all its children's ranges as they appear in
11607 the address map, which is quadratic behavior.
11609 It would be nicer to record the parent's ranges before
11610 traversing its children, simply overriding whatever you find
11611 there. But since we don't even decide whether to create a
11612 block until after we've traversed its children, that's hard
11614 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11616 local_symbols
= newobj
->locals
;
11617 local_using_directives
= newobj
->local_using_directives
;
11620 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
11623 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11625 struct objfile
*objfile
= cu
->objfile
;
11626 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11627 CORE_ADDR pc
, baseaddr
;
11628 struct attribute
*attr
;
11629 struct call_site
*call_site
, call_site_local
;
11632 struct die_info
*child_die
;
11634 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11636 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11639 complaint (&symfile_complaints
,
11640 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
11641 "DIE 0x%x [in module %s]"),
11642 die
->offset
.sect_off
, objfile_name (objfile
));
11645 pc
= attr_value_as_address (attr
) + baseaddr
;
11646 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
11648 if (cu
->call_site_htab
== NULL
)
11649 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
11650 NULL
, &objfile
->objfile_obstack
,
11651 hashtab_obstack_allocate
, NULL
);
11652 call_site_local
.pc
= pc
;
11653 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
11656 complaint (&symfile_complaints
,
11657 _("Duplicate PC %s for DW_TAG_GNU_call_site "
11658 "DIE 0x%x [in module %s]"),
11659 paddress (gdbarch
, pc
), die
->offset
.sect_off
,
11660 objfile_name (objfile
));
11664 /* Count parameters at the caller. */
11667 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11668 child_die
= sibling_die (child_die
))
11670 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11672 complaint (&symfile_complaints
,
11673 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
11674 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11675 child_die
->tag
, child_die
->offset
.sect_off
,
11676 objfile_name (objfile
));
11684 = ((struct call_site
*)
11685 obstack_alloc (&objfile
->objfile_obstack
,
11686 sizeof (*call_site
)
11687 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
11689 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
11690 call_site
->pc
= pc
;
11692 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
11694 struct die_info
*func_die
;
11696 /* Skip also over DW_TAG_inlined_subroutine. */
11697 for (func_die
= die
->parent
;
11698 func_die
&& func_die
->tag
!= DW_TAG_subprogram
11699 && func_die
->tag
!= DW_TAG_subroutine_type
;
11700 func_die
= func_die
->parent
);
11702 /* DW_AT_GNU_all_call_sites is a superset
11703 of DW_AT_GNU_all_tail_call_sites. */
11705 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
11706 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
11708 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
11709 not complete. But keep CALL_SITE for look ups via call_site_htab,
11710 both the initial caller containing the real return address PC and
11711 the final callee containing the current PC of a chain of tail
11712 calls do not need to have the tail call list complete. But any
11713 function candidate for a virtual tail call frame searched via
11714 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
11715 determined unambiguously. */
11719 struct type
*func_type
= NULL
;
11722 func_type
= get_die_type (func_die
, cu
);
11723 if (func_type
!= NULL
)
11725 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
11727 /* Enlist this call site to the function. */
11728 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
11729 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
11732 complaint (&symfile_complaints
,
11733 _("Cannot find function owning DW_TAG_GNU_call_site "
11734 "DIE 0x%x [in module %s]"),
11735 die
->offset
.sect_off
, objfile_name (objfile
));
11739 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
11741 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11742 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
11743 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
11744 /* Keep NULL DWARF_BLOCK. */;
11745 else if (attr_form_is_block (attr
))
11747 struct dwarf2_locexpr_baton
*dlbaton
;
11749 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
11750 dlbaton
->data
= DW_BLOCK (attr
)->data
;
11751 dlbaton
->size
= DW_BLOCK (attr
)->size
;
11752 dlbaton
->per_cu
= cu
->per_cu
;
11754 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
11756 else if (attr_form_is_ref (attr
))
11758 struct dwarf2_cu
*target_cu
= cu
;
11759 struct die_info
*target_die
;
11761 target_die
= follow_die_ref (die
, attr
, &target_cu
);
11762 gdb_assert (target_cu
->objfile
== objfile
);
11763 if (die_is_declaration (target_die
, target_cu
))
11765 const char *target_physname
;
11767 /* Prefer the mangled name; otherwise compute the demangled one. */
11768 target_physname
= dwarf2_string_attr (target_die
,
11769 DW_AT_linkage_name
,
11771 if (target_physname
== NULL
)
11772 target_physname
= dwarf2_string_attr (target_die
,
11773 DW_AT_MIPS_linkage_name
,
11775 if (target_physname
== NULL
)
11776 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
11777 if (target_physname
== NULL
)
11778 complaint (&symfile_complaints
,
11779 _("DW_AT_GNU_call_site_target target DIE has invalid "
11780 "physname, for referencing DIE 0x%x [in module %s]"),
11781 die
->offset
.sect_off
, objfile_name (objfile
));
11783 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
11789 /* DW_AT_entry_pc should be preferred. */
11790 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
11791 <= PC_BOUNDS_INVALID
)
11792 complaint (&symfile_complaints
,
11793 _("DW_AT_GNU_call_site_target target DIE has invalid "
11794 "low pc, for referencing DIE 0x%x [in module %s]"),
11795 die
->offset
.sect_off
, objfile_name (objfile
));
11798 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11799 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
11804 complaint (&symfile_complaints
,
11805 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
11806 "block nor reference, for DIE 0x%x [in module %s]"),
11807 die
->offset
.sect_off
, objfile_name (objfile
));
11809 call_site
->per_cu
= cu
->per_cu
;
11811 for (child_die
= die
->child
;
11812 child_die
&& child_die
->tag
;
11813 child_die
= sibling_die (child_die
))
11815 struct call_site_parameter
*parameter
;
11816 struct attribute
*loc
, *origin
;
11818 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11820 /* Already printed the complaint above. */
11824 gdb_assert (call_site
->parameter_count
< nparams
);
11825 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
11827 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
11828 specifies DW_TAG_formal_parameter. Value of the data assumed for the
11829 register is contained in DW_AT_GNU_call_site_value. */
11831 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
11832 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
11833 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
11835 sect_offset offset
;
11837 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
11838 offset
= dwarf2_get_ref_die_offset (origin
);
11839 if (!offset_in_cu_p (&cu
->header
, offset
))
11841 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
11842 binding can be done only inside one CU. Such referenced DIE
11843 therefore cannot be even moved to DW_TAG_partial_unit. */
11844 complaint (&symfile_complaints
,
11845 _("DW_AT_abstract_origin offset is not in CU for "
11846 "DW_TAG_GNU_call_site child DIE 0x%x "
11848 child_die
->offset
.sect_off
, objfile_name (objfile
));
11851 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
11852 - cu
->header
.offset
.sect_off
);
11854 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
11856 complaint (&symfile_complaints
,
11857 _("No DW_FORM_block* DW_AT_location for "
11858 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11859 child_die
->offset
.sect_off
, objfile_name (objfile
));
11864 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
11865 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
11866 if (parameter
->u
.dwarf_reg
!= -1)
11867 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
11868 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
11869 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
11870 ¶meter
->u
.fb_offset
))
11871 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
11874 complaint (&symfile_complaints
,
11875 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
11876 "for DW_FORM_block* DW_AT_location is supported for "
11877 "DW_TAG_GNU_call_site child DIE 0x%x "
11879 child_die
->offset
.sect_off
, objfile_name (objfile
));
11884 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
11885 if (!attr_form_is_block (attr
))
11887 complaint (&symfile_complaints
,
11888 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
11889 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11890 child_die
->offset
.sect_off
, objfile_name (objfile
));
11893 parameter
->value
= DW_BLOCK (attr
)->data
;
11894 parameter
->value_size
= DW_BLOCK (attr
)->size
;
11896 /* Parameters are not pre-cleared by memset above. */
11897 parameter
->data_value
= NULL
;
11898 parameter
->data_value_size
= 0;
11899 call_site
->parameter_count
++;
11901 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
11904 if (!attr_form_is_block (attr
))
11905 complaint (&symfile_complaints
,
11906 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
11907 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11908 child_die
->offset
.sect_off
, objfile_name (objfile
));
11911 parameter
->data_value
= DW_BLOCK (attr
)->data
;
11912 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
11918 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
11919 Return 1 if the attributes are present and valid, otherwise, return 0.
11920 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
11923 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
11924 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
11925 struct partial_symtab
*ranges_pst
)
11927 struct objfile
*objfile
= cu
->objfile
;
11928 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11929 struct comp_unit_head
*cu_header
= &cu
->header
;
11930 bfd
*obfd
= objfile
->obfd
;
11931 unsigned int addr_size
= cu_header
->addr_size
;
11932 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
11933 /* Base address selection entry. */
11936 unsigned int dummy
;
11937 const gdb_byte
*buffer
;
11940 CORE_ADDR high
= 0;
11941 CORE_ADDR baseaddr
;
11943 found_base
= cu
->base_known
;
11944 base
= cu
->base_address
;
11946 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
11947 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
11949 complaint (&symfile_complaints
,
11950 _("Offset %d out of bounds for DW_AT_ranges attribute"),
11954 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
11958 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11962 CORE_ADDR range_beginning
, range_end
;
11964 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
11965 buffer
+= addr_size
;
11966 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
11967 buffer
+= addr_size
;
11968 offset
+= 2 * addr_size
;
11970 /* An end of list marker is a pair of zero addresses. */
11971 if (range_beginning
== 0 && range_end
== 0)
11972 /* Found the end of list entry. */
11975 /* Each base address selection entry is a pair of 2 values.
11976 The first is the largest possible address, the second is
11977 the base address. Check for a base address here. */
11978 if ((range_beginning
& mask
) == mask
)
11980 /* If we found the largest possible address, then we already
11981 have the base address in range_end. */
11989 /* We have no valid base address for the ranges
11991 complaint (&symfile_complaints
,
11992 _("Invalid .debug_ranges data (no base address)"));
11996 if (range_beginning
> range_end
)
11998 /* Inverted range entries are invalid. */
11999 complaint (&symfile_complaints
,
12000 _("Invalid .debug_ranges data (inverted range)"));
12004 /* Empty range entries have no effect. */
12005 if (range_beginning
== range_end
)
12008 range_beginning
+= base
;
12011 /* A not-uncommon case of bad debug info.
12012 Don't pollute the addrmap with bad data. */
12013 if (range_beginning
+ baseaddr
== 0
12014 && !dwarf2_per_objfile
->has_section_at_zero
)
12016 complaint (&symfile_complaints
,
12017 _(".debug_ranges entry has start address of zero"
12018 " [in module %s]"), objfile_name (objfile
));
12022 if (ranges_pst
!= NULL
)
12027 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
12028 range_beginning
+ baseaddr
);
12029 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
12030 range_end
+ baseaddr
);
12031 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
12035 /* FIXME: This is recording everything as a low-high
12036 segment of consecutive addresses. We should have a
12037 data structure for discontiguous block ranges
12041 low
= range_beginning
;
12047 if (range_beginning
< low
)
12048 low
= range_beginning
;
12049 if (range_end
> high
)
12055 /* If the first entry is an end-of-list marker, the range
12056 describes an empty scope, i.e. no instructions. */
12062 *high_return
= high
;
12066 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
12067 definition for the return value. *LOWPC and *HIGHPC are set iff
12068 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
12070 static enum pc_bounds_kind
12071 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
12072 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
12073 struct partial_symtab
*pst
)
12075 struct attribute
*attr
;
12076 struct attribute
*attr_high
;
12078 CORE_ADDR high
= 0;
12079 enum pc_bounds_kind ret
;
12081 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12084 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12087 low
= attr_value_as_address (attr
);
12088 high
= attr_value_as_address (attr_high
);
12089 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12093 /* Found high w/o low attribute. */
12094 return PC_BOUNDS_INVALID
;
12096 /* Found consecutive range of addresses. */
12097 ret
= PC_BOUNDS_HIGH_LOW
;
12101 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12104 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12105 We take advantage of the fact that DW_AT_ranges does not appear
12106 in DW_TAG_compile_unit of DWO files. */
12107 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12108 unsigned int ranges_offset
= (DW_UNSND (attr
)
12109 + (need_ranges_base
12113 /* Value of the DW_AT_ranges attribute is the offset in the
12114 .debug_ranges section. */
12115 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
12116 return PC_BOUNDS_INVALID
;
12117 /* Found discontinuous range of addresses. */
12118 ret
= PC_BOUNDS_RANGES
;
12121 return PC_BOUNDS_NOT_PRESENT
;
12124 /* read_partial_die has also the strict LOW < HIGH requirement. */
12126 return PC_BOUNDS_INVALID
;
12128 /* When using the GNU linker, .gnu.linkonce. sections are used to
12129 eliminate duplicate copies of functions and vtables and such.
12130 The linker will arbitrarily choose one and discard the others.
12131 The AT_*_pc values for such functions refer to local labels in
12132 these sections. If the section from that file was discarded, the
12133 labels are not in the output, so the relocs get a value of 0.
12134 If this is a discarded function, mark the pc bounds as invalid,
12135 so that GDB will ignore it. */
12136 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12137 return PC_BOUNDS_INVALID
;
12145 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
12146 its low and high PC addresses. Do nothing if these addresses could not
12147 be determined. Otherwise, set LOWPC to the low address if it is smaller,
12148 and HIGHPC to the high address if greater than HIGHPC. */
12151 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
12152 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12153 struct dwarf2_cu
*cu
)
12155 CORE_ADDR low
, high
;
12156 struct die_info
*child
= die
->child
;
12158 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
12160 *lowpc
= std::min (*lowpc
, low
);
12161 *highpc
= std::max (*highpc
, high
);
12164 /* If the language does not allow nested subprograms (either inside
12165 subprograms or lexical blocks), we're done. */
12166 if (cu
->language
!= language_ada
)
12169 /* Check all the children of the given DIE. If it contains nested
12170 subprograms, then check their pc bounds. Likewise, we need to
12171 check lexical blocks as well, as they may also contain subprogram
12173 while (child
&& child
->tag
)
12175 if (child
->tag
== DW_TAG_subprogram
12176 || child
->tag
== DW_TAG_lexical_block
)
12177 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
12178 child
= sibling_die (child
);
12182 /* Get the low and high pc's represented by the scope DIE, and store
12183 them in *LOWPC and *HIGHPC. If the correct values can't be
12184 determined, set *LOWPC to -1 and *HIGHPC to 0. */
12187 get_scope_pc_bounds (struct die_info
*die
,
12188 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12189 struct dwarf2_cu
*cu
)
12191 CORE_ADDR best_low
= (CORE_ADDR
) -1;
12192 CORE_ADDR best_high
= (CORE_ADDR
) 0;
12193 CORE_ADDR current_low
, current_high
;
12195 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
12196 >= PC_BOUNDS_RANGES
)
12198 best_low
= current_low
;
12199 best_high
= current_high
;
12203 struct die_info
*child
= die
->child
;
12205 while (child
&& child
->tag
)
12207 switch (child
->tag
) {
12208 case DW_TAG_subprogram
:
12209 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
12211 case DW_TAG_namespace
:
12212 case DW_TAG_module
:
12213 /* FIXME: carlton/2004-01-16: Should we do this for
12214 DW_TAG_class_type/DW_TAG_structure_type, too? I think
12215 that current GCC's always emit the DIEs corresponding
12216 to definitions of methods of classes as children of a
12217 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
12218 the DIEs giving the declarations, which could be
12219 anywhere). But I don't see any reason why the
12220 standards says that they have to be there. */
12221 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
12223 if (current_low
!= ((CORE_ADDR
) -1))
12225 best_low
= std::min (best_low
, current_low
);
12226 best_high
= std::max (best_high
, current_high
);
12234 child
= sibling_die (child
);
12239 *highpc
= best_high
;
12242 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
12246 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
12247 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
12249 struct objfile
*objfile
= cu
->objfile
;
12250 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12251 struct attribute
*attr
;
12252 struct attribute
*attr_high
;
12254 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12257 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12260 CORE_ADDR low
= attr_value_as_address (attr
);
12261 CORE_ADDR high
= attr_value_as_address (attr_high
);
12263 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12266 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
12267 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
12268 record_block_range (block
, low
, high
- 1);
12272 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12275 bfd
*obfd
= objfile
->obfd
;
12276 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12277 We take advantage of the fact that DW_AT_ranges does not appear
12278 in DW_TAG_compile_unit of DWO files. */
12279 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12281 /* The value of the DW_AT_ranges attribute is the offset of the
12282 address range list in the .debug_ranges section. */
12283 unsigned long offset
= (DW_UNSND (attr
)
12284 + (need_ranges_base
? cu
->ranges_base
: 0));
12285 const gdb_byte
*buffer
;
12287 /* For some target architectures, but not others, the
12288 read_address function sign-extends the addresses it returns.
12289 To recognize base address selection entries, we need a
12291 unsigned int addr_size
= cu
->header
.addr_size
;
12292 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12294 /* The base address, to which the next pair is relative. Note
12295 that this 'base' is a DWARF concept: most entries in a range
12296 list are relative, to reduce the number of relocs against the
12297 debugging information. This is separate from this function's
12298 'baseaddr' argument, which GDB uses to relocate debugging
12299 information from a shared library based on the address at
12300 which the library was loaded. */
12301 CORE_ADDR base
= cu
->base_address
;
12302 int base_known
= cu
->base_known
;
12304 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
12305 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
12307 complaint (&symfile_complaints
,
12308 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
12312 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
12316 unsigned int bytes_read
;
12317 CORE_ADDR start
, end
;
12319 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12320 buffer
+= bytes_read
;
12321 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12322 buffer
+= bytes_read
;
12324 /* Did we find the end of the range list? */
12325 if (start
== 0 && end
== 0)
12328 /* Did we find a base address selection entry? */
12329 else if ((start
& base_select_mask
) == base_select_mask
)
12335 /* We found an ordinary address range. */
12340 complaint (&symfile_complaints
,
12341 _("Invalid .debug_ranges data "
12342 "(no base address)"));
12348 /* Inverted range entries are invalid. */
12349 complaint (&symfile_complaints
,
12350 _("Invalid .debug_ranges data "
12351 "(inverted range)"));
12355 /* Empty range entries have no effect. */
12359 start
+= base
+ baseaddr
;
12360 end
+= base
+ baseaddr
;
12362 /* A not-uncommon case of bad debug info.
12363 Don't pollute the addrmap with bad data. */
12364 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12366 complaint (&symfile_complaints
,
12367 _(".debug_ranges entry has start address of zero"
12368 " [in module %s]"), objfile_name (objfile
));
12372 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
12373 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
12374 record_block_range (block
, start
, end
- 1);
12380 /* Check whether the producer field indicates either of GCC < 4.6, or the
12381 Intel C/C++ compiler, and cache the result in CU. */
12384 check_producer (struct dwarf2_cu
*cu
)
12388 if (cu
->producer
== NULL
)
12390 /* For unknown compilers expect their behavior is DWARF version
12393 GCC started to support .debug_types sections by -gdwarf-4 since
12394 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
12395 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
12396 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
12397 interpreted incorrectly by GDB now - GCC PR debug/48229. */
12399 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
12401 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
12402 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
12404 else if (startswith (cu
->producer
, "Intel(R) C"))
12405 cu
->producer_is_icc
= 1;
12408 /* For other non-GCC compilers, expect their behavior is DWARF version
12412 cu
->checked_producer
= 1;
12415 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
12416 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
12417 during 4.6.0 experimental. */
12420 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
12422 if (!cu
->checked_producer
)
12423 check_producer (cu
);
12425 return cu
->producer_is_gxx_lt_4_6
;
12428 /* Return the default accessibility type if it is not overriden by
12429 DW_AT_accessibility. */
12431 static enum dwarf_access_attribute
12432 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
12434 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
12436 /* The default DWARF 2 accessibility for members is public, the default
12437 accessibility for inheritance is private. */
12439 if (die
->tag
!= DW_TAG_inheritance
)
12440 return DW_ACCESS_public
;
12442 return DW_ACCESS_private
;
12446 /* DWARF 3+ defines the default accessibility a different way. The same
12447 rules apply now for DW_TAG_inheritance as for the members and it only
12448 depends on the container kind. */
12450 if (die
->parent
->tag
== DW_TAG_class_type
)
12451 return DW_ACCESS_private
;
12453 return DW_ACCESS_public
;
12457 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
12458 offset. If the attribute was not found return 0, otherwise return
12459 1. If it was found but could not properly be handled, set *OFFSET
12463 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
12466 struct attribute
*attr
;
12468 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
12473 /* Note that we do not check for a section offset first here.
12474 This is because DW_AT_data_member_location is new in DWARF 4,
12475 so if we see it, we can assume that a constant form is really
12476 a constant and not a section offset. */
12477 if (attr_form_is_constant (attr
))
12478 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
12479 else if (attr_form_is_section_offset (attr
))
12480 dwarf2_complex_location_expr_complaint ();
12481 else if (attr_form_is_block (attr
))
12482 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
12484 dwarf2_complex_location_expr_complaint ();
12492 /* Add an aggregate field to the field list. */
12495 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
12496 struct dwarf2_cu
*cu
)
12498 struct objfile
*objfile
= cu
->objfile
;
12499 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12500 struct nextfield
*new_field
;
12501 struct attribute
*attr
;
12503 const char *fieldname
= "";
12505 /* Allocate a new field list entry and link it in. */
12506 new_field
= XNEW (struct nextfield
);
12507 make_cleanup (xfree
, new_field
);
12508 memset (new_field
, 0, sizeof (struct nextfield
));
12510 if (die
->tag
== DW_TAG_inheritance
)
12512 new_field
->next
= fip
->baseclasses
;
12513 fip
->baseclasses
= new_field
;
12517 new_field
->next
= fip
->fields
;
12518 fip
->fields
= new_field
;
12522 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
12524 new_field
->accessibility
= DW_UNSND (attr
);
12526 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
12527 if (new_field
->accessibility
!= DW_ACCESS_public
)
12528 fip
->non_public_fields
= 1;
12530 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
12532 new_field
->virtuality
= DW_UNSND (attr
);
12534 new_field
->virtuality
= DW_VIRTUALITY_none
;
12536 fp
= &new_field
->field
;
12538 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
12542 /* Data member other than a C++ static data member. */
12544 /* Get type of field. */
12545 fp
->type
= die_type (die
, cu
);
12547 SET_FIELD_BITPOS (*fp
, 0);
12549 /* Get bit size of field (zero if none). */
12550 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
12553 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
12557 FIELD_BITSIZE (*fp
) = 0;
12560 /* Get bit offset of field. */
12561 if (handle_data_member_location (die
, cu
, &offset
))
12562 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12563 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
12566 if (gdbarch_bits_big_endian (gdbarch
))
12568 /* For big endian bits, the DW_AT_bit_offset gives the
12569 additional bit offset from the MSB of the containing
12570 anonymous object to the MSB of the field. We don't
12571 have to do anything special since we don't need to
12572 know the size of the anonymous object. */
12573 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
12577 /* For little endian bits, compute the bit offset to the
12578 MSB of the anonymous object, subtract off the number of
12579 bits from the MSB of the field to the MSB of the
12580 object, and then subtract off the number of bits of
12581 the field itself. The result is the bit offset of
12582 the LSB of the field. */
12583 int anonymous_size
;
12584 int bit_offset
= DW_UNSND (attr
);
12586 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12589 /* The size of the anonymous object containing
12590 the bit field is explicit, so use the
12591 indicated size (in bytes). */
12592 anonymous_size
= DW_UNSND (attr
);
12596 /* The size of the anonymous object containing
12597 the bit field must be inferred from the type
12598 attribute of the data member containing the
12600 anonymous_size
= TYPE_LENGTH (fp
->type
);
12602 SET_FIELD_BITPOS (*fp
,
12603 (FIELD_BITPOS (*fp
)
12604 + anonymous_size
* bits_per_byte
12605 - bit_offset
- FIELD_BITSIZE (*fp
)));
12609 /* Get name of field. */
12610 fieldname
= dwarf2_name (die
, cu
);
12611 if (fieldname
== NULL
)
12614 /* The name is already allocated along with this objfile, so we don't
12615 need to duplicate it for the type. */
12616 fp
->name
= fieldname
;
12618 /* Change accessibility for artificial fields (e.g. virtual table
12619 pointer or virtual base class pointer) to private. */
12620 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
12622 FIELD_ARTIFICIAL (*fp
) = 1;
12623 new_field
->accessibility
= DW_ACCESS_private
;
12624 fip
->non_public_fields
= 1;
12627 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
12629 /* C++ static member. */
12631 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
12632 is a declaration, but all versions of G++ as of this writing
12633 (so through at least 3.2.1) incorrectly generate
12634 DW_TAG_variable tags. */
12636 const char *physname
;
12638 /* Get name of field. */
12639 fieldname
= dwarf2_name (die
, cu
);
12640 if (fieldname
== NULL
)
12643 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12645 /* Only create a symbol if this is an external value.
12646 new_symbol checks this and puts the value in the global symbol
12647 table, which we want. If it is not external, new_symbol
12648 will try to put the value in cu->list_in_scope which is wrong. */
12649 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
12651 /* A static const member, not much different than an enum as far as
12652 we're concerned, except that we can support more types. */
12653 new_symbol (die
, NULL
, cu
);
12656 /* Get physical name. */
12657 physname
= dwarf2_physname (fieldname
, die
, cu
);
12659 /* The name is already allocated along with this objfile, so we don't
12660 need to duplicate it for the type. */
12661 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
12662 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12663 FIELD_NAME (*fp
) = fieldname
;
12665 else if (die
->tag
== DW_TAG_inheritance
)
12669 /* C++ base class field. */
12670 if (handle_data_member_location (die
, cu
, &offset
))
12671 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12672 FIELD_BITSIZE (*fp
) = 0;
12673 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12674 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
12675 fip
->nbaseclasses
++;
12679 /* Add a typedef defined in the scope of the FIP's class. */
12682 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
12683 struct dwarf2_cu
*cu
)
12685 struct typedef_field_list
*new_field
;
12686 struct typedef_field
*fp
;
12688 /* Allocate a new field list entry and link it in. */
12689 new_field
= XCNEW (struct typedef_field_list
);
12690 make_cleanup (xfree
, new_field
);
12692 gdb_assert (die
->tag
== DW_TAG_typedef
);
12694 fp
= &new_field
->field
;
12696 /* Get name of field. */
12697 fp
->name
= dwarf2_name (die
, cu
);
12698 if (fp
->name
== NULL
)
12701 fp
->type
= read_type_die (die
, cu
);
12703 new_field
->next
= fip
->typedef_field_list
;
12704 fip
->typedef_field_list
= new_field
;
12705 fip
->typedef_field_list_count
++;
12708 /* Create the vector of fields, and attach it to the type. */
12711 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
12712 struct dwarf2_cu
*cu
)
12714 int nfields
= fip
->nfields
;
12716 /* Record the field count, allocate space for the array of fields,
12717 and create blank accessibility bitfields if necessary. */
12718 TYPE_NFIELDS (type
) = nfields
;
12719 TYPE_FIELDS (type
) = (struct field
*)
12720 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
12721 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
12723 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
12725 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12727 TYPE_FIELD_PRIVATE_BITS (type
) =
12728 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12729 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
12731 TYPE_FIELD_PROTECTED_BITS (type
) =
12732 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12733 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
12735 TYPE_FIELD_IGNORE_BITS (type
) =
12736 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12737 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
12740 /* If the type has baseclasses, allocate and clear a bit vector for
12741 TYPE_FIELD_VIRTUAL_BITS. */
12742 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
12744 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
12745 unsigned char *pointer
;
12747 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12748 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
12749 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
12750 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
12751 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
12754 /* Copy the saved-up fields into the field vector. Start from the head of
12755 the list, adding to the tail of the field array, so that they end up in
12756 the same order in the array in which they were added to the list. */
12757 while (nfields
-- > 0)
12759 struct nextfield
*fieldp
;
12763 fieldp
= fip
->fields
;
12764 fip
->fields
= fieldp
->next
;
12768 fieldp
= fip
->baseclasses
;
12769 fip
->baseclasses
= fieldp
->next
;
12772 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
12773 switch (fieldp
->accessibility
)
12775 case DW_ACCESS_private
:
12776 if (cu
->language
!= language_ada
)
12777 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
12780 case DW_ACCESS_protected
:
12781 if (cu
->language
!= language_ada
)
12782 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
12785 case DW_ACCESS_public
:
12789 /* Unknown accessibility. Complain and treat it as public. */
12791 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
12792 fieldp
->accessibility
);
12796 if (nfields
< fip
->nbaseclasses
)
12798 switch (fieldp
->virtuality
)
12800 case DW_VIRTUALITY_virtual
:
12801 case DW_VIRTUALITY_pure_virtual
:
12802 if (cu
->language
== language_ada
)
12803 error (_("unexpected virtuality in component of Ada type"));
12804 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
12811 /* Return true if this member function is a constructor, false
12815 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
12817 const char *fieldname
;
12818 const char *type_name
;
12821 if (die
->parent
== NULL
)
12824 if (die
->parent
->tag
!= DW_TAG_structure_type
12825 && die
->parent
->tag
!= DW_TAG_union_type
12826 && die
->parent
->tag
!= DW_TAG_class_type
)
12829 fieldname
= dwarf2_name (die
, cu
);
12830 type_name
= dwarf2_name (die
->parent
, cu
);
12831 if (fieldname
== NULL
|| type_name
== NULL
)
12834 len
= strlen (fieldname
);
12835 return (strncmp (fieldname
, type_name
, len
) == 0
12836 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
12839 /* Add a member function to the proper fieldlist. */
12842 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
12843 struct type
*type
, struct dwarf2_cu
*cu
)
12845 struct objfile
*objfile
= cu
->objfile
;
12846 struct attribute
*attr
;
12847 struct fnfieldlist
*flp
;
12849 struct fn_field
*fnp
;
12850 const char *fieldname
;
12851 struct nextfnfield
*new_fnfield
;
12852 struct type
*this_type
;
12853 enum dwarf_access_attribute accessibility
;
12855 if (cu
->language
== language_ada
)
12856 error (_("unexpected member function in Ada type"));
12858 /* Get name of member function. */
12859 fieldname
= dwarf2_name (die
, cu
);
12860 if (fieldname
== NULL
)
12863 /* Look up member function name in fieldlist. */
12864 for (i
= 0; i
< fip
->nfnfields
; i
++)
12866 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
12870 /* Create new list element if necessary. */
12871 if (i
< fip
->nfnfields
)
12872 flp
= &fip
->fnfieldlists
[i
];
12875 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
12877 fip
->fnfieldlists
= (struct fnfieldlist
*)
12878 xrealloc (fip
->fnfieldlists
,
12879 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
12880 * sizeof (struct fnfieldlist
));
12881 if (fip
->nfnfields
== 0)
12882 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
12884 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
12885 flp
->name
= fieldname
;
12888 i
= fip
->nfnfields
++;
12891 /* Create a new member function field and chain it to the field list
12893 new_fnfield
= XNEW (struct nextfnfield
);
12894 make_cleanup (xfree
, new_fnfield
);
12895 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
12896 new_fnfield
->next
= flp
->head
;
12897 flp
->head
= new_fnfield
;
12900 /* Fill in the member function field info. */
12901 fnp
= &new_fnfield
->fnfield
;
12903 /* Delay processing of the physname until later. */
12904 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
12906 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
12911 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
12912 fnp
->physname
= physname
? physname
: "";
12915 fnp
->type
= alloc_type (objfile
);
12916 this_type
= read_type_die (die
, cu
);
12917 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
12919 int nparams
= TYPE_NFIELDS (this_type
);
12921 /* TYPE is the domain of this method, and THIS_TYPE is the type
12922 of the method itself (TYPE_CODE_METHOD). */
12923 smash_to_method_type (fnp
->type
, type
,
12924 TYPE_TARGET_TYPE (this_type
),
12925 TYPE_FIELDS (this_type
),
12926 TYPE_NFIELDS (this_type
),
12927 TYPE_VARARGS (this_type
));
12929 /* Handle static member functions.
12930 Dwarf2 has no clean way to discern C++ static and non-static
12931 member functions. G++ helps GDB by marking the first
12932 parameter for non-static member functions (which is the this
12933 pointer) as artificial. We obtain this information from
12934 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
12935 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
12936 fnp
->voffset
= VOFFSET_STATIC
;
12939 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
12940 dwarf2_full_name (fieldname
, die
, cu
));
12942 /* Get fcontext from DW_AT_containing_type if present. */
12943 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
12944 fnp
->fcontext
= die_containing_type (die
, cu
);
12946 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
12947 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
12949 /* Get accessibility. */
12950 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
12952 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
12954 accessibility
= dwarf2_default_access_attribute (die
, cu
);
12955 switch (accessibility
)
12957 case DW_ACCESS_private
:
12958 fnp
->is_private
= 1;
12960 case DW_ACCESS_protected
:
12961 fnp
->is_protected
= 1;
12965 /* Check for artificial methods. */
12966 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
12967 if (attr
&& DW_UNSND (attr
) != 0)
12968 fnp
->is_artificial
= 1;
12970 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
12972 /* Get index in virtual function table if it is a virtual member
12973 function. For older versions of GCC, this is an offset in the
12974 appropriate virtual table, as specified by DW_AT_containing_type.
12975 For everyone else, it is an expression to be evaluated relative
12976 to the object address. */
12978 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
12981 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
12983 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
12985 /* Old-style GCC. */
12986 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
12988 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
12989 || (DW_BLOCK (attr
)->size
> 1
12990 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
12991 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
12993 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
12994 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
12995 dwarf2_complex_location_expr_complaint ();
12997 fnp
->voffset
/= cu
->header
.addr_size
;
13001 dwarf2_complex_location_expr_complaint ();
13003 if (!fnp
->fcontext
)
13005 /* If there is no `this' field and no DW_AT_containing_type,
13006 we cannot actually find a base class context for the
13008 if (TYPE_NFIELDS (this_type
) == 0
13009 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
13011 complaint (&symfile_complaints
,
13012 _("cannot determine context for virtual member "
13013 "function \"%s\" (offset %d)"),
13014 fieldname
, die
->offset
.sect_off
);
13019 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
13023 else if (attr_form_is_section_offset (attr
))
13025 dwarf2_complex_location_expr_complaint ();
13029 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
13035 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
13036 if (attr
&& DW_UNSND (attr
))
13038 /* GCC does this, as of 2008-08-25; PR debug/37237. */
13039 complaint (&symfile_complaints
,
13040 _("Member function \"%s\" (offset %d) is virtual "
13041 "but the vtable offset is not specified"),
13042 fieldname
, die
->offset
.sect_off
);
13043 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13044 TYPE_CPLUS_DYNAMIC (type
) = 1;
13049 /* Create the vector of member function fields, and attach it to the type. */
13052 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
13053 struct dwarf2_cu
*cu
)
13055 struct fnfieldlist
*flp
;
13058 if (cu
->language
== language_ada
)
13059 error (_("unexpected member functions in Ada type"));
13061 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13062 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
13063 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
13065 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
13067 struct nextfnfield
*nfp
= flp
->head
;
13068 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
13071 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
13072 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
13073 fn_flp
->fn_fields
= (struct fn_field
*)
13074 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
13075 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
13076 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
13079 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
13082 /* Returns non-zero if NAME is the name of a vtable member in CU's
13083 language, zero otherwise. */
13085 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
13087 static const char vptr
[] = "_vptr";
13088 static const char vtable
[] = "vtable";
13090 /* Look for the C++ and Java forms of the vtable. */
13091 if ((cu
->language
== language_java
13092 && startswith (name
, vtable
))
13093 || (startswith (name
, vptr
)
13094 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
13100 /* GCC outputs unnamed structures that are really pointers to member
13101 functions, with the ABI-specified layout. If TYPE describes
13102 such a structure, smash it into a member function type.
13104 GCC shouldn't do this; it should just output pointer to member DIEs.
13105 This is GCC PR debug/28767. */
13108 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
13110 struct type
*pfn_type
, *self_type
, *new_type
;
13112 /* Check for a structure with no name and two children. */
13113 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
13116 /* Check for __pfn and __delta members. */
13117 if (TYPE_FIELD_NAME (type
, 0) == NULL
13118 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
13119 || TYPE_FIELD_NAME (type
, 1) == NULL
13120 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
13123 /* Find the type of the method. */
13124 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
13125 if (pfn_type
== NULL
13126 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
13127 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
13130 /* Look for the "this" argument. */
13131 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
13132 if (TYPE_NFIELDS (pfn_type
) == 0
13133 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
13134 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
13137 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
13138 new_type
= alloc_type (objfile
);
13139 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
13140 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
13141 TYPE_VARARGS (pfn_type
));
13142 smash_to_methodptr_type (type
, new_type
);
13145 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
13149 producer_is_icc (struct dwarf2_cu
*cu
)
13151 if (!cu
->checked_producer
)
13152 check_producer (cu
);
13154 return cu
->producer_is_icc
;
13157 /* Called when we find the DIE that starts a structure or union scope
13158 (definition) to create a type for the structure or union. Fill in
13159 the type's name and general properties; the members will not be
13160 processed until process_structure_scope. A symbol table entry for
13161 the type will also not be done until process_structure_scope (assuming
13162 the type has a name).
13164 NOTE: we need to call these functions regardless of whether or not the
13165 DIE has a DW_AT_name attribute, since it might be an anonymous
13166 structure or union. This gets the type entered into our set of
13167 user defined types. */
13169 static struct type
*
13170 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13172 struct objfile
*objfile
= cu
->objfile
;
13174 struct attribute
*attr
;
13177 /* If the definition of this type lives in .debug_types, read that type.
13178 Don't follow DW_AT_specification though, that will take us back up
13179 the chain and we want to go down. */
13180 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
13183 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13185 /* The type's CU may not be the same as CU.
13186 Ensure TYPE is recorded with CU in die_type_hash. */
13187 return set_die_type (die
, type
, cu
);
13190 type
= alloc_type (objfile
);
13191 INIT_CPLUS_SPECIFIC (type
);
13193 name
= dwarf2_name (die
, cu
);
13196 if (cu
->language
== language_cplus
13197 || cu
->language
== language_java
13198 || cu
->language
== language_d
13199 || cu
->language
== language_rust
)
13201 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
13203 /* dwarf2_full_name might have already finished building the DIE's
13204 type. If so, there is no need to continue. */
13205 if (get_die_type (die
, cu
) != NULL
)
13206 return get_die_type (die
, cu
);
13208 TYPE_TAG_NAME (type
) = full_name
;
13209 if (die
->tag
== DW_TAG_structure_type
13210 || die
->tag
== DW_TAG_class_type
)
13211 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13215 /* The name is already allocated along with this objfile, so
13216 we don't need to duplicate it for the type. */
13217 TYPE_TAG_NAME (type
) = name
;
13218 if (die
->tag
== DW_TAG_class_type
)
13219 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13223 if (die
->tag
== DW_TAG_structure_type
)
13225 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13227 else if (die
->tag
== DW_TAG_union_type
)
13229 TYPE_CODE (type
) = TYPE_CODE_UNION
;
13233 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13236 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
13237 TYPE_DECLARED_CLASS (type
) = 1;
13239 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13242 if (attr_form_is_constant (attr
))
13243 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13246 /* For the moment, dynamic type sizes are not supported
13247 by GDB's struct type. The actual size is determined
13248 on-demand when resolving the type of a given object,
13249 so set the type's length to zero for now. Otherwise,
13250 we record an expression as the length, and that expression
13251 could lead to a very large value, which could eventually
13252 lead to us trying to allocate that much memory when creating
13253 a value of that type. */
13254 TYPE_LENGTH (type
) = 0;
13259 TYPE_LENGTH (type
) = 0;
13262 if (producer_is_icc (cu
) && (TYPE_LENGTH (type
) == 0))
13264 /* ICC does not output the required DW_AT_declaration
13265 on incomplete types, but gives them a size of zero. */
13266 TYPE_STUB (type
) = 1;
13269 TYPE_STUB_SUPPORTED (type
) = 1;
13271 if (die_is_declaration (die
, cu
))
13272 TYPE_STUB (type
) = 1;
13273 else if (attr
== NULL
&& die
->child
== NULL
13274 && producer_is_realview (cu
->producer
))
13275 /* RealView does not output the required DW_AT_declaration
13276 on incomplete types. */
13277 TYPE_STUB (type
) = 1;
13279 /* We need to add the type field to the die immediately so we don't
13280 infinitely recurse when dealing with pointers to the structure
13281 type within the structure itself. */
13282 set_die_type (die
, type
, cu
);
13284 /* set_die_type should be already done. */
13285 set_descriptive_type (type
, die
, cu
);
13290 /* Finish creating a structure or union type, including filling in
13291 its members and creating a symbol for it. */
13294 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13296 struct objfile
*objfile
= cu
->objfile
;
13297 struct die_info
*child_die
;
13300 type
= get_die_type (die
, cu
);
13302 type
= read_structure_type (die
, cu
);
13304 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
13306 struct field_info fi
;
13307 VEC (symbolp
) *template_args
= NULL
;
13308 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
13310 memset (&fi
, 0, sizeof (struct field_info
));
13312 child_die
= die
->child
;
13314 while (child_die
&& child_die
->tag
)
13316 if (child_die
->tag
== DW_TAG_member
13317 || child_die
->tag
== DW_TAG_variable
)
13319 /* NOTE: carlton/2002-11-05: A C++ static data member
13320 should be a DW_TAG_member that is a declaration, but
13321 all versions of G++ as of this writing (so through at
13322 least 3.2.1) incorrectly generate DW_TAG_variable
13323 tags for them instead. */
13324 dwarf2_add_field (&fi
, child_die
, cu
);
13326 else if (child_die
->tag
== DW_TAG_subprogram
)
13328 /* Rust doesn't have member functions in the C++ sense.
13329 However, it does emit ordinary functions as children
13330 of a struct DIE. */
13331 if (cu
->language
== language_rust
)
13332 read_func_scope (child_die
, cu
);
13335 /* C++ member function. */
13336 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
13339 else if (child_die
->tag
== DW_TAG_inheritance
)
13341 /* C++ base class field. */
13342 dwarf2_add_field (&fi
, child_die
, cu
);
13344 else if (child_die
->tag
== DW_TAG_typedef
)
13345 dwarf2_add_typedef (&fi
, child_die
, cu
);
13346 else if (child_die
->tag
== DW_TAG_template_type_param
13347 || child_die
->tag
== DW_TAG_template_value_param
)
13349 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13352 VEC_safe_push (symbolp
, template_args
, arg
);
13355 child_die
= sibling_die (child_die
);
13358 /* Attach template arguments to type. */
13359 if (! VEC_empty (symbolp
, template_args
))
13361 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13362 TYPE_N_TEMPLATE_ARGUMENTS (type
)
13363 = VEC_length (symbolp
, template_args
);
13364 TYPE_TEMPLATE_ARGUMENTS (type
)
13365 = XOBNEWVEC (&objfile
->objfile_obstack
,
13367 TYPE_N_TEMPLATE_ARGUMENTS (type
));
13368 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
13369 VEC_address (symbolp
, template_args
),
13370 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
13371 * sizeof (struct symbol
*)));
13372 VEC_free (symbolp
, template_args
);
13375 /* Attach fields and member functions to the type. */
13377 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
13380 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
13382 /* Get the type which refers to the base class (possibly this
13383 class itself) which contains the vtable pointer for the current
13384 class from the DW_AT_containing_type attribute. This use of
13385 DW_AT_containing_type is a GNU extension. */
13387 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
13389 struct type
*t
= die_containing_type (die
, cu
);
13391 set_type_vptr_basetype (type
, t
);
13396 /* Our own class provides vtbl ptr. */
13397 for (i
= TYPE_NFIELDS (t
) - 1;
13398 i
>= TYPE_N_BASECLASSES (t
);
13401 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
13403 if (is_vtable_name (fieldname
, cu
))
13405 set_type_vptr_fieldno (type
, i
);
13410 /* Complain if virtual function table field not found. */
13411 if (i
< TYPE_N_BASECLASSES (t
))
13412 complaint (&symfile_complaints
,
13413 _("virtual function table pointer "
13414 "not found when defining class '%s'"),
13415 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
13420 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
13423 else if (cu
->producer
13424 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
13426 /* The IBM XLC compiler does not provide direct indication
13427 of the containing type, but the vtable pointer is
13428 always named __vfp. */
13432 for (i
= TYPE_NFIELDS (type
) - 1;
13433 i
>= TYPE_N_BASECLASSES (type
);
13436 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
13438 set_type_vptr_fieldno (type
, i
);
13439 set_type_vptr_basetype (type
, type
);
13446 /* Copy fi.typedef_field_list linked list elements content into the
13447 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
13448 if (fi
.typedef_field_list
)
13450 int i
= fi
.typedef_field_list_count
;
13452 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13453 TYPE_TYPEDEF_FIELD_ARRAY (type
)
13454 = ((struct typedef_field
*)
13455 TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
));
13456 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
13458 /* Reverse the list order to keep the debug info elements order. */
13461 struct typedef_field
*dest
, *src
;
13463 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
13464 src
= &fi
.typedef_field_list
->field
;
13465 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
13470 do_cleanups (back_to
);
13472 if (HAVE_CPLUS_STRUCT (type
))
13473 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
13476 quirk_gcc_member_function_pointer (type
, objfile
);
13478 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
13479 snapshots) has been known to create a die giving a declaration
13480 for a class that has, as a child, a die giving a definition for a
13481 nested class. So we have to process our children even if the
13482 current die is a declaration. Normally, of course, a declaration
13483 won't have any children at all. */
13485 child_die
= die
->child
;
13487 while (child_die
!= NULL
&& child_die
->tag
)
13489 if (child_die
->tag
== DW_TAG_member
13490 || child_die
->tag
== DW_TAG_variable
13491 || child_die
->tag
== DW_TAG_inheritance
13492 || child_die
->tag
== DW_TAG_template_value_param
13493 || child_die
->tag
== DW_TAG_template_type_param
)
13498 process_die (child_die
, cu
);
13500 child_die
= sibling_die (child_die
);
13503 /* Do not consider external references. According to the DWARF standard,
13504 these DIEs are identified by the fact that they have no byte_size
13505 attribute, and a declaration attribute. */
13506 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
13507 || !die_is_declaration (die
, cu
))
13508 new_symbol (die
, type
, cu
);
13511 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
13512 update TYPE using some information only available in DIE's children. */
13515 update_enumeration_type_from_children (struct die_info
*die
,
13517 struct dwarf2_cu
*cu
)
13519 struct obstack obstack
;
13520 struct die_info
*child_die
;
13521 int unsigned_enum
= 1;
13524 struct cleanup
*old_chain
;
13526 obstack_init (&obstack
);
13527 old_chain
= make_cleanup_obstack_free (&obstack
);
13529 for (child_die
= die
->child
;
13530 child_die
!= NULL
&& child_die
->tag
;
13531 child_die
= sibling_die (child_die
))
13533 struct attribute
*attr
;
13535 const gdb_byte
*bytes
;
13536 struct dwarf2_locexpr_baton
*baton
;
13539 if (child_die
->tag
!= DW_TAG_enumerator
)
13542 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
13546 name
= dwarf2_name (child_die
, cu
);
13548 name
= "<anonymous enumerator>";
13550 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
13551 &value
, &bytes
, &baton
);
13557 else if ((mask
& value
) != 0)
13562 /* If we already know that the enum type is neither unsigned, nor
13563 a flag type, no need to look at the rest of the enumerates. */
13564 if (!unsigned_enum
&& !flag_enum
)
13569 TYPE_UNSIGNED (type
) = 1;
13571 TYPE_FLAG_ENUM (type
) = 1;
13573 do_cleanups (old_chain
);
13576 /* Given a DW_AT_enumeration_type die, set its type. We do not
13577 complete the type's fields yet, or create any symbols. */
13579 static struct type
*
13580 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13582 struct objfile
*objfile
= cu
->objfile
;
13584 struct attribute
*attr
;
13587 /* If the definition of this type lives in .debug_types, read that type.
13588 Don't follow DW_AT_specification though, that will take us back up
13589 the chain and we want to go down. */
13590 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
13593 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13595 /* The type's CU may not be the same as CU.
13596 Ensure TYPE is recorded with CU in die_type_hash. */
13597 return set_die_type (die
, type
, cu
);
13600 type
= alloc_type (objfile
);
13602 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
13603 name
= dwarf2_full_name (NULL
, die
, cu
);
13605 TYPE_TAG_NAME (type
) = name
;
13607 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13610 struct type
*underlying_type
= die_type (die
, cu
);
13612 TYPE_TARGET_TYPE (type
) = underlying_type
;
13615 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13618 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13622 TYPE_LENGTH (type
) = 0;
13625 /* The enumeration DIE can be incomplete. In Ada, any type can be
13626 declared as private in the package spec, and then defined only
13627 inside the package body. Such types are known as Taft Amendment
13628 Types. When another package uses such a type, an incomplete DIE
13629 may be generated by the compiler. */
13630 if (die_is_declaration (die
, cu
))
13631 TYPE_STUB (type
) = 1;
13633 /* Finish the creation of this type by using the enum's children.
13634 We must call this even when the underlying type has been provided
13635 so that we can determine if we're looking at a "flag" enum. */
13636 update_enumeration_type_from_children (die
, type
, cu
);
13638 /* If this type has an underlying type that is not a stub, then we
13639 may use its attributes. We always use the "unsigned" attribute
13640 in this situation, because ordinarily we guess whether the type
13641 is unsigned -- but the guess can be wrong and the underlying type
13642 can tell us the reality. However, we defer to a local size
13643 attribute if one exists, because this lets the compiler override
13644 the underlying type if needed. */
13645 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
13647 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
13648 if (TYPE_LENGTH (type
) == 0)
13649 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
13652 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
13654 return set_die_type (die
, type
, cu
);
13657 /* Given a pointer to a die which begins an enumeration, process all
13658 the dies that define the members of the enumeration, and create the
13659 symbol for the enumeration type.
13661 NOTE: We reverse the order of the element list. */
13664 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13666 struct type
*this_type
;
13668 this_type
= get_die_type (die
, cu
);
13669 if (this_type
== NULL
)
13670 this_type
= read_enumeration_type (die
, cu
);
13672 if (die
->child
!= NULL
)
13674 struct die_info
*child_die
;
13675 struct symbol
*sym
;
13676 struct field
*fields
= NULL
;
13677 int num_fields
= 0;
13680 child_die
= die
->child
;
13681 while (child_die
&& child_die
->tag
)
13683 if (child_die
->tag
!= DW_TAG_enumerator
)
13685 process_die (child_die
, cu
);
13689 name
= dwarf2_name (child_die
, cu
);
13692 sym
= new_symbol (child_die
, this_type
, cu
);
13694 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
13696 fields
= (struct field
*)
13698 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
13699 * sizeof (struct field
));
13702 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
13703 FIELD_TYPE (fields
[num_fields
]) = NULL
;
13704 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
13705 FIELD_BITSIZE (fields
[num_fields
]) = 0;
13711 child_die
= sibling_die (child_die
);
13716 TYPE_NFIELDS (this_type
) = num_fields
;
13717 TYPE_FIELDS (this_type
) = (struct field
*)
13718 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
13719 memcpy (TYPE_FIELDS (this_type
), fields
,
13720 sizeof (struct field
) * num_fields
);
13725 /* If we are reading an enum from a .debug_types unit, and the enum
13726 is a declaration, and the enum is not the signatured type in the
13727 unit, then we do not want to add a symbol for it. Adding a
13728 symbol would in some cases obscure the true definition of the
13729 enum, giving users an incomplete type when the definition is
13730 actually available. Note that we do not want to do this for all
13731 enums which are just declarations, because C++0x allows forward
13732 enum declarations. */
13733 if (cu
->per_cu
->is_debug_types
13734 && die_is_declaration (die
, cu
))
13736 struct signatured_type
*sig_type
;
13738 sig_type
= (struct signatured_type
*) cu
->per_cu
;
13739 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
13740 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
13744 new_symbol (die
, this_type
, cu
);
13747 /* Extract all information from a DW_TAG_array_type DIE and put it in
13748 the DIE's type field. For now, this only handles one dimensional
13751 static struct type
*
13752 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13754 struct objfile
*objfile
= cu
->objfile
;
13755 struct die_info
*child_die
;
13757 struct type
*element_type
, *range_type
, *index_type
;
13758 struct type
**range_types
= NULL
;
13759 struct attribute
*attr
;
13761 struct cleanup
*back_to
;
13763 unsigned int bit_stride
= 0;
13765 element_type
= die_type (die
, cu
);
13767 /* The die_type call above may have already set the type for this DIE. */
13768 type
= get_die_type (die
, cu
);
13772 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
13774 bit_stride
= DW_UNSND (attr
) * 8;
13776 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
13778 bit_stride
= DW_UNSND (attr
);
13780 /* Irix 6.2 native cc creates array types without children for
13781 arrays with unspecified length. */
13782 if (die
->child
== NULL
)
13784 index_type
= objfile_type (objfile
)->builtin_int
;
13785 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
13786 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
13788 return set_die_type (die
, type
, cu
);
13791 back_to
= make_cleanup (null_cleanup
, NULL
);
13792 child_die
= die
->child
;
13793 while (child_die
&& child_die
->tag
)
13795 if (child_die
->tag
== DW_TAG_subrange_type
)
13797 struct type
*child_type
= read_type_die (child_die
, cu
);
13799 if (child_type
!= NULL
)
13801 /* The range type was succesfully read. Save it for the
13802 array type creation. */
13803 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
13805 range_types
= (struct type
**)
13806 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
13807 * sizeof (struct type
*));
13809 make_cleanup (free_current_contents
, &range_types
);
13811 range_types
[ndim
++] = child_type
;
13814 child_die
= sibling_die (child_die
);
13817 /* Dwarf2 dimensions are output from left to right, create the
13818 necessary array types in backwards order. */
13820 type
= element_type
;
13822 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
13827 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
13833 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
13837 /* Understand Dwarf2 support for vector types (like they occur on
13838 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
13839 array type. This is not part of the Dwarf2/3 standard yet, but a
13840 custom vendor extension. The main difference between a regular
13841 array and the vector variant is that vectors are passed by value
13843 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
13845 make_vector_type (type
);
13847 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
13848 implementation may choose to implement triple vectors using this
13850 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13853 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
13854 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13856 complaint (&symfile_complaints
,
13857 _("DW_AT_byte_size for array type smaller "
13858 "than the total size of elements"));
13861 name
= dwarf2_name (die
, cu
);
13863 TYPE_NAME (type
) = name
;
13865 /* Install the type in the die. */
13866 set_die_type (die
, type
, cu
);
13868 /* set_die_type should be already done. */
13869 set_descriptive_type (type
, die
, cu
);
13871 do_cleanups (back_to
);
13876 static enum dwarf_array_dim_ordering
13877 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
13879 struct attribute
*attr
;
13881 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
13884 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
13886 /* GNU F77 is a special case, as at 08/2004 array type info is the
13887 opposite order to the dwarf2 specification, but data is still
13888 laid out as per normal fortran.
13890 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
13891 version checking. */
13893 if (cu
->language
== language_fortran
13894 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
13896 return DW_ORD_row_major
;
13899 switch (cu
->language_defn
->la_array_ordering
)
13901 case array_column_major
:
13902 return DW_ORD_col_major
;
13903 case array_row_major
:
13905 return DW_ORD_row_major
;
13909 /* Extract all information from a DW_TAG_set_type DIE and put it in
13910 the DIE's type field. */
13912 static struct type
*
13913 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13915 struct type
*domain_type
, *set_type
;
13916 struct attribute
*attr
;
13918 domain_type
= die_type (die
, cu
);
13920 /* The die_type call above may have already set the type for this DIE. */
13921 set_type
= get_die_type (die
, cu
);
13925 set_type
= create_set_type (NULL
, domain_type
);
13927 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13929 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
13931 return set_die_type (die
, set_type
, cu
);
13934 /* A helper for read_common_block that creates a locexpr baton.
13935 SYM is the symbol which we are marking as computed.
13936 COMMON_DIE is the DIE for the common block.
13937 COMMON_LOC is the location expression attribute for the common
13939 MEMBER_LOC is the location expression attribute for the particular
13940 member of the common block that we are processing.
13941 CU is the CU from which the above come. */
13944 mark_common_block_symbol_computed (struct symbol
*sym
,
13945 struct die_info
*common_die
,
13946 struct attribute
*common_loc
,
13947 struct attribute
*member_loc
,
13948 struct dwarf2_cu
*cu
)
13950 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13951 struct dwarf2_locexpr_baton
*baton
;
13953 unsigned int cu_off
;
13954 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
13955 LONGEST offset
= 0;
13957 gdb_assert (common_loc
&& member_loc
);
13958 gdb_assert (attr_form_is_block (common_loc
));
13959 gdb_assert (attr_form_is_block (member_loc
)
13960 || attr_form_is_constant (member_loc
));
13962 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13963 baton
->per_cu
= cu
->per_cu
;
13964 gdb_assert (baton
->per_cu
);
13966 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
13968 if (attr_form_is_constant (member_loc
))
13970 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
13971 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
13974 baton
->size
+= DW_BLOCK (member_loc
)->size
;
13976 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
13979 *ptr
++ = DW_OP_call4
;
13980 cu_off
= common_die
->offset
.sect_off
- cu
->per_cu
->offset
.sect_off
;
13981 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
13984 if (attr_form_is_constant (member_loc
))
13986 *ptr
++ = DW_OP_addr
;
13987 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
13988 ptr
+= cu
->header
.addr_size
;
13992 /* We have to copy the data here, because DW_OP_call4 will only
13993 use a DW_AT_location attribute. */
13994 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
13995 ptr
+= DW_BLOCK (member_loc
)->size
;
13998 *ptr
++ = DW_OP_plus
;
13999 gdb_assert (ptr
- baton
->data
== baton
->size
);
14001 SYMBOL_LOCATION_BATON (sym
) = baton
;
14002 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
14005 /* Create appropriate locally-scoped variables for all the
14006 DW_TAG_common_block entries. Also create a struct common_block
14007 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
14008 is used to sepate the common blocks name namespace from regular
14012 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
14014 struct attribute
*attr
;
14016 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14019 /* Support the .debug_loc offsets. */
14020 if (attr_form_is_block (attr
))
14024 else if (attr_form_is_section_offset (attr
))
14026 dwarf2_complex_location_expr_complaint ();
14031 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
14032 "common block member");
14037 if (die
->child
!= NULL
)
14039 struct objfile
*objfile
= cu
->objfile
;
14040 struct die_info
*child_die
;
14041 size_t n_entries
= 0, size
;
14042 struct common_block
*common_block
;
14043 struct symbol
*sym
;
14045 for (child_die
= die
->child
;
14046 child_die
&& child_die
->tag
;
14047 child_die
= sibling_die (child_die
))
14050 size
= (sizeof (struct common_block
)
14051 + (n_entries
- 1) * sizeof (struct symbol
*));
14053 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
14055 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
14056 common_block
->n_entries
= 0;
14058 for (child_die
= die
->child
;
14059 child_die
&& child_die
->tag
;
14060 child_die
= sibling_die (child_die
))
14062 /* Create the symbol in the DW_TAG_common_block block in the current
14064 sym
= new_symbol (child_die
, NULL
, cu
);
14067 struct attribute
*member_loc
;
14069 common_block
->contents
[common_block
->n_entries
++] = sym
;
14071 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
14075 /* GDB has handled this for a long time, but it is
14076 not specified by DWARF. It seems to have been
14077 emitted by gfortran at least as recently as:
14078 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
14079 complaint (&symfile_complaints
,
14080 _("Variable in common block has "
14081 "DW_AT_data_member_location "
14082 "- DIE at 0x%x [in module %s]"),
14083 child_die
->offset
.sect_off
,
14084 objfile_name (cu
->objfile
));
14086 if (attr_form_is_section_offset (member_loc
))
14087 dwarf2_complex_location_expr_complaint ();
14088 else if (attr_form_is_constant (member_loc
)
14089 || attr_form_is_block (member_loc
))
14092 mark_common_block_symbol_computed (sym
, die
, attr
,
14096 dwarf2_complex_location_expr_complaint ();
14101 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
14102 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
14106 /* Create a type for a C++ namespace. */
14108 static struct type
*
14109 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14111 struct objfile
*objfile
= cu
->objfile
;
14112 const char *previous_prefix
, *name
;
14116 /* For extensions, reuse the type of the original namespace. */
14117 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
14119 struct die_info
*ext_die
;
14120 struct dwarf2_cu
*ext_cu
= cu
;
14122 ext_die
= dwarf2_extension (die
, &ext_cu
);
14123 type
= read_type_die (ext_die
, ext_cu
);
14125 /* EXT_CU may not be the same as CU.
14126 Ensure TYPE is recorded with CU in die_type_hash. */
14127 return set_die_type (die
, type
, cu
);
14130 name
= namespace_name (die
, &is_anonymous
, cu
);
14132 /* Now build the name of the current namespace. */
14134 previous_prefix
= determine_prefix (die
, cu
);
14135 if (previous_prefix
[0] != '\0')
14136 name
= typename_concat (&objfile
->objfile_obstack
,
14137 previous_prefix
, name
, 0, cu
);
14139 /* Create the type. */
14140 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
14141 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14143 return set_die_type (die
, type
, cu
);
14146 /* Read a namespace scope. */
14149 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
14151 struct objfile
*objfile
= cu
->objfile
;
14154 /* Add a symbol associated to this if we haven't seen the namespace
14155 before. Also, add a using directive if it's an anonymous
14158 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
14162 type
= read_type_die (die
, cu
);
14163 new_symbol (die
, type
, cu
);
14165 namespace_name (die
, &is_anonymous
, cu
);
14168 const char *previous_prefix
= determine_prefix (die
, cu
);
14170 add_using_directive (using_directives (cu
->language
),
14171 previous_prefix
, TYPE_NAME (type
), NULL
,
14172 NULL
, NULL
, 0, &objfile
->objfile_obstack
);
14176 if (die
->child
!= NULL
)
14178 struct die_info
*child_die
= die
->child
;
14180 while (child_die
&& child_die
->tag
)
14182 process_die (child_die
, cu
);
14183 child_die
= sibling_die (child_die
);
14188 /* Read a Fortran module as type. This DIE can be only a declaration used for
14189 imported module. Still we need that type as local Fortran "use ... only"
14190 declaration imports depend on the created type in determine_prefix. */
14192 static struct type
*
14193 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14195 struct objfile
*objfile
= cu
->objfile
;
14196 const char *module_name
;
14199 module_name
= dwarf2_name (die
, cu
);
14201 complaint (&symfile_complaints
,
14202 _("DW_TAG_module has no name, offset 0x%x"),
14203 die
->offset
.sect_off
);
14204 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
14206 /* determine_prefix uses TYPE_TAG_NAME. */
14207 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14209 return set_die_type (die
, type
, cu
);
14212 /* Read a Fortran module. */
14215 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
14217 struct die_info
*child_die
= die
->child
;
14220 type
= read_type_die (die
, cu
);
14221 new_symbol (die
, type
, cu
);
14223 while (child_die
&& child_die
->tag
)
14225 process_die (child_die
, cu
);
14226 child_die
= sibling_die (child_die
);
14230 /* Return the name of the namespace represented by DIE. Set
14231 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
14234 static const char *
14235 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
14237 struct die_info
*current_die
;
14238 const char *name
= NULL
;
14240 /* Loop through the extensions until we find a name. */
14242 for (current_die
= die
;
14243 current_die
!= NULL
;
14244 current_die
= dwarf2_extension (die
, &cu
))
14246 /* We don't use dwarf2_name here so that we can detect the absence
14247 of a name -> anonymous namespace. */
14248 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
14254 /* Is it an anonymous namespace? */
14256 *is_anonymous
= (name
== NULL
);
14258 name
= CP_ANONYMOUS_NAMESPACE_STR
;
14263 /* Extract all information from a DW_TAG_pointer_type DIE and add to
14264 the user defined type vector. */
14266 static struct type
*
14267 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14269 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
14270 struct comp_unit_head
*cu_header
= &cu
->header
;
14272 struct attribute
*attr_byte_size
;
14273 struct attribute
*attr_address_class
;
14274 int byte_size
, addr_class
;
14275 struct type
*target_type
;
14277 target_type
= die_type (die
, cu
);
14279 /* The die_type call above may have already set the type for this DIE. */
14280 type
= get_die_type (die
, cu
);
14284 type
= lookup_pointer_type (target_type
);
14286 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14287 if (attr_byte_size
)
14288 byte_size
= DW_UNSND (attr_byte_size
);
14290 byte_size
= cu_header
->addr_size
;
14292 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
14293 if (attr_address_class
)
14294 addr_class
= DW_UNSND (attr_address_class
);
14296 addr_class
= DW_ADDR_none
;
14298 /* If the pointer size or address class is different than the
14299 default, create a type variant marked as such and set the
14300 length accordingly. */
14301 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
14303 if (gdbarch_address_class_type_flags_p (gdbarch
))
14307 type_flags
= gdbarch_address_class_type_flags
14308 (gdbarch
, byte_size
, addr_class
);
14309 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
14311 type
= make_type_with_address_space (type
, type_flags
);
14313 else if (TYPE_LENGTH (type
) != byte_size
)
14315 complaint (&symfile_complaints
,
14316 _("invalid pointer size %d"), byte_size
);
14320 /* Should we also complain about unhandled address classes? */
14324 TYPE_LENGTH (type
) = byte_size
;
14325 return set_die_type (die
, type
, cu
);
14328 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
14329 the user defined type vector. */
14331 static struct type
*
14332 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14335 struct type
*to_type
;
14336 struct type
*domain
;
14338 to_type
= die_type (die
, cu
);
14339 domain
= die_containing_type (die
, cu
);
14341 /* The calls above may have already set the type for this DIE. */
14342 type
= get_die_type (die
, cu
);
14346 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
14347 type
= lookup_methodptr_type (to_type
);
14348 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
14350 struct type
*new_type
= alloc_type (cu
->objfile
);
14352 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
14353 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
14354 TYPE_VARARGS (to_type
));
14355 type
= lookup_methodptr_type (new_type
);
14358 type
= lookup_memberptr_type (to_type
, domain
);
14360 return set_die_type (die
, type
, cu
);
14363 /* Extract all information from a DW_TAG_reference_type DIE and add to
14364 the user defined type vector. */
14366 static struct type
*
14367 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14369 struct comp_unit_head
*cu_header
= &cu
->header
;
14370 struct type
*type
, *target_type
;
14371 struct attribute
*attr
;
14373 target_type
= die_type (die
, cu
);
14375 /* The die_type call above may have already set the type for this DIE. */
14376 type
= get_die_type (die
, cu
);
14380 type
= lookup_reference_type (target_type
);
14381 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14384 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14388 TYPE_LENGTH (type
) = cu_header
->addr_size
;
14390 return set_die_type (die
, type
, cu
);
14393 /* Add the given cv-qualifiers to the element type of the array. GCC
14394 outputs DWARF type qualifiers that apply to an array, not the
14395 element type. But GDB relies on the array element type to carry
14396 the cv-qualifiers. This mimics section 6.7.3 of the C99
14399 static struct type
*
14400 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
14401 struct type
*base_type
, int cnst
, int voltl
)
14403 struct type
*el_type
, *inner_array
;
14405 base_type
= copy_type (base_type
);
14406 inner_array
= base_type
;
14408 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
14410 TYPE_TARGET_TYPE (inner_array
) =
14411 copy_type (TYPE_TARGET_TYPE (inner_array
));
14412 inner_array
= TYPE_TARGET_TYPE (inner_array
);
14415 el_type
= TYPE_TARGET_TYPE (inner_array
);
14416 cnst
|= TYPE_CONST (el_type
);
14417 voltl
|= TYPE_VOLATILE (el_type
);
14418 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
14420 return set_die_type (die
, base_type
, cu
);
14423 static struct type
*
14424 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14426 struct type
*base_type
, *cv_type
;
14428 base_type
= die_type (die
, cu
);
14430 /* The die_type call above may have already set the type for this DIE. */
14431 cv_type
= get_die_type (die
, cu
);
14435 /* In case the const qualifier is applied to an array type, the element type
14436 is so qualified, not the array type (section 6.7.3 of C99). */
14437 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
14438 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
14440 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
14441 return set_die_type (die
, cv_type
, cu
);
14444 static struct type
*
14445 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14447 struct type
*base_type
, *cv_type
;
14449 base_type
= die_type (die
, cu
);
14451 /* The die_type call above may have already set the type for this DIE. */
14452 cv_type
= get_die_type (die
, cu
);
14456 /* In case the volatile qualifier is applied to an array type, the
14457 element type is so qualified, not the array type (section 6.7.3
14459 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
14460 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
14462 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
14463 return set_die_type (die
, cv_type
, cu
);
14466 /* Handle DW_TAG_restrict_type. */
14468 static struct type
*
14469 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14471 struct type
*base_type
, *cv_type
;
14473 base_type
= die_type (die
, cu
);
14475 /* The die_type call above may have already set the type for this DIE. */
14476 cv_type
= get_die_type (die
, cu
);
14480 cv_type
= make_restrict_type (base_type
);
14481 return set_die_type (die
, cv_type
, cu
);
14484 /* Handle DW_TAG_atomic_type. */
14486 static struct type
*
14487 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14489 struct type
*base_type
, *cv_type
;
14491 base_type
= die_type (die
, cu
);
14493 /* The die_type call above may have already set the type for this DIE. */
14494 cv_type
= get_die_type (die
, cu
);
14498 cv_type
= make_atomic_type (base_type
);
14499 return set_die_type (die
, cv_type
, cu
);
14502 /* Extract all information from a DW_TAG_string_type DIE and add to
14503 the user defined type vector. It isn't really a user defined type,
14504 but it behaves like one, with other DIE's using an AT_user_def_type
14505 attribute to reference it. */
14507 static struct type
*
14508 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14510 struct objfile
*objfile
= cu
->objfile
;
14511 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14512 struct type
*type
, *range_type
, *index_type
, *char_type
;
14513 struct attribute
*attr
;
14514 unsigned int length
;
14516 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
14519 length
= DW_UNSND (attr
);
14523 /* Check for the DW_AT_byte_size attribute. */
14524 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14527 length
= DW_UNSND (attr
);
14535 index_type
= objfile_type (objfile
)->builtin_int
;
14536 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
14537 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
14538 type
= create_string_type (NULL
, char_type
, range_type
);
14540 return set_die_type (die
, type
, cu
);
14543 /* Assuming that DIE corresponds to a function, returns nonzero
14544 if the function is prototyped. */
14547 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
14549 struct attribute
*attr
;
14551 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
14552 if (attr
&& (DW_UNSND (attr
) != 0))
14555 /* The DWARF standard implies that the DW_AT_prototyped attribute
14556 is only meaninful for C, but the concept also extends to other
14557 languages that allow unprototyped functions (Eg: Objective C).
14558 For all other languages, assume that functions are always
14560 if (cu
->language
!= language_c
14561 && cu
->language
!= language_objc
14562 && cu
->language
!= language_opencl
)
14565 /* RealView does not emit DW_AT_prototyped. We can not distinguish
14566 prototyped and unprototyped functions; default to prototyped,
14567 since that is more common in modern code (and RealView warns
14568 about unprototyped functions). */
14569 if (producer_is_realview (cu
->producer
))
14575 /* Handle DIES due to C code like:
14579 int (*funcp)(int a, long l);
14583 ('funcp' generates a DW_TAG_subroutine_type DIE). */
14585 static struct type
*
14586 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14588 struct objfile
*objfile
= cu
->objfile
;
14589 struct type
*type
; /* Type that this function returns. */
14590 struct type
*ftype
; /* Function that returns above type. */
14591 struct attribute
*attr
;
14593 type
= die_type (die
, cu
);
14595 /* The die_type call above may have already set the type for this DIE. */
14596 ftype
= get_die_type (die
, cu
);
14600 ftype
= lookup_function_type (type
);
14602 if (prototyped_function_p (die
, cu
))
14603 TYPE_PROTOTYPED (ftype
) = 1;
14605 /* Store the calling convention in the type if it's available in
14606 the subroutine die. Otherwise set the calling convention to
14607 the default value DW_CC_normal. */
14608 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
14610 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
14611 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
14612 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
14614 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
14616 /* Record whether the function returns normally to its caller or not
14617 if the DWARF producer set that information. */
14618 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
14619 if (attr
&& (DW_UNSND (attr
) != 0))
14620 TYPE_NO_RETURN (ftype
) = 1;
14622 /* We need to add the subroutine type to the die immediately so
14623 we don't infinitely recurse when dealing with parameters
14624 declared as the same subroutine type. */
14625 set_die_type (die
, ftype
, cu
);
14627 if (die
->child
!= NULL
)
14629 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
14630 struct die_info
*child_die
;
14631 int nparams
, iparams
;
14633 /* Count the number of parameters.
14634 FIXME: GDB currently ignores vararg functions, but knows about
14635 vararg member functions. */
14637 child_die
= die
->child
;
14638 while (child_die
&& child_die
->tag
)
14640 if (child_die
->tag
== DW_TAG_formal_parameter
)
14642 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
14643 TYPE_VARARGS (ftype
) = 1;
14644 child_die
= sibling_die (child_die
);
14647 /* Allocate storage for parameters and fill them in. */
14648 TYPE_NFIELDS (ftype
) = nparams
;
14649 TYPE_FIELDS (ftype
) = (struct field
*)
14650 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
14652 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
14653 even if we error out during the parameters reading below. */
14654 for (iparams
= 0; iparams
< nparams
; iparams
++)
14655 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
14658 child_die
= die
->child
;
14659 while (child_die
&& child_die
->tag
)
14661 if (child_die
->tag
== DW_TAG_formal_parameter
)
14663 struct type
*arg_type
;
14665 /* DWARF version 2 has no clean way to discern C++
14666 static and non-static member functions. G++ helps
14667 GDB by marking the first parameter for non-static
14668 member functions (which is the this pointer) as
14669 artificial. We pass this information to
14670 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
14672 DWARF version 3 added DW_AT_object_pointer, which GCC
14673 4.5 does not yet generate. */
14674 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
14676 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
14679 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
14681 /* GCC/43521: In java, the formal parameter
14682 "this" is sometimes not marked with DW_AT_artificial. */
14683 if (cu
->language
== language_java
)
14685 const char *name
= dwarf2_name (child_die
, cu
);
14687 if (name
&& !strcmp (name
, "this"))
14688 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
14691 arg_type
= die_type (child_die
, cu
);
14693 /* RealView does not mark THIS as const, which the testsuite
14694 expects. GCC marks THIS as const in method definitions,
14695 but not in the class specifications (GCC PR 43053). */
14696 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
14697 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
14700 struct dwarf2_cu
*arg_cu
= cu
;
14701 const char *name
= dwarf2_name (child_die
, cu
);
14703 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
14706 /* If the compiler emits this, use it. */
14707 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
14710 else if (name
&& strcmp (name
, "this") == 0)
14711 /* Function definitions will have the argument names. */
14713 else if (name
== NULL
&& iparams
== 0)
14714 /* Declarations may not have the names, so like
14715 elsewhere in GDB, assume an artificial first
14716 argument is "this". */
14720 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
14724 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
14727 child_die
= sibling_die (child_die
);
14734 static struct type
*
14735 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
14737 struct objfile
*objfile
= cu
->objfile
;
14738 const char *name
= NULL
;
14739 struct type
*this_type
, *target_type
;
14741 name
= dwarf2_full_name (NULL
, die
, cu
);
14742 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
14743 TYPE_TARGET_STUB (this_type
) = 1;
14744 set_die_type (die
, this_type
, cu
);
14745 target_type
= die_type (die
, cu
);
14746 if (target_type
!= this_type
)
14747 TYPE_TARGET_TYPE (this_type
) = target_type
;
14750 /* Self-referential typedefs are, it seems, not allowed by the DWARF
14751 spec and cause infinite loops in GDB. */
14752 complaint (&symfile_complaints
,
14753 _("Self-referential DW_TAG_typedef "
14754 "- DIE at 0x%x [in module %s]"),
14755 die
->offset
.sect_off
, objfile_name (objfile
));
14756 TYPE_TARGET_TYPE (this_type
) = NULL
;
14761 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
14762 (which may be different from NAME) to the architecture back-end to allow
14763 it to guess the correct format if necessary. */
14765 static struct type
*
14766 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
14767 const char *name_hint
)
14769 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14770 const struct floatformat
**format
;
14773 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
14775 type
= init_float_type (objfile
, bits
, name
, format
);
14777 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
/ TARGET_CHAR_BIT
, name
);
14782 /* Find a representation of a given base type and install
14783 it in the TYPE field of the die. */
14785 static struct type
*
14786 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14788 struct objfile
*objfile
= cu
->objfile
;
14790 struct attribute
*attr
;
14791 int encoding
= 0, bits
= 0;
14794 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
14797 encoding
= DW_UNSND (attr
);
14799 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14802 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
14804 name
= dwarf2_name (die
, cu
);
14807 complaint (&symfile_complaints
,
14808 _("DW_AT_name missing from DW_TAG_base_type"));
14813 case DW_ATE_address
:
14814 /* Turn DW_ATE_address into a void * pointer. */
14815 type
= init_type (objfile
, TYPE_CODE_VOID
, 1, NULL
);
14816 type
= init_pointer_type (objfile
, bits
, name
, type
);
14818 case DW_ATE_boolean
:
14819 type
= init_boolean_type (objfile
, bits
, 1, name
);
14821 case DW_ATE_complex_float
:
14822 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
14823 type
= init_complex_type (objfile
, name
, type
);
14825 case DW_ATE_decimal_float
:
14826 type
= init_decfloat_type (objfile
, bits
, name
);
14829 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
14831 case DW_ATE_signed
:
14832 type
= init_integer_type (objfile
, bits
, 0, name
);
14834 case DW_ATE_unsigned
:
14835 if (cu
->language
== language_fortran
14837 && startswith (name
, "character("))
14838 type
= init_character_type (objfile
, bits
, 1, name
);
14840 type
= init_integer_type (objfile
, bits
, 1, name
);
14842 case DW_ATE_signed_char
:
14843 if (cu
->language
== language_ada
|| cu
->language
== language_m2
14844 || cu
->language
== language_pascal
14845 || cu
->language
== language_fortran
)
14846 type
= init_character_type (objfile
, bits
, 0, name
);
14848 type
= init_integer_type (objfile
, bits
, 0, name
);
14850 case DW_ATE_unsigned_char
:
14851 if (cu
->language
== language_ada
|| cu
->language
== language_m2
14852 || cu
->language
== language_pascal
14853 || cu
->language
== language_fortran
14854 || cu
->language
== language_rust
)
14855 type
= init_character_type (objfile
, bits
, 1, name
);
14857 type
= init_integer_type (objfile
, bits
, 1, name
);
14860 /* We just treat this as an integer and then recognize the
14861 type by name elsewhere. */
14862 type
= init_integer_type (objfile
, bits
, 0, name
);
14866 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
14867 dwarf_type_encoding_name (encoding
));
14868 type
= init_type (objfile
, TYPE_CODE_ERROR
,
14869 bits
/ TARGET_CHAR_BIT
, name
);
14873 if (name
&& strcmp (name
, "char") == 0)
14874 TYPE_NOSIGN (type
) = 1;
14876 return set_die_type (die
, type
, cu
);
14879 /* Parse dwarf attribute if it's a block, reference or constant and put the
14880 resulting value of the attribute into struct bound_prop.
14881 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
14884 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
14885 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
14887 struct dwarf2_property_baton
*baton
;
14888 struct obstack
*obstack
= &cu
->objfile
->objfile_obstack
;
14890 if (attr
== NULL
|| prop
== NULL
)
14893 if (attr_form_is_block (attr
))
14895 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
14896 baton
->referenced_type
= NULL
;
14897 baton
->locexpr
.per_cu
= cu
->per_cu
;
14898 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
14899 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
14900 prop
->data
.baton
= baton
;
14901 prop
->kind
= PROP_LOCEXPR
;
14902 gdb_assert (prop
->data
.baton
!= NULL
);
14904 else if (attr_form_is_ref (attr
))
14906 struct dwarf2_cu
*target_cu
= cu
;
14907 struct die_info
*target_die
;
14908 struct attribute
*target_attr
;
14910 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14911 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
14912 if (target_attr
== NULL
)
14913 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
14915 if (target_attr
== NULL
)
14918 switch (target_attr
->name
)
14920 case DW_AT_location
:
14921 if (attr_form_is_section_offset (target_attr
))
14923 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
14924 baton
->referenced_type
= die_type (target_die
, target_cu
);
14925 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
14926 prop
->data
.baton
= baton
;
14927 prop
->kind
= PROP_LOCLIST
;
14928 gdb_assert (prop
->data
.baton
!= NULL
);
14930 else if (attr_form_is_block (target_attr
))
14932 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
14933 baton
->referenced_type
= die_type (target_die
, target_cu
);
14934 baton
->locexpr
.per_cu
= cu
->per_cu
;
14935 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
14936 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
14937 prop
->data
.baton
= baton
;
14938 prop
->kind
= PROP_LOCEXPR
;
14939 gdb_assert (prop
->data
.baton
!= NULL
);
14943 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
14944 "dynamic property");
14948 case DW_AT_data_member_location
:
14952 if (!handle_data_member_location (target_die
, target_cu
,
14956 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
14957 baton
->referenced_type
= read_type_die (target_die
->parent
,
14959 baton
->offset_info
.offset
= offset
;
14960 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
14961 prop
->data
.baton
= baton
;
14962 prop
->kind
= PROP_ADDR_OFFSET
;
14967 else if (attr_form_is_constant (attr
))
14969 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
14970 prop
->kind
= PROP_CONST
;
14974 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
14975 dwarf2_name (die
, cu
));
14982 /* Read the given DW_AT_subrange DIE. */
14984 static struct type
*
14985 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14987 struct type
*base_type
, *orig_base_type
;
14988 struct type
*range_type
;
14989 struct attribute
*attr
;
14990 struct dynamic_prop low
, high
;
14991 int low_default_is_valid
;
14992 int high_bound_is_count
= 0;
14994 LONGEST negative_mask
;
14996 orig_base_type
= die_type (die
, cu
);
14997 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
14998 whereas the real type might be. So, we use ORIG_BASE_TYPE when
14999 creating the range type, but we use the result of check_typedef
15000 when examining properties of the type. */
15001 base_type
= check_typedef (orig_base_type
);
15003 /* The die_type call above may have already set the type for this DIE. */
15004 range_type
= get_die_type (die
, cu
);
15008 low
.kind
= PROP_CONST
;
15009 high
.kind
= PROP_CONST
;
15010 high
.data
.const_val
= 0;
15012 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
15013 omitting DW_AT_lower_bound. */
15014 switch (cu
->language
)
15017 case language_cplus
:
15018 low
.data
.const_val
= 0;
15019 low_default_is_valid
= 1;
15021 case language_fortran
:
15022 low
.data
.const_val
= 1;
15023 low_default_is_valid
= 1;
15026 case language_java
:
15027 case language_objc
:
15028 case language_rust
:
15029 low
.data
.const_val
= 0;
15030 low_default_is_valid
= (cu
->header
.version
>= 4);
15034 case language_pascal
:
15035 low
.data
.const_val
= 1;
15036 low_default_is_valid
= (cu
->header
.version
>= 4);
15039 low
.data
.const_val
= 0;
15040 low_default_is_valid
= 0;
15044 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
15046 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
15047 else if (!low_default_is_valid
)
15048 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
15049 "- DIE at 0x%x [in module %s]"),
15050 die
->offset
.sect_off
, objfile_name (cu
->objfile
));
15052 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
15053 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
15055 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
15056 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
15058 /* If bounds are constant do the final calculation here. */
15059 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
15060 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
15062 high_bound_is_count
= 1;
15066 /* Dwarf-2 specifications explicitly allows to create subrange types
15067 without specifying a base type.
15068 In that case, the base type must be set to the type of
15069 the lower bound, upper bound or count, in that order, if any of these
15070 three attributes references an object that has a type.
15071 If no base type is found, the Dwarf-2 specifications say that
15072 a signed integer type of size equal to the size of an address should
15074 For the following C code: `extern char gdb_int [];'
15075 GCC produces an empty range DIE.
15076 FIXME: muller/2010-05-28: Possible references to object for low bound,
15077 high bound or count are not yet handled by this code. */
15078 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
15080 struct objfile
*objfile
= cu
->objfile
;
15081 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15082 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
15083 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
15085 /* Test "int", "long int", and "long long int" objfile types,
15086 and select the first one having a size above or equal to the
15087 architecture address size. */
15088 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15089 base_type
= int_type
;
15092 int_type
= objfile_type (objfile
)->builtin_long
;
15093 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15094 base_type
= int_type
;
15097 int_type
= objfile_type (objfile
)->builtin_long_long
;
15098 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15099 base_type
= int_type
;
15104 /* Normally, the DWARF producers are expected to use a signed
15105 constant form (Eg. DW_FORM_sdata) to express negative bounds.
15106 But this is unfortunately not always the case, as witnessed
15107 with GCC, for instance, where the ambiguous DW_FORM_dataN form
15108 is used instead. To work around that ambiguity, we treat
15109 the bounds as signed, and thus sign-extend their values, when
15110 the base type is signed. */
15112 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
15113 if (low
.kind
== PROP_CONST
15114 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
15115 low
.data
.const_val
|= negative_mask
;
15116 if (high
.kind
== PROP_CONST
15117 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
15118 high
.data
.const_val
|= negative_mask
;
15120 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
15122 if (high_bound_is_count
)
15123 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
15125 /* Ada expects an empty array on no boundary attributes. */
15126 if (attr
== NULL
&& cu
->language
!= language_ada
)
15127 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
15129 name
= dwarf2_name (die
, cu
);
15131 TYPE_NAME (range_type
) = name
;
15133 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15135 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
15137 set_die_type (die
, range_type
, cu
);
15139 /* set_die_type should be already done. */
15140 set_descriptive_type (range_type
, die
, cu
);
15145 static struct type
*
15146 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15150 /* For now, we only support the C meaning of an unspecified type: void. */
15152 type
= init_type (cu
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
15153 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
15155 return set_die_type (die
, type
, cu
);
15158 /* Read a single die and all its descendents. Set the die's sibling
15159 field to NULL; set other fields in the die correctly, and set all
15160 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
15161 location of the info_ptr after reading all of those dies. PARENT
15162 is the parent of the die in question. */
15164 static struct die_info
*
15165 read_die_and_children (const struct die_reader_specs
*reader
,
15166 const gdb_byte
*info_ptr
,
15167 const gdb_byte
**new_info_ptr
,
15168 struct die_info
*parent
)
15170 struct die_info
*die
;
15171 const gdb_byte
*cur_ptr
;
15174 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
15177 *new_info_ptr
= cur_ptr
;
15180 store_in_ref_table (die
, reader
->cu
);
15183 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
15187 *new_info_ptr
= cur_ptr
;
15190 die
->sibling
= NULL
;
15191 die
->parent
= parent
;
15195 /* Read a die, all of its descendents, and all of its siblings; set
15196 all of the fields of all of the dies correctly. Arguments are as
15197 in read_die_and_children. */
15199 static struct die_info
*
15200 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
15201 const gdb_byte
*info_ptr
,
15202 const gdb_byte
**new_info_ptr
,
15203 struct die_info
*parent
)
15205 struct die_info
*first_die
, *last_sibling
;
15206 const gdb_byte
*cur_ptr
;
15208 cur_ptr
= info_ptr
;
15209 first_die
= last_sibling
= NULL
;
15213 struct die_info
*die
15214 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
15218 *new_info_ptr
= cur_ptr
;
15225 last_sibling
->sibling
= die
;
15227 last_sibling
= die
;
15231 /* Read a die, all of its descendents, and all of its siblings; set
15232 all of the fields of all of the dies correctly. Arguments are as
15233 in read_die_and_children.
15234 This the main entry point for reading a DIE and all its children. */
15236 static struct die_info
*
15237 read_die_and_siblings (const struct die_reader_specs
*reader
,
15238 const gdb_byte
*info_ptr
,
15239 const gdb_byte
**new_info_ptr
,
15240 struct die_info
*parent
)
15242 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
15243 new_info_ptr
, parent
);
15245 if (dwarf_die_debug
)
15247 fprintf_unfiltered (gdb_stdlog
,
15248 "Read die from %s@0x%x of %s:\n",
15249 get_section_name (reader
->die_section
),
15250 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15251 bfd_get_filename (reader
->abfd
));
15252 dump_die (die
, dwarf_die_debug
);
15258 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
15260 The caller is responsible for filling in the extra attributes
15261 and updating (*DIEP)->num_attrs.
15262 Set DIEP to point to a newly allocated die with its information,
15263 except for its child, sibling, and parent fields.
15264 Set HAS_CHILDREN to tell whether the die has children or not. */
15266 static const gdb_byte
*
15267 read_full_die_1 (const struct die_reader_specs
*reader
,
15268 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15269 int *has_children
, int num_extra_attrs
)
15271 unsigned int abbrev_number
, bytes_read
, i
;
15272 sect_offset offset
;
15273 struct abbrev_info
*abbrev
;
15274 struct die_info
*die
;
15275 struct dwarf2_cu
*cu
= reader
->cu
;
15276 bfd
*abfd
= reader
->abfd
;
15278 offset
.sect_off
= info_ptr
- reader
->buffer
;
15279 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15280 info_ptr
+= bytes_read
;
15281 if (!abbrev_number
)
15288 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
15290 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
15292 bfd_get_filename (abfd
));
15294 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
15295 die
->offset
= offset
;
15296 die
->tag
= abbrev
->tag
;
15297 die
->abbrev
= abbrev_number
;
15299 /* Make the result usable.
15300 The caller needs to update num_attrs after adding the extra
15302 die
->num_attrs
= abbrev
->num_attrs
;
15304 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
15305 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
15309 *has_children
= abbrev
->has_children
;
15313 /* Read a die and all its attributes.
15314 Set DIEP to point to a newly allocated die with its information,
15315 except for its child, sibling, and parent fields.
15316 Set HAS_CHILDREN to tell whether the die has children or not. */
15318 static const gdb_byte
*
15319 read_full_die (const struct die_reader_specs
*reader
,
15320 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15323 const gdb_byte
*result
;
15325 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
15327 if (dwarf_die_debug
)
15329 fprintf_unfiltered (gdb_stdlog
,
15330 "Read die from %s@0x%x of %s:\n",
15331 get_section_name (reader
->die_section
),
15332 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15333 bfd_get_filename (reader
->abfd
));
15334 dump_die (*diep
, dwarf_die_debug
);
15340 /* Abbreviation tables.
15342 In DWARF version 2, the description of the debugging information is
15343 stored in a separate .debug_abbrev section. Before we read any
15344 dies from a section we read in all abbreviations and install them
15345 in a hash table. */
15347 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
15349 static struct abbrev_info
*
15350 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
15352 struct abbrev_info
*abbrev
;
15354 abbrev
= XOBNEW (&abbrev_table
->abbrev_obstack
, struct abbrev_info
);
15355 memset (abbrev
, 0, sizeof (struct abbrev_info
));
15360 /* Add an abbreviation to the table. */
15363 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
15364 unsigned int abbrev_number
,
15365 struct abbrev_info
*abbrev
)
15367 unsigned int hash_number
;
15369 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
15370 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
15371 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
15374 /* Look up an abbrev in the table.
15375 Returns NULL if the abbrev is not found. */
15377 static struct abbrev_info
*
15378 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
15379 unsigned int abbrev_number
)
15381 unsigned int hash_number
;
15382 struct abbrev_info
*abbrev
;
15384 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
15385 abbrev
= abbrev_table
->abbrevs
[hash_number
];
15389 if (abbrev
->number
== abbrev_number
)
15391 abbrev
= abbrev
->next
;
15396 /* Read in an abbrev table. */
15398 static struct abbrev_table
*
15399 abbrev_table_read_table (struct dwarf2_section_info
*section
,
15400 sect_offset offset
)
15402 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15403 bfd
*abfd
= get_section_bfd_owner (section
);
15404 struct abbrev_table
*abbrev_table
;
15405 const gdb_byte
*abbrev_ptr
;
15406 struct abbrev_info
*cur_abbrev
;
15407 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
15408 unsigned int abbrev_form
;
15409 struct attr_abbrev
*cur_attrs
;
15410 unsigned int allocated_attrs
;
15412 abbrev_table
= XNEW (struct abbrev_table
);
15413 abbrev_table
->offset
= offset
;
15414 obstack_init (&abbrev_table
->abbrev_obstack
);
15415 abbrev_table
->abbrevs
=
15416 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct abbrev_info
*,
15418 memset (abbrev_table
->abbrevs
, 0,
15419 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
15421 dwarf2_read_section (objfile
, section
);
15422 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
15423 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15424 abbrev_ptr
+= bytes_read
;
15426 allocated_attrs
= ATTR_ALLOC_CHUNK
;
15427 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
15429 /* Loop until we reach an abbrev number of 0. */
15430 while (abbrev_number
)
15432 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
15434 /* read in abbrev header */
15435 cur_abbrev
->number
= abbrev_number
;
15437 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15438 abbrev_ptr
+= bytes_read
;
15439 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
15442 /* now read in declarations */
15443 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15444 abbrev_ptr
+= bytes_read
;
15445 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15446 abbrev_ptr
+= bytes_read
;
15447 while (abbrev_name
)
15449 if (cur_abbrev
->num_attrs
== allocated_attrs
)
15451 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
15453 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
15456 cur_attrs
[cur_abbrev
->num_attrs
].name
15457 = (enum dwarf_attribute
) abbrev_name
;
15458 cur_attrs
[cur_abbrev
->num_attrs
++].form
15459 = (enum dwarf_form
) abbrev_form
;
15460 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15461 abbrev_ptr
+= bytes_read
;
15462 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15463 abbrev_ptr
+= bytes_read
;
15466 cur_abbrev
->attrs
=
15467 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
15468 cur_abbrev
->num_attrs
);
15469 memcpy (cur_abbrev
->attrs
, cur_attrs
,
15470 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
15472 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
15474 /* Get next abbreviation.
15475 Under Irix6 the abbreviations for a compilation unit are not
15476 always properly terminated with an abbrev number of 0.
15477 Exit loop if we encounter an abbreviation which we have
15478 already read (which means we are about to read the abbreviations
15479 for the next compile unit) or if the end of the abbreviation
15480 table is reached. */
15481 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
15483 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15484 abbrev_ptr
+= bytes_read
;
15485 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
15490 return abbrev_table
;
15493 /* Free the resources held by ABBREV_TABLE. */
15496 abbrev_table_free (struct abbrev_table
*abbrev_table
)
15498 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
15499 xfree (abbrev_table
);
15502 /* Same as abbrev_table_free but as a cleanup.
15503 We pass in a pointer to the pointer to the table so that we can
15504 set the pointer to NULL when we're done. It also simplifies
15505 build_type_psymtabs_1. */
15508 abbrev_table_free_cleanup (void *table_ptr
)
15510 struct abbrev_table
**abbrev_table_ptr
= (struct abbrev_table
**) table_ptr
;
15512 if (*abbrev_table_ptr
!= NULL
)
15513 abbrev_table_free (*abbrev_table_ptr
);
15514 *abbrev_table_ptr
= NULL
;
15517 /* Read the abbrev table for CU from ABBREV_SECTION. */
15520 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
15521 struct dwarf2_section_info
*abbrev_section
)
15524 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
15527 /* Release the memory used by the abbrev table for a compilation unit. */
15530 dwarf2_free_abbrev_table (void *ptr_to_cu
)
15532 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr_to_cu
;
15534 if (cu
->abbrev_table
!= NULL
)
15535 abbrev_table_free (cu
->abbrev_table
);
15536 /* Set this to NULL so that we SEGV if we try to read it later,
15537 and also because free_comp_unit verifies this is NULL. */
15538 cu
->abbrev_table
= NULL
;
15541 /* Returns nonzero if TAG represents a type that we might generate a partial
15545 is_type_tag_for_partial (int tag
)
15550 /* Some types that would be reasonable to generate partial symbols for,
15551 that we don't at present. */
15552 case DW_TAG_array_type
:
15553 case DW_TAG_file_type
:
15554 case DW_TAG_ptr_to_member_type
:
15555 case DW_TAG_set_type
:
15556 case DW_TAG_string_type
:
15557 case DW_TAG_subroutine_type
:
15559 case DW_TAG_base_type
:
15560 case DW_TAG_class_type
:
15561 case DW_TAG_interface_type
:
15562 case DW_TAG_enumeration_type
:
15563 case DW_TAG_structure_type
:
15564 case DW_TAG_subrange_type
:
15565 case DW_TAG_typedef
:
15566 case DW_TAG_union_type
:
15573 /* Load all DIEs that are interesting for partial symbols into memory. */
15575 static struct partial_die_info
*
15576 load_partial_dies (const struct die_reader_specs
*reader
,
15577 const gdb_byte
*info_ptr
, int building_psymtab
)
15579 struct dwarf2_cu
*cu
= reader
->cu
;
15580 struct objfile
*objfile
= cu
->objfile
;
15581 struct partial_die_info
*part_die
;
15582 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
15583 struct abbrev_info
*abbrev
;
15584 unsigned int bytes_read
;
15585 unsigned int load_all
= 0;
15586 int nesting_level
= 1;
15591 gdb_assert (cu
->per_cu
!= NULL
);
15592 if (cu
->per_cu
->load_all_dies
)
15596 = htab_create_alloc_ex (cu
->header
.length
/ 12,
15600 &cu
->comp_unit_obstack
,
15601 hashtab_obstack_allocate
,
15602 dummy_obstack_deallocate
);
15604 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
15608 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
15610 /* A NULL abbrev means the end of a series of children. */
15611 if (abbrev
== NULL
)
15613 if (--nesting_level
== 0)
15615 /* PART_DIE was probably the last thing allocated on the
15616 comp_unit_obstack, so we could call obstack_free
15617 here. We don't do that because the waste is small,
15618 and will be cleaned up when we're done with this
15619 compilation unit. This way, we're also more robust
15620 against other users of the comp_unit_obstack. */
15623 info_ptr
+= bytes_read
;
15624 last_die
= parent_die
;
15625 parent_die
= parent_die
->die_parent
;
15629 /* Check for template arguments. We never save these; if
15630 they're seen, we just mark the parent, and go on our way. */
15631 if (parent_die
!= NULL
15632 && cu
->language
== language_cplus
15633 && (abbrev
->tag
== DW_TAG_template_type_param
15634 || abbrev
->tag
== DW_TAG_template_value_param
))
15636 parent_die
->has_template_arguments
= 1;
15640 /* We don't need a partial DIE for the template argument. */
15641 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15646 /* We only recurse into c++ subprograms looking for template arguments.
15647 Skip their other children. */
15649 && cu
->language
== language_cplus
15650 && parent_die
!= NULL
15651 && parent_die
->tag
== DW_TAG_subprogram
)
15653 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15657 /* Check whether this DIE is interesting enough to save. Normally
15658 we would not be interested in members here, but there may be
15659 later variables referencing them via DW_AT_specification (for
15660 static members). */
15662 && !is_type_tag_for_partial (abbrev
->tag
)
15663 && abbrev
->tag
!= DW_TAG_constant
15664 && abbrev
->tag
!= DW_TAG_enumerator
15665 && abbrev
->tag
!= DW_TAG_subprogram
15666 && abbrev
->tag
!= DW_TAG_lexical_block
15667 && abbrev
->tag
!= DW_TAG_variable
15668 && abbrev
->tag
!= DW_TAG_namespace
15669 && abbrev
->tag
!= DW_TAG_module
15670 && abbrev
->tag
!= DW_TAG_member
15671 && abbrev
->tag
!= DW_TAG_imported_unit
15672 && abbrev
->tag
!= DW_TAG_imported_declaration
)
15674 /* Otherwise we skip to the next sibling, if any. */
15675 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15679 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
15682 /* This two-pass algorithm for processing partial symbols has a
15683 high cost in cache pressure. Thus, handle some simple cases
15684 here which cover the majority of C partial symbols. DIEs
15685 which neither have specification tags in them, nor could have
15686 specification tags elsewhere pointing at them, can simply be
15687 processed and discarded.
15689 This segment is also optional; scan_partial_symbols and
15690 add_partial_symbol will handle these DIEs if we chain
15691 them in normally. When compilers which do not emit large
15692 quantities of duplicate debug information are more common,
15693 this code can probably be removed. */
15695 /* Any complete simple types at the top level (pretty much all
15696 of them, for a language without namespaces), can be processed
15698 if (parent_die
== NULL
15699 && part_die
->has_specification
== 0
15700 && part_die
->is_declaration
== 0
15701 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
15702 || part_die
->tag
== DW_TAG_base_type
15703 || part_die
->tag
== DW_TAG_subrange_type
))
15705 if (building_psymtab
&& part_die
->name
!= NULL
)
15706 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
15707 VAR_DOMAIN
, LOC_TYPEDEF
,
15708 &objfile
->static_psymbols
,
15709 0, cu
->language
, objfile
);
15710 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
15714 /* The exception for DW_TAG_typedef with has_children above is
15715 a workaround of GCC PR debug/47510. In the case of this complaint
15716 type_name_no_tag_or_error will error on such types later.
15718 GDB skipped children of DW_TAG_typedef by the shortcut above and then
15719 it could not find the child DIEs referenced later, this is checked
15720 above. In correct DWARF DW_TAG_typedef should have no children. */
15722 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
15723 complaint (&symfile_complaints
,
15724 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
15725 "- DIE at 0x%x [in module %s]"),
15726 part_die
->offset
.sect_off
, objfile_name (objfile
));
15728 /* If we're at the second level, and we're an enumerator, and
15729 our parent has no specification (meaning possibly lives in a
15730 namespace elsewhere), then we can add the partial symbol now
15731 instead of queueing it. */
15732 if (part_die
->tag
== DW_TAG_enumerator
15733 && parent_die
!= NULL
15734 && parent_die
->die_parent
== NULL
15735 && parent_die
->tag
== DW_TAG_enumeration_type
15736 && parent_die
->has_specification
== 0)
15738 if (part_die
->name
== NULL
)
15739 complaint (&symfile_complaints
,
15740 _("malformed enumerator DIE ignored"));
15741 else if (building_psymtab
)
15742 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
15743 VAR_DOMAIN
, LOC_CONST
,
15744 (cu
->language
== language_cplus
15745 || cu
->language
== language_java
)
15746 ? &objfile
->global_psymbols
15747 : &objfile
->static_psymbols
,
15748 0, cu
->language
, objfile
);
15750 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
15754 /* We'll save this DIE so link it in. */
15755 part_die
->die_parent
= parent_die
;
15756 part_die
->die_sibling
= NULL
;
15757 part_die
->die_child
= NULL
;
15759 if (last_die
&& last_die
== parent_die
)
15760 last_die
->die_child
= part_die
;
15762 last_die
->die_sibling
= part_die
;
15764 last_die
= part_die
;
15766 if (first_die
== NULL
)
15767 first_die
= part_die
;
15769 /* Maybe add the DIE to the hash table. Not all DIEs that we
15770 find interesting need to be in the hash table, because we
15771 also have the parent/sibling/child chains; only those that we
15772 might refer to by offset later during partial symbol reading.
15774 For now this means things that might have be the target of a
15775 DW_AT_specification, DW_AT_abstract_origin, or
15776 DW_AT_extension. DW_AT_extension will refer only to
15777 namespaces; DW_AT_abstract_origin refers to functions (and
15778 many things under the function DIE, but we do not recurse
15779 into function DIEs during partial symbol reading) and
15780 possibly variables as well; DW_AT_specification refers to
15781 declarations. Declarations ought to have the DW_AT_declaration
15782 flag. It happens that GCC forgets to put it in sometimes, but
15783 only for functions, not for types.
15785 Adding more things than necessary to the hash table is harmless
15786 except for the performance cost. Adding too few will result in
15787 wasted time in find_partial_die, when we reread the compilation
15788 unit with load_all_dies set. */
15791 || abbrev
->tag
== DW_TAG_constant
15792 || abbrev
->tag
== DW_TAG_subprogram
15793 || abbrev
->tag
== DW_TAG_variable
15794 || abbrev
->tag
== DW_TAG_namespace
15795 || part_die
->is_declaration
)
15799 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
15800 part_die
->offset
.sect_off
, INSERT
);
15804 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
15806 /* For some DIEs we want to follow their children (if any). For C
15807 we have no reason to follow the children of structures; for other
15808 languages we have to, so that we can get at method physnames
15809 to infer fully qualified class names, for DW_AT_specification,
15810 and for C++ template arguments. For C++, we also look one level
15811 inside functions to find template arguments (if the name of the
15812 function does not already contain the template arguments).
15814 For Ada, we need to scan the children of subprograms and lexical
15815 blocks as well because Ada allows the definition of nested
15816 entities that could be interesting for the debugger, such as
15817 nested subprograms for instance. */
15818 if (last_die
->has_children
15820 || last_die
->tag
== DW_TAG_namespace
15821 || last_die
->tag
== DW_TAG_module
15822 || last_die
->tag
== DW_TAG_enumeration_type
15823 || (cu
->language
== language_cplus
15824 && last_die
->tag
== DW_TAG_subprogram
15825 && (last_die
->name
== NULL
15826 || strchr (last_die
->name
, '<') == NULL
))
15827 || (cu
->language
!= language_c
15828 && (last_die
->tag
== DW_TAG_class_type
15829 || last_die
->tag
== DW_TAG_interface_type
15830 || last_die
->tag
== DW_TAG_structure_type
15831 || last_die
->tag
== DW_TAG_union_type
))
15832 || (cu
->language
== language_ada
15833 && (last_die
->tag
== DW_TAG_subprogram
15834 || last_die
->tag
== DW_TAG_lexical_block
))))
15837 parent_die
= last_die
;
15841 /* Otherwise we skip to the next sibling, if any. */
15842 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
15844 /* Back to the top, do it again. */
15848 /* Read a minimal amount of information into the minimal die structure. */
15850 static const gdb_byte
*
15851 read_partial_die (const struct die_reader_specs
*reader
,
15852 struct partial_die_info
*part_die
,
15853 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
15854 const gdb_byte
*info_ptr
)
15856 struct dwarf2_cu
*cu
= reader
->cu
;
15857 struct objfile
*objfile
= cu
->objfile
;
15858 const gdb_byte
*buffer
= reader
->buffer
;
15860 struct attribute attr
;
15861 int has_low_pc_attr
= 0;
15862 int has_high_pc_attr
= 0;
15863 int high_pc_relative
= 0;
15865 memset (part_die
, 0, sizeof (struct partial_die_info
));
15867 part_die
->offset
.sect_off
= info_ptr
- buffer
;
15869 info_ptr
+= abbrev_len
;
15871 if (abbrev
== NULL
)
15874 part_die
->tag
= abbrev
->tag
;
15875 part_die
->has_children
= abbrev
->has_children
;
15877 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
15879 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
15881 /* Store the data if it is of an attribute we want to keep in a
15882 partial symbol table. */
15886 switch (part_die
->tag
)
15888 case DW_TAG_compile_unit
:
15889 case DW_TAG_partial_unit
:
15890 case DW_TAG_type_unit
:
15891 /* Compilation units have a DW_AT_name that is a filename, not
15892 a source language identifier. */
15893 case DW_TAG_enumeration_type
:
15894 case DW_TAG_enumerator
:
15895 /* These tags always have simple identifiers already; no need
15896 to canonicalize them. */
15897 part_die
->name
= DW_STRING (&attr
);
15901 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
15902 &objfile
->per_bfd
->storage_obstack
);
15906 case DW_AT_linkage_name
:
15907 case DW_AT_MIPS_linkage_name
:
15908 /* Note that both forms of linkage name might appear. We
15909 assume they will be the same, and we only store the last
15911 if (cu
->language
== language_ada
)
15912 part_die
->name
= DW_STRING (&attr
);
15913 part_die
->linkage_name
= DW_STRING (&attr
);
15916 has_low_pc_attr
= 1;
15917 part_die
->lowpc
= attr_value_as_address (&attr
);
15919 case DW_AT_high_pc
:
15920 has_high_pc_attr
= 1;
15921 part_die
->highpc
= attr_value_as_address (&attr
);
15922 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
15923 high_pc_relative
= 1;
15925 case DW_AT_location
:
15926 /* Support the .debug_loc offsets. */
15927 if (attr_form_is_block (&attr
))
15929 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
15931 else if (attr_form_is_section_offset (&attr
))
15933 dwarf2_complex_location_expr_complaint ();
15937 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15938 "partial symbol information");
15941 case DW_AT_external
:
15942 part_die
->is_external
= DW_UNSND (&attr
);
15944 case DW_AT_declaration
:
15945 part_die
->is_declaration
= DW_UNSND (&attr
);
15948 part_die
->has_type
= 1;
15950 case DW_AT_abstract_origin
:
15951 case DW_AT_specification
:
15952 case DW_AT_extension
:
15953 part_die
->has_specification
= 1;
15954 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
15955 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
15956 || cu
->per_cu
->is_dwz
);
15958 case DW_AT_sibling
:
15959 /* Ignore absolute siblings, they might point outside of
15960 the current compile unit. */
15961 if (attr
.form
== DW_FORM_ref_addr
)
15962 complaint (&symfile_complaints
,
15963 _("ignoring absolute DW_AT_sibling"));
15966 unsigned int off
= dwarf2_get_ref_die_offset (&attr
).sect_off
;
15967 const gdb_byte
*sibling_ptr
= buffer
+ off
;
15969 if (sibling_ptr
< info_ptr
)
15970 complaint (&symfile_complaints
,
15971 _("DW_AT_sibling points backwards"));
15972 else if (sibling_ptr
> reader
->buffer_end
)
15973 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
15975 part_die
->sibling
= sibling_ptr
;
15978 case DW_AT_byte_size
:
15979 part_die
->has_byte_size
= 1;
15981 case DW_AT_const_value
:
15982 part_die
->has_const_value
= 1;
15984 case DW_AT_calling_convention
:
15985 /* DWARF doesn't provide a way to identify a program's source-level
15986 entry point. DW_AT_calling_convention attributes are only meant
15987 to describe functions' calling conventions.
15989 However, because it's a necessary piece of information in
15990 Fortran, and because DW_CC_program is the only piece of debugging
15991 information whose definition refers to a 'main program' at all,
15992 several compilers have begun marking Fortran main programs with
15993 DW_CC_program --- even when those functions use the standard
15994 calling conventions.
15996 So until DWARF specifies a way to provide this information and
15997 compilers pick up the new representation, we'll support this
15999 if (DW_UNSND (&attr
) == DW_CC_program
16000 && cu
->language
== language_fortran
16001 && part_die
->name
!= NULL
)
16002 set_objfile_main_name (objfile
, part_die
->name
, language_fortran
);
16005 if (DW_UNSND (&attr
) == DW_INL_inlined
16006 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
16007 part_die
->may_be_inlined
= 1;
16011 if (part_die
->tag
== DW_TAG_imported_unit
)
16013 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
16014 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
16015 || cu
->per_cu
->is_dwz
);
16024 if (high_pc_relative
)
16025 part_die
->highpc
+= part_die
->lowpc
;
16027 if (has_low_pc_attr
&& has_high_pc_attr
)
16029 /* When using the GNU linker, .gnu.linkonce. sections are used to
16030 eliminate duplicate copies of functions and vtables and such.
16031 The linker will arbitrarily choose one and discard the others.
16032 The AT_*_pc values for such functions refer to local labels in
16033 these sections. If the section from that file was discarded, the
16034 labels are not in the output, so the relocs get a value of 0.
16035 If this is a discarded function, mark the pc bounds as invalid,
16036 so that GDB will ignore it. */
16037 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
16039 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16041 complaint (&symfile_complaints
,
16042 _("DW_AT_low_pc %s is zero "
16043 "for DIE at 0x%x [in module %s]"),
16044 paddress (gdbarch
, part_die
->lowpc
),
16045 part_die
->offset
.sect_off
, objfile_name (objfile
));
16047 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
16048 else if (part_die
->lowpc
>= part_die
->highpc
)
16050 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16052 complaint (&symfile_complaints
,
16053 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
16054 "for DIE at 0x%x [in module %s]"),
16055 paddress (gdbarch
, part_die
->lowpc
),
16056 paddress (gdbarch
, part_die
->highpc
),
16057 part_die
->offset
.sect_off
, objfile_name (objfile
));
16060 part_die
->has_pc_info
= 1;
16066 /* Find a cached partial DIE at OFFSET in CU. */
16068 static struct partial_die_info
*
16069 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
16071 struct partial_die_info
*lookup_die
= NULL
;
16072 struct partial_die_info part_die
;
16074 part_die
.offset
= offset
;
16075 lookup_die
= ((struct partial_die_info
*)
16076 htab_find_with_hash (cu
->partial_dies
, &part_die
,
16082 /* Find a partial DIE at OFFSET, which may or may not be in CU,
16083 except in the case of .debug_types DIEs which do not reference
16084 outside their CU (they do however referencing other types via
16085 DW_FORM_ref_sig8). */
16087 static struct partial_die_info
*
16088 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
16090 struct objfile
*objfile
= cu
->objfile
;
16091 struct dwarf2_per_cu_data
*per_cu
= NULL
;
16092 struct partial_die_info
*pd
= NULL
;
16094 if (offset_in_dwz
== cu
->per_cu
->is_dwz
16095 && offset_in_cu_p (&cu
->header
, offset
))
16097 pd
= find_partial_die_in_comp_unit (offset
, cu
);
16100 /* We missed recording what we needed.
16101 Load all dies and try again. */
16102 per_cu
= cu
->per_cu
;
16106 /* TUs don't reference other CUs/TUs (except via type signatures). */
16107 if (cu
->per_cu
->is_debug_types
)
16109 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
16110 " external reference to offset 0x%lx [in module %s].\n"),
16111 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
16112 bfd_get_filename (objfile
->obfd
));
16114 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
16117 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
16118 load_partial_comp_unit (per_cu
);
16120 per_cu
->cu
->last_used
= 0;
16121 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
16124 /* If we didn't find it, and not all dies have been loaded,
16125 load them all and try again. */
16127 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
16129 per_cu
->load_all_dies
= 1;
16131 /* This is nasty. When we reread the DIEs, somewhere up the call chain
16132 THIS_CU->cu may already be in use. So we can't just free it and
16133 replace its DIEs with the ones we read in. Instead, we leave those
16134 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
16135 and clobber THIS_CU->cu->partial_dies with the hash table for the new
16137 load_partial_comp_unit (per_cu
);
16139 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
16143 internal_error (__FILE__
, __LINE__
,
16144 _("could not find partial DIE 0x%x "
16145 "in cache [from module %s]\n"),
16146 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16150 /* See if we can figure out if the class lives in a namespace. We do
16151 this by looking for a member function; its demangled name will
16152 contain namespace info, if there is any. */
16155 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
16156 struct dwarf2_cu
*cu
)
16158 /* NOTE: carlton/2003-10-07: Getting the info this way changes
16159 what template types look like, because the demangler
16160 frequently doesn't give the same name as the debug info. We
16161 could fix this by only using the demangled name to get the
16162 prefix (but see comment in read_structure_type). */
16164 struct partial_die_info
*real_pdi
;
16165 struct partial_die_info
*child_pdi
;
16167 /* If this DIE (this DIE's specification, if any) has a parent, then
16168 we should not do this. We'll prepend the parent's fully qualified
16169 name when we create the partial symbol. */
16171 real_pdi
= struct_pdi
;
16172 while (real_pdi
->has_specification
)
16173 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
16174 real_pdi
->spec_is_dwz
, cu
);
16176 if (real_pdi
->die_parent
!= NULL
)
16179 for (child_pdi
= struct_pdi
->die_child
;
16181 child_pdi
= child_pdi
->die_sibling
)
16183 if (child_pdi
->tag
== DW_TAG_subprogram
16184 && child_pdi
->linkage_name
!= NULL
)
16186 char *actual_class_name
16187 = language_class_name_from_physname (cu
->language_defn
,
16188 child_pdi
->linkage_name
);
16189 if (actual_class_name
!= NULL
)
16193 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16195 strlen (actual_class_name
)));
16196 xfree (actual_class_name
);
16203 /* Adjust PART_DIE before generating a symbol for it. This function
16204 may set the is_external flag or change the DIE's name. */
16207 fixup_partial_die (struct partial_die_info
*part_die
,
16208 struct dwarf2_cu
*cu
)
16210 /* Once we've fixed up a die, there's no point in doing so again.
16211 This also avoids a memory leak if we were to call
16212 guess_partial_die_structure_name multiple times. */
16213 if (part_die
->fixup_called
)
16216 /* If we found a reference attribute and the DIE has no name, try
16217 to find a name in the referred to DIE. */
16219 if (part_die
->name
== NULL
&& part_die
->has_specification
)
16221 struct partial_die_info
*spec_die
;
16223 spec_die
= find_partial_die (part_die
->spec_offset
,
16224 part_die
->spec_is_dwz
, cu
);
16226 fixup_partial_die (spec_die
, cu
);
16228 if (spec_die
->name
)
16230 part_die
->name
= spec_die
->name
;
16232 /* Copy DW_AT_external attribute if it is set. */
16233 if (spec_die
->is_external
)
16234 part_die
->is_external
= spec_die
->is_external
;
16238 /* Set default names for some unnamed DIEs. */
16240 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
16241 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
16243 /* If there is no parent die to provide a namespace, and there are
16244 children, see if we can determine the namespace from their linkage
16246 if (cu
->language
== language_cplus
16247 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
16248 && part_die
->die_parent
== NULL
16249 && part_die
->has_children
16250 && (part_die
->tag
== DW_TAG_class_type
16251 || part_die
->tag
== DW_TAG_structure_type
16252 || part_die
->tag
== DW_TAG_union_type
))
16253 guess_partial_die_structure_name (part_die
, cu
);
16255 /* GCC might emit a nameless struct or union that has a linkage
16256 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16257 if (part_die
->name
== NULL
16258 && (part_die
->tag
== DW_TAG_class_type
16259 || part_die
->tag
== DW_TAG_interface_type
16260 || part_die
->tag
== DW_TAG_structure_type
16261 || part_die
->tag
== DW_TAG_union_type
)
16262 && part_die
->linkage_name
!= NULL
)
16266 demangled
= gdb_demangle (part_die
->linkage_name
, DMGL_TYPES
);
16271 /* Strip any leading namespaces/classes, keep only the base name.
16272 DW_AT_name for named DIEs does not contain the prefixes. */
16273 base
= strrchr (demangled
, ':');
16274 if (base
&& base
> demangled
&& base
[-1] == ':')
16281 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16282 base
, strlen (base
)));
16287 part_die
->fixup_called
= 1;
16290 /* Read an attribute value described by an attribute form. */
16292 static const gdb_byte
*
16293 read_attribute_value (const struct die_reader_specs
*reader
,
16294 struct attribute
*attr
, unsigned form
,
16295 const gdb_byte
*info_ptr
)
16297 struct dwarf2_cu
*cu
= reader
->cu
;
16298 struct objfile
*objfile
= cu
->objfile
;
16299 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16300 bfd
*abfd
= reader
->abfd
;
16301 struct comp_unit_head
*cu_header
= &cu
->header
;
16302 unsigned int bytes_read
;
16303 struct dwarf_block
*blk
;
16305 attr
->form
= (enum dwarf_form
) form
;
16308 case DW_FORM_ref_addr
:
16309 if (cu
->header
.version
== 2)
16310 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
16312 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
16313 &cu
->header
, &bytes_read
);
16314 info_ptr
+= bytes_read
;
16316 case DW_FORM_GNU_ref_alt
:
16317 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
16318 info_ptr
+= bytes_read
;
16321 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
16322 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
16323 info_ptr
+= bytes_read
;
16325 case DW_FORM_block2
:
16326 blk
= dwarf_alloc_block (cu
);
16327 blk
->size
= read_2_bytes (abfd
, info_ptr
);
16329 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16330 info_ptr
+= blk
->size
;
16331 DW_BLOCK (attr
) = blk
;
16333 case DW_FORM_block4
:
16334 blk
= dwarf_alloc_block (cu
);
16335 blk
->size
= read_4_bytes (abfd
, info_ptr
);
16337 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16338 info_ptr
+= blk
->size
;
16339 DW_BLOCK (attr
) = blk
;
16341 case DW_FORM_data2
:
16342 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
16345 case DW_FORM_data4
:
16346 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
16349 case DW_FORM_data8
:
16350 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
16353 case DW_FORM_sec_offset
:
16354 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
16355 info_ptr
+= bytes_read
;
16357 case DW_FORM_string
:
16358 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
16359 DW_STRING_IS_CANONICAL (attr
) = 0;
16360 info_ptr
+= bytes_read
;
16363 if (!cu
->per_cu
->is_dwz
)
16365 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
16367 DW_STRING_IS_CANONICAL (attr
) = 0;
16368 info_ptr
+= bytes_read
;
16372 case DW_FORM_GNU_strp_alt
:
16374 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
16375 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
16378 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
16379 DW_STRING_IS_CANONICAL (attr
) = 0;
16380 info_ptr
+= bytes_read
;
16383 case DW_FORM_exprloc
:
16384 case DW_FORM_block
:
16385 blk
= dwarf_alloc_block (cu
);
16386 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16387 info_ptr
+= bytes_read
;
16388 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16389 info_ptr
+= blk
->size
;
16390 DW_BLOCK (attr
) = blk
;
16392 case DW_FORM_block1
:
16393 blk
= dwarf_alloc_block (cu
);
16394 blk
->size
= read_1_byte (abfd
, info_ptr
);
16396 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16397 info_ptr
+= blk
->size
;
16398 DW_BLOCK (attr
) = blk
;
16400 case DW_FORM_data1
:
16401 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
16405 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
16408 case DW_FORM_flag_present
:
16409 DW_UNSND (attr
) = 1;
16411 case DW_FORM_sdata
:
16412 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
16413 info_ptr
+= bytes_read
;
16415 case DW_FORM_udata
:
16416 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16417 info_ptr
+= bytes_read
;
16420 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16421 + read_1_byte (abfd
, info_ptr
));
16425 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16426 + read_2_bytes (abfd
, info_ptr
));
16430 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16431 + read_4_bytes (abfd
, info_ptr
));
16435 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16436 + read_8_bytes (abfd
, info_ptr
));
16439 case DW_FORM_ref_sig8
:
16440 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
16443 case DW_FORM_ref_udata
:
16444 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16445 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
16446 info_ptr
+= bytes_read
;
16448 case DW_FORM_indirect
:
16449 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16450 info_ptr
+= bytes_read
;
16451 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
16453 case DW_FORM_GNU_addr_index
:
16454 if (reader
->dwo_file
== NULL
)
16456 /* For now flag a hard error.
16457 Later we can turn this into a complaint. */
16458 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
16459 dwarf_form_name (form
),
16460 bfd_get_filename (abfd
));
16462 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
16463 info_ptr
+= bytes_read
;
16465 case DW_FORM_GNU_str_index
:
16466 if (reader
->dwo_file
== NULL
)
16468 /* For now flag a hard error.
16469 Later we can turn this into a complaint if warranted. */
16470 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
16471 dwarf_form_name (form
),
16472 bfd_get_filename (abfd
));
16475 ULONGEST str_index
=
16476 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16478 DW_STRING (attr
) = read_str_index (reader
, str_index
);
16479 DW_STRING_IS_CANONICAL (attr
) = 0;
16480 info_ptr
+= bytes_read
;
16484 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
16485 dwarf_form_name (form
),
16486 bfd_get_filename (abfd
));
16490 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
16491 attr
->form
= DW_FORM_GNU_ref_alt
;
16493 /* We have seen instances where the compiler tried to emit a byte
16494 size attribute of -1 which ended up being encoded as an unsigned
16495 0xffffffff. Although 0xffffffff is technically a valid size value,
16496 an object of this size seems pretty unlikely so we can relatively
16497 safely treat these cases as if the size attribute was invalid and
16498 treat them as zero by default. */
16499 if (attr
->name
== DW_AT_byte_size
16500 && form
== DW_FORM_data4
16501 && DW_UNSND (attr
) >= 0xffffffff)
16504 (&symfile_complaints
,
16505 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
16506 hex_string (DW_UNSND (attr
)));
16507 DW_UNSND (attr
) = 0;
16513 /* Read an attribute described by an abbreviated attribute. */
16515 static const gdb_byte
*
16516 read_attribute (const struct die_reader_specs
*reader
,
16517 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
16518 const gdb_byte
*info_ptr
)
16520 attr
->name
= abbrev
->name
;
16521 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
16524 /* Read dwarf information from a buffer. */
16526 static unsigned int
16527 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
16529 return bfd_get_8 (abfd
, buf
);
16533 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
16535 return bfd_get_signed_8 (abfd
, buf
);
16538 static unsigned int
16539 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16541 return bfd_get_16 (abfd
, buf
);
16545 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16547 return bfd_get_signed_16 (abfd
, buf
);
16550 static unsigned int
16551 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16553 return bfd_get_32 (abfd
, buf
);
16557 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16559 return bfd_get_signed_32 (abfd
, buf
);
16563 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16565 return bfd_get_64 (abfd
, buf
);
16569 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
16570 unsigned int *bytes_read
)
16572 struct comp_unit_head
*cu_header
= &cu
->header
;
16573 CORE_ADDR retval
= 0;
16575 if (cu_header
->signed_addr_p
)
16577 switch (cu_header
->addr_size
)
16580 retval
= bfd_get_signed_16 (abfd
, buf
);
16583 retval
= bfd_get_signed_32 (abfd
, buf
);
16586 retval
= bfd_get_signed_64 (abfd
, buf
);
16589 internal_error (__FILE__
, __LINE__
,
16590 _("read_address: bad switch, signed [in module %s]"),
16591 bfd_get_filename (abfd
));
16596 switch (cu_header
->addr_size
)
16599 retval
= bfd_get_16 (abfd
, buf
);
16602 retval
= bfd_get_32 (abfd
, buf
);
16605 retval
= bfd_get_64 (abfd
, buf
);
16608 internal_error (__FILE__
, __LINE__
,
16609 _("read_address: bad switch, "
16610 "unsigned [in module %s]"),
16611 bfd_get_filename (abfd
));
16615 *bytes_read
= cu_header
->addr_size
;
16619 /* Read the initial length from a section. The (draft) DWARF 3
16620 specification allows the initial length to take up either 4 bytes
16621 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
16622 bytes describe the length and all offsets will be 8 bytes in length
16625 An older, non-standard 64-bit format is also handled by this
16626 function. The older format in question stores the initial length
16627 as an 8-byte quantity without an escape value. Lengths greater
16628 than 2^32 aren't very common which means that the initial 4 bytes
16629 is almost always zero. Since a length value of zero doesn't make
16630 sense for the 32-bit format, this initial zero can be considered to
16631 be an escape value which indicates the presence of the older 64-bit
16632 format. As written, the code can't detect (old format) lengths
16633 greater than 4GB. If it becomes necessary to handle lengths
16634 somewhat larger than 4GB, we could allow other small values (such
16635 as the non-sensical values of 1, 2, and 3) to also be used as
16636 escape values indicating the presence of the old format.
16638 The value returned via bytes_read should be used to increment the
16639 relevant pointer after calling read_initial_length().
16641 [ Note: read_initial_length() and read_offset() are based on the
16642 document entitled "DWARF Debugging Information Format", revision
16643 3, draft 8, dated November 19, 2001. This document was obtained
16646 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
16648 This document is only a draft and is subject to change. (So beware.)
16650 Details regarding the older, non-standard 64-bit format were
16651 determined empirically by examining 64-bit ELF files produced by
16652 the SGI toolchain on an IRIX 6.5 machine.
16654 - Kevin, July 16, 2002
16658 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
16660 LONGEST length
= bfd_get_32 (abfd
, buf
);
16662 if (length
== 0xffffffff)
16664 length
= bfd_get_64 (abfd
, buf
+ 4);
16667 else if (length
== 0)
16669 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
16670 length
= bfd_get_64 (abfd
, buf
);
16681 /* Cover function for read_initial_length.
16682 Returns the length of the object at BUF, and stores the size of the
16683 initial length in *BYTES_READ and stores the size that offsets will be in
16685 If the initial length size is not equivalent to that specified in
16686 CU_HEADER then issue a complaint.
16687 This is useful when reading non-comp-unit headers. */
16690 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
16691 const struct comp_unit_head
*cu_header
,
16692 unsigned int *bytes_read
,
16693 unsigned int *offset_size
)
16695 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
16697 gdb_assert (cu_header
->initial_length_size
== 4
16698 || cu_header
->initial_length_size
== 8
16699 || cu_header
->initial_length_size
== 12);
16701 if (cu_header
->initial_length_size
!= *bytes_read
)
16702 complaint (&symfile_complaints
,
16703 _("intermixed 32-bit and 64-bit DWARF sections"));
16705 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
16709 /* Read an offset from the data stream. The size of the offset is
16710 given by cu_header->offset_size. */
16713 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
16714 const struct comp_unit_head
*cu_header
,
16715 unsigned int *bytes_read
)
16717 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
16719 *bytes_read
= cu_header
->offset_size
;
16723 /* Read an offset from the data stream. */
16726 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
16728 LONGEST retval
= 0;
16730 switch (offset_size
)
16733 retval
= bfd_get_32 (abfd
, buf
);
16736 retval
= bfd_get_64 (abfd
, buf
);
16739 internal_error (__FILE__
, __LINE__
,
16740 _("read_offset_1: bad switch [in module %s]"),
16741 bfd_get_filename (abfd
));
16747 static const gdb_byte
*
16748 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
16750 /* If the size of a host char is 8 bits, we can return a pointer
16751 to the buffer, otherwise we have to copy the data to a buffer
16752 allocated on the temporary obstack. */
16753 gdb_assert (HOST_CHAR_BIT
== 8);
16757 static const char *
16758 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
16759 unsigned int *bytes_read_ptr
)
16761 /* If the size of a host char is 8 bits, we can return a pointer
16762 to the string, otherwise we have to copy the string to a buffer
16763 allocated on the temporary obstack. */
16764 gdb_assert (HOST_CHAR_BIT
== 8);
16767 *bytes_read_ptr
= 1;
16770 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
16771 return (const char *) buf
;
16774 static const char *
16775 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
16777 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
16778 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
16779 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
16780 bfd_get_filename (abfd
));
16781 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
16782 error (_("DW_FORM_strp pointing outside of "
16783 ".debug_str section [in module %s]"),
16784 bfd_get_filename (abfd
));
16785 gdb_assert (HOST_CHAR_BIT
== 8);
16786 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
16788 return (const char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
16791 /* Read a string at offset STR_OFFSET in the .debug_str section from
16792 the .dwz file DWZ. Throw an error if the offset is too large. If
16793 the string consists of a single NUL byte, return NULL; otherwise
16794 return a pointer to the string. */
16796 static const char *
16797 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
16799 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
16801 if (dwz
->str
.buffer
== NULL
)
16802 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
16803 "section [in module %s]"),
16804 bfd_get_filename (dwz
->dwz_bfd
));
16805 if (str_offset
>= dwz
->str
.size
)
16806 error (_("DW_FORM_GNU_strp_alt pointing outside of "
16807 ".debug_str section [in module %s]"),
16808 bfd_get_filename (dwz
->dwz_bfd
));
16809 gdb_assert (HOST_CHAR_BIT
== 8);
16810 if (dwz
->str
.buffer
[str_offset
] == '\0')
16812 return (const char *) (dwz
->str
.buffer
+ str_offset
);
16815 static const char *
16816 read_indirect_string (bfd
*abfd
, const gdb_byte
*buf
,
16817 const struct comp_unit_head
*cu_header
,
16818 unsigned int *bytes_read_ptr
)
16820 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
16822 return read_indirect_string_at_offset (abfd
, str_offset
);
16826 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
16827 unsigned int *bytes_read_ptr
)
16830 unsigned int num_read
;
16832 unsigned char byte
;
16839 byte
= bfd_get_8 (abfd
, buf
);
16842 result
|= ((ULONGEST
) (byte
& 127) << shift
);
16843 if ((byte
& 128) == 0)
16849 *bytes_read_ptr
= num_read
;
16854 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
16855 unsigned int *bytes_read_ptr
)
16858 int shift
, num_read
;
16859 unsigned char byte
;
16866 byte
= bfd_get_8 (abfd
, buf
);
16869 result
|= ((LONGEST
) (byte
& 127) << shift
);
16871 if ((byte
& 128) == 0)
16876 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
16877 result
|= -(((LONGEST
) 1) << shift
);
16878 *bytes_read_ptr
= num_read
;
16882 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
16883 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
16884 ADDR_SIZE is the size of addresses from the CU header. */
16887 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
16889 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16890 bfd
*abfd
= objfile
->obfd
;
16891 const gdb_byte
*info_ptr
;
16893 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
16894 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
16895 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
16896 objfile_name (objfile
));
16897 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
16898 error (_("DW_FORM_addr_index pointing outside of "
16899 ".debug_addr section [in module %s]"),
16900 objfile_name (objfile
));
16901 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
16902 + addr_base
+ addr_index
* addr_size
);
16903 if (addr_size
== 4)
16904 return bfd_get_32 (abfd
, info_ptr
);
16906 return bfd_get_64 (abfd
, info_ptr
);
16909 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
16912 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
16914 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
16917 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
16920 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
16921 unsigned int *bytes_read
)
16923 bfd
*abfd
= cu
->objfile
->obfd
;
16924 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
16926 return read_addr_index (cu
, addr_index
);
16929 /* Data structure to pass results from dwarf2_read_addr_index_reader
16930 back to dwarf2_read_addr_index. */
16932 struct dwarf2_read_addr_index_data
16934 ULONGEST addr_base
;
16938 /* die_reader_func for dwarf2_read_addr_index. */
16941 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
16942 const gdb_byte
*info_ptr
,
16943 struct die_info
*comp_unit_die
,
16947 struct dwarf2_cu
*cu
= reader
->cu
;
16948 struct dwarf2_read_addr_index_data
*aidata
=
16949 (struct dwarf2_read_addr_index_data
*) data
;
16951 aidata
->addr_base
= cu
->addr_base
;
16952 aidata
->addr_size
= cu
->header
.addr_size
;
16955 /* Given an index in .debug_addr, fetch the value.
16956 NOTE: This can be called during dwarf expression evaluation,
16957 long after the debug information has been read, and thus per_cu->cu
16958 may no longer exist. */
16961 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
16962 unsigned int addr_index
)
16964 struct objfile
*objfile
= per_cu
->objfile
;
16965 struct dwarf2_cu
*cu
= per_cu
->cu
;
16966 ULONGEST addr_base
;
16969 /* This is intended to be called from outside this file. */
16970 dw2_setup (objfile
);
16972 /* We need addr_base and addr_size.
16973 If we don't have PER_CU->cu, we have to get it.
16974 Nasty, but the alternative is storing the needed info in PER_CU,
16975 which at this point doesn't seem justified: it's not clear how frequently
16976 it would get used and it would increase the size of every PER_CU.
16977 Entry points like dwarf2_per_cu_addr_size do a similar thing
16978 so we're not in uncharted territory here.
16979 Alas we need to be a bit more complicated as addr_base is contained
16982 We don't need to read the entire CU(/TU).
16983 We just need the header and top level die.
16985 IWBN to use the aging mechanism to let us lazily later discard the CU.
16986 For now we skip this optimization. */
16990 addr_base
= cu
->addr_base
;
16991 addr_size
= cu
->header
.addr_size
;
16995 struct dwarf2_read_addr_index_data aidata
;
16997 /* Note: We can't use init_cutu_and_read_dies_simple here,
16998 we need addr_base. */
16999 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
17000 dwarf2_read_addr_index_reader
, &aidata
);
17001 addr_base
= aidata
.addr_base
;
17002 addr_size
= aidata
.addr_size
;
17005 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
17008 /* Given a DW_FORM_GNU_str_index, fetch the string.
17009 This is only used by the Fission support. */
17011 static const char *
17012 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
17014 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17015 const char *objf_name
= objfile_name (objfile
);
17016 bfd
*abfd
= objfile
->obfd
;
17017 struct dwarf2_cu
*cu
= reader
->cu
;
17018 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
17019 struct dwarf2_section_info
*str_offsets_section
=
17020 &reader
->dwo_file
->sections
.str_offsets
;
17021 const gdb_byte
*info_ptr
;
17022 ULONGEST str_offset
;
17023 static const char form_name
[] = "DW_FORM_GNU_str_index";
17025 dwarf2_read_section (objfile
, str_section
);
17026 dwarf2_read_section (objfile
, str_offsets_section
);
17027 if (str_section
->buffer
== NULL
)
17028 error (_("%s used without .debug_str.dwo section"
17029 " in CU at offset 0x%lx [in module %s]"),
17030 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
17031 if (str_offsets_section
->buffer
== NULL
)
17032 error (_("%s used without .debug_str_offsets.dwo section"
17033 " in CU at offset 0x%lx [in module %s]"),
17034 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
17035 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
17036 error (_("%s pointing outside of .debug_str_offsets.dwo"
17037 " section in CU at offset 0x%lx [in module %s]"),
17038 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
17039 info_ptr
= (str_offsets_section
->buffer
17040 + str_index
* cu
->header
.offset_size
);
17041 if (cu
->header
.offset_size
== 4)
17042 str_offset
= bfd_get_32 (abfd
, info_ptr
);
17044 str_offset
= bfd_get_64 (abfd
, info_ptr
);
17045 if (str_offset
>= str_section
->size
)
17046 error (_("Offset from %s pointing outside of"
17047 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
17048 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
17049 return (const char *) (str_section
->buffer
+ str_offset
);
17052 /* Return the length of an LEB128 number in BUF. */
17055 leb128_size (const gdb_byte
*buf
)
17057 const gdb_byte
*begin
= buf
;
17063 if ((byte
& 128) == 0)
17064 return buf
- begin
;
17069 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
17078 cu
->language
= language_c
;
17080 case DW_LANG_C_plus_plus
:
17081 case DW_LANG_C_plus_plus_11
:
17082 case DW_LANG_C_plus_plus_14
:
17083 cu
->language
= language_cplus
;
17086 cu
->language
= language_d
;
17088 case DW_LANG_Fortran77
:
17089 case DW_LANG_Fortran90
:
17090 case DW_LANG_Fortran95
:
17091 case DW_LANG_Fortran03
:
17092 case DW_LANG_Fortran08
:
17093 cu
->language
= language_fortran
;
17096 cu
->language
= language_go
;
17098 case DW_LANG_Mips_Assembler
:
17099 cu
->language
= language_asm
;
17102 cu
->language
= language_java
;
17104 case DW_LANG_Ada83
:
17105 case DW_LANG_Ada95
:
17106 cu
->language
= language_ada
;
17108 case DW_LANG_Modula2
:
17109 cu
->language
= language_m2
;
17111 case DW_LANG_Pascal83
:
17112 cu
->language
= language_pascal
;
17115 cu
->language
= language_objc
;
17118 case DW_LANG_Rust_old
:
17119 cu
->language
= language_rust
;
17121 case DW_LANG_Cobol74
:
17122 case DW_LANG_Cobol85
:
17124 cu
->language
= language_minimal
;
17127 cu
->language_defn
= language_def (cu
->language
);
17130 /* Return the named attribute or NULL if not there. */
17132 static struct attribute
*
17133 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17138 struct attribute
*spec
= NULL
;
17140 for (i
= 0; i
< die
->num_attrs
; ++i
)
17142 if (die
->attrs
[i
].name
== name
)
17143 return &die
->attrs
[i
];
17144 if (die
->attrs
[i
].name
== DW_AT_specification
17145 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
17146 spec
= &die
->attrs
[i
];
17152 die
= follow_die_ref (die
, spec
, &cu
);
17158 /* Return the named attribute or NULL if not there,
17159 but do not follow DW_AT_specification, etc.
17160 This is for use in contexts where we're reading .debug_types dies.
17161 Following DW_AT_specification, DW_AT_abstract_origin will take us
17162 back up the chain, and we want to go down. */
17164 static struct attribute
*
17165 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
17169 for (i
= 0; i
< die
->num_attrs
; ++i
)
17170 if (die
->attrs
[i
].name
== name
)
17171 return &die
->attrs
[i
];
17176 /* Return the string associated with a string-typed attribute, or NULL if it
17177 is either not found or is of an incorrect type. */
17179 static const char *
17180 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17182 struct attribute
*attr
;
17183 const char *str
= NULL
;
17185 attr
= dwarf2_attr (die
, name
, cu
);
17189 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_string
17190 || attr
->form
== DW_FORM_GNU_strp_alt
)
17191 str
= DW_STRING (attr
);
17193 complaint (&symfile_complaints
,
17194 _("string type expected for attribute %s for "
17195 "DIE at 0x%x in module %s"),
17196 dwarf_attr_name (name
), die
->offset
.sect_off
,
17197 objfile_name (cu
->objfile
));
17203 /* Return non-zero iff the attribute NAME is defined for the given DIE,
17204 and holds a non-zero value. This function should only be used for
17205 DW_FORM_flag or DW_FORM_flag_present attributes. */
17208 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
17210 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
17212 return (attr
&& DW_UNSND (attr
));
17216 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
17218 /* A DIE is a declaration if it has a DW_AT_declaration attribute
17219 which value is non-zero. However, we have to be careful with
17220 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
17221 (via dwarf2_flag_true_p) follows this attribute. So we may
17222 end up accidently finding a declaration attribute that belongs
17223 to a different DIE referenced by the specification attribute,
17224 even though the given DIE does not have a declaration attribute. */
17225 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
17226 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
17229 /* Return the die giving the specification for DIE, if there is
17230 one. *SPEC_CU is the CU containing DIE on input, and the CU
17231 containing the return value on output. If there is no
17232 specification, but there is an abstract origin, that is
17235 static struct die_info
*
17236 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
17238 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
17241 if (spec_attr
== NULL
)
17242 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
17244 if (spec_attr
== NULL
)
17247 return follow_die_ref (die
, spec_attr
, spec_cu
);
17250 /* Free the line_header structure *LH, and any arrays and strings it
17252 NOTE: This is also used as a "cleanup" function. */
17255 free_line_header (struct line_header
*lh
)
17257 if (lh
->standard_opcode_lengths
)
17258 xfree (lh
->standard_opcode_lengths
);
17260 /* Remember that all the lh->file_names[i].name pointers are
17261 pointers into debug_line_buffer, and don't need to be freed. */
17262 if (lh
->file_names
)
17263 xfree (lh
->file_names
);
17265 /* Similarly for the include directory names. */
17266 if (lh
->include_dirs
)
17267 xfree (lh
->include_dirs
);
17272 /* Stub for free_line_header to match void * callback types. */
17275 free_line_header_voidp (void *arg
)
17277 struct line_header
*lh
= (struct line_header
*) arg
;
17279 free_line_header (lh
);
17282 /* Add an entry to LH's include directory table. */
17285 add_include_dir (struct line_header
*lh
, const char *include_dir
)
17287 if (dwarf_line_debug
>= 2)
17288 fprintf_unfiltered (gdb_stdlog
, "Adding dir %u: %s\n",
17289 lh
->num_include_dirs
+ 1, include_dir
);
17291 /* Grow the array if necessary. */
17292 if (lh
->include_dirs_size
== 0)
17294 lh
->include_dirs_size
= 1; /* for testing */
17295 lh
->include_dirs
= XNEWVEC (const char *, lh
->include_dirs_size
);
17297 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
17299 lh
->include_dirs_size
*= 2;
17300 lh
->include_dirs
= XRESIZEVEC (const char *, lh
->include_dirs
,
17301 lh
->include_dirs_size
);
17304 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
17307 /* Add an entry to LH's file name table. */
17310 add_file_name (struct line_header
*lh
,
17312 unsigned int dir_index
,
17313 unsigned int mod_time
,
17314 unsigned int length
)
17316 struct file_entry
*fe
;
17318 if (dwarf_line_debug
>= 2)
17319 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
17320 lh
->num_file_names
+ 1, name
);
17322 /* Grow the array if necessary. */
17323 if (lh
->file_names_size
== 0)
17325 lh
->file_names_size
= 1; /* for testing */
17326 lh
->file_names
= XNEWVEC (struct file_entry
, lh
->file_names_size
);
17328 else if (lh
->num_file_names
>= lh
->file_names_size
)
17330 lh
->file_names_size
*= 2;
17332 = XRESIZEVEC (struct file_entry
, lh
->file_names
, lh
->file_names_size
);
17335 fe
= &lh
->file_names
[lh
->num_file_names
++];
17337 fe
->dir_index
= dir_index
;
17338 fe
->mod_time
= mod_time
;
17339 fe
->length
= length
;
17340 fe
->included_p
= 0;
17344 /* A convenience function to find the proper .debug_line section for a CU. */
17346 static struct dwarf2_section_info
*
17347 get_debug_line_section (struct dwarf2_cu
*cu
)
17349 struct dwarf2_section_info
*section
;
17351 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
17353 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17354 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
17355 else if (cu
->per_cu
->is_dwz
)
17357 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
17359 section
= &dwz
->line
;
17362 section
= &dwarf2_per_objfile
->line
;
17367 /* Read the statement program header starting at OFFSET in
17368 .debug_line, or .debug_line.dwo. Return a pointer
17369 to a struct line_header, allocated using xmalloc.
17370 Returns NULL if there is a problem reading the header, e.g., if it
17371 has a version we don't understand.
17373 NOTE: the strings in the include directory and file name tables of
17374 the returned object point into the dwarf line section buffer,
17375 and must not be freed. */
17377 static struct line_header
*
17378 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
17380 struct cleanup
*back_to
;
17381 struct line_header
*lh
;
17382 const gdb_byte
*line_ptr
;
17383 unsigned int bytes_read
, offset_size
;
17385 const char *cur_dir
, *cur_file
;
17386 struct dwarf2_section_info
*section
;
17389 section
= get_debug_line_section (cu
);
17390 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
17391 if (section
->buffer
== NULL
)
17393 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17394 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
17396 complaint (&symfile_complaints
, _("missing .debug_line section"));
17400 /* We can't do this until we know the section is non-empty.
17401 Only then do we know we have such a section. */
17402 abfd
= get_section_bfd_owner (section
);
17404 /* Make sure that at least there's room for the total_length field.
17405 That could be 12 bytes long, but we're just going to fudge that. */
17406 if (offset
+ 4 >= section
->size
)
17408 dwarf2_statement_list_fits_in_line_number_section_complaint ();
17412 lh
= XNEW (struct line_header
);
17413 memset (lh
, 0, sizeof (*lh
));
17414 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
17417 lh
->offset
.sect_off
= offset
;
17418 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
17420 line_ptr
= section
->buffer
+ offset
;
17422 /* Read in the header. */
17424 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
17425 &bytes_read
, &offset_size
);
17426 line_ptr
+= bytes_read
;
17427 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
17429 dwarf2_statement_list_fits_in_line_number_section_complaint ();
17430 do_cleanups (back_to
);
17433 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
17434 lh
->version
= read_2_bytes (abfd
, line_ptr
);
17436 if (lh
->version
> 4)
17438 /* This is a version we don't understand. The format could have
17439 changed in ways we don't handle properly so just punt. */
17440 complaint (&symfile_complaints
,
17441 _("unsupported version in .debug_line section"));
17444 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
17445 line_ptr
+= offset_size
;
17446 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
17448 if (lh
->version
>= 4)
17450 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
17454 lh
->maximum_ops_per_instruction
= 1;
17456 if (lh
->maximum_ops_per_instruction
== 0)
17458 lh
->maximum_ops_per_instruction
= 1;
17459 complaint (&symfile_complaints
,
17460 _("invalid maximum_ops_per_instruction "
17461 "in `.debug_line' section"));
17464 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
17466 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
17468 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
17470 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
17472 lh
->standard_opcode_lengths
= XNEWVEC (unsigned char, lh
->opcode_base
);
17474 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
17475 for (i
= 1; i
< lh
->opcode_base
; ++i
)
17477 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
17481 /* Read directory table. */
17482 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
17484 line_ptr
+= bytes_read
;
17485 add_include_dir (lh
, cur_dir
);
17487 line_ptr
+= bytes_read
;
17489 /* Read file name table. */
17490 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
17492 unsigned int dir_index
, mod_time
, length
;
17494 line_ptr
+= bytes_read
;
17495 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17496 line_ptr
+= bytes_read
;
17497 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17498 line_ptr
+= bytes_read
;
17499 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17500 line_ptr
+= bytes_read
;
17502 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
17504 line_ptr
+= bytes_read
;
17505 lh
->statement_program_start
= line_ptr
;
17507 if (line_ptr
> (section
->buffer
+ section
->size
))
17508 complaint (&symfile_complaints
,
17509 _("line number info header doesn't "
17510 "fit in `.debug_line' section"));
17512 discard_cleanups (back_to
);
17516 /* Subroutine of dwarf_decode_lines to simplify it.
17517 Return the file name of the psymtab for included file FILE_INDEX
17518 in line header LH of PST.
17519 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
17520 If space for the result is malloc'd, it will be freed by a cleanup.
17521 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
17523 The function creates dangling cleanup registration. */
17525 static const char *
17526 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
17527 const struct partial_symtab
*pst
,
17528 const char *comp_dir
)
17530 const struct file_entry fe
= lh
->file_names
[file_index
];
17531 const char *include_name
= fe
.name
;
17532 const char *include_name_to_compare
= include_name
;
17533 const char *dir_name
= NULL
;
17534 const char *pst_filename
;
17535 char *copied_name
= NULL
;
17538 if (fe
.dir_index
&& lh
->include_dirs
!= NULL
)
17539 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
17541 if (!IS_ABSOLUTE_PATH (include_name
)
17542 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
17544 /* Avoid creating a duplicate psymtab for PST.
17545 We do this by comparing INCLUDE_NAME and PST_FILENAME.
17546 Before we do the comparison, however, we need to account
17547 for DIR_NAME and COMP_DIR.
17548 First prepend dir_name (if non-NULL). If we still don't
17549 have an absolute path prepend comp_dir (if non-NULL).
17550 However, the directory we record in the include-file's
17551 psymtab does not contain COMP_DIR (to match the
17552 corresponding symtab(s)).
17557 bash$ gcc -g ./hello.c
17558 include_name = "hello.c"
17560 DW_AT_comp_dir = comp_dir = "/tmp"
17561 DW_AT_name = "./hello.c"
17565 if (dir_name
!= NULL
)
17567 char *tem
= concat (dir_name
, SLASH_STRING
,
17568 include_name
, (char *)NULL
);
17570 make_cleanup (xfree
, tem
);
17571 include_name
= tem
;
17572 include_name_to_compare
= include_name
;
17574 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
17576 char *tem
= concat (comp_dir
, SLASH_STRING
,
17577 include_name
, (char *)NULL
);
17579 make_cleanup (xfree
, tem
);
17580 include_name_to_compare
= tem
;
17584 pst_filename
= pst
->filename
;
17585 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
17587 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
17588 pst_filename
, (char *)NULL
);
17589 pst_filename
= copied_name
;
17592 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
17594 if (copied_name
!= NULL
)
17595 xfree (copied_name
);
17599 return include_name
;
17602 /* State machine to track the state of the line number program. */
17606 /* These are part of the standard DWARF line number state machine. */
17608 unsigned char op_index
;
17613 unsigned int discriminator
;
17615 /* Additional bits of state we need to track. */
17617 /* The last file that we called dwarf2_start_subfile for.
17618 This is only used for TLLs. */
17619 unsigned int last_file
;
17620 /* The last file a line number was recorded for. */
17621 struct subfile
*last_subfile
;
17623 /* The function to call to record a line. */
17624 record_line_ftype
*record_line
;
17626 /* The last line number that was recorded, used to coalesce
17627 consecutive entries for the same line. This can happen, for
17628 example, when discriminators are present. PR 17276. */
17629 unsigned int last_line
;
17630 int line_has_non_zero_discriminator
;
17631 } lnp_state_machine
;
17633 /* There's a lot of static state to pass to dwarf_record_line.
17634 This keeps it all together. */
17639 struct gdbarch
*gdbarch
;
17641 /* The line number header. */
17642 struct line_header
*line_header
;
17644 /* Non-zero if we're recording lines.
17645 Otherwise we're building partial symtabs and are just interested in
17646 finding include files mentioned by the line number program. */
17647 int record_lines_p
;
17648 } lnp_reader_state
;
17650 /* Ignore this record_line request. */
17653 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
17658 /* Return non-zero if we should add LINE to the line number table.
17659 LINE is the line to add, LAST_LINE is the last line that was added,
17660 LAST_SUBFILE is the subfile for LAST_LINE.
17661 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
17662 had a non-zero discriminator.
17664 We have to be careful in the presence of discriminators.
17665 E.g., for this line:
17667 for (i = 0; i < 100000; i++);
17669 clang can emit four line number entries for that one line,
17670 each with a different discriminator.
17671 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
17673 However, we want gdb to coalesce all four entries into one.
17674 Otherwise the user could stepi into the middle of the line and
17675 gdb would get confused about whether the pc really was in the
17676 middle of the line.
17678 Things are further complicated by the fact that two consecutive
17679 line number entries for the same line is a heuristic used by gcc
17680 to denote the end of the prologue. So we can't just discard duplicate
17681 entries, we have to be selective about it. The heuristic we use is
17682 that we only collapse consecutive entries for the same line if at least
17683 one of those entries has a non-zero discriminator. PR 17276.
17685 Note: Addresses in the line number state machine can never go backwards
17686 within one sequence, thus this coalescing is ok. */
17689 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
17690 int line_has_non_zero_discriminator
,
17691 struct subfile
*last_subfile
)
17693 if (current_subfile
!= last_subfile
)
17695 if (line
!= last_line
)
17697 /* Same line for the same file that we've seen already.
17698 As a last check, for pr 17276, only record the line if the line
17699 has never had a non-zero discriminator. */
17700 if (!line_has_non_zero_discriminator
)
17705 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
17706 in the line table of subfile SUBFILE. */
17709 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
17710 unsigned int line
, CORE_ADDR address
,
17711 record_line_ftype p_record_line
)
17713 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
17715 if (dwarf_line_debug
)
17717 fprintf_unfiltered (gdb_stdlog
,
17718 "Recording line %u, file %s, address %s\n",
17719 line
, lbasename (subfile
->name
),
17720 paddress (gdbarch
, address
));
17723 (*p_record_line
) (subfile
, line
, addr
);
17726 /* Subroutine of dwarf_decode_lines_1 to simplify it.
17727 Mark the end of a set of line number records.
17728 The arguments are the same as for dwarf_record_line_1.
17729 If SUBFILE is NULL the request is ignored. */
17732 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
17733 CORE_ADDR address
, record_line_ftype p_record_line
)
17735 if (subfile
== NULL
)
17738 if (dwarf_line_debug
)
17740 fprintf_unfiltered (gdb_stdlog
,
17741 "Finishing current line, file %s, address %s\n",
17742 lbasename (subfile
->name
),
17743 paddress (gdbarch
, address
));
17746 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
17749 /* Record the line in STATE.
17750 END_SEQUENCE is non-zero if we're processing the end of a sequence. */
17753 dwarf_record_line (lnp_reader_state
*reader
, lnp_state_machine
*state
,
17756 const struct line_header
*lh
= reader
->line_header
;
17757 unsigned int file
, line
, discriminator
;
17760 file
= state
->file
;
17761 line
= state
->line
;
17762 is_stmt
= state
->is_stmt
;
17763 discriminator
= state
->discriminator
;
17765 if (dwarf_line_debug
)
17767 fprintf_unfiltered (gdb_stdlog
,
17768 "Processing actual line %u: file %u,"
17769 " address %s, is_stmt %u, discrim %u\n",
17771 paddress (reader
->gdbarch
, state
->address
),
17772 is_stmt
, discriminator
);
17775 if (file
== 0 || file
- 1 >= lh
->num_file_names
)
17776 dwarf2_debug_line_missing_file_complaint ();
17777 /* For now we ignore lines not starting on an instruction boundary.
17778 But not when processing end_sequence for compatibility with the
17779 previous version of the code. */
17780 else if (state
->op_index
== 0 || end_sequence
)
17782 lh
->file_names
[file
- 1].included_p
= 1;
17783 if (reader
->record_lines_p
&& is_stmt
)
17785 if (state
->last_subfile
!= current_subfile
|| end_sequence
)
17787 dwarf_finish_line (reader
->gdbarch
, state
->last_subfile
,
17788 state
->address
, state
->record_line
);
17793 if (dwarf_record_line_p (line
, state
->last_line
,
17794 state
->line_has_non_zero_discriminator
,
17795 state
->last_subfile
))
17797 dwarf_record_line_1 (reader
->gdbarch
, current_subfile
,
17798 line
, state
->address
,
17799 state
->record_line
);
17801 state
->last_subfile
= current_subfile
;
17802 state
->last_line
= line
;
17808 /* Initialize STATE for the start of a line number program. */
17811 init_lnp_state_machine (lnp_state_machine
*state
,
17812 const lnp_reader_state
*reader
)
17814 memset (state
, 0, sizeof (*state
));
17816 /* Just starting, there is no "last file". */
17817 state
->last_file
= 0;
17818 state
->last_subfile
= NULL
;
17820 state
->record_line
= record_line
;
17822 state
->last_line
= 0;
17823 state
->line_has_non_zero_discriminator
= 0;
17825 /* Initialize these according to the DWARF spec. */
17826 state
->op_index
= 0;
17829 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
17830 was a line entry for it so that the backend has a chance to adjust it
17831 and also record it in case it needs it. This is currently used by MIPS
17832 code, cf. `mips_adjust_dwarf2_line'. */
17833 state
->address
= gdbarch_adjust_dwarf2_line (reader
->gdbarch
, 0, 0);
17834 state
->is_stmt
= reader
->line_header
->default_is_stmt
;
17835 state
->discriminator
= 0;
17838 /* Check address and if invalid nop-out the rest of the lines in this
17842 check_line_address (struct dwarf2_cu
*cu
, lnp_state_machine
*state
,
17843 const gdb_byte
*line_ptr
,
17844 CORE_ADDR lowpc
, CORE_ADDR address
)
17846 /* If address < lowpc then it's not a usable value, it's outside the
17847 pc range of the CU. However, we restrict the test to only address
17848 values of zero to preserve GDB's previous behaviour which is to
17849 handle the specific case of a function being GC'd by the linker. */
17851 if (address
== 0 && address
< lowpc
)
17853 /* This line table is for a function which has been
17854 GCd by the linker. Ignore it. PR gdb/12528 */
17856 struct objfile
*objfile
= cu
->objfile
;
17857 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
17859 complaint (&symfile_complaints
,
17860 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
17861 line_offset
, objfile_name (objfile
));
17862 state
->record_line
= noop_record_line
;
17863 /* Note: sm.record_line is left as noop_record_line
17864 until we see DW_LNE_end_sequence. */
17868 /* Subroutine of dwarf_decode_lines to simplify it.
17869 Process the line number information in LH.
17870 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
17871 program in order to set included_p for every referenced header. */
17874 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
17875 const int decode_for_pst_p
, CORE_ADDR lowpc
)
17877 const gdb_byte
*line_ptr
, *extended_end
;
17878 const gdb_byte
*line_end
;
17879 unsigned int bytes_read
, extended_len
;
17880 unsigned char op_code
, extended_op
;
17881 CORE_ADDR baseaddr
;
17882 struct objfile
*objfile
= cu
->objfile
;
17883 bfd
*abfd
= objfile
->obfd
;
17884 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17885 /* Non-zero if we're recording line info (as opposed to building partial
17887 int record_lines_p
= !decode_for_pst_p
;
17888 /* A collection of things we need to pass to dwarf_record_line. */
17889 lnp_reader_state reader_state
;
17891 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17893 line_ptr
= lh
->statement_program_start
;
17894 line_end
= lh
->statement_program_end
;
17896 reader_state
.gdbarch
= gdbarch
;
17897 reader_state
.line_header
= lh
;
17898 reader_state
.record_lines_p
= record_lines_p
;
17900 /* Read the statement sequences until there's nothing left. */
17901 while (line_ptr
< line_end
)
17903 /* The DWARF line number program state machine. */
17904 lnp_state_machine state_machine
;
17905 int end_sequence
= 0;
17907 /* Reset the state machine at the start of each sequence. */
17908 init_lnp_state_machine (&state_machine
, &reader_state
);
17910 if (record_lines_p
&& lh
->num_file_names
>= state_machine
.file
)
17912 /* Start a subfile for the current file of the state machine. */
17913 /* lh->include_dirs and lh->file_names are 0-based, but the
17914 directory and file name numbers in the statement program
17916 struct file_entry
*fe
= &lh
->file_names
[state_machine
.file
- 1];
17917 const char *dir
= NULL
;
17919 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
17920 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
17922 dwarf2_start_subfile (fe
->name
, dir
);
17925 /* Decode the table. */
17926 while (line_ptr
< line_end
&& !end_sequence
)
17928 op_code
= read_1_byte (abfd
, line_ptr
);
17931 if (op_code
>= lh
->opcode_base
)
17933 /* Special opcode. */
17934 unsigned char adj_opcode
;
17935 CORE_ADDR addr_adj
;
17938 adj_opcode
= op_code
- lh
->opcode_base
;
17939 addr_adj
= (((state_machine
.op_index
17940 + (adj_opcode
/ lh
->line_range
))
17941 / lh
->maximum_ops_per_instruction
)
17942 * lh
->minimum_instruction_length
);
17943 state_machine
.address
17944 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
17945 state_machine
.op_index
= ((state_machine
.op_index
17946 + (adj_opcode
/ lh
->line_range
))
17947 % lh
->maximum_ops_per_instruction
);
17948 line_delta
= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
17949 state_machine
.line
+= line_delta
;
17950 if (line_delta
!= 0)
17951 state_machine
.line_has_non_zero_discriminator
17952 = state_machine
.discriminator
!= 0;
17954 dwarf_record_line (&reader_state
, &state_machine
, 0);
17955 state_machine
.discriminator
= 0;
17957 else switch (op_code
)
17959 case DW_LNS_extended_op
:
17960 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
17962 line_ptr
+= bytes_read
;
17963 extended_end
= line_ptr
+ extended_len
;
17964 extended_op
= read_1_byte (abfd
, line_ptr
);
17966 switch (extended_op
)
17968 case DW_LNE_end_sequence
:
17969 state_machine
.record_line
= record_line
;
17972 case DW_LNE_set_address
:
17975 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
17977 line_ptr
+= bytes_read
;
17978 check_line_address (cu
, &state_machine
, line_ptr
,
17980 state_machine
.op_index
= 0;
17981 address
+= baseaddr
;
17982 state_machine
.address
17983 = gdbarch_adjust_dwarf2_line (gdbarch
, address
, 0);
17986 case DW_LNE_define_file
:
17988 const char *cur_file
;
17989 unsigned int dir_index
, mod_time
, length
;
17991 cur_file
= read_direct_string (abfd
, line_ptr
,
17993 line_ptr
+= bytes_read
;
17995 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17996 line_ptr
+= bytes_read
;
17998 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17999 line_ptr
+= bytes_read
;
18001 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18002 line_ptr
+= bytes_read
;
18003 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
18006 case DW_LNE_set_discriminator
:
18007 /* The discriminator is not interesting to the debugger;
18008 just ignore it. We still need to check its value though:
18009 if there are consecutive entries for the same
18010 (non-prologue) line we want to coalesce them.
18012 state_machine
.discriminator
18013 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18014 state_machine
.line_has_non_zero_discriminator
18015 |= state_machine
.discriminator
!= 0;
18016 line_ptr
+= bytes_read
;
18019 complaint (&symfile_complaints
,
18020 _("mangled .debug_line section"));
18023 /* Make sure that we parsed the extended op correctly. If e.g.
18024 we expected a different address size than the producer used,
18025 we may have read the wrong number of bytes. */
18026 if (line_ptr
!= extended_end
)
18028 complaint (&symfile_complaints
,
18029 _("mangled .debug_line section"));
18034 dwarf_record_line (&reader_state
, &state_machine
, 0);
18035 state_machine
.discriminator
= 0;
18037 case DW_LNS_advance_pc
:
18040 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18041 CORE_ADDR addr_adj
;
18043 addr_adj
= (((state_machine
.op_index
+ adjust
)
18044 / lh
->maximum_ops_per_instruction
)
18045 * lh
->minimum_instruction_length
);
18046 state_machine
.address
18047 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
18048 state_machine
.op_index
= ((state_machine
.op_index
+ adjust
)
18049 % lh
->maximum_ops_per_instruction
);
18050 line_ptr
+= bytes_read
;
18053 case DW_LNS_advance_line
:
18056 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
18058 state_machine
.line
+= line_delta
;
18059 if (line_delta
!= 0)
18060 state_machine
.line_has_non_zero_discriminator
18061 = state_machine
.discriminator
!= 0;
18062 line_ptr
+= bytes_read
;
18065 case DW_LNS_set_file
:
18067 /* The arrays lh->include_dirs and lh->file_names are
18068 0-based, but the directory and file name numbers in
18069 the statement program are 1-based. */
18070 struct file_entry
*fe
;
18071 const char *dir
= NULL
;
18073 state_machine
.file
= read_unsigned_leb128 (abfd
, line_ptr
,
18075 line_ptr
+= bytes_read
;
18076 if (state_machine
.file
== 0
18077 || state_machine
.file
- 1 >= lh
->num_file_names
)
18078 dwarf2_debug_line_missing_file_complaint ();
18081 fe
= &lh
->file_names
[state_machine
.file
- 1];
18082 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
18083 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
18084 if (record_lines_p
)
18086 state_machine
.last_subfile
= current_subfile
;
18087 state_machine
.line_has_non_zero_discriminator
18088 = state_machine
.discriminator
!= 0;
18089 dwarf2_start_subfile (fe
->name
, dir
);
18094 case DW_LNS_set_column
:
18095 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18096 line_ptr
+= bytes_read
;
18098 case DW_LNS_negate_stmt
:
18099 state_machine
.is_stmt
= (!state_machine
.is_stmt
);
18101 case DW_LNS_set_basic_block
:
18103 /* Add to the address register of the state machine the
18104 address increment value corresponding to special opcode
18105 255. I.e., this value is scaled by the minimum
18106 instruction length since special opcode 255 would have
18107 scaled the increment. */
18108 case DW_LNS_const_add_pc
:
18110 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
18111 CORE_ADDR addr_adj
;
18113 addr_adj
= (((state_machine
.op_index
+ adjust
)
18114 / lh
->maximum_ops_per_instruction
)
18115 * lh
->minimum_instruction_length
);
18116 state_machine
.address
18117 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
18118 state_machine
.op_index
= ((state_machine
.op_index
+ adjust
)
18119 % lh
->maximum_ops_per_instruction
);
18122 case DW_LNS_fixed_advance_pc
:
18124 CORE_ADDR addr_adj
;
18126 addr_adj
= read_2_bytes (abfd
, line_ptr
);
18127 state_machine
.address
18128 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
18129 state_machine
.op_index
= 0;
18135 /* Unknown standard opcode, ignore it. */
18138 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
18140 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18141 line_ptr
+= bytes_read
;
18148 dwarf2_debug_line_missing_end_sequence_complaint ();
18150 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
18151 in which case we still finish recording the last line). */
18152 dwarf_record_line (&reader_state
, &state_machine
, 1);
18156 /* Decode the Line Number Program (LNP) for the given line_header
18157 structure and CU. The actual information extracted and the type
18158 of structures created from the LNP depends on the value of PST.
18160 1. If PST is NULL, then this procedure uses the data from the program
18161 to create all necessary symbol tables, and their linetables.
18163 2. If PST is not NULL, this procedure reads the program to determine
18164 the list of files included by the unit represented by PST, and
18165 builds all the associated partial symbol tables.
18167 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
18168 It is used for relative paths in the line table.
18169 NOTE: When processing partial symtabs (pst != NULL),
18170 comp_dir == pst->dirname.
18172 NOTE: It is important that psymtabs have the same file name (via strcmp)
18173 as the corresponding symtab. Since COMP_DIR is not used in the name of the
18174 symtab we don't use it in the name of the psymtabs we create.
18175 E.g. expand_line_sal requires this when finding psymtabs to expand.
18176 A good testcase for this is mb-inline.exp.
18178 LOWPC is the lowest address in CU (or 0 if not known).
18180 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
18181 for its PC<->lines mapping information. Otherwise only the filename
18182 table is read in. */
18185 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
18186 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
18187 CORE_ADDR lowpc
, int decode_mapping
)
18189 struct objfile
*objfile
= cu
->objfile
;
18190 const int decode_for_pst_p
= (pst
!= NULL
);
18192 if (decode_mapping
)
18193 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
18195 if (decode_for_pst_p
)
18199 /* Now that we're done scanning the Line Header Program, we can
18200 create the psymtab of each included file. */
18201 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
18202 if (lh
->file_names
[file_index
].included_p
== 1)
18204 const char *include_name
=
18205 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
18206 if (include_name
!= NULL
)
18207 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
18212 /* Make sure a symtab is created for every file, even files
18213 which contain only variables (i.e. no code with associated
18215 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
18218 for (i
= 0; i
< lh
->num_file_names
; i
++)
18220 const char *dir
= NULL
;
18221 struct file_entry
*fe
;
18223 fe
= &lh
->file_names
[i
];
18224 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
18225 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
18226 dwarf2_start_subfile (fe
->name
, dir
);
18228 if (current_subfile
->symtab
== NULL
)
18230 current_subfile
->symtab
18231 = allocate_symtab (cust
, current_subfile
->name
);
18233 fe
->symtab
= current_subfile
->symtab
;
18238 /* Start a subfile for DWARF. FILENAME is the name of the file and
18239 DIRNAME the name of the source directory which contains FILENAME
18240 or NULL if not known.
18241 This routine tries to keep line numbers from identical absolute and
18242 relative file names in a common subfile.
18244 Using the `list' example from the GDB testsuite, which resides in
18245 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
18246 of /srcdir/list0.c yields the following debugging information for list0.c:
18248 DW_AT_name: /srcdir/list0.c
18249 DW_AT_comp_dir: /compdir
18250 files.files[0].name: list0.h
18251 files.files[0].dir: /srcdir
18252 files.files[1].name: list0.c
18253 files.files[1].dir: /srcdir
18255 The line number information for list0.c has to end up in a single
18256 subfile, so that `break /srcdir/list0.c:1' works as expected.
18257 start_subfile will ensure that this happens provided that we pass the
18258 concatenation of files.files[1].dir and files.files[1].name as the
18262 dwarf2_start_subfile (const char *filename
, const char *dirname
)
18266 /* In order not to lose the line information directory,
18267 we concatenate it to the filename when it makes sense.
18268 Note that the Dwarf3 standard says (speaking of filenames in line
18269 information): ``The directory index is ignored for file names
18270 that represent full path names''. Thus ignoring dirname in the
18271 `else' branch below isn't an issue. */
18273 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
18275 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
18279 start_subfile (filename
);
18285 /* Start a symtab for DWARF.
18286 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
18288 static struct compunit_symtab
*
18289 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
18290 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
18292 struct compunit_symtab
*cust
18293 = start_symtab (cu
->objfile
, name
, comp_dir
, low_pc
);
18295 record_debugformat ("DWARF 2");
18296 record_producer (cu
->producer
);
18298 /* We assume that we're processing GCC output. */
18299 processing_gcc_compilation
= 2;
18301 cu
->processing_has_namespace_info
= 0;
18307 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
18308 struct dwarf2_cu
*cu
)
18310 struct objfile
*objfile
= cu
->objfile
;
18311 struct comp_unit_head
*cu_header
= &cu
->header
;
18313 /* NOTE drow/2003-01-30: There used to be a comment and some special
18314 code here to turn a symbol with DW_AT_external and a
18315 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
18316 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
18317 with some versions of binutils) where shared libraries could have
18318 relocations against symbols in their debug information - the
18319 minimal symbol would have the right address, but the debug info
18320 would not. It's no longer necessary, because we will explicitly
18321 apply relocations when we read in the debug information now. */
18323 /* A DW_AT_location attribute with no contents indicates that a
18324 variable has been optimized away. */
18325 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
18327 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
18331 /* Handle one degenerate form of location expression specially, to
18332 preserve GDB's previous behavior when section offsets are
18333 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
18334 then mark this symbol as LOC_STATIC. */
18336 if (attr_form_is_block (attr
)
18337 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
18338 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
18339 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
18340 && (DW_BLOCK (attr
)->size
18341 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
18343 unsigned int dummy
;
18345 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
18346 SYMBOL_VALUE_ADDRESS (sym
) =
18347 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
18349 SYMBOL_VALUE_ADDRESS (sym
) =
18350 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
18351 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
18352 fixup_symbol_section (sym
, objfile
);
18353 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
18354 SYMBOL_SECTION (sym
));
18358 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
18359 expression evaluator, and use LOC_COMPUTED only when necessary
18360 (i.e. when the value of a register or memory location is
18361 referenced, or a thread-local block, etc.). Then again, it might
18362 not be worthwhile. I'm assuming that it isn't unless performance
18363 or memory numbers show me otherwise. */
18365 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
18367 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
18368 cu
->has_loclist
= 1;
18371 /* Given a pointer to a DWARF information entry, figure out if we need
18372 to make a symbol table entry for it, and if so, create a new entry
18373 and return a pointer to it.
18374 If TYPE is NULL, determine symbol type from the die, otherwise
18375 used the passed type.
18376 If SPACE is not NULL, use it to hold the new symbol. If it is
18377 NULL, allocate a new symbol on the objfile's obstack. */
18379 static struct symbol
*
18380 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
18381 struct symbol
*space
)
18383 struct objfile
*objfile
= cu
->objfile
;
18384 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18385 struct symbol
*sym
= NULL
;
18387 struct attribute
*attr
= NULL
;
18388 struct attribute
*attr2
= NULL
;
18389 CORE_ADDR baseaddr
;
18390 struct pending
**list_to_add
= NULL
;
18392 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
18394 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18396 name
= dwarf2_name (die
, cu
);
18399 const char *linkagename
;
18400 int suppress_add
= 0;
18405 sym
= allocate_symbol (objfile
);
18406 OBJSTAT (objfile
, n_syms
++);
18408 /* Cache this symbol's name and the name's demangled form (if any). */
18409 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
18410 linkagename
= dwarf2_physname (name
, die
, cu
);
18411 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
18413 /* Fortran does not have mangling standard and the mangling does differ
18414 between gfortran, iFort etc. */
18415 if (cu
->language
== language_fortran
18416 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
18417 symbol_set_demangled_name (&(sym
->ginfo
),
18418 dwarf2_full_name (name
, die
, cu
),
18421 /* Default assumptions.
18422 Use the passed type or decode it from the die. */
18423 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
18424 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
18426 SYMBOL_TYPE (sym
) = type
;
18428 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
18429 attr
= dwarf2_attr (die
,
18430 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
18434 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
18437 attr
= dwarf2_attr (die
,
18438 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
18442 int file_index
= DW_UNSND (attr
);
18444 if (cu
->line_header
== NULL
18445 || file_index
> cu
->line_header
->num_file_names
)
18446 complaint (&symfile_complaints
,
18447 _("file index out of range"));
18448 else if (file_index
> 0)
18450 struct file_entry
*fe
;
18452 fe
= &cu
->line_header
->file_names
[file_index
- 1];
18453 symbol_set_symtab (sym
, fe
->symtab
);
18460 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
18465 addr
= attr_value_as_address (attr
);
18466 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
18467 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
18469 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
18470 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
18471 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
18472 add_symbol_to_list (sym
, cu
->list_in_scope
);
18474 case DW_TAG_subprogram
:
18475 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
18477 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
18478 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18479 if ((attr2
&& (DW_UNSND (attr2
) != 0))
18480 || cu
->language
== language_ada
)
18482 /* Subprograms marked external are stored as a global symbol.
18483 Ada subprograms, whether marked external or not, are always
18484 stored as a global symbol, because we want to be able to
18485 access them globally. For instance, we want to be able
18486 to break on a nested subprogram without having to
18487 specify the context. */
18488 list_to_add
= &global_symbols
;
18492 list_to_add
= cu
->list_in_scope
;
18495 case DW_TAG_inlined_subroutine
:
18496 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
18498 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
18499 SYMBOL_INLINED (sym
) = 1;
18500 list_to_add
= cu
->list_in_scope
;
18502 case DW_TAG_template_value_param
:
18504 /* Fall through. */
18505 case DW_TAG_constant
:
18506 case DW_TAG_variable
:
18507 case DW_TAG_member
:
18508 /* Compilation with minimal debug info may result in
18509 variables with missing type entries. Change the
18510 misleading `void' type to something sensible. */
18511 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
18513 = objfile_type (objfile
)->nodebug_data_symbol
;
18515 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
18516 /* In the case of DW_TAG_member, we should only be called for
18517 static const members. */
18518 if (die
->tag
== DW_TAG_member
)
18520 /* dwarf2_add_field uses die_is_declaration,
18521 so we do the same. */
18522 gdb_assert (die_is_declaration (die
, cu
));
18527 dwarf2_const_value (attr
, sym
, cu
);
18528 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18531 if (attr2
&& (DW_UNSND (attr2
) != 0))
18532 list_to_add
= &global_symbols
;
18534 list_to_add
= cu
->list_in_scope
;
18538 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
18541 var_decode_location (attr
, sym
, cu
);
18542 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18544 /* Fortran explicitly imports any global symbols to the local
18545 scope by DW_TAG_common_block. */
18546 if (cu
->language
== language_fortran
&& die
->parent
18547 && die
->parent
->tag
== DW_TAG_common_block
)
18550 if (SYMBOL_CLASS (sym
) == LOC_STATIC
18551 && SYMBOL_VALUE_ADDRESS (sym
) == 0
18552 && !dwarf2_per_objfile
->has_section_at_zero
)
18554 /* When a static variable is eliminated by the linker,
18555 the corresponding debug information is not stripped
18556 out, but the variable address is set to null;
18557 do not add such variables into symbol table. */
18559 else if (attr2
&& (DW_UNSND (attr2
) != 0))
18561 /* Workaround gfortran PR debug/40040 - it uses
18562 DW_AT_location for variables in -fPIC libraries which may
18563 get overriden by other libraries/executable and get
18564 a different address. Resolve it by the minimal symbol
18565 which may come from inferior's executable using copy
18566 relocation. Make this workaround only for gfortran as for
18567 other compilers GDB cannot guess the minimal symbol
18568 Fortran mangling kind. */
18569 if (cu
->language
== language_fortran
&& die
->parent
18570 && die
->parent
->tag
== DW_TAG_module
18572 && startswith (cu
->producer
, "GNU Fortran"))
18573 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
18575 /* A variable with DW_AT_external is never static,
18576 but it may be block-scoped. */
18577 list_to_add
= (cu
->list_in_scope
== &file_symbols
18578 ? &global_symbols
: cu
->list_in_scope
);
18581 list_to_add
= cu
->list_in_scope
;
18585 /* We do not know the address of this symbol.
18586 If it is an external symbol and we have type information
18587 for it, enter the symbol as a LOC_UNRESOLVED symbol.
18588 The address of the variable will then be determined from
18589 the minimal symbol table whenever the variable is
18591 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18593 /* Fortran explicitly imports any global symbols to the local
18594 scope by DW_TAG_common_block. */
18595 if (cu
->language
== language_fortran
&& die
->parent
18596 && die
->parent
->tag
== DW_TAG_common_block
)
18598 /* SYMBOL_CLASS doesn't matter here because
18599 read_common_block is going to reset it. */
18601 list_to_add
= cu
->list_in_scope
;
18603 else if (attr2
&& (DW_UNSND (attr2
) != 0)
18604 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
18606 /* A variable with DW_AT_external is never static, but it
18607 may be block-scoped. */
18608 list_to_add
= (cu
->list_in_scope
== &file_symbols
18609 ? &global_symbols
: cu
->list_in_scope
);
18611 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
18613 else if (!die_is_declaration (die
, cu
))
18615 /* Use the default LOC_OPTIMIZED_OUT class. */
18616 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
18618 list_to_add
= cu
->list_in_scope
;
18622 case DW_TAG_formal_parameter
:
18623 /* If we are inside a function, mark this as an argument. If
18624 not, we might be looking at an argument to an inlined function
18625 when we do not have enough information to show inlined frames;
18626 pretend it's a local variable in that case so that the user can
18628 if (context_stack_depth
> 0
18629 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
18630 SYMBOL_IS_ARGUMENT (sym
) = 1;
18631 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
18634 var_decode_location (attr
, sym
, cu
);
18636 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
18639 dwarf2_const_value (attr
, sym
, cu
);
18642 list_to_add
= cu
->list_in_scope
;
18644 case DW_TAG_unspecified_parameters
:
18645 /* From varargs functions; gdb doesn't seem to have any
18646 interest in this information, so just ignore it for now.
18649 case DW_TAG_template_type_param
:
18651 /* Fall through. */
18652 case DW_TAG_class_type
:
18653 case DW_TAG_interface_type
:
18654 case DW_TAG_structure_type
:
18655 case DW_TAG_union_type
:
18656 case DW_TAG_set_type
:
18657 case DW_TAG_enumeration_type
:
18658 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
18659 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
18662 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
18663 really ever be static objects: otherwise, if you try
18664 to, say, break of a class's method and you're in a file
18665 which doesn't mention that class, it won't work unless
18666 the check for all static symbols in lookup_symbol_aux
18667 saves you. See the OtherFileClass tests in
18668 gdb.c++/namespace.exp. */
18672 list_to_add
= (cu
->list_in_scope
== &file_symbols
18673 && (cu
->language
== language_cplus
18674 || cu
->language
== language_java
)
18675 ? &global_symbols
: cu
->list_in_scope
);
18677 /* The semantics of C++ state that "struct foo {
18678 ... }" also defines a typedef for "foo". A Java
18679 class declaration also defines a typedef for the
18681 if (cu
->language
== language_cplus
18682 || cu
->language
== language_java
18683 || cu
->language
== language_ada
18684 || cu
->language
== language_d
18685 || cu
->language
== language_rust
)
18687 /* The symbol's name is already allocated along
18688 with this objfile, so we don't need to
18689 duplicate it for the type. */
18690 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
18691 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
18696 case DW_TAG_typedef
:
18697 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
18698 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
18699 list_to_add
= cu
->list_in_scope
;
18701 case DW_TAG_base_type
:
18702 case DW_TAG_subrange_type
:
18703 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
18704 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
18705 list_to_add
= cu
->list_in_scope
;
18707 case DW_TAG_enumerator
:
18708 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
18711 dwarf2_const_value (attr
, sym
, cu
);
18714 /* NOTE: carlton/2003-11-10: See comment above in the
18715 DW_TAG_class_type, etc. block. */
18717 list_to_add
= (cu
->list_in_scope
== &file_symbols
18718 && (cu
->language
== language_cplus
18719 || cu
->language
== language_java
)
18720 ? &global_symbols
: cu
->list_in_scope
);
18723 case DW_TAG_imported_declaration
:
18724 case DW_TAG_namespace
:
18725 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
18726 list_to_add
= &global_symbols
;
18728 case DW_TAG_module
:
18729 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
18730 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
18731 list_to_add
= &global_symbols
;
18733 case DW_TAG_common_block
:
18734 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
18735 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
18736 add_symbol_to_list (sym
, cu
->list_in_scope
);
18739 /* Not a tag we recognize. Hopefully we aren't processing
18740 trash data, but since we must specifically ignore things
18741 we don't recognize, there is nothing else we should do at
18743 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
18744 dwarf_tag_name (die
->tag
));
18750 sym
->hash_next
= objfile
->template_symbols
;
18751 objfile
->template_symbols
= sym
;
18752 list_to_add
= NULL
;
18755 if (list_to_add
!= NULL
)
18756 add_symbol_to_list (sym
, list_to_add
);
18758 /* For the benefit of old versions of GCC, check for anonymous
18759 namespaces based on the demangled name. */
18760 if (!cu
->processing_has_namespace_info
18761 && cu
->language
== language_cplus
)
18762 cp_scan_for_anonymous_namespaces (sym
, objfile
);
18767 /* A wrapper for new_symbol_full that always allocates a new symbol. */
18769 static struct symbol
*
18770 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
18772 return new_symbol_full (die
, type
, cu
, NULL
);
18775 /* Given an attr with a DW_FORM_dataN value in host byte order,
18776 zero-extend it as appropriate for the symbol's type. The DWARF
18777 standard (v4) is not entirely clear about the meaning of using
18778 DW_FORM_dataN for a constant with a signed type, where the type is
18779 wider than the data. The conclusion of a discussion on the DWARF
18780 list was that this is unspecified. We choose to always zero-extend
18781 because that is the interpretation long in use by GCC. */
18784 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
18785 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
18787 struct objfile
*objfile
= cu
->objfile
;
18788 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
18789 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
18790 LONGEST l
= DW_UNSND (attr
);
18792 if (bits
< sizeof (*value
) * 8)
18794 l
&= ((LONGEST
) 1 << bits
) - 1;
18797 else if (bits
== sizeof (*value
) * 8)
18801 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
18802 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
18809 /* Read a constant value from an attribute. Either set *VALUE, or if
18810 the value does not fit in *VALUE, set *BYTES - either already
18811 allocated on the objfile obstack, or newly allocated on OBSTACK,
18812 or, set *BATON, if we translated the constant to a location
18816 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
18817 const char *name
, struct obstack
*obstack
,
18818 struct dwarf2_cu
*cu
,
18819 LONGEST
*value
, const gdb_byte
**bytes
,
18820 struct dwarf2_locexpr_baton
**baton
)
18822 struct objfile
*objfile
= cu
->objfile
;
18823 struct comp_unit_head
*cu_header
= &cu
->header
;
18824 struct dwarf_block
*blk
;
18825 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
18826 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
18832 switch (attr
->form
)
18835 case DW_FORM_GNU_addr_index
:
18839 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
18840 dwarf2_const_value_length_mismatch_complaint (name
,
18841 cu_header
->addr_size
,
18842 TYPE_LENGTH (type
));
18843 /* Symbols of this form are reasonably rare, so we just
18844 piggyback on the existing location code rather than writing
18845 a new implementation of symbol_computed_ops. */
18846 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
18847 (*baton
)->per_cu
= cu
->per_cu
;
18848 gdb_assert ((*baton
)->per_cu
);
18850 (*baton
)->size
= 2 + cu_header
->addr_size
;
18851 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
18852 (*baton
)->data
= data
;
18854 data
[0] = DW_OP_addr
;
18855 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
18856 byte_order
, DW_ADDR (attr
));
18857 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
18860 case DW_FORM_string
:
18862 case DW_FORM_GNU_str_index
:
18863 case DW_FORM_GNU_strp_alt
:
18864 /* DW_STRING is already allocated on the objfile obstack, point
18866 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
18868 case DW_FORM_block1
:
18869 case DW_FORM_block2
:
18870 case DW_FORM_block4
:
18871 case DW_FORM_block
:
18872 case DW_FORM_exprloc
:
18873 blk
= DW_BLOCK (attr
);
18874 if (TYPE_LENGTH (type
) != blk
->size
)
18875 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
18876 TYPE_LENGTH (type
));
18877 *bytes
= blk
->data
;
18880 /* The DW_AT_const_value attributes are supposed to carry the
18881 symbol's value "represented as it would be on the target
18882 architecture." By the time we get here, it's already been
18883 converted to host endianness, so we just need to sign- or
18884 zero-extend it as appropriate. */
18885 case DW_FORM_data1
:
18886 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
18888 case DW_FORM_data2
:
18889 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
18891 case DW_FORM_data4
:
18892 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
18894 case DW_FORM_data8
:
18895 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
18898 case DW_FORM_sdata
:
18899 *value
= DW_SND (attr
);
18902 case DW_FORM_udata
:
18903 *value
= DW_UNSND (attr
);
18907 complaint (&symfile_complaints
,
18908 _("unsupported const value attribute form: '%s'"),
18909 dwarf_form_name (attr
->form
));
18916 /* Copy constant value from an attribute to a symbol. */
18919 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
18920 struct dwarf2_cu
*cu
)
18922 struct objfile
*objfile
= cu
->objfile
;
18924 const gdb_byte
*bytes
;
18925 struct dwarf2_locexpr_baton
*baton
;
18927 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
18928 SYMBOL_PRINT_NAME (sym
),
18929 &objfile
->objfile_obstack
, cu
,
18930 &value
, &bytes
, &baton
);
18934 SYMBOL_LOCATION_BATON (sym
) = baton
;
18935 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
18937 else if (bytes
!= NULL
)
18939 SYMBOL_VALUE_BYTES (sym
) = bytes
;
18940 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
18944 SYMBOL_VALUE (sym
) = value
;
18945 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
18949 /* Return the type of the die in question using its DW_AT_type attribute. */
18951 static struct type
*
18952 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18954 struct attribute
*type_attr
;
18956 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
18959 /* A missing DW_AT_type represents a void type. */
18960 return objfile_type (cu
->objfile
)->builtin_void
;
18963 return lookup_die_type (die
, type_attr
, cu
);
18966 /* True iff CU's producer generates GNAT Ada auxiliary information
18967 that allows to find parallel types through that information instead
18968 of having to do expensive parallel lookups by type name. */
18971 need_gnat_info (struct dwarf2_cu
*cu
)
18973 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
18974 of GNAT produces this auxiliary information, without any indication
18975 that it is produced. Part of enhancing the FSF version of GNAT
18976 to produce that information will be to put in place an indicator
18977 that we can use in order to determine whether the descriptive type
18978 info is available or not. One suggestion that has been made is
18979 to use a new attribute, attached to the CU die. For now, assume
18980 that the descriptive type info is not available. */
18984 /* Return the auxiliary type of the die in question using its
18985 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
18986 attribute is not present. */
18988 static struct type
*
18989 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18991 struct attribute
*type_attr
;
18993 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
18997 return lookup_die_type (die
, type_attr
, cu
);
19000 /* If DIE has a descriptive_type attribute, then set the TYPE's
19001 descriptive type accordingly. */
19004 set_descriptive_type (struct type
*type
, struct die_info
*die
,
19005 struct dwarf2_cu
*cu
)
19007 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
19009 if (descriptive_type
)
19011 ALLOCATE_GNAT_AUX_TYPE (type
);
19012 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
19016 /* Return the containing type of the die in question using its
19017 DW_AT_containing_type attribute. */
19019 static struct type
*
19020 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19022 struct attribute
*type_attr
;
19024 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
19026 error (_("Dwarf Error: Problem turning containing type into gdb type "
19027 "[in module %s]"), objfile_name (cu
->objfile
));
19029 return lookup_die_type (die
, type_attr
, cu
);
19032 /* Return an error marker type to use for the ill formed type in DIE/CU. */
19034 static struct type
*
19035 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
19037 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19038 char *message
, *saved
;
19040 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
19041 objfile_name (objfile
),
19042 cu
->header
.offset
.sect_off
,
19043 die
->offset
.sect_off
);
19044 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
19045 message
, strlen (message
));
19048 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
19051 /* Look up the type of DIE in CU using its type attribute ATTR.
19052 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
19053 DW_AT_containing_type.
19054 If there is no type substitute an error marker. */
19056 static struct type
*
19057 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
19058 struct dwarf2_cu
*cu
)
19060 struct objfile
*objfile
= cu
->objfile
;
19061 struct type
*this_type
;
19063 gdb_assert (attr
->name
== DW_AT_type
19064 || attr
->name
== DW_AT_GNAT_descriptive_type
19065 || attr
->name
== DW_AT_containing_type
);
19067 /* First see if we have it cached. */
19069 if (attr
->form
== DW_FORM_GNU_ref_alt
)
19071 struct dwarf2_per_cu_data
*per_cu
;
19072 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
19074 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
19075 this_type
= get_die_type_at_offset (offset
, per_cu
);
19077 else if (attr_form_is_ref (attr
))
19079 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
19081 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
19083 else if (attr
->form
== DW_FORM_ref_sig8
)
19085 ULONGEST signature
= DW_SIGNATURE (attr
);
19087 return get_signatured_type (die
, signature
, cu
);
19091 complaint (&symfile_complaints
,
19092 _("Dwarf Error: Bad type attribute %s in DIE"
19093 " at 0x%x [in module %s]"),
19094 dwarf_attr_name (attr
->name
), die
->offset
.sect_off
,
19095 objfile_name (objfile
));
19096 return build_error_marker_type (cu
, die
);
19099 /* If not cached we need to read it in. */
19101 if (this_type
== NULL
)
19103 struct die_info
*type_die
= NULL
;
19104 struct dwarf2_cu
*type_cu
= cu
;
19106 if (attr_form_is_ref (attr
))
19107 type_die
= follow_die_ref (die
, attr
, &type_cu
);
19108 if (type_die
== NULL
)
19109 return build_error_marker_type (cu
, die
);
19110 /* If we find the type now, it's probably because the type came
19111 from an inter-CU reference and the type's CU got expanded before
19113 this_type
= read_type_die (type_die
, type_cu
);
19116 /* If we still don't have a type use an error marker. */
19118 if (this_type
== NULL
)
19119 return build_error_marker_type (cu
, die
);
19124 /* Return the type in DIE, CU.
19125 Returns NULL for invalid types.
19127 This first does a lookup in die_type_hash,
19128 and only reads the die in if necessary.
19130 NOTE: This can be called when reading in partial or full symbols. */
19132 static struct type
*
19133 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
19135 struct type
*this_type
;
19137 this_type
= get_die_type (die
, cu
);
19141 return read_type_die_1 (die
, cu
);
19144 /* Read the type in DIE, CU.
19145 Returns NULL for invalid types. */
19147 static struct type
*
19148 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
19150 struct type
*this_type
= NULL
;
19154 case DW_TAG_class_type
:
19155 case DW_TAG_interface_type
:
19156 case DW_TAG_structure_type
:
19157 case DW_TAG_union_type
:
19158 this_type
= read_structure_type (die
, cu
);
19160 case DW_TAG_enumeration_type
:
19161 this_type
= read_enumeration_type (die
, cu
);
19163 case DW_TAG_subprogram
:
19164 case DW_TAG_subroutine_type
:
19165 case DW_TAG_inlined_subroutine
:
19166 this_type
= read_subroutine_type (die
, cu
);
19168 case DW_TAG_array_type
:
19169 this_type
= read_array_type (die
, cu
);
19171 case DW_TAG_set_type
:
19172 this_type
= read_set_type (die
, cu
);
19174 case DW_TAG_pointer_type
:
19175 this_type
= read_tag_pointer_type (die
, cu
);
19177 case DW_TAG_ptr_to_member_type
:
19178 this_type
= read_tag_ptr_to_member_type (die
, cu
);
19180 case DW_TAG_reference_type
:
19181 this_type
= read_tag_reference_type (die
, cu
);
19183 case DW_TAG_const_type
:
19184 this_type
= read_tag_const_type (die
, cu
);
19186 case DW_TAG_volatile_type
:
19187 this_type
= read_tag_volatile_type (die
, cu
);
19189 case DW_TAG_restrict_type
:
19190 this_type
= read_tag_restrict_type (die
, cu
);
19192 case DW_TAG_string_type
:
19193 this_type
= read_tag_string_type (die
, cu
);
19195 case DW_TAG_typedef
:
19196 this_type
= read_typedef (die
, cu
);
19198 case DW_TAG_subrange_type
:
19199 this_type
= read_subrange_type (die
, cu
);
19201 case DW_TAG_base_type
:
19202 this_type
= read_base_type (die
, cu
);
19204 case DW_TAG_unspecified_type
:
19205 this_type
= read_unspecified_type (die
, cu
);
19207 case DW_TAG_namespace
:
19208 this_type
= read_namespace_type (die
, cu
);
19210 case DW_TAG_module
:
19211 this_type
= read_module_type (die
, cu
);
19213 case DW_TAG_atomic_type
:
19214 this_type
= read_tag_atomic_type (die
, cu
);
19217 complaint (&symfile_complaints
,
19218 _("unexpected tag in read_type_die: '%s'"),
19219 dwarf_tag_name (die
->tag
));
19226 /* See if we can figure out if the class lives in a namespace. We do
19227 this by looking for a member function; its demangled name will
19228 contain namespace info, if there is any.
19229 Return the computed name or NULL.
19230 Space for the result is allocated on the objfile's obstack.
19231 This is the full-die version of guess_partial_die_structure_name.
19232 In this case we know DIE has no useful parent. */
19235 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19237 struct die_info
*spec_die
;
19238 struct dwarf2_cu
*spec_cu
;
19239 struct die_info
*child
;
19242 spec_die
= die_specification (die
, &spec_cu
);
19243 if (spec_die
!= NULL
)
19249 for (child
= die
->child
;
19251 child
= child
->sibling
)
19253 if (child
->tag
== DW_TAG_subprogram
)
19255 const char *linkage_name
;
19257 linkage_name
= dwarf2_string_attr (child
, DW_AT_linkage_name
, cu
);
19258 if (linkage_name
== NULL
)
19259 linkage_name
= dwarf2_string_attr (child
, DW_AT_MIPS_linkage_name
,
19261 if (linkage_name
!= NULL
)
19264 = language_class_name_from_physname (cu
->language_defn
,
19268 if (actual_name
!= NULL
)
19270 const char *die_name
= dwarf2_name (die
, cu
);
19272 if (die_name
!= NULL
19273 && strcmp (die_name
, actual_name
) != 0)
19275 /* Strip off the class name from the full name.
19276 We want the prefix. */
19277 int die_name_len
= strlen (die_name
);
19278 int actual_name_len
= strlen (actual_name
);
19280 /* Test for '::' as a sanity check. */
19281 if (actual_name_len
> die_name_len
+ 2
19282 && actual_name
[actual_name_len
19283 - die_name_len
- 1] == ':')
19284 name
= (char *) obstack_copy0 (
19285 &cu
->objfile
->per_bfd
->storage_obstack
,
19286 actual_name
, actual_name_len
- die_name_len
- 2);
19289 xfree (actual_name
);
19298 /* GCC might emit a nameless typedef that has a linkage name. Determine the
19299 prefix part in such case. See
19300 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19303 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19305 struct attribute
*attr
;
19308 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
19309 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
19312 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
19315 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
19317 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
19318 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
19321 /* dwarf2_name had to be already called. */
19322 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
19324 /* Strip the base name, keep any leading namespaces/classes. */
19325 base
= strrchr (DW_STRING (attr
), ':');
19326 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
19329 return (char *) obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
19331 &base
[-1] - DW_STRING (attr
));
19334 /* Return the name of the namespace/class that DIE is defined within,
19335 or "" if we can't tell. The caller should not xfree the result.
19337 For example, if we're within the method foo() in the following
19347 then determine_prefix on foo's die will return "N::C". */
19349 static const char *
19350 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19352 struct die_info
*parent
, *spec_die
;
19353 struct dwarf2_cu
*spec_cu
;
19354 struct type
*parent_type
;
19357 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
19358 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
19359 && cu
->language
!= language_rust
)
19362 retval
= anonymous_struct_prefix (die
, cu
);
19366 /* We have to be careful in the presence of DW_AT_specification.
19367 For example, with GCC 3.4, given the code
19371 // Definition of N::foo.
19375 then we'll have a tree of DIEs like this:
19377 1: DW_TAG_compile_unit
19378 2: DW_TAG_namespace // N
19379 3: DW_TAG_subprogram // declaration of N::foo
19380 4: DW_TAG_subprogram // definition of N::foo
19381 DW_AT_specification // refers to die #3
19383 Thus, when processing die #4, we have to pretend that we're in
19384 the context of its DW_AT_specification, namely the contex of die
19387 spec_die
= die_specification (die
, &spec_cu
);
19388 if (spec_die
== NULL
)
19389 parent
= die
->parent
;
19392 parent
= spec_die
->parent
;
19396 if (parent
== NULL
)
19398 else if (parent
->building_fullname
)
19401 const char *parent_name
;
19403 /* It has been seen on RealView 2.2 built binaries,
19404 DW_TAG_template_type_param types actually _defined_ as
19405 children of the parent class:
19408 template class <class Enum> Class{};
19409 Class<enum E> class_e;
19411 1: DW_TAG_class_type (Class)
19412 2: DW_TAG_enumeration_type (E)
19413 3: DW_TAG_enumerator (enum1:0)
19414 3: DW_TAG_enumerator (enum2:1)
19416 2: DW_TAG_template_type_param
19417 DW_AT_type DW_FORM_ref_udata (E)
19419 Besides being broken debug info, it can put GDB into an
19420 infinite loop. Consider:
19422 When we're building the full name for Class<E>, we'll start
19423 at Class, and go look over its template type parameters,
19424 finding E. We'll then try to build the full name of E, and
19425 reach here. We're now trying to build the full name of E,
19426 and look over the parent DIE for containing scope. In the
19427 broken case, if we followed the parent DIE of E, we'd again
19428 find Class, and once again go look at its template type
19429 arguments, etc., etc. Simply don't consider such parent die
19430 as source-level parent of this die (it can't be, the language
19431 doesn't allow it), and break the loop here. */
19432 name
= dwarf2_name (die
, cu
);
19433 parent_name
= dwarf2_name (parent
, cu
);
19434 complaint (&symfile_complaints
,
19435 _("template param type '%s' defined within parent '%s'"),
19436 name
? name
: "<unknown>",
19437 parent_name
? parent_name
: "<unknown>");
19441 switch (parent
->tag
)
19443 case DW_TAG_namespace
:
19444 parent_type
= read_type_die (parent
, cu
);
19445 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
19446 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
19447 Work around this problem here. */
19448 if (cu
->language
== language_cplus
19449 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
19451 /* We give a name to even anonymous namespaces. */
19452 return TYPE_TAG_NAME (parent_type
);
19453 case DW_TAG_class_type
:
19454 case DW_TAG_interface_type
:
19455 case DW_TAG_structure_type
:
19456 case DW_TAG_union_type
:
19457 case DW_TAG_module
:
19458 parent_type
= read_type_die (parent
, cu
);
19459 if (TYPE_TAG_NAME (parent_type
) != NULL
)
19460 return TYPE_TAG_NAME (parent_type
);
19462 /* An anonymous structure is only allowed non-static data
19463 members; no typedefs, no member functions, et cetera.
19464 So it does not need a prefix. */
19466 case DW_TAG_compile_unit
:
19467 case DW_TAG_partial_unit
:
19468 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
19469 if (cu
->language
== language_cplus
19470 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
19471 && die
->child
!= NULL
19472 && (die
->tag
== DW_TAG_class_type
19473 || die
->tag
== DW_TAG_structure_type
19474 || die
->tag
== DW_TAG_union_type
))
19476 char *name
= guess_full_die_structure_name (die
, cu
);
19481 case DW_TAG_enumeration_type
:
19482 parent_type
= read_type_die (parent
, cu
);
19483 if (TYPE_DECLARED_CLASS (parent_type
))
19485 if (TYPE_TAG_NAME (parent_type
) != NULL
)
19486 return TYPE_TAG_NAME (parent_type
);
19489 /* Fall through. */
19491 return determine_prefix (parent
, cu
);
19495 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
19496 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
19497 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
19498 an obconcat, otherwise allocate storage for the result. The CU argument is
19499 used to determine the language and hence, the appropriate separator. */
19501 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
19504 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
19505 int physname
, struct dwarf2_cu
*cu
)
19507 const char *lead
= "";
19510 if (suffix
== NULL
|| suffix
[0] == '\0'
19511 || prefix
== NULL
|| prefix
[0] == '\0')
19513 else if (cu
->language
== language_java
)
19515 else if (cu
->language
== language_d
)
19517 /* For D, the 'main' function could be defined in any module, but it
19518 should never be prefixed. */
19519 if (strcmp (suffix
, "D main") == 0)
19527 else if (cu
->language
== language_fortran
&& physname
)
19529 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
19530 DW_AT_MIPS_linkage_name is preferred and used instead. */
19538 if (prefix
== NULL
)
19540 if (suffix
== NULL
)
19547 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
19549 strcpy (retval
, lead
);
19550 strcat (retval
, prefix
);
19551 strcat (retval
, sep
);
19552 strcat (retval
, suffix
);
19557 /* We have an obstack. */
19558 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
19562 /* Return sibling of die, NULL if no sibling. */
19564 static struct die_info
*
19565 sibling_die (struct die_info
*die
)
19567 return die
->sibling
;
19570 /* Get name of a die, return NULL if not found. */
19572 static const char *
19573 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
19574 struct obstack
*obstack
)
19576 if (name
&& cu
->language
== language_cplus
)
19578 char *canon_name
= cp_canonicalize_string (name
);
19580 if (canon_name
!= NULL
)
19582 if (strcmp (canon_name
, name
) != 0)
19583 name
= (const char *) obstack_copy0 (obstack
, canon_name
,
19584 strlen (canon_name
));
19585 xfree (canon_name
);
19592 /* Get name of a die, return NULL if not found.
19593 Anonymous namespaces are converted to their magic string. */
19595 static const char *
19596 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19598 struct attribute
*attr
;
19600 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
19601 if ((!attr
|| !DW_STRING (attr
))
19602 && die
->tag
!= DW_TAG_namespace
19603 && die
->tag
!= DW_TAG_class_type
19604 && die
->tag
!= DW_TAG_interface_type
19605 && die
->tag
!= DW_TAG_structure_type
19606 && die
->tag
!= DW_TAG_union_type
)
19611 case DW_TAG_compile_unit
:
19612 case DW_TAG_partial_unit
:
19613 /* Compilation units have a DW_AT_name that is a filename, not
19614 a source language identifier. */
19615 case DW_TAG_enumeration_type
:
19616 case DW_TAG_enumerator
:
19617 /* These tags always have simple identifiers already; no need
19618 to canonicalize them. */
19619 return DW_STRING (attr
);
19621 case DW_TAG_namespace
:
19622 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
19623 return DW_STRING (attr
);
19624 return CP_ANONYMOUS_NAMESPACE_STR
;
19626 case DW_TAG_subprogram
:
19627 /* Java constructors will all be named "<init>", so return
19628 the class name when we see this special case. */
19629 if (cu
->language
== language_java
19630 && DW_STRING (attr
) != NULL
19631 && strcmp (DW_STRING (attr
), "<init>") == 0)
19633 struct dwarf2_cu
*spec_cu
= cu
;
19634 struct die_info
*spec_die
;
19636 /* GCJ will output '<init>' for Java constructor names.
19637 For this special case, return the name of the parent class. */
19639 /* GCJ may output subprogram DIEs with AT_specification set.
19640 If so, use the name of the specified DIE. */
19641 spec_die
= die_specification (die
, &spec_cu
);
19642 if (spec_die
!= NULL
)
19643 return dwarf2_name (spec_die
, spec_cu
);
19648 if (die
->tag
== DW_TAG_class_type
)
19649 return dwarf2_name (die
, cu
);
19651 while (die
->tag
!= DW_TAG_compile_unit
19652 && die
->tag
!= DW_TAG_partial_unit
);
19656 case DW_TAG_class_type
:
19657 case DW_TAG_interface_type
:
19658 case DW_TAG_structure_type
:
19659 case DW_TAG_union_type
:
19660 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
19661 structures or unions. These were of the form "._%d" in GCC 4.1,
19662 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
19663 and GCC 4.4. We work around this problem by ignoring these. */
19664 if (attr
&& DW_STRING (attr
)
19665 && (startswith (DW_STRING (attr
), "._")
19666 || startswith (DW_STRING (attr
), "<anonymous")))
19669 /* GCC might emit a nameless typedef that has a linkage name. See
19670 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19671 if (!attr
|| DW_STRING (attr
) == NULL
)
19673 char *demangled
= NULL
;
19675 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
19677 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
19679 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
19682 /* Avoid demangling DW_STRING (attr) the second time on a second
19683 call for the same DIE. */
19684 if (!DW_STRING_IS_CANONICAL (attr
))
19685 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
19691 /* FIXME: we already did this for the partial symbol... */
19694 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
19695 demangled
, strlen (demangled
)));
19696 DW_STRING_IS_CANONICAL (attr
) = 1;
19699 /* Strip any leading namespaces/classes, keep only the base name.
19700 DW_AT_name for named DIEs does not contain the prefixes. */
19701 base
= strrchr (DW_STRING (attr
), ':');
19702 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
19705 return DW_STRING (attr
);
19714 if (!DW_STRING_IS_CANONICAL (attr
))
19717 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
19718 &cu
->objfile
->per_bfd
->storage_obstack
);
19719 DW_STRING_IS_CANONICAL (attr
) = 1;
19721 return DW_STRING (attr
);
19724 /* Return the die that this die in an extension of, or NULL if there
19725 is none. *EXT_CU is the CU containing DIE on input, and the CU
19726 containing the return value on output. */
19728 static struct die_info
*
19729 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
19731 struct attribute
*attr
;
19733 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
19737 return follow_die_ref (die
, attr
, ext_cu
);
19740 /* Convert a DIE tag into its string name. */
19742 static const char *
19743 dwarf_tag_name (unsigned tag
)
19745 const char *name
= get_DW_TAG_name (tag
);
19748 return "DW_TAG_<unknown>";
19753 /* Convert a DWARF attribute code into its string name. */
19755 static const char *
19756 dwarf_attr_name (unsigned attr
)
19760 #ifdef MIPS /* collides with DW_AT_HP_block_index */
19761 if (attr
== DW_AT_MIPS_fde
)
19762 return "DW_AT_MIPS_fde";
19764 if (attr
== DW_AT_HP_block_index
)
19765 return "DW_AT_HP_block_index";
19768 name
= get_DW_AT_name (attr
);
19771 return "DW_AT_<unknown>";
19776 /* Convert a DWARF value form code into its string name. */
19778 static const char *
19779 dwarf_form_name (unsigned form
)
19781 const char *name
= get_DW_FORM_name (form
);
19784 return "DW_FORM_<unknown>";
19790 dwarf_bool_name (unsigned mybool
)
19798 /* Convert a DWARF type code into its string name. */
19800 static const char *
19801 dwarf_type_encoding_name (unsigned enc
)
19803 const char *name
= get_DW_ATE_name (enc
);
19806 return "DW_ATE_<unknown>";
19812 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
19816 print_spaces (indent
, f
);
19817 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
19818 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
19820 if (die
->parent
!= NULL
)
19822 print_spaces (indent
, f
);
19823 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
19824 die
->parent
->offset
.sect_off
);
19827 print_spaces (indent
, f
);
19828 fprintf_unfiltered (f
, " has children: %s\n",
19829 dwarf_bool_name (die
->child
!= NULL
));
19831 print_spaces (indent
, f
);
19832 fprintf_unfiltered (f
, " attributes:\n");
19834 for (i
= 0; i
< die
->num_attrs
; ++i
)
19836 print_spaces (indent
, f
);
19837 fprintf_unfiltered (f
, " %s (%s) ",
19838 dwarf_attr_name (die
->attrs
[i
].name
),
19839 dwarf_form_name (die
->attrs
[i
].form
));
19841 switch (die
->attrs
[i
].form
)
19844 case DW_FORM_GNU_addr_index
:
19845 fprintf_unfiltered (f
, "address: ");
19846 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
19848 case DW_FORM_block2
:
19849 case DW_FORM_block4
:
19850 case DW_FORM_block
:
19851 case DW_FORM_block1
:
19852 fprintf_unfiltered (f
, "block: size %s",
19853 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
19855 case DW_FORM_exprloc
:
19856 fprintf_unfiltered (f
, "expression: size %s",
19857 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
19859 case DW_FORM_ref_addr
:
19860 fprintf_unfiltered (f
, "ref address: ");
19861 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
19863 case DW_FORM_GNU_ref_alt
:
19864 fprintf_unfiltered (f
, "alt ref address: ");
19865 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
19871 case DW_FORM_ref_udata
:
19872 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
19873 (long) (DW_UNSND (&die
->attrs
[i
])));
19875 case DW_FORM_data1
:
19876 case DW_FORM_data2
:
19877 case DW_FORM_data4
:
19878 case DW_FORM_data8
:
19879 case DW_FORM_udata
:
19880 case DW_FORM_sdata
:
19881 fprintf_unfiltered (f
, "constant: %s",
19882 pulongest (DW_UNSND (&die
->attrs
[i
])));
19884 case DW_FORM_sec_offset
:
19885 fprintf_unfiltered (f
, "section offset: %s",
19886 pulongest (DW_UNSND (&die
->attrs
[i
])));
19888 case DW_FORM_ref_sig8
:
19889 fprintf_unfiltered (f
, "signature: %s",
19890 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
19892 case DW_FORM_string
:
19894 case DW_FORM_GNU_str_index
:
19895 case DW_FORM_GNU_strp_alt
:
19896 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
19897 DW_STRING (&die
->attrs
[i
])
19898 ? DW_STRING (&die
->attrs
[i
]) : "",
19899 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
19902 if (DW_UNSND (&die
->attrs
[i
]))
19903 fprintf_unfiltered (f
, "flag: TRUE");
19905 fprintf_unfiltered (f
, "flag: FALSE");
19907 case DW_FORM_flag_present
:
19908 fprintf_unfiltered (f
, "flag: TRUE");
19910 case DW_FORM_indirect
:
19911 /* The reader will have reduced the indirect form to
19912 the "base form" so this form should not occur. */
19913 fprintf_unfiltered (f
,
19914 "unexpected attribute form: DW_FORM_indirect");
19917 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
19918 die
->attrs
[i
].form
);
19921 fprintf_unfiltered (f
, "\n");
19926 dump_die_for_error (struct die_info
*die
)
19928 dump_die_shallow (gdb_stderr
, 0, die
);
19932 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
19934 int indent
= level
* 4;
19936 gdb_assert (die
!= NULL
);
19938 if (level
>= max_level
)
19941 dump_die_shallow (f
, indent
, die
);
19943 if (die
->child
!= NULL
)
19945 print_spaces (indent
, f
);
19946 fprintf_unfiltered (f
, " Children:");
19947 if (level
+ 1 < max_level
)
19949 fprintf_unfiltered (f
, "\n");
19950 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
19954 fprintf_unfiltered (f
,
19955 " [not printed, max nesting level reached]\n");
19959 if (die
->sibling
!= NULL
&& level
> 0)
19961 dump_die_1 (f
, level
, max_level
, die
->sibling
);
19965 /* This is called from the pdie macro in gdbinit.in.
19966 It's not static so gcc will keep a copy callable from gdb. */
19969 dump_die (struct die_info
*die
, int max_level
)
19971 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
19975 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
19979 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
19985 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
19989 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
19991 sect_offset retval
= { DW_UNSND (attr
) };
19993 if (attr_form_is_ref (attr
))
19996 retval
.sect_off
= 0;
19997 complaint (&symfile_complaints
,
19998 _("unsupported die ref attribute form: '%s'"),
19999 dwarf_form_name (attr
->form
));
20003 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
20004 * the value held by the attribute is not constant. */
20007 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
20009 if (attr
->form
== DW_FORM_sdata
)
20010 return DW_SND (attr
);
20011 else if (attr
->form
== DW_FORM_udata
20012 || attr
->form
== DW_FORM_data1
20013 || attr
->form
== DW_FORM_data2
20014 || attr
->form
== DW_FORM_data4
20015 || attr
->form
== DW_FORM_data8
)
20016 return DW_UNSND (attr
);
20019 complaint (&symfile_complaints
,
20020 _("Attribute value is not a constant (%s)"),
20021 dwarf_form_name (attr
->form
));
20022 return default_value
;
20026 /* Follow reference or signature attribute ATTR of SRC_DIE.
20027 On entry *REF_CU is the CU of SRC_DIE.
20028 On exit *REF_CU is the CU of the result. */
20030 static struct die_info
*
20031 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20032 struct dwarf2_cu
**ref_cu
)
20034 struct die_info
*die
;
20036 if (attr_form_is_ref (attr
))
20037 die
= follow_die_ref (src_die
, attr
, ref_cu
);
20038 else if (attr
->form
== DW_FORM_ref_sig8
)
20039 die
= follow_die_sig (src_die
, attr
, ref_cu
);
20042 dump_die_for_error (src_die
);
20043 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
20044 objfile_name ((*ref_cu
)->objfile
));
20050 /* Follow reference OFFSET.
20051 On entry *REF_CU is the CU of the source die referencing OFFSET.
20052 On exit *REF_CU is the CU of the result.
20053 Returns NULL if OFFSET is invalid. */
20055 static struct die_info
*
20056 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
20057 struct dwarf2_cu
**ref_cu
)
20059 struct die_info temp_die
;
20060 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
20062 gdb_assert (cu
->per_cu
!= NULL
);
20066 if (cu
->per_cu
->is_debug_types
)
20068 /* .debug_types CUs cannot reference anything outside their CU.
20069 If they need to, they have to reference a signatured type via
20070 DW_FORM_ref_sig8. */
20071 if (! offset_in_cu_p (&cu
->header
, offset
))
20074 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
20075 || ! offset_in_cu_p (&cu
->header
, offset
))
20077 struct dwarf2_per_cu_data
*per_cu
;
20079 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
20082 /* If necessary, add it to the queue and load its DIEs. */
20083 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
20084 load_full_comp_unit (per_cu
, cu
->language
);
20086 target_cu
= per_cu
->cu
;
20088 else if (cu
->dies
== NULL
)
20090 /* We're loading full DIEs during partial symbol reading. */
20091 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
20092 load_full_comp_unit (cu
->per_cu
, language_minimal
);
20095 *ref_cu
= target_cu
;
20096 temp_die
.offset
= offset
;
20097 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
20098 &temp_die
, offset
.sect_off
);
20101 /* Follow reference attribute ATTR of SRC_DIE.
20102 On entry *REF_CU is the CU of SRC_DIE.
20103 On exit *REF_CU is the CU of the result. */
20105 static struct die_info
*
20106 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
20107 struct dwarf2_cu
**ref_cu
)
20109 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
20110 struct dwarf2_cu
*cu
= *ref_cu
;
20111 struct die_info
*die
;
20113 die
= follow_die_offset (offset
,
20114 (attr
->form
== DW_FORM_GNU_ref_alt
20115 || cu
->per_cu
->is_dwz
),
20118 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
20119 "at 0x%x [in module %s]"),
20120 offset
.sect_off
, src_die
->offset
.sect_off
,
20121 objfile_name (cu
->objfile
));
20126 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
20127 Returned value is intended for DW_OP_call*. Returned
20128 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
20130 struct dwarf2_locexpr_baton
20131 dwarf2_fetch_die_loc_sect_off (sect_offset offset
,
20132 struct dwarf2_per_cu_data
*per_cu
,
20133 CORE_ADDR (*get_frame_pc
) (void *baton
),
20136 struct dwarf2_cu
*cu
;
20137 struct die_info
*die
;
20138 struct attribute
*attr
;
20139 struct dwarf2_locexpr_baton retval
;
20141 dw2_setup (per_cu
->objfile
);
20143 if (per_cu
->cu
== NULL
)
20148 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20149 Instead just throw an error, not much else we can do. */
20150 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
20151 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20154 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
20156 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
20157 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20159 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20162 /* DWARF: "If there is no such attribute, then there is no effect.".
20163 DATA is ignored if SIZE is 0. */
20165 retval
.data
= NULL
;
20168 else if (attr_form_is_section_offset (attr
))
20170 struct dwarf2_loclist_baton loclist_baton
;
20171 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
20174 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
20176 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
20178 retval
.size
= size
;
20182 if (!attr_form_is_block (attr
))
20183 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
20184 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
20185 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20187 retval
.data
= DW_BLOCK (attr
)->data
;
20188 retval
.size
= DW_BLOCK (attr
)->size
;
20190 retval
.per_cu
= cu
->per_cu
;
20192 age_cached_comp_units ();
20197 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
20200 struct dwarf2_locexpr_baton
20201 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
20202 struct dwarf2_per_cu_data
*per_cu
,
20203 CORE_ADDR (*get_frame_pc
) (void *baton
),
20206 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
20208 return dwarf2_fetch_die_loc_sect_off (offset
, per_cu
, get_frame_pc
, baton
);
20211 /* Write a constant of a given type as target-ordered bytes into
20214 static const gdb_byte
*
20215 write_constant_as_bytes (struct obstack
*obstack
,
20216 enum bfd_endian byte_order
,
20223 *len
= TYPE_LENGTH (type
);
20224 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20225 store_unsigned_integer (result
, *len
, byte_order
, value
);
20230 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
20231 pointer to the constant bytes and set LEN to the length of the
20232 data. If memory is needed, allocate it on OBSTACK. If the DIE
20233 does not have a DW_AT_const_value, return NULL. */
20236 dwarf2_fetch_constant_bytes (sect_offset offset
,
20237 struct dwarf2_per_cu_data
*per_cu
,
20238 struct obstack
*obstack
,
20241 struct dwarf2_cu
*cu
;
20242 struct die_info
*die
;
20243 struct attribute
*attr
;
20244 const gdb_byte
*result
= NULL
;
20247 enum bfd_endian byte_order
;
20249 dw2_setup (per_cu
->objfile
);
20251 if (per_cu
->cu
== NULL
)
20256 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20257 Instead just throw an error, not much else we can do. */
20258 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
20259 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20262 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
20264 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
20265 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20268 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20272 byte_order
= (bfd_big_endian (per_cu
->objfile
->obfd
)
20273 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20275 switch (attr
->form
)
20278 case DW_FORM_GNU_addr_index
:
20282 *len
= cu
->header
.addr_size
;
20283 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20284 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
20288 case DW_FORM_string
:
20290 case DW_FORM_GNU_str_index
:
20291 case DW_FORM_GNU_strp_alt
:
20292 /* DW_STRING is already allocated on the objfile obstack, point
20294 result
= (const gdb_byte
*) DW_STRING (attr
);
20295 *len
= strlen (DW_STRING (attr
));
20297 case DW_FORM_block1
:
20298 case DW_FORM_block2
:
20299 case DW_FORM_block4
:
20300 case DW_FORM_block
:
20301 case DW_FORM_exprloc
:
20302 result
= DW_BLOCK (attr
)->data
;
20303 *len
= DW_BLOCK (attr
)->size
;
20306 /* The DW_AT_const_value attributes are supposed to carry the
20307 symbol's value "represented as it would be on the target
20308 architecture." By the time we get here, it's already been
20309 converted to host endianness, so we just need to sign- or
20310 zero-extend it as appropriate. */
20311 case DW_FORM_data1
:
20312 type
= die_type (die
, cu
);
20313 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
20314 if (result
== NULL
)
20315 result
= write_constant_as_bytes (obstack
, byte_order
,
20318 case DW_FORM_data2
:
20319 type
= die_type (die
, cu
);
20320 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
20321 if (result
== NULL
)
20322 result
= write_constant_as_bytes (obstack
, byte_order
,
20325 case DW_FORM_data4
:
20326 type
= die_type (die
, cu
);
20327 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
20328 if (result
== NULL
)
20329 result
= write_constant_as_bytes (obstack
, byte_order
,
20332 case DW_FORM_data8
:
20333 type
= die_type (die
, cu
);
20334 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
20335 if (result
== NULL
)
20336 result
= write_constant_as_bytes (obstack
, byte_order
,
20340 case DW_FORM_sdata
:
20341 type
= die_type (die
, cu
);
20342 result
= write_constant_as_bytes (obstack
, byte_order
,
20343 type
, DW_SND (attr
), len
);
20346 case DW_FORM_udata
:
20347 type
= die_type (die
, cu
);
20348 result
= write_constant_as_bytes (obstack
, byte_order
,
20349 type
, DW_UNSND (attr
), len
);
20353 complaint (&symfile_complaints
,
20354 _("unsupported const value attribute form: '%s'"),
20355 dwarf_form_name (attr
->form
));
20362 /* Return the type of the DIE at DIE_OFFSET in the CU named by
20366 dwarf2_get_die_type (cu_offset die_offset
,
20367 struct dwarf2_per_cu_data
*per_cu
)
20369 sect_offset die_offset_sect
;
20371 dw2_setup (per_cu
->objfile
);
20373 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
20374 return get_die_type_at_offset (die_offset_sect
, per_cu
);
20377 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
20378 On entry *REF_CU is the CU of SRC_DIE.
20379 On exit *REF_CU is the CU of the result.
20380 Returns NULL if the referenced DIE isn't found. */
20382 static struct die_info
*
20383 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
20384 struct dwarf2_cu
**ref_cu
)
20386 struct die_info temp_die
;
20387 struct dwarf2_cu
*sig_cu
;
20388 struct die_info
*die
;
20390 /* While it might be nice to assert sig_type->type == NULL here,
20391 we can get here for DW_AT_imported_declaration where we need
20392 the DIE not the type. */
20394 /* If necessary, add it to the queue and load its DIEs. */
20396 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
20397 read_signatured_type (sig_type
);
20399 sig_cu
= sig_type
->per_cu
.cu
;
20400 gdb_assert (sig_cu
!= NULL
);
20401 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
20402 temp_die
.offset
= sig_type
->type_offset_in_section
;
20403 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
20404 temp_die
.offset
.sect_off
);
20407 /* For .gdb_index version 7 keep track of included TUs.
20408 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
20409 if (dwarf2_per_objfile
->index_table
!= NULL
20410 && dwarf2_per_objfile
->index_table
->version
<= 7)
20412 VEC_safe_push (dwarf2_per_cu_ptr
,
20413 (*ref_cu
)->per_cu
->imported_symtabs
,
20424 /* Follow signatured type referenced by ATTR in SRC_DIE.
20425 On entry *REF_CU is the CU of SRC_DIE.
20426 On exit *REF_CU is the CU of the result.
20427 The result is the DIE of the type.
20428 If the referenced type cannot be found an error is thrown. */
20430 static struct die_info
*
20431 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20432 struct dwarf2_cu
**ref_cu
)
20434 ULONGEST signature
= DW_SIGNATURE (attr
);
20435 struct signatured_type
*sig_type
;
20436 struct die_info
*die
;
20438 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
20440 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
20441 /* sig_type will be NULL if the signatured type is missing from
20443 if (sig_type
== NULL
)
20445 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
20446 " from DIE at 0x%x [in module %s]"),
20447 hex_string (signature
), src_die
->offset
.sect_off
,
20448 objfile_name ((*ref_cu
)->objfile
));
20451 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
20454 dump_die_for_error (src_die
);
20455 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
20456 " from DIE at 0x%x [in module %s]"),
20457 hex_string (signature
), src_die
->offset
.sect_off
,
20458 objfile_name ((*ref_cu
)->objfile
));
20464 /* Get the type specified by SIGNATURE referenced in DIE/CU,
20465 reading in and processing the type unit if necessary. */
20467 static struct type
*
20468 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
20469 struct dwarf2_cu
*cu
)
20471 struct signatured_type
*sig_type
;
20472 struct dwarf2_cu
*type_cu
;
20473 struct die_info
*type_die
;
20476 sig_type
= lookup_signatured_type (cu
, signature
);
20477 /* sig_type will be NULL if the signatured type is missing from
20479 if (sig_type
== NULL
)
20481 complaint (&symfile_complaints
,
20482 _("Dwarf Error: Cannot find signatured DIE %s referenced"
20483 " from DIE at 0x%x [in module %s]"),
20484 hex_string (signature
), die
->offset
.sect_off
,
20485 objfile_name (dwarf2_per_objfile
->objfile
));
20486 return build_error_marker_type (cu
, die
);
20489 /* If we already know the type we're done. */
20490 if (sig_type
->type
!= NULL
)
20491 return sig_type
->type
;
20494 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
20495 if (type_die
!= NULL
)
20497 /* N.B. We need to call get_die_type to ensure only one type for this DIE
20498 is created. This is important, for example, because for c++ classes
20499 we need TYPE_NAME set which is only done by new_symbol. Blech. */
20500 type
= read_type_die (type_die
, type_cu
);
20503 complaint (&symfile_complaints
,
20504 _("Dwarf Error: Cannot build signatured type %s"
20505 " referenced from DIE at 0x%x [in module %s]"),
20506 hex_string (signature
), die
->offset
.sect_off
,
20507 objfile_name (dwarf2_per_objfile
->objfile
));
20508 type
= build_error_marker_type (cu
, die
);
20513 complaint (&symfile_complaints
,
20514 _("Dwarf Error: Problem reading signatured DIE %s referenced"
20515 " from DIE at 0x%x [in module %s]"),
20516 hex_string (signature
), die
->offset
.sect_off
,
20517 objfile_name (dwarf2_per_objfile
->objfile
));
20518 type
= build_error_marker_type (cu
, die
);
20520 sig_type
->type
= type
;
20525 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
20526 reading in and processing the type unit if necessary. */
20528 static struct type
*
20529 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
20530 struct dwarf2_cu
*cu
) /* ARI: editCase function */
20532 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
20533 if (attr_form_is_ref (attr
))
20535 struct dwarf2_cu
*type_cu
= cu
;
20536 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
20538 return read_type_die (type_die
, type_cu
);
20540 else if (attr
->form
== DW_FORM_ref_sig8
)
20542 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
20546 complaint (&symfile_complaints
,
20547 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
20548 " at 0x%x [in module %s]"),
20549 dwarf_form_name (attr
->form
), die
->offset
.sect_off
,
20550 objfile_name (dwarf2_per_objfile
->objfile
));
20551 return build_error_marker_type (cu
, die
);
20555 /* Load the DIEs associated with type unit PER_CU into memory. */
20558 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
20560 struct signatured_type
*sig_type
;
20562 /* Caller is responsible for ensuring type_unit_groups don't get here. */
20563 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
20565 /* We have the per_cu, but we need the signatured_type.
20566 Fortunately this is an easy translation. */
20567 gdb_assert (per_cu
->is_debug_types
);
20568 sig_type
= (struct signatured_type
*) per_cu
;
20570 gdb_assert (per_cu
->cu
== NULL
);
20572 read_signatured_type (sig_type
);
20574 gdb_assert (per_cu
->cu
!= NULL
);
20577 /* die_reader_func for read_signatured_type.
20578 This is identical to load_full_comp_unit_reader,
20579 but is kept separate for now. */
20582 read_signatured_type_reader (const struct die_reader_specs
*reader
,
20583 const gdb_byte
*info_ptr
,
20584 struct die_info
*comp_unit_die
,
20588 struct dwarf2_cu
*cu
= reader
->cu
;
20590 gdb_assert (cu
->die_hash
== NULL
);
20592 htab_create_alloc_ex (cu
->header
.length
/ 12,
20596 &cu
->comp_unit_obstack
,
20597 hashtab_obstack_allocate
,
20598 dummy_obstack_deallocate
);
20601 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
20602 &info_ptr
, comp_unit_die
);
20603 cu
->dies
= comp_unit_die
;
20604 /* comp_unit_die is not stored in die_hash, no need. */
20606 /* We try not to read any attributes in this function, because not
20607 all CUs needed for references have been loaded yet, and symbol
20608 table processing isn't initialized. But we have to set the CU language,
20609 or we won't be able to build types correctly.
20610 Similarly, if we do not read the producer, we can not apply
20611 producer-specific interpretation. */
20612 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
20615 /* Read in a signatured type and build its CU and DIEs.
20616 If the type is a stub for the real type in a DWO file,
20617 read in the real type from the DWO file as well. */
20620 read_signatured_type (struct signatured_type
*sig_type
)
20622 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
20624 gdb_assert (per_cu
->is_debug_types
);
20625 gdb_assert (per_cu
->cu
== NULL
);
20627 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
20628 read_signatured_type_reader
, NULL
);
20629 sig_type
->per_cu
.tu_read
= 1;
20632 /* Decode simple location descriptions.
20633 Given a pointer to a dwarf block that defines a location, compute
20634 the location and return the value.
20636 NOTE drow/2003-11-18: This function is called in two situations
20637 now: for the address of static or global variables (partial symbols
20638 only) and for offsets into structures which are expected to be
20639 (more or less) constant. The partial symbol case should go away,
20640 and only the constant case should remain. That will let this
20641 function complain more accurately. A few special modes are allowed
20642 without complaint for global variables (for instance, global
20643 register values and thread-local values).
20645 A location description containing no operations indicates that the
20646 object is optimized out. The return value is 0 for that case.
20647 FIXME drow/2003-11-16: No callers check for this case any more; soon all
20648 callers will only want a very basic result and this can become a
20651 Note that stack[0] is unused except as a default error return. */
20654 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
20656 struct objfile
*objfile
= cu
->objfile
;
20658 size_t size
= blk
->size
;
20659 const gdb_byte
*data
= blk
->data
;
20660 CORE_ADDR stack
[64];
20662 unsigned int bytes_read
, unsnd
;
20668 stack
[++stacki
] = 0;
20707 stack
[++stacki
] = op
- DW_OP_lit0
;
20742 stack
[++stacki
] = op
- DW_OP_reg0
;
20744 dwarf2_complex_location_expr_complaint ();
20748 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
20750 stack
[++stacki
] = unsnd
;
20752 dwarf2_complex_location_expr_complaint ();
20756 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
20761 case DW_OP_const1u
:
20762 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
20766 case DW_OP_const1s
:
20767 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
20771 case DW_OP_const2u
:
20772 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
20776 case DW_OP_const2s
:
20777 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
20781 case DW_OP_const4u
:
20782 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
20786 case DW_OP_const4s
:
20787 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
20791 case DW_OP_const8u
:
20792 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
20797 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
20803 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
20808 stack
[stacki
+ 1] = stack
[stacki
];
20813 stack
[stacki
- 1] += stack
[stacki
];
20817 case DW_OP_plus_uconst
:
20818 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
20824 stack
[stacki
- 1] -= stack
[stacki
];
20829 /* If we're not the last op, then we definitely can't encode
20830 this using GDB's address_class enum. This is valid for partial
20831 global symbols, although the variable's address will be bogus
20834 dwarf2_complex_location_expr_complaint ();
20837 case DW_OP_GNU_push_tls_address
:
20838 case DW_OP_form_tls_address
:
20839 /* The top of the stack has the offset from the beginning
20840 of the thread control block at which the variable is located. */
20841 /* Nothing should follow this operator, so the top of stack would
20843 /* This is valid for partial global symbols, but the variable's
20844 address will be bogus in the psymtab. Make it always at least
20845 non-zero to not look as a variable garbage collected by linker
20846 which have DW_OP_addr 0. */
20848 dwarf2_complex_location_expr_complaint ();
20852 case DW_OP_GNU_uninit
:
20855 case DW_OP_GNU_addr_index
:
20856 case DW_OP_GNU_const_index
:
20857 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
20864 const char *name
= get_DW_OP_name (op
);
20867 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
20870 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
20874 return (stack
[stacki
]);
20877 /* Enforce maximum stack depth of SIZE-1 to avoid writing
20878 outside of the allocated space. Also enforce minimum>0. */
20879 if (stacki
>= ARRAY_SIZE (stack
) - 1)
20881 complaint (&symfile_complaints
,
20882 _("location description stack overflow"));
20888 complaint (&symfile_complaints
,
20889 _("location description stack underflow"));
20893 return (stack
[stacki
]);
20896 /* memory allocation interface */
20898 static struct dwarf_block
*
20899 dwarf_alloc_block (struct dwarf2_cu
*cu
)
20901 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
20904 static struct die_info
*
20905 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
20907 struct die_info
*die
;
20908 size_t size
= sizeof (struct die_info
);
20911 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
20913 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
20914 memset (die
, 0, sizeof (struct die_info
));
20919 /* Macro support. */
20921 /* Return file name relative to the compilation directory of file number I in
20922 *LH's file name table. The result is allocated using xmalloc; the caller is
20923 responsible for freeing it. */
20926 file_file_name (int file
, struct line_header
*lh
)
20928 /* Is the file number a valid index into the line header's file name
20929 table? Remember that file numbers start with one, not zero. */
20930 if (1 <= file
&& file
<= lh
->num_file_names
)
20932 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
20934 if (IS_ABSOLUTE_PATH (fe
->name
) || fe
->dir_index
== 0
20935 || lh
->include_dirs
== NULL
)
20936 return xstrdup (fe
->name
);
20937 return concat (lh
->include_dirs
[fe
->dir_index
- 1], SLASH_STRING
,
20938 fe
->name
, (char *) NULL
);
20942 /* The compiler produced a bogus file number. We can at least
20943 record the macro definitions made in the file, even if we
20944 won't be able to find the file by name. */
20945 char fake_name
[80];
20947 xsnprintf (fake_name
, sizeof (fake_name
),
20948 "<bad macro file number %d>", file
);
20950 complaint (&symfile_complaints
,
20951 _("bad file number in macro information (%d)"),
20954 return xstrdup (fake_name
);
20958 /* Return the full name of file number I in *LH's file name table.
20959 Use COMP_DIR as the name of the current directory of the
20960 compilation. The result is allocated using xmalloc; the caller is
20961 responsible for freeing it. */
20963 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
20965 /* Is the file number a valid index into the line header's file name
20966 table? Remember that file numbers start with one, not zero. */
20967 if (1 <= file
&& file
<= lh
->num_file_names
)
20969 char *relative
= file_file_name (file
, lh
);
20971 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
20973 return reconcat (relative
, comp_dir
, SLASH_STRING
,
20974 relative
, (char *) NULL
);
20977 return file_file_name (file
, lh
);
20981 static struct macro_source_file
*
20982 macro_start_file (int file
, int line
,
20983 struct macro_source_file
*current_file
,
20984 struct line_header
*lh
)
20986 /* File name relative to the compilation directory of this source file. */
20987 char *file_name
= file_file_name (file
, lh
);
20989 if (! current_file
)
20991 /* Note: We don't create a macro table for this compilation unit
20992 at all until we actually get a filename. */
20993 struct macro_table
*macro_table
= get_macro_table ();
20995 /* If we have no current file, then this must be the start_file
20996 directive for the compilation unit's main source file. */
20997 current_file
= macro_set_main (macro_table
, file_name
);
20998 macro_define_special (macro_table
);
21001 current_file
= macro_include (current_file
, line
, file_name
);
21005 return current_file
;
21009 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
21010 followed by a null byte. */
21012 copy_string (const char *buf
, int len
)
21014 char *s
= (char *) xmalloc (len
+ 1);
21016 memcpy (s
, buf
, len
);
21022 static const char *
21023 consume_improper_spaces (const char *p
, const char *body
)
21027 complaint (&symfile_complaints
,
21028 _("macro definition contains spaces "
21029 "in formal argument list:\n`%s'"),
21041 parse_macro_definition (struct macro_source_file
*file
, int line
,
21046 /* The body string takes one of two forms. For object-like macro
21047 definitions, it should be:
21049 <macro name> " " <definition>
21051 For function-like macro definitions, it should be:
21053 <macro name> "() " <definition>
21055 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
21057 Spaces may appear only where explicitly indicated, and in the
21060 The Dwarf 2 spec says that an object-like macro's name is always
21061 followed by a space, but versions of GCC around March 2002 omit
21062 the space when the macro's definition is the empty string.
21064 The Dwarf 2 spec says that there should be no spaces between the
21065 formal arguments in a function-like macro's formal argument list,
21066 but versions of GCC around March 2002 include spaces after the
21070 /* Find the extent of the macro name. The macro name is terminated
21071 by either a space or null character (for an object-like macro) or
21072 an opening paren (for a function-like macro). */
21073 for (p
= body
; *p
; p
++)
21074 if (*p
== ' ' || *p
== '(')
21077 if (*p
== ' ' || *p
== '\0')
21079 /* It's an object-like macro. */
21080 int name_len
= p
- body
;
21081 char *name
= copy_string (body
, name_len
);
21082 const char *replacement
;
21085 replacement
= body
+ name_len
+ 1;
21088 dwarf2_macro_malformed_definition_complaint (body
);
21089 replacement
= body
+ name_len
;
21092 macro_define_object (file
, line
, name
, replacement
);
21096 else if (*p
== '(')
21098 /* It's a function-like macro. */
21099 char *name
= copy_string (body
, p
- body
);
21102 char **argv
= XNEWVEC (char *, argv_size
);
21106 p
= consume_improper_spaces (p
, body
);
21108 /* Parse the formal argument list. */
21109 while (*p
&& *p
!= ')')
21111 /* Find the extent of the current argument name. */
21112 const char *arg_start
= p
;
21114 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
21117 if (! *p
|| p
== arg_start
)
21118 dwarf2_macro_malformed_definition_complaint (body
);
21121 /* Make sure argv has room for the new argument. */
21122 if (argc
>= argv_size
)
21125 argv
= XRESIZEVEC (char *, argv
, argv_size
);
21128 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
21131 p
= consume_improper_spaces (p
, body
);
21133 /* Consume the comma, if present. */
21138 p
= consume_improper_spaces (p
, body
);
21147 /* Perfectly formed definition, no complaints. */
21148 macro_define_function (file
, line
, name
,
21149 argc
, (const char **) argv
,
21151 else if (*p
== '\0')
21153 /* Complain, but do define it. */
21154 dwarf2_macro_malformed_definition_complaint (body
);
21155 macro_define_function (file
, line
, name
,
21156 argc
, (const char **) argv
,
21160 /* Just complain. */
21161 dwarf2_macro_malformed_definition_complaint (body
);
21164 /* Just complain. */
21165 dwarf2_macro_malformed_definition_complaint (body
);
21171 for (i
= 0; i
< argc
; i
++)
21177 dwarf2_macro_malformed_definition_complaint (body
);
21180 /* Skip some bytes from BYTES according to the form given in FORM.
21181 Returns the new pointer. */
21183 static const gdb_byte
*
21184 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
21185 enum dwarf_form form
,
21186 unsigned int offset_size
,
21187 struct dwarf2_section_info
*section
)
21189 unsigned int bytes_read
;
21193 case DW_FORM_data1
:
21198 case DW_FORM_data2
:
21202 case DW_FORM_data4
:
21206 case DW_FORM_data8
:
21210 case DW_FORM_string
:
21211 read_direct_string (abfd
, bytes
, &bytes_read
);
21212 bytes
+= bytes_read
;
21215 case DW_FORM_sec_offset
:
21217 case DW_FORM_GNU_strp_alt
:
21218 bytes
+= offset_size
;
21221 case DW_FORM_block
:
21222 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
21223 bytes
+= bytes_read
;
21226 case DW_FORM_block1
:
21227 bytes
+= 1 + read_1_byte (abfd
, bytes
);
21229 case DW_FORM_block2
:
21230 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
21232 case DW_FORM_block4
:
21233 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
21236 case DW_FORM_sdata
:
21237 case DW_FORM_udata
:
21238 case DW_FORM_GNU_addr_index
:
21239 case DW_FORM_GNU_str_index
:
21240 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
21243 dwarf2_section_buffer_overflow_complaint (section
);
21251 complaint (&symfile_complaints
,
21252 _("invalid form 0x%x in `%s'"),
21253 form
, get_section_name (section
));
21261 /* A helper for dwarf_decode_macros that handles skipping an unknown
21262 opcode. Returns an updated pointer to the macro data buffer; or,
21263 on error, issues a complaint and returns NULL. */
21265 static const gdb_byte
*
21266 skip_unknown_opcode (unsigned int opcode
,
21267 const gdb_byte
**opcode_definitions
,
21268 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
21270 unsigned int offset_size
,
21271 struct dwarf2_section_info
*section
)
21273 unsigned int bytes_read
, i
;
21275 const gdb_byte
*defn
;
21277 if (opcode_definitions
[opcode
] == NULL
)
21279 complaint (&symfile_complaints
,
21280 _("unrecognized DW_MACFINO opcode 0x%x"),
21285 defn
= opcode_definitions
[opcode
];
21286 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
21287 defn
+= bytes_read
;
21289 for (i
= 0; i
< arg
; ++i
)
21291 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
21292 (enum dwarf_form
) defn
[i
], offset_size
,
21294 if (mac_ptr
== NULL
)
21296 /* skip_form_bytes already issued the complaint. */
21304 /* A helper function which parses the header of a macro section.
21305 If the macro section is the extended (for now called "GNU") type,
21306 then this updates *OFFSET_SIZE. Returns a pointer to just after
21307 the header, or issues a complaint and returns NULL on error. */
21309 static const gdb_byte
*
21310 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
21312 const gdb_byte
*mac_ptr
,
21313 unsigned int *offset_size
,
21314 int section_is_gnu
)
21316 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
21318 if (section_is_gnu
)
21320 unsigned int version
, flags
;
21322 version
= read_2_bytes (abfd
, mac_ptr
);
21325 complaint (&symfile_complaints
,
21326 _("unrecognized version `%d' in .debug_macro section"),
21332 flags
= read_1_byte (abfd
, mac_ptr
);
21334 *offset_size
= (flags
& 1) ? 8 : 4;
21336 if ((flags
& 2) != 0)
21337 /* We don't need the line table offset. */
21338 mac_ptr
+= *offset_size
;
21340 /* Vendor opcode descriptions. */
21341 if ((flags
& 4) != 0)
21343 unsigned int i
, count
;
21345 count
= read_1_byte (abfd
, mac_ptr
);
21347 for (i
= 0; i
< count
; ++i
)
21349 unsigned int opcode
, bytes_read
;
21352 opcode
= read_1_byte (abfd
, mac_ptr
);
21354 opcode_definitions
[opcode
] = mac_ptr
;
21355 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21356 mac_ptr
+= bytes_read
;
21365 /* A helper for dwarf_decode_macros that handles the GNU extensions,
21366 including DW_MACRO_GNU_transparent_include. */
21369 dwarf_decode_macro_bytes (bfd
*abfd
,
21370 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
21371 struct macro_source_file
*current_file
,
21372 struct line_header
*lh
,
21373 struct dwarf2_section_info
*section
,
21374 int section_is_gnu
, int section_is_dwz
,
21375 unsigned int offset_size
,
21376 htab_t include_hash
)
21378 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21379 enum dwarf_macro_record_type macinfo_type
;
21380 int at_commandline
;
21381 const gdb_byte
*opcode_definitions
[256];
21383 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
21384 &offset_size
, section_is_gnu
);
21385 if (mac_ptr
== NULL
)
21387 /* We already issued a complaint. */
21391 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
21392 GDB is still reading the definitions from command line. First
21393 DW_MACINFO_start_file will need to be ignored as it was already executed
21394 to create CURRENT_FILE for the main source holding also the command line
21395 definitions. On first met DW_MACINFO_start_file this flag is reset to
21396 normally execute all the remaining DW_MACINFO_start_file macinfos. */
21398 at_commandline
= 1;
21402 /* Do we at least have room for a macinfo type byte? */
21403 if (mac_ptr
>= mac_end
)
21405 dwarf2_section_buffer_overflow_complaint (section
);
21409 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
21412 /* Note that we rely on the fact that the corresponding GNU and
21413 DWARF constants are the same. */
21414 switch (macinfo_type
)
21416 /* A zero macinfo type indicates the end of the macro
21421 case DW_MACRO_GNU_define
:
21422 case DW_MACRO_GNU_undef
:
21423 case DW_MACRO_GNU_define_indirect
:
21424 case DW_MACRO_GNU_undef_indirect
:
21425 case DW_MACRO_GNU_define_indirect_alt
:
21426 case DW_MACRO_GNU_undef_indirect_alt
:
21428 unsigned int bytes_read
;
21433 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21434 mac_ptr
+= bytes_read
;
21436 if (macinfo_type
== DW_MACRO_GNU_define
21437 || macinfo_type
== DW_MACRO_GNU_undef
)
21439 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21440 mac_ptr
+= bytes_read
;
21444 LONGEST str_offset
;
21446 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
21447 mac_ptr
+= offset_size
;
21449 if (macinfo_type
== DW_MACRO_GNU_define_indirect_alt
21450 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
21453 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
21455 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
21458 body
= read_indirect_string_at_offset (abfd
, str_offset
);
21461 is_define
= (macinfo_type
== DW_MACRO_GNU_define
21462 || macinfo_type
== DW_MACRO_GNU_define_indirect
21463 || macinfo_type
== DW_MACRO_GNU_define_indirect_alt
);
21464 if (! current_file
)
21466 /* DWARF violation as no main source is present. */
21467 complaint (&symfile_complaints
,
21468 _("debug info with no main source gives macro %s "
21470 is_define
? _("definition") : _("undefinition"),
21474 if ((line
== 0 && !at_commandline
)
21475 || (line
!= 0 && at_commandline
))
21476 complaint (&symfile_complaints
,
21477 _("debug info gives %s macro %s with %s line %d: %s"),
21478 at_commandline
? _("command-line") : _("in-file"),
21479 is_define
? _("definition") : _("undefinition"),
21480 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
21483 parse_macro_definition (current_file
, line
, body
);
21486 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
21487 || macinfo_type
== DW_MACRO_GNU_undef_indirect
21488 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
);
21489 macro_undef (current_file
, line
, body
);
21494 case DW_MACRO_GNU_start_file
:
21496 unsigned int bytes_read
;
21499 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21500 mac_ptr
+= bytes_read
;
21501 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21502 mac_ptr
+= bytes_read
;
21504 if ((line
== 0 && !at_commandline
)
21505 || (line
!= 0 && at_commandline
))
21506 complaint (&symfile_complaints
,
21507 _("debug info gives source %d included "
21508 "from %s at %s line %d"),
21509 file
, at_commandline
? _("command-line") : _("file"),
21510 line
== 0 ? _("zero") : _("non-zero"), line
);
21512 if (at_commandline
)
21514 /* This DW_MACRO_GNU_start_file was executed in the
21516 at_commandline
= 0;
21519 current_file
= macro_start_file (file
, line
, current_file
, lh
);
21523 case DW_MACRO_GNU_end_file
:
21524 if (! current_file
)
21525 complaint (&symfile_complaints
,
21526 _("macro debug info has an unmatched "
21527 "`close_file' directive"));
21530 current_file
= current_file
->included_by
;
21531 if (! current_file
)
21533 enum dwarf_macro_record_type next_type
;
21535 /* GCC circa March 2002 doesn't produce the zero
21536 type byte marking the end of the compilation
21537 unit. Complain if it's not there, but exit no
21540 /* Do we at least have room for a macinfo type byte? */
21541 if (mac_ptr
>= mac_end
)
21543 dwarf2_section_buffer_overflow_complaint (section
);
21547 /* We don't increment mac_ptr here, so this is just
21550 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
21552 if (next_type
!= 0)
21553 complaint (&symfile_complaints
,
21554 _("no terminating 0-type entry for "
21555 "macros in `.debug_macinfo' section"));
21562 case DW_MACRO_GNU_transparent_include
:
21563 case DW_MACRO_GNU_transparent_include_alt
:
21567 bfd
*include_bfd
= abfd
;
21568 struct dwarf2_section_info
*include_section
= section
;
21569 const gdb_byte
*include_mac_end
= mac_end
;
21570 int is_dwz
= section_is_dwz
;
21571 const gdb_byte
*new_mac_ptr
;
21573 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
21574 mac_ptr
+= offset_size
;
21576 if (macinfo_type
== DW_MACRO_GNU_transparent_include_alt
)
21578 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
21580 dwarf2_read_section (objfile
, &dwz
->macro
);
21582 include_section
= &dwz
->macro
;
21583 include_bfd
= get_section_bfd_owner (include_section
);
21584 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
21588 new_mac_ptr
= include_section
->buffer
+ offset
;
21589 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
21593 /* This has actually happened; see
21594 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
21595 complaint (&symfile_complaints
,
21596 _("recursive DW_MACRO_GNU_transparent_include in "
21597 ".debug_macro section"));
21601 *slot
= (void *) new_mac_ptr
;
21603 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
21604 include_mac_end
, current_file
, lh
,
21605 section
, section_is_gnu
, is_dwz
,
21606 offset_size
, include_hash
);
21608 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
21613 case DW_MACINFO_vendor_ext
:
21614 if (!section_is_gnu
)
21616 unsigned int bytes_read
;
21618 /* This reads the constant, but since we don't recognize
21619 any vendor extensions, we ignore it. */
21620 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21621 mac_ptr
+= bytes_read
;
21622 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21623 mac_ptr
+= bytes_read
;
21625 /* We don't recognize any vendor extensions. */
21631 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
21632 mac_ptr
, mac_end
, abfd
, offset_size
,
21634 if (mac_ptr
== NULL
)
21638 } while (macinfo_type
!= 0);
21642 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
21643 int section_is_gnu
)
21645 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21646 struct line_header
*lh
= cu
->line_header
;
21648 const gdb_byte
*mac_ptr
, *mac_end
;
21649 struct macro_source_file
*current_file
= 0;
21650 enum dwarf_macro_record_type macinfo_type
;
21651 unsigned int offset_size
= cu
->header
.offset_size
;
21652 const gdb_byte
*opcode_definitions
[256];
21653 struct cleanup
*cleanup
;
21654 htab_t include_hash
;
21656 struct dwarf2_section_info
*section
;
21657 const char *section_name
;
21659 if (cu
->dwo_unit
!= NULL
)
21661 if (section_is_gnu
)
21663 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
21664 section_name
= ".debug_macro.dwo";
21668 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
21669 section_name
= ".debug_macinfo.dwo";
21674 if (section_is_gnu
)
21676 section
= &dwarf2_per_objfile
->macro
;
21677 section_name
= ".debug_macro";
21681 section
= &dwarf2_per_objfile
->macinfo
;
21682 section_name
= ".debug_macinfo";
21686 dwarf2_read_section (objfile
, section
);
21687 if (section
->buffer
== NULL
)
21689 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
21692 abfd
= get_section_bfd_owner (section
);
21694 /* First pass: Find the name of the base filename.
21695 This filename is needed in order to process all macros whose definition
21696 (or undefinition) comes from the command line. These macros are defined
21697 before the first DW_MACINFO_start_file entry, and yet still need to be
21698 associated to the base file.
21700 To determine the base file name, we scan the macro definitions until we
21701 reach the first DW_MACINFO_start_file entry. We then initialize
21702 CURRENT_FILE accordingly so that any macro definition found before the
21703 first DW_MACINFO_start_file can still be associated to the base file. */
21705 mac_ptr
= section
->buffer
+ offset
;
21706 mac_end
= section
->buffer
+ section
->size
;
21708 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
21709 &offset_size
, section_is_gnu
);
21710 if (mac_ptr
== NULL
)
21712 /* We already issued a complaint. */
21718 /* Do we at least have room for a macinfo type byte? */
21719 if (mac_ptr
>= mac_end
)
21721 /* Complaint is printed during the second pass as GDB will probably
21722 stop the first pass earlier upon finding
21723 DW_MACINFO_start_file. */
21727 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
21730 /* Note that we rely on the fact that the corresponding GNU and
21731 DWARF constants are the same. */
21732 switch (macinfo_type
)
21734 /* A zero macinfo type indicates the end of the macro
21739 case DW_MACRO_GNU_define
:
21740 case DW_MACRO_GNU_undef
:
21741 /* Only skip the data by MAC_PTR. */
21743 unsigned int bytes_read
;
21745 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21746 mac_ptr
+= bytes_read
;
21747 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21748 mac_ptr
+= bytes_read
;
21752 case DW_MACRO_GNU_start_file
:
21754 unsigned int bytes_read
;
21757 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21758 mac_ptr
+= bytes_read
;
21759 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21760 mac_ptr
+= bytes_read
;
21762 current_file
= macro_start_file (file
, line
, current_file
, lh
);
21766 case DW_MACRO_GNU_end_file
:
21767 /* No data to skip by MAC_PTR. */
21770 case DW_MACRO_GNU_define_indirect
:
21771 case DW_MACRO_GNU_undef_indirect
:
21772 case DW_MACRO_GNU_define_indirect_alt
:
21773 case DW_MACRO_GNU_undef_indirect_alt
:
21775 unsigned int bytes_read
;
21777 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21778 mac_ptr
+= bytes_read
;
21779 mac_ptr
+= offset_size
;
21783 case DW_MACRO_GNU_transparent_include
:
21784 case DW_MACRO_GNU_transparent_include_alt
:
21785 /* Note that, according to the spec, a transparent include
21786 chain cannot call DW_MACRO_GNU_start_file. So, we can just
21787 skip this opcode. */
21788 mac_ptr
+= offset_size
;
21791 case DW_MACINFO_vendor_ext
:
21792 /* Only skip the data by MAC_PTR. */
21793 if (!section_is_gnu
)
21795 unsigned int bytes_read
;
21797 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21798 mac_ptr
+= bytes_read
;
21799 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21800 mac_ptr
+= bytes_read
;
21805 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
21806 mac_ptr
, mac_end
, abfd
, offset_size
,
21808 if (mac_ptr
== NULL
)
21812 } while (macinfo_type
!= 0 && current_file
== NULL
);
21814 /* Second pass: Process all entries.
21816 Use the AT_COMMAND_LINE flag to determine whether we are still processing
21817 command-line macro definitions/undefinitions. This flag is unset when we
21818 reach the first DW_MACINFO_start_file entry. */
21820 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
21821 NULL
, xcalloc
, xfree
);
21822 cleanup
= make_cleanup_htab_delete (include_hash
);
21823 mac_ptr
= section
->buffer
+ offset
;
21824 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
21825 *slot
= (void *) mac_ptr
;
21826 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
21827 current_file
, lh
, section
,
21828 section_is_gnu
, 0, offset_size
, include_hash
);
21829 do_cleanups (cleanup
);
21832 /* Check if the attribute's form is a DW_FORM_block*
21833 if so return true else false. */
21836 attr_form_is_block (const struct attribute
*attr
)
21838 return (attr
== NULL
? 0 :
21839 attr
->form
== DW_FORM_block1
21840 || attr
->form
== DW_FORM_block2
21841 || attr
->form
== DW_FORM_block4
21842 || attr
->form
== DW_FORM_block
21843 || attr
->form
== DW_FORM_exprloc
);
21846 /* Return non-zero if ATTR's value is a section offset --- classes
21847 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
21848 You may use DW_UNSND (attr) to retrieve such offsets.
21850 Section 7.5.4, "Attribute Encodings", explains that no attribute
21851 may have a value that belongs to more than one of these classes; it
21852 would be ambiguous if we did, because we use the same forms for all
21856 attr_form_is_section_offset (const struct attribute
*attr
)
21858 return (attr
->form
== DW_FORM_data4
21859 || attr
->form
== DW_FORM_data8
21860 || attr
->form
== DW_FORM_sec_offset
);
21863 /* Return non-zero if ATTR's value falls in the 'constant' class, or
21864 zero otherwise. When this function returns true, you can apply
21865 dwarf2_get_attr_constant_value to it.
21867 However, note that for some attributes you must check
21868 attr_form_is_section_offset before using this test. DW_FORM_data4
21869 and DW_FORM_data8 are members of both the constant class, and of
21870 the classes that contain offsets into other debug sections
21871 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
21872 that, if an attribute's can be either a constant or one of the
21873 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
21874 taken as section offsets, not constants. */
21877 attr_form_is_constant (const struct attribute
*attr
)
21879 switch (attr
->form
)
21881 case DW_FORM_sdata
:
21882 case DW_FORM_udata
:
21883 case DW_FORM_data1
:
21884 case DW_FORM_data2
:
21885 case DW_FORM_data4
:
21886 case DW_FORM_data8
:
21894 /* DW_ADDR is always stored already as sect_offset; despite for the forms
21895 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
21898 attr_form_is_ref (const struct attribute
*attr
)
21900 switch (attr
->form
)
21902 case DW_FORM_ref_addr
:
21907 case DW_FORM_ref_udata
:
21908 case DW_FORM_GNU_ref_alt
:
21915 /* Return the .debug_loc section to use for CU.
21916 For DWO files use .debug_loc.dwo. */
21918 static struct dwarf2_section_info
*
21919 cu_debug_loc_section (struct dwarf2_cu
*cu
)
21922 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
21923 return &dwarf2_per_objfile
->loc
;
21926 /* A helper function that fills in a dwarf2_loclist_baton. */
21929 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
21930 struct dwarf2_loclist_baton
*baton
,
21931 const struct attribute
*attr
)
21933 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
21935 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
21937 baton
->per_cu
= cu
->per_cu
;
21938 gdb_assert (baton
->per_cu
);
21939 /* We don't know how long the location list is, but make sure we
21940 don't run off the edge of the section. */
21941 baton
->size
= section
->size
- DW_UNSND (attr
);
21942 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
21943 baton
->base_address
= cu
->base_address
;
21944 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
21948 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
21949 struct dwarf2_cu
*cu
, int is_block
)
21951 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21952 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
21954 if (attr_form_is_section_offset (attr
)
21955 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
21956 the section. If so, fall through to the complaint in the
21958 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
21960 struct dwarf2_loclist_baton
*baton
;
21962 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
21964 fill_in_loclist_baton (cu
, baton
, attr
);
21966 if (cu
->base_known
== 0)
21967 complaint (&symfile_complaints
,
21968 _("Location list used without "
21969 "specifying the CU base address."));
21971 SYMBOL_ACLASS_INDEX (sym
) = (is_block
21972 ? dwarf2_loclist_block_index
21973 : dwarf2_loclist_index
);
21974 SYMBOL_LOCATION_BATON (sym
) = baton
;
21978 struct dwarf2_locexpr_baton
*baton
;
21980 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
21981 baton
->per_cu
= cu
->per_cu
;
21982 gdb_assert (baton
->per_cu
);
21984 if (attr_form_is_block (attr
))
21986 /* Note that we're just copying the block's data pointer
21987 here, not the actual data. We're still pointing into the
21988 info_buffer for SYM's objfile; right now we never release
21989 that buffer, but when we do clean up properly this may
21991 baton
->size
= DW_BLOCK (attr
)->size
;
21992 baton
->data
= DW_BLOCK (attr
)->data
;
21996 dwarf2_invalid_attrib_class_complaint ("location description",
21997 SYMBOL_NATURAL_NAME (sym
));
22001 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22002 ? dwarf2_locexpr_block_index
22003 : dwarf2_locexpr_index
);
22004 SYMBOL_LOCATION_BATON (sym
) = baton
;
22008 /* Return the OBJFILE associated with the compilation unit CU. If CU
22009 came from a separate debuginfo file, then the master objfile is
22013 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
22015 struct objfile
*objfile
= per_cu
->objfile
;
22017 /* Return the master objfile, so that we can report and look up the
22018 correct file containing this variable. */
22019 if (objfile
->separate_debug_objfile_backlink
)
22020 objfile
= objfile
->separate_debug_objfile_backlink
;
22025 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22026 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22027 CU_HEADERP first. */
22029 static const struct comp_unit_head
*
22030 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22031 struct dwarf2_per_cu_data
*per_cu
)
22033 const gdb_byte
*info_ptr
;
22036 return &per_cu
->cu
->header
;
22038 info_ptr
= per_cu
->section
->buffer
+ per_cu
->offset
.sect_off
;
22040 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22041 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
22046 /* Return the address size given in the compilation unit header for CU. */
22049 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
22051 struct comp_unit_head cu_header_local
;
22052 const struct comp_unit_head
*cu_headerp
;
22054 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22056 return cu_headerp
->addr_size
;
22059 /* Return the offset size given in the compilation unit header for CU. */
22062 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
22064 struct comp_unit_head cu_header_local
;
22065 const struct comp_unit_head
*cu_headerp
;
22067 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22069 return cu_headerp
->offset_size
;
22072 /* See its dwarf2loc.h declaration. */
22075 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
22077 struct comp_unit_head cu_header_local
;
22078 const struct comp_unit_head
*cu_headerp
;
22080 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22082 if (cu_headerp
->version
== 2)
22083 return cu_headerp
->addr_size
;
22085 return cu_headerp
->offset_size
;
22088 /* Return the text offset of the CU. The returned offset comes from
22089 this CU's objfile. If this objfile came from a separate debuginfo
22090 file, then the offset may be different from the corresponding
22091 offset in the parent objfile. */
22094 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
22096 struct objfile
*objfile
= per_cu
->objfile
;
22098 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
22101 /* Locate the .debug_info compilation unit from CU's objfile which contains
22102 the DIE at OFFSET. Raises an error on failure. */
22104 static struct dwarf2_per_cu_data
*
22105 dwarf2_find_containing_comp_unit (sect_offset offset
,
22106 unsigned int offset_in_dwz
,
22107 struct objfile
*objfile
)
22109 struct dwarf2_per_cu_data
*this_cu
;
22111 const sect_offset
*cu_off
;
22114 high
= dwarf2_per_objfile
->n_comp_units
- 1;
22117 struct dwarf2_per_cu_data
*mid_cu
;
22118 int mid
= low
+ (high
- low
) / 2;
22120 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
22121 cu_off
= &mid_cu
->offset
;
22122 if (mid_cu
->is_dwz
> offset_in_dwz
22123 || (mid_cu
->is_dwz
== offset_in_dwz
22124 && cu_off
->sect_off
>= offset
.sect_off
))
22129 gdb_assert (low
== high
);
22130 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
22131 cu_off
= &this_cu
->offset
;
22132 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
22134 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
22135 error (_("Dwarf Error: could not find partial DIE containing "
22136 "offset 0x%lx [in module %s]"),
22137 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
22139 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
22140 <= offset
.sect_off
);
22141 return dwarf2_per_objfile
->all_comp_units
[low
-1];
22145 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
22146 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
22147 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
22148 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
22149 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
22154 /* Initialize dwarf2_cu CU, owned by PER_CU. */
22157 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
22159 memset (cu
, 0, sizeof (*cu
));
22161 cu
->per_cu
= per_cu
;
22162 cu
->objfile
= per_cu
->objfile
;
22163 obstack_init (&cu
->comp_unit_obstack
);
22166 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
22169 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
22170 enum language pretend_language
)
22172 struct attribute
*attr
;
22174 /* Set the language we're debugging. */
22175 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
22177 set_cu_language (DW_UNSND (attr
), cu
);
22180 cu
->language
= pretend_language
;
22181 cu
->language_defn
= language_def (cu
->language
);
22184 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
22187 /* Release one cached compilation unit, CU. We unlink it from the tree
22188 of compilation units, but we don't remove it from the read_in_chain;
22189 the caller is responsible for that.
22190 NOTE: DATA is a void * because this function is also used as a
22191 cleanup routine. */
22194 free_heap_comp_unit (void *data
)
22196 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
22198 gdb_assert (cu
->per_cu
!= NULL
);
22199 cu
->per_cu
->cu
= NULL
;
22202 obstack_free (&cu
->comp_unit_obstack
, NULL
);
22207 /* This cleanup function is passed the address of a dwarf2_cu on the stack
22208 when we're finished with it. We can't free the pointer itself, but be
22209 sure to unlink it from the cache. Also release any associated storage. */
22212 free_stack_comp_unit (void *data
)
22214 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
22216 gdb_assert (cu
->per_cu
!= NULL
);
22217 cu
->per_cu
->cu
= NULL
;
22220 obstack_free (&cu
->comp_unit_obstack
, NULL
);
22221 cu
->partial_dies
= NULL
;
22224 /* Free all cached compilation units. */
22227 free_cached_comp_units (void *data
)
22229 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22231 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22232 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22233 while (per_cu
!= NULL
)
22235 struct dwarf2_per_cu_data
*next_cu
;
22237 next_cu
= per_cu
->cu
->read_in_chain
;
22239 free_heap_comp_unit (per_cu
->cu
);
22240 *last_chain
= next_cu
;
22246 /* Increase the age counter on each cached compilation unit, and free
22247 any that are too old. */
22250 age_cached_comp_units (void)
22252 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22254 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
22255 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22256 while (per_cu
!= NULL
)
22258 per_cu
->cu
->last_used
++;
22259 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
22260 dwarf2_mark (per_cu
->cu
);
22261 per_cu
= per_cu
->cu
->read_in_chain
;
22264 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22265 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22266 while (per_cu
!= NULL
)
22268 struct dwarf2_per_cu_data
*next_cu
;
22270 next_cu
= per_cu
->cu
->read_in_chain
;
22272 if (!per_cu
->cu
->mark
)
22274 free_heap_comp_unit (per_cu
->cu
);
22275 *last_chain
= next_cu
;
22278 last_chain
= &per_cu
->cu
->read_in_chain
;
22284 /* Remove a single compilation unit from the cache. */
22287 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
22289 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22291 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22292 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22293 while (per_cu
!= NULL
)
22295 struct dwarf2_per_cu_data
*next_cu
;
22297 next_cu
= per_cu
->cu
->read_in_chain
;
22299 if (per_cu
== target_per_cu
)
22301 free_heap_comp_unit (per_cu
->cu
);
22303 *last_chain
= next_cu
;
22307 last_chain
= &per_cu
->cu
->read_in_chain
;
22313 /* Release all extra memory associated with OBJFILE. */
22316 dwarf2_free_objfile (struct objfile
*objfile
)
22319 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
22320 dwarf2_objfile_data_key
);
22322 if (dwarf2_per_objfile
== NULL
)
22325 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
22326 free_cached_comp_units (NULL
);
22328 if (dwarf2_per_objfile
->quick_file_names_table
)
22329 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
22331 if (dwarf2_per_objfile
->line_header_hash
)
22332 htab_delete (dwarf2_per_objfile
->line_header_hash
);
22334 /* Everything else should be on the objfile obstack. */
22337 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
22338 We store these in a hash table separate from the DIEs, and preserve them
22339 when the DIEs are flushed out of cache.
22341 The CU "per_cu" pointer is needed because offset alone is not enough to
22342 uniquely identify the type. A file may have multiple .debug_types sections,
22343 or the type may come from a DWO file. Furthermore, while it's more logical
22344 to use per_cu->section+offset, with Fission the section with the data is in
22345 the DWO file but we don't know that section at the point we need it.
22346 We have to use something in dwarf2_per_cu_data (or the pointer to it)
22347 because we can enter the lookup routine, get_die_type_at_offset, from
22348 outside this file, and thus won't necessarily have PER_CU->cu.
22349 Fortunately, PER_CU is stable for the life of the objfile. */
22351 struct dwarf2_per_cu_offset_and_type
22353 const struct dwarf2_per_cu_data
*per_cu
;
22354 sect_offset offset
;
22358 /* Hash function for a dwarf2_per_cu_offset_and_type. */
22361 per_cu_offset_and_type_hash (const void *item
)
22363 const struct dwarf2_per_cu_offset_and_type
*ofs
22364 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
22366 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
22369 /* Equality function for a dwarf2_per_cu_offset_and_type. */
22372 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
22374 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
22375 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
22376 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
22377 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
22379 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
22380 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
22383 /* Set the type associated with DIE to TYPE. Save it in CU's hash
22384 table if necessary. For convenience, return TYPE.
22386 The DIEs reading must have careful ordering to:
22387 * Not cause infite loops trying to read in DIEs as a prerequisite for
22388 reading current DIE.
22389 * Not trying to dereference contents of still incompletely read in types
22390 while reading in other DIEs.
22391 * Enable referencing still incompletely read in types just by a pointer to
22392 the type without accessing its fields.
22394 Therefore caller should follow these rules:
22395 * Try to fetch any prerequisite types we may need to build this DIE type
22396 before building the type and calling set_die_type.
22397 * After building type call set_die_type for current DIE as soon as
22398 possible before fetching more types to complete the current type.
22399 * Make the type as complete as possible before fetching more types. */
22401 static struct type
*
22402 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
22404 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
22405 struct objfile
*objfile
= cu
->objfile
;
22406 struct attribute
*attr
;
22407 struct dynamic_prop prop
;
22409 /* For Ada types, make sure that the gnat-specific data is always
22410 initialized (if not already set). There are a few types where
22411 we should not be doing so, because the type-specific area is
22412 already used to hold some other piece of info (eg: TYPE_CODE_FLT
22413 where the type-specific area is used to store the floatformat).
22414 But this is not a problem, because the gnat-specific information
22415 is actually not needed for these types. */
22416 if (need_gnat_info (cu
)
22417 && TYPE_CODE (type
) != TYPE_CODE_FUNC
22418 && TYPE_CODE (type
) != TYPE_CODE_FLT
22419 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
22420 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
22421 && TYPE_CODE (type
) != TYPE_CODE_METHOD
22422 && !HAVE_GNAT_AUX_INFO (type
))
22423 INIT_GNAT_SPECIFIC (type
);
22425 /* Read DW_AT_allocated and set in type. */
22426 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
22427 if (attr_form_is_block (attr
))
22429 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22430 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
, objfile
);
22432 else if (attr
!= NULL
)
22434 complaint (&symfile_complaints
,
22435 _("DW_AT_allocated has the wrong form (%s) at DIE 0x%x"),
22436 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
22437 die
->offset
.sect_off
);
22440 /* Read DW_AT_associated and set in type. */
22441 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
22442 if (attr_form_is_block (attr
))
22444 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22445 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
, objfile
);
22447 else if (attr
!= NULL
)
22449 complaint (&symfile_complaints
,
22450 _("DW_AT_associated has the wrong form (%s) at DIE 0x%x"),
22451 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
22452 die
->offset
.sect_off
);
22455 /* Read DW_AT_data_location and set in type. */
22456 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
22457 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22458 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
, objfile
);
22460 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
22462 dwarf2_per_objfile
->die_type_hash
=
22463 htab_create_alloc_ex (127,
22464 per_cu_offset_and_type_hash
,
22465 per_cu_offset_and_type_eq
,
22467 &objfile
->objfile_obstack
,
22468 hashtab_obstack_allocate
,
22469 dummy_obstack_deallocate
);
22472 ofs
.per_cu
= cu
->per_cu
;
22473 ofs
.offset
= die
->offset
;
22475 slot
= (struct dwarf2_per_cu_offset_and_type
**)
22476 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
22478 complaint (&symfile_complaints
,
22479 _("A problem internal to GDB: DIE 0x%x has type already set"),
22480 die
->offset
.sect_off
);
22481 *slot
= XOBNEW (&objfile
->objfile_obstack
,
22482 struct dwarf2_per_cu_offset_and_type
);
22487 /* Look up the type for the die at OFFSET in PER_CU in die_type_hash,
22488 or return NULL if the die does not have a saved type. */
22490 static struct type
*
22491 get_die_type_at_offset (sect_offset offset
,
22492 struct dwarf2_per_cu_data
*per_cu
)
22494 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
22496 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
22499 ofs
.per_cu
= per_cu
;
22500 ofs
.offset
= offset
;
22501 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
22502 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
22509 /* Look up the type for DIE in CU in die_type_hash,
22510 or return NULL if DIE does not have a saved type. */
22512 static struct type
*
22513 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22515 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
22518 /* Add a dependence relationship from CU to REF_PER_CU. */
22521 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
22522 struct dwarf2_per_cu_data
*ref_per_cu
)
22526 if (cu
->dependencies
== NULL
)
22528 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
22529 NULL
, &cu
->comp_unit_obstack
,
22530 hashtab_obstack_allocate
,
22531 dummy_obstack_deallocate
);
22533 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
22535 *slot
= ref_per_cu
;
22538 /* Subroutine of dwarf2_mark to pass to htab_traverse.
22539 Set the mark field in every compilation unit in the
22540 cache that we must keep because we are keeping CU. */
22543 dwarf2_mark_helper (void **slot
, void *data
)
22545 struct dwarf2_per_cu_data
*per_cu
;
22547 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
22549 /* cu->dependencies references may not yet have been ever read if QUIT aborts
22550 reading of the chain. As such dependencies remain valid it is not much
22551 useful to track and undo them during QUIT cleanups. */
22552 if (per_cu
->cu
== NULL
)
22555 if (per_cu
->cu
->mark
)
22557 per_cu
->cu
->mark
= 1;
22559 if (per_cu
->cu
->dependencies
!= NULL
)
22560 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
22565 /* Set the mark field in CU and in every other compilation unit in the
22566 cache that we must keep because we are keeping CU. */
22569 dwarf2_mark (struct dwarf2_cu
*cu
)
22574 if (cu
->dependencies
!= NULL
)
22575 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
22579 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
22583 per_cu
->cu
->mark
= 0;
22584 per_cu
= per_cu
->cu
->read_in_chain
;
22588 /* Trivial hash function for partial_die_info: the hash value of a DIE
22589 is its offset in .debug_info for this objfile. */
22592 partial_die_hash (const void *item
)
22594 const struct partial_die_info
*part_die
22595 = (const struct partial_die_info
*) item
;
22597 return part_die
->offset
.sect_off
;
22600 /* Trivial comparison function for partial_die_info structures: two DIEs
22601 are equal if they have the same offset. */
22604 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
22606 const struct partial_die_info
*part_die_lhs
22607 = (const struct partial_die_info
*) item_lhs
;
22608 const struct partial_die_info
*part_die_rhs
22609 = (const struct partial_die_info
*) item_rhs
;
22611 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
22614 static struct cmd_list_element
*set_dwarf_cmdlist
;
22615 static struct cmd_list_element
*show_dwarf_cmdlist
;
22618 set_dwarf_cmd (char *args
, int from_tty
)
22620 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
22625 show_dwarf_cmd (char *args
, int from_tty
)
22627 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
22630 /* Free data associated with OBJFILE, if necessary. */
22633 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
22635 struct dwarf2_per_objfile
*data
= (struct dwarf2_per_objfile
*) d
;
22638 /* Make sure we don't accidentally use dwarf2_per_objfile while
22640 dwarf2_per_objfile
= NULL
;
22642 for (ix
= 0; ix
< data
->n_comp_units
; ++ix
)
22643 VEC_free (dwarf2_per_cu_ptr
, data
->all_comp_units
[ix
]->imported_symtabs
);
22645 for (ix
= 0; ix
< data
->n_type_units
; ++ix
)
22646 VEC_free (dwarf2_per_cu_ptr
,
22647 data
->all_type_units
[ix
]->per_cu
.imported_symtabs
);
22648 xfree (data
->all_type_units
);
22650 VEC_free (dwarf2_section_info_def
, data
->types
);
22652 if (data
->dwo_files
)
22653 free_dwo_files (data
->dwo_files
, objfile
);
22654 if (data
->dwp_file
)
22655 gdb_bfd_unref (data
->dwp_file
->dbfd
);
22657 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
22658 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
22662 /* The "save gdb-index" command. */
22664 /* The contents of the hash table we create when building the string
22666 struct strtab_entry
22668 offset_type offset
;
22672 /* Hash function for a strtab_entry.
22674 Function is used only during write_hash_table so no index format backward
22675 compatibility is needed. */
22678 hash_strtab_entry (const void *e
)
22680 const struct strtab_entry
*entry
= (const struct strtab_entry
*) e
;
22681 return mapped_index_string_hash (INT_MAX
, entry
->str
);
22684 /* Equality function for a strtab_entry. */
22687 eq_strtab_entry (const void *a
, const void *b
)
22689 const struct strtab_entry
*ea
= (const struct strtab_entry
*) a
;
22690 const struct strtab_entry
*eb
= (const struct strtab_entry
*) b
;
22691 return !strcmp (ea
->str
, eb
->str
);
22694 /* Create a strtab_entry hash table. */
22697 create_strtab (void)
22699 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
22700 xfree
, xcalloc
, xfree
);
22703 /* Add a string to the constant pool. Return the string's offset in
22707 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
22710 struct strtab_entry entry
;
22711 struct strtab_entry
*result
;
22714 slot
= htab_find_slot (table
, &entry
, INSERT
);
22716 result
= (struct strtab_entry
*) *slot
;
22719 result
= XNEW (struct strtab_entry
);
22720 result
->offset
= obstack_object_size (cpool
);
22722 obstack_grow_str0 (cpool
, str
);
22725 return result
->offset
;
22728 /* An entry in the symbol table. */
22729 struct symtab_index_entry
22731 /* The name of the symbol. */
22733 /* The offset of the name in the constant pool. */
22734 offset_type index_offset
;
22735 /* A sorted vector of the indices of all the CUs that hold an object
22737 VEC (offset_type
) *cu_indices
;
22740 /* The symbol table. This is a power-of-2-sized hash table. */
22741 struct mapped_symtab
22743 offset_type n_elements
;
22745 struct symtab_index_entry
**data
;
22748 /* Hash function for a symtab_index_entry. */
22751 hash_symtab_entry (const void *e
)
22753 const struct symtab_index_entry
*entry
22754 = (const struct symtab_index_entry
*) e
;
22755 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
22756 sizeof (offset_type
) * VEC_length (offset_type
,
22757 entry
->cu_indices
),
22761 /* Equality function for a symtab_index_entry. */
22764 eq_symtab_entry (const void *a
, const void *b
)
22766 const struct symtab_index_entry
*ea
= (const struct symtab_index_entry
*) a
;
22767 const struct symtab_index_entry
*eb
= (const struct symtab_index_entry
*) b
;
22768 int len
= VEC_length (offset_type
, ea
->cu_indices
);
22769 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
22771 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
22772 VEC_address (offset_type
, eb
->cu_indices
),
22773 sizeof (offset_type
) * len
);
22776 /* Destroy a symtab_index_entry. */
22779 delete_symtab_entry (void *p
)
22781 struct symtab_index_entry
*entry
= (struct symtab_index_entry
*) p
;
22782 VEC_free (offset_type
, entry
->cu_indices
);
22786 /* Create a hash table holding symtab_index_entry objects. */
22789 create_symbol_hash_table (void)
22791 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
22792 delete_symtab_entry
, xcalloc
, xfree
);
22795 /* Create a new mapped symtab object. */
22797 static struct mapped_symtab
*
22798 create_mapped_symtab (void)
22800 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
22801 symtab
->n_elements
= 0;
22802 symtab
->size
= 1024;
22803 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
22807 /* Destroy a mapped_symtab. */
22810 cleanup_mapped_symtab (void *p
)
22812 struct mapped_symtab
*symtab
= (struct mapped_symtab
*) p
;
22813 /* The contents of the array are freed when the other hash table is
22815 xfree (symtab
->data
);
22819 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
22822 Function is used only during write_hash_table so no index format backward
22823 compatibility is needed. */
22825 static struct symtab_index_entry
**
22826 find_slot (struct mapped_symtab
*symtab
, const char *name
)
22828 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
22830 index
= hash
& (symtab
->size
- 1);
22831 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
22835 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
22836 return &symtab
->data
[index
];
22837 index
= (index
+ step
) & (symtab
->size
- 1);
22841 /* Expand SYMTAB's hash table. */
22844 hash_expand (struct mapped_symtab
*symtab
)
22846 offset_type old_size
= symtab
->size
;
22848 struct symtab_index_entry
**old_entries
= symtab
->data
;
22851 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
22853 for (i
= 0; i
< old_size
; ++i
)
22855 if (old_entries
[i
])
22857 struct symtab_index_entry
**slot
= find_slot (symtab
,
22858 old_entries
[i
]->name
);
22859 *slot
= old_entries
[i
];
22863 xfree (old_entries
);
22866 /* Add an entry to SYMTAB. NAME is the name of the symbol.
22867 CU_INDEX is the index of the CU in which the symbol appears.
22868 IS_STATIC is one if the symbol is static, otherwise zero (global). */
22871 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
22872 int is_static
, gdb_index_symbol_kind kind
,
22873 offset_type cu_index
)
22875 struct symtab_index_entry
**slot
;
22876 offset_type cu_index_and_attrs
;
22878 ++symtab
->n_elements
;
22879 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
22880 hash_expand (symtab
);
22882 slot
= find_slot (symtab
, name
);
22885 *slot
= XNEW (struct symtab_index_entry
);
22886 (*slot
)->name
= name
;
22887 /* index_offset is set later. */
22888 (*slot
)->cu_indices
= NULL
;
22891 cu_index_and_attrs
= 0;
22892 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
22893 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
22894 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
22896 /* We don't want to record an index value twice as we want to avoid the
22898 We process all global symbols and then all static symbols
22899 (which would allow us to avoid the duplication by only having to check
22900 the last entry pushed), but a symbol could have multiple kinds in one CU.
22901 To keep things simple we don't worry about the duplication here and
22902 sort and uniqufy the list after we've processed all symbols. */
22903 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
22906 /* qsort helper routine for uniquify_cu_indices. */
22909 offset_type_compare (const void *ap
, const void *bp
)
22911 offset_type a
= *(offset_type
*) ap
;
22912 offset_type b
= *(offset_type
*) bp
;
22914 return (a
> b
) - (b
> a
);
22917 /* Sort and remove duplicates of all symbols' cu_indices lists. */
22920 uniquify_cu_indices (struct mapped_symtab
*symtab
)
22924 for (i
= 0; i
< symtab
->size
; ++i
)
22926 struct symtab_index_entry
*entry
= symtab
->data
[i
];
22929 && entry
->cu_indices
!= NULL
)
22931 unsigned int next_to_insert
, next_to_check
;
22932 offset_type last_value
;
22934 qsort (VEC_address (offset_type
, entry
->cu_indices
),
22935 VEC_length (offset_type
, entry
->cu_indices
),
22936 sizeof (offset_type
), offset_type_compare
);
22938 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
22939 next_to_insert
= 1;
22940 for (next_to_check
= 1;
22941 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
22944 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
22947 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
22949 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
22954 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
22959 /* Add a vector of indices to the constant pool. */
22962 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
22963 struct symtab_index_entry
*entry
)
22967 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
22970 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
22971 offset_type val
= MAYBE_SWAP (len
);
22976 entry
->index_offset
= obstack_object_size (cpool
);
22978 obstack_grow (cpool
, &val
, sizeof (val
));
22980 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
22983 val
= MAYBE_SWAP (iter
);
22984 obstack_grow (cpool
, &val
, sizeof (val
));
22989 struct symtab_index_entry
*old_entry
22990 = (struct symtab_index_entry
*) *slot
;
22991 entry
->index_offset
= old_entry
->index_offset
;
22994 return entry
->index_offset
;
22997 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
22998 constant pool entries going into the obstack CPOOL. */
23001 write_hash_table (struct mapped_symtab
*symtab
,
23002 struct obstack
*output
, struct obstack
*cpool
)
23005 htab_t symbol_hash_table
;
23008 symbol_hash_table
= create_symbol_hash_table ();
23009 str_table
= create_strtab ();
23011 /* We add all the index vectors to the constant pool first, to
23012 ensure alignment is ok. */
23013 for (i
= 0; i
< symtab
->size
; ++i
)
23015 if (symtab
->data
[i
])
23016 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
23019 /* Now write out the hash table. */
23020 for (i
= 0; i
< symtab
->size
; ++i
)
23022 offset_type str_off
, vec_off
;
23024 if (symtab
->data
[i
])
23026 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
23027 vec_off
= symtab
->data
[i
]->index_offset
;
23031 /* While 0 is a valid constant pool index, it is not valid
23032 to have 0 for both offsets. */
23037 str_off
= MAYBE_SWAP (str_off
);
23038 vec_off
= MAYBE_SWAP (vec_off
);
23040 obstack_grow (output
, &str_off
, sizeof (str_off
));
23041 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
23044 htab_delete (str_table
);
23045 htab_delete (symbol_hash_table
);
23048 /* Struct to map psymtab to CU index in the index file. */
23049 struct psymtab_cu_index_map
23051 struct partial_symtab
*psymtab
;
23052 unsigned int cu_index
;
23056 hash_psymtab_cu_index (const void *item
)
23058 const struct psymtab_cu_index_map
*map
23059 = (const struct psymtab_cu_index_map
*) item
;
23061 return htab_hash_pointer (map
->psymtab
);
23065 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
23067 const struct psymtab_cu_index_map
*lhs
23068 = (const struct psymtab_cu_index_map
*) item_lhs
;
23069 const struct psymtab_cu_index_map
*rhs
23070 = (const struct psymtab_cu_index_map
*) item_rhs
;
23072 return lhs
->psymtab
== rhs
->psymtab
;
23075 /* Helper struct for building the address table. */
23076 struct addrmap_index_data
23078 struct objfile
*objfile
;
23079 struct obstack
*addr_obstack
;
23080 htab_t cu_index_htab
;
23082 /* Non-zero if the previous_* fields are valid.
23083 We can't write an entry until we see the next entry (since it is only then
23084 that we know the end of the entry). */
23085 int previous_valid
;
23086 /* Index of the CU in the table of all CUs in the index file. */
23087 unsigned int previous_cu_index
;
23088 /* Start address of the CU. */
23089 CORE_ADDR previous_cu_start
;
23092 /* Write an address entry to OBSTACK. */
23095 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
23096 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
23098 offset_type cu_index_to_write
;
23100 CORE_ADDR baseaddr
;
23102 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23104 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
23105 obstack_grow (obstack
, addr
, 8);
23106 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
23107 obstack_grow (obstack
, addr
, 8);
23108 cu_index_to_write
= MAYBE_SWAP (cu_index
);
23109 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
23112 /* Worker function for traversing an addrmap to build the address table. */
23115 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
23117 struct addrmap_index_data
*data
= (struct addrmap_index_data
*) datap
;
23118 struct partial_symtab
*pst
= (struct partial_symtab
*) obj
;
23120 if (data
->previous_valid
)
23121 add_address_entry (data
->objfile
, data
->addr_obstack
,
23122 data
->previous_cu_start
, start_addr
,
23123 data
->previous_cu_index
);
23125 data
->previous_cu_start
= start_addr
;
23128 struct psymtab_cu_index_map find_map
, *map
;
23129 find_map
.psymtab
= pst
;
23130 map
= ((struct psymtab_cu_index_map
*)
23131 htab_find (data
->cu_index_htab
, &find_map
));
23132 gdb_assert (map
!= NULL
);
23133 data
->previous_cu_index
= map
->cu_index
;
23134 data
->previous_valid
= 1;
23137 data
->previous_valid
= 0;
23142 /* Write OBJFILE's address map to OBSTACK.
23143 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
23144 in the index file. */
23147 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
23148 htab_t cu_index_htab
)
23150 struct addrmap_index_data addrmap_index_data
;
23152 /* When writing the address table, we have to cope with the fact that
23153 the addrmap iterator only provides the start of a region; we have to
23154 wait until the next invocation to get the start of the next region. */
23156 addrmap_index_data
.objfile
= objfile
;
23157 addrmap_index_data
.addr_obstack
= obstack
;
23158 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
23159 addrmap_index_data
.previous_valid
= 0;
23161 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
23162 &addrmap_index_data
);
23164 /* It's highly unlikely the last entry (end address = 0xff...ff)
23165 is valid, but we should still handle it.
23166 The end address is recorded as the start of the next region, but that
23167 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
23169 if (addrmap_index_data
.previous_valid
)
23170 add_address_entry (objfile
, obstack
,
23171 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
23172 addrmap_index_data
.previous_cu_index
);
23175 /* Return the symbol kind of PSYM. */
23177 static gdb_index_symbol_kind
23178 symbol_kind (struct partial_symbol
*psym
)
23180 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
23181 enum address_class aclass
= PSYMBOL_CLASS (psym
);
23189 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
23191 return GDB_INDEX_SYMBOL_KIND_TYPE
;
23193 case LOC_CONST_BYTES
:
23194 case LOC_OPTIMIZED_OUT
:
23196 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
23198 /* Note: It's currently impossible to recognize psyms as enum values
23199 short of reading the type info. For now punt. */
23200 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
23202 /* There are other LOC_FOO values that one might want to classify
23203 as variables, but dwarf2read.c doesn't currently use them. */
23204 return GDB_INDEX_SYMBOL_KIND_OTHER
;
23206 case STRUCT_DOMAIN
:
23207 return GDB_INDEX_SYMBOL_KIND_TYPE
;
23209 return GDB_INDEX_SYMBOL_KIND_OTHER
;
23213 /* Add a list of partial symbols to SYMTAB. */
23216 write_psymbols (struct mapped_symtab
*symtab
,
23218 struct partial_symbol
**psymp
,
23220 offset_type cu_index
,
23223 for (; count
-- > 0; ++psymp
)
23225 struct partial_symbol
*psym
= *psymp
;
23228 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
23229 error (_("Ada is not currently supported by the index"));
23231 /* Only add a given psymbol once. */
23232 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
23235 gdb_index_symbol_kind kind
= symbol_kind (psym
);
23238 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
23239 is_static
, kind
, cu_index
);
23244 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
23245 exception if there is an error. */
23248 write_obstack (FILE *file
, struct obstack
*obstack
)
23250 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
23252 != obstack_object_size (obstack
))
23253 error (_("couldn't data write to file"));
23256 /* Unlink a file if the argument is not NULL. */
23259 unlink_if_set (void *p
)
23261 char **filename
= (char **) p
;
23263 unlink (*filename
);
23266 /* A helper struct used when iterating over debug_types. */
23267 struct signatured_type_index_data
23269 struct objfile
*objfile
;
23270 struct mapped_symtab
*symtab
;
23271 struct obstack
*types_list
;
23276 /* A helper function that writes a single signatured_type to an
23280 write_one_signatured_type (void **slot
, void *d
)
23282 struct signatured_type_index_data
*info
23283 = (struct signatured_type_index_data
*) d
;
23284 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
23285 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
23288 write_psymbols (info
->symtab
,
23290 info
->objfile
->global_psymbols
.list
23291 + psymtab
->globals_offset
,
23292 psymtab
->n_global_syms
, info
->cu_index
,
23294 write_psymbols (info
->symtab
,
23296 info
->objfile
->static_psymbols
.list
23297 + psymtab
->statics_offset
,
23298 psymtab
->n_static_syms
, info
->cu_index
,
23301 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23302 entry
->per_cu
.offset
.sect_off
);
23303 obstack_grow (info
->types_list
, val
, 8);
23304 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23305 entry
->type_offset_in_tu
.cu_off
);
23306 obstack_grow (info
->types_list
, val
, 8);
23307 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
23308 obstack_grow (info
->types_list
, val
, 8);
23315 /* Recurse into all "included" dependencies and write their symbols as
23316 if they appeared in this psymtab. */
23319 recursively_write_psymbols (struct objfile
*objfile
,
23320 struct partial_symtab
*psymtab
,
23321 struct mapped_symtab
*symtab
,
23323 offset_type cu_index
)
23327 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
23328 if (psymtab
->dependencies
[i
]->user
!= NULL
)
23329 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
23330 symtab
, psyms_seen
, cu_index
);
23332 write_psymbols (symtab
,
23334 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
23335 psymtab
->n_global_syms
, cu_index
,
23337 write_psymbols (symtab
,
23339 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
23340 psymtab
->n_static_syms
, cu_index
,
23344 /* Create an index file for OBJFILE in the directory DIR. */
23347 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
23349 struct cleanup
*cleanup
;
23350 char *filename
, *cleanup_filename
;
23351 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
23352 struct obstack cu_list
, types_cu_list
;
23355 struct mapped_symtab
*symtab
;
23356 offset_type val
, size_of_contents
, total_len
;
23359 htab_t cu_index_htab
;
23360 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
23362 if (dwarf2_per_objfile
->using_index
)
23363 error (_("Cannot use an index to create the index"));
23365 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
23366 error (_("Cannot make an index when the file has multiple .debug_types sections"));
23368 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
23371 if (stat (objfile_name (objfile
), &st
) < 0)
23372 perror_with_name (objfile_name (objfile
));
23374 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile_name (objfile
)),
23375 INDEX_SUFFIX
, (char *) NULL
);
23376 cleanup
= make_cleanup (xfree
, filename
);
23378 out_file
= gdb_fopen_cloexec (filename
, "wb");
23380 error (_("Can't open `%s' for writing"), filename
);
23382 cleanup_filename
= filename
;
23383 make_cleanup (unlink_if_set
, &cleanup_filename
);
23385 symtab
= create_mapped_symtab ();
23386 make_cleanup (cleanup_mapped_symtab
, symtab
);
23388 obstack_init (&addr_obstack
);
23389 make_cleanup_obstack_free (&addr_obstack
);
23391 obstack_init (&cu_list
);
23392 make_cleanup_obstack_free (&cu_list
);
23394 obstack_init (&types_cu_list
);
23395 make_cleanup_obstack_free (&types_cu_list
);
23397 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
23398 NULL
, xcalloc
, xfree
);
23399 make_cleanup_htab_delete (psyms_seen
);
23401 /* While we're scanning CU's create a table that maps a psymtab pointer
23402 (which is what addrmap records) to its index (which is what is recorded
23403 in the index file). This will later be needed to write the address
23405 cu_index_htab
= htab_create_alloc (100,
23406 hash_psymtab_cu_index
,
23407 eq_psymtab_cu_index
,
23408 NULL
, xcalloc
, xfree
);
23409 make_cleanup_htab_delete (cu_index_htab
);
23410 psymtab_cu_index_map
= XNEWVEC (struct psymtab_cu_index_map
,
23411 dwarf2_per_objfile
->n_comp_units
);
23412 make_cleanup (xfree
, psymtab_cu_index_map
);
23414 /* The CU list is already sorted, so we don't need to do additional
23415 work here. Also, the debug_types entries do not appear in
23416 all_comp_units, but only in their own hash table. */
23417 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
23419 struct dwarf2_per_cu_data
*per_cu
23420 = dwarf2_per_objfile
->all_comp_units
[i
];
23421 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
23423 struct psymtab_cu_index_map
*map
;
23426 /* CU of a shared file from 'dwz -m' may be unused by this main file.
23427 It may be referenced from a local scope but in such case it does not
23428 need to be present in .gdb_index. */
23429 if (psymtab
== NULL
)
23432 if (psymtab
->user
== NULL
)
23433 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
23435 map
= &psymtab_cu_index_map
[i
];
23436 map
->psymtab
= psymtab
;
23438 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
23439 gdb_assert (slot
!= NULL
);
23440 gdb_assert (*slot
== NULL
);
23443 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23444 per_cu
->offset
.sect_off
);
23445 obstack_grow (&cu_list
, val
, 8);
23446 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
23447 obstack_grow (&cu_list
, val
, 8);
23450 /* Dump the address map. */
23451 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
23453 /* Write out the .debug_type entries, if any. */
23454 if (dwarf2_per_objfile
->signatured_types
)
23456 struct signatured_type_index_data sig_data
;
23458 sig_data
.objfile
= objfile
;
23459 sig_data
.symtab
= symtab
;
23460 sig_data
.types_list
= &types_cu_list
;
23461 sig_data
.psyms_seen
= psyms_seen
;
23462 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
23463 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
23464 write_one_signatured_type
, &sig_data
);
23467 /* Now that we've processed all symbols we can shrink their cu_indices
23469 uniquify_cu_indices (symtab
);
23471 obstack_init (&constant_pool
);
23472 make_cleanup_obstack_free (&constant_pool
);
23473 obstack_init (&symtab_obstack
);
23474 make_cleanup_obstack_free (&symtab_obstack
);
23475 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
23477 obstack_init (&contents
);
23478 make_cleanup_obstack_free (&contents
);
23479 size_of_contents
= 6 * sizeof (offset_type
);
23480 total_len
= size_of_contents
;
23482 /* The version number. */
23483 val
= MAYBE_SWAP (8);
23484 obstack_grow (&contents
, &val
, sizeof (val
));
23486 /* The offset of the CU list from the start of the file. */
23487 val
= MAYBE_SWAP (total_len
);
23488 obstack_grow (&contents
, &val
, sizeof (val
));
23489 total_len
+= obstack_object_size (&cu_list
);
23491 /* The offset of the types CU list from the start of the file. */
23492 val
= MAYBE_SWAP (total_len
);
23493 obstack_grow (&contents
, &val
, sizeof (val
));
23494 total_len
+= obstack_object_size (&types_cu_list
);
23496 /* The offset of the address table from the start of the file. */
23497 val
= MAYBE_SWAP (total_len
);
23498 obstack_grow (&contents
, &val
, sizeof (val
));
23499 total_len
+= obstack_object_size (&addr_obstack
);
23501 /* The offset of the symbol table from the start of the file. */
23502 val
= MAYBE_SWAP (total_len
);
23503 obstack_grow (&contents
, &val
, sizeof (val
));
23504 total_len
+= obstack_object_size (&symtab_obstack
);
23506 /* The offset of the constant pool from the start of the file. */
23507 val
= MAYBE_SWAP (total_len
);
23508 obstack_grow (&contents
, &val
, sizeof (val
));
23509 total_len
+= obstack_object_size (&constant_pool
);
23511 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
23513 write_obstack (out_file
, &contents
);
23514 write_obstack (out_file
, &cu_list
);
23515 write_obstack (out_file
, &types_cu_list
);
23516 write_obstack (out_file
, &addr_obstack
);
23517 write_obstack (out_file
, &symtab_obstack
);
23518 write_obstack (out_file
, &constant_pool
);
23522 /* We want to keep the file, so we set cleanup_filename to NULL
23523 here. See unlink_if_set. */
23524 cleanup_filename
= NULL
;
23526 do_cleanups (cleanup
);
23529 /* Implementation of the `save gdb-index' command.
23531 Note that the file format used by this command is documented in the
23532 GDB manual. Any changes here must be documented there. */
23535 save_gdb_index_command (char *arg
, int from_tty
)
23537 struct objfile
*objfile
;
23540 error (_("usage: save gdb-index DIRECTORY"));
23542 ALL_OBJFILES (objfile
)
23546 /* If the objfile does not correspond to an actual file, skip it. */
23547 if (stat (objfile_name (objfile
), &st
) < 0)
23551 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
23552 dwarf2_objfile_data_key
);
23553 if (dwarf2_per_objfile
)
23558 write_psymtabs_to_index (objfile
, arg
);
23560 CATCH (except
, RETURN_MASK_ERROR
)
23562 exception_fprintf (gdb_stderr
, except
,
23563 _("Error while writing index for `%s': "),
23564 objfile_name (objfile
));
23573 int dwarf_always_disassemble
;
23576 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
23577 struct cmd_list_element
*c
, const char *value
)
23579 fprintf_filtered (file
,
23580 _("Whether to always disassemble "
23581 "DWARF expressions is %s.\n"),
23586 show_check_physname (struct ui_file
*file
, int from_tty
,
23587 struct cmd_list_element
*c
, const char *value
)
23589 fprintf_filtered (file
,
23590 _("Whether to check \"physname\" is %s.\n"),
23594 void _initialize_dwarf2_read (void);
23597 _initialize_dwarf2_read (void)
23599 struct cmd_list_element
*c
;
23601 dwarf2_objfile_data_key
23602 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
23604 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23605 Set DWARF specific variables.\n\
23606 Configure DWARF variables such as the cache size"),
23607 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23608 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23610 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23611 Show DWARF specific variables\n\
23612 Show DWARF variables such as the cache size"),
23613 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23614 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23616 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23617 &dwarf_max_cache_age
, _("\
23618 Set the upper bound on the age of cached DWARF compilation units."), _("\
23619 Show the upper bound on the age of cached DWARF compilation units."), _("\
23620 A higher limit means that cached compilation units will be stored\n\
23621 in memory longer, and more total memory will be used. Zero disables\n\
23622 caching, which can slow down startup."),
23624 show_dwarf_max_cache_age
,
23625 &set_dwarf_cmdlist
,
23626 &show_dwarf_cmdlist
);
23628 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
23629 &dwarf_always_disassemble
, _("\
23630 Set whether `info address' always disassembles DWARF expressions."), _("\
23631 Show whether `info address' always disassembles DWARF expressions."), _("\
23632 When enabled, DWARF expressions are always printed in an assembly-like\n\
23633 syntax. When disabled, expressions will be printed in a more\n\
23634 conversational style, when possible."),
23636 show_dwarf_always_disassemble
,
23637 &set_dwarf_cmdlist
,
23638 &show_dwarf_cmdlist
);
23640 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23641 Set debugging of the DWARF reader."), _("\
23642 Show debugging of the DWARF reader."), _("\
23643 When enabled (non-zero), debugging messages are printed during DWARF\n\
23644 reading and symtab expansion. A value of 1 (one) provides basic\n\
23645 information. A value greater than 1 provides more verbose information."),
23648 &setdebuglist
, &showdebuglist
);
23650 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23651 Set debugging of the DWARF DIE reader."), _("\
23652 Show debugging of the DWARF DIE reader."), _("\
23653 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23654 The value is the maximum depth to print."),
23657 &setdebuglist
, &showdebuglist
);
23659 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23660 Set debugging of the dwarf line reader."), _("\
23661 Show debugging of the dwarf line reader."), _("\
23662 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23663 A value of 1 (one) provides basic information.\n\
23664 A value greater than 1 provides more verbose information."),
23667 &setdebuglist
, &showdebuglist
);
23669 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23670 Set cross-checking of \"physname\" code against demangler."), _("\
23671 Show cross-checking of \"physname\" code against demangler."), _("\
23672 When enabled, GDB's internal \"physname\" code is checked against\n\
23674 NULL
, show_check_physname
,
23675 &setdebuglist
, &showdebuglist
);
23677 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23678 no_class
, &use_deprecated_index_sections
, _("\
23679 Set whether to use deprecated gdb_index sections."), _("\
23680 Show whether to use deprecated gdb_index sections."), _("\
23681 When enabled, deprecated .gdb_index sections are used anyway.\n\
23682 Normally they are ignored either because of a missing feature or\n\
23683 performance issue.\n\
23684 Warning: This option must be enabled before gdb reads the file."),
23687 &setlist
, &showlist
);
23689 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
23691 Save a gdb-index file.\n\
23692 Usage: save gdb-index DIRECTORY"),
23694 set_cmd_completer (c
, filename_completer
);
23696 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23697 &dwarf2_locexpr_funcs
);
23698 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23699 &dwarf2_loclist_funcs
);
23701 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23702 &dwarf2_block_frame_base_locexpr_funcs
);
23703 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23704 &dwarf2_block_frame_base_loclist_funcs
);