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"));
7020 unsigned int off
= dwarf2_get_ref_die_offset (&attr
).sect_off
;
7021 const gdb_byte
*sibling_ptr
= buffer
+ off
;
7023 if (sibling_ptr
< info_ptr
)
7024 complaint (&symfile_complaints
,
7025 _("DW_AT_sibling points backwards"));
7031 /* If it isn't DW_AT_sibling, skip this attribute. */
7032 form
= abbrev
->attrs
[i
].form
;
7036 case DW_FORM_ref_addr
:
7037 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
7038 and later it is offset sized. */
7039 if (cu
->header
.version
== 2)
7040 info_ptr
+= cu
->header
.addr_size
;
7042 info_ptr
+= cu
->header
.offset_size
;
7044 case DW_FORM_GNU_ref_alt
:
7045 info_ptr
+= cu
->header
.offset_size
;
7048 info_ptr
+= cu
->header
.addr_size
;
7055 case DW_FORM_flag_present
:
7067 case DW_FORM_ref_sig8
:
7070 case DW_FORM_string
:
7071 read_direct_string (abfd
, info_ptr
, &bytes_read
);
7072 info_ptr
+= bytes_read
;
7074 case DW_FORM_sec_offset
:
7076 case DW_FORM_GNU_strp_alt
:
7077 info_ptr
+= cu
->header
.offset_size
;
7079 case DW_FORM_exprloc
:
7081 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7082 info_ptr
+= bytes_read
;
7084 case DW_FORM_block1
:
7085 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
7087 case DW_FORM_block2
:
7088 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
7090 case DW_FORM_block4
:
7091 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
7095 case DW_FORM_ref_udata
:
7096 case DW_FORM_GNU_addr_index
:
7097 case DW_FORM_GNU_str_index
:
7098 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
7100 case DW_FORM_indirect
:
7101 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7102 info_ptr
+= bytes_read
;
7103 /* We need to continue parsing from here, so just go back to
7105 goto skip_attribute
;
7108 error (_("Dwarf Error: Cannot handle %s "
7109 "in DWARF reader [in module %s]"),
7110 dwarf_form_name (form
),
7111 bfd_get_filename (abfd
));
7115 if (abbrev
->has_children
)
7116 return skip_children (reader
, info_ptr
);
7121 /* Locate ORIG_PDI's sibling.
7122 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
7124 static const gdb_byte
*
7125 locate_pdi_sibling (const struct die_reader_specs
*reader
,
7126 struct partial_die_info
*orig_pdi
,
7127 const gdb_byte
*info_ptr
)
7129 /* Do we know the sibling already? */
7131 if (orig_pdi
->sibling
)
7132 return orig_pdi
->sibling
;
7134 /* Are there any children to deal with? */
7136 if (!orig_pdi
->has_children
)
7139 /* Skip the children the long way. */
7141 return skip_children (reader
, info_ptr
);
7144 /* Expand this partial symbol table into a full symbol table. SELF is
7148 dwarf2_read_symtab (struct partial_symtab
*self
,
7149 struct objfile
*objfile
)
7153 warning (_("bug: psymtab for %s is already read in."),
7160 printf_filtered (_("Reading in symbols for %s..."),
7162 gdb_flush (gdb_stdout
);
7165 /* Restore our global data. */
7166 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
7168 /* If this psymtab is constructed from a debug-only objfile, the
7169 has_section_at_zero flag will not necessarily be correct. We
7170 can get the correct value for this flag by looking at the data
7171 associated with the (presumably stripped) associated objfile. */
7172 if (objfile
->separate_debug_objfile_backlink
)
7174 struct dwarf2_per_objfile
*dpo_backlink
7175 = objfile_data (objfile
->separate_debug_objfile_backlink
,
7176 dwarf2_objfile_data_key
);
7178 dwarf2_per_objfile
->has_section_at_zero
7179 = dpo_backlink
->has_section_at_zero
;
7182 dwarf2_per_objfile
->reading_partial_symbols
= 0;
7184 psymtab_to_symtab_1 (self
);
7186 /* Finish up the debug error message. */
7188 printf_filtered (_("done.\n"));
7191 process_cu_includes ();
7194 /* Reading in full CUs. */
7196 /* Add PER_CU to the queue. */
7199 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
7200 enum language pretend_language
)
7202 struct dwarf2_queue_item
*item
;
7205 item
= xmalloc (sizeof (*item
));
7206 item
->per_cu
= per_cu
;
7207 item
->pretend_language
= pretend_language
;
7210 if (dwarf2_queue
== NULL
)
7211 dwarf2_queue
= item
;
7213 dwarf2_queue_tail
->next
= item
;
7215 dwarf2_queue_tail
= item
;
7218 /* If PER_CU is not yet queued, add it to the queue.
7219 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
7221 The result is non-zero if PER_CU was queued, otherwise the result is zero
7222 meaning either PER_CU is already queued or it is already loaded.
7224 N.B. There is an invariant here that if a CU is queued then it is loaded.
7225 The caller is required to load PER_CU if we return non-zero. */
7228 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
7229 struct dwarf2_per_cu_data
*per_cu
,
7230 enum language pretend_language
)
7232 /* We may arrive here during partial symbol reading, if we need full
7233 DIEs to process an unusual case (e.g. template arguments). Do
7234 not queue PER_CU, just tell our caller to load its DIEs. */
7235 if (dwarf2_per_objfile
->reading_partial_symbols
)
7237 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
7242 /* Mark the dependence relation so that we don't flush PER_CU
7244 if (dependent_cu
!= NULL
)
7245 dwarf2_add_dependence (dependent_cu
, per_cu
);
7247 /* If it's already on the queue, we have nothing to do. */
7251 /* If the compilation unit is already loaded, just mark it as
7253 if (per_cu
->cu
!= NULL
)
7255 per_cu
->cu
->last_used
= 0;
7259 /* Add it to the queue. */
7260 queue_comp_unit (per_cu
, pretend_language
);
7265 /* Process the queue. */
7268 process_queue (void)
7270 struct dwarf2_queue_item
*item
, *next_item
;
7272 if (dwarf2_read_debug
)
7274 fprintf_unfiltered (gdb_stdlog
,
7275 "Expanding one or more symtabs of objfile %s ...\n",
7276 objfile_name (dwarf2_per_objfile
->objfile
));
7279 /* The queue starts out with one item, but following a DIE reference
7280 may load a new CU, adding it to the end of the queue. */
7281 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
7283 if (dwarf2_per_objfile
->using_index
7284 ? !item
->per_cu
->v
.quick
->symtab
7285 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
7287 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
7290 if (per_cu
->is_debug_types
)
7292 struct signatured_type
*sig_type
=
7293 (struct signatured_type
*) per_cu
;
7295 sprintf (buf
, "TU %s at offset 0x%x",
7296 hex_string (sig_type
->signature
), per_cu
->offset
.sect_off
);
7299 sprintf (buf
, "CU at offset 0x%x", per_cu
->offset
.sect_off
);
7301 if (dwarf2_read_debug
)
7302 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
7304 if (per_cu
->is_debug_types
)
7305 process_full_type_unit (per_cu
, item
->pretend_language
);
7307 process_full_comp_unit (per_cu
, item
->pretend_language
);
7309 if (dwarf2_read_debug
)
7310 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
7313 item
->per_cu
->queued
= 0;
7314 next_item
= item
->next
;
7318 dwarf2_queue_tail
= NULL
;
7320 if (dwarf2_read_debug
)
7322 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
7323 objfile_name (dwarf2_per_objfile
->objfile
));
7327 /* Free all allocated queue entries. This function only releases anything if
7328 an error was thrown; if the queue was processed then it would have been
7329 freed as we went along. */
7332 dwarf2_release_queue (void *dummy
)
7334 struct dwarf2_queue_item
*item
, *last
;
7336 item
= dwarf2_queue
;
7339 /* Anything still marked queued is likely to be in an
7340 inconsistent state, so discard it. */
7341 if (item
->per_cu
->queued
)
7343 if (item
->per_cu
->cu
!= NULL
)
7344 free_one_cached_comp_unit (item
->per_cu
);
7345 item
->per_cu
->queued
= 0;
7353 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
7356 /* Read in full symbols for PST, and anything it depends on. */
7359 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
7361 struct dwarf2_per_cu_data
*per_cu
;
7367 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
7368 if (!pst
->dependencies
[i
]->readin
7369 && pst
->dependencies
[i
]->user
== NULL
)
7371 /* Inform about additional files that need to be read in. */
7374 /* FIXME: i18n: Need to make this a single string. */
7375 fputs_filtered (" ", gdb_stdout
);
7377 fputs_filtered ("and ", gdb_stdout
);
7379 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
7380 wrap_here (""); /* Flush output. */
7381 gdb_flush (gdb_stdout
);
7383 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
7386 per_cu
= pst
->read_symtab_private
;
7390 /* It's an include file, no symbols to read for it.
7391 Everything is in the parent symtab. */
7396 dw2_do_instantiate_symtab (per_cu
);
7399 /* Trivial hash function for die_info: the hash value of a DIE
7400 is its offset in .debug_info for this objfile. */
7403 die_hash (const void *item
)
7405 const struct die_info
*die
= item
;
7407 return die
->offset
.sect_off
;
7410 /* Trivial comparison function for die_info structures: two DIEs
7411 are equal if they have the same offset. */
7414 die_eq (const void *item_lhs
, const void *item_rhs
)
7416 const struct die_info
*die_lhs
= item_lhs
;
7417 const struct die_info
*die_rhs
= item_rhs
;
7419 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
7422 /* die_reader_func for load_full_comp_unit.
7423 This is identical to read_signatured_type_reader,
7424 but is kept separate for now. */
7427 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
7428 const gdb_byte
*info_ptr
,
7429 struct die_info
*comp_unit_die
,
7433 struct dwarf2_cu
*cu
= reader
->cu
;
7434 enum language
*language_ptr
= data
;
7436 gdb_assert (cu
->die_hash
== NULL
);
7438 htab_create_alloc_ex (cu
->header
.length
/ 12,
7442 &cu
->comp_unit_obstack
,
7443 hashtab_obstack_allocate
,
7444 dummy_obstack_deallocate
);
7447 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
7448 &info_ptr
, comp_unit_die
);
7449 cu
->dies
= comp_unit_die
;
7450 /* comp_unit_die is not stored in die_hash, no need. */
7452 /* We try not to read any attributes in this function, because not
7453 all CUs needed for references have been loaded yet, and symbol
7454 table processing isn't initialized. But we have to set the CU language,
7455 or we won't be able to build types correctly.
7456 Similarly, if we do not read the producer, we can not apply
7457 producer-specific interpretation. */
7458 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
7461 /* Load the DIEs associated with PER_CU into memory. */
7464 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7465 enum language pretend_language
)
7467 gdb_assert (! this_cu
->is_debug_types
);
7469 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
7470 load_full_comp_unit_reader
, &pretend_language
);
7473 /* Add a DIE to the delayed physname list. */
7476 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
7477 const char *name
, struct die_info
*die
,
7478 struct dwarf2_cu
*cu
)
7480 struct delayed_method_info mi
;
7482 mi
.fnfield_index
= fnfield_index
;
7486 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
7489 /* A cleanup for freeing the delayed method list. */
7492 free_delayed_list (void *ptr
)
7494 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
7495 if (cu
->method_list
!= NULL
)
7497 VEC_free (delayed_method_info
, cu
->method_list
);
7498 cu
->method_list
= NULL
;
7502 /* Compute the physnames of any methods on the CU's method list.
7504 The computation of method physnames is delayed in order to avoid the
7505 (bad) condition that one of the method's formal parameters is of an as yet
7509 compute_delayed_physnames (struct dwarf2_cu
*cu
)
7512 struct delayed_method_info
*mi
;
7513 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
7515 const char *physname
;
7516 struct fn_fieldlist
*fn_flp
7517 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
7518 physname
= dwarf2_physname (mi
->name
, mi
->die
, cu
);
7519 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
7523 /* Go objects should be embedded in a DW_TAG_module DIE,
7524 and it's not clear if/how imported objects will appear.
7525 To keep Go support simple until that's worked out,
7526 go back through what we've read and create something usable.
7527 We could do this while processing each DIE, and feels kinda cleaner,
7528 but that way is more invasive.
7529 This is to, for example, allow the user to type "p var" or "b main"
7530 without having to specify the package name, and allow lookups
7531 of module.object to work in contexts that use the expression
7535 fixup_go_packaging (struct dwarf2_cu
*cu
)
7537 char *package_name
= NULL
;
7538 struct pending
*list
;
7541 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
7543 for (i
= 0; i
< list
->nsyms
; ++i
)
7545 struct symbol
*sym
= list
->symbol
[i
];
7547 if (SYMBOL_LANGUAGE (sym
) == language_go
7548 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
7550 char *this_package_name
= go_symbol_package_name (sym
);
7552 if (this_package_name
== NULL
)
7554 if (package_name
== NULL
)
7555 package_name
= this_package_name
;
7558 if (strcmp (package_name
, this_package_name
) != 0)
7559 complaint (&symfile_complaints
,
7560 _("Symtab %s has objects from two different Go packages: %s and %s"),
7561 (SYMBOL_SYMTAB (sym
)
7562 ? symtab_to_filename_for_display (SYMBOL_SYMTAB (sym
))
7563 : objfile_name (cu
->objfile
)),
7564 this_package_name
, package_name
);
7565 xfree (this_package_name
);
7571 if (package_name
!= NULL
)
7573 struct objfile
*objfile
= cu
->objfile
;
7574 const char *saved_package_name
= obstack_copy0 (&objfile
->objfile_obstack
,
7576 strlen (package_name
));
7577 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
7578 saved_package_name
, objfile
);
7581 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7583 sym
= allocate_symbol (objfile
);
7584 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
7585 SYMBOL_SET_NAMES (sym
, saved_package_name
,
7586 strlen (saved_package_name
), 0, objfile
);
7587 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
7588 e.g., "main" finds the "main" module and not C's main(). */
7589 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7590 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
7591 SYMBOL_TYPE (sym
) = type
;
7593 add_symbol_to_list (sym
, &global_symbols
);
7595 xfree (package_name
);
7599 /* Return the symtab for PER_CU. This works properly regardless of
7600 whether we're using the index or psymtabs. */
7602 static struct symtab
*
7603 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
7605 return (dwarf2_per_objfile
->using_index
7606 ? per_cu
->v
.quick
->symtab
7607 : per_cu
->v
.psymtab
->symtab
);
7610 /* A helper function for computing the list of all symbol tables
7611 included by PER_CU. */
7614 recursively_compute_inclusions (VEC (symtab_ptr
) **result
,
7615 htab_t all_children
, htab_t all_type_symtabs
,
7616 struct dwarf2_per_cu_data
*per_cu
,
7617 struct symtab
*immediate_parent
)
7621 struct symtab
*symtab
;
7622 struct dwarf2_per_cu_data
*iter
;
7624 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
7627 /* This inclusion and its children have been processed. */
7632 /* Only add a CU if it has a symbol table. */
7633 symtab
= get_symtab (per_cu
);
7636 /* If this is a type unit only add its symbol table if we haven't
7637 seen it yet (type unit per_cu's can share symtabs). */
7638 if (per_cu
->is_debug_types
)
7640 slot
= htab_find_slot (all_type_symtabs
, symtab
, INSERT
);
7644 VEC_safe_push (symtab_ptr
, *result
, symtab
);
7645 if (symtab
->user
== NULL
)
7646 symtab
->user
= immediate_parent
;
7651 VEC_safe_push (symtab_ptr
, *result
, symtab
);
7652 if (symtab
->user
== NULL
)
7653 symtab
->user
= immediate_parent
;
7658 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
7661 recursively_compute_inclusions (result
, all_children
,
7662 all_type_symtabs
, iter
, symtab
);
7666 /* Compute the symtab 'includes' fields for the symtab related to
7670 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
7672 gdb_assert (! per_cu
->is_debug_types
);
7674 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
7677 struct dwarf2_per_cu_data
*per_cu_iter
;
7678 struct symtab
*symtab_iter
;
7679 VEC (symtab_ptr
) *result_symtabs
= NULL
;
7680 htab_t all_children
, all_type_symtabs
;
7681 struct symtab
*symtab
= get_symtab (per_cu
);
7683 /* If we don't have a symtab, we can just skip this case. */
7687 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
7688 NULL
, xcalloc
, xfree
);
7689 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
7690 NULL
, xcalloc
, xfree
);
7693 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
7697 recursively_compute_inclusions (&result_symtabs
, all_children
,
7698 all_type_symtabs
, per_cu_iter
,
7702 /* Now we have a transitive closure of all the included symtabs. */
7703 len
= VEC_length (symtab_ptr
, result_symtabs
);
7705 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
7706 (len
+ 1) * sizeof (struct symtab
*));
7708 VEC_iterate (symtab_ptr
, result_symtabs
, ix
, symtab_iter
);
7710 symtab
->includes
[ix
] = symtab_iter
;
7711 symtab
->includes
[len
] = NULL
;
7713 VEC_free (symtab_ptr
, result_symtabs
);
7714 htab_delete (all_children
);
7715 htab_delete (all_type_symtabs
);
7719 /* Compute the 'includes' field for the symtabs of all the CUs we just
7723 process_cu_includes (void)
7726 struct dwarf2_per_cu_data
*iter
;
7729 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
7733 if (! iter
->is_debug_types
)
7734 compute_symtab_includes (iter
);
7737 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
7740 /* Generate full symbol information for PER_CU, whose DIEs have
7741 already been loaded into memory. */
7744 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
7745 enum language pretend_language
)
7747 struct dwarf2_cu
*cu
= per_cu
->cu
;
7748 struct objfile
*objfile
= per_cu
->objfile
;
7749 CORE_ADDR lowpc
, highpc
;
7750 struct symtab
*symtab
;
7751 struct cleanup
*back_to
, *delayed_list_cleanup
;
7753 struct block
*static_block
;
7755 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7758 back_to
= make_cleanup (really_free_pendings
, NULL
);
7759 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
7761 cu
->list_in_scope
= &file_symbols
;
7763 cu
->language
= pretend_language
;
7764 cu
->language_defn
= language_def (cu
->language
);
7766 /* Do line number decoding in read_file_scope () */
7767 process_die (cu
->dies
, cu
);
7769 /* For now fudge the Go package. */
7770 if (cu
->language
== language_go
)
7771 fixup_go_packaging (cu
);
7773 /* Now that we have processed all the DIEs in the CU, all the types
7774 should be complete, and it should now be safe to compute all of the
7776 compute_delayed_physnames (cu
);
7777 do_cleanups (delayed_list_cleanup
);
7779 /* Some compilers don't define a DW_AT_high_pc attribute for the
7780 compilation unit. If the DW_AT_high_pc is missing, synthesize
7781 it, by scanning the DIE's below the compilation unit. */
7782 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
7785 = end_symtab_get_static_block (highpc
+ baseaddr
, objfile
, 0, 1);
7787 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
7788 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
7789 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
7790 addrmap to help ensure it has an accurate map of pc values belonging to
7792 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
7794 symtab
= end_symtab_from_static_block (static_block
, objfile
,
7795 SECT_OFF_TEXT (objfile
), 0);
7799 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
7801 /* Set symtab language to language from DW_AT_language. If the
7802 compilation is from a C file generated by language preprocessors, do
7803 not set the language if it was already deduced by start_subfile. */
7804 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
7805 symtab
->language
= cu
->language
;
7807 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
7808 produce DW_AT_location with location lists but it can be possibly
7809 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
7810 there were bugs in prologue debug info, fixed later in GCC-4.5
7811 by "unwind info for epilogues" patch (which is not directly related).
7813 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
7814 needed, it would be wrong due to missing DW_AT_producer there.
7816 Still one can confuse GDB by using non-standard GCC compilation
7817 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
7819 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
7820 symtab
->locations_valid
= 1;
7822 if (gcc_4_minor
>= 5)
7823 symtab
->epilogue_unwind_valid
= 1;
7825 symtab
->call_site_htab
= cu
->call_site_htab
;
7828 if (dwarf2_per_objfile
->using_index
)
7829 per_cu
->v
.quick
->symtab
= symtab
;
7832 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7833 pst
->symtab
= symtab
;
7837 /* Push it for inclusion processing later. */
7838 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
7840 do_cleanups (back_to
);
7843 /* Generate full symbol information for type unit PER_CU, whose DIEs have
7844 already been loaded into memory. */
7847 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
7848 enum language pretend_language
)
7850 struct dwarf2_cu
*cu
= per_cu
->cu
;
7851 struct objfile
*objfile
= per_cu
->objfile
;
7852 struct symtab
*symtab
;
7853 struct cleanup
*back_to
, *delayed_list_cleanup
;
7854 struct signatured_type
*sig_type
;
7856 gdb_assert (per_cu
->is_debug_types
);
7857 sig_type
= (struct signatured_type
*) per_cu
;
7860 back_to
= make_cleanup (really_free_pendings
, NULL
);
7861 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
7863 cu
->list_in_scope
= &file_symbols
;
7865 cu
->language
= pretend_language
;
7866 cu
->language_defn
= language_def (cu
->language
);
7868 /* The symbol tables are set up in read_type_unit_scope. */
7869 process_die (cu
->dies
, cu
);
7871 /* For now fudge the Go package. */
7872 if (cu
->language
== language_go
)
7873 fixup_go_packaging (cu
);
7875 /* Now that we have processed all the DIEs in the CU, all the types
7876 should be complete, and it should now be safe to compute all of the
7878 compute_delayed_physnames (cu
);
7879 do_cleanups (delayed_list_cleanup
);
7881 /* TUs share symbol tables.
7882 If this is the first TU to use this symtab, complete the construction
7883 of it with end_expandable_symtab. Otherwise, complete the addition of
7884 this TU's symbols to the existing symtab. */
7885 if (sig_type
->type_unit_group
->primary_symtab
== NULL
)
7887 symtab
= end_expandable_symtab (0, objfile
, SECT_OFF_TEXT (objfile
));
7888 sig_type
->type_unit_group
->primary_symtab
= symtab
;
7892 /* Set symtab language to language from DW_AT_language. If the
7893 compilation is from a C file generated by language preprocessors,
7894 do not set the language if it was already deduced by
7896 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
7897 symtab
->language
= cu
->language
;
7902 augment_type_symtab (objfile
,
7903 sig_type
->type_unit_group
->primary_symtab
);
7904 symtab
= sig_type
->type_unit_group
->primary_symtab
;
7907 if (dwarf2_per_objfile
->using_index
)
7908 per_cu
->v
.quick
->symtab
= symtab
;
7911 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7912 pst
->symtab
= symtab
;
7916 do_cleanups (back_to
);
7919 /* Process an imported unit DIE. */
7922 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7924 struct attribute
*attr
;
7926 /* For now we don't handle imported units in type units. */
7927 if (cu
->per_cu
->is_debug_types
)
7929 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7930 " supported in type units [in module %s]"),
7931 objfile_name (cu
->objfile
));
7934 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7937 struct dwarf2_per_cu_data
*per_cu
;
7938 struct symtab
*imported_symtab
;
7942 offset
= dwarf2_get_ref_die_offset (attr
);
7943 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
7944 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
7946 /* If necessary, add it to the queue and load its DIEs. */
7947 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
7948 load_full_comp_unit (per_cu
, cu
->language
);
7950 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
7955 /* Process a die and its children. */
7958 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7962 case DW_TAG_padding
:
7964 case DW_TAG_compile_unit
:
7965 case DW_TAG_partial_unit
:
7966 read_file_scope (die
, cu
);
7968 case DW_TAG_type_unit
:
7969 read_type_unit_scope (die
, cu
);
7971 case DW_TAG_subprogram
:
7972 case DW_TAG_inlined_subroutine
:
7973 read_func_scope (die
, cu
);
7975 case DW_TAG_lexical_block
:
7976 case DW_TAG_try_block
:
7977 case DW_TAG_catch_block
:
7978 read_lexical_block_scope (die
, cu
);
7980 case DW_TAG_GNU_call_site
:
7981 read_call_site_scope (die
, cu
);
7983 case DW_TAG_class_type
:
7984 case DW_TAG_interface_type
:
7985 case DW_TAG_structure_type
:
7986 case DW_TAG_union_type
:
7987 process_structure_scope (die
, cu
);
7989 case DW_TAG_enumeration_type
:
7990 process_enumeration_scope (die
, cu
);
7993 /* These dies have a type, but processing them does not create
7994 a symbol or recurse to process the children. Therefore we can
7995 read them on-demand through read_type_die. */
7996 case DW_TAG_subroutine_type
:
7997 case DW_TAG_set_type
:
7998 case DW_TAG_array_type
:
7999 case DW_TAG_pointer_type
:
8000 case DW_TAG_ptr_to_member_type
:
8001 case DW_TAG_reference_type
:
8002 case DW_TAG_string_type
:
8005 case DW_TAG_base_type
:
8006 case DW_TAG_subrange_type
:
8007 case DW_TAG_typedef
:
8008 /* Add a typedef symbol for the type definition, if it has a
8010 new_symbol (die
, read_type_die (die
, cu
), cu
);
8012 case DW_TAG_common_block
:
8013 read_common_block (die
, cu
);
8015 case DW_TAG_common_inclusion
:
8017 case DW_TAG_namespace
:
8018 cu
->processing_has_namespace_info
= 1;
8019 read_namespace (die
, cu
);
8022 cu
->processing_has_namespace_info
= 1;
8023 read_module (die
, cu
);
8025 case DW_TAG_imported_declaration
:
8026 case DW_TAG_imported_module
:
8027 cu
->processing_has_namespace_info
= 1;
8028 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
8029 || cu
->language
!= language_fortran
))
8030 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
8031 dwarf_tag_name (die
->tag
));
8032 read_import_statement (die
, cu
);
8035 case DW_TAG_imported_unit
:
8036 process_imported_unit_die (die
, cu
);
8040 new_symbol (die
, NULL
, cu
);
8045 /* DWARF name computation. */
8047 /* A helper function for dwarf2_compute_name which determines whether DIE
8048 needs to have the name of the scope prepended to the name listed in the
8052 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8054 struct attribute
*attr
;
8058 case DW_TAG_namespace
:
8059 case DW_TAG_typedef
:
8060 case DW_TAG_class_type
:
8061 case DW_TAG_interface_type
:
8062 case DW_TAG_structure_type
:
8063 case DW_TAG_union_type
:
8064 case DW_TAG_enumeration_type
:
8065 case DW_TAG_enumerator
:
8066 case DW_TAG_subprogram
:
8070 case DW_TAG_variable
:
8071 case DW_TAG_constant
:
8072 /* We only need to prefix "globally" visible variables. These include
8073 any variable marked with DW_AT_external or any variable that
8074 lives in a namespace. [Variables in anonymous namespaces
8075 require prefixing, but they are not DW_AT_external.] */
8077 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
8079 struct dwarf2_cu
*spec_cu
= cu
;
8081 return die_needs_namespace (die_specification (die
, &spec_cu
),
8085 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8086 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
8087 && die
->parent
->tag
!= DW_TAG_module
)
8089 /* A variable in a lexical block of some kind does not need a
8090 namespace, even though in C++ such variables may be external
8091 and have a mangled name. */
8092 if (die
->parent
->tag
== DW_TAG_lexical_block
8093 || die
->parent
->tag
== DW_TAG_try_block
8094 || die
->parent
->tag
== DW_TAG_catch_block
8095 || die
->parent
->tag
== DW_TAG_subprogram
)
8104 /* Retrieve the last character from a mem_file. */
8107 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
8109 char *last_char_p
= (char *) object
;
8112 *last_char_p
= buffer
[length
- 1];
8115 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
8116 compute the physname for the object, which include a method's:
8117 - formal parameters (C++/Java),
8118 - receiver type (Go),
8119 - return type (Java).
8121 The term "physname" is a bit confusing.
8122 For C++, for example, it is the demangled name.
8123 For Go, for example, it's the mangled name.
8125 For Ada, return the DIE's linkage name rather than the fully qualified
8126 name. PHYSNAME is ignored..
8128 The result is allocated on the objfile_obstack and canonicalized. */
8131 dwarf2_compute_name (const char *name
,
8132 struct die_info
*die
, struct dwarf2_cu
*cu
,
8135 struct objfile
*objfile
= cu
->objfile
;
8138 name
= dwarf2_name (die
, cu
);
8140 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
8141 compute it by typename_concat inside GDB. */
8142 if (cu
->language
== language_ada
8143 || (cu
->language
== language_fortran
&& physname
))
8145 /* For Ada unit, we prefer the linkage name over the name, as
8146 the former contains the exported name, which the user expects
8147 to be able to reference. Ideally, we want the user to be able
8148 to reference this entity using either natural or linkage name,
8149 but we haven't started looking at this enhancement yet. */
8150 struct attribute
*attr
;
8152 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
8154 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8155 if (attr
&& DW_STRING (attr
))
8156 return DW_STRING (attr
);
8159 /* These are the only languages we know how to qualify names in. */
8161 && (cu
->language
== language_cplus
|| cu
->language
== language_java
8162 || cu
->language
== language_fortran
))
8164 if (die_needs_namespace (die
, cu
))
8168 struct ui_file
*buf
;
8170 prefix
= determine_prefix (die
, cu
);
8171 buf
= mem_fileopen ();
8172 if (*prefix
!= '\0')
8174 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
8177 fputs_unfiltered (prefixed_name
, buf
);
8178 xfree (prefixed_name
);
8181 fputs_unfiltered (name
, buf
);
8183 /* Template parameters may be specified in the DIE's DW_AT_name, or
8184 as children with DW_TAG_template_type_param or
8185 DW_TAG_value_type_param. If the latter, add them to the name
8186 here. If the name already has template parameters, then
8187 skip this step; some versions of GCC emit both, and
8188 it is more efficient to use the pre-computed name.
8190 Something to keep in mind about this process: it is very
8191 unlikely, or in some cases downright impossible, to produce
8192 something that will match the mangled name of a function.
8193 If the definition of the function has the same debug info,
8194 we should be able to match up with it anyway. But fallbacks
8195 using the minimal symbol, for instance to find a method
8196 implemented in a stripped copy of libstdc++, will not work.
8197 If we do not have debug info for the definition, we will have to
8198 match them up some other way.
8200 When we do name matching there is a related problem with function
8201 templates; two instantiated function templates are allowed to
8202 differ only by their return types, which we do not add here. */
8204 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
8206 struct attribute
*attr
;
8207 struct die_info
*child
;
8210 die
->building_fullname
= 1;
8212 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
8216 const gdb_byte
*bytes
;
8217 struct dwarf2_locexpr_baton
*baton
;
8220 if (child
->tag
!= DW_TAG_template_type_param
8221 && child
->tag
!= DW_TAG_template_value_param
)
8226 fputs_unfiltered ("<", buf
);
8230 fputs_unfiltered (", ", buf
);
8232 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
8235 complaint (&symfile_complaints
,
8236 _("template parameter missing DW_AT_type"));
8237 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
8240 type
= die_type (child
, cu
);
8242 if (child
->tag
== DW_TAG_template_type_param
)
8244 c_print_type (type
, "", buf
, -1, 0, &type_print_raw_options
);
8248 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
8251 complaint (&symfile_complaints
,
8252 _("template parameter missing "
8253 "DW_AT_const_value"));
8254 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
8258 dwarf2_const_value_attr (attr
, type
, name
,
8259 &cu
->comp_unit_obstack
, cu
,
8260 &value
, &bytes
, &baton
);
8262 if (TYPE_NOSIGN (type
))
8263 /* GDB prints characters as NUMBER 'CHAR'. If that's
8264 changed, this can use value_print instead. */
8265 c_printchar (value
, type
, buf
);
8268 struct value_print_options opts
;
8271 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
8275 else if (bytes
!= NULL
)
8277 v
= allocate_value (type
);
8278 memcpy (value_contents_writeable (v
), bytes
,
8279 TYPE_LENGTH (type
));
8282 v
= value_from_longest (type
, value
);
8284 /* Specify decimal so that we do not depend on
8286 get_formatted_print_options (&opts
, 'd');
8288 value_print (v
, buf
, &opts
);
8294 die
->building_fullname
= 0;
8298 /* Close the argument list, with a space if necessary
8299 (nested templates). */
8300 char last_char
= '\0';
8301 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
8302 if (last_char
== '>')
8303 fputs_unfiltered (" >", buf
);
8305 fputs_unfiltered (">", buf
);
8309 /* For Java and C++ methods, append formal parameter type
8310 information, if PHYSNAME. */
8312 if (physname
&& die
->tag
== DW_TAG_subprogram
8313 && (cu
->language
== language_cplus
8314 || cu
->language
== language_java
))
8316 struct type
*type
= read_type_die (die
, cu
);
8318 c_type_print_args (type
, buf
, 1, cu
->language
,
8319 &type_print_raw_options
);
8321 if (cu
->language
== language_java
)
8323 /* For java, we must append the return type to method
8325 if (die
->tag
== DW_TAG_subprogram
)
8326 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
8327 0, 0, &type_print_raw_options
);
8329 else if (cu
->language
== language_cplus
)
8331 /* Assume that an artificial first parameter is
8332 "this", but do not crash if it is not. RealView
8333 marks unnamed (and thus unused) parameters as
8334 artificial; there is no way to differentiate
8336 if (TYPE_NFIELDS (type
) > 0
8337 && TYPE_FIELD_ARTIFICIAL (type
, 0)
8338 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
8339 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
8341 fputs_unfiltered (" const", buf
);
8345 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
8347 ui_file_delete (buf
);
8349 if (cu
->language
== language_cplus
)
8352 = dwarf2_canonicalize_name (name
, cu
,
8353 &objfile
->objfile_obstack
);
8364 /* Return the fully qualified name of DIE, based on its DW_AT_name.
8365 If scope qualifiers are appropriate they will be added. The result
8366 will be allocated on the objfile_obstack, or NULL if the DIE does
8367 not have a name. NAME may either be from a previous call to
8368 dwarf2_name or NULL.
8370 The output string will be canonicalized (if C++/Java). */
8373 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8375 return dwarf2_compute_name (name
, die
, cu
, 0);
8378 /* Construct a physname for the given DIE in CU. NAME may either be
8379 from a previous call to dwarf2_name or NULL. The result will be
8380 allocated on the objfile_objstack or NULL if the DIE does not have a
8383 The output string will be canonicalized (if C++/Java). */
8386 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8388 struct objfile
*objfile
= cu
->objfile
;
8389 struct attribute
*attr
;
8390 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
8391 struct cleanup
*back_to
;
8394 /* In this case dwarf2_compute_name is just a shortcut not building anything
8396 if (!die_needs_namespace (die
, cu
))
8397 return dwarf2_compute_name (name
, die
, cu
, 1);
8399 back_to
= make_cleanup (null_cleanup
, NULL
);
8401 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
8403 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8405 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
8407 if (attr
&& DW_STRING (attr
))
8411 mangled
= DW_STRING (attr
);
8413 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
8414 type. It is easier for GDB users to search for such functions as
8415 `name(params)' than `long name(params)'. In such case the minimal
8416 symbol names do not match the full symbol names but for template
8417 functions there is never a need to look up their definition from their
8418 declaration so the only disadvantage remains the minimal symbol
8419 variant `long name(params)' does not have the proper inferior type.
8422 if (cu
->language
== language_go
)
8424 /* This is a lie, but we already lie to the caller new_symbol_full.
8425 new_symbol_full assumes we return the mangled name.
8426 This just undoes that lie until things are cleaned up. */
8431 demangled
= gdb_demangle (mangled
,
8432 (DMGL_PARAMS
| DMGL_ANSI
8433 | (cu
->language
== language_java
8434 ? DMGL_JAVA
| DMGL_RET_POSTFIX
8439 make_cleanup (xfree
, demangled
);
8449 if (canon
== NULL
|| check_physname
)
8451 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
8453 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
8455 /* It may not mean a bug in GDB. The compiler could also
8456 compute DW_AT_linkage_name incorrectly. But in such case
8457 GDB would need to be bug-to-bug compatible. */
8459 complaint (&symfile_complaints
,
8460 _("Computed physname <%s> does not match demangled <%s> "
8461 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
8462 physname
, canon
, mangled
, die
->offset
.sect_off
,
8463 objfile_name (objfile
));
8465 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
8466 is available here - over computed PHYSNAME. It is safer
8467 against both buggy GDB and buggy compilers. */
8481 retval
= obstack_copy0 (&objfile
->objfile_obstack
, retval
, strlen (retval
));
8483 do_cleanups (back_to
);
8487 /* Read the import statement specified by the given die and record it. */
8490 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
8492 struct objfile
*objfile
= cu
->objfile
;
8493 struct attribute
*import_attr
;
8494 struct die_info
*imported_die
, *child_die
;
8495 struct dwarf2_cu
*imported_cu
;
8496 const char *imported_name
;
8497 const char *imported_name_prefix
;
8498 const char *canonical_name
;
8499 const char *import_alias
;
8500 const char *imported_declaration
= NULL
;
8501 const char *import_prefix
;
8502 VEC (const_char_ptr
) *excludes
= NULL
;
8503 struct cleanup
*cleanups
;
8505 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8506 if (import_attr
== NULL
)
8508 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
8509 dwarf_tag_name (die
->tag
));
8514 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
8515 imported_name
= dwarf2_name (imported_die
, imported_cu
);
8516 if (imported_name
== NULL
)
8518 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
8520 The import in the following code:
8534 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
8535 <52> DW_AT_decl_file : 1
8536 <53> DW_AT_decl_line : 6
8537 <54> DW_AT_import : <0x75>
8538 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
8540 <5b> DW_AT_decl_file : 1
8541 <5c> DW_AT_decl_line : 2
8542 <5d> DW_AT_type : <0x6e>
8544 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
8545 <76> DW_AT_byte_size : 4
8546 <77> DW_AT_encoding : 5 (signed)
8548 imports the wrong die ( 0x75 instead of 0x58 ).
8549 This case will be ignored until the gcc bug is fixed. */
8553 /* Figure out the local name after import. */
8554 import_alias
= dwarf2_name (die
, cu
);
8556 /* Figure out where the statement is being imported to. */
8557 import_prefix
= determine_prefix (die
, cu
);
8559 /* Figure out what the scope of the imported die is and prepend it
8560 to the name of the imported die. */
8561 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
8563 if (imported_die
->tag
!= DW_TAG_namespace
8564 && imported_die
->tag
!= DW_TAG_module
)
8566 imported_declaration
= imported_name
;
8567 canonical_name
= imported_name_prefix
;
8569 else if (strlen (imported_name_prefix
) > 0)
8570 canonical_name
= obconcat (&objfile
->objfile_obstack
,
8571 imported_name_prefix
, "::", imported_name
,
8574 canonical_name
= imported_name
;
8576 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
8578 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
8579 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
8580 child_die
= sibling_die (child_die
))
8582 /* DWARF-4: A Fortran use statement with a “rename list” may be
8583 represented by an imported module entry with an import attribute
8584 referring to the module and owned entries corresponding to those
8585 entities that are renamed as part of being imported. */
8587 if (child_die
->tag
!= DW_TAG_imported_declaration
)
8589 complaint (&symfile_complaints
,
8590 _("child DW_TAG_imported_declaration expected "
8591 "- DIE at 0x%x [in module %s]"),
8592 child_die
->offset
.sect_off
, objfile_name (objfile
));
8596 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
8597 if (import_attr
== NULL
)
8599 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
8600 dwarf_tag_name (child_die
->tag
));
8605 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
8607 imported_name
= dwarf2_name (imported_die
, imported_cu
);
8608 if (imported_name
== NULL
)
8610 complaint (&symfile_complaints
,
8611 _("child DW_TAG_imported_declaration has unknown "
8612 "imported name - DIE at 0x%x [in module %s]"),
8613 child_die
->offset
.sect_off
, objfile_name (objfile
));
8617 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
8619 process_die (child_die
, cu
);
8622 cp_add_using_directive (import_prefix
,
8625 imported_declaration
,
8628 &objfile
->objfile_obstack
);
8630 do_cleanups (cleanups
);
8633 /* Cleanup function for handle_DW_AT_stmt_list. */
8636 free_cu_line_header (void *arg
)
8638 struct dwarf2_cu
*cu
= arg
;
8640 free_line_header (cu
->line_header
);
8641 cu
->line_header
= NULL
;
8644 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
8645 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
8646 this, it was first present in GCC release 4.3.0. */
8649 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
8651 if (!cu
->checked_producer
)
8652 check_producer (cu
);
8654 return cu
->producer_is_gcc_lt_4_3
;
8658 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
8659 const char **name
, const char **comp_dir
)
8661 struct attribute
*attr
;
8666 /* Find the filename. Do not use dwarf2_name here, since the filename
8667 is not a source language identifier. */
8668 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8671 *name
= DW_STRING (attr
);
8674 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
8676 *comp_dir
= DW_STRING (attr
);
8677 else if (producer_is_gcc_lt_4_3 (cu
) && *name
!= NULL
8678 && IS_ABSOLUTE_PATH (*name
))
8680 char *d
= ldirname (*name
);
8684 make_cleanup (xfree
, d
);
8686 if (*comp_dir
!= NULL
)
8688 /* Irix 6.2 native cc prepends <machine>.: to the compilation
8689 directory, get rid of it. */
8690 char *cp
= strchr (*comp_dir
, ':');
8692 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
8697 *name
= "<unknown>";
8700 /* Handle DW_AT_stmt_list for a compilation unit.
8701 DIE is the DW_TAG_compile_unit die for CU.
8702 COMP_DIR is the compilation directory.
8703 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
8706 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
8707 const char *comp_dir
) /* ARI: editCase function */
8709 struct attribute
*attr
;
8711 gdb_assert (! cu
->per_cu
->is_debug_types
);
8713 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
8716 unsigned int line_offset
= DW_UNSND (attr
);
8717 struct line_header
*line_header
8718 = dwarf_decode_line_header (line_offset
, cu
);
8722 cu
->line_header
= line_header
;
8723 make_cleanup (free_cu_line_header
, cu
);
8724 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, 1);
8729 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
8732 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8734 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8735 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
8736 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
8737 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
8738 struct attribute
*attr
;
8739 const char *name
= NULL
;
8740 const char *comp_dir
= NULL
;
8741 struct die_info
*child_die
;
8742 bfd
*abfd
= objfile
->obfd
;
8745 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8747 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
8749 /* If we didn't find a lowpc, set it to highpc to avoid complaints
8750 from finish_block. */
8751 if (lowpc
== ((CORE_ADDR
) -1))
8756 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
8758 prepare_one_comp_unit (cu
, die
, cu
->language
);
8760 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
8761 standardised yet. As a workaround for the language detection we fall
8762 back to the DW_AT_producer string. */
8763 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
8764 cu
->language
= language_opencl
;
8766 /* Similar hack for Go. */
8767 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
8768 set_cu_language (DW_LANG_Go
, cu
);
8770 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
8772 /* Decode line number information if present. We do this before
8773 processing child DIEs, so that the line header table is available
8774 for DW_AT_decl_file. */
8775 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
8777 /* Process all dies in compilation unit. */
8778 if (die
->child
!= NULL
)
8780 child_die
= die
->child
;
8781 while (child_die
&& child_die
->tag
)
8783 process_die (child_die
, cu
);
8784 child_die
= sibling_die (child_die
);
8788 /* Decode macro information, if present. Dwarf 2 macro information
8789 refers to information in the line number info statement program
8790 header, so we can only read it if we've read the header
8792 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
8793 if (attr
&& cu
->line_header
)
8795 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
8796 complaint (&symfile_complaints
,
8797 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
8799 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
8803 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
8804 if (attr
&& cu
->line_header
)
8806 unsigned int macro_offset
= DW_UNSND (attr
);
8808 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
8812 do_cleanups (back_to
);
8815 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
8816 Create the set of symtabs used by this TU, or if this TU is sharing
8817 symtabs with another TU and the symtabs have already been created
8818 then restore those symtabs in the line header.
8819 We don't need the pc/line-number mapping for type units. */
8822 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
8824 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8825 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8826 struct type_unit_group
*tu_group
;
8828 struct line_header
*lh
;
8829 struct attribute
*attr
;
8830 unsigned int i
, line_offset
;
8831 struct signatured_type
*sig_type
;
8833 gdb_assert (per_cu
->is_debug_types
);
8834 sig_type
= (struct signatured_type
*) per_cu
;
8836 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
8838 /* If we're using .gdb_index (includes -readnow) then
8839 per_cu->type_unit_group may not have been set up yet. */
8840 if (sig_type
->type_unit_group
== NULL
)
8841 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
8842 tu_group
= sig_type
->type_unit_group
;
8844 /* If we've already processed this stmt_list there's no real need to
8845 do it again, we could fake it and just recreate the part we need
8846 (file name,index -> symtab mapping). If data shows this optimization
8847 is useful we can do it then. */
8848 first_time
= tu_group
->primary_symtab
== NULL
;
8850 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
8855 line_offset
= DW_UNSND (attr
);
8856 lh
= dwarf_decode_line_header (line_offset
, cu
);
8861 dwarf2_start_symtab (cu
, "", NULL
, 0);
8864 gdb_assert (tu_group
->symtabs
== NULL
);
8867 /* Note: The primary symtab will get allocated at the end. */
8871 cu
->line_header
= lh
;
8872 make_cleanup (free_cu_line_header
, cu
);
8876 dwarf2_start_symtab (cu
, "", NULL
, 0);
8878 tu_group
->num_symtabs
= lh
->num_file_names
;
8879 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
8881 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8883 const char *dir
= NULL
;
8884 struct file_entry
*fe
= &lh
->file_names
[i
];
8887 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8888 dwarf2_start_subfile (fe
->name
, dir
, NULL
);
8890 /* Note: We don't have to watch for the main subfile here, type units
8891 don't have DW_AT_name. */
8893 if (current_subfile
->symtab
== NULL
)
8895 /* NOTE: start_subfile will recognize when it's been passed
8896 a file it has already seen. So we can't assume there's a
8897 simple mapping from lh->file_names to subfiles,
8898 lh->file_names may contain dups. */
8899 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8903 fe
->symtab
= current_subfile
->symtab
;
8904 tu_group
->symtabs
[i
] = fe
->symtab
;
8911 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8913 struct file_entry
*fe
= &lh
->file_names
[i
];
8915 fe
->symtab
= tu_group
->symtabs
[i
];
8919 /* The main symtab is allocated last. Type units don't have DW_AT_name
8920 so they don't have a "real" (so to speak) symtab anyway.
8921 There is later code that will assign the main symtab to all symbols
8922 that don't have one. We need to handle the case of a symbol with a
8923 missing symtab (DW_AT_decl_file) anyway. */
8926 /* Process DW_TAG_type_unit.
8927 For TUs we want to skip the first top level sibling if it's not the
8928 actual type being defined by this TU. In this case the first top
8929 level sibling is there to provide context only. */
8932 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8934 struct die_info
*child_die
;
8936 prepare_one_comp_unit (cu
, die
, language_minimal
);
8938 /* Initialize (or reinitialize) the machinery for building symtabs.
8939 We do this before processing child DIEs, so that the line header table
8940 is available for DW_AT_decl_file. */
8941 setup_type_unit_groups (die
, cu
);
8943 if (die
->child
!= NULL
)
8945 child_die
= die
->child
;
8946 while (child_die
&& child_die
->tag
)
8948 process_die (child_die
, cu
);
8949 child_die
= sibling_die (child_die
);
8956 http://gcc.gnu.org/wiki/DebugFission
8957 http://gcc.gnu.org/wiki/DebugFissionDWP
8959 To simplify handling of both DWO files ("object" files with the DWARF info)
8960 and DWP files (a file with the DWOs packaged up into one file), we treat
8961 DWP files as having a collection of virtual DWO files. */
8964 hash_dwo_file (const void *item
)
8966 const struct dwo_file
*dwo_file
= item
;
8969 hash
= htab_hash_string (dwo_file
->dwo_name
);
8970 if (dwo_file
->comp_dir
!= NULL
)
8971 hash
+= htab_hash_string (dwo_file
->comp_dir
);
8976 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
8978 const struct dwo_file
*lhs
= item_lhs
;
8979 const struct dwo_file
*rhs
= item_rhs
;
8981 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
8983 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
8984 return lhs
->comp_dir
== rhs
->comp_dir
;
8985 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
8988 /* Allocate a hash table for DWO files. */
8991 allocate_dwo_file_hash_table (void)
8993 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8995 return htab_create_alloc_ex (41,
8999 &objfile
->objfile_obstack
,
9000 hashtab_obstack_allocate
,
9001 dummy_obstack_deallocate
);
9004 /* Lookup DWO file DWO_NAME. */
9007 lookup_dwo_file_slot (const char *dwo_name
, const char *comp_dir
)
9009 struct dwo_file find_entry
;
9012 if (dwarf2_per_objfile
->dwo_files
== NULL
)
9013 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
9015 memset (&find_entry
, 0, sizeof (find_entry
));
9016 find_entry
.dwo_name
= dwo_name
;
9017 find_entry
.comp_dir
= comp_dir
;
9018 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
9024 hash_dwo_unit (const void *item
)
9026 const struct dwo_unit
*dwo_unit
= item
;
9028 /* This drops the top 32 bits of the id, but is ok for a hash. */
9029 return dwo_unit
->signature
;
9033 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
9035 const struct dwo_unit
*lhs
= item_lhs
;
9036 const struct dwo_unit
*rhs
= item_rhs
;
9038 /* The signature is assumed to be unique within the DWO file.
9039 So while object file CU dwo_id's always have the value zero,
9040 that's OK, assuming each object file DWO file has only one CU,
9041 and that's the rule for now. */
9042 return lhs
->signature
== rhs
->signature
;
9045 /* Allocate a hash table for DWO CUs,TUs.
9046 There is one of these tables for each of CUs,TUs for each DWO file. */
9049 allocate_dwo_unit_table (struct objfile
*objfile
)
9051 /* Start out with a pretty small number.
9052 Generally DWO files contain only one CU and maybe some TUs. */
9053 return htab_create_alloc_ex (3,
9057 &objfile
->objfile_obstack
,
9058 hashtab_obstack_allocate
,
9059 dummy_obstack_deallocate
);
9062 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
9064 struct create_dwo_cu_data
9066 struct dwo_file
*dwo_file
;
9067 struct dwo_unit dwo_unit
;
9070 /* die_reader_func for create_dwo_cu. */
9073 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
9074 const gdb_byte
*info_ptr
,
9075 struct die_info
*comp_unit_die
,
9079 struct dwarf2_cu
*cu
= reader
->cu
;
9080 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9081 sect_offset offset
= cu
->per_cu
->offset
;
9082 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
9083 struct create_dwo_cu_data
*data
= datap
;
9084 struct dwo_file
*dwo_file
= data
->dwo_file
;
9085 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
9086 struct attribute
*attr
;
9088 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
9091 complaint (&symfile_complaints
,
9092 _("Dwarf Error: debug entry at offset 0x%x is missing"
9093 " its dwo_id [in module %s]"),
9094 offset
.sect_off
, dwo_file
->dwo_name
);
9098 dwo_unit
->dwo_file
= dwo_file
;
9099 dwo_unit
->signature
= DW_UNSND (attr
);
9100 dwo_unit
->section
= section
;
9101 dwo_unit
->offset
= offset
;
9102 dwo_unit
->length
= cu
->per_cu
->length
;
9104 if (dwarf2_read_debug
)
9105 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id %s\n",
9106 offset
.sect_off
, hex_string (dwo_unit
->signature
));
9109 /* Create the dwo_unit for the lone CU in DWO_FILE.
9110 Note: This function processes DWO files only, not DWP files. */
9112 static struct dwo_unit
*
9113 create_dwo_cu (struct dwo_file
*dwo_file
)
9115 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9116 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
9119 const gdb_byte
*info_ptr
, *end_ptr
;
9120 struct create_dwo_cu_data create_dwo_cu_data
;
9121 struct dwo_unit
*dwo_unit
;
9123 dwarf2_read_section (objfile
, section
);
9124 info_ptr
= section
->buffer
;
9126 if (info_ptr
== NULL
)
9129 /* We can't set abfd until now because the section may be empty or
9130 not present, in which case section->asection will be NULL. */
9131 abfd
= get_section_bfd_owner (section
);
9133 if (dwarf2_read_debug
)
9135 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
9136 get_section_name (section
),
9137 get_section_file_name (section
));
9140 create_dwo_cu_data
.dwo_file
= dwo_file
;
9143 end_ptr
= info_ptr
+ section
->size
;
9144 while (info_ptr
< end_ptr
)
9146 struct dwarf2_per_cu_data per_cu
;
9148 memset (&create_dwo_cu_data
.dwo_unit
, 0,
9149 sizeof (create_dwo_cu_data
.dwo_unit
));
9150 memset (&per_cu
, 0, sizeof (per_cu
));
9151 per_cu
.objfile
= objfile
;
9152 per_cu
.is_debug_types
= 0;
9153 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
9154 per_cu
.section
= section
;
9156 init_cutu_and_read_dies_no_follow (&per_cu
,
9157 &dwo_file
->sections
.abbrev
,
9159 create_dwo_cu_reader
,
9160 &create_dwo_cu_data
);
9162 if (create_dwo_cu_data
.dwo_unit
.dwo_file
!= NULL
)
9164 /* If we've already found one, complain. We only support one
9165 because having more than one requires hacking the dwo_name of
9166 each to match, which is highly unlikely to happen. */
9167 if (dwo_unit
!= NULL
)
9169 complaint (&symfile_complaints
,
9170 _("Multiple CUs in DWO file %s [in module %s]"),
9171 dwo_file
->dwo_name
, objfile_name (objfile
));
9175 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
9176 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
9179 info_ptr
+= per_cu
.length
;
9185 /* DWP file .debug_{cu,tu}_index section format:
9186 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
9190 Both index sections have the same format, and serve to map a 64-bit
9191 signature to a set of section numbers. Each section begins with a header,
9192 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
9193 indexes, and a pool of 32-bit section numbers. The index sections will be
9194 aligned at 8-byte boundaries in the file.
9196 The index section header consists of:
9198 V, 32 bit version number
9200 N, 32 bit number of compilation units or type units in the index
9201 M, 32 bit number of slots in the hash table
9203 Numbers are recorded using the byte order of the application binary.
9205 The hash table begins at offset 16 in the section, and consists of an array
9206 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
9207 order of the application binary). Unused slots in the hash table are 0.
9208 (We rely on the extreme unlikeliness of a signature being exactly 0.)
9210 The parallel table begins immediately after the hash table
9211 (at offset 16 + 8 * M from the beginning of the section), and consists of an
9212 array of 32-bit indexes (using the byte order of the application binary),
9213 corresponding 1-1 with slots in the hash table. Each entry in the parallel
9214 table contains a 32-bit index into the pool of section numbers. For unused
9215 hash table slots, the corresponding entry in the parallel table will be 0.
9217 The pool of section numbers begins immediately following the hash table
9218 (at offset 16 + 12 * M from the beginning of the section). The pool of
9219 section numbers consists of an array of 32-bit words (using the byte order
9220 of the application binary). Each item in the array is indexed starting
9221 from 0. The hash table entry provides the index of the first section
9222 number in the set. Additional section numbers in the set follow, and the
9223 set is terminated by a 0 entry (section number 0 is not used in ELF).
9225 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
9226 section must be the first entry in the set, and the .debug_abbrev.dwo must
9227 be the second entry. Other members of the set may follow in any order.
9233 DWP Version 2 combines all the .debug_info, etc. sections into one,
9234 and the entries in the index tables are now offsets into these sections.
9235 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
9238 Index Section Contents:
9240 Hash Table of Signatures dwp_hash_table.hash_table
9241 Parallel Table of Indices dwp_hash_table.unit_table
9242 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
9243 Table of Section Sizes dwp_hash_table.v2.sizes
9245 The index section header consists of:
9247 V, 32 bit version number
9248 L, 32 bit number of columns in the table of section offsets
9249 N, 32 bit number of compilation units or type units in the index
9250 M, 32 bit number of slots in the hash table
9252 Numbers are recorded using the byte order of the application binary.
9254 The hash table has the same format as version 1.
9255 The parallel table of indices has the same format as version 1,
9256 except that the entries are origin-1 indices into the table of sections
9257 offsets and the table of section sizes.
9259 The table of offsets begins immediately following the parallel table
9260 (at offset 16 + 12 * M from the beginning of the section). The table is
9261 a two-dimensional array of 32-bit words (using the byte order of the
9262 application binary), with L columns and N+1 rows, in row-major order.
9263 Each row in the array is indexed starting from 0. The first row provides
9264 a key to the remaining rows: each column in this row provides an identifier
9265 for a debug section, and the offsets in the same column of subsequent rows
9266 refer to that section. The section identifiers are:
9268 DW_SECT_INFO 1 .debug_info.dwo
9269 DW_SECT_TYPES 2 .debug_types.dwo
9270 DW_SECT_ABBREV 3 .debug_abbrev.dwo
9271 DW_SECT_LINE 4 .debug_line.dwo
9272 DW_SECT_LOC 5 .debug_loc.dwo
9273 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
9274 DW_SECT_MACINFO 7 .debug_macinfo.dwo
9275 DW_SECT_MACRO 8 .debug_macro.dwo
9277 The offsets provided by the CU and TU index sections are the base offsets
9278 for the contributions made by each CU or TU to the corresponding section
9279 in the package file. Each CU and TU header contains an abbrev_offset
9280 field, used to find the abbreviations table for that CU or TU within the
9281 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
9282 be interpreted as relative to the base offset given in the index section.
9283 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
9284 should be interpreted as relative to the base offset for .debug_line.dwo,
9285 and offsets into other debug sections obtained from DWARF attributes should
9286 also be interpreted as relative to the corresponding base offset.
9288 The table of sizes begins immediately following the table of offsets.
9289 Like the table of offsets, it is a two-dimensional array of 32-bit words,
9290 with L columns and N rows, in row-major order. Each row in the array is
9291 indexed starting from 1 (row 0 is shared by the two tables).
9295 Hash table lookup is handled the same in version 1 and 2:
9297 We assume that N and M will not exceed 2^32 - 1.
9298 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
9300 Given a 64-bit compilation unit signature or a type signature S, an entry
9301 in the hash table is located as follows:
9303 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
9304 the low-order k bits all set to 1.
9306 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
9308 3) If the hash table entry at index H matches the signature, use that
9309 entry. If the hash table entry at index H is unused (all zeroes),
9310 terminate the search: the signature is not present in the table.
9312 4) Let H = (H + H') modulo M. Repeat at Step 3.
9314 Because M > N and H' and M are relatively prime, the search is guaranteed
9315 to stop at an unused slot or find the match. */
9317 /* Create a hash table to map DWO IDs to their CU/TU entry in
9318 .debug_{info,types}.dwo in DWP_FILE.
9319 Returns NULL if there isn't one.
9320 Note: This function processes DWP files only, not DWO files. */
9322 static struct dwp_hash_table
*
9323 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
9325 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9326 bfd
*dbfd
= dwp_file
->dbfd
;
9327 const gdb_byte
*index_ptr
, *index_end
;
9328 struct dwarf2_section_info
*index
;
9329 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
9330 struct dwp_hash_table
*htab
;
9333 index
= &dwp_file
->sections
.tu_index
;
9335 index
= &dwp_file
->sections
.cu_index
;
9337 if (dwarf2_section_empty_p (index
))
9339 dwarf2_read_section (objfile
, index
);
9341 index_ptr
= index
->buffer
;
9342 index_end
= index_ptr
+ index
->size
;
9344 version
= read_4_bytes (dbfd
, index_ptr
);
9347 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
9351 nr_units
= read_4_bytes (dbfd
, index_ptr
);
9353 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
9356 if (version
!= 1 && version
!= 2)
9358 error (_("Dwarf Error: unsupported DWP file version (%s)"
9360 pulongest (version
), dwp_file
->name
);
9362 if (nr_slots
!= (nr_slots
& -nr_slots
))
9364 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
9365 " is not power of 2 [in module %s]"),
9366 pulongest (nr_slots
), dwp_file
->name
);
9369 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
9370 htab
->version
= version
;
9371 htab
->nr_columns
= nr_columns
;
9372 htab
->nr_units
= nr_units
;
9373 htab
->nr_slots
= nr_slots
;
9374 htab
->hash_table
= index_ptr
;
9375 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
9377 /* Exit early if the table is empty. */
9378 if (nr_slots
== 0 || nr_units
== 0
9379 || (version
== 2 && nr_columns
== 0))
9381 /* All must be zero. */
9382 if (nr_slots
!= 0 || nr_units
!= 0
9383 || (version
== 2 && nr_columns
!= 0))
9385 complaint (&symfile_complaints
,
9386 _("Empty DWP but nr_slots,nr_units,nr_columns not"
9387 " all zero [in modules %s]"),
9395 htab
->section_pool
.v1
.indices
=
9396 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9397 /* It's harder to decide whether the section is too small in v1.
9398 V1 is deprecated anyway so we punt. */
9402 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9403 int *ids
= htab
->section_pool
.v2
.section_ids
;
9404 /* Reverse map for error checking. */
9405 int ids_seen
[DW_SECT_MAX
+ 1];
9410 error (_("Dwarf Error: bad DWP hash table, too few columns"
9411 " in section table [in module %s]"),
9414 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
9416 error (_("Dwarf Error: bad DWP hash table, too many columns"
9417 " in section table [in module %s]"),
9420 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
9421 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
9422 for (i
= 0; i
< nr_columns
; ++i
)
9424 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
9426 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
9428 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
9429 " in section table [in module %s]"),
9430 id
, dwp_file
->name
);
9432 if (ids_seen
[id
] != -1)
9434 error (_("Dwarf Error: bad DWP hash table, duplicate section"
9435 " id %d in section table [in module %s]"),
9436 id
, dwp_file
->name
);
9441 /* Must have exactly one info or types section. */
9442 if (((ids_seen
[DW_SECT_INFO
] != -1)
9443 + (ids_seen
[DW_SECT_TYPES
] != -1))
9446 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
9447 " DWO info/types section [in module %s]"),
9450 /* Must have an abbrev section. */
9451 if (ids_seen
[DW_SECT_ABBREV
] == -1)
9453 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
9454 " section [in module %s]"),
9457 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
9458 htab
->section_pool
.v2
.sizes
=
9459 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
9460 * nr_units
* nr_columns
);
9461 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
9462 * nr_units
* nr_columns
))
9465 error (_("Dwarf Error: DWP index section is corrupt (too small)"
9474 /* Update SECTIONS with the data from SECTP.
9476 This function is like the other "locate" section routines that are
9477 passed to bfd_map_over_sections, but in this context the sections to
9478 read comes from the DWP V1 hash table, not the full ELF section table.
9480 The result is non-zero for success, or zero if an error was found. */
9483 locate_v1_virtual_dwo_sections (asection
*sectp
,
9484 struct virtual_v1_dwo_sections
*sections
)
9486 const struct dwop_section_names
*names
= &dwop_section_names
;
9488 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
9490 /* There can be only one. */
9491 if (sections
->abbrev
.s
.asection
!= NULL
)
9493 sections
->abbrev
.s
.asection
= sectp
;
9494 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
9496 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
9497 || section_is_p (sectp
->name
, &names
->types_dwo
))
9499 /* There can be only one. */
9500 if (sections
->info_or_types
.s
.asection
!= NULL
)
9502 sections
->info_or_types
.s
.asection
= sectp
;
9503 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
9505 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
9507 /* There can be only one. */
9508 if (sections
->line
.s
.asection
!= NULL
)
9510 sections
->line
.s
.asection
= sectp
;
9511 sections
->line
.size
= bfd_get_section_size (sectp
);
9513 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
9515 /* There can be only one. */
9516 if (sections
->loc
.s
.asection
!= NULL
)
9518 sections
->loc
.s
.asection
= sectp
;
9519 sections
->loc
.size
= bfd_get_section_size (sectp
);
9521 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
9523 /* There can be only one. */
9524 if (sections
->macinfo
.s
.asection
!= NULL
)
9526 sections
->macinfo
.s
.asection
= sectp
;
9527 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
9529 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
9531 /* There can be only one. */
9532 if (sections
->macro
.s
.asection
!= NULL
)
9534 sections
->macro
.s
.asection
= sectp
;
9535 sections
->macro
.size
= bfd_get_section_size (sectp
);
9537 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
9539 /* There can be only one. */
9540 if (sections
->str_offsets
.s
.asection
!= NULL
)
9542 sections
->str_offsets
.s
.asection
= sectp
;
9543 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
9547 /* No other kind of section is valid. */
9554 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
9555 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
9556 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
9557 This is for DWP version 1 files. */
9559 static struct dwo_unit
*
9560 create_dwo_unit_in_dwp_v1 (struct dwp_file
*dwp_file
,
9561 uint32_t unit_index
,
9562 const char *comp_dir
,
9563 ULONGEST signature
, int is_debug_types
)
9565 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9566 const struct dwp_hash_table
*dwp_htab
=
9567 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9568 bfd
*dbfd
= dwp_file
->dbfd
;
9569 const char *kind
= is_debug_types
? "TU" : "CU";
9570 struct dwo_file
*dwo_file
;
9571 struct dwo_unit
*dwo_unit
;
9572 struct virtual_v1_dwo_sections sections
;
9573 void **dwo_file_slot
;
9574 char *virtual_dwo_name
;
9575 struct dwarf2_section_info
*cutu
;
9576 struct cleanup
*cleanups
;
9579 gdb_assert (dwp_file
->version
== 1);
9581 if (dwarf2_read_debug
)
9583 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
9585 pulongest (unit_index
), hex_string (signature
),
9589 /* Fetch the sections of this DWO unit.
9590 Put a limit on the number of sections we look for so that bad data
9591 doesn't cause us to loop forever. */
9593 #define MAX_NR_V1_DWO_SECTIONS \
9594 (1 /* .debug_info or .debug_types */ \
9595 + 1 /* .debug_abbrev */ \
9596 + 1 /* .debug_line */ \
9597 + 1 /* .debug_loc */ \
9598 + 1 /* .debug_str_offsets */ \
9599 + 1 /* .debug_macro or .debug_macinfo */ \
9600 + 1 /* trailing zero */)
9602 memset (§ions
, 0, sizeof (sections
));
9603 cleanups
= make_cleanup (null_cleanup
, 0);
9605 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
9608 uint32_t section_nr
=
9610 dwp_htab
->section_pool
.v1
.indices
9611 + (unit_index
+ i
) * sizeof (uint32_t));
9613 if (section_nr
== 0)
9615 if (section_nr
>= dwp_file
->num_sections
)
9617 error (_("Dwarf Error: bad DWP hash table, section number too large"
9622 sectp
= dwp_file
->elf_sections
[section_nr
];
9623 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
9625 error (_("Dwarf Error: bad DWP hash table, invalid section found"
9632 || dwarf2_section_empty_p (§ions
.info_or_types
)
9633 || dwarf2_section_empty_p (§ions
.abbrev
))
9635 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
9639 if (i
== MAX_NR_V1_DWO_SECTIONS
)
9641 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
9646 /* It's easier for the rest of the code if we fake a struct dwo_file and
9647 have dwo_unit "live" in that. At least for now.
9649 The DWP file can be made up of a random collection of CUs and TUs.
9650 However, for each CU + set of TUs that came from the same original DWO
9651 file, we can combine them back into a virtual DWO file to save space
9652 (fewer struct dwo_file objects to allocate). Remember that for really
9653 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
9656 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
9657 get_section_id (§ions
.abbrev
),
9658 get_section_id (§ions
.line
),
9659 get_section_id (§ions
.loc
),
9660 get_section_id (§ions
.str_offsets
));
9661 make_cleanup (xfree
, virtual_dwo_name
);
9662 /* Can we use an existing virtual DWO file? */
9663 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
9664 /* Create one if necessary. */
9665 if (*dwo_file_slot
== NULL
)
9667 if (dwarf2_read_debug
)
9669 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
9672 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
9673 dwo_file
->dwo_name
= obstack_copy0 (&objfile
->objfile_obstack
,
9675 strlen (virtual_dwo_name
));
9676 dwo_file
->comp_dir
= comp_dir
;
9677 dwo_file
->sections
.abbrev
= sections
.abbrev
;
9678 dwo_file
->sections
.line
= sections
.line
;
9679 dwo_file
->sections
.loc
= sections
.loc
;
9680 dwo_file
->sections
.macinfo
= sections
.macinfo
;
9681 dwo_file
->sections
.macro
= sections
.macro
;
9682 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
9683 /* The "str" section is global to the entire DWP file. */
9684 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
9685 /* The info or types section is assigned below to dwo_unit,
9686 there's no need to record it in dwo_file.
9687 Also, we can't simply record type sections in dwo_file because
9688 we record a pointer into the vector in dwo_unit. As we collect more
9689 types we'll grow the vector and eventually have to reallocate space
9690 for it, invalidating all copies of pointers into the previous
9692 *dwo_file_slot
= dwo_file
;
9696 if (dwarf2_read_debug
)
9698 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
9701 dwo_file
= *dwo_file_slot
;
9703 do_cleanups (cleanups
);
9705 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
9706 dwo_unit
->dwo_file
= dwo_file
;
9707 dwo_unit
->signature
= signature
;
9708 dwo_unit
->section
= obstack_alloc (&objfile
->objfile_obstack
,
9709 sizeof (struct dwarf2_section_info
));
9710 *dwo_unit
->section
= sections
.info_or_types
;
9711 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
9716 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
9717 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
9718 piece within that section used by a TU/CU, return a virtual section
9719 of just that piece. */
9721 static struct dwarf2_section_info
9722 create_dwp_v2_section (struct dwarf2_section_info
*section
,
9723 bfd_size_type offset
, bfd_size_type size
)
9725 struct dwarf2_section_info result
;
9728 gdb_assert (section
!= NULL
);
9729 gdb_assert (!section
->is_virtual
);
9731 memset (&result
, 0, sizeof (result
));
9732 result
.s
.containing_section
= section
;
9733 result
.is_virtual
= 1;
9738 sectp
= get_section_bfd_section (section
);
9740 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
9741 bounds of the real section. This is a pretty-rare event, so just
9742 flag an error (easier) instead of a warning and trying to cope. */
9744 || offset
+ size
> bfd_get_section_size (sectp
))
9746 bfd
*abfd
= sectp
->owner
;
9748 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
9749 " in section %s [in module %s]"),
9750 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
9751 objfile_name (dwarf2_per_objfile
->objfile
));
9754 result
.virtual_offset
= offset
;
9759 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
9760 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
9761 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
9762 This is for DWP version 2 files. */
9764 static struct dwo_unit
*
9765 create_dwo_unit_in_dwp_v2 (struct dwp_file
*dwp_file
,
9766 uint32_t unit_index
,
9767 const char *comp_dir
,
9768 ULONGEST signature
, int is_debug_types
)
9770 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9771 const struct dwp_hash_table
*dwp_htab
=
9772 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9773 bfd
*dbfd
= dwp_file
->dbfd
;
9774 const char *kind
= is_debug_types
? "TU" : "CU";
9775 struct dwo_file
*dwo_file
;
9776 struct dwo_unit
*dwo_unit
;
9777 struct virtual_v2_dwo_sections sections
;
9778 void **dwo_file_slot
;
9779 char *virtual_dwo_name
;
9780 struct dwarf2_section_info
*cutu
;
9781 struct cleanup
*cleanups
;
9784 gdb_assert (dwp_file
->version
== 2);
9786 if (dwarf2_read_debug
)
9788 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
9790 pulongest (unit_index
), hex_string (signature
),
9794 /* Fetch the section offsets of this DWO unit. */
9796 memset (§ions
, 0, sizeof (sections
));
9797 cleanups
= make_cleanup (null_cleanup
, 0);
9799 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
9801 uint32_t offset
= read_4_bytes (dbfd
,
9802 dwp_htab
->section_pool
.v2
.offsets
9803 + (((unit_index
- 1) * dwp_htab
->nr_columns
9805 * sizeof (uint32_t)));
9806 uint32_t size
= read_4_bytes (dbfd
,
9807 dwp_htab
->section_pool
.v2
.sizes
9808 + (((unit_index
- 1) * dwp_htab
->nr_columns
9810 * sizeof (uint32_t)));
9812 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
9816 sections
.info_or_types_offset
= offset
;
9817 sections
.info_or_types_size
= size
;
9819 case DW_SECT_ABBREV
:
9820 sections
.abbrev_offset
= offset
;
9821 sections
.abbrev_size
= size
;
9824 sections
.line_offset
= offset
;
9825 sections
.line_size
= size
;
9828 sections
.loc_offset
= offset
;
9829 sections
.loc_size
= size
;
9831 case DW_SECT_STR_OFFSETS
:
9832 sections
.str_offsets_offset
= offset
;
9833 sections
.str_offsets_size
= size
;
9835 case DW_SECT_MACINFO
:
9836 sections
.macinfo_offset
= offset
;
9837 sections
.macinfo_size
= size
;
9840 sections
.macro_offset
= offset
;
9841 sections
.macro_size
= size
;
9846 /* It's easier for the rest of the code if we fake a struct dwo_file and
9847 have dwo_unit "live" in that. At least for now.
9849 The DWP file can be made up of a random collection of CUs and TUs.
9850 However, for each CU + set of TUs that came from the same original DWO
9851 file, we can combine them back into a virtual DWO file to save space
9852 (fewer struct dwo_file objects to allocate). Remember that for really
9853 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
9856 xstrprintf ("virtual-dwo/%ld-%ld-%ld-%ld",
9857 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
9858 (long) (sections
.line_size
? sections
.line_offset
: 0),
9859 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
9860 (long) (sections
.str_offsets_size
9861 ? sections
.str_offsets_offset
: 0));
9862 make_cleanup (xfree
, virtual_dwo_name
);
9863 /* Can we use an existing virtual DWO file? */
9864 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
9865 /* Create one if necessary. */
9866 if (*dwo_file_slot
== NULL
)
9868 if (dwarf2_read_debug
)
9870 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
9873 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
9874 dwo_file
->dwo_name
= obstack_copy0 (&objfile
->objfile_obstack
,
9876 strlen (virtual_dwo_name
));
9877 dwo_file
->comp_dir
= comp_dir
;
9878 dwo_file
->sections
.abbrev
=
9879 create_dwp_v2_section (&dwp_file
->sections
.abbrev
,
9880 sections
.abbrev_offset
, sections
.abbrev_size
);
9881 dwo_file
->sections
.line
=
9882 create_dwp_v2_section (&dwp_file
->sections
.line
,
9883 sections
.line_offset
, sections
.line_size
);
9884 dwo_file
->sections
.loc
=
9885 create_dwp_v2_section (&dwp_file
->sections
.loc
,
9886 sections
.loc_offset
, sections
.loc_size
);
9887 dwo_file
->sections
.macinfo
=
9888 create_dwp_v2_section (&dwp_file
->sections
.macinfo
,
9889 sections
.macinfo_offset
, sections
.macinfo_size
);
9890 dwo_file
->sections
.macro
=
9891 create_dwp_v2_section (&dwp_file
->sections
.macro
,
9892 sections
.macro_offset
, sections
.macro_size
);
9893 dwo_file
->sections
.str_offsets
=
9894 create_dwp_v2_section (&dwp_file
->sections
.str_offsets
,
9895 sections
.str_offsets_offset
,
9896 sections
.str_offsets_size
);
9897 /* The "str" section is global to the entire DWP file. */
9898 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
9899 /* The info or types section is assigned below to dwo_unit,
9900 there's no need to record it in dwo_file.
9901 Also, we can't simply record type sections in dwo_file because
9902 we record a pointer into the vector in dwo_unit. As we collect more
9903 types we'll grow the vector and eventually have to reallocate space
9904 for it, invalidating all copies of pointers into the previous
9906 *dwo_file_slot
= dwo_file
;
9910 if (dwarf2_read_debug
)
9912 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
9915 dwo_file
= *dwo_file_slot
;
9917 do_cleanups (cleanups
);
9919 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
9920 dwo_unit
->dwo_file
= dwo_file
;
9921 dwo_unit
->signature
= signature
;
9922 dwo_unit
->section
= obstack_alloc (&objfile
->objfile_obstack
,
9923 sizeof (struct dwarf2_section_info
));
9924 *dwo_unit
->section
= create_dwp_v2_section (is_debug_types
9925 ? &dwp_file
->sections
.types
9926 : &dwp_file
->sections
.info
,
9927 sections
.info_or_types_offset
,
9928 sections
.info_or_types_size
);
9929 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
9934 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
9935 Returns NULL if the signature isn't found. */
9937 static struct dwo_unit
*
9938 lookup_dwo_unit_in_dwp (struct dwp_file
*dwp_file
, const char *comp_dir
,
9939 ULONGEST signature
, int is_debug_types
)
9941 const struct dwp_hash_table
*dwp_htab
=
9942 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9943 bfd
*dbfd
= dwp_file
->dbfd
;
9944 uint32_t mask
= dwp_htab
->nr_slots
- 1;
9945 uint32_t hash
= signature
& mask
;
9946 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
9949 struct dwo_unit find_dwo_cu
, *dwo_cu
;
9951 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
9952 find_dwo_cu
.signature
= signature
;
9953 slot
= htab_find_slot (is_debug_types
9954 ? dwp_file
->loaded_tus
9955 : dwp_file
->loaded_cus
,
9956 &find_dwo_cu
, INSERT
);
9961 /* Use a for loop so that we don't loop forever on bad debug info. */
9962 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
9964 ULONGEST signature_in_table
;
9966 signature_in_table
=
9967 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
9968 if (signature_in_table
== signature
)
9970 uint32_t unit_index
=
9972 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
9974 if (dwp_file
->version
== 1)
9976 *slot
= create_dwo_unit_in_dwp_v1 (dwp_file
, unit_index
,
9977 comp_dir
, signature
,
9982 *slot
= create_dwo_unit_in_dwp_v2 (dwp_file
, unit_index
,
9983 comp_dir
, signature
,
9988 if (signature_in_table
== 0)
9990 hash
= (hash
+ hash2
) & mask
;
9993 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
9998 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
9999 Open the file specified by FILE_NAME and hand it off to BFD for
10000 preliminary analysis. Return a newly initialized bfd *, which
10001 includes a canonicalized copy of FILE_NAME.
10002 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
10003 SEARCH_CWD is true if the current directory is to be searched.
10004 It will be searched before debug-file-directory.
10005 If unable to find/open the file, return NULL.
10006 NOTE: This function is derived from symfile_bfd_open. */
10009 try_open_dwop_file (const char *file_name
, int is_dwp
, int search_cwd
)
10013 char *absolute_name
;
10014 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
10015 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
10016 to debug_file_directory. */
10018 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
10022 if (*debug_file_directory
!= '\0')
10023 search_path
= concat (".", dirname_separator_string
,
10024 debug_file_directory
, NULL
);
10026 search_path
= xstrdup (".");
10029 search_path
= xstrdup (debug_file_directory
);
10031 flags
= OPF_RETURN_REALPATH
;
10033 flags
|= OPF_SEARCH_IN_PATH
;
10034 desc
= openp (search_path
, flags
, file_name
,
10035 O_RDONLY
| O_BINARY
, &absolute_name
);
10036 xfree (search_path
);
10040 sym_bfd
= gdb_bfd_open (absolute_name
, gnutarget
, desc
);
10041 xfree (absolute_name
);
10042 if (sym_bfd
== NULL
)
10044 bfd_set_cacheable (sym_bfd
, 1);
10046 if (!bfd_check_format (sym_bfd
, bfd_object
))
10048 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
10055 /* Try to open DWO file FILE_NAME.
10056 COMP_DIR is the DW_AT_comp_dir attribute.
10057 The result is the bfd handle of the file.
10058 If there is a problem finding or opening the file, return NULL.
10059 Upon success, the canonicalized path of the file is stored in the bfd,
10060 same as symfile_bfd_open. */
10063 open_dwo_file (const char *file_name
, const char *comp_dir
)
10067 if (IS_ABSOLUTE_PATH (file_name
))
10068 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 0 /*search_cwd*/);
10070 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
10072 if (comp_dir
!= NULL
)
10074 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, file_name
, NULL
);
10076 /* NOTE: If comp_dir is a relative path, this will also try the
10077 search path, which seems useful. */
10078 abfd
= try_open_dwop_file (path_to_try
, 0 /*is_dwp*/, 1 /*search_cwd*/);
10079 xfree (path_to_try
);
10084 /* That didn't work, try debug-file-directory, which, despite its name,
10085 is a list of paths. */
10087 if (*debug_file_directory
== '\0')
10090 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 1 /*search_cwd*/);
10093 /* This function is mapped across the sections and remembers the offset and
10094 size of each of the DWO debugging sections we are interested in. */
10097 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
10099 struct dwo_sections
*dwo_sections
= dwo_sections_ptr
;
10100 const struct dwop_section_names
*names
= &dwop_section_names
;
10102 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10104 dwo_sections
->abbrev
.s
.asection
= sectp
;
10105 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10107 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10109 dwo_sections
->info
.s
.asection
= sectp
;
10110 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
10112 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10114 dwo_sections
->line
.s
.asection
= sectp
;
10115 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
10117 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10119 dwo_sections
->loc
.s
.asection
= sectp
;
10120 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
10122 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10124 dwo_sections
->macinfo
.s
.asection
= sectp
;
10125 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10127 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10129 dwo_sections
->macro
.s
.asection
= sectp
;
10130 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
10132 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
10134 dwo_sections
->str
.s
.asection
= sectp
;
10135 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
10137 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10139 dwo_sections
->str_offsets
.s
.asection
= sectp
;
10140 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10142 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10144 struct dwarf2_section_info type_section
;
10146 memset (&type_section
, 0, sizeof (type_section
));
10147 type_section
.s
.asection
= sectp
;
10148 type_section
.size
= bfd_get_section_size (sectp
);
10149 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
10154 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
10155 by PER_CU. This is for the non-DWP case.
10156 The result is NULL if DWO_NAME can't be found. */
10158 static struct dwo_file
*
10159 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
10160 const char *dwo_name
, const char *comp_dir
)
10162 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10163 struct dwo_file
*dwo_file
;
10165 struct cleanup
*cleanups
;
10167 dbfd
= open_dwo_file (dwo_name
, comp_dir
);
10170 if (dwarf2_read_debug
)
10171 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
10174 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10175 dwo_file
->dwo_name
= dwo_name
;
10176 dwo_file
->comp_dir
= comp_dir
;
10177 dwo_file
->dbfd
= dbfd
;
10179 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
10181 bfd_map_over_sections (dbfd
, dwarf2_locate_dwo_sections
, &dwo_file
->sections
);
10183 dwo_file
->cu
= create_dwo_cu (dwo_file
);
10185 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
10186 dwo_file
->sections
.types
);
10188 discard_cleanups (cleanups
);
10190 if (dwarf2_read_debug
)
10191 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
10196 /* This function is mapped across the sections and remembers the offset and
10197 size of each of the DWP debugging sections common to version 1 and 2 that
10198 we are interested in. */
10201 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
10202 void *dwp_file_ptr
)
10204 struct dwp_file
*dwp_file
= dwp_file_ptr
;
10205 const struct dwop_section_names
*names
= &dwop_section_names
;
10206 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10208 /* Record the ELF section number for later lookup: this is what the
10209 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10210 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10211 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10213 /* Look for specific sections that we need. */
10214 if (section_is_p (sectp
->name
, &names
->str_dwo
))
10216 dwp_file
->sections
.str
.s
.asection
= sectp
;
10217 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
10219 else if (section_is_p (sectp
->name
, &names
->cu_index
))
10221 dwp_file
->sections
.cu_index
.s
.asection
= sectp
;
10222 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
10224 else if (section_is_p (sectp
->name
, &names
->tu_index
))
10226 dwp_file
->sections
.tu_index
.s
.asection
= sectp
;
10227 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
10231 /* This function is mapped across the sections and remembers the offset and
10232 size of each of the DWP version 2 debugging sections that we are interested
10233 in. This is split into a separate function because we don't know if we
10234 have version 1 or 2 until we parse the cu_index/tu_index sections. */
10237 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
10239 struct dwp_file
*dwp_file
= dwp_file_ptr
;
10240 const struct dwop_section_names
*names
= &dwop_section_names
;
10241 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10243 /* Record the ELF section number for later lookup: this is what the
10244 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10245 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10246 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10248 /* Look for specific sections that we need. */
10249 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10251 dwp_file
->sections
.abbrev
.s
.asection
= sectp
;
10252 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
10254 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10256 dwp_file
->sections
.info
.s
.asection
= sectp
;
10257 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
10259 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10261 dwp_file
->sections
.line
.s
.asection
= sectp
;
10262 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
10264 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10266 dwp_file
->sections
.loc
.s
.asection
= sectp
;
10267 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
10269 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10271 dwp_file
->sections
.macinfo
.s
.asection
= sectp
;
10272 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
10274 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10276 dwp_file
->sections
.macro
.s
.asection
= sectp
;
10277 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
10279 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10281 dwp_file
->sections
.str_offsets
.s
.asection
= sectp
;
10282 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
10284 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10286 dwp_file
->sections
.types
.s
.asection
= sectp
;
10287 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
10291 /* Hash function for dwp_file loaded CUs/TUs. */
10294 hash_dwp_loaded_cutus (const void *item
)
10296 const struct dwo_unit
*dwo_unit
= item
;
10298 /* This drops the top 32 bits of the signature, but is ok for a hash. */
10299 return dwo_unit
->signature
;
10302 /* Equality function for dwp_file loaded CUs/TUs. */
10305 eq_dwp_loaded_cutus (const void *a
, const void *b
)
10307 const struct dwo_unit
*dua
= a
;
10308 const struct dwo_unit
*dub
= b
;
10310 return dua
->signature
== dub
->signature
;
10313 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
10316 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
10318 return htab_create_alloc_ex (3,
10319 hash_dwp_loaded_cutus
,
10320 eq_dwp_loaded_cutus
,
10322 &objfile
->objfile_obstack
,
10323 hashtab_obstack_allocate
,
10324 dummy_obstack_deallocate
);
10327 /* Try to open DWP file FILE_NAME.
10328 The result is the bfd handle of the file.
10329 If there is a problem finding or opening the file, return NULL.
10330 Upon success, the canonicalized path of the file is stored in the bfd,
10331 same as symfile_bfd_open. */
10334 open_dwp_file (const char *file_name
)
10338 abfd
= try_open_dwop_file (file_name
, 1 /*is_dwp*/, 1 /*search_cwd*/);
10342 /* Work around upstream bug 15652.
10343 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
10344 [Whether that's a "bug" is debatable, but it is getting in our way.]
10345 We have no real idea where the dwp file is, because gdb's realpath-ing
10346 of the executable's path may have discarded the needed info.
10347 [IWBN if the dwp file name was recorded in the executable, akin to
10348 .gnu_debuglink, but that doesn't exist yet.]
10349 Strip the directory from FILE_NAME and search again. */
10350 if (*debug_file_directory
!= '\0')
10352 /* Don't implicitly search the current directory here.
10353 If the user wants to search "." to handle this case,
10354 it must be added to debug-file-directory. */
10355 return try_open_dwop_file (lbasename (file_name
), 1 /*is_dwp*/,
10362 /* Initialize the use of the DWP file for the current objfile.
10363 By convention the name of the DWP file is ${objfile}.dwp.
10364 The result is NULL if it can't be found. */
10366 static struct dwp_file
*
10367 open_and_init_dwp_file (void)
10369 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10370 struct dwp_file
*dwp_file
;
10373 struct cleanup
*cleanups
;
10375 /* Try to find first .dwp for the binary file before any symbolic links
10377 dwp_name
= xstrprintf ("%s.dwp", objfile
->original_name
);
10378 cleanups
= make_cleanup (xfree
, dwp_name
);
10380 dbfd
= open_dwp_file (dwp_name
);
10382 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
10384 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
10385 dwp_name
= xstrprintf ("%s.dwp", objfile_name (objfile
));
10386 make_cleanup (xfree
, dwp_name
);
10387 dbfd
= open_dwp_file (dwp_name
);
10392 if (dwarf2_read_debug
)
10393 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
);
10394 do_cleanups (cleanups
);
10397 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
10398 dwp_file
->name
= bfd_get_filename (dbfd
);
10399 dwp_file
->dbfd
= dbfd
;
10400 do_cleanups (cleanups
);
10402 /* +1: section 0 is unused */
10403 dwp_file
->num_sections
= bfd_count_sections (dbfd
) + 1;
10404 dwp_file
->elf_sections
=
10405 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
10406 dwp_file
->num_sections
, asection
*);
10408 bfd_map_over_sections (dbfd
, dwarf2_locate_common_dwp_sections
, dwp_file
);
10410 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
10412 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
10414 /* The DWP file version is stored in the hash table. Oh well. */
10415 if (dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
10417 /* Technically speaking, we should try to limp along, but this is
10419 error (_("Dwarf Error: DWP file CU version %d doesn't match"
10420 " TU version %d [in DWP file %s]"),
10421 dwp_file
->cus
->version
, dwp_file
->tus
->version
, dwp_name
);
10423 dwp_file
->version
= dwp_file
->cus
->version
;
10425 if (dwp_file
->version
== 2)
10426 bfd_map_over_sections (dbfd
, dwarf2_locate_v2_dwp_sections
, dwp_file
);
10428 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
10429 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
10431 if (dwarf2_read_debug
)
10433 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
10434 fprintf_unfiltered (gdb_stdlog
,
10435 " %s CUs, %s TUs\n",
10436 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
10437 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
10443 /* Wrapper around open_and_init_dwp_file, only open it once. */
10445 static struct dwp_file
*
10446 get_dwp_file (void)
10448 if (! dwarf2_per_objfile
->dwp_checked
)
10450 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file ();
10451 dwarf2_per_objfile
->dwp_checked
= 1;
10453 return dwarf2_per_objfile
->dwp_file
;
10456 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
10457 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
10458 or in the DWP file for the objfile, referenced by THIS_UNIT.
10459 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
10460 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
10462 This is called, for example, when wanting to read a variable with a
10463 complex location. Therefore we don't want to do file i/o for every call.
10464 Therefore we don't want to look for a DWO file on every call.
10465 Therefore we first see if we've already seen SIGNATURE in a DWP file,
10466 then we check if we've already seen DWO_NAME, and only THEN do we check
10469 The result is a pointer to the dwo_unit object or NULL if we didn't find it
10470 (dwo_id mismatch or couldn't find the DWO/DWP file). */
10472 static struct dwo_unit
*
10473 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
10474 const char *dwo_name
, const char *comp_dir
,
10475 ULONGEST signature
, int is_debug_types
)
10477 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10478 const char *kind
= is_debug_types
? "TU" : "CU";
10479 void **dwo_file_slot
;
10480 struct dwo_file
*dwo_file
;
10481 struct dwp_file
*dwp_file
;
10483 /* First see if there's a DWP file.
10484 If we have a DWP file but didn't find the DWO inside it, don't
10485 look for the original DWO file. It makes gdb behave differently
10486 depending on whether one is debugging in the build tree. */
10488 dwp_file
= get_dwp_file ();
10489 if (dwp_file
!= NULL
)
10491 const struct dwp_hash_table
*dwp_htab
=
10492 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10494 if (dwp_htab
!= NULL
)
10496 struct dwo_unit
*dwo_cutu
=
10497 lookup_dwo_unit_in_dwp (dwp_file
, comp_dir
,
10498 signature
, is_debug_types
);
10500 if (dwo_cutu
!= NULL
)
10502 if (dwarf2_read_debug
)
10504 fprintf_unfiltered (gdb_stdlog
,
10505 "Virtual DWO %s %s found: @%s\n",
10506 kind
, hex_string (signature
),
10507 host_address_to_string (dwo_cutu
));
10515 /* No DWP file, look for the DWO file. */
10517 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
, comp_dir
);
10518 if (*dwo_file_slot
== NULL
)
10520 /* Read in the file and build a table of the CUs/TUs it contains. */
10521 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
10523 /* NOTE: This will be NULL if unable to open the file. */
10524 dwo_file
= *dwo_file_slot
;
10526 if (dwo_file
!= NULL
)
10528 struct dwo_unit
*dwo_cutu
= NULL
;
10530 if (is_debug_types
&& dwo_file
->tus
)
10532 struct dwo_unit find_dwo_cutu
;
10534 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
10535 find_dwo_cutu
.signature
= signature
;
10536 dwo_cutu
= htab_find (dwo_file
->tus
, &find_dwo_cutu
);
10538 else if (!is_debug_types
&& dwo_file
->cu
)
10540 if (signature
== dwo_file
->cu
->signature
)
10541 dwo_cutu
= dwo_file
->cu
;
10544 if (dwo_cutu
!= NULL
)
10546 if (dwarf2_read_debug
)
10548 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
10549 kind
, dwo_name
, hex_string (signature
),
10550 host_address_to_string (dwo_cutu
));
10557 /* We didn't find it. This could mean a dwo_id mismatch, or
10558 someone deleted the DWO/DWP file, or the search path isn't set up
10559 correctly to find the file. */
10561 if (dwarf2_read_debug
)
10563 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
10564 kind
, dwo_name
, hex_string (signature
));
10567 /* This is a warning and not a complaint because it can be caused by
10568 pilot error (e.g., user accidentally deleting the DWO). */
10569 warning (_("Could not find DWO %s %s(%s) referenced by %s at offset 0x%x"
10570 " [in module %s]"),
10571 kind
, dwo_name
, hex_string (signature
),
10572 this_unit
->is_debug_types
? "TU" : "CU",
10573 this_unit
->offset
.sect_off
, objfile_name (objfile
));
10577 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
10578 See lookup_dwo_cutu_unit for details. */
10580 static struct dwo_unit
*
10581 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
10582 const char *dwo_name
, const char *comp_dir
,
10583 ULONGEST signature
)
10585 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
10588 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
10589 See lookup_dwo_cutu_unit for details. */
10591 static struct dwo_unit
*
10592 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
10593 const char *dwo_name
, const char *comp_dir
)
10595 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
10598 /* Traversal function for queue_and_load_all_dwo_tus. */
10601 queue_and_load_dwo_tu (void **slot
, void *info
)
10603 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
10604 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
10605 ULONGEST signature
= dwo_unit
->signature
;
10606 struct signatured_type
*sig_type
=
10607 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
10609 if (sig_type
!= NULL
)
10611 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
10613 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
10614 a real dependency of PER_CU on SIG_TYPE. That is detected later
10615 while processing PER_CU. */
10616 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
10617 load_full_type_unit (sig_cu
);
10618 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
10624 /* Queue all TUs contained in the DWO of PER_CU to be read in.
10625 The DWO may have the only definition of the type, though it may not be
10626 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
10627 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
10630 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
10632 struct dwo_unit
*dwo_unit
;
10633 struct dwo_file
*dwo_file
;
10635 gdb_assert (!per_cu
->is_debug_types
);
10636 gdb_assert (get_dwp_file () == NULL
);
10637 gdb_assert (per_cu
->cu
!= NULL
);
10639 dwo_unit
= per_cu
->cu
->dwo_unit
;
10640 gdb_assert (dwo_unit
!= NULL
);
10642 dwo_file
= dwo_unit
->dwo_file
;
10643 if (dwo_file
->tus
!= NULL
)
10644 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
10647 /* Free all resources associated with DWO_FILE.
10648 Close the DWO file and munmap the sections.
10649 All memory should be on the objfile obstack. */
10652 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
10655 struct dwarf2_section_info
*section
;
10657 /* Note: dbfd is NULL for virtual DWO files. */
10658 gdb_bfd_unref (dwo_file
->dbfd
);
10660 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
10663 /* Wrapper for free_dwo_file for use in cleanups. */
10666 free_dwo_file_cleanup (void *arg
)
10668 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
10669 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10671 free_dwo_file (dwo_file
, objfile
);
10674 /* Traversal function for free_dwo_files. */
10677 free_dwo_file_from_slot (void **slot
, void *info
)
10679 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
10680 struct objfile
*objfile
= (struct objfile
*) info
;
10682 free_dwo_file (dwo_file
, objfile
);
10687 /* Free all resources associated with DWO_FILES. */
10690 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
10692 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
10695 /* Read in various DIEs. */
10697 /* qsort helper for inherit_abstract_dies. */
10700 unsigned_int_compar (const void *ap
, const void *bp
)
10702 unsigned int a
= *(unsigned int *) ap
;
10703 unsigned int b
= *(unsigned int *) bp
;
10705 return (a
> b
) - (b
> a
);
10708 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
10709 Inherit only the children of the DW_AT_abstract_origin DIE not being
10710 already referenced by DW_AT_abstract_origin from the children of the
10714 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
10716 struct die_info
*child_die
;
10717 unsigned die_children_count
;
10718 /* CU offsets which were referenced by children of the current DIE. */
10719 sect_offset
*offsets
;
10720 sect_offset
*offsets_end
, *offsetp
;
10721 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
10722 struct die_info
*origin_die
;
10723 /* Iterator of the ORIGIN_DIE children. */
10724 struct die_info
*origin_child_die
;
10725 struct cleanup
*cleanups
;
10726 struct attribute
*attr
;
10727 struct dwarf2_cu
*origin_cu
;
10728 struct pending
**origin_previous_list_in_scope
;
10730 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
10734 /* Note that following die references may follow to a die in a
10738 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
10740 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
10742 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
10743 origin_cu
->list_in_scope
= cu
->list_in_scope
;
10745 if (die
->tag
!= origin_die
->tag
10746 && !(die
->tag
== DW_TAG_inlined_subroutine
10747 && origin_die
->tag
== DW_TAG_subprogram
))
10748 complaint (&symfile_complaints
,
10749 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
10750 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
10752 child_die
= die
->child
;
10753 die_children_count
= 0;
10754 while (child_die
&& child_die
->tag
)
10756 child_die
= sibling_die (child_die
);
10757 die_children_count
++;
10759 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
10760 cleanups
= make_cleanup (xfree
, offsets
);
10762 offsets_end
= offsets
;
10763 child_die
= die
->child
;
10764 while (child_die
&& child_die
->tag
)
10766 /* For each CHILD_DIE, find the corresponding child of
10767 ORIGIN_DIE. If there is more than one layer of
10768 DW_AT_abstract_origin, follow them all; there shouldn't be,
10769 but GCC versions at least through 4.4 generate this (GCC PR
10771 struct die_info
*child_origin_die
= child_die
;
10772 struct dwarf2_cu
*child_origin_cu
= cu
;
10776 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
10780 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
10784 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
10785 counterpart may exist. */
10786 if (child_origin_die
!= child_die
)
10788 if (child_die
->tag
!= child_origin_die
->tag
10789 && !(child_die
->tag
== DW_TAG_inlined_subroutine
10790 && child_origin_die
->tag
== DW_TAG_subprogram
))
10791 complaint (&symfile_complaints
,
10792 _("Child DIE 0x%x and its abstract origin 0x%x have "
10793 "different tags"), child_die
->offset
.sect_off
,
10794 child_origin_die
->offset
.sect_off
);
10795 if (child_origin_die
->parent
!= origin_die
)
10796 complaint (&symfile_complaints
,
10797 _("Child DIE 0x%x and its abstract origin 0x%x have "
10798 "different parents"), child_die
->offset
.sect_off
,
10799 child_origin_die
->offset
.sect_off
);
10801 *offsets_end
++ = child_origin_die
->offset
;
10803 child_die
= sibling_die (child_die
);
10805 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
10806 unsigned_int_compar
);
10807 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
10808 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
10809 complaint (&symfile_complaints
,
10810 _("Multiple children of DIE 0x%x refer "
10811 "to DIE 0x%x as their abstract origin"),
10812 die
->offset
.sect_off
, offsetp
->sect_off
);
10815 origin_child_die
= origin_die
->child
;
10816 while (origin_child_die
&& origin_child_die
->tag
)
10818 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
10819 while (offsetp
< offsets_end
10820 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
10822 if (offsetp
>= offsets_end
10823 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
10825 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
10826 process_die (origin_child_die
, origin_cu
);
10828 origin_child_die
= sibling_die (origin_child_die
);
10830 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
10832 do_cleanups (cleanups
);
10836 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10838 struct objfile
*objfile
= cu
->objfile
;
10839 struct context_stack
*new;
10842 struct die_info
*child_die
;
10843 struct attribute
*attr
, *call_line
, *call_file
;
10845 CORE_ADDR baseaddr
;
10846 struct block
*block
;
10847 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10848 VEC (symbolp
) *template_args
= NULL
;
10849 struct template_symbol
*templ_func
= NULL
;
10853 /* If we do not have call site information, we can't show the
10854 caller of this inlined function. That's too confusing, so
10855 only use the scope for local variables. */
10856 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
10857 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
10858 if (call_line
== NULL
|| call_file
== NULL
)
10860 read_lexical_block_scope (die
, cu
);
10865 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10867 name
= dwarf2_name (die
, cu
);
10869 /* Ignore functions with missing or empty names. These are actually
10870 illegal according to the DWARF standard. */
10873 complaint (&symfile_complaints
,
10874 _("missing name for subprogram DIE at %d"),
10875 die
->offset
.sect_off
);
10879 /* Ignore functions with missing or invalid low and high pc attributes. */
10880 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
10882 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10883 if (!attr
|| !DW_UNSND (attr
))
10884 complaint (&symfile_complaints
,
10885 _("cannot get low and high bounds "
10886 "for subprogram DIE at %d"),
10887 die
->offset
.sect_off
);
10892 highpc
+= baseaddr
;
10894 /* If we have any template arguments, then we must allocate a
10895 different sort of symbol. */
10896 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
10898 if (child_die
->tag
== DW_TAG_template_type_param
10899 || child_die
->tag
== DW_TAG_template_value_param
)
10901 templ_func
= allocate_template_symbol (objfile
);
10902 templ_func
->base
.is_cplus_template_function
= 1;
10907 new = push_context (0, lowpc
);
10908 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
10909 (struct symbol
*) templ_func
);
10911 /* If there is a location expression for DW_AT_frame_base, record
10913 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
10915 dwarf2_symbol_mark_computed (attr
, new->name
, cu
, 1);
10917 cu
->list_in_scope
= &local_symbols
;
10919 if (die
->child
!= NULL
)
10921 child_die
= die
->child
;
10922 while (child_die
&& child_die
->tag
)
10924 if (child_die
->tag
== DW_TAG_template_type_param
10925 || child_die
->tag
== DW_TAG_template_value_param
)
10927 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
10930 VEC_safe_push (symbolp
, template_args
, arg
);
10933 process_die (child_die
, cu
);
10934 child_die
= sibling_die (child_die
);
10938 inherit_abstract_dies (die
, cu
);
10940 /* If we have a DW_AT_specification, we might need to import using
10941 directives from the context of the specification DIE. See the
10942 comment in determine_prefix. */
10943 if (cu
->language
== language_cplus
10944 && dwarf2_attr (die
, DW_AT_specification
, cu
))
10946 struct dwarf2_cu
*spec_cu
= cu
;
10947 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
10951 child_die
= spec_die
->child
;
10952 while (child_die
&& child_die
->tag
)
10954 if (child_die
->tag
== DW_TAG_imported_module
)
10955 process_die (child_die
, spec_cu
);
10956 child_die
= sibling_die (child_die
);
10959 /* In some cases, GCC generates specification DIEs that
10960 themselves contain DW_AT_specification attributes. */
10961 spec_die
= die_specification (spec_die
, &spec_cu
);
10965 new = pop_context ();
10966 /* Make a block for the local symbols within. */
10967 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
10968 lowpc
, highpc
, objfile
);
10970 /* For C++, set the block's scope. */
10971 if ((cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
10972 && cu
->processing_has_namespace_info
)
10973 block_set_scope (block
, determine_prefix (die
, cu
),
10974 &objfile
->objfile_obstack
);
10976 /* If we have address ranges, record them. */
10977 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
10979 /* Attach template arguments to function. */
10980 if (! VEC_empty (symbolp
, template_args
))
10982 gdb_assert (templ_func
!= NULL
);
10984 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
10985 templ_func
->template_arguments
10986 = obstack_alloc (&objfile
->objfile_obstack
,
10987 (templ_func
->n_template_arguments
10988 * sizeof (struct symbol
*)));
10989 memcpy (templ_func
->template_arguments
,
10990 VEC_address (symbolp
, template_args
),
10991 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
10992 VEC_free (symbolp
, template_args
);
10995 /* In C++, we can have functions nested inside functions (e.g., when
10996 a function declares a class that has methods). This means that
10997 when we finish processing a function scope, we may need to go
10998 back to building a containing block's symbol lists. */
10999 local_symbols
= new->locals
;
11000 using_directives
= new->using_directives
;
11002 /* If we've finished processing a top-level function, subsequent
11003 symbols go in the file symbol list. */
11004 if (outermost_context_p ())
11005 cu
->list_in_scope
= &file_symbols
;
11008 /* Process all the DIES contained within a lexical block scope. Start
11009 a new scope, process the dies, and then close the scope. */
11012 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11014 struct objfile
*objfile
= cu
->objfile
;
11015 struct context_stack
*new;
11016 CORE_ADDR lowpc
, highpc
;
11017 struct die_info
*child_die
;
11018 CORE_ADDR baseaddr
;
11020 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11022 /* Ignore blocks with missing or invalid low and high pc attributes. */
11023 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
11024 as multiple lexical blocks? Handling children in a sane way would
11025 be nasty. Might be easier to properly extend generic blocks to
11026 describe ranges. */
11027 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
11030 highpc
+= baseaddr
;
11032 push_context (0, lowpc
);
11033 if (die
->child
!= NULL
)
11035 child_die
= die
->child
;
11036 while (child_die
&& child_die
->tag
)
11038 process_die (child_die
, cu
);
11039 child_die
= sibling_die (child_die
);
11042 new = pop_context ();
11044 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
11046 struct block
*block
11047 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
11050 /* Note that recording ranges after traversing children, as we
11051 do here, means that recording a parent's ranges entails
11052 walking across all its children's ranges as they appear in
11053 the address map, which is quadratic behavior.
11055 It would be nicer to record the parent's ranges before
11056 traversing its children, simply overriding whatever you find
11057 there. But since we don't even decide whether to create a
11058 block until after we've traversed its children, that's hard
11060 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11062 local_symbols
= new->locals
;
11063 using_directives
= new->using_directives
;
11066 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
11069 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11071 struct objfile
*objfile
= cu
->objfile
;
11072 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11073 CORE_ADDR pc
, baseaddr
;
11074 struct attribute
*attr
;
11075 struct call_site
*call_site
, call_site_local
;
11078 struct die_info
*child_die
;
11080 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11082 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11085 complaint (&symfile_complaints
,
11086 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
11087 "DIE 0x%x [in module %s]"),
11088 die
->offset
.sect_off
, objfile_name (objfile
));
11091 pc
= DW_ADDR (attr
) + baseaddr
;
11093 if (cu
->call_site_htab
== NULL
)
11094 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
11095 NULL
, &objfile
->objfile_obstack
,
11096 hashtab_obstack_allocate
, NULL
);
11097 call_site_local
.pc
= pc
;
11098 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
11101 complaint (&symfile_complaints
,
11102 _("Duplicate PC %s for DW_TAG_GNU_call_site "
11103 "DIE 0x%x [in module %s]"),
11104 paddress (gdbarch
, pc
), die
->offset
.sect_off
,
11105 objfile_name (objfile
));
11109 /* Count parameters at the caller. */
11112 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11113 child_die
= sibling_die (child_die
))
11115 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11117 complaint (&symfile_complaints
,
11118 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
11119 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11120 child_die
->tag
, child_die
->offset
.sect_off
,
11121 objfile_name (objfile
));
11128 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
11129 (sizeof (*call_site
)
11130 + (sizeof (*call_site
->parameter
)
11131 * (nparams
- 1))));
11133 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
11134 call_site
->pc
= pc
;
11136 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
11138 struct die_info
*func_die
;
11140 /* Skip also over DW_TAG_inlined_subroutine. */
11141 for (func_die
= die
->parent
;
11142 func_die
&& func_die
->tag
!= DW_TAG_subprogram
11143 && func_die
->tag
!= DW_TAG_subroutine_type
;
11144 func_die
= func_die
->parent
);
11146 /* DW_AT_GNU_all_call_sites is a superset
11147 of DW_AT_GNU_all_tail_call_sites. */
11149 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
11150 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
11152 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
11153 not complete. But keep CALL_SITE for look ups via call_site_htab,
11154 both the initial caller containing the real return address PC and
11155 the final callee containing the current PC of a chain of tail
11156 calls do not need to have the tail call list complete. But any
11157 function candidate for a virtual tail call frame searched via
11158 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
11159 determined unambiguously. */
11163 struct type
*func_type
= NULL
;
11166 func_type
= get_die_type (func_die
, cu
);
11167 if (func_type
!= NULL
)
11169 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
11171 /* Enlist this call site to the function. */
11172 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
11173 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
11176 complaint (&symfile_complaints
,
11177 _("Cannot find function owning DW_TAG_GNU_call_site "
11178 "DIE 0x%x [in module %s]"),
11179 die
->offset
.sect_off
, objfile_name (objfile
));
11183 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
11185 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11186 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
11187 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
11188 /* Keep NULL DWARF_BLOCK. */;
11189 else if (attr_form_is_block (attr
))
11191 struct dwarf2_locexpr_baton
*dlbaton
;
11193 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
11194 dlbaton
->data
= DW_BLOCK (attr
)->data
;
11195 dlbaton
->size
= DW_BLOCK (attr
)->size
;
11196 dlbaton
->per_cu
= cu
->per_cu
;
11198 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
11200 else if (attr_form_is_ref (attr
))
11202 struct dwarf2_cu
*target_cu
= cu
;
11203 struct die_info
*target_die
;
11205 target_die
= follow_die_ref (die
, attr
, &target_cu
);
11206 gdb_assert (target_cu
->objfile
== objfile
);
11207 if (die_is_declaration (target_die
, target_cu
))
11209 const char *target_physname
= NULL
;
11210 struct attribute
*target_attr
;
11212 /* Prefer the mangled name; otherwise compute the demangled one. */
11213 target_attr
= dwarf2_attr (target_die
, DW_AT_linkage_name
, target_cu
);
11214 if (target_attr
== NULL
)
11215 target_attr
= dwarf2_attr (target_die
, DW_AT_MIPS_linkage_name
,
11217 if (target_attr
!= NULL
&& DW_STRING (target_attr
) != NULL
)
11218 target_physname
= DW_STRING (target_attr
);
11220 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
11221 if (target_physname
== NULL
)
11222 complaint (&symfile_complaints
,
11223 _("DW_AT_GNU_call_site_target target DIE has invalid "
11224 "physname, for referencing DIE 0x%x [in module %s]"),
11225 die
->offset
.sect_off
, objfile_name (objfile
));
11227 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
11233 /* DW_AT_entry_pc should be preferred. */
11234 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
11235 complaint (&symfile_complaints
,
11236 _("DW_AT_GNU_call_site_target target DIE has invalid "
11237 "low pc, for referencing DIE 0x%x [in module %s]"),
11238 die
->offset
.sect_off
, objfile_name (objfile
));
11240 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
11244 complaint (&symfile_complaints
,
11245 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
11246 "block nor reference, for DIE 0x%x [in module %s]"),
11247 die
->offset
.sect_off
, objfile_name (objfile
));
11249 call_site
->per_cu
= cu
->per_cu
;
11251 for (child_die
= die
->child
;
11252 child_die
&& child_die
->tag
;
11253 child_die
= sibling_die (child_die
))
11255 struct call_site_parameter
*parameter
;
11256 struct attribute
*loc
, *origin
;
11258 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11260 /* Already printed the complaint above. */
11264 gdb_assert (call_site
->parameter_count
< nparams
);
11265 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
11267 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
11268 specifies DW_TAG_formal_parameter. Value of the data assumed for the
11269 register is contained in DW_AT_GNU_call_site_value. */
11271 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
11272 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
11273 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
11275 sect_offset offset
;
11277 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
11278 offset
= dwarf2_get_ref_die_offset (origin
);
11279 if (!offset_in_cu_p (&cu
->header
, offset
))
11281 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
11282 binding can be done only inside one CU. Such referenced DIE
11283 therefore cannot be even moved to DW_TAG_partial_unit. */
11284 complaint (&symfile_complaints
,
11285 _("DW_AT_abstract_origin offset is not in CU for "
11286 "DW_TAG_GNU_call_site child DIE 0x%x "
11288 child_die
->offset
.sect_off
, objfile_name (objfile
));
11291 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
11292 - cu
->header
.offset
.sect_off
);
11294 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
11296 complaint (&symfile_complaints
,
11297 _("No DW_FORM_block* DW_AT_location for "
11298 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11299 child_die
->offset
.sect_off
, objfile_name (objfile
));
11304 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
11305 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
11306 if (parameter
->u
.dwarf_reg
!= -1)
11307 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
11308 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
11309 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
11310 ¶meter
->u
.fb_offset
))
11311 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
11314 complaint (&symfile_complaints
,
11315 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
11316 "for DW_FORM_block* DW_AT_location is supported for "
11317 "DW_TAG_GNU_call_site child DIE 0x%x "
11319 child_die
->offset
.sect_off
, objfile_name (objfile
));
11324 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
11325 if (!attr_form_is_block (attr
))
11327 complaint (&symfile_complaints
,
11328 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
11329 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11330 child_die
->offset
.sect_off
, objfile_name (objfile
));
11333 parameter
->value
= DW_BLOCK (attr
)->data
;
11334 parameter
->value_size
= DW_BLOCK (attr
)->size
;
11336 /* Parameters are not pre-cleared by memset above. */
11337 parameter
->data_value
= NULL
;
11338 parameter
->data_value_size
= 0;
11339 call_site
->parameter_count
++;
11341 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
11344 if (!attr_form_is_block (attr
))
11345 complaint (&symfile_complaints
,
11346 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
11347 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11348 child_die
->offset
.sect_off
, objfile_name (objfile
));
11351 parameter
->data_value
= DW_BLOCK (attr
)->data
;
11352 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
11358 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
11359 Return 1 if the attributes are present and valid, otherwise, return 0.
11360 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
11363 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
11364 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
11365 struct partial_symtab
*ranges_pst
)
11367 struct objfile
*objfile
= cu
->objfile
;
11368 struct comp_unit_head
*cu_header
= &cu
->header
;
11369 bfd
*obfd
= objfile
->obfd
;
11370 unsigned int addr_size
= cu_header
->addr_size
;
11371 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
11372 /* Base address selection entry. */
11375 unsigned int dummy
;
11376 const gdb_byte
*buffer
;
11380 CORE_ADDR high
= 0;
11381 CORE_ADDR baseaddr
;
11383 found_base
= cu
->base_known
;
11384 base
= cu
->base_address
;
11386 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
11387 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
11389 complaint (&symfile_complaints
,
11390 _("Offset %d out of bounds for DW_AT_ranges attribute"),
11394 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
11396 /* Read in the largest possible address. */
11397 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
11398 if ((marker
& mask
) == mask
)
11400 /* If we found the largest possible address, then
11401 read the base address. */
11402 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
11403 buffer
+= 2 * addr_size
;
11404 offset
+= 2 * addr_size
;
11410 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11414 CORE_ADDR range_beginning
, range_end
;
11416 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
11417 buffer
+= addr_size
;
11418 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
11419 buffer
+= addr_size
;
11420 offset
+= 2 * addr_size
;
11422 /* An end of list marker is a pair of zero addresses. */
11423 if (range_beginning
== 0 && range_end
== 0)
11424 /* Found the end of list entry. */
11427 /* Each base address selection entry is a pair of 2 values.
11428 The first is the largest possible address, the second is
11429 the base address. Check for a base address here. */
11430 if ((range_beginning
& mask
) == mask
)
11432 /* If we found the largest possible address, then
11433 read the base address. */
11434 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
11441 /* We have no valid base address for the ranges
11443 complaint (&symfile_complaints
,
11444 _("Invalid .debug_ranges data (no base address)"));
11448 if (range_beginning
> range_end
)
11450 /* Inverted range entries are invalid. */
11451 complaint (&symfile_complaints
,
11452 _("Invalid .debug_ranges data (inverted range)"));
11456 /* Empty range entries have no effect. */
11457 if (range_beginning
== range_end
)
11460 range_beginning
+= base
;
11463 /* A not-uncommon case of bad debug info.
11464 Don't pollute the addrmap with bad data. */
11465 if (range_beginning
+ baseaddr
== 0
11466 && !dwarf2_per_objfile
->has_section_at_zero
)
11468 complaint (&symfile_complaints
,
11469 _(".debug_ranges entry has start address of zero"
11470 " [in module %s]"), objfile_name (objfile
));
11474 if (ranges_pst
!= NULL
)
11475 addrmap_set_empty (objfile
->psymtabs_addrmap
,
11476 range_beginning
+ baseaddr
,
11477 range_end
- 1 + baseaddr
,
11480 /* FIXME: This is recording everything as a low-high
11481 segment of consecutive addresses. We should have a
11482 data structure for discontiguous block ranges
11486 low
= range_beginning
;
11492 if (range_beginning
< low
)
11493 low
= range_beginning
;
11494 if (range_end
> high
)
11500 /* If the first entry is an end-of-list marker, the range
11501 describes an empty scope, i.e. no instructions. */
11507 *high_return
= high
;
11511 /* Get low and high pc attributes from a die. Return 1 if the attributes
11512 are present and valid, otherwise, return 0. Return -1 if the range is
11513 discontinuous, i.e. derived from DW_AT_ranges information. */
11516 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
11517 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
11518 struct partial_symtab
*pst
)
11520 struct attribute
*attr
;
11521 struct attribute
*attr_high
;
11523 CORE_ADDR high
= 0;
11526 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
11529 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11532 low
= DW_ADDR (attr
);
11533 if (attr_high
->form
== DW_FORM_addr
11534 || attr_high
->form
== DW_FORM_GNU_addr_index
)
11535 high
= DW_ADDR (attr_high
);
11537 high
= low
+ DW_UNSND (attr_high
);
11540 /* Found high w/o low attribute. */
11543 /* Found consecutive range of addresses. */
11548 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
11551 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
11552 We take advantage of the fact that DW_AT_ranges does not appear
11553 in DW_TAG_compile_unit of DWO files. */
11554 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
11555 unsigned int ranges_offset
= (DW_UNSND (attr
)
11556 + (need_ranges_base
11560 /* Value of the DW_AT_ranges attribute is the offset in the
11561 .debug_ranges section. */
11562 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
11564 /* Found discontinuous range of addresses. */
11569 /* read_partial_die has also the strict LOW < HIGH requirement. */
11573 /* When using the GNU linker, .gnu.linkonce. sections are used to
11574 eliminate duplicate copies of functions and vtables and such.
11575 The linker will arbitrarily choose one and discard the others.
11576 The AT_*_pc values for such functions refer to local labels in
11577 these sections. If the section from that file was discarded, the
11578 labels are not in the output, so the relocs get a value of 0.
11579 If this is a discarded function, mark the pc bounds as invalid,
11580 so that GDB will ignore it. */
11581 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11590 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
11591 its low and high PC addresses. Do nothing if these addresses could not
11592 be determined. Otherwise, set LOWPC to the low address if it is smaller,
11593 and HIGHPC to the high address if greater than HIGHPC. */
11596 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
11597 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
11598 struct dwarf2_cu
*cu
)
11600 CORE_ADDR low
, high
;
11601 struct die_info
*child
= die
->child
;
11603 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
11605 *lowpc
= min (*lowpc
, low
);
11606 *highpc
= max (*highpc
, high
);
11609 /* If the language does not allow nested subprograms (either inside
11610 subprograms or lexical blocks), we're done. */
11611 if (cu
->language
!= language_ada
)
11614 /* Check all the children of the given DIE. If it contains nested
11615 subprograms, then check their pc bounds. Likewise, we need to
11616 check lexical blocks as well, as they may also contain subprogram
11618 while (child
&& child
->tag
)
11620 if (child
->tag
== DW_TAG_subprogram
11621 || child
->tag
== DW_TAG_lexical_block
)
11622 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
11623 child
= sibling_die (child
);
11627 /* Get the low and high pc's represented by the scope DIE, and store
11628 them in *LOWPC and *HIGHPC. If the correct values can't be
11629 determined, set *LOWPC to -1 and *HIGHPC to 0. */
11632 get_scope_pc_bounds (struct die_info
*die
,
11633 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
11634 struct dwarf2_cu
*cu
)
11636 CORE_ADDR best_low
= (CORE_ADDR
) -1;
11637 CORE_ADDR best_high
= (CORE_ADDR
) 0;
11638 CORE_ADDR current_low
, current_high
;
11640 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
11642 best_low
= current_low
;
11643 best_high
= current_high
;
11647 struct die_info
*child
= die
->child
;
11649 while (child
&& child
->tag
)
11651 switch (child
->tag
) {
11652 case DW_TAG_subprogram
:
11653 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
11655 case DW_TAG_namespace
:
11656 case DW_TAG_module
:
11657 /* FIXME: carlton/2004-01-16: Should we do this for
11658 DW_TAG_class_type/DW_TAG_structure_type, too? I think
11659 that current GCC's always emit the DIEs corresponding
11660 to definitions of methods of classes as children of a
11661 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
11662 the DIEs giving the declarations, which could be
11663 anywhere). But I don't see any reason why the
11664 standards says that they have to be there. */
11665 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
11667 if (current_low
!= ((CORE_ADDR
) -1))
11669 best_low
= min (best_low
, current_low
);
11670 best_high
= max (best_high
, current_high
);
11678 child
= sibling_die (child
);
11683 *highpc
= best_high
;
11686 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
11690 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
11691 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
11693 struct objfile
*objfile
= cu
->objfile
;
11694 struct attribute
*attr
;
11695 struct attribute
*attr_high
;
11697 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
11700 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11703 CORE_ADDR low
= DW_ADDR (attr
);
11705 if (attr_high
->form
== DW_FORM_addr
11706 || attr_high
->form
== DW_FORM_GNU_addr_index
)
11707 high
= DW_ADDR (attr_high
);
11709 high
= low
+ DW_UNSND (attr_high
);
11711 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
11715 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
11718 bfd
*obfd
= objfile
->obfd
;
11719 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
11720 We take advantage of the fact that DW_AT_ranges does not appear
11721 in DW_TAG_compile_unit of DWO files. */
11722 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
11724 /* The value of the DW_AT_ranges attribute is the offset of the
11725 address range list in the .debug_ranges section. */
11726 unsigned long offset
= (DW_UNSND (attr
)
11727 + (need_ranges_base
? cu
->ranges_base
: 0));
11728 const gdb_byte
*buffer
;
11730 /* For some target architectures, but not others, the
11731 read_address function sign-extends the addresses it returns.
11732 To recognize base address selection entries, we need a
11734 unsigned int addr_size
= cu
->header
.addr_size
;
11735 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
11737 /* The base address, to which the next pair is relative. Note
11738 that this 'base' is a DWARF concept: most entries in a range
11739 list are relative, to reduce the number of relocs against the
11740 debugging information. This is separate from this function's
11741 'baseaddr' argument, which GDB uses to relocate debugging
11742 information from a shared library based on the address at
11743 which the library was loaded. */
11744 CORE_ADDR base
= cu
->base_address
;
11745 int base_known
= cu
->base_known
;
11747 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
11748 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
11750 complaint (&symfile_complaints
,
11751 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
11755 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
11759 unsigned int bytes_read
;
11760 CORE_ADDR start
, end
;
11762 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
11763 buffer
+= bytes_read
;
11764 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
11765 buffer
+= bytes_read
;
11767 /* Did we find the end of the range list? */
11768 if (start
== 0 && end
== 0)
11771 /* Did we find a base address selection entry? */
11772 else if ((start
& base_select_mask
) == base_select_mask
)
11778 /* We found an ordinary address range. */
11783 complaint (&symfile_complaints
,
11784 _("Invalid .debug_ranges data "
11785 "(no base address)"));
11791 /* Inverted range entries are invalid. */
11792 complaint (&symfile_complaints
,
11793 _("Invalid .debug_ranges data "
11794 "(inverted range)"));
11798 /* Empty range entries have no effect. */
11802 start
+= base
+ baseaddr
;
11803 end
+= base
+ baseaddr
;
11805 /* A not-uncommon case of bad debug info.
11806 Don't pollute the addrmap with bad data. */
11807 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11809 complaint (&symfile_complaints
,
11810 _(".debug_ranges entry has start address of zero"
11811 " [in module %s]"), objfile_name (objfile
));
11815 record_block_range (block
, start
, end
- 1);
11821 /* Check whether the producer field indicates either of GCC < 4.6, or the
11822 Intel C/C++ compiler, and cache the result in CU. */
11825 check_producer (struct dwarf2_cu
*cu
)
11828 int major
, minor
, release
;
11830 if (cu
->producer
== NULL
)
11832 /* For unknown compilers expect their behavior is DWARF version
11835 GCC started to support .debug_types sections by -gdwarf-4 since
11836 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
11837 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
11838 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
11839 interpreted incorrectly by GDB now - GCC PR debug/48229. */
11841 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
11843 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
11845 cs
= &cu
->producer
[strlen ("GNU ")];
11846 while (*cs
&& !isdigit (*cs
))
11848 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
11850 /* Not recognized as GCC. */
11854 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
11855 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
11858 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
11859 cu
->producer_is_icc
= 1;
11862 /* For other non-GCC compilers, expect their behavior is DWARF version
11866 cu
->checked_producer
= 1;
11869 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
11870 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
11871 during 4.6.0 experimental. */
11874 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
11876 if (!cu
->checked_producer
)
11877 check_producer (cu
);
11879 return cu
->producer_is_gxx_lt_4_6
;
11882 /* Return the default accessibility type if it is not overriden by
11883 DW_AT_accessibility. */
11885 static enum dwarf_access_attribute
11886 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
11888 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
11890 /* The default DWARF 2 accessibility for members is public, the default
11891 accessibility for inheritance is private. */
11893 if (die
->tag
!= DW_TAG_inheritance
)
11894 return DW_ACCESS_public
;
11896 return DW_ACCESS_private
;
11900 /* DWARF 3+ defines the default accessibility a different way. The same
11901 rules apply now for DW_TAG_inheritance as for the members and it only
11902 depends on the container kind. */
11904 if (die
->parent
->tag
== DW_TAG_class_type
)
11905 return DW_ACCESS_private
;
11907 return DW_ACCESS_public
;
11911 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
11912 offset. If the attribute was not found return 0, otherwise return
11913 1. If it was found but could not properly be handled, set *OFFSET
11917 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
11920 struct attribute
*attr
;
11922 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
11927 /* Note that we do not check for a section offset first here.
11928 This is because DW_AT_data_member_location is new in DWARF 4,
11929 so if we see it, we can assume that a constant form is really
11930 a constant and not a section offset. */
11931 if (attr_form_is_constant (attr
))
11932 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
11933 else if (attr_form_is_section_offset (attr
))
11934 dwarf2_complex_location_expr_complaint ();
11935 else if (attr_form_is_block (attr
))
11936 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
11938 dwarf2_complex_location_expr_complaint ();
11946 /* Add an aggregate field to the field list. */
11949 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
11950 struct dwarf2_cu
*cu
)
11952 struct objfile
*objfile
= cu
->objfile
;
11953 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11954 struct nextfield
*new_field
;
11955 struct attribute
*attr
;
11957 const char *fieldname
= "";
11959 /* Allocate a new field list entry and link it in. */
11960 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
11961 make_cleanup (xfree
, new_field
);
11962 memset (new_field
, 0, sizeof (struct nextfield
));
11964 if (die
->tag
== DW_TAG_inheritance
)
11966 new_field
->next
= fip
->baseclasses
;
11967 fip
->baseclasses
= new_field
;
11971 new_field
->next
= fip
->fields
;
11972 fip
->fields
= new_field
;
11976 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
11978 new_field
->accessibility
= DW_UNSND (attr
);
11980 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
11981 if (new_field
->accessibility
!= DW_ACCESS_public
)
11982 fip
->non_public_fields
= 1;
11984 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
11986 new_field
->virtuality
= DW_UNSND (attr
);
11988 new_field
->virtuality
= DW_VIRTUALITY_none
;
11990 fp
= &new_field
->field
;
11992 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
11996 /* Data member other than a C++ static data member. */
11998 /* Get type of field. */
11999 fp
->type
= die_type (die
, cu
);
12001 SET_FIELD_BITPOS (*fp
, 0);
12003 /* Get bit size of field (zero if none). */
12004 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
12007 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
12011 FIELD_BITSIZE (*fp
) = 0;
12014 /* Get bit offset of field. */
12015 if (handle_data_member_location (die
, cu
, &offset
))
12016 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12017 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
12020 if (gdbarch_bits_big_endian (gdbarch
))
12022 /* For big endian bits, the DW_AT_bit_offset gives the
12023 additional bit offset from the MSB of the containing
12024 anonymous object to the MSB of the field. We don't
12025 have to do anything special since we don't need to
12026 know the size of the anonymous object. */
12027 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
12031 /* For little endian bits, compute the bit offset to the
12032 MSB of the anonymous object, subtract off the number of
12033 bits from the MSB of the field to the MSB of the
12034 object, and then subtract off the number of bits of
12035 the field itself. The result is the bit offset of
12036 the LSB of the field. */
12037 int anonymous_size
;
12038 int bit_offset
= DW_UNSND (attr
);
12040 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12043 /* The size of the anonymous object containing
12044 the bit field is explicit, so use the
12045 indicated size (in bytes). */
12046 anonymous_size
= DW_UNSND (attr
);
12050 /* The size of the anonymous object containing
12051 the bit field must be inferred from the type
12052 attribute of the data member containing the
12054 anonymous_size
= TYPE_LENGTH (fp
->type
);
12056 SET_FIELD_BITPOS (*fp
,
12057 (FIELD_BITPOS (*fp
)
12058 + anonymous_size
* bits_per_byte
12059 - bit_offset
- FIELD_BITSIZE (*fp
)));
12063 /* Get name of field. */
12064 fieldname
= dwarf2_name (die
, cu
);
12065 if (fieldname
== NULL
)
12068 /* The name is already allocated along with this objfile, so we don't
12069 need to duplicate it for the type. */
12070 fp
->name
= fieldname
;
12072 /* Change accessibility for artificial fields (e.g. virtual table
12073 pointer or virtual base class pointer) to private. */
12074 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
12076 FIELD_ARTIFICIAL (*fp
) = 1;
12077 new_field
->accessibility
= DW_ACCESS_private
;
12078 fip
->non_public_fields
= 1;
12081 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
12083 /* C++ static member. */
12085 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
12086 is a declaration, but all versions of G++ as of this writing
12087 (so through at least 3.2.1) incorrectly generate
12088 DW_TAG_variable tags. */
12090 const char *physname
;
12092 /* Get name of field. */
12093 fieldname
= dwarf2_name (die
, cu
);
12094 if (fieldname
== NULL
)
12097 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12099 /* Only create a symbol if this is an external value.
12100 new_symbol checks this and puts the value in the global symbol
12101 table, which we want. If it is not external, new_symbol
12102 will try to put the value in cu->list_in_scope which is wrong. */
12103 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
12105 /* A static const member, not much different than an enum as far as
12106 we're concerned, except that we can support more types. */
12107 new_symbol (die
, NULL
, cu
);
12110 /* Get physical name. */
12111 physname
= dwarf2_physname (fieldname
, die
, cu
);
12113 /* The name is already allocated along with this objfile, so we don't
12114 need to duplicate it for the type. */
12115 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
12116 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12117 FIELD_NAME (*fp
) = fieldname
;
12119 else if (die
->tag
== DW_TAG_inheritance
)
12123 /* C++ base class field. */
12124 if (handle_data_member_location (die
, cu
, &offset
))
12125 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12126 FIELD_BITSIZE (*fp
) = 0;
12127 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12128 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
12129 fip
->nbaseclasses
++;
12133 /* Add a typedef defined in the scope of the FIP's class. */
12136 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
12137 struct dwarf2_cu
*cu
)
12139 struct objfile
*objfile
= cu
->objfile
;
12140 struct typedef_field_list
*new_field
;
12141 struct attribute
*attr
;
12142 struct typedef_field
*fp
;
12143 char *fieldname
= "";
12145 /* Allocate a new field list entry and link it in. */
12146 new_field
= xzalloc (sizeof (*new_field
));
12147 make_cleanup (xfree
, new_field
);
12149 gdb_assert (die
->tag
== DW_TAG_typedef
);
12151 fp
= &new_field
->field
;
12153 /* Get name of field. */
12154 fp
->name
= dwarf2_name (die
, cu
);
12155 if (fp
->name
== NULL
)
12158 fp
->type
= read_type_die (die
, cu
);
12160 new_field
->next
= fip
->typedef_field_list
;
12161 fip
->typedef_field_list
= new_field
;
12162 fip
->typedef_field_list_count
++;
12165 /* Create the vector of fields, and attach it to the type. */
12168 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
12169 struct dwarf2_cu
*cu
)
12171 int nfields
= fip
->nfields
;
12173 /* Record the field count, allocate space for the array of fields,
12174 and create blank accessibility bitfields if necessary. */
12175 TYPE_NFIELDS (type
) = nfields
;
12176 TYPE_FIELDS (type
) = (struct field
*)
12177 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
12178 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
12180 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
12182 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12184 TYPE_FIELD_PRIVATE_BITS (type
) =
12185 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12186 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
12188 TYPE_FIELD_PROTECTED_BITS (type
) =
12189 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12190 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
12192 TYPE_FIELD_IGNORE_BITS (type
) =
12193 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12194 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
12197 /* If the type has baseclasses, allocate and clear a bit vector for
12198 TYPE_FIELD_VIRTUAL_BITS. */
12199 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
12201 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
12202 unsigned char *pointer
;
12204 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12205 pointer
= TYPE_ALLOC (type
, num_bytes
);
12206 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
12207 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
12208 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
12211 /* Copy the saved-up fields into the field vector. Start from the head of
12212 the list, adding to the tail of the field array, so that they end up in
12213 the same order in the array in which they were added to the list. */
12214 while (nfields
-- > 0)
12216 struct nextfield
*fieldp
;
12220 fieldp
= fip
->fields
;
12221 fip
->fields
= fieldp
->next
;
12225 fieldp
= fip
->baseclasses
;
12226 fip
->baseclasses
= fieldp
->next
;
12229 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
12230 switch (fieldp
->accessibility
)
12232 case DW_ACCESS_private
:
12233 if (cu
->language
!= language_ada
)
12234 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
12237 case DW_ACCESS_protected
:
12238 if (cu
->language
!= language_ada
)
12239 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
12242 case DW_ACCESS_public
:
12246 /* Unknown accessibility. Complain and treat it as public. */
12248 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
12249 fieldp
->accessibility
);
12253 if (nfields
< fip
->nbaseclasses
)
12255 switch (fieldp
->virtuality
)
12257 case DW_VIRTUALITY_virtual
:
12258 case DW_VIRTUALITY_pure_virtual
:
12259 if (cu
->language
== language_ada
)
12260 error (_("unexpected virtuality in component of Ada type"));
12261 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
12268 /* Return true if this member function is a constructor, false
12272 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
12274 const char *fieldname
;
12275 const char *typename
;
12278 if (die
->parent
== NULL
)
12281 if (die
->parent
->tag
!= DW_TAG_structure_type
12282 && die
->parent
->tag
!= DW_TAG_union_type
12283 && die
->parent
->tag
!= DW_TAG_class_type
)
12286 fieldname
= dwarf2_name (die
, cu
);
12287 typename
= dwarf2_name (die
->parent
, cu
);
12288 if (fieldname
== NULL
|| typename
== NULL
)
12291 len
= strlen (fieldname
);
12292 return (strncmp (fieldname
, typename
, len
) == 0
12293 && (typename
[len
] == '\0' || typename
[len
] == '<'));
12296 /* Add a member function to the proper fieldlist. */
12299 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
12300 struct type
*type
, struct dwarf2_cu
*cu
)
12302 struct objfile
*objfile
= cu
->objfile
;
12303 struct attribute
*attr
;
12304 struct fnfieldlist
*flp
;
12306 struct fn_field
*fnp
;
12307 const char *fieldname
;
12308 struct nextfnfield
*new_fnfield
;
12309 struct type
*this_type
;
12310 enum dwarf_access_attribute accessibility
;
12312 if (cu
->language
== language_ada
)
12313 error (_("unexpected member function in Ada type"));
12315 /* Get name of member function. */
12316 fieldname
= dwarf2_name (die
, cu
);
12317 if (fieldname
== NULL
)
12320 /* Look up member function name in fieldlist. */
12321 for (i
= 0; i
< fip
->nfnfields
; i
++)
12323 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
12327 /* Create new list element if necessary. */
12328 if (i
< fip
->nfnfields
)
12329 flp
= &fip
->fnfieldlists
[i
];
12332 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
12334 fip
->fnfieldlists
= (struct fnfieldlist
*)
12335 xrealloc (fip
->fnfieldlists
,
12336 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
12337 * sizeof (struct fnfieldlist
));
12338 if (fip
->nfnfields
== 0)
12339 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
12341 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
12342 flp
->name
= fieldname
;
12345 i
= fip
->nfnfields
++;
12348 /* Create a new member function field and chain it to the field list
12350 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
12351 make_cleanup (xfree
, new_fnfield
);
12352 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
12353 new_fnfield
->next
= flp
->head
;
12354 flp
->head
= new_fnfield
;
12357 /* Fill in the member function field info. */
12358 fnp
= &new_fnfield
->fnfield
;
12360 /* Delay processing of the physname until later. */
12361 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
12363 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
12368 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
12369 fnp
->physname
= physname
? physname
: "";
12372 fnp
->type
= alloc_type (objfile
);
12373 this_type
= read_type_die (die
, cu
);
12374 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
12376 int nparams
= TYPE_NFIELDS (this_type
);
12378 /* TYPE is the domain of this method, and THIS_TYPE is the type
12379 of the method itself (TYPE_CODE_METHOD). */
12380 smash_to_method_type (fnp
->type
, type
,
12381 TYPE_TARGET_TYPE (this_type
),
12382 TYPE_FIELDS (this_type
),
12383 TYPE_NFIELDS (this_type
),
12384 TYPE_VARARGS (this_type
));
12386 /* Handle static member functions.
12387 Dwarf2 has no clean way to discern C++ static and non-static
12388 member functions. G++ helps GDB by marking the first
12389 parameter for non-static member functions (which is the this
12390 pointer) as artificial. We obtain this information from
12391 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
12392 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
12393 fnp
->voffset
= VOFFSET_STATIC
;
12396 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
12397 dwarf2_full_name (fieldname
, die
, cu
));
12399 /* Get fcontext from DW_AT_containing_type if present. */
12400 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
12401 fnp
->fcontext
= die_containing_type (die
, cu
);
12403 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
12404 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
12406 /* Get accessibility. */
12407 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
12409 accessibility
= DW_UNSND (attr
);
12411 accessibility
= dwarf2_default_access_attribute (die
, cu
);
12412 switch (accessibility
)
12414 case DW_ACCESS_private
:
12415 fnp
->is_private
= 1;
12417 case DW_ACCESS_protected
:
12418 fnp
->is_protected
= 1;
12422 /* Check for artificial methods. */
12423 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
12424 if (attr
&& DW_UNSND (attr
) != 0)
12425 fnp
->is_artificial
= 1;
12427 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
12429 /* Get index in virtual function table if it is a virtual member
12430 function. For older versions of GCC, this is an offset in the
12431 appropriate virtual table, as specified by DW_AT_containing_type.
12432 For everyone else, it is an expression to be evaluated relative
12433 to the object address. */
12435 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
12438 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
12440 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
12442 /* Old-style GCC. */
12443 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
12445 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
12446 || (DW_BLOCK (attr
)->size
> 1
12447 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
12448 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
12450 struct dwarf_block blk
;
12453 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
12455 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
12456 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
12457 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
12458 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
12459 dwarf2_complex_location_expr_complaint ();
12461 fnp
->voffset
/= cu
->header
.addr_size
;
12465 dwarf2_complex_location_expr_complaint ();
12467 if (!fnp
->fcontext
)
12468 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
12470 else if (attr_form_is_section_offset (attr
))
12472 dwarf2_complex_location_expr_complaint ();
12476 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
12482 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
12483 if (attr
&& DW_UNSND (attr
))
12485 /* GCC does this, as of 2008-08-25; PR debug/37237. */
12486 complaint (&symfile_complaints
,
12487 _("Member function \"%s\" (offset %d) is virtual "
12488 "but the vtable offset is not specified"),
12489 fieldname
, die
->offset
.sect_off
);
12490 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12491 TYPE_CPLUS_DYNAMIC (type
) = 1;
12496 /* Create the vector of member function fields, and attach it to the type. */
12499 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
12500 struct dwarf2_cu
*cu
)
12502 struct fnfieldlist
*flp
;
12505 if (cu
->language
== language_ada
)
12506 error (_("unexpected member functions in Ada type"));
12508 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12509 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
12510 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
12512 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
12514 struct nextfnfield
*nfp
= flp
->head
;
12515 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
12518 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
12519 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
12520 fn_flp
->fn_fields
= (struct fn_field
*)
12521 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
12522 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
12523 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
12526 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
12529 /* Returns non-zero if NAME is the name of a vtable member in CU's
12530 language, zero otherwise. */
12532 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
12534 static const char vptr
[] = "_vptr";
12535 static const char vtable
[] = "vtable";
12537 /* Look for the C++ and Java forms of the vtable. */
12538 if ((cu
->language
== language_java
12539 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
12540 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
12541 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
12547 /* GCC outputs unnamed structures that are really pointers to member
12548 functions, with the ABI-specified layout. If TYPE describes
12549 such a structure, smash it into a member function type.
12551 GCC shouldn't do this; it should just output pointer to member DIEs.
12552 This is GCC PR debug/28767. */
12555 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
12557 struct type
*pfn_type
, *domain_type
, *new_type
;
12559 /* Check for a structure with no name and two children. */
12560 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
12563 /* Check for __pfn and __delta members. */
12564 if (TYPE_FIELD_NAME (type
, 0) == NULL
12565 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
12566 || TYPE_FIELD_NAME (type
, 1) == NULL
12567 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
12570 /* Find the type of the method. */
12571 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
12572 if (pfn_type
== NULL
12573 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
12574 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
12577 /* Look for the "this" argument. */
12578 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
12579 if (TYPE_NFIELDS (pfn_type
) == 0
12580 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
12581 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
12584 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
12585 new_type
= alloc_type (objfile
);
12586 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
12587 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
12588 TYPE_VARARGS (pfn_type
));
12589 smash_to_methodptr_type (type
, new_type
);
12592 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
12596 producer_is_icc (struct dwarf2_cu
*cu
)
12598 if (!cu
->checked_producer
)
12599 check_producer (cu
);
12601 return cu
->producer_is_icc
;
12604 /* Called when we find the DIE that starts a structure or union scope
12605 (definition) to create a type for the structure or union. Fill in
12606 the type's name and general properties; the members will not be
12607 processed until process_structure_scope.
12609 NOTE: we need to call these functions regardless of whether or not the
12610 DIE has a DW_AT_name attribute, since it might be an anonymous
12611 structure or union. This gets the type entered into our set of
12612 user defined types.
12614 However, if the structure is incomplete (an opaque struct/union)
12615 then suppress creating a symbol table entry for it since gdb only
12616 wants to find the one with the complete definition. Note that if
12617 it is complete, we just call new_symbol, which does it's own
12618 checking about whether the struct/union is anonymous or not (and
12619 suppresses creating a symbol table entry itself). */
12621 static struct type
*
12622 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12624 struct objfile
*objfile
= cu
->objfile
;
12626 struct attribute
*attr
;
12629 /* If the definition of this type lives in .debug_types, read that type.
12630 Don't follow DW_AT_specification though, that will take us back up
12631 the chain and we want to go down. */
12632 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
12635 type
= get_DW_AT_signature_type (die
, attr
, cu
);
12637 /* The type's CU may not be the same as CU.
12638 Ensure TYPE is recorded with CU in die_type_hash. */
12639 return set_die_type (die
, type
, cu
);
12642 type
= alloc_type (objfile
);
12643 INIT_CPLUS_SPECIFIC (type
);
12645 name
= dwarf2_name (die
, cu
);
12648 if (cu
->language
== language_cplus
12649 || cu
->language
== language_java
)
12651 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
12653 /* dwarf2_full_name might have already finished building the DIE's
12654 type. If so, there is no need to continue. */
12655 if (get_die_type (die
, cu
) != NULL
)
12656 return get_die_type (die
, cu
);
12658 TYPE_TAG_NAME (type
) = full_name
;
12659 if (die
->tag
== DW_TAG_structure_type
12660 || die
->tag
== DW_TAG_class_type
)
12661 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
12665 /* The name is already allocated along with this objfile, so
12666 we don't need to duplicate it for the type. */
12667 TYPE_TAG_NAME (type
) = name
;
12668 if (die
->tag
== DW_TAG_class_type
)
12669 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
12673 if (die
->tag
== DW_TAG_structure_type
)
12675 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
12677 else if (die
->tag
== DW_TAG_union_type
)
12679 TYPE_CODE (type
) = TYPE_CODE_UNION
;
12683 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
12686 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
12687 TYPE_DECLARED_CLASS (type
) = 1;
12689 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12692 TYPE_LENGTH (type
) = DW_UNSND (attr
);
12696 TYPE_LENGTH (type
) = 0;
12699 if (producer_is_icc (cu
))
12701 /* ICC does not output the required DW_AT_declaration
12702 on incomplete types, but gives them a size of zero. */
12705 TYPE_STUB_SUPPORTED (type
) = 1;
12707 if (die_is_declaration (die
, cu
))
12708 TYPE_STUB (type
) = 1;
12709 else if (attr
== NULL
&& die
->child
== NULL
12710 && producer_is_realview (cu
->producer
))
12711 /* RealView does not output the required DW_AT_declaration
12712 on incomplete types. */
12713 TYPE_STUB (type
) = 1;
12715 /* We need to add the type field to the die immediately so we don't
12716 infinitely recurse when dealing with pointers to the structure
12717 type within the structure itself. */
12718 set_die_type (die
, type
, cu
);
12720 /* set_die_type should be already done. */
12721 set_descriptive_type (type
, die
, cu
);
12726 /* Finish creating a structure or union type, including filling in
12727 its members and creating a symbol for it. */
12730 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12732 struct objfile
*objfile
= cu
->objfile
;
12733 struct die_info
*child_die
= die
->child
;
12736 type
= get_die_type (die
, cu
);
12738 type
= read_structure_type (die
, cu
);
12740 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
12742 struct field_info fi
;
12743 struct die_info
*child_die
;
12744 VEC (symbolp
) *template_args
= NULL
;
12745 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
12747 memset (&fi
, 0, sizeof (struct field_info
));
12749 child_die
= die
->child
;
12751 while (child_die
&& child_die
->tag
)
12753 if (child_die
->tag
== DW_TAG_member
12754 || child_die
->tag
== DW_TAG_variable
)
12756 /* NOTE: carlton/2002-11-05: A C++ static data member
12757 should be a DW_TAG_member that is a declaration, but
12758 all versions of G++ as of this writing (so through at
12759 least 3.2.1) incorrectly generate DW_TAG_variable
12760 tags for them instead. */
12761 dwarf2_add_field (&fi
, child_die
, cu
);
12763 else if (child_die
->tag
== DW_TAG_subprogram
)
12765 /* C++ member function. */
12766 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
12768 else if (child_die
->tag
== DW_TAG_inheritance
)
12770 /* C++ base class field. */
12771 dwarf2_add_field (&fi
, child_die
, cu
);
12773 else if (child_die
->tag
== DW_TAG_typedef
)
12774 dwarf2_add_typedef (&fi
, child_die
, cu
);
12775 else if (child_die
->tag
== DW_TAG_template_type_param
12776 || child_die
->tag
== DW_TAG_template_value_param
)
12778 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12781 VEC_safe_push (symbolp
, template_args
, arg
);
12784 child_die
= sibling_die (child_die
);
12787 /* Attach template arguments to type. */
12788 if (! VEC_empty (symbolp
, template_args
))
12790 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12791 TYPE_N_TEMPLATE_ARGUMENTS (type
)
12792 = VEC_length (symbolp
, template_args
);
12793 TYPE_TEMPLATE_ARGUMENTS (type
)
12794 = obstack_alloc (&objfile
->objfile_obstack
,
12795 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
12796 * sizeof (struct symbol
*)));
12797 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
12798 VEC_address (symbolp
, template_args
),
12799 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
12800 * sizeof (struct symbol
*)));
12801 VEC_free (symbolp
, template_args
);
12804 /* Attach fields and member functions to the type. */
12806 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
12809 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
12811 /* Get the type which refers to the base class (possibly this
12812 class itself) which contains the vtable pointer for the current
12813 class from the DW_AT_containing_type attribute. This use of
12814 DW_AT_containing_type is a GNU extension. */
12816 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
12818 struct type
*t
= die_containing_type (die
, cu
);
12820 TYPE_VPTR_BASETYPE (type
) = t
;
12825 /* Our own class provides vtbl ptr. */
12826 for (i
= TYPE_NFIELDS (t
) - 1;
12827 i
>= TYPE_N_BASECLASSES (t
);
12830 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
12832 if (is_vtable_name (fieldname
, cu
))
12834 TYPE_VPTR_FIELDNO (type
) = i
;
12839 /* Complain if virtual function table field not found. */
12840 if (i
< TYPE_N_BASECLASSES (t
))
12841 complaint (&symfile_complaints
,
12842 _("virtual function table pointer "
12843 "not found when defining class '%s'"),
12844 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
12849 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
12852 else if (cu
->producer
12853 && strncmp (cu
->producer
,
12854 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
12856 /* The IBM XLC compiler does not provide direct indication
12857 of the containing type, but the vtable pointer is
12858 always named __vfp. */
12862 for (i
= TYPE_NFIELDS (type
) - 1;
12863 i
>= TYPE_N_BASECLASSES (type
);
12866 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
12868 TYPE_VPTR_FIELDNO (type
) = i
;
12869 TYPE_VPTR_BASETYPE (type
) = type
;
12876 /* Copy fi.typedef_field_list linked list elements content into the
12877 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
12878 if (fi
.typedef_field_list
)
12880 int i
= fi
.typedef_field_list_count
;
12882 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12883 TYPE_TYPEDEF_FIELD_ARRAY (type
)
12884 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
12885 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
12887 /* Reverse the list order to keep the debug info elements order. */
12890 struct typedef_field
*dest
, *src
;
12892 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
12893 src
= &fi
.typedef_field_list
->field
;
12894 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
12899 do_cleanups (back_to
);
12901 if (HAVE_CPLUS_STRUCT (type
))
12902 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
12905 quirk_gcc_member_function_pointer (type
, objfile
);
12907 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
12908 snapshots) has been known to create a die giving a declaration
12909 for a class that has, as a child, a die giving a definition for a
12910 nested class. So we have to process our children even if the
12911 current die is a declaration. Normally, of course, a declaration
12912 won't have any children at all. */
12914 while (child_die
!= NULL
&& child_die
->tag
)
12916 if (child_die
->tag
== DW_TAG_member
12917 || child_die
->tag
== DW_TAG_variable
12918 || child_die
->tag
== DW_TAG_inheritance
12919 || child_die
->tag
== DW_TAG_template_value_param
12920 || child_die
->tag
== DW_TAG_template_type_param
)
12925 process_die (child_die
, cu
);
12927 child_die
= sibling_die (child_die
);
12930 /* Do not consider external references. According to the DWARF standard,
12931 these DIEs are identified by the fact that they have no byte_size
12932 attribute, and a declaration attribute. */
12933 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
12934 || !die_is_declaration (die
, cu
))
12935 new_symbol (die
, type
, cu
);
12938 /* Given a DW_AT_enumeration_type die, set its type. We do not
12939 complete the type's fields yet, or create any symbols. */
12941 static struct type
*
12942 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12944 struct objfile
*objfile
= cu
->objfile
;
12946 struct attribute
*attr
;
12949 /* If the definition of this type lives in .debug_types, read that type.
12950 Don't follow DW_AT_specification though, that will take us back up
12951 the chain and we want to go down. */
12952 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
12955 type
= get_DW_AT_signature_type (die
, attr
, cu
);
12957 /* The type's CU may not be the same as CU.
12958 Ensure TYPE is recorded with CU in die_type_hash. */
12959 return set_die_type (die
, type
, cu
);
12962 type
= alloc_type (objfile
);
12964 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
12965 name
= dwarf2_full_name (NULL
, die
, cu
);
12967 TYPE_TAG_NAME (type
) = name
;
12969 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12972 TYPE_LENGTH (type
) = DW_UNSND (attr
);
12976 TYPE_LENGTH (type
) = 0;
12979 /* The enumeration DIE can be incomplete. In Ada, any type can be
12980 declared as private in the package spec, and then defined only
12981 inside the package body. Such types are known as Taft Amendment
12982 Types. When another package uses such a type, an incomplete DIE
12983 may be generated by the compiler. */
12984 if (die_is_declaration (die
, cu
))
12985 TYPE_STUB (type
) = 1;
12987 return set_die_type (die
, type
, cu
);
12990 /* Given a pointer to a die which begins an enumeration, process all
12991 the dies that define the members of the enumeration, and create the
12992 symbol for the enumeration type.
12994 NOTE: We reverse the order of the element list. */
12997 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12999 struct type
*this_type
;
13001 this_type
= get_die_type (die
, cu
);
13002 if (this_type
== NULL
)
13003 this_type
= read_enumeration_type (die
, cu
);
13005 if (die
->child
!= NULL
)
13007 struct die_info
*child_die
;
13008 struct symbol
*sym
;
13009 struct field
*fields
= NULL
;
13010 int num_fields
= 0;
13011 int unsigned_enum
= 1;
13016 child_die
= die
->child
;
13017 while (child_die
&& child_die
->tag
)
13019 if (child_die
->tag
!= DW_TAG_enumerator
)
13021 process_die (child_die
, cu
);
13025 name
= dwarf2_name (child_die
, cu
);
13028 sym
= new_symbol (child_die
, this_type
, cu
);
13029 if (SYMBOL_VALUE (sym
) < 0)
13034 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
13037 mask
|= SYMBOL_VALUE (sym
);
13039 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
13041 fields
= (struct field
*)
13043 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
13044 * sizeof (struct field
));
13047 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
13048 FIELD_TYPE (fields
[num_fields
]) = NULL
;
13049 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
13050 FIELD_BITSIZE (fields
[num_fields
]) = 0;
13056 child_die
= sibling_die (child_die
);
13061 TYPE_NFIELDS (this_type
) = num_fields
;
13062 TYPE_FIELDS (this_type
) = (struct field
*)
13063 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
13064 memcpy (TYPE_FIELDS (this_type
), fields
,
13065 sizeof (struct field
) * num_fields
);
13069 TYPE_UNSIGNED (this_type
) = 1;
13071 TYPE_FLAG_ENUM (this_type
) = 1;
13074 /* If we are reading an enum from a .debug_types unit, and the enum
13075 is a declaration, and the enum is not the signatured type in the
13076 unit, then we do not want to add a symbol for it. Adding a
13077 symbol would in some cases obscure the true definition of the
13078 enum, giving users an incomplete type when the definition is
13079 actually available. Note that we do not want to do this for all
13080 enums which are just declarations, because C++0x allows forward
13081 enum declarations. */
13082 if (cu
->per_cu
->is_debug_types
13083 && die_is_declaration (die
, cu
))
13085 struct signatured_type
*sig_type
;
13087 sig_type
= (struct signatured_type
*) cu
->per_cu
;
13088 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
13089 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
13093 new_symbol (die
, this_type
, cu
);
13096 /* Extract all information from a DW_TAG_array_type DIE and put it in
13097 the DIE's type field. For now, this only handles one dimensional
13100 static struct type
*
13101 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13103 struct objfile
*objfile
= cu
->objfile
;
13104 struct die_info
*child_die
;
13106 struct type
*element_type
, *range_type
, *index_type
;
13107 struct type
**range_types
= NULL
;
13108 struct attribute
*attr
;
13110 struct cleanup
*back_to
;
13113 element_type
= die_type (die
, cu
);
13115 /* The die_type call above may have already set the type for this DIE. */
13116 type
= get_die_type (die
, cu
);
13120 /* Irix 6.2 native cc creates array types without children for
13121 arrays with unspecified length. */
13122 if (die
->child
== NULL
)
13124 index_type
= objfile_type (objfile
)->builtin_int
;
13125 range_type
= create_range_type (NULL
, index_type
, 0, -1);
13126 type
= create_array_type (NULL
, element_type
, range_type
);
13127 return set_die_type (die
, type
, cu
);
13130 back_to
= make_cleanup (null_cleanup
, NULL
);
13131 child_die
= die
->child
;
13132 while (child_die
&& child_die
->tag
)
13134 if (child_die
->tag
== DW_TAG_subrange_type
)
13136 struct type
*child_type
= read_type_die (child_die
, cu
);
13138 if (child_type
!= NULL
)
13140 /* The range type was succesfully read. Save it for the
13141 array type creation. */
13142 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
13144 range_types
= (struct type
**)
13145 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
13146 * sizeof (struct type
*));
13148 make_cleanup (free_current_contents
, &range_types
);
13150 range_types
[ndim
++] = child_type
;
13153 child_die
= sibling_die (child_die
);
13156 /* Dwarf2 dimensions are output from left to right, create the
13157 necessary array types in backwards order. */
13159 type
= element_type
;
13161 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
13166 type
= create_array_type (NULL
, type
, range_types
[i
++]);
13171 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
13174 /* Understand Dwarf2 support for vector types (like they occur on
13175 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
13176 array type. This is not part of the Dwarf2/3 standard yet, but a
13177 custom vendor extension. The main difference between a regular
13178 array and the vector variant is that vectors are passed by value
13180 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
13182 make_vector_type (type
);
13184 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
13185 implementation may choose to implement triple vectors using this
13187 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13190 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
13191 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13193 complaint (&symfile_complaints
,
13194 _("DW_AT_byte_size for array type smaller "
13195 "than the total size of elements"));
13198 name
= dwarf2_name (die
, cu
);
13200 TYPE_NAME (type
) = name
;
13202 /* Install the type in the die. */
13203 set_die_type (die
, type
, cu
);
13205 /* set_die_type should be already done. */
13206 set_descriptive_type (type
, die
, cu
);
13208 do_cleanups (back_to
);
13213 static enum dwarf_array_dim_ordering
13214 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
13216 struct attribute
*attr
;
13218 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
13220 if (attr
) return DW_SND (attr
);
13222 /* GNU F77 is a special case, as at 08/2004 array type info is the
13223 opposite order to the dwarf2 specification, but data is still
13224 laid out as per normal fortran.
13226 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
13227 version checking. */
13229 if (cu
->language
== language_fortran
13230 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
13232 return DW_ORD_row_major
;
13235 switch (cu
->language_defn
->la_array_ordering
)
13237 case array_column_major
:
13238 return DW_ORD_col_major
;
13239 case array_row_major
:
13241 return DW_ORD_row_major
;
13245 /* Extract all information from a DW_TAG_set_type DIE and put it in
13246 the DIE's type field. */
13248 static struct type
*
13249 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13251 struct type
*domain_type
, *set_type
;
13252 struct attribute
*attr
;
13254 domain_type
= die_type (die
, cu
);
13256 /* The die_type call above may have already set the type for this DIE. */
13257 set_type
= get_die_type (die
, cu
);
13261 set_type
= create_set_type (NULL
, domain_type
);
13263 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13265 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
13267 return set_die_type (die
, set_type
, cu
);
13270 /* A helper for read_common_block that creates a locexpr baton.
13271 SYM is the symbol which we are marking as computed.
13272 COMMON_DIE is the DIE for the common block.
13273 COMMON_LOC is the location expression attribute for the common
13275 MEMBER_LOC is the location expression attribute for the particular
13276 member of the common block that we are processing.
13277 CU is the CU from which the above come. */
13280 mark_common_block_symbol_computed (struct symbol
*sym
,
13281 struct die_info
*common_die
,
13282 struct attribute
*common_loc
,
13283 struct attribute
*member_loc
,
13284 struct dwarf2_cu
*cu
)
13286 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13287 struct dwarf2_locexpr_baton
*baton
;
13289 unsigned int cu_off
;
13290 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
13291 LONGEST offset
= 0;
13293 gdb_assert (common_loc
&& member_loc
);
13294 gdb_assert (attr_form_is_block (common_loc
));
13295 gdb_assert (attr_form_is_block (member_loc
)
13296 || attr_form_is_constant (member_loc
));
13298 baton
= obstack_alloc (&objfile
->objfile_obstack
,
13299 sizeof (struct dwarf2_locexpr_baton
));
13300 baton
->per_cu
= cu
->per_cu
;
13301 gdb_assert (baton
->per_cu
);
13303 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
13305 if (attr_form_is_constant (member_loc
))
13307 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
13308 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
13311 baton
->size
+= DW_BLOCK (member_loc
)->size
;
13313 ptr
= obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
13316 *ptr
++ = DW_OP_call4
;
13317 cu_off
= common_die
->offset
.sect_off
- cu
->per_cu
->offset
.sect_off
;
13318 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
13321 if (attr_form_is_constant (member_loc
))
13323 *ptr
++ = DW_OP_addr
;
13324 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
13325 ptr
+= cu
->header
.addr_size
;
13329 /* We have to copy the data here, because DW_OP_call4 will only
13330 use a DW_AT_location attribute. */
13331 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
13332 ptr
+= DW_BLOCK (member_loc
)->size
;
13335 *ptr
++ = DW_OP_plus
;
13336 gdb_assert (ptr
- baton
->data
== baton
->size
);
13338 SYMBOL_LOCATION_BATON (sym
) = baton
;
13339 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
13342 /* Create appropriate locally-scoped variables for all the
13343 DW_TAG_common_block entries. Also create a struct common_block
13344 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
13345 is used to sepate the common blocks name namespace from regular
13349 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
13351 struct attribute
*attr
;
13353 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13356 /* Support the .debug_loc offsets. */
13357 if (attr_form_is_block (attr
))
13361 else if (attr_form_is_section_offset (attr
))
13363 dwarf2_complex_location_expr_complaint ();
13368 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
13369 "common block member");
13374 if (die
->child
!= NULL
)
13376 struct objfile
*objfile
= cu
->objfile
;
13377 struct die_info
*child_die
;
13378 size_t n_entries
= 0, size
;
13379 struct common_block
*common_block
;
13380 struct symbol
*sym
;
13382 for (child_die
= die
->child
;
13383 child_die
&& child_die
->tag
;
13384 child_die
= sibling_die (child_die
))
13387 size
= (sizeof (struct common_block
)
13388 + (n_entries
- 1) * sizeof (struct symbol
*));
13389 common_block
= obstack_alloc (&objfile
->objfile_obstack
, size
);
13390 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
13391 common_block
->n_entries
= 0;
13393 for (child_die
= die
->child
;
13394 child_die
&& child_die
->tag
;
13395 child_die
= sibling_die (child_die
))
13397 /* Create the symbol in the DW_TAG_common_block block in the current
13399 sym
= new_symbol (child_die
, NULL
, cu
);
13402 struct attribute
*member_loc
;
13404 common_block
->contents
[common_block
->n_entries
++] = sym
;
13406 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
13410 /* GDB has handled this for a long time, but it is
13411 not specified by DWARF. It seems to have been
13412 emitted by gfortran at least as recently as:
13413 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
13414 complaint (&symfile_complaints
,
13415 _("Variable in common block has "
13416 "DW_AT_data_member_location "
13417 "- DIE at 0x%x [in module %s]"),
13418 child_die
->offset
.sect_off
,
13419 objfile_name (cu
->objfile
));
13421 if (attr_form_is_section_offset (member_loc
))
13422 dwarf2_complex_location_expr_complaint ();
13423 else if (attr_form_is_constant (member_loc
)
13424 || attr_form_is_block (member_loc
))
13427 mark_common_block_symbol_computed (sym
, die
, attr
,
13431 dwarf2_complex_location_expr_complaint ();
13436 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
13437 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
13441 /* Create a type for a C++ namespace. */
13443 static struct type
*
13444 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13446 struct objfile
*objfile
= cu
->objfile
;
13447 const char *previous_prefix
, *name
;
13451 /* For extensions, reuse the type of the original namespace. */
13452 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
13454 struct die_info
*ext_die
;
13455 struct dwarf2_cu
*ext_cu
= cu
;
13457 ext_die
= dwarf2_extension (die
, &ext_cu
);
13458 type
= read_type_die (ext_die
, ext_cu
);
13460 /* EXT_CU may not be the same as CU.
13461 Ensure TYPE is recorded with CU in die_type_hash. */
13462 return set_die_type (die
, type
, cu
);
13465 name
= namespace_name (die
, &is_anonymous
, cu
);
13467 /* Now build the name of the current namespace. */
13469 previous_prefix
= determine_prefix (die
, cu
);
13470 if (previous_prefix
[0] != '\0')
13471 name
= typename_concat (&objfile
->objfile_obstack
,
13472 previous_prefix
, name
, 0, cu
);
13474 /* Create the type. */
13475 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
13477 TYPE_NAME (type
) = name
;
13478 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
13480 return set_die_type (die
, type
, cu
);
13483 /* Read a C++ namespace. */
13486 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
13488 struct objfile
*objfile
= cu
->objfile
;
13491 /* Add a symbol associated to this if we haven't seen the namespace
13492 before. Also, add a using directive if it's an anonymous
13495 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
13499 type
= read_type_die (die
, cu
);
13500 new_symbol (die
, type
, cu
);
13502 namespace_name (die
, &is_anonymous
, cu
);
13505 const char *previous_prefix
= determine_prefix (die
, cu
);
13507 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
13508 NULL
, NULL
, 0, &objfile
->objfile_obstack
);
13512 if (die
->child
!= NULL
)
13514 struct die_info
*child_die
= die
->child
;
13516 while (child_die
&& child_die
->tag
)
13518 process_die (child_die
, cu
);
13519 child_die
= sibling_die (child_die
);
13524 /* Read a Fortran module as type. This DIE can be only a declaration used for
13525 imported module. Still we need that type as local Fortran "use ... only"
13526 declaration imports depend on the created type in determine_prefix. */
13528 static struct type
*
13529 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13531 struct objfile
*objfile
= cu
->objfile
;
13532 const char *module_name
;
13535 module_name
= dwarf2_name (die
, cu
);
13537 complaint (&symfile_complaints
,
13538 _("DW_TAG_module has no name, offset 0x%x"),
13539 die
->offset
.sect_off
);
13540 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
13542 /* determine_prefix uses TYPE_TAG_NAME. */
13543 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
13545 return set_die_type (die
, type
, cu
);
13548 /* Read a Fortran module. */
13551 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
13553 struct die_info
*child_die
= die
->child
;
13555 while (child_die
&& child_die
->tag
)
13557 process_die (child_die
, cu
);
13558 child_die
= sibling_die (child_die
);
13562 /* Return the name of the namespace represented by DIE. Set
13563 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
13566 static const char *
13567 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
13569 struct die_info
*current_die
;
13570 const char *name
= NULL
;
13572 /* Loop through the extensions until we find a name. */
13574 for (current_die
= die
;
13575 current_die
!= NULL
;
13576 current_die
= dwarf2_extension (die
, &cu
))
13578 name
= dwarf2_name (current_die
, cu
);
13583 /* Is it an anonymous namespace? */
13585 *is_anonymous
= (name
== NULL
);
13587 name
= CP_ANONYMOUS_NAMESPACE_STR
;
13592 /* Extract all information from a DW_TAG_pointer_type DIE and add to
13593 the user defined type vector. */
13595 static struct type
*
13596 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13598 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
13599 struct comp_unit_head
*cu_header
= &cu
->header
;
13601 struct attribute
*attr_byte_size
;
13602 struct attribute
*attr_address_class
;
13603 int byte_size
, addr_class
;
13604 struct type
*target_type
;
13606 target_type
= die_type (die
, cu
);
13608 /* The die_type call above may have already set the type for this DIE. */
13609 type
= get_die_type (die
, cu
);
13613 type
= lookup_pointer_type (target_type
);
13615 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13616 if (attr_byte_size
)
13617 byte_size
= DW_UNSND (attr_byte_size
);
13619 byte_size
= cu_header
->addr_size
;
13621 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
13622 if (attr_address_class
)
13623 addr_class
= DW_UNSND (attr_address_class
);
13625 addr_class
= DW_ADDR_none
;
13627 /* If the pointer size or address class is different than the
13628 default, create a type variant marked as such and set the
13629 length accordingly. */
13630 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
13632 if (gdbarch_address_class_type_flags_p (gdbarch
))
13636 type_flags
= gdbarch_address_class_type_flags
13637 (gdbarch
, byte_size
, addr_class
);
13638 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
13640 type
= make_type_with_address_space (type
, type_flags
);
13642 else if (TYPE_LENGTH (type
) != byte_size
)
13644 complaint (&symfile_complaints
,
13645 _("invalid pointer size %d"), byte_size
);
13649 /* Should we also complain about unhandled address classes? */
13653 TYPE_LENGTH (type
) = byte_size
;
13654 return set_die_type (die
, type
, cu
);
13657 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
13658 the user defined type vector. */
13660 static struct type
*
13661 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13664 struct type
*to_type
;
13665 struct type
*domain
;
13667 to_type
= die_type (die
, cu
);
13668 domain
= die_containing_type (die
, cu
);
13670 /* The calls above may have already set the type for this DIE. */
13671 type
= get_die_type (die
, cu
);
13675 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
13676 type
= lookup_methodptr_type (to_type
);
13677 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
13679 struct type
*new_type
= alloc_type (cu
->objfile
);
13681 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
13682 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
13683 TYPE_VARARGS (to_type
));
13684 type
= lookup_methodptr_type (new_type
);
13687 type
= lookup_memberptr_type (to_type
, domain
);
13689 return set_die_type (die
, type
, cu
);
13692 /* Extract all information from a DW_TAG_reference_type DIE and add to
13693 the user defined type vector. */
13695 static struct type
*
13696 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13698 struct comp_unit_head
*cu_header
= &cu
->header
;
13699 struct type
*type
, *target_type
;
13700 struct attribute
*attr
;
13702 target_type
= die_type (die
, cu
);
13704 /* The die_type call above may have already set the type for this DIE. */
13705 type
= get_die_type (die
, cu
);
13709 type
= lookup_reference_type (target_type
);
13710 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13713 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13717 TYPE_LENGTH (type
) = cu_header
->addr_size
;
13719 return set_die_type (die
, type
, cu
);
13722 static struct type
*
13723 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13725 struct type
*base_type
, *cv_type
;
13727 base_type
= die_type (die
, cu
);
13729 /* The die_type call above may have already set the type for this DIE. */
13730 cv_type
= get_die_type (die
, cu
);
13734 /* In case the const qualifier is applied to an array type, the element type
13735 is so qualified, not the array type (section 6.7.3 of C99). */
13736 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
13738 struct type
*el_type
, *inner_array
;
13740 base_type
= copy_type (base_type
);
13741 inner_array
= base_type
;
13743 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
13745 TYPE_TARGET_TYPE (inner_array
) =
13746 copy_type (TYPE_TARGET_TYPE (inner_array
));
13747 inner_array
= TYPE_TARGET_TYPE (inner_array
);
13750 el_type
= TYPE_TARGET_TYPE (inner_array
);
13751 TYPE_TARGET_TYPE (inner_array
) =
13752 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
13754 return set_die_type (die
, base_type
, cu
);
13757 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
13758 return set_die_type (die
, cv_type
, cu
);
13761 static struct type
*
13762 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13764 struct type
*base_type
, *cv_type
;
13766 base_type
= die_type (die
, cu
);
13768 /* The die_type call above may have already set the type for this DIE. */
13769 cv_type
= get_die_type (die
, cu
);
13773 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
13774 return set_die_type (die
, cv_type
, cu
);
13777 /* Handle DW_TAG_restrict_type. */
13779 static struct type
*
13780 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13782 struct type
*base_type
, *cv_type
;
13784 base_type
= die_type (die
, cu
);
13786 /* The die_type call above may have already set the type for this DIE. */
13787 cv_type
= get_die_type (die
, cu
);
13791 cv_type
= make_restrict_type (base_type
);
13792 return set_die_type (die
, cv_type
, cu
);
13795 /* Extract all information from a DW_TAG_string_type DIE and add to
13796 the user defined type vector. It isn't really a user defined type,
13797 but it behaves like one, with other DIE's using an AT_user_def_type
13798 attribute to reference it. */
13800 static struct type
*
13801 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13803 struct objfile
*objfile
= cu
->objfile
;
13804 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13805 struct type
*type
, *range_type
, *index_type
, *char_type
;
13806 struct attribute
*attr
;
13807 unsigned int length
;
13809 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
13812 length
= DW_UNSND (attr
);
13816 /* Check for the DW_AT_byte_size attribute. */
13817 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13820 length
= DW_UNSND (attr
);
13828 index_type
= objfile_type (objfile
)->builtin_int
;
13829 range_type
= create_range_type (NULL
, index_type
, 1, length
);
13830 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
13831 type
= create_string_type (NULL
, char_type
, range_type
);
13833 return set_die_type (die
, type
, cu
);
13836 /* Assuming that DIE corresponds to a function, returns nonzero
13837 if the function is prototyped. */
13840 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
13842 struct attribute
*attr
;
13844 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
13845 if (attr
&& (DW_UNSND (attr
) != 0))
13848 /* The DWARF standard implies that the DW_AT_prototyped attribute
13849 is only meaninful for C, but the concept also extends to other
13850 languages that allow unprototyped functions (Eg: Objective C).
13851 For all other languages, assume that functions are always
13853 if (cu
->language
!= language_c
13854 && cu
->language
!= language_objc
13855 && cu
->language
!= language_opencl
)
13858 /* RealView does not emit DW_AT_prototyped. We can not distinguish
13859 prototyped and unprototyped functions; default to prototyped,
13860 since that is more common in modern code (and RealView warns
13861 about unprototyped functions). */
13862 if (producer_is_realview (cu
->producer
))
13868 /* Handle DIES due to C code like:
13872 int (*funcp)(int a, long l);
13876 ('funcp' generates a DW_TAG_subroutine_type DIE). */
13878 static struct type
*
13879 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13881 struct objfile
*objfile
= cu
->objfile
;
13882 struct type
*type
; /* Type that this function returns. */
13883 struct type
*ftype
; /* Function that returns above type. */
13884 struct attribute
*attr
;
13886 type
= die_type (die
, cu
);
13888 /* The die_type call above may have already set the type for this DIE. */
13889 ftype
= get_die_type (die
, cu
);
13893 ftype
= lookup_function_type (type
);
13895 if (prototyped_function_p (die
, cu
))
13896 TYPE_PROTOTYPED (ftype
) = 1;
13898 /* Store the calling convention in the type if it's available in
13899 the subroutine die. Otherwise set the calling convention to
13900 the default value DW_CC_normal. */
13901 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
13903 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
13904 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
13905 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
13907 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
13909 /* We need to add the subroutine type to the die immediately so
13910 we don't infinitely recurse when dealing with parameters
13911 declared as the same subroutine type. */
13912 set_die_type (die
, ftype
, cu
);
13914 if (die
->child
!= NULL
)
13916 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
13917 struct die_info
*child_die
;
13918 int nparams
, iparams
;
13920 /* Count the number of parameters.
13921 FIXME: GDB currently ignores vararg functions, but knows about
13922 vararg member functions. */
13924 child_die
= die
->child
;
13925 while (child_die
&& child_die
->tag
)
13927 if (child_die
->tag
== DW_TAG_formal_parameter
)
13929 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
13930 TYPE_VARARGS (ftype
) = 1;
13931 child_die
= sibling_die (child_die
);
13934 /* Allocate storage for parameters and fill them in. */
13935 TYPE_NFIELDS (ftype
) = nparams
;
13936 TYPE_FIELDS (ftype
) = (struct field
*)
13937 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
13939 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
13940 even if we error out during the parameters reading below. */
13941 for (iparams
= 0; iparams
< nparams
; iparams
++)
13942 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
13945 child_die
= die
->child
;
13946 while (child_die
&& child_die
->tag
)
13948 if (child_die
->tag
== DW_TAG_formal_parameter
)
13950 struct type
*arg_type
;
13952 /* DWARF version 2 has no clean way to discern C++
13953 static and non-static member functions. G++ helps
13954 GDB by marking the first parameter for non-static
13955 member functions (which is the this pointer) as
13956 artificial. We pass this information to
13957 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
13959 DWARF version 3 added DW_AT_object_pointer, which GCC
13960 4.5 does not yet generate. */
13961 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
13963 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
13966 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
13968 /* GCC/43521: In java, the formal parameter
13969 "this" is sometimes not marked with DW_AT_artificial. */
13970 if (cu
->language
== language_java
)
13972 const char *name
= dwarf2_name (child_die
, cu
);
13974 if (name
&& !strcmp (name
, "this"))
13975 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
13978 arg_type
= die_type (child_die
, cu
);
13980 /* RealView does not mark THIS as const, which the testsuite
13981 expects. GCC marks THIS as const in method definitions,
13982 but not in the class specifications (GCC PR 43053). */
13983 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
13984 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
13987 struct dwarf2_cu
*arg_cu
= cu
;
13988 const char *name
= dwarf2_name (child_die
, cu
);
13990 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
13993 /* If the compiler emits this, use it. */
13994 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
13997 else if (name
&& strcmp (name
, "this") == 0)
13998 /* Function definitions will have the argument names. */
14000 else if (name
== NULL
&& iparams
== 0)
14001 /* Declarations may not have the names, so like
14002 elsewhere in GDB, assume an artificial first
14003 argument is "this". */
14007 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
14011 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
14014 child_die
= sibling_die (child_die
);
14021 static struct type
*
14022 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
14024 struct objfile
*objfile
= cu
->objfile
;
14025 const char *name
= NULL
;
14026 struct type
*this_type
, *target_type
;
14028 name
= dwarf2_full_name (NULL
, die
, cu
);
14029 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
14030 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
14031 TYPE_NAME (this_type
) = name
;
14032 set_die_type (die
, this_type
, cu
);
14033 target_type
= die_type (die
, cu
);
14034 if (target_type
!= this_type
)
14035 TYPE_TARGET_TYPE (this_type
) = target_type
;
14038 /* Self-referential typedefs are, it seems, not allowed by the DWARF
14039 spec and cause infinite loops in GDB. */
14040 complaint (&symfile_complaints
,
14041 _("Self-referential DW_TAG_typedef "
14042 "- DIE at 0x%x [in module %s]"),
14043 die
->offset
.sect_off
, objfile_name (objfile
));
14044 TYPE_TARGET_TYPE (this_type
) = NULL
;
14049 /* Find a representation of a given base type and install
14050 it in the TYPE field of the die. */
14052 static struct type
*
14053 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14055 struct objfile
*objfile
= cu
->objfile
;
14057 struct attribute
*attr
;
14058 int encoding
= 0, size
= 0;
14060 enum type_code code
= TYPE_CODE_INT
;
14061 int type_flags
= 0;
14062 struct type
*target_type
= NULL
;
14064 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
14067 encoding
= DW_UNSND (attr
);
14069 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14072 size
= DW_UNSND (attr
);
14074 name
= dwarf2_name (die
, cu
);
14077 complaint (&symfile_complaints
,
14078 _("DW_AT_name missing from DW_TAG_base_type"));
14083 case DW_ATE_address
:
14084 /* Turn DW_ATE_address into a void * pointer. */
14085 code
= TYPE_CODE_PTR
;
14086 type_flags
|= TYPE_FLAG_UNSIGNED
;
14087 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
14089 case DW_ATE_boolean
:
14090 code
= TYPE_CODE_BOOL
;
14091 type_flags
|= TYPE_FLAG_UNSIGNED
;
14093 case DW_ATE_complex_float
:
14094 code
= TYPE_CODE_COMPLEX
;
14095 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
14097 case DW_ATE_decimal_float
:
14098 code
= TYPE_CODE_DECFLOAT
;
14101 code
= TYPE_CODE_FLT
;
14103 case DW_ATE_signed
:
14105 case DW_ATE_unsigned
:
14106 type_flags
|= TYPE_FLAG_UNSIGNED
;
14107 if (cu
->language
== language_fortran
14109 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
14110 code
= TYPE_CODE_CHAR
;
14112 case DW_ATE_signed_char
:
14113 if (cu
->language
== language_ada
|| cu
->language
== language_m2
14114 || cu
->language
== language_pascal
14115 || cu
->language
== language_fortran
)
14116 code
= TYPE_CODE_CHAR
;
14118 case DW_ATE_unsigned_char
:
14119 if (cu
->language
== language_ada
|| cu
->language
== language_m2
14120 || cu
->language
== language_pascal
14121 || cu
->language
== language_fortran
)
14122 code
= TYPE_CODE_CHAR
;
14123 type_flags
|= TYPE_FLAG_UNSIGNED
;
14126 /* We just treat this as an integer and then recognize the
14127 type by name elsewhere. */
14131 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
14132 dwarf_type_encoding_name (encoding
));
14136 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
14137 TYPE_NAME (type
) = name
;
14138 TYPE_TARGET_TYPE (type
) = target_type
;
14140 if (name
&& strcmp (name
, "char") == 0)
14141 TYPE_NOSIGN (type
) = 1;
14143 return set_die_type (die
, type
, cu
);
14146 /* Read the given DW_AT_subrange DIE. */
14148 static struct type
*
14149 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14151 struct type
*base_type
, *orig_base_type
;
14152 struct type
*range_type
;
14153 struct attribute
*attr
;
14155 int low_default_is_valid
;
14157 LONGEST negative_mask
;
14159 orig_base_type
= die_type (die
, cu
);
14160 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
14161 whereas the real type might be. So, we use ORIG_BASE_TYPE when
14162 creating the range type, but we use the result of check_typedef
14163 when examining properties of the type. */
14164 base_type
= check_typedef (orig_base_type
);
14166 /* The die_type call above may have already set the type for this DIE. */
14167 range_type
= get_die_type (die
, cu
);
14171 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
14172 omitting DW_AT_lower_bound. */
14173 switch (cu
->language
)
14176 case language_cplus
:
14178 low_default_is_valid
= 1;
14180 case language_fortran
:
14182 low_default_is_valid
= 1;
14185 case language_java
:
14186 case language_objc
:
14188 low_default_is_valid
= (cu
->header
.version
>= 4);
14192 case language_pascal
:
14194 low_default_is_valid
= (cu
->header
.version
>= 4);
14198 low_default_is_valid
= 0;
14202 /* FIXME: For variable sized arrays either of these could be
14203 a variable rather than a constant value. We'll allow it,
14204 but we don't know how to handle it. */
14205 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
14207 low
= dwarf2_get_attr_constant_value (attr
, low
);
14208 else if (!low_default_is_valid
)
14209 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
14210 "- DIE at 0x%x [in module %s]"),
14211 die
->offset
.sect_off
, objfile_name (cu
->objfile
));
14213 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
14216 if (attr_form_is_block (attr
) || attr_form_is_ref (attr
))
14218 /* GCC encodes arrays with unspecified or dynamic length
14219 with a DW_FORM_block1 attribute or a reference attribute.
14220 FIXME: GDB does not yet know how to handle dynamic
14221 arrays properly, treat them as arrays with unspecified
14224 FIXME: jimb/2003-09-22: GDB does not really know
14225 how to handle arrays of unspecified length
14226 either; we just represent them as zero-length
14227 arrays. Choose an appropriate upper bound given
14228 the lower bound we've computed above. */
14232 high
= dwarf2_get_attr_constant_value (attr
, 1);
14236 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
14239 int count
= dwarf2_get_attr_constant_value (attr
, 1);
14240 high
= low
+ count
- 1;
14244 /* Unspecified array length. */
14249 /* Dwarf-2 specifications explicitly allows to create subrange types
14250 without specifying a base type.
14251 In that case, the base type must be set to the type of
14252 the lower bound, upper bound or count, in that order, if any of these
14253 three attributes references an object that has a type.
14254 If no base type is found, the Dwarf-2 specifications say that
14255 a signed integer type of size equal to the size of an address should
14257 For the following C code: `extern char gdb_int [];'
14258 GCC produces an empty range DIE.
14259 FIXME: muller/2010-05-28: Possible references to object for low bound,
14260 high bound or count are not yet handled by this code. */
14261 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
14263 struct objfile
*objfile
= cu
->objfile
;
14264 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14265 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
14266 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
14268 /* Test "int", "long int", and "long long int" objfile types,
14269 and select the first one having a size above or equal to the
14270 architecture address size. */
14271 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
14272 base_type
= int_type
;
14275 int_type
= objfile_type (objfile
)->builtin_long
;
14276 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
14277 base_type
= int_type
;
14280 int_type
= objfile_type (objfile
)->builtin_long_long
;
14281 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
14282 base_type
= int_type
;
14288 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
14289 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
14290 low
|= negative_mask
;
14291 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
14292 high
|= negative_mask
;
14294 range_type
= create_range_type (NULL
, orig_base_type
, low
, high
);
14296 /* Mark arrays with dynamic length at least as an array of unspecified
14297 length. GDB could check the boundary but before it gets implemented at
14298 least allow accessing the array elements. */
14299 if (attr
&& attr_form_is_block (attr
))
14300 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
14302 /* Ada expects an empty array on no boundary attributes. */
14303 if (attr
== NULL
&& cu
->language
!= language_ada
)
14304 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
14306 name
= dwarf2_name (die
, cu
);
14308 TYPE_NAME (range_type
) = name
;
14310 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14312 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
14314 set_die_type (die
, range_type
, cu
);
14316 /* set_die_type should be already done. */
14317 set_descriptive_type (range_type
, die
, cu
);
14322 static struct type
*
14323 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14327 /* For now, we only support the C meaning of an unspecified type: void. */
14329 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
14330 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
14332 return set_die_type (die
, type
, cu
);
14335 /* Read a single die and all its descendents. Set the die's sibling
14336 field to NULL; set other fields in the die correctly, and set all
14337 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
14338 location of the info_ptr after reading all of those dies. PARENT
14339 is the parent of the die in question. */
14341 static struct die_info
*
14342 read_die_and_children (const struct die_reader_specs
*reader
,
14343 const gdb_byte
*info_ptr
,
14344 const gdb_byte
**new_info_ptr
,
14345 struct die_info
*parent
)
14347 struct die_info
*die
;
14348 const gdb_byte
*cur_ptr
;
14351 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
14354 *new_info_ptr
= cur_ptr
;
14357 store_in_ref_table (die
, reader
->cu
);
14360 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
14364 *new_info_ptr
= cur_ptr
;
14367 die
->sibling
= NULL
;
14368 die
->parent
= parent
;
14372 /* Read a die, all of its descendents, and all of its siblings; set
14373 all of the fields of all of the dies correctly. Arguments are as
14374 in read_die_and_children. */
14376 static struct die_info
*
14377 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
14378 const gdb_byte
*info_ptr
,
14379 const gdb_byte
**new_info_ptr
,
14380 struct die_info
*parent
)
14382 struct die_info
*first_die
, *last_sibling
;
14383 const gdb_byte
*cur_ptr
;
14385 cur_ptr
= info_ptr
;
14386 first_die
= last_sibling
= NULL
;
14390 struct die_info
*die
14391 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
14395 *new_info_ptr
= cur_ptr
;
14402 last_sibling
->sibling
= die
;
14404 last_sibling
= die
;
14408 /* Read a die, all of its descendents, and all of its siblings; set
14409 all of the fields of all of the dies correctly. Arguments are as
14410 in read_die_and_children.
14411 This the main entry point for reading a DIE and all its children. */
14413 static struct die_info
*
14414 read_die_and_siblings (const struct die_reader_specs
*reader
,
14415 const gdb_byte
*info_ptr
,
14416 const gdb_byte
**new_info_ptr
,
14417 struct die_info
*parent
)
14419 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
14420 new_info_ptr
, parent
);
14422 if (dwarf2_die_debug
)
14424 fprintf_unfiltered (gdb_stdlog
,
14425 "Read die from %s@0x%x of %s:\n",
14426 get_section_name (reader
->die_section
),
14427 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
14428 bfd_get_filename (reader
->abfd
));
14429 dump_die (die
, dwarf2_die_debug
);
14435 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
14437 The caller is responsible for filling in the extra attributes
14438 and updating (*DIEP)->num_attrs.
14439 Set DIEP to point to a newly allocated die with its information,
14440 except for its child, sibling, and parent fields.
14441 Set HAS_CHILDREN to tell whether the die has children or not. */
14443 static const gdb_byte
*
14444 read_full_die_1 (const struct die_reader_specs
*reader
,
14445 struct die_info
**diep
, const gdb_byte
*info_ptr
,
14446 int *has_children
, int num_extra_attrs
)
14448 unsigned int abbrev_number
, bytes_read
, i
;
14449 sect_offset offset
;
14450 struct abbrev_info
*abbrev
;
14451 struct die_info
*die
;
14452 struct dwarf2_cu
*cu
= reader
->cu
;
14453 bfd
*abfd
= reader
->abfd
;
14455 offset
.sect_off
= info_ptr
- reader
->buffer
;
14456 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14457 info_ptr
+= bytes_read
;
14458 if (!abbrev_number
)
14465 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
14467 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
14469 bfd_get_filename (abfd
));
14471 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
14472 die
->offset
= offset
;
14473 die
->tag
= abbrev
->tag
;
14474 die
->abbrev
= abbrev_number
;
14476 /* Make the result usable.
14477 The caller needs to update num_attrs after adding the extra
14479 die
->num_attrs
= abbrev
->num_attrs
;
14481 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
14482 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
14486 *has_children
= abbrev
->has_children
;
14490 /* Read a die and all its attributes.
14491 Set DIEP to point to a newly allocated die with its information,
14492 except for its child, sibling, and parent fields.
14493 Set HAS_CHILDREN to tell whether the die has children or not. */
14495 static const gdb_byte
*
14496 read_full_die (const struct die_reader_specs
*reader
,
14497 struct die_info
**diep
, const gdb_byte
*info_ptr
,
14500 const gdb_byte
*result
;
14502 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
14504 if (dwarf2_die_debug
)
14506 fprintf_unfiltered (gdb_stdlog
,
14507 "Read die from %s@0x%x of %s:\n",
14508 get_section_name (reader
->die_section
),
14509 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
14510 bfd_get_filename (reader
->abfd
));
14511 dump_die (*diep
, dwarf2_die_debug
);
14517 /* Abbreviation tables.
14519 In DWARF version 2, the description of the debugging information is
14520 stored in a separate .debug_abbrev section. Before we read any
14521 dies from a section we read in all abbreviations and install them
14522 in a hash table. */
14524 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
14526 static struct abbrev_info
*
14527 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
14529 struct abbrev_info
*abbrev
;
14531 abbrev
= (struct abbrev_info
*)
14532 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
14533 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14537 /* Add an abbreviation to the table. */
14540 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
14541 unsigned int abbrev_number
,
14542 struct abbrev_info
*abbrev
)
14544 unsigned int hash_number
;
14546 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
14547 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
14548 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
14551 /* Look up an abbrev in the table.
14552 Returns NULL if the abbrev is not found. */
14554 static struct abbrev_info
*
14555 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
14556 unsigned int abbrev_number
)
14558 unsigned int hash_number
;
14559 struct abbrev_info
*abbrev
;
14561 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
14562 abbrev
= abbrev_table
->abbrevs
[hash_number
];
14566 if (abbrev
->number
== abbrev_number
)
14568 abbrev
= abbrev
->next
;
14573 /* Read in an abbrev table. */
14575 static struct abbrev_table
*
14576 abbrev_table_read_table (struct dwarf2_section_info
*section
,
14577 sect_offset offset
)
14579 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14580 bfd
*abfd
= get_section_bfd_owner (section
);
14581 struct abbrev_table
*abbrev_table
;
14582 const gdb_byte
*abbrev_ptr
;
14583 struct abbrev_info
*cur_abbrev
;
14584 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
14585 unsigned int abbrev_form
;
14586 struct attr_abbrev
*cur_attrs
;
14587 unsigned int allocated_attrs
;
14589 abbrev_table
= XMALLOC (struct abbrev_table
);
14590 abbrev_table
->offset
= offset
;
14591 obstack_init (&abbrev_table
->abbrev_obstack
);
14592 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
14594 * sizeof (struct abbrev_info
*)));
14595 memset (abbrev_table
->abbrevs
, 0,
14596 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
14598 dwarf2_read_section (objfile
, section
);
14599 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
14600 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
14601 abbrev_ptr
+= bytes_read
;
14603 allocated_attrs
= ATTR_ALLOC_CHUNK
;
14604 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
14606 /* Loop until we reach an abbrev number of 0. */
14607 while (abbrev_number
)
14609 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
14611 /* read in abbrev header */
14612 cur_abbrev
->number
= abbrev_number
;
14613 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
14614 abbrev_ptr
+= bytes_read
;
14615 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
14618 /* now read in declarations */
14619 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
14620 abbrev_ptr
+= bytes_read
;
14621 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
14622 abbrev_ptr
+= bytes_read
;
14623 while (abbrev_name
)
14625 if (cur_abbrev
->num_attrs
== allocated_attrs
)
14627 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
14629 = xrealloc (cur_attrs
, (allocated_attrs
14630 * sizeof (struct attr_abbrev
)));
14633 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
14634 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
14635 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
14636 abbrev_ptr
+= bytes_read
;
14637 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
14638 abbrev_ptr
+= bytes_read
;
14641 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
14642 (cur_abbrev
->num_attrs
14643 * sizeof (struct attr_abbrev
)));
14644 memcpy (cur_abbrev
->attrs
, cur_attrs
,
14645 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
14647 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
14649 /* Get next abbreviation.
14650 Under Irix6 the abbreviations for a compilation unit are not
14651 always properly terminated with an abbrev number of 0.
14652 Exit loop if we encounter an abbreviation which we have
14653 already read (which means we are about to read the abbreviations
14654 for the next compile unit) or if the end of the abbreviation
14655 table is reached. */
14656 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
14658 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
14659 abbrev_ptr
+= bytes_read
;
14660 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
14665 return abbrev_table
;
14668 /* Free the resources held by ABBREV_TABLE. */
14671 abbrev_table_free (struct abbrev_table
*abbrev_table
)
14673 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
14674 xfree (abbrev_table
);
14677 /* Same as abbrev_table_free but as a cleanup.
14678 We pass in a pointer to the pointer to the table so that we can
14679 set the pointer to NULL when we're done. It also simplifies
14680 build_type_unit_groups. */
14683 abbrev_table_free_cleanup (void *table_ptr
)
14685 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
14687 if (*abbrev_table_ptr
!= NULL
)
14688 abbrev_table_free (*abbrev_table_ptr
);
14689 *abbrev_table_ptr
= NULL
;
14692 /* Read the abbrev table for CU from ABBREV_SECTION. */
14695 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
14696 struct dwarf2_section_info
*abbrev_section
)
14699 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
14702 /* Release the memory used by the abbrev table for a compilation unit. */
14705 dwarf2_free_abbrev_table (void *ptr_to_cu
)
14707 struct dwarf2_cu
*cu
= ptr_to_cu
;
14709 if (cu
->abbrev_table
!= NULL
)
14710 abbrev_table_free (cu
->abbrev_table
);
14711 /* Set this to NULL so that we SEGV if we try to read it later,
14712 and also because free_comp_unit verifies this is NULL. */
14713 cu
->abbrev_table
= NULL
;
14716 /* Returns nonzero if TAG represents a type that we might generate a partial
14720 is_type_tag_for_partial (int tag
)
14725 /* Some types that would be reasonable to generate partial symbols for,
14726 that we don't at present. */
14727 case DW_TAG_array_type
:
14728 case DW_TAG_file_type
:
14729 case DW_TAG_ptr_to_member_type
:
14730 case DW_TAG_set_type
:
14731 case DW_TAG_string_type
:
14732 case DW_TAG_subroutine_type
:
14734 case DW_TAG_base_type
:
14735 case DW_TAG_class_type
:
14736 case DW_TAG_interface_type
:
14737 case DW_TAG_enumeration_type
:
14738 case DW_TAG_structure_type
:
14739 case DW_TAG_subrange_type
:
14740 case DW_TAG_typedef
:
14741 case DW_TAG_union_type
:
14748 /* Load all DIEs that are interesting for partial symbols into memory. */
14750 static struct partial_die_info
*
14751 load_partial_dies (const struct die_reader_specs
*reader
,
14752 const gdb_byte
*info_ptr
, int building_psymtab
)
14754 struct dwarf2_cu
*cu
= reader
->cu
;
14755 struct objfile
*objfile
= cu
->objfile
;
14756 struct partial_die_info
*part_die
;
14757 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
14758 struct abbrev_info
*abbrev
;
14759 unsigned int bytes_read
;
14760 unsigned int load_all
= 0;
14761 int nesting_level
= 1;
14766 gdb_assert (cu
->per_cu
!= NULL
);
14767 if (cu
->per_cu
->load_all_dies
)
14771 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14775 &cu
->comp_unit_obstack
,
14776 hashtab_obstack_allocate
,
14777 dummy_obstack_deallocate
);
14779 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
14780 sizeof (struct partial_die_info
));
14784 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
14786 /* A NULL abbrev means the end of a series of children. */
14787 if (abbrev
== NULL
)
14789 if (--nesting_level
== 0)
14791 /* PART_DIE was probably the last thing allocated on the
14792 comp_unit_obstack, so we could call obstack_free
14793 here. We don't do that because the waste is small,
14794 and will be cleaned up when we're done with this
14795 compilation unit. This way, we're also more robust
14796 against other users of the comp_unit_obstack. */
14799 info_ptr
+= bytes_read
;
14800 last_die
= parent_die
;
14801 parent_die
= parent_die
->die_parent
;
14805 /* Check for template arguments. We never save these; if
14806 they're seen, we just mark the parent, and go on our way. */
14807 if (parent_die
!= NULL
14808 && cu
->language
== language_cplus
14809 && (abbrev
->tag
== DW_TAG_template_type_param
14810 || abbrev
->tag
== DW_TAG_template_value_param
))
14812 parent_die
->has_template_arguments
= 1;
14816 /* We don't need a partial DIE for the template argument. */
14817 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
14822 /* We only recurse into c++ subprograms looking for template arguments.
14823 Skip their other children. */
14825 && cu
->language
== language_cplus
14826 && parent_die
!= NULL
14827 && parent_die
->tag
== DW_TAG_subprogram
)
14829 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
14833 /* Check whether this DIE is interesting enough to save. Normally
14834 we would not be interested in members here, but there may be
14835 later variables referencing them via DW_AT_specification (for
14836 static members). */
14838 && !is_type_tag_for_partial (abbrev
->tag
)
14839 && abbrev
->tag
!= DW_TAG_constant
14840 && abbrev
->tag
!= DW_TAG_enumerator
14841 && abbrev
->tag
!= DW_TAG_subprogram
14842 && abbrev
->tag
!= DW_TAG_lexical_block
14843 && abbrev
->tag
!= DW_TAG_variable
14844 && abbrev
->tag
!= DW_TAG_namespace
14845 && abbrev
->tag
!= DW_TAG_module
14846 && abbrev
->tag
!= DW_TAG_member
14847 && abbrev
->tag
!= DW_TAG_imported_unit
)
14849 /* Otherwise we skip to the next sibling, if any. */
14850 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
14854 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
14857 /* This two-pass algorithm for processing partial symbols has a
14858 high cost in cache pressure. Thus, handle some simple cases
14859 here which cover the majority of C partial symbols. DIEs
14860 which neither have specification tags in them, nor could have
14861 specification tags elsewhere pointing at them, can simply be
14862 processed and discarded.
14864 This segment is also optional; scan_partial_symbols and
14865 add_partial_symbol will handle these DIEs if we chain
14866 them in normally. When compilers which do not emit large
14867 quantities of duplicate debug information are more common,
14868 this code can probably be removed. */
14870 /* Any complete simple types at the top level (pretty much all
14871 of them, for a language without namespaces), can be processed
14873 if (parent_die
== NULL
14874 && part_die
->has_specification
== 0
14875 && part_die
->is_declaration
== 0
14876 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
14877 || part_die
->tag
== DW_TAG_base_type
14878 || part_die
->tag
== DW_TAG_subrange_type
))
14880 if (building_psymtab
&& part_die
->name
!= NULL
)
14881 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
14882 VAR_DOMAIN
, LOC_TYPEDEF
,
14883 &objfile
->static_psymbols
,
14884 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
14885 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
14889 /* The exception for DW_TAG_typedef with has_children above is
14890 a workaround of GCC PR debug/47510. In the case of this complaint
14891 type_name_no_tag_or_error will error on such types later.
14893 GDB skipped children of DW_TAG_typedef by the shortcut above and then
14894 it could not find the child DIEs referenced later, this is checked
14895 above. In correct DWARF DW_TAG_typedef should have no children. */
14897 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
14898 complaint (&symfile_complaints
,
14899 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
14900 "- DIE at 0x%x [in module %s]"),
14901 part_die
->offset
.sect_off
, objfile_name (objfile
));
14903 /* If we're at the second level, and we're an enumerator, and
14904 our parent has no specification (meaning possibly lives in a
14905 namespace elsewhere), then we can add the partial symbol now
14906 instead of queueing it. */
14907 if (part_die
->tag
== DW_TAG_enumerator
14908 && parent_die
!= NULL
14909 && parent_die
->die_parent
== NULL
14910 && parent_die
->tag
== DW_TAG_enumeration_type
14911 && parent_die
->has_specification
== 0)
14913 if (part_die
->name
== NULL
)
14914 complaint (&symfile_complaints
,
14915 _("malformed enumerator DIE ignored"));
14916 else if (building_psymtab
)
14917 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
14918 VAR_DOMAIN
, LOC_CONST
,
14919 (cu
->language
== language_cplus
14920 || cu
->language
== language_java
)
14921 ? &objfile
->global_psymbols
14922 : &objfile
->static_psymbols
,
14923 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
14925 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
14929 /* We'll save this DIE so link it in. */
14930 part_die
->die_parent
= parent_die
;
14931 part_die
->die_sibling
= NULL
;
14932 part_die
->die_child
= NULL
;
14934 if (last_die
&& last_die
== parent_die
)
14935 last_die
->die_child
= part_die
;
14937 last_die
->die_sibling
= part_die
;
14939 last_die
= part_die
;
14941 if (first_die
== NULL
)
14942 first_die
= part_die
;
14944 /* Maybe add the DIE to the hash table. Not all DIEs that we
14945 find interesting need to be in the hash table, because we
14946 also have the parent/sibling/child chains; only those that we
14947 might refer to by offset later during partial symbol reading.
14949 For now this means things that might have be the target of a
14950 DW_AT_specification, DW_AT_abstract_origin, or
14951 DW_AT_extension. DW_AT_extension will refer only to
14952 namespaces; DW_AT_abstract_origin refers to functions (and
14953 many things under the function DIE, but we do not recurse
14954 into function DIEs during partial symbol reading) and
14955 possibly variables as well; DW_AT_specification refers to
14956 declarations. Declarations ought to have the DW_AT_declaration
14957 flag. It happens that GCC forgets to put it in sometimes, but
14958 only for functions, not for types.
14960 Adding more things than necessary to the hash table is harmless
14961 except for the performance cost. Adding too few will result in
14962 wasted time in find_partial_die, when we reread the compilation
14963 unit with load_all_dies set. */
14966 || abbrev
->tag
== DW_TAG_constant
14967 || abbrev
->tag
== DW_TAG_subprogram
14968 || abbrev
->tag
== DW_TAG_variable
14969 || abbrev
->tag
== DW_TAG_namespace
14970 || part_die
->is_declaration
)
14974 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
14975 part_die
->offset
.sect_off
, INSERT
);
14979 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
14980 sizeof (struct partial_die_info
));
14982 /* For some DIEs we want to follow their children (if any). For C
14983 we have no reason to follow the children of structures; for other
14984 languages we have to, so that we can get at method physnames
14985 to infer fully qualified class names, for DW_AT_specification,
14986 and for C++ template arguments. For C++, we also look one level
14987 inside functions to find template arguments (if the name of the
14988 function does not already contain the template arguments).
14990 For Ada, we need to scan the children of subprograms and lexical
14991 blocks as well because Ada allows the definition of nested
14992 entities that could be interesting for the debugger, such as
14993 nested subprograms for instance. */
14994 if (last_die
->has_children
14996 || last_die
->tag
== DW_TAG_namespace
14997 || last_die
->tag
== DW_TAG_module
14998 || last_die
->tag
== DW_TAG_enumeration_type
14999 || (cu
->language
== language_cplus
15000 && last_die
->tag
== DW_TAG_subprogram
15001 && (last_die
->name
== NULL
15002 || strchr (last_die
->name
, '<') == NULL
))
15003 || (cu
->language
!= language_c
15004 && (last_die
->tag
== DW_TAG_class_type
15005 || last_die
->tag
== DW_TAG_interface_type
15006 || last_die
->tag
== DW_TAG_structure_type
15007 || last_die
->tag
== DW_TAG_union_type
))
15008 || (cu
->language
== language_ada
15009 && (last_die
->tag
== DW_TAG_subprogram
15010 || last_die
->tag
== DW_TAG_lexical_block
))))
15013 parent_die
= last_die
;
15017 /* Otherwise we skip to the next sibling, if any. */
15018 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
15020 /* Back to the top, do it again. */
15024 /* Read a minimal amount of information into the minimal die structure. */
15026 static const gdb_byte
*
15027 read_partial_die (const struct die_reader_specs
*reader
,
15028 struct partial_die_info
*part_die
,
15029 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
15030 const gdb_byte
*info_ptr
)
15032 struct dwarf2_cu
*cu
= reader
->cu
;
15033 struct objfile
*objfile
= cu
->objfile
;
15034 const gdb_byte
*buffer
= reader
->buffer
;
15036 struct attribute attr
;
15037 int has_low_pc_attr
= 0;
15038 int has_high_pc_attr
= 0;
15039 int high_pc_relative
= 0;
15041 memset (part_die
, 0, sizeof (struct partial_die_info
));
15043 part_die
->offset
.sect_off
= info_ptr
- buffer
;
15045 info_ptr
+= abbrev_len
;
15047 if (abbrev
== NULL
)
15050 part_die
->tag
= abbrev
->tag
;
15051 part_die
->has_children
= abbrev
->has_children
;
15053 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
15055 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
15057 /* Store the data if it is of an attribute we want to keep in a
15058 partial symbol table. */
15062 switch (part_die
->tag
)
15064 case DW_TAG_compile_unit
:
15065 case DW_TAG_partial_unit
:
15066 case DW_TAG_type_unit
:
15067 /* Compilation units have a DW_AT_name that is a filename, not
15068 a source language identifier. */
15069 case DW_TAG_enumeration_type
:
15070 case DW_TAG_enumerator
:
15071 /* These tags always have simple identifiers already; no need
15072 to canonicalize them. */
15073 part_die
->name
= DW_STRING (&attr
);
15077 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
15078 &objfile
->objfile_obstack
);
15082 case DW_AT_linkage_name
:
15083 case DW_AT_MIPS_linkage_name
:
15084 /* Note that both forms of linkage name might appear. We
15085 assume they will be the same, and we only store the last
15087 if (cu
->language
== language_ada
)
15088 part_die
->name
= DW_STRING (&attr
);
15089 part_die
->linkage_name
= DW_STRING (&attr
);
15092 has_low_pc_attr
= 1;
15093 part_die
->lowpc
= DW_ADDR (&attr
);
15095 case DW_AT_high_pc
:
15096 has_high_pc_attr
= 1;
15097 if (attr
.form
== DW_FORM_addr
15098 || attr
.form
== DW_FORM_GNU_addr_index
)
15099 part_die
->highpc
= DW_ADDR (&attr
);
15102 high_pc_relative
= 1;
15103 part_die
->highpc
= DW_UNSND (&attr
);
15106 case DW_AT_location
:
15107 /* Support the .debug_loc offsets. */
15108 if (attr_form_is_block (&attr
))
15110 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
15112 else if (attr_form_is_section_offset (&attr
))
15114 dwarf2_complex_location_expr_complaint ();
15118 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15119 "partial symbol information");
15122 case DW_AT_external
:
15123 part_die
->is_external
= DW_UNSND (&attr
);
15125 case DW_AT_declaration
:
15126 part_die
->is_declaration
= DW_UNSND (&attr
);
15129 part_die
->has_type
= 1;
15131 case DW_AT_abstract_origin
:
15132 case DW_AT_specification
:
15133 case DW_AT_extension
:
15134 part_die
->has_specification
= 1;
15135 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
15136 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
15137 || cu
->per_cu
->is_dwz
);
15139 case DW_AT_sibling
:
15140 /* Ignore absolute siblings, they might point outside of
15141 the current compile unit. */
15142 if (attr
.form
== DW_FORM_ref_addr
)
15143 complaint (&symfile_complaints
,
15144 _("ignoring absolute DW_AT_sibling"));
15147 unsigned int off
= dwarf2_get_ref_die_offset (&attr
).sect_off
;
15148 const gdb_byte
*sibling_ptr
= buffer
+ off
;
15150 if (sibling_ptr
< info_ptr
)
15151 complaint (&symfile_complaints
,
15152 _("DW_AT_sibling points backwards"));
15154 part_die
->sibling
= sibling_ptr
;
15157 case DW_AT_byte_size
:
15158 part_die
->has_byte_size
= 1;
15160 case DW_AT_calling_convention
:
15161 /* DWARF doesn't provide a way to identify a program's source-level
15162 entry point. DW_AT_calling_convention attributes are only meant
15163 to describe functions' calling conventions.
15165 However, because it's a necessary piece of information in
15166 Fortran, and because DW_CC_program is the only piece of debugging
15167 information whose definition refers to a 'main program' at all,
15168 several compilers have begun marking Fortran main programs with
15169 DW_CC_program --- even when those functions use the standard
15170 calling conventions.
15172 So until DWARF specifies a way to provide this information and
15173 compilers pick up the new representation, we'll support this
15175 if (DW_UNSND (&attr
) == DW_CC_program
15176 && cu
->language
== language_fortran
)
15178 set_main_name (part_die
->name
);
15180 /* As this DIE has a static linkage the name would be difficult
15181 to look up later. */
15182 language_of_main
= language_fortran
;
15186 if (DW_UNSND (&attr
) == DW_INL_inlined
15187 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
15188 part_die
->may_be_inlined
= 1;
15192 if (part_die
->tag
== DW_TAG_imported_unit
)
15194 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
15195 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
15196 || cu
->per_cu
->is_dwz
);
15205 if (high_pc_relative
)
15206 part_die
->highpc
+= part_die
->lowpc
;
15208 if (has_low_pc_attr
&& has_high_pc_attr
)
15210 /* When using the GNU linker, .gnu.linkonce. sections are used to
15211 eliminate duplicate copies of functions and vtables and such.
15212 The linker will arbitrarily choose one and discard the others.
15213 The AT_*_pc values for such functions refer to local labels in
15214 these sections. If the section from that file was discarded, the
15215 labels are not in the output, so the relocs get a value of 0.
15216 If this is a discarded function, mark the pc bounds as invalid,
15217 so that GDB will ignore it. */
15218 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
15220 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15222 complaint (&symfile_complaints
,
15223 _("DW_AT_low_pc %s is zero "
15224 "for DIE at 0x%x [in module %s]"),
15225 paddress (gdbarch
, part_die
->lowpc
),
15226 part_die
->offset
.sect_off
, objfile_name (objfile
));
15228 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
15229 else if (part_die
->lowpc
>= part_die
->highpc
)
15231 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15233 complaint (&symfile_complaints
,
15234 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
15235 "for DIE at 0x%x [in module %s]"),
15236 paddress (gdbarch
, part_die
->lowpc
),
15237 paddress (gdbarch
, part_die
->highpc
),
15238 part_die
->offset
.sect_off
, objfile_name (objfile
));
15241 part_die
->has_pc_info
= 1;
15247 /* Find a cached partial DIE at OFFSET in CU. */
15249 static struct partial_die_info
*
15250 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
15252 struct partial_die_info
*lookup_die
= NULL
;
15253 struct partial_die_info part_die
;
15255 part_die
.offset
= offset
;
15256 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
15262 /* Find a partial DIE at OFFSET, which may or may not be in CU,
15263 except in the case of .debug_types DIEs which do not reference
15264 outside their CU (they do however referencing other types via
15265 DW_FORM_ref_sig8). */
15267 static struct partial_die_info
*
15268 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
15270 struct objfile
*objfile
= cu
->objfile
;
15271 struct dwarf2_per_cu_data
*per_cu
= NULL
;
15272 struct partial_die_info
*pd
= NULL
;
15274 if (offset_in_dwz
== cu
->per_cu
->is_dwz
15275 && offset_in_cu_p (&cu
->header
, offset
))
15277 pd
= find_partial_die_in_comp_unit (offset
, cu
);
15280 /* We missed recording what we needed.
15281 Load all dies and try again. */
15282 per_cu
= cu
->per_cu
;
15286 /* TUs don't reference other CUs/TUs (except via type signatures). */
15287 if (cu
->per_cu
->is_debug_types
)
15289 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
15290 " external reference to offset 0x%lx [in module %s].\n"),
15291 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
15292 bfd_get_filename (objfile
->obfd
));
15294 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
15297 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
15298 load_partial_comp_unit (per_cu
);
15300 per_cu
->cu
->last_used
= 0;
15301 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
15304 /* If we didn't find it, and not all dies have been loaded,
15305 load them all and try again. */
15307 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
15309 per_cu
->load_all_dies
= 1;
15311 /* This is nasty. When we reread the DIEs, somewhere up the call chain
15312 THIS_CU->cu may already be in use. So we can't just free it and
15313 replace its DIEs with the ones we read in. Instead, we leave those
15314 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
15315 and clobber THIS_CU->cu->partial_dies with the hash table for the new
15317 load_partial_comp_unit (per_cu
);
15319 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
15323 internal_error (__FILE__
, __LINE__
,
15324 _("could not find partial DIE 0x%x "
15325 "in cache [from module %s]\n"),
15326 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
15330 /* See if we can figure out if the class lives in a namespace. We do
15331 this by looking for a member function; its demangled name will
15332 contain namespace info, if there is any. */
15335 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
15336 struct dwarf2_cu
*cu
)
15338 /* NOTE: carlton/2003-10-07: Getting the info this way changes
15339 what template types look like, because the demangler
15340 frequently doesn't give the same name as the debug info. We
15341 could fix this by only using the demangled name to get the
15342 prefix (but see comment in read_structure_type). */
15344 struct partial_die_info
*real_pdi
;
15345 struct partial_die_info
*child_pdi
;
15347 /* If this DIE (this DIE's specification, if any) has a parent, then
15348 we should not do this. We'll prepend the parent's fully qualified
15349 name when we create the partial symbol. */
15351 real_pdi
= struct_pdi
;
15352 while (real_pdi
->has_specification
)
15353 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
15354 real_pdi
->spec_is_dwz
, cu
);
15356 if (real_pdi
->die_parent
!= NULL
)
15359 for (child_pdi
= struct_pdi
->die_child
;
15361 child_pdi
= child_pdi
->die_sibling
)
15363 if (child_pdi
->tag
== DW_TAG_subprogram
15364 && child_pdi
->linkage_name
!= NULL
)
15366 char *actual_class_name
15367 = language_class_name_from_physname (cu
->language_defn
,
15368 child_pdi
->linkage_name
);
15369 if (actual_class_name
!= NULL
)
15372 = obstack_copy0 (&cu
->objfile
->objfile_obstack
,
15374 strlen (actual_class_name
));
15375 xfree (actual_class_name
);
15382 /* Adjust PART_DIE before generating a symbol for it. This function
15383 may set the is_external flag or change the DIE's name. */
15386 fixup_partial_die (struct partial_die_info
*part_die
,
15387 struct dwarf2_cu
*cu
)
15389 /* Once we've fixed up a die, there's no point in doing so again.
15390 This also avoids a memory leak if we were to call
15391 guess_partial_die_structure_name multiple times. */
15392 if (part_die
->fixup_called
)
15395 /* If we found a reference attribute and the DIE has no name, try
15396 to find a name in the referred to DIE. */
15398 if (part_die
->name
== NULL
&& part_die
->has_specification
)
15400 struct partial_die_info
*spec_die
;
15402 spec_die
= find_partial_die (part_die
->spec_offset
,
15403 part_die
->spec_is_dwz
, cu
);
15405 fixup_partial_die (spec_die
, cu
);
15407 if (spec_die
->name
)
15409 part_die
->name
= spec_die
->name
;
15411 /* Copy DW_AT_external attribute if it is set. */
15412 if (spec_die
->is_external
)
15413 part_die
->is_external
= spec_die
->is_external
;
15417 /* Set default names for some unnamed DIEs. */
15419 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
15420 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
15422 /* If there is no parent die to provide a namespace, and there are
15423 children, see if we can determine the namespace from their linkage
15425 if (cu
->language
== language_cplus
15426 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
15427 && part_die
->die_parent
== NULL
15428 && part_die
->has_children
15429 && (part_die
->tag
== DW_TAG_class_type
15430 || part_die
->tag
== DW_TAG_structure_type
15431 || part_die
->tag
== DW_TAG_union_type
))
15432 guess_partial_die_structure_name (part_die
, cu
);
15434 /* GCC might emit a nameless struct or union that has a linkage
15435 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
15436 if (part_die
->name
== NULL
15437 && (part_die
->tag
== DW_TAG_class_type
15438 || part_die
->tag
== DW_TAG_interface_type
15439 || part_die
->tag
== DW_TAG_structure_type
15440 || part_die
->tag
== DW_TAG_union_type
)
15441 && part_die
->linkage_name
!= NULL
)
15445 demangled
= gdb_demangle (part_die
->linkage_name
, DMGL_TYPES
);
15450 /* Strip any leading namespaces/classes, keep only the base name.
15451 DW_AT_name for named DIEs does not contain the prefixes. */
15452 base
= strrchr (demangled
, ':');
15453 if (base
&& base
> demangled
&& base
[-1] == ':')
15458 part_die
->name
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
15459 base
, strlen (base
));
15464 part_die
->fixup_called
= 1;
15467 /* Read an attribute value described by an attribute form. */
15469 static const gdb_byte
*
15470 read_attribute_value (const struct die_reader_specs
*reader
,
15471 struct attribute
*attr
, unsigned form
,
15472 const gdb_byte
*info_ptr
)
15474 struct dwarf2_cu
*cu
= reader
->cu
;
15475 bfd
*abfd
= reader
->abfd
;
15476 struct comp_unit_head
*cu_header
= &cu
->header
;
15477 unsigned int bytes_read
;
15478 struct dwarf_block
*blk
;
15483 case DW_FORM_ref_addr
:
15484 if (cu
->header
.version
== 2)
15485 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
15487 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
15488 &cu
->header
, &bytes_read
);
15489 info_ptr
+= bytes_read
;
15491 case DW_FORM_GNU_ref_alt
:
15492 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
15493 info_ptr
+= bytes_read
;
15496 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
15497 info_ptr
+= bytes_read
;
15499 case DW_FORM_block2
:
15500 blk
= dwarf_alloc_block (cu
);
15501 blk
->size
= read_2_bytes (abfd
, info_ptr
);
15503 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
15504 info_ptr
+= blk
->size
;
15505 DW_BLOCK (attr
) = blk
;
15507 case DW_FORM_block4
:
15508 blk
= dwarf_alloc_block (cu
);
15509 blk
->size
= read_4_bytes (abfd
, info_ptr
);
15511 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
15512 info_ptr
+= blk
->size
;
15513 DW_BLOCK (attr
) = blk
;
15515 case DW_FORM_data2
:
15516 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
15519 case DW_FORM_data4
:
15520 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
15523 case DW_FORM_data8
:
15524 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
15527 case DW_FORM_sec_offset
:
15528 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
15529 info_ptr
+= bytes_read
;
15531 case DW_FORM_string
:
15532 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
15533 DW_STRING_IS_CANONICAL (attr
) = 0;
15534 info_ptr
+= bytes_read
;
15537 if (!cu
->per_cu
->is_dwz
)
15539 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
15541 DW_STRING_IS_CANONICAL (attr
) = 0;
15542 info_ptr
+= bytes_read
;
15546 case DW_FORM_GNU_strp_alt
:
15548 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
15549 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
15552 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
15553 DW_STRING_IS_CANONICAL (attr
) = 0;
15554 info_ptr
+= bytes_read
;
15557 case DW_FORM_exprloc
:
15558 case DW_FORM_block
:
15559 blk
= dwarf_alloc_block (cu
);
15560 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15561 info_ptr
+= bytes_read
;
15562 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
15563 info_ptr
+= blk
->size
;
15564 DW_BLOCK (attr
) = blk
;
15566 case DW_FORM_block1
:
15567 blk
= dwarf_alloc_block (cu
);
15568 blk
->size
= read_1_byte (abfd
, info_ptr
);
15570 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
15571 info_ptr
+= blk
->size
;
15572 DW_BLOCK (attr
) = blk
;
15574 case DW_FORM_data1
:
15575 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
15579 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
15582 case DW_FORM_flag_present
:
15583 DW_UNSND (attr
) = 1;
15585 case DW_FORM_sdata
:
15586 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
15587 info_ptr
+= bytes_read
;
15589 case DW_FORM_udata
:
15590 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15591 info_ptr
+= bytes_read
;
15594 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
15595 + read_1_byte (abfd
, info_ptr
));
15599 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
15600 + read_2_bytes (abfd
, info_ptr
));
15604 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
15605 + read_4_bytes (abfd
, info_ptr
));
15609 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
15610 + read_8_bytes (abfd
, info_ptr
));
15613 case DW_FORM_ref_sig8
:
15614 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
15617 case DW_FORM_ref_udata
:
15618 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
15619 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
15620 info_ptr
+= bytes_read
;
15622 case DW_FORM_indirect
:
15623 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15624 info_ptr
+= bytes_read
;
15625 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
15627 case DW_FORM_GNU_addr_index
:
15628 if (reader
->dwo_file
== NULL
)
15630 /* For now flag a hard error.
15631 Later we can turn this into a complaint. */
15632 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
15633 dwarf_form_name (form
),
15634 bfd_get_filename (abfd
));
15636 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
15637 info_ptr
+= bytes_read
;
15639 case DW_FORM_GNU_str_index
:
15640 if (reader
->dwo_file
== NULL
)
15642 /* For now flag a hard error.
15643 Later we can turn this into a complaint if warranted. */
15644 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
15645 dwarf_form_name (form
),
15646 bfd_get_filename (abfd
));
15649 ULONGEST str_index
=
15650 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15652 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
15653 DW_STRING_IS_CANONICAL (attr
) = 0;
15654 info_ptr
+= bytes_read
;
15658 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
15659 dwarf_form_name (form
),
15660 bfd_get_filename (abfd
));
15664 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
15665 attr
->form
= DW_FORM_GNU_ref_alt
;
15667 /* We have seen instances where the compiler tried to emit a byte
15668 size attribute of -1 which ended up being encoded as an unsigned
15669 0xffffffff. Although 0xffffffff is technically a valid size value,
15670 an object of this size seems pretty unlikely so we can relatively
15671 safely treat these cases as if the size attribute was invalid and
15672 treat them as zero by default. */
15673 if (attr
->name
== DW_AT_byte_size
15674 && form
== DW_FORM_data4
15675 && DW_UNSND (attr
) >= 0xffffffff)
15678 (&symfile_complaints
,
15679 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
15680 hex_string (DW_UNSND (attr
)));
15681 DW_UNSND (attr
) = 0;
15687 /* Read an attribute described by an abbreviated attribute. */
15689 static const gdb_byte
*
15690 read_attribute (const struct die_reader_specs
*reader
,
15691 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
15692 const gdb_byte
*info_ptr
)
15694 attr
->name
= abbrev
->name
;
15695 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
15698 /* Read dwarf information from a buffer. */
15700 static unsigned int
15701 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
15703 return bfd_get_8 (abfd
, buf
);
15707 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
15709 return bfd_get_signed_8 (abfd
, buf
);
15712 static unsigned int
15713 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
15715 return bfd_get_16 (abfd
, buf
);
15719 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
15721 return bfd_get_signed_16 (abfd
, buf
);
15724 static unsigned int
15725 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
15727 return bfd_get_32 (abfd
, buf
);
15731 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
15733 return bfd_get_signed_32 (abfd
, buf
);
15737 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
15739 return bfd_get_64 (abfd
, buf
);
15743 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
15744 unsigned int *bytes_read
)
15746 struct comp_unit_head
*cu_header
= &cu
->header
;
15747 CORE_ADDR retval
= 0;
15749 if (cu_header
->signed_addr_p
)
15751 switch (cu_header
->addr_size
)
15754 retval
= bfd_get_signed_16 (abfd
, buf
);
15757 retval
= bfd_get_signed_32 (abfd
, buf
);
15760 retval
= bfd_get_signed_64 (abfd
, buf
);
15763 internal_error (__FILE__
, __LINE__
,
15764 _("read_address: bad switch, signed [in module %s]"),
15765 bfd_get_filename (abfd
));
15770 switch (cu_header
->addr_size
)
15773 retval
= bfd_get_16 (abfd
, buf
);
15776 retval
= bfd_get_32 (abfd
, buf
);
15779 retval
= bfd_get_64 (abfd
, buf
);
15782 internal_error (__FILE__
, __LINE__
,
15783 _("read_address: bad switch, "
15784 "unsigned [in module %s]"),
15785 bfd_get_filename (abfd
));
15789 *bytes_read
= cu_header
->addr_size
;
15793 /* Read the initial length from a section. The (draft) DWARF 3
15794 specification allows the initial length to take up either 4 bytes
15795 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
15796 bytes describe the length and all offsets will be 8 bytes in length
15799 An older, non-standard 64-bit format is also handled by this
15800 function. The older format in question stores the initial length
15801 as an 8-byte quantity without an escape value. Lengths greater
15802 than 2^32 aren't very common which means that the initial 4 bytes
15803 is almost always zero. Since a length value of zero doesn't make
15804 sense for the 32-bit format, this initial zero can be considered to
15805 be an escape value which indicates the presence of the older 64-bit
15806 format. As written, the code can't detect (old format) lengths
15807 greater than 4GB. If it becomes necessary to handle lengths
15808 somewhat larger than 4GB, we could allow other small values (such
15809 as the non-sensical values of 1, 2, and 3) to also be used as
15810 escape values indicating the presence of the old format.
15812 The value returned via bytes_read should be used to increment the
15813 relevant pointer after calling read_initial_length().
15815 [ Note: read_initial_length() and read_offset() are based on the
15816 document entitled "DWARF Debugging Information Format", revision
15817 3, draft 8, dated November 19, 2001. This document was obtained
15820 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
15822 This document is only a draft and is subject to change. (So beware.)
15824 Details regarding the older, non-standard 64-bit format were
15825 determined empirically by examining 64-bit ELF files produced by
15826 the SGI toolchain on an IRIX 6.5 machine.
15828 - Kevin, July 16, 2002
15832 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
15834 LONGEST length
= bfd_get_32 (abfd
, buf
);
15836 if (length
== 0xffffffff)
15838 length
= bfd_get_64 (abfd
, buf
+ 4);
15841 else if (length
== 0)
15843 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
15844 length
= bfd_get_64 (abfd
, buf
);
15855 /* Cover function for read_initial_length.
15856 Returns the length of the object at BUF, and stores the size of the
15857 initial length in *BYTES_READ and stores the size that offsets will be in
15859 If the initial length size is not equivalent to that specified in
15860 CU_HEADER then issue a complaint.
15861 This is useful when reading non-comp-unit headers. */
15864 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
15865 const struct comp_unit_head
*cu_header
,
15866 unsigned int *bytes_read
,
15867 unsigned int *offset_size
)
15869 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
15871 gdb_assert (cu_header
->initial_length_size
== 4
15872 || cu_header
->initial_length_size
== 8
15873 || cu_header
->initial_length_size
== 12);
15875 if (cu_header
->initial_length_size
!= *bytes_read
)
15876 complaint (&symfile_complaints
,
15877 _("intermixed 32-bit and 64-bit DWARF sections"));
15879 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
15883 /* Read an offset from the data stream. The size of the offset is
15884 given by cu_header->offset_size. */
15887 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
15888 const struct comp_unit_head
*cu_header
,
15889 unsigned int *bytes_read
)
15891 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
15893 *bytes_read
= cu_header
->offset_size
;
15897 /* Read an offset from the data stream. */
15900 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
15902 LONGEST retval
= 0;
15904 switch (offset_size
)
15907 retval
= bfd_get_32 (abfd
, buf
);
15910 retval
= bfd_get_64 (abfd
, buf
);
15913 internal_error (__FILE__
, __LINE__
,
15914 _("read_offset_1: bad switch [in module %s]"),
15915 bfd_get_filename (abfd
));
15921 static const gdb_byte
*
15922 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
15924 /* If the size of a host char is 8 bits, we can return a pointer
15925 to the buffer, otherwise we have to copy the data to a buffer
15926 allocated on the temporary obstack. */
15927 gdb_assert (HOST_CHAR_BIT
== 8);
15931 static const char *
15932 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
15933 unsigned int *bytes_read_ptr
)
15935 /* If the size of a host char is 8 bits, we can return a pointer
15936 to the string, otherwise we have to copy the string to a buffer
15937 allocated on the temporary obstack. */
15938 gdb_assert (HOST_CHAR_BIT
== 8);
15941 *bytes_read_ptr
= 1;
15944 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
15945 return (const char *) buf
;
15948 static const char *
15949 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
15951 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
15952 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
15953 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
15954 bfd_get_filename (abfd
));
15955 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
15956 error (_("DW_FORM_strp pointing outside of "
15957 ".debug_str section [in module %s]"),
15958 bfd_get_filename (abfd
));
15959 gdb_assert (HOST_CHAR_BIT
== 8);
15960 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
15962 return (const char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
15965 /* Read a string at offset STR_OFFSET in the .debug_str section from
15966 the .dwz file DWZ. Throw an error if the offset is too large. If
15967 the string consists of a single NUL byte, return NULL; otherwise
15968 return a pointer to the string. */
15970 static const char *
15971 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
15973 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
15975 if (dwz
->str
.buffer
== NULL
)
15976 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
15977 "section [in module %s]"),
15978 bfd_get_filename (dwz
->dwz_bfd
));
15979 if (str_offset
>= dwz
->str
.size
)
15980 error (_("DW_FORM_GNU_strp_alt pointing outside of "
15981 ".debug_str section [in module %s]"),
15982 bfd_get_filename (dwz
->dwz_bfd
));
15983 gdb_assert (HOST_CHAR_BIT
== 8);
15984 if (dwz
->str
.buffer
[str_offset
] == '\0')
15986 return (const char *) (dwz
->str
.buffer
+ str_offset
);
15989 static const char *
15990 read_indirect_string (bfd
*abfd
, const gdb_byte
*buf
,
15991 const struct comp_unit_head
*cu_header
,
15992 unsigned int *bytes_read_ptr
)
15994 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
15996 return read_indirect_string_at_offset (abfd
, str_offset
);
16000 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
16001 unsigned int *bytes_read_ptr
)
16004 unsigned int num_read
;
16006 unsigned char byte
;
16014 byte
= bfd_get_8 (abfd
, buf
);
16017 result
|= ((ULONGEST
) (byte
& 127) << shift
);
16018 if ((byte
& 128) == 0)
16024 *bytes_read_ptr
= num_read
;
16029 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
16030 unsigned int *bytes_read_ptr
)
16033 int i
, shift
, num_read
;
16034 unsigned char byte
;
16042 byte
= bfd_get_8 (abfd
, buf
);
16045 result
|= ((LONGEST
) (byte
& 127) << shift
);
16047 if ((byte
& 128) == 0)
16052 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
16053 result
|= -(((LONGEST
) 1) << shift
);
16054 *bytes_read_ptr
= num_read
;
16058 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
16059 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
16060 ADDR_SIZE is the size of addresses from the CU header. */
16063 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
16065 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16066 bfd
*abfd
= objfile
->obfd
;
16067 const gdb_byte
*info_ptr
;
16069 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
16070 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
16071 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
16072 objfile_name (objfile
));
16073 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
16074 error (_("DW_FORM_addr_index pointing outside of "
16075 ".debug_addr section [in module %s]"),
16076 objfile_name (objfile
));
16077 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
16078 + addr_base
+ addr_index
* addr_size
);
16079 if (addr_size
== 4)
16080 return bfd_get_32 (abfd
, info_ptr
);
16082 return bfd_get_64 (abfd
, info_ptr
);
16085 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
16088 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
16090 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
16093 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
16096 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
16097 unsigned int *bytes_read
)
16099 bfd
*abfd
= cu
->objfile
->obfd
;
16100 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
16102 return read_addr_index (cu
, addr_index
);
16105 /* Data structure to pass results from dwarf2_read_addr_index_reader
16106 back to dwarf2_read_addr_index. */
16108 struct dwarf2_read_addr_index_data
16110 ULONGEST addr_base
;
16114 /* die_reader_func for dwarf2_read_addr_index. */
16117 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
16118 const gdb_byte
*info_ptr
,
16119 struct die_info
*comp_unit_die
,
16123 struct dwarf2_cu
*cu
= reader
->cu
;
16124 struct dwarf2_read_addr_index_data
*aidata
=
16125 (struct dwarf2_read_addr_index_data
*) data
;
16127 aidata
->addr_base
= cu
->addr_base
;
16128 aidata
->addr_size
= cu
->header
.addr_size
;
16131 /* Given an index in .debug_addr, fetch the value.
16132 NOTE: This can be called during dwarf expression evaluation,
16133 long after the debug information has been read, and thus per_cu->cu
16134 may no longer exist. */
16137 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
16138 unsigned int addr_index
)
16140 struct objfile
*objfile
= per_cu
->objfile
;
16141 struct dwarf2_cu
*cu
= per_cu
->cu
;
16142 ULONGEST addr_base
;
16145 /* This is intended to be called from outside this file. */
16146 dw2_setup (objfile
);
16148 /* We need addr_base and addr_size.
16149 If we don't have PER_CU->cu, we have to get it.
16150 Nasty, but the alternative is storing the needed info in PER_CU,
16151 which at this point doesn't seem justified: it's not clear how frequently
16152 it would get used and it would increase the size of every PER_CU.
16153 Entry points like dwarf2_per_cu_addr_size do a similar thing
16154 so we're not in uncharted territory here.
16155 Alas we need to be a bit more complicated as addr_base is contained
16158 We don't need to read the entire CU(/TU).
16159 We just need the header and top level die.
16161 IWBN to use the aging mechanism to let us lazily later discard the CU.
16162 For now we skip this optimization. */
16166 addr_base
= cu
->addr_base
;
16167 addr_size
= cu
->header
.addr_size
;
16171 struct dwarf2_read_addr_index_data aidata
;
16173 /* Note: We can't use init_cutu_and_read_dies_simple here,
16174 we need addr_base. */
16175 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
16176 dwarf2_read_addr_index_reader
, &aidata
);
16177 addr_base
= aidata
.addr_base
;
16178 addr_size
= aidata
.addr_size
;
16181 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
16184 /* Given a DW_FORM_GNU_str_index, fetch the string.
16185 This is only used by the Fission support. */
16187 static const char *
16188 read_str_index (const struct die_reader_specs
*reader
,
16189 struct dwarf2_cu
*cu
, ULONGEST str_index
)
16191 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16192 const char *dwo_name
= objfile_name (objfile
);
16193 bfd
*abfd
= objfile
->obfd
;
16194 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
16195 struct dwarf2_section_info
*str_offsets_section
=
16196 &reader
->dwo_file
->sections
.str_offsets
;
16197 const gdb_byte
*info_ptr
;
16198 ULONGEST str_offset
;
16199 static const char form_name
[] = "DW_FORM_GNU_str_index";
16201 dwarf2_read_section (objfile
, str_section
);
16202 dwarf2_read_section (objfile
, str_offsets_section
);
16203 if (str_section
->buffer
== NULL
)
16204 error (_("%s used without .debug_str.dwo section"
16205 " in CU at offset 0x%lx [in module %s]"),
16206 form_name
, (long) cu
->header
.offset
.sect_off
, dwo_name
);
16207 if (str_offsets_section
->buffer
== NULL
)
16208 error (_("%s used without .debug_str_offsets.dwo section"
16209 " in CU at offset 0x%lx [in module %s]"),
16210 form_name
, (long) cu
->header
.offset
.sect_off
, dwo_name
);
16211 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
16212 error (_("%s pointing outside of .debug_str_offsets.dwo"
16213 " section in CU at offset 0x%lx [in module %s]"),
16214 form_name
, (long) cu
->header
.offset
.sect_off
, dwo_name
);
16215 info_ptr
= (str_offsets_section
->buffer
16216 + str_index
* cu
->header
.offset_size
);
16217 if (cu
->header
.offset_size
== 4)
16218 str_offset
= bfd_get_32 (abfd
, info_ptr
);
16220 str_offset
= bfd_get_64 (abfd
, info_ptr
);
16221 if (str_offset
>= str_section
->size
)
16222 error (_("Offset from %s pointing outside of"
16223 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
16224 form_name
, (long) cu
->header
.offset
.sect_off
, dwo_name
);
16225 return (const char *) (str_section
->buffer
+ str_offset
);
16228 /* Return the length of an LEB128 number in BUF. */
16231 leb128_size (const gdb_byte
*buf
)
16233 const gdb_byte
*begin
= buf
;
16239 if ((byte
& 128) == 0)
16240 return buf
- begin
;
16245 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
16253 cu
->language
= language_c
;
16255 case DW_LANG_C_plus_plus
:
16256 cu
->language
= language_cplus
;
16259 cu
->language
= language_d
;
16261 case DW_LANG_Fortran77
:
16262 case DW_LANG_Fortran90
:
16263 case DW_LANG_Fortran95
:
16264 cu
->language
= language_fortran
;
16267 cu
->language
= language_go
;
16269 case DW_LANG_Mips_Assembler
:
16270 cu
->language
= language_asm
;
16273 cu
->language
= language_java
;
16275 case DW_LANG_Ada83
:
16276 case DW_LANG_Ada95
:
16277 cu
->language
= language_ada
;
16279 case DW_LANG_Modula2
:
16280 cu
->language
= language_m2
;
16282 case DW_LANG_Pascal83
:
16283 cu
->language
= language_pascal
;
16286 cu
->language
= language_objc
;
16288 case DW_LANG_Cobol74
:
16289 case DW_LANG_Cobol85
:
16291 cu
->language
= language_minimal
;
16294 cu
->language_defn
= language_def (cu
->language
);
16297 /* Return the named attribute or NULL if not there. */
16299 static struct attribute
*
16300 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
16305 struct attribute
*spec
= NULL
;
16307 for (i
= 0; i
< die
->num_attrs
; ++i
)
16309 if (die
->attrs
[i
].name
== name
)
16310 return &die
->attrs
[i
];
16311 if (die
->attrs
[i
].name
== DW_AT_specification
16312 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
16313 spec
= &die
->attrs
[i
];
16319 die
= follow_die_ref (die
, spec
, &cu
);
16325 /* Return the named attribute or NULL if not there,
16326 but do not follow DW_AT_specification, etc.
16327 This is for use in contexts where we're reading .debug_types dies.
16328 Following DW_AT_specification, DW_AT_abstract_origin will take us
16329 back up the chain, and we want to go down. */
16331 static struct attribute
*
16332 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
16336 for (i
= 0; i
< die
->num_attrs
; ++i
)
16337 if (die
->attrs
[i
].name
== name
)
16338 return &die
->attrs
[i
];
16343 /* Return non-zero iff the attribute NAME is defined for the given DIE,
16344 and holds a non-zero value. This function should only be used for
16345 DW_FORM_flag or DW_FORM_flag_present attributes. */
16348 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
16350 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16352 return (attr
&& DW_UNSND (attr
));
16356 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
16358 /* A DIE is a declaration if it has a DW_AT_declaration attribute
16359 which value is non-zero. However, we have to be careful with
16360 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
16361 (via dwarf2_flag_true_p) follows this attribute. So we may
16362 end up accidently finding a declaration attribute that belongs
16363 to a different DIE referenced by the specification attribute,
16364 even though the given DIE does not have a declaration attribute. */
16365 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
16366 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
16369 /* Return the die giving the specification for DIE, if there is
16370 one. *SPEC_CU is the CU containing DIE on input, and the CU
16371 containing the return value on output. If there is no
16372 specification, but there is an abstract origin, that is
16375 static struct die_info
*
16376 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
16378 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
16381 if (spec_attr
== NULL
)
16382 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
16384 if (spec_attr
== NULL
)
16387 return follow_die_ref (die
, spec_attr
, spec_cu
);
16390 /* Free the line_header structure *LH, and any arrays and strings it
16392 NOTE: This is also used as a "cleanup" function. */
16395 free_line_header (struct line_header
*lh
)
16397 if (lh
->standard_opcode_lengths
)
16398 xfree (lh
->standard_opcode_lengths
);
16400 /* Remember that all the lh->file_names[i].name pointers are
16401 pointers into debug_line_buffer, and don't need to be freed. */
16402 if (lh
->file_names
)
16403 xfree (lh
->file_names
);
16405 /* Similarly for the include directory names. */
16406 if (lh
->include_dirs
)
16407 xfree (lh
->include_dirs
);
16412 /* Add an entry to LH's include directory table. */
16415 add_include_dir (struct line_header
*lh
, const char *include_dir
)
16417 /* Grow the array if necessary. */
16418 if (lh
->include_dirs_size
== 0)
16420 lh
->include_dirs_size
= 1; /* for testing */
16421 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
16422 * sizeof (*lh
->include_dirs
));
16424 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
16426 lh
->include_dirs_size
*= 2;
16427 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
16428 (lh
->include_dirs_size
16429 * sizeof (*lh
->include_dirs
)));
16432 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
16435 /* Add an entry to LH's file name table. */
16438 add_file_name (struct line_header
*lh
,
16440 unsigned int dir_index
,
16441 unsigned int mod_time
,
16442 unsigned int length
)
16444 struct file_entry
*fe
;
16446 /* Grow the array if necessary. */
16447 if (lh
->file_names_size
== 0)
16449 lh
->file_names_size
= 1; /* for testing */
16450 lh
->file_names
= xmalloc (lh
->file_names_size
16451 * sizeof (*lh
->file_names
));
16453 else if (lh
->num_file_names
>= lh
->file_names_size
)
16455 lh
->file_names_size
*= 2;
16456 lh
->file_names
= xrealloc (lh
->file_names
,
16457 (lh
->file_names_size
16458 * sizeof (*lh
->file_names
)));
16461 fe
= &lh
->file_names
[lh
->num_file_names
++];
16463 fe
->dir_index
= dir_index
;
16464 fe
->mod_time
= mod_time
;
16465 fe
->length
= length
;
16466 fe
->included_p
= 0;
16470 /* A convenience function to find the proper .debug_line section for a
16473 static struct dwarf2_section_info
*
16474 get_debug_line_section (struct dwarf2_cu
*cu
)
16476 struct dwarf2_section_info
*section
;
16478 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
16480 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
16481 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
16482 else if (cu
->per_cu
->is_dwz
)
16484 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
16486 section
= &dwz
->line
;
16489 section
= &dwarf2_per_objfile
->line
;
16494 /* Read the statement program header starting at OFFSET in
16495 .debug_line, or .debug_line.dwo. Return a pointer
16496 to a struct line_header, allocated using xmalloc.
16498 NOTE: the strings in the include directory and file name tables of
16499 the returned object point into the dwarf line section buffer,
16500 and must not be freed. */
16502 static struct line_header
*
16503 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
16505 struct cleanup
*back_to
;
16506 struct line_header
*lh
;
16507 const gdb_byte
*line_ptr
;
16508 unsigned int bytes_read
, offset_size
;
16510 const char *cur_dir
, *cur_file
;
16511 struct dwarf2_section_info
*section
;
16514 section
= get_debug_line_section (cu
);
16515 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
16516 if (section
->buffer
== NULL
)
16518 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
16519 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
16521 complaint (&symfile_complaints
, _("missing .debug_line section"));
16525 /* We can't do this until we know the section is non-empty.
16526 Only then do we know we have such a section. */
16527 abfd
= get_section_bfd_owner (section
);
16529 /* Make sure that at least there's room for the total_length field.
16530 That could be 12 bytes long, but we're just going to fudge that. */
16531 if (offset
+ 4 >= section
->size
)
16533 dwarf2_statement_list_fits_in_line_number_section_complaint ();
16537 lh
= xmalloc (sizeof (*lh
));
16538 memset (lh
, 0, sizeof (*lh
));
16539 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
16542 line_ptr
= section
->buffer
+ offset
;
16544 /* Read in the header. */
16546 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
16547 &bytes_read
, &offset_size
);
16548 line_ptr
+= bytes_read
;
16549 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
16551 dwarf2_statement_list_fits_in_line_number_section_complaint ();
16552 do_cleanups (back_to
);
16555 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
16556 lh
->version
= read_2_bytes (abfd
, line_ptr
);
16558 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
16559 line_ptr
+= offset_size
;
16560 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
16562 if (lh
->version
>= 4)
16564 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
16568 lh
->maximum_ops_per_instruction
= 1;
16570 if (lh
->maximum_ops_per_instruction
== 0)
16572 lh
->maximum_ops_per_instruction
= 1;
16573 complaint (&symfile_complaints
,
16574 _("invalid maximum_ops_per_instruction "
16575 "in `.debug_line' section"));
16578 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
16580 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
16582 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
16584 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
16586 lh
->standard_opcode_lengths
16587 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
16589 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
16590 for (i
= 1; i
< lh
->opcode_base
; ++i
)
16592 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
16596 /* Read directory table. */
16597 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
16599 line_ptr
+= bytes_read
;
16600 add_include_dir (lh
, cur_dir
);
16602 line_ptr
+= bytes_read
;
16604 /* Read file name table. */
16605 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
16607 unsigned int dir_index
, mod_time
, length
;
16609 line_ptr
+= bytes_read
;
16610 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16611 line_ptr
+= bytes_read
;
16612 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16613 line_ptr
+= bytes_read
;
16614 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16615 line_ptr
+= bytes_read
;
16617 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
16619 line_ptr
+= bytes_read
;
16620 lh
->statement_program_start
= line_ptr
;
16622 if (line_ptr
> (section
->buffer
+ section
->size
))
16623 complaint (&symfile_complaints
,
16624 _("line number info header doesn't "
16625 "fit in `.debug_line' section"));
16627 discard_cleanups (back_to
);
16631 /* Subroutine of dwarf_decode_lines to simplify it.
16632 Return the file name of the psymtab for included file FILE_INDEX
16633 in line header LH of PST.
16634 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
16635 If space for the result is malloc'd, it will be freed by a cleanup.
16636 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
16638 The function creates dangling cleanup registration. */
16640 static const char *
16641 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
16642 const struct partial_symtab
*pst
,
16643 const char *comp_dir
)
16645 const struct file_entry fe
= lh
->file_names
[file_index
];
16646 const char *include_name
= fe
.name
;
16647 const char *include_name_to_compare
= include_name
;
16648 const char *dir_name
= NULL
;
16649 const char *pst_filename
;
16650 char *copied_name
= NULL
;
16654 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
16656 if (!IS_ABSOLUTE_PATH (include_name
)
16657 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
16659 /* Avoid creating a duplicate psymtab for PST.
16660 We do this by comparing INCLUDE_NAME and PST_FILENAME.
16661 Before we do the comparison, however, we need to account
16662 for DIR_NAME and COMP_DIR.
16663 First prepend dir_name (if non-NULL). If we still don't
16664 have an absolute path prepend comp_dir (if non-NULL).
16665 However, the directory we record in the include-file's
16666 psymtab does not contain COMP_DIR (to match the
16667 corresponding symtab(s)).
16672 bash$ gcc -g ./hello.c
16673 include_name = "hello.c"
16675 DW_AT_comp_dir = comp_dir = "/tmp"
16676 DW_AT_name = "./hello.c" */
16678 if (dir_name
!= NULL
)
16680 char *tem
= concat (dir_name
, SLASH_STRING
,
16681 include_name
, (char *)NULL
);
16683 make_cleanup (xfree
, tem
);
16684 include_name
= tem
;
16685 include_name_to_compare
= include_name
;
16687 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
16689 char *tem
= concat (comp_dir
, SLASH_STRING
,
16690 include_name
, (char *)NULL
);
16692 make_cleanup (xfree
, tem
);
16693 include_name_to_compare
= tem
;
16697 pst_filename
= pst
->filename
;
16698 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
16700 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
16701 pst_filename
, (char *)NULL
);
16702 pst_filename
= copied_name
;
16705 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
16707 if (copied_name
!= NULL
)
16708 xfree (copied_name
);
16712 return include_name
;
16715 /* Ignore this record_line request. */
16718 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
16723 /* Subroutine of dwarf_decode_lines to simplify it.
16724 Process the line number information in LH. */
16727 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
16728 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
16730 const gdb_byte
*line_ptr
, *extended_end
;
16731 const gdb_byte
*line_end
;
16732 unsigned int bytes_read
, extended_len
;
16733 unsigned char op_code
, extended_op
, adj_opcode
;
16734 CORE_ADDR baseaddr
;
16735 struct objfile
*objfile
= cu
->objfile
;
16736 bfd
*abfd
= objfile
->obfd
;
16737 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16738 const int decode_for_pst_p
= (pst
!= NULL
);
16739 struct subfile
*last_subfile
= NULL
;
16740 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
16743 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16745 line_ptr
= lh
->statement_program_start
;
16746 line_end
= lh
->statement_program_end
;
16748 /* Read the statement sequences until there's nothing left. */
16749 while (line_ptr
< line_end
)
16751 /* state machine registers */
16752 CORE_ADDR address
= 0;
16753 unsigned int file
= 1;
16754 unsigned int line
= 1;
16755 unsigned int column
= 0;
16756 int is_stmt
= lh
->default_is_stmt
;
16757 int basic_block
= 0;
16758 int end_sequence
= 0;
16760 unsigned char op_index
= 0;
16762 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
16764 /* Start a subfile for the current file of the state machine. */
16765 /* lh->include_dirs and lh->file_names are 0-based, but the
16766 directory and file name numbers in the statement program
16768 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
16769 const char *dir
= NULL
;
16772 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
16774 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
16777 /* Decode the table. */
16778 while (!end_sequence
)
16780 op_code
= read_1_byte (abfd
, line_ptr
);
16782 if (line_ptr
> line_end
)
16784 dwarf2_debug_line_missing_end_sequence_complaint ();
16788 if (op_code
>= lh
->opcode_base
)
16790 /* Special operand. */
16791 adj_opcode
= op_code
- lh
->opcode_base
;
16792 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
16793 / lh
->maximum_ops_per_instruction
)
16794 * lh
->minimum_instruction_length
);
16795 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
16796 % lh
->maximum_ops_per_instruction
);
16797 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
16798 if (lh
->num_file_names
< file
|| file
== 0)
16799 dwarf2_debug_line_missing_file_complaint ();
16800 /* For now we ignore lines not starting on an
16801 instruction boundary. */
16802 else if (op_index
== 0)
16804 lh
->file_names
[file
- 1].included_p
= 1;
16805 if (!decode_for_pst_p
&& is_stmt
)
16807 if (last_subfile
!= current_subfile
)
16809 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
16811 (*p_record_line
) (last_subfile
, 0, addr
);
16812 last_subfile
= current_subfile
;
16814 /* Append row to matrix using current values. */
16815 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
16816 (*p_record_line
) (current_subfile
, line
, addr
);
16821 else switch (op_code
)
16823 case DW_LNS_extended_op
:
16824 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
16826 line_ptr
+= bytes_read
;
16827 extended_end
= line_ptr
+ extended_len
;
16828 extended_op
= read_1_byte (abfd
, line_ptr
);
16830 switch (extended_op
)
16832 case DW_LNE_end_sequence
:
16833 p_record_line
= record_line
;
16836 case DW_LNE_set_address
:
16837 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
16839 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
16841 /* This line table is for a function which has been
16842 GCd by the linker. Ignore it. PR gdb/12528 */
16845 = line_ptr
- get_debug_line_section (cu
)->buffer
;
16847 complaint (&symfile_complaints
,
16848 _(".debug_line address at offset 0x%lx is 0 "
16850 line_offset
, objfile_name (objfile
));
16851 p_record_line
= noop_record_line
;
16855 line_ptr
+= bytes_read
;
16856 address
+= baseaddr
;
16858 case DW_LNE_define_file
:
16860 const char *cur_file
;
16861 unsigned int dir_index
, mod_time
, length
;
16863 cur_file
= read_direct_string (abfd
, line_ptr
,
16865 line_ptr
+= bytes_read
;
16867 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16868 line_ptr
+= bytes_read
;
16870 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16871 line_ptr
+= bytes_read
;
16873 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16874 line_ptr
+= bytes_read
;
16875 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
16878 case DW_LNE_set_discriminator
:
16879 /* The discriminator is not interesting to the debugger;
16881 line_ptr
= extended_end
;
16884 complaint (&symfile_complaints
,
16885 _("mangled .debug_line section"));
16888 /* Make sure that we parsed the extended op correctly. If e.g.
16889 we expected a different address size than the producer used,
16890 we may have read the wrong number of bytes. */
16891 if (line_ptr
!= extended_end
)
16893 complaint (&symfile_complaints
,
16894 _("mangled .debug_line section"));
16899 if (lh
->num_file_names
< file
|| file
== 0)
16900 dwarf2_debug_line_missing_file_complaint ();
16903 lh
->file_names
[file
- 1].included_p
= 1;
16904 if (!decode_for_pst_p
&& is_stmt
)
16906 if (last_subfile
!= current_subfile
)
16908 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
16910 (*p_record_line
) (last_subfile
, 0, addr
);
16911 last_subfile
= current_subfile
;
16913 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
16914 (*p_record_line
) (current_subfile
, line
, addr
);
16919 case DW_LNS_advance_pc
:
16922 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16924 address
+= (((op_index
+ adjust
)
16925 / lh
->maximum_ops_per_instruction
)
16926 * lh
->minimum_instruction_length
);
16927 op_index
= ((op_index
+ adjust
)
16928 % lh
->maximum_ops_per_instruction
);
16929 line_ptr
+= bytes_read
;
16932 case DW_LNS_advance_line
:
16933 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
16934 line_ptr
+= bytes_read
;
16936 case DW_LNS_set_file
:
16938 /* The arrays lh->include_dirs and lh->file_names are
16939 0-based, but the directory and file name numbers in
16940 the statement program are 1-based. */
16941 struct file_entry
*fe
;
16942 const char *dir
= NULL
;
16944 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16945 line_ptr
+= bytes_read
;
16946 if (lh
->num_file_names
< file
|| file
== 0)
16947 dwarf2_debug_line_missing_file_complaint ();
16950 fe
= &lh
->file_names
[file
- 1];
16952 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
16953 if (!decode_for_pst_p
)
16955 last_subfile
= current_subfile
;
16956 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
16961 case DW_LNS_set_column
:
16962 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16963 line_ptr
+= bytes_read
;
16965 case DW_LNS_negate_stmt
:
16966 is_stmt
= (!is_stmt
);
16968 case DW_LNS_set_basic_block
:
16971 /* Add to the address register of the state machine the
16972 address increment value corresponding to special opcode
16973 255. I.e., this value is scaled by the minimum
16974 instruction length since special opcode 255 would have
16975 scaled the increment. */
16976 case DW_LNS_const_add_pc
:
16978 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
16980 address
+= (((op_index
+ adjust
)
16981 / lh
->maximum_ops_per_instruction
)
16982 * lh
->minimum_instruction_length
);
16983 op_index
= ((op_index
+ adjust
)
16984 % lh
->maximum_ops_per_instruction
);
16987 case DW_LNS_fixed_advance_pc
:
16988 address
+= read_2_bytes (abfd
, line_ptr
);
16994 /* Unknown standard opcode, ignore it. */
16997 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
16999 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17000 line_ptr
+= bytes_read
;
17005 if (lh
->num_file_names
< file
|| file
== 0)
17006 dwarf2_debug_line_missing_file_complaint ();
17009 lh
->file_names
[file
- 1].included_p
= 1;
17010 if (!decode_for_pst_p
)
17012 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
17013 (*p_record_line
) (current_subfile
, 0, addr
);
17019 /* Decode the Line Number Program (LNP) for the given line_header
17020 structure and CU. The actual information extracted and the type
17021 of structures created from the LNP depends on the value of PST.
17023 1. If PST is NULL, then this procedure uses the data from the program
17024 to create all necessary symbol tables, and their linetables.
17026 2. If PST is not NULL, this procedure reads the program to determine
17027 the list of files included by the unit represented by PST, and
17028 builds all the associated partial symbol tables.
17030 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
17031 It is used for relative paths in the line table.
17032 NOTE: When processing partial symtabs (pst != NULL),
17033 comp_dir == pst->dirname.
17035 NOTE: It is important that psymtabs have the same file name (via strcmp)
17036 as the corresponding symtab. Since COMP_DIR is not used in the name of the
17037 symtab we don't use it in the name of the psymtabs we create.
17038 E.g. expand_line_sal requires this when finding psymtabs to expand.
17039 A good testcase for this is mb-inline.exp. */
17042 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
17043 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
17044 int want_line_info
)
17046 struct objfile
*objfile
= cu
->objfile
;
17047 const int decode_for_pst_p
= (pst
!= NULL
);
17048 struct subfile
*first_subfile
= current_subfile
;
17050 if (want_line_info
)
17051 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
17053 if (decode_for_pst_p
)
17057 /* Now that we're done scanning the Line Header Program, we can
17058 create the psymtab of each included file. */
17059 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
17060 if (lh
->file_names
[file_index
].included_p
== 1)
17062 const char *include_name
=
17063 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
17064 if (include_name
!= NULL
)
17065 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
17070 /* Make sure a symtab is created for every file, even files
17071 which contain only variables (i.e. no code with associated
17075 for (i
= 0; i
< lh
->num_file_names
; i
++)
17077 const char *dir
= NULL
;
17078 struct file_entry
*fe
;
17080 fe
= &lh
->file_names
[i
];
17082 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
17083 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
17085 /* Skip the main file; we don't need it, and it must be
17086 allocated last, so that it will show up before the
17087 non-primary symtabs in the objfile's symtab list. */
17088 if (current_subfile
== first_subfile
)
17091 if (current_subfile
->symtab
== NULL
)
17092 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
17094 fe
->symtab
= current_subfile
->symtab
;
17099 /* Start a subfile for DWARF. FILENAME is the name of the file and
17100 DIRNAME the name of the source directory which contains FILENAME
17101 or NULL if not known. COMP_DIR is the compilation directory for the
17102 linetable's compilation unit or NULL if not known.
17103 This routine tries to keep line numbers from identical absolute and
17104 relative file names in a common subfile.
17106 Using the `list' example from the GDB testsuite, which resides in
17107 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
17108 of /srcdir/list0.c yields the following debugging information for list0.c:
17110 DW_AT_name: /srcdir/list0.c
17111 DW_AT_comp_dir: /compdir
17112 files.files[0].name: list0.h
17113 files.files[0].dir: /srcdir
17114 files.files[1].name: list0.c
17115 files.files[1].dir: /srcdir
17117 The line number information for list0.c has to end up in a single
17118 subfile, so that `break /srcdir/list0.c:1' works as expected.
17119 start_subfile will ensure that this happens provided that we pass the
17120 concatenation of files.files[1].dir and files.files[1].name as the
17124 dwarf2_start_subfile (const char *filename
, const char *dirname
,
17125 const char *comp_dir
)
17129 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
17130 `start_symtab' will always pass the contents of DW_AT_comp_dir as
17131 second argument to start_subfile. To be consistent, we do the
17132 same here. In order not to lose the line information directory,
17133 we concatenate it to the filename when it makes sense.
17134 Note that the Dwarf3 standard says (speaking of filenames in line
17135 information): ``The directory index is ignored for file names
17136 that represent full path names''. Thus ignoring dirname in the
17137 `else' branch below isn't an issue. */
17139 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
17141 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
17145 start_subfile (filename
, comp_dir
);
17151 /* Start a symtab for DWARF.
17152 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
17155 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
17156 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
17158 start_symtab (name
, comp_dir
, low_pc
);
17159 record_debugformat ("DWARF 2");
17160 record_producer (cu
->producer
);
17162 /* We assume that we're processing GCC output. */
17163 processing_gcc_compilation
= 2;
17165 cu
->processing_has_namespace_info
= 0;
17169 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
17170 struct dwarf2_cu
*cu
)
17172 struct objfile
*objfile
= cu
->objfile
;
17173 struct comp_unit_head
*cu_header
= &cu
->header
;
17175 /* NOTE drow/2003-01-30: There used to be a comment and some special
17176 code here to turn a symbol with DW_AT_external and a
17177 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
17178 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
17179 with some versions of binutils) where shared libraries could have
17180 relocations against symbols in their debug information - the
17181 minimal symbol would have the right address, but the debug info
17182 would not. It's no longer necessary, because we will explicitly
17183 apply relocations when we read in the debug information now. */
17185 /* A DW_AT_location attribute with no contents indicates that a
17186 variable has been optimized away. */
17187 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
17189 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
17193 /* Handle one degenerate form of location expression specially, to
17194 preserve GDB's previous behavior when section offsets are
17195 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
17196 then mark this symbol as LOC_STATIC. */
17198 if (attr_form_is_block (attr
)
17199 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
17200 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
17201 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
17202 && (DW_BLOCK (attr
)->size
17203 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
17205 unsigned int dummy
;
17207 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
17208 SYMBOL_VALUE_ADDRESS (sym
) =
17209 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
17211 SYMBOL_VALUE_ADDRESS (sym
) =
17212 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
17213 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
17214 fixup_symbol_section (sym
, objfile
);
17215 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
17216 SYMBOL_SECTION (sym
));
17220 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
17221 expression evaluator, and use LOC_COMPUTED only when necessary
17222 (i.e. when the value of a register or memory location is
17223 referenced, or a thread-local block, etc.). Then again, it might
17224 not be worthwhile. I'm assuming that it isn't unless performance
17225 or memory numbers show me otherwise. */
17227 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
17229 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
17230 cu
->has_loclist
= 1;
17233 /* Given a pointer to a DWARF information entry, figure out if we need
17234 to make a symbol table entry for it, and if so, create a new entry
17235 and return a pointer to it.
17236 If TYPE is NULL, determine symbol type from the die, otherwise
17237 used the passed type.
17238 If SPACE is not NULL, use it to hold the new symbol. If it is
17239 NULL, allocate a new symbol on the objfile's obstack. */
17241 static struct symbol
*
17242 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
17243 struct symbol
*space
)
17245 struct objfile
*objfile
= cu
->objfile
;
17246 struct symbol
*sym
= NULL
;
17248 struct attribute
*attr
= NULL
;
17249 struct attribute
*attr2
= NULL
;
17250 CORE_ADDR baseaddr
;
17251 struct pending
**list_to_add
= NULL
;
17253 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
17255 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17257 name
= dwarf2_name (die
, cu
);
17260 const char *linkagename
;
17261 int suppress_add
= 0;
17266 sym
= allocate_symbol (objfile
);
17267 OBJSTAT (objfile
, n_syms
++);
17269 /* Cache this symbol's name and the name's demangled form (if any). */
17270 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
17271 linkagename
= dwarf2_physname (name
, die
, cu
);
17272 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
17274 /* Fortran does not have mangling standard and the mangling does differ
17275 between gfortran, iFort etc. */
17276 if (cu
->language
== language_fortran
17277 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
17278 symbol_set_demangled_name (&(sym
->ginfo
),
17279 dwarf2_full_name (name
, die
, cu
),
17282 /* Default assumptions.
17283 Use the passed type or decode it from the die. */
17284 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
17285 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
17287 SYMBOL_TYPE (sym
) = type
;
17289 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
17290 attr
= dwarf2_attr (die
,
17291 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
17295 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
17298 attr
= dwarf2_attr (die
,
17299 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
17303 int file_index
= DW_UNSND (attr
);
17305 if (cu
->line_header
== NULL
17306 || file_index
> cu
->line_header
->num_file_names
)
17307 complaint (&symfile_complaints
,
17308 _("file index out of range"));
17309 else if (file_index
> 0)
17311 struct file_entry
*fe
;
17313 fe
= &cu
->line_header
->file_names
[file_index
- 1];
17314 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
17321 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
17324 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
17326 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
17327 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
17328 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
17329 add_symbol_to_list (sym
, cu
->list_in_scope
);
17331 case DW_TAG_subprogram
:
17332 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
17334 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
17335 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
17336 if ((attr2
&& (DW_UNSND (attr2
) != 0))
17337 || cu
->language
== language_ada
)
17339 /* Subprograms marked external are stored as a global symbol.
17340 Ada subprograms, whether marked external or not, are always
17341 stored as a global symbol, because we want to be able to
17342 access them globally. For instance, we want to be able
17343 to break on a nested subprogram without having to
17344 specify the context. */
17345 list_to_add
= &global_symbols
;
17349 list_to_add
= cu
->list_in_scope
;
17352 case DW_TAG_inlined_subroutine
:
17353 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
17355 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
17356 SYMBOL_INLINED (sym
) = 1;
17357 list_to_add
= cu
->list_in_scope
;
17359 case DW_TAG_template_value_param
:
17361 /* Fall through. */
17362 case DW_TAG_constant
:
17363 case DW_TAG_variable
:
17364 case DW_TAG_member
:
17365 /* Compilation with minimal debug info may result in
17366 variables with missing type entries. Change the
17367 misleading `void' type to something sensible. */
17368 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
17370 = objfile_type (objfile
)->nodebug_data_symbol
;
17372 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
17373 /* In the case of DW_TAG_member, we should only be called for
17374 static const members. */
17375 if (die
->tag
== DW_TAG_member
)
17377 /* dwarf2_add_field uses die_is_declaration,
17378 so we do the same. */
17379 gdb_assert (die_is_declaration (die
, cu
));
17384 dwarf2_const_value (attr
, sym
, cu
);
17385 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
17388 if (attr2
&& (DW_UNSND (attr2
) != 0))
17389 list_to_add
= &global_symbols
;
17391 list_to_add
= cu
->list_in_scope
;
17395 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17398 var_decode_location (attr
, sym
, cu
);
17399 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
17401 /* Fortran explicitly imports any global symbols to the local
17402 scope by DW_TAG_common_block. */
17403 if (cu
->language
== language_fortran
&& die
->parent
17404 && die
->parent
->tag
== DW_TAG_common_block
)
17407 if (SYMBOL_CLASS (sym
) == LOC_STATIC
17408 && SYMBOL_VALUE_ADDRESS (sym
) == 0
17409 && !dwarf2_per_objfile
->has_section_at_zero
)
17411 /* When a static variable is eliminated by the linker,
17412 the corresponding debug information is not stripped
17413 out, but the variable address is set to null;
17414 do not add such variables into symbol table. */
17416 else if (attr2
&& (DW_UNSND (attr2
) != 0))
17418 /* Workaround gfortran PR debug/40040 - it uses
17419 DW_AT_location for variables in -fPIC libraries which may
17420 get overriden by other libraries/executable and get
17421 a different address. Resolve it by the minimal symbol
17422 which may come from inferior's executable using copy
17423 relocation. Make this workaround only for gfortran as for
17424 other compilers GDB cannot guess the minimal symbol
17425 Fortran mangling kind. */
17426 if (cu
->language
== language_fortran
&& die
->parent
17427 && die
->parent
->tag
== DW_TAG_module
17429 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
17430 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
17432 /* A variable with DW_AT_external is never static,
17433 but it may be block-scoped. */
17434 list_to_add
= (cu
->list_in_scope
== &file_symbols
17435 ? &global_symbols
: cu
->list_in_scope
);
17438 list_to_add
= cu
->list_in_scope
;
17442 /* We do not know the address of this symbol.
17443 If it is an external symbol and we have type information
17444 for it, enter the symbol as a LOC_UNRESOLVED symbol.
17445 The address of the variable will then be determined from
17446 the minimal symbol table whenever the variable is
17448 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
17450 /* Fortran explicitly imports any global symbols to the local
17451 scope by DW_TAG_common_block. */
17452 if (cu
->language
== language_fortran
&& die
->parent
17453 && die
->parent
->tag
== DW_TAG_common_block
)
17455 /* SYMBOL_CLASS doesn't matter here because
17456 read_common_block is going to reset it. */
17458 list_to_add
= cu
->list_in_scope
;
17460 else if (attr2
&& (DW_UNSND (attr2
) != 0)
17461 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
17463 /* A variable with DW_AT_external is never static, but it
17464 may be block-scoped. */
17465 list_to_add
= (cu
->list_in_scope
== &file_symbols
17466 ? &global_symbols
: cu
->list_in_scope
);
17468 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
17470 else if (!die_is_declaration (die
, cu
))
17472 /* Use the default LOC_OPTIMIZED_OUT class. */
17473 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
17475 list_to_add
= cu
->list_in_scope
;
17479 case DW_TAG_formal_parameter
:
17480 /* If we are inside a function, mark this as an argument. If
17481 not, we might be looking at an argument to an inlined function
17482 when we do not have enough information to show inlined frames;
17483 pretend it's a local variable in that case so that the user can
17485 if (context_stack_depth
> 0
17486 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
17487 SYMBOL_IS_ARGUMENT (sym
) = 1;
17488 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17491 var_decode_location (attr
, sym
, cu
);
17493 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
17496 dwarf2_const_value (attr
, sym
, cu
);
17499 list_to_add
= cu
->list_in_scope
;
17501 case DW_TAG_unspecified_parameters
:
17502 /* From varargs functions; gdb doesn't seem to have any
17503 interest in this information, so just ignore it for now.
17506 case DW_TAG_template_type_param
:
17508 /* Fall through. */
17509 case DW_TAG_class_type
:
17510 case DW_TAG_interface_type
:
17511 case DW_TAG_structure_type
:
17512 case DW_TAG_union_type
:
17513 case DW_TAG_set_type
:
17514 case DW_TAG_enumeration_type
:
17515 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
17516 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
17519 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
17520 really ever be static objects: otherwise, if you try
17521 to, say, break of a class's method and you're in a file
17522 which doesn't mention that class, it won't work unless
17523 the check for all static symbols in lookup_symbol_aux
17524 saves you. See the OtherFileClass tests in
17525 gdb.c++/namespace.exp. */
17529 list_to_add
= (cu
->list_in_scope
== &file_symbols
17530 && (cu
->language
== language_cplus
17531 || cu
->language
== language_java
)
17532 ? &global_symbols
: cu
->list_in_scope
);
17534 /* The semantics of C++ state that "struct foo {
17535 ... }" also defines a typedef for "foo". A Java
17536 class declaration also defines a typedef for the
17538 if (cu
->language
== language_cplus
17539 || cu
->language
== language_java
17540 || cu
->language
== language_ada
)
17542 /* The symbol's name is already allocated along
17543 with this objfile, so we don't need to
17544 duplicate it for the type. */
17545 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
17546 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
17551 case DW_TAG_typedef
:
17552 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
17553 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
17554 list_to_add
= cu
->list_in_scope
;
17556 case DW_TAG_base_type
:
17557 case DW_TAG_subrange_type
:
17558 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
17559 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
17560 list_to_add
= cu
->list_in_scope
;
17562 case DW_TAG_enumerator
:
17563 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
17566 dwarf2_const_value (attr
, sym
, cu
);
17569 /* NOTE: carlton/2003-11-10: See comment above in the
17570 DW_TAG_class_type, etc. block. */
17572 list_to_add
= (cu
->list_in_scope
== &file_symbols
17573 && (cu
->language
== language_cplus
17574 || cu
->language
== language_java
)
17575 ? &global_symbols
: cu
->list_in_scope
);
17578 case DW_TAG_namespace
:
17579 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
17580 list_to_add
= &global_symbols
;
17582 case DW_TAG_common_block
:
17583 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
17584 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
17585 add_symbol_to_list (sym
, cu
->list_in_scope
);
17588 /* Not a tag we recognize. Hopefully we aren't processing
17589 trash data, but since we must specifically ignore things
17590 we don't recognize, there is nothing else we should do at
17592 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
17593 dwarf_tag_name (die
->tag
));
17599 sym
->hash_next
= objfile
->template_symbols
;
17600 objfile
->template_symbols
= sym
;
17601 list_to_add
= NULL
;
17604 if (list_to_add
!= NULL
)
17605 add_symbol_to_list (sym
, list_to_add
);
17607 /* For the benefit of old versions of GCC, check for anonymous
17608 namespaces based on the demangled name. */
17609 if (!cu
->processing_has_namespace_info
17610 && cu
->language
== language_cplus
)
17611 cp_scan_for_anonymous_namespaces (sym
, objfile
);
17616 /* A wrapper for new_symbol_full that always allocates a new symbol. */
17618 static struct symbol
*
17619 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
17621 return new_symbol_full (die
, type
, cu
, NULL
);
17624 /* Given an attr with a DW_FORM_dataN value in host byte order,
17625 zero-extend it as appropriate for the symbol's type. The DWARF
17626 standard (v4) is not entirely clear about the meaning of using
17627 DW_FORM_dataN for a constant with a signed type, where the type is
17628 wider than the data. The conclusion of a discussion on the DWARF
17629 list was that this is unspecified. We choose to always zero-extend
17630 because that is the interpretation long in use by GCC. */
17633 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
17634 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
17636 struct objfile
*objfile
= cu
->objfile
;
17637 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
17638 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
17639 LONGEST l
= DW_UNSND (attr
);
17641 if (bits
< sizeof (*value
) * 8)
17643 l
&= ((LONGEST
) 1 << bits
) - 1;
17646 else if (bits
== sizeof (*value
) * 8)
17650 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
17651 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
17658 /* Read a constant value from an attribute. Either set *VALUE, or if
17659 the value does not fit in *VALUE, set *BYTES - either already
17660 allocated on the objfile obstack, or newly allocated on OBSTACK,
17661 or, set *BATON, if we translated the constant to a location
17665 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
17666 const char *name
, struct obstack
*obstack
,
17667 struct dwarf2_cu
*cu
,
17668 LONGEST
*value
, const gdb_byte
**bytes
,
17669 struct dwarf2_locexpr_baton
**baton
)
17671 struct objfile
*objfile
= cu
->objfile
;
17672 struct comp_unit_head
*cu_header
= &cu
->header
;
17673 struct dwarf_block
*blk
;
17674 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
17675 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
17681 switch (attr
->form
)
17684 case DW_FORM_GNU_addr_index
:
17688 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
17689 dwarf2_const_value_length_mismatch_complaint (name
,
17690 cu_header
->addr_size
,
17691 TYPE_LENGTH (type
));
17692 /* Symbols of this form are reasonably rare, so we just
17693 piggyback on the existing location code rather than writing
17694 a new implementation of symbol_computed_ops. */
17695 *baton
= obstack_alloc (obstack
, sizeof (struct dwarf2_locexpr_baton
));
17696 (*baton
)->per_cu
= cu
->per_cu
;
17697 gdb_assert ((*baton
)->per_cu
);
17699 (*baton
)->size
= 2 + cu_header
->addr_size
;
17700 data
= obstack_alloc (obstack
, (*baton
)->size
);
17701 (*baton
)->data
= data
;
17703 data
[0] = DW_OP_addr
;
17704 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
17705 byte_order
, DW_ADDR (attr
));
17706 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
17709 case DW_FORM_string
:
17711 case DW_FORM_GNU_str_index
:
17712 case DW_FORM_GNU_strp_alt
:
17713 /* DW_STRING is already allocated on the objfile obstack, point
17715 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
17717 case DW_FORM_block1
:
17718 case DW_FORM_block2
:
17719 case DW_FORM_block4
:
17720 case DW_FORM_block
:
17721 case DW_FORM_exprloc
:
17722 blk
= DW_BLOCK (attr
);
17723 if (TYPE_LENGTH (type
) != blk
->size
)
17724 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
17725 TYPE_LENGTH (type
));
17726 *bytes
= blk
->data
;
17729 /* The DW_AT_const_value attributes are supposed to carry the
17730 symbol's value "represented as it would be on the target
17731 architecture." By the time we get here, it's already been
17732 converted to host endianness, so we just need to sign- or
17733 zero-extend it as appropriate. */
17734 case DW_FORM_data1
:
17735 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
17737 case DW_FORM_data2
:
17738 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
17740 case DW_FORM_data4
:
17741 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
17743 case DW_FORM_data8
:
17744 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
17747 case DW_FORM_sdata
:
17748 *value
= DW_SND (attr
);
17751 case DW_FORM_udata
:
17752 *value
= DW_UNSND (attr
);
17756 complaint (&symfile_complaints
,
17757 _("unsupported const value attribute form: '%s'"),
17758 dwarf_form_name (attr
->form
));
17765 /* Copy constant value from an attribute to a symbol. */
17768 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
17769 struct dwarf2_cu
*cu
)
17771 struct objfile
*objfile
= cu
->objfile
;
17772 struct comp_unit_head
*cu_header
= &cu
->header
;
17774 const gdb_byte
*bytes
;
17775 struct dwarf2_locexpr_baton
*baton
;
17777 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
17778 SYMBOL_PRINT_NAME (sym
),
17779 &objfile
->objfile_obstack
, cu
,
17780 &value
, &bytes
, &baton
);
17784 SYMBOL_LOCATION_BATON (sym
) = baton
;
17785 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
17787 else if (bytes
!= NULL
)
17789 SYMBOL_VALUE_BYTES (sym
) = bytes
;
17790 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
17794 SYMBOL_VALUE (sym
) = value
;
17795 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
17799 /* Return the type of the die in question using its DW_AT_type attribute. */
17801 static struct type
*
17802 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17804 struct attribute
*type_attr
;
17806 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
17809 /* A missing DW_AT_type represents a void type. */
17810 return objfile_type (cu
->objfile
)->builtin_void
;
17813 return lookup_die_type (die
, type_attr
, cu
);
17816 /* True iff CU's producer generates GNAT Ada auxiliary information
17817 that allows to find parallel types through that information instead
17818 of having to do expensive parallel lookups by type name. */
17821 need_gnat_info (struct dwarf2_cu
*cu
)
17823 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
17824 of GNAT produces this auxiliary information, without any indication
17825 that it is produced. Part of enhancing the FSF version of GNAT
17826 to produce that information will be to put in place an indicator
17827 that we can use in order to determine whether the descriptive type
17828 info is available or not. One suggestion that has been made is
17829 to use a new attribute, attached to the CU die. For now, assume
17830 that the descriptive type info is not available. */
17834 /* Return the auxiliary type of the die in question using its
17835 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
17836 attribute is not present. */
17838 static struct type
*
17839 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17841 struct attribute
*type_attr
;
17843 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
17847 return lookup_die_type (die
, type_attr
, cu
);
17850 /* If DIE has a descriptive_type attribute, then set the TYPE's
17851 descriptive type accordingly. */
17854 set_descriptive_type (struct type
*type
, struct die_info
*die
,
17855 struct dwarf2_cu
*cu
)
17857 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
17859 if (descriptive_type
)
17861 ALLOCATE_GNAT_AUX_TYPE (type
);
17862 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
17866 /* Return the containing type of the die in question using its
17867 DW_AT_containing_type attribute. */
17869 static struct type
*
17870 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17872 struct attribute
*type_attr
;
17874 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
17876 error (_("Dwarf Error: Problem turning containing type into gdb type "
17877 "[in module %s]"), objfile_name (cu
->objfile
));
17879 return lookup_die_type (die
, type_attr
, cu
);
17882 /* Return an error marker type to use for the ill formed type in DIE/CU. */
17884 static struct type
*
17885 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
17887 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17888 char *message
, *saved
;
17890 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
17891 objfile_name (objfile
),
17892 cu
->header
.offset
.sect_off
,
17893 die
->offset
.sect_off
);
17894 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
17895 message
, strlen (message
));
17898 return init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
17901 /* Look up the type of DIE in CU using its type attribute ATTR.
17902 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
17903 DW_AT_containing_type.
17904 If there is no type substitute an error marker. */
17906 static struct type
*
17907 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
17908 struct dwarf2_cu
*cu
)
17910 struct objfile
*objfile
= cu
->objfile
;
17911 struct type
*this_type
;
17913 gdb_assert (attr
->name
== DW_AT_type
17914 || attr
->name
== DW_AT_GNAT_descriptive_type
17915 || attr
->name
== DW_AT_containing_type
);
17917 /* First see if we have it cached. */
17919 if (attr
->form
== DW_FORM_GNU_ref_alt
)
17921 struct dwarf2_per_cu_data
*per_cu
;
17922 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
17924 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
17925 this_type
= get_die_type_at_offset (offset
, per_cu
);
17927 else if (attr_form_is_ref (attr
))
17929 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
17931 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
17933 else if (attr
->form
== DW_FORM_ref_sig8
)
17935 ULONGEST signature
= DW_SIGNATURE (attr
);
17937 return get_signatured_type (die
, signature
, cu
);
17941 complaint (&symfile_complaints
,
17942 _("Dwarf Error: Bad type attribute %s in DIE"
17943 " at 0x%x [in module %s]"),
17944 dwarf_attr_name (attr
->name
), die
->offset
.sect_off
,
17945 objfile_name (objfile
));
17946 return build_error_marker_type (cu
, die
);
17949 /* If not cached we need to read it in. */
17951 if (this_type
== NULL
)
17953 struct die_info
*type_die
= NULL
;
17954 struct dwarf2_cu
*type_cu
= cu
;
17956 if (attr_form_is_ref (attr
))
17957 type_die
= follow_die_ref (die
, attr
, &type_cu
);
17958 if (type_die
== NULL
)
17959 return build_error_marker_type (cu
, die
);
17960 /* If we find the type now, it's probably because the type came
17961 from an inter-CU reference and the type's CU got expanded before
17963 this_type
= read_type_die (type_die
, type_cu
);
17966 /* If we still don't have a type use an error marker. */
17968 if (this_type
== NULL
)
17969 return build_error_marker_type (cu
, die
);
17974 /* Return the type in DIE, CU.
17975 Returns NULL for invalid types.
17977 This first does a lookup in die_type_hash,
17978 and only reads the die in if necessary.
17980 NOTE: This can be called when reading in partial or full symbols. */
17982 static struct type
*
17983 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
17985 struct type
*this_type
;
17987 this_type
= get_die_type (die
, cu
);
17991 return read_type_die_1 (die
, cu
);
17994 /* Read the type in DIE, CU.
17995 Returns NULL for invalid types. */
17997 static struct type
*
17998 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
18000 struct type
*this_type
= NULL
;
18004 case DW_TAG_class_type
:
18005 case DW_TAG_interface_type
:
18006 case DW_TAG_structure_type
:
18007 case DW_TAG_union_type
:
18008 this_type
= read_structure_type (die
, cu
);
18010 case DW_TAG_enumeration_type
:
18011 this_type
= read_enumeration_type (die
, cu
);
18013 case DW_TAG_subprogram
:
18014 case DW_TAG_subroutine_type
:
18015 case DW_TAG_inlined_subroutine
:
18016 this_type
= read_subroutine_type (die
, cu
);
18018 case DW_TAG_array_type
:
18019 this_type
= read_array_type (die
, cu
);
18021 case DW_TAG_set_type
:
18022 this_type
= read_set_type (die
, cu
);
18024 case DW_TAG_pointer_type
:
18025 this_type
= read_tag_pointer_type (die
, cu
);
18027 case DW_TAG_ptr_to_member_type
:
18028 this_type
= read_tag_ptr_to_member_type (die
, cu
);
18030 case DW_TAG_reference_type
:
18031 this_type
= read_tag_reference_type (die
, cu
);
18033 case DW_TAG_const_type
:
18034 this_type
= read_tag_const_type (die
, cu
);
18036 case DW_TAG_volatile_type
:
18037 this_type
= read_tag_volatile_type (die
, cu
);
18039 case DW_TAG_restrict_type
:
18040 this_type
= read_tag_restrict_type (die
, cu
);
18042 case DW_TAG_string_type
:
18043 this_type
= read_tag_string_type (die
, cu
);
18045 case DW_TAG_typedef
:
18046 this_type
= read_typedef (die
, cu
);
18048 case DW_TAG_subrange_type
:
18049 this_type
= read_subrange_type (die
, cu
);
18051 case DW_TAG_base_type
:
18052 this_type
= read_base_type (die
, cu
);
18054 case DW_TAG_unspecified_type
:
18055 this_type
= read_unspecified_type (die
, cu
);
18057 case DW_TAG_namespace
:
18058 this_type
= read_namespace_type (die
, cu
);
18060 case DW_TAG_module
:
18061 this_type
= read_module_type (die
, cu
);
18064 complaint (&symfile_complaints
,
18065 _("unexpected tag in read_type_die: '%s'"),
18066 dwarf_tag_name (die
->tag
));
18073 /* See if we can figure out if the class lives in a namespace. We do
18074 this by looking for a member function; its demangled name will
18075 contain namespace info, if there is any.
18076 Return the computed name or NULL.
18077 Space for the result is allocated on the objfile's obstack.
18078 This is the full-die version of guess_partial_die_structure_name.
18079 In this case we know DIE has no useful parent. */
18082 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18084 struct die_info
*spec_die
;
18085 struct dwarf2_cu
*spec_cu
;
18086 struct die_info
*child
;
18089 spec_die
= die_specification (die
, &spec_cu
);
18090 if (spec_die
!= NULL
)
18096 for (child
= die
->child
;
18098 child
= child
->sibling
)
18100 if (child
->tag
== DW_TAG_subprogram
)
18102 struct attribute
*attr
;
18104 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
18106 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
18110 = language_class_name_from_physname (cu
->language_defn
,
18114 if (actual_name
!= NULL
)
18116 const char *die_name
= dwarf2_name (die
, cu
);
18118 if (die_name
!= NULL
18119 && strcmp (die_name
, actual_name
) != 0)
18121 /* Strip off the class name from the full name.
18122 We want the prefix. */
18123 int die_name_len
= strlen (die_name
);
18124 int actual_name_len
= strlen (actual_name
);
18126 /* Test for '::' as a sanity check. */
18127 if (actual_name_len
> die_name_len
+ 2
18128 && actual_name
[actual_name_len
18129 - die_name_len
- 1] == ':')
18131 obstack_copy0 (&cu
->objfile
->objfile_obstack
,
18133 actual_name_len
- die_name_len
- 2);
18136 xfree (actual_name
);
18145 /* GCC might emit a nameless typedef that has a linkage name. Determine the
18146 prefix part in such case. See
18147 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18150 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
18152 struct attribute
*attr
;
18155 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
18156 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
18159 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
18160 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
18163 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
18165 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
18166 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
18169 /* dwarf2_name had to be already called. */
18170 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
18172 /* Strip the base name, keep any leading namespaces/classes. */
18173 base
= strrchr (DW_STRING (attr
), ':');
18174 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
18177 return obstack_copy0 (&cu
->objfile
->objfile_obstack
,
18178 DW_STRING (attr
), &base
[-1] - DW_STRING (attr
));
18181 /* Return the name of the namespace/class that DIE is defined within,
18182 or "" if we can't tell. The caller should not xfree the result.
18184 For example, if we're within the method foo() in the following
18194 then determine_prefix on foo's die will return "N::C". */
18196 static const char *
18197 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
18199 struct die_info
*parent
, *spec_die
;
18200 struct dwarf2_cu
*spec_cu
;
18201 struct type
*parent_type
;
18204 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
18205 && cu
->language
!= language_fortran
)
18208 retval
= anonymous_struct_prefix (die
, cu
);
18212 /* We have to be careful in the presence of DW_AT_specification.
18213 For example, with GCC 3.4, given the code
18217 // Definition of N::foo.
18221 then we'll have a tree of DIEs like this:
18223 1: DW_TAG_compile_unit
18224 2: DW_TAG_namespace // N
18225 3: DW_TAG_subprogram // declaration of N::foo
18226 4: DW_TAG_subprogram // definition of N::foo
18227 DW_AT_specification // refers to die #3
18229 Thus, when processing die #4, we have to pretend that we're in
18230 the context of its DW_AT_specification, namely the contex of die
18233 spec_die
= die_specification (die
, &spec_cu
);
18234 if (spec_die
== NULL
)
18235 parent
= die
->parent
;
18238 parent
= spec_die
->parent
;
18242 if (parent
== NULL
)
18244 else if (parent
->building_fullname
)
18247 const char *parent_name
;
18249 /* It has been seen on RealView 2.2 built binaries,
18250 DW_TAG_template_type_param types actually _defined_ as
18251 children of the parent class:
18254 template class <class Enum> Class{};
18255 Class<enum E> class_e;
18257 1: DW_TAG_class_type (Class)
18258 2: DW_TAG_enumeration_type (E)
18259 3: DW_TAG_enumerator (enum1:0)
18260 3: DW_TAG_enumerator (enum2:1)
18262 2: DW_TAG_template_type_param
18263 DW_AT_type DW_FORM_ref_udata (E)
18265 Besides being broken debug info, it can put GDB into an
18266 infinite loop. Consider:
18268 When we're building the full name for Class<E>, we'll start
18269 at Class, and go look over its template type parameters,
18270 finding E. We'll then try to build the full name of E, and
18271 reach here. We're now trying to build the full name of E,
18272 and look over the parent DIE for containing scope. In the
18273 broken case, if we followed the parent DIE of E, we'd again
18274 find Class, and once again go look at its template type
18275 arguments, etc., etc. Simply don't consider such parent die
18276 as source-level parent of this die (it can't be, the language
18277 doesn't allow it), and break the loop here. */
18278 name
= dwarf2_name (die
, cu
);
18279 parent_name
= dwarf2_name (parent
, cu
);
18280 complaint (&symfile_complaints
,
18281 _("template param type '%s' defined within parent '%s'"),
18282 name
? name
: "<unknown>",
18283 parent_name
? parent_name
: "<unknown>");
18287 switch (parent
->tag
)
18289 case DW_TAG_namespace
:
18290 parent_type
= read_type_die (parent
, cu
);
18291 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
18292 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
18293 Work around this problem here. */
18294 if (cu
->language
== language_cplus
18295 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
18297 /* We give a name to even anonymous namespaces. */
18298 return TYPE_TAG_NAME (parent_type
);
18299 case DW_TAG_class_type
:
18300 case DW_TAG_interface_type
:
18301 case DW_TAG_structure_type
:
18302 case DW_TAG_union_type
:
18303 case DW_TAG_module
:
18304 parent_type
= read_type_die (parent
, cu
);
18305 if (TYPE_TAG_NAME (parent_type
) != NULL
)
18306 return TYPE_TAG_NAME (parent_type
);
18308 /* An anonymous structure is only allowed non-static data
18309 members; no typedefs, no member functions, et cetera.
18310 So it does not need a prefix. */
18312 case DW_TAG_compile_unit
:
18313 case DW_TAG_partial_unit
:
18314 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
18315 if (cu
->language
== language_cplus
18316 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
18317 && die
->child
!= NULL
18318 && (die
->tag
== DW_TAG_class_type
18319 || die
->tag
== DW_TAG_structure_type
18320 || die
->tag
== DW_TAG_union_type
))
18322 char *name
= guess_full_die_structure_name (die
, cu
);
18328 return determine_prefix (parent
, cu
);
18332 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
18333 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
18334 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
18335 an obconcat, otherwise allocate storage for the result. The CU argument is
18336 used to determine the language and hence, the appropriate separator. */
18338 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
18341 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
18342 int physname
, struct dwarf2_cu
*cu
)
18344 const char *lead
= "";
18347 if (suffix
== NULL
|| suffix
[0] == '\0'
18348 || prefix
== NULL
|| prefix
[0] == '\0')
18350 else if (cu
->language
== language_java
)
18352 else if (cu
->language
== language_fortran
&& physname
)
18354 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
18355 DW_AT_MIPS_linkage_name is preferred and used instead. */
18363 if (prefix
== NULL
)
18365 if (suffix
== NULL
)
18371 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
18373 strcpy (retval
, lead
);
18374 strcat (retval
, prefix
);
18375 strcat (retval
, sep
);
18376 strcat (retval
, suffix
);
18381 /* We have an obstack. */
18382 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
18386 /* Return sibling of die, NULL if no sibling. */
18388 static struct die_info
*
18389 sibling_die (struct die_info
*die
)
18391 return die
->sibling
;
18394 /* Get name of a die, return NULL if not found. */
18396 static const char *
18397 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
18398 struct obstack
*obstack
)
18400 if (name
&& cu
->language
== language_cplus
)
18402 char *canon_name
= cp_canonicalize_string (name
);
18404 if (canon_name
!= NULL
)
18406 if (strcmp (canon_name
, name
) != 0)
18407 name
= obstack_copy0 (obstack
, canon_name
, strlen (canon_name
));
18408 xfree (canon_name
);
18415 /* Get name of a die, return NULL if not found. */
18417 static const char *
18418 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18420 struct attribute
*attr
;
18422 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
18423 if ((!attr
|| !DW_STRING (attr
))
18424 && die
->tag
!= DW_TAG_class_type
18425 && die
->tag
!= DW_TAG_interface_type
18426 && die
->tag
!= DW_TAG_structure_type
18427 && die
->tag
!= DW_TAG_union_type
)
18432 case DW_TAG_compile_unit
:
18433 case DW_TAG_partial_unit
:
18434 /* Compilation units have a DW_AT_name that is a filename, not
18435 a source language identifier. */
18436 case DW_TAG_enumeration_type
:
18437 case DW_TAG_enumerator
:
18438 /* These tags always have simple identifiers already; no need
18439 to canonicalize them. */
18440 return DW_STRING (attr
);
18442 case DW_TAG_subprogram
:
18443 /* Java constructors will all be named "<init>", so return
18444 the class name when we see this special case. */
18445 if (cu
->language
== language_java
18446 && DW_STRING (attr
) != NULL
18447 && strcmp (DW_STRING (attr
), "<init>") == 0)
18449 struct dwarf2_cu
*spec_cu
= cu
;
18450 struct die_info
*spec_die
;
18452 /* GCJ will output '<init>' for Java constructor names.
18453 For this special case, return the name of the parent class. */
18455 /* GCJ may output suprogram DIEs with AT_specification set.
18456 If so, use the name of the specified DIE. */
18457 spec_die
= die_specification (die
, &spec_cu
);
18458 if (spec_die
!= NULL
)
18459 return dwarf2_name (spec_die
, spec_cu
);
18464 if (die
->tag
== DW_TAG_class_type
)
18465 return dwarf2_name (die
, cu
);
18467 while (die
->tag
!= DW_TAG_compile_unit
18468 && die
->tag
!= DW_TAG_partial_unit
);
18472 case DW_TAG_class_type
:
18473 case DW_TAG_interface_type
:
18474 case DW_TAG_structure_type
:
18475 case DW_TAG_union_type
:
18476 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
18477 structures or unions. These were of the form "._%d" in GCC 4.1,
18478 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
18479 and GCC 4.4. We work around this problem by ignoring these. */
18480 if (attr
&& DW_STRING (attr
)
18481 && (strncmp (DW_STRING (attr
), "._", 2) == 0
18482 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
18485 /* GCC might emit a nameless typedef that has a linkage name. See
18486 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18487 if (!attr
|| DW_STRING (attr
) == NULL
)
18489 char *demangled
= NULL
;
18491 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
18493 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
18495 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
18498 /* Avoid demangling DW_STRING (attr) the second time on a second
18499 call for the same DIE. */
18500 if (!DW_STRING_IS_CANONICAL (attr
))
18501 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
18507 /* FIXME: we already did this for the partial symbol... */
18508 DW_STRING (attr
) = obstack_copy0 (&cu
->objfile
->objfile_obstack
,
18509 demangled
, strlen (demangled
));
18510 DW_STRING_IS_CANONICAL (attr
) = 1;
18513 /* Strip any leading namespaces/classes, keep only the base name.
18514 DW_AT_name for named DIEs does not contain the prefixes. */
18515 base
= strrchr (DW_STRING (attr
), ':');
18516 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
18519 return DW_STRING (attr
);
18528 if (!DW_STRING_IS_CANONICAL (attr
))
18531 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
18532 &cu
->objfile
->objfile_obstack
);
18533 DW_STRING_IS_CANONICAL (attr
) = 1;
18535 return DW_STRING (attr
);
18538 /* Return the die that this die in an extension of, or NULL if there
18539 is none. *EXT_CU is the CU containing DIE on input, and the CU
18540 containing the return value on output. */
18542 static struct die_info
*
18543 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
18545 struct attribute
*attr
;
18547 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
18551 return follow_die_ref (die
, attr
, ext_cu
);
18554 /* Convert a DIE tag into its string name. */
18556 static const char *
18557 dwarf_tag_name (unsigned tag
)
18559 const char *name
= get_DW_TAG_name (tag
);
18562 return "DW_TAG_<unknown>";
18567 /* Convert a DWARF attribute code into its string name. */
18569 static const char *
18570 dwarf_attr_name (unsigned attr
)
18574 #ifdef MIPS /* collides with DW_AT_HP_block_index */
18575 if (attr
== DW_AT_MIPS_fde
)
18576 return "DW_AT_MIPS_fde";
18578 if (attr
== DW_AT_HP_block_index
)
18579 return "DW_AT_HP_block_index";
18582 name
= get_DW_AT_name (attr
);
18585 return "DW_AT_<unknown>";
18590 /* Convert a DWARF value form code into its string name. */
18592 static const char *
18593 dwarf_form_name (unsigned form
)
18595 const char *name
= get_DW_FORM_name (form
);
18598 return "DW_FORM_<unknown>";
18604 dwarf_bool_name (unsigned mybool
)
18612 /* Convert a DWARF type code into its string name. */
18614 static const char *
18615 dwarf_type_encoding_name (unsigned enc
)
18617 const char *name
= get_DW_ATE_name (enc
);
18620 return "DW_ATE_<unknown>";
18626 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
18630 print_spaces (indent
, f
);
18631 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
18632 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
18634 if (die
->parent
!= NULL
)
18636 print_spaces (indent
, f
);
18637 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
18638 die
->parent
->offset
.sect_off
);
18641 print_spaces (indent
, f
);
18642 fprintf_unfiltered (f
, " has children: %s\n",
18643 dwarf_bool_name (die
->child
!= NULL
));
18645 print_spaces (indent
, f
);
18646 fprintf_unfiltered (f
, " attributes:\n");
18648 for (i
= 0; i
< die
->num_attrs
; ++i
)
18650 print_spaces (indent
, f
);
18651 fprintf_unfiltered (f
, " %s (%s) ",
18652 dwarf_attr_name (die
->attrs
[i
].name
),
18653 dwarf_form_name (die
->attrs
[i
].form
));
18655 switch (die
->attrs
[i
].form
)
18658 case DW_FORM_GNU_addr_index
:
18659 fprintf_unfiltered (f
, "address: ");
18660 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
18662 case DW_FORM_block2
:
18663 case DW_FORM_block4
:
18664 case DW_FORM_block
:
18665 case DW_FORM_block1
:
18666 fprintf_unfiltered (f
, "block: size %s",
18667 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
18669 case DW_FORM_exprloc
:
18670 fprintf_unfiltered (f
, "expression: size %s",
18671 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
18673 case DW_FORM_ref_addr
:
18674 fprintf_unfiltered (f
, "ref address: ");
18675 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
18677 case DW_FORM_GNU_ref_alt
:
18678 fprintf_unfiltered (f
, "alt ref address: ");
18679 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
18685 case DW_FORM_ref_udata
:
18686 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
18687 (long) (DW_UNSND (&die
->attrs
[i
])));
18689 case DW_FORM_data1
:
18690 case DW_FORM_data2
:
18691 case DW_FORM_data4
:
18692 case DW_FORM_data8
:
18693 case DW_FORM_udata
:
18694 case DW_FORM_sdata
:
18695 fprintf_unfiltered (f
, "constant: %s",
18696 pulongest (DW_UNSND (&die
->attrs
[i
])));
18698 case DW_FORM_sec_offset
:
18699 fprintf_unfiltered (f
, "section offset: %s",
18700 pulongest (DW_UNSND (&die
->attrs
[i
])));
18702 case DW_FORM_ref_sig8
:
18703 fprintf_unfiltered (f
, "signature: %s",
18704 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
18706 case DW_FORM_string
:
18708 case DW_FORM_GNU_str_index
:
18709 case DW_FORM_GNU_strp_alt
:
18710 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
18711 DW_STRING (&die
->attrs
[i
])
18712 ? DW_STRING (&die
->attrs
[i
]) : "",
18713 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
18716 if (DW_UNSND (&die
->attrs
[i
]))
18717 fprintf_unfiltered (f
, "flag: TRUE");
18719 fprintf_unfiltered (f
, "flag: FALSE");
18721 case DW_FORM_flag_present
:
18722 fprintf_unfiltered (f
, "flag: TRUE");
18724 case DW_FORM_indirect
:
18725 /* The reader will have reduced the indirect form to
18726 the "base form" so this form should not occur. */
18727 fprintf_unfiltered (f
,
18728 "unexpected attribute form: DW_FORM_indirect");
18731 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
18732 die
->attrs
[i
].form
);
18735 fprintf_unfiltered (f
, "\n");
18740 dump_die_for_error (struct die_info
*die
)
18742 dump_die_shallow (gdb_stderr
, 0, die
);
18746 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
18748 int indent
= level
* 4;
18750 gdb_assert (die
!= NULL
);
18752 if (level
>= max_level
)
18755 dump_die_shallow (f
, indent
, die
);
18757 if (die
->child
!= NULL
)
18759 print_spaces (indent
, f
);
18760 fprintf_unfiltered (f
, " Children:");
18761 if (level
+ 1 < max_level
)
18763 fprintf_unfiltered (f
, "\n");
18764 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
18768 fprintf_unfiltered (f
,
18769 " [not printed, max nesting level reached]\n");
18773 if (die
->sibling
!= NULL
&& level
> 0)
18775 dump_die_1 (f
, level
, max_level
, die
->sibling
);
18779 /* This is called from the pdie macro in gdbinit.in.
18780 It's not static so gcc will keep a copy callable from gdb. */
18783 dump_die (struct die_info
*die
, int max_level
)
18785 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
18789 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
18793 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
18799 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
18803 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
18805 sect_offset retval
= { DW_UNSND (attr
) };
18807 if (attr_form_is_ref (attr
))
18810 retval
.sect_off
= 0;
18811 complaint (&symfile_complaints
,
18812 _("unsupported die ref attribute form: '%s'"),
18813 dwarf_form_name (attr
->form
));
18817 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
18818 * the value held by the attribute is not constant. */
18821 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
18823 if (attr
->form
== DW_FORM_sdata
)
18824 return DW_SND (attr
);
18825 else if (attr
->form
== DW_FORM_udata
18826 || attr
->form
== DW_FORM_data1
18827 || attr
->form
== DW_FORM_data2
18828 || attr
->form
== DW_FORM_data4
18829 || attr
->form
== DW_FORM_data8
)
18830 return DW_UNSND (attr
);
18833 complaint (&symfile_complaints
,
18834 _("Attribute value is not a constant (%s)"),
18835 dwarf_form_name (attr
->form
));
18836 return default_value
;
18840 /* Follow reference or signature attribute ATTR of SRC_DIE.
18841 On entry *REF_CU is the CU of SRC_DIE.
18842 On exit *REF_CU is the CU of the result. */
18844 static struct die_info
*
18845 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
18846 struct dwarf2_cu
**ref_cu
)
18848 struct die_info
*die
;
18850 if (attr_form_is_ref (attr
))
18851 die
= follow_die_ref (src_die
, attr
, ref_cu
);
18852 else if (attr
->form
== DW_FORM_ref_sig8
)
18853 die
= follow_die_sig (src_die
, attr
, ref_cu
);
18856 dump_die_for_error (src_die
);
18857 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
18858 objfile_name ((*ref_cu
)->objfile
));
18864 /* Follow reference OFFSET.
18865 On entry *REF_CU is the CU of the source die referencing OFFSET.
18866 On exit *REF_CU is the CU of the result.
18867 Returns NULL if OFFSET is invalid. */
18869 static struct die_info
*
18870 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
18871 struct dwarf2_cu
**ref_cu
)
18873 struct die_info temp_die
;
18874 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
18876 gdb_assert (cu
->per_cu
!= NULL
);
18880 if (cu
->per_cu
->is_debug_types
)
18882 /* .debug_types CUs cannot reference anything outside their CU.
18883 If they need to, they have to reference a signatured type via
18884 DW_FORM_ref_sig8. */
18885 if (! offset_in_cu_p (&cu
->header
, offset
))
18888 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
18889 || ! offset_in_cu_p (&cu
->header
, offset
))
18891 struct dwarf2_per_cu_data
*per_cu
;
18893 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
18896 /* If necessary, add it to the queue and load its DIEs. */
18897 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
18898 load_full_comp_unit (per_cu
, cu
->language
);
18900 target_cu
= per_cu
->cu
;
18902 else if (cu
->dies
== NULL
)
18904 /* We're loading full DIEs during partial symbol reading. */
18905 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
18906 load_full_comp_unit (cu
->per_cu
, language_minimal
);
18909 *ref_cu
= target_cu
;
18910 temp_die
.offset
= offset
;
18911 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
18914 /* Follow reference attribute ATTR of SRC_DIE.
18915 On entry *REF_CU is the CU of SRC_DIE.
18916 On exit *REF_CU is the CU of the result. */
18918 static struct die_info
*
18919 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
18920 struct dwarf2_cu
**ref_cu
)
18922 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
18923 struct dwarf2_cu
*cu
= *ref_cu
;
18924 struct die_info
*die
;
18926 die
= follow_die_offset (offset
,
18927 (attr
->form
== DW_FORM_GNU_ref_alt
18928 || cu
->per_cu
->is_dwz
),
18931 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
18932 "at 0x%x [in module %s]"),
18933 offset
.sect_off
, src_die
->offset
.sect_off
,
18934 objfile_name (cu
->objfile
));
18939 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
18940 Returned value is intended for DW_OP_call*. Returned
18941 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
18943 struct dwarf2_locexpr_baton
18944 dwarf2_fetch_die_loc_sect_off (sect_offset offset
,
18945 struct dwarf2_per_cu_data
*per_cu
,
18946 CORE_ADDR (*get_frame_pc
) (void *baton
),
18949 struct dwarf2_cu
*cu
;
18950 struct die_info
*die
;
18951 struct attribute
*attr
;
18952 struct dwarf2_locexpr_baton retval
;
18954 dw2_setup (per_cu
->objfile
);
18956 if (per_cu
->cu
== NULL
)
18960 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
18962 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
18963 offset
.sect_off
, objfile_name (per_cu
->objfile
));
18965 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
18968 /* DWARF: "If there is no such attribute, then there is no effect.".
18969 DATA is ignored if SIZE is 0. */
18971 retval
.data
= NULL
;
18974 else if (attr_form_is_section_offset (attr
))
18976 struct dwarf2_loclist_baton loclist_baton
;
18977 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
18980 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
18982 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
18984 retval
.size
= size
;
18988 if (!attr_form_is_block (attr
))
18989 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
18990 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
18991 offset
.sect_off
, objfile_name (per_cu
->objfile
));
18993 retval
.data
= DW_BLOCK (attr
)->data
;
18994 retval
.size
= DW_BLOCK (attr
)->size
;
18996 retval
.per_cu
= cu
->per_cu
;
18998 age_cached_comp_units ();
19003 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
19006 struct dwarf2_locexpr_baton
19007 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
19008 struct dwarf2_per_cu_data
*per_cu
,
19009 CORE_ADDR (*get_frame_pc
) (void *baton
),
19012 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
19014 return dwarf2_fetch_die_loc_sect_off (offset
, per_cu
, get_frame_pc
, baton
);
19017 /* Write a constant of a given type as target-ordered bytes into
19020 static const gdb_byte
*
19021 write_constant_as_bytes (struct obstack
*obstack
,
19022 enum bfd_endian byte_order
,
19029 *len
= TYPE_LENGTH (type
);
19030 result
= obstack_alloc (obstack
, *len
);
19031 store_unsigned_integer (result
, *len
, byte_order
, value
);
19036 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
19037 pointer to the constant bytes and set LEN to the length of the
19038 data. If memory is needed, allocate it on OBSTACK. If the DIE
19039 does not have a DW_AT_const_value, return NULL. */
19042 dwarf2_fetch_constant_bytes (sect_offset offset
,
19043 struct dwarf2_per_cu_data
*per_cu
,
19044 struct obstack
*obstack
,
19047 struct dwarf2_cu
*cu
;
19048 struct die_info
*die
;
19049 struct attribute
*attr
;
19050 const gdb_byte
*result
= NULL
;
19053 enum bfd_endian byte_order
;
19055 dw2_setup (per_cu
->objfile
);
19057 if (per_cu
->cu
== NULL
)
19061 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
19063 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
19064 offset
.sect_off
, objfile_name (per_cu
->objfile
));
19067 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19071 byte_order
= (bfd_big_endian (per_cu
->objfile
->obfd
)
19072 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
19074 switch (attr
->form
)
19077 case DW_FORM_GNU_addr_index
:
19081 *len
= cu
->header
.addr_size
;
19082 tem
= obstack_alloc (obstack
, *len
);
19083 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
19087 case DW_FORM_string
:
19089 case DW_FORM_GNU_str_index
:
19090 case DW_FORM_GNU_strp_alt
:
19091 /* DW_STRING is already allocated on the objfile obstack, point
19093 result
= (const gdb_byte
*) DW_STRING (attr
);
19094 *len
= strlen (DW_STRING (attr
));
19096 case DW_FORM_block1
:
19097 case DW_FORM_block2
:
19098 case DW_FORM_block4
:
19099 case DW_FORM_block
:
19100 case DW_FORM_exprloc
:
19101 result
= DW_BLOCK (attr
)->data
;
19102 *len
= DW_BLOCK (attr
)->size
;
19105 /* The DW_AT_const_value attributes are supposed to carry the
19106 symbol's value "represented as it would be on the target
19107 architecture." By the time we get here, it's already been
19108 converted to host endianness, so we just need to sign- or
19109 zero-extend it as appropriate. */
19110 case DW_FORM_data1
:
19111 type
= die_type (die
, cu
);
19112 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
19113 if (result
== NULL
)
19114 result
= write_constant_as_bytes (obstack
, byte_order
,
19117 case DW_FORM_data2
:
19118 type
= die_type (die
, cu
);
19119 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
19120 if (result
== NULL
)
19121 result
= write_constant_as_bytes (obstack
, byte_order
,
19124 case DW_FORM_data4
:
19125 type
= die_type (die
, cu
);
19126 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
19127 if (result
== NULL
)
19128 result
= write_constant_as_bytes (obstack
, byte_order
,
19131 case DW_FORM_data8
:
19132 type
= die_type (die
, cu
);
19133 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
19134 if (result
== NULL
)
19135 result
= write_constant_as_bytes (obstack
, byte_order
,
19139 case DW_FORM_sdata
:
19140 type
= die_type (die
, cu
);
19141 result
= write_constant_as_bytes (obstack
, byte_order
,
19142 type
, DW_SND (attr
), len
);
19145 case DW_FORM_udata
:
19146 type
= die_type (die
, cu
);
19147 result
= write_constant_as_bytes (obstack
, byte_order
,
19148 type
, DW_UNSND (attr
), len
);
19152 complaint (&symfile_complaints
,
19153 _("unsupported const value attribute form: '%s'"),
19154 dwarf_form_name (attr
->form
));
19161 /* Return the type of the DIE at DIE_OFFSET in the CU named by
19165 dwarf2_get_die_type (cu_offset die_offset
,
19166 struct dwarf2_per_cu_data
*per_cu
)
19168 sect_offset die_offset_sect
;
19170 dw2_setup (per_cu
->objfile
);
19172 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
19173 return get_die_type_at_offset (die_offset_sect
, per_cu
);
19176 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
19177 On entry *REF_CU is the CU of SRC_DIE.
19178 On exit *REF_CU is the CU of the result.
19179 Returns NULL if the referenced DIE isn't found. */
19181 static struct die_info
*
19182 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
19183 struct dwarf2_cu
**ref_cu
)
19185 struct objfile
*objfile
= (*ref_cu
)->objfile
;
19186 struct die_info temp_die
;
19187 struct dwarf2_cu
*sig_cu
;
19188 struct die_info
*die
;
19190 /* While it might be nice to assert sig_type->type == NULL here,
19191 we can get here for DW_AT_imported_declaration where we need
19192 the DIE not the type. */
19194 /* If necessary, add it to the queue and load its DIEs. */
19196 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
19197 read_signatured_type (sig_type
);
19199 sig_cu
= sig_type
->per_cu
.cu
;
19200 gdb_assert (sig_cu
!= NULL
);
19201 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
19202 temp_die
.offset
= sig_type
->type_offset_in_section
;
19203 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
19204 temp_die
.offset
.sect_off
);
19207 /* For .gdb_index version 7 keep track of included TUs.
19208 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
19209 if (dwarf2_per_objfile
->index_table
!= NULL
19210 && dwarf2_per_objfile
->index_table
->version
<= 7)
19212 VEC_safe_push (dwarf2_per_cu_ptr
,
19213 (*ref_cu
)->per_cu
->imported_symtabs
,
19224 /* Follow signatured type referenced by ATTR in SRC_DIE.
19225 On entry *REF_CU is the CU of SRC_DIE.
19226 On exit *REF_CU is the CU of the result.
19227 The result is the DIE of the type.
19228 If the referenced type cannot be found an error is thrown. */
19230 static struct die_info
*
19231 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
19232 struct dwarf2_cu
**ref_cu
)
19234 ULONGEST signature
= DW_SIGNATURE (attr
);
19235 struct signatured_type
*sig_type
;
19236 struct die_info
*die
;
19238 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
19240 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
19241 /* sig_type will be NULL if the signatured type is missing from
19243 if (sig_type
== NULL
)
19245 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
19246 " from DIE at 0x%x [in module %s]"),
19247 hex_string (signature
), src_die
->offset
.sect_off
,
19248 objfile_name ((*ref_cu
)->objfile
));
19251 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
19254 dump_die_for_error (src_die
);
19255 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
19256 " from DIE at 0x%x [in module %s]"),
19257 hex_string (signature
), src_die
->offset
.sect_off
,
19258 objfile_name ((*ref_cu
)->objfile
));
19264 /* Get the type specified by SIGNATURE referenced in DIE/CU,
19265 reading in and processing the type unit if necessary. */
19267 static struct type
*
19268 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
19269 struct dwarf2_cu
*cu
)
19271 struct signatured_type
*sig_type
;
19272 struct dwarf2_cu
*type_cu
;
19273 struct die_info
*type_die
;
19276 sig_type
= lookup_signatured_type (cu
, signature
);
19277 /* sig_type will be NULL if the signatured type is missing from
19279 if (sig_type
== NULL
)
19281 complaint (&symfile_complaints
,
19282 _("Dwarf Error: Cannot find signatured DIE %s referenced"
19283 " from DIE at 0x%x [in module %s]"),
19284 hex_string (signature
), die
->offset
.sect_off
,
19285 objfile_name (dwarf2_per_objfile
->objfile
));
19286 return build_error_marker_type (cu
, die
);
19289 /* If we already know the type we're done. */
19290 if (sig_type
->type
!= NULL
)
19291 return sig_type
->type
;
19294 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
19295 if (type_die
!= NULL
)
19297 /* N.B. We need to call get_die_type to ensure only one type for this DIE
19298 is created. This is important, for example, because for c++ classes
19299 we need TYPE_NAME set which is only done by new_symbol. Blech. */
19300 type
= read_type_die (type_die
, type_cu
);
19303 complaint (&symfile_complaints
,
19304 _("Dwarf Error: Cannot build signatured type %s"
19305 " referenced from DIE at 0x%x [in module %s]"),
19306 hex_string (signature
), die
->offset
.sect_off
,
19307 objfile_name (dwarf2_per_objfile
->objfile
));
19308 type
= build_error_marker_type (cu
, die
);
19313 complaint (&symfile_complaints
,
19314 _("Dwarf Error: Problem reading signatured DIE %s referenced"
19315 " from DIE at 0x%x [in module %s]"),
19316 hex_string (signature
), die
->offset
.sect_off
,
19317 objfile_name (dwarf2_per_objfile
->objfile
));
19318 type
= build_error_marker_type (cu
, die
);
19320 sig_type
->type
= type
;
19325 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
19326 reading in and processing the type unit if necessary. */
19328 static struct type
*
19329 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
19330 struct dwarf2_cu
*cu
) /* ARI: editCase function */
19332 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
19333 if (attr_form_is_ref (attr
))
19335 struct dwarf2_cu
*type_cu
= cu
;
19336 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
19338 return read_type_die (type_die
, type_cu
);
19340 else if (attr
->form
== DW_FORM_ref_sig8
)
19342 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
19346 complaint (&symfile_complaints
,
19347 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
19348 " at 0x%x [in module %s]"),
19349 dwarf_form_name (attr
->form
), die
->offset
.sect_off
,
19350 objfile_name (dwarf2_per_objfile
->objfile
));
19351 return build_error_marker_type (cu
, die
);
19355 /* Load the DIEs associated with type unit PER_CU into memory. */
19358 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
19360 struct signatured_type
*sig_type
;
19362 /* Caller is responsible for ensuring type_unit_groups don't get here. */
19363 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
19365 /* We have the per_cu, but we need the signatured_type.
19366 Fortunately this is an easy translation. */
19367 gdb_assert (per_cu
->is_debug_types
);
19368 sig_type
= (struct signatured_type
*) per_cu
;
19370 gdb_assert (per_cu
->cu
== NULL
);
19372 read_signatured_type (sig_type
);
19374 gdb_assert (per_cu
->cu
!= NULL
);
19377 /* die_reader_func for read_signatured_type.
19378 This is identical to load_full_comp_unit_reader,
19379 but is kept separate for now. */
19382 read_signatured_type_reader (const struct die_reader_specs
*reader
,
19383 const gdb_byte
*info_ptr
,
19384 struct die_info
*comp_unit_die
,
19388 struct dwarf2_cu
*cu
= reader
->cu
;
19390 gdb_assert (cu
->die_hash
== NULL
);
19392 htab_create_alloc_ex (cu
->header
.length
/ 12,
19396 &cu
->comp_unit_obstack
,
19397 hashtab_obstack_allocate
,
19398 dummy_obstack_deallocate
);
19401 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
19402 &info_ptr
, comp_unit_die
);
19403 cu
->dies
= comp_unit_die
;
19404 /* comp_unit_die is not stored in die_hash, no need. */
19406 /* We try not to read any attributes in this function, because not
19407 all CUs needed for references have been loaded yet, and symbol
19408 table processing isn't initialized. But we have to set the CU language,
19409 or we won't be able to build types correctly.
19410 Similarly, if we do not read the producer, we can not apply
19411 producer-specific interpretation. */
19412 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
19415 /* Read in a signatured type and build its CU and DIEs.
19416 If the type is a stub for the real type in a DWO file,
19417 read in the real type from the DWO file as well. */
19420 read_signatured_type (struct signatured_type
*sig_type
)
19422 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
19424 gdb_assert (per_cu
->is_debug_types
);
19425 gdb_assert (per_cu
->cu
== NULL
);
19427 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
19428 read_signatured_type_reader
, NULL
);
19429 sig_type
->per_cu
.tu_read
= 1;
19432 /* Decode simple location descriptions.
19433 Given a pointer to a dwarf block that defines a location, compute
19434 the location and return the value.
19436 NOTE drow/2003-11-18: This function is called in two situations
19437 now: for the address of static or global variables (partial symbols
19438 only) and for offsets into structures which are expected to be
19439 (more or less) constant. The partial symbol case should go away,
19440 and only the constant case should remain. That will let this
19441 function complain more accurately. A few special modes are allowed
19442 without complaint for global variables (for instance, global
19443 register values and thread-local values).
19445 A location description containing no operations indicates that the
19446 object is optimized out. The return value is 0 for that case.
19447 FIXME drow/2003-11-16: No callers check for this case any more; soon all
19448 callers will only want a very basic result and this can become a
19451 Note that stack[0] is unused except as a default error return. */
19454 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
19456 struct objfile
*objfile
= cu
->objfile
;
19458 size_t size
= blk
->size
;
19459 const gdb_byte
*data
= blk
->data
;
19460 CORE_ADDR stack
[64];
19462 unsigned int bytes_read
, unsnd
;
19468 stack
[++stacki
] = 0;
19507 stack
[++stacki
] = op
- DW_OP_lit0
;
19542 stack
[++stacki
] = op
- DW_OP_reg0
;
19544 dwarf2_complex_location_expr_complaint ();
19548 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
19550 stack
[++stacki
] = unsnd
;
19552 dwarf2_complex_location_expr_complaint ();
19556 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
19561 case DW_OP_const1u
:
19562 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
19566 case DW_OP_const1s
:
19567 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
19571 case DW_OP_const2u
:
19572 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
19576 case DW_OP_const2s
:
19577 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
19581 case DW_OP_const4u
:
19582 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
19586 case DW_OP_const4s
:
19587 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
19591 case DW_OP_const8u
:
19592 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
19597 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
19603 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
19608 stack
[stacki
+ 1] = stack
[stacki
];
19613 stack
[stacki
- 1] += stack
[stacki
];
19617 case DW_OP_plus_uconst
:
19618 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
19624 stack
[stacki
- 1] -= stack
[stacki
];
19629 /* If we're not the last op, then we definitely can't encode
19630 this using GDB's address_class enum. This is valid for partial
19631 global symbols, although the variable's address will be bogus
19634 dwarf2_complex_location_expr_complaint ();
19637 case DW_OP_GNU_push_tls_address
:
19638 /* The top of the stack has the offset from the beginning
19639 of the thread control block at which the variable is located. */
19640 /* Nothing should follow this operator, so the top of stack would
19642 /* This is valid for partial global symbols, but the variable's
19643 address will be bogus in the psymtab. Make it always at least
19644 non-zero to not look as a variable garbage collected by linker
19645 which have DW_OP_addr 0. */
19647 dwarf2_complex_location_expr_complaint ();
19651 case DW_OP_GNU_uninit
:
19654 case DW_OP_GNU_addr_index
:
19655 case DW_OP_GNU_const_index
:
19656 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
19663 const char *name
= get_DW_OP_name (op
);
19666 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
19669 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
19673 return (stack
[stacki
]);
19676 /* Enforce maximum stack depth of SIZE-1 to avoid writing
19677 outside of the allocated space. Also enforce minimum>0. */
19678 if (stacki
>= ARRAY_SIZE (stack
) - 1)
19680 complaint (&symfile_complaints
,
19681 _("location description stack overflow"));
19687 complaint (&symfile_complaints
,
19688 _("location description stack underflow"));
19692 return (stack
[stacki
]);
19695 /* memory allocation interface */
19697 static struct dwarf_block
*
19698 dwarf_alloc_block (struct dwarf2_cu
*cu
)
19700 struct dwarf_block
*blk
;
19702 blk
= (struct dwarf_block
*)
19703 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
19707 static struct die_info
*
19708 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
19710 struct die_info
*die
;
19711 size_t size
= sizeof (struct die_info
);
19714 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
19716 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
19717 memset (die
, 0, sizeof (struct die_info
));
19722 /* Macro support. */
19724 /* Return file name relative to the compilation directory of file number I in
19725 *LH's file name table. The result is allocated using xmalloc; the caller is
19726 responsible for freeing it. */
19729 file_file_name (int file
, struct line_header
*lh
)
19731 /* Is the file number a valid index into the line header's file name
19732 table? Remember that file numbers start with one, not zero. */
19733 if (1 <= file
&& file
<= lh
->num_file_names
)
19735 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
19737 if (IS_ABSOLUTE_PATH (fe
->name
) || fe
->dir_index
== 0)
19738 return xstrdup (fe
->name
);
19739 return concat (lh
->include_dirs
[fe
->dir_index
- 1], SLASH_STRING
,
19744 /* The compiler produced a bogus file number. We can at least
19745 record the macro definitions made in the file, even if we
19746 won't be able to find the file by name. */
19747 char fake_name
[80];
19749 xsnprintf (fake_name
, sizeof (fake_name
),
19750 "<bad macro file number %d>", file
);
19752 complaint (&symfile_complaints
,
19753 _("bad file number in macro information (%d)"),
19756 return xstrdup (fake_name
);
19760 /* Return the full name of file number I in *LH's file name table.
19761 Use COMP_DIR as the name of the current directory of the
19762 compilation. The result is allocated using xmalloc; the caller is
19763 responsible for freeing it. */
19765 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
19767 /* Is the file number a valid index into the line header's file name
19768 table? Remember that file numbers start with one, not zero. */
19769 if (1 <= file
&& file
<= lh
->num_file_names
)
19771 char *relative
= file_file_name (file
, lh
);
19773 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
19775 return reconcat (relative
, comp_dir
, SLASH_STRING
, relative
, NULL
);
19778 return file_file_name (file
, lh
);
19782 static struct macro_source_file
*
19783 macro_start_file (int file
, int line
,
19784 struct macro_source_file
*current_file
,
19785 const char *comp_dir
,
19786 struct line_header
*lh
, struct objfile
*objfile
)
19788 /* File name relative to the compilation directory of this source file. */
19789 char *file_name
= file_file_name (file
, lh
);
19791 if (! current_file
)
19793 /* Note: We don't create a macro table for this compilation unit
19794 at all until we actually get a filename. */
19795 struct macro_table
*macro_table
= get_macro_table (objfile
, comp_dir
);
19797 /* If we have no current file, then this must be the start_file
19798 directive for the compilation unit's main source file. */
19799 current_file
= macro_set_main (macro_table
, file_name
);
19800 macro_define_special (macro_table
);
19803 current_file
= macro_include (current_file
, line
, file_name
);
19807 return current_file
;
19811 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
19812 followed by a null byte. */
19814 copy_string (const char *buf
, int len
)
19816 char *s
= xmalloc (len
+ 1);
19818 memcpy (s
, buf
, len
);
19824 static const char *
19825 consume_improper_spaces (const char *p
, const char *body
)
19829 complaint (&symfile_complaints
,
19830 _("macro definition contains spaces "
19831 "in formal argument list:\n`%s'"),
19843 parse_macro_definition (struct macro_source_file
*file
, int line
,
19848 /* The body string takes one of two forms. For object-like macro
19849 definitions, it should be:
19851 <macro name> " " <definition>
19853 For function-like macro definitions, it should be:
19855 <macro name> "() " <definition>
19857 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
19859 Spaces may appear only where explicitly indicated, and in the
19862 The Dwarf 2 spec says that an object-like macro's name is always
19863 followed by a space, but versions of GCC around March 2002 omit
19864 the space when the macro's definition is the empty string.
19866 The Dwarf 2 spec says that there should be no spaces between the
19867 formal arguments in a function-like macro's formal argument list,
19868 but versions of GCC around March 2002 include spaces after the
19872 /* Find the extent of the macro name. The macro name is terminated
19873 by either a space or null character (for an object-like macro) or
19874 an opening paren (for a function-like macro). */
19875 for (p
= body
; *p
; p
++)
19876 if (*p
== ' ' || *p
== '(')
19879 if (*p
== ' ' || *p
== '\0')
19881 /* It's an object-like macro. */
19882 int name_len
= p
- body
;
19883 char *name
= copy_string (body
, name_len
);
19884 const char *replacement
;
19887 replacement
= body
+ name_len
+ 1;
19890 dwarf2_macro_malformed_definition_complaint (body
);
19891 replacement
= body
+ name_len
;
19894 macro_define_object (file
, line
, name
, replacement
);
19898 else if (*p
== '(')
19900 /* It's a function-like macro. */
19901 char *name
= copy_string (body
, p
- body
);
19904 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
19908 p
= consume_improper_spaces (p
, body
);
19910 /* Parse the formal argument list. */
19911 while (*p
&& *p
!= ')')
19913 /* Find the extent of the current argument name. */
19914 const char *arg_start
= p
;
19916 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
19919 if (! *p
|| p
== arg_start
)
19920 dwarf2_macro_malformed_definition_complaint (body
);
19923 /* Make sure argv has room for the new argument. */
19924 if (argc
>= argv_size
)
19927 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
19930 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
19933 p
= consume_improper_spaces (p
, body
);
19935 /* Consume the comma, if present. */
19940 p
= consume_improper_spaces (p
, body
);
19949 /* Perfectly formed definition, no complaints. */
19950 macro_define_function (file
, line
, name
,
19951 argc
, (const char **) argv
,
19953 else if (*p
== '\0')
19955 /* Complain, but do define it. */
19956 dwarf2_macro_malformed_definition_complaint (body
);
19957 macro_define_function (file
, line
, name
,
19958 argc
, (const char **) argv
,
19962 /* Just complain. */
19963 dwarf2_macro_malformed_definition_complaint (body
);
19966 /* Just complain. */
19967 dwarf2_macro_malformed_definition_complaint (body
);
19973 for (i
= 0; i
< argc
; i
++)
19979 dwarf2_macro_malformed_definition_complaint (body
);
19982 /* Skip some bytes from BYTES according to the form given in FORM.
19983 Returns the new pointer. */
19985 static const gdb_byte
*
19986 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
19987 enum dwarf_form form
,
19988 unsigned int offset_size
,
19989 struct dwarf2_section_info
*section
)
19991 unsigned int bytes_read
;
19995 case DW_FORM_data1
:
20000 case DW_FORM_data2
:
20004 case DW_FORM_data4
:
20008 case DW_FORM_data8
:
20012 case DW_FORM_string
:
20013 read_direct_string (abfd
, bytes
, &bytes_read
);
20014 bytes
+= bytes_read
;
20017 case DW_FORM_sec_offset
:
20019 case DW_FORM_GNU_strp_alt
:
20020 bytes
+= offset_size
;
20023 case DW_FORM_block
:
20024 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
20025 bytes
+= bytes_read
;
20028 case DW_FORM_block1
:
20029 bytes
+= 1 + read_1_byte (abfd
, bytes
);
20031 case DW_FORM_block2
:
20032 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
20034 case DW_FORM_block4
:
20035 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
20038 case DW_FORM_sdata
:
20039 case DW_FORM_udata
:
20040 case DW_FORM_GNU_addr_index
:
20041 case DW_FORM_GNU_str_index
:
20042 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
20045 dwarf2_section_buffer_overflow_complaint (section
);
20053 complaint (&symfile_complaints
,
20054 _("invalid form 0x%x in `%s'"),
20055 form
, get_section_name (section
));
20063 /* A helper for dwarf_decode_macros that handles skipping an unknown
20064 opcode. Returns an updated pointer to the macro data buffer; or,
20065 on error, issues a complaint and returns NULL. */
20067 static const gdb_byte
*
20068 skip_unknown_opcode (unsigned int opcode
,
20069 const gdb_byte
**opcode_definitions
,
20070 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
20072 unsigned int offset_size
,
20073 struct dwarf2_section_info
*section
)
20075 unsigned int bytes_read
, i
;
20077 const gdb_byte
*defn
;
20079 if (opcode_definitions
[opcode
] == NULL
)
20081 complaint (&symfile_complaints
,
20082 _("unrecognized DW_MACFINO opcode 0x%x"),
20087 defn
= opcode_definitions
[opcode
];
20088 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
20089 defn
+= bytes_read
;
20091 for (i
= 0; i
< arg
; ++i
)
20093 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
20095 if (mac_ptr
== NULL
)
20097 /* skip_form_bytes already issued the complaint. */
20105 /* A helper function which parses the header of a macro section.
20106 If the macro section is the extended (for now called "GNU") type,
20107 then this updates *OFFSET_SIZE. Returns a pointer to just after
20108 the header, or issues a complaint and returns NULL on error. */
20110 static const gdb_byte
*
20111 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
20113 const gdb_byte
*mac_ptr
,
20114 unsigned int *offset_size
,
20115 int section_is_gnu
)
20117 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
20119 if (section_is_gnu
)
20121 unsigned int version
, flags
;
20123 version
= read_2_bytes (abfd
, mac_ptr
);
20126 complaint (&symfile_complaints
,
20127 _("unrecognized version `%d' in .debug_macro section"),
20133 flags
= read_1_byte (abfd
, mac_ptr
);
20135 *offset_size
= (flags
& 1) ? 8 : 4;
20137 if ((flags
& 2) != 0)
20138 /* We don't need the line table offset. */
20139 mac_ptr
+= *offset_size
;
20141 /* Vendor opcode descriptions. */
20142 if ((flags
& 4) != 0)
20144 unsigned int i
, count
;
20146 count
= read_1_byte (abfd
, mac_ptr
);
20148 for (i
= 0; i
< count
; ++i
)
20150 unsigned int opcode
, bytes_read
;
20153 opcode
= read_1_byte (abfd
, mac_ptr
);
20155 opcode_definitions
[opcode
] = mac_ptr
;
20156 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20157 mac_ptr
+= bytes_read
;
20166 /* A helper for dwarf_decode_macros that handles the GNU extensions,
20167 including DW_MACRO_GNU_transparent_include. */
20170 dwarf_decode_macro_bytes (bfd
*abfd
,
20171 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
20172 struct macro_source_file
*current_file
,
20173 struct line_header
*lh
, const char *comp_dir
,
20174 struct dwarf2_section_info
*section
,
20175 int section_is_gnu
, int section_is_dwz
,
20176 unsigned int offset_size
,
20177 struct objfile
*objfile
,
20178 htab_t include_hash
)
20180 enum dwarf_macro_record_type macinfo_type
;
20181 int at_commandline
;
20182 const gdb_byte
*opcode_definitions
[256];
20184 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
20185 &offset_size
, section_is_gnu
);
20186 if (mac_ptr
== NULL
)
20188 /* We already issued a complaint. */
20192 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
20193 GDB is still reading the definitions from command line. First
20194 DW_MACINFO_start_file will need to be ignored as it was already executed
20195 to create CURRENT_FILE for the main source holding also the command line
20196 definitions. On first met DW_MACINFO_start_file this flag is reset to
20197 normally execute all the remaining DW_MACINFO_start_file macinfos. */
20199 at_commandline
= 1;
20203 /* Do we at least have room for a macinfo type byte? */
20204 if (mac_ptr
>= mac_end
)
20206 dwarf2_section_buffer_overflow_complaint (section
);
20210 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
20213 /* Note that we rely on the fact that the corresponding GNU and
20214 DWARF constants are the same. */
20215 switch (macinfo_type
)
20217 /* A zero macinfo type indicates the end of the macro
20222 case DW_MACRO_GNU_define
:
20223 case DW_MACRO_GNU_undef
:
20224 case DW_MACRO_GNU_define_indirect
:
20225 case DW_MACRO_GNU_undef_indirect
:
20226 case DW_MACRO_GNU_define_indirect_alt
:
20227 case DW_MACRO_GNU_undef_indirect_alt
:
20229 unsigned int bytes_read
;
20234 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20235 mac_ptr
+= bytes_read
;
20237 if (macinfo_type
== DW_MACRO_GNU_define
20238 || macinfo_type
== DW_MACRO_GNU_undef
)
20240 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
20241 mac_ptr
+= bytes_read
;
20245 LONGEST str_offset
;
20247 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
20248 mac_ptr
+= offset_size
;
20250 if (macinfo_type
== DW_MACRO_GNU_define_indirect_alt
20251 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
20254 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
20256 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
20259 body
= read_indirect_string_at_offset (abfd
, str_offset
);
20262 is_define
= (macinfo_type
== DW_MACRO_GNU_define
20263 || macinfo_type
== DW_MACRO_GNU_define_indirect
20264 || macinfo_type
== DW_MACRO_GNU_define_indirect_alt
);
20265 if (! current_file
)
20267 /* DWARF violation as no main source is present. */
20268 complaint (&symfile_complaints
,
20269 _("debug info with no main source gives macro %s "
20271 is_define
? _("definition") : _("undefinition"),
20275 if ((line
== 0 && !at_commandline
)
20276 || (line
!= 0 && at_commandline
))
20277 complaint (&symfile_complaints
,
20278 _("debug info gives %s macro %s with %s line %d: %s"),
20279 at_commandline
? _("command-line") : _("in-file"),
20280 is_define
? _("definition") : _("undefinition"),
20281 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
20284 parse_macro_definition (current_file
, line
, body
);
20287 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
20288 || macinfo_type
== DW_MACRO_GNU_undef_indirect
20289 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
);
20290 macro_undef (current_file
, line
, body
);
20295 case DW_MACRO_GNU_start_file
:
20297 unsigned int bytes_read
;
20300 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20301 mac_ptr
+= bytes_read
;
20302 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20303 mac_ptr
+= bytes_read
;
20305 if ((line
== 0 && !at_commandline
)
20306 || (line
!= 0 && at_commandline
))
20307 complaint (&symfile_complaints
,
20308 _("debug info gives source %d included "
20309 "from %s at %s line %d"),
20310 file
, at_commandline
? _("command-line") : _("file"),
20311 line
== 0 ? _("zero") : _("non-zero"), line
);
20313 if (at_commandline
)
20315 /* This DW_MACRO_GNU_start_file was executed in the
20317 at_commandline
= 0;
20320 current_file
= macro_start_file (file
, line
,
20321 current_file
, comp_dir
,
20326 case DW_MACRO_GNU_end_file
:
20327 if (! current_file
)
20328 complaint (&symfile_complaints
,
20329 _("macro debug info has an unmatched "
20330 "`close_file' directive"));
20333 current_file
= current_file
->included_by
;
20334 if (! current_file
)
20336 enum dwarf_macro_record_type next_type
;
20338 /* GCC circa March 2002 doesn't produce the zero
20339 type byte marking the end of the compilation
20340 unit. Complain if it's not there, but exit no
20343 /* Do we at least have room for a macinfo type byte? */
20344 if (mac_ptr
>= mac_end
)
20346 dwarf2_section_buffer_overflow_complaint (section
);
20350 /* We don't increment mac_ptr here, so this is just
20352 next_type
= read_1_byte (abfd
, mac_ptr
);
20353 if (next_type
!= 0)
20354 complaint (&symfile_complaints
,
20355 _("no terminating 0-type entry for "
20356 "macros in `.debug_macinfo' section"));
20363 case DW_MACRO_GNU_transparent_include
:
20364 case DW_MACRO_GNU_transparent_include_alt
:
20368 bfd
*include_bfd
= abfd
;
20369 struct dwarf2_section_info
*include_section
= section
;
20370 struct dwarf2_section_info alt_section
;
20371 const gdb_byte
*include_mac_end
= mac_end
;
20372 int is_dwz
= section_is_dwz
;
20373 const gdb_byte
*new_mac_ptr
;
20375 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
20376 mac_ptr
+= offset_size
;
20378 if (macinfo_type
== DW_MACRO_GNU_transparent_include_alt
)
20380 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
20382 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
20385 include_section
= &dwz
->macro
;
20386 include_bfd
= get_section_bfd_owner (include_section
);
20387 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
20391 new_mac_ptr
= include_section
->buffer
+ offset
;
20392 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
20396 /* This has actually happened; see
20397 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
20398 complaint (&symfile_complaints
,
20399 _("recursive DW_MACRO_GNU_transparent_include in "
20400 ".debug_macro section"));
20404 *slot
= (void *) new_mac_ptr
;
20406 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
20407 include_mac_end
, current_file
,
20409 section
, section_is_gnu
, is_dwz
,
20410 offset_size
, objfile
, include_hash
);
20412 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
20417 case DW_MACINFO_vendor_ext
:
20418 if (!section_is_gnu
)
20420 unsigned int bytes_read
;
20423 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20424 mac_ptr
+= bytes_read
;
20425 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
20426 mac_ptr
+= bytes_read
;
20428 /* We don't recognize any vendor extensions. */
20434 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
20435 mac_ptr
, mac_end
, abfd
, offset_size
,
20437 if (mac_ptr
== NULL
)
20441 } while (macinfo_type
!= 0);
20445 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
20446 const char *comp_dir
, int section_is_gnu
)
20448 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20449 struct line_header
*lh
= cu
->line_header
;
20451 const gdb_byte
*mac_ptr
, *mac_end
;
20452 struct macro_source_file
*current_file
= 0;
20453 enum dwarf_macro_record_type macinfo_type
;
20454 unsigned int offset_size
= cu
->header
.offset_size
;
20455 const gdb_byte
*opcode_definitions
[256];
20456 struct cleanup
*cleanup
;
20457 htab_t include_hash
;
20459 struct dwarf2_section_info
*section
;
20460 const char *section_name
;
20462 if (cu
->dwo_unit
!= NULL
)
20464 if (section_is_gnu
)
20466 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
20467 section_name
= ".debug_macro.dwo";
20471 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
20472 section_name
= ".debug_macinfo.dwo";
20477 if (section_is_gnu
)
20479 section
= &dwarf2_per_objfile
->macro
;
20480 section_name
= ".debug_macro";
20484 section
= &dwarf2_per_objfile
->macinfo
;
20485 section_name
= ".debug_macinfo";
20489 dwarf2_read_section (objfile
, section
);
20490 if (section
->buffer
== NULL
)
20492 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
20495 abfd
= get_section_bfd_owner (section
);
20497 /* First pass: Find the name of the base filename.
20498 This filename is needed in order to process all macros whose definition
20499 (or undefinition) comes from the command line. These macros are defined
20500 before the first DW_MACINFO_start_file entry, and yet still need to be
20501 associated to the base file.
20503 To determine the base file name, we scan the macro definitions until we
20504 reach the first DW_MACINFO_start_file entry. We then initialize
20505 CURRENT_FILE accordingly so that any macro definition found before the
20506 first DW_MACINFO_start_file can still be associated to the base file. */
20508 mac_ptr
= section
->buffer
+ offset
;
20509 mac_end
= section
->buffer
+ section
->size
;
20511 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
20512 &offset_size
, section_is_gnu
);
20513 if (mac_ptr
== NULL
)
20515 /* We already issued a complaint. */
20521 /* Do we at least have room for a macinfo type byte? */
20522 if (mac_ptr
>= mac_end
)
20524 /* Complaint is printed during the second pass as GDB will probably
20525 stop the first pass earlier upon finding
20526 DW_MACINFO_start_file. */
20530 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
20533 /* Note that we rely on the fact that the corresponding GNU and
20534 DWARF constants are the same. */
20535 switch (macinfo_type
)
20537 /* A zero macinfo type indicates the end of the macro
20542 case DW_MACRO_GNU_define
:
20543 case DW_MACRO_GNU_undef
:
20544 /* Only skip the data by MAC_PTR. */
20546 unsigned int bytes_read
;
20548 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20549 mac_ptr
+= bytes_read
;
20550 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
20551 mac_ptr
+= bytes_read
;
20555 case DW_MACRO_GNU_start_file
:
20557 unsigned int bytes_read
;
20560 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20561 mac_ptr
+= bytes_read
;
20562 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20563 mac_ptr
+= bytes_read
;
20565 current_file
= macro_start_file (file
, line
, current_file
,
20566 comp_dir
, lh
, objfile
);
20570 case DW_MACRO_GNU_end_file
:
20571 /* No data to skip by MAC_PTR. */
20574 case DW_MACRO_GNU_define_indirect
:
20575 case DW_MACRO_GNU_undef_indirect
:
20576 case DW_MACRO_GNU_define_indirect_alt
:
20577 case DW_MACRO_GNU_undef_indirect_alt
:
20579 unsigned int bytes_read
;
20581 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20582 mac_ptr
+= bytes_read
;
20583 mac_ptr
+= offset_size
;
20587 case DW_MACRO_GNU_transparent_include
:
20588 case DW_MACRO_GNU_transparent_include_alt
:
20589 /* Note that, according to the spec, a transparent include
20590 chain cannot call DW_MACRO_GNU_start_file. So, we can just
20591 skip this opcode. */
20592 mac_ptr
+= offset_size
;
20595 case DW_MACINFO_vendor_ext
:
20596 /* Only skip the data by MAC_PTR. */
20597 if (!section_is_gnu
)
20599 unsigned int bytes_read
;
20601 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
20602 mac_ptr
+= bytes_read
;
20603 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
20604 mac_ptr
+= bytes_read
;
20609 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
20610 mac_ptr
, mac_end
, abfd
, offset_size
,
20612 if (mac_ptr
== NULL
)
20616 } while (macinfo_type
!= 0 && current_file
== NULL
);
20618 /* Second pass: Process all entries.
20620 Use the AT_COMMAND_LINE flag to determine whether we are still processing
20621 command-line macro definitions/undefinitions. This flag is unset when we
20622 reach the first DW_MACINFO_start_file entry. */
20624 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
20625 NULL
, xcalloc
, xfree
);
20626 cleanup
= make_cleanup_htab_delete (include_hash
);
20627 mac_ptr
= section
->buffer
+ offset
;
20628 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
20629 *slot
= (void *) mac_ptr
;
20630 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
20631 current_file
, lh
, comp_dir
, section
,
20633 offset_size
, objfile
, include_hash
);
20634 do_cleanups (cleanup
);
20637 /* Check if the attribute's form is a DW_FORM_block*
20638 if so return true else false. */
20641 attr_form_is_block (const struct attribute
*attr
)
20643 return (attr
== NULL
? 0 :
20644 attr
->form
== DW_FORM_block1
20645 || attr
->form
== DW_FORM_block2
20646 || attr
->form
== DW_FORM_block4
20647 || attr
->form
== DW_FORM_block
20648 || attr
->form
== DW_FORM_exprloc
);
20651 /* Return non-zero if ATTR's value is a section offset --- classes
20652 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
20653 You may use DW_UNSND (attr) to retrieve such offsets.
20655 Section 7.5.4, "Attribute Encodings", explains that no attribute
20656 may have a value that belongs to more than one of these classes; it
20657 would be ambiguous if we did, because we use the same forms for all
20661 attr_form_is_section_offset (const struct attribute
*attr
)
20663 return (attr
->form
== DW_FORM_data4
20664 || attr
->form
== DW_FORM_data8
20665 || attr
->form
== DW_FORM_sec_offset
);
20668 /* Return non-zero if ATTR's value falls in the 'constant' class, or
20669 zero otherwise. When this function returns true, you can apply
20670 dwarf2_get_attr_constant_value to it.
20672 However, note that for some attributes you must check
20673 attr_form_is_section_offset before using this test. DW_FORM_data4
20674 and DW_FORM_data8 are members of both the constant class, and of
20675 the classes that contain offsets into other debug sections
20676 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
20677 that, if an attribute's can be either a constant or one of the
20678 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
20679 taken as section offsets, not constants. */
20682 attr_form_is_constant (const struct attribute
*attr
)
20684 switch (attr
->form
)
20686 case DW_FORM_sdata
:
20687 case DW_FORM_udata
:
20688 case DW_FORM_data1
:
20689 case DW_FORM_data2
:
20690 case DW_FORM_data4
:
20691 case DW_FORM_data8
:
20699 /* DW_ADDR is always stored already as sect_offset; despite for the forms
20700 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
20703 attr_form_is_ref (const struct attribute
*attr
)
20705 switch (attr
->form
)
20707 case DW_FORM_ref_addr
:
20712 case DW_FORM_ref_udata
:
20713 case DW_FORM_GNU_ref_alt
:
20720 /* Return the .debug_loc section to use for CU.
20721 For DWO files use .debug_loc.dwo. */
20723 static struct dwarf2_section_info
*
20724 cu_debug_loc_section (struct dwarf2_cu
*cu
)
20727 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
20728 return &dwarf2_per_objfile
->loc
;
20731 /* A helper function that fills in a dwarf2_loclist_baton. */
20734 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
20735 struct dwarf2_loclist_baton
*baton
,
20736 const struct attribute
*attr
)
20738 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
20740 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20742 baton
->per_cu
= cu
->per_cu
;
20743 gdb_assert (baton
->per_cu
);
20744 /* We don't know how long the location list is, but make sure we
20745 don't run off the edge of the section. */
20746 baton
->size
= section
->size
- DW_UNSND (attr
);
20747 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
20748 baton
->base_address
= cu
->base_address
;
20749 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
20753 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
20754 struct dwarf2_cu
*cu
, int is_block
)
20756 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20757 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
20759 if (attr_form_is_section_offset (attr
)
20760 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
20761 the section. If so, fall through to the complaint in the
20763 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
20765 struct dwarf2_loclist_baton
*baton
;
20767 baton
= obstack_alloc (&objfile
->objfile_obstack
,
20768 sizeof (struct dwarf2_loclist_baton
));
20770 fill_in_loclist_baton (cu
, baton
, attr
);
20772 if (cu
->base_known
== 0)
20773 complaint (&symfile_complaints
,
20774 _("Location list used without "
20775 "specifying the CU base address."));
20777 SYMBOL_ACLASS_INDEX (sym
) = (is_block
20778 ? dwarf2_loclist_block_index
20779 : dwarf2_loclist_index
);
20780 SYMBOL_LOCATION_BATON (sym
) = baton
;
20784 struct dwarf2_locexpr_baton
*baton
;
20786 baton
= obstack_alloc (&objfile
->objfile_obstack
,
20787 sizeof (struct dwarf2_locexpr_baton
));
20788 baton
->per_cu
= cu
->per_cu
;
20789 gdb_assert (baton
->per_cu
);
20791 if (attr_form_is_block (attr
))
20793 /* Note that we're just copying the block's data pointer
20794 here, not the actual data. We're still pointing into the
20795 info_buffer for SYM's objfile; right now we never release
20796 that buffer, but when we do clean up properly this may
20798 baton
->size
= DW_BLOCK (attr
)->size
;
20799 baton
->data
= DW_BLOCK (attr
)->data
;
20803 dwarf2_invalid_attrib_class_complaint ("location description",
20804 SYMBOL_NATURAL_NAME (sym
));
20808 SYMBOL_ACLASS_INDEX (sym
) = (is_block
20809 ? dwarf2_locexpr_block_index
20810 : dwarf2_locexpr_index
);
20811 SYMBOL_LOCATION_BATON (sym
) = baton
;
20815 /* Return the OBJFILE associated with the compilation unit CU. If CU
20816 came from a separate debuginfo file, then the master objfile is
20820 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
20822 struct objfile
*objfile
= per_cu
->objfile
;
20824 /* Return the master objfile, so that we can report and look up the
20825 correct file containing this variable. */
20826 if (objfile
->separate_debug_objfile_backlink
)
20827 objfile
= objfile
->separate_debug_objfile_backlink
;
20832 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
20833 (CU_HEADERP is unused in such case) or prepare a temporary copy at
20834 CU_HEADERP first. */
20836 static const struct comp_unit_head
*
20837 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
20838 struct dwarf2_per_cu_data
*per_cu
)
20840 const gdb_byte
*info_ptr
;
20843 return &per_cu
->cu
->header
;
20845 info_ptr
= per_cu
->section
->buffer
+ per_cu
->offset
.sect_off
;
20847 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
20848 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
20853 /* Return the address size given in the compilation unit header for CU. */
20856 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
20858 struct comp_unit_head cu_header_local
;
20859 const struct comp_unit_head
*cu_headerp
;
20861 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
20863 return cu_headerp
->addr_size
;
20866 /* Return the offset size given in the compilation unit header for CU. */
20869 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
20871 struct comp_unit_head cu_header_local
;
20872 const struct comp_unit_head
*cu_headerp
;
20874 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
20876 return cu_headerp
->offset_size
;
20879 /* See its dwarf2loc.h declaration. */
20882 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
20884 struct comp_unit_head cu_header_local
;
20885 const struct comp_unit_head
*cu_headerp
;
20887 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
20889 if (cu_headerp
->version
== 2)
20890 return cu_headerp
->addr_size
;
20892 return cu_headerp
->offset_size
;
20895 /* Return the text offset of the CU. The returned offset comes from
20896 this CU's objfile. If this objfile came from a separate debuginfo
20897 file, then the offset may be different from the corresponding
20898 offset in the parent objfile. */
20901 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
20903 struct objfile
*objfile
= per_cu
->objfile
;
20905 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
20908 /* Locate the .debug_info compilation unit from CU's objfile which contains
20909 the DIE at OFFSET. Raises an error on failure. */
20911 static struct dwarf2_per_cu_data
*
20912 dwarf2_find_containing_comp_unit (sect_offset offset
,
20913 unsigned int offset_in_dwz
,
20914 struct objfile
*objfile
)
20916 struct dwarf2_per_cu_data
*this_cu
;
20918 const sect_offset
*cu_off
;
20921 high
= dwarf2_per_objfile
->n_comp_units
- 1;
20924 struct dwarf2_per_cu_data
*mid_cu
;
20925 int mid
= low
+ (high
- low
) / 2;
20927 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
20928 cu_off
= &mid_cu
->offset
;
20929 if (mid_cu
->is_dwz
> offset_in_dwz
20930 || (mid_cu
->is_dwz
== offset_in_dwz
20931 && cu_off
->sect_off
>= offset
.sect_off
))
20936 gdb_assert (low
== high
);
20937 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
20938 cu_off
= &this_cu
->offset
;
20939 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
20941 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
20942 error (_("Dwarf Error: could not find partial DIE containing "
20943 "offset 0x%lx [in module %s]"),
20944 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
20946 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
20947 <= offset
.sect_off
);
20948 return dwarf2_per_objfile
->all_comp_units
[low
-1];
20952 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
20953 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
20954 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
20955 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
20956 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
20961 /* Initialize dwarf2_cu CU, owned by PER_CU. */
20964 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
20966 memset (cu
, 0, sizeof (*cu
));
20968 cu
->per_cu
= per_cu
;
20969 cu
->objfile
= per_cu
->objfile
;
20970 obstack_init (&cu
->comp_unit_obstack
);
20973 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
20976 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
20977 enum language pretend_language
)
20979 struct attribute
*attr
;
20981 /* Set the language we're debugging. */
20982 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
20984 set_cu_language (DW_UNSND (attr
), cu
);
20987 cu
->language
= pretend_language
;
20988 cu
->language_defn
= language_def (cu
->language
);
20991 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
20993 cu
->producer
= DW_STRING (attr
);
20996 /* Release one cached compilation unit, CU. We unlink it from the tree
20997 of compilation units, but we don't remove it from the read_in_chain;
20998 the caller is responsible for that.
20999 NOTE: DATA is a void * because this function is also used as a
21000 cleanup routine. */
21003 free_heap_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
);
21016 /* This cleanup function is passed the address of a dwarf2_cu on the stack
21017 when we're finished with it. We can't free the pointer itself, but be
21018 sure to unlink it from the cache. Also release any associated storage. */
21021 free_stack_comp_unit (void *data
)
21023 struct dwarf2_cu
*cu
= data
;
21025 gdb_assert (cu
->per_cu
!= NULL
);
21026 cu
->per_cu
->cu
= NULL
;
21029 obstack_free (&cu
->comp_unit_obstack
, NULL
);
21030 cu
->partial_dies
= NULL
;
21033 /* Free all cached compilation units. */
21036 free_cached_comp_units (void *data
)
21038 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
21040 per_cu
= dwarf2_per_objfile
->read_in_chain
;
21041 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
21042 while (per_cu
!= NULL
)
21044 struct dwarf2_per_cu_data
*next_cu
;
21046 next_cu
= per_cu
->cu
->read_in_chain
;
21048 free_heap_comp_unit (per_cu
->cu
);
21049 *last_chain
= next_cu
;
21055 /* Increase the age counter on each cached compilation unit, and free
21056 any that are too old. */
21059 age_cached_comp_units (void)
21061 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
21063 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
21064 per_cu
= dwarf2_per_objfile
->read_in_chain
;
21065 while (per_cu
!= NULL
)
21067 per_cu
->cu
->last_used
++;
21068 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
21069 dwarf2_mark (per_cu
->cu
);
21070 per_cu
= per_cu
->cu
->read_in_chain
;
21073 per_cu
= dwarf2_per_objfile
->read_in_chain
;
21074 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
21075 while (per_cu
!= NULL
)
21077 struct dwarf2_per_cu_data
*next_cu
;
21079 next_cu
= per_cu
->cu
->read_in_chain
;
21081 if (!per_cu
->cu
->mark
)
21083 free_heap_comp_unit (per_cu
->cu
);
21084 *last_chain
= next_cu
;
21087 last_chain
= &per_cu
->cu
->read_in_chain
;
21093 /* Remove a single compilation unit from the cache. */
21096 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
21098 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
21100 per_cu
= dwarf2_per_objfile
->read_in_chain
;
21101 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
21102 while (per_cu
!= NULL
)
21104 struct dwarf2_per_cu_data
*next_cu
;
21106 next_cu
= per_cu
->cu
->read_in_chain
;
21108 if (per_cu
== target_per_cu
)
21110 free_heap_comp_unit (per_cu
->cu
);
21112 *last_chain
= next_cu
;
21116 last_chain
= &per_cu
->cu
->read_in_chain
;
21122 /* Release all extra memory associated with OBJFILE. */
21125 dwarf2_free_objfile (struct objfile
*objfile
)
21127 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
21129 if (dwarf2_per_objfile
== NULL
)
21132 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
21133 free_cached_comp_units (NULL
);
21135 if (dwarf2_per_objfile
->quick_file_names_table
)
21136 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
21138 /* Everything else should be on the objfile obstack. */
21141 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
21142 We store these in a hash table separate from the DIEs, and preserve them
21143 when the DIEs are flushed out of cache.
21145 The CU "per_cu" pointer is needed because offset alone is not enough to
21146 uniquely identify the type. A file may have multiple .debug_types sections,
21147 or the type may come from a DWO file. Furthermore, while it's more logical
21148 to use per_cu->section+offset, with Fission the section with the data is in
21149 the DWO file but we don't know that section at the point we need it.
21150 We have to use something in dwarf2_per_cu_data (or the pointer to it)
21151 because we can enter the lookup routine, get_die_type_at_offset, from
21152 outside this file, and thus won't necessarily have PER_CU->cu.
21153 Fortunately, PER_CU is stable for the life of the objfile. */
21155 struct dwarf2_per_cu_offset_and_type
21157 const struct dwarf2_per_cu_data
*per_cu
;
21158 sect_offset offset
;
21162 /* Hash function for a dwarf2_per_cu_offset_and_type. */
21165 per_cu_offset_and_type_hash (const void *item
)
21167 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
21169 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
21172 /* Equality function for a dwarf2_per_cu_offset_and_type. */
21175 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
21177 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
21178 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
21180 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
21181 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
21184 /* Set the type associated with DIE to TYPE. Save it in CU's hash
21185 table if necessary. For convenience, return TYPE.
21187 The DIEs reading must have careful ordering to:
21188 * Not cause infite loops trying to read in DIEs as a prerequisite for
21189 reading current DIE.
21190 * Not trying to dereference contents of still incompletely read in types
21191 while reading in other DIEs.
21192 * Enable referencing still incompletely read in types just by a pointer to
21193 the type without accessing its fields.
21195 Therefore caller should follow these rules:
21196 * Try to fetch any prerequisite types we may need to build this DIE type
21197 before building the type and calling set_die_type.
21198 * After building type call set_die_type for current DIE as soon as
21199 possible before fetching more types to complete the current type.
21200 * Make the type as complete as possible before fetching more types. */
21202 static struct type
*
21203 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
21205 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
21206 struct objfile
*objfile
= cu
->objfile
;
21208 /* For Ada types, make sure that the gnat-specific data is always
21209 initialized (if not already set). There are a few types where
21210 we should not be doing so, because the type-specific area is
21211 already used to hold some other piece of info (eg: TYPE_CODE_FLT
21212 where the type-specific area is used to store the floatformat).
21213 But this is not a problem, because the gnat-specific information
21214 is actually not needed for these types. */
21215 if (need_gnat_info (cu
)
21216 && TYPE_CODE (type
) != TYPE_CODE_FUNC
21217 && TYPE_CODE (type
) != TYPE_CODE_FLT
21218 && !HAVE_GNAT_AUX_INFO (type
))
21219 INIT_GNAT_SPECIFIC (type
);
21221 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
21223 dwarf2_per_objfile
->die_type_hash
=
21224 htab_create_alloc_ex (127,
21225 per_cu_offset_and_type_hash
,
21226 per_cu_offset_and_type_eq
,
21228 &objfile
->objfile_obstack
,
21229 hashtab_obstack_allocate
,
21230 dummy_obstack_deallocate
);
21233 ofs
.per_cu
= cu
->per_cu
;
21234 ofs
.offset
= die
->offset
;
21236 slot
= (struct dwarf2_per_cu_offset_and_type
**)
21237 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
21239 complaint (&symfile_complaints
,
21240 _("A problem internal to GDB: DIE 0x%x has type already set"),
21241 die
->offset
.sect_off
);
21242 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
21247 /* Look up the type for the die at OFFSET in PER_CU in die_type_hash,
21248 or return NULL if the die does not have a saved type. */
21250 static struct type
*
21251 get_die_type_at_offset (sect_offset offset
,
21252 struct dwarf2_per_cu_data
*per_cu
)
21254 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
21256 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
21259 ofs
.per_cu
= per_cu
;
21260 ofs
.offset
= offset
;
21261 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
21268 /* Look up the type for DIE in CU in die_type_hash,
21269 or return NULL if DIE does not have a saved type. */
21271 static struct type
*
21272 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21274 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
21277 /* Add a dependence relationship from CU to REF_PER_CU. */
21280 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
21281 struct dwarf2_per_cu_data
*ref_per_cu
)
21285 if (cu
->dependencies
== NULL
)
21287 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
21288 NULL
, &cu
->comp_unit_obstack
,
21289 hashtab_obstack_allocate
,
21290 dummy_obstack_deallocate
);
21292 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
21294 *slot
= ref_per_cu
;
21297 /* Subroutine of dwarf2_mark to pass to htab_traverse.
21298 Set the mark field in every compilation unit in the
21299 cache that we must keep because we are keeping CU. */
21302 dwarf2_mark_helper (void **slot
, void *data
)
21304 struct dwarf2_per_cu_data
*per_cu
;
21306 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
21308 /* cu->dependencies references may not yet have been ever read if QUIT aborts
21309 reading of the chain. As such dependencies remain valid it is not much
21310 useful to track and undo them during QUIT cleanups. */
21311 if (per_cu
->cu
== NULL
)
21314 if (per_cu
->cu
->mark
)
21316 per_cu
->cu
->mark
= 1;
21318 if (per_cu
->cu
->dependencies
!= NULL
)
21319 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
21324 /* Set the mark field in CU and in every other compilation unit in the
21325 cache that we must keep because we are keeping CU. */
21328 dwarf2_mark (struct dwarf2_cu
*cu
)
21333 if (cu
->dependencies
!= NULL
)
21334 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
21338 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
21342 per_cu
->cu
->mark
= 0;
21343 per_cu
= per_cu
->cu
->read_in_chain
;
21347 /* Trivial hash function for partial_die_info: the hash value of a DIE
21348 is its offset in .debug_info for this objfile. */
21351 partial_die_hash (const void *item
)
21353 const struct partial_die_info
*part_die
= item
;
21355 return part_die
->offset
.sect_off
;
21358 /* Trivial comparison function for partial_die_info structures: two DIEs
21359 are equal if they have the same offset. */
21362 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
21364 const struct partial_die_info
*part_die_lhs
= item_lhs
;
21365 const struct partial_die_info
*part_die_rhs
= item_rhs
;
21367 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
21370 static struct cmd_list_element
*set_dwarf2_cmdlist
;
21371 static struct cmd_list_element
*show_dwarf2_cmdlist
;
21374 set_dwarf2_cmd (char *args
, int from_tty
)
21376 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
21380 show_dwarf2_cmd (char *args
, int from_tty
)
21382 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
21385 /* Free data associated with OBJFILE, if necessary. */
21388 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
21390 struct dwarf2_per_objfile
*data
= d
;
21393 /* Make sure we don't accidentally use dwarf2_per_objfile while
21395 dwarf2_per_objfile
= NULL
;
21397 for (ix
= 0; ix
< data
->n_comp_units
; ++ix
)
21398 VEC_free (dwarf2_per_cu_ptr
, data
->all_comp_units
[ix
]->imported_symtabs
);
21400 for (ix
= 0; ix
< data
->n_type_units
; ++ix
)
21401 VEC_free (dwarf2_per_cu_ptr
,
21402 data
->all_type_units
[ix
]->per_cu
.imported_symtabs
);
21403 xfree (data
->all_type_units
);
21405 VEC_free (dwarf2_section_info_def
, data
->types
);
21407 if (data
->dwo_files
)
21408 free_dwo_files (data
->dwo_files
, objfile
);
21409 if (data
->dwp_file
)
21410 gdb_bfd_unref (data
->dwp_file
->dbfd
);
21412 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
21413 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
21417 /* The "save gdb-index" command. */
21419 /* The contents of the hash table we create when building the string
21421 struct strtab_entry
21423 offset_type offset
;
21427 /* Hash function for a strtab_entry.
21429 Function is used only during write_hash_table so no index format backward
21430 compatibility is needed. */
21433 hash_strtab_entry (const void *e
)
21435 const struct strtab_entry
*entry
= e
;
21436 return mapped_index_string_hash (INT_MAX
, entry
->str
);
21439 /* Equality function for a strtab_entry. */
21442 eq_strtab_entry (const void *a
, const void *b
)
21444 const struct strtab_entry
*ea
= a
;
21445 const struct strtab_entry
*eb
= b
;
21446 return !strcmp (ea
->str
, eb
->str
);
21449 /* Create a strtab_entry hash table. */
21452 create_strtab (void)
21454 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
21455 xfree
, xcalloc
, xfree
);
21458 /* Add a string to the constant pool. Return the string's offset in
21462 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
21465 struct strtab_entry entry
;
21466 struct strtab_entry
*result
;
21469 slot
= htab_find_slot (table
, &entry
, INSERT
);
21474 result
= XNEW (struct strtab_entry
);
21475 result
->offset
= obstack_object_size (cpool
);
21477 obstack_grow_str0 (cpool
, str
);
21480 return result
->offset
;
21483 /* An entry in the symbol table. */
21484 struct symtab_index_entry
21486 /* The name of the symbol. */
21488 /* The offset of the name in the constant pool. */
21489 offset_type index_offset
;
21490 /* A sorted vector of the indices of all the CUs that hold an object
21492 VEC (offset_type
) *cu_indices
;
21495 /* The symbol table. This is a power-of-2-sized hash table. */
21496 struct mapped_symtab
21498 offset_type n_elements
;
21500 struct symtab_index_entry
**data
;
21503 /* Hash function for a symtab_index_entry. */
21506 hash_symtab_entry (const void *e
)
21508 const struct symtab_index_entry
*entry
= e
;
21509 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
21510 sizeof (offset_type
) * VEC_length (offset_type
,
21511 entry
->cu_indices
),
21515 /* Equality function for a symtab_index_entry. */
21518 eq_symtab_entry (const void *a
, const void *b
)
21520 const struct symtab_index_entry
*ea
= a
;
21521 const struct symtab_index_entry
*eb
= b
;
21522 int len
= VEC_length (offset_type
, ea
->cu_indices
);
21523 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
21525 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
21526 VEC_address (offset_type
, eb
->cu_indices
),
21527 sizeof (offset_type
) * len
);
21530 /* Destroy a symtab_index_entry. */
21533 delete_symtab_entry (void *p
)
21535 struct symtab_index_entry
*entry
= p
;
21536 VEC_free (offset_type
, entry
->cu_indices
);
21540 /* Create a hash table holding symtab_index_entry objects. */
21543 create_symbol_hash_table (void)
21545 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
21546 delete_symtab_entry
, xcalloc
, xfree
);
21549 /* Create a new mapped symtab object. */
21551 static struct mapped_symtab
*
21552 create_mapped_symtab (void)
21554 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
21555 symtab
->n_elements
= 0;
21556 symtab
->size
= 1024;
21557 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
21561 /* Destroy a mapped_symtab. */
21564 cleanup_mapped_symtab (void *p
)
21566 struct mapped_symtab
*symtab
= p
;
21567 /* The contents of the array are freed when the other hash table is
21569 xfree (symtab
->data
);
21573 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
21576 Function is used only during write_hash_table so no index format backward
21577 compatibility is needed. */
21579 static struct symtab_index_entry
**
21580 find_slot (struct mapped_symtab
*symtab
, const char *name
)
21582 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
21584 index
= hash
& (symtab
->size
- 1);
21585 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
21589 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
21590 return &symtab
->data
[index
];
21591 index
= (index
+ step
) & (symtab
->size
- 1);
21595 /* Expand SYMTAB's hash table. */
21598 hash_expand (struct mapped_symtab
*symtab
)
21600 offset_type old_size
= symtab
->size
;
21602 struct symtab_index_entry
**old_entries
= symtab
->data
;
21605 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
21607 for (i
= 0; i
< old_size
; ++i
)
21609 if (old_entries
[i
])
21611 struct symtab_index_entry
**slot
= find_slot (symtab
,
21612 old_entries
[i
]->name
);
21613 *slot
= old_entries
[i
];
21617 xfree (old_entries
);
21620 /* Add an entry to SYMTAB. NAME is the name of the symbol.
21621 CU_INDEX is the index of the CU in which the symbol appears.
21622 IS_STATIC is one if the symbol is static, otherwise zero (global). */
21625 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
21626 int is_static
, gdb_index_symbol_kind kind
,
21627 offset_type cu_index
)
21629 struct symtab_index_entry
**slot
;
21630 offset_type cu_index_and_attrs
;
21632 ++symtab
->n_elements
;
21633 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
21634 hash_expand (symtab
);
21636 slot
= find_slot (symtab
, name
);
21639 *slot
= XNEW (struct symtab_index_entry
);
21640 (*slot
)->name
= name
;
21641 /* index_offset is set later. */
21642 (*slot
)->cu_indices
= NULL
;
21645 cu_index_and_attrs
= 0;
21646 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
21647 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
21648 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
21650 /* We don't want to record an index value twice as we want to avoid the
21652 We process all global symbols and then all static symbols
21653 (which would allow us to avoid the duplication by only having to check
21654 the last entry pushed), but a symbol could have multiple kinds in one CU.
21655 To keep things simple we don't worry about the duplication here and
21656 sort and uniqufy the list after we've processed all symbols. */
21657 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
21660 /* qsort helper routine for uniquify_cu_indices. */
21663 offset_type_compare (const void *ap
, const void *bp
)
21665 offset_type a
= *(offset_type
*) ap
;
21666 offset_type b
= *(offset_type
*) bp
;
21668 return (a
> b
) - (b
> a
);
21671 /* Sort and remove duplicates of all symbols' cu_indices lists. */
21674 uniquify_cu_indices (struct mapped_symtab
*symtab
)
21678 for (i
= 0; i
< symtab
->size
; ++i
)
21680 struct symtab_index_entry
*entry
= symtab
->data
[i
];
21683 && entry
->cu_indices
!= NULL
)
21685 unsigned int next_to_insert
, next_to_check
;
21686 offset_type last_value
;
21688 qsort (VEC_address (offset_type
, entry
->cu_indices
),
21689 VEC_length (offset_type
, entry
->cu_indices
),
21690 sizeof (offset_type
), offset_type_compare
);
21692 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
21693 next_to_insert
= 1;
21694 for (next_to_check
= 1;
21695 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
21698 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
21701 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
21703 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
21708 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
21713 /* Add a vector of indices to the constant pool. */
21716 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
21717 struct symtab_index_entry
*entry
)
21721 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
21724 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
21725 offset_type val
= MAYBE_SWAP (len
);
21730 entry
->index_offset
= obstack_object_size (cpool
);
21732 obstack_grow (cpool
, &val
, sizeof (val
));
21734 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
21737 val
= MAYBE_SWAP (iter
);
21738 obstack_grow (cpool
, &val
, sizeof (val
));
21743 struct symtab_index_entry
*old_entry
= *slot
;
21744 entry
->index_offset
= old_entry
->index_offset
;
21747 return entry
->index_offset
;
21750 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
21751 constant pool entries going into the obstack CPOOL. */
21754 write_hash_table (struct mapped_symtab
*symtab
,
21755 struct obstack
*output
, struct obstack
*cpool
)
21758 htab_t symbol_hash_table
;
21761 symbol_hash_table
= create_symbol_hash_table ();
21762 str_table
= create_strtab ();
21764 /* We add all the index vectors to the constant pool first, to
21765 ensure alignment is ok. */
21766 for (i
= 0; i
< symtab
->size
; ++i
)
21768 if (symtab
->data
[i
])
21769 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
21772 /* Now write out the hash table. */
21773 for (i
= 0; i
< symtab
->size
; ++i
)
21775 offset_type str_off
, vec_off
;
21777 if (symtab
->data
[i
])
21779 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
21780 vec_off
= symtab
->data
[i
]->index_offset
;
21784 /* While 0 is a valid constant pool index, it is not valid
21785 to have 0 for both offsets. */
21790 str_off
= MAYBE_SWAP (str_off
);
21791 vec_off
= MAYBE_SWAP (vec_off
);
21793 obstack_grow (output
, &str_off
, sizeof (str_off
));
21794 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
21797 htab_delete (str_table
);
21798 htab_delete (symbol_hash_table
);
21801 /* Struct to map psymtab to CU index in the index file. */
21802 struct psymtab_cu_index_map
21804 struct partial_symtab
*psymtab
;
21805 unsigned int cu_index
;
21809 hash_psymtab_cu_index (const void *item
)
21811 const struct psymtab_cu_index_map
*map
= item
;
21813 return htab_hash_pointer (map
->psymtab
);
21817 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
21819 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
21820 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
21822 return lhs
->psymtab
== rhs
->psymtab
;
21825 /* Helper struct for building the address table. */
21826 struct addrmap_index_data
21828 struct objfile
*objfile
;
21829 struct obstack
*addr_obstack
;
21830 htab_t cu_index_htab
;
21832 /* Non-zero if the previous_* fields are valid.
21833 We can't write an entry until we see the next entry (since it is only then
21834 that we know the end of the entry). */
21835 int previous_valid
;
21836 /* Index of the CU in the table of all CUs in the index file. */
21837 unsigned int previous_cu_index
;
21838 /* Start address of the CU. */
21839 CORE_ADDR previous_cu_start
;
21842 /* Write an address entry to OBSTACK. */
21845 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
21846 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
21848 offset_type cu_index_to_write
;
21850 CORE_ADDR baseaddr
;
21852 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21854 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
21855 obstack_grow (obstack
, addr
, 8);
21856 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
21857 obstack_grow (obstack
, addr
, 8);
21858 cu_index_to_write
= MAYBE_SWAP (cu_index
);
21859 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
21862 /* Worker function for traversing an addrmap to build the address table. */
21865 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
21867 struct addrmap_index_data
*data
= datap
;
21868 struct partial_symtab
*pst
= obj
;
21870 if (data
->previous_valid
)
21871 add_address_entry (data
->objfile
, data
->addr_obstack
,
21872 data
->previous_cu_start
, start_addr
,
21873 data
->previous_cu_index
);
21875 data
->previous_cu_start
= start_addr
;
21878 struct psymtab_cu_index_map find_map
, *map
;
21879 find_map
.psymtab
= pst
;
21880 map
= htab_find (data
->cu_index_htab
, &find_map
);
21881 gdb_assert (map
!= NULL
);
21882 data
->previous_cu_index
= map
->cu_index
;
21883 data
->previous_valid
= 1;
21886 data
->previous_valid
= 0;
21891 /* Write OBJFILE's address map to OBSTACK.
21892 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
21893 in the index file. */
21896 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
21897 htab_t cu_index_htab
)
21899 struct addrmap_index_data addrmap_index_data
;
21901 /* When writing the address table, we have to cope with the fact that
21902 the addrmap iterator only provides the start of a region; we have to
21903 wait until the next invocation to get the start of the next region. */
21905 addrmap_index_data
.objfile
= objfile
;
21906 addrmap_index_data
.addr_obstack
= obstack
;
21907 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
21908 addrmap_index_data
.previous_valid
= 0;
21910 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
21911 &addrmap_index_data
);
21913 /* It's highly unlikely the last entry (end address = 0xff...ff)
21914 is valid, but we should still handle it.
21915 The end address is recorded as the start of the next region, but that
21916 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
21918 if (addrmap_index_data
.previous_valid
)
21919 add_address_entry (objfile
, obstack
,
21920 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
21921 addrmap_index_data
.previous_cu_index
);
21924 /* Return the symbol kind of PSYM. */
21926 static gdb_index_symbol_kind
21927 symbol_kind (struct partial_symbol
*psym
)
21929 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
21930 enum address_class aclass
= PSYMBOL_CLASS (psym
);
21938 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
21940 return GDB_INDEX_SYMBOL_KIND_TYPE
;
21942 case LOC_CONST_BYTES
:
21943 case LOC_OPTIMIZED_OUT
:
21945 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
21947 /* Note: It's currently impossible to recognize psyms as enum values
21948 short of reading the type info. For now punt. */
21949 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
21951 /* There are other LOC_FOO values that one might want to classify
21952 as variables, but dwarf2read.c doesn't currently use them. */
21953 return GDB_INDEX_SYMBOL_KIND_OTHER
;
21955 case STRUCT_DOMAIN
:
21956 return GDB_INDEX_SYMBOL_KIND_TYPE
;
21958 return GDB_INDEX_SYMBOL_KIND_OTHER
;
21962 /* Add a list of partial symbols to SYMTAB. */
21965 write_psymbols (struct mapped_symtab
*symtab
,
21967 struct partial_symbol
**psymp
,
21969 offset_type cu_index
,
21972 for (; count
-- > 0; ++psymp
)
21974 struct partial_symbol
*psym
= *psymp
;
21977 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
21978 error (_("Ada is not currently supported by the index"));
21980 /* Only add a given psymbol once. */
21981 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
21984 gdb_index_symbol_kind kind
= symbol_kind (psym
);
21987 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
21988 is_static
, kind
, cu_index
);
21993 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
21994 exception if there is an error. */
21997 write_obstack (FILE *file
, struct obstack
*obstack
)
21999 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
22001 != obstack_object_size (obstack
))
22002 error (_("couldn't data write to file"));
22005 /* Unlink a file if the argument is not NULL. */
22008 unlink_if_set (void *p
)
22010 char **filename
= p
;
22012 unlink (*filename
);
22015 /* A helper struct used when iterating over debug_types. */
22016 struct signatured_type_index_data
22018 struct objfile
*objfile
;
22019 struct mapped_symtab
*symtab
;
22020 struct obstack
*types_list
;
22025 /* A helper function that writes a single signatured_type to an
22029 write_one_signatured_type (void **slot
, void *d
)
22031 struct signatured_type_index_data
*info
= d
;
22032 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
22033 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
22036 write_psymbols (info
->symtab
,
22038 info
->objfile
->global_psymbols
.list
22039 + psymtab
->globals_offset
,
22040 psymtab
->n_global_syms
, info
->cu_index
,
22042 write_psymbols (info
->symtab
,
22044 info
->objfile
->static_psymbols
.list
22045 + psymtab
->statics_offset
,
22046 psymtab
->n_static_syms
, info
->cu_index
,
22049 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
22050 entry
->per_cu
.offset
.sect_off
);
22051 obstack_grow (info
->types_list
, val
, 8);
22052 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
22053 entry
->type_offset_in_tu
.cu_off
);
22054 obstack_grow (info
->types_list
, val
, 8);
22055 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
22056 obstack_grow (info
->types_list
, val
, 8);
22063 /* Recurse into all "included" dependencies and write their symbols as
22064 if they appeared in this psymtab. */
22067 recursively_write_psymbols (struct objfile
*objfile
,
22068 struct partial_symtab
*psymtab
,
22069 struct mapped_symtab
*symtab
,
22071 offset_type cu_index
)
22075 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
22076 if (psymtab
->dependencies
[i
]->user
!= NULL
)
22077 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
22078 symtab
, psyms_seen
, cu_index
);
22080 write_psymbols (symtab
,
22082 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
22083 psymtab
->n_global_syms
, cu_index
,
22085 write_psymbols (symtab
,
22087 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
22088 psymtab
->n_static_syms
, cu_index
,
22092 /* Create an index file for OBJFILE in the directory DIR. */
22095 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
22097 struct cleanup
*cleanup
;
22098 char *filename
, *cleanup_filename
;
22099 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
22100 struct obstack cu_list
, types_cu_list
;
22103 struct mapped_symtab
*symtab
;
22104 offset_type val
, size_of_contents
, total_len
;
22107 htab_t cu_index_htab
;
22108 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
22110 if (dwarf2_per_objfile
->using_index
)
22111 error (_("Cannot use an index to create the index"));
22113 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
22114 error (_("Cannot make an index when the file has multiple .debug_types sections"));
22116 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
22119 if (stat (objfile_name (objfile
), &st
) < 0)
22120 perror_with_name (objfile_name (objfile
));
22122 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile_name (objfile
)),
22123 INDEX_SUFFIX
, (char *) NULL
);
22124 cleanup
= make_cleanup (xfree
, filename
);
22126 out_file
= gdb_fopen_cloexec (filename
, "wb");
22128 error (_("Can't open `%s' for writing"), filename
);
22130 cleanup_filename
= filename
;
22131 make_cleanup (unlink_if_set
, &cleanup_filename
);
22133 symtab
= create_mapped_symtab ();
22134 make_cleanup (cleanup_mapped_symtab
, symtab
);
22136 obstack_init (&addr_obstack
);
22137 make_cleanup_obstack_free (&addr_obstack
);
22139 obstack_init (&cu_list
);
22140 make_cleanup_obstack_free (&cu_list
);
22142 obstack_init (&types_cu_list
);
22143 make_cleanup_obstack_free (&types_cu_list
);
22145 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
22146 NULL
, xcalloc
, xfree
);
22147 make_cleanup_htab_delete (psyms_seen
);
22149 /* While we're scanning CU's create a table that maps a psymtab pointer
22150 (which is what addrmap records) to its index (which is what is recorded
22151 in the index file). This will later be needed to write the address
22153 cu_index_htab
= htab_create_alloc (100,
22154 hash_psymtab_cu_index
,
22155 eq_psymtab_cu_index
,
22156 NULL
, xcalloc
, xfree
);
22157 make_cleanup_htab_delete (cu_index_htab
);
22158 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
22159 xmalloc (sizeof (struct psymtab_cu_index_map
)
22160 * dwarf2_per_objfile
->n_comp_units
);
22161 make_cleanup (xfree
, psymtab_cu_index_map
);
22163 /* The CU list is already sorted, so we don't need to do additional
22164 work here. Also, the debug_types entries do not appear in
22165 all_comp_units, but only in their own hash table. */
22166 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
22168 struct dwarf2_per_cu_data
*per_cu
22169 = dwarf2_per_objfile
->all_comp_units
[i
];
22170 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
22172 struct psymtab_cu_index_map
*map
;
22175 /* CU of a shared file from 'dwz -m' may be unused by this main file.
22176 It may be referenced from a local scope but in such case it does not
22177 need to be present in .gdb_index. */
22178 if (psymtab
== NULL
)
22181 if (psymtab
->user
== NULL
)
22182 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
22184 map
= &psymtab_cu_index_map
[i
];
22185 map
->psymtab
= psymtab
;
22187 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
22188 gdb_assert (slot
!= NULL
);
22189 gdb_assert (*slot
== NULL
);
22192 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
22193 per_cu
->offset
.sect_off
);
22194 obstack_grow (&cu_list
, val
, 8);
22195 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
22196 obstack_grow (&cu_list
, val
, 8);
22199 /* Dump the address map. */
22200 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
22202 /* Write out the .debug_type entries, if any. */
22203 if (dwarf2_per_objfile
->signatured_types
)
22205 struct signatured_type_index_data sig_data
;
22207 sig_data
.objfile
= objfile
;
22208 sig_data
.symtab
= symtab
;
22209 sig_data
.types_list
= &types_cu_list
;
22210 sig_data
.psyms_seen
= psyms_seen
;
22211 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
22212 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
22213 write_one_signatured_type
, &sig_data
);
22216 /* Now that we've processed all symbols we can shrink their cu_indices
22218 uniquify_cu_indices (symtab
);
22220 obstack_init (&constant_pool
);
22221 make_cleanup_obstack_free (&constant_pool
);
22222 obstack_init (&symtab_obstack
);
22223 make_cleanup_obstack_free (&symtab_obstack
);
22224 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
22226 obstack_init (&contents
);
22227 make_cleanup_obstack_free (&contents
);
22228 size_of_contents
= 6 * sizeof (offset_type
);
22229 total_len
= size_of_contents
;
22231 /* The version number. */
22232 val
= MAYBE_SWAP (8);
22233 obstack_grow (&contents
, &val
, sizeof (val
));
22235 /* The offset of the CU list from the start of the file. */
22236 val
= MAYBE_SWAP (total_len
);
22237 obstack_grow (&contents
, &val
, sizeof (val
));
22238 total_len
+= obstack_object_size (&cu_list
);
22240 /* The offset of the types CU list from the start of the file. */
22241 val
= MAYBE_SWAP (total_len
);
22242 obstack_grow (&contents
, &val
, sizeof (val
));
22243 total_len
+= obstack_object_size (&types_cu_list
);
22245 /* The offset of the address table from the start of the file. */
22246 val
= MAYBE_SWAP (total_len
);
22247 obstack_grow (&contents
, &val
, sizeof (val
));
22248 total_len
+= obstack_object_size (&addr_obstack
);
22250 /* The offset of the symbol table from the start of the file. */
22251 val
= MAYBE_SWAP (total_len
);
22252 obstack_grow (&contents
, &val
, sizeof (val
));
22253 total_len
+= obstack_object_size (&symtab_obstack
);
22255 /* The offset of the constant pool from the start of the file. */
22256 val
= MAYBE_SWAP (total_len
);
22257 obstack_grow (&contents
, &val
, sizeof (val
));
22258 total_len
+= obstack_object_size (&constant_pool
);
22260 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
22262 write_obstack (out_file
, &contents
);
22263 write_obstack (out_file
, &cu_list
);
22264 write_obstack (out_file
, &types_cu_list
);
22265 write_obstack (out_file
, &addr_obstack
);
22266 write_obstack (out_file
, &symtab_obstack
);
22267 write_obstack (out_file
, &constant_pool
);
22271 /* We want to keep the file, so we set cleanup_filename to NULL
22272 here. See unlink_if_set. */
22273 cleanup_filename
= NULL
;
22275 do_cleanups (cleanup
);
22278 /* Implementation of the `save gdb-index' command.
22280 Note that the file format used by this command is documented in the
22281 GDB manual. Any changes here must be documented there. */
22284 save_gdb_index_command (char *arg
, int from_tty
)
22286 struct objfile
*objfile
;
22289 error (_("usage: save gdb-index DIRECTORY"));
22291 ALL_OBJFILES (objfile
)
22295 /* If the objfile does not correspond to an actual file, skip it. */
22296 if (stat (objfile_name (objfile
), &st
) < 0)
22299 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
22300 if (dwarf2_per_objfile
)
22302 volatile struct gdb_exception except
;
22304 TRY_CATCH (except
, RETURN_MASK_ERROR
)
22306 write_psymtabs_to_index (objfile
, arg
);
22308 if (except
.reason
< 0)
22309 exception_fprintf (gdb_stderr
, except
,
22310 _("Error while writing index for `%s': "),
22311 objfile_name (objfile
));
22318 int dwarf2_always_disassemble
;
22321 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
22322 struct cmd_list_element
*c
, const char *value
)
22324 fprintf_filtered (file
,
22325 _("Whether to always disassemble "
22326 "DWARF expressions is %s.\n"),
22331 show_check_physname (struct ui_file
*file
, int from_tty
,
22332 struct cmd_list_element
*c
, const char *value
)
22334 fprintf_filtered (file
,
22335 _("Whether to check \"physname\" is %s.\n"),
22339 void _initialize_dwarf2_read (void);
22342 _initialize_dwarf2_read (void)
22344 struct cmd_list_element
*c
;
22346 dwarf2_objfile_data_key
22347 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
22349 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
22350 Set DWARF 2 specific variables.\n\
22351 Configure DWARF 2 variables such as the cache size"),
22352 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
22353 0/*allow-unknown*/, &maintenance_set_cmdlist
);
22355 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
22356 Show DWARF 2 specific variables\n\
22357 Show DWARF 2 variables such as the cache size"),
22358 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
22359 0/*allow-unknown*/, &maintenance_show_cmdlist
);
22361 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
22362 &dwarf2_max_cache_age
, _("\
22363 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
22364 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
22365 A higher limit means that cached compilation units will be stored\n\
22366 in memory longer, and more total memory will be used. Zero disables\n\
22367 caching, which can slow down startup."),
22369 show_dwarf2_max_cache_age
,
22370 &set_dwarf2_cmdlist
,
22371 &show_dwarf2_cmdlist
);
22373 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
22374 &dwarf2_always_disassemble
, _("\
22375 Set whether `info address' always disassembles DWARF expressions."), _("\
22376 Show whether `info address' always disassembles DWARF expressions."), _("\
22377 When enabled, DWARF expressions are always printed in an assembly-like\n\
22378 syntax. When disabled, expressions will be printed in a more\n\
22379 conversational style, when possible."),
22381 show_dwarf2_always_disassemble
,
22382 &set_dwarf2_cmdlist
,
22383 &show_dwarf2_cmdlist
);
22385 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
22386 Set debugging of the dwarf2 reader."), _("\
22387 Show debugging of the dwarf2 reader."), _("\
22388 When enabled, debugging messages are printed during dwarf2 reading\n\
22389 and symtab expansion."),
22392 &setdebuglist
, &showdebuglist
);
22394 add_setshow_zuinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
22395 Set debugging of the dwarf2 DIE reader."), _("\
22396 Show debugging of the dwarf2 DIE reader."), _("\
22397 When enabled (non-zero), DIEs are dumped after they are read in.\n\
22398 The value is the maximum depth to print."),
22401 &setdebuglist
, &showdebuglist
);
22403 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
22404 Set cross-checking of \"physname\" code against demangler."), _("\
22405 Show cross-checking of \"physname\" code against demangler."), _("\
22406 When enabled, GDB's internal \"physname\" code is checked against\n\
22408 NULL
, show_check_physname
,
22409 &setdebuglist
, &showdebuglist
);
22411 add_setshow_boolean_cmd ("use-deprecated-index-sections",
22412 no_class
, &use_deprecated_index_sections
, _("\
22413 Set whether to use deprecated gdb_index sections."), _("\
22414 Show whether to use deprecated gdb_index sections."), _("\
22415 When enabled, deprecated .gdb_index sections are used anyway.\n\
22416 Normally they are ignored either because of a missing feature or\n\
22417 performance issue.\n\
22418 Warning: This option must be enabled before gdb reads the file."),
22421 &setlist
, &showlist
);
22423 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
22425 Save a gdb-index file.\n\
22426 Usage: save gdb-index DIRECTORY"),
22428 set_cmd_completer (c
, filename_completer
);
22430 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
22431 &dwarf2_locexpr_funcs
);
22432 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
22433 &dwarf2_loclist_funcs
);
22435 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
22436 &dwarf2_block_frame_base_locexpr_funcs
);
22437 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
22438 &dwarf2_block_frame_base_loclist_funcs
);