1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2013 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
40 #include "gdb-demangle.h"
41 #include "expression.h"
42 #include "filenames.h" /* for DOSish file names */
45 #include "complaints.h"
47 #include "dwarf2expr.h"
48 #include "dwarf2loc.h"
49 #include "cp-support.h"
55 #include "typeprint.h"
58 #include "exceptions.h"
60 #include "completer.h"
65 #include "gdbcore.h" /* for gnutarget */
66 #include "gdb/gdb-index.h"
71 #include "filestuff.h"
75 #include "gdb_string.h"
76 #include "gdb_assert.h"
77 #include <sys/types.h>
79 typedef struct symbol
*symbolp
;
82 /* When non-zero, print basic high level tracing messages.
83 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
84 static int dwarf2_read_debug
= 0;
86 /* When non-zero, dump DIEs after they are read in. */
87 static unsigned int dwarf2_die_debug
= 0;
89 /* When non-zero, cross-check physname against demangler. */
90 static int check_physname
= 0;
92 /* When non-zero, do not reject deprecated .gdb_index sections. */
93 static int use_deprecated_index_sections
= 0;
95 static const struct objfile_data
*dwarf2_objfile_data_key
;
97 /* The "aclass" indices for various kinds of computed DWARF symbols. */
99 static int dwarf2_locexpr_index
;
100 static int dwarf2_loclist_index
;
101 static int dwarf2_locexpr_block_index
;
102 static int dwarf2_loclist_block_index
;
104 /* A descriptor for dwarf sections.
106 S.ASECTION, SIZE are typically initialized when the objfile is first
107 scanned. BUFFER, READIN are filled in later when the section is read.
108 If the section contained compressed data then SIZE is updated to record
109 the uncompressed size of the section.
111 DWP file format V2 introduces a wrinkle that is easiest to handle by
112 creating the concept of virtual sections contained within a real section.
113 In DWP V2 the sections of the input DWO files are concatenated together
114 into one section, but section offsets are kept relative to the original
116 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
117 the real section this "virtual" section is contained in, and BUFFER,SIZE
118 describe the virtual section. */
120 struct dwarf2_section_info
124 /* If this is a real section, the bfd section. */
126 /* If this is a virtual section, pointer to the containing ("real")
128 struct dwarf2_section_info
*containing_section
;
130 /* Pointer to section data, only valid if readin. */
131 const gdb_byte
*buffer
;
132 /* The size of the section, real or virtual. */
134 /* If this is a virtual section, the offset in the real section.
135 Only valid if is_virtual. */
136 bfd_size_type virtual_offset
;
137 /* True if we have tried to read this section. */
139 /* True if this is a virtual section, False otherwise.
140 This specifies which of s.asection and s.containing_section to use. */
144 typedef struct dwarf2_section_info dwarf2_section_info_def
;
145 DEF_VEC_O (dwarf2_section_info_def
);
147 /* All offsets in the index are of this type. It must be
148 architecture-independent. */
149 typedef uint32_t offset_type
;
151 DEF_VEC_I (offset_type
);
153 /* Ensure only legit values are used. */
154 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
156 gdb_assert ((unsigned int) (value) <= 1); \
157 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
160 /* Ensure only legit values are used. */
161 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
163 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
164 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
165 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
168 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
169 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
171 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
172 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
175 /* A description of the mapped index. The file format is described in
176 a comment by the code that writes the index. */
179 /* Index data format version. */
182 /* The total length of the buffer. */
185 /* A pointer to the address table data. */
186 const gdb_byte
*address_table
;
188 /* Size of the address table data in bytes. */
189 offset_type address_table_size
;
191 /* The symbol table, implemented as a hash table. */
192 const offset_type
*symbol_table
;
194 /* Size in slots, each slot is 2 offset_types. */
195 offset_type symbol_table_slots
;
197 /* A pointer to the constant pool. */
198 const char *constant_pool
;
201 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
202 DEF_VEC_P (dwarf2_per_cu_ptr
);
204 /* Collection of data recorded per objfile.
205 This hangs off of dwarf2_objfile_data_key. */
207 struct dwarf2_per_objfile
209 struct dwarf2_section_info info
;
210 struct dwarf2_section_info abbrev
;
211 struct dwarf2_section_info line
;
212 struct dwarf2_section_info loc
;
213 struct dwarf2_section_info macinfo
;
214 struct dwarf2_section_info macro
;
215 struct dwarf2_section_info str
;
216 struct dwarf2_section_info ranges
;
217 struct dwarf2_section_info addr
;
218 struct dwarf2_section_info frame
;
219 struct dwarf2_section_info eh_frame
;
220 struct dwarf2_section_info gdb_index
;
222 VEC (dwarf2_section_info_def
) *types
;
225 struct objfile
*objfile
;
227 /* Table of all the compilation units. This is used to locate
228 the target compilation unit of a particular reference. */
229 struct dwarf2_per_cu_data
**all_comp_units
;
231 /* The number of compilation units in ALL_COMP_UNITS. */
234 /* The number of .debug_types-related CUs. */
237 /* The .debug_types-related CUs (TUs).
238 This is stored in malloc space because we may realloc it. */
239 struct signatured_type
**all_type_units
;
241 /* The number of entries in all_type_unit_groups. */
242 int n_type_unit_groups
;
244 /* Table of type unit groups.
245 This exists to make it easy to iterate over all CUs and TU groups. */
246 struct type_unit_group
**all_type_unit_groups
;
248 /* Table of struct type_unit_group objects.
249 The hash key is the DW_AT_stmt_list value. */
250 htab_t type_unit_groups
;
252 /* A table mapping .debug_types signatures to its signatured_type entry.
253 This is NULL if the .debug_types section hasn't been read in yet. */
254 htab_t signatured_types
;
256 /* Type unit statistics, to see how well the scaling improvements
260 int nr_uniq_abbrev_tables
;
262 int nr_symtab_sharers
;
263 int nr_stmt_less_type_units
;
266 /* A chain of compilation units that are currently read in, so that
267 they can be freed later. */
268 struct dwarf2_per_cu_data
*read_in_chain
;
270 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
271 This is NULL if the table hasn't been allocated yet. */
274 /* Non-zero if we've check for whether there is a DWP file. */
277 /* The DWP file if there is one, or NULL. */
278 struct dwp_file
*dwp_file
;
280 /* The shared '.dwz' file, if one exists. This is used when the
281 original data was compressed using 'dwz -m'. */
282 struct dwz_file
*dwz_file
;
284 /* A flag indicating wether this objfile has a section loaded at a
286 int has_section_at_zero
;
288 /* True if we are using the mapped index,
289 or we are faking it for OBJF_READNOW's sake. */
290 unsigned char using_index
;
292 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
293 struct mapped_index
*index_table
;
295 /* When using index_table, this keeps track of all quick_file_names entries.
296 TUs typically share line table entries with a CU, so we maintain a
297 separate table of all line table entries to support the sharing.
298 Note that while there can be way more TUs than CUs, we've already
299 sorted all the TUs into "type unit groups", grouped by their
300 DW_AT_stmt_list value. Therefore the only sharing done here is with a
301 CU and its associated TU group if there is one. */
302 htab_t quick_file_names_table
;
304 /* Set during partial symbol reading, to prevent queueing of full
306 int reading_partial_symbols
;
308 /* Table mapping type DIEs to their struct type *.
309 This is NULL if not allocated yet.
310 The mapping is done via (CU/TU + DIE offset) -> type. */
311 htab_t die_type_hash
;
313 /* The CUs we recently read. */
314 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
317 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
319 /* Default names of the debugging sections. */
321 /* Note that if the debugging section has been compressed, it might
322 have a name like .zdebug_info. */
324 static const struct dwarf2_debug_sections dwarf2_elf_names
=
326 { ".debug_info", ".zdebug_info" },
327 { ".debug_abbrev", ".zdebug_abbrev" },
328 { ".debug_line", ".zdebug_line" },
329 { ".debug_loc", ".zdebug_loc" },
330 { ".debug_macinfo", ".zdebug_macinfo" },
331 { ".debug_macro", ".zdebug_macro" },
332 { ".debug_str", ".zdebug_str" },
333 { ".debug_ranges", ".zdebug_ranges" },
334 { ".debug_types", ".zdebug_types" },
335 { ".debug_addr", ".zdebug_addr" },
336 { ".debug_frame", ".zdebug_frame" },
337 { ".eh_frame", NULL
},
338 { ".gdb_index", ".zgdb_index" },
342 /* List of DWO/DWP sections. */
344 static const struct dwop_section_names
346 struct dwarf2_section_names abbrev_dwo
;
347 struct dwarf2_section_names info_dwo
;
348 struct dwarf2_section_names line_dwo
;
349 struct dwarf2_section_names loc_dwo
;
350 struct dwarf2_section_names macinfo_dwo
;
351 struct dwarf2_section_names macro_dwo
;
352 struct dwarf2_section_names str_dwo
;
353 struct dwarf2_section_names str_offsets_dwo
;
354 struct dwarf2_section_names types_dwo
;
355 struct dwarf2_section_names cu_index
;
356 struct dwarf2_section_names tu_index
;
360 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
361 { ".debug_info.dwo", ".zdebug_info.dwo" },
362 { ".debug_line.dwo", ".zdebug_line.dwo" },
363 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
364 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
365 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
366 { ".debug_str.dwo", ".zdebug_str.dwo" },
367 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
368 { ".debug_types.dwo", ".zdebug_types.dwo" },
369 { ".debug_cu_index", ".zdebug_cu_index" },
370 { ".debug_tu_index", ".zdebug_tu_index" },
373 /* local data types */
375 /* The data in a compilation unit header, after target2host
376 translation, looks like this. */
377 struct comp_unit_head
381 unsigned char addr_size
;
382 unsigned char signed_addr_p
;
383 sect_offset abbrev_offset
;
385 /* Size of file offsets; either 4 or 8. */
386 unsigned int offset_size
;
388 /* Size of the length field; either 4 or 12. */
389 unsigned int initial_length_size
;
391 /* Offset to the first byte of this compilation unit header in the
392 .debug_info section, for resolving relative reference dies. */
395 /* Offset to first die in this cu from the start of the cu.
396 This will be the first byte following the compilation unit header. */
397 cu_offset first_die_offset
;
400 /* Type used for delaying computation of method physnames.
401 See comments for compute_delayed_physnames. */
402 struct delayed_method_info
404 /* The type to which the method is attached, i.e., its parent class. */
407 /* The index of the method in the type's function fieldlists. */
410 /* The index of the method in the fieldlist. */
413 /* The name of the DIE. */
416 /* The DIE associated with this method. */
417 struct die_info
*die
;
420 typedef struct delayed_method_info delayed_method_info
;
421 DEF_VEC_O (delayed_method_info
);
423 /* Internal state when decoding a particular compilation unit. */
426 /* The objfile containing this compilation unit. */
427 struct objfile
*objfile
;
429 /* The header of the compilation unit. */
430 struct comp_unit_head header
;
432 /* Base address of this compilation unit. */
433 CORE_ADDR base_address
;
435 /* Non-zero if base_address has been set. */
438 /* The language we are debugging. */
439 enum language language
;
440 const struct language_defn
*language_defn
;
442 const char *producer
;
444 /* The generic symbol table building routines have separate lists for
445 file scope symbols and all all other scopes (local scopes). So
446 we need to select the right one to pass to add_symbol_to_list().
447 We do it by keeping a pointer to the correct list in list_in_scope.
449 FIXME: The original dwarf code just treated the file scope as the
450 first local scope, and all other local scopes as nested local
451 scopes, and worked fine. Check to see if we really need to
452 distinguish these in buildsym.c. */
453 struct pending
**list_in_scope
;
455 /* The abbrev table for this CU.
456 Normally this points to the abbrev table in the objfile.
457 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
458 struct abbrev_table
*abbrev_table
;
460 /* Hash table holding all the loaded partial DIEs
461 with partial_die->offset.SECT_OFF as hash. */
464 /* Storage for things with the same lifetime as this read-in compilation
465 unit, including partial DIEs. */
466 struct obstack comp_unit_obstack
;
468 /* When multiple dwarf2_cu structures are living in memory, this field
469 chains them all together, so that they can be released efficiently.
470 We will probably also want a generation counter so that most-recently-used
471 compilation units are cached... */
472 struct dwarf2_per_cu_data
*read_in_chain
;
474 /* Backlink to our per_cu entry. */
475 struct dwarf2_per_cu_data
*per_cu
;
477 /* How many compilation units ago was this CU last referenced? */
480 /* A hash table of DIE cu_offset for following references with
481 die_info->offset.sect_off as hash. */
484 /* Full DIEs if read in. */
485 struct die_info
*dies
;
487 /* A set of pointers to dwarf2_per_cu_data objects for compilation
488 units referenced by this one. Only set during full symbol processing;
489 partial symbol tables do not have dependencies. */
492 /* Header data from the line table, during full symbol processing. */
493 struct line_header
*line_header
;
495 /* A list of methods which need to have physnames computed
496 after all type information has been read. */
497 VEC (delayed_method_info
) *method_list
;
499 /* To be copied to symtab->call_site_htab. */
500 htab_t call_site_htab
;
502 /* Non-NULL if this CU came from a DWO file.
503 There is an invariant here that is important to remember:
504 Except for attributes copied from the top level DIE in the "main"
505 (or "stub") file in preparation for reading the DWO file
506 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
507 Either there isn't a DWO file (in which case this is NULL and the point
508 is moot), or there is and either we're not going to read it (in which
509 case this is NULL) or there is and we are reading it (in which case this
511 struct dwo_unit
*dwo_unit
;
513 /* The DW_AT_addr_base attribute if present, zero otherwise
514 (zero is a valid value though).
515 Note this value comes from the stub CU/TU's DIE. */
518 /* The DW_AT_ranges_base attribute if present, zero otherwise
519 (zero is a valid value though).
520 Note this value comes from the stub CU/TU's DIE.
521 Also note that the value is zero in the non-DWO case so this value can
522 be used without needing to know whether DWO files are in use or not.
523 N.B. This does not apply to DW_AT_ranges appearing in
524 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
525 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
526 DW_AT_ranges_base *would* have to be applied, and we'd have to care
527 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
528 ULONGEST ranges_base
;
530 /* Mark used when releasing cached dies. */
531 unsigned int mark
: 1;
533 /* This CU references .debug_loc. See the symtab->locations_valid field.
534 This test is imperfect as there may exist optimized debug code not using
535 any location list and still facing inlining issues if handled as
536 unoptimized code. For a future better test see GCC PR other/32998. */
537 unsigned int has_loclist
: 1;
539 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
540 if all the producer_is_* fields are valid. This information is cached
541 because profiling CU expansion showed excessive time spent in
542 producer_is_gxx_lt_4_6. */
543 unsigned int checked_producer
: 1;
544 unsigned int producer_is_gxx_lt_4_6
: 1;
545 unsigned int producer_is_gcc_lt_4_3
: 1;
546 unsigned int producer_is_icc
: 1;
548 /* When set, the file that we're processing is known to have
549 debugging info for C++ namespaces. GCC 3.3.x did not produce
550 this information, but later versions do. */
552 unsigned int processing_has_namespace_info
: 1;
555 /* Persistent data held for a compilation unit, even when not
556 processing it. We put a pointer to this structure in the
557 read_symtab_private field of the psymtab. */
559 struct dwarf2_per_cu_data
561 /* The start offset and length of this compilation unit.
562 NOTE: Unlike comp_unit_head.length, this length includes
564 If the DIE refers to a DWO file, this is always of the original die,
569 /* Flag indicating this compilation unit will be read in before
570 any of the current compilation units are processed. */
571 unsigned int queued
: 1;
573 /* This flag will be set when reading partial DIEs if we need to load
574 absolutely all DIEs for this compilation unit, instead of just the ones
575 we think are interesting. It gets set if we look for a DIE in the
576 hash table and don't find it. */
577 unsigned int load_all_dies
: 1;
579 /* Non-zero if this CU is from .debug_types.
580 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
582 unsigned int is_debug_types
: 1;
584 /* Non-zero if this CU is from the .dwz file. */
585 unsigned int is_dwz
: 1;
587 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
588 This flag is only valid if is_debug_types is true.
589 We can't read a CU directly from a DWO file: There are required
590 attributes in the stub. */
591 unsigned int reading_dwo_directly
: 1;
593 /* Non-zero if the TU has been read.
594 This is used to assist the "Stay in DWO Optimization" for Fission:
595 When reading a DWO, it's faster to read TUs from the DWO instead of
596 fetching them from random other DWOs (due to comdat folding).
597 If the TU has already been read, the optimization is unnecessary
598 (and unwise - we don't want to change where gdb thinks the TU lives
600 This flag is only valid if is_debug_types is true. */
601 unsigned int tu_read
: 1;
603 /* The section this CU/TU lives in.
604 If the DIE refers to a DWO file, this is always the original die,
606 struct dwarf2_section_info
*section
;
608 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
609 of the CU cache it gets reset to NULL again. */
610 struct dwarf2_cu
*cu
;
612 /* The corresponding objfile.
613 Normally we can get the objfile from dwarf2_per_objfile.
614 However we can enter this file with just a "per_cu" handle. */
615 struct objfile
*objfile
;
617 /* When using partial symbol tables, the 'psymtab' field is active.
618 Otherwise the 'quick' field is active. */
621 /* The partial symbol table associated with this compilation unit,
622 or NULL for unread partial units. */
623 struct partial_symtab
*psymtab
;
625 /* Data needed by the "quick" functions. */
626 struct dwarf2_per_cu_quick_data
*quick
;
629 /* The CUs we import using DW_TAG_imported_unit. This is filled in
630 while reading psymtabs, used to compute the psymtab dependencies,
631 and then cleared. Then it is filled in again while reading full
632 symbols, and only deleted when the objfile is destroyed.
634 This is also used to work around a difference between the way gold
635 generates .gdb_index version <=7 and the way gdb does. Arguably this
636 is a gold bug. For symbols coming from TUs, gold records in the index
637 the CU that includes the TU instead of the TU itself. This breaks
638 dw2_lookup_symbol: It assumes that if the index says symbol X lives
639 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
640 will find X. Alas TUs live in their own symtab, so after expanding CU Y
641 we need to look in TU Z to find X. Fortunately, this is akin to
642 DW_TAG_imported_unit, so we just use the same mechanism: For
643 .gdb_index version <=7 this also records the TUs that the CU referred
644 to. Concurrently with this change gdb was modified to emit version 8
645 indices so we only pay a price for gold generated indices.
646 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
647 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
650 /* Entry in the signatured_types hash table. */
652 struct signatured_type
654 /* The "per_cu" object of this type.
655 This struct is used iff per_cu.is_debug_types.
656 N.B.: This is the first member so that it's easy to convert pointers
658 struct dwarf2_per_cu_data per_cu
;
660 /* The type's signature. */
663 /* Offset in the TU of the type's DIE, as read from the TU header.
664 If this TU is a DWO stub and the definition lives in a DWO file
665 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
666 cu_offset type_offset_in_tu
;
668 /* Offset in the section of the type's DIE.
669 If the definition lives in a DWO file, this is the offset in the
670 .debug_types.dwo section.
671 The value is zero until the actual value is known.
672 Zero is otherwise not a valid section offset. */
673 sect_offset type_offset_in_section
;
675 /* Type units are grouped by their DW_AT_stmt_list entry so that they
676 can share them. This points to the containing symtab. */
677 struct type_unit_group
*type_unit_group
;
680 The first time we encounter this type we fully read it in and install it
681 in the symbol tables. Subsequent times we only need the type. */
684 /* Containing DWO unit.
685 This field is valid iff per_cu.reading_dwo_directly. */
686 struct dwo_unit
*dwo_unit
;
689 typedef struct signatured_type
*sig_type_ptr
;
690 DEF_VEC_P (sig_type_ptr
);
692 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
693 This includes type_unit_group and quick_file_names. */
695 struct stmt_list_hash
697 /* The DWO unit this table is from or NULL if there is none. */
698 struct dwo_unit
*dwo_unit
;
700 /* Offset in .debug_line or .debug_line.dwo. */
701 sect_offset line_offset
;
704 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
705 an object of this type. */
707 struct type_unit_group
709 /* dwarf2read.c's main "handle" on a TU symtab.
710 To simplify things we create an artificial CU that "includes" all the
711 type units using this stmt_list so that the rest of the code still has
712 a "per_cu" handle on the symtab.
713 This PER_CU is recognized by having no section. */
714 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
715 struct dwarf2_per_cu_data per_cu
;
717 /* The TUs that share this DW_AT_stmt_list entry.
718 This is added to while parsing type units to build partial symtabs,
719 and is deleted afterwards and not used again. */
720 VEC (sig_type_ptr
) *tus
;
722 /* The primary symtab.
723 Type units in a group needn't all be defined in the same source file,
724 so we create an essentially anonymous symtab as the primary symtab. */
725 struct symtab
*primary_symtab
;
727 /* The data used to construct the hash key. */
728 struct stmt_list_hash hash
;
730 /* The number of symtabs from the line header.
731 The value here must match line_header.num_file_names. */
732 unsigned int num_symtabs
;
734 /* The symbol tables for this TU (obtained from the files listed in
736 WARNING: The order of entries here must match the order of entries
737 in the line header. After the first TU using this type_unit_group, the
738 line header for the subsequent TUs is recreated from this. This is done
739 because we need to use the same symtabs for each TU using the same
740 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
741 there's no guarantee the line header doesn't have duplicate entries. */
742 struct symtab
**symtabs
;
745 /* These sections are what may appear in a (real or virtual) DWO file. */
749 struct dwarf2_section_info abbrev
;
750 struct dwarf2_section_info line
;
751 struct dwarf2_section_info loc
;
752 struct dwarf2_section_info macinfo
;
753 struct dwarf2_section_info macro
;
754 struct dwarf2_section_info str
;
755 struct dwarf2_section_info str_offsets
;
756 /* In the case of a virtual DWO file, these two are unused. */
757 struct dwarf2_section_info info
;
758 VEC (dwarf2_section_info_def
) *types
;
761 /* CUs/TUs in DWP/DWO files. */
765 /* Backlink to the containing struct dwo_file. */
766 struct dwo_file
*dwo_file
;
768 /* The "id" that distinguishes this CU/TU.
769 .debug_info calls this "dwo_id", .debug_types calls this "signature".
770 Since signatures came first, we stick with it for consistency. */
773 /* The section this CU/TU lives in, in the DWO file. */
774 struct dwarf2_section_info
*section
;
776 /* Same as dwarf2_per_cu_data:{offset,length} but in the DWO section. */
780 /* For types, offset in the type's DIE of the type defined by this TU. */
781 cu_offset type_offset_in_tu
;
784 /* include/dwarf2.h defines the DWP section codes.
785 It defines a max value but it doesn't define a min value, which we
786 use for error checking, so provide one. */
788 enum dwp_v2_section_ids
793 /* Data for one DWO file.
795 This includes virtual DWO files (a virtual DWO file is a DWO file as it
796 appears in a DWP file). DWP files don't really have DWO files per se -
797 comdat folding of types "loses" the DWO file they came from, and from
798 a high level view DWP files appear to contain a mass of random types.
799 However, to maintain consistency with the non-DWP case we pretend DWP
800 files contain virtual DWO files, and we assign each TU with one virtual
801 DWO file (generally based on the line and abbrev section offsets -
802 a heuristic that seems to work in practice). */
806 /* The DW_AT_GNU_dwo_name attribute.
807 For virtual DWO files the name is constructed from the section offsets
808 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
809 from related CU+TUs. */
810 const char *dwo_name
;
812 /* The DW_AT_comp_dir attribute. */
813 const char *comp_dir
;
815 /* The bfd, when the file is open. Otherwise this is NULL.
816 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
819 /* The sections that make up this DWO file.
820 Remember that for virtual DWO files in DWP V2, these are virtual
821 sections (for lack of a better name). */
822 struct dwo_sections sections
;
824 /* The CU in the file.
825 We only support one because having more than one requires hacking the
826 dwo_name of each to match, which is highly unlikely to happen.
827 Doing this means all TUs can share comp_dir: We also assume that
828 DW_AT_comp_dir across all TUs in a DWO file will be identical. */
831 /* Table of TUs in the file.
832 Each element is a struct dwo_unit. */
836 /* These sections are what may appear in a DWP file. */
840 /* These are used by both DWP version 1 and 2. */
841 struct dwarf2_section_info str
;
842 struct dwarf2_section_info cu_index
;
843 struct dwarf2_section_info tu_index
;
845 /* These are only used by DWP version 2 files.
846 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
847 sections are referenced by section number, and are not recorded here.
848 In DWP version 2 there is at most one copy of all these sections, each
849 section being (effectively) comprised of the concatenation of all of the
850 individual sections that exist in the version 1 format.
851 To keep the code simple we treat each of these concatenated pieces as a
852 section itself (a virtual section?). */
853 struct dwarf2_section_info abbrev
;
854 struct dwarf2_section_info info
;
855 struct dwarf2_section_info line
;
856 struct dwarf2_section_info loc
;
857 struct dwarf2_section_info macinfo
;
858 struct dwarf2_section_info macro
;
859 struct dwarf2_section_info str_offsets
;
860 struct dwarf2_section_info types
;
863 /* These sections are what may appear in a virtual DWO file in DWP version 1.
864 A virtual DWO file is a DWO file as it appears in a DWP file. */
866 struct virtual_v1_dwo_sections
868 struct dwarf2_section_info abbrev
;
869 struct dwarf2_section_info line
;
870 struct dwarf2_section_info loc
;
871 struct dwarf2_section_info macinfo
;
872 struct dwarf2_section_info macro
;
873 struct dwarf2_section_info str_offsets
;
874 /* Each DWP hash table entry records one CU or one TU.
875 That is recorded here, and copied to dwo_unit.section. */
876 struct dwarf2_section_info info_or_types
;
879 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
880 In version 2, the sections of the DWO files are concatenated together
881 and stored in one section of that name. Thus each ELF section contains
882 several "virtual" sections. */
884 struct virtual_v2_dwo_sections
886 bfd_size_type abbrev_offset
;
887 bfd_size_type abbrev_size
;
889 bfd_size_type line_offset
;
890 bfd_size_type line_size
;
892 bfd_size_type loc_offset
;
893 bfd_size_type loc_size
;
895 bfd_size_type macinfo_offset
;
896 bfd_size_type macinfo_size
;
898 bfd_size_type macro_offset
;
899 bfd_size_type macro_size
;
901 bfd_size_type str_offsets_offset
;
902 bfd_size_type str_offsets_size
;
904 /* Each DWP hash table entry records one CU or one TU.
905 That is recorded here, and copied to dwo_unit.section. */
906 bfd_size_type info_or_types_offset
;
907 bfd_size_type info_or_types_size
;
910 /* Contents of DWP hash tables. */
912 struct dwp_hash_table
914 uint32_t version
, nr_columns
;
915 uint32_t nr_units
, nr_slots
;
916 const gdb_byte
*hash_table
, *unit_table
;
921 const gdb_byte
*indices
;
925 /* This is indexed by column number and gives the id of the section
927 #define MAX_NR_V2_DWO_SECTIONS \
928 (1 /* .debug_info or .debug_types */ \
929 + 1 /* .debug_abbrev */ \
930 + 1 /* .debug_line */ \
931 + 1 /* .debug_loc */ \
932 + 1 /* .debug_str_offsets */ \
933 + 1 /* .debug_macro or .debug_macinfo */)
934 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
935 const gdb_byte
*offsets
;
936 const gdb_byte
*sizes
;
941 /* Data for one DWP file. */
945 /* Name of the file. */
948 /* File format version. */
954 /* Section info for this file. */
955 struct dwp_sections sections
;
957 /* Table of CUs in the file. */
958 const struct dwp_hash_table
*cus
;
960 /* Table of TUs in the file. */
961 const struct dwp_hash_table
*tus
;
963 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
967 /* Table to map ELF section numbers to their sections.
968 This is only needed for the DWP V1 file format. */
969 unsigned int num_sections
;
970 asection
**elf_sections
;
973 /* This represents a '.dwz' file. */
977 /* A dwz file can only contain a few sections. */
978 struct dwarf2_section_info abbrev
;
979 struct dwarf2_section_info info
;
980 struct dwarf2_section_info str
;
981 struct dwarf2_section_info line
;
982 struct dwarf2_section_info macro
;
983 struct dwarf2_section_info gdb_index
;
989 /* Struct used to pass misc. parameters to read_die_and_children, et
990 al. which are used for both .debug_info and .debug_types dies.
991 All parameters here are unchanging for the life of the call. This
992 struct exists to abstract away the constant parameters of die reading. */
994 struct die_reader_specs
996 /* The bfd of die_section. */
999 /* The CU of the DIE we are parsing. */
1000 struct dwarf2_cu
*cu
;
1002 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1003 struct dwo_file
*dwo_file
;
1005 /* The section the die comes from.
1006 This is either .debug_info or .debug_types, or the .dwo variants. */
1007 struct dwarf2_section_info
*die_section
;
1009 /* die_section->buffer. */
1010 const gdb_byte
*buffer
;
1012 /* The end of the buffer. */
1013 const gdb_byte
*buffer_end
;
1015 /* The value of the DW_AT_comp_dir attribute. */
1016 const char *comp_dir
;
1019 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1020 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1021 const gdb_byte
*info_ptr
,
1022 struct die_info
*comp_unit_die
,
1026 /* The line number information for a compilation unit (found in the
1027 .debug_line section) begins with a "statement program header",
1028 which contains the following information. */
1031 unsigned int total_length
;
1032 unsigned short version
;
1033 unsigned int header_length
;
1034 unsigned char minimum_instruction_length
;
1035 unsigned char maximum_ops_per_instruction
;
1036 unsigned char default_is_stmt
;
1038 unsigned char line_range
;
1039 unsigned char opcode_base
;
1041 /* standard_opcode_lengths[i] is the number of operands for the
1042 standard opcode whose value is i. This means that
1043 standard_opcode_lengths[0] is unused, and the last meaningful
1044 element is standard_opcode_lengths[opcode_base - 1]. */
1045 unsigned char *standard_opcode_lengths
;
1047 /* The include_directories table. NOTE! These strings are not
1048 allocated with xmalloc; instead, they are pointers into
1049 debug_line_buffer. If you try to free them, `free' will get
1051 unsigned int num_include_dirs
, include_dirs_size
;
1052 const char **include_dirs
;
1054 /* The file_names table. NOTE! These strings are not allocated
1055 with xmalloc; instead, they are pointers into debug_line_buffer.
1056 Don't try to free them directly. */
1057 unsigned int num_file_names
, file_names_size
;
1061 unsigned int dir_index
;
1062 unsigned int mod_time
;
1063 unsigned int length
;
1064 int included_p
; /* Non-zero if referenced by the Line Number Program. */
1065 struct symtab
*symtab
; /* The associated symbol table, if any. */
1068 /* The start and end of the statement program following this
1069 header. These point into dwarf2_per_objfile->line_buffer. */
1070 const gdb_byte
*statement_program_start
, *statement_program_end
;
1073 /* When we construct a partial symbol table entry we only
1074 need this much information. */
1075 struct partial_die_info
1077 /* Offset of this DIE. */
1080 /* DWARF-2 tag for this DIE. */
1081 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1083 /* Assorted flags describing the data found in this DIE. */
1084 unsigned int has_children
: 1;
1085 unsigned int is_external
: 1;
1086 unsigned int is_declaration
: 1;
1087 unsigned int has_type
: 1;
1088 unsigned int has_specification
: 1;
1089 unsigned int has_pc_info
: 1;
1090 unsigned int may_be_inlined
: 1;
1092 /* Flag set if the SCOPE field of this structure has been
1094 unsigned int scope_set
: 1;
1096 /* Flag set if the DIE has a byte_size attribute. */
1097 unsigned int has_byte_size
: 1;
1099 /* Flag set if any of the DIE's children are template arguments. */
1100 unsigned int has_template_arguments
: 1;
1102 /* Flag set if fixup_partial_die has been called on this die. */
1103 unsigned int fixup_called
: 1;
1105 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1106 unsigned int is_dwz
: 1;
1108 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1109 unsigned int spec_is_dwz
: 1;
1111 /* The name of this DIE. Normally the value of DW_AT_name, but
1112 sometimes a default name for unnamed DIEs. */
1115 /* The linkage name, if present. */
1116 const char *linkage_name
;
1118 /* The scope to prepend to our children. This is generally
1119 allocated on the comp_unit_obstack, so will disappear
1120 when this compilation unit leaves the cache. */
1123 /* Some data associated with the partial DIE. The tag determines
1124 which field is live. */
1127 /* The location description associated with this DIE, if any. */
1128 struct dwarf_block
*locdesc
;
1129 /* The offset of an import, for DW_TAG_imported_unit. */
1133 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1137 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1138 DW_AT_sibling, if any. */
1139 /* NOTE: This member isn't strictly necessary, read_partial_die could
1140 return DW_AT_sibling values to its caller load_partial_dies. */
1141 const gdb_byte
*sibling
;
1143 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1144 DW_AT_specification (or DW_AT_abstract_origin or
1145 DW_AT_extension). */
1146 sect_offset spec_offset
;
1148 /* Pointers to this DIE's parent, first child, and next sibling,
1150 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
1153 /* This data structure holds the information of an abbrev. */
1156 unsigned int number
; /* number identifying abbrev */
1157 enum dwarf_tag tag
; /* dwarf tag */
1158 unsigned short has_children
; /* boolean */
1159 unsigned short num_attrs
; /* number of attributes */
1160 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1161 struct abbrev_info
*next
; /* next in chain */
1166 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1167 ENUM_BITFIELD(dwarf_form
) form
: 16;
1170 /* Size of abbrev_table.abbrev_hash_table. */
1171 #define ABBREV_HASH_SIZE 121
1173 /* Top level data structure to contain an abbreviation table. */
1177 /* Where the abbrev table came from.
1178 This is used as a sanity check when the table is used. */
1181 /* Storage for the abbrev table. */
1182 struct obstack abbrev_obstack
;
1184 /* Hash table of abbrevs.
1185 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1186 It could be statically allocated, but the previous code didn't so we
1188 struct abbrev_info
**abbrevs
;
1191 /* Attributes have a name and a value. */
1194 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1195 ENUM_BITFIELD(dwarf_form
) form
: 15;
1197 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1198 field should be in u.str (existing only for DW_STRING) but it is kept
1199 here for better struct attribute alignment. */
1200 unsigned int string_is_canonical
: 1;
1205 struct dwarf_block
*blk
;
1214 /* This data structure holds a complete die structure. */
1217 /* DWARF-2 tag for this DIE. */
1218 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1220 /* Number of attributes */
1221 unsigned char num_attrs
;
1223 /* True if we're presently building the full type name for the
1224 type derived from this DIE. */
1225 unsigned char building_fullname
: 1;
1228 unsigned int abbrev
;
1230 /* Offset in .debug_info or .debug_types section. */
1233 /* The dies in a compilation unit form an n-ary tree. PARENT
1234 points to this die's parent; CHILD points to the first child of
1235 this node; and all the children of a given node are chained
1236 together via their SIBLING fields. */
1237 struct die_info
*child
; /* Its first child, if any. */
1238 struct die_info
*sibling
; /* Its next sibling, if any. */
1239 struct die_info
*parent
; /* Its parent, if any. */
1241 /* An array of attributes, with NUM_ATTRS elements. There may be
1242 zero, but it's not common and zero-sized arrays are not
1243 sufficiently portable C. */
1244 struct attribute attrs
[1];
1247 /* Get at parts of an attribute structure. */
1249 #define DW_STRING(attr) ((attr)->u.str)
1250 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1251 #define DW_UNSND(attr) ((attr)->u.unsnd)
1252 #define DW_BLOCK(attr) ((attr)->u.blk)
1253 #define DW_SND(attr) ((attr)->u.snd)
1254 #define DW_ADDR(attr) ((attr)->u.addr)
1255 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1257 /* Blocks are a bunch of untyped bytes. */
1262 /* Valid only if SIZE is not zero. */
1263 const gdb_byte
*data
;
1266 #ifndef ATTR_ALLOC_CHUNK
1267 #define ATTR_ALLOC_CHUNK 4
1270 /* Allocate fields for structs, unions and enums in this size. */
1271 #ifndef DW_FIELD_ALLOC_CHUNK
1272 #define DW_FIELD_ALLOC_CHUNK 4
1275 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1276 but this would require a corresponding change in unpack_field_as_long
1278 static int bits_per_byte
= 8;
1280 /* The routines that read and process dies for a C struct or C++ class
1281 pass lists of data member fields and lists of member function fields
1282 in an instance of a field_info structure, as defined below. */
1285 /* List of data member and baseclasses fields. */
1288 struct nextfield
*next
;
1293 *fields
, *baseclasses
;
1295 /* Number of fields (including baseclasses). */
1298 /* Number of baseclasses. */
1301 /* Set if the accesibility of one of the fields is not public. */
1302 int non_public_fields
;
1304 /* Member function fields array, entries are allocated in the order they
1305 are encountered in the object file. */
1308 struct nextfnfield
*next
;
1309 struct fn_field fnfield
;
1313 /* Member function fieldlist array, contains name of possibly overloaded
1314 member function, number of overloaded member functions and a pointer
1315 to the head of the member function field chain. */
1320 struct nextfnfield
*head
;
1324 /* Number of entries in the fnfieldlists array. */
1327 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1328 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1329 struct typedef_field_list
1331 struct typedef_field field
;
1332 struct typedef_field_list
*next
;
1334 *typedef_field_list
;
1335 unsigned typedef_field_list_count
;
1338 /* One item on the queue of compilation units to read in full symbols
1340 struct dwarf2_queue_item
1342 struct dwarf2_per_cu_data
*per_cu
;
1343 enum language pretend_language
;
1344 struct dwarf2_queue_item
*next
;
1347 /* The current queue. */
1348 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1350 /* Loaded secondary compilation units are kept in memory until they
1351 have not been referenced for the processing of this many
1352 compilation units. Set this to zero to disable caching. Cache
1353 sizes of up to at least twenty will improve startup time for
1354 typical inter-CU-reference binaries, at an obvious memory cost. */
1355 static int dwarf2_max_cache_age
= 5;
1357 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
1358 struct cmd_list_element
*c
, const char *value
)
1360 fprintf_filtered (file
, _("The upper bound on the age of cached "
1361 "dwarf2 compilation units is %s.\n"),
1365 /* local function prototypes */
1367 static const char *get_section_name (const struct dwarf2_section_info
*);
1369 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1371 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1373 static void dwarf2_find_base_address (struct die_info
*die
,
1374 struct dwarf2_cu
*cu
);
1376 static struct partial_symtab
*create_partial_symtab
1377 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1379 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1381 static void scan_partial_symbols (struct partial_die_info
*,
1382 CORE_ADDR
*, CORE_ADDR
*,
1383 int, struct dwarf2_cu
*);
1385 static void add_partial_symbol (struct partial_die_info
*,
1386 struct dwarf2_cu
*);
1388 static void add_partial_namespace (struct partial_die_info
*pdi
,
1389 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1390 int need_pc
, struct dwarf2_cu
*cu
);
1392 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1393 CORE_ADDR
*highpc
, int need_pc
,
1394 struct dwarf2_cu
*cu
);
1396 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1397 struct dwarf2_cu
*cu
);
1399 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1400 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1401 int need_pc
, struct dwarf2_cu
*cu
);
1403 static void dwarf2_read_symtab (struct partial_symtab
*,
1406 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1408 static struct abbrev_info
*abbrev_table_lookup_abbrev
1409 (const struct abbrev_table
*, unsigned int);
1411 static struct abbrev_table
*abbrev_table_read_table
1412 (struct dwarf2_section_info
*, sect_offset
);
1414 static void abbrev_table_free (struct abbrev_table
*);
1416 static void abbrev_table_free_cleanup (void *);
1418 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1419 struct dwarf2_section_info
*);
1421 static void dwarf2_free_abbrev_table (void *);
1423 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1425 static struct partial_die_info
*load_partial_dies
1426 (const struct die_reader_specs
*, const gdb_byte
*, int);
1428 static const gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1429 struct partial_die_info
*,
1430 struct abbrev_info
*,
1434 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1435 struct dwarf2_cu
*);
1437 static void fixup_partial_die (struct partial_die_info
*,
1438 struct dwarf2_cu
*);
1440 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1441 struct attribute
*, struct attr_abbrev
*,
1444 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1446 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1448 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1450 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1452 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1454 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1457 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1459 static LONGEST read_checked_initial_length_and_offset
1460 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1461 unsigned int *, unsigned int *);
1463 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1464 const struct comp_unit_head
*,
1467 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1469 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1472 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1474 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1476 static const char *read_indirect_string (bfd
*, const gdb_byte
*,
1477 const struct comp_unit_head
*,
1480 static const char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1482 static ULONGEST
read_unsigned_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1484 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1486 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1490 static const char *read_str_index (const struct die_reader_specs
*reader
,
1491 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1493 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1495 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1496 struct dwarf2_cu
*);
1498 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1501 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1502 struct dwarf2_cu
*cu
);
1504 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1506 static struct die_info
*die_specification (struct die_info
*die
,
1507 struct dwarf2_cu
**);
1509 static void free_line_header (struct line_header
*lh
);
1511 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1512 struct dwarf2_cu
*cu
);
1514 static void dwarf_decode_lines (struct line_header
*, const char *,
1515 struct dwarf2_cu
*, struct partial_symtab
*,
1518 static void dwarf2_start_subfile (const char *, const char *, const char *);
1520 static void dwarf2_start_symtab (struct dwarf2_cu
*,
1521 const char *, const char *, CORE_ADDR
);
1523 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1524 struct dwarf2_cu
*);
1526 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1527 struct dwarf2_cu
*, struct symbol
*);
1529 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1530 struct dwarf2_cu
*);
1532 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1535 struct obstack
*obstack
,
1536 struct dwarf2_cu
*cu
, LONGEST
*value
,
1537 const gdb_byte
**bytes
,
1538 struct dwarf2_locexpr_baton
**baton
);
1540 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1542 static int need_gnat_info (struct dwarf2_cu
*);
1544 static struct type
*die_descriptive_type (struct die_info
*,
1545 struct dwarf2_cu
*);
1547 static void set_descriptive_type (struct type
*, struct die_info
*,
1548 struct dwarf2_cu
*);
1550 static struct type
*die_containing_type (struct die_info
*,
1551 struct dwarf2_cu
*);
1553 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1554 struct dwarf2_cu
*);
1556 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1558 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1560 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1562 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1563 const char *suffix
, int physname
,
1564 struct dwarf2_cu
*cu
);
1566 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1568 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1570 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1572 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1574 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1576 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1577 struct dwarf2_cu
*, struct partial_symtab
*);
1579 static int dwarf2_get_pc_bounds (struct die_info
*,
1580 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1581 struct partial_symtab
*);
1583 static void get_scope_pc_bounds (struct die_info
*,
1584 CORE_ADDR
*, CORE_ADDR
*,
1585 struct dwarf2_cu
*);
1587 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1588 CORE_ADDR
, struct dwarf2_cu
*);
1590 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1591 struct dwarf2_cu
*);
1593 static void dwarf2_attach_fields_to_type (struct field_info
*,
1594 struct type
*, struct dwarf2_cu
*);
1596 static void dwarf2_add_member_fn (struct field_info
*,
1597 struct die_info
*, struct type
*,
1598 struct dwarf2_cu
*);
1600 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1602 struct dwarf2_cu
*);
1604 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1606 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1608 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1610 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1612 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1614 static struct type
*read_module_type (struct die_info
*die
,
1615 struct dwarf2_cu
*cu
);
1617 static const char *namespace_name (struct die_info
*die
,
1618 int *is_anonymous
, struct dwarf2_cu
*);
1620 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1622 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1624 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1625 struct dwarf2_cu
*);
1627 static struct die_info
*read_die_and_siblings_1
1628 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1631 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1632 const gdb_byte
*info_ptr
,
1633 const gdb_byte
**new_info_ptr
,
1634 struct die_info
*parent
);
1636 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1637 struct die_info
**, const gdb_byte
*,
1640 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1641 struct die_info
**, const gdb_byte
*,
1644 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1646 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1649 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1651 static const char *dwarf2_full_name (const char *name
,
1652 struct die_info
*die
,
1653 struct dwarf2_cu
*cu
);
1655 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1656 struct dwarf2_cu
*cu
);
1658 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1659 struct dwarf2_cu
**);
1661 static const char *dwarf_tag_name (unsigned int);
1663 static const char *dwarf_attr_name (unsigned int);
1665 static const char *dwarf_form_name (unsigned int);
1667 static char *dwarf_bool_name (unsigned int);
1669 static const char *dwarf_type_encoding_name (unsigned int);
1671 static struct die_info
*sibling_die (struct die_info
*);
1673 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1675 static void dump_die_for_error (struct die_info
*);
1677 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1680 /*static*/ void dump_die (struct die_info
*, int max_level
);
1682 static void store_in_ref_table (struct die_info
*,
1683 struct dwarf2_cu
*);
1685 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1687 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1689 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1690 const struct attribute
*,
1691 struct dwarf2_cu
**);
1693 static struct die_info
*follow_die_ref (struct die_info
*,
1694 const struct attribute
*,
1695 struct dwarf2_cu
**);
1697 static struct die_info
*follow_die_sig (struct die_info
*,
1698 const struct attribute
*,
1699 struct dwarf2_cu
**);
1701 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1702 struct dwarf2_cu
*);
1704 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1705 const struct attribute
*,
1706 struct dwarf2_cu
*);
1708 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1710 static void read_signatured_type (struct signatured_type
*);
1712 static struct type_unit_group
*get_type_unit_group
1713 (struct dwarf2_cu
*, const struct attribute
*);
1715 static void build_type_unit_groups (die_reader_func_ftype
*, void *);
1717 /* memory allocation interface */
1719 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1721 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1723 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1726 static int attr_form_is_block (const struct attribute
*);
1728 static int attr_form_is_section_offset (const struct attribute
*);
1730 static int attr_form_is_constant (const struct attribute
*);
1732 static int attr_form_is_ref (const struct attribute
*);
1734 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1735 struct dwarf2_loclist_baton
*baton
,
1736 const struct attribute
*attr
);
1738 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1740 struct dwarf2_cu
*cu
,
1743 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1744 const gdb_byte
*info_ptr
,
1745 struct abbrev_info
*abbrev
);
1747 static void free_stack_comp_unit (void *);
1749 static hashval_t
partial_die_hash (const void *item
);
1751 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1753 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1754 (sect_offset offset
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1756 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1757 struct dwarf2_per_cu_data
*per_cu
);
1759 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1760 struct die_info
*comp_unit_die
,
1761 enum language pretend_language
);
1763 static void free_heap_comp_unit (void *);
1765 static void free_cached_comp_units (void *);
1767 static void age_cached_comp_units (void);
1769 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1771 static struct type
*set_die_type (struct die_info
*, struct type
*,
1772 struct dwarf2_cu
*);
1774 static void create_all_comp_units (struct objfile
*);
1776 static int create_all_type_units (struct objfile
*);
1778 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1781 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1784 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1787 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1788 struct dwarf2_per_cu_data
*);
1790 static void dwarf2_mark (struct dwarf2_cu
*);
1792 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1794 static struct type
*get_die_type_at_offset (sect_offset
,
1795 struct dwarf2_per_cu_data
*);
1797 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1799 static void dwarf2_release_queue (void *dummy
);
1801 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1802 enum language pretend_language
);
1804 static void process_queue (void);
1806 static void find_file_and_directory (struct die_info
*die
,
1807 struct dwarf2_cu
*cu
,
1808 const char **name
, const char **comp_dir
);
1810 static char *file_full_name (int file
, struct line_header
*lh
,
1811 const char *comp_dir
);
1813 static const gdb_byte
*read_and_check_comp_unit_head
1814 (struct comp_unit_head
*header
,
1815 struct dwarf2_section_info
*section
,
1816 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1817 int is_debug_types_section
);
1819 static void init_cutu_and_read_dies
1820 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1821 int use_existing_cu
, int keep
,
1822 die_reader_func_ftype
*die_reader_func
, void *data
);
1824 static void init_cutu_and_read_dies_simple
1825 (struct dwarf2_per_cu_data
*this_cu
,
1826 die_reader_func_ftype
*die_reader_func
, void *data
);
1828 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1830 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1832 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1833 (struct dwp_file
*dwp_file
, const char *comp_dir
,
1834 ULONGEST signature
, int is_debug_types
);
1836 static struct dwp_file
*get_dwp_file (void);
1838 static struct dwo_unit
*lookup_dwo_comp_unit
1839 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1841 static struct dwo_unit
*lookup_dwo_type_unit
1842 (struct signatured_type
*, const char *, const char *);
1844 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1846 static void free_dwo_file_cleanup (void *);
1848 static void process_cu_includes (void);
1850 static void check_producer (struct dwarf2_cu
*cu
);
1852 /* Various complaints about symbol reading that don't abort the process. */
1855 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1857 complaint (&symfile_complaints
,
1858 _("statement list doesn't fit in .debug_line section"));
1862 dwarf2_debug_line_missing_file_complaint (void)
1864 complaint (&symfile_complaints
,
1865 _(".debug_line section has line data without a file"));
1869 dwarf2_debug_line_missing_end_sequence_complaint (void)
1871 complaint (&symfile_complaints
,
1872 _(".debug_line section has line "
1873 "program sequence without an end"));
1877 dwarf2_complex_location_expr_complaint (void)
1879 complaint (&symfile_complaints
, _("location expression too complex"));
1883 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1886 complaint (&symfile_complaints
,
1887 _("const value length mismatch for '%s', got %d, expected %d"),
1892 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1894 complaint (&symfile_complaints
,
1895 _("debug info runs off end of %s section"
1897 get_section_name (section
),
1898 get_section_file_name (section
));
1902 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1904 complaint (&symfile_complaints
,
1905 _("macro debug info contains a "
1906 "malformed macro definition:\n`%s'"),
1911 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1913 complaint (&symfile_complaints
,
1914 _("invalid attribute class or form for '%s' in '%s'"),
1920 /* Convert VALUE between big- and little-endian. */
1922 byte_swap (offset_type value
)
1926 result
= (value
& 0xff) << 24;
1927 result
|= (value
& 0xff00) << 8;
1928 result
|= (value
& 0xff0000) >> 8;
1929 result
|= (value
& 0xff000000) >> 24;
1933 #define MAYBE_SWAP(V) byte_swap (V)
1936 #define MAYBE_SWAP(V) (V)
1937 #endif /* WORDS_BIGENDIAN */
1939 /* The suffix for an index file. */
1940 #define INDEX_SUFFIX ".gdb-index"
1942 /* Try to locate the sections we need for DWARF 2 debugging
1943 information and return true if we have enough to do something.
1944 NAMES points to the dwarf2 section names, or is NULL if the standard
1945 ELF names are used. */
1948 dwarf2_has_info (struct objfile
*objfile
,
1949 const struct dwarf2_debug_sections
*names
)
1951 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1952 if (!dwarf2_per_objfile
)
1954 /* Initialize per-objfile state. */
1955 struct dwarf2_per_objfile
*data
1956 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1958 memset (data
, 0, sizeof (*data
));
1959 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1960 dwarf2_per_objfile
= data
;
1962 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1964 dwarf2_per_objfile
->objfile
= objfile
;
1966 return (!dwarf2_per_objfile
->info
.is_virtual
1967 && dwarf2_per_objfile
->info
.s
.asection
!= NULL
1968 && !dwarf2_per_objfile
->abbrev
.is_virtual
1969 && dwarf2_per_objfile
->abbrev
.s
.asection
!= NULL
);
1972 /* Return the containing section of virtual section SECTION. */
1974 static struct dwarf2_section_info
*
1975 get_containing_section (const struct dwarf2_section_info
*section
)
1977 gdb_assert (section
->is_virtual
);
1978 return section
->s
.containing_section
;
1981 /* Return the bfd owner of SECTION. */
1984 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
1986 if (section
->is_virtual
)
1988 section
= get_containing_section (section
);
1989 gdb_assert (!section
->is_virtual
);
1991 return section
->s
.asection
->owner
;
1994 /* Return the bfd section of SECTION.
1995 Returns NULL if the section is not present. */
1998 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2000 if (section
->is_virtual
)
2002 section
= get_containing_section (section
);
2003 gdb_assert (!section
->is_virtual
);
2005 return section
->s
.asection
;
2008 /* Return the name of SECTION. */
2011 get_section_name (const struct dwarf2_section_info
*section
)
2013 asection
*sectp
= get_section_bfd_section (section
);
2015 gdb_assert (sectp
!= NULL
);
2016 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2019 /* Return the name of the file SECTION is in. */
2022 get_section_file_name (const struct dwarf2_section_info
*section
)
2024 bfd
*abfd
= get_section_bfd_owner (section
);
2026 return bfd_get_filename (abfd
);
2029 /* Return the id of SECTION.
2030 Returns 0 if SECTION doesn't exist. */
2033 get_section_id (const struct dwarf2_section_info
*section
)
2035 asection
*sectp
= get_section_bfd_section (section
);
2042 /* Return the flags of SECTION.
2043 SECTION (or containing section if this is a virtual section) must exist. */
2046 get_section_flags (const struct dwarf2_section_info
*section
)
2048 asection
*sectp
= get_section_bfd_section (section
);
2050 gdb_assert (sectp
!= NULL
);
2051 return bfd_get_section_flags (sectp
->owner
, sectp
);
2054 /* When loading sections, we look either for uncompressed section or for
2055 compressed section names. */
2058 section_is_p (const char *section_name
,
2059 const struct dwarf2_section_names
*names
)
2061 if (names
->normal
!= NULL
2062 && strcmp (section_name
, names
->normal
) == 0)
2064 if (names
->compressed
!= NULL
2065 && strcmp (section_name
, names
->compressed
) == 0)
2070 /* This function is mapped across the sections and remembers the
2071 offset and size of each of the debugging sections we are interested
2075 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
2077 const struct dwarf2_debug_sections
*names
;
2078 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2081 names
= &dwarf2_elf_names
;
2083 names
= (const struct dwarf2_debug_sections
*) vnames
;
2085 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2088 else if (section_is_p (sectp
->name
, &names
->info
))
2090 dwarf2_per_objfile
->info
.s
.asection
= sectp
;
2091 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
2093 else if (section_is_p (sectp
->name
, &names
->abbrev
))
2095 dwarf2_per_objfile
->abbrev
.s
.asection
= sectp
;
2096 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
2098 else if (section_is_p (sectp
->name
, &names
->line
))
2100 dwarf2_per_objfile
->line
.s
.asection
= sectp
;
2101 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
2103 else if (section_is_p (sectp
->name
, &names
->loc
))
2105 dwarf2_per_objfile
->loc
.s
.asection
= sectp
;
2106 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
2108 else if (section_is_p (sectp
->name
, &names
->macinfo
))
2110 dwarf2_per_objfile
->macinfo
.s
.asection
= sectp
;
2111 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
2113 else if (section_is_p (sectp
->name
, &names
->macro
))
2115 dwarf2_per_objfile
->macro
.s
.asection
= sectp
;
2116 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
2118 else if (section_is_p (sectp
->name
, &names
->str
))
2120 dwarf2_per_objfile
->str
.s
.asection
= sectp
;
2121 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
2123 else if (section_is_p (sectp
->name
, &names
->addr
))
2125 dwarf2_per_objfile
->addr
.s
.asection
= sectp
;
2126 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
2128 else if (section_is_p (sectp
->name
, &names
->frame
))
2130 dwarf2_per_objfile
->frame
.s
.asection
= sectp
;
2131 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
2133 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
2135 dwarf2_per_objfile
->eh_frame
.s
.asection
= sectp
;
2136 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
2138 else if (section_is_p (sectp
->name
, &names
->ranges
))
2140 dwarf2_per_objfile
->ranges
.s
.asection
= sectp
;
2141 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
2143 else if (section_is_p (sectp
->name
, &names
->types
))
2145 struct dwarf2_section_info type_section
;
2147 memset (&type_section
, 0, sizeof (type_section
));
2148 type_section
.s
.asection
= sectp
;
2149 type_section
.size
= bfd_get_section_size (sectp
);
2151 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
2154 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
2156 dwarf2_per_objfile
->gdb_index
.s
.asection
= sectp
;
2157 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
2160 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
2161 && bfd_section_vma (abfd
, sectp
) == 0)
2162 dwarf2_per_objfile
->has_section_at_zero
= 1;
2165 /* A helper function that decides whether a section is empty,
2169 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2171 if (section
->is_virtual
)
2172 return section
->size
== 0;
2173 return section
->s
.asection
== NULL
|| section
->size
== 0;
2176 /* Read the contents of the section INFO.
2177 OBJFILE is the main object file, but not necessarily the file where
2178 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2180 If the section is compressed, uncompress it before returning. */
2183 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2187 gdb_byte
*buf
, *retbuf
;
2191 info
->buffer
= NULL
;
2194 if (dwarf2_section_empty_p (info
))
2197 sectp
= get_section_bfd_section (info
);
2199 /* If this is a virtual section we need to read in the real one first. */
2200 if (info
->is_virtual
)
2202 struct dwarf2_section_info
*containing_section
=
2203 get_containing_section (info
);
2205 gdb_assert (sectp
!= NULL
);
2206 if ((sectp
->flags
& SEC_RELOC
) != 0)
2208 error (_("Dwarf Error: DWP format V2 with relocations is not"
2209 " supported in section %s [in module %s]"),
2210 get_section_name (info
), get_section_file_name (info
));
2212 dwarf2_read_section (objfile
, containing_section
);
2213 /* Other code should have already caught virtual sections that don't
2215 gdb_assert (info
->virtual_offset
+ info
->size
2216 <= containing_section
->size
);
2217 /* If the real section is empty or there was a problem reading the
2218 section we shouldn't get here. */
2219 gdb_assert (containing_section
->buffer
!= NULL
);
2220 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2224 /* If the section has relocations, we must read it ourselves.
2225 Otherwise we attach it to the BFD. */
2226 if ((sectp
->flags
& SEC_RELOC
) == 0)
2228 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2232 buf
= obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2235 /* When debugging .o files, we may need to apply relocations; see
2236 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2237 We never compress sections in .o files, so we only need to
2238 try this when the section is not compressed. */
2239 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2242 info
->buffer
= retbuf
;
2246 abfd
= get_section_bfd_owner (info
);
2247 gdb_assert (abfd
!= NULL
);
2249 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2250 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2252 error (_("Dwarf Error: Can't read DWARF data"
2253 " in section %s [in module %s]"),
2254 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2258 /* A helper function that returns the size of a section in a safe way.
2259 If you are positive that the section has been read before using the
2260 size, then it is safe to refer to the dwarf2_section_info object's
2261 "size" field directly. In other cases, you must call this
2262 function, because for compressed sections the size field is not set
2263 correctly until the section has been read. */
2265 static bfd_size_type
2266 dwarf2_section_size (struct objfile
*objfile
,
2267 struct dwarf2_section_info
*info
)
2270 dwarf2_read_section (objfile
, info
);
2274 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2278 dwarf2_get_section_info (struct objfile
*objfile
,
2279 enum dwarf2_section_enum sect
,
2280 asection
**sectp
, const gdb_byte
**bufp
,
2281 bfd_size_type
*sizep
)
2283 struct dwarf2_per_objfile
*data
2284 = objfile_data (objfile
, dwarf2_objfile_data_key
);
2285 struct dwarf2_section_info
*info
;
2287 /* We may see an objfile without any DWARF, in which case we just
2298 case DWARF2_DEBUG_FRAME
:
2299 info
= &data
->frame
;
2301 case DWARF2_EH_FRAME
:
2302 info
= &data
->eh_frame
;
2305 gdb_assert_not_reached ("unexpected section");
2308 dwarf2_read_section (objfile
, info
);
2310 *sectp
= get_section_bfd_section (info
);
2311 *bufp
= info
->buffer
;
2312 *sizep
= info
->size
;
2315 /* A helper function to find the sections for a .dwz file. */
2318 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2320 struct dwz_file
*dwz_file
= arg
;
2322 /* Note that we only support the standard ELF names, because .dwz
2323 is ELF-only (at the time of writing). */
2324 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2326 dwz_file
->abbrev
.s
.asection
= sectp
;
2327 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2329 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2331 dwz_file
->info
.s
.asection
= sectp
;
2332 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2334 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2336 dwz_file
->str
.s
.asection
= sectp
;
2337 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2339 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2341 dwz_file
->line
.s
.asection
= sectp
;
2342 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2344 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2346 dwz_file
->macro
.s
.asection
= sectp
;
2347 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2349 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2351 dwz_file
->gdb_index
.s
.asection
= sectp
;
2352 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2356 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2357 there is no .gnu_debugaltlink section in the file. Error if there
2358 is such a section but the file cannot be found. */
2360 static struct dwz_file
*
2361 dwarf2_get_dwz_file (void)
2365 struct cleanup
*cleanup
;
2366 const char *filename
;
2367 struct dwz_file
*result
;
2368 bfd_size_type buildid_len_arg
;
2372 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2373 return dwarf2_per_objfile
->dwz_file
;
2375 bfd_set_error (bfd_error_no_error
);
2376 data
= bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2377 &buildid_len_arg
, &buildid
);
2380 if (bfd_get_error () == bfd_error_no_error
)
2382 error (_("could not read '.gnu_debugaltlink' section: %s"),
2383 bfd_errmsg (bfd_get_error ()));
2385 cleanup
= make_cleanup (xfree
, data
);
2386 make_cleanup (xfree
, buildid
);
2388 buildid_len
= (size_t) buildid_len_arg
;
2390 filename
= (const char *) data
;
2391 if (!IS_ABSOLUTE_PATH (filename
))
2393 char *abs
= gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2396 make_cleanup (xfree
, abs
);
2397 abs
= ldirname (abs
);
2398 make_cleanup (xfree
, abs
);
2400 rel
= concat (abs
, SLASH_STRING
, filename
, (char *) NULL
);
2401 make_cleanup (xfree
, rel
);
2405 /* First try the file name given in the section. If that doesn't
2406 work, try to use the build-id instead. */
2407 dwz_bfd
= gdb_bfd_open (filename
, gnutarget
, -1);
2408 if (dwz_bfd
!= NULL
)
2410 if (!build_id_verify (dwz_bfd
, buildid_len
, buildid
))
2412 gdb_bfd_unref (dwz_bfd
);
2417 if (dwz_bfd
== NULL
)
2418 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2420 if (dwz_bfd
== NULL
)
2421 error (_("could not find '.gnu_debugaltlink' file for %s"),
2422 objfile_name (dwarf2_per_objfile
->objfile
));
2424 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2426 result
->dwz_bfd
= dwz_bfd
;
2428 bfd_map_over_sections (dwz_bfd
, locate_dwz_sections
, result
);
2430 do_cleanups (cleanup
);
2432 dwarf2_per_objfile
->dwz_file
= result
;
2436 /* DWARF quick_symbols_functions support. */
2438 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2439 unique line tables, so we maintain a separate table of all .debug_line
2440 derived entries to support the sharing.
2441 All the quick functions need is the list of file names. We discard the
2442 line_header when we're done and don't need to record it here. */
2443 struct quick_file_names
2445 /* The data used to construct the hash key. */
2446 struct stmt_list_hash hash
;
2448 /* The number of entries in file_names, real_names. */
2449 unsigned int num_file_names
;
2451 /* The file names from the line table, after being run through
2453 const char **file_names
;
2455 /* The file names from the line table after being run through
2456 gdb_realpath. These are computed lazily. */
2457 const char **real_names
;
2460 /* When using the index (and thus not using psymtabs), each CU has an
2461 object of this type. This is used to hold information needed by
2462 the various "quick" methods. */
2463 struct dwarf2_per_cu_quick_data
2465 /* The file table. This can be NULL if there was no file table
2466 or it's currently not read in.
2467 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2468 struct quick_file_names
*file_names
;
2470 /* The corresponding symbol table. This is NULL if symbols for this
2471 CU have not yet been read. */
2472 struct symtab
*symtab
;
2474 /* A temporary mark bit used when iterating over all CUs in
2475 expand_symtabs_matching. */
2476 unsigned int mark
: 1;
2478 /* True if we've tried to read the file table and found there isn't one.
2479 There will be no point in trying to read it again next time. */
2480 unsigned int no_file_data
: 1;
2483 /* Utility hash function for a stmt_list_hash. */
2486 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2490 if (stmt_list_hash
->dwo_unit
!= NULL
)
2491 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2492 v
+= stmt_list_hash
->line_offset
.sect_off
;
2496 /* Utility equality function for a stmt_list_hash. */
2499 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2500 const struct stmt_list_hash
*rhs
)
2502 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2504 if (lhs
->dwo_unit
!= NULL
2505 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2508 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2511 /* Hash function for a quick_file_names. */
2514 hash_file_name_entry (const void *e
)
2516 const struct quick_file_names
*file_data
= e
;
2518 return hash_stmt_list_entry (&file_data
->hash
);
2521 /* Equality function for a quick_file_names. */
2524 eq_file_name_entry (const void *a
, const void *b
)
2526 const struct quick_file_names
*ea
= a
;
2527 const struct quick_file_names
*eb
= b
;
2529 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2532 /* Delete function for a quick_file_names. */
2535 delete_file_name_entry (void *e
)
2537 struct quick_file_names
*file_data
= e
;
2540 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2542 xfree ((void*) file_data
->file_names
[i
]);
2543 if (file_data
->real_names
)
2544 xfree ((void*) file_data
->real_names
[i
]);
2547 /* The space for the struct itself lives on objfile_obstack,
2548 so we don't free it here. */
2551 /* Create a quick_file_names hash table. */
2554 create_quick_file_names_table (unsigned int nr_initial_entries
)
2556 return htab_create_alloc (nr_initial_entries
,
2557 hash_file_name_entry
, eq_file_name_entry
,
2558 delete_file_name_entry
, xcalloc
, xfree
);
2561 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2562 have to be created afterwards. You should call age_cached_comp_units after
2563 processing PER_CU->CU. dw2_setup must have been already called. */
2566 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2568 if (per_cu
->is_debug_types
)
2569 load_full_type_unit (per_cu
);
2571 load_full_comp_unit (per_cu
, language_minimal
);
2573 gdb_assert (per_cu
->cu
!= NULL
);
2575 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2578 /* Read in the symbols for PER_CU. */
2581 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2583 struct cleanup
*back_to
;
2585 /* Skip type_unit_groups, reading the type units they contain
2586 is handled elsewhere. */
2587 if (IS_TYPE_UNIT_GROUP (per_cu
))
2590 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2592 if (dwarf2_per_objfile
->using_index
2593 ? per_cu
->v
.quick
->symtab
== NULL
2594 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2596 queue_comp_unit (per_cu
, language_minimal
);
2599 /* If we just loaded a CU from a DWO, and we're working with an index
2600 that may badly handle TUs, load all the TUs in that DWO as well.
2601 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2602 if (!per_cu
->is_debug_types
2603 && per_cu
->cu
->dwo_unit
!= NULL
2604 && dwarf2_per_objfile
->index_table
!= NULL
2605 && dwarf2_per_objfile
->index_table
->version
<= 7
2606 /* DWP files aren't supported yet. */
2607 && get_dwp_file () == NULL
)
2608 queue_and_load_all_dwo_tus (per_cu
);
2613 /* Age the cache, releasing compilation units that have not
2614 been used recently. */
2615 age_cached_comp_units ();
2617 do_cleanups (back_to
);
2620 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2621 the objfile from which this CU came. Returns the resulting symbol
2624 static struct symtab
*
2625 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2627 gdb_assert (dwarf2_per_objfile
->using_index
);
2628 if (!per_cu
->v
.quick
->symtab
)
2630 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2631 increment_reading_symtab ();
2632 dw2_do_instantiate_symtab (per_cu
);
2633 process_cu_includes ();
2634 do_cleanups (back_to
);
2636 return per_cu
->v
.quick
->symtab
;
2639 /* Return the CU given its index.
2641 This is intended for loops like:
2643 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2644 + dwarf2_per_objfile->n_type_units); ++i)
2646 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2652 static struct dwarf2_per_cu_data
*
2653 dw2_get_cu (int index
)
2655 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2657 index
-= dwarf2_per_objfile
->n_comp_units
;
2658 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2659 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2662 return dwarf2_per_objfile
->all_comp_units
[index
];
2665 /* Return the primary CU given its index.
2666 The difference between this function and dw2_get_cu is in the handling
2667 of type units (TUs). Here we return the type_unit_group object.
2669 This is intended for loops like:
2671 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2672 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2674 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2680 static struct dwarf2_per_cu_data
*
2681 dw2_get_primary_cu (int index
)
2683 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2685 index
-= dwarf2_per_objfile
->n_comp_units
;
2686 gdb_assert (index
< dwarf2_per_objfile
->n_type_unit_groups
);
2687 return &dwarf2_per_objfile
->all_type_unit_groups
[index
]->per_cu
;
2690 return dwarf2_per_objfile
->all_comp_units
[index
];
2693 /* A helper for create_cus_from_index that handles a given list of
2697 create_cus_from_index_list (struct objfile
*objfile
,
2698 const gdb_byte
*cu_list
, offset_type n_elements
,
2699 struct dwarf2_section_info
*section
,
2705 for (i
= 0; i
< n_elements
; i
+= 2)
2707 struct dwarf2_per_cu_data
*the_cu
;
2708 ULONGEST offset
, length
;
2710 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2711 offset
= extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2712 length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2715 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2716 struct dwarf2_per_cu_data
);
2717 the_cu
->offset
.sect_off
= offset
;
2718 the_cu
->length
= length
;
2719 the_cu
->objfile
= objfile
;
2720 the_cu
->section
= section
;
2721 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2722 struct dwarf2_per_cu_quick_data
);
2723 the_cu
->is_dwz
= is_dwz
;
2724 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2728 /* Read the CU list from the mapped index, and use it to create all
2729 the CU objects for this objfile. */
2732 create_cus_from_index (struct objfile
*objfile
,
2733 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2734 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2736 struct dwz_file
*dwz
;
2738 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2739 dwarf2_per_objfile
->all_comp_units
2740 = obstack_alloc (&objfile
->objfile_obstack
,
2741 dwarf2_per_objfile
->n_comp_units
2742 * sizeof (struct dwarf2_per_cu_data
*));
2744 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2745 &dwarf2_per_objfile
->info
, 0, 0);
2747 if (dwz_elements
== 0)
2750 dwz
= dwarf2_get_dwz_file ();
2751 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
2752 cu_list_elements
/ 2);
2755 /* Create the signatured type hash table from the index. */
2758 create_signatured_type_table_from_index (struct objfile
*objfile
,
2759 struct dwarf2_section_info
*section
,
2760 const gdb_byte
*bytes
,
2761 offset_type elements
)
2764 htab_t sig_types_hash
;
2766 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2767 dwarf2_per_objfile
->all_type_units
2768 = xmalloc (dwarf2_per_objfile
->n_type_units
2769 * sizeof (struct signatured_type
*));
2771 sig_types_hash
= allocate_signatured_type_table (objfile
);
2773 for (i
= 0; i
< elements
; i
+= 3)
2775 struct signatured_type
*sig_type
;
2776 ULONGEST offset
, type_offset_in_tu
, signature
;
2779 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2780 offset
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2781 type_offset_in_tu
= extract_unsigned_integer (bytes
+ 8, 8,
2783 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2786 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2787 struct signatured_type
);
2788 sig_type
->signature
= signature
;
2789 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2790 sig_type
->per_cu
.is_debug_types
= 1;
2791 sig_type
->per_cu
.section
= section
;
2792 sig_type
->per_cu
.offset
.sect_off
= offset
;
2793 sig_type
->per_cu
.objfile
= objfile
;
2794 sig_type
->per_cu
.v
.quick
2795 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2796 struct dwarf2_per_cu_quick_data
);
2798 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2801 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2804 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2807 /* Read the address map data from the mapped index, and use it to
2808 populate the objfile's psymtabs_addrmap. */
2811 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2813 const gdb_byte
*iter
, *end
;
2814 struct obstack temp_obstack
;
2815 struct addrmap
*mutable_map
;
2816 struct cleanup
*cleanup
;
2819 obstack_init (&temp_obstack
);
2820 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2821 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2823 iter
= index
->address_table
;
2824 end
= iter
+ index
->address_table_size
;
2826 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2830 ULONGEST hi
, lo
, cu_index
;
2831 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2833 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2835 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2840 complaint (&symfile_complaints
,
2841 _(".gdb_index address table has invalid range (%s - %s)"),
2842 hex_string (lo
), hex_string (hi
));
2846 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
2848 complaint (&symfile_complaints
,
2849 _(".gdb_index address table has invalid CU number %u"),
2850 (unsigned) cu_index
);
2854 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2855 dw2_get_cu (cu_index
));
2858 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2859 &objfile
->objfile_obstack
);
2860 do_cleanups (cleanup
);
2863 /* The hash function for strings in the mapped index. This is the same as
2864 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2865 implementation. This is necessary because the hash function is tied to the
2866 format of the mapped index file. The hash values do not have to match with
2869 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2872 mapped_index_string_hash (int index_version
, const void *p
)
2874 const unsigned char *str
= (const unsigned char *) p
;
2878 while ((c
= *str
++) != 0)
2880 if (index_version
>= 5)
2882 r
= r
* 67 + c
- 113;
2888 /* Find a slot in the mapped index INDEX for the object named NAME.
2889 If NAME is found, set *VEC_OUT to point to the CU vector in the
2890 constant pool and return 1. If NAME cannot be found, return 0. */
2893 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2894 offset_type
**vec_out
)
2896 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2898 offset_type slot
, step
;
2899 int (*cmp
) (const char *, const char *);
2901 if (current_language
->la_language
== language_cplus
2902 || current_language
->la_language
== language_java
2903 || current_language
->la_language
== language_fortran
)
2905 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2907 const char *paren
= strchr (name
, '(');
2913 dup
= xmalloc (paren
- name
+ 1);
2914 memcpy (dup
, name
, paren
- name
);
2915 dup
[paren
- name
] = 0;
2917 make_cleanup (xfree
, dup
);
2922 /* Index version 4 did not support case insensitive searches. But the
2923 indices for case insensitive languages are built in lowercase, therefore
2924 simulate our NAME being searched is also lowercased. */
2925 hash
= mapped_index_string_hash ((index
->version
== 4
2926 && case_sensitivity
== case_sensitive_off
2927 ? 5 : index
->version
),
2930 slot
= hash
& (index
->symbol_table_slots
- 1);
2931 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2932 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2936 /* Convert a slot number to an offset into the table. */
2937 offset_type i
= 2 * slot
;
2939 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2941 do_cleanups (back_to
);
2945 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2946 if (!cmp (name
, str
))
2948 *vec_out
= (offset_type
*) (index
->constant_pool
2949 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2950 do_cleanups (back_to
);
2954 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2958 /* A helper function that reads the .gdb_index from SECTION and fills
2959 in MAP. FILENAME is the name of the file containing the section;
2960 it is used for error reporting. DEPRECATED_OK is nonzero if it is
2961 ok to use deprecated sections.
2963 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2964 out parameters that are filled in with information about the CU and
2965 TU lists in the section.
2967 Returns 1 if all went well, 0 otherwise. */
2970 read_index_from_section (struct objfile
*objfile
,
2971 const char *filename
,
2973 struct dwarf2_section_info
*section
,
2974 struct mapped_index
*map
,
2975 const gdb_byte
**cu_list
,
2976 offset_type
*cu_list_elements
,
2977 const gdb_byte
**types_list
,
2978 offset_type
*types_list_elements
)
2980 const gdb_byte
*addr
;
2981 offset_type version
;
2982 offset_type
*metadata
;
2985 if (dwarf2_section_empty_p (section
))
2988 /* Older elfutils strip versions could keep the section in the main
2989 executable while splitting it for the separate debug info file. */
2990 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
2993 dwarf2_read_section (objfile
, section
);
2995 addr
= section
->buffer
;
2996 /* Version check. */
2997 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2998 /* Versions earlier than 3 emitted every copy of a psymbol. This
2999 causes the index to behave very poorly for certain requests. Version 3
3000 contained incomplete addrmap. So, it seems better to just ignore such
3004 static int warning_printed
= 0;
3005 if (!warning_printed
)
3007 warning (_("Skipping obsolete .gdb_index section in %s."),
3009 warning_printed
= 1;
3013 /* Index version 4 uses a different hash function than index version
3016 Versions earlier than 6 did not emit psymbols for inlined
3017 functions. Using these files will cause GDB not to be able to
3018 set breakpoints on inlined functions by name, so we ignore these
3019 indices unless the user has done
3020 "set use-deprecated-index-sections on". */
3021 if (version
< 6 && !deprecated_ok
)
3023 static int warning_printed
= 0;
3024 if (!warning_printed
)
3027 Skipping deprecated .gdb_index section in %s.\n\
3028 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3029 to use the section anyway."),
3031 warning_printed
= 1;
3035 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3036 of the TU (for symbols coming from TUs). It's just a performance bug, and
3037 we can't distinguish gdb-generated indices from gold-generated ones, so
3038 nothing to do here. */
3040 /* Indexes with higher version than the one supported by GDB may be no
3041 longer backward compatible. */
3045 map
->version
= version
;
3046 map
->total_size
= section
->size
;
3048 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3051 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3052 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3056 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3057 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3058 - MAYBE_SWAP (metadata
[i
]))
3062 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3063 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
3064 - MAYBE_SWAP (metadata
[i
]));
3067 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
3068 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
3069 - MAYBE_SWAP (metadata
[i
]))
3070 / (2 * sizeof (offset_type
)));
3073 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3079 /* Read the index file. If everything went ok, initialize the "quick"
3080 elements of all the CUs and return 1. Otherwise, return 0. */
3083 dwarf2_read_index (struct objfile
*objfile
)
3085 struct mapped_index local_map
, *map
;
3086 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3087 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3088 struct dwz_file
*dwz
;
3090 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3091 use_deprecated_index_sections
,
3092 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3093 &cu_list
, &cu_list_elements
,
3094 &types_list
, &types_list_elements
))
3097 /* Don't use the index if it's empty. */
3098 if (local_map
.symbol_table_slots
== 0)
3101 /* If there is a .dwz file, read it so we can get its CU list as
3103 dwz
= dwarf2_get_dwz_file ();
3106 struct mapped_index dwz_map
;
3107 const gdb_byte
*dwz_types_ignore
;
3108 offset_type dwz_types_elements_ignore
;
3110 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3112 &dwz
->gdb_index
, &dwz_map
,
3113 &dwz_list
, &dwz_list_elements
,
3115 &dwz_types_elements_ignore
))
3117 warning (_("could not read '.gdb_index' section from %s; skipping"),
3118 bfd_get_filename (dwz
->dwz_bfd
));
3123 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3126 if (types_list_elements
)
3128 struct dwarf2_section_info
*section
;
3130 /* We can only handle a single .debug_types when we have an
3132 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3135 section
= VEC_index (dwarf2_section_info_def
,
3136 dwarf2_per_objfile
->types
, 0);
3138 create_signatured_type_table_from_index (objfile
, section
, types_list
,
3139 types_list_elements
);
3142 create_addrmap_from_index (objfile
, &local_map
);
3144 map
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct mapped_index
));
3147 dwarf2_per_objfile
->index_table
= map
;
3148 dwarf2_per_objfile
->using_index
= 1;
3149 dwarf2_per_objfile
->quick_file_names_table
=
3150 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3155 /* A helper for the "quick" functions which sets the global
3156 dwarf2_per_objfile according to OBJFILE. */
3159 dw2_setup (struct objfile
*objfile
)
3161 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
3162 gdb_assert (dwarf2_per_objfile
);
3165 /* die_reader_func for dw2_get_file_names. */
3168 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3169 const gdb_byte
*info_ptr
,
3170 struct die_info
*comp_unit_die
,
3174 struct dwarf2_cu
*cu
= reader
->cu
;
3175 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3176 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3177 struct dwarf2_per_cu_data
*lh_cu
;
3178 struct line_header
*lh
;
3179 struct attribute
*attr
;
3181 const char *name
, *comp_dir
;
3183 struct quick_file_names
*qfn
;
3184 unsigned int line_offset
;
3186 gdb_assert (! this_cu
->is_debug_types
);
3188 /* Our callers never want to match partial units -- instead they
3189 will match the enclosing full CU. */
3190 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3192 this_cu
->v
.quick
->no_file_data
= 1;
3201 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3204 struct quick_file_names find_entry
;
3206 line_offset
= DW_UNSND (attr
);
3208 /* We may have already read in this line header (TU line header sharing).
3209 If we have we're done. */
3210 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3211 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
3212 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3213 &find_entry
, INSERT
);
3216 lh_cu
->v
.quick
->file_names
= *slot
;
3220 lh
= dwarf_decode_line_header (line_offset
, cu
);
3224 lh_cu
->v
.quick
->no_file_data
= 1;
3228 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
3229 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3230 qfn
->hash
.line_offset
.sect_off
= line_offset
;
3231 gdb_assert (slot
!= NULL
);
3234 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
3236 qfn
->num_file_names
= lh
->num_file_names
;
3237 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
3238 lh
->num_file_names
* sizeof (char *));
3239 for (i
= 0; i
< lh
->num_file_names
; ++i
)
3240 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
3241 qfn
->real_names
= NULL
;
3243 free_line_header (lh
);
3245 lh_cu
->v
.quick
->file_names
= qfn
;
3248 /* A helper for the "quick" functions which attempts to read the line
3249 table for THIS_CU. */
3251 static struct quick_file_names
*
3252 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3254 /* This should never be called for TUs. */
3255 gdb_assert (! this_cu
->is_debug_types
);
3256 /* Nor type unit groups. */
3257 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3259 if (this_cu
->v
.quick
->file_names
!= NULL
)
3260 return this_cu
->v
.quick
->file_names
;
3261 /* If we know there is no line data, no point in looking again. */
3262 if (this_cu
->v
.quick
->no_file_data
)
3265 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3267 if (this_cu
->v
.quick
->no_file_data
)
3269 return this_cu
->v
.quick
->file_names
;
3272 /* A helper for the "quick" functions which computes and caches the
3273 real path for a given file name from the line table. */
3276 dw2_get_real_path (struct objfile
*objfile
,
3277 struct quick_file_names
*qfn
, int index
)
3279 if (qfn
->real_names
== NULL
)
3280 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3281 qfn
->num_file_names
, char *);
3283 if (qfn
->real_names
[index
] == NULL
)
3284 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
3286 return qfn
->real_names
[index
];
3289 static struct symtab
*
3290 dw2_find_last_source_symtab (struct objfile
*objfile
)
3294 dw2_setup (objfile
);
3295 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3296 return dw2_instantiate_symtab (dw2_get_cu (index
));
3299 /* Traversal function for dw2_forget_cached_source_info. */
3302 dw2_free_cached_file_names (void **slot
, void *info
)
3304 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3306 if (file_data
->real_names
)
3310 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3312 xfree ((void*) file_data
->real_names
[i
]);
3313 file_data
->real_names
[i
] = NULL
;
3321 dw2_forget_cached_source_info (struct objfile
*objfile
)
3323 dw2_setup (objfile
);
3325 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3326 dw2_free_cached_file_names
, NULL
);
3329 /* Helper function for dw2_map_symtabs_matching_filename that expands
3330 the symtabs and calls the iterator. */
3333 dw2_map_expand_apply (struct objfile
*objfile
,
3334 struct dwarf2_per_cu_data
*per_cu
,
3335 const char *name
, const char *real_path
,
3336 int (*callback
) (struct symtab
*, void *),
3339 struct symtab
*last_made
= objfile
->symtabs
;
3341 /* Don't visit already-expanded CUs. */
3342 if (per_cu
->v
.quick
->symtab
)
3345 /* This may expand more than one symtab, and we want to iterate over
3347 dw2_instantiate_symtab (per_cu
);
3349 return iterate_over_some_symtabs (name
, real_path
, callback
, data
,
3350 objfile
->symtabs
, last_made
);
3353 /* Implementation of the map_symtabs_matching_filename method. */
3356 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
3357 const char *real_path
,
3358 int (*callback
) (struct symtab
*, void *),
3362 const char *name_basename
= lbasename (name
);
3364 dw2_setup (objfile
);
3366 /* The rule is CUs specify all the files, including those used by
3367 any TU, so there's no need to scan TUs here. */
3369 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3372 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3373 struct quick_file_names
*file_data
;
3375 /* We only need to look at symtabs not already expanded. */
3376 if (per_cu
->v
.quick
->symtab
)
3379 file_data
= dw2_get_file_names (per_cu
);
3380 if (file_data
== NULL
)
3383 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3385 const char *this_name
= file_data
->file_names
[j
];
3386 const char *this_real_name
;
3388 if (compare_filenames_for_search (this_name
, name
))
3390 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3396 /* Before we invoke realpath, which can get expensive when many
3397 files are involved, do a quick comparison of the basenames. */
3398 if (! basenames_may_differ
3399 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3402 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3403 if (compare_filenames_for_search (this_real_name
, name
))
3405 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3411 if (real_path
!= NULL
)
3413 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3414 gdb_assert (IS_ABSOLUTE_PATH (name
));
3415 if (this_real_name
!= NULL
3416 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3418 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3430 /* Struct used to manage iterating over all CUs looking for a symbol. */
3432 struct dw2_symtab_iterator
3434 /* The internalized form of .gdb_index. */
3435 struct mapped_index
*index
;
3436 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3437 int want_specific_block
;
3438 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3439 Unused if !WANT_SPECIFIC_BLOCK. */
3441 /* The kind of symbol we're looking for. */
3443 /* The list of CUs from the index entry of the symbol,
3444 or NULL if not found. */
3446 /* The next element in VEC to look at. */
3448 /* The number of elements in VEC, or zero if there is no match. */
3452 /* Initialize the index symtab iterator ITER.
3453 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3454 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3457 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3458 struct mapped_index
*index
,
3459 int want_specific_block
,
3464 iter
->index
= index
;
3465 iter
->want_specific_block
= want_specific_block
;
3466 iter
->block_index
= block_index
;
3467 iter
->domain
= domain
;
3470 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3471 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3479 /* Return the next matching CU or NULL if there are no more. */
3481 static struct dwarf2_per_cu_data
*
3482 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3484 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3486 offset_type cu_index_and_attrs
=
3487 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3488 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3489 struct dwarf2_per_cu_data
*per_cu
;
3490 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3491 /* This value is only valid for index versions >= 7. */
3492 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3493 gdb_index_symbol_kind symbol_kind
=
3494 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3495 /* Only check the symbol attributes if they're present.
3496 Indices prior to version 7 don't record them,
3497 and indices >= 7 may elide them for certain symbols
3498 (gold does this). */
3500 (iter
->index
->version
>= 7
3501 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3503 /* Don't crash on bad data. */
3504 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3505 + dwarf2_per_objfile
->n_type_units
))
3507 complaint (&symfile_complaints
,
3508 _(".gdb_index entry has bad CU index"
3510 objfile_name (dwarf2_per_objfile
->objfile
));
3514 per_cu
= dw2_get_cu (cu_index
);
3516 /* Skip if already read in. */
3517 if (per_cu
->v
.quick
->symtab
)
3521 && iter
->want_specific_block
3522 && want_static
!= is_static
)
3525 /* Only check the symbol's kind if it has one. */
3528 switch (iter
->domain
)
3531 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3532 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3533 /* Some types are also in VAR_DOMAIN. */
3534 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3538 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3542 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3557 static struct symtab
*
3558 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3559 const char *name
, domain_enum domain
)
3561 struct symtab
*stab_best
= NULL
;
3562 struct mapped_index
*index
;
3564 dw2_setup (objfile
);
3566 index
= dwarf2_per_objfile
->index_table
;
3568 /* index is NULL if OBJF_READNOW. */
3571 struct dw2_symtab_iterator iter
;
3572 struct dwarf2_per_cu_data
*per_cu
;
3574 dw2_symtab_iter_init (&iter
, index
, 1, block_index
, domain
, name
);
3576 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3578 struct symbol
*sym
= NULL
;
3579 struct symtab
*stab
= dw2_instantiate_symtab (per_cu
);
3581 /* Some caution must be observed with overloaded functions
3582 and methods, since the index will not contain any overload
3583 information (but NAME might contain it). */
3586 struct blockvector
*bv
= BLOCKVECTOR (stab
);
3587 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3589 sym
= lookup_block_symbol (block
, name
, domain
);
3592 if (sym
&& strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
3594 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
3600 /* Keep looking through other CUs. */
3608 dw2_print_stats (struct objfile
*objfile
)
3610 int i
, total
, count
;
3612 dw2_setup (objfile
);
3613 total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
3615 for (i
= 0; i
< total
; ++i
)
3617 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3619 if (!per_cu
->v
.quick
->symtab
)
3622 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3623 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3626 /* This dumps minimal information about the index.
3627 It is called via "mt print objfiles".
3628 One use is to verify .gdb_index has been loaded by the
3629 gdb.dwarf2/gdb-index.exp testcase. */
3632 dw2_dump (struct objfile
*objfile
)
3634 dw2_setup (objfile
);
3635 gdb_assert (dwarf2_per_objfile
->using_index
);
3636 printf_filtered (".gdb_index:");
3637 if (dwarf2_per_objfile
->index_table
!= NULL
)
3639 printf_filtered (" version %d\n",
3640 dwarf2_per_objfile
->index_table
->version
);
3643 printf_filtered (" faked for \"readnow\"\n");
3644 printf_filtered ("\n");
3648 dw2_relocate (struct objfile
*objfile
,
3649 const struct section_offsets
*new_offsets
,
3650 const struct section_offsets
*delta
)
3652 /* There's nothing to relocate here. */
3656 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3657 const char *func_name
)
3659 struct mapped_index
*index
;
3661 dw2_setup (objfile
);
3663 index
= dwarf2_per_objfile
->index_table
;
3665 /* index is NULL if OBJF_READNOW. */
3668 struct dw2_symtab_iterator iter
;
3669 struct dwarf2_per_cu_data
*per_cu
;
3671 /* Note: It doesn't matter what we pass for block_index here. */
3672 dw2_symtab_iter_init (&iter
, index
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
3675 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3676 dw2_instantiate_symtab (per_cu
);
3681 dw2_expand_all_symtabs (struct objfile
*objfile
)
3685 dw2_setup (objfile
);
3687 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3688 + dwarf2_per_objfile
->n_type_units
); ++i
)
3690 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3692 dw2_instantiate_symtab (per_cu
);
3697 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3698 const char *fullname
)
3702 dw2_setup (objfile
);
3704 /* We don't need to consider type units here.
3705 This is only called for examining code, e.g. expand_line_sal.
3706 There can be an order of magnitude (or more) more type units
3707 than comp units, and we avoid them if we can. */
3709 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3712 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3713 struct quick_file_names
*file_data
;
3715 /* We only need to look at symtabs not already expanded. */
3716 if (per_cu
->v
.quick
->symtab
)
3719 file_data
= dw2_get_file_names (per_cu
);
3720 if (file_data
== NULL
)
3723 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3725 const char *this_fullname
= file_data
->file_names
[j
];
3727 if (filename_cmp (this_fullname
, fullname
) == 0)
3729 dw2_instantiate_symtab (per_cu
);
3737 dw2_map_matching_symbols (struct objfile
*objfile
,
3738 const char * name
, domain_enum
namespace,
3740 int (*callback
) (struct block
*,
3741 struct symbol
*, void *),
3742 void *data
, symbol_compare_ftype
*match
,
3743 symbol_compare_ftype
*ordered_compare
)
3745 /* Currently unimplemented; used for Ada. The function can be called if the
3746 current language is Ada for a non-Ada objfile using GNU index. As Ada
3747 does not look for non-Ada symbols this function should just return. */
3751 dw2_expand_symtabs_matching
3752 (struct objfile
*objfile
,
3753 int (*file_matcher
) (const char *, void *, int basenames
),
3754 int (*name_matcher
) (const char *, void *),
3755 enum search_domain kind
,
3760 struct mapped_index
*index
;
3762 dw2_setup (objfile
);
3764 /* index_table is NULL if OBJF_READNOW. */
3765 if (!dwarf2_per_objfile
->index_table
)
3767 index
= dwarf2_per_objfile
->index_table
;
3769 if (file_matcher
!= NULL
)
3771 struct cleanup
*cleanup
;
3772 htab_t visited_found
, visited_not_found
;
3774 visited_found
= htab_create_alloc (10,
3775 htab_hash_pointer
, htab_eq_pointer
,
3776 NULL
, xcalloc
, xfree
);
3777 cleanup
= make_cleanup_htab_delete (visited_found
);
3778 visited_not_found
= htab_create_alloc (10,
3779 htab_hash_pointer
, htab_eq_pointer
,
3780 NULL
, xcalloc
, xfree
);
3781 make_cleanup_htab_delete (visited_not_found
);
3783 /* The rule is CUs specify all the files, including those used by
3784 any TU, so there's no need to scan TUs here. */
3786 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3789 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3790 struct quick_file_names
*file_data
;
3793 per_cu
->v
.quick
->mark
= 0;
3795 /* We only need to look at symtabs not already expanded. */
3796 if (per_cu
->v
.quick
->symtab
)
3799 file_data
= dw2_get_file_names (per_cu
);
3800 if (file_data
== NULL
)
3803 if (htab_find (visited_not_found
, file_data
) != NULL
)
3805 else if (htab_find (visited_found
, file_data
) != NULL
)
3807 per_cu
->v
.quick
->mark
= 1;
3811 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3813 const char *this_real_name
;
3815 if (file_matcher (file_data
->file_names
[j
], data
, 0))
3817 per_cu
->v
.quick
->mark
= 1;
3821 /* Before we invoke realpath, which can get expensive when many
3822 files are involved, do a quick comparison of the basenames. */
3823 if (!basenames_may_differ
3824 && !file_matcher (lbasename (file_data
->file_names
[j
]),
3828 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3829 if (file_matcher (this_real_name
, data
, 0))
3831 per_cu
->v
.quick
->mark
= 1;
3836 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3838 : visited_not_found
,
3843 do_cleanups (cleanup
);
3846 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3848 offset_type idx
= 2 * iter
;
3850 offset_type
*vec
, vec_len
, vec_idx
;
3852 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3855 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3857 if (! (*name_matcher
) (name
, data
))
3860 /* The name was matched, now expand corresponding CUs that were
3862 vec
= (offset_type
*) (index
->constant_pool
3863 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3864 vec_len
= MAYBE_SWAP (vec
[0]);
3865 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3867 struct dwarf2_per_cu_data
*per_cu
;
3868 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3869 gdb_index_symbol_kind symbol_kind
=
3870 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3871 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3872 /* Only check the symbol attributes if they're present.
3873 Indices prior to version 7 don't record them,
3874 and indices >= 7 may elide them for certain symbols
3875 (gold does this). */
3877 (index
->version
>= 7
3878 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3880 /* Only check the symbol's kind if it has one. */
3885 case VARIABLES_DOMAIN
:
3886 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3889 case FUNCTIONS_DOMAIN
:
3890 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3894 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3902 /* Don't crash on bad data. */
3903 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3904 + dwarf2_per_objfile
->n_type_units
))
3906 complaint (&symfile_complaints
,
3907 _(".gdb_index entry has bad CU index"
3908 " [in module %s]"), objfile_name (objfile
));
3912 per_cu
= dw2_get_cu (cu_index
);
3913 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3914 dw2_instantiate_symtab (per_cu
);
3919 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3922 static struct symtab
*
3923 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3927 if (BLOCKVECTOR (symtab
) != NULL
3928 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3931 if (symtab
->includes
== NULL
)
3934 for (i
= 0; symtab
->includes
[i
]; ++i
)
3936 struct symtab
*s
= symtab
->includes
[i
];
3938 s
= recursively_find_pc_sect_symtab (s
, pc
);
3946 static struct symtab
*
3947 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3948 struct minimal_symbol
*msymbol
,
3950 struct obj_section
*section
,
3953 struct dwarf2_per_cu_data
*data
;
3954 struct symtab
*result
;
3956 dw2_setup (objfile
);
3958 if (!objfile
->psymtabs_addrmap
)
3961 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3965 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3966 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3967 paddress (get_objfile_arch (objfile
), pc
));
3969 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3970 gdb_assert (result
!= NULL
);
3975 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3976 void *data
, int need_fullname
)
3979 struct cleanup
*cleanup
;
3980 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3981 NULL
, xcalloc
, xfree
);
3983 cleanup
= make_cleanup_htab_delete (visited
);
3984 dw2_setup (objfile
);
3986 /* The rule is CUs specify all the files, including those used by
3987 any TU, so there's no need to scan TUs here.
3988 We can ignore file names coming from already-expanded CUs. */
3990 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3992 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3994 if (per_cu
->v
.quick
->symtab
)
3996 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3999 *slot
= per_cu
->v
.quick
->file_names
;
4003 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4006 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
4007 struct quick_file_names
*file_data
;
4010 /* We only need to look at symtabs not already expanded. */
4011 if (per_cu
->v
.quick
->symtab
)
4014 file_data
= dw2_get_file_names (per_cu
);
4015 if (file_data
== NULL
)
4018 slot
= htab_find_slot (visited
, file_data
, INSERT
);
4021 /* Already visited. */
4026 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4028 const char *this_real_name
;
4031 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4033 this_real_name
= NULL
;
4034 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
4038 do_cleanups (cleanup
);
4042 dw2_has_symbols (struct objfile
*objfile
)
4047 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4050 dw2_find_last_source_symtab
,
4051 dw2_forget_cached_source_info
,
4052 dw2_map_symtabs_matching_filename
,
4057 dw2_expand_symtabs_for_function
,
4058 dw2_expand_all_symtabs
,
4059 dw2_expand_symtabs_with_fullname
,
4060 dw2_map_matching_symbols
,
4061 dw2_expand_symtabs_matching
,
4062 dw2_find_pc_sect_symtab
,
4063 dw2_map_symbol_filenames
4066 /* Initialize for reading DWARF for this objfile. Return 0 if this
4067 file will use psymtabs, or 1 if using the GNU index. */
4070 dwarf2_initialize_objfile (struct objfile
*objfile
)
4072 /* If we're about to read full symbols, don't bother with the
4073 indices. In this case we also don't care if some other debug
4074 format is making psymtabs, because they are all about to be
4076 if ((objfile
->flags
& OBJF_READNOW
))
4080 dwarf2_per_objfile
->using_index
= 1;
4081 create_all_comp_units (objfile
);
4082 create_all_type_units (objfile
);
4083 dwarf2_per_objfile
->quick_file_names_table
=
4084 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
4086 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
4087 + dwarf2_per_objfile
->n_type_units
); ++i
)
4089 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4091 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4092 struct dwarf2_per_cu_quick_data
);
4095 /* Return 1 so that gdb sees the "quick" functions. However,
4096 these functions will be no-ops because we will have expanded
4101 if (dwarf2_read_index (objfile
))
4109 /* Build a partial symbol table. */
4112 dwarf2_build_psymtabs (struct objfile
*objfile
)
4114 volatile struct gdb_exception except
;
4116 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
4118 init_psymbol_list (objfile
, 1024);
4121 TRY_CATCH (except
, RETURN_MASK_ERROR
)
4123 /* This isn't really ideal: all the data we allocate on the
4124 objfile's obstack is still uselessly kept around. However,
4125 freeing it seems unsafe. */
4126 struct cleanup
*cleanups
= make_cleanup_discard_psymtabs (objfile
);
4128 dwarf2_build_psymtabs_hard (objfile
);
4129 discard_cleanups (cleanups
);
4131 if (except
.reason
< 0)
4132 exception_print (gdb_stderr
, except
);
4135 /* Return the total length of the CU described by HEADER. */
4138 get_cu_length (const struct comp_unit_head
*header
)
4140 return header
->initial_length_size
+ header
->length
;
4143 /* Return TRUE if OFFSET is within CU_HEADER. */
4146 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
4148 sect_offset bottom
= { cu_header
->offset
.sect_off
};
4149 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
4151 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
4154 /* Find the base address of the compilation unit for range lists and
4155 location lists. It will normally be specified by DW_AT_low_pc.
4156 In DWARF-3 draft 4, the base address could be overridden by
4157 DW_AT_entry_pc. It's been removed, but GCC still uses this for
4158 compilation units with discontinuous ranges. */
4161 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
4163 struct attribute
*attr
;
4166 cu
->base_address
= 0;
4168 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
4171 cu
->base_address
= DW_ADDR (attr
);
4176 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4179 cu
->base_address
= DW_ADDR (attr
);
4185 /* Read in the comp unit header information from the debug_info at info_ptr.
4186 NOTE: This leaves members offset, first_die_offset to be filled in
4189 static const gdb_byte
*
4190 read_comp_unit_head (struct comp_unit_head
*cu_header
,
4191 const gdb_byte
*info_ptr
, bfd
*abfd
)
4194 unsigned int bytes_read
;
4196 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
4197 cu_header
->initial_length_size
= bytes_read
;
4198 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
4199 info_ptr
+= bytes_read
;
4200 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
4202 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
4204 info_ptr
+= bytes_read
;
4205 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
4207 signed_addr
= bfd_get_sign_extend_vma (abfd
);
4208 if (signed_addr
< 0)
4209 internal_error (__FILE__
, __LINE__
,
4210 _("read_comp_unit_head: dwarf from non elf file"));
4211 cu_header
->signed_addr_p
= signed_addr
;
4216 /* Helper function that returns the proper abbrev section for
4219 static struct dwarf2_section_info
*
4220 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
4222 struct dwarf2_section_info
*abbrev
;
4224 if (this_cu
->is_dwz
)
4225 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
4227 abbrev
= &dwarf2_per_objfile
->abbrev
;
4232 /* Subroutine of read_and_check_comp_unit_head and
4233 read_and_check_type_unit_head to simplify them.
4234 Perform various error checking on the header. */
4237 error_check_comp_unit_head (struct comp_unit_head
*header
,
4238 struct dwarf2_section_info
*section
,
4239 struct dwarf2_section_info
*abbrev_section
)
4241 bfd
*abfd
= get_section_bfd_owner (section
);
4242 const char *filename
= get_section_file_name (section
);
4244 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
4245 error (_("Dwarf Error: wrong version in compilation unit header "
4246 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
4249 if (header
->abbrev_offset
.sect_off
4250 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
4251 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
4252 "(offset 0x%lx + 6) [in module %s]"),
4253 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
4256 /* Cast to unsigned long to use 64-bit arithmetic when possible to
4257 avoid potential 32-bit overflow. */
4258 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
4260 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
4261 "(offset 0x%lx + 0) [in module %s]"),
4262 (long) header
->length
, (long) header
->offset
.sect_off
,
4266 /* Read in a CU/TU header and perform some basic error checking.
4267 The contents of the header are stored in HEADER.
4268 The result is a pointer to the start of the first DIE. */
4270 static const gdb_byte
*
4271 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
4272 struct dwarf2_section_info
*section
,
4273 struct dwarf2_section_info
*abbrev_section
,
4274 const gdb_byte
*info_ptr
,
4275 int is_debug_types_section
)
4277 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
4278 bfd
*abfd
= get_section_bfd_owner (section
);
4280 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4282 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
4284 /* If we're reading a type unit, skip over the signature and
4285 type_offset fields. */
4286 if (is_debug_types_section
)
4287 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
4289 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4291 error_check_comp_unit_head (header
, section
, abbrev_section
);
4296 /* Read in the types comp unit header information from .debug_types entry at
4297 types_ptr. The result is a pointer to one past the end of the header. */
4299 static const gdb_byte
*
4300 read_and_check_type_unit_head (struct comp_unit_head
*header
,
4301 struct dwarf2_section_info
*section
,
4302 struct dwarf2_section_info
*abbrev_section
,
4303 const gdb_byte
*info_ptr
,
4304 ULONGEST
*signature
,
4305 cu_offset
*type_offset_in_tu
)
4307 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
4308 bfd
*abfd
= get_section_bfd_owner (section
);
4310 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4312 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
4314 /* If we're reading a type unit, skip over the signature and
4315 type_offset fields. */
4316 if (signature
!= NULL
)
4317 *signature
= read_8_bytes (abfd
, info_ptr
);
4319 if (type_offset_in_tu
!= NULL
)
4320 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
4321 header
->offset_size
);
4322 info_ptr
+= header
->offset_size
;
4324 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4326 error_check_comp_unit_head (header
, section
, abbrev_section
);
4331 /* Fetch the abbreviation table offset from a comp or type unit header. */
4334 read_abbrev_offset (struct dwarf2_section_info
*section
,
4337 bfd
*abfd
= get_section_bfd_owner (section
);
4338 const gdb_byte
*info_ptr
;
4339 unsigned int length
, initial_length_size
, offset_size
;
4340 sect_offset abbrev_offset
;
4342 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
4343 info_ptr
= section
->buffer
+ offset
.sect_off
;
4344 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
4345 offset_size
= initial_length_size
== 4 ? 4 : 8;
4346 info_ptr
+= initial_length_size
+ 2 /*version*/;
4347 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
4348 return abbrev_offset
;
4351 /* Allocate a new partial symtab for file named NAME and mark this new
4352 partial symtab as being an include of PST. */
4355 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
4356 struct objfile
*objfile
)
4358 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
4360 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
4362 /* It shares objfile->objfile_obstack. */
4363 subpst
->dirname
= pst
->dirname
;
4366 subpst
->section_offsets
= pst
->section_offsets
;
4367 subpst
->textlow
= 0;
4368 subpst
->texthigh
= 0;
4370 subpst
->dependencies
= (struct partial_symtab
**)
4371 obstack_alloc (&objfile
->objfile_obstack
,
4372 sizeof (struct partial_symtab
*));
4373 subpst
->dependencies
[0] = pst
;
4374 subpst
->number_of_dependencies
= 1;
4376 subpst
->globals_offset
= 0;
4377 subpst
->n_global_syms
= 0;
4378 subpst
->statics_offset
= 0;
4379 subpst
->n_static_syms
= 0;
4380 subpst
->symtab
= NULL
;
4381 subpst
->read_symtab
= pst
->read_symtab
;
4384 /* No private part is necessary for include psymtabs. This property
4385 can be used to differentiate between such include psymtabs and
4386 the regular ones. */
4387 subpst
->read_symtab_private
= NULL
;
4390 /* Read the Line Number Program data and extract the list of files
4391 included by the source file represented by PST. Build an include
4392 partial symtab for each of these included files. */
4395 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4396 struct die_info
*die
,
4397 struct partial_symtab
*pst
)
4399 struct line_header
*lh
= NULL
;
4400 struct attribute
*attr
;
4402 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4404 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
4406 return; /* No linetable, so no includes. */
4408 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4409 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
4411 free_line_header (lh
);
4415 hash_signatured_type (const void *item
)
4417 const struct signatured_type
*sig_type
= item
;
4419 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4420 return sig_type
->signature
;
4424 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4426 const struct signatured_type
*lhs
= item_lhs
;
4427 const struct signatured_type
*rhs
= item_rhs
;
4429 return lhs
->signature
== rhs
->signature
;
4432 /* Allocate a hash table for signatured types. */
4435 allocate_signatured_type_table (struct objfile
*objfile
)
4437 return htab_create_alloc_ex (41,
4438 hash_signatured_type
,
4441 &objfile
->objfile_obstack
,
4442 hashtab_obstack_allocate
,
4443 dummy_obstack_deallocate
);
4446 /* A helper function to add a signatured type CU to a table. */
4449 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4451 struct signatured_type
*sigt
= *slot
;
4452 struct signatured_type
***datap
= datum
;
4460 /* Create the hash table of all entries in the .debug_types
4461 (or .debug_types.dwo) section(s).
4462 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
4463 otherwise it is NULL.
4465 The result is a pointer to the hash table or NULL if there are no types.
4467 Note: This function processes DWO files only, not DWP files. */
4470 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4471 VEC (dwarf2_section_info_def
) *types
)
4473 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4474 htab_t types_htab
= NULL
;
4476 struct dwarf2_section_info
*section
;
4477 struct dwarf2_section_info
*abbrev_section
;
4479 if (VEC_empty (dwarf2_section_info_def
, types
))
4482 abbrev_section
= (dwo_file
!= NULL
4483 ? &dwo_file
->sections
.abbrev
4484 : &dwarf2_per_objfile
->abbrev
);
4486 if (dwarf2_read_debug
)
4487 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
4488 dwo_file
? ".dwo" : "",
4489 get_section_file_name (abbrev_section
));
4492 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4496 const gdb_byte
*info_ptr
, *end_ptr
;
4498 dwarf2_read_section (objfile
, section
);
4499 info_ptr
= section
->buffer
;
4501 if (info_ptr
== NULL
)
4504 /* We can't set abfd until now because the section may be empty or
4505 not present, in which case the bfd is unknown. */
4506 abfd
= get_section_bfd_owner (section
);
4508 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4509 because we don't need to read any dies: the signature is in the
4512 end_ptr
= info_ptr
+ section
->size
;
4513 while (info_ptr
< end_ptr
)
4516 cu_offset type_offset_in_tu
;
4518 struct signatured_type
*sig_type
;
4519 struct dwo_unit
*dwo_tu
;
4521 const gdb_byte
*ptr
= info_ptr
;
4522 struct comp_unit_head header
;
4523 unsigned int length
;
4525 offset
.sect_off
= ptr
- section
->buffer
;
4527 /* We need to read the type's signature in order to build the hash
4528 table, but we don't need anything else just yet. */
4530 ptr
= read_and_check_type_unit_head (&header
, section
,
4531 abbrev_section
, ptr
,
4532 &signature
, &type_offset_in_tu
);
4534 length
= get_cu_length (&header
);
4536 /* Skip dummy type units. */
4537 if (ptr
>= info_ptr
+ length
4538 || peek_abbrev_code (abfd
, ptr
) == 0)
4544 if (types_htab
== NULL
)
4547 types_htab
= allocate_dwo_unit_table (objfile
);
4549 types_htab
= allocate_signatured_type_table (objfile
);
4555 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4557 dwo_tu
->dwo_file
= dwo_file
;
4558 dwo_tu
->signature
= signature
;
4559 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
4560 dwo_tu
->section
= section
;
4561 dwo_tu
->offset
= offset
;
4562 dwo_tu
->length
= length
;
4566 /* N.B.: type_offset is not usable if this type uses a DWO file.
4567 The real type_offset is in the DWO file. */
4569 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4570 struct signatured_type
);
4571 sig_type
->signature
= signature
;
4572 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
4573 sig_type
->per_cu
.objfile
= objfile
;
4574 sig_type
->per_cu
.is_debug_types
= 1;
4575 sig_type
->per_cu
.section
= section
;
4576 sig_type
->per_cu
.offset
= offset
;
4577 sig_type
->per_cu
.length
= length
;
4580 slot
= htab_find_slot (types_htab
,
4581 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4583 gdb_assert (slot
!= NULL
);
4586 sect_offset dup_offset
;
4590 const struct dwo_unit
*dup_tu
= *slot
;
4592 dup_offset
= dup_tu
->offset
;
4596 const struct signatured_type
*dup_tu
= *slot
;
4598 dup_offset
= dup_tu
->per_cu
.offset
;
4601 complaint (&symfile_complaints
,
4602 _("debug type entry at offset 0x%x is duplicate to"
4603 " the entry at offset 0x%x, signature %s"),
4604 offset
.sect_off
, dup_offset
.sect_off
,
4605 hex_string (signature
));
4607 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4609 if (dwarf2_read_debug
)
4610 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature %s\n",
4612 hex_string (signature
));
4621 /* Create the hash table of all entries in the .debug_types section,
4622 and initialize all_type_units.
4623 The result is zero if there is an error (e.g. missing .debug_types section),
4624 otherwise non-zero. */
4627 create_all_type_units (struct objfile
*objfile
)
4630 struct signatured_type
**iter
;
4632 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4633 if (types_htab
== NULL
)
4635 dwarf2_per_objfile
->signatured_types
= NULL
;
4639 dwarf2_per_objfile
->signatured_types
= types_htab
;
4641 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
4642 dwarf2_per_objfile
->all_type_units
4643 = xmalloc (dwarf2_per_objfile
->n_type_units
4644 * sizeof (struct signatured_type
*));
4645 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4646 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4647 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4648 == dwarf2_per_objfile
->n_type_units
);
4653 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
4654 Fill in SIG_ENTRY with DWO_ENTRY. */
4657 fill_in_sig_entry_from_dwo_entry (struct objfile
*objfile
,
4658 struct signatured_type
*sig_entry
,
4659 struct dwo_unit
*dwo_entry
)
4661 /* Make sure we're not clobbering something we don't expect to. */
4662 gdb_assert (! sig_entry
->per_cu
.queued
);
4663 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
4664 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
4665 gdb_assert (sig_entry
->per_cu
.v
.quick
->symtab
== NULL
);
4666 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
4667 gdb_assert (sig_entry
->type_offset_in_section
.sect_off
== 0);
4668 gdb_assert (sig_entry
->type_unit_group
== NULL
);
4669 gdb_assert (sig_entry
->dwo_unit
== NULL
);
4671 sig_entry
->per_cu
.section
= dwo_entry
->section
;
4672 sig_entry
->per_cu
.offset
= dwo_entry
->offset
;
4673 sig_entry
->per_cu
.length
= dwo_entry
->length
;
4674 sig_entry
->per_cu
.reading_dwo_directly
= 1;
4675 sig_entry
->per_cu
.objfile
= objfile
;
4676 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
4677 sig_entry
->dwo_unit
= dwo_entry
;
4680 /* Subroutine of lookup_signatured_type.
4681 If we haven't read the TU yet, create the signatured_type data structure
4682 for a TU to be read in directly from a DWO file, bypassing the stub.
4683 This is the "Stay in DWO Optimization": When there is no DWP file and we're
4684 using .gdb_index, then when reading a CU we want to stay in the DWO file
4685 containing that CU. Otherwise we could end up reading several other DWO
4686 files (due to comdat folding) to process the transitive closure of all the
4687 mentioned TUs, and that can be slow. The current DWO file will have every
4688 type signature that it needs.
4689 We only do this for .gdb_index because in the psymtab case we already have
4690 to read all the DWOs to build the type unit groups. */
4692 static struct signatured_type
*
4693 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
4695 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4696 struct dwo_file
*dwo_file
;
4697 struct dwo_unit find_dwo_entry
, *dwo_entry
;
4698 struct signatured_type find_sig_entry
, *sig_entry
;
4700 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
4702 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
4703 dwo_unit of the TU itself. */
4704 dwo_file
= cu
->dwo_unit
->dwo_file
;
4706 /* We only ever need to read in one copy of a signatured type.
4707 Just use the global signatured_types array. If this is the first time
4708 we're reading this type, replace the recorded data from .gdb_index with
4711 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4713 find_sig_entry
.signature
= sig
;
4714 sig_entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_sig_entry
);
4715 if (sig_entry
== NULL
)
4718 /* We can get here with the TU already read, *or* in the process of being
4719 read. Don't reassign it if that's the case. Also note that if the TU is
4720 already being read, it may not have come from a DWO, the program may be
4721 a mix of Fission-compiled code and non-Fission-compiled code. */
4722 /* Have we already tried to read this TU? */
4723 if (sig_entry
->per_cu
.tu_read
)
4726 /* Ok, this is the first time we're reading this TU. */
4727 if (dwo_file
->tus
== NULL
)
4729 find_dwo_entry
.signature
= sig
;
4730 dwo_entry
= htab_find (dwo_file
->tus
, &find_dwo_entry
);
4731 if (dwo_entry
== NULL
)
4734 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
4735 sig_entry
->per_cu
.tu_read
= 1;
4739 /* Subroutine of lookup_dwp_signatured_type.
4740 Add an entry for signature SIG to dwarf2_per_objfile->signatured_types. */
4742 static struct signatured_type
*
4743 add_type_unit (ULONGEST sig
)
4745 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4746 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
4747 struct signatured_type
*sig_type
;
4751 dwarf2_per_objfile
->all_type_units
=
4752 xrealloc (dwarf2_per_objfile
->all_type_units
,
4753 n_type_units
* sizeof (struct signatured_type
*));
4754 dwarf2_per_objfile
->n_type_units
= n_type_units
;
4755 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4756 struct signatured_type
);
4757 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
4758 sig_type
->signature
= sig
;
4759 sig_type
->per_cu
.is_debug_types
= 1;
4760 sig_type
->per_cu
.v
.quick
=
4761 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4762 struct dwarf2_per_cu_quick_data
);
4763 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
4765 gdb_assert (*slot
== NULL
);
4767 /* The rest of sig_type must be filled in by the caller. */
4771 /* Subroutine of lookup_signatured_type.
4772 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
4773 then try the DWP file.
4774 Normally this "can't happen", but if there's a bug in signature
4775 generation and/or the DWP file is built incorrectly, it can happen.
4776 Using the type directly from the DWP file means we don't have the stub
4777 which has some useful attributes (e.g., DW_AT_comp_dir), but they're
4778 not critical. [Eventually the stub may go away for type units anyway.] */
4780 static struct signatured_type
*
4781 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
4783 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4784 struct dwp_file
*dwp_file
= get_dwp_file ();
4785 struct dwo_unit
*dwo_entry
;
4786 struct signatured_type find_sig_entry
, *sig_entry
;
4788 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
4789 gdb_assert (dwp_file
!= NULL
);
4791 if (dwarf2_per_objfile
->signatured_types
!= NULL
)
4793 find_sig_entry
.signature
= sig
;
4794 sig_entry
= htab_find (dwarf2_per_objfile
->signatured_types
,
4796 if (sig_entry
!= NULL
)
4800 /* This is the "shouldn't happen" case.
4801 Try the DWP file and hope for the best. */
4802 if (dwp_file
->tus
== NULL
)
4804 dwo_entry
= lookup_dwo_unit_in_dwp (dwp_file
, NULL
,
4805 sig
, 1 /* is_debug_types */);
4806 if (dwo_entry
== NULL
)
4809 sig_entry
= add_type_unit (sig
);
4810 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
4812 /* The caller will signal a complaint if we return NULL.
4813 Here we don't return NULL but we still want to complain. */
4814 complaint (&symfile_complaints
,
4815 _("Bad type signature %s referenced by %s at 0x%x,"
4816 " coping by using copy in DWP [in module %s]"),
4818 cu
->per_cu
->is_debug_types
? "TU" : "CU",
4819 cu
->per_cu
->offset
.sect_off
,
4820 objfile_name (objfile
));
4825 /* Lookup a signature based type for DW_FORM_ref_sig8.
4826 Returns NULL if signature SIG is not present in the table.
4827 It is up to the caller to complain about this. */
4829 static struct signatured_type
*
4830 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
4833 && dwarf2_per_objfile
->using_index
)
4835 /* We're in a DWO/DWP file, and we're using .gdb_index.
4836 These cases require special processing. */
4837 if (get_dwp_file () == NULL
)
4838 return lookup_dwo_signatured_type (cu
, sig
);
4840 return lookup_dwp_signatured_type (cu
, sig
);
4844 struct signatured_type find_entry
, *entry
;
4846 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4848 find_entry
.signature
= sig
;
4849 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
4854 /* Low level DIE reading support. */
4856 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4859 init_cu_die_reader (struct die_reader_specs
*reader
,
4860 struct dwarf2_cu
*cu
,
4861 struct dwarf2_section_info
*section
,
4862 struct dwo_file
*dwo_file
)
4864 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
4865 reader
->abfd
= get_section_bfd_owner (section
);
4867 reader
->dwo_file
= dwo_file
;
4868 reader
->die_section
= section
;
4869 reader
->buffer
= section
->buffer
;
4870 reader
->buffer_end
= section
->buffer
+ section
->size
;
4871 reader
->comp_dir
= NULL
;
4874 /* Subroutine of init_cutu_and_read_dies to simplify it.
4875 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
4876 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
4879 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
4880 from it to the DIE in the DWO. If NULL we are skipping the stub.
4881 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
4882 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
4883 attribute of the referencing CU. Exactly one of STUB_COMP_UNIT_DIE and
4884 COMP_DIR must be non-NULL.
4885 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
4886 are filled in with the info of the DIE from the DWO file.
4887 ABBREV_TABLE_PROVIDED is non-zero if the caller of init_cutu_and_read_dies
4888 provided an abbrev table to use.
4889 The result is non-zero if a valid (non-dummy) DIE was found. */
4892 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
4893 struct dwo_unit
*dwo_unit
,
4894 int abbrev_table_provided
,
4895 struct die_info
*stub_comp_unit_die
,
4896 const char *stub_comp_dir
,
4897 struct die_reader_specs
*result_reader
,
4898 const gdb_byte
**result_info_ptr
,
4899 struct die_info
**result_comp_unit_die
,
4900 int *result_has_children
)
4902 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4903 struct dwarf2_cu
*cu
= this_cu
->cu
;
4904 struct dwarf2_section_info
*section
;
4906 const gdb_byte
*begin_info_ptr
, *info_ptr
;
4907 const char *comp_dir_string
;
4908 ULONGEST signature
; /* Or dwo_id. */
4909 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
4910 int i
,num_extra_attrs
;
4911 struct dwarf2_section_info
*dwo_abbrev_section
;
4912 struct attribute
*attr
;
4913 struct attribute comp_dir_attr
;
4914 struct die_info
*comp_unit_die
;
4916 /* Both can't be provided. */
4917 gdb_assert (! (stub_comp_unit_die
&& stub_comp_dir
));
4919 /* These attributes aren't processed until later:
4920 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4921 However, the attribute is found in the stub which we won't have later.
4922 In order to not impose this complication on the rest of the code,
4923 we read them here and copy them to the DWO CU/TU die. */
4931 if (stub_comp_unit_die
!= NULL
)
4933 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4935 if (! this_cu
->is_debug_types
)
4936 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
4937 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
4938 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
4939 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
4940 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
4942 /* There should be a DW_AT_addr_base attribute here (if needed).
4943 We need the value before we can process DW_FORM_GNU_addr_index. */
4945 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4947 cu
->addr_base
= DW_UNSND (attr
);
4949 /* There should be a DW_AT_ranges_base attribute here (if needed).
4950 We need the value before we can process DW_AT_ranges. */
4951 cu
->ranges_base
= 0;
4952 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4954 cu
->ranges_base
= DW_UNSND (attr
);
4956 else if (stub_comp_dir
!= NULL
)
4958 /* Reconstruct the comp_dir attribute to simplify the code below. */
4959 comp_dir
= (struct attribute
*)
4960 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (*comp_dir
));
4961 comp_dir
->name
= DW_AT_comp_dir
;
4962 comp_dir
->form
= DW_FORM_string
;
4963 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
4964 DW_STRING (comp_dir
) = stub_comp_dir
;
4967 /* Set up for reading the DWO CU/TU. */
4968 cu
->dwo_unit
= dwo_unit
;
4969 section
= dwo_unit
->section
;
4970 dwarf2_read_section (objfile
, section
);
4971 abfd
= get_section_bfd_owner (section
);
4972 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4973 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4974 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
);
4976 if (this_cu
->is_debug_types
)
4978 ULONGEST header_signature
;
4979 cu_offset type_offset_in_tu
;
4980 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
4982 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4986 &type_offset_in_tu
);
4987 /* This is not an assert because it can be caused by bad debug info. */
4988 if (sig_type
->signature
!= header_signature
)
4990 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
4991 " TU at offset 0x%x [in module %s]"),
4992 hex_string (sig_type
->signature
),
4993 hex_string (header_signature
),
4994 dwo_unit
->offset
.sect_off
,
4995 bfd_get_filename (abfd
));
4997 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4998 /* For DWOs coming from DWP files, we don't know the CU length
4999 nor the type's offset in the TU until now. */
5000 dwo_unit
->length
= get_cu_length (&cu
->header
);
5001 dwo_unit
->type_offset_in_tu
= type_offset_in_tu
;
5003 /* Establish the type offset that can be used to lookup the type.
5004 For DWO files, we don't know it until now. */
5005 sig_type
->type_offset_in_section
.sect_off
=
5006 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
5010 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5013 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5014 /* For DWOs coming from DWP files, we don't know the CU length
5016 dwo_unit
->length
= get_cu_length (&cu
->header
);
5019 /* Replace the CU's original abbrev table with the DWO's.
5020 Reminder: We can't read the abbrev table until we've read the header. */
5021 if (abbrev_table_provided
)
5023 /* Don't free the provided abbrev table, the caller of
5024 init_cutu_and_read_dies owns it. */
5025 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5026 /* Ensure the DWO abbrev table gets freed. */
5027 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5031 dwarf2_free_abbrev_table (cu
);
5032 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5033 /* Leave any existing abbrev table cleanup as is. */
5036 /* Read in the die, but leave space to copy over the attributes
5037 from the stub. This has the benefit of simplifying the rest of
5038 the code - all the work to maintain the illusion of a single
5039 DW_TAG_{compile,type}_unit DIE is done here. */
5040 num_extra_attrs
= ((stmt_list
!= NULL
)
5044 + (comp_dir
!= NULL
));
5045 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
5046 result_has_children
, num_extra_attrs
);
5048 /* Copy over the attributes from the stub to the DIE we just read in. */
5049 comp_unit_die
= *result_comp_unit_die
;
5050 i
= comp_unit_die
->num_attrs
;
5051 if (stmt_list
!= NULL
)
5052 comp_unit_die
->attrs
[i
++] = *stmt_list
;
5054 comp_unit_die
->attrs
[i
++] = *low_pc
;
5055 if (high_pc
!= NULL
)
5056 comp_unit_die
->attrs
[i
++] = *high_pc
;
5058 comp_unit_die
->attrs
[i
++] = *ranges
;
5059 if (comp_dir
!= NULL
)
5060 comp_unit_die
->attrs
[i
++] = *comp_dir
;
5061 comp_unit_die
->num_attrs
+= num_extra_attrs
;
5063 if (dwarf2_die_debug
)
5065 fprintf_unfiltered (gdb_stdlog
,
5066 "Read die from %s@0x%x of %s:\n",
5067 get_section_name (section
),
5068 (unsigned) (begin_info_ptr
- section
->buffer
),
5069 bfd_get_filename (abfd
));
5070 dump_die (comp_unit_die
, dwarf2_die_debug
);
5073 /* Save the comp_dir attribute. If there is no DWP file then we'll read
5074 TUs by skipping the stub and going directly to the entry in the DWO file.
5075 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
5076 to get it via circuitous means. Blech. */
5077 if (comp_dir
!= NULL
)
5078 result_reader
->comp_dir
= DW_STRING (comp_dir
);
5080 /* Skip dummy compilation units. */
5081 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
5082 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5085 *result_info_ptr
= info_ptr
;
5089 /* Subroutine of init_cutu_and_read_dies to simplify it.
5090 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
5091 Returns NULL if the specified DWO unit cannot be found. */
5093 static struct dwo_unit
*
5094 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
5095 struct die_info
*comp_unit_die
)
5097 struct dwarf2_cu
*cu
= this_cu
->cu
;
5098 struct attribute
*attr
;
5100 struct dwo_unit
*dwo_unit
;
5101 const char *comp_dir
, *dwo_name
;
5103 gdb_assert (cu
!= NULL
);
5105 /* Yeah, we look dwo_name up again, but it simplifies the code. */
5106 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5107 gdb_assert (attr
!= NULL
);
5108 dwo_name
= DW_STRING (attr
);
5110 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
5112 comp_dir
= DW_STRING (attr
);
5114 if (this_cu
->is_debug_types
)
5116 struct signatured_type
*sig_type
;
5118 /* Since this_cu is the first member of struct signatured_type,
5119 we can go from a pointer to one to a pointer to the other. */
5120 sig_type
= (struct signatured_type
*) this_cu
;
5121 signature
= sig_type
->signature
;
5122 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
5126 struct attribute
*attr
;
5128 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
5130 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
5132 dwo_name
, objfile_name (this_cu
->objfile
));
5133 signature
= DW_UNSND (attr
);
5134 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
5141 /* Subroutine of init_cutu_and_read_dies to simplify it.
5142 Read a TU directly from a DWO file, bypassing the stub. */
5145 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
, int keep
,
5146 die_reader_func_ftype
*die_reader_func
,
5149 struct dwarf2_cu
*cu
;
5150 struct signatured_type
*sig_type
;
5151 struct cleanup
*cleanups
, *free_cu_cleanup
;
5152 struct die_reader_specs reader
;
5153 const gdb_byte
*info_ptr
;
5154 struct die_info
*comp_unit_die
;
5157 /* Verify we can do the following downcast, and that we have the
5159 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
5160 sig_type
= (struct signatured_type
*) this_cu
;
5161 gdb_assert (sig_type
->dwo_unit
!= NULL
);
5163 cleanups
= make_cleanup (null_cleanup
, NULL
);
5165 gdb_assert (this_cu
->cu
== NULL
);
5166 cu
= xmalloc (sizeof (*cu
));
5167 init_one_comp_unit (cu
, this_cu
);
5168 /* If an error occurs while loading, release our storage. */
5169 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5171 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
5172 0 /* abbrev_table_provided */,
5173 NULL
/* stub_comp_unit_die */,
5174 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
5176 &comp_unit_die
, &has_children
) == 0)
5179 do_cleanups (cleanups
);
5183 /* All the "real" work is done here. */
5184 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5186 /* This duplicates some code in init_cutu_and_read_dies,
5187 but the alternative is making the latter more complex.
5188 This function is only for the special case of using DWO files directly:
5189 no point in overly complicating the general case just to handle this. */
5192 /* We've successfully allocated this compilation unit. Let our
5193 caller clean it up when finished with it. */
5194 discard_cleanups (free_cu_cleanup
);
5196 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5197 So we have to manually free the abbrev table. */
5198 dwarf2_free_abbrev_table (cu
);
5200 /* Link this CU into read_in_chain. */
5201 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5202 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5205 do_cleanups (free_cu_cleanup
);
5207 do_cleanups (cleanups
);
5210 /* Initialize a CU (or TU) and read its DIEs.
5211 If the CU defers to a DWO file, read the DWO file as well.
5213 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
5214 Otherwise the table specified in the comp unit header is read in and used.
5215 This is an optimization for when we already have the abbrev table.
5217 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
5218 Otherwise, a new CU is allocated with xmalloc.
5220 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
5221 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
5223 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5224 linker) then DIE_READER_FUNC will not get called. */
5227 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
5228 struct abbrev_table
*abbrev_table
,
5229 int use_existing_cu
, int keep
,
5230 die_reader_func_ftype
*die_reader_func
,
5233 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5234 struct dwarf2_section_info
*section
= this_cu
->section
;
5235 bfd
*abfd
= get_section_bfd_owner (section
);
5236 struct dwarf2_cu
*cu
;
5237 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5238 struct die_reader_specs reader
;
5239 struct die_info
*comp_unit_die
;
5241 struct attribute
*attr
;
5242 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5243 struct signatured_type
*sig_type
= NULL
;
5244 struct dwarf2_section_info
*abbrev_section
;
5245 /* Non-zero if CU currently points to a DWO file and we need to
5246 reread it. When this happens we need to reread the skeleton die
5247 before we can reread the DWO file (this only applies to CUs, not TUs). */
5248 int rereading_dwo_cu
= 0;
5250 if (dwarf2_die_debug
)
5251 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5252 this_cu
->is_debug_types
? "type" : "comp",
5253 this_cu
->offset
.sect_off
);
5255 if (use_existing_cu
)
5258 /* If we're reading a TU directly from a DWO file, including a virtual DWO
5259 file (instead of going through the stub), short-circuit all of this. */
5260 if (this_cu
->reading_dwo_directly
)
5262 /* Narrow down the scope of possibilities to have to understand. */
5263 gdb_assert (this_cu
->is_debug_types
);
5264 gdb_assert (abbrev_table
== NULL
);
5265 gdb_assert (!use_existing_cu
);
5266 init_tu_and_read_dwo_dies (this_cu
, keep
, die_reader_func
, data
);
5270 cleanups
= make_cleanup (null_cleanup
, NULL
);
5272 /* This is cheap if the section is already read in. */
5273 dwarf2_read_section (objfile
, section
);
5275 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
5277 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
5279 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5283 /* If this CU is from a DWO file we need to start over, we need to
5284 refetch the attributes from the skeleton CU.
5285 This could be optimized by retrieving those attributes from when we
5286 were here the first time: the previous comp_unit_die was stored in
5287 comp_unit_obstack. But there's no data yet that we need this
5289 if (cu
->dwo_unit
!= NULL
)
5290 rereading_dwo_cu
= 1;
5294 /* If !use_existing_cu, this_cu->cu must be NULL. */
5295 gdb_assert (this_cu
->cu
== NULL
);
5297 cu
= xmalloc (sizeof (*cu
));
5298 init_one_comp_unit (cu
, this_cu
);
5300 /* If an error occurs while loading, release our storage. */
5301 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5304 /* Get the header. */
5305 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
5307 /* We already have the header, there's no need to read it in again. */
5308 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
5312 if (this_cu
->is_debug_types
)
5315 cu_offset type_offset_in_tu
;
5317 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
5318 abbrev_section
, info_ptr
,
5320 &type_offset_in_tu
);
5322 /* Since per_cu is the first member of struct signatured_type,
5323 we can go from a pointer to one to a pointer to the other. */
5324 sig_type
= (struct signatured_type
*) this_cu
;
5325 gdb_assert (sig_type
->signature
== signature
);
5326 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
5327 == type_offset_in_tu
.cu_off
);
5328 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5330 /* LENGTH has not been set yet for type units if we're
5331 using .gdb_index. */
5332 this_cu
->length
= get_cu_length (&cu
->header
);
5334 /* Establish the type offset that can be used to lookup the type. */
5335 sig_type
->type_offset_in_section
.sect_off
=
5336 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
5340 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5344 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5345 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
5349 /* Skip dummy compilation units. */
5350 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5351 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5353 do_cleanups (cleanups
);
5357 /* If we don't have them yet, read the abbrevs for this compilation unit.
5358 And if we need to read them now, make sure they're freed when we're
5359 done. Note that it's important that if the CU had an abbrev table
5360 on entry we don't free it when we're done: Somewhere up the call stack
5361 it may be in use. */
5362 if (abbrev_table
!= NULL
)
5364 gdb_assert (cu
->abbrev_table
== NULL
);
5365 gdb_assert (cu
->header
.abbrev_offset
.sect_off
5366 == abbrev_table
->offset
.sect_off
);
5367 cu
->abbrev_table
= abbrev_table
;
5369 else if (cu
->abbrev_table
== NULL
)
5371 dwarf2_read_abbrevs (cu
, abbrev_section
);
5372 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5374 else if (rereading_dwo_cu
)
5376 dwarf2_free_abbrev_table (cu
);
5377 dwarf2_read_abbrevs (cu
, abbrev_section
);
5380 /* Read the top level CU/TU die. */
5381 init_cu_die_reader (&reader
, cu
, section
, NULL
);
5382 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5384 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
5386 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
5387 DWO CU, that this test will fail (the attribute will not be present). */
5388 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5391 struct dwo_unit
*dwo_unit
;
5392 struct die_info
*dwo_comp_unit_die
;
5396 complaint (&symfile_complaints
,
5397 _("compilation unit with DW_AT_GNU_dwo_name"
5398 " has children (offset 0x%x) [in module %s]"),
5399 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
5401 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
5402 if (dwo_unit
!= NULL
)
5404 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
5405 abbrev_table
!= NULL
,
5406 comp_unit_die
, NULL
,
5408 &dwo_comp_unit_die
, &has_children
) == 0)
5411 do_cleanups (cleanups
);
5414 comp_unit_die
= dwo_comp_unit_die
;
5418 /* Yikes, we couldn't find the rest of the DIE, we only have
5419 the stub. A complaint has already been logged. There's
5420 not much more we can do except pass on the stub DIE to
5421 die_reader_func. We don't want to throw an error on bad
5426 /* All of the above is setup for this call. Yikes. */
5427 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5429 /* Done, clean up. */
5430 if (free_cu_cleanup
!= NULL
)
5434 /* We've successfully allocated this compilation unit. Let our
5435 caller clean it up when finished with it. */
5436 discard_cleanups (free_cu_cleanup
);
5438 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5439 So we have to manually free the abbrev table. */
5440 dwarf2_free_abbrev_table (cu
);
5442 /* Link this CU into read_in_chain. */
5443 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5444 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5447 do_cleanups (free_cu_cleanup
);
5450 do_cleanups (cleanups
);
5453 /* Read CU/TU THIS_CU in section SECTION,
5454 but do not follow DW_AT_GNU_dwo_name if present.
5455 DWOP_FILE, if non-NULL, is the DWO/DWP file to read (the caller is assumed
5456 to have already done the lookup to find the DWO/DWP file).
5458 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
5459 THIS_CU->is_debug_types, but nothing else.
5461 We fill in THIS_CU->length.
5463 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5464 linker) then DIE_READER_FUNC will not get called.
5466 THIS_CU->cu is always freed when done.
5467 This is done in order to not leave THIS_CU->cu in a state where we have
5468 to care whether it refers to the "main" CU or the DWO CU. */
5471 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
5472 struct dwarf2_section_info
*abbrev_section
,
5473 struct dwo_file
*dwo_file
,
5474 die_reader_func_ftype
*die_reader_func
,
5477 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5478 struct dwarf2_section_info
*section
= this_cu
->section
;
5479 bfd
*abfd
= get_section_bfd_owner (section
);
5480 struct dwarf2_cu cu
;
5481 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5482 struct die_reader_specs reader
;
5483 struct cleanup
*cleanups
;
5484 struct die_info
*comp_unit_die
;
5487 if (dwarf2_die_debug
)
5488 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5489 this_cu
->is_debug_types
? "type" : "comp",
5490 this_cu
->offset
.sect_off
);
5492 gdb_assert (this_cu
->cu
== NULL
);
5494 /* This is cheap if the section is already read in. */
5495 dwarf2_read_section (objfile
, section
);
5497 init_one_comp_unit (&cu
, this_cu
);
5499 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
5501 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
5502 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
5503 abbrev_section
, info_ptr
,
5504 this_cu
->is_debug_types
);
5506 this_cu
->length
= get_cu_length (&cu
.header
);
5508 /* Skip dummy compilation units. */
5509 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5510 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5512 do_cleanups (cleanups
);
5516 dwarf2_read_abbrevs (&cu
, abbrev_section
);
5517 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
5519 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
5520 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5522 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5524 do_cleanups (cleanups
);
5527 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
5528 does not lookup the specified DWO file.
5529 This cannot be used to read DWO files.
5531 THIS_CU->cu is always freed when done.
5532 This is done in order to not leave THIS_CU->cu in a state where we have
5533 to care whether it refers to the "main" CU or the DWO CU.
5534 We can revisit this if the data shows there's a performance issue. */
5537 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
5538 die_reader_func_ftype
*die_reader_func
,
5541 init_cutu_and_read_dies_no_follow (this_cu
,
5542 get_abbrev_section_for_cu (this_cu
),
5544 die_reader_func
, data
);
5547 /* Type Unit Groups.
5549 Type Unit Groups are a way to collapse the set of all TUs (type units) into
5550 a more manageable set. The grouping is done by DW_AT_stmt_list entry
5551 so that all types coming from the same compilation (.o file) are grouped
5552 together. A future step could be to put the types in the same symtab as
5553 the CU the types ultimately came from. */
5556 hash_type_unit_group (const void *item
)
5558 const struct type_unit_group
*tu_group
= item
;
5560 return hash_stmt_list_entry (&tu_group
->hash
);
5564 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
5566 const struct type_unit_group
*lhs
= item_lhs
;
5567 const struct type_unit_group
*rhs
= item_rhs
;
5569 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
5572 /* Allocate a hash table for type unit groups. */
5575 allocate_type_unit_groups_table (void)
5577 return htab_create_alloc_ex (3,
5578 hash_type_unit_group
,
5581 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
5582 hashtab_obstack_allocate
,
5583 dummy_obstack_deallocate
);
5586 /* Type units that don't have DW_AT_stmt_list are grouped into their own
5587 partial symtabs. We combine several TUs per psymtab to not let the size
5588 of any one psymtab grow too big. */
5589 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
5590 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5592 /* Helper routine for get_type_unit_group.
5593 Create the type_unit_group object used to hold one or more TUs. */
5595 static struct type_unit_group
*
5596 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
5598 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5599 struct dwarf2_per_cu_data
*per_cu
;
5600 struct type_unit_group
*tu_group
;
5602 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5603 struct type_unit_group
);
5604 per_cu
= &tu_group
->per_cu
;
5605 per_cu
->objfile
= objfile
;
5607 if (dwarf2_per_objfile
->using_index
)
5609 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5610 struct dwarf2_per_cu_quick_data
);
5614 unsigned int line_offset
= line_offset_struct
.sect_off
;
5615 struct partial_symtab
*pst
;
5618 /* Give the symtab a useful name for debug purposes. */
5619 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
5620 name
= xstrprintf ("<type_units_%d>",
5621 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
5623 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
5625 pst
= create_partial_symtab (per_cu
, name
);
5631 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
5632 tu_group
->hash
.line_offset
= line_offset_struct
;
5637 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5638 STMT_LIST is a DW_AT_stmt_list attribute. */
5640 static struct type_unit_group
*
5641 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
5643 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5644 struct type_unit_group
*tu_group
;
5646 unsigned int line_offset
;
5647 struct type_unit_group type_unit_group_for_lookup
;
5649 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
5651 dwarf2_per_objfile
->type_unit_groups
=
5652 allocate_type_unit_groups_table ();
5655 /* Do we need to create a new group, or can we use an existing one? */
5659 line_offset
= DW_UNSND (stmt_list
);
5660 ++tu_stats
->nr_symtab_sharers
;
5664 /* Ugh, no stmt_list. Rare, but we have to handle it.
5665 We can do various things here like create one group per TU or
5666 spread them over multiple groups to split up the expansion work.
5667 To avoid worst case scenarios (too many groups or too large groups)
5668 we, umm, group them in bunches. */
5669 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5670 | (tu_stats
->nr_stmt_less_type_units
5671 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
5672 ++tu_stats
->nr_stmt_less_type_units
;
5675 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
5676 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
5677 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
5678 &type_unit_group_for_lookup
, INSERT
);
5682 gdb_assert (tu_group
!= NULL
);
5686 sect_offset line_offset_struct
;
5688 line_offset_struct
.sect_off
= line_offset
;
5689 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
5691 ++tu_stats
->nr_symtabs
;
5697 /* Struct used to sort TUs by their abbreviation table offset. */
5699 struct tu_abbrev_offset
5701 struct signatured_type
*sig_type
;
5702 sect_offset abbrev_offset
;
5705 /* Helper routine for build_type_unit_groups, passed to qsort. */
5708 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
5710 const struct tu_abbrev_offset
* const *a
= ap
;
5711 const struct tu_abbrev_offset
* const *b
= bp
;
5712 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
5713 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
5715 return (aoff
> boff
) - (aoff
< boff
);
5718 /* A helper function to add a type_unit_group to a table. */
5721 add_type_unit_group_to_table (void **slot
, void *datum
)
5723 struct type_unit_group
*tu_group
= *slot
;
5724 struct type_unit_group
***datap
= datum
;
5732 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
5733 each one passing FUNC,DATA.
5735 The efficiency is because we sort TUs by the abbrev table they use and
5736 only read each abbrev table once. In one program there are 200K TUs
5737 sharing 8K abbrev tables.
5739 The main purpose of this function is to support building the
5740 dwarf2_per_objfile->type_unit_groups table.
5741 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
5742 can collapse the search space by grouping them by stmt_list.
5743 The savings can be significant, in the same program from above the 200K TUs
5744 share 8K stmt_list tables.
5746 FUNC is expected to call get_type_unit_group, which will create the
5747 struct type_unit_group if necessary and add it to
5748 dwarf2_per_objfile->type_unit_groups. */
5751 build_type_unit_groups (die_reader_func_ftype
*func
, void *data
)
5753 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5754 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5755 struct cleanup
*cleanups
;
5756 struct abbrev_table
*abbrev_table
;
5757 sect_offset abbrev_offset
;
5758 struct tu_abbrev_offset
*sorted_by_abbrev
;
5759 struct type_unit_group
**iter
;
5762 /* It's up to the caller to not call us multiple times. */
5763 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
5765 if (dwarf2_per_objfile
->n_type_units
== 0)
5768 /* TUs typically share abbrev tables, and there can be way more TUs than
5769 abbrev tables. Sort by abbrev table to reduce the number of times we
5770 read each abbrev table in.
5771 Alternatives are to punt or to maintain a cache of abbrev tables.
5772 This is simpler and efficient enough for now.
5774 Later we group TUs by their DW_AT_stmt_list value (as this defines the
5775 symtab to use). Typically TUs with the same abbrev offset have the same
5776 stmt_list value too so in practice this should work well.
5778 The basic algorithm here is:
5780 sort TUs by abbrev table
5781 for each TU with same abbrev table:
5782 read abbrev table if first user
5783 read TU top level DIE
5784 [IWBN if DWO skeletons had DW_AT_stmt_list]
5787 if (dwarf2_read_debug
)
5788 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
5790 /* Sort in a separate table to maintain the order of all_type_units
5791 for .gdb_index: TU indices directly index all_type_units. */
5792 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
5793 dwarf2_per_objfile
->n_type_units
);
5794 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5796 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
5798 sorted_by_abbrev
[i
].sig_type
= sig_type
;
5799 sorted_by_abbrev
[i
].abbrev_offset
=
5800 read_abbrev_offset (sig_type
->per_cu
.section
,
5801 sig_type
->per_cu
.offset
);
5803 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
5804 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
5805 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
5807 /* Note: In the .gdb_index case, get_type_unit_group may have already been
5808 called any number of times, so we don't reset tu_stats here. */
5810 abbrev_offset
.sect_off
= ~(unsigned) 0;
5811 abbrev_table
= NULL
;
5812 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
5814 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5816 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
5818 /* Switch to the next abbrev table if necessary. */
5819 if (abbrev_table
== NULL
5820 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
5822 if (abbrev_table
!= NULL
)
5824 abbrev_table_free (abbrev_table
);
5825 /* Reset to NULL in case abbrev_table_read_table throws
5826 an error: abbrev_table_free_cleanup will get called. */
5827 abbrev_table
= NULL
;
5829 abbrev_offset
= tu
->abbrev_offset
;
5831 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
5833 ++tu_stats
->nr_uniq_abbrev_tables
;
5836 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
5840 /* type_unit_groups can be NULL if there is an error in the debug info.
5841 Just create an empty table so the rest of gdb doesn't have to watch
5842 for this error case. */
5843 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
5845 dwarf2_per_objfile
->type_unit_groups
=
5846 allocate_type_unit_groups_table ();
5847 dwarf2_per_objfile
->n_type_unit_groups
= 0;
5850 /* Create a vector of pointers to primary type units to make it easy to
5851 iterate over them and CUs. See dw2_get_primary_cu. */
5852 dwarf2_per_objfile
->n_type_unit_groups
=
5853 htab_elements (dwarf2_per_objfile
->type_unit_groups
);
5854 dwarf2_per_objfile
->all_type_unit_groups
=
5855 obstack_alloc (&objfile
->objfile_obstack
,
5856 dwarf2_per_objfile
->n_type_unit_groups
5857 * sizeof (struct type_unit_group
*));
5858 iter
= &dwarf2_per_objfile
->all_type_unit_groups
[0];
5859 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5860 add_type_unit_group_to_table
, &iter
);
5861 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_unit_groups
[0]
5862 == dwarf2_per_objfile
->n_type_unit_groups
);
5864 do_cleanups (cleanups
);
5866 if (dwarf2_read_debug
)
5868 fprintf_unfiltered (gdb_stdlog
, "Done building type unit groups:\n");
5869 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
5870 dwarf2_per_objfile
->n_type_units
);
5871 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
5872 tu_stats
->nr_uniq_abbrev_tables
);
5873 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
5874 tu_stats
->nr_symtabs
);
5875 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
5876 tu_stats
->nr_symtab_sharers
);
5877 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
5878 tu_stats
->nr_stmt_less_type_units
);
5882 /* Partial symbol tables. */
5884 /* Create a psymtab named NAME and assign it to PER_CU.
5886 The caller must fill in the following details:
5887 dirname, textlow, texthigh. */
5889 static struct partial_symtab
*
5890 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
5892 struct objfile
*objfile
= per_cu
->objfile
;
5893 struct partial_symtab
*pst
;
5895 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
5897 objfile
->global_psymbols
.next
,
5898 objfile
->static_psymbols
.next
);
5900 pst
->psymtabs_addrmap_supported
= 1;
5902 /* This is the glue that links PST into GDB's symbol API. */
5903 pst
->read_symtab_private
= per_cu
;
5904 pst
->read_symtab
= dwarf2_read_symtab
;
5905 per_cu
->v
.psymtab
= pst
;
5910 /* The DATA object passed to process_psymtab_comp_unit_reader has this
5913 struct process_psymtab_comp_unit_data
5915 /* True if we are reading a DW_TAG_partial_unit. */
5917 int want_partial_unit
;
5919 /* The "pretend" language that is used if the CU doesn't declare a
5922 enum language pretend_language
;
5925 /* die_reader_func for process_psymtab_comp_unit. */
5928 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
5929 const gdb_byte
*info_ptr
,
5930 struct die_info
*comp_unit_die
,
5934 struct dwarf2_cu
*cu
= reader
->cu
;
5935 struct objfile
*objfile
= cu
->objfile
;
5936 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5937 struct attribute
*attr
;
5939 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
5940 struct partial_symtab
*pst
;
5942 const char *filename
;
5943 struct process_psymtab_comp_unit_data
*info
= data
;
5945 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
5948 gdb_assert (! per_cu
->is_debug_types
);
5950 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
5952 cu
->list_in_scope
= &file_symbols
;
5954 /* Allocate a new partial symbol table structure. */
5955 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
5956 if (attr
== NULL
|| !DW_STRING (attr
))
5959 filename
= DW_STRING (attr
);
5961 pst
= create_partial_symtab (per_cu
, filename
);
5963 /* This must be done before calling dwarf2_build_include_psymtabs. */
5964 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
5966 pst
->dirname
= DW_STRING (attr
);
5968 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5970 dwarf2_find_base_address (comp_unit_die
, cu
);
5972 /* Possibly set the default values of LOWPC and HIGHPC from
5974 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
5975 &best_highpc
, cu
, pst
);
5976 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
5977 /* Store the contiguous range if it is not empty; it can be empty for
5978 CUs with no code. */
5979 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5980 best_lowpc
+ baseaddr
,
5981 best_highpc
+ baseaddr
- 1, pst
);
5983 /* Check if comp unit has_children.
5984 If so, read the rest of the partial symbols from this comp unit.
5985 If not, there's no more debug_info for this comp unit. */
5988 struct partial_die_info
*first_die
;
5989 CORE_ADDR lowpc
, highpc
;
5991 lowpc
= ((CORE_ADDR
) -1);
5992 highpc
= ((CORE_ADDR
) 0);
5994 first_die
= load_partial_dies (reader
, info_ptr
, 1);
5996 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
5999 /* If we didn't find a lowpc, set it to highpc to avoid
6000 complaints from `maint check'. */
6001 if (lowpc
== ((CORE_ADDR
) -1))
6004 /* If the compilation unit didn't have an explicit address range,
6005 then use the information extracted from its child dies. */
6009 best_highpc
= highpc
;
6012 pst
->textlow
= best_lowpc
+ baseaddr
;
6013 pst
->texthigh
= best_highpc
+ baseaddr
;
6015 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
6016 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
6017 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
6018 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
6019 sort_pst_symbols (objfile
, pst
);
6021 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
6024 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6025 struct dwarf2_per_cu_data
*iter
;
6027 /* Fill in 'dependencies' here; we fill in 'users' in a
6029 pst
->number_of_dependencies
= len
;
6030 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
6031 len
* sizeof (struct symtab
*));
6033 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
6036 pst
->dependencies
[i
] = iter
->v
.psymtab
;
6038 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6041 /* Get the list of files included in the current compilation unit,
6042 and build a psymtab for each of them. */
6043 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
6045 if (dwarf2_read_debug
)
6047 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6049 fprintf_unfiltered (gdb_stdlog
,
6050 "Psymtab for %s unit @0x%x: %s - %s"
6051 ", %d global, %d static syms\n",
6052 per_cu
->is_debug_types
? "type" : "comp",
6053 per_cu
->offset
.sect_off
,
6054 paddress (gdbarch
, pst
->textlow
),
6055 paddress (gdbarch
, pst
->texthigh
),
6056 pst
->n_global_syms
, pst
->n_static_syms
);
6060 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6061 Process compilation unit THIS_CU for a psymtab. */
6064 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6065 int want_partial_unit
,
6066 enum language pretend_language
)
6068 struct process_psymtab_comp_unit_data info
;
6070 /* If this compilation unit was already read in, free the
6071 cached copy in order to read it in again. This is
6072 necessary because we skipped some symbols when we first
6073 read in the compilation unit (see load_partial_dies).
6074 This problem could be avoided, but the benefit is unclear. */
6075 if (this_cu
->cu
!= NULL
)
6076 free_one_cached_comp_unit (this_cu
);
6078 gdb_assert (! this_cu
->is_debug_types
);
6079 info
.want_partial_unit
= want_partial_unit
;
6080 info
.pretend_language
= pretend_language
;
6081 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
6082 process_psymtab_comp_unit_reader
,
6085 /* Age out any secondary CUs. */
6086 age_cached_comp_units ();
6089 /* Reader function for build_type_psymtabs. */
6092 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
6093 const gdb_byte
*info_ptr
,
6094 struct die_info
*type_unit_die
,
6098 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6099 struct dwarf2_cu
*cu
= reader
->cu
;
6100 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6101 struct signatured_type
*sig_type
;
6102 struct type_unit_group
*tu_group
;
6103 struct attribute
*attr
;
6104 struct partial_die_info
*first_die
;
6105 CORE_ADDR lowpc
, highpc
;
6106 struct partial_symtab
*pst
;
6108 gdb_assert (data
== NULL
);
6109 gdb_assert (per_cu
->is_debug_types
);
6110 sig_type
= (struct signatured_type
*) per_cu
;
6115 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
6116 tu_group
= get_type_unit_group (cu
, attr
);
6118 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
6120 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
6121 cu
->list_in_scope
= &file_symbols
;
6122 pst
= create_partial_symtab (per_cu
, "");
6125 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6127 lowpc
= (CORE_ADDR
) -1;
6128 highpc
= (CORE_ADDR
) 0;
6129 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
6131 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
6132 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
6133 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
6134 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
6135 sort_pst_symbols (objfile
, pst
);
6138 /* Traversal function for build_type_psymtabs. */
6141 build_type_psymtab_dependencies (void **slot
, void *info
)
6143 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6144 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
6145 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
6146 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6147 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
6148 struct signatured_type
*iter
;
6151 gdb_assert (len
> 0);
6152 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
6154 pst
->number_of_dependencies
= len
;
6155 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
6156 len
* sizeof (struct psymtab
*));
6158 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
6161 gdb_assert (iter
->per_cu
.is_debug_types
);
6162 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
6163 iter
->type_unit_group
= tu_group
;
6166 VEC_free (sig_type_ptr
, tu_group
->tus
);
6171 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6172 Build partial symbol tables for the .debug_types comp-units. */
6175 build_type_psymtabs (struct objfile
*objfile
)
6177 if (! create_all_type_units (objfile
))
6180 build_type_unit_groups (build_type_psymtabs_reader
, NULL
);
6182 /* Now that all TUs have been processed we can fill in the dependencies. */
6183 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
6184 build_type_psymtab_dependencies
, NULL
);
6187 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
6190 psymtabs_addrmap_cleanup (void *o
)
6192 struct objfile
*objfile
= o
;
6194 objfile
->psymtabs_addrmap
= NULL
;
6197 /* Compute the 'user' field for each psymtab in OBJFILE. */
6200 set_partial_user (struct objfile
*objfile
)
6204 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6206 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
6207 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6213 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
6215 /* Set the 'user' field only if it is not already set. */
6216 if (pst
->dependencies
[j
]->user
== NULL
)
6217 pst
->dependencies
[j
]->user
= pst
;
6222 /* Build the partial symbol table by doing a quick pass through the
6223 .debug_info and .debug_abbrev sections. */
6226 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
6228 struct cleanup
*back_to
, *addrmap_cleanup
;
6229 struct obstack temp_obstack
;
6232 if (dwarf2_read_debug
)
6234 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
6235 objfile_name (objfile
));
6238 dwarf2_per_objfile
->reading_partial_symbols
= 1;
6240 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
6242 /* Any cached compilation units will be linked by the per-objfile
6243 read_in_chain. Make sure to free them when we're done. */
6244 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
6246 build_type_psymtabs (objfile
);
6248 create_all_comp_units (objfile
);
6250 /* Create a temporary address map on a temporary obstack. We later
6251 copy this to the final obstack. */
6252 obstack_init (&temp_obstack
);
6253 make_cleanup_obstack_free (&temp_obstack
);
6254 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
6255 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
6257 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6259 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
6261 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
6264 set_partial_user (objfile
);
6266 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
6267 &objfile
->objfile_obstack
);
6268 discard_cleanups (addrmap_cleanup
);
6270 do_cleanups (back_to
);
6272 if (dwarf2_read_debug
)
6273 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
6274 objfile_name (objfile
));
6277 /* die_reader_func for load_partial_comp_unit. */
6280 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
6281 const gdb_byte
*info_ptr
,
6282 struct die_info
*comp_unit_die
,
6286 struct dwarf2_cu
*cu
= reader
->cu
;
6288 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
6290 /* Check if comp unit has_children.
6291 If so, read the rest of the partial symbols from this comp unit.
6292 If not, there's no more debug_info for this comp unit. */
6294 load_partial_dies (reader
, info_ptr
, 0);
6297 /* Load the partial DIEs for a secondary CU into memory.
6298 This is also used when rereading a primary CU with load_all_dies. */
6301 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
6303 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6304 load_partial_comp_unit_reader
, NULL
);
6308 read_comp_units_from_section (struct objfile
*objfile
,
6309 struct dwarf2_section_info
*section
,
6310 unsigned int is_dwz
,
6313 struct dwarf2_per_cu_data
***all_comp_units
)
6315 const gdb_byte
*info_ptr
;
6316 bfd
*abfd
= get_section_bfd_owner (section
);
6318 if (dwarf2_read_debug
)
6319 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
6320 get_section_name (section
),
6321 get_section_file_name (section
));
6323 dwarf2_read_section (objfile
, section
);
6325 info_ptr
= section
->buffer
;
6327 while (info_ptr
< section
->buffer
+ section
->size
)
6329 unsigned int length
, initial_length_size
;
6330 struct dwarf2_per_cu_data
*this_cu
;
6333 offset
.sect_off
= info_ptr
- section
->buffer
;
6335 /* Read just enough information to find out where the next
6336 compilation unit is. */
6337 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6339 /* Save the compilation unit for later lookup. */
6340 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
6341 sizeof (struct dwarf2_per_cu_data
));
6342 memset (this_cu
, 0, sizeof (*this_cu
));
6343 this_cu
->offset
= offset
;
6344 this_cu
->length
= length
+ initial_length_size
;
6345 this_cu
->is_dwz
= is_dwz
;
6346 this_cu
->objfile
= objfile
;
6347 this_cu
->section
= section
;
6349 if (*n_comp_units
== *n_allocated
)
6352 *all_comp_units
= xrealloc (*all_comp_units
,
6354 * sizeof (struct dwarf2_per_cu_data
*));
6356 (*all_comp_units
)[*n_comp_units
] = this_cu
;
6359 info_ptr
= info_ptr
+ this_cu
->length
;
6363 /* Create a list of all compilation units in OBJFILE.
6364 This is only done for -readnow and building partial symtabs. */
6367 create_all_comp_units (struct objfile
*objfile
)
6371 struct dwarf2_per_cu_data
**all_comp_units
;
6372 struct dwz_file
*dwz
;
6376 all_comp_units
= xmalloc (n_allocated
6377 * sizeof (struct dwarf2_per_cu_data
*));
6379 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
6380 &n_allocated
, &n_comp_units
, &all_comp_units
);
6382 dwz
= dwarf2_get_dwz_file ();
6384 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
6385 &n_allocated
, &n_comp_units
,
6388 dwarf2_per_objfile
->all_comp_units
6389 = obstack_alloc (&objfile
->objfile_obstack
,
6390 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
6391 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
6392 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
6393 xfree (all_comp_units
);
6394 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
6397 /* Process all loaded DIEs for compilation unit CU, starting at
6398 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
6399 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
6400 DW_AT_ranges). If NEED_PC is set, then this function will set
6401 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
6402 and record the covered ranges in the addrmap. */
6405 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
6406 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
6408 struct partial_die_info
*pdi
;
6410 /* Now, march along the PDI's, descending into ones which have
6411 interesting children but skipping the children of the other ones,
6412 until we reach the end of the compilation unit. */
6418 fixup_partial_die (pdi
, cu
);
6420 /* Anonymous namespaces or modules have no name but have interesting
6421 children, so we need to look at them. Ditto for anonymous
6424 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
6425 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
6426 || pdi
->tag
== DW_TAG_imported_unit
)
6430 case DW_TAG_subprogram
:
6431 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
6433 case DW_TAG_constant
:
6434 case DW_TAG_variable
:
6435 case DW_TAG_typedef
:
6436 case DW_TAG_union_type
:
6437 if (!pdi
->is_declaration
)
6439 add_partial_symbol (pdi
, cu
);
6442 case DW_TAG_class_type
:
6443 case DW_TAG_interface_type
:
6444 case DW_TAG_structure_type
:
6445 if (!pdi
->is_declaration
)
6447 add_partial_symbol (pdi
, cu
);
6450 case DW_TAG_enumeration_type
:
6451 if (!pdi
->is_declaration
)
6452 add_partial_enumeration (pdi
, cu
);
6454 case DW_TAG_base_type
:
6455 case DW_TAG_subrange_type
:
6456 /* File scope base type definitions are added to the partial
6458 add_partial_symbol (pdi
, cu
);
6460 case DW_TAG_namespace
:
6461 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
6464 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
6466 case DW_TAG_imported_unit
:
6468 struct dwarf2_per_cu_data
*per_cu
;
6470 /* For now we don't handle imported units in type units. */
6471 if (cu
->per_cu
->is_debug_types
)
6473 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6474 " supported in type units [in module %s]"),
6475 objfile_name (cu
->objfile
));
6478 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
6482 /* Go read the partial unit, if needed. */
6483 if (per_cu
->v
.psymtab
== NULL
)
6484 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
6486 VEC_safe_push (dwarf2_per_cu_ptr
,
6487 cu
->per_cu
->imported_symtabs
, per_cu
);
6495 /* If the die has a sibling, skip to the sibling. */
6497 pdi
= pdi
->die_sibling
;
6501 /* Functions used to compute the fully scoped name of a partial DIE.
6503 Normally, this is simple. For C++, the parent DIE's fully scoped
6504 name is concatenated with "::" and the partial DIE's name. For
6505 Java, the same thing occurs except that "." is used instead of "::".
6506 Enumerators are an exception; they use the scope of their parent
6507 enumeration type, i.e. the name of the enumeration type is not
6508 prepended to the enumerator.
6510 There are two complexities. One is DW_AT_specification; in this
6511 case "parent" means the parent of the target of the specification,
6512 instead of the direct parent of the DIE. The other is compilers
6513 which do not emit DW_TAG_namespace; in this case we try to guess
6514 the fully qualified name of structure types from their members'
6515 linkage names. This must be done using the DIE's children rather
6516 than the children of any DW_AT_specification target. We only need
6517 to do this for structures at the top level, i.e. if the target of
6518 any DW_AT_specification (if any; otherwise the DIE itself) does not
6521 /* Compute the scope prefix associated with PDI's parent, in
6522 compilation unit CU. The result will be allocated on CU's
6523 comp_unit_obstack, or a copy of the already allocated PDI->NAME
6524 field. NULL is returned if no prefix is necessary. */
6526 partial_die_parent_scope (struct partial_die_info
*pdi
,
6527 struct dwarf2_cu
*cu
)
6529 const char *grandparent_scope
;
6530 struct partial_die_info
*parent
, *real_pdi
;
6532 /* We need to look at our parent DIE; if we have a DW_AT_specification,
6533 then this means the parent of the specification DIE. */
6536 while (real_pdi
->has_specification
)
6537 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
6538 real_pdi
->spec_is_dwz
, cu
);
6540 parent
= real_pdi
->die_parent
;
6544 if (parent
->scope_set
)
6545 return parent
->scope
;
6547 fixup_partial_die (parent
, cu
);
6549 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
6551 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
6552 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
6553 Work around this problem here. */
6554 if (cu
->language
== language_cplus
6555 && parent
->tag
== DW_TAG_namespace
6556 && strcmp (parent
->name
, "::") == 0
6557 && grandparent_scope
== NULL
)
6559 parent
->scope
= NULL
;
6560 parent
->scope_set
= 1;
6564 if (pdi
->tag
== DW_TAG_enumerator
)
6565 /* Enumerators should not get the name of the enumeration as a prefix. */
6566 parent
->scope
= grandparent_scope
;
6567 else if (parent
->tag
== DW_TAG_namespace
6568 || parent
->tag
== DW_TAG_module
6569 || parent
->tag
== DW_TAG_structure_type
6570 || parent
->tag
== DW_TAG_class_type
6571 || parent
->tag
== DW_TAG_interface_type
6572 || parent
->tag
== DW_TAG_union_type
6573 || parent
->tag
== DW_TAG_enumeration_type
)
6575 if (grandparent_scope
== NULL
)
6576 parent
->scope
= parent
->name
;
6578 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
6580 parent
->name
, 0, cu
);
6584 /* FIXME drow/2004-04-01: What should we be doing with
6585 function-local names? For partial symbols, we should probably be
6587 complaint (&symfile_complaints
,
6588 _("unhandled containing DIE tag %d for DIE at %d"),
6589 parent
->tag
, pdi
->offset
.sect_off
);
6590 parent
->scope
= grandparent_scope
;
6593 parent
->scope_set
= 1;
6594 return parent
->scope
;
6597 /* Return the fully scoped name associated with PDI, from compilation unit
6598 CU. The result will be allocated with malloc. */
6601 partial_die_full_name (struct partial_die_info
*pdi
,
6602 struct dwarf2_cu
*cu
)
6604 const char *parent_scope
;
6606 /* If this is a template instantiation, we can not work out the
6607 template arguments from partial DIEs. So, unfortunately, we have
6608 to go through the full DIEs. At least any work we do building
6609 types here will be reused if full symbols are loaded later. */
6610 if (pdi
->has_template_arguments
)
6612 fixup_partial_die (pdi
, cu
);
6614 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
6616 struct die_info
*die
;
6617 struct attribute attr
;
6618 struct dwarf2_cu
*ref_cu
= cu
;
6620 /* DW_FORM_ref_addr is using section offset. */
6622 attr
.form
= DW_FORM_ref_addr
;
6623 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
6624 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
6626 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
6630 parent_scope
= partial_die_parent_scope (pdi
, cu
);
6631 if (parent_scope
== NULL
)
6634 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
6638 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
6640 struct objfile
*objfile
= cu
->objfile
;
6642 const char *actual_name
= NULL
;
6644 char *built_actual_name
;
6646 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6648 built_actual_name
= partial_die_full_name (pdi
, cu
);
6649 if (built_actual_name
!= NULL
)
6650 actual_name
= built_actual_name
;
6652 if (actual_name
== NULL
)
6653 actual_name
= pdi
->name
;
6657 case DW_TAG_subprogram
:
6658 if (pdi
->is_external
|| cu
->language
== language_ada
)
6660 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
6661 of the global scope. But in Ada, we want to be able to access
6662 nested procedures globally. So all Ada subprograms are stored
6663 in the global scope. */
6664 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
6665 mst_text, objfile); */
6666 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6667 built_actual_name
!= NULL
,
6668 VAR_DOMAIN
, LOC_BLOCK
,
6669 &objfile
->global_psymbols
,
6670 0, pdi
->lowpc
+ baseaddr
,
6671 cu
->language
, objfile
);
6675 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
6676 mst_file_text, objfile); */
6677 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6678 built_actual_name
!= NULL
,
6679 VAR_DOMAIN
, LOC_BLOCK
,
6680 &objfile
->static_psymbols
,
6681 0, pdi
->lowpc
+ baseaddr
,
6682 cu
->language
, objfile
);
6685 case DW_TAG_constant
:
6687 struct psymbol_allocation_list
*list
;
6689 if (pdi
->is_external
)
6690 list
= &objfile
->global_psymbols
;
6692 list
= &objfile
->static_psymbols
;
6693 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6694 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
6695 list
, 0, 0, cu
->language
, objfile
);
6698 case DW_TAG_variable
:
6700 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
6704 && !dwarf2_per_objfile
->has_section_at_zero
)
6706 /* A global or static variable may also have been stripped
6707 out by the linker if unused, in which case its address
6708 will be nullified; do not add such variables into partial
6709 symbol table then. */
6711 else if (pdi
->is_external
)
6714 Don't enter into the minimal symbol tables as there is
6715 a minimal symbol table entry from the ELF symbols already.
6716 Enter into partial symbol table if it has a location
6717 descriptor or a type.
6718 If the location descriptor is missing, new_symbol will create
6719 a LOC_UNRESOLVED symbol, the address of the variable will then
6720 be determined from the minimal symbol table whenever the variable
6722 The address for the partial symbol table entry is not
6723 used by GDB, but it comes in handy for debugging partial symbol
6726 if (pdi
->d
.locdesc
|| pdi
->has_type
)
6727 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6728 built_actual_name
!= NULL
,
6729 VAR_DOMAIN
, LOC_STATIC
,
6730 &objfile
->global_psymbols
,
6732 cu
->language
, objfile
);
6736 /* Static Variable. Skip symbols without location descriptors. */
6737 if (pdi
->d
.locdesc
== NULL
)
6739 xfree (built_actual_name
);
6742 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
6743 mst_file_data, objfile); */
6744 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6745 built_actual_name
!= NULL
,
6746 VAR_DOMAIN
, LOC_STATIC
,
6747 &objfile
->static_psymbols
,
6749 cu
->language
, objfile
);
6752 case DW_TAG_typedef
:
6753 case DW_TAG_base_type
:
6754 case DW_TAG_subrange_type
:
6755 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6756 built_actual_name
!= NULL
,
6757 VAR_DOMAIN
, LOC_TYPEDEF
,
6758 &objfile
->static_psymbols
,
6759 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6761 case DW_TAG_namespace
:
6762 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6763 built_actual_name
!= NULL
,
6764 VAR_DOMAIN
, LOC_TYPEDEF
,
6765 &objfile
->global_psymbols
,
6766 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6768 case DW_TAG_class_type
:
6769 case DW_TAG_interface_type
:
6770 case DW_TAG_structure_type
:
6771 case DW_TAG_union_type
:
6772 case DW_TAG_enumeration_type
:
6773 /* Skip external references. The DWARF standard says in the section
6774 about "Structure, Union, and Class Type Entries": "An incomplete
6775 structure, union or class type is represented by a structure,
6776 union or class entry that does not have a byte size attribute
6777 and that has a DW_AT_declaration attribute." */
6778 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
6780 xfree (built_actual_name
);
6784 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
6785 static vs. global. */
6786 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6787 built_actual_name
!= NULL
,
6788 STRUCT_DOMAIN
, LOC_TYPEDEF
,
6789 (cu
->language
== language_cplus
6790 || cu
->language
== language_java
)
6791 ? &objfile
->global_psymbols
6792 : &objfile
->static_psymbols
,
6793 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6796 case DW_TAG_enumerator
:
6797 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6798 built_actual_name
!= NULL
,
6799 VAR_DOMAIN
, LOC_CONST
,
6800 (cu
->language
== language_cplus
6801 || cu
->language
== language_java
)
6802 ? &objfile
->global_psymbols
6803 : &objfile
->static_psymbols
,
6804 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6810 xfree (built_actual_name
);
6813 /* Read a partial die corresponding to a namespace; also, add a symbol
6814 corresponding to that namespace to the symbol table. NAMESPACE is
6815 the name of the enclosing namespace. */
6818 add_partial_namespace (struct partial_die_info
*pdi
,
6819 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6820 int need_pc
, struct dwarf2_cu
*cu
)
6822 /* Add a symbol for the namespace. */
6824 add_partial_symbol (pdi
, cu
);
6826 /* Now scan partial symbols in that namespace. */
6828 if (pdi
->has_children
)
6829 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6832 /* Read a partial die corresponding to a Fortran module. */
6835 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
6836 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
6838 /* Now scan partial symbols in that module. */
6840 if (pdi
->has_children
)
6841 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6844 /* Read a partial die corresponding to a subprogram and create a partial
6845 symbol for that subprogram. When the CU language allows it, this
6846 routine also defines a partial symbol for each nested subprogram
6847 that this subprogram contains.
6849 DIE my also be a lexical block, in which case we simply search
6850 recursively for suprograms defined inside that lexical block.
6851 Again, this is only performed when the CU language allows this
6852 type of definitions. */
6855 add_partial_subprogram (struct partial_die_info
*pdi
,
6856 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6857 int need_pc
, struct dwarf2_cu
*cu
)
6859 if (pdi
->tag
== DW_TAG_subprogram
)
6861 if (pdi
->has_pc_info
)
6863 if (pdi
->lowpc
< *lowpc
)
6864 *lowpc
= pdi
->lowpc
;
6865 if (pdi
->highpc
> *highpc
)
6866 *highpc
= pdi
->highpc
;
6870 struct objfile
*objfile
= cu
->objfile
;
6872 baseaddr
= ANOFFSET (objfile
->section_offsets
,
6873 SECT_OFF_TEXT (objfile
));
6874 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6875 pdi
->lowpc
+ baseaddr
,
6876 pdi
->highpc
- 1 + baseaddr
,
6877 cu
->per_cu
->v
.psymtab
);
6881 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
6883 if (!pdi
->is_declaration
)
6884 /* Ignore subprogram DIEs that do not have a name, they are
6885 illegal. Do not emit a complaint at this point, we will
6886 do so when we convert this psymtab into a symtab. */
6888 add_partial_symbol (pdi
, cu
);
6892 if (! pdi
->has_children
)
6895 if (cu
->language
== language_ada
)
6897 pdi
= pdi
->die_child
;
6900 fixup_partial_die (pdi
, cu
);
6901 if (pdi
->tag
== DW_TAG_subprogram
6902 || pdi
->tag
== DW_TAG_lexical_block
)
6903 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
6904 pdi
= pdi
->die_sibling
;
6909 /* Read a partial die corresponding to an enumeration type. */
6912 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
6913 struct dwarf2_cu
*cu
)
6915 struct partial_die_info
*pdi
;
6917 if (enum_pdi
->name
!= NULL
)
6918 add_partial_symbol (enum_pdi
, cu
);
6920 pdi
= enum_pdi
->die_child
;
6923 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
6924 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6926 add_partial_symbol (pdi
, cu
);
6927 pdi
= pdi
->die_sibling
;
6931 /* Return the initial uleb128 in the die at INFO_PTR. */
6934 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
6936 unsigned int bytes_read
;
6938 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6941 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
6942 Return the corresponding abbrev, or NULL if the number is zero (indicating
6943 an empty DIE). In either case *BYTES_READ will be set to the length of
6944 the initial number. */
6946 static struct abbrev_info
*
6947 peek_die_abbrev (const gdb_byte
*info_ptr
, unsigned int *bytes_read
,
6948 struct dwarf2_cu
*cu
)
6950 bfd
*abfd
= cu
->objfile
->obfd
;
6951 unsigned int abbrev_number
;
6952 struct abbrev_info
*abbrev
;
6954 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
6956 if (abbrev_number
== 0)
6959 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
6962 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
6963 abbrev_number
, bfd_get_filename (abfd
));
6969 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6970 Returns a pointer to the end of a series of DIEs, terminated by an empty
6971 DIE. Any children of the skipped DIEs will also be skipped. */
6973 static const gdb_byte
*
6974 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
6976 struct dwarf2_cu
*cu
= reader
->cu
;
6977 struct abbrev_info
*abbrev
;
6978 unsigned int bytes_read
;
6982 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6984 return info_ptr
+ bytes_read
;
6986 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
6990 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6991 INFO_PTR should point just after the initial uleb128 of a DIE, and the
6992 abbrev corresponding to that skipped uleb128 should be passed in
6993 ABBREV. Returns a pointer to this DIE's sibling, skipping any
6996 static const gdb_byte
*
6997 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
6998 struct abbrev_info
*abbrev
)
7000 unsigned int bytes_read
;
7001 struct attribute attr
;
7002 bfd
*abfd
= reader
->abfd
;
7003 struct dwarf2_cu
*cu
= reader
->cu
;
7004 const gdb_byte
*buffer
= reader
->buffer
;
7005 const gdb_byte
*buffer_end
= reader
->buffer_end
;
7006 const gdb_byte
*start_info_ptr
= info_ptr
;
7007 unsigned int form
, i
;
7009 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
7011 /* The only abbrev we care about is DW_AT_sibling. */
7012 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
7014 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
7015 if (attr
.form
== DW_FORM_ref_addr
)
7016 complaint (&symfile_complaints
,
7017 _("ignoring absolute DW_AT_sibling"));
7019 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
7022 /* If it isn't DW_AT_sibling, skip this attribute. */
7023 form
= abbrev
->attrs
[i
].form
;
7027 case DW_FORM_ref_addr
:
7028 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
7029 and later it is offset sized. */
7030 if (cu
->header
.version
== 2)
7031 info_ptr
+= cu
->header
.addr_size
;
7033 info_ptr
+= cu
->header
.offset_size
;
7035 case DW_FORM_GNU_ref_alt
:
7036 info_ptr
+= cu
->header
.offset_size
;
7039 info_ptr
+= cu
->header
.addr_size
;
7046 case DW_FORM_flag_present
:
7058 case DW_FORM_ref_sig8
:
7061 case DW_FORM_string
:
7062 read_direct_string (abfd
, info_ptr
, &bytes_read
);
7063 info_ptr
+= bytes_read
;
7065 case DW_FORM_sec_offset
:
7067 case DW_FORM_GNU_strp_alt
:
7068 info_ptr
+= cu
->header
.offset_size
;
7070 case DW_FORM_exprloc
:
7072 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7073 info_ptr
+= bytes_read
;
7075 case DW_FORM_block1
:
7076 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
7078 case DW_FORM_block2
:
7079 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
7081 case DW_FORM_block4
:
7082 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
7086 case DW_FORM_ref_udata
:
7087 case DW_FORM_GNU_addr_index
:
7088 case DW_FORM_GNU_str_index
:
7089 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
7091 case DW_FORM_indirect
:
7092 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7093 info_ptr
+= bytes_read
;
7094 /* We need to continue parsing from here, so just go back to
7096 goto skip_attribute
;
7099 error (_("Dwarf Error: Cannot handle %s "
7100 "in DWARF reader [in module %s]"),
7101 dwarf_form_name (form
),
7102 bfd_get_filename (abfd
));
7106 if (abbrev
->has_children
)
7107 return skip_children (reader
, info_ptr
);
7112 /* Locate ORIG_PDI's sibling.
7113 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
7115 static const gdb_byte
*
7116 locate_pdi_sibling (const struct die_reader_specs
*reader
,
7117 struct partial_die_info
*orig_pdi
,
7118 const gdb_byte
*info_ptr
)
7120 /* Do we know the sibling already? */
7122 if (orig_pdi
->sibling
)
7123 return orig_pdi
->sibling
;
7125 /* Are there any children to deal with? */
7127 if (!orig_pdi
->has_children
)
7130 /* Skip the children the long way. */
7132 return skip_children (reader
, info_ptr
);
7135 /* Expand this partial symbol table into a full symbol table. SELF is
7139 dwarf2_read_symtab (struct partial_symtab
*self
,
7140 struct objfile
*objfile
)
7144 warning (_("bug: psymtab for %s is already read in."),
7151 printf_filtered (_("Reading in symbols for %s..."),
7153 gdb_flush (gdb_stdout
);
7156 /* Restore our global data. */
7157 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
7159 /* If this psymtab is constructed from a debug-only objfile, the
7160 has_section_at_zero flag will not necessarily be correct. We
7161 can get the correct value for this flag by looking at the data
7162 associated with the (presumably stripped) associated objfile. */
7163 if (objfile
->separate_debug_objfile_backlink
)
7165 struct dwarf2_per_objfile
*dpo_backlink
7166 = objfile_data (objfile
->separate_debug_objfile_backlink
,
7167 dwarf2_objfile_data_key
);
7169 dwarf2_per_objfile
->has_section_at_zero
7170 = dpo_backlink
->has_section_at_zero
;
7173 dwarf2_per_objfile
->reading_partial_symbols
= 0;
7175 psymtab_to_symtab_1 (self
);
7177 /* Finish up the debug error message. */
7179 printf_filtered (_("done.\n"));
7182 process_cu_includes ();
7185 /* Reading in full CUs. */
7187 /* Add PER_CU to the queue. */
7190 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
7191 enum language pretend_language
)
7193 struct dwarf2_queue_item
*item
;
7196 item
= xmalloc (sizeof (*item
));
7197 item
->per_cu
= per_cu
;
7198 item
->pretend_language
= pretend_language
;
7201 if (dwarf2_queue
== NULL
)
7202 dwarf2_queue
= item
;
7204 dwarf2_queue_tail
->next
= item
;
7206 dwarf2_queue_tail
= item
;
7209 /* If PER_CU is not yet queued, add it to the queue.
7210 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
7212 The result is non-zero if PER_CU was queued, otherwise the result is zero
7213 meaning either PER_CU is already queued or it is already loaded.
7215 N.B. There is an invariant here that if a CU is queued then it is loaded.
7216 The caller is required to load PER_CU if we return non-zero. */
7219 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
7220 struct dwarf2_per_cu_data
*per_cu
,
7221 enum language pretend_language
)
7223 /* We may arrive here during partial symbol reading, if we need full
7224 DIEs to process an unusual case (e.g. template arguments). Do
7225 not queue PER_CU, just tell our caller to load its DIEs. */
7226 if (dwarf2_per_objfile
->reading_partial_symbols
)
7228 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
7233 /* Mark the dependence relation so that we don't flush PER_CU
7235 if (dependent_cu
!= NULL
)
7236 dwarf2_add_dependence (dependent_cu
, per_cu
);
7238 /* If it's already on the queue, we have nothing to do. */
7242 /* If the compilation unit is already loaded, just mark it as
7244 if (per_cu
->cu
!= NULL
)
7246 per_cu
->cu
->last_used
= 0;
7250 /* Add it to the queue. */
7251 queue_comp_unit (per_cu
, pretend_language
);
7256 /* Process the queue. */
7259 process_queue (void)
7261 struct dwarf2_queue_item
*item
, *next_item
;
7263 if (dwarf2_read_debug
)
7265 fprintf_unfiltered (gdb_stdlog
,
7266 "Expanding one or more symtabs of objfile %s ...\n",
7267 objfile_name (dwarf2_per_objfile
->objfile
));
7270 /* The queue starts out with one item, but following a DIE reference
7271 may load a new CU, adding it to the end of the queue. */
7272 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
7274 if (dwarf2_per_objfile
->using_index
7275 ? !item
->per_cu
->v
.quick
->symtab
7276 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
7278 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
7281 if (per_cu
->is_debug_types
)
7283 struct signatured_type
*sig_type
=
7284 (struct signatured_type
*) per_cu
;
7286 sprintf (buf
, "TU %s at offset 0x%x",
7287 hex_string (sig_type
->signature
), per_cu
->offset
.sect_off
);
7290 sprintf (buf
, "CU at offset 0x%x", per_cu
->offset
.sect_off
);
7292 if (dwarf2_read_debug
)
7293 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
7295 if (per_cu
->is_debug_types
)
7296 process_full_type_unit (per_cu
, item
->pretend_language
);
7298 process_full_comp_unit (per_cu
, item
->pretend_language
);
7300 if (dwarf2_read_debug
)
7301 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
7304 item
->per_cu
->queued
= 0;
7305 next_item
= item
->next
;
7309 dwarf2_queue_tail
= NULL
;
7311 if (dwarf2_read_debug
)
7313 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
7314 objfile_name (dwarf2_per_objfile
->objfile
));
7318 /* Free all allocated queue entries. This function only releases anything if
7319 an error was thrown; if the queue was processed then it would have been
7320 freed as we went along. */
7323 dwarf2_release_queue (void *dummy
)
7325 struct dwarf2_queue_item
*item
, *last
;
7327 item
= dwarf2_queue
;
7330 /* Anything still marked queued is likely to be in an
7331 inconsistent state, so discard it. */
7332 if (item
->per_cu
->queued
)
7334 if (item
->per_cu
->cu
!= NULL
)
7335 free_one_cached_comp_unit (item
->per_cu
);
7336 item
->per_cu
->queued
= 0;
7344 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
7347 /* Read in full symbols for PST, and anything it depends on. */
7350 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
7352 struct dwarf2_per_cu_data
*per_cu
;
7358 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
7359 if (!pst
->dependencies
[i
]->readin
7360 && pst
->dependencies
[i
]->user
== NULL
)
7362 /* Inform about additional files that need to be read in. */
7365 /* FIXME: i18n: Need to make this a single string. */
7366 fputs_filtered (" ", gdb_stdout
);
7368 fputs_filtered ("and ", gdb_stdout
);
7370 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
7371 wrap_here (""); /* Flush output. */
7372 gdb_flush (gdb_stdout
);
7374 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
7377 per_cu
= pst
->read_symtab_private
;
7381 /* It's an include file, no symbols to read for it.
7382 Everything is in the parent symtab. */
7387 dw2_do_instantiate_symtab (per_cu
);
7390 /* Trivial hash function for die_info: the hash value of a DIE
7391 is its offset in .debug_info for this objfile. */
7394 die_hash (const void *item
)
7396 const struct die_info
*die
= item
;
7398 return die
->offset
.sect_off
;
7401 /* Trivial comparison function for die_info structures: two DIEs
7402 are equal if they have the same offset. */
7405 die_eq (const void *item_lhs
, const void *item_rhs
)
7407 const struct die_info
*die_lhs
= item_lhs
;
7408 const struct die_info
*die_rhs
= item_rhs
;
7410 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
7413 /* die_reader_func for load_full_comp_unit.
7414 This is identical to read_signatured_type_reader,
7415 but is kept separate for now. */
7418 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
7419 const gdb_byte
*info_ptr
,
7420 struct die_info
*comp_unit_die
,
7424 struct dwarf2_cu
*cu
= reader
->cu
;
7425 enum language
*language_ptr
= data
;
7427 gdb_assert (cu
->die_hash
== NULL
);
7429 htab_create_alloc_ex (cu
->header
.length
/ 12,
7433 &cu
->comp_unit_obstack
,
7434 hashtab_obstack_allocate
,
7435 dummy_obstack_deallocate
);
7438 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
7439 &info_ptr
, comp_unit_die
);
7440 cu
->dies
= comp_unit_die
;
7441 /* comp_unit_die is not stored in die_hash, no need. */
7443 /* We try not to read any attributes in this function, because not
7444 all CUs needed for references have been loaded yet, and symbol
7445 table processing isn't initialized. But we have to set the CU language,
7446 or we won't be able to build types correctly.
7447 Similarly, if we do not read the producer, we can not apply
7448 producer-specific interpretation. */
7449 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
7452 /* Load the DIEs associated with PER_CU into memory. */
7455 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7456 enum language pretend_language
)
7458 gdb_assert (! this_cu
->is_debug_types
);
7460 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
7461 load_full_comp_unit_reader
, &pretend_language
);
7464 /* Add a DIE to the delayed physname list. */
7467 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
7468 const char *name
, struct die_info
*die
,
7469 struct dwarf2_cu
*cu
)
7471 struct delayed_method_info mi
;
7473 mi
.fnfield_index
= fnfield_index
;
7477 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
7480 /* A cleanup for freeing the delayed method list. */
7483 free_delayed_list (void *ptr
)
7485 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
7486 if (cu
->method_list
!= NULL
)
7488 VEC_free (delayed_method_info
, cu
->method_list
);
7489 cu
->method_list
= NULL
;
7493 /* Compute the physnames of any methods on the CU's method list.
7495 The computation of method physnames is delayed in order to avoid the
7496 (bad) condition that one of the method's formal parameters is of an as yet
7500 compute_delayed_physnames (struct dwarf2_cu
*cu
)
7503 struct delayed_method_info
*mi
;
7504 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
7506 const char *physname
;
7507 struct fn_fieldlist
*fn_flp
7508 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
7509 physname
= dwarf2_physname (mi
->name
, mi
->die
, cu
);
7510 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
7514 /* Go objects should be embedded in a DW_TAG_module DIE,
7515 and it's not clear if/how imported objects will appear.
7516 To keep Go support simple until that's worked out,
7517 go back through what we've read and create something usable.
7518 We could do this while processing each DIE, and feels kinda cleaner,
7519 but that way is more invasive.
7520 This is to, for example, allow the user to type "p var" or "b main"
7521 without having to specify the package name, and allow lookups
7522 of module.object to work in contexts that use the expression
7526 fixup_go_packaging (struct dwarf2_cu
*cu
)
7528 char *package_name
= NULL
;
7529 struct pending
*list
;
7532 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
7534 for (i
= 0; i
< list
->nsyms
; ++i
)
7536 struct symbol
*sym
= list
->symbol
[i
];
7538 if (SYMBOL_LANGUAGE (sym
) == language_go
7539 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
7541 char *this_package_name
= go_symbol_package_name (sym
);
7543 if (this_package_name
== NULL
)
7545 if (package_name
== NULL
)
7546 package_name
= this_package_name
;
7549 if (strcmp (package_name
, this_package_name
) != 0)
7550 complaint (&symfile_complaints
,
7551 _("Symtab %s has objects from two different Go packages: %s and %s"),
7552 (SYMBOL_SYMTAB (sym
)
7553 ? symtab_to_filename_for_display (SYMBOL_SYMTAB (sym
))
7554 : objfile_name (cu
->objfile
)),
7555 this_package_name
, package_name
);
7556 xfree (this_package_name
);
7562 if (package_name
!= NULL
)
7564 struct objfile
*objfile
= cu
->objfile
;
7565 const char *saved_package_name
= obstack_copy0 (&objfile
->objfile_obstack
,
7567 strlen (package_name
));
7568 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
7569 saved_package_name
, objfile
);
7572 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7574 sym
= allocate_symbol (objfile
);
7575 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
7576 SYMBOL_SET_NAMES (sym
, saved_package_name
,
7577 strlen (saved_package_name
), 0, objfile
);
7578 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
7579 e.g., "main" finds the "main" module and not C's main(). */
7580 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7581 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
7582 SYMBOL_TYPE (sym
) = type
;
7584 add_symbol_to_list (sym
, &global_symbols
);
7586 xfree (package_name
);
7590 /* Return the symtab for PER_CU. This works properly regardless of
7591 whether we're using the index or psymtabs. */
7593 static struct symtab
*
7594 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
7596 return (dwarf2_per_objfile
->using_index
7597 ? per_cu
->v
.quick
->symtab
7598 : per_cu
->v
.psymtab
->symtab
);
7601 /* A helper function for computing the list of all symbol tables
7602 included by PER_CU. */
7605 recursively_compute_inclusions (VEC (symtab_ptr
) **result
,
7606 htab_t all_children
, htab_t all_type_symtabs
,
7607 struct dwarf2_per_cu_data
*per_cu
,
7608 struct symtab
*immediate_parent
)
7612 struct symtab
*symtab
;
7613 struct dwarf2_per_cu_data
*iter
;
7615 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
7618 /* This inclusion and its children have been processed. */
7623 /* Only add a CU if it has a symbol table. */
7624 symtab
= get_symtab (per_cu
);
7627 /* If this is a type unit only add its symbol table if we haven't
7628 seen it yet (type unit per_cu's can share symtabs). */
7629 if (per_cu
->is_debug_types
)
7631 slot
= htab_find_slot (all_type_symtabs
, symtab
, INSERT
);
7635 VEC_safe_push (symtab_ptr
, *result
, symtab
);
7636 if (symtab
->user
== NULL
)
7637 symtab
->user
= immediate_parent
;
7642 VEC_safe_push (symtab_ptr
, *result
, symtab
);
7643 if (symtab
->user
== NULL
)
7644 symtab
->user
= immediate_parent
;
7649 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
7652 recursively_compute_inclusions (result
, all_children
,
7653 all_type_symtabs
, iter
, symtab
);
7657 /* Compute the symtab 'includes' fields for the symtab related to
7661 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
7663 gdb_assert (! per_cu
->is_debug_types
);
7665 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
7668 struct dwarf2_per_cu_data
*per_cu_iter
;
7669 struct symtab
*symtab_iter
;
7670 VEC (symtab_ptr
) *result_symtabs
= NULL
;
7671 htab_t all_children
, all_type_symtabs
;
7672 struct symtab
*symtab
= get_symtab (per_cu
);
7674 /* If we don't have a symtab, we can just skip this case. */
7678 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
7679 NULL
, xcalloc
, xfree
);
7680 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
7681 NULL
, xcalloc
, xfree
);
7684 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
7688 recursively_compute_inclusions (&result_symtabs
, all_children
,
7689 all_type_symtabs
, per_cu_iter
,
7693 /* Now we have a transitive closure of all the included symtabs. */
7694 len
= VEC_length (symtab_ptr
, result_symtabs
);
7696 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
7697 (len
+ 1) * sizeof (struct symtab
*));
7699 VEC_iterate (symtab_ptr
, result_symtabs
, ix
, symtab_iter
);
7701 symtab
->includes
[ix
] = symtab_iter
;
7702 symtab
->includes
[len
] = NULL
;
7704 VEC_free (symtab_ptr
, result_symtabs
);
7705 htab_delete (all_children
);
7706 htab_delete (all_type_symtabs
);
7710 /* Compute the 'includes' field for the symtabs of all the CUs we just
7714 process_cu_includes (void)
7717 struct dwarf2_per_cu_data
*iter
;
7720 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
7724 if (! iter
->is_debug_types
)
7725 compute_symtab_includes (iter
);
7728 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
7731 /* Generate full symbol information for PER_CU, whose DIEs have
7732 already been loaded into memory. */
7735 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
7736 enum language pretend_language
)
7738 struct dwarf2_cu
*cu
= per_cu
->cu
;
7739 struct objfile
*objfile
= per_cu
->objfile
;
7740 CORE_ADDR lowpc
, highpc
;
7741 struct symtab
*symtab
;
7742 struct cleanup
*back_to
, *delayed_list_cleanup
;
7744 struct block
*static_block
;
7746 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7749 back_to
= make_cleanup (really_free_pendings
, NULL
);
7750 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
7752 cu
->list_in_scope
= &file_symbols
;
7754 cu
->language
= pretend_language
;
7755 cu
->language_defn
= language_def (cu
->language
);
7757 /* Do line number decoding in read_file_scope () */
7758 process_die (cu
->dies
, cu
);
7760 /* For now fudge the Go package. */
7761 if (cu
->language
== language_go
)
7762 fixup_go_packaging (cu
);
7764 /* Now that we have processed all the DIEs in the CU, all the types
7765 should be complete, and it should now be safe to compute all of the
7767 compute_delayed_physnames (cu
);
7768 do_cleanups (delayed_list_cleanup
);
7770 /* Some compilers don't define a DW_AT_high_pc attribute for the
7771 compilation unit. If the DW_AT_high_pc is missing, synthesize
7772 it, by scanning the DIE's below the compilation unit. */
7773 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
7776 = end_symtab_get_static_block (highpc
+ baseaddr
, objfile
, 0, 1);
7778 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
7779 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
7780 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
7781 addrmap to help ensure it has an accurate map of pc values belonging to
7783 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
7785 symtab
= end_symtab_from_static_block (static_block
, objfile
,
7786 SECT_OFF_TEXT (objfile
), 0);
7790 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
7792 /* Set symtab language to language from DW_AT_language. If the
7793 compilation is from a C file generated by language preprocessors, do
7794 not set the language if it was already deduced by start_subfile. */
7795 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
7796 symtab
->language
= cu
->language
;
7798 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
7799 produce DW_AT_location with location lists but it can be possibly
7800 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
7801 there were bugs in prologue debug info, fixed later in GCC-4.5
7802 by "unwind info for epilogues" patch (which is not directly related).
7804 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
7805 needed, it would be wrong due to missing DW_AT_producer there.
7807 Still one can confuse GDB by using non-standard GCC compilation
7808 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
7810 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
7811 symtab
->locations_valid
= 1;
7813 if (gcc_4_minor
>= 5)
7814 symtab
->epilogue_unwind_valid
= 1;
7816 symtab
->call_site_htab
= cu
->call_site_htab
;
7819 if (dwarf2_per_objfile
->using_index
)
7820 per_cu
->v
.quick
->symtab
= symtab
;
7823 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7824 pst
->symtab
= symtab
;
7828 /* Push it for inclusion processing later. */
7829 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
7831 do_cleanups (back_to
);
7834 /* Generate full symbol information for type unit PER_CU, whose DIEs have
7835 already been loaded into memory. */
7838 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
7839 enum language pretend_language
)
7841 struct dwarf2_cu
*cu
= per_cu
->cu
;
7842 struct objfile
*objfile
= per_cu
->objfile
;
7843 struct symtab
*symtab
;
7844 struct cleanup
*back_to
, *delayed_list_cleanup
;
7845 struct signatured_type
*sig_type
;
7847 gdb_assert (per_cu
->is_debug_types
);
7848 sig_type
= (struct signatured_type
*) per_cu
;
7851 back_to
= make_cleanup (really_free_pendings
, NULL
);
7852 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
7854 cu
->list_in_scope
= &file_symbols
;
7856 cu
->language
= pretend_language
;
7857 cu
->language_defn
= language_def (cu
->language
);
7859 /* The symbol tables are set up in read_type_unit_scope. */
7860 process_die (cu
->dies
, cu
);
7862 /* For now fudge the Go package. */
7863 if (cu
->language
== language_go
)
7864 fixup_go_packaging (cu
);
7866 /* Now that we have processed all the DIEs in the CU, all the types
7867 should be complete, and it should now be safe to compute all of the
7869 compute_delayed_physnames (cu
);
7870 do_cleanups (delayed_list_cleanup
);
7872 /* TUs share symbol tables.
7873 If this is the first TU to use this symtab, complete the construction
7874 of it with end_expandable_symtab. Otherwise, complete the addition of
7875 this TU's symbols to the existing symtab. */
7876 if (sig_type
->type_unit_group
->primary_symtab
== NULL
)
7878 symtab
= end_expandable_symtab (0, objfile
, SECT_OFF_TEXT (objfile
));
7879 sig_type
->type_unit_group
->primary_symtab
= symtab
;
7883 /* Set symtab language to language from DW_AT_language. If the
7884 compilation is from a C file generated by language preprocessors,
7885 do not set the language if it was already deduced by
7887 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
7888 symtab
->language
= cu
->language
;
7893 augment_type_symtab (objfile
,
7894 sig_type
->type_unit_group
->primary_symtab
);
7895 symtab
= sig_type
->type_unit_group
->primary_symtab
;
7898 if (dwarf2_per_objfile
->using_index
)
7899 per_cu
->v
.quick
->symtab
= symtab
;
7902 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7903 pst
->symtab
= symtab
;
7907 do_cleanups (back_to
);
7910 /* Process an imported unit DIE. */
7913 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7915 struct attribute
*attr
;
7917 /* For now we don't handle imported units in type units. */
7918 if (cu
->per_cu
->is_debug_types
)
7920 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7921 " supported in type units [in module %s]"),
7922 objfile_name (cu
->objfile
));
7925 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7928 struct dwarf2_per_cu_data
*per_cu
;
7929 struct symtab
*imported_symtab
;
7933 offset
= dwarf2_get_ref_die_offset (attr
);
7934 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
7935 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
7937 /* If necessary, add it to the queue and load its DIEs. */
7938 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
7939 load_full_comp_unit (per_cu
, cu
->language
);
7941 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
7946 /* Process a die and its children. */
7949 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7953 case DW_TAG_padding
:
7955 case DW_TAG_compile_unit
:
7956 case DW_TAG_partial_unit
:
7957 read_file_scope (die
, cu
);
7959 case DW_TAG_type_unit
:
7960 read_type_unit_scope (die
, cu
);
7962 case DW_TAG_subprogram
:
7963 case DW_TAG_inlined_subroutine
:
7964 read_func_scope (die
, cu
);
7966 case DW_TAG_lexical_block
:
7967 case DW_TAG_try_block
:
7968 case DW_TAG_catch_block
:
7969 read_lexical_block_scope (die
, cu
);
7971 case DW_TAG_GNU_call_site
:
7972 read_call_site_scope (die
, cu
);
7974 case DW_TAG_class_type
:
7975 case DW_TAG_interface_type
:
7976 case DW_TAG_structure_type
:
7977 case DW_TAG_union_type
:
7978 process_structure_scope (die
, cu
);
7980 case DW_TAG_enumeration_type
:
7981 process_enumeration_scope (die
, cu
);
7984 /* These dies have a type, but processing them does not create
7985 a symbol or recurse to process the children. Therefore we can
7986 read them on-demand through read_type_die. */
7987 case DW_TAG_subroutine_type
:
7988 case DW_TAG_set_type
:
7989 case DW_TAG_array_type
:
7990 case DW_TAG_pointer_type
:
7991 case DW_TAG_ptr_to_member_type
:
7992 case DW_TAG_reference_type
:
7993 case DW_TAG_string_type
:
7996 case DW_TAG_base_type
:
7997 case DW_TAG_subrange_type
:
7998 case DW_TAG_typedef
:
7999 /* Add a typedef symbol for the type definition, if it has a
8001 new_symbol (die
, read_type_die (die
, cu
), cu
);
8003 case DW_TAG_common_block
:
8004 read_common_block (die
, cu
);
8006 case DW_TAG_common_inclusion
:
8008 case DW_TAG_namespace
:
8009 cu
->processing_has_namespace_info
= 1;
8010 read_namespace (die
, cu
);
8013 cu
->processing_has_namespace_info
= 1;
8014 read_module (die
, cu
);
8016 case DW_TAG_imported_declaration
:
8017 case DW_TAG_imported_module
:
8018 cu
->processing_has_namespace_info
= 1;
8019 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
8020 || cu
->language
!= language_fortran
))
8021 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
8022 dwarf_tag_name (die
->tag
));
8023 read_import_statement (die
, cu
);
8026 case DW_TAG_imported_unit
:
8027 process_imported_unit_die (die
, cu
);
8031 new_symbol (die
, NULL
, cu
);
8036 /* DWARF name computation. */
8038 /* A helper function for dwarf2_compute_name which determines whether DIE
8039 needs to have the name of the scope prepended to the name listed in the
8043 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8045 struct attribute
*attr
;
8049 case DW_TAG_namespace
:
8050 case DW_TAG_typedef
:
8051 case DW_TAG_class_type
:
8052 case DW_TAG_interface_type
:
8053 case DW_TAG_structure_type
:
8054 case DW_TAG_union_type
:
8055 case DW_TAG_enumeration_type
:
8056 case DW_TAG_enumerator
:
8057 case DW_TAG_subprogram
:
8061 case DW_TAG_variable
:
8062 case DW_TAG_constant
:
8063 /* We only need to prefix "globally" visible variables. These include
8064 any variable marked with DW_AT_external or any variable that
8065 lives in a namespace. [Variables in anonymous namespaces
8066 require prefixing, but they are not DW_AT_external.] */
8068 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
8070 struct dwarf2_cu
*spec_cu
= cu
;
8072 return die_needs_namespace (die_specification (die
, &spec_cu
),
8076 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8077 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
8078 && die
->parent
->tag
!= DW_TAG_module
)
8080 /* A variable in a lexical block of some kind does not need a
8081 namespace, even though in C++ such variables may be external
8082 and have a mangled name. */
8083 if (die
->parent
->tag
== DW_TAG_lexical_block
8084 || die
->parent
->tag
== DW_TAG_try_block
8085 || die
->parent
->tag
== DW_TAG_catch_block
8086 || die
->parent
->tag
== DW_TAG_subprogram
)
8095 /* Retrieve the last character from a mem_file. */
8098 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
8100 char *last_char_p
= (char *) object
;
8103 *last_char_p
= buffer
[length
- 1];
8106 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
8107 compute the physname for the object, which include a method's:
8108 - formal parameters (C++/Java),
8109 - receiver type (Go),
8110 - return type (Java).
8112 The term "physname" is a bit confusing.
8113 For C++, for example, it is the demangled name.
8114 For Go, for example, it's the mangled name.
8116 For Ada, return the DIE's linkage name rather than the fully qualified
8117 name. PHYSNAME is ignored..
8119 The result is allocated on the objfile_obstack and canonicalized. */
8122 dwarf2_compute_name (const char *name
,
8123 struct die_info
*die
, struct dwarf2_cu
*cu
,
8126 struct objfile
*objfile
= cu
->objfile
;
8129 name
= dwarf2_name (die
, cu
);
8131 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
8132 compute it by typename_concat inside GDB. */
8133 if (cu
->language
== language_ada
8134 || (cu
->language
== language_fortran
&& physname
))
8136 /* For Ada unit, we prefer the linkage name over the name, as
8137 the former contains the exported name, which the user expects
8138 to be able to reference. Ideally, we want the user to be able
8139 to reference this entity using either natural or linkage name,
8140 but we haven't started looking at this enhancement yet. */
8141 struct attribute
*attr
;
8143 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
8145 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8146 if (attr
&& DW_STRING (attr
))
8147 return DW_STRING (attr
);
8150 /* These are the only languages we know how to qualify names in. */
8152 && (cu
->language
== language_cplus
|| cu
->language
== language_java
8153 || cu
->language
== language_fortran
))
8155 if (die_needs_namespace (die
, cu
))
8159 struct ui_file
*buf
;
8161 prefix
= determine_prefix (die
, cu
);
8162 buf
= mem_fileopen ();
8163 if (*prefix
!= '\0')
8165 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
8168 fputs_unfiltered (prefixed_name
, buf
);
8169 xfree (prefixed_name
);
8172 fputs_unfiltered (name
, buf
);
8174 /* Template parameters may be specified in the DIE's DW_AT_name, or
8175 as children with DW_TAG_template_type_param or
8176 DW_TAG_value_type_param. If the latter, add them to the name
8177 here. If the name already has template parameters, then
8178 skip this step; some versions of GCC emit both, and
8179 it is more efficient to use the pre-computed name.
8181 Something to keep in mind about this process: it is very
8182 unlikely, or in some cases downright impossible, to produce
8183 something that will match the mangled name of a function.
8184 If the definition of the function has the same debug info,
8185 we should be able to match up with it anyway. But fallbacks
8186 using the minimal symbol, for instance to find a method
8187 implemented in a stripped copy of libstdc++, will not work.
8188 If we do not have debug info for the definition, we will have to
8189 match them up some other way.
8191 When we do name matching there is a related problem with function
8192 templates; two instantiated function templates are allowed to
8193 differ only by their return types, which we do not add here. */
8195 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
8197 struct attribute
*attr
;
8198 struct die_info
*child
;
8201 die
->building_fullname
= 1;
8203 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
8207 const gdb_byte
*bytes
;
8208 struct dwarf2_locexpr_baton
*baton
;
8211 if (child
->tag
!= DW_TAG_template_type_param
8212 && child
->tag
!= DW_TAG_template_value_param
)
8217 fputs_unfiltered ("<", buf
);
8221 fputs_unfiltered (", ", buf
);
8223 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
8226 complaint (&symfile_complaints
,
8227 _("template parameter missing DW_AT_type"));
8228 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
8231 type
= die_type (child
, cu
);
8233 if (child
->tag
== DW_TAG_template_type_param
)
8235 c_print_type (type
, "", buf
, -1, 0, &type_print_raw_options
);
8239 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
8242 complaint (&symfile_complaints
,
8243 _("template parameter missing "
8244 "DW_AT_const_value"));
8245 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
8249 dwarf2_const_value_attr (attr
, type
, name
,
8250 &cu
->comp_unit_obstack
, cu
,
8251 &value
, &bytes
, &baton
);
8253 if (TYPE_NOSIGN (type
))
8254 /* GDB prints characters as NUMBER 'CHAR'. If that's
8255 changed, this can use value_print instead. */
8256 c_printchar (value
, type
, buf
);
8259 struct value_print_options opts
;
8262 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
8266 else if (bytes
!= NULL
)
8268 v
= allocate_value (type
);
8269 memcpy (value_contents_writeable (v
), bytes
,
8270 TYPE_LENGTH (type
));
8273 v
= value_from_longest (type
, value
);
8275 /* Specify decimal so that we do not depend on
8277 get_formatted_print_options (&opts
, 'd');
8279 value_print (v
, buf
, &opts
);
8285 die
->building_fullname
= 0;
8289 /* Close the argument list, with a space if necessary
8290 (nested templates). */
8291 char last_char
= '\0';
8292 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
8293 if (last_char
== '>')
8294 fputs_unfiltered (" >", buf
);
8296 fputs_unfiltered (">", buf
);
8300 /* For Java and C++ methods, append formal parameter type
8301 information, if PHYSNAME. */
8303 if (physname
&& die
->tag
== DW_TAG_subprogram
8304 && (cu
->language
== language_cplus
8305 || cu
->language
== language_java
))
8307 struct type
*type
= read_type_die (die
, cu
);
8309 c_type_print_args (type
, buf
, 1, cu
->language
,
8310 &type_print_raw_options
);
8312 if (cu
->language
== language_java
)
8314 /* For java, we must append the return type to method
8316 if (die
->tag
== DW_TAG_subprogram
)
8317 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
8318 0, 0, &type_print_raw_options
);
8320 else if (cu
->language
== language_cplus
)
8322 /* Assume that an artificial first parameter is
8323 "this", but do not crash if it is not. RealView
8324 marks unnamed (and thus unused) parameters as
8325 artificial; there is no way to differentiate
8327 if (TYPE_NFIELDS (type
) > 0
8328 && TYPE_FIELD_ARTIFICIAL (type
, 0)
8329 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
8330 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
8332 fputs_unfiltered (" const", buf
);
8336 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
8338 ui_file_delete (buf
);
8340 if (cu
->language
== language_cplus
)
8343 = dwarf2_canonicalize_name (name
, cu
,
8344 &objfile
->objfile_obstack
);
8355 /* Return the fully qualified name of DIE, based on its DW_AT_name.
8356 If scope qualifiers are appropriate they will be added. The result
8357 will be allocated on the objfile_obstack, or NULL if the DIE does
8358 not have a name. NAME may either be from a previous call to
8359 dwarf2_name or NULL.
8361 The output string will be canonicalized (if C++/Java). */
8364 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8366 return dwarf2_compute_name (name
, die
, cu
, 0);
8369 /* Construct a physname for the given DIE in CU. NAME may either be
8370 from a previous call to dwarf2_name or NULL. The result will be
8371 allocated on the objfile_objstack or NULL if the DIE does not have a
8374 The output string will be canonicalized (if C++/Java). */
8377 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8379 struct objfile
*objfile
= cu
->objfile
;
8380 struct attribute
*attr
;
8381 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
8382 struct cleanup
*back_to
;
8385 /* In this case dwarf2_compute_name is just a shortcut not building anything
8387 if (!die_needs_namespace (die
, cu
))
8388 return dwarf2_compute_name (name
, die
, cu
, 1);
8390 back_to
= make_cleanup (null_cleanup
, NULL
);
8392 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
8394 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8396 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
8398 if (attr
&& DW_STRING (attr
))
8402 mangled
= DW_STRING (attr
);
8404 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
8405 type. It is easier for GDB users to search for such functions as
8406 `name(params)' than `long name(params)'. In such case the minimal
8407 symbol names do not match the full symbol names but for template
8408 functions there is never a need to look up their definition from their
8409 declaration so the only disadvantage remains the minimal symbol
8410 variant `long name(params)' does not have the proper inferior type.
8413 if (cu
->language
== language_go
)
8415 /* This is a lie, but we already lie to the caller new_symbol_full.
8416 new_symbol_full assumes we return the mangled name.
8417 This just undoes that lie until things are cleaned up. */
8422 demangled
= gdb_demangle (mangled
,
8423 (DMGL_PARAMS
| DMGL_ANSI
8424 | (cu
->language
== language_java
8425 ? DMGL_JAVA
| DMGL_RET_POSTFIX
8430 make_cleanup (xfree
, demangled
);
8440 if (canon
== NULL
|| check_physname
)
8442 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
8444 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
8446 /* It may not mean a bug in GDB. The compiler could also
8447 compute DW_AT_linkage_name incorrectly. But in such case
8448 GDB would need to be bug-to-bug compatible. */
8450 complaint (&symfile_complaints
,
8451 _("Computed physname <%s> does not match demangled <%s> "
8452 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
8453 physname
, canon
, mangled
, die
->offset
.sect_off
,
8454 objfile_name (objfile
));
8456 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
8457 is available here - over computed PHYSNAME. It is safer
8458 against both buggy GDB and buggy compilers. */
8472 retval
= obstack_copy0 (&objfile
->objfile_obstack
, retval
, strlen (retval
));
8474 do_cleanups (back_to
);
8478 /* Read the import statement specified by the given die and record it. */
8481 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
8483 struct objfile
*objfile
= cu
->objfile
;
8484 struct attribute
*import_attr
;
8485 struct die_info
*imported_die
, *child_die
;
8486 struct dwarf2_cu
*imported_cu
;
8487 const char *imported_name
;
8488 const char *imported_name_prefix
;
8489 const char *canonical_name
;
8490 const char *import_alias
;
8491 const char *imported_declaration
= NULL
;
8492 const char *import_prefix
;
8493 VEC (const_char_ptr
) *excludes
= NULL
;
8494 struct cleanup
*cleanups
;
8496 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8497 if (import_attr
== NULL
)
8499 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
8500 dwarf_tag_name (die
->tag
));
8505 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
8506 imported_name
= dwarf2_name (imported_die
, imported_cu
);
8507 if (imported_name
== NULL
)
8509 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
8511 The import in the following code:
8525 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
8526 <52> DW_AT_decl_file : 1
8527 <53> DW_AT_decl_line : 6
8528 <54> DW_AT_import : <0x75>
8529 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
8531 <5b> DW_AT_decl_file : 1
8532 <5c> DW_AT_decl_line : 2
8533 <5d> DW_AT_type : <0x6e>
8535 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
8536 <76> DW_AT_byte_size : 4
8537 <77> DW_AT_encoding : 5 (signed)
8539 imports the wrong die ( 0x75 instead of 0x58 ).
8540 This case will be ignored until the gcc bug is fixed. */
8544 /* Figure out the local name after import. */
8545 import_alias
= dwarf2_name (die
, cu
);
8547 /* Figure out where the statement is being imported to. */
8548 import_prefix
= determine_prefix (die
, cu
);
8550 /* Figure out what the scope of the imported die is and prepend it
8551 to the name of the imported die. */
8552 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
8554 if (imported_die
->tag
!= DW_TAG_namespace
8555 && imported_die
->tag
!= DW_TAG_module
)
8557 imported_declaration
= imported_name
;
8558 canonical_name
= imported_name_prefix
;
8560 else if (strlen (imported_name_prefix
) > 0)
8561 canonical_name
= obconcat (&objfile
->objfile_obstack
,
8562 imported_name_prefix
, "::", imported_name
,
8565 canonical_name
= imported_name
;
8567 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
8569 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
8570 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
8571 child_die
= sibling_die (child_die
))
8573 /* DWARF-4: A Fortran use statement with a “rename list” may be
8574 represented by an imported module entry with an import attribute
8575 referring to the module and owned entries corresponding to those
8576 entities that are renamed as part of being imported. */
8578 if (child_die
->tag
!= DW_TAG_imported_declaration
)
8580 complaint (&symfile_complaints
,
8581 _("child DW_TAG_imported_declaration expected "
8582 "- DIE at 0x%x [in module %s]"),
8583 child_die
->offset
.sect_off
, objfile_name (objfile
));
8587 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
8588 if (import_attr
== NULL
)
8590 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
8591 dwarf_tag_name (child_die
->tag
));
8596 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
8598 imported_name
= dwarf2_name (imported_die
, imported_cu
);
8599 if (imported_name
== NULL
)
8601 complaint (&symfile_complaints
,
8602 _("child DW_TAG_imported_declaration has unknown "
8603 "imported name - DIE at 0x%x [in module %s]"),
8604 child_die
->offset
.sect_off
, objfile_name (objfile
));
8608 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
8610 process_die (child_die
, cu
);
8613 cp_add_using_directive (import_prefix
,
8616 imported_declaration
,
8619 &objfile
->objfile_obstack
);
8621 do_cleanups (cleanups
);
8624 /* Cleanup function for handle_DW_AT_stmt_list. */
8627 free_cu_line_header (void *arg
)
8629 struct dwarf2_cu
*cu
= arg
;
8631 free_line_header (cu
->line_header
);
8632 cu
->line_header
= NULL
;
8635 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
8636 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
8637 this, it was first present in GCC release 4.3.0. */
8640 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
8642 if (!cu
->checked_producer
)
8643 check_producer (cu
);
8645 return cu
->producer_is_gcc_lt_4_3
;
8649 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
8650 const char **name
, const char **comp_dir
)
8652 struct attribute
*attr
;
8657 /* Find the filename. Do not use dwarf2_name here, since the filename
8658 is not a source language identifier. */
8659 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8662 *name
= DW_STRING (attr
);
8665 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
8667 *comp_dir
= DW_STRING (attr
);
8668 else if (producer_is_gcc_lt_4_3 (cu
) && *name
!= NULL
8669 && IS_ABSOLUTE_PATH (*name
))
8671 char *d
= ldirname (*name
);
8675 make_cleanup (xfree
, d
);
8677 if (*comp_dir
!= NULL
)
8679 /* Irix 6.2 native cc prepends <machine>.: to the compilation
8680 directory, get rid of it. */
8681 char *cp
= strchr (*comp_dir
, ':');
8683 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
8688 *name
= "<unknown>";
8691 /* Handle DW_AT_stmt_list for a compilation unit.
8692 DIE is the DW_TAG_compile_unit die for CU.
8693 COMP_DIR is the compilation directory.
8694 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
8697 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
8698 const char *comp_dir
) /* ARI: editCase function */
8700 struct attribute
*attr
;
8702 gdb_assert (! cu
->per_cu
->is_debug_types
);
8704 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
8707 unsigned int line_offset
= DW_UNSND (attr
);
8708 struct line_header
*line_header
8709 = dwarf_decode_line_header (line_offset
, cu
);
8713 cu
->line_header
= line_header
;
8714 make_cleanup (free_cu_line_header
, cu
);
8715 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, 1);
8720 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
8723 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8725 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8726 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
8727 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
8728 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
8729 struct attribute
*attr
;
8730 const char *name
= NULL
;
8731 const char *comp_dir
= NULL
;
8732 struct die_info
*child_die
;
8733 bfd
*abfd
= objfile
->obfd
;
8736 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8738 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
8740 /* If we didn't find a lowpc, set it to highpc to avoid complaints
8741 from finish_block. */
8742 if (lowpc
== ((CORE_ADDR
) -1))
8747 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
8749 prepare_one_comp_unit (cu
, die
, cu
->language
);
8751 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
8752 standardised yet. As a workaround for the language detection we fall
8753 back to the DW_AT_producer string. */
8754 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
8755 cu
->language
= language_opencl
;
8757 /* Similar hack for Go. */
8758 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
8759 set_cu_language (DW_LANG_Go
, cu
);
8761 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
8763 /* Decode line number information if present. We do this before
8764 processing child DIEs, so that the line header table is available
8765 for DW_AT_decl_file. */
8766 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
8768 /* Process all dies in compilation unit. */
8769 if (die
->child
!= NULL
)
8771 child_die
= die
->child
;
8772 while (child_die
&& child_die
->tag
)
8774 process_die (child_die
, cu
);
8775 child_die
= sibling_die (child_die
);
8779 /* Decode macro information, if present. Dwarf 2 macro information
8780 refers to information in the line number info statement program
8781 header, so we can only read it if we've read the header
8783 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
8784 if (attr
&& cu
->line_header
)
8786 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
8787 complaint (&symfile_complaints
,
8788 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
8790 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
8794 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
8795 if (attr
&& cu
->line_header
)
8797 unsigned int macro_offset
= DW_UNSND (attr
);
8799 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
8803 do_cleanups (back_to
);
8806 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
8807 Create the set of symtabs used by this TU, or if this TU is sharing
8808 symtabs with another TU and the symtabs have already been created
8809 then restore those symtabs in the line header.
8810 We don't need the pc/line-number mapping for type units. */
8813 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
8815 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8816 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8817 struct type_unit_group
*tu_group
;
8819 struct line_header
*lh
;
8820 struct attribute
*attr
;
8821 unsigned int i
, line_offset
;
8822 struct signatured_type
*sig_type
;
8824 gdb_assert (per_cu
->is_debug_types
);
8825 sig_type
= (struct signatured_type
*) per_cu
;
8827 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
8829 /* If we're using .gdb_index (includes -readnow) then
8830 per_cu->type_unit_group may not have been set up yet. */
8831 if (sig_type
->type_unit_group
== NULL
)
8832 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
8833 tu_group
= sig_type
->type_unit_group
;
8835 /* If we've already processed this stmt_list there's no real need to
8836 do it again, we could fake it and just recreate the part we need
8837 (file name,index -> symtab mapping). If data shows this optimization
8838 is useful we can do it then. */
8839 first_time
= tu_group
->primary_symtab
== NULL
;
8841 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
8846 line_offset
= DW_UNSND (attr
);
8847 lh
= dwarf_decode_line_header (line_offset
, cu
);
8852 dwarf2_start_symtab (cu
, "", NULL
, 0);
8855 gdb_assert (tu_group
->symtabs
== NULL
);
8858 /* Note: The primary symtab will get allocated at the end. */
8862 cu
->line_header
= lh
;
8863 make_cleanup (free_cu_line_header
, cu
);
8867 dwarf2_start_symtab (cu
, "", NULL
, 0);
8869 tu_group
->num_symtabs
= lh
->num_file_names
;
8870 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
8872 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8874 const char *dir
= NULL
;
8875 struct file_entry
*fe
= &lh
->file_names
[i
];
8878 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8879 dwarf2_start_subfile (fe
->name
, dir
, NULL
);
8881 /* Note: We don't have to watch for the main subfile here, type units
8882 don't have DW_AT_name. */
8884 if (current_subfile
->symtab
== NULL
)
8886 /* NOTE: start_subfile will recognize when it's been passed
8887 a file it has already seen. So we can't assume there's a
8888 simple mapping from lh->file_names to subfiles,
8889 lh->file_names may contain dups. */
8890 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8894 fe
->symtab
= current_subfile
->symtab
;
8895 tu_group
->symtabs
[i
] = fe
->symtab
;
8902 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8904 struct file_entry
*fe
= &lh
->file_names
[i
];
8906 fe
->symtab
= tu_group
->symtabs
[i
];
8910 /* The main symtab is allocated last. Type units don't have DW_AT_name
8911 so they don't have a "real" (so to speak) symtab anyway.
8912 There is later code that will assign the main symtab to all symbols
8913 that don't have one. We need to handle the case of a symbol with a
8914 missing symtab (DW_AT_decl_file) anyway. */
8917 /* Process DW_TAG_type_unit.
8918 For TUs we want to skip the first top level sibling if it's not the
8919 actual type being defined by this TU. In this case the first top
8920 level sibling is there to provide context only. */
8923 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8925 struct die_info
*child_die
;
8927 prepare_one_comp_unit (cu
, die
, language_minimal
);
8929 /* Initialize (or reinitialize) the machinery for building symtabs.
8930 We do this before processing child DIEs, so that the line header table
8931 is available for DW_AT_decl_file. */
8932 setup_type_unit_groups (die
, cu
);
8934 if (die
->child
!= NULL
)
8936 child_die
= die
->child
;
8937 while (child_die
&& child_die
->tag
)
8939 process_die (child_die
, cu
);
8940 child_die
= sibling_die (child_die
);
8947 http://gcc.gnu.org/wiki/DebugFission
8948 http://gcc.gnu.org/wiki/DebugFissionDWP
8950 To simplify handling of both DWO files ("object" files with the DWARF info)
8951 and DWP files (a file with the DWOs packaged up into one file), we treat
8952 DWP files as having a collection of virtual DWO files. */
8955 hash_dwo_file (const void *item
)
8957 const struct dwo_file
*dwo_file
= item
;
8960 hash
= htab_hash_string (dwo_file
->dwo_name
);
8961 if (dwo_file
->comp_dir
!= NULL
)
8962 hash
+= htab_hash_string (dwo_file
->comp_dir
);
8967 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
8969 const struct dwo_file
*lhs
= item_lhs
;
8970 const struct dwo_file
*rhs
= item_rhs
;
8972 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
8974 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
8975 return lhs
->comp_dir
== rhs
->comp_dir
;
8976 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
8979 /* Allocate a hash table for DWO files. */
8982 allocate_dwo_file_hash_table (void)
8984 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8986 return htab_create_alloc_ex (41,
8990 &objfile
->objfile_obstack
,
8991 hashtab_obstack_allocate
,
8992 dummy_obstack_deallocate
);
8995 /* Lookup DWO file DWO_NAME. */
8998 lookup_dwo_file_slot (const char *dwo_name
, const char *comp_dir
)
9000 struct dwo_file find_entry
;
9003 if (dwarf2_per_objfile
->dwo_files
== NULL
)
9004 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
9006 memset (&find_entry
, 0, sizeof (find_entry
));
9007 find_entry
.dwo_name
= dwo_name
;
9008 find_entry
.comp_dir
= comp_dir
;
9009 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
9015 hash_dwo_unit (const void *item
)
9017 const struct dwo_unit
*dwo_unit
= item
;
9019 /* This drops the top 32 bits of the id, but is ok for a hash. */
9020 return dwo_unit
->signature
;
9024 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
9026 const struct dwo_unit
*lhs
= item_lhs
;
9027 const struct dwo_unit
*rhs
= item_rhs
;
9029 /* The signature is assumed to be unique within the DWO file.
9030 So while object file CU dwo_id's always have the value zero,
9031 that's OK, assuming each object file DWO file has only one CU,
9032 and that's the rule for now. */
9033 return lhs
->signature
== rhs
->signature
;
9036 /* Allocate a hash table for DWO CUs,TUs.
9037 There is one of these tables for each of CUs,TUs for each DWO file. */
9040 allocate_dwo_unit_table (struct objfile
*objfile
)
9042 /* Start out with a pretty small number.
9043 Generally DWO files contain only one CU and maybe some TUs. */
9044 return htab_create_alloc_ex (3,
9048 &objfile
->objfile_obstack
,
9049 hashtab_obstack_allocate
,
9050 dummy_obstack_deallocate
);
9053 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
9055 struct create_dwo_cu_data
9057 struct dwo_file
*dwo_file
;
9058 struct dwo_unit dwo_unit
;
9061 /* die_reader_func for create_dwo_cu. */
9064 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
9065 const gdb_byte
*info_ptr
,
9066 struct die_info
*comp_unit_die
,
9070 struct dwarf2_cu
*cu
= reader
->cu
;
9071 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9072 sect_offset offset
= cu
->per_cu
->offset
;
9073 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
9074 struct create_dwo_cu_data
*data
= datap
;
9075 struct dwo_file
*dwo_file
= data
->dwo_file
;
9076 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
9077 struct attribute
*attr
;
9079 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
9082 complaint (&symfile_complaints
,
9083 _("Dwarf Error: debug entry at offset 0x%x is missing"
9084 " its dwo_id [in module %s]"),
9085 offset
.sect_off
, dwo_file
->dwo_name
);
9089 dwo_unit
->dwo_file
= dwo_file
;
9090 dwo_unit
->signature
= DW_UNSND (attr
);
9091 dwo_unit
->section
= section
;
9092 dwo_unit
->offset
= offset
;
9093 dwo_unit
->length
= cu
->per_cu
->length
;
9095 if (dwarf2_read_debug
)
9096 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id %s\n",
9097 offset
.sect_off
, hex_string (dwo_unit
->signature
));
9100 /* Create the dwo_unit for the lone CU in DWO_FILE.
9101 Note: This function processes DWO files only, not DWP files. */
9103 static struct dwo_unit
*
9104 create_dwo_cu (struct dwo_file
*dwo_file
)
9106 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9107 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
9110 const gdb_byte
*info_ptr
, *end_ptr
;
9111 struct create_dwo_cu_data create_dwo_cu_data
;
9112 struct dwo_unit
*dwo_unit
;
9114 dwarf2_read_section (objfile
, section
);
9115 info_ptr
= section
->buffer
;
9117 if (info_ptr
== NULL
)
9120 /* We can't set abfd until now because the section may be empty or
9121 not present, in which case section->asection will be NULL. */
9122 abfd
= get_section_bfd_owner (section
);
9124 if (dwarf2_read_debug
)
9126 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
9127 get_section_name (section
),
9128 get_section_file_name (section
));
9131 create_dwo_cu_data
.dwo_file
= dwo_file
;
9134 end_ptr
= info_ptr
+ section
->size
;
9135 while (info_ptr
< end_ptr
)
9137 struct dwarf2_per_cu_data per_cu
;
9139 memset (&create_dwo_cu_data
.dwo_unit
, 0,
9140 sizeof (create_dwo_cu_data
.dwo_unit
));
9141 memset (&per_cu
, 0, sizeof (per_cu
));
9142 per_cu
.objfile
= objfile
;
9143 per_cu
.is_debug_types
= 0;
9144 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
9145 per_cu
.section
= section
;
9147 init_cutu_and_read_dies_no_follow (&per_cu
,
9148 &dwo_file
->sections
.abbrev
,
9150 create_dwo_cu_reader
,
9151 &create_dwo_cu_data
);
9153 if (create_dwo_cu_data
.dwo_unit
.dwo_file
!= NULL
)
9155 /* If we've already found one, complain. We only support one
9156 because having more than one requires hacking the dwo_name of
9157 each to match, which is highly unlikely to happen. */
9158 if (dwo_unit
!= NULL
)
9160 complaint (&symfile_complaints
,
9161 _("Multiple CUs in DWO file %s [in module %s]"),
9162 dwo_file
->dwo_name
, objfile_name (objfile
));
9166 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
9167 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
9170 info_ptr
+= per_cu
.length
;
9176 /* DWP file .debug_{cu,tu}_index section format:
9177 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
9181 Both index sections have the same format, and serve to map a 64-bit
9182 signature to a set of section numbers. Each section begins with a header,
9183 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
9184 indexes, and a pool of 32-bit section numbers. The index sections will be
9185 aligned at 8-byte boundaries in the file.
9187 The index section header consists of:
9189 V, 32 bit version number
9191 N, 32 bit number of compilation units or type units in the index
9192 M, 32 bit number of slots in the hash table
9194 Numbers are recorded using the byte order of the application binary.
9196 The hash table begins at offset 16 in the section, and consists of an array
9197 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
9198 order of the application binary). Unused slots in the hash table are 0.
9199 (We rely on the extreme unlikeliness of a signature being exactly 0.)
9201 The parallel table begins immediately after the hash table
9202 (at offset 16 + 8 * M from the beginning of the section), and consists of an
9203 array of 32-bit indexes (using the byte order of the application binary),
9204 corresponding 1-1 with slots in the hash table. Each entry in the parallel
9205 table contains a 32-bit index into the pool of section numbers. For unused
9206 hash table slots, the corresponding entry in the parallel table will be 0.
9208 The pool of section numbers begins immediately following the hash table
9209 (at offset 16 + 12 * M from the beginning of the section). The pool of
9210 section numbers consists of an array of 32-bit words (using the byte order
9211 of the application binary). Each item in the array is indexed starting
9212 from 0. The hash table entry provides the index of the first section
9213 number in the set. Additional section numbers in the set follow, and the
9214 set is terminated by a 0 entry (section number 0 is not used in ELF).
9216 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
9217 section must be the first entry in the set, and the .debug_abbrev.dwo must
9218 be the second entry. Other members of the set may follow in any order.
9224 DWP Version 2 combines all the .debug_info, etc. sections into one,
9225 and the entries in the index tables are now offsets into these sections.
9226 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
9229 Index Section Contents:
9231 Hash Table of Signatures dwp_hash_table.hash_table
9232 Parallel Table of Indices dwp_hash_table.unit_table
9233 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
9234 Table of Section Sizes dwp_hash_table.v2.sizes
9236 The index section header consists of:
9238 V, 32 bit version number
9239 L, 32 bit number of columns in the table of section offsets
9240 N, 32 bit number of compilation units or type units in the index
9241 M, 32 bit number of slots in the hash table
9243 Numbers are recorded using the byte order of the application binary.
9245 The hash table has the same format as version 1.
9246 The parallel table of indices has the same format as version 1,
9247 except that the entries are origin-1 indices into the table of sections
9248 offsets and the table of section sizes.
9250 The table of offsets begins immediately following the parallel table
9251 (at offset 16 + 12 * M from the beginning of the section). The table is
9252 a two-dimensional array of 32-bit words (using the byte order of the
9253 application binary), with L columns and N+1 rows, in row-major order.
9254 Each row in the array is indexed starting from 0. The first row provides
9255 a key to the remaining rows: each column in this row provides an identifier
9256 for a debug section, and the offsets in the same column of subsequent rows
9257 refer to that section. The section identifiers are:
9259 DW_SECT_INFO 1 .debug_info.dwo
9260 DW_SECT_TYPES 2 .debug_types.dwo
9261 DW_SECT_ABBREV 3 .debug_abbrev.dwo
9262 DW_SECT_LINE 4 .debug_line.dwo
9263 DW_SECT_LOC 5 .debug_loc.dwo
9264 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
9265 DW_SECT_MACINFO 7 .debug_macinfo.dwo
9266 DW_SECT_MACRO 8 .debug_macro.dwo
9268 The offsets provided by the CU and TU index sections are the base offsets
9269 for the contributions made by each CU or TU to the corresponding section
9270 in the package file. Each CU and TU header contains an abbrev_offset
9271 field, used to find the abbreviations table for that CU or TU within the
9272 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
9273 be interpreted as relative to the base offset given in the index section.
9274 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
9275 should be interpreted as relative to the base offset for .debug_line.dwo,
9276 and offsets into other debug sections obtained from DWARF attributes should
9277 also be interpreted as relative to the corresponding base offset.
9279 The table of sizes begins immediately following the table of offsets.
9280 Like the table of offsets, it is a two-dimensional array of 32-bit words,
9281 with L columns and N rows, in row-major order. Each row in the array is
9282 indexed starting from 1 (row 0 is shared by the two tables).
9286 Hash table lookup is handled the same in version 1 and 2:
9288 We assume that N and M will not exceed 2^32 - 1.
9289 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
9291 Given a 64-bit compilation unit signature or a type signature S, an entry
9292 in the hash table is located as follows:
9294 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
9295 the low-order k bits all set to 1.
9297 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
9299 3) If the hash table entry at index H matches the signature, use that
9300 entry. If the hash table entry at index H is unused (all zeroes),
9301 terminate the search: the signature is not present in the table.
9303 4) Let H = (H + H') modulo M. Repeat at Step 3.
9305 Because M > N and H' and M are relatively prime, the search is guaranteed
9306 to stop at an unused slot or find the match. */
9308 /* Create a hash table to map DWO IDs to their CU/TU entry in
9309 .debug_{info,types}.dwo in DWP_FILE.
9310 Returns NULL if there isn't one.
9311 Note: This function processes DWP files only, not DWO files. */
9313 static struct dwp_hash_table
*
9314 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
9316 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9317 bfd
*dbfd
= dwp_file
->dbfd
;
9318 const gdb_byte
*index_ptr
, *index_end
;
9319 struct dwarf2_section_info
*index
;
9320 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
9321 struct dwp_hash_table
*htab
;
9324 index
= &dwp_file
->sections
.tu_index
;
9326 index
= &dwp_file
->sections
.cu_index
;
9328 if (dwarf2_section_empty_p (index
))
9330 dwarf2_read_section (objfile
, index
);
9332 index_ptr
= index
->buffer
;
9333 index_end
= index_ptr
+ index
->size
;
9335 version
= read_4_bytes (dbfd
, index_ptr
);
9338 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
9342 nr_units
= read_4_bytes (dbfd
, index_ptr
);
9344 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
9347 if (version
!= 1 && version
!= 2)
9349 error (_("Dwarf Error: unsupported DWP file version (%s)"
9351 pulongest (version
), dwp_file
->name
);
9353 if (nr_slots
!= (nr_slots
& -nr_slots
))
9355 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
9356 " is not power of 2 [in module %s]"),
9357 pulongest (nr_slots
), dwp_file
->name
);
9360 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
9361 htab
->version
= version
;
9362 htab
->nr_columns
= nr_columns
;
9363 htab
->nr_units
= nr_units
;
9364 htab
->nr_slots
= nr_slots
;
9365 htab
->hash_table
= index_ptr
;
9366 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
9368 /* Exit early if the table is empty. */
9369 if (nr_slots
== 0 || nr_units
== 0
9370 || (version
== 2 && nr_columns
== 0))
9372 /* All must be zero. */
9373 if (nr_slots
!= 0 || nr_units
!= 0
9374 || (version
== 2 && nr_columns
!= 0))
9376 complaint (&symfile_complaints
,
9377 _("Empty DWP but nr_slots,nr_units,nr_columns not"
9378 " all zero [in modules %s]"),
9386 htab
->section_pool
.v1
.indices
=
9387 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9388 /* It's harder to decide whether the section is too small in v1.
9389 V1 is deprecated anyway so we punt. */
9393 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9394 int *ids
= htab
->section_pool
.v2
.section_ids
;
9395 /* Reverse map for error checking. */
9396 int ids_seen
[DW_SECT_MAX
+ 1];
9401 error (_("Dwarf Error: bad DWP hash table, too few columns"
9402 " in section table [in module %s]"),
9405 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
9407 error (_("Dwarf Error: bad DWP hash table, too many columns"
9408 " in section table [in module %s]"),
9411 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
9412 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
9413 for (i
= 0; i
< nr_columns
; ++i
)
9415 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
9417 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
9419 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
9420 " in section table [in module %s]"),
9421 id
, dwp_file
->name
);
9423 if (ids_seen
[id
] != -1)
9425 error (_("Dwarf Error: bad DWP hash table, duplicate section"
9426 " id %d in section table [in module %s]"),
9427 id
, dwp_file
->name
);
9432 /* Must have exactly one info or types section. */
9433 if (((ids_seen
[DW_SECT_INFO
] != -1)
9434 + (ids_seen
[DW_SECT_TYPES
] != -1))
9437 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
9438 " DWO info/types section [in module %s]"),
9441 /* Must have an abbrev section. */
9442 if (ids_seen
[DW_SECT_ABBREV
] == -1)
9444 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
9445 " section [in module %s]"),
9448 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
9449 htab
->section_pool
.v2
.sizes
=
9450 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
9451 * nr_units
* nr_columns
);
9452 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
9453 * nr_units
* nr_columns
))
9456 error (_("Dwarf Error: DWP index section is corrupt (too small)"
9465 /* Update SECTIONS with the data from SECTP.
9467 This function is like the other "locate" section routines that are
9468 passed to bfd_map_over_sections, but in this context the sections to
9469 read comes from the DWP V1 hash table, not the full ELF section table.
9471 The result is non-zero for success, or zero if an error was found. */
9474 locate_v1_virtual_dwo_sections (asection
*sectp
,
9475 struct virtual_v1_dwo_sections
*sections
)
9477 const struct dwop_section_names
*names
= &dwop_section_names
;
9479 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
9481 /* There can be only one. */
9482 if (sections
->abbrev
.s
.asection
!= NULL
)
9484 sections
->abbrev
.s
.asection
= sectp
;
9485 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
9487 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
9488 || section_is_p (sectp
->name
, &names
->types_dwo
))
9490 /* There can be only one. */
9491 if (sections
->info_or_types
.s
.asection
!= NULL
)
9493 sections
->info_or_types
.s
.asection
= sectp
;
9494 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
9496 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
9498 /* There can be only one. */
9499 if (sections
->line
.s
.asection
!= NULL
)
9501 sections
->line
.s
.asection
= sectp
;
9502 sections
->line
.size
= bfd_get_section_size (sectp
);
9504 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
9506 /* There can be only one. */
9507 if (sections
->loc
.s
.asection
!= NULL
)
9509 sections
->loc
.s
.asection
= sectp
;
9510 sections
->loc
.size
= bfd_get_section_size (sectp
);
9512 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
9514 /* There can be only one. */
9515 if (sections
->macinfo
.s
.asection
!= NULL
)
9517 sections
->macinfo
.s
.asection
= sectp
;
9518 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
9520 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
9522 /* There can be only one. */
9523 if (sections
->macro
.s
.asection
!= NULL
)
9525 sections
->macro
.s
.asection
= sectp
;
9526 sections
->macro
.size
= bfd_get_section_size (sectp
);
9528 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
9530 /* There can be only one. */
9531 if (sections
->str_offsets
.s
.asection
!= NULL
)
9533 sections
->str_offsets
.s
.asection
= sectp
;
9534 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
9538 /* No other kind of section is valid. */
9545 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
9546 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
9547 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
9548 This is for DWP version 1 files. */
9550 static struct dwo_unit
*
9551 create_dwo_unit_in_dwp_v1 (struct dwp_file
*dwp_file
,
9552 uint32_t unit_index
,
9553 const char *comp_dir
,
9554 ULONGEST signature
, int is_debug_types
)
9556 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9557 const struct dwp_hash_table
*dwp_htab
=
9558 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9559 bfd
*dbfd
= dwp_file
->dbfd
;
9560 const char *kind
= is_debug_types
? "TU" : "CU";
9561 struct dwo_file
*dwo_file
;
9562 struct dwo_unit
*dwo_unit
;
9563 struct virtual_v1_dwo_sections sections
;
9564 void **dwo_file_slot
;
9565 char *virtual_dwo_name
;
9566 struct dwarf2_section_info
*cutu
;
9567 struct cleanup
*cleanups
;
9570 gdb_assert (dwp_file
->version
== 1);
9572 if (dwarf2_read_debug
)
9574 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
9576 pulongest (unit_index
), hex_string (signature
),
9580 /* Fetch the sections of this DWO unit.
9581 Put a limit on the number of sections we look for so that bad data
9582 doesn't cause us to loop forever. */
9584 #define MAX_NR_V1_DWO_SECTIONS \
9585 (1 /* .debug_info or .debug_types */ \
9586 + 1 /* .debug_abbrev */ \
9587 + 1 /* .debug_line */ \
9588 + 1 /* .debug_loc */ \
9589 + 1 /* .debug_str_offsets */ \
9590 + 1 /* .debug_macro or .debug_macinfo */ \
9591 + 1 /* trailing zero */)
9593 memset (§ions
, 0, sizeof (sections
));
9594 cleanups
= make_cleanup (null_cleanup
, 0);
9596 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
9599 uint32_t section_nr
=
9601 dwp_htab
->section_pool
.v1
.indices
9602 + (unit_index
+ i
) * sizeof (uint32_t));
9604 if (section_nr
== 0)
9606 if (section_nr
>= dwp_file
->num_sections
)
9608 error (_("Dwarf Error: bad DWP hash table, section number too large"
9613 sectp
= dwp_file
->elf_sections
[section_nr
];
9614 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
9616 error (_("Dwarf Error: bad DWP hash table, invalid section found"
9623 || dwarf2_section_empty_p (§ions
.info_or_types
)
9624 || dwarf2_section_empty_p (§ions
.abbrev
))
9626 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
9630 if (i
== MAX_NR_V1_DWO_SECTIONS
)
9632 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
9637 /* It's easier for the rest of the code if we fake a struct dwo_file and
9638 have dwo_unit "live" in that. At least for now.
9640 The DWP file can be made up of a random collection of CUs and TUs.
9641 However, for each CU + set of TUs that came from the same original DWO
9642 file, we can combine them back into a virtual DWO file to save space
9643 (fewer struct dwo_file objects to allocate). Remember that for really
9644 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
9647 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
9648 get_section_id (§ions
.abbrev
),
9649 get_section_id (§ions
.line
),
9650 get_section_id (§ions
.loc
),
9651 get_section_id (§ions
.str_offsets
));
9652 make_cleanup (xfree
, virtual_dwo_name
);
9653 /* Can we use an existing virtual DWO file? */
9654 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
9655 /* Create one if necessary. */
9656 if (*dwo_file_slot
== NULL
)
9658 if (dwarf2_read_debug
)
9660 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
9663 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
9664 dwo_file
->dwo_name
= obstack_copy0 (&objfile
->objfile_obstack
,
9666 strlen (virtual_dwo_name
));
9667 dwo_file
->comp_dir
= comp_dir
;
9668 dwo_file
->sections
.abbrev
= sections
.abbrev
;
9669 dwo_file
->sections
.line
= sections
.line
;
9670 dwo_file
->sections
.loc
= sections
.loc
;
9671 dwo_file
->sections
.macinfo
= sections
.macinfo
;
9672 dwo_file
->sections
.macro
= sections
.macro
;
9673 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
9674 /* The "str" section is global to the entire DWP file. */
9675 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
9676 /* The info or types section is assigned below to dwo_unit,
9677 there's no need to record it in dwo_file.
9678 Also, we can't simply record type sections in dwo_file because
9679 we record a pointer into the vector in dwo_unit. As we collect more
9680 types we'll grow the vector and eventually have to reallocate space
9681 for it, invalidating all copies of pointers into the previous
9683 *dwo_file_slot
= dwo_file
;
9687 if (dwarf2_read_debug
)
9689 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
9692 dwo_file
= *dwo_file_slot
;
9694 do_cleanups (cleanups
);
9696 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
9697 dwo_unit
->dwo_file
= dwo_file
;
9698 dwo_unit
->signature
= signature
;
9699 dwo_unit
->section
= obstack_alloc (&objfile
->objfile_obstack
,
9700 sizeof (struct dwarf2_section_info
));
9701 *dwo_unit
->section
= sections
.info_or_types
;
9702 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
9707 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
9708 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
9709 piece within that section used by a TU/CU, return a virtual section
9710 of just that piece. */
9712 static struct dwarf2_section_info
9713 create_dwp_v2_section (struct dwarf2_section_info
*section
,
9714 bfd_size_type offset
, bfd_size_type size
)
9716 struct dwarf2_section_info result
;
9719 gdb_assert (section
!= NULL
);
9720 gdb_assert (!section
->is_virtual
);
9722 memset (&result
, 0, sizeof (result
));
9723 result
.s
.containing_section
= section
;
9724 result
.is_virtual
= 1;
9729 sectp
= get_section_bfd_section (section
);
9731 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
9732 bounds of the real section. This is a pretty-rare event, so just
9733 flag an error (easier) instead of a warning and trying to cope. */
9735 || offset
+ size
> bfd_get_section_size (sectp
))
9737 bfd
*abfd
= sectp
->owner
;
9739 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
9740 " in section %s [in module %s]"),
9741 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
9742 objfile_name (dwarf2_per_objfile
->objfile
));
9745 result
.virtual_offset
= offset
;
9750 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
9751 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
9752 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
9753 This is for DWP version 2 files. */
9755 static struct dwo_unit
*
9756 create_dwo_unit_in_dwp_v2 (struct dwp_file
*dwp_file
,
9757 uint32_t unit_index
,
9758 const char *comp_dir
,
9759 ULONGEST signature
, int is_debug_types
)
9761 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9762 const struct dwp_hash_table
*dwp_htab
=
9763 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9764 bfd
*dbfd
= dwp_file
->dbfd
;
9765 const char *kind
= is_debug_types
? "TU" : "CU";
9766 struct dwo_file
*dwo_file
;
9767 struct dwo_unit
*dwo_unit
;
9768 struct virtual_v2_dwo_sections sections
;
9769 void **dwo_file_slot
;
9770 char *virtual_dwo_name
;
9771 struct dwarf2_section_info
*cutu
;
9772 struct cleanup
*cleanups
;
9775 gdb_assert (dwp_file
->version
== 2);
9777 if (dwarf2_read_debug
)
9779 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
9781 pulongest (unit_index
), hex_string (signature
),
9785 /* Fetch the section offsets of this DWO unit. */
9787 memset (§ions
, 0, sizeof (sections
));
9788 cleanups
= make_cleanup (null_cleanup
, 0);
9790 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
9792 uint32_t offset
= read_4_bytes (dbfd
,
9793 dwp_htab
->section_pool
.v2
.offsets
9794 + (((unit_index
- 1) * dwp_htab
->nr_columns
9796 * sizeof (uint32_t)));
9797 uint32_t size
= read_4_bytes (dbfd
,
9798 dwp_htab
->section_pool
.v2
.sizes
9799 + (((unit_index
- 1) * dwp_htab
->nr_columns
9801 * sizeof (uint32_t)));
9803 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
9807 sections
.info_or_types_offset
= offset
;
9808 sections
.info_or_types_size
= size
;
9810 case DW_SECT_ABBREV
:
9811 sections
.abbrev_offset
= offset
;
9812 sections
.abbrev_size
= size
;
9815 sections
.line_offset
= offset
;
9816 sections
.line_size
= size
;
9819 sections
.loc_offset
= offset
;
9820 sections
.loc_size
= size
;
9822 case DW_SECT_STR_OFFSETS
:
9823 sections
.str_offsets_offset
= offset
;
9824 sections
.str_offsets_size
= size
;
9826 case DW_SECT_MACINFO
:
9827 sections
.macinfo_offset
= offset
;
9828 sections
.macinfo_size
= size
;
9831 sections
.macro_offset
= offset
;
9832 sections
.macro_size
= size
;
9837 /* It's easier for the rest of the code if we fake a struct dwo_file and
9838 have dwo_unit "live" in that. At least for now.
9840 The DWP file can be made up of a random collection of CUs and TUs.
9841 However, for each CU + set of TUs that came from the same original DWO
9842 file, we can combine them back into a virtual DWO file to save space
9843 (fewer struct dwo_file objects to allocate). Remember that for really
9844 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
9847 xstrprintf ("virtual-dwo/%ld-%ld-%ld-%ld",
9848 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
9849 (long) (sections
.line_size
? sections
.line_offset
: 0),
9850 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
9851 (long) (sections
.str_offsets_size
9852 ? sections
.str_offsets_offset
: 0));
9853 make_cleanup (xfree
, virtual_dwo_name
);
9854 /* Can we use an existing virtual DWO file? */
9855 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
9856 /* Create one if necessary. */
9857 if (*dwo_file_slot
== NULL
)
9859 if (dwarf2_read_debug
)
9861 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
9864 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
9865 dwo_file
->dwo_name
= obstack_copy0 (&objfile
->objfile_obstack
,
9867 strlen (virtual_dwo_name
));
9868 dwo_file
->comp_dir
= comp_dir
;
9869 dwo_file
->sections
.abbrev
=
9870 create_dwp_v2_section (&dwp_file
->sections
.abbrev
,
9871 sections
.abbrev_offset
, sections
.abbrev_size
);
9872 dwo_file
->sections
.line
=
9873 create_dwp_v2_section (&dwp_file
->sections
.line
,
9874 sections
.line_offset
, sections
.line_size
);
9875 dwo_file
->sections
.loc
=
9876 create_dwp_v2_section (&dwp_file
->sections
.loc
,
9877 sections
.loc_offset
, sections
.loc_size
);
9878 dwo_file
->sections
.macinfo
=
9879 create_dwp_v2_section (&dwp_file
->sections
.macinfo
,
9880 sections
.macinfo_offset
, sections
.macinfo_size
);
9881 dwo_file
->sections
.macro
=
9882 create_dwp_v2_section (&dwp_file
->sections
.macro
,
9883 sections
.macro_offset
, sections
.macro_size
);
9884 dwo_file
->sections
.str_offsets
=
9885 create_dwp_v2_section (&dwp_file
->sections
.str_offsets
,
9886 sections
.str_offsets_offset
,
9887 sections
.str_offsets_size
);
9888 /* The "str" section is global to the entire DWP file. */
9889 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
9890 /* The info or types section is assigned below to dwo_unit,
9891 there's no need to record it in dwo_file.
9892 Also, we can't simply record type sections in dwo_file because
9893 we record a pointer into the vector in dwo_unit. As we collect more
9894 types we'll grow the vector and eventually have to reallocate space
9895 for it, invalidating all copies of pointers into the previous
9897 *dwo_file_slot
= dwo_file
;
9901 if (dwarf2_read_debug
)
9903 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
9906 dwo_file
= *dwo_file_slot
;
9908 do_cleanups (cleanups
);
9910 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
9911 dwo_unit
->dwo_file
= dwo_file
;
9912 dwo_unit
->signature
= signature
;
9913 dwo_unit
->section
= obstack_alloc (&objfile
->objfile_obstack
,
9914 sizeof (struct dwarf2_section_info
));
9915 *dwo_unit
->section
= create_dwp_v2_section (is_debug_types
9916 ? &dwp_file
->sections
.types
9917 : &dwp_file
->sections
.info
,
9918 sections
.info_or_types_offset
,
9919 sections
.info_or_types_size
);
9920 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
9925 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
9926 Returns NULL if the signature isn't found. */
9928 static struct dwo_unit
*
9929 lookup_dwo_unit_in_dwp (struct dwp_file
*dwp_file
, const char *comp_dir
,
9930 ULONGEST signature
, int is_debug_types
)
9932 const struct dwp_hash_table
*dwp_htab
=
9933 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9934 bfd
*dbfd
= dwp_file
->dbfd
;
9935 uint32_t mask
= dwp_htab
->nr_slots
- 1;
9936 uint32_t hash
= signature
& mask
;
9937 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
9940 struct dwo_unit find_dwo_cu
, *dwo_cu
;
9942 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
9943 find_dwo_cu
.signature
= signature
;
9944 slot
= htab_find_slot (is_debug_types
9945 ? dwp_file
->loaded_tus
9946 : dwp_file
->loaded_cus
,
9947 &find_dwo_cu
, INSERT
);
9952 /* Use a for loop so that we don't loop forever on bad debug info. */
9953 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
9955 ULONGEST signature_in_table
;
9957 signature_in_table
=
9958 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
9959 if (signature_in_table
== signature
)
9961 uint32_t unit_index
=
9963 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
9965 if (dwp_file
->version
== 1)
9967 *slot
= create_dwo_unit_in_dwp_v1 (dwp_file
, unit_index
,
9968 comp_dir
, signature
,
9973 *slot
= create_dwo_unit_in_dwp_v2 (dwp_file
, unit_index
,
9974 comp_dir
, signature
,
9979 if (signature_in_table
== 0)
9981 hash
= (hash
+ hash2
) & mask
;
9984 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
9989 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
9990 Open the file specified by FILE_NAME and hand it off to BFD for
9991 preliminary analysis. Return a newly initialized bfd *, which
9992 includes a canonicalized copy of FILE_NAME.
9993 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
9994 SEARCH_CWD is true if the current directory is to be searched.
9995 It will be searched before debug-file-directory.
9996 If unable to find/open the file, return NULL.
9997 NOTE: This function is derived from symfile_bfd_open. */
10000 try_open_dwop_file (const char *file_name
, int is_dwp
, int search_cwd
)
10004 char *absolute_name
;
10005 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
10006 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
10007 to debug_file_directory. */
10009 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
10013 if (*debug_file_directory
!= '\0')
10014 search_path
= concat (".", dirname_separator_string
,
10015 debug_file_directory
, NULL
);
10017 search_path
= xstrdup (".");
10020 search_path
= xstrdup (debug_file_directory
);
10022 flags
= OPF_RETURN_REALPATH
;
10024 flags
|= OPF_SEARCH_IN_PATH
;
10025 desc
= openp (search_path
, flags
, file_name
,
10026 O_RDONLY
| O_BINARY
, &absolute_name
);
10027 xfree (search_path
);
10031 sym_bfd
= gdb_bfd_open (absolute_name
, gnutarget
, desc
);
10032 xfree (absolute_name
);
10033 if (sym_bfd
== NULL
)
10035 bfd_set_cacheable (sym_bfd
, 1);
10037 if (!bfd_check_format (sym_bfd
, bfd_object
))
10039 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
10046 /* Try to open DWO file FILE_NAME.
10047 COMP_DIR is the DW_AT_comp_dir attribute.
10048 The result is the bfd handle of the file.
10049 If there is a problem finding or opening the file, return NULL.
10050 Upon success, the canonicalized path of the file is stored in the bfd,
10051 same as symfile_bfd_open. */
10054 open_dwo_file (const char *file_name
, const char *comp_dir
)
10058 if (IS_ABSOLUTE_PATH (file_name
))
10059 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 0 /*search_cwd*/);
10061 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
10063 if (comp_dir
!= NULL
)
10065 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, file_name
, NULL
);
10067 /* NOTE: If comp_dir is a relative path, this will also try the
10068 search path, which seems useful. */
10069 abfd
= try_open_dwop_file (path_to_try
, 0 /*is_dwp*/, 1 /*search_cwd*/);
10070 xfree (path_to_try
);
10075 /* That didn't work, try debug-file-directory, which, despite its name,
10076 is a list of paths. */
10078 if (*debug_file_directory
== '\0')
10081 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 1 /*search_cwd*/);
10084 /* This function is mapped across the sections and remembers the offset and
10085 size of each of the DWO debugging sections we are interested in. */
10088 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
10090 struct dwo_sections
*dwo_sections
= dwo_sections_ptr
;
10091 const struct dwop_section_names
*names
= &dwop_section_names
;
10093 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10095 dwo_sections
->abbrev
.s
.asection
= sectp
;
10096 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10098 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10100 dwo_sections
->info
.s
.asection
= sectp
;
10101 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
10103 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10105 dwo_sections
->line
.s
.asection
= sectp
;
10106 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
10108 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10110 dwo_sections
->loc
.s
.asection
= sectp
;
10111 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
10113 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10115 dwo_sections
->macinfo
.s
.asection
= sectp
;
10116 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10118 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10120 dwo_sections
->macro
.s
.asection
= sectp
;
10121 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
10123 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
10125 dwo_sections
->str
.s
.asection
= sectp
;
10126 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
10128 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10130 dwo_sections
->str_offsets
.s
.asection
= sectp
;
10131 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10133 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10135 struct dwarf2_section_info type_section
;
10137 memset (&type_section
, 0, sizeof (type_section
));
10138 type_section
.s
.asection
= sectp
;
10139 type_section
.size
= bfd_get_section_size (sectp
);
10140 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
10145 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
10146 by PER_CU. This is for the non-DWP case.
10147 The result is NULL if DWO_NAME can't be found. */
10149 static struct dwo_file
*
10150 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
10151 const char *dwo_name
, const char *comp_dir
)
10153 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10154 struct dwo_file
*dwo_file
;
10156 struct cleanup
*cleanups
;
10158 dbfd
= open_dwo_file (dwo_name
, comp_dir
);
10161 if (dwarf2_read_debug
)
10162 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
10165 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10166 dwo_file
->dwo_name
= dwo_name
;
10167 dwo_file
->comp_dir
= comp_dir
;
10168 dwo_file
->dbfd
= dbfd
;
10170 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
10172 bfd_map_over_sections (dbfd
, dwarf2_locate_dwo_sections
, &dwo_file
->sections
);
10174 dwo_file
->cu
= create_dwo_cu (dwo_file
);
10176 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
10177 dwo_file
->sections
.types
);
10179 discard_cleanups (cleanups
);
10181 if (dwarf2_read_debug
)
10182 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
10187 /* This function is mapped across the sections and remembers the offset and
10188 size of each of the DWP debugging sections common to version 1 and 2 that
10189 we are interested in. */
10192 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
10193 void *dwp_file_ptr
)
10195 struct dwp_file
*dwp_file
= dwp_file_ptr
;
10196 const struct dwop_section_names
*names
= &dwop_section_names
;
10197 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10199 /* Record the ELF section number for later lookup: this is what the
10200 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10201 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10202 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10204 /* Look for specific sections that we need. */
10205 if (section_is_p (sectp
->name
, &names
->str_dwo
))
10207 dwp_file
->sections
.str
.s
.asection
= sectp
;
10208 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
10210 else if (section_is_p (sectp
->name
, &names
->cu_index
))
10212 dwp_file
->sections
.cu_index
.s
.asection
= sectp
;
10213 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
10215 else if (section_is_p (sectp
->name
, &names
->tu_index
))
10217 dwp_file
->sections
.tu_index
.s
.asection
= sectp
;
10218 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
10222 /* This function is mapped across the sections and remembers the offset and
10223 size of each of the DWP version 2 debugging sections that we are interested
10224 in. This is split into a separate function because we don't know if we
10225 have version 1 or 2 until we parse the cu_index/tu_index sections. */
10228 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
10230 struct dwp_file
*dwp_file
= dwp_file_ptr
;
10231 const struct dwop_section_names
*names
= &dwop_section_names
;
10232 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10234 /* Record the ELF section number for later lookup: this is what the
10235 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10236 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10237 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10239 /* Look for specific sections that we need. */
10240 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10242 dwp_file
->sections
.abbrev
.s
.asection
= sectp
;
10243 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
10245 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10247 dwp_file
->sections
.info
.s
.asection
= sectp
;
10248 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
10250 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10252 dwp_file
->sections
.line
.s
.asection
= sectp
;
10253 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
10255 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10257 dwp_file
->sections
.loc
.s
.asection
= sectp
;
10258 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
10260 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10262 dwp_file
->sections
.macinfo
.s
.asection
= sectp
;
10263 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
10265 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10267 dwp_file
->sections
.macro
.s
.asection
= sectp
;
10268 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
10270 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10272 dwp_file
->sections
.str_offsets
.s
.asection
= sectp
;
10273 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
10275 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10277 dwp_file
->sections
.types
.s
.asection
= sectp
;
10278 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
10282 /* Hash function for dwp_file loaded CUs/TUs. */
10285 hash_dwp_loaded_cutus (const void *item
)
10287 const struct dwo_unit
*dwo_unit
= item
;
10289 /* This drops the top 32 bits of the signature, but is ok for a hash. */
10290 return dwo_unit
->signature
;
10293 /* Equality function for dwp_file loaded CUs/TUs. */
10296 eq_dwp_loaded_cutus (const void *a
, const void *b
)
10298 const struct dwo_unit
*dua
= a
;
10299 const struct dwo_unit
*dub
= b
;
10301 return dua
->signature
== dub
->signature
;
10304 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
10307 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
10309 return htab_create_alloc_ex (3,
10310 hash_dwp_loaded_cutus
,
10311 eq_dwp_loaded_cutus
,
10313 &objfile
->objfile_obstack
,
10314 hashtab_obstack_allocate
,
10315 dummy_obstack_deallocate
);
10318 /* Try to open DWP file FILE_NAME.
10319 The result is the bfd handle of the file.
10320 If there is a problem finding or opening the file, return NULL.
10321 Upon success, the canonicalized path of the file is stored in the bfd,
10322 same as symfile_bfd_open. */
10325 open_dwp_file (const char *file_name
)
10329 abfd
= try_open_dwop_file (file_name
, 1 /*is_dwp*/, 1 /*search_cwd*/);
10333 /* Work around upstream bug 15652.
10334 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
10335 [Whether that's a "bug" is debatable, but it is getting in our way.]
10336 We have no real idea where the dwp file is, because gdb's realpath-ing
10337 of the executable's path may have discarded the needed info.
10338 [IWBN if the dwp file name was recorded in the executable, akin to
10339 .gnu_debuglink, but that doesn't exist yet.]
10340 Strip the directory from FILE_NAME and search again. */
10341 if (*debug_file_directory
!= '\0')
10343 /* Don't implicitly search the current directory here.
10344 If the user wants to search "." to handle this case,
10345 it must be added to debug-file-directory. */
10346 return try_open_dwop_file (lbasename (file_name
), 1 /*is_dwp*/,
10353 /* Initialize the use of the DWP file for the current objfile.
10354 By convention the name of the DWP file is ${objfile}.dwp.
10355 The result is NULL if it can't be found. */
10357 static struct dwp_file
*
10358 open_and_init_dwp_file (void)
10360 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10361 struct dwp_file
*dwp_file
;
10364 struct cleanup
*cleanups
;
10366 /* Try to find first .dwp for the binary file before any symbolic links
10368 dwp_name
= xstrprintf ("%s.dwp", objfile
->original_name
);
10369 cleanups
= make_cleanup (xfree
, dwp_name
);
10371 dbfd
= open_dwp_file (dwp_name
);
10373 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
10375 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
10376 dwp_name
= xstrprintf ("%s.dwp", objfile_name (objfile
));
10377 make_cleanup (xfree
, dwp_name
);
10378 dbfd
= open_dwp_file (dwp_name
);
10383 if (dwarf2_read_debug
)
10384 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
);
10385 do_cleanups (cleanups
);
10388 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
10389 dwp_file
->name
= bfd_get_filename (dbfd
);
10390 dwp_file
->dbfd
= dbfd
;
10391 do_cleanups (cleanups
);
10393 /* +1: section 0 is unused */
10394 dwp_file
->num_sections
= bfd_count_sections (dbfd
) + 1;
10395 dwp_file
->elf_sections
=
10396 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
10397 dwp_file
->num_sections
, asection
*);
10399 bfd_map_over_sections (dbfd
, dwarf2_locate_common_dwp_sections
, dwp_file
);
10401 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
10403 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
10405 /* The DWP file version is stored in the hash table. Oh well. */
10406 if (dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
10408 /* Technically speaking, we should try to limp along, but this is
10410 error (_("Dwarf Error: DWP file CU version %d doesn't match"
10411 " TU version %d [in DWP file %s]"),
10412 dwp_file
->cus
->version
, dwp_file
->tus
->version
, dwp_name
);
10414 dwp_file
->version
= dwp_file
->cus
->version
;
10416 if (dwp_file
->version
== 2)
10417 bfd_map_over_sections (dbfd
, dwarf2_locate_v2_dwp_sections
, dwp_file
);
10419 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
10420 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
10422 if (dwarf2_read_debug
)
10424 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
10425 fprintf_unfiltered (gdb_stdlog
,
10426 " %s CUs, %s TUs\n",
10427 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
10428 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
10434 /* Wrapper around open_and_init_dwp_file, only open it once. */
10436 static struct dwp_file
*
10437 get_dwp_file (void)
10439 if (! dwarf2_per_objfile
->dwp_checked
)
10441 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file ();
10442 dwarf2_per_objfile
->dwp_checked
= 1;
10444 return dwarf2_per_objfile
->dwp_file
;
10447 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
10448 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
10449 or in the DWP file for the objfile, referenced by THIS_UNIT.
10450 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
10451 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
10453 This is called, for example, when wanting to read a variable with a
10454 complex location. Therefore we don't want to do file i/o for every call.
10455 Therefore we don't want to look for a DWO file on every call.
10456 Therefore we first see if we've already seen SIGNATURE in a DWP file,
10457 then we check if we've already seen DWO_NAME, and only THEN do we check
10460 The result is a pointer to the dwo_unit object or NULL if we didn't find it
10461 (dwo_id mismatch or couldn't find the DWO/DWP file). */
10463 static struct dwo_unit
*
10464 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
10465 const char *dwo_name
, const char *comp_dir
,
10466 ULONGEST signature
, int is_debug_types
)
10468 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10469 const char *kind
= is_debug_types
? "TU" : "CU";
10470 void **dwo_file_slot
;
10471 struct dwo_file
*dwo_file
;
10472 struct dwp_file
*dwp_file
;
10474 /* First see if there's a DWP file.
10475 If we have a DWP file but didn't find the DWO inside it, don't
10476 look for the original DWO file. It makes gdb behave differently
10477 depending on whether one is debugging in the build tree. */
10479 dwp_file
= get_dwp_file ();
10480 if (dwp_file
!= NULL
)
10482 const struct dwp_hash_table
*dwp_htab
=
10483 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10485 if (dwp_htab
!= NULL
)
10487 struct dwo_unit
*dwo_cutu
=
10488 lookup_dwo_unit_in_dwp (dwp_file
, comp_dir
,
10489 signature
, is_debug_types
);
10491 if (dwo_cutu
!= NULL
)
10493 if (dwarf2_read_debug
)
10495 fprintf_unfiltered (gdb_stdlog
,
10496 "Virtual DWO %s %s found: @%s\n",
10497 kind
, hex_string (signature
),
10498 host_address_to_string (dwo_cutu
));
10506 /* No DWP file, look for the DWO file. */
10508 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
, comp_dir
);
10509 if (*dwo_file_slot
== NULL
)
10511 /* Read in the file and build a table of the CUs/TUs it contains. */
10512 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
10514 /* NOTE: This will be NULL if unable to open the file. */
10515 dwo_file
= *dwo_file_slot
;
10517 if (dwo_file
!= NULL
)
10519 struct dwo_unit
*dwo_cutu
= NULL
;
10521 if (is_debug_types
&& dwo_file
->tus
)
10523 struct dwo_unit find_dwo_cutu
;
10525 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
10526 find_dwo_cutu
.signature
= signature
;
10527 dwo_cutu
= htab_find (dwo_file
->tus
, &find_dwo_cutu
);
10529 else if (!is_debug_types
&& dwo_file
->cu
)
10531 if (signature
== dwo_file
->cu
->signature
)
10532 dwo_cutu
= dwo_file
->cu
;
10535 if (dwo_cutu
!= NULL
)
10537 if (dwarf2_read_debug
)
10539 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
10540 kind
, dwo_name
, hex_string (signature
),
10541 host_address_to_string (dwo_cutu
));
10548 /* We didn't find it. This could mean a dwo_id mismatch, or
10549 someone deleted the DWO/DWP file, or the search path isn't set up
10550 correctly to find the file. */
10552 if (dwarf2_read_debug
)
10554 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
10555 kind
, dwo_name
, hex_string (signature
));
10558 /* This is a warning and not a complaint because it can be caused by
10559 pilot error (e.g., user accidentally deleting the DWO). */
10560 warning (_("Could not find DWO %s %s(%s) referenced by %s at offset 0x%x"
10561 " [in module %s]"),
10562 kind
, dwo_name
, hex_string (signature
),
10563 this_unit
->is_debug_types
? "TU" : "CU",
10564 this_unit
->offset
.sect_off
, objfile_name (objfile
));
10568 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
10569 See lookup_dwo_cutu_unit for details. */
10571 static struct dwo_unit
*
10572 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
10573 const char *dwo_name
, const char *comp_dir
,
10574 ULONGEST signature
)
10576 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
10579 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
10580 See lookup_dwo_cutu_unit for details. */
10582 static struct dwo_unit
*
10583 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
10584 const char *dwo_name
, const char *comp_dir
)
10586 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
10589 /* Traversal function for queue_and_load_all_dwo_tus. */
10592 queue_and_load_dwo_tu (void **slot
, void *info
)
10594 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
10595 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
10596 ULONGEST signature
= dwo_unit
->signature
;
10597 struct signatured_type
*sig_type
=
10598 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
10600 if (sig_type
!= NULL
)
10602 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
10604 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
10605 a real dependency of PER_CU on SIG_TYPE. That is detected later
10606 while processing PER_CU. */
10607 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
10608 load_full_type_unit (sig_cu
);
10609 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
10615 /* Queue all TUs contained in the DWO of PER_CU to be read in.
10616 The DWO may have the only definition of the type, though it may not be
10617 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
10618 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
10621 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
10623 struct dwo_unit
*dwo_unit
;
10624 struct dwo_file
*dwo_file
;
10626 gdb_assert (!per_cu
->is_debug_types
);
10627 gdb_assert (get_dwp_file () == NULL
);
10628 gdb_assert (per_cu
->cu
!= NULL
);
10630 dwo_unit
= per_cu
->cu
->dwo_unit
;
10631 gdb_assert (dwo_unit
!= NULL
);
10633 dwo_file
= dwo_unit
->dwo_file
;
10634 if (dwo_file
->tus
!= NULL
)
10635 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
10638 /* Free all resources associated with DWO_FILE.
10639 Close the DWO file and munmap the sections.
10640 All memory should be on the objfile obstack. */
10643 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
10646 struct dwarf2_section_info
*section
;
10648 /* Note: dbfd is NULL for virtual DWO files. */
10649 gdb_bfd_unref (dwo_file
->dbfd
);
10651 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
10654 /* Wrapper for free_dwo_file for use in cleanups. */
10657 free_dwo_file_cleanup (void *arg
)
10659 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
10660 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10662 free_dwo_file (dwo_file
, objfile
);
10665 /* Traversal function for free_dwo_files. */
10668 free_dwo_file_from_slot (void **slot
, void *info
)
10670 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
10671 struct objfile
*objfile
= (struct objfile
*) info
;
10673 free_dwo_file (dwo_file
, objfile
);
10678 /* Free all resources associated with DWO_FILES. */
10681 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
10683 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
10686 /* Read in various DIEs. */
10688 /* qsort helper for inherit_abstract_dies. */
10691 unsigned_int_compar (const void *ap
, const void *bp
)
10693 unsigned int a
= *(unsigned int *) ap
;
10694 unsigned int b
= *(unsigned int *) bp
;
10696 return (a
> b
) - (b
> a
);
10699 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
10700 Inherit only the children of the DW_AT_abstract_origin DIE not being
10701 already referenced by DW_AT_abstract_origin from the children of the
10705 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
10707 struct die_info
*child_die
;
10708 unsigned die_children_count
;
10709 /* CU offsets which were referenced by children of the current DIE. */
10710 sect_offset
*offsets
;
10711 sect_offset
*offsets_end
, *offsetp
;
10712 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
10713 struct die_info
*origin_die
;
10714 /* Iterator of the ORIGIN_DIE children. */
10715 struct die_info
*origin_child_die
;
10716 struct cleanup
*cleanups
;
10717 struct attribute
*attr
;
10718 struct dwarf2_cu
*origin_cu
;
10719 struct pending
**origin_previous_list_in_scope
;
10721 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
10725 /* Note that following die references may follow to a die in a
10729 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
10731 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
10733 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
10734 origin_cu
->list_in_scope
= cu
->list_in_scope
;
10736 if (die
->tag
!= origin_die
->tag
10737 && !(die
->tag
== DW_TAG_inlined_subroutine
10738 && origin_die
->tag
== DW_TAG_subprogram
))
10739 complaint (&symfile_complaints
,
10740 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
10741 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
10743 child_die
= die
->child
;
10744 die_children_count
= 0;
10745 while (child_die
&& child_die
->tag
)
10747 child_die
= sibling_die (child_die
);
10748 die_children_count
++;
10750 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
10751 cleanups
= make_cleanup (xfree
, offsets
);
10753 offsets_end
= offsets
;
10754 child_die
= die
->child
;
10755 while (child_die
&& child_die
->tag
)
10757 /* For each CHILD_DIE, find the corresponding child of
10758 ORIGIN_DIE. If there is more than one layer of
10759 DW_AT_abstract_origin, follow them all; there shouldn't be,
10760 but GCC versions at least through 4.4 generate this (GCC PR
10762 struct die_info
*child_origin_die
= child_die
;
10763 struct dwarf2_cu
*child_origin_cu
= cu
;
10767 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
10771 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
10775 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
10776 counterpart may exist. */
10777 if (child_origin_die
!= child_die
)
10779 if (child_die
->tag
!= child_origin_die
->tag
10780 && !(child_die
->tag
== DW_TAG_inlined_subroutine
10781 && child_origin_die
->tag
== DW_TAG_subprogram
))
10782 complaint (&symfile_complaints
,
10783 _("Child DIE 0x%x and its abstract origin 0x%x have "
10784 "different tags"), child_die
->offset
.sect_off
,
10785 child_origin_die
->offset
.sect_off
);
10786 if (child_origin_die
->parent
!= origin_die
)
10787 complaint (&symfile_complaints
,
10788 _("Child DIE 0x%x and its abstract origin 0x%x have "
10789 "different parents"), child_die
->offset
.sect_off
,
10790 child_origin_die
->offset
.sect_off
);
10792 *offsets_end
++ = child_origin_die
->offset
;
10794 child_die
= sibling_die (child_die
);
10796 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
10797 unsigned_int_compar
);
10798 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
10799 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
10800 complaint (&symfile_complaints
,
10801 _("Multiple children of DIE 0x%x refer "
10802 "to DIE 0x%x as their abstract origin"),
10803 die
->offset
.sect_off
, offsetp
->sect_off
);
10806 origin_child_die
= origin_die
->child
;
10807 while (origin_child_die
&& origin_child_die
->tag
)
10809 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
10810 while (offsetp
< offsets_end
10811 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
10813 if (offsetp
>= offsets_end
10814 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
10816 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
10817 process_die (origin_child_die
, origin_cu
);
10819 origin_child_die
= sibling_die (origin_child_die
);
10821 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
10823 do_cleanups (cleanups
);
10827 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10829 struct objfile
*objfile
= cu
->objfile
;
10830 struct context_stack
*new;
10833 struct die_info
*child_die
;
10834 struct attribute
*attr
, *call_line
, *call_file
;
10836 CORE_ADDR baseaddr
;
10837 struct block
*block
;
10838 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10839 VEC (symbolp
) *template_args
= NULL
;
10840 struct template_symbol
*templ_func
= NULL
;
10844 /* If we do not have call site information, we can't show the
10845 caller of this inlined function. That's too confusing, so
10846 only use the scope for local variables. */
10847 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
10848 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
10849 if (call_line
== NULL
|| call_file
== NULL
)
10851 read_lexical_block_scope (die
, cu
);
10856 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10858 name
= dwarf2_name (die
, cu
);
10860 /* Ignore functions with missing or empty names. These are actually
10861 illegal according to the DWARF standard. */
10864 complaint (&symfile_complaints
,
10865 _("missing name for subprogram DIE at %d"),
10866 die
->offset
.sect_off
);
10870 /* Ignore functions with missing or invalid low and high pc attributes. */
10871 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
10873 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10874 if (!attr
|| !DW_UNSND (attr
))
10875 complaint (&symfile_complaints
,
10876 _("cannot get low and high bounds "
10877 "for subprogram DIE at %d"),
10878 die
->offset
.sect_off
);
10883 highpc
+= baseaddr
;
10885 /* If we have any template arguments, then we must allocate a
10886 different sort of symbol. */
10887 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
10889 if (child_die
->tag
== DW_TAG_template_type_param
10890 || child_die
->tag
== DW_TAG_template_value_param
)
10892 templ_func
= allocate_template_symbol (objfile
);
10893 templ_func
->base
.is_cplus_template_function
= 1;
10898 new = push_context (0, lowpc
);
10899 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
10900 (struct symbol
*) templ_func
);
10902 /* If there is a location expression for DW_AT_frame_base, record
10904 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
10906 dwarf2_symbol_mark_computed (attr
, new->name
, cu
, 1);
10908 cu
->list_in_scope
= &local_symbols
;
10910 if (die
->child
!= NULL
)
10912 child_die
= die
->child
;
10913 while (child_die
&& child_die
->tag
)
10915 if (child_die
->tag
== DW_TAG_template_type_param
10916 || child_die
->tag
== DW_TAG_template_value_param
)
10918 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
10921 VEC_safe_push (symbolp
, template_args
, arg
);
10924 process_die (child_die
, cu
);
10925 child_die
= sibling_die (child_die
);
10929 inherit_abstract_dies (die
, cu
);
10931 /* If we have a DW_AT_specification, we might need to import using
10932 directives from the context of the specification DIE. See the
10933 comment in determine_prefix. */
10934 if (cu
->language
== language_cplus
10935 && dwarf2_attr (die
, DW_AT_specification
, cu
))
10937 struct dwarf2_cu
*spec_cu
= cu
;
10938 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
10942 child_die
= spec_die
->child
;
10943 while (child_die
&& child_die
->tag
)
10945 if (child_die
->tag
== DW_TAG_imported_module
)
10946 process_die (child_die
, spec_cu
);
10947 child_die
= sibling_die (child_die
);
10950 /* In some cases, GCC generates specification DIEs that
10951 themselves contain DW_AT_specification attributes. */
10952 spec_die
= die_specification (spec_die
, &spec_cu
);
10956 new = pop_context ();
10957 /* Make a block for the local symbols within. */
10958 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
10959 lowpc
, highpc
, objfile
);
10961 /* For C++, set the block's scope. */
10962 if ((cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
10963 && cu
->processing_has_namespace_info
)
10964 block_set_scope (block
, determine_prefix (die
, cu
),
10965 &objfile
->objfile_obstack
);
10967 /* If we have address ranges, record them. */
10968 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
10970 /* Attach template arguments to function. */
10971 if (! VEC_empty (symbolp
, template_args
))
10973 gdb_assert (templ_func
!= NULL
);
10975 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
10976 templ_func
->template_arguments
10977 = obstack_alloc (&objfile
->objfile_obstack
,
10978 (templ_func
->n_template_arguments
10979 * sizeof (struct symbol
*)));
10980 memcpy (templ_func
->template_arguments
,
10981 VEC_address (symbolp
, template_args
),
10982 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
10983 VEC_free (symbolp
, template_args
);
10986 /* In C++, we can have functions nested inside functions (e.g., when
10987 a function declares a class that has methods). This means that
10988 when we finish processing a function scope, we may need to go
10989 back to building a containing block's symbol lists. */
10990 local_symbols
= new->locals
;
10991 using_directives
= new->using_directives
;
10993 /* If we've finished processing a top-level function, subsequent
10994 symbols go in the file symbol list. */
10995 if (outermost_context_p ())
10996 cu
->list_in_scope
= &file_symbols
;
10999 /* Process all the DIES contained within a lexical block scope. Start
11000 a new scope, process the dies, and then close the scope. */
11003 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11005 struct objfile
*objfile
= cu
->objfile
;
11006 struct context_stack
*new;
11007 CORE_ADDR lowpc
, highpc
;
11008 struct die_info
*child_die
;
11009 CORE_ADDR baseaddr
;
11011 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11013 /* Ignore blocks with missing or invalid low and high pc attributes. */
11014 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
11015 as multiple lexical blocks? Handling children in a sane way would
11016 be nasty. Might be easier to properly extend generic blocks to
11017 describe ranges. */
11018 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
11021 highpc
+= baseaddr
;
11023 push_context (0, lowpc
);
11024 if (die
->child
!= NULL
)
11026 child_die
= die
->child
;
11027 while (child_die
&& child_die
->tag
)
11029 process_die (child_die
, cu
);
11030 child_die
= sibling_die (child_die
);
11033 new = pop_context ();
11035 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
11037 struct block
*block
11038 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
11041 /* Note that recording ranges after traversing children, as we
11042 do here, means that recording a parent's ranges entails
11043 walking across all its children's ranges as they appear in
11044 the address map, which is quadratic behavior.
11046 It would be nicer to record the parent's ranges before
11047 traversing its children, simply overriding whatever you find
11048 there. But since we don't even decide whether to create a
11049 block until after we've traversed its children, that's hard
11051 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11053 local_symbols
= new->locals
;
11054 using_directives
= new->using_directives
;
11057 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
11060 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11062 struct objfile
*objfile
= cu
->objfile
;
11063 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11064 CORE_ADDR pc
, baseaddr
;
11065 struct attribute
*attr
;
11066 struct call_site
*call_site
, call_site_local
;
11069 struct die_info
*child_die
;
11071 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11073 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11076 complaint (&symfile_complaints
,
11077 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
11078 "DIE 0x%x [in module %s]"),
11079 die
->offset
.sect_off
, objfile_name (objfile
));
11082 pc
= DW_ADDR (attr
) + baseaddr
;
11084 if (cu
->call_site_htab
== NULL
)
11085 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
11086 NULL
, &objfile
->objfile_obstack
,
11087 hashtab_obstack_allocate
, NULL
);
11088 call_site_local
.pc
= pc
;
11089 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
11092 complaint (&symfile_complaints
,
11093 _("Duplicate PC %s for DW_TAG_GNU_call_site "
11094 "DIE 0x%x [in module %s]"),
11095 paddress (gdbarch
, pc
), die
->offset
.sect_off
,
11096 objfile_name (objfile
));
11100 /* Count parameters at the caller. */
11103 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11104 child_die
= sibling_die (child_die
))
11106 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11108 complaint (&symfile_complaints
,
11109 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
11110 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11111 child_die
->tag
, child_die
->offset
.sect_off
,
11112 objfile_name (objfile
));
11119 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
11120 (sizeof (*call_site
)
11121 + (sizeof (*call_site
->parameter
)
11122 * (nparams
- 1))));
11124 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
11125 call_site
->pc
= pc
;
11127 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
11129 struct die_info
*func_die
;
11131 /* Skip also over DW_TAG_inlined_subroutine. */
11132 for (func_die
= die
->parent
;
11133 func_die
&& func_die
->tag
!= DW_TAG_subprogram
11134 && func_die
->tag
!= DW_TAG_subroutine_type
;
11135 func_die
= func_die
->parent
);
11137 /* DW_AT_GNU_all_call_sites is a superset
11138 of DW_AT_GNU_all_tail_call_sites. */
11140 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
11141 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
11143 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
11144 not complete. But keep CALL_SITE for look ups via call_site_htab,
11145 both the initial caller containing the real return address PC and
11146 the final callee containing the current PC of a chain of tail
11147 calls do not need to have the tail call list complete. But any
11148 function candidate for a virtual tail call frame searched via
11149 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
11150 determined unambiguously. */
11154 struct type
*func_type
= NULL
;
11157 func_type
= get_die_type (func_die
, cu
);
11158 if (func_type
!= NULL
)
11160 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
11162 /* Enlist this call site to the function. */
11163 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
11164 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
11167 complaint (&symfile_complaints
,
11168 _("Cannot find function owning DW_TAG_GNU_call_site "
11169 "DIE 0x%x [in module %s]"),
11170 die
->offset
.sect_off
, objfile_name (objfile
));
11174 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
11176 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11177 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
11178 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
11179 /* Keep NULL DWARF_BLOCK. */;
11180 else if (attr_form_is_block (attr
))
11182 struct dwarf2_locexpr_baton
*dlbaton
;
11184 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
11185 dlbaton
->data
= DW_BLOCK (attr
)->data
;
11186 dlbaton
->size
= DW_BLOCK (attr
)->size
;
11187 dlbaton
->per_cu
= cu
->per_cu
;
11189 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
11191 else if (attr_form_is_ref (attr
))
11193 struct dwarf2_cu
*target_cu
= cu
;
11194 struct die_info
*target_die
;
11196 target_die
= follow_die_ref (die
, attr
, &target_cu
);
11197 gdb_assert (target_cu
->objfile
== objfile
);
11198 if (die_is_declaration (target_die
, target_cu
))
11200 const char *target_physname
= NULL
;
11201 struct attribute
*target_attr
;
11203 /* Prefer the mangled name; otherwise compute the demangled one. */
11204 target_attr
= dwarf2_attr (target_die
, DW_AT_linkage_name
, target_cu
);
11205 if (target_attr
== NULL
)
11206 target_attr
= dwarf2_attr (target_die
, DW_AT_MIPS_linkage_name
,
11208 if (target_attr
!= NULL
&& DW_STRING (target_attr
) != NULL
)
11209 target_physname
= DW_STRING (target_attr
);
11211 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
11212 if (target_physname
== NULL
)
11213 complaint (&symfile_complaints
,
11214 _("DW_AT_GNU_call_site_target target DIE has invalid "
11215 "physname, for referencing DIE 0x%x [in module %s]"),
11216 die
->offset
.sect_off
, objfile_name (objfile
));
11218 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
11224 /* DW_AT_entry_pc should be preferred. */
11225 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
11226 complaint (&symfile_complaints
,
11227 _("DW_AT_GNU_call_site_target target DIE has invalid "
11228 "low pc, for referencing DIE 0x%x [in module %s]"),
11229 die
->offset
.sect_off
, objfile_name (objfile
));
11231 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
11235 complaint (&symfile_complaints
,
11236 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
11237 "block nor reference, for DIE 0x%x [in module %s]"),
11238 die
->offset
.sect_off
, objfile_name (objfile
));
11240 call_site
->per_cu
= cu
->per_cu
;
11242 for (child_die
= die
->child
;
11243 child_die
&& child_die
->tag
;
11244 child_die
= sibling_die (child_die
))
11246 struct call_site_parameter
*parameter
;
11247 struct attribute
*loc
, *origin
;
11249 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11251 /* Already printed the complaint above. */
11255 gdb_assert (call_site
->parameter_count
< nparams
);
11256 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
11258 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
11259 specifies DW_TAG_formal_parameter. Value of the data assumed for the
11260 register is contained in DW_AT_GNU_call_site_value. */
11262 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
11263 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
11264 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
11266 sect_offset offset
;
11268 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
11269 offset
= dwarf2_get_ref_die_offset (origin
);
11270 if (!offset_in_cu_p (&cu
->header
, offset
))
11272 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
11273 binding can be done only inside one CU. Such referenced DIE
11274 therefore cannot be even moved to DW_TAG_partial_unit. */
11275 complaint (&symfile_complaints
,
11276 _("DW_AT_abstract_origin offset is not in CU for "
11277 "DW_TAG_GNU_call_site child DIE 0x%x "
11279 child_die
->offset
.sect_off
, objfile_name (objfile
));
11282 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
11283 - cu
->header
.offset
.sect_off
);
11285 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
11287 complaint (&symfile_complaints
,
11288 _("No DW_FORM_block* DW_AT_location for "
11289 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11290 child_die
->offset
.sect_off
, objfile_name (objfile
));
11295 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
11296 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
11297 if (parameter
->u
.dwarf_reg
!= -1)
11298 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
11299 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
11300 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
11301 ¶meter
->u
.fb_offset
))
11302 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
11305 complaint (&symfile_complaints
,
11306 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
11307 "for DW_FORM_block* DW_AT_location is supported for "
11308 "DW_TAG_GNU_call_site child DIE 0x%x "
11310 child_die
->offset
.sect_off
, objfile_name (objfile
));
11315 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
11316 if (!attr_form_is_block (attr
))
11318 complaint (&symfile_complaints
,
11319 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
11320 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11321 child_die
->offset
.sect_off
, objfile_name (objfile
));
11324 parameter
->value
= DW_BLOCK (attr
)->data
;
11325 parameter
->value_size
= DW_BLOCK (attr
)->size
;
11327 /* Parameters are not pre-cleared by memset above. */
11328 parameter
->data_value
= NULL
;
11329 parameter
->data_value_size
= 0;
11330 call_site
->parameter_count
++;
11332 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
11335 if (!attr_form_is_block (attr
))
11336 complaint (&symfile_complaints
,
11337 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
11338 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11339 child_die
->offset
.sect_off
, objfile_name (objfile
));
11342 parameter
->data_value
= DW_BLOCK (attr
)->data
;
11343 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
11349 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
11350 Return 1 if the attributes are present and valid, otherwise, return 0.
11351 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
11354 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
11355 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
11356 struct partial_symtab
*ranges_pst
)
11358 struct objfile
*objfile
= cu
->objfile
;
11359 struct comp_unit_head
*cu_header
= &cu
->header
;
11360 bfd
*obfd
= objfile
->obfd
;
11361 unsigned int addr_size
= cu_header
->addr_size
;
11362 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
11363 /* Base address selection entry. */
11366 unsigned int dummy
;
11367 const gdb_byte
*buffer
;
11371 CORE_ADDR high
= 0;
11372 CORE_ADDR baseaddr
;
11374 found_base
= cu
->base_known
;
11375 base
= cu
->base_address
;
11377 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
11378 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
11380 complaint (&symfile_complaints
,
11381 _("Offset %d out of bounds for DW_AT_ranges attribute"),
11385 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
11387 /* Read in the largest possible address. */
11388 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
11389 if ((marker
& mask
) == mask
)
11391 /* If we found the largest possible address, then
11392 read the base address. */
11393 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
11394 buffer
+= 2 * addr_size
;
11395 offset
+= 2 * addr_size
;
11401 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11405 CORE_ADDR range_beginning
, range_end
;
11407 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
11408 buffer
+= addr_size
;
11409 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
11410 buffer
+= addr_size
;
11411 offset
+= 2 * addr_size
;
11413 /* An end of list marker is a pair of zero addresses. */
11414 if (range_beginning
== 0 && range_end
== 0)
11415 /* Found the end of list entry. */
11418 /* Each base address selection entry is a pair of 2 values.
11419 The first is the largest possible address, the second is
11420 the base address. Check for a base address here. */
11421 if ((range_beginning
& mask
) == mask
)
11423 /* If we found the largest possible address, then
11424 read the base address. */
11425 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
11432 /* We have no valid base address for the ranges
11434 complaint (&symfile_complaints
,
11435 _("Invalid .debug_ranges data (no base address)"));
11439 if (range_beginning
> range_end
)
11441 /* Inverted range entries are invalid. */
11442 complaint (&symfile_complaints
,
11443 _("Invalid .debug_ranges data (inverted range)"));
11447 /* Empty range entries have no effect. */
11448 if (range_beginning
== range_end
)
11451 range_beginning
+= base
;
11454 /* A not-uncommon case of bad debug info.
11455 Don't pollute the addrmap with bad data. */
11456 if (range_beginning
+ baseaddr
== 0
11457 && !dwarf2_per_objfile
->has_section_at_zero
)
11459 complaint (&symfile_complaints
,
11460 _(".debug_ranges entry has start address of zero"
11461 " [in module %s]"), objfile_name (objfile
));
11465 if (ranges_pst
!= NULL
)
11466 addrmap_set_empty (objfile
->psymtabs_addrmap
,
11467 range_beginning
+ baseaddr
,
11468 range_end
- 1 + baseaddr
,
11471 /* FIXME: This is recording everything as a low-high
11472 segment of consecutive addresses. We should have a
11473 data structure for discontiguous block ranges
11477 low
= range_beginning
;
11483 if (range_beginning
< low
)
11484 low
= range_beginning
;
11485 if (range_end
> high
)
11491 /* If the first entry is an end-of-list marker, the range
11492 describes an empty scope, i.e. no instructions. */
11498 *high_return
= high
;
11502 /* Get low and high pc attributes from a die. Return 1 if the attributes
11503 are present and valid, otherwise, return 0. Return -1 if the range is
11504 discontinuous, i.e. derived from DW_AT_ranges information. */
11507 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
11508 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
11509 struct partial_symtab
*pst
)
11511 struct attribute
*attr
;
11512 struct attribute
*attr_high
;
11514 CORE_ADDR high
= 0;
11517 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
11520 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11523 low
= DW_ADDR (attr
);
11524 if (attr_high
->form
== DW_FORM_addr
11525 || attr_high
->form
== DW_FORM_GNU_addr_index
)
11526 high
= DW_ADDR (attr_high
);
11528 high
= low
+ DW_UNSND (attr_high
);
11531 /* Found high w/o low attribute. */
11534 /* Found consecutive range of addresses. */
11539 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
11542 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
11543 We take advantage of the fact that DW_AT_ranges does not appear
11544 in DW_TAG_compile_unit of DWO files. */
11545 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
11546 unsigned int ranges_offset
= (DW_UNSND (attr
)
11547 + (need_ranges_base
11551 /* Value of the DW_AT_ranges attribute is the offset in the
11552 .debug_ranges section. */
11553 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
11555 /* Found discontinuous range of addresses. */
11560 /* read_partial_die has also the strict LOW < HIGH requirement. */
11564 /* When using the GNU linker, .gnu.linkonce. sections are used to
11565 eliminate duplicate copies of functions and vtables and such.
11566 The linker will arbitrarily choose one and discard the others.
11567 The AT_*_pc values for such functions refer to local labels in
11568 these sections. If the section from that file was discarded, the
11569 labels are not in the output, so the relocs get a value of 0.
11570 If this is a discarded function, mark the pc bounds as invalid,
11571 so that GDB will ignore it. */
11572 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11581 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
11582 its low and high PC addresses. Do nothing if these addresses could not
11583 be determined. Otherwise, set LOWPC to the low address if it is smaller,
11584 and HIGHPC to the high address if greater than HIGHPC. */
11587 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
11588 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
11589 struct dwarf2_cu
*cu
)
11591 CORE_ADDR low
, high
;
11592 struct die_info
*child
= die
->child
;
11594 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
11596 *lowpc
= min (*lowpc
, low
);
11597 *highpc
= max (*highpc
, high
);
11600 /* If the language does not allow nested subprograms (either inside
11601 subprograms or lexical blocks), we're done. */
11602 if (cu
->language
!= language_ada
)
11605 /* Check all the children of the given DIE. If it contains nested
11606 subprograms, then check their pc bounds. Likewise, we need to
11607 check lexical blocks as well, as they may also contain subprogram
11609 while (child
&& child
->tag
)
11611 if (child
->tag
== DW_TAG_subprogram
11612 || child
->tag
== DW_TAG_lexical_block
)
11613 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
11614 child
= sibling_die (child
);
11618 /* Get the low and high pc's represented by the scope DIE, and store
11619 them in *LOWPC and *HIGHPC. If the correct values can't be
11620 determined, set *LOWPC to -1 and *HIGHPC to 0. */
11623 get_scope_pc_bounds (struct die_info
*die
,
11624 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
11625 struct dwarf2_cu
*cu
)
11627 CORE_ADDR best_low
= (CORE_ADDR
) -1;
11628 CORE_ADDR best_high
= (CORE_ADDR
) 0;
11629 CORE_ADDR current_low
, current_high
;
11631 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
11633 best_low
= current_low
;
11634 best_high
= current_high
;
11638 struct die_info
*child
= die
->child
;
11640 while (child
&& child
->tag
)
11642 switch (child
->tag
) {
11643 case DW_TAG_subprogram
:
11644 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
11646 case DW_TAG_namespace
:
11647 case DW_TAG_module
:
11648 /* FIXME: carlton/2004-01-16: Should we do this for
11649 DW_TAG_class_type/DW_TAG_structure_type, too? I think
11650 that current GCC's always emit the DIEs corresponding
11651 to definitions of methods of classes as children of a
11652 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
11653 the DIEs giving the declarations, which could be
11654 anywhere). But I don't see any reason why the
11655 standards says that they have to be there. */
11656 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
11658 if (current_low
!= ((CORE_ADDR
) -1))
11660 best_low
= min (best_low
, current_low
);
11661 best_high
= max (best_high
, current_high
);
11669 child
= sibling_die (child
);
11674 *highpc
= best_high
;
11677 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
11681 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
11682 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
11684 struct objfile
*objfile
= cu
->objfile
;
11685 struct attribute
*attr
;
11686 struct attribute
*attr_high
;
11688 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
11691 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11694 CORE_ADDR low
= DW_ADDR (attr
);
11696 if (attr_high
->form
== DW_FORM_addr
11697 || attr_high
->form
== DW_FORM_GNU_addr_index
)
11698 high
= DW_ADDR (attr_high
);
11700 high
= low
+ DW_UNSND (attr_high
);
11702 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
11706 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
11709 bfd
*obfd
= objfile
->obfd
;
11710 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
11711 We take advantage of the fact that DW_AT_ranges does not appear
11712 in DW_TAG_compile_unit of DWO files. */
11713 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
11715 /* The value of the DW_AT_ranges attribute is the offset of the
11716 address range list in the .debug_ranges section. */
11717 unsigned long offset
= (DW_UNSND (attr
)
11718 + (need_ranges_base
? cu
->ranges_base
: 0));
11719 const gdb_byte
*buffer
;
11721 /* For some target architectures, but not others, the
11722 read_address function sign-extends the addresses it returns.
11723 To recognize base address selection entries, we need a
11725 unsigned int addr_size
= cu
->header
.addr_size
;
11726 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
11728 /* The base address, to which the next pair is relative. Note
11729 that this 'base' is a DWARF concept: most entries in a range
11730 list are relative, to reduce the number of relocs against the
11731 debugging information. This is separate from this function's
11732 'baseaddr' argument, which GDB uses to relocate debugging
11733 information from a shared library based on the address at
11734 which the library was loaded. */
11735 CORE_ADDR base
= cu
->base_address
;
11736 int base_known
= cu
->base_known
;
11738 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
11739 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
11741 complaint (&symfile_complaints
,
11742 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
11746 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
11750 unsigned int bytes_read
;
11751 CORE_ADDR start
, end
;
11753 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
11754 buffer
+= bytes_read
;
11755 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
11756 buffer
+= bytes_read
;
11758 /* Did we find the end of the range list? */
11759 if (start
== 0 && end
== 0)
11762 /* Did we find a base address selection entry? */
11763 else if ((start
& base_select_mask
) == base_select_mask
)
11769 /* We found an ordinary address range. */
11774 complaint (&symfile_complaints
,
11775 _("Invalid .debug_ranges data "
11776 "(no base address)"));
11782 /* Inverted range entries are invalid. */
11783 complaint (&symfile_complaints
,
11784 _("Invalid .debug_ranges data "
11785 "(inverted range)"));
11789 /* Empty range entries have no effect. */
11793 start
+= base
+ baseaddr
;
11794 end
+= base
+ baseaddr
;
11796 /* A not-uncommon case of bad debug info.
11797 Don't pollute the addrmap with bad data. */
11798 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11800 complaint (&symfile_complaints
,
11801 _(".debug_ranges entry has start address of zero"
11802 " [in module %s]"), objfile_name (objfile
));
11806 record_block_range (block
, start
, end
- 1);
11812 /* Check whether the producer field indicates either of GCC < 4.6, or the
11813 Intel C/C++ compiler, and cache the result in CU. */
11816 check_producer (struct dwarf2_cu
*cu
)
11819 int major
, minor
, release
;
11821 if (cu
->producer
== NULL
)
11823 /* For unknown compilers expect their behavior is DWARF version
11826 GCC started to support .debug_types sections by -gdwarf-4 since
11827 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
11828 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
11829 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
11830 interpreted incorrectly by GDB now - GCC PR debug/48229. */
11832 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
11834 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
11836 cs
= &cu
->producer
[strlen ("GNU ")];
11837 while (*cs
&& !isdigit (*cs
))
11839 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
11841 /* Not recognized as GCC. */
11845 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
11846 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
11849 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
11850 cu
->producer_is_icc
= 1;
11853 /* For other non-GCC compilers, expect their behavior is DWARF version
11857 cu
->checked_producer
= 1;
11860 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
11861 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
11862 during 4.6.0 experimental. */
11865 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
11867 if (!cu
->checked_producer
)
11868 check_producer (cu
);
11870 return cu
->producer_is_gxx_lt_4_6
;
11873 /* Return the default accessibility type if it is not overriden by
11874 DW_AT_accessibility. */
11876 static enum dwarf_access_attribute
11877 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
11879 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
11881 /* The default DWARF 2 accessibility for members is public, the default
11882 accessibility for inheritance is private. */
11884 if (die
->tag
!= DW_TAG_inheritance
)
11885 return DW_ACCESS_public
;
11887 return DW_ACCESS_private
;
11891 /* DWARF 3+ defines the default accessibility a different way. The same
11892 rules apply now for DW_TAG_inheritance as for the members and it only
11893 depends on the container kind. */
11895 if (die
->parent
->tag
== DW_TAG_class_type
)
11896 return DW_ACCESS_private
;
11898 return DW_ACCESS_public
;
11902 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
11903 offset. If the attribute was not found return 0, otherwise return
11904 1. If it was found but could not properly be handled, set *OFFSET
11908 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
11911 struct attribute
*attr
;
11913 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
11918 /* Note that we do not check for a section offset first here.
11919 This is because DW_AT_data_member_location is new in DWARF 4,
11920 so if we see it, we can assume that a constant form is really
11921 a constant and not a section offset. */
11922 if (attr_form_is_constant (attr
))
11923 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
11924 else if (attr_form_is_section_offset (attr
))
11925 dwarf2_complex_location_expr_complaint ();
11926 else if (attr_form_is_block (attr
))
11927 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
11929 dwarf2_complex_location_expr_complaint ();
11937 /* Add an aggregate field to the field list. */
11940 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
11941 struct dwarf2_cu
*cu
)
11943 struct objfile
*objfile
= cu
->objfile
;
11944 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11945 struct nextfield
*new_field
;
11946 struct attribute
*attr
;
11948 const char *fieldname
= "";
11950 /* Allocate a new field list entry and link it in. */
11951 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
11952 make_cleanup (xfree
, new_field
);
11953 memset (new_field
, 0, sizeof (struct nextfield
));
11955 if (die
->tag
== DW_TAG_inheritance
)
11957 new_field
->next
= fip
->baseclasses
;
11958 fip
->baseclasses
= new_field
;
11962 new_field
->next
= fip
->fields
;
11963 fip
->fields
= new_field
;
11967 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
11969 new_field
->accessibility
= DW_UNSND (attr
);
11971 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
11972 if (new_field
->accessibility
!= DW_ACCESS_public
)
11973 fip
->non_public_fields
= 1;
11975 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
11977 new_field
->virtuality
= DW_UNSND (attr
);
11979 new_field
->virtuality
= DW_VIRTUALITY_none
;
11981 fp
= &new_field
->field
;
11983 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
11987 /* Data member other than a C++ static data member. */
11989 /* Get type of field. */
11990 fp
->type
= die_type (die
, cu
);
11992 SET_FIELD_BITPOS (*fp
, 0);
11994 /* Get bit size of field (zero if none). */
11995 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
11998 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
12002 FIELD_BITSIZE (*fp
) = 0;
12005 /* Get bit offset of field. */
12006 if (handle_data_member_location (die
, cu
, &offset
))
12007 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12008 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
12011 if (gdbarch_bits_big_endian (gdbarch
))
12013 /* For big endian bits, the DW_AT_bit_offset gives the
12014 additional bit offset from the MSB of the containing
12015 anonymous object to the MSB of the field. We don't
12016 have to do anything special since we don't need to
12017 know the size of the anonymous object. */
12018 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
12022 /* For little endian bits, compute the bit offset to the
12023 MSB of the anonymous object, subtract off the number of
12024 bits from the MSB of the field to the MSB of the
12025 object, and then subtract off the number of bits of
12026 the field itself. The result is the bit offset of
12027 the LSB of the field. */
12028 int anonymous_size
;
12029 int bit_offset
= DW_UNSND (attr
);
12031 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12034 /* The size of the anonymous object containing
12035 the bit field is explicit, so use the
12036 indicated size (in bytes). */
12037 anonymous_size
= DW_UNSND (attr
);
12041 /* The size of the anonymous object containing
12042 the bit field must be inferred from the type
12043 attribute of the data member containing the
12045 anonymous_size
= TYPE_LENGTH (fp
->type
);
12047 SET_FIELD_BITPOS (*fp
,
12048 (FIELD_BITPOS (*fp
)
12049 + anonymous_size
* bits_per_byte
12050 - bit_offset
- FIELD_BITSIZE (*fp
)));
12054 /* Get name of field. */
12055 fieldname
= dwarf2_name (die
, cu
);
12056 if (fieldname
== NULL
)
12059 /* The name is already allocated along with this objfile, so we don't
12060 need to duplicate it for the type. */
12061 fp
->name
= fieldname
;
12063 /* Change accessibility for artificial fields (e.g. virtual table
12064 pointer or virtual base class pointer) to private. */
12065 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
12067 FIELD_ARTIFICIAL (*fp
) = 1;
12068 new_field
->accessibility
= DW_ACCESS_private
;
12069 fip
->non_public_fields
= 1;
12072 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
12074 /* C++ static member. */
12076 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
12077 is a declaration, but all versions of G++ as of this writing
12078 (so through at least 3.2.1) incorrectly generate
12079 DW_TAG_variable tags. */
12081 const char *physname
;
12083 /* Get name of field. */
12084 fieldname
= dwarf2_name (die
, cu
);
12085 if (fieldname
== NULL
)
12088 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12090 /* Only create a symbol if this is an external value.
12091 new_symbol checks this and puts the value in the global symbol
12092 table, which we want. If it is not external, new_symbol
12093 will try to put the value in cu->list_in_scope which is wrong. */
12094 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
12096 /* A static const member, not much different than an enum as far as
12097 we're concerned, except that we can support more types. */
12098 new_symbol (die
, NULL
, cu
);
12101 /* Get physical name. */
12102 physname
= dwarf2_physname (fieldname
, die
, cu
);
12104 /* The name is already allocated along with this objfile, so we don't
12105 need to duplicate it for the type. */
12106 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
12107 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12108 FIELD_NAME (*fp
) = fieldname
;
12110 else if (die
->tag
== DW_TAG_inheritance
)
12114 /* C++ base class field. */
12115 if (handle_data_member_location (die
, cu
, &offset
))
12116 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12117 FIELD_BITSIZE (*fp
) = 0;
12118 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12119 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
12120 fip
->nbaseclasses
++;
12124 /* Add a typedef defined in the scope of the FIP's class. */
12127 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
12128 struct dwarf2_cu
*cu
)
12130 struct objfile
*objfile
= cu
->objfile
;
12131 struct typedef_field_list
*new_field
;
12132 struct attribute
*attr
;
12133 struct typedef_field
*fp
;
12134 char *fieldname
= "";
12136 /* Allocate a new field list entry and link it in. */
12137 new_field
= xzalloc (sizeof (*new_field
));
12138 make_cleanup (xfree
, new_field
);
12140 gdb_assert (die
->tag
== DW_TAG_typedef
);
12142 fp
= &new_field
->field
;
12144 /* Get name of field. */
12145 fp
->name
= dwarf2_name (die
, cu
);
12146 if (fp
->name
== NULL
)
12149 fp
->type
= read_type_die (die
, cu
);
12151 new_field
->next
= fip
->typedef_field_list
;
12152 fip
->typedef_field_list
= new_field
;
12153 fip
->typedef_field_list_count
++;
12156 /* Create the vector of fields, and attach it to the type. */
12159 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
12160 struct dwarf2_cu
*cu
)
12162 int nfields
= fip
->nfields
;
12164 /* Record the field count, allocate space for the array of fields,
12165 and create blank accessibility bitfields if necessary. */
12166 TYPE_NFIELDS (type
) = nfields
;
12167 TYPE_FIELDS (type
) = (struct field
*)
12168 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
12169 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
12171 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
12173 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12175 TYPE_FIELD_PRIVATE_BITS (type
) =
12176 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12177 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
12179 TYPE_FIELD_PROTECTED_BITS (type
) =
12180 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12181 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
12183 TYPE_FIELD_IGNORE_BITS (type
) =
12184 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12185 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
12188 /* If the type has baseclasses, allocate and clear a bit vector for
12189 TYPE_FIELD_VIRTUAL_BITS. */
12190 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
12192 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
12193 unsigned char *pointer
;
12195 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12196 pointer
= TYPE_ALLOC (type
, num_bytes
);
12197 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
12198 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
12199 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
12202 /* Copy the saved-up fields into the field vector. Start from the head of
12203 the list, adding to the tail of the field array, so that they end up in
12204 the same order in the array in which they were added to the list. */
12205 while (nfields
-- > 0)
12207 struct nextfield
*fieldp
;
12211 fieldp
= fip
->fields
;
12212 fip
->fields
= fieldp
->next
;
12216 fieldp
= fip
->baseclasses
;
12217 fip
->baseclasses
= fieldp
->next
;
12220 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
12221 switch (fieldp
->accessibility
)
12223 case DW_ACCESS_private
:
12224 if (cu
->language
!= language_ada
)
12225 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
12228 case DW_ACCESS_protected
:
12229 if (cu
->language
!= language_ada
)
12230 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
12233 case DW_ACCESS_public
:
12237 /* Unknown accessibility. Complain and treat it as public. */
12239 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
12240 fieldp
->accessibility
);
12244 if (nfields
< fip
->nbaseclasses
)
12246 switch (fieldp
->virtuality
)
12248 case DW_VIRTUALITY_virtual
:
12249 case DW_VIRTUALITY_pure_virtual
:
12250 if (cu
->language
== language_ada
)
12251 error (_("unexpected virtuality in component of Ada type"));
12252 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
12259 /* Return true if this member function is a constructor, false
12263 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
12265 const char *fieldname
;
12266 const char *typename
;
12269 if (die
->parent
== NULL
)
12272 if (die
->parent
->tag
!= DW_TAG_structure_type
12273 && die
->parent
->tag
!= DW_TAG_union_type
12274 && die
->parent
->tag
!= DW_TAG_class_type
)
12277 fieldname
= dwarf2_name (die
, cu
);
12278 typename
= dwarf2_name (die
->parent
, cu
);
12279 if (fieldname
== NULL
|| typename
== NULL
)
12282 len
= strlen (fieldname
);
12283 return (strncmp (fieldname
, typename
, len
) == 0
12284 && (typename
[len
] == '\0' || typename
[len
] == '<'));
12287 /* Add a member function to the proper fieldlist. */
12290 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
12291 struct type
*type
, struct dwarf2_cu
*cu
)
12293 struct objfile
*objfile
= cu
->objfile
;
12294 struct attribute
*attr
;
12295 struct fnfieldlist
*flp
;
12297 struct fn_field
*fnp
;
12298 const char *fieldname
;
12299 struct nextfnfield
*new_fnfield
;
12300 struct type
*this_type
;
12301 enum dwarf_access_attribute accessibility
;
12303 if (cu
->language
== language_ada
)
12304 error (_("unexpected member function in Ada type"));
12306 /* Get name of member function. */
12307 fieldname
= dwarf2_name (die
, cu
);
12308 if (fieldname
== NULL
)
12311 /* Look up member function name in fieldlist. */
12312 for (i
= 0; i
< fip
->nfnfields
; i
++)
12314 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
12318 /* Create new list element if necessary. */
12319 if (i
< fip
->nfnfields
)
12320 flp
= &fip
->fnfieldlists
[i
];
12323 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
12325 fip
->fnfieldlists
= (struct fnfieldlist
*)
12326 xrealloc (fip
->fnfieldlists
,
12327 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
12328 * sizeof (struct fnfieldlist
));
12329 if (fip
->nfnfields
== 0)
12330 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
12332 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
12333 flp
->name
= fieldname
;
12336 i
= fip
->nfnfields
++;
12339 /* Create a new member function field and chain it to the field list
12341 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
12342 make_cleanup (xfree
, new_fnfield
);
12343 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
12344 new_fnfield
->next
= flp
->head
;
12345 flp
->head
= new_fnfield
;
12348 /* Fill in the member function field info. */
12349 fnp
= &new_fnfield
->fnfield
;
12351 /* Delay processing of the physname until later. */
12352 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
12354 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
12359 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
12360 fnp
->physname
= physname
? physname
: "";
12363 fnp
->type
= alloc_type (objfile
);
12364 this_type
= read_type_die (die
, cu
);
12365 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
12367 int nparams
= TYPE_NFIELDS (this_type
);
12369 /* TYPE is the domain of this method, and THIS_TYPE is the type
12370 of the method itself (TYPE_CODE_METHOD). */
12371 smash_to_method_type (fnp
->type
, type
,
12372 TYPE_TARGET_TYPE (this_type
),
12373 TYPE_FIELDS (this_type
),
12374 TYPE_NFIELDS (this_type
),
12375 TYPE_VARARGS (this_type
));
12377 /* Handle static member functions.
12378 Dwarf2 has no clean way to discern C++ static and non-static
12379 member functions. G++ helps GDB by marking the first
12380 parameter for non-static member functions (which is the this
12381 pointer) as artificial. We obtain this information from
12382 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
12383 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
12384 fnp
->voffset
= VOFFSET_STATIC
;
12387 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
12388 dwarf2_full_name (fieldname
, die
, cu
));
12390 /* Get fcontext from DW_AT_containing_type if present. */
12391 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
12392 fnp
->fcontext
= die_containing_type (die
, cu
);
12394 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
12395 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
12397 /* Get accessibility. */
12398 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
12400 accessibility
= DW_UNSND (attr
);
12402 accessibility
= dwarf2_default_access_attribute (die
, cu
);
12403 switch (accessibility
)
12405 case DW_ACCESS_private
:
12406 fnp
->is_private
= 1;
12408 case DW_ACCESS_protected
:
12409 fnp
->is_protected
= 1;
12413 /* Check for artificial methods. */
12414 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
12415 if (attr
&& DW_UNSND (attr
) != 0)
12416 fnp
->is_artificial
= 1;
12418 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
12420 /* Get index in virtual function table if it is a virtual member
12421 function. For older versions of GCC, this is an offset in the
12422 appropriate virtual table, as specified by DW_AT_containing_type.
12423 For everyone else, it is an expression to be evaluated relative
12424 to the object address. */
12426 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
12429 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
12431 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
12433 /* Old-style GCC. */
12434 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
12436 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
12437 || (DW_BLOCK (attr
)->size
> 1
12438 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
12439 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
12441 struct dwarf_block blk
;
12444 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
12446 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
12447 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
12448 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
12449 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
12450 dwarf2_complex_location_expr_complaint ();
12452 fnp
->voffset
/= cu
->header
.addr_size
;
12456 dwarf2_complex_location_expr_complaint ();
12458 if (!fnp
->fcontext
)
12459 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
12461 else if (attr_form_is_section_offset (attr
))
12463 dwarf2_complex_location_expr_complaint ();
12467 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
12473 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
12474 if (attr
&& DW_UNSND (attr
))
12476 /* GCC does this, as of 2008-08-25; PR debug/37237. */
12477 complaint (&symfile_complaints
,
12478 _("Member function \"%s\" (offset %d) is virtual "
12479 "but the vtable offset is not specified"),
12480 fieldname
, die
->offset
.sect_off
);
12481 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12482 TYPE_CPLUS_DYNAMIC (type
) = 1;
12487 /* Create the vector of member function fields, and attach it to the type. */
12490 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
12491 struct dwarf2_cu
*cu
)
12493 struct fnfieldlist
*flp
;
12496 if (cu
->language
== language_ada
)
12497 error (_("unexpected member functions in Ada type"));
12499 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12500 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
12501 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
12503 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
12505 struct nextfnfield
*nfp
= flp
->head
;
12506 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
12509 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
12510 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
12511 fn_flp
->fn_fields
= (struct fn_field
*)
12512 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
12513 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
12514 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
12517 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
12520 /* Returns non-zero if NAME is the name of a vtable member in CU's
12521 language, zero otherwise. */
12523 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
12525 static const char vptr
[] = "_vptr";
12526 static const char vtable
[] = "vtable";
12528 /* Look for the C++ and Java forms of the vtable. */
12529 if ((cu
->language
== language_java
12530 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
12531 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
12532 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
12538 /* GCC outputs unnamed structures that are really pointers to member
12539 functions, with the ABI-specified layout. If TYPE describes
12540 such a structure, smash it into a member function type.
12542 GCC shouldn't do this; it should just output pointer to member DIEs.
12543 This is GCC PR debug/28767. */
12546 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
12548 struct type
*pfn_type
, *domain_type
, *new_type
;
12550 /* Check for a structure with no name and two children. */
12551 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
12554 /* Check for __pfn and __delta members. */
12555 if (TYPE_FIELD_NAME (type
, 0) == NULL
12556 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
12557 || TYPE_FIELD_NAME (type
, 1) == NULL
12558 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
12561 /* Find the type of the method. */
12562 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
12563 if (pfn_type
== NULL
12564 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
12565 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
12568 /* Look for the "this" argument. */
12569 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
12570 if (TYPE_NFIELDS (pfn_type
) == 0
12571 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
12572 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
12575 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
12576 new_type
= alloc_type (objfile
);
12577 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
12578 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
12579 TYPE_VARARGS (pfn_type
));
12580 smash_to_methodptr_type (type
, new_type
);
12583 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
12587 producer_is_icc (struct dwarf2_cu
*cu
)
12589 if (!cu
->checked_producer
)
12590 check_producer (cu
);
12592 return cu
->producer_is_icc
;
12595 /* Called when we find the DIE that starts a structure or union scope
12596 (definition) to create a type for the structure or union. Fill in
12597 the type's name and general properties; the members will not be
12598 processed until process_structure_scope.
12600 NOTE: we need to call these functions regardless of whether or not the
12601 DIE has a DW_AT_name attribute, since it might be an anonymous
12602 structure or union. This gets the type entered into our set of
12603 user defined types.
12605 However, if the structure is incomplete (an opaque struct/union)
12606 then suppress creating a symbol table entry for it since gdb only
12607 wants to find the one with the complete definition. Note that if
12608 it is complete, we just call new_symbol, which does it's own
12609 checking about whether the struct/union is anonymous or not (and
12610 suppresses creating a symbol table entry itself). */
12612 static struct type
*
12613 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12615 struct objfile
*objfile
= cu
->objfile
;
12617 struct attribute
*attr
;
12620 /* If the definition of this type lives in .debug_types, read that type.
12621 Don't follow DW_AT_specification though, that will take us back up
12622 the chain and we want to go down. */
12623 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
12626 type
= get_DW_AT_signature_type (die
, attr
, cu
);
12628 /* The type's CU may not be the same as CU.
12629 Ensure TYPE is recorded with CU in die_type_hash. */
12630 return set_die_type (die
, type
, cu
);
12633 type
= alloc_type (objfile
);
12634 INIT_CPLUS_SPECIFIC (type
);
12636 name
= dwarf2_name (die
, cu
);
12639 if (cu
->language
== language_cplus
12640 || cu
->language
== language_java
)
12642 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
12644 /* dwarf2_full_name might have already finished building the DIE's
12645 type. If so, there is no need to continue. */
12646 if (get_die_type (die
, cu
) != NULL
)
12647 return get_die_type (die
, cu
);
12649 TYPE_TAG_NAME (type
) = full_name
;
12650 if (die
->tag
== DW_TAG_structure_type
12651 || die
->tag
== DW_TAG_class_type
)
12652 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
12656 /* The name is already allocated along with this objfile, so
12657 we don't need to duplicate it for the type. */
12658 TYPE_TAG_NAME (type
) = name
;
12659 if (die
->tag
== DW_TAG_class_type
)
12660 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
12664 if (die
->tag
== DW_TAG_structure_type
)
12666 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
12668 else if (die
->tag
== DW_TAG_union_type
)
12670 TYPE_CODE (type
) = TYPE_CODE_UNION
;
12674 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
12677 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
12678 TYPE_DECLARED_CLASS (type
) = 1;
12680 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12683 TYPE_LENGTH (type
) = DW_UNSND (attr
);
12687 TYPE_LENGTH (type
) = 0;
12690 if (producer_is_icc (cu
))
12692 /* ICC does not output the required DW_AT_declaration
12693 on incomplete types, but gives them a size of zero. */
12696 TYPE_STUB_SUPPORTED (type
) = 1;
12698 if (die_is_declaration (die
, cu
))
12699 TYPE_STUB (type
) = 1;
12700 else if (attr
== NULL
&& die
->child
== NULL
12701 && producer_is_realview (cu
->producer
))
12702 /* RealView does not output the required DW_AT_declaration
12703 on incomplete types. */
12704 TYPE_STUB (type
) = 1;
12706 /* We need to add the type field to the die immediately so we don't
12707 infinitely recurse when dealing with pointers to the structure
12708 type within the structure itself. */
12709 set_die_type (die
, type
, cu
);
12711 /* set_die_type should be already done. */
12712 set_descriptive_type (type
, die
, cu
);
12717 /* Finish creating a structure or union type, including filling in
12718 its members and creating a symbol for it. */
12721 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12723 struct objfile
*objfile
= cu
->objfile
;
12724 struct die_info
*child_die
= die
->child
;
12727 type
= get_die_type (die
, cu
);
12729 type
= read_structure_type (die
, cu
);
12731 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
12733 struct field_info fi
;
12734 struct die_info
*child_die
;
12735 VEC (symbolp
) *template_args
= NULL
;
12736 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
12738 memset (&fi
, 0, sizeof (struct field_info
));
12740 child_die
= die
->child
;
12742 while (child_die
&& child_die
->tag
)
12744 if (child_die
->tag
== DW_TAG_member
12745 || child_die
->tag
== DW_TAG_variable
)
12747 /* NOTE: carlton/2002-11-05: A C++ static data member
12748 should be a DW_TAG_member that is a declaration, but
12749 all versions of G++ as of this writing (so through at
12750 least 3.2.1) incorrectly generate DW_TAG_variable
12751 tags for them instead. */
12752 dwarf2_add_field (&fi
, child_die
, cu
);
12754 else if (child_die
->tag
== DW_TAG_subprogram
)
12756 /* C++ member function. */
12757 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
12759 else if (child_die
->tag
== DW_TAG_inheritance
)
12761 /* C++ base class field. */
12762 dwarf2_add_field (&fi
, child_die
, cu
);
12764 else if (child_die
->tag
== DW_TAG_typedef
)
12765 dwarf2_add_typedef (&fi
, child_die
, cu
);
12766 else if (child_die
->tag
== DW_TAG_template_type_param
12767 || child_die
->tag
== DW_TAG_template_value_param
)
12769 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12772 VEC_safe_push (symbolp
, template_args
, arg
);
12775 child_die
= sibling_die (child_die
);
12778 /* Attach template arguments to type. */
12779 if (! VEC_empty (symbolp
, template_args
))
12781 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12782 TYPE_N_TEMPLATE_ARGUMENTS (type
)
12783 = VEC_length (symbolp
, template_args
);
12784 TYPE_TEMPLATE_ARGUMENTS (type
)
12785 = obstack_alloc (&objfile
->objfile_obstack
,
12786 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
12787 * sizeof (struct symbol
*)));
12788 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
12789 VEC_address (symbolp
, template_args
),
12790 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
12791 * sizeof (struct symbol
*)));
12792 VEC_free (symbolp
, template_args
);
12795 /* Attach fields and member functions to the type. */
12797 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
12800 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
12802 /* Get the type which refers to the base class (possibly this
12803 class itself) which contains the vtable pointer for the current
12804 class from the DW_AT_containing_type attribute. This use of
12805 DW_AT_containing_type is a GNU extension. */
12807 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
12809 struct type
*t
= die_containing_type (die
, cu
);
12811 TYPE_VPTR_BASETYPE (type
) = t
;
12816 /* Our own class provides vtbl ptr. */
12817 for (i
= TYPE_NFIELDS (t
) - 1;
12818 i
>= TYPE_N_BASECLASSES (t
);
12821 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
12823 if (is_vtable_name (fieldname
, cu
))
12825 TYPE_VPTR_FIELDNO (type
) = i
;
12830 /* Complain if virtual function table field not found. */
12831 if (i
< TYPE_N_BASECLASSES (t
))
12832 complaint (&symfile_complaints
,
12833 _("virtual function table pointer "
12834 "not found when defining class '%s'"),
12835 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
12840 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
12843 else if (cu
->producer
12844 && strncmp (cu
->producer
,
12845 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
12847 /* The IBM XLC compiler does not provide direct indication
12848 of the containing type, but the vtable pointer is
12849 always named __vfp. */
12853 for (i
= TYPE_NFIELDS (type
) - 1;
12854 i
>= TYPE_N_BASECLASSES (type
);
12857 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
12859 TYPE_VPTR_FIELDNO (type
) = i
;
12860 TYPE_VPTR_BASETYPE (type
) = type
;
12867 /* Copy fi.typedef_field_list linked list elements content into the
12868 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
12869 if (fi
.typedef_field_list
)
12871 int i
= fi
.typedef_field_list_count
;
12873 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12874 TYPE_TYPEDEF_FIELD_ARRAY (type
)
12875 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
12876 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
12878 /* Reverse the list order to keep the debug info elements order. */
12881 struct typedef_field
*dest
, *src
;
12883 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
12884 src
= &fi
.typedef_field_list
->field
;
12885 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
12890 do_cleanups (back_to
);
12892 if (HAVE_CPLUS_STRUCT (type
))
12893 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
12896 quirk_gcc_member_function_pointer (type
, objfile
);
12898 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
12899 snapshots) has been known to create a die giving a declaration
12900 for a class that has, as a child, a die giving a definition for a
12901 nested class. So we have to process our children even if the
12902 current die is a declaration. Normally, of course, a declaration
12903 won't have any children at all. */
12905 while (child_die
!= NULL
&& child_die
->tag
)
12907 if (child_die
->tag
== DW_TAG_member
12908 || child_die
->tag
== DW_TAG_variable
12909 || child_die
->tag
== DW_TAG_inheritance
12910 || child_die
->tag
== DW_TAG_template_value_param
12911 || child_die
->tag
== DW_TAG_template_type_param
)
12916 process_die (child_die
, cu
);
12918 child_die
= sibling_die (child_die
);
12921 /* Do not consider external references. According to the DWARF standard,
12922 these DIEs are identified by the fact that they have no byte_size
12923 attribute, and a declaration attribute. */
12924 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
12925 || !die_is_declaration (die
, cu
))
12926 new_symbol (die
, type
, cu
);
12929 /* Given a DW_AT_enumeration_type die, set its type. We do not
12930 complete the type's fields yet, or create any symbols. */
12932 static struct type
*
12933 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12935 struct objfile
*objfile
= cu
->objfile
;
12937 struct attribute
*attr
;
12940 /* If the definition of this type lives in .debug_types, read that type.
12941 Don't follow DW_AT_specification though, that will take us back up
12942 the chain and we want to go down. */
12943 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
12946 type
= get_DW_AT_signature_type (die
, attr
, cu
);
12948 /* The type's CU may not be the same as CU.
12949 Ensure TYPE is recorded with CU in die_type_hash. */
12950 return set_die_type (die
, type
, cu
);
12953 type
= alloc_type (objfile
);
12955 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
12956 name
= dwarf2_full_name (NULL
, die
, cu
);
12958 TYPE_TAG_NAME (type
) = name
;
12960 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12963 TYPE_LENGTH (type
) = DW_UNSND (attr
);
12967 TYPE_LENGTH (type
) = 0;
12970 /* The enumeration DIE can be incomplete. In Ada, any type can be
12971 declared as private in the package spec, and then defined only
12972 inside the package body. Such types are known as Taft Amendment
12973 Types. When another package uses such a type, an incomplete DIE
12974 may be generated by the compiler. */
12975 if (die_is_declaration (die
, cu
))
12976 TYPE_STUB (type
) = 1;
12978 return set_die_type (die
, type
, cu
);
12981 /* Given a pointer to a die which begins an enumeration, process all
12982 the dies that define the members of the enumeration, and create the
12983 symbol for the enumeration type.
12985 NOTE: We reverse the order of the element list. */
12988 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12990 struct type
*this_type
;
12992 this_type
= get_die_type (die
, cu
);
12993 if (this_type
== NULL
)
12994 this_type
= read_enumeration_type (die
, cu
);
12996 if (die
->child
!= NULL
)
12998 struct die_info
*child_die
;
12999 struct symbol
*sym
;
13000 struct field
*fields
= NULL
;
13001 int num_fields
= 0;
13002 int unsigned_enum
= 1;
13007 child_die
= die
->child
;
13008 while (child_die
&& child_die
->tag
)
13010 if (child_die
->tag
!= DW_TAG_enumerator
)
13012 process_die (child_die
, cu
);
13016 name
= dwarf2_name (child_die
, cu
);
13019 sym
= new_symbol (child_die
, this_type
, cu
);
13020 if (SYMBOL_VALUE (sym
) < 0)
13025 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
13028 mask
|= SYMBOL_VALUE (sym
);
13030 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
13032 fields
= (struct field
*)
13034 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
13035 * sizeof (struct field
));
13038 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
13039 FIELD_TYPE (fields
[num_fields
]) = NULL
;
13040 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
13041 FIELD_BITSIZE (fields
[num_fields
]) = 0;
13047 child_die
= sibling_die (child_die
);
13052 TYPE_NFIELDS (this_type
) = num_fields
;
13053 TYPE_FIELDS (this_type
) = (struct field
*)
13054 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
13055 memcpy (TYPE_FIELDS (this_type
), fields
,
13056 sizeof (struct field
) * num_fields
);
13060 TYPE_UNSIGNED (this_type
) = 1;
13062 TYPE_FLAG_ENUM (this_type
) = 1;
13065 /* If we are reading an enum from a .debug_types unit, and the enum
13066 is a declaration, and the enum is not the signatured type in the
13067 unit, then we do not want to add a symbol for it. Adding a
13068 symbol would in some cases obscure the true definition of the
13069 enum, giving users an incomplete type when the definition is
13070 actually available. Note that we do not want to do this for all
13071 enums which are just declarations, because C++0x allows forward
13072 enum declarations. */
13073 if (cu
->per_cu
->is_debug_types
13074 && die_is_declaration (die
, cu
))
13076 struct signatured_type
*sig_type
;
13078 sig_type
= (struct signatured_type
*) cu
->per_cu
;
13079 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
13080 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
13084 new_symbol (die
, this_type
, cu
);
13087 /* Extract all information from a DW_TAG_array_type DIE and put it in
13088 the DIE's type field. For now, this only handles one dimensional
13091 static struct type
*
13092 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13094 struct objfile
*objfile
= cu
->objfile
;
13095 struct die_info
*child_die
;
13097 struct type
*element_type
, *range_type
, *index_type
;
13098 struct type
**range_types
= NULL
;
13099 struct attribute
*attr
;
13101 struct cleanup
*back_to
;
13104 element_type
= die_type (die
, cu
);
13106 /* The die_type call above may have already set the type for this DIE. */
13107 type
= get_die_type (die
, cu
);
13111 /* Irix 6.2 native cc creates array types without children for
13112 arrays with unspecified length. */
13113 if (die
->child
== NULL
)
13115 index_type
= objfile_type (objfile
)->builtin_int
;
13116 range_type
= create_range_type (NULL
, index_type
, 0, -1);
13117 type
= create_array_type (NULL
, element_type
, range_type
);
13118 return set_die_type (die
, type
, cu
);
13121 back_to
= make_cleanup (null_cleanup
, NULL
);
13122 child_die
= die
->child
;
13123 while (child_die
&& child_die
->tag
)
13125 if (child_die
->tag
== DW_TAG_subrange_type
)
13127 struct type
*child_type
= read_type_die (child_die
, cu
);
13129 if (child_type
!= NULL
)
13131 /* The range type was succesfully read. Save it for the
13132 array type creation. */
13133 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
13135 range_types
= (struct type
**)
13136 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
13137 * sizeof (struct type
*));
13139 make_cleanup (free_current_contents
, &range_types
);
13141 range_types
[ndim
++] = child_type
;
13144 child_die
= sibling_die (child_die
);
13147 /* Dwarf2 dimensions are output from left to right, create the
13148 necessary array types in backwards order. */
13150 type
= element_type
;
13152 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
13157 type
= create_array_type (NULL
, type
, range_types
[i
++]);
13162 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
13165 /* Understand Dwarf2 support for vector types (like they occur on
13166 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
13167 array type. This is not part of the Dwarf2/3 standard yet, but a
13168 custom vendor extension. The main difference between a regular
13169 array and the vector variant is that vectors are passed by value
13171 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
13173 make_vector_type (type
);
13175 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
13176 implementation may choose to implement triple vectors using this
13178 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13181 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
13182 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13184 complaint (&symfile_complaints
,
13185 _("DW_AT_byte_size for array type smaller "
13186 "than the total size of elements"));
13189 name
= dwarf2_name (die
, cu
);
13191 TYPE_NAME (type
) = name
;
13193 /* Install the type in the die. */
13194 set_die_type (die
, type
, cu
);
13196 /* set_die_type should be already done. */
13197 set_descriptive_type (type
, die
, cu
);
13199 do_cleanups (back_to
);
13204 static enum dwarf_array_dim_ordering
13205 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
13207 struct attribute
*attr
;
13209 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
13211 if (attr
) return DW_SND (attr
);
13213 /* GNU F77 is a special case, as at 08/2004 array type info is the
13214 opposite order to the dwarf2 specification, but data is still
13215 laid out as per normal fortran.
13217 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
13218 version checking. */
13220 if (cu
->language
== language_fortran
13221 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
13223 return DW_ORD_row_major
;
13226 switch (cu
->language_defn
->la_array_ordering
)
13228 case array_column_major
:
13229 return DW_ORD_col_major
;
13230 case array_row_major
:
13232 return DW_ORD_row_major
;
13236 /* Extract all information from a DW_TAG_set_type DIE and put it in
13237 the DIE's type field. */
13239 static struct type
*
13240 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13242 struct type
*domain_type
, *set_type
;
13243 struct attribute
*attr
;
13245 domain_type
= die_type (die
, cu
);
13247 /* The die_type call above may have already set the type for this DIE. */
13248 set_type
= get_die_type (die
, cu
);
13252 set_type
= create_set_type (NULL
, domain_type
);
13254 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13256 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
13258 return set_die_type (die
, set_type
, cu
);
13261 /* A helper for read_common_block that creates a locexpr baton.
13262 SYM is the symbol which we are marking as computed.
13263 COMMON_DIE is the DIE for the common block.
13264 COMMON_LOC is the location expression attribute for the common
13266 MEMBER_LOC is the location expression attribute for the particular
13267 member of the common block that we are processing.
13268 CU is the CU from which the above come. */
13271 mark_common_block_symbol_computed (struct symbol
*sym
,
13272 struct die_info
*common_die
,
13273 struct attribute
*common_loc
,
13274 struct attribute
*member_loc
,
13275 struct dwarf2_cu
*cu
)
13277 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13278 struct dwarf2_locexpr_baton
*baton
;
13280 unsigned int cu_off
;
13281 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
13282 LONGEST offset
= 0;
13284 gdb_assert (common_loc
&& member_loc
);
13285 gdb_assert (attr_form_is_block (common_loc
));
13286 gdb_assert (attr_form_is_block (member_loc
)
13287 || attr_form_is_constant (member_loc
));
13289 baton
= obstack_alloc (&objfile
->objfile_obstack
,
13290 sizeof (struct dwarf2_locexpr_baton
));
13291 baton
->per_cu
= cu
->per_cu
;
13292 gdb_assert (baton
->per_cu
);
13294 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
13296 if (attr_form_is_constant (member_loc
))
13298 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
13299 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
13302 baton
->size
+= DW_BLOCK (member_loc
)->size
;
13304 ptr
= obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
13307 *ptr
++ = DW_OP_call4
;
13308 cu_off
= common_die
->offset
.sect_off
- cu
->per_cu
->offset
.sect_off
;
13309 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
13312 if (attr_form_is_constant (member_loc
))
13314 *ptr
++ = DW_OP_addr
;
13315 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
13316 ptr
+= cu
->header
.addr_size
;
13320 /* We have to copy the data here, because DW_OP_call4 will only
13321 use a DW_AT_location attribute. */
13322 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
13323 ptr
+= DW_BLOCK (member_loc
)->size
;
13326 *ptr
++ = DW_OP_plus
;
13327 gdb_assert (ptr
- baton
->data
== baton
->size
);
13329 SYMBOL_LOCATION_BATON (sym
) = baton
;
13330 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
13333 /* Create appropriate locally-scoped variables for all the
13334 DW_TAG_common_block entries. Also create a struct common_block
13335 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
13336 is used to sepate the common blocks name namespace from regular
13340 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
13342 struct attribute
*attr
;
13344 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13347 /* Support the .debug_loc offsets. */
13348 if (attr_form_is_block (attr
))
13352 else if (attr_form_is_section_offset (attr
))
13354 dwarf2_complex_location_expr_complaint ();
13359 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
13360 "common block member");
13365 if (die
->child
!= NULL
)
13367 struct objfile
*objfile
= cu
->objfile
;
13368 struct die_info
*child_die
;
13369 size_t n_entries
= 0, size
;
13370 struct common_block
*common_block
;
13371 struct symbol
*sym
;
13373 for (child_die
= die
->child
;
13374 child_die
&& child_die
->tag
;
13375 child_die
= sibling_die (child_die
))
13378 size
= (sizeof (struct common_block
)
13379 + (n_entries
- 1) * sizeof (struct symbol
*));
13380 common_block
= obstack_alloc (&objfile
->objfile_obstack
, size
);
13381 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
13382 common_block
->n_entries
= 0;
13384 for (child_die
= die
->child
;
13385 child_die
&& child_die
->tag
;
13386 child_die
= sibling_die (child_die
))
13388 /* Create the symbol in the DW_TAG_common_block block in the current
13390 sym
= new_symbol (child_die
, NULL
, cu
);
13393 struct attribute
*member_loc
;
13395 common_block
->contents
[common_block
->n_entries
++] = sym
;
13397 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
13401 /* GDB has handled this for a long time, but it is
13402 not specified by DWARF. It seems to have been
13403 emitted by gfortran at least as recently as:
13404 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
13405 complaint (&symfile_complaints
,
13406 _("Variable in common block has "
13407 "DW_AT_data_member_location "
13408 "- DIE at 0x%x [in module %s]"),
13409 child_die
->offset
.sect_off
,
13410 objfile_name (cu
->objfile
));
13412 if (attr_form_is_section_offset (member_loc
))
13413 dwarf2_complex_location_expr_complaint ();
13414 else if (attr_form_is_constant (member_loc
)
13415 || attr_form_is_block (member_loc
))
13418 mark_common_block_symbol_computed (sym
, die
, attr
,
13422 dwarf2_complex_location_expr_complaint ();
13427 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
13428 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
13432 /* Create a type for a C++ namespace. */
13434 static struct type
*
13435 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13437 struct objfile
*objfile
= cu
->objfile
;
13438 const char *previous_prefix
, *name
;
13442 /* For extensions, reuse the type of the original namespace. */
13443 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
13445 struct die_info
*ext_die
;
13446 struct dwarf2_cu
*ext_cu
= cu
;
13448 ext_die
= dwarf2_extension (die
, &ext_cu
);
13449 type
= read_type_die (ext_die
, ext_cu
);
13451 /* EXT_CU may not be the same as CU.
13452 Ensure TYPE is recorded with CU in die_type_hash. */
13453 return set_die_type (die
, type
, cu
);
13456 name
= namespace_name (die
, &is_anonymous
, cu
);
13458 /* Now build the name of the current namespace. */
13460 previous_prefix
= determine_prefix (die
, cu
);
13461 if (previous_prefix
[0] != '\0')
13462 name
= typename_concat (&objfile
->objfile_obstack
,
13463 previous_prefix
, name
, 0, cu
);
13465 /* Create the type. */
13466 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
13468 TYPE_NAME (type
) = name
;
13469 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
13471 return set_die_type (die
, type
, cu
);
13474 /* Read a C++ namespace. */
13477 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
13479 struct objfile
*objfile
= cu
->objfile
;
13482 /* Add a symbol associated to this if we haven't seen the namespace
13483 before. Also, add a using directive if it's an anonymous
13486 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
13490 type
= read_type_die (die
, cu
);
13491 new_symbol (die
, type
, cu
);
13493 namespace_name (die
, &is_anonymous
, cu
);
13496 const char *previous_prefix
= determine_prefix (die
, cu
);
13498 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
13499 NULL
, NULL
, 0, &objfile
->objfile_obstack
);
13503 if (die
->child
!= NULL
)
13505 struct die_info
*child_die
= die
->child
;
13507 while (child_die
&& child_die
->tag
)
13509 process_die (child_die
, cu
);
13510 child_die
= sibling_die (child_die
);
13515 /* Read a Fortran module as type. This DIE can be only a declaration used for
13516 imported module. Still we need that type as local Fortran "use ... only"
13517 declaration imports depend on the created type in determine_prefix. */
13519 static struct type
*
13520 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13522 struct objfile
*objfile
= cu
->objfile
;
13523 const char *module_name
;
13526 module_name
= dwarf2_name (die
, cu
);
13528 complaint (&symfile_complaints
,
13529 _("DW_TAG_module has no name, offset 0x%x"),
13530 die
->offset
.sect_off
);
13531 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
13533 /* determine_prefix uses TYPE_TAG_NAME. */
13534 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
13536 return set_die_type (die
, type
, cu
);
13539 /* Read a Fortran module. */
13542 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
13544 struct die_info
*child_die
= die
->child
;
13546 while (child_die
&& child_die
->tag
)
13548 process_die (child_die
, cu
);
13549 child_die
= sibling_die (child_die
);
13553 /* Return the name of the namespace represented by DIE. Set
13554 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
13557 static const char *
13558 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
13560 struct die_info
*current_die
;
13561 const char *name
= NULL
;
13563 /* Loop through the extensions until we find a name. */
13565 for (current_die
= die
;
13566 current_die
!= NULL
;
13567 current_die
= dwarf2_extension (die
, &cu
))
13569 name
= dwarf2_name (current_die
, cu
);
13574 /* Is it an anonymous namespace? */
13576 *is_anonymous
= (name
== NULL
);
13578 name
= CP_ANONYMOUS_NAMESPACE_STR
;
13583 /* Extract all information from a DW_TAG_pointer_type DIE and add to
13584 the user defined type vector. */
13586 static struct type
*
13587 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13589 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
13590 struct comp_unit_head
*cu_header
= &cu
->header
;
13592 struct attribute
*attr_byte_size
;
13593 struct attribute
*attr_address_class
;
13594 int byte_size
, addr_class
;
13595 struct type
*target_type
;
13597 target_type
= die_type (die
, cu
);
13599 /* The die_type call above may have already set the type for this DIE. */
13600 type
= get_die_type (die
, cu
);
13604 type
= lookup_pointer_type (target_type
);
13606 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13607 if (attr_byte_size
)
13608 byte_size
= DW_UNSND (attr_byte_size
);
13610 byte_size
= cu_header
->addr_size
;
13612 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
13613 if (attr_address_class
)
13614 addr_class
= DW_UNSND (attr_address_class
);
13616 addr_class
= DW_ADDR_none
;
13618 /* If the pointer size or address class is different than the
13619 default, create a type variant marked as such and set the
13620 length accordingly. */
13621 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
13623 if (gdbarch_address_class_type_flags_p (gdbarch
))
13627 type_flags
= gdbarch_address_class_type_flags
13628 (gdbarch
, byte_size
, addr_class
);
13629 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
13631 type
= make_type_with_address_space (type
, type_flags
);
13633 else if (TYPE_LENGTH (type
) != byte_size
)
13635 complaint (&symfile_complaints
,
13636 _("invalid pointer size %d"), byte_size
);
13640 /* Should we also complain about unhandled address classes? */
13644 TYPE_LENGTH (type
) = byte_size
;
13645 return set_die_type (die
, type
, cu
);
13648 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
13649 the user defined type vector. */
13651 static struct type
*
13652 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13655 struct type
*to_type
;
13656 struct type
*domain
;
13658 to_type
= die_type (die
, cu
);
13659 domain
= die_containing_type (die
, cu
);
13661 /* The calls above may have already set the type for this DIE. */
13662 type
= get_die_type (die
, cu
);
13666 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
13667 type
= lookup_methodptr_type (to_type
);
13668 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
13670 struct type
*new_type
= alloc_type (cu
->objfile
);
13672 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
13673 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
13674 TYPE_VARARGS (to_type
));
13675 type
= lookup_methodptr_type (new_type
);
13678 type
= lookup_memberptr_type (to_type
, domain
);
13680 return set_die_type (die
, type
, cu
);
13683 /* Extract all information from a DW_TAG_reference_type DIE and add to
13684 the user defined type vector. */
13686 static struct type
*
13687 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13689 struct comp_unit_head
*cu_header
= &cu
->header
;
13690 struct type
*type
, *target_type
;
13691 struct attribute
*attr
;
13693 target_type
= die_type (die
, cu
);
13695 /* The die_type call above may have already set the type for this DIE. */
13696 type
= get_die_type (die
, cu
);
13700 type
= lookup_reference_type (target_type
);
13701 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13704 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13708 TYPE_LENGTH (type
) = cu_header
->addr_size
;
13710 return set_die_type (die
, type
, cu
);
13713 static struct type
*
13714 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13716 struct type
*base_type
, *cv_type
;
13718 base_type
= die_type (die
, cu
);
13720 /* The die_type call above may have already set the type for this DIE. */
13721 cv_type
= get_die_type (die
, cu
);
13725 /* In case the const qualifier is applied to an array type, the element type
13726 is so qualified, not the array type (section 6.7.3 of C99). */
13727 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
13729 struct type
*el_type
, *inner_array
;
13731 base_type
= copy_type (base_type
);
13732 inner_array
= base_type
;
13734 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
13736 TYPE_TARGET_TYPE (inner_array
) =
13737 copy_type (TYPE_TARGET_TYPE (inner_array
));
13738 inner_array
= TYPE_TARGET_TYPE (inner_array
);
13741 el_type
= TYPE_TARGET_TYPE (inner_array
);
13742 TYPE_TARGET_TYPE (inner_array
) =
13743 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
13745 return set_die_type (die
, base_type
, cu
);
13748 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
13749 return set_die_type (die
, cv_type
, cu
);
13752 static struct type
*
13753 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13755 struct type
*base_type
, *cv_type
;
13757 base_type
= die_type (die
, cu
);
13759 /* The die_type call above may have already set the type for this DIE. */
13760 cv_type
= get_die_type (die
, cu
);
13764 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
13765 return set_die_type (die
, cv_type
, cu
);
13768 /* Handle DW_TAG_restrict_type. */
13770 static struct type
*
13771 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13773 struct type
*base_type
, *cv_type
;
13775 base_type
= die_type (die
, cu
);
13777 /* The die_type call above may have already set the type for this DIE. */
13778 cv_type
= get_die_type (die
, cu
);
13782 cv_type
= make_restrict_type (base_type
);
13783 return set_die_type (die
, cv_type
, cu
);
13786 /* Extract all information from a DW_TAG_string_type DIE and add to
13787 the user defined type vector. It isn't really a user defined type,
13788 but it behaves like one, with other DIE's using an AT_user_def_type
13789 attribute to reference it. */
13791 static struct type
*
13792 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13794 struct objfile
*objfile
= cu
->objfile
;
13795 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13796 struct type
*type
, *range_type
, *index_type
, *char_type
;
13797 struct attribute
*attr
;
13798 unsigned int length
;
13800 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
13803 length
= DW_UNSND (attr
);
13807 /* Check for the DW_AT_byte_size attribute. */
13808 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13811 length
= DW_UNSND (attr
);
13819 index_type
= objfile_type (objfile
)->builtin_int
;
13820 range_type
= create_range_type (NULL
, index_type
, 1, length
);
13821 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
13822 type
= create_string_type (NULL
, char_type
, range_type
);
13824 return set_die_type (die
, type
, cu
);
13827 /* Assuming that DIE corresponds to a function, returns nonzero
13828 if the function is prototyped. */
13831 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
13833 struct attribute
*attr
;
13835 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
13836 if (attr
&& (DW_UNSND (attr
) != 0))
13839 /* The DWARF standard implies that the DW_AT_prototyped attribute
13840 is only meaninful for C, but the concept also extends to other
13841 languages that allow unprototyped functions (Eg: Objective C).
13842 For all other languages, assume that functions are always
13844 if (cu
->language
!= language_c
13845 && cu
->language
!= language_objc
13846 && cu
->language
!= language_opencl
)
13849 /* RealView does not emit DW_AT_prototyped. We can not distinguish
13850 prototyped and unprototyped functions; default to prototyped,
13851 since that is more common in modern code (and RealView warns
13852 about unprototyped functions). */
13853 if (producer_is_realview (cu
->producer
))
13859 /* Handle DIES due to C code like:
13863 int (*funcp)(int a, long l);
13867 ('funcp' generates a DW_TAG_subroutine_type DIE). */
13869 static struct type
*
13870 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13872 struct objfile
*objfile
= cu
->objfile
;
13873 struct type
*type
; /* Type that this function returns. */
13874 struct type
*ftype
; /* Function that returns above type. */
13875 struct attribute
*attr
;
13877 type
= die_type (die
, cu
);
13879 /* The die_type call above may have already set the type for this DIE. */
13880 ftype
= get_die_type (die
, cu
);
13884 ftype
= lookup_function_type (type
);
13886 if (prototyped_function_p (die
, cu
))
13887 TYPE_PROTOTYPED (ftype
) = 1;
13889 /* Store the calling convention in the type if it's available in
13890 the subroutine die. Otherwise set the calling convention to
13891 the default value DW_CC_normal. */
13892 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
13894 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
13895 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
13896 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
13898 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
13900 /* We need to add the subroutine type to the die immediately so
13901 we don't infinitely recurse when dealing with parameters
13902 declared as the same subroutine type. */
13903 set_die_type (die
, ftype
, cu
);
13905 if (die
->child
!= NULL
)
13907 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
13908 struct die_info
*child_die
;
13909 int nparams
, iparams
;
13911 /* Count the number of parameters.
13912 FIXME: GDB currently ignores vararg functions, but knows about
13913 vararg member functions. */
13915 child_die
= die
->child
;
13916 while (child_die
&& child_die
->tag
)
13918 if (child_die
->tag
== DW_TAG_formal_parameter
)
13920 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
13921 TYPE_VARARGS (ftype
) = 1;
13922 child_die
= sibling_die (child_die
);
13925 /* Allocate storage for parameters and fill them in. */
13926 TYPE_NFIELDS (ftype
) = nparams
;
13927 TYPE_FIELDS (ftype
) = (struct field
*)
13928 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
13930 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
13931 even if we error out during the parameters reading below. */
13932 for (iparams
= 0; iparams
< nparams
; iparams
++)
13933 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
13936 child_die
= die
->child
;
13937 while (child_die
&& child_die
->tag
)
13939 if (child_die
->tag
== DW_TAG_formal_parameter
)
13941 struct type
*arg_type
;
13943 /* DWARF version 2 has no clean way to discern C++
13944 static and non-static member functions. G++ helps
13945 GDB by marking the first parameter for non-static
13946 member functions (which is the this pointer) as
13947 artificial. We pass this information to
13948 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
13950 DWARF version 3 added DW_AT_object_pointer, which GCC
13951 4.5 does not yet generate. */
13952 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
13954 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
13957 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
13959 /* GCC/43521: In java, the formal parameter
13960 "this" is sometimes not marked with DW_AT_artificial. */
13961 if (cu
->language
== language_java
)
13963 const char *name
= dwarf2_name (child_die
, cu
);
13965 if (name
&& !strcmp (name
, "this"))
13966 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
13969 arg_type
= die_type (child_die
, cu
);
13971 /* RealView does not mark THIS as const, which the testsuite
13972 expects. GCC marks THIS as const in method definitions,
13973 but not in the class specifications (GCC PR 43053). */
13974 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
13975 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
13978 struct dwarf2_cu
*arg_cu
= cu
;
13979 const char *name
= dwarf2_name (child_die
, cu
);
13981 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
13984 /* If the compiler emits this, use it. */
13985 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
13988 else if (name
&& strcmp (name
, "this") == 0)
13989 /* Function definitions will have the argument names. */
13991 else if (name
== NULL
&& iparams
== 0)
13992 /* Declarations may not have the names, so like
13993 elsewhere in GDB, assume an artificial first
13994 argument is "this". */
13998 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
14002 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
14005 child_die
= sibling_die (child_die
);
14012 static struct type
*
14013 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
14015 struct objfile
*objfile
= cu
->objfile
;
14016 const char *name
= NULL
;
14017 struct type
*this_type
, *target_type
;
14019 name
= dwarf2_full_name (NULL
, die
, cu
);
14020 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
14021 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
14022 TYPE_NAME (this_type
) = name
;
14023 set_die_type (die
, this_type
, cu
);
14024 target_type
= die_type (die
, cu
);
14025 if (target_type
!= this_type
)
14026 TYPE_TARGET_TYPE (this_type
) = target_type
;
14029 /* Self-referential typedefs are, it seems, not allowed by the DWARF
14030 spec and cause infinite loops in GDB. */
14031 complaint (&symfile_complaints
,
14032 _("Self-referential DW_TAG_typedef "
14033 "- DIE at 0x%x [in module %s]"),
14034 die
->offset
.sect_off
, objfile_name (objfile
));
14035 TYPE_TARGET_TYPE (this_type
) = NULL
;
14040 /* Find a representation of a given base type and install
14041 it in the TYPE field of the die. */
14043 static struct type
*
14044 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14046 struct objfile
*objfile
= cu
->objfile
;
14048 struct attribute
*attr
;
14049 int encoding
= 0, size
= 0;
14051 enum type_code code
= TYPE_CODE_INT
;
14052 int type_flags
= 0;
14053 struct type
*target_type
= NULL
;
14055 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
14058 encoding
= DW_UNSND (attr
);
14060 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14063 size
= DW_UNSND (attr
);
14065 name
= dwarf2_name (die
, cu
);
14068 complaint (&symfile_complaints
,
14069 _("DW_AT_name missing from DW_TAG_base_type"));
14074 case DW_ATE_address
:
14075 /* Turn DW_ATE_address into a void * pointer. */
14076 code
= TYPE_CODE_PTR
;
14077 type_flags
|= TYPE_FLAG_UNSIGNED
;
14078 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
14080 case DW_ATE_boolean
:
14081 code
= TYPE_CODE_BOOL
;
14082 type_flags
|= TYPE_FLAG_UNSIGNED
;
14084 case DW_ATE_complex_float
:
14085 code
= TYPE_CODE_COMPLEX
;
14086 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
14088 case DW_ATE_decimal_float
:
14089 code
= TYPE_CODE_DECFLOAT
;
14092 code
= TYPE_CODE_FLT
;
14094 case DW_ATE_signed
:
14096 case DW_ATE_unsigned
:
14097 type_flags
|= TYPE_FLAG_UNSIGNED
;
14098 if (cu
->language
== language_fortran
14100 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
14101 code
= TYPE_CODE_CHAR
;
14103 case DW_ATE_signed_char
:
14104 if (cu
->language
== language_ada
|| cu
->language
== language_m2
14105 || cu
->language
== language_pascal
14106 || cu
->language
== language_fortran
)
14107 code
= TYPE_CODE_CHAR
;
14109 case DW_ATE_unsigned_char
:
14110 if (cu
->language
== language_ada
|| cu
->language
== language_m2
14111 || cu
->language
== language_pascal
14112 || cu
->language
== language_fortran
)
14113 code
= TYPE_CODE_CHAR
;
14114 type_flags
|= TYPE_FLAG_UNSIGNED
;
14117 /* We just treat this as an integer and then recognize the
14118 type by name elsewhere. */
14122 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
14123 dwarf_type_encoding_name (encoding
));
14127 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
14128 TYPE_NAME (type
) = name
;
14129 TYPE_TARGET_TYPE (type
) = target_type
;
14131 if (name
&& strcmp (name
, "char") == 0)
14132 TYPE_NOSIGN (type
) = 1;
14134 return set_die_type (die
, type
, cu
);
14137 /* Read the given DW_AT_subrange DIE. */
14139 static struct type
*
14140 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14142 struct type
*base_type
, *orig_base_type
;
14143 struct type
*range_type
;
14144 struct attribute
*attr
;
14146 int low_default_is_valid
;
14148 LONGEST negative_mask
;
14150 orig_base_type
= die_type (die
, cu
);
14151 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
14152 whereas the real type might be. So, we use ORIG_BASE_TYPE when
14153 creating the range type, but we use the result of check_typedef
14154 when examining properties of the type. */
14155 base_type
= check_typedef (orig_base_type
);
14157 /* The die_type call above may have already set the type for this DIE. */
14158 range_type
= get_die_type (die
, cu
);
14162 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
14163 omitting DW_AT_lower_bound. */
14164 switch (cu
->language
)
14167 case language_cplus
:
14169 low_default_is_valid
= 1;
14171 case language_fortran
:
14173 low_default_is_valid
= 1;
14176 case language_java
:
14177 case language_objc
:
14179 low_default_is_valid
= (cu
->header
.version
>= 4);
14183 case language_pascal
:
14185 low_default_is_valid
= (cu
->header
.version
>= 4);
14189 low_default_is_valid
= 0;
14193 /* FIXME: For variable sized arrays either of these could be
14194 a variable rather than a constant value. We'll allow it,
14195 but we don't know how to handle it. */
14196 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
14198 low
= dwarf2_get_attr_constant_value (attr
, low
);
14199 else if (!low_default_is_valid
)
14200 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
14201 "- DIE at 0x%x [in module %s]"),
14202 die
->offset
.sect_off
, objfile_name (cu
->objfile
));
14204 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
14207 if (attr_form_is_block (attr
) || attr_form_is_ref (attr
))
14209 /* GCC encodes arrays with unspecified or dynamic length
14210 with a DW_FORM_block1 attribute or a reference attribute.
14211 FIXME: GDB does not yet know how to handle dynamic
14212 arrays properly, treat them as arrays with unspecified
14215 FIXME: jimb/2003-09-22: GDB does not really know
14216 how to handle arrays of unspecified length
14217 either; we just represent them as zero-length
14218 arrays. Choose an appropriate upper bound given
14219 the lower bound we've computed above. */
14223 high
= dwarf2_get_attr_constant_value (attr
, 1);
14227 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
14230 int count
= dwarf2_get_attr_constant_value (attr
, 1);
14231 high
= low
+ count
- 1;
14235 /* Unspecified array length. */
14240 /* Dwarf-2 specifications explicitly allows to create subrange types
14241 without specifying a base type.
14242 In that case, the base type must be set to the type of
14243 the lower bound, upper bound or count, in that order, if any of these
14244 three attributes references an object that has a type.
14245 If no base type is found, the Dwarf-2 specifications say that
14246 a signed integer type of size equal to the size of an address should
14248 For the following C code: `extern char gdb_int [];'
14249 GCC produces an empty range DIE.
14250 FIXME: muller/2010-05-28: Possible references to object for low bound,
14251 high bound or count are not yet handled by this code. */
14252 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
14254 struct objfile
*objfile
= cu
->objfile
;
14255 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14256 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
14257 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
14259 /* Test "int", "long int", and "long long int" objfile types,
14260 and select the first one having a size above or equal to the
14261 architecture address size. */
14262 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
14263 base_type
= int_type
;
14266 int_type
= objfile_type (objfile
)->builtin_long
;
14267 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
14268 base_type
= int_type
;
14271 int_type
= objfile_type (objfile
)->builtin_long_long
;
14272 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
14273 base_type
= int_type
;
14279 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
14280 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
14281 low
|= negative_mask
;
14282 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
14283 high
|= negative_mask
;
14285 range_type
= create_range_type (NULL
, orig_base_type
, low
, high
);
14287 /* Mark arrays with dynamic length at least as an array of unspecified
14288 length. GDB could check the boundary but before it gets implemented at
14289 least allow accessing the array elements. */
14290 if (attr
&& attr_form_is_block (attr
))
14291 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
14293 /* Ada expects an empty array on no boundary attributes. */
14294 if (attr
== NULL
&& cu
->language
!= language_ada
)
14295 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
14297 name
= dwarf2_name (die
, cu
);
14299 TYPE_NAME (range_type
) = name
;
14301 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14303 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
14305 set_die_type (die
, range_type
, cu
);
14307 /* set_die_type should be already done. */
14308 set_descriptive_type (range_type
, die
, cu
);
14313 static struct type
*
14314 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14318 /* For now, we only support the C meaning of an unspecified type: void. */
14320 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
14321 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
14323 return set_die_type (die
, type
, cu
);
14326 /* Read a single die and all its descendents. Set the die's sibling
14327 field to NULL; set other fields in the die correctly, and set all
14328 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
14329 location of the info_ptr after reading all of those dies. PARENT
14330 is the parent of the die in question. */
14332 static struct die_info
*
14333 read_die_and_children (const struct die_reader_specs
*reader
,
14334 const gdb_byte
*info_ptr
,
14335 const gdb_byte
**new_info_ptr
,
14336 struct die_info
*parent
)
14338 struct die_info
*die
;
14339 const gdb_byte
*cur_ptr
;
14342 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
14345 *new_info_ptr
= cur_ptr
;
14348 store_in_ref_table (die
, reader
->cu
);
14351 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
14355 *new_info_ptr
= cur_ptr
;
14358 die
->sibling
= NULL
;
14359 die
->parent
= parent
;
14363 /* Read a die, all of its descendents, and all of its siblings; set
14364 all of the fields of all of the dies correctly. Arguments are as
14365 in read_die_and_children. */
14367 static struct die_info
*
14368 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
14369 const gdb_byte
*info_ptr
,
14370 const gdb_byte
**new_info_ptr
,
14371 struct die_info
*parent
)
14373 struct die_info
*first_die
, *last_sibling
;
14374 const gdb_byte
*cur_ptr
;
14376 cur_ptr
= info_ptr
;
14377 first_die
= last_sibling
= NULL
;
14381 struct die_info
*die
14382 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
14386 *new_info_ptr
= cur_ptr
;
14393 last_sibling
->sibling
= die
;
14395 last_sibling
= die
;
14399 /* Read a die, all of its descendents, and all of its siblings; set
14400 all of the fields of all of the dies correctly. Arguments are as
14401 in read_die_and_children.
14402 This the main entry point for reading a DIE and all its children. */
14404 static struct die_info
*
14405 read_die_and_siblings (const struct die_reader_specs
*reader
,
14406 const gdb_byte
*info_ptr
,
14407 const gdb_byte
**new_info_ptr
,
14408 struct die_info
*parent
)
14410 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
14411 new_info_ptr
, parent
);
14413 if (dwarf2_die_debug
)
14415 fprintf_unfiltered (gdb_stdlog
,
14416 "Read die from %s@0x%x of %s:\n",
14417 get_section_name (reader
->die_section
),
14418 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
14419 bfd_get_filename (reader
->abfd
));
14420 dump_die (die
, dwarf2_die_debug
);
14426 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
14428 The caller is responsible for filling in the extra attributes
14429 and updating (*DIEP)->num_attrs.
14430 Set DIEP to point to a newly allocated die with its information,
14431 except for its child, sibling, and parent fields.
14432 Set HAS_CHILDREN to tell whether the die has children or not. */
14434 static const gdb_byte
*
14435 read_full_die_1 (const struct die_reader_specs
*reader
,
14436 struct die_info
**diep
, const gdb_byte
*info_ptr
,
14437 int *has_children
, int num_extra_attrs
)
14439 unsigned int abbrev_number
, bytes_read
, i
;
14440 sect_offset offset
;
14441 struct abbrev_info
*abbrev
;
14442 struct die_info
*die
;
14443 struct dwarf2_cu
*cu
= reader
->cu
;
14444 bfd
*abfd
= reader
->abfd
;
14446 offset
.sect_off
= info_ptr
- reader
->buffer
;
14447 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14448 info_ptr
+= bytes_read
;
14449 if (!abbrev_number
)
14456 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
14458 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
14460 bfd_get_filename (abfd
));
14462 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
14463 die
->offset
= offset
;
14464 die
->tag
= abbrev
->tag
;
14465 die
->abbrev
= abbrev_number
;
14467 /* Make the result usable.
14468 The caller needs to update num_attrs after adding the extra
14470 die
->num_attrs
= abbrev
->num_attrs
;
14472 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
14473 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
14477 *has_children
= abbrev
->has_children
;
14481 /* Read a die and all its attributes.
14482 Set DIEP to point to a newly allocated die with its information,
14483 except for its child, sibling, and parent fields.
14484 Set HAS_CHILDREN to tell whether the die has children or not. */
14486 static const gdb_byte
*
14487 read_full_die (const struct die_reader_specs
*reader
,
14488 struct die_info
**diep
, const gdb_byte
*info_ptr
,
14491 const gdb_byte
*result
;
14493 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
14495 if (dwarf2_die_debug
)
14497 fprintf_unfiltered (gdb_stdlog
,
14498 "Read die from %s@0x%x of %s:\n",
14499 get_section_name (reader
->die_section
),
14500 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
14501 bfd_get_filename (reader
->abfd
));
14502 dump_die (*diep
, dwarf2_die_debug
);
14508 /* Abbreviation tables.
14510 In DWARF version 2, the description of the debugging information is
14511 stored in a separate .debug_abbrev section. Before we read any
14512 dies from a section we read in all abbreviations and install them
14513 in a hash table. */
14515 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
14517 static struct abbrev_info
*
14518 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
14520 struct abbrev_info
*abbrev
;
14522 abbrev
= (struct abbrev_info
*)
14523 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
14524 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14528 /* Add an abbreviation to the table. */
14531 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
14532 unsigned int abbrev_number
,
14533 struct abbrev_info
*abbrev
)
14535 unsigned int hash_number
;
14537 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
14538 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
14539 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
14542 /* Look up an abbrev in the table.
14543 Returns NULL if the abbrev is not found. */
14545 static struct abbrev_info
*
14546 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
14547 unsigned int abbrev_number
)
14549 unsigned int hash_number
;
14550 struct abbrev_info
*abbrev
;
14552 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
14553 abbrev
= abbrev_table
->abbrevs
[hash_number
];
14557 if (abbrev
->number
== abbrev_number
)
14559 abbrev
= abbrev
->next
;
14564 /* Read in an abbrev table. */
14566 static struct abbrev_table
*
14567 abbrev_table_read_table (struct dwarf2_section_info
*section
,
14568 sect_offset offset
)
14570 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14571 bfd
*abfd
= get_section_bfd_owner (section
);
14572 struct abbrev_table
*abbrev_table
;
14573 const gdb_byte
*abbrev_ptr
;
14574 struct abbrev_info
*cur_abbrev
;
14575 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
14576 unsigned int abbrev_form
;
14577 struct attr_abbrev
*cur_attrs
;
14578 unsigned int allocated_attrs
;
14580 abbrev_table
= XMALLOC (struct abbrev_table
);
14581 abbrev_table
->offset
= offset
;
14582 obstack_init (&abbrev_table
->abbrev_obstack
);
14583 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
14585 * sizeof (struct abbrev_info
*)));
14586 memset (abbrev_table
->abbrevs
, 0,
14587 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
14589 dwarf2_read_section (objfile
, section
);
14590 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
14591 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
14592 abbrev_ptr
+= bytes_read
;
14594 allocated_attrs
= ATTR_ALLOC_CHUNK
;
14595 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
14597 /* Loop until we reach an abbrev number of 0. */
14598 while (abbrev_number
)
14600 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
14602 /* read in abbrev header */
14603 cur_abbrev
->number
= abbrev_number
;
14604 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
14605 abbrev_ptr
+= bytes_read
;
14606 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
14609 /* now read in declarations */
14610 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
14611 abbrev_ptr
+= bytes_read
;
14612 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
14613 abbrev_ptr
+= bytes_read
;
14614 while (abbrev_name
)
14616 if (cur_abbrev
->num_attrs
== allocated_attrs
)
14618 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
14620 = xrealloc (cur_attrs
, (allocated_attrs
14621 * sizeof (struct attr_abbrev
)));
14624 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
14625 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
14626 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
14627 abbrev_ptr
+= bytes_read
;
14628 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
14629 abbrev_ptr
+= bytes_read
;
14632 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
14633 (cur_abbrev
->num_attrs
14634 * sizeof (struct attr_abbrev
)));
14635 memcpy (cur_abbrev
->attrs
, cur_attrs
,
14636 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
14638 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
14640 /* Get next abbreviation.
14641 Under Irix6 the abbreviations for a compilation unit are not
14642 always properly terminated with an abbrev number of 0.
14643 Exit loop if we encounter an abbreviation which we have
14644 already read (which means we are about to read the abbreviations
14645 for the next compile unit) or if the end of the abbreviation
14646 table is reached. */
14647 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
14649 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
14650 abbrev_ptr
+= bytes_read
;
14651 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
14656 return abbrev_table
;
14659 /* Free the resources held by ABBREV_TABLE. */
14662 abbrev_table_free (struct abbrev_table
*abbrev_table
)
14664 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
14665 xfree (abbrev_table
);
14668 /* Same as abbrev_table_free but as a cleanup.
14669 We pass in a pointer to the pointer to the table so that we can
14670 set the pointer to NULL when we're done. It also simplifies
14671 build_type_unit_groups. */
14674 abbrev_table_free_cleanup (void *table_ptr
)
14676 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
14678 if (*abbrev_table_ptr
!= NULL
)
14679 abbrev_table_free (*abbrev_table_ptr
);
14680 *abbrev_table_ptr
= NULL
;
14683 /* Read the abbrev table for CU from ABBREV_SECTION. */
14686 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
14687 struct dwarf2_section_info
*abbrev_section
)
14690 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
14693 /* Release the memory used by the abbrev table for a compilation unit. */
14696 dwarf2_free_abbrev_table (void *ptr_to_cu
)
14698 struct dwarf2_cu
*cu
= ptr_to_cu
;
14700 if (cu
->abbrev_table
!= NULL
)
14701 abbrev_table_free (cu
->abbrev_table
);
14702 /* Set this to NULL so that we SEGV if we try to read it later,
14703 and also because free_comp_unit verifies this is NULL. */
14704 cu
->abbrev_table
= NULL
;
14707 /* Returns nonzero if TAG represents a type that we might generate a partial
14711 is_type_tag_for_partial (int tag
)
14716 /* Some types that would be reasonable to generate partial symbols for,
14717 that we don't at present. */
14718 case DW_TAG_array_type
:
14719 case DW_TAG_file_type
:
14720 case DW_TAG_ptr_to_member_type
:
14721 case DW_TAG_set_type
:
14722 case DW_TAG_string_type
:
14723 case DW_TAG_subroutine_type
:
14725 case DW_TAG_base_type
:
14726 case DW_TAG_class_type
:
14727 case DW_TAG_interface_type
:
14728 case DW_TAG_enumeration_type
:
14729 case DW_TAG_structure_type
:
14730 case DW_TAG_subrange_type
:
14731 case DW_TAG_typedef
:
14732 case DW_TAG_union_type
:
14739 /* Load all DIEs that are interesting for partial symbols into memory. */
14741 static struct partial_die_info
*
14742 load_partial_dies (const struct die_reader_specs
*reader
,
14743 const gdb_byte
*info_ptr
, int building_psymtab
)
14745 struct dwarf2_cu
*cu
= reader
->cu
;
14746 struct objfile
*objfile
= cu
->objfile
;
14747 struct partial_die_info
*part_die
;
14748 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
14749 struct abbrev_info
*abbrev
;
14750 unsigned int bytes_read
;
14751 unsigned int load_all
= 0;
14752 int nesting_level
= 1;
14757 gdb_assert (cu
->per_cu
!= NULL
);
14758 if (cu
->per_cu
->load_all_dies
)
14762 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14766 &cu
->comp_unit_obstack
,
14767 hashtab_obstack_allocate
,
14768 dummy_obstack_deallocate
);
14770 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
14771 sizeof (struct partial_die_info
));
14775 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
14777 /* A NULL abbrev means the end of a series of children. */
14778 if (abbrev
== NULL
)
14780 if (--nesting_level
== 0)
14782 /* PART_DIE was probably the last thing allocated on the
14783 comp_unit_obstack, so we could call obstack_free
14784 here. We don't do that because the waste is small,
14785 and will be cleaned up when we're done with this
14786 compilation unit. This way, we're also more robust
14787 against other users of the comp_unit_obstack. */
14790 info_ptr
+= bytes_read
;
14791 last_die
= parent_die
;
14792 parent_die
= parent_die
->die_parent
;
14796 /* Check for template arguments. We never save these; if
14797 they're seen, we just mark the parent, and go on our way. */
14798 if (parent_die
!= NULL
14799 && cu
->language
== language_cplus
14800 && (abbrev
->tag
== DW_TAG_template_type_param
14801 || abbrev
->tag
== DW_TAG_template_value_param
))
14803 parent_die
->has_template_arguments
= 1;
14807 /* We don't need a partial DIE for the template argument. */
14808 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
14813 /* We only recurse into c++ subprograms looking for template arguments.
14814 Skip their other children. */
14816 && cu
->language
== language_cplus
14817 && parent_die
!= NULL
14818 && parent_die
->tag
== DW_TAG_subprogram
)
14820 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
14824 /* Check whether this DIE is interesting enough to save. Normally
14825 we would not be interested in members here, but there may be
14826 later variables referencing them via DW_AT_specification (for
14827 static members). */
14829 && !is_type_tag_for_partial (abbrev
->tag
)
14830 && abbrev
->tag
!= DW_TAG_constant
14831 && abbrev
->tag
!= DW_TAG_enumerator
14832 && abbrev
->tag
!= DW_TAG_subprogram
14833 && abbrev
->tag
!= DW_TAG_lexical_block
14834 && abbrev
->tag
!= DW_TAG_variable
14835 && abbrev
->tag
!= DW_TAG_namespace
14836 && abbrev
->tag
!= DW_TAG_module
14837 && abbrev
->tag
!= DW_TAG_member
14838 && abbrev
->tag
!= DW_TAG_imported_unit
)
14840 /* Otherwise we skip to the next sibling, if any. */
14841 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
14845 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
14848 /* This two-pass algorithm for processing partial symbols has a
14849 high cost in cache pressure. Thus, handle some simple cases
14850 here which cover the majority of C partial symbols. DIEs
14851 which neither have specification tags in them, nor could have
14852 specification tags elsewhere pointing at them, can simply be
14853 processed and discarded.
14855 This segment is also optional; scan_partial_symbols and
14856 add_partial_symbol will handle these DIEs if we chain
14857 them in normally. When compilers which do not emit large
14858 quantities of duplicate debug information are more common,
14859 this code can probably be removed. */
14861 /* Any complete simple types at the top level (pretty much all
14862 of them, for a language without namespaces), can be processed
14864 if (parent_die
== NULL
14865 && part_die
->has_specification
== 0
14866 && part_die
->is_declaration
== 0
14867 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
14868 || part_die
->tag
== DW_TAG_base_type
14869 || part_die
->tag
== DW_TAG_subrange_type
))
14871 if (building_psymtab
&& part_die
->name
!= NULL
)
14872 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
14873 VAR_DOMAIN
, LOC_TYPEDEF
,
14874 &objfile
->static_psymbols
,
14875 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
14876 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
14880 /* The exception for DW_TAG_typedef with has_children above is
14881 a workaround of GCC PR debug/47510. In the case of this complaint
14882 type_name_no_tag_or_error will error on such types later.
14884 GDB skipped children of DW_TAG_typedef by the shortcut above and then
14885 it could not find the child DIEs referenced later, this is checked
14886 above. In correct DWARF DW_TAG_typedef should have no children. */
14888 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
14889 complaint (&symfile_complaints
,
14890 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
14891 "- DIE at 0x%x [in module %s]"),
14892 part_die
->offset
.sect_off
, objfile_name (objfile
));
14894 /* If we're at the second level, and we're an enumerator, and
14895 our parent has no specification (meaning possibly lives in a
14896 namespace elsewhere), then we can add the partial symbol now
14897 instead of queueing it. */
14898 if (part_die
->tag
== DW_TAG_enumerator
14899 && parent_die
!= NULL
14900 && parent_die
->die_parent
== NULL
14901 && parent_die
->tag
== DW_TAG_enumeration_type
14902 && parent_die
->has_specification
== 0)
14904 if (part_die
->name
== NULL
)
14905 complaint (&symfile_complaints
,
14906 _("malformed enumerator DIE ignored"));
14907 else if (building_psymtab
)
14908 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
14909 VAR_DOMAIN
, LOC_CONST
,
14910 (cu
->language
== language_cplus
14911 || cu
->language
== language_java
)
14912 ? &objfile
->global_psymbols
14913 : &objfile
->static_psymbols
,
14914 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
14916 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
14920 /* We'll save this DIE so link it in. */
14921 part_die
->die_parent
= parent_die
;
14922 part_die
->die_sibling
= NULL
;
14923 part_die
->die_child
= NULL
;
14925 if (last_die
&& last_die
== parent_die
)
14926 last_die
->die_child
= part_die
;
14928 last_die
->die_sibling
= part_die
;
14930 last_die
= part_die
;
14932 if (first_die
== NULL
)
14933 first_die
= part_die
;
14935 /* Maybe add the DIE to the hash table. Not all DIEs that we
14936 find interesting need to be in the hash table, because we
14937 also have the parent/sibling/child chains; only those that we
14938 might refer to by offset later during partial symbol reading.
14940 For now this means things that might have be the target of a
14941 DW_AT_specification, DW_AT_abstract_origin, or
14942 DW_AT_extension. DW_AT_extension will refer only to
14943 namespaces; DW_AT_abstract_origin refers to functions (and
14944 many things under the function DIE, but we do not recurse
14945 into function DIEs during partial symbol reading) and
14946 possibly variables as well; DW_AT_specification refers to
14947 declarations. Declarations ought to have the DW_AT_declaration
14948 flag. It happens that GCC forgets to put it in sometimes, but
14949 only for functions, not for types.
14951 Adding more things than necessary to the hash table is harmless
14952 except for the performance cost. Adding too few will result in
14953 wasted time in find_partial_die, when we reread the compilation
14954 unit with load_all_dies set. */
14957 || abbrev
->tag
== DW_TAG_constant
14958 || abbrev
->tag
== DW_TAG_subprogram
14959 || abbrev
->tag
== DW_TAG_variable
14960 || abbrev
->tag
== DW_TAG_namespace
14961 || part_die
->is_declaration
)
14965 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
14966 part_die
->offset
.sect_off
, INSERT
);
14970 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
14971 sizeof (struct partial_die_info
));
14973 /* For some DIEs we want to follow their children (if any). For C
14974 we have no reason to follow the children of structures; for other
14975 languages we have to, so that we can get at method physnames
14976 to infer fully qualified class names, for DW_AT_specification,
14977 and for C++ template arguments. For C++, we also look one level
14978 inside functions to find template arguments (if the name of the
14979 function does not already contain the template arguments).
14981 For Ada, we need to scan the children of subprograms and lexical
14982 blocks as well because Ada allows the definition of nested
14983 entities that could be interesting for the debugger, such as
14984 nested subprograms for instance. */
14985 if (last_die
->has_children
14987 || last_die
->tag
== DW_TAG_namespace
14988 || last_die
->tag
== DW_TAG_module
14989 || last_die
->tag
== DW_TAG_enumeration_type
14990 || (cu
->language
== language_cplus
14991 && last_die
->tag
== DW_TAG_subprogram
14992 && (last_die
->name
== NULL
14993 || strchr (last_die
->name
, '<') == NULL
))
14994 || (cu
->language
!= language_c
14995 && (last_die
->tag
== DW_TAG_class_type
14996 || last_die
->tag
== DW_TAG_interface_type
14997 || last_die
->tag
== DW_TAG_structure_type
14998 || last_die
->tag
== DW_TAG_union_type
))
14999 || (cu
->language
== language_ada
15000 && (last_die
->tag
== DW_TAG_subprogram
15001 || last_die
->tag
== DW_TAG_lexical_block
))))
15004 parent_die
= last_die
;
15008 /* Otherwise we skip to the next sibling, if any. */
15009 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
15011 /* Back to the top, do it again. */
15015 /* Read a minimal amount of information into the minimal die structure. */
15017 static const gdb_byte
*
15018 read_partial_die (const struct die_reader_specs
*reader
,
15019 struct partial_die_info
*part_die
,
15020 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
15021 const gdb_byte
*info_ptr
)
15023 struct dwarf2_cu
*cu
= reader
->cu
;
15024 struct objfile
*objfile
= cu
->objfile
;
15025 const gdb_byte
*buffer
= reader
->buffer
;
15027 struct attribute attr
;
15028 int has_low_pc_attr
= 0;
15029 int has_high_pc_attr
= 0;
15030 int high_pc_relative
= 0;
15032 memset (part_die
, 0, sizeof (struct partial_die_info
));
15034 part_die
->offset
.sect_off
= info_ptr
- buffer
;
15036 info_ptr
+= abbrev_len
;
15038 if (abbrev
== NULL
)
15041 part_die
->tag
= abbrev
->tag
;
15042 part_die
->has_children
= abbrev
->has_children
;
15044 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
15046 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
15048 /* Store the data if it is of an attribute we want to keep in a
15049 partial symbol table. */
15053 switch (part_die
->tag
)
15055 case DW_TAG_compile_unit
:
15056 case DW_TAG_partial_unit
:
15057 case DW_TAG_type_unit
:
15058 /* Compilation units have a DW_AT_name that is a filename, not
15059 a source language identifier. */
15060 case DW_TAG_enumeration_type
:
15061 case DW_TAG_enumerator
:
15062 /* These tags always have simple identifiers already; no need
15063 to canonicalize them. */
15064 part_die
->name
= DW_STRING (&attr
);
15068 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
15069 &objfile
->objfile_obstack
);
15073 case DW_AT_linkage_name
:
15074 case DW_AT_MIPS_linkage_name
:
15075 /* Note that both forms of linkage name might appear. We
15076 assume they will be the same, and we only store the last
15078 if (cu
->language
== language_ada
)
15079 part_die
->name
= DW_STRING (&attr
);
15080 part_die
->linkage_name
= DW_STRING (&attr
);
15083 has_low_pc_attr
= 1;
15084 part_die
->lowpc
= DW_ADDR (&attr
);
15086 case DW_AT_high_pc
:
15087 has_high_pc_attr
= 1;
15088 if (attr
.form
== DW_FORM_addr
15089 || attr
.form
== DW_FORM_GNU_addr_index
)
15090 part_die
->highpc
= DW_ADDR (&attr
);
15093 high_pc_relative
= 1;
15094 part_die
->highpc
= DW_UNSND (&attr
);
15097 case DW_AT_location
:
15098 /* Support the .debug_loc offsets. */
15099 if (attr_form_is_block (&attr
))
15101 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
15103 else if (attr_form_is_section_offset (&attr
))
15105 dwarf2_complex_location_expr_complaint ();
15109 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15110 "partial symbol information");
15113 case DW_AT_external
:
15114 part_die
->is_external
= DW_UNSND (&attr
);
15116 case DW_AT_declaration
:
15117 part_die
->is_declaration
= DW_UNSND (&attr
);
15120 part_die
->has_type
= 1;
15122 case DW_AT_abstract_origin
:
15123 case DW_AT_specification
:
15124 case DW_AT_extension
:
15125 part_die
->has_specification
= 1;
15126 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
15127 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
15128 || cu
->per_cu
->is_dwz
);
15130 case DW_AT_sibling
:
15131 /* Ignore absolute siblings, they might point outside of
15132 the current compile unit. */
15133 if (attr
.form
== DW_FORM_ref_addr
)
15134 complaint (&symfile_complaints
,
15135 _("ignoring absolute DW_AT_sibling"));
15137 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
15139 case DW_AT_byte_size
:
15140 part_die
->has_byte_size
= 1;
15142 case DW_AT_calling_convention
:
15143 /* DWARF doesn't provide a way to identify a program's source-level
15144 entry point. DW_AT_calling_convention attributes are only meant
15145 to describe functions' calling conventions.
15147 However, because it's a necessary piece of information in
15148 Fortran, and because DW_CC_program is the only piece of debugging
15149 information whose definition refers to a 'main program' at all,
15150 several compilers have begun marking Fortran main programs with
15151 DW_CC_program --- even when those functions use the standard
15152 calling conventions.
15154 So until DWARF specifies a way to provide this information and
15155 compilers pick up the new representation, we'll support this
15157 if (DW_UNSND (&attr
) == DW_CC_program
15158 && cu
->language
== language_fortran
)
15160 set_main_name (part_die
->name
);
15162 /* As this DIE has a static linkage the name would be difficult
15163 to look up later. */
15164 language_of_main
= language_fortran
;
15168 if (DW_UNSND (&attr
) == DW_INL_inlined
15169 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
15170 part_die
->may_be_inlined
= 1;
15174 if (part_die
->tag
== DW_TAG_imported_unit
)
15176 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
15177 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
15178 || cu
->per_cu
->is_dwz
);
15187 if (high_pc_relative
)
15188 part_die
->highpc
+= part_die
->lowpc
;
15190 if (has_low_pc_attr
&& has_high_pc_attr
)
15192 /* When using the GNU linker, .gnu.linkonce. sections are used to
15193 eliminate duplicate copies of functions and vtables and such.
15194 The linker will arbitrarily choose one and discard the others.
15195 The AT_*_pc values for such functions refer to local labels in
15196 these sections. If the section from that file was discarded, the
15197 labels are not in the output, so the relocs get a value of 0.
15198 If this is a discarded function, mark the pc bounds as invalid,
15199 so that GDB will ignore it. */
15200 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
15202 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15204 complaint (&symfile_complaints
,
15205 _("DW_AT_low_pc %s is zero "
15206 "for DIE at 0x%x [in module %s]"),
15207 paddress (gdbarch
, part_die
->lowpc
),
15208 part_die
->offset
.sect_off
, objfile_name (objfile
));
15210 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
15211 else if (part_die
->lowpc
>= part_die
->highpc
)
15213 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15215 complaint (&symfile_complaints
,
15216 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
15217 "for DIE at 0x%x [in module %s]"),
15218 paddress (gdbarch
, part_die
->lowpc
),
15219 paddress (gdbarch
, part_die
->highpc
),
15220 part_die
->offset
.sect_off
, objfile_name (objfile
));
15223 part_die
->has_pc_info
= 1;
15229 /* Find a cached partial DIE at OFFSET in CU. */
15231 static struct partial_die_info
*
15232 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
15234 struct partial_die_info
*lookup_die
= NULL
;
15235 struct partial_die_info part_die
;
15237 part_die
.offset
= offset
;
15238 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
15244 /* Find a partial DIE at OFFSET, which may or may not be in CU,
15245 except in the case of .debug_types DIEs which do not reference
15246 outside their CU (they do however referencing other types via
15247 DW_FORM_ref_sig8). */
15249 static struct partial_die_info
*
15250 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
15252 struct objfile
*objfile
= cu
->objfile
;
15253 struct dwarf2_per_cu_data
*per_cu
= NULL
;
15254 struct partial_die_info
*pd
= NULL
;
15256 if (offset_in_dwz
== cu
->per_cu
->is_dwz
15257 && offset_in_cu_p (&cu
->header
, offset
))
15259 pd
= find_partial_die_in_comp_unit (offset
, cu
);
15262 /* We missed recording what we needed.
15263 Load all dies and try again. */
15264 per_cu
= cu
->per_cu
;
15268 /* TUs don't reference other CUs/TUs (except via type signatures). */
15269 if (cu
->per_cu
->is_debug_types
)
15271 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
15272 " external reference to offset 0x%lx [in module %s].\n"),
15273 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
15274 bfd_get_filename (objfile
->obfd
));
15276 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
15279 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
15280 load_partial_comp_unit (per_cu
);
15282 per_cu
->cu
->last_used
= 0;
15283 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
15286 /* If we didn't find it, and not all dies have been loaded,
15287 load them all and try again. */
15289 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
15291 per_cu
->load_all_dies
= 1;
15293 /* This is nasty. When we reread the DIEs, somewhere up the call chain
15294 THIS_CU->cu may already be in use. So we can't just free it and
15295 replace its DIEs with the ones we read in. Instead, we leave those
15296 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
15297 and clobber THIS_CU->cu->partial_dies with the hash table for the new
15299 load_partial_comp_unit (per_cu
);
15301 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
15305 internal_error (__FILE__
, __LINE__
,
15306 _("could not find partial DIE 0x%x "
15307 "in cache [from module %s]\n"),
15308 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
15312 /* See if we can figure out if the class lives in a namespace. We do
15313 this by looking for a member function; its demangled name will
15314 contain namespace info, if there is any. */
15317 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
15318 struct dwarf2_cu
*cu
)
15320 /* NOTE: carlton/2003-10-07: Getting the info this way changes
15321 what template types look like, because the demangler
15322 frequently doesn't give the same name as the debug info. We
15323 could fix this by only using the demangled name to get the
15324 prefix (but see comment in read_structure_type). */
15326 struct partial_die_info
*real_pdi
;
15327 struct partial_die_info
*child_pdi
;
15329 /* If this DIE (this DIE's specification, if any) has a parent, then
15330 we should not do this. We'll prepend the parent's fully qualified
15331 name when we create the partial symbol. */
15333 real_pdi
= struct_pdi
;
15334 while (real_pdi
->has_specification
)
15335 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
15336 real_pdi
->spec_is_dwz
, cu
);
15338 if (real_pdi
->die_parent
!= NULL
)
15341 for (child_pdi
= struct_pdi
->die_child
;
15343 child_pdi
= child_pdi
->die_sibling
)
15345 if (child_pdi
->tag
== DW_TAG_subprogram
15346 && child_pdi
->linkage_name
!= NULL
)
15348 char *actual_class_name
15349 = language_class_name_from_physname (cu
->language_defn
,
15350 child_pdi
->linkage_name
);
15351 if (actual_class_name
!= NULL
)
15354 = obstack_copy0 (&cu
->objfile
->objfile_obstack
,
15356 strlen (actual_class_name
));
15357 xfree (actual_class_name
);
15364 /* Adjust PART_DIE before generating a symbol for it. This function
15365 may set the is_external flag or change the DIE's name. */
15368 fixup_partial_die (struct partial_die_info
*part_die
,
15369 struct dwarf2_cu
*cu
)
15371 /* Once we've fixed up a die, there's no point in doing so again.
15372 This also avoids a memory leak if we were to call
15373 guess_partial_die_structure_name multiple times. */
15374 if (part_die
->fixup_called
)
15377 /* If we found a reference attribute and the DIE has no name, try
15378 to find a name in the referred to DIE. */
15380 if (part_die
->name
== NULL
&& part_die
->has_specification
)
15382 struct partial_die_info
*spec_die
;
15384 spec_die
= find_partial_die (part_die
->spec_offset
,
15385 part_die
->spec_is_dwz
, cu
);
15387 fixup_partial_die (spec_die
, cu
);
15389 if (spec_die
->name
)
15391 part_die
->name
= spec_die
->name
;
15393 /* Copy DW_AT_external attribute if it is set. */
15394 if (spec_die
->is_external
)
15395 part_die
->is_external
= spec_die
->is_external
;
15399 /* Set default names for some unnamed DIEs. */
15401 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
15402 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
15404 /* If there is no parent die to provide a namespace, and there are
15405 children, see if we can determine the namespace from their linkage
15407 if (cu
->language
== language_cplus
15408 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
15409 && part_die
->die_parent
== NULL
15410 && part_die
->has_children
15411 && (part_die
->tag
== DW_TAG_class_type
15412 || part_die
->tag
== DW_TAG_structure_type
15413 || part_die
->tag
== DW_TAG_union_type
))
15414 guess_partial_die_structure_name (part_die
, cu
);
15416 /* GCC might emit a nameless struct or union that has a linkage
15417 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
15418 if (part_die
->name
== NULL
15419 && (part_die
->tag
== DW_TAG_class_type
15420 || part_die
->tag
== DW_TAG_interface_type
15421 || part_die
->tag
== DW_TAG_structure_type
15422 || part_die
->tag
== DW_TAG_union_type
)
15423 && part_die
->linkage_name
!= NULL
)
15427 demangled
= gdb_demangle (part_die
->linkage_name
, DMGL_TYPES
);
15432 /* Strip any leading namespaces/classes, keep only the base name.
15433 DW_AT_name for named DIEs does not contain the prefixes. */
15434 base
= strrchr (demangled
, ':');
15435 if (base
&& base
> demangled
&& base
[-1] == ':')
15440 part_die
->name
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
15441 base
, strlen (base
));
15446 part_die
->fixup_called
= 1;
15449 /* Read an attribute value described by an attribute form. */
15451 static const gdb_byte
*
15452 read_attribute_value (const struct die_reader_specs
*reader
,
15453 struct attribute
*attr
, unsigned form
,
15454 const gdb_byte
*info_ptr
)
15456 struct dwarf2_cu
*cu
= reader
->cu
;
15457 bfd
*abfd
= reader
->abfd
;
15458 struct comp_unit_head
*cu_header
= &cu
->header
;
15459 unsigned int bytes_read
;
15460 struct dwarf_block
*blk
;
15465 case DW_FORM_ref_addr
:
15466 if (cu
->header
.version
== 2)
15467 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
15469 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
15470 &cu
->header
, &bytes_read
);
15471 info_ptr
+= bytes_read
;
15473 case DW_FORM_GNU_ref_alt
:
15474 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
15475 info_ptr
+= bytes_read
;
15478 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
15479 info_ptr
+= bytes_read
;
15481 case DW_FORM_block2
:
15482 blk
= dwarf_alloc_block (cu
);
15483 blk
->size
= read_2_bytes (abfd
, info_ptr
);
15485 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
15486 info_ptr
+= blk
->size
;
15487 DW_BLOCK (attr
) = blk
;
15489 case DW_FORM_block4
:
15490 blk
= dwarf_alloc_block (cu
);
15491 blk
->size
= read_4_bytes (abfd
, info_ptr
);
15493 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
15494 info_ptr
+= blk
->size
;
15495 DW_BLOCK (attr
) = blk
;
15497 case DW_FORM_data2
:
15498 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
15501 case DW_FORM_data4
:
15502 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
15505 case DW_FORM_data8
:
15506 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
15509 case DW_FORM_sec_offset
:
15510 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
15511 info_ptr
+= bytes_read
;
15513 case DW_FORM_string
:
15514 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
15515 DW_STRING_IS_CANONICAL (attr
) = 0;
15516 info_ptr
+= bytes_read
;
15519 if (!cu
->per_cu
->is_dwz
)
15521 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
15523 DW_STRING_IS_CANONICAL (attr
) = 0;
15524 info_ptr
+= bytes_read
;
15528 case DW_FORM_GNU_strp_alt
:
15530 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
15531 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
15534 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
15535 DW_STRING_IS_CANONICAL (attr
) = 0;
15536 info_ptr
+= bytes_read
;
15539 case DW_FORM_exprloc
:
15540 case DW_FORM_block
:
15541 blk
= dwarf_alloc_block (cu
);
15542 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15543 info_ptr
+= bytes_read
;
15544 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
15545 info_ptr
+= blk
->size
;
15546 DW_BLOCK (attr
) = blk
;
15548 case DW_FORM_block1
:
15549 blk
= dwarf_alloc_block (cu
);
15550 blk
->size
= read_1_byte (abfd
, info_ptr
);
15552 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
15553 info_ptr
+= blk
->size
;
15554 DW_BLOCK (attr
) = blk
;
15556 case DW_FORM_data1
:
15557 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
15561 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
15564 case DW_FORM_flag_present
:
15565 DW_UNSND (attr
) = 1;
15567 case DW_FORM_sdata
:
15568 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
15569 info_ptr
+= bytes_read
;
15571 case DW_FORM_udata
:
15572 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15573 info_ptr
+= bytes_read
;
15576 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
15577 + read_1_byte (abfd
, info_ptr
));
15581 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
15582 + read_2_bytes (abfd
, info_ptr
));
15586 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
15587 + read_4_bytes (abfd
, info_ptr
));
15591 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
15592 + read_8_bytes (abfd
, info_ptr
));
15595 case DW_FORM_ref_sig8
:
15596 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
15599 case DW_FORM_ref_udata
:
15600 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
15601 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
15602 info_ptr
+= bytes_read
;
15604 case DW_FORM_indirect
:
15605 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15606 info_ptr
+= bytes_read
;
15607 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
15609 case DW_FORM_GNU_addr_index
:
15610 if (reader
->dwo_file
== NULL
)
15612 /* For now flag a hard error.
15613 Later we can turn this into a complaint. */
15614 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
15615 dwarf_form_name (form
),
15616 bfd_get_filename (abfd
));
15618 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
15619 info_ptr
+= bytes_read
;
15621 case DW_FORM_GNU_str_index
:
15622 if (reader
->dwo_file
== NULL
)
15624 /* For now flag a hard error.
15625 Later we can turn this into a complaint if warranted. */
15626 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
15627 dwarf_form_name (form
),
15628 bfd_get_filename (abfd
));
15631 ULONGEST str_index
=
15632 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15634 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
15635 DW_STRING_IS_CANONICAL (attr
) = 0;
15636 info_ptr
+= bytes_read
;
15640 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
15641 dwarf_form_name (form
),
15642 bfd_get_filename (abfd
));
15646 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
15647 attr
->form
= DW_FORM_GNU_ref_alt
;
15649 /* We have seen instances where the compiler tried to emit a byte
15650 size attribute of -1 which ended up being encoded as an unsigned
15651 0xffffffff. Although 0xffffffff is technically a valid size value,
15652 an object of this size seems pretty unlikely so we can relatively
15653 safely treat these cases as if the size attribute was invalid and
15654 treat them as zero by default. */
15655 if (attr
->name
== DW_AT_byte_size
15656 && form
== DW_FORM_data4
15657 && DW_UNSND (attr
) >= 0xffffffff)
15660 (&symfile_complaints
,
15661 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
15662 hex_string (DW_UNSND (attr
)));
15663 DW_UNSND (attr
) = 0;
15669 /* Read an attribute described by an abbreviated attribute. */
15671 static const gdb_byte
*
15672 read_attribute (const struct die_reader_specs
*reader
,
15673 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
15674 const gdb_byte
*info_ptr
)
15676 attr
->name
= abbrev
->name
;
15677 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
15680 /* Read dwarf information from a buffer. */
15682 static unsigned int
15683 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
15685 return bfd_get_8 (abfd
, buf
);
15689 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
15691 return bfd_get_signed_8 (abfd
, buf
);
15694 static unsigned int
15695 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
15697 return bfd_get_16 (abfd
, buf
);
15701 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
15703 return bfd_get_signed_16 (abfd
, buf
);
15706 static unsigned int
15707 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
15709 return bfd_get_32 (abfd
, buf
);
15713 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
15715 return bfd_get_signed_32 (abfd
, buf
);
15719 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
15721 return bfd_get_64 (abfd
, buf
);
15725 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
15726 unsigned int *bytes_read
)
15728 struct comp_unit_head
*cu_header
= &cu
->header
;
15729 CORE_ADDR retval
= 0;
15731 if (cu_header
->signed_addr_p
)
15733 switch (cu_header
->addr_size
)
15736 retval
= bfd_get_signed_16 (abfd
, buf
);
15739 retval
= bfd_get_signed_32 (abfd
, buf
);
15742 retval
= bfd_get_signed_64 (abfd
, buf
);
15745 internal_error (__FILE__
, __LINE__
,
15746 _("read_address: bad switch, signed [in module %s]"),
15747 bfd_get_filename (abfd
));
15752 switch (cu_header
->addr_size
)
15755 retval
= bfd_get_16 (abfd
, buf
);
15758 retval
= bfd_get_32 (abfd
, buf
);
15761 retval
= bfd_get_64 (abfd
, buf
);
15764 internal_error (__FILE__
, __LINE__
,
15765 _("read_address: bad switch, "
15766 "unsigned [in module %s]"),
15767 bfd_get_filename (abfd
));
15771 *bytes_read
= cu_header
->addr_size
;
15775 /* Read the initial length from a section. The (draft) DWARF 3
15776 specification allows the initial length to take up either 4 bytes
15777 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
15778 bytes describe the length and all offsets will be 8 bytes in length
15781 An older, non-standard 64-bit format is also handled by this
15782 function. The older format in question stores the initial length
15783 as an 8-byte quantity without an escape value. Lengths greater
15784 than 2^32 aren't very common which means that the initial 4 bytes
15785 is almost always zero. Since a length value of zero doesn't make
15786 sense for the 32-bit format, this initial zero can be considered to
15787 be an escape value which indicates the presence of the older 64-bit
15788 format. As written, the code can't detect (old format) lengths
15789 greater than 4GB. If it becomes necessary to handle lengths
15790 somewhat larger than 4GB, we could allow other small values (such
15791 as the non-sensical values of 1, 2, and 3) to also be used as
15792 escape values indicating the presence of the old format.
15794 The value returned via bytes_read should be used to increment the
15795 relevant pointer after calling read_initial_length().
15797 [ Note: read_initial_length() and read_offset() are based on the
15798 document entitled "DWARF Debugging Information Format", revision
15799 3, draft 8, dated November 19, 2001. This document was obtained
15802 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
15804 This document is only a draft and is subject to change. (So beware.)
15806 Details regarding the older, non-standard 64-bit format were
15807 determined empirically by examining 64-bit ELF files produced by
15808 the SGI toolchain on an IRIX 6.5 machine.
15810 - Kevin, July 16, 2002
15814 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
15816 LONGEST length
= bfd_get_32 (abfd
, buf
);
15818 if (length
== 0xffffffff)
15820 length
= bfd_get_64 (abfd
, buf
+ 4);
15823 else if (length
== 0)
15825 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
15826 length
= bfd_get_64 (abfd
, buf
);
15837 /* Cover function for read_initial_length.
15838 Returns the length of the object at BUF, and stores the size of the
15839 initial length in *BYTES_READ and stores the size that offsets will be in
15841 If the initial length size is not equivalent to that specified in
15842 CU_HEADER then issue a complaint.
15843 This is useful when reading non-comp-unit headers. */
15846 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
15847 const struct comp_unit_head
*cu_header
,
15848 unsigned int *bytes_read
,
15849 unsigned int *offset_size
)
15851 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
15853 gdb_assert (cu_header
->initial_length_size
== 4
15854 || cu_header
->initial_length_size
== 8
15855 || cu_header
->initial_length_size
== 12);
15857 if (cu_header
->initial_length_size
!= *bytes_read
)
15858 complaint (&symfile_complaints
,
15859 _("intermixed 32-bit and 64-bit DWARF sections"));
15861 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
15865 /* Read an offset from the data stream. The size of the offset is
15866 given by cu_header->offset_size. */
15869 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
15870 const struct comp_unit_head
*cu_header
,
15871 unsigned int *bytes_read
)
15873 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
15875 *bytes_read
= cu_header
->offset_size
;
15879 /* Read an offset from the data stream. */
15882 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
15884 LONGEST retval
= 0;
15886 switch (offset_size
)
15889 retval
= bfd_get_32 (abfd
, buf
);
15892 retval
= bfd_get_64 (abfd
, buf
);
15895 internal_error (__FILE__
, __LINE__
,
15896 _("read_offset_1: bad switch [in module %s]"),
15897 bfd_get_filename (abfd
));
15903 static const gdb_byte
*
15904 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
15906 /* If the size of a host char is 8 bits, we can return a pointer
15907 to the buffer, otherwise we have to copy the data to a buffer
15908 allocated on the temporary obstack. */
15909 gdb_assert (HOST_CHAR_BIT
== 8);
15913 static const char *
15914 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
15915 unsigned int *bytes_read_ptr
)
15917 /* If the size of a host char is 8 bits, we can return a pointer
15918 to the string, otherwise we have to copy the string to a buffer
15919 allocated on the temporary obstack. */
15920 gdb_assert (HOST_CHAR_BIT
== 8);
15923 *bytes_read_ptr
= 1;
15926 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
15927 return (const char *) buf
;
15930 static const char *
15931 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
15933 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
15934 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
15935 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
15936 bfd_get_filename (abfd
));
15937 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
15938 error (_("DW_FORM_strp pointing outside of "
15939 ".debug_str section [in module %s]"),
15940 bfd_get_filename (abfd
));
15941 gdb_assert (HOST_CHAR_BIT
== 8);
15942 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
15944 return (const char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
15947 /* Read a string at offset STR_OFFSET in the .debug_str section from
15948 the .dwz file DWZ. Throw an error if the offset is too large. If
15949 the string consists of a single NUL byte, return NULL; otherwise
15950 return a pointer to the string. */
15952 static const char *
15953 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
15955 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
15957 if (dwz
->str
.buffer
== NULL
)
15958 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
15959 "section [in module %s]"),
15960 bfd_get_filename (dwz
->dwz_bfd
));
15961 if (str_offset
>= dwz
->str
.size
)
15962 error (_("DW_FORM_GNU_strp_alt pointing outside of "
15963 ".debug_str section [in module %s]"),
15964 bfd_get_filename (dwz
->dwz_bfd
));
15965 gdb_assert (HOST_CHAR_BIT
== 8);
15966 if (dwz
->str
.buffer
[str_offset
] == '\0')
15968 return (const char *) (dwz
->str
.buffer
+ str_offset
);
15971 static const char *
15972 read_indirect_string (bfd
*abfd
, const gdb_byte
*buf
,
15973 const struct comp_unit_head
*cu_header
,
15974 unsigned int *bytes_read_ptr
)
15976 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
15978 return read_indirect_string_at_offset (abfd
, str_offset
);
15982 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
15983 unsigned int *bytes_read_ptr
)
15986 unsigned int num_read
;
15988 unsigned char byte
;
15996 byte
= bfd_get_8 (abfd
, buf
);
15999 result
|= ((ULONGEST
) (byte
& 127) << shift
);
16000 if ((byte
& 128) == 0)
16006 *bytes_read_ptr
= num_read
;
16011 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
16012 unsigned int *bytes_read_ptr
)
16015 int i
, shift
, num_read
;
16016 unsigned char byte
;
16024 byte
= bfd_get_8 (abfd
, buf
);
16027 result
|= ((LONGEST
) (byte
& 127) << shift
);
16029 if ((byte
& 128) == 0)
16034 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
16035 result
|= -(((LONGEST
) 1) << shift
);
16036 *bytes_read_ptr
= num_read
;
16040 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
16041 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
16042 ADDR_SIZE is the size of addresses from the CU header. */
16045 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
16047 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16048 bfd
*abfd
= objfile
->obfd
;
16049 const gdb_byte
*info_ptr
;
16051 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
16052 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
16053 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
16054 objfile_name (objfile
));
16055 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
16056 error (_("DW_FORM_addr_index pointing outside of "
16057 ".debug_addr section [in module %s]"),
16058 objfile_name (objfile
));
16059 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
16060 + addr_base
+ addr_index
* addr_size
);
16061 if (addr_size
== 4)
16062 return bfd_get_32 (abfd
, info_ptr
);
16064 return bfd_get_64 (abfd
, info_ptr
);
16067 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
16070 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
16072 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
16075 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
16078 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
16079 unsigned int *bytes_read
)
16081 bfd
*abfd
= cu
->objfile
->obfd
;
16082 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
16084 return read_addr_index (cu
, addr_index
);
16087 /* Data structure to pass results from dwarf2_read_addr_index_reader
16088 back to dwarf2_read_addr_index. */
16090 struct dwarf2_read_addr_index_data
16092 ULONGEST addr_base
;
16096 /* die_reader_func for dwarf2_read_addr_index. */
16099 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
16100 const gdb_byte
*info_ptr
,
16101 struct die_info
*comp_unit_die
,
16105 struct dwarf2_cu
*cu
= reader
->cu
;
16106 struct dwarf2_read_addr_index_data
*aidata
=
16107 (struct dwarf2_read_addr_index_data
*) data
;
16109 aidata
->addr_base
= cu
->addr_base
;
16110 aidata
->addr_size
= cu
->header
.addr_size
;
16113 /* Given an index in .debug_addr, fetch the value.
16114 NOTE: This can be called during dwarf expression evaluation,
16115 long after the debug information has been read, and thus per_cu->cu
16116 may no longer exist. */
16119 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
16120 unsigned int addr_index
)
16122 struct objfile
*objfile
= per_cu
->objfile
;
16123 struct dwarf2_cu
*cu
= per_cu
->cu
;
16124 ULONGEST addr_base
;
16127 /* This is intended to be called from outside this file. */
16128 dw2_setup (objfile
);
16130 /* We need addr_base and addr_size.
16131 If we don't have PER_CU->cu, we have to get it.
16132 Nasty, but the alternative is storing the needed info in PER_CU,
16133 which at this point doesn't seem justified: it's not clear how frequently
16134 it would get used and it would increase the size of every PER_CU.
16135 Entry points like dwarf2_per_cu_addr_size do a similar thing
16136 so we're not in uncharted territory here.
16137 Alas we need to be a bit more complicated as addr_base is contained
16140 We don't need to read the entire CU(/TU).
16141 We just need the header and top level die.
16143 IWBN to use the aging mechanism to let us lazily later discard the CU.
16144 For now we skip this optimization. */
16148 addr_base
= cu
->addr_base
;
16149 addr_size
= cu
->header
.addr_size
;
16153 struct dwarf2_read_addr_index_data aidata
;
16155 /* Note: We can't use init_cutu_and_read_dies_simple here,
16156 we need addr_base. */
16157 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
16158 dwarf2_read_addr_index_reader
, &aidata
);
16159 addr_base
= aidata
.addr_base
;
16160 addr_size
= aidata
.addr_size
;
16163 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
16166 /* Given a DW_FORM_GNU_str_index, fetch the string.
16167 This is only used by the Fission support. */
16169 static const char *
16170 read_str_index (const struct die_reader_specs
*reader
,
16171 struct dwarf2_cu
*cu
, ULONGEST str_index
)
16173 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16174 const char *dwo_name
= objfile_name (objfile
);
16175 bfd
*abfd
= objfile
->obfd
;
16176 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
16177 struct dwarf2_section_info
*str_offsets_section
=
16178 &reader
->dwo_file
->sections
.str_offsets
;
16179 const gdb_byte
*info_ptr
;
16180 ULONGEST str_offset
;
16181 static const char form_name
[] = "DW_FORM_GNU_str_index";
16183 dwarf2_read_section (objfile
, str_section
);
16184 dwarf2_read_section (objfile
, str_offsets_section
);
16185 if (str_section
->buffer
== NULL
)
16186 error (_("%s used without .debug_str.dwo section"
16187 " in CU at offset 0x%lx [in module %s]"),
16188 form_name
, (long) cu
->header
.offset
.sect_off
, dwo_name
);
16189 if (str_offsets_section
->buffer
== NULL
)
16190 error (_("%s used without .debug_str_offsets.dwo section"
16191 " in CU at offset 0x%lx [in module %s]"),
16192 form_name
, (long) cu
->header
.offset
.sect_off
, dwo_name
);
16193 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
16194 error (_("%s pointing outside of .debug_str_offsets.dwo"
16195 " section in CU at offset 0x%lx [in module %s]"),
16196 form_name
, (long) cu
->header
.offset
.sect_off
, dwo_name
);
16197 info_ptr
= (str_offsets_section
->buffer
16198 + str_index
* cu
->header
.offset_size
);
16199 if (cu
->header
.offset_size
== 4)
16200 str_offset
= bfd_get_32 (abfd
, info_ptr
);
16202 str_offset
= bfd_get_64 (abfd
, info_ptr
);
16203 if (str_offset
>= str_section
->size
)
16204 error (_("Offset from %s pointing outside of"
16205 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
16206 form_name
, (long) cu
->header
.offset
.sect_off
, dwo_name
);
16207 return (const char *) (str_section
->buffer
+ str_offset
);
16210 /* Return the length of an LEB128 number in BUF. */
16213 leb128_size (const gdb_byte
*buf
)
16215 const gdb_byte
*begin
= buf
;
16221 if ((byte
& 128) == 0)
16222 return buf
- begin
;
16227 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
16235 cu
->language
= language_c
;
16237 case DW_LANG_C_plus_plus
:
16238 cu
->language
= language_cplus
;
16241 cu
->language
= language_d
;
16243 case DW_LANG_Fortran77
:
16244 case DW_LANG_Fortran90
:
16245 case DW_LANG_Fortran95
:
16246 cu
->language
= language_fortran
;
16249 cu
->language
= language_go
;
16251 case DW_LANG_Mips_Assembler
:
16252 cu
->language
= language_asm
;
16255 cu
->language
= language_java
;
16257 case DW_LANG_Ada83
:
16258 case DW_LANG_Ada95
:
16259 cu
->language
= language_ada
;
16261 case DW_LANG_Modula2
:
16262 cu
->language
= language_m2
;
16264 case DW_LANG_Pascal83
:
16265 cu
->language
= language_pascal
;
16268 cu
->language
= language_objc
;
16270 case DW_LANG_Cobol74
:
16271 case DW_LANG_Cobol85
:
16273 cu
->language
= language_minimal
;
16276 cu
->language_defn
= language_def (cu
->language
);
16279 /* Return the named attribute or NULL if not there. */
16281 static struct attribute
*
16282 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
16287 struct attribute
*spec
= NULL
;
16289 for (i
= 0; i
< die
->num_attrs
; ++i
)
16291 if (die
->attrs
[i
].name
== name
)
16292 return &die
->attrs
[i
];
16293 if (die
->attrs
[i
].name
== DW_AT_specification
16294 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
16295 spec
= &die
->attrs
[i
];
16301 die
= follow_die_ref (die
, spec
, &cu
);
16307 /* Return the named attribute or NULL if not there,
16308 but do not follow DW_AT_specification, etc.
16309 This is for use in contexts where we're reading .debug_types dies.
16310 Following DW_AT_specification, DW_AT_abstract_origin will take us
16311 back up the chain, and we want to go down. */
16313 static struct attribute
*
16314 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
16318 for (i
= 0; i
< die
->num_attrs
; ++i
)
16319 if (die
->attrs
[i
].name
== name
)
16320 return &die
->attrs
[i
];
16325 /* Return non-zero iff the attribute NAME is defined for the given DIE,
16326 and holds a non-zero value. This function should only be used for
16327 DW_FORM_flag or DW_FORM_flag_present attributes. */
16330 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
16332 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16334 return (attr
&& DW_UNSND (attr
));
16338 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
16340 /* A DIE is a declaration if it has a DW_AT_declaration attribute
16341 which value is non-zero. However, we have to be careful with
16342 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
16343 (via dwarf2_flag_true_p) follows this attribute. So we may
16344 end up accidently finding a declaration attribute that belongs
16345 to a different DIE referenced by the specification attribute,
16346 even though the given DIE does not have a declaration attribute. */
16347 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
16348 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
16351 /* Return the die giving the specification for DIE, if there is
16352 one. *SPEC_CU is the CU containing DIE on input, and the CU
16353 containing the return value on output. If there is no
16354 specification, but there is an abstract origin, that is
16357 static struct die_info
*
16358 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
16360 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
16363 if (spec_attr
== NULL
)
16364 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
16366 if (spec_attr
== NULL
)
16369 return follow_die_ref (die
, spec_attr
, spec_cu
);
16372 /* Free the line_header structure *LH, and any arrays and strings it
16374 NOTE: This is also used as a "cleanup" function. */
16377 free_line_header (struct line_header
*lh
)
16379 if (lh
->standard_opcode_lengths
)
16380 xfree (lh
->standard_opcode_lengths
);
16382 /* Remember that all the lh->file_names[i].name pointers are
16383 pointers into debug_line_buffer, and don't need to be freed. */
16384 if (lh
->file_names
)
16385 xfree (lh
->file_names
);
16387 /* Similarly for the include directory names. */
16388 if (lh
->include_dirs
)
16389 xfree (lh
->include_dirs
);
16394 /* Add an entry to LH's include directory table. */
16397 add_include_dir (struct line_header
*lh
, const char *include_dir
)
16399 /* Grow the array if necessary. */
16400 if (lh
->include_dirs_size
== 0)
16402 lh
->include_dirs_size
= 1; /* for testing */
16403 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
16404 * sizeof (*lh
->include_dirs
));
16406 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
16408 lh
->include_dirs_size
*= 2;
16409 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
16410 (lh
->include_dirs_size
16411 * sizeof (*lh
->include_dirs
)));
16414 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
16417 /* Add an entry to LH's file name table. */
16420 add_file_name (struct line_header
*lh
,
16422 unsigned int dir_index
,
16423 unsigned int mod_time
,
16424 unsigned int length
)
16426 struct file_entry
*fe
;
16428 /* Grow the array if necessary. */
16429 if (lh
->file_names_size
== 0)
16431 lh
->file_names_size
= 1; /* for testing */
16432 lh
->file_names
= xmalloc (lh
->file_names_size
16433 * sizeof (*lh
->file_names
));
16435 else if (lh
->num_file_names
>= lh
->file_names_size
)
16437 lh
->file_names_size
*= 2;
16438 lh
->file_names
= xrealloc (lh
->file_names
,
16439 (lh
->file_names_size
16440 * sizeof (*lh
->file_names
)));
16443 fe
= &lh
->file_names
[lh
->num_file_names
++];
16445 fe
->dir_index
= dir_index
;
16446 fe
->mod_time
= mod_time
;
16447 fe
->length
= length
;
16448 fe
->included_p
= 0;
16452 /* A convenience function to find the proper .debug_line section for a
16455 static struct dwarf2_section_info
*
16456 get_debug_line_section (struct dwarf2_cu
*cu
)
16458 struct dwarf2_section_info
*section
;
16460 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
16462 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
16463 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
16464 else if (cu
->per_cu
->is_dwz
)
16466 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
16468 section
= &dwz
->line
;
16471 section
= &dwarf2_per_objfile
->line
;
16476 /* Read the statement program header starting at OFFSET in
16477 .debug_line, or .debug_line.dwo. Return a pointer
16478 to a struct line_header, allocated using xmalloc.
16480 NOTE: the strings in the include directory and file name tables of
16481 the returned object point into the dwarf line section buffer,
16482 and must not be freed. */
16484 static struct line_header
*
16485 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
16487 struct cleanup
*back_to
;
16488 struct line_header
*lh
;
16489 const gdb_byte
*line_ptr
;
16490 unsigned int bytes_read
, offset_size
;
16492 const char *cur_dir
, *cur_file
;
16493 struct dwarf2_section_info
*section
;
16496 section
= get_debug_line_section (cu
);
16497 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
16498 if (section
->buffer
== NULL
)
16500 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
16501 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
16503 complaint (&symfile_complaints
, _("missing .debug_line section"));
16507 /* We can't do this until we know the section is non-empty.
16508 Only then do we know we have such a section. */
16509 abfd
= get_section_bfd_owner (section
);
16511 /* Make sure that at least there's room for the total_length field.
16512 That could be 12 bytes long, but we're just going to fudge that. */
16513 if (offset
+ 4 >= section
->size
)
16515 dwarf2_statement_list_fits_in_line_number_section_complaint ();
16519 lh
= xmalloc (sizeof (*lh
));
16520 memset (lh
, 0, sizeof (*lh
));
16521 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
16524 line_ptr
= section
->buffer
+ offset
;
16526 /* Read in the header. */
16528 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
16529 &bytes_read
, &offset_size
);
16530 line_ptr
+= bytes_read
;
16531 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
16533 dwarf2_statement_list_fits_in_line_number_section_complaint ();
16534 do_cleanups (back_to
);
16537 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
16538 lh
->version
= read_2_bytes (abfd
, line_ptr
);
16540 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
16541 line_ptr
+= offset_size
;
16542 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
16544 if (lh
->version
>= 4)
16546 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
16550 lh
->maximum_ops_per_instruction
= 1;
16552 if (lh
->maximum_ops_per_instruction
== 0)
16554 lh
->maximum_ops_per_instruction
= 1;
16555 complaint (&symfile_complaints
,
16556 _("invalid maximum_ops_per_instruction "
16557 "in `.debug_line' section"));
16560 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
16562 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
16564 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
16566 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
16568 lh
->standard_opcode_lengths
16569 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
16571 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
16572 for (i
= 1; i
< lh
->opcode_base
; ++i
)
16574 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
16578 /* Read directory table. */
16579 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
16581 line_ptr
+= bytes_read
;
16582 add_include_dir (lh
, cur_dir
);
16584 line_ptr
+= bytes_read
;
16586 /* Read file name table. */
16587 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
16589 unsigned int dir_index
, mod_time
, length
;
16591 line_ptr
+= bytes_read
;
16592 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16593 line_ptr
+= bytes_read
;
16594 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16595 line_ptr
+= bytes_read
;
16596 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16597 line_ptr
+= bytes_read
;
16599 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
16601 line_ptr
+= bytes_read
;
16602 lh
->statement_program_start
= line_ptr
;
16604 if (line_ptr
> (section
->buffer
+ section
->size
))
16605 complaint (&symfile_complaints
,
16606 _("line number info header doesn't "
16607 "fit in `.debug_line' section"));
16609 discard_cleanups (back_to
);
16613 /* Subroutine of dwarf_decode_lines to simplify it.
16614 Return the file name of the psymtab for included file FILE_INDEX
16615 in line header LH of PST.
16616 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
16617 If space for the result is malloc'd, it will be freed by a cleanup.
16618 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
16620 The function creates dangling cleanup registration. */
16622 static const char *
16623 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
16624 const struct partial_symtab
*pst
,
16625 const char *comp_dir
)
16627 const struct file_entry fe
= lh
->file_names
[file_index
];
16628 const char *include_name
= fe
.name
;
16629 const char *include_name_to_compare
= include_name
;
16630 const char *dir_name
= NULL
;
16631 const char *pst_filename
;
16632 char *copied_name
= NULL
;
16636 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
16638 if (!IS_ABSOLUTE_PATH (include_name
)
16639 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
16641 /* Avoid creating a duplicate psymtab for PST.
16642 We do this by comparing INCLUDE_NAME and PST_FILENAME.
16643 Before we do the comparison, however, we need to account
16644 for DIR_NAME and COMP_DIR.
16645 First prepend dir_name (if non-NULL). If we still don't
16646 have an absolute path prepend comp_dir (if non-NULL).
16647 However, the directory we record in the include-file's
16648 psymtab does not contain COMP_DIR (to match the
16649 corresponding symtab(s)).
16654 bash$ gcc -g ./hello.c
16655 include_name = "hello.c"
16657 DW_AT_comp_dir = comp_dir = "/tmp"
16658 DW_AT_name = "./hello.c" */
16660 if (dir_name
!= NULL
)
16662 char *tem
= concat (dir_name
, SLASH_STRING
,
16663 include_name
, (char *)NULL
);
16665 make_cleanup (xfree
, tem
);
16666 include_name
= tem
;
16667 include_name_to_compare
= include_name
;
16669 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
16671 char *tem
= concat (comp_dir
, SLASH_STRING
,
16672 include_name
, (char *)NULL
);
16674 make_cleanup (xfree
, tem
);
16675 include_name_to_compare
= tem
;
16679 pst_filename
= pst
->filename
;
16680 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
16682 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
16683 pst_filename
, (char *)NULL
);
16684 pst_filename
= copied_name
;
16687 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
16689 if (copied_name
!= NULL
)
16690 xfree (copied_name
);
16694 return include_name
;
16697 /* Ignore this record_line request. */
16700 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
16705 /* Subroutine of dwarf_decode_lines to simplify it.
16706 Process the line number information in LH. */
16709 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
16710 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
16712 const gdb_byte
*line_ptr
, *extended_end
;
16713 const gdb_byte
*line_end
;
16714 unsigned int bytes_read
, extended_len
;
16715 unsigned char op_code
, extended_op
, adj_opcode
;
16716 CORE_ADDR baseaddr
;
16717 struct objfile
*objfile
= cu
->objfile
;
16718 bfd
*abfd
= objfile
->obfd
;
16719 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16720 const int decode_for_pst_p
= (pst
!= NULL
);
16721 struct subfile
*last_subfile
= NULL
;
16722 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
16725 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16727 line_ptr
= lh
->statement_program_start
;
16728 line_end
= lh
->statement_program_end
;
16730 /* Read the statement sequences until there's nothing left. */
16731 while (line_ptr
< line_end
)
16733 /* state machine registers */
16734 CORE_ADDR address
= 0;
16735 unsigned int file
= 1;
16736 unsigned int line
= 1;
16737 unsigned int column
= 0;
16738 int is_stmt
= lh
->default_is_stmt
;
16739 int basic_block
= 0;
16740 int end_sequence
= 0;
16742 unsigned char op_index
= 0;
16744 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
16746 /* Start a subfile for the current file of the state machine. */
16747 /* lh->include_dirs and lh->file_names are 0-based, but the
16748 directory and file name numbers in the statement program
16750 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
16751 const char *dir
= NULL
;
16754 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
16756 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
16759 /* Decode the table. */
16760 while (!end_sequence
)
16762 op_code
= read_1_byte (abfd
, line_ptr
);
16764 if (line_ptr
> line_end
)
16766 dwarf2_debug_line_missing_end_sequence_complaint ();
16770 if (op_code
>= lh
->opcode_base
)
16772 /* Special operand. */
16773 adj_opcode
= op_code
- lh
->opcode_base
;
16774 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
16775 / lh
->maximum_ops_per_instruction
)
16776 * lh
->minimum_instruction_length
);
16777 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
16778 % lh
->maximum_ops_per_instruction
);
16779 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
16780 if (lh
->num_file_names
< file
|| file
== 0)
16781 dwarf2_debug_line_missing_file_complaint ();
16782 /* For now we ignore lines not starting on an
16783 instruction boundary. */
16784 else if (op_index
== 0)
16786 lh
->file_names
[file
- 1].included_p
= 1;
16787 if (!decode_for_pst_p
&& is_stmt
)
16789 if (last_subfile
!= current_subfile
)
16791 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
16793 (*p_record_line
) (last_subfile
, 0, addr
);
16794 last_subfile
= current_subfile
;
16796 /* Append row to matrix using current values. */
16797 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
16798 (*p_record_line
) (current_subfile
, line
, addr
);
16803 else switch (op_code
)
16805 case DW_LNS_extended_op
:
16806 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
16808 line_ptr
+= bytes_read
;
16809 extended_end
= line_ptr
+ extended_len
;
16810 extended_op
= read_1_byte (abfd
, line_ptr
);
16812 switch (extended_op
)
16814 case DW_LNE_end_sequence
:
16815 p_record_line
= record_line
;
16818 case DW_LNE_set_address
:
16819 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
16821 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
16823 /* This line table is for a function which has been
16824 GCd by the linker. Ignore it. PR gdb/12528 */
16827 = line_ptr
- get_debug_line_section (cu
)->buffer
;
16829 complaint (&symfile_complaints
,
16830 _(".debug_line address at offset 0x%lx is 0 "
16832 line_offset
, objfile_name (objfile
));
16833 p_record_line
= noop_record_line
;
16837 line_ptr
+= bytes_read
;
16838 address
+= baseaddr
;
16840 case DW_LNE_define_file
:
16842 const char *cur_file
;
16843 unsigned int dir_index
, mod_time
, length
;
16845 cur_file
= read_direct_string (abfd
, line_ptr
,
16847 line_ptr
+= bytes_read
;
16849 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16850 line_ptr
+= bytes_read
;
16852 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16853 line_ptr
+= bytes_read
;
16855 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16856 line_ptr
+= bytes_read
;
16857 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
16860 case DW_LNE_set_discriminator
:
16861 /* The discriminator is not interesting to the debugger;
16863 line_ptr
= extended_end
;
16866 complaint (&symfile_complaints
,
16867 _("mangled .debug_line section"));
16870 /* Make sure that we parsed the extended op correctly. If e.g.
16871 we expected a different address size than the producer used,
16872 we may have read the wrong number of bytes. */
16873 if (line_ptr
!= extended_end
)
16875 complaint (&symfile_complaints
,
16876 _("mangled .debug_line section"));
16881 if (lh
->num_file_names
< file
|| file
== 0)
16882 dwarf2_debug_line_missing_file_complaint ();
16885 lh
->file_names
[file
- 1].included_p
= 1;
16886 if (!decode_for_pst_p
&& is_stmt
)
16888 if (last_subfile
!= current_subfile
)
16890 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
16892 (*p_record_line
) (last_subfile
, 0, addr
);
16893 last_subfile
= current_subfile
;
16895 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
16896 (*p_record_line
) (current_subfile
, line
, addr
);
16901 case DW_LNS_advance_pc
:
16904 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16906 address
+= (((op_index
+ adjust
)
16907 / lh
->maximum_ops_per_instruction
)
16908 * lh
->minimum_instruction_length
);
16909 op_index
= ((op_index
+ adjust
)
16910 % lh
->maximum_ops_per_instruction
);
16911 line_ptr
+= bytes_read
;
16914 case DW_LNS_advance_line
:
16915 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
16916 line_ptr
+= bytes_read
;
16918 case DW_LNS_set_file
:
16920 /* The arrays lh->include_dirs and lh->file_names are
16921 0-based, but the directory and file name numbers in
16922 the statement program are 1-based. */
16923 struct file_entry
*fe
;
16924 const char *dir
= NULL
;
16926 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16927 line_ptr
+= bytes_read
;
16928 if (lh
->num_file_names
< file
|| file
== 0)
16929 dwarf2_debug_line_missing_file_complaint ();
16932 fe
= &lh
->file_names
[file
- 1];
16934 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
16935 if (!decode_for_pst_p
)
16937 last_subfile
= current_subfile
;
16938 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
16943 case DW_LNS_set_column
:
16944 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16945 line_ptr
+= bytes_read
;
16947 case DW_LNS_negate_stmt
:
16948 is_stmt
= (!is_stmt
);
16950 case DW_LNS_set_basic_block
:
16953 /* Add to the address register of the state machine the
16954 address increment value corresponding to special opcode
16955 255. I.e., this value is scaled by the minimum
16956 instruction length since special opcode 255 would have
16957 scaled the increment. */
16958 case DW_LNS_const_add_pc
:
16960 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
16962 address
+= (((op_index
+ adjust
)
16963 / lh
->maximum_ops_per_instruction
)
16964 * lh
->minimum_instruction_length
);
16965 op_index
= ((op_index
+ adjust
)
16966 % lh
->maximum_ops_per_instruction
);
16969 case DW_LNS_fixed_advance_pc
:
16970 address
+= read_2_bytes (abfd
, line_ptr
);
16976 /* Unknown standard opcode, ignore it. */
16979 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
16981 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16982 line_ptr
+= bytes_read
;
16987 if (lh
->num_file_names
< file
|| file
== 0)
16988 dwarf2_debug_line_missing_file_complaint ();
16991 lh
->file_names
[file
- 1].included_p
= 1;
16992 if (!decode_for_pst_p
)
16994 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
16995 (*p_record_line
) (current_subfile
, 0, addr
);
17001 /* Decode the Line Number Program (LNP) for the given line_header
17002 structure and CU. The actual information extracted and the type
17003 of structures created from the LNP depends on the value of PST.
17005 1. If PST is NULL, then this procedure uses the data from the program
17006 to create all necessary symbol tables, and their linetables.
17008 2. If PST is not NULL, this procedure reads the program to determine
17009 the list of files included by the unit represented by PST, and
17010 builds all the associated partial symbol tables.
17012 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
17013 It is used for relative paths in the line table.
17014 NOTE: When processing partial symtabs (pst != NULL),
17015 comp_dir == pst->dirname.
17017 NOTE: It is important that psymtabs have the same file name (via strcmp)
17018 as the corresponding symtab. Since COMP_DIR is not used in the name of the
17019 symtab we don't use it in the name of the psymtabs we create.
17020 E.g. expand_line_sal requires this when finding psymtabs to expand.
17021 A good testcase for this is mb-inline.exp. */
17024 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
17025 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
17026 int want_line_info
)
17028 struct objfile
*objfile
= cu
->objfile
;
17029 const int decode_for_pst_p
= (pst
!= NULL
);
17030 struct subfile
*first_subfile
= current_subfile
;
17032 if (want_line_info
)
17033 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
17035 if (decode_for_pst_p
)
17039 /* Now that we're done scanning the Line Header Program, we can
17040 create the psymtab of each included file. */
17041 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
17042 if (lh
->file_names
[file_index
].included_p
== 1)
17044 const char *include_name
=
17045 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
17046 if (include_name
!= NULL
)
17047 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
17052 /* Make sure a symtab is created for every file, even files
17053 which contain only variables (i.e. no code with associated
17057 for (i
= 0; i
< lh
->num_file_names
; i
++)
17059 const char *dir
= NULL
;
17060 struct file_entry
*fe
;
17062 fe
= &lh
->file_names
[i
];
17064 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
17065 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
17067 /* Skip the main file; we don't need it, and it must be
17068 allocated last, so that it will show up before the
17069 non-primary symtabs in the objfile's symtab list. */
17070 if (current_subfile
== first_subfile
)
17073 if (current_subfile
->symtab
== NULL
)
17074 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
17076 fe
->symtab
= current_subfile
->symtab
;
17081 /* Start a subfile for DWARF. FILENAME is the name of the file and
17082 DIRNAME the name of the source directory which contains FILENAME
17083 or NULL if not known. COMP_DIR is the compilation directory for the
17084 linetable's compilation unit or NULL if not known.
17085 This routine tries to keep line numbers from identical absolute and
17086 relative file names in a common subfile.
17088 Using the `list' example from the GDB testsuite, which resides in
17089 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
17090 of /srcdir/list0.c yields the following debugging information for list0.c:
17092 DW_AT_name: /srcdir/list0.c
17093 DW_AT_comp_dir: /compdir
17094 files.files[0].name: list0.h
17095 files.files[0].dir: /srcdir
17096 files.files[1].name: list0.c
17097 files.files[1].dir: /srcdir
17099 The line number information for list0.c has to end up in a single
17100 subfile, so that `break /srcdir/list0.c:1' works as expected.
17101 start_subfile will ensure that this happens provided that we pass the
17102 concatenation of files.files[1].dir and files.files[1].name as the
17106 dwarf2_start_subfile (const char *filename
, const char *dirname
,
17107 const char *comp_dir
)
17111 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
17112 `start_symtab' will always pass the contents of DW_AT_comp_dir as
17113 second argument to start_subfile. To be consistent, we do the
17114 same here. In order not to lose the line information directory,
17115 we concatenate it to the filename when it makes sense.
17116 Note that the Dwarf3 standard says (speaking of filenames in line
17117 information): ``The directory index is ignored for file names
17118 that represent full path names''. Thus ignoring dirname in the
17119 `else' branch below isn't an issue. */
17121 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
17123 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
17127 start_subfile (filename
, comp_dir
);
17133 /* Start a symtab for DWARF.
17134 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
17137 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
17138 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
17140 start_symtab (name
, comp_dir
, low_pc
);
17141 record_debugformat ("DWARF 2");
17142 record_producer (cu
->producer
);
17144 /* We assume that we're processing GCC output. */
17145 processing_gcc_compilation
= 2;
17147 cu
->processing_has_namespace_info
= 0;
17151 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
17152 struct dwarf2_cu
*cu
)
17154 struct objfile
*objfile
= cu
->objfile
;
17155 struct comp_unit_head
*cu_header
= &cu
->header
;
17157 /* NOTE drow/2003-01-30: There used to be a comment and some special
17158 code here to turn a symbol with DW_AT_external and a
17159 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
17160 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
17161 with some versions of binutils) where shared libraries could have
17162 relocations against symbols in their debug information - the
17163 minimal symbol would have the right address, but the debug info
17164 would not. It's no longer necessary, because we will explicitly
17165 apply relocations when we read in the debug information now. */
17167 /* A DW_AT_location attribute with no contents indicates that a
17168 variable has been optimized away. */
17169 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
17171 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
17175 /* Handle one degenerate form of location expression specially, to
17176 preserve GDB's previous behavior when section offsets are
17177 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
17178 then mark this symbol as LOC_STATIC. */
17180 if (attr_form_is_block (attr
)
17181 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
17182 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
17183 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
17184 && (DW_BLOCK (attr
)->size
17185 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
17187 unsigned int dummy
;
17189 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
17190 SYMBOL_VALUE_ADDRESS (sym
) =
17191 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
17193 SYMBOL_VALUE_ADDRESS (sym
) =
17194 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
17195 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
17196 fixup_symbol_section (sym
, objfile
);
17197 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
17198 SYMBOL_SECTION (sym
));
17202 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
17203 expression evaluator, and use LOC_COMPUTED only when necessary
17204 (i.e. when the value of a register or memory location is
17205 referenced, or a thread-local block, etc.). Then again, it might
17206 not be worthwhile. I'm assuming that it isn't unless performance
17207 or memory numbers show me otherwise. */
17209 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
17211 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
17212 cu
->has_loclist
= 1;
17215 /* Given a pointer to a DWARF information entry, figure out if we need
17216 to make a symbol table entry for it, and if so, create a new entry
17217 and return a pointer to it.
17218 If TYPE is NULL, determine symbol type from the die, otherwise
17219 used the passed type.
17220 If SPACE is not NULL, use it to hold the new symbol. If it is
17221 NULL, allocate a new symbol on the objfile's obstack. */
17223 static struct symbol
*
17224 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
17225 struct symbol
*space
)
17227 struct objfile
*objfile
= cu
->objfile
;
17228 struct symbol
*sym
= NULL
;
17230 struct attribute
*attr
= NULL
;
17231 struct attribute
*attr2
= NULL
;
17232 CORE_ADDR baseaddr
;
17233 struct pending
**list_to_add
= NULL
;
17235 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
17237 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17239 name
= dwarf2_name (die
, cu
);
17242 const char *linkagename
;
17243 int suppress_add
= 0;
17248 sym
= allocate_symbol (objfile
);
17249 OBJSTAT (objfile
, n_syms
++);
17251 /* Cache this symbol's name and the name's demangled form (if any). */
17252 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
17253 linkagename
= dwarf2_physname (name
, die
, cu
);
17254 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
17256 /* Fortran does not have mangling standard and the mangling does differ
17257 between gfortran, iFort etc. */
17258 if (cu
->language
== language_fortran
17259 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
17260 symbol_set_demangled_name (&(sym
->ginfo
),
17261 dwarf2_full_name (name
, die
, cu
),
17264 /* Default assumptions.
17265 Use the passed type or decode it from the die. */
17266 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
17267 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
17269 SYMBOL_TYPE (sym
) = type
;
17271 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
17272 attr
= dwarf2_attr (die
,
17273 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
17277 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
17280 attr
= dwarf2_attr (die
,
17281 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
17285 int file_index
= DW_UNSND (attr
);
17287 if (cu
->line_header
== NULL
17288 || file_index
> cu
->line_header
->num_file_names
)
17289 complaint (&symfile_complaints
,
17290 _("file index out of range"));
17291 else if (file_index
> 0)
17293 struct file_entry
*fe
;
17295 fe
= &cu
->line_header
->file_names
[file_index
- 1];
17296 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
17303 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
17306 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
17308 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
17309 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
17310 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
17311 add_symbol_to_list (sym
, cu
->list_in_scope
);
17313 case DW_TAG_subprogram
:
17314 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
17316 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
17317 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
17318 if ((attr2
&& (DW_UNSND (attr2
) != 0))
17319 || cu
->language
== language_ada
)
17321 /* Subprograms marked external are stored as a global symbol.
17322 Ada subprograms, whether marked external or not, are always
17323 stored as a global symbol, because we want to be able to
17324 access them globally. For instance, we want to be able
17325 to break on a nested subprogram without having to
17326 specify the context. */
17327 list_to_add
= &global_symbols
;
17331 list_to_add
= cu
->list_in_scope
;
17334 case DW_TAG_inlined_subroutine
:
17335 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
17337 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
17338 SYMBOL_INLINED (sym
) = 1;
17339 list_to_add
= cu
->list_in_scope
;
17341 case DW_TAG_template_value_param
:
17343 /* Fall through. */
17344 case DW_TAG_constant
:
17345 case DW_TAG_variable
:
17346 case DW_TAG_member
:
17347 /* Compilation with minimal debug info may result in
17348 variables with missing type entries. Change the
17349 misleading `void' type to something sensible. */
17350 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
17352 = objfile_type (objfile
)->nodebug_data_symbol
;
17354 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
17355 /* In the case of DW_TAG_member, we should only be called for
17356 static const members. */
17357 if (die
->tag
== DW_TAG_member
)
17359 /* dwarf2_add_field uses die_is_declaration,
17360 so we do the same. */
17361 gdb_assert (die_is_declaration (die
, cu
));
17366 dwarf2_const_value (attr
, sym
, cu
);
17367 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
17370 if (attr2
&& (DW_UNSND (attr2
) != 0))
17371 list_to_add
= &global_symbols
;
17373 list_to_add
= cu
->list_in_scope
;
17377 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17380 var_decode_location (attr
, sym
, cu
);
17381 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
17383 /* Fortran explicitly imports any global symbols to the local
17384 scope by DW_TAG_common_block. */
17385 if (cu
->language
== language_fortran
&& die
->parent
17386 && die
->parent
->tag
== DW_TAG_common_block
)
17389 if (SYMBOL_CLASS (sym
) == LOC_STATIC
17390 && SYMBOL_VALUE_ADDRESS (sym
) == 0
17391 && !dwarf2_per_objfile
->has_section_at_zero
)
17393 /* When a static variable is eliminated by the linker,
17394 the corresponding debug information is not stripped
17395 out, but the variable address is set to null;
17396 do not add such variables into symbol table. */
17398 else if (attr2
&& (DW_UNSND (attr2
) != 0))
17400 /* Workaround gfortran PR debug/40040 - it uses
17401 DW_AT_location for variables in -fPIC libraries which may
17402 get overriden by other libraries/executable and get
17403 a different address. Resolve it by the minimal symbol
17404 which may come from inferior's executable using copy
17405 relocation. Make this workaround only for gfortran as for
17406 other compilers GDB cannot guess the minimal symbol
17407 Fortran mangling kind. */
17408 if (cu
->language
== language_fortran
&& die
->parent
17409 && die
->parent
->tag
== DW_TAG_module
17411 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
17412 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
17414 /* A variable with DW_AT_external is never static,
17415 but it may be block-scoped. */
17416 list_to_add
= (cu
->list_in_scope
== &file_symbols
17417 ? &global_symbols
: cu
->list_in_scope
);
17420 list_to_add
= cu
->list_in_scope
;
17424 /* We do not know the address of this symbol.
17425 If it is an external symbol and we have type information
17426 for it, enter the symbol as a LOC_UNRESOLVED symbol.
17427 The address of the variable will then be determined from
17428 the minimal symbol table whenever the variable is
17430 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
17432 /* Fortran explicitly imports any global symbols to the local
17433 scope by DW_TAG_common_block. */
17434 if (cu
->language
== language_fortran
&& die
->parent
17435 && die
->parent
->tag
== DW_TAG_common_block
)
17437 /* SYMBOL_CLASS doesn't matter here because
17438 read_common_block is going to reset it. */
17440 list_to_add
= cu
->list_in_scope
;
17442 else if (attr2
&& (DW_UNSND (attr2
) != 0)
17443 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
17445 /* A variable with DW_AT_external is never static, but it
17446 may be block-scoped. */
17447 list_to_add
= (cu
->list_in_scope
== &file_symbols
17448 ? &global_symbols
: cu
->list_in_scope
);
17450 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
17452 else if (!die_is_declaration (die
, cu
))
17454 /* Use the default LOC_OPTIMIZED_OUT class. */
17455 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
17457 list_to_add
= cu
->list_in_scope
;
17461 case DW_TAG_formal_parameter
:
17462 /* If we are inside a function, mark this as an argument. If
17463 not, we might be looking at an argument to an inlined function
17464 when we do not have enough information to show inlined frames;
17465 pretend it's a local variable in that case so that the user can
17467 if (context_stack_depth
> 0
17468 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
17469 SYMBOL_IS_ARGUMENT (sym
) = 1;
17470 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17473 var_decode_location (attr
, sym
, cu
);
17475 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
17478 dwarf2_const_value (attr
, sym
, cu
);
17481 list_to_add
= cu
->list_in_scope
;
17483 case DW_TAG_unspecified_parameters
:
17484 /* From varargs functions; gdb doesn't seem to have any
17485 interest in this information, so just ignore it for now.
17488 case DW_TAG_template_type_param
:
17490 /* Fall through. */
17491 case DW_TAG_class_type
:
17492 case DW_TAG_interface_type
:
17493 case DW_TAG_structure_type
:
17494 case DW_TAG_union_type
:
17495 case DW_TAG_set_type
:
17496 case DW_TAG_enumeration_type
:
17497 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
17498 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
17501 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
17502 really ever be static objects: otherwise, if you try
17503 to, say, break of a class's method and you're in a file
17504 which doesn't mention that class, it won't work unless
17505 the check for all static symbols in lookup_symbol_aux
17506 saves you. See the OtherFileClass tests in
17507 gdb.c++/namespace.exp. */
17511 list_to_add
= (cu
->list_in_scope
== &file_symbols
17512 && (cu
->language
== language_cplus
17513 || cu
->language
== language_java
)
17514 ? &global_symbols
: cu
->list_in_scope
);
17516 /* The semantics of C++ state that "struct foo {
17517 ... }" also defines a typedef for "foo". A Java
17518 class declaration also defines a typedef for the
17520 if (cu
->language
== language_cplus
17521 || cu
->language
== language_java
17522 || cu
->language
== language_ada
)
17524 /* The symbol's name is already allocated along
17525 with this objfile, so we don't need to
17526 duplicate it for the type. */
17527 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
17528 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
17533 case DW_TAG_typedef
:
17534 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
17535 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
17536 list_to_add
= cu
->list_in_scope
;
17538 case DW_TAG_base_type
:
17539 case DW_TAG_subrange_type
:
17540 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
17541 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
17542 list_to_add
= cu
->list_in_scope
;
17544 case DW_TAG_enumerator
:
17545 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
17548 dwarf2_const_value (attr
, sym
, cu
);
17551 /* NOTE: carlton/2003-11-10: See comment above in the
17552 DW_TAG_class_type, etc. block. */
17554 list_to_add
= (cu
->list_in_scope
== &file_symbols
17555 && (cu
->language
== language_cplus
17556 || cu
->language
== language_java
)
17557 ? &global_symbols
: cu
->list_in_scope
);
17560 case DW_TAG_namespace
:
17561 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
17562 list_to_add
= &global_symbols
;
17564 case DW_TAG_common_block
:
17565 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
17566 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
17567 add_symbol_to_list (sym
, cu
->list_in_scope
);
17570 /* Not a tag we recognize. Hopefully we aren't processing
17571 trash data, but since we must specifically ignore things
17572 we don't recognize, there is nothing else we should do at
17574 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
17575 dwarf_tag_name (die
->tag
));
17581 sym
->hash_next
= objfile
->template_symbols
;
17582 objfile
->template_symbols
= sym
;
17583 list_to_add
= NULL
;
17586 if (list_to_add
!= NULL
)
17587 add_symbol_to_list (sym
, list_to_add
);
17589 /* For the benefit of old versions of GCC, check for anonymous
17590 namespaces based on the demangled name. */
17591 if (!cu
->processing_has_namespace_info
17592 && cu
->language
== language_cplus
)
17593 cp_scan_for_anonymous_namespaces (sym
, objfile
);
17598 /* A wrapper for new_symbol_full that always allocates a new symbol. */
17600 static struct symbol
*
17601 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
17603 return new_symbol_full (die
, type
, cu
, NULL
);
17606 /* Given an attr with a DW_FORM_dataN value in host byte order,
17607 zero-extend it as appropriate for the symbol's type. The DWARF
17608 standard (v4) is not entirely clear about the meaning of using
17609 DW_FORM_dataN for a constant with a signed type, where the type is
17610 wider than the data. The conclusion of a discussion on the DWARF
17611 list was that this is unspecified. We choose to always zero-extend
17612 because that is the interpretation long in use by GCC. */
17615 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
17616 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
17618 struct objfile
*objfile
= cu
->objfile
;
17619 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
17620 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
17621 LONGEST l
= DW_UNSND (attr
);
17623 if (bits
< sizeof (*value
) * 8)
17625 l
&= ((LONGEST
) 1 << bits
) - 1;
17628 else if (bits
== sizeof (*value
) * 8)
17632 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
17633 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
17640 /* Read a constant value from an attribute. Either set *VALUE, or if
17641 the value does not fit in *VALUE, set *BYTES - either already
17642 allocated on the objfile obstack, or newly allocated on OBSTACK,
17643 or, set *BATON, if we translated the constant to a location
17647 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
17648 const char *name
, struct obstack
*obstack
,
17649 struct dwarf2_cu
*cu
,
17650 LONGEST
*value
, const gdb_byte
**bytes
,
17651 struct dwarf2_locexpr_baton
**baton
)
17653 struct objfile
*objfile
= cu
->objfile
;
17654 struct comp_unit_head
*cu_header
= &cu
->header
;
17655 struct dwarf_block
*blk
;
17656 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
17657 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
17663 switch (attr
->form
)
17666 case DW_FORM_GNU_addr_index
:
17670 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
17671 dwarf2_const_value_length_mismatch_complaint (name
,
17672 cu_header
->addr_size
,
17673 TYPE_LENGTH (type
));
17674 /* Symbols of this form are reasonably rare, so we just
17675 piggyback on the existing location code rather than writing
17676 a new implementation of symbol_computed_ops. */
17677 *baton
= obstack_alloc (obstack
, sizeof (struct dwarf2_locexpr_baton
));
17678 (*baton
)->per_cu
= cu
->per_cu
;
17679 gdb_assert ((*baton
)->per_cu
);
17681 (*baton
)->size
= 2 + cu_header
->addr_size
;
17682 data
= obstack_alloc (obstack
, (*baton
)->size
);
17683 (*baton
)->data
= data
;
17685 data
[0] = DW_OP_addr
;
17686 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
17687 byte_order
, DW_ADDR (attr
));
17688 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
17691 case DW_FORM_string
:
17693 case DW_FORM_GNU_str_index
:
17694 case DW_FORM_GNU_strp_alt
:
17695 /* DW_STRING is already allocated on the objfile obstack, point
17697 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
17699 case DW_FORM_block1
:
17700 case DW_FORM_block2
:
17701 case DW_FORM_block4
:
17702 case DW_FORM_block
:
17703 case DW_FORM_exprloc
:
17704 blk
= DW_BLOCK (attr
);
17705 if (TYPE_LENGTH (type
) != blk
->size
)
17706 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
17707 TYPE_LENGTH (type
));
17708 *bytes
= blk
->data
;
17711 /* The DW_AT_const_value attributes are supposed to carry the
17712 symbol's value "represented as it would be on the target
17713 architecture." By the time we get here, it's already been
17714 converted to host endianness, so we just need to sign- or
17715 zero-extend it as appropriate. */
17716 case DW_FORM_data1
:
17717 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
17719 case DW_FORM_data2
:
17720 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
17722 case DW_FORM_data4
:
17723 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
17725 case DW_FORM_data8
:
17726 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
17729 case DW_FORM_sdata
:
17730 *value
= DW_SND (attr
);
17733 case DW_FORM_udata
:
17734 *value
= DW_UNSND (attr
);
17738 complaint (&symfile_complaints
,
17739 _("unsupported const value attribute form: '%s'"),
17740 dwarf_form_name (attr
->form
));
17747 /* Copy constant value from an attribute to a symbol. */
17750 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
17751 struct dwarf2_cu
*cu
)
17753 struct objfile
*objfile
= cu
->objfile
;
17754 struct comp_unit_head
*cu_header
= &cu
->header
;
17756 const gdb_byte
*bytes
;
17757 struct dwarf2_locexpr_baton
*baton
;
17759 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
17760 SYMBOL_PRINT_NAME (sym
),
17761 &objfile
->objfile_obstack
, cu
,
17762 &value
, &bytes
, &baton
);
17766 SYMBOL_LOCATION_BATON (sym
) = baton
;
17767 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
17769 else if (bytes
!= NULL
)
17771 SYMBOL_VALUE_BYTES (sym
) = bytes
;
17772 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
17776 SYMBOL_VALUE (sym
) = value
;
17777 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
17781 /* Return the type of the die in question using its DW_AT_type attribute. */
17783 static struct type
*
17784 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17786 struct attribute
*type_attr
;
17788 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
17791 /* A missing DW_AT_type represents a void type. */
17792 return objfile_type (cu
->objfile
)->builtin_void
;
17795 return lookup_die_type (die
, type_attr
, cu
);
17798 /* True iff CU's producer generates GNAT Ada auxiliary information
17799 that allows to find parallel types through that information instead
17800 of having to do expensive parallel lookups by type name. */
17803 need_gnat_info (struct dwarf2_cu
*cu
)
17805 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
17806 of GNAT produces this auxiliary information, without any indication
17807 that it is produced. Part of enhancing the FSF version of GNAT
17808 to produce that information will be to put in place an indicator
17809 that we can use in order to determine whether the descriptive type
17810 info is available or not. One suggestion that has been made is
17811 to use a new attribute, attached to the CU die. For now, assume
17812 that the descriptive type info is not available. */
17816 /* Return the auxiliary type of the die in question using its
17817 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
17818 attribute is not present. */
17820 static struct type
*
17821 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17823 struct attribute
*type_attr
;
17825 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
17829 return lookup_die_type (die
, type_attr
, cu
);
17832 /* If DIE has a descriptive_type attribute, then set the TYPE's
17833 descriptive type accordingly. */
17836 set_descriptive_type (struct type
*type
, struct die_info
*die
,
17837 struct dwarf2_cu
*cu
)
17839 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
17841 if (descriptive_type
)
17843 ALLOCATE_GNAT_AUX_TYPE (type
);
17844 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
17848 /* Return the containing type of the die in question using its
17849 DW_AT_containing_type attribute. */
17851 static struct type
*
17852 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17854 struct attribute
*type_attr
;
17856 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
17858 error (_("Dwarf Error: Problem turning containing type into gdb type "
17859 "[in module %s]"), objfile_name (cu
->objfile
));
17861 return lookup_die_type (die
, type_attr
, cu
);
17864 /* Return an error marker type to use for the ill formed type in DIE/CU. */
17866 static struct type
*
17867 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
17869 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17870 char *message
, *saved
;
17872 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
17873 objfile_name (objfile
),
17874 cu
->header
.offset
.sect_off
,
17875 die
->offset
.sect_off
);
17876 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
17877 message
, strlen (message
));
17880 return init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
17883 /* Look up the type of DIE in CU using its type attribute ATTR.
17884 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
17885 DW_AT_containing_type.
17886 If there is no type substitute an error marker. */
17888 static struct type
*
17889 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
17890 struct dwarf2_cu
*cu
)
17892 struct objfile
*objfile
= cu
->objfile
;
17893 struct type
*this_type
;
17895 gdb_assert (attr
->name
== DW_AT_type
17896 || attr
->name
== DW_AT_GNAT_descriptive_type
17897 || attr
->name
== DW_AT_containing_type
);
17899 /* First see if we have it cached. */
17901 if (attr
->form
== DW_FORM_GNU_ref_alt
)
17903 struct dwarf2_per_cu_data
*per_cu
;
17904 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
17906 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
17907 this_type
= get_die_type_at_offset (offset
, per_cu
);
17909 else if (attr_form_is_ref (attr
))
17911 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
17913 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
17915 else if (attr
->form
== DW_FORM_ref_sig8
)
17917 ULONGEST signature
= DW_SIGNATURE (attr
);
17919 return get_signatured_type (die
, signature
, cu
);
17923 complaint (&symfile_complaints
,
17924 _("Dwarf Error: Bad type attribute %s in DIE"
17925 " at 0x%x [in module %s]"),
17926 dwarf_attr_name (attr
->name
), die
->offset
.sect_off
,
17927 objfile_name (objfile
));
17928 return build_error_marker_type (cu
, die
);
17931 /* If not cached we need to read it in. */
17933 if (this_type
== NULL
)
17935 struct die_info
*type_die
= NULL
;
17936 struct dwarf2_cu
*type_cu
= cu
;
17938 if (attr_form_is_ref (attr
))
17939 type_die
= follow_die_ref (die
, attr
, &type_cu
);
17940 if (type_die
== NULL
)
17941 return build_error_marker_type (cu
, die
);
17942 /* If we find the type now, it's probably because the type came
17943 from an inter-CU reference and the type's CU got expanded before
17945 this_type
= read_type_die (type_die
, type_cu
);
17948 /* If we still don't have a type use an error marker. */
17950 if (this_type
== NULL
)
17951 return build_error_marker_type (cu
, die
);
17956 /* Return the type in DIE, CU.
17957 Returns NULL for invalid types.
17959 This first does a lookup in die_type_hash,
17960 and only reads the die in if necessary.
17962 NOTE: This can be called when reading in partial or full symbols. */
17964 static struct type
*
17965 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
17967 struct type
*this_type
;
17969 this_type
= get_die_type (die
, cu
);
17973 return read_type_die_1 (die
, cu
);
17976 /* Read the type in DIE, CU.
17977 Returns NULL for invalid types. */
17979 static struct type
*
17980 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
17982 struct type
*this_type
= NULL
;
17986 case DW_TAG_class_type
:
17987 case DW_TAG_interface_type
:
17988 case DW_TAG_structure_type
:
17989 case DW_TAG_union_type
:
17990 this_type
= read_structure_type (die
, cu
);
17992 case DW_TAG_enumeration_type
:
17993 this_type
= read_enumeration_type (die
, cu
);
17995 case DW_TAG_subprogram
:
17996 case DW_TAG_subroutine_type
:
17997 case DW_TAG_inlined_subroutine
:
17998 this_type
= read_subroutine_type (die
, cu
);
18000 case DW_TAG_array_type
:
18001 this_type
= read_array_type (die
, cu
);
18003 case DW_TAG_set_type
:
18004 this_type
= read_set_type (die
, cu
);
18006 case DW_TAG_pointer_type
:
18007 this_type
= read_tag_pointer_type (die
, cu
);
18009 case DW_TAG_ptr_to_member_type
:
18010 this_type
= read_tag_ptr_to_member_type (die
, cu
);
18012 case DW_TAG_reference_type
:
18013 this_type
= read_tag_reference_type (die
, cu
);
18015 case DW_TAG_const_type
:
18016 this_type
= read_tag_const_type (die
, cu
);
18018 case DW_TAG_volatile_type
:
18019 this_type
= read_tag_volatile_type (die
, cu
);
18021 case DW_TAG_restrict_type
:
18022 this_type
= read_tag_restrict_type (die
, cu
);
18024 case DW_TAG_string_type
:
18025 this_type
= read_tag_string_type (die
, cu
);
18027 case DW_TAG_typedef
:
18028 this_type
= read_typedef (die
, cu
);
18030 case DW_TAG_subrange_type
:
18031 this_type
= read_subrange_type (die
, cu
);
18033 case DW_TAG_base_type
:
18034 this_type
= read_base_type (die
, cu
);
18036 case DW_TAG_unspecified_type
:
18037 this_type
= read_unspecified_type (die
, cu
);
18039 case DW_TAG_namespace
:
18040 this_type
= read_namespace_type (die
, cu
);
18042 case DW_TAG_module
:
18043 this_type
= read_module_type (die
, cu
);
18046 complaint (&symfile_complaints
,
18047 _("unexpected tag in read_type_die: '%s'"),
18048 dwarf_tag_name (die
->tag
));
18055 /* See if we can figure out if the class lives in a namespace. We do
18056 this by looking for a member function; its demangled name will
18057 contain namespace info, if there is any.
18058 Return the computed name or NULL.
18059 Space for the result is allocated on the objfile's obstack.
18060 This is the full-die version of guess_partial_die_structure_name.
18061 In this case we know DIE has no useful parent. */
18064 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18066 struct die_info
*spec_die
;
18067 struct dwarf2_cu
*spec_cu
;
18068 struct die_info
*child
;
18071 spec_die
= die_specification (die
, &spec_cu
);
18072 if (spec_die
!= NULL
)
18078 for (child
= die
->child
;
18080 child
= child
->sibling
)
18082 if (child
->tag
== DW_TAG_subprogram
)
18084 struct attribute
*attr
;
18086 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
18088 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
18092 = language_class_name_from_physname (cu
->language_defn
,
18096 if (actual_name
!= NULL
)
18098 const char *die_name
= dwarf2_name (die
, cu
);
18100 if (die_name
!= NULL
18101 && strcmp (die_name
, actual_name
) != 0)
18103 /* Strip off the class name from the full name.
18104 We want the prefix. */
18105 int die_name_len
= strlen (die_name
);
18106 int actual_name_len
= strlen (actual_name
);
18108 /* Test for '::' as a sanity check. */
18109 if (actual_name_len
> die_name_len
+ 2
18110 && actual_name
[actual_name_len
18111 - die_name_len
- 1] == ':')
18113 obstack_copy0 (&cu
->objfile
->objfile_obstack
,
18115 actual_name_len
- die_name_len
- 2);
18118 xfree (actual_name
);
18127 /* GCC might emit a nameless typedef that has a linkage name. Determine the
18128 prefix part in such case. See
18129 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18132 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
18134 struct attribute
*attr
;
18137 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
18138 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
18141 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
18142 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
18145 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
18147 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
18148 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
18151 /* dwarf2_name had to be already called. */
18152 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
18154 /* Strip the base name, keep any leading namespaces/classes. */
18155 base
= strrchr (DW_STRING (attr
), ':');
18156 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
18159 return obstack_copy0 (&cu
->objfile
->objfile_obstack
,
18160 DW_STRING (attr
), &base
[-1] - DW_STRING (attr
));
18163 /* Return the name of the namespace/class that DIE is defined within,
18164 or "" if we can't tell. The caller should not xfree the result.
18166 For example, if we're within the method foo() in the following
18176 then determine_prefix on foo's die will return "N::C". */
18178 static const char *
18179 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
18181 struct die_info
*parent
, *spec_die
;
18182 struct dwarf2_cu
*spec_cu
;
18183 struct type
*parent_type
;
18186 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
18187 && cu
->language
!= language_fortran
)
18190 retval
= anonymous_struct_prefix (die
, cu
);
18194 /* We have to be careful in the presence of DW_AT_specification.
18195 For example, with GCC 3.4, given the code
18199 // Definition of N::foo.
18203 then we'll have a tree of DIEs like this:
18205 1: DW_TAG_compile_unit
18206 2: DW_TAG_namespace // N
18207 3: DW_TAG_subprogram // declaration of N::foo
18208 4: DW_TAG_subprogram // definition of N::foo
18209 DW_AT_specification // refers to die #3
18211 Thus, when processing die #4, we have to pretend that we're in
18212 the context of its DW_AT_specification, namely the contex of die
18215 spec_die
= die_specification (die
, &spec_cu
);
18216 if (spec_die
== NULL
)
18217 parent
= die
->parent
;
18220 parent
= spec_die
->parent
;
18224 if (parent
== NULL
)
18226 else if (parent
->building_fullname
)
18229 const char *parent_name
;
18231 /* It has been seen on RealView 2.2 built binaries,
18232 DW_TAG_template_type_param types actually _defined_ as
18233 children of the parent class:
18236 template class <class Enum> Class{};
18237 Class<enum E> class_e;
18239 1: DW_TAG_class_type (Class)
18240 2: DW_TAG_enumeration_type (E)
18241 3: DW_TAG_enumerator (enum1:0)
18242 3: DW_TAG_enumerator (enum2:1)
18244 2: DW_TAG_template_type_param
18245 DW_AT_type DW_FORM_ref_udata (E)
18247 Besides being broken debug info, it can put GDB into an
18248 infinite loop. Consider:
18250 When we're building the full name for Class<E>, we'll start
18251 at Class, and go look over its template type parameters,
18252 finding E. We'll then try to build the full name of E, and
18253 reach here. We're now trying to build the full name of E,
18254 and look over the parent DIE for containing scope. In the
18255 broken case, if we followed the parent DIE of E, we'd again
18256 find Class, and once again go look at its template type
18257 arguments, etc., etc. Simply don't consider such parent die
18258 as source-level parent of this die (it can't be, the language
18259 doesn't allow it), and break the loop here. */
18260 name
= dwarf2_name (die
, cu
);
18261 parent_name
= dwarf2_name (parent
, cu
);
18262 complaint (&symfile_complaints
,
18263 _("template param type '%s' defined within parent '%s'"),
18264 name
? name
: "<unknown>",
18265 parent_name
? parent_name
: "<unknown>");
18269 switch (parent
->tag
)
18271 case DW_TAG_namespace
:
18272 parent_type
= read_type_die (parent
, cu
);
18273 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
18274 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
18275 Work around this problem here. */
18276 if (cu
->language
== language_cplus
18277 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
18279 /* We give a name to even anonymous namespaces. */
18280 return TYPE_TAG_NAME (parent_type
);
18281 case DW_TAG_class_type
:
18282 case DW_TAG_interface_type
:
18283 case DW_TAG_structure_type
:
18284 case DW_TAG_union_type
:
18285 case DW_TAG_module
:
18286 parent_type
= read_type_die (parent
, cu
);
18287 if (TYPE_TAG_NAME (parent_type
) != NULL
)
18288 return TYPE_TAG_NAME (parent_type
);
18290 /* An anonymous structure is only allowed non-static data
18291 members; no typedefs, no member functions, et cetera.
18292 So it does not need a prefix. */
18294 case DW_TAG_compile_unit
:
18295 case DW_TAG_partial_unit
:
18296 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
18297 if (cu
->language
== language_cplus
18298 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
18299 && die
->child
!= NULL
18300 && (die
->tag
== DW_TAG_class_type
18301 || die
->tag
== DW_TAG_structure_type
18302 || die
->tag
== DW_TAG_union_type
))
18304 char *name
= guess_full_die_structure_name (die
, cu
);
18310 return determine_prefix (parent
, cu
);
18314 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
18315 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
18316 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
18317 an obconcat, otherwise allocate storage for the result. The CU argument is
18318 used to determine the language and hence, the appropriate separator. */
18320 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
18323 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
18324 int physname
, struct dwarf2_cu
*cu
)
18326 const char *lead
= "";
18329 if (suffix
== NULL
|| suffix
[0] == '\0'
18330 || prefix
== NULL
|| prefix
[0] == '\0')
18332 else if (cu
->language
== language_java
)
18334 else if (cu
->language
== language_fortran
&& physname
)
18336 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
18337 DW_AT_MIPS_linkage_name is preferred and used instead. */
18345 if (prefix
== NULL
)
18347 if (suffix
== NULL
)
18353 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
18355 strcpy (retval
, lead
);
18356 strcat (retval
, prefix
);
18357 strcat (retval
, sep
);
18358 strcat (retval
, suffix
);
18363 /* We have an obstack. */
18364 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
18368 /* Return sibling of die, NULL if no sibling. */
18370 static struct die_info
*
18371 sibling_die (struct die_info
*die
)
18373 return die
->sibling
;
18376 /* Get name of a die, return NULL if not found. */
18378 static const char *
18379 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
18380 struct obstack
*obstack
)
18382 if (name
&& cu
->language
== language_cplus
)
18384 char *canon_name
= cp_canonicalize_string (name
);
18386 if (canon_name
!= NULL
)
18388 if (strcmp (canon_name
, name
) != 0)
18389 name
= obstack_copy0 (obstack
, canon_name
, strlen (canon_name
));
18390 xfree (canon_name
);
18397 /* Get name of a die, return NULL if not found. */
18399 static const char *
18400 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18402 struct attribute
*attr
;
18404 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
18405 if ((!attr
|| !DW_STRING (attr
))
18406 && die
->tag
!= DW_TAG_class_type
18407 && die
->tag
!= DW_TAG_interface_type
18408 && die
->tag
!= DW_TAG_structure_type
18409 && die
->tag
!= DW_TAG_union_type
)
18414 case DW_TAG_compile_unit
:
18415 case DW_TAG_partial_unit
:
18416 /* Compilation units have a DW_AT_name that is a filename, not
18417 a source language identifier. */
18418 case DW_TAG_enumeration_type
:
18419 case DW_TAG_enumerator
:
18420 /* These tags always have simple identifiers already; no need
18421 to canonicalize them. */
18422 return DW_STRING (attr
);
18424 case DW_TAG_subprogram
:
18425 /* Java constructors will all be named "<init>", so return
18426 the class name when we see this special case. */
18427 if (cu
->language
== language_java
18428 && DW_STRING (attr
) != NULL
18429 && strcmp (DW_STRING (attr
), "<init>") == 0)
18431 struct dwarf2_cu
*spec_cu
= cu
;
18432 struct die_info
*spec_die
;
18434 /* GCJ will output '<init>' for Java constructor names.
18435 For this special case, return the name of the parent class. */
18437 /* GCJ may output suprogram DIEs with AT_specification set.
18438 If so, use the name of the specified DIE. */
18439 spec_die
= die_specification (die
, &spec_cu
);
18440 if (spec_die
!= NULL
)
18441 return dwarf2_name (spec_die
, spec_cu
);
18446 if (die
->tag
== DW_TAG_class_type
)
18447 return dwarf2_name (die
, cu
);
18449 while (die
->tag
!= DW_TAG_compile_unit
18450 && die
->tag
!= DW_TAG_partial_unit
);
18454 case DW_TAG_class_type
:
18455 case DW_TAG_interface_type
:
18456 case DW_TAG_structure_type
:
18457 case DW_TAG_union_type
:
18458 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
18459 structures or unions. These were of the form "._%d" in GCC 4.1,
18460 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
18461 and GCC 4.4. We work around this problem by ignoring these. */
18462 if (attr
&& DW_STRING (attr
)
18463 && (strncmp (DW_STRING (attr
), "._", 2) == 0
18464 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
18467 /* GCC might emit a nameless typedef that has a linkage name. See
18468 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18469 if (!attr
|| DW_STRING (attr
) == NULL
)
18471 char *demangled
= NULL
;
18473 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
18475 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
18477 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
18480 /* Avoid demangling DW_STRING (attr) the second time on a second
18481 call for the same DIE. */
18482 if (!DW_STRING_IS_CANONICAL (attr
))
18483 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
18489 /* FIXME: we already did this for the partial symbol... */
18490 DW_STRING (attr
) = obstack_copy0 (&cu
->objfile
->objfile_obstack
,
18491 demangled
, strlen (demangled
));
18492 DW_STRING_IS_CANONICAL (attr
) = 1;
18495 /* Strip any leading namespaces/classes, keep only the base name.
18496 DW_AT_name for named DIEs does not contain the prefixes. */
18497 base
= strrchr (DW_STRING (attr
), ':');
18498 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
18501 return DW_STRING (attr
);
18510 if (!DW_STRING_IS_CANONICAL (attr
))
18513 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
18514 &cu
->objfile
->objfile_obstack
);
18515 DW_STRING_IS_CANONICAL (attr
) = 1;
18517 return DW_STRING (attr
);
18520 /* Return the die that this die in an extension of, or NULL if there
18521 is none. *EXT_CU is the CU containing DIE on input, and the CU
18522 containing the return value on output. */
18524 static struct die_info
*
18525 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
18527 struct attribute
*attr
;
18529 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
18533 return follow_die_ref (die
, attr
, ext_cu
);
18536 /* Convert a DIE tag into its string name. */
18538 static const char *
18539 dwarf_tag_name (unsigned tag
)
18541 const char *name
= get_DW_TAG_name (tag
);
18544 return "DW_TAG_<unknown>";
18549 /* Convert a DWARF attribute code into its string name. */
18551 static const char *
18552 dwarf_attr_name (unsigned attr
)
18556 #ifdef MIPS /* collides with DW_AT_HP_block_index */
18557 if (attr
== DW_AT_MIPS_fde
)
18558 return "DW_AT_MIPS_fde";
18560 if (attr
== DW_AT_HP_block_index
)
18561 return "DW_AT_HP_block_index";
18564 name
= get_DW_AT_name (attr
);
18567 return "DW_AT_<unknown>";
18572 /* Convert a DWARF value form code into its string name. */
18574 static const char *
18575 dwarf_form_name (unsigned form
)
18577 const char *name
= get_DW_FORM_name (form
);
18580 return "DW_FORM_<unknown>";
18586 dwarf_bool_name (unsigned mybool
)
18594 /* Convert a DWARF type code into its string name. */
18596 static const char *
18597 dwarf_type_encoding_name (unsigned enc
)
18599 const char *name
= get_DW_ATE_name (enc
);
18602 return "DW_ATE_<unknown>";
18608 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
18612 print_spaces (indent
, f
);
18613 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
18614 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
18616 if (die
->parent
!= NULL
)
18618 print_spaces (indent
, f
);
18619 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
18620 die
->parent
->offset
.sect_off
);
18623 print_spaces (indent
, f
);
18624 fprintf_unfiltered (f
, " has children: %s\n",
18625 dwarf_bool_name (die
->child
!= NULL
));
18627 print_spaces (indent
, f
);
18628 fprintf_unfiltered (f
, " attributes:\n");
18630 for (i
= 0; i
< die
->num_attrs
; ++i
)
18632 print_spaces (indent
, f
);
18633 fprintf_unfiltered (f
, " %s (%s) ",
18634 dwarf_attr_name (die
->attrs
[i
].name
),
18635 dwarf_form_name (die
->attrs
[i
].form
));
18637 switch (die
->attrs
[i
].form
)
18640 case DW_FORM_GNU_addr_index
:
18641 fprintf_unfiltered (f
, "address: ");
18642 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
18644 case DW_FORM_block2
:
18645 case DW_FORM_block4
:
18646 case DW_FORM_block
:
18647 case DW_FORM_block1
:
18648 fprintf_unfiltered (f
, "block: size %s",
18649 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
18651 case DW_FORM_exprloc
:
18652 fprintf_unfiltered (f
, "expression: size %s",
18653 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
18655 case DW_FORM_ref_addr
:
18656 fprintf_unfiltered (f
, "ref address: ");
18657 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
18659 case DW_FORM_GNU_ref_alt
:
18660 fprintf_unfiltered (f
, "alt ref address: ");
18661 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
18667 case DW_FORM_ref_udata
:
18668 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
18669 (long) (DW_UNSND (&die
->attrs
[i
])));
18671 case DW_FORM_data1
:
18672 case DW_FORM_data2
:
18673 case DW_FORM_data4
:
18674 case DW_FORM_data8
:
18675 case DW_FORM_udata
:
18676 case DW_FORM_sdata
:
18677 fprintf_unfiltered (f
, "constant: %s",
18678 pulongest (DW_UNSND (&die
->attrs
[i
])));
18680 case DW_FORM_sec_offset
:
18681 fprintf_unfiltered (f
, "section offset: %s",
18682 pulongest (DW_UNSND (&die
->attrs
[i
])));
18684 case DW_FORM_ref_sig8
:
18685 fprintf_unfiltered (f
, "signature: %s",
18686 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
18688 case DW_FORM_string
:
18690 case DW_FORM_GNU_str_index
:
18691 case DW_FORM_GNU_strp_alt
:
18692 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
18693 DW_STRING (&die
->attrs
[i
])
18694 ? DW_STRING (&die
->attrs
[i
]) : "",
18695 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
18698 if (DW_UNSND (&die
->attrs
[i
]))
18699 fprintf_unfiltered (f
, "flag: TRUE");
18701 fprintf_unfiltered (f
, "flag: FALSE");
18703 case DW_FORM_flag_present
:
18704 fprintf_unfiltered (f
, "flag: TRUE");
18706 case DW_FORM_indirect
:
18707 /* The reader will have reduced the indirect form to
18708 the "base form" so this form should not occur. */
18709 fprintf_unfiltered (f
,
18710 "unexpected attribute form: DW_FORM_indirect");
18713 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
18714 die
->attrs
[i
].form
);
18717 fprintf_unfiltered (f
, "\n");
18722 dump_die_for_error (struct die_info
*die
)
18724 dump_die_shallow (gdb_stderr
, 0, die
);
18728 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
18730 int indent
= level
* 4;
18732 gdb_assert (die
!= NULL
);
18734 if (level
>= max_level
)
18737 dump_die_shallow (f
, indent
, die
);
18739 if (die
->child
!= NULL
)
18741 print_spaces (indent
, f
);
18742 fprintf_unfiltered (f
, " Children:");
18743 if (level
+ 1 < max_level
)
18745 fprintf_unfiltered (f
, "\n");
18746 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
18750 fprintf_unfiltered (f
,
18751 " [not printed, max nesting level reached]\n");
18755 if (die
->sibling
!= NULL
&& level
> 0)
18757 dump_die_1 (f
, level
, max_level
, die
->sibling
);
18761 /* This is called from the pdie macro in gdbinit.in.
18762 It's not static so gcc will keep a copy callable from gdb. */
18765 dump_die (struct die_info
*die
, int max_level
)
18767 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
18771 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
18775 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
18781 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
18785 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
18787 sect_offset retval
= { DW_UNSND (attr
) };
18789 if (attr_form_is_ref (attr
))
18792 retval
.sect_off
= 0;
18793 complaint (&symfile_complaints
,
18794 _("unsupported die ref attribute form: '%s'"),
18795 dwarf_form_name (attr
->form
));
18799 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
18800 * the value held by the attribute is not constant. */
18803 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
18805 if (attr
->form
== DW_FORM_sdata
)
18806 return DW_SND (attr
);
18807 else if (attr
->form
== DW_FORM_udata
18808 || attr
->form
== DW_FORM_data1
18809 || attr
->form
== DW_FORM_data2
18810 || attr
->form
== DW_FORM_data4
18811 || attr
->form
== DW_FORM_data8
)
18812 return DW_UNSND (attr
);
18815 complaint (&symfile_complaints
,
18816 _("Attribute value is not a constant (%s)"),
18817 dwarf_form_name (attr
->form
));
18818 return default_value
;
18822 /* Follow reference or signature attribute ATTR of SRC_DIE.
18823 On entry *REF_CU is the CU of SRC_DIE.
18824 On exit *REF_CU is the CU of the result. */
18826 static struct die_info
*
18827 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
18828 struct dwarf2_cu
**ref_cu
)
18830 struct die_info
*die
;
18832 if (attr_form_is_ref (attr
))
18833 die
= follow_die_ref (src_die
, attr
, ref_cu
);
18834 else if (attr
->form
== DW_FORM_ref_sig8
)
18835 die
= follow_die_sig (src_die
, attr
, ref_cu
);
18838 dump_die_for_error (src_die
);
18839 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
18840 objfile_name ((*ref_cu
)->objfile
));
18846 /* Follow reference OFFSET.
18847 On entry *REF_CU is the CU of the source die referencing OFFSET.
18848 On exit *REF_CU is the CU of the result.
18849 Returns NULL if OFFSET is invalid. */
18851 static struct die_info
*
18852 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
18853 struct dwarf2_cu
**ref_cu
)
18855 struct die_info temp_die
;
18856 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
18858 gdb_assert (cu
->per_cu
!= NULL
);
18862 if (cu
->per_cu
->is_debug_types
)
18864 /* .debug_types CUs cannot reference anything outside their CU.
18865 If they need to, they have to reference a signatured type via
18866 DW_FORM_ref_sig8. */
18867 if (! offset_in_cu_p (&cu
->header
, offset
))
18870 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
18871 || ! offset_in_cu_p (&cu
->header
, offset
))
18873 struct dwarf2_per_cu_data
*per_cu
;
18875 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
18878 /* If necessary, add it to the queue and load its DIEs. */
18879 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
18880 load_full_comp_unit (per_cu
, cu
->language
);
18882 target_cu
= per_cu
->cu
;
18884 else if (cu
->dies
== NULL
)
18886 /* We're loading full DIEs during partial symbol reading. */
18887 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
18888 load_full_comp_unit (cu
->per_cu
, language_minimal
);
18891 *ref_cu
= target_cu
;
18892 temp_die
.offset
= offset
;
18893 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
18896 /* Follow reference attribute ATTR of SRC_DIE.
18897 On entry *REF_CU is the CU of SRC_DIE.
18898 On exit *REF_CU is the CU of the result. */
18900 static struct die_info
*
18901 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
18902 struct dwarf2_cu
**ref_cu
)
18904 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
18905 struct dwarf2_cu
*cu
= *ref_cu
;
18906 struct die_info
*die
;
18908 die
= follow_die_offset (offset
,
18909 (attr
->form
== DW_FORM_GNU_ref_alt
18910 || cu
->per_cu
->is_dwz
),
18913 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
18914 "at 0x%x [in module %s]"),
18915 offset
.sect_off
, src_die
->offset
.sect_off
,
18916 objfile_name (cu
->objfile
));
18921 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
18922 Returned value is intended for DW_OP_call*. Returned
18923 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
18925 struct dwarf2_locexpr_baton
18926 dwarf2_fetch_die_loc_sect_off (sect_offset offset
,
18927 struct dwarf2_per_cu_data
*per_cu
,
18928 CORE_ADDR (*get_frame_pc
) (void *baton
),
18931 struct dwarf2_cu
*cu
;
18932 struct die_info
*die
;
18933 struct attribute
*attr
;
18934 struct dwarf2_locexpr_baton retval
;
18936 dw2_setup (per_cu
->objfile
);
18938 if (per_cu
->cu
== NULL
)
18942 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
18944 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
18945 offset
.sect_off
, objfile_name (per_cu
->objfile
));
18947 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
18950 /* DWARF: "If there is no such attribute, then there is no effect.".
18951 DATA is ignored if SIZE is 0. */
18953 retval
.data
= NULL
;
18956 else if (attr_form_is_section_offset (attr
))
18958 struct dwarf2_loclist_baton loclist_baton
;
18959 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
18962 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
18964 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
18966 retval
.size
= size
;
18970 if (!attr_form_is_block (attr
))
18971 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
18972 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
18973 offset
.sect_off
, objfile_name (per_cu
->objfile
));
18975 retval
.data
= DW_BLOCK (attr
)->data
;
18976 retval
.size
= DW_BLOCK (attr
)->size
;
18978 retval
.per_cu
= cu
->per_cu
;
18980 age_cached_comp_units ();
18985 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
18988 struct dwarf2_locexpr_baton
18989 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
18990 struct dwarf2_per_cu_data
*per_cu
,
18991 CORE_ADDR (*get_frame_pc
) (void *baton
),
18994 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
18996 return dwarf2_fetch_die_loc_sect_off (offset
, per_cu
, get_frame_pc
, baton
);
18999 /* Write a constant of a given type as target-ordered bytes into
19002 static const gdb_byte
*
19003 write_constant_as_bytes (struct obstack
*obstack
,
19004 enum bfd_endian byte_order
,
19011 *len
= TYPE_LENGTH (type
);
19012 result
= obstack_alloc (obstack
, *len
);
19013 store_unsigned_integer (result
, *len
, byte_order
, value
);
19018 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
19019 pointer to the constant bytes and set LEN to the length of the
19020 data. If memory is needed, allocate it on OBSTACK. If the DIE
19021 does not have a DW_AT_const_value, return NULL. */
19024 dwarf2_fetch_constant_bytes (sect_offset offset
,
19025 struct dwarf2_per_cu_data
*per_cu
,
19026 struct obstack
*obstack
,
19029 struct dwarf2_cu
*cu
;
19030 struct die_info
*die
;
19031 struct attribute
*attr
;
19032 const gdb_byte
*result
= NULL
;
19035 enum bfd_endian byte_order
;
19037 dw2_setup (per_cu
->objfile
);
19039 if (per_cu
->cu
== NULL
)
19043 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
19045 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
19046 offset
.sect_off
, objfile_name (per_cu
->objfile
));
19049 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19053 byte_order
= (bfd_big_endian (per_cu
->objfile
->obfd
)
19054 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
19056 switch (attr
->form
)
19059 case DW_FORM_GNU_addr_index
:
19063 *len
= cu
->header
.addr_size
;
19064 tem
= obstack_alloc (obstack
, *len
);
19065 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
19069 case DW_FORM_string
:
19071 case DW_FORM_GNU_str_index
:
19072 case DW_FORM_GNU_strp_alt
:
19073 /* DW_STRING is already allocated on the objfile obstack, point
19075 result
= (const gdb_byte
*) DW_STRING (attr
);
19076 *len
= strlen (DW_STRING (attr
));
19078 case DW_FORM_block1
:
19079 case DW_FORM_block2
:
19080 case DW_FORM_block4
:
19081 case DW_FORM_block
:
19082 case DW_FORM_exprloc
:
19083 result
= DW_BLOCK (attr
)->data
;
19084 *len
= DW_BLOCK (attr
)->size
;
19087 /* The DW_AT_const_value attributes are supposed to carry the
19088 symbol's value "represented as it would be on the target
19089 architecture." By the time we get here, it's already been
19090 converted to host endianness, so we just need to sign- or
19091 zero-extend it as appropriate. */
19092 case DW_FORM_data1
:
19093 type
= die_type (die
, cu
);
19094 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
19095 if (result
== NULL
)
19096 result
= write_constant_as_bytes (obstack
, byte_order
,
19099 case DW_FORM_data2
:
19100 type
= die_type (die
, cu
);
19101 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
19102 if (result
== NULL
)
19103 result
= write_constant_as_bytes (obstack
, byte_order
,
19106 case DW_FORM_data4
:
19107 type
= die_type (die
, cu
);
19108 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
19109 if (result
== NULL
)
19110 result
= write_constant_as_bytes (obstack
, byte_order
,
19113 case DW_FORM_data8
:
19114 type
= die_type (die
, cu
);
19115 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
19116 if (result
== NULL
)
19117 result
= write_constant_as_bytes (obstack
, byte_order
,
19121 case DW_FORM_sdata
:
19122 type
= die_type (die
, cu
);
19123 result
= write_constant_as_bytes (obstack
, byte_order
,
19124 type
, DW_SND (attr
), len
);
19127 case DW_FORM_udata
:
19128 type
= die_type (die
, cu
);
19129 result
= write_constant_as_bytes (obstack
, byte_order
,
19130 type
, DW_UNSND (attr
), len
);
19134 complaint (&symfile_complaints
,
19135 _("unsupported const value attribute form: '%s'"),
19136 dwarf_form_name (attr
->form
));
19143 /* Return the type of the DIE at DIE_OFFSET in the CU named by
19147 dwarf2_get_die_type (cu_offset die_offset
,
19148 struct dwarf2_per_cu_data
*per_cu
)
19150 sect_offset die_offset_sect
;
19152 dw2_setup (per_cu
->objfile
);
19154 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
19155 return get_die_type_at_offset (die_offset_sect
, per_cu
);
19158 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
19159 On entry *REF_CU is the CU of SRC_DIE.
19160 On exit *REF_CU is the CU of the result.
19161 Returns NULL if the referenced DIE isn't found. */
19163 static struct die_info
*
19164 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
19165 struct dwarf2_cu
**ref_cu
)
19167 struct objfile
*objfile
= (*ref_cu
)->objfile
;
19168 struct die_info temp_die
;
19169 struct dwarf2_cu
*sig_cu
;
19170 struct die_info
*die
;
19172 /* While it might be nice to assert sig_type->type == NULL here,
19173 we can get here for DW_AT_imported_declaration where we need
19174 the DIE not the type. */
19176 /* If necessary, add it to the queue and load its DIEs. */
19178 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
19179 read_signatured_type (sig_type
);
19181 sig_cu
= sig_type
->per_cu
.cu
;
19182 gdb_assert (sig_cu
!= NULL
);
19183 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
19184 temp_die
.offset
= sig_type
->type_offset_in_section
;
19185 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
19186 temp_die
.offset
.sect_off
);
19189 /* For .gdb_index version 7 keep track of included TUs.
19190 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
19191 if (dwarf2_per_objfile
->index_table
!= NULL
19192 && dwarf2_per_objfile
->index_table
->version
<= 7)
19194 VEC_safe_push (dwarf2_per_cu_ptr
,
19195 (*ref_cu
)->per_cu
->imported_symtabs
,
19206 /* Follow signatured type referenced by ATTR in SRC_DIE.
19207 On entry *REF_CU is the CU of SRC_DIE.
19208 On exit *REF_CU is the CU of the result.
19209 The result is the DIE of the type.
19210 If the referenced type cannot be found an error is thrown. */
19212 static struct die_info
*
19213 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
19214 struct dwarf2_cu
**ref_cu
)
19216 ULONGEST signature
= DW_SIGNATURE (attr
);
19217 struct signatured_type
*sig_type
;
19218 struct die_info
*die
;
19220 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
19222 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
19223 /* sig_type will be NULL if the signatured type is missing from
19225 if (sig_type
== NULL
)
19227 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
19228 " from DIE at 0x%x [in module %s]"),
19229 hex_string (signature
), src_die
->offset
.sect_off
,
19230 objfile_name ((*ref_cu
)->objfile
));
19233 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
19236 dump_die_for_error (src_die
);
19237 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
19238 " from DIE at 0x%x [in module %s]"),
19239 hex_string (signature
), src_die
->offset
.sect_off
,
19240 objfile_name ((*ref_cu
)->objfile
));
19246 /* Get the type specified by SIGNATURE referenced in DIE/CU,
19247 reading in and processing the type unit if necessary. */
19249 static struct type
*
19250 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
19251 struct dwarf2_cu
*cu
)
19253 struct signatured_type
*sig_type
;
19254 struct dwarf2_cu
*type_cu
;
19255 struct die_info
*type_die
;
19258 sig_type
= lookup_signatured_type (cu
, signature
);
19259 /* sig_type will be NULL if the signatured type is missing from
19261 if (sig_type
== NULL
)
19263 complaint (&symfile_complaints
,
19264 _("Dwarf Error: Cannot find signatured DIE %s referenced"
19265 " from DIE at 0x%x [in module %s]"),
19266 hex_string (signature
), die
->offset
.sect_off
,
19267 objfile_name (dwarf2_per_objfile
->objfile
));
19268 return build_error_marker_type (cu
, die
);
19271 /* If we already know the type we're done. */
19272 if (sig_type
->type
!= NULL
)
19273 return sig_type
->type
;
19276 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
19277 if (type_die
!= NULL
)
19279 /* N.B. We need to call get_die_type to ensure only one type for this DIE
19280 is created. This is important, for example, because for c++ classes
19281 we need TYPE_NAME set which is only done by new_symbol. Blech. */
19282 type
= read_type_die (type_die
, type_cu
);
19285 complaint (&symfile_complaints
,
19286 _("Dwarf Error: Cannot build signatured type %s"
19287 " referenced from DIE at 0x%x [in module %s]"),
19288 hex_string (signature
), die
->offset
.sect_off
,
19289 objfile_name (dwarf2_per_objfile
->objfile
));
19290 type
= build_error_marker_type (cu
, die
);
19295 complaint (&symfile_complaints
,
19296 _("Dwarf Error: Problem reading signatured DIE %s referenced"
19297 " from DIE at 0x%x [in module %s]"),
19298 hex_string (signature
), die
->offset
.sect_off
,
19299 objfile_name (dwarf2_per_objfile
->objfile
));
19300 type
= build_error_marker_type (cu
, die
);
19302 sig_type
->type
= type
;
19307 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
19308 reading in and processing the type unit if necessary. */
19310 static struct type
*
19311 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
19312 struct dwarf2_cu
*cu
) /* ARI: editCase function */
19314 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
19315 if (attr_form_is_ref (attr
))
19317 struct dwarf2_cu
*type_cu
= cu
;
19318 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
19320 return read_type_die (type_die
, type_cu
);
19322 else if (attr
->form
== DW_FORM_ref_sig8
)
19324 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
19328 complaint (&symfile_complaints
,
19329 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
19330 " at 0x%x [in module %s]"),
19331 dwarf_form_name (attr
->form
), die
->offset
.sect_off
,
19332 objfile_name (dwarf2_per_objfile
->objfile
));
19333 return build_error_marker_type (cu
, die
);
19337 /* Load the DIEs associated with type unit PER_CU into memory. */
19340 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
19342 struct signatured_type
*sig_type
;
19344 /* Caller is responsible for ensuring type_unit_groups don't get here. */
19345 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
19347 /* We have the per_cu, but we need the signatured_type.
19348 Fortunately this is an easy translation. */
19349 gdb_assert (per_cu
->is_debug_types
);
19350 sig_type
= (struct signatured_type
*) per_cu
;
19352 gdb_assert (per_cu
->cu
== NULL
);
19354 read_signatured_type (sig_type
);
19356 gdb_assert (per_cu
->cu
!= NULL
);
19359 /* die_reader_func for read_signatured_type.
19360 This is identical to load_full_comp_unit_reader,
19361 but is kept separate for now. */
19364 read_signatured_type_reader (const struct die_reader_specs
*reader
,
19365 const gdb_byte
*info_ptr
,
19366 struct die_info
*comp_unit_die
,
19370 struct dwarf2_cu
*cu
= reader
->cu
;
19372 gdb_assert (cu
->die_hash
== NULL
);
19374 htab_create_alloc_ex (cu
->header
.length
/ 12,
19378 &cu
->comp_unit_obstack
,
19379 hashtab_obstack_allocate
,
19380 dummy_obstack_deallocate
);
19383 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
19384 &info_ptr
, comp_unit_die
);
19385 cu
->dies
= comp_unit_die
;
19386 /* comp_unit_die is not stored in die_hash, no need. */
19388 /* We try not to read any attributes in this function, because not
19389 all CUs needed for references have been loaded yet, and symbol
19390 table processing isn't initialized. But we have to set the CU language,
19391 or we won't be able to build types correctly.
19392 Similarly, if we do not read the producer, we can not apply
19393 producer-specific interpretation. */
19394 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
19397 /* Read in a signatured type and build its CU and DIEs.
19398 If the type is a stub for the real type in a DWO file,
19399 read in the real type from the DWO file as well. */
19402 read_signatured_type (struct signatured_type
*sig_type
)
19404 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
19406 gdb_assert (per_cu
->is_debug_types
);
19407 gdb_assert (per_cu
->cu
== NULL
);
19409 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
19410 read_signatured_type_reader
, NULL
);
19411 sig_type
->per_cu
.tu_read
= 1;
19414 /* Decode simple location descriptions.
19415 Given a pointer to a dwarf block that defines a location, compute
19416 the location and return the value.
19418 NOTE drow/2003-11-18: This function is called in two situations
19419 now: for the address of static or global variables (partial symbols
19420 only) and for offsets into structures which are expected to be
19421 (more or less) constant. The partial symbol case should go away,
19422 and only the constant case should remain. That will let this
19423 function complain more accurately. A few special modes are allowed
19424 without complaint for global variables (for instance, global
19425 register values and thread-local values).
19427 A location description containing no operations indicates that the
19428 object is optimized out. The return value is 0 for that case.
19429 FIXME drow/2003-11-16: No callers check for this case any more; soon all
19430 callers will only want a very basic result and this can become a
19433 Note that stack[0] is unused except as a default error return. */
19436 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
19438 struct objfile
*objfile
= cu
->objfile
;
19440 size_t size
= blk
->size
;
19441 const gdb_byte
*data
= blk
->data
;
19442 CORE_ADDR stack
[64];
19444 unsigned int bytes_read
, unsnd
;
19450 stack
[++stacki
] = 0;
19489 stack
[++stacki
] = op
- DW_OP_lit0
;
19524 stack
[++stacki
] = op
- DW_OP_reg0
;
19526 dwarf2_complex_location_expr_complaint ();
19530 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
19532 stack
[++stacki
] = unsnd
;
19534 dwarf2_complex_location_expr_complaint ();
19538 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
19543 case DW_OP_const1u
:
19544 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
19548 case DW_OP_const1s
:
19549 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
19553 case DW_OP_const2u
:
19554 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
19558 case DW_OP_const2s
:
19559 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
19563 case DW_OP_const4u
:
19564 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
19568 case DW_OP_const4s
:
19569 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
19573 case DW_OP_const8u
:
19574 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
19579 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
19585 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
19590 stack
[stacki
+ 1] = stack
[stacki
];
19595 stack
[stacki
- 1] += stack
[stacki
];
19599 case DW_OP_plus_uconst
:
19600 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
19606 stack
[stacki
- 1] -= stack
[stacki
];
19611 /* If we're not the last op, then we definitely can't encode
19612 this using GDB's address_class enum. This is valid for partial
19613 global symbols, although the variable's address will be bogus
19616 dwarf2_complex_location_expr_complaint ();
19619 case DW_OP_GNU_push_tls_address
:
19620 /* The top of the stack has the offset from the beginning
19621 of the thread control block at which the variable is located. */
19622 /* Nothing should follow this operator, so the top of stack would
19624 /* This is valid for partial global symbols, but the variable's
19625 address will be bogus in the psymtab. Make it always at least
19626 non-zero to not look as a variable garbage collected by linker
19627 which have DW_OP_addr 0. */
19629 dwarf2_complex_location_expr_complaint ();
19633 case DW_OP_GNU_uninit
:
19636 case DW_OP_GNU_addr_index
:
19637 case DW_OP_GNU_const_index
:
19638 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
19645 const char *name
= get_DW_OP_name (op
);
19648 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
19651 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
19655 return (stack
[stacki
]);
19658 /* Enforce maximum stack depth of SIZE-1 to avoid writing
19659 outside of the allocated space. Also enforce minimum>0. */
19660 if (stacki
>= ARRAY_SIZE (stack
) - 1)
19662 complaint (&symfile_complaints
,
19663 _("location description stack overflow"));
19669 complaint (&symfile_complaints
,
19670 _("location description stack underflow"));
19674 return (stack
[stacki
]);
19677 /* memory allocation interface */
19679 static struct dwarf_block
*
19680 dwarf_alloc_block (struct dwarf2_cu
*cu
)
19682 struct dwarf_block
*blk
;
19684 blk
= (struct dwarf_block
*)
19685 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
19689 static struct die_info
*
19690 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
19692 struct die_info
*die
;
19693 size_t size
= sizeof (struct die_info
);
19696 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
19698 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
19699 memset (die
, 0, sizeof (struct die_info
));
19704 /* Macro support. */
19706 /* Return file name relative to the compilation directory of file number I in
19707 *LH's file name table. The result is allocated using xmalloc; the caller is
19708 responsible for freeing it. */
19711 file_file_name (int file
, struct line_header
*lh
)
19713 /* Is the file number a valid index into the line header's file name
19714 table? Remember that file numbers start with one, not zero. */
19715 if (1 <= file
&& file
<= lh
->num_file_names
)
19717 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
19719 if (IS_ABSOLUTE_PATH (fe
->name
) || fe
->dir_index
== 0)
19720 return xstrdup (fe
->name
);
19721 return concat (lh
->include_dirs
[fe
->dir_index
- 1], SLASH_STRING
,
19726 /* The compiler produced a bogus file number. We can at least
19727 record the macro definitions made in the file, even if we
19728 won't be able to find the file by name. */
19729 char fake_name
[80];
19731 xsnprintf (fake_name
, sizeof (fake_name
),
19732 "<bad macro file number %d>", file
);
19734 complaint (&symfile_complaints
,
19735 _("bad file number in macro information (%d)"),
19738 return xstrdup (fake_name
);
19742 /* Return the full name of file number I in *LH's file name table.
19743 Use COMP_DIR as the name of the current directory of the
19744 compilation. The result is allocated using xmalloc; the caller is
19745 responsible for freeing it. */
19747 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
19749 /* Is the file number a valid index into the line header's file name
19750 table? Remember that file numbers start with one, not zero. */
19751 if (1 <= file
&& file
<= lh
->num_file_names
)
19753 char *relative
= file_file_name (file
, lh
);
19755 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
19757 return reconcat (relative
, comp_dir
, SLASH_STRING
, relative
, NULL
);
19760 return file_file_name (file
, lh
);
19764 static struct macro_source_file
*
19765 macro_start_file (int file
, int line
,
19766 struct macro_source_file
*current_file
,
19767 const char *comp_dir
,
19768 struct line_header
*lh
, struct objfile
*objfile
)
19770 /* File name relative to the compilation directory of this source file. */
19771 char *file_name
= file_file_name (file
, lh
);
19773 if (! current_file
)
19775 /* Note: We don't create a macro table for this compilation unit
19776 at all until we actually get a filename. */
19777 struct macro_table
*macro_table
= get_macro_table (objfile
, comp_dir
);
19779 /* If we have no current file, then this must be the start_file
19780 directive for the compilation unit's main source file. */
19781 current_file
= macro_set_main (macro_table
, file_name
);
19782 macro_define_special (macro_table
);
19785 current_file
= macro_include (current_file
, line
, file_name
);
19789 return current_file
;
19793 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
19794 followed by a null byte. */
19796 copy_string (const char *buf
, int len
)
19798 char *s
= xmalloc (len
+ 1);
19800 memcpy (s
, buf
, len
);
19806 static const char *
19807 consume_improper_spaces (const char *p
, const char *body
)
19811 complaint (&symfile_complaints
,
19812 _("macro definition contains spaces "
19813 "in formal argument list:\n`%s'"),
19825 parse_macro_definition (struct macro_source_file
*file
, int line
,
19830 /* The body string takes one of two forms. For object-like macro
19831 definitions, it should be:
19833 <macro name> " " <definition>
19835 For function-like macro definitions, it should be:
19837 <macro name> "() " <definition>
19839 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
19841 Spaces may appear only where explicitly indicated, and in the
19844 The Dwarf 2 spec says that an object-like macro's name is always
19845 followed by a space, but versions of GCC around March 2002 omit
19846 the space when the macro's definition is the empty string.
19848 The Dwarf 2 spec says that there should be no spaces between the
19849 formal arguments in a function-like macro's formal argument list,
19850 but versions of GCC around March 2002 include spaces after the
19854 /* Find the extent of the macro name. The macro name is terminated
19855 by either a space or null character (for an object-like macro) or
19856 an opening paren (for a function-like macro). */
19857 for (p
= body
; *p
; p
++)
19858 if (*p
== ' ' || *p
== '(')
19861 if (*p
== ' ' || *p
== '\0')
19863 /* It's an object-like macro. */
19864 int name_len
= p
- body
;
19865 char *name
= copy_string (body
, name_len
);
19866 const char *replacement
;
19869 replacement
= body
+ name_len
+ 1;
19872 dwarf2_macro_malformed_definition_complaint (body
);
19873 replacement
= body
+ name_len
;
19876 macro_define_object (file
, line
, name
, replacement
);
19880 else if (*p
== '(')
19882 /* It's a function-like macro. */
19883 char *name
= copy_string (body
, p
- body
);
19886 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
19890 p
= consume_improper_spaces (p
, body
);
19892 /* Parse the formal argument list. */
19893 while (*p
&& *p
!= ')')
19895 /* Find the extent of the current argument name. */
19896 const char *arg_start
= p
;
19898 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
19901 if (! *p
|| p
== arg_start
)
19902 dwarf2_macro_malformed_definition_complaint (body
);
19905 /* Make sure argv has room for the new argument. */
19906 if (argc
>= argv_size
)
19909 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
19912 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
19915 p
= consume_improper_spaces (p
, body
);
19917 /* Consume the comma, if present. */
19922 p
= consume_improper_spaces (p
, body
);
19931 /* Perfectly formed definition, no complaints. */
19932 macro_define_function (file
, line
, name
,
19933 argc
, (const char **) argv
,
19935 else if (*p
== '\0')
19937 /* Complain, but do define it. */
19938 dwarf2_macro_malformed_definition_complaint (body
);
19939 macro_define_function (file
, line
, name
,
19940 argc
, (const char **) argv
,
19944 /* Just complain. */
19945 dwarf2_macro_malformed_definition_complaint (body
);
19948 /* Just complain. */
19949 dwarf2_macro_malformed_definition_complaint (body
);
19955 for (i
= 0; i
< argc
; i
++)
19961 dwarf2_macro_malformed_definition_complaint (body
);
19964 /* Skip some bytes from BYTES according to the form given in FORM.
19965 Returns the new pointer. */
19967 static const gdb_byte
*
19968 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
19969 enum dwarf_form form
,
19970 unsigned int offset_size
,
19971 struct dwarf2_section_info
*section
)
19973 unsigned int bytes_read
;
19977 case DW_FORM_data1
:
19982 case DW_FORM_data2
:
19986 case DW_FORM_data4
:
19990 case DW_FORM_data8
:
19994 case DW_FORM_string
:
19995 read_direct_string (abfd
, bytes
, &bytes_read
);
19996 bytes
+= bytes_read
;
19999 case DW_FORM_sec_offset
:
20001 case DW_FORM_GNU_strp_alt
:
20002 bytes
+= offset_size
;
20005 case DW_FORM_block
:
20006 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
20007 bytes
+= bytes_read
;
20010 case DW_FORM_block1
:
20011 bytes
+= 1 + read_1_byte (abfd
, bytes
);
20013 case DW_FORM_block2
:
20014 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
20016 case DW_FORM_block4
:
20017 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
20020 case DW_FORM_sdata
:
20021 case DW_FORM_udata
:
20022 case DW_FORM_GNU_addr_index
:
20023 case DW_FORM_GNU_str_index
:
20024 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
20027 dwarf2_section_buffer_overflow_complaint (section
);
20035 complaint (&symfile_complaints
,
20036 _("invalid form 0x%x in `%s'"),
20037 form
, get_section_name (section
));
20045 /* A helper for dwarf_decode_macros that handles skipping an unknown
20046 opcode. Returns an updated pointer to the macro data buffer; or,
20047 on error, issues a complaint and returns NULL. */
20049 static const gdb_byte
*
20050 skip_unknown_opcode (unsigned int opcode
,
20051 const gdb_byte
**opcode_definitions
,
20052 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
20054 unsigned int offset_size
,
20055 struct dwarf2_section_info
*section
)
20057 unsigned int bytes_read
, i
;
20059 const gdb_byte
*defn
;
20061 if (opcode_definitions
[opcode
] == NULL
)
20063 complaint (&symfile_complaints
,
20064 _("unrecognized DW_MACFINO opcode 0x%x"),
20069 defn
= opcode_definitions
[opcode
];
20070 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
20071 defn
+= bytes_read
;
20073 for (i
= 0; i
< arg
; ++i
)
20075 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
20077 if (mac_ptr
== NULL
)
20079 /* skip_form_bytes already issued the complaint. */
20087 /* A helper function which parses the header of a macro section.
20088 If the macro section is the extended (for now called "GNU") type,
20089 then this updates *OFFSET_SIZE. Returns a pointer to just after
20090 the header, or issues a complaint and returns NULL on error. */
20092 static const gdb_byte
*
20093 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
20095 const gdb_byte
*mac_ptr
,
20096 unsigned int *offset_size
,
20097 int section_is_gnu
)
20099 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
20101 if (section_is_gnu
)
20103 unsigned int version
, flags
;
20105 version
= read_2_bytes (abfd
, mac_ptr
);
20108 complaint (&symfile_complaints
,
20109 _("unrecognized version `%d' in .debug_macro section"),
20115 flags
= read_1_byte (abfd
, mac_ptr
);
20117 *offset_size
= (flags
& 1) ? 8 : 4;
20119 if ((flags
& 2) != 0)
20120 /* We don't need the line table offset. */
20121 mac_ptr
+= *offset_size
;
20123 /* Vendor opcode descriptions. */
20124 if ((flags
& 4) != 0)
20126 unsigned int i
, count
;
20128 count
= read_1_byte (abfd
, mac_ptr
);
20130 for (i
= 0; i
< count
; ++i
)
20132 unsigned int opcode
, bytes_read
;
20135 opcode
= read_1_byte (abfd
, mac_ptr
);
20137 opcode_definitions
[opcode
] = mac_ptr
;
20138 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20139 mac_ptr
+= bytes_read
;
20148 /* A helper for dwarf_decode_macros that handles the GNU extensions,
20149 including DW_MACRO_GNU_transparent_include. */
20152 dwarf_decode_macro_bytes (bfd
*abfd
,
20153 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
20154 struct macro_source_file
*current_file
,
20155 struct line_header
*lh
, const char *comp_dir
,
20156 struct dwarf2_section_info
*section
,
20157 int section_is_gnu
, int section_is_dwz
,
20158 unsigned int offset_size
,
20159 struct objfile
*objfile
,
20160 htab_t include_hash
)
20162 enum dwarf_macro_record_type macinfo_type
;
20163 int at_commandline
;
20164 const gdb_byte
*opcode_definitions
[256];
20166 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
20167 &offset_size
, section_is_gnu
);
20168 if (mac_ptr
== NULL
)
20170 /* We already issued a complaint. */
20174 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
20175 GDB is still reading the definitions from command line. First
20176 DW_MACINFO_start_file will need to be ignored as it was already executed
20177 to create CURRENT_FILE for the main source holding also the command line
20178 definitions. On first met DW_MACINFO_start_file this flag is reset to
20179 normally execute all the remaining DW_MACINFO_start_file macinfos. */
20181 at_commandline
= 1;
20185 /* Do we at least have room for a macinfo type byte? */
20186 if (mac_ptr
>= mac_end
)
20188 dwarf2_section_buffer_overflow_complaint (section
);
20192 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
20195 /* Note that we rely on the fact that the corresponding GNU and
20196 DWARF constants are the same. */
20197 switch (macinfo_type
)
20199 /* A zero macinfo type indicates the end of the macro
20204 case DW_MACRO_GNU_define
:
20205 case DW_MACRO_GNU_undef
:
20206 case DW_MACRO_GNU_define_indirect
:
20207 case DW_MACRO_GNU_undef_indirect
:
20208 case DW_MACRO_GNU_define_indirect_alt
:
20209 case DW_MACRO_GNU_undef_indirect_alt
:
20211 unsigned int bytes_read
;
20216 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20217 mac_ptr
+= bytes_read
;
20219 if (macinfo_type
== DW_MACRO_GNU_define
20220 || macinfo_type
== DW_MACRO_GNU_undef
)
20222 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
20223 mac_ptr
+= bytes_read
;
20227 LONGEST str_offset
;
20229 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
20230 mac_ptr
+= offset_size
;
20232 if (macinfo_type
== DW_MACRO_GNU_define_indirect_alt
20233 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
20236 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
20238 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
20241 body
= read_indirect_string_at_offset (abfd
, str_offset
);
20244 is_define
= (macinfo_type
== DW_MACRO_GNU_define
20245 || macinfo_type
== DW_MACRO_GNU_define_indirect
20246 || macinfo_type
== DW_MACRO_GNU_define_indirect_alt
);
20247 if (! current_file
)
20249 /* DWARF violation as no main source is present. */
20250 complaint (&symfile_complaints
,
20251 _("debug info with no main source gives macro %s "
20253 is_define
? _("definition") : _("undefinition"),
20257 if ((line
== 0 && !at_commandline
)
20258 || (line
!= 0 && at_commandline
))
20259 complaint (&symfile_complaints
,
20260 _("debug info gives %s macro %s with %s line %d: %s"),
20261 at_commandline
? _("command-line") : _("in-file"),
20262 is_define
? _("definition") : _("undefinition"),
20263 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
20266 parse_macro_definition (current_file
, line
, body
);
20269 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
20270 || macinfo_type
== DW_MACRO_GNU_undef_indirect
20271 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
);
20272 macro_undef (current_file
, line
, body
);
20277 case DW_MACRO_GNU_start_file
:
20279 unsigned int bytes_read
;
20282 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20283 mac_ptr
+= bytes_read
;
20284 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20285 mac_ptr
+= bytes_read
;
20287 if ((line
== 0 && !at_commandline
)
20288 || (line
!= 0 && at_commandline
))
20289 complaint (&symfile_complaints
,
20290 _("debug info gives source %d included "
20291 "from %s at %s line %d"),
20292 file
, at_commandline
? _("command-line") : _("file"),
20293 line
== 0 ? _("zero") : _("non-zero"), line
);
20295 if (at_commandline
)
20297 /* This DW_MACRO_GNU_start_file was executed in the
20299 at_commandline
= 0;
20302 current_file
= macro_start_file (file
, line
,
20303 current_file
, comp_dir
,
20308 case DW_MACRO_GNU_end_file
:
20309 if (! current_file
)
20310 complaint (&symfile_complaints
,
20311 _("macro debug info has an unmatched "
20312 "`close_file' directive"));
20315 current_file
= current_file
->included_by
;
20316 if (! current_file
)
20318 enum dwarf_macro_record_type next_type
;
20320 /* GCC circa March 2002 doesn't produce the zero
20321 type byte marking the end of the compilation
20322 unit. Complain if it's not there, but exit no
20325 /* Do we at least have room for a macinfo type byte? */
20326 if (mac_ptr
>= mac_end
)
20328 dwarf2_section_buffer_overflow_complaint (section
);
20332 /* We don't increment mac_ptr here, so this is just
20334 next_type
= read_1_byte (abfd
, mac_ptr
);
20335 if (next_type
!= 0)
20336 complaint (&symfile_complaints
,
20337 _("no terminating 0-type entry for "
20338 "macros in `.debug_macinfo' section"));
20345 case DW_MACRO_GNU_transparent_include
:
20346 case DW_MACRO_GNU_transparent_include_alt
:
20350 bfd
*include_bfd
= abfd
;
20351 struct dwarf2_section_info
*include_section
= section
;
20352 struct dwarf2_section_info alt_section
;
20353 const gdb_byte
*include_mac_end
= mac_end
;
20354 int is_dwz
= section_is_dwz
;
20355 const gdb_byte
*new_mac_ptr
;
20357 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
20358 mac_ptr
+= offset_size
;
20360 if (macinfo_type
== DW_MACRO_GNU_transparent_include_alt
)
20362 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
20364 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
20367 include_section
= &dwz
->macro
;
20368 include_bfd
= get_section_bfd_owner (include_section
);
20369 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
20373 new_mac_ptr
= include_section
->buffer
+ offset
;
20374 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
20378 /* This has actually happened; see
20379 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
20380 complaint (&symfile_complaints
,
20381 _("recursive DW_MACRO_GNU_transparent_include in "
20382 ".debug_macro section"));
20386 *slot
= (void *) new_mac_ptr
;
20388 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
20389 include_mac_end
, current_file
,
20391 section
, section_is_gnu
, is_dwz
,
20392 offset_size
, objfile
, include_hash
);
20394 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
20399 case DW_MACINFO_vendor_ext
:
20400 if (!section_is_gnu
)
20402 unsigned int bytes_read
;
20405 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20406 mac_ptr
+= bytes_read
;
20407 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
20408 mac_ptr
+= bytes_read
;
20410 /* We don't recognize any vendor extensions. */
20416 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
20417 mac_ptr
, mac_end
, abfd
, offset_size
,
20419 if (mac_ptr
== NULL
)
20423 } while (macinfo_type
!= 0);
20427 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
20428 const char *comp_dir
, int section_is_gnu
)
20430 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20431 struct line_header
*lh
= cu
->line_header
;
20433 const gdb_byte
*mac_ptr
, *mac_end
;
20434 struct macro_source_file
*current_file
= 0;
20435 enum dwarf_macro_record_type macinfo_type
;
20436 unsigned int offset_size
= cu
->header
.offset_size
;
20437 const gdb_byte
*opcode_definitions
[256];
20438 struct cleanup
*cleanup
;
20439 htab_t include_hash
;
20441 struct dwarf2_section_info
*section
;
20442 const char *section_name
;
20444 if (cu
->dwo_unit
!= NULL
)
20446 if (section_is_gnu
)
20448 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
20449 section_name
= ".debug_macro.dwo";
20453 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
20454 section_name
= ".debug_macinfo.dwo";
20459 if (section_is_gnu
)
20461 section
= &dwarf2_per_objfile
->macro
;
20462 section_name
= ".debug_macro";
20466 section
= &dwarf2_per_objfile
->macinfo
;
20467 section_name
= ".debug_macinfo";
20471 dwarf2_read_section (objfile
, section
);
20472 if (section
->buffer
== NULL
)
20474 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
20477 abfd
= get_section_bfd_owner (section
);
20479 /* First pass: Find the name of the base filename.
20480 This filename is needed in order to process all macros whose definition
20481 (or undefinition) comes from the command line. These macros are defined
20482 before the first DW_MACINFO_start_file entry, and yet still need to be
20483 associated to the base file.
20485 To determine the base file name, we scan the macro definitions until we
20486 reach the first DW_MACINFO_start_file entry. We then initialize
20487 CURRENT_FILE accordingly so that any macro definition found before the
20488 first DW_MACINFO_start_file can still be associated to the base file. */
20490 mac_ptr
= section
->buffer
+ offset
;
20491 mac_end
= section
->buffer
+ section
->size
;
20493 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
20494 &offset_size
, section_is_gnu
);
20495 if (mac_ptr
== NULL
)
20497 /* We already issued a complaint. */
20503 /* Do we at least have room for a macinfo type byte? */
20504 if (mac_ptr
>= mac_end
)
20506 /* Complaint is printed during the second pass as GDB will probably
20507 stop the first pass earlier upon finding
20508 DW_MACINFO_start_file. */
20512 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
20515 /* Note that we rely on the fact that the corresponding GNU and
20516 DWARF constants are the same. */
20517 switch (macinfo_type
)
20519 /* A zero macinfo type indicates the end of the macro
20524 case DW_MACRO_GNU_define
:
20525 case DW_MACRO_GNU_undef
:
20526 /* Only skip the data by MAC_PTR. */
20528 unsigned int bytes_read
;
20530 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20531 mac_ptr
+= bytes_read
;
20532 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
20533 mac_ptr
+= bytes_read
;
20537 case DW_MACRO_GNU_start_file
:
20539 unsigned int bytes_read
;
20542 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20543 mac_ptr
+= bytes_read
;
20544 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20545 mac_ptr
+= bytes_read
;
20547 current_file
= macro_start_file (file
, line
, current_file
,
20548 comp_dir
, lh
, objfile
);
20552 case DW_MACRO_GNU_end_file
:
20553 /* No data to skip by MAC_PTR. */
20556 case DW_MACRO_GNU_define_indirect
:
20557 case DW_MACRO_GNU_undef_indirect
:
20558 case DW_MACRO_GNU_define_indirect_alt
:
20559 case DW_MACRO_GNU_undef_indirect_alt
:
20561 unsigned int bytes_read
;
20563 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20564 mac_ptr
+= bytes_read
;
20565 mac_ptr
+= offset_size
;
20569 case DW_MACRO_GNU_transparent_include
:
20570 case DW_MACRO_GNU_transparent_include_alt
:
20571 /* Note that, according to the spec, a transparent include
20572 chain cannot call DW_MACRO_GNU_start_file. So, we can just
20573 skip this opcode. */
20574 mac_ptr
+= offset_size
;
20577 case DW_MACINFO_vendor_ext
:
20578 /* Only skip the data by MAC_PTR. */
20579 if (!section_is_gnu
)
20581 unsigned int bytes_read
;
20583 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20584 mac_ptr
+= bytes_read
;
20585 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
20586 mac_ptr
+= bytes_read
;
20591 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
20592 mac_ptr
, mac_end
, abfd
, offset_size
,
20594 if (mac_ptr
== NULL
)
20598 } while (macinfo_type
!= 0 && current_file
== NULL
);
20600 /* Second pass: Process all entries.
20602 Use the AT_COMMAND_LINE flag to determine whether we are still processing
20603 command-line macro definitions/undefinitions. This flag is unset when we
20604 reach the first DW_MACINFO_start_file entry. */
20606 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
20607 NULL
, xcalloc
, xfree
);
20608 cleanup
= make_cleanup_htab_delete (include_hash
);
20609 mac_ptr
= section
->buffer
+ offset
;
20610 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
20611 *slot
= (void *) mac_ptr
;
20612 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
20613 current_file
, lh
, comp_dir
, section
,
20615 offset_size
, objfile
, include_hash
);
20616 do_cleanups (cleanup
);
20619 /* Check if the attribute's form is a DW_FORM_block*
20620 if so return true else false. */
20623 attr_form_is_block (const struct attribute
*attr
)
20625 return (attr
== NULL
? 0 :
20626 attr
->form
== DW_FORM_block1
20627 || attr
->form
== DW_FORM_block2
20628 || attr
->form
== DW_FORM_block4
20629 || attr
->form
== DW_FORM_block
20630 || attr
->form
== DW_FORM_exprloc
);
20633 /* Return non-zero if ATTR's value is a section offset --- classes
20634 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
20635 You may use DW_UNSND (attr) to retrieve such offsets.
20637 Section 7.5.4, "Attribute Encodings", explains that no attribute
20638 may have a value that belongs to more than one of these classes; it
20639 would be ambiguous if we did, because we use the same forms for all
20643 attr_form_is_section_offset (const struct attribute
*attr
)
20645 return (attr
->form
== DW_FORM_data4
20646 || attr
->form
== DW_FORM_data8
20647 || attr
->form
== DW_FORM_sec_offset
);
20650 /* Return non-zero if ATTR's value falls in the 'constant' class, or
20651 zero otherwise. When this function returns true, you can apply
20652 dwarf2_get_attr_constant_value to it.
20654 However, note that for some attributes you must check
20655 attr_form_is_section_offset before using this test. DW_FORM_data4
20656 and DW_FORM_data8 are members of both the constant class, and of
20657 the classes that contain offsets into other debug sections
20658 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
20659 that, if an attribute's can be either a constant or one of the
20660 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
20661 taken as section offsets, not constants. */
20664 attr_form_is_constant (const struct attribute
*attr
)
20666 switch (attr
->form
)
20668 case DW_FORM_sdata
:
20669 case DW_FORM_udata
:
20670 case DW_FORM_data1
:
20671 case DW_FORM_data2
:
20672 case DW_FORM_data4
:
20673 case DW_FORM_data8
:
20681 /* DW_ADDR is always stored already as sect_offset; despite for the forms
20682 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
20685 attr_form_is_ref (const struct attribute
*attr
)
20687 switch (attr
->form
)
20689 case DW_FORM_ref_addr
:
20694 case DW_FORM_ref_udata
:
20695 case DW_FORM_GNU_ref_alt
:
20702 /* Return the .debug_loc section to use for CU.
20703 For DWO files use .debug_loc.dwo. */
20705 static struct dwarf2_section_info
*
20706 cu_debug_loc_section (struct dwarf2_cu
*cu
)
20709 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
20710 return &dwarf2_per_objfile
->loc
;
20713 /* A helper function that fills in a dwarf2_loclist_baton. */
20716 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
20717 struct dwarf2_loclist_baton
*baton
,
20718 const struct attribute
*attr
)
20720 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
20722 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20724 baton
->per_cu
= cu
->per_cu
;
20725 gdb_assert (baton
->per_cu
);
20726 /* We don't know how long the location list is, but make sure we
20727 don't run off the edge of the section. */
20728 baton
->size
= section
->size
- DW_UNSND (attr
);
20729 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
20730 baton
->base_address
= cu
->base_address
;
20731 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
20735 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
20736 struct dwarf2_cu
*cu
, int is_block
)
20738 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20739 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
20741 if (attr_form_is_section_offset (attr
)
20742 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
20743 the section. If so, fall through to the complaint in the
20745 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
20747 struct dwarf2_loclist_baton
*baton
;
20749 baton
= obstack_alloc (&objfile
->objfile_obstack
,
20750 sizeof (struct dwarf2_loclist_baton
));
20752 fill_in_loclist_baton (cu
, baton
, attr
);
20754 if (cu
->base_known
== 0)
20755 complaint (&symfile_complaints
,
20756 _("Location list used without "
20757 "specifying the CU base address."));
20759 SYMBOL_ACLASS_INDEX (sym
) = (is_block
20760 ? dwarf2_loclist_block_index
20761 : dwarf2_loclist_index
);
20762 SYMBOL_LOCATION_BATON (sym
) = baton
;
20766 struct dwarf2_locexpr_baton
*baton
;
20768 baton
= obstack_alloc (&objfile
->objfile_obstack
,
20769 sizeof (struct dwarf2_locexpr_baton
));
20770 baton
->per_cu
= cu
->per_cu
;
20771 gdb_assert (baton
->per_cu
);
20773 if (attr_form_is_block (attr
))
20775 /* Note that we're just copying the block's data pointer
20776 here, not the actual data. We're still pointing into the
20777 info_buffer for SYM's objfile; right now we never release
20778 that buffer, but when we do clean up properly this may
20780 baton
->size
= DW_BLOCK (attr
)->size
;
20781 baton
->data
= DW_BLOCK (attr
)->data
;
20785 dwarf2_invalid_attrib_class_complaint ("location description",
20786 SYMBOL_NATURAL_NAME (sym
));
20790 SYMBOL_ACLASS_INDEX (sym
) = (is_block
20791 ? dwarf2_locexpr_block_index
20792 : dwarf2_locexpr_index
);
20793 SYMBOL_LOCATION_BATON (sym
) = baton
;
20797 /* Return the OBJFILE associated with the compilation unit CU. If CU
20798 came from a separate debuginfo file, then the master objfile is
20802 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
20804 struct objfile
*objfile
= per_cu
->objfile
;
20806 /* Return the master objfile, so that we can report and look up the
20807 correct file containing this variable. */
20808 if (objfile
->separate_debug_objfile_backlink
)
20809 objfile
= objfile
->separate_debug_objfile_backlink
;
20814 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
20815 (CU_HEADERP is unused in such case) or prepare a temporary copy at
20816 CU_HEADERP first. */
20818 static const struct comp_unit_head
*
20819 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
20820 struct dwarf2_per_cu_data
*per_cu
)
20822 const gdb_byte
*info_ptr
;
20825 return &per_cu
->cu
->header
;
20827 info_ptr
= per_cu
->section
->buffer
+ per_cu
->offset
.sect_off
;
20829 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
20830 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
20835 /* Return the address size given in the compilation unit header for CU. */
20838 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
20840 struct comp_unit_head cu_header_local
;
20841 const struct comp_unit_head
*cu_headerp
;
20843 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
20845 return cu_headerp
->addr_size
;
20848 /* Return the offset size given in the compilation unit header for CU. */
20851 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
20853 struct comp_unit_head cu_header_local
;
20854 const struct comp_unit_head
*cu_headerp
;
20856 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
20858 return cu_headerp
->offset_size
;
20861 /* See its dwarf2loc.h declaration. */
20864 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
20866 struct comp_unit_head cu_header_local
;
20867 const struct comp_unit_head
*cu_headerp
;
20869 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
20871 if (cu_headerp
->version
== 2)
20872 return cu_headerp
->addr_size
;
20874 return cu_headerp
->offset_size
;
20877 /* Return the text offset of the CU. The returned offset comes from
20878 this CU's objfile. If this objfile came from a separate debuginfo
20879 file, then the offset may be different from the corresponding
20880 offset in the parent objfile. */
20883 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
20885 struct objfile
*objfile
= per_cu
->objfile
;
20887 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
20890 /* Locate the .debug_info compilation unit from CU's objfile which contains
20891 the DIE at OFFSET. Raises an error on failure. */
20893 static struct dwarf2_per_cu_data
*
20894 dwarf2_find_containing_comp_unit (sect_offset offset
,
20895 unsigned int offset_in_dwz
,
20896 struct objfile
*objfile
)
20898 struct dwarf2_per_cu_data
*this_cu
;
20900 const sect_offset
*cu_off
;
20903 high
= dwarf2_per_objfile
->n_comp_units
- 1;
20906 struct dwarf2_per_cu_data
*mid_cu
;
20907 int mid
= low
+ (high
- low
) / 2;
20909 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
20910 cu_off
= &mid_cu
->offset
;
20911 if (mid_cu
->is_dwz
> offset_in_dwz
20912 || (mid_cu
->is_dwz
== offset_in_dwz
20913 && cu_off
->sect_off
>= offset
.sect_off
))
20918 gdb_assert (low
== high
);
20919 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
20920 cu_off
= &this_cu
->offset
;
20921 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
20923 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
20924 error (_("Dwarf Error: could not find partial DIE containing "
20925 "offset 0x%lx [in module %s]"),
20926 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
20928 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
20929 <= offset
.sect_off
);
20930 return dwarf2_per_objfile
->all_comp_units
[low
-1];
20934 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
20935 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
20936 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
20937 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
20938 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
20943 /* Initialize dwarf2_cu CU, owned by PER_CU. */
20946 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
20948 memset (cu
, 0, sizeof (*cu
));
20950 cu
->per_cu
= per_cu
;
20951 cu
->objfile
= per_cu
->objfile
;
20952 obstack_init (&cu
->comp_unit_obstack
);
20955 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
20958 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
20959 enum language pretend_language
)
20961 struct attribute
*attr
;
20963 /* Set the language we're debugging. */
20964 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
20966 set_cu_language (DW_UNSND (attr
), cu
);
20969 cu
->language
= pretend_language
;
20970 cu
->language_defn
= language_def (cu
->language
);
20973 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
20975 cu
->producer
= DW_STRING (attr
);
20978 /* Release one cached compilation unit, CU. We unlink it from the tree
20979 of compilation units, but we don't remove it from the read_in_chain;
20980 the caller is responsible for that.
20981 NOTE: DATA is a void * because this function is also used as a
20982 cleanup routine. */
20985 free_heap_comp_unit (void *data
)
20987 struct dwarf2_cu
*cu
= data
;
20989 gdb_assert (cu
->per_cu
!= NULL
);
20990 cu
->per_cu
->cu
= NULL
;
20993 obstack_free (&cu
->comp_unit_obstack
, NULL
);
20998 /* This cleanup function is passed the address of a dwarf2_cu on the stack
20999 when we're finished with it. We can't free the pointer itself, but be
21000 sure to unlink it from the cache. Also release any associated storage. */
21003 free_stack_comp_unit (void *data
)
21005 struct dwarf2_cu
*cu
= data
;
21007 gdb_assert (cu
->per_cu
!= NULL
);
21008 cu
->per_cu
->cu
= NULL
;
21011 obstack_free (&cu
->comp_unit_obstack
, NULL
);
21012 cu
->partial_dies
= NULL
;
21015 /* Free all cached compilation units. */
21018 free_cached_comp_units (void *data
)
21020 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
21022 per_cu
= dwarf2_per_objfile
->read_in_chain
;
21023 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
21024 while (per_cu
!= NULL
)
21026 struct dwarf2_per_cu_data
*next_cu
;
21028 next_cu
= per_cu
->cu
->read_in_chain
;
21030 free_heap_comp_unit (per_cu
->cu
);
21031 *last_chain
= next_cu
;
21037 /* Increase the age counter on each cached compilation unit, and free
21038 any that are too old. */
21041 age_cached_comp_units (void)
21043 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
21045 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
21046 per_cu
= dwarf2_per_objfile
->read_in_chain
;
21047 while (per_cu
!= NULL
)
21049 per_cu
->cu
->last_used
++;
21050 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
21051 dwarf2_mark (per_cu
->cu
);
21052 per_cu
= per_cu
->cu
->read_in_chain
;
21055 per_cu
= dwarf2_per_objfile
->read_in_chain
;
21056 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
21057 while (per_cu
!= NULL
)
21059 struct dwarf2_per_cu_data
*next_cu
;
21061 next_cu
= per_cu
->cu
->read_in_chain
;
21063 if (!per_cu
->cu
->mark
)
21065 free_heap_comp_unit (per_cu
->cu
);
21066 *last_chain
= next_cu
;
21069 last_chain
= &per_cu
->cu
->read_in_chain
;
21075 /* Remove a single compilation unit from the cache. */
21078 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
21080 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
21082 per_cu
= dwarf2_per_objfile
->read_in_chain
;
21083 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
21084 while (per_cu
!= NULL
)
21086 struct dwarf2_per_cu_data
*next_cu
;
21088 next_cu
= per_cu
->cu
->read_in_chain
;
21090 if (per_cu
== target_per_cu
)
21092 free_heap_comp_unit (per_cu
->cu
);
21094 *last_chain
= next_cu
;
21098 last_chain
= &per_cu
->cu
->read_in_chain
;
21104 /* Release all extra memory associated with OBJFILE. */
21107 dwarf2_free_objfile (struct objfile
*objfile
)
21109 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
21111 if (dwarf2_per_objfile
== NULL
)
21114 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
21115 free_cached_comp_units (NULL
);
21117 if (dwarf2_per_objfile
->quick_file_names_table
)
21118 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
21120 /* Everything else should be on the objfile obstack. */
21123 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
21124 We store these in a hash table separate from the DIEs, and preserve them
21125 when the DIEs are flushed out of cache.
21127 The CU "per_cu" pointer is needed because offset alone is not enough to
21128 uniquely identify the type. A file may have multiple .debug_types sections,
21129 or the type may come from a DWO file. Furthermore, while it's more logical
21130 to use per_cu->section+offset, with Fission the section with the data is in
21131 the DWO file but we don't know that section at the point we need it.
21132 We have to use something in dwarf2_per_cu_data (or the pointer to it)
21133 because we can enter the lookup routine, get_die_type_at_offset, from
21134 outside this file, and thus won't necessarily have PER_CU->cu.
21135 Fortunately, PER_CU is stable for the life of the objfile. */
21137 struct dwarf2_per_cu_offset_and_type
21139 const struct dwarf2_per_cu_data
*per_cu
;
21140 sect_offset offset
;
21144 /* Hash function for a dwarf2_per_cu_offset_and_type. */
21147 per_cu_offset_and_type_hash (const void *item
)
21149 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
21151 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
21154 /* Equality function for a dwarf2_per_cu_offset_and_type. */
21157 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
21159 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
21160 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
21162 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
21163 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
21166 /* Set the type associated with DIE to TYPE. Save it in CU's hash
21167 table if necessary. For convenience, return TYPE.
21169 The DIEs reading must have careful ordering to:
21170 * Not cause infite loops trying to read in DIEs as a prerequisite for
21171 reading current DIE.
21172 * Not trying to dereference contents of still incompletely read in types
21173 while reading in other DIEs.
21174 * Enable referencing still incompletely read in types just by a pointer to
21175 the type without accessing its fields.
21177 Therefore caller should follow these rules:
21178 * Try to fetch any prerequisite types we may need to build this DIE type
21179 before building the type and calling set_die_type.
21180 * After building type call set_die_type for current DIE as soon as
21181 possible before fetching more types to complete the current type.
21182 * Make the type as complete as possible before fetching more types. */
21184 static struct type
*
21185 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
21187 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
21188 struct objfile
*objfile
= cu
->objfile
;
21190 /* For Ada types, make sure that the gnat-specific data is always
21191 initialized (if not already set). There are a few types where
21192 we should not be doing so, because the type-specific area is
21193 already used to hold some other piece of info (eg: TYPE_CODE_FLT
21194 where the type-specific area is used to store the floatformat).
21195 But this is not a problem, because the gnat-specific information
21196 is actually not needed for these types. */
21197 if (need_gnat_info (cu
)
21198 && TYPE_CODE (type
) != TYPE_CODE_FUNC
21199 && TYPE_CODE (type
) != TYPE_CODE_FLT
21200 && !HAVE_GNAT_AUX_INFO (type
))
21201 INIT_GNAT_SPECIFIC (type
);
21203 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
21205 dwarf2_per_objfile
->die_type_hash
=
21206 htab_create_alloc_ex (127,
21207 per_cu_offset_and_type_hash
,
21208 per_cu_offset_and_type_eq
,
21210 &objfile
->objfile_obstack
,
21211 hashtab_obstack_allocate
,
21212 dummy_obstack_deallocate
);
21215 ofs
.per_cu
= cu
->per_cu
;
21216 ofs
.offset
= die
->offset
;
21218 slot
= (struct dwarf2_per_cu_offset_and_type
**)
21219 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
21221 complaint (&symfile_complaints
,
21222 _("A problem internal to GDB: DIE 0x%x has type already set"),
21223 die
->offset
.sect_off
);
21224 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
21229 /* Look up the type for the die at OFFSET in PER_CU in die_type_hash,
21230 or return NULL if the die does not have a saved type. */
21232 static struct type
*
21233 get_die_type_at_offset (sect_offset offset
,
21234 struct dwarf2_per_cu_data
*per_cu
)
21236 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
21238 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
21241 ofs
.per_cu
= per_cu
;
21242 ofs
.offset
= offset
;
21243 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
21250 /* Look up the type for DIE in CU in die_type_hash,
21251 or return NULL if DIE does not have a saved type. */
21253 static struct type
*
21254 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21256 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
21259 /* Add a dependence relationship from CU to REF_PER_CU. */
21262 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
21263 struct dwarf2_per_cu_data
*ref_per_cu
)
21267 if (cu
->dependencies
== NULL
)
21269 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
21270 NULL
, &cu
->comp_unit_obstack
,
21271 hashtab_obstack_allocate
,
21272 dummy_obstack_deallocate
);
21274 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
21276 *slot
= ref_per_cu
;
21279 /* Subroutine of dwarf2_mark to pass to htab_traverse.
21280 Set the mark field in every compilation unit in the
21281 cache that we must keep because we are keeping CU. */
21284 dwarf2_mark_helper (void **slot
, void *data
)
21286 struct dwarf2_per_cu_data
*per_cu
;
21288 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
21290 /* cu->dependencies references may not yet have been ever read if QUIT aborts
21291 reading of the chain. As such dependencies remain valid it is not much
21292 useful to track and undo them during QUIT cleanups. */
21293 if (per_cu
->cu
== NULL
)
21296 if (per_cu
->cu
->mark
)
21298 per_cu
->cu
->mark
= 1;
21300 if (per_cu
->cu
->dependencies
!= NULL
)
21301 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
21306 /* Set the mark field in CU and in every other compilation unit in the
21307 cache that we must keep because we are keeping CU. */
21310 dwarf2_mark (struct dwarf2_cu
*cu
)
21315 if (cu
->dependencies
!= NULL
)
21316 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
21320 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
21324 per_cu
->cu
->mark
= 0;
21325 per_cu
= per_cu
->cu
->read_in_chain
;
21329 /* Trivial hash function for partial_die_info: the hash value of a DIE
21330 is its offset in .debug_info for this objfile. */
21333 partial_die_hash (const void *item
)
21335 const struct partial_die_info
*part_die
= item
;
21337 return part_die
->offset
.sect_off
;
21340 /* Trivial comparison function for partial_die_info structures: two DIEs
21341 are equal if they have the same offset. */
21344 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
21346 const struct partial_die_info
*part_die_lhs
= item_lhs
;
21347 const struct partial_die_info
*part_die_rhs
= item_rhs
;
21349 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
21352 static struct cmd_list_element
*set_dwarf2_cmdlist
;
21353 static struct cmd_list_element
*show_dwarf2_cmdlist
;
21356 set_dwarf2_cmd (char *args
, int from_tty
)
21358 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
21362 show_dwarf2_cmd (char *args
, int from_tty
)
21364 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
21367 /* Free data associated with OBJFILE, if necessary. */
21370 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
21372 struct dwarf2_per_objfile
*data
= d
;
21375 /* Make sure we don't accidentally use dwarf2_per_objfile while
21377 dwarf2_per_objfile
= NULL
;
21379 for (ix
= 0; ix
< data
->n_comp_units
; ++ix
)
21380 VEC_free (dwarf2_per_cu_ptr
, data
->all_comp_units
[ix
]->imported_symtabs
);
21382 for (ix
= 0; ix
< data
->n_type_units
; ++ix
)
21383 VEC_free (dwarf2_per_cu_ptr
,
21384 data
->all_type_units
[ix
]->per_cu
.imported_symtabs
);
21385 xfree (data
->all_type_units
);
21387 VEC_free (dwarf2_section_info_def
, data
->types
);
21389 if (data
->dwo_files
)
21390 free_dwo_files (data
->dwo_files
, objfile
);
21391 if (data
->dwp_file
)
21392 gdb_bfd_unref (data
->dwp_file
->dbfd
);
21394 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
21395 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
21399 /* The "save gdb-index" command. */
21401 /* The contents of the hash table we create when building the string
21403 struct strtab_entry
21405 offset_type offset
;
21409 /* Hash function for a strtab_entry.
21411 Function is used only during write_hash_table so no index format backward
21412 compatibility is needed. */
21415 hash_strtab_entry (const void *e
)
21417 const struct strtab_entry
*entry
= e
;
21418 return mapped_index_string_hash (INT_MAX
, entry
->str
);
21421 /* Equality function for a strtab_entry. */
21424 eq_strtab_entry (const void *a
, const void *b
)
21426 const struct strtab_entry
*ea
= a
;
21427 const struct strtab_entry
*eb
= b
;
21428 return !strcmp (ea
->str
, eb
->str
);
21431 /* Create a strtab_entry hash table. */
21434 create_strtab (void)
21436 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
21437 xfree
, xcalloc
, xfree
);
21440 /* Add a string to the constant pool. Return the string's offset in
21444 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
21447 struct strtab_entry entry
;
21448 struct strtab_entry
*result
;
21451 slot
= htab_find_slot (table
, &entry
, INSERT
);
21456 result
= XNEW (struct strtab_entry
);
21457 result
->offset
= obstack_object_size (cpool
);
21459 obstack_grow_str0 (cpool
, str
);
21462 return result
->offset
;
21465 /* An entry in the symbol table. */
21466 struct symtab_index_entry
21468 /* The name of the symbol. */
21470 /* The offset of the name in the constant pool. */
21471 offset_type index_offset
;
21472 /* A sorted vector of the indices of all the CUs that hold an object
21474 VEC (offset_type
) *cu_indices
;
21477 /* The symbol table. This is a power-of-2-sized hash table. */
21478 struct mapped_symtab
21480 offset_type n_elements
;
21482 struct symtab_index_entry
**data
;
21485 /* Hash function for a symtab_index_entry. */
21488 hash_symtab_entry (const void *e
)
21490 const struct symtab_index_entry
*entry
= e
;
21491 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
21492 sizeof (offset_type
) * VEC_length (offset_type
,
21493 entry
->cu_indices
),
21497 /* Equality function for a symtab_index_entry. */
21500 eq_symtab_entry (const void *a
, const void *b
)
21502 const struct symtab_index_entry
*ea
= a
;
21503 const struct symtab_index_entry
*eb
= b
;
21504 int len
= VEC_length (offset_type
, ea
->cu_indices
);
21505 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
21507 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
21508 VEC_address (offset_type
, eb
->cu_indices
),
21509 sizeof (offset_type
) * len
);
21512 /* Destroy a symtab_index_entry. */
21515 delete_symtab_entry (void *p
)
21517 struct symtab_index_entry
*entry
= p
;
21518 VEC_free (offset_type
, entry
->cu_indices
);
21522 /* Create a hash table holding symtab_index_entry objects. */
21525 create_symbol_hash_table (void)
21527 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
21528 delete_symtab_entry
, xcalloc
, xfree
);
21531 /* Create a new mapped symtab object. */
21533 static struct mapped_symtab
*
21534 create_mapped_symtab (void)
21536 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
21537 symtab
->n_elements
= 0;
21538 symtab
->size
= 1024;
21539 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
21543 /* Destroy a mapped_symtab. */
21546 cleanup_mapped_symtab (void *p
)
21548 struct mapped_symtab
*symtab
= p
;
21549 /* The contents of the array are freed when the other hash table is
21551 xfree (symtab
->data
);
21555 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
21558 Function is used only during write_hash_table so no index format backward
21559 compatibility is needed. */
21561 static struct symtab_index_entry
**
21562 find_slot (struct mapped_symtab
*symtab
, const char *name
)
21564 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
21566 index
= hash
& (symtab
->size
- 1);
21567 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
21571 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
21572 return &symtab
->data
[index
];
21573 index
= (index
+ step
) & (symtab
->size
- 1);
21577 /* Expand SYMTAB's hash table. */
21580 hash_expand (struct mapped_symtab
*symtab
)
21582 offset_type old_size
= symtab
->size
;
21584 struct symtab_index_entry
**old_entries
= symtab
->data
;
21587 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
21589 for (i
= 0; i
< old_size
; ++i
)
21591 if (old_entries
[i
])
21593 struct symtab_index_entry
**slot
= find_slot (symtab
,
21594 old_entries
[i
]->name
);
21595 *slot
= old_entries
[i
];
21599 xfree (old_entries
);
21602 /* Add an entry to SYMTAB. NAME is the name of the symbol.
21603 CU_INDEX is the index of the CU in which the symbol appears.
21604 IS_STATIC is one if the symbol is static, otherwise zero (global). */
21607 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
21608 int is_static
, gdb_index_symbol_kind kind
,
21609 offset_type cu_index
)
21611 struct symtab_index_entry
**slot
;
21612 offset_type cu_index_and_attrs
;
21614 ++symtab
->n_elements
;
21615 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
21616 hash_expand (symtab
);
21618 slot
= find_slot (symtab
, name
);
21621 *slot
= XNEW (struct symtab_index_entry
);
21622 (*slot
)->name
= name
;
21623 /* index_offset is set later. */
21624 (*slot
)->cu_indices
= NULL
;
21627 cu_index_and_attrs
= 0;
21628 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
21629 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
21630 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
21632 /* We don't want to record an index value twice as we want to avoid the
21634 We process all global symbols and then all static symbols
21635 (which would allow us to avoid the duplication by only having to check
21636 the last entry pushed), but a symbol could have multiple kinds in one CU.
21637 To keep things simple we don't worry about the duplication here and
21638 sort and uniqufy the list after we've processed all symbols. */
21639 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
21642 /* qsort helper routine for uniquify_cu_indices. */
21645 offset_type_compare (const void *ap
, const void *bp
)
21647 offset_type a
= *(offset_type
*) ap
;
21648 offset_type b
= *(offset_type
*) bp
;
21650 return (a
> b
) - (b
> a
);
21653 /* Sort and remove duplicates of all symbols' cu_indices lists. */
21656 uniquify_cu_indices (struct mapped_symtab
*symtab
)
21660 for (i
= 0; i
< symtab
->size
; ++i
)
21662 struct symtab_index_entry
*entry
= symtab
->data
[i
];
21665 && entry
->cu_indices
!= NULL
)
21667 unsigned int next_to_insert
, next_to_check
;
21668 offset_type last_value
;
21670 qsort (VEC_address (offset_type
, entry
->cu_indices
),
21671 VEC_length (offset_type
, entry
->cu_indices
),
21672 sizeof (offset_type
), offset_type_compare
);
21674 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
21675 next_to_insert
= 1;
21676 for (next_to_check
= 1;
21677 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
21680 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
21683 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
21685 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
21690 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
21695 /* Add a vector of indices to the constant pool. */
21698 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
21699 struct symtab_index_entry
*entry
)
21703 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
21706 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
21707 offset_type val
= MAYBE_SWAP (len
);
21712 entry
->index_offset
= obstack_object_size (cpool
);
21714 obstack_grow (cpool
, &val
, sizeof (val
));
21716 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
21719 val
= MAYBE_SWAP (iter
);
21720 obstack_grow (cpool
, &val
, sizeof (val
));
21725 struct symtab_index_entry
*old_entry
= *slot
;
21726 entry
->index_offset
= old_entry
->index_offset
;
21729 return entry
->index_offset
;
21732 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
21733 constant pool entries going into the obstack CPOOL. */
21736 write_hash_table (struct mapped_symtab
*symtab
,
21737 struct obstack
*output
, struct obstack
*cpool
)
21740 htab_t symbol_hash_table
;
21743 symbol_hash_table
= create_symbol_hash_table ();
21744 str_table
= create_strtab ();
21746 /* We add all the index vectors to the constant pool first, to
21747 ensure alignment is ok. */
21748 for (i
= 0; i
< symtab
->size
; ++i
)
21750 if (symtab
->data
[i
])
21751 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
21754 /* Now write out the hash table. */
21755 for (i
= 0; i
< symtab
->size
; ++i
)
21757 offset_type str_off
, vec_off
;
21759 if (symtab
->data
[i
])
21761 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
21762 vec_off
= symtab
->data
[i
]->index_offset
;
21766 /* While 0 is a valid constant pool index, it is not valid
21767 to have 0 for both offsets. */
21772 str_off
= MAYBE_SWAP (str_off
);
21773 vec_off
= MAYBE_SWAP (vec_off
);
21775 obstack_grow (output
, &str_off
, sizeof (str_off
));
21776 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
21779 htab_delete (str_table
);
21780 htab_delete (symbol_hash_table
);
21783 /* Struct to map psymtab to CU index in the index file. */
21784 struct psymtab_cu_index_map
21786 struct partial_symtab
*psymtab
;
21787 unsigned int cu_index
;
21791 hash_psymtab_cu_index (const void *item
)
21793 const struct psymtab_cu_index_map
*map
= item
;
21795 return htab_hash_pointer (map
->psymtab
);
21799 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
21801 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
21802 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
21804 return lhs
->psymtab
== rhs
->psymtab
;
21807 /* Helper struct for building the address table. */
21808 struct addrmap_index_data
21810 struct objfile
*objfile
;
21811 struct obstack
*addr_obstack
;
21812 htab_t cu_index_htab
;
21814 /* Non-zero if the previous_* fields are valid.
21815 We can't write an entry until we see the next entry (since it is only then
21816 that we know the end of the entry). */
21817 int previous_valid
;
21818 /* Index of the CU in the table of all CUs in the index file. */
21819 unsigned int previous_cu_index
;
21820 /* Start address of the CU. */
21821 CORE_ADDR previous_cu_start
;
21824 /* Write an address entry to OBSTACK. */
21827 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
21828 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
21830 offset_type cu_index_to_write
;
21832 CORE_ADDR baseaddr
;
21834 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21836 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
21837 obstack_grow (obstack
, addr
, 8);
21838 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
21839 obstack_grow (obstack
, addr
, 8);
21840 cu_index_to_write
= MAYBE_SWAP (cu_index
);
21841 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
21844 /* Worker function for traversing an addrmap to build the address table. */
21847 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
21849 struct addrmap_index_data
*data
= datap
;
21850 struct partial_symtab
*pst
= obj
;
21852 if (data
->previous_valid
)
21853 add_address_entry (data
->objfile
, data
->addr_obstack
,
21854 data
->previous_cu_start
, start_addr
,
21855 data
->previous_cu_index
);
21857 data
->previous_cu_start
= start_addr
;
21860 struct psymtab_cu_index_map find_map
, *map
;
21861 find_map
.psymtab
= pst
;
21862 map
= htab_find (data
->cu_index_htab
, &find_map
);
21863 gdb_assert (map
!= NULL
);
21864 data
->previous_cu_index
= map
->cu_index
;
21865 data
->previous_valid
= 1;
21868 data
->previous_valid
= 0;
21873 /* Write OBJFILE's address map to OBSTACK.
21874 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
21875 in the index file. */
21878 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
21879 htab_t cu_index_htab
)
21881 struct addrmap_index_data addrmap_index_data
;
21883 /* When writing the address table, we have to cope with the fact that
21884 the addrmap iterator only provides the start of a region; we have to
21885 wait until the next invocation to get the start of the next region. */
21887 addrmap_index_data
.objfile
= objfile
;
21888 addrmap_index_data
.addr_obstack
= obstack
;
21889 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
21890 addrmap_index_data
.previous_valid
= 0;
21892 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
21893 &addrmap_index_data
);
21895 /* It's highly unlikely the last entry (end address = 0xff...ff)
21896 is valid, but we should still handle it.
21897 The end address is recorded as the start of the next region, but that
21898 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
21900 if (addrmap_index_data
.previous_valid
)
21901 add_address_entry (objfile
, obstack
,
21902 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
21903 addrmap_index_data
.previous_cu_index
);
21906 /* Return the symbol kind of PSYM. */
21908 static gdb_index_symbol_kind
21909 symbol_kind (struct partial_symbol
*psym
)
21911 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
21912 enum address_class aclass
= PSYMBOL_CLASS (psym
);
21920 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
21922 return GDB_INDEX_SYMBOL_KIND_TYPE
;
21924 case LOC_CONST_BYTES
:
21925 case LOC_OPTIMIZED_OUT
:
21927 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
21929 /* Note: It's currently impossible to recognize psyms as enum values
21930 short of reading the type info. For now punt. */
21931 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
21933 /* There are other LOC_FOO values that one might want to classify
21934 as variables, but dwarf2read.c doesn't currently use them. */
21935 return GDB_INDEX_SYMBOL_KIND_OTHER
;
21937 case STRUCT_DOMAIN
:
21938 return GDB_INDEX_SYMBOL_KIND_TYPE
;
21940 return GDB_INDEX_SYMBOL_KIND_OTHER
;
21944 /* Add a list of partial symbols to SYMTAB. */
21947 write_psymbols (struct mapped_symtab
*symtab
,
21949 struct partial_symbol
**psymp
,
21951 offset_type cu_index
,
21954 for (; count
-- > 0; ++psymp
)
21956 struct partial_symbol
*psym
= *psymp
;
21959 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
21960 error (_("Ada is not currently supported by the index"));
21962 /* Only add a given psymbol once. */
21963 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
21966 gdb_index_symbol_kind kind
= symbol_kind (psym
);
21969 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
21970 is_static
, kind
, cu_index
);
21975 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
21976 exception if there is an error. */
21979 write_obstack (FILE *file
, struct obstack
*obstack
)
21981 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
21983 != obstack_object_size (obstack
))
21984 error (_("couldn't data write to file"));
21987 /* Unlink a file if the argument is not NULL. */
21990 unlink_if_set (void *p
)
21992 char **filename
= p
;
21994 unlink (*filename
);
21997 /* A helper struct used when iterating over debug_types. */
21998 struct signatured_type_index_data
22000 struct objfile
*objfile
;
22001 struct mapped_symtab
*symtab
;
22002 struct obstack
*types_list
;
22007 /* A helper function that writes a single signatured_type to an
22011 write_one_signatured_type (void **slot
, void *d
)
22013 struct signatured_type_index_data
*info
= d
;
22014 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
22015 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
22018 write_psymbols (info
->symtab
,
22020 info
->objfile
->global_psymbols
.list
22021 + psymtab
->globals_offset
,
22022 psymtab
->n_global_syms
, info
->cu_index
,
22024 write_psymbols (info
->symtab
,
22026 info
->objfile
->static_psymbols
.list
22027 + psymtab
->statics_offset
,
22028 psymtab
->n_static_syms
, info
->cu_index
,
22031 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
22032 entry
->per_cu
.offset
.sect_off
);
22033 obstack_grow (info
->types_list
, val
, 8);
22034 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
22035 entry
->type_offset_in_tu
.cu_off
);
22036 obstack_grow (info
->types_list
, val
, 8);
22037 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
22038 obstack_grow (info
->types_list
, val
, 8);
22045 /* Recurse into all "included" dependencies and write their symbols as
22046 if they appeared in this psymtab. */
22049 recursively_write_psymbols (struct objfile
*objfile
,
22050 struct partial_symtab
*psymtab
,
22051 struct mapped_symtab
*symtab
,
22053 offset_type cu_index
)
22057 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
22058 if (psymtab
->dependencies
[i
]->user
!= NULL
)
22059 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
22060 symtab
, psyms_seen
, cu_index
);
22062 write_psymbols (symtab
,
22064 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
22065 psymtab
->n_global_syms
, cu_index
,
22067 write_psymbols (symtab
,
22069 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
22070 psymtab
->n_static_syms
, cu_index
,
22074 /* Create an index file for OBJFILE in the directory DIR. */
22077 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
22079 struct cleanup
*cleanup
;
22080 char *filename
, *cleanup_filename
;
22081 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
22082 struct obstack cu_list
, types_cu_list
;
22085 struct mapped_symtab
*symtab
;
22086 offset_type val
, size_of_contents
, total_len
;
22089 htab_t cu_index_htab
;
22090 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
22092 if (dwarf2_per_objfile
->using_index
)
22093 error (_("Cannot use an index to create the index"));
22095 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
22096 error (_("Cannot make an index when the file has multiple .debug_types sections"));
22098 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
22101 if (stat (objfile_name (objfile
), &st
) < 0)
22102 perror_with_name (objfile_name (objfile
));
22104 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile_name (objfile
)),
22105 INDEX_SUFFIX
, (char *) NULL
);
22106 cleanup
= make_cleanup (xfree
, filename
);
22108 out_file
= gdb_fopen_cloexec (filename
, "wb");
22110 error (_("Can't open `%s' for writing"), filename
);
22112 cleanup_filename
= filename
;
22113 make_cleanup (unlink_if_set
, &cleanup_filename
);
22115 symtab
= create_mapped_symtab ();
22116 make_cleanup (cleanup_mapped_symtab
, symtab
);
22118 obstack_init (&addr_obstack
);
22119 make_cleanup_obstack_free (&addr_obstack
);
22121 obstack_init (&cu_list
);
22122 make_cleanup_obstack_free (&cu_list
);
22124 obstack_init (&types_cu_list
);
22125 make_cleanup_obstack_free (&types_cu_list
);
22127 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
22128 NULL
, xcalloc
, xfree
);
22129 make_cleanup_htab_delete (psyms_seen
);
22131 /* While we're scanning CU's create a table that maps a psymtab pointer
22132 (which is what addrmap records) to its index (which is what is recorded
22133 in the index file). This will later be needed to write the address
22135 cu_index_htab
= htab_create_alloc (100,
22136 hash_psymtab_cu_index
,
22137 eq_psymtab_cu_index
,
22138 NULL
, xcalloc
, xfree
);
22139 make_cleanup_htab_delete (cu_index_htab
);
22140 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
22141 xmalloc (sizeof (struct psymtab_cu_index_map
)
22142 * dwarf2_per_objfile
->n_comp_units
);
22143 make_cleanup (xfree
, psymtab_cu_index_map
);
22145 /* The CU list is already sorted, so we don't need to do additional
22146 work here. Also, the debug_types entries do not appear in
22147 all_comp_units, but only in their own hash table. */
22148 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
22150 struct dwarf2_per_cu_data
*per_cu
22151 = dwarf2_per_objfile
->all_comp_units
[i
];
22152 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
22154 struct psymtab_cu_index_map
*map
;
22157 /* CU of a shared file from 'dwz -m' may be unused by this main file.
22158 It may be referenced from a local scope but in such case it does not
22159 need to be present in .gdb_index. */
22160 if (psymtab
== NULL
)
22163 if (psymtab
->user
== NULL
)
22164 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
22166 map
= &psymtab_cu_index_map
[i
];
22167 map
->psymtab
= psymtab
;
22169 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
22170 gdb_assert (slot
!= NULL
);
22171 gdb_assert (*slot
== NULL
);
22174 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
22175 per_cu
->offset
.sect_off
);
22176 obstack_grow (&cu_list
, val
, 8);
22177 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
22178 obstack_grow (&cu_list
, val
, 8);
22181 /* Dump the address map. */
22182 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
22184 /* Write out the .debug_type entries, if any. */
22185 if (dwarf2_per_objfile
->signatured_types
)
22187 struct signatured_type_index_data sig_data
;
22189 sig_data
.objfile
= objfile
;
22190 sig_data
.symtab
= symtab
;
22191 sig_data
.types_list
= &types_cu_list
;
22192 sig_data
.psyms_seen
= psyms_seen
;
22193 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
22194 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
22195 write_one_signatured_type
, &sig_data
);
22198 /* Now that we've processed all symbols we can shrink their cu_indices
22200 uniquify_cu_indices (symtab
);
22202 obstack_init (&constant_pool
);
22203 make_cleanup_obstack_free (&constant_pool
);
22204 obstack_init (&symtab_obstack
);
22205 make_cleanup_obstack_free (&symtab_obstack
);
22206 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
22208 obstack_init (&contents
);
22209 make_cleanup_obstack_free (&contents
);
22210 size_of_contents
= 6 * sizeof (offset_type
);
22211 total_len
= size_of_contents
;
22213 /* The version number. */
22214 val
= MAYBE_SWAP (8);
22215 obstack_grow (&contents
, &val
, sizeof (val
));
22217 /* The offset of the CU list from the start of the file. */
22218 val
= MAYBE_SWAP (total_len
);
22219 obstack_grow (&contents
, &val
, sizeof (val
));
22220 total_len
+= obstack_object_size (&cu_list
);
22222 /* The offset of the types CU list from the start of the file. */
22223 val
= MAYBE_SWAP (total_len
);
22224 obstack_grow (&contents
, &val
, sizeof (val
));
22225 total_len
+= obstack_object_size (&types_cu_list
);
22227 /* The offset of the address table from the start of the file. */
22228 val
= MAYBE_SWAP (total_len
);
22229 obstack_grow (&contents
, &val
, sizeof (val
));
22230 total_len
+= obstack_object_size (&addr_obstack
);
22232 /* The offset of the symbol table from the start of the file. */
22233 val
= MAYBE_SWAP (total_len
);
22234 obstack_grow (&contents
, &val
, sizeof (val
));
22235 total_len
+= obstack_object_size (&symtab_obstack
);
22237 /* The offset of the constant pool from the start of the file. */
22238 val
= MAYBE_SWAP (total_len
);
22239 obstack_grow (&contents
, &val
, sizeof (val
));
22240 total_len
+= obstack_object_size (&constant_pool
);
22242 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
22244 write_obstack (out_file
, &contents
);
22245 write_obstack (out_file
, &cu_list
);
22246 write_obstack (out_file
, &types_cu_list
);
22247 write_obstack (out_file
, &addr_obstack
);
22248 write_obstack (out_file
, &symtab_obstack
);
22249 write_obstack (out_file
, &constant_pool
);
22253 /* We want to keep the file, so we set cleanup_filename to NULL
22254 here. See unlink_if_set. */
22255 cleanup_filename
= NULL
;
22257 do_cleanups (cleanup
);
22260 /* Implementation of the `save gdb-index' command.
22262 Note that the file format used by this command is documented in the
22263 GDB manual. Any changes here must be documented there. */
22266 save_gdb_index_command (char *arg
, int from_tty
)
22268 struct objfile
*objfile
;
22271 error (_("usage: save gdb-index DIRECTORY"));
22273 ALL_OBJFILES (objfile
)
22277 /* If the objfile does not correspond to an actual file, skip it. */
22278 if (stat (objfile_name (objfile
), &st
) < 0)
22281 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
22282 if (dwarf2_per_objfile
)
22284 volatile struct gdb_exception except
;
22286 TRY_CATCH (except
, RETURN_MASK_ERROR
)
22288 write_psymtabs_to_index (objfile
, arg
);
22290 if (except
.reason
< 0)
22291 exception_fprintf (gdb_stderr
, except
,
22292 _("Error while writing index for `%s': "),
22293 objfile_name (objfile
));
22300 int dwarf2_always_disassemble
;
22303 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
22304 struct cmd_list_element
*c
, const char *value
)
22306 fprintf_filtered (file
,
22307 _("Whether to always disassemble "
22308 "DWARF expressions is %s.\n"),
22313 show_check_physname (struct ui_file
*file
, int from_tty
,
22314 struct cmd_list_element
*c
, const char *value
)
22316 fprintf_filtered (file
,
22317 _("Whether to check \"physname\" is %s.\n"),
22321 void _initialize_dwarf2_read (void);
22324 _initialize_dwarf2_read (void)
22326 struct cmd_list_element
*c
;
22328 dwarf2_objfile_data_key
22329 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
22331 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
22332 Set DWARF 2 specific variables.\n\
22333 Configure DWARF 2 variables such as the cache size"),
22334 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
22335 0/*allow-unknown*/, &maintenance_set_cmdlist
);
22337 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
22338 Show DWARF 2 specific variables\n\
22339 Show DWARF 2 variables such as the cache size"),
22340 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
22341 0/*allow-unknown*/, &maintenance_show_cmdlist
);
22343 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
22344 &dwarf2_max_cache_age
, _("\
22345 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
22346 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
22347 A higher limit means that cached compilation units will be stored\n\
22348 in memory longer, and more total memory will be used. Zero disables\n\
22349 caching, which can slow down startup."),
22351 show_dwarf2_max_cache_age
,
22352 &set_dwarf2_cmdlist
,
22353 &show_dwarf2_cmdlist
);
22355 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
22356 &dwarf2_always_disassemble
, _("\
22357 Set whether `info address' always disassembles DWARF expressions."), _("\
22358 Show whether `info address' always disassembles DWARF expressions."), _("\
22359 When enabled, DWARF expressions are always printed in an assembly-like\n\
22360 syntax. When disabled, expressions will be printed in a more\n\
22361 conversational style, when possible."),
22363 show_dwarf2_always_disassemble
,
22364 &set_dwarf2_cmdlist
,
22365 &show_dwarf2_cmdlist
);
22367 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
22368 Set debugging of the dwarf2 reader."), _("\
22369 Show debugging of the dwarf2 reader."), _("\
22370 When enabled, debugging messages are printed during dwarf2 reading\n\
22371 and symtab expansion."),
22374 &setdebuglist
, &showdebuglist
);
22376 add_setshow_zuinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
22377 Set debugging of the dwarf2 DIE reader."), _("\
22378 Show debugging of the dwarf2 DIE reader."), _("\
22379 When enabled (non-zero), DIEs are dumped after they are read in.\n\
22380 The value is the maximum depth to print."),
22383 &setdebuglist
, &showdebuglist
);
22385 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
22386 Set cross-checking of \"physname\" code against demangler."), _("\
22387 Show cross-checking of \"physname\" code against demangler."), _("\
22388 When enabled, GDB's internal \"physname\" code is checked against\n\
22390 NULL
, show_check_physname
,
22391 &setdebuglist
, &showdebuglist
);
22393 add_setshow_boolean_cmd ("use-deprecated-index-sections",
22394 no_class
, &use_deprecated_index_sections
, _("\
22395 Set whether to use deprecated gdb_index sections."), _("\
22396 Show whether to use deprecated gdb_index sections."), _("\
22397 When enabled, deprecated .gdb_index sections are used anyway.\n\
22398 Normally they are ignored either because of a missing feature or\n\
22399 performance issue.\n\
22400 Warning: This option must be enabled before gdb reads the file."),
22403 &setlist
, &showlist
);
22405 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
22407 Save a gdb-index file.\n\
22408 Usage: save gdb-index DIRECTORY"),
22410 set_cmd_completer (c
, filename_completer
);
22412 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
22413 &dwarf2_locexpr_funcs
);
22414 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
22415 &dwarf2_loclist_funcs
);
22417 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
22418 &dwarf2_block_frame_base_locexpr_funcs
);
22419 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
22420 &dwarf2_block_frame_base_loclist_funcs
);