1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2012 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. */
39 #include "gdb-demangle.h"
40 #include "expression.h"
41 #include "filenames.h" /* for DOSish file names */
44 #include "complaints.h"
46 #include "dwarf2expr.h"
47 #include "dwarf2loc.h"
48 #include "cp-support.h"
54 #include "typeprint.h"
57 #include "exceptions.h"
59 #include "completer.h"
64 #include "gdbcore.h" /* for gnutarget */
68 #include "gdb_string.h"
69 #include "gdb_assert.h"
70 #include <sys/types.h>
77 #define MAP_FAILED ((void *) -1)
81 typedef struct symbol
*symbolp
;
84 /* When non-zero, dump DIEs after they are read in. */
85 static int dwarf2_die_debug
= 0;
87 /* When non-zero, cross-check physname against demangler. */
88 static int check_physname
= 0;
90 /* When non-zero, do not reject deprecated .gdb_index sections. */
91 int use_deprecated_index_sections
= 0;
95 /* When set, the file that we're processing is known to have debugging
96 info for C++ namespaces. GCC 3.3.x did not produce this information,
97 but later versions do. */
99 static int processing_has_namespace_info
;
101 static const struct objfile_data
*dwarf2_objfile_data_key
;
103 struct dwarf2_section_info
108 /* Not NULL if the section was actually mmapped. */
110 /* Page aligned size of mmapped area. */
111 bfd_size_type map_len
;
112 /* True if we have tried to read this section. */
116 typedef struct dwarf2_section_info dwarf2_section_info_def
;
117 DEF_VEC_O (dwarf2_section_info_def
);
119 /* All offsets in the index are of this type. It must be
120 architecture-independent. */
121 typedef uint32_t offset_type
;
123 DEF_VEC_I (offset_type
);
125 /* A description of the mapped index. The file format is described in
126 a comment by the code that writes the index. */
129 /* Index data format version. */
132 /* The total length of the buffer. */
135 /* A pointer to the address table data. */
136 const gdb_byte
*address_table
;
138 /* Size of the address table data in bytes. */
139 offset_type address_table_size
;
141 /* The symbol table, implemented as a hash table. */
142 const offset_type
*symbol_table
;
144 /* Size in slots, each slot is 2 offset_types. */
145 offset_type symbol_table_slots
;
147 /* A pointer to the constant pool. */
148 const char *constant_pool
;
151 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
152 DEF_VEC_P (dwarf2_per_cu_ptr
);
154 /* Collection of data recorded per objfile.
155 This hangs off of dwarf2_objfile_data_key. */
157 struct dwarf2_per_objfile
159 struct dwarf2_section_info info
;
160 struct dwarf2_section_info abbrev
;
161 struct dwarf2_section_info line
;
162 struct dwarf2_section_info loc
;
163 struct dwarf2_section_info macinfo
;
164 struct dwarf2_section_info macro
;
165 struct dwarf2_section_info str
;
166 struct dwarf2_section_info ranges
;
167 struct dwarf2_section_info addr
;
168 struct dwarf2_section_info frame
;
169 struct dwarf2_section_info eh_frame
;
170 struct dwarf2_section_info gdb_index
;
172 VEC (dwarf2_section_info_def
) *types
;
175 struct objfile
*objfile
;
177 /* Table of all the compilation units. This is used to locate
178 the target compilation unit of a particular reference. */
179 struct dwarf2_per_cu_data
**all_comp_units
;
181 /* The number of compilation units in ALL_COMP_UNITS. */
184 /* The number of .debug_types-related CUs. */
187 /* The .debug_types-related CUs (TUs). */
188 struct dwarf2_per_cu_data
**all_type_units
;
190 /* A chain of compilation units that are currently read in, so that
191 they can be freed later. */
192 struct dwarf2_per_cu_data
*read_in_chain
;
194 /* A table mapping .debug_types signatures to its signatured_type entry.
195 This is NULL if the .debug_types section hasn't been read in yet. */
196 htab_t signatured_types
;
198 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
199 This is NULL if the table hasn't been allocated yet. */
202 /* A flag indicating wether this objfile has a section loaded at a
204 int has_section_at_zero
;
206 /* True if we are using the mapped index,
207 or we are faking it for OBJF_READNOW's sake. */
208 unsigned char using_index
;
210 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
211 struct mapped_index
*index_table
;
213 /* When using index_table, this keeps track of all quick_file_names entries.
214 TUs can share line table entries with CUs or other TUs, and there can be
215 a lot more TUs than unique line tables, so we maintain a separate table
216 of all line table entries to support the sharing. */
217 htab_t quick_file_names_table
;
219 /* Set during partial symbol reading, to prevent queueing of full
221 int reading_partial_symbols
;
223 /* Table mapping type DIEs to their struct type *.
224 This is NULL if not allocated yet.
225 The mapping is done via (CU/TU signature + DIE offset) -> type. */
226 htab_t die_type_hash
;
228 /* The CUs we recently read. */
229 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
232 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
234 /* Default names of the debugging sections. */
236 /* Note that if the debugging section has been compressed, it might
237 have a name like .zdebug_info. */
239 static const struct dwarf2_debug_sections dwarf2_elf_names
=
241 { ".debug_info", ".zdebug_info" },
242 { ".debug_abbrev", ".zdebug_abbrev" },
243 { ".debug_line", ".zdebug_line" },
244 { ".debug_loc", ".zdebug_loc" },
245 { ".debug_macinfo", ".zdebug_macinfo" },
246 { ".debug_macro", ".zdebug_macro" },
247 { ".debug_str", ".zdebug_str" },
248 { ".debug_ranges", ".zdebug_ranges" },
249 { ".debug_types", ".zdebug_types" },
250 { ".debug_addr", ".zdebug_addr" },
251 { ".debug_frame", ".zdebug_frame" },
252 { ".eh_frame", NULL
},
253 { ".gdb_index", ".zgdb_index" },
257 /* List of DWO sections. */
259 static const struct dwo_section_names
261 struct dwarf2_section_names abbrev_dwo
;
262 struct dwarf2_section_names info_dwo
;
263 struct dwarf2_section_names line_dwo
;
264 struct dwarf2_section_names loc_dwo
;
265 struct dwarf2_section_names str_dwo
;
266 struct dwarf2_section_names str_offsets_dwo
;
267 struct dwarf2_section_names types_dwo
;
271 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
272 { ".debug_info.dwo", ".zdebug_info.dwo" },
273 { ".debug_line.dwo", ".zdebug_line.dwo" },
274 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
275 { ".debug_str.dwo", ".zdebug_str.dwo" },
276 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
277 { ".debug_types.dwo", ".zdebug_types.dwo" },
280 /* local data types */
282 /* We hold several abbreviation tables in memory at the same time. */
283 #ifndef ABBREV_HASH_SIZE
284 #define ABBREV_HASH_SIZE 121
287 /* The data in a compilation unit header, after target2host
288 translation, looks like this. */
289 struct comp_unit_head
293 unsigned char addr_size
;
294 unsigned char signed_addr_p
;
295 sect_offset abbrev_offset
;
297 /* Size of file offsets; either 4 or 8. */
298 unsigned int offset_size
;
300 /* Size of the length field; either 4 or 12. */
301 unsigned int initial_length_size
;
303 /* Offset to the first byte of this compilation unit header in the
304 .debug_info section, for resolving relative reference dies. */
307 /* Offset to first die in this cu from the start of the cu.
308 This will be the first byte following the compilation unit header. */
309 cu_offset first_die_offset
;
312 /* Type used for delaying computation of method physnames.
313 See comments for compute_delayed_physnames. */
314 struct delayed_method_info
316 /* The type to which the method is attached, i.e., its parent class. */
319 /* The index of the method in the type's function fieldlists. */
322 /* The index of the method in the fieldlist. */
325 /* The name of the DIE. */
328 /* The DIE associated with this method. */
329 struct die_info
*die
;
332 typedef struct delayed_method_info delayed_method_info
;
333 DEF_VEC_O (delayed_method_info
);
335 /* Internal state when decoding a particular compilation unit. */
338 /* The objfile containing this compilation unit. */
339 struct objfile
*objfile
;
341 /* The header of the compilation unit. */
342 struct comp_unit_head header
;
344 /* Base address of this compilation unit. */
345 CORE_ADDR base_address
;
347 /* Non-zero if base_address has been set. */
350 /* The language we are debugging. */
351 enum language language
;
352 const struct language_defn
*language_defn
;
354 const char *producer
;
356 /* The generic symbol table building routines have separate lists for
357 file scope symbols and all all other scopes (local scopes). So
358 we need to select the right one to pass to add_symbol_to_list().
359 We do it by keeping a pointer to the correct list in list_in_scope.
361 FIXME: The original dwarf code just treated the file scope as the
362 first local scope, and all other local scopes as nested local
363 scopes, and worked fine. Check to see if we really need to
364 distinguish these in buildsym.c. */
365 struct pending
**list_in_scope
;
367 /* DWARF abbreviation table associated with this compilation unit. */
368 struct abbrev_info
**dwarf2_abbrevs
;
370 /* Storage for the abbrev table. */
371 struct obstack abbrev_obstack
;
373 /* Hash table holding all the loaded partial DIEs
374 with partial_die->offset.SECT_OFF as hash. */
377 /* Storage for things with the same lifetime as this read-in compilation
378 unit, including partial DIEs. */
379 struct obstack comp_unit_obstack
;
381 /* When multiple dwarf2_cu structures are living in memory, this field
382 chains them all together, so that they can be released efficiently.
383 We will probably also want a generation counter so that most-recently-used
384 compilation units are cached... */
385 struct dwarf2_per_cu_data
*read_in_chain
;
387 /* Backchain to our per_cu entry if the tree has been built. */
388 struct dwarf2_per_cu_data
*per_cu
;
390 /* How many compilation units ago was this CU last referenced? */
393 /* A hash table of DIE cu_offset for following references with
394 die_info->offset.sect_off as hash. */
397 /* Full DIEs if read in. */
398 struct die_info
*dies
;
400 /* A set of pointers to dwarf2_per_cu_data objects for compilation
401 units referenced by this one. Only set during full symbol processing;
402 partial symbol tables do not have dependencies. */
405 /* Header data from the line table, during full symbol processing. */
406 struct line_header
*line_header
;
408 /* A list of methods which need to have physnames computed
409 after all type information has been read. */
410 VEC (delayed_method_info
) *method_list
;
412 /* To be copied to symtab->call_site_htab. */
413 htab_t call_site_htab
;
415 /* Non-NULL if this CU came from a DWO file. */
416 struct dwo_unit
*dwo_unit
;
418 /* The DW_AT_addr_base attribute if present, zero otherwise
419 (zero is a valid value though).
420 Note this value comes from the stub CU/TU's DIE. */
423 /* Mark used when releasing cached dies. */
424 unsigned int mark
: 1;
426 /* This CU references .debug_loc. See the symtab->locations_valid field.
427 This test is imperfect as there may exist optimized debug code not using
428 any location list and still facing inlining issues if handled as
429 unoptimized code. For a future better test see GCC PR other/32998. */
430 unsigned int has_loclist
: 1;
432 /* These cache the results of producer_is_gxx_lt_4_6.
433 CHECKED_PRODUCER is set if PRODUCER_IS_GXX_LT_4_6 is valid. This
434 information is cached because profiling CU expansion showed
435 excessive time spent in producer_is_gxx_lt_4_6. */
436 unsigned int checked_producer
: 1;
437 unsigned int producer_is_gxx_lt_4_6
: 1;
439 /* Non-zero if DW_AT_addr_base was found.
440 Used when processing DWO files. */
441 unsigned int have_addr_base
: 1;
444 /* Persistent data held for a compilation unit, even when not
445 processing it. We put a pointer to this structure in the
446 read_symtab_private field of the psymtab. */
448 struct dwarf2_per_cu_data
450 /* The start offset and length of this compilation unit. 2**29-1
451 bytes should suffice to store the length of any compilation unit
452 - if it doesn't, GDB will fall over anyway.
453 NOTE: Unlike comp_unit_head.length, this length includes
455 If the DIE refers to a DWO file, this is always of the original die,
458 unsigned int length
: 29;
460 /* Flag indicating this compilation unit will be read in before
461 any of the current compilation units are processed. */
462 unsigned int queued
: 1;
464 /* This flag will be set when reading partial DIEs if we need to load
465 absolutely all DIEs for this compilation unit, instead of just the ones
466 we think are interesting. It gets set if we look for a DIE in the
467 hash table and don't find it. */
468 unsigned int load_all_dies
: 1;
470 /* Non-zero if this CU is from .debug_types. */
471 unsigned int is_debug_types
: 1;
473 /* The section this CU/TU lives in.
474 If the DIE refers to a DWO file, this is always the original die,
476 struct dwarf2_section_info
*info_or_types_section
;
478 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
479 of the CU cache it gets reset to NULL again. */
480 struct dwarf2_cu
*cu
;
482 /* The corresponding objfile.
483 Normally we can get the objfile from dwarf2_per_objfile.
484 However we can enter this file with just a "per_cu" handle. */
485 struct objfile
*objfile
;
487 /* When using partial symbol tables, the 'psymtab' field is active.
488 Otherwise the 'quick' field is active. */
491 /* The partial symbol table associated with this compilation unit,
492 or NULL for unread partial units. */
493 struct partial_symtab
*psymtab
;
495 /* Data needed by the "quick" functions. */
496 struct dwarf2_per_cu_quick_data
*quick
;
499 /* The CUs we import using DW_TAG_imported_unit. This is filled in
500 while reading psymtabs, used to compute the psymtab dependencies,
501 and then cleared. Then it is filled in again while reading full
502 symbols, and only deleted when the objfile is destroyed. */
503 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
506 /* Entry in the signatured_types hash table. */
508 struct signatured_type
510 /* The type's signature. */
513 /* Offset in the TU of the type's DIE, as read from the TU header.
514 If the definition lives in a DWO file, this value is unusable. */
515 cu_offset type_offset_in_tu
;
517 /* Offset in the section of the type's DIE.
518 If the definition lives in a DWO file, this is the offset in the
519 .debug_types.dwo section.
520 The value is zero until the actual value is known.
521 Zero is otherwise not a valid section offset. */
522 sect_offset type_offset_in_section
;
524 /* The CU(/TU) of this type. */
525 struct dwarf2_per_cu_data per_cu
;
528 /* These sections are what may appear in a "dwo" file. */
532 struct dwarf2_section_info abbrev
;
533 struct dwarf2_section_info info
;
534 struct dwarf2_section_info line
;
535 struct dwarf2_section_info loc
;
536 struct dwarf2_section_info str
;
537 struct dwarf2_section_info str_offsets
;
538 VEC (dwarf2_section_info_def
) *types
;
541 /* Common bits of DWO CUs/TUs. */
545 /* Backlink to the containing struct dwo_file. */
546 struct dwo_file
*dwo_file
;
548 /* The "id" that distinguishes this CU/TU.
549 .debug_info calls this "dwo_id", .debug_types calls this "signature".
550 Since signatures came first, we stick with it for consistency. */
553 /* The section this CU/TU lives in, in the DWO file. */
554 struct dwarf2_section_info
*info_or_types_section
;
556 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
560 /* For types, offset in the type's DIE of the type defined by this TU. */
561 cu_offset type_offset_in_tu
;
564 /* Data for one DWO file. */
568 /* The DW_AT_GNU_dwo_name attribute.
569 We don't manage space for this, it's an attribute. */
570 const char *dwo_name
;
572 /* The bfd, when the file is open. Otherwise this is NULL. */
575 /* Section info for this file. */
576 struct dwo_sections sections
;
578 /* Table of CUs in the file.
579 Each element is a struct dwo_unit. */
582 /* Table of TUs in the file.
583 Each element is a struct dwo_unit. */
587 /* Struct used to pass misc. parameters to read_die_and_children, et
588 al. which are used for both .debug_info and .debug_types dies.
589 All parameters here are unchanging for the life of the call. This
590 struct exists to abstract away the constant parameters of die reading. */
592 struct die_reader_specs
594 /* die_section->asection->owner. */
597 /* The CU of the DIE we are parsing. */
598 struct dwarf2_cu
*cu
;
600 /* Non-NULL if reading a DWO file. */
601 struct dwo_file
*dwo_file
;
603 /* The section the die comes from.
604 This is either .debug_info or .debug_types, or the .dwo variants. */
605 struct dwarf2_section_info
*die_section
;
607 /* die_section->buffer. */
611 /* Type of function passed to init_cutu_and_read_dies, et.al. */
612 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
614 struct die_info
*comp_unit_die
,
618 /* The line number information for a compilation unit (found in the
619 .debug_line section) begins with a "statement program header",
620 which contains the following information. */
623 unsigned int total_length
;
624 unsigned short version
;
625 unsigned int header_length
;
626 unsigned char minimum_instruction_length
;
627 unsigned char maximum_ops_per_instruction
;
628 unsigned char default_is_stmt
;
630 unsigned char line_range
;
631 unsigned char opcode_base
;
633 /* standard_opcode_lengths[i] is the number of operands for the
634 standard opcode whose value is i. This means that
635 standard_opcode_lengths[0] is unused, and the last meaningful
636 element is standard_opcode_lengths[opcode_base - 1]. */
637 unsigned char *standard_opcode_lengths
;
639 /* The include_directories table. NOTE! These strings are not
640 allocated with xmalloc; instead, they are pointers into
641 debug_line_buffer. If you try to free them, `free' will get
643 unsigned int num_include_dirs
, include_dirs_size
;
646 /* The file_names table. NOTE! These strings are not allocated
647 with xmalloc; instead, they are pointers into debug_line_buffer.
648 Don't try to free them directly. */
649 unsigned int num_file_names
, file_names_size
;
653 unsigned int dir_index
;
654 unsigned int mod_time
;
656 int included_p
; /* Non-zero if referenced by the Line Number Program. */
657 struct symtab
*symtab
; /* The associated symbol table, if any. */
660 /* The start and end of the statement program following this
661 header. These point into dwarf2_per_objfile->line_buffer. */
662 gdb_byte
*statement_program_start
, *statement_program_end
;
665 /* When we construct a partial symbol table entry we only
666 need this much information. */
667 struct partial_die_info
669 /* Offset of this DIE. */
672 /* DWARF-2 tag for this DIE. */
673 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
675 /* Assorted flags describing the data found in this DIE. */
676 unsigned int has_children
: 1;
677 unsigned int is_external
: 1;
678 unsigned int is_declaration
: 1;
679 unsigned int has_type
: 1;
680 unsigned int has_specification
: 1;
681 unsigned int has_pc_info
: 1;
682 unsigned int may_be_inlined
: 1;
684 /* Flag set if the SCOPE field of this structure has been
686 unsigned int scope_set
: 1;
688 /* Flag set if the DIE has a byte_size attribute. */
689 unsigned int has_byte_size
: 1;
691 /* Flag set if any of the DIE's children are template arguments. */
692 unsigned int has_template_arguments
: 1;
694 /* Flag set if fixup_partial_die has been called on this die. */
695 unsigned int fixup_called
: 1;
697 /* The name of this DIE. Normally the value of DW_AT_name, but
698 sometimes a default name for unnamed DIEs. */
701 /* The linkage name, if present. */
702 const char *linkage_name
;
704 /* The scope to prepend to our children. This is generally
705 allocated on the comp_unit_obstack, so will disappear
706 when this compilation unit leaves the cache. */
709 /* Some data associated with the partial DIE. The tag determines
710 which field is live. */
713 /* The location description associated with this DIE, if any. */
714 struct dwarf_block
*locdesc
;
715 /* The offset of an import, for DW_TAG_imported_unit. */
719 /* If HAS_PC_INFO, the PC range associated with this DIE. */
723 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
724 DW_AT_sibling, if any. */
725 /* NOTE: This member isn't strictly necessary, read_partial_die could
726 return DW_AT_sibling values to its caller load_partial_dies. */
729 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
730 DW_AT_specification (or DW_AT_abstract_origin or
732 sect_offset spec_offset
;
734 /* Pointers to this DIE's parent, first child, and next sibling,
736 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
739 /* This data structure holds the information of an abbrev. */
742 unsigned int number
; /* number identifying abbrev */
743 enum dwarf_tag tag
; /* dwarf tag */
744 unsigned short has_children
; /* boolean */
745 unsigned short num_attrs
; /* number of attributes */
746 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
747 struct abbrev_info
*next
; /* next in chain */
752 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
753 ENUM_BITFIELD(dwarf_form
) form
: 16;
756 /* Attributes have a name and a value. */
759 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
760 ENUM_BITFIELD(dwarf_form
) form
: 15;
762 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
763 field should be in u.str (existing only for DW_STRING) but it is kept
764 here for better struct attribute alignment. */
765 unsigned int string_is_canonical
: 1;
770 struct dwarf_block
*blk
;
774 struct signatured_type
*signatured_type
;
779 /* This data structure holds a complete die structure. */
782 /* DWARF-2 tag for this DIE. */
783 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
785 /* Number of attributes */
786 unsigned char num_attrs
;
788 /* True if we're presently building the full type name for the
789 type derived from this DIE. */
790 unsigned char building_fullname
: 1;
795 /* Offset in .debug_info or .debug_types section. */
798 /* The dies in a compilation unit form an n-ary tree. PARENT
799 points to this die's parent; CHILD points to the first child of
800 this node; and all the children of a given node are chained
801 together via their SIBLING fields. */
802 struct die_info
*child
; /* Its first child, if any. */
803 struct die_info
*sibling
; /* Its next sibling, if any. */
804 struct die_info
*parent
; /* Its parent, if any. */
806 /* An array of attributes, with NUM_ATTRS elements. There may be
807 zero, but it's not common and zero-sized arrays are not
808 sufficiently portable C. */
809 struct attribute attrs
[1];
812 /* Get at parts of an attribute structure. */
814 #define DW_STRING(attr) ((attr)->u.str)
815 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
816 #define DW_UNSND(attr) ((attr)->u.unsnd)
817 #define DW_BLOCK(attr) ((attr)->u.blk)
818 #define DW_SND(attr) ((attr)->u.snd)
819 #define DW_ADDR(attr) ((attr)->u.addr)
820 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
822 /* Blocks are a bunch of untyped bytes. */
827 /* Valid only if SIZE is not zero. */
831 #ifndef ATTR_ALLOC_CHUNK
832 #define ATTR_ALLOC_CHUNK 4
835 /* Allocate fields for structs, unions and enums in this size. */
836 #ifndef DW_FIELD_ALLOC_CHUNK
837 #define DW_FIELD_ALLOC_CHUNK 4
840 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
841 but this would require a corresponding change in unpack_field_as_long
843 static int bits_per_byte
= 8;
845 /* The routines that read and process dies for a C struct or C++ class
846 pass lists of data member fields and lists of member function fields
847 in an instance of a field_info structure, as defined below. */
850 /* List of data member and baseclasses fields. */
853 struct nextfield
*next
;
858 *fields
, *baseclasses
;
860 /* Number of fields (including baseclasses). */
863 /* Number of baseclasses. */
866 /* Set if the accesibility of one of the fields is not public. */
867 int non_public_fields
;
869 /* Member function fields array, entries are allocated in the order they
870 are encountered in the object file. */
873 struct nextfnfield
*next
;
874 struct fn_field fnfield
;
878 /* Member function fieldlist array, contains name of possibly overloaded
879 member function, number of overloaded member functions and a pointer
880 to the head of the member function field chain. */
885 struct nextfnfield
*head
;
889 /* Number of entries in the fnfieldlists array. */
892 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
893 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
894 struct typedef_field_list
896 struct typedef_field field
;
897 struct typedef_field_list
*next
;
900 unsigned typedef_field_list_count
;
903 /* One item on the queue of compilation units to read in full symbols
905 struct dwarf2_queue_item
907 struct dwarf2_per_cu_data
*per_cu
;
908 enum language pretend_language
;
909 struct dwarf2_queue_item
*next
;
912 /* The current queue. */
913 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
915 /* Loaded secondary compilation units are kept in memory until they
916 have not been referenced for the processing of this many
917 compilation units. Set this to zero to disable caching. Cache
918 sizes of up to at least twenty will improve startup time for
919 typical inter-CU-reference binaries, at an obvious memory cost. */
920 static int dwarf2_max_cache_age
= 5;
922 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
923 struct cmd_list_element
*c
, const char *value
)
925 fprintf_filtered (file
, _("The upper bound on the age of cached "
926 "dwarf2 compilation units is %s.\n"),
931 /* Various complaints about symbol reading that don't abort the process. */
934 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
936 complaint (&symfile_complaints
,
937 _("statement list doesn't fit in .debug_line section"));
941 dwarf2_debug_line_missing_file_complaint (void)
943 complaint (&symfile_complaints
,
944 _(".debug_line section has line data without a file"));
948 dwarf2_debug_line_missing_end_sequence_complaint (void)
950 complaint (&symfile_complaints
,
951 _(".debug_line section has line "
952 "program sequence without an end"));
956 dwarf2_complex_location_expr_complaint (void)
958 complaint (&symfile_complaints
, _("location expression too complex"));
962 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
965 complaint (&symfile_complaints
,
966 _("const value length mismatch for '%s', got %d, expected %d"),
971 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
973 complaint (&symfile_complaints
,
974 _("macro info runs off end of `%s' section"),
975 section
->asection
->name
);
979 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
981 complaint (&symfile_complaints
,
982 _("macro debug info contains a "
983 "malformed macro definition:\n`%s'"),
988 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
990 complaint (&symfile_complaints
,
991 _("invalid attribute class or form for '%s' in '%s'"),
995 /* local function prototypes */
997 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
999 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1002 static void dwarf2_find_base_address (struct die_info
*die
,
1003 struct dwarf2_cu
*cu
);
1005 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1007 static void scan_partial_symbols (struct partial_die_info
*,
1008 CORE_ADDR
*, CORE_ADDR
*,
1009 int, struct dwarf2_cu
*);
1011 static void add_partial_symbol (struct partial_die_info
*,
1012 struct dwarf2_cu
*);
1014 static void add_partial_namespace (struct partial_die_info
*pdi
,
1015 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1016 int need_pc
, struct dwarf2_cu
*cu
);
1018 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1019 CORE_ADDR
*highpc
, int need_pc
,
1020 struct dwarf2_cu
*cu
);
1022 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1023 struct dwarf2_cu
*cu
);
1025 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1026 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1027 int need_pc
, struct dwarf2_cu
*cu
);
1029 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1031 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1033 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1034 struct dwarf2_section_info
*);
1036 static void dwarf2_free_abbrev_table (void *);
1038 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1040 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
1041 struct dwarf2_cu
*);
1043 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
1044 struct dwarf2_cu
*);
1046 static struct partial_die_info
*load_partial_dies
1047 (const struct die_reader_specs
*, gdb_byte
*, int);
1049 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1050 struct partial_die_info
*,
1051 struct abbrev_info
*,
1055 static struct partial_die_info
*find_partial_die (sect_offset
,
1056 struct dwarf2_cu
*);
1058 static void fixup_partial_die (struct partial_die_info
*,
1059 struct dwarf2_cu
*);
1061 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1062 struct attribute
*, struct attr_abbrev
*,
1065 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1067 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1069 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1071 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1073 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1075 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1078 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1080 static LONGEST read_checked_initial_length_and_offset
1081 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1082 unsigned int *, unsigned int *);
1084 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1087 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1089 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1091 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1093 static char *read_indirect_string (bfd
*, gdb_byte
*,
1094 const struct comp_unit_head
*,
1097 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1099 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1101 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1104 static char *read_str_index (const struct die_reader_specs
*reader
,
1105 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1107 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
1109 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1111 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1112 struct dwarf2_cu
*);
1114 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1116 struct dwarf2_cu
*);
1118 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1119 struct dwarf2_cu
*cu
);
1121 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1123 static struct die_info
*die_specification (struct die_info
*die
,
1124 struct dwarf2_cu
**);
1126 static void free_line_header (struct line_header
*lh
);
1128 static void add_file_name (struct line_header
*, char *, unsigned int,
1129 unsigned int, unsigned int);
1131 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1132 struct dwarf2_cu
*cu
);
1134 static void dwarf_decode_lines (struct line_header
*, const char *,
1135 struct dwarf2_cu
*, struct partial_symtab
*,
1138 static void dwarf2_start_subfile (char *, const char *, const char *);
1140 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1141 struct dwarf2_cu
*);
1143 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1144 struct dwarf2_cu
*, struct symbol
*);
1146 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1147 struct dwarf2_cu
*);
1149 static void dwarf2_const_value_attr (struct attribute
*attr
,
1152 struct obstack
*obstack
,
1153 struct dwarf2_cu
*cu
, LONGEST
*value
,
1155 struct dwarf2_locexpr_baton
**baton
);
1157 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1159 static int need_gnat_info (struct dwarf2_cu
*);
1161 static struct type
*die_descriptive_type (struct die_info
*,
1162 struct dwarf2_cu
*);
1164 static void set_descriptive_type (struct type
*, struct die_info
*,
1165 struct dwarf2_cu
*);
1167 static struct type
*die_containing_type (struct die_info
*,
1168 struct dwarf2_cu
*);
1170 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1171 struct dwarf2_cu
*);
1173 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1175 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1177 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1179 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1180 const char *suffix
, int physname
,
1181 struct dwarf2_cu
*cu
);
1183 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1185 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1187 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1189 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1191 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1193 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1194 struct dwarf2_cu
*, struct partial_symtab
*);
1196 static int dwarf2_get_pc_bounds (struct die_info
*,
1197 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1198 struct partial_symtab
*);
1200 static void get_scope_pc_bounds (struct die_info
*,
1201 CORE_ADDR
*, CORE_ADDR
*,
1202 struct dwarf2_cu
*);
1204 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1205 CORE_ADDR
, struct dwarf2_cu
*);
1207 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1208 struct dwarf2_cu
*);
1210 static void dwarf2_attach_fields_to_type (struct field_info
*,
1211 struct type
*, struct dwarf2_cu
*);
1213 static void dwarf2_add_member_fn (struct field_info
*,
1214 struct die_info
*, struct type
*,
1215 struct dwarf2_cu
*);
1217 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1219 struct dwarf2_cu
*);
1221 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1223 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1225 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1227 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1229 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1231 static struct type
*read_module_type (struct die_info
*die
,
1232 struct dwarf2_cu
*cu
);
1234 static const char *namespace_name (struct die_info
*die
,
1235 int *is_anonymous
, struct dwarf2_cu
*);
1237 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1239 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1241 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1242 struct dwarf2_cu
*);
1244 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1246 gdb_byte
**new_info_ptr
,
1247 struct die_info
*parent
);
1249 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1251 gdb_byte
**new_info_ptr
,
1252 struct die_info
*parent
);
1254 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1255 struct die_info
**, gdb_byte
*, int *, int);
1257 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1258 struct die_info
**, gdb_byte
*, int *);
1260 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1262 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1265 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1267 static const char *dwarf2_full_name (char *name
,
1268 struct die_info
*die
,
1269 struct dwarf2_cu
*cu
);
1271 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1272 struct dwarf2_cu
**);
1274 static const char *dwarf_tag_name (unsigned int);
1276 static const char *dwarf_attr_name (unsigned int);
1278 static const char *dwarf_form_name (unsigned int);
1280 static char *dwarf_bool_name (unsigned int);
1282 static const char *dwarf_type_encoding_name (unsigned int);
1284 static struct die_info
*sibling_die (struct die_info
*);
1286 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1288 static void dump_die_for_error (struct die_info
*);
1290 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1293 /*static*/ void dump_die (struct die_info
*, int max_level
);
1295 static void store_in_ref_table (struct die_info
*,
1296 struct dwarf2_cu
*);
1298 static int is_ref_attr (struct attribute
*);
1300 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1302 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1304 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1306 struct dwarf2_cu
**);
1308 static struct die_info
*follow_die_ref (struct die_info
*,
1310 struct dwarf2_cu
**);
1312 static struct die_info
*follow_die_sig (struct die_info
*,
1314 struct dwarf2_cu
**);
1316 static struct signatured_type
*lookup_signatured_type_at_offset
1317 (struct objfile
*objfile
,
1318 struct dwarf2_section_info
*section
, sect_offset offset
);
1320 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1322 static void read_signatured_type (struct signatured_type
*);
1324 /* memory allocation interface */
1326 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1328 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1330 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1332 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1333 char *, bfd
*, struct dwarf2_cu
*,
1334 struct dwarf2_section_info
*,
1337 static int attr_form_is_block (struct attribute
*);
1339 static int attr_form_is_section_offset (struct attribute
*);
1341 static int attr_form_is_constant (struct attribute
*);
1343 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1344 struct dwarf2_loclist_baton
*baton
,
1345 struct attribute
*attr
);
1347 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1349 struct dwarf2_cu
*cu
);
1351 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1353 struct abbrev_info
*abbrev
);
1355 static void free_stack_comp_unit (void *);
1357 static hashval_t
partial_die_hash (const void *item
);
1359 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1361 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1362 (sect_offset offset
, struct objfile
*objfile
);
1364 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1365 struct dwarf2_per_cu_data
*per_cu
);
1367 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1368 struct die_info
*comp_unit_die
,
1369 enum language pretend_language
);
1371 static void free_heap_comp_unit (void *);
1373 static void free_cached_comp_units (void *);
1375 static void age_cached_comp_units (void);
1377 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1379 static struct type
*set_die_type (struct die_info
*, struct type
*,
1380 struct dwarf2_cu
*);
1382 static void create_all_comp_units (struct objfile
*);
1384 static int create_all_type_units (struct objfile
*);
1386 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1389 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1392 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1393 struct dwarf2_per_cu_data
*);
1395 static void dwarf2_mark (struct dwarf2_cu
*);
1397 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1399 static struct type
*get_die_type_at_offset (sect_offset
,
1400 struct dwarf2_per_cu_data
*per_cu
);
1402 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1404 static void dwarf2_release_queue (void *dummy
);
1406 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1407 enum language pretend_language
);
1409 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1410 struct dwarf2_per_cu_data
*per_cu
,
1411 enum language pretend_language
);
1413 static void process_queue (void);
1415 static void find_file_and_directory (struct die_info
*die
,
1416 struct dwarf2_cu
*cu
,
1417 char **name
, char **comp_dir
);
1419 static char *file_full_name (int file
, struct line_header
*lh
,
1420 const char *comp_dir
);
1422 static gdb_byte
*read_and_check_comp_unit_head
1423 (struct comp_unit_head
*header
,
1424 struct dwarf2_section_info
*section
, gdb_byte
*info_ptr
,
1425 int is_debug_types_section
);
1427 static void init_cutu_and_read_dies
1428 (struct dwarf2_per_cu_data
*this_cu
, int use_existing_cu
, int keep
,
1429 die_reader_func_ftype
*die_reader_func
, void *data
);
1431 static void init_cutu_and_read_dies_simple
1432 (struct dwarf2_per_cu_data
*this_cu
,
1433 die_reader_func_ftype
*die_reader_func
, void *data
);
1435 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1437 static void process_psymtab_comp_unit (struct dwarf2_per_cu_data
*, int);
1439 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1441 static struct dwo_unit
*lookup_dwo_comp_unit
1442 (struct dwarf2_per_cu_data
*, char *, const char *, ULONGEST
);
1444 static struct dwo_unit
*lookup_dwo_type_unit
1445 (struct signatured_type
*, char *, const char *);
1447 static void free_dwo_file_cleanup (void *);
1449 static void munmap_section_buffer (struct dwarf2_section_info
*);
1451 static void process_cu_includes (void);
1455 /* Convert VALUE between big- and little-endian. */
1457 byte_swap (offset_type value
)
1461 result
= (value
& 0xff) << 24;
1462 result
|= (value
& 0xff00) << 8;
1463 result
|= (value
& 0xff0000) >> 8;
1464 result
|= (value
& 0xff000000) >> 24;
1468 #define MAYBE_SWAP(V) byte_swap (V)
1471 #define MAYBE_SWAP(V) (V)
1472 #endif /* WORDS_BIGENDIAN */
1474 /* The suffix for an index file. */
1475 #define INDEX_SUFFIX ".gdb-index"
1477 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1478 struct dwarf2_cu
*cu
);
1480 /* Try to locate the sections we need for DWARF 2 debugging
1481 information and return true if we have enough to do something.
1482 NAMES points to the dwarf2 section names, or is NULL if the standard
1483 ELF names are used. */
1486 dwarf2_has_info (struct objfile
*objfile
,
1487 const struct dwarf2_debug_sections
*names
)
1489 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1490 if (!dwarf2_per_objfile
)
1492 /* Initialize per-objfile state. */
1493 struct dwarf2_per_objfile
*data
1494 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1496 memset (data
, 0, sizeof (*data
));
1497 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1498 dwarf2_per_objfile
= data
;
1500 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1502 dwarf2_per_objfile
->objfile
= objfile
;
1504 return (dwarf2_per_objfile
->info
.asection
!= NULL
1505 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1508 /* When loading sections, we look either for uncompressed section or for
1509 compressed section names. */
1512 section_is_p (const char *section_name
,
1513 const struct dwarf2_section_names
*names
)
1515 if (names
->normal
!= NULL
1516 && strcmp (section_name
, names
->normal
) == 0)
1518 if (names
->compressed
!= NULL
1519 && strcmp (section_name
, names
->compressed
) == 0)
1524 /* This function is mapped across the sections and remembers the
1525 offset and size of each of the debugging sections we are interested
1529 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1531 const struct dwarf2_debug_sections
*names
;
1534 names
= &dwarf2_elf_names
;
1536 names
= (const struct dwarf2_debug_sections
*) vnames
;
1538 if (section_is_p (sectp
->name
, &names
->info
))
1540 dwarf2_per_objfile
->info
.asection
= sectp
;
1541 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1543 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1545 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1546 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1548 else if (section_is_p (sectp
->name
, &names
->line
))
1550 dwarf2_per_objfile
->line
.asection
= sectp
;
1551 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1553 else if (section_is_p (sectp
->name
, &names
->loc
))
1555 dwarf2_per_objfile
->loc
.asection
= sectp
;
1556 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1558 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1560 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1561 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1563 else if (section_is_p (sectp
->name
, &names
->macro
))
1565 dwarf2_per_objfile
->macro
.asection
= sectp
;
1566 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1568 else if (section_is_p (sectp
->name
, &names
->str
))
1570 dwarf2_per_objfile
->str
.asection
= sectp
;
1571 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1573 else if (section_is_p (sectp
->name
, &names
->addr
))
1575 dwarf2_per_objfile
->addr
.asection
= sectp
;
1576 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1578 else if (section_is_p (sectp
->name
, &names
->frame
))
1580 dwarf2_per_objfile
->frame
.asection
= sectp
;
1581 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1583 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1585 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1587 if (aflag
& SEC_HAS_CONTENTS
)
1589 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1590 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1593 else if (section_is_p (sectp
->name
, &names
->ranges
))
1595 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1596 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1598 else if (section_is_p (sectp
->name
, &names
->types
))
1600 struct dwarf2_section_info type_section
;
1602 memset (&type_section
, 0, sizeof (type_section
));
1603 type_section
.asection
= sectp
;
1604 type_section
.size
= bfd_get_section_size (sectp
);
1606 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1609 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1611 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1612 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1615 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1616 && bfd_section_vma (abfd
, sectp
) == 0)
1617 dwarf2_per_objfile
->has_section_at_zero
= 1;
1620 /* Decompress a section that was compressed using zlib. Store the
1621 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1624 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1625 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1627 bfd
*abfd
= sectp
->owner
;
1629 error (_("Support for zlib-compressed DWARF data (from '%s') "
1630 "is disabled in this copy of GDB"),
1631 bfd_get_filename (abfd
));
1633 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1634 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1635 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1636 bfd_size_type uncompressed_size
;
1637 gdb_byte
*uncompressed_buffer
;
1640 int header_size
= 12;
1642 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1643 || bfd_bread (compressed_buffer
,
1644 compressed_size
, abfd
) != compressed_size
)
1645 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1646 bfd_get_filename (abfd
));
1648 /* Read the zlib header. In this case, it should be "ZLIB" followed
1649 by the uncompressed section size, 8 bytes in big-endian order. */
1650 if (compressed_size
< header_size
1651 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1652 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1653 bfd_get_filename (abfd
));
1654 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1655 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1656 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1657 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1658 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1659 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1660 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1661 uncompressed_size
+= compressed_buffer
[11];
1663 /* It is possible the section consists of several compressed
1664 buffers concatenated together, so we uncompress in a loop. */
1668 strm
.avail_in
= compressed_size
- header_size
;
1669 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1670 strm
.avail_out
= uncompressed_size
;
1671 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1673 rc
= inflateInit (&strm
);
1674 while (strm
.avail_in
> 0)
1677 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1678 bfd_get_filename (abfd
), rc
);
1679 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1680 + (uncompressed_size
- strm
.avail_out
));
1681 rc
= inflate (&strm
, Z_FINISH
);
1682 if (rc
!= Z_STREAM_END
)
1683 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1684 bfd_get_filename (abfd
), rc
);
1685 rc
= inflateReset (&strm
);
1687 rc
= inflateEnd (&strm
);
1689 || strm
.avail_out
!= 0)
1690 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1691 bfd_get_filename (abfd
), rc
);
1693 do_cleanups (cleanup
);
1694 *outbuf
= uncompressed_buffer
;
1695 *outsize
= uncompressed_size
;
1699 /* A helper function that decides whether a section is empty,
1703 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1705 return info
->asection
== NULL
|| info
->size
== 0;
1708 /* Read the contents of the section INFO.
1709 OBJFILE is the main object file, but not necessarily the file where
1710 the section comes from. E.g., for DWO files INFO->asection->owner
1711 is the bfd of the DWO file.
1712 If the section is compressed, uncompress it before returning. */
1715 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1717 asection
*sectp
= info
->asection
;
1719 gdb_byte
*buf
, *retbuf
;
1720 unsigned char header
[4];
1724 info
->buffer
= NULL
;
1725 info
->map_addr
= NULL
;
1728 if (dwarf2_section_empty_p (info
))
1731 /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */
1732 abfd
= sectp
->owner
;
1734 /* Check if the file has a 4-byte header indicating compression. */
1735 if (info
->size
> sizeof (header
)
1736 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1737 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1739 /* Upon decompression, update the buffer and its size. */
1740 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1742 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1750 pagesize
= getpagesize ();
1752 /* Only try to mmap sections which are large enough: we don't want to
1753 waste space due to fragmentation. Also, only try mmap for sections
1754 without relocations. */
1756 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1758 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1759 MAP_PRIVATE
, sectp
->filepos
,
1760 &info
->map_addr
, &info
->map_len
);
1762 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1764 #if HAVE_POSIX_MADVISE
1765 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1772 /* If we get here, we are a normal, not-compressed section. */
1774 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1776 /* When debugging .o files, we may need to apply relocations; see
1777 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1778 We never compress sections in .o files, so we only need to
1779 try this when the section is not compressed. */
1780 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1783 info
->buffer
= retbuf
;
1787 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1788 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1789 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1790 bfd_get_filename (abfd
));
1793 /* A helper function that returns the size of a section in a safe way.
1794 If you are positive that the section has been read before using the
1795 size, then it is safe to refer to the dwarf2_section_info object's
1796 "size" field directly. In other cases, you must call this
1797 function, because for compressed sections the size field is not set
1798 correctly until the section has been read. */
1800 static bfd_size_type
1801 dwarf2_section_size (struct objfile
*objfile
,
1802 struct dwarf2_section_info
*info
)
1805 dwarf2_read_section (objfile
, info
);
1809 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1813 dwarf2_get_section_info (struct objfile
*objfile
,
1814 enum dwarf2_section_enum sect
,
1815 asection
**sectp
, gdb_byte
**bufp
,
1816 bfd_size_type
*sizep
)
1818 struct dwarf2_per_objfile
*data
1819 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1820 struct dwarf2_section_info
*info
;
1822 /* We may see an objfile without any DWARF, in which case we just
1833 case DWARF2_DEBUG_FRAME
:
1834 info
= &data
->frame
;
1836 case DWARF2_EH_FRAME
:
1837 info
= &data
->eh_frame
;
1840 gdb_assert_not_reached ("unexpected section");
1843 dwarf2_read_section (objfile
, info
);
1845 *sectp
= info
->asection
;
1846 *bufp
= info
->buffer
;
1847 *sizep
= info
->size
;
1851 /* DWARF quick_symbols_functions support. */
1853 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1854 unique line tables, so we maintain a separate table of all .debug_line
1855 derived entries to support the sharing.
1856 All the quick functions need is the list of file names. We discard the
1857 line_header when we're done and don't need to record it here. */
1858 struct quick_file_names
1860 /* The offset in .debug_line of the line table. We hash on this. */
1861 unsigned int offset
;
1863 /* The number of entries in file_names, real_names. */
1864 unsigned int num_file_names
;
1866 /* The file names from the line table, after being run through
1868 const char **file_names
;
1870 /* The file names from the line table after being run through
1871 gdb_realpath. These are computed lazily. */
1872 const char **real_names
;
1875 /* When using the index (and thus not using psymtabs), each CU has an
1876 object of this type. This is used to hold information needed by
1877 the various "quick" methods. */
1878 struct dwarf2_per_cu_quick_data
1880 /* The file table. This can be NULL if there was no file table
1881 or it's currently not read in.
1882 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1883 struct quick_file_names
*file_names
;
1885 /* The corresponding symbol table. This is NULL if symbols for this
1886 CU have not yet been read. */
1887 struct symtab
*symtab
;
1889 /* A temporary mark bit used when iterating over all CUs in
1890 expand_symtabs_matching. */
1891 unsigned int mark
: 1;
1893 /* True if we've tried to read the file table and found there isn't one.
1894 There will be no point in trying to read it again next time. */
1895 unsigned int no_file_data
: 1;
1898 /* Hash function for a quick_file_names. */
1901 hash_file_name_entry (const void *e
)
1903 const struct quick_file_names
*file_data
= e
;
1905 return file_data
->offset
;
1908 /* Equality function for a quick_file_names. */
1911 eq_file_name_entry (const void *a
, const void *b
)
1913 const struct quick_file_names
*ea
= a
;
1914 const struct quick_file_names
*eb
= b
;
1916 return ea
->offset
== eb
->offset
;
1919 /* Delete function for a quick_file_names. */
1922 delete_file_name_entry (void *e
)
1924 struct quick_file_names
*file_data
= e
;
1927 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1929 xfree ((void*) file_data
->file_names
[i
]);
1930 if (file_data
->real_names
)
1931 xfree ((void*) file_data
->real_names
[i
]);
1934 /* The space for the struct itself lives on objfile_obstack,
1935 so we don't free it here. */
1938 /* Create a quick_file_names hash table. */
1941 create_quick_file_names_table (unsigned int nr_initial_entries
)
1943 return htab_create_alloc (nr_initial_entries
,
1944 hash_file_name_entry
, eq_file_name_entry
,
1945 delete_file_name_entry
, xcalloc
, xfree
);
1948 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1949 have to be created afterwards. You should call age_cached_comp_units after
1950 processing PER_CU->CU. dw2_setup must have been already called. */
1953 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1955 if (per_cu
->is_debug_types
)
1956 load_full_type_unit (per_cu
);
1958 load_full_comp_unit (per_cu
, language_minimal
);
1960 gdb_assert (per_cu
->cu
!= NULL
);
1962 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1965 /* Read in the symbols for PER_CU. */
1968 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1970 struct cleanup
*back_to
;
1972 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1974 if (dwarf2_per_objfile
->using_index
1975 ? per_cu
->v
.quick
->symtab
== NULL
1976 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
1978 queue_comp_unit (per_cu
, language_minimal
);
1984 /* Age the cache, releasing compilation units that have not
1985 been used recently. */
1986 age_cached_comp_units ();
1988 do_cleanups (back_to
);
1991 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1992 the objfile from which this CU came. Returns the resulting symbol
1995 static struct symtab
*
1996 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1998 gdb_assert (dwarf2_per_objfile
->using_index
);
1999 if (!per_cu
->v
.quick
->symtab
)
2001 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2002 increment_reading_symtab ();
2003 dw2_do_instantiate_symtab (per_cu
);
2004 process_cu_includes ();
2005 do_cleanups (back_to
);
2007 return per_cu
->v
.quick
->symtab
;
2010 /* Return the CU given its index. */
2012 static struct dwarf2_per_cu_data
*
2013 dw2_get_cu (int index
)
2015 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2017 index
-= dwarf2_per_objfile
->n_comp_units
;
2018 return dwarf2_per_objfile
->all_type_units
[index
];
2020 return dwarf2_per_objfile
->all_comp_units
[index
];
2023 /* A helper function that knows how to read a 64-bit value in a way
2024 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2028 extract_cu_value (const char *bytes
, ULONGEST
*result
)
2030 if (sizeof (ULONGEST
) < 8)
2034 /* Ignore the upper 4 bytes if they are all zero. */
2035 for (i
= 0; i
< 4; ++i
)
2036 if (bytes
[i
+ 4] != 0)
2039 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2042 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2046 /* Read the CU list from the mapped index, and use it to create all
2047 the CU objects for this objfile. Return 0 if something went wrong,
2048 1 if everything went ok. */
2051 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
2052 offset_type cu_list_elements
)
2056 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
2057 dwarf2_per_objfile
->all_comp_units
2058 = obstack_alloc (&objfile
->objfile_obstack
,
2059 dwarf2_per_objfile
->n_comp_units
2060 * sizeof (struct dwarf2_per_cu_data
*));
2062 for (i
= 0; i
< cu_list_elements
; i
+= 2)
2064 struct dwarf2_per_cu_data
*the_cu
;
2065 ULONGEST offset
, length
;
2067 if (!extract_cu_value (cu_list
, &offset
)
2068 || !extract_cu_value (cu_list
+ 8, &length
))
2072 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2073 struct dwarf2_per_cu_data
);
2074 the_cu
->offset
.sect_off
= offset
;
2075 the_cu
->length
= length
;
2076 the_cu
->objfile
= objfile
;
2077 the_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
2078 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2079 struct dwarf2_per_cu_quick_data
);
2080 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
2086 /* Create the signatured type hash table from the index. */
2089 create_signatured_type_table_from_index (struct objfile
*objfile
,
2090 struct dwarf2_section_info
*section
,
2091 const gdb_byte
*bytes
,
2092 offset_type elements
)
2095 htab_t sig_types_hash
;
2097 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2098 dwarf2_per_objfile
->all_type_units
2099 = obstack_alloc (&objfile
->objfile_obstack
,
2100 dwarf2_per_objfile
->n_type_units
2101 * sizeof (struct dwarf2_per_cu_data
*));
2103 sig_types_hash
= allocate_signatured_type_table (objfile
);
2105 for (i
= 0; i
< elements
; i
+= 3)
2107 struct signatured_type
*sig_type
;
2108 ULONGEST offset
, type_offset_in_tu
, signature
;
2111 if (!extract_cu_value (bytes
, &offset
)
2112 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2114 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2117 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2118 struct signatured_type
);
2119 sig_type
->signature
= signature
;
2120 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2121 sig_type
->per_cu
.is_debug_types
= 1;
2122 sig_type
->per_cu
.info_or_types_section
= section
;
2123 sig_type
->per_cu
.offset
.sect_off
= offset
;
2124 sig_type
->per_cu
.objfile
= objfile
;
2125 sig_type
->per_cu
.v
.quick
2126 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2127 struct dwarf2_per_cu_quick_data
);
2129 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2132 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &sig_type
->per_cu
;
2135 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2140 /* Read the address map data from the mapped index, and use it to
2141 populate the objfile's psymtabs_addrmap. */
2144 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2146 const gdb_byte
*iter
, *end
;
2147 struct obstack temp_obstack
;
2148 struct addrmap
*mutable_map
;
2149 struct cleanup
*cleanup
;
2152 obstack_init (&temp_obstack
);
2153 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2154 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2156 iter
= index
->address_table
;
2157 end
= iter
+ index
->address_table_size
;
2159 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2163 ULONGEST hi
, lo
, cu_index
;
2164 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2166 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2168 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2171 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2172 dw2_get_cu (cu_index
));
2175 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2176 &objfile
->objfile_obstack
);
2177 do_cleanups (cleanup
);
2180 /* The hash function for strings in the mapped index. This is the same as
2181 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2182 implementation. This is necessary because the hash function is tied to the
2183 format of the mapped index file. The hash values do not have to match with
2186 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2189 mapped_index_string_hash (int index_version
, const void *p
)
2191 const unsigned char *str
= (const unsigned char *) p
;
2195 while ((c
= *str
++) != 0)
2197 if (index_version
>= 5)
2199 r
= r
* 67 + c
- 113;
2205 /* Find a slot in the mapped index INDEX for the object named NAME.
2206 If NAME is found, set *VEC_OUT to point to the CU vector in the
2207 constant pool and return 1. If NAME cannot be found, return 0. */
2210 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2211 offset_type
**vec_out
)
2213 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2215 offset_type slot
, step
;
2216 int (*cmp
) (const char *, const char *);
2218 if (current_language
->la_language
== language_cplus
2219 || current_language
->la_language
== language_java
2220 || current_language
->la_language
== language_fortran
)
2222 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2224 const char *paren
= strchr (name
, '(');
2230 dup
= xmalloc (paren
- name
+ 1);
2231 memcpy (dup
, name
, paren
- name
);
2232 dup
[paren
- name
] = 0;
2234 make_cleanup (xfree
, dup
);
2239 /* Index version 4 did not support case insensitive searches. But the
2240 indices for case insensitive languages are built in lowercase, therefore
2241 simulate our NAME being searched is also lowercased. */
2242 hash
= mapped_index_string_hash ((index
->version
== 4
2243 && case_sensitivity
== case_sensitive_off
2244 ? 5 : index
->version
),
2247 slot
= hash
& (index
->symbol_table_slots
- 1);
2248 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2249 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2253 /* Convert a slot number to an offset into the table. */
2254 offset_type i
= 2 * slot
;
2256 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2258 do_cleanups (back_to
);
2262 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2263 if (!cmp (name
, str
))
2265 *vec_out
= (offset_type
*) (index
->constant_pool
2266 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2267 do_cleanups (back_to
);
2271 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2275 /* Read the index file. If everything went ok, initialize the "quick"
2276 elements of all the CUs and return 1. Otherwise, return 0. */
2279 dwarf2_read_index (struct objfile
*objfile
)
2282 struct mapped_index
*map
;
2283 offset_type
*metadata
;
2284 const gdb_byte
*cu_list
;
2285 const gdb_byte
*types_list
= NULL
;
2286 offset_type version
, cu_list_elements
;
2287 offset_type types_list_elements
= 0;
2290 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2293 /* Older elfutils strip versions could keep the section in the main
2294 executable while splitting it for the separate debug info file. */
2295 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2296 & SEC_HAS_CONTENTS
) == 0)
2299 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2301 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2302 /* Version check. */
2303 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2304 /* Versions earlier than 3 emitted every copy of a psymbol. This
2305 causes the index to behave very poorly for certain requests. Version 3
2306 contained incomplete addrmap. So, it seems better to just ignore such
2310 static int warning_printed
= 0;
2311 if (!warning_printed
)
2313 warning (_("Skipping obsolete .gdb_index section in %s."),
2315 warning_printed
= 1;
2319 /* Index version 4 uses a different hash function than index version
2322 Versions earlier than 6 did not emit psymbols for inlined
2323 functions. Using these files will cause GDB not to be able to
2324 set breakpoints on inlined functions by name, so we ignore these
2325 indices unless the --use-deprecated-index-sections command line
2326 option was supplied. */
2327 if (version
< 6 && !use_deprecated_index_sections
)
2329 static int warning_printed
= 0;
2330 if (!warning_printed
)
2332 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2333 "--use-deprecated-index-sections to use them anyway"),
2335 warning_printed
= 1;
2339 /* Indexes with higher version than the one supported by GDB may be no
2340 longer backward compatible. */
2344 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2345 map
->version
= version
;
2346 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2348 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2351 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2352 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2356 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2357 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2358 - MAYBE_SWAP (metadata
[i
]))
2362 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2363 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2364 - MAYBE_SWAP (metadata
[i
]));
2367 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2368 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2369 - MAYBE_SWAP (metadata
[i
]))
2370 / (2 * sizeof (offset_type
)));
2373 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2375 /* Don't use the index if it's empty. */
2376 if (map
->symbol_table_slots
== 0)
2379 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2382 if (types_list_elements
)
2384 struct dwarf2_section_info
*section
;
2386 /* We can only handle a single .debug_types when we have an
2388 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2391 section
= VEC_index (dwarf2_section_info_def
,
2392 dwarf2_per_objfile
->types
, 0);
2394 if (!create_signatured_type_table_from_index (objfile
, section
,
2396 types_list_elements
))
2400 create_addrmap_from_index (objfile
, map
);
2402 dwarf2_per_objfile
->index_table
= map
;
2403 dwarf2_per_objfile
->using_index
= 1;
2404 dwarf2_per_objfile
->quick_file_names_table
=
2405 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2410 /* A helper for the "quick" functions which sets the global
2411 dwarf2_per_objfile according to OBJFILE. */
2414 dw2_setup (struct objfile
*objfile
)
2416 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2417 gdb_assert (dwarf2_per_objfile
);
2420 /* die_reader_func for dw2_get_file_names. */
2423 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2425 struct die_info
*comp_unit_die
,
2429 struct dwarf2_cu
*cu
= reader
->cu
;
2430 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2431 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2432 struct line_header
*lh
;
2433 struct attribute
*attr
;
2435 unsigned int bytes_read
;
2436 char *name
, *comp_dir
;
2438 struct quick_file_names
*qfn
;
2439 unsigned int line_offset
;
2445 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2448 struct quick_file_names find_entry
;
2450 line_offset
= DW_UNSND (attr
);
2452 /* We may have already read in this line header (TU line header sharing).
2453 If we have we're done. */
2454 find_entry
.offset
= line_offset
;
2455 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2456 &find_entry
, INSERT
);
2459 this_cu
->v
.quick
->file_names
= *slot
;
2463 lh
= dwarf_decode_line_header (line_offset
, cu
);
2467 this_cu
->v
.quick
->no_file_data
= 1;
2471 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2472 qfn
->offset
= line_offset
;
2473 gdb_assert (slot
!= NULL
);
2476 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2478 qfn
->num_file_names
= lh
->num_file_names
;
2479 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2480 lh
->num_file_names
* sizeof (char *));
2481 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2482 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2483 qfn
->real_names
= NULL
;
2485 free_line_header (lh
);
2487 this_cu
->v
.quick
->file_names
= qfn
;
2490 /* A helper for the "quick" functions which attempts to read the line
2491 table for THIS_CU. */
2493 static struct quick_file_names
*
2494 dw2_get_file_names (struct objfile
*objfile
,
2495 struct dwarf2_per_cu_data
*this_cu
)
2497 if (this_cu
->v
.quick
->file_names
!= NULL
)
2498 return this_cu
->v
.quick
->file_names
;
2499 /* If we know there is no line data, no point in looking again. */
2500 if (this_cu
->v
.quick
->no_file_data
)
2503 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2504 in the stub for CUs, there's is no need to lookup the DWO file.
2505 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2507 if (this_cu
->is_debug_types
)
2508 init_cutu_and_read_dies (this_cu
, 0, 0, dw2_get_file_names_reader
, NULL
);
2510 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2512 if (this_cu
->v
.quick
->no_file_data
)
2514 return this_cu
->v
.quick
->file_names
;
2517 /* A helper for the "quick" functions which computes and caches the
2518 real path for a given file name from the line table. */
2521 dw2_get_real_path (struct objfile
*objfile
,
2522 struct quick_file_names
*qfn
, int index
)
2524 if (qfn
->real_names
== NULL
)
2525 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2526 qfn
->num_file_names
, sizeof (char *));
2528 if (qfn
->real_names
[index
] == NULL
)
2529 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2531 return qfn
->real_names
[index
];
2534 static struct symtab
*
2535 dw2_find_last_source_symtab (struct objfile
*objfile
)
2539 dw2_setup (objfile
);
2540 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2541 return dw2_instantiate_symtab (dw2_get_cu (index
));
2544 /* Traversal function for dw2_forget_cached_source_info. */
2547 dw2_free_cached_file_names (void **slot
, void *info
)
2549 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2551 if (file_data
->real_names
)
2555 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2557 xfree ((void*) file_data
->real_names
[i
]);
2558 file_data
->real_names
[i
] = NULL
;
2566 dw2_forget_cached_source_info (struct objfile
*objfile
)
2568 dw2_setup (objfile
);
2570 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2571 dw2_free_cached_file_names
, NULL
);
2574 /* Helper function for dw2_map_symtabs_matching_filename that expands
2575 the symtabs and calls the iterator. */
2578 dw2_map_expand_apply (struct objfile
*objfile
,
2579 struct dwarf2_per_cu_data
*per_cu
,
2581 const char *full_path
, const char *real_path
,
2582 int (*callback
) (struct symtab
*, void *),
2585 struct symtab
*last_made
= objfile
->symtabs
;
2587 /* Don't visit already-expanded CUs. */
2588 if (per_cu
->v
.quick
->symtab
)
2591 /* This may expand more than one symtab, and we want to iterate over
2593 dw2_instantiate_symtab (per_cu
);
2595 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2596 objfile
->symtabs
, last_made
);
2599 /* Implementation of the map_symtabs_matching_filename method. */
2602 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2603 const char *full_path
, const char *real_path
,
2604 int (*callback
) (struct symtab
*, void *),
2608 const char *name_basename
= lbasename (name
);
2609 int name_len
= strlen (name
);
2610 int is_abs
= IS_ABSOLUTE_PATH (name
);
2612 dw2_setup (objfile
);
2614 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2615 + dwarf2_per_objfile
->n_type_units
); ++i
)
2618 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2619 struct quick_file_names
*file_data
;
2621 /* We only need to look at symtabs not already expanded. */
2622 if (per_cu
->v
.quick
->symtab
)
2625 file_data
= dw2_get_file_names (objfile
, per_cu
);
2626 if (file_data
== NULL
)
2629 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2631 const char *this_name
= file_data
->file_names
[j
];
2633 if (FILENAME_CMP (name
, this_name
) == 0
2634 || (!is_abs
&& compare_filenames_for_search (this_name
,
2637 if (dw2_map_expand_apply (objfile
, per_cu
,
2638 name
, full_path
, real_path
,
2643 /* Before we invoke realpath, which can get expensive when many
2644 files are involved, do a quick comparison of the basenames. */
2645 if (! basenames_may_differ
2646 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2649 if (full_path
!= NULL
)
2651 const char *this_real_name
= dw2_get_real_path (objfile
,
2654 if (this_real_name
!= NULL
2655 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2657 && compare_filenames_for_search (this_real_name
,
2660 if (dw2_map_expand_apply (objfile
, per_cu
,
2661 name
, full_path
, real_path
,
2667 if (real_path
!= NULL
)
2669 const char *this_real_name
= dw2_get_real_path (objfile
,
2672 if (this_real_name
!= NULL
2673 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2675 && compare_filenames_for_search (this_real_name
,
2678 if (dw2_map_expand_apply (objfile
, per_cu
,
2679 name
, full_path
, real_path
,
2690 static struct symtab
*
2691 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2692 const char *name
, domain_enum domain
)
2694 /* We do all the work in the pre_expand_symtabs_matching hook
2699 /* A helper function that expands all symtabs that hold an object
2703 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2705 dw2_setup (objfile
);
2707 /* index_table is NULL if OBJF_READNOW. */
2708 if (dwarf2_per_objfile
->index_table
)
2712 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2715 offset_type i
, len
= MAYBE_SWAP (*vec
);
2716 for (i
= 0; i
< len
; ++i
)
2718 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2719 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2721 dw2_instantiate_symtab (per_cu
);
2728 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2729 enum block_enum block_kind
, const char *name
,
2732 dw2_do_expand_symtabs_matching (objfile
, name
);
2736 dw2_print_stats (struct objfile
*objfile
)
2740 dw2_setup (objfile
);
2742 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2743 + dwarf2_per_objfile
->n_type_units
); ++i
)
2745 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2747 if (!per_cu
->v
.quick
->symtab
)
2750 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2754 dw2_dump (struct objfile
*objfile
)
2756 /* Nothing worth printing. */
2760 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2761 struct section_offsets
*delta
)
2763 /* There's nothing to relocate here. */
2767 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2768 const char *func_name
)
2770 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2774 dw2_expand_all_symtabs (struct objfile
*objfile
)
2778 dw2_setup (objfile
);
2780 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2781 + dwarf2_per_objfile
->n_type_units
); ++i
)
2783 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2785 dw2_instantiate_symtab (per_cu
);
2790 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2791 const char *filename
)
2795 dw2_setup (objfile
);
2797 /* We don't need to consider type units here.
2798 This is only called for examining code, e.g. expand_line_sal.
2799 There can be an order of magnitude (or more) more type units
2800 than comp units, and we avoid them if we can. */
2802 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2805 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2806 struct quick_file_names
*file_data
;
2808 /* We only need to look at symtabs not already expanded. */
2809 if (per_cu
->v
.quick
->symtab
)
2812 file_data
= dw2_get_file_names (objfile
, per_cu
);
2813 if (file_data
== NULL
)
2816 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2818 const char *this_name
= file_data
->file_names
[j
];
2819 if (FILENAME_CMP (this_name
, filename
) == 0)
2821 dw2_instantiate_symtab (per_cu
);
2829 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2831 struct dwarf2_per_cu_data
*per_cu
;
2833 struct quick_file_names
*file_data
;
2835 dw2_setup (objfile
);
2837 /* index_table is NULL if OBJF_READNOW. */
2838 if (!dwarf2_per_objfile
->index_table
)
2842 ALL_OBJFILE_SYMTABS (objfile
, s
)
2845 struct blockvector
*bv
= BLOCKVECTOR (s
);
2846 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2847 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2850 return sym
->symtab
->filename
;
2855 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2859 /* Note that this just looks at the very first one named NAME -- but
2860 actually we are looking for a function. find_main_filename
2861 should be rewritten so that it doesn't require a custom hook. It
2862 could just use the ordinary symbol tables. */
2863 /* vec[0] is the length, which must always be >0. */
2864 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2866 file_data
= dw2_get_file_names (objfile
, per_cu
);
2867 if (file_data
== NULL
2868 || file_data
->num_file_names
== 0)
2871 return file_data
->file_names
[file_data
->num_file_names
- 1];
2875 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2876 struct objfile
*objfile
, int global
,
2877 int (*callback
) (struct block
*,
2878 struct symbol
*, void *),
2879 void *data
, symbol_compare_ftype
*match
,
2880 symbol_compare_ftype
*ordered_compare
)
2882 /* Currently unimplemented; used for Ada. The function can be called if the
2883 current language is Ada for a non-Ada objfile using GNU index. As Ada
2884 does not look for non-Ada symbols this function should just return. */
2888 dw2_expand_symtabs_matching
2889 (struct objfile
*objfile
,
2890 int (*file_matcher
) (const char *, void *),
2891 int (*name_matcher
) (const char *, void *),
2892 enum search_domain kind
,
2897 struct mapped_index
*index
;
2899 dw2_setup (objfile
);
2901 /* index_table is NULL if OBJF_READNOW. */
2902 if (!dwarf2_per_objfile
->index_table
)
2904 index
= dwarf2_per_objfile
->index_table
;
2906 if (file_matcher
!= NULL
)
2908 struct cleanup
*cleanup
;
2909 htab_t visited_found
, visited_not_found
;
2911 visited_found
= htab_create_alloc (10,
2912 htab_hash_pointer
, htab_eq_pointer
,
2913 NULL
, xcalloc
, xfree
);
2914 cleanup
= make_cleanup_htab_delete (visited_found
);
2915 visited_not_found
= htab_create_alloc (10,
2916 htab_hash_pointer
, htab_eq_pointer
,
2917 NULL
, xcalloc
, xfree
);
2918 make_cleanup_htab_delete (visited_not_found
);
2920 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2921 + dwarf2_per_objfile
->n_type_units
); ++i
)
2924 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2925 struct quick_file_names
*file_data
;
2928 per_cu
->v
.quick
->mark
= 0;
2930 /* We only need to look at symtabs not already expanded. */
2931 if (per_cu
->v
.quick
->symtab
)
2934 file_data
= dw2_get_file_names (objfile
, per_cu
);
2935 if (file_data
== NULL
)
2938 if (htab_find (visited_not_found
, file_data
) != NULL
)
2940 else if (htab_find (visited_found
, file_data
) != NULL
)
2942 per_cu
->v
.quick
->mark
= 1;
2946 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2948 if (file_matcher (file_data
->file_names
[j
], data
))
2950 per_cu
->v
.quick
->mark
= 1;
2955 slot
= htab_find_slot (per_cu
->v
.quick
->mark
2957 : visited_not_found
,
2962 do_cleanups (cleanup
);
2965 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2967 offset_type idx
= 2 * iter
;
2969 offset_type
*vec
, vec_len
, vec_idx
;
2971 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2974 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2976 if (! (*name_matcher
) (name
, data
))
2979 /* The name was matched, now expand corresponding CUs that were
2981 vec
= (offset_type
*) (index
->constant_pool
2982 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2983 vec_len
= MAYBE_SWAP (vec
[0]);
2984 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2986 struct dwarf2_per_cu_data
*per_cu
;
2988 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2989 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2990 dw2_instantiate_symtab (per_cu
);
2995 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
2998 static struct symtab
*
2999 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3003 if (BLOCKVECTOR (symtab
) != NULL
3004 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3007 for (i
= 0; symtab
->includes
[i
]; ++i
)
3011 s
= recursively_find_pc_sect_symtab (s
, pc
);
3019 static struct symtab
*
3020 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3021 struct minimal_symbol
*msymbol
,
3023 struct obj_section
*section
,
3026 struct dwarf2_per_cu_data
*data
;
3027 struct symtab
*result
;
3029 dw2_setup (objfile
);
3031 if (!objfile
->psymtabs_addrmap
)
3034 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3038 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3039 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3040 paddress (get_objfile_arch (objfile
), pc
));
3042 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3043 gdb_assert (result
!= NULL
);
3048 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3049 void *data
, int need_fullname
)
3052 struct cleanup
*cleanup
;
3053 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3054 NULL
, xcalloc
, xfree
);
3056 cleanup
= make_cleanup_htab_delete (visited
);
3057 dw2_setup (objfile
);
3059 /* We can ignore file names coming from already-expanded CUs. */
3060 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3061 + dwarf2_per_objfile
->n_type_units
); ++i
)
3063 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3065 if (per_cu
->v
.quick
->symtab
)
3067 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3070 *slot
= per_cu
->v
.quick
->file_names
;
3074 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3075 + dwarf2_per_objfile
->n_type_units
); ++i
)
3078 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3079 struct quick_file_names
*file_data
;
3082 /* We only need to look at symtabs not already expanded. */
3083 if (per_cu
->v
.quick
->symtab
)
3086 file_data
= dw2_get_file_names (objfile
, per_cu
);
3087 if (file_data
== NULL
)
3090 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3093 /* Already visited. */
3098 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3100 const char *this_real_name
;
3103 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3105 this_real_name
= NULL
;
3106 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3110 do_cleanups (cleanup
);
3114 dw2_has_symbols (struct objfile
*objfile
)
3119 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3122 dw2_find_last_source_symtab
,
3123 dw2_forget_cached_source_info
,
3124 dw2_map_symtabs_matching_filename
,
3126 dw2_pre_expand_symtabs_matching
,
3130 dw2_expand_symtabs_for_function
,
3131 dw2_expand_all_symtabs
,
3132 dw2_expand_symtabs_with_filename
,
3133 dw2_find_symbol_file
,
3134 dw2_map_matching_symbols
,
3135 dw2_expand_symtabs_matching
,
3136 dw2_find_pc_sect_symtab
,
3137 dw2_map_symbol_filenames
3140 /* Initialize for reading DWARF for this objfile. Return 0 if this
3141 file will use psymtabs, or 1 if using the GNU index. */
3144 dwarf2_initialize_objfile (struct objfile
*objfile
)
3146 /* If we're about to read full symbols, don't bother with the
3147 indices. In this case we also don't care if some other debug
3148 format is making psymtabs, because they are all about to be
3150 if ((objfile
->flags
& OBJF_READNOW
))
3154 dwarf2_per_objfile
->using_index
= 1;
3155 create_all_comp_units (objfile
);
3156 create_all_type_units (objfile
);
3157 dwarf2_per_objfile
->quick_file_names_table
=
3158 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3160 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3161 + dwarf2_per_objfile
->n_type_units
); ++i
)
3163 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3165 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3166 struct dwarf2_per_cu_quick_data
);
3169 /* Return 1 so that gdb sees the "quick" functions. However,
3170 these functions will be no-ops because we will have expanded
3175 if (dwarf2_read_index (objfile
))
3183 /* Build a partial symbol table. */
3186 dwarf2_build_psymtabs (struct objfile
*objfile
)
3188 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3190 init_psymbol_list (objfile
, 1024);
3193 dwarf2_build_psymtabs_hard (objfile
);
3196 /* Return TRUE if OFFSET is within CU_HEADER. */
3199 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3201 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3202 sect_offset top
= { (cu_header
->offset
.sect_off
+ cu_header
->length
3203 + cu_header
->initial_length_size
) };
3205 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3208 /* Read in the comp unit header information from the debug_info at info_ptr.
3209 NOTE: This leaves members offset, first_die_offset to be filled in
3213 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3214 gdb_byte
*info_ptr
, bfd
*abfd
)
3217 unsigned int bytes_read
;
3219 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3220 cu_header
->initial_length_size
= bytes_read
;
3221 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3222 info_ptr
+= bytes_read
;
3223 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3225 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3227 info_ptr
+= bytes_read
;
3228 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3230 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3231 if (signed_addr
< 0)
3232 internal_error (__FILE__
, __LINE__
,
3233 _("read_comp_unit_head: dwarf from non elf file"));
3234 cu_header
->signed_addr_p
= signed_addr
;
3239 /* Subroutine of read_and_check_comp_unit_head and
3240 read_and_check_type_unit_head to simplify them.
3241 Perform various error checking on the header. */
3244 error_check_comp_unit_head (struct comp_unit_head
*header
,
3245 struct dwarf2_section_info
*section
)
3247 bfd
*abfd
= section
->asection
->owner
;
3248 const char *filename
= bfd_get_filename (abfd
);
3250 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3251 error (_("Dwarf Error: wrong version in compilation unit header "
3252 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3255 if (header
->abbrev_offset
.sect_off
3256 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3257 &dwarf2_per_objfile
->abbrev
))
3258 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3259 "(offset 0x%lx + 6) [in module %s]"),
3260 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3263 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3264 avoid potential 32-bit overflow. */
3265 if (((unsigned long) header
->offset
.sect_off
3266 + header
->length
+ header
->initial_length_size
)
3268 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3269 "(offset 0x%lx + 0) [in module %s]"),
3270 (long) header
->length
, (long) header
->offset
.sect_off
,
3274 /* Read in a CU/TU header and perform some basic error checking.
3275 The contents of the header are stored in HEADER.
3276 The result is a pointer to the start of the first DIE. */
3279 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3280 struct dwarf2_section_info
*section
,
3282 int is_debug_types_section
)
3284 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3285 bfd
*abfd
= section
->asection
->owner
;
3287 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3289 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3291 /* If we're reading a type unit, skip over the signature and
3292 type_offset fields. */
3293 if (is_debug_types_section
)
3294 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3296 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3298 error_check_comp_unit_head (header
, section
);
3303 /* Read in the types comp unit header information from .debug_types entry at
3304 types_ptr. The result is a pointer to one past the end of the header. */
3307 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3308 struct dwarf2_section_info
*section
,
3310 ULONGEST
*signature
,
3311 cu_offset
*type_offset_in_tu
)
3313 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3314 bfd
*abfd
= section
->asection
->owner
;
3316 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3318 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3320 /* If we're reading a type unit, skip over the signature and
3321 type_offset fields. */
3322 if (signature
!= NULL
)
3323 *signature
= read_8_bytes (abfd
, info_ptr
);
3325 if (type_offset_in_tu
!= NULL
)
3326 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3327 header
->offset_size
);
3328 info_ptr
+= header
->offset_size
;
3330 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3332 error_check_comp_unit_head (header
, section
);
3337 /* Allocate a new partial symtab for file named NAME and mark this new
3338 partial symtab as being an include of PST. */
3341 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3342 struct objfile
*objfile
)
3344 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3346 subpst
->section_offsets
= pst
->section_offsets
;
3347 subpst
->textlow
= 0;
3348 subpst
->texthigh
= 0;
3350 subpst
->dependencies
= (struct partial_symtab
**)
3351 obstack_alloc (&objfile
->objfile_obstack
,
3352 sizeof (struct partial_symtab
*));
3353 subpst
->dependencies
[0] = pst
;
3354 subpst
->number_of_dependencies
= 1;
3356 subpst
->globals_offset
= 0;
3357 subpst
->n_global_syms
= 0;
3358 subpst
->statics_offset
= 0;
3359 subpst
->n_static_syms
= 0;
3360 subpst
->symtab
= NULL
;
3361 subpst
->read_symtab
= pst
->read_symtab
;
3364 /* No private part is necessary for include psymtabs. This property
3365 can be used to differentiate between such include psymtabs and
3366 the regular ones. */
3367 subpst
->read_symtab_private
= NULL
;
3370 /* Read the Line Number Program data and extract the list of files
3371 included by the source file represented by PST. Build an include
3372 partial symtab for each of these included files. */
3375 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3376 struct die_info
*die
,
3377 struct partial_symtab
*pst
)
3379 struct line_header
*lh
= NULL
;
3380 struct attribute
*attr
;
3382 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3384 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3386 return; /* No linetable, so no includes. */
3388 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3389 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3391 free_line_header (lh
);
3395 hash_signatured_type (const void *item
)
3397 const struct signatured_type
*sig_type
= item
;
3399 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3400 return sig_type
->signature
;
3404 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3406 const struct signatured_type
*lhs
= item_lhs
;
3407 const struct signatured_type
*rhs
= item_rhs
;
3409 return lhs
->signature
== rhs
->signature
;
3412 /* Allocate a hash table for signatured types. */
3415 allocate_signatured_type_table (struct objfile
*objfile
)
3417 return htab_create_alloc_ex (41,
3418 hash_signatured_type
,
3421 &objfile
->objfile_obstack
,
3422 hashtab_obstack_allocate
,
3423 dummy_obstack_deallocate
);
3426 /* A helper function to add a signatured type CU to a table. */
3429 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3431 struct signatured_type
*sigt
= *slot
;
3432 struct dwarf2_per_cu_data
***datap
= datum
;
3434 **datap
= &sigt
->per_cu
;
3440 /* Create the hash table of all entries in the .debug_types section.
3441 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
3442 The result is a pointer to the hash table or NULL if there are
3446 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
3447 VEC (dwarf2_section_info_def
) *types
)
3449 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3450 htab_t types_htab
= NULL
;
3452 struct dwarf2_section_info
*section
;
3454 if (VEC_empty (dwarf2_section_info_def
, types
))
3458 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
3462 gdb_byte
*info_ptr
, *end_ptr
;
3464 dwarf2_read_section (objfile
, section
);
3465 info_ptr
= section
->buffer
;
3467 if (info_ptr
== NULL
)
3470 /* We can't set abfd until now because the section may be empty or
3471 not present, in which case section->asection will be NULL. */
3472 abfd
= section
->asection
->owner
;
3474 if (types_htab
== NULL
)
3477 types_htab
= allocate_dwo_unit_table (objfile
);
3479 types_htab
= allocate_signatured_type_table (objfile
);
3482 if (dwarf2_die_debug
)
3483 fprintf_unfiltered (gdb_stdlog
, "Reading signatured types for %s:\n",
3484 bfd_get_filename (abfd
));
3486 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3487 because we don't need to read any dies: the signature is in the
3490 end_ptr
= info_ptr
+ section
->size
;
3491 while (info_ptr
< end_ptr
)
3494 cu_offset type_offset_in_tu
;
3496 struct signatured_type
*sig_type
;
3497 struct dwo_unit
*dwo_tu
;
3499 gdb_byte
*ptr
= info_ptr
;
3500 struct comp_unit_head header
;
3501 unsigned int length
;
3503 offset
.sect_off
= ptr
- section
->buffer
;
3505 /* We need to read the type's signature in order to build the hash
3506 table, but we don't need anything else just yet. */
3508 ptr
= read_and_check_type_unit_head (&header
, section
, ptr
,
3509 &signature
, &type_offset_in_tu
);
3511 length
= header
.initial_length_size
+ header
.length
;
3513 /* Skip dummy type units. */
3514 if (ptr
>= info_ptr
+ length
3515 || peek_abbrev_code (abfd
, ptr
) == 0)
3517 info_ptr
+= header
.initial_length_size
+ header
.length
;
3524 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3526 dwo_tu
->dwo_file
= dwo_file
;
3527 dwo_tu
->signature
= signature
;
3528 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
3529 dwo_tu
->info_or_types_section
= section
;
3530 dwo_tu
->offset
= offset
;
3531 dwo_tu
->length
= length
;
3535 /* N.B.: type_offset is not usable if this type uses a DWO file.
3536 The real type_offset is in the DWO file. */
3538 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3539 struct signatured_type
);
3540 sig_type
->signature
= signature
;
3541 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3542 sig_type
->per_cu
.objfile
= objfile
;
3543 sig_type
->per_cu
.is_debug_types
= 1;
3544 sig_type
->per_cu
.info_or_types_section
= section
;
3545 sig_type
->per_cu
.offset
= offset
;
3546 sig_type
->per_cu
.length
= length
;
3549 slot
= htab_find_slot (types_htab
,
3550 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
3552 gdb_assert (slot
!= NULL
);
3555 sect_offset dup_offset
;
3559 const struct dwo_unit
*dup_tu
= *slot
;
3561 dup_offset
= dup_tu
->offset
;
3565 const struct signatured_type
*dup_tu
= *slot
;
3567 dup_offset
= dup_tu
->per_cu
.offset
;
3570 complaint (&symfile_complaints
,
3571 _("debug type entry at offset 0x%x is duplicate to the "
3572 "entry at offset 0x%x, signature 0x%s"),
3573 offset
.sect_off
, dup_offset
.sect_off
,
3574 phex (signature
, sizeof (signature
)));
3576 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
3578 if (dwarf2_die_debug
)
3579 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3581 phex (signature
, sizeof (signature
)));
3590 /* Create the hash table of all entries in the .debug_types section,
3591 and initialize all_type_units.
3592 The result is zero if there is an error (e.g. missing .debug_types section),
3593 otherwise non-zero. */
3596 create_all_type_units (struct objfile
*objfile
)
3599 struct dwarf2_per_cu_data
**iter
;
3601 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
3602 if (types_htab
== NULL
)
3604 dwarf2_per_objfile
->signatured_types
= NULL
;
3608 dwarf2_per_objfile
->signatured_types
= types_htab
;
3610 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3611 dwarf2_per_objfile
->all_type_units
3612 = obstack_alloc (&objfile
->objfile_obstack
,
3613 dwarf2_per_objfile
->n_type_units
3614 * sizeof (struct dwarf2_per_cu_data
*));
3615 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3616 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3617 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3618 == dwarf2_per_objfile
->n_type_units
);
3623 /* Lookup a signature based type for DW_FORM_ref_sig8.
3624 Returns NULL if signature SIG is not present in the table. */
3626 static struct signatured_type
*
3627 lookup_signatured_type (ULONGEST sig
)
3629 struct signatured_type find_entry
, *entry
;
3631 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3633 complaint (&symfile_complaints
,
3634 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3638 find_entry
.signature
= sig
;
3639 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3643 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3646 init_cu_die_reader (struct die_reader_specs
*reader
,
3647 struct dwarf2_cu
*cu
,
3648 struct dwarf2_section_info
*section
,
3649 struct dwo_file
*dwo_file
)
3651 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
3652 reader
->abfd
= section
->asection
->owner
;
3654 reader
->dwo_file
= dwo_file
;
3655 reader
->die_section
= section
;
3656 reader
->buffer
= section
->buffer
;
3659 /* Find the base address of the compilation unit for range lists and
3660 location lists. It will normally be specified by DW_AT_low_pc.
3661 In DWARF-3 draft 4, the base address could be overridden by
3662 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3663 compilation units with discontinuous ranges. */
3666 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3668 struct attribute
*attr
;
3671 cu
->base_address
= 0;
3673 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3676 cu
->base_address
= DW_ADDR (attr
);
3681 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3684 cu
->base_address
= DW_ADDR (attr
);
3690 /* Initialize a CU (or TU) and read its DIEs.
3691 If the CU defers to a DWO file, read the DWO file as well.
3693 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
3694 Otherwise, a new CU is allocated with xmalloc.
3696 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
3697 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
3699 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3700 linker) then DIE_READER_FUNC will not get called. */
3703 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
3704 int use_existing_cu
, int keep
,
3705 die_reader_func_ftype
*die_reader_func
,
3708 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3709 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
3710 bfd
*abfd
= section
->asection
->owner
;
3711 struct dwarf2_cu
*cu
;
3712 gdb_byte
*begin_info_ptr
, *info_ptr
;
3713 struct die_reader_specs reader
;
3714 struct die_info
*comp_unit_die
;
3716 struct attribute
*attr
;
3717 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
3718 struct signatured_type
*sig_type
= NULL
;
3720 if (use_existing_cu
)
3723 cleanups
= make_cleanup (null_cleanup
, NULL
);
3725 /* This is cheap if the section is already read in. */
3726 dwarf2_read_section (objfile
, section
);
3728 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3730 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
3733 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
3737 /* If !use_existing_cu, this_cu->cu must be NULL. */
3738 gdb_assert (this_cu
->cu
== NULL
);
3740 cu
= xmalloc (sizeof (*cu
));
3741 init_one_comp_unit (cu
, this_cu
);
3743 /* If an error occurs while loading, release our storage. */
3744 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3746 if (this_cu
->is_debug_types
)
3750 info_ptr
= read_and_check_type_unit_head (&cu
->header
,
3754 /* There's no way to get from PER_CU to its containing
3755 struct signatured_type.
3756 But we have the signature so we can use that. */
3757 sig_type
= lookup_signatured_type (signature
);
3758 /* We've already scanned all the signatured types,
3759 this must succeed. */
3760 gdb_assert (sig_type
!= NULL
);
3761 gdb_assert (&sig_type
->per_cu
== this_cu
);
3762 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3764 /* LENGTH has not been set yet for type units. */
3765 this_cu
->length
= cu
->header
.length
+ cu
->header
.initial_length_size
;
3767 /* Establish the type offset that can be used to lookup the type. */
3768 sig_type
->type_offset_in_section
.sect_off
=
3769 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
3773 info_ptr
= read_and_check_comp_unit_head (&cu
->header
,
3774 section
, info_ptr
, 0);
3776 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3777 gdb_assert (this_cu
->length
3778 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3782 /* Skip dummy compilation units. */
3783 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
3784 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3786 do_cleanups (cleanups
);
3790 /* Read the abbrevs for this compilation unit into a table. */
3791 if (cu
->dwarf2_abbrevs
== NULL
)
3793 dwarf2_read_abbrevs (cu
, &dwarf2_per_objfile
->abbrev
);
3794 make_cleanup (dwarf2_free_abbrev_table
, cu
);
3797 /* Read the top level CU/TU die. */
3798 init_cu_die_reader (&reader
, cu
, section
, NULL
);
3799 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
3801 /* If we have a DWO stub, process it and then read in the DWO file.
3802 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
3803 a DWO CU, that this test will fail. */
3804 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
3807 char *dwo_name
= DW_STRING (attr
);
3808 const char *comp_dir
;
3809 struct dwo_unit
*dwo_unit
;
3810 ULONGEST signature
; /* Or dwo_id. */
3811 struct attribute
*stmt_list
, *low_pc
, *high_pc
, *ranges
;
3812 int i
,num_extra_attrs
;
3815 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
3816 " has children (offset 0x%x) [in module %s]"),
3817 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
3819 /* These attributes aren't processed until later:
3820 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
3821 However, the attribute is found in the stub which we won't have later.
3822 In order to not impose this complication on the rest of the code,
3823 we read them here and copy them to the DWO CU/TU die. */
3824 stmt_list
= low_pc
= high_pc
= ranges
= NULL
;
3826 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
3828 if (! this_cu
->is_debug_types
)
3829 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3830 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
3831 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
3832 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
3834 /* There should be a DW_AT_addr_base attribute here (if needed).
3835 We need the value before we can process DW_FORM_GNU_addr_index. */
3837 cu
->have_addr_base
= 0;
3838 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
3841 cu
->addr_base
= DW_UNSND (attr
);
3842 cu
->have_addr_base
= 1;
3845 if (this_cu
->is_debug_types
)
3847 gdb_assert (sig_type
!= NULL
);
3848 signature
= sig_type
->signature
;
3852 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
3854 error (_("Dwarf Error: missing dwo_id [in module %s]"),
3856 signature
= DW_UNSND (attr
);
3859 /* We may need the comp_dir in order to find the DWO file. */
3861 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
3863 comp_dir
= DW_STRING (attr
);
3865 if (this_cu
->is_debug_types
)
3866 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
3868 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
3871 if (dwo_unit
== NULL
)
3873 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
3874 " with ID %s [in module %s]"),
3875 this_cu
->offset
.sect_off
,
3876 phex (signature
, sizeof (signature
)),
3880 /* Set up for reading the DWO CU/TU. */
3881 cu
->dwo_unit
= dwo_unit
;
3882 section
= dwo_unit
->info_or_types_section
;
3883 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
3884 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
3886 if (this_cu
->is_debug_types
)
3890 info_ptr
= read_and_check_type_unit_head (&cu
->header
,
3893 gdb_assert (sig_type
->signature
== signature
);
3894 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3895 gdb_assert (dwo_unit
->length
3896 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3898 /* Establish the type offset that can be used to lookup the type.
3899 For DWO files, we don't know it until now. */
3900 sig_type
->type_offset_in_section
.sect_off
=
3901 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
3905 info_ptr
= read_and_check_comp_unit_head (&cu
->header
,
3906 section
, info_ptr
, 0);
3907 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3908 gdb_assert (dwo_unit
->length
3909 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3912 /* Discard the original CU's abbrev table, and read the DWO's. */
3913 dwarf2_free_abbrev_table (cu
);
3914 dwarf2_read_abbrevs (cu
, &dwo_unit
->dwo_file
->sections
.abbrev
);
3916 /* Read in the die, but leave space to copy over the attributes
3917 from the stub. This has the benefit of simplifying the rest of
3918 the code - all the real work is done here. */
3919 num_extra_attrs
= ((stmt_list
!= NULL
)
3922 + (ranges
!= NULL
));
3923 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
3924 &has_children
, num_extra_attrs
);
3926 /* Copy over the attributes from the stub to the DWO die. */
3927 i
= comp_unit_die
->num_attrs
;
3928 if (stmt_list
!= NULL
)
3929 comp_unit_die
->attrs
[i
++] = *stmt_list
;
3931 comp_unit_die
->attrs
[i
++] = *low_pc
;
3932 if (high_pc
!= NULL
)
3933 comp_unit_die
->attrs
[i
++] = *high_pc
;
3935 comp_unit_die
->attrs
[i
++] = *ranges
;
3936 comp_unit_die
->num_attrs
+= num_extra_attrs
;
3938 /* Skip dummy compilation units. */
3939 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
3940 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3942 do_cleanups (cleanups
);
3947 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
3949 if (free_cu_cleanup
!= NULL
)
3953 /* We've successfully allocated this compilation unit. Let our
3954 caller clean it up when finished with it. */
3955 discard_cleanups (free_cu_cleanup
);
3957 /* We can only discard free_cu_cleanup and all subsequent cleanups.
3958 So we have to manually free the abbrev table. */
3959 dwarf2_free_abbrev_table (cu
);
3961 /* Link this CU into read_in_chain. */
3962 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3963 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3966 do_cleanups (free_cu_cleanup
);
3969 do_cleanups (cleanups
);
3972 /* Read CU/TU THIS_CU in section SECTION,
3973 but do not follow DW_AT_GNU_dwo_name if present.
3974 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
3975 have already done the lookup to find the DWO file).
3977 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
3978 THIS_CU->is_debug_types, but nothing else.
3980 We fill in THIS_CU->length.
3982 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3983 linker) then DIE_READER_FUNC will not get called.
3985 THIS_CU->cu is always freed when done.
3986 This is done in order to not leave THIS_CU->cu in a state where we have
3987 to care whether it refers to the "main" CU or the DWO CU. */
3990 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
3991 struct dwarf2_section_info
*abbrev_section
,
3992 struct dwo_file
*dwo_file
,
3993 die_reader_func_ftype
*die_reader_func
,
3996 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3997 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
3998 bfd
*abfd
= section
->asection
->owner
;
3999 struct dwarf2_cu cu
;
4000 gdb_byte
*begin_info_ptr
, *info_ptr
;
4001 struct die_reader_specs reader
;
4002 struct cleanup
*cleanups
;
4003 struct die_info
*comp_unit_die
;
4006 gdb_assert (this_cu
->cu
== NULL
);
4008 /* This is cheap if the section is already read in. */
4009 dwarf2_read_section (objfile
, section
);
4011 init_one_comp_unit (&cu
, this_cu
);
4013 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4015 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4016 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
, info_ptr
,
4017 this_cu
->is_debug_types
);
4019 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
4021 /* Skip dummy compilation units. */
4022 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4023 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4025 do_cleanups (cleanups
);
4029 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4030 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4032 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4033 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4035 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4037 do_cleanups (cleanups
);
4040 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4041 does not lookup the specified DWO file.
4042 This cannot be used to read DWO files.
4044 THIS_CU->cu is always freed when done.
4045 This is done in order to not leave THIS_CU->cu in a state where we have
4046 to care whether it refers to the "main" CU or the DWO CU.
4047 We can revisit this if the data shows there's a performance issue. */
4050 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4051 die_reader_func_ftype
*die_reader_func
,
4054 init_cutu_and_read_dies_no_follow (this_cu
,
4055 &dwarf2_per_objfile
->abbrev
,
4057 die_reader_func
, data
);
4060 /* die_reader_func for process_psymtab_comp_unit. */
4063 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4065 struct die_info
*comp_unit_die
,
4069 struct dwarf2_cu
*cu
= reader
->cu
;
4070 struct objfile
*objfile
= cu
->objfile
;
4071 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4072 bfd
*abfd
= objfile
->obfd
;
4073 struct attribute
*attr
;
4075 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4076 struct partial_symtab
*pst
;
4078 const char *filename
;
4079 int *want_partial_unit_ptr
= data
;
4081 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4082 && (want_partial_unit_ptr
== NULL
4083 || !*want_partial_unit_ptr
))
4086 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4088 cu
->list_in_scope
= &file_symbols
;
4090 /* Allocate a new partial symbol table structure. */
4091 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4092 if (attr
== NULL
|| !DW_STRING (attr
))
4095 filename
= DW_STRING (attr
);
4096 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4098 /* TEXTLOW and TEXTHIGH are set below. */
4100 objfile
->global_psymbols
.next
,
4101 objfile
->static_psymbols
.next
);
4102 pst
->psymtabs_addrmap_supported
= 1;
4104 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4106 pst
->dirname
= DW_STRING (attr
);
4108 pst
->read_symtab_private
= per_cu
;
4110 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4112 /* Store the function that reads in the rest of the symbol table. */
4113 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4115 per_cu
->v
.psymtab
= pst
;
4117 dwarf2_find_base_address (comp_unit_die
, cu
);
4119 /* Possibly set the default values of LOWPC and HIGHPC from
4121 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4122 &best_highpc
, cu
, pst
);
4123 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4124 /* Store the contiguous range if it is not empty; it can be empty for
4125 CUs with no code. */
4126 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4127 best_lowpc
+ baseaddr
,
4128 best_highpc
+ baseaddr
- 1, pst
);
4130 /* Check if comp unit has_children.
4131 If so, read the rest of the partial symbols from this comp unit.
4132 If not, there's no more debug_info for this comp unit. */
4135 struct partial_die_info
*first_die
;
4136 CORE_ADDR lowpc
, highpc
;
4138 lowpc
= ((CORE_ADDR
) -1);
4139 highpc
= ((CORE_ADDR
) 0);
4141 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4143 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4146 /* If we didn't find a lowpc, set it to highpc to avoid
4147 complaints from `maint check'. */
4148 if (lowpc
== ((CORE_ADDR
) -1))
4151 /* If the compilation unit didn't have an explicit address range,
4152 then use the information extracted from its child dies. */
4156 best_highpc
= highpc
;
4159 pst
->textlow
= best_lowpc
+ baseaddr
;
4160 pst
->texthigh
= best_highpc
+ baseaddr
;
4162 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4163 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4164 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4165 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4166 sort_pst_symbols (pst
);
4168 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
4171 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4172 struct dwarf2_per_cu_data
*iter
;
4174 /* Fill in 'dependencies' here; we fill in 'users' in a
4176 pst
->number_of_dependencies
= len
;
4177 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4178 len
* sizeof (struct symtab
*));
4180 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4183 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4185 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4188 if (per_cu
->is_debug_types
)
4190 /* It's not clear we want to do anything with stmt lists here.
4191 Waiting to see what gcc ultimately does. */
4195 /* Get the list of files included in the current compilation unit,
4196 and build a psymtab for each of them. */
4197 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4201 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4202 Process compilation unit THIS_CU for a psymtab. */
4205 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4206 int want_partial_unit
)
4208 /* If this compilation unit was already read in, free the
4209 cached copy in order to read it in again. This is
4210 necessary because we skipped some symbols when we first
4211 read in the compilation unit (see load_partial_dies).
4212 This problem could be avoided, but the benefit is unclear. */
4213 if (this_cu
->cu
!= NULL
)
4214 free_one_cached_comp_unit (this_cu
);
4216 gdb_assert (! this_cu
->is_debug_types
);
4217 init_cutu_and_read_dies (this_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4218 &want_partial_unit
);
4220 /* Age out any secondary CUs. */
4221 age_cached_comp_units ();
4224 /* Traversal function for htab_traverse_noresize.
4225 Process one .debug_types comp-unit. */
4228 process_psymtab_type_unit (void **slot
, void *info
)
4230 struct signatured_type
*sig_type
= (struct signatured_type
*) *slot
;
4231 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
4233 gdb_assert (per_cu
->is_debug_types
);
4234 gdb_assert (info
== NULL
);
4236 /* If this compilation unit was already read in, free the
4237 cached copy in order to read it in again. This is
4238 necessary because we skipped some symbols when we first
4239 read in the compilation unit (see load_partial_dies).
4240 This problem could be avoided, but the benefit is unclear. */
4241 if (per_cu
->cu
!= NULL
)
4242 free_one_cached_comp_unit (per_cu
);
4244 init_cutu_and_read_dies (per_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4247 /* Age out any secondary CUs. */
4248 age_cached_comp_units ();
4253 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4254 Build partial symbol tables for the .debug_types comp-units. */
4257 build_type_psymtabs (struct objfile
*objfile
)
4259 if (! create_all_type_units (objfile
))
4262 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
4263 process_psymtab_type_unit
, NULL
);
4266 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
4269 psymtabs_addrmap_cleanup (void *o
)
4271 struct objfile
*objfile
= o
;
4273 objfile
->psymtabs_addrmap
= NULL
;
4276 /* Compute the 'user' field for each psymtab in OBJFILE. */
4279 set_partial_user (struct objfile
*objfile
)
4283 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4285 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4286 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4289 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
4291 /* Set the 'user' field only if it is not already set. */
4292 if (pst
->dependencies
[j
]->user
== NULL
)
4293 pst
->dependencies
[j
]->user
= pst
;
4298 /* Build the partial symbol table by doing a quick pass through the
4299 .debug_info and .debug_abbrev sections. */
4302 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
4304 struct cleanup
*back_to
, *addrmap_cleanup
;
4305 struct obstack temp_obstack
;
4308 dwarf2_per_objfile
->reading_partial_symbols
= 1;
4310 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4312 /* Any cached compilation units will be linked by the per-objfile
4313 read_in_chain. Make sure to free them when we're done. */
4314 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
4316 build_type_psymtabs (objfile
);
4318 create_all_comp_units (objfile
);
4320 /* Create a temporary address map on a temporary obstack. We later
4321 copy this to the final obstack. */
4322 obstack_init (&temp_obstack
);
4323 make_cleanup_obstack_free (&temp_obstack
);
4324 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
4325 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
4327 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4329 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4331 process_psymtab_comp_unit (per_cu
, 0);
4334 set_partial_user (objfile
);
4336 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
4337 &objfile
->objfile_obstack
);
4338 discard_cleanups (addrmap_cleanup
);
4340 do_cleanups (back_to
);
4343 /* die_reader_func for load_partial_comp_unit. */
4346 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
4348 struct die_info
*comp_unit_die
,
4352 struct dwarf2_cu
*cu
= reader
->cu
;
4354 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4356 /* Check if comp unit has_children.
4357 If so, read the rest of the partial symbols from this comp unit.
4358 If not, there's no more debug_info for this comp unit. */
4360 load_partial_dies (reader
, info_ptr
, 0);
4363 /* Load the partial DIEs for a secondary CU into memory.
4364 This is also used when rereading a primary CU with load_all_dies. */
4367 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
4369 init_cutu_and_read_dies (this_cu
, 1, 1, load_partial_comp_unit_reader
, NULL
);
4372 /* Create a list of all compilation units in OBJFILE.
4373 This is only done for -readnow and building partial symtabs. */
4376 create_all_comp_units (struct objfile
*objfile
)
4380 struct dwarf2_per_cu_data
**all_comp_units
;
4383 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4384 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
4388 all_comp_units
= xmalloc (n_allocated
4389 * sizeof (struct dwarf2_per_cu_data
*));
4391 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
4392 + dwarf2_per_objfile
->info
.size
)
4394 unsigned int length
, initial_length_size
;
4395 struct dwarf2_per_cu_data
*this_cu
;
4398 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
4400 /* Read just enough information to find out where the next
4401 compilation unit is. */
4402 length
= read_initial_length (objfile
->obfd
, info_ptr
,
4403 &initial_length_size
);
4405 /* Save the compilation unit for later lookup. */
4406 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
4407 sizeof (struct dwarf2_per_cu_data
));
4408 memset (this_cu
, 0, sizeof (*this_cu
));
4409 this_cu
->offset
= offset
;
4410 this_cu
->length
= length
+ initial_length_size
;
4411 this_cu
->objfile
= objfile
;
4412 this_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
4414 if (n_comp_units
== n_allocated
)
4417 all_comp_units
= xrealloc (all_comp_units
,
4419 * sizeof (struct dwarf2_per_cu_data
*));
4421 all_comp_units
[n_comp_units
++] = this_cu
;
4423 info_ptr
= info_ptr
+ this_cu
->length
;
4426 dwarf2_per_objfile
->all_comp_units
4427 = obstack_alloc (&objfile
->objfile_obstack
,
4428 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4429 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
4430 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4431 xfree (all_comp_units
);
4432 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
4435 /* Process all loaded DIEs for compilation unit CU, starting at
4436 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
4437 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
4438 DW_AT_ranges). If NEED_PC is set, then this function will set
4439 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
4440 and record the covered ranges in the addrmap. */
4443 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
4444 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4446 struct partial_die_info
*pdi
;
4448 /* Now, march along the PDI's, descending into ones which have
4449 interesting children but skipping the children of the other ones,
4450 until we reach the end of the compilation unit. */
4456 fixup_partial_die (pdi
, cu
);
4458 /* Anonymous namespaces or modules have no name but have interesting
4459 children, so we need to look at them. Ditto for anonymous
4462 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
4463 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
4464 || pdi
->tag
== DW_TAG_imported_unit
)
4468 case DW_TAG_subprogram
:
4469 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4471 case DW_TAG_constant
:
4472 case DW_TAG_variable
:
4473 case DW_TAG_typedef
:
4474 case DW_TAG_union_type
:
4475 if (!pdi
->is_declaration
)
4477 add_partial_symbol (pdi
, cu
);
4480 case DW_TAG_class_type
:
4481 case DW_TAG_interface_type
:
4482 case DW_TAG_structure_type
:
4483 if (!pdi
->is_declaration
)
4485 add_partial_symbol (pdi
, cu
);
4488 case DW_TAG_enumeration_type
:
4489 if (!pdi
->is_declaration
)
4490 add_partial_enumeration (pdi
, cu
);
4492 case DW_TAG_base_type
:
4493 case DW_TAG_subrange_type
:
4494 /* File scope base type definitions are added to the partial
4496 add_partial_symbol (pdi
, cu
);
4498 case DW_TAG_namespace
:
4499 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
4502 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
4504 case DW_TAG_imported_unit
:
4506 struct dwarf2_per_cu_data
*per_cu
;
4508 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
4511 /* Go read the partial unit, if needed. */
4512 if (per_cu
->v
.psymtab
== NULL
)
4513 process_psymtab_comp_unit (per_cu
, 1);
4515 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4524 /* If the die has a sibling, skip to the sibling. */
4526 pdi
= pdi
->die_sibling
;
4530 /* Functions used to compute the fully scoped name of a partial DIE.
4532 Normally, this is simple. For C++, the parent DIE's fully scoped
4533 name is concatenated with "::" and the partial DIE's name. For
4534 Java, the same thing occurs except that "." is used instead of "::".
4535 Enumerators are an exception; they use the scope of their parent
4536 enumeration type, i.e. the name of the enumeration type is not
4537 prepended to the enumerator.
4539 There are two complexities. One is DW_AT_specification; in this
4540 case "parent" means the parent of the target of the specification,
4541 instead of the direct parent of the DIE. The other is compilers
4542 which do not emit DW_TAG_namespace; in this case we try to guess
4543 the fully qualified name of structure types from their members'
4544 linkage names. This must be done using the DIE's children rather
4545 than the children of any DW_AT_specification target. We only need
4546 to do this for structures at the top level, i.e. if the target of
4547 any DW_AT_specification (if any; otherwise the DIE itself) does not
4550 /* Compute the scope prefix associated with PDI's parent, in
4551 compilation unit CU. The result will be allocated on CU's
4552 comp_unit_obstack, or a copy of the already allocated PDI->NAME
4553 field. NULL is returned if no prefix is necessary. */
4555 partial_die_parent_scope (struct partial_die_info
*pdi
,
4556 struct dwarf2_cu
*cu
)
4558 char *grandparent_scope
;
4559 struct partial_die_info
*parent
, *real_pdi
;
4561 /* We need to look at our parent DIE; if we have a DW_AT_specification,
4562 then this means the parent of the specification DIE. */
4565 while (real_pdi
->has_specification
)
4566 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
4568 parent
= real_pdi
->die_parent
;
4572 if (parent
->scope_set
)
4573 return parent
->scope
;
4575 fixup_partial_die (parent
, cu
);
4577 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
4579 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
4580 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
4581 Work around this problem here. */
4582 if (cu
->language
== language_cplus
4583 && parent
->tag
== DW_TAG_namespace
4584 && strcmp (parent
->name
, "::") == 0
4585 && grandparent_scope
== NULL
)
4587 parent
->scope
= NULL
;
4588 parent
->scope_set
= 1;
4592 if (pdi
->tag
== DW_TAG_enumerator
)
4593 /* Enumerators should not get the name of the enumeration as a prefix. */
4594 parent
->scope
= grandparent_scope
;
4595 else if (parent
->tag
== DW_TAG_namespace
4596 || parent
->tag
== DW_TAG_module
4597 || parent
->tag
== DW_TAG_structure_type
4598 || parent
->tag
== DW_TAG_class_type
4599 || parent
->tag
== DW_TAG_interface_type
4600 || parent
->tag
== DW_TAG_union_type
4601 || parent
->tag
== DW_TAG_enumeration_type
)
4603 if (grandparent_scope
== NULL
)
4604 parent
->scope
= parent
->name
;
4606 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
4608 parent
->name
, 0, cu
);
4612 /* FIXME drow/2004-04-01: What should we be doing with
4613 function-local names? For partial symbols, we should probably be
4615 complaint (&symfile_complaints
,
4616 _("unhandled containing DIE tag %d for DIE at %d"),
4617 parent
->tag
, pdi
->offset
.sect_off
);
4618 parent
->scope
= grandparent_scope
;
4621 parent
->scope_set
= 1;
4622 return parent
->scope
;
4625 /* Return the fully scoped name associated with PDI, from compilation unit
4626 CU. The result will be allocated with malloc. */
4629 partial_die_full_name (struct partial_die_info
*pdi
,
4630 struct dwarf2_cu
*cu
)
4634 /* If this is a template instantiation, we can not work out the
4635 template arguments from partial DIEs. So, unfortunately, we have
4636 to go through the full DIEs. At least any work we do building
4637 types here will be reused if full symbols are loaded later. */
4638 if (pdi
->has_template_arguments
)
4640 fixup_partial_die (pdi
, cu
);
4642 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4644 struct die_info
*die
;
4645 struct attribute attr
;
4646 struct dwarf2_cu
*ref_cu
= cu
;
4648 /* DW_FORM_ref_addr is using section offset. */
4650 attr
.form
= DW_FORM_ref_addr
;
4651 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
4652 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4654 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4658 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4659 if (parent_scope
== NULL
)
4662 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4666 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4668 struct objfile
*objfile
= cu
->objfile
;
4670 char *actual_name
= NULL
;
4672 int built_actual_name
= 0;
4674 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4676 actual_name
= partial_die_full_name (pdi
, cu
);
4678 built_actual_name
= 1;
4680 if (actual_name
== NULL
)
4681 actual_name
= pdi
->name
;
4685 case DW_TAG_subprogram
:
4686 if (pdi
->is_external
|| cu
->language
== language_ada
)
4688 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4689 of the global scope. But in Ada, we want to be able to access
4690 nested procedures globally. So all Ada subprograms are stored
4691 in the global scope. */
4692 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4693 mst_text, objfile); */
4694 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4696 VAR_DOMAIN
, LOC_BLOCK
,
4697 &objfile
->global_psymbols
,
4698 0, pdi
->lowpc
+ baseaddr
,
4699 cu
->language
, objfile
);
4703 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4704 mst_file_text, objfile); */
4705 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4707 VAR_DOMAIN
, LOC_BLOCK
,
4708 &objfile
->static_psymbols
,
4709 0, pdi
->lowpc
+ baseaddr
,
4710 cu
->language
, objfile
);
4713 case DW_TAG_constant
:
4715 struct psymbol_allocation_list
*list
;
4717 if (pdi
->is_external
)
4718 list
= &objfile
->global_psymbols
;
4720 list
= &objfile
->static_psymbols
;
4721 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4722 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4723 list
, 0, 0, cu
->language
, objfile
);
4726 case DW_TAG_variable
:
4728 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
4732 && !dwarf2_per_objfile
->has_section_at_zero
)
4734 /* A global or static variable may also have been stripped
4735 out by the linker if unused, in which case its address
4736 will be nullified; do not add such variables into partial
4737 symbol table then. */
4739 else if (pdi
->is_external
)
4742 Don't enter into the minimal symbol tables as there is
4743 a minimal symbol table entry from the ELF symbols already.
4744 Enter into partial symbol table if it has a location
4745 descriptor or a type.
4746 If the location descriptor is missing, new_symbol will create
4747 a LOC_UNRESOLVED symbol, the address of the variable will then
4748 be determined from the minimal symbol table whenever the variable
4750 The address for the partial symbol table entry is not
4751 used by GDB, but it comes in handy for debugging partial symbol
4754 if (pdi
->d
.locdesc
|| pdi
->has_type
)
4755 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4757 VAR_DOMAIN
, LOC_STATIC
,
4758 &objfile
->global_psymbols
,
4760 cu
->language
, objfile
);
4764 /* Static Variable. Skip symbols without location descriptors. */
4765 if (pdi
->d
.locdesc
== NULL
)
4767 if (built_actual_name
)
4768 xfree (actual_name
);
4771 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4772 mst_file_data, objfile); */
4773 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4775 VAR_DOMAIN
, LOC_STATIC
,
4776 &objfile
->static_psymbols
,
4778 cu
->language
, objfile
);
4781 case DW_TAG_typedef
:
4782 case DW_TAG_base_type
:
4783 case DW_TAG_subrange_type
:
4784 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4786 VAR_DOMAIN
, LOC_TYPEDEF
,
4787 &objfile
->static_psymbols
,
4788 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4790 case DW_TAG_namespace
:
4791 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4793 VAR_DOMAIN
, LOC_TYPEDEF
,
4794 &objfile
->global_psymbols
,
4795 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4797 case DW_TAG_class_type
:
4798 case DW_TAG_interface_type
:
4799 case DW_TAG_structure_type
:
4800 case DW_TAG_union_type
:
4801 case DW_TAG_enumeration_type
:
4802 /* Skip external references. The DWARF standard says in the section
4803 about "Structure, Union, and Class Type Entries": "An incomplete
4804 structure, union or class type is represented by a structure,
4805 union or class entry that does not have a byte size attribute
4806 and that has a DW_AT_declaration attribute." */
4807 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4809 if (built_actual_name
)
4810 xfree (actual_name
);
4814 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4815 static vs. global. */
4816 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4818 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4819 (cu
->language
== language_cplus
4820 || cu
->language
== language_java
)
4821 ? &objfile
->global_psymbols
4822 : &objfile
->static_psymbols
,
4823 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4826 case DW_TAG_enumerator
:
4827 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4829 VAR_DOMAIN
, LOC_CONST
,
4830 (cu
->language
== language_cplus
4831 || cu
->language
== language_java
)
4832 ? &objfile
->global_psymbols
4833 : &objfile
->static_psymbols
,
4834 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4840 if (built_actual_name
)
4841 xfree (actual_name
);
4844 /* Read a partial die corresponding to a namespace; also, add a symbol
4845 corresponding to that namespace to the symbol table. NAMESPACE is
4846 the name of the enclosing namespace. */
4849 add_partial_namespace (struct partial_die_info
*pdi
,
4850 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4851 int need_pc
, struct dwarf2_cu
*cu
)
4853 /* Add a symbol for the namespace. */
4855 add_partial_symbol (pdi
, cu
);
4857 /* Now scan partial symbols in that namespace. */
4859 if (pdi
->has_children
)
4860 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4863 /* Read a partial die corresponding to a Fortran module. */
4866 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4867 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4869 /* Now scan partial symbols in that module. */
4871 if (pdi
->has_children
)
4872 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4875 /* Read a partial die corresponding to a subprogram and create a partial
4876 symbol for that subprogram. When the CU language allows it, this
4877 routine also defines a partial symbol for each nested subprogram
4878 that this subprogram contains.
4880 DIE my also be a lexical block, in which case we simply search
4881 recursively for suprograms defined inside that lexical block.
4882 Again, this is only performed when the CU language allows this
4883 type of definitions. */
4886 add_partial_subprogram (struct partial_die_info
*pdi
,
4887 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4888 int need_pc
, struct dwarf2_cu
*cu
)
4890 if (pdi
->tag
== DW_TAG_subprogram
)
4892 if (pdi
->has_pc_info
)
4894 if (pdi
->lowpc
< *lowpc
)
4895 *lowpc
= pdi
->lowpc
;
4896 if (pdi
->highpc
> *highpc
)
4897 *highpc
= pdi
->highpc
;
4901 struct objfile
*objfile
= cu
->objfile
;
4903 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4904 SECT_OFF_TEXT (objfile
));
4905 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4906 pdi
->lowpc
+ baseaddr
,
4907 pdi
->highpc
- 1 + baseaddr
,
4908 cu
->per_cu
->v
.psymtab
);
4912 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
4914 if (!pdi
->is_declaration
)
4915 /* Ignore subprogram DIEs that do not have a name, they are
4916 illegal. Do not emit a complaint at this point, we will
4917 do so when we convert this psymtab into a symtab. */
4919 add_partial_symbol (pdi
, cu
);
4923 if (! pdi
->has_children
)
4926 if (cu
->language
== language_ada
)
4928 pdi
= pdi
->die_child
;
4931 fixup_partial_die (pdi
, cu
);
4932 if (pdi
->tag
== DW_TAG_subprogram
4933 || pdi
->tag
== DW_TAG_lexical_block
)
4934 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4935 pdi
= pdi
->die_sibling
;
4940 /* Read a partial die corresponding to an enumeration type. */
4943 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4944 struct dwarf2_cu
*cu
)
4946 struct partial_die_info
*pdi
;
4948 if (enum_pdi
->name
!= NULL
)
4949 add_partial_symbol (enum_pdi
, cu
);
4951 pdi
= enum_pdi
->die_child
;
4954 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4955 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4957 add_partial_symbol (pdi
, cu
);
4958 pdi
= pdi
->die_sibling
;
4962 /* Return the initial uleb128 in the die at INFO_PTR. */
4965 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4967 unsigned int bytes_read
;
4969 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4972 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4973 Return the corresponding abbrev, or NULL if the number is zero (indicating
4974 an empty DIE). In either case *BYTES_READ will be set to the length of
4975 the initial number. */
4977 static struct abbrev_info
*
4978 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4979 struct dwarf2_cu
*cu
)
4981 bfd
*abfd
= cu
->objfile
->obfd
;
4982 unsigned int abbrev_number
;
4983 struct abbrev_info
*abbrev
;
4985 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4987 if (abbrev_number
== 0)
4990 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4993 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4994 abbrev_number
, bfd_get_filename (abfd
));
5000 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5001 Returns a pointer to the end of a series of DIEs, terminated by an empty
5002 DIE. Any children of the skipped DIEs will also be skipped. */
5005 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
5007 struct dwarf2_cu
*cu
= reader
->cu
;
5008 struct abbrev_info
*abbrev
;
5009 unsigned int bytes_read
;
5013 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5015 return info_ptr
+ bytes_read
;
5017 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
5021 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5022 INFO_PTR should point just after the initial uleb128 of a DIE, and the
5023 abbrev corresponding to that skipped uleb128 should be passed in
5024 ABBREV. Returns a pointer to this DIE's sibling, skipping any
5028 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
5029 struct abbrev_info
*abbrev
)
5031 unsigned int bytes_read
;
5032 struct attribute attr
;
5033 bfd
*abfd
= reader
->abfd
;
5034 struct dwarf2_cu
*cu
= reader
->cu
;
5035 gdb_byte
*buffer
= reader
->buffer
;
5036 unsigned int form
, i
;
5038 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
5040 /* The only abbrev we care about is DW_AT_sibling. */
5041 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
5043 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
5044 if (attr
.form
== DW_FORM_ref_addr
)
5045 complaint (&symfile_complaints
,
5046 _("ignoring absolute DW_AT_sibling"));
5048 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
5051 /* If it isn't DW_AT_sibling, skip this attribute. */
5052 form
= abbrev
->attrs
[i
].form
;
5056 case DW_FORM_ref_addr
:
5057 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
5058 and later it is offset sized. */
5059 if (cu
->header
.version
== 2)
5060 info_ptr
+= cu
->header
.addr_size
;
5062 info_ptr
+= cu
->header
.offset_size
;
5065 info_ptr
+= cu
->header
.addr_size
;
5072 case DW_FORM_flag_present
:
5084 case DW_FORM_ref_sig8
:
5087 case DW_FORM_string
:
5088 read_direct_string (abfd
, info_ptr
, &bytes_read
);
5089 info_ptr
+= bytes_read
;
5091 case DW_FORM_sec_offset
:
5093 info_ptr
+= cu
->header
.offset_size
;
5095 case DW_FORM_exprloc
:
5097 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5098 info_ptr
+= bytes_read
;
5100 case DW_FORM_block1
:
5101 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
5103 case DW_FORM_block2
:
5104 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
5106 case DW_FORM_block4
:
5107 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
5111 case DW_FORM_ref_udata
:
5112 case DW_FORM_GNU_addr_index
:
5113 case DW_FORM_GNU_str_index
:
5114 info_ptr
= skip_leb128 (abfd
, info_ptr
);
5116 case DW_FORM_indirect
:
5117 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5118 info_ptr
+= bytes_read
;
5119 /* We need to continue parsing from here, so just go back to
5121 goto skip_attribute
;
5124 error (_("Dwarf Error: Cannot handle %s "
5125 "in DWARF reader [in module %s]"),
5126 dwarf_form_name (form
),
5127 bfd_get_filename (abfd
));
5131 if (abbrev
->has_children
)
5132 return skip_children (reader
, info_ptr
);
5137 /* Locate ORIG_PDI's sibling.
5138 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
5141 locate_pdi_sibling (const struct die_reader_specs
*reader
,
5142 struct partial_die_info
*orig_pdi
,
5145 /* Do we know the sibling already? */
5147 if (orig_pdi
->sibling
)
5148 return orig_pdi
->sibling
;
5150 /* Are there any children to deal with? */
5152 if (!orig_pdi
->has_children
)
5155 /* Skip the children the long way. */
5157 return skip_children (reader
, info_ptr
);
5160 /* Expand this partial symbol table into a full symbol table. */
5163 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
5169 warning (_("bug: psymtab for %s is already read in."),
5176 printf_filtered (_("Reading in symbols for %s..."),
5178 gdb_flush (gdb_stdout
);
5181 /* Restore our global data. */
5182 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
5183 dwarf2_objfile_data_key
);
5185 /* If this psymtab is constructed from a debug-only objfile, the
5186 has_section_at_zero flag will not necessarily be correct. We
5187 can get the correct value for this flag by looking at the data
5188 associated with the (presumably stripped) associated objfile. */
5189 if (pst
->objfile
->separate_debug_objfile_backlink
)
5191 struct dwarf2_per_objfile
*dpo_backlink
5192 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
5193 dwarf2_objfile_data_key
);
5195 dwarf2_per_objfile
->has_section_at_zero
5196 = dpo_backlink
->has_section_at_zero
;
5199 dwarf2_per_objfile
->reading_partial_symbols
= 0;
5201 psymtab_to_symtab_1 (pst
);
5203 /* Finish up the debug error message. */
5205 printf_filtered (_("done.\n"));
5209 process_cu_includes ();
5212 /* Reading in full CUs. */
5214 /* Add PER_CU to the queue. */
5217 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
5218 enum language pretend_language
)
5220 struct dwarf2_queue_item
*item
;
5223 item
= xmalloc (sizeof (*item
));
5224 item
->per_cu
= per_cu
;
5225 item
->pretend_language
= pretend_language
;
5228 if (dwarf2_queue
== NULL
)
5229 dwarf2_queue
= item
;
5231 dwarf2_queue_tail
->next
= item
;
5233 dwarf2_queue_tail
= item
;
5236 /* Process the queue. */
5239 process_queue (void)
5241 struct dwarf2_queue_item
*item
, *next_item
;
5243 /* The queue starts out with one item, but following a DIE reference
5244 may load a new CU, adding it to the end of the queue. */
5245 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
5247 if (dwarf2_per_objfile
->using_index
5248 ? !item
->per_cu
->v
.quick
->symtab
5249 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
5250 process_full_comp_unit (item
->per_cu
, item
->pretend_language
);
5252 item
->per_cu
->queued
= 0;
5253 next_item
= item
->next
;
5257 dwarf2_queue_tail
= NULL
;
5260 /* Free all allocated queue entries. This function only releases anything if
5261 an error was thrown; if the queue was processed then it would have been
5262 freed as we went along. */
5265 dwarf2_release_queue (void *dummy
)
5267 struct dwarf2_queue_item
*item
, *last
;
5269 item
= dwarf2_queue
;
5272 /* Anything still marked queued is likely to be in an
5273 inconsistent state, so discard it. */
5274 if (item
->per_cu
->queued
)
5276 if (item
->per_cu
->cu
!= NULL
)
5277 free_one_cached_comp_unit (item
->per_cu
);
5278 item
->per_cu
->queued
= 0;
5286 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
5289 /* Read in full symbols for PST, and anything it depends on. */
5292 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
5294 struct dwarf2_per_cu_data
*per_cu
;
5295 struct cleanup
*back_to
;
5301 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
5302 if (!pst
->dependencies
[i
]->readin
5303 && pst
->dependencies
[i
]->user
== NULL
)
5305 /* Inform about additional files that need to be read in. */
5308 /* FIXME: i18n: Need to make this a single string. */
5309 fputs_filtered (" ", gdb_stdout
);
5311 fputs_filtered ("and ", gdb_stdout
);
5313 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
5314 wrap_here (""); /* Flush output. */
5315 gdb_flush (gdb_stdout
);
5317 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
5320 per_cu
= pst
->read_symtab_private
;
5324 /* It's an include file, no symbols to read for it.
5325 Everything is in the parent symtab. */
5330 dw2_do_instantiate_symtab (per_cu
);
5333 /* Trivial hash function for die_info: the hash value of a DIE
5334 is its offset in .debug_info for this objfile. */
5337 die_hash (const void *item
)
5339 const struct die_info
*die
= item
;
5341 return die
->offset
.sect_off
;
5344 /* Trivial comparison function for die_info structures: two DIEs
5345 are equal if they have the same offset. */
5348 die_eq (const void *item_lhs
, const void *item_rhs
)
5350 const struct die_info
*die_lhs
= item_lhs
;
5351 const struct die_info
*die_rhs
= item_rhs
;
5353 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
5356 /* die_reader_func for load_full_comp_unit.
5357 This is identical to read_signatured_type_reader,
5358 but is kept separate for now. */
5361 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
5363 struct die_info
*comp_unit_die
,
5367 struct dwarf2_cu
*cu
= reader
->cu
;
5368 struct attribute
*attr
;
5369 enum language
*language_ptr
= data
;
5371 gdb_assert (cu
->die_hash
== NULL
);
5373 htab_create_alloc_ex (cu
->header
.length
/ 12,
5377 &cu
->comp_unit_obstack
,
5378 hashtab_obstack_allocate
,
5379 dummy_obstack_deallocate
);
5382 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
5383 &info_ptr
, comp_unit_die
);
5384 cu
->dies
= comp_unit_die
;
5385 /* comp_unit_die is not stored in die_hash, no need. */
5387 /* We try not to read any attributes in this function, because not
5388 all CUs needed for references have been loaded yet, and symbol
5389 table processing isn't initialized. But we have to set the CU language,
5390 or we won't be able to build types correctly.
5391 Similarly, if we do not read the producer, we can not apply
5392 producer-specific interpretation. */
5393 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
5396 /* Load the DIEs associated with PER_CU into memory. */
5399 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
5400 enum language pretend_language
)
5402 gdb_assert (! this_cu
->is_debug_types
);
5404 init_cutu_and_read_dies (this_cu
, 1, 1, load_full_comp_unit_reader
,
5408 /* Add a DIE to the delayed physname list. */
5411 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
5412 const char *name
, struct die_info
*die
,
5413 struct dwarf2_cu
*cu
)
5415 struct delayed_method_info mi
;
5417 mi
.fnfield_index
= fnfield_index
;
5421 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
5424 /* A cleanup for freeing the delayed method list. */
5427 free_delayed_list (void *ptr
)
5429 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
5430 if (cu
->method_list
!= NULL
)
5432 VEC_free (delayed_method_info
, cu
->method_list
);
5433 cu
->method_list
= NULL
;
5437 /* Compute the physnames of any methods on the CU's method list.
5439 The computation of method physnames is delayed in order to avoid the
5440 (bad) condition that one of the method's formal parameters is of an as yet
5444 compute_delayed_physnames (struct dwarf2_cu
*cu
)
5447 struct delayed_method_info
*mi
;
5448 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
5450 const char *physname
;
5451 struct fn_fieldlist
*fn_flp
5452 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
5453 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
5454 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
5458 /* Go objects should be embedded in a DW_TAG_module DIE,
5459 and it's not clear if/how imported objects will appear.
5460 To keep Go support simple until that's worked out,
5461 go back through what we've read and create something usable.
5462 We could do this while processing each DIE, and feels kinda cleaner,
5463 but that way is more invasive.
5464 This is to, for example, allow the user to type "p var" or "b main"
5465 without having to specify the package name, and allow lookups
5466 of module.object to work in contexts that use the expression
5470 fixup_go_packaging (struct dwarf2_cu
*cu
)
5472 char *package_name
= NULL
;
5473 struct pending
*list
;
5476 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
5478 for (i
= 0; i
< list
->nsyms
; ++i
)
5480 struct symbol
*sym
= list
->symbol
[i
];
5482 if (SYMBOL_LANGUAGE (sym
) == language_go
5483 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
5485 char *this_package_name
= go_symbol_package_name (sym
);
5487 if (this_package_name
== NULL
)
5489 if (package_name
== NULL
)
5490 package_name
= this_package_name
;
5493 if (strcmp (package_name
, this_package_name
) != 0)
5494 complaint (&symfile_complaints
,
5495 _("Symtab %s has objects from two different Go packages: %s and %s"),
5496 (sym
->symtab
&& sym
->symtab
->filename
5497 ? sym
->symtab
->filename
5498 : cu
->objfile
->name
),
5499 this_package_name
, package_name
);
5500 xfree (this_package_name
);
5506 if (package_name
!= NULL
)
5508 struct objfile
*objfile
= cu
->objfile
;
5509 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
5510 package_name
, objfile
);
5513 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5515 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
5516 SYMBOL_SET_LANGUAGE (sym
, language_go
);
5517 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
5518 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
5519 e.g., "main" finds the "main" module and not C's main(). */
5520 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5521 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5522 SYMBOL_TYPE (sym
) = type
;
5524 add_symbol_to_list (sym
, &global_symbols
);
5526 xfree (package_name
);
5530 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
5532 /* Return the symtab for PER_CU. This works properly regardless of
5533 whether we're using the index or psymtabs. */
5535 static struct symtab
*
5536 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
5538 return (dwarf2_per_objfile
->using_index
5539 ? per_cu
->v
.quick
->symtab
5540 : per_cu
->v
.psymtab
->symtab
);
5543 /* A helper function for computing the list of all symbol tables
5544 included by PER_CU. */
5547 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
5548 htab_t all_children
,
5549 struct dwarf2_per_cu_data
*per_cu
)
5553 struct dwarf2_per_cu_data
*iter
;
5555 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
5558 /* This inclusion and its children have been processed. */
5563 /* Only add a CU if it has a symbol table. */
5564 if (get_symtab (per_cu
) != NULL
)
5565 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
5568 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
5570 recursively_compute_inclusions (result
, all_children
, iter
);
5573 /* Compute the symtab 'includes' fields for the symtab related to
5577 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
5579 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
5582 struct dwarf2_per_cu_data
*iter
;
5583 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
5584 htab_t all_children
;
5585 struct symtab
*symtab
= get_symtab (per_cu
);
5587 /* If we don't have a symtab, we can just skip this case. */
5591 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
5592 NULL
, xcalloc
, xfree
);
5595 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
5598 recursively_compute_inclusions (&result_children
, all_children
, iter
);
5600 /* Now we have a transitive closure of all the included CUs, so
5601 we can convert it to a list of symtabs. */
5602 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
5604 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
5605 (len
+ 1) * sizeof (struct symtab
*));
5607 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
5609 symtab
->includes
[ix
] = get_symtab (iter
);
5610 symtab
->includes
[len
] = NULL
;
5612 VEC_free (dwarf2_per_cu_ptr
, result_children
);
5613 htab_delete (all_children
);
5617 /* Compute the 'includes' field for the symtabs of all the CUs we just
5621 process_cu_includes (void)
5624 struct dwarf2_per_cu_data
*iter
;
5627 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
5630 compute_symtab_includes (iter
);
5632 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
5635 /* Generate full symbol information for PER_CU, whose DIEs have
5636 already been loaded into memory. */
5639 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
5640 enum language pretend_language
)
5642 struct dwarf2_cu
*cu
= per_cu
->cu
;
5643 struct objfile
*objfile
= per_cu
->objfile
;
5644 CORE_ADDR lowpc
, highpc
;
5645 struct symtab
*symtab
;
5646 struct cleanup
*back_to
, *delayed_list_cleanup
;
5649 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5652 back_to
= make_cleanup (really_free_pendings
, NULL
);
5653 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
5655 cu
->list_in_scope
= &file_symbols
;
5657 cu
->language
= pretend_language
;
5658 cu
->language_defn
= language_def (cu
->language
);
5660 /* Do line number decoding in read_file_scope () */
5661 process_die (cu
->dies
, cu
);
5663 /* For now fudge the Go package. */
5664 if (cu
->language
== language_go
)
5665 fixup_go_packaging (cu
);
5667 /* Now that we have processed all the DIEs in the CU, all the types
5668 should be complete, and it should now be safe to compute all of the
5670 compute_delayed_physnames (cu
);
5671 do_cleanups (delayed_list_cleanup
);
5673 /* Some compilers don't define a DW_AT_high_pc attribute for the
5674 compilation unit. If the DW_AT_high_pc is missing, synthesize
5675 it, by scanning the DIE's below the compilation unit. */
5676 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
5678 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
5682 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
5684 /* Set symtab language to language from DW_AT_language. If the
5685 compilation is from a C file generated by language preprocessors, do
5686 not set the language if it was already deduced by start_subfile. */
5687 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
5688 symtab
->language
= cu
->language
;
5690 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
5691 produce DW_AT_location with location lists but it can be possibly
5692 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
5693 there were bugs in prologue debug info, fixed later in GCC-4.5
5694 by "unwind info for epilogues" patch (which is not directly related).
5696 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
5697 needed, it would be wrong due to missing DW_AT_producer there.
5699 Still one can confuse GDB by using non-standard GCC compilation
5700 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
5702 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
5703 symtab
->locations_valid
= 1;
5705 if (gcc_4_minor
>= 5)
5706 symtab
->epilogue_unwind_valid
= 1;
5708 symtab
->call_site_htab
= cu
->call_site_htab
;
5711 if (dwarf2_per_objfile
->using_index
)
5712 per_cu
->v
.quick
->symtab
= symtab
;
5715 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5716 pst
->symtab
= symtab
;
5720 /* Push it for inclusion processing later. */
5721 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
5723 do_cleanups (back_to
);
5726 /* Process an imported unit DIE. */
5729 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5731 struct attribute
*attr
;
5733 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5736 struct dwarf2_per_cu_data
*per_cu
;
5737 struct symtab
*imported_symtab
;
5740 offset
= dwarf2_get_ref_die_offset (attr
);
5741 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5743 /* Queue the unit, if needed. */
5744 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
5745 load_full_comp_unit (per_cu
, cu
->language
);
5747 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
5752 /* Process a die and its children. */
5755 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5759 case DW_TAG_padding
:
5761 case DW_TAG_compile_unit
:
5762 case DW_TAG_partial_unit
:
5763 read_file_scope (die
, cu
);
5765 case DW_TAG_type_unit
:
5766 read_type_unit_scope (die
, cu
);
5768 case DW_TAG_subprogram
:
5769 case DW_TAG_inlined_subroutine
:
5770 read_func_scope (die
, cu
);
5772 case DW_TAG_lexical_block
:
5773 case DW_TAG_try_block
:
5774 case DW_TAG_catch_block
:
5775 read_lexical_block_scope (die
, cu
);
5777 case DW_TAG_GNU_call_site
:
5778 read_call_site_scope (die
, cu
);
5780 case DW_TAG_class_type
:
5781 case DW_TAG_interface_type
:
5782 case DW_TAG_structure_type
:
5783 case DW_TAG_union_type
:
5784 process_structure_scope (die
, cu
);
5786 case DW_TAG_enumeration_type
:
5787 process_enumeration_scope (die
, cu
);
5790 /* These dies have a type, but processing them does not create
5791 a symbol or recurse to process the children. Therefore we can
5792 read them on-demand through read_type_die. */
5793 case DW_TAG_subroutine_type
:
5794 case DW_TAG_set_type
:
5795 case DW_TAG_array_type
:
5796 case DW_TAG_pointer_type
:
5797 case DW_TAG_ptr_to_member_type
:
5798 case DW_TAG_reference_type
:
5799 case DW_TAG_string_type
:
5802 case DW_TAG_base_type
:
5803 case DW_TAG_subrange_type
:
5804 case DW_TAG_typedef
:
5805 /* Add a typedef symbol for the type definition, if it has a
5807 new_symbol (die
, read_type_die (die
, cu
), cu
);
5809 case DW_TAG_common_block
:
5810 read_common_block (die
, cu
);
5812 case DW_TAG_common_inclusion
:
5814 case DW_TAG_namespace
:
5815 processing_has_namespace_info
= 1;
5816 read_namespace (die
, cu
);
5819 processing_has_namespace_info
= 1;
5820 read_module (die
, cu
);
5822 case DW_TAG_imported_declaration
:
5823 case DW_TAG_imported_module
:
5824 processing_has_namespace_info
= 1;
5825 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
5826 || cu
->language
!= language_fortran
))
5827 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
5828 dwarf_tag_name (die
->tag
));
5829 read_import_statement (die
, cu
);
5832 case DW_TAG_imported_unit
:
5833 process_imported_unit_die (die
, cu
);
5837 new_symbol (die
, NULL
, cu
);
5842 /* A helper function for dwarf2_compute_name which determines whether DIE
5843 needs to have the name of the scope prepended to the name listed in the
5847 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5849 struct attribute
*attr
;
5853 case DW_TAG_namespace
:
5854 case DW_TAG_typedef
:
5855 case DW_TAG_class_type
:
5856 case DW_TAG_interface_type
:
5857 case DW_TAG_structure_type
:
5858 case DW_TAG_union_type
:
5859 case DW_TAG_enumeration_type
:
5860 case DW_TAG_enumerator
:
5861 case DW_TAG_subprogram
:
5865 case DW_TAG_variable
:
5866 case DW_TAG_constant
:
5867 /* We only need to prefix "globally" visible variables. These include
5868 any variable marked with DW_AT_external or any variable that
5869 lives in a namespace. [Variables in anonymous namespaces
5870 require prefixing, but they are not DW_AT_external.] */
5872 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
5874 struct dwarf2_cu
*spec_cu
= cu
;
5876 return die_needs_namespace (die_specification (die
, &spec_cu
),
5880 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5881 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
5882 && die
->parent
->tag
!= DW_TAG_module
)
5884 /* A variable in a lexical block of some kind does not need a
5885 namespace, even though in C++ such variables may be external
5886 and have a mangled name. */
5887 if (die
->parent
->tag
== DW_TAG_lexical_block
5888 || die
->parent
->tag
== DW_TAG_try_block
5889 || die
->parent
->tag
== DW_TAG_catch_block
5890 || die
->parent
->tag
== DW_TAG_subprogram
)
5899 /* Retrieve the last character from a mem_file. */
5902 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
5904 char *last_char_p
= (char *) object
;
5907 *last_char_p
= buffer
[length
- 1];
5910 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5911 compute the physname for the object, which include a method's:
5912 - formal parameters (C++/Java),
5913 - receiver type (Go),
5914 - return type (Java).
5916 The term "physname" is a bit confusing.
5917 For C++, for example, it is the demangled name.
5918 For Go, for example, it's the mangled name.
5920 For Ada, return the DIE's linkage name rather than the fully qualified
5921 name. PHYSNAME is ignored..
5923 The result is allocated on the objfile_obstack and canonicalized. */
5926 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5929 struct objfile
*objfile
= cu
->objfile
;
5932 name
= dwarf2_name (die
, cu
);
5934 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5935 compute it by typename_concat inside GDB. */
5936 if (cu
->language
== language_ada
5937 || (cu
->language
== language_fortran
&& physname
))
5939 /* For Ada unit, we prefer the linkage name over the name, as
5940 the former contains the exported name, which the user expects
5941 to be able to reference. Ideally, we want the user to be able
5942 to reference this entity using either natural or linkage name,
5943 but we haven't started looking at this enhancement yet. */
5944 struct attribute
*attr
;
5946 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5948 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5949 if (attr
&& DW_STRING (attr
))
5950 return DW_STRING (attr
);
5953 /* These are the only languages we know how to qualify names in. */
5955 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5956 || cu
->language
== language_fortran
))
5958 if (die_needs_namespace (die
, cu
))
5962 struct ui_file
*buf
;
5964 prefix
= determine_prefix (die
, cu
);
5965 buf
= mem_fileopen ();
5966 if (*prefix
!= '\0')
5968 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5971 fputs_unfiltered (prefixed_name
, buf
);
5972 xfree (prefixed_name
);
5975 fputs_unfiltered (name
, buf
);
5977 /* Template parameters may be specified in the DIE's DW_AT_name, or
5978 as children with DW_TAG_template_type_param or
5979 DW_TAG_value_type_param. If the latter, add them to the name
5980 here. If the name already has template parameters, then
5981 skip this step; some versions of GCC emit both, and
5982 it is more efficient to use the pre-computed name.
5984 Something to keep in mind about this process: it is very
5985 unlikely, or in some cases downright impossible, to produce
5986 something that will match the mangled name of a function.
5987 If the definition of the function has the same debug info,
5988 we should be able to match up with it anyway. But fallbacks
5989 using the minimal symbol, for instance to find a method
5990 implemented in a stripped copy of libstdc++, will not work.
5991 If we do not have debug info for the definition, we will have to
5992 match them up some other way.
5994 When we do name matching there is a related problem with function
5995 templates; two instantiated function templates are allowed to
5996 differ only by their return types, which we do not add here. */
5998 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
6000 struct attribute
*attr
;
6001 struct die_info
*child
;
6004 die
->building_fullname
= 1;
6006 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
6011 struct dwarf2_locexpr_baton
*baton
;
6014 if (child
->tag
!= DW_TAG_template_type_param
6015 && child
->tag
!= DW_TAG_template_value_param
)
6020 fputs_unfiltered ("<", buf
);
6024 fputs_unfiltered (", ", buf
);
6026 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
6029 complaint (&symfile_complaints
,
6030 _("template parameter missing DW_AT_type"));
6031 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
6034 type
= die_type (child
, cu
);
6036 if (child
->tag
== DW_TAG_template_type_param
)
6038 c_print_type (type
, "", buf
, -1, 0);
6042 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
6045 complaint (&symfile_complaints
,
6046 _("template parameter missing "
6047 "DW_AT_const_value"));
6048 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
6052 dwarf2_const_value_attr (attr
, type
, name
,
6053 &cu
->comp_unit_obstack
, cu
,
6054 &value
, &bytes
, &baton
);
6056 if (TYPE_NOSIGN (type
))
6057 /* GDB prints characters as NUMBER 'CHAR'. If that's
6058 changed, this can use value_print instead. */
6059 c_printchar (value
, type
, buf
);
6062 struct value_print_options opts
;
6065 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
6069 else if (bytes
!= NULL
)
6071 v
= allocate_value (type
);
6072 memcpy (value_contents_writeable (v
), bytes
,
6073 TYPE_LENGTH (type
));
6076 v
= value_from_longest (type
, value
);
6078 /* Specify decimal so that we do not depend on
6080 get_formatted_print_options (&opts
, 'd');
6082 value_print (v
, buf
, &opts
);
6088 die
->building_fullname
= 0;
6092 /* Close the argument list, with a space if necessary
6093 (nested templates). */
6094 char last_char
= '\0';
6095 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
6096 if (last_char
== '>')
6097 fputs_unfiltered (" >", buf
);
6099 fputs_unfiltered (">", buf
);
6103 /* For Java and C++ methods, append formal parameter type
6104 information, if PHYSNAME. */
6106 if (physname
&& die
->tag
== DW_TAG_subprogram
6107 && (cu
->language
== language_cplus
6108 || cu
->language
== language_java
))
6110 struct type
*type
= read_type_die (die
, cu
);
6112 c_type_print_args (type
, buf
, 1, cu
->language
);
6114 if (cu
->language
== language_java
)
6116 /* For java, we must append the return type to method
6118 if (die
->tag
== DW_TAG_subprogram
)
6119 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
6122 else if (cu
->language
== language_cplus
)
6124 /* Assume that an artificial first parameter is
6125 "this", but do not crash if it is not. RealView
6126 marks unnamed (and thus unused) parameters as
6127 artificial; there is no way to differentiate
6129 if (TYPE_NFIELDS (type
) > 0
6130 && TYPE_FIELD_ARTIFICIAL (type
, 0)
6131 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
6132 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
6134 fputs_unfiltered (" const", buf
);
6138 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
6140 ui_file_delete (buf
);
6142 if (cu
->language
== language_cplus
)
6145 = dwarf2_canonicalize_name (name
, cu
,
6146 &objfile
->objfile_obstack
);
6157 /* Return the fully qualified name of DIE, based on its DW_AT_name.
6158 If scope qualifiers are appropriate they will be added. The result
6159 will be allocated on the objfile_obstack, or NULL if the DIE does
6160 not have a name. NAME may either be from a previous call to
6161 dwarf2_name or NULL.
6163 The output string will be canonicalized (if C++/Java). */
6166 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
6168 return dwarf2_compute_name (name
, die
, cu
, 0);
6171 /* Construct a physname for the given DIE in CU. NAME may either be
6172 from a previous call to dwarf2_name or NULL. The result will be
6173 allocated on the objfile_objstack or NULL if the DIE does not have a
6176 The output string will be canonicalized (if C++/Java). */
6179 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
6181 struct objfile
*objfile
= cu
->objfile
;
6182 struct attribute
*attr
;
6183 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
6184 struct cleanup
*back_to
;
6187 /* In this case dwarf2_compute_name is just a shortcut not building anything
6189 if (!die_needs_namespace (die
, cu
))
6190 return dwarf2_compute_name (name
, die
, cu
, 1);
6192 back_to
= make_cleanup (null_cleanup
, NULL
);
6194 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6196 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6198 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
6200 if (attr
&& DW_STRING (attr
))
6204 mangled
= DW_STRING (attr
);
6206 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
6207 type. It is easier for GDB users to search for such functions as
6208 `name(params)' than `long name(params)'. In such case the minimal
6209 symbol names do not match the full symbol names but for template
6210 functions there is never a need to look up their definition from their
6211 declaration so the only disadvantage remains the minimal symbol
6212 variant `long name(params)' does not have the proper inferior type.
6215 if (cu
->language
== language_go
)
6217 /* This is a lie, but we already lie to the caller new_symbol_full.
6218 new_symbol_full assumes we return the mangled name.
6219 This just undoes that lie until things are cleaned up. */
6224 demangled
= cplus_demangle (mangled
,
6225 (DMGL_PARAMS
| DMGL_ANSI
6226 | (cu
->language
== language_java
6227 ? DMGL_JAVA
| DMGL_RET_POSTFIX
6232 make_cleanup (xfree
, demangled
);
6242 if (canon
== NULL
|| check_physname
)
6244 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
6246 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
6248 /* It may not mean a bug in GDB. The compiler could also
6249 compute DW_AT_linkage_name incorrectly. But in such case
6250 GDB would need to be bug-to-bug compatible. */
6252 complaint (&symfile_complaints
,
6253 _("Computed physname <%s> does not match demangled <%s> "
6254 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
6255 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
6257 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
6258 is available here - over computed PHYSNAME. It is safer
6259 against both buggy GDB and buggy compilers. */
6273 retval
= obsavestring (retval
, strlen (retval
),
6274 &objfile
->objfile_obstack
);
6276 do_cleanups (back_to
);
6280 /* Read the import statement specified by the given die and record it. */
6283 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
6285 struct objfile
*objfile
= cu
->objfile
;
6286 struct attribute
*import_attr
;
6287 struct die_info
*imported_die
, *child_die
;
6288 struct dwarf2_cu
*imported_cu
;
6289 const char *imported_name
;
6290 const char *imported_name_prefix
;
6291 const char *canonical_name
;
6292 const char *import_alias
;
6293 const char *imported_declaration
= NULL
;
6294 const char *import_prefix
;
6295 VEC (const_char_ptr
) *excludes
= NULL
;
6296 struct cleanup
*cleanups
;
6300 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6301 if (import_attr
== NULL
)
6303 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6304 dwarf_tag_name (die
->tag
));
6309 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
6310 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6311 if (imported_name
== NULL
)
6313 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
6315 The import in the following code:
6329 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
6330 <52> DW_AT_decl_file : 1
6331 <53> DW_AT_decl_line : 6
6332 <54> DW_AT_import : <0x75>
6333 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
6335 <5b> DW_AT_decl_file : 1
6336 <5c> DW_AT_decl_line : 2
6337 <5d> DW_AT_type : <0x6e>
6339 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
6340 <76> DW_AT_byte_size : 4
6341 <77> DW_AT_encoding : 5 (signed)
6343 imports the wrong die ( 0x75 instead of 0x58 ).
6344 This case will be ignored until the gcc bug is fixed. */
6348 /* Figure out the local name after import. */
6349 import_alias
= dwarf2_name (die
, cu
);
6351 /* Figure out where the statement is being imported to. */
6352 import_prefix
= determine_prefix (die
, cu
);
6354 /* Figure out what the scope of the imported die is and prepend it
6355 to the name of the imported die. */
6356 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
6358 if (imported_die
->tag
!= DW_TAG_namespace
6359 && imported_die
->tag
!= DW_TAG_module
)
6361 imported_declaration
= imported_name
;
6362 canonical_name
= imported_name_prefix
;
6364 else if (strlen (imported_name_prefix
) > 0)
6366 temp
= alloca (strlen (imported_name_prefix
)
6367 + 2 + strlen (imported_name
) + 1);
6368 strcpy (temp
, imported_name_prefix
);
6369 strcat (temp
, "::");
6370 strcat (temp
, imported_name
);
6371 canonical_name
= temp
;
6374 canonical_name
= imported_name
;
6376 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
6378 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
6379 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6380 child_die
= sibling_die (child_die
))
6382 /* DWARF-4: A Fortran use statement with a “rename list” may be
6383 represented by an imported module entry with an import attribute
6384 referring to the module and owned entries corresponding to those
6385 entities that are renamed as part of being imported. */
6387 if (child_die
->tag
!= DW_TAG_imported_declaration
)
6389 complaint (&symfile_complaints
,
6390 _("child DW_TAG_imported_declaration expected "
6391 "- DIE at 0x%x [in module %s]"),
6392 child_die
->offset
.sect_off
, objfile
->name
);
6396 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
6397 if (import_attr
== NULL
)
6399 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6400 dwarf_tag_name (child_die
->tag
));
6405 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
6407 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6408 if (imported_name
== NULL
)
6410 complaint (&symfile_complaints
,
6411 _("child DW_TAG_imported_declaration has unknown "
6412 "imported name - DIE at 0x%x [in module %s]"),
6413 child_die
->offset
.sect_off
, objfile
->name
);
6417 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
6419 process_die (child_die
, cu
);
6422 cp_add_using_directive (import_prefix
,
6425 imported_declaration
,
6427 &objfile
->objfile_obstack
);
6429 do_cleanups (cleanups
);
6432 /* Cleanup function for read_file_scope. */
6435 free_cu_line_header (void *arg
)
6437 struct dwarf2_cu
*cu
= arg
;
6439 free_line_header (cu
->line_header
);
6440 cu
->line_header
= NULL
;
6444 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
6445 char **name
, char **comp_dir
)
6447 struct attribute
*attr
;
6452 /* Find the filename. Do not use dwarf2_name here, since the filename
6453 is not a source language identifier. */
6454 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6457 *name
= DW_STRING (attr
);
6460 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6462 *comp_dir
= DW_STRING (attr
);
6463 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
6465 *comp_dir
= ldirname (*name
);
6466 if (*comp_dir
!= NULL
)
6467 make_cleanup (xfree
, *comp_dir
);
6469 if (*comp_dir
!= NULL
)
6471 /* Irix 6.2 native cc prepends <machine>.: to the compilation
6472 directory, get rid of it. */
6473 char *cp
= strchr (*comp_dir
, ':');
6475 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
6480 *name
= "<unknown>";
6483 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
6484 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
6485 COMP_DIR is the compilation directory.
6486 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
6489 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
6490 const char *comp_dir
, int want_line_info
)
6492 struct attribute
*attr
;
6494 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6497 unsigned int line_offset
= DW_UNSND (attr
);
6498 struct line_header
*line_header
6499 = dwarf_decode_line_header (line_offset
, cu
);
6503 cu
->line_header
= line_header
;
6504 make_cleanup (free_cu_line_header
, cu
);
6505 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
6510 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
6513 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6515 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6516 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6517 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
6518 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
6519 struct attribute
*attr
;
6521 char *comp_dir
= NULL
;
6522 struct die_info
*child_die
;
6523 bfd
*abfd
= objfile
->obfd
;
6526 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6528 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
6530 /* If we didn't find a lowpc, set it to highpc to avoid complaints
6531 from finish_block. */
6532 if (lowpc
== ((CORE_ADDR
) -1))
6537 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
6539 prepare_one_comp_unit (cu
, die
, cu
->language
);
6541 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
6542 standardised yet. As a workaround for the language detection we fall
6543 back to the DW_AT_producer string. */
6544 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
6545 cu
->language
= language_opencl
;
6547 /* Similar hack for Go. */
6548 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
6549 set_cu_language (DW_LANG_Go
, cu
);
6551 /* We assume that we're processing GCC output. */
6552 processing_gcc_compilation
= 2;
6554 processing_has_namespace_info
= 0;
6556 start_symtab (name
, comp_dir
, lowpc
);
6557 record_debugformat ("DWARF 2");
6558 record_producer (cu
->producer
);
6560 /* Decode line number information if present. We do this before
6561 processing child DIEs, so that the line header table is available
6562 for DW_AT_decl_file. */
6563 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
6565 /* Process all dies in compilation unit. */
6566 if (die
->child
!= NULL
)
6568 child_die
= die
->child
;
6569 while (child_die
&& child_die
->tag
)
6571 process_die (child_die
, cu
);
6572 child_die
= sibling_die (child_die
);
6576 /* Decode macro information, if present. Dwarf 2 macro information
6577 refers to information in the line number info statement program
6578 header, so we can only read it if we've read the header
6580 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
6581 if (attr
&& cu
->line_header
)
6583 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
6584 complaint (&symfile_complaints
,
6585 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
6587 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
6589 &dwarf2_per_objfile
->macro
, 1,
6594 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
6595 if (attr
&& cu
->line_header
)
6597 unsigned int macro_offset
= DW_UNSND (attr
);
6599 dwarf_decode_macros (cu
->line_header
, macro_offset
,
6601 &dwarf2_per_objfile
->macinfo
, 0,
6606 do_cleanups (back_to
);
6609 /* Process DW_TAG_type_unit.
6610 For TUs we want to skip the first top level sibling if it's not the
6611 actual type being defined by this TU. In this case the first top
6612 level sibling is there to provide context only. */
6615 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6617 struct objfile
*objfile
= cu
->objfile
;
6618 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6620 struct attribute
*attr
;
6622 char *comp_dir
= NULL
;
6623 struct die_info
*child_die
;
6624 bfd
*abfd
= objfile
->obfd
;
6626 /* start_symtab needs a low pc, but we don't really have one.
6627 Do what read_file_scope would do in the absence of such info. */
6628 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6630 /* Find the filename. Do not use dwarf2_name here, since the filename
6631 is not a source language identifier. */
6632 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6634 name
= DW_STRING (attr
);
6636 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6638 comp_dir
= DW_STRING (attr
);
6639 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
6641 comp_dir
= ldirname (name
);
6642 if (comp_dir
!= NULL
)
6643 make_cleanup (xfree
, comp_dir
);
6649 prepare_one_comp_unit (cu
, die
, language_minimal
);
6651 /* We assume that we're processing GCC output. */
6652 processing_gcc_compilation
= 2;
6654 processing_has_namespace_info
= 0;
6656 start_symtab (name
, comp_dir
, lowpc
);
6657 record_debugformat ("DWARF 2");
6658 record_producer (cu
->producer
);
6660 /* Decode line number information if present. We do this before
6661 processing child DIEs, so that the line header table is available
6662 for DW_AT_decl_file.
6663 We don't need the pc/line-number mapping for type units. */
6664 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
6666 /* Process the dies in the type unit. */
6667 if (die
->child
== NULL
)
6669 dump_die_for_error (die
);
6670 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
6671 bfd_get_filename (abfd
));
6674 child_die
= die
->child
;
6676 while (child_die
&& child_die
->tag
)
6678 process_die (child_die
, cu
);
6680 child_die
= sibling_die (child_die
);
6683 do_cleanups (back_to
);
6689 hash_dwo_file (const void *item
)
6691 const struct dwo_file
*dwo_file
= item
;
6693 return htab_hash_string (dwo_file
->dwo_name
);
6697 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
6699 const struct dwo_file
*lhs
= item_lhs
;
6700 const struct dwo_file
*rhs
= item_rhs
;
6702 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
6705 /* Allocate a hash table for DWO files. */
6708 allocate_dwo_file_hash_table (void)
6710 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6712 return htab_create_alloc_ex (41,
6716 &objfile
->objfile_obstack
,
6717 hashtab_obstack_allocate
,
6718 dummy_obstack_deallocate
);
6722 hash_dwo_unit (const void *item
)
6724 const struct dwo_unit
*dwo_unit
= item
;
6726 /* This drops the top 32 bits of the id, but is ok for a hash. */
6727 return dwo_unit
->signature
;
6731 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
6733 const struct dwo_unit
*lhs
= item_lhs
;
6734 const struct dwo_unit
*rhs
= item_rhs
;
6736 /* The signature is assumed to be unique within the DWO file.
6737 So while object file CU dwo_id's always have the value zero,
6738 that's OK, assuming each object file DWO file has only one CU,
6739 and that's the rule for now. */
6740 return lhs
->signature
== rhs
->signature
;
6743 /* Allocate a hash table for DWO CUs,TUs.
6744 There is one of these tables for each of CUs,TUs for each DWO file. */
6747 allocate_dwo_unit_table (struct objfile
*objfile
)
6749 /* Start out with a pretty small number.
6750 Generally DWO files contain only one CU and maybe some TUs. */
6751 return htab_create_alloc_ex (3,
6755 &objfile
->objfile_obstack
,
6756 hashtab_obstack_allocate
,
6757 dummy_obstack_deallocate
);
6760 /* This function is mapped across the sections and remembers the offset and
6761 size of each of the DWO debugging sections we are interested in. */
6764 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
6766 struct dwo_file
*dwo_file
= dwo_file_ptr
;
6767 const struct dwo_section_names
*names
= &dwo_section_names
;
6769 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
6771 dwo_file
->sections
.abbrev
.asection
= sectp
;
6772 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
6774 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
6776 dwo_file
->sections
.info
.asection
= sectp
;
6777 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
6779 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
6781 dwo_file
->sections
.line
.asection
= sectp
;
6782 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
6784 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
6786 dwo_file
->sections
.loc
.asection
= sectp
;
6787 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
6789 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
6791 dwo_file
->sections
.str
.asection
= sectp
;
6792 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
6794 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
6796 dwo_file
->sections
.str_offsets
.asection
= sectp
;
6797 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
6799 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
6801 struct dwarf2_section_info type_section
;
6803 memset (&type_section
, 0, sizeof (type_section
));
6804 type_section
.asection
= sectp
;
6805 type_section
.size
= bfd_get_section_size (sectp
);
6806 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
6811 /* Structure used to pass data to create_debug_info_hash_table_reader. */
6813 struct create_dwo_info_table_data
6815 struct dwo_file
*dwo_file
;
6819 /* die_reader_func for create_debug_info_hash_table. */
6822 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
6824 struct die_info
*comp_unit_die
,
6828 struct dwarf2_cu
*cu
= reader
->cu
;
6829 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6830 sect_offset offset
= cu
->per_cu
->offset
;
6831 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
6832 struct create_dwo_info_table_data
*data
= datap
;
6833 struct dwo_file
*dwo_file
= data
->dwo_file
;
6834 htab_t cu_htab
= data
->cu_htab
;
6836 struct attribute
*attr
;
6837 struct dwo_unit
*dwo_unit
;
6839 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6842 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
6843 " its dwo_id [in module %s]"),
6844 offset
.sect_off
, dwo_file
->dwo_name
);
6848 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
6849 dwo_unit
->dwo_file
= dwo_file
;
6850 dwo_unit
->signature
= DW_UNSND (attr
);
6851 dwo_unit
->info_or_types_section
= section
;
6852 dwo_unit
->offset
= offset
;
6853 dwo_unit
->length
= cu
->per_cu
->length
;
6855 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
6856 gdb_assert (slot
!= NULL
);
6859 const struct dwo_unit
*dup_dwo_unit
= *slot
;
6861 complaint (&symfile_complaints
,
6862 _("debug entry at offset 0x%x is duplicate to the entry at"
6863 " offset 0x%x, dwo_id 0x%s [in module %s]"),
6864 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
6865 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
6866 dwo_file
->dwo_name
);
6871 if (dwarf2_die_debug
)
6872 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
6874 phex (dwo_unit
->signature
,
6875 sizeof (dwo_unit
->signature
)));
6878 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
6881 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
6883 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6884 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
6887 gdb_byte
*info_ptr
, *end_ptr
;
6888 struct create_dwo_info_table_data create_dwo_info_table_data
;
6890 dwarf2_read_section (objfile
, section
);
6891 info_ptr
= section
->buffer
;
6893 if (info_ptr
== NULL
)
6896 /* We can't set abfd until now because the section may be empty or
6897 not present, in which case section->asection will be NULL. */
6898 abfd
= section
->asection
->owner
;
6900 if (dwarf2_die_debug
)
6901 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
6902 bfd_get_filename (abfd
));
6904 cu_htab
= allocate_dwo_unit_table (objfile
);
6906 create_dwo_info_table_data
.dwo_file
= dwo_file
;
6907 create_dwo_info_table_data
.cu_htab
= cu_htab
;
6909 end_ptr
= info_ptr
+ section
->size
;
6910 while (info_ptr
< end_ptr
)
6912 struct dwarf2_per_cu_data per_cu
;
6914 memset (&per_cu
, 0, sizeof (per_cu
));
6915 per_cu
.objfile
= objfile
;
6916 per_cu
.is_debug_types
= 0;
6917 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
6918 per_cu
.info_or_types_section
= section
;
6920 init_cutu_and_read_dies_no_follow (&per_cu
,
6921 &dwo_file
->sections
.abbrev
,
6923 create_debug_info_hash_table_reader
,
6924 &create_dwo_info_table_data
);
6926 info_ptr
+= per_cu
.length
;
6932 /* Subroutine of open_dwo_file to simplify it.
6933 Open the file specified by FILE_NAME and hand it off to BFD for
6934 preliminary analysis. Return a newly initialized bfd *, which
6935 includes a canonicalized copy of FILE_NAME.
6936 In case of trouble, return NULL.
6937 NOTE: This function is derived from symfile_bfd_open. */
6940 try_open_dwo_file (const char *file_name
)
6944 char *absolute_name
;
6947 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
6948 O_RDONLY
| O_BINARY
, &absolute_name
);
6952 sym_bfd
= bfd_fopen (absolute_name
, gnutarget
, FOPEN_RB
, desc
);
6956 xfree (absolute_name
);
6959 bfd_set_cacheable (sym_bfd
, 1);
6961 if (!bfd_check_format (sym_bfd
, bfd_object
))
6963 bfd_close (sym_bfd
); /* This also closes desc. */
6964 xfree (absolute_name
);
6968 /* bfd_usrdata exists for applications and libbfd must not touch it. */
6969 gdb_assert (bfd_usrdata (sym_bfd
) == NULL
);
6974 /* Try to open DWO file DWO_NAME.
6975 COMP_DIR is the DW_AT_comp_dir attribute.
6976 The result is the bfd handle of the file.
6977 If there is a problem finding or opening the file, return NULL.
6978 Upon success, the canonicalized path of the file is stored in the bfd,
6979 same as symfile_bfd_open. */
6982 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
6985 char *path_to_try
, *debug_dir
;
6987 if (IS_ABSOLUTE_PATH (dwo_name
))
6988 return try_open_dwo_file (dwo_name
);
6990 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
6992 if (comp_dir
!= NULL
)
6994 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
6996 /* NOTE: If comp_dir is a relative path, this will also try the
6997 search path, which seems useful. */
6998 abfd
= try_open_dwo_file (path_to_try
);
6999 xfree (path_to_try
);
7004 /* That didn't work, try debug-file-directory, which, despite its name,
7005 is a list of paths. */
7007 if (*debug_file_directory
== '\0')
7010 return try_open_dwo_file (dwo_name
);
7013 /* Initialize the use of the DWO file specified by DWO_NAME. */
7015 static struct dwo_file
*
7016 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
7018 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7019 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7022 struct cleanup
*cleanups
;
7024 if (dwarf2_die_debug
)
7025 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
7027 abfd
= open_dwo_file (dwo_name
, comp_dir
);
7030 dwo_file
->dwo_name
= dwo_name
;
7031 dwo_file
->dwo_bfd
= abfd
;
7033 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
7035 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
7037 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
7039 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
7040 dwo_file
->sections
.types
);
7042 discard_cleanups (cleanups
);
7047 /* Lookup DWO file DWO_NAME. */
7049 static struct dwo_file
*
7050 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
7052 struct dwo_file
*dwo_file
;
7053 struct dwo_file find_entry
;
7056 if (dwarf2_per_objfile
->dwo_files
== NULL
)
7057 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
7059 /* Have we already seen this DWO file? */
7060 find_entry
.dwo_name
= dwo_name
;
7061 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
7063 /* If not, read it in and build a table of the DWOs it contains. */
7065 *slot
= init_dwo_file (dwo_name
, comp_dir
);
7067 /* NOTE: This will be NULL if unable to open the file. */
7073 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
7074 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
7075 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
7076 nomenclature as TUs).
7077 The result is the DWO CU or NULL if we didn't find it
7078 (dwo_id mismatch or couldn't find the DWO file). */
7080 static struct dwo_unit
*
7081 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7082 char *dwo_name
, const char *comp_dir
,
7085 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7086 struct dwo_file
*dwo_file
;
7088 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
7089 if (dwo_file
== NULL
)
7092 /* Look up the DWO using its signature(dwo_id). */
7094 if (dwo_file
->cus
!= NULL
)
7096 struct dwo_unit find_dwo_cu
, *dwo_cu
;
7098 find_dwo_cu
.signature
= signature
;
7099 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
7105 /* We didn't find it. This must mean a dwo_id mismatch. */
7107 complaint (&symfile_complaints
,
7108 _("Could not find DWO CU referenced by CU at offset 0x%x"
7110 this_cu
->offset
.sect_off
, objfile
->name
);
7114 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
7115 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
7116 The result is the DWO CU or NULL if we didn't find it
7117 (dwo_id mismatch or couldn't find the DWO file). */
7119 static struct dwo_unit
*
7120 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
7121 char *dwo_name
, const char *comp_dir
)
7123 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7124 struct dwo_file
*dwo_file
;
7125 struct dwo_unit find_dwo_tu
, *dwo_tu
;
7127 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
7128 if (dwo_file
== NULL
)
7131 /* Look up the DWO using its signature(dwo_id). */
7133 if (dwo_file
->tus
!= NULL
)
7135 struct dwo_unit find_dwo_tu
, *dwo_tu
;
7137 find_dwo_tu
.signature
= this_tu
->signature
;
7138 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
7144 /* We didn't find it. This must mean a dwo_id mismatch. */
7146 complaint (&symfile_complaints
,
7147 _("Could not find DWO TU referenced by TU at offset 0x%x"
7149 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
7153 /* Free all resources associated with DWO_FILE.
7154 Close the DWO file and munmap the sections.
7155 All memory should be on the objfile obstack. */
7158 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
7161 struct dwarf2_section_info
*section
;
7163 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
7164 bfd_close (dwo_file
->dwo_bfd
);
7166 munmap_section_buffer (&dwo_file
->sections
.abbrev
);
7167 munmap_section_buffer (&dwo_file
->sections
.info
);
7168 munmap_section_buffer (&dwo_file
->sections
.line
);
7169 munmap_section_buffer (&dwo_file
->sections
.loc
);
7170 munmap_section_buffer (&dwo_file
->sections
.str
);
7171 munmap_section_buffer (&dwo_file
->sections
.str_offsets
);
7174 VEC_iterate (dwarf2_section_info_def
, dwo_file
->sections
.types
,
7177 munmap_section_buffer (section
);
7179 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
7182 /* Wrapper for free_dwo_file for use in cleanups. */
7185 free_dwo_file_cleanup (void *arg
)
7187 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
7188 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7190 free_dwo_file (dwo_file
, objfile
);
7193 /* Traversal function for free_dwo_files. */
7196 free_dwo_file_from_slot (void **slot
, void *info
)
7198 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7199 struct objfile
*objfile
= (struct objfile
*) info
;
7201 free_dwo_file (dwo_file
, objfile
);
7206 /* Free all resources associated with DWO_FILES. */
7209 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
7211 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
7214 /* Read in various DIEs. */
7216 /* qsort helper for inherit_abstract_dies. */
7219 unsigned_int_compar (const void *ap
, const void *bp
)
7221 unsigned int a
= *(unsigned int *) ap
;
7222 unsigned int b
= *(unsigned int *) bp
;
7224 return (a
> b
) - (b
> a
);
7227 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
7228 Inherit only the children of the DW_AT_abstract_origin DIE not being
7229 already referenced by DW_AT_abstract_origin from the children of the
7233 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
7235 struct die_info
*child_die
;
7236 unsigned die_children_count
;
7237 /* CU offsets which were referenced by children of the current DIE. */
7238 sect_offset
*offsets
;
7239 sect_offset
*offsets_end
, *offsetp
;
7240 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
7241 struct die_info
*origin_die
;
7242 /* Iterator of the ORIGIN_DIE children. */
7243 struct die_info
*origin_child_die
;
7244 struct cleanup
*cleanups
;
7245 struct attribute
*attr
;
7246 struct dwarf2_cu
*origin_cu
;
7247 struct pending
**origin_previous_list_in_scope
;
7249 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7253 /* Note that following die references may follow to a die in a
7257 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
7259 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
7261 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
7262 origin_cu
->list_in_scope
= cu
->list_in_scope
;
7264 if (die
->tag
!= origin_die
->tag
7265 && !(die
->tag
== DW_TAG_inlined_subroutine
7266 && origin_die
->tag
== DW_TAG_subprogram
))
7267 complaint (&symfile_complaints
,
7268 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
7269 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
7271 child_die
= die
->child
;
7272 die_children_count
= 0;
7273 while (child_die
&& child_die
->tag
)
7275 child_die
= sibling_die (child_die
);
7276 die_children_count
++;
7278 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
7279 cleanups
= make_cleanup (xfree
, offsets
);
7281 offsets_end
= offsets
;
7282 child_die
= die
->child
;
7283 while (child_die
&& child_die
->tag
)
7285 /* For each CHILD_DIE, find the corresponding child of
7286 ORIGIN_DIE. If there is more than one layer of
7287 DW_AT_abstract_origin, follow them all; there shouldn't be,
7288 but GCC versions at least through 4.4 generate this (GCC PR
7290 struct die_info
*child_origin_die
= child_die
;
7291 struct dwarf2_cu
*child_origin_cu
= cu
;
7295 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
7299 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
7303 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
7304 counterpart may exist. */
7305 if (child_origin_die
!= child_die
)
7307 if (child_die
->tag
!= child_origin_die
->tag
7308 && !(child_die
->tag
== DW_TAG_inlined_subroutine
7309 && child_origin_die
->tag
== DW_TAG_subprogram
))
7310 complaint (&symfile_complaints
,
7311 _("Child DIE 0x%x and its abstract origin 0x%x have "
7312 "different tags"), child_die
->offset
.sect_off
,
7313 child_origin_die
->offset
.sect_off
);
7314 if (child_origin_die
->parent
!= origin_die
)
7315 complaint (&symfile_complaints
,
7316 _("Child DIE 0x%x and its abstract origin 0x%x have "
7317 "different parents"), child_die
->offset
.sect_off
,
7318 child_origin_die
->offset
.sect_off
);
7320 *offsets_end
++ = child_origin_die
->offset
;
7322 child_die
= sibling_die (child_die
);
7324 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
7325 unsigned_int_compar
);
7326 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
7327 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
7328 complaint (&symfile_complaints
,
7329 _("Multiple children of DIE 0x%x refer "
7330 "to DIE 0x%x as their abstract origin"),
7331 die
->offset
.sect_off
, offsetp
->sect_off
);
7334 origin_child_die
= origin_die
->child
;
7335 while (origin_child_die
&& origin_child_die
->tag
)
7337 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
7338 while (offsetp
< offsets_end
7339 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
7341 if (offsetp
>= offsets_end
7342 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
7344 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
7345 process_die (origin_child_die
, origin_cu
);
7347 origin_child_die
= sibling_die (origin_child_die
);
7349 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
7351 do_cleanups (cleanups
);
7355 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7357 struct objfile
*objfile
= cu
->objfile
;
7358 struct context_stack
*new;
7361 struct die_info
*child_die
;
7362 struct attribute
*attr
, *call_line
, *call_file
;
7365 struct block
*block
;
7366 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
7367 VEC (symbolp
) *template_args
= NULL
;
7368 struct template_symbol
*templ_func
= NULL
;
7372 /* If we do not have call site information, we can't show the
7373 caller of this inlined function. That's too confusing, so
7374 only use the scope for local variables. */
7375 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
7376 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
7377 if (call_line
== NULL
|| call_file
== NULL
)
7379 read_lexical_block_scope (die
, cu
);
7384 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7386 name
= dwarf2_name (die
, cu
);
7388 /* Ignore functions with missing or empty names. These are actually
7389 illegal according to the DWARF standard. */
7392 complaint (&symfile_complaints
,
7393 _("missing name for subprogram DIE at %d"),
7394 die
->offset
.sect_off
);
7398 /* Ignore functions with missing or invalid low and high pc attributes. */
7399 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7401 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7402 if (!attr
|| !DW_UNSND (attr
))
7403 complaint (&symfile_complaints
,
7404 _("cannot get low and high bounds "
7405 "for subprogram DIE at %d"),
7406 die
->offset
.sect_off
);
7413 /* If we have any template arguments, then we must allocate a
7414 different sort of symbol. */
7415 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
7417 if (child_die
->tag
== DW_TAG_template_type_param
7418 || child_die
->tag
== DW_TAG_template_value_param
)
7420 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7421 struct template_symbol
);
7422 templ_func
->base
.is_cplus_template_function
= 1;
7427 new = push_context (0, lowpc
);
7428 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
7429 (struct symbol
*) templ_func
);
7431 /* If there is a location expression for DW_AT_frame_base, record
7433 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
7435 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
7436 expression is being recorded directly in the function's symbol
7437 and not in a separate frame-base object. I guess this hack is
7438 to avoid adding some sort of frame-base adjunct/annex to the
7439 function's symbol :-(. The problem with doing this is that it
7440 results in a function symbol with a location expression that
7441 has nothing to do with the location of the function, ouch! The
7442 relationship should be: a function's symbol has-a frame base; a
7443 frame-base has-a location expression. */
7444 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
7446 cu
->list_in_scope
= &local_symbols
;
7448 if (die
->child
!= NULL
)
7450 child_die
= die
->child
;
7451 while (child_die
&& child_die
->tag
)
7453 if (child_die
->tag
== DW_TAG_template_type_param
7454 || child_die
->tag
== DW_TAG_template_value_param
)
7456 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7459 VEC_safe_push (symbolp
, template_args
, arg
);
7462 process_die (child_die
, cu
);
7463 child_die
= sibling_die (child_die
);
7467 inherit_abstract_dies (die
, cu
);
7469 /* If we have a DW_AT_specification, we might need to import using
7470 directives from the context of the specification DIE. See the
7471 comment in determine_prefix. */
7472 if (cu
->language
== language_cplus
7473 && dwarf2_attr (die
, DW_AT_specification
, cu
))
7475 struct dwarf2_cu
*spec_cu
= cu
;
7476 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
7480 child_die
= spec_die
->child
;
7481 while (child_die
&& child_die
->tag
)
7483 if (child_die
->tag
== DW_TAG_imported_module
)
7484 process_die (child_die
, spec_cu
);
7485 child_die
= sibling_die (child_die
);
7488 /* In some cases, GCC generates specification DIEs that
7489 themselves contain DW_AT_specification attributes. */
7490 spec_die
= die_specification (spec_die
, &spec_cu
);
7494 new = pop_context ();
7495 /* Make a block for the local symbols within. */
7496 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
7497 lowpc
, highpc
, objfile
);
7499 /* For C++, set the block's scope. */
7500 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
7501 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
7502 determine_prefix (die
, cu
),
7503 processing_has_namespace_info
);
7505 /* If we have address ranges, record them. */
7506 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7508 /* Attach template arguments to function. */
7509 if (! VEC_empty (symbolp
, template_args
))
7511 gdb_assert (templ_func
!= NULL
);
7513 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
7514 templ_func
->template_arguments
7515 = obstack_alloc (&objfile
->objfile_obstack
,
7516 (templ_func
->n_template_arguments
7517 * sizeof (struct symbol
*)));
7518 memcpy (templ_func
->template_arguments
,
7519 VEC_address (symbolp
, template_args
),
7520 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
7521 VEC_free (symbolp
, template_args
);
7524 /* In C++, we can have functions nested inside functions (e.g., when
7525 a function declares a class that has methods). This means that
7526 when we finish processing a function scope, we may need to go
7527 back to building a containing block's symbol lists. */
7528 local_symbols
= new->locals
;
7529 param_symbols
= new->params
;
7530 using_directives
= new->using_directives
;
7532 /* If we've finished processing a top-level function, subsequent
7533 symbols go in the file symbol list. */
7534 if (outermost_context_p ())
7535 cu
->list_in_scope
= &file_symbols
;
7538 /* Process all the DIES contained within a lexical block scope. Start
7539 a new scope, process the dies, and then close the scope. */
7542 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7544 struct objfile
*objfile
= cu
->objfile
;
7545 struct context_stack
*new;
7546 CORE_ADDR lowpc
, highpc
;
7547 struct die_info
*child_die
;
7550 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7552 /* Ignore blocks with missing or invalid low and high pc attributes. */
7553 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
7554 as multiple lexical blocks? Handling children in a sane way would
7555 be nasty. Might be easier to properly extend generic blocks to
7557 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7562 push_context (0, lowpc
);
7563 if (die
->child
!= NULL
)
7565 child_die
= die
->child
;
7566 while (child_die
&& child_die
->tag
)
7568 process_die (child_die
, cu
);
7569 child_die
= sibling_die (child_die
);
7572 new = pop_context ();
7574 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
7577 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
7580 /* Note that recording ranges after traversing children, as we
7581 do here, means that recording a parent's ranges entails
7582 walking across all its children's ranges as they appear in
7583 the address map, which is quadratic behavior.
7585 It would be nicer to record the parent's ranges before
7586 traversing its children, simply overriding whatever you find
7587 there. But since we don't even decide whether to create a
7588 block until after we've traversed its children, that's hard
7590 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7592 local_symbols
= new->locals
;
7593 using_directives
= new->using_directives
;
7596 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
7599 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7601 struct objfile
*objfile
= cu
->objfile
;
7602 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7603 CORE_ADDR pc
, baseaddr
;
7604 struct attribute
*attr
;
7605 struct call_site
*call_site
, call_site_local
;
7608 struct die_info
*child_die
;
7610 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7612 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7615 complaint (&symfile_complaints
,
7616 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
7617 "DIE 0x%x [in module %s]"),
7618 die
->offset
.sect_off
, objfile
->name
);
7621 pc
= DW_ADDR (attr
) + baseaddr
;
7623 if (cu
->call_site_htab
== NULL
)
7624 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
7625 NULL
, &objfile
->objfile_obstack
,
7626 hashtab_obstack_allocate
, NULL
);
7627 call_site_local
.pc
= pc
;
7628 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
7631 complaint (&symfile_complaints
,
7632 _("Duplicate PC %s for DW_TAG_GNU_call_site "
7633 "DIE 0x%x [in module %s]"),
7634 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
7638 /* Count parameters at the caller. */
7641 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7642 child_die
= sibling_die (child_die
))
7644 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7646 complaint (&symfile_complaints
,
7647 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
7648 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7649 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
7656 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
7657 (sizeof (*call_site
)
7658 + (sizeof (*call_site
->parameter
)
7661 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
7664 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
7666 struct die_info
*func_die
;
7668 /* Skip also over DW_TAG_inlined_subroutine. */
7669 for (func_die
= die
->parent
;
7670 func_die
&& func_die
->tag
!= DW_TAG_subprogram
7671 && func_die
->tag
!= DW_TAG_subroutine_type
;
7672 func_die
= func_die
->parent
);
7674 /* DW_AT_GNU_all_call_sites is a superset
7675 of DW_AT_GNU_all_tail_call_sites. */
7677 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
7678 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
7680 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
7681 not complete. But keep CALL_SITE for look ups via call_site_htab,
7682 both the initial caller containing the real return address PC and
7683 the final callee containing the current PC of a chain of tail
7684 calls do not need to have the tail call list complete. But any
7685 function candidate for a virtual tail call frame searched via
7686 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
7687 determined unambiguously. */
7691 struct type
*func_type
= NULL
;
7694 func_type
= get_die_type (func_die
, cu
);
7695 if (func_type
!= NULL
)
7697 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
7699 /* Enlist this call site to the function. */
7700 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
7701 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
7704 complaint (&symfile_complaints
,
7705 _("Cannot find function owning DW_TAG_GNU_call_site "
7706 "DIE 0x%x [in module %s]"),
7707 die
->offset
.sect_off
, objfile
->name
);
7711 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
7713 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7714 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
7715 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
7716 /* Keep NULL DWARF_BLOCK. */;
7717 else if (attr_form_is_block (attr
))
7719 struct dwarf2_locexpr_baton
*dlbaton
;
7721 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
7722 dlbaton
->data
= DW_BLOCK (attr
)->data
;
7723 dlbaton
->size
= DW_BLOCK (attr
)->size
;
7724 dlbaton
->per_cu
= cu
->per_cu
;
7726 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
7728 else if (is_ref_attr (attr
))
7730 struct dwarf2_cu
*target_cu
= cu
;
7731 struct die_info
*target_die
;
7733 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
7734 gdb_assert (target_cu
->objfile
== objfile
);
7735 if (die_is_declaration (target_die
, target_cu
))
7737 const char *target_physname
;
7739 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
7740 if (target_physname
== NULL
)
7741 complaint (&symfile_complaints
,
7742 _("DW_AT_GNU_call_site_target target DIE has invalid "
7743 "physname, for referencing DIE 0x%x [in module %s]"),
7744 die
->offset
.sect_off
, objfile
->name
);
7746 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
7752 /* DW_AT_entry_pc should be preferred. */
7753 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
7754 complaint (&symfile_complaints
,
7755 _("DW_AT_GNU_call_site_target target DIE has invalid "
7756 "low pc, for referencing DIE 0x%x [in module %s]"),
7757 die
->offset
.sect_off
, objfile
->name
);
7759 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
7763 complaint (&symfile_complaints
,
7764 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
7765 "block nor reference, for DIE 0x%x [in module %s]"),
7766 die
->offset
.sect_off
, objfile
->name
);
7768 call_site
->per_cu
= cu
->per_cu
;
7770 for (child_die
= die
->child
;
7771 child_die
&& child_die
->tag
;
7772 child_die
= sibling_die (child_die
))
7774 struct dwarf2_locexpr_baton
*dlbaton
;
7775 struct call_site_parameter
*parameter
;
7777 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7779 /* Already printed the complaint above. */
7783 gdb_assert (call_site
->parameter_count
< nparams
);
7784 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
7786 /* DW_AT_location specifies the register number. Value of the data
7787 assumed for the register is contained in DW_AT_GNU_call_site_value. */
7789 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
7790 if (!attr
|| !attr_form_is_block (attr
))
7792 complaint (&symfile_complaints
,
7793 _("No DW_FORM_block* DW_AT_location for "
7794 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7795 child_die
->offset
.sect_off
, objfile
->name
);
7798 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
7799 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
7800 if (parameter
->dwarf_reg
== -1
7801 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
7802 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
7803 ¶meter
->fb_offset
))
7805 complaint (&symfile_complaints
,
7806 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
7807 "for DW_FORM_block* DW_AT_location for "
7808 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7809 child_die
->offset
.sect_off
, objfile
->name
);
7813 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
7814 if (!attr_form_is_block (attr
))
7816 complaint (&symfile_complaints
,
7817 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
7818 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7819 child_die
->offset
.sect_off
, objfile
->name
);
7822 parameter
->value
= DW_BLOCK (attr
)->data
;
7823 parameter
->value_size
= DW_BLOCK (attr
)->size
;
7825 /* Parameters are not pre-cleared by memset above. */
7826 parameter
->data_value
= NULL
;
7827 parameter
->data_value_size
= 0;
7828 call_site
->parameter_count
++;
7830 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
7833 if (!attr_form_is_block (attr
))
7834 complaint (&symfile_complaints
,
7835 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
7836 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7837 child_die
->offset
.sect_off
, objfile
->name
);
7840 parameter
->data_value
= DW_BLOCK (attr
)->data
;
7841 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
7847 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
7848 Return 1 if the attributes are present and valid, otherwise, return 0.
7849 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
7852 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
7853 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
7854 struct partial_symtab
*ranges_pst
)
7856 struct objfile
*objfile
= cu
->objfile
;
7857 struct comp_unit_head
*cu_header
= &cu
->header
;
7858 bfd
*obfd
= objfile
->obfd
;
7859 unsigned int addr_size
= cu_header
->addr_size
;
7860 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
7861 /* Base address selection entry. */
7872 found_base
= cu
->base_known
;
7873 base
= cu
->base_address
;
7875 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
7876 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
7878 complaint (&symfile_complaints
,
7879 _("Offset %d out of bounds for DW_AT_ranges attribute"),
7883 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
7885 /* Read in the largest possible address. */
7886 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
7887 if ((marker
& mask
) == mask
)
7889 /* If we found the largest possible address, then
7890 read the base address. */
7891 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
7892 buffer
+= 2 * addr_size
;
7893 offset
+= 2 * addr_size
;
7899 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7903 CORE_ADDR range_beginning
, range_end
;
7905 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
7906 buffer
+= addr_size
;
7907 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
7908 buffer
+= addr_size
;
7909 offset
+= 2 * addr_size
;
7911 /* An end of list marker is a pair of zero addresses. */
7912 if (range_beginning
== 0 && range_end
== 0)
7913 /* Found the end of list entry. */
7916 /* Each base address selection entry is a pair of 2 values.
7917 The first is the largest possible address, the second is
7918 the base address. Check for a base address here. */
7919 if ((range_beginning
& mask
) == mask
)
7921 /* If we found the largest possible address, then
7922 read the base address. */
7923 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
7930 /* We have no valid base address for the ranges
7932 complaint (&symfile_complaints
,
7933 _("Invalid .debug_ranges data (no base address)"));
7937 if (range_beginning
> range_end
)
7939 /* Inverted range entries are invalid. */
7940 complaint (&symfile_complaints
,
7941 _("Invalid .debug_ranges data (inverted range)"));
7945 /* Empty range entries have no effect. */
7946 if (range_beginning
== range_end
)
7949 range_beginning
+= base
;
7952 if (ranges_pst
!= NULL
)
7953 addrmap_set_empty (objfile
->psymtabs_addrmap
,
7954 range_beginning
+ baseaddr
,
7955 range_end
- 1 + baseaddr
,
7958 /* FIXME: This is recording everything as a low-high
7959 segment of consecutive addresses. We should have a
7960 data structure for discontiguous block ranges
7964 low
= range_beginning
;
7970 if (range_beginning
< low
)
7971 low
= range_beginning
;
7972 if (range_end
> high
)
7978 /* If the first entry is an end-of-list marker, the range
7979 describes an empty scope, i.e. no instructions. */
7985 *high_return
= high
;
7989 /* Get low and high pc attributes from a die. Return 1 if the attributes
7990 are present and valid, otherwise, return 0. Return -1 if the range is
7991 discontinuous, i.e. derived from DW_AT_ranges information. */
7994 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
7995 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
7996 struct partial_symtab
*pst
)
7998 struct attribute
*attr
;
7999 struct attribute
*attr_high
;
8004 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
8007 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8010 low
= DW_ADDR (attr
);
8011 if (attr_high
->form
== DW_FORM_addr
8012 || attr_high
->form
== DW_FORM_GNU_addr_index
)
8013 high
= DW_ADDR (attr_high
);
8015 high
= low
+ DW_UNSND (attr_high
);
8018 /* Found high w/o low attribute. */
8021 /* Found consecutive range of addresses. */
8026 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
8029 /* Value of the DW_AT_ranges attribute is the offset in the
8030 .debug_ranges section. */
8031 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
8033 /* Found discontinuous range of addresses. */
8038 /* read_partial_die has also the strict LOW < HIGH requirement. */
8042 /* When using the GNU linker, .gnu.linkonce. sections are used to
8043 eliminate duplicate copies of functions and vtables and such.
8044 The linker will arbitrarily choose one and discard the others.
8045 The AT_*_pc values for such functions refer to local labels in
8046 these sections. If the section from that file was discarded, the
8047 labels are not in the output, so the relocs get a value of 0.
8048 If this is a discarded function, mark the pc bounds as invalid,
8049 so that GDB will ignore it. */
8050 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
8059 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
8060 its low and high PC addresses. Do nothing if these addresses could not
8061 be determined. Otherwise, set LOWPC to the low address if it is smaller,
8062 and HIGHPC to the high address if greater than HIGHPC. */
8065 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
8066 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8067 struct dwarf2_cu
*cu
)
8069 CORE_ADDR low
, high
;
8070 struct die_info
*child
= die
->child
;
8072 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
8074 *lowpc
= min (*lowpc
, low
);
8075 *highpc
= max (*highpc
, high
);
8078 /* If the language does not allow nested subprograms (either inside
8079 subprograms or lexical blocks), we're done. */
8080 if (cu
->language
!= language_ada
)
8083 /* Check all the children of the given DIE. If it contains nested
8084 subprograms, then check their pc bounds. Likewise, we need to
8085 check lexical blocks as well, as they may also contain subprogram
8087 while (child
&& child
->tag
)
8089 if (child
->tag
== DW_TAG_subprogram
8090 || child
->tag
== DW_TAG_lexical_block
)
8091 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
8092 child
= sibling_die (child
);
8096 /* Get the low and high pc's represented by the scope DIE, and store
8097 them in *LOWPC and *HIGHPC. If the correct values can't be
8098 determined, set *LOWPC to -1 and *HIGHPC to 0. */
8101 get_scope_pc_bounds (struct die_info
*die
,
8102 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8103 struct dwarf2_cu
*cu
)
8105 CORE_ADDR best_low
= (CORE_ADDR
) -1;
8106 CORE_ADDR best_high
= (CORE_ADDR
) 0;
8107 CORE_ADDR current_low
, current_high
;
8109 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
8111 best_low
= current_low
;
8112 best_high
= current_high
;
8116 struct die_info
*child
= die
->child
;
8118 while (child
&& child
->tag
)
8120 switch (child
->tag
) {
8121 case DW_TAG_subprogram
:
8122 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
8124 case DW_TAG_namespace
:
8126 /* FIXME: carlton/2004-01-16: Should we do this for
8127 DW_TAG_class_type/DW_TAG_structure_type, too? I think
8128 that current GCC's always emit the DIEs corresponding
8129 to definitions of methods of classes as children of a
8130 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
8131 the DIEs giving the declarations, which could be
8132 anywhere). But I don't see any reason why the
8133 standards says that they have to be there. */
8134 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
8136 if (current_low
!= ((CORE_ADDR
) -1))
8138 best_low
= min (best_low
, current_low
);
8139 best_high
= max (best_high
, current_high
);
8147 child
= sibling_die (child
);
8152 *highpc
= best_high
;
8155 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
8159 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
8160 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
8162 struct objfile
*objfile
= cu
->objfile
;
8163 struct attribute
*attr
;
8164 struct attribute
*attr_high
;
8166 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
8169 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8172 CORE_ADDR low
= DW_ADDR (attr
);
8174 if (attr_high
->form
== DW_FORM_addr
8175 || attr_high
->form
== DW_FORM_GNU_addr_index
)
8176 high
= DW_ADDR (attr_high
);
8178 high
= low
+ DW_UNSND (attr_high
);
8180 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
8184 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
8187 bfd
*obfd
= objfile
->obfd
;
8189 /* The value of the DW_AT_ranges attribute is the offset of the
8190 address range list in the .debug_ranges section. */
8191 unsigned long offset
= DW_UNSND (attr
);
8192 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
8194 /* For some target architectures, but not others, the
8195 read_address function sign-extends the addresses it returns.
8196 To recognize base address selection entries, we need a
8198 unsigned int addr_size
= cu
->header
.addr_size
;
8199 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
8201 /* The base address, to which the next pair is relative. Note
8202 that this 'base' is a DWARF concept: most entries in a range
8203 list are relative, to reduce the number of relocs against the
8204 debugging information. This is separate from this function's
8205 'baseaddr' argument, which GDB uses to relocate debugging
8206 information from a shared library based on the address at
8207 which the library was loaded. */
8208 CORE_ADDR base
= cu
->base_address
;
8209 int base_known
= cu
->base_known
;
8211 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
8212 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
8214 complaint (&symfile_complaints
,
8215 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
8222 unsigned int bytes_read
;
8223 CORE_ADDR start
, end
;
8225 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
8226 buffer
+= bytes_read
;
8227 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
8228 buffer
+= bytes_read
;
8230 /* Did we find the end of the range list? */
8231 if (start
== 0 && end
== 0)
8234 /* Did we find a base address selection entry? */
8235 else if ((start
& base_select_mask
) == base_select_mask
)
8241 /* We found an ordinary address range. */
8246 complaint (&symfile_complaints
,
8247 _("Invalid .debug_ranges data "
8248 "(no base address)"));
8254 /* Inverted range entries are invalid. */
8255 complaint (&symfile_complaints
,
8256 _("Invalid .debug_ranges data "
8257 "(inverted range)"));
8261 /* Empty range entries have no effect. */
8265 record_block_range (block
,
8266 baseaddr
+ base
+ start
,
8267 baseaddr
+ base
+ end
- 1);
8273 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
8274 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
8275 during 4.6.0 experimental. */
8278 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
8281 int major
, minor
, release
;
8284 if (cu
->producer
== NULL
)
8286 /* For unknown compilers expect their behavior is DWARF version
8289 GCC started to support .debug_types sections by -gdwarf-4 since
8290 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
8291 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
8292 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
8293 interpreted incorrectly by GDB now - GCC PR debug/48229. */
8298 if (cu
->checked_producer
)
8299 return cu
->producer_is_gxx_lt_4_6
;
8301 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
8303 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
8305 /* For non-GCC compilers expect their behavior is DWARF version
8310 cs
= &cu
->producer
[strlen ("GNU ")];
8311 while (*cs
&& !isdigit (*cs
))
8313 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
8315 /* Not recognized as GCC. */
8318 result
= major
< 4 || (major
== 4 && minor
< 6);
8321 cu
->checked_producer
= 1;
8322 cu
->producer_is_gxx_lt_4_6
= result
;
8327 /* Return the default accessibility type if it is not overriden by
8328 DW_AT_accessibility. */
8330 static enum dwarf_access_attribute
8331 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
8333 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
8335 /* The default DWARF 2 accessibility for members is public, the default
8336 accessibility for inheritance is private. */
8338 if (die
->tag
!= DW_TAG_inheritance
)
8339 return DW_ACCESS_public
;
8341 return DW_ACCESS_private
;
8345 /* DWARF 3+ defines the default accessibility a different way. The same
8346 rules apply now for DW_TAG_inheritance as for the members and it only
8347 depends on the container kind. */
8349 if (die
->parent
->tag
== DW_TAG_class_type
)
8350 return DW_ACCESS_private
;
8352 return DW_ACCESS_public
;
8356 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
8357 offset. If the attribute was not found return 0, otherwise return
8358 1. If it was found but could not properly be handled, set *OFFSET
8362 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
8365 struct attribute
*attr
;
8367 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
8372 /* Note that we do not check for a section offset first here.
8373 This is because DW_AT_data_member_location is new in DWARF 4,
8374 so if we see it, we can assume that a constant form is really
8375 a constant and not a section offset. */
8376 if (attr_form_is_constant (attr
))
8377 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
8378 else if (attr_form_is_section_offset (attr
))
8379 dwarf2_complex_location_expr_complaint ();
8380 else if (attr_form_is_block (attr
))
8381 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8383 dwarf2_complex_location_expr_complaint ();
8391 /* Add an aggregate field to the field list. */
8394 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
8395 struct dwarf2_cu
*cu
)
8397 struct objfile
*objfile
= cu
->objfile
;
8398 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8399 struct nextfield
*new_field
;
8400 struct attribute
*attr
;
8402 char *fieldname
= "";
8404 /* Allocate a new field list entry and link it in. */
8405 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
8406 make_cleanup (xfree
, new_field
);
8407 memset (new_field
, 0, sizeof (struct nextfield
));
8409 if (die
->tag
== DW_TAG_inheritance
)
8411 new_field
->next
= fip
->baseclasses
;
8412 fip
->baseclasses
= new_field
;
8416 new_field
->next
= fip
->fields
;
8417 fip
->fields
= new_field
;
8421 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8423 new_field
->accessibility
= DW_UNSND (attr
);
8425 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
8426 if (new_field
->accessibility
!= DW_ACCESS_public
)
8427 fip
->non_public_fields
= 1;
8429 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8431 new_field
->virtuality
= DW_UNSND (attr
);
8433 new_field
->virtuality
= DW_VIRTUALITY_none
;
8435 fp
= &new_field
->field
;
8437 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
8441 /* Data member other than a C++ static data member. */
8443 /* Get type of field. */
8444 fp
->type
= die_type (die
, cu
);
8446 SET_FIELD_BITPOS (*fp
, 0);
8448 /* Get bit size of field (zero if none). */
8449 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
8452 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
8456 FIELD_BITSIZE (*fp
) = 0;
8459 /* Get bit offset of field. */
8460 if (handle_data_member_location (die
, cu
, &offset
))
8461 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8462 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
8465 if (gdbarch_bits_big_endian (gdbarch
))
8467 /* For big endian bits, the DW_AT_bit_offset gives the
8468 additional bit offset from the MSB of the containing
8469 anonymous object to the MSB of the field. We don't
8470 have to do anything special since we don't need to
8471 know the size of the anonymous object. */
8472 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
8476 /* For little endian bits, compute the bit offset to the
8477 MSB of the anonymous object, subtract off the number of
8478 bits from the MSB of the field to the MSB of the
8479 object, and then subtract off the number of bits of
8480 the field itself. The result is the bit offset of
8481 the LSB of the field. */
8483 int bit_offset
= DW_UNSND (attr
);
8485 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8488 /* The size of the anonymous object containing
8489 the bit field is explicit, so use the
8490 indicated size (in bytes). */
8491 anonymous_size
= DW_UNSND (attr
);
8495 /* The size of the anonymous object containing
8496 the bit field must be inferred from the type
8497 attribute of the data member containing the
8499 anonymous_size
= TYPE_LENGTH (fp
->type
);
8501 SET_FIELD_BITPOS (*fp
,
8503 + anonymous_size
* bits_per_byte
8504 - bit_offset
- FIELD_BITSIZE (*fp
)));
8508 /* Get name of field. */
8509 fieldname
= dwarf2_name (die
, cu
);
8510 if (fieldname
== NULL
)
8513 /* The name is already allocated along with this objfile, so we don't
8514 need to duplicate it for the type. */
8515 fp
->name
= fieldname
;
8517 /* Change accessibility for artificial fields (e.g. virtual table
8518 pointer or virtual base class pointer) to private. */
8519 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
8521 FIELD_ARTIFICIAL (*fp
) = 1;
8522 new_field
->accessibility
= DW_ACCESS_private
;
8523 fip
->non_public_fields
= 1;
8526 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
8528 /* C++ static member. */
8530 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
8531 is a declaration, but all versions of G++ as of this writing
8532 (so through at least 3.2.1) incorrectly generate
8533 DW_TAG_variable tags. */
8535 const char *physname
;
8537 /* Get name of field. */
8538 fieldname
= dwarf2_name (die
, cu
);
8539 if (fieldname
== NULL
)
8542 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8544 /* Only create a symbol if this is an external value.
8545 new_symbol checks this and puts the value in the global symbol
8546 table, which we want. If it is not external, new_symbol
8547 will try to put the value in cu->list_in_scope which is wrong. */
8548 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
8550 /* A static const member, not much different than an enum as far as
8551 we're concerned, except that we can support more types. */
8552 new_symbol (die
, NULL
, cu
);
8555 /* Get physical name. */
8556 physname
= dwarf2_physname (fieldname
, die
, cu
);
8558 /* The name is already allocated along with this objfile, so we don't
8559 need to duplicate it for the type. */
8560 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
8561 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8562 FIELD_NAME (*fp
) = fieldname
;
8564 else if (die
->tag
== DW_TAG_inheritance
)
8568 /* C++ base class field. */
8569 if (handle_data_member_location (die
, cu
, &offset
))
8570 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8571 FIELD_BITSIZE (*fp
) = 0;
8572 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8573 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
8574 fip
->nbaseclasses
++;
8578 /* Add a typedef defined in the scope of the FIP's class. */
8581 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
8582 struct dwarf2_cu
*cu
)
8584 struct objfile
*objfile
= cu
->objfile
;
8585 struct typedef_field_list
*new_field
;
8586 struct attribute
*attr
;
8587 struct typedef_field
*fp
;
8588 char *fieldname
= "";
8590 /* Allocate a new field list entry and link it in. */
8591 new_field
= xzalloc (sizeof (*new_field
));
8592 make_cleanup (xfree
, new_field
);
8594 gdb_assert (die
->tag
== DW_TAG_typedef
);
8596 fp
= &new_field
->field
;
8598 /* Get name of field. */
8599 fp
->name
= dwarf2_name (die
, cu
);
8600 if (fp
->name
== NULL
)
8603 fp
->type
= read_type_die (die
, cu
);
8605 new_field
->next
= fip
->typedef_field_list
;
8606 fip
->typedef_field_list
= new_field
;
8607 fip
->typedef_field_list_count
++;
8610 /* Create the vector of fields, and attach it to the type. */
8613 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
8614 struct dwarf2_cu
*cu
)
8616 int nfields
= fip
->nfields
;
8618 /* Record the field count, allocate space for the array of fields,
8619 and create blank accessibility bitfields if necessary. */
8620 TYPE_NFIELDS (type
) = nfields
;
8621 TYPE_FIELDS (type
) = (struct field
*)
8622 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
8623 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
8625 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
8627 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8629 TYPE_FIELD_PRIVATE_BITS (type
) =
8630 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8631 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
8633 TYPE_FIELD_PROTECTED_BITS (type
) =
8634 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8635 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
8637 TYPE_FIELD_IGNORE_BITS (type
) =
8638 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8639 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
8642 /* If the type has baseclasses, allocate and clear a bit vector for
8643 TYPE_FIELD_VIRTUAL_BITS. */
8644 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
8646 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
8647 unsigned char *pointer
;
8649 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8650 pointer
= TYPE_ALLOC (type
, num_bytes
);
8651 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
8652 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
8653 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
8656 /* Copy the saved-up fields into the field vector. Start from the head of
8657 the list, adding to the tail of the field array, so that they end up in
8658 the same order in the array in which they were added to the list. */
8659 while (nfields
-- > 0)
8661 struct nextfield
*fieldp
;
8665 fieldp
= fip
->fields
;
8666 fip
->fields
= fieldp
->next
;
8670 fieldp
= fip
->baseclasses
;
8671 fip
->baseclasses
= fieldp
->next
;
8674 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
8675 switch (fieldp
->accessibility
)
8677 case DW_ACCESS_private
:
8678 if (cu
->language
!= language_ada
)
8679 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
8682 case DW_ACCESS_protected
:
8683 if (cu
->language
!= language_ada
)
8684 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
8687 case DW_ACCESS_public
:
8691 /* Unknown accessibility. Complain and treat it as public. */
8693 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
8694 fieldp
->accessibility
);
8698 if (nfields
< fip
->nbaseclasses
)
8700 switch (fieldp
->virtuality
)
8702 case DW_VIRTUALITY_virtual
:
8703 case DW_VIRTUALITY_pure_virtual
:
8704 if (cu
->language
== language_ada
)
8705 error (_("unexpected virtuality in component of Ada type"));
8706 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
8713 /* Add a member function to the proper fieldlist. */
8716 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
8717 struct type
*type
, struct dwarf2_cu
*cu
)
8719 struct objfile
*objfile
= cu
->objfile
;
8720 struct attribute
*attr
;
8721 struct fnfieldlist
*flp
;
8723 struct fn_field
*fnp
;
8725 struct nextfnfield
*new_fnfield
;
8726 struct type
*this_type
;
8727 enum dwarf_access_attribute accessibility
;
8729 if (cu
->language
== language_ada
)
8730 error (_("unexpected member function in Ada type"));
8732 /* Get name of member function. */
8733 fieldname
= dwarf2_name (die
, cu
);
8734 if (fieldname
== NULL
)
8737 /* Look up member function name in fieldlist. */
8738 for (i
= 0; i
< fip
->nfnfields
; i
++)
8740 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
8744 /* Create new list element if necessary. */
8745 if (i
< fip
->nfnfields
)
8746 flp
= &fip
->fnfieldlists
[i
];
8749 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8751 fip
->fnfieldlists
= (struct fnfieldlist
*)
8752 xrealloc (fip
->fnfieldlists
,
8753 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
8754 * sizeof (struct fnfieldlist
));
8755 if (fip
->nfnfields
== 0)
8756 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
8758 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
8759 flp
->name
= fieldname
;
8762 i
= fip
->nfnfields
++;
8765 /* Create a new member function field and chain it to the field list
8767 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
8768 make_cleanup (xfree
, new_fnfield
);
8769 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
8770 new_fnfield
->next
= flp
->head
;
8771 flp
->head
= new_fnfield
;
8774 /* Fill in the member function field info. */
8775 fnp
= &new_fnfield
->fnfield
;
8777 /* Delay processing of the physname until later. */
8778 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
8780 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
8785 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
8786 fnp
->physname
= physname
? physname
: "";
8789 fnp
->type
= alloc_type (objfile
);
8790 this_type
= read_type_die (die
, cu
);
8791 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
8793 int nparams
= TYPE_NFIELDS (this_type
);
8795 /* TYPE is the domain of this method, and THIS_TYPE is the type
8796 of the method itself (TYPE_CODE_METHOD). */
8797 smash_to_method_type (fnp
->type
, type
,
8798 TYPE_TARGET_TYPE (this_type
),
8799 TYPE_FIELDS (this_type
),
8800 TYPE_NFIELDS (this_type
),
8801 TYPE_VARARGS (this_type
));
8803 /* Handle static member functions.
8804 Dwarf2 has no clean way to discern C++ static and non-static
8805 member functions. G++ helps GDB by marking the first
8806 parameter for non-static member functions (which is the this
8807 pointer) as artificial. We obtain this information from
8808 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
8809 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
8810 fnp
->voffset
= VOFFSET_STATIC
;
8813 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
8814 dwarf2_full_name (fieldname
, die
, cu
));
8816 /* Get fcontext from DW_AT_containing_type if present. */
8817 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
8818 fnp
->fcontext
= die_containing_type (die
, cu
);
8820 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
8821 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
8823 /* Get accessibility. */
8824 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8826 accessibility
= DW_UNSND (attr
);
8828 accessibility
= dwarf2_default_access_attribute (die
, cu
);
8829 switch (accessibility
)
8831 case DW_ACCESS_private
:
8832 fnp
->is_private
= 1;
8834 case DW_ACCESS_protected
:
8835 fnp
->is_protected
= 1;
8839 /* Check for artificial methods. */
8840 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
8841 if (attr
&& DW_UNSND (attr
) != 0)
8842 fnp
->is_artificial
= 1;
8844 /* Get index in virtual function table if it is a virtual member
8845 function. For older versions of GCC, this is an offset in the
8846 appropriate virtual table, as specified by DW_AT_containing_type.
8847 For everyone else, it is an expression to be evaluated relative
8848 to the object address. */
8850 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
8853 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
8855 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
8857 /* Old-style GCC. */
8858 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
8860 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
8861 || (DW_BLOCK (attr
)->size
> 1
8862 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
8863 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
8865 struct dwarf_block blk
;
8868 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
8870 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
8871 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
8872 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8873 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
8874 dwarf2_complex_location_expr_complaint ();
8876 fnp
->voffset
/= cu
->header
.addr_size
;
8880 dwarf2_complex_location_expr_complaint ();
8883 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
8885 else if (attr_form_is_section_offset (attr
))
8887 dwarf2_complex_location_expr_complaint ();
8891 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
8897 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8898 if (attr
&& DW_UNSND (attr
))
8900 /* GCC does this, as of 2008-08-25; PR debug/37237. */
8901 complaint (&symfile_complaints
,
8902 _("Member function \"%s\" (offset %d) is virtual "
8903 "but the vtable offset is not specified"),
8904 fieldname
, die
->offset
.sect_off
);
8905 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8906 TYPE_CPLUS_DYNAMIC (type
) = 1;
8911 /* Create the vector of member function fields, and attach it to the type. */
8914 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
8915 struct dwarf2_cu
*cu
)
8917 struct fnfieldlist
*flp
;
8920 if (cu
->language
== language_ada
)
8921 error (_("unexpected member functions in Ada type"));
8923 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8924 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
8925 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
8927 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
8929 struct nextfnfield
*nfp
= flp
->head
;
8930 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
8933 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
8934 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
8935 fn_flp
->fn_fields
= (struct fn_field
*)
8936 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
8937 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
8938 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
8941 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
8944 /* Returns non-zero if NAME is the name of a vtable member in CU's
8945 language, zero otherwise. */
8947 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
8949 static const char vptr
[] = "_vptr";
8950 static const char vtable
[] = "vtable";
8952 /* Look for the C++ and Java forms of the vtable. */
8953 if ((cu
->language
== language_java
8954 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
8955 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
8956 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
8962 /* GCC outputs unnamed structures that are really pointers to member
8963 functions, with the ABI-specified layout. If TYPE describes
8964 such a structure, smash it into a member function type.
8966 GCC shouldn't do this; it should just output pointer to member DIEs.
8967 This is GCC PR debug/28767. */
8970 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
8972 struct type
*pfn_type
, *domain_type
, *new_type
;
8974 /* Check for a structure with no name and two children. */
8975 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
8978 /* Check for __pfn and __delta members. */
8979 if (TYPE_FIELD_NAME (type
, 0) == NULL
8980 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
8981 || TYPE_FIELD_NAME (type
, 1) == NULL
8982 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
8985 /* Find the type of the method. */
8986 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
8987 if (pfn_type
== NULL
8988 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
8989 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
8992 /* Look for the "this" argument. */
8993 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
8994 if (TYPE_NFIELDS (pfn_type
) == 0
8995 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
8996 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
8999 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
9000 new_type
= alloc_type (objfile
);
9001 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
9002 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
9003 TYPE_VARARGS (pfn_type
));
9004 smash_to_methodptr_type (type
, new_type
);
9007 /* Called when we find the DIE that starts a structure or union scope
9008 (definition) to create a type for the structure or union. Fill in
9009 the type's name and general properties; the members will not be
9010 processed until process_structure_type.
9012 NOTE: we need to call these functions regardless of whether or not the
9013 DIE has a DW_AT_name attribute, since it might be an anonymous
9014 structure or union. This gets the type entered into our set of
9017 However, if the structure is incomplete (an opaque struct/union)
9018 then suppress creating a symbol table entry for it since gdb only
9019 wants to find the one with the complete definition. Note that if
9020 it is complete, we just call new_symbol, which does it's own
9021 checking about whether the struct/union is anonymous or not (and
9022 suppresses creating a symbol table entry itself). */
9024 static struct type
*
9025 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9027 struct objfile
*objfile
= cu
->objfile
;
9029 struct attribute
*attr
;
9032 /* If the definition of this type lives in .debug_types, read that type.
9033 Don't follow DW_AT_specification though, that will take us back up
9034 the chain and we want to go down. */
9035 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9038 struct dwarf2_cu
*type_cu
= cu
;
9039 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9041 /* We could just recurse on read_structure_type, but we need to call
9042 get_die_type to ensure only one type for this DIE is created.
9043 This is important, for example, because for c++ classes we need
9044 TYPE_NAME set which is only done by new_symbol. Blech. */
9045 type
= read_type_die (type_die
, type_cu
);
9047 /* TYPE_CU may not be the same as CU.
9048 Ensure TYPE is recorded in CU's type_hash table. */
9049 return set_die_type (die
, type
, cu
);
9052 type
= alloc_type (objfile
);
9053 INIT_CPLUS_SPECIFIC (type
);
9055 name
= dwarf2_name (die
, cu
);
9058 if (cu
->language
== language_cplus
9059 || cu
->language
== language_java
)
9061 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
9063 /* dwarf2_full_name might have already finished building the DIE's
9064 type. If so, there is no need to continue. */
9065 if (get_die_type (die
, cu
) != NULL
)
9066 return get_die_type (die
, cu
);
9068 TYPE_TAG_NAME (type
) = full_name
;
9069 if (die
->tag
== DW_TAG_structure_type
9070 || die
->tag
== DW_TAG_class_type
)
9071 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
9075 /* The name is already allocated along with this objfile, so
9076 we don't need to duplicate it for the type. */
9077 TYPE_TAG_NAME (type
) = (char *) name
;
9078 if (die
->tag
== DW_TAG_class_type
)
9079 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
9083 if (die
->tag
== DW_TAG_structure_type
)
9085 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9087 else if (die
->tag
== DW_TAG_union_type
)
9089 TYPE_CODE (type
) = TYPE_CODE_UNION
;
9093 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
9096 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
9097 TYPE_DECLARED_CLASS (type
) = 1;
9099 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9102 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9106 TYPE_LENGTH (type
) = 0;
9109 TYPE_STUB_SUPPORTED (type
) = 1;
9110 if (die_is_declaration (die
, cu
))
9111 TYPE_STUB (type
) = 1;
9112 else if (attr
== NULL
&& die
->child
== NULL
9113 && producer_is_realview (cu
->producer
))
9114 /* RealView does not output the required DW_AT_declaration
9115 on incomplete types. */
9116 TYPE_STUB (type
) = 1;
9118 /* We need to add the type field to the die immediately so we don't
9119 infinitely recurse when dealing with pointers to the structure
9120 type within the structure itself. */
9121 set_die_type (die
, type
, cu
);
9123 /* set_die_type should be already done. */
9124 set_descriptive_type (type
, die
, cu
);
9129 /* Finish creating a structure or union type, including filling in
9130 its members and creating a symbol for it. */
9133 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9135 struct objfile
*objfile
= cu
->objfile
;
9136 struct die_info
*child_die
= die
->child
;
9139 type
= get_die_type (die
, cu
);
9141 type
= read_structure_type (die
, cu
);
9143 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
9145 struct field_info fi
;
9146 struct die_info
*child_die
;
9147 VEC (symbolp
) *template_args
= NULL
;
9148 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
9150 memset (&fi
, 0, sizeof (struct field_info
));
9152 child_die
= die
->child
;
9154 while (child_die
&& child_die
->tag
)
9156 if (child_die
->tag
== DW_TAG_member
9157 || child_die
->tag
== DW_TAG_variable
)
9159 /* NOTE: carlton/2002-11-05: A C++ static data member
9160 should be a DW_TAG_member that is a declaration, but
9161 all versions of G++ as of this writing (so through at
9162 least 3.2.1) incorrectly generate DW_TAG_variable
9163 tags for them instead. */
9164 dwarf2_add_field (&fi
, child_die
, cu
);
9166 else if (child_die
->tag
== DW_TAG_subprogram
)
9168 /* C++ member function. */
9169 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
9171 else if (child_die
->tag
== DW_TAG_inheritance
)
9173 /* C++ base class field. */
9174 dwarf2_add_field (&fi
, child_die
, cu
);
9176 else if (child_die
->tag
== DW_TAG_typedef
)
9177 dwarf2_add_typedef (&fi
, child_die
, cu
);
9178 else if (child_die
->tag
== DW_TAG_template_type_param
9179 || child_die
->tag
== DW_TAG_template_value_param
)
9181 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
9184 VEC_safe_push (symbolp
, template_args
, arg
);
9187 child_die
= sibling_die (child_die
);
9190 /* Attach template arguments to type. */
9191 if (! VEC_empty (symbolp
, template_args
))
9193 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9194 TYPE_N_TEMPLATE_ARGUMENTS (type
)
9195 = VEC_length (symbolp
, template_args
);
9196 TYPE_TEMPLATE_ARGUMENTS (type
)
9197 = obstack_alloc (&objfile
->objfile_obstack
,
9198 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
9199 * sizeof (struct symbol
*)));
9200 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
9201 VEC_address (symbolp
, template_args
),
9202 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
9203 * sizeof (struct symbol
*)));
9204 VEC_free (symbolp
, template_args
);
9207 /* Attach fields and member functions to the type. */
9209 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
9212 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
9214 /* Get the type which refers to the base class (possibly this
9215 class itself) which contains the vtable pointer for the current
9216 class from the DW_AT_containing_type attribute. This use of
9217 DW_AT_containing_type is a GNU extension. */
9219 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
9221 struct type
*t
= die_containing_type (die
, cu
);
9223 TYPE_VPTR_BASETYPE (type
) = t
;
9228 /* Our own class provides vtbl ptr. */
9229 for (i
= TYPE_NFIELDS (t
) - 1;
9230 i
>= TYPE_N_BASECLASSES (t
);
9233 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
9235 if (is_vtable_name (fieldname
, cu
))
9237 TYPE_VPTR_FIELDNO (type
) = i
;
9242 /* Complain if virtual function table field not found. */
9243 if (i
< TYPE_N_BASECLASSES (t
))
9244 complaint (&symfile_complaints
,
9245 _("virtual function table pointer "
9246 "not found when defining class '%s'"),
9247 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
9252 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
9255 else if (cu
->producer
9256 && strncmp (cu
->producer
,
9257 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
9259 /* The IBM XLC compiler does not provide direct indication
9260 of the containing type, but the vtable pointer is
9261 always named __vfp. */
9265 for (i
= TYPE_NFIELDS (type
) - 1;
9266 i
>= TYPE_N_BASECLASSES (type
);
9269 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
9271 TYPE_VPTR_FIELDNO (type
) = i
;
9272 TYPE_VPTR_BASETYPE (type
) = type
;
9279 /* Copy fi.typedef_field_list linked list elements content into the
9280 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
9281 if (fi
.typedef_field_list
)
9283 int i
= fi
.typedef_field_list_count
;
9285 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9286 TYPE_TYPEDEF_FIELD_ARRAY (type
)
9287 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
9288 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
9290 /* Reverse the list order to keep the debug info elements order. */
9293 struct typedef_field
*dest
, *src
;
9295 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
9296 src
= &fi
.typedef_field_list
->field
;
9297 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
9302 do_cleanups (back_to
);
9304 if (HAVE_CPLUS_STRUCT (type
))
9305 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
9308 quirk_gcc_member_function_pointer (type
, objfile
);
9310 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
9311 snapshots) has been known to create a die giving a declaration
9312 for a class that has, as a child, a die giving a definition for a
9313 nested class. So we have to process our children even if the
9314 current die is a declaration. Normally, of course, a declaration
9315 won't have any children at all. */
9317 while (child_die
!= NULL
&& child_die
->tag
)
9319 if (child_die
->tag
== DW_TAG_member
9320 || child_die
->tag
== DW_TAG_variable
9321 || child_die
->tag
== DW_TAG_inheritance
9322 || child_die
->tag
== DW_TAG_template_value_param
9323 || child_die
->tag
== DW_TAG_template_type_param
)
9328 process_die (child_die
, cu
);
9330 child_die
= sibling_die (child_die
);
9333 /* Do not consider external references. According to the DWARF standard,
9334 these DIEs are identified by the fact that they have no byte_size
9335 attribute, and a declaration attribute. */
9336 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
9337 || !die_is_declaration (die
, cu
))
9338 new_symbol (die
, type
, cu
);
9341 /* Given a DW_AT_enumeration_type die, set its type. We do not
9342 complete the type's fields yet, or create any symbols. */
9344 static struct type
*
9345 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9347 struct objfile
*objfile
= cu
->objfile
;
9349 struct attribute
*attr
;
9352 /* If the definition of this type lives in .debug_types, read that type.
9353 Don't follow DW_AT_specification though, that will take us back up
9354 the chain and we want to go down. */
9355 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9358 struct dwarf2_cu
*type_cu
= cu
;
9359 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9361 type
= read_type_die (type_die
, type_cu
);
9363 /* TYPE_CU may not be the same as CU.
9364 Ensure TYPE is recorded in CU's type_hash table. */
9365 return set_die_type (die
, type
, cu
);
9368 type
= alloc_type (objfile
);
9370 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
9371 name
= dwarf2_full_name (NULL
, die
, cu
);
9373 TYPE_TAG_NAME (type
) = (char *) name
;
9375 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9378 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9382 TYPE_LENGTH (type
) = 0;
9385 /* The enumeration DIE can be incomplete. In Ada, any type can be
9386 declared as private in the package spec, and then defined only
9387 inside the package body. Such types are known as Taft Amendment
9388 Types. When another package uses such a type, an incomplete DIE
9389 may be generated by the compiler. */
9390 if (die_is_declaration (die
, cu
))
9391 TYPE_STUB (type
) = 1;
9393 return set_die_type (die
, type
, cu
);
9396 /* Given a pointer to a die which begins an enumeration, process all
9397 the dies that define the members of the enumeration, and create the
9398 symbol for the enumeration type.
9400 NOTE: We reverse the order of the element list. */
9403 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9405 struct type
*this_type
;
9407 this_type
= get_die_type (die
, cu
);
9408 if (this_type
== NULL
)
9409 this_type
= read_enumeration_type (die
, cu
);
9411 if (die
->child
!= NULL
)
9413 struct die_info
*child_die
;
9415 struct field
*fields
= NULL
;
9417 int unsigned_enum
= 1;
9422 child_die
= die
->child
;
9423 while (child_die
&& child_die
->tag
)
9425 if (child_die
->tag
!= DW_TAG_enumerator
)
9427 process_die (child_die
, cu
);
9431 name
= dwarf2_name (child_die
, cu
);
9434 sym
= new_symbol (child_die
, this_type
, cu
);
9435 if (SYMBOL_VALUE (sym
) < 0)
9440 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
9443 mask
|= SYMBOL_VALUE (sym
);
9445 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9447 fields
= (struct field
*)
9449 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
9450 * sizeof (struct field
));
9453 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
9454 FIELD_TYPE (fields
[num_fields
]) = NULL
;
9455 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
9456 FIELD_BITSIZE (fields
[num_fields
]) = 0;
9462 child_die
= sibling_die (child_die
);
9467 TYPE_NFIELDS (this_type
) = num_fields
;
9468 TYPE_FIELDS (this_type
) = (struct field
*)
9469 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
9470 memcpy (TYPE_FIELDS (this_type
), fields
,
9471 sizeof (struct field
) * num_fields
);
9475 TYPE_UNSIGNED (this_type
) = 1;
9477 TYPE_FLAG_ENUM (this_type
) = 1;
9480 /* If we are reading an enum from a .debug_types unit, and the enum
9481 is a declaration, and the enum is not the signatured type in the
9482 unit, then we do not want to add a symbol for it. Adding a
9483 symbol would in some cases obscure the true definition of the
9484 enum, giving users an incomplete type when the definition is
9485 actually available. Note that we do not want to do this for all
9486 enums which are just declarations, because C++0x allows forward
9487 enum declarations. */
9488 if (cu
->per_cu
->is_debug_types
9489 && die_is_declaration (die
, cu
))
9491 struct signatured_type
*sig_type
;
9494 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
9495 cu
->per_cu
->info_or_types_section
,
9496 cu
->per_cu
->offset
);
9497 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
9498 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
9502 new_symbol (die
, this_type
, cu
);
9505 /* Extract all information from a DW_TAG_array_type DIE and put it in
9506 the DIE's type field. For now, this only handles one dimensional
9509 static struct type
*
9510 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9512 struct objfile
*objfile
= cu
->objfile
;
9513 struct die_info
*child_die
;
9515 struct type
*element_type
, *range_type
, *index_type
;
9516 struct type
**range_types
= NULL
;
9517 struct attribute
*attr
;
9519 struct cleanup
*back_to
;
9522 element_type
= die_type (die
, cu
);
9524 /* The die_type call above may have already set the type for this DIE. */
9525 type
= get_die_type (die
, cu
);
9529 /* Irix 6.2 native cc creates array types without children for
9530 arrays with unspecified length. */
9531 if (die
->child
== NULL
)
9533 index_type
= objfile_type (objfile
)->builtin_int
;
9534 range_type
= create_range_type (NULL
, index_type
, 0, -1);
9535 type
= create_array_type (NULL
, element_type
, range_type
);
9536 return set_die_type (die
, type
, cu
);
9539 back_to
= make_cleanup (null_cleanup
, NULL
);
9540 child_die
= die
->child
;
9541 while (child_die
&& child_die
->tag
)
9543 if (child_die
->tag
== DW_TAG_subrange_type
)
9545 struct type
*child_type
= read_type_die (child_die
, cu
);
9547 if (child_type
!= NULL
)
9549 /* The range type was succesfully read. Save it for the
9550 array type creation. */
9551 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
9553 range_types
= (struct type
**)
9554 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
9555 * sizeof (struct type
*));
9557 make_cleanup (free_current_contents
, &range_types
);
9559 range_types
[ndim
++] = child_type
;
9562 child_die
= sibling_die (child_die
);
9565 /* Dwarf2 dimensions are output from left to right, create the
9566 necessary array types in backwards order. */
9568 type
= element_type
;
9570 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
9575 type
= create_array_type (NULL
, type
, range_types
[i
++]);
9580 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
9583 /* Understand Dwarf2 support for vector types (like they occur on
9584 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
9585 array type. This is not part of the Dwarf2/3 standard yet, but a
9586 custom vendor extension. The main difference between a regular
9587 array and the vector variant is that vectors are passed by value
9589 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
9591 make_vector_type (type
);
9593 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
9594 implementation may choose to implement triple vectors using this
9596 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9599 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
9600 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9602 complaint (&symfile_complaints
,
9603 _("DW_AT_byte_size for array type smaller "
9604 "than the total size of elements"));
9607 name
= dwarf2_name (die
, cu
);
9609 TYPE_NAME (type
) = name
;
9611 /* Install the type in the die. */
9612 set_die_type (die
, type
, cu
);
9614 /* set_die_type should be already done. */
9615 set_descriptive_type (type
, die
, cu
);
9617 do_cleanups (back_to
);
9622 static enum dwarf_array_dim_ordering
9623 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
9625 struct attribute
*attr
;
9627 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
9629 if (attr
) return DW_SND (attr
);
9631 /* GNU F77 is a special case, as at 08/2004 array type info is the
9632 opposite order to the dwarf2 specification, but data is still
9633 laid out as per normal fortran.
9635 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
9636 version checking. */
9638 if (cu
->language
== language_fortran
9639 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
9641 return DW_ORD_row_major
;
9644 switch (cu
->language_defn
->la_array_ordering
)
9646 case array_column_major
:
9647 return DW_ORD_col_major
;
9648 case array_row_major
:
9650 return DW_ORD_row_major
;
9654 /* Extract all information from a DW_TAG_set_type DIE and put it in
9655 the DIE's type field. */
9657 static struct type
*
9658 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9660 struct type
*domain_type
, *set_type
;
9661 struct attribute
*attr
;
9663 domain_type
= die_type (die
, cu
);
9665 /* The die_type call above may have already set the type for this DIE. */
9666 set_type
= get_die_type (die
, cu
);
9670 set_type
= create_set_type (NULL
, domain_type
);
9672 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9674 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
9676 return set_die_type (die
, set_type
, cu
);
9679 /* First cut: install each common block member as a global variable. */
9682 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
9684 struct die_info
*child_die
;
9685 struct attribute
*attr
;
9687 CORE_ADDR base
= (CORE_ADDR
) 0;
9689 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
9692 /* Support the .debug_loc offsets. */
9693 if (attr_form_is_block (attr
))
9695 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
9697 else if (attr_form_is_section_offset (attr
))
9699 dwarf2_complex_location_expr_complaint ();
9703 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9704 "common block member");
9707 if (die
->child
!= NULL
)
9709 child_die
= die
->child
;
9710 while (child_die
&& child_die
->tag
)
9714 sym
= new_symbol (child_die
, NULL
, cu
);
9716 && handle_data_member_location (child_die
, cu
, &offset
))
9718 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
9719 add_symbol_to_list (sym
, &global_symbols
);
9721 child_die
= sibling_die (child_die
);
9726 /* Create a type for a C++ namespace. */
9728 static struct type
*
9729 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9731 struct objfile
*objfile
= cu
->objfile
;
9732 const char *previous_prefix
, *name
;
9736 /* For extensions, reuse the type of the original namespace. */
9737 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
9739 struct die_info
*ext_die
;
9740 struct dwarf2_cu
*ext_cu
= cu
;
9742 ext_die
= dwarf2_extension (die
, &ext_cu
);
9743 type
= read_type_die (ext_die
, ext_cu
);
9745 /* EXT_CU may not be the same as CU.
9746 Ensure TYPE is recorded in CU's type_hash table. */
9747 return set_die_type (die
, type
, cu
);
9750 name
= namespace_name (die
, &is_anonymous
, cu
);
9752 /* Now build the name of the current namespace. */
9754 previous_prefix
= determine_prefix (die
, cu
);
9755 if (previous_prefix
[0] != '\0')
9756 name
= typename_concat (&objfile
->objfile_obstack
,
9757 previous_prefix
, name
, 0, cu
);
9759 /* Create the type. */
9760 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
9762 TYPE_NAME (type
) = (char *) name
;
9763 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9765 return set_die_type (die
, type
, cu
);
9768 /* Read a C++ namespace. */
9771 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9773 struct objfile
*objfile
= cu
->objfile
;
9776 /* Add a symbol associated to this if we haven't seen the namespace
9777 before. Also, add a using directive if it's an anonymous
9780 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
9784 type
= read_type_die (die
, cu
);
9785 new_symbol (die
, type
, cu
);
9787 namespace_name (die
, &is_anonymous
, cu
);
9790 const char *previous_prefix
= determine_prefix (die
, cu
);
9792 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
9793 NULL
, NULL
, &objfile
->objfile_obstack
);
9797 if (die
->child
!= NULL
)
9799 struct die_info
*child_die
= die
->child
;
9801 while (child_die
&& child_die
->tag
)
9803 process_die (child_die
, cu
);
9804 child_die
= sibling_die (child_die
);
9809 /* Read a Fortran module as type. This DIE can be only a declaration used for
9810 imported module. Still we need that type as local Fortran "use ... only"
9811 declaration imports depend on the created type in determine_prefix. */
9813 static struct type
*
9814 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9816 struct objfile
*objfile
= cu
->objfile
;
9820 module_name
= dwarf2_name (die
, cu
);
9822 complaint (&symfile_complaints
,
9823 _("DW_TAG_module has no name, offset 0x%x"),
9824 die
->offset
.sect_off
);
9825 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
9827 /* determine_prefix uses TYPE_TAG_NAME. */
9828 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9830 return set_die_type (die
, type
, cu
);
9833 /* Read a Fortran module. */
9836 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
9838 struct die_info
*child_die
= die
->child
;
9840 while (child_die
&& child_die
->tag
)
9842 process_die (child_die
, cu
);
9843 child_die
= sibling_die (child_die
);
9847 /* Return the name of the namespace represented by DIE. Set
9848 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
9852 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
9854 struct die_info
*current_die
;
9855 const char *name
= NULL
;
9857 /* Loop through the extensions until we find a name. */
9859 for (current_die
= die
;
9860 current_die
!= NULL
;
9861 current_die
= dwarf2_extension (die
, &cu
))
9863 name
= dwarf2_name (current_die
, cu
);
9868 /* Is it an anonymous namespace? */
9870 *is_anonymous
= (name
== NULL
);
9872 name
= CP_ANONYMOUS_NAMESPACE_STR
;
9877 /* Extract all information from a DW_TAG_pointer_type DIE and add to
9878 the user defined type vector. */
9880 static struct type
*
9881 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9883 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9884 struct comp_unit_head
*cu_header
= &cu
->header
;
9886 struct attribute
*attr_byte_size
;
9887 struct attribute
*attr_address_class
;
9888 int byte_size
, addr_class
;
9889 struct type
*target_type
;
9891 target_type
= die_type (die
, cu
);
9893 /* The die_type call above may have already set the type for this DIE. */
9894 type
= get_die_type (die
, cu
);
9898 type
= lookup_pointer_type (target_type
);
9900 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9902 byte_size
= DW_UNSND (attr_byte_size
);
9904 byte_size
= cu_header
->addr_size
;
9906 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
9907 if (attr_address_class
)
9908 addr_class
= DW_UNSND (attr_address_class
);
9910 addr_class
= DW_ADDR_none
;
9912 /* If the pointer size or address class is different than the
9913 default, create a type variant marked as such and set the
9914 length accordingly. */
9915 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
9917 if (gdbarch_address_class_type_flags_p (gdbarch
))
9921 type_flags
= gdbarch_address_class_type_flags
9922 (gdbarch
, byte_size
, addr_class
);
9923 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
9925 type
= make_type_with_address_space (type
, type_flags
);
9927 else if (TYPE_LENGTH (type
) != byte_size
)
9929 complaint (&symfile_complaints
,
9930 _("invalid pointer size %d"), byte_size
);
9934 /* Should we also complain about unhandled address classes? */
9938 TYPE_LENGTH (type
) = byte_size
;
9939 return set_die_type (die
, type
, cu
);
9942 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
9943 the user defined type vector. */
9945 static struct type
*
9946 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9949 struct type
*to_type
;
9950 struct type
*domain
;
9952 to_type
= die_type (die
, cu
);
9953 domain
= die_containing_type (die
, cu
);
9955 /* The calls above may have already set the type for this DIE. */
9956 type
= get_die_type (die
, cu
);
9960 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
9961 type
= lookup_methodptr_type (to_type
);
9963 type
= lookup_memberptr_type (to_type
, domain
);
9965 return set_die_type (die
, type
, cu
);
9968 /* Extract all information from a DW_TAG_reference_type DIE and add to
9969 the user defined type vector. */
9971 static struct type
*
9972 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9974 struct comp_unit_head
*cu_header
= &cu
->header
;
9975 struct type
*type
, *target_type
;
9976 struct attribute
*attr
;
9978 target_type
= die_type (die
, cu
);
9980 /* The die_type call above may have already set the type for this DIE. */
9981 type
= get_die_type (die
, cu
);
9985 type
= lookup_reference_type (target_type
);
9986 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9989 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9993 TYPE_LENGTH (type
) = cu_header
->addr_size
;
9995 return set_die_type (die
, type
, cu
);
9998 static struct type
*
9999 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10001 struct type
*base_type
, *cv_type
;
10003 base_type
= die_type (die
, cu
);
10005 /* The die_type call above may have already set the type for this DIE. */
10006 cv_type
= get_die_type (die
, cu
);
10010 /* In case the const qualifier is applied to an array type, the element type
10011 is so qualified, not the array type (section 6.7.3 of C99). */
10012 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
10014 struct type
*el_type
, *inner_array
;
10016 base_type
= copy_type (base_type
);
10017 inner_array
= base_type
;
10019 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
10021 TYPE_TARGET_TYPE (inner_array
) =
10022 copy_type (TYPE_TARGET_TYPE (inner_array
));
10023 inner_array
= TYPE_TARGET_TYPE (inner_array
);
10026 el_type
= TYPE_TARGET_TYPE (inner_array
);
10027 TYPE_TARGET_TYPE (inner_array
) =
10028 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
10030 return set_die_type (die
, base_type
, cu
);
10033 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
10034 return set_die_type (die
, cv_type
, cu
);
10037 static struct type
*
10038 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10040 struct type
*base_type
, *cv_type
;
10042 base_type
= die_type (die
, cu
);
10044 /* The die_type call above may have already set the type for this DIE. */
10045 cv_type
= get_die_type (die
, cu
);
10049 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
10050 return set_die_type (die
, cv_type
, cu
);
10053 /* Extract all information from a DW_TAG_string_type DIE and add to
10054 the user defined type vector. It isn't really a user defined type,
10055 but it behaves like one, with other DIE's using an AT_user_def_type
10056 attribute to reference it. */
10058 static struct type
*
10059 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10061 struct objfile
*objfile
= cu
->objfile
;
10062 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10063 struct type
*type
, *range_type
, *index_type
, *char_type
;
10064 struct attribute
*attr
;
10065 unsigned int length
;
10067 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
10070 length
= DW_UNSND (attr
);
10074 /* Check for the DW_AT_byte_size attribute. */
10075 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10078 length
= DW_UNSND (attr
);
10086 index_type
= objfile_type (objfile
)->builtin_int
;
10087 range_type
= create_range_type (NULL
, index_type
, 1, length
);
10088 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
10089 type
= create_string_type (NULL
, char_type
, range_type
);
10091 return set_die_type (die
, type
, cu
);
10094 /* Handle DIES due to C code like:
10098 int (*funcp)(int a, long l);
10102 ('funcp' generates a DW_TAG_subroutine_type DIE). */
10104 static struct type
*
10105 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10107 struct objfile
*objfile
= cu
->objfile
;
10108 struct type
*type
; /* Type that this function returns. */
10109 struct type
*ftype
; /* Function that returns above type. */
10110 struct attribute
*attr
;
10112 type
= die_type (die
, cu
);
10114 /* The die_type call above may have already set the type for this DIE. */
10115 ftype
= get_die_type (die
, cu
);
10119 ftype
= lookup_function_type (type
);
10121 /* All functions in C++, Pascal and Java have prototypes. */
10122 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
10123 if ((attr
&& (DW_UNSND (attr
) != 0))
10124 || cu
->language
== language_cplus
10125 || cu
->language
== language_java
10126 || cu
->language
== language_pascal
)
10127 TYPE_PROTOTYPED (ftype
) = 1;
10128 else if (producer_is_realview (cu
->producer
))
10129 /* RealView does not emit DW_AT_prototyped. We can not
10130 distinguish prototyped and unprototyped functions; default to
10131 prototyped, since that is more common in modern code (and
10132 RealView warns about unprototyped functions). */
10133 TYPE_PROTOTYPED (ftype
) = 1;
10135 /* Store the calling convention in the type if it's available in
10136 the subroutine die. Otherwise set the calling convention to
10137 the default value DW_CC_normal. */
10138 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
10140 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
10141 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
10142 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
10144 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
10146 /* We need to add the subroutine type to the die immediately so
10147 we don't infinitely recurse when dealing with parameters
10148 declared as the same subroutine type. */
10149 set_die_type (die
, ftype
, cu
);
10151 if (die
->child
!= NULL
)
10153 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
10154 struct die_info
*child_die
;
10155 int nparams
, iparams
;
10157 /* Count the number of parameters.
10158 FIXME: GDB currently ignores vararg functions, but knows about
10159 vararg member functions. */
10161 child_die
= die
->child
;
10162 while (child_die
&& child_die
->tag
)
10164 if (child_die
->tag
== DW_TAG_formal_parameter
)
10166 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
10167 TYPE_VARARGS (ftype
) = 1;
10168 child_die
= sibling_die (child_die
);
10171 /* Allocate storage for parameters and fill them in. */
10172 TYPE_NFIELDS (ftype
) = nparams
;
10173 TYPE_FIELDS (ftype
) = (struct field
*)
10174 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
10176 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
10177 even if we error out during the parameters reading below. */
10178 for (iparams
= 0; iparams
< nparams
; iparams
++)
10179 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
10182 child_die
= die
->child
;
10183 while (child_die
&& child_die
->tag
)
10185 if (child_die
->tag
== DW_TAG_formal_parameter
)
10187 struct type
*arg_type
;
10189 /* DWARF version 2 has no clean way to discern C++
10190 static and non-static member functions. G++ helps
10191 GDB by marking the first parameter for non-static
10192 member functions (which is the this pointer) as
10193 artificial. We pass this information to
10194 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
10196 DWARF version 3 added DW_AT_object_pointer, which GCC
10197 4.5 does not yet generate. */
10198 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
10200 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
10203 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
10205 /* GCC/43521: In java, the formal parameter
10206 "this" is sometimes not marked with DW_AT_artificial. */
10207 if (cu
->language
== language_java
)
10209 const char *name
= dwarf2_name (child_die
, cu
);
10211 if (name
&& !strcmp (name
, "this"))
10212 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
10215 arg_type
= die_type (child_die
, cu
);
10217 /* RealView does not mark THIS as const, which the testsuite
10218 expects. GCC marks THIS as const in method definitions,
10219 but not in the class specifications (GCC PR 43053). */
10220 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
10221 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
10224 struct dwarf2_cu
*arg_cu
= cu
;
10225 const char *name
= dwarf2_name (child_die
, cu
);
10227 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
10230 /* If the compiler emits this, use it. */
10231 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
10234 else if (name
&& strcmp (name
, "this") == 0)
10235 /* Function definitions will have the argument names. */
10237 else if (name
== NULL
&& iparams
== 0)
10238 /* Declarations may not have the names, so like
10239 elsewhere in GDB, assume an artificial first
10240 argument is "this". */
10244 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
10248 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
10251 child_die
= sibling_die (child_die
);
10258 static struct type
*
10259 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
10261 struct objfile
*objfile
= cu
->objfile
;
10262 const char *name
= NULL
;
10263 struct type
*this_type
, *target_type
;
10265 name
= dwarf2_full_name (NULL
, die
, cu
);
10266 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
10267 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
10268 TYPE_NAME (this_type
) = (char *) name
;
10269 set_die_type (die
, this_type
, cu
);
10270 target_type
= die_type (die
, cu
);
10271 if (target_type
!= this_type
)
10272 TYPE_TARGET_TYPE (this_type
) = target_type
;
10275 /* Self-referential typedefs are, it seems, not allowed by the DWARF
10276 spec and cause infinite loops in GDB. */
10277 complaint (&symfile_complaints
,
10278 _("Self-referential DW_TAG_typedef "
10279 "- DIE at 0x%x [in module %s]"),
10280 die
->offset
.sect_off
, objfile
->name
);
10281 TYPE_TARGET_TYPE (this_type
) = NULL
;
10286 /* Find a representation of a given base type and install
10287 it in the TYPE field of the die. */
10289 static struct type
*
10290 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10292 struct objfile
*objfile
= cu
->objfile
;
10294 struct attribute
*attr
;
10295 int encoding
= 0, size
= 0;
10297 enum type_code code
= TYPE_CODE_INT
;
10298 int type_flags
= 0;
10299 struct type
*target_type
= NULL
;
10301 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
10304 encoding
= DW_UNSND (attr
);
10306 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10309 size
= DW_UNSND (attr
);
10311 name
= dwarf2_name (die
, cu
);
10314 complaint (&symfile_complaints
,
10315 _("DW_AT_name missing from DW_TAG_base_type"));
10320 case DW_ATE_address
:
10321 /* Turn DW_ATE_address into a void * pointer. */
10322 code
= TYPE_CODE_PTR
;
10323 type_flags
|= TYPE_FLAG_UNSIGNED
;
10324 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
10326 case DW_ATE_boolean
:
10327 code
= TYPE_CODE_BOOL
;
10328 type_flags
|= TYPE_FLAG_UNSIGNED
;
10330 case DW_ATE_complex_float
:
10331 code
= TYPE_CODE_COMPLEX
;
10332 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
10334 case DW_ATE_decimal_float
:
10335 code
= TYPE_CODE_DECFLOAT
;
10338 code
= TYPE_CODE_FLT
;
10340 case DW_ATE_signed
:
10342 case DW_ATE_unsigned
:
10343 type_flags
|= TYPE_FLAG_UNSIGNED
;
10344 if (cu
->language
== language_fortran
10346 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
10347 code
= TYPE_CODE_CHAR
;
10349 case DW_ATE_signed_char
:
10350 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10351 || cu
->language
== language_pascal
10352 || cu
->language
== language_fortran
)
10353 code
= TYPE_CODE_CHAR
;
10355 case DW_ATE_unsigned_char
:
10356 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10357 || cu
->language
== language_pascal
10358 || cu
->language
== language_fortran
)
10359 code
= TYPE_CODE_CHAR
;
10360 type_flags
|= TYPE_FLAG_UNSIGNED
;
10363 /* We just treat this as an integer and then recognize the
10364 type by name elsewhere. */
10368 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
10369 dwarf_type_encoding_name (encoding
));
10373 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
10374 TYPE_NAME (type
) = name
;
10375 TYPE_TARGET_TYPE (type
) = target_type
;
10377 if (name
&& strcmp (name
, "char") == 0)
10378 TYPE_NOSIGN (type
) = 1;
10380 return set_die_type (die
, type
, cu
);
10383 /* Read the given DW_AT_subrange DIE. */
10385 static struct type
*
10386 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10388 struct type
*base_type
;
10389 struct type
*range_type
;
10390 struct attribute
*attr
;
10392 int low_default_is_valid
;
10394 LONGEST negative_mask
;
10396 base_type
= die_type (die
, cu
);
10397 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
10398 check_typedef (base_type
);
10400 /* The die_type call above may have already set the type for this DIE. */
10401 range_type
= get_die_type (die
, cu
);
10405 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
10406 omitting DW_AT_lower_bound. */
10407 switch (cu
->language
)
10410 case language_cplus
:
10412 low_default_is_valid
= 1;
10414 case language_fortran
:
10416 low_default_is_valid
= 1;
10419 case language_java
:
10420 case language_objc
:
10422 low_default_is_valid
= (cu
->header
.version
>= 4);
10426 case language_pascal
:
10428 low_default_is_valid
= (cu
->header
.version
>= 4);
10432 low_default_is_valid
= 0;
10436 /* FIXME: For variable sized arrays either of these could be
10437 a variable rather than a constant value. We'll allow it,
10438 but we don't know how to handle it. */
10439 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
10441 low
= dwarf2_get_attr_constant_value (attr
, low
);
10442 else if (!low_default_is_valid
)
10443 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
10444 "- DIE at 0x%x [in module %s]"),
10445 die
->offset
.sect_off
, cu
->objfile
->name
);
10447 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
10450 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
10452 /* GCC encodes arrays with unspecified or dynamic length
10453 with a DW_FORM_block1 attribute or a reference attribute.
10454 FIXME: GDB does not yet know how to handle dynamic
10455 arrays properly, treat them as arrays with unspecified
10458 FIXME: jimb/2003-09-22: GDB does not really know
10459 how to handle arrays of unspecified length
10460 either; we just represent them as zero-length
10461 arrays. Choose an appropriate upper bound given
10462 the lower bound we've computed above. */
10466 high
= dwarf2_get_attr_constant_value (attr
, 1);
10470 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
10473 int count
= dwarf2_get_attr_constant_value (attr
, 1);
10474 high
= low
+ count
- 1;
10478 /* Unspecified array length. */
10483 /* Dwarf-2 specifications explicitly allows to create subrange types
10484 without specifying a base type.
10485 In that case, the base type must be set to the type of
10486 the lower bound, upper bound or count, in that order, if any of these
10487 three attributes references an object that has a type.
10488 If no base type is found, the Dwarf-2 specifications say that
10489 a signed integer type of size equal to the size of an address should
10491 For the following C code: `extern char gdb_int [];'
10492 GCC produces an empty range DIE.
10493 FIXME: muller/2010-05-28: Possible references to object for low bound,
10494 high bound or count are not yet handled by this code. */
10495 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
10497 struct objfile
*objfile
= cu
->objfile
;
10498 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10499 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
10500 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
10502 /* Test "int", "long int", and "long long int" objfile types,
10503 and select the first one having a size above or equal to the
10504 architecture address size. */
10505 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10506 base_type
= int_type
;
10509 int_type
= objfile_type (objfile
)->builtin_long
;
10510 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10511 base_type
= int_type
;
10514 int_type
= objfile_type (objfile
)->builtin_long_long
;
10515 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10516 base_type
= int_type
;
10522 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
10523 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
10524 low
|= negative_mask
;
10525 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
10526 high
|= negative_mask
;
10528 range_type
= create_range_type (NULL
, base_type
, low
, high
);
10530 /* Mark arrays with dynamic length at least as an array of unspecified
10531 length. GDB could check the boundary but before it gets implemented at
10532 least allow accessing the array elements. */
10533 if (attr
&& attr_form_is_block (attr
))
10534 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10536 /* Ada expects an empty array on no boundary attributes. */
10537 if (attr
== NULL
&& cu
->language
!= language_ada
)
10538 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10540 name
= dwarf2_name (die
, cu
);
10542 TYPE_NAME (range_type
) = name
;
10544 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10546 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
10548 set_die_type (die
, range_type
, cu
);
10550 /* set_die_type should be already done. */
10551 set_descriptive_type (range_type
, die
, cu
);
10556 static struct type
*
10557 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10561 /* For now, we only support the C meaning of an unspecified type: void. */
10563 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
10564 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
10566 return set_die_type (die
, type
, cu
);
10569 /* Read a single die and all its descendents. Set the die's sibling
10570 field to NULL; set other fields in the die correctly, and set all
10571 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
10572 location of the info_ptr after reading all of those dies. PARENT
10573 is the parent of the die in question. */
10575 static struct die_info
*
10576 read_die_and_children (const struct die_reader_specs
*reader
,
10577 gdb_byte
*info_ptr
,
10578 gdb_byte
**new_info_ptr
,
10579 struct die_info
*parent
)
10581 struct die_info
*die
;
10585 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
10588 *new_info_ptr
= cur_ptr
;
10591 store_in_ref_table (die
, reader
->cu
);
10594 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
10598 *new_info_ptr
= cur_ptr
;
10601 die
->sibling
= NULL
;
10602 die
->parent
= parent
;
10606 /* Read a die, all of its descendents, and all of its siblings; set
10607 all of the fields of all of the dies correctly. Arguments are as
10608 in read_die_and_children. */
10610 static struct die_info
*
10611 read_die_and_siblings (const struct die_reader_specs
*reader
,
10612 gdb_byte
*info_ptr
,
10613 gdb_byte
**new_info_ptr
,
10614 struct die_info
*parent
)
10616 struct die_info
*first_die
, *last_sibling
;
10619 cur_ptr
= info_ptr
;
10620 first_die
= last_sibling
= NULL
;
10624 struct die_info
*die
10625 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
10629 *new_info_ptr
= cur_ptr
;
10636 last_sibling
->sibling
= die
;
10638 last_sibling
= die
;
10642 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
10644 The caller is responsible for filling in the extra attributes
10645 and updating (*DIEP)->num_attrs.
10646 Set DIEP to point to a newly allocated die with its information,
10647 except for its child, sibling, and parent fields.
10648 Set HAS_CHILDREN to tell whether the die has children or not. */
10651 read_full_die_1 (const struct die_reader_specs
*reader
,
10652 struct die_info
**diep
, gdb_byte
*info_ptr
,
10653 int *has_children
, int num_extra_attrs
)
10655 unsigned int abbrev_number
, bytes_read
, i
;
10656 sect_offset offset
;
10657 struct abbrev_info
*abbrev
;
10658 struct die_info
*die
;
10659 struct dwarf2_cu
*cu
= reader
->cu
;
10660 bfd
*abfd
= reader
->abfd
;
10662 offset
.sect_off
= info_ptr
- reader
->buffer
;
10663 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10664 info_ptr
+= bytes_read
;
10665 if (!abbrev_number
)
10672 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
10674 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
10676 bfd_get_filename (abfd
));
10678 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
10679 die
->offset
= offset
;
10680 die
->tag
= abbrev
->tag
;
10681 die
->abbrev
= abbrev_number
;
10683 /* Make the result usable.
10684 The caller needs to update num_attrs after adding the extra
10686 die
->num_attrs
= abbrev
->num_attrs
;
10688 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
10689 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
10693 *has_children
= abbrev
->has_children
;
10697 /* Read a die and all its attributes.
10698 Set DIEP to point to a newly allocated die with its information,
10699 except for its child, sibling, and parent fields.
10700 Set HAS_CHILDREN to tell whether the die has children or not. */
10703 read_full_die (const struct die_reader_specs
*reader
,
10704 struct die_info
**diep
, gdb_byte
*info_ptr
,
10707 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
10710 /* In DWARF version 2, the description of the debugging information is
10711 stored in a separate .debug_abbrev section. Before we read any
10712 dies from a section we read in all abbreviations and install them
10713 in a hash table. This function also sets flags in CU describing
10714 the data found in the abbrev table. */
10717 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
10718 struct dwarf2_section_info
*abbrev_section
)
10721 bfd
*abfd
= abbrev_section
->asection
->owner
;
10722 struct comp_unit_head
*cu_header
= &cu
->header
;
10723 gdb_byte
*abbrev_ptr
;
10724 struct abbrev_info
*cur_abbrev
;
10725 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
10726 unsigned int abbrev_form
, hash_number
;
10727 struct attr_abbrev
*cur_attrs
;
10728 unsigned int allocated_attrs
;
10730 /* Initialize dwarf2 abbrevs. */
10731 obstack_init (&cu
->abbrev_obstack
);
10732 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
10734 * sizeof (struct abbrev_info
*)));
10735 memset (cu
->dwarf2_abbrevs
, 0,
10736 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
10738 dwarf2_read_section (cu
->objfile
, abbrev_section
);
10739 abbrev_ptr
= abbrev_section
->buffer
+ cu_header
->abbrev_offset
.sect_off
;
10740 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10741 abbrev_ptr
+= bytes_read
;
10743 allocated_attrs
= ATTR_ALLOC_CHUNK
;
10744 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
10746 /* Loop until we reach an abbrev number of 0. */
10747 while (abbrev_number
)
10749 cur_abbrev
= dwarf_alloc_abbrev (cu
);
10751 /* read in abbrev header */
10752 cur_abbrev
->number
= abbrev_number
;
10753 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10754 abbrev_ptr
+= bytes_read
;
10755 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
10758 /* now read in declarations */
10759 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10760 abbrev_ptr
+= bytes_read
;
10761 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10762 abbrev_ptr
+= bytes_read
;
10763 while (abbrev_name
)
10765 if (cur_abbrev
->num_attrs
== allocated_attrs
)
10767 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
10769 = xrealloc (cur_attrs
, (allocated_attrs
10770 * sizeof (struct attr_abbrev
)));
10773 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
10774 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
10775 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10776 abbrev_ptr
+= bytes_read
;
10777 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10778 abbrev_ptr
+= bytes_read
;
10781 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
10782 (cur_abbrev
->num_attrs
10783 * sizeof (struct attr_abbrev
)));
10784 memcpy (cur_abbrev
->attrs
, cur_attrs
,
10785 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
10787 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
10788 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
10789 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
10791 /* Get next abbreviation.
10792 Under Irix6 the abbreviations for a compilation unit are not
10793 always properly terminated with an abbrev number of 0.
10794 Exit loop if we encounter an abbreviation which we have
10795 already read (which means we are about to read the abbreviations
10796 for the next compile unit) or if the end of the abbreviation
10797 table is reached. */
10798 if ((unsigned int) (abbrev_ptr
- abbrev_section
->buffer
)
10799 >= abbrev_section
->size
)
10801 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10802 abbrev_ptr
+= bytes_read
;
10803 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
10810 /* Release the memory used by the abbrev table for a compilation unit. */
10813 dwarf2_free_abbrev_table (void *ptr_to_cu
)
10815 struct dwarf2_cu
*cu
= ptr_to_cu
;
10817 obstack_free (&cu
->abbrev_obstack
, NULL
);
10818 cu
->dwarf2_abbrevs
= NULL
;
10821 /* Lookup an abbrev_info structure in the abbrev hash table. */
10823 static struct abbrev_info
*
10824 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
10826 unsigned int hash_number
;
10827 struct abbrev_info
*abbrev
;
10829 hash_number
= number
% ABBREV_HASH_SIZE
;
10830 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
10834 if (abbrev
->number
== number
)
10837 abbrev
= abbrev
->next
;
10842 /* Returns nonzero if TAG represents a type that we might generate a partial
10846 is_type_tag_for_partial (int tag
)
10851 /* Some types that would be reasonable to generate partial symbols for,
10852 that we don't at present. */
10853 case DW_TAG_array_type
:
10854 case DW_TAG_file_type
:
10855 case DW_TAG_ptr_to_member_type
:
10856 case DW_TAG_set_type
:
10857 case DW_TAG_string_type
:
10858 case DW_TAG_subroutine_type
:
10860 case DW_TAG_base_type
:
10861 case DW_TAG_class_type
:
10862 case DW_TAG_interface_type
:
10863 case DW_TAG_enumeration_type
:
10864 case DW_TAG_structure_type
:
10865 case DW_TAG_subrange_type
:
10866 case DW_TAG_typedef
:
10867 case DW_TAG_union_type
:
10874 /* Load all DIEs that are interesting for partial symbols into memory. */
10876 static struct partial_die_info
*
10877 load_partial_dies (const struct die_reader_specs
*reader
,
10878 gdb_byte
*info_ptr
, int building_psymtab
)
10880 struct dwarf2_cu
*cu
= reader
->cu
;
10881 struct objfile
*objfile
= cu
->objfile
;
10882 struct partial_die_info
*part_die
;
10883 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
10884 struct abbrev_info
*abbrev
;
10885 unsigned int bytes_read
;
10886 unsigned int load_all
= 0;
10887 int nesting_level
= 1;
10892 gdb_assert (cu
->per_cu
!= NULL
);
10893 if (cu
->per_cu
->load_all_dies
)
10897 = htab_create_alloc_ex (cu
->header
.length
/ 12,
10901 &cu
->comp_unit_obstack
,
10902 hashtab_obstack_allocate
,
10903 dummy_obstack_deallocate
);
10905 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
10906 sizeof (struct partial_die_info
));
10910 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
10912 /* A NULL abbrev means the end of a series of children. */
10913 if (abbrev
== NULL
)
10915 if (--nesting_level
== 0)
10917 /* PART_DIE was probably the last thing allocated on the
10918 comp_unit_obstack, so we could call obstack_free
10919 here. We don't do that because the waste is small,
10920 and will be cleaned up when we're done with this
10921 compilation unit. This way, we're also more robust
10922 against other users of the comp_unit_obstack. */
10925 info_ptr
+= bytes_read
;
10926 last_die
= parent_die
;
10927 parent_die
= parent_die
->die_parent
;
10931 /* Check for template arguments. We never save these; if
10932 they're seen, we just mark the parent, and go on our way. */
10933 if (parent_die
!= NULL
10934 && cu
->language
== language_cplus
10935 && (abbrev
->tag
== DW_TAG_template_type_param
10936 || abbrev
->tag
== DW_TAG_template_value_param
))
10938 parent_die
->has_template_arguments
= 1;
10942 /* We don't need a partial DIE for the template argument. */
10943 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10948 /* We only recurse into c++ subprograms looking for template arguments.
10949 Skip their other children. */
10951 && cu
->language
== language_cplus
10952 && parent_die
!= NULL
10953 && parent_die
->tag
== DW_TAG_subprogram
)
10955 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10959 /* Check whether this DIE is interesting enough to save. Normally
10960 we would not be interested in members here, but there may be
10961 later variables referencing them via DW_AT_specification (for
10962 static members). */
10964 && !is_type_tag_for_partial (abbrev
->tag
)
10965 && abbrev
->tag
!= DW_TAG_constant
10966 && abbrev
->tag
!= DW_TAG_enumerator
10967 && abbrev
->tag
!= DW_TAG_subprogram
10968 && abbrev
->tag
!= DW_TAG_lexical_block
10969 && abbrev
->tag
!= DW_TAG_variable
10970 && abbrev
->tag
!= DW_TAG_namespace
10971 && abbrev
->tag
!= DW_TAG_module
10972 && abbrev
->tag
!= DW_TAG_member
10973 && abbrev
->tag
!= DW_TAG_imported_unit
)
10975 /* Otherwise we skip to the next sibling, if any. */
10976 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10980 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
10983 /* This two-pass algorithm for processing partial symbols has a
10984 high cost in cache pressure. Thus, handle some simple cases
10985 here which cover the majority of C partial symbols. DIEs
10986 which neither have specification tags in them, nor could have
10987 specification tags elsewhere pointing at them, can simply be
10988 processed and discarded.
10990 This segment is also optional; scan_partial_symbols and
10991 add_partial_symbol will handle these DIEs if we chain
10992 them in normally. When compilers which do not emit large
10993 quantities of duplicate debug information are more common,
10994 this code can probably be removed. */
10996 /* Any complete simple types at the top level (pretty much all
10997 of them, for a language without namespaces), can be processed
10999 if (parent_die
== NULL
11000 && part_die
->has_specification
== 0
11001 && part_die
->is_declaration
== 0
11002 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
11003 || part_die
->tag
== DW_TAG_base_type
11004 || part_die
->tag
== DW_TAG_subrange_type
))
11006 if (building_psymtab
&& part_die
->name
!= NULL
)
11007 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11008 VAR_DOMAIN
, LOC_TYPEDEF
,
11009 &objfile
->static_psymbols
,
11010 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11011 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11015 /* The exception for DW_TAG_typedef with has_children above is
11016 a workaround of GCC PR debug/47510. In the case of this complaint
11017 type_name_no_tag_or_error will error on such types later.
11019 GDB skipped children of DW_TAG_typedef by the shortcut above and then
11020 it could not find the child DIEs referenced later, this is checked
11021 above. In correct DWARF DW_TAG_typedef should have no children. */
11023 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
11024 complaint (&symfile_complaints
,
11025 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
11026 "- DIE at 0x%x [in module %s]"),
11027 part_die
->offset
.sect_off
, objfile
->name
);
11029 /* If we're at the second level, and we're an enumerator, and
11030 our parent has no specification (meaning possibly lives in a
11031 namespace elsewhere), then we can add the partial symbol now
11032 instead of queueing it. */
11033 if (part_die
->tag
== DW_TAG_enumerator
11034 && parent_die
!= NULL
11035 && parent_die
->die_parent
== NULL
11036 && parent_die
->tag
== DW_TAG_enumeration_type
11037 && parent_die
->has_specification
== 0)
11039 if (part_die
->name
== NULL
)
11040 complaint (&symfile_complaints
,
11041 _("malformed enumerator DIE ignored"));
11042 else if (building_psymtab
)
11043 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11044 VAR_DOMAIN
, LOC_CONST
,
11045 (cu
->language
== language_cplus
11046 || cu
->language
== language_java
)
11047 ? &objfile
->global_psymbols
11048 : &objfile
->static_psymbols
,
11049 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11051 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11055 /* We'll save this DIE so link it in. */
11056 part_die
->die_parent
= parent_die
;
11057 part_die
->die_sibling
= NULL
;
11058 part_die
->die_child
= NULL
;
11060 if (last_die
&& last_die
== parent_die
)
11061 last_die
->die_child
= part_die
;
11063 last_die
->die_sibling
= part_die
;
11065 last_die
= part_die
;
11067 if (first_die
== NULL
)
11068 first_die
= part_die
;
11070 /* Maybe add the DIE to the hash table. Not all DIEs that we
11071 find interesting need to be in the hash table, because we
11072 also have the parent/sibling/child chains; only those that we
11073 might refer to by offset later during partial symbol reading.
11075 For now this means things that might have be the target of a
11076 DW_AT_specification, DW_AT_abstract_origin, or
11077 DW_AT_extension. DW_AT_extension will refer only to
11078 namespaces; DW_AT_abstract_origin refers to functions (and
11079 many things under the function DIE, but we do not recurse
11080 into function DIEs during partial symbol reading) and
11081 possibly variables as well; DW_AT_specification refers to
11082 declarations. Declarations ought to have the DW_AT_declaration
11083 flag. It happens that GCC forgets to put it in sometimes, but
11084 only for functions, not for types.
11086 Adding more things than necessary to the hash table is harmless
11087 except for the performance cost. Adding too few will result in
11088 wasted time in find_partial_die, when we reread the compilation
11089 unit with load_all_dies set. */
11092 || abbrev
->tag
== DW_TAG_constant
11093 || abbrev
->tag
== DW_TAG_subprogram
11094 || abbrev
->tag
== DW_TAG_variable
11095 || abbrev
->tag
== DW_TAG_namespace
11096 || part_die
->is_declaration
)
11100 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
11101 part_die
->offset
.sect_off
, INSERT
);
11105 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
11106 sizeof (struct partial_die_info
));
11108 /* For some DIEs we want to follow their children (if any). For C
11109 we have no reason to follow the children of structures; for other
11110 languages we have to, so that we can get at method physnames
11111 to infer fully qualified class names, for DW_AT_specification,
11112 and for C++ template arguments. For C++, we also look one level
11113 inside functions to find template arguments (if the name of the
11114 function does not already contain the template arguments).
11116 For Ada, we need to scan the children of subprograms and lexical
11117 blocks as well because Ada allows the definition of nested
11118 entities that could be interesting for the debugger, such as
11119 nested subprograms for instance. */
11120 if (last_die
->has_children
11122 || last_die
->tag
== DW_TAG_namespace
11123 || last_die
->tag
== DW_TAG_module
11124 || last_die
->tag
== DW_TAG_enumeration_type
11125 || (cu
->language
== language_cplus
11126 && last_die
->tag
== DW_TAG_subprogram
11127 && (last_die
->name
== NULL
11128 || strchr (last_die
->name
, '<') == NULL
))
11129 || (cu
->language
!= language_c
11130 && (last_die
->tag
== DW_TAG_class_type
11131 || last_die
->tag
== DW_TAG_interface_type
11132 || last_die
->tag
== DW_TAG_structure_type
11133 || last_die
->tag
== DW_TAG_union_type
))
11134 || (cu
->language
== language_ada
11135 && (last_die
->tag
== DW_TAG_subprogram
11136 || last_die
->tag
== DW_TAG_lexical_block
))))
11139 parent_die
= last_die
;
11143 /* Otherwise we skip to the next sibling, if any. */
11144 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
11146 /* Back to the top, do it again. */
11150 /* Read a minimal amount of information into the minimal die structure. */
11153 read_partial_die (const struct die_reader_specs
*reader
,
11154 struct partial_die_info
*part_die
,
11155 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
11156 gdb_byte
*info_ptr
)
11158 struct dwarf2_cu
*cu
= reader
->cu
;
11159 struct objfile
*objfile
= cu
->objfile
;
11160 gdb_byte
*buffer
= reader
->buffer
;
11162 struct attribute attr
;
11163 int has_low_pc_attr
= 0;
11164 int has_high_pc_attr
= 0;
11165 int high_pc_relative
= 0;
11167 memset (part_die
, 0, sizeof (struct partial_die_info
));
11169 part_die
->offset
.sect_off
= info_ptr
- buffer
;
11171 info_ptr
+= abbrev_len
;
11173 if (abbrev
== NULL
)
11176 part_die
->tag
= abbrev
->tag
;
11177 part_die
->has_children
= abbrev
->has_children
;
11179 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
11181 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
11183 /* Store the data if it is of an attribute we want to keep in a
11184 partial symbol table. */
11188 switch (part_die
->tag
)
11190 case DW_TAG_compile_unit
:
11191 case DW_TAG_partial_unit
:
11192 case DW_TAG_type_unit
:
11193 /* Compilation units have a DW_AT_name that is a filename, not
11194 a source language identifier. */
11195 case DW_TAG_enumeration_type
:
11196 case DW_TAG_enumerator
:
11197 /* These tags always have simple identifiers already; no need
11198 to canonicalize them. */
11199 part_die
->name
= DW_STRING (&attr
);
11203 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
11204 &objfile
->objfile_obstack
);
11208 case DW_AT_linkage_name
:
11209 case DW_AT_MIPS_linkage_name
:
11210 /* Note that both forms of linkage name might appear. We
11211 assume they will be the same, and we only store the last
11213 if (cu
->language
== language_ada
)
11214 part_die
->name
= DW_STRING (&attr
);
11215 part_die
->linkage_name
= DW_STRING (&attr
);
11218 has_low_pc_attr
= 1;
11219 part_die
->lowpc
= DW_ADDR (&attr
);
11221 case DW_AT_high_pc
:
11222 has_high_pc_attr
= 1;
11223 if (attr
.form
== DW_FORM_addr
11224 || attr
.form
== DW_FORM_GNU_addr_index
)
11225 part_die
->highpc
= DW_ADDR (&attr
);
11228 high_pc_relative
= 1;
11229 part_die
->highpc
= DW_UNSND (&attr
);
11232 case DW_AT_location
:
11233 /* Support the .debug_loc offsets. */
11234 if (attr_form_is_block (&attr
))
11236 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
11238 else if (attr_form_is_section_offset (&attr
))
11240 dwarf2_complex_location_expr_complaint ();
11244 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11245 "partial symbol information");
11248 case DW_AT_external
:
11249 part_die
->is_external
= DW_UNSND (&attr
);
11251 case DW_AT_declaration
:
11252 part_die
->is_declaration
= DW_UNSND (&attr
);
11255 part_die
->has_type
= 1;
11257 case DW_AT_abstract_origin
:
11258 case DW_AT_specification
:
11259 case DW_AT_extension
:
11260 part_die
->has_specification
= 1;
11261 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
11263 case DW_AT_sibling
:
11264 /* Ignore absolute siblings, they might point outside of
11265 the current compile unit. */
11266 if (attr
.form
== DW_FORM_ref_addr
)
11267 complaint (&symfile_complaints
,
11268 _("ignoring absolute DW_AT_sibling"));
11270 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
11272 case DW_AT_byte_size
:
11273 part_die
->has_byte_size
= 1;
11275 case DW_AT_calling_convention
:
11276 /* DWARF doesn't provide a way to identify a program's source-level
11277 entry point. DW_AT_calling_convention attributes are only meant
11278 to describe functions' calling conventions.
11280 However, because it's a necessary piece of information in
11281 Fortran, and because DW_CC_program is the only piece of debugging
11282 information whose definition refers to a 'main program' at all,
11283 several compilers have begun marking Fortran main programs with
11284 DW_CC_program --- even when those functions use the standard
11285 calling conventions.
11287 So until DWARF specifies a way to provide this information and
11288 compilers pick up the new representation, we'll support this
11290 if (DW_UNSND (&attr
) == DW_CC_program
11291 && cu
->language
== language_fortran
)
11293 set_main_name (part_die
->name
);
11295 /* As this DIE has a static linkage the name would be difficult
11296 to look up later. */
11297 language_of_main
= language_fortran
;
11301 if (DW_UNSND (&attr
) == DW_INL_inlined
11302 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
11303 part_die
->may_be_inlined
= 1;
11307 if (part_die
->tag
== DW_TAG_imported_unit
)
11308 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
11316 if (high_pc_relative
)
11317 part_die
->highpc
+= part_die
->lowpc
;
11319 if (has_low_pc_attr
&& has_high_pc_attr
)
11321 /* When using the GNU linker, .gnu.linkonce. sections are used to
11322 eliminate duplicate copies of functions and vtables and such.
11323 The linker will arbitrarily choose one and discard the others.
11324 The AT_*_pc values for such functions refer to local labels in
11325 these sections. If the section from that file was discarded, the
11326 labels are not in the output, so the relocs get a value of 0.
11327 If this is a discarded function, mark the pc bounds as invalid,
11328 so that GDB will ignore it. */
11329 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11331 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11333 complaint (&symfile_complaints
,
11334 _("DW_AT_low_pc %s is zero "
11335 "for DIE at 0x%x [in module %s]"),
11336 paddress (gdbarch
, part_die
->lowpc
),
11337 part_die
->offset
.sect_off
, objfile
->name
);
11339 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
11340 else if (part_die
->lowpc
>= part_die
->highpc
)
11342 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11344 complaint (&symfile_complaints
,
11345 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
11346 "for DIE at 0x%x [in module %s]"),
11347 paddress (gdbarch
, part_die
->lowpc
),
11348 paddress (gdbarch
, part_die
->highpc
),
11349 part_die
->offset
.sect_off
, objfile
->name
);
11352 part_die
->has_pc_info
= 1;
11358 /* Find a cached partial DIE at OFFSET in CU. */
11360 static struct partial_die_info
*
11361 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
11363 struct partial_die_info
*lookup_die
= NULL
;
11364 struct partial_die_info part_die
;
11366 part_die
.offset
= offset
;
11367 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
11373 /* Find a partial DIE at OFFSET, which may or may not be in CU,
11374 except in the case of .debug_types DIEs which do not reference
11375 outside their CU (they do however referencing other types via
11376 DW_FORM_ref_sig8). */
11378 static struct partial_die_info
*
11379 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
11381 struct objfile
*objfile
= cu
->objfile
;
11382 struct dwarf2_per_cu_data
*per_cu
= NULL
;
11383 struct partial_die_info
*pd
= NULL
;
11385 if (offset_in_cu_p (&cu
->header
, offset
))
11387 pd
= find_partial_die_in_comp_unit (offset
, cu
);
11390 /* We missed recording what we needed.
11391 Load all dies and try again. */
11392 per_cu
= cu
->per_cu
;
11396 /* TUs don't reference other CUs/TUs (except via type signatures). */
11397 if (cu
->per_cu
->is_debug_types
)
11399 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
11400 " external reference to offset 0x%lx [in module %s].\n"),
11401 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
11402 bfd_get_filename (objfile
->obfd
));
11404 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11406 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
11407 load_partial_comp_unit (per_cu
);
11409 per_cu
->cu
->last_used
= 0;
11410 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11413 /* If we didn't find it, and not all dies have been loaded,
11414 load them all and try again. */
11416 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
11418 per_cu
->load_all_dies
= 1;
11420 /* This is nasty. When we reread the DIEs, somewhere up the call chain
11421 THIS_CU->cu may already be in use. So we can't just free it and
11422 replace its DIEs with the ones we read in. Instead, we leave those
11423 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
11424 and clobber THIS_CU->cu->partial_dies with the hash table for the new
11426 load_partial_comp_unit (per_cu
);
11428 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11432 internal_error (__FILE__
, __LINE__
,
11433 _("could not find partial DIE 0x%x "
11434 "in cache [from module %s]\n"),
11435 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
11439 /* See if we can figure out if the class lives in a namespace. We do
11440 this by looking for a member function; its demangled name will
11441 contain namespace info, if there is any. */
11444 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
11445 struct dwarf2_cu
*cu
)
11447 /* NOTE: carlton/2003-10-07: Getting the info this way changes
11448 what template types look like, because the demangler
11449 frequently doesn't give the same name as the debug info. We
11450 could fix this by only using the demangled name to get the
11451 prefix (but see comment in read_structure_type). */
11453 struct partial_die_info
*real_pdi
;
11454 struct partial_die_info
*child_pdi
;
11456 /* If this DIE (this DIE's specification, if any) has a parent, then
11457 we should not do this. We'll prepend the parent's fully qualified
11458 name when we create the partial symbol. */
11460 real_pdi
= struct_pdi
;
11461 while (real_pdi
->has_specification
)
11462 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
11464 if (real_pdi
->die_parent
!= NULL
)
11467 for (child_pdi
= struct_pdi
->die_child
;
11469 child_pdi
= child_pdi
->die_sibling
)
11471 if (child_pdi
->tag
== DW_TAG_subprogram
11472 && child_pdi
->linkage_name
!= NULL
)
11474 char *actual_class_name
11475 = language_class_name_from_physname (cu
->language_defn
,
11476 child_pdi
->linkage_name
);
11477 if (actual_class_name
!= NULL
)
11480 = obsavestring (actual_class_name
,
11481 strlen (actual_class_name
),
11482 &cu
->objfile
->objfile_obstack
);
11483 xfree (actual_class_name
);
11490 /* Adjust PART_DIE before generating a symbol for it. This function
11491 may set the is_external flag or change the DIE's name. */
11494 fixup_partial_die (struct partial_die_info
*part_die
,
11495 struct dwarf2_cu
*cu
)
11497 /* Once we've fixed up a die, there's no point in doing so again.
11498 This also avoids a memory leak if we were to call
11499 guess_partial_die_structure_name multiple times. */
11500 if (part_die
->fixup_called
)
11503 /* If we found a reference attribute and the DIE has no name, try
11504 to find a name in the referred to DIE. */
11506 if (part_die
->name
== NULL
&& part_die
->has_specification
)
11508 struct partial_die_info
*spec_die
;
11510 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
11512 fixup_partial_die (spec_die
, cu
);
11514 if (spec_die
->name
)
11516 part_die
->name
= spec_die
->name
;
11518 /* Copy DW_AT_external attribute if it is set. */
11519 if (spec_die
->is_external
)
11520 part_die
->is_external
= spec_die
->is_external
;
11524 /* Set default names for some unnamed DIEs. */
11526 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
11527 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
11529 /* If there is no parent die to provide a namespace, and there are
11530 children, see if we can determine the namespace from their linkage
11532 if (cu
->language
== language_cplus
11533 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
11534 && part_die
->die_parent
== NULL
11535 && part_die
->has_children
11536 && (part_die
->tag
== DW_TAG_class_type
11537 || part_die
->tag
== DW_TAG_structure_type
11538 || part_die
->tag
== DW_TAG_union_type
))
11539 guess_partial_die_structure_name (part_die
, cu
);
11541 /* GCC might emit a nameless struct or union that has a linkage
11542 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
11543 if (part_die
->name
== NULL
11544 && (part_die
->tag
== DW_TAG_class_type
11545 || part_die
->tag
== DW_TAG_interface_type
11546 || part_die
->tag
== DW_TAG_structure_type
11547 || part_die
->tag
== DW_TAG_union_type
)
11548 && part_die
->linkage_name
!= NULL
)
11552 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
11557 /* Strip any leading namespaces/classes, keep only the base name.
11558 DW_AT_name for named DIEs does not contain the prefixes. */
11559 base
= strrchr (demangled
, ':');
11560 if (base
&& base
> demangled
&& base
[-1] == ':')
11565 part_die
->name
= obsavestring (base
, strlen (base
),
11566 &cu
->objfile
->objfile_obstack
);
11571 part_die
->fixup_called
= 1;
11574 /* Read an attribute value described by an attribute form. */
11577 read_attribute_value (const struct die_reader_specs
*reader
,
11578 struct attribute
*attr
, unsigned form
,
11579 gdb_byte
*info_ptr
)
11581 struct dwarf2_cu
*cu
= reader
->cu
;
11582 bfd
*abfd
= reader
->abfd
;
11583 struct comp_unit_head
*cu_header
= &cu
->header
;
11584 unsigned int bytes_read
;
11585 struct dwarf_block
*blk
;
11590 case DW_FORM_ref_addr
:
11591 if (cu
->header
.version
== 2)
11592 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11594 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
11595 &cu
->header
, &bytes_read
);
11596 info_ptr
+= bytes_read
;
11599 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11600 info_ptr
+= bytes_read
;
11602 case DW_FORM_block2
:
11603 blk
= dwarf_alloc_block (cu
);
11604 blk
->size
= read_2_bytes (abfd
, info_ptr
);
11606 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11607 info_ptr
+= blk
->size
;
11608 DW_BLOCK (attr
) = blk
;
11610 case DW_FORM_block4
:
11611 blk
= dwarf_alloc_block (cu
);
11612 blk
->size
= read_4_bytes (abfd
, info_ptr
);
11614 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11615 info_ptr
+= blk
->size
;
11616 DW_BLOCK (attr
) = blk
;
11618 case DW_FORM_data2
:
11619 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
11622 case DW_FORM_data4
:
11623 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
11626 case DW_FORM_data8
:
11627 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
11630 case DW_FORM_sec_offset
:
11631 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
11632 info_ptr
+= bytes_read
;
11634 case DW_FORM_string
:
11635 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
11636 DW_STRING_IS_CANONICAL (attr
) = 0;
11637 info_ptr
+= bytes_read
;
11640 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
11642 DW_STRING_IS_CANONICAL (attr
) = 0;
11643 info_ptr
+= bytes_read
;
11645 case DW_FORM_exprloc
:
11646 case DW_FORM_block
:
11647 blk
= dwarf_alloc_block (cu
);
11648 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11649 info_ptr
+= bytes_read
;
11650 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11651 info_ptr
+= blk
->size
;
11652 DW_BLOCK (attr
) = blk
;
11654 case DW_FORM_block1
:
11655 blk
= dwarf_alloc_block (cu
);
11656 blk
->size
= read_1_byte (abfd
, info_ptr
);
11658 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11659 info_ptr
+= blk
->size
;
11660 DW_BLOCK (attr
) = blk
;
11662 case DW_FORM_data1
:
11663 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11667 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11670 case DW_FORM_flag_present
:
11671 DW_UNSND (attr
) = 1;
11673 case DW_FORM_sdata
:
11674 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
11675 info_ptr
+= bytes_read
;
11677 case DW_FORM_udata
:
11678 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11679 info_ptr
+= bytes_read
;
11682 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11683 + read_1_byte (abfd
, info_ptr
));
11687 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11688 + read_2_bytes (abfd
, info_ptr
));
11692 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11693 + read_4_bytes (abfd
, info_ptr
));
11697 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11698 + read_8_bytes (abfd
, info_ptr
));
11701 case DW_FORM_ref_sig8
:
11702 /* Convert the signature to something we can record in DW_UNSND
11704 NOTE: This is NULL if the type wasn't found. */
11705 DW_SIGNATURED_TYPE (attr
) =
11706 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
11709 case DW_FORM_ref_udata
:
11710 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11711 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
11712 info_ptr
+= bytes_read
;
11714 case DW_FORM_indirect
:
11715 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11716 info_ptr
+= bytes_read
;
11717 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
11719 case DW_FORM_GNU_addr_index
:
11720 if (reader
->dwo_file
== NULL
)
11722 /* For now flag a hard error.
11723 Later we can turn this into a complaint. */
11724 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11725 dwarf_form_name (form
),
11726 bfd_get_filename (abfd
));
11728 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
11729 info_ptr
+= bytes_read
;
11731 case DW_FORM_GNU_str_index
:
11732 if (reader
->dwo_file
== NULL
)
11734 /* For now flag a hard error.
11735 Later we can turn this into a complaint if warranted. */
11736 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11737 dwarf_form_name (form
),
11738 bfd_get_filename (abfd
));
11741 ULONGEST str_index
=
11742 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11744 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
11745 DW_STRING_IS_CANONICAL (attr
) = 0;
11746 info_ptr
+= bytes_read
;
11750 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
11751 dwarf_form_name (form
),
11752 bfd_get_filename (abfd
));
11755 /* We have seen instances where the compiler tried to emit a byte
11756 size attribute of -1 which ended up being encoded as an unsigned
11757 0xffffffff. Although 0xffffffff is technically a valid size value,
11758 an object of this size seems pretty unlikely so we can relatively
11759 safely treat these cases as if the size attribute was invalid and
11760 treat them as zero by default. */
11761 if (attr
->name
== DW_AT_byte_size
11762 && form
== DW_FORM_data4
11763 && DW_UNSND (attr
) >= 0xffffffff)
11766 (&symfile_complaints
,
11767 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
11768 hex_string (DW_UNSND (attr
)));
11769 DW_UNSND (attr
) = 0;
11775 /* Read an attribute described by an abbreviated attribute. */
11778 read_attribute (const struct die_reader_specs
*reader
,
11779 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
11780 gdb_byte
*info_ptr
)
11782 attr
->name
= abbrev
->name
;
11783 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
11786 /* Read dwarf information from a buffer. */
11788 static unsigned int
11789 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
11791 return bfd_get_8 (abfd
, buf
);
11795 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
11797 return bfd_get_signed_8 (abfd
, buf
);
11800 static unsigned int
11801 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
11803 return bfd_get_16 (abfd
, buf
);
11807 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
11809 return bfd_get_signed_16 (abfd
, buf
);
11812 static unsigned int
11813 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
11815 return bfd_get_32 (abfd
, buf
);
11819 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
11821 return bfd_get_signed_32 (abfd
, buf
);
11825 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
11827 return bfd_get_64 (abfd
, buf
);
11831 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
11832 unsigned int *bytes_read
)
11834 struct comp_unit_head
*cu_header
= &cu
->header
;
11835 CORE_ADDR retval
= 0;
11837 if (cu_header
->signed_addr_p
)
11839 switch (cu_header
->addr_size
)
11842 retval
= bfd_get_signed_16 (abfd
, buf
);
11845 retval
= bfd_get_signed_32 (abfd
, buf
);
11848 retval
= bfd_get_signed_64 (abfd
, buf
);
11851 internal_error (__FILE__
, __LINE__
,
11852 _("read_address: bad switch, signed [in module %s]"),
11853 bfd_get_filename (abfd
));
11858 switch (cu_header
->addr_size
)
11861 retval
= bfd_get_16 (abfd
, buf
);
11864 retval
= bfd_get_32 (abfd
, buf
);
11867 retval
= bfd_get_64 (abfd
, buf
);
11870 internal_error (__FILE__
, __LINE__
,
11871 _("read_address: bad switch, "
11872 "unsigned [in module %s]"),
11873 bfd_get_filename (abfd
));
11877 *bytes_read
= cu_header
->addr_size
;
11881 /* Read the initial length from a section. The (draft) DWARF 3
11882 specification allows the initial length to take up either 4 bytes
11883 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
11884 bytes describe the length and all offsets will be 8 bytes in length
11887 An older, non-standard 64-bit format is also handled by this
11888 function. The older format in question stores the initial length
11889 as an 8-byte quantity without an escape value. Lengths greater
11890 than 2^32 aren't very common which means that the initial 4 bytes
11891 is almost always zero. Since a length value of zero doesn't make
11892 sense for the 32-bit format, this initial zero can be considered to
11893 be an escape value which indicates the presence of the older 64-bit
11894 format. As written, the code can't detect (old format) lengths
11895 greater than 4GB. If it becomes necessary to handle lengths
11896 somewhat larger than 4GB, we could allow other small values (such
11897 as the non-sensical values of 1, 2, and 3) to also be used as
11898 escape values indicating the presence of the old format.
11900 The value returned via bytes_read should be used to increment the
11901 relevant pointer after calling read_initial_length().
11903 [ Note: read_initial_length() and read_offset() are based on the
11904 document entitled "DWARF Debugging Information Format", revision
11905 3, draft 8, dated November 19, 2001. This document was obtained
11908 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
11910 This document is only a draft and is subject to change. (So beware.)
11912 Details regarding the older, non-standard 64-bit format were
11913 determined empirically by examining 64-bit ELF files produced by
11914 the SGI toolchain on an IRIX 6.5 machine.
11916 - Kevin, July 16, 2002
11920 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
11922 LONGEST length
= bfd_get_32 (abfd
, buf
);
11924 if (length
== 0xffffffff)
11926 length
= bfd_get_64 (abfd
, buf
+ 4);
11929 else if (length
== 0)
11931 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
11932 length
= bfd_get_64 (abfd
, buf
);
11943 /* Cover function for read_initial_length.
11944 Returns the length of the object at BUF, and stores the size of the
11945 initial length in *BYTES_READ and stores the size that offsets will be in
11947 If the initial length size is not equivalent to that specified in
11948 CU_HEADER then issue a complaint.
11949 This is useful when reading non-comp-unit headers. */
11952 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
11953 const struct comp_unit_head
*cu_header
,
11954 unsigned int *bytes_read
,
11955 unsigned int *offset_size
)
11957 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
11959 gdb_assert (cu_header
->initial_length_size
== 4
11960 || cu_header
->initial_length_size
== 8
11961 || cu_header
->initial_length_size
== 12);
11963 if (cu_header
->initial_length_size
!= *bytes_read
)
11964 complaint (&symfile_complaints
,
11965 _("intermixed 32-bit and 64-bit DWARF sections"));
11967 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
11971 /* Read an offset from the data stream. The size of the offset is
11972 given by cu_header->offset_size. */
11975 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
11976 unsigned int *bytes_read
)
11978 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
11980 *bytes_read
= cu_header
->offset_size
;
11984 /* Read an offset from the data stream. */
11987 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
11989 LONGEST retval
= 0;
11991 switch (offset_size
)
11994 retval
= bfd_get_32 (abfd
, buf
);
11997 retval
= bfd_get_64 (abfd
, buf
);
12000 internal_error (__FILE__
, __LINE__
,
12001 _("read_offset_1: bad switch [in module %s]"),
12002 bfd_get_filename (abfd
));
12009 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
12011 /* If the size of a host char is 8 bits, we can return a pointer
12012 to the buffer, otherwise we have to copy the data to a buffer
12013 allocated on the temporary obstack. */
12014 gdb_assert (HOST_CHAR_BIT
== 8);
12019 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12021 /* If the size of a host char is 8 bits, we can return a pointer
12022 to the string, otherwise we have to copy the string to a buffer
12023 allocated on the temporary obstack. */
12024 gdb_assert (HOST_CHAR_BIT
== 8);
12027 *bytes_read_ptr
= 1;
12030 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
12031 return (char *) buf
;
12035 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
12037 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
12038 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
12039 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
12040 bfd_get_filename (abfd
));
12041 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
12042 error (_("DW_FORM_strp pointing outside of "
12043 ".debug_str section [in module %s]"),
12044 bfd_get_filename (abfd
));
12045 gdb_assert (HOST_CHAR_BIT
== 8);
12046 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
12048 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
12052 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
12053 const struct comp_unit_head
*cu_header
,
12054 unsigned int *bytes_read_ptr
)
12056 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
12058 return read_indirect_string_at_offset (abfd
, str_offset
);
12062 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12065 unsigned int num_read
;
12067 unsigned char byte
;
12075 byte
= bfd_get_8 (abfd
, buf
);
12078 result
|= ((ULONGEST
) (byte
& 127) << shift
);
12079 if ((byte
& 128) == 0)
12085 *bytes_read_ptr
= num_read
;
12090 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12093 int i
, shift
, num_read
;
12094 unsigned char byte
;
12102 byte
= bfd_get_8 (abfd
, buf
);
12105 result
|= ((LONGEST
) (byte
& 127) << shift
);
12107 if ((byte
& 128) == 0)
12112 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
12113 result
|= -(((LONGEST
) 1) << shift
);
12114 *bytes_read_ptr
= num_read
;
12118 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
12119 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
12120 ADDR_SIZE is the size of addresses from the CU header. */
12123 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
12125 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12126 bfd
*abfd
= objfile
->obfd
;
12127 const gdb_byte
*info_ptr
;
12129 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
12130 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
12131 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
12133 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
12134 error (_("DW_FORM_addr_index pointing outside of "
12135 ".debug_addr section [in module %s]"),
12137 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
12138 + addr_base
+ addr_index
* addr_size
);
12139 if (addr_size
== 4)
12140 return bfd_get_32 (abfd
, info_ptr
);
12142 return bfd_get_64 (abfd
, info_ptr
);
12145 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
12148 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
12150 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
12153 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
12156 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
12157 unsigned int *bytes_read
)
12159 bfd
*abfd
= cu
->objfile
->obfd
;
12160 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
12162 return read_addr_index (cu
, addr_index
);
12165 /* Data structure to pass results from dwarf2_read_addr_index_reader
12166 back to dwarf2_read_addr_index. */
12168 struct dwarf2_read_addr_index_data
12170 ULONGEST addr_base
;
12174 /* die_reader_func for dwarf2_read_addr_index. */
12177 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
12178 gdb_byte
*info_ptr
,
12179 struct die_info
*comp_unit_die
,
12183 struct dwarf2_cu
*cu
= reader
->cu
;
12184 struct dwarf2_read_addr_index_data
*aidata
=
12185 (struct dwarf2_read_addr_index_data
*) data
;
12187 aidata
->addr_base
= cu
->addr_base
;
12188 aidata
->addr_size
= cu
->header
.addr_size
;
12191 /* Given an index in .debug_addr, fetch the value.
12192 NOTE: This can be called during dwarf expression evaluation,
12193 long after the debug information has been read, and thus per_cu->cu
12194 may no longer exist. */
12197 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
12198 unsigned int addr_index
)
12200 struct objfile
*objfile
= per_cu
->objfile
;
12201 struct dwarf2_cu
*cu
= per_cu
->cu
;
12202 ULONGEST addr_base
;
12205 /* This is intended to be called from outside this file. */
12206 dw2_setup (objfile
);
12208 /* We need addr_base and addr_size.
12209 If we don't have PER_CU->cu, we have to get it.
12210 Nasty, but the alternative is storing the needed info in PER_CU,
12211 which at this point doesn't seem justified: it's not clear how frequently
12212 it would get used and it would increase the size of every PER_CU.
12213 Entry points like dwarf2_per_cu_addr_size do a similar thing
12214 so we're not in uncharted territory here.
12215 Alas we need to be a bit more complicated as addr_base is contained
12218 We don't need to read the entire CU(/TU).
12219 We just need the header and top level die.
12220 IWBN to use the aging mechanism to let us lazily later discard the CU.
12221 See however init_cutu_and_read_dies_simple. */
12225 addr_base
= cu
->addr_base
;
12226 addr_size
= cu
->header
.addr_size
;
12230 struct dwarf2_read_addr_index_data aidata
;
12232 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
12234 addr_base
= aidata
.addr_base
;
12235 addr_size
= aidata
.addr_size
;
12238 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
12241 /* Given a DW_AT_str_index, fetch the string. */
12244 read_str_index (const struct die_reader_specs
*reader
,
12245 struct dwarf2_cu
*cu
, ULONGEST str_index
)
12247 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12248 const char *dwo_name
= objfile
->name
;
12249 bfd
*abfd
= objfile
->obfd
;
12250 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
12251 gdb_byte
*info_ptr
;
12252 ULONGEST str_offset
;
12254 dwarf2_read_section (objfile
, §ions
->str
);
12255 dwarf2_read_section (objfile
, §ions
->str_offsets
);
12256 if (sections
->str
.buffer
== NULL
)
12257 error (_("DW_FORM_str_index used without .debug_str.dwo section"
12258 " in CU at offset 0x%lx [in module %s]"),
12259 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12260 if (sections
->str_offsets
.buffer
== NULL
)
12261 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
12262 " in CU at offset 0x%lx [in module %s]"),
12263 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12264 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
12265 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
12266 " section in CU at offset 0x%lx [in module %s]"),
12267 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12268 info_ptr
= (sections
->str_offsets
.buffer
12269 + str_index
* cu
->header
.offset_size
);
12270 if (cu
->header
.offset_size
== 4)
12271 str_offset
= bfd_get_32 (abfd
, info_ptr
);
12273 str_offset
= bfd_get_64 (abfd
, info_ptr
);
12274 if (str_offset
>= sections
->str
.size
)
12275 error (_("Offset from DW_FORM_str_index pointing outside of"
12276 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
12277 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12278 return (char *) (sections
->str
.buffer
+ str_offset
);
12281 /* Return a pointer to just past the end of an LEB128 number in BUF. */
12284 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
12290 byte
= bfd_get_8 (abfd
, buf
);
12292 if ((byte
& 128) == 0)
12297 /* Return the length of an LEB128 number in BUF. */
12300 leb128_size (const gdb_byte
*buf
)
12302 const gdb_byte
*begin
= buf
;
12308 if ((byte
& 128) == 0)
12309 return buf
- begin
;
12314 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
12321 cu
->language
= language_c
;
12323 case DW_LANG_C_plus_plus
:
12324 cu
->language
= language_cplus
;
12327 cu
->language
= language_d
;
12329 case DW_LANG_Fortran77
:
12330 case DW_LANG_Fortran90
:
12331 case DW_LANG_Fortran95
:
12332 cu
->language
= language_fortran
;
12335 cu
->language
= language_go
;
12337 case DW_LANG_Mips_Assembler
:
12338 cu
->language
= language_asm
;
12341 cu
->language
= language_java
;
12343 case DW_LANG_Ada83
:
12344 case DW_LANG_Ada95
:
12345 cu
->language
= language_ada
;
12347 case DW_LANG_Modula2
:
12348 cu
->language
= language_m2
;
12350 case DW_LANG_Pascal83
:
12351 cu
->language
= language_pascal
;
12354 cu
->language
= language_objc
;
12356 case DW_LANG_Cobol74
:
12357 case DW_LANG_Cobol85
:
12359 cu
->language
= language_minimal
;
12362 cu
->language_defn
= language_def (cu
->language
);
12365 /* Return the named attribute or NULL if not there. */
12367 static struct attribute
*
12368 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
12373 struct attribute
*spec
= NULL
;
12375 for (i
= 0; i
< die
->num_attrs
; ++i
)
12377 if (die
->attrs
[i
].name
== name
)
12378 return &die
->attrs
[i
];
12379 if (die
->attrs
[i
].name
== DW_AT_specification
12380 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
12381 spec
= &die
->attrs
[i
];
12387 die
= follow_die_ref (die
, spec
, &cu
);
12393 /* Return the named attribute or NULL if not there,
12394 but do not follow DW_AT_specification, etc.
12395 This is for use in contexts where we're reading .debug_types dies.
12396 Following DW_AT_specification, DW_AT_abstract_origin will take us
12397 back up the chain, and we want to go down. */
12399 static struct attribute
*
12400 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
12401 struct dwarf2_cu
*cu
)
12405 for (i
= 0; i
< die
->num_attrs
; ++i
)
12406 if (die
->attrs
[i
].name
== name
)
12407 return &die
->attrs
[i
];
12412 /* Return non-zero iff the attribute NAME is defined for the given DIE,
12413 and holds a non-zero value. This function should only be used for
12414 DW_FORM_flag or DW_FORM_flag_present attributes. */
12417 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
12419 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
12421 return (attr
&& DW_UNSND (attr
));
12425 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
12427 /* A DIE is a declaration if it has a DW_AT_declaration attribute
12428 which value is non-zero. However, we have to be careful with
12429 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
12430 (via dwarf2_flag_true_p) follows this attribute. So we may
12431 end up accidently finding a declaration attribute that belongs
12432 to a different DIE referenced by the specification attribute,
12433 even though the given DIE does not have a declaration attribute. */
12434 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
12435 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
12438 /* Return the die giving the specification for DIE, if there is
12439 one. *SPEC_CU is the CU containing DIE on input, and the CU
12440 containing the return value on output. If there is no
12441 specification, but there is an abstract origin, that is
12444 static struct die_info
*
12445 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
12447 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
12450 if (spec_attr
== NULL
)
12451 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
12453 if (spec_attr
== NULL
)
12456 return follow_die_ref (die
, spec_attr
, spec_cu
);
12459 /* Free the line_header structure *LH, and any arrays and strings it
12461 NOTE: This is also used as a "cleanup" function. */
12464 free_line_header (struct line_header
*lh
)
12466 if (lh
->standard_opcode_lengths
)
12467 xfree (lh
->standard_opcode_lengths
);
12469 /* Remember that all the lh->file_names[i].name pointers are
12470 pointers into debug_line_buffer, and don't need to be freed. */
12471 if (lh
->file_names
)
12472 xfree (lh
->file_names
);
12474 /* Similarly for the include directory names. */
12475 if (lh
->include_dirs
)
12476 xfree (lh
->include_dirs
);
12481 /* Add an entry to LH's include directory table. */
12484 add_include_dir (struct line_header
*lh
, char *include_dir
)
12486 /* Grow the array if necessary. */
12487 if (lh
->include_dirs_size
== 0)
12489 lh
->include_dirs_size
= 1; /* for testing */
12490 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
12491 * sizeof (*lh
->include_dirs
));
12493 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
12495 lh
->include_dirs_size
*= 2;
12496 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
12497 (lh
->include_dirs_size
12498 * sizeof (*lh
->include_dirs
)));
12501 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
12504 /* Add an entry to LH's file name table. */
12507 add_file_name (struct line_header
*lh
,
12509 unsigned int dir_index
,
12510 unsigned int mod_time
,
12511 unsigned int length
)
12513 struct file_entry
*fe
;
12515 /* Grow the array if necessary. */
12516 if (lh
->file_names_size
== 0)
12518 lh
->file_names_size
= 1; /* for testing */
12519 lh
->file_names
= xmalloc (lh
->file_names_size
12520 * sizeof (*lh
->file_names
));
12522 else if (lh
->num_file_names
>= lh
->file_names_size
)
12524 lh
->file_names_size
*= 2;
12525 lh
->file_names
= xrealloc (lh
->file_names
,
12526 (lh
->file_names_size
12527 * sizeof (*lh
->file_names
)));
12530 fe
= &lh
->file_names
[lh
->num_file_names
++];
12532 fe
->dir_index
= dir_index
;
12533 fe
->mod_time
= mod_time
;
12534 fe
->length
= length
;
12535 fe
->included_p
= 0;
12539 /* Read the statement program header starting at OFFSET in
12540 .debug_line, or .debug_line.dwo. Return a pointer
12541 to a struct line_header, allocated using xmalloc.
12543 NOTE: the strings in the include directory and file name tables of
12544 the returned object point into the dwarf line section buffer,
12545 and must not be freed. */
12547 static struct line_header
*
12548 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
12550 struct cleanup
*back_to
;
12551 struct line_header
*lh
;
12552 gdb_byte
*line_ptr
;
12553 unsigned int bytes_read
, offset_size
;
12555 char *cur_dir
, *cur_file
;
12556 struct dwarf2_section_info
*section
;
12559 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
12561 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12562 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
12564 section
= &dwarf2_per_objfile
->line
;
12566 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
12567 if (section
->buffer
== NULL
)
12569 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12570 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
12572 complaint (&symfile_complaints
, _("missing .debug_line section"));
12576 /* We can't do this until we know the section is non-empty.
12577 Only then do we know we have such a section. */
12578 abfd
= section
->asection
->owner
;
12580 /* Make sure that at least there's room for the total_length field.
12581 That could be 12 bytes long, but we're just going to fudge that. */
12582 if (offset
+ 4 >= section
->size
)
12584 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12588 lh
= xmalloc (sizeof (*lh
));
12589 memset (lh
, 0, sizeof (*lh
));
12590 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
12593 line_ptr
= section
->buffer
+ offset
;
12595 /* Read in the header. */
12597 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
12598 &bytes_read
, &offset_size
);
12599 line_ptr
+= bytes_read
;
12600 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
12602 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12605 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
12606 lh
->version
= read_2_bytes (abfd
, line_ptr
);
12608 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
12609 line_ptr
+= offset_size
;
12610 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
12612 if (lh
->version
>= 4)
12614 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
12618 lh
->maximum_ops_per_instruction
= 1;
12620 if (lh
->maximum_ops_per_instruction
== 0)
12622 lh
->maximum_ops_per_instruction
= 1;
12623 complaint (&symfile_complaints
,
12624 _("invalid maximum_ops_per_instruction "
12625 "in `.debug_line' section"));
12628 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
12630 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
12632 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
12634 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
12636 lh
->standard_opcode_lengths
12637 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
12639 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
12640 for (i
= 1; i
< lh
->opcode_base
; ++i
)
12642 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
12646 /* Read directory table. */
12647 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12649 line_ptr
+= bytes_read
;
12650 add_include_dir (lh
, cur_dir
);
12652 line_ptr
+= bytes_read
;
12654 /* Read file name table. */
12655 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12657 unsigned int dir_index
, mod_time
, length
;
12659 line_ptr
+= bytes_read
;
12660 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12661 line_ptr
+= bytes_read
;
12662 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12663 line_ptr
+= bytes_read
;
12664 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12665 line_ptr
+= bytes_read
;
12667 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12669 line_ptr
+= bytes_read
;
12670 lh
->statement_program_start
= line_ptr
;
12672 if (line_ptr
> (section
->buffer
+ section
->size
))
12673 complaint (&symfile_complaints
,
12674 _("line number info header doesn't "
12675 "fit in `.debug_line' section"));
12677 discard_cleanups (back_to
);
12681 /* Subroutine of dwarf_decode_lines to simplify it.
12682 Return the file name of the psymtab for included file FILE_INDEX
12683 in line header LH of PST.
12684 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
12685 If space for the result is malloc'd, it will be freed by a cleanup.
12686 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
12689 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
12690 const struct partial_symtab
*pst
,
12691 const char *comp_dir
)
12693 const struct file_entry fe
= lh
->file_names
[file_index
];
12694 char *include_name
= fe
.name
;
12695 char *include_name_to_compare
= include_name
;
12696 char *dir_name
= NULL
;
12697 const char *pst_filename
;
12698 char *copied_name
= NULL
;
12702 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
12704 if (!IS_ABSOLUTE_PATH (include_name
)
12705 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
12707 /* Avoid creating a duplicate psymtab for PST.
12708 We do this by comparing INCLUDE_NAME and PST_FILENAME.
12709 Before we do the comparison, however, we need to account
12710 for DIR_NAME and COMP_DIR.
12711 First prepend dir_name (if non-NULL). If we still don't
12712 have an absolute path prepend comp_dir (if non-NULL).
12713 However, the directory we record in the include-file's
12714 psymtab does not contain COMP_DIR (to match the
12715 corresponding symtab(s)).
12720 bash$ gcc -g ./hello.c
12721 include_name = "hello.c"
12723 DW_AT_comp_dir = comp_dir = "/tmp"
12724 DW_AT_name = "./hello.c" */
12726 if (dir_name
!= NULL
)
12728 include_name
= concat (dir_name
, SLASH_STRING
,
12729 include_name
, (char *)NULL
);
12730 include_name_to_compare
= include_name
;
12731 make_cleanup (xfree
, include_name
);
12733 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
12735 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
12736 include_name
, (char *)NULL
);
12740 pst_filename
= pst
->filename
;
12741 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
12743 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
12744 pst_filename
, (char *)NULL
);
12745 pst_filename
= copied_name
;
12748 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
12750 if (include_name_to_compare
!= include_name
)
12751 xfree (include_name_to_compare
);
12752 if (copied_name
!= NULL
)
12753 xfree (copied_name
);
12757 return include_name
;
12760 /* Ignore this record_line request. */
12763 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
12768 /* Subroutine of dwarf_decode_lines to simplify it.
12769 Process the line number information in LH. */
12772 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
12773 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
12775 gdb_byte
*line_ptr
, *extended_end
;
12776 gdb_byte
*line_end
;
12777 unsigned int bytes_read
, extended_len
;
12778 unsigned char op_code
, extended_op
, adj_opcode
;
12779 CORE_ADDR baseaddr
;
12780 struct objfile
*objfile
= cu
->objfile
;
12781 bfd
*abfd
= objfile
->obfd
;
12782 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12783 const int decode_for_pst_p
= (pst
!= NULL
);
12784 struct subfile
*last_subfile
= NULL
;
12785 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
12788 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12790 line_ptr
= lh
->statement_program_start
;
12791 line_end
= lh
->statement_program_end
;
12793 /* Read the statement sequences until there's nothing left. */
12794 while (line_ptr
< line_end
)
12796 /* state machine registers */
12797 CORE_ADDR address
= 0;
12798 unsigned int file
= 1;
12799 unsigned int line
= 1;
12800 unsigned int column
= 0;
12801 int is_stmt
= lh
->default_is_stmt
;
12802 int basic_block
= 0;
12803 int end_sequence
= 0;
12805 unsigned char op_index
= 0;
12807 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
12809 /* Start a subfile for the current file of the state machine. */
12810 /* lh->include_dirs and lh->file_names are 0-based, but the
12811 directory and file name numbers in the statement program
12813 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
12817 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12819 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
12822 /* Decode the table. */
12823 while (!end_sequence
)
12825 op_code
= read_1_byte (abfd
, line_ptr
);
12827 if (line_ptr
> line_end
)
12829 dwarf2_debug_line_missing_end_sequence_complaint ();
12833 if (op_code
>= lh
->opcode_base
)
12835 /* Special operand. */
12836 adj_opcode
= op_code
- lh
->opcode_base
;
12837 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
12838 / lh
->maximum_ops_per_instruction
)
12839 * lh
->minimum_instruction_length
);
12840 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
12841 % lh
->maximum_ops_per_instruction
);
12842 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
12843 if (lh
->num_file_names
< file
|| file
== 0)
12844 dwarf2_debug_line_missing_file_complaint ();
12845 /* For now we ignore lines not starting on an
12846 instruction boundary. */
12847 else if (op_index
== 0)
12849 lh
->file_names
[file
- 1].included_p
= 1;
12850 if (!decode_for_pst_p
&& is_stmt
)
12852 if (last_subfile
!= current_subfile
)
12854 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12856 (*p_record_line
) (last_subfile
, 0, addr
);
12857 last_subfile
= current_subfile
;
12859 /* Append row to matrix using current values. */
12860 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12861 (*p_record_line
) (current_subfile
, line
, addr
);
12866 else switch (op_code
)
12868 case DW_LNS_extended_op
:
12869 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
12871 line_ptr
+= bytes_read
;
12872 extended_end
= line_ptr
+ extended_len
;
12873 extended_op
= read_1_byte (abfd
, line_ptr
);
12875 switch (extended_op
)
12877 case DW_LNE_end_sequence
:
12878 p_record_line
= record_line
;
12881 case DW_LNE_set_address
:
12882 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
12884 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12886 /* This line table is for a function which has been
12887 GCd by the linker. Ignore it. PR gdb/12528 */
12890 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
12892 complaint (&symfile_complaints
,
12893 _(".debug_line address at offset 0x%lx is 0 "
12895 line_offset
, objfile
->name
);
12896 p_record_line
= noop_record_line
;
12900 line_ptr
+= bytes_read
;
12901 address
+= baseaddr
;
12903 case DW_LNE_define_file
:
12906 unsigned int dir_index
, mod_time
, length
;
12908 cur_file
= read_direct_string (abfd
, line_ptr
,
12910 line_ptr
+= bytes_read
;
12912 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12913 line_ptr
+= bytes_read
;
12915 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12916 line_ptr
+= bytes_read
;
12918 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12919 line_ptr
+= bytes_read
;
12920 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12923 case DW_LNE_set_discriminator
:
12924 /* The discriminator is not interesting to the debugger;
12926 line_ptr
= extended_end
;
12929 complaint (&symfile_complaints
,
12930 _("mangled .debug_line section"));
12933 /* Make sure that we parsed the extended op correctly. If e.g.
12934 we expected a different address size than the producer used,
12935 we may have read the wrong number of bytes. */
12936 if (line_ptr
!= extended_end
)
12938 complaint (&symfile_complaints
,
12939 _("mangled .debug_line section"));
12944 if (lh
->num_file_names
< file
|| file
== 0)
12945 dwarf2_debug_line_missing_file_complaint ();
12948 lh
->file_names
[file
- 1].included_p
= 1;
12949 if (!decode_for_pst_p
&& is_stmt
)
12951 if (last_subfile
!= current_subfile
)
12953 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12955 (*p_record_line
) (last_subfile
, 0, addr
);
12956 last_subfile
= current_subfile
;
12958 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12959 (*p_record_line
) (current_subfile
, line
, addr
);
12964 case DW_LNS_advance_pc
:
12967 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12969 address
+= (((op_index
+ adjust
)
12970 / lh
->maximum_ops_per_instruction
)
12971 * lh
->minimum_instruction_length
);
12972 op_index
= ((op_index
+ adjust
)
12973 % lh
->maximum_ops_per_instruction
);
12974 line_ptr
+= bytes_read
;
12977 case DW_LNS_advance_line
:
12978 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
12979 line_ptr
+= bytes_read
;
12981 case DW_LNS_set_file
:
12983 /* The arrays lh->include_dirs and lh->file_names are
12984 0-based, but the directory and file name numbers in
12985 the statement program are 1-based. */
12986 struct file_entry
*fe
;
12989 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12990 line_ptr
+= bytes_read
;
12991 if (lh
->num_file_names
< file
|| file
== 0)
12992 dwarf2_debug_line_missing_file_complaint ();
12995 fe
= &lh
->file_names
[file
- 1];
12997 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12998 if (!decode_for_pst_p
)
13000 last_subfile
= current_subfile
;
13001 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13006 case DW_LNS_set_column
:
13007 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13008 line_ptr
+= bytes_read
;
13010 case DW_LNS_negate_stmt
:
13011 is_stmt
= (!is_stmt
);
13013 case DW_LNS_set_basic_block
:
13016 /* Add to the address register of the state machine the
13017 address increment value corresponding to special opcode
13018 255. I.e., this value is scaled by the minimum
13019 instruction length since special opcode 255 would have
13020 scaled the increment. */
13021 case DW_LNS_const_add_pc
:
13023 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
13025 address
+= (((op_index
+ adjust
)
13026 / lh
->maximum_ops_per_instruction
)
13027 * lh
->minimum_instruction_length
);
13028 op_index
= ((op_index
+ adjust
)
13029 % lh
->maximum_ops_per_instruction
);
13032 case DW_LNS_fixed_advance_pc
:
13033 address
+= read_2_bytes (abfd
, line_ptr
);
13039 /* Unknown standard opcode, ignore it. */
13042 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
13044 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13045 line_ptr
+= bytes_read
;
13050 if (lh
->num_file_names
< file
|| file
== 0)
13051 dwarf2_debug_line_missing_file_complaint ();
13054 lh
->file_names
[file
- 1].included_p
= 1;
13055 if (!decode_for_pst_p
)
13057 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13058 (*p_record_line
) (current_subfile
, 0, addr
);
13064 /* Decode the Line Number Program (LNP) for the given line_header
13065 structure and CU. The actual information extracted and the type
13066 of structures created from the LNP depends on the value of PST.
13068 1. If PST is NULL, then this procedure uses the data from the program
13069 to create all necessary symbol tables, and their linetables.
13071 2. If PST is not NULL, this procedure reads the program to determine
13072 the list of files included by the unit represented by PST, and
13073 builds all the associated partial symbol tables.
13075 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
13076 It is used for relative paths in the line table.
13077 NOTE: When processing partial symtabs (pst != NULL),
13078 comp_dir == pst->dirname.
13080 NOTE: It is important that psymtabs have the same file name (via strcmp)
13081 as the corresponding symtab. Since COMP_DIR is not used in the name of the
13082 symtab we don't use it in the name of the psymtabs we create.
13083 E.g. expand_line_sal requires this when finding psymtabs to expand.
13084 A good testcase for this is mb-inline.exp. */
13087 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
13088 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
13089 int want_line_info
)
13091 struct objfile
*objfile
= cu
->objfile
;
13092 const int decode_for_pst_p
= (pst
!= NULL
);
13093 struct subfile
*first_subfile
= current_subfile
;
13095 if (want_line_info
)
13096 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
13098 if (decode_for_pst_p
)
13102 /* Now that we're done scanning the Line Header Program, we can
13103 create the psymtab of each included file. */
13104 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
13105 if (lh
->file_names
[file_index
].included_p
== 1)
13107 char *include_name
=
13108 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
13109 if (include_name
!= NULL
)
13110 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
13115 /* Make sure a symtab is created for every file, even files
13116 which contain only variables (i.e. no code with associated
13120 for (i
= 0; i
< lh
->num_file_names
; i
++)
13123 struct file_entry
*fe
;
13125 fe
= &lh
->file_names
[i
];
13127 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13128 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13130 /* Skip the main file; we don't need it, and it must be
13131 allocated last, so that it will show up before the
13132 non-primary symtabs in the objfile's symtab list. */
13133 if (current_subfile
== first_subfile
)
13136 if (current_subfile
->symtab
== NULL
)
13137 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
13139 fe
->symtab
= current_subfile
->symtab
;
13144 /* Start a subfile for DWARF. FILENAME is the name of the file and
13145 DIRNAME the name of the source directory which contains FILENAME
13146 or NULL if not known. COMP_DIR is the compilation directory for the
13147 linetable's compilation unit or NULL if not known.
13148 This routine tries to keep line numbers from identical absolute and
13149 relative file names in a common subfile.
13151 Using the `list' example from the GDB testsuite, which resides in
13152 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
13153 of /srcdir/list0.c yields the following debugging information for list0.c:
13155 DW_AT_name: /srcdir/list0.c
13156 DW_AT_comp_dir: /compdir
13157 files.files[0].name: list0.h
13158 files.files[0].dir: /srcdir
13159 files.files[1].name: list0.c
13160 files.files[1].dir: /srcdir
13162 The line number information for list0.c has to end up in a single
13163 subfile, so that `break /srcdir/list0.c:1' works as expected.
13164 start_subfile will ensure that this happens provided that we pass the
13165 concatenation of files.files[1].dir and files.files[1].name as the
13169 dwarf2_start_subfile (char *filename
, const char *dirname
,
13170 const char *comp_dir
)
13174 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
13175 `start_symtab' will always pass the contents of DW_AT_comp_dir as
13176 second argument to start_subfile. To be consistent, we do the
13177 same here. In order not to lose the line information directory,
13178 we concatenate it to the filename when it makes sense.
13179 Note that the Dwarf3 standard says (speaking of filenames in line
13180 information): ``The directory index is ignored for file names
13181 that represent full path names''. Thus ignoring dirname in the
13182 `else' branch below isn't an issue. */
13184 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
13185 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
13187 fullname
= filename
;
13189 start_subfile (fullname
, comp_dir
);
13191 if (fullname
!= filename
)
13196 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
13197 struct dwarf2_cu
*cu
)
13199 struct objfile
*objfile
= cu
->objfile
;
13200 struct comp_unit_head
*cu_header
= &cu
->header
;
13202 /* NOTE drow/2003-01-30: There used to be a comment and some special
13203 code here to turn a symbol with DW_AT_external and a
13204 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
13205 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
13206 with some versions of binutils) where shared libraries could have
13207 relocations against symbols in their debug information - the
13208 minimal symbol would have the right address, but the debug info
13209 would not. It's no longer necessary, because we will explicitly
13210 apply relocations when we read in the debug information now. */
13212 /* A DW_AT_location attribute with no contents indicates that a
13213 variable has been optimized away. */
13214 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
13216 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13220 /* Handle one degenerate form of location expression specially, to
13221 preserve GDB's previous behavior when section offsets are
13222 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
13223 then mark this symbol as LOC_STATIC. */
13225 if (attr_form_is_block (attr
)
13226 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
13227 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
13228 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
13229 && (DW_BLOCK (attr
)->size
13230 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
13232 unsigned int dummy
;
13234 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
13235 SYMBOL_VALUE_ADDRESS (sym
) =
13236 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
13238 SYMBOL_VALUE_ADDRESS (sym
) =
13239 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
13240 SYMBOL_CLASS (sym
) = LOC_STATIC
;
13241 fixup_symbol_section (sym
, objfile
);
13242 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
13243 SYMBOL_SECTION (sym
));
13247 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
13248 expression evaluator, and use LOC_COMPUTED only when necessary
13249 (i.e. when the value of a register or memory location is
13250 referenced, or a thread-local block, etc.). Then again, it might
13251 not be worthwhile. I'm assuming that it isn't unless performance
13252 or memory numbers show me otherwise. */
13254 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
13255 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13257 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
13258 cu
->has_loclist
= 1;
13261 /* Given a pointer to a DWARF information entry, figure out if we need
13262 to make a symbol table entry for it, and if so, create a new entry
13263 and return a pointer to it.
13264 If TYPE is NULL, determine symbol type from the die, otherwise
13265 used the passed type.
13266 If SPACE is not NULL, use it to hold the new symbol. If it is
13267 NULL, allocate a new symbol on the objfile's obstack. */
13269 static struct symbol
*
13270 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
13271 struct symbol
*space
)
13273 struct objfile
*objfile
= cu
->objfile
;
13274 struct symbol
*sym
= NULL
;
13276 struct attribute
*attr
= NULL
;
13277 struct attribute
*attr2
= NULL
;
13278 CORE_ADDR baseaddr
;
13279 struct pending
**list_to_add
= NULL
;
13281 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13283 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13285 name
= dwarf2_name (die
, cu
);
13288 const char *linkagename
;
13289 int suppress_add
= 0;
13294 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
13295 OBJSTAT (objfile
, n_syms
++);
13297 /* Cache this symbol's name and the name's demangled form (if any). */
13298 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
13299 linkagename
= dwarf2_physname (name
, die
, cu
);
13300 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
13302 /* Fortran does not have mangling standard and the mangling does differ
13303 between gfortran, iFort etc. */
13304 if (cu
->language
== language_fortran
13305 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
13306 symbol_set_demangled_name (&(sym
->ginfo
),
13307 (char *) dwarf2_full_name (name
, die
, cu
),
13310 /* Default assumptions.
13311 Use the passed type or decode it from the die. */
13312 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13313 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13315 SYMBOL_TYPE (sym
) = type
;
13317 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
13318 attr
= dwarf2_attr (die
,
13319 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
13323 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
13326 attr
= dwarf2_attr (die
,
13327 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
13331 int file_index
= DW_UNSND (attr
);
13333 if (cu
->line_header
== NULL
13334 || file_index
> cu
->line_header
->num_file_names
)
13335 complaint (&symfile_complaints
,
13336 _("file index out of range"));
13337 else if (file_index
> 0)
13339 struct file_entry
*fe
;
13341 fe
= &cu
->line_header
->file_names
[file_index
- 1];
13342 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
13349 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13352 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
13354 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
13355 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
13356 SYMBOL_CLASS (sym
) = LOC_LABEL
;
13357 add_symbol_to_list (sym
, cu
->list_in_scope
);
13359 case DW_TAG_subprogram
:
13360 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13362 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13363 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13364 if ((attr2
&& (DW_UNSND (attr2
) != 0))
13365 || cu
->language
== language_ada
)
13367 /* Subprograms marked external are stored as a global symbol.
13368 Ada subprograms, whether marked external or not, are always
13369 stored as a global symbol, because we want to be able to
13370 access them globally. For instance, we want to be able
13371 to break on a nested subprogram without having to
13372 specify the context. */
13373 list_to_add
= &global_symbols
;
13377 list_to_add
= cu
->list_in_scope
;
13380 case DW_TAG_inlined_subroutine
:
13381 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13383 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13384 SYMBOL_INLINED (sym
) = 1;
13385 list_to_add
= cu
->list_in_scope
;
13387 case DW_TAG_template_value_param
:
13389 /* Fall through. */
13390 case DW_TAG_constant
:
13391 case DW_TAG_variable
:
13392 case DW_TAG_member
:
13393 /* Compilation with minimal debug info may result in
13394 variables with missing type entries. Change the
13395 misleading `void' type to something sensible. */
13396 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
13398 = objfile_type (objfile
)->nodebug_data_symbol
;
13400 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13401 /* In the case of DW_TAG_member, we should only be called for
13402 static const members. */
13403 if (die
->tag
== DW_TAG_member
)
13405 /* dwarf2_add_field uses die_is_declaration,
13406 so we do the same. */
13407 gdb_assert (die_is_declaration (die
, cu
));
13412 dwarf2_const_value (attr
, sym
, cu
);
13413 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13416 if (attr2
&& (DW_UNSND (attr2
) != 0))
13417 list_to_add
= &global_symbols
;
13419 list_to_add
= cu
->list_in_scope
;
13423 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13426 var_decode_location (attr
, sym
, cu
);
13427 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13428 if (SYMBOL_CLASS (sym
) == LOC_STATIC
13429 && SYMBOL_VALUE_ADDRESS (sym
) == 0
13430 && !dwarf2_per_objfile
->has_section_at_zero
)
13432 /* When a static variable is eliminated by the linker,
13433 the corresponding debug information is not stripped
13434 out, but the variable address is set to null;
13435 do not add such variables into symbol table. */
13437 else if (attr2
&& (DW_UNSND (attr2
) != 0))
13439 /* Workaround gfortran PR debug/40040 - it uses
13440 DW_AT_location for variables in -fPIC libraries which may
13441 get overriden by other libraries/executable and get
13442 a different address. Resolve it by the minimal symbol
13443 which may come from inferior's executable using copy
13444 relocation. Make this workaround only for gfortran as for
13445 other compilers GDB cannot guess the minimal symbol
13446 Fortran mangling kind. */
13447 if (cu
->language
== language_fortran
&& die
->parent
13448 && die
->parent
->tag
== DW_TAG_module
13450 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
13451 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13453 /* A variable with DW_AT_external is never static,
13454 but it may be block-scoped. */
13455 list_to_add
= (cu
->list_in_scope
== &file_symbols
13456 ? &global_symbols
: cu
->list_in_scope
);
13459 list_to_add
= cu
->list_in_scope
;
13463 /* We do not know the address of this symbol.
13464 If it is an external symbol and we have type information
13465 for it, enter the symbol as a LOC_UNRESOLVED symbol.
13466 The address of the variable will then be determined from
13467 the minimal symbol table whenever the variable is
13469 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13470 if (attr2
&& (DW_UNSND (attr2
) != 0)
13471 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
13473 /* A variable with DW_AT_external is never static, but it
13474 may be block-scoped. */
13475 list_to_add
= (cu
->list_in_scope
== &file_symbols
13476 ? &global_symbols
: cu
->list_in_scope
);
13478 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13480 else if (!die_is_declaration (die
, cu
))
13482 /* Use the default LOC_OPTIMIZED_OUT class. */
13483 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
13485 list_to_add
= cu
->list_in_scope
;
13489 case DW_TAG_formal_parameter
:
13490 /* If we are inside a function, mark this as an argument. If
13491 not, we might be looking at an argument to an inlined function
13492 when we do not have enough information to show inlined frames;
13493 pretend it's a local variable in that case so that the user can
13495 if (context_stack_depth
> 0
13496 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
13497 SYMBOL_IS_ARGUMENT (sym
) = 1;
13498 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13501 var_decode_location (attr
, sym
, cu
);
13503 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13506 dwarf2_const_value (attr
, sym
, cu
);
13509 list_to_add
= cu
->list_in_scope
;
13511 case DW_TAG_unspecified_parameters
:
13512 /* From varargs functions; gdb doesn't seem to have any
13513 interest in this information, so just ignore it for now.
13516 case DW_TAG_template_type_param
:
13518 /* Fall through. */
13519 case DW_TAG_class_type
:
13520 case DW_TAG_interface_type
:
13521 case DW_TAG_structure_type
:
13522 case DW_TAG_union_type
:
13523 case DW_TAG_set_type
:
13524 case DW_TAG_enumeration_type
:
13525 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13526 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
13529 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
13530 really ever be static objects: otherwise, if you try
13531 to, say, break of a class's method and you're in a file
13532 which doesn't mention that class, it won't work unless
13533 the check for all static symbols in lookup_symbol_aux
13534 saves you. See the OtherFileClass tests in
13535 gdb.c++/namespace.exp. */
13539 list_to_add
= (cu
->list_in_scope
== &file_symbols
13540 && (cu
->language
== language_cplus
13541 || cu
->language
== language_java
)
13542 ? &global_symbols
: cu
->list_in_scope
);
13544 /* The semantics of C++ state that "struct foo {
13545 ... }" also defines a typedef for "foo". A Java
13546 class declaration also defines a typedef for the
13548 if (cu
->language
== language_cplus
13549 || cu
->language
== language_java
13550 || cu
->language
== language_ada
)
13552 /* The symbol's name is already allocated along
13553 with this objfile, so we don't need to
13554 duplicate it for the type. */
13555 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
13556 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
13561 case DW_TAG_typedef
:
13562 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13563 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13564 list_to_add
= cu
->list_in_scope
;
13566 case DW_TAG_base_type
:
13567 case DW_TAG_subrange_type
:
13568 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13569 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13570 list_to_add
= cu
->list_in_scope
;
13572 case DW_TAG_enumerator
:
13573 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13576 dwarf2_const_value (attr
, sym
, cu
);
13579 /* NOTE: carlton/2003-11-10: See comment above in the
13580 DW_TAG_class_type, etc. block. */
13582 list_to_add
= (cu
->list_in_scope
== &file_symbols
13583 && (cu
->language
== language_cplus
13584 || cu
->language
== language_java
)
13585 ? &global_symbols
: cu
->list_in_scope
);
13588 case DW_TAG_namespace
:
13589 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13590 list_to_add
= &global_symbols
;
13593 /* Not a tag we recognize. Hopefully we aren't processing
13594 trash data, but since we must specifically ignore things
13595 we don't recognize, there is nothing else we should do at
13597 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
13598 dwarf_tag_name (die
->tag
));
13604 sym
->hash_next
= objfile
->template_symbols
;
13605 objfile
->template_symbols
= sym
;
13606 list_to_add
= NULL
;
13609 if (list_to_add
!= NULL
)
13610 add_symbol_to_list (sym
, list_to_add
);
13612 /* For the benefit of old versions of GCC, check for anonymous
13613 namespaces based on the demangled name. */
13614 if (!processing_has_namespace_info
13615 && cu
->language
== language_cplus
)
13616 cp_scan_for_anonymous_namespaces (sym
, objfile
);
13621 /* A wrapper for new_symbol_full that always allocates a new symbol. */
13623 static struct symbol
*
13624 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
13626 return new_symbol_full (die
, type
, cu
, NULL
);
13629 /* Given an attr with a DW_FORM_dataN value in host byte order,
13630 zero-extend it as appropriate for the symbol's type. The DWARF
13631 standard (v4) is not entirely clear about the meaning of using
13632 DW_FORM_dataN for a constant with a signed type, where the type is
13633 wider than the data. The conclusion of a discussion on the DWARF
13634 list was that this is unspecified. We choose to always zero-extend
13635 because that is the interpretation long in use by GCC. */
13638 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
13639 const char *name
, struct obstack
*obstack
,
13640 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
13642 struct objfile
*objfile
= cu
->objfile
;
13643 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
13644 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
13645 LONGEST l
= DW_UNSND (attr
);
13647 if (bits
< sizeof (*value
) * 8)
13649 l
&= ((LONGEST
) 1 << bits
) - 1;
13652 else if (bits
== sizeof (*value
) * 8)
13656 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
13657 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
13664 /* Read a constant value from an attribute. Either set *VALUE, or if
13665 the value does not fit in *VALUE, set *BYTES - either already
13666 allocated on the objfile obstack, or newly allocated on OBSTACK,
13667 or, set *BATON, if we translated the constant to a location
13671 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
13672 const char *name
, struct obstack
*obstack
,
13673 struct dwarf2_cu
*cu
,
13674 LONGEST
*value
, gdb_byte
**bytes
,
13675 struct dwarf2_locexpr_baton
**baton
)
13677 struct objfile
*objfile
= cu
->objfile
;
13678 struct comp_unit_head
*cu_header
= &cu
->header
;
13679 struct dwarf_block
*blk
;
13680 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
13681 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
13687 switch (attr
->form
)
13690 case DW_FORM_GNU_addr_index
:
13694 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
13695 dwarf2_const_value_length_mismatch_complaint (name
,
13696 cu_header
->addr_size
,
13697 TYPE_LENGTH (type
));
13698 /* Symbols of this form are reasonably rare, so we just
13699 piggyback on the existing location code rather than writing
13700 a new implementation of symbol_computed_ops. */
13701 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
13702 sizeof (struct dwarf2_locexpr_baton
));
13703 (*baton
)->per_cu
= cu
->per_cu
;
13704 gdb_assert ((*baton
)->per_cu
);
13706 (*baton
)->size
= 2 + cu_header
->addr_size
;
13707 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
13708 (*baton
)->data
= data
;
13710 data
[0] = DW_OP_addr
;
13711 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
13712 byte_order
, DW_ADDR (attr
));
13713 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
13716 case DW_FORM_string
:
13718 case DW_FORM_GNU_str_index
:
13719 /* DW_STRING is already allocated on the objfile obstack, point
13721 *bytes
= (gdb_byte
*) DW_STRING (attr
);
13723 case DW_FORM_block1
:
13724 case DW_FORM_block2
:
13725 case DW_FORM_block4
:
13726 case DW_FORM_block
:
13727 case DW_FORM_exprloc
:
13728 blk
= DW_BLOCK (attr
);
13729 if (TYPE_LENGTH (type
) != blk
->size
)
13730 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
13731 TYPE_LENGTH (type
));
13732 *bytes
= blk
->data
;
13735 /* The DW_AT_const_value attributes are supposed to carry the
13736 symbol's value "represented as it would be on the target
13737 architecture." By the time we get here, it's already been
13738 converted to host endianness, so we just need to sign- or
13739 zero-extend it as appropriate. */
13740 case DW_FORM_data1
:
13741 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13742 obstack
, cu
, value
, 8);
13744 case DW_FORM_data2
:
13745 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13746 obstack
, cu
, value
, 16);
13748 case DW_FORM_data4
:
13749 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13750 obstack
, cu
, value
, 32);
13752 case DW_FORM_data8
:
13753 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13754 obstack
, cu
, value
, 64);
13757 case DW_FORM_sdata
:
13758 *value
= DW_SND (attr
);
13761 case DW_FORM_udata
:
13762 *value
= DW_UNSND (attr
);
13766 complaint (&symfile_complaints
,
13767 _("unsupported const value attribute form: '%s'"),
13768 dwarf_form_name (attr
->form
));
13775 /* Copy constant value from an attribute to a symbol. */
13778 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
13779 struct dwarf2_cu
*cu
)
13781 struct objfile
*objfile
= cu
->objfile
;
13782 struct comp_unit_head
*cu_header
= &cu
->header
;
13785 struct dwarf2_locexpr_baton
*baton
;
13787 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
13788 SYMBOL_PRINT_NAME (sym
),
13789 &objfile
->objfile_obstack
, cu
,
13790 &value
, &bytes
, &baton
);
13794 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
13795 SYMBOL_LOCATION_BATON (sym
) = baton
;
13796 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13798 else if (bytes
!= NULL
)
13800 SYMBOL_VALUE_BYTES (sym
) = bytes
;
13801 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
13805 SYMBOL_VALUE (sym
) = value
;
13806 SYMBOL_CLASS (sym
) = LOC_CONST
;
13810 /* Return the type of the die in question using its DW_AT_type attribute. */
13812 static struct type
*
13813 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13815 struct attribute
*type_attr
;
13817 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13820 /* A missing DW_AT_type represents a void type. */
13821 return objfile_type (cu
->objfile
)->builtin_void
;
13824 return lookup_die_type (die
, type_attr
, cu
);
13827 /* True iff CU's producer generates GNAT Ada auxiliary information
13828 that allows to find parallel types through that information instead
13829 of having to do expensive parallel lookups by type name. */
13832 need_gnat_info (struct dwarf2_cu
*cu
)
13834 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
13835 of GNAT produces this auxiliary information, without any indication
13836 that it is produced. Part of enhancing the FSF version of GNAT
13837 to produce that information will be to put in place an indicator
13838 that we can use in order to determine whether the descriptive type
13839 info is available or not. One suggestion that has been made is
13840 to use a new attribute, attached to the CU die. For now, assume
13841 that the descriptive type info is not available. */
13845 /* Return the auxiliary type of the die in question using its
13846 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
13847 attribute is not present. */
13849 static struct type
*
13850 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13852 struct attribute
*type_attr
;
13854 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
13858 return lookup_die_type (die
, type_attr
, cu
);
13861 /* If DIE has a descriptive_type attribute, then set the TYPE's
13862 descriptive type accordingly. */
13865 set_descriptive_type (struct type
*type
, struct die_info
*die
,
13866 struct dwarf2_cu
*cu
)
13868 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
13870 if (descriptive_type
)
13872 ALLOCATE_GNAT_AUX_TYPE (type
);
13873 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
13877 /* Return the containing type of the die in question using its
13878 DW_AT_containing_type attribute. */
13880 static struct type
*
13881 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13883 struct attribute
*type_attr
;
13885 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
13887 error (_("Dwarf Error: Problem turning containing type into gdb type "
13888 "[in module %s]"), cu
->objfile
->name
);
13890 return lookup_die_type (die
, type_attr
, cu
);
13893 /* Look up the type of DIE in CU using its type attribute ATTR.
13894 If there is no type substitute an error marker. */
13896 static struct type
*
13897 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
13898 struct dwarf2_cu
*cu
)
13900 struct objfile
*objfile
= cu
->objfile
;
13901 struct type
*this_type
;
13903 /* First see if we have it cached. */
13905 if (is_ref_attr (attr
))
13907 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
13909 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
13911 else if (attr
->form
== DW_FORM_ref_sig8
)
13913 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13915 /* sig_type will be NULL if the signatured type is missing from
13917 if (sig_type
== NULL
)
13918 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13919 "at 0x%x [in module %s]"),
13920 die
->offset
.sect_off
, objfile
->name
);
13922 gdb_assert (sig_type
->per_cu
.is_debug_types
);
13923 /* If we haven't filled in type_offset_in_section yet, then we
13924 haven't read the type in yet. */
13926 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
13929 get_die_type_at_offset (sig_type
->type_offset_in_section
,
13930 &sig_type
->per_cu
);
13935 dump_die_for_error (die
);
13936 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
13937 dwarf_attr_name (attr
->name
), objfile
->name
);
13940 /* If not cached we need to read it in. */
13942 if (this_type
== NULL
)
13944 struct die_info
*type_die
;
13945 struct dwarf2_cu
*type_cu
= cu
;
13947 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
13948 /* If we found the type now, it's probably because the type came
13949 from an inter-CU reference and the type's CU got expanded before
13951 this_type
= get_die_type (type_die
, type_cu
);
13952 if (this_type
== NULL
)
13953 this_type
= read_type_die_1 (type_die
, type_cu
);
13956 /* If we still don't have a type use an error marker. */
13958 if (this_type
== NULL
)
13960 char *message
, *saved
;
13962 /* read_type_die already issued a complaint. */
13963 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
13965 cu
->header
.offset
.sect_off
,
13966 die
->offset
.sect_off
);
13967 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
13968 message
, strlen (message
));
13971 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
13977 /* Return the type in DIE, CU.
13978 Returns NULL for invalid types.
13980 This first does a lookup in the appropriate type_hash table,
13981 and only reads the die in if necessary.
13983 NOTE: This can be called when reading in partial or full symbols. */
13985 static struct type
*
13986 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
13988 struct type
*this_type
;
13990 this_type
= get_die_type (die
, cu
);
13994 return read_type_die_1 (die
, cu
);
13997 /* Read the type in DIE, CU.
13998 Returns NULL for invalid types. */
14000 static struct type
*
14001 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
14003 struct type
*this_type
= NULL
;
14007 case DW_TAG_class_type
:
14008 case DW_TAG_interface_type
:
14009 case DW_TAG_structure_type
:
14010 case DW_TAG_union_type
:
14011 this_type
= read_structure_type (die
, cu
);
14013 case DW_TAG_enumeration_type
:
14014 this_type
= read_enumeration_type (die
, cu
);
14016 case DW_TAG_subprogram
:
14017 case DW_TAG_subroutine_type
:
14018 case DW_TAG_inlined_subroutine
:
14019 this_type
= read_subroutine_type (die
, cu
);
14021 case DW_TAG_array_type
:
14022 this_type
= read_array_type (die
, cu
);
14024 case DW_TAG_set_type
:
14025 this_type
= read_set_type (die
, cu
);
14027 case DW_TAG_pointer_type
:
14028 this_type
= read_tag_pointer_type (die
, cu
);
14030 case DW_TAG_ptr_to_member_type
:
14031 this_type
= read_tag_ptr_to_member_type (die
, cu
);
14033 case DW_TAG_reference_type
:
14034 this_type
= read_tag_reference_type (die
, cu
);
14036 case DW_TAG_const_type
:
14037 this_type
= read_tag_const_type (die
, cu
);
14039 case DW_TAG_volatile_type
:
14040 this_type
= read_tag_volatile_type (die
, cu
);
14042 case DW_TAG_string_type
:
14043 this_type
= read_tag_string_type (die
, cu
);
14045 case DW_TAG_typedef
:
14046 this_type
= read_typedef (die
, cu
);
14048 case DW_TAG_subrange_type
:
14049 this_type
= read_subrange_type (die
, cu
);
14051 case DW_TAG_base_type
:
14052 this_type
= read_base_type (die
, cu
);
14054 case DW_TAG_unspecified_type
:
14055 this_type
= read_unspecified_type (die
, cu
);
14057 case DW_TAG_namespace
:
14058 this_type
= read_namespace_type (die
, cu
);
14060 case DW_TAG_module
:
14061 this_type
= read_module_type (die
, cu
);
14064 complaint (&symfile_complaints
,
14065 _("unexpected tag in read_type_die: '%s'"),
14066 dwarf_tag_name (die
->tag
));
14073 /* See if we can figure out if the class lives in a namespace. We do
14074 this by looking for a member function; its demangled name will
14075 contain namespace info, if there is any.
14076 Return the computed name or NULL.
14077 Space for the result is allocated on the objfile's obstack.
14078 This is the full-die version of guess_partial_die_structure_name.
14079 In this case we know DIE has no useful parent. */
14082 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14084 struct die_info
*spec_die
;
14085 struct dwarf2_cu
*spec_cu
;
14086 struct die_info
*child
;
14089 spec_die
= die_specification (die
, &spec_cu
);
14090 if (spec_die
!= NULL
)
14096 for (child
= die
->child
;
14098 child
= child
->sibling
)
14100 if (child
->tag
== DW_TAG_subprogram
)
14102 struct attribute
*attr
;
14104 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
14106 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
14110 = language_class_name_from_physname (cu
->language_defn
,
14114 if (actual_name
!= NULL
)
14116 char *die_name
= dwarf2_name (die
, cu
);
14118 if (die_name
!= NULL
14119 && strcmp (die_name
, actual_name
) != 0)
14121 /* Strip off the class name from the full name.
14122 We want the prefix. */
14123 int die_name_len
= strlen (die_name
);
14124 int actual_name_len
= strlen (actual_name
);
14126 /* Test for '::' as a sanity check. */
14127 if (actual_name_len
> die_name_len
+ 2
14128 && actual_name
[actual_name_len
14129 - die_name_len
- 1] == ':')
14131 obsavestring (actual_name
,
14132 actual_name_len
- die_name_len
- 2,
14133 &cu
->objfile
->objfile_obstack
);
14136 xfree (actual_name
);
14145 /* GCC might emit a nameless typedef that has a linkage name. Determine the
14146 prefix part in such case. See
14147 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14150 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14152 struct attribute
*attr
;
14155 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
14156 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
14159 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14160 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
14163 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14165 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14166 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14169 /* dwarf2_name had to be already called. */
14170 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
14172 /* Strip the base name, keep any leading namespaces/classes. */
14173 base
= strrchr (DW_STRING (attr
), ':');
14174 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
14177 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
14178 &cu
->objfile
->objfile_obstack
);
14181 /* Return the name of the namespace/class that DIE is defined within,
14182 or "" if we can't tell. The caller should not xfree the result.
14184 For example, if we're within the method foo() in the following
14194 then determine_prefix on foo's die will return "N::C". */
14196 static const char *
14197 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14199 struct die_info
*parent
, *spec_die
;
14200 struct dwarf2_cu
*spec_cu
;
14201 struct type
*parent_type
;
14204 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
14205 && cu
->language
!= language_fortran
)
14208 retval
= anonymous_struct_prefix (die
, cu
);
14212 /* We have to be careful in the presence of DW_AT_specification.
14213 For example, with GCC 3.4, given the code
14217 // Definition of N::foo.
14221 then we'll have a tree of DIEs like this:
14223 1: DW_TAG_compile_unit
14224 2: DW_TAG_namespace // N
14225 3: DW_TAG_subprogram // declaration of N::foo
14226 4: DW_TAG_subprogram // definition of N::foo
14227 DW_AT_specification // refers to die #3
14229 Thus, when processing die #4, we have to pretend that we're in
14230 the context of its DW_AT_specification, namely the contex of die
14233 spec_die
= die_specification (die
, &spec_cu
);
14234 if (spec_die
== NULL
)
14235 parent
= die
->parent
;
14238 parent
= spec_die
->parent
;
14242 if (parent
== NULL
)
14244 else if (parent
->building_fullname
)
14247 const char *parent_name
;
14249 /* It has been seen on RealView 2.2 built binaries,
14250 DW_TAG_template_type_param types actually _defined_ as
14251 children of the parent class:
14254 template class <class Enum> Class{};
14255 Class<enum E> class_e;
14257 1: DW_TAG_class_type (Class)
14258 2: DW_TAG_enumeration_type (E)
14259 3: DW_TAG_enumerator (enum1:0)
14260 3: DW_TAG_enumerator (enum2:1)
14262 2: DW_TAG_template_type_param
14263 DW_AT_type DW_FORM_ref_udata (E)
14265 Besides being broken debug info, it can put GDB into an
14266 infinite loop. Consider:
14268 When we're building the full name for Class<E>, we'll start
14269 at Class, and go look over its template type parameters,
14270 finding E. We'll then try to build the full name of E, and
14271 reach here. We're now trying to build the full name of E,
14272 and look over the parent DIE for containing scope. In the
14273 broken case, if we followed the parent DIE of E, we'd again
14274 find Class, and once again go look at its template type
14275 arguments, etc., etc. Simply don't consider such parent die
14276 as source-level parent of this die (it can't be, the language
14277 doesn't allow it), and break the loop here. */
14278 name
= dwarf2_name (die
, cu
);
14279 parent_name
= dwarf2_name (parent
, cu
);
14280 complaint (&symfile_complaints
,
14281 _("template param type '%s' defined within parent '%s'"),
14282 name
? name
: "<unknown>",
14283 parent_name
? parent_name
: "<unknown>");
14287 switch (parent
->tag
)
14289 case DW_TAG_namespace
:
14290 parent_type
= read_type_die (parent
, cu
);
14291 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
14292 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
14293 Work around this problem here. */
14294 if (cu
->language
== language_cplus
14295 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
14297 /* We give a name to even anonymous namespaces. */
14298 return TYPE_TAG_NAME (parent_type
);
14299 case DW_TAG_class_type
:
14300 case DW_TAG_interface_type
:
14301 case DW_TAG_structure_type
:
14302 case DW_TAG_union_type
:
14303 case DW_TAG_module
:
14304 parent_type
= read_type_die (parent
, cu
);
14305 if (TYPE_TAG_NAME (parent_type
) != NULL
)
14306 return TYPE_TAG_NAME (parent_type
);
14308 /* An anonymous structure is only allowed non-static data
14309 members; no typedefs, no member functions, et cetera.
14310 So it does not need a prefix. */
14312 case DW_TAG_compile_unit
:
14313 case DW_TAG_partial_unit
:
14314 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
14315 if (cu
->language
== language_cplus
14316 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
14317 && die
->child
!= NULL
14318 && (die
->tag
== DW_TAG_class_type
14319 || die
->tag
== DW_TAG_structure_type
14320 || die
->tag
== DW_TAG_union_type
))
14322 char *name
= guess_full_die_structure_name (die
, cu
);
14328 return determine_prefix (parent
, cu
);
14332 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
14333 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
14334 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
14335 an obconcat, otherwise allocate storage for the result. The CU argument is
14336 used to determine the language and hence, the appropriate separator. */
14338 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
14341 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
14342 int physname
, struct dwarf2_cu
*cu
)
14344 const char *lead
= "";
14347 if (suffix
== NULL
|| suffix
[0] == '\0'
14348 || prefix
== NULL
|| prefix
[0] == '\0')
14350 else if (cu
->language
== language_java
)
14352 else if (cu
->language
== language_fortran
&& physname
)
14354 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
14355 DW_AT_MIPS_linkage_name is preferred and used instead. */
14363 if (prefix
== NULL
)
14365 if (suffix
== NULL
)
14371 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
14373 strcpy (retval
, lead
);
14374 strcat (retval
, prefix
);
14375 strcat (retval
, sep
);
14376 strcat (retval
, suffix
);
14381 /* We have an obstack. */
14382 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
14386 /* Return sibling of die, NULL if no sibling. */
14388 static struct die_info
*
14389 sibling_die (struct die_info
*die
)
14391 return die
->sibling
;
14394 /* Get name of a die, return NULL if not found. */
14397 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
14398 struct obstack
*obstack
)
14400 if (name
&& cu
->language
== language_cplus
)
14402 char *canon_name
= cp_canonicalize_string (name
);
14404 if (canon_name
!= NULL
)
14406 if (strcmp (canon_name
, name
) != 0)
14407 name
= obsavestring (canon_name
, strlen (canon_name
),
14409 xfree (canon_name
);
14416 /* Get name of a die, return NULL if not found. */
14419 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14421 struct attribute
*attr
;
14423 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14424 if ((!attr
|| !DW_STRING (attr
))
14425 && die
->tag
!= DW_TAG_class_type
14426 && die
->tag
!= DW_TAG_interface_type
14427 && die
->tag
!= DW_TAG_structure_type
14428 && die
->tag
!= DW_TAG_union_type
)
14433 case DW_TAG_compile_unit
:
14434 case DW_TAG_partial_unit
:
14435 /* Compilation units have a DW_AT_name that is a filename, not
14436 a source language identifier. */
14437 case DW_TAG_enumeration_type
:
14438 case DW_TAG_enumerator
:
14439 /* These tags always have simple identifiers already; no need
14440 to canonicalize them. */
14441 return DW_STRING (attr
);
14443 case DW_TAG_subprogram
:
14444 /* Java constructors will all be named "<init>", so return
14445 the class name when we see this special case. */
14446 if (cu
->language
== language_java
14447 && DW_STRING (attr
) != NULL
14448 && strcmp (DW_STRING (attr
), "<init>") == 0)
14450 struct dwarf2_cu
*spec_cu
= cu
;
14451 struct die_info
*spec_die
;
14453 /* GCJ will output '<init>' for Java constructor names.
14454 For this special case, return the name of the parent class. */
14456 /* GCJ may output suprogram DIEs with AT_specification set.
14457 If so, use the name of the specified DIE. */
14458 spec_die
= die_specification (die
, &spec_cu
);
14459 if (spec_die
!= NULL
)
14460 return dwarf2_name (spec_die
, spec_cu
);
14465 if (die
->tag
== DW_TAG_class_type
)
14466 return dwarf2_name (die
, cu
);
14468 while (die
->tag
!= DW_TAG_compile_unit
14469 && die
->tag
!= DW_TAG_partial_unit
);
14473 case DW_TAG_class_type
:
14474 case DW_TAG_interface_type
:
14475 case DW_TAG_structure_type
:
14476 case DW_TAG_union_type
:
14477 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
14478 structures or unions. These were of the form "._%d" in GCC 4.1,
14479 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
14480 and GCC 4.4. We work around this problem by ignoring these. */
14481 if (attr
&& DW_STRING (attr
)
14482 && (strncmp (DW_STRING (attr
), "._", 2) == 0
14483 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
14486 /* GCC might emit a nameless typedef that has a linkage name. See
14487 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14488 if (!attr
|| DW_STRING (attr
) == NULL
)
14490 char *demangled
= NULL
;
14492 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14494 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14496 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14499 /* Avoid demangling DW_STRING (attr) the second time on a second
14500 call for the same DIE. */
14501 if (!DW_STRING_IS_CANONICAL (attr
))
14502 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
14508 /* FIXME: we already did this for the partial symbol... */
14509 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
14510 &cu
->objfile
->objfile_obstack
);
14511 DW_STRING_IS_CANONICAL (attr
) = 1;
14514 /* Strip any leading namespaces/classes, keep only the base name.
14515 DW_AT_name for named DIEs does not contain the prefixes. */
14516 base
= strrchr (DW_STRING (attr
), ':');
14517 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
14520 return DW_STRING (attr
);
14529 if (!DW_STRING_IS_CANONICAL (attr
))
14532 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
14533 &cu
->objfile
->objfile_obstack
);
14534 DW_STRING_IS_CANONICAL (attr
) = 1;
14536 return DW_STRING (attr
);
14539 /* Return the die that this die in an extension of, or NULL if there
14540 is none. *EXT_CU is the CU containing DIE on input, and the CU
14541 containing the return value on output. */
14543 static struct die_info
*
14544 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
14546 struct attribute
*attr
;
14548 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
14552 return follow_die_ref (die
, attr
, ext_cu
);
14555 /* Convert a DIE tag into its string name. */
14557 static const char *
14558 dwarf_tag_name (unsigned tag
)
14560 const char *name
= get_DW_TAG_name (tag
);
14563 return "DW_TAG_<unknown>";
14568 /* Convert a DWARF attribute code into its string name. */
14570 static const char *
14571 dwarf_attr_name (unsigned attr
)
14575 #ifdef MIPS /* collides with DW_AT_HP_block_index */
14576 if (attr
== DW_AT_MIPS_fde
)
14577 return "DW_AT_MIPS_fde";
14579 if (attr
== DW_AT_HP_block_index
)
14580 return "DW_AT_HP_block_index";
14583 name
= get_DW_AT_name (attr
);
14586 return "DW_AT_<unknown>";
14591 /* Convert a DWARF value form code into its string name. */
14593 static const char *
14594 dwarf_form_name (unsigned form
)
14596 const char *name
= get_DW_FORM_name (form
);
14599 return "DW_FORM_<unknown>";
14605 dwarf_bool_name (unsigned mybool
)
14613 /* Convert a DWARF type code into its string name. */
14615 static const char *
14616 dwarf_type_encoding_name (unsigned enc
)
14618 const char *name
= get_DW_ATE_name (enc
);
14621 return "DW_ATE_<unknown>";
14627 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
14631 print_spaces (indent
, f
);
14632 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
14633 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
14635 if (die
->parent
!= NULL
)
14637 print_spaces (indent
, f
);
14638 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
14639 die
->parent
->offset
.sect_off
);
14642 print_spaces (indent
, f
);
14643 fprintf_unfiltered (f
, " has children: %s\n",
14644 dwarf_bool_name (die
->child
!= NULL
));
14646 print_spaces (indent
, f
);
14647 fprintf_unfiltered (f
, " attributes:\n");
14649 for (i
= 0; i
< die
->num_attrs
; ++i
)
14651 print_spaces (indent
, f
);
14652 fprintf_unfiltered (f
, " %s (%s) ",
14653 dwarf_attr_name (die
->attrs
[i
].name
),
14654 dwarf_form_name (die
->attrs
[i
].form
));
14656 switch (die
->attrs
[i
].form
)
14659 case DW_FORM_GNU_addr_index
:
14660 fprintf_unfiltered (f
, "address: ");
14661 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
14663 case DW_FORM_block2
:
14664 case DW_FORM_block4
:
14665 case DW_FORM_block
:
14666 case DW_FORM_block1
:
14667 fprintf_unfiltered (f
, "block: size %d",
14668 DW_BLOCK (&die
->attrs
[i
])->size
);
14670 case DW_FORM_exprloc
:
14671 fprintf_unfiltered (f
, "expression: size %u",
14672 DW_BLOCK (&die
->attrs
[i
])->size
);
14674 case DW_FORM_ref_addr
:
14675 fprintf_unfiltered (f
, "ref address: ");
14676 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
14682 case DW_FORM_ref_udata
:
14683 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
14684 (long) (DW_UNSND (&die
->attrs
[i
])));
14686 case DW_FORM_data1
:
14687 case DW_FORM_data2
:
14688 case DW_FORM_data4
:
14689 case DW_FORM_data8
:
14690 case DW_FORM_udata
:
14691 case DW_FORM_sdata
:
14692 fprintf_unfiltered (f
, "constant: %s",
14693 pulongest (DW_UNSND (&die
->attrs
[i
])));
14695 case DW_FORM_sec_offset
:
14696 fprintf_unfiltered (f
, "section offset: %s",
14697 pulongest (DW_UNSND (&die
->attrs
[i
])));
14699 case DW_FORM_ref_sig8
:
14700 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
14701 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
14702 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
14704 fprintf_unfiltered (f
, "signatured type, offset: unknown");
14706 case DW_FORM_string
:
14708 case DW_FORM_GNU_str_index
:
14709 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
14710 DW_STRING (&die
->attrs
[i
])
14711 ? DW_STRING (&die
->attrs
[i
]) : "",
14712 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
14715 if (DW_UNSND (&die
->attrs
[i
]))
14716 fprintf_unfiltered (f
, "flag: TRUE");
14718 fprintf_unfiltered (f
, "flag: FALSE");
14720 case DW_FORM_flag_present
:
14721 fprintf_unfiltered (f
, "flag: TRUE");
14723 case DW_FORM_indirect
:
14724 /* The reader will have reduced the indirect form to
14725 the "base form" so this form should not occur. */
14726 fprintf_unfiltered (f
,
14727 "unexpected attribute form: DW_FORM_indirect");
14730 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
14731 die
->attrs
[i
].form
);
14734 fprintf_unfiltered (f
, "\n");
14739 dump_die_for_error (struct die_info
*die
)
14741 dump_die_shallow (gdb_stderr
, 0, die
);
14745 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
14747 int indent
= level
* 4;
14749 gdb_assert (die
!= NULL
);
14751 if (level
>= max_level
)
14754 dump_die_shallow (f
, indent
, die
);
14756 if (die
->child
!= NULL
)
14758 print_spaces (indent
, f
);
14759 fprintf_unfiltered (f
, " Children:");
14760 if (level
+ 1 < max_level
)
14762 fprintf_unfiltered (f
, "\n");
14763 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
14767 fprintf_unfiltered (f
,
14768 " [not printed, max nesting level reached]\n");
14772 if (die
->sibling
!= NULL
&& level
> 0)
14774 dump_die_1 (f
, level
, max_level
, die
->sibling
);
14778 /* This is called from the pdie macro in gdbinit.in.
14779 It's not static so gcc will keep a copy callable from gdb. */
14782 dump_die (struct die_info
*die
, int max_level
)
14784 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14788 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14792 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
14798 /* DW_ADDR is always stored already as sect_offset; despite for the forms
14799 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
14802 is_ref_attr (struct attribute
*attr
)
14804 switch (attr
->form
)
14806 case DW_FORM_ref_addr
:
14811 case DW_FORM_ref_udata
:
14818 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
14822 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14824 sect_offset retval
= { DW_UNSND (attr
) };
14826 if (is_ref_attr (attr
))
14829 retval
.sect_off
= 0;
14830 complaint (&symfile_complaints
,
14831 _("unsupported die ref attribute form: '%s'"),
14832 dwarf_form_name (attr
->form
));
14836 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14837 * the value held by the attribute is not constant. */
14840 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14842 if (attr
->form
== DW_FORM_sdata
)
14843 return DW_SND (attr
);
14844 else if (attr
->form
== DW_FORM_udata
14845 || attr
->form
== DW_FORM_data1
14846 || attr
->form
== DW_FORM_data2
14847 || attr
->form
== DW_FORM_data4
14848 || attr
->form
== DW_FORM_data8
)
14849 return DW_UNSND (attr
);
14852 complaint (&symfile_complaints
,
14853 _("Attribute value is not a constant (%s)"),
14854 dwarf_form_name (attr
->form
));
14855 return default_value
;
14859 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14860 unit and add it to our queue.
14861 The result is non-zero if PER_CU was queued, otherwise the result is zero
14862 meaning either PER_CU is already queued or it is already loaded. */
14865 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14866 struct dwarf2_per_cu_data
*per_cu
,
14867 enum language pretend_language
)
14869 /* We may arrive here during partial symbol reading, if we need full
14870 DIEs to process an unusual case (e.g. template arguments). Do
14871 not queue PER_CU, just tell our caller to load its DIEs. */
14872 if (dwarf2_per_objfile
->reading_partial_symbols
)
14874 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14879 /* Mark the dependence relation so that we don't flush PER_CU
14881 dwarf2_add_dependence (this_cu
, per_cu
);
14883 /* If it's already on the queue, we have nothing to do. */
14884 if (per_cu
->queued
)
14887 /* If the compilation unit is already loaded, just mark it as
14889 if (per_cu
->cu
!= NULL
)
14891 per_cu
->cu
->last_used
= 0;
14895 /* Add it to the queue. */
14896 queue_comp_unit (per_cu
, pretend_language
);
14901 /* Follow reference or signature attribute ATTR of SRC_DIE.
14902 On entry *REF_CU is the CU of SRC_DIE.
14903 On exit *REF_CU is the CU of the result. */
14905 static struct die_info
*
14906 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14907 struct dwarf2_cu
**ref_cu
)
14909 struct die_info
*die
;
14911 if (is_ref_attr (attr
))
14912 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14913 else if (attr
->form
== DW_FORM_ref_sig8
)
14914 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14917 dump_die_for_error (src_die
);
14918 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14919 (*ref_cu
)->objfile
->name
);
14925 /* Follow reference OFFSET.
14926 On entry *REF_CU is the CU of the source die referencing OFFSET.
14927 On exit *REF_CU is the CU of the result.
14928 Returns NULL if OFFSET is invalid. */
14930 static struct die_info
*
14931 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
14933 struct die_info temp_die
;
14934 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14936 gdb_assert (cu
->per_cu
!= NULL
);
14940 if (cu
->per_cu
->is_debug_types
)
14942 /* .debug_types CUs cannot reference anything outside their CU.
14943 If they need to, they have to reference a signatured type via
14944 DW_FORM_ref_sig8. */
14945 if (! offset_in_cu_p (&cu
->header
, offset
))
14948 else if (! offset_in_cu_p (&cu
->header
, offset
))
14950 struct dwarf2_per_cu_data
*per_cu
;
14952 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14954 /* If necessary, add it to the queue and load its DIEs. */
14955 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
14956 load_full_comp_unit (per_cu
, cu
->language
);
14958 target_cu
= per_cu
->cu
;
14960 else if (cu
->dies
== NULL
)
14962 /* We're loading full DIEs during partial symbol reading. */
14963 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14964 load_full_comp_unit (cu
->per_cu
, language_minimal
);
14967 *ref_cu
= target_cu
;
14968 temp_die
.offset
= offset
;
14969 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
14972 /* Follow reference attribute ATTR of SRC_DIE.
14973 On entry *REF_CU is the CU of SRC_DIE.
14974 On exit *REF_CU is the CU of the result. */
14976 static struct die_info
*
14977 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14978 struct dwarf2_cu
**ref_cu
)
14980 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
14981 struct dwarf2_cu
*cu
= *ref_cu
;
14982 struct die_info
*die
;
14984 die
= follow_die_offset (offset
, ref_cu
);
14986 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14987 "at 0x%x [in module %s]"),
14988 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
14993 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14994 Returned value is intended for DW_OP_call*. Returned
14995 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14997 struct dwarf2_locexpr_baton
14998 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
14999 struct dwarf2_per_cu_data
*per_cu
,
15000 CORE_ADDR (*get_frame_pc
) (void *baton
),
15003 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
15004 struct dwarf2_cu
*cu
;
15005 struct die_info
*die
;
15006 struct attribute
*attr
;
15007 struct dwarf2_locexpr_baton retval
;
15009 dw2_setup (per_cu
->objfile
);
15011 if (per_cu
->cu
== NULL
)
15015 die
= follow_die_offset (offset
, &cu
);
15017 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
15018 offset
.sect_off
, per_cu
->objfile
->name
);
15020 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15023 /* DWARF: "If there is no such attribute, then there is no effect.".
15024 DATA is ignored if SIZE is 0. */
15026 retval
.data
= NULL
;
15029 else if (attr_form_is_section_offset (attr
))
15031 struct dwarf2_loclist_baton loclist_baton
;
15032 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
15035 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
15037 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
15039 retval
.size
= size
;
15043 if (!attr_form_is_block (attr
))
15044 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
15045 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
15046 offset
.sect_off
, per_cu
->objfile
->name
);
15048 retval
.data
= DW_BLOCK (attr
)->data
;
15049 retval
.size
= DW_BLOCK (attr
)->size
;
15051 retval
.per_cu
= cu
->per_cu
;
15053 age_cached_comp_units ();
15058 /* Return the type of the DIE at DIE_OFFSET in the CU named by
15062 dwarf2_get_die_type (cu_offset die_offset
,
15063 struct dwarf2_per_cu_data
*per_cu
)
15065 sect_offset die_offset_sect
;
15067 dw2_setup (per_cu
->objfile
);
15069 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
15070 return get_die_type_at_offset (die_offset_sect
, per_cu
);
15073 /* Follow the signature attribute ATTR in SRC_DIE.
15074 On entry *REF_CU is the CU of SRC_DIE.
15075 On exit *REF_CU is the CU of the result. */
15077 static struct die_info
*
15078 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
15079 struct dwarf2_cu
**ref_cu
)
15081 struct objfile
*objfile
= (*ref_cu
)->objfile
;
15082 struct die_info temp_die
;
15083 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15084 struct dwarf2_cu
*sig_cu
;
15085 struct die_info
*die
;
15087 /* sig_type will be NULL if the signatured type is missing from
15089 if (sig_type
== NULL
)
15090 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15091 "at 0x%x [in module %s]"),
15092 src_die
->offset
.sect_off
, objfile
->name
);
15094 /* If necessary, add it to the queue and load its DIEs. */
15096 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
15097 read_signatured_type (sig_type
);
15099 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15101 sig_cu
= sig_type
->per_cu
.cu
;
15102 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
15103 temp_die
.offset
= sig_type
->type_offset_in_section
;
15104 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
15105 temp_die
.offset
.sect_off
);
15112 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
15113 "from DIE at 0x%x [in module %s]"),
15114 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
15117 /* Given an offset of a signatured type, return its signatured_type. */
15119 static struct signatured_type
*
15120 lookup_signatured_type_at_offset (struct objfile
*objfile
,
15121 struct dwarf2_section_info
*section
,
15122 sect_offset offset
)
15124 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
15125 unsigned int length
, initial_length_size
;
15126 unsigned int sig_offset
;
15127 struct signatured_type find_entry
, *sig_type
;
15129 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
15130 sig_offset
= (initial_length_size
15132 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
15133 + 1 /*address_size*/);
15134 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
15135 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
15137 /* This is only used to lookup previously recorded types.
15138 If we didn't find it, it's our bug. */
15139 gdb_assert (sig_type
!= NULL
);
15140 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
15145 /* Load the DIEs associated with type unit PER_CU into memory. */
15148 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
15150 struct objfile
*objfile
= per_cu
->objfile
;
15151 struct dwarf2_section_info
*sect
= per_cu
->info_or_types_section
;
15152 sect_offset offset
= per_cu
->offset
;
15153 struct signatured_type
*sig_type
;
15155 dwarf2_read_section (objfile
, sect
);
15157 /* We have the section offset, but we need the signature to do the
15158 hash table lookup. */
15159 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
15160 the signature to assert we found the right one.
15161 Ok, but it's a lot of work. We should simplify things so any needed
15162 assert doesn't require all this clumsiness. */
15163 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
15165 gdb_assert (&sig_type
->per_cu
== per_cu
);
15166 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
15168 read_signatured_type (sig_type
);
15170 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15173 /* die_reader_func for read_signatured_type.
15174 This is identical to load_full_comp_unit_reader,
15175 but is kept separate for now. */
15178 read_signatured_type_reader (const struct die_reader_specs
*reader
,
15179 gdb_byte
*info_ptr
,
15180 struct die_info
*comp_unit_die
,
15184 struct dwarf2_cu
*cu
= reader
->cu
;
15185 struct attribute
*attr
;
15187 gdb_assert (cu
->die_hash
== NULL
);
15189 htab_create_alloc_ex (cu
->header
.length
/ 12,
15193 &cu
->comp_unit_obstack
,
15194 hashtab_obstack_allocate
,
15195 dummy_obstack_deallocate
);
15198 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
15199 &info_ptr
, comp_unit_die
);
15200 cu
->dies
= comp_unit_die
;
15201 /* comp_unit_die is not stored in die_hash, no need. */
15203 /* We try not to read any attributes in this function, because not
15204 all CUs needed for references have been loaded yet, and symbol
15205 table processing isn't initialized. But we have to set the CU language,
15206 or we won't be able to build types correctly.
15207 Similarly, if we do not read the producer, we can not apply
15208 producer-specific interpretation. */
15209 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
15212 /* Read in a signatured type and build its CU and DIEs.
15213 If the type is a stub for the real type in a DWO file,
15214 read in the real type from the DWO file as well. */
15217 read_signatured_type (struct signatured_type
*sig_type
)
15219 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
15221 gdb_assert (per_cu
->is_debug_types
);
15222 gdb_assert (per_cu
->cu
== NULL
);
15224 init_cutu_and_read_dies (per_cu
, 0, 1, read_signatured_type_reader
, NULL
);
15227 /* Decode simple location descriptions.
15228 Given a pointer to a dwarf block that defines a location, compute
15229 the location and return the value.
15231 NOTE drow/2003-11-18: This function is called in two situations
15232 now: for the address of static or global variables (partial symbols
15233 only) and for offsets into structures which are expected to be
15234 (more or less) constant. The partial symbol case should go away,
15235 and only the constant case should remain. That will let this
15236 function complain more accurately. A few special modes are allowed
15237 without complaint for global variables (for instance, global
15238 register values and thread-local values).
15240 A location description containing no operations indicates that the
15241 object is optimized out. The return value is 0 for that case.
15242 FIXME drow/2003-11-16: No callers check for this case any more; soon all
15243 callers will only want a very basic result and this can become a
15246 Note that stack[0] is unused except as a default error return. */
15249 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
15251 struct objfile
*objfile
= cu
->objfile
;
15253 int size
= blk
->size
;
15254 gdb_byte
*data
= blk
->data
;
15255 CORE_ADDR stack
[64];
15257 unsigned int bytes_read
, unsnd
;
15263 stack
[++stacki
] = 0;
15302 stack
[++stacki
] = op
- DW_OP_lit0
;
15337 stack
[++stacki
] = op
- DW_OP_reg0
;
15339 dwarf2_complex_location_expr_complaint ();
15343 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
15345 stack
[++stacki
] = unsnd
;
15347 dwarf2_complex_location_expr_complaint ();
15351 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
15356 case DW_OP_const1u
:
15357 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
15361 case DW_OP_const1s
:
15362 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
15366 case DW_OP_const2u
:
15367 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
15371 case DW_OP_const2s
:
15372 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
15376 case DW_OP_const4u
:
15377 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
15381 case DW_OP_const4s
:
15382 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
15386 case DW_OP_const8u
:
15387 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
15392 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
15398 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
15403 stack
[stacki
+ 1] = stack
[stacki
];
15408 stack
[stacki
- 1] += stack
[stacki
];
15412 case DW_OP_plus_uconst
:
15413 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
15419 stack
[stacki
- 1] -= stack
[stacki
];
15424 /* If we're not the last op, then we definitely can't encode
15425 this using GDB's address_class enum. This is valid for partial
15426 global symbols, although the variable's address will be bogus
15429 dwarf2_complex_location_expr_complaint ();
15432 case DW_OP_GNU_push_tls_address
:
15433 /* The top of the stack has the offset from the beginning
15434 of the thread control block at which the variable is located. */
15435 /* Nothing should follow this operator, so the top of stack would
15437 /* This is valid for partial global symbols, but the variable's
15438 address will be bogus in the psymtab. Make it always at least
15439 non-zero to not look as a variable garbage collected by linker
15440 which have DW_OP_addr 0. */
15442 dwarf2_complex_location_expr_complaint ();
15446 case DW_OP_GNU_uninit
:
15449 case DW_OP_GNU_addr_index
:
15450 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
15457 const char *name
= get_DW_OP_name (op
);
15460 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
15463 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
15467 return (stack
[stacki
]);
15470 /* Enforce maximum stack depth of SIZE-1 to avoid writing
15471 outside of the allocated space. Also enforce minimum>0. */
15472 if (stacki
>= ARRAY_SIZE (stack
) - 1)
15474 complaint (&symfile_complaints
,
15475 _("location description stack overflow"));
15481 complaint (&symfile_complaints
,
15482 _("location description stack underflow"));
15486 return (stack
[stacki
]);
15489 /* memory allocation interface */
15491 static struct dwarf_block
*
15492 dwarf_alloc_block (struct dwarf2_cu
*cu
)
15494 struct dwarf_block
*blk
;
15496 blk
= (struct dwarf_block
*)
15497 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
15501 static struct abbrev_info
*
15502 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
15504 struct abbrev_info
*abbrev
;
15506 abbrev
= (struct abbrev_info
*)
15507 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
15508 memset (abbrev
, 0, sizeof (struct abbrev_info
));
15512 static struct die_info
*
15513 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
15515 struct die_info
*die
;
15516 size_t size
= sizeof (struct die_info
);
15519 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
15521 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
15522 memset (die
, 0, sizeof (struct die_info
));
15527 /* Macro support. */
15529 /* Return the full name of file number I in *LH's file name table.
15530 Use COMP_DIR as the name of the current directory of the
15531 compilation. The result is allocated using xmalloc; the caller is
15532 responsible for freeing it. */
15534 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
15536 /* Is the file number a valid index into the line header's file name
15537 table? Remember that file numbers start with one, not zero. */
15538 if (1 <= file
&& file
<= lh
->num_file_names
)
15540 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15542 if (IS_ABSOLUTE_PATH (fe
->name
))
15543 return xstrdup (fe
->name
);
15551 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15557 dir_len
= strlen (dir
);
15558 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
15559 strcpy (full_name
, dir
);
15560 full_name
[dir_len
] = '/';
15561 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
15565 return xstrdup (fe
->name
);
15570 /* The compiler produced a bogus file number. We can at least
15571 record the macro definitions made in the file, even if we
15572 won't be able to find the file by name. */
15573 char fake_name
[80];
15575 sprintf (fake_name
, "<bad macro file number %d>", file
);
15577 complaint (&symfile_complaints
,
15578 _("bad file number in macro information (%d)"),
15581 return xstrdup (fake_name
);
15586 static struct macro_source_file
*
15587 macro_start_file (int file
, int line
,
15588 struct macro_source_file
*current_file
,
15589 const char *comp_dir
,
15590 struct line_header
*lh
, struct objfile
*objfile
)
15592 /* The full name of this source file. */
15593 char *full_name
= file_full_name (file
, lh
, comp_dir
);
15595 /* We don't create a macro table for this compilation unit
15596 at all until we actually get a filename. */
15597 if (! pending_macros
)
15598 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
15599 objfile
->macro_cache
);
15601 if (! current_file
)
15603 /* If we have no current file, then this must be the start_file
15604 directive for the compilation unit's main source file. */
15605 current_file
= macro_set_main (pending_macros
, full_name
);
15606 macro_define_special (pending_macros
);
15609 current_file
= macro_include (current_file
, line
, full_name
);
15613 return current_file
;
15617 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
15618 followed by a null byte. */
15620 copy_string (const char *buf
, int len
)
15622 char *s
= xmalloc (len
+ 1);
15624 memcpy (s
, buf
, len
);
15630 static const char *
15631 consume_improper_spaces (const char *p
, const char *body
)
15635 complaint (&symfile_complaints
,
15636 _("macro definition contains spaces "
15637 "in formal argument list:\n`%s'"),
15649 parse_macro_definition (struct macro_source_file
*file
, int line
,
15654 /* The body string takes one of two forms. For object-like macro
15655 definitions, it should be:
15657 <macro name> " " <definition>
15659 For function-like macro definitions, it should be:
15661 <macro name> "() " <definition>
15663 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
15665 Spaces may appear only where explicitly indicated, and in the
15668 The Dwarf 2 spec says that an object-like macro's name is always
15669 followed by a space, but versions of GCC around March 2002 omit
15670 the space when the macro's definition is the empty string.
15672 The Dwarf 2 spec says that there should be no spaces between the
15673 formal arguments in a function-like macro's formal argument list,
15674 but versions of GCC around March 2002 include spaces after the
15678 /* Find the extent of the macro name. The macro name is terminated
15679 by either a space or null character (for an object-like macro) or
15680 an opening paren (for a function-like macro). */
15681 for (p
= body
; *p
; p
++)
15682 if (*p
== ' ' || *p
== '(')
15685 if (*p
== ' ' || *p
== '\0')
15687 /* It's an object-like macro. */
15688 int name_len
= p
- body
;
15689 char *name
= copy_string (body
, name_len
);
15690 const char *replacement
;
15693 replacement
= body
+ name_len
+ 1;
15696 dwarf2_macro_malformed_definition_complaint (body
);
15697 replacement
= body
+ name_len
;
15700 macro_define_object (file
, line
, name
, replacement
);
15704 else if (*p
== '(')
15706 /* It's a function-like macro. */
15707 char *name
= copy_string (body
, p
- body
);
15710 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
15714 p
= consume_improper_spaces (p
, body
);
15716 /* Parse the formal argument list. */
15717 while (*p
&& *p
!= ')')
15719 /* Find the extent of the current argument name. */
15720 const char *arg_start
= p
;
15722 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
15725 if (! *p
|| p
== arg_start
)
15726 dwarf2_macro_malformed_definition_complaint (body
);
15729 /* Make sure argv has room for the new argument. */
15730 if (argc
>= argv_size
)
15733 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
15736 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
15739 p
= consume_improper_spaces (p
, body
);
15741 /* Consume the comma, if present. */
15746 p
= consume_improper_spaces (p
, body
);
15755 /* Perfectly formed definition, no complaints. */
15756 macro_define_function (file
, line
, name
,
15757 argc
, (const char **) argv
,
15759 else if (*p
== '\0')
15761 /* Complain, but do define it. */
15762 dwarf2_macro_malformed_definition_complaint (body
);
15763 macro_define_function (file
, line
, name
,
15764 argc
, (const char **) argv
,
15768 /* Just complain. */
15769 dwarf2_macro_malformed_definition_complaint (body
);
15772 /* Just complain. */
15773 dwarf2_macro_malformed_definition_complaint (body
);
15779 for (i
= 0; i
< argc
; i
++)
15785 dwarf2_macro_malformed_definition_complaint (body
);
15788 /* Skip some bytes from BYTES according to the form given in FORM.
15789 Returns the new pointer. */
15792 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
15793 enum dwarf_form form
,
15794 unsigned int offset_size
,
15795 struct dwarf2_section_info
*section
)
15797 unsigned int bytes_read
;
15801 case DW_FORM_data1
:
15806 case DW_FORM_data2
:
15810 case DW_FORM_data4
:
15814 case DW_FORM_data8
:
15818 case DW_FORM_string
:
15819 read_direct_string (abfd
, bytes
, &bytes_read
);
15820 bytes
+= bytes_read
;
15823 case DW_FORM_sec_offset
:
15825 bytes
+= offset_size
;
15828 case DW_FORM_block
:
15829 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15830 bytes
+= bytes_read
;
15833 case DW_FORM_block1
:
15834 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15836 case DW_FORM_block2
:
15837 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15839 case DW_FORM_block4
:
15840 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15843 case DW_FORM_sdata
:
15844 case DW_FORM_udata
:
15845 case DW_FORM_GNU_addr_index
:
15846 case DW_FORM_GNU_str_index
:
15847 bytes
= skip_leb128 (abfd
, bytes
);
15853 complaint (&symfile_complaints
,
15854 _("invalid form 0x%x in `%s'"),
15856 section
->asection
->name
);
15864 /* A helper for dwarf_decode_macros that handles skipping an unknown
15865 opcode. Returns an updated pointer to the macro data buffer; or,
15866 on error, issues a complaint and returns NULL. */
15869 skip_unknown_opcode (unsigned int opcode
,
15870 gdb_byte
**opcode_definitions
,
15873 unsigned int offset_size
,
15874 struct dwarf2_section_info
*section
)
15876 unsigned int bytes_read
, i
;
15880 if (opcode_definitions
[opcode
] == NULL
)
15882 complaint (&symfile_complaints
,
15883 _("unrecognized DW_MACFINO opcode 0x%x"),
15888 defn
= opcode_definitions
[opcode
];
15889 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15890 defn
+= bytes_read
;
15892 for (i
= 0; i
< arg
; ++i
)
15894 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15895 if (mac_ptr
== NULL
)
15897 /* skip_form_bytes already issued the complaint. */
15905 /* A helper function which parses the header of a macro section.
15906 If the macro section is the extended (for now called "GNU") type,
15907 then this updates *OFFSET_SIZE. Returns a pointer to just after
15908 the header, or issues a complaint and returns NULL on error. */
15911 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15914 unsigned int *offset_size
,
15915 int section_is_gnu
)
15917 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15919 if (section_is_gnu
)
15921 unsigned int version
, flags
;
15923 version
= read_2_bytes (abfd
, mac_ptr
);
15926 complaint (&symfile_complaints
,
15927 _("unrecognized version `%d' in .debug_macro section"),
15933 flags
= read_1_byte (abfd
, mac_ptr
);
15935 *offset_size
= (flags
& 1) ? 8 : 4;
15937 if ((flags
& 2) != 0)
15938 /* We don't need the line table offset. */
15939 mac_ptr
+= *offset_size
;
15941 /* Vendor opcode descriptions. */
15942 if ((flags
& 4) != 0)
15944 unsigned int i
, count
;
15946 count
= read_1_byte (abfd
, mac_ptr
);
15948 for (i
= 0; i
< count
; ++i
)
15950 unsigned int opcode
, bytes_read
;
15953 opcode
= read_1_byte (abfd
, mac_ptr
);
15955 opcode_definitions
[opcode
] = mac_ptr
;
15956 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15957 mac_ptr
+= bytes_read
;
15966 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15967 including DW_MACRO_GNU_transparent_include. */
15970 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15971 struct macro_source_file
*current_file
,
15972 struct line_header
*lh
, char *comp_dir
,
15973 struct dwarf2_section_info
*section
,
15974 int section_is_gnu
,
15975 unsigned int offset_size
,
15976 struct objfile
*objfile
,
15977 htab_t include_hash
)
15979 enum dwarf_macro_record_type macinfo_type
;
15980 int at_commandline
;
15981 gdb_byte
*opcode_definitions
[256];
15983 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15984 &offset_size
, section_is_gnu
);
15985 if (mac_ptr
== NULL
)
15987 /* We already issued a complaint. */
15991 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15992 GDB is still reading the definitions from command line. First
15993 DW_MACINFO_start_file will need to be ignored as it was already executed
15994 to create CURRENT_FILE for the main source holding also the command line
15995 definitions. On first met DW_MACINFO_start_file this flag is reset to
15996 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15998 at_commandline
= 1;
16002 /* Do we at least have room for a macinfo type byte? */
16003 if (mac_ptr
>= mac_end
)
16005 dwarf2_macros_too_long_complaint (section
);
16009 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16012 /* Note that we rely on the fact that the corresponding GNU and
16013 DWARF constants are the same. */
16014 switch (macinfo_type
)
16016 /* A zero macinfo type indicates the end of the macro
16021 case DW_MACRO_GNU_define
:
16022 case DW_MACRO_GNU_undef
:
16023 case DW_MACRO_GNU_define_indirect
:
16024 case DW_MACRO_GNU_undef_indirect
:
16026 unsigned int bytes_read
;
16031 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16032 mac_ptr
+= bytes_read
;
16034 if (macinfo_type
== DW_MACRO_GNU_define
16035 || macinfo_type
== DW_MACRO_GNU_undef
)
16037 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16038 mac_ptr
+= bytes_read
;
16042 LONGEST str_offset
;
16044 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16045 mac_ptr
+= offset_size
;
16047 body
= read_indirect_string_at_offset (abfd
, str_offset
);
16050 is_define
= (macinfo_type
== DW_MACRO_GNU_define
16051 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
16052 if (! current_file
)
16054 /* DWARF violation as no main source is present. */
16055 complaint (&symfile_complaints
,
16056 _("debug info with no main source gives macro %s "
16058 is_define
? _("definition") : _("undefinition"),
16062 if ((line
== 0 && !at_commandline
)
16063 || (line
!= 0 && at_commandline
))
16064 complaint (&symfile_complaints
,
16065 _("debug info gives %s macro %s with %s line %d: %s"),
16066 at_commandline
? _("command-line") : _("in-file"),
16067 is_define
? _("definition") : _("undefinition"),
16068 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
16071 parse_macro_definition (current_file
, line
, body
);
16074 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
16075 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
16076 macro_undef (current_file
, line
, body
);
16081 case DW_MACRO_GNU_start_file
:
16083 unsigned int bytes_read
;
16086 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16087 mac_ptr
+= bytes_read
;
16088 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16089 mac_ptr
+= bytes_read
;
16091 if ((line
== 0 && !at_commandline
)
16092 || (line
!= 0 && at_commandline
))
16093 complaint (&symfile_complaints
,
16094 _("debug info gives source %d included "
16095 "from %s at %s line %d"),
16096 file
, at_commandline
? _("command-line") : _("file"),
16097 line
== 0 ? _("zero") : _("non-zero"), line
);
16099 if (at_commandline
)
16101 /* This DW_MACRO_GNU_start_file was executed in the
16103 at_commandline
= 0;
16106 current_file
= macro_start_file (file
, line
,
16107 current_file
, comp_dir
,
16112 case DW_MACRO_GNU_end_file
:
16113 if (! current_file
)
16114 complaint (&symfile_complaints
,
16115 _("macro debug info has an unmatched "
16116 "`close_file' directive"));
16119 current_file
= current_file
->included_by
;
16120 if (! current_file
)
16122 enum dwarf_macro_record_type next_type
;
16124 /* GCC circa March 2002 doesn't produce the zero
16125 type byte marking the end of the compilation
16126 unit. Complain if it's not there, but exit no
16129 /* Do we at least have room for a macinfo type byte? */
16130 if (mac_ptr
>= mac_end
)
16132 dwarf2_macros_too_long_complaint (section
);
16136 /* We don't increment mac_ptr here, so this is just
16138 next_type
= read_1_byte (abfd
, mac_ptr
);
16139 if (next_type
!= 0)
16140 complaint (&symfile_complaints
,
16141 _("no terminating 0-type entry for "
16142 "macros in `.debug_macinfo' section"));
16149 case DW_MACRO_GNU_transparent_include
:
16154 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16155 mac_ptr
+= offset_size
;
16157 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16160 /* This has actually happened; see
16161 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
16162 complaint (&symfile_complaints
,
16163 _("recursive DW_MACRO_GNU_transparent_include in "
16164 ".debug_macro section"));
16170 dwarf_decode_macro_bytes (abfd
,
16171 section
->buffer
+ offset
,
16172 mac_end
, current_file
,
16174 section
, section_is_gnu
,
16175 offset_size
, objfile
, include_hash
);
16177 htab_remove_elt (include_hash
, mac_ptr
);
16182 case DW_MACINFO_vendor_ext
:
16183 if (!section_is_gnu
)
16185 unsigned int bytes_read
;
16188 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16189 mac_ptr
+= bytes_read
;
16190 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16191 mac_ptr
+= bytes_read
;
16193 /* We don't recognize any vendor extensions. */
16199 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16200 mac_ptr
, abfd
, offset_size
,
16202 if (mac_ptr
== NULL
)
16206 } while (macinfo_type
!= 0);
16210 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
16211 char *comp_dir
, bfd
*abfd
,
16212 struct dwarf2_cu
*cu
,
16213 struct dwarf2_section_info
*section
,
16214 int section_is_gnu
, const char *section_name
)
16216 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16217 gdb_byte
*mac_ptr
, *mac_end
;
16218 struct macro_source_file
*current_file
= 0;
16219 enum dwarf_macro_record_type macinfo_type
;
16220 unsigned int offset_size
= cu
->header
.offset_size
;
16221 gdb_byte
*opcode_definitions
[256];
16222 struct cleanup
*cleanup
;
16223 htab_t include_hash
;
16226 dwarf2_read_section (objfile
, section
);
16227 if (section
->buffer
== NULL
)
16229 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
16233 /* First pass: Find the name of the base filename.
16234 This filename is needed in order to process all macros whose definition
16235 (or undefinition) comes from the command line. These macros are defined
16236 before the first DW_MACINFO_start_file entry, and yet still need to be
16237 associated to the base file.
16239 To determine the base file name, we scan the macro definitions until we
16240 reach the first DW_MACINFO_start_file entry. We then initialize
16241 CURRENT_FILE accordingly so that any macro definition found before the
16242 first DW_MACINFO_start_file can still be associated to the base file. */
16244 mac_ptr
= section
->buffer
+ offset
;
16245 mac_end
= section
->buffer
+ section
->size
;
16247 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16248 &offset_size
, section_is_gnu
);
16249 if (mac_ptr
== NULL
)
16251 /* We already issued a complaint. */
16257 /* Do we at least have room for a macinfo type byte? */
16258 if (mac_ptr
>= mac_end
)
16260 /* Complaint is printed during the second pass as GDB will probably
16261 stop the first pass earlier upon finding
16262 DW_MACINFO_start_file. */
16266 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16269 /* Note that we rely on the fact that the corresponding GNU and
16270 DWARF constants are the same. */
16271 switch (macinfo_type
)
16273 /* A zero macinfo type indicates the end of the macro
16278 case DW_MACRO_GNU_define
:
16279 case DW_MACRO_GNU_undef
:
16280 /* Only skip the data by MAC_PTR. */
16282 unsigned int bytes_read
;
16284 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16285 mac_ptr
+= bytes_read
;
16286 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16287 mac_ptr
+= bytes_read
;
16291 case DW_MACRO_GNU_start_file
:
16293 unsigned int bytes_read
;
16296 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16297 mac_ptr
+= bytes_read
;
16298 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16299 mac_ptr
+= bytes_read
;
16301 current_file
= macro_start_file (file
, line
, current_file
,
16302 comp_dir
, lh
, objfile
);
16306 case DW_MACRO_GNU_end_file
:
16307 /* No data to skip by MAC_PTR. */
16310 case DW_MACRO_GNU_define_indirect
:
16311 case DW_MACRO_GNU_undef_indirect
:
16313 unsigned int bytes_read
;
16315 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16316 mac_ptr
+= bytes_read
;
16317 mac_ptr
+= offset_size
;
16321 case DW_MACRO_GNU_transparent_include
:
16322 /* Note that, according to the spec, a transparent include
16323 chain cannot call DW_MACRO_GNU_start_file. So, we can just
16324 skip this opcode. */
16325 mac_ptr
+= offset_size
;
16328 case DW_MACINFO_vendor_ext
:
16329 /* Only skip the data by MAC_PTR. */
16330 if (!section_is_gnu
)
16332 unsigned int bytes_read
;
16334 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16335 mac_ptr
+= bytes_read
;
16336 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16337 mac_ptr
+= bytes_read
;
16342 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16343 mac_ptr
, abfd
, offset_size
,
16345 if (mac_ptr
== NULL
)
16349 } while (macinfo_type
!= 0 && current_file
== NULL
);
16351 /* Second pass: Process all entries.
16353 Use the AT_COMMAND_LINE flag to determine whether we are still processing
16354 command-line macro definitions/undefinitions. This flag is unset when we
16355 reach the first DW_MACINFO_start_file entry. */
16357 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
16358 NULL
, xcalloc
, xfree
);
16359 cleanup
= make_cleanup_htab_delete (include_hash
);
16360 mac_ptr
= section
->buffer
+ offset
;
16361 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16363 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
16364 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
16365 offset_size
, objfile
, include_hash
);
16366 do_cleanups (cleanup
);
16369 /* Check if the attribute's form is a DW_FORM_block*
16370 if so return true else false. */
16373 attr_form_is_block (struct attribute
*attr
)
16375 return (attr
== NULL
? 0 :
16376 attr
->form
== DW_FORM_block1
16377 || attr
->form
== DW_FORM_block2
16378 || attr
->form
== DW_FORM_block4
16379 || attr
->form
== DW_FORM_block
16380 || attr
->form
== DW_FORM_exprloc
);
16383 /* Return non-zero if ATTR's value is a section offset --- classes
16384 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
16385 You may use DW_UNSND (attr) to retrieve such offsets.
16387 Section 7.5.4, "Attribute Encodings", explains that no attribute
16388 may have a value that belongs to more than one of these classes; it
16389 would be ambiguous if we did, because we use the same forms for all
16393 attr_form_is_section_offset (struct attribute
*attr
)
16395 return (attr
->form
== DW_FORM_data4
16396 || attr
->form
== DW_FORM_data8
16397 || attr
->form
== DW_FORM_sec_offset
);
16400 /* Return non-zero if ATTR's value falls in the 'constant' class, or
16401 zero otherwise. When this function returns true, you can apply
16402 dwarf2_get_attr_constant_value to it.
16404 However, note that for some attributes you must check
16405 attr_form_is_section_offset before using this test. DW_FORM_data4
16406 and DW_FORM_data8 are members of both the constant class, and of
16407 the classes that contain offsets into other debug sections
16408 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
16409 that, if an attribute's can be either a constant or one of the
16410 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
16411 taken as section offsets, not constants. */
16414 attr_form_is_constant (struct attribute
*attr
)
16416 switch (attr
->form
)
16418 case DW_FORM_sdata
:
16419 case DW_FORM_udata
:
16420 case DW_FORM_data1
:
16421 case DW_FORM_data2
:
16422 case DW_FORM_data4
:
16423 case DW_FORM_data8
:
16430 /* Return the .debug_loc section to use for CU.
16431 For DWO files use .debug_loc.dwo. */
16433 static struct dwarf2_section_info
*
16434 cu_debug_loc_section (struct dwarf2_cu
*cu
)
16437 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
16438 return &dwarf2_per_objfile
->loc
;
16441 /* A helper function that fills in a dwarf2_loclist_baton. */
16444 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
16445 struct dwarf2_loclist_baton
*baton
,
16446 struct attribute
*attr
)
16448 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16450 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
16452 baton
->per_cu
= cu
->per_cu
;
16453 gdb_assert (baton
->per_cu
);
16454 /* We don't know how long the location list is, but make sure we
16455 don't run off the edge of the section. */
16456 baton
->size
= section
->size
- DW_UNSND (attr
);
16457 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
16458 baton
->base_address
= cu
->base_address
;
16462 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
16463 struct dwarf2_cu
*cu
)
16465 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16466 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16468 if (attr_form_is_section_offset (attr
)
16469 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
16470 the section. If so, fall through to the complaint in the
16472 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
16474 struct dwarf2_loclist_baton
*baton
;
16476 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16477 sizeof (struct dwarf2_loclist_baton
));
16479 fill_in_loclist_baton (cu
, baton
, attr
);
16481 if (cu
->base_known
== 0)
16482 complaint (&symfile_complaints
,
16483 _("Location list used without "
16484 "specifying the CU base address."));
16486 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
16487 SYMBOL_LOCATION_BATON (sym
) = baton
;
16491 struct dwarf2_locexpr_baton
*baton
;
16493 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16494 sizeof (struct dwarf2_locexpr_baton
));
16495 baton
->per_cu
= cu
->per_cu
;
16496 gdb_assert (baton
->per_cu
);
16498 if (attr_form_is_block (attr
))
16500 /* Note that we're just copying the block's data pointer
16501 here, not the actual data. We're still pointing into the
16502 info_buffer for SYM's objfile; right now we never release
16503 that buffer, but when we do clean up properly this may
16505 baton
->size
= DW_BLOCK (attr
)->size
;
16506 baton
->data
= DW_BLOCK (attr
)->data
;
16510 dwarf2_invalid_attrib_class_complaint ("location description",
16511 SYMBOL_NATURAL_NAME (sym
));
16515 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16516 SYMBOL_LOCATION_BATON (sym
) = baton
;
16520 /* Return the OBJFILE associated with the compilation unit CU. If CU
16521 came from a separate debuginfo file, then the master objfile is
16525 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
16527 struct objfile
*objfile
= per_cu
->objfile
;
16529 /* Return the master objfile, so that we can report and look up the
16530 correct file containing this variable. */
16531 if (objfile
->separate_debug_objfile_backlink
)
16532 objfile
= objfile
->separate_debug_objfile_backlink
;
16537 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
16538 (CU_HEADERP is unused in such case) or prepare a temporary copy at
16539 CU_HEADERP first. */
16541 static const struct comp_unit_head
*
16542 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
16543 struct dwarf2_per_cu_data
*per_cu
)
16545 struct objfile
*objfile
;
16546 struct dwarf2_per_objfile
*per_objfile
;
16547 gdb_byte
*info_ptr
;
16550 return &per_cu
->cu
->header
;
16552 objfile
= per_cu
->objfile
;
16553 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16554 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
.sect_off
;
16556 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
16557 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
16562 /* Return the address size given in the compilation unit header for CU. */
16565 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16567 struct comp_unit_head cu_header_local
;
16568 const struct comp_unit_head
*cu_headerp
;
16570 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16572 return cu_headerp
->addr_size
;
16575 /* Return the offset size given in the compilation unit header for CU. */
16578 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
16580 struct comp_unit_head cu_header_local
;
16581 const struct comp_unit_head
*cu_headerp
;
16583 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16585 return cu_headerp
->offset_size
;
16588 /* See its dwarf2loc.h declaration. */
16591 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16593 struct comp_unit_head cu_header_local
;
16594 const struct comp_unit_head
*cu_headerp
;
16596 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16598 if (cu_headerp
->version
== 2)
16599 return cu_headerp
->addr_size
;
16601 return cu_headerp
->offset_size
;
16604 /* Return the text offset of the CU. The returned offset comes from
16605 this CU's objfile. If this objfile came from a separate debuginfo
16606 file, then the offset may be different from the corresponding
16607 offset in the parent objfile. */
16610 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
16612 struct objfile
*objfile
= per_cu
->objfile
;
16614 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16617 /* Locate the .debug_info compilation unit from CU's objfile which contains
16618 the DIE at OFFSET. Raises an error on failure. */
16620 static struct dwarf2_per_cu_data
*
16621 dwarf2_find_containing_comp_unit (sect_offset offset
,
16622 struct objfile
*objfile
)
16624 struct dwarf2_per_cu_data
*this_cu
;
16628 high
= dwarf2_per_objfile
->n_comp_units
- 1;
16631 int mid
= low
+ (high
- low
) / 2;
16633 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
16634 >= offset
.sect_off
)
16639 gdb_assert (low
== high
);
16640 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
16644 error (_("Dwarf Error: could not find partial DIE containing "
16645 "offset 0x%lx [in module %s]"),
16646 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16648 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
16649 <= offset
.sect_off
);
16650 return dwarf2_per_objfile
->all_comp_units
[low
-1];
16654 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
16655 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
16656 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
16657 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
16658 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
16663 /* Initialize dwarf2_cu CU, owned by PER_CU. */
16666 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
16668 memset (cu
, 0, sizeof (*cu
));
16670 cu
->per_cu
= per_cu
;
16671 cu
->objfile
= per_cu
->objfile
;
16672 obstack_init (&cu
->comp_unit_obstack
);
16675 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
16678 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
16679 enum language pretend_language
)
16681 struct attribute
*attr
;
16683 /* Set the language we're debugging. */
16684 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
16686 set_cu_language (DW_UNSND (attr
), cu
);
16689 cu
->language
= pretend_language
;
16690 cu
->language_defn
= language_def (cu
->language
);
16693 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
16695 cu
->producer
= DW_STRING (attr
);
16698 /* Release one cached compilation unit, CU. We unlink it from the tree
16699 of compilation units, but we don't remove it from the read_in_chain;
16700 the caller is responsible for that.
16701 NOTE: DATA is a void * because this function is also used as a
16702 cleanup routine. */
16705 free_heap_comp_unit (void *data
)
16707 struct dwarf2_cu
*cu
= data
;
16709 gdb_assert (cu
->per_cu
!= NULL
);
16710 cu
->per_cu
->cu
= NULL
;
16713 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16718 /* This cleanup function is passed the address of a dwarf2_cu on the stack
16719 when we're finished with it. We can't free the pointer itself, but be
16720 sure to unlink it from the cache. Also release any associated storage. */
16723 free_stack_comp_unit (void *data
)
16725 struct dwarf2_cu
*cu
= data
;
16727 gdb_assert (cu
->per_cu
!= NULL
);
16728 cu
->per_cu
->cu
= NULL
;
16731 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16732 cu
->partial_dies
= NULL
;
16735 /* Free all cached compilation units. */
16738 free_cached_comp_units (void *data
)
16740 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16742 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16743 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16744 while (per_cu
!= NULL
)
16746 struct dwarf2_per_cu_data
*next_cu
;
16748 next_cu
= per_cu
->cu
->read_in_chain
;
16750 free_heap_comp_unit (per_cu
->cu
);
16751 *last_chain
= next_cu
;
16757 /* Increase the age counter on each cached compilation unit, and free
16758 any that are too old. */
16761 age_cached_comp_units (void)
16763 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16765 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
16766 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16767 while (per_cu
!= NULL
)
16769 per_cu
->cu
->last_used
++;
16770 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
16771 dwarf2_mark (per_cu
->cu
);
16772 per_cu
= per_cu
->cu
->read_in_chain
;
16775 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16776 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16777 while (per_cu
!= NULL
)
16779 struct dwarf2_per_cu_data
*next_cu
;
16781 next_cu
= per_cu
->cu
->read_in_chain
;
16783 if (!per_cu
->cu
->mark
)
16785 free_heap_comp_unit (per_cu
->cu
);
16786 *last_chain
= next_cu
;
16789 last_chain
= &per_cu
->cu
->read_in_chain
;
16795 /* Remove a single compilation unit from the cache. */
16798 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
16800 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16802 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16803 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16804 while (per_cu
!= NULL
)
16806 struct dwarf2_per_cu_data
*next_cu
;
16808 next_cu
= per_cu
->cu
->read_in_chain
;
16810 if (per_cu
== target_per_cu
)
16812 free_heap_comp_unit (per_cu
->cu
);
16814 *last_chain
= next_cu
;
16818 last_chain
= &per_cu
->cu
->read_in_chain
;
16824 /* Release all extra memory associated with OBJFILE. */
16827 dwarf2_free_objfile (struct objfile
*objfile
)
16829 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16831 if (dwarf2_per_objfile
== NULL
)
16834 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16835 free_cached_comp_units (NULL
);
16837 if (dwarf2_per_objfile
->quick_file_names_table
)
16838 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
16840 /* Everything else should be on the objfile obstack. */
16843 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
16844 We store these in a hash table separate from the DIEs, and preserve them
16845 when the DIEs are flushed out of cache.
16847 The CU "per_cu" pointer is needed because offset alone is not enough to
16848 uniquely identify the type. A file may have multiple .debug_types sections,
16849 or the type may come from a DWO file. We have to use something in
16850 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
16851 routine, get_die_type_at_offset, from outside this file, and thus won't
16852 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
16855 struct dwarf2_per_cu_offset_and_type
16857 const struct dwarf2_per_cu_data
*per_cu
;
16858 sect_offset offset
;
16862 /* Hash function for a dwarf2_per_cu_offset_and_type. */
16865 per_cu_offset_and_type_hash (const void *item
)
16867 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
16869 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
16872 /* Equality function for a dwarf2_per_cu_offset_and_type. */
16875 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16877 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
16878 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
16880 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
16881 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
16884 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16885 table if necessary. For convenience, return TYPE.
16887 The DIEs reading must have careful ordering to:
16888 * Not cause infite loops trying to read in DIEs as a prerequisite for
16889 reading current DIE.
16890 * Not trying to dereference contents of still incompletely read in types
16891 while reading in other DIEs.
16892 * Enable referencing still incompletely read in types just by a pointer to
16893 the type without accessing its fields.
16895 Therefore caller should follow these rules:
16896 * Try to fetch any prerequisite types we may need to build this DIE type
16897 before building the type and calling set_die_type.
16898 * After building type call set_die_type for current DIE as soon as
16899 possible before fetching more types to complete the current type.
16900 * Make the type as complete as possible before fetching more types. */
16902 static struct type
*
16903 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16905 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
16906 struct objfile
*objfile
= cu
->objfile
;
16908 /* For Ada types, make sure that the gnat-specific data is always
16909 initialized (if not already set). There are a few types where
16910 we should not be doing so, because the type-specific area is
16911 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16912 where the type-specific area is used to store the floatformat).
16913 But this is not a problem, because the gnat-specific information
16914 is actually not needed for these types. */
16915 if (need_gnat_info (cu
)
16916 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16917 && TYPE_CODE (type
) != TYPE_CODE_FLT
16918 && !HAVE_GNAT_AUX_INFO (type
))
16919 INIT_GNAT_SPECIFIC (type
);
16921 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
16923 dwarf2_per_objfile
->die_type_hash
=
16924 htab_create_alloc_ex (127,
16925 per_cu_offset_and_type_hash
,
16926 per_cu_offset_and_type_eq
,
16928 &objfile
->objfile_obstack
,
16929 hashtab_obstack_allocate
,
16930 dummy_obstack_deallocate
);
16933 ofs
.per_cu
= cu
->per_cu
;
16934 ofs
.offset
= die
->offset
;
16936 slot
= (struct dwarf2_per_cu_offset_and_type
**)
16937 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
16939 complaint (&symfile_complaints
,
16940 _("A problem internal to GDB: DIE 0x%x has type already set"),
16941 die
->offset
.sect_off
);
16942 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16947 /* Look up the type for the die at OFFSET in the appropriate type_hash
16948 table, or return NULL if the die does not have a saved type. */
16950 static struct type
*
16951 get_die_type_at_offset (sect_offset offset
,
16952 struct dwarf2_per_cu_data
*per_cu
)
16954 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
16956 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
16959 ofs
.per_cu
= per_cu
;
16960 ofs
.offset
= offset
;
16961 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
16968 /* Look up the type for DIE in the appropriate type_hash table,
16969 or return NULL if DIE does not have a saved type. */
16971 static struct type
*
16972 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16974 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16977 /* Add a dependence relationship from CU to REF_PER_CU. */
16980 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16981 struct dwarf2_per_cu_data
*ref_per_cu
)
16985 if (cu
->dependencies
== NULL
)
16987 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16988 NULL
, &cu
->comp_unit_obstack
,
16989 hashtab_obstack_allocate
,
16990 dummy_obstack_deallocate
);
16992 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16994 *slot
= ref_per_cu
;
16997 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16998 Set the mark field in every compilation unit in the
16999 cache that we must keep because we are keeping CU. */
17002 dwarf2_mark_helper (void **slot
, void *data
)
17004 struct dwarf2_per_cu_data
*per_cu
;
17006 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
17008 /* cu->dependencies references may not yet have been ever read if QUIT aborts
17009 reading of the chain. As such dependencies remain valid it is not much
17010 useful to track and undo them during QUIT cleanups. */
17011 if (per_cu
->cu
== NULL
)
17014 if (per_cu
->cu
->mark
)
17016 per_cu
->cu
->mark
= 1;
17018 if (per_cu
->cu
->dependencies
!= NULL
)
17019 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17024 /* Set the mark field in CU and in every other compilation unit in the
17025 cache that we must keep because we are keeping CU. */
17028 dwarf2_mark (struct dwarf2_cu
*cu
)
17033 if (cu
->dependencies
!= NULL
)
17034 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17038 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
17042 per_cu
->cu
->mark
= 0;
17043 per_cu
= per_cu
->cu
->read_in_chain
;
17047 /* Trivial hash function for partial_die_info: the hash value of a DIE
17048 is its offset in .debug_info for this objfile. */
17051 partial_die_hash (const void *item
)
17053 const struct partial_die_info
*part_die
= item
;
17055 return part_die
->offset
.sect_off
;
17058 /* Trivial comparison function for partial_die_info structures: two DIEs
17059 are equal if they have the same offset. */
17062 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
17064 const struct partial_die_info
*part_die_lhs
= item_lhs
;
17065 const struct partial_die_info
*part_die_rhs
= item_rhs
;
17067 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
17070 static struct cmd_list_element
*set_dwarf2_cmdlist
;
17071 static struct cmd_list_element
*show_dwarf2_cmdlist
;
17074 set_dwarf2_cmd (char *args
, int from_tty
)
17076 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
17080 show_dwarf2_cmd (char *args
, int from_tty
)
17082 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
17085 /* If section described by INFO was mmapped, munmap it now. */
17088 munmap_section_buffer (struct dwarf2_section_info
*info
)
17090 if (info
->map_addr
!= NULL
)
17095 res
= munmap (info
->map_addr
, info
->map_len
);
17096 gdb_assert (res
== 0);
17098 /* Without HAVE_MMAP, we should never be here to begin with. */
17099 gdb_assert_not_reached ("no mmap support");
17104 /* munmap debug sections for OBJFILE, if necessary. */
17107 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
17109 struct dwarf2_per_objfile
*data
= d
;
17111 struct dwarf2_section_info
*section
;
17113 /* This is sorted according to the order they're defined in to make it easier
17114 to keep in sync. */
17115 munmap_section_buffer (&data
->info
);
17116 munmap_section_buffer (&data
->abbrev
);
17117 munmap_section_buffer (&data
->line
);
17118 munmap_section_buffer (&data
->loc
);
17119 munmap_section_buffer (&data
->macinfo
);
17120 munmap_section_buffer (&data
->macro
);
17121 munmap_section_buffer (&data
->str
);
17122 munmap_section_buffer (&data
->ranges
);
17123 munmap_section_buffer (&data
->addr
);
17124 munmap_section_buffer (&data
->frame
);
17125 munmap_section_buffer (&data
->eh_frame
);
17126 munmap_section_buffer (&data
->gdb_index
);
17129 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
17131 munmap_section_buffer (section
);
17133 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
17134 VEC_free (dwarf2_per_cu_ptr
,
17135 dwarf2_per_objfile
->all_comp_units
[ix
]->imported_symtabs
);
17137 VEC_free (dwarf2_section_info_def
, data
->types
);
17139 if (data
->dwo_files
)
17140 free_dwo_files (data
->dwo_files
, objfile
);
17144 /* The "save gdb-index" command. */
17146 /* The contents of the hash table we create when building the string
17148 struct strtab_entry
17150 offset_type offset
;
17154 /* Hash function for a strtab_entry.
17156 Function is used only during write_hash_table so no index format backward
17157 compatibility is needed. */
17160 hash_strtab_entry (const void *e
)
17162 const struct strtab_entry
*entry
= e
;
17163 return mapped_index_string_hash (INT_MAX
, entry
->str
);
17166 /* Equality function for a strtab_entry. */
17169 eq_strtab_entry (const void *a
, const void *b
)
17171 const struct strtab_entry
*ea
= a
;
17172 const struct strtab_entry
*eb
= b
;
17173 return !strcmp (ea
->str
, eb
->str
);
17176 /* Create a strtab_entry hash table. */
17179 create_strtab (void)
17181 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
17182 xfree
, xcalloc
, xfree
);
17185 /* Add a string to the constant pool. Return the string's offset in
17189 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
17192 struct strtab_entry entry
;
17193 struct strtab_entry
*result
;
17196 slot
= htab_find_slot (table
, &entry
, INSERT
);
17201 result
= XNEW (struct strtab_entry
);
17202 result
->offset
= obstack_object_size (cpool
);
17204 obstack_grow_str0 (cpool
, str
);
17207 return result
->offset
;
17210 /* An entry in the symbol table. */
17211 struct symtab_index_entry
17213 /* The name of the symbol. */
17215 /* The offset of the name in the constant pool. */
17216 offset_type index_offset
;
17217 /* A sorted vector of the indices of all the CUs that hold an object
17219 VEC (offset_type
) *cu_indices
;
17222 /* The symbol table. This is a power-of-2-sized hash table. */
17223 struct mapped_symtab
17225 offset_type n_elements
;
17227 struct symtab_index_entry
**data
;
17230 /* Hash function for a symtab_index_entry. */
17233 hash_symtab_entry (const void *e
)
17235 const struct symtab_index_entry
*entry
= e
;
17236 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
17237 sizeof (offset_type
) * VEC_length (offset_type
,
17238 entry
->cu_indices
),
17242 /* Equality function for a symtab_index_entry. */
17245 eq_symtab_entry (const void *a
, const void *b
)
17247 const struct symtab_index_entry
*ea
= a
;
17248 const struct symtab_index_entry
*eb
= b
;
17249 int len
= VEC_length (offset_type
, ea
->cu_indices
);
17250 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
17252 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
17253 VEC_address (offset_type
, eb
->cu_indices
),
17254 sizeof (offset_type
) * len
);
17257 /* Destroy a symtab_index_entry. */
17260 delete_symtab_entry (void *p
)
17262 struct symtab_index_entry
*entry
= p
;
17263 VEC_free (offset_type
, entry
->cu_indices
);
17267 /* Create a hash table holding symtab_index_entry objects. */
17270 create_symbol_hash_table (void)
17272 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
17273 delete_symtab_entry
, xcalloc
, xfree
);
17276 /* Create a new mapped symtab object. */
17278 static struct mapped_symtab
*
17279 create_mapped_symtab (void)
17281 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
17282 symtab
->n_elements
= 0;
17283 symtab
->size
= 1024;
17284 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17288 /* Destroy a mapped_symtab. */
17291 cleanup_mapped_symtab (void *p
)
17293 struct mapped_symtab
*symtab
= p
;
17294 /* The contents of the array are freed when the other hash table is
17296 xfree (symtab
->data
);
17300 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
17303 Function is used only during write_hash_table so no index format backward
17304 compatibility is needed. */
17306 static struct symtab_index_entry
**
17307 find_slot (struct mapped_symtab
*symtab
, const char *name
)
17309 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
17311 index
= hash
& (symtab
->size
- 1);
17312 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
17316 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
17317 return &symtab
->data
[index
];
17318 index
= (index
+ step
) & (symtab
->size
- 1);
17322 /* Expand SYMTAB's hash table. */
17325 hash_expand (struct mapped_symtab
*symtab
)
17327 offset_type old_size
= symtab
->size
;
17329 struct symtab_index_entry
**old_entries
= symtab
->data
;
17332 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17334 for (i
= 0; i
< old_size
; ++i
)
17336 if (old_entries
[i
])
17338 struct symtab_index_entry
**slot
= find_slot (symtab
,
17339 old_entries
[i
]->name
);
17340 *slot
= old_entries
[i
];
17344 xfree (old_entries
);
17347 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
17348 is the index of the CU in which the symbol appears. */
17351 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
17352 offset_type cu_index
)
17354 struct symtab_index_entry
**slot
;
17356 ++symtab
->n_elements
;
17357 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
17358 hash_expand (symtab
);
17360 slot
= find_slot (symtab
, name
);
17363 *slot
= XNEW (struct symtab_index_entry
);
17364 (*slot
)->name
= name
;
17365 (*slot
)->cu_indices
= NULL
;
17367 /* Don't push an index twice. Due to how we add entries we only
17368 have to check the last one. */
17369 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
17370 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
17371 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
17374 /* Add a vector of indices to the constant pool. */
17377 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
17378 struct symtab_index_entry
*entry
)
17382 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
17385 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
17386 offset_type val
= MAYBE_SWAP (len
);
17391 entry
->index_offset
= obstack_object_size (cpool
);
17393 obstack_grow (cpool
, &val
, sizeof (val
));
17395 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
17398 val
= MAYBE_SWAP (iter
);
17399 obstack_grow (cpool
, &val
, sizeof (val
));
17404 struct symtab_index_entry
*old_entry
= *slot
;
17405 entry
->index_offset
= old_entry
->index_offset
;
17408 return entry
->index_offset
;
17411 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
17412 constant pool entries going into the obstack CPOOL. */
17415 write_hash_table (struct mapped_symtab
*symtab
,
17416 struct obstack
*output
, struct obstack
*cpool
)
17419 htab_t symbol_hash_table
;
17422 symbol_hash_table
= create_symbol_hash_table ();
17423 str_table
= create_strtab ();
17425 /* We add all the index vectors to the constant pool first, to
17426 ensure alignment is ok. */
17427 for (i
= 0; i
< symtab
->size
; ++i
)
17429 if (symtab
->data
[i
])
17430 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
17433 /* Now write out the hash table. */
17434 for (i
= 0; i
< symtab
->size
; ++i
)
17436 offset_type str_off
, vec_off
;
17438 if (symtab
->data
[i
])
17440 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
17441 vec_off
= symtab
->data
[i
]->index_offset
;
17445 /* While 0 is a valid constant pool index, it is not valid
17446 to have 0 for both offsets. */
17451 str_off
= MAYBE_SWAP (str_off
);
17452 vec_off
= MAYBE_SWAP (vec_off
);
17454 obstack_grow (output
, &str_off
, sizeof (str_off
));
17455 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
17458 htab_delete (str_table
);
17459 htab_delete (symbol_hash_table
);
17462 /* Struct to map psymtab to CU index in the index file. */
17463 struct psymtab_cu_index_map
17465 struct partial_symtab
*psymtab
;
17466 unsigned int cu_index
;
17470 hash_psymtab_cu_index (const void *item
)
17472 const struct psymtab_cu_index_map
*map
= item
;
17474 return htab_hash_pointer (map
->psymtab
);
17478 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
17480 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
17481 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
17483 return lhs
->psymtab
== rhs
->psymtab
;
17486 /* Helper struct for building the address table. */
17487 struct addrmap_index_data
17489 struct objfile
*objfile
;
17490 struct obstack
*addr_obstack
;
17491 htab_t cu_index_htab
;
17493 /* Non-zero if the previous_* fields are valid.
17494 We can't write an entry until we see the next entry (since it is only then
17495 that we know the end of the entry). */
17496 int previous_valid
;
17497 /* Index of the CU in the table of all CUs in the index file. */
17498 unsigned int previous_cu_index
;
17499 /* Start address of the CU. */
17500 CORE_ADDR previous_cu_start
;
17503 /* Write an address entry to OBSTACK. */
17506 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
17507 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
17509 offset_type cu_index_to_write
;
17511 CORE_ADDR baseaddr
;
17513 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17515 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
17516 obstack_grow (obstack
, addr
, 8);
17517 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
17518 obstack_grow (obstack
, addr
, 8);
17519 cu_index_to_write
= MAYBE_SWAP (cu_index
);
17520 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
17523 /* Worker function for traversing an addrmap to build the address table. */
17526 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
17528 struct addrmap_index_data
*data
= datap
;
17529 struct partial_symtab
*pst
= obj
;
17530 offset_type cu_index
;
17533 if (data
->previous_valid
)
17534 add_address_entry (data
->objfile
, data
->addr_obstack
,
17535 data
->previous_cu_start
, start_addr
,
17536 data
->previous_cu_index
);
17538 data
->previous_cu_start
= start_addr
;
17541 struct psymtab_cu_index_map find_map
, *map
;
17542 find_map
.psymtab
= pst
;
17543 map
= htab_find (data
->cu_index_htab
, &find_map
);
17544 gdb_assert (map
!= NULL
);
17545 data
->previous_cu_index
= map
->cu_index
;
17546 data
->previous_valid
= 1;
17549 data
->previous_valid
= 0;
17554 /* Write OBJFILE's address map to OBSTACK.
17555 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
17556 in the index file. */
17559 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
17560 htab_t cu_index_htab
)
17562 struct addrmap_index_data addrmap_index_data
;
17564 /* When writing the address table, we have to cope with the fact that
17565 the addrmap iterator only provides the start of a region; we have to
17566 wait until the next invocation to get the start of the next region. */
17568 addrmap_index_data
.objfile
= objfile
;
17569 addrmap_index_data
.addr_obstack
= obstack
;
17570 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
17571 addrmap_index_data
.previous_valid
= 0;
17573 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
17574 &addrmap_index_data
);
17576 /* It's highly unlikely the last entry (end address = 0xff...ff)
17577 is valid, but we should still handle it.
17578 The end address is recorded as the start of the next region, but that
17579 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
17581 if (addrmap_index_data
.previous_valid
)
17582 add_address_entry (objfile
, obstack
,
17583 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
17584 addrmap_index_data
.previous_cu_index
);
17587 /* Add a list of partial symbols to SYMTAB. */
17590 write_psymbols (struct mapped_symtab
*symtab
,
17592 struct partial_symbol
**psymp
,
17594 offset_type cu_index
,
17597 for (; count
-- > 0; ++psymp
)
17599 void **slot
, *lookup
;
17601 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
17602 error (_("Ada is not currently supported by the index"));
17604 /* We only want to add a given psymbol once. However, we also
17605 want to account for whether it is global or static. So, we
17606 may add it twice, using slightly different values. */
17609 uintptr_t val
= 1 | (uintptr_t) *psymp
;
17611 lookup
= (void *) val
;
17616 /* Only add a given psymbol once. */
17617 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
17621 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
17626 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
17627 exception if there is an error. */
17630 write_obstack (FILE *file
, struct obstack
*obstack
)
17632 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
17634 != obstack_object_size (obstack
))
17635 error (_("couldn't data write to file"));
17638 /* Unlink a file if the argument is not NULL. */
17641 unlink_if_set (void *p
)
17643 char **filename
= p
;
17645 unlink (*filename
);
17648 /* A helper struct used when iterating over debug_types. */
17649 struct signatured_type_index_data
17651 struct objfile
*objfile
;
17652 struct mapped_symtab
*symtab
;
17653 struct obstack
*types_list
;
17658 /* A helper function that writes a single signatured_type to an
17662 write_one_signatured_type (void **slot
, void *d
)
17664 struct signatured_type_index_data
*info
= d
;
17665 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
17666 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
17667 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17670 write_psymbols (info
->symtab
,
17672 info
->objfile
->global_psymbols
.list
17673 + psymtab
->globals_offset
,
17674 psymtab
->n_global_syms
, info
->cu_index
,
17676 write_psymbols (info
->symtab
,
17678 info
->objfile
->static_psymbols
.list
17679 + psymtab
->statics_offset
,
17680 psymtab
->n_static_syms
, info
->cu_index
,
17683 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17684 entry
->per_cu
.offset
.sect_off
);
17685 obstack_grow (info
->types_list
, val
, 8);
17686 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17687 entry
->type_offset_in_tu
.cu_off
);
17688 obstack_grow (info
->types_list
, val
, 8);
17689 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
17690 obstack_grow (info
->types_list
, val
, 8);
17697 /* Recurse into all "included" dependencies and write their symbols as
17698 if they appeared in this psymtab. */
17701 recursively_write_psymbols (struct objfile
*objfile
,
17702 struct partial_symtab
*psymtab
,
17703 struct mapped_symtab
*symtab
,
17705 offset_type cu_index
)
17709 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
17710 if (psymtab
->dependencies
[i
]->user
!= NULL
)
17711 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
17712 symtab
, psyms_seen
, cu_index
);
17714 write_psymbols (symtab
,
17716 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
17717 psymtab
->n_global_syms
, cu_index
,
17719 write_psymbols (symtab
,
17721 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
17722 psymtab
->n_static_syms
, cu_index
,
17726 /* Create an index file for OBJFILE in the directory DIR. */
17729 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
17731 struct cleanup
*cleanup
;
17732 char *filename
, *cleanup_filename
;
17733 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
17734 struct obstack cu_list
, types_cu_list
;
17737 struct mapped_symtab
*symtab
;
17738 offset_type val
, size_of_contents
, total_len
;
17742 htab_t cu_index_htab
;
17743 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
17745 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
17748 if (dwarf2_per_objfile
->using_index
)
17749 error (_("Cannot use an index to create the index"));
17751 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
17752 error (_("Cannot make an index when the file has multiple .debug_types sections"));
17754 if (stat (objfile
->name
, &st
) < 0)
17755 perror_with_name (objfile
->name
);
17757 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
17758 INDEX_SUFFIX
, (char *) NULL
);
17759 cleanup
= make_cleanup (xfree
, filename
);
17761 out_file
= fopen (filename
, "wb");
17763 error (_("Can't open `%s' for writing"), filename
);
17765 cleanup_filename
= filename
;
17766 make_cleanup (unlink_if_set
, &cleanup_filename
);
17768 symtab
= create_mapped_symtab ();
17769 make_cleanup (cleanup_mapped_symtab
, symtab
);
17771 obstack_init (&addr_obstack
);
17772 make_cleanup_obstack_free (&addr_obstack
);
17774 obstack_init (&cu_list
);
17775 make_cleanup_obstack_free (&cu_list
);
17777 obstack_init (&types_cu_list
);
17778 make_cleanup_obstack_free (&types_cu_list
);
17780 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
17781 NULL
, xcalloc
, xfree
);
17782 make_cleanup_htab_delete (psyms_seen
);
17784 /* While we're scanning CU's create a table that maps a psymtab pointer
17785 (which is what addrmap records) to its index (which is what is recorded
17786 in the index file). This will later be needed to write the address
17788 cu_index_htab
= htab_create_alloc (100,
17789 hash_psymtab_cu_index
,
17790 eq_psymtab_cu_index
,
17791 NULL
, xcalloc
, xfree
);
17792 make_cleanup_htab_delete (cu_index_htab
);
17793 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
17794 xmalloc (sizeof (struct psymtab_cu_index_map
)
17795 * dwarf2_per_objfile
->n_comp_units
);
17796 make_cleanup (xfree
, psymtab_cu_index_map
);
17798 /* The CU list is already sorted, so we don't need to do additional
17799 work here. Also, the debug_types entries do not appear in
17800 all_comp_units, but only in their own hash table. */
17801 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
17803 struct dwarf2_per_cu_data
*per_cu
17804 = dwarf2_per_objfile
->all_comp_units
[i
];
17805 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17807 struct psymtab_cu_index_map
*map
;
17810 if (psymtab
->user
== NULL
)
17811 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
17813 map
= &psymtab_cu_index_map
[i
];
17814 map
->psymtab
= psymtab
;
17816 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
17817 gdb_assert (slot
!= NULL
);
17818 gdb_assert (*slot
== NULL
);
17821 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17822 per_cu
->offset
.sect_off
);
17823 obstack_grow (&cu_list
, val
, 8);
17824 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
17825 obstack_grow (&cu_list
, val
, 8);
17828 /* Dump the address map. */
17829 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
17831 /* Write out the .debug_type entries, if any. */
17832 if (dwarf2_per_objfile
->signatured_types
)
17834 struct signatured_type_index_data sig_data
;
17836 sig_data
.objfile
= objfile
;
17837 sig_data
.symtab
= symtab
;
17838 sig_data
.types_list
= &types_cu_list
;
17839 sig_data
.psyms_seen
= psyms_seen
;
17840 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
17841 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
17842 write_one_signatured_type
, &sig_data
);
17845 obstack_init (&constant_pool
);
17846 make_cleanup_obstack_free (&constant_pool
);
17847 obstack_init (&symtab_obstack
);
17848 make_cleanup_obstack_free (&symtab_obstack
);
17849 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
17851 obstack_init (&contents
);
17852 make_cleanup_obstack_free (&contents
);
17853 size_of_contents
= 6 * sizeof (offset_type
);
17854 total_len
= size_of_contents
;
17856 /* The version number. */
17857 val
= MAYBE_SWAP (6);
17858 obstack_grow (&contents
, &val
, sizeof (val
));
17860 /* The offset of the CU list from the start of the file. */
17861 val
= MAYBE_SWAP (total_len
);
17862 obstack_grow (&contents
, &val
, sizeof (val
));
17863 total_len
+= obstack_object_size (&cu_list
);
17865 /* The offset of the types CU list from the start of the file. */
17866 val
= MAYBE_SWAP (total_len
);
17867 obstack_grow (&contents
, &val
, sizeof (val
));
17868 total_len
+= obstack_object_size (&types_cu_list
);
17870 /* The offset of the address table from the start of the file. */
17871 val
= MAYBE_SWAP (total_len
);
17872 obstack_grow (&contents
, &val
, sizeof (val
));
17873 total_len
+= obstack_object_size (&addr_obstack
);
17875 /* The offset of the symbol table from the start of the file. */
17876 val
= MAYBE_SWAP (total_len
);
17877 obstack_grow (&contents
, &val
, sizeof (val
));
17878 total_len
+= obstack_object_size (&symtab_obstack
);
17880 /* The offset of the constant pool from the start of the file. */
17881 val
= MAYBE_SWAP (total_len
);
17882 obstack_grow (&contents
, &val
, sizeof (val
));
17883 total_len
+= obstack_object_size (&constant_pool
);
17885 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17887 write_obstack (out_file
, &contents
);
17888 write_obstack (out_file
, &cu_list
);
17889 write_obstack (out_file
, &types_cu_list
);
17890 write_obstack (out_file
, &addr_obstack
);
17891 write_obstack (out_file
, &symtab_obstack
);
17892 write_obstack (out_file
, &constant_pool
);
17896 /* We want to keep the file, so we set cleanup_filename to NULL
17897 here. See unlink_if_set. */
17898 cleanup_filename
= NULL
;
17900 do_cleanups (cleanup
);
17903 /* Implementation of the `save gdb-index' command.
17905 Note that the file format used by this command is documented in the
17906 GDB manual. Any changes here must be documented there. */
17909 save_gdb_index_command (char *arg
, int from_tty
)
17911 struct objfile
*objfile
;
17914 error (_("usage: save gdb-index DIRECTORY"));
17916 ALL_OBJFILES (objfile
)
17920 /* If the objfile does not correspond to an actual file, skip it. */
17921 if (stat (objfile
->name
, &st
) < 0)
17924 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17925 if (dwarf2_per_objfile
)
17927 volatile struct gdb_exception except
;
17929 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17931 write_psymtabs_to_index (objfile
, arg
);
17933 if (except
.reason
< 0)
17934 exception_fprintf (gdb_stderr
, except
,
17935 _("Error while writing index for `%s': "),
17943 int dwarf2_always_disassemble
;
17946 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17947 struct cmd_list_element
*c
, const char *value
)
17949 fprintf_filtered (file
,
17950 _("Whether to always disassemble "
17951 "DWARF expressions is %s.\n"),
17956 show_check_physname (struct ui_file
*file
, int from_tty
,
17957 struct cmd_list_element
*c
, const char *value
)
17959 fprintf_filtered (file
,
17960 _("Whether to check \"physname\" is %s.\n"),
17964 void _initialize_dwarf2_read (void);
17967 _initialize_dwarf2_read (void)
17969 struct cmd_list_element
*c
;
17971 dwarf2_objfile_data_key
17972 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17974 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17975 Set DWARF 2 specific variables.\n\
17976 Configure DWARF 2 variables such as the cache size"),
17977 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17978 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17980 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17981 Show DWARF 2 specific variables\n\
17982 Show DWARF 2 variables such as the cache size"),
17983 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17984 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17986 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17987 &dwarf2_max_cache_age
, _("\
17988 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17989 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17990 A higher limit means that cached compilation units will be stored\n\
17991 in memory longer, and more total memory will be used. Zero disables\n\
17992 caching, which can slow down startup."),
17994 show_dwarf2_max_cache_age
,
17995 &set_dwarf2_cmdlist
,
17996 &show_dwarf2_cmdlist
);
17998 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17999 &dwarf2_always_disassemble
, _("\
18000 Set whether `info address' always disassembles DWARF expressions."), _("\
18001 Show whether `info address' always disassembles DWARF expressions."), _("\
18002 When enabled, DWARF expressions are always printed in an assembly-like\n\
18003 syntax. When disabled, expressions will be printed in a more\n\
18004 conversational style, when possible."),
18006 show_dwarf2_always_disassemble
,
18007 &set_dwarf2_cmdlist
,
18008 &show_dwarf2_cmdlist
);
18010 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
18011 Set debugging of the dwarf2 DIE reader."), _("\
18012 Show debugging of the dwarf2 DIE reader."), _("\
18013 When enabled (non-zero), DIEs are dumped after they are read in.\n\
18014 The value is the maximum depth to print."),
18017 &setdebuglist
, &showdebuglist
);
18019 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
18020 Set cross-checking of \"physname\" code against demangler."), _("\
18021 Show cross-checking of \"physname\" code against demangler."), _("\
18022 When enabled, GDB's internal \"physname\" code is checked against\n\
18024 NULL
, show_check_physname
,
18025 &setdebuglist
, &showdebuglist
);
18027 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
18029 Save a gdb-index file.\n\
18030 Usage: save gdb-index DIRECTORY"),
18032 set_cmd_completer (c
, filename_completer
);